@tooark/wysiwyg 1.6.0 → 1.7.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
@@ -65,7 +65,7 @@ Pick the toolbar groups per instance with `toolbar` and, to enable images and vi
65
65
 
66
66
  ### `ark-wysiwyg-editor`
67
67
 
68
- - Attributes: `toolbar` (groups and/or items, comma-separated; `all`; `none`; default `style,marks,lists,link,blocks,clear,history`), `theme` (`auto` | `light` | `dark`), `placeholder`, `editable="false"`, `lang` (`en` | `pt` | `es`, or `custom` with `locale-json`), `colors`/`highlights` (JSON arrays of CSS colors: hex, a color name or `rgb()`/`hsl()`; others, such as `oklch()` or `var()`, are dropped), `max-file-size` (bytes, default 10 MiB), `aria-label` (names the editable content, Tiptap's `role="textbox"`), `testid`.
68
+ - Attributes: `toolbar` (groups and/or items, comma-separated; `all`; `none`; default `style,marks,lists,link,blocks,clear,history`), `theme` (`auto` | `light` | `dark`), `placeholder`, `editable="false"`, `lang` (`en` | `pt` | `es`, also with a region such as `pt-BR`, or `custom` with `locale-json`; without it, the default of `setArkLocale()` from `@tooark/core` or `@tooark/tokens`, followed at runtime, with the element's `locale-json` on top), `colors`/`highlights` (JSON arrays of CSS colors: hex, a color name or `rgb()`/`hsl()`; others, such as `oklch()` or `var()`, are dropped), `max-file-size` (bytes, default 10 MiB), `aria-label` (names the editable content, Tiptap's `role="textbox"`), `testid`.
69
69
  - Toolbar items, to mix with the groups in `toolbar` (unknown names are ignored; `image`/`video` only with `uploadFile`): `heading` (block style select), `heading-1` to `heading-4`, `bold`, `italic`, `underline`, `strike`, `code`, `text-color`, `highlight`, `align-left`, `align-center`, `align-right`, `align-justify`, `bullet-list`, `ordered-list`, `outdent`, `indent`, `link`, `image`, `video`, `blockquote`, `horizontal-rule`, `clear-format`, `undo`, `redo`.
70
70
  - Properties: `content` (Tiptap JSON, sanitized; setting it does not emit `ark-wysiwyg-change` and stays out of the undo history), `uploadFile`, `colors`, `highlights` (an array, or the attribute's JSON string, which is what a framework assigns), `resolvedTheme`, `editor` (the Tiptap instance); `insertFile(file)`.
71
71
  - Events: `ark-wysiwyg-change` (`detail` = JSON), `ark-wysiwyg-upload-error` (`detail: { reason, file, error? }`, reasons `no-uploader`, `unsupported-type`, `too-large`, `invalid-src`, `failed`).
@@ -124,16 +124,16 @@ Installed automatically unless marked as peer; peer dependencies are yours to in
124
124
 
125
125
  | Package | Version | Description |
126
126
  | ---------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------ |
127
- | [`@tiptap/core`](https://www.npmjs.com/package/@tiptap/core) | ^3.31.3 | Tiptap editor core (ProseMirror) |
128
- | [`@tiptap/extension-highlight`](https://www.npmjs.com/package/@tiptap/extension-highlight) | ^3.31.3 | Multicolor highlight mark (`<mark>`) |
129
- | [`@tiptap/extension-image`](https://www.npmjs.com/package/@tiptap/extension-image) | ^3.31.3 | Image node (base64 disabled) |
130
- | [`@tiptap/extension-placeholder`](https://www.npmjs.com/package/@tiptap/extension-placeholder) | ^3.31.3 | Placeholder for the empty document |
131
- | [`@tiptap/extension-text-align`](https://www.npmjs.com/package/@tiptap/extension-text-align) | ^3.31.3 | Text alignment on paragraphs and headings |
132
- | [`@tiptap/extension-text-style`](https://www.npmjs.com/package/@tiptap/extension-text-style) | ^3.31.3 | Text style mark with color |
133
- | [`@tiptap/pm`](https://www.npmjs.com/package/@tiptap/pm) | ^3.31.3 | ProseMirror packages used by Tiptap |
134
- | [`@tiptap/starter-kit`](https://www.npmjs.com/package/@tiptap/starter-kit) | ^3.31.3 | Base nodes and marks (paragraph, heading, lists, bold, link, underline…) |
135
- | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.6.0 | Design tokens (colors, sizes, motion) and primitive types |
136
- | [`tslib`](https://www.npmjs.com/package/tslib) | ^2.8.1 | TypeScript runtime helpers |
127
+ | [`@tiptap/core`](https://www.npmjs.com/package/@tiptap/core) | ^3.34.0 | Tiptap editor core (ProseMirror) |
128
+ | [`@tiptap/extension-highlight`](https://www.npmjs.com/package/@tiptap/extension-highlight) | ^3.34.0 | Multicolor highlight mark (`<mark>`) |
129
+ | [`@tiptap/extension-image`](https://www.npmjs.com/package/@tiptap/extension-image) | ^3.34.0 | Image node (base64 disabled) |
130
+ | [`@tiptap/extension-placeholder`](https://www.npmjs.com/package/@tiptap/extension-placeholder) | ^3.34.0 | Placeholder for the empty document |
131
+ | [`@tiptap/extension-text-align`](https://www.npmjs.com/package/@tiptap/extension-text-align) | ^3.34.0 | Text alignment on paragraphs and headings |
132
+ | [`@tiptap/extension-text-style`](https://www.npmjs.com/package/@tiptap/extension-text-style) | ^3.34.0 | Text style mark with color |
133
+ | [`@tiptap/pm`](https://www.npmjs.com/package/@tiptap/pm) | ^3.34.0 | ProseMirror packages used by Tiptap |
134
+ | [`@tiptap/starter-kit`](https://www.npmjs.com/package/@tiptap/starter-kit) | ^3.34.0 | Base nodes and marks (paragraph, heading, lists, bold, link, underline…) |
135
+ | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.7.0 | Design tokens (colors, sizes, motion) and primitive types |
136
+ | [`tslib`](https://www.npmjs.com/package/tslib) | ^2.9.1 | TypeScript runtime helpers |
137
137
 
138
138
  ---
139
139
 
package/README.pt-BR.md CHANGED
@@ -65,7 +65,7 @@ Escolha os grupos da toolbar por instância com `toolbar` e, para ligar imagens
65
65
 
66
66
  ### `ark-wysiwyg-editor`
67
67
 
68
- - Atributos: `toolbar` (grupos e/ou itens separados por vírgula; `all`; `none`; padrão `style,marks,lists,link,blocks,clear,history`), `theme` (`auto` | `light` | `dark`), `placeholder`, `editable="false"`, `lang` (`en` | `pt` | `es`, ou `custom` com `locale-json`), `colors`/`highlights` (arrays JSON de cores CSS: hex, nome de cor ou `rgb()`/`hsl()`; as demais, como `oklch()` ou `var()`, são descartadas), `max-file-size` (bytes, padrão 10 MiB), `aria-label` (nomeia o conteúdo editável, o `role="textbox"` do Tiptap), `testid`.
68
+ - Atributos: `toolbar` (grupos e/ou itens separados por vírgula; `all`; `none`; padrão `style,marks,lists,link,blocks,clear,history`), `theme` (`auto` | `light` | `dark`), `placeholder`, `editable="false"`, `lang` (`en` | `pt` | `es`, também com região como `pt-BR`, ou `custom` com `locale-json`; sem ele, o padrão de `setArkLocale()` do `@tooark/core` ou do `@tooark/tokens`, acompanhado em tempo de execução, com o `locale-json` do elemento por cima), `colors`/`highlights` (arrays JSON de cores CSS: hex, nome de cor ou `rgb()`/`hsl()`; as demais, como `oklch()` ou `var()`, são descartadas), `max-file-size` (bytes, padrão 10 MiB), `aria-label` (nomeia o conteúdo editável, o `role="textbox"` do Tiptap), `testid`.
69
69
  - Itens da toolbar, para combinar com os grupos em `toolbar` (nomes desconhecidos são ignorados; `image`/`video` só com `uploadFile`): `heading` (seletor de estilo do bloco), `heading-1` a `heading-4`, `bold`, `italic`, `underline`, `strike`, `code`, `text-color`, `highlight`, `align-left`, `align-center`, `align-right`, `align-justify`, `bullet-list`, `ordered-list`, `outdent`, `indent`, `link`, `image`, `video`, `blockquote`, `horizontal-rule`, `clear-format`, `undo`, `redo`.
70
70
  - Propriedades: `content` (JSON do Tiptap, sanitizado; atribuir não emite `ark-wysiwyg-change` e fica fora do histórico), `uploadFile`, `colors`, `highlights` (um array, ou a string JSON do atributo, que é o que um framework atribui), `resolvedTheme`, `editor` (a instância do Tiptap); `insertFile(file)`.
71
71
  - Eventos: `ark-wysiwyg-change` (`detail` = JSON), `ark-wysiwyg-upload-error` (`detail: { reason, file, error? }`, motivos `no-uploader`, `unsupported-type`, `too-large`, `invalid-src`, `failed`).
@@ -124,16 +124,16 @@ Instaladas automaticamente, salvo as marcadas como peer, que ficam por sua conta
124
124
 
125
125
  | Pacote | Versão | Descrição |
126
126
  | ---------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------- |
127
- | [`@tiptap/core`](https://www.npmjs.com/package/@tiptap/core) | ^3.31.3 | Núcleo do editor Tiptap (ProseMirror) |
128
- | [`@tiptap/extension-highlight`](https://www.npmjs.com/package/@tiptap/extension-highlight) | ^3.31.3 | Marca-texto multicolor (`<mark>`) |
129
- | [`@tiptap/extension-image`](https://www.npmjs.com/package/@tiptap/extension-image) | ^3.31.3 | Nó de imagem (base64 desligado) |
130
- | [`@tiptap/extension-placeholder`](https://www.npmjs.com/package/@tiptap/extension-placeholder) | ^3.31.3 | Placeholder do documento vazio |
131
- | [`@tiptap/extension-text-align`](https://www.npmjs.com/package/@tiptap/extension-text-align) | ^3.31.3 | Alinhamento de parágrafos e títulos |
132
- | [`@tiptap/extension-text-style`](https://www.npmjs.com/package/@tiptap/extension-text-style) | ^3.31.3 | Marca de estilo de texto com cor |
133
- | [`@tiptap/pm`](https://www.npmjs.com/package/@tiptap/pm) | ^3.31.3 | Pacotes ProseMirror usados pelo Tiptap |
134
- | [`@tiptap/starter-kit`](https://www.npmjs.com/package/@tiptap/starter-kit) | ^3.31.3 | Nós e marcas base (parágrafo, título, listas, negrito, link, sublinhado…) |
135
- | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.6.0 | Design tokens (cores, tamanhos, motion) e tipos primitivos |
136
- | [`tslib`](https://www.npmjs.com/package/tslib) | ^2.8.1 | Helpers de runtime do TypeScript |
127
+ | [`@tiptap/core`](https://www.npmjs.com/package/@tiptap/core) | ^3.34.0 | Núcleo do editor Tiptap (ProseMirror) |
128
+ | [`@tiptap/extension-highlight`](https://www.npmjs.com/package/@tiptap/extension-highlight) | ^3.34.0 | Marca-texto multicolor (`<mark>`) |
129
+ | [`@tiptap/extension-image`](https://www.npmjs.com/package/@tiptap/extension-image) | ^3.34.0 | Nó de imagem (base64 desligado) |
130
+ | [`@tiptap/extension-placeholder`](https://www.npmjs.com/package/@tiptap/extension-placeholder) | ^3.34.0 | Placeholder do documento vazio |
131
+ | [`@tiptap/extension-text-align`](https://www.npmjs.com/package/@tiptap/extension-text-align) | ^3.34.0 | Alinhamento de parágrafos e títulos |
132
+ | [`@tiptap/extension-text-style`](https://www.npmjs.com/package/@tiptap/extension-text-style) | ^3.34.0 | Marca de estilo de texto com cor |
133
+ | [`@tiptap/pm`](https://www.npmjs.com/package/@tiptap/pm) | ^3.34.0 | Pacotes ProseMirror usados pelo Tiptap |
134
+ | [`@tiptap/starter-kit`](https://www.npmjs.com/package/@tiptap/starter-kit) | ^3.34.0 | Nós e marcas base (parágrafo, título, listas, negrito, link, sublinhado…) |
135
+ | [`@tooark/tokens`](https://www.npmjs.com/package/@tooark/tokens) | ^1.7.0 | Design tokens (cores, tamanhos, motion) e tipos primitivos |
136
+ | [`tslib`](https://www.npmjs.com/package/tslib) | ^2.9.1 | Helpers de runtime do TypeScript |
137
137
 
138
138
  ---
139
139
 
package/dist/index.cjs CHANGED
@@ -265,7 +265,7 @@ function createInstance(element, options) {
265
265
  const setContent = (content) => {
266
266
  applying = true;
267
267
  try {
268
- // Fora do historico: Ctrl+Z depois de o app trocar o conteudo nao pode voltar ao documento anterior.
268
+ // Fora do histórico: Ctrl+Z depois de o app trocar o conteúdo não pode voltar ao documento anterior.
269
269
  editor
270
270
  .chain()
271
271
  .setMeta("addToHistory", false)
@@ -482,11 +482,14 @@ const es = {
482
482
  };
483
483
  const LOCALES = { en, pt, es };
484
484
  /**
485
- * Resolve os rótulos da toolbar: `en`, `pt` ou `es` (desconhecido cai em `en`); `localeJson` (objeto ou JSON)
486
- * sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram; JSON inválido é ignorado.
485
+ * Resolve os rótulos da toolbar: `en`, `pt` ou `es`, também com região (`pt-BR` usa o `pt`; desconhecido cai em
486
+ * `en`); `localeJson` (objeto ou JSON) sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
487
+ * JSON inválido é ignorado.
487
488
  */
488
489
  function resolveWysiwygLabels(lang, localeJson) {
489
- const base = LOCALES[(lang || "en").toLowerCase()] ?? en;
490
+ // Idioma base da tag (`pt-BR` e `pt_br` viram `pt`), buscado como chave própria do mapa.
491
+ const key = (lang || "en").trim().toLowerCase().split(/[-_]/)[0];
492
+ const base = Object.getOwnPropertyDescriptor(LOCALES, key)?.value ?? en;
490
493
  let overrides = {};
491
494
  if (typeof localeJson === "string" && localeJson.trim()) {
492
495
  try {
@@ -1055,6 +1058,8 @@ class ArkWysiwygEditor extends HTMLElementBase {
1055
1058
  this.syncers = [];
1056
1059
  /** Para de observar o tema da página; só existe com `theme="auto"`. */
1057
1060
  this.disposeTheme = null;
1061
+ /** Para de seguir `setArkLocale()`; existe enquanto conectado. */
1062
+ this.disposeLocale = null;
1058
1063
  // Um tab stop por toolbar: setas movem entre os controles habilitados, Home/End vão às pontas.
1059
1064
  this.handleToolbarKeydown = (event) => {
1060
1065
  if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key))
@@ -1154,9 +1159,16 @@ class ArkWysiwygEditor extends HTMLElementBase {
1154
1159
  // Gravadas antes do registro: o setter guarda e só a montagem abaixo constrói.
1155
1160
  upgradeProperties(this);
1156
1161
  ensureWysiwygStyles();
1162
+ // Sem `lang` próprio os rótulos seguem setArkLocale(): a troca reconstrói, como a do atributo (o texto fica).
1163
+ this.disposeLocale ?? (this.disposeLocale = tokens.observeArkLocale(() => {
1164
+ if (!this.hasAttribute("lang") && this.instance)
1165
+ this.build();
1166
+ }));
1157
1167
  this.build();
1158
1168
  }
1159
1169
  disconnectedCallback() {
1170
+ this.disposeLocale?.();
1171
+ this.disposeLocale = null;
1160
1172
  this.teardown();
1161
1173
  }
1162
1174
  attributeChangedCallback(name, oldValue, newValue) {
@@ -1183,6 +1195,29 @@ class ArkWysiwygEditor extends HTMLElementBase {
1183
1195
  insertFile(file) {
1184
1196
  return this.instance ? this.instance.insertFile(file) : Promise.resolve(false);
1185
1197
  }
1198
+ /**
1199
+ * Rótulos da toolbar: o `lang` próprio com o `locale-json`; sem `lang`, o padrão de `setArkLocale()` (do
1200
+ * `@tooark/tokens`, que o core reexporta), com as strings dele por baixo do `locale-json` do elemento.
1201
+ */
1202
+ resolveLabels() {
1203
+ const lang = this.getAttribute("lang");
1204
+ const json = this.getAttribute("locale-json");
1205
+ if (lang)
1206
+ return resolveWysiwygLabels(lang, json);
1207
+ const fallback = tokens.getArkLocale();
1208
+ let own = {};
1209
+ if (json?.trim()) {
1210
+ try {
1211
+ const parsed = JSON.parse(json);
1212
+ if (parsed && typeof parsed === "object")
1213
+ own = parsed;
1214
+ }
1215
+ catch {
1216
+ // JSON inválido é ignorado, como em resolveWysiwygLabels.
1217
+ }
1218
+ }
1219
+ return resolveWysiwygLabels(fallback.lang, { ...fallback.localeJson, ...own });
1220
+ }
1186
1221
  getTheme() {
1187
1222
  const value = (this.getAttribute("theme") || "auto").toLowerCase();
1188
1223
  if (value === "light" || value === "dark")
@@ -1267,7 +1302,7 @@ class ArkWysiwygEditor extends HTMLElementBase {
1267
1302
  }
1268
1303
  build() {
1269
1304
  this.teardown();
1270
- this.labels = resolveWysiwygLabels(this.getAttribute("lang"), this.getAttribute("locale-json"));
1305
+ this.labels = this.resolveLabels();
1271
1306
  const root = document.createElement("div");
1272
1307
  root.className = "ark-wysiwyg";
1273
1308
  const segments = this.getToolbar();