@tooark/code 1.2.2 → 1.4.0

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 CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ---
11
11
 
12
- ## Contents
12
+ ## 📑 Contents
13
13
 
14
14
  - [Overview](#-overview)
15
15
  - [Installation](#-installation)
@@ -18,6 +18,8 @@
18
18
  - [Usage examples](#-usage-examples)
19
19
  - [Dependencies](#-dependencies)
20
20
  - [Contributing](#-contributing)
21
+ - [Help & Security](#-help--security)
22
+ - [Support](#-support)
21
23
  - [License](#-license)
22
24
 
23
25
  ---
@@ -56,14 +58,16 @@ import { registerTooarkCode } from "@tooark/code";
56
58
  registerTooarkCode();
57
59
  ```
58
60
 
61
+ In React, Vue or Angular use the tag directly (the framework READMEs show how); a JS property the framework assigns before this call, such as `value` bound on the tag, is applied when the element upgrades, so the order does not matter.
62
+
59
63
  ---
60
64
 
61
65
  ## 📦 Components
62
66
 
63
67
  ### `ark-code-editor`
64
68
 
65
- - Attributes: `language` (`json` | `javascript` | `yaml` | `text`), `readonly`, `placeholder`, `min-height` (default `8rem`), `line-numbers` and `fold` (on; `"false"` turns off), `wrap`, `indent-style` (`space` | `tab`), `indent-size` (default 2), `line-ending` (`auto` | `lf` | `crlf`), `tab-indent` and `autocomplete` (on; `"false"` turns off), `mark-unknown-variables`, `single-line`, `size` (`xs` … `xl`, default `md`: font and side padding, plus the height in `single-line`), `theme`, `testid`.
66
- - Properties: `value`, `variableKeys`, `variables`, `completions`, `completionSource`, `formatter`, `canFormat`, `resolvedLineEnding`, `resolvedTheme`, `view` (the `EditorView`), and one per attribute except `testid`; methods `format()`, `focus()`.
69
+ - Attributes: `language` (`json` | `javascript` | `yaml` | `text`), `readonly`, `placeholder`, `min-height` (default `8rem`), `line-numbers` and `fold` (on; `"false"` turns off), `wrap`, `indent-style` (`space` | `tab`), `indent-size` (default 2), `line-ending` (`auto` | `lf` | `crlf`), `tab-indent` and `autocomplete` (on; `"false"` turns off), `mark-unknown-variables`, `single-line`, `size` (`xs` … `xl`, default `md`: font and side padding, plus the height in `single-line`), `theme`, `aria-label` (names the editable content, CodeMirror's `role="textbox"`), `testid`.
70
+ - Properties: `value`, `variableKeys`, `variables`, `completions`, `completionSource`, `formatter`, `canFormat`, `resolvedLineEnding`, `resolvedTheme`, `view` (the `EditorView`), and one per attribute except `aria-label` and `testid`; methods `format()`, `focus()`.
67
71
  - Events: `change` (`detail: { value }`, user edits only), `ark-format-error` (`detail: { error }`), `ark-submit` (`detail: { value }`, Enter in `single-line`).
68
72
  - Keys: Ctrl/Cmd+F search, Ctrl/Cmd+Z undo, Ctrl+Y redo (Cmd+Shift+Z on macOS), Ctrl+Space completions, Shift+Alt+F format, Tab/Shift+Tab indent, Esc+Tab leave, Ctrl+M (Shift+Alt+M on macOS) toggles CodeMirror's tab-focus mode.
69
73
  - Hooks: the CodeMirror root carries `data-ark="code-editor"` and the `testid` as `data-testid`; each painted variable `data-ark="code-editor-variable"` with `data-key`; its tooltip `data-ark="code-editor-variable-tooltip"`.
@@ -156,7 +160,7 @@ Installed automatically unless marked as peer; peer dependencies are yours to in
156
160
 
157
161
  | Package | Version | Description |
158
162
  | ------------------------------------------------------------------------------------------ | ------------- | --------------------------------------------------------- |
159
- | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.2.2 | Design tokens (colors, sizes, motion) and primitive types |
163
+ | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.4.0 | Design tokens (colors, sizes, motion) and primitive types |
160
164
  | [`tslib`](https://www.npmjs.com/package/tslib) | ^2.8.1 | TypeScript runtime helpers |
161
165
  | [`@codemirror/autocomplete`](https://www.npmjs.com/package/@codemirror/autocomplete) | >=6 (peer) | Completions and bracket closing |
162
166
  | [`@codemirror/commands`](https://www.npmjs.com/package/@codemirror/commands) | >=6.6 (peer) | Keymaps, history, indentation commands |
@@ -177,6 +181,24 @@ Contributions are welcome! Open issues and pull requests in the [Tooark/web-comp
177
181
 
178
182
  ---
179
183
 
184
+ ## 🆘 Help & Security
185
+
186
+ - ❓ **Questions, bugs, feature ideas** — see [SUPPORT.md](https://github.com/Tooark/web-components/blob/main/SUPPORT.md) for the right channel
187
+ - 🔒 **Security vulnerabilities** — do **not** open a public issue; follow [SECURITY.md](https://github.com/Tooark/web-components/blob/main/SECURITY.md)
188
+
189
+ ---
190
+
191
+ ## 💖 Support
192
+
193
+ If this project helps your workflow, consider supporting its development:
194
+
195
+ - 💙 [GitHub Sponsors](https://github.com/sponsors/paulosfjunior)
196
+ - ☕ [Ko-fi](https://ko-fi.com/paulosfjunior)
197
+
198
+ Every contribution helps keep the project maintained and improving. Thank you! 🙏
199
+
200
+ ---
201
+
180
202
  ## 📄 License
181
203
 
182
204
  This project is licensed under the Apache License 2.0. See the [LICENSE](https://github.com/Tooark/web-components/blob/main/LICENSE) file for details.
package/README.pt-BR.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ---
11
11
 
12
- ## Conteúdo
12
+ ## 📑 Conteúdo
13
13
 
14
14
  - [Visão Geral](#-visão-geral)
15
15
  - [Instalação](#-instalação)
@@ -18,6 +18,8 @@
18
18
  - [Exemplos de Uso](#-exemplos-de-uso)
19
19
  - [Dependências](#-dependências)
20
20
  - [Contribuição](#-contribuição)
21
+ - [Ajuda & Segurança](#-ajuda--segurança)
22
+ - [Apoie](#-apoie)
21
23
  - [Licença](#-licença)
22
24
 
23
25
  ---
@@ -56,14 +58,16 @@ import { registerTooarkCode } from "@tooark/code";
56
58
  registerTooarkCode();
57
59
  ```
58
60
 
61
+ Em React, Vue ou Angular use a tag diretamente (os READMEs dos wrappers mostram como); uma propriedade JS que o framework atribui antes desta chamada, como `value` ligada na tag, é aplicada quando o elemento faz o upgrade, então a ordem não importa.
62
+
59
63
  ---
60
64
 
61
65
  ## 📦 Componentes
62
66
 
63
67
  ### `ark-code-editor`
64
68
 
65
- - Atributos: `language` (`json` | `javascript` | `yaml` | `text`), `readonly`, `placeholder`, `min-height` (padrão `8rem`), `line-numbers` e `fold` (ligados; `"false"` desliga), `wrap`, `indent-style` (`space` | `tab`), `indent-size` (padrão 2), `line-ending` (`auto` | `lf` | `crlf`), `tab-indent` e `autocomplete` (ligados; `"false"` desliga), `mark-unknown-variables`, `single-line`, `size` (`xs` … `xl`, padrão `md`: fonte e recuo lateral, e a altura em `single-line`), `theme`, `testid`.
66
- - Propriedades: `value`, `variableKeys`, `variables`, `completions`, `completionSource`, `formatter`, `canFormat`, `resolvedLineEnding`, `resolvedTheme`, `view` (o `EditorView`), e uma por atributo exceto `testid`; métodos `format()`, `focus()`.
69
+ - Atributos: `language` (`json` | `javascript` | `yaml` | `text`), `readonly`, `placeholder`, `min-height` (padrão `8rem`), `line-numbers` e `fold` (ligados; `"false"` desliga), `wrap`, `indent-style` (`space` | `tab`), `indent-size` (padrão 2), `line-ending` (`auto` | `lf` | `crlf`), `tab-indent` e `autocomplete` (ligados; `"false"` desliga), `mark-unknown-variables`, `single-line`, `size` (`xs` … `xl`, padrão `md`: fonte e recuo lateral, e a altura em `single-line`), `theme`, `aria-label` (nomeia o conteúdo editável, o `role="textbox"` do CodeMirror), `testid`.
70
+ - Propriedades: `value`, `variableKeys`, `variables`, `completions`, `completionSource`, `formatter`, `canFormat`, `resolvedLineEnding`, `resolvedTheme`, `view` (o `EditorView`), e uma por atributo exceto `aria-label` e `testid`; métodos `format()`, `focus()`.
67
71
  - Eventos: `change` (`detail: { value }`, só edições do usuário), `ark-format-error` (`detail: { error }`), `ark-submit` (`detail: { value }`, Enter em `single-line`).
68
72
  - Teclas: Ctrl/Cmd+F busca, Ctrl/Cmd+Z desfazer, Ctrl+Y refazer (Cmd+Shift+Z no macOS), Ctrl+Espaço completions, Shift+Alt+F formatar, Tab/Shift+Tab recuo, Esc+Tab sair, Ctrl+M (Shift+Alt+M no macOS) alterna o modo tab-focus do CodeMirror.
69
73
  - Hooks: a raiz do CodeMirror leva `data-ark="code-editor"` e o `testid` como `data-testid`; cada variável pintada, `data-ark="code-editor-variable"` com `data-key`; o tooltip dela, `data-ark="code-editor-variable-tooltip"`.
@@ -156,7 +160,7 @@ Instaladas automaticamente, salvo as marcadas como peer, que ficam por sua conta
156
160
 
157
161
  | Pacote | Versão | Descrição |
158
162
  | ------------------------------------------------------------------------------------------ | ------------- | ---------------------------------------------------------- |
159
- | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.2.2 | Design tokens (cores, tamanhos, motion) e tipos primitivos |
163
+ | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.4.0 | Design tokens (cores, tamanhos, motion) e tipos primitivos |
160
164
  | [`tslib`](https://www.npmjs.com/package/tslib) | ^2.8.1 | Helpers de runtime do TypeScript |
161
165
  | [`@codemirror/autocomplete`](https://www.npmjs.com/package/@codemirror/autocomplete) | >=6 (peer) | Completions e fechamento de pares |
162
166
  | [`@codemirror/commands`](https://www.npmjs.com/package/@codemirror/commands) | >=6.6 (peer) | Atalhos, histórico, comandos de recuo |
@@ -177,6 +181,24 @@ Contribuições são bem-vindas! Abra issues e pull requests no repositório [To
177
181
 
178
182
  ---
179
183
 
184
+ ## 🆘 Ajuda & Segurança
185
+
186
+ - ❓ **Dúvidas, bugs e ideias** — veja o [SUPPORT.md](https://github.com/Tooark/web-components/blob/main/SUPPORT.md) para escolher o canal certo
187
+ - 🔒 **Vulnerabilidades de segurança** — **não** abra issue pública; siga o [SECURITY.md](https://github.com/Tooark/web-components/blob/main/SECURITY.md)
188
+
189
+ ---
190
+
191
+ ## 💖 Apoie
192
+
193
+ Se este projeto ajuda no seu dia a dia, considere apoiar o desenvolvimento:
194
+
195
+ - 💙 [GitHub Sponsors](https://github.com/sponsors/paulosfjunior)
196
+ - ☕ [Ko-fi](https://ko-fi.com/paulosfjunior)
197
+
198
+ Cada contribuição ajuda a manter o projeto ativo e em evolução. Obrigado! 🙏
199
+
200
+ ---
201
+
180
202
  ## 📄 Licença
181
203
 
182
204
  Este projeto está licenciado sob a licença Apache 2.0. Veja o arquivo [LICENSE](https://github.com/Tooark/web-components/blob/main/LICENSE) para mais detalhes.
package/dist/index.cjs CHANGED
@@ -425,6 +425,10 @@ function joinLines(tr) {
425
425
  }
426
426
  return [tr, { changes, sequential: true }];
427
427
  }
428
+ // O conteúdo editável é o `role="textbox"` do CodeMirror: é nele que o nome acessível precisa estar.
429
+ function labelExtension(label) {
430
+ return label ? view.EditorView.contentAttributes.of({ "aria-label": label }) : [];
431
+ }
428
432
  function singleLineExtensions(on, submit) {
429
433
  if (!on)
430
434
  return [];
@@ -503,6 +507,7 @@ function createCodeEditor(parent, options = {}) {
503
507
  const theme = new state.Compartment();
504
508
  const readonly = new state.Compartment();
505
509
  const placeholder = new state.Compartment();
510
+ const labelling = new state.Compartment();
506
511
  const gutterNumbers = new state.Compartment();
507
512
  const gutterFold = new state.Compartment();
508
513
  const wrapping = new state.Compartment();
@@ -632,6 +637,7 @@ function createCodeEditor(parent, options = {}) {
632
637
  theme.of(themeFor(resolved)),
633
638
  readonly.of(readonlyExtensions()),
634
639
  placeholder.of(options.placeholder ? view.placeholder(options.placeholder) : []),
640
+ labelling.of(labelExtension(options.label)),
635
641
  wrapping.of(options.wrap ? view.EditorView.lineWrapping : []),
636
642
  indentation.of(indentExtensions(indentStyle, indentSize)),
637
643
  tabKey.of(tabExtension()),
@@ -679,6 +685,7 @@ function createCodeEditor(parent, options = {}) {
679
685
  view$1.dispatch({ effects: readonly.reconfigure(readonlyExtensions()) });
680
686
  },
681
687
  setPlaceholder: (text) => view$1.dispatch({ effects: placeholder.reconfigure(text ? view.placeholder(text) : []) }),
688
+ setLabel: (label) => view$1.dispatch({ effects: labelling.reconfigure(labelExtension(label)) }),
682
689
  setLineNumbers: (on) => {
683
690
  lineNumbersOn = on;
684
691
  view$1.dispatch({ effects: gutterNumbers.reconfigure(numbersExtension()) });
@@ -776,6 +783,33 @@ function createCodeEditor(parent, options = {}) {
776
783
  const HTMLElementBase = typeof HTMLElement === "undefined" ? class {
777
784
  } : HTMLElement;
778
785
 
786
+ // Um framework (ou o app) pode gravar uma propriedade no elemento antes de registerTooark*() defini-lo: sem a classe,
787
+ // `el.rows = x` vira uma propriedade própria do nó, que depois do upgrade esconde o setter da classe e o valor nunca
788
+ // chega ao componente. Ao conectar, toda propriedade própria que tem setter na classe é retirada e regravada por ele,
789
+ // na ordem em que foi gravada. Os campos da própria classe e o que os frameworks penduram no nó (chaves internas do
790
+ // React e do Vue) não têm setter e ficam como estão.
791
+ /** Reaplica pelo setter da classe as propriedades gravadas no nó antes de o elemento ser registrado. */
792
+ function upgradeProperties(element) {
793
+ const target = element;
794
+ for (const name of Object.keys(element)) {
795
+ if (!hasSetter(Object.getPrototypeOf(element), name))
796
+ continue;
797
+ const value = target[name];
798
+ delete target[name];
799
+ target[name] = value;
800
+ }
801
+ }
802
+ // Procura o acessor na cadeia de protótipos até o HTMLElement: as propriedades nativas nunca viram propriedade própria,
803
+ // porque o nó já é um HTMLElement antes do registro.
804
+ function hasSetter(prototype, name) {
805
+ for (let proto = prototype; proto && proto !== HTMLElement.prototype; proto = Object.getPrototypeOf(proto)) {
806
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
807
+ if (descriptor)
808
+ return typeof descriptor.set === "function";
809
+ }
810
+ return false;
811
+ }
812
+
779
813
  // Mesma regra do coerceBooleanAttr de @tooark/core (este pacote só depende de tokens): frameworks passam o valor do
780
814
  // atributo como propriedade, então "" é presente e "false" é ausente.
781
815
  function truthy(value) {
@@ -794,7 +828,8 @@ function truthy(value) {
794
828
  * `readonly`, `placeholder`, `min-height` (comprimento CSS), `line-numbers`,
795
829
  * `fold`, `tab-indent` e `autocomplete` (ligados por padrão; "false"
796
830
  * desliga), `wrap`, `indent-style` (space | tab), `indent-size`,
797
- * `line-ending` (lf | crlf | auto), `theme` (auto | light | dark) e
831
+ * `line-ending` (lf | crlf | auto), `theme` (auto | light | dark),
832
+ * `aria-label` (vai para o conteúdo editável, o `role="textbox"`) e
798
833
  * `testid`. Propriedades JS: `variableKeys` (completions depois de `{{`),
799
834
  * `completions` (palavras oferecidas em qualquer linguagem),
800
835
  * `completionSource` (fonte própria), `formatter` (formatador do app;
@@ -840,6 +875,7 @@ class ArkCodeEditor extends HTMLElementBase {
840
875
  "single-line",
841
876
  "size",
842
877
  "theme",
878
+ "aria-label",
843
879
  "testid"
844
880
  ];
845
881
  }
@@ -1031,6 +1067,7 @@ class ArkCodeEditor extends HTMLElementBase {
1031
1067
  return this.instance?.view ?? null;
1032
1068
  }
1033
1069
  connectedCallback() {
1070
+ upgradeProperties(this);
1034
1071
  // O atributo `value` só dá o texto inicial; depois a propriedade manda.
1035
1072
  if (!this.instance && !this.pendingValue && this.hasAttribute("value")) {
1036
1073
  this.pendingValue = this.getAttribute("value") ?? "";
@@ -1049,6 +1086,8 @@ class ArkCodeEditor extends HTMLElementBase {
1049
1086
  this.instance.setReadonly(this.readonly);
1050
1087
  if (name === "placeholder")
1051
1088
  this.instance.setPlaceholder(this.placeholder);
1089
+ if (name === "aria-label")
1090
+ this.instance.setLabel(newValue || undefined);
1052
1091
  if (name === "min-height")
1053
1092
  this.instance.setMinHeight(this.minHeight);
1054
1093
  if (name === "line-numbers")
@@ -1099,6 +1138,7 @@ class ArkCodeEditor extends HTMLElementBase {
1099
1138
  theme: this.theme,
1100
1139
  readonly: this.readonly,
1101
1140
  placeholder: this.placeholder || undefined,
1141
+ label: this.getAttribute("aria-label") || undefined,
1102
1142
  lineNumbers: this.lineNumbers,
1103
1143
  fold: this.fold,
1104
1144
  wrap: this.wrap,