@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,278 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@tiptap/core');
|
|
4
|
+
var extensionHighlight = require('@tiptap/extension-highlight');
|
|
5
|
+
var extensionImage = require('@tiptap/extension-image');
|
|
6
|
+
var Placeholder = require('@tiptap/extension-placeholder');
|
|
7
|
+
var extensionTextAlign = require('@tiptap/extension-text-align');
|
|
8
|
+
var extensionTextStyle = require('@tiptap/extension-text-style');
|
|
9
|
+
var StarterKit = require('@tiptap/starter-kit');
|
|
10
|
+
var tokens = require('@tooark/tokens');
|
|
11
|
+
var security = require('../security.cjs');
|
|
12
|
+
|
|
13
|
+
/** Documento vazio do ProseMirror (um parágrafo). */
|
|
14
|
+
const EMPTY_DOC = { type: "doc", content: [{ type: "paragraph" }] };
|
|
15
|
+
/** Tamanho máximo de arquivo aceito por padrão (10 MiB). */
|
|
16
|
+
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
17
|
+
/** Níveis de título disponíveis no editor. */
|
|
18
|
+
const HEADING_LEVELS = [1, 2, 3, 4];
|
|
19
|
+
/** Resolve "auto" para "light"/"dark" pelo color-scheme computado de `element`, ou pela preferência do sistema. */
|
|
20
|
+
function resolveWysiwygTheme(theme, element) {
|
|
21
|
+
if (theme === "dark")
|
|
22
|
+
return "dark";
|
|
23
|
+
if (theme === "light")
|
|
24
|
+
return "light";
|
|
25
|
+
return tokens.resolveColorScheme(element);
|
|
26
|
+
}
|
|
27
|
+
function applyTheme(element, theme) {
|
|
28
|
+
element.setAttribute("data-ark-theme", theme);
|
|
29
|
+
}
|
|
30
|
+
/** Vídeo externo como bloco atômico: `src` (e `poster`) apontam para fora, nunca para base64. */
|
|
31
|
+
const Video = core.Node.create({
|
|
32
|
+
name: "video",
|
|
33
|
+
group: "block",
|
|
34
|
+
atom: true,
|
|
35
|
+
draggable: true,
|
|
36
|
+
selectable: true,
|
|
37
|
+
addAttributes() {
|
|
38
|
+
return {
|
|
39
|
+
src: { default: null },
|
|
40
|
+
// HTML colado: um poster fora da lista de permissão cai, o vídeo fica.
|
|
41
|
+
poster: {
|
|
42
|
+
default: null,
|
|
43
|
+
parseHTML: (element) => {
|
|
44
|
+
const poster = element.getAttribute("poster");
|
|
45
|
+
return security.isSafeUrl(poster) ? poster : null;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
title: { default: null }
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
parseHTML() {
|
|
52
|
+
// HTML colado: só vira nó com src permitido (nada de data:/blob:, que a sanitização do JSON também barra).
|
|
53
|
+
return [{ tag: "video[src]", getAttrs: (element) => (security.isSafeUrl(element.getAttribute("src")) ? null : false) }];
|
|
54
|
+
},
|
|
55
|
+
renderHTML({ HTMLAttributes }) {
|
|
56
|
+
return ["video", core.mergeAttributes({ controls: "true", preload: "metadata" }, HTMLAttributes)];
|
|
57
|
+
},
|
|
58
|
+
addCommands() {
|
|
59
|
+
return {
|
|
60
|
+
setVideo: (attrs) => ({ commands }) => commands.insertContent({ type: this.name, attrs })
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
/** Imagem do Tiptap que, no HTML colado, só vira nó com src permitido (o padrão só barra data:, não blob:). */
|
|
65
|
+
const SafeImage = extensionImage.Image.extend({
|
|
66
|
+
parseHTML() {
|
|
67
|
+
return [{ tag: "img[src]", getAttrs: (element) => (security.isSafeUrl(element.getAttribute("src")) ? null : false) }];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// --- Extensões compartilhadas ---
|
|
71
|
+
/**
|
|
72
|
+
* Extensões do editor e do viewer (o mesmo schema nos dois, senão o conteúdo salvo não renderiza): StarterKit
|
|
73
|
+
* (títulos 1-4, sublinhado e link com URL validada), cor de texto, marca-texto, alinhamento, imagem sem base64
|
|
74
|
+
* e vídeo externo. Em `editable` o link não abre no clique (o clique edita); no viewer abre em nova aba.
|
|
75
|
+
*/
|
|
76
|
+
function createWysiwygExtensions(options) {
|
|
77
|
+
const extensions = [
|
|
78
|
+
StarterKit.configure({
|
|
79
|
+
heading: { levels: [...HEADING_LEVELS] },
|
|
80
|
+
link: {
|
|
81
|
+
openOnClick: !options.editable,
|
|
82
|
+
autolink: true,
|
|
83
|
+
linkOnPaste: true,
|
|
84
|
+
// A lista de permissão do pacote vale para o que o usuário digita, cola ou autolinka; um host sem
|
|
85
|
+
// esquema ("exemplo.com") passa aqui porque o autolink grava o href já com http.
|
|
86
|
+
isAllowedUri: (url) => security.isSafeUrl(url) || security.looksLikeHostname(url),
|
|
87
|
+
HTMLAttributes: { target: "_blank", rel: "noopener noreferrer nofollow" }
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
extensionTextStyle.TextStyle,
|
|
91
|
+
extensionTextStyle.Color,
|
|
92
|
+
extensionHighlight.Highlight.configure({ multicolor: true }),
|
|
93
|
+
extensionTextAlign.TextAlign.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right", "justify"] }),
|
|
94
|
+
SafeImage.configure({ allowBase64: false, inline: false }),
|
|
95
|
+
Video
|
|
96
|
+
];
|
|
97
|
+
if (options.placeholder) {
|
|
98
|
+
extensions.push(Placeholder.configure({ placeholder: options.placeholder }));
|
|
99
|
+
}
|
|
100
|
+
return extensions;
|
|
101
|
+
}
|
|
102
|
+
function kindOf(file) {
|
|
103
|
+
if (file.type.startsWith("image/"))
|
|
104
|
+
return "image";
|
|
105
|
+
if (file.type.startsWith("video/"))
|
|
106
|
+
return "video";
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function filesOf(list) {
|
|
110
|
+
return Array.from(list ?? []);
|
|
111
|
+
}
|
|
112
|
+
function createInstance(element, options) {
|
|
113
|
+
let resolved = resolveWysiwygTheme(options.theme, element);
|
|
114
|
+
let applying = false;
|
|
115
|
+
let uploading = 0;
|
|
116
|
+
const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;
|
|
117
|
+
const fail = (reason, file, error) => {
|
|
118
|
+
options.onUploadError?.({ reason, file, error });
|
|
119
|
+
return false;
|
|
120
|
+
};
|
|
121
|
+
// Arquivos colados ou arrastados só entram pelo gancho; sem ele são consumidos (nada de base64 no JSON). Os que
|
|
122
|
+
// não são imagem nem vídeo são recusados com o motivo (insertFile emite unsupported-type), em vez de sumir.
|
|
123
|
+
const handleFiles = (files, position) => {
|
|
124
|
+
if (files.length === 0)
|
|
125
|
+
return false;
|
|
126
|
+
for (const file of files)
|
|
127
|
+
void insertFile(file, position);
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
130
|
+
const editor = new core.Editor({
|
|
131
|
+
element,
|
|
132
|
+
editable: options.editable,
|
|
133
|
+
extensions: createWysiwygExtensions({ editable: options.editable, placeholder: options.placeholder }),
|
|
134
|
+
content: EMPTY_DOC,
|
|
135
|
+
editorProps: {
|
|
136
|
+
// O Tiptap já põe role="textbox" no conteúdo editável; o nome acessível vai junto, só quando o app dá um.
|
|
137
|
+
...(options.label ? { attributes: { "aria-label": options.label } } : {}),
|
|
138
|
+
handlePaste: (_view, event) => {
|
|
139
|
+
const files = filesOf(event.clipboardData?.files);
|
|
140
|
+
// Planilhas e editores copiam o texto junto de arquivos que não são mídia: aí o texto vence e cola normal.
|
|
141
|
+
const hasText = Array.from(event.clipboardData?.types ?? []).some((type) => type.startsWith("text/"));
|
|
142
|
+
if (hasText && !files.some((file) => kindOf(file)))
|
|
143
|
+
return false;
|
|
144
|
+
return handleFiles(files);
|
|
145
|
+
},
|
|
146
|
+
handleDrop: (view, event, _slice, moved) => {
|
|
147
|
+
if (moved)
|
|
148
|
+
return false;
|
|
149
|
+
const at = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
150
|
+
return handleFiles(filesOf(event.dataTransfer?.files), at?.pos);
|
|
151
|
+
},
|
|
152
|
+
// HTML colado com <img>/<video> só vira nó quando há gancho: sem ele, seria um hotlink que o app não controla.
|
|
153
|
+
transformPastedHTML: (html) => (options.uploadFile ? html : html.replace(/<(img|video|source)\b[^>]*>/gi, ""))
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const setContent = (content) => {
|
|
157
|
+
applying = true;
|
|
158
|
+
try {
|
|
159
|
+
// Fora do histórico: Ctrl+Z depois de o app trocar o conteúdo não pode voltar ao documento anterior.
|
|
160
|
+
editor
|
|
161
|
+
.chain()
|
|
162
|
+
.setMeta("addToHistory", false)
|
|
163
|
+
.setContent(security.sanitizeWysiwygContent(content, editor.schema) ?? EMPTY_DOC, { emitUpdate: false })
|
|
164
|
+
.run();
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
applying = false;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
if (options.content)
|
|
171
|
+
setContent(options.content);
|
|
172
|
+
if (options.onChange) {
|
|
173
|
+
editor.on("update", () => {
|
|
174
|
+
if (!applying)
|
|
175
|
+
options.onChange?.(editor.getJSON());
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const setUploading = (next) => {
|
|
179
|
+
uploading = next;
|
|
180
|
+
options.onUploadingChange?.(next);
|
|
181
|
+
};
|
|
182
|
+
const insertFile = async (file, position) => {
|
|
183
|
+
const kind = kindOf(file);
|
|
184
|
+
if (!kind)
|
|
185
|
+
return fail("unsupported-type", file);
|
|
186
|
+
if (!options.uploadFile)
|
|
187
|
+
return fail("no-uploader", file);
|
|
188
|
+
if (file.size > maxFileSize)
|
|
189
|
+
return fail("too-large", file);
|
|
190
|
+
const at = position ?? editor.state.selection.to;
|
|
191
|
+
setUploading(uploading + 1);
|
|
192
|
+
try {
|
|
193
|
+
const result = await options.uploadFile(file, kind);
|
|
194
|
+
if (!result || !security.isSafeUrl(result.src))
|
|
195
|
+
return fail("invalid-src", file);
|
|
196
|
+
if (editor.isDestroyed)
|
|
197
|
+
return false;
|
|
198
|
+
const pos = Math.min(at, editor.state.doc.content.size);
|
|
199
|
+
const attrs = kind === "image"
|
|
200
|
+
? { src: result.src, alt: result.alt ?? file.name, title: result.title ?? null }
|
|
201
|
+
: { src: result.src, poster: security.isSafeUrl(result.poster) ? result.poster : null, title: result.title ?? null };
|
|
202
|
+
editor.chain().focus().insertContentAt(pos, { type: kind, attrs }).run();
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
return fail("failed", file, error);
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
setUploading(uploading - 1);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
applyTheme(element, resolved);
|
|
213
|
+
return {
|
|
214
|
+
editor,
|
|
215
|
+
getJSON: () => editor.getJSON(),
|
|
216
|
+
setContent,
|
|
217
|
+
isActive: (name, attrs) => editor.isActive(name, attrs),
|
|
218
|
+
setEditable: (editable) => editor.setEditable(editable),
|
|
219
|
+
setTheme: (theme) => {
|
|
220
|
+
resolved = resolveWysiwygTheme(theme, element);
|
|
221
|
+
applyTheme(element, resolved);
|
|
222
|
+
},
|
|
223
|
+
resolvedTheme: () => resolved,
|
|
224
|
+
insertFile,
|
|
225
|
+
uploading: () => uploading,
|
|
226
|
+
setLink: (raw) => {
|
|
227
|
+
const trimmed = raw.trim();
|
|
228
|
+
const href = security.looksLikeHostname(trimmed) && !/^[a-z][a-z0-9+.-]*:/i.test(trimmed) ? `https://${trimmed}` : trimmed;
|
|
229
|
+
if (!security.isSafeUrl(href))
|
|
230
|
+
return false;
|
|
231
|
+
const chain = editor.chain().focus().extendMarkRange("link");
|
|
232
|
+
if (editor.state.selection.empty && !editor.isActive("link")) {
|
|
233
|
+
chain.insertContent({ type: "text", text: href, marks: [{ type: "link", attrs: { href } }] }).run();
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
chain.setLink({ href }).run();
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
},
|
|
240
|
+
unsetLink: () => {
|
|
241
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
242
|
+
},
|
|
243
|
+
destroy: () => editor.destroy()
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/** Cria um editor WYSIWYG (editável) dentro de `element`. */
|
|
247
|
+
function createWysiwygEditor(element, options = {}) {
|
|
248
|
+
return createInstance(element, {
|
|
249
|
+
content: options.content,
|
|
250
|
+
theme: options.theme,
|
|
251
|
+
placeholder: options.placeholder,
|
|
252
|
+
label: options.label,
|
|
253
|
+
editable: options.editable ?? true,
|
|
254
|
+
uploadFile: options.uploadFile,
|
|
255
|
+
maxFileSize: options.maxFileSize,
|
|
256
|
+
onChange: options.onChange,
|
|
257
|
+
onUploadError: options.onUploadError,
|
|
258
|
+
onUploadingChange: options.onUploadingChange
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/** Cria um viewer (somente leitura) que renderiza o mesmo JSON do editor. */
|
|
262
|
+
function createWysiwygViewer(element, options = {}) {
|
|
263
|
+
return createInstance(element, {
|
|
264
|
+
content: options.content,
|
|
265
|
+
theme: options.theme,
|
|
266
|
+
editable: false
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
exports.DEFAULT_MAX_FILE_SIZE = DEFAULT_MAX_FILE_SIZE;
|
|
271
|
+
exports.EMPTY_DOC = EMPTY_DOC;
|
|
272
|
+
exports.HEADING_LEVELS = HEADING_LEVELS;
|
|
273
|
+
exports.Video = Video;
|
|
274
|
+
exports.createWysiwygEditor = createWysiwygEditor;
|
|
275
|
+
exports.createWysiwygExtensions = createWysiwygExtensions;
|
|
276
|
+
exports.createWysiwygViewer = createWysiwygViewer;
|
|
277
|
+
exports.resolveWysiwygTheme = resolveWysiwygTheme;
|
|
278
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/engine/index.ts"],"sourcesContent":["import type { Extensions, JSONContent } from \"@tiptap/core\";\nimport { Editor, mergeAttributes, Node } from \"@tiptap/core\";\nimport { Highlight } from \"@tiptap/extension-highlight\";\nimport { Image } from \"@tiptap/extension-image\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { TextAlign } from \"@tiptap/extension-text-align\";\nimport { Color, TextStyle } from \"@tiptap/extension-text-style\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport { type ArkThemeSelected, resolveColorScheme } from \"@tooark/tokens\";\nimport { isSafeUrl, looksLikeHostname, sanitizeWysiwygContent } from \"../security\";\nimport type {\n ArkWysiwygEditorOptions,\n ArkWysiwygTheme,\n ArkWysiwygUploadError,\n ArkWysiwygUploadKind,\n ArkWysiwygViewerOptions\n} from \"../types\";\n\n/** Documento vazio do ProseMirror (um parágrafo). */\nexport const EMPTY_DOC: JSONContent = { type: \"doc\", content: [{ type: \"paragraph\" }] };\n\n/** Tamanho máximo de arquivo aceito por padrão (10 MiB). */\nexport const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;\n\n/** Níveis de título disponíveis no editor. */\nexport const HEADING_LEVELS = [1, 2, 3, 4] as const;\n\nexport type ArkWysiwygInstance = {\n /** Instância nativa do Tiptap (uso avançado: comandos, eventos, etc.). */\n readonly editor: Editor;\n /** Conteúdo atual como JSON do Tiptap. */\n getJSON(): JSONContent;\n /** Substitui o conteúdo (sanitizado) sem disparar `onChange`. `null` limpa para um documento vazio. */\n setContent(content: JSONContent | null): void;\n /** Indica se uma mark/node está ativo na seleção (ex.: \"bold\", \"heading\"). */\n isActive(name: string, attrs?: Record<string, unknown>): boolean;\n /** Habilita/desabilita a edição. */\n setEditable(editable: boolean): void;\n /** Troca o tema (aplica data-attribute no elemento host). */\n setTheme(theme: ArkWysiwygTheme): void;\n /** Tema efetivamente aplicado (após resolver \"auto\"). */\n resolvedTheme(): ArkThemeSelected;\n /** Envia um arquivo pelo gancho de upload e insere a imagem/vídeo na posição dada (padrão: seleção). */\n insertFile(file: File, position?: number): Promise<boolean>;\n /** Uploads em andamento. */\n uploading(): number;\n /** Aplica um link à seleção (ou insere a URL como texto linkado); `false` se a URL é recusada. */\n setLink(href: string): boolean;\n /** Remove o link da seleção. */\n unsetLink(): void;\n /** Libera a instância do Tiptap. */\n destroy(): void;\n};\n\n/** Resolve \"auto\" para \"light\"/\"dark\" pelo color-scheme computado de `element`, ou pela preferência do sistema. */\nexport function resolveWysiwygTheme(theme: ArkWysiwygTheme | undefined, element?: Element | null): ArkThemeSelected {\n if (theme === \"dark\") return \"dark\";\n if (theme === \"light\") return \"light\";\n return resolveColorScheme(element);\n}\n\nfunction applyTheme(element: HTMLElement, theme: ArkThemeSelected): void {\n element.setAttribute(\"data-ark-theme\", theme);\n}\n\n// --- Nó de vídeo ---\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n video: {\n /** Insere um vídeo externo (`<video controls>`). */\n setVideo: (attrs: { src: string; poster?: string | null; title?: string | null }) => ReturnType;\n };\n }\n}\n\n/** Vídeo externo como bloco atômico: `src` (e `poster`) apontam para fora, nunca para base64. */\nexport const Video = Node.create({\n name: \"video\",\n group: \"block\",\n atom: true,\n draggable: true,\n selectable: true,\n\n addAttributes() {\n return {\n src: { default: null },\n // HTML colado: um poster fora da lista de permissão cai, o vídeo fica.\n poster: {\n default: null,\n parseHTML: (element) => {\n const poster = element.getAttribute(\"poster\");\n return isSafeUrl(poster) ? poster : null;\n }\n },\n title: { default: null }\n };\n },\n\n parseHTML() {\n // HTML colado: só vira nó com src permitido (nada de data:/blob:, que a sanitização do JSON também barra).\n return [{ tag: \"video[src]\", getAttrs: (element) => (isSafeUrl(element.getAttribute(\"src\")) ? null : false) }];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\"video\", mergeAttributes({ controls: \"true\", preload: \"metadata\" }, HTMLAttributes)];\n },\n\n addCommands() {\n return {\n setVideo:\n (attrs) =>\n ({ commands }) =>\n commands.insertContent({ type: this.name, attrs })\n };\n }\n});\n\n/** Imagem do Tiptap que, no HTML colado, só vira nó com src permitido (o padrão só barra data:, não blob:). */\nconst SafeImage = Image.extend({\n parseHTML() {\n return [{ tag: \"img[src]\", getAttrs: (element) => (isSafeUrl(element.getAttribute(\"src\")) ? null : false) }];\n }\n});\n\n// --- Extensões compartilhadas ---\n\n/**\n * Extensões do editor e do viewer (o mesmo schema nos dois, senão o conteúdo salvo não renderiza): StarterKit\n * (títulos 1-4, sublinhado e link com URL validada), cor de texto, marca-texto, alinhamento, imagem sem base64\n * e vídeo externo. Em `editable` o link não abre no clique (o clique edita); no viewer abre em nova aba.\n */\nexport function createWysiwygExtensions(options: { editable: boolean; placeholder?: string }): Extensions {\n const extensions: Extensions = [\n StarterKit.configure({\n heading: { levels: [...HEADING_LEVELS] },\n link: {\n openOnClick: !options.editable,\n autolink: true,\n linkOnPaste: true,\n // A lista de permissão do pacote vale para o que o usuário digita, cola ou autolinka; um host sem\n // esquema (\"exemplo.com\") passa aqui porque o autolink grava o href já com http.\n isAllowedUri: (url) => isSafeUrl(url) || looksLikeHostname(url),\n HTMLAttributes: { target: \"_blank\", rel: \"noopener noreferrer nofollow\" }\n }\n }),\n TextStyle,\n Color,\n Highlight.configure({ multicolor: true }),\n TextAlign.configure({ types: [\"heading\", \"paragraph\"], alignments: [\"left\", \"center\", \"right\", \"justify\"] }),\n SafeImage.configure({ allowBase64: false, inline: false }),\n Video\n ];\n if (options.placeholder) {\n extensions.push(Placeholder.configure({ placeholder: options.placeholder }));\n }\n return extensions;\n}\n\n// --- Instância ---\n\ntype InternalOptions = {\n content?: JSONContent | null;\n theme?: ArkWysiwygTheme;\n placeholder?: string;\n label?: string;\n editable: boolean;\n uploadFile?: ArkWysiwygEditorOptions[\"uploadFile\"];\n maxFileSize?: number;\n onChange?: (content: JSONContent) => void;\n onUploadError?: (error: ArkWysiwygUploadError) => void;\n onUploadingChange?: (count: number) => void;\n};\n\nfunction kindOf(file: File): ArkWysiwygUploadKind | null {\n if (file.type.startsWith(\"image/\")) return \"image\";\n if (file.type.startsWith(\"video/\")) return \"video\";\n return null;\n}\n\nfunction filesOf(list: FileList | null | undefined): File[] {\n return Array.from(list ?? []);\n}\n\nfunction createInstance(element: HTMLElement, options: InternalOptions): ArkWysiwygInstance {\n let resolved = resolveWysiwygTheme(options.theme, element);\n let applying = false;\n let uploading = 0;\n\n const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;\n const fail = (reason: ArkWysiwygUploadError[\"reason\"], file: File, error?: unknown): false => {\n options.onUploadError?.({ reason, file, error });\n return false;\n };\n\n // Arquivos colados ou arrastados só entram pelo gancho; sem ele são consumidos (nada de base64 no JSON). Os que\n // não são imagem nem vídeo são recusados com o motivo (insertFile emite unsupported-type), em vez de sumir.\n const handleFiles = (files: File[], position?: number): boolean => {\n if (files.length === 0) return false;\n for (const file of files) void insertFile(file, position);\n return true;\n };\n\n const editor = new Editor({\n element,\n editable: options.editable,\n extensions: createWysiwygExtensions({ editable: options.editable, placeholder: options.placeholder }),\n content: EMPTY_DOC,\n editorProps: {\n // O Tiptap já põe role=\"textbox\" no conteúdo editável; o nome acessível vai junto, só quando o app dá um.\n ...(options.label ? { attributes: { \"aria-label\": options.label } } : {}),\n handlePaste: (_view, event) => {\n const files = filesOf(event.clipboardData?.files);\n // Planilhas e editores copiam o texto junto de arquivos que não são mídia: aí o texto vence e cola normal.\n const hasText = Array.from(event.clipboardData?.types ?? []).some((type) => type.startsWith(\"text/\"));\n if (hasText && !files.some((file) => kindOf(file))) return false;\n return handleFiles(files);\n },\n handleDrop: (view, event, _slice, moved) => {\n if (moved) return false;\n const at = view.posAtCoords({ left: event.clientX, top: event.clientY });\n return handleFiles(filesOf(event.dataTransfer?.files), at?.pos);\n },\n // HTML colado com <img>/<video> só vira nó quando há gancho: sem ele, seria um hotlink que o app não controla.\n transformPastedHTML: (html) => (options.uploadFile ? html : html.replace(/<(img|video|source)\\b[^>]*>/gi, \"\"))\n }\n });\n\n const setContent = (content: JSONContent | null): void => {\n applying = true;\n try {\n // Fora do histórico: Ctrl+Z depois de o app trocar o conteúdo não pode voltar ao documento anterior.\n editor\n .chain()\n .setMeta(\"addToHistory\", false)\n .setContent(sanitizeWysiwygContent(content, editor.schema) ?? EMPTY_DOC, { emitUpdate: false })\n .run();\n } finally {\n applying = false;\n }\n };\n if (options.content) setContent(options.content);\n\n if (options.onChange) {\n editor.on(\"update\", () => {\n if (!applying) options.onChange?.(editor.getJSON());\n });\n }\n\n const setUploading = (next: number): void => {\n uploading = next;\n options.onUploadingChange?.(next);\n };\n\n const insertFile = async (file: File, position?: number): Promise<boolean> => {\n const kind = kindOf(file);\n if (!kind) return fail(\"unsupported-type\", file);\n if (!options.uploadFile) return fail(\"no-uploader\", file);\n if (file.size > maxFileSize) return fail(\"too-large\", file);\n\n const at = position ?? editor.state.selection.to;\n setUploading(uploading + 1);\n try {\n const result = await options.uploadFile(file, kind);\n if (!result || !isSafeUrl(result.src)) return fail(\"invalid-src\", file);\n if (editor.isDestroyed) return false;\n const pos = Math.min(at, editor.state.doc.content.size);\n const attrs =\n kind === \"image\"\n ? { src: result.src, alt: result.alt ?? file.name, title: result.title ?? null }\n : { src: result.src, poster: isSafeUrl(result.poster) ? result.poster : null, title: result.title ?? null };\n editor.chain().focus().insertContentAt(pos, { type: kind, attrs }).run();\n return true;\n } catch (error) {\n return fail(\"failed\", file, error);\n } finally {\n setUploading(uploading - 1);\n }\n };\n\n applyTheme(element, resolved);\n\n return {\n editor,\n getJSON: () => editor.getJSON(),\n setContent,\n isActive: (name, attrs) => editor.isActive(name, attrs),\n setEditable: (editable) => editor.setEditable(editable),\n setTheme: (theme) => {\n resolved = resolveWysiwygTheme(theme, element);\n applyTheme(element, resolved);\n },\n resolvedTheme: () => resolved,\n insertFile,\n uploading: () => uploading,\n setLink: (raw) => {\n const trimmed = raw.trim();\n const href = looksLikeHostname(trimmed) && !/^[a-z][a-z0-9+.-]*:/i.test(trimmed) ? `https://${trimmed}` : trimmed;\n if (!isSafeUrl(href)) return false;\n const chain = editor.chain().focus().extendMarkRange(\"link\");\n if (editor.state.selection.empty && !editor.isActive(\"link\")) {\n chain.insertContent({ type: \"text\", text: href, marks: [{ type: \"link\", attrs: { href } }] }).run();\n } else {\n chain.setLink({ href }).run();\n }\n return true;\n },\n unsetLink: () => {\n editor.chain().focus().extendMarkRange(\"link\").unsetLink().run();\n },\n destroy: () => editor.destroy()\n };\n}\n\n/** Cria um editor WYSIWYG (editável) dentro de `element`. */\nexport function createWysiwygEditor(element: HTMLElement, options: ArkWysiwygEditorOptions = {}): ArkWysiwygInstance {\n return createInstance(element, {\n content: options.content,\n theme: options.theme,\n placeholder: options.placeholder,\n label: options.label,\n editable: options.editable ?? true,\n uploadFile: options.uploadFile,\n maxFileSize: options.maxFileSize,\n onChange: options.onChange,\n onUploadError: options.onUploadError,\n onUploadingChange: options.onUploadingChange\n });\n}\n\n/** Cria um viewer (somente leitura) que renderiza o mesmo JSON do editor. */\nexport function createWysiwygViewer(element: HTMLElement, options: ArkWysiwygViewerOptions = {}): ArkWysiwygInstance {\n return createInstance(element, {\n content: options.content,\n theme: options.theme,\n editable: false\n });\n}\n"],"names":["resolveColorScheme","Node","isSafeUrl","mergeAttributes","Image","looksLikeHostname","TextStyle","Color","Highlight","TextAlign","Editor","sanitizeWysiwygContent"],"mappings":";;;;;;;;;;;;AAkBA;AACO,MAAM,SAAS,GAAgB,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAErF;MACa,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG;AAEjD;AACO,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAA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AE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,iBAAiB,EAAE,OAAO,CAAC;AAC5B,KAAA,CAAC;AACJ;AAEA;SACgB,mBAAmB,CAAC,OAAoB,EAAE,UAAmC,EAAE,EAAA;IAC7F,OAAO,cAAc,CAAC,OAAO,EAAE;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;AACpB,QAAA,QAAQ,EAAE;AACX,KAAA,CAAC;AACJ;;;;;;;;;"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Node, mergeAttributes, Editor } from '@tiptap/core';
|
|
2
|
+
import { Highlight } from '@tiptap/extension-highlight';
|
|
3
|
+
import { Image } from '@tiptap/extension-image';
|
|
4
|
+
import Placeholder from '@tiptap/extension-placeholder';
|
|
5
|
+
import { TextAlign } from '@tiptap/extension-text-align';
|
|
6
|
+
import { TextStyle, Color } from '@tiptap/extension-text-style';
|
|
7
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
8
|
+
import { resolveColorScheme } from '@tooark/tokens';
|
|
9
|
+
import { isSafeUrl, looksLikeHostname, sanitizeWysiwygContent } from '../security.js';
|
|
10
|
+
|
|
11
|
+
/** Documento vazio do ProseMirror (um parágrafo). */
|
|
12
|
+
const EMPTY_DOC = { type: "doc", content: [{ type: "paragraph" }] };
|
|
13
|
+
/** Tamanho máximo de arquivo aceito por padrão (10 MiB). */
|
|
14
|
+
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
15
|
+
/** Níveis de título disponíveis no editor. */
|
|
16
|
+
const HEADING_LEVELS = [1, 2, 3, 4];
|
|
17
|
+
/** Resolve "auto" para "light"/"dark" pelo color-scheme computado de `element`, ou pela preferência do sistema. */
|
|
18
|
+
function resolveWysiwygTheme(theme, element) {
|
|
19
|
+
if (theme === "dark")
|
|
20
|
+
return "dark";
|
|
21
|
+
if (theme === "light")
|
|
22
|
+
return "light";
|
|
23
|
+
return resolveColorScheme(element);
|
|
24
|
+
}
|
|
25
|
+
function applyTheme(element, theme) {
|
|
26
|
+
element.setAttribute("data-ark-theme", theme);
|
|
27
|
+
}
|
|
28
|
+
/** Vídeo externo como bloco atômico: `src` (e `poster`) apontam para fora, nunca para base64. */
|
|
29
|
+
const Video = Node.create({
|
|
30
|
+
name: "video",
|
|
31
|
+
group: "block",
|
|
32
|
+
atom: true,
|
|
33
|
+
draggable: true,
|
|
34
|
+
selectable: true,
|
|
35
|
+
addAttributes() {
|
|
36
|
+
return {
|
|
37
|
+
src: { default: null },
|
|
38
|
+
// HTML colado: um poster fora da lista de permissão cai, o vídeo fica.
|
|
39
|
+
poster: {
|
|
40
|
+
default: null,
|
|
41
|
+
parseHTML: (element) => {
|
|
42
|
+
const poster = element.getAttribute("poster");
|
|
43
|
+
return isSafeUrl(poster) ? poster : null;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
title: { default: null }
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
parseHTML() {
|
|
50
|
+
// HTML colado: só vira nó com src permitido (nada de data:/blob:, que a sanitização do JSON também barra).
|
|
51
|
+
return [{ tag: "video[src]", getAttrs: (element) => (isSafeUrl(element.getAttribute("src")) ? null : false) }];
|
|
52
|
+
},
|
|
53
|
+
renderHTML({ HTMLAttributes }) {
|
|
54
|
+
return ["video", mergeAttributes({ controls: "true", preload: "metadata" }, HTMLAttributes)];
|
|
55
|
+
},
|
|
56
|
+
addCommands() {
|
|
57
|
+
return {
|
|
58
|
+
setVideo: (attrs) => ({ commands }) => commands.insertContent({ type: this.name, attrs })
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
/** Imagem do Tiptap que, no HTML colado, só vira nó com src permitido (o padrão só barra data:, não blob:). */
|
|
63
|
+
const SafeImage = Image.extend({
|
|
64
|
+
parseHTML() {
|
|
65
|
+
return [{ tag: "img[src]", getAttrs: (element) => (isSafeUrl(element.getAttribute("src")) ? null : false) }];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
// --- Extensões compartilhadas ---
|
|
69
|
+
/**
|
|
70
|
+
* Extensões do editor e do viewer (o mesmo schema nos dois, senão o conteúdo salvo não renderiza): StarterKit
|
|
71
|
+
* (títulos 1-4, sublinhado e link com URL validada), cor de texto, marca-texto, alinhamento, imagem sem base64
|
|
72
|
+
* e vídeo externo. Em `editable` o link não abre no clique (o clique edita); no viewer abre em nova aba.
|
|
73
|
+
*/
|
|
74
|
+
function createWysiwygExtensions(options) {
|
|
75
|
+
const extensions = [
|
|
76
|
+
StarterKit.configure({
|
|
77
|
+
heading: { levels: [...HEADING_LEVELS] },
|
|
78
|
+
link: {
|
|
79
|
+
openOnClick: !options.editable,
|
|
80
|
+
autolink: true,
|
|
81
|
+
linkOnPaste: true,
|
|
82
|
+
// A lista de permissão do pacote vale para o que o usuário digita, cola ou autolinka; um host sem
|
|
83
|
+
// esquema ("exemplo.com") passa aqui porque o autolink grava o href já com http.
|
|
84
|
+
isAllowedUri: (url) => isSafeUrl(url) || looksLikeHostname(url),
|
|
85
|
+
HTMLAttributes: { target: "_blank", rel: "noopener noreferrer nofollow" }
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
TextStyle,
|
|
89
|
+
Color,
|
|
90
|
+
Highlight.configure({ multicolor: true }),
|
|
91
|
+
TextAlign.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right", "justify"] }),
|
|
92
|
+
SafeImage.configure({ allowBase64: false, inline: false }),
|
|
93
|
+
Video
|
|
94
|
+
];
|
|
95
|
+
if (options.placeholder) {
|
|
96
|
+
extensions.push(Placeholder.configure({ placeholder: options.placeholder }));
|
|
97
|
+
}
|
|
98
|
+
return extensions;
|
|
99
|
+
}
|
|
100
|
+
function kindOf(file) {
|
|
101
|
+
if (file.type.startsWith("image/"))
|
|
102
|
+
return "image";
|
|
103
|
+
if (file.type.startsWith("video/"))
|
|
104
|
+
return "video";
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
function filesOf(list) {
|
|
108
|
+
return Array.from(list ?? []);
|
|
109
|
+
}
|
|
110
|
+
function createInstance(element, options) {
|
|
111
|
+
let resolved = resolveWysiwygTheme(options.theme, element);
|
|
112
|
+
let applying = false;
|
|
113
|
+
let uploading = 0;
|
|
114
|
+
const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;
|
|
115
|
+
const fail = (reason, file, error) => {
|
|
116
|
+
options.onUploadError?.({ reason, file, error });
|
|
117
|
+
return false;
|
|
118
|
+
};
|
|
119
|
+
// Arquivos colados ou arrastados só entram pelo gancho; sem ele são consumidos (nada de base64 no JSON). Os que
|
|
120
|
+
// não são imagem nem vídeo são recusados com o motivo (insertFile emite unsupported-type), em vez de sumir.
|
|
121
|
+
const handleFiles = (files, position) => {
|
|
122
|
+
if (files.length === 0)
|
|
123
|
+
return false;
|
|
124
|
+
for (const file of files)
|
|
125
|
+
void insertFile(file, position);
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
const editor = new Editor({
|
|
129
|
+
element,
|
|
130
|
+
editable: options.editable,
|
|
131
|
+
extensions: createWysiwygExtensions({ editable: options.editable, placeholder: options.placeholder }),
|
|
132
|
+
content: EMPTY_DOC,
|
|
133
|
+
editorProps: {
|
|
134
|
+
// O Tiptap já põe role="textbox" no conteúdo editável; o nome acessível vai junto, só quando o app dá um.
|
|
135
|
+
...(options.label ? { attributes: { "aria-label": options.label } } : {}),
|
|
136
|
+
handlePaste: (_view, event) => {
|
|
137
|
+
const files = filesOf(event.clipboardData?.files);
|
|
138
|
+
// Planilhas e editores copiam o texto junto de arquivos que não são mídia: aí o texto vence e cola normal.
|
|
139
|
+
const hasText = Array.from(event.clipboardData?.types ?? []).some((type) => type.startsWith("text/"));
|
|
140
|
+
if (hasText && !files.some((file) => kindOf(file)))
|
|
141
|
+
return false;
|
|
142
|
+
return handleFiles(files);
|
|
143
|
+
},
|
|
144
|
+
handleDrop: (view, event, _slice, moved) => {
|
|
145
|
+
if (moved)
|
|
146
|
+
return false;
|
|
147
|
+
const at = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
148
|
+
return handleFiles(filesOf(event.dataTransfer?.files), at?.pos);
|
|
149
|
+
},
|
|
150
|
+
// HTML colado com <img>/<video> só vira nó quando há gancho: sem ele, seria um hotlink que o app não controla.
|
|
151
|
+
transformPastedHTML: (html) => (options.uploadFile ? html : html.replace(/<(img|video|source)\b[^>]*>/gi, ""))
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const setContent = (content) => {
|
|
155
|
+
applying = true;
|
|
156
|
+
try {
|
|
157
|
+
// Fora do histórico: Ctrl+Z depois de o app trocar o conteúdo não pode voltar ao documento anterior.
|
|
158
|
+
editor
|
|
159
|
+
.chain()
|
|
160
|
+
.setMeta("addToHistory", false)
|
|
161
|
+
.setContent(sanitizeWysiwygContent(content, editor.schema) ?? EMPTY_DOC, { emitUpdate: false })
|
|
162
|
+
.run();
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
applying = false;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
if (options.content)
|
|
169
|
+
setContent(options.content);
|
|
170
|
+
if (options.onChange) {
|
|
171
|
+
editor.on("update", () => {
|
|
172
|
+
if (!applying)
|
|
173
|
+
options.onChange?.(editor.getJSON());
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const setUploading = (next) => {
|
|
177
|
+
uploading = next;
|
|
178
|
+
options.onUploadingChange?.(next);
|
|
179
|
+
};
|
|
180
|
+
const insertFile = async (file, position) => {
|
|
181
|
+
const kind = kindOf(file);
|
|
182
|
+
if (!kind)
|
|
183
|
+
return fail("unsupported-type", file);
|
|
184
|
+
if (!options.uploadFile)
|
|
185
|
+
return fail("no-uploader", file);
|
|
186
|
+
if (file.size > maxFileSize)
|
|
187
|
+
return fail("too-large", file);
|
|
188
|
+
const at = position ?? editor.state.selection.to;
|
|
189
|
+
setUploading(uploading + 1);
|
|
190
|
+
try {
|
|
191
|
+
const result = await options.uploadFile(file, kind);
|
|
192
|
+
if (!result || !isSafeUrl(result.src))
|
|
193
|
+
return fail("invalid-src", file);
|
|
194
|
+
if (editor.isDestroyed)
|
|
195
|
+
return false;
|
|
196
|
+
const pos = Math.min(at, editor.state.doc.content.size);
|
|
197
|
+
const attrs = kind === "image"
|
|
198
|
+
? { src: result.src, alt: result.alt ?? file.name, title: result.title ?? null }
|
|
199
|
+
: { src: result.src, poster: isSafeUrl(result.poster) ? result.poster : null, title: result.title ?? null };
|
|
200
|
+
editor.chain().focus().insertContentAt(pos, { type: kind, attrs }).run();
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
return fail("failed", file, error);
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
setUploading(uploading - 1);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
applyTheme(element, resolved);
|
|
211
|
+
return {
|
|
212
|
+
editor,
|
|
213
|
+
getJSON: () => editor.getJSON(),
|
|
214
|
+
setContent,
|
|
215
|
+
isActive: (name, attrs) => editor.isActive(name, attrs),
|
|
216
|
+
setEditable: (editable) => editor.setEditable(editable),
|
|
217
|
+
setTheme: (theme) => {
|
|
218
|
+
resolved = resolveWysiwygTheme(theme, element);
|
|
219
|
+
applyTheme(element, resolved);
|
|
220
|
+
},
|
|
221
|
+
resolvedTheme: () => resolved,
|
|
222
|
+
insertFile,
|
|
223
|
+
uploading: () => uploading,
|
|
224
|
+
setLink: (raw) => {
|
|
225
|
+
const trimmed = raw.trim();
|
|
226
|
+
const href = looksLikeHostname(trimmed) && !/^[a-z][a-z0-9+.-]*:/i.test(trimmed) ? `https://${trimmed}` : trimmed;
|
|
227
|
+
if (!isSafeUrl(href))
|
|
228
|
+
return false;
|
|
229
|
+
const chain = editor.chain().focus().extendMarkRange("link");
|
|
230
|
+
if (editor.state.selection.empty && !editor.isActive("link")) {
|
|
231
|
+
chain.insertContent({ type: "text", text: href, marks: [{ type: "link", attrs: { href } }] }).run();
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
chain.setLink({ href }).run();
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
unsetLink: () => {
|
|
239
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
240
|
+
},
|
|
241
|
+
destroy: () => editor.destroy()
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** Cria um editor WYSIWYG (editável) dentro de `element`. */
|
|
245
|
+
function createWysiwygEditor(element, options = {}) {
|
|
246
|
+
return createInstance(element, {
|
|
247
|
+
content: options.content,
|
|
248
|
+
theme: options.theme,
|
|
249
|
+
placeholder: options.placeholder,
|
|
250
|
+
label: options.label,
|
|
251
|
+
editable: options.editable ?? true,
|
|
252
|
+
uploadFile: options.uploadFile,
|
|
253
|
+
maxFileSize: options.maxFileSize,
|
|
254
|
+
onChange: options.onChange,
|
|
255
|
+
onUploadError: options.onUploadError,
|
|
256
|
+
onUploadingChange: options.onUploadingChange
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/** Cria um viewer (somente leitura) que renderiza o mesmo JSON do editor. */
|
|
260
|
+
function createWysiwygViewer(element, options = {}) {
|
|
261
|
+
return createInstance(element, {
|
|
262
|
+
content: options.content,
|
|
263
|
+
theme: options.theme,
|
|
264
|
+
editable: false
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export { DEFAULT_MAX_FILE_SIZE, EMPTY_DOC, HEADING_LEVELS, Video, createWysiwygEditor, createWysiwygExtensions, createWysiwygViewer, resolveWysiwygTheme };
|
|
269
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/engine/index.ts"],"sourcesContent":["import type { Extensions, JSONContent } from \"@tiptap/core\";\nimport { Editor, mergeAttributes, Node } from \"@tiptap/core\";\nimport { Highlight } from \"@tiptap/extension-highlight\";\nimport { Image } from \"@tiptap/extension-image\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { TextAlign } from \"@tiptap/extension-text-align\";\nimport { Color, TextStyle } from \"@tiptap/extension-text-style\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport { type ArkThemeSelected, resolveColorScheme } from \"@tooark/tokens\";\nimport { isSafeUrl, looksLikeHostname, sanitizeWysiwygContent } from \"../security\";\nimport type {\n ArkWysiwygEditorOptions,\n ArkWysiwygTheme,\n ArkWysiwygUploadError,\n ArkWysiwygUploadKind,\n ArkWysiwygViewerOptions\n} from \"../types\";\n\n/** Documento vazio do ProseMirror (um parágrafo). */\nexport const EMPTY_DOC: JSONContent = { type: \"doc\", content: [{ type: \"paragraph\" }] };\n\n/** Tamanho máximo de arquivo aceito por padrão (10 MiB). */\nexport const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;\n\n/** Níveis de título disponíveis no editor. */\nexport const HEADING_LEVELS = [1, 2, 3, 4] as const;\n\nexport type ArkWysiwygInstance = {\n /** Instância nativa do Tiptap (uso avançado: comandos, eventos, etc.). */\n readonly editor: Editor;\n /** Conteúdo atual como JSON do Tiptap. */\n getJSON(): JSONContent;\n /** Substitui o conteúdo (sanitizado) sem disparar `onChange`. `null` limpa para um documento vazio. */\n setContent(content: JSONContent | null): void;\n /** Indica se uma mark/node está ativo na seleção (ex.: \"bold\", \"heading\"). */\n isActive(name: string, attrs?: Record<string, unknown>): boolean;\n /** Habilita/desabilita a edição. */\n setEditable(editable: boolean): void;\n /** Troca o tema (aplica data-attribute no elemento host). */\n setTheme(theme: ArkWysiwygTheme): void;\n /** Tema efetivamente aplicado (após resolver \"auto\"). */\n resolvedTheme(): ArkThemeSelected;\n /** Envia um arquivo pelo gancho de upload e insere a imagem/vídeo na posição dada (padrão: seleção). */\n insertFile(file: File, position?: number): Promise<boolean>;\n /** Uploads em andamento. */\n uploading(): number;\n /** Aplica um link à seleção (ou insere a URL como texto linkado); `false` se a URL é recusada. */\n setLink(href: string): boolean;\n /** Remove o link da seleção. */\n unsetLink(): void;\n /** Libera a instância do Tiptap. */\n destroy(): void;\n};\n\n/** Resolve \"auto\" para \"light\"/\"dark\" pelo color-scheme computado de `element`, ou pela preferência do sistema. */\nexport function resolveWysiwygTheme(theme: ArkWysiwygTheme | undefined, element?: Element | null): ArkThemeSelected {\n if (theme === \"dark\") return \"dark\";\n if (theme === \"light\") return \"light\";\n return resolveColorScheme(element);\n}\n\nfunction applyTheme(element: HTMLElement, theme: ArkThemeSelected): void {\n element.setAttribute(\"data-ark-theme\", theme);\n}\n\n// --- Nó de vídeo ---\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n video: {\n /** Insere um vídeo externo (`<video controls>`). */\n setVideo: (attrs: { src: string; poster?: string | null; title?: string | null }) => ReturnType;\n };\n }\n}\n\n/** Vídeo externo como bloco atômico: `src` (e `poster`) apontam para fora, nunca para base64. */\nexport const Video = Node.create({\n name: \"video\",\n group: \"block\",\n atom: true,\n draggable: true,\n selectable: true,\n\n addAttributes() {\n return {\n src: { default: null },\n // HTML colado: um poster fora da lista de permissão cai, o vídeo fica.\n poster: {\n default: null,\n parseHTML: (element) => {\n const poster = element.getAttribute(\"poster\");\n return isSafeUrl(poster) ? poster : null;\n }\n },\n title: { default: null }\n };\n },\n\n parseHTML() {\n // HTML colado: só vira nó com src permitido (nada de data:/blob:, que a sanitização do JSON também barra).\n return [{ tag: \"video[src]\", getAttrs: (element) => (isSafeUrl(element.getAttribute(\"src\")) ? null : false) }];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\"video\", mergeAttributes({ controls: \"true\", preload: \"metadata\" }, HTMLAttributes)];\n },\n\n addCommands() {\n return {\n setVideo:\n (attrs) =>\n ({ commands }) =>\n commands.insertContent({ type: this.name, attrs })\n };\n }\n});\n\n/** Imagem do Tiptap que, no HTML colado, só vira nó com src permitido (o padrão só barra data:, não blob:). */\nconst SafeImage = Image.extend({\n parseHTML() {\n return [{ tag: \"img[src]\", getAttrs: (element) => (isSafeUrl(element.getAttribute(\"src\")) ? null : false) }];\n }\n});\n\n// --- Extensões compartilhadas ---\n\n/**\n * Extensões do editor e do viewer (o mesmo schema nos dois, senão o conteúdo salvo não renderiza): StarterKit\n * (títulos 1-4, sublinhado e link com URL validada), cor de texto, marca-texto, alinhamento, imagem sem base64\n * e vídeo externo. Em `editable` o link não abre no clique (o clique edita); no viewer abre em nova aba.\n */\nexport function createWysiwygExtensions(options: { editable: boolean; placeholder?: string }): Extensions {\n const extensions: Extensions = [\n StarterKit.configure({\n heading: { levels: [...HEADING_LEVELS] },\n link: {\n openOnClick: !options.editable,\n autolink: true,\n linkOnPaste: true,\n // A lista de permissão do pacote vale para o que o usuário digita, cola ou autolinka; um host sem\n // esquema (\"exemplo.com\") passa aqui porque o autolink grava o href já com http.\n isAllowedUri: (url) => isSafeUrl(url) || looksLikeHostname(url),\n HTMLAttributes: { target: \"_blank\", rel: \"noopener noreferrer nofollow\" }\n }\n }),\n TextStyle,\n Color,\n Highlight.configure({ multicolor: true }),\n TextAlign.configure({ types: [\"heading\", \"paragraph\"], alignments: [\"left\", \"center\", \"right\", \"justify\"] }),\n SafeImage.configure({ allowBase64: false, inline: false }),\n Video\n ];\n if (options.placeholder) {\n extensions.push(Placeholder.configure({ placeholder: options.placeholder }));\n }\n return extensions;\n}\n\n// --- Instância ---\n\ntype InternalOptions = {\n content?: JSONContent | null;\n theme?: ArkWysiwygTheme;\n placeholder?: string;\n label?: string;\n editable: boolean;\n uploadFile?: ArkWysiwygEditorOptions[\"uploadFile\"];\n maxFileSize?: number;\n onChange?: (content: JSONContent) => void;\n onUploadError?: (error: ArkWysiwygUploadError) => void;\n onUploadingChange?: (count: number) => void;\n};\n\nfunction kindOf(file: File): ArkWysiwygUploadKind | null {\n if (file.type.startsWith(\"image/\")) return \"image\";\n if (file.type.startsWith(\"video/\")) return \"video\";\n return null;\n}\n\nfunction filesOf(list: FileList | null | undefined): File[] {\n return Array.from(list ?? []);\n}\n\nfunction createInstance(element: HTMLElement, options: InternalOptions): ArkWysiwygInstance {\n let resolved = resolveWysiwygTheme(options.theme, element);\n let applying = false;\n let uploading = 0;\n\n const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;\n const fail = (reason: ArkWysiwygUploadError[\"reason\"], file: File, error?: unknown): false => {\n options.onUploadError?.({ reason, file, error });\n return false;\n };\n\n // Arquivos colados ou arrastados só entram pelo gancho; sem ele são consumidos (nada de base64 no JSON). Os que\n // não são imagem nem vídeo são recusados com o motivo (insertFile emite unsupported-type), em vez de sumir.\n const handleFiles = (files: File[], position?: number): boolean => {\n if (files.length === 0) return false;\n for (const file of files) void insertFile(file, position);\n return true;\n };\n\n const editor = new Editor({\n element,\n editable: options.editable,\n extensions: createWysiwygExtensions({ editable: options.editable, placeholder: options.placeholder }),\n content: EMPTY_DOC,\n editorProps: {\n // O Tiptap já põe role=\"textbox\" no conteúdo editável; o nome acessível vai junto, só quando o app dá um.\n ...(options.label ? { attributes: { \"aria-label\": options.label } } : {}),\n handlePaste: (_view, event) => {\n const files = filesOf(event.clipboardData?.files);\n // Planilhas e editores copiam o texto junto de arquivos que não são mídia: aí o texto vence e cola normal.\n const hasText = Array.from(event.clipboardData?.types ?? []).some((type) => type.startsWith(\"text/\"));\n if (hasText && !files.some((file) => kindOf(file))) return false;\n return handleFiles(files);\n },\n handleDrop: (view, event, _slice, moved) => {\n if (moved) return false;\n const at = view.posAtCoords({ left: event.clientX, top: event.clientY });\n return handleFiles(filesOf(event.dataTransfer?.files), at?.pos);\n },\n // HTML colado com <img>/<video> só vira nó quando há gancho: sem ele, seria um hotlink que o app não controla.\n transformPastedHTML: (html) => (options.uploadFile ? html : html.replace(/<(img|video|source)\\b[^>]*>/gi, \"\"))\n }\n });\n\n const setContent = (content: JSONContent | null): void => {\n applying = true;\n try {\n // Fora do histórico: Ctrl+Z depois de o app trocar o conteúdo não pode voltar ao documento anterior.\n editor\n .chain()\n .setMeta(\"addToHistory\", false)\n .setContent(sanitizeWysiwygContent(content, editor.schema) ?? EMPTY_DOC, { emitUpdate: false })\n .run();\n } finally {\n applying = false;\n }\n };\n if (options.content) setContent(options.content);\n\n if (options.onChange) {\n editor.on(\"update\", () => {\n if (!applying) options.onChange?.(editor.getJSON());\n });\n }\n\n const setUploading = (next: number): void => {\n uploading = next;\n options.onUploadingChange?.(next);\n };\n\n const insertFile = async (file: File, position?: number): Promise<boolean> => {\n const kind = kindOf(file);\n if (!kind) return fail(\"unsupported-type\", file);\n if (!options.uploadFile) return fail(\"no-uploader\", file);\n if (file.size > maxFileSize) return fail(\"too-large\", file);\n\n const at = position ?? editor.state.selection.to;\n setUploading(uploading + 1);\n try {\n const result = await options.uploadFile(file, kind);\n if (!result || !isSafeUrl(result.src)) return fail(\"invalid-src\", file);\n if (editor.isDestroyed) return false;\n const pos = Math.min(at, editor.state.doc.content.size);\n const attrs =\n kind === \"image\"\n ? { src: result.src, alt: result.alt ?? file.name, title: result.title ?? null }\n : { src: result.src, poster: isSafeUrl(result.poster) ? result.poster : null, title: result.title ?? null };\n editor.chain().focus().insertContentAt(pos, { type: kind, attrs }).run();\n return true;\n } catch (error) {\n return fail(\"failed\", file, error);\n } finally {\n setUploading(uploading - 1);\n }\n };\n\n applyTheme(element, resolved);\n\n return {\n editor,\n getJSON: () => editor.getJSON(),\n setContent,\n isActive: (name, attrs) => editor.isActive(name, attrs),\n setEditable: (editable) => editor.setEditable(editable),\n setTheme: (theme) => {\n resolved = resolveWysiwygTheme(theme, element);\n applyTheme(element, resolved);\n },\n resolvedTheme: () => resolved,\n insertFile,\n uploading: () => uploading,\n setLink: (raw) => {\n const trimmed = raw.trim();\n const href = looksLikeHostname(trimmed) && !/^[a-z][a-z0-9+.-]*:/i.test(trimmed) ? `https://${trimmed}` : trimmed;\n if (!isSafeUrl(href)) return false;\n const chain = editor.chain().focus().extendMarkRange(\"link\");\n if (editor.state.selection.empty && !editor.isActive(\"link\")) {\n chain.insertContent({ type: \"text\", text: href, marks: [{ type: \"link\", attrs: { href } }] }).run();\n } else {\n chain.setLink({ href }).run();\n }\n return true;\n },\n unsetLink: () => {\n editor.chain().focus().extendMarkRange(\"link\").unsetLink().run();\n },\n destroy: () => editor.destroy()\n };\n}\n\n/** Cria um editor WYSIWYG (editável) dentro de `element`. */\nexport function createWysiwygEditor(element: HTMLElement, options: ArkWysiwygEditorOptions = {}): ArkWysiwygInstance {\n return createInstance(element, {\n content: options.content,\n theme: options.theme,\n placeholder: options.placeholder,\n label: options.label,\n editable: options.editable ?? true,\n uploadFile: options.uploadFile,\n maxFileSize: options.maxFileSize,\n onChange: options.onChange,\n onUploadError: options.onUploadError,\n onUploadingChange: options.onUploadingChange\n });\n}\n\n/** Cria um viewer (somente leitura) que renderiza o mesmo JSON do editor. */\nexport function createWysiwygViewer(element: HTMLElement, options: ArkWysiwygViewerOptions = {}): ArkWysiwygInstance {\n return createInstance(element, {\n content: options.content,\n theme: options.theme,\n editable: false\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAkBA;AACO,MAAM,SAAS,GAAgB,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAErF;MACa,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG;AAEjD;AACO,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AA6BzC;AACM,SAAU,mBAAmB,CAAC,KAAkC,EAAE,OAAwB,EAAA;IAC9F,IAAI,KAAK,KAAK,MAAM;AAAE,QAAA,OAAO,MAAM;IACnC,IAAI,KAAK,KAAK,OAAO;AAAE,QAAA,OAAO,OAAO;AACrC,IAAA,OAAO,kBAAkB,CAAC,OAAO,CAAC;AACpC;AAEA,SAAS,UAAU,CAAC,OAAoB,EAAE,KAAuB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