@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 +11 -11
- package/README.pt-BR.md +11 -11
- package/dist/index.cjs +40 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +41 -6
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/index.d.cts
CHANGED
|
@@ -154,6 +154,8 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
154
154
|
private syncers;
|
|
155
155
|
/** Para de observar o tema da página; só existe com `theme="auto"`. */
|
|
156
156
|
private disposeTheme;
|
|
157
|
+
/** Para de seguir `setArkLocale()`; existe enquanto conectado. */
|
|
158
|
+
private disposeLocale;
|
|
157
159
|
static get observedAttributes(): string[];
|
|
158
160
|
/** Conteúdo do editor como JSON do Tiptap. Atribuir substitui (sanitizado) sem disparar `ark-wysiwyg-change`. */
|
|
159
161
|
get content(): ArkWysiwygContent | null;
|
|
@@ -176,6 +178,11 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
176
178
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
177
179
|
/** Envia um arquivo pelo gancho e insere a mídia na seleção; `false` se recusado (o evento diz por quê). */
|
|
178
180
|
insertFile(file: File): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Rótulos da toolbar: o `lang` próprio com o `locale-json`; sem `lang`, o padrão de `setArkLocale()` (do
|
|
183
|
+
* `@tooark/tokens`, que o core reexporta), com as strings dele por baixo do `locale-json` do elemento.
|
|
184
|
+
*/
|
|
185
|
+
private resolveLabels;
|
|
179
186
|
private getTheme;
|
|
180
187
|
private isEditable;
|
|
181
188
|
private readPalette;
|
|
@@ -306,8 +313,9 @@ declare function createWysiwygEditor(element: HTMLElement, options?: ArkWysiwygE
|
|
|
306
313
|
declare function createWysiwygViewer(element: HTMLElement, options?: ArkWysiwygViewerOptions): ArkWysiwygInstance;
|
|
307
314
|
|
|
308
315
|
/**
|
|
309
|
-
* Resolve os rótulos da toolbar: `en`, `pt` ou `es
|
|
310
|
-
* sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
|
|
316
|
+
* Resolve os rótulos da toolbar: `en`, `pt` ou `es`, também com região (`pt-BR` usa o `pt`; desconhecido cai em
|
|
317
|
+
* `en`); `localeJson` (objeto ou JSON) sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
|
|
318
|
+
* JSON inválido é ignorado.
|
|
311
319
|
*/
|
|
312
320
|
declare function resolveWysiwygLabels(lang?: string | null, localeJson?: string | Partial<ArkWysiwygLabels> | null): ArkWysiwygLabels;
|
|
313
321
|
|
package/dist/index.d.ts
CHANGED
|
@@ -154,6 +154,8 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
154
154
|
private syncers;
|
|
155
155
|
/** Para de observar o tema da página; só existe com `theme="auto"`. */
|
|
156
156
|
private disposeTheme;
|
|
157
|
+
/** Para de seguir `setArkLocale()`; existe enquanto conectado. */
|
|
158
|
+
private disposeLocale;
|
|
157
159
|
static get observedAttributes(): string[];
|
|
158
160
|
/** Conteúdo do editor como JSON do Tiptap. Atribuir substitui (sanitizado) sem disparar `ark-wysiwyg-change`. */
|
|
159
161
|
get content(): ArkWysiwygContent | null;
|
|
@@ -176,6 +178,11 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
176
178
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
177
179
|
/** Envia um arquivo pelo gancho e insere a mídia na seleção; `false` se recusado (o evento diz por quê). */
|
|
178
180
|
insertFile(file: File): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Rótulos da toolbar: o `lang` próprio com o `locale-json`; sem `lang`, o padrão de `setArkLocale()` (do
|
|
183
|
+
* `@tooark/tokens`, que o core reexporta), com as strings dele por baixo do `locale-json` do elemento.
|
|
184
|
+
*/
|
|
185
|
+
private resolveLabels;
|
|
179
186
|
private getTheme;
|
|
180
187
|
private isEditable;
|
|
181
188
|
private readPalette;
|
|
@@ -306,8 +313,9 @@ declare function createWysiwygEditor(element: HTMLElement, options?: ArkWysiwygE
|
|
|
306
313
|
declare function createWysiwygViewer(element: HTMLElement, options?: ArkWysiwygViewerOptions): ArkWysiwygInstance;
|
|
307
314
|
|
|
308
315
|
/**
|
|
309
|
-
* Resolve os rótulos da toolbar: `en`, `pt` ou `es
|
|
310
|
-
* sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
|
|
316
|
+
* Resolve os rótulos da toolbar: `en`, `pt` ou `es`, também com região (`pt-BR` usa o `pt`; desconhecido cai em
|
|
317
|
+
* `en`); `localeJson` (objeto ou JSON) sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
|
|
318
|
+
* JSON inválido é ignorado.
|
|
311
319
|
*/
|
|
312
320
|
declare function resolveWysiwygLabels(lang?: string | null, localeJson?: string | Partial<ArkWysiwygLabels> | null): ArkWysiwygLabels;
|
|
313
321
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveColorScheme, observeColorScheme } from '@tooark/tokens';
|
|
1
|
+
import { resolveColorScheme, observeArkLocale, getArkLocale, observeColorScheme } from '@tooark/tokens';
|
|
2
2
|
import { Node, mergeAttributes, Editor } from '@tiptap/core';
|
|
3
3
|
import { Highlight } from '@tiptap/extension-highlight';
|
|
4
4
|
import { Image } from '@tiptap/extension-image';
|
|
@@ -263,7 +263,7 @@ function createInstance(element, options) {
|
|
|
263
263
|
const setContent = (content) => {
|
|
264
264
|
applying = true;
|
|
265
265
|
try {
|
|
266
|
-
// Fora do
|
|
266
|
+
// Fora do histórico: Ctrl+Z depois de o app trocar o conteúdo não pode voltar ao documento anterior.
|
|
267
267
|
editor
|
|
268
268
|
.chain()
|
|
269
269
|
.setMeta("addToHistory", false)
|
|
@@ -480,11 +480,14 @@ const es = {
|
|
|
480
480
|
};
|
|
481
481
|
const LOCALES = { en, pt, es };
|
|
482
482
|
/**
|
|
483
|
-
* Resolve os rótulos da toolbar: `en`, `pt` ou `es
|
|
484
|
-
* sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
|
|
483
|
+
* Resolve os rótulos da toolbar: `en`, `pt` ou `es`, também com região (`pt-BR` usa o `pt`; desconhecido cai em
|
|
484
|
+
* `en`); `localeJson` (objeto ou JSON) sobrescreve chave a chave, e é a única fonte de `custom`. Só strings entram;
|
|
485
|
+
* JSON inválido é ignorado.
|
|
485
486
|
*/
|
|
486
487
|
function resolveWysiwygLabels(lang, localeJson) {
|
|
487
|
-
|
|
488
|
+
// Idioma base da tag (`pt-BR` e `pt_br` viram `pt`), buscado como chave própria do mapa.
|
|
489
|
+
const key = (lang || "en").trim().toLowerCase().split(/[-_]/)[0];
|
|
490
|
+
const base = Object.getOwnPropertyDescriptor(LOCALES, key)?.value ?? en;
|
|
488
491
|
let overrides = {};
|
|
489
492
|
if (typeof localeJson === "string" && localeJson.trim()) {
|
|
490
493
|
try {
|
|
@@ -1053,6 +1056,8 @@ class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
1053
1056
|
this.syncers = [];
|
|
1054
1057
|
/** Para de observar o tema da página; só existe com `theme="auto"`. */
|
|
1055
1058
|
this.disposeTheme = null;
|
|
1059
|
+
/** Para de seguir `setArkLocale()`; existe enquanto conectado. */
|
|
1060
|
+
this.disposeLocale = null;
|
|
1056
1061
|
// Um tab stop por toolbar: setas movem entre os controles habilitados, Home/End vão às pontas.
|
|
1057
1062
|
this.handleToolbarKeydown = (event) => {
|
|
1058
1063
|
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key))
|
|
@@ -1152,9 +1157,16 @@ class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
1152
1157
|
// Gravadas antes do registro: o setter guarda e só a montagem abaixo constrói.
|
|
1153
1158
|
upgradeProperties(this);
|
|
1154
1159
|
ensureWysiwygStyles();
|
|
1160
|
+
// Sem `lang` próprio os rótulos seguem setArkLocale(): a troca reconstrói, como a do atributo (o texto fica).
|
|
1161
|
+
this.disposeLocale ?? (this.disposeLocale = observeArkLocale(() => {
|
|
1162
|
+
if (!this.hasAttribute("lang") && this.instance)
|
|
1163
|
+
this.build();
|
|
1164
|
+
}));
|
|
1155
1165
|
this.build();
|
|
1156
1166
|
}
|
|
1157
1167
|
disconnectedCallback() {
|
|
1168
|
+
this.disposeLocale?.();
|
|
1169
|
+
this.disposeLocale = null;
|
|
1158
1170
|
this.teardown();
|
|
1159
1171
|
}
|
|
1160
1172
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
@@ -1181,6 +1193,29 @@ class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
1181
1193
|
insertFile(file) {
|
|
1182
1194
|
return this.instance ? this.instance.insertFile(file) : Promise.resolve(false);
|
|
1183
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Rótulos da toolbar: o `lang` próprio com o `locale-json`; sem `lang`, o padrão de `setArkLocale()` (do
|
|
1198
|
+
* `@tooark/tokens`, que o core reexporta), com as strings dele por baixo do `locale-json` do elemento.
|
|
1199
|
+
*/
|
|
1200
|
+
resolveLabels() {
|
|
1201
|
+
const lang = this.getAttribute("lang");
|
|
1202
|
+
const json = this.getAttribute("locale-json");
|
|
1203
|
+
if (lang)
|
|
1204
|
+
return resolveWysiwygLabels(lang, json);
|
|
1205
|
+
const fallback = getArkLocale();
|
|
1206
|
+
let own = {};
|
|
1207
|
+
if (json?.trim()) {
|
|
1208
|
+
try {
|
|
1209
|
+
const parsed = JSON.parse(json);
|
|
1210
|
+
if (parsed && typeof parsed === "object")
|
|
1211
|
+
own = parsed;
|
|
1212
|
+
}
|
|
1213
|
+
catch {
|
|
1214
|
+
// JSON inválido é ignorado, como em resolveWysiwygLabels.
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
return resolveWysiwygLabels(fallback.lang, { ...fallback.localeJson, ...own });
|
|
1218
|
+
}
|
|
1184
1219
|
getTheme() {
|
|
1185
1220
|
const value = (this.getAttribute("theme") || "auto").toLowerCase();
|
|
1186
1221
|
if (value === "light" || value === "dark")
|
|
@@ -1265,7 +1300,7 @@ class ArkWysiwygEditor extends HTMLElementBase {
|
|
|
1265
1300
|
}
|
|
1266
1301
|
build() {
|
|
1267
1302
|
this.teardown();
|
|
1268
|
-
this.labels =
|
|
1303
|
+
this.labels = this.resolveLabels();
|
|
1269
1304
|
const root = document.createElement("div");
|
|
1270
1305
|
root.className = "ark-wysiwyg";
|
|
1271
1306
|
const segments = this.getToolbar();
|