@tooark/wysiwyg 1.2.1 → 1.3.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/dist/index.d.cts CHANGED
@@ -98,6 +98,8 @@ type ArkWysiwygEditorOptions = {
98
98
  theme?: ArkWysiwygTheme;
99
99
  /** Texto exibido quando o editor está vazio. */
100
100
  placeholder?: string;
101
+ /** Nome acessível do conteúdo editável (`aria-label`), para quem não tem um rótulo visível. Padrão: nenhum. */
102
+ label?: string;
101
103
  /** Se o conteúdo é editável. Padrão: true. */
102
104
  editable?: boolean;
103
105
  /** Gancho de upload de imagem/vídeo; sem ele arquivos são recusados. */
@@ -132,9 +134,11 @@ declare const HTMLElementBase: typeof HTMLElement;
132
134
  * `locale-json` (rótulos), `toolbar` (grupos e/ou itens separados por vírgula,
133
135
  * `all`, ou "none"/"false" para ocultar; padrão: style, marks, lists, link,
134
136
  * blocks, clear, history), `colors` e `highlights` (JSON com a paleta),
135
- * `max-file-size` (bytes). Propriedade `uploadFile`: sem ela, imagem e vídeo
136
- * não aparecem na toolbar e arquivos colados ou arrastados são recusados
137
- * (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
137
+ * `max-file-size` (bytes), `aria-label` (vai para o conteúdo editável, o
138
+ * `role="textbox"`) e `testid` (`data-ark="wysiwyg-editor"` na raiz, com as
139
+ * partes `-toolbar` e `-content`). Propriedade `uploadFile`: sem ela, imagem
140
+ * e vídeo não aparecem na toolbar e arquivos colados ou arrastados são
141
+ * recusados (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
138
142
  */
139
143
  declare class ArkWysiwygEditor extends HTMLElementBase {
140
144
  static readonly tagName = "ark-wysiwyg-editor";
@@ -159,10 +163,10 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
159
163
  set uploadFile(value: ArkWysiwygUploader | null | undefined);
160
164
  /** Paleta da cor do texto (atributo `colors` em JSON ou propriedade). */
161
165
  get colors(): string[];
162
- set colors(value: string[] | null | undefined);
166
+ set colors(value: string[] | string | null | undefined);
163
167
  /** Paleta do marca-texto (atributo `highlights` em JSON ou propriedade). */
164
168
  get highlights(): string[];
165
- set highlights(value: string[] | null | undefined);
169
+ set highlights(value: string[] | string | null | undefined);
166
170
  /** Tema efetivamente aplicado (depois de resolver `auto`); `null` antes de renderizar. */
167
171
  get resolvedTheme(): ArkThemeSelected | null;
168
172
  /** Instância nativa do Tiptap (uso avançado); `null` antes de renderizar. */
@@ -179,6 +183,7 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
179
183
  private getMaxFileSize;
180
184
  private getToolbar;
181
185
  private build;
186
+ private applyHooks;
182
187
  private syncThemeObserver;
183
188
  private applyTheme;
184
189
  private buildToolbar;
@@ -204,7 +209,8 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
204
209
  * sanitizado ao entrar (`sanitizeWysiwygContent`), sem injetar HTML
205
210
  * arbitrário; links abrem em nova aba com `rel="noopener noreferrer nofollow"`.
206
211
  *
207
- * Conteúdo via propriedade `content` (JSON do Tiptap). Atributo: `theme`.
212
+ * Conteúdo via propriedade `content` (JSON do Tiptap). Atributos: `theme` e
213
+ * `testid` (`data-ark="wysiwyg-viewer"` na raiz e `-content` no conteúdo).
208
214
  */
209
215
  declare class ArkWysiwygViewer extends HTMLElementBase {
210
216
  static readonly tagName = "ark-wysiwyg-viewer";
@@ -224,6 +230,7 @@ declare class ArkWysiwygViewer extends HTMLElementBase {
224
230
  attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
225
231
  private getTheme;
226
232
  private build;
233
+ private applyHooks;
227
234
  private syncThemeObserver;
228
235
  private applyTheme;
229
236
  private teardown;
package/dist/index.d.ts CHANGED
@@ -98,6 +98,8 @@ type ArkWysiwygEditorOptions = {
98
98
  theme?: ArkWysiwygTheme;
99
99
  /** Texto exibido quando o editor está vazio. */
100
100
  placeholder?: string;
101
+ /** Nome acessível do conteúdo editável (`aria-label`), para quem não tem um rótulo visível. Padrão: nenhum. */
102
+ label?: string;
101
103
  /** Se o conteúdo é editável. Padrão: true. */
102
104
  editable?: boolean;
103
105
  /** Gancho de upload de imagem/vídeo; sem ele arquivos são recusados. */
@@ -132,9 +134,11 @@ declare const HTMLElementBase: typeof HTMLElement;
132
134
  * `locale-json` (rótulos), `toolbar` (grupos e/ou itens separados por vírgula,
133
135
  * `all`, ou "none"/"false" para ocultar; padrão: style, marks, lists, link,
134
136
  * blocks, clear, history), `colors` e `highlights` (JSON com a paleta),
135
- * `max-file-size` (bytes). Propriedade `uploadFile`: sem ela, imagem e vídeo
136
- * não aparecem na toolbar e arquivos colados ou arrastados são recusados
137
- * (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
137
+ * `max-file-size` (bytes), `aria-label` (vai para o conteúdo editável, o
138
+ * `role="textbox"`) e `testid` (`data-ark="wysiwyg-editor"` na raiz, com as
139
+ * partes `-toolbar` e `-content`). Propriedade `uploadFile`: sem ela, imagem
140
+ * e vídeo não aparecem na toolbar e arquivos colados ou arrastados são
141
+ * recusados (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
138
142
  */
139
143
  declare class ArkWysiwygEditor extends HTMLElementBase {
140
144
  static readonly tagName = "ark-wysiwyg-editor";
@@ -159,10 +163,10 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
159
163
  set uploadFile(value: ArkWysiwygUploader | null | undefined);
160
164
  /** Paleta da cor do texto (atributo `colors` em JSON ou propriedade). */
161
165
  get colors(): string[];
162
- set colors(value: string[] | null | undefined);
166
+ set colors(value: string[] | string | null | undefined);
163
167
  /** Paleta do marca-texto (atributo `highlights` em JSON ou propriedade). */
164
168
  get highlights(): string[];
165
- set highlights(value: string[] | null | undefined);
169
+ set highlights(value: string[] | string | null | undefined);
166
170
  /** Tema efetivamente aplicado (depois de resolver `auto`); `null` antes de renderizar. */
167
171
  get resolvedTheme(): ArkThemeSelected | null;
168
172
  /** Instância nativa do Tiptap (uso avançado); `null` antes de renderizar. */
@@ -179,6 +183,7 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
179
183
  private getMaxFileSize;
180
184
  private getToolbar;
181
185
  private build;
186
+ private applyHooks;
182
187
  private syncThemeObserver;
183
188
  private applyTheme;
184
189
  private buildToolbar;
@@ -204,7 +209,8 @@ declare class ArkWysiwygEditor extends HTMLElementBase {
204
209
  * sanitizado ao entrar (`sanitizeWysiwygContent`), sem injetar HTML
205
210
  * arbitrário; links abrem em nova aba com `rel="noopener noreferrer nofollow"`.
206
211
  *
207
- * Conteúdo via propriedade `content` (JSON do Tiptap). Atributo: `theme`.
212
+ * Conteúdo via propriedade `content` (JSON do Tiptap). Atributos: `theme` e
213
+ * `testid` (`data-ark="wysiwyg-viewer"` na raiz e `-content` no conteúdo).
208
214
  */
209
215
  declare class ArkWysiwygViewer extends HTMLElementBase {
210
216
  static readonly tagName = "ark-wysiwyg-viewer";
@@ -224,6 +230,7 @@ declare class ArkWysiwygViewer extends HTMLElementBase {
224
230
  attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
225
231
  private getTheme;
226
232
  private build;
233
+ private applyHooks;
227
234
  private syncThemeObserver;
228
235
  private applyTheme;
229
236
  private teardown;
package/dist/index.js CHANGED
@@ -240,6 +240,8 @@ function createInstance(element, options) {
240
240
  extensions: createWysiwygExtensions({ editable: options.editable, placeholder: options.placeholder }),
241
241
  content: EMPTY_DOC,
242
242
  editorProps: {
243
+ // O Tiptap já põe role="textbox" no conteúdo editável; o nome acessível vai junto, só quando o app dá um.
244
+ ...(options.label ? { attributes: { "aria-label": options.label } } : {}),
243
245
  handlePaste: (_view, event) => {
244
246
  const files = filesOf(event.clipboardData?.files);
245
247
  // Planilhas e editores copiam o texto junto de arquivos que não são mídia: aí o texto vence e cola normal.
@@ -354,6 +356,7 @@ function createWysiwygEditor(element, options = {}) {
354
356
  content: options.content,
355
357
  theme: options.theme,
356
358
  placeholder: options.placeholder,
359
+ label: options.label,
357
360
  editable: options.editable ?? true,
358
361
  uploadFile: options.uploadFile,
359
362
  maxFileSize: options.maxFileSize,
@@ -841,6 +844,48 @@ const ARK_WYSIWYG_DEFAULT_TOOLBAR = [
841
844
  const HTMLElementBase = typeof HTMLElement === "undefined" ? class {
842
845
  } : HTMLElement;
843
846
 
847
+ // Mesmos hooks de E2E de @tooark/web-components (este pacote não depende dele): `data-ark` estático em cada parte e,
848
+ // com `testid` no host, `data-testid` na parte principal e sufixado nas demais.
849
+ /** Marca `el` com `data-ark="<componente>[-parte]"` e, com `testid` no host, `data-testid="<testid>[-parte]"`. */
850
+ function applyTestHooks(host, component, el, part) {
851
+ const suffix = part ? `-${part}` : "";
852
+ el.setAttribute("data-ark", `${component}${suffix}`);
853
+ const testid = host.getAttribute("testid");
854
+ if (testid) {
855
+ el.setAttribute("data-testid", `${testid}${suffix}`);
856
+ }
857
+ else {
858
+ el.removeAttribute("data-testid");
859
+ }
860
+ }
861
+
862
+ // Um framework (ou o app) pode gravar uma propriedade no elemento antes de registerTooark*() defini-lo: sem a classe,
863
+ // `el.rows = x` vira uma propriedade própria do nó, que depois do upgrade esconde o setter da classe e o valor nunca
864
+ // chega ao componente. Ao conectar, toda propriedade própria que tem setter na classe é retirada e regravada por ele,
865
+ // na ordem em que foi gravada. Os campos da própria classe e o que os frameworks penduram no nó (chaves internas do
866
+ // React e do Vue) não têm setter e ficam como estão.
867
+ /** Reaplica pelo setter da classe as propriedades gravadas no nó antes de o elemento ser registrado. */
868
+ function upgradeProperties(element) {
869
+ const target = element;
870
+ for (const name of Object.keys(element)) {
871
+ if (!hasSetter(Object.getPrototypeOf(element), name))
872
+ continue;
873
+ const value = target[name];
874
+ delete target[name];
875
+ target[name] = value;
876
+ }
877
+ }
878
+ // Procura o acessor na cadeia de protótipos até o HTMLElement: as propriedades nativas nunca viram propriedade própria,
879
+ // porque o nó já é um HTMLElement antes do registro.
880
+ function hasSetter(prototype, name) {
881
+ for (let proto = prototype; proto && proto !== HTMLElement.prototype; proto = Object.getPrototypeOf(proto)) {
882
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
883
+ if (descriptor)
884
+ return typeof descriptor.set === "function";
885
+ }
886
+ return false;
887
+ }
888
+
844
889
  const headingAction = (level) => ({
845
890
  icon: "bold",
846
891
  label: "heading",
@@ -987,9 +1032,11 @@ let popoverSeq = 0;
987
1032
  * `locale-json` (rótulos), `toolbar` (grupos e/ou itens separados por vírgula,
988
1033
  * `all`, ou "none"/"false" para ocultar; padrão: style, marks, lists, link,
989
1034
  * blocks, clear, history), `colors` e `highlights` (JSON com a paleta),
990
- * `max-file-size` (bytes). Propriedade `uploadFile`: sem ela, imagem e vídeo
991
- * não aparecem na toolbar e arquivos colados ou arrastados são recusados
992
- * (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
1035
+ * `max-file-size` (bytes), `aria-label` (vai para o conteúdo editável, o
1036
+ * `role="textbox"`) e `testid` (`data-ark="wysiwyg-editor"` na raiz, com as
1037
+ * partes `-toolbar` e `-content`). Propriedade `uploadFile`: sem ela, imagem
1038
+ * e vídeo não aparecem na toolbar e arquivos colados ou arrastados são
1039
+ * recusados (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
993
1040
  */
994
1041
  class ArkWysiwygEditor extends HTMLElementBase {
995
1042
  constructor() {
@@ -1057,7 +1104,9 @@ class ArkWysiwygEditor extends HTMLElementBase {
1057
1104
  "locale-json",
1058
1105
  "colors",
1059
1106
  "highlights",
1060
- "max-file-size"
1107
+ "max-file-size",
1108
+ "aria-label",
1109
+ "testid"
1061
1110
  ];
1062
1111
  }
1063
1112
  /** Conteúdo do editor como JSON do Tiptap. Atribuir substitui (sanitizado) sem disparar `ark-wysiwyg-change`. */
@@ -1100,6 +1149,8 @@ class ArkWysiwygEditor extends HTMLElementBase {
1100
1149
  return this.instance?.editor ?? null;
1101
1150
  }
1102
1151
  connectedCallback() {
1152
+ // Gravadas antes do registro: o setter guarda e só a montagem abaixo constrói.
1153
+ upgradeProperties(this);
1103
1154
  ensureWysiwygStyles();
1104
1155
  this.build();
1105
1156
  }
@@ -1119,6 +1170,10 @@ class ArkWysiwygEditor extends HTMLElementBase {
1119
1170
  this.syncToolbar();
1120
1171
  return;
1121
1172
  }
1173
+ if (name === "testid") {
1174
+ this.applyHooks();
1175
+ return;
1176
+ }
1122
1177
  // placeholder, toolbar, rótulos, paletas e limite exigem reconstrução.
1123
1178
  this.build();
1124
1179
  }
@@ -1148,7 +1203,12 @@ class ArkWysiwygEditor extends HTMLElementBase {
1148
1203
  }
1149
1204
  }
1150
1205
  writePalette(name, value) {
1151
- if (Array.isArray(value)) {
1206
+ // Uma string é o JSON do atributo (React 19 e Vue gravam a prop como propriedade): vai como está, e a leitura
1207
+ // filtra as cores inválidas.
1208
+ if (typeof value === "string") {
1209
+ this.setAttribute(name, value);
1210
+ }
1211
+ else if (Array.isArray(value)) {
1152
1212
  this.setAttribute(name, JSON.stringify(value.filter(isSafeColor)));
1153
1213
  }
1154
1214
  else {
@@ -1222,6 +1282,7 @@ class ArkWysiwygEditor extends HTMLElementBase {
1222
1282
  content: this.pendingContent,
1223
1283
  theme: this.getTheme(),
1224
1284
  placeholder: this.getAttribute("placeholder") || undefined,
1285
+ label: this.getAttribute("aria-label") || undefined,
1225
1286
  editable: this.isEditable(),
1226
1287
  uploadFile: this.uploader ?? undefined,
1227
1288
  maxFileSize: this.getMaxFileSize(),
@@ -1246,8 +1307,18 @@ class ArkWysiwygEditor extends HTMLElementBase {
1246
1307
  this.instance.editor.on("transaction", this.syncToolbar);
1247
1308
  this.syncToolbar();
1248
1309
  this.root.setAttribute("data-ark-theme", this.instance.resolvedTheme());
1310
+ this.applyHooks();
1249
1311
  this.syncThemeObserver();
1250
1312
  }
1313
+ // Raiz, toolbar e conteúdo editável levam os hooks de E2E, como os componentes de @tooark/web-components.
1314
+ applyHooks() {
1315
+ if (!this.root || !this.instance)
1316
+ return;
1317
+ applyTestHooks(this, "wysiwyg-editor", this.root);
1318
+ if (this.toolbarEl)
1319
+ applyTestHooks(this, "wysiwyg-editor", this.toolbarEl, "toolbar");
1320
+ applyTestHooks(this, "wysiwyg-editor", this.instance.editor.view.dom, "content");
1321
+ }
1251
1322
  // Em `auto`, a troca de tema da página re-resolve o tema do editor; com tema fixo não há o que observar.
1252
1323
  syncThemeObserver() {
1253
1324
  this.disposeTheme?.();
@@ -1606,7 +1677,8 @@ ArkWysiwygEditor.tagName = "ark-wysiwyg-editor";
1606
1677
  * sanitizado ao entrar (`sanitizeWysiwygContent`), sem injetar HTML
1607
1678
  * arbitrário; links abrem em nova aba com `rel="noopener noreferrer nofollow"`.
1608
1679
  *
1609
- * Conteúdo via propriedade `content` (JSON do Tiptap). Atributo: `theme`.
1680
+ * Conteúdo via propriedade `content` (JSON do Tiptap). Atributos: `theme` e
1681
+ * `testid` (`data-ark="wysiwyg-viewer"` na raiz e `-content` no conteúdo).
1610
1682
  */
1611
1683
  class ArkWysiwygViewer extends HTMLElementBase {
1612
1684
  constructor() {
@@ -1618,7 +1690,7 @@ class ArkWysiwygViewer extends HTMLElementBase {
1618
1690
  this.disposeTheme = null;
1619
1691
  }
1620
1692
  static get observedAttributes() {
1621
- return ["theme"];
1693
+ return ["theme", "testid"];
1622
1694
  }
1623
1695
  /** Conteúdo a renderizar como JSON do Tiptap. */
1624
1696
  get content() {
@@ -1633,6 +1705,7 @@ class ArkWysiwygViewer extends HTMLElementBase {
1633
1705
  return this.instance?.resolvedTheme() ?? null;
1634
1706
  }
1635
1707
  connectedCallback() {
1708
+ upgradeProperties(this);
1636
1709
  ensureWysiwygStyles();
1637
1710
  this.build();
1638
1711
  }
@@ -1646,6 +1719,8 @@ class ArkWysiwygViewer extends HTMLElementBase {
1646
1719
  this.applyTheme(this.getTheme());
1647
1720
  this.syncThemeObserver();
1648
1721
  }
1722
+ if (name === "testid")
1723
+ this.applyHooks();
1649
1724
  }
1650
1725
  getTheme() {
1651
1726
  const value = (this.getAttribute("theme") || "auto").toLowerCase();
@@ -1670,8 +1745,16 @@ class ArkWysiwygViewer extends HTMLElementBase {
1670
1745
  theme: this.getTheme()
1671
1746
  });
1672
1747
  this.root.setAttribute("data-ark-theme", this.instance.resolvedTheme());
1748
+ this.applyHooks();
1673
1749
  this.syncThemeObserver();
1674
1750
  }
1751
+ // Raiz e conteúdo levam os hooks de E2E, como os componentes de @tooark/web-components.
1752
+ applyHooks() {
1753
+ if (!this.root || !this.instance)
1754
+ return;
1755
+ applyTestHooks(this, "wysiwyg-viewer", this.root);
1756
+ applyTestHooks(this, "wysiwyg-viewer", this.instance.editor.view.dom, "content");
1757
+ }
1675
1758
  // Em `auto`, a troca de tema da página re-resolve o tema do viewer; com tema fixo não há o que observar.
1676
1759
  syncThemeObserver() {
1677
1760
  this.disposeTheme?.();