@tooark/wysiwyg 1.9.4 → 1.10.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 +2 -1
- package/README.pt-BR.md +2 -1
- package/dist/components/ark-wysiwyg-editor.cjs +830 -0
- package/dist/components/ark-wysiwyg-editor.cjs.map +1 -0
- package/dist/components/ark-wysiwyg-editor.js +828 -0
- package/dist/components/ark-wysiwyg-editor.js.map +1 -0
- package/dist/components/ark-wysiwyg-viewer.cjs +125 -0
- package/dist/components/ark-wysiwyg-viewer.cjs.map +1 -0
- package/dist/components/ark-wysiwyg-viewer.js +123 -0
- package/dist/components/ark-wysiwyg-viewer.js.map +1 -0
- package/dist/components/html-element-base.cjs +11 -0
- package/dist/components/html-element-base.cjs.map +1 -0
- package/dist/components/html-element-base.js +9 -0
- package/dist/components/html-element-base.js.map +1 -0
- package/dist/components/test-hooks.cjs +19 -0
- package/dist/components/test-hooks.cjs.map +1 -0
- package/dist/components/test-hooks.js +17 -0
- package/dist/components/test-hooks.js.map +1 -0
- package/dist/components/upgrade-properties.cjs +31 -0
- package/dist/components/upgrade-properties.cjs.map +1 -0
- package/dist/components/upgrade-properties.js +29 -0
- package/dist/components/upgrade-properties.js.map +1 -0
- package/dist/engine/index.cjs +278 -0
- package/dist/engine/index.cjs.map +1 -0
- package/dist/engine/index.js +269 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/i18n.cjs +139 -0
- package/dist/i18n.cjs.map +1 -0
- package/dist/i18n.js +137 -0
- package/dist/i18n.js.map +1 -0
- package/dist/icons.cjs +34 -0
- package/dist/icons.cjs.map +1 -0
- package/dist/icons.js +32 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.cjs +31 -1856
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -1837
- package/dist/index.js.map +1 -1
- package/dist/register.cjs +23 -0
- package/dist/register.cjs.map +1 -0
- package/dist/register.js +21 -0
- package/dist/register.js.map +1 -0
- package/dist/security.cjs +117 -0
- package/dist/security.cjs.map +1 -0
- package/dist/security.js +112 -0
- package/dist/security.js.map +1 -0
- package/dist/styles.cjs +288 -0
- package/dist/styles.cjs.map +1 -0
- package/dist/styles.js +284 -0
- package/dist/styles.js.map +1 -0
- package/dist/types/index.cjs +29 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.js +26 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tokens = require('@tooark/tokens');
|
|
4
|
+
var index$1 = require('../engine/index.cjs');
|
|
5
|
+
var i18n = require('../i18n.cjs');
|
|
6
|
+
var icons = require('../icons.cjs');
|
|
7
|
+
var security = require('../security.cjs');
|
|
8
|
+
var styles = require('../styles.cjs');
|
|
9
|
+
var index = require('../types/index.cjs');
|
|
10
|
+
var htmlElementBase = require('./html-element-base.cjs');
|
|
11
|
+
var testHooks = require('./test-hooks.cjs');
|
|
12
|
+
var upgradeProperties = require('./upgrade-properties.cjs');
|
|
13
|
+
|
|
14
|
+
const headingAction = (level) => ({
|
|
15
|
+
icon: "bold",
|
|
16
|
+
label: "heading",
|
|
17
|
+
run: (e) => e.chain().focus().toggleHeading({ level }).run(),
|
|
18
|
+
active: (e) => e.isActive("heading", { level })
|
|
19
|
+
});
|
|
20
|
+
// Botões simples: um comando, um estado. Os itens com popover, select ou arquivo têm construção própria.
|
|
21
|
+
const ACTIONS = {
|
|
22
|
+
"heading-1": headingAction(1),
|
|
23
|
+
"heading-2": headingAction(2),
|
|
24
|
+
"heading-3": headingAction(3),
|
|
25
|
+
"heading-4": headingAction(4),
|
|
26
|
+
bold: {
|
|
27
|
+
icon: "bold",
|
|
28
|
+
label: "bold",
|
|
29
|
+
run: (e) => e.chain().focus().toggleBold().run(),
|
|
30
|
+
active: (e) => e.isActive("bold")
|
|
31
|
+
},
|
|
32
|
+
italic: {
|
|
33
|
+
icon: "italic",
|
|
34
|
+
label: "italic",
|
|
35
|
+
run: (e) => e.chain().focus().toggleItalic().run(),
|
|
36
|
+
active: (e) => e.isActive("italic")
|
|
37
|
+
},
|
|
38
|
+
underline: {
|
|
39
|
+
icon: "underline",
|
|
40
|
+
label: "underline",
|
|
41
|
+
run: (e) => e.chain().focus().toggleUnderline().run(),
|
|
42
|
+
active: (e) => e.isActive("underline")
|
|
43
|
+
},
|
|
44
|
+
strike: {
|
|
45
|
+
icon: "strike",
|
|
46
|
+
label: "strike",
|
|
47
|
+
run: (e) => e.chain().focus().toggleStrike().run(),
|
|
48
|
+
active: (e) => e.isActive("strike")
|
|
49
|
+
},
|
|
50
|
+
code: {
|
|
51
|
+
icon: "code",
|
|
52
|
+
label: "code",
|
|
53
|
+
run: (e) => e.chain().focus().toggleCode().run(),
|
|
54
|
+
active: (e) => e.isActive("code")
|
|
55
|
+
},
|
|
56
|
+
"align-left": {
|
|
57
|
+
icon: "alignLeft",
|
|
58
|
+
label: "alignLeft",
|
|
59
|
+
run: (e) => e.chain().focus().setTextAlign("left").run(),
|
|
60
|
+
active: (e) => e.isActive({ textAlign: "left" })
|
|
61
|
+
},
|
|
62
|
+
"align-center": {
|
|
63
|
+
icon: "alignCenter",
|
|
64
|
+
label: "alignCenter",
|
|
65
|
+
run: (e) => e.chain().focus().setTextAlign("center").run(),
|
|
66
|
+
active: (e) => e.isActive({ textAlign: "center" })
|
|
67
|
+
},
|
|
68
|
+
"align-right": {
|
|
69
|
+
icon: "alignRight",
|
|
70
|
+
label: "alignRight",
|
|
71
|
+
run: (e) => e.chain().focus().setTextAlign("right").run(),
|
|
72
|
+
active: (e) => e.isActive({ textAlign: "right" })
|
|
73
|
+
},
|
|
74
|
+
"align-justify": {
|
|
75
|
+
icon: "alignJustify",
|
|
76
|
+
label: "alignJustify",
|
|
77
|
+
run: (e) => e.chain().focus().setTextAlign("justify").run(),
|
|
78
|
+
active: (e) => e.isActive({ textAlign: "justify" })
|
|
79
|
+
},
|
|
80
|
+
"bullet-list": {
|
|
81
|
+
icon: "bulletList",
|
|
82
|
+
label: "bulletList",
|
|
83
|
+
run: (e) => e.chain().focus().toggleBulletList().run(),
|
|
84
|
+
active: (e) => e.isActive("bulletList")
|
|
85
|
+
},
|
|
86
|
+
"ordered-list": {
|
|
87
|
+
icon: "orderedList",
|
|
88
|
+
label: "orderedList",
|
|
89
|
+
run: (e) => e.chain().focus().toggleOrderedList().run(),
|
|
90
|
+
active: (e) => e.isActive("orderedList")
|
|
91
|
+
},
|
|
92
|
+
// Recuo só em listas (aninhar/desaninhar itens): recuo de parágrafo não tem semântica no documento.
|
|
93
|
+
outdent: {
|
|
94
|
+
icon: "outdent",
|
|
95
|
+
label: "outdent",
|
|
96
|
+
run: (e) => e.chain().focus().liftListItem("listItem").run(),
|
|
97
|
+
can: (e) => e.can().liftListItem("listItem")
|
|
98
|
+
},
|
|
99
|
+
indent: {
|
|
100
|
+
icon: "indent",
|
|
101
|
+
label: "indent",
|
|
102
|
+
run: (e) => e.chain().focus().sinkListItem("listItem").run(),
|
|
103
|
+
can: (e) => e.can().sinkListItem("listItem")
|
|
104
|
+
},
|
|
105
|
+
blockquote: {
|
|
106
|
+
icon: "blockquote",
|
|
107
|
+
label: "blockquote",
|
|
108
|
+
run: (e) => e.chain().focus().toggleBlockquote().run(),
|
|
109
|
+
active: (e) => e.isActive("blockquote")
|
|
110
|
+
},
|
|
111
|
+
"horizontal-rule": {
|
|
112
|
+
icon: "horizontalRule",
|
|
113
|
+
label: "horizontalRule",
|
|
114
|
+
run: (e) => e.chain().focus().setHorizontalRule().run()
|
|
115
|
+
},
|
|
116
|
+
"clear-format": {
|
|
117
|
+
icon: "clearFormat",
|
|
118
|
+
label: "clearFormat",
|
|
119
|
+
run: (e) => e.chain().focus().unsetAllMarks().clearNodes().run()
|
|
120
|
+
},
|
|
121
|
+
undo: { icon: "undo", label: "undo", run: (e) => e.chain().focus().undo().run(), can: (e) => e.can().undo() },
|
|
122
|
+
redo: { icon: "redo", label: "redo", run: (e) => e.chain().focus().redo().run(), can: (e) => e.can().redo() }
|
|
123
|
+
};
|
|
124
|
+
const ALL_ITEMS = new Set(Object.values(index.ARK_WYSIWYG_TOOLBAR_GROUPS).flat());
|
|
125
|
+
function groupOf(item) {
|
|
126
|
+
if (item.startsWith("heading"))
|
|
127
|
+
return "style";
|
|
128
|
+
for (const [group, items] of Object.entries(index.ARK_WYSIWYG_TOOLBAR_GROUPS)) {
|
|
129
|
+
if (items.includes(item))
|
|
130
|
+
return group;
|
|
131
|
+
}
|
|
132
|
+
return "marks";
|
|
133
|
+
}
|
|
134
|
+
/** Cores oferecidas por padrão: tons médios, legíveis nos dois temas. */
|
|
135
|
+
const DEFAULT_COLORS = [
|
|
136
|
+
"#ef4444",
|
|
137
|
+
"#f97316",
|
|
138
|
+
"#eab308",
|
|
139
|
+
"#22c55e",
|
|
140
|
+
"#06b6d4",
|
|
141
|
+
"#3b82f6",
|
|
142
|
+
"#8b5cf6",
|
|
143
|
+
"#ec4899",
|
|
144
|
+
"#64748b"
|
|
145
|
+
];
|
|
146
|
+
/** Marca-texto por padrão: pastéis; o CSS força texto escuro dentro de `mark` para ler nos dois temas. */
|
|
147
|
+
const DEFAULT_HIGHLIGHTS = ["#fde047", "#fdba74", "#86efac", "#7dd3fc", "#c4b5fd", "#f9a8d4"];
|
|
148
|
+
let popoverSeq = 0;
|
|
149
|
+
/**
|
|
150
|
+
* Editor WYSIWYG (Custom Element) baseado em Tiptap.
|
|
151
|
+
*
|
|
152
|
+
* O conteúdo é trocado pela propriedade `content` (JSON do Tiptap, sanitizado
|
|
153
|
+
* ao entrar), não por atributo. Dispara `ark-wysiwyg-change` (bubbles/composed)
|
|
154
|
+
* com `detail` = JSON a cada edição do usuário.
|
|
155
|
+
*
|
|
156
|
+
* Atributos: `theme`, `placeholder`, `editable` ("false" desabilita), `lang` e
|
|
157
|
+
* `locale-json` (rótulos), `toolbar` (grupos e/ou itens separados por vírgula,
|
|
158
|
+
* `all`, ou "none"/"false" para ocultar; padrão: style, marks, lists, link,
|
|
159
|
+
* blocks, clear, history), `colors` e `highlights` (JSON com a paleta),
|
|
160
|
+
* `max-file-size` (bytes), `aria-label` (vai para o conteúdo editável, o
|
|
161
|
+
* `role="textbox"`) e `testid` (`data-ark="wysiwyg-editor"` na raiz, com as
|
|
162
|
+
* partes `-toolbar` e `-content`). Propriedade `uploadFile`: sem ela, imagem
|
|
163
|
+
* e vídeo não aparecem na toolbar e arquivos colados ou arrastados são
|
|
164
|
+
* recusados (`ark-wysiwyg-upload-error`), nunca embutidos em base64.
|
|
165
|
+
*/
|
|
166
|
+
class ArkWysiwygEditor extends htmlElementBase.HTMLElementBase {
|
|
167
|
+
constructor() {
|
|
168
|
+
super(...arguments);
|
|
169
|
+
this.instance = null;
|
|
170
|
+
this.root = null;
|
|
171
|
+
this.toolbarEl = null;
|
|
172
|
+
this.pendingContent = null;
|
|
173
|
+
this.uploader = null;
|
|
174
|
+
this.labels = i18n.resolveWysiwygLabels("en");
|
|
175
|
+
/** Controles da toolbar na ordem visual, para o tabindex circulante. */
|
|
176
|
+
this.controls = [];
|
|
177
|
+
/** Sincronizadores por controle (estado ativo, habilitado, cor atual), rodados a cada mudança de seleção. */
|
|
178
|
+
this.syncers = [];
|
|
179
|
+
/** Para de observar o tema da página; só existe com `theme="auto"`. */
|
|
180
|
+
this.disposeTheme = null;
|
|
181
|
+
/** Para de seguir `setArkLocale()`; existe enquanto conectado. */
|
|
182
|
+
this.disposeLocale = null;
|
|
183
|
+
// Um tab stop por toolbar: setas movem entre os controles habilitados, Home/End vão às pontas.
|
|
184
|
+
this.handleToolbarKeydown = (event) => {
|
|
185
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key))
|
|
186
|
+
return;
|
|
187
|
+
const target = event.target;
|
|
188
|
+
const enabled = this.controls.filter((control) => !control.disabled);
|
|
189
|
+
const index = enabled.indexOf(target);
|
|
190
|
+
if (index < 0)
|
|
191
|
+
return;
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
let next = index;
|
|
194
|
+
if (event.key === "ArrowLeft")
|
|
195
|
+
next = (index - 1 + enabled.length) % enabled.length;
|
|
196
|
+
if (event.key === "ArrowRight")
|
|
197
|
+
next = (index + 1) % enabled.length;
|
|
198
|
+
if (event.key === "Home")
|
|
199
|
+
next = 0;
|
|
200
|
+
if (event.key === "End")
|
|
201
|
+
next = enabled.length - 1;
|
|
202
|
+
this.setCurrent(enabled[next]);
|
|
203
|
+
enabled[next].focus();
|
|
204
|
+
};
|
|
205
|
+
this.handleToolbarFocus = (event) => {
|
|
206
|
+
const target = event.target;
|
|
207
|
+
if (this.controls.includes(target))
|
|
208
|
+
this.setCurrent(target);
|
|
209
|
+
};
|
|
210
|
+
this.syncToolbar = () => {
|
|
211
|
+
if (!this.instance)
|
|
212
|
+
return;
|
|
213
|
+
for (const sync of this.syncers)
|
|
214
|
+
sync();
|
|
215
|
+
// O controle corrente do tabindex não pode ser um desabilitado, senão a toolbar some da ordem do Tab.
|
|
216
|
+
const current = this.controls.find((control) => control.tabIndex === 0);
|
|
217
|
+
if (current && current.disabled) {
|
|
218
|
+
const first = this.controls.find((control) => !control.disabled);
|
|
219
|
+
if (first)
|
|
220
|
+
this.setCurrent(first);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
static get observedAttributes() {
|
|
225
|
+
return [
|
|
226
|
+
"theme",
|
|
227
|
+
"placeholder",
|
|
228
|
+
"editable",
|
|
229
|
+
"toolbar",
|
|
230
|
+
"lang",
|
|
231
|
+
"locale-json",
|
|
232
|
+
"colors",
|
|
233
|
+
"highlights",
|
|
234
|
+
"max-file-size",
|
|
235
|
+
"aria-label",
|
|
236
|
+
"testid"
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
/** Conteúdo do editor como JSON do Tiptap. Atribuir substitui (sanitizado) sem disparar `ark-wysiwyg-change`. */
|
|
240
|
+
get content() {
|
|
241
|
+
return this.instance ? this.instance.getJSON() : this.pendingContent;
|
|
242
|
+
}
|
|
243
|
+
set content(value) {
|
|
244
|
+
this.pendingContent = value;
|
|
245
|
+
this.instance?.setContent(value);
|
|
246
|
+
}
|
|
247
|
+
/** Gancho de upload de imagem/vídeo (propriedade JS). Sem ele o grupo `media` não aparece e arquivos são recusados. */
|
|
248
|
+
get uploadFile() {
|
|
249
|
+
return this.uploader;
|
|
250
|
+
}
|
|
251
|
+
set uploadFile(value) {
|
|
252
|
+
this.uploader = typeof value === "function" ? value : null;
|
|
253
|
+
if (this.instance)
|
|
254
|
+
this.build();
|
|
255
|
+
}
|
|
256
|
+
/** Paleta da cor do texto (atributo `colors` em JSON ou propriedade). */
|
|
257
|
+
get colors() {
|
|
258
|
+
return this.readPalette("colors", DEFAULT_COLORS);
|
|
259
|
+
}
|
|
260
|
+
set colors(value) {
|
|
261
|
+
this.writePalette("colors", value);
|
|
262
|
+
}
|
|
263
|
+
/** Paleta do marca-texto (atributo `highlights` em JSON ou propriedade). */
|
|
264
|
+
get highlights() {
|
|
265
|
+
return this.readPalette("highlights", DEFAULT_HIGHLIGHTS);
|
|
266
|
+
}
|
|
267
|
+
set highlights(value) {
|
|
268
|
+
this.writePalette("highlights", value);
|
|
269
|
+
}
|
|
270
|
+
/** Tema efetivamente aplicado (depois de resolver `auto`); `null` antes de renderizar. */
|
|
271
|
+
get resolvedTheme() {
|
|
272
|
+
return this.instance?.resolvedTheme() ?? null;
|
|
273
|
+
}
|
|
274
|
+
/** Instância nativa do Tiptap (uso avançado); `null` antes de renderizar. */
|
|
275
|
+
get editor() {
|
|
276
|
+
return this.instance?.editor ?? null;
|
|
277
|
+
}
|
|
278
|
+
connectedCallback() {
|
|
279
|
+
// Gravadas antes do registro: o setter guarda e só a montagem abaixo constrói.
|
|
280
|
+
upgradeProperties.upgradeProperties(this);
|
|
281
|
+
styles.ensureWysiwygStyles();
|
|
282
|
+
// Sem `lang` próprio os rótulos seguem setArkLocale(): a troca reconstrói, como a do atributo (o texto fica).
|
|
283
|
+
this.disposeLocale ?? (this.disposeLocale = tokens.observeArkLocale(() => {
|
|
284
|
+
if (!this.hasAttribute("lang") && this.instance)
|
|
285
|
+
this.build();
|
|
286
|
+
}));
|
|
287
|
+
this.build();
|
|
288
|
+
}
|
|
289
|
+
disconnectedCallback() {
|
|
290
|
+
this.disposeLocale?.();
|
|
291
|
+
this.disposeLocale = null;
|
|
292
|
+
this.teardown();
|
|
293
|
+
}
|
|
294
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
295
|
+
if (oldValue === newValue || !this.instance)
|
|
296
|
+
return;
|
|
297
|
+
if (name === "theme") {
|
|
298
|
+
this.applyTheme(this.getTheme());
|
|
299
|
+
this.syncThemeObserver();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (name === "editable") {
|
|
303
|
+
this.instance.setEditable(this.isEditable());
|
|
304
|
+
this.syncToolbar();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (name === "testid") {
|
|
308
|
+
this.applyHooks();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// placeholder, toolbar, rótulos, paletas e limite exigem reconstrução.
|
|
312
|
+
this.build();
|
|
313
|
+
}
|
|
314
|
+
/** Envia um arquivo pelo gancho e insere a mídia na seleção; `false` se recusado (o evento diz por quê). */
|
|
315
|
+
insertFile(file) {
|
|
316
|
+
return this.instance ? this.instance.insertFile(file) : Promise.resolve(false);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Rótulos da toolbar: o `lang` próprio com o `locale-json`; sem `lang`, o padrão de `setArkLocale()` (do
|
|
320
|
+
* `@tooark/tokens`, que o core reexporta), com as strings dele por baixo do `locale-json` do elemento.
|
|
321
|
+
*/
|
|
322
|
+
resolveLabels() {
|
|
323
|
+
const lang = this.getAttribute("lang");
|
|
324
|
+
const json = this.getAttribute("locale-json");
|
|
325
|
+
if (lang)
|
|
326
|
+
return i18n.resolveWysiwygLabels(lang, json);
|
|
327
|
+
const fallback = tokens.getArkLocale();
|
|
328
|
+
let own = {};
|
|
329
|
+
if (json?.trim()) {
|
|
330
|
+
try {
|
|
331
|
+
const parsed = JSON.parse(json);
|
|
332
|
+
if (parsed && typeof parsed === "object")
|
|
333
|
+
own = parsed;
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
// JSON inválido é ignorado, como em resolveWysiwygLabels.
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return i18n.resolveWysiwygLabels(fallback.lang, { ...fallback.localeJson, ...own });
|
|
340
|
+
}
|
|
341
|
+
getTheme() {
|
|
342
|
+
const value = (this.getAttribute("theme") || "auto").toLowerCase();
|
|
343
|
+
if (value === "light" || value === "dark")
|
|
344
|
+
return value;
|
|
345
|
+
return "auto";
|
|
346
|
+
}
|
|
347
|
+
isEditable() {
|
|
348
|
+
return this.getAttribute("editable") !== "false";
|
|
349
|
+
}
|
|
350
|
+
readPalette(name, fallback) {
|
|
351
|
+
const raw = this.getAttribute(name);
|
|
352
|
+
if (raw === null)
|
|
353
|
+
return [...fallback];
|
|
354
|
+
try {
|
|
355
|
+
const parsed = JSON.parse(raw);
|
|
356
|
+
return Array.isArray(parsed) ? parsed.filter(security.isSafeColor) : [...fallback];
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
return [...fallback];
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
writePalette(name, value) {
|
|
363
|
+
// Uma string é o JSON do atributo (React 19 e Vue gravam a prop como propriedade): vai como está, e a leitura
|
|
364
|
+
// filtra as cores inválidas.
|
|
365
|
+
if (typeof value === "string") {
|
|
366
|
+
this.setAttribute(name, value);
|
|
367
|
+
}
|
|
368
|
+
else if (Array.isArray(value)) {
|
|
369
|
+
this.setAttribute(name, JSON.stringify(value.filter(security.isSafeColor)));
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.removeAttribute(name);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
getMaxFileSize() {
|
|
376
|
+
const raw = Number(this.getAttribute("max-file-size"));
|
|
377
|
+
return this.hasAttribute("max-file-size") && Number.isFinite(raw) && raw > 0 ? raw : index$1.DEFAULT_MAX_FILE_SIZE;
|
|
378
|
+
}
|
|
379
|
+
// Grupos e itens viram segmentos (um por grupo, na ordem pedida); `media` só entra com o gancho de upload.
|
|
380
|
+
getToolbar() {
|
|
381
|
+
const raw = this.getAttribute("toolbar");
|
|
382
|
+
let tokens;
|
|
383
|
+
if (raw === null) {
|
|
384
|
+
tokens = [...index.ARK_WYSIWYG_DEFAULT_TOOLBAR];
|
|
385
|
+
}
|
|
386
|
+
else if (raw === "none" || raw === "false" || raw.trim() === "") {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
else if (raw.trim() === "all") {
|
|
390
|
+
tokens = Object.keys(index.ARK_WYSIWYG_TOOLBAR_GROUPS);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
tokens = raw.split(",").map((token) => token.trim());
|
|
394
|
+
}
|
|
395
|
+
const segments = [];
|
|
396
|
+
const push = (group, items) => {
|
|
397
|
+
const last = segments[segments.length - 1];
|
|
398
|
+
if (last && last.group === group) {
|
|
399
|
+
last.items.push(...items);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
segments.push({ group, items: [...items] });
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
for (const token of tokens) {
|
|
406
|
+
if (token in index.ARK_WYSIWYG_TOOLBAR_GROUPS) {
|
|
407
|
+
const group = token;
|
|
408
|
+
push(group, index.ARK_WYSIWYG_TOOLBAR_GROUPS[group]);
|
|
409
|
+
}
|
|
410
|
+
else if (ALL_ITEMS.has(token) || token in ACTIONS) {
|
|
411
|
+
const item = token;
|
|
412
|
+
push(groupOf(item), [item]);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const result = segments
|
|
416
|
+
.map((segment) => ({
|
|
417
|
+
group: segment.group,
|
|
418
|
+
items: segment.items.filter((item) => (item === "image" || item === "video" ? this.uploader !== null : true))
|
|
419
|
+
}))
|
|
420
|
+
.filter((segment) => segment.items.length > 0);
|
|
421
|
+
return result.length > 0 ? result : false;
|
|
422
|
+
}
|
|
423
|
+
build() {
|
|
424
|
+
this.teardown();
|
|
425
|
+
this.labels = this.resolveLabels();
|
|
426
|
+
const root = document.createElement("div");
|
|
427
|
+
root.className = "ark-wysiwyg";
|
|
428
|
+
const segments = this.getToolbar();
|
|
429
|
+
if (segments) {
|
|
430
|
+
this.toolbarEl = this.buildToolbar(segments);
|
|
431
|
+
root.appendChild(this.toolbarEl);
|
|
432
|
+
}
|
|
433
|
+
const mount = document.createElement("div");
|
|
434
|
+
mount.className = "ark-wysiwyg__content";
|
|
435
|
+
root.appendChild(mount);
|
|
436
|
+
this.appendChild(root);
|
|
437
|
+
this.root = root;
|
|
438
|
+
this.instance = index$1.createWysiwygEditor(mount, {
|
|
439
|
+
content: this.pendingContent,
|
|
440
|
+
theme: this.getTheme(),
|
|
441
|
+
placeholder: this.getAttribute("placeholder") || undefined,
|
|
442
|
+
label: this.getAttribute("aria-label") || undefined,
|
|
443
|
+
editable: this.isEditable(),
|
|
444
|
+
uploadFile: this.uploader ?? undefined,
|
|
445
|
+
maxFileSize: this.getMaxFileSize(),
|
|
446
|
+
onChange: (content) => {
|
|
447
|
+
this.dispatchEvent(new CustomEvent("ark-wysiwyg-change", {
|
|
448
|
+
detail: content,
|
|
449
|
+
bubbles: true,
|
|
450
|
+
composed: true
|
|
451
|
+
}));
|
|
452
|
+
this.syncToolbar();
|
|
453
|
+
},
|
|
454
|
+
onUploadError: (error) => {
|
|
455
|
+
this.dispatchEvent(new CustomEvent("ark-wysiwyg-upload-error", { detail: error, bubbles: true, composed: true }));
|
|
456
|
+
},
|
|
457
|
+
onUploadingChange: (count) => {
|
|
458
|
+
this.root?.toggleAttribute("aria-busy", count > 0);
|
|
459
|
+
this.root?.setAttribute("data-uploading", String(count));
|
|
460
|
+
this.syncToolbar();
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
this.instance.editor.on("selectionUpdate", this.syncToolbar);
|
|
464
|
+
this.instance.editor.on("transaction", this.syncToolbar);
|
|
465
|
+
this.syncToolbar();
|
|
466
|
+
this.root.setAttribute("data-ark-theme", this.instance.resolvedTheme());
|
|
467
|
+
this.applyHooks();
|
|
468
|
+
this.syncThemeObserver();
|
|
469
|
+
}
|
|
470
|
+
// Raiz, toolbar e conteúdo editável levam os hooks de E2E, como os componentes de @tooark/web-components.
|
|
471
|
+
applyHooks() {
|
|
472
|
+
if (!this.root || !this.instance)
|
|
473
|
+
return;
|
|
474
|
+
testHooks.applyTestHooks(this, "wysiwyg-editor", this.root);
|
|
475
|
+
if (this.toolbarEl)
|
|
476
|
+
testHooks.applyTestHooks(this, "wysiwyg-editor", this.toolbarEl, "toolbar");
|
|
477
|
+
testHooks.applyTestHooks(this, "wysiwyg-editor", this.instance.editor.view.dom, "content");
|
|
478
|
+
}
|
|
479
|
+
// Em `auto`, a troca de tema da página re-resolve o tema do editor; com tema fixo não há o que observar.
|
|
480
|
+
syncThemeObserver() {
|
|
481
|
+
this.disposeTheme?.();
|
|
482
|
+
this.disposeTheme = null;
|
|
483
|
+
if (this.getTheme() !== "auto")
|
|
484
|
+
return;
|
|
485
|
+
this.disposeTheme = tokens.observeColorScheme(this, () => this.applyTheme("auto"));
|
|
486
|
+
}
|
|
487
|
+
// O engine marca o mount com data-ark-theme; o CSS do tema lê a raiz .ark-wysiwyg, então ela recebe o mesmo.
|
|
488
|
+
applyTheme(theme) {
|
|
489
|
+
if (!this.instance)
|
|
490
|
+
return;
|
|
491
|
+
this.instance.setTheme(theme);
|
|
492
|
+
this.root?.setAttribute("data-ark-theme", this.instance.resolvedTheme());
|
|
493
|
+
}
|
|
494
|
+
// --- Toolbar ---
|
|
495
|
+
buildToolbar(segments) {
|
|
496
|
+
const toolbar = document.createElement("div");
|
|
497
|
+
toolbar.className = "ark-wysiwyg__toolbar";
|
|
498
|
+
toolbar.setAttribute("part", "toolbar");
|
|
499
|
+
toolbar.setAttribute("role", "toolbar");
|
|
500
|
+
toolbar.addEventListener("keydown", this.handleToolbarKeydown);
|
|
501
|
+
toolbar.addEventListener("focusin", this.handleToolbarFocus);
|
|
502
|
+
this.controls = [];
|
|
503
|
+
this.syncers = [];
|
|
504
|
+
segments.forEach((segment, index) => {
|
|
505
|
+
if (index > 0) {
|
|
506
|
+
const separator = document.createElement("span");
|
|
507
|
+
separator.className = "ark-wysiwyg__separator";
|
|
508
|
+
separator.setAttribute("role", "separator");
|
|
509
|
+
separator.setAttribute("aria-orientation", "vertical");
|
|
510
|
+
toolbar.appendChild(separator);
|
|
511
|
+
}
|
|
512
|
+
const group = document.createElement("div");
|
|
513
|
+
group.className = "ark-wysiwyg__group";
|
|
514
|
+
group.setAttribute("data-group", segment.group);
|
|
515
|
+
for (const item of segment.items)
|
|
516
|
+
group.appendChild(this.buildItem(item));
|
|
517
|
+
toolbar.appendChild(group);
|
|
518
|
+
});
|
|
519
|
+
if (this.controls.length > 0)
|
|
520
|
+
this.controls[0].tabIndex = 0;
|
|
521
|
+
return toolbar;
|
|
522
|
+
}
|
|
523
|
+
buildItem(item) {
|
|
524
|
+
if (item === "heading")
|
|
525
|
+
return this.buildHeadingSelect();
|
|
526
|
+
if (item === "text-color")
|
|
527
|
+
return this.buildPalette("text-color");
|
|
528
|
+
if (item === "highlight")
|
|
529
|
+
return this.buildPalette("highlight");
|
|
530
|
+
if (item === "link")
|
|
531
|
+
return this.buildLink();
|
|
532
|
+
if (item === "image" || item === "video")
|
|
533
|
+
return this.buildFilePicker(item);
|
|
534
|
+
const action = ACTIONS[item];
|
|
535
|
+
const level = item.startsWith("heading-") ? item.slice(-1) : "";
|
|
536
|
+
const label = level ? `${this.labels.heading} ${level}` : this.labels[action.label];
|
|
537
|
+
const button = this.createButton(label, action.icon);
|
|
538
|
+
if (level) {
|
|
539
|
+
button.textContent = `H${level}`;
|
|
540
|
+
button.classList.add("ark-wysiwyg__btn--text");
|
|
541
|
+
}
|
|
542
|
+
button.addEventListener("click", () => {
|
|
543
|
+
if (!this.instance)
|
|
544
|
+
return;
|
|
545
|
+
action.run(this.instance.editor);
|
|
546
|
+
this.syncToolbar();
|
|
547
|
+
});
|
|
548
|
+
this.syncers.push(() => {
|
|
549
|
+
if (!this.instance)
|
|
550
|
+
return;
|
|
551
|
+
const editor = this.instance.editor;
|
|
552
|
+
if (action.active)
|
|
553
|
+
button.setAttribute("aria-pressed", String(action.active(editor)));
|
|
554
|
+
button.disabled = !editor.isEditable || (action.can ? !action.can(editor) : false);
|
|
555
|
+
});
|
|
556
|
+
return button;
|
|
557
|
+
}
|
|
558
|
+
createButton(label, icon) {
|
|
559
|
+
const button = document.createElement("button");
|
|
560
|
+
button.type = "button";
|
|
561
|
+
button.className = "ark-wysiwyg__btn";
|
|
562
|
+
button.innerHTML = icons.ICONS[icon];
|
|
563
|
+
button.title = label;
|
|
564
|
+
button.setAttribute("aria-label", label);
|
|
565
|
+
button.tabIndex = -1;
|
|
566
|
+
// No mouse o botão não rouba o foco do editor (padrão de toolbar de editor): a seleção continua visível e o
|
|
567
|
+
// comando aplica sobre ela sem vai-e-volta de foco. O focus() do Tiptap só devolve o foco no próximo frame, e
|
|
568
|
+
// um Enter digitado nesse intervalo acionava o botão em vez de chegar ao editor. Teclado entra pelo Tab.
|
|
569
|
+
button.addEventListener("mousedown", (event) => event.preventDefault());
|
|
570
|
+
button.addEventListener("click", () => this.setCurrent(button));
|
|
571
|
+
this.controls.push(button);
|
|
572
|
+
return button;
|
|
573
|
+
}
|
|
574
|
+
// Estilo do bloco: um <select> nativo (teclado e leitor de tela de graça) mostrando o estilo atual.
|
|
575
|
+
buildHeadingSelect() {
|
|
576
|
+
const select = document.createElement("select");
|
|
577
|
+
select.className = "ark-wysiwyg__select";
|
|
578
|
+
select.setAttribute("aria-label", this.labels.textStyle);
|
|
579
|
+
select.title = this.labels.textStyle;
|
|
580
|
+
select.tabIndex = -1;
|
|
581
|
+
const normal = document.createElement("option");
|
|
582
|
+
normal.value = "paragraph";
|
|
583
|
+
normal.textContent = this.labels.paragraph;
|
|
584
|
+
select.appendChild(normal);
|
|
585
|
+
for (const level of index$1.HEADING_LEVELS) {
|
|
586
|
+
const option = document.createElement("option");
|
|
587
|
+
option.value = String(level);
|
|
588
|
+
option.textContent = `${this.labels.heading} ${level}`;
|
|
589
|
+
select.appendChild(option);
|
|
590
|
+
}
|
|
591
|
+
select.addEventListener("change", () => {
|
|
592
|
+
if (!this.instance)
|
|
593
|
+
return;
|
|
594
|
+
const chain = this.instance.editor.chain().focus();
|
|
595
|
+
if (select.value === "paragraph") {
|
|
596
|
+
chain.setParagraph().run();
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
chain.setHeading({ level: Number(select.value) }).run();
|
|
600
|
+
}
|
|
601
|
+
this.syncToolbar();
|
|
602
|
+
});
|
|
603
|
+
this.controls.push(select);
|
|
604
|
+
this.syncers.push(() => {
|
|
605
|
+
if (!this.instance)
|
|
606
|
+
return;
|
|
607
|
+
const editor = this.instance.editor;
|
|
608
|
+
const level = index$1.HEADING_LEVELS.find((candidate) => editor.isActive("heading", { level: candidate }));
|
|
609
|
+
const value = level ? String(level) : "paragraph";
|
|
610
|
+
if (select.value !== value)
|
|
611
|
+
select.value = value;
|
|
612
|
+
select.disabled = !editor.isEditable;
|
|
613
|
+
});
|
|
614
|
+
return select;
|
|
615
|
+
}
|
|
616
|
+
// Cor do texto e marca-texto: botão com a cor atual na barra e uma paleta em popover (light dismiss nativo).
|
|
617
|
+
buildPalette(item) {
|
|
618
|
+
const isText = item === "text-color";
|
|
619
|
+
const wrap = document.createElement("span");
|
|
620
|
+
wrap.className = "ark-wysiwyg__item";
|
|
621
|
+
const button = this.createButton(isText ? this.labels.textColor : this.labels.highlight, isText ? "textColor" : "highlight");
|
|
622
|
+
button.classList.add("ark-wysiwyg__btn--swatch");
|
|
623
|
+
const popover = this.createPopover();
|
|
624
|
+
button.setAttribute("popovertarget", popover.id);
|
|
625
|
+
button.setAttribute("aria-haspopup", "true");
|
|
626
|
+
const grid = document.createElement("div");
|
|
627
|
+
grid.className = "ark-wysiwyg__swatches";
|
|
628
|
+
grid.setAttribute("role", "group");
|
|
629
|
+
grid.setAttribute("aria-label", button.title);
|
|
630
|
+
const apply = (color) => {
|
|
631
|
+
if (!this.instance)
|
|
632
|
+
return;
|
|
633
|
+
const chain = this.instance.editor.chain().focus();
|
|
634
|
+
if (isText) {
|
|
635
|
+
(color ? chain.setColor(color) : chain.unsetColor()).run();
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
(color ? chain.setHighlight({ color }) : chain.unsetHighlight()).run();
|
|
639
|
+
}
|
|
640
|
+
popover.hidePopover();
|
|
641
|
+
this.syncToolbar();
|
|
642
|
+
};
|
|
643
|
+
for (const color of isText ? this.colors : this.highlights) {
|
|
644
|
+
const swatch = document.createElement("button");
|
|
645
|
+
swatch.type = "button";
|
|
646
|
+
swatch.className = "ark-wysiwyg__swatch";
|
|
647
|
+
swatch.style.backgroundColor = color;
|
|
648
|
+
swatch.title = color;
|
|
649
|
+
swatch.setAttribute("aria-label", color);
|
|
650
|
+
swatch.addEventListener("click", () => apply(color));
|
|
651
|
+
grid.appendChild(swatch);
|
|
652
|
+
}
|
|
653
|
+
const none = document.createElement("button");
|
|
654
|
+
none.type = "button";
|
|
655
|
+
none.className = "ark-wysiwyg__swatch ark-wysiwyg__swatch--none";
|
|
656
|
+
none.innerHTML = icons.ICONS.none;
|
|
657
|
+
none.title = this.labels.noColor;
|
|
658
|
+
none.setAttribute("aria-label", this.labels.noColor);
|
|
659
|
+
none.addEventListener("click", () => apply(null));
|
|
660
|
+
grid.appendChild(none);
|
|
661
|
+
popover.appendChild(grid);
|
|
662
|
+
wrap.append(button, popover);
|
|
663
|
+
this.syncers.push(() => {
|
|
664
|
+
if (!this.instance)
|
|
665
|
+
return;
|
|
666
|
+
const editor = this.instance.editor;
|
|
667
|
+
const current = isText ? editor.getAttributes("textStyle").color : editor.getAttributes("highlight").color;
|
|
668
|
+
button.style.setProperty("--ark-wysiwyg-swatch", security.isSafeColor(current) ? current : "transparent");
|
|
669
|
+
button.setAttribute("aria-pressed", String(security.isSafeColor(current)));
|
|
670
|
+
button.disabled = !editor.isEditable;
|
|
671
|
+
});
|
|
672
|
+
return wrap;
|
|
673
|
+
}
|
|
674
|
+
// Link: popover com campo de URL; aplica na seleção (ou insere a URL) e recusa esquemas fora da lista.
|
|
675
|
+
buildLink() {
|
|
676
|
+
const wrap = document.createElement("span");
|
|
677
|
+
wrap.className = "ark-wysiwyg__item";
|
|
678
|
+
const button = this.createButton(this.labels.link, "link");
|
|
679
|
+
const popover = this.createPopover();
|
|
680
|
+
popover.classList.add("ark-wysiwyg__popover--link");
|
|
681
|
+
button.setAttribute("popovertarget", popover.id);
|
|
682
|
+
button.setAttribute("aria-haspopup", "dialog");
|
|
683
|
+
const form = document.createElement("form");
|
|
684
|
+
form.className = "ark-wysiwyg__link";
|
|
685
|
+
const input = document.createElement("input");
|
|
686
|
+
input.type = "text";
|
|
687
|
+
input.inputMode = "url";
|
|
688
|
+
input.setAttribute("autocomplete", "url");
|
|
689
|
+
input.className = "ark-wysiwyg__input";
|
|
690
|
+
input.placeholder = "https://";
|
|
691
|
+
input.setAttribute("aria-label", this.labels.linkUrl);
|
|
692
|
+
const error = document.createElement("p");
|
|
693
|
+
error.className = "ark-wysiwyg__error";
|
|
694
|
+
error.id = `${popover.id}-error`;
|
|
695
|
+
error.hidden = true;
|
|
696
|
+
error.textContent = this.labels.invalidUrl;
|
|
697
|
+
const applyBtn = document.createElement("button");
|
|
698
|
+
applyBtn.type = "submit";
|
|
699
|
+
applyBtn.className = "ark-wysiwyg__btn ark-wysiwyg__btn--text";
|
|
700
|
+
applyBtn.textContent = this.labels.apply;
|
|
701
|
+
const removeBtn = document.createElement("button");
|
|
702
|
+
removeBtn.type = "button";
|
|
703
|
+
removeBtn.className = "ark-wysiwyg__btn ark-wysiwyg__btn--text";
|
|
704
|
+
removeBtn.textContent = this.labels.remove;
|
|
705
|
+
form.addEventListener("submit", (event) => {
|
|
706
|
+
event.preventDefault();
|
|
707
|
+
if (!this.instance)
|
|
708
|
+
return;
|
|
709
|
+
const ok = this.instance.setLink(input.value);
|
|
710
|
+
error.hidden = ok;
|
|
711
|
+
input.setAttribute("aria-invalid", ok ? "false" : "true");
|
|
712
|
+
if (ok) {
|
|
713
|
+
input.removeAttribute("aria-describedby");
|
|
714
|
+
popover.hidePopover();
|
|
715
|
+
this.syncToolbar();
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
input.setAttribute("aria-describedby", error.id);
|
|
719
|
+
input.focus();
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
removeBtn.addEventListener("click", () => {
|
|
723
|
+
this.instance?.unsetLink();
|
|
724
|
+
popover.hidePopover();
|
|
725
|
+
this.syncToolbar();
|
|
726
|
+
});
|
|
727
|
+
popover.addEventListener("toggle", (event) => {
|
|
728
|
+
if (event.newState !== "open" || !this.instance)
|
|
729
|
+
return;
|
|
730
|
+
const href = this.instance.editor.getAttributes("link").href;
|
|
731
|
+
input.value = typeof href === "string" ? href : "";
|
|
732
|
+
error.hidden = true;
|
|
733
|
+
input.removeAttribute("aria-invalid");
|
|
734
|
+
input.removeAttribute("aria-describedby");
|
|
735
|
+
removeBtn.hidden = !this.instance.editor.isActive("link");
|
|
736
|
+
input.focus();
|
|
737
|
+
input.select();
|
|
738
|
+
});
|
|
739
|
+
form.append(input, applyBtn, removeBtn);
|
|
740
|
+
popover.append(form, error);
|
|
741
|
+
wrap.append(button, popover);
|
|
742
|
+
this.syncers.push(() => {
|
|
743
|
+
if (!this.instance)
|
|
744
|
+
return;
|
|
745
|
+
const editor = this.instance.editor;
|
|
746
|
+
button.setAttribute("aria-pressed", String(editor.isActive("link")));
|
|
747
|
+
button.disabled = !editor.isEditable;
|
|
748
|
+
});
|
|
749
|
+
return wrap;
|
|
750
|
+
}
|
|
751
|
+
// Imagem e vídeo: input de arquivo oculto; o envio é do gancho `uploadFile`, o editor só insere a URL.
|
|
752
|
+
buildFilePicker(item) {
|
|
753
|
+
const wrap = document.createElement("span");
|
|
754
|
+
wrap.className = "ark-wysiwyg__item";
|
|
755
|
+
const label = item === "image" ? this.labels.image : this.labels.video;
|
|
756
|
+
const button = this.createButton(label, item === "image" ? "image" : "video");
|
|
757
|
+
const input = document.createElement("input");
|
|
758
|
+
input.type = "file";
|
|
759
|
+
input.accept = `${item}/*`;
|
|
760
|
+
input.hidden = true;
|
|
761
|
+
input.tabIndex = -1;
|
|
762
|
+
input.setAttribute("aria-hidden", "true");
|
|
763
|
+
input.addEventListener("change", () => {
|
|
764
|
+
const file = input.files?.[0];
|
|
765
|
+
input.value = "";
|
|
766
|
+
if (file)
|
|
767
|
+
void this.insertFile(file);
|
|
768
|
+
});
|
|
769
|
+
button.addEventListener("click", () => input.click());
|
|
770
|
+
wrap.append(button, input);
|
|
771
|
+
this.syncers.push(() => {
|
|
772
|
+
if (!this.instance)
|
|
773
|
+
return;
|
|
774
|
+
const busy = this.instance.uploading() > 0;
|
|
775
|
+
button.disabled = !this.instance.editor.isEditable || busy;
|
|
776
|
+
button.title = busy ? `${this.labels.uploading}…` : label;
|
|
777
|
+
});
|
|
778
|
+
return wrap;
|
|
779
|
+
}
|
|
780
|
+
// `popover="auto"` + popovertarget abrem e fecham sem JS (light dismiss nativo); só a posição é calculada aqui.
|
|
781
|
+
createPopover() {
|
|
782
|
+
const popover = document.createElement("div");
|
|
783
|
+
popover.id = `ark-wysiwyg-popover-${++popoverSeq}`;
|
|
784
|
+
popover.className = "ark-wysiwyg__popover";
|
|
785
|
+
popover.setAttribute("popover", "auto");
|
|
786
|
+
popover.addEventListener("toggle", (event) => {
|
|
787
|
+
if (event.newState !== "open")
|
|
788
|
+
return;
|
|
789
|
+
const anchor = this.toolbarEl?.querySelector(`[popovertarget="${popover.id}"]`);
|
|
790
|
+
if (!anchor)
|
|
791
|
+
return;
|
|
792
|
+
const rect = anchor.getBoundingClientRect();
|
|
793
|
+
const width = popover.offsetWidth;
|
|
794
|
+
const height = popover.offsetHeight;
|
|
795
|
+
const maxLeft = Math.max(8, document.documentElement.clientWidth - width - 8);
|
|
796
|
+
const below = rect.bottom + 4;
|
|
797
|
+
const top = below + height > document.documentElement.clientHeight - 8 ? Math.max(8, rect.top - height - 4) : below;
|
|
798
|
+
popover.style.left = `${Math.round(Math.min(Math.max(8, rect.left), maxLeft))}px`;
|
|
799
|
+
popover.style.top = `${Math.round(top)}px`;
|
|
800
|
+
});
|
|
801
|
+
return popover;
|
|
802
|
+
}
|
|
803
|
+
setCurrent(control) {
|
|
804
|
+
for (const candidate of this.controls)
|
|
805
|
+
candidate.tabIndex = candidate === control ? 0 : -1;
|
|
806
|
+
}
|
|
807
|
+
teardown() {
|
|
808
|
+
this.disposeTheme?.();
|
|
809
|
+
this.disposeTheme = null;
|
|
810
|
+
if (this.instance) {
|
|
811
|
+
// Reconstruir (toolbar, rótulos, paletas, gancho) ou mover o nó no DOM não pode perder o que foi digitado.
|
|
812
|
+
this.pendingContent = this.instance.getJSON();
|
|
813
|
+
this.instance.editor.off("selectionUpdate", this.syncToolbar);
|
|
814
|
+
this.instance.editor.off("transaction", this.syncToolbar);
|
|
815
|
+
this.instance.destroy();
|
|
816
|
+
this.instance = null;
|
|
817
|
+
}
|
|
818
|
+
this.controls = [];
|
|
819
|
+
this.syncers = [];
|
|
820
|
+
this.toolbarEl = null;
|
|
821
|
+
if (this.root) {
|
|
822
|
+
this.root.remove();
|
|
823
|
+
this.root = null;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
ArkWysiwygEditor.tagName = "ark-wysiwyg-editor";
|
|
828
|
+
|
|
829
|
+
exports.ArkWysiwygEditor = ArkWysiwygEditor;
|
|
830
|
+
//# sourceMappingURL=ark-wysiwyg-editor.cjs.map
|