@bettercms-ai/kit 3.0.2 → 3.1.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/dist/adapters/lossy.d.ts +1 -1
- package/dist/adapters/lossy.js +3 -2
- package/dist/adapters/lossy.js.map +1 -1
- package/dist/adapters/schema.js +5 -5
- package/dist/adapters/schema.js.map +1 -1
- package/dist/brand/logo.js +18 -67
- package/dist/brand/logo.js.map +1 -1
- package/dist/context.js +3 -8
- package/dist/context.js.map +1 -1
- package/dist/controls/button.js +134 -451
- package/dist/controls/button.js.map +1 -1
- package/dist/controls/choice.js +95 -336
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/code.js +72 -245
- package/dist/controls/code.js.map +1 -1
- package/dist/controls/color.js +31 -108
- package/dist/controls/color.js.map +1 -1
- package/dist/controls/date.js +83 -268
- package/dist/controls/date.js.map +1 -1
- package/dist/controls/form-picker.js +9 -26
- package/dist/controls/form-picker.js.map +1 -1
- package/dist/controls/icon.js +100 -341
- package/dist/controls/icon.js.map +1 -1
- package/dist/controls/json.js +7 -20
- package/dist/controls/json.js.map +1 -1
- package/dist/controls/link.js +156 -561
- package/dist/controls/link.js.map +1 -1
- package/dist/controls/location.js +35 -124
- package/dist/controls/location.js.map +1 -1
- package/dist/controls/media.js +267 -928
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/number.js +23 -80
- package/dist/controls/number.js.map +1 -1
- package/dist/controls/reference.js +155 -516
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/article-shell.js +86 -327
- package/dist/controls/rich-text/article-shell.js.map +1 -1
- package/dist/controls/rich-text/author.js +21 -78
- package/dist/controls/rich-text/author.js.map +1 -1
- package/dist/controls/rich-text/blocks.js +317 -1086
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/button.js +10 -31
- package/dist/controls/rich-text/button.js.map +1 -1
- package/dist/controls/rich-text/catalog.js +51 -168
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/columns.js +31 -104
- package/dist/controls/rich-text/columns.js.map +1 -1
- package/dist/controls/rich-text/component-card.js +209 -790
- package/dist/controls/rich-text/component-card.js.map +1 -1
- package/dist/controls/rich-text/component-panel.js +40 -102
- package/dist/controls/rich-text/component-panel.js.map +1 -1
- package/dist/controls/rich-text/control.js +32 -101
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/editor.js +108 -369
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/embed.js +51 -184
- package/dist/controls/rich-text/embed.js.map +1 -1
- package/dist/controls/rich-text/floating.js +42 -171
- package/dist/controls/rich-text/floating.js.map +1 -1
- package/dist/controls/rich-text/footnote.js +28 -89
- package/dist/controls/rich-text/footnote.js.map +1 -1
- package/dist/controls/rich-text/gallery.js +27 -88
- package/dist/controls/rich-text/gallery.js.map +1 -1
- package/dist/controls/rich-text/link-form.d.ts +10 -0
- package/dist/controls/rich-text/link-form.js +16 -204
- package/dist/controls/rich-text/link-form.js.map +1 -1
- package/dist/controls/rich-text/plain.js +3 -8
- package/dist/controls/rich-text/plain.js.map +1 -1
- package/dist/controls/rich-text/related.js +25 -86
- package/dist/controls/rich-text/related.js.map +1 -1
- package/dist/controls/rich-text/toc.js +15 -48
- package/dist/controls/rich-text/toc.js.map +1 -1
- package/dist/controls/rich-text/toolbar.js +105 -402
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/scale.js +52 -169
- package/dist/controls/scale.js.map +1 -1
- package/dist/controls/slot.js +73 -238
- package/dist/controls/slot.js.map +1 -1
- package/dist/controls/table/table-editor.js +500 -1766
- package/dist/controls/table/table-editor.js.map +1 -1
- package/dist/controls/table/table-link.js +41 -121
- package/dist/controls/table/table-link.js.map +1 -1
- package/dist/controls/table/table.js +9 -26
- package/dist/controls/table/table.js.map +1 -1
- package/dist/controls/text.js +68 -221
- package/dist/controls/text.js.map +1 -1
- package/dist/controls/unknown-value.js +22 -79
- package/dist/controls/unknown-value.js.map +1 -1
- package/dist/engine/array.js +228 -821
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/bits.js +13 -38
- package/dist/engine/bits.js.map +1 -1
- package/dist/engine/breadcrumb.js +8 -25
- package/dist/engine/breadcrumb.js.map +1 -1
- package/dist/engine/expand.js +13 -38
- package/dist/engine/expand.js.map +1 -1
- package/dist/engine/field-list.js +5 -14
- package/dist/engine/field-list.js.map +1 -1
- package/dist/engine/field-shell.js +244 -849
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +78 -275
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.js +193 -630
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +50 -187
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/kit-field.js +95 -320
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/schema-form.js +32 -101
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/engine/slot.js +45 -146
- package/dist/engine/slot.js.map +1 -1
- package/dist/lib/icons.js +5 -14
- package/dist/lib/icons.js.map +1 -1
- package/dist/library/kit-catalog.json +2 -1
- package/dist/styles.css +1 -5821
- package/dist/table/table-view.js +16 -49
- package/dist/table/table-view.js.map +1 -1
- package/dist/testing/test-form.js +5 -14
- package/dist/testing/test-form.js.map +1 -1
- package/dist/theme.js +3 -8
- package/dist/theme.js.map +1 -1
- package/dist/ui/action-tray.js +24 -97
- package/dist/ui/action-tray.js.map +1 -1
- package/dist/ui/autocomplete.js +38 -135
- package/dist/ui/autocomplete.js.map +1 -1
- package/dist/ui/button.js +31 -108
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/choice-switch.js +5 -14
- package/dist/ui/choice-switch.js.map +1 -1
- package/dist/ui/controls.js +86 -279
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/display.js +116 -401
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/expanded-editor-modal.js +27 -100
- package/dist/ui/expanded-editor-modal.js.map +1 -1
- package/dist/ui/floating-panel.js +37 -130
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/input.js +59 -196
- package/dist/ui/input.js.map +1 -1
- package/dist/ui/mode-bar.js +11 -32
- package/dist/ui/mode-bar.js.map +1 -1
- package/dist/ui/overlay.js +176 -613
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/path-crumbs.js +113 -374
- package/dist/ui/path-crumbs.js.map +1 -1
- package/dist/ui/select.js +78 -311
- package/dist/ui/select.js.map +1 -1
- package/dist/ui/shortcut-hint.js +6 -19
- package/dist/ui/shortcut-hint.js.map +1 -1
- package/dist/ui/spinner.js +7 -20
- package/dist/ui/spinner.js.map +1 -1
- package/dist/ui/split-button.js +10 -35
- package/dist/ui/split-button.js.map +1 -1
- package/dist/ui/tab.js +17 -50
- package/dist/ui/tab.js.map +1 -1
- package/dist/ui/toast.js +30 -107
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/tooltip-root.js +7 -24
- package/dist/ui/tooltip-root.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { placeCaret } from "./dom.js";
|
|
|
3
3
|
import { ArticlePopoverBlock } from "./article-shell.js";
|
|
4
4
|
import { slugify } from "@bettercms-ai/types";
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
import {
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
//#region src/controls/rich-text/toc.tsx
|
|
8
8
|
/**
|
|
9
9
|
* RICH TEXT · Table of contents (kit-richtext-ui-spec.md §5): V2's article block, stored as the PT block object
|
|
@@ -20,7 +20,6 @@ import { jsxDEV } from "react/jsx-dev-runtime";
|
|
|
20
20
|
* The block itself (card, chip, popover at its corner) is the shared article shell (article-shell.tsx, kit-40); it
|
|
21
21
|
* opens on a fresh insert by focusing the card only (V2 article-blocks.tsx:131).
|
|
22
22
|
*/
|
|
23
|
-
var _jsxFileName = "D:/Github/bettercms/bettercms-backend/packages/kit/src/controls/rich-text/toc.tsx";
|
|
24
23
|
var TOC_LABEL = "Table of contents";
|
|
25
24
|
var tocDefault = () => ({
|
|
26
25
|
title: "In this article",
|
|
@@ -105,56 +104,32 @@ function TocPreview({ m, outline, host }) {
|
|
|
105
104
|
root.focus({ preventScroll: true });
|
|
106
105
|
placeCaret(h);
|
|
107
106
|
};
|
|
108
|
-
return /* @__PURE__ */
|
|
107
|
+
return /* @__PURE__ */ jsxs("nav", {
|
|
109
108
|
"aria-label": m.title || "Table of contents",
|
|
110
109
|
className: "rounded-kit-lg border border-kit-line bg-kit-surface px-4 py-3",
|
|
111
|
-
children: [m.title ? /* @__PURE__ */
|
|
110
|
+
children: [m.title ? /* @__PURE__ */ jsx("p", {
|
|
112
111
|
"data-field": "title",
|
|
113
112
|
className: "mb-1.5 text-kit-sm font-semibold text-kit-fg",
|
|
114
113
|
children: m.title
|
|
115
|
-
}
|
|
116
|
-
fileName: _jsxFileName,
|
|
117
|
-
lineNumber: 117,
|
|
118
|
-
columnNumber: 9
|
|
119
|
-
}, this) : null, items.length ? /* @__PURE__ */ jsxDEV("ol", {
|
|
114
|
+
}) : null, items.length ? /* @__PURE__ */ jsx("ol", {
|
|
120
115
|
className: "m-0 flex list-none flex-col gap-0.5 p-0 text-kit-sm",
|
|
121
|
-
children: items.map((it, i) => /* @__PURE__ */
|
|
116
|
+
children: items.map((it, i) => /* @__PURE__ */ jsx("li", {
|
|
122
117
|
className: cn(it.depth === 3 && "pl-4"),
|
|
123
|
-
children: /* @__PURE__ */
|
|
118
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
124
119
|
type: "button",
|
|
125
120
|
onClick: (e) => (e.stopPropagation(), go(it)),
|
|
126
121
|
className: "max-w-full truncate rounded-kit-sm text-left text-kit-fg-2 hover:text-kit-fg hover:underline",
|
|
127
122
|
children: it.text
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
columnNumber: 15
|
|
132
|
-
}, this)
|
|
133
|
-
}, `${it.id}-${i}`, false, {
|
|
134
|
-
fileName: _jsxFileName,
|
|
135
|
-
lineNumber: 124,
|
|
136
|
-
columnNumber: 13
|
|
137
|
-
}, this))
|
|
138
|
-
}, void 0, false, {
|
|
139
|
-
fileName: _jsxFileName,
|
|
140
|
-
lineNumber: 122,
|
|
141
|
-
columnNumber: 9
|
|
142
|
-
}, this) : /* @__PURE__ */ jsxDEV("p", {
|
|
123
|
+
})
|
|
124
|
+
}, `${it.id}-${i}`))
|
|
125
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
143
126
|
className: "text-kit-sm text-kit-fg-3",
|
|
144
127
|
children: "No headings yet."
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
lineNumber: 132,
|
|
148
|
-
columnNumber: 9
|
|
149
|
-
}, this)]
|
|
150
|
-
}, void 0, true, {
|
|
151
|
-
fileName: _jsxFileName,
|
|
152
|
-
lineNumber: 115,
|
|
153
|
-
columnNumber: 5
|
|
154
|
-
}, this);
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
155
130
|
}
|
|
156
131
|
function TocBlock({ m, set, el, ctx, autoFocus }) {
|
|
157
|
-
return /* @__PURE__ */
|
|
132
|
+
return /* @__PURE__ */ jsx(ArticlePopoverBlock, {
|
|
158
133
|
label: TOC_LABEL,
|
|
159
134
|
kind: "toc",
|
|
160
135
|
schema: TOC_SCHEMA,
|
|
@@ -172,20 +147,12 @@ function TocBlock({ m, set, el, ctx, autoFocus }) {
|
|
|
172
147
|
title: String(v.title ?? ""),
|
|
173
148
|
depth: v.depth === "2" ? "2" : "3"
|
|
174
149
|
}),
|
|
175
|
-
children: () => /* @__PURE__ */
|
|
150
|
+
children: () => /* @__PURE__ */ jsx(TocPreview, {
|
|
176
151
|
m,
|
|
177
152
|
outline: ctx.outline ?? NO_OUTLINE,
|
|
178
153
|
host: el
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
lineNumber: 163,
|
|
182
|
-
columnNumber: 14
|
|
183
|
-
}, this)
|
|
184
|
-
}, void 0, false, {
|
|
185
|
-
fileName: _jsxFileName,
|
|
186
|
-
lineNumber: 150,
|
|
187
|
-
columnNumber: 5
|
|
188
|
-
}, this);
|
|
154
|
+
})
|
|
155
|
+
});
|
|
189
156
|
}
|
|
190
157
|
//#endregion
|
|
191
158
|
export { NO_OUTLINE, TOC_LABEL, TOC_SCHEMA, TocBlock, TocPreview, createOutlineStore, outlineOf, slugify, tocDefault, tocVisible };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toc.js","names":[],"sources":["../../../src/controls/rich-text/toc.tsx"],"sourcesContent":["/**\n * RICH TEXT · Table of contents (kit-richtext-ui-spec.md §5): V2's article block, stored as the PT block object\n * `{ _type: \"tableOfContents\", title?, depth: \"2\" | \"3\" }`. The list is derived from the same body's top-level H2/H3,\n * never stored.\n *\n * form V2 article.ts:137-156: Title (max 40, default \"In this article\"), Headings H2 | H2 and H3 (segmented)\n * outline V2 article.ts:248-266: the body's top-level non-empty H2/H3 in order, ids slugified and de-duplicated\n * (x, x-2, …), the same ids the site stamps on its headings\n * preview V2 article-blocks.tsx:537-568: the nav as the reader sees it; each entry a button that scrolls the\n * heading to the centre and puts the caret in it; \"No headings yet.\" when there are none\n * store V2 article-blocks.tsx:45-66: one live outline per editor, so every TOC follows the headings as they are typed\n *\n * The block itself (card, chip, popover at its corner) is the shared article shell (article-shell.tsx, kit-40); it\n * opens on a fresh insert by focusing the card only (V2 article-blocks.tsx:131).\n */\nimport * as React from \"react\";\nimport { cn } from \"../../lib/cn\";\nimport { slugify } from \"@bettercms-ai/types\";\nimport type { TypeSchema } from \"../../schema/types\";\nimport { ArticlePopoverBlock } from \"./article-shell\";\nimport type { IslandCtx } from \"./blocks\";\nimport { placeCaret, type IslandEl } from \"./dom\";\n\nexport interface TocModel {\n title: string;\n depth: \"2\" | \"3\";\n}\nexport const TOC_LABEL = \"Table of contents\";\nexport const tocDefault = (): TocModel => ({ title: \"In this article\", depth: \"3\" });\n\n/** The popover form (V2 ARTICLE_SCHEMAS.toc). Two settings → the shell's popover (D54). */\nexport const TOC_SCHEMA: TypeSchema = {\n name: \"tableOfContents\",\n title: TOC_LABEL,\n kind: \"object\",\n icon: \"list-tree\",\n fields: [\n { name: \"title\", title: \"Title\", type: \"string\", validation: { max: 40 } },\n {\n name: \"depth\",\n title: \"Headings\",\n type: \"select\",\n layout: \"segmented\",\n initialValue: \"3\",\n options: [\n { value: \"2\", label: \"H2\" },\n { value: \"3\", label: \"H2 and H3\" },\n ],\n },\n ],\n};\n\n/* ── Outline ───────────────────────────────────────────────────────── */\nexport interface OutlineItem {\n id: string;\n text: string;\n depth: 2 | 3;\n}\n/** V2 article.ts:250-251, the one heading-id rule the site stamps too (types heading-id.ts, plan RT5). */\nexport { slugify };\n\n/** The body's H2 and H3, top level only, in order, with stable de-duplicated ids. */\nexport function outlineOf(root: ParentNode): OutlineItem[] {\n const used = new Set<string>();\n const out: OutlineItem[] = [];\n root.querySelectorAll(\":scope > h2, :scope > h3\").forEach((h) => {\n const text = (h.textContent ?? \"\").replace(//g, \"\").trim();\n if (!text) return;\n let id = slugify(text);\n for (let n = 2; used.has(id); n++) id = `${slugify(text)}-${n}`;\n used.add(id);\n out.push({ id, text, depth: h.tagName === \"H2\" ? 2 : 3 });\n });\n return out;\n}\nexport const tocVisible = (outline: OutlineItem[], depth: TocModel[\"depth\"]) => outline.filter((o) => o.depth === 2 || depth === \"3\");\n\n/** One live outline per editor: the editor sets it after each input, every TOC preview subscribes. */\nexport interface OutlineStore {\n get: () => OutlineItem[];\n subscribe: (fn: () => void) => () => void;\n set: (next: OutlineItem[]) => void;\n}\nexport function createOutlineStore(): OutlineStore {\n let cur: OutlineItem[] = [];\n const subs = new Set<() => void>();\n return {\n get: () => cur,\n subscribe: (fn) => (subs.add(fn), () => void subs.delete(fn)),\n set: (next) => {\n if (JSON.stringify(next) === JSON.stringify(cur)) return;\n cur = next;\n subs.forEach((f) => f());\n },\n };\n}\nexport const NO_OUTLINE: OutlineStore = { get: () => [], subscribe: () => () => {}, set: () => {} };\n\n/* ── Preview (what the reader sees) ────────────────────────────────── */\n/** `host` is the TOC's island element; its parent is the editor surface whose headings it lists. */\nexport function TocPreview({ m, outline, host }: { m: TocModel; outline: OutlineStore; host: HTMLElement }) {\n const all = React.useSyncExternalStore(outline.subscribe, outline.get, outline.get);\n const items = tocVisible(all, m.depth);\n const go = (it: OutlineItem) => {\n const root = host.parentElement;\n if (!root) return;\n const hs = Array.from(root.querySelectorAll<HTMLElement>(\":scope > h2, :scope > h3\")).filter((h) => (h.textContent ?? \"\").replace(//g, \"\").trim());\n const h = hs[all.indexOf(it)];\n if (!h) return;\n h.scrollIntoView?.({ block: \"center\", behavior: \"smooth\" });\n root.focus({ preventScroll: true });\n placeCaret(h);\n };\n return (\n <nav aria-label={m.title || TOC_LABEL} className=\"rounded-kit-lg border border-kit-line bg-kit-surface px-4 py-3\">\n {m.title ? (\n <p data-field=\"title\" className=\"mb-1.5 text-kit-sm font-semibold text-kit-fg\">\n {m.title}\n </p>\n ) : null}\n {items.length ? (\n <ol className=\"m-0 flex list-none flex-col gap-0.5 p-0 text-kit-sm\">\n {items.map((it, i) => (\n <li key={`${it.id}-${i}`} className={cn(it.depth === 3 && \"pl-4\")}>\n <button type=\"button\" onClick={(e) => (e.stopPropagation(), go(it))} className=\"max-w-full truncate rounded-kit-sm text-left text-kit-fg-2 hover:text-kit-fg hover:underline\">\n {it.text}\n </button>\n </li>\n ))}\n </ol>\n ) : (\n <p className=\"text-kit-sm text-kit-fg-3\">No headings yet.</p>\n )}\n </nav>\n );\n}\n\n/* ── The block (V2 ArticleBlock, surface \"popover\") ────────────────── */\nexport interface TocBlockProps {\n m: TocModel;\n set: (fn: (m: TocModel) => TocModel, label?: string) => void;\n el: IslandEl;\n /** the editor's live outline rides the island context */\n ctx: IslandCtx & { outline?: OutlineStore };\n autoFocus: boolean;\n}\n\nexport function TocBlock({ m, set, el, ctx, autoFocus }: TocBlockProps) {\n return (\n <ArticlePopoverBlock<TocModel>\n label={TOC_LABEL}\n kind=\"toc\"\n schema={TOC_SCHEMA}\n m={m}\n set={set}\n el={el}\n ctx={ctx}\n autoFocus={autoFocus}\n openOnInsert={false}\n toForm={(x) => ({ title: x.title, depth: x.depth })}\n fromForm={(v) => ({ title: String(v.title ?? \"\"), depth: v.depth === \"2\" ? \"2\" : \"3\" })}\n >\n {() => <TocPreview m={m} outline={ctx.outline ?? NO_OUTLINE} host={el} />}\n </ArticlePopoverBlock>\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"toc.js","names":[],"sources":["../../../src/controls/rich-text/toc.tsx"],"sourcesContent":["/**\n * RICH TEXT · Table of contents (kit-richtext-ui-spec.md §5): V2's article block, stored as the PT block object\n * `{ _type: \"tableOfContents\", title?, depth: \"2\" | \"3\" }`. The list is derived from the same body's top-level H2/H3,\n * never stored.\n *\n * form V2 article.ts:137-156: Title (max 40, default \"In this article\"), Headings H2 | H2 and H3 (segmented)\n * outline V2 article.ts:248-266: the body's top-level non-empty H2/H3 in order, ids slugified and de-duplicated\n * (x, x-2, …), the same ids the site stamps on its headings\n * preview V2 article-blocks.tsx:537-568: the nav as the reader sees it; each entry a button that scrolls the\n * heading to the centre and puts the caret in it; \"No headings yet.\" when there are none\n * store V2 article-blocks.tsx:45-66: one live outline per editor, so every TOC follows the headings as they are typed\n *\n * The block itself (card, chip, popover at its corner) is the shared article shell (article-shell.tsx, kit-40); it\n * opens on a fresh insert by focusing the card only (V2 article-blocks.tsx:131).\n */\nimport * as React from \"react\";\nimport { cn } from \"../../lib/cn\";\nimport { slugify } from \"@bettercms-ai/types\";\nimport type { TypeSchema } from \"../../schema/types\";\nimport { ArticlePopoverBlock } from \"./article-shell\";\nimport type { IslandCtx } from \"./blocks\";\nimport { placeCaret, type IslandEl } from \"./dom\";\n\nexport interface TocModel {\n title: string;\n depth: \"2\" | \"3\";\n}\nexport const TOC_LABEL = \"Table of contents\";\nexport const tocDefault = (): TocModel => ({ title: \"In this article\", depth: \"3\" });\n\n/** The popover form (V2 ARTICLE_SCHEMAS.toc). Two settings → the shell's popover (D54). */\nexport const TOC_SCHEMA: TypeSchema = {\n name: \"tableOfContents\",\n title: TOC_LABEL,\n kind: \"object\",\n icon: \"list-tree\",\n fields: [\n { name: \"title\", title: \"Title\", type: \"string\", validation: { max: 40 } },\n {\n name: \"depth\",\n title: \"Headings\",\n type: \"select\",\n layout: \"segmented\",\n initialValue: \"3\",\n options: [\n { value: \"2\", label: \"H2\" },\n { value: \"3\", label: \"H2 and H3\" },\n ],\n },\n ],\n};\n\n/* ── Outline ───────────────────────────────────────────────────────── */\nexport interface OutlineItem {\n id: string;\n text: string;\n depth: 2 | 3;\n}\n/** V2 article.ts:250-251, the one heading-id rule the site stamps too (types heading-id.ts, plan RT5). */\nexport { slugify };\n\n/** The body's H2 and H3, top level only, in order, with stable de-duplicated ids. */\nexport function outlineOf(root: ParentNode): OutlineItem[] {\n const used = new Set<string>();\n const out: OutlineItem[] = [];\n root.querySelectorAll(\":scope > h2, :scope > h3\").forEach((h) => {\n const text = (h.textContent ?? \"\").replace(//g, \"\").trim();\n if (!text) return;\n let id = slugify(text);\n for (let n = 2; used.has(id); n++) id = `${slugify(text)}-${n}`;\n used.add(id);\n out.push({ id, text, depth: h.tagName === \"H2\" ? 2 : 3 });\n });\n return out;\n}\nexport const tocVisible = (outline: OutlineItem[], depth: TocModel[\"depth\"]) => outline.filter((o) => o.depth === 2 || depth === \"3\");\n\n/** One live outline per editor: the editor sets it after each input, every TOC preview subscribes. */\nexport interface OutlineStore {\n get: () => OutlineItem[];\n subscribe: (fn: () => void) => () => void;\n set: (next: OutlineItem[]) => void;\n}\nexport function createOutlineStore(): OutlineStore {\n let cur: OutlineItem[] = [];\n const subs = new Set<() => void>();\n return {\n get: () => cur,\n subscribe: (fn) => (subs.add(fn), () => void subs.delete(fn)),\n set: (next) => {\n if (JSON.stringify(next) === JSON.stringify(cur)) return;\n cur = next;\n subs.forEach((f) => f());\n },\n };\n}\nexport const NO_OUTLINE: OutlineStore = { get: () => [], subscribe: () => () => {}, set: () => {} };\n\n/* ── Preview (what the reader sees) ────────────────────────────────── */\n/** `host` is the TOC's island element; its parent is the editor surface whose headings it lists. */\nexport function TocPreview({ m, outline, host }: { m: TocModel; outline: OutlineStore; host: HTMLElement }) {\n const all = React.useSyncExternalStore(outline.subscribe, outline.get, outline.get);\n const items = tocVisible(all, m.depth);\n const go = (it: OutlineItem) => {\n const root = host.parentElement;\n if (!root) return;\n const hs = Array.from(root.querySelectorAll<HTMLElement>(\":scope > h2, :scope > h3\")).filter((h) => (h.textContent ?? \"\").replace(//g, \"\").trim());\n const h = hs[all.indexOf(it)];\n if (!h) return;\n h.scrollIntoView?.({ block: \"center\", behavior: \"smooth\" });\n root.focus({ preventScroll: true });\n placeCaret(h);\n };\n return (\n <nav aria-label={m.title || TOC_LABEL} className=\"rounded-kit-lg border border-kit-line bg-kit-surface px-4 py-3\">\n {m.title ? (\n <p data-field=\"title\" className=\"mb-1.5 text-kit-sm font-semibold text-kit-fg\">\n {m.title}\n </p>\n ) : null}\n {items.length ? (\n <ol className=\"m-0 flex list-none flex-col gap-0.5 p-0 text-kit-sm\">\n {items.map((it, i) => (\n <li key={`${it.id}-${i}`} className={cn(it.depth === 3 && \"pl-4\")}>\n <button type=\"button\" onClick={(e) => (e.stopPropagation(), go(it))} className=\"max-w-full truncate rounded-kit-sm text-left text-kit-fg-2 hover:text-kit-fg hover:underline\">\n {it.text}\n </button>\n </li>\n ))}\n </ol>\n ) : (\n <p className=\"text-kit-sm text-kit-fg-3\">No headings yet.</p>\n )}\n </nav>\n );\n}\n\n/* ── The block (V2 ArticleBlock, surface \"popover\") ────────────────── */\nexport interface TocBlockProps {\n m: TocModel;\n set: (fn: (m: TocModel) => TocModel, label?: string) => void;\n el: IslandEl;\n /** the editor's live outline rides the island context */\n ctx: IslandCtx & { outline?: OutlineStore };\n autoFocus: boolean;\n}\n\nexport function TocBlock({ m, set, el, ctx, autoFocus }: TocBlockProps) {\n return (\n <ArticlePopoverBlock<TocModel>\n label={TOC_LABEL}\n kind=\"toc\"\n schema={TOC_SCHEMA}\n m={m}\n set={set}\n el={el}\n ctx={ctx}\n autoFocus={autoFocus}\n openOnInsert={false}\n toForm={(x) => ({ title: x.title, depth: x.depth })}\n fromForm={(v) => ({ title: String(v.title ?? \"\"), depth: v.depth === \"2\" ? \"2\" : \"3\" })}\n >\n {() => <TocPreview m={m} outline={ctx.outline ?? NO_OUTLINE} host={el} />}\n </ArticlePopoverBlock>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,YAAY;AACzB,IAAa,oBAA8B;CAAE,OAAO;CAAmB,OAAO;AAAI;;AAGlF,IAAa,aAAyB;CACpC,MAAM;CACN,OAAO;CACP,MAAM;CACN,MAAM;CACN,QAAQ,CACN;EAAE,MAAM;EAAS,OAAO;EAAS,MAAM;EAAU,YAAY,EAAE,KAAK,GAAG;CAAE,GACzE;EACE,MAAM;EACN,OAAO;EACP,MAAM;EACN,QAAQ;EACR,cAAc;EACd,SAAS,CACP;GAAE,OAAO;GAAK,OAAO;EAAK,GAC1B;GAAE,OAAO;GAAK,OAAO;EAAY,CACnC;CACF,CACF;AACF;;AAYA,SAAgB,UAAU,MAAiC;CACzD,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,MAAqB,CAAC;CAC5B,KAAK,iBAAiB,0BAA0B,CAAC,CAAC,SAAS,MAAM;EAC/D,MAAM,QAAQ,EAAE,eAAe,GAAA,CAAI,QAAQ,MAAM,EAAE,CAAC,CAAC,KAAK;EAC1D,IAAI,CAAC,MAAM;EACX,IAAI,KAAK,QAAQ,IAAI;EACrB,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK,KAAK,GAAG,QAAQ,IAAI,EAAE,GAAG;EAC5D,KAAK,IAAI,EAAE;EACX,IAAI,KAAK;GAAE;GAAI;GAAM,OAAO,EAAE,YAAY,OAAO,IAAI;EAAE,CAAC;CAC1D,CA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