@namroodinc/liquid-editorial 0.14.0 → 0.16.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/README.md +283 -12
- package/UPGRADING.md +106 -0
- package/dist/chunks/{Avatar-Dw7EWd_-.cjs → Avatar-BZGFSE6C.cjs} +2 -2
- package/dist/chunks/{Avatar-Dw7EWd_-.cjs.map → Avatar-BZGFSE6C.cjs.map} +1 -1
- package/dist/chunks/{Avatar-BToMaTdL.js → Avatar-C4W-g8nU.js} +2 -2
- package/dist/chunks/{Avatar-BToMaTdL.js.map → Avatar-C4W-g8nU.js.map} +1 -1
- package/dist/chunks/{Board-XeDG9nWP.js → Board-Cbi5FMW-.js} +2 -2
- package/dist/chunks/{Board-XeDG9nWP.js.map → Board-Cbi5FMW-.js.map} +1 -1
- package/dist/chunks/{Board-DeXtaWNO.cjs → Board-_agEjTy8.cjs} +2 -2
- package/dist/chunks/{Board-DeXtaWNO.cjs.map → Board-_agEjTy8.cjs.map} +1 -1
- package/dist/chunks/{CollectionView-Dbg4d_tA.cjs → CollectionView-BfX2Lxre.cjs} +2 -2
- package/dist/chunks/{CollectionView-Dbg4d_tA.cjs.map → CollectionView-BfX2Lxre.cjs.map} +1 -1
- package/dist/chunks/{CollectionView-C0_bTO2v.js → CollectionView-DPJGtSP5.js} +2 -2
- package/dist/chunks/{CollectionView-C0_bTO2v.js.map → CollectionView-DPJGtSP5.js.map} +1 -1
- package/dist/chunks/{ColourField-DAFzOIOq.cjs → ColourField-BVGnW8Wh.cjs} +2 -2
- package/dist/chunks/{ColourField-DAFzOIOq.cjs.map → ColourField-BVGnW8Wh.cjs.map} +1 -1
- package/dist/chunks/{ColourField-Bb8H87fg.js → ColourField-BcuARZY4.js} +6 -6
- package/dist/chunks/{ColourField-Bb8H87fg.js.map → ColourField-BcuARZY4.js.map} +1 -1
- package/dist/chunks/{DatePicker-COm1giw8.js → DatePicker-VQUsbYdo.js} +3 -3
- package/dist/chunks/{DatePicker-COm1giw8.js.map → DatePicker-VQUsbYdo.js.map} +1 -1
- package/dist/chunks/{DatePicker-DOg3iQYy.cjs → DatePicker-zA0bWVBp.cjs} +2 -2
- package/dist/chunks/{DatePicker-DOg3iQYy.cjs.map → DatePicker-zA0bWVBp.cjs.map} +1 -1
- package/dist/chunks/{Drawer-nUTJtwX_.js → Drawer-2cf0SaG4.js} +3 -3
- package/dist/chunks/{Drawer-nUTJtwX_.js.map → Drawer-2cf0SaG4.js.map} +1 -1
- package/dist/chunks/{Drawer-B2dcTh5l.cjs → Drawer-BzvSfkCL.cjs} +2 -2
- package/dist/chunks/{Drawer-B2dcTh5l.cjs.map → Drawer-BzvSfkCL.cjs.map} +1 -1
- package/dist/chunks/EntryPicker-C7EBfpaw.cjs +2 -0
- package/dist/chunks/EntryPicker-C7EBfpaw.cjs.map +1 -0
- package/dist/chunks/{EntryPicker-Ie9T47hA.js → EntryPicker-DBnDsgzi.js} +397 -397
- package/dist/chunks/EntryPicker-DBnDsgzi.js.map +1 -0
- package/dist/chunks/FormEditor-BG8bOXI8.js +35 -0
- package/dist/chunks/FormEditor-BG8bOXI8.js.map +1 -0
- package/dist/chunks/FormEditor-BJN0QuLI.cjs +2 -0
- package/dist/chunks/FormEditor-BJN0QuLI.cjs.map +1 -0
- package/dist/chunks/Icon-QLZH31JA.cjs +2 -0
- package/dist/chunks/Icon-QLZH31JA.cjs.map +1 -0
- package/dist/chunks/Icon-kLLQC54Z.js +107 -0
- package/dist/chunks/Icon-kLLQC54Z.js.map +1 -0
- package/dist/chunks/{Message-VJTPhId7.js → Message-DM6pTq7N.js} +2 -2
- package/dist/chunks/{Message-VJTPhId7.js.map → Message-DM6pTq7N.js.map} +1 -1
- package/dist/chunks/{Message-B0A5bz8V.cjs → Message-yZJDVzb8.cjs} +2 -2
- package/dist/chunks/{Message-B0A5bz8V.cjs.map → Message-yZJDVzb8.cjs.map} +1 -1
- package/dist/chunks/{NumberField-C90eJGny.js → NumberField-CVsK4l9P.js} +13 -13
- package/dist/chunks/{NumberField-C90eJGny.js.map → NumberField-CVsK4l9P.js.map} +1 -1
- package/dist/chunks/{NumberField-BrWFmPkW.cjs → NumberField-Ccjpa_1d.cjs} +2 -2
- package/dist/chunks/{NumberField-BrWFmPkW.cjs.map → NumberField-Ccjpa_1d.cjs.map} +1 -1
- package/dist/chunks/RichTextEditor-D4rNww9d.cjs +2 -0
- package/dist/chunks/RichTextEditor-D4rNww9d.cjs.map +1 -0
- package/dist/chunks/RichTextEditor-DSxiMLVd.js +2832 -0
- package/dist/chunks/RichTextEditor-DSxiMLVd.js.map +1 -0
- package/dist/chunks/dialogLabel-Dx-WEEzI.cjs +2 -0
- package/dist/chunks/dialogLabel-Dx-WEEzI.cjs.map +1 -0
- package/dist/chunks/dialogLabel-nB1gwKz0.js +157 -0
- package/dist/chunks/dialogLabel-nB1gwKz0.js.map +1 -0
- package/dist/chunks/overlayLayer-CPd3zj_u.cjs +2 -0
- package/dist/chunks/overlayLayer-CPd3zj_u.cjs.map +1 -0
- package/dist/chunks/overlayLayer-Dv1vmfaI.js +199 -0
- package/dist/chunks/overlayLayer-Dv1vmfaI.js.map +1 -0
- package/dist/chunks/{useTooltip-Du8PutGX.js → useTooltip-COyAcujL.js} +2 -2
- package/dist/chunks/{useTooltip-Du8PutGX.js.map → useTooltip-COyAcujL.js.map} +1 -1
- package/dist/chunks/{useTooltip-ekdwMJFz.cjs → useTooltip-nEDN0ObI.cjs} +2 -2
- package/dist/chunks/{useTooltip-ekdwMJFz.cjs.map → useTooltip-nEDN0ObI.cjs.map} +1 -1
- package/dist/components/AppShell/index.cjs +1 -1
- package/dist/components/AppShell/index.js +1 -1
- package/dist/components/AssetCard/index.cjs +1 -1
- package/dist/components/AssetCard/index.js +1 -1
- package/dist/components/AssetGrid/index.cjs +1 -1
- package/dist/components/AssetGrid/index.js +1 -1
- package/dist/components/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +1 -1
- package/dist/components/Banner/index.cjs +1 -1
- package/dist/components/Banner/index.js +1 -1
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.cjs.map +1 -1
- package/dist/components/Choice/index.js +5 -5
- package/dist/components/CollectionView/index.cjs +1 -1
- package/dist/components/CollectionView/index.js +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.js +1 -1
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.cjs.map +1 -1
- package/dist/components/EditLayout/index.js +6 -7
- package/dist/components/EditLayout/index.js.map +1 -1
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.js +1 -1
- package/dist/components/EntryPicker/style.css +1 -1
- package/dist/components/FormEditor/README.md +205 -178
- package/dist/components/FormEditor/control.d.cts +4 -4
- package/dist/components/FormEditor/control.d.cts.map +1 -1
- package/dist/components/FormEditor/control.d.ts +4 -4
- package/dist/components/FormEditor/control.d.ts.map +1 -1
- package/dist/components/FormEditor/form.d.cts +3 -3
- package/dist/components/FormEditor/form.d.cts.map +1 -1
- package/dist/components/FormEditor/form.d.ts +3 -3
- package/dist/components/FormEditor/form.d.ts.map +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.js +2 -2
- package/dist/components/FormEditor/model.d.cts +2 -0
- package/dist/components/FormEditor/model.d.cts.map +1 -1
- package/dist/components/FormEditor/model.d.ts +2 -0
- package/dist/components/FormEditor/model.d.ts.map +1 -1
- package/dist/components/FormEditor/rich-text-control.d.cts +1 -2
- package/dist/components/FormEditor/rich-text-control.d.cts.map +1 -1
- package/dist/components/FormEditor/rich-text-control.d.ts +1 -2
- package/dist/components/FormEditor/rich-text-control.d.ts.map +1 -1
- package/dist/components/Icon/icons.d.cts +5 -0
- package/dist/components/Icon/icons.d.cts.map +1 -1
- package/dist/components/Icon/icons.d.ts +5 -0
- package/dist/components/Icon/icons.d.ts.map +1 -1
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +1 -1
- package/dist/components/ImageCropper/index.cjs +1 -1
- package/dist/components/ImageCropper/index.cjs.map +1 -1
- package/dist/components/ImageCropper/index.js +6 -6
- package/dist/components/Menu/index.cjs +1 -1
- package/dist/components/Menu/index.js +9 -9
- package/dist/components/Menu/index.js.map +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.js +2 -2
- package/dist/components/NumberField/index.cjs +1 -1
- package/dist/components/NumberField/index.js +1 -1
- package/dist/components/Popover/index.cjs +1 -1
- package/dist/components/Popover/index.cjs.map +1 -1
- package/dist/components/Popover/index.d.cts.map +1 -1
- package/dist/components/Popover/index.d.ts.map +1 -1
- package/dist/components/Popover/index.js +67 -64
- package/dist/components/Popover/index.js.map +1 -1
- package/dist/components/RichTextEditor/block-plugins.d.cts +62 -0
- package/dist/components/RichTextEditor/block-plugins.d.cts.map +1 -0
- package/dist/components/RichTextEditor/block-plugins.d.ts +62 -0
- package/dist/components/RichTextEditor/block-plugins.d.ts.map +1 -0
- package/dist/components/RichTextEditor/content-block-frame.d.cts +32 -0
- package/dist/components/RichTextEditor/content-block-frame.d.cts.map +1 -0
- package/dist/components/RichTextEditor/content-block-frame.d.ts +32 -0
- package/dist/components/RichTextEditor/content-block-frame.d.ts.map +1 -0
- package/dist/components/RichTextEditor/content-block-view.d.cts +3 -0
- package/dist/components/RichTextEditor/content-block-view.d.cts.map +1 -0
- package/dist/components/RichTextEditor/content-block-view.d.ts +3 -0
- package/dist/components/RichTextEditor/content-block-view.d.ts.map +1 -0
- package/dist/components/RichTextEditor/content-block.d.cts +10 -0
- package/dist/components/RichTextEditor/content-block.d.cts.map +1 -0
- package/dist/components/RichTextEditor/content-block.d.ts +10 -0
- package/dist/components/RichTextEditor/content-block.d.ts.map +1 -0
- package/dist/components/RichTextEditor/document.d.cts +24 -8
- package/dist/components/RichTextEditor/document.d.cts.map +1 -1
- package/dist/components/RichTextEditor/document.d.ts +24 -8
- package/dist/components/RichTextEditor/document.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.d.cts +6 -4
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts +6 -4
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RichTextEditor/picker-block.d.cts +25 -0
- package/dist/components/RichTextEditor/picker-block.d.cts.map +1 -0
- package/dist/components/RichTextEditor/picker-block.d.ts +25 -0
- package/dist/components/RichTextEditor/picker-block.d.ts.map +1 -0
- package/dist/components/RichTextEditor/style.css +126 -49
- package/dist/components/RichTextEditor/table-actions.d.cts +11 -0
- package/dist/components/RichTextEditor/table-actions.d.cts.map +1 -0
- package/dist/components/RichTextEditor/table-actions.d.ts +11 -0
- package/dist/components/RichTextEditor/table-actions.d.ts.map +1 -0
- package/dist/components/RichTextEditor/table-bands.d.cts +19 -0
- package/dist/components/RichTextEditor/table-bands.d.cts.map +1 -0
- package/dist/components/RichTextEditor/table-bands.d.ts +19 -0
- package/dist/components/RichTextEditor/table-bands.d.ts.map +1 -0
- package/dist/components/RichTextEditor/table-view.d.cts +4 -0
- package/dist/components/RichTextEditor/table-view.d.cts.map +1 -0
- package/dist/components/RichTextEditor/table-view.d.ts +4 -0
- package/dist/components/RichTextEditor/table-view.d.ts.map +1 -0
- package/dist/components/RichTextEditor/tables.d.cts.map +1 -1
- package/dist/components/RichTextEditor/tables.d.ts.map +1 -1
- package/dist/components/RichTextEditor/use-blocks.d.cts +19 -0
- package/dist/components/RichTextEditor/use-blocks.d.cts.map +1 -0
- package/dist/components/RichTextEditor/use-blocks.d.ts +19 -0
- package/dist/components/RichTextEditor/use-blocks.d.ts.map +1 -0
- package/dist/components/SearchField/index.cjs +1 -1
- package/dist/components/SearchField/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +2 -2
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.cjs.map +1 -1
- package/dist/components/SelectionCard/index.js +4 -4
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.js +1 -1
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.js +1 -1
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/SubNav/index.cjs +1 -1
- package/dist/components/SubNav/index.js +1 -1
- package/dist/components/Switch/style.css +2 -6
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TopNav/index.cjs +1 -1
- package/dist/components/TopNav/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -49
- package/dist/internal/useStableValue.d.cts +8 -0
- package/dist/internal/useStableValue.d.cts.map +1 -0
- package/dist/internal/useStableValue.d.ts +8 -0
- package/dist/internal/useStableValue.d.ts.map +1 -0
- package/dist/rich-text-blocks.cjs +2 -0
- package/dist/rich-text-blocks.cjs.map +1 -0
- package/dist/rich-text-blocks.d.cts +20 -0
- package/dist/rich-text-blocks.d.cts.map +1 -0
- package/dist/rich-text-blocks.d.ts +20 -0
- package/dist/rich-text-blocks.d.ts.map +1 -0
- package/dist/rich-text-blocks.js +36 -0
- package/dist/rich-text-blocks.js.map +1 -0
- package/package.json +14 -1
- package/dist/chunks/EntryPicker-BwEYRtQl.cjs +0 -2
- package/dist/chunks/EntryPicker-BwEYRtQl.cjs.map +0 -1
- package/dist/chunks/EntryPicker-Ie9T47hA.js.map +0 -1
- package/dist/chunks/FormEditor-D1HUnjMI.cjs +0 -2
- package/dist/chunks/FormEditor-D1HUnjMI.cjs.map +0 -1
- package/dist/chunks/FormEditor-DgDV5aeR.js +0 -30
- package/dist/chunks/FormEditor-DgDV5aeR.js.map +0 -1
- package/dist/chunks/Icon-Bxvp1-td.js +0 -102
- package/dist/chunks/Icon-Bxvp1-td.js.map +0 -1
- package/dist/chunks/Icon-CnnTrtNb.cjs +0 -2
- package/dist/chunks/Icon-CnnTrtNb.cjs.map +0 -1
- package/dist/chunks/RichTextEditor-DPhEkDxi.js +0 -2108
- package/dist/chunks/RichTextEditor-DPhEkDxi.js.map +0 -1
- package/dist/chunks/RichTextEditor-DV7NZp_k.cjs +0 -2
- package/dist/chunks/RichTextEditor-DV7NZp_k.cjs.map +0 -1
- package/dist/chunks/dialogLabel-C153NosD.js +0 -176
- package/dist/chunks/dialogLabel-C153NosD.js.map +0 -1
- package/dist/chunks/dialogLabel-CNNQbtob.cjs +0 -2
- package/dist/chunks/dialogLabel-CNNQbtob.cjs.map +0 -1
- package/dist/chunks/overlayLayer-CtOTt1xB.cjs +0 -2
- package/dist/chunks/overlayLayer-CtOTt1xB.cjs.map +0 -1
- package/dist/chunks/overlayLayer-Og07sIyl.js +0 -180
- package/dist/chunks/overlayLayer-Og07sIyl.js.map +0 -1
- package/dist/components/RichTextEditor/embed-context.d.cts +0 -41
- package/dist/components/RichTextEditor/embed-context.d.cts.map +0 -1
- package/dist/components/RichTextEditor/embed-context.d.ts +0 -41
- package/dist/components/RichTextEditor/embed-context.d.ts.map +0 -1
- package/dist/components/RichTextEditor/embed-types.d.cts +0 -29
- package/dist/components/RichTextEditor/embed-types.d.cts.map +0 -1
- package/dist/components/RichTextEditor/embed-types.d.ts +0 -29
- package/dist/components/RichTextEditor/embed-types.d.ts.map +0 -1
- package/dist/components/RichTextEditor/storyblock-view.d.cts +0 -3
- package/dist/components/RichTextEditor/storyblock-view.d.cts.map +0 -1
- package/dist/components/RichTextEditor/storyblock-view.d.ts +0 -3
- package/dist/components/RichTextEditor/storyblock-view.d.ts.map +0 -1
- package/dist/components/RichTextEditor/storyblock.d.cts +0 -19
- package/dist/components/RichTextEditor/storyblock.d.cts.map +0 -1
- package/dist/components/RichTextEditor/storyblock.d.ts +0 -19
- package/dist/components/RichTextEditor/storyblock.d.ts.map +0 -1
- package/dist/components/RichTextEditor/use-embeds.d.cts +0 -31
- package/dist/components/RichTextEditor/use-embeds.d.cts.map +0 -1
- package/dist/components/RichTextEditor/use-embeds.d.ts +0 -31
- package/dist/components/RichTextEditor/use-embeds.d.ts.map +0 -1
|
@@ -0,0 +1,2832 @@
|
|
|
1
|
+
import { t as e } from "./Icon-kLLQC54Z.js";
|
|
2
|
+
import { Button as t } from "../components/Button/index.js";
|
|
3
|
+
import { t as n } from "./mergeRefs-C6_5pADN.js";
|
|
4
|
+
import { _ as r, g as i, h as a, m as o, o as s, p as c, s as l, u } from "./overlayLayer-Dv1vmfaI.js";
|
|
5
|
+
import { t as d } from "./useIsomorphicLayoutEffect-Bc9hxFMc.js";
|
|
6
|
+
import { ButtonGroup as f } from "../components/ButtonGroup/index.js";
|
|
7
|
+
import { Badge as p } from "../components/Badge/index.js";
|
|
8
|
+
/* empty css */
|
|
9
|
+
import { Field as m } from "../components/Field/index.js";
|
|
10
|
+
import { Modal as h } from "../components/Modal/index.js";
|
|
11
|
+
import { TextArea as g, TextField as _ } from "../components/TextField/index.js";
|
|
12
|
+
import { contentBlockRegistry as v, isBlockData as y, validContentBlock as b } from "../rich-text-blocks.js";
|
|
13
|
+
import { Popover as x } from "../components/Popover/index.js";
|
|
14
|
+
import { Menu as S, MenuItem as C, MenuLabel as w, MenuSeparator as T } from "../components/Menu/index.js";
|
|
15
|
+
import { Container as E } from "../components/Container/index.js";
|
|
16
|
+
import { a as D, c as O, i as ee, l as te, n as ne, o as re, r as k, s as ie, t as A } from "./EntryPicker-DBnDsgzi.js";
|
|
17
|
+
import { Checkbox as ae, ChoiceGroup as oe, Radio as se } from "../components/Choice/index.js";
|
|
18
|
+
import { n as ce } from "./decimal-hq_W9D3s.js";
|
|
19
|
+
import { t as le } from "./NumberField-CVsK4l9P.js";
|
|
20
|
+
import { Select as ue } from "../components/Select/index.js";
|
|
21
|
+
import { Switch as de } from "../components/Switch/index.js";
|
|
22
|
+
import { i as j } from "./colour-CYEF4Q_n.js";
|
|
23
|
+
import { i as M, n as N, r as P, t as fe } from "./Slider-Cab6NqhK.js";
|
|
24
|
+
import { t as pe } from "./ColourField-BcuARZY4.js";
|
|
25
|
+
import { a as me, n as he } from "./DatePicker-VQUsbYdo.js";
|
|
26
|
+
import { TagsInput as ge } from "../components/TagsInput/index.js";
|
|
27
|
+
import { CheckboxCard as _e, RadioCard as F, SelectionCardGroup as ve } from "../components/SelectionCard/index.js";
|
|
28
|
+
import { Fragment as ye, createContext as be, forwardRef as xe, useCallback as I, useContext as L, useEffect as R, useId as z, useMemo as B, useRef as V, useState as H, useSyncExternalStore as Se } from "react";
|
|
29
|
+
import { createPortal as Ce } from "react-dom";
|
|
30
|
+
import { Fragment as U, jsx as W, jsxs as G } from "react/jsx-runtime";
|
|
31
|
+
import { EditorContent as we, Extension as Te, Node as Ee, NodeViewWrapper as De, ReactNodeViewRenderer as Oe, ReactRenderer as ke, createDocument as Ae, getMarkRange as je, getSchema as Me, mergeAttributes as Ne, useEditor as Pe, useEditorState as Fe } from "@tiptap/react";
|
|
32
|
+
import { Placeholder as Ie } from "@tiptap/extension-placeholder";
|
|
33
|
+
import { EditorState as Le, NodeSelection as K, Plugin as Re, PluginKey as ze, TextSelection as Be } from "@tiptap/pm/state";
|
|
34
|
+
import { StarterKit as Ve } from "@tiptap/starter-kit";
|
|
35
|
+
import { Link as He } from "@tiptap/extension-link";
|
|
36
|
+
import { Table as Ue, TableKit as We, TableView as Ge, createTable as Ke } from "@tiptap/extension-table";
|
|
37
|
+
import { Fragment as qe, Slice as Je } from "@tiptap/pm/model";
|
|
38
|
+
import { closeHistory as q } from "@tiptap/pm/history";
|
|
39
|
+
import { CellSelection as J, TableMap as Ye, addColumn as Xe, addRow as Ze, cellAround as Qe, columnIsHeader as $e, deleteColumn as et, deleteRow as tt, deleteTable as nt, findTable as Y, mergeCells as rt, rowIsHeader as it, selectedRect as at, splitCell as ot, toggleHeader as st } from "@tiptap/pm/tables";
|
|
40
|
+
//#region src/internal/useStableValue.ts
|
|
41
|
+
function ct(e, t) {
|
|
42
|
+
return e.length === t.length && e.every((e, n) => Object.is(e, t[n]));
|
|
43
|
+
}
|
|
44
|
+
function lt(e, t) {
|
|
45
|
+
let [n, r] = H(e), i = Object.is(n, e) || t(n, e);
|
|
46
|
+
return i || r(e), i ? n : e;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/RichTextEditor/expansion.tsx
|
|
50
|
+
function ut(e, t) {
|
|
51
|
+
let n = t.querySelector(".ds-rte__content");
|
|
52
|
+
if (!n) return;
|
|
53
|
+
let r = e.view.coordsAtPos(e.state.selection.head), i = n.getBoundingClientRect();
|
|
54
|
+
(r.top < i.top || r.bottom > i.bottom) && (n.scrollTop += r.top - i.top - i.height / 2);
|
|
55
|
+
}
|
|
56
|
+
function dt({ editor: e, disabled: n, isHeld: i = !1, invalid: s, label: l, labelledBy: u, expandedWidth: f, frameRef: p }) {
|
|
57
|
+
let m = o("ds-rte__host"), [g, _] = H(!1), [v, y] = H(0), b = V(null), x = V(null), S = V(null), C = V(!1), w = V(!1), T = z();
|
|
58
|
+
g && n && !i && _(!1);
|
|
59
|
+
let E = I(() => {
|
|
60
|
+
C.current = document.activeElement === S.current, _(!1);
|
|
61
|
+
}, []);
|
|
62
|
+
d(() => {
|
|
63
|
+
m && (c(m, g ? x.current : b.current), w.current !== g && (w.current = g, n || !e ? a(document.activeElement) && r(p.current, { preventScroll: !0 }) : (ut(e, m), !g && C.current ? S.current?.focus() : (e.view.focus(), e.commands.scrollIntoView()), C.current = !1)));
|
|
64
|
+
}, [
|
|
65
|
+
m,
|
|
66
|
+
g,
|
|
67
|
+
e,
|
|
68
|
+
n,
|
|
69
|
+
p
|
|
70
|
+
]);
|
|
71
|
+
let D = g ? "Collapse editor" : "Expand editor";
|
|
72
|
+
return {
|
|
73
|
+
expanded: g,
|
|
74
|
+
toggle: /* @__PURE__ */ W(t, {
|
|
75
|
+
ref: S,
|
|
76
|
+
size: "sm",
|
|
77
|
+
isIconOnly: !0,
|
|
78
|
+
iconStart: g ? "minimize-2" : "maximize-2",
|
|
79
|
+
className: "ds-rte__expand",
|
|
80
|
+
"aria-label": D,
|
|
81
|
+
title: D,
|
|
82
|
+
"aria-expanded": g,
|
|
83
|
+
"aria-controls": g ? T : void 0,
|
|
84
|
+
isDisabled: n || !e || !m,
|
|
85
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
86
|
+
onClick: () => {
|
|
87
|
+
g ? E() : (y(p.current.getBoundingClientRect().height), _(!0));
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
surfaceSlot: (e) => /* @__PURE__ */ W("div", {
|
|
91
|
+
ref: b,
|
|
92
|
+
className: "ds-rte__slot",
|
|
93
|
+
children: m ? Ce(e, m) : e
|
|
94
|
+
}),
|
|
95
|
+
dialog: /* @__PURE__ */ W(h, {
|
|
96
|
+
id: T,
|
|
97
|
+
isOpen: g,
|
|
98
|
+
onClose: E,
|
|
99
|
+
title: l,
|
|
100
|
+
hasHeader: !1,
|
|
101
|
+
size: f === "full" ? "full" : "wide",
|
|
102
|
+
className: "ds-rte__modal",
|
|
103
|
+
"data-invalid": s || void 0,
|
|
104
|
+
"aria-labelledby": u,
|
|
105
|
+
children: /* @__PURE__ */ W("div", {
|
|
106
|
+
ref: x,
|
|
107
|
+
className: "ds-rte__expanded-slot"
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
110
|
+
frameStyle: g ? { minBlockSize: v } : void 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/components/RichTextEditor/content-block.ts
|
|
115
|
+
function ft(e) {
|
|
116
|
+
try {
|
|
117
|
+
return JSON.parse(e.getAttribute("data-content-block-data") ?? "null");
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function pt(e) {
|
|
123
|
+
return {
|
|
124
|
+
type: e.getAttribute("data-content-block-type"),
|
|
125
|
+
align: e.getAttribute("data-content-block-align") ?? "full",
|
|
126
|
+
data: ft(e)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function mt(e, t) {
|
|
130
|
+
return {
|
|
131
|
+
default: t,
|
|
132
|
+
parseHTML: (t) => pt(t)[e],
|
|
133
|
+
renderHTML: () => ({})
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
var ht = Ee.create({
|
|
137
|
+
name: "contentBlock",
|
|
138
|
+
group: "block",
|
|
139
|
+
atom: !0,
|
|
140
|
+
draggable: !0,
|
|
141
|
+
selectable: !0,
|
|
142
|
+
marks: "",
|
|
143
|
+
addAttributes() {
|
|
144
|
+
return {
|
|
145
|
+
type: mt("type", null),
|
|
146
|
+
align: mt("align", "full"),
|
|
147
|
+
data: mt("data", null)
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
parseHTML() {
|
|
151
|
+
return [{ tag: "div[data-content-block]" }];
|
|
152
|
+
},
|
|
153
|
+
renderHTML({ node: e }) {
|
|
154
|
+
let { type: t, align: n, data: r } = e.attrs;
|
|
155
|
+
return ["div", Ne({
|
|
156
|
+
"data-content-block": "",
|
|
157
|
+
"data-content-block-type": t,
|
|
158
|
+
"data-content-block-align": n,
|
|
159
|
+
"data-content-block-data": y(r) ? JSON.stringify(r) : ""
|
|
160
|
+
})];
|
|
161
|
+
}
|
|
162
|
+
}), gt = {
|
|
163
|
+
type: "doc",
|
|
164
|
+
content: [{ type: "paragraph" }]
|
|
165
|
+
}, _t = [Ve.configure({
|
|
166
|
+
link: !1,
|
|
167
|
+
trailingNode: { notAfter: ["paragraph", "contentBlock"] }
|
|
168
|
+
}), He.configure({
|
|
169
|
+
openOnClick: !1,
|
|
170
|
+
autolink: !0
|
|
171
|
+
})];
|
|
172
|
+
function vt(e) {
|
|
173
|
+
if (!e.size) return e;
|
|
174
|
+
let t = [], n = !1;
|
|
175
|
+
return e.forEach((e) => {
|
|
176
|
+
let r = vt(e.content), i = e.attrs.colwidth == null ? e.copy(r) : e.type.create({
|
|
177
|
+
...e.attrs,
|
|
178
|
+
colwidth: null
|
|
179
|
+
}, r, e.marks);
|
|
180
|
+
t.push(i), n ||= i !== e;
|
|
181
|
+
}), n ? qe.fromArray(t) : e;
|
|
182
|
+
}
|
|
183
|
+
function yt() {
|
|
184
|
+
let e = null, t = (t) => (t.state.selection.empty || (e = t.state.selection.content()), !1);
|
|
185
|
+
return new Re({ props: {
|
|
186
|
+
handleDOMEvents: {
|
|
187
|
+
copy: t,
|
|
188
|
+
cut: t
|
|
189
|
+
},
|
|
190
|
+
transformPasted(t, n) {
|
|
191
|
+
if ([e, n.dragging?.slice].some((e) => e?.eq(t))) return t;
|
|
192
|
+
let r = vt(t.content);
|
|
193
|
+
return r === t.content ? t : new Je(r, t.openStart, t.openEnd);
|
|
194
|
+
}
|
|
195
|
+
} });
|
|
196
|
+
}
|
|
197
|
+
var bt = Ue.extend({
|
|
198
|
+
addProseMirrorPlugins() {
|
|
199
|
+
return [...this.parent?.() ?? [], yt()];
|
|
200
|
+
},
|
|
201
|
+
renderHTML({ node: e, HTMLAttributes: t }) {
|
|
202
|
+
let n = [
|
|
203
|
+
"table",
|
|
204
|
+
Ne(this.options.HTMLAttributes, t),
|
|
205
|
+
["tbody", 0]
|
|
206
|
+
];
|
|
207
|
+
return e.firstChild?.children.some(({ attrs: e }) => Array.isArray(e.colwidth) && e.colwidth.some(Boolean)) ? this.parent?.({
|
|
208
|
+
node: e,
|
|
209
|
+
HTMLAttributes: t
|
|
210
|
+
}) ?? n : n;
|
|
211
|
+
}
|
|
212
|
+
}).configure({ cellMinWidth: 80 }), xt = We.configure({ table: !1 });
|
|
213
|
+
function St(e = ht, { tables: t = !0 } = {}, n = bt) {
|
|
214
|
+
return t ? [
|
|
215
|
+
e,
|
|
216
|
+
..._t,
|
|
217
|
+
n,
|
|
218
|
+
xt
|
|
219
|
+
] : [e, ..._t];
|
|
220
|
+
}
|
|
221
|
+
var Ct = {
|
|
222
|
+
withTables: Me(St()),
|
|
223
|
+
withoutTables: Me(St(ht, { tables: !1 }))
|
|
224
|
+
};
|
|
225
|
+
function wt(e) {
|
|
226
|
+
return e.content == null || Array.isArray(e.content) && !e.content.length ? {
|
|
227
|
+
...e,
|
|
228
|
+
content: gt.content
|
|
229
|
+
} : e;
|
|
230
|
+
}
|
|
231
|
+
var Tt = "Unsupported or invalid rich-text document.";
|
|
232
|
+
function Et(e) {
|
|
233
|
+
return {
|
|
234
|
+
definitions: e,
|
|
235
|
+
passed: /* @__PURE__ */ new WeakSet()
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function Dt(e, t) {
|
|
239
|
+
if (t.passed.has(e)) return !0;
|
|
240
|
+
if (e.type.name === "contentBlock") {
|
|
241
|
+
if (!b(e.attrs, t.definitions)) return !1;
|
|
242
|
+
} else if (!e.isTextblock) {
|
|
243
|
+
for (let n = 0; n < e.childCount; n += 1) if (!Dt(e.child(n), t)) return !1;
|
|
244
|
+
}
|
|
245
|
+
return t.passed.add(e), !0;
|
|
246
|
+
}
|
|
247
|
+
function Ot(e, t) {
|
|
248
|
+
if (typeof DOMParser > "u" || !/data-(content-block|storyblock)/i.test(e)) return;
|
|
249
|
+
let n = v(t), { body: r } = new DOMParser().parseFromString(e, "text/html"), i = r.querySelectorAll("[data-content-block], [data-storyblock]");
|
|
250
|
+
return Array.from(i).some((e) => e.tagName !== "DIV" || e.hasAttribute("data-storyblock") || !b(pt(e), n)) ? Tt : void 0;
|
|
251
|
+
}
|
|
252
|
+
function kt(e, { tables: t = !0, blockDefinitions: n = [] } = {}) {
|
|
253
|
+
let r = v(n), i = t ? Ct.withTables : Ct.withoutTables;
|
|
254
|
+
try {
|
|
255
|
+
if (!e || typeof e != "object" || !("type" in e) || e.type !== "doc") throw Error();
|
|
256
|
+
let t = (e) => {
|
|
257
|
+
let n = i.nodes[e.type ?? ""];
|
|
258
|
+
if (!n || Object.keys(e).some((e) => ![
|
|
259
|
+
"type",
|
|
260
|
+
"attrs",
|
|
261
|
+
"content",
|
|
262
|
+
"marks",
|
|
263
|
+
"text"
|
|
264
|
+
].includes(e)) || e.text !== void 0 && e.type !== "text" || e.content != null && !Array.isArray(e.content) || e.attrs && Object.keys(e.attrs).some((e) => !Object.hasOwn(n.spec.attrs ?? {}, e)) || e.type === "contentBlock" && (!b(e.attrs, r) || e.marks?.length)) throw Error();
|
|
265
|
+
for (let t of e.marks ?? []) {
|
|
266
|
+
let e = i.marks[t.type];
|
|
267
|
+
if (!e || Object.keys(t).some((e) => !["type", "attrs"].includes(e)) || Object.keys(t.attrs ?? {}).some((t) => !Object.hasOwn(e.spec.attrs ?? {}, t))) throw Error();
|
|
268
|
+
}
|
|
269
|
+
e.content?.forEach(t);
|
|
270
|
+
}, n = wt(e);
|
|
271
|
+
t(n), i.nodeFromJSON(n).check();
|
|
272
|
+
} catch {
|
|
273
|
+
return Tt;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/components/RichTextEditor/block-plugins.ts
|
|
278
|
+
var At = [], jt = /* @__PURE__ */ new WeakMap();
|
|
279
|
+
function Mt(e, t) {
|
|
280
|
+
if (e === t) return !0;
|
|
281
|
+
let n = jt.get(e), r = jt.get(t);
|
|
282
|
+
if (!n || !r || !ct(n, r)) return !1;
|
|
283
|
+
let i = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]);
|
|
284
|
+
return Array.from(i).every((n) => {
|
|
285
|
+
let r = e[n], i = t[n];
|
|
286
|
+
return typeof r == "function" && typeof i == "function" || Object.is(r, i);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function Nt(e, t) {
|
|
290
|
+
if (e === t) return !0;
|
|
291
|
+
if (e.size !== t.size) return !1;
|
|
292
|
+
for (let [n, r] of t) {
|
|
293
|
+
let t = e.get(n);
|
|
294
|
+
if (!t || !Mt(t, r)) return !1;
|
|
295
|
+
}
|
|
296
|
+
return !0;
|
|
297
|
+
}
|
|
298
|
+
var X = be({
|
|
299
|
+
plugins: /* @__PURE__ */ new Map(),
|
|
300
|
+
latest: () => void 0,
|
|
301
|
+
picks: /* @__PURE__ */ new Map(),
|
|
302
|
+
disabled: !1,
|
|
303
|
+
busy: !1,
|
|
304
|
+
revision: 0,
|
|
305
|
+
open: () => {}
|
|
306
|
+
}), Pt = "ds-content-block ds-field-surface";
|
|
307
|
+
function Ft({ action: e, groupDescription: t }) {
|
|
308
|
+
let n = z(), r = [e.description && n, e.disabled && t].filter(Boolean);
|
|
309
|
+
return /* @__PURE__ */ W(C, {
|
|
310
|
+
icon: e.icon,
|
|
311
|
+
tone: e.tone,
|
|
312
|
+
isDisabled: e.disabled,
|
|
313
|
+
className: e.inlineIcon ? "ds-content-block__inline-action" : void 0,
|
|
314
|
+
"aria-label": e.description ? e.label : void 0,
|
|
315
|
+
"aria-describedby": r.length ? r.join(" ") : void 0,
|
|
316
|
+
onClick: e.run,
|
|
317
|
+
children: e.description ? /* @__PURE__ */ G("span", { children: [e.label, /* @__PURE__ */ W("span", {
|
|
318
|
+
id: n,
|
|
319
|
+
className: "ds-content-block__description",
|
|
320
|
+
children: e.description
|
|
321
|
+
})] }) : e.label
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function It({ group: { label: e, description: n, actions: r, choices: i, keepOpen: a, separate: o } }) {
|
|
325
|
+
let s = z();
|
|
326
|
+
return /* @__PURE__ */ G(U, { children: [
|
|
327
|
+
o && /* @__PURE__ */ W(T, {}),
|
|
328
|
+
e && /* @__PURE__ */ W(w, { children: e }),
|
|
329
|
+
n && /* @__PURE__ */ W("span", {
|
|
330
|
+
id: s,
|
|
331
|
+
className: "ds-content-block__description ds-content-block__group-description",
|
|
332
|
+
children: n
|
|
333
|
+
}),
|
|
334
|
+
i ? /* @__PURE__ */ W(f, {
|
|
335
|
+
"aria-label": e,
|
|
336
|
+
children: r.map((e) => /* @__PURE__ */ W(t, {
|
|
337
|
+
role: "menuitemradio",
|
|
338
|
+
"aria-checked": e.checked,
|
|
339
|
+
"aria-label": e.label,
|
|
340
|
+
title: e.label,
|
|
341
|
+
size: "sm",
|
|
342
|
+
isIconOnly: !0,
|
|
343
|
+
iconStart: e.icon,
|
|
344
|
+
variant: e.checked ? "primary" : "neutral",
|
|
345
|
+
isDisabled: e.disabled,
|
|
346
|
+
onClick: (t) => {
|
|
347
|
+
a && t.preventDefault(), e.run();
|
|
348
|
+
}
|
|
349
|
+
}, e.label))
|
|
350
|
+
}) : r.map((e) => /* @__PURE__ */ W(Ft, {
|
|
351
|
+
action: e,
|
|
352
|
+
groupDescription: n ? s : void 0
|
|
353
|
+
}, e.label))
|
|
354
|
+
] });
|
|
355
|
+
}
|
|
356
|
+
function Lt({ groups: e }) {
|
|
357
|
+
return e.map((e) => /* @__PURE__ */ W(It, { group: e }, e.label ?? e.actions[0]?.label));
|
|
358
|
+
}
|
|
359
|
+
function Rt({ kind: t, meta: n, isMovable: r, onSelect: i }) {
|
|
360
|
+
return /* @__PURE__ */ G("span", {
|
|
361
|
+
className: "ds-content-block__kind",
|
|
362
|
+
"data-drag-handle": r ? "" : void 0,
|
|
363
|
+
draggable: r || void 0,
|
|
364
|
+
title: r ? "Drag to move" : void 0,
|
|
365
|
+
onClick: r ? i : void 0,
|
|
366
|
+
children: [
|
|
367
|
+
r && /* @__PURE__ */ W("span", {
|
|
368
|
+
className: "ds-content-block__grip",
|
|
369
|
+
"aria-hidden": "true",
|
|
370
|
+
children: /* @__PURE__ */ W(e, {
|
|
371
|
+
name: "grip-vertical",
|
|
372
|
+
size: 16
|
|
373
|
+
})
|
|
374
|
+
}),
|
|
375
|
+
/* @__PURE__ */ W(p, {
|
|
376
|
+
className: "ds-content-block__kind-label",
|
|
377
|
+
shape: "tag",
|
|
378
|
+
size: "sm",
|
|
379
|
+
children: t
|
|
380
|
+
}),
|
|
381
|
+
n && /* @__PURE__ */ W("bdi", {
|
|
382
|
+
className: "ds-rte__block-meta",
|
|
383
|
+
children: n
|
|
384
|
+
})
|
|
385
|
+
]
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
function zt({ kind: e, meta: n, isSelected: r, isDisabled: i, isLocked: a, menuLabel: o, actions: s, onSelect: c }) {
|
|
389
|
+
let [l, u] = H(!1), [d, f] = H("end"), [p, m] = H([]), h = {
|
|
390
|
+
size: "sm",
|
|
391
|
+
isIconOnly: !0,
|
|
392
|
+
iconStart: "more-horizontal",
|
|
393
|
+
"aria-label": o,
|
|
394
|
+
title: o
|
|
395
|
+
};
|
|
396
|
+
return /* @__PURE__ */ G("div", {
|
|
397
|
+
className: "ds-content-block__bar ds-field-surface",
|
|
398
|
+
onMouseDown: (e) => {
|
|
399
|
+
let t = e.target;
|
|
400
|
+
!i && !a && t instanceof Element && e.currentTarget.contains(t) && !t.closest("button, [data-drag-handle]") && (e.preventDefault(), c());
|
|
401
|
+
},
|
|
402
|
+
children: [/* @__PURE__ */ W(Rt, {
|
|
403
|
+
kind: e,
|
|
404
|
+
meta: n,
|
|
405
|
+
isMovable: !i && !a,
|
|
406
|
+
onSelect: c
|
|
407
|
+
}), !i && (a ? /* @__PURE__ */ W(t, {
|
|
408
|
+
...h,
|
|
409
|
+
variant: "simple",
|
|
410
|
+
isDisabled: !0,
|
|
411
|
+
"aria-haspopup": "menu",
|
|
412
|
+
"aria-expanded": !1
|
|
413
|
+
}) : /* @__PURE__ */ W(S, {
|
|
414
|
+
"aria-label": o,
|
|
415
|
+
align: d,
|
|
416
|
+
trigger: (e) => /* @__PURE__ */ W(t, {
|
|
417
|
+
...e,
|
|
418
|
+
...h,
|
|
419
|
+
variant: e["aria-expanded"] ? "active" : "simple",
|
|
420
|
+
tabIndex: r || l || e["aria-expanded"] ? 0 : -1,
|
|
421
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
422
|
+
onFocus: () => u(!0),
|
|
423
|
+
onBlur: () => u(!1),
|
|
424
|
+
onClick: (t) => {
|
|
425
|
+
if (!e["aria-expanded"]) {
|
|
426
|
+
let e = getComputedStyle(t.currentTarget).direction === "rtl";
|
|
427
|
+
f(e ? "start" : "end"), typeof s == "function" && m(s(e));
|
|
428
|
+
}
|
|
429
|
+
e.onClick();
|
|
430
|
+
}
|
|
431
|
+
}),
|
|
432
|
+
children: /* @__PURE__ */ W(Lt, { groups: typeof s == "function" ? p : s })
|
|
433
|
+
}))]
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/components/RichTextEditor/content-block-view.tsx
|
|
438
|
+
var Bt = [
|
|
439
|
+
{
|
|
440
|
+
align: "left",
|
|
441
|
+
icon: "align-left",
|
|
442
|
+
label: "Align left"
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
align: "full",
|
|
446
|
+
icon: "align-justify",
|
|
447
|
+
label: "Full width"
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
align: "right",
|
|
451
|
+
icon: "align-right",
|
|
452
|
+
label: "Align right"
|
|
453
|
+
}
|
|
454
|
+
];
|
|
455
|
+
function Vt({ node: e, selected: t, editor: n, getPos: r, updateAttributes: i }) {
|
|
456
|
+
let { disabled: a, busy: o, open: s, plugins: c } = L(X), l = String(e.attrs.type), u = c.get(l), d = B(() => !!u && b(e.attrs, /* @__PURE__ */ new Map([[l, u.definition]])), [
|
|
457
|
+
u,
|
|
458
|
+
e.attrs,
|
|
459
|
+
l
|
|
460
|
+
]) ? u : void 0, f = u?.label ?? l, p = e.attrs.data, m = e.attrs.align ?? "full", h = t && !a, g = () => {
|
|
461
|
+
let e = r();
|
|
462
|
+
e !== void 0 && n.chain().focus().setNodeSelection(e).run();
|
|
463
|
+
}, _ = () => {
|
|
464
|
+
let t = r();
|
|
465
|
+
t !== void 0 && n.chain().focus().setNodeSelection(t).deleteRange({
|
|
466
|
+
from: t,
|
|
467
|
+
to: t + e.nodeSize
|
|
468
|
+
}).run();
|
|
469
|
+
}, v = (e) => {
|
|
470
|
+
let t = e.target;
|
|
471
|
+
!e.defaultPrevented && t instanceof Element && e.currentTarget.contains(t) && (t.closest("button") ? e.preventDefault() : !a && !t.closest("[data-drag-handle]") && (e.preventDefault(), g()));
|
|
472
|
+
}, y = (e) => {
|
|
473
|
+
let t = r();
|
|
474
|
+
t !== void 0 && s(l, e, t);
|
|
475
|
+
}, x = ({ title: e, body: t, tone: n, missing: r, onEdit: s, replaceLabel: c }) => {
|
|
476
|
+
let p = [];
|
|
477
|
+
return (s || d?.editLabel && d.renderEditor) && p.push({
|
|
478
|
+
label: d?.editLabel ?? `Edit ${f}`,
|
|
479
|
+
icon: "pencil",
|
|
480
|
+
disabled: !s && o,
|
|
481
|
+
run: s ?? (() => y("edit"))
|
|
482
|
+
}), d?.replaceLabel && d.renderEditor && p.push({
|
|
483
|
+
label: c ?? d.replaceLabel,
|
|
484
|
+
icon: "rotate-cw",
|
|
485
|
+
disabled: o,
|
|
486
|
+
run: () => y("replace")
|
|
487
|
+
}), /* @__PURE__ */ G(De, {
|
|
488
|
+
className: Pt,
|
|
489
|
+
"data-kind": l,
|
|
490
|
+
"data-align": m,
|
|
491
|
+
"data-selected": h || void 0,
|
|
492
|
+
"data-missing": r || void 0,
|
|
493
|
+
"data-tone": r ? "removed" : n,
|
|
494
|
+
contentEditable: !1,
|
|
495
|
+
onMouseDown: v,
|
|
496
|
+
children: [/* @__PURE__ */ W(zt, {
|
|
497
|
+
kind: f,
|
|
498
|
+
isSelected: h,
|
|
499
|
+
isDisabled: a,
|
|
500
|
+
isLocked: !!u?.isDialogHidden,
|
|
501
|
+
menuLabel: `Block actions for ${e ?? f}`,
|
|
502
|
+
onSelect: g,
|
|
503
|
+
actions: [
|
|
504
|
+
{
|
|
505
|
+
label: "Alignment",
|
|
506
|
+
choices: !0,
|
|
507
|
+
keepOpen: !0,
|
|
508
|
+
actions: Bt.map((e) => ({
|
|
509
|
+
label: e.label,
|
|
510
|
+
icon: e.icon,
|
|
511
|
+
checked: m === e.align,
|
|
512
|
+
run: () => i({ align: e.align })
|
|
513
|
+
}))
|
|
514
|
+
},
|
|
515
|
+
...p.length ? [{
|
|
516
|
+
actions: p,
|
|
517
|
+
separate: !0
|
|
518
|
+
}] : [],
|
|
519
|
+
{
|
|
520
|
+
separate: !0,
|
|
521
|
+
actions: [{
|
|
522
|
+
label: "Remove from field",
|
|
523
|
+
icon: "trash",
|
|
524
|
+
tone: "danger",
|
|
525
|
+
run: _
|
|
526
|
+
}]
|
|
527
|
+
}
|
|
528
|
+
]
|
|
529
|
+
}), t]
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
return d?.renderPreview ? d.renderPreview(p, x) : x({});
|
|
533
|
+
}
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region src/components/RichTextEditor/use-blocks.tsx
|
|
536
|
+
var Ht = "ds-rte-block-commit";
|
|
537
|
+
function Ut(e, t) {
|
|
538
|
+
return !!e && !!t.node && e.type === t.node.type && e.hasMarkup(t.node.type, {
|
|
539
|
+
...t.node.attrs,
|
|
540
|
+
align: e.attrs.align
|
|
541
|
+
}, t.node.marks);
|
|
542
|
+
}
|
|
543
|
+
function Wt(e, t) {
|
|
544
|
+
if (e?.renderEditor) switch (t) {
|
|
545
|
+
case "insert": return e.insertLabel;
|
|
546
|
+
case "edit": return e.editLabel;
|
|
547
|
+
case "replace": return e.replaceLabel;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function Gt(e) {
|
|
551
|
+
return e.flatMap((e) => e.mapping.maps);
|
|
552
|
+
}
|
|
553
|
+
function Kt(e, t) {
|
|
554
|
+
let n = t;
|
|
555
|
+
for (let t of Gt(e)) {
|
|
556
|
+
let e = n, r;
|
|
557
|
+
if (t.forEach((t, n, i, a) => {
|
|
558
|
+
r === void 0 && t <= e && e < n && n - t === a - i && (r = i + (e - t));
|
|
559
|
+
}), r !== void 0) {
|
|
560
|
+
n = r;
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
let i = t.mapResult(e, 1);
|
|
564
|
+
if (i.deletedAfter) return null;
|
|
565
|
+
n = i.pos;
|
|
566
|
+
}
|
|
567
|
+
return n;
|
|
568
|
+
}
|
|
569
|
+
function qt(e, t, n) {
|
|
570
|
+
let r = t, i = n;
|
|
571
|
+
for (let t of Gt(e)) {
|
|
572
|
+
if (r === i) {
|
|
573
|
+
r = i = t.map(i, -1);
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
let e = !1;
|
|
577
|
+
if (t.forEach((t, n, a, o) => {
|
|
578
|
+
let s = i - r === 1 && t === r && n === i && o - a === 1;
|
|
579
|
+
e ||= t <= r && i <= n && !s;
|
|
580
|
+
}), r = t.map(r, 1), i = t.map(i, -1), e || i <= r) return null;
|
|
581
|
+
}
|
|
582
|
+
return {
|
|
583
|
+
from: r,
|
|
584
|
+
to: i
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function Jt(e, t) {
|
|
588
|
+
let n = e.resolve(Math.min(t, e.content.size));
|
|
589
|
+
return n.depth ? n.after(1) : n.pos;
|
|
590
|
+
}
|
|
591
|
+
function Yt(e, n, r, i) {
|
|
592
|
+
let [a, o] = H(null), s = V(0), c = V(null), [l, d] = H(0), p = I(() => {
|
|
593
|
+
c.current && (c.current.alive = !1), o(null);
|
|
594
|
+
}, []), m = a ? n.get(a.kind) : void 0, h = a && Wt(m, a.mode) && (!r || m?.isCreating);
|
|
595
|
+
a && !h && o(null);
|
|
596
|
+
let g = !!(h && (m?.isDialogHidden || m?.isCreating)), _ = u({
|
|
597
|
+
editor: e,
|
|
598
|
+
plugins: n,
|
|
599
|
+
disabled: r,
|
|
600
|
+
busy: g
|
|
601
|
+
}), v = lt(n, Nt), y = I((e) => _.current.plugins.get(e), [_]), [x] = H(() => /* @__PURE__ */ new Map());
|
|
602
|
+
R(() => {
|
|
603
|
+
let t = c.current;
|
|
604
|
+
if (!e || !a || t?.session !== a) return;
|
|
605
|
+
if (t.editor !== e) {
|
|
606
|
+
p();
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
let n = ({ editor: e, transaction: n, appendedTransactions: r }) => {
|
|
610
|
+
let i = [n, ...r];
|
|
611
|
+
if (!t.alive || !i.some((e) => e.docChanged)) return;
|
|
612
|
+
if (a.mode === "insert") {
|
|
613
|
+
let e = qt(i, t.from, t.to);
|
|
614
|
+
e ? Object.assign(t, e) : p();
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
let o = Kt(i, t.from);
|
|
618
|
+
o === null || !Ut(e.state.doc.nodeAt(o), a) ? p() : Object.assign(t, {
|
|
619
|
+
from: o,
|
|
620
|
+
to: o + 1
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
return e.on("transaction", n), () => {
|
|
624
|
+
e.off("transaction", n), t.alive = !1;
|
|
625
|
+
};
|
|
626
|
+
}, [
|
|
627
|
+
e,
|
|
628
|
+
a,
|
|
629
|
+
p
|
|
630
|
+
]);
|
|
631
|
+
let S = I((e) => {
|
|
632
|
+
let { editor: t, plugins: n, disabled: r } = _.current, i = c.current, a = n.get(e.kind);
|
|
633
|
+
return !(!t || t.isDestroyed || i?.session !== e || i.editor !== t || !i.alive || !Wt(a, e.mode) || r && !a?.isCreating);
|
|
634
|
+
}, [_]), C = I((e, t) => {
|
|
635
|
+
let n = _.current.editor, r = c.current, i = _.current.plugins.get(e.kind)?.definition, a = e.mode !== "insert", o = Array.isArray(t) ? t : [t];
|
|
636
|
+
if (!n || !r || !i || !S(e) || !o.length || a && o.length !== 1) return !1;
|
|
637
|
+
let s = a ? n.state.doc.nodeAt(r.from) : null;
|
|
638
|
+
if (a && !Ut(s, e)) return !1;
|
|
639
|
+
let l = /* @__PURE__ */ new Map([[e.kind, i]]), u = o.map((t) => ({
|
|
640
|
+
type: e.kind,
|
|
641
|
+
align: s?.attrs.align ?? "full",
|
|
642
|
+
data: t
|
|
643
|
+
}));
|
|
644
|
+
if (!u.every((e) => b(e, l))) return !1;
|
|
645
|
+
let f = a ? r.from : Jt(n.state.doc, r.to);
|
|
646
|
+
r.alive = !1;
|
|
647
|
+
let m;
|
|
648
|
+
try {
|
|
649
|
+
let e = n.chain().focus().setMeta(Ht, !0).command(({ tr: e }) => (q(e), !0));
|
|
650
|
+
m = a ? e.setNodeSelection(f).updateAttributes("contentBlock", u[0]).run() : e.insertContentAt(f, u.map((e) => ({
|
|
651
|
+
type: "contentBlock",
|
|
652
|
+
attrs: e
|
|
653
|
+
}))).setNodeSelection(f + u.length - 1).run();
|
|
654
|
+
} catch {
|
|
655
|
+
m = !1;
|
|
656
|
+
} finally {
|
|
657
|
+
p();
|
|
658
|
+
}
|
|
659
|
+
return m && (n.isDestroyed || n.view.dispatch(q(n.state.tr)), d((e) => e + 1)), m;
|
|
660
|
+
}, [
|
|
661
|
+
S,
|
|
662
|
+
p,
|
|
663
|
+
_
|
|
664
|
+
]), w = I((e, t, n) => {
|
|
665
|
+
let { editor: r, plugins: i, disabled: a, busy: l } = _.current;
|
|
666
|
+
if (!r || a || l || !Wt(i.get(e), t)) return;
|
|
667
|
+
let u = n === void 0 ? null : r.state.doc.nodeAt(n);
|
|
668
|
+
if (t !== "insert" && (u?.type.name !== "contentBlock" || u.attrs.type !== e)) return;
|
|
669
|
+
let { $from: d, from: f, to: m } = r.state.selection, h = {
|
|
670
|
+
id: ++s.current,
|
|
671
|
+
kind: e,
|
|
672
|
+
mode: t,
|
|
673
|
+
node: u,
|
|
674
|
+
target: {
|
|
675
|
+
available: () => S(h),
|
|
676
|
+
commit: (e) => C(h, e),
|
|
677
|
+
close: () => {
|
|
678
|
+
c.current?.session === h && p();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}, g = n === void 0 ? d.depth ? {
|
|
682
|
+
from: d.before(1),
|
|
683
|
+
to: d.after(1)
|
|
684
|
+
} : {
|
|
685
|
+
from: f,
|
|
686
|
+
to: m
|
|
687
|
+
} : {
|
|
688
|
+
from: n,
|
|
689
|
+
to: n + 1
|
|
690
|
+
};
|
|
691
|
+
c.current = {
|
|
692
|
+
session: h,
|
|
693
|
+
editor: r,
|
|
694
|
+
...g,
|
|
695
|
+
alive: !0
|
|
696
|
+
}, o(h);
|
|
697
|
+
}, [
|
|
698
|
+
S,
|
|
699
|
+
p,
|
|
700
|
+
C,
|
|
701
|
+
_
|
|
702
|
+
]), T = B(() => ({
|
|
703
|
+
plugins: v,
|
|
704
|
+
latest: y,
|
|
705
|
+
picks: x,
|
|
706
|
+
disabled: r,
|
|
707
|
+
busy: g,
|
|
708
|
+
revision: l,
|
|
709
|
+
open: w
|
|
710
|
+
}), [
|
|
711
|
+
v,
|
|
712
|
+
y,
|
|
713
|
+
x,
|
|
714
|
+
r,
|
|
715
|
+
g,
|
|
716
|
+
l,
|
|
717
|
+
w
|
|
718
|
+
]), E = Array.from(n.values()), D = E.filter((e) => Wt(e, "insert")), O = h && a.mode === "insert" ? a.kind : void 0;
|
|
719
|
+
return {
|
|
720
|
+
context: T,
|
|
721
|
+
isCreating: E.some((e) => e.isCreating),
|
|
722
|
+
toolbar: D.length > 0 && /* @__PURE__ */ W(f, {
|
|
723
|
+
"aria-label": "Insert content block",
|
|
724
|
+
children: D.map(({ definition: n, insertLabel: i, icon: a }) => /* @__PURE__ */ W(t, {
|
|
725
|
+
size: "sm",
|
|
726
|
+
isIconOnly: !0,
|
|
727
|
+
iconStart: a,
|
|
728
|
+
"aria-label": i,
|
|
729
|
+
title: i,
|
|
730
|
+
"aria-pressed": O === n.type,
|
|
731
|
+
variant: O === n.type ? "primary" : "neutral",
|
|
732
|
+
isDisabled: r || !e || g,
|
|
733
|
+
onClick: () => w(n.type, "insert")
|
|
734
|
+
}, n.type))
|
|
735
|
+
}),
|
|
736
|
+
dialog: h && /* @__PURE__ */ W(ye, { children: m?.renderEditor?.({
|
|
737
|
+
mode: a.mode,
|
|
738
|
+
data: a.node?.attrs.data,
|
|
739
|
+
target: a.target,
|
|
740
|
+
isDisabled: r,
|
|
741
|
+
fieldLabel: i
|
|
742
|
+
}) }, a.id)
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
//#endregion
|
|
746
|
+
//#region src/components/RichTextEditor/expanded-width.ts
|
|
747
|
+
var Xt = ["wide", "full"], Zt = [
|
|
748
|
+
"sm",
|
|
749
|
+
"md",
|
|
750
|
+
"lg"
|
|
751
|
+
], Qt = /* @__PURE__ */ new Set([
|
|
752
|
+
"shortText",
|
|
753
|
+
"longText",
|
|
754
|
+
"richText",
|
|
755
|
+
"number",
|
|
756
|
+
"boolean",
|
|
757
|
+
"dateTime",
|
|
758
|
+
"asset",
|
|
759
|
+
"reference",
|
|
760
|
+
"select",
|
|
761
|
+
"slider",
|
|
762
|
+
"rangeSlider",
|
|
763
|
+
"colour",
|
|
764
|
+
"radioGroup",
|
|
765
|
+
"checkboxGroup",
|
|
766
|
+
"tags",
|
|
767
|
+
"date",
|
|
768
|
+
"divider"
|
|
769
|
+
]);
|
|
770
|
+
function $t(e) {
|
|
771
|
+
let t = /* @__PURE__ */ new Set();
|
|
772
|
+
for (let n of e.fields) {
|
|
773
|
+
if (!n.id?.trim() || t.has(n.id)) throw Error("Form field IDs must be nonempty and unique.");
|
|
774
|
+
if (!Qt.has(n.type)) throw Error(`Unsupported form field type: ${n.type}`);
|
|
775
|
+
if ("labelHint" in n) throw Error(`Field ${n.id} uses the removed labelHint; move its content into hint.`);
|
|
776
|
+
n.type !== "divider" && (en(n), dn(n), an(n)), t.add(n.id);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function en(e) {
|
|
780
|
+
switch (e.type) {
|
|
781
|
+
case "select":
|
|
782
|
+
case "radioGroup":
|
|
783
|
+
case "checkboxGroup": return mn(e);
|
|
784
|
+
case "slider":
|
|
785
|
+
case "rangeSlider": return fn(e);
|
|
786
|
+
case "number": return pn(e);
|
|
787
|
+
case "richText":
|
|
788
|
+
if (e.tables !== void 0 && typeof e.tables != "boolean") throw Error(`Rich text field ${e.id} needs a boolean tables.`);
|
|
789
|
+
return tn(e);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function tn(e) {
|
|
793
|
+
if (e.blockDefinitions !== void 0) {
|
|
794
|
+
if (!Array.isArray(e.blockDefinitions)) throw Error(`Rich text field ${e.id} needs an array of blockDefinitions.`);
|
|
795
|
+
try {
|
|
796
|
+
v(e.blockDefinitions);
|
|
797
|
+
} catch (t) {
|
|
798
|
+
let n = t instanceof Error ? ` ${t.message}` : "";
|
|
799
|
+
throw Error(`Rich text field ${e.id} has invalid blockDefinitions.${n}`);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
var nn = /* @__PURE__ */ new Set([
|
|
804
|
+
"shortText",
|
|
805
|
+
"longText",
|
|
806
|
+
"tags",
|
|
807
|
+
"asset",
|
|
808
|
+
"reference"
|
|
809
|
+
]);
|
|
810
|
+
function rn(e) {
|
|
811
|
+
return nn.has(e.type);
|
|
812
|
+
}
|
|
813
|
+
function an(e) {
|
|
814
|
+
if (rn(e)) {
|
|
815
|
+
if (e.limitDisplay !== void 0 && !["used", "remaining"].includes(e.limitDisplay)) throw Error(`Field ${e.id} needs a limitDisplay of used or remaining.`);
|
|
816
|
+
if (e.limitVisibility !== void 0 && !["always", "nearLimit"].includes(e.limitVisibility)) throw Error(`Field ${e.id} needs a limitVisibility of always or nearLimit.`);
|
|
817
|
+
if (e.showLimitRing !== void 0 && typeof e.showLimitRing != "boolean") throw Error(`Field ${e.id} needs a boolean showLimitRing.`);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
function on(e, t, n, r) {
|
|
821
|
+
return rn(e) ? {
|
|
822
|
+
limitDisplay: e.limitDisplay,
|
|
823
|
+
limitVisibility: e.limitVisibility,
|
|
824
|
+
showLimitRing: e.showLimitRing,
|
|
825
|
+
limit: sn(e, t, n ?? [], r)
|
|
826
|
+
} : {};
|
|
827
|
+
}
|
|
828
|
+
function sn(e, t, n, r) {
|
|
829
|
+
switch (e.type) {
|
|
830
|
+
case "shortText":
|
|
831
|
+
case "longText": return e.maxLength === void 0 ? void 0 : {
|
|
832
|
+
count: ln(t).length,
|
|
833
|
+
max: e.maxLength
|
|
834
|
+
};
|
|
835
|
+
case "tags": return e.max === void 0 ? void 0 : {
|
|
836
|
+
count: Tn(t).length,
|
|
837
|
+
max: e.max
|
|
838
|
+
};
|
|
839
|
+
default: {
|
|
840
|
+
let { mode: t, max: i } = un(e, r);
|
|
841
|
+
return D(t, n.length, i);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
function cn(e, t, n, r) {
|
|
846
|
+
if (n !== void 0 && (e.type === "asset" || e.type === "reference")) {
|
|
847
|
+
let { mode: t, max: i } = un(e, r);
|
|
848
|
+
return ee(t, n.length, i);
|
|
849
|
+
}
|
|
850
|
+
return e.type === "checkboxGroup" ? Tn(t).length : void 0;
|
|
851
|
+
}
|
|
852
|
+
function ln(e) {
|
|
853
|
+
return typeof e == "string" ? e : "";
|
|
854
|
+
}
|
|
855
|
+
function un(e, t) {
|
|
856
|
+
let n = t?.mode ?? (e.multiple ? "multiple" : "single");
|
|
857
|
+
if (!e.multiple) return {
|
|
858
|
+
mode: n,
|
|
859
|
+
max: n === "multiple" ? 1 : void 0
|
|
860
|
+
};
|
|
861
|
+
let r = [_n(e).max, t?.max].filter((e) => e !== void 0 && Number.isFinite(e));
|
|
862
|
+
return {
|
|
863
|
+
mode: n,
|
|
864
|
+
max: r.length > 0 ? Math.min(...r) : void 0
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
function dn(e) {
|
|
868
|
+
if (e.width !== void 0 && !Zt.includes(e.width)) throw Error(`Field ${e.id} needs a width of sm, md or lg.`);
|
|
869
|
+
if (e.type === "richText" && e.expandedWidth !== void 0 && !Xt.includes(e.expandedWidth)) throw Error(`Rich text field ${e.id} needs an expandedWidth of wide or full.`);
|
|
870
|
+
}
|
|
871
|
+
function fn(e) {
|
|
872
|
+
let { min: t, max: n, step: r } = M(e);
|
|
873
|
+
if (![
|
|
874
|
+
t,
|
|
875
|
+
n,
|
|
876
|
+
r
|
|
877
|
+
].every(Number.isFinite) || t >= n || r <= 0) throw Error(`Slider field ${e.id} needs finite min < max and a positive step.`);
|
|
878
|
+
if (e.type === "rangeSlider" && r > ce(n, -t)) throw Error(`Range slider ${e.id} needs room for at least one step.`);
|
|
879
|
+
}
|
|
880
|
+
function pn(e) {
|
|
881
|
+
let { min: t, max: n, step: r = "any" } = e;
|
|
882
|
+
if ([t, n].some((e) => e !== void 0 && !Number.isFinite(e)) || t !== void 0 && n !== void 0 && t > n || r !== "any" && !(Number.isFinite(r) && r > 0)) throw Error(`Number field ${e.id} needs finite min <= max and a positive step or "any".`);
|
|
883
|
+
if ([e.decreaseLabel, e.increaseLabel].some((e) => e !== void 0 && (typeof e != "string" || !e.trim()))) throw Error(`Number field ${e.id} needs nonempty stepper labels.`);
|
|
884
|
+
}
|
|
885
|
+
function mn(e) {
|
|
886
|
+
if (!Array.isArray(e.options)) {
|
|
887
|
+
let t = e.type === "select" ? "Select" : "Choice";
|
|
888
|
+
throw Error(`${t} field ${e.id} needs an options array.`);
|
|
889
|
+
}
|
|
890
|
+
if (e.type === "select") return;
|
|
891
|
+
let t = e.options.map((e) => e.value);
|
|
892
|
+
if (t.some((e) => typeof e != "string" || !e.trim()) || new Set(t).size !== t.length) throw Error(`Choice field ${e.id} needs nonempty, unique option values.`);
|
|
893
|
+
}
|
|
894
|
+
var hn = {
|
|
895
|
+
asset: {
|
|
896
|
+
key: "assetId",
|
|
897
|
+
itemLabel: "asset",
|
|
898
|
+
itemsLabel: "assets"
|
|
899
|
+
},
|
|
900
|
+
reference: {
|
|
901
|
+
key: "entryId",
|
|
902
|
+
itemLabel: "entry",
|
|
903
|
+
itemsLabel: "entries"
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
function gn(e) {
|
|
907
|
+
return e.type === "asset" || e.type === "reference" ? e.picker?.label ?? e.label : e.label;
|
|
908
|
+
}
|
|
909
|
+
function _n(e) {
|
|
910
|
+
let t = hn[e.type], { addLabel: n = `Choose ${gn(e)}`, emptyLabel: r, itemLabel: i = t.itemLabel, itemsLabel: a = t.itemsLabel, max: o, isReorderable: s } = e.picker ?? {};
|
|
911
|
+
return {
|
|
912
|
+
addLabel: n,
|
|
913
|
+
emptyLabel: r,
|
|
914
|
+
itemLabel: i,
|
|
915
|
+
itemsLabel: a,
|
|
916
|
+
max: o,
|
|
917
|
+
isReorderable: s
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
function vn(e, t) {
|
|
921
|
+
let { key: n } = hn[e.type];
|
|
922
|
+
return (Array.isArray(t) ? t : t === void 0 ? [] : [t]).flatMap((e) => bn(e, n) ? [e[n]] : []);
|
|
923
|
+
}
|
|
924
|
+
function yn(e) {
|
|
925
|
+
if (typeof e != "string") return;
|
|
926
|
+
let t = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|\+00:00)$/.exec(e);
|
|
927
|
+
if (!t) return;
|
|
928
|
+
let n = `${t[1]}:${t[2] ?? "00"}.${(t[3] ?? "").padEnd(3, "0")}Z`, r = new Date(n);
|
|
929
|
+
if (Number.isFinite(r.getTime()) && r.toISOString() === n) return n;
|
|
930
|
+
}
|
|
931
|
+
function bn(e, t) {
|
|
932
|
+
return !!e && typeof e == "object" && t in e && typeof e[t] == "string" && e[t].trim().length > 0;
|
|
933
|
+
}
|
|
934
|
+
function xn(e) {
|
|
935
|
+
return !!e.text?.trim() || e.type === "horizontalRule" || e.type === "contentBlock" || !!e.content?.some(xn);
|
|
936
|
+
}
|
|
937
|
+
function Z(e) {
|
|
938
|
+
return `${gn(e)} is required.`;
|
|
939
|
+
}
|
|
940
|
+
function Sn(e, t) {
|
|
941
|
+
if (typeof t != "string") return "Enter text.";
|
|
942
|
+
if (e.required && !t.trim()) return Z(e);
|
|
943
|
+
if ((e.type === "shortText" || e.type === "longText") && e.maxLength !== void 0 && t.length > e.maxLength) return `Enter no more than ${e.maxLength} characters.`;
|
|
944
|
+
}
|
|
945
|
+
function Cn(e, t) {
|
|
946
|
+
let n = kt(t, {
|
|
947
|
+
tables: e.type !== "richText" || e.tables !== !1,
|
|
948
|
+
blockDefinitions: e.type === "richText" ? e.blockDefinitions : void 0
|
|
949
|
+
});
|
|
950
|
+
if (n) return n;
|
|
951
|
+
if (e.required && !xn(wt(t))) return Z(e);
|
|
952
|
+
}
|
|
953
|
+
function wn(e, t) {
|
|
954
|
+
if (typeof t != "string") return "Choose an available option.";
|
|
955
|
+
if (t === "") return e.required ? Z(e) : void 0;
|
|
956
|
+
if ((e.type === "select" || e.type === "radioGroup") && e.options.length > 0 && !e.options.some((e) => e.value === t)) return "Choose an available option.";
|
|
957
|
+
}
|
|
958
|
+
function Tn(e) {
|
|
959
|
+
return Array.isArray(e) ? e.filter((e) => typeof e == "string") : [];
|
|
960
|
+
}
|
|
961
|
+
function En(e, t) {
|
|
962
|
+
if (!Array.isArray(t) || !t.every((e) => typeof e == "string" && e.trim()) || new Set(t).size !== t.length) return "Enter a list of unique, nonempty text values.";
|
|
963
|
+
if (e.required && !t.length) return Z(e);
|
|
964
|
+
if (e.type === "tags" && e.max !== void 0 && t.length > e.max) return `Enter no more than ${e.max} tags.`;
|
|
965
|
+
if (e.type === "checkboxGroup" && e.options.length && t.some((t) => !e.options.some((e) => e.value === t))) return "Choose available options.";
|
|
966
|
+
}
|
|
967
|
+
function Dn(e, t) {
|
|
968
|
+
if (typeof t != "number" || !Number.isFinite(t)) return "Enter a finite number.";
|
|
969
|
+
let { min: n, max: r } = e.type === "slider" || e.type === "rangeSlider" ? M(e) : e.type === "number" ? e : {};
|
|
970
|
+
if (n !== void 0 && t < n) return `Enter a number of at least ${n}.`;
|
|
971
|
+
if (r !== void 0 && t > r) return `Enter a number no greater than ${r}.`;
|
|
972
|
+
}
|
|
973
|
+
function On(e, t) {
|
|
974
|
+
if (typeof t != "string") return "Enter a valid calendar date (YYYY-MM-DD).";
|
|
975
|
+
if (!t) return e.required ? Z(e) : void 0;
|
|
976
|
+
if (!me(t)) return "Enter a valid calendar date (YYYY-MM-DD).";
|
|
977
|
+
if (e.type === "date") {
|
|
978
|
+
if (e.min && t < e.min) return `Choose a date on or after ${e.min}.`;
|
|
979
|
+
if (e.max && t > e.max) return `Choose a date on or before ${e.max}.`;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
function kn(e, t) {
|
|
983
|
+
return typeof e == "number" && Number.isFinite(e) ? P(e, t) : void 0;
|
|
984
|
+
}
|
|
985
|
+
function An(e, t) {
|
|
986
|
+
let n = e, r = kn(n?.min, t), i = kn(n?.max, t);
|
|
987
|
+
if (r === void 0 && i === void 0) return;
|
|
988
|
+
let [a, o] = [r ?? t.min, i ?? t.max].sort((e, t) => e - t);
|
|
989
|
+
return {
|
|
990
|
+
min: a,
|
|
991
|
+
max: o
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
function jn(e, t) {
|
|
995
|
+
if (!t || typeof t != "object" || Array.isArray(t)) return "Enter a range.";
|
|
996
|
+
let n = t, r = n.min, i = n.max, a = Dn(e, r) ?? Dn(e, i);
|
|
997
|
+
if (a) return a;
|
|
998
|
+
if (r > i) return "The start must not be greater than the end.";
|
|
999
|
+
if (e.type === "rangeSlider" && ce(i, -r) < M(e).step) return "Keep the range endpoints at least one step apart.";
|
|
1000
|
+
}
|
|
1001
|
+
function Mn(e, t) {
|
|
1002
|
+
return typeof t == "string" ? t.trim() ? j(t) ? void 0 : "Enter a valid colour." : e.required ? Z(e) : void 0 : "Enter a valid colour.";
|
|
1003
|
+
}
|
|
1004
|
+
function Nn(e, t) {
|
|
1005
|
+
if (e.type !== "asset" && e.type !== "reference") return;
|
|
1006
|
+
let { key: n, itemLabel: r, itemsLabel: i } = hn[e.type];
|
|
1007
|
+
if (!e.multiple) return bn(t, n) ? void 0 : `Choose an ${r}.`;
|
|
1008
|
+
if (!Array.isArray(t) || !t.every((e) => bn(e, n))) return `Choose a list of ${i}.`;
|
|
1009
|
+
if (e.required && t.length === 0) return Z(e);
|
|
1010
|
+
let a = e.picker?.max;
|
|
1011
|
+
if (a !== void 0 && t.length > a) return `Choose no more than ${a} ${_n(e).itemsLabel}.`;
|
|
1012
|
+
}
|
|
1013
|
+
var Pn = {
|
|
1014
|
+
shortText: Sn,
|
|
1015
|
+
longText: Sn,
|
|
1016
|
+
richText: Cn,
|
|
1017
|
+
number: Dn,
|
|
1018
|
+
slider: Dn,
|
|
1019
|
+
rangeSlider: jn,
|
|
1020
|
+
date: On,
|
|
1021
|
+
colour: Mn,
|
|
1022
|
+
radioGroup: wn,
|
|
1023
|
+
checkboxGroup: En,
|
|
1024
|
+
tags: En,
|
|
1025
|
+
boolean: (e, t) => typeof t == "boolean" ? void 0 : "Choose a boolean value.",
|
|
1026
|
+
dateTime: (e, t) => yn(t) ? void 0 : "Enter a valid UTC date and time.",
|
|
1027
|
+
select: wn,
|
|
1028
|
+
asset: Nn,
|
|
1029
|
+
reference: Nn
|
|
1030
|
+
};
|
|
1031
|
+
function Fn(e, t) {
|
|
1032
|
+
return t === void 0 ? e.required ? Z(e) : void 0 : Pn[e.type](e, t);
|
|
1033
|
+
}
|
|
1034
|
+
function In(e, t) {
|
|
1035
|
+
return $t(e), Object.fromEntries(e.fields.flatMap((e) => {
|
|
1036
|
+
if (e.type === "divider") return [];
|
|
1037
|
+
let n = Fn(e, Object.hasOwn(t, e.id) ? t[e.id] : void 0);
|
|
1038
|
+
return n ? [[e.id, n]] : [];
|
|
1039
|
+
}));
|
|
1040
|
+
}
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/components/FormEditor/choice-control.tsx
|
|
1043
|
+
function Ln({ field: e, option: t, name: n, checked: r, isDisabled: i, invalid: a, onChange: o }) {
|
|
1044
|
+
let s = {
|
|
1045
|
+
name: n,
|
|
1046
|
+
value: t.value,
|
|
1047
|
+
checked: r,
|
|
1048
|
+
disabled: i || t.isDisabled,
|
|
1049
|
+
"aria-invalid": a,
|
|
1050
|
+
onChange: () => {
|
|
1051
|
+
!i && !t.isDisabled && o();
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
if (e.appearance === "card") {
|
|
1055
|
+
let n = e.type === "radioGroup" ? F : _e;
|
|
1056
|
+
return /* @__PURE__ */ W(n, {
|
|
1057
|
+
...s,
|
|
1058
|
+
title: t.label,
|
|
1059
|
+
description: t.description
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
let c = e.type === "radioGroup" ? se : ae;
|
|
1063
|
+
return /* @__PURE__ */ W(c, {
|
|
1064
|
+
...s,
|
|
1065
|
+
children: /* @__PURE__ */ G("span", { children: [t.label, t.description && /* @__PURE__ */ W("span", {
|
|
1066
|
+
className: "ds-form-editor__option-description",
|
|
1067
|
+
children: t.description
|
|
1068
|
+
})] })
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
function Rn({ field: e, stored: n, isDisabled: r, required: i, accessibility: a, onChange: o }) {
|
|
1072
|
+
let s = e.type === "checkboxGroup", c = s ? Tn(n) : typeof n == "string" && n ? [n] : [], l = e.appearance === "card" ? ve : oe;
|
|
1073
|
+
return /* @__PURE__ */ G(U, { children: [/* @__PURE__ */ W(l, {
|
|
1074
|
+
...a,
|
|
1075
|
+
label: e.label,
|
|
1076
|
+
columns: e.columns ?? (e.appearance === "card" ? 2 : 1),
|
|
1077
|
+
children: e.options.map((t) => /* @__PURE__ */ W(Ln, {
|
|
1078
|
+
field: e,
|
|
1079
|
+
option: t,
|
|
1080
|
+
name: a.id,
|
|
1081
|
+
checked: c.includes(t.value),
|
|
1082
|
+
isDisabled: r,
|
|
1083
|
+
invalid: a["aria-invalid"],
|
|
1084
|
+
onChange: () => {
|
|
1085
|
+
o(s ? c.includes(t.value) ? c.filter((e) => e !== t.value) : [...c, t.value] : t.value);
|
|
1086
|
+
}
|
|
1087
|
+
}, t.value))
|
|
1088
|
+
}), !s && !i && c.length > 0 && /* @__PURE__ */ G(t, {
|
|
1089
|
+
variant: "simple",
|
|
1090
|
+
size: "sm",
|
|
1091
|
+
isDisabled: r,
|
|
1092
|
+
onClick: () => o(void 0),
|
|
1093
|
+
children: ["Clear ", e.label]
|
|
1094
|
+
})] });
|
|
1095
|
+
}
|
|
1096
|
+
//#endregion
|
|
1097
|
+
//#region src/components/FormEditor/additional-control.tsx
|
|
1098
|
+
function zn({ field: e, stored: t, isDisabled: n, accessibility: r, onChange: i }) {
|
|
1099
|
+
let a = M(e), o = kn(t, a);
|
|
1100
|
+
return /* @__PURE__ */ W(N, {
|
|
1101
|
+
...r,
|
|
1102
|
+
...a,
|
|
1103
|
+
prefix: e.prefix,
|
|
1104
|
+
suffix: e.suffix,
|
|
1105
|
+
hasValueLabel: e.hasValueLabel,
|
|
1106
|
+
valueText: o === void 0 ? e.placeholder ?? "Not set" : void 0,
|
|
1107
|
+
autoFocus: e.autoFocus,
|
|
1108
|
+
isDisabled: n,
|
|
1109
|
+
value: o ?? a.min,
|
|
1110
|
+
onValueChange: i,
|
|
1111
|
+
onValueCommit: (e) => {
|
|
1112
|
+
o === void 0 && i(e);
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
function Bn({ field: e, stored: t, isDisabled: n, accessibility: r, onChange: i }) {
|
|
1117
|
+
let a = M(e), o = An(t, a);
|
|
1118
|
+
return /* @__PURE__ */ W(fe, {
|
|
1119
|
+
...r,
|
|
1120
|
+
...a,
|
|
1121
|
+
prefix: e.prefix,
|
|
1122
|
+
suffix: e.suffix,
|
|
1123
|
+
hasValueLabel: e.hasValueLabel,
|
|
1124
|
+
minLabel: `${e.label} minimum`,
|
|
1125
|
+
maxLabel: `${e.label} maximum`,
|
|
1126
|
+
isDisabled: n,
|
|
1127
|
+
valueText: o === void 0 ? e.placeholder ?? "Not set" : void 0,
|
|
1128
|
+
hasFill: o !== void 0,
|
|
1129
|
+
value: o ?? {
|
|
1130
|
+
min: a.min,
|
|
1131
|
+
max: a.max
|
|
1132
|
+
},
|
|
1133
|
+
onValueChange: i,
|
|
1134
|
+
onValueCommit: (e) => {
|
|
1135
|
+
o === void 0 && i(e);
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
function Vn({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
|
|
1140
|
+
let o = {
|
|
1141
|
+
stored: t,
|
|
1142
|
+
isDisabled: n,
|
|
1143
|
+
required: r,
|
|
1144
|
+
accessibility: i,
|
|
1145
|
+
onChange: a
|
|
1146
|
+
};
|
|
1147
|
+
switch (e.type) {
|
|
1148
|
+
case "radioGroup":
|
|
1149
|
+
case "checkboxGroup": return /* @__PURE__ */ W(Rn, {
|
|
1150
|
+
field: e,
|
|
1151
|
+
...o
|
|
1152
|
+
});
|
|
1153
|
+
case "rangeSlider": return /* @__PURE__ */ W(Bn, {
|
|
1154
|
+
field: e,
|
|
1155
|
+
...o
|
|
1156
|
+
});
|
|
1157
|
+
case "slider": return /* @__PURE__ */ W(zn, {
|
|
1158
|
+
field: e,
|
|
1159
|
+
...o
|
|
1160
|
+
});
|
|
1161
|
+
case "colour": return /* @__PURE__ */ W(pe, {
|
|
1162
|
+
...i,
|
|
1163
|
+
required: r,
|
|
1164
|
+
placeholder: e.placeholder,
|
|
1165
|
+
presets: e.presets,
|
|
1166
|
+
showPresets: e.showPresets,
|
|
1167
|
+
picker: e.picker,
|
|
1168
|
+
placement: e.placement,
|
|
1169
|
+
readOnly: e.readOnly,
|
|
1170
|
+
autoFocus: e.autoFocus,
|
|
1171
|
+
isDisabled: n,
|
|
1172
|
+
value: typeof t == "string" ? t : "",
|
|
1173
|
+
onInput: (e) => {
|
|
1174
|
+
let t = e.currentTarget.value;
|
|
1175
|
+
t.trim() && !j(t) && a(t);
|
|
1176
|
+
},
|
|
1177
|
+
onValueChange: (e) => a(e === "" ? void 0 : e)
|
|
1178
|
+
});
|
|
1179
|
+
case "tags": return /* @__PURE__ */ W(ge, {
|
|
1180
|
+
...i,
|
|
1181
|
+
required: r,
|
|
1182
|
+
placeholder: e.placeholder,
|
|
1183
|
+
max: e.max,
|
|
1184
|
+
isDisabled: n,
|
|
1185
|
+
value: Tn(t),
|
|
1186
|
+
onValueChange: a
|
|
1187
|
+
});
|
|
1188
|
+
case "date": return /* @__PURE__ */ W(he, {
|
|
1189
|
+
...i,
|
|
1190
|
+
placeholder: e.placeholder,
|
|
1191
|
+
min: e.min,
|
|
1192
|
+
max: e.max,
|
|
1193
|
+
placement: e.placement,
|
|
1194
|
+
isDisabled: n,
|
|
1195
|
+
isClearable: !0,
|
|
1196
|
+
clearLabel: `Clear ${e.label}`,
|
|
1197
|
+
value: typeof t == "string" ? t : "",
|
|
1198
|
+
onValueChange: (e) => a(e === "" ? void 0 : e)
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
//#endregion
|
|
1203
|
+
//#region src/components/FormEditor/control.tsx
|
|
1204
|
+
function Hn(e, t) {
|
|
1205
|
+
if (e.type === "asset") {
|
|
1206
|
+
let n = t.map((e) => ({ assetId: e }));
|
|
1207
|
+
return e.multiple ? n : n[0];
|
|
1208
|
+
}
|
|
1209
|
+
let n = t.map((e) => ({ entryId: e }));
|
|
1210
|
+
return e.multiple ? n : n[0];
|
|
1211
|
+
}
|
|
1212
|
+
var Un = be(null);
|
|
1213
|
+
function Wn({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
|
|
1214
|
+
return /* @__PURE__ */ W(le, {
|
|
1215
|
+
...i,
|
|
1216
|
+
required: r,
|
|
1217
|
+
isDisabled: n,
|
|
1218
|
+
placeholder: e.placeholder,
|
|
1219
|
+
min: e.min,
|
|
1220
|
+
max: e.max,
|
|
1221
|
+
step: e.step ?? "any",
|
|
1222
|
+
hasSteppers: e.hasSteppers,
|
|
1223
|
+
prefix: e.prefix,
|
|
1224
|
+
suffix: e.suffix,
|
|
1225
|
+
autoFocus: e.autoFocus,
|
|
1226
|
+
decreaseLabel: e.decreaseLabel ?? `Decrease ${e.label}`,
|
|
1227
|
+
increaseLabel: e.increaseLabel ?? `Increase ${e.label}`,
|
|
1228
|
+
value: typeof t == "number" && Number.isFinite(t) ? t : "",
|
|
1229
|
+
onValueChange: (e) => {
|
|
1230
|
+
(e === "" || Number.isFinite(e)) && a(e === "" ? void 0 : e);
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
function Gn({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
|
|
1235
|
+
let o = !r && !e.options.some((e) => e.value === "");
|
|
1236
|
+
return /* @__PURE__ */ W(ue, {
|
|
1237
|
+
...i,
|
|
1238
|
+
"aria-required": r || void 0,
|
|
1239
|
+
isDisabled: n,
|
|
1240
|
+
isInvalid: i["aria-invalid"],
|
|
1241
|
+
options: o ? [{
|
|
1242
|
+
value: "",
|
|
1243
|
+
label: e.placeholder ?? "None"
|
|
1244
|
+
}, ...e.options] : e.options,
|
|
1245
|
+
placeholder: e.placeholder,
|
|
1246
|
+
autoFocus: e.autoFocus,
|
|
1247
|
+
value: typeof t == "string" ? t : "",
|
|
1248
|
+
onValueChange: (e) => a(e === "" ? void 0 : e)
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
function Kn({ field: e, selected: t, items: n, source: r, isDisabled: i, accessibility: a, onChange: o }) {
|
|
1252
|
+
return /* @__PURE__ */ W(A, {
|
|
1253
|
+
...a,
|
|
1254
|
+
...r,
|
|
1255
|
+
items: n,
|
|
1256
|
+
value: t,
|
|
1257
|
+
..._n(e),
|
|
1258
|
+
...un(e, r),
|
|
1259
|
+
isDisabled: i,
|
|
1260
|
+
onValueChange: (t) => o(Hn(e, t))
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
function qn({ blockPlugins: e, field: t, stored: n, selected: r, items: i, source: a, isDisabled: o, accessibility: { required: s, ...c }, onChange: l }) {
|
|
1264
|
+
let u = L(Un), d = {
|
|
1265
|
+
stored: n,
|
|
1266
|
+
isDisabled: o,
|
|
1267
|
+
required: s,
|
|
1268
|
+
accessibility: c,
|
|
1269
|
+
onChange: l
|
|
1270
|
+
};
|
|
1271
|
+
switch (t.type) {
|
|
1272
|
+
case "shortText": return /* @__PURE__ */ W(_, {
|
|
1273
|
+
...c,
|
|
1274
|
+
required: s,
|
|
1275
|
+
disabled: o,
|
|
1276
|
+
placeholder: t.placeholder,
|
|
1277
|
+
type: t.inputType,
|
|
1278
|
+
maxLength: t.maxLength,
|
|
1279
|
+
readOnly: t.readOnly,
|
|
1280
|
+
autoFocus: t.autoFocus,
|
|
1281
|
+
value: ln(n),
|
|
1282
|
+
onChange: (e) => l(e.target.value)
|
|
1283
|
+
});
|
|
1284
|
+
case "longText": return /* @__PURE__ */ W(g, {
|
|
1285
|
+
...c,
|
|
1286
|
+
required: s,
|
|
1287
|
+
disabled: o,
|
|
1288
|
+
placeholder: t.placeholder,
|
|
1289
|
+
rows: t.rows,
|
|
1290
|
+
maxLength: t.maxLength,
|
|
1291
|
+
readOnly: t.readOnly,
|
|
1292
|
+
autoFocus: t.autoFocus,
|
|
1293
|
+
value: ln(n),
|
|
1294
|
+
onChange: (e) => l(e.target.value)
|
|
1295
|
+
});
|
|
1296
|
+
case "number": return /* @__PURE__ */ W(Wn, {
|
|
1297
|
+
field: t,
|
|
1298
|
+
...d
|
|
1299
|
+
});
|
|
1300
|
+
case "boolean": return /* @__PURE__ */ W(de, {
|
|
1301
|
+
...c,
|
|
1302
|
+
isDisabled: o,
|
|
1303
|
+
autoFocus: t.autoFocus,
|
|
1304
|
+
isSelected: n === !0,
|
|
1305
|
+
onSelectedChange: l
|
|
1306
|
+
});
|
|
1307
|
+
case "dateTime": return /* @__PURE__ */ W(_, {
|
|
1308
|
+
...c,
|
|
1309
|
+
required: s,
|
|
1310
|
+
disabled: o,
|
|
1311
|
+
type: "datetime-local",
|
|
1312
|
+
step: "0.001",
|
|
1313
|
+
autoFocus: t.autoFocus,
|
|
1314
|
+
value: yn(n)?.slice(0, -1) ?? "",
|
|
1315
|
+
onChange: (e) => l(yn(`${e.target.value}Z`))
|
|
1316
|
+
});
|
|
1317
|
+
case "richText":
|
|
1318
|
+
if (!u) throw Error(`Rich text field ${t.id} needs FormEditor's rich-text control.`);
|
|
1319
|
+
return u({
|
|
1320
|
+
field: t,
|
|
1321
|
+
blockPlugins: e,
|
|
1322
|
+
...d
|
|
1323
|
+
});
|
|
1324
|
+
case "select": return /* @__PURE__ */ W(Gn, {
|
|
1325
|
+
field: t,
|
|
1326
|
+
...d
|
|
1327
|
+
});
|
|
1328
|
+
case "asset":
|
|
1329
|
+
case "reference": return /* @__PURE__ */ W(Kn, {
|
|
1330
|
+
field: t,
|
|
1331
|
+
items: i,
|
|
1332
|
+
source: a,
|
|
1333
|
+
selected: r ?? [],
|
|
1334
|
+
...d
|
|
1335
|
+
});
|
|
1336
|
+
default: return /* @__PURE__ */ W(Vn, {
|
|
1337
|
+
field: t,
|
|
1338
|
+
...d
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
//#endregion
|
|
1343
|
+
//#region src/components/FormEditor/form.tsx
|
|
1344
|
+
function Jn({ field: e, stored: t, items: n, source: r, blockPlugins: i, isDisabled: a, error: o, isErrorVisible: s, onChange: c }) {
|
|
1345
|
+
let l = B(() => o === void 0 && s ? Fn(e, t) : void 0, [
|
|
1346
|
+
o,
|
|
1347
|
+
s,
|
|
1348
|
+
e,
|
|
1349
|
+
t
|
|
1350
|
+
]), u = B(() => e.type === "asset" || e.type === "reference" ? vn(e, t) : void 0, [e, t]);
|
|
1351
|
+
return /* @__PURE__ */ W(E, {
|
|
1352
|
+
width: e.width,
|
|
1353
|
+
padded: !1,
|
|
1354
|
+
center: !1,
|
|
1355
|
+
className: "ds-form-editor__field",
|
|
1356
|
+
children: /* @__PURE__ */ W(m, {
|
|
1357
|
+
...on(e, t, u, r),
|
|
1358
|
+
label: e.type === "dateTime" ? `${e.label} (UTC)` : gn(e),
|
|
1359
|
+
hint: e.hint,
|
|
1360
|
+
error: o ?? l,
|
|
1361
|
+
isRequired: e.required,
|
|
1362
|
+
count: cn(e, t, u, r),
|
|
1363
|
+
isGroup: u !== void 0 || Yn.has(e.type),
|
|
1364
|
+
children: (o) => /* @__PURE__ */ W(qn, {
|
|
1365
|
+
field: e,
|
|
1366
|
+
stored: t,
|
|
1367
|
+
selected: u,
|
|
1368
|
+
items: n,
|
|
1369
|
+
source: r,
|
|
1370
|
+
blockPlugins: i,
|
|
1371
|
+
isDisabled: a,
|
|
1372
|
+
accessibility: o,
|
|
1373
|
+
onChange: c
|
|
1374
|
+
})
|
|
1375
|
+
})
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
var Yn = /* @__PURE__ */ new Set([
|
|
1379
|
+
"radioGroup",
|
|
1380
|
+
"checkboxGroup",
|
|
1381
|
+
"rangeSlider"
|
|
1382
|
+
]), Xn = /* @__PURE__ */ new Set([
|
|
1383
|
+
"slider",
|
|
1384
|
+
"rangeSlider",
|
|
1385
|
+
"date",
|
|
1386
|
+
"colour"
|
|
1387
|
+
]);
|
|
1388
|
+
function Zn({ schema: e, value: t, defaultValue: n = {}, onValueChange: r, pickerItems: i = {}, pickerSources: a = {}, blockPlugins: o = {}, errors: s = {}, isDisabled: c = !1, showAllErrors: l = !1, columns: u = 1, minColumnWidth: d = "16rem", className: f, style: p, ...m }) {
|
|
1389
|
+
let [h, g] = H(n), [_, v] = H(() => /* @__PURE__ */ new Set()), y = t ?? h;
|
|
1390
|
+
B(() => $t(e), [e]);
|
|
1391
|
+
let b = (e, n) => {
|
|
1392
|
+
let i = { ...y };
|
|
1393
|
+
n === void 0 ? delete i[e] : i[e] = n, t === void 0 && g(i), v((t) => new Set(t).add(e)), r?.(i, { fieldId: e });
|
|
1394
|
+
}, x = u === "auto" ? { "--form-editor-min-column": d } : {
|
|
1395
|
+
"--form-editor-columns": u,
|
|
1396
|
+
"--form-editor-min-column": d
|
|
1397
|
+
};
|
|
1398
|
+
return /* @__PURE__ */ W("div", {
|
|
1399
|
+
className: [
|
|
1400
|
+
"ds-form-editor",
|
|
1401
|
+
u === "auto" && "ds-form-editor--auto",
|
|
1402
|
+
f
|
|
1403
|
+
].filter(Boolean).join(" "),
|
|
1404
|
+
style: {
|
|
1405
|
+
...x,
|
|
1406
|
+
...p
|
|
1407
|
+
},
|
|
1408
|
+
...m,
|
|
1409
|
+
children: e.fields.map((e) => {
|
|
1410
|
+
if (e.type === "divider") return /* @__PURE__ */ W("hr", { className: "ds-form-editor__divider" }, e.id);
|
|
1411
|
+
let t = Object.hasOwn(y, e.id) ? y[e.id] : void 0, n = c || !!e.isDisabled, r = n || "readOnly" in e && !!e.readOnly, u = typeof t == "string" ? t.trim() !== "" : t !== void 0, d = l || _.has(e.id) || u && Xn.has(e.type) || e.type === "number" && typeof t == "number";
|
|
1412
|
+
return /* @__PURE__ */ W(Jn, {
|
|
1413
|
+
field: e,
|
|
1414
|
+
stored: t,
|
|
1415
|
+
items: i[e.id] ?? [],
|
|
1416
|
+
source: a[e.id],
|
|
1417
|
+
blockPlugins: o[e.id],
|
|
1418
|
+
isDisabled: n,
|
|
1419
|
+
error: s[e.id],
|
|
1420
|
+
isErrorVisible: d,
|
|
1421
|
+
onChange: (t) => {
|
|
1422
|
+
(!r || e.type === "richText" && o[e.id]?.some((e) => e.isCreating)) && b(e.id, t);
|
|
1423
|
+
}
|
|
1424
|
+
}, e.id);
|
|
1425
|
+
})
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
//#endregion
|
|
1429
|
+
//#region src/components/RichTextEditor/tables.tsx
|
|
1430
|
+
var Qn = 50, $n = { fields: [
|
|
1431
|
+
{
|
|
1432
|
+
id: "rows",
|
|
1433
|
+
type: "number",
|
|
1434
|
+
label: "Rows",
|
|
1435
|
+
required: !0,
|
|
1436
|
+
min: 1,
|
|
1437
|
+
max: Qn,
|
|
1438
|
+
step: 1,
|
|
1439
|
+
decreaseLabel: "Fewer rows",
|
|
1440
|
+
increaseLabel: "More rows"
|
|
1441
|
+
},
|
|
1442
|
+
{
|
|
1443
|
+
id: "cols",
|
|
1444
|
+
type: "number",
|
|
1445
|
+
label: "Columns",
|
|
1446
|
+
required: !0,
|
|
1447
|
+
min: 1,
|
|
1448
|
+
max: Qn,
|
|
1449
|
+
step: 1,
|
|
1450
|
+
decreaseLabel: "Fewer columns",
|
|
1451
|
+
increaseLabel: "More columns"
|
|
1452
|
+
},
|
|
1453
|
+
{
|
|
1454
|
+
id: "withHeaderRow",
|
|
1455
|
+
type: "boolean",
|
|
1456
|
+
label: "Include header row"
|
|
1457
|
+
}
|
|
1458
|
+
] }, er = {
|
|
1459
|
+
rows: 3,
|
|
1460
|
+
cols: 3
|
|
1461
|
+
}, tr = {
|
|
1462
|
+
...er,
|
|
1463
|
+
withHeaderRow: !0
|
|
1464
|
+
}, nr = "Enter a whole number.";
|
|
1465
|
+
function rr(e) {
|
|
1466
|
+
return typeof e == "number" && Number.isInteger(e) && e >= 1 && e <= Qn ? e : void 0;
|
|
1467
|
+
}
|
|
1468
|
+
function ir(e) {
|
|
1469
|
+
return typeof e == "number" && !Number.isInteger(e) ? nr : void 0;
|
|
1470
|
+
}
|
|
1471
|
+
function ar(e, t, { rows: n, cols: r, withHeaderRow: i }) {
|
|
1472
|
+
e.chain().focus().command(({ tr: a, dispatch: o }) => {
|
|
1473
|
+
let s = t.getBookmark().resolve(a.doc), c = Ke(e.schema, n, r, i), l = s instanceof K ? s.node.isInline ? s.$to.after() : s.to : null;
|
|
1474
|
+
if (l !== null) {
|
|
1475
|
+
let e = a.doc.resolve(l);
|
|
1476
|
+
if (!e.parent.canReplaceWith(e.index(), e.index(), c.type)) return !1;
|
|
1477
|
+
}
|
|
1478
|
+
if (o) {
|
|
1479
|
+
q(a);
|
|
1480
|
+
let e;
|
|
1481
|
+
l === null ? (e = s.from + 1, a.setSelection(s).replaceSelectionWith(c)) : (e = l + 1, a.insert(l, c)), a.setSelection(Be.near(a.doc.resolve(e))).scrollIntoView();
|
|
1482
|
+
}
|
|
1483
|
+
return !0;
|
|
1484
|
+
}).run() && !e.isDestroyed && (e.view.dispatch(q(e.state.tr)), e.view.focus());
|
|
1485
|
+
}
|
|
1486
|
+
function or({ editor: e, selection: n, withHeaderRow: r, onClose: i }) {
|
|
1487
|
+
let a = z(), [o, s] = H(() => ({
|
|
1488
|
+
...tr,
|
|
1489
|
+
withHeaderRow: r
|
|
1490
|
+
})), [c, l] = H(!1), u = rr(o.rows), d = rr(o.cols);
|
|
1491
|
+
return /* @__PURE__ */ W(h, {
|
|
1492
|
+
isOpen: !0,
|
|
1493
|
+
title: "Insert table",
|
|
1494
|
+
size: "dialog",
|
|
1495
|
+
onClose: i,
|
|
1496
|
+
footer: /* @__PURE__ */ G(U, { children: [/* @__PURE__ */ W(t, {
|
|
1497
|
+
onClick: i,
|
|
1498
|
+
children: "Cancel"
|
|
1499
|
+
}), /* @__PURE__ */ W(t, {
|
|
1500
|
+
variant: "primary",
|
|
1501
|
+
type: "submit",
|
|
1502
|
+
form: a,
|
|
1503
|
+
children: "Insert table"
|
|
1504
|
+
})] }),
|
|
1505
|
+
children: /* @__PURE__ */ W("form", {
|
|
1506
|
+
id: a,
|
|
1507
|
+
noValidate: !0,
|
|
1508
|
+
onSubmit: (t) => {
|
|
1509
|
+
t.preventDefault(), t.stopPropagation(), l(!0), u !== void 0 && d !== void 0 && (!e.isDestroyed && e.isEditable && e.state.doc.eq(n.$from.doc) && ar(e, n, {
|
|
1510
|
+
rows: u,
|
|
1511
|
+
cols: d,
|
|
1512
|
+
withHeaderRow: o.withHeaderRow === !0
|
|
1513
|
+
}), i());
|
|
1514
|
+
},
|
|
1515
|
+
children: /* @__PURE__ */ W(Zn, {
|
|
1516
|
+
schema: $n,
|
|
1517
|
+
value: o,
|
|
1518
|
+
onValueChange: s,
|
|
1519
|
+
errors: {
|
|
1520
|
+
rows: ir(o.rows),
|
|
1521
|
+
cols: ir(o.cols)
|
|
1522
|
+
},
|
|
1523
|
+
showAllErrors: c,
|
|
1524
|
+
columns: 2,
|
|
1525
|
+
minColumnWidth: "8rem"
|
|
1526
|
+
})
|
|
1527
|
+
})
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
var sr = 6, cr = 8, lr = Array.from({ length: sr }, (e, t) => t + 1), ur = Array.from({ length: cr }, (e, t) => t + 1);
|
|
1531
|
+
function dr({ editor: e, selection: t }) {
|
|
1532
|
+
return !e.isDestroyed && e.isEditable && e.state.doc.eq(t.$from.doc);
|
|
1533
|
+
}
|
|
1534
|
+
function fr({ editor: e, disabled: n, inTable: r }) {
|
|
1535
|
+
let [a, o] = H(null), [c, l] = H(!0), [u, f] = H(er), [p, m] = H(er), [h, g] = H(!1), _ = V(null), v = V(null), y = V(null), b = V(null), S = z(), C = I(() => o(null), []), E = n || !e || r, D = !E && a?.editor === e ? a : null, O = s(D?.mode === "grid");
|
|
1536
|
+
return a && !D && o(null), R(() => {
|
|
1537
|
+
if (!D) return;
|
|
1538
|
+
let e = D.editor, t = () => {
|
|
1539
|
+
dr(D) || C();
|
|
1540
|
+
};
|
|
1541
|
+
return e.on("transaction", t), t(), () => {
|
|
1542
|
+
e.off("transaction", t);
|
|
1543
|
+
};
|
|
1544
|
+
}, [D, C]), d(() => {
|
|
1545
|
+
O && y.current?.querySelector("button[tabindex='0']")?.focus();
|
|
1546
|
+
}, [O]), R(() => {
|
|
1547
|
+
if (!O) return;
|
|
1548
|
+
let e = (e) => {
|
|
1549
|
+
let t = e.target;
|
|
1550
|
+
!v.current?.contains(t) && !y.current?.contains(t) && C();
|
|
1551
|
+
}, t = (e) => {
|
|
1552
|
+
e.key === "Escape" && !e.defaultPrevented && !e.isComposing && (e.preventDefault(), C(), _.current?.focus());
|
|
1553
|
+
};
|
|
1554
|
+
return document.addEventListener("mousedown", e), document.addEventListener("keydown", t), () => {
|
|
1555
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
|
|
1556
|
+
};
|
|
1557
|
+
}, [O, C]), /* @__PURE__ */ G("span", {
|
|
1558
|
+
ref: v,
|
|
1559
|
+
children: [
|
|
1560
|
+
/* @__PURE__ */ W(t, {
|
|
1561
|
+
ref: _,
|
|
1562
|
+
size: "sm",
|
|
1563
|
+
isIconOnly: !0,
|
|
1564
|
+
iconStart: "table",
|
|
1565
|
+
variant: O ? "active" : "neutral",
|
|
1566
|
+
"aria-label": "Insert table",
|
|
1567
|
+
title: "Insert table",
|
|
1568
|
+
"aria-haspopup": "dialog",
|
|
1569
|
+
"aria-expanded": O,
|
|
1570
|
+
"aria-controls": O ? S : void 0,
|
|
1571
|
+
isDisabled: E,
|
|
1572
|
+
onClick: (t) => {
|
|
1573
|
+
O ? C() : e && (g(getComputedStyle(t.currentTarget).direction === "rtl"), f(er), m(er), l(!0), o({
|
|
1574
|
+
editor: e,
|
|
1575
|
+
selection: e.state.selection,
|
|
1576
|
+
mode: "grid"
|
|
1577
|
+
}));
|
|
1578
|
+
}
|
|
1579
|
+
}),
|
|
1580
|
+
/* @__PURE__ */ W(x, {
|
|
1581
|
+
anchorRef: _,
|
|
1582
|
+
panelRef: y,
|
|
1583
|
+
id: S,
|
|
1584
|
+
isOpen: O,
|
|
1585
|
+
placement: "bottom",
|
|
1586
|
+
align: h ? "end" : "start",
|
|
1587
|
+
role: "dialog",
|
|
1588
|
+
"aria-label": "Insert table",
|
|
1589
|
+
tabIndex: -1,
|
|
1590
|
+
className: "ds-rte__table-picker ds-surface-raised ds-field-surface",
|
|
1591
|
+
children: /* @__PURE__ */ G("div", {
|
|
1592
|
+
className: "ds-rte__table-picker-content",
|
|
1593
|
+
onKeyDown: (e) => {
|
|
1594
|
+
if (e.key !== "Tab") return;
|
|
1595
|
+
let t = e.target.hasAttribute("data-cell");
|
|
1596
|
+
e.shiftKey && t ? (e.preventDefault(), C(), _.current?.focus()) : !e.shiftKey && e.target === b.current && v.current && (e.preventDefault(), C(), i(v.current));
|
|
1597
|
+
},
|
|
1598
|
+
children: [
|
|
1599
|
+
/* @__PURE__ */ G("div", {
|
|
1600
|
+
className: "ds-rte__table-picker-heading",
|
|
1601
|
+
children: [/* @__PURE__ */ W(w, { children: "Insert table" }), /* @__PURE__ */ W("bdi", {
|
|
1602
|
+
dir: "ltr",
|
|
1603
|
+
children: `${p.rows} × ${p.cols}`
|
|
1604
|
+
})]
|
|
1605
|
+
}),
|
|
1606
|
+
/* @__PURE__ */ W("div", {
|
|
1607
|
+
className: "ds-rte__table-picker-grid",
|
|
1608
|
+
role: "grid",
|
|
1609
|
+
"aria-label": "Table size",
|
|
1610
|
+
onKeyDown: (e) => {
|
|
1611
|
+
let { rows: t, cols: n } = u, r = {
|
|
1612
|
+
ArrowDown: {
|
|
1613
|
+
rows: t + 1,
|
|
1614
|
+
cols: n
|
|
1615
|
+
},
|
|
1616
|
+
ArrowUp: {
|
|
1617
|
+
rows: t - 1,
|
|
1618
|
+
cols: n
|
|
1619
|
+
},
|
|
1620
|
+
ArrowLeft: {
|
|
1621
|
+
rows: t,
|
|
1622
|
+
cols: n + (h ? 1 : -1)
|
|
1623
|
+
},
|
|
1624
|
+
ArrowRight: {
|
|
1625
|
+
rows: t,
|
|
1626
|
+
cols: n + (h ? -1 : 1)
|
|
1627
|
+
},
|
|
1628
|
+
Home: {
|
|
1629
|
+
rows: t,
|
|
1630
|
+
cols: 1
|
|
1631
|
+
},
|
|
1632
|
+
End: {
|
|
1633
|
+
rows: t,
|
|
1634
|
+
cols: cr
|
|
1635
|
+
}
|
|
1636
|
+
}[e.key];
|
|
1637
|
+
if (r) {
|
|
1638
|
+
e.preventDefault();
|
|
1639
|
+
let t = Math.max(1, Math.min(sr, r.rows)), n = Math.max(1, Math.min(cr, r.cols));
|
|
1640
|
+
e.currentTarget.querySelector(`[data-cell="${t}:${n}"]`)?.focus();
|
|
1641
|
+
}
|
|
1642
|
+
},
|
|
1643
|
+
onMouseLeave: () => m(u),
|
|
1644
|
+
children: lr.map((e) => /* @__PURE__ */ W("div", {
|
|
1645
|
+
role: "row",
|
|
1646
|
+
className: "ds-rte__table-picker-row",
|
|
1647
|
+
children: ur.map((n) => {
|
|
1648
|
+
let r = e <= p.rows && n <= p.cols;
|
|
1649
|
+
return /* @__PURE__ */ W("div", {
|
|
1650
|
+
role: "gridcell",
|
|
1651
|
+
children: /* @__PURE__ */ W(t, {
|
|
1652
|
+
size: "xs",
|
|
1653
|
+
isIconOnly: !0,
|
|
1654
|
+
tabIndex: e === u.rows && n === u.cols ? 0 : -1,
|
|
1655
|
+
"aria-label": `${e} ${e === 1 ? "row" : "rows"} by ${n} ${n === 1 ? "column" : "columns"}`,
|
|
1656
|
+
"data-cell": `${e}:${n}`,
|
|
1657
|
+
variant: r ? e === 1 && c ? "primary" : "active" : "neutral",
|
|
1658
|
+
onMouseEnter: (t) => {
|
|
1659
|
+
let r = t.currentTarget;
|
|
1660
|
+
r.parentElement?.closest("[role='grid']")?.contains(r.ownerDocument.activeElement) ? r.focus() : m({
|
|
1661
|
+
rows: e,
|
|
1662
|
+
cols: n
|
|
1663
|
+
});
|
|
1664
|
+
},
|
|
1665
|
+
onFocus: () => {
|
|
1666
|
+
let t = {
|
|
1667
|
+
rows: e,
|
|
1668
|
+
cols: n
|
|
1669
|
+
};
|
|
1670
|
+
f(t), m(t);
|
|
1671
|
+
},
|
|
1672
|
+
onClick: () => {
|
|
1673
|
+
D && dr(D) && ar(D.editor, D.selection, {
|
|
1674
|
+
rows: e,
|
|
1675
|
+
cols: n,
|
|
1676
|
+
withHeaderRow: c
|
|
1677
|
+
}), C();
|
|
1678
|
+
}
|
|
1679
|
+
})
|
|
1680
|
+
}, n);
|
|
1681
|
+
})
|
|
1682
|
+
}, e))
|
|
1683
|
+
}),
|
|
1684
|
+
/* @__PURE__ */ W(de, {
|
|
1685
|
+
isSelected: c,
|
|
1686
|
+
onSelectedChange: l,
|
|
1687
|
+
children: "Include header row"
|
|
1688
|
+
}),
|
|
1689
|
+
/* @__PURE__ */ W(T, {}),
|
|
1690
|
+
/* @__PURE__ */ G(t, {
|
|
1691
|
+
ref: b,
|
|
1692
|
+
size: "sm",
|
|
1693
|
+
variant: "simple",
|
|
1694
|
+
className: "ds-rte__table-picker-custom",
|
|
1695
|
+
onClick: () => {
|
|
1696
|
+
D && (_.current?.focus(), o({
|
|
1697
|
+
...D,
|
|
1698
|
+
mode: "custom"
|
|
1699
|
+
}));
|
|
1700
|
+
},
|
|
1701
|
+
children: ["Custom size…", /* @__PURE__ */ W("span", { children: "up to 50 × 50" })]
|
|
1702
|
+
})
|
|
1703
|
+
]
|
|
1704
|
+
})
|
|
1705
|
+
}),
|
|
1706
|
+
D?.mode === "custom" && /* @__PURE__ */ W(or, {
|
|
1707
|
+
editor: D.editor,
|
|
1708
|
+
selection: D.selection,
|
|
1709
|
+
withHeaderRow: c,
|
|
1710
|
+
onClose: C
|
|
1711
|
+
})
|
|
1712
|
+
]
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
//#endregion
|
|
1716
|
+
//#region src/components/RichTextEditor/table-bands.ts
|
|
1717
|
+
function pr(e, t) {
|
|
1718
|
+
return t === "row" ? e.height : e.width;
|
|
1719
|
+
}
|
|
1720
|
+
function mr(e, t) {
|
|
1721
|
+
let { map: n, table: r } = e;
|
|
1722
|
+
for (let e = 0; e < n.height; e += 1) for (let i = 0; i < n.width; i += 1) {
|
|
1723
|
+
let a = e * n.width + i, o = n.map[a];
|
|
1724
|
+
if (i > 0 && o === n.map[a - 1] || e > 0 && o === n.map[a - n.width]) continue;
|
|
1725
|
+
let s = r.nodeAt(o);
|
|
1726
|
+
s && t(s, e, i);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
function hr(e, t) {
|
|
1730
|
+
let n = /* @__PURE__ */ new Set();
|
|
1731
|
+
mr(e, (e, r, i) => {
|
|
1732
|
+
let a = t === "row" ? r : i, o = Number(t === "row" ? e.attrs.rowspan : e.attrs.colspan);
|
|
1733
|
+
for (let e = a + 1; e < a + o; e += 1) n.add(e);
|
|
1734
|
+
});
|
|
1735
|
+
let r = [], i = pr(e.map, t), a = 0;
|
|
1736
|
+
for (let e = 1; e <= i; e += 1) n.has(e) || (r.push({
|
|
1737
|
+
start: a,
|
|
1738
|
+
end: e
|
|
1739
|
+
}), a = e);
|
|
1740
|
+
return r;
|
|
1741
|
+
}
|
|
1742
|
+
function gr(e, t, n) {
|
|
1743
|
+
return (n < t.start || n > t.end) && (n === 0 || e.some(({ end: e }) => e === n));
|
|
1744
|
+
}
|
|
1745
|
+
function _r(e, t, n, r) {
|
|
1746
|
+
let { pos: i, map: a } = t, { start: o, end: s } = r, c = n === "row" ? o * a.width : o, l = n === "row" ? s * a.width - 1 : (a.height - 1) * a.width + s - 1, u = e.resolve(i + 1 + a.map[c]), d = e.resolve(i + 1 + a.map[l]);
|
|
1747
|
+
return n === "row" ? J.rowSelection(u, d) : J.colSelection(u, d);
|
|
1748
|
+
}
|
|
1749
|
+
function vr(e, t, n, r) {
|
|
1750
|
+
let { map: i, table: a } = e, o = hr(e, t), s = o.find(({ start: e, end: t }) => n >= e && n < t);
|
|
1751
|
+
if (!s || !gr(o, s, r)) return null;
|
|
1752
|
+
let c = Array.from({ length: pr(i, t) }, (e, t) => t), l = c.splice(s.start, s.end - s.start), u = r > s.end ? r - l.length : r;
|
|
1753
|
+
c.splice(u, 0, ...l);
|
|
1754
|
+
let d = c.map(() => 0);
|
|
1755
|
+
c.forEach((e, t) => {
|
|
1756
|
+
d[e] = t;
|
|
1757
|
+
});
|
|
1758
|
+
let f = Array.from({ length: i.height }, () => /* @__PURE__ */ new Map());
|
|
1759
|
+
return mr(e, (e, n, r) => {
|
|
1760
|
+
let o = t === "row" ? d[n] : n, s = t === "column" ? d[r] : r, c = a.nodeAt(i.map[o * i.width + s])?.type ?? e.type;
|
|
1761
|
+
f[o].set(s, c === e.type ? e : c.createChecked(e.attrs, e.content, e.marks));
|
|
1762
|
+
}), {
|
|
1763
|
+
table: a.copy(qe.fromArray(f.map((e, n) => a.child(t === "row" ? c[n] : n).copy(qe.fromArray([...e.entries()].sort(([e], [t]) => e - t).map(([, e]) => e)))))),
|
|
1764
|
+
index: d[n]
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
//#endregion
|
|
1768
|
+
//#region src/components/RichTextEditor/table-actions.ts
|
|
1769
|
+
var yr = [
|
|
1770
|
+
{
|
|
1771
|
+
align: "left",
|
|
1772
|
+
icon: "align-left",
|
|
1773
|
+
label: "Align left"
|
|
1774
|
+
},
|
|
1775
|
+
{
|
|
1776
|
+
align: "center",
|
|
1777
|
+
icon: "align-center",
|
|
1778
|
+
label: "Align centre"
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
align: "right",
|
|
1782
|
+
icon: "align-right",
|
|
1783
|
+
label: "Align right"
|
|
1784
|
+
}
|
|
1785
|
+
];
|
|
1786
|
+
function Q(e, t) {
|
|
1787
|
+
e.view.dispatch(t.scrollIntoView()), e.view.focus();
|
|
1788
|
+
}
|
|
1789
|
+
function br({ map: e, table: t, pos: n }) {
|
|
1790
|
+
return {
|
|
1791
|
+
map: e,
|
|
1792
|
+
table: t,
|
|
1793
|
+
tableStart: n + 1,
|
|
1794
|
+
top: 0,
|
|
1795
|
+
left: 0,
|
|
1796
|
+
bottom: e.height,
|
|
1797
|
+
right: e.width
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
function xr({ map: e, table: t }, n, r) {
|
|
1801
|
+
return n !== "row" || r !== 0 || !it(e, t, 0);
|
|
1802
|
+
}
|
|
1803
|
+
function Sr(e, t, n, r) {
|
|
1804
|
+
if (!e.isEditable || e.state.doc.nodeAt(t.pos) !== t.table || !xr(t, n, r)) return;
|
|
1805
|
+
let { pos: i } = t, a = (n === "row" ? Ze : Xe)(q(e.state.tr), br(t), r), o = a.doc.nodeAt(i), s = {
|
|
1806
|
+
table: o,
|
|
1807
|
+
pos: i,
|
|
1808
|
+
map: Ye.get(o)
|
|
1809
|
+
};
|
|
1810
|
+
Q(e, a.setSelection(_r(a.doc, s, n, {
|
|
1811
|
+
start: r,
|
|
1812
|
+
end: r + 1
|
|
1813
|
+
})));
|
|
1814
|
+
}
|
|
1815
|
+
function Cr(e, t, n, r, i) {
|
|
1816
|
+
if (!e.isEditable || e.state.doc.nodeAt(t.pos) !== t.table) return !1;
|
|
1817
|
+
let a = vr(t, n, n === "row" ? r.top : r.left, i);
|
|
1818
|
+
if (!a) return !1;
|
|
1819
|
+
let { pos: o, table: s } = t, c = q(e.state.tr).replaceWith(o, o + s.nodeSize, a.table), l = Ye.get(a.table), u = n === "row" ? a.index : r.top, d = n === "column" ? a.index : r.left, f = l.map[u * l.width + d];
|
|
1820
|
+
return Q(e, c.setSelection(new J(c.doc.resolve(o + 1 + f)))), !0;
|
|
1821
|
+
}
|
|
1822
|
+
var wr = {
|
|
1823
|
+
row: {
|
|
1824
|
+
group: "Row",
|
|
1825
|
+
insertBefore: {
|
|
1826
|
+
label: "Add row above",
|
|
1827
|
+
icon: "rows-2-plus-top"
|
|
1828
|
+
},
|
|
1829
|
+
insertAfter: {
|
|
1830
|
+
label: "Add row below",
|
|
1831
|
+
icon: "rows-2-plus-bottom"
|
|
1832
|
+
},
|
|
1833
|
+
remove: {
|
|
1834
|
+
label: "Delete row",
|
|
1835
|
+
icon: "table-rows-split"
|
|
1836
|
+
}
|
|
1837
|
+
},
|
|
1838
|
+
column: {
|
|
1839
|
+
group: "Column",
|
|
1840
|
+
insertBefore: {
|
|
1841
|
+
label: "Add column before",
|
|
1842
|
+
icon: "columns-2-plus-left",
|
|
1843
|
+
inlineIcon: !0
|
|
1844
|
+
},
|
|
1845
|
+
insertAfter: {
|
|
1846
|
+
label: "Add column after",
|
|
1847
|
+
icon: "columns-2-plus-right",
|
|
1848
|
+
inlineIcon: !0
|
|
1849
|
+
},
|
|
1850
|
+
remove: {
|
|
1851
|
+
label: "Delete column",
|
|
1852
|
+
icon: "table-columns-split"
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
function Tr(e, t, n, r) {
|
|
1857
|
+
let i = { boundary: n?.start }, a = { boundary: r?.end };
|
|
1858
|
+
if (e === "row") return [{
|
|
1859
|
+
label: "Move row up",
|
|
1860
|
+
icon: "arrow-up",
|
|
1861
|
+
...i
|
|
1862
|
+
}, {
|
|
1863
|
+
label: "Move row down",
|
|
1864
|
+
icon: "arrow-down",
|
|
1865
|
+
...a
|
|
1866
|
+
}];
|
|
1867
|
+
let [o, s] = t ? [a, i] : [i, a];
|
|
1868
|
+
return [{
|
|
1869
|
+
label: "Move column left",
|
|
1870
|
+
icon: "arrow-left",
|
|
1871
|
+
...o
|
|
1872
|
+
}, {
|
|
1873
|
+
label: "Move column right",
|
|
1874
|
+
icon: "arrow-right",
|
|
1875
|
+
...s
|
|
1876
|
+
}];
|
|
1877
|
+
}
|
|
1878
|
+
function Er(e, t, n) {
|
|
1879
|
+
return n === "row" ? e.top === 0 && e.bottom === t.height : e.left === 0 && e.right === t.width;
|
|
1880
|
+
}
|
|
1881
|
+
function Dr(e, t, n, r) {
|
|
1882
|
+
let { doc: i } = e.state, { map: a, pos: o } = t, s = o + 1, c = a.map[0], l = n !== null, u = J.create(i, s + c, s + a.map[a.map.length - 1]), d = Le.create({
|
|
1883
|
+
doc: i,
|
|
1884
|
+
selection: n ?? u
|
|
1885
|
+
}), f = n ? n instanceof J ? n.$headCell : Qe(n.$head) : null, p = f ? f.pos - s : c, m = a.map.includes(p) ? p : c, h = a.findCell(m), g = new J(i.resolve(s + m)), _ = Le.create({
|
|
1886
|
+
doc: i,
|
|
1887
|
+
selection: g
|
|
1888
|
+
}), v = n instanceof J ? d : _, y = at(v), b = (t) => () => {
|
|
1889
|
+
!e.isDestroyed && e.isEditable && e.state.doc === i && t();
|
|
1890
|
+
}, x = d.selection instanceof J ? d.selection : g, S = (t) => {
|
|
1891
|
+
let n = q(d.tr);
|
|
1892
|
+
x.forEachCell((e, r) => {
|
|
1893
|
+
(e.attrs.align ?? "left") !== t && n.setNodeMarkup(r, null, {
|
|
1894
|
+
...e.attrs,
|
|
1895
|
+
align: t === "left" ? null : t
|
|
1896
|
+
});
|
|
1897
|
+
}), n.docChanged ? Q(e, n) : e.view.focus();
|
|
1898
|
+
}, C = /* @__PURE__ */ new Set();
|
|
1899
|
+
x.forEachCell((e) => C.add(e.attrs.align ?? "left"));
|
|
1900
|
+
let w = l && rt(d), T = [{
|
|
1901
|
+
label: "Merge cells",
|
|
1902
|
+
icon: "table-cells-merge",
|
|
1903
|
+
description: w ? void 0 : "Drag across 2 or more cells",
|
|
1904
|
+
disabled: !w,
|
|
1905
|
+
run: b(() => rt(d, (t) => Q(e, t)))
|
|
1906
|
+
}];
|
|
1907
|
+
l && ot(d) && T.push({
|
|
1908
|
+
label: "Split cell",
|
|
1909
|
+
icon: "table-cells-split",
|
|
1910
|
+
run: b(() => ot(d, (t) => Q(e, t)))
|
|
1911
|
+
});
|
|
1912
|
+
let E = (n) => {
|
|
1913
|
+
let { group: i, insertBefore: o, insertAfter: s, remove: c } = wr[n], u = n === "row" ? h.top : h.left, d = n === "row" ? h.bottom : h.right, f = Er(y, a, n), p = hr(t, n), m = p.findIndex(({ start: e, end: t }) => u >= e && u < t), g = [
|
|
1914
|
+
...Tr(n, r, p[m - 1], p[m + 1]).map(({ label: r, icon: i, boundary: a }) => ({
|
|
1915
|
+
label: r,
|
|
1916
|
+
icon: i,
|
|
1917
|
+
disabled: a === void 0,
|
|
1918
|
+
run: b(() => {
|
|
1919
|
+
a !== void 0 && Cr(e, t, n, h, a);
|
|
1920
|
+
})
|
|
1921
|
+
})),
|
|
1922
|
+
{
|
|
1923
|
+
...o,
|
|
1924
|
+
disabled: !xr(t, n, u),
|
|
1925
|
+
run: b(() => Sr(e, t, n, u))
|
|
1926
|
+
},
|
|
1927
|
+
{
|
|
1928
|
+
...s,
|
|
1929
|
+
run: b(() => Sr(e, t, n, d))
|
|
1930
|
+
},
|
|
1931
|
+
{
|
|
1932
|
+
...c,
|
|
1933
|
+
tone: "danger",
|
|
1934
|
+
disabled: f,
|
|
1935
|
+
run: b(() => {
|
|
1936
|
+
l && !f && (n === "row" ? tt : et)(v, (t) => Q(e, q(t)));
|
|
1937
|
+
})
|
|
1938
|
+
}
|
|
1939
|
+
];
|
|
1940
|
+
return {
|
|
1941
|
+
label: i,
|
|
1942
|
+
description: l ? void 0 : "Select a cell first",
|
|
1943
|
+
separate: !0,
|
|
1944
|
+
actions: l ? g : g.map((e) => ({
|
|
1945
|
+
...e,
|
|
1946
|
+
disabled: !0
|
|
1947
|
+
}))
|
|
1948
|
+
};
|
|
1949
|
+
}, D = (n) => {
|
|
1950
|
+
let r = n === "row", { table: i, map: a } = t, o = r ? it(a, i, 0) : $e(a, i, 0), s = !1, c = st(n);
|
|
1951
|
+
return c(_, (e) => {
|
|
1952
|
+
s = e.docChanged;
|
|
1953
|
+
}), {
|
|
1954
|
+
label: `${o ? "Remove" : "Add"} header ${n}`,
|
|
1955
|
+
icon: r ? "panel-top" : "panel-left",
|
|
1956
|
+
inlineIcon: !r,
|
|
1957
|
+
disabled: !s,
|
|
1958
|
+
run: b(() => c(_, (t) => Q(e, t)))
|
|
1959
|
+
};
|
|
1960
|
+
};
|
|
1961
|
+
return [
|
|
1962
|
+
{
|
|
1963
|
+
label: "Cell alignment",
|
|
1964
|
+
choices: !0,
|
|
1965
|
+
actions: yr.map(({ align: e, icon: t, label: n }) => ({
|
|
1966
|
+
label: n,
|
|
1967
|
+
icon: t,
|
|
1968
|
+
checked: C.size === 1 && C.has(e),
|
|
1969
|
+
run: b(() => S(e))
|
|
1970
|
+
}))
|
|
1971
|
+
},
|
|
1972
|
+
E("row"),
|
|
1973
|
+
E("column"),
|
|
1974
|
+
{
|
|
1975
|
+
label: "Cells",
|
|
1976
|
+
actions: T,
|
|
1977
|
+
separate: !0
|
|
1978
|
+
},
|
|
1979
|
+
{
|
|
1980
|
+
label: "Headers",
|
|
1981
|
+
separate: !0,
|
|
1982
|
+
actions: [D("row"), D("column")]
|
|
1983
|
+
},
|
|
1984
|
+
{
|
|
1985
|
+
separate: !0,
|
|
1986
|
+
actions: [{
|
|
1987
|
+
label: "Delete table",
|
|
1988
|
+
icon: "grid-2x2-x",
|
|
1989
|
+
tone: "danger",
|
|
1990
|
+
run: b(() => nt(d, (t) => Q(e, t)))
|
|
1991
|
+
}]
|
|
1992
|
+
}
|
|
1993
|
+
];
|
|
1994
|
+
}
|
|
1995
|
+
//#endregion
|
|
1996
|
+
//#region src/components/RichTextEditor/table-view.tsx
|
|
1997
|
+
var Or = new ze("tableCellContext"), kr = /* @__PURE__ */ new WeakMap(), $ = (e) => e.type.spec.tableRole === "table", Ar = (e) => e.type.name === "contentBlock";
|
|
1998
|
+
function jr(e) {
|
|
1999
|
+
return e instanceof K && $(e.node) || !!Y(e.$from) || !!Y(e.$to);
|
|
2000
|
+
}
|
|
2001
|
+
function Mr(e, t) {
|
|
2002
|
+
let n = e instanceof J ? e.$anchorCell : e.$from, r = e instanceof J ? e.$headCell : e.$to;
|
|
2003
|
+
return Y(n)?.pos === t && Y(r)?.pos === t;
|
|
2004
|
+
}
|
|
2005
|
+
function Nr(e, t, n = !1) {
|
|
2006
|
+
let { state: r } = e, i = Mr(r.selection, t) ? r.selection : null, a = K.create(r.doc, t), o = r.tr.setSelection(a);
|
|
2007
|
+
i && o.setMeta(Or, i), e.dispatch(n ? q(o) : o);
|
|
2008
|
+
}
|
|
2009
|
+
function Pr(e, t) {
|
|
2010
|
+
let n = !1;
|
|
2011
|
+
return e.content.descendants((e) => (n ||= t(e), !n)), n;
|
|
2012
|
+
}
|
|
2013
|
+
function Fr({ node: e, isSelected: t, frame: n, onSelect: r, actions: i }) {
|
|
2014
|
+
let { disabled: a } = L(X), { height: o, width: s } = Ye.get(e), c = `${o} ${o === 1 ? "row" : "rows"}`, l = `${s} ${s === 1 ? "column" : "columns"}`;
|
|
2015
|
+
return d(() => {
|
|
2016
|
+
n.toggleAttribute("data-selected", t && !a);
|
|
2017
|
+
}, [
|
|
2018
|
+
a,
|
|
2019
|
+
n,
|
|
2020
|
+
t
|
|
2021
|
+
]), /* @__PURE__ */ W(zt, {
|
|
2022
|
+
kind: "Table",
|
|
2023
|
+
meta: `${c} · ${l}`,
|
|
2024
|
+
isSelected: t,
|
|
2025
|
+
isDisabled: a,
|
|
2026
|
+
menuLabel: "Table actions",
|
|
2027
|
+
onSelect: r,
|
|
2028
|
+
actions: i
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
var Ir = /* @__PURE__ */ new WeakMap();
|
|
2032
|
+
function Lr(e, t) {
|
|
2033
|
+
Ir.get(e)?.();
|
|
2034
|
+
let n = () => {
|
|
2035
|
+
e.removeEventListener("contextmenu", r, !0), e.removeEventListener("pointerdown", n, !0), e.removeEventListener("mousedown", n, !0), e.removeEventListener("keydown", i, !0), Ir.get(e) === n && Ir.delete(e);
|
|
2036
|
+
}, r = (e) => {
|
|
2037
|
+
e.preventDefault(), n();
|
|
2038
|
+
}, i = (e) => {
|
|
2039
|
+
e.key !== t && n();
|
|
2040
|
+
};
|
|
2041
|
+
e.addEventListener("contextmenu", r, !0), e.addEventListener("pointerdown", n, !0), e.addEventListener("mousedown", n, !0), e.addEventListener("keydown", i, !0), Ir.set(e, n);
|
|
2042
|
+
}
|
|
2043
|
+
function Rr(e) {
|
|
2044
|
+
if (!e.isEditable) return null;
|
|
2045
|
+
let { selection: t } = e.state, n = t instanceof J ? t.$headCell : t.$head, r = t instanceof K && $(t.node) ? t.from : Y(n)?.pos, i = r === void 0 ? null : e.view.nodeDOM(r);
|
|
2046
|
+
return i instanceof HTMLElement ? i.querySelector(".ds-rte__table-bar-host button") : null;
|
|
2047
|
+
}
|
|
2048
|
+
var zr = class extends Ge {
|
|
2049
|
+
bar;
|
|
2050
|
+
constructor({ editor: e, node: t, view: n, getPos: r, HTMLAttributes: i }, a) {
|
|
2051
|
+
super(t, a, n, i);
|
|
2052
|
+
let o = this.dom, s = o.ownerDocument;
|
|
2053
|
+
this.dom = s.createElement("div"), this.dom.className = Pt, this.dom.dataset.kind = "table", this.dom.dataset.align = "full", this.bar = new ke(Fr, {
|
|
2054
|
+
editor: e,
|
|
2055
|
+
className: "ds-rte__table-bar-host",
|
|
2056
|
+
props: {
|
|
2057
|
+
node: t,
|
|
2058
|
+
isSelected: !1,
|
|
2059
|
+
frame: this.dom,
|
|
2060
|
+
onSelect: () => {
|
|
2061
|
+
let e = r();
|
|
2062
|
+
n.editable && e !== void 0 && (Nr(n, e), n.focus());
|
|
2063
|
+
},
|
|
2064
|
+
actions: (t) => {
|
|
2065
|
+
let i = r(), { state: a } = n, o = i === void 0 ? null : a.doc.nodeAt(i);
|
|
2066
|
+
if (i === void 0 || !o || !$(o)) return [];
|
|
2067
|
+
let s = Ye.get(o);
|
|
2068
|
+
if (!s.map.length) return [];
|
|
2069
|
+
let c = Or.getState(a), l = Mr(a.selection, i) ? a.selection : c && Mr(c, i) ? c : null;
|
|
2070
|
+
return Dr(e, {
|
|
2071
|
+
table: o,
|
|
2072
|
+
map: s,
|
|
2073
|
+
pos: i
|
|
2074
|
+
}, l, t);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
}), this.bar.element.contentEditable = "false", this.dom.append(this.bar.element, o), this.bar.element.addEventListener("dragstart", (e) => {
|
|
2078
|
+
let t = r();
|
|
2079
|
+
n.editable && t !== void 0 && e.dataTransfer && e.target instanceof Element && e.target.closest("[data-drag-handle]") && (Nr(n, t, !0), n.state.selection instanceof K && kr.set(n, n.state.selection), e.dataTransfer.setDragImage?.(this.dom, 12, 12));
|
|
2080
|
+
}), this.bar.element.addEventListener("dragend", () => kr.delete(n));
|
|
2081
|
+
}
|
|
2082
|
+
update(e) {
|
|
2083
|
+
return super.update(e) ? (this.bar.updateProps({ node: e }), !0) : !1;
|
|
2084
|
+
}
|
|
2085
|
+
selectNode() {
|
|
2086
|
+
this.bar.updateProps({ isSelected: !0 });
|
|
2087
|
+
}
|
|
2088
|
+
deselectNode() {
|
|
2089
|
+
this.bar.updateProps({ isSelected: !1 });
|
|
2090
|
+
}
|
|
2091
|
+
ignoreMutation(e) {
|
|
2092
|
+
return this.bar.element.contains(e.target) || super.ignoreMutation(e);
|
|
2093
|
+
}
|
|
2094
|
+
stopEvent(e) {
|
|
2095
|
+
return e.target instanceof Element && this.bar.element.contains(e.target) && !["dragstart", "dragend"].includes(e.type);
|
|
2096
|
+
}
|
|
2097
|
+
destroy() {
|
|
2098
|
+
this.bar.destroy();
|
|
2099
|
+
}
|
|
2100
|
+
}, Br = bt.extend({
|
|
2101
|
+
addNodeView() {
|
|
2102
|
+
return (e) => new zr(e, this.options.cellMinWidth);
|
|
2103
|
+
},
|
|
2104
|
+
addKeyboardShortcuts() {
|
|
2105
|
+
let e = this.parent?.(), t = (e) => ({ editor: t }) => {
|
|
2106
|
+
let n = Rr(t);
|
|
2107
|
+
return n ? (n.click(), Lr(t.view.dom.ownerDocument, e), !0) : !1;
|
|
2108
|
+
};
|
|
2109
|
+
return {
|
|
2110
|
+
...e,
|
|
2111
|
+
"Shift-F10": t("F10"),
|
|
2112
|
+
ContextMenu: t("ContextMenu"),
|
|
2113
|
+
Escape: ({ editor: e }) => {
|
|
2114
|
+
let t = Y(e.state.selection.$from);
|
|
2115
|
+
return !e.isEditable || !t ? !1 : (Nr(e.view, t.pos), !0);
|
|
2116
|
+
},
|
|
2117
|
+
Tab: ({ editor: t }) => {
|
|
2118
|
+
let { selection: n } = t.state;
|
|
2119
|
+
if (t.isEditable && n instanceof K && $(n.node)) {
|
|
2120
|
+
let e = Rr(t);
|
|
2121
|
+
if (e) return e.focus(), !0;
|
|
2122
|
+
}
|
|
2123
|
+
return e?.Tab?.({ editor: t }) ?? !1;
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
},
|
|
2127
|
+
addProseMirrorPlugins() {
|
|
2128
|
+
return [
|
|
2129
|
+
new Re({ props: { handlePaste(e, t, n) {
|
|
2130
|
+
let { selection: r } = e.state;
|
|
2131
|
+
return (r instanceof J || !!Qe(r.$from) || !!Qe(r.$head)) && Pr(n, Ar);
|
|
2132
|
+
} } }),
|
|
2133
|
+
...this.parent?.() ?? [],
|
|
2134
|
+
new Re({
|
|
2135
|
+
key: Or,
|
|
2136
|
+
state: {
|
|
2137
|
+
init: () => null,
|
|
2138
|
+
apply(e, t) {
|
|
2139
|
+
return e.docChanged || !(e.selection instanceof K) || !$(e.selection.node) ? null : e.getMeta(Or) ?? (t && Mr(t, e.selection.from) ? t : null);
|
|
2140
|
+
}
|
|
2141
|
+
},
|
|
2142
|
+
props: {
|
|
2143
|
+
handleDrop(e, t, n, r) {
|
|
2144
|
+
let i = kr.get(e);
|
|
2145
|
+
if (kr.delete(e), r && i && (i.$from.doc !== e.state.doc || !i.eq(e.state.selection))) return !0;
|
|
2146
|
+
let a = e.posAtCoords({
|
|
2147
|
+
left: t.clientX,
|
|
2148
|
+
top: t.clientY
|
|
2149
|
+
});
|
|
2150
|
+
if (!a) return !1;
|
|
2151
|
+
let { doc: o } = e.state, s = o.resolve(a.pos);
|
|
2152
|
+
return !!(Qe(s) ?? (a.inside >= 0 ? Qe(o.resolve(a.inside + 1)) : null)) && Pr(n, Ar) || !!Y(s) && Pr(n, $);
|
|
2153
|
+
},
|
|
2154
|
+
handlePaste: (e, t, n) => !!Y(e.state.selection.$from) && Pr(n, $)
|
|
2155
|
+
}
|
|
2156
|
+
})
|
|
2157
|
+
];
|
|
2158
|
+
}
|
|
2159
|
+
}).configure({ allowTableNodeSelection: !0 }), Vr = [], Hr = /* @__PURE__ */ new WeakMap();
|
|
2160
|
+
function Ur(e, t) {
|
|
2161
|
+
return `${e}:${t}`;
|
|
2162
|
+
}
|
|
2163
|
+
function Wr(e) {
|
|
2164
|
+
let { latest: t } = L(X);
|
|
2165
|
+
return I(() => {
|
|
2166
|
+
let n = t(e.definition.type);
|
|
2167
|
+
return (n && Hr.get(n)) ?? e;
|
|
2168
|
+
}, [t, e]);
|
|
2169
|
+
}
|
|
2170
|
+
function Gr(e) {
|
|
2171
|
+
return !!(e.loadPage || e.items?.length);
|
|
2172
|
+
}
|
|
2173
|
+
function Kr(e, t) {
|
|
2174
|
+
let { itemLabel: n, toData: r, definition: i, invalidItemReason: a } = e;
|
|
2175
|
+
if (t.tone === "removed") return {
|
|
2176
|
+
label: t.removedLabel ?? "Removed",
|
|
2177
|
+
description: `This ${n} was removed.`
|
|
2178
|
+
};
|
|
2179
|
+
if (t.isUnavailable) return {
|
|
2180
|
+
label: "Unavailable",
|
|
2181
|
+
description: `This ${n} is unavailable.`
|
|
2182
|
+
};
|
|
2183
|
+
let o = r(t);
|
|
2184
|
+
if (!y(o) || !i.validate(o)) return {
|
|
2185
|
+
label: "Can't embed",
|
|
2186
|
+
description: a?.(t) ?? `This ${n} can't be embedded.`
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
function qr(e, t, n, r) {
|
|
2190
|
+
let i = e.flatMap((e) => {
|
|
2191
|
+
let i = r(e.item.id);
|
|
2192
|
+
return i === void 0 ? [e] : !i || i.isDisabled || Kr(t, i) ? [] : i === e.item && Object.is(n, e.revision) ? [e] : [{
|
|
2193
|
+
item: i,
|
|
2194
|
+
revision: n
|
|
2195
|
+
}];
|
|
2196
|
+
});
|
|
2197
|
+
return i.length !== e.length || i.some((t, n) => t !== e[n]) ? i : e;
|
|
2198
|
+
}
|
|
2199
|
+
function Jr({ config: e, data: t, frame: n }) {
|
|
2200
|
+
let { picks: r } = L(X), i = Wr(e), { itemLabel: a, itemId: o, source: s, definition: c } = e, l = o(t), u = s?.items ?? Vr, d = B(() => [l], [l]), f = I((e) => r.get(Ur(c.type, e)), [r, c.type]), p = s.resolveItem ? (e) => i().source.resolveItem?.(e) ?? null : void 0, m = k(d, u, p, s.refreshKey, f), h = Ur(c.type, l), g = r.get(h);
|
|
2201
|
+
R(() => {
|
|
2202
|
+
g && r.get(h) === g && r.delete(h);
|
|
2203
|
+
}, [
|
|
2204
|
+
r,
|
|
2205
|
+
h,
|
|
2206
|
+
g
|
|
2207
|
+
]);
|
|
2208
|
+
let { known: _, failures: v } = m, y = !!s?.resolveItem, b = B(() => re({
|
|
2209
|
+
selected: d,
|
|
2210
|
+
items: u,
|
|
2211
|
+
pageItems: Vr,
|
|
2212
|
+
known: _,
|
|
2213
|
+
failures: v,
|
|
2214
|
+
hasResolver: y,
|
|
2215
|
+
itemLabel: a
|
|
2216
|
+
})[0], [
|
|
2217
|
+
d,
|
|
2218
|
+
u,
|
|
2219
|
+
_,
|
|
2220
|
+
v,
|
|
2221
|
+
y,
|
|
2222
|
+
a
|
|
2223
|
+
]), x = te(`Couldn't load ${a}`, m.status, m.error, m.retry), S = u.some((e) => e.id === l), C = b.tone === "removed" || !S && _.has(l) && !_.get(l), w = !C && !b.isUnavailable && !b.isDisabled && s.onEditItem;
|
|
2224
|
+
return n({
|
|
2225
|
+
title: C ? `Unavailable ${a}` : b.title,
|
|
2226
|
+
tone: b.tone,
|
|
2227
|
+
missing: C,
|
|
2228
|
+
onEdit: w ? () => i().source.onEditItem?.(b) : void 0,
|
|
2229
|
+
replaceLabel: C ? `Choose another ${a}` : void 0,
|
|
2230
|
+
body: /* @__PURE__ */ G(U, { children: [/* @__PURE__ */ W(Yr, {
|
|
2231
|
+
kind: a,
|
|
2232
|
+
id: l,
|
|
2233
|
+
item: b,
|
|
2234
|
+
missing: C
|
|
2235
|
+
}), x && /* @__PURE__ */ W("div", {
|
|
2236
|
+
className: "ds-content-block__failure",
|
|
2237
|
+
children: x
|
|
2238
|
+
})] })
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
function Yr({ kind: e, id: t, item: n, missing: r }) {
|
|
2242
|
+
return /* @__PURE__ */ W("div", {
|
|
2243
|
+
className: "ds-entry ds-content-block__body",
|
|
2244
|
+
children: r ? /* @__PURE__ */ G("span", {
|
|
2245
|
+
className: "ds-entry__body",
|
|
2246
|
+
children: [/* @__PURE__ */ W("em", {
|
|
2247
|
+
className: "ds-entry__title",
|
|
2248
|
+
children: `Unavailable ${e}`
|
|
2249
|
+
}), /* @__PURE__ */ G("span", {
|
|
2250
|
+
className: "ds-entry__meta",
|
|
2251
|
+
children: [/* @__PURE__ */ W("span", { children: `This ${e} was deleted. Replace or remove it.` }), /* @__PURE__ */ W("code", { children: t })]
|
|
2252
|
+
})]
|
|
2253
|
+
}) : /* @__PURE__ */ W(O, { item: n })
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
function Xr(e, t, n, r, i) {
|
|
2257
|
+
let a = [];
|
|
2258
|
+
for (let e of n) {
|
|
2259
|
+
let n = t.toData(e.item);
|
|
2260
|
+
if (!n || e.item.isDisabled || Kr(t, e.item)) return !1;
|
|
2261
|
+
a.push(n);
|
|
2262
|
+
}
|
|
2263
|
+
i.clear();
|
|
2264
|
+
for (let e of n) i.set(Ur(t.definition.type, e.item.id), e);
|
|
2265
|
+
let o = e.target.commit(r ? a : a[0]);
|
|
2266
|
+
return o || i.clear(), o;
|
|
2267
|
+
}
|
|
2268
|
+
function Zr(e, t, n, r) {
|
|
2269
|
+
let { itemLabel: i, itemsLabel: a, source: o } = t, { isDisabled: s, target: c } = e, l = c.close, d = e.data && t.itemId(e.data), f = I((e) => Kr(t, e), [t]), p = !!o.isCreating, [m, h] = H([]), [g, _] = H(""), v = u(m.length), y = B(() => d ? [d] : m.map(({ item: e }) => e.id), [d, m]), b = ne(y, o.items ?? Vr, {
|
|
2270
|
+
...o,
|
|
2271
|
+
resolveItem: n ? o.resolveItem : void 0,
|
|
2272
|
+
mode: n ? "multiple" : "single",
|
|
2273
|
+
max: void 0
|
|
2274
|
+
}, {
|
|
2275
|
+
isOpen: !0,
|
|
2276
|
+
isDisabled: s || p,
|
|
2277
|
+
itemLabel: i,
|
|
2278
|
+
itemsLabel: a,
|
|
2279
|
+
close: l,
|
|
2280
|
+
recheckSelection: n,
|
|
2281
|
+
restrict: f
|
|
2282
|
+
}), x = qr(m, t, o.refreshKey, (e) => b.isRemote ? b.selection.current.get(e) : o.items?.find((t) => t.id === e) ?? null), S = m.length - x.length;
|
|
2283
|
+
return x !== m && h(x), S > 0 && _(`${S} unavailable ${S === 1 ? i : a} removed from selection.`), {
|
|
2284
|
+
canInsert: !s && !p && b.selection.status === "ready" && x.length > 0 && S === 0,
|
|
2285
|
+
choices: x,
|
|
2286
|
+
pendingCount: v,
|
|
2287
|
+
hasPending: m.length > 0,
|
|
2288
|
+
picker: b,
|
|
2289
|
+
selectionNotice: g,
|
|
2290
|
+
toggle: (e) => {
|
|
2291
|
+
let t = b.choice(e);
|
|
2292
|
+
if (!t) return;
|
|
2293
|
+
let i = {
|
|
2294
|
+
item: t,
|
|
2295
|
+
revision: b.revision
|
|
2296
|
+
};
|
|
2297
|
+
n ? (_(""), y.includes(e) ? h((t) => t.filter(({ item: t }) => t.id !== e)) : (b.selection.remember([t], i.revision, [...y, e]), h((e) => [...e, i]))) : r([i]);
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
function Qr({ session: e, config: t }) {
|
|
2302
|
+
let { itemLabel: n, itemsLabel: r, source: i } = t, { fieldLabel: a, target: o } = e, s = o.close, c = e.mode === "replace", l = !c && Gr(i), { picks: d } = L(X), f = (n) => Xr(e, t, n, l, d), p = u({
|
|
2303
|
+
source: i,
|
|
2304
|
+
pick: f
|
|
2305
|
+
}), { canInsert: m, choices: h, pendingCount: g, hasPending: _, picker: v, selectionNotice: y, toggle: b } = Zr(e, t, l, f), x = te(`Couldn't load selected ${r}`, v.selection.status, v.selection.error, v.selection.retry), S = c ? "Replace" : "Embed", C = () => {
|
|
2306
|
+
m && f(h);
|
|
2307
|
+
};
|
|
2308
|
+
return /* @__PURE__ */ W(ie, {
|
|
2309
|
+
...v.dialog,
|
|
2310
|
+
isOpen: !0,
|
|
2311
|
+
onClose: s,
|
|
2312
|
+
onToggle: b,
|
|
2313
|
+
addLabel: `${S} ${l ? r : n}`,
|
|
2314
|
+
confirm: l ? {
|
|
2315
|
+
label: "Insert selected",
|
|
2316
|
+
isDisabled: !m,
|
|
2317
|
+
onClick: C
|
|
2318
|
+
} : void 0,
|
|
2319
|
+
selectionNotice: y,
|
|
2320
|
+
selectionFailure: x,
|
|
2321
|
+
onCreate: i.onCreate ? () => i.onCreate?.({
|
|
2322
|
+
available: () => g.current === 0 && o.available(),
|
|
2323
|
+
commit: (e) => g.current === 0 && p.current.pick([{
|
|
2324
|
+
item: e,
|
|
2325
|
+
revision: p.current.source.refreshKey
|
|
2326
|
+
}])
|
|
2327
|
+
}) : void 0,
|
|
2328
|
+
isCreateDisabled: _,
|
|
2329
|
+
isCreating: i.isCreating,
|
|
2330
|
+
dialogTitle: i.dialogTitle,
|
|
2331
|
+
dialogDescription: `${l ? `Choose ${r}` : `Choose one ${n}`} to embed in ${a}. ${i.dialogDescription ?? ""}`.trim(),
|
|
2332
|
+
isDialogHidden: i.isDialogHidden
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
function $r(e) {
|
|
2336
|
+
let { definition: t, itemLabel: n, itemsLabel: r, icon: i, source: a } = e, o = Gr(a) || !!a.onCreate, s = {
|
|
2337
|
+
definition: t,
|
|
2338
|
+
label: n,
|
|
2339
|
+
icon: i,
|
|
2340
|
+
insertLabel: o ? `Embed ${Gr(a) ? r : n}` : void 0,
|
|
2341
|
+
replaceLabel: o ? "Replace" : void 0,
|
|
2342
|
+
isCreating: a.isCreating,
|
|
2343
|
+
isDialogHidden: a.isDialogHidden,
|
|
2344
|
+
renderPreview: (t, n) => /* @__PURE__ */ W(Jr, {
|
|
2345
|
+
config: e,
|
|
2346
|
+
data: t,
|
|
2347
|
+
frame: n
|
|
2348
|
+
}),
|
|
2349
|
+
renderEditor: (t) => /* @__PURE__ */ W(Qr, {
|
|
2350
|
+
session: t,
|
|
2351
|
+
config: e
|
|
2352
|
+
})
|
|
2353
|
+
};
|
|
2354
|
+
return Hr.set(s, e), jt.set(s, [
|
|
2355
|
+
a.items,
|
|
2356
|
+
a.refreshKey,
|
|
2357
|
+
!!a.resolveItem,
|
|
2358
|
+
!!a.onEditItem
|
|
2359
|
+
]), s;
|
|
2360
|
+
}
|
|
2361
|
+
//#endregion
|
|
2362
|
+
//#region src/components/RichTextEditor/index.tsx
|
|
2363
|
+
var ei = /* @__PURE__ */ new Map();
|
|
2364
|
+
function ti({ editor: e, selection: n, onClose: r }) {
|
|
2365
|
+
let [i, a] = H(n.href), [o, s] = H(), c = z();
|
|
2366
|
+
R(() => {
|
|
2367
|
+
let t = () => {
|
|
2368
|
+
e.state.doc.eq(n.document) || r();
|
|
2369
|
+
};
|
|
2370
|
+
return e.on("transaction", t), () => {
|
|
2371
|
+
e.off("transaction", t);
|
|
2372
|
+
};
|
|
2373
|
+
}, [
|
|
2374
|
+
e,
|
|
2375
|
+
n,
|
|
2376
|
+
r
|
|
2377
|
+
]);
|
|
2378
|
+
let l = () => !e.isDestroyed && e.isEditable && e.state.doc.eq(n.document), u = () => {
|
|
2379
|
+
if (!l()) {
|
|
2380
|
+
r();
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2383
|
+
let t = i.trim();
|
|
2384
|
+
if (!t || !e.can().setLink({ href: t })) {
|
|
2385
|
+
s(t ? "Enter a valid link URL." : "Enter a link URL.");
|
|
2386
|
+
return;
|
|
2387
|
+
}
|
|
2388
|
+
let a = e.chain().focus().setTextSelection({
|
|
2389
|
+
from: n.from,
|
|
2390
|
+
to: n.to
|
|
2391
|
+
});
|
|
2392
|
+
n.from === n.to && !n.isEditing ? a.setLink({ href: t }).insertContent({
|
|
2393
|
+
type: "text",
|
|
2394
|
+
text: t,
|
|
2395
|
+
marks: [{
|
|
2396
|
+
type: "link",
|
|
2397
|
+
attrs: { href: t }
|
|
2398
|
+
}]
|
|
2399
|
+
}).run() : a.setLink({ href: t }).run(), r();
|
|
2400
|
+
};
|
|
2401
|
+
return /* @__PURE__ */ W(h, {
|
|
2402
|
+
isOpen: !0,
|
|
2403
|
+
title: n.isEditing ? "Edit link" : "Add link",
|
|
2404
|
+
size: "dialog",
|
|
2405
|
+
onClose: r,
|
|
2406
|
+
footer: /* @__PURE__ */ G(U, { children: [
|
|
2407
|
+
n.isEditing && /* @__PURE__ */ W(t, {
|
|
2408
|
+
variant: "danger",
|
|
2409
|
+
onClick: () => {
|
|
2410
|
+
l() && e.chain().focus().setTextSelection({
|
|
2411
|
+
from: n.from,
|
|
2412
|
+
to: n.to
|
|
2413
|
+
}).unsetLink().run(), r();
|
|
2414
|
+
},
|
|
2415
|
+
children: "Remove link"
|
|
2416
|
+
}),
|
|
2417
|
+
/* @__PURE__ */ W(t, {
|
|
2418
|
+
onClick: r,
|
|
2419
|
+
children: "Cancel"
|
|
2420
|
+
}),
|
|
2421
|
+
/* @__PURE__ */ W(t, {
|
|
2422
|
+
variant: "primary",
|
|
2423
|
+
type: "submit",
|
|
2424
|
+
form: c,
|
|
2425
|
+
children: "Save"
|
|
2426
|
+
})
|
|
2427
|
+
] }),
|
|
2428
|
+
children: /* @__PURE__ */ W("form", {
|
|
2429
|
+
id: c,
|
|
2430
|
+
noValidate: !0,
|
|
2431
|
+
onSubmit: (e) => {
|
|
2432
|
+
e.preventDefault(), e.stopPropagation(), u();
|
|
2433
|
+
},
|
|
2434
|
+
children: /* @__PURE__ */ W(m, {
|
|
2435
|
+
label: "URL",
|
|
2436
|
+
isRequired: !0,
|
|
2437
|
+
error: o,
|
|
2438
|
+
children: (e) => /* @__PURE__ */ W(_, {
|
|
2439
|
+
...e,
|
|
2440
|
+
value: i,
|
|
2441
|
+
inputMode: "url",
|
|
2442
|
+
autoComplete: "url",
|
|
2443
|
+
placeholder: "https://example.com",
|
|
2444
|
+
onChange: (e) => {
|
|
2445
|
+
a(e.target.value), s(void 0);
|
|
2446
|
+
}
|
|
2447
|
+
})
|
|
2448
|
+
})
|
|
2449
|
+
})
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
var ni = [
|
|
2453
|
+
[
|
|
2454
|
+
{
|
|
2455
|
+
id: "bold",
|
|
2456
|
+
icon: "bold",
|
|
2457
|
+
label: "Bold",
|
|
2458
|
+
run: (e) => e.chain().focus().toggleBold().run(),
|
|
2459
|
+
active: (e) => e.isActive("bold")
|
|
2460
|
+
},
|
|
2461
|
+
{
|
|
2462
|
+
id: "italic",
|
|
2463
|
+
icon: "italic",
|
|
2464
|
+
label: "Italic",
|
|
2465
|
+
run: (e) => e.chain().focus().toggleItalic().run(),
|
|
2466
|
+
active: (e) => e.isActive("italic")
|
|
2467
|
+
},
|
|
2468
|
+
{
|
|
2469
|
+
id: "strike",
|
|
2470
|
+
icon: "strikethrough",
|
|
2471
|
+
label: "Strikethrough",
|
|
2472
|
+
run: (e) => e.chain().focus().toggleStrike().run(),
|
|
2473
|
+
active: (e) => e.isActive("strike")
|
|
2474
|
+
},
|
|
2475
|
+
{
|
|
2476
|
+
id: "code",
|
|
2477
|
+
icon: "code",
|
|
2478
|
+
label: "Inline code",
|
|
2479
|
+
run: (e) => e.chain().focus().toggleCode().run(),
|
|
2480
|
+
active: (e) => e.isActive("code")
|
|
2481
|
+
}
|
|
2482
|
+
],
|
|
2483
|
+
[
|
|
2484
|
+
{
|
|
2485
|
+
id: "h2",
|
|
2486
|
+
icon: "heading-2",
|
|
2487
|
+
label: "Heading",
|
|
2488
|
+
run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),
|
|
2489
|
+
active: (e) => e.isActive("heading", { level: 2 })
|
|
2490
|
+
},
|
|
2491
|
+
{
|
|
2492
|
+
id: "h3",
|
|
2493
|
+
icon: "heading-3",
|
|
2494
|
+
label: "Subheading",
|
|
2495
|
+
run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),
|
|
2496
|
+
active: (e) => e.isActive("heading", { level: 3 })
|
|
2497
|
+
},
|
|
2498
|
+
{
|
|
2499
|
+
id: "quote",
|
|
2500
|
+
icon: "quote",
|
|
2501
|
+
label: "Quote",
|
|
2502
|
+
run: (e) => e.chain().focus().toggleBlockquote().run(),
|
|
2503
|
+
active: (e) => e.isActive("blockquote")
|
|
2504
|
+
}
|
|
2505
|
+
],
|
|
2506
|
+
[{
|
|
2507
|
+
id: "ul",
|
|
2508
|
+
icon: "list",
|
|
2509
|
+
label: "Bulleted list",
|
|
2510
|
+
run: (e) => e.chain().focus().toggleBulletList().run(),
|
|
2511
|
+
active: (e) => e.isActive("bulletList")
|
|
2512
|
+
}, {
|
|
2513
|
+
id: "ol",
|
|
2514
|
+
icon: "list-ordered",
|
|
2515
|
+
label: "Numbered list",
|
|
2516
|
+
run: (e) => e.chain().focus().toggleOrderedList().run(),
|
|
2517
|
+
active: (e) => e.isActive("orderedList")
|
|
2518
|
+
}],
|
|
2519
|
+
[{
|
|
2520
|
+
id: "undo",
|
|
2521
|
+
icon: "undo",
|
|
2522
|
+
label: "Undo",
|
|
2523
|
+
run: (e) => e.chain().focus().undo().run()
|
|
2524
|
+
}, {
|
|
2525
|
+
id: "redo",
|
|
2526
|
+
icon: "redo",
|
|
2527
|
+
label: "Redo",
|
|
2528
|
+
run: (e) => e.chain().focus().redo().run()
|
|
2529
|
+
}]
|
|
2530
|
+
];
|
|
2531
|
+
function ri({ editor: e, state: n, disabled: r, label: i, toolbarExtra: a, openLink: o, expandControl: s, embedControl: c, tables: l }) {
|
|
2532
|
+
return /* @__PURE__ */ G("div", {
|
|
2533
|
+
className: "ds-rte__toolbar ds-field-surface",
|
|
2534
|
+
role: "toolbar",
|
|
2535
|
+
"aria-label": `${i} formatting`,
|
|
2536
|
+
children: [
|
|
2537
|
+
ni.map((i, a) => /* @__PURE__ */ W(f, {
|
|
2538
|
+
"aria-label": `Formatting ${a + 1}`,
|
|
2539
|
+
children: i.map((i) => /* @__PURE__ */ W(t, {
|
|
2540
|
+
size: "sm",
|
|
2541
|
+
isIconOnly: !0,
|
|
2542
|
+
iconStart: i.icon,
|
|
2543
|
+
"aria-label": i.label,
|
|
2544
|
+
title: i.label,
|
|
2545
|
+
"aria-pressed": i.active ? n?.active[i.id] : void 0,
|
|
2546
|
+
variant: n?.active[i.id] ? "primary" : "neutral",
|
|
2547
|
+
isDisabled: r || !e,
|
|
2548
|
+
onClick: () => e && i.run(e)
|
|
2549
|
+
}, i.id))
|
|
2550
|
+
}, a)),
|
|
2551
|
+
/* @__PURE__ */ W(f, {
|
|
2552
|
+
"aria-label": "Link",
|
|
2553
|
+
children: /* @__PURE__ */ W(t, {
|
|
2554
|
+
size: "sm",
|
|
2555
|
+
isIconOnly: !0,
|
|
2556
|
+
iconStart: "link",
|
|
2557
|
+
"aria-label": n?.linkActive ? "Edit link" : "Add link",
|
|
2558
|
+
title: n?.linkActive ? "Edit link" : "Add link",
|
|
2559
|
+
variant: n?.linkActive ? "primary" : "neutral",
|
|
2560
|
+
isDisabled: r || !e,
|
|
2561
|
+
onClick: () => e && o(e.state, e.isActive("link") ? e.state.selection.from : void 0)
|
|
2562
|
+
})
|
|
2563
|
+
}),
|
|
2564
|
+
l && /* @__PURE__ */ W(fr, {
|
|
2565
|
+
editor: e,
|
|
2566
|
+
disabled: r,
|
|
2567
|
+
inTable: n?.tableActive ?? !1
|
|
2568
|
+
}),
|
|
2569
|
+
c,
|
|
2570
|
+
a,
|
|
2571
|
+
s
|
|
2572
|
+
]
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
var ii = xe(function({ scopeRef: e, className: t, expansion: n, isFocused: r, disabled: i, invalid: a, contentError: o, errorId: s, surface: c, children: u }, d) {
|
|
2576
|
+
return /* @__PURE__ */ W(l.Provider, {
|
|
2577
|
+
value: e,
|
|
2578
|
+
children: /* @__PURE__ */ G("div", {
|
|
2579
|
+
ref: d,
|
|
2580
|
+
className: ["ds-rte", t].filter(Boolean).join(" "),
|
|
2581
|
+
style: n.frameStyle,
|
|
2582
|
+
"data-expanded": n.expanded || void 0,
|
|
2583
|
+
"data-focused": r && !n.expanded || void 0,
|
|
2584
|
+
"data-disabled": i || void 0,
|
|
2585
|
+
"data-invalid": a || void 0,
|
|
2586
|
+
"aria-invalid": a || void 0,
|
|
2587
|
+
children: [
|
|
2588
|
+
o && /* @__PURE__ */ W("p", {
|
|
2589
|
+
id: s,
|
|
2590
|
+
role: "alert",
|
|
2591
|
+
className: "ds-field__error",
|
|
2592
|
+
children: o
|
|
2593
|
+
}),
|
|
2594
|
+
n.expanded && /* @__PURE__ */ W("p", {
|
|
2595
|
+
className: "ds-rte__placeholder",
|
|
2596
|
+
children: "Editing in expanded view. Press Esc to return."
|
|
2597
|
+
}),
|
|
2598
|
+
n.surfaceSlot(/* @__PURE__ */ W("div", {
|
|
2599
|
+
className: "ds-rte__surface",
|
|
2600
|
+
hidden: !!o,
|
|
2601
|
+
"data-expanded": n.expanded || void 0,
|
|
2602
|
+
"data-focused": r || void 0,
|
|
2603
|
+
"data-disabled": i || void 0,
|
|
2604
|
+
"data-invalid": a || void 0,
|
|
2605
|
+
children: c
|
|
2606
|
+
})),
|
|
2607
|
+
n.dialog,
|
|
2608
|
+
u
|
|
2609
|
+
]
|
|
2610
|
+
})
|
|
2611
|
+
});
|
|
2612
|
+
}), ai = ht.extend({ addNodeView() {
|
|
2613
|
+
return Oe(Vt, { update: ({ oldNode: e, newNode: t, updateProps: n }) => e.attrs.type === t.attrs.type && (e !== t && n(), !0) });
|
|
2614
|
+
} });
|
|
2615
|
+
function oi(e, t) {
|
|
2616
|
+
return t.key !== "Escape" || t.isComposing ? !1 : (e.someProp("handleKeyDown", (n) => n(e, t)) && t.preventDefault(), !0);
|
|
2617
|
+
}
|
|
2618
|
+
function si(e, { format: t, value: n }, r, i, a, o) {
|
|
2619
|
+
if (n === void 0 && e && !e.isDestroyed) {
|
|
2620
|
+
if (t !== "json") {
|
|
2621
|
+
let t = typeof r == "string" && Ot(r, o);
|
|
2622
|
+
return (i || a) && !t ? e.getHTML() : void 0;
|
|
2623
|
+
}
|
|
2624
|
+
return kt(r, {
|
|
2625
|
+
tables: i,
|
|
2626
|
+
blockDefinitions: o
|
|
2627
|
+
}) ? void 0 : e.getJSON();
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
var ci = Te.create({
|
|
2631
|
+
name: "contentBlockGuard",
|
|
2632
|
+
addOptions() {
|
|
2633
|
+
let e = Et(/* @__PURE__ */ new Map());
|
|
2634
|
+
return { check: () => e };
|
|
2635
|
+
},
|
|
2636
|
+
addProseMirrorPlugins() {
|
|
2637
|
+
let { check: e } = this.options;
|
|
2638
|
+
return [new Re({ filterTransaction: (t) => !t.docChanged || Dt(t.doc, e()) })];
|
|
2639
|
+
}
|
|
2640
|
+
});
|
|
2641
|
+
function li(e, t, { definitions: n, check: r }) {
|
|
2642
|
+
if (Ot(e, n)) return !0;
|
|
2643
|
+
let i = !1;
|
|
2644
|
+
return t.content.forEach((e) => {
|
|
2645
|
+
i ||= !Dt(e, r);
|
|
2646
|
+
}), i;
|
|
2647
|
+
}
|
|
2648
|
+
var ui = () => () => {}, di = () => typeof DOMParser < "u", fi = () => !1;
|
|
2649
|
+
function pi() {
|
|
2650
|
+
return Se(ui, di, fi);
|
|
2651
|
+
}
|
|
2652
|
+
var mi = xe(function(e, t) {
|
|
2653
|
+
let { placeholder: r = "Write something…", size: i = "md", expandedWidth: a = "wide", isDisabled: o = !1, isInvalid: s = !1, label: c = "Rich text editor", className: l, toolbarExtra: d, tables: f = !0, blockPlugins: p = At, id: m, isRequired: h, required: g, "aria-label": _, "aria-labelledby": y, "aria-describedby": b, "aria-invalid": x } = e, S = V(null), C = B(() => n(S, t), [t]), [w, T] = H(!1), [E, D] = H(null), O = I(() => D(null), []), [ee, te] = H(() => e.defaultValue ?? (e.format === "json" ? gt : "")), [ne, re] = H(!1), k = e.value === void 0 ? ee : e.value, ie = B(() => new Map(p.map((e) => [e.definition.type, e])), [p]), A = lt(B(() => p.map(({ definition: e }) => e), [p]), ct), ae = B(() => Et(v(A)), [A]), oe = u(ae), se = I(() => oe.current, [oe]), ce = pi(), [le, ue] = H(null), de = le !== null && Object.is(le.value, k) && le.check === ae && le.tables === f, j = B(() => {
|
|
2654
|
+
if (!de) return typeof k == "string" && e.format !== "json" ? ce ? Ot(k, A) : void 0 : kt(k, {
|
|
2655
|
+
tables: f,
|
|
2656
|
+
blockDefinitions: A
|
|
2657
|
+
});
|
|
2658
|
+
}, [
|
|
2659
|
+
de,
|
|
2660
|
+
k,
|
|
2661
|
+
e.format,
|
|
2662
|
+
ce,
|
|
2663
|
+
f,
|
|
2664
|
+
A
|
|
2665
|
+
]), M = z(), N = s || !!j || x, P = o || !!j;
|
|
2666
|
+
P && E && D(null);
|
|
2667
|
+
let fe = I((e, t) => {
|
|
2668
|
+
if (P) return;
|
|
2669
|
+
let n = t === void 0 ? void 0 : je(e.doc.resolve(t), e.schema.marks.link), r = n && e.doc.nodeAt(n.from)?.marks.find((t) => t.type === e.schema.marks.link);
|
|
2670
|
+
D({
|
|
2671
|
+
from: n?.from ?? e.selection.from,
|
|
2672
|
+
to: n?.to ?? e.selection.to,
|
|
2673
|
+
href: r?.attrs.href ?? "",
|
|
2674
|
+
isEditing: !!r,
|
|
2675
|
+
document: e.doc
|
|
2676
|
+
});
|
|
2677
|
+
}, [P]), pe = B(() => ({
|
|
2678
|
+
role: "textbox",
|
|
2679
|
+
...y ? {} : { "aria-label": _ ?? c },
|
|
2680
|
+
"aria-multiline": "true",
|
|
2681
|
+
...m ? { id: m } : {},
|
|
2682
|
+
...y ? { "aria-labelledby": y } : {},
|
|
2683
|
+
...b ? { "aria-describedby": b } : {},
|
|
2684
|
+
...N ? { "aria-invalid": String(N) } : {},
|
|
2685
|
+
...h || g ? { "aria-required": "true" } : {}
|
|
2686
|
+
}), [
|
|
2687
|
+
c,
|
|
2688
|
+
_,
|
|
2689
|
+
m,
|
|
2690
|
+
y,
|
|
2691
|
+
b,
|
|
2692
|
+
N,
|
|
2693
|
+
h,
|
|
2694
|
+
g
|
|
2695
|
+
]), me = u({
|
|
2696
|
+
definitions: A,
|
|
2697
|
+
check: ae
|
|
2698
|
+
}), he = B(() => ({
|
|
2699
|
+
attributes: pe,
|
|
2700
|
+
handlePaste: (e, t, n) => li(t.clipboardData?.getData("text/html") ?? "", n, me.current),
|
|
2701
|
+
handleDrop: (e, t, n) => li(t.dataTransfer?.getData("text/html") ?? "", n, me.current),
|
|
2702
|
+
handleDOMEvents: {
|
|
2703
|
+
keydown: oi,
|
|
2704
|
+
click: (e, t) => {
|
|
2705
|
+
let n = t.target instanceof Element ? t.target.closest("a") : null;
|
|
2706
|
+
return !n || !e.dom.contains(n) ? !1 : (t.preventDefault(), e.editable && fe(e.state, e.posAtDOM(n, 0)), !0);
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
}), [
|
|
2710
|
+
pe,
|
|
2711
|
+
fe,
|
|
2712
|
+
me
|
|
2713
|
+
]), ge = B(() => [
|
|
2714
|
+
...St(ai, { tables: f }, Br),
|
|
2715
|
+
Ie.configure({ placeholder: r }),
|
|
2716
|
+
ci.configure({ check: se })
|
|
2717
|
+
], [
|
|
2718
|
+
r,
|
|
2719
|
+
f,
|
|
2720
|
+
se
|
|
2721
|
+
]), _e = B(() => j ? gt : typeof k == "string" ? k : wt(k), [k, j]), F = Pe({
|
|
2722
|
+
immediatelyRender: !1,
|
|
2723
|
+
editable: !P,
|
|
2724
|
+
content: _e,
|
|
2725
|
+
extensions: ge,
|
|
2726
|
+
editorProps: he,
|
|
2727
|
+
onFocus: () => T(!0),
|
|
2728
|
+
onBlur: () => T(!1),
|
|
2729
|
+
onUpdate: ({ editor: t, transaction: n }) => {
|
|
2730
|
+
if (P && !n.getMeta("ds-rte-block-commit")) return;
|
|
2731
|
+
let r = (n) => {
|
|
2732
|
+
ue({
|
|
2733
|
+
value: n,
|
|
2734
|
+
check: oe.current,
|
|
2735
|
+
tables: !!t.schema.nodes.table
|
|
2736
|
+
}), e.value === void 0 && te(n);
|
|
2737
|
+
};
|
|
2738
|
+
if (e.format === "json") {
|
|
2739
|
+
let n = t.getJSON();
|
|
2740
|
+
r(n), e.onChange?.(n);
|
|
2741
|
+
} else {
|
|
2742
|
+
e.value === void 0 && !t.schema.nodes.table && re(!0);
|
|
2743
|
+
let n = t.getHTML();
|
|
2744
|
+
r(n), e.onChange?.(n);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}, [f]), [ve, ye] = H(f);
|
|
2748
|
+
if (ve !== f) {
|
|
2749
|
+
ye(f), T(!1), re(!1);
|
|
2750
|
+
let t = si(F, e, k, ve, ne, A);
|
|
2751
|
+
t !== void 0 && te(t);
|
|
2752
|
+
}
|
|
2753
|
+
R(() => {
|
|
2754
|
+
F && !F.isDestroyed && (F.setEditable(!P, !1), F.setOptions({ editorProps: he }));
|
|
2755
|
+
}, [
|
|
2756
|
+
F,
|
|
2757
|
+
P,
|
|
2758
|
+
he
|
|
2759
|
+
]);
|
|
2760
|
+
let be = V(!1);
|
|
2761
|
+
R(() => {
|
|
2762
|
+
if (!F || F.isDestroyed) return;
|
|
2763
|
+
if (j) {
|
|
2764
|
+
be.current = !0;
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
let t = e.value ?? (be.current ? k : void 0);
|
|
2768
|
+
if (be.current = !1, t === void 0) return;
|
|
2769
|
+
let n = typeof t == "string" ? Ae(t, F.schema) : F.schema.nodeFromJSON(wt(t));
|
|
2770
|
+
n.eq(F.state.doc) || F.commands.setContent(n, { emitUpdate: !1 });
|
|
2771
|
+
}, [
|
|
2772
|
+
F,
|
|
2773
|
+
e.value,
|
|
2774
|
+
k,
|
|
2775
|
+
j
|
|
2776
|
+
]);
|
|
2777
|
+
let xe = Fe({
|
|
2778
|
+
editor: F,
|
|
2779
|
+
selector: ({ editor: e }) => e ? {
|
|
2780
|
+
active: Object.fromEntries(ni.flat().map((t) => [t.id, t.active?.(e) ?? !1])),
|
|
2781
|
+
linkActive: e.isActive("link"),
|
|
2782
|
+
tableActive: jr(e.state.selection)
|
|
2783
|
+
} : null
|
|
2784
|
+
}), L = Yt(F, j ? ei : ie, P, c), Se = dt({
|
|
2785
|
+
editor: F,
|
|
2786
|
+
disabled: P,
|
|
2787
|
+
isHeld: L.isCreating,
|
|
2788
|
+
invalid: !!N,
|
|
2789
|
+
label: _ ?? c,
|
|
2790
|
+
labelledBy: y,
|
|
2791
|
+
expandedWidth: a,
|
|
2792
|
+
frameRef: S
|
|
2793
|
+
});
|
|
2794
|
+
return /* @__PURE__ */ W(X.Provider, {
|
|
2795
|
+
value: L.context,
|
|
2796
|
+
children: /* @__PURE__ */ G(ii, {
|
|
2797
|
+
ref: C,
|
|
2798
|
+
scopeRef: S,
|
|
2799
|
+
className: l,
|
|
2800
|
+
expansion: Se,
|
|
2801
|
+
isFocused: w,
|
|
2802
|
+
disabled: P,
|
|
2803
|
+
invalid: !!N,
|
|
2804
|
+
contentError: j,
|
|
2805
|
+
errorId: M,
|
|
2806
|
+
surface: /* @__PURE__ */ G(U, { children: [/* @__PURE__ */ W(ri, {
|
|
2807
|
+
editor: F,
|
|
2808
|
+
state: xe,
|
|
2809
|
+
disabled: P,
|
|
2810
|
+
label: c,
|
|
2811
|
+
toolbarExtra: d,
|
|
2812
|
+
openLink: fe,
|
|
2813
|
+
expandControl: Se.toggle,
|
|
2814
|
+
embedControl: L.toolbar,
|
|
2815
|
+
tables: f
|
|
2816
|
+
}), /* @__PURE__ */ W("div", {
|
|
2817
|
+
className: "ds-rte__content ds-field-surface",
|
|
2818
|
+
"data-size": i,
|
|
2819
|
+
children: /* @__PURE__ */ W(we, { editor: F })
|
|
2820
|
+
})] }),
|
|
2821
|
+
children: [L.dialog, F && E && !P && /* @__PURE__ */ W(ti, {
|
|
2822
|
+
editor: F,
|
|
2823
|
+
selection: E,
|
|
2824
|
+
onClose: O
|
|
2825
|
+
})]
|
|
2826
|
+
})
|
|
2827
|
+
});
|
|
2828
|
+
});
|
|
2829
|
+
//#endregion
|
|
2830
|
+
export { In as a, Un as i, $r as n, gt as o, Zn as r, mi as t };
|
|
2831
|
+
|
|
2832
|
+
//# sourceMappingURL=RichTextEditor-DSxiMLVd.js.map
|