@philosaether/chipper 0.1.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.
Files changed (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +778 -0
  3. package/dist/base.css +1 -0
  4. package/dist/headless.d.ts +16 -0
  5. package/dist/headless.d.ts.map +1 -0
  6. package/dist/headless.js +18 -0
  7. package/dist/index.js +1445 -0
  8. package/dist/src/builder/index.d.ts +82 -0
  9. package/dist/src/builder/index.d.ts.map +1 -0
  10. package/dist/src/builder/predicates.d.ts +18 -0
  11. package/dist/src/builder/predicates.d.ts.map +1 -0
  12. package/dist/src/components/Chip.d.ts +15 -0
  13. package/dist/src/components/Chip.d.ts.map +1 -0
  14. package/dist/src/components/ChipInfoPopup.d.ts +12 -0
  15. package/dist/src/components/ChipInfoPopup.d.ts.map +1 -0
  16. package/dist/src/components/ChipPopup.d.ts +20 -0
  17. package/dist/src/components/ChipPopup.d.ts.map +1 -0
  18. package/dist/src/components/Chipper.d.ts +25 -0
  19. package/dist/src/components/Chipper.d.ts.map +1 -0
  20. package/dist/src/components/Clause.d.ts +13 -0
  21. package/dist/src/components/Clause.d.ts.map +1 -0
  22. package/dist/src/components/Sentence.d.ts +15 -0
  23. package/dist/src/components/Sentence.d.ts.map +1 -0
  24. package/dist/src/components/index.d.ts +12 -0
  25. package/dist/src/components/index.d.ts.map +1 -0
  26. package/dist/src/components/popups/AlternativeCoordinatePopup.d.ts +16 -0
  27. package/dist/src/components/popups/AlternativeCoordinatePopup.d.ts.map +1 -0
  28. package/dist/src/components/popups/KeywordGroupList.d.ts +29 -0
  29. package/dist/src/components/popups/KeywordGroupList.d.ts.map +1 -0
  30. package/dist/src/components/popups/KeywordOrExpressionPopup.d.ts +30 -0
  31. package/dist/src/components/popups/KeywordOrExpressionPopup.d.ts.map +1 -0
  32. package/dist/src/components/popups/MultiSelectPopup.d.ts +20 -0
  33. package/dist/src/components/popups/MultiSelectPopup.d.ts.map +1 -0
  34. package/dist/src/components/popups/NumericInput.d.ts +16 -0
  35. package/dist/src/components/popups/NumericInput.d.ts.map +1 -0
  36. package/dist/src/components/popups/ReferencePopup.d.ts +20 -0
  37. package/dist/src/components/popups/ReferencePopup.d.ts.map +1 -0
  38. package/dist/src/core/actions/set-chip-value.d.ts +17 -0
  39. package/dist/src/core/actions/set-chip-value.d.ts.map +1 -0
  40. package/dist/src/core/actions/set-context.d.ts +18 -0
  41. package/dist/src/core/actions/set-context.d.ts.map +1 -0
  42. package/dist/src/core/actions/set-display-value.d.ts +18 -0
  43. package/dist/src/core/actions/set-display-value.d.ts.map +1 -0
  44. package/dist/src/core/actions/toggle-clause.d.ts +15 -0
  45. package/dist/src/core/actions/toggle-clause.d.ts.map +1 -0
  46. package/dist/src/core/context-resolution.d.ts +36 -0
  47. package/dist/src/core/context-resolution.d.ts.map +1 -0
  48. package/dist/src/core/initialize.d.ts +43 -0
  49. package/dist/src/core/initialize.d.ts.map +1 -0
  50. package/dist/src/core/mode-switching.d.ts +10 -0
  51. package/dist/src/core/mode-switching.d.ts.map +1 -0
  52. package/dist/src/core/reducer.d.ts +16 -0
  53. package/dist/src/core/reducer.d.ts.map +1 -0
  54. package/dist/src/core/resolve-keyword-label.d.ts +7 -0
  55. package/dist/src/core/resolve-keyword-label.d.ts.map +1 -0
  56. package/dist/src/core/serialize.d.ts +34 -0
  57. package/dist/src/core/serialize.d.ts.map +1 -0
  58. package/dist/src/core/state.d.ts +59 -0
  59. package/dist/src/core/state.d.ts.map +1 -0
  60. package/dist/src/core/store.d.ts +23 -0
  61. package/dist/src/core/store.d.ts.map +1 -0
  62. package/dist/src/core/types.d.ts +242 -0
  63. package/dist/src/core/types.d.ts.map +1 -0
  64. package/dist/src/domains/alternative-coordinate.d.ts +110 -0
  65. package/dist/src/domains/alternative-coordinate.d.ts.map +1 -0
  66. package/dist/src/domains/create-domain.d.ts +30 -0
  67. package/dist/src/domains/create-domain.d.ts.map +1 -0
  68. package/dist/src/domains/facades.d.ts +134 -0
  69. package/dist/src/domains/facades.d.ts.map +1 -0
  70. package/dist/src/domains/index.d.ts +14 -0
  71. package/dist/src/domains/index.d.ts.map +1 -0
  72. package/dist/src/domains/keyword-or-expression.d.ts +148 -0
  73. package/dist/src/domains/keyword-or-expression.d.ts.map +1 -0
  74. package/dist/src/domains/multi-select.d.ts +68 -0
  75. package/dist/src/domains/multi-select.d.ts.map +1 -0
  76. package/dist/src/domains/normalize-keywords.d.ts +83 -0
  77. package/dist/src/domains/normalize-keywords.d.ts.map +1 -0
  78. package/dist/src/domains/reference.d.ts +89 -0
  79. package/dist/src/domains/reference.d.ts.map +1 -0
  80. package/dist/src/hooks/SentenceProvider.d.ts +17 -0
  81. package/dist/src/hooks/SentenceProvider.d.ts.map +1 -0
  82. package/dist/src/hooks/context.d.ts +31 -0
  83. package/dist/src/hooks/context.d.ts.map +1 -0
  84. package/dist/src/hooks/index.d.ts +13 -0
  85. package/dist/src/hooks/index.d.ts.map +1 -0
  86. package/dist/src/hooks/useChip.d.ts +21 -0
  87. package/dist/src/hooks/useChip.d.ts.map +1 -0
  88. package/dist/src/hooks/useDisplaySource.d.ts +16 -0
  89. package/dist/src/hooks/useDisplaySource.d.ts.map +1 -0
  90. package/dist/src/hooks/useKeyboardNavigation.d.ts +44 -0
  91. package/dist/src/hooks/useKeyboardNavigation.d.ts.map +1 -0
  92. package/dist/src/hooks/usePopup.d.ts +13 -0
  93. package/dist/src/hooks/usePopup.d.ts.map +1 -0
  94. package/dist/src/hooks/useReferenceDisplay.d.ts +22 -0
  95. package/dist/src/hooks/useReferenceDisplay.d.ts.map +1 -0
  96. package/dist/src/hooks/useSentence.d.ts +14 -0
  97. package/dist/src/hooks/useSentence.d.ts.map +1 -0
  98. package/dist/src/index.d.ts +25 -0
  99. package/dist/src/index.d.ts.map +1 -0
  100. package/dist/src/palette/index.d.ts +29 -0
  101. package/dist/src/palette/index.d.ts.map +1 -0
  102. package/dist/src/themes/apply-theme.d.ts +34 -0
  103. package/dist/src/themes/apply-theme.d.ts.map +1 -0
  104. package/dist/src/themes/create-hue.d.ts +23 -0
  105. package/dist/src/themes/create-hue.d.ts.map +1 -0
  106. package/dist/src/themes/index.d.ts +13 -0
  107. package/dist/src/themes/index.d.ts.map +1 -0
  108. package/dist/src/themes/midnight.d.ts +11 -0
  109. package/dist/src/themes/midnight.d.ts.map +1 -0
  110. package/dist/src/themes/praxis.d.ts +11 -0
  111. package/dist/src/themes/praxis.d.ts.map +1 -0
  112. package/dist/src/themes/terminal.d.ts +9 -0
  113. package/dist/src/themes/terminal.d.ts.map +1 -0
  114. package/dist/src/themes/types.d.ts +72 -0
  115. package/dist/src/themes/types.d.ts.map +1 -0
  116. package/dist/styles.css +1 -0
  117. package/dist/themes/index.js +256 -0
  118. package/dist/themes/midnight.css +1 -0
  119. package/dist/themes/praxis.css +1 -0
  120. package/dist/themes/terminal.css +1 -0
  121. package/dist/usePopup-Of6OHa1_.js +653 -0
  122. package/package.json +75 -0
package/dist/index.js ADDED
@@ -0,0 +1,1445 @@
1
+ import { k as W, T as ne, u as oe, j as X, h as ae, S as se } from "./usePopup-Of6OHa1_.js";
2
+ import { b as We, c as Xe, a as Ze, d as Me, e as et, i as tt, r as rt, s as nt, f as ot, g as at } from "./usePopup-Of6OHa1_.js";
3
+ import { useState as V, useEffect as T, useCallback as B, useRef as R, useMemo as H } from "react";
4
+ import { jsxs as S, jsx as c, Fragment as z } from "react/jsx-runtime";
5
+ function q(e) {
6
+ return {
7
+ type: e.type,
8
+ color: e.color,
9
+ keywords: e.keywords ?? [],
10
+ keywordGroups: e.keywordGroups,
11
+ expressionModes: e.expressionModes ?? [],
12
+ defaultValue: e.defaultValue,
13
+ placeholder: e.placeholder,
14
+ validate: e.validate ?? (() => !0),
15
+ display: e.display ?? ((t) => String(t)),
16
+ consumes: e.consumes,
17
+ produces: e.produces,
18
+ onContextChange: e.onContextChange,
19
+ meta: e.meta
20
+ };
21
+ }
22
+ function ie(e) {
23
+ return "keywords" in e && Array.isArray(e.keywords) && !("value" in e);
24
+ }
25
+ function J(e) {
26
+ return e.map((t) => ({
27
+ label: t.label ?? String(t.value),
28
+ display: t.display,
29
+ value: t.value,
30
+ partial: t.partial
31
+ }));
32
+ }
33
+ function Z(e) {
34
+ const t = [], o = [];
35
+ for (const s of e)
36
+ ie(s) ? o.push(s) : t.push(s);
37
+ const r = [];
38
+ t.length > 0 && r.push({
39
+ layout: "flow",
40
+ keywords: J(t)
41
+ });
42
+ for (const s of o)
43
+ s.keywords.length !== 0 && r.push({
44
+ label: s.label,
45
+ layout: s.layout ?? "flow",
46
+ columns: s.columns,
47
+ prefix: s.prefix,
48
+ keywords: J(s.keywords)
49
+ });
50
+ return { flat: r.flatMap((s) => s.keywords), groups: r };
51
+ }
52
+ function te(e) {
53
+ return new Map(e.map((t) => {
54
+ const o = t.display ?? (typeof t.label == "string" ? t.label : void 0);
55
+ return o ? [t.value, o] : void 0;
56
+ }).filter((t) => t !== void 0));
57
+ }
58
+ function le(e, t, o, r) {
59
+ return e.default !== void 0 ? e.default : e.defaultValue !== void 0 ? e.defaultValue : e.placeholder ? r : o ?? r;
60
+ }
61
+ function ce(e) {
62
+ return { inputType: "text", ...e };
63
+ }
64
+ function pe(e) {
65
+ return {
66
+ inputType: "number",
67
+ validate: (t) => {
68
+ if (t === "") return !1;
69
+ const o = Number(t);
70
+ return !isNaN(o) && isFinite(o);
71
+ },
72
+ ...e
73
+ };
74
+ }
75
+ function ue(e) {
76
+ return {
77
+ inputType: "date",
78
+ validate: (t) => {
79
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(t)) return !1;
80
+ const [o, r, a] = t.split("-").map(Number), s = new Date(o, r - 1, a);
81
+ return s.getFullYear() === o && s.getMonth() === r - 1 && s.getDate() === a;
82
+ },
83
+ ...e
84
+ };
85
+ }
86
+ function U(e) {
87
+ var x;
88
+ const t = e.keywords ?? [], { flat: o, groups: r } = Z(t), a = r.length > 1 || r.some((w) => w.label || w.layout === "grid" || w.prefix) ? r : void 0, s = new Set(o.map((w) => w.value)), n = te(o), l = e.expression, d = (l == null ? void 0 : l.validate) ?? ((w) => w.length > 0), i = (l == null ? void 0 : l.display) ?? ((w) => w), f = l ? (w) => s.has(w) || d(w) : (w) => s.has(w), h = (w, y) => w ? typeof w == "function" ? w(y) : w : "", u = (w, y) => {
89
+ const _ = n.get(w);
90
+ if (_) return _;
91
+ const N = o.find(
92
+ (O) => O.value === w && typeof O.label == "function"
93
+ );
94
+ if (N) return N.label(y ?? {});
95
+ const k = y ?? {}, K = h(l == null ? void 0 : l.prefix, k), I = h(l == null ? void 0 : l.suffix, k), E = i(w);
96
+ return [K, E, I].filter(Boolean).join(" ");
97
+ }, p = [];
98
+ l && p.push({
99
+ id: l.inputType,
100
+ label: l.placeholder ?? "Type a value",
101
+ degreesOfFreedom: 1,
102
+ validate: d,
103
+ display: i,
104
+ maxLength: l.maxLength,
105
+ inputType: l.inputType,
106
+ min: l.min,
107
+ max: l.max,
108
+ step: l.step,
109
+ prefix: l.prefix,
110
+ suffix: l.suffix,
111
+ position: l.position
112
+ });
113
+ const m = le(e, o, (x = o[0]) == null ? void 0 : x.value, ""), v = l != null && l.trigger ? { trigger: l.trigger } : void 0;
114
+ return q({
115
+ type: "keyword-or-expression",
116
+ color: e.color,
117
+ keywords: o,
118
+ keywordGroups: a ?? void 0,
119
+ expressionModes: p,
120
+ defaultValue: m,
121
+ placeholder: e.placeholder,
122
+ validate: f,
123
+ display: u,
124
+ consumes: e.consumes,
125
+ produces: e.produces,
126
+ onContextChange: e.onContextChange,
127
+ meta: v
128
+ });
129
+ }
130
+ function Ge(e) {
131
+ return U({ ...e, keywords: [] });
132
+ }
133
+ function Be(e) {
134
+ return U({
135
+ color: e.color,
136
+ placeholder: e.placeholder,
137
+ default: e.default,
138
+ keywords: e.keywords,
139
+ expression: ce({
140
+ maxLength: e.maxLength ?? 140,
141
+ validate: e.validate,
142
+ display: e.display
143
+ })
144
+ });
145
+ }
146
+ function Re(e) {
147
+ return U({
148
+ color: e.color,
149
+ placeholder: e.placeholder,
150
+ default: e.default,
151
+ keywords: e.keywords,
152
+ expression: pe({
153
+ min: e.min,
154
+ max: e.max,
155
+ step: e.step,
156
+ prefix: e.prefix,
157
+ suffix: e.suffix,
158
+ validate: e.validate,
159
+ display: e.display
160
+ })
161
+ });
162
+ }
163
+ function $e(e) {
164
+ return U({
165
+ color: e.color,
166
+ placeholder: e.placeholder,
167
+ default: e.default,
168
+ keywords: e.keywords,
169
+ expression: ue({
170
+ validate: e.validate,
171
+ display: e.display
172
+ })
173
+ });
174
+ }
175
+ function je(e) {
176
+ return U({
177
+ color: e.color,
178
+ keywords: e.keywords,
179
+ default: e.default,
180
+ placeholder: e.placeholder
181
+ });
182
+ }
183
+ const de = 3;
184
+ function re(e, t, o) {
185
+ return o.length === t && o.every((r) => e.has(r));
186
+ }
187
+ function Ue(e) {
188
+ const t = e.options, { flat: o, groups: r } = Z(t), a = r.length > 1 || r.some((p) => p.label || p.layout === "grid" || p.prefix) ? r : void 0, s = e.keywords ? J(e.keywords) : [], n = new Set(o.map((p) => p.value)), l = te(o), d = e.maxSelections, i = e.countLabel ?? "selected", f = (p) => p.length === 0 || d !== void 0 && p.length > d ? !1 : p.every((m) => n.has(m)), h = (p) => {
189
+ if (p.length === 0) return "";
190
+ const m = new Set(p);
191
+ for (const v of s)
192
+ if (re(m, p.length, v.value))
193
+ return v.display ?? (typeof v.label == "string" ? v.label : String(v.value));
194
+ return p.length <= de ? p.map((v) => l.get(v) ?? v).join(", ") : `${p.length} ${i}`;
195
+ }, u = e.default ?? e.defaultValue ?? [];
196
+ return q({
197
+ type: "multi-select",
198
+ color: e.color,
199
+ keywords: s,
200
+ defaultValue: u,
201
+ placeholder: e.placeholder,
202
+ validate: f,
203
+ display: h,
204
+ consumes: e.consumes,
205
+ produces: e.produces,
206
+ onContextChange: e.onContextChange,
207
+ meta: {
208
+ options: o,
209
+ optionGroups: a ?? void 0,
210
+ maxSelections: e.maxSelections
211
+ }
212
+ });
213
+ }
214
+ function he(e) {
215
+ const t = e.keywords, { flat: o, groups: r } = Z(t), a = r.length > 1 || r.some((s) => s.label || s.layout === "grid" || s.prefix);
216
+ return {
217
+ keywords: o,
218
+ keywordGroups: a ? r : void 0,
219
+ prefix: e.prefix
220
+ };
221
+ }
222
+ function fe(e) {
223
+ return e.map((t) => ({
224
+ ...t,
225
+ slots: t.slots.map(he)
226
+ }));
227
+ }
228
+ function ye(e) {
229
+ const t = /* @__PURE__ */ new Set();
230
+ if (e.slots.length === 1)
231
+ for (const o of e.slots[0].keywords)
232
+ t.add(o.value);
233
+ return t;
234
+ }
235
+ function me(e) {
236
+ const t = /* @__PURE__ */ new Map();
237
+ for (const o of e)
238
+ if (o.slots.length === 1) {
239
+ const r = o.slots[0], a = r.prefix ? `${r.prefix} ` : "";
240
+ for (const s of r.keywords)
241
+ if (!t.has(s.value)) {
242
+ const n = s.display ?? (typeof s.label == "string" ? s.label : s.value);
243
+ t.set(s.value, `${a}${n}`);
244
+ }
245
+ }
246
+ return t;
247
+ }
248
+ function Fe(e) {
249
+ const t = fe(e.modes), o = me(t), r = /* @__PURE__ */ new Set();
250
+ for (const d of t)
251
+ for (const i of ye(d))
252
+ r.add(i);
253
+ const a = (d) => {
254
+ var i;
255
+ if (d === "") return !1;
256
+ if (r.has(d)) return !0;
257
+ for (const f of t) {
258
+ if (f.validate) {
259
+ if (f.validate(d)) return !0;
260
+ } else if (f.slots.length > 1 && f.decompose && f.decompose(d).every((u) => u !== void 0))
261
+ return !0;
262
+ if ((i = f.expression) != null && i.validate && f.expression.validate(d))
263
+ return !0;
264
+ }
265
+ return !1;
266
+ }, s = (d) => {
267
+ var f;
268
+ const i = o.get(d);
269
+ if (i !== void 0) return i;
270
+ for (const h of t) {
271
+ if (h.display) {
272
+ const u = h.display(d);
273
+ if (u !== d) return u;
274
+ }
275
+ if ((f = h.expression) != null && f.display) {
276
+ const u = h.expression.display(d);
277
+ if (u !== d) return u;
278
+ }
279
+ }
280
+ return d;
281
+ }, n = t.filter((d) => d.expression).map((d) => ({
282
+ id: d.id,
283
+ label: d.expression.placeholder ?? d.label,
284
+ degreesOfFreedom: 1,
285
+ validate: d.expression.validate ?? ((i) => i.length > 0),
286
+ display: d.expression.display ?? ((i) => i),
287
+ maxLength: d.expression.maxLength
288
+ })), l = [];
289
+ for (const d of t)
290
+ d.slots.length === 1 && l.push(...d.slots[0].keywords);
291
+ return q({
292
+ type: "alternative-coordinate",
293
+ color: e.color,
294
+ keywords: l,
295
+ expressionModes: n,
296
+ defaultValue: e.default ?? "",
297
+ placeholder: e.placeholder,
298
+ validate: a,
299
+ display: s,
300
+ consumes: e.consumes,
301
+ produces: e.produces,
302
+ onContextChange: e.onContextChange,
303
+ meta: { modes: t }
304
+ });
305
+ }
306
+ function Ye(e) {
307
+ const t = e.keywords ?? [], o = new Map(
308
+ t.filter((a) => typeof a.label == "string").map((a) => [a.value, a.label])
309
+ ), r = /* @__PURE__ */ new Map();
310
+ return q({
311
+ type: "reference",
312
+ color: e.color,
313
+ keywords: t,
314
+ defaultValue: e.default ?? "",
315
+ placeholder: e.placeholder,
316
+ validate: (a) => a !== "",
317
+ display: (a) => {
318
+ const s = o.get(a);
319
+ return s !== void 0 ? s : r.get(a) ?? a;
320
+ },
321
+ consumes: e.consumes,
322
+ produces: e.produces,
323
+ onContextChange: e.onContextChange,
324
+ meta: { source: e.source, displayCache: r }
325
+ });
326
+ }
327
+ function He(e) {
328
+ return (t) => {
329
+ const o = t[e];
330
+ return o != null && o !== "" && !isNaN(Number(o));
331
+ };
332
+ }
333
+ function ze(e, ...t) {
334
+ const o = new Set(t);
335
+ return (r) => o.has(r[e]);
336
+ }
337
+ function Q({
338
+ itemCount: e,
339
+ onSelect: t,
340
+ onClose: o,
341
+ initialIndex: r = -1,
342
+ closeOnSelect: a = !0,
343
+ idPrefix: s = "chipper-option"
344
+ }) {
345
+ const [n, l] = V(r);
346
+ T(() => {
347
+ e === 0 ? l(-1) : n >= e && l(e - 1);
348
+ }, [e, n]);
349
+ const d = B(
350
+ (u) => `${s}-${u}`,
351
+ [s]
352
+ ), i = B(
353
+ (u) => {
354
+ if (e !== 0)
355
+ switch (u.key) {
356
+ case "ArrowDown":
357
+ case "ArrowRight": {
358
+ u.preventDefault(), l(
359
+ (p) => p < e - 1 ? p + 1 : 0
360
+ );
361
+ break;
362
+ }
363
+ case "ArrowUp":
364
+ case "ArrowLeft": {
365
+ u.preventDefault(), l(
366
+ (p) => p > 0 ? p - 1 : e - 1
367
+ );
368
+ break;
369
+ }
370
+ case "Home": {
371
+ u.preventDefault(), l(0);
372
+ break;
373
+ }
374
+ case "End": {
375
+ u.preventDefault(), l(e - 1);
376
+ break;
377
+ }
378
+ case "Enter": {
379
+ n >= 0 && n < e && (u.preventDefault(), t(n), a && o());
380
+ break;
381
+ }
382
+ case " ": {
383
+ !a && n >= 0 && n < e && (u.preventDefault(), t(n));
384
+ break;
385
+ }
386
+ case "Escape": {
387
+ u.preventDefault(), o();
388
+ break;
389
+ }
390
+ }
391
+ },
392
+ [e, n, t, o, a]
393
+ ), f = B(
394
+ (u) => ({
395
+ id: d(u),
396
+ role: "option",
397
+ "aria-selected": u === n,
398
+ className: [
399
+ "chipper-popup-option",
400
+ u === n && "chipper-popup-option--active"
401
+ ].filter(Boolean).join(" "),
402
+ onMouseEnter: () => l(u),
403
+ onClick: () => {
404
+ t(u), a && o();
405
+ }
406
+ }),
407
+ [d, n, t, o, a]
408
+ ), h = n >= 0 ? d(n) : void 0;
409
+ return {
410
+ activeIndex: n,
411
+ setActiveIndex: l,
412
+ handleKeyDown: i,
413
+ getOptionProps: f,
414
+ activeDescendantId: h
415
+ };
416
+ }
417
+ function ve(e, t, o, r, a) {
418
+ T(() => {
419
+ var i, f;
420
+ if (e.type !== "reference" || typeof t != "string" || t === "" || e.keywords.some((h) => h.value === t)) return;
421
+ const s = (i = e.meta) == null ? void 0 : i.displayCache;
422
+ if (!s || s.has(t)) return;
423
+ const n = (f = e.meta) == null ? void 0 : f.source;
424
+ if (!(n != null && n.resolveDisplay)) return;
425
+ let l = !1;
426
+ const d = n.resolveDisplay(t);
427
+ return d instanceof Promise ? d.then((h) => {
428
+ l || (s.set(t, h), a({ type: "SET_CHIP_VALUE", clauseId: o, chipId: r, value: t }));
429
+ }) : (s.set(t, d), a({ type: "SET_CHIP_VALUE", clauseId: o, chipId: r, value: t })), () => {
430
+ l = !0;
431
+ };
432
+ }, [e, t]);
433
+ }
434
+ function be(e, t, o, r, a) {
435
+ const s = e.mode, n = s.type === "display" ? s.source : null, l = e.id, d = R(void 0);
436
+ T(() => {
437
+ if (!n || n.type !== "derived") return;
438
+ const i = r.get(t), f = o.clauses[t], h = i && f ? W(t, i, f.chips, r, o.contexts) : {}, u = n.compute(h, o);
439
+ Object.is(u, d.current) || (d.current = u, a({ type: "SET_DISPLAY_VALUE", chipId: l, value: u }));
440
+ }, [n, o, a, l, t, r]), T(() => {
441
+ if (!n || n.type !== "remote") return;
442
+ let i = !0;
443
+ const f = async () => {
444
+ a({ type: "SET_DISPLAY_VALUE", chipId: l, value: void 0, loading: !0 });
445
+ try {
446
+ const u = await fetch(n.url), m = (u.headers.get("content-type") ?? "").includes("application/json") ? await u.json() : await u.text(), v = n.extract(m);
447
+ i && a({ type: "SET_DISPLAY_VALUE", chipId: l, value: v });
448
+ } catch (u) {
449
+ i && a({ type: "SET_DISPLAY_VALUE", chipId: l, value: void 0, error: String(u) });
450
+ }
451
+ };
452
+ f();
453
+ const h = n.interval ? setInterval(f, n.interval) : void 0;
454
+ return () => {
455
+ i = !1, h && clearInterval(h);
456
+ };
457
+ }, [n, l, a]), T(() => !n || n.type !== "external" ? void 0 : n.subscribe((f) => {
458
+ a({ type: "SET_DISPLAY_VALUE", chipId: l, value: f });
459
+ }), [n, l, a]);
460
+ }
461
+ function j(e, t) {
462
+ return typeof e.label == "function" ? e.label(t ?? {}) : e.label;
463
+ }
464
+ function _e({
465
+ value: e,
466
+ min: t,
467
+ max: o,
468
+ step: r = 1,
469
+ onSelect: a,
470
+ onSubmit: s
471
+ }) {
472
+ const n = e === "" ? 0 : Number(e), l = !isNaN(n), d = l ? n : 0, i = t === void 0 || d - r >= t, f = o === void 0 || d + r <= o;
473
+ return /* @__PURE__ */ S("div", { className: "chipper-numeric-input", children: [
474
+ /* @__PURE__ */ c(
475
+ "button",
476
+ {
477
+ type: "button",
478
+ className: "chipper-numeric-input__button",
479
+ onClick: () => {
480
+ i && a(String(d - r));
481
+ },
482
+ disabled: !i,
483
+ "aria-label": "Decrease",
484
+ children: "−"
485
+ }
486
+ ),
487
+ /* @__PURE__ */ c(
488
+ "input",
489
+ {
490
+ type: "text",
491
+ inputMode: "numeric",
492
+ className: "chipper-numeric-input__value",
493
+ value: e,
494
+ onChange: (m) => {
495
+ const v = m.target.value;
496
+ if (v === "" || v === "-") {
497
+ a(v);
498
+ return;
499
+ }
500
+ const x = Number(v);
501
+ isNaN(x) || a(String(x));
502
+ },
503
+ onKeyDown: (m) => {
504
+ m.key === "Enter" && s && s();
505
+ },
506
+ role: "spinbutton",
507
+ "aria-label": "Numeric value",
508
+ "aria-valuemin": t,
509
+ "aria-valuemax": o,
510
+ "aria-valuenow": l ? d : void 0
511
+ }
512
+ ),
513
+ /* @__PURE__ */ c(
514
+ "button",
515
+ {
516
+ type: "button",
517
+ className: "chipper-numeric-input__button",
518
+ onClick: () => {
519
+ f && a(String(d + r));
520
+ },
521
+ disabled: !f,
522
+ "aria-label": "Increase",
523
+ children: "+"
524
+ }
525
+ )
526
+ ] });
527
+ }
528
+ function M({
529
+ groups: e,
530
+ context: t,
531
+ getOptionProps: o,
532
+ isSelected: r,
533
+ isDisabled: a
534
+ }) {
535
+ let s = 0;
536
+ return /* @__PURE__ */ c(z, { children: e.map((n, l) => {
537
+ const d = s;
538
+ s += n.keywords.length;
539
+ const i = n.layout === "grid" ? "chipper-keyword-group__items--grid" : "chipper-keyword-group__items--flow", f = n.layout === "grid" && n.columns ? { "--chipper-group-columns": n.columns } : void 0;
540
+ return /* @__PURE__ */ S("div", { className: "chipper-keyword-group", children: [
541
+ l > 0 && /* @__PURE__ */ c("hr", { className: "chipper-keyword-group__separator" }),
542
+ n.label && /* @__PURE__ */ c("span", { className: "chipper-keyword-group__label", children: n.label }),
543
+ /* @__PURE__ */ S("div", { className: `chipper-keyword-group__items ${i}`, style: f, children: [
544
+ n.prefix && /* @__PURE__ */ c("span", { className: "chipper-keyword-group__prefix", children: n.prefix }),
545
+ n.keywords.map((h, u) => {
546
+ const p = d + u, m = o(p), v = (r == null ? void 0 : r(h)) ?? !1, x = (a == null ? void 0 : a(h)) ?? !1;
547
+ return /* @__PURE__ */ c(
548
+ "button",
549
+ {
550
+ type: "button",
551
+ ...m,
552
+ "aria-selected": v || void 0,
553
+ className: [
554
+ m.className,
555
+ v && "chipper-popup-option--selected"
556
+ ].filter(Boolean).join(" "),
557
+ disabled: x,
558
+ children: j(h, t)
559
+ },
560
+ `${h.value}-${p}`
561
+ );
562
+ })
563
+ ] })
564
+ ] }, l);
565
+ }) });
566
+ }
567
+ function we(e, t) {
568
+ return t.some((o) => o.value === e);
569
+ }
570
+ function ge({
571
+ keywords: e,
572
+ keywordGroups: t,
573
+ value: o,
574
+ expressionMode: r,
575
+ expressionActive: a,
576
+ triggerLabel: s,
577
+ context: n,
578
+ maxLength: l,
579
+ onSelect: d,
580
+ onClose: i
581
+ }) {
582
+ const f = !!s, h = r && (!f || a), u = (r == null ? void 0 : r.inputType) === "number", p = (r == null ? void 0 : r.inputType) === "date", [m, v] = V(
583
+ // No expression visible → no input state needed.
584
+ // Numeric/date inputs always initialize with the current value.
585
+ // Text inputs start empty when the current value is a keyword.
586
+ h ? u || p ? o : we(o, e) ? "" : o : ""
587
+ ), x = R(!1), w = e.length + (f && !a ? 1 : 0), y = e.findIndex((g) => g.value === o && !a), _ = Q({
588
+ itemCount: w,
589
+ initialIndex: y >= 0 ? y : -1,
590
+ onSelect: (g) => {
591
+ g < e.length ? (x.current = !0, d(e[g].value)) : d(ne);
592
+ },
593
+ onClose: i,
594
+ idPrefix: "chipper-koe-option"
595
+ }), N = R(m);
596
+ N.current = m;
597
+ const k = () => {
598
+ if (!r) return;
599
+ const g = m.trim();
600
+ g && r.validate(g) && (d(g), i());
601
+ };
602
+ T(() => () => {
603
+ if (!r || x.current || u || !h) return;
604
+ const g = N.current.trim();
605
+ g && g !== o && r.validate(g) && d(g);
606
+ }, []);
607
+ const K = (r == null ? void 0 : r.position) === "above", I = e.length > 0 && (t ? /* @__PURE__ */ c("div", { className: "chipper-koe-popup__keywords chipper-koe-popup__keywords--grouped", children: /* @__PURE__ */ c(
608
+ M,
609
+ {
610
+ groups: t,
611
+ context: n,
612
+ getOptionProps: _.getOptionProps,
613
+ isSelected: (g) => g.value === o && !a
614
+ }
615
+ ) }) : /* @__PURE__ */ c("div", { className: "chipper-koe-popup__keywords", children: e.map((g, C) => {
616
+ const A = _.getOptionProps(C);
617
+ return /* @__PURE__ */ c(
618
+ "button",
619
+ {
620
+ type: "button",
621
+ ...A,
622
+ className: [
623
+ A.className,
624
+ g.value === o && !a && "chipper-popup-option--selected"
625
+ ].filter(Boolean).join(" "),
626
+ children: j(g, n)
627
+ },
628
+ g.value
629
+ );
630
+ }) })), E = f && !a && /* @__PURE__ */ c("div", { className: "chipper-koe-popup__trigger", children: /* @__PURE__ */ c(
631
+ "button",
632
+ {
633
+ type: "button",
634
+ ..._.getOptionProps(e.length),
635
+ children: s
636
+ }
637
+ ) }), O = h && /* @__PURE__ */ S(z, { children: [
638
+ e.length > 0 && /* @__PURE__ */ c("hr", { className: "chipper-koe-popup__separator" }),
639
+ /* @__PURE__ */ S("div", { className: "chipper-koe-popup__input-row", children: [
640
+ r.prefix && /* @__PURE__ */ c("span", { className: "chipper-koe-popup__affix", children: typeof r.prefix == "function" ? r.prefix(n ?? {}) : r.prefix }),
641
+ r.inputType === "number" ? /* @__PURE__ */ c(
642
+ _e,
643
+ {
644
+ value: m,
645
+ min: r.min,
646
+ max: r.max,
647
+ step: r.step,
648
+ onSelect: (g) => {
649
+ v(g), r.validate(g) && d(g);
650
+ },
651
+ onSubmit: () => {
652
+ r.validate(m) && (d(m), i());
653
+ }
654
+ }
655
+ ) : r.inputType === "date" ? /* @__PURE__ */ c(
656
+ "input",
657
+ {
658
+ type: "date",
659
+ className: "chipper-koe-popup__input",
660
+ value: m,
661
+ onChange: (g) => {
662
+ const C = g.target.value;
663
+ v(C), C && r.validate(C) && (d(C), i());
664
+ },
665
+ autoFocus: e.length === 0
666
+ }
667
+ ) : /* @__PURE__ */ c(
668
+ "input",
669
+ {
670
+ type: "text",
671
+ className: "chipper-koe-popup__input",
672
+ value: m,
673
+ onChange: (g) => v(g.target.value),
674
+ onKeyDown: (g) => {
675
+ g.key === "Enter" ? _.activeIndex >= 0 && _.activeIndex < e.length ? _.handleKeyDown(g) : k() : _.handleKeyDown(g);
676
+ },
677
+ placeholder: r.label,
678
+ maxLength: l,
679
+ autoFocus: e.length === 0,
680
+ "aria-activedescendant": _.activeDescendantId,
681
+ role: "combobox",
682
+ "aria-expanded": !0
683
+ }
684
+ ),
685
+ r.suffix && /* @__PURE__ */ c("span", { className: "chipper-koe-popup__affix", children: typeof r.suffix == "function" ? r.suffix(n ?? {}) : r.suffix })
686
+ ] })
687
+ ] });
688
+ return /* @__PURE__ */ c(
689
+ "div",
690
+ {
691
+ className: "chipper-koe-popup",
692
+ onKeyDown: h ? void 0 : _.handleKeyDown,
693
+ tabIndex: h ? void 0 : 0,
694
+ "aria-activedescendant": h ? void 0 : _.activeDescendantId,
695
+ children: K ? /* @__PURE__ */ S(z, { children: [
696
+ O,
697
+ I,
698
+ E
699
+ ] }) : /* @__PURE__ */ S(z, { children: [
700
+ I,
701
+ E,
702
+ O
703
+ ] })
704
+ }
705
+ );
706
+ }
707
+ function xe({
708
+ options: e,
709
+ optionGroups: t,
710
+ keywords: o,
711
+ value: r,
712
+ maxSelections: a,
713
+ onSelect: s,
714
+ onClose: n
715
+ }) {
716
+ const l = new Set(r), d = [
717
+ ...o.map((p) => ({ type: "keyword", keyword: p })),
718
+ ...e.map((p) => ({ type: "option", option: p }))
719
+ ], i = Q({
720
+ itemCount: d.length,
721
+ onSelect: (p) => {
722
+ const m = d[p];
723
+ m.type === "keyword" ? h(m.keyword.value) : f(m.option.value);
724
+ },
725
+ onClose: n ?? (() => {
726
+ }),
727
+ closeOnSelect: !1,
728
+ idPrefix: "chipper-multi-option"
729
+ }), f = (p) => {
730
+ if (l.has(p))
731
+ s(r.filter((m) => m !== p));
732
+ else {
733
+ if (a !== void 0 && r.length >= a) return;
734
+ s([...r, p]);
735
+ }
736
+ }, h = (p) => {
737
+ s(p);
738
+ }, u = o.length;
739
+ return /* @__PURE__ */ S(
740
+ "div",
741
+ {
742
+ className: "chipper-multi-select-popup",
743
+ onKeyDown: i.handleKeyDown,
744
+ tabIndex: 0,
745
+ "aria-activedescendant": i.activeDescendantId,
746
+ children: [
747
+ o.length > 0 && /* @__PURE__ */ c("div", { className: "chipper-multi-select-popup__keywords", children: o.map((p, m) => {
748
+ const v = re(l, r.length, p.value), x = i.getOptionProps(m);
749
+ return /* @__PURE__ */ c(
750
+ "button",
751
+ {
752
+ type: "button",
753
+ ...x,
754
+ "aria-selected": v,
755
+ className: [
756
+ x.className,
757
+ v && "chipper-popup-option--selected"
758
+ ].filter(Boolean).join(" "),
759
+ children: j(p)
760
+ },
761
+ String(p.value)
762
+ );
763
+ }) }),
764
+ t ? /* @__PURE__ */ c("div", { className: "chipper-multi-select-popup__grid", children: /* @__PURE__ */ c(
765
+ M,
766
+ {
767
+ groups: t,
768
+ getOptionProps: (p) => i.getOptionProps(u + p),
769
+ isSelected: (p) => l.has(p.value),
770
+ isDisabled: (p) => !l.has(p.value) && a !== void 0 && r.length >= a
771
+ }
772
+ ) }) : /* @__PURE__ */ c("div", { className: "chipper-multi-select-popup__grid", children: e.map((p, m) => {
773
+ const v = l.has(p.value), x = !v && a !== void 0 && r.length >= a, w = i.getOptionProps(u + m);
774
+ return /* @__PURE__ */ c(
775
+ "button",
776
+ {
777
+ type: "button",
778
+ ...w,
779
+ "aria-selected": v,
780
+ className: [
781
+ w.className,
782
+ v && "chipper-popup-option--selected"
783
+ ].filter(Boolean).join(" "),
784
+ disabled: x,
785
+ children: j(p)
786
+ },
787
+ p.value
788
+ );
789
+ }) })
790
+ ]
791
+ }
792
+ );
793
+ }
794
+ function Ne(e, t) {
795
+ var o;
796
+ if (t === "") return 0;
797
+ for (let r = 0; r < e.length; r++) {
798
+ const a = e[r];
799
+ if (a.slots.length === 1 && a.slots[0].keywords.some((s) => s.value === t) || a.slots.length > 1 && a.decompose && a.decompose(t).every((n) => n !== void 0) || (o = a.expression) != null && o.validate && a.expression.validate(t))
800
+ return r;
801
+ }
802
+ return 0;
803
+ }
804
+ function ee(e, t) {
805
+ if (e.decompose && t !== "") {
806
+ const o = e.decompose(t);
807
+ if (o.every((r) => r !== void 0)) return o;
808
+ }
809
+ return new Array(e.slots.length).fill(void 0);
810
+ }
811
+ function ke({
812
+ modes: e,
813
+ value: t,
814
+ onSelect: o,
815
+ onClose: r
816
+ }) {
817
+ const [a, s] = V(
818
+ () => Ne(e, t)
819
+ ), n = e[a], [l, d] = V(
820
+ () => ee(n, t)
821
+ ), [i, f] = V(""), h = (y) => {
822
+ s(y);
823
+ const _ = e[y];
824
+ d(ee(_, t)), f("");
825
+ }, u = (y, _) => {
826
+ const N = [...l];
827
+ if (N[y] = _, d(N), N.every((k) => k !== void 0)) {
828
+ const k = n.compose(...N);
829
+ o(k), r();
830
+ }
831
+ }, p = () => {
832
+ var N;
833
+ const y = i.trim();
834
+ if (!y) return;
835
+ (((N = n.expression) == null ? void 0 : N.validate) ?? ((k) => k.length > 0))(y) && (o(y), r());
836
+ }, m = [];
837
+ for (let y = 0; y < n.slots.length; y++)
838
+ for (let _ = 0; _ < n.slots[y].keywords.length; _++)
839
+ m.push({ slotIndex: y, keywordIndex: _ });
840
+ const v = Q({
841
+ itemCount: m.length,
842
+ onSelect: (y) => {
843
+ const _ = m[y], N = n.slots[_.slotIndex].keywords[_.keywordIndex];
844
+ u(_.slotIndex, N.value);
845
+ },
846
+ onClose: r,
847
+ closeOnSelect: !1,
848
+ // multi-slot modes stay open until all filled
849
+ idPrefix: "chipper-alt-option"
850
+ }), x = (y) => {
851
+ y.key === "ArrowLeft" ? (y.preventDefault(), h(a > 0 ? a - 1 : e.length - 1)) : y.key === "ArrowRight" && (y.preventDefault(), h(a < e.length - 1 ? a + 1 : 0));
852
+ };
853
+ let w = 0;
854
+ return /* @__PURE__ */ S(
855
+ "div",
856
+ {
857
+ className: "chipper-alt-coord-popup",
858
+ onKeyDown: n.expression ? void 0 : v.handleKeyDown,
859
+ tabIndex: n.expression ? void 0 : 0,
860
+ "aria-activedescendant": n.expression ? void 0 : v.activeDescendantId,
861
+ children: [
862
+ e.length > 1 && /* @__PURE__ */ c("div", { className: "chipper-alt-coord-popup__tabs", role: "tablist", onKeyDown: x, children: e.map((y, _) => /* @__PURE__ */ c(
863
+ "button",
864
+ {
865
+ type: "button",
866
+ role: "tab",
867
+ className: [
868
+ "chipper-alt-coord-popup__tab",
869
+ _ === a && "chipper-alt-coord-popup__tab--active"
870
+ ].filter(Boolean).join(" "),
871
+ "aria-selected": _ === a,
872
+ onClick: () => h(_),
873
+ children: y.label
874
+ },
875
+ y.id
876
+ )) }),
877
+ /* @__PURE__ */ S("div", { className: "chipper-alt-coord-popup__content", children: [
878
+ n.slots.map((y, _) => {
879
+ const N = w;
880
+ return w += y.keywords.length, y.keywordGroups ? /* @__PURE__ */ S("div", { className: "chipper-alt-coord-popup__slot", children: [
881
+ y.prefix && !y.keywordGroups.some((k) => k.prefix) && /* @__PURE__ */ c("span", { className: "chipper-alt-coord-popup__slot-prefix", children: y.prefix }),
882
+ /* @__PURE__ */ c(
883
+ M,
884
+ {
885
+ groups: y.keywordGroups,
886
+ getOptionProps: (k) => v.getOptionProps(N + k),
887
+ isSelected: (k) => l[_] === k.value
888
+ }
889
+ )
890
+ ] }, _) : /* @__PURE__ */ c("div", { className: "chipper-alt-coord-popup__slot", children: /* @__PURE__ */ S("div", { className: "chipper-alt-coord-popup__slot-keywords", children: [
891
+ y.prefix && /* @__PURE__ */ c("span", { className: "chipper-alt-coord-popup__slot-prefix", children: y.prefix }),
892
+ y.keywords.map((k, K) => {
893
+ const I = l[_] === k.value, E = v.getOptionProps(N + K);
894
+ return /* @__PURE__ */ c(
895
+ "button",
896
+ {
897
+ type: "button",
898
+ ...E,
899
+ "aria-selected": I,
900
+ className: [
901
+ E.className,
902
+ I && "chipper-popup-option--selected"
903
+ ].filter(Boolean).join(" "),
904
+ children: j(k)
905
+ },
906
+ k.value
907
+ );
908
+ })
909
+ ] }) }, _);
910
+ }),
911
+ n.expression && /* @__PURE__ */ c("div", { className: "chipper-alt-coord-popup__expression", children: /* @__PURE__ */ c(
912
+ "input",
913
+ {
914
+ type: "text",
915
+ className: "chipper-koe-popup__input",
916
+ value: i,
917
+ onChange: (y) => f(y.target.value),
918
+ onKeyDown: (y) => {
919
+ y.key === "Enter" ? v.activeIndex >= 0 ? v.handleKeyDown(y) : p() : v.handleKeyDown(y);
920
+ },
921
+ placeholder: n.expression.placeholder,
922
+ maxLength: n.expression.maxLength,
923
+ "aria-activedescendant": v.activeDescendantId,
924
+ role: "combobox",
925
+ "aria-expanded": !0
926
+ }
927
+ ) })
928
+ ] })
929
+ ]
930
+ }
931
+ );
932
+ }
933
+ const De = 300;
934
+ function Se({
935
+ source: e,
936
+ keywords: t,
937
+ value: o,
938
+ onSelect: r,
939
+ onClose: a,
940
+ displayCache: s
941
+ }) {
942
+ const [n, l] = V([]), [d, i] = V([]), [f, h] = V(!0), [u, p] = V(null), [m, v] = V(""), [x, w] = V(null), [y, _] = V(!1), N = R(void 0), k = R(0), K = B(
943
+ (b) => {
944
+ const D = ++k.current;
945
+ h(!0), p(null);
946
+ try {
947
+ const P = e.getItems(b);
948
+ P instanceof Promise ? P.then((L) => {
949
+ D === k.current && (i(L), h(!1));
950
+ }).catch((L) => {
951
+ D === k.current && (p(L instanceof Error ? L.message : "Failed to load items"), h(!1));
952
+ }) : (i(P), h(!1));
953
+ } catch (P) {
954
+ p(P instanceof Error ? P.message : "Failed to load items"), h(!1);
955
+ }
956
+ },
957
+ [e]
958
+ );
959
+ T(() => {
960
+ K([]);
961
+ }, [K]);
962
+ const I = B(
963
+ (b) => {
964
+ const D = [...n, b];
965
+ l(D), v(""), w(null), K(D);
966
+ },
967
+ [n, K]
968
+ ), E = B(
969
+ (b) => {
970
+ const D = b < 0 ? [] : n.slice(0, b + 1);
971
+ l(D), v(""), w(null), K(D);
972
+ },
973
+ [n, K]
974
+ ), O = B(
975
+ (b) => {
976
+ s.set(b.id, b.label), r(b.id), a();
977
+ },
978
+ [r, a, s]
979
+ ), g = B(
980
+ (b) => {
981
+ if (v(b), N.current && clearTimeout(N.current), !b.trim() || !e.search) {
982
+ w(null), _(!1);
983
+ return;
984
+ }
985
+ _(!0), N.current = setTimeout(() => {
986
+ try {
987
+ const D = e.search(b.trim());
988
+ D instanceof Promise ? D.then((P) => {
989
+ w(P), _(!1);
990
+ }).catch(() => {
991
+ w([]), _(!1);
992
+ }) : (w(D), _(!1));
993
+ } catch {
994
+ w([]), _(!1);
995
+ }
996
+ }, De);
997
+ },
998
+ [e]
999
+ );
1000
+ T(() => () => {
1001
+ N.current && clearTimeout(N.current);
1002
+ }, []);
1003
+ const C = x !== null, A = C ? x : d, $ = C ? y : f, F = t.length + ($ ? 0 : A.length), G = Q({
1004
+ itemCount: F,
1005
+ closeOnSelect: !1,
1006
+ onSelect: (b) => {
1007
+ if (b < t.length)
1008
+ r(t[b].value), a();
1009
+ else {
1010
+ const D = A[b - t.length], P = D.selectable !== !1, L = D.hasChildren === !0;
1011
+ P ? O(D) : L && I(D);
1012
+ }
1013
+ },
1014
+ onClose: a,
1015
+ idPrefix: "chipper-ref-option"
1016
+ });
1017
+ return /* @__PURE__ */ S("div", { className: "chipper-reference-popup", children: [
1018
+ t.length > 0 && /* @__PURE__ */ c("div", { className: "chipper-reference-popup__keywords", children: t.map((b, D) => {
1019
+ const P = G.getOptionProps(D);
1020
+ return /* @__PURE__ */ c(
1021
+ "button",
1022
+ {
1023
+ type: "button",
1024
+ ...P,
1025
+ "aria-selected": b.value === o,
1026
+ className: [
1027
+ P.className,
1028
+ b.value === o && "chipper-popup-option--selected"
1029
+ ].filter(Boolean).join(" "),
1030
+ children: j(b)
1031
+ },
1032
+ b.value
1033
+ );
1034
+ }) }),
1035
+ !C && n.length > 0 && /* @__PURE__ */ S("nav", { className: "chipper-reference-popup__breadcrumb", children: [
1036
+ /* @__PURE__ */ c(
1037
+ "button",
1038
+ {
1039
+ type: "button",
1040
+ className: "chipper-reference-popup__breadcrumb-segment",
1041
+ "aria-label": "all items",
1042
+ onClick: () => E(-1),
1043
+ children: "all"
1044
+ }
1045
+ ),
1046
+ n.map((b, D) => /* @__PURE__ */ S("span", { children: [
1047
+ /* @__PURE__ */ c("span", { className: "chipper-reference-popup__breadcrumb-separator", children: "›" }),
1048
+ D < n.length - 1 ? /* @__PURE__ */ c(
1049
+ "button",
1050
+ {
1051
+ type: "button",
1052
+ className: "chipper-reference-popup__breadcrumb-segment",
1053
+ onClick: () => E(D),
1054
+ children: b.label
1055
+ }
1056
+ ) : /* @__PURE__ */ c("span", { className: "chipper-reference-popup__breadcrumb-current", children: b.label })
1057
+ ] }, b.id))
1058
+ ] }),
1059
+ /* @__PURE__ */ S("div", { className: "chipper-reference-popup__items", "aria-live": "polite", children: [
1060
+ $ && /* @__PURE__ */ c("div", { className: "chipper-reference-popup__loading", children: "Loading…" }),
1061
+ !$ && u && /* @__PURE__ */ S("div", { className: "chipper-reference-popup__empty", children: [
1062
+ /* @__PURE__ */ c("span", { children: u }),
1063
+ /* @__PURE__ */ c(
1064
+ "button",
1065
+ {
1066
+ type: "button",
1067
+ className: "chipper-reference-popup__retry",
1068
+ onClick: () => K(n),
1069
+ children: "Retry"
1070
+ }
1071
+ )
1072
+ ] }),
1073
+ !$ && !u && A.length === 0 && /* @__PURE__ */ c("div", { className: "chipper-reference-popup__empty", children: C ? `No results for '${m}'` : "No items" }),
1074
+ !$ && !u && A.map((b, D) => {
1075
+ const P = b.selectable !== !1, L = b.hasChildren === !0, Y = G.getOptionProps(t.length + D);
1076
+ return !P && L ? /* @__PURE__ */ S(
1077
+ "button",
1078
+ {
1079
+ type: "button",
1080
+ ...Y,
1081
+ onClick: () => I(b),
1082
+ className: [
1083
+ "chipper-reference-popup__item chipper-reference-popup__item--non-selectable",
1084
+ Y.className
1085
+ ].filter(Boolean).join(" "),
1086
+ "aria-label": `expand ${b.label}`,
1087
+ children: [
1088
+ /* @__PURE__ */ c("span", { className: "chipper-reference-popup__item-label", children: b.label }),
1089
+ /* @__PURE__ */ c("span", { className: "chipper-reference-popup__item-drill", children: "▸" })
1090
+ ]
1091
+ },
1092
+ b.id
1093
+ ) : /* @__PURE__ */ S("div", { className: "chipper-reference-popup__item", children: [
1094
+ P ? /* @__PURE__ */ c(
1095
+ "button",
1096
+ {
1097
+ type: "button",
1098
+ ...Y,
1099
+ className: [
1100
+ "chipper-reference-popup__item-label",
1101
+ Y.className,
1102
+ b.id === o && "chipper-reference-popup__item-label--selected"
1103
+ ].filter(Boolean).join(" "),
1104
+ children: b.label
1105
+ }
1106
+ ) : /* @__PURE__ */ c("span", { className: "chipper-reference-popup__item-label chipper-reference-popup__item-label--inert", children: b.label }),
1107
+ L && /* @__PURE__ */ c(
1108
+ "button",
1109
+ {
1110
+ type: "button",
1111
+ className: "chipper-reference-popup__item-drill",
1112
+ "aria-label": `expand ${b.label}`,
1113
+ onClick: () => I(b),
1114
+ children: "▸"
1115
+ }
1116
+ )
1117
+ ] }, b.id);
1118
+ })
1119
+ ] }),
1120
+ e.search && /* @__PURE__ */ c("div", { className: "chipper-reference-popup__search-row", children: /* @__PURE__ */ c(
1121
+ "input",
1122
+ {
1123
+ type: "text",
1124
+ className: "chipper-reference-popup__search",
1125
+ value: m,
1126
+ onChange: (b) => g(b.target.value),
1127
+ onKeyDown: (b) => {
1128
+ b.key === "Enter" && G.activeIndex >= 0, G.handleKeyDown(b);
1129
+ },
1130
+ placeholder: "Search…",
1131
+ "aria-label": "search items",
1132
+ "aria-activedescendant": G.activeDescendantId,
1133
+ role: "combobox",
1134
+ "aria-expanded": !0
1135
+ }
1136
+ ) })
1137
+ ] });
1138
+ }
1139
+ function Ee({ chipId: e, domain: t, value: o, expressionActive: r, context: a, onSelect: s, onClose: n }) {
1140
+ const l = R(null);
1141
+ T(() => {
1142
+ const i = (f) => {
1143
+ f.key === "Escape" && n();
1144
+ };
1145
+ return document.addEventListener("keydown", i), () => document.removeEventListener("keydown", i);
1146
+ }, [n]), T(() => {
1147
+ const i = (h) => {
1148
+ if (h.key === "Tab" && l.current) {
1149
+ const u = l.current.querySelectorAll(
1150
+ 'button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])'
1151
+ );
1152
+ if (u.length === 0) return;
1153
+ const p = u[0], m = u[u.length - 1];
1154
+ h.shiftKey && document.activeElement === p ? (h.preventDefault(), m.focus()) : !h.shiftKey && document.activeElement === m && (h.preventDefault(), p.focus());
1155
+ }
1156
+ }, f = l.current;
1157
+ return f == null || f.addEventListener("keydown", i), () => f == null ? void 0 : f.removeEventListener("keydown", i);
1158
+ }, []), T(() => {
1159
+ const i = (h) => {
1160
+ l.current && !l.current.contains(h.target) && n();
1161
+ }, f = setTimeout(() => {
1162
+ document.addEventListener("mousedown", i);
1163
+ }, 0);
1164
+ return () => {
1165
+ clearTimeout(f), document.removeEventListener("mousedown", i);
1166
+ };
1167
+ }, [n]);
1168
+ const d = () => {
1169
+ var i, f, h, u, p, m, v;
1170
+ switch (t.type) {
1171
+ case "keyword-or-expression": {
1172
+ const x = t.expressionModes[0], w = (i = t.meta) == null ? void 0 : i.trigger;
1173
+ return /* @__PURE__ */ c(
1174
+ ge,
1175
+ {
1176
+ keywords: t.keywords,
1177
+ keywordGroups: t.keywordGroups,
1178
+ value: o,
1179
+ expressionMode: x,
1180
+ expressionActive: r,
1181
+ triggerLabel: w == null ? void 0 : w.label,
1182
+ context: a,
1183
+ maxLength: x == null ? void 0 : x.maxLength,
1184
+ onSelect: s,
1185
+ onClose: n
1186
+ }
1187
+ );
1188
+ }
1189
+ case "multi-select":
1190
+ return /* @__PURE__ */ c(
1191
+ xe,
1192
+ {
1193
+ options: (f = t.meta) == null ? void 0 : f.options,
1194
+ optionGroups: (h = t.meta) == null ? void 0 : h.optionGroups,
1195
+ keywords: t.keywords,
1196
+ value: o,
1197
+ maxSelections: (u = t.meta) == null ? void 0 : u.maxSelections,
1198
+ onSelect: s,
1199
+ onClose: n
1200
+ }
1201
+ );
1202
+ case "alternative-coordinate":
1203
+ return /* @__PURE__ */ c(
1204
+ ke,
1205
+ {
1206
+ modes: (p = t.meta) == null ? void 0 : p.modes,
1207
+ value: o,
1208
+ onSelect: s,
1209
+ onClose: n
1210
+ }
1211
+ );
1212
+ case "reference":
1213
+ return /* @__PURE__ */ c(
1214
+ Se,
1215
+ {
1216
+ source: (m = t.meta) == null ? void 0 : m.source,
1217
+ keywords: t.keywords,
1218
+ value: o,
1219
+ onSelect: s,
1220
+ onClose: n,
1221
+ displayCache: (v = t.meta) == null ? void 0 : v.displayCache
1222
+ }
1223
+ );
1224
+ default:
1225
+ return /* @__PURE__ */ S("div", { children: [
1226
+ "Unsupported domain type: ",
1227
+ t.type
1228
+ ] });
1229
+ }
1230
+ };
1231
+ return T(() => {
1232
+ if (!l.current) return;
1233
+ const i = l.current.querySelector(
1234
+ 'input:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])'
1235
+ );
1236
+ i == null || i.focus();
1237
+ }, []), /* @__PURE__ */ c(
1238
+ "div",
1239
+ {
1240
+ ref: l,
1241
+ id: `chipper-popup-${e}`,
1242
+ className: "chipper-popup chipper-popup--open",
1243
+ role: "listbox",
1244
+ "aria-label": t.placeholder ?? t.type,
1245
+ children: d()
1246
+ }
1247
+ );
1248
+ }
1249
+ function Le({ content: e, onClose: t }) {
1250
+ const o = R(null);
1251
+ return T(() => {
1252
+ const r = (a) => {
1253
+ o.current && !o.current.contains(a.target) && setTimeout(t, 0);
1254
+ };
1255
+ return document.addEventListener("mousedown", r), () => document.removeEventListener("mousedown", r);
1256
+ }, [t]), T(() => {
1257
+ const r = (a) => {
1258
+ a.key === "Escape" && t();
1259
+ };
1260
+ return document.addEventListener("keydown", r), () => document.removeEventListener("keydown", r);
1261
+ }, [t]), /* @__PURE__ */ S("div", { ref: o, className: "chipper-chip-info", role: "dialog", "aria-label": "Chip information", children: [
1262
+ /* @__PURE__ */ c("div", { className: "chipper-chip-info__caret" }),
1263
+ /* @__PURE__ */ c("div", { className: "chipper-chip-info__content", children: e })
1264
+ ] });
1265
+ }
1266
+ function Ce({ clauseId: e, chipId: t }) {
1267
+ const { displayValue: o, valid: r, domain: a, chipDefinition: s, value: n, expressionMode: l, loading: d, error: i, setValue: f } = oe(e, t), { definition: h, state: u, clauseById: p, dispatch: m } = X(), { open: v, close: x, isOpen: w } = ae();
1268
+ ve(a, n, e, t, m), be(s, e, u, p, m);
1269
+ const y = R(null), _ = H(
1270
+ () => a.expressionModes.some(
1271
+ (L) => typeof L.prefix == "function" || typeof L.suffix == "function"
1272
+ ),
1273
+ [a.expressionModes]
1274
+ ), N = _ ? p.get(e) : void 0, k = _ ? u.clauses[e] : void 0, K = H(
1275
+ () => _ && N && k ? W(e, N, k.chips, p, u.contexts) : void 0,
1276
+ [_, e, N, k, p, u.contexts]
1277
+ ), I = s.mode.type === "interactive", E = s.mode.type === "display" ? s.mode : void 0, O = E != null, g = (E == null ? void 0 : E.info) != null, C = w(t), A = !r, $ = () => {
1278
+ y.current && (!I && !g || (C ? (x(), y.current.focus()) : v(e, t, y.current)));
1279
+ }, F = B(() => {
1280
+ var L;
1281
+ x(), (L = y.current) == null || L.focus();
1282
+ }, [x]), G = [
1283
+ "chipper-chip-trigger",
1284
+ A && "chipper-chip-trigger--placeholder",
1285
+ C && "chipper-chip-trigger--expanded",
1286
+ O && "chipper-chip-trigger--display",
1287
+ d && "chipper-chip-trigger--loading",
1288
+ i && "chipper-chip-trigger--error"
1289
+ ].filter(Boolean).join(" "), b = {
1290
+ "--chip-trigger-color-text": `var(--chipper-color-${a.color}-text)`,
1291
+ "--chip-trigger-color-bg": `var(--chipper-color-${a.color}-bg)`,
1292
+ "--chip-trigger-color-hover": `var(--chipper-color-${a.color}-hover)`,
1293
+ "--chip-trigger-color-glow": `var(--chipper-color-${a.color}-glow, rgba(0, 0, 0, 0.12))`
1294
+ }, D = H(() => {
1295
+ if (!(E != null && E.info)) return;
1296
+ const L = E.info;
1297
+ return typeof L == "function" ? L(n, u) : L;
1298
+ }, [E, n, u]);
1299
+ return /* @__PURE__ */ S("span", { className: "chipper-chip", style: b, children: [
1300
+ I || g ? /* @__PURE__ */ c(
1301
+ "button",
1302
+ {
1303
+ ref: y,
1304
+ type: "button",
1305
+ className: G,
1306
+ onClick: $,
1307
+ "aria-expanded": C,
1308
+ "aria-haspopup": I ? "listbox" : g ? "dialog" : void 0,
1309
+ "aria-invalid": !r || void 0,
1310
+ "aria-controls": C ? `chipper-popup-${t}` : void 0,
1311
+ children: /* @__PURE__ */ c("span", { className: "chipper-chip-trigger__text", children: o })
1312
+ }
1313
+ ) : /* @__PURE__ */ c("span", { className: G, children: /* @__PURE__ */ c("span", { className: "chipper-chip-trigger__text", children: o }) }),
1314
+ C && I && /* @__PURE__ */ c(
1315
+ Ee,
1316
+ {
1317
+ clauseId: e,
1318
+ chipId: t,
1319
+ domain: a,
1320
+ value: n,
1321
+ expressionActive: l,
1322
+ context: K,
1323
+ onSelect: f,
1324
+ onClose: F
1325
+ }
1326
+ ),
1327
+ C && g && D && /* @__PURE__ */ c(
1328
+ Le,
1329
+ {
1330
+ content: D,
1331
+ onClose: F
1332
+ }
1333
+ )
1334
+ ] });
1335
+ }
1336
+ function Pe({ clauseId: e }) {
1337
+ const { state: t, dispatch: o, domains: r, clauseById: a } = X(), s = a.get(e), n = t.clauses[e];
1338
+ if (!s || s.contingency && !(n != null && n.present))
1339
+ return null;
1340
+ if (s.necessity === "optional" && !(n != null && n.active))
1341
+ return /* @__PURE__ */ S("div", { className: "chipper-clause chipper-clause--dormant", children: [
1342
+ /* @__PURE__ */ c(
1343
+ "button",
1344
+ {
1345
+ type: "button",
1346
+ className: "chipper-clause__toggle",
1347
+ "aria-label": "activate clause",
1348
+ onClick: () => o({ type: "TOGGLE_CLAUSE", clauseId: e }),
1349
+ children: "↳"
1350
+ }
1351
+ ),
1352
+ s.segments.map((i, f) => {
1353
+ if (i.type === "text")
1354
+ return typeof i.value == "function" ? null : /* @__PURE__ */ c("span", { className: "chipper-clause__text", children: i.value }, f);
1355
+ if (n != null && n.visibleChips && !n.visibleChips.includes(i.chipId))
1356
+ return null;
1357
+ const h = n == null ? void 0 : n.chips[i.chipId], u = r[i.chipId], p = h ? h.valid ? h.displayValue : (u == null ? void 0 : u.placeholder) ?? h.displayValue : (u == null ? void 0 : u.placeholder) ?? i.chipId;
1358
+ return /* @__PURE__ */ c("span", { className: "chipper-clause__text", children: p }, i.chipId);
1359
+ })
1360
+ ] });
1361
+ const l = s.segments.some(
1362
+ (i) => i.type === "text" && i.present
1363
+ ), d = H(() => !l || !n ? {} : W(e, s, n.chips, a, t.contexts), [l, e, s, n, a, t.contexts]);
1364
+ return /* @__PURE__ */ S("div", { className: "chipper-clause", children: [
1365
+ s.necessity === "optional" && /* @__PURE__ */ c(
1366
+ "button",
1367
+ {
1368
+ type: "button",
1369
+ className: "chipper-clause__toggle",
1370
+ "aria-label": "deactivate clause",
1371
+ onClick: () => o({ type: "TOGGLE_CLAUSE", clauseId: e }),
1372
+ children: "×"
1373
+ }
1374
+ ),
1375
+ s.segments.map((i, f) => {
1376
+ if (i.type === "text") {
1377
+ if (i.present && !i.present(d))
1378
+ return null;
1379
+ const h = typeof i.value == "function" ? i.value(t) : i.value;
1380
+ return h ? /* @__PURE__ */ c("span", { className: "chipper-clause__text", children: h }, f) : null;
1381
+ }
1382
+ return n != null && n.visibleChips && !n.visibleChips.includes(i.chipId) ? null : /* @__PURE__ */ c(Ce, { clauseId: e, chipId: i.chipId }, i.chipId);
1383
+ })
1384
+ ] });
1385
+ }
1386
+ function Ie(e, t) {
1387
+ if (e.indent !== void 0) return e.indent;
1388
+ let o = !1;
1389
+ return e.clauseIds.every((a) => {
1390
+ const s = t.get(a);
1391
+ return s ? (s.necessity === "optional" && (o = !0), s.necessity === "optional" || !!s.contingency) : !1;
1392
+ }) && o;
1393
+ }
1394
+ function Ke({ line: e, clausesByIds: t }) {
1395
+ const r = Ie(e, t) ? "chipper-line chipper-line--indent" : "chipper-line";
1396
+ return /* @__PURE__ */ c("div", { className: r, children: e.clauseIds.map((a) => /* @__PURE__ */ c(Pe, { clauseId: a }, a)) });
1397
+ }
1398
+ function Te() {
1399
+ const { definition: e } = X(), t = new Map(
1400
+ e.clauses.map((r) => [r.id, r])
1401
+ ), o = (e.lines ?? e.clauses.map((r) => ({ clauseIds: [r.id] }))).filter((r) => r.clauseIds.length > 0);
1402
+ return /* @__PURE__ */ c("div", { className: "chipper-sentence", children: o.map((r, a) => /* @__PURE__ */ c(Ke, { line: r, clausesByIds: t }, a)) });
1403
+ }
1404
+ function qe({ sentence: e, initialValues: t, onChange: o, children: r }) {
1405
+ return /* @__PURE__ */ c(se, { definition: e, initialValues: t, onChange: o, children: r ?? /* @__PURE__ */ c(Te, {}) });
1406
+ }
1407
+ export {
1408
+ ke as AlternativeCoordinatePopup,
1409
+ Ce as Chip,
1410
+ Ee as ChipPopup,
1411
+ qe as Chipper,
1412
+ Pe as Clause,
1413
+ ge as KeywordOrExpressionPopup,
1414
+ xe as MultiSelectPopup,
1415
+ Se as ReferencePopup,
1416
+ Te as Sentence,
1417
+ se as SentenceProvider,
1418
+ Fe as alternativeCoordinateDomain,
1419
+ We as builder,
1420
+ Xe as chip,
1421
+ Ze as createPalette,
1422
+ $e as dateDomain,
1423
+ ue as dateExpression,
1424
+ Me as deserialize,
1425
+ Ge as expressionDomain,
1426
+ et as extendPalette,
1427
+ tt as initializeSentenceState,
1428
+ He as isNumeric,
1429
+ ze as isOneOf,
1430
+ je as keywordDomain,
1431
+ U as keywordOrExpressionDomain,
1432
+ Ue as multiSelectDomain,
1433
+ Re as numberDomain,
1434
+ pe as numericExpression,
1435
+ Ye as referenceDomain,
1436
+ rt as repeating,
1437
+ nt as sentence,
1438
+ ot as sentenceReducer,
1439
+ at as serialize,
1440
+ Be as textDomain,
1441
+ ce as textExpression,
1442
+ oe as useChip,
1443
+ ae as usePopup,
1444
+ X as useSentence
1445
+ };