@bettercms-ai/kit 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controls/choice.js +2 -2
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/code.js +1 -1
- package/dist/controls/code.js.map +1 -1
- package/dist/controls/color.js +1 -1
- package/dist/controls/color.js.map +1 -1
- package/dist/controls/date.js +1 -1
- package/dist/controls/date.js.map +1 -1
- package/dist/controls/icon.js +2 -2
- package/dist/controls/icon.js.map +1 -1
- package/dist/controls/location.js +1 -1
- package/dist/controls/location.js.map +1 -1
- package/dist/controls/number.js +16 -4
- package/dist/controls/number.js.map +1 -1
- package/dist/controls/reference.js +3 -3
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/catalog.js +7 -4
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/editor.js +24 -3
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/ops.d.ts +30 -0
- package/dist/controls/rich-text/ops.js +117 -10
- package/dist/controls/rich-text/ops.js.map +1 -1
- package/dist/controls/table/table-editor.js +1 -1
- package/dist/controls/table/table-editor.js.map +1 -1
- package/dist/engine/add-limit.d.ts +18 -0
- package/dist/engine/add-limit.js +36 -0
- package/dist/engine/add-limit.js.map +1 -0
- package/dist/engine/array.d.ts +4 -1
- package/dist/engine/array.js +56 -14
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/field-shell.js +8 -4
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/item-list.d.ts +1 -0
- package/dist/engine/item-list.js +15 -10
- package/dist/engine/item-list.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +3 -0
- package/dist/tokens.css +12 -6
- package/dist/ui/controls.js +9 -9
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/select.js +1 -1
- package/dist/ui/select.js.map +1 -1
- package/package.json +2 -2
|
@@ -24,11 +24,41 @@ export declare function insertBasic(root: HTMLElement, id: BasicId): void;
|
|
|
24
24
|
export declare function liveMarkdown(root: HTMLElement, data: string | null, allows?: (f: RichTextFeature) => boolean): boolean;
|
|
25
25
|
/** `text` typed between backticks becomes inline code. */
|
|
26
26
|
export declare function liveInlineCode(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* RT-030: `**text**` becomes bold and `*text*` / `_text_` italic, run as the closing marker is typed (as
|
|
29
|
+
* `liveInlineCode` is for the backtick), each only where the field accepts the mark. The first closing `*` of a
|
|
30
|
+
* `**bold**` being typed is not an italic (its run starts with another `*`), and `_` inside a word (`snake_case_`)
|
|
31
|
+
* stays as typed. Nothing inside code converts.
|
|
32
|
+
*/
|
|
33
|
+
export declare function liveInlineEmphasis(data: string | null, allows?: (f: RichTextFeature) => boolean): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Tab: nest `li` one level deeper, under the item before it, in a list of the same kind (`ul` / `ol`). The
|
|
36
|
+
* previous item's own nested list of that kind takes it when it has one. False (nothing moves) for the first item:
|
|
37
|
+
* there is no item to nest under.
|
|
38
|
+
*/
|
|
39
|
+
export declare function indentListItem(li: HTMLElement): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Shift+Tab: bring a nested `li` up one level, right after the item that held it. The items after it in its list stay
|
|
42
|
+
* after it, nested under it, so the reading order never changes; an emptied nested list goes. False for an item
|
|
43
|
+
* already at the top level.
|
|
44
|
+
*/
|
|
45
|
+
export declare function outdentListItem(li: HTMLElement): boolean;
|
|
27
46
|
/**
|
|
28
47
|
* HTML with every element the field does not accept turned into what it does: a heading / quote / code block becomes a
|
|
29
48
|
* paragraph, a list becomes one paragraph per item, a mark or link is unwrapped to its text, a divider or image is
|
|
30
49
|
* removed. `dropped` names what was taken out entirely (said to the author, never silent).
|
|
31
50
|
*/
|
|
51
|
+
/**
|
|
52
|
+
* RT-016: HTML from another page as this editor takes it, before `restrictHtml` keeps it to the field. Classes, inline
|
|
53
|
+
* styles and ids are the source page's look, not content: only a link's address is kept. A wrapper that is only styling
|
|
54
|
+
* (a span, a font, Google Docs' `<b style="font-weight:normal">` around a whole paste) is unwrapped to its contents. A
|
|
55
|
+
* picture is taken out when `dropImages` (the field holds images, but a pasted address is not a media-library image);
|
|
56
|
+
* otherwise it is left for `restrictHtml`, which removes it and says so. `images` counts what was taken out here.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pastedHtml(html: string, dropImages: boolean): {
|
|
59
|
+
html: string;
|
|
60
|
+
images: number;
|
|
61
|
+
};
|
|
32
62
|
export declare function restrictHtml(html: string, allows: (f: RichTextFeature) => boolean): {
|
|
33
63
|
html: string;
|
|
34
64
|
dropped: string[];
|
|
@@ -100,7 +100,7 @@ function takeEmptyBlock(root) {
|
|
|
100
100
|
function insertIsland(root, kind, model = defaultModel(kind)) {
|
|
101
101
|
const target = takeEmptyBlock(root);
|
|
102
102
|
const isl = createIsland(kind, model);
|
|
103
|
-
isl.__rtFocus =
|
|
103
|
+
isl.__rtFocus = kind !== "toc";
|
|
104
104
|
target.before(isl);
|
|
105
105
|
const next = target.nextElementSibling;
|
|
106
106
|
if (isWritable(next)) {
|
|
@@ -216,14 +216,93 @@ function liveInlineCode() {
|
|
|
216
216
|
const node = r.startContainer;
|
|
217
217
|
const m = node.data.slice(0, r.startOffset).match(/`([^`\n]+)`$/);
|
|
218
218
|
if (!m) return false;
|
|
219
|
+
wrapTypedRun(s, node, r.startOffset, m[0].length, "code", m[1]);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* RT-030: `**text**` becomes bold and `*text*` / `_text_` italic, run as the closing marker is typed (as
|
|
224
|
+
* `liveInlineCode` is for the backtick), each only where the field accepts the mark. The first closing `*` of a
|
|
225
|
+
* `**bold**` being typed is not an italic (its run starts with another `*`), and `_` inside a word (`snake_case_`)
|
|
226
|
+
* stays as typed. Nothing inside code converts.
|
|
227
|
+
*/
|
|
228
|
+
function liveInlineEmphasis(data, allows = () => true) {
|
|
229
|
+
if (data !== "*" && data !== "_") return false;
|
|
230
|
+
const s = window.getSelection();
|
|
231
|
+
if (!s || !s.rangeCount || !s.isCollapsed) return false;
|
|
232
|
+
const r = s.getRangeAt(0);
|
|
233
|
+
if (r.startContainer.nodeType !== 3 || r.startContainer.parentElement?.closest("code,pre")) return false;
|
|
234
|
+
const node = r.startContainer;
|
|
235
|
+
const before = node.data.slice(0, r.startOffset);
|
|
236
|
+
const bold = data === "*" && allows("bold") ? before.match(/\*\*([^*\n]+)\*\*$/) : null;
|
|
237
|
+
if (bold) {
|
|
238
|
+
wrapTypedRun(s, node, r.startOffset, bold[0].length, "strong", bold[1]);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
if (!allows("italic")) return false;
|
|
242
|
+
const italic = data === "*" ? before.match(/(?:^|[^*])\*([^*\n]+)\*$/) : before.match(/(?:^|[^\w_])_([^_\n]+)_$/);
|
|
243
|
+
if (!italic) return false;
|
|
244
|
+
const run = italic[0].replace(/^[^*_]/, "");
|
|
245
|
+
wrapTypedRun(s, node, r.startOffset, run.length, "em", italic[1]);
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Run `move` and put the caret back where it was. Moving a node takes the selection out of it, and a cloned Range is
|
|
250
|
+
* live too (the DOM moves it to the old parent on removal), so the caret is kept as its plain node and offsets.
|
|
251
|
+
*/
|
|
252
|
+
function keepingCaret(move) {
|
|
253
|
+
const s = window.getSelection();
|
|
254
|
+
const at = s && s.rangeCount && s.anchorNode && s.focusNode ? [
|
|
255
|
+
s.anchorNode,
|
|
256
|
+
s.anchorOffset,
|
|
257
|
+
s.focusNode,
|
|
258
|
+
s.focusOffset
|
|
259
|
+
] : null;
|
|
260
|
+
move();
|
|
261
|
+
if (s && at) s.setBaseAndExtent(at[0], at[1], at[2], at[3]);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Tab: nest `li` one level deeper, under the item before it, in a list of the same kind (`ul` / `ol`). The
|
|
265
|
+
* previous item's own nested list of that kind takes it when it has one. False (nothing moves) for the first item:
|
|
266
|
+
* there is no item to nest under.
|
|
267
|
+
*/
|
|
268
|
+
function indentListItem(li) {
|
|
269
|
+
const list = li.parentElement;
|
|
270
|
+
const prev = li.previousElementSibling;
|
|
271
|
+
if (!list || !/^(UL|OL)$/.test(list.tagName) || !prev || prev.tagName !== "LI") return false;
|
|
272
|
+
keepingCaret(() => {
|
|
273
|
+
const last = prev.lastElementChild;
|
|
274
|
+
(last && last.tagName === list.tagName ? last : prev.appendChild(document.createElement(list.tagName.toLowerCase()))).append(li);
|
|
275
|
+
});
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Shift+Tab: bring a nested `li` up one level, right after the item that held it. The items after it in its list stay
|
|
280
|
+
* after it, nested under it, so the reading order never changes; an emptied nested list goes. False for an item
|
|
281
|
+
* already at the top level.
|
|
282
|
+
*/
|
|
283
|
+
function outdentListItem(li) {
|
|
284
|
+
const list = li.parentElement;
|
|
285
|
+
const parentLi = list?.parentElement;
|
|
286
|
+
if (!list || !/^(UL|OL)$/.test(list.tagName) || !parentLi || parentLi.tagName !== "LI") return false;
|
|
287
|
+
keepingCaret(() => {
|
|
288
|
+
const after = [];
|
|
289
|
+
for (let n = li.nextElementSibling; n; n = n.nextElementSibling) after.push(n);
|
|
290
|
+
if (after.length) (li.lastElementChild && li.lastElementChild.tagName === list.tagName ? li.lastElementChild : li.appendChild(document.createElement(list.tagName.toLowerCase()))).append(...after);
|
|
291
|
+
parentLi.after(li);
|
|
292
|
+
if (!list.children.length) list.remove();
|
|
293
|
+
});
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
/** Replace the `length` characters typed before `end` in `node` with `<tag>text</tag>`, the caret after it. */
|
|
297
|
+
function wrapTypedRun(s, node, end, length, tag, text) {
|
|
219
298
|
const del = document.createRange();
|
|
220
|
-
del.setStart(node,
|
|
221
|
-
del.setEnd(node,
|
|
299
|
+
del.setStart(node, end - length);
|
|
300
|
+
del.setEnd(node, end);
|
|
222
301
|
del.deleteContents();
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
del.insertNode(
|
|
226
|
-
const next =
|
|
302
|
+
const el = document.createElement(tag);
|
|
303
|
+
el.textContent = text;
|
|
304
|
+
del.insertNode(el);
|
|
305
|
+
const next = el.nextSibling;
|
|
227
306
|
if (next && next.nodeType === 3 && next.textContent) {
|
|
228
307
|
const c = document.createRange();
|
|
229
308
|
c.setStart(next, 0);
|
|
@@ -232,10 +311,9 @@ function liveInlineCode() {
|
|
|
232
311
|
s.addRange(c);
|
|
233
312
|
} else {
|
|
234
313
|
const after = document.createTextNode("");
|
|
235
|
-
|
|
314
|
+
el.after(after);
|
|
236
315
|
placeCaret(after);
|
|
237
316
|
}
|
|
238
|
-
return true;
|
|
239
317
|
}
|
|
240
318
|
var MARK_FEATURE = {
|
|
241
319
|
STRONG: "bold",
|
|
@@ -278,6 +356,35 @@ var FEATURE_WORD = {
|
|
|
278
356
|
* paragraph, a list becomes one paragraph per item, a mark or link is unwrapped to its text, a divider or image is
|
|
279
357
|
* removed. `dropped` names what was taken out entirely (said to the author, never silent).
|
|
280
358
|
*/
|
|
359
|
+
/**
|
|
360
|
+
* RT-016: HTML from another page as this editor takes it, before `restrictHtml` keeps it to the field. Classes, inline
|
|
361
|
+
* styles and ids are the source page's look, not content: only a link's address is kept. A wrapper that is only styling
|
|
362
|
+
* (a span, a font, Google Docs' `<b style="font-weight:normal">` around a whole paste) is unwrapped to its contents. A
|
|
363
|
+
* picture is taken out when `dropImages` (the field holds images, but a pasted address is not a media-library image);
|
|
364
|
+
* otherwise it is left for `restrictHtml`, which removes it and says so. `images` counts what was taken out here.
|
|
365
|
+
*/
|
|
366
|
+
function pastedHtml(html, dropImages) {
|
|
367
|
+
const doc = new DOMParser().parseFromString(`<body>${html}</body>`, "text/html");
|
|
368
|
+
doc.body.querySelectorAll("script,style,meta,link,title,iframe,object,embed,form,input,button,textarea,select,noscript,template").forEach((n) => n.remove());
|
|
369
|
+
let images = 0;
|
|
370
|
+
if (dropImages) doc.body.querySelectorAll("picture,figure,img").forEach((n) => {
|
|
371
|
+
if (!n.isConnected) return;
|
|
372
|
+
if (n.tagName === "IMG" || n.querySelector("img")) images++;
|
|
373
|
+
n.remove();
|
|
374
|
+
});
|
|
375
|
+
const unwrap = (el) => el.replaceWith(...Array.from(el.childNodes));
|
|
376
|
+
for (const el of Array.from(doc.body.querySelectorAll("*")).reverse()) {
|
|
377
|
+
if (el.tagName === "SPAN" || el.tagName === "FONT" || (el.tagName === "B" || el.tagName === "STRONG") && /font-weight\s*:\s*(normal|400)/i.test(el.getAttribute("style") ?? "")) {
|
|
378
|
+
unwrap(el);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
for (const a of Array.from(el.attributes)) if (!(el.tagName === "A" && a.name === "href" || el.tagName === "IMG" && (a.name === "src" || a.name === "alt"))) el.removeAttribute(a.name);
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
html: doc.body.innerHTML.trim(),
|
|
385
|
+
images
|
|
386
|
+
};
|
|
387
|
+
}
|
|
281
388
|
function restrictHtml(html, allows) {
|
|
282
389
|
if (!html) return {
|
|
283
390
|
html,
|
|
@@ -317,6 +424,6 @@ function restrictHtml(html, allows) {
|
|
|
317
424
|
};
|
|
318
425
|
}
|
|
319
426
|
//#endregion
|
|
320
|
-
export { duplicateBlock, ensureLineAfter, insertBasic, insertIsland, liveInlineCode, liveMarkdown, moveBlock, restrictHtml, takeEmptyBlock, turnInto };
|
|
427
|
+
export { duplicateBlock, ensureLineAfter, indentListItem, insertBasic, insertIsland, liveInlineCode, liveInlineEmphasis, liveMarkdown, moveBlock, outdentListItem, pastedHtml, restrictHtml, takeEmptyBlock, turnInto };
|
|
321
428
|
|
|
322
429
|
//# sourceMappingURL=ops.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ops.js","names":[],"sources":["../../../src/controls/rich-text/ops.ts"],"sourcesContent":["/**\n * RICH TEXT · pure DOM block operations on the editor surface (V2 HEAD controls/rich-text/ops.ts; no React, no\n * emitting). The editor wraps each one, then serializes and emits the new value.\n */\nimport { closestBlock, cloneModel, createIsland, defaultModel, esc, placeCaret, textBeforeCaret, topBlock, type IslandEl, type IslandKind, type IslandModels } from \"./dom\";\nimport type { RichTextFeature } from \"./codec\";\nimport type { BasicId } from \"./catalog\";\n\nconst emptyP = () => {\n const p = document.createElement(\"p\");\n p.innerHTML = \"<br>\";\n return p;\n};\nconst isWritable = (el: Element | null): el is HTMLElement => !!el && !el.hasAttribute(\"data-rt-island\") && el.tagName !== \"HR\";\n\n/** The writable line after a block, created when the block is last or followed by another rich block. */\nexport function ensureLineAfter(b: Element): HTMLElement {\n const next = b.nextElementSibling;\n if (isWritable(next)) return next;\n const p = emptyP();\n b.after(p);\n return p;\n}\n\nexport function duplicateBlock(b: HTMLElement): HTMLElement {\n let c: HTMLElement;\n if (b.hasAttribute(\"data-rt-island\")) {\n const k = b.getAttribute(\"data-rt-island\") as IslandKind;\n c = createIsland(k, cloneModel(k, (b as IslandEl).__rt as never));\n } else {\n c = b.cloneNode(true) as HTMLElement;\n c.removeAttribute(\"data-hint\");\n }\n b.after(c);\n return c;\n}\n\n/** Moves a block one step, keeping the caret where it was. Returns false at the edge. */\nexport function moveBlock(b: HTMLElement, dir: -1 | 1): boolean {\n const sib = dir < 0 ? b.previousElementSibling : b.nextElementSibling;\n if (!sib) return false;\n const s = window.getSelection();\n // ranges are live (a move collapses them), so keep the raw caret position\n const at = s && s.rangeCount ? { n: s.getRangeAt(0).startContainer, o: s.getRangeAt(0).startOffset } : null;\n const host = document.activeElement as HTMLElement | null;\n if (dir < 0) sib.before(b);\n else sib.after(b);\n if (at && s && b.contains(at.n)) {\n host?.focus({ preventScroll: true });\n const r = document.createRange();\n r.setStart(at.n, Math.min(at.o, at.n.nodeType === 3 ? (at.n as Text).length : at.n.childNodes.length));\n r.collapse(true);\n s.removeAllRanges();\n s.addRange(r);\n }\n return true;\n}\n\n/** Text / Heading / Quote / Code. Returns the new element, or null when nothing changed. */\nexport function turnInto(root: HTMLElement, b: HTMLElement | null, tag: string): HTMLElement | null {\n if (!b || b.parentNode !== root || b.hasAttribute(\"data-rt-island\") || b.tagName === \"HR\") return null;\n if (b.tagName.toLowerCase() === tag) return null;\n const inner =\n b.tagName === \"UL\" || b.tagName === \"OL\"\n ? Array.from(b.children).map((c) => c.innerHTML).join(\"<br>\")\n : b.tagName === \"PRE\"\n ? esc(b.textContent ?? \"\").replace(/\\n/g, \"<br>\")\n : b.innerHTML;\n const n = document.createElement(tag);\n n.innerHTML = tag === \"pre\" ? esc((b.textContent ?? \"\").replace(//g, \"\")) || \"<br>\" : inner || \"<br>\";\n b.replaceWith(n);\n root.focus({ preventScroll: true });\n placeCaret(n);\n return n;\n}\n\n/** An empty paragraph at the caret to build a block from (reuses the current one when it is empty). */\nexport function takeEmptyBlock(root: HTMLElement): HTMLElement {\n const s = window.getSelection();\n const anchor = s && s.rangeCount && root.contains(s.anchorNode) ? s.anchorNode : null;\n const li = anchor ? closestBlock(root, anchor) : null;\n let b = topBlock(root, anchor);\n if (li && li.tagName === \"LI\" && !li.textContent?.trim()) {\n const list = li.parentElement!;\n li.remove();\n if (!list.children.length) {\n const p = emptyP();\n list.replaceWith(p);\n b = p;\n } else b = list;\n }\n root.focus({ preventScroll: true });\n if (b && b.tagName === \"P\" && !b.textContent?.replace(//g, \"\").trim() && !b.querySelector(\"img\")) {\n b.innerHTML = \"<br>\";\n placeCaret(b);\n return b;\n }\n // an empty heading, quote or code line (e.g. \"/\" typed on one) is reused too, so no empty block is left behind\n if (b && /^(H[1-6]|BLOCKQUOTE|PRE)$/.test(b.tagName) && !b.textContent?.replace(//g, \"\").trim()) {\n const p = emptyP();\n b.replaceWith(p);\n placeCaret(p);\n return p;\n }\n const p = emptyP();\n if (b) b.after(p);\n else root.append(p);\n placeCaret(p);\n return p;\n}\n\nexport function insertIsland<K extends IslandKind>(root: HTMLElement, kind: K, model: IslandModels[K] = defaultModel(kind)): IslandEl {\n const target = takeEmptyBlock(root);\n const isl = createIsland(kind, model);\n isl.__rtFocus = true;\n target.before(isl);\n // keep the document tidy: reuse the line that already follows instead of leaving an empty one\n const next = target.nextElementSibling;\n if (isWritable(next)) {\n target.remove();\n placeCaret(next, false);\n } else placeCaret(target);\n return isl;\n}\n\n/** Inserts a basic block at the caret. */\nexport function insertBasic(root: HTMLElement, id: BasicId) {\n switch (id) {\n case \"p\":\n takeEmptyBlock(root);\n return;\n case \"h1\": case \"h2\": case \"h3\": case \"h4\": case \"h5\": case \"h6\":\n turnInto(root, takeEmptyBlock(root), id);\n return;\n case \"quote\":\n turnInto(root, takeEmptyBlock(root), \"blockquote\");\n return;\n case \"code\":\n turnInto(root, takeEmptyBlock(root), \"pre\");\n return;\n case \"ul\": case \"ol\": {\n const t = takeEmptyBlock(root);\n const l = document.createElement(id);\n l.innerHTML = \"<li><br></li>\";\n t.replaceWith(l);\n placeCaret(l.firstElementChild!);\n return;\n }\n case \"hr\": {\n const t = takeEmptyBlock(root);\n t.before(document.createElement(\"hr\"));\n placeCaret(t);\n return;\n }\n case \"image\": case \"table\": case \"pullquote\": case \"takeaways\": case \"callout\": case \"toggle\": case \"video\": case \"file\":\n case \"gallery\": case \"embed\": case \"toc\": case \"columns\": case \"related\": case \"author\":\n insertIsland(root, id);\n return;\n }\n}\n\n/**\n * \"# \", \"> \", \"- \", \"1. \" and \"---\" at the start of a paragraph, each only when the field accepts what it makes.\n * Returns true when it converted.\n */\nexport function liveMarkdown(root: HTMLElement, data: string | null, allows: (f: RichTextFeature) => boolean = () => true): boolean {\n const s = window.getSelection();\n if (!s || !s.rangeCount || !s.isCollapsed) return false;\n const blk = topBlock(root, s.anchorNode);\n if (!blk || blk.tagName !== \"P\") return false;\n const before = textBeforeCaret(blk)?.replace(/ /g, \" \");\n if (before == null) return false;\n if (data === \"-\" && before === \"---\" && (blk.textContent ?? \"\").replace(/ /g, \" \") === \"---\") {\n if (!allows(\"hr\")) return false;\n const p = emptyP();\n blk.replaceWith(document.createElement(\"hr\"), p);\n placeCaret(p);\n return true;\n }\n if (data !== \" \") return false;\n const h = before.match(/^(#{1,6}) $/);\n let tag = h ? `h${h[1].length}` : before === \"> \" ? \"blockquote\" : null;\n let list = before === \"- \" || before === \"* \" ? \"ul\" : /^1[.)] $/.test(before) ? \"ol\" : null;\n if (tag && !allows(tag as RichTextFeature)) tag = null;\n if (list && !allows(list as RichTextFeature)) list = null;\n if (!tag && !list) return false;\n const r = document.createRange();\n r.selectNodeContents(blk);\n r.setEnd(s.anchorNode!, s.anchorOffset);\n r.deleteContents();\n const html = blk.textContent || blk.querySelector(\"img\") ? blk.innerHTML : \"<br>\";\n let target: HTMLElement;\n if (tag) {\n target = document.createElement(tag);\n target.innerHTML = html;\n blk.replaceWith(target);\n } else {\n const l = document.createElement(list!);\n target = document.createElement(\"li\");\n target.innerHTML = html;\n l.append(target);\n blk.replaceWith(l);\n }\n placeCaret(target, false);\n return true;\n}\n\n/** `text` typed between backticks becomes inline code. */\nexport function liveInlineCode(): boolean {\n const s = window.getSelection();\n if (!s || !s.rangeCount || !s.isCollapsed) return false;\n const r = s.getRangeAt(0);\n if (r.startContainer.nodeType !== 3 || r.startContainer.parentElement?.closest(\"code,pre\")) return false;\n const node = r.startContainer as Text;\n const m = node.data.slice(0, r.startOffset).match(/`([^`\\n]+)`$/);\n if (!m) return false;\n const del = document.createRange();\n del.setStart(node, r.startOffset - m[0].length);\n del.setEnd(node, r.startOffset);\n del.deleteContents();\n const code = document.createElement(\"code\");\n code.textContent = m[1];\n del.insertNode(code);\n const next = code.nextSibling;\n if (next && next.nodeType === 3 && next.textContent) {\n const c = document.createRange();\n c.setStart(next, 0);\n c.collapse(true);\n s.removeAllRanges();\n s.addRange(c);\n } else {\n const after = document.createTextNode(\"\");\n code.after(after);\n placeCaret(after);\n }\n return true;\n}\n\n/* ── What a field accepts, applied to HTML that arrives from outside (paste, Markdown) ── */\nconst MARK_FEATURE: Record<string, RichTextFeature> = {\n STRONG: \"bold\", B: \"bold\", EM: \"italic\", I: \"italic\", U: \"underline\", S: \"strike\", STRIKE: \"strike\", DEL: \"strike\", CODE: \"code\", A: \"link\",\n};\nconst BLOCK_FEATURE: Record<string, RichTextFeature> = {\n H1: \"h1\", H2: \"h2\", H3: \"h3\", H4: \"h4\", H5: \"h5\", H6: \"h6\", BLOCKQUOTE: \"blockquote\", UL: \"ul\", OL: \"ol\", PRE: \"pre\", HR: \"hr\", FIGURE: \"image\", IMG: \"image\",\n};\nconst FEATURE_WORD: Partial<Record<RichTextFeature, string>> = {\n image: \"images\", hr: \"dividers\", pre: \"code blocks\", ul: \"bulleted lists\", ol: \"numbered lists\", blockquote: \"quotes\", link: \"links\",\n};\n\n/**\n * HTML with every element the field does not accept turned into what it does: a heading / quote / code block becomes a\n * paragraph, a list becomes one paragraph per item, a mark or link is unwrapped to its text, a divider or image is\n * removed. `dropped` names what was taken out entirely (said to the author, never silent).\n */\nexport function restrictHtml(html: string, allows: (f: RichTextFeature) => boolean): { html: string; dropped: string[] } {\n if (!html) return { html, dropped: [] };\n const doc = new DOMParser().parseFromString(`<body>${html}</body>`, \"text/html\");\n const dropped = new Set<string>();\n const walk = (el: Element) => {\n for (const ch of Array.from(el.children)) {\n walk(ch);\n const mark = MARK_FEATURE[ch.tagName];\n const block = BLOCK_FEATURE[ch.tagName];\n if (mark && !allows(mark)) ch.replaceWith(...Array.from(ch.childNodes));\n else if (block && !allows(block)) {\n if (block === \"hr\" || block === \"image\") {\n dropped.add(FEATURE_WORD[block]!);\n ch.remove();\n } else if (block === \"ul\" || block === \"ol\") {\n const ps = Array.from(ch.children).map((li) => {\n const p = doc.createElement(\"p\");\n p.innerHTML = li.innerHTML;\n return p;\n });\n ch.replaceWith(...ps);\n } else {\n const p = doc.createElement(\"p\");\n p.innerHTML = block === \"pre\" ? esc(ch.textContent ?? \"\").replace(/\\n/g, \"<br>\") : ch.innerHTML;\n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AY,GAAG,MAAM,KAAK,GAAG,UAAU,CAAC;QACjE,IAAI,SAAS,CAAC,OAAO,KAAK,GAAG;IAChC,IAAI,UAAU,QAAQ,UAAU,SAAS;KACvC,QAAQ,IAAI,aAAa,MAAO;KAChC,GAAG,OAAO;IACZ,OAAO,IAAI,UAAU,QAAQ,UAAU,MAAM;KAC3C,MAAM,KAAK,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,KAAK,OAAO;MAC7C,MAAM,IAAI,IAAI,cAAc,GAAG;MAC/B,EAAE,YAAY,GAAG;MACjB,OAAO;KACT,CAAC;KACD,GAAG,YAAY,GAAG,EAAE;IACtB,OAAO;KACL,MAAM,IAAI,IAAI,cAAc,GAAG;KAC/B,EAAE,YAAY,UAAU,QAAQ,IAAI,GAAG,eAAe,EAAE,CAAC,CAAC,QAAQ,OAAO,MAAM,IAAI,GAAG;KACtF,GAAG,YAAY,CAAC;IAClB;GACF;EACF;CACF;CACA,KAAK,IAAI,IAAI;CACb,OAAO;EAAE,MAAM,IAAI,KAAK;EAAW,SAAS,CAAC,GAAG,OAAO;CAAE;AAC3D"}
|
|
1
|
+
{"version":3,"file":"ops.js","names":[],"sources":["../../../src/controls/rich-text/ops.ts"],"sourcesContent":["/**\n * RICH TEXT · pure DOM block operations on the editor surface (V2 HEAD controls/rich-text/ops.ts; no React, no\n * emitting). The editor wraps each one, then serializes and emits the new value.\n */\nimport { closestBlock, cloneModel, createIsland, defaultModel, esc, placeCaret, textBeforeCaret, topBlock, type IslandEl, type IslandKind, type IslandModels } from \"./dom\";\nimport type { RichTextFeature } from \"./codec\";\nimport type { BasicId } from \"./catalog\";\n\nconst emptyP = () => {\n const p = document.createElement(\"p\");\n p.innerHTML = \"<br>\";\n return p;\n};\nconst isWritable = (el: Element | null): el is HTMLElement => !!el && !el.hasAttribute(\"data-rt-island\") && el.tagName !== \"HR\";\n\n/** The writable line after a block, created when the block is last or followed by another rich block. */\nexport function ensureLineAfter(b: Element): HTMLElement {\n const next = b.nextElementSibling;\n if (isWritable(next)) return next;\n const p = emptyP();\n b.after(p);\n return p;\n}\n\nexport function duplicateBlock(b: HTMLElement): HTMLElement {\n let c: HTMLElement;\n if (b.hasAttribute(\"data-rt-island\")) {\n const k = b.getAttribute(\"data-rt-island\") as IslandKind;\n c = createIsland(k, cloneModel(k, (b as IslandEl).__rt as never));\n } else {\n c = b.cloneNode(true) as HTMLElement;\n c.removeAttribute(\"data-hint\");\n }\n b.after(c);\n return c;\n}\n\n/** Moves a block one step, keeping the caret where it was. Returns false at the edge. */\nexport function moveBlock(b: HTMLElement, dir: -1 | 1): boolean {\n const sib = dir < 0 ? b.previousElementSibling : b.nextElementSibling;\n if (!sib) return false;\n const s = window.getSelection();\n // ranges are live (a move collapses them), so keep the raw caret position\n const at = s && s.rangeCount ? { n: s.getRangeAt(0).startContainer, o: s.getRangeAt(0).startOffset } : null;\n const host = document.activeElement as HTMLElement | null;\n if (dir < 0) sib.before(b);\n else sib.after(b);\n if (at && s && b.contains(at.n)) {\n host?.focus({ preventScroll: true });\n const r = document.createRange();\n r.setStart(at.n, Math.min(at.o, at.n.nodeType === 3 ? (at.n as Text).length : at.n.childNodes.length));\n r.collapse(true);\n s.removeAllRanges();\n s.addRange(r);\n }\n return true;\n}\n\n/** Text / Heading / Quote / Code. Returns the new element, or null when nothing changed. */\nexport function turnInto(root: HTMLElement, b: HTMLElement | null, tag: string): HTMLElement | null {\n if (!b || b.parentNode !== root || b.hasAttribute(\"data-rt-island\") || b.tagName === \"HR\") return null;\n if (b.tagName.toLowerCase() === tag) return null;\n const inner =\n b.tagName === \"UL\" || b.tagName === \"OL\"\n ? Array.from(b.children).map((c) => c.innerHTML).join(\"<br>\")\n : b.tagName === \"PRE\"\n ? esc(b.textContent ?? \"\").replace(/\\n/g, \"<br>\")\n : b.innerHTML;\n const n = document.createElement(tag);\n n.innerHTML = tag === \"pre\" ? esc((b.textContent ?? \"\").replace(//g, \"\")) || \"<br>\" : inner || \"<br>\";\n b.replaceWith(n);\n root.focus({ preventScroll: true });\n placeCaret(n);\n return n;\n}\n\n/** An empty paragraph at the caret to build a block from (reuses the current one when it is empty). */\nexport function takeEmptyBlock(root: HTMLElement): HTMLElement {\n const s = window.getSelection();\n const anchor = s && s.rangeCount && root.contains(s.anchorNode) ? s.anchorNode : null;\n const li = anchor ? closestBlock(root, anchor) : null;\n let b = topBlock(root, anchor);\n if (li && li.tagName === \"LI\" && !li.textContent?.trim()) {\n const list = li.parentElement!;\n li.remove();\n if (!list.children.length) {\n const p = emptyP();\n list.replaceWith(p);\n b = p;\n } else b = list;\n }\n root.focus({ preventScroll: true });\n if (b && b.tagName === \"P\" && !b.textContent?.replace(//g, \"\").trim() && !b.querySelector(\"img\")) {\n b.innerHTML = \"<br>\";\n placeCaret(b);\n return b;\n }\n // an empty heading, quote or code line (e.g. \"/\" typed on one) is reused too, so no empty block is left behind\n if (b && /^(H[1-6]|BLOCKQUOTE|PRE)$/.test(b.tagName) && !b.textContent?.replace(//g, \"\").trim()) {\n const p = emptyP();\n b.replaceWith(p);\n placeCaret(p);\n return p;\n }\n const p = emptyP();\n if (b) b.after(p);\n else root.append(p);\n placeCaret(p);\n return p;\n}\n\nexport function insertIsland<K extends IslandKind>(root: HTMLElement, kind: K, model: IslandModels[K] = defaultModel(kind)): IslandEl {\n const target = takeEmptyBlock(root);\n const isl = createIsland(kind, model);\n // A table of contents is built from the headings: nothing in it is typed first, so the caret goes on in the\n // paragraph after it (RP-054: it sat in the title, and the next \"/pull\" was typed into \"In this article\").\n isl.__rtFocus = kind !== \"toc\";\n target.before(isl);\n // keep the document tidy: reuse the line that already follows instead of leaving an empty one\n const next = target.nextElementSibling;\n if (isWritable(next)) {\n target.remove();\n placeCaret(next, false);\n } else placeCaret(target);\n return isl;\n}\n\n/** Inserts a basic block at the caret. */\nexport function insertBasic(root: HTMLElement, id: BasicId) {\n switch (id) {\n case \"p\":\n takeEmptyBlock(root);\n return;\n case \"h1\": case \"h2\": case \"h3\": case \"h4\": case \"h5\": case \"h6\":\n turnInto(root, takeEmptyBlock(root), id);\n return;\n case \"quote\":\n turnInto(root, takeEmptyBlock(root), \"blockquote\");\n return;\n case \"code\":\n turnInto(root, takeEmptyBlock(root), \"pre\");\n return;\n case \"ul\": case \"ol\": {\n const t = takeEmptyBlock(root);\n const l = document.createElement(id);\n l.innerHTML = \"<li><br></li>\";\n t.replaceWith(l);\n placeCaret(l.firstElementChild!);\n return;\n }\n case \"hr\": {\n const t = takeEmptyBlock(root);\n t.before(document.createElement(\"hr\"));\n placeCaret(t);\n return;\n }\n case \"image\": case \"table\": case \"pullquote\": case \"takeaways\": case \"callout\": case \"toggle\": case \"video\": case \"file\":\n case \"gallery\": case \"embed\": case \"toc\": case \"columns\": case \"related\": case \"author\":\n insertIsland(root, id);\n return;\n }\n}\n\n/**\n * \"# \", \"> \", \"- \", \"1. \" and \"---\" at the start of a paragraph, each only when the field accepts what it makes.\n * Returns true when it converted.\n */\nexport function liveMarkdown(root: HTMLElement, data: string | null, allows: (f: RichTextFeature) => boolean = () => true): boolean {\n const s = window.getSelection();\n if (!s || !s.rangeCount || !s.isCollapsed) return false;\n const blk = topBlock(root, s.anchorNode);\n if (!blk || blk.tagName !== \"P\") return false;\n const before = textBeforeCaret(blk)?.replace(/ /g, \" \");\n if (before == null) return false;\n if (data === \"-\" && before === \"---\" && (blk.textContent ?? \"\").replace(/ /g, \" \") === \"---\") {\n if (!allows(\"hr\")) return false;\n const p = emptyP();\n blk.replaceWith(document.createElement(\"hr\"), p);\n placeCaret(p);\n return true;\n }\n if (data !== \" \") return false;\n const h = before.match(/^(#{1,6}) $/);\n let tag = h ? `h${h[1].length}` : before === \"> \" ? \"blockquote\" : null;\n let list = before === \"- \" || before === \"* \" ? \"ul\" : /^1[.)] $/.test(before) ? \"ol\" : null;\n if (tag && !allows(tag as RichTextFeature)) tag = null;\n if (list && !allows(list as RichTextFeature)) list = null;\n if (!tag && !list) return false;\n const r = document.createRange();\n r.selectNodeContents(blk);\n r.setEnd(s.anchorNode!, s.anchorOffset);\n r.deleteContents();\n const html = blk.textContent || blk.querySelector(\"img\") ? blk.innerHTML : \"<br>\";\n let target: HTMLElement;\n if (tag) {\n target = document.createElement(tag);\n target.innerHTML = html;\n blk.replaceWith(target);\n } else {\n const l = document.createElement(list!);\n target = document.createElement(\"li\");\n target.innerHTML = html;\n l.append(target);\n blk.replaceWith(l);\n }\n placeCaret(target, false);\n return true;\n}\n\n/** `text` typed between backticks becomes inline code. */\nexport function liveInlineCode(): boolean {\n const s = window.getSelection();\n if (!s || !s.rangeCount || !s.isCollapsed) return false;\n const r = s.getRangeAt(0);\n if (r.startContainer.nodeType !== 3 || r.startContainer.parentElement?.closest(\"code,pre\")) return false;\n const node = r.startContainer as Text;\n const m = node.data.slice(0, r.startOffset).match(/`([^`\\n]+)`$/);\n if (!m) return false;\n wrapTypedRun(s, node, r.startOffset, m[0].length, \"code\", m[1]);\n return true;\n}\n\n/**\n * RT-030: `**text**` becomes bold and `*text*` / `_text_` italic, run as the closing marker is typed (as\n * `liveInlineCode` is for the backtick), each only where the field accepts the mark. The first closing `*` of a\n * `**bold**` being typed is not an italic (its run starts with another `*`), and `_` inside a word (`snake_case_`)\n * stays as typed. Nothing inside code converts.\n */\nexport function liveInlineEmphasis(data: string | null, allows: (f: RichTextFeature) => boolean = () => true): boolean {\n if (data !== \"*\" && data !== \"_\") return false;\n const s = window.getSelection();\n if (!s || !s.rangeCount || !s.isCollapsed) return false;\n const r = s.getRangeAt(0);\n if (r.startContainer.nodeType !== 3 || r.startContainer.parentElement?.closest(\"code,pre\")) return false;\n const node = r.startContainer as Text;\n const before = node.data.slice(0, r.startOffset);\n const bold = data === \"*\" && allows(\"bold\") ? before.match(/\\*\\*([^*\\n]+)\\*\\*$/) : null;\n if (bold) {\n wrapTypedRun(s, node, r.startOffset, bold[0].length, \"strong\", bold[1]);\n return true;\n }\n if (!allows(\"italic\")) return false;\n const italic = data === \"*\" ? before.match(/(?:^|[^*])\\*([^*\\n]+)\\*$/) : before.match(/(?:^|[^\\w_])_([^_\\n]+)_$/);\n if (!italic) return false;\n // the match may start with the character before the opening marker: only the marked run is replaced\n const run = italic[0].replace(/^[^*_]/, \"\");\n wrapTypedRun(s, node, r.startOffset, run.length, \"em\", italic[1]);\n return true;\n}\n\n/* ── RT-028: list levels (Tab / Shift+Tab in a list item) ── */\n\n/**\n * Run `move` and put the caret back where it was. Moving a node takes the selection out of it, and a cloned Range is\n * live too (the DOM moves it to the old parent on removal), so the caret is kept as its plain node and offsets.\n */\nfunction keepingCaret(move: () => void): void {\n const s = window.getSelection();\n const at = s && s.rangeCount && s.anchorNode && s.focusNode ? [s.anchorNode, s.anchorOffset, s.focusNode, s.focusOffset] as const : null;\n move();\n if (s && at) s.setBaseAndExtent(at[0], at[1], at[2], at[3]);\n}\n\n/**\n * Tab: nest `li` one level deeper, under the item before it, in a list of the same kind (`ul` / `ol`). The\n * previous item's own nested list of that kind takes it when it has one. False (nothing moves) for the first item:\n * there is no item to nest under.\n */\nexport function indentListItem(li: HTMLElement): boolean {\n const list = li.parentElement;\n const prev = li.previousElementSibling as HTMLElement | null;\n if (!list || !/^(UL|OL)$/.test(list.tagName) || !prev || prev.tagName !== \"LI\") return false;\n keepingCaret(() => {\n const last = prev.lastElementChild;\n const nested = last && last.tagName === list.tagName ? last : prev.appendChild(document.createElement(list.tagName.toLowerCase()));\n nested.append(li);\n });\n return true;\n}\n\n/**\n * Shift+Tab: bring a nested `li` up one level, right after the item that held it. The items after it in its list stay\n * after it, nested under it, so the reading order never changes; an emptied nested list goes. False for an item\n * already at the top level.\n */\nexport function outdentListItem(li: HTMLElement): boolean {\n const list = li.parentElement;\n const parentLi = list?.parentElement;\n if (!list || !/^(UL|OL)$/.test(list.tagName) || !parentLi || parentLi.tagName !== \"LI\") return false;\n keepingCaret(() => {\n const after: Element[] = [];\n for (let n = li.nextElementSibling; n; n = n.nextElementSibling) after.push(n);\n if (after.length) {\n const own = li.lastElementChild && li.lastElementChild.tagName === list.tagName ? li.lastElementChild : li.appendChild(document.createElement(list.tagName.toLowerCase()));\n own.append(...after);\n }\n parentLi.after(li);\n if (!list.children.length) list.remove();\n });\n return true;\n}\n\n/** Replace the `length` characters typed before `end` in `node` with `<tag>text</tag>`, the caret after it. */\nfunction wrapTypedRun(s: Selection, node: Text, end: number, length: number, tag: \"code\" | \"strong\" | \"em\", text: string): void {\n const del = document.createRange();\n del.setStart(node, end - length);\n del.setEnd(node, end);\n del.deleteContents();\n const el = document.createElement(tag);\n el.textContent = text;\n del.insertNode(el);\n const next = el.nextSibling;\n if (next && next.nodeType === 3 && next.textContent) {\n const c = document.createRange();\n c.setStart(next, 0);\n c.collapse(true);\n s.removeAllRanges();\n s.addRange(c);\n } else {\n const after = document.createTextNode(\"\");\n el.after(after);\n placeCaret(after);\n }\n}\n\n/* ── What a field accepts, applied to HTML that arrives from outside (paste, Markdown) ── */\nconst MARK_FEATURE: Record<string, RichTextFeature> = {\n STRONG: \"bold\", B: \"bold\", EM: \"italic\", I: \"italic\", U: \"underline\", S: \"strike\", STRIKE: \"strike\", DEL: \"strike\", CODE: \"code\", A: \"link\",\n};\nconst BLOCK_FEATURE: Record<string, RichTextFeature> = {\n H1: \"h1\", H2: \"h2\", H3: \"h3\", H4: \"h4\", H5: \"h5\", H6: \"h6\", BLOCKQUOTE: \"blockquote\", UL: \"ul\", OL: \"ol\", PRE: \"pre\", HR: \"hr\", FIGURE: \"image\", IMG: \"image\",\n};\nconst FEATURE_WORD: Partial<Record<RichTextFeature, string>> = {\n image: \"images\", hr: \"dividers\", pre: \"code blocks\", ul: \"bulleted lists\", ol: \"numbered lists\", blockquote: \"quotes\", link: \"links\",\n};\n\n/**\n * HTML with every element the field does not accept turned into what it does: a heading / quote / code block becomes a\n * paragraph, a list becomes one paragraph per item, a mark or link is unwrapped to its text, a divider or image is\n * removed. `dropped` names what was taken out entirely (said to the author, never silent).\n */\n/**\n * RT-016: HTML from another page as this editor takes it, before `restrictHtml` keeps it to the field. Classes, inline\n * styles and ids are the source page's look, not content: only a link's address is kept. A wrapper that is only styling\n * (a span, a font, Google Docs' `<b style=\"font-weight:normal\">` around a whole paste) is unwrapped to its contents. A\n * picture is taken out when `dropImages` (the field holds images, but a pasted address is not a media-library image);\n * otherwise it is left for `restrictHtml`, which removes it and says so. `images` counts what was taken out here.\n */\nexport function pastedHtml(html: string, dropImages: boolean): { html: string; images: number } {\n const doc = new DOMParser().parseFromString(`<body>${html}</body>`, \"text/html\");\n doc.body.querySelectorAll(\"script,style,meta,link,title,iframe,object,embed,form,input,button,textarea,select,noscript,template\").forEach((n) => n.remove());\n let images = 0;\n if (dropImages) {\n doc.body.querySelectorAll(\"picture,figure,img\").forEach((n) => {\n if (!n.isConnected) return;\n if (n.tagName === \"IMG\" || n.querySelector(\"img\")) images++;\n n.remove();\n });\n }\n const unwrap = (el: Element) => el.replaceWith(...Array.from(el.childNodes));\n for (const el of Array.from(doc.body.querySelectorAll(\"*\")).reverse()) {\n if (el.tagName === \"SPAN\" || el.tagName === \"FONT\" || ((el.tagName === \"B\" || el.tagName === \"STRONG\") && /font-weight\\s*:\\s*(normal|400)/i.test(el.getAttribute(\"style\") ?? \"\"))) {\n unwrap(el);\n continue;\n }\n for (const a of Array.from(el.attributes)) {\n const keep = (el.tagName === \"A\" && a.name === \"href\") || (el.tagName === \"IMG\" && (a.name === \"src\" || a.name === \"alt\"));\n if (!keep) el.removeAttribute(a.name);\n }\n }\n return { html: doc.body.innerHTML.trim(), images };\n}\n\nexport function restrictHtml(html: string, allows: (f: RichTextFeature) => boolean): { html: string; dropped: string[] } {\n if (!html) return { html, dropped: [] };\n const doc = new DOMParser().parseFromString(`<body>${html}</body>`, \"text/html\");\n const dropped = new Set<string>();\n const walk = (el: Element) => {\n for (const ch of Array.from(el.children)) {\n walk(ch);\n const mark = MARK_FEATURE[ch.tagName];\n const block = BLOCK_FEATURE[ch.tagName];\n if (mark && !allows(mark)) ch.replaceWith(...Array.from(ch.childNodes));\n else if (block && !allows(block)) {\n if (block === \"hr\" || block === \"image\") {\n dropped.add(FEATURE_WORD[block]!);\n ch.remove();\n } else if (block === \"ul\" || block === \"ol\") {\n const ps = Array.from(ch.children).map((li) => {\n const p = doc.createElement(\"p\");\n p.innerHTML = li.innerHTML;\n return p;\n });\n ch.replaceWith(...ps);\n } else {\n const p = doc.createElement(\"p\");\n p.innerHTML = block === \"pre\" ? esc(ch.textContent ?? \"\").replace(/\\n/g, \"<br>\") : ch.innerHTML;\n ch.replaceWith(p);\n }\n }\n }\n };\n walk(doc.body);\n return { html: doc.body.innerHTML, dropped: [...dropped] };\n}\n"],"mappings":";;;;;;AAQA,IAAM,eAAe;CACnB,MAAM,IAAI,SAAS,cAAc,GAAG;CACpC,EAAE,YAAY;CACd,OAAO;AACT;AACA,IAAM,cAAc,OAA0C,CAAC,CAAC,MAAM,CAAC,GAAG,aAAa,gBAAgB,KAAK,GAAG,YAAY;;AAG3H,SAAgB,gBAAgB,GAAyB;CACvD,MAAM,OAAO,EAAE;CACf,IAAI,WAAW,IAAI,GAAG,OAAO;CAC7B,MAAM,IAAI,OAAO;CACjB,EAAE,MAAM,CAAC;CACT,OAAO;AACT;AAEA,SAAgB,eAAe,GAA6B;CAC1D,IAAI;CACJ,IAAI,EAAE,aAAa,gBAAgB,GAAG;EACpC,MAAM,IAAI,EAAE,aAAa,gBAAgB;EACzC,IAAI,aAAa,GAAG,WAAW,GAAI,EAAe,IAAa,CAAC;CAClE,OAAO;EACL,IAAI,EAAE,UAAU,IAAI;EACpB,EAAE,gBAAgB,WAAW;CAC/B;CACA,EAAE,MAAM,CAAC;CACT,OAAO;AACT;;AAGA,SAAgB,UAAU,GAAgB,KAAsB;CAC9D,MAAM,MAAM,MAAM,IAAI,EAAE,yBAAyB,EAAE;CACnD,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,IAAI,OAAO,aAAa;CAE9B,MAAM,KAAK,KAAK,EAAE,aAAa;EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;EAAgB,GAAG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AAM;KAC3C,MAAM,KAAK,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,KAAK,OAAO;MAC7C,MAAM,IAAI,IAAI,cAAc,GAAG;MAC/B,EAAE,YAAY,GAAG;MACjB,OAAO;KACT,CAAC;KACD,GAAG,YAAY,GAAG,EAAE;IACtB,OAAO;KACL,MAAM,IAAI,IAAI,cAAc,GAAG;KAC/B,EAAE,YAAY,UAAU,QAAQ,IAAI,GAAG,eAAe,EAAE,CAAC,CAAC,QAAQ,OAAO,MAAM,IAAI,GAAG;KACtF,GAAG,YAAY,CAAC;IAClB;GACF;EACF;CACF;CACA,KAAK,IAAI,IAAI;CACb,OAAO;EAAE,MAAM,IAAI,KAAK;EAAW,SAAS,CAAC,GAAG,OAAO;CAAE;AAC3D"}
|
|
@@ -726,7 +726,7 @@ function GridCell({ ctx, row, col, r, c, onMove, onPaste, full }) {
|
|
|
726
726
|
className: "text-kit-fg-4",
|
|
727
727
|
children: "—"
|
|
728
728
|
}) : /* @__PURE__ */ jsx("span", {
|
|
729
|
-
className: cn("flex size-4 items-center justify-center rounded-kit-sm border", b ? "border-kit-inverse bg-kit-inverse text-kit-fg-inverse" : "border-kit-
|
|
729
|
+
className: cn("flex size-4 items-center justify-center rounded-kit-sm border", b ? "border-kit-inverse bg-kit-inverse text-kit-fg-inverse" : "border-kit-field-border"),
|
|
730
730
|
children: b ? /* @__PURE__ */ jsx(IconCheck, {
|
|
731
731
|
className: "size-3",
|
|
732
732
|
stroke: 3,
|