@bettercms-ai/kit 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/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 +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floating.js","names":[],"sources":["../../../src/controls/rich-text/floating.tsx"],"sourcesContent":["/**\n * RICH TEXT · the selection bubble: AI rewrite, style, marks, link (V2 HEAD controls/rich-text/floating.tsx).\n * V2's inline \"Ask AI\" prompt took free text; the host's AI service rewrites by preset only, so it is not drawn.\n */\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { IconBold, IconCode, IconItalic, IconLink, IconMessage, IconStrikethrough, IconSubscript, IconSuperscript, IconUnderline } from \"@tabler/icons-react\";\nimport { Sparkle } from \"../../ui/button\";\nimport { Menu, MenuContent, MenuItem, MenuTrigger } from \"../../ui/overlay\";\nimport type { AiPreset } from \"../../context\";\nimport type { RichTextFeature } from \"./codec\";\nimport { StyleMenu, ToolButton, stylesFor, type Fmt, type MarkCmd } from \"./toolbar\";\n\n/** The bubble's rewrite directions (V2: improve, shorter, punchier, grammar), as the host service's presets. */\nexport const BUBBLE_AI: { id: AiPreset; label: string }[] = [\n { id: \"improve\", label: \"Improve writing\" },\n { id: \"shorter\", label: \"Make shorter\" },\n { id: \"simplify\", label: \"Simplify\" },\n { id: \"grammar\", label: \"Fix spelling and grammar\" },\n];\n\nexport function SelectionBubble({\n rect,\n fmt,\n allows,\n saveSel,\n onAi,\n onStyle,\n onMark,\n onInlineCode,\n onLink,\n onComment,\n avoid,\n}: {\n rect: DOMRect;\n /** The editor's own toolbar row (when it is open): the bubble never sits on top of it. */\n avoid?: DOMRect | null;\n fmt: Fmt;\n allows: (f: RichTextFeature) => boolean;\n saveSel: () => void;\n /** Absent when the person has no AI (D58: ai.use) or the host has no AI service: the AI menu and its divider are not drawn. */\n onAi?: (preset: AiPreset) => void;\n onStyle: (tag: string) => void;\n onMark: (cmd: MarkCmd) => void;\n onInlineCode: () => void;\n onLink: () => void;\n onComment?: () => void;\n}) {\n // Above the selection by default; flips below it when above would cover the editor's toolbar or leave the viewport.\n const above = rect.top - 44;\n const blocked = above < 8 || (!!avoid && above < avoid.bottom + 4 && above + 36 > avoid.top);\n const top = blocked ? rect.bottom + 8 : above;\n const styles = stylesFor(allows);\n // centre on the selection with the bubble's real width (it grows with AI, style and comment), never past either edge\n const ref = React.useRef<HTMLDivElement>(null);\n const [w, setW] = React.useState(460);\n React.useLayoutEffect(() => {\n if (ref.current) setW(ref.current.offsetWidth);\n }, [fmt.block, !!onAi, !!onComment]);\n return createPortal(\n // No entrance motion: the bubble shows on every text selection, a 100+/day action.\n <div\n onMouseDown={(e) => {\n if (!(e.target as HTMLElement).closest(\"button\")) e.preventDefault();\n }}\n ref={ref}\n style={{ top, boxShadow: \"var(--kit-shadow-sm)\", left: Math.min(window.innerWidth - w - 8, Math.max(8, rect.left + rect.width / 2 - w / 2)) }}\n data-floating-layer=\"\"\n data-kit-scope=\"\"\n /* V2 floating.tsx:57-59: glass-strong for the raised fill and hairline; the tight shadow-sm (inline, so it beats the\n glass drop) keeps the shadow off the selected text right under the bubble */\n className=\"glass-strong pointer-events-auto fixed z-[calc(var(--kit-z-popover,84)_+_1)] flex h-9 items-center gap-0.5 rounded-kit-lg border border-kit-line px-1\"\n role=\"toolbar\"\n aria-label=\"Selection formatting\"\n >\n {onAi ? (\n <>\n <Menu>\n <MenuTrigger\n onMouseDown={(e) => {\n e.preventDefault();\n saveSel();\n }}\n className=\"flex h-7 items-center gap-1.5 rounded-kit-md px-2 text-kit-sm text-kit-fg hover:bg-kit-hover data-[popup-open]:bg-kit-hover\"\n >\n <Sparkle size={14} /> Improve writing\n </MenuTrigger>\n <MenuContent className=\"w-52\" finalFocus={false}>\n {BUBBLE_AI.map((p) => (\n <MenuItem key={p.id} icon={<Sparkle size={16} />} onClick={() => onAi(p.id)}>\n {p.label}\n </MenuItem>\n ))}\n </MenuContent>\n </Menu>\n <span aria-hidden className=\"mx-0.5 h-4 w-px bg-kit-line\" />\n </>\n ) : null}\n {fmt.block !== \"island\" && styles.length > 1 ? (\n <>\n <StyleMenu block={fmt.block} styles={styles} onPick={onStyle} />\n <span aria-hidden className=\"mx-0.5 h-4 w-px bg-kit-line\" />\n </>\n ) : null}\n {allows(\"bold\") ? <ToolButton label=\"Bold\" icon={<IconBold stroke={1.5} />} shortcut=\"⌘B\" active={fmt.bold} onClick={() => onMark(\"bold\")} /> : null}\n {allows(\"italic\") ? <ToolButton label=\"Italic\" icon={<IconItalic stroke={1.5} />} shortcut=\"⌘I\" active={fmt.italic} onClick={() => onMark(\"italic\")} /> : null}\n {allows(\"underline\") ? <ToolButton label=\"Underline\" icon={<IconUnderline stroke={1.5} />} shortcut=\"⌘U\" active={fmt.underline} onClick={() => onMark(\"underline\")} /> : null}\n {allows(\"strike\") ? <ToolButton label=\"Strikethrough\" icon={<IconStrikethrough stroke={1.5} />} active={fmt.strike} onClick={() => onMark(\"strikeThrough\")} /> : null}\n {/* x² and x₂: one at a time (picking one inside the other swaps them) */}\n {allows(\"sup\") ? <ToolButton label=\"Superscript\" icon={<IconSuperscript stroke={1.5} />} active={fmt.sup} onClick={() => onMark(\"superscript\")} /> : null}\n {allows(\"sub\") ? <ToolButton label=\"Subscript\" icon={<IconSubscript stroke={1.5} />} active={fmt.sub} onClick={() => onMark(\"subscript\")} /> : null}\n {allows(\"code\") ? <ToolButton label=\"Inline code\" icon={<IconCode stroke={1.5} />} shortcut=\"⌘E\" onClick={onInlineCode} /> : null}\n {allows(\"link\") ? <ToolButton label=\"Link\" icon={<IconLink stroke={1.5} />} shortcut=\"⌘K\" active={fmt.onLink} onClick={onLink} /> : null}\n {onComment ? (\n <>\n <span aria-hidden className=\"mx-0.5 h-4 w-px bg-kit-line\" />\n <ToolButton label=\"Comment\" icon={<IconMessage stroke={1.5} />} onClick={onComment} />\n </>\n ) : null}\n </div>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,YAA+C;CAC1D;EAAE,IAAI;EAAW,OAAO;CAAkB;CAC1C;EAAE,IAAI;EAAW,OAAO;CAAe;CACvC;EAAE,IAAI;EAAY,OAAO;CAAW;CACpC;EAAE,IAAI;EAAW,OAAO;CAA2B;AACrD;AAEA,SAAgB,gBAAgB,EAC9B,MACA,KACA,QACA,SACA,MACA,SACA,QACA,cACA,QACA,WACA,SAeC;CAED,MAAM,QAAQ,KAAK,MAAM;CAEzB,MAAM,MADU,QAAQ,KAAM,CAAC,CAAC,SAAS,QAAQ,MAAM,SAAS,KAAK,QAAQ,KAAK,MAAM,MAClE,KAAK,SAAS,IAAI;CACxC,MAAM,SAAS,UAAU,MAAM;CAE/B,MAAM,MAAM,MAAM,OAAuB,IAAI;CAC7C,MAAM,CAAC,GAAG,QAAQ,MAAM,SAAS,GAAG;CACpC,MAAM,sBAAsB;EAC1B,IAAI,IAAI,SAAS,KAAK,IAAI,QAAQ,WAAW;CAC/C,GAAG;EAAC,IAAI;EAAO,CAAC,CAAC;EAAM,CAAC,CAAC;CAAS,CAAC;CACnC,OAAO,aAEL,uBAAC,OAAD;EACE,cAAc,MAAM;GAClB,IAAI,CAAE,EAAE,OAAuB,QAAQ,QAAQ,GAAG,EAAE,eAAe;EACrE;EACK;EACL,OAAO;GAAE;GAAK,WAAW;GAAwB,MAAM,KAAK,IAAI,OAAO,aAAa,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IAAA;GACpJ,OAAO,KAAK,IAAI,uBAAC,YAAD;IAAY,OAAM;IAAY,MAAM,uBAAC,eAAD,EAAe,QAAQ,IAAM,GAAA,KAAA,GAAA,OAAA;;;;;IAAG,QAAQ,IAAI;IAAK,eAAe,OAAO,WAAW;GAAI,GAAA,KAAA,GAAA,OAAA;;;;GAAI,GAAA,IAAA,IAAA;GAC9I,OAAO,MAAM,IAAI,uBAAC,YAAD;IAAY,OAAM;IAAc,MAAM,uBAAC,UAAD,EAAU,QAAQ,IAAM,GAAA,KAAA,GAAA,OAAA;;;;;IAAG,UAAS;IAAK,SAAS;GAAe,GAAA,KAAA,GAAA,OAAA;;;;GAAI,GAAA,IAAA,IAAA;GAC5H,OAAO,MAAM,IAAI,uBAAC,YAAD;IAAY,OAAM;IAAO,MAAM,uBAAC,UAAD,EAAU,QAAQ,IAAM,GAAA,KAAA,GAAA,OAAA;;;;;IAAG,UAAS;IAAK,QAAQ,IAAI;IAAQ,SAAS;GAAS,GAAA,KAAA,GAAA,OAAA;;;;GAAI,GAAA,IAAA,IAAA;GACnI,YACC,uBAAA,UAAA,EAAA,UAAA,CACE,uBAAC,QAAD;IAAM,eAAA;IAAY,WAAU;GAA+B,GAAA,KAAA,GAAA,OAAA;;;;GAC3D,GAAA,IAAA,GAAA,uBAAC,YAAD;IAAY,OAAM;IAAU,MAAM,uBAAC,aAAD,EAAa,QAAQ,IAAM,GAAA,KAAA,GAAA,OAAA;;;;;IAAG,SAAS;GAAY,GAAA,KAAA,GAAA,OAAA;;;;GACrF,GAAA,IAAA,CAAA,EAAA,GAAA,KAAA,GAAA,MAAA;;;;GACA,GAAA,IAAA,IAAA;EACD;;;;;CACL,GAAA,IAAA,GAAA,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"floating.js","names":[],"sources":["../../../src/controls/rich-text/floating.tsx"],"sourcesContent":["/**\n * RICH TEXT · the selection bubble: AI rewrite, style, marks, link (V2 HEAD controls/rich-text/floating.tsx).\n * V2's inline \"Ask AI\" prompt took free text; the host's AI service rewrites by preset only, so it is not drawn.\n */\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { IconBold, IconCode, IconItalic, IconLink, IconMessage, IconStrikethrough, IconSubscript, IconSuperscript, IconUnderline } from \"@tabler/icons-react\";\nimport { Sparkle } from \"../../ui/button\";\nimport { Menu, MenuContent, MenuItem, MenuTrigger } from \"../../ui/overlay\";\nimport type { AiPreset } from \"../../context\";\nimport type { RichTextFeature } from \"./codec\";\nimport { StyleMenu, ToolButton, stylesFor, type Fmt, type MarkCmd } from \"./toolbar\";\n\n/** The bubble's rewrite directions (V2: improve, shorter, punchier, grammar), as the host service's presets. */\nexport const BUBBLE_AI: { id: AiPreset; label: string }[] = [\n { id: \"improve\", label: \"Improve writing\" },\n { id: \"shorter\", label: \"Make shorter\" },\n { id: \"simplify\", label: \"Simplify\" },\n { id: \"grammar\", label: \"Fix spelling and grammar\" },\n];\n\nexport function SelectionBubble({\n rect,\n fmt,\n allows,\n saveSel,\n onAi,\n onStyle,\n onMark,\n onInlineCode,\n onLink,\n onComment,\n avoid,\n}: {\n rect: DOMRect;\n /** The editor's own toolbar row (when it is open): the bubble never sits on top of it. */\n avoid?: DOMRect | null;\n fmt: Fmt;\n allows: (f: RichTextFeature) => boolean;\n saveSel: () => void;\n /** Absent when the person has no AI (D58: ai.use) or the host has no AI service: the AI menu and its divider are not drawn. */\n onAi?: (preset: AiPreset) => void;\n onStyle: (tag: string) => void;\n onMark: (cmd: MarkCmd) => void;\n onInlineCode: () => void;\n onLink: () => void;\n onComment?: () => void;\n}) {\n // Above the selection by default; flips below it when above would cover the editor's toolbar or leave the viewport.\n const above = rect.top - 44;\n const blocked = above < 8 || (!!avoid && above < avoid.bottom + 4 && above + 36 > avoid.top);\n const top = blocked ? rect.bottom + 8 : above;\n const styles = stylesFor(allows);\n // centre on the selection with the bubble's real width (it grows with AI, style and comment), never past either edge\n const ref = React.useRef<HTMLDivElement>(null);\n const [w, setW] = React.useState(460);\n React.useLayoutEffect(() => {\n if (ref.current) setW(ref.current.offsetWidth);\n }, [fmt.block, !!onAi, !!onComment]);\n return createPortal(\n // No entrance motion: the bubble shows on every text selection, a 100+/day action.\n <div\n onMouseDown={(e) => {\n if (!(e.target as HTMLElement).closest(\"button\")) e.preventDefault();\n }}\n ref={ref}\n style={{ top, boxShadow: \"var(--kit-shadow-sm)\", left: Math.min(window.innerWidth - w - 8, Math.max(8, rect.left + rect.width / 2 - w / 2)) }}\n data-floating-layer=\"\"\n data-kit-scope=\"\"\n /* V2 floating.tsx:57-59: glass-strong for the raised fill and hairline; the tight shadow-sm (inline, so it beats the\n glass drop) keeps the shadow off the selected text right under the bubble */\n className=\"glass-strong pointer-events-auto fixed z-[calc(var(--kit-z-popover,84)_+_1)] flex h-9 items-center gap-0.5 rounded-kit-lg border border-kit-line px-1\"\n role=\"toolbar\"\n aria-label=\"Selection formatting\"\n >\n {onAi ? (\n <>\n <Menu>\n <MenuTrigger\n onMouseDown={(e) => {\n e.preventDefault();\n saveSel();\n }}\n className=\"flex h-7 items-center gap-1.5 rounded-kit-md px-2 text-kit-sm text-kit-fg hover:bg-kit-hover data-[popup-open]:bg-kit-hover\"\n >\n <Sparkle size={14} /> Improve writing\n </MenuTrigger>\n <MenuContent className=\"w-52\" finalFocus={false}>\n {BUBBLE_AI.map((p) => (\n <MenuItem key={p.id} icon={<Sparkle size={16} />} onClick={() => onAi(p.id)}>\n {p.label}\n </MenuItem>\n ))}\n </MenuContent>\n </Menu>\n <span aria-hidden className=\"mx-0.5 h-4 w-px bg-kit-line\" />\n </>\n ) : null}\n {fmt.block !== \"island\" && styles.length > 1 ? (\n <>\n <StyleMenu block={fmt.block} styles={styles} onPick={onStyle} />\n <span aria-hidden className=\"mx-0.5 h-4 w-px bg-kit-line\" />\n </>\n ) : null}\n {allows(\"bold\") ? <ToolButton label=\"Bold\" icon={<IconBold stroke={1.5} />} shortcut=\"⌘B\" active={fmt.bold} onClick={() => onMark(\"bold\")} /> : null}\n {allows(\"italic\") ? <ToolButton label=\"Italic\" icon={<IconItalic stroke={1.5} />} shortcut=\"⌘I\" active={fmt.italic} onClick={() => onMark(\"italic\")} /> : null}\n {allows(\"underline\") ? <ToolButton label=\"Underline\" icon={<IconUnderline stroke={1.5} />} shortcut=\"⌘U\" active={fmt.underline} onClick={() => onMark(\"underline\")} /> : null}\n {allows(\"strike\") ? <ToolButton label=\"Strikethrough\" icon={<IconStrikethrough stroke={1.5} />} active={fmt.strike} onClick={() => onMark(\"strikeThrough\")} /> : null}\n {/* x² and x₂: one at a time (picking one inside the other swaps them) */}\n {allows(\"sup\") ? <ToolButton label=\"Superscript\" icon={<IconSuperscript stroke={1.5} />} active={fmt.sup} onClick={() => onMark(\"superscript\")} /> : null}\n {allows(\"sub\") ? <ToolButton label=\"Subscript\" icon={<IconSubscript stroke={1.5} />} active={fmt.sub} onClick={() => onMark(\"subscript\")} /> : null}\n {allows(\"code\") ? <ToolButton label=\"Inline code\" icon={<IconCode stroke={1.5} />} shortcut=\"⌘E\" onClick={onInlineCode} /> : null}\n {allows(\"link\") ? <ToolButton label=\"Link\" icon={<IconLink stroke={1.5} />} shortcut=\"⌘K\" active={fmt.onLink} onClick={onLink} /> : null}\n {onComment ? (\n <>\n <span aria-hidden className=\"mx-0.5 h-4 w-px bg-kit-line\" />\n <ToolButton label=\"Comment\" icon={<IconMessage stroke={1.5} />} onClick={onComment} />\n </>\n ) : null}\n </div>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,IAAa,YAA+C;CAC1D;EAAE,IAAI;EAAW,OAAO;CAAkB;CAC1C;EAAE,IAAI;EAAW,OAAO;CAAe;CACvC;EAAE,IAAI;EAAY,OAAO;CAAW;CACpC;EAAE,IAAI;EAAW,OAAO;CAA2B;AACrD;AAEA,SAAgB,gBAAgB,EAC9B,MACA,KACA,QACA,SACA,MACA,SACA,QACA,cACA,QACA,WACA,SAeC;CAED,MAAM,QAAQ,KAAK,MAAM;CAEzB,MA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,eAAe,OAAO,WAAW;GAAI,CAAA,IAAI;GAC9I,OAAO,MAAM,IAAI,oBAAC,YAAD;IAAY,OAAM;IAAc,MAAM,oBAAC,UAAD,EAAU,QAAQ,IAAM,CAAA;IAAG,UAAS;IAAK,SAAS;GAAe,CAAA,IAAI;GAC5H,OAAO,MAAM,IAAI,oBAAC,YAAD;IAAY,OAAM;IAAO,MAAM,oBAAC,UAAD,EAAU,QAAQ,IAAM,CAAA;IAAG,UAAS;IAAK,QAAQ,IAAI;IAAQ,SAAS;GAAS,CAAA,IAAI;GACnI,YACC,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,QAAD;IAAM,eAAA;IAAY,WAAU;GAA+B,CAAA,GAC3D,oBAAC,YAAD;IAAY,OAAM;IAAU,MAAM,oBAAC,aAAD,EAAa,QAAQ,IAAM,CAAA;IAAG,SAAS;GAAY,CAAA,CACrF,EAAA,CAAA,IACA;EACD;CACL,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
@@ -3,7 +3,7 @@ import { Button } from "../../ui/button.js";
|
|
|
3
3
|
import { Tooltip } from "../../ui/overlay.js";
|
|
4
4
|
import { Textarea } from "../../ui/input.js";
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
import {
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { IconTrash } from "@tabler/icons-react";
|
|
8
8
|
//#region src/controls/rich-text/footnote.tsx
|
|
9
9
|
/**
|
|
@@ -19,7 +19,6 @@ import { IconTrash } from "@tabler/icons-react";
|
|
|
19
19
|
* list V2 notes section (rich-text-editor.tsx:1533-1560): each note a button that edits it, and ↩ back to it
|
|
20
20
|
* back V2 backToMarker (rich-text-editor.tsx:1095-1100): scroll to it, caret after it, a 1200ms accent flash
|
|
21
21
|
*/
|
|
22
|
-
var _jsxFileName = "D:/Github/bettercms/bettercms-backend/packages/kit/src/controls/rich-text/footnote.tsx";
|
|
23
22
|
var FN_MARK = "sup[data-rt=fn]";
|
|
24
23
|
/** The toast when a footnote cannot go where the caret is (V2 rich-text-editor.tsx:613). */
|
|
25
24
|
var FOOTNOTE_REFUSED = {
|
|
@@ -95,23 +94,19 @@ function backToMarker(root, m) {
|
|
|
95
94
|
function FootnoteEditor({ n, note, onChange, onRemove, onDone }) {
|
|
96
95
|
const [v, setV] = React.useState(note);
|
|
97
96
|
const id = React.useId();
|
|
98
|
-
return /* @__PURE__ */
|
|
97
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
99
98
|
className: "flex flex-col gap-2",
|
|
100
99
|
onSubmit: (e) => {
|
|
101
100
|
e.preventDefault();
|
|
102
101
|
onDone();
|
|
103
102
|
},
|
|
104
103
|
children: [
|
|
105
|
-
/* @__PURE__ */
|
|
104
|
+
/* @__PURE__ */ jsxs("label", {
|
|
106
105
|
htmlFor: id,
|
|
107
106
|
className: "text-kit-xs font-medium text-kit-fg-2",
|
|
108
107
|
children: ["Footnote ", n]
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
lineNumber: 106,
|
|
112
|
-
columnNumber: 7
|
|
113
|
-
}, this),
|
|
114
|
-
/* @__PURE__ */ jsxDEV(Textarea, {
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ jsx(Textarea, {
|
|
115
110
|
id,
|
|
116
111
|
autoFocus: true,
|
|
117
112
|
rows: 3,
|
|
@@ -127,118 +122,62 @@ function FootnoteEditor({ n, note, onChange, onRemove, onDone }) {
|
|
|
127
122
|
onDone();
|
|
128
123
|
}
|
|
129
124
|
}
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
lineNumber: 109,
|
|
133
|
-
columnNumber: 7
|
|
134
|
-
}, this),
|
|
135
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
125
|
+
}),
|
|
126
|
+
/* @__PURE__ */ jsxs("div", {
|
|
136
127
|
className: "flex items-center justify-between",
|
|
137
|
-
children: [/* @__PURE__ */
|
|
128
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
138
129
|
size: "xs",
|
|
139
130
|
variant: "ghost",
|
|
140
|
-
leftIcon: /* @__PURE__ */
|
|
141
|
-
fileName: _jsxFileName,
|
|
142
|
-
lineNumber: 127,
|
|
143
|
-
columnNumber: 53
|
|
144
|
-
}, this),
|
|
131
|
+
leftIcon: /* @__PURE__ */ jsx(IconTrash, { stroke: 1.5 }),
|
|
145
132
|
onClick: onRemove,
|
|
146
133
|
className: "hover:text-kit-danger-fg",
|
|
147
134
|
children: "Remove"
|
|
148
|
-
},
|
|
149
|
-
fileName: _jsxFileName,
|
|
150
|
-
lineNumber: 127,
|
|
151
|
-
columnNumber: 9
|
|
152
|
-
}, this), /* @__PURE__ */ jsxDEV(Button, {
|
|
135
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
153
136
|
size: "xs",
|
|
154
137
|
variant: "primary",
|
|
155
138
|
type: "submit",
|
|
156
139
|
children: "Done"
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
lineNumber: 130,
|
|
160
|
-
columnNumber: 9
|
|
161
|
-
}, this)]
|
|
162
|
-
}, void 0, true, {
|
|
163
|
-
fileName: _jsxFileName,
|
|
164
|
-
lineNumber: 126,
|
|
165
|
-
columnNumber: 7
|
|
166
|
-
}, this)
|
|
140
|
+
})]
|
|
141
|
+
})
|
|
167
142
|
]
|
|
168
|
-
}
|
|
169
|
-
fileName: _jsxFileName,
|
|
170
|
-
lineNumber: 99,
|
|
171
|
-
columnNumber: 5
|
|
172
|
-
}, this);
|
|
143
|
+
});
|
|
173
144
|
}
|
|
174
145
|
/** The notes under the body, numbered in text order, each with a way back to its marker. Renders nothing when empty. */
|
|
175
146
|
function FootnotesList({ notes, readOnly, density = "default", onEdit, onBack }) {
|
|
176
147
|
if (!notes.length) return null;
|
|
177
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ jsx("section", {
|
|
178
149
|
"aria-label": "Footnotes",
|
|
179
150
|
className: cn("border-t border-kit-line-subtle text-kit-sm text-kit-fg-2", density === "bare" ? "mt-4 pt-2" : density === "dense" ? "mx-2.5 mb-2 pt-2" : "mx-4 mb-3 pt-2.5"),
|
|
180
|
-
children: /* @__PURE__ */
|
|
151
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
181
152
|
className: "m-0 flex list-decimal flex-col gap-1 pl-5 marker:text-kit-fg-3",
|
|
182
|
-
children: notes.map((n, i) => /* @__PURE__ */
|
|
153
|
+
children: notes.map((n, i) => /* @__PURE__ */ jsx("li", {
|
|
183
154
|
className: "pl-1",
|
|
184
|
-
children: /* @__PURE__ */
|
|
155
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
185
156
|
className: "flex items-start gap-1",
|
|
186
|
-
children: [/* @__PURE__ */
|
|
157
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
187
158
|
type: "button",
|
|
188
159
|
disabled: readOnly,
|
|
189
160
|
"aria-label": `Footnote ${i + 1}: ${n.note || "empty"}. Edit`,
|
|
190
161
|
onClick: () => onEdit(n.el),
|
|
191
162
|
className: "min-w-0 flex-1 rounded-kit-sm text-left leading-relaxed enabled:hover:text-kit-fg",
|
|
192
|
-
children: n.note || /* @__PURE__ */
|
|
163
|
+
children: n.note || /* @__PURE__ */ jsx("span", {
|
|
193
164
|
className: "text-kit-warning-fg",
|
|
194
165
|
children: "Empty note"
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
lineNumber: 170,
|
|
198
|
-
columnNumber: 28
|
|
199
|
-
}, this)
|
|
200
|
-
}, void 0, false, {
|
|
201
|
-
fileName: _jsxFileName,
|
|
202
|
-
lineNumber: 163,
|
|
203
|
-
columnNumber: 15
|
|
204
|
-
}, this), /* @__PURE__ */ jsxDEV(Tooltip, {
|
|
166
|
+
})
|
|
167
|
+
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
205
168
|
content: "Back to the text",
|
|
206
|
-
children: /* @__PURE__ */
|
|
169
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
207
170
|
type: "button",
|
|
208
171
|
"aria-label": `Back to reference ${i + 1}`,
|
|
209
172
|
onClick: () => onBack(n.el),
|
|
210
173
|
className: "shrink-0 rounded-kit-sm px-1 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg",
|
|
211
174
|
children: "↩"
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
fileName: _jsxFileName,
|
|
219
|
-
lineNumber: 172,
|
|
220
|
-
columnNumber: 15
|
|
221
|
-
}, this)]
|
|
222
|
-
}, void 0, true, {
|
|
223
|
-
fileName: _jsxFileName,
|
|
224
|
-
lineNumber: 162,
|
|
225
|
-
columnNumber: 13
|
|
226
|
-
}, this)
|
|
227
|
-
}, i, false, {
|
|
228
|
-
fileName: _jsxFileName,
|
|
229
|
-
lineNumber: 161,
|
|
230
|
-
columnNumber: 11
|
|
231
|
-
}, this))
|
|
232
|
-
}, void 0, false, {
|
|
233
|
-
fileName: _jsxFileName,
|
|
234
|
-
lineNumber: 159,
|
|
235
|
-
columnNumber: 7
|
|
236
|
-
}, this)
|
|
237
|
-
}, void 0, false, {
|
|
238
|
-
fileName: _jsxFileName,
|
|
239
|
-
lineNumber: 155,
|
|
240
|
-
columnNumber: 5
|
|
241
|
-
}, this);
|
|
175
|
+
})
|
|
176
|
+
})]
|
|
177
|
+
})
|
|
178
|
+
}, i))
|
|
179
|
+
})
|
|
180
|
+
});
|
|
242
181
|
}
|
|
243
182
|
//#endregion
|
|
244
183
|
export { FN_MARK, FOOTNOTE_POPOVER_CLASS, FOOTNOTE_REFUSED, FootnoteEditor, FootnotesList, backToMarker, caretAfterMarker, footnoteMarkers, insertFootnote, renumberFootnotes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footnote.js","names":[],"sources":["../../../src/controls/rich-text/footnote.tsx"],"sourcesContent":["/**\n * RICH TEXT · Footnotes (kit-richtext-ui-spec.md §1): V2's inline footnote, stored as the PT inline object\n * `{ _type: \"footnote\", note }`, written in the editor as `<sup data-rt=\"fn\" data-note contenteditable=\"false\">N</sup>`.\n * The number, the notes list and the way back are derived from the markers' text order, never stored.\n *\n * Editor chrome, not an island: the editor owns the clicks and the popover's anchor; this module is the V2 parts.\n * insert V2 ops.ts:182-205: at the caret through the browser's insert (⌘Z takes it back), never inside a rich\n * block or code; null then, and the editor toasts FOOTNOTE_REFUSED (V2 rich-text-editor.tsx:610-615)\n * numbers V2 dom.ts:429-436: the body's own markers in text order, 1…n\n * popover V2 FootnoteEditor (rich-text-editor.tsx:1736-1777) at the marker, w-[320px] rounded p-3\n * list V2 notes section (rich-text-editor.tsx:1533-1560): each note a button that edits it, and ↩ back to it\n * back V2 backToMarker (rich-text-editor.tsx:1095-1100): scroll to it, caret after it, a 1200ms accent flash\n */\nimport * as React from \"react\";\nimport { IconTrash } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport { Button } from \"../../ui/button\";\nimport { Textarea } from \"../../ui/input\";\nimport { Tooltip } from \"../../ui/overlay\";\n\nexport const FN_MARK = \"sup[data-rt=fn]\";\n/** The toast when a footnote cannot go where the caret is (V2 rich-text-editor.tsx:613). */\nexport const FOOTNOTE_REFUSED = {\n title: \"Put the caret in the text first\",\n description: \"Footnotes number the story's own text, not text inside a block.\",\n} as const;\n/** The popover's chrome (V2 rich-text-editor.tsx:1650). */\nexport const FOOTNOTE_POPOVER_CLASS = \"w-[320px] rounded-kit-lg p-3\";\n\n/** The body's own markers in text order (markers inside a rich block are not the body's). */\nexport const footnoteMarkers = (root: HTMLElement): HTMLElement[] =>\n Array.from(root.querySelectorAll<HTMLElement>(FN_MARK)).filter((m) => !m.closest(\"[data-rt-island],[data-rt-isolate]\"));\n\n/** Numbers the markers 1…n in text order; returns them with their notes, for the list. */\nexport function renumberFootnotes(root: HTMLElement): { el: HTMLElement; note: string }[] {\n return footnoteMarkers(root).map((m, i) => {\n if (m.textContent !== String(i + 1)) m.textContent = String(i + 1);\n return { el: m, note: m.getAttribute(\"data-note\") ?? \"\" };\n });\n}\n\n/** A new, empty marker at the caret. Null when the caret is outside the body's text (a rich block, code, elsewhere). */\nexport function insertFootnote(root: HTMLElement): HTMLElement | null {\n const s = window.getSelection();\n if (!s || !s.rangeCount || !root.contains(s.anchorNode)) return null;\n const at = s.anchorNode?.nodeType === 1 ? (s.anchorNode as HTMLElement) : s.anchorNode?.parentElement;\n if (!at || at.closest(\"[data-rt-island],[data-rt-isolate]\") || at.closest(\"pre\")) return null;\n root.focus({ preventScroll: true });\n if (typeof document.execCommand === \"function\") document.execCommand(\"insertHTML\", false, `<sup data-rt=\"fn\" data-note=\"\" contenteditable=\"false\" data-fn-new=\"\">1</sup>`);\n let sup = root.querySelector<HTMLElement>(\"sup[data-fn-new]\");\n if (!sup) {\n // the browser dropped the marker (or has no execCommand): place it by hand\n sup = document.createElement(\"sup\");\n sup.setAttribute(\"data-rt\", \"fn\");\n sup.setAttribute(\"data-note\", \"\");\n sup.setAttribute(\"contenteditable\", \"false\");\n sup.textContent = \"1\";\n const r = s.getRangeAt(0);\n r.collapse(false);\n r.insertNode(sup);\n const after = document.createTextNode(\"\");\n sup.after(after);\n const c = document.createRange();\n c.setStart(after, after.length);\n c.collapse(true);\n s.removeAllRanges();\n s.addRange(c);\n }\n sup.removeAttribute(\"data-fn-new\");\n renumberFootnotes(root);\n return sup;\n}\n\n/** The caret right after a marker, in the body. */\nexport function caretAfterMarker(root: HTMLElement, m: HTMLElement) {\n const s = window.getSelection();\n if (!s || !m.isConnected) return;\n root.focus({ preventScroll: true });\n const r = document.createRange();\n r.setStartAfter(m);\n r.collapse(true);\n s.removeAllRanges();\n s.addRange(r);\n}\n\n/** \"Back to the text\": scroll the marker to the centre, caret after it, and flash it (1200ms). */\nexport function backToMarker(root: HTMLElement, m: HTMLElement) {\n if (!m.isConnected) return;\n m.scrollIntoView?.({ block: \"center\", behavior: \"smooth\" });\n caretAfterMarker(root, m);\n m.animate?.([{ boxShadow: \"0 0 0 3px var(--kit-accent-soft)\" }, { boxShadow: \"0 0 0 0 transparent\" }], { duration: 1200 });\n}\n\n/** The note of one footnote: one setting, edited in a popover at its marker (V2 D54 / D55). */\nexport function FootnoteEditor({ n, note, onChange, onRemove, onDone }: { n: number; note: string; onChange: (v: string) => void; onRemove: () => void; onDone: () => void }) {\n const [v, setV] = React.useState(note);\n const id = React.useId();\n return (\n <form\n className=\"flex flex-col gap-2\"\n onSubmit={(e) => {\n e.preventDefault();\n onDone();\n }}\n >\n <label htmlFor={id} className=\"text-kit-xs font-medium text-kit-fg-2\">\n Footnote {n}\n </label>\n <Textarea\n id={id}\n autoFocus\n rows={3}\n value={v}\n placeholder=\"Write the note\"\n onChange={(e) => {\n setV(e.target.value);\n onChange(e.target.value);\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n onDone();\n }\n }}\n />\n <div className=\"flex items-center justify-between\">\n <Button size=\"xs\" variant=\"ghost\" leftIcon={<IconTrash stroke={1.5} />} onClick={onRemove} className=\"hover:text-kit-danger-fg\">\n Remove\n </Button>\n <Button size=\"xs\" variant=\"primary\" type=\"submit\">\n Done\n </Button>\n </div>\n </form>\n );\n}\n\n/** The notes under the body, numbered in text order, each with a way back to its marker. Renders nothing when empty. */\nexport function FootnotesList({\n notes,\n readOnly,\n density = \"default\",\n onEdit,\n onBack,\n}: {\n notes: { el: HTMLElement; note: string }[];\n readOnly?: boolean;\n /** the editor's spacing: bare (no chrome), dense (panel), default */\n density?: \"bare\" | \"dense\" | \"default\";\n onEdit: (el: HTMLElement) => void;\n onBack: (el: HTMLElement) => void;\n}) {\n if (!notes.length) return null;\n return (\n <section\n aria-label=\"Footnotes\"\n className={cn(\"border-t border-kit-line-subtle text-kit-sm text-kit-fg-2\", density === \"bare\" ? \"mt-4 pt-2\" : density === \"dense\" ? \"mx-2.5 mb-2 pt-2\" : \"mx-4 mb-3 pt-2.5\")}\n >\n <ol className=\"m-0 flex list-decimal flex-col gap-1 pl-5 marker:text-kit-fg-3\">\n {notes.map((n, i) => (\n <li key={i} className=\"pl-1\">\n <span className=\"flex items-start gap-1\">\n <button\n type=\"button\"\n disabled={readOnly}\n aria-label={`Footnote ${i + 1}: ${n.note || \"empty\"}. Edit`}\n onClick={() => onEdit(n.el)}\n className=\"min-w-0 flex-1 rounded-kit-sm text-left leading-relaxed enabled:hover:text-kit-fg\"\n >\n {n.note || <span className=\"text-kit-warning-fg\">Empty note</span>}\n </button>\n <Tooltip content=\"Back to the text\">\n <button type=\"button\" aria-label={`Back to reference ${i + 1}`} onClick={() => onBack(n.el)} className=\"shrink-0 rounded-kit-sm px-1 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n ↩\n </button>\n </Tooltip>\n </span>\n </li>\n ))}\n </ol>\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,UAAU;;AAEvB,IAAa,mBAAmB;CAC9B,OAAO;CACP,aAAa;AACf;;AAEA,IAAa,yBAAyB;;AAGtC,IAAa,mBAAmB,SAC9B,MAAM,KAAK,KAAK,iBAA8B,OAAO,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,QAAQ,oCAAoC,CAAC;;AAGxH,SAAgB,kBAAkB,MAAwD;CACxF,OAAO,gBAAgB,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM;EACzC,IAAI,EAAE,gBAAgB,OAAO,IAAI,CAAC,GAAG,EAAE,cAAc,OAAO,IAAI,CAAC;EACjE,OAAO;GAAE,IAAI;GAAG,MAAM,EAAE,aAAa,WAAW,KAAK;EAAG;CAC1D,CAAC;AACH;;AAGA,SAAgB,eAAe,MAAuC;CACpE,MAAM,IAAI,OAAO,aAAa;CAC9B,IAAI,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,KAAK,SAAS,EAAE,UAAU,GAAG,OAAO;CAChE,MAAM,KAAK,EAAE,YAAY,aAAa,IAAK,EAAE,aAA6B,EAAE,YAAY;CACxF,IAAI,CAAC,MAAM,GAAG,QAAQ,oCAAoC,KAAK,G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A,uBAAC,MAAD;GAAI,WAAU;GACX,UAAA,MAAM,KAAK,GAAG,MACb,uBAAC,MAAD;IAAY,WAAU;IACpB,UAAA,uBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACE,uBAAC,UAAD;MACE,MAAK;MACL,UAAU;MACV,cAAY,YAAY,IAAI,EAAE,IAAI,EAAE,QAAQ,QAAQ;MACpD,eAAe,OAAO,EAAE,EAAE;MAC1B,WAAU;MAET,UAAA,EAAE,QAAQ,uBAAC,QAAD;OAAM,WAAU;OAAsB,UAAA;MAAgB,GAAA,KAAA,GAAA,OAAA;;;;;KAC3D,GAAA,KAAA,GAAA,OAAA;;;;KACR,GAAA,IAAA,GAAA,uBAAC,SAAD;MAAS,SAAQ;MACf,UAAA,uBAAC,UAAD;OAAQ,MAAK;OAAS,cAAY,qBAAqB,IAAI;OAAK,eAAe,OAAO,EAAE,EAAE;OAAG,WAAU;OAAkF,UAAA;MAEjL,GAAA,KAAA,GAAA,OAAA;;;;;KACD,GAAA,KAAA,GAAA,OAAA;;;;KACL,GAAA,IAAA,CAAA;;;;;;GACJ,GAjBK,GAAA,OAAA;;;;GAiBL,GAAA,IAAA,CACL;EACC,GAAA,KAAA,GAAA,OAAA;;;;;CACG,GAAA,KAAA,GAAA,OAAA;;;;;AAEb"}
|
|
1
|
+
{"version":3,"file":"footnote.js","names":[],"sources":["../../../src/controls/rich-text/footnote.tsx"],"sourcesContent":["/**\n * RICH TEXT · Footnotes (kit-richtext-ui-spec.md §1): V2's inline footnote, stored as the PT inline object\n * `{ _type: \"footnote\", note }`, written in the editor as `<sup data-rt=\"fn\" data-note contenteditable=\"false\">N</sup>`.\n * The number, the notes list and the way back are derived from the markers' text order, never stored.\n *\n * Editor chrome, not an island: the editor owns the clicks and the popover's anchor; this module is the V2 parts.\n * insert V2 ops.ts:182-205: at the caret through the browser's insert (⌘Z takes it back), never inside a rich\n * block or code; null then, and the editor toasts FOOTNOTE_REFUSED (V2 rich-text-editor.tsx:610-615)\n * numbers V2 dom.ts:429-436: the body's own markers in text order, 1…n\n * popover V2 FootnoteEditor (rich-text-editor.tsx:1736-1777) at the marker, w-[320px] rounded p-3\n * list V2 notes section (rich-text-editor.tsx:1533-1560): each note a button that edits it, and ↩ back to it\n * back V2 backToMarker (rich-text-editor.tsx:1095-1100): scroll to it, caret after it, a 1200ms accent flash\n */\nimport * as React from \"react\";\nimport { IconTrash } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport { Button } from \"../../ui/button\";\nimport { Textarea } from \"../../ui/input\";\nimport { Tooltip } from \"../../ui/overlay\";\n\nexport const FN_MARK = \"sup[data-rt=fn]\";\n/** The toast when a footnote cannot go where the caret is (V2 rich-text-editor.tsx:613). */\nexport const FOOTNOTE_REFUSED = {\n title: \"Put the caret in the text first\",\n description: \"Footnotes number the story's own text, not text inside a block.\",\n} as const;\n/** The popover's chrome (V2 rich-text-editor.tsx:1650). */\nexport const FOOTNOTE_POPOVER_CLASS = \"w-[320px] rounded-kit-lg p-3\";\n\n/** The body's own markers in text order (markers inside a rich block are not the body's). */\nexport const footnoteMarkers = (root: HTMLElement): HTMLElement[] =>\n Array.from(root.querySelectorAll<HTMLElement>(FN_MARK)).filter((m) => !m.closest(\"[data-rt-island],[data-rt-isolate]\"));\n\n/** Numbers the markers 1…n in text order; returns them with their notes, for the list. */\nexport function renumberFootnotes(root: HTMLElement): { el: HTMLElement; note: string }[] {\n return footnoteMarkers(root).map((m, i) => {\n if (m.textContent !== String(i + 1)) m.textContent = String(i + 1);\n return { el: m, note: m.getAttribute(\"data-note\") ?? \"\" };\n });\n}\n\n/** A new, empty marker at the caret. Null when the caret is outside the body's text (a rich block, code, elsewhere). */\nexport function insertFootnote(root: HTMLElement): HTMLElement | null {\n const s = window.getSelection();\n if (!s || !s.rangeCount || !root.contains(s.anchorNode)) return null;\n const at = s.anchorNode?.nodeType === 1 ? (s.anchorNode as HTMLElement) : s.anchorNode?.parentElement;\n if (!at || at.closest(\"[data-rt-island],[data-rt-isolate]\") || at.closest(\"pre\")) return null;\n root.focus({ preventScroll: true });\n if (typeof document.execCommand === \"function\") document.execCommand(\"insertHTML\", false, `<sup data-rt=\"fn\" data-note=\"\" contenteditable=\"false\" data-fn-new=\"\">1</sup>`);\n let sup = root.querySelector<HTMLElement>(\"sup[data-fn-new]\");\n if (!sup) {\n // the browser dropped the marker (or has no execCommand): place it by hand\n sup = document.createElement(\"sup\");\n sup.setAttribute(\"data-rt\", \"fn\");\n sup.setAttribute(\"data-note\", \"\");\n sup.setAttribute(\"contenteditable\", \"false\");\n sup.textContent = \"1\";\n const r = s.getRangeAt(0);\n r.collapse(false);\n r.insertNode(sup);\n const after = document.createTextNode(\"\");\n sup.after(after);\n const c = document.createRange();\n c.setStart(after, after.length);\n c.collapse(true);\n s.removeAllRanges();\n s.addRange(c);\n }\n sup.removeAttribute(\"data-fn-new\");\n renumberFootnotes(root);\n return sup;\n}\n\n/** The caret right after a marker, in the body. */\nexport function caretAfterMarker(root: HTMLElement, m: HTMLElement) {\n const s = window.getSelection();\n if (!s || !m.isConnected) return;\n root.focus({ preventScroll: true });\n const r = document.createRange();\n r.setStartAfter(m);\n r.collapse(true);\n s.removeAllRanges();\n s.addRange(r);\n}\n\n/** \"Back to the text\": scroll the marker to the centre, caret after it, and flash it (1200ms). */\nexport function backToMarker(root: HTMLElement, m: HTMLElement) {\n if (!m.isConnected) return;\n m.scrollIntoView?.({ block: \"center\", behavior: \"smooth\" });\n caretAfterMarker(root, m);\n m.animate?.([{ boxShadow: \"0 0 0 3px var(--kit-accent-soft)\" }, { boxShadow: \"0 0 0 0 transparent\" }], { duration: 1200 });\n}\n\n/** The note of one footnote: one setting, edited in a popover at its marker (V2 D54 / D55). */\nexport function FootnoteEditor({ n, note, onChange, onRemove, onDone }: { n: number; note: string; onChange: (v: string) => void; onRemove: () => void; onDone: () => void }) {\n const [v, setV] = React.useState(note);\n const id = React.useId();\n return (\n <form\n className=\"flex flex-col gap-2\"\n onSubmit={(e) => {\n e.preventDefault();\n onDone();\n }}\n >\n <label htmlFor={id} className=\"text-kit-xs font-medium text-kit-fg-2\">\n Footnote {n}\n </label>\n <Textarea\n id={id}\n autoFocus\n rows={3}\n value={v}\n placeholder=\"Write the note\"\n onChange={(e) => {\n setV(e.target.value);\n onChange(e.target.value);\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n onDone();\n }\n }}\n />\n <div className=\"flex items-center justify-between\">\n <Button size=\"xs\" variant=\"ghost\" leftIcon={<IconTrash stroke={1.5} />} onClick={onRemove} className=\"hover:text-kit-danger-fg\">\n Remove\n </Button>\n <Button size=\"xs\" variant=\"primary\" type=\"submit\">\n Done\n </Button>\n </div>\n </form>\n );\n}\n\n/** The notes under the body, numbered in text order, each with a way back to its marker. Renders nothing when empty. */\nexport function FootnotesList({\n notes,\n readOnly,\n density = \"default\",\n onEdit,\n onBack,\n}: {\n notes: { el: HTMLElement; note: string }[];\n readOnly?: boolean;\n /** the editor's spacing: bare (no chrome), dense (panel), default */\n density?: \"bare\" | \"dense\" | \"default\";\n onEdit: (el: HTMLElement) => void;\n onBack: (el: HTMLElement) => void;\n}) {\n if (!notes.length) return null;\n return (\n <section\n aria-label=\"Footnotes\"\n className={cn(\"border-t border-kit-line-subtle text-kit-sm text-kit-fg-2\", density === \"bare\" ? \"mt-4 pt-2\" : density === \"dense\" ? \"mx-2.5 mb-2 pt-2\" : \"mx-4 mb-3 pt-2.5\")}\n >\n <ol className=\"m-0 flex list-decimal flex-col gap-1 pl-5 marker:text-kit-fg-3\">\n {notes.map((n, i) => (\n <li key={i} className=\"pl-1\">\n <span className=\"flex items-start gap-1\">\n <button\n type=\"button\"\n disabled={readOnly}\n aria-label={`Footnote ${i + 1}: ${n.note || \"empty\"}. Edit`}\n onClick={() => onEdit(n.el)}\n className=\"min-w-0 flex-1 rounded-kit-sm text-left leading-relaxed enabled:hover:text-kit-fg\"\n >\n {n.note || <span className=\"text-kit-warning-fg\">Empty note</span>}\n </button>\n <Tooltip content=\"Back to the text\">\n <button type=\"button\" aria-label={`Back to reference ${i + 1}`} onClick={() => onBack(n.el)} className=\"shrink-0 rounded-kit-sm px-1 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg\">\n ↩\n </button>\n </Tooltip>\n </span>\n </li>\n ))}\n </ol>\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,UAAU;;AAEvB,IAAa,mBAAmB;CAC9B,OAAO;CACP,aAAa;AACf;;AAEA,IAAa,yBAAyB;;AAGtC,IAAa,mBAAmB,SAC9B,MAAM,KAAK,KAAK,iBAA8B,OAAO,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,QAAQ,oCAAoC,CAAC;;AAGxH,SAAgB,kBAAkB,MAAwD;CACxF,OAAO,gBAAgB,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM;EACzC,IAAI,EAAE,gBAAgB,OAAO,IAAI,CAAC,GAAG,EAAE,cAAc,OAAO,IAAI,CAAC;EACjE,OAAO;GAAE,IAAI;GAAG,MAAM,EAAE,aAAa,WAAW,KAAK;EAAG;CAC1D,CAAC;AACH;;AAGA,SAAgB,eAAe,MAAuC;CACpE,MAAM,IAAI,OAAO,aAAa;CAC9B,IAAI,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,KAAK,SAAS,EAAE,UAAU,GAAG,OAAO;CAChE,MAAM,KAAK,EAAE,YAAY,aAAa,IAAK,EAAE,aAA6B,EAAE,YAAY;CACxF,IAAI,CAAC,MAAM,GAAG,QAAQ,oCAAoC,KAAK,GAAG,QAAQ,KAAK,GAAG,OAAO;CACzF,KAAK,MAAM,EAAE,eAAe,KAAK,CAAC;CAClC,IAAI,OAAO,SAAS,gBAAgB,YAAY,SAAS,YAAY,cAAc,OAAO,gFAAgF;CAC1K,IAAI,MAAM,KAAK,cAA2B,kBAAkB;CAC5D,IAAI,CAAC,KAAK;EAER,MAAM,SAAS,cAAc,KAAK;EA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D;MAAS,SAAQ;MACf,UAAA,oBAAC,UAAD;OAAQ,MAAK;OAAS,cAAY,qBAAqB,IAAI;OAAK,eAAe,OAAO,EAAE,EAAE;OAAG,WAAU;OAAkF,UAAA;MAEjL,CAAA;KACD,CAAA,CACL;;GACJ,GAjBK,CAiBL,CACL;EACC,CAAA;CACG,CAAA;AAEb"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "../../lib/cn.js";
|
|
2
2
|
import { ArticleEmpty, ArticlePanelBlock } from "./article-shell.js";
|
|
3
|
-
import {
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { IconPhoto } from "@tabler/icons-react";
|
|
5
5
|
//#region src/controls/rich-text/gallery.tsx
|
|
6
6
|
/**
|
|
@@ -13,7 +13,6 @@ import { IconPhoto } from "@tabler/icons-react";
|
|
|
13
13
|
* preview V2 article-blocks.tsx:451-480: Grid in 2 columns for 2 or 4 images, else 3, square crops; Carousel a
|
|
14
14
|
* 72%-wide scroll-snap row of 4:3 crops with "N images · carousel"; "Add images" when there are none.
|
|
15
15
|
*/
|
|
16
|
-
var _jsxFileName = "D:/Github/bettercms/bettercms-backend/packages/kit/src/controls/rich-text/gallery.tsx";
|
|
17
16
|
var GALLERY_LABEL = "Gallery";
|
|
18
17
|
var galleryDefault = () => ({
|
|
19
18
|
layout: "grid",
|
|
@@ -73,56 +72,32 @@ var GALLERY_SCHEMA = {
|
|
|
73
72
|
};
|
|
74
73
|
function GalleryPreview({ m, onAdd, ro }) {
|
|
75
74
|
const imgs = m.images.filter((x) => x.image?.url);
|
|
76
|
-
if (!imgs.length) return /* @__PURE__ */
|
|
77
|
-
icon: /* @__PURE__ */
|
|
78
|
-
fileName: _jsxFileName,
|
|
79
|
-
lineNumber: 74,
|
|
80
|
-
columnNumber: 48
|
|
81
|
-
}, this),
|
|
75
|
+
if (!imgs.length) return /* @__PURE__ */ jsx(ArticleEmpty, {
|
|
76
|
+
icon: /* @__PURE__ */ jsx(IconPhoto, { stroke: 1.5 }),
|
|
82
77
|
title: GALLERY_LABEL,
|
|
83
78
|
action: "Add images",
|
|
84
79
|
onAction: onAdd,
|
|
85
80
|
ro
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
lineNumber: 74,
|
|
89
|
-
columnNumber: 28
|
|
90
|
-
}, this);
|
|
91
|
-
if (m.layout === "carousel") return /* @__PURE__ */ jsxDEV("figure", {
|
|
81
|
+
});
|
|
82
|
+
if (m.layout === "carousel") return /* @__PURE__ */ jsxs("figure", {
|
|
92
83
|
className: "m-0",
|
|
93
84
|
"data-field": "images",
|
|
94
|
-
children: [/* @__PURE__ */
|
|
85
|
+
children: [/* @__PURE__ */ jsx("ul", {
|
|
95
86
|
className: "m-0 flex snap-x gap-2 overflow-x-auto p-0 pb-1",
|
|
96
87
|
"aria-label": GALLERY_LABEL,
|
|
97
|
-
children: imgs.map((x) => /* @__PURE__ */
|
|
88
|
+
children: imgs.map((x) => /* @__PURE__ */ jsxs("li", {
|
|
98
89
|
className: "w-[72%] shrink-0 snap-start list-none",
|
|
99
|
-
children: [/* @__PURE__ */
|
|
90
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
100
91
|
src: x.image.url,
|
|
101
92
|
alt: x.image.alt ?? "",
|
|
102
93
|
draggable: false,
|
|
103
94
|
className: "block aspect-[4/3] w-full rounded-kit-lg border border-kit-line object-cover"
|
|
104
|
-
},
|
|
105
|
-
fileName: _jsxFileName,
|
|
106
|
-
lineNumber: 81,
|
|
107
|
-
columnNumber: 15
|
|
108
|
-
}, this), x.caption ? /* @__PURE__ */ jsxDEV("p", {
|
|
95
|
+
}), x.caption ? /* @__PURE__ */ jsx("p", {
|
|
109
96
|
className: "mt-1 truncate text-kit-xs text-kit-fg-3",
|
|
110
97
|
children: x.caption
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
columnNumber: 28
|
|
115
|
-
}, this) : null]
|
|
116
|
-
}, x._key, true, {
|
|
117
|
-
fileName: _jsxFileName,
|
|
118
|
-
lineNumber: 80,
|
|
119
|
-
columnNumber: 13
|
|
120
|
-
}, this))
|
|
121
|
-
}, void 0, false, {
|
|
122
|
-
fileName: _jsxFileName,
|
|
123
|
-
lineNumber: 78,
|
|
124
|
-
columnNumber: 9
|
|
125
|
-
}, this), /* @__PURE__ */ jsxDEV("figcaption", {
|
|
98
|
+
}) : null]
|
|
99
|
+
}, x._key))
|
|
100
|
+
}), /* @__PURE__ */ jsxs("figcaption", {
|
|
126
101
|
className: "mt-1 text-kit-2xs text-kit-fg-3",
|
|
127
102
|
children: [
|
|
128
103
|
imgs.length,
|
|
@@ -130,56 +105,28 @@ function GalleryPreview({ m, onAdd, ro }) {
|
|
|
130
105
|
imgs.length === 1 ? "image" : "images",
|
|
131
106
|
" · carousel"
|
|
132
107
|
]
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
columnNumber: 9
|
|
137
|
-
}, this)]
|
|
138
|
-
}, void 0, true, {
|
|
139
|
-
fileName: _jsxFileName,
|
|
140
|
-
lineNumber: 77,
|
|
141
|
-
columnNumber: 7
|
|
142
|
-
}, this);
|
|
143
|
-
return /* @__PURE__ */ jsxDEV("figure", {
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
return /* @__PURE__ */ jsx("figure", {
|
|
144
111
|
className: "m-0",
|
|
145
112
|
"data-field": "images",
|
|
146
|
-
children: /* @__PURE__ */
|
|
113
|
+
children: /* @__PURE__ */ jsx("ul", {
|
|
147
114
|
className: cn("m-0 grid gap-2 p-0", imgs.length === 2 || imgs.length === 4 ? "grid-cols-2" : "grid-cols-3"),
|
|
148
115
|
"aria-label": GALLERY_LABEL,
|
|
149
|
-
children: imgs.map((x) => /* @__PURE__ */
|
|
116
|
+
children: imgs.map((x) => /* @__PURE__ */ jsxs("li", {
|
|
150
117
|
className: "list-none",
|
|
151
|
-
children: [/* @__PURE__ */
|
|
118
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
152
119
|
src: x.image.url,
|
|
153
120
|
alt: x.image.alt ?? "",
|
|
154
121
|
draggable: false,
|
|
155
122
|
className: "block aspect-square w-full rounded-kit-lg border border-kit-line object-cover"
|
|
156
|
-
},
|
|
157
|
-
fileName: _jsxFileName,
|
|
158
|
-
lineNumber: 96,
|
|
159
|
-
columnNumber: 13
|
|
160
|
-
}, this), x.caption ? /* @__PURE__ */ jsxDEV("p", {
|
|
123
|
+
}), x.caption ? /* @__PURE__ */ jsx("p", {
|
|
161
124
|
className: "mt-1 truncate text-kit-xs text-kit-fg-3",
|
|
162
125
|
children: x.caption
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}, this) : null]
|
|
168
|
-
}, x._key, true, {
|
|
169
|
-
fileName: _jsxFileName,
|
|
170
|
-
lineNumber: 95,
|
|
171
|
-
columnNumber: 11
|
|
172
|
-
}, this))
|
|
173
|
-
}, void 0, false, {
|
|
174
|
-
fileName: _jsxFileName,
|
|
175
|
-
lineNumber: 93,
|
|
176
|
-
columnNumber: 7
|
|
177
|
-
}, this)
|
|
178
|
-
}, void 0, false, {
|
|
179
|
-
fileName: _jsxFileName,
|
|
180
|
-
lineNumber: 92,
|
|
181
|
-
columnNumber: 5
|
|
182
|
-
}, this);
|
|
126
|
+
}) : null]
|
|
127
|
+
}, x._key))
|
|
128
|
+
})
|
|
129
|
+
});
|
|
183
130
|
}
|
|
184
131
|
var asImages = (v) => Array.isArray(v) ? v.map((x, i) => {
|
|
185
132
|
const o = x ?? {};
|
|
@@ -190,7 +137,7 @@ var asImages = (v) => Array.isArray(v) ? v.map((x, i) => {
|
|
|
190
137
|
};
|
|
191
138
|
}) : [];
|
|
192
139
|
function GalleryBlock({ m, set, el, ctx, autoFocus }) {
|
|
193
|
-
return /* @__PURE__ */
|
|
140
|
+
return /* @__PURE__ */ jsx(ArticlePanelBlock, {
|
|
194
141
|
label: GALLERY_LABEL,
|
|
195
142
|
kind: "gallery",
|
|
196
143
|
schema: GALLERY_SCHEMA,
|
|
@@ -207,20 +154,12 @@ function GalleryBlock({ m, set, el, ctx, autoFocus }) {
|
|
|
207
154
|
images: asImages(v.images),
|
|
208
155
|
layout: v.layout === "carousel" ? "carousel" : "grid"
|
|
209
156
|
}),
|
|
210
|
-
children: (open, ro) => /* @__PURE__ */
|
|
157
|
+
children: (open, ro) => /* @__PURE__ */ jsx(GalleryPreview, {
|
|
211
158
|
m,
|
|
212
159
|
onAdd: () => open("images"),
|
|
213
160
|
ro
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
lineNumber: 135,
|
|
217
|
-
columnNumber: 22
|
|
218
|
-
}, this)
|
|
219
|
-
}, void 0, false, {
|
|
220
|
-
fileName: _jsxFileName,
|
|
221
|
-
lineNumber: 123,
|
|
222
|
-
columnNumber: 5
|
|
223
|
-
}, this);
|
|
161
|
+
})
|
|
162
|
+
});
|
|
224
163
|
}
|
|
225
164
|
//#endregion
|
|
226
165
|
export { GALLERY_LABEL, GALLERY_SCHEMA, GalleryBlock, GalleryPreview, galleryDefault };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gallery.js","names":[],"sources":["../../../src/controls/rich-text/gallery.tsx"],"sourcesContent":["/**\n * RICH TEXT · Gallery (kit-richtext-ui-spec.md §2): V2's article block, stored as the PT block object\n * `{ _type: \"gallery\", layout: \"grid\" | \"carousel\", images: { _key, image, caption? }[] }`; each image is the rich-text\n * image's own shape (src/alt + media id), so media rewrites and alt audits reach it.\n *\n * form V2 article.ts:75-114: Images (a grid list, 2–24, each a required image + caption ≤160), Layout\n * (Grid | Carousel, segmented). A list of objects → the floating properties panel (D54); a fresh insert opens it.\n * preview V2 article-blocks.tsx:451-480: Grid in 2 columns for 2 or 4 images, else 3, square crops; Carousel a\n * 72%-wide scroll-snap row of 4:3 crops with \"N images · carousel\"; \"Add images\" when there are none.\n */\nimport { IconPhoto } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport type { TypeSchema } from \"../../schema/types\";\nimport type { ImageValue } from \"../media\";\nimport { ArticleEmpty, ArticlePanelBlock } from \"./article-shell\";\nimport type { IslandCtx } from \"./blocks\";\nimport type { IslandEl } from \"./dom\";\n\nexport interface GalleryImage {\n _key: string;\n image: ImageValue | null;\n caption: string;\n}\nexport interface GalleryModel {\n layout: \"grid\" | \"carousel\";\n images: GalleryImage[];\n}\nexport const GALLERY_LABEL = \"Gallery\";\nexport const galleryDefault = (): GalleryModel => ({ layout: \"grid\", images: [] });\n\nexport const GALLERY_SCHEMA: TypeSchema = {\n name: \"gallery\",\n title: GALLERY_LABEL,\n kind: \"object\",\n icon: \"photo\",\n fields: [\n {\n name: \"images\",\n title: \"Images\",\n type: \"array\",\n itemNoun: \"image\",\n arrayLayout: \"grid\",\n validation: { min: 2, max: 24 },\n of: [\n {\n name: \"photo\",\n title: \"Image\",\n type: \"object\",\n icon: \"photo\",\n preview: { title: \"caption\", media: \"image\", fallback: \"Untitled image\" },\n fields: [\n { name: \"image\", title: \"Image\", type: \"image\", validation: { required: true } },\n { name: \"caption\", title: \"Caption\", type: \"string\", validation: { max: 160 } },\n ],\n },\n ],\n },\n {\n name: \"layout\",\n title: \"Layout\",\n type: \"select\",\n layout: \"segmented\",\n initialValue: \"grid\",\n options: [\n { value: \"grid\", label: \"Grid\" },\n { value: \"carousel\", label: \"Carousel\" },\n ],\n },\n ],\n};\n\nexport function GalleryPreview({ m, onAdd, ro }: { m: GalleryModel; onAdd: () => void; ro: boolean }) {\n const imgs = m.images.filter((x) => x.image?.url);\n if (!imgs.length) return <ArticleEmpty icon={<IconPhoto stroke={1.5} />} title={GALLERY_LABEL} action=\"Add images\" onAction={onAdd} ro={ro} />;\n if (m.layout === \"carousel\")\n return (\n <figure className=\"m-0\" data-field=\"images\">\n <ul className=\"m-0 flex snap-x gap-2 overflow-x-auto p-0 pb-1\" aria-label={GALLERY_LABEL}>\n {imgs.map((x) => (\n <li key={x._key} className=\"w-[72%] shrink-0 snap-start list-none\">\n <img src={x.image!.url} alt={x.image!.alt ?? \"\"} draggable={false} className=\"block aspect-[4/3] w-full rounded-kit-lg border border-kit-line object-cover\" />\n {x.caption ? <p className=\"mt-1 truncate text-kit-xs text-kit-fg-3\">{x.caption}</p> : null}\n </li>\n ))}\n </ul>\n <figcaption className=\"mt-1 text-kit-2xs text-kit-fg-3\">\n {imgs.length} {imgs.length === 1 ? \"image\" : \"images\"} · carousel\n </figcaption>\n </figure>\n );\n return (\n <figure className=\"m-0\" data-field=\"images\">\n <ul className={cn(\"m-0 grid gap-2 p-0\", imgs.length === 2 || imgs.length === 4 ? \"grid-cols-2\" : \"grid-cols-3\")} aria-label={GALLERY_LABEL}>\n {imgs.map((x) => (\n <li key={x._key} className=\"list-none\">\n <img src={x.image!.url} alt={x.image!.alt ?? \"\"} draggable={false} className=\"block aspect-square w-full rounded-kit-lg border border-kit-line object-cover\" />\n {x.caption ? <p className=\"mt-1 truncate text-kit-xs text-kit-fg-3\">{x.caption}</p> : null}\n </li>\n ))}\n </ul>\n </figure>\n );\n}\n\nconst asImages = (v: unknown): GalleryImage[] =>\n Array.isArray(v)\n ? v.map((x, i) => {\n const o = (x ?? {}) as Record<string, unknown>;\n return { _key: typeof o._key === \"string\" ? o._key : `g${i}`, image: (o.image as ImageValue | null) ?? null, caption: typeof o.caption === \"string\" ? o.caption : \"\" };\n })\n : [];\n\nexport function GalleryBlock({\n m, set, el, ctx, autoFocus,\n}: {\n m: GalleryModel;\n set: (fn: (m: GalleryModel) => GalleryModel, label?: string) => void;\n el: IslandEl;\n ctx: IslandCtx;\n autoFocus: boolean;\n}) {\n return (\n <ArticlePanelBlock<GalleryModel>\n label={GALLERY_LABEL}\n kind=\"gallery\"\n schema={GALLERY_SCHEMA}\n m={m}\n set={set}\n el={el}\n ctx={ctx}\n autoFocus={autoFocus}\n toForm={(x) => ({ images: x.images, layout: x.layout })}\n fromForm={(v) => ({ images: asImages(v.images), layout: v.layout === \"carousel\" ? \"carousel\" : \"grid\" })}\n >\n {(open, ro) => <GalleryPreview m={m} onAdd={() => open(\"images\")} ro={ro} />}\n </ArticlePanelBlock>\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"gallery.js","names":[],"sources":["../../../src/controls/rich-text/gallery.tsx"],"sourcesContent":["/**\n * RICH TEXT · Gallery (kit-richtext-ui-spec.md §2): V2's article block, stored as the PT block object\n * `{ _type: \"gallery\", layout: \"grid\" | \"carousel\", images: { _key, image, caption? }[] }`; each image is the rich-text\n * image's own shape (src/alt + media id), so media rewrites and alt audits reach it.\n *\n * form V2 article.ts:75-114: Images (a grid list, 2–24, each a required image + caption ≤160), Layout\n * (Grid | Carousel, segmented). A list of objects → the floating properties panel (D54); a fresh insert opens it.\n * preview V2 article-blocks.tsx:451-480: Grid in 2 columns for 2 or 4 images, else 3, square crops; Carousel a\n * 72%-wide scroll-snap row of 4:3 crops with \"N images · carousel\"; \"Add images\" when there are none.\n */\nimport { IconPhoto } from \"@tabler/icons-react\";\nimport { cn } from \"../../lib/cn\";\nimport type { TypeSchema } from \"../../schema/types\";\nimport type { ImageValue } from \"../media\";\nimport { ArticleEmpty, ArticlePanelBlock } from \"./article-shell\";\nimport type { IslandCtx } from \"./blocks\";\nimport type { IslandEl } from \"./dom\";\n\nexport interface GalleryImage {\n _key: string;\n image: ImageValue | null;\n caption: string;\n}\nexport interface GalleryModel {\n layout: \"grid\" | \"carousel\";\n images: GalleryImage[];\n}\nexport const GALLERY_LABEL = \"Gallery\";\nexport const galleryDefault = (): GalleryModel => ({ layout: \"grid\", images: [] });\n\nexport const GALLERY_SCHEMA: TypeSchema = {\n name: \"gallery\",\n title: GALLERY_LABEL,\n kind: \"object\",\n icon: \"photo\",\n fields: [\n {\n name: \"images\",\n title: \"Images\",\n type: \"array\",\n itemNoun: \"image\",\n arrayLayout: \"grid\",\n validation: { min: 2, max: 24 },\n of: [\n {\n name: \"photo\",\n title: \"Image\",\n type: \"object\",\n icon: \"photo\",\n preview: { title: \"caption\", media: \"image\", fallback: \"Untitled image\" },\n fields: [\n { name: \"image\", title: \"Image\", type: \"image\", validation: { required: true } },\n { name: \"caption\", title: \"Caption\", type: \"string\", validation: { max: 160 } },\n ],\n },\n ],\n },\n {\n name: \"layout\",\n title: \"Layout\",\n type: \"select\",\n layout: \"segmented\",\n initialValue: \"grid\",\n options: [\n { value: \"grid\", label: \"Grid\" },\n { value: \"carousel\", label: \"Carousel\" },\n ],\n },\n ],\n};\n\nexport function GalleryPreview({ m, onAdd, ro }: { m: GalleryModel; onAdd: () => void; ro: boolean }) {\n const imgs = m.images.filter((x) => x.image?.url);\n if (!imgs.length) return <ArticleEmpty icon={<IconPhoto stroke={1.5} />} title={GALLERY_LABEL} action=\"Add images\" onAction={onAdd} ro={ro} />;\n if (m.layout === \"carousel\")\n return (\n <figure className=\"m-0\" data-field=\"images\">\n <ul className=\"m-0 flex snap-x gap-2 overflow-x-auto p-0 pb-1\" aria-label={GALLERY_LABEL}>\n {imgs.map((x) => (\n <li key={x._key} className=\"w-[72%] shrink-0 snap-start list-none\">\n <img src={x.image!.url} alt={x.image!.alt ?? \"\"} draggable={false} className=\"block aspect-[4/3] w-full rounded-kit-lg border border-kit-line object-cover\" />\n {x.caption ? <p className=\"mt-1 truncate text-kit-xs text-kit-fg-3\">{x.caption}</p> : null}\n </li>\n ))}\n </ul>\n <figcaption className=\"mt-1 text-kit-2xs text-kit-fg-3\">\n {imgs.length} {imgs.length === 1 ? \"image\" : \"images\"} · carousel\n </figcaption>\n </figure>\n );\n return (\n <figure className=\"m-0\" data-field=\"images\">\n <ul className={cn(\"m-0 grid gap-2 p-0\", imgs.length === 2 || imgs.length === 4 ? \"grid-cols-2\" : \"grid-cols-3\")} aria-label={GALLERY_LABEL}>\n {imgs.map((x) => (\n <li key={x._key} className=\"list-none\">\n <img src={x.image!.url} alt={x.image!.alt ?? \"\"} draggable={false} className=\"block aspect-square w-full rounded-kit-lg border border-kit-line object-cover\" />\n {x.caption ? <p className=\"mt-1 truncate text-kit-xs text-kit-fg-3\">{x.caption}</p> : null}\n </li>\n ))}\n </ul>\n </figure>\n );\n}\n\nconst asImages = (v: unknown): GalleryImage[] =>\n Array.isArray(v)\n ? v.map((x, i) => {\n const o = (x ?? {}) as Record<string, unknown>;\n return { _key: typeof o._key === \"string\" ? o._key : `g${i}`, image: (o.image as ImageValue | null) ?? null, caption: typeof o.caption === \"string\" ? o.caption : \"\" };\n })\n : [];\n\nexport function GalleryBlock({\n m, set, el, ctx, autoFocus,\n}: {\n m: GalleryModel;\n set: (fn: (m: GalleryModel) => GalleryModel, label?: string) => void;\n el: IslandEl;\n ctx: IslandCtx;\n autoFocus: boolean;\n}) {\n return (\n <ArticlePanelBlock<GalleryModel>\n label={GALLERY_LABEL}\n kind=\"gallery\"\n schema={GALLERY_SCHEMA}\n m={m}\n set={set}\n el={el}\n ctx={ctx}\n autoFocus={autoFocus}\n toForm={(x) => ({ images: x.images, layout: x.layout })}\n fromForm={(v) => ({ images: asImages(v.images), layout: v.layout === \"carousel\" ? \"carousel\" : \"grid\" })}\n >\n {(open, ro) => <GalleryPreview m={m} onAdd={() => open(\"images\")} ro={ro} />}\n </ArticlePanelBlock>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,IAAa,gBAAgB;AAC7B,IAAa,wBAAsC;CAAE,QAAQ;CAAQ,QAAQ,CAAC;AAAE;AAEhF,IAAa,iBAA6B;CACxC,MAAM;CACN,OAAO;CACP,MAAM;CACN,MAAM;CACN,QAAQ,CACN;EACE,MAAM;EACN,OAAO;EACP,MAAM;EACN,UAAU;EACV,aAAa;EACb,YAAY;GAAE,KAAK;GAAG,KAAK;EAAG;EAC9B,IAAI,CACF;GACE,MAAM;GACN,OAAO;GACP,MAAM;GACN,MAAM;GACN,SAAS;IAAE,OAAO;IAAW,OAAO;IAAS,UAAU;GAAiB;GACxE,QAAQ,CACN;IAAE,MAAM;IAAS,OAAO;IAAS,MAAM;IAAS,YAAY,EAAE,UAAU,KAAK;GAAE,GAC/E;IAAE,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AY;GAC1H,UAAA,KAAK,KAAK,MACT,qBAAC,MAAD;IAAiB,WAAU;IAA3B,UAAA,CACE,oBAAC,OAAD;KAAK,KAAK,EAAE,MAAO;KAAK,KAAK,EAAE,MAAO,OAAO;KAAI,WAAW;KAAO,WAAU;IAAiF,CAAA,GAC7J,EAAE,UAAU,oBAAC,KAAD;KAAG,WAAU;KAA2C,UAAA,EAAE;IAAW,CAAA,IAAI,IACpF;GAHK,GAAA,EAAE,IAGP,CACL;EACC,CAAA;CACE,CAAA;AAEZ;AAEA,IAAM,YAAY,MAChB,MAAM,QAAQ,CAAC,IACX,EAAE,KAAK,GAAG,MAAM;CACd,MAAM,IAAK,KAAK,CAAC;CACjB,OAAO;EAAE,MAAM,OAAO,EAAE,SAAS,WAAW,EAAE,OAAO,IAAI;EAAK,OAAQ,EAAE,SAA+B;EAAM,SAAS,OAAO,EAAE,YAAY,WAAW,EAAE,UAAU;CAAG;AACvK,CAAC,IACD,CAAC;AAEP,SAAgB,aAAa,EAC3B,GAAG,KAAK,IAAI,KAAK,aAOhB;CACD,OACE,oBAAC,mBAAD;EACE,OAAO;EACP,MAAK;EACL,QAAQ;EACL;EACE;EACD;EACC;EACM;EACX,SAAS,OAAO;GAAE,QAAQ,EAAE;GAAQ,QAAQ,EAAE;EAAO;EACrD,WAAW,OAAO;GAAE,QAAQ,SAAS,EAAE,MAAM;GAAG,QAAQ,EAAE,WAAW,aAAa,aAAa;EAAO;EAEpG,WAAA,MAAM,OAAO,oBAAC,gBAAD;GAAmB;GAAG,aAAa,KAAK,QAAQ;GAAO;EAAK,CAAA;CAC1D,CAAA;AAEvB"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RICH TEXT · a link inside the text. A text link and a button are edited in V2's own link panel (controls/link.tsx
|
|
3
|
+
* LinkPopoverBody: Type, the page/section/address, new tab and Rel; RTE:1696) and stored as production's link mark:
|
|
4
|
+
* the resolved href, target and rel (`toLinkValue` / `fromLinkValue`). The image block uses the same panel; `LinkForm`
|
|
5
|
+
* below is kept only as a deprecated alias of it.
|
|
6
|
+
*/
|
|
1
7
|
import { type LinkRel, type LinkValue } from "../link";
|
|
2
8
|
export interface TextLink {
|
|
3
9
|
href: string;
|
|
@@ -14,6 +20,10 @@ export declare const toLinkValue: (l: TextLink) => LinkValue;
|
|
|
14
20
|
export declare const fromLinkValue: (v: LinkValue, allowNewTab: boolean) => TextLink;
|
|
15
21
|
/** An address a link may carry: http(s), mailto, tel, a site path or an in-page anchor. */
|
|
16
22
|
export declare function linkProblem(href: string): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated since 3.1.0: the address-only form V2 never had. It now renders V2's one link panel (`LinkPopoverBody`,
|
|
25
|
+
* controls/link.tsx), so every link opens the same UI; import that directly. Removed at the next major.
|
|
26
|
+
*/
|
|
17
27
|
export declare function LinkForm({ initial, allowNewTab, onSave, onCancel, onDetach, dirty, }: {
|
|
18
28
|
initial: TextLink;
|
|
19
29
|
allowNewTab: boolean;
|