@kopexa/extension-controlref 1.0.0 → 2.0.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 (126) hide show
  1. package/dist/chunk-4C72VBLP.mjs +52 -0
  2. package/dist/chunk-A7FWOQDN.mjs +210 -0
  3. package/dist/chunk-AQTNFDGA.mjs +57 -0
  4. package/dist/chunk-D53W4HWR.mjs +245 -0
  5. package/dist/chunk-FTEE5U3H.mjs +37 -0
  6. package/dist/chunk-GYDJVHHG.mjs +250 -0
  7. package/dist/chunk-IMHLTRZJ.mjs +29 -0
  8. package/dist/chunk-JM66CQVD.mjs +10 -0
  9. package/dist/chunk-LMKP3DDN.mjs +189 -0
  10. package/dist/chunk-RTBFRPB3.mjs +186 -0
  11. package/dist/chunk-TEDXYIGO.mjs +38 -0
  12. package/dist/chunk-WIS7ZNTO.mjs +4 -0
  13. package/dist/chunk-X46EFFCE.mjs +148 -0
  14. package/dist/chunk-XHD2KFKQ.mjs +16 -0
  15. package/dist/chunk-ZRKYAFRY.mjs +46 -0
  16. package/dist/chunk-ZUR6XKMG.mjs +21 -0
  17. package/dist/components/control-block-view.d.mts +6 -0
  18. package/dist/components/control-block-view.d.ts +6 -0
  19. package/dist/components/control-block-view.js +789 -0
  20. package/dist/components/control-block-view.mjs +11 -0
  21. package/dist/components/control-implementation-view.d.mts +6 -0
  22. package/dist/components/control-implementation-view.d.ts +6 -0
  23. package/dist/components/control-implementation-view.js +52 -0
  24. package/dist/components/control-implementation-view.mjs +7 -0
  25. package/dist/components/control-picker.d.mts +25 -0
  26. package/dist/components/control-picker.d.ts +25 -0
  27. package/dist/components/control-picker.js +522 -0
  28. package/dist/components/control-picker.mjs +10 -0
  29. package/dist/components/control-view.js +677 -122
  30. package/dist/components/control-view.mjs +5 -5
  31. package/dist/components/use-control.d.mts +20 -0
  32. package/dist/components/use-control.d.ts +20 -0
  33. package/dist/components/use-control.js +127 -0
  34. package/dist/components/use-control.mjs +9 -0
  35. package/dist/control-block.d.mts +35 -0
  36. package/dist/control-block.d.ts +35 -0
  37. package/dist/control-block.js +1012 -0
  38. package/dist/control-block.mjs +17 -0
  39. package/dist/control-implementation.d.mts +7 -0
  40. package/dist/control-implementation.d.ts +7 -0
  41. package/dist/control-implementation.js +92 -0
  42. package/dist/control-implementation.mjs +9 -0
  43. package/dist/control.d.mts +31 -1
  44. package/dist/control.d.ts +31 -1
  45. package/dist/control.js +819 -136
  46. package/dist/control.mjs +7 -6
  47. package/dist/defaults.d.mts +3 -9
  48. package/dist/defaults.d.ts +3 -9
  49. package/dist/defaults.js +3 -20
  50. package/dist/defaults.mjs +3 -6
  51. package/dist/index.d.mts +10 -10
  52. package/dist/index.d.ts +10 -10
  53. package/dist/index.js +1229 -569
  54. package/dist/index.mjs +58 -21
  55. package/dist/messages/index.d.mts +135 -0
  56. package/dist/messages/index.d.ts +135 -0
  57. package/dist/messages/index.js +137 -2
  58. package/dist/messages/index.mjs +1 -2
  59. package/dist/role.d.mts +17 -0
  60. package/dist/role.d.ts +17 -0
  61. package/dist/role.js +5 -0
  62. package/dist/role.mjs +2 -0
  63. package/dist/types.d.mts +23 -16
  64. package/dist/types.d.ts +23 -16
  65. package/dist/utils/create-control-block.d.mts +7 -0
  66. package/dist/utils/create-control-block.d.ts +7 -0
  67. package/dist/utils/create-control-block.js +85 -0
  68. package/dist/utils/create-control-block.mjs +10 -0
  69. package/dist/utils/create-control-implementation.d.mts +8 -0
  70. package/dist/utils/create-control-implementation.d.ts +8 -0
  71. package/dist/utils/create-control-implementation.js +39 -0
  72. package/dist/utils/create-control-implementation.mjs +7 -0
  73. package/dist/utils/getControlNodeTypes.d.mts +5 -0
  74. package/dist/utils/getControlNodeTypes.d.ts +5 -0
  75. package/dist/utils/getControlNodeTypes.js +44 -0
  76. package/dist/utils/getControlNodeTypes.mjs +7 -0
  77. package/dist/utils/index.d.mts +7 -2
  78. package/dist/utils/index.d.ts +7 -2
  79. package/dist/utils/index.js +35 -3
  80. package/dist/utils/index.mjs +7 -4
  81. package/dist/utils/status-indicator.d.mts +18 -0
  82. package/dist/utils/status-indicator.d.ts +18 -0
  83. package/dist/utils/status-indicator.js +80 -0
  84. package/dist/utils/status-indicator.mjs +7 -0
  85. package/package.json +9 -9
  86. package/dist/card-variant.d.mts +0 -12
  87. package/dist/card-variant.d.ts +0 -12
  88. package/dist/card-variant.js +0 -66
  89. package/dist/card-variant.mjs +0 -8
  90. package/dist/chunk-AC4KL3WX.mjs +0 -29
  91. package/dist/chunk-AZ5M5MVC.mjs +0 -36
  92. package/dist/chunk-DTFR234X.mjs +0 -244
  93. package/dist/chunk-EDD7DYLE.mjs +0 -29
  94. package/dist/chunk-GC5EBQ7G.mjs +0 -10
  95. package/dist/chunk-H2ECPGOG.mjs +0 -81
  96. package/dist/chunk-KLX7Q3HL.mjs +0 -109
  97. package/dist/chunk-LKRTUIEV.mjs +0 -46
  98. package/dist/chunk-NAJ6IC4Y.mjs +0 -43
  99. package/dist/chunk-QI3ZPZTR.mjs +0 -26
  100. package/dist/chunk-SNRVOTF5.mjs +0 -8
  101. package/dist/chunk-VP5POY44.mjs +0 -57
  102. package/dist/chunk-WIR5FCIC.mjs +0 -110
  103. package/dist/control-ref-view.d.mts +0 -6
  104. package/dist/control-ref-view.d.ts +0 -6
  105. package/dist/control-ref-view.js +0 -615
  106. package/dist/control-ref-view.mjs +0 -15
  107. package/dist/control-ref.d.mts +0 -28
  108. package/dist/control-ref.d.ts +0 -28
  109. package/dist/control-ref.js +0 -687
  110. package/dist/control-ref.mjs +0 -16
  111. package/dist/i18n.d.mts +0 -4
  112. package/dist/i18n.d.ts +0 -4
  113. package/dist/i18n.js +0 -128
  114. package/dist/i18n.mjs +0 -10
  115. package/dist/lang/de.d.mts +0 -24
  116. package/dist/lang/de.d.ts +0 -24
  117. package/dist/lang/de.js +0 -25
  118. package/dist/lang/de.mjs +0 -8
  119. package/dist/lang/en.d.mts +0 -24
  120. package/dist/lang/en.d.ts +0 -24
  121. package/dist/lang/en.js +0 -25
  122. package/dist/lang/en.mjs +0 -8
  123. package/dist/settings-dialog.d.mts +0 -19
  124. package/dist/settings-dialog.d.ts +0 -19
  125. package/dist/settings-dialog.js +0 -371
  126. package/dist/settings-dialog.mjs +0 -9
@@ -0,0 +1,789 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/components/control-block-view.tsx
22
+ var control_block_view_exports = {};
23
+ __export(control_block_view_exports, {
24
+ ControlBlockView: () => ControlBlockView
25
+ });
26
+ module.exports = __toCommonJS(control_block_view_exports);
27
+ var import_i18n = require("@kopexa/i18n");
28
+ var import_icons = require("@kopexa/icons");
29
+ var import_sight2 = require("@kopexa/sight");
30
+ var import_react3 = require("@tiptap/react");
31
+ var import_react4 = require("react");
32
+
33
+ // src/messages/index.ts
34
+ var import_react_intl = require("react-intl");
35
+ var messages = (0, import_react_intl.defineMessages)({
36
+ control: {
37
+ id: "editor.controlref.control",
38
+ defaultMessage: "Control",
39
+ description: "Label for control"
40
+ },
41
+ settings_dialog_description: {
42
+ id: "editor.controlref.settings_dialog_description",
43
+ defaultMessage: "Customize the appearance and details of the control reference.",
44
+ description: "Description for the settings dialog"
45
+ },
46
+ controls: {
47
+ id: "editor.controlref.controls",
48
+ defaultMessage: "Controls",
49
+ description: "Label for controls"
50
+ },
51
+ change_control: {
52
+ id: "editor.controlref.change_control",
53
+ defaultMessage: "Change Control",
54
+ description: "Label for change control button"
55
+ },
56
+ map_control: {
57
+ id: "editor.controlref.map_control",
58
+ defaultMessage: "Map Control",
59
+ description: "Label for map control button"
60
+ },
61
+ settings: {
62
+ id: "editor.controlref.settings",
63
+ defaultMessage: "Settings",
64
+ description: "Label for settings button"
65
+ },
66
+ appearance: {
67
+ id: "editor.controlref.appearance",
68
+ defaultMessage: "Appearance",
69
+ description: "Label for appearance section"
70
+ },
71
+ search_controls: {
72
+ id: "editor.controlref.search_controls",
73
+ defaultMessage: "Search controls\u2026",
74
+ description: "Placeholder for search controls input"
75
+ },
76
+ variant: {
77
+ id: "editor.controlref.variant",
78
+ defaultMessage: "Variante",
79
+ description: "Label for variant section"
80
+ },
81
+ variant_hint: {
82
+ id: "editor.controlref.variant_hint",
83
+ defaultMessage: "Choose a visual emphasis for this section.",
84
+ description: "Hint for variant section"
85
+ },
86
+ variant_chip: {
87
+ id: "editor.controlref.variant_chip",
88
+ defaultMessage: "Chip",
89
+ description: "Label for variant chip"
90
+ },
91
+ variant_card: {
92
+ id: "editor.controlref.variant_card",
93
+ defaultMessage: "Card",
94
+ description: "Label for variant card"
95
+ },
96
+ show_status: {
97
+ id: "editor.controlref.show_status",
98
+ defaultMessage: "Show Status",
99
+ description: "Label for show status toggle"
100
+ },
101
+ show_description: {
102
+ id: "editor.controlref.show_description",
103
+ defaultMessage: "Show Description",
104
+ description: "Label for show description toggle"
105
+ },
106
+ show_implementations: {
107
+ id: "editor.controlref.show_implementations",
108
+ defaultMessage: "Show Implementations",
109
+ description: "Label for show implementations toggle"
110
+ },
111
+ border: {
112
+ id: "editor.controlref.border",
113
+ defaultMessage: "Border",
114
+ description: "Label for border toggle"
115
+ },
116
+ shadow: {
117
+ id: "editor.controlref.shadow",
118
+ defaultMessage: "Shadow",
119
+ description: "Label for shadow toggle"
120
+ },
121
+ radius: {
122
+ id: "editor.controlref.radius",
123
+ defaultMessage: "Radius",
124
+ description: "Label for radius toggle"
125
+ },
126
+ spacing: {
127
+ id: "editor.controlref.spacing",
128
+ defaultMessage: "Spacing",
129
+ description: "Label for spacing section"
130
+ },
131
+ cancel: {
132
+ id: "editor.controlref.cancel",
133
+ defaultMessage: "Cancel",
134
+ description: "Label for cancel button"
135
+ },
136
+ save_settings: {
137
+ id: "editor.controlref.save_settings",
138
+ defaultMessage: "Save Settings",
139
+ description: "Label for save settings button"
140
+ },
141
+ unmapped_control: {
142
+ id: "editor.controlref.unmapped_control",
143
+ defaultMessage: "Unmapped Control",
144
+ description: "Fallback label when no control is selected"
145
+ },
146
+ control_with_title: {
147
+ id: "editor.controlref.control_with_title",
148
+ defaultMessage: "Control: {title}",
149
+ description: "Dialog title with selected control"
150
+ },
151
+ search_hint: {
152
+ id: "editor.controlref.search_hint",
153
+ defaultMessage: "Start typing to search by ID, title or status.",
154
+ description: "Empty search hint"
155
+ },
156
+ no_results: {
157
+ id: "editor.controlref.no_results",
158
+ defaultMessage: "No controls found for \u201C{query}\u201D. You can keep this chip unmapped.",
159
+ description: "Shown when no controls match search query"
160
+ },
161
+ results_count: {
162
+ id: "editor.controlref.results_count",
163
+ defaultMessage: "{count, plural, one {# result} other {# results}}",
164
+ description: "Number of search results"
165
+ },
166
+ updated_at: {
167
+ id: "editor.controlref.updated_at",
168
+ defaultMessage: "Updated {date}",
169
+ description: "Updated date label"
170
+ },
171
+ selected: {
172
+ id: "editor.controlref.selected",
173
+ defaultMessage: "Selected",
174
+ description: "Label for selected item area"
175
+ },
176
+ no_control_selected: {
177
+ id: "editor.controlref.no_control_selected",
178
+ defaultMessage: "No control selected",
179
+ description: "Empty state in selected area"
180
+ },
181
+ clear: {
182
+ id: "editor.controlref.clear",
183
+ defaultMessage: "Clear",
184
+ description: "Clear selection button"
185
+ },
186
+ unmap: {
187
+ id: "editor.controlref.unmap",
188
+ defaultMessage: "Unmap",
189
+ description: "Unmap selection button"
190
+ },
191
+ live_preview: {
192
+ id: "editor.controlref.live_preview",
193
+ defaultMessage: "Live preview",
194
+ description: "Live preview section title"
195
+ },
196
+ display_options: {
197
+ id: "editor.controlref.display_options",
198
+ defaultMessage: "Display options",
199
+ description: "Display options section title"
200
+ },
201
+ show_status_indicator: {
202
+ id: "editor.controlref.show_status_indicator",
203
+ defaultMessage: "Show status indicator",
204
+ description: "Toggle for showing indicator"
205
+ },
206
+ searching: {
207
+ id: "editor.controlref.searching",
208
+ defaultMessage: "Searching\u2026",
209
+ description: "Loading indicator text"
210
+ },
211
+ map_control_aria: {
212
+ id: "editor.controlref.map_control_aria",
213
+ defaultMessage: "Map control",
214
+ description: "ARIA label for mapping control"
215
+ },
216
+ outdated_badge: {
217
+ id: "editor.controlref.outdated_badge",
218
+ defaultMessage: "A newer revision exists",
219
+ description: "Badge for outdated controls"
220
+ },
221
+ missing_badge: {
222
+ id: "editor.controlref.missing_badge",
223
+ defaultMessage: "Control no longer exists",
224
+ description: "Badge for missing controls"
225
+ },
226
+ error_loading: {
227
+ id: "editor.controlref.error_loading",
228
+ defaultMessage: "Failed to load controls",
229
+ description: "Error message when failing to load controls"
230
+ },
231
+ error_timeout: {
232
+ id: "editor.controlref.error_timeout",
233
+ defaultMessage: "The request timed out. Please try again.",
234
+ description: "Error message when the request times out"
235
+ },
236
+ missing_callout: {
237
+ id: "editor.controlref.missing_callout",
238
+ defaultMessage: "The currently mapped control could not be found. It may have been deleted or you may not have access to it anymore. Please select a different control.",
239
+ description: "Callout message when the selected control is missing"
240
+ },
241
+ outdated_callout: {
242
+ id: "editor.controlref.outdated_callout",
243
+ defaultMessage: "A newer revision of the currently mapped control exists. Consider updating to the latest version by re-selecting it below.",
244
+ description: "Callout message when the selected control is outdated"
245
+ },
246
+ search_placeholder: {
247
+ id: "editor.controlref.search_placeholder",
248
+ defaultMessage: "e.g. CTRL-001, Asset Inventory\u2026",
249
+ description: "Placeholder for search controls input"
250
+ },
251
+ control_implementations: {
252
+ id: "editor.controlref.control_implementations",
253
+ defaultMessage: "Implementations",
254
+ description: "Label for control implementations section"
255
+ },
256
+ header_status: {
257
+ id: "editor.controlblock.header_status",
258
+ defaultMessage: "Show status in header",
259
+ description: "Label for show status in header toggle"
260
+ },
261
+ header_status_aria: {
262
+ id: "editor.controlblock.header_status_aria",
263
+ defaultMessage: "Toggle status chip in card header",
264
+ description: "ARIA label for show status in header toggle"
265
+ },
266
+ header_status_avv_tip: {
267
+ id: "editor.controlblock.header_status_avv_tip",
268
+ defaultMessage: "If this document is intended for use or export as a data processing agreement (AVV), disable this option unless you explicitly want to publish the current control status.",
269
+ description: "Tooltip for show status in header toggle when used in AVV documents"
270
+ }
271
+ });
272
+
273
+ // src/components/control-picker.tsx
274
+ var import_sight = require("@kopexa/sight");
275
+ var import_react = require("react");
276
+ var import_react_intl2 = require("react-intl");
277
+
278
+ // src/utils/status-indicator.ts
279
+ function norm(status) {
280
+ return (status != null ? status : "").trim().replace(/[\s-]+/g, "_").toUpperCase();
281
+ }
282
+ function colorForStatusKey(key) {
283
+ switch (key == null ? void 0 : key.toUpperCase()) {
284
+ case "FULFILLED_MANUAL":
285
+ case "FULFILLED_AUTO":
286
+ case "IMPLEMENTED":
287
+ case "APPROVED":
288
+ case "PASSED":
289
+ return "success";
290
+ case "IN_PROGRESS":
291
+ case "NEEDS_APPROVAL":
292
+ case "CHANGES_REQUESTED":
293
+ case "PENDING":
294
+ case "PARTIAL":
295
+ return "warning";
296
+ case "FAILED":
297
+ case "REJECTED":
298
+ return "destructive";
299
+ case "OUT_OF_SCOPE":
300
+ case "PREPARING":
301
+ return "secondary";
302
+ default:
303
+ return "default";
304
+ }
305
+ }
306
+ function getIndicatorProps(status, opts) {
307
+ var _a, _b;
308
+ const mapped = (_a = opts == null ? void 0 : opts.mapped) != null ? _a : true;
309
+ const enable = (_b = opts == null ? void 0 : opts.enable) != null ? _b : true;
310
+ if (!enable) {
311
+ return { indicator: false, indicatorColor: "default" };
312
+ }
313
+ if (!mapped) {
314
+ return {
315
+ indicator: true,
316
+ indicatorColor: "destructive",
317
+ indicatorVariant: "pulse"
318
+ };
319
+ }
320
+ const key = norm(status);
321
+ const indicatorColor = colorForStatusKey(key);
322
+ const shouldPulse = key === "IN_PROGRESS" || key === "NEEDS_APPROVAL" || key === "CHANGES_REQUESTED" || key === "PENDING";
323
+ return {
324
+ indicator: true,
325
+ indicatorColor,
326
+ ...shouldPulse ? { indicatorVariant: "pulse" } : {}
327
+ };
328
+ }
329
+
330
+ // src/components/control-picker.tsx
331
+ var import_jsx_runtime = require("react/jsx-runtime");
332
+ function ControlPicker({
333
+ resolver,
334
+ value,
335
+ onChange,
336
+ debounceMs = 300,
337
+ timeoutMs = 5e3,
338
+ initialQuery = "",
339
+ showItemStatus = true
340
+ }) {
341
+ const intl = (0, import_react_intl2.useIntl)();
342
+ const searchId = (0, import_react.useId)();
343
+ const [search, setSearch] = (0, import_react.useState)(initialQuery);
344
+ const [debouncedSearch, setDebouncedSearch] = (0, import_react.useState)(search);
345
+ const [loading, setLoading] = (0, import_react.useState)(false);
346
+ const [error, setError] = (0, import_react.useState)(null);
347
+ const [results, setResults] = (0, import_react.useState)([]);
348
+ (0, import_react.useEffect)(() => {
349
+ const t = setTimeout(() => setDebouncedSearch(search), debounceMs);
350
+ return () => clearTimeout(t);
351
+ }, [search, debounceMs]);
352
+ (0, import_react.useEffect)(() => {
353
+ if (!(resolver == null ? void 0 : resolver.getControls)) return;
354
+ let ignore = false;
355
+ (async () => {
356
+ setLoading(true);
357
+ setError(null);
358
+ try {
359
+ const p = resolver.getControls(debouncedSearch);
360
+ const data = await Promise.race([
361
+ p,
362
+ new Promise(
363
+ (_, rej) => setTimeout(
364
+ () => rej(new Error(intl.formatMessage(messages.error_timeout))),
365
+ timeoutMs
366
+ )
367
+ )
368
+ ]);
369
+ if (!ignore) setResults(data);
370
+ } catch (e) {
371
+ if (!ignore) {
372
+ setError(
373
+ e instanceof Error ? e.message : intl.formatMessage(messages.error_loading)
374
+ );
375
+ setResults([]);
376
+ }
377
+ } finally {
378
+ if (!ignore) setLoading(false);
379
+ }
380
+ })();
381
+ return () => {
382
+ ignore = true;
383
+ };
384
+ }, [debouncedSearch, resolver, timeoutMs, intl]);
385
+ const statusNode = (0, import_react.useMemo)(() => {
386
+ if (loading)
387
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
388
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Spinner, { size: "sm" }),
389
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: intl.formatMessage(messages.searching) })
390
+ ] });
391
+ if (error) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-destructive text-sm", children: error });
392
+ if (results.length === 0 && debouncedSearch)
393
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.no_results, { query: debouncedSearch }) });
394
+ if (results.length > 0)
395
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.results_count, {
396
+ count: results.length
397
+ }) });
398
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.search_hint) });
399
+ }, [loading, error, results.length, debouncedSearch, intl]);
400
+ const itemToStringValue = (item) => {
401
+ var _a, _b;
402
+ return (_b = (_a = item == null ? void 0 : item.title) != null ? _a : item == null ? void 0 : item.id) != null ? _b : "";
403
+ };
404
+ const highlight = (text) => {
405
+ const t = (text != null ? text : "").toString();
406
+ const q = debouncedSearch.trim();
407
+ if (!q) return t;
408
+ const i = t.toLowerCase().indexOf(q.toLowerCase());
409
+ if (i === -1) return t;
410
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
411
+ t.slice(0, i),
412
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("mark", { className: "bg-primary/15 rounded px-0.5", children: t.slice(i, i + q.length) }),
413
+ t.slice(i + q.length)
414
+ ] });
415
+ };
416
+ const indicator = getIndicatorProps(value == null ? void 0 : value.status, {
417
+ mapped: !!(value == null ? void 0 : value.id),
418
+ enable: showItemStatus
419
+ });
420
+ const selInd = value ? indicator : {
421
+ indicator: false,
422
+ indicatorColor: "default"
423
+ };
424
+ const handleClear = () => {
425
+ onChange(null);
426
+ };
427
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3", children: [
428
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
429
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Label, { htmlFor: searchId, children: intl.formatMessage(messages.controls) }),
430
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
431
+ import_sight.Autocomplete,
432
+ {
433
+ items: results,
434
+ value: search,
435
+ onValueChange: setSearch,
436
+ filter: null,
437
+ itemToStringValue,
438
+ children: [
439
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_sight.Autocomplete.Control, { children: [
440
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
441
+ import_sight.Autocomplete.Input,
442
+ {
443
+ id: searchId,
444
+ placeholder: intl.formatMessage(messages.search_placeholder)
445
+ }
446
+ ),
447
+ search && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Autocomplete.Clear, {})
448
+ ] }),
449
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_sight.Autocomplete.Content, { children: [
450
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "sticky top-0 z-10 bg-background border-b px-2 py-1", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Autocomplete.Status, { children: statusNode }) }),
451
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Autocomplete.List, { children: (c) => {
452
+ var _a, _b, _c;
453
+ const id = (_a = c.id) != null ? _a : crypto.randomUUID();
454
+ const active = (value == null ? void 0 : value.id) && c.id === value.id;
455
+ const ind = getIndicatorProps(c.status, {
456
+ mapped: !!c.id,
457
+ enable: showItemStatus
458
+ });
459
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
460
+ import_sight.Autocomplete.Item,
461
+ {
462
+ value: c,
463
+ className: "rounded-lg data-[active=true]:bg-muted",
464
+ "data-active": active ? "true" : void 0,
465
+ "aria-selected": active ? "true" : "false",
466
+ onClick: () => onChange(c),
467
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2.5 truncate", children: [
468
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex-1 min-w-0", children: [
469
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "font-medium truncate", children: highlight((_b = c.title) != null ? _b : c.id) }),
470
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "text-sm text-muted-foreground truncate", children: [
471
+ highlight((_c = c.id) != null ? _c : ""),
472
+ c.updatedAt ? ` \u2022 ${intl.formatMessage(messages.updated_at, {
473
+ date: intl.formatDate(new Date(c.updatedAt), {
474
+ year: "numeric",
475
+ month: "short",
476
+ day: "2-digit",
477
+ hour: "2-digit",
478
+ minute: "2-digit"
479
+ })
480
+ })}` : ""
481
+ ] })
482
+ ] }),
483
+ showItemStatus && c.status && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
484
+ import_sight.Chip,
485
+ {
486
+ size: "sm",
487
+ variant: "ghost",
488
+ indicator: ind.indicator,
489
+ indicatorColor: ind.indicatorColor,
490
+ indicatorVariant: ind.indicatorVariant,
491
+ status: c.status,
492
+ children: c.status
493
+ }
494
+ )
495
+ ] })
496
+ },
497
+ id
498
+ );
499
+ } })
500
+ ] })
501
+ ]
502
+ }
503
+ )
504
+ ] }),
505
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between gap-2 border rounded-md px-3 py-2", children: [
506
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-3 min-w-0", children: [
507
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Label, { children: intl.formatMessage(messages.selected) }),
508
+ value ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
509
+ import_sight.Chip,
510
+ {
511
+ size: "sm",
512
+ variant: "bordered",
513
+ indicator: selInd.indicator,
514
+ indicatorColor: selInd.indicatorColor,
515
+ indicatorVariant: selInd.indicatorVariant,
516
+ status: showItemStatus ? value == null ? void 0 : value.status : void 0,
517
+ children: value.title
518
+ }
519
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.no_control_selected) })
520
+ ] }),
521
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sight.Button, { variant: "ghost", onClick: handleClear, disabled: !value, children: intl.formatMessage(messages.clear) }) })
522
+ ] })
523
+ ] });
524
+ }
525
+
526
+ // src/components/use-control.ts
527
+ var import_react2 = require("react");
528
+ function useControl({ attrs, resolver, editor }) {
529
+ var _a;
530
+ const isEdit = !!editor.isEditable;
531
+ const interactive = !!editor.isEditable && !!resolver;
532
+ const [isMissing, setIsMissing] = (0, import_react2.useState)(false);
533
+ const [isOutdated, setIsOutdated] = (0, import_react2.useState)(false);
534
+ const lastCheckedRef = (0, import_react2.useRef)(0);
535
+ const mapped = !!attrs.id;
536
+ const ind = getIndicatorProps(attrs.status, {
537
+ mapped,
538
+ enable: !!((_a = attrs == null ? void 0 : attrs.options) == null ? void 0 : _a.showStatus)
539
+ });
540
+ (0, import_react2.useEffect)(() => {
541
+ if (!isEdit || !(resolver == null ? void 0 : resolver.getControl) || !mapped || !attrs.id) return;
542
+ let cancelled = false;
543
+ const now = Date.now();
544
+ if (now - lastCheckedRef.current < 1e4) return;
545
+ (async () => {
546
+ try {
547
+ if (!attrs.id) return;
548
+ lastCheckedRef.current = now;
549
+ const latest = await resolver.getControl(attrs.id);
550
+ if (cancelled) return;
551
+ if (!latest) {
552
+ setIsMissing(true);
553
+ setIsOutdated(false);
554
+ return;
555
+ }
556
+ setIsMissing(false);
557
+ const localUpdated = attrs.updatedAt ? new Date(attrs.updatedAt).getTime() : 0;
558
+ const remoteUpdated = latest.updatedAt ? new Date(latest.updatedAt).getTime() : 0;
559
+ setIsOutdated(remoteUpdated > localUpdated);
560
+ } catch {
561
+ }
562
+ })();
563
+ return () => {
564
+ cancelled = true;
565
+ };
566
+ }, [isEdit, resolver, mapped, attrs.id, attrs.updatedAt]);
567
+ return { isEdit, interactive, ind, mapped, isMissing, isOutdated };
568
+ }
569
+
570
+ // src/components/control-block-view.tsx
571
+ var import_jsx_runtime2 = require("react/jsx-runtime");
572
+ var ControlBlockView = (props) => {
573
+ var _a, _b, _c, _d, _e, _f;
574
+ const { node, editor, updateAttributes, getPos } = props;
575
+ const attrs = node.attrs;
576
+ const { showStatus, variant } = attrs.options || {};
577
+ const resolver = props.extension.options.resolver;
578
+ const intl = (0, import_i18n.useSafeIntl)();
579
+ const { interactive, ind, mapped, isMissing, isOutdated } = useControl({
580
+ attrs,
581
+ resolver,
582
+ editor
583
+ });
584
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react3.NodeViewWrapper, { "data-id": (_a = attrs.id) != null ? _a : "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Card.Root, { variant, children: [
585
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Card.Header, { children: [
586
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Card.Heading, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Heading, { level: "h3", contentEditable: false, children: (_b = attrs.title) != null ? _b : "Unmapped Control" }) }),
587
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Card.Toolbar, { children: [
588
+ showStatus && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
589
+ import_sight2.Chip,
590
+ {
591
+ size: "sm",
592
+ "data-active": open,
593
+ contentEditable: false,
594
+ indicator: ind.indicator,
595
+ indicatorColor: ind.indicatorColor,
596
+ indicatorVariant: ind.indicatorVariant,
597
+ ...((_c = attrs.options) == null ? void 0 : _c.showStatus) && (attrs == null ? void 0 : attrs.status) && { status: attrs.status },
598
+ variant: "bordered",
599
+ children: (_d = attrs.title) != null ? _d : "Unmapped Control"
600
+ }
601
+ ),
602
+ interactive && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
603
+ SettingsDialog,
604
+ {
605
+ resolver,
606
+ initialSelection: attrs.id ? {
607
+ id: attrs.id,
608
+ title: (_e = attrs.title) != null ? _e : "",
609
+ status: (_f = attrs.status) != null ? _f : null
610
+ } : null,
611
+ initialOptions: attrs.options,
612
+ onSave: async ({ control, options }) => {
613
+ var _a2, _b2, _c2, _d2;
614
+ updateAttributes({
615
+ id: (_a2 = control == null ? void 0 : control.id) != null ? _a2 : null,
616
+ title: (_b2 = control == null ? void 0 : control.title) != null ? _b2 : null,
617
+ status: (_c2 = control == null ? void 0 : control.status) != null ? _c2 : null,
618
+ updatedAt: control == null ? void 0 : control.updatedAt,
619
+ options
620
+ });
621
+ const pos = typeof getPos === "function" ? getPos() : null;
622
+ if (pos == null) return;
623
+ const rows = (_d2 = control == null ? void 0 : control.implementations) != null ? _d2 : [];
624
+ try {
625
+ editor.commands.setControlImplementationsAt(pos, rows);
626
+ } catch {
627
+ editor.commands.setControlImplementationsAt(pos, []);
628
+ }
629
+ },
630
+ onUnlink: () => {
631
+ updateAttributes({ id: null, title: null, status: null });
632
+ const pos = typeof getPos === "function" ? getPos() : null;
633
+ if (pos != null)
634
+ editor.commands.setControlImplementationsAt(pos, []);
635
+ }
636
+ }
637
+ )
638
+ ] })
639
+ ] }),
640
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Card.Body, { children: [
641
+ interactive && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
642
+ mapped && isMissing && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
643
+ import_sight2.Callout,
644
+ {
645
+ print: false,
646
+ variant: "destructive",
647
+ contentEditable: false,
648
+ className: "mb-4",
649
+ children: intl.formatMessage(messages.missing_callout)
650
+ }
651
+ ),
652
+ !isMissing && isOutdated && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
653
+ import_sight2.Callout,
654
+ {
655
+ print: false,
656
+ variant: "warning",
657
+ contentEditable: false,
658
+ className: "mb-4",
659
+ children: intl.formatMessage(messages.outdated_callout)
660
+ }
661
+ )
662
+ ] }),
663
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex flex-col gap-3", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react3.NodeViewContent, { className: "content is-editable", as: "div" }) })
664
+ ] })
665
+ ] }) });
666
+ };
667
+ var SettingsDialog = ({
668
+ initialSelection,
669
+ initialOptions,
670
+ resolver,
671
+ onSave
672
+ }) => {
673
+ const intl = (0, import_i18n.useSafeIntl)();
674
+ const [isOpen, onOpenChange] = (0, import_react4.useState)(false);
675
+ const [selection, setSelection] = (0, import_react4.useState)(
676
+ initialSelection
677
+ );
678
+ const [options, setOptions] = (0, import_react4.useState)({
679
+ showStatus: false,
680
+ ...initialOptions
681
+ });
682
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Dialog, { size: "2xl", open: isOpen, onOpenChange, children: [
683
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
684
+ import_sight2.Dialog.Trigger,
685
+ {
686
+ render: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.IconButton, { variant: "outline", color: "default", "aria-label": "Settings", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons.SettingsIcon, {}) })
687
+ }
688
+ ),
689
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Dialog.Content, { children: [
690
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Dialog.Header, { children: [
691
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Dialog.Title, { children: (selection == null ? void 0 : selection.title) ? intl.formatMessage(messages.control_with_title, {
692
+ title: selection.title
693
+ }) : intl.formatMessage(messages.map_control) }),
694
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Dialog.Description, { children: intl.formatMessage(messages.settings_dialog_description) })
695
+ ] }),
696
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Dialog.Body, { children: [
697
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
698
+ ControlPicker,
699
+ {
700
+ resolver,
701
+ value: selection,
702
+ onChange: (next) => {
703
+ setSelection(next);
704
+ },
705
+ debounceMs: 300,
706
+ timeoutMs: 5e3
707
+ }
708
+ ),
709
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mt-6 flex flex-col gap-3", children: [
710
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Label, { children: intl.formatMessage(messages.display_options) }),
711
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
712
+ import_sight2.Label,
713
+ {
714
+ variant: "secondary",
715
+ className: "flex items-center justify-between gap-3",
716
+ children: [
717
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: intl.formatMessage(messages.header_status) }),
718
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
719
+ import_sight2.Switch,
720
+ {
721
+ "aria-label": intl.formatMessage(messages.header_status_aria),
722
+ checked: !!options.showStatus,
723
+ onCheckedChange: (checked) => setOptions((o) => ({ ...o, showStatus: checked }))
724
+ }
725
+ )
726
+ ]
727
+ }
728
+ ),
729
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Callout, { variant: "info", children: intl.formatMessage(messages.header_status_avv_tip) }),
730
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
731
+ import_sight2.Label,
732
+ {
733
+ variant: "secondary",
734
+ className: "flex items-center justify-between gap-3",
735
+ children: [
736
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-col gap-1", children: [
737
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: intl.formatMessage(messages.variant) }),
738
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-muted-foreground text-sm", children: intl.formatMessage(messages.variant_hint) })
739
+ ] }),
740
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
741
+ import_sight2.Select,
742
+ {
743
+ value: options.variant || "default",
744
+ onValueChange: (value) => setOptions((o) => ({
745
+ ...o,
746
+ variant: value
747
+ })),
748
+ children: [
749
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Select.Trigger, { className: "w-[180px]", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Select.Value, { placeholder: "Select a variant" }) }),
750
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Select.Content, { children: [
751
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Select.Item, { value: "default", children: "Default" }),
752
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Select.Item, { value: "muted", children: "Muted" }),
753
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Select.Item, { value: "accent", children: "Accent" })
754
+ ] })
755
+ ]
756
+ }
757
+ )
758
+ ]
759
+ }
760
+ )
761
+ ] })
762
+ ] }),
763
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_sight2.Dialog.Footer, { className: "sticky bottom-0 bg-background", children: [
764
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
765
+ import_sight2.Dialog.CloseTrigger,
766
+ {
767
+ render: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sight2.Button, { variant: "ghost", color: "default", children: intl.formatMessage(messages.cancel) })
768
+ }
769
+ ),
770
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
771
+ import_sight2.Button,
772
+ {
773
+ color: "primary",
774
+ onClick: () => {
775
+ onSave({ control: selection, options });
776
+ onOpenChange(false);
777
+ },
778
+ disabled: JSON.stringify(selection) === JSON.stringify(initialSelection) && JSON.stringify(options) === JSON.stringify(initialOptions),
779
+ children: intl.formatMessage(messages.save_settings)
780
+ }
781
+ )
782
+ ] })
783
+ ] })
784
+ ] });
785
+ };
786
+ // Annotate the CommonJS export names for ESM import in node:
787
+ 0 && (module.exports = {
788
+ ControlBlockView
789
+ });