@namroodinc/liquid-editorial 0.10.0 → 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 (171) hide show
  1. package/README.md +10 -0
  2. package/UPGRADING.md +54 -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/style.css +0 -4
  68. package/dist/components/EntryPicker/use-picker-session.d.cts +110 -0
  69. package/dist/components/EntryPicker/use-picker-session.d.cts.map +1 -0
  70. package/dist/components/EntryPicker/use-picker-session.d.ts +110 -0
  71. package/dist/components/EntryPicker/use-picker-session.d.ts.map +1 -0
  72. package/dist/components/EntryPicker/use-selected-items.d.cts +9 -2
  73. package/dist/components/EntryPicker/use-selected-items.d.cts.map +1 -1
  74. package/dist/components/EntryPicker/use-selected-items.d.ts +9 -2
  75. package/dist/components/EntryPicker/use-selected-items.d.ts.map +1 -1
  76. package/dist/components/FormEditor/README.md +106 -0
  77. package/dist/components/FormEditor/control.d.cts +3 -1
  78. package/dist/components/FormEditor/control.d.cts.map +1 -1
  79. package/dist/components/FormEditor/control.d.ts +3 -1
  80. package/dist/components/FormEditor/control.d.ts.map +1 -1
  81. package/dist/components/FormEditor/index.cjs +1 -1
  82. package/dist/components/FormEditor/index.d.cts +3 -1
  83. package/dist/components/FormEditor/index.d.cts.map +1 -1
  84. package/dist/components/FormEditor/index.d.ts +3 -1
  85. package/dist/components/FormEditor/index.d.ts.map +1 -1
  86. package/dist/components/FormEditor/index.js +1 -1
  87. package/dist/components/FormEditor/model.d.cts.map +1 -1
  88. package/dist/components/FormEditor/model.d.ts.map +1 -1
  89. package/dist/components/Icon/icons.d.cts +3 -0
  90. package/dist/components/Icon/icons.d.cts.map +1 -1
  91. package/dist/components/Icon/icons.d.ts +3 -0
  92. package/dist/components/Icon/icons.d.ts.map +1 -1
  93. package/dist/components/Icon/index.cjs +1 -1
  94. package/dist/components/Icon/index.js +1 -1
  95. package/dist/components/NumberField/index.cjs +1 -1
  96. package/dist/components/NumberField/index.js +1 -1
  97. package/dist/components/RichTextEditor/document.d.cts +7 -1
  98. package/dist/components/RichTextEditor/document.d.cts.map +1 -1
  99. package/dist/components/RichTextEditor/document.d.ts +7 -1
  100. package/dist/components/RichTextEditor/document.d.ts.map +1 -1
  101. package/dist/components/RichTextEditor/embed-context.d.cts +36 -0
  102. package/dist/components/RichTextEditor/embed-context.d.cts.map +1 -0
  103. package/dist/components/RichTextEditor/embed-context.d.ts +36 -0
  104. package/dist/components/RichTextEditor/embed-context.d.ts.map +1 -0
  105. package/dist/components/RichTextEditor/embed-types.d.cts +27 -0
  106. package/dist/components/RichTextEditor/embed-types.d.cts.map +1 -0
  107. package/dist/components/RichTextEditor/embed-types.d.ts +27 -0
  108. package/dist/components/RichTextEditor/embed-types.d.ts.map +1 -0
  109. package/dist/components/RichTextEditor/expansion.d.cts +6 -1
  110. package/dist/components/RichTextEditor/expansion.d.cts.map +1 -1
  111. package/dist/components/RichTextEditor/expansion.d.ts +6 -1
  112. package/dist/components/RichTextEditor/expansion.d.ts.map +1 -1
  113. package/dist/components/RichTextEditor/index.cjs +1 -1
  114. package/dist/components/RichTextEditor/index.d.cts +4 -0
  115. package/dist/components/RichTextEditor/index.d.cts.map +1 -1
  116. package/dist/components/RichTextEditor/index.d.ts +4 -0
  117. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  118. package/dist/components/RichTextEditor/index.js +1 -1
  119. package/dist/components/RichTextEditor/storyblock-view.d.cts +3 -0
  120. package/dist/components/RichTextEditor/storyblock-view.d.cts.map +1 -0
  121. package/dist/components/RichTextEditor/storyblock-view.d.ts +3 -0
  122. package/dist/components/RichTextEditor/storyblock-view.d.ts.map +1 -0
  123. package/dist/components/RichTextEditor/storyblock.d.cts +19 -0
  124. package/dist/components/RichTextEditor/storyblock.d.cts.map +1 -0
  125. package/dist/components/RichTextEditor/storyblock.d.ts +19 -0
  126. package/dist/components/RichTextEditor/storyblock.d.ts.map +1 -0
  127. package/dist/components/RichTextEditor/style.css +92 -0
  128. package/dist/components/RichTextEditor/use-embeds.d.cts +31 -0
  129. package/dist/components/RichTextEditor/use-embeds.d.cts.map +1 -0
  130. package/dist/components/RichTextEditor/use-embeds.d.ts +31 -0
  131. package/dist/components/RichTextEditor/use-embeds.d.ts.map +1 -0
  132. package/dist/components/SearchField/index.cjs +1 -1
  133. package/dist/components/SearchField/index.js +1 -1
  134. package/dist/components/Select/index.cjs +1 -1
  135. package/dist/components/Select/index.js +1 -1
  136. package/dist/components/SideNav/index.cjs +1 -1
  137. package/dist/components/SideNav/index.js +1 -1
  138. package/dist/components/SortableList/index.cjs +1 -1
  139. package/dist/components/SortableList/index.js +1 -1
  140. package/dist/components/Stepper/index.cjs +1 -1
  141. package/dist/components/Stepper/index.js +1 -1
  142. package/dist/components/SubNav/index.cjs +1 -1
  143. package/dist/components/SubNav/index.js +1 -1
  144. package/dist/components/Table/index.cjs +1 -1
  145. package/dist/components/Table/index.js +1 -1
  146. package/dist/components/Toast/index.cjs +1 -1
  147. package/dist/components/Toast/index.js +1 -1
  148. package/dist/components/TopNav/index.cjs +1 -1
  149. package/dist/components/TopNav/index.js +1 -1
  150. package/dist/index.cjs +1 -1
  151. package/dist/index.d.cts +1 -1
  152. package/dist/index.d.cts.map +1 -1
  153. package/dist/index.d.ts +1 -1
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +18 -18
  156. package/package.json +1 -1
  157. package/dist/chunks/EntryPicker-BhApdZtE.cjs +0 -2
  158. package/dist/chunks/EntryPicker-BhApdZtE.cjs.map +0 -1
  159. package/dist/chunks/EntryPicker-LBj_56_e.js +0 -803
  160. package/dist/chunks/EntryPicker-LBj_56_e.js.map +0 -1
  161. package/dist/chunks/FormEditor-B5A38LZ4.cjs +0 -2
  162. package/dist/chunks/FormEditor-B5A38LZ4.cjs.map +0 -1
  163. package/dist/chunks/FormEditor-BEOp5EW-.js.map +0 -1
  164. package/dist/chunks/Icon-WOhlu6Rp.cjs +0 -2
  165. package/dist/chunks/Icon-WOhlu6Rp.cjs.map +0 -1
  166. package/dist/chunks/Icon-spaFBU4S.js +0 -85
  167. package/dist/chunks/Icon-spaFBU4S.js.map +0 -1
  168. package/dist/chunks/RichTextEditor-CuZnjiy2.js +0 -483
  169. package/dist/chunks/RichTextEditor-CuZnjiy2.js.map +0 -1
  170. package/dist/chunks/RichTextEditor-DcbLho2Q.cjs +0 -2
  171. package/dist/chunks/RichTextEditor-DcbLho2Q.cjs.map +0 -1
@@ -0,0 +1,712 @@
1
+ import { t as e } from "./Icon-CYXOo0Kt.js";
2
+ import { Button as t } from "../components/Button/index.js";
3
+ import { d as n, h as r, u as i } from "./overlayLayer-IuoPVwTO.js";
4
+ import { Badge as a } from "../components/Badge/index.js";
5
+ import { r as o } from "./limit-s9zfxIMC.js";
6
+ import { LimitReading as s } from "../components/LimitReading/index.js";
7
+ import { Modal as c } from "../components/Modal/index.js";
8
+ import { n as l, r as u, t as d } from "./LoadState-B056EPu7.js";
9
+ import { SearchField as f } from "../components/SearchField/index.js";
10
+ import { Checkbox as p } from "../components/Choice/index.js";
11
+ import { useEffect as m, useId as h, useMemo as g, useRef as _, useState as v } from "react";
12
+ import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
13
+ //#region src/components/EntryPicker/item.tsx
14
+ function S(e) {
15
+ return e.isDisabled ? e.disabledReason : void 0;
16
+ }
17
+ function C(e) {
18
+ return e.tone === "removed";
19
+ }
20
+ function w(e) {
21
+ return C(e) ? void 0 : S(e);
22
+ }
23
+ function T({ item: t, reasonId: n, titlePrefix: r }) {
24
+ let i = S(t);
25
+ return /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b("span", {
26
+ className: "ds-entry__thumb",
27
+ children: t.imageUrl ? /* @__PURE__ */ b("img", {
28
+ src: t.imageUrl,
29
+ alt: "",
30
+ loading: "lazy"
31
+ }) : /* @__PURE__ */ b(e, {
32
+ name: "file-text",
33
+ size: 20
34
+ })
35
+ }), /* @__PURE__ */ x("span", {
36
+ className: "ds-entry__body",
37
+ children: [
38
+ /* @__PURE__ */ x("span", {
39
+ className: "ds-entry__title",
40
+ "data-unavailable": t.isUnavailable || void 0,
41
+ children: [r, t.title]
42
+ }),
43
+ t.metadata != null && /* @__PURE__ */ b("span", {
44
+ className: "ds-entry__meta",
45
+ children: t.metadata
46
+ }),
47
+ i && /* @__PURE__ */ x("span", {
48
+ id: n,
49
+ className: "ds-entry__reason",
50
+ children: [
51
+ /* @__PURE__ */ b(a, {
52
+ shape: "tag",
53
+ size: "sm",
54
+ children: i.label
55
+ }),
56
+ " ",
57
+ /* @__PURE__ */ b("span", { children: i.description })
58
+ ]
59
+ })
60
+ ]
61
+ })] });
62
+ }
63
+ function E({ item: e, reasonId: t }) {
64
+ return C(e) ? /* @__PURE__ */ x("span", {
65
+ className: "ds-entry__removed",
66
+ children: [
67
+ /* @__PURE__ */ b("strong", { children: e.title }),
68
+ " ",
69
+ e.metadata ?? /* @__PURE__ */ b("code", { children: e.id })
70
+ ]
71
+ }) : /* @__PURE__ */ b(T, {
72
+ item: e,
73
+ reasonId: t
74
+ });
75
+ }
76
+ function D({ item: e }) {
77
+ return C(e) ? /* @__PURE__ */ b(a, {
78
+ shape: "tag",
79
+ children: e.removedLabel ?? "Removed on save"
80
+ }) : null;
81
+ }
82
+ function O({ item: e, onEdit: n, isDisabled: r }) {
83
+ return !n || e.isUnavailable || e.isDisabled ? null : /* @__PURE__ */ b(t, {
84
+ variant: "simple",
85
+ size: "sm",
86
+ isIconOnly: !0,
87
+ iconStart: "pencil",
88
+ "aria-label": `Edit ${e.title}`,
89
+ isDisabled: r,
90
+ onClick: () => n(e)
91
+ });
92
+ }
93
+ //#endregion
94
+ //#region src/components/EntryPicker/chosen.ts
95
+ function k(e, t, n) {
96
+ return {
97
+ id: e,
98
+ title: t,
99
+ metadata: n,
100
+ isUnavailable: !0
101
+ };
102
+ }
103
+ function A({ selected: e, items: t, pageItems: n, known: r, failures: i, hasResolver: a, itemLabel: o }) {
104
+ let s = new Map(t.map((e) => [e.id, e])), c = new Map(n.map((e) => [e.id, e]));
105
+ return e.map((e) => (s.get(e) ?? (r.has(e) ? r.get(e) : c.get(e))) || (r.has(e) ? k(e, `${`${o.charAt(0).toUpperCase()}${o.slice(1)}`} no longer available`, "Replace or clear this selection.") : a ? k(e, i.has(e) ? `Couldn't load ${o}` : "Loading…") : {
106
+ id: e,
107
+ title: e
108
+ }));
109
+ }
110
+ //#endregion
111
+ //#region src/components/EntryPicker/use-selected-items.ts
112
+ function j(e) {
113
+ return e instanceof Error ? e : null;
114
+ }
115
+ function M(e, t) {
116
+ if (!t.some((t) => e.has(t))) return e;
117
+ let n = new Map(e);
118
+ for (let e of t) n.delete(e);
119
+ return n;
120
+ }
121
+ function N(e, t, n) {
122
+ let r = n ? t.flatMap((t) => {
123
+ let r = n(t);
124
+ return r?.item.id === t && e.seeds.get(t) !== r ? [r] : [];
125
+ }) : [];
126
+ if (r.length === 0) return e;
127
+ let i = r.filter((t) => Object.is(t.revision, e.refreshKey)), a = r.filter((t) => !Object.is(t.revision, e.refreshKey) && !e.known.has(t.item.id) && !e.stale.has(t.item.id)), o = (e) => e.map((e) => [e.item.id, e.item]);
128
+ return {
129
+ ...e,
130
+ seeds: new Map([...e.seeds, ...r.map((e) => [e.item.id, e])]),
131
+ known: i.length ? new Map([...e.known, ...o(i)]) : e.known,
132
+ stale: a.length ? new Map([...e.stale, ...o(a)]) : e.stale,
133
+ failures: M(e.failures, i.map((e) => e.item.id))
134
+ };
135
+ }
136
+ function P(e, t) {
137
+ return e !== t && (e.length !== t.length || t.some((t) => !e.includes(t)));
138
+ }
139
+ function F(e, t, n, r) {
140
+ let i = e;
141
+ if (Object.is(i.refreshKey, n) || (i = {
142
+ ...i,
143
+ refreshKey: n,
144
+ known: /* @__PURE__ */ new Map(),
145
+ stale: new Map([...i.stale, ...i.known]),
146
+ failures: /* @__PURE__ */ new Map()
147
+ }), P(i.selected, t)) {
148
+ let e = i.selected.filter((e) => !t.includes(e));
149
+ i = {
150
+ ...i,
151
+ selected: t,
152
+ known: M(i.known, e),
153
+ stale: M(i.stale, e),
154
+ failures: M(i.failures, e),
155
+ seeds: M(i.seeds, e)
156
+ };
157
+ }
158
+ return N(i, t, r);
159
+ }
160
+ function I(e, t, n, r, a) {
161
+ let o = i(n), s = i(e), [c, l] = v(() => N({
162
+ refreshKey: r,
163
+ selected: e,
164
+ known: /* @__PURE__ */ new Map(),
165
+ stale: /* @__PURE__ */ new Map(),
166
+ failures: /* @__PURE__ */ new Map(),
167
+ seeds: /* @__PURE__ */ new Map()
168
+ }, e, a)), u = F(c, e, r, a);
169
+ u !== c && l(u);
170
+ let { known: d, stale: f, failures: p } = u, h = g(() => f.size === 0 ? d : new Map([...f, ...d]), [f, d]), y = (e, t, n = s.current) => {
171
+ let r = e.filter((e) => e !== void 0 && n.includes(e.id)).map((e) => [e.id, e]);
172
+ r.length !== 0 && l((e) => {
173
+ if (Object.is(e.refreshKey, t)) return {
174
+ ...e,
175
+ known: new Map([...e.known, ...r])
176
+ };
177
+ let n = r.filter(([t]) => !e.known.has(t) && !e.stale.has(t));
178
+ return n.length === 0 ? e : {
179
+ ...e,
180
+ stale: new Map([...e.stale, ...n])
181
+ };
182
+ });
183
+ }, b = new Set(t.map((e) => e.id)), x = n ? e.filter((e) => !b.has(e) && !d.has(e) && !p.has(e)) : [], S = JSON.stringify(x), C = _({
184
+ refreshKey: r,
185
+ tokens: /* @__PURE__ */ new Map()
186
+ });
187
+ m(() => {
188
+ let e = o.current;
189
+ if (!e) return;
190
+ let t = JSON.parse(S);
191
+ Object.is(C.current.refreshKey, r) || (C.current = {
192
+ refreshKey: r,
193
+ tokens: /* @__PURE__ */ new Map()
194
+ });
195
+ let { tokens: n } = C.current;
196
+ for (let e of n.keys()) t.includes(e) || n.delete(e);
197
+ for (let i of t.filter((e) => !n.has(e))) {
198
+ let t = Symbol(i);
199
+ n.set(i, t);
200
+ let a = (e) => {
201
+ C.current.tokens.get(i) === t && (C.current.tokens.delete(i), l((t) => Object.is(t.refreshKey, r) && t.selected.includes(i) ? e(t) : t));
202
+ };
203
+ Promise.resolve().then(() => e(i)).then((e) => a((t) => t.known.has(i) ? t : {
204
+ ...t,
205
+ known: new Map(t.known).set(i, e ?? null)
206
+ }), (e) => a((t) => ({
207
+ ...t,
208
+ failures: new Map(t.failures).set(i, j(e))
209
+ })));
210
+ }
211
+ }, [
212
+ S,
213
+ r,
214
+ o
215
+ ]);
216
+ let w = e.filter((e) => p.has(e) && !d.has(e));
217
+ return {
218
+ known: h,
219
+ failures: p,
220
+ remember: y,
221
+ status: x.length > 0 ? "loading" : w.length > 0 ? "error" : "ready",
222
+ error: w.length > 0 ? p.get(w[0]) ?? null : null,
223
+ retry: () => l((e) => ({
224
+ ...e,
225
+ failures: M(e.failures, w)
226
+ }))
227
+ };
228
+ }
229
+ //#endregion
230
+ //#region src/components/EntryPicker/feedback.tsx
231
+ function L(e, t, n, r) {
232
+ let i = l(t, n, r);
233
+ return t !== "error" && i.state !== "pending" ? null : /* @__PURE__ */ b(u, {
234
+ title: e,
235
+ error: i.error,
236
+ onRetry: i.retry,
237
+ retryState: i.state
238
+ });
239
+ }
240
+ function R({ query: e, itemLabel: t, itemsLabel: n, canCreate: r }) {
241
+ let i = e.trim();
242
+ return /* @__PURE__ */ x("div", {
243
+ className: "ds-entry-picker__no-results",
244
+ children: [/* @__PURE__ */ b("p", { children: i ? `No ${n} match “${i}”` : `No ${n} yet` }), i && /* @__PURE__ */ x("p", { children: ["Try a different search.", r ? ` Or create the ${t} you need.` : ""] })]
245
+ });
246
+ }
247
+ function z(e, t) {
248
+ let n = e.closest(".ds-entry-picker__scroll") ?? e.parentElement, i = Array.from(n?.querySelectorAll(".ds-entry-picker__result") ?? []);
249
+ for (let e of [...i.slice(t), ...i.slice(0, t).reverse()]) {
250
+ let t = r(e)[0];
251
+ if (t) return t;
252
+ }
253
+ }
254
+ function B(e) {
255
+ let t = _(null), i = _(null), { more: a, offset: o } = e;
256
+ return m(() => {
257
+ let e = i.current, o = t.current;
258
+ e !== null && a.status !== "loading" && (i.current = null, o && n(document.activeElement) && (a.status === "error" ? r(o)[0] : z(o, e))?.focus());
259
+ }, [a.status, o]), {
260
+ pagingRef: t,
261
+ load: () => {
262
+ i.current = t.current?.contains(document.activeElement) ? o : null, a.load();
263
+ }
264
+ };
265
+ }
266
+ function V(e, t) {
267
+ let i = _(t);
268
+ m(() => {
269
+ if (i.current === t) return;
270
+ i.current = t;
271
+ let a = e.current;
272
+ a && n(document.activeElement) && (r(a)[0] ?? z(a, Infinity))?.focus();
273
+ }, [e, t]);
274
+ }
275
+ function H({ count: e, total: n, isRemote: r, pageSize: i, remote: a, itemsLabel: o }) {
276
+ let { more: s } = a, { pagingRef: c, load: l } = B(a), u = L(`Couldn't load more ${o}`, s.status, s.error, l);
277
+ return V(c, u ? "failure" : r && a.hasMore ? "more" : "none"), n === 0 ? null : /* @__PURE__ */ x("div", {
278
+ ref: c,
279
+ className: "ds-entry-picker__paging",
280
+ children: [u ?? (r && a.hasMore && /* @__PURE__ */ x(t, {
281
+ isPending: s.status === "loading",
282
+ isFocusableWhenDisabled: !0,
283
+ isDisabled: !s.isAvailable,
284
+ onClick: l,
285
+ children: [
286
+ "Load ",
287
+ Math.min(i, n - a.offset),
288
+ " more"
289
+ ]
290
+ })), /* @__PURE__ */ b("span", { children: e < n ? `Showing ${e} of ${n}` : `All ${e} shown` })]
291
+ });
292
+ }
293
+ //#endregion
294
+ //#region src/components/EntryPicker/blocked.ts
295
+ function U(e, t, { isDisabled: n, searching: r, atMax: i }) {
296
+ if (n || r) return "inactive";
297
+ if (e.isDisabled) return "restricted";
298
+ if (!t && i) return "full";
299
+ }
300
+ //#endregion
301
+ //#region src/components/EntryPicker/results.tsx
302
+ function W({ items: e, selected: t, block: n, onToggle: r, onEdit: i }) {
303
+ let a = h(), o = `${a}-full`;
304
+ return /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b("span", {
305
+ id: o,
306
+ hidden: !0,
307
+ children: "The selection is full. Remove one to choose another."
308
+ }), /* @__PURE__ */ b("ul", {
309
+ className: "ds-entry-picker__results",
310
+ "data-searching": n.searching || void 0,
311
+ children: e.map((e, s) => {
312
+ let c = t.includes(e.id), l = U(e, c, n), u = S(e) ? `${a}-reason-${s}` : void 0;
313
+ return /* @__PURE__ */ x("li", {
314
+ className: "ds-entry-picker__result",
315
+ "data-selected": c || void 0,
316
+ "data-blocked": l ? !0 : void 0,
317
+ onClick: (t) => {
318
+ let n = t.target instanceof Element ? t.target.closest("button, input, label, a, select, textarea, summary, [tabindex]") : null;
319
+ (!n || !t.currentTarget.contains(n)) && r(e.id);
320
+ },
321
+ children: [
322
+ /* @__PURE__ */ b(p, {
323
+ checked: c,
324
+ "aria-checked": c,
325
+ "aria-label": `Select ${e.title}`,
326
+ "aria-describedby": l === "full" ? o : u,
327
+ disabled: !!l,
328
+ isFocusableWhenDisabled: l !== "inactive",
329
+ onChange: () => r(e.id)
330
+ }),
331
+ /* @__PURE__ */ b("span", {
332
+ className: "ds-entry",
333
+ children: /* @__PURE__ */ b(T, {
334
+ item: e,
335
+ reasonId: u
336
+ })
337
+ }),
338
+ /* @__PURE__ */ b(O, {
339
+ item: e,
340
+ onEdit: i,
341
+ isDisabled: l === "inactive"
342
+ })
343
+ ]
344
+ }, e.id);
345
+ })
346
+ })] });
347
+ }
348
+ //#endregion
349
+ //#region src/components/EntryPicker/use-picker-scroll.ts
350
+ function G() {
351
+ let e = _(null), [t, n] = v(!1);
352
+ return {
353
+ ref: e,
354
+ scrolled: t,
355
+ toTop: () => {
356
+ n(!1), e.current && (e.current.scrollTop = 0);
357
+ },
358
+ onScroll: (e) => {
359
+ n(e.currentTarget.scrollTop > 0);
360
+ }
361
+ };
362
+ }
363
+ //#endregion
364
+ //#region src/components/EntryPicker/dialog.tsx
365
+ function K({ isOpen: e, onClose: n, query: r, onQuery: i, selected: a, results: o, cap: l, block: u, isRemote: f, pageSize: p, remote: m, onToggle: h, onEdit: g, itemLabel: _, itemsLabel: v, addLabel: S, onCreate: C, isCreating: w, dialogTitle: T, dialogDescription: E, isDialogHidden: D }) {
366
+ let O = L(`Couldn't refresh ${v}`, m.refresh.status, m.refresh.error, m.refresh.retry);
367
+ return /* @__PURE__ */ b(c, {
368
+ isOpen: e,
369
+ isHidden: D,
370
+ onClose: n,
371
+ title: T ?? S,
372
+ description: E ?? l.description,
373
+ className: "ds-entry-picker__dialog",
374
+ footer: /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b("span", {
375
+ className: "ds-entry-picker__selection",
376
+ role: "status",
377
+ children: l.reading ? /* @__PURE__ */ b(s, {
378
+ ...l.reading,
379
+ size: "lg"
380
+ }) : `${a.length} selected`
381
+ }), /* @__PURE__ */ b(t, {
382
+ variant: "primary",
383
+ onClick: n,
384
+ children: "Done"
385
+ })] }),
386
+ children: /* @__PURE__ */ b(q, {
387
+ query: r,
388
+ onQuery: i,
389
+ itemsLabel: v,
390
+ isSearching: m.loading,
391
+ action: C && /* @__PURE__ */ b(t, {
392
+ variant: "primary",
393
+ isPending: w,
394
+ isFocusableWhenDisabled: !0,
395
+ iconStart: "plus",
396
+ isDisabled: u.isDisabled || l.atMax,
397
+ onClick: C,
398
+ children: `New ${_}`
399
+ }),
400
+ banner: O,
401
+ isBusy: m.loading || m.more.status === "loading" || m.refresh.status === "loading",
402
+ children: /* @__PURE__ */ x(d, {
403
+ status: m.status,
404
+ errorTitle: `Couldn't load ${v}`,
405
+ error: m.error,
406
+ onRetry: m.retry,
407
+ children: [
408
+ /* @__PURE__ */ b(W, {
409
+ items: o,
410
+ selected: a,
411
+ block: u,
412
+ onToggle: h,
413
+ onEdit: g
414
+ }),
415
+ !m.searching && o.length === 0 && /* @__PURE__ */ b(R, {
416
+ query: r,
417
+ itemLabel: _,
418
+ itemsLabel: v,
419
+ canCreate: !!C
420
+ }),
421
+ /* @__PURE__ */ b(H, {
422
+ count: o.length,
423
+ total: f ? m.total : o.length,
424
+ isRemote: f,
425
+ pageSize: p,
426
+ remote: m,
427
+ itemsLabel: v
428
+ })
429
+ ]
430
+ })
431
+ })
432
+ });
433
+ }
434
+ function q({ query: e, onQuery: t, itemsLabel: n, isSearching: r, action: i, banner: a, isBusy: o, children: s }) {
435
+ let { ref: c, scrolled: l, onScroll: u, toTop: d } = G(), p = (e) => {
436
+ d(), t(e);
437
+ };
438
+ return /* @__PURE__ */ x(y, { children: [
439
+ /* @__PURE__ */ x("div", {
440
+ className: "ds-entry-picker__search",
441
+ "data-scrolled": l || void 0,
442
+ children: [/* @__PURE__ */ b(f, {
443
+ "aria-label": `Search ${n}`,
444
+ value: e,
445
+ isBusy: r,
446
+ placeholder: `Search ${n}`,
447
+ onChange: (e) => p(e.target.value),
448
+ onClear: () => p("")
449
+ }), i]
450
+ }),
451
+ a && /* @__PURE__ */ b("div", {
452
+ className: "ds-entry-picker__refresh",
453
+ children: a
454
+ }),
455
+ /* @__PURE__ */ b("div", {
456
+ className: "ds-entry-picker__scroll",
457
+ ref: c,
458
+ onScroll: u,
459
+ "aria-busy": o,
460
+ children: s
461
+ })
462
+ ] });
463
+ }
464
+ //#endregion
465
+ //#region src/components/EntryPicker/limit.ts
466
+ function J(e, t) {
467
+ return e === "single" || t === 1;
468
+ }
469
+ function Y(e, t, n) {
470
+ return J(e, n) ? {
471
+ count: t,
472
+ max: 1,
473
+ tone: "neutral"
474
+ } : e === "multiple" && n !== void 0 ? {
475
+ count: t,
476
+ max: n
477
+ } : void 0;
478
+ }
479
+ function X(e, t, n) {
480
+ return J(e, n) ? void 0 : t;
481
+ }
482
+ function ee(e, t, n, { itemLabel: r, itemsLabel: i }) {
483
+ let a = Y(e, t, n), s = e === "multiple" && a && Number.isFinite(a.max) ? a.max : void 0, c = `Choose as many ${i} as you need.`;
484
+ return e === "single" || s === 1 ? c = `Choose one ${r}.` : s !== void 0 && (c = `Choose up to ${s} ${i}.`), {
485
+ limit: a,
486
+ atMax: s !== void 0 && t >= s,
487
+ description: c,
488
+ reading: e === "multiple" && o(a) ? a : void 0
489
+ };
490
+ }
491
+ //#endregion
492
+ //#region src/components/EntryPicker/use-picker-data.ts
493
+ var te = 250;
494
+ function ne(e) {
495
+ return Array.from(new Map(e.map((e) => [e.id, e])).values());
496
+ }
497
+ var Z = {
498
+ items: [],
499
+ offset: 0,
500
+ total: 0
501
+ }, Q = {
502
+ ...Z,
503
+ key: null,
504
+ revision: void 0,
505
+ status: "ready",
506
+ error: null
507
+ };
508
+ function re(e, t) {
509
+ let n = e?.status === "error" && t;
510
+ return {
511
+ status: e?.status === "loading" ? "loading" : n ? "error" : "ready",
512
+ error: n ? e.error ?? null : null,
513
+ isAvailable: t
514
+ };
515
+ }
516
+ function $(e, t) {
517
+ return {
518
+ items: ne([...e.items, ...t.items]),
519
+ offset: e.offset + t.items.length,
520
+ total: t.items.length === 0 ? Math.min(t.total, e.offset) : t.total
521
+ };
522
+ }
523
+ function ie(e, t, n, r) {
524
+ return e.key !== t || e.offset !== n ? e : {
525
+ ...e,
526
+ ...$(e, r)
527
+ };
528
+ }
529
+ async function ae(e, t, n, r, i) {
530
+ let a = Math.max(1, Math.ceil(r / n)), o = await Promise.all(Array.from({ length: a }, (r, i) => e({
531
+ offset: i * n,
532
+ limit: n
533
+ }, { query: t }))), s = Z;
534
+ for (let [e, t] of o.entries()) {
535
+ if (s.offset !== e * n) break;
536
+ s = $(s, t);
537
+ }
538
+ for (; s.offset < r && s.offset < s.total && i();) s = $(s, await e({
539
+ offset: s.offset,
540
+ limit: n
541
+ }, { query: t }));
542
+ return s;
543
+ }
544
+ function oe(e, t, n, r) {
545
+ let i = e !== null && t.key === e, a = i && Object.is(t.revision, n), o = e !== null && !a && (!i || t.status === "error"), s = o && t.key !== null && t.status === "ready", c = o && !s ? "loading" : t.status === "error" ? "error" : "ready", l = t.status === "ready" && t.offset < t.total, u = i && !a && t.status === "ready", d = u && r?.key === e && Object.is(r.revision, n);
546
+ return {
547
+ loading: o,
548
+ searching: s,
549
+ status: c,
550
+ hasMore: l,
551
+ refresh: u ? d ? "error" : "loading" : "ready",
552
+ refreshFailed: d
553
+ };
554
+ }
555
+ function se(e, t, n, r, a, o) {
556
+ let s = i(e), c = i(a), l = i(o), [u, d] = v(0), [f, p] = v(Q), [h, g] = v(null), [y, b] = v(null), [x, S] = v(r);
557
+ x !== r && (S(r), r || (p(Q), g(null), b(null), d((e) => e + 1)));
558
+ let C = n.trim(), w = e && r ? JSON.stringify([
559
+ C,
560
+ t,
561
+ u
562
+ ]) : null, T = i(f), E = _(null), D = _(C), { loading: O, searching: k, status: A, hasMore: M, refresh: N, refreshFailed: P } = oe(w, f, o, y), F = !O && N === "ready", I = O ? "load" : N === "loading" ? "refresh" : null;
563
+ m(() => {
564
+ if (w === null) return;
565
+ let e = I === "load" && C !== D.current ? te : 0;
566
+ if (D.current = C, I === null) return;
567
+ let n = I === "refresh" ? T.current.offset + (E.current ? t : 0) : 0, r = !0, i = window.setTimeout(() => {
568
+ let e = s.current;
569
+ e && ae(e, C, t, n, () => r).then((e) => {
570
+ r && (E.current = null, p({
571
+ ...e,
572
+ key: w,
573
+ revision: o,
574
+ status: "ready",
575
+ error: null
576
+ }), g(null), b(null), c.current(e.items, o));
577
+ }, (e) => {
578
+ r && (I === "refresh" ? b({
579
+ key: w,
580
+ revision: o,
581
+ error: j(e)
582
+ }) : (E.current = null, p({
583
+ ...Q,
584
+ key: w,
585
+ revision: o,
586
+ status: "error",
587
+ error: j(e)
588
+ }), g(null)));
589
+ });
590
+ }, e);
591
+ return () => {
592
+ r = !1, window.clearTimeout(i);
593
+ };
594
+ }, [
595
+ w,
596
+ I,
597
+ o,
598
+ C,
599
+ t,
600
+ s,
601
+ c,
602
+ T
603
+ ]);
604
+ let L = () => {
605
+ let e = s.current, n = f.key, { offset: r } = f;
606
+ if (!e || n === null || !F || !M || E.current) return;
607
+ let i = Symbol("load more"), a = o;
608
+ E.current = i, g({
609
+ token: i,
610
+ status: "loading",
611
+ error: null
612
+ });
613
+ let u = () => E.current === i && T.current.key === n && T.current.offset === r && Object.is(l.current, a), d = (e) => {
614
+ E.current === i && (E.current = null), g((t) => t?.token === i ? e : t);
615
+ };
616
+ Promise.resolve().then(() => e({
617
+ offset: r,
618
+ limit: t
619
+ }, { query: C })).then((e) => {
620
+ u() && (p((t) => ie(t, n, r, e)), c.current(e.items, a)), d(null);
621
+ }, (e) => d(u() ? {
622
+ token: i,
623
+ status: "error",
624
+ error: j(e)
625
+ } : null));
626
+ };
627
+ return {
628
+ items: f.items,
629
+ total: f.total,
630
+ offset: f.offset,
631
+ hasMore: M,
632
+ pageRevision: f.revision,
633
+ loading: O,
634
+ searching: k,
635
+ status: A,
636
+ error: f.error,
637
+ retry: () => d((e) => e + 1),
638
+ more: {
639
+ ...re(h, F),
640
+ load: L
641
+ },
642
+ refresh: {
643
+ status: N,
644
+ error: P ? y?.error ?? null : null,
645
+ retry: () => b(null)
646
+ }
647
+ };
648
+ }
649
+ //#endregion
650
+ //#region src/components/EntryPicker/use-picker-session.ts
651
+ var ce = [];
652
+ function le(e, t) {
653
+ return t ? e.map((e) => {
654
+ let n = e.isDisabled ? void 0 : t(e);
655
+ return n ? {
656
+ ...e,
657
+ isDisabled: !0,
658
+ disabledReason: n
659
+ } : e;
660
+ }) : e;
661
+ }
662
+ function ue(e, t, n, { isOpen: r, isDisabled: i, itemLabel: a, itemsLabel: o, close: s, restrict: c }) {
663
+ let [l, u] = v(""), { resolveItem: d, refreshKey: f, loadPage: p, pageSize: m = 10, mode: h = "multiple", max: _, onEditItem: y } = n, b = I(e, t, d, f), x = se(p, m, l, r, b.remember, f), S = !!p, C = g(() => {
664
+ let e = l.trim().toLowerCase();
665
+ return S ? ce : t.filter((t) => !e || [t.title, ...t.keywords ?? []].join(" ").toLowerCase().includes(e));
666
+ }, [
667
+ S,
668
+ t,
669
+ l
670
+ ]), w = S ? x.items : C, T = g(() => le(w, c), [w, c]), E = ee(h, e.length, _, {
671
+ itemLabel: a,
672
+ itemsLabel: o
673
+ }), D = {
674
+ isDisabled: i,
675
+ searching: x.searching,
676
+ atMax: E.atMax
677
+ }, O = y ? (e) => {
678
+ y(e) === !1 && s();
679
+ } : void 0;
680
+ return {
681
+ selection: b,
682
+ remote: x,
683
+ isRemote: S,
684
+ results: T,
685
+ cap: E,
686
+ block: D,
687
+ editItem: O,
688
+ revision: S ? x.pageRevision : f,
689
+ choice: (t) => {
690
+ let n = T.find((e) => e.id === t);
691
+ return n && !U(n, e.includes(t), D) ? n : void 0;
692
+ },
693
+ dialog: {
694
+ query: l,
695
+ onQuery: u,
696
+ selected: e,
697
+ results: T,
698
+ cap: E,
699
+ block: D,
700
+ isRemote: S,
701
+ pageSize: m,
702
+ remote: x,
703
+ onEdit: O,
704
+ itemLabel: a,
705
+ itemsLabel: o
706
+ }
707
+ };
708
+ }
709
+ //#endregion
710
+ export { L as a, O as c, E as d, w as f, K as i, T as l, X as n, I as o, Y as r, A as s, ue as t, D as u };
711
+
712
+ //# sourceMappingURL=use-picker-session-BLH1tXk3.js.map