@tooark/code 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -19
- package/README.pt-BR.md +60 -19
- package/dist/index.cjs +379 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -3
- package/dist/index.d.ts +62 -3
- package/dist/index.js +385 -35
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorView } from '@codemirror/view';
|
|
2
|
-
import { ArkThemeSelected } from '@tooark/tokens';
|
|
2
|
+
import { ArkIntent, ArkThemeSelected, ArkSize } from '@tooark/tokens';
|
|
3
3
|
import { Completion, CompletionContext, CompletionResult } from '@codemirror/autocomplete';
|
|
4
4
|
|
|
5
5
|
/** Tema do editor. "auto" segue o color-scheme do host, ou a preferência do sistema sem lado fixo. */
|
|
@@ -19,6 +19,20 @@ type ArkCodeCompletionSource = (context: CompletionContext) => CompletionResult
|
|
|
19
19
|
* Sem ele, só `json` tem formatação (nativa, com o recuo configurado).
|
|
20
20
|
*/
|
|
21
21
|
type ArkCodeFormatter = (value: string, language: ArkCodeLanguage) => string | Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Variável `{{chave}}` informada pelo app: oferecida depois de `{{` e pintada no texto. O escopo é livre (a lib não
|
|
24
|
+
* conhece nenhum); quando a mesma chave existe em mais de um escopo, o app manda só a que vale.
|
|
25
|
+
*/
|
|
26
|
+
type ArkCodeVariable = {
|
|
27
|
+
/** Chave usada em `{{chave}}`: letras, dígitos, `_`, `.`, `-` e `$`. */
|
|
28
|
+
key: string;
|
|
29
|
+
/** Nome do escopo: vai para `data-scope` no token, para o detalhe da completion e para o tooltip. */
|
|
30
|
+
scope?: string;
|
|
31
|
+
/** Cor do token (fundo e texto suaves do intent). Padrão: "primary". */
|
|
32
|
+
intent?: ArkIntent;
|
|
33
|
+
/** Valor mostrado no tooltip e na completion; o app deixa de fora o que for segredo. */
|
|
34
|
+
value?: string;
|
|
35
|
+
};
|
|
22
36
|
/** Opções de `createCodeEditor`; cada uma tem um `set*` correspondente na instância. */
|
|
23
37
|
type ArkCodeEditorOptions = {
|
|
24
38
|
/** Texto inicial. Padrão: "". */
|
|
@@ -51,6 +65,21 @@ type ArkCodeEditorOptions = {
|
|
|
51
65
|
autocomplete?: boolean;
|
|
52
66
|
/** Chaves oferecidas como completions depois de `{{`; a escolha insere `{{chave}}`. Padrão: nenhuma. */
|
|
53
67
|
variableKeys?: string[];
|
|
68
|
+
/**
|
|
69
|
+
* Variáveis com escopo e cor: oferecidas depois de `{{` como `variableKeys` e pintadas no texto, com tooltip do
|
|
70
|
+
* escopo e do valor. Padrão: nenhuma (nada é pintado).
|
|
71
|
+
*/
|
|
72
|
+
variables?: ArkCodeVariable[];
|
|
73
|
+
/** Pinta em `danger`, sublinhado, o `{{chave}}` que não está em `variables` nem em `variableKeys`. Padrão: false. */
|
|
74
|
+
markUnknownVariables?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Campo de uma linha na altura dos controles (`size`): sem calhas nem linha ativa, Enter chama `onSubmit` em vez
|
|
77
|
+
* de quebrar a linha, quebras coladas são removidas (como num `<input>`), Tab sai do editor e Ctrl+F fica com o
|
|
78
|
+
* navegador. Padrão: false.
|
|
79
|
+
*/
|
|
80
|
+
singleLine?: boolean;
|
|
81
|
+
/** Escala da fonte e do recuo lateral; em `singleLine`, também a altura (`--ark-size-*`). Padrão: "md". */
|
|
82
|
+
size?: ArkSize;
|
|
54
83
|
/** Palavras oferecidas como completion em qualquer linguagem (chaves de um schema, nomes conhecidos). */
|
|
55
84
|
completions?: ArkCodeCompletion[];
|
|
56
85
|
/** Fonte de completion própria, além das da linguagem. */
|
|
@@ -59,6 +88,8 @@ type ArkCodeEditorOptions = {
|
|
|
59
88
|
formatter?: ArkCodeFormatter;
|
|
60
89
|
/** Chamado a cada edição do usuário com o texto atual (não dispara em `setValue`). */
|
|
61
90
|
onChange?: (value: string) => void;
|
|
91
|
+
/** Chamado com o texto atual quando Enter é pressionado em `singleLine` (fora da lista de completions). */
|
|
92
|
+
onSubmit?: (value: string) => void;
|
|
62
93
|
/** Chamado quando `format()` falha (JSON inválido, formatador lançou). */
|
|
63
94
|
onFormatError?: (error: unknown) => void;
|
|
64
95
|
};
|
|
@@ -84,6 +115,12 @@ declare const HTMLElementBase: typeof HTMLElement;
|
|
|
84
115
|
* acompanha a troca em tempo de execução (`observeColorScheme` de
|
|
85
116
|
* @tooark/tokens). O nó do CodeMirror leva `data-ark="code-editor"` e o
|
|
86
117
|
* `testid` como `data-testid`.
|
|
118
|
+
*
|
|
119
|
+
* Opcionais, desligados até o app pedir: a propriedade `variables` pinta
|
|
120
|
+
* cada `{{chave}}` pelo intent da variável, com tooltip do escopo e do valor;
|
|
121
|
+
* `mark-unknown-variables` pinta em `danger` a chave desconhecida;
|
|
122
|
+
* `single-line` vira um campo de uma linha na altura dos controles (`size`),
|
|
123
|
+
* com Enter emitindo `ark-submit` (`detail: { value }`).
|
|
87
124
|
*/
|
|
88
125
|
declare class ArkCodeEditor extends HTMLElementBase {
|
|
89
126
|
static readonly tagName = "ark-code-editor";
|
|
@@ -91,6 +128,7 @@ declare class ArkCodeEditor extends HTMLElementBase {
|
|
|
91
128
|
/** Texto antes de montar, ou o último conhecido depois de desmontar. */
|
|
92
129
|
private pendingValue;
|
|
93
130
|
private keys;
|
|
131
|
+
private vars;
|
|
94
132
|
private items;
|
|
95
133
|
private source;
|
|
96
134
|
private formatFn;
|
|
@@ -103,6 +141,18 @@ declare class ArkCodeEditor extends HTMLElementBase {
|
|
|
103
141
|
/** Chaves oferecidas como completions depois de `{{` (propriedade JS). */
|
|
104
142
|
get variableKeys(): string[];
|
|
105
143
|
set variableKeys(next: string[] | null | undefined);
|
|
144
|
+
/** Variáveis com escopo e cor (propriedade JS): completam depois de `{{` e pintam o `{{chave}}` no texto. */
|
|
145
|
+
get variables(): ArkCodeVariable[];
|
|
146
|
+
set variables(next: ArkCodeVariable[] | null | undefined);
|
|
147
|
+
/** Pinta em `danger` o `{{chave}}` fora de `variables` e `variableKeys` (atributo `mark-unknown-variables`). */
|
|
148
|
+
get markUnknownVariables(): boolean;
|
|
149
|
+
set markUnknownVariables(value: boolean | string | null | undefined);
|
|
150
|
+
/** Campo de uma linha na altura dos controles (atributo `single-line`); Enter emite `ark-submit`. */
|
|
151
|
+
get singleLine(): boolean;
|
|
152
|
+
set singleLine(value: boolean | string | null | undefined);
|
|
153
|
+
/** Escala da fonte e do recuo; em `single-line`, também a altura (atributo `size`). Padrão: "md". */
|
|
154
|
+
get size(): ArkSize;
|
|
155
|
+
set size(value: ArkSize);
|
|
106
156
|
/** Palavras oferecidas como completion em qualquer linguagem (propriedade JS, formato do CodeMirror). */
|
|
107
157
|
get completions(): ArkCodeCompletion[];
|
|
108
158
|
set completions(next: ArkCodeCompletion[] | null | undefined);
|
|
@@ -210,6 +260,14 @@ type ArkCodeEditorInstance = {
|
|
|
210
260
|
setAutocomplete(on: boolean): void;
|
|
211
261
|
/** Troca as chaves oferecidas depois de `{{`. */
|
|
212
262
|
setVariableKeys(keys: string[]): void;
|
|
263
|
+
/** Troca as variáveis com escopo e cor (completion, pintura e tooltip); lista vazia deixa de pintar. */
|
|
264
|
+
setVariables(variables: ArkCodeVariable[]): void;
|
|
265
|
+
/** Liga/desliga a marcação em `danger` dos `{{chave}}` desconhecidos. */
|
|
266
|
+
setMarkUnknownVariables(on: boolean): void;
|
|
267
|
+
/** Liga/desliga o campo de uma linha; ligar junta as linhas do documento sem chamar `onChange`. */
|
|
268
|
+
setSingleLine(on: boolean): void;
|
|
269
|
+
/** Troca a escala da fonte e do recuo lateral (e a altura em `singleLine`). */
|
|
270
|
+
setSize(size: ArkSize): void;
|
|
213
271
|
/** Troca as palavras oferecidas como completion em qualquer linguagem. */
|
|
214
272
|
setCompletions(items: ArkCodeCompletion[]): void;
|
|
215
273
|
/** Troca a fonte de completion própria. */
|
|
@@ -234,7 +292,8 @@ declare function resolveCodeTheme(theme: ArkCodeTheme | undefined, element?: Ele
|
|
|
234
292
|
* fechamento de pares, realce da linha ativa (só editável), busca por Ctrl+F, completions (da linguagem, de
|
|
235
293
|
* `variableKeys`, de `completions` e de `completionSource`), Tab para recuar com saída por Esc+Tab, recuo por
|
|
236
294
|
* espaços ou tabulação, fim de linha LF/CRLF na fronteira do valor, formatação por Shift+Alt+F (JSON nativo ou o
|
|
237
|
-
* `formatter` do app) e tema pelos tokens.
|
|
295
|
+
* `formatter` do app) e tema pelos tokens. Opcionais, ligados só pelas opções: `variables` pintadas por intent com
|
|
296
|
+
* tooltip, `markUnknownVariables` e o campo `singleLine`.
|
|
238
297
|
*/
|
|
239
298
|
declare function createCodeEditor(parent: HTMLElement, options?: ArkCodeEditorOptions): ArkCodeEditorInstance;
|
|
240
299
|
|
|
@@ -245,4 +304,4 @@ declare function createCodeEditor(parent: HTMLElement, options?: ArkCodeEditorOp
|
|
|
245
304
|
declare function registerTooarkCode(): void;
|
|
246
305
|
|
|
247
306
|
export { ArkCodeEditor, createCodeEditor, registerTooarkCode, resolveCodeTheme };
|
|
248
|
-
export type { ArkCodeCompletion, ArkCodeCompletionSource, ArkCodeEditorInstance, ArkCodeEditorOptions, ArkCodeFormatter, ArkCodeIndentStyle, ArkCodeLanguage, ArkCodeLineEnding, ArkCodeTheme };
|
|
307
|
+
export type { ArkCodeCompletion, ArkCodeCompletionSource, ArkCodeEditorInstance, ArkCodeEditorOptions, ArkCodeFormatter, ArkCodeIndentStyle, ArkCodeLanguage, ArkCodeLineEnding, ArkCodeTheme, ArkCodeVariable };
|