@bettercms-ai/kit 3.0.1 → 3.0.2
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 +67 -18
- package/dist/brand/logo.js.map +1 -1
- package/dist/context.js +8 -3
- package/dist/context.js.map +1 -1
- package/dist/controls/button.js +451 -134
- package/dist/controls/button.js.map +1 -1
- package/dist/controls/choice.js +336 -95
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/code.js +245 -72
- package/dist/controls/code.js.map +1 -1
- package/dist/controls/color.js +108 -31
- package/dist/controls/color.js.map +1 -1
- package/dist/controls/date.js +268 -83
- package/dist/controls/date.js.map +1 -1
- package/dist/controls/form-picker.js +26 -9
- package/dist/controls/form-picker.js.map +1 -1
- package/dist/controls/icon.js +341 -100
- package/dist/controls/icon.js.map +1 -1
- package/dist/controls/json.js +20 -7
- package/dist/controls/json.js.map +1 -1
- package/dist/controls/link.js +561 -156
- package/dist/controls/link.js.map +1 -1
- package/dist/controls/location.js +124 -35
- package/dist/controls/location.js.map +1 -1
- package/dist/controls/media.js +928 -267
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/number.js +80 -23
- package/dist/controls/number.js.map +1 -1
- package/dist/controls/reference.js +516 -155
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/article-shell.js +327 -86
- package/dist/controls/rich-text/article-shell.js.map +1 -1
- package/dist/controls/rich-text/author.js +78 -21
- package/dist/controls/rich-text/author.js.map +1 -1
- package/dist/controls/rich-text/blocks.js +1084 -315
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/button.js +30 -9
- package/dist/controls/rich-text/button.js.map +1 -1
- package/dist/controls/rich-text/catalog.js +168 -51
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/columns.js +104 -31
- package/dist/controls/rich-text/columns.js.map +1 -1
- package/dist/controls/rich-text/component-card.js +790 -209
- package/dist/controls/rich-text/component-card.js.map +1 -1
- package/dist/controls/rich-text/component-panel.js +102 -40
- package/dist/controls/rich-text/component-panel.js.map +1 -1
- package/dist/controls/rich-text/control.js +101 -32
- package/dist/controls/rich-text/control.js.map +1 -1
- package/dist/controls/rich-text/editor.js +423 -121
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/embed.js +184 -51
- package/dist/controls/rich-text/embed.js.map +1 -1
- package/dist/controls/rich-text/floating.js +171 -42
- package/dist/controls/rich-text/floating.js.map +1 -1
- package/dist/controls/rich-text/footnote.js +89 -28
- package/dist/controls/rich-text/footnote.js.map +1 -1
- package/dist/controls/rich-text/gallery.js +88 -27
- package/dist/controls/rich-text/gallery.js.map +1 -1
- package/dist/controls/rich-text/link-form.js +111 -34
- package/dist/controls/rich-text/link-form.js.map +1 -1
- package/dist/controls/rich-text/plain.js +8 -3
- package/dist/controls/rich-text/plain.js.map +1 -1
- package/dist/controls/rich-text/related.js +86 -25
- package/dist/controls/rich-text/related.js.map +1 -1
- package/dist/controls/rich-text/toc.js +48 -15
- package/dist/controls/rich-text/toc.js.map +1 -1
- package/dist/controls/rich-text/toolbar.js +408 -107
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/scale.js +169 -52
- package/dist/controls/scale.js.map +1 -1
- package/dist/controls/slot.js +238 -73
- package/dist/controls/slot.js.map +1 -1
- package/dist/controls/table/table-editor.js +1766 -500
- package/dist/controls/table/table-editor.js.map +1 -1
- package/dist/controls/table/table-link.js +119 -38
- package/dist/controls/table/table-link.js.map +1 -1
- package/dist/controls/table/table.js +26 -9
- package/dist/controls/table/table.js.map +1 -1
- package/dist/controls/text.js +221 -68
- package/dist/controls/text.js.map +1 -1
- package/dist/controls/unknown-value.js +79 -22
- package/dist/controls/unknown-value.js.map +1 -1
- package/dist/engine/array.js +821 -228
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/bits.js +38 -13
- package/dist/engine/bits.js.map +1 -1
- package/dist/engine/breadcrumb.js +25 -8
- package/dist/engine/breadcrumb.js.map +1 -1
- package/dist/engine/expand.js +38 -13
- package/dist/engine/expand.js.map +1 -1
- package/dist/engine/field-list.js +14 -5
- package/dist/engine/field-list.js.map +1 -1
- package/dist/engine/field-shell.js +849 -244
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +275 -78
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.js +630 -193
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +187 -50
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/kit-field.js +320 -95
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/schema-form.js +101 -32
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/engine/slot.js +146 -45
- package/dist/engine/slot.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/icons.js +14 -5
- package/dist/lib/icons.js.map +1 -1
- package/dist/styles.css +5821 -1
- package/dist/table/table-view.js +49 -16
- package/dist/table/table-view.js.map +1 -1
- package/dist/testing/test-form.js +14 -5
- package/dist/testing/test-form.js.map +1 -1
- package/dist/theme.js +8 -3
- package/dist/theme.js.map +1 -1
- package/dist/ui/action-tray.js +97 -24
- package/dist/ui/action-tray.js.map +1 -1
- package/dist/ui/autocomplete.js +135 -38
- package/dist/ui/autocomplete.js.map +1 -1
- package/dist/ui/button.js +108 -31
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/choice-switch.js +14 -5
- package/dist/ui/choice-switch.js.map +1 -1
- package/dist/ui/controls.js +279 -86
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/display.js +401 -116
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/expanded-editor-modal.js +100 -27
- package/dist/ui/expanded-editor-modal.js.map +1 -1
- package/dist/ui/floating-panel.js +130 -37
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/ui/input.js +196 -59
- package/dist/ui/input.js.map +1 -1
- package/dist/ui/mode-bar.js +32 -11
- package/dist/ui/mode-bar.js.map +1 -1
- package/dist/ui/overlay.js +616 -179
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/path-crumbs.js +374 -113
- package/dist/ui/path-crumbs.js.map +1 -1
- package/dist/ui/select.js +311 -78
- package/dist/ui/select.js.map +1 -1
- package/dist/ui/shortcut-hint.d.ts +3 -0
- package/dist/ui/shortcut-hint.js +33 -7
- package/dist/ui/shortcut-hint.js.map +1 -1
- package/dist/ui/spinner.js +20 -7
- package/dist/ui/spinner.js.map +1 -1
- package/dist/ui/split-button.js +35 -10
- package/dist/ui/split-button.js.map +1 -1
- package/dist/ui/tab.js +50 -17
- package/dist/ui/tab.js.map +1 -1
- package/dist/ui/toast.js +107 -30
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/tooltip-root.js +24 -7
- 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,qBAAC,OAAD;EACE,cAAc,MAAM;GAClB,IAAI,CAAE,EAAE,OAAuB,QAAQ,QAAQ,GAAG,EAAE,eAAe;EACrE;EACK;EACL,OAAO;GAAE;GAAK,WAAW;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,SAAS;GAAY,CAAA,CACrF,EAAA,CAAA,IACA;EACD;CACL,CAAA,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;C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AA;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"}
|
|
@@ -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 { jsxDEV } from "react/jsx-dev-runtime";
|
|
7
7
|
import { IconTrash } from "@tabler/icons-react";
|
|
8
8
|
//#region src/controls/rich-text/footnote.tsx
|
|
9
9
|
/**
|
|
@@ -19,6 +19,7 @@ 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";
|
|
22
23
|
var FN_MARK = "sup[data-rt=fn]";
|
|
23
24
|
/** The toast when a footnote cannot go where the caret is (V2 rich-text-editor.tsx:613). */
|
|
24
25
|
var FOOTNOTE_REFUSED = {
|
|
@@ -94,19 +95,23 @@ function backToMarker(root, m) {
|
|
|
94
95
|
function FootnoteEditor({ n, note, onChange, onRemove, onDone }) {
|
|
95
96
|
const [v, setV] = React.useState(note);
|
|
96
97
|
const id = React.useId();
|
|
97
|
-
return /* @__PURE__ */
|
|
98
|
+
return /* @__PURE__ */ jsxDEV("form", {
|
|
98
99
|
className: "flex flex-col gap-2",
|
|
99
100
|
onSubmit: (e) => {
|
|
100
101
|
e.preventDefault();
|
|
101
102
|
onDone();
|
|
102
103
|
},
|
|
103
104
|
children: [
|
|
104
|
-
/* @__PURE__ */
|
|
105
|
+
/* @__PURE__ */ jsxDEV("label", {
|
|
105
106
|
htmlFor: id,
|
|
106
107
|
className: "text-kit-xs font-medium text-kit-fg-2",
|
|
107
108
|
children: ["Footnote ", n]
|
|
108
|
-
}
|
|
109
|
-
|
|
109
|
+
}, void 0, true, {
|
|
110
|
+
fileName: _jsxFileName,
|
|
111
|
+
lineNumber: 106,
|
|
112
|
+
columnNumber: 7
|
|
113
|
+
}, this),
|
|
114
|
+
/* @__PURE__ */ jsxDEV(Textarea, {
|
|
110
115
|
id,
|
|
111
116
|
autoFocus: true,
|
|
112
117
|
rows: 3,
|
|
@@ -122,62 +127,118 @@ function FootnoteEditor({ n, note, onChange, onRemove, onDone }) {
|
|
|
122
127
|
onDone();
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
130
|
+
}, void 0, false, {
|
|
131
|
+
fileName: _jsxFileName,
|
|
132
|
+
lineNumber: 109,
|
|
133
|
+
columnNumber: 7
|
|
134
|
+
}, this),
|
|
135
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
127
136
|
className: "flex items-center justify-between",
|
|
128
|
-
children: [/* @__PURE__ */
|
|
137
|
+
children: [/* @__PURE__ */ jsxDEV(Button, {
|
|
129
138
|
size: "xs",
|
|
130
139
|
variant: "ghost",
|
|
131
|
-
leftIcon: /* @__PURE__ */
|
|
140
|
+
leftIcon: /* @__PURE__ */ jsxDEV(IconTrash, { stroke: 1.5 }, void 0, false, {
|
|
141
|
+
fileName: _jsxFileName,
|
|
142
|
+
lineNumber: 127,
|
|
143
|
+
columnNumber: 53
|
|
144
|
+
}, this),
|
|
132
145
|
onClick: onRemove,
|
|
133
146
|
className: "hover:text-kit-danger-fg",
|
|
134
147
|
children: "Remove"
|
|
135
|
-
}
|
|
148
|
+
}, void 0, false, {
|
|
149
|
+
fileName: _jsxFileName,
|
|
150
|
+
lineNumber: 127,
|
|
151
|
+
columnNumber: 9
|
|
152
|
+
}, this), /* @__PURE__ */ jsxDEV(Button, {
|
|
136
153
|
size: "xs",
|
|
137
154
|
variant: "primary",
|
|
138
155
|
type: "submit",
|
|
139
156
|
children: "Done"
|
|
140
|
-
}
|
|
141
|
-
|
|
157
|
+
}, void 0, false, {
|
|
158
|
+
fileName: _jsxFileName,
|
|
159
|
+
lineNumber: 130,
|
|
160
|
+
columnNumber: 9
|
|
161
|
+
}, this)]
|
|
162
|
+
}, void 0, true, {
|
|
163
|
+
fileName: _jsxFileName,
|
|
164
|
+
lineNumber: 126,
|
|
165
|
+
columnNumber: 7
|
|
166
|
+
}, this)
|
|
142
167
|
]
|
|
143
|
-
}
|
|
168
|
+
}, void 0, true, {
|
|
169
|
+
fileName: _jsxFileName,
|
|
170
|
+
lineNumber: 99,
|
|
171
|
+
columnNumber: 5
|
|
172
|
+
}, this);
|
|
144
173
|
}
|
|
145
174
|
/** The notes under the body, numbered in text order, each with a way back to its marker. Renders nothing when empty. */
|
|
146
175
|
function FootnotesList({ notes, readOnly, density = "default", onEdit, onBack }) {
|
|
147
176
|
if (!notes.length) return null;
|
|
148
|
-
return /* @__PURE__ */
|
|
177
|
+
return /* @__PURE__ */ jsxDEV("section", {
|
|
149
178
|
"aria-label": "Footnotes",
|
|
150
179
|
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"),
|
|
151
|
-
children: /* @__PURE__ */
|
|
180
|
+
children: /* @__PURE__ */ jsxDEV("ol", {
|
|
152
181
|
className: "m-0 flex list-decimal flex-col gap-1 pl-5 marker:text-kit-fg-3",
|
|
153
|
-
children: notes.map((n, i) => /* @__PURE__ */
|
|
182
|
+
children: notes.map((n, i) => /* @__PURE__ */ jsxDEV("li", {
|
|
154
183
|
className: "pl-1",
|
|
155
|
-
children: /* @__PURE__ */
|
|
184
|
+
children: /* @__PURE__ */ jsxDEV("span", {
|
|
156
185
|
className: "flex items-start gap-1",
|
|
157
|
-
children: [/* @__PURE__ */
|
|
186
|
+
children: [/* @__PURE__ */ jsxDEV("button", {
|
|
158
187
|
type: "button",
|
|
159
188
|
disabled: readOnly,
|
|
160
189
|
"aria-label": `Footnote ${i + 1}: ${n.note || "empty"}. Edit`,
|
|
161
190
|
onClick: () => onEdit(n.el),
|
|
162
191
|
className: "min-w-0 flex-1 rounded-kit-sm text-left leading-relaxed enabled:hover:text-kit-fg",
|
|
163
|
-
children: n.note || /* @__PURE__ */
|
|
192
|
+
children: n.note || /* @__PURE__ */ jsxDEV("span", {
|
|
164
193
|
className: "text-kit-warning-fg",
|
|
165
194
|
children: "Empty note"
|
|
166
|
-
}
|
|
167
|
-
|
|
195
|
+
}, void 0, false, {
|
|
196
|
+
fileName: _jsxFileName,
|
|
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, {
|
|
168
205
|
content: "Back to the text",
|
|
169
|
-
children: /* @__PURE__ */
|
|
206
|
+
children: /* @__PURE__ */ jsxDEV("button", {
|
|
170
207
|
type: "button",
|
|
171
208
|
"aria-label": `Back to reference ${i + 1}`,
|
|
172
209
|
onClick: () => onBack(n.el),
|
|
173
210
|
className: "shrink-0 rounded-kit-sm px-1 text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg",
|
|
174
211
|
children: "↩"
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
212
|
+
}, void 0, false, {
|
|
213
|
+
fileName: _jsxFileName,
|
|
214
|
+
lineNumber: 173,
|
|
215
|
+
columnNumber: 17
|
|
216
|
+
}, this)
|
|
217
|
+
}, void 0, false, {
|
|
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);
|
|
181
242
|
}
|
|
182
243
|
//#endregion
|
|
183
244
|
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,EA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AAA,oBAAC,MAAD;GAAI,WAAU;GACX,UAAA,MAAM,KAAK,GAAG,MACb,oBAAC,MAAD;IAAY,WAAU;IACpB,UAAA,qBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACE,oBAAC,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,oBAAC,QAAD;OAAM,WAAU;OAAsB,UAAA;MAAgB,CAAA;KAC3D,CAAA,GACR,oBAAC,SAAD;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
|
+
{"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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AAD;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,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "../../lib/cn.js";
|
|
2
2
|
import { ArticleEmpty, ArticlePanelBlock } from "./article-shell.js";
|
|
3
|
-
import {
|
|
3
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
4
4
|
import { IconPhoto } from "@tabler/icons-react";
|
|
5
5
|
//#region src/controls/rich-text/gallery.tsx
|
|
6
6
|
/**
|
|
@@ -13,6 +13,7 @@ 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";
|
|
16
17
|
var GALLERY_LABEL = "Gallery";
|
|
17
18
|
var galleryDefault = () => ({
|
|
18
19
|
layout: "grid",
|
|
@@ -72,32 +73,56 @@ var GALLERY_SCHEMA = {
|
|
|
72
73
|
};
|
|
73
74
|
function GalleryPreview({ m, onAdd, ro }) {
|
|
74
75
|
const imgs = m.images.filter((x) => x.image?.url);
|
|
75
|
-
if (!imgs.length) return /* @__PURE__ */
|
|
76
|
-
icon: /* @__PURE__ */
|
|
76
|
+
if (!imgs.length) return /* @__PURE__ */ jsxDEV(ArticleEmpty, {
|
|
77
|
+
icon: /* @__PURE__ */ jsxDEV(IconPhoto, { stroke: 1.5 }, void 0, false, {
|
|
78
|
+
fileName: _jsxFileName,
|
|
79
|
+
lineNumber: 74,
|
|
80
|
+
columnNumber: 48
|
|
81
|
+
}, this),
|
|
77
82
|
title: GALLERY_LABEL,
|
|
78
83
|
action: "Add images",
|
|
79
84
|
onAction: onAdd,
|
|
80
85
|
ro
|
|
81
|
-
}
|
|
82
|
-
|
|
86
|
+
}, void 0, false, {
|
|
87
|
+
fileName: _jsxFileName,
|
|
88
|
+
lineNumber: 74,
|
|
89
|
+
columnNumber: 28
|
|
90
|
+
}, this);
|
|
91
|
+
if (m.layout === "carousel") return /* @__PURE__ */ jsxDEV("figure", {
|
|
83
92
|
className: "m-0",
|
|
84
93
|
"data-field": "images",
|
|
85
|
-
children: [/* @__PURE__ */
|
|
94
|
+
children: [/* @__PURE__ */ jsxDEV("ul", {
|
|
86
95
|
className: "m-0 flex snap-x gap-2 overflow-x-auto p-0 pb-1",
|
|
87
96
|
"aria-label": GALLERY_LABEL,
|
|
88
|
-
children: imgs.map((x) => /* @__PURE__ */
|
|
97
|
+
children: imgs.map((x) => /* @__PURE__ */ jsxDEV("li", {
|
|
89
98
|
className: "w-[72%] shrink-0 snap-start list-none",
|
|
90
|
-
children: [/* @__PURE__ */
|
|
99
|
+
children: [/* @__PURE__ */ jsxDEV("img", {
|
|
91
100
|
src: x.image.url,
|
|
92
101
|
alt: x.image.alt ?? "",
|
|
93
102
|
draggable: false,
|
|
94
103
|
className: "block aspect-[4/3] w-full rounded-kit-lg border border-kit-line object-cover"
|
|
95
|
-
}
|
|
104
|
+
}, void 0, false, {
|
|
105
|
+
fileName: _jsxFileName,
|
|
106
|
+
lineNumber: 81,
|
|
107
|
+
columnNumber: 15
|
|
108
|
+
}, this), x.caption ? /* @__PURE__ */ jsxDEV("p", {
|
|
96
109
|
className: "mt-1 truncate text-kit-xs text-kit-fg-3",
|
|
97
110
|
children: x.caption
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
}, void 0, false, {
|
|
112
|
+
fileName: _jsxFileName,
|
|
113
|
+
lineNumber: 82,
|
|
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", {
|
|
101
126
|
className: "mt-1 text-kit-2xs text-kit-fg-3",
|
|
102
127
|
children: [
|
|
103
128
|
imgs.length,
|
|
@@ -105,28 +130,56 @@ function GalleryPreview({ m, onAdd, ro }) {
|
|
|
105
130
|
imgs.length === 1 ? "image" : "images",
|
|
106
131
|
" · carousel"
|
|
107
132
|
]
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
133
|
+
}, void 0, true, {
|
|
134
|
+
fileName: _jsxFileName,
|
|
135
|
+
lineNumber: 86,
|
|
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", {
|
|
111
144
|
className: "m-0",
|
|
112
145
|
"data-field": "images",
|
|
113
|
-
children: /* @__PURE__ */
|
|
146
|
+
children: /* @__PURE__ */ jsxDEV("ul", {
|
|
114
147
|
className: cn("m-0 grid gap-2 p-0", imgs.length === 2 || imgs.length === 4 ? "grid-cols-2" : "grid-cols-3"),
|
|
115
148
|
"aria-label": GALLERY_LABEL,
|
|
116
|
-
children: imgs.map((x) => /* @__PURE__ */
|
|
149
|
+
children: imgs.map((x) => /* @__PURE__ */ jsxDEV("li", {
|
|
117
150
|
className: "list-none",
|
|
118
|
-
children: [/* @__PURE__ */
|
|
151
|
+
children: [/* @__PURE__ */ jsxDEV("img", {
|
|
119
152
|
src: x.image.url,
|
|
120
153
|
alt: x.image.alt ?? "",
|
|
121
154
|
draggable: false,
|
|
122
155
|
className: "block aspect-square w-full rounded-kit-lg border border-kit-line object-cover"
|
|
123
|
-
}
|
|
156
|
+
}, void 0, false, {
|
|
157
|
+
fileName: _jsxFileName,
|
|
158
|
+
lineNumber: 96,
|
|
159
|
+
columnNumber: 13
|
|
160
|
+
}, this), x.caption ? /* @__PURE__ */ jsxDEV("p", {
|
|
124
161
|
className: "mt-1 truncate text-kit-xs text-kit-fg-3",
|
|
125
162
|
children: x.caption
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
163
|
+
}, void 0, false, {
|
|
164
|
+
fileName: _jsxFileName,
|
|
165
|
+
lineNumber: 97,
|
|
166
|
+
columnNumber: 26
|
|
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);
|
|
130
183
|
}
|
|
131
184
|
var asImages = (v) => Array.isArray(v) ? v.map((x, i) => {
|
|
132
185
|
const o = x ?? {};
|
|
@@ -137,7 +190,7 @@ var asImages = (v) => Array.isArray(v) ? v.map((x, i) => {
|
|
|
137
190
|
};
|
|
138
191
|
}) : [];
|
|
139
192
|
function GalleryBlock({ m, set, el, ctx, autoFocus }) {
|
|
140
|
-
return /* @__PURE__ */
|
|
193
|
+
return /* @__PURE__ */ jsxDEV(ArticlePanelBlock, {
|
|
141
194
|
label: GALLERY_LABEL,
|
|
142
195
|
kind: "gallery",
|
|
143
196
|
schema: GALLERY_SCHEMA,
|
|
@@ -154,12 +207,20 @@ function GalleryBlock({ m, set, el, ctx, autoFocus }) {
|
|
|
154
207
|
images: asImages(v.images),
|
|
155
208
|
layout: v.layout === "carousel" ? "carousel" : "grid"
|
|
156
209
|
}),
|
|
157
|
-
children: (open, ro) => /* @__PURE__ */
|
|
210
|
+
children: (open, ro) => /* @__PURE__ */ jsxDEV(GalleryPreview, {
|
|
158
211
|
m,
|
|
159
212
|
onAdd: () => open("images"),
|
|
160
213
|
ro
|
|
161
|
-
}
|
|
162
|
-
|
|
214
|
+
}, void 0, false, {
|
|
215
|
+
fileName: _jsxFileName,
|
|
216
|
+
lineNumber: 135,
|
|
217
|
+
columnNumber: 22
|
|
218
|
+
}, this)
|
|
219
|
+
}, void 0, false, {
|
|
220
|
+
fileName: _jsxFileName,
|
|
221
|
+
lineNumber: 123,
|
|
222
|
+
columnNumber: 5
|
|
223
|
+
}, this);
|
|
163
224
|
}
|
|
164
225
|
//#endregion
|
|
165
226
|
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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