@namroodinc/liquid-editorial 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +10 -0
  2. package/UPGRADING.md +52 -0
  3. package/dist/chunks/{Board-B8wK079I.js → Board-Cnyqrc-R.js} +2 -2
  4. package/dist/chunks/{Board-B8wK079I.js.map → Board-Cnyqrc-R.js.map} +1 -1
  5. package/dist/chunks/{Board-CMf5Azt0.cjs → Board-DFuJt2Oh.cjs} +2 -2
  6. package/dist/chunks/{Board-CMf5Azt0.cjs.map → Board-DFuJt2Oh.cjs.map} +1 -1
  7. package/dist/chunks/{ColourField-C1qjpIfB.cjs → ColourField-B03ejnGS.cjs} +2 -2
  8. package/dist/chunks/{ColourField-C1qjpIfB.cjs.map → ColourField-B03ejnGS.cjs.map} +1 -1
  9. package/dist/chunks/{ColourField-Ce2oaVcd.js → ColourField-D17gkytm.js} +6 -6
  10. package/dist/chunks/{ColourField-Ce2oaVcd.js.map → ColourField-D17gkytm.js.map} +1 -1
  11. package/dist/chunks/{DatePicker-CnVmsCwO.js → DatePicker-0uvnuiye.js} +21 -21
  12. package/dist/chunks/{DatePicker-CnVmsCwO.js.map → DatePicker-0uvnuiye.js.map} +1 -1
  13. package/dist/chunks/{DatePicker-BCnzFJFF.cjs → DatePicker-CVaefhfS.cjs} +2 -2
  14. package/dist/chunks/{DatePicker-BCnzFJFF.cjs.map → DatePicker-CVaefhfS.cjs.map} +1 -1
  15. package/dist/chunks/EntryPicker-CiS8zT64.cjs +2 -0
  16. package/dist/chunks/EntryPicker-CiS8zT64.cjs.map +1 -0
  17. package/dist/chunks/EntryPicker-LWwX_EzL.js +160 -0
  18. package/dist/chunks/EntryPicker-LWwX_EzL.js.map +1 -0
  19. package/dist/chunks/FormEditor-BZ_4nxIG.cjs +2 -0
  20. package/dist/chunks/FormEditor-BZ_4nxIG.cjs.map +1 -0
  21. package/dist/chunks/{FormEditor-BEOp5EW-.js → FormEditor-IKdPwVPx.js} +112 -108
  22. package/dist/chunks/FormEditor-IKdPwVPx.js.map +1 -0
  23. package/dist/chunks/Icon-CD3oeiNA.cjs +2 -0
  24. package/dist/chunks/Icon-CD3oeiNA.cjs.map +1 -0
  25. package/dist/chunks/Icon-CYXOo0Kt.js +88 -0
  26. package/dist/chunks/Icon-CYXOo0Kt.js.map +1 -0
  27. package/dist/chunks/{Message-CaX8Y1Xb.js → Message-CyLq9ef-.js} +2 -2
  28. package/dist/chunks/{Message-CaX8Y1Xb.js.map → Message-CyLq9ef-.js.map} +1 -1
  29. package/dist/chunks/{Message-DU31JAb3.cjs → Message-D3b8HDhm.cjs} +2 -2
  30. package/dist/chunks/{Message-DU31JAb3.cjs.map → Message-D3b8HDhm.cjs.map} +1 -1
  31. package/dist/chunks/{NumberField-Ccjpa_1d.cjs → NumberField-BrWFmPkW.cjs} +2 -2
  32. package/dist/chunks/{NumberField-Ccjpa_1d.cjs.map → NumberField-BrWFmPkW.cjs.map} +1 -1
  33. package/dist/chunks/{NumberField-CVsK4l9P.js → NumberField-C90eJGny.js} +13 -13
  34. package/dist/chunks/{NumberField-CVsK4l9P.js.map → NumberField-C90eJGny.js.map} +1 -1
  35. package/dist/chunks/RichTextEditor-CwoHE-AN.js +1034 -0
  36. package/dist/chunks/RichTextEditor-CwoHE-AN.js.map +1 -0
  37. package/dist/chunks/RichTextEditor-DMrxJhA6.cjs +2 -0
  38. package/dist/chunks/RichTextEditor-DMrxJhA6.cjs.map +1 -0
  39. package/dist/chunks/use-picker-session-BLH1tXk3.js +712 -0
  40. package/dist/chunks/use-picker-session-BLH1tXk3.js.map +1 -0
  41. package/dist/chunks/use-picker-session-tRDYUd_d.cjs +2 -0
  42. package/dist/chunks/use-picker-session-tRDYUd_d.cjs.map +1 -0
  43. package/dist/components/AssetCard/index.cjs +1 -1
  44. package/dist/components/AssetCard/index.js +1 -1
  45. package/dist/components/AssetGrid/index.cjs +1 -1
  46. package/dist/components/AssetGrid/index.js +1 -1
  47. package/dist/components/Banner/index.cjs +1 -1
  48. package/dist/components/Banner/index.js +1 -1
  49. package/dist/components/Board/index.cjs +1 -1
  50. package/dist/components/Board/index.js +1 -1
  51. package/dist/components/Button/index.cjs +1 -1
  52. package/dist/components/Button/index.js +1 -1
  53. package/dist/components/ColourField/index.cjs +1 -1
  54. package/dist/components/ColourField/index.js +1 -1
  55. package/dist/components/DatePicker/index.cjs +1 -1
  56. package/dist/components/DatePicker/index.js +1 -1
  57. package/dist/components/EditLayout/index.cjs +1 -1
  58. package/dist/components/EditLayout/index.js +1 -1
  59. package/dist/components/EntryPicker/index.cjs +1 -1
  60. package/dist/components/EntryPicker/index.d.cts.map +1 -1
  61. package/dist/components/EntryPicker/index.d.ts.map +1 -1
  62. package/dist/components/EntryPicker/index.js +1 -1
  63. package/dist/components/EntryPicker/item.d.cts +3 -1
  64. package/dist/components/EntryPicker/item.d.cts.map +1 -1
  65. package/dist/components/EntryPicker/item.d.ts +3 -1
  66. package/dist/components/EntryPicker/item.d.ts.map +1 -1
  67. package/dist/components/EntryPicker/use-picker-session.d.cts +110 -0
  68. package/dist/components/EntryPicker/use-picker-session.d.cts.map +1 -0
  69. package/dist/components/EntryPicker/use-picker-session.d.ts +110 -0
  70. package/dist/components/EntryPicker/use-picker-session.d.ts.map +1 -0
  71. package/dist/components/EntryPicker/use-selected-items.d.cts +9 -2
  72. package/dist/components/EntryPicker/use-selected-items.d.cts.map +1 -1
  73. package/dist/components/EntryPicker/use-selected-items.d.ts +9 -2
  74. package/dist/components/EntryPicker/use-selected-items.d.ts.map +1 -1
  75. package/dist/components/FormEditor/README.md +106 -0
  76. package/dist/components/FormEditor/control.d.cts +3 -1
  77. package/dist/components/FormEditor/control.d.cts.map +1 -1
  78. package/dist/components/FormEditor/control.d.ts +3 -1
  79. package/dist/components/FormEditor/control.d.ts.map +1 -1
  80. package/dist/components/FormEditor/index.cjs +1 -1
  81. package/dist/components/FormEditor/index.d.cts +3 -1
  82. package/dist/components/FormEditor/index.d.cts.map +1 -1
  83. package/dist/components/FormEditor/index.d.ts +3 -1
  84. package/dist/components/FormEditor/index.d.ts.map +1 -1
  85. package/dist/components/FormEditor/index.js +1 -1
  86. package/dist/components/FormEditor/model.d.cts.map +1 -1
  87. package/dist/components/FormEditor/model.d.ts.map +1 -1
  88. package/dist/components/Icon/icons.d.cts +3 -0
  89. package/dist/components/Icon/icons.d.cts.map +1 -1
  90. package/dist/components/Icon/icons.d.ts +3 -0
  91. package/dist/components/Icon/icons.d.ts.map +1 -1
  92. package/dist/components/Icon/index.cjs +1 -1
  93. package/dist/components/Icon/index.js +1 -1
  94. package/dist/components/NumberField/index.cjs +1 -1
  95. package/dist/components/NumberField/index.js +1 -1
  96. package/dist/components/RichTextEditor/document.d.cts +7 -1
  97. package/dist/components/RichTextEditor/document.d.cts.map +1 -1
  98. package/dist/components/RichTextEditor/document.d.ts +7 -1
  99. package/dist/components/RichTextEditor/document.d.ts.map +1 -1
  100. package/dist/components/RichTextEditor/embed-context.d.cts +36 -0
  101. package/dist/components/RichTextEditor/embed-context.d.cts.map +1 -0
  102. package/dist/components/RichTextEditor/embed-context.d.ts +36 -0
  103. package/dist/components/RichTextEditor/embed-context.d.ts.map +1 -0
  104. package/dist/components/RichTextEditor/embed-types.d.cts +27 -0
  105. package/dist/components/RichTextEditor/embed-types.d.cts.map +1 -0
  106. package/dist/components/RichTextEditor/embed-types.d.ts +27 -0
  107. package/dist/components/RichTextEditor/embed-types.d.ts.map +1 -0
  108. package/dist/components/RichTextEditor/expansion.d.cts +6 -1
  109. package/dist/components/RichTextEditor/expansion.d.cts.map +1 -1
  110. package/dist/components/RichTextEditor/expansion.d.ts +6 -1
  111. package/dist/components/RichTextEditor/expansion.d.ts.map +1 -1
  112. package/dist/components/RichTextEditor/index.cjs +1 -1
  113. package/dist/components/RichTextEditor/index.d.cts +4 -0
  114. package/dist/components/RichTextEditor/index.d.cts.map +1 -1
  115. package/dist/components/RichTextEditor/index.d.ts +4 -0
  116. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  117. package/dist/components/RichTextEditor/index.js +1 -1
  118. package/dist/components/RichTextEditor/storyblock-view.d.cts +3 -0
  119. package/dist/components/RichTextEditor/storyblock-view.d.cts.map +1 -0
  120. package/dist/components/RichTextEditor/storyblock-view.d.ts +3 -0
  121. package/dist/components/RichTextEditor/storyblock-view.d.ts.map +1 -0
  122. package/dist/components/RichTextEditor/storyblock.d.cts +19 -0
  123. package/dist/components/RichTextEditor/storyblock.d.cts.map +1 -0
  124. package/dist/components/RichTextEditor/storyblock.d.ts +19 -0
  125. package/dist/components/RichTextEditor/storyblock.d.ts.map +1 -0
  126. package/dist/components/RichTextEditor/style.css +92 -0
  127. package/dist/components/RichTextEditor/use-embeds.d.cts +31 -0
  128. package/dist/components/RichTextEditor/use-embeds.d.cts.map +1 -0
  129. package/dist/components/RichTextEditor/use-embeds.d.ts +31 -0
  130. package/dist/components/RichTextEditor/use-embeds.d.ts.map +1 -0
  131. package/dist/components/SearchField/index.cjs +1 -1
  132. package/dist/components/SearchField/index.js +1 -1
  133. package/dist/components/Select/index.cjs +1 -1
  134. package/dist/components/Select/index.js +1 -1
  135. package/dist/components/SideNav/index.cjs +1 -1
  136. package/dist/components/SideNav/index.js +1 -1
  137. package/dist/components/SortableList/index.cjs +1 -1
  138. package/dist/components/SortableList/index.js +1 -1
  139. package/dist/components/Stepper/index.cjs +1 -1
  140. package/dist/components/Stepper/index.js +1 -1
  141. package/dist/components/SubNav/index.cjs +1 -1
  142. package/dist/components/SubNav/index.js +1 -1
  143. package/dist/components/Table/index.cjs +1 -1
  144. package/dist/components/Table/index.js +1 -1
  145. package/dist/components/Toast/index.cjs +1 -1
  146. package/dist/components/Toast/index.js +1 -1
  147. package/dist/components/TopNav/index.cjs +1 -1
  148. package/dist/components/TopNav/index.js +1 -1
  149. package/dist/index.cjs +1 -1
  150. package/dist/index.d.cts +1 -1
  151. package/dist/index.d.cts.map +1 -1
  152. package/dist/index.d.ts +1 -1
  153. package/dist/index.d.ts.map +1 -1
  154. package/dist/index.js +18 -18
  155. package/package.json +1 -1
  156. package/dist/chunks/EntryPicker-BhApdZtE.cjs +0 -2
  157. package/dist/chunks/EntryPicker-BhApdZtE.cjs.map +0 -1
  158. package/dist/chunks/EntryPicker-LBj_56_e.js +0 -803
  159. package/dist/chunks/EntryPicker-LBj_56_e.js.map +0 -1
  160. package/dist/chunks/FormEditor-B5A38LZ4.cjs +0 -2
  161. package/dist/chunks/FormEditor-B5A38LZ4.cjs.map +0 -1
  162. package/dist/chunks/FormEditor-BEOp5EW-.js.map +0 -1
  163. package/dist/chunks/Icon-WOhlu6Rp.cjs +0 -2
  164. package/dist/chunks/Icon-WOhlu6Rp.cjs.map +0 -1
  165. package/dist/chunks/Icon-spaFBU4S.js +0 -85
  166. package/dist/chunks/Icon-spaFBU4S.js.map +0 -1
  167. package/dist/chunks/RichTextEditor-CuZnjiy2.js +0 -483
  168. package/dist/chunks/RichTextEditor-CuZnjiy2.js.map +0 -1
  169. package/dist/chunks/RichTextEditor-DcbLho2Q.cjs +0 -2
  170. package/dist/chunks/RichTextEditor-DcbLho2Q.cjs.map +0 -1
@@ -0,0 +1,1034 @@
1
+ import { t as e } from "./Icon-CYXOo0Kt.js";
2
+ import { Button as t } from "../components/Button/index.js";
3
+ import { t as n } from "./mergeRefs-C6_5pADN.js";
4
+ import { d as r, f as i, s as a, u as o } from "./overlayLayer-IuoPVwTO.js";
5
+ import { a as s, o as c } from "./dialogLabel-D18maX-p.js";
6
+ import { t as l } from "./useIsomorphicLayoutEffect-Bc9hxFMc.js";
7
+ import { ButtonGroup as u } from "../components/ButtonGroup/index.js";
8
+ import { Badge as d } from "../components/Badge/index.js";
9
+ /* empty css */
10
+ import { Field as f } from "../components/Field/index.js";
11
+ import { Modal as p } from "../components/Modal/index.js";
12
+ import { TextField as m } from "../components/TextField/index.js";
13
+ import { Popover as h } from "../components/Popover/index.js";
14
+ import { a as g, i as _, l as v, o as y, s as b, t as x } from "./use-picker-session-BLH1tXk3.js";
15
+ import { createContext as S, forwardRef as C, useCallback as w, useContext as T, useEffect as E, useId as D, useMemo as O, useRef as k, useState as A } from "react";
16
+ import { createPortal as j } from "react-dom";
17
+ import { Fragment as M, jsx as N, jsxs as P } from "react/jsx-runtime";
18
+ import { EditorContent as ee, Node as F, NodeViewWrapper as I, ReactNodeViewRenderer as te, createDocument as ne, getMarkRange as re, getSchema as L, mergeAttributes as R, useEditor as ie, useEditorState as ae } from "@tiptap/react";
19
+ import { Placeholder as oe } from "@tiptap/extension-placeholder";
20
+ import { StarterKit as z } from "@tiptap/starter-kit";
21
+ import { Link as B } from "@tiptap/extension-link";
22
+ //#region src/components/RichTextEditor/expansion.tsx
23
+ function V(e, t) {
24
+ let n = t.querySelector(".ds-rte__content");
25
+ if (!n) return;
26
+ let r = e.view.coordsAtPos(e.state.selection.head), i = n.getBoundingClientRect();
27
+ (r.top < i.top || r.bottom > i.bottom) && (n.scrollTop += r.top - i.top - i.height / 2);
28
+ }
29
+ function se({ editor: e, disabled: n, isHeld: a = !1, invalid: o, label: u, labelledBy: d, expandedWidth: f, frameRef: m }) {
30
+ let h = c("ds-rte__host"), [g, _] = A(!1), [v, y] = A(0), b = k(null), x = k(null), S = k(null), C = k(!1), T = k(!1), E = D();
31
+ g && n && !a && _(!1);
32
+ let O = w(() => {
33
+ C.current = document.activeElement === S.current, _(!1);
34
+ }, []);
35
+ l(() => {
36
+ h && (s(h, g ? x.current : b.current), T.current !== g && (T.current = g, n || !e ? r(document.activeElement) && i(m.current, { preventScroll: !0 }) : (V(e, h), !g && C.current ? S.current?.focus() : (e.view.focus(), e.commands.scrollIntoView()), C.current = !1)));
37
+ }, [
38
+ h,
39
+ g,
40
+ e,
41
+ n,
42
+ m
43
+ ]);
44
+ let M = g ? "Collapse editor" : "Expand editor";
45
+ return {
46
+ expanded: g,
47
+ toggle: /* @__PURE__ */ N(t, {
48
+ ref: S,
49
+ size: "sm",
50
+ isIconOnly: !0,
51
+ iconStart: g ? "minimize-2" : "maximize-2",
52
+ className: "ds-rte__expand",
53
+ "aria-label": M,
54
+ title: M,
55
+ "aria-expanded": g,
56
+ "aria-controls": g ? E : void 0,
57
+ isDisabled: n || !e || !h,
58
+ onMouseDown: (e) => e.preventDefault(),
59
+ onClick: () => {
60
+ g ? O() : (y(m.current.getBoundingClientRect().height), _(!0));
61
+ }
62
+ }),
63
+ surfaceSlot: (e) => /* @__PURE__ */ N("div", {
64
+ ref: b,
65
+ className: "ds-rte__slot",
66
+ children: h ? j(e, h) : e
67
+ }),
68
+ dialog: /* @__PURE__ */ N(p, {
69
+ id: E,
70
+ isOpen: g,
71
+ onClose: O,
72
+ title: u,
73
+ hasHeader: !1,
74
+ size: f === "full" ? "full" : "wide",
75
+ className: "ds-rte__modal",
76
+ "data-invalid": o || void 0,
77
+ "aria-labelledby": d,
78
+ children: /* @__PURE__ */ N("div", {
79
+ ref: x,
80
+ className: "ds-rte__expanded-slot"
81
+ })
82
+ }),
83
+ frameStyle: g ? { minBlockSize: v } : void 0
84
+ };
85
+ }
86
+ //#endregion
87
+ //#region src/components/RichTextEditor/storyblock.ts
88
+ function H(e) {
89
+ let t = (e) => typeof e == "string" && e.trim().length > 0;
90
+ return [
91
+ "left",
92
+ "full",
93
+ "right"
94
+ ].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);
95
+ }
96
+ function U(e) {
97
+ return {
98
+ ...e,
99
+ ...e.type === "storyblock" && e.attrs ? { attrs: {
100
+ type: e.attrs.type,
101
+ ...e.attrs.type === "entry" ? {
102
+ id: e.attrs.id,
103
+ entryId: e.attrs.entryId
104
+ } : { assetId: e.attrs.assetId },
105
+ align: e.attrs.align ?? "full"
106
+ } } : {},
107
+ ...e.content ? { content: e.content.map(U) } : {}
108
+ };
109
+ }
110
+ var W = F.create({
111
+ name: "storyblock",
112
+ group: "block",
113
+ atom: !0,
114
+ draggable: !0,
115
+ selectable: !0,
116
+ marks: "",
117
+ addAttributes() {
118
+ return Object.fromEntries([
119
+ "type",
120
+ "id",
121
+ "entryId",
122
+ "assetId",
123
+ "align"
124
+ ].map((e) => [e, {
125
+ default: e === "align" ? "full" : null,
126
+ parseHTML: (t) => t.getAttribute(`data-storyblock-${e.toLowerCase()}`),
127
+ renderHTML: () => ({})
128
+ }]));
129
+ },
130
+ parseHTML() {
131
+ return [{
132
+ tag: "div[data-storyblock]",
133
+ getAttrs: (e) => H(Object.fromEntries([
134
+ "type",
135
+ "id",
136
+ "entryId",
137
+ "assetId",
138
+ "align"
139
+ ].map((t) => [t, e.getAttribute(`data-storyblock-${t.toLowerCase()}`)]))) ? null : !1
140
+ }];
141
+ },
142
+ renderHTML({ node: e, HTMLAttributes: t }) {
143
+ let n = U({
144
+ type: "storyblock",
145
+ attrs: e.attrs
146
+ }).attrs;
147
+ return ["div", R(t, {
148
+ "data-storyblock": "",
149
+ ...Object.fromEntries(Object.entries(n).map(([e, t]) => [`data-storyblock-${e.toLowerCase()}`, t]))
150
+ })];
151
+ }
152
+ }), G = {
153
+ type: "doc",
154
+ content: [{ type: "paragraph" }]
155
+ }, K = [z.configure({
156
+ link: !1,
157
+ trailingNode: { notAfter: ["paragraph", "storyblock"] }
158
+ }), B.configure({
159
+ openOnClick: !1,
160
+ autolink: !0
161
+ })];
162
+ function q(e = W) {
163
+ return [e, ...K];
164
+ }
165
+ var J = L(q());
166
+ function Y(e) {
167
+ return e.content?.length ? e : {
168
+ ...e,
169
+ content: G.content
170
+ };
171
+ }
172
+ function ce(e) {
173
+ try {
174
+ if (!e || typeof e != "object" || !("type" in e) || e.type !== "doc") throw Error();
175
+ let t = (e) => {
176
+ let n = J.nodes[e.type ?? ""];
177
+ if (!n || Object.keys(e).some((e) => ![
178
+ "type",
179
+ "attrs",
180
+ "content",
181
+ "marks",
182
+ "text"
183
+ ].includes(e)) || e.text !== void 0 && e.type !== "text" || e.attrs && Object.keys(e.attrs).some((e) => !Object.hasOwn(n.spec.attrs ?? {}, e)) || e.type === "storyblock" && (!H(e.attrs ?? {}) || e.marks?.length)) throw Error();
184
+ for (let t of e.marks ?? []) {
185
+ let e = J.marks[t.type];
186
+ 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();
187
+ }
188
+ e.content?.forEach(t);
189
+ }, n = e;
190
+ t(n), J.nodeFromJSON(Y(n)).check();
191
+ } catch {
192
+ return "Unsupported or invalid rich-text document.";
193
+ }
194
+ }
195
+ //#endregion
196
+ //#region src/components/RichTextEditor/embed-context.ts
197
+ function X(e) {
198
+ return !!(e && (e.loadPage || e.items?.length || e.onCreate));
199
+ }
200
+ var Z = S({
201
+ views: {},
202
+ disabled: !1,
203
+ busy: !1,
204
+ pickCount: 0,
205
+ replace: () => {},
206
+ seed: () => void 0,
207
+ forgetSeed: () => {}
208
+ }), Q = [], le = [
209
+ {
210
+ align: "left",
211
+ icon: "align-left",
212
+ label: "Align left"
213
+ },
214
+ {
215
+ align: "full",
216
+ icon: "align-justify",
217
+ label: "Full width"
218
+ },
219
+ {
220
+ align: "right",
221
+ icon: "align-right",
222
+ label: "Align right"
223
+ }
224
+ ];
225
+ function ue(e, t) {
226
+ let { views: n, seed: r, forgetSeed: i } = T(Z), a = n[e], o = a?.items ?? Q, s = O(() => [t], [t]), c = w((t) => r(e, t), [r, e]), l = y(s, o, a?.resolveItem, a?.refreshKey, c), u = r(e, t);
227
+ E(() => {
228
+ u && i(e, t, u);
229
+ }, [
230
+ i,
231
+ e,
232
+ t,
233
+ u
234
+ ]);
235
+ let { known: d, failures: f } = l, p = !!a?.resolveItem, m = O(() => b({
236
+ selected: s,
237
+ items: o,
238
+ pageItems: Q,
239
+ known: d,
240
+ failures: f,
241
+ hasResolver: p,
242
+ itemLabel: e
243
+ })[0], [
244
+ s,
245
+ o,
246
+ d,
247
+ f,
248
+ p,
249
+ e
250
+ ]), h = g(`Couldn't load ${e}`, l.status, l.error, l.retry), _ = o.some((e) => e.id === t);
251
+ return {
252
+ view: a,
253
+ item: m,
254
+ missing: m.tone === "removed" || !_ && d.has(t) && !d.get(t),
255
+ failure: h
256
+ };
257
+ }
258
+ function de({ kind: e }) {
259
+ return /* @__PURE__ */ N(d, {
260
+ shape: "tag",
261
+ size: "sm",
262
+ children: e
263
+ });
264
+ }
265
+ function fe({ anchorRef: e, isOpen: n, kind: r, align: i, canReplace: a, onEditItem: o, editable: s, onAlign: c, onReplace: l, onRemove: d }) {
266
+ let f = k(null);
267
+ return /* @__PURE__ */ N(h, {
268
+ anchorRef: e,
269
+ panelRef: f,
270
+ isOpen: n,
271
+ placement: "top",
272
+ align: "end",
273
+ role: "toolbar",
274
+ "aria-label": "Block actions",
275
+ className: "ds-surface-raised ds-storyblock__actions",
276
+ children: /* @__PURE__ */ P("div", {
277
+ onMouseDown: (e) => e.preventDefault(),
278
+ children: [
279
+ /* @__PURE__ */ N(u, {
280
+ "aria-label": "Alignment",
281
+ children: le.map((e) => /* @__PURE__ */ N(t, {
282
+ size: "sm",
283
+ isIconOnly: !0,
284
+ iconStart: e.icon,
285
+ "aria-label": e.label,
286
+ "aria-pressed": i === e.align,
287
+ variant: i === e.align ? "active" : "neutral",
288
+ onClick: () => c(e.align)
289
+ }, e.align))
290
+ }),
291
+ a && /* @__PURE__ */ N(t, {
292
+ variant: "simple",
293
+ size: "sm",
294
+ onClick: l,
295
+ children: "Replace"
296
+ }),
297
+ s && o && /* @__PURE__ */ N(t, {
298
+ variant: "simple",
299
+ size: "sm",
300
+ isIconOnly: !0,
301
+ iconStart: "pencil",
302
+ "aria-label": `Edit ${r}`,
303
+ onClick: () => o(s)
304
+ }),
305
+ /* @__PURE__ */ N(t, {
306
+ variant: "simple",
307
+ size: "sm",
308
+ isIconOnly: !0,
309
+ iconStart: "trash",
310
+ "aria-label": "Remove block",
311
+ title: "Remove block from this field",
312
+ onClick: d
313
+ })
314
+ ]
315
+ })
316
+ });
317
+ }
318
+ function pe({ node: t, selected: n, editor: r, getPos: i, updateAttributes: a, deleteNode: o }) {
319
+ let { disabled: s, busy: c, replace: l } = T(Z), u = t.attrs.type, d = String(u === "entry" ? t.attrs.entryId : t.attrs.assetId), { view: f, item: p, missing: m, failure: h } = ue(u, d), g = k(null), _ = t.attrs.align ?? "full", y = !m && !p.isUnavailable && !p.isDisabled;
320
+ return /* @__PURE__ */ P(I, {
321
+ ref: g,
322
+ className: "ds-storyblock",
323
+ "data-align": _,
324
+ "data-selected": n || void 0,
325
+ "data-missing": m || void 0,
326
+ contentEditable: !1,
327
+ onMouseDown: (e) => {
328
+ if (e.target instanceof Element && e.target.closest("button, [data-drag-handle]")) return;
329
+ e.preventDefault();
330
+ let t = i();
331
+ t !== void 0 && r.chain().focus().setNodeSelection(t).run();
332
+ },
333
+ children: [
334
+ /* @__PURE__ */ N("span", {
335
+ className: "ds-storyblock__grip",
336
+ "data-drag-handle": !0,
337
+ "aria-hidden": "true",
338
+ title: "Drag to move",
339
+ children: /* @__PURE__ */ N(e, {
340
+ name: "grip-vertical",
341
+ size: 16
342
+ })
343
+ }),
344
+ m ? /* @__PURE__ */ P("span", {
345
+ className: "ds-storyblock__missing",
346
+ children: [
347
+ /* @__PURE__ */ N(de, { kind: u }),
348
+ /* @__PURE__ */ N("em", { children: `Unavailable ${u}` }),
349
+ /* @__PURE__ */ N("span", { children: `This ${u} was deleted. Replace or remove it.` }),
350
+ /* @__PURE__ */ N("code", { children: d })
351
+ ]
352
+ }) : /* @__PURE__ */ N(v, {
353
+ item: p,
354
+ titlePrefix: /* @__PURE__ */ N(de, { kind: u })
355
+ }),
356
+ h,
357
+ /* @__PURE__ */ N(fe, {
358
+ anchorRef: g,
359
+ isOpen: n && !s && !f?.isDialogHidden,
360
+ kind: u,
361
+ align: _,
362
+ canReplace: !!f?.canEmbed && !c,
363
+ onEditItem: f?.onEditItem,
364
+ editable: y ? p : void 0,
365
+ onAlign: (e) => a({ align: e }),
366
+ onReplace: () => {
367
+ let e = i();
368
+ e !== void 0 && l(u, e);
369
+ },
370
+ onRemove: o
371
+ })
372
+ ]
373
+ });
374
+ }
375
+ //#endregion
376
+ //#region src/components/RichTextEditor/use-embeds.tsx
377
+ var me = "ds-rte-embed-commit", he = ["entry", "asset"], ge = {
378
+ entry: {
379
+ itemLabel: "entry",
380
+ itemsLabel: "entries"
381
+ },
382
+ asset: {
383
+ itemLabel: "asset",
384
+ itemsLabel: "assets"
385
+ }
386
+ }, _e = {}, ve = [];
387
+ function ye(e, t, n) {
388
+ return {
389
+ type: e,
390
+ align: t,
391
+ ...e === "entry" ? {
392
+ id: n.modelId,
393
+ entryId: n.id
394
+ } : { assetId: n.id }
395
+ };
396
+ }
397
+ function be(e, t) {
398
+ if (t.tone === "removed") return {
399
+ label: t.removedLabel ?? "Removed",
400
+ description: `This ${e} was removed.`
401
+ };
402
+ if (!H(ye(e, "full", t))) return {
403
+ label: "Can't embed",
404
+ description: `This ${e} has no ${e === "entry" && !t.modelId?.trim() ? "model API ID" : "ID"}.`
405
+ };
406
+ }
407
+ var xe = {
408
+ entry: (e) => be("entry", e),
409
+ asset: (e) => be("asset", e)
410
+ };
411
+ function Se(e, t) {
412
+ return e?.type.name === "storyblock" && e.attrs.type === t.kind && String(t.kind === "entry" ? e.attrs.entryId : e.attrs.assetId) === t.replaceId;
413
+ }
414
+ function Ce(e) {
415
+ return e.flatMap((e) => e.mapping.maps);
416
+ }
417
+ function we(e, t) {
418
+ let n = t;
419
+ for (let t of Ce(e)) {
420
+ let e = n, r;
421
+ if (t.forEach((t, n, i, a) => {
422
+ r === void 0 && t <= e && e < n && n - t === a - i && (r = i + (e - t));
423
+ }), r !== void 0) {
424
+ n = r;
425
+ continue;
426
+ }
427
+ let i = t.mapResult(e, 1);
428
+ if (i.deletedAfter) return null;
429
+ n = i.pos;
430
+ }
431
+ return n;
432
+ }
433
+ function Te(e, t, n) {
434
+ let r = t, i = n;
435
+ for (let t of Ce(e)) {
436
+ if (r === i) {
437
+ r = i = t.map(i, -1);
438
+ continue;
439
+ }
440
+ let e = !1;
441
+ if (t.forEach((t, n, a, o) => {
442
+ let s = i - r === 1 && t === r && n === i && o - a === 1;
443
+ e ||= t <= r && i <= n && !s;
444
+ }), r = t.map(r, 1), i = t.map(i, -1), e || i <= r) return null;
445
+ }
446
+ return {
447
+ from: r,
448
+ to: i
449
+ };
450
+ }
451
+ function Ee(e, t) {
452
+ let n = e.resolve(Math.min(t, e.content.size));
453
+ return n.depth ? n.after(1) : n.pos;
454
+ }
455
+ function De(e, t, n) {
456
+ let r = e !== void 0, i = !!e?.resolveItem, a = !!e?.onEditItem, o = e?.refreshKey, s = e?.items, c = !!e?.isDialogHidden, l = X(e);
457
+ return O(() => r ? {
458
+ resolveItem: i ? t : void 0,
459
+ refreshKey: o,
460
+ items: s,
461
+ isDialogHidden: c,
462
+ canEmbed: l,
463
+ onEditItem: a ? n : void 0
464
+ } : void 0, [
465
+ r,
466
+ i,
467
+ a,
468
+ o,
469
+ s,
470
+ c,
471
+ l,
472
+ t,
473
+ n
474
+ ]);
475
+ }
476
+ function Oe({ session: e, source: t, disabled: n, label: r, close: i, target: a, pick: o }) {
477
+ let { itemLabel: s, itemsLabel: c } = ge[e.kind], l = O(() => e.replaceId ? [e.replaceId] : [], [e]), u = x(l, t.items ?? ve, {
478
+ ...t,
479
+ resolveItem: void 0,
480
+ mode: "single"
481
+ }, {
482
+ isOpen: !0,
483
+ isDisabled: n,
484
+ itemLabel: s,
485
+ itemsLabel: c,
486
+ close: i,
487
+ restrict: xe[e.kind]
488
+ }), d = e.replaceId ? "Replace" : "Embed";
489
+ return /* @__PURE__ */ N(_, {
490
+ ...u.dialog,
491
+ isOpen: !0,
492
+ onClose: i,
493
+ onToggle: (e) => {
494
+ let t = u.choice(e);
495
+ t && o(t, u.revision);
496
+ },
497
+ addLabel: `${d} ${s}`,
498
+ onCreate: t.onCreate ? () => t.onCreate?.(a) : void 0,
499
+ isCreating: t.isCreating,
500
+ dialogTitle: t.dialogTitle,
501
+ dialogDescription: `Choose one ${s} to embed in ${r}. ${t.dialogDescription ?? ""}`.trim(),
502
+ isDialogHidden: t.isDialogHidden
503
+ });
504
+ }
505
+ function ke(e, n = _e, r, i) {
506
+ let [a, s] = A(null), c = k(0), l = k({
507
+ session: null,
508
+ from: 0,
509
+ to: 0,
510
+ alive: !1
511
+ }), d = k(/* @__PURE__ */ new Map()), [f, p] = A(0), m = w(() => {
512
+ l.current.alive = !1, s(null);
513
+ }, []), h = a ? n[a.kind] : void 0, g = a && X(h) && (!r || h?.isCreating) ? a : null;
514
+ a && !g && s(null);
515
+ let _ = !!(g && (h?.isDialogHidden || h?.isCreating)), v = o({
516
+ editor: e,
517
+ sources: n,
518
+ disabled: r,
519
+ busy: _
520
+ });
521
+ E(() => {
522
+ if (!e || !a) return;
523
+ l.current.alive = !0;
524
+ let t = ({ editor: e, transaction: t, appendedTransactions: n }) => {
525
+ let r = [t, ...n];
526
+ if (!l.current.alive || !r.some((e) => e.docChanged)) return;
527
+ let { from: i, to: o } = l.current;
528
+ if (a.replaceId === void 0) {
529
+ let e = Te(r, i, o);
530
+ e ? Object.assign(l.current, e) : m();
531
+ return;
532
+ }
533
+ let s = we(r, i);
534
+ s === null || !Se(e.state.doc.nodeAt(s), a) ? m() : Object.assign(l.current, {
535
+ from: s,
536
+ to: s + 1
537
+ });
538
+ };
539
+ return e.on("transaction", t), () => {
540
+ e.off("transaction", t), l.current.session === a && (l.current.alive = !1);
541
+ };
542
+ }, [
543
+ e,
544
+ a,
545
+ m
546
+ ]);
547
+ let y = (e) => {
548
+ let { editor: t, sources: n, disabled: r } = v.current, i = n[e.kind];
549
+ return !(!t || t.isDestroyed || l.current.session !== e || !l.current.alive || !X(i) || r && !i?.isCreating);
550
+ }, b = (e, t, n) => {
551
+ let r = v.current.editor;
552
+ if (!r || !y(e) || t.isDisabled || t.tone === "removed") return !1;
553
+ let { doc: i } = r.state, a = e.replaceId !== void 0, o = a ? i.nodeAt(l.current.from) : null;
554
+ if (a && !Se(o, e)) return !1;
555
+ let s = ye(e.kind, o?.attrs.align ?? "full", t);
556
+ if (!H(s)) return !1;
557
+ let c = a ? l.current.from : Ee(i, l.current.to), u = `${e.kind}:${t.id}`;
558
+ l.current.alive = !1, d.current = /* @__PURE__ */ new Map([[u, {
559
+ item: t,
560
+ revision: n
561
+ }]]);
562
+ let f = !1;
563
+ try {
564
+ let e = r.chain().focus().setMeta(me, !0);
565
+ f = a ? e.setNodeSelection(c).updateAttributes("storyblock", s).run() : e.insertContentAt(c, {
566
+ type: "storyblock",
567
+ attrs: s
568
+ }).setNodeSelection(c).run();
569
+ } catch {
570
+ f = !1;
571
+ } finally {
572
+ m();
573
+ }
574
+ return f ? p((e) => e + 1) : d.current.delete(u), f;
575
+ }, x = (e, t) => {
576
+ let { editor: n, sources: r, disabled: i, busy: a } = v.current;
577
+ if (!n || i || a || !X(r[e])) return;
578
+ let o = t === void 0 ? null : n.state.doc.nodeAt(t);
579
+ if (t !== void 0 && (o?.type.name !== "storyblock" || o.attrs.type !== e)) return;
580
+ let { $from: u, from: d, to: f } = n.state.selection, p = {
581
+ id: c.current += 1,
582
+ kind: e,
583
+ replaceId: o ? String(e === "entry" ? o.attrs.entryId : o.attrs.assetId) : void 0
584
+ }, m = t === void 0 ? u.depth ? {
585
+ from: u.before(1),
586
+ to: u.after(1)
587
+ } : {
588
+ from: d,
589
+ to: f
590
+ } : {
591
+ from: t,
592
+ to: t + 1
593
+ };
594
+ l.current = {
595
+ session: p,
596
+ ...m,
597
+ alive: !0
598
+ }, s(p);
599
+ }, S = o({ open: x }), [C] = A(() => ({
600
+ replace: (e, t) => S.current.open(e, t),
601
+ seed: (e, t) => d.current.get(`${e}:${t}`),
602
+ forgetSeed: (e, t, n) => {
603
+ d.current.get(`${e}:${t}`) === n && d.current.delete(`${e}:${t}`);
604
+ },
605
+ resolve: {
606
+ entry: (e) => v.current.sources.entry?.resolveItem?.(e) ?? null,
607
+ asset: (e) => v.current.sources.asset?.resolveItem?.(e) ?? null
608
+ },
609
+ edit: {
610
+ entry: (e) => {
611
+ v.current.sources.entry?.onEditItem?.(e);
612
+ },
613
+ asset: (e) => {
614
+ v.current.sources.asset?.onEditItem?.(e);
615
+ }
616
+ }
617
+ })), T = De(n.entry, C.resolve.entry, C.edit.entry), D = De(n.asset, C.resolve.asset, C.edit.asset), j = O(() => ({
618
+ views: {
619
+ entry: T,
620
+ asset: D
621
+ },
622
+ disabled: r,
623
+ busy: _,
624
+ pickCount: f,
625
+ replace: C.replace,
626
+ seed: C.seed,
627
+ forgetSeed: C.forgetSeed
628
+ }), [
629
+ T,
630
+ D,
631
+ r,
632
+ _,
633
+ f,
634
+ C
635
+ ]), M = he.filter((e) => X(n[e]));
636
+ return {
637
+ context: j,
638
+ isCreating: he.some((e) => n[e]?.isCreating),
639
+ toolbar: M.length > 0 && /* @__PURE__ */ N(u, {
640
+ "aria-label": "Embed",
641
+ children: M.map((n) => /* @__PURE__ */ N(t, {
642
+ size: "sm",
643
+ isIconOnly: !0,
644
+ iconStart: n === "entry" ? "file-text" : "image",
645
+ "aria-label": `Embed ${n}`,
646
+ title: `Embed ${n}`,
647
+ "aria-pressed": g?.kind === n,
648
+ variant: g?.kind === n ? "active" : "neutral",
649
+ isDisabled: r || _ || !e,
650
+ onClick: () => x(n)
651
+ }, n))
652
+ }),
653
+ dialog: e && g && h && /* @__PURE__ */ N(Oe, {
654
+ session: g,
655
+ source: h,
656
+ disabled: r,
657
+ label: i,
658
+ close: m,
659
+ target: {
660
+ available: () => y(g),
661
+ commit: (e) => b(g, e, v.current.sources[g.kind]?.refreshKey)
662
+ },
663
+ pick: (e, t) => b(g, e, t)
664
+ }, g.id)
665
+ };
666
+ }
667
+ //#endregion
668
+ //#region src/components/RichTextEditor/index.tsx
669
+ function Ae({ editor: e, selection: n, onClose: r }) {
670
+ let [i, a] = A(n.href), [o, s] = A(), c = D();
671
+ E(() => {
672
+ let t = () => {
673
+ e.state.doc.eq(n.document) || r();
674
+ };
675
+ return e.on("transaction", t), () => {
676
+ e.off("transaction", t);
677
+ };
678
+ }, [
679
+ e,
680
+ n,
681
+ r
682
+ ]);
683
+ let l = () => !e.isDestroyed && e.isEditable && e.state.doc.eq(n.document), u = () => {
684
+ if (!l()) {
685
+ r();
686
+ return;
687
+ }
688
+ let t = i.trim();
689
+ if (!t || !e.can().setLink({ href: t })) {
690
+ s(t ? "Enter a valid link URL." : "Enter a link URL.");
691
+ return;
692
+ }
693
+ let a = e.chain().focus().setTextSelection({
694
+ from: n.from,
695
+ to: n.to
696
+ });
697
+ n.from === n.to && !n.isEditing ? a.setLink({ href: t }).insertContent({
698
+ type: "text",
699
+ text: t,
700
+ marks: [{
701
+ type: "link",
702
+ attrs: { href: t }
703
+ }]
704
+ }).run() : a.setLink({ href: t }).run(), r();
705
+ };
706
+ return /* @__PURE__ */ N(p, {
707
+ isOpen: !0,
708
+ title: n.isEditing ? "Edit link" : "Add link",
709
+ size: "dialog",
710
+ onClose: r,
711
+ footer: /* @__PURE__ */ P(M, { children: [
712
+ n.isEditing && /* @__PURE__ */ N(t, {
713
+ variant: "danger",
714
+ onClick: () => {
715
+ l() && e.chain().focus().setTextSelection({
716
+ from: n.from,
717
+ to: n.to
718
+ }).unsetLink().run(), r();
719
+ },
720
+ children: "Remove link"
721
+ }),
722
+ /* @__PURE__ */ N(t, {
723
+ onClick: r,
724
+ children: "Cancel"
725
+ }),
726
+ /* @__PURE__ */ N(t, {
727
+ variant: "primary",
728
+ type: "submit",
729
+ form: c,
730
+ children: "Save"
731
+ })
732
+ ] }),
733
+ children: /* @__PURE__ */ N("form", {
734
+ id: c,
735
+ noValidate: !0,
736
+ onSubmit: (e) => {
737
+ e.preventDefault(), e.stopPropagation(), u();
738
+ },
739
+ children: /* @__PURE__ */ N(f, {
740
+ label: "URL",
741
+ isRequired: !0,
742
+ error: o,
743
+ children: (e) => /* @__PURE__ */ N(m, {
744
+ ...e,
745
+ value: i,
746
+ inputMode: "url",
747
+ autoComplete: "url",
748
+ placeholder: "https://example.com",
749
+ onChange: (e) => {
750
+ a(e.target.value), s(void 0);
751
+ }
752
+ })
753
+ })
754
+ })
755
+ });
756
+ }
757
+ var $ = [
758
+ [
759
+ {
760
+ id: "bold",
761
+ icon: "bold",
762
+ label: "Bold",
763
+ run: (e) => e.chain().focus().toggleBold().run(),
764
+ active: (e) => e.isActive("bold")
765
+ },
766
+ {
767
+ id: "italic",
768
+ icon: "italic",
769
+ label: "Italic",
770
+ run: (e) => e.chain().focus().toggleItalic().run(),
771
+ active: (e) => e.isActive("italic")
772
+ },
773
+ {
774
+ id: "strike",
775
+ icon: "strikethrough",
776
+ label: "Strikethrough",
777
+ run: (e) => e.chain().focus().toggleStrike().run(),
778
+ active: (e) => e.isActive("strike")
779
+ },
780
+ {
781
+ id: "code",
782
+ icon: "code",
783
+ label: "Inline code",
784
+ run: (e) => e.chain().focus().toggleCode().run(),
785
+ active: (e) => e.isActive("code")
786
+ }
787
+ ],
788
+ [
789
+ {
790
+ id: "h2",
791
+ icon: "heading-2",
792
+ label: "Heading",
793
+ run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),
794
+ active: (e) => e.isActive("heading", { level: 2 })
795
+ },
796
+ {
797
+ id: "h3",
798
+ icon: "heading-3",
799
+ label: "Subheading",
800
+ run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),
801
+ active: (e) => e.isActive("heading", { level: 3 })
802
+ },
803
+ {
804
+ id: "quote",
805
+ icon: "quote",
806
+ label: "Quote",
807
+ run: (e) => e.chain().focus().toggleBlockquote().run(),
808
+ active: (e) => e.isActive("blockquote")
809
+ }
810
+ ],
811
+ [{
812
+ id: "ul",
813
+ icon: "list",
814
+ label: "Bulleted list",
815
+ run: (e) => e.chain().focus().toggleBulletList().run(),
816
+ active: (e) => e.isActive("bulletList")
817
+ }, {
818
+ id: "ol",
819
+ icon: "list-ordered",
820
+ label: "Numbered list",
821
+ run: (e) => e.chain().focus().toggleOrderedList().run(),
822
+ active: (e) => e.isActive("orderedList")
823
+ }],
824
+ [{
825
+ id: "undo",
826
+ icon: "undo",
827
+ label: "Undo",
828
+ run: (e) => e.chain().focus().undo().run()
829
+ }, {
830
+ id: "redo",
831
+ icon: "redo",
832
+ label: "Redo",
833
+ run: (e) => e.chain().focus().redo().run()
834
+ }]
835
+ ];
836
+ function je({ editor: e, state: n, disabled: r, label: i, toolbarExtra: a, openLink: o, expandControl: s, embedControl: c }) {
837
+ return /* @__PURE__ */ P("div", {
838
+ className: "ds-rte__toolbar",
839
+ role: "toolbar",
840
+ "aria-label": `${i} formatting`,
841
+ children: [
842
+ $.map((i, a) => /* @__PURE__ */ N(u, {
843
+ "aria-label": `Formatting ${a + 1}`,
844
+ children: i.map((i) => /* @__PURE__ */ N(t, {
845
+ size: "sm",
846
+ isIconOnly: !0,
847
+ iconStart: i.icon,
848
+ "aria-label": i.label,
849
+ title: i.label,
850
+ "aria-pressed": i.active ? n?.active[i.id] : void 0,
851
+ variant: n?.active[i.id] ? "active" : "neutral",
852
+ isDisabled: r || !e,
853
+ onClick: () => e && i.run(e)
854
+ }, i.id))
855
+ }, a)),
856
+ /* @__PURE__ */ N(u, {
857
+ "aria-label": "Link",
858
+ children: /* @__PURE__ */ N(t, {
859
+ size: "sm",
860
+ isIconOnly: !0,
861
+ iconStart: "link",
862
+ "aria-label": n?.linkActive ? "Edit link" : "Add link",
863
+ title: n?.linkActive ? "Edit link" : "Add link",
864
+ variant: n?.linkActive ? "active" : "neutral",
865
+ isDisabled: r || !e,
866
+ onClick: () => e && o(e.state, e.isActive("link") ? e.state.selection.from : void 0)
867
+ })
868
+ }),
869
+ c,
870
+ a,
871
+ s
872
+ ]
873
+ });
874
+ }
875
+ var Me = C(function({ scopeRef: e, className: t, expansion: n, isFocused: r, disabled: i, invalid: o, contentError: s, errorId: c, surface: l, children: u }, d) {
876
+ return /* @__PURE__ */ N(a.Provider, {
877
+ value: e,
878
+ children: /* @__PURE__ */ P("div", {
879
+ ref: d,
880
+ className: ["ds-rte", t].filter(Boolean).join(" "),
881
+ style: n.frameStyle,
882
+ "data-expanded": n.expanded || void 0,
883
+ "data-focused": r && !n.expanded || void 0,
884
+ "data-disabled": i || void 0,
885
+ "aria-invalid": o || void 0,
886
+ children: [
887
+ s && /* @__PURE__ */ N("p", {
888
+ id: c,
889
+ role: "alert",
890
+ className: "ds-field__error",
891
+ children: s
892
+ }),
893
+ n.expanded && /* @__PURE__ */ N("p", {
894
+ className: "ds-rte__placeholder",
895
+ children: "Editing in expanded view. Press Esc to return."
896
+ }),
897
+ n.surfaceSlot(/* @__PURE__ */ N("div", {
898
+ className: "ds-rte__surface",
899
+ hidden: !!s,
900
+ "data-invalid": o || void 0,
901
+ children: l
902
+ })),
903
+ n.dialog,
904
+ u
905
+ ]
906
+ })
907
+ });
908
+ }), Ne = W.extend({ addNodeView() {
909
+ return te(pe, { update: ({ oldNode: e, newNode: t, updateProps: n }) => e.attrs.type === t.attrs.type && (e !== t && n(), !0) });
910
+ } });
911
+ function Pe(e, t) {
912
+ return t.key !== "Escape" || t.isComposing ? !1 : (e.someProp("handleKeyDown", (n) => n(e, t)) && t.preventDefault(), !0);
913
+ }
914
+ var Fe = C(function(e, t) {
915
+ 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, id: d, isRequired: f, required: p, "aria-label": m, "aria-labelledby": h, "aria-describedby": g, "aria-invalid": _ } = e, v = k(null), y = O(() => n(v, t), [t]), [b, x] = A(!1), [S, C] = A(null), T = w(() => C(null), []), [j] = A(() => e.defaultValue ?? (e.format === "json" ? G : "")), F = e.value === void 0 ? j : e.value, I = O(() => e.format === "json" ? ce(F) : void 0, [e.format, F]), te = D(), L = s || !!I || _, R = o || !!I;
916
+ R && S && C(null);
917
+ let z = w((e, t) => {
918
+ if (R) return;
919
+ let n = t === void 0 ? void 0 : re(e.doc.resolve(t), e.schema.marks.link), r = n && e.doc.nodeAt(n.from)?.marks.find((t) => t.type === e.schema.marks.link);
920
+ C({
921
+ from: n?.from ?? e.selection.from,
922
+ to: n?.to ?? e.selection.to,
923
+ href: r?.attrs.href ?? "",
924
+ isEditing: !!r,
925
+ document: e.doc
926
+ });
927
+ }, [R]), B = O(() => ({
928
+ role: "textbox",
929
+ ...h ? {} : { "aria-label": m ?? c },
930
+ "aria-multiline": "true",
931
+ ...d ? { id: d } : {},
932
+ ...h ? { "aria-labelledby": h } : {},
933
+ ...g ? { "aria-describedby": g } : {},
934
+ ...L ? { "aria-invalid": String(L) } : {},
935
+ ...f || p ? { "aria-required": "true" } : {}
936
+ }), [
937
+ c,
938
+ m,
939
+ d,
940
+ h,
941
+ g,
942
+ L,
943
+ f,
944
+ p
945
+ ]), V = O(() => ({
946
+ attributes: B,
947
+ handleDOMEvents: {
948
+ keydown: Pe,
949
+ click: (e, t) => {
950
+ let n = t.target instanceof Element ? t.target.closest("a") : null;
951
+ return !n || !e.dom.contains(n) ? !1 : (t.preventDefault(), e.editable && z(e.state, e.posAtDOM(n, 0)), !0);
952
+ }
953
+ }
954
+ }), [B, z]), H = O(() => [...q(Ne), oe.configure({ placeholder: r })], [r]), W = O(() => I ? G : typeof F == "string" ? F : Y(F), [F, I]), K = ie({
955
+ immediatelyRender: !1,
956
+ editable: !R,
957
+ content: W,
958
+ extensions: H,
959
+ editorProps: V,
960
+ onFocus: () => x(!0),
961
+ onBlur: () => x(!1),
962
+ onUpdate: ({ editor: t, transaction: n }) => {
963
+ (!R || n.getMeta("ds-rte-embed-commit")) && (e.format === "json" ? e.onChange?.(U(t.getJSON())) : e.onChange?.(t.getHTML()));
964
+ }
965
+ });
966
+ E(() => {
967
+ K && (K.setEditable(!R, !1), K.setOptions({ editorProps: V }));
968
+ }, [
969
+ K,
970
+ R,
971
+ V
972
+ ]), E(() => {
973
+ if (!K || e.value === void 0 || I) return;
974
+ let t = typeof e.value == "string" ? ne(e.value, K.schema) : K.schema.nodeFromJSON(Y(e.value));
975
+ t.eq(K.state.doc) || K.commands.setContent(t, { emitUpdate: !1 });
976
+ }, [
977
+ K,
978
+ e.value,
979
+ I
980
+ ]);
981
+ let J = ae({
982
+ editor: K,
983
+ selector: ({ editor: e }) => e ? {
984
+ active: Object.fromEntries($.flat().map((t) => [t.id, t.active?.(e) ?? !1])),
985
+ linkActive: e.isActive("link")
986
+ } : null
987
+ }), X = ke(K, I ? void 0 : e.embeds, R, c), Q = se({
988
+ editor: K,
989
+ disabled: R,
990
+ isHeld: X.isCreating,
991
+ invalid: !!L,
992
+ label: m ?? c,
993
+ labelledBy: h,
994
+ expandedWidth: a,
995
+ frameRef: v
996
+ });
997
+ return /* @__PURE__ */ N(Z.Provider, {
998
+ value: X.context,
999
+ children: /* @__PURE__ */ P(Me, {
1000
+ ref: y,
1001
+ scopeRef: v,
1002
+ className: l,
1003
+ expansion: Q,
1004
+ isFocused: b,
1005
+ disabled: R,
1006
+ invalid: !!L,
1007
+ contentError: I,
1008
+ errorId: te,
1009
+ surface: /* @__PURE__ */ P(M, { children: [/* @__PURE__ */ N(je, {
1010
+ editor: K,
1011
+ state: J,
1012
+ disabled: R,
1013
+ label: c,
1014
+ toolbarExtra: u,
1015
+ openLink: z,
1016
+ expandControl: Q.toggle,
1017
+ embedControl: X.toolbar
1018
+ }), /* @__PURE__ */ N("div", {
1019
+ className: "ds-rte__content",
1020
+ "data-size": i,
1021
+ children: /* @__PURE__ */ N(ee, { editor: K })
1022
+ })] }),
1023
+ children: [X.dialog, K && S && !R && /* @__PURE__ */ N(Ae, {
1024
+ editor: K,
1025
+ selection: S,
1026
+ onClose: T
1027
+ })]
1028
+ })
1029
+ });
1030
+ });
1031
+ //#endregion
1032
+ export { ce as n, G as r, Fe as t };
1033
+
1034
+ //# sourceMappingURL=RichTextEditor-CwoHE-AN.js.map