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