add command source indicator

This commit is contained in:
LenAnderson 2024-06-24 16:44:51 -04:00
parent 8f98a60e7e
commit 916c7f1738
3 changed files with 81 additions and 8 deletions

View File

@ -63,6 +63,10 @@ export class SlashCommand {
/**@type {Object.<string, HTMLElement>}*/ helpCache = {}; /**@type {Object.<string, HTMLElement>}*/ helpCache = {};
/**@type {Object.<string, DocumentFragment>}*/ helpDetailsCache = {}; /**@type {Object.<string, DocumentFragment>}*/ helpDetailsCache = {};
/**@type {boolean}*/ isExtension = false;
/**@type {boolean}*/ isThirdParty = false;
/**@type {string}*/ source;
renderHelpItem(key = null) { renderHelpItem(key = null) {
key = key ?? this.name; key = key ?? this.name;
if (!this.helpCache[key]) { if (!this.helpCache[key]) {
@ -227,12 +231,35 @@ export class SlashCommand {
const aliasList = [cmd.name, ...(cmd.aliases ?? [])].filter(it=>it != key); const aliasList = [cmd.name, ...(cmd.aliases ?? [])].filter(it=>it != key);
const specs = document.createElement('div'); { const specs = document.createElement('div'); {
specs.classList.add('specs'); specs.classList.add('specs');
const name = document.createElement('div'); { const head = document.createElement('div'); {
name.classList.add('name'); head.classList.add('head');
name.classList.add('monospace'); const name = document.createElement('div'); {
name.title = 'command name'; name.classList.add('name');
name.textContent = `/${key}`; name.classList.add('monospace');
specs.append(name); name.title = 'command name';
name.textContent = `/${key}`;
head.append(name);
}
const src = document.createElement('div'); {
src.classList.add('source');
src.classList.add('fa-solid');
if (this.isExtension) {
src.classList.add('isExtension');
src.classList.add('fa-cubes');
if (this.isThirdParty) src.classList.add('isThirdParty');
else src.classList.add('isCore');
} else {
src.classList.add('isCore');
src.classList.add('fa-star-of-life');
}
src.title = [
this.isExtension ? 'Extension' : 'Core',
this.isThirdParty ? 'Third Party' : (this.isExtension ? 'Core' : null),
this.source,
].filter(it=>it).join('\n');
head.append(src);
}
specs.append(head);
} }
const body = document.createElement('div'); { const body = document.createElement('div'); {
body.classList.add('body'); body.classList.add('body');

View File

@ -73,6 +73,18 @@ export class SlashCommandParser {
console.trace('WARN: Duplicate slash command registered!', [command.name, ...command.aliases]); console.trace('WARN: Duplicate slash command registered!', [command.name, ...command.aliases]);
} }
const stack = new Error().stack.split('\n').map(it=>it.trim());
command.isExtension = stack.find(it=>it.includes('/scripts/extensions/')) != null;
command.isThirdParty = stack.find(it=>it.includes('/scripts/extensions/third-party/')) != null;
if (command.isThirdParty) {
command.source = stack.find(it=>it.includes('/scripts/extensions/third-party/')).replace(/^.*?\/scripts\/extensions\/third-party\/([^/]+)\/.*$/, '$1');
} else if (command.isExtension) {
command.source = stack.find(it=>it.includes('/scripts/extensions/')).replace(/^.*?\/scripts\/extensions\/([^/]+)\/.*$/, '$1');
} else {
const idx = stack.findLastIndex(it=>it.includes('at SlashCommandParser\.')) + 1;
command.source = stack[idx].replace(/^.*?\/((?:scripts\/)?(?:[^/]+)\.js).*$/, '$1');
}
this.commands[command.name] = command; this.commands[command.name] = command;
if (Array.isArray(command.aliases)) { if (Array.isArray(command.aliases)) {

View File

@ -1744,7 +1744,12 @@ body[data-stscript-style] .hljs.language-stscript {
padding: 0.25em 0.25em 0.5em 0.25em; padding: 0.25em 0.25em 0.5em 0.25em;
border-bottom: 1px solid var(--ac-color-border); border-bottom: 1px solid var(--ac-color-border);
>.name { > .head {
display: flex;
gap: 0.5em;
}
> .head > .name, > .name {
flex: 1 1 auto;
font-weight: bold; font-weight: bold;
color: var(--ac-color-text); color: var(--ac-color-text);
cursor: help; cursor: help;
@ -1753,6 +1758,35 @@ body[data-stscript-style] .hljs.language-stscript {
text-decoration: 1px dotted underline; text-decoration: 1px dotted underline;
} }
} }
> .head > .source {
padding: 0 0.5em;
cursor: help;
display: flex;
align-items: center;
gap: 0.5em;
&.isThirdParty.isExtension {
color: #F89406;
}
&.isCore {
color: transparent;
&.isExtension {
color: #51A351;
}
&:after {
content: '';
order: -1;
height: 14px;
aspect-ratio: 1 / 1;
background-image: url('/favicon.ico');
background-size: contain;
background-repeat: no-repeat;
}
}
&:hover {
text-decoration: 1px dotted underline;
}
}
>.body { >.body {
flex-direction: column; flex-direction: column;
@ -1840,7 +1874,7 @@ body[data-stscript-style] .hljs.language-stscript {
>code { >code {
display: block; display: block;
padding: 0; padding: 1px;
} }
} }
} }