@overvis/hmi-workspace-ui 0.1.0 → 0.1.1

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 (115) hide show
  1. package/dist/alarm-list-sheAq-pb.js +414 -0
  2. package/dist/alarm-rule-dialog-D_ml7V0v.js +417 -0
  3. package/dist/{alarm-rule-lists-C5v1Kf7A.js → alarm-rule-lists-DaA4soF4.js} +123 -125
  4. package/dist/{alarm-rules-page-CqFzofPd.js → alarm-rules-page-OFjOQ-dm.js} +15 -18
  5. package/dist/alert-dialog-B60PF7S9.js +891 -0
  6. package/dist/{base-revision-YCO27zR4.js → base-revision-DYCOZS0R.js} +26 -29
  7. package/dist/{breadcrumbs-0cjsV2cq.js → breadcrumbs-D2u8KZQo.js} +6 -7
  8. package/dist/{catalog-list-DjZojYLJ.js → catalog-list-LXuRix0-.js} +2 -4
  9. package/dist/{code-editor-BVimvjDV.js → code-editor-BMSyzAxu.js} +5 -6
  10. package/dist/dashboard-bindings.js +1 -2
  11. package/dist/{dashboards-page-BlrJguNz.js → dashboards-page-wnmmLpVC.js} +335 -359
  12. package/dist/{de-14WdmJxZ.js → de-hkEr2usK.js} +1 -2
  13. package/dist/diagnostic-text-CsbENUNI.js +116 -0
  14. package/dist/{dialogs-B6BRnf3Q.js → dialogs-AtIYlNSy.js} +219 -227
  15. package/dist/{dialogs-D_v1LeH4.js → dialogs-DsHbKgZD.js} +2523 -2590
  16. package/dist/{display-DmOo23mi.js → display-DSyEwQt8.js} +4 -6
  17. package/dist/{editor-language-To9MxloY.js → editor-language-CTfJBXMs.js} +3 -5
  18. package/dist/editor-page-BWbVGJvU.js +1337 -0
  19. package/dist/{en-BgercpT0.js → en-UW_k-Bd6.js} +1 -2
  20. package/dist/entity-controls-BCuRx882.js +71 -0
  21. package/dist/errors-Cawve9yD.js +25 -0
  22. package/dist/{footer-DC-Q0052.js → footer-B9XdpVzq.js} +2404 -2515
  23. package/dist/host.js +8143 -675
  24. package/dist/{i18n-BgzakKoC.js → i18n-Dt6xbSK6.js} +77 -90
  25. package/dist/i18n.js +1 -2
  26. package/dist/index.js +5149 -5345
  27. package/dist/{lat-lng-B12P7QyY.js → lat-lng-Bl77AGSO.js} +1 -2
  28. package/dist/{list-page-CvsdZb86.js → list-page-agHupfNb.js} +116 -123
  29. package/dist/{location-map-renderer-DO5yfdSU.js → location-map-renderer-kxU6cgFl.js} +6 -6
  30. package/dist/{location-picker-renderer-CjCxg6ai.js → location-picker-renderer-B1_-n8lf.js} +3 -4
  31. package/dist/{model-B8gGi4OK.js → model-tpg_xpFB.js} +1 -2
  32. package/dist/{notice-card-DyGywFsW.js → notice-card-CH28rYUt.js} +54 -58
  33. package/dist/{page-v6LCwswN.js → page-CZPHJUmz.js} +92 -100
  34. package/dist/page-DpdkOGGb.js +449 -0
  35. package/dist/page-HCGXXGjy.js +507 -0
  36. package/dist/panel-BCwBlB_h.js +949 -0
  37. package/dist/parameter-values.js +3 -16
  38. package/dist/{pl-lQ9HXV9k.js → pl-BokvsP3J.js} +1 -2
  39. package/dist/presence-code-cT6wxlTg.js +73 -0
  40. package/dist/{query-gate-DVhNIkge.js → query-gate-DqmHsZ07.js} +6 -6
  41. package/dist/{provider-DoEpKcQ-.js → quick-report-DEqqwQxR.js} +9423 -5102
  42. package/dist/{retention-BYXNpYmR.js → retention-DZ0reGGe.js} +4 -6
  43. package/dist/retention-note-nequESpo.js +40 -0
  44. package/dist/{rolldown-runtime-Dy4uBu1J.js → rolldown-runtime-CGnMp29N.js} +1 -2
  45. package/dist/{ru-qTKINoUj.js → ru-DZSlsRHq.js} +1 -2
  46. package/dist/run-text-DneX9rWh.js +112 -0
  47. package/dist/{search-D4rDnE9T.js → search-DP9_alSQ.js} +26 -29
  48. package/dist/{sections-kCOyc4NR.js → sections-BU7NKUOQ.js} +2 -3
  49. package/dist/{select-BKiOWdSr.js → select-Te6Qv1Zu.js} +17 -23
  50. package/dist/{spinner-C-HPNxOc.js → spinner-BRcNKwjH.js} +182 -201
  51. package/dist/src/version.d.ts +1 -1
  52. package/dist/src/workspace/local-workspace-app.d.ts +1 -1
  53. package/dist/src/workspace/routes.d.ts +1 -1
  54. package/dist/{starter-fields-BRLX0z-v.js → starter-fields-yM4B49nd.js} +154 -157
  55. package/dist/{starter-handoff-BA3ucMKL.js → starter-handoff-BaK8Ss8I.js} +1 -2
  56. package/dist/styles.css +1 -1
  57. package/dist/ui.js +334 -374
  58. package/dist/{uk-CwpJAxmx.js → uk-CjXPq9Lk.js} +1 -2
  59. package/dist/{wireguard-docs-AfU6NzTL.js → wireguard-docs-CC8XKBR7.js} +14 -17
  60. package/package.json +15 -9
  61. package/dist/alarm-list-BL3xQ5Lf.js +0 -423
  62. package/dist/alarm-rule-dialog-S1ZUg-74.js +0 -423
  63. package/dist/alert-B8MAoIO8.js +0 -45
  64. package/dist/alert-dialog-CYkuMg5D.js +0 -129
  65. package/dist/api-error-9rQmUN5L.js +0 -93
  66. package/dist/breadcrumb-DzVL1yHa.js +0 -74
  67. package/dist/button-6SxPBYMz.js +0 -44
  68. package/dist/context-u9KJQmdB.js +0 -102
  69. package/dist/copyable-id-DYGiAcnq.js +0 -40
  70. package/dist/dashboard-context-CBfG6DoT.js +0 -191
  71. package/dist/date-time-picker-C3FhMXk6.js +0 -266
  72. package/dist/diagnostic-text-BAkzW0SE.js +0 -111
  73. package/dist/diagnostic-text-DiKd2i1w.js +0 -76
  74. package/dist/dialog-BIhQXcZC.js +0 -237
  75. package/dist/dialog-BqyIxMD-.js +0 -54
  76. package/dist/dropdown-menu-DSzbBq3v.js +0 -136
  77. package/dist/editor-page-BiSZJz5b.js +0 -1353
  78. package/dist/empty-B-QJ-06w.js +0 -59
  79. package/dist/entity-controls-D1K4Ot3O.js +0 -76
  80. package/dist/errors-CcsvDHu8.js +0 -26
  81. package/dist/history-page-sAAhG54V.js +0 -1400
  82. package/dist/icon-D-pR9htW.js +0 -57
  83. package/dist/index-page-DMH82fZe.js +0 -214
  84. package/dist/item-B5SaTFQU.js +0 -120
  85. package/dist/mutation-form-validators-BNz5bsv1.js +0 -2408
  86. package/dist/mutations-THtGG6Ai.js +0 -240
  87. package/dist/page-2KPemaAj.js +0 -328
  88. package/dist/page-6rIoTg2L.js +0 -459
  89. package/dist/page-C6giEoEd.js +0 -1935
  90. package/dist/page-DCbTxKsi.js +0 -313
  91. package/dist/page-DWO427hT.js +0 -208
  92. package/dist/page-LXu_2zm3.js +0 -137
  93. package/dist/page-aaUiVOnk.js +0 -513
  94. package/dist/page-header-RB2YFWlE.js +0 -55
  95. package/dist/page-title-CdCbiLt8.js +0 -14
  96. package/dist/panel-DDy8tUNR.js +0 -338
  97. package/dist/presence-code-BfSXr50g.js +0 -83
  98. package/dist/progress-C7cxNJA1.js +0 -83
  99. package/dist/provider-BOeYHi0n.js +0 -134
  100. package/dist/quick-report-CUVJnbKP.js +0 -416
  101. package/dist/radio-group-CZGqVbkJ.js +0 -26
  102. package/dist/retention-note-CHhA6gjY.js +0 -42
  103. package/dist/run-text-DvaO8LDF.js +0 -113
  104. package/dist/select-eNgZdZ30.js +0 -521
  105. package/dist/skeleton-6yk8Tdh5.js +0 -19
  106. package/dist/slider-DorDsoF8.js +0 -37
  107. package/dist/status-page-DAHiKM9P.js +0 -3286
  108. package/dist/switch-BqD0RH_G.js +0 -18
  109. package/dist/table-Q2-voLuw.js +0 -65
  110. package/dist/tabs-CSIucYFP.js +0 -57
  111. package/dist/theme-provider-BkRohQFU.js +0 -61
  112. package/dist/toggle-group-9Bs0Mm3r.js +0 -82
  113. package/dist/trpc-CvJUuUXp.js +0 -153
  114. package/dist/utils-CX-Pz5p6.js +0 -8
  115. package/dist/writability-BuH-spxv.js +0 -57
@@ -1,2408 +0,0 @@
1
- import { r as e } from "./trpc-CvJUuUXp.js";
2
- import { f as t, h as n, m as r, v as i } from "./i18n-BgzakKoC.js";
3
- import { t as a } from "./utils-CX-Pz5p6.js";
4
- import { A as o, B as s, D as c, E as l, F as u, H as d, I as f, L as p, M as m, N as h, O as g, P as _, R as v, S as y, Y as b, _ as x, a as ee, c as S, d as C, f as w, g as T, i as te, l as E, n as ne, r as re, y as D, z as O } from "./spinner-C-HPNxOc.js";
5
- import { t as ie } from "./button-6SxPBYMz.js";
6
- import { f as k } from "./dialog-BIhQXcZC.js";
7
- import { n as A, t as j } from "./skeleton-6yk8Tdh5.js";
8
- import { aggregateParameterValues as M, isCurrentParameterValue as ae, isParameterValuePending as N, noDemandParameterValueState as P, parameterDiagnosticFromResult as F, parameterValueBoolean as oe, parameterValueFlag as se } from "./parameter-values.js";
9
- import { i as ce } from "./context-u9KJQmdB.js";
10
- import { n as le, r as ue, t as de } from "./api-error-9rQmUN5L.js";
11
- import { createContext as fe, createElement as pe, useCallback as I, useContext as me, useEffect as L, useId as he, useMemo as R, useRef as z, useState as B, useSyncExternalStore as ge } from "react";
12
- import { createFormHook as _e, createFormHookContexts as ve } from "@tanstack/react-form";
13
- import { Fragment as ye, jsx as V, jsxs as H } from "react/jsx-runtime";
14
- import { CheckIcon as be, ChevronRightIcon as xe, ChevronsUpDownIcon as Se, SearchIcon as Ce, XIcon as we } from "lucide-react";
15
- import { REGEXP_ONLY_DIGITS as Te } from "input-otp";
16
- import { API_INPUT_INVALID_CODE as Ee, formatAppDateTime as De, localizedStringValues as Oe, resolveLocalized as U, searchMatches as ke, searchRelevance as Ae, searchWords as je } from "@overvis/hmi-shared";
17
- import { defaultKeymap as Me, history as Ne, historyKeymap as Pe } from "@codemirror/commands";
18
- import { Compartment as Fe, EditorState as Ie, Prec as Le, StateEffect as Re, StateField as ze } from "@codemirror/state";
19
- import { Decoration as Be, EditorView as W, ViewPlugin as Ve, WidgetType as He, drawSelection as Ue, hoverTooltip as We, keymap as G, placeholder as Ge, showTooltip as Ke } from "@codemirror/view";
20
- import { acceptCompletion as qe, autocompletion as Je, pickedCompletion as Ye, snippet as Xe, startCompletion as Ze } from "@codemirror/autocomplete";
21
- import { canWriteParameterValues as Qe } from "@overvis/hmi-shared/workspace";
22
- //#region src/form/form-contexts.ts
23
- var { fieldContext: $e, formContext: et, useFieldContext: K, useFormContext: tt } = ve(), q = class {
24
- read;
25
- constructor(e) {
26
- this.read = e;
27
- }
28
- };
29
- //#endregion
30
- //#region src/form/format-field-errors.ts
31
- function nt(e) {
32
- if (!("keyword" in e)) return null;
33
- let t = Reflect.get(e, "keyword");
34
- return typeof t == "string" ? t : null;
35
- }
36
- function rt(e) {
37
- if (!("params" in e)) return null;
38
- let t = Reflect.get(e, "params");
39
- return typeof t != "object" || !t || Array.isArray(t) ? null : Object.fromEntries(Object.entries(t));
40
- }
41
- function it(e, t) {
42
- if (!e || !(t in e)) return null;
43
- let n = Reflect.get(e, t);
44
- return typeof n == "number" && Number.isFinite(n) ? n : null;
45
- }
46
- function at(e, t) {
47
- if (!e || !(t in e)) return null;
48
- let n = Reflect.get(e, t);
49
- return typeof n == "string" ? n : null;
50
- }
51
- function ot(e) {
52
- return e.toLowerCase().includes("password");
53
- }
54
- function st(e) {
55
- return e.toLowerCase().includes("email");
56
- }
57
- function J(e) {
58
- return String(e);
59
- }
60
- function ct(e, n, r) {
61
- switch (n) {
62
- case "minLength": {
63
- let n = it(r, "limit");
64
- return n === null ? t("error_field_required") : n <= 1 ? ot(e) ? t("error_password_required") : t("error_field_required") : ot(e) ? t("error_password_too_short", { limit: J(n) }) : st(e) ? t("error_invalid_email") : t("error_field_too_short", { limit: J(n) });
65
- }
66
- case "maxLength": {
67
- let n = it(r, "limit");
68
- return n === null ? t("error_field_invalid") : ot(e) ? t("error_password_too_long", { limit: J(n) }) : t("error_field_too_long", { limit: J(n) });
69
- }
70
- case "minimum":
71
- case "exclusiveMinimum": {
72
- let e = it(r, "limit");
73
- return e === null ? t("error_field_invalid") : t("error_field_min", { limit: J(e) });
74
- }
75
- case "maximum":
76
- case "exclusiveMaximum": {
77
- let e = it(r, "limit");
78
- return e === null ? t("error_field_invalid") : t("error_field_max", { limit: J(e) });
79
- }
80
- case "format": return at(r, "format") === "email" || st(e) ? t("error_invalid_email") : t("error_field_invalid_format");
81
- case "pattern": return e === "port" ? t("error_endpoint_port_invalid") : e === "hostname" ? t("error_endpoint_hostname_invalid") : e === "publicKey" ? t("error_endpoint_public_key_invalid") : e === "pinCode" ? t("error_endpoint_pin_invalid") : ["^0*[1-9][0-9]*$", "^(?:|0*[1-9][0-9]*)$"].includes(at(r, "pattern") ?? "") ? t("error_endpoint_tcp_positive_integer") : ["^[0-9]+$", "^[0-9]*$"].includes(at(r, "pattern") ?? "") ? t("error_endpoint_tcp_invalid") : t("error_field_invalid_format");
82
- case "from_after_to": return t("report_runtime_range_invalid");
83
- case "type":
84
- case "invalid":
85
- case "multipleOf":
86
- case "const":
87
- case "enum":
88
- case "anyOf":
89
- case "oneOf":
90
- case "allOf":
91
- case "not":
92
- case "minItems":
93
- case "maxItems":
94
- case "uniqueItems":
95
- case "minProperties":
96
- case "maxProperties":
97
- case "additionalProperties":
98
- case "unevaluatedProperties":
99
- case "unevaluatedItems":
100
- case "contains":
101
- case "minContains":
102
- case "maxContains":
103
- case "propertyNames":
104
- case "dependentRequired":
105
- case "dependentSchemas":
106
- case "if":
107
- case "then":
108
- case "else": return t("error_field_invalid");
109
- case "required": return ot(e) ? t("error_password_required") : t("error_field_required");
110
- default: break;
111
- }
112
- return t("error_field_invalid");
113
- }
114
- function Y(e, n) {
115
- return e.flatMap((e) => {
116
- if (e == null) return [];
117
- if (e instanceof q) return [{ message: e.read() }];
118
- if (typeof e == "string") return e === t("error_generic") ? [{ message: t("error_field_invalid") }] : [{ message: e }];
119
- if (typeof e != "object") return [{ message: t("error_field_invalid") }];
120
- let r = nt(e);
121
- return r ? [{ message: ct(n, r, rt(e)) }] : [{ message: t("error_field_invalid") }];
122
- });
123
- }
124
- //#endregion
125
- //#region src/form/fields/checkbox-field.tsx
126
- function lt({ label: e, id: t, description: r, disabled: i }) {
127
- n();
128
- let a = K(), o = t ?? a.name, c = !a.state.meta.isValid, l = Y(a.state.meta.errors, a.name);
129
- return /* @__PURE__ */ H(p, {
130
- orientation: "horizontal",
131
- "data-invalid": c ? !0 : void 0,
132
- children: [/* @__PURE__ */ V(b, {
133
- id: o,
134
- name: a.name,
135
- checked: a.state.value,
136
- onCheckedChange: (e) => {
137
- a.handleChange(e);
138
- },
139
- onBlur: a.handleBlur,
140
- "aria-invalid": c || void 0,
141
- ...i == null ? {} : { disabled: i }
142
- }), /* @__PURE__ */ H(v, { children: [
143
- /* @__PURE__ */ V(d, {
144
- htmlFor: o,
145
- children: e
146
- }),
147
- r == null ? null : /* @__PURE__ */ V(O, { children: r }),
148
- /* @__PURE__ */ V(s, { errors: l })
149
- ] })]
150
- });
151
- }
152
- //#endregion
153
- //#region src/form/fields/otp-field.tsx
154
- function ut({ label: e, id: t, description: r, length: i = 6, disabled: a, autoFocus: o, onComplete: c }) {
155
- n();
156
- let l = K(), m = t ?? l.name, g = !l.state.meta.isValid, v = Y(l.state.meta.errors, l.name), y = Math.ceil(i / 2), b = Array.from({ length: i }, (e, t) => t);
157
- return /* @__PURE__ */ H(p, {
158
- "data-invalid": g ? !0 : void 0,
159
- children: [
160
- /* @__PURE__ */ V(d, {
161
- htmlFor: m,
162
- children: e
163
- }),
164
- /* @__PURE__ */ H(h, {
165
- id: m,
166
- name: l.name,
167
- maxLength: i,
168
- pattern: Te,
169
- inputMode: "numeric",
170
- autoComplete: "one-time-code",
171
- value: l.state.value,
172
- onChange: l.handleChange,
173
- onBlur: l.handleBlur,
174
- ...c ? { onComplete: c } : {},
175
- ...a == null ? {} : { disabled: a },
176
- ...o == null ? {} : { autoFocus: o },
177
- "aria-invalid": g || void 0,
178
- children: [
179
- /* @__PURE__ */ V(_, { children: b.slice(0, y).map((e) => /* @__PURE__ */ V(f, {
180
- index: e,
181
- className: "size-10 text-base"
182
- }, e)) }),
183
- /* @__PURE__ */ V(u, {}),
184
- /* @__PURE__ */ V(_, { children: b.slice(y).map((e) => /* @__PURE__ */ V(f, {
185
- index: e,
186
- className: "size-10 text-base"
187
- }, e)) })
188
- ]
189
- }),
190
- r == null ? null : /* @__PURE__ */ V(O, { children: r }),
191
- /* @__PURE__ */ V(s, { errors: v })
192
- ]
193
- });
194
- }
195
- //#endregion
196
- //#region src/form/fields/dashboard-picker-field.tsx
197
- function dt({ label: t, workspaceId: i, allowEmpty: a = !0, exclude: c = [], description: l }) {
198
- let u = r(), f = n(), h = K(), g = e.dashboard.list.useQuery({ workspaceId: i }), _ = he(), v = !h.state.meta.isValid, y = Y(h.state.meta.errors, h.name), b = (g.data?.dashboards ?? []).filter((e) => !c.includes(e.id)), x = h.state.value, ee = x !== "" && !b.some((e) => e.id === x);
199
- return /* @__PURE__ */ H(p, {
200
- "data-invalid": v ? !0 : void 0,
201
- children: [
202
- /* @__PURE__ */ V(d, {
203
- htmlFor: _,
204
- children: t
205
- }),
206
- /* @__PURE__ */ V(o, {
207
- id: _,
208
- name: h.name,
209
- value: x,
210
- disabled: g.isPending,
211
- "aria-invalid": v || void 0,
212
- onBlur: h.handleBlur,
213
- onChange: (e) => {
214
- h.handleChange(e.target.value);
215
- },
216
- children: g.isPending ? /* @__PURE__ */ V(m, {
217
- value: x,
218
- children: u("dashboard_picker_loading")
219
- }) : /* @__PURE__ */ H(ye, { children: [
220
- a || x === "" ? /* @__PURE__ */ V(m, {
221
- value: "",
222
- children: u("dashboard_picker_none")
223
- }) : null,
224
- ee ? /* @__PURE__ */ V(m, {
225
- value: x,
226
- children: g.isError ? u("dashboard_picker_error") : u("dashboard_picker_missing")
227
- }) : null,
228
- b.map((e) => /* @__PURE__ */ V(m, {
229
- value: e.id,
230
- children: U(e.name, f)
231
- }, e.id))
232
- ] })
233
- }),
234
- g.isError ? /* @__PURE__ */ V(O, { children: u("dashboard_picker_error") }) : l == null ? null : /* @__PURE__ */ V(O, { children: l }),
235
- /* @__PURE__ */ V(s, { errors: y })
236
- ]
237
- });
238
- }
239
- //#endregion
240
- //#region src/code-editor/language-features.ts
241
- var ft = {
242
- property: "property",
243
- value: "enum",
244
- kind: "type",
245
- snippet: "class",
246
- function: "function",
247
- variable: "variable",
248
- constant: "constant",
249
- keyword: "keyword",
250
- operator: "keyword",
251
- literal: "constant",
252
- entity: "namespace",
253
- procedure: "method",
254
- key: "text"
255
- };
256
- function X(e, t, n) {
257
- let r = document.createElement(e);
258
- return r.className = t, n !== void 0 && (r.textContent = n), r;
259
- }
260
- function pt(e, t) {
261
- let n = X("a", "text-xs font-medium text-primary underline-offset-4 hover:underline", t);
262
- return n.href = e, n.target = "_blank", n.rel = "noreferrer", n;
263
- }
264
- function mt(e, t, n) {
265
- let r = X("div", "flex max-w-[min(28rem,85vw)] flex-col gap-1.5 px-3 py-2 text-sm");
266
- for (let t of e.code) r.append(X("code", "font-mono text-xs break-words whitespace-pre-wrap", t));
267
- e.description !== void 0 && r.append(X("p", "text-muted-foreground", e.description));
268
- let i = X("div", "flex flex-wrap items-center gap-x-3 gap-y-1");
269
- e.docsUrl !== void 0 && i.append(pt(e.docsUrl, t));
270
- for (let t of n === void 0 ? [] : e.actions ?? []) {
271
- let e = X("button", "text-xs font-medium text-primary underline-offset-4 hover:underline", t.label);
272
- e.type = "button", e.addEventListener("click", () => {
273
- n !== void 0 && t.run(n);
274
- }), i.append(e);
275
- }
276
- return i.childElementCount > 0 && r.append(i), r;
277
- }
278
- function ht(e) {
279
- let t = e.completions;
280
- return (n) => {
281
- if (t === void 0) return null;
282
- let r = n.state.doc.toString(), i = t(r, n.pos);
283
- if (i === null) return null;
284
- let a = Math.max(0, i.to - n.pos), o = r[i.from] === "\"" && i.from < n.pos;
285
- if (!n.explicit && i.from === n.pos && /\s/.test(r[n.pos - 1] ?? "")) return null;
286
- let s = i.items.map((t) => ({
287
- label: o && !t.label.startsWith("\"") ? `"${t.label}` : t.label,
288
- displayLabel: t.label,
289
- type: ft[t.kind] ?? "text",
290
- ...t.detail === void 0 ? {} : { detail: t.detail },
291
- ...t.boost === void 0 ? {} : { boost: Math.max(-99, Math.min(99, t.boost)) },
292
- ...t.description === void 0 && t.docsUrl === void 0 ? {} : { info: () => mt({
293
- from: 0,
294
- to: 0,
295
- code: [],
296
- ...t.description === void 0 ? {} : { description: t.description },
297
- ...t.docsUrl === void 0 ? {} : { docsUrl: t.docsUrl }
298
- }, e.docsLabel) },
299
- apply: (e, n, r, i) => {
300
- let o = Math.min(e.state.doc.length, i + a);
301
- t.snippet === !0 ? Xe(t.insert)(e, n, r, o) : e.dispatch({
302
- changes: {
303
- from: r,
304
- to: o,
305
- insert: t.insert
306
- },
307
- selection: { anchor: r + t.insert.length },
308
- annotations: Ye.of(n),
309
- userEvent: "input.complete"
310
- }), t.additionalEdits !== void 0 && t.additionalEdits.length > 0 && e.dispatch({
311
- changes: t.additionalEdits.map((e) => ({ ...e })),
312
- userEvent: "input.complete"
313
- }), t.snippet !== !0 && t.insert.endsWith(" ") && Ze(e);
314
- }
315
- }));
316
- return i.filtered ? {
317
- from: i.from,
318
- to: n.pos,
319
- options: s,
320
- filter: !1
321
- } : {
322
- from: i.from,
323
- to: n.pos,
324
- options: s,
325
- validFor: /^["\w$.:/-]*$/
326
- };
327
- };
328
- }
329
- var Z = Re.define(), gt = ze.define({
330
- create: () => null,
331
- update(e, t) {
332
- for (let e of t.effects) if (e.is(Z)) return e.value;
333
- return t.docChanged || t.selection !== void 0 ? null : e;
334
- },
335
- provide: (e) => Ke.from(e)
336
- });
337
- function _t(e, t, n) {
338
- let r = t.doc.toString(), i = e.info?.(r, n);
339
- if (i == null) return null;
340
- let a = [...i.actions ?? []], { referencesLabel: o, renameLabel: s } = e;
341
- return o !== void 0 && (e.references?.(r, n)?.length ?? 0) > 0 && a.push({
342
- label: o,
343
- run: (t) => {
344
- yt(e, t, n);
345
- }
346
- }), s !== void 0 && !t.readOnly && e.rename?.prepare(r, n) != null && a.push({
347
- label: s,
348
- run: (t) => {
349
- bt(e, t, n);
350
- }
351
- }), {
352
- pos: i.from,
353
- end: i.to,
354
- above: !0,
355
- create: (t) => ({ dom: mt({
356
- ...i,
357
- actions: a
358
- }, e.docsLabel, t) })
359
- };
360
- }
361
- function vt(e, t) {
362
- if ("open" in t) {
363
- t.open();
364
- return;
365
- }
366
- e.dispatch({
367
- selection: {
368
- anchor: t.from,
369
- head: t.to
370
- },
371
- effects: W.scrollIntoView(t.from, { y: "center" })
372
- }), e.focus();
373
- }
374
- function yt(e, t, n) {
375
- let r = e.references?.(t.state.doc.toString(), n);
376
- if (r == null || r.length === 0) return !1;
377
- let i = {
378
- pos: n,
379
- above: !1,
380
- create: () => {
381
- let n = X("div", "flex max-h-72 w-[min(32rem,90vw)] flex-col overflow-y-auto py-1 text-sm");
382
- e.referencesLabel !== void 0 && n.append(X("p", "px-3 py-1 text-xs font-medium text-muted-foreground", `${e.referencesLabel} (${String(r.length)})`));
383
- for (let e of r) {
384
- let r = X("button", "flex w-full min-w-0 items-baseline gap-2 px-3 py-1 text-left hover:bg-muted focus-visible:bg-muted focus-visible:outline-none");
385
- r.type = "button", r.append(X("span", e.definition === !0 ? "shrink-0 text-xs font-medium text-foreground" : "shrink-0 text-xs text-muted-foreground", e.location), X("code", "min-w-0 truncate font-mono text-xs", e.text)), r.title = e.text, r.addEventListener("click", () => {
386
- t.dispatch({ effects: Z.of(null) }), vt(t, e.target);
387
- }), n.append(r);
388
- }
389
- return n.addEventListener("keydown", (e) => {
390
- e.key === "Escape" && (e.preventDefault(), t.dispatch({ effects: Z.of(null) }), t.focus());
391
- }), {
392
- dom: n,
393
- mount: () => {
394
- n.querySelector("button")?.focus();
395
- }
396
- };
397
- }
398
- };
399
- return t.dispatch({ effects: Z.of(i) }), !0;
400
- }
401
- function bt(e, t, n) {
402
- if (t.state.readOnly) return !1;
403
- let r = e.rename, i = r?.prepare(t.state.doc.toString(), n);
404
- if (r === void 0 || i == null) return !1;
405
- let a = {
406
- pos: i.from,
407
- end: i.to,
408
- above: !1,
409
- create: () => {
410
- let a = X("div", "flex w-64 max-w-[85vw] flex-col gap-1 p-2"), o = X("input", "h-8 w-full rounded-md border border-input bg-transparent px-2 font-mono text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive");
411
- o.value = i.name, o.spellcheck = !1, o.autocomplete = "off", e.renameLabel !== void 0 && o.setAttribute("aria-label", e.renameLabel);
412
- let s = X("p", "text-xs text-destructive");
413
- s.hidden = !0, s.id = `cm-rename-problem-${String(i.from)}`, o.setAttribute("aria-describedby", s.id), a.append(o, s);
414
- let c = () => {
415
- t.dispatch({ effects: Z.of(null) }), t.focus();
416
- }, l = () => {
417
- if (t.state.readOnly) {
418
- c();
419
- return;
420
- }
421
- let e = r.apply(t.state.doc.toString(), n, o.value.trim());
422
- if ("problem" in e) {
423
- s.textContent = e.problem, s.hidden = !1, o.setAttribute("aria-invalid", "true");
424
- return;
425
- }
426
- t.dispatch({
427
- changes: e.edits.map((e) => ({ ...e })),
428
- effects: Z.of(null),
429
- userEvent: "input.rename"
430
- }), t.focus();
431
- };
432
- return o.addEventListener("keydown", (e) => {
433
- e.key !== "Enter" && e.key !== "Escape" || (e.preventDefault(), e.stopPropagation(), e.key === "Enter" ? l() : c());
434
- }), {
435
- dom: a,
436
- mount: () => {
437
- o.focus(), o.select();
438
- }
439
- };
440
- }
441
- };
442
- return t.dispatch({ effects: Z.of(a) }), !0;
443
- }
444
- function xt(e) {
445
- return (t) => {
446
- let n = _t(e, t.state, t.state.selection.main.head);
447
- return t.dispatch({ effects: Z.of(n) }), n !== null;
448
- };
449
- }
450
- function St(e, t, n) {
451
- let r = t.definition?.(e.state.doc.toString(), n);
452
- return r == null ? !1 : (vt(e, r), !0);
453
- }
454
- function Ct(e) {
455
- let t = (t) => {
456
- let n = t.selection.main;
457
- if (!n.empty || e.signatureHelp === void 0) return null;
458
- let r = e.signatureHelp(t.doc.toString(), n.head);
459
- return r === null ? null : {
460
- pos: n.head,
461
- above: !0,
462
- strictSide: !0,
463
- create: () => {
464
- let t = X("div", "flex max-w-[min(28rem,85vw)] flex-col gap-1 px-3 py-2 text-sm"), n = r.signatures[r.active];
465
- if (n !== void 0) {
466
- let e = X("code", "font-mono text-xs break-words whitespace-pre-wrap"), i = n.parameters[r.parameter];
467
- i === void 0 ? e.textContent = n.label : (e.append(n.label.slice(0, i.from)), e.append(X("strong", "font-semibold text-foreground underline", n.label.slice(i.from, i.to))), e.append(n.label.slice(i.to))), t.append(e);
468
- }
469
- return r.signatures.length > 1 && t.append(X("span", "text-xs text-muted-foreground", `${String(r.active + 1)}/${String(r.signatures.length)}`)), r.description !== void 0 && t.append(X("p", "text-muted-foreground", r.description)), r.docsUrl !== void 0 && t.append(pt(r.docsUrl, e.docsLabel)), { dom: t };
470
- }
471
- };
472
- };
473
- return ze.define({
474
- create: t,
475
- update: (e, n) => n.docChanged || n.selection !== void 0 ? t(n.state) : e,
476
- provide: (e) => Ke.from(e)
477
- });
478
- }
479
- var wt = class extends He {
480
- text;
481
- unknown;
482
- constructor(e, t) {
483
- super(), this.text = e, this.unknown = t;
484
- }
485
- eq(e) {
486
- return e.text === this.text && e.unknown === this.unknown;
487
- }
488
- toDOM() {
489
- let e = X("span", this.unknown ? "cm-name-hint ml-1.5 inline-block max-w-40 truncate align-bottom font-sans text-xs text-destructive sm:max-w-64" : "cm-name-hint ml-1.5 inline-block max-w-40 truncate align-bottom font-sans text-xs text-muted-foreground sm:max-w-64", this.text);
490
- return e.title = this.text, e.setAttribute("aria-hidden", "true"), e;
491
- }
492
- ignoreEvent() {
493
- return !1;
494
- }
495
- };
496
- function Tt(e) {
497
- let t = e.nameHints, n = (e) => {
498
- if (t === void 0) return Be.none;
499
- let n = e.state.doc.length, r = t(e.state.doc.toString()).filter((e) => e.offset <= n).map((e) => Be.widget({
500
- widget: new wt(e.text, e.unknown === !0),
501
- side: 1
502
- }).range(e.offset));
503
- return Be.set(r, !0);
504
- };
505
- return Ve.fromClass(class {
506
- decorations;
507
- timer;
508
- view;
509
- constructor(e) {
510
- this.view = e, this.decorations = n(e);
511
- }
512
- update(e) {
513
- e.docChanged && (this.decorations = this.decorations.map(e.changes), clearTimeout(this.timer), this.timer = setTimeout(() => {
514
- this.decorations = n(this.view), this.view.dispatch({});
515
- }, 150));
516
- }
517
- destroy() {
518
- clearTimeout(this.timer);
519
- }
520
- }, { decorations: (e) => e.decorations });
521
- }
522
- function Et(e) {
523
- let t = [];
524
- return e.completions !== void 0 && t.push(Je({
525
- override: [ht(e)],
526
- icons: !0,
527
- closeOnBlur: !0,
528
- tooltipClass: () => "cm-language-completions"
529
- }), Le.highest(G.of([{
530
- key: "Tab",
531
- run: qe
532
- }]))), e.info !== void 0 && t.push(gt, We((t, n) => _t(e, t.state, n), { hideOnChange: !0 }), G.of([{
533
- key: "Mod-k Mod-i",
534
- run: xt(e)
535
- }]), W.domEventHandlers({ pointerup(t, n) {
536
- return t.pointerType === "touch" && setTimeout(() => {
537
- xt(e)(n);
538
- }, 0), !1;
539
- } })), e.signatureHelp !== void 0 && t.push(Ct(e)), e.nameHints !== void 0 && t.push(Tt(e)), e.definition !== void 0 && t.push(G.of([{
540
- key: "F12",
541
- run: (t) => St(t, e, t.state.selection.main.head)
542
- }]), W.domEventHandlers({ mousedown(t, n) {
543
- if (!(t.ctrlKey || t.metaKey) || t.button !== 0) return !1;
544
- let r = n.posAtCoords({
545
- x: t.clientX,
546
- y: t.clientY
547
- });
548
- return r === null || !St(n, e, r) ? !1 : (t.preventDefault(), !0);
549
- } })), (e.references !== void 0 || e.rename !== void 0) && t.push(gt, G.of([{
550
- key: "Shift-F12",
551
- run: (t) => yt(e, t, t.state.selection.main.head)
552
- }, {
553
- key: "F2",
554
- run: (t) => bt(e, t, t.state.selection.main.head)
555
- }])), t;
556
- }
557
- var Dt = Ze, Ot = "\n flex h-8 w-full min-w-0 items-center rounded-lg border border-input bg-transparent text-base\n transition-colors\n focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50\n md:text-sm\n dark:bg-input/30\n [&_.cm-content]:px-2.5 [&_.cm-content]:py-1 [&_.cm-content]:font-mono\n [&_.cm-content]:caret-foreground!\n [&_.cm-cursor]:border-foreground!\n [&_.cm-editor]:w-full [&_.cm-editor]:outline-none\n [&_.cm-line]:p-0\n [&_.cm-placeholder]:text-muted-foreground!\n [&_.cm-scroller]:overflow-x-auto [&_.cm-scroller]:font-mono [&_.cm-scroller]:leading-normal\n [&_.cm-selectionBackground]:bg-primary/20!\n [&_.cm-tooltip]:rounded-md [&_.cm-tooltip]:border! [&_.cm-tooltip]:border-border!\n [&_.cm-tooltip]:bg-popover! [&_.cm-tooltip]:text-popover-foreground [&_.cm-tooltip]:shadow-md\n [&_.cm-tooltip-autocomplete_ul]:max-h-[min(18rem,45vh)]! [&_.cm-tooltip-autocomplete_ul]:font-mono!\n [&_.cm-tooltip-autocomplete_ul_li]:px-2! [&_.cm-tooltip-autocomplete_ul_li]:py-1!\n [&_.cm-tooltip-autocomplete_ul_li[aria-selected]]:bg-accent!\n [&_.cm-tooltip-autocomplete_ul_li[aria-selected]]:text-accent-foreground!\n [&_.cm-completionDetail]:ml-2 [&_.cm-completionDetail]:text-xs\n [&_.cm-completionDetail]:text-muted-foreground [&_.cm-completionDetail]:not-italic!\n [&_.cm-completionInfo]:rounded-md [&_.cm-completionInfo]:border!\n [&_.cm-completionInfo]:border-border! [&_.cm-completionInfo]:bg-popover!\n [&_.cm-completionInfo]:p-0! [&_.cm-completionInfo]:shadow-md\n max-sm:[&_.cm-completionInfo]:hidden!\n [&_.cm-completionMatchedText]:font-semibold [&_.cm-completionMatchedText]:no-underline!\n";
558
- function kt(e) {
559
- return {
560
- get docsLabel() {
561
- return e.current.docsLabel;
562
- },
563
- completions: (t, n) => e.current.completions?.(t, n) ?? null,
564
- info: (t, n) => e.current.info?.(t, n) ?? null,
565
- signatureHelp: (t, n) => e.current.signatureHelp?.(t, n) ?? null
566
- };
567
- }
568
- var At = Ie.transactionFilter.of((e) => {
569
- if (!e.docChanged || e.newDoc.lines === 1) return e;
570
- let t = e.newDoc.toString().replace(/\r?\n/g, " ");
571
- return [e, {
572
- changes: {
573
- from: 0,
574
- to: e.newDoc.length,
575
- insert: t
576
- },
577
- sequential: !0
578
- }];
579
- });
580
- function jt({ id: e, labelId: t, value: n, onChange: r, language: i, invalid: o = !1, placeholder: s, ariaDescribedBy: c, className: l }) {
581
- let u = z(null), d = z(null), f = z(r), p = z(new Fe()), m = z(n), h = z(i);
582
- return L(() => {
583
- f.current = r;
584
- }, [r]), L(() => {
585
- h.current = i;
586
- }, [i]), L(() => {
587
- let e = u.current;
588
- if (e === null) return;
589
- let t = new W({
590
- parent: e,
591
- state: Ie.create({
592
- doc: m.current,
593
- extensions: [
594
- Ue(),
595
- Ne(),
596
- At,
597
- G.of([
598
- {
599
- key: "Enter",
600
- run: (e) => (e.contentDOM.closest("form")?.requestSubmit(), !0)
601
- },
602
- ...Me,
603
- ...Pe
604
- ]),
605
- W.updateListener.of((e) => {
606
- e.docChanged && f.current(e.state.doc.toString());
607
- }),
608
- p.current.of([]),
609
- Et(kt(h))
610
- ]
611
- })
612
- });
613
- return d.current = t, () => {
614
- t.destroy(), d.current = null;
615
- };
616
- }, []), L(() => {
617
- d.current?.dispatch({ effects: p.current.reconfigure([W.contentAttributes.of({
618
- id: e,
619
- spellcheck: "false",
620
- autocapitalize: "off",
621
- autocorrect: "off",
622
- "aria-labelledby": t,
623
- ...c === void 0 ? {} : { "aria-describedby": c },
624
- ...o ? { "aria-invalid": "true" } : {}
625
- }), ...s === void 0 ? [] : [Ge(s)]]) });
626
- }, [
627
- e,
628
- t,
629
- c,
630
- o,
631
- s
632
- ]), L(() => {
633
- let e = document.getElementById(t);
634
- if (e === null) return;
635
- let n = () => {
636
- d.current?.focus();
637
- };
638
- return e.addEventListener("click", n), () => {
639
- e.removeEventListener("click", n);
640
- };
641
- }, [t]), L(() => {
642
- let e = d.current;
643
- e === null || e.state.doc.toString() === n || e.dispatch({ changes: {
644
- from: 0,
645
- to: e.state.doc.length,
646
- insert: n
647
- } });
648
- }, [n]), /* @__PURE__ */ V("div", {
649
- ref: u,
650
- "data-invalid": o ? !0 : void 0,
651
- className: a(Ot, o && "\n border-destructive ring-3 ring-destructive/20\n dark:border-destructive/50 dark:ring-destructive/40\n ", l)
652
- });
653
- }
654
- //#endregion
655
- //#region src/form/fields/formula-field.tsx
656
- function Mt({ label: e, language: t, id: r, description: i }) {
657
- n();
658
- let a = K(), o = r ?? a.name, c = !a.state.meta.isValid, l = Y(a.state.meta.errors, a.name);
659
- return /* @__PURE__ */ H(p, {
660
- "data-invalid": c ? !0 : void 0,
661
- children: [
662
- /* @__PURE__ */ V(d, {
663
- id: `${o}-label`,
664
- htmlFor: o,
665
- children: e
666
- }),
667
- /* @__PURE__ */ V(jt, {
668
- id: o,
669
- labelId: `${o}-label`,
670
- value: a.state.value,
671
- onChange: a.handleChange,
672
- language: t,
673
- invalid: c
674
- }),
675
- i == null ? null : /* @__PURE__ */ V(O, { children: i }),
676
- /* @__PURE__ */ V(s, { errors: l })
677
- ]
678
- });
679
- }
680
- //#endregion
681
- //#region src/workspace/device-presets/quantity.ts
682
- function Nt(e, t, n, r = 2) {
683
- let i = new Intl.NumberFormat(n, {
684
- maximumFractionDigits: r,
685
- useGrouping: !1
686
- }).format(e);
687
- return t.length === 0 ? i : `${i} ${t}`;
688
- }
689
- function Pt(e, t, n) {
690
- return new Intl.NumberFormat(t, {
691
- minimumFractionDigits: n,
692
- maximumFractionDigits: n,
693
- useGrouping: !1
694
- }).format(e);
695
- }
696
- //#endregion
697
- //#region src/workspace/parameters/live/stale-note.ts
698
- function Q(e) {
699
- return t("parameter_value_stale_since", { when: De(e) });
700
- }
701
- function Ft(e) {
702
- return e?.status === "value" && e.freshness === "stale" ? Q(e.snapshot.receivedAt) : void 0;
703
- }
704
- //#endregion
705
- //#region src/workspace/parameters/live/value-display.tsx
706
- function It({ state: e, locale: n, children: r, skeletonClassName: i = "h-6 w-20", unavailable: a = t("parameter_value_unavailable") }) {
707
- if (N(e)) return /* @__PURE__ */ V(j, { className: i });
708
- if (e.status === "idle" || e.status === "error") return /* @__PURE__ */ V("span", {
709
- className: "text-muted-foreground",
710
- children: a
711
- });
712
- let o = e.freshness === "stale" ? Q(e.snapshot.receivedAt) : void 0;
713
- return /* @__PURE__ */ H("span", {
714
- className: "inline-flex min-w-0 items-center gap-2",
715
- children: [/* @__PURE__ */ V("span", {
716
- className: o == null ? "truncate" : "truncate text-muted-foreground",
717
- title: o,
718
- children: r == null ? U(e.snapshot.value, n) : r(e.snapshot)
719
- }), o == null ? null : /* @__PURE__ */ V("span", {
720
- className: "sr-only",
721
- children: o
722
- })]
723
- });
724
- }
725
- function Lt({ state: e, trueLabel: t, falseLabel: n, trueVariant: r = "destructive", falseVariant: i = "success", flag: a = !1 }) {
726
- let o = a ? se(e) : oe(e);
727
- if (o == null) return N(e) ? /* @__PURE__ */ V(j, { className: "h-5 w-16" }) : /* @__PURE__ */ V(E, {
728
- variant: "outline",
729
- children: "—"
730
- });
731
- let s = e.status === "value" && e.freshness === "stale" ? Q(e.snapshot.receivedAt) : void 0;
732
- return /* @__PURE__ */ H("span", {
733
- className: "inline-flex flex-wrap items-center gap-2",
734
- children: [/* @__PURE__ */ V(E, {
735
- variant: o ? r : i,
736
- className: s == null ? void 0 : "opacity-60",
737
- title: s,
738
- children: o ? t : n
739
- }), s == null ? null : /* @__PURE__ */ V("span", {
740
- className: "sr-only",
741
- children: s
742
- })]
743
- });
744
- }
745
- //#endregion
746
- //#region src/workspace/parameters/live/metric.tsx
747
- function Rt({ state: e, locale: t, unit: n = "", fractionDigits: i, unavailable: a, skeletonClassName: o }) {
748
- let s = r();
749
- return /* @__PURE__ */ H("span", {
750
- className: "inline-flex max-w-full items-baseline gap-1 tabular-nums",
751
- children: [/* @__PURE__ */ V(It, {
752
- state: e,
753
- locale: t,
754
- unavailable: a ?? /* @__PURE__ */ V("span", {
755
- className: "text-sm font-normal wrap-anywhere",
756
- children: s("parameter_value_unavailable")
757
- }),
758
- ...o == null ? {} : { skeletonClassName: o },
759
- ...i == null ? {} : { children: (e) => e.numberValue == null ? "—" : Pt(e.numberValue, t, i) }
760
- }), e.status === "value" && n ? /* @__PURE__ */ V("span", {
761
- className: "shrink-0 text-xs font-normal text-muted-foreground",
762
- children: n
763
- }) : null]
764
- });
765
- }
766
- function zt({ label: e, icon: t, state: n, locale: r, unit: i = "", compact: a = !1, marker: o }) {
767
- return /* @__PURE__ */ H("div", {
768
- className: "flex min-w-0 items-start gap-2.5",
769
- children: [t == null ? null : /* @__PURE__ */ V("span", {
770
- "aria-hidden": "true",
771
- className: "\n size-4 shrink-0 text-muted-foreground\n [&_svg]:size-4\n ",
772
- children: t
773
- }), /* @__PURE__ */ H("div", {
774
- className: "min-w-0",
775
- children: [/* @__PURE__ */ V("div", {
776
- title: e,
777
- className: a ? "text-xs text-muted-foreground" : "min-h-8 text-xs text-muted-foreground",
778
- children: e
779
- }), /* @__PURE__ */ H("div", {
780
- className: a ? "mt-0.5 text-lg font-semibold tracking-tight" : "mt-1 text-2xl font-semibold tracking-tight",
781
- children: [/* @__PURE__ */ V(Rt, {
782
- state: n,
783
- locale: r,
784
- unit: i
785
- }), o]
786
- })]
787
- })]
788
- });
789
- }
790
- //#endregion
791
- //#region src/workspace/parameters/live/coordinator.ts
792
- var Bt = 1e4, Vt = 250, Ht = 6e4, Ut = 3e4;
793
- function Wt(e) {
794
- return (typeof DOMException < "u" && e instanceof DOMException || e instanceof Error) && e.name === "AbortError";
795
- }
796
- function Gt(e, t) {
797
- if (typeof e != "object" || !e) return null;
798
- let n = Reflect.get(e, t);
799
- return typeof n == "string" ? n : null;
800
- }
801
- function Kt(e, t) {
802
- if (typeof e != "object" || !e) return null;
803
- let n = Reflect.get(e, t);
804
- return typeof n == "number" && Number.isFinite(n) ? n : null;
805
- }
806
- function qt(e, t) {
807
- if (typeof e != "object" || !e) return null;
808
- let n = Reflect.get(e, t);
809
- return typeof n == "object" && n ? n : null;
810
- }
811
- function Jt(e, t) {
812
- let n = qt(e, "data"), r = Gt(n, "code") ?? Gt(e, "code") ?? "", i = Kt(n, "retryAfterMs") ?? Kt(n, "tryAgainIn") ?? Kt(e, "retryAfterMs") ?? Kt(e, "tryAgainIn");
813
- return r === "FORBIDDEN" || r === "UNAUTHORIZED" ? {
814
- kind: "permission",
815
- code: "permission_denied",
816
- parameterIds: t
817
- } : r === "TOO_MANY_REQUESTS" ? {
818
- kind: "capacity",
819
- code: "request_failed",
820
- parameterIds: t,
821
- ...i != null && i > 0 ? { retryAfterMs: i } : {}
822
- } : {
823
- kind: "internal",
824
- code: "request_failed",
825
- parameterIds: t
826
- };
827
- }
828
- function Yt(e, t) {
829
- if (e.kind === "permission") return null;
830
- if (e.kind === "configuration") return Ht;
831
- if (e.kind === "capacity" && e.retryAfterMs != null) return Math.max(Vt, e.retryAfterMs);
832
- let n = [
833
- 2e3,
834
- 5e3,
835
- 1e4,
836
- Ut
837
- ], r = n[Math.min(t, n.length - 1)] ?? Ut, i = Math.round(r * .08 * (t % 3 - 1));
838
- return Math.max(Vt, r + i);
839
- }
840
- function Xt(e, t) {
841
- return {
842
- value: e.value,
843
- rawHex: e.rawHex,
844
- ...e.numberValue === void 0 ? {} : { numberValue: e.numberValue },
845
- ...e.boolValue === void 0 ? {} : { boolValue: e.boolValue },
846
- receivedAt: e.acquiredAt == null ? t : Date.parse(e.acquiredAt)
847
- };
848
- }
849
- var Zt = class {
850
- transport;
851
- access;
852
- visible = !0;
853
- states = /* @__PURE__ */ new Map();
854
- listenersByParameter = /* @__PURE__ */ new Map();
855
- allListeners = /* @__PURE__ */ new Set();
856
- demands = /* @__PURE__ */ new Map();
857
- activeIntervals = /* @__PURE__ */ new Map();
858
- manualIds = /* @__PURE__ */ new Set();
859
- dueAt = /* @__PURE__ */ new Map();
860
- failureAttempts = /* @__PURE__ */ new Map();
861
- suspendedIds = /* @__PURE__ */ new Set();
862
- versions = /* @__PURE__ */ new Map();
863
- pendingWrites = /* @__PURE__ */ new Map();
864
- timer = null;
865
- inFlight = null;
866
- revision = 0;
867
- notificationTimer = null;
868
- stopped = !1;
869
- sequenceTail = Promise.resolve();
870
- constructor(e) {
871
- this.transport = e.transport, this.access = e.access;
872
- }
873
- setTransport(e) {
874
- this.transport = e;
875
- }
876
- setAccess(e) {
877
- e !== this.access && (this.access = e, this.notifyAll());
878
- }
879
- setVisible(e) {
880
- if (e !== this.visible) {
881
- if (this.visible = e, e) {
882
- let e = Date.now();
883
- for (let t of this.demandedIntervals().keys()) this.dueAt.set(t, e);
884
- this.schedule();
885
- } else {
886
- for (let e of this.demandedIntervals().keys()) this.markStale(e);
887
- this.cancelRead(), this.clearTimer();
888
- }
889
- this.notifyAll();
890
- }
891
- }
892
- isPaused() {
893
- return !this.visible;
894
- }
895
- getRevision = () => this.revision;
896
- subscribeAll = (e) => (this.allListeners.add(e), () => this.allListeners.delete(e));
897
- subscribeParameter(e, t) {
898
- let n = this.listenersByParameter.get(e);
899
- return n ?? (n = /* @__PURE__ */ new Set(), this.listenersByParameter.set(e, n)), n.add(t), () => {
900
- n.delete(t), n.size === 0 && this.listenersByParameter.delete(e);
901
- };
902
- }
903
- getState(e) {
904
- return this.states.get(e) ?? P;
905
- }
906
- registerDemand(e, t) {
907
- let n = new Set(t.parameterIds);
908
- this.demands.set(e, {
909
- parameterIds: n,
910
- intervalMs: Math.max(Vt, Math.round(t.intervalMs)),
911
- enabled: t.enabled
912
- }), this.reconcileDemand();
913
- }
914
- unregisterDemand(e) {
915
- this.demands.delete(e), this.reconcileDemand();
916
- }
917
- refresh(e) {
918
- let t = Date.now();
919
- for (let n of new Set(e)) {
920
- this.bumpVersion(n), this.manualIds.add(n), this.suspendedIds.delete(n), this.dueAt.set(n, t);
921
- let e = this.states.get(n);
922
- (e == null || e.status === "idle") && this.setState(n, { status: "loading" });
923
- }
924
- this.schedule();
925
- }
926
- readNow(e) {
927
- let t = Date.now(), n = this.demandedIntervals(), r = /* @__PURE__ */ new Set();
928
- for (let i of new Set(e)) !n.has(i) || this.suspendedIds.has(i) || (this.dueAt.set(i, t), r.add(i));
929
- return this.schedule(), r;
930
- }
931
- retry(e) {
932
- for (let t of e) this.failureAttempts.delete(t), this.suspendedIds.delete(t);
933
- this.refresh(e);
934
- }
935
- runSequence(e) {
936
- let t = this.sequenceTail.then(e, e);
937
- return this.sequenceTail = t.catch(() => void 0), t;
938
- }
939
- async writeValues(e, t = {}) {
940
- if (!Qe(this.access)) throw Error("workspace_not_operator");
941
- let n = [...new Set(e.items.map((e) => e.paramId))], r = Symbol();
942
- for (let e of n) this.bumpVersion(e), this.pendingWrites.set(e, r), this.updateSaving(e);
943
- try {
944
- let t = await this.transport.write(e);
945
- for (let e of n) {
946
- if (this.pendingWrites.get(e) !== r) continue;
947
- let n = t.results[e];
948
- if (n == null) this.applyDiagnostic(e, {
949
- kind: "internal",
950
- code: "request_failed",
951
- parameterIds: [e]
952
- });
953
- else if (n.status === "ok") {
954
- let t = this.getState(e);
955
- t.status === "value" && this.setState(e, {
956
- ...t,
957
- freshness: "stale"
958
- });
959
- } else this.applyDiagnostic(e, F(e, n));
960
- }
961
- return t;
962
- } catch (e) {
963
- let t = Jt(e, n);
964
- for (let e of n) this.pendingWrites.get(e) === r && this.applyDiagnostic(e, {
965
- ...t,
966
- parameterIds: [e]
967
- });
968
- throw e;
969
- } finally {
970
- let e = n.filter((e) => this.pendingWrites.get(e) === r);
971
- for (let t of e) this.pendingWrites.delete(t), this.updateSaving(t);
972
- let i = new Set(t.writeOnly);
973
- this.refresh(e.filter((e) => !i.has(e)));
974
- }
975
- }
976
- stop() {
977
- this.stopped = !0, this.notificationTimer !== null && clearTimeout(this.notificationTimer), this.notificationTimer = null, this.clearTimer(), this.cancelRead(), this.demands.clear(), this.activeIntervals.clear(), this.manualIds.clear(), this.suspendedIds.clear();
978
- }
979
- start() {
980
- this.stopped && (this.stopped = !1, this.reconcileDemand());
981
- }
982
- reconcileDemand() {
983
- let e = this.demandedIntervals(), t = Date.now();
984
- for (let n of e.keys()) {
985
- this.activeIntervals.get(n) === e.get(n) ? this.dueAt.has(n) || this.dueAt.set(n, t) : (this.bumpVersion(n), this.dueAt.set(n, t));
986
- let r = this.states.get(n);
987
- (r == null || r.status === "idle") && this.setState(n, { status: "loading" });
988
- }
989
- for (let t of this.activeIntervals.keys()) !e.has(t) && !this.manualIds.has(t) && (this.bumpVersion(t), this.dueAt.delete(t), this.markStale(t));
990
- for (let t of [...this.dueAt.keys()]) !e.has(t) && !this.manualIds.has(t) && (this.dueAt.delete(t), this.markStale(t));
991
- this.activeIntervals = e, e.size === 0 && this.manualIds.size === 0 ? (this.clearTimer(), this.cancelRead()) : this.schedule(), this.notifyAll();
992
- }
993
- demandedIntervals() {
994
- let e = /* @__PURE__ */ new Map();
995
- for (let t of this.demands.values()) if (t.enabled) for (let n of t.parameterIds) e.set(n, Math.min(e.get(n) ?? Infinity, t.intervalMs));
996
- return e;
997
- }
998
- schedule() {
999
- if (this.stopped || !this.visible || this.inFlight != null) return;
1000
- this.clearTimer();
1001
- let e = this.demandedIntervals(), t = new Set([...e.keys(), ...this.manualIds].filter((e) => !this.suspendedIds.has(e)));
1002
- if (t.size === 0) return;
1003
- let n = Date.now(), r = Infinity;
1004
- for (let e of t) r = Math.min(r, this.dueAt.get(e) ?? n);
1005
- let i = Math.max(0, r - n);
1006
- this.timer = setTimeout(() => {
1007
- this.timer = null, this.runDueRead();
1008
- }, i);
1009
- }
1010
- async runDueRead() {
1011
- if (this.inFlight != null || this.stopped || !this.visible) return;
1012
- let e = Date.now(), t = this.demandedIntervals(), n = [...new Set([...t.keys(), ...this.manualIds].filter((e) => !this.suspendedIds.has(e)))].filter((t) => (this.dueAt.get(t) ?? e) <= e).sort((t, n) => (this.dueAt.get(t) ?? e) - (this.dueAt.get(n) ?? e)).slice(0, Bt);
1013
- if (n.length === 0) {
1014
- this.schedule();
1015
- return;
1016
- }
1017
- let r = new AbortController(), i = /* @__PURE__ */ new Map();
1018
- for (let e of n) i.set(e, this.versions.get(e) ?? 0), this.markRefreshing(e), this.dueAt.delete(e);
1019
- let a = {
1020
- controller: r,
1021
- versions: i,
1022
- parameterIds: n
1023
- };
1024
- this.inFlight = a;
1025
- let o = /* @__PURE__ */ new Set();
1026
- try {
1027
- let e = await this.transport.read(n, r.signal);
1028
- for await (let n of e) {
1029
- if (r.signal.aborted || this.inFlight !== a) break;
1030
- if (n.type === "ping") continue;
1031
- o.add(n.paramId);
1032
- let e = i.get(n.paramId);
1033
- e == null || e !== (this.versions.get(n.paramId) ?? 0) || this.applyReadResult(n.paramId, n.result, t);
1034
- }
1035
- if (!r.signal.aborted) for (let e of n) o.has(e) || (this.applyDiagnostic(e, {
1036
- kind: "internal",
1037
- code: "request_failed",
1038
- parameterIds: [e]
1039
- }), this.manualIds.delete(e), this.setNextDue(e, t));
1040
- } catch (e) {
1041
- if (!r.signal.aborted && !Wt(e)) {
1042
- let r = Jt(e, n);
1043
- for (let e of n) o.has(e) || (this.applyDiagnostic(e, {
1044
- ...r,
1045
- parameterIds: [e]
1046
- }), this.manualIds.delete(e), this.setNextDue(e, t));
1047
- }
1048
- } finally {
1049
- if (this.inFlight === a && (this.inFlight = null), r.signal.aborted) for (let e of n) this.clearRefreshing(e);
1050
- this.schedule();
1051
- }
1052
- }
1053
- applyReadResult(e, t, n) {
1054
- t.status === "ok" ? (this.failureAttempts.delete(e), this.suspendedIds.delete(e), this.setState(e, {
1055
- status: "value",
1056
- snapshot: Xt(t, Date.now()),
1057
- freshness: "fresh",
1058
- refreshing: !1,
1059
- saving: this.pendingWrites.has(e)
1060
- }), this.setNextDue(e, n)) : (this.applyDiagnostic(e, F(e, t)), this.setNextDue(e, n)), this.manualIds.delete(e);
1061
- }
1062
- setNextDue(e, t) {
1063
- let n = t.get(e), r = this.states.get(e);
1064
- if (r?.status === "value" && r.freshness === "fresh" && n != null) {
1065
- this.dueAt.set(e, Date.now() + n);
1066
- return;
1067
- }
1068
- let i = r?.status === "error" || r?.status === "value" ? r.diagnostic : void 0;
1069
- if (i == null) return;
1070
- let a = this.failureAttempts.get(e) ?? 0, o = Yt(i, a);
1071
- if (this.failureAttempts.set(e, a + 1), o != null && n != null) {
1072
- let t = Date.now() + o;
1073
- this.dueAt.set(e, t), r?.status === "error" && this.setState(e, {
1074
- ...r,
1075
- retryAt: t
1076
- });
1077
- } else o == null && n != null && this.suspendedIds.add(e);
1078
- }
1079
- applyDiagnostic(e, t) {
1080
- let n = this.states.get(e);
1081
- if (n?.status === "value" && t.kind !== "unavailable") {
1082
- this.setState(e, {
1083
- ...n,
1084
- freshness: "stale",
1085
- refreshing: !1,
1086
- saving: this.pendingWrites.has(e),
1087
- diagnostic: t
1088
- });
1089
- return;
1090
- }
1091
- this.setState(e, {
1092
- status: "error",
1093
- diagnostic: t,
1094
- refreshing: !1,
1095
- saving: this.pendingWrites.has(e)
1096
- });
1097
- }
1098
- markStale(e) {
1099
- let t = this.states.get(e);
1100
- t?.status === "value" && t.freshness === "fresh" && this.setState(e, {
1101
- ...t,
1102
- freshness: "stale",
1103
- refreshing: !1
1104
- });
1105
- }
1106
- markRefreshing(e) {
1107
- let t = this.states.get(e);
1108
- t?.status === "value" || t?.status === "error" ? this.setState(e, {
1109
- ...t,
1110
- refreshing: !0
1111
- }) : this.setState(e, { status: "loading" });
1112
- }
1113
- clearRefreshing(e) {
1114
- let t = this.states.get(e);
1115
- (t?.status === "value" || t?.status === "error") && this.setState(e, {
1116
- ...t,
1117
- refreshing: !1
1118
- });
1119
- }
1120
- updateSaving(e) {
1121
- let t = this.states.get(e);
1122
- (t?.status === "value" || t?.status === "error") && this.setState(e, {
1123
- ...t,
1124
- saving: this.pendingWrites.has(e)
1125
- });
1126
- }
1127
- setState(e, t) {
1128
- this.states.set(e, t);
1129
- let n = this.listenersByParameter.get(e);
1130
- if (n != null) for (let e of n) e();
1131
- this.notifyAll();
1132
- }
1133
- notifyAll() {
1134
- this.stopped || this.notificationTimer !== null || (this.notificationTimer = setTimeout(() => {
1135
- this.notificationTimer = null, this.revision += 1;
1136
- for (let e of this.allListeners) e();
1137
- }, 16));
1138
- }
1139
- bumpVersion(e) {
1140
- this.versions.set(e, (this.versions.get(e) ?? 0) + 1);
1141
- }
1142
- clearTimer() {
1143
- this.timer != null && (clearTimeout(this.timer), this.timer = null);
1144
- }
1145
- cancelRead() {
1146
- this.inFlight?.controller.abort(), this.inFlight = null;
1147
- }
1148
- }, Qt = 8e3;
1149
- function $t(e) {
1150
- return N(e) ? !1 : e.status === "idle" ? !0 : e.refreshing ? !1 : e.status === "error" || e.freshness === "fresh" || e.diagnostic != null;
1151
- }
1152
- function en(e) {
1153
- return e.status === "idle" ? e.reason !== "no-demand" : ae(e) && !e.refreshing;
1154
- }
1155
- function tn(e, t, n = Qt) {
1156
- let r = [...new Set(t)], i = {};
1157
- e.registerDemand(i, {
1158
- parameterIds: r,
1159
- intervalMs: n,
1160
- enabled: !0
1161
- });
1162
- let a = new Map(r.map((t) => [t, e.getState(t)])), o = e.readNow(r);
1163
- return new Promise((t) => {
1164
- let s = !1, c = () => {
1165
- if (s) return;
1166
- s = !0, u(), clearTimeout(d);
1167
- let n = new Map(r.map((t) => [t, e.getState(t)]));
1168
- e.unregisterDemand(i), t(n);
1169
- }, l = () => {
1170
- r.every((t) => {
1171
- let n = e.getState(t);
1172
- return $t(n) && (!o.has(t) || n !== a.get(t) || en(n));
1173
- }) && c();
1174
- }, u = e.subscribeAll(l), d = setTimeout(c, n);
1175
- l();
1176
- });
1177
- }
1178
- //#endregion
1179
- //#region src/workspace/parameters/live/provider.tsx
1180
- var nn = fe(null);
1181
- function $() {
1182
- let e = me(nn);
1183
- if (e == null) throw Error("Parameter value hooks require ParameterValuesProvider");
1184
- return e;
1185
- }
1186
- function rn({ children: t, access: n }) {
1187
- let r = ce(), i = n ?? r?.access ?? "view_only", a = e.useUtils(), o = R(() => ({
1188
- read: (e, t) => a.client.parameter.readValuesStream.mutate({ paramIds: [...e] }, { signal: t }),
1189
- write: (e) => a.client.parameter.writeValues.mutate(e)
1190
- }), [a.client]), [s] = B(() => new Zt({
1191
- transport: o,
1192
- access: i
1193
- }));
1194
- return L(() => {
1195
- s.setTransport(o);
1196
- }, [s, o]), L(() => {
1197
- s.setAccess(i);
1198
- }, [s, i]), L(() => {
1199
- let e = () => {
1200
- s.setVisible(document.visibilityState === "visible");
1201
- };
1202
- return e(), document.addEventListener("visibilitychange", e), () => {
1203
- document.removeEventListener("visibilitychange", e);
1204
- };
1205
- }, [s]), L(() => (s.start(), () => {
1206
- s.stop();
1207
- }), [s]), pe(nn.Provider, { value: s }, t);
1208
- }
1209
- function an({ children: e }) {
1210
- return me(nn) == null ? pe(rn, null, e) : e;
1211
- }
1212
- function on(e) {
1213
- return [...new Set(e)].sort().join("\0");
1214
- }
1215
- function sn(e) {
1216
- return e.length === 0 ? [] : e.split("\0");
1217
- }
1218
- function cn() {
1219
- return () => void 0;
1220
- }
1221
- function ln() {
1222
- return 0;
1223
- }
1224
- function un({ parameterIds: e, intervalMs: t, enabled: n = !0 }) {
1225
- let r = $(), i = z({}), a = on(e), o = R(() => sn(a), [a]), s = o.length > 0;
1226
- ge(s ? r.subscribeAll : cn, s ? r.getRevision : ln, s ? r.getRevision : ln), L(() => {
1227
- let e = i.current;
1228
- return r.registerDemand(e, {
1229
- parameterIds: o,
1230
- intervalMs: t,
1231
- enabled: n
1232
- }), () => {
1233
- r.unregisterDemand(e);
1234
- };
1235
- }, [
1236
- r,
1237
- n,
1238
- o,
1239
- t
1240
- ]);
1241
- let c = I(() => {
1242
- r.retry(o);
1243
- }, [r, o]);
1244
- return {
1245
- ...M({
1246
- parameterIds: o,
1247
- getState: (e) => r.getState(e),
1248
- enabled: n,
1249
- paused: r.isPaused()
1250
- }),
1251
- retry: c
1252
- };
1253
- }
1254
- function dn(e) {
1255
- let t = me(nn), n = I(() => t != null && e.some((e) => {
1256
- let n = t.getState(e);
1257
- return n.status === "loading" || (n.status === "value" || n.status === "error") && n.refreshing;
1258
- }), [t, e]);
1259
- return ge(t == null ? cn : t.subscribeAll, n, n);
1260
- }
1261
- function fn(e) {
1262
- let t = $(), n = I((n) => t.subscribeParameter(e, n), [t, e]), r = I(() => t.getState(e), [t, e]);
1263
- return ge(n, r, r);
1264
- }
1265
- function pn() {
1266
- let e = $(), t = I((t) => {
1267
- e.refresh(t);
1268
- }, [e]), n = I((t, n) => e.writeValues(t, n), [e]), r = I((t) => e.runSequence(t), [e]);
1269
- return R(() => ({
1270
- refreshValues: t,
1271
- writeValues: n,
1272
- runSequence: r
1273
- }), [
1274
- t,
1275
- n,
1276
- r
1277
- ]);
1278
- }
1279
- function mn() {
1280
- let e = $();
1281
- return I((t, n) => tn(e, t, n), [e]);
1282
- }
1283
- function hn() {
1284
- return $();
1285
- }
1286
- //#endregion
1287
- //#region src/workspace/parameters/option-labels.ts
1288
- function gn(e) {
1289
- switch (e) {
1290
- case "holding-register": return t("parameter_option_table_holding_register");
1291
- case "input-register": return t("parameter_option_table_input_register");
1292
- case "coil": return t("parameter_option_table_coil");
1293
- case "discrete-input": return t("parameter_option_table_discrete_input");
1294
- }
1295
- }
1296
- function _n(e) {
1297
- switch (e) {
1298
- case "none": return t("parameter_option_write_none");
1299
- case "single-write": return t("parameter_option_write_single");
1300
- case "multi-or-single-write": return t("parameter_option_write_multi_or_single");
1301
- case "always-multi-write": return t("parameter_option_write_always_multi");
1302
- }
1303
- }
1304
- function vn(e) {
1305
- switch (e) {
1306
- case "float": return t("parameter_option_return_float");
1307
- case "int": return t("parameter_option_return_int");
1308
- }
1309
- }
1310
- function yn(e) {
1311
- switch (e) {
1312
- case "bytes": return t("parameter_option_swap_bytes");
1313
- case "words": return t("parameter_option_swap_words");
1314
- }
1315
- }
1316
- function bn(e) {
1317
- switch (e) {
1318
- case "leave-first-byte-in-word": return t("parameter_option_filter_leave_first");
1319
- case "leave-last-byte-in-word": return t("parameter_option_filter_leave_last");
1320
- }
1321
- }
1322
- function xn(e) {
1323
- switch (e) {
1324
- case "str": return t("parameter_option_value_type_str");
1325
- case "num": return t("parameter_option_value_type_num");
1326
- case "int": return t("parameter_option_value_type_int");
1327
- case "bool": return t("parameter_option_value_type_bool");
1328
- case "bigint": return t("parameter_option_value_type_bigint");
1329
- case "datetime": return t("parameter_option_value_type_datetime");
1330
- case "ipaddr": return t("parameter_option_value_type_ipaddr");
1331
- case "macaddr": return t("parameter_option_value_type_macaddr");
1332
- case "geo": return t("parameter_option_value_type_geo");
1333
- }
1334
- }
1335
- function Sn(e) {
1336
- switch (e) {
1337
- case "ascii": return t("parameter_option_encoding_ascii");
1338
- case "utf8": return t("parameter_option_encoding_utf8");
1339
- case "utf16le": return t("parameter_option_encoding_utf16le");
1340
- case "base64": return t("parameter_option_encoding_base64");
1341
- case "hex": return t("parameter_option_encoding_hex");
1342
- }
1343
- }
1344
- function Cn(e) {
1345
- switch (e) {
1346
- case "unsigned-int": return t("parameter_option_packing_unsigned_int");
1347
- case "signed-int": return t("parameter_option_packing_signed_int");
1348
- case "bcd-int": return t("parameter_option_packing_bcd_int");
1349
- case "bcd": return t("parameter_option_packing_bcd");
1350
- case "float16": return t("parameter_option_packing_float16");
1351
- case "float32": return t("parameter_option_packing_float32");
1352
- case "float64": return t("parameter_option_packing_float64");
1353
- case "decimal16": return t("parameter_option_packing_decimal16");
1354
- case "decimal32": return t("parameter_option_packing_decimal32");
1355
- case "decimal64": return t("parameter_option_packing_decimal64");
1356
- }
1357
- }
1358
- function wn(e) {
1359
- switch (e) {
1360
- case "timestamp-sec-32": return t("parameter_option_datetime_kind_timestamp_sec_32");
1361
- case "timestamp-msec-32": return t("parameter_option_datetime_kind_timestamp_msec_32");
1362
- case "timestamp-days-32": return t("parameter_option_datetime_kind_timestamp_days_32");
1363
- case "timestamp-days-16": return t("parameter_option_datetime_kind_timestamp_days_16");
1364
- case "iso-8601-string": return t("parameter_option_datetime_kind_iso_8601");
1365
- case "datetime": return t("parameter_option_datetime_kind_datetime");
1366
- }
1367
- }
1368
- function Tn(e) {
1369
- switch (e) {
1370
- case "ipv4": return t("parameter_option_ip_ipv4");
1371
- case "ipv6": return t("parameter_option_ip_ipv6");
1372
- }
1373
- }
1374
- function En(e) {
1375
- switch (e) {
1376
- case "hours": return t("parameter_option_tz_hours");
1377
- case "minutes": return t("parameter_option_tz_minutes");
1378
- case "seconds": return t("parameter_option_tz_seconds");
1379
- }
1380
- }
1381
- //#endregion
1382
- //#region src/workspace/parameters/display.ts
1383
- function Dn(e) {
1384
- if (e.length === 0) return "0";
1385
- let t = e[0] ?? 0;
1386
- if (e.length === 1) return String(t);
1387
- let n = e[e.length - 1] ?? t;
1388
- return e.every((t, n) => n === 0 || t === (e[n - 1] ?? 0) + 1) ? `${String(t)}-${String(n)}` : e.join(",");
1389
- }
1390
- function On(e) {
1391
- switch (e) {
1392
- case "coil": return t("parameter_list_modbus_table_coil");
1393
- case "discrete-input": return t("parameter_list_modbus_table_discrete_input");
1394
- case "holding-register": return t("parameter_list_modbus_table_holding_register");
1395
- case "input-register": return t("parameter_list_modbus_table_input_register");
1396
- }
1397
- }
1398
- function kn(e, t) {
1399
- let n = t.get(e);
1400
- return n != null && n.length > 0 ? n : e.slice(0, 8);
1401
- }
1402
- function An(e, t) {
1403
- if (e == null) return null;
1404
- let n = U(e, t).trim();
1405
- return n.length > 0 ? n : null;
1406
- }
1407
- function jn(e, t = i()) {
1408
- return {
1409
- mnemonic: An(e.mnemonic, t),
1410
- name: U(e.name, t),
1411
- units: An(e.units, t)
1412
- };
1413
- }
1414
- function Mn(e, t) {
1415
- return e || t == null ? null : t;
1416
- }
1417
- function Nn(e) {
1418
- let t = Math.floor(e / 1e3);
1419
- return t % 3600 == 0 ? {
1420
- n: t / 3600,
1421
- unit: "h"
1422
- } : t % 60 == 0 ? {
1423
- n: t / 60,
1424
- unit: "m"
1425
- } : {
1426
- n: t,
1427
- unit: "s"
1428
- };
1429
- }
1430
- function Pn(e) {
1431
- let { n, unit: r } = Nn(e), i = String(n);
1432
- switch (r) {
1433
- case "h": return t("parameter_background_reading_period_compact_hours", { n: i });
1434
- case "m": return t("parameter_background_reading_period_compact_minutes", { n: i });
1435
- case "s": return t("parameter_background_reading_period_compact_seconds", { n: i });
1436
- }
1437
- }
1438
- function Fn(e) {
1439
- return t("parameter_background_reading_period_aria", { seconds: String(Math.floor(e / 1e3)) });
1440
- }
1441
- function In(e, n) {
1442
- let r = i(), a = e.valueType.name, o = xn(a), s = An(e.description, r), c, l = e.source;
1443
- if (l.kind === "const") c = [
1444
- t("parameter_list_source_const"),
1445
- l.key,
1446
- o
1447
- ].join(" · ");
1448
- else if (l.kind === "calc") c = [
1449
- t("parameter_list_source_calc"),
1450
- t("parameter_details_calc_inputs", { count: String(l.inputParamIds.length) }),
1451
- o
1452
- ].join(" · ");
1453
- else {
1454
- let e = `${On(l.table)} ${Dn(l.addresses)}`;
1455
- c = [
1456
- kn(l.endpointId, n),
1457
- t("parameter_details_unit", { id: String(l.unitId) }),
1458
- e,
1459
- o
1460
- ].join(" · ");
1461
- }
1462
- return {
1463
- description: s,
1464
- metaLine: c,
1465
- tags: [...e.tags]
1466
- };
1467
- }
1468
- function Ln(e, t) {
1469
- return e != null && Oe(e).some((e) => e.toLowerCase().includes(t));
1470
- }
1471
- //#endregion
1472
- //#region src/workspace/parameters/picker/model.ts
1473
- function Rn(e, t) {
1474
- if (e == null) return null;
1475
- let n = U(e, t).trim();
1476
- return n.length > 0 ? n : null;
1477
- }
1478
- function zn(e) {
1479
- switch (e.kind) {
1480
- case "modbus-tcp": return `${On(e.table)} ${Dn(e.addresses)}`;
1481
- case "const": return e.key;
1482
- case "calc": return null;
1483
- }
1484
- }
1485
- function Bn(e) {
1486
- let t = /* @__PURE__ */ new Map();
1487
- for (let n of e.branches) t.set(n.id, n);
1488
- let n = /* @__PURE__ */ new Map(), r = (r) => {
1489
- let i = n.get(r);
1490
- if (i != null) return i;
1491
- let a = [], o = /* @__PURE__ */ new Set(), s = r;
1492
- for (; s != null && !o.has(s);) {
1493
- o.add(s);
1494
- let n = t.get(s);
1495
- if (n == null) break;
1496
- a.unshift(U(n.name, e.locale)), s = n.parentId;
1497
- }
1498
- return n.set(r, a), a;
1499
- }, i = [...e.branches].sort((e, t) => e.sortOrder - t.sortOrder || e.id.localeCompare(t.id)), a = [...e.parameters].sort((e, t) => e.sortOrder - t.sortOrder || e.id.localeCompare(t.id)), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
1500
- for (let t of a) {
1501
- let n = U(t.name, e.locale), i = Rn(t.mnemonic, e.locale), a = zn(t.source), c = r(t.branchId), l = {
1502
- id: t.id,
1503
- branchId: t.branchId,
1504
- name: n,
1505
- mnemonic: i,
1506
- units: Rn(t.units, e.locale),
1507
- address: a,
1508
- path: c,
1509
- disabled: t.disabledSince != null,
1510
- valueTypeName: t.valueType.name,
1511
- order: 0,
1512
- haystack: [
1513
- ...Oe(t.name),
1514
- ...t.mnemonic == null ? [] : Oe(t.mnemonic),
1515
- ...c,
1516
- a ?? "",
1517
- ...t.source.kind === "modbus-tcp" ? t.source.addresses.map(String) : []
1518
- ].join("\n").toLowerCase()
1519
- };
1520
- if (o.set(t.id, l), l.disabled && e.includeDisabled !== !0 || e.include != null && !e.include(t)) continue;
1521
- let u = s.get(t.branchId) ?? [];
1522
- u.push(l), s.set(t.branchId, u);
1523
- }
1524
- let c = /* @__PURE__ */ new Map();
1525
- for (let e of i) {
1526
- let n = e.parentId != null && t.has(e.parentId) ? e.parentId : null, r = c.get(n) ?? [];
1527
- r.push(e), c.set(n, r);
1528
- }
1529
- let l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = [], m = /* @__PURE__ */ new Set(), h = (t, n) => {
1530
- if (m.has(t.id)) return [];
1531
- m.add(t.id);
1532
- let r = [], i = {
1533
- id: t.id,
1534
- parentId: n,
1535
- name: U(t.name, e.locale)
1536
- }, a = [];
1537
- for (let e of c.get(t.id) ?? []) {
1538
- let n = h(e, t.id), i = l.get(e.id);
1539
- n.length === 0 || i == null || (r.push(...n), a.push(i));
1540
- }
1541
- let o = s.get(t.id) ?? [];
1542
- for (let e of o) p.push(e), r.push(e.id);
1543
- return r.length === 0 ? r : (l.set(t.id, i), a.length > 0 && u.set(t.id, a), o.length > 0 && d.set(t.id, o), f.set(t.id, r), r);
1544
- }, g = [];
1545
- for (let e of c.get(null) ?? []) {
1546
- if (h(e, null).length === 0) continue;
1547
- let t = l.get(e.id);
1548
- t != null && g.push(t);
1549
- }
1550
- return g.length > 0 && u.set(null, g), p.forEach((e, t) => {
1551
- e.order = t;
1552
- }), {
1553
- parameters: o,
1554
- listed: p,
1555
- branches: l,
1556
- childBranches: u,
1557
- branchParameters: d,
1558
- subtreeParameterIds: f
1559
- };
1560
- }
1561
- function Vn(e, t) {
1562
- let n = [], r = (i, a) => {
1563
- for (let o of e.childBranches.get(i) ?? []) {
1564
- let i = t.has(o.id);
1565
- if (n.push({
1566
- kind: "branch",
1567
- key: `b:${o.id}`,
1568
- id: o.id,
1569
- name: o.name,
1570
- depth: a,
1571
- count: e.subtreeParameterIds.get(o.id)?.length ?? 0,
1572
- open: i
1573
- }), i) {
1574
- r(o.id, a + 1);
1575
- for (let t of e.branchParameters.get(o.id) ?? []) n.push({
1576
- kind: "parameter",
1577
- key: `p:${t.id}`,
1578
- parameter: t,
1579
- depth: a + 1
1580
- });
1581
- }
1582
- }
1583
- };
1584
- return r(null, 0), n;
1585
- }
1586
- function Hn(e, t) {
1587
- let n = e.parameters.get(t);
1588
- if (n == null) return [];
1589
- let r = [], i = n.branchId;
1590
- for (; i != null && !r.includes(i);) {
1591
- let t = e.branches.get(i);
1592
- if (t == null) break;
1593
- r.unshift(i), i = t.parentId;
1594
- }
1595
- return r;
1596
- }
1597
- function Un(e, t) {
1598
- return [t, ...(e.childBranches.get(t) ?? []).flatMap((t) => Un(e, t.id))];
1599
- }
1600
- function Wn(e, t, n) {
1601
- let r = je(t);
1602
- if (r.length === 0) return {
1603
- rows: [],
1604
- hidden: 0,
1605
- matchIds: []
1606
- };
1607
- let i = [];
1608
- for (let t of e.listed) ke(t.haystack, r) && i.push({
1609
- parameter: t,
1610
- preferred: n.preferred == null || n.preferred(t.id),
1611
- score: Ae(t.name, t.mnemonic, r)
1612
- });
1613
- i.sort((e, t) => Number(t.preferred) - Number(e.preferred) || t.score - e.score || (e.score > 0 ? e.parameter.name.length - t.parameter.name.length : 0) || e.parameter.order - t.parameter.order);
1614
- let a = i.slice(0, n.limit);
1615
- return {
1616
- rows: a.map(({ parameter: e }) => ({
1617
- kind: "parameter",
1618
- key: `p:${e.id}`,
1619
- parameter: e,
1620
- depth: 0
1621
- })),
1622
- hidden: i.length - a.length,
1623
- matchIds: i.map(({ parameter: e }) => e.id)
1624
- };
1625
- }
1626
- function Gn(e, t) {
1627
- if (t.length === 0 || e.length === 0) return [{
1628
- text: e,
1629
- match: !1
1630
- }];
1631
- let n = e.toLowerCase(), r = Array(e.length).fill(!1);
1632
- for (let e of t) {
1633
- let t = 0;
1634
- for (;;) {
1635
- let i = n.indexOf(e, t);
1636
- if (i < 0) break;
1637
- r.fill(!0, i, i + e.length), t = i + e.length;
1638
- }
1639
- }
1640
- let i = [], a = 0;
1641
- for (let t = 1; t <= e.length; t += 1) (t === e.length || r[t] !== r[a]) && (i.push({
1642
- text: e.slice(a, t),
1643
- match: r[a] === !0
1644
- }), a = t);
1645
- return i;
1646
- }
1647
- function Kn(e, t, n) {
1648
- let r = e.subtreeParameterIds.get(t) ?? [], i = !1, a = r.length > 0;
1649
- for (let e of r) n.has(e) ? i = !0 : a = !1;
1650
- return a ? !0 : i ? "indeterminate" : !1;
1651
- }
1652
- //#endregion
1653
- //#region src/workspace/parameters/picker/browser.tsx
1654
- var qn = 200, Jn = 8, Yn = [
1655
- "pl-1",
1656
- "pl-5",
1657
- "pl-9",
1658
- "pl-13",
1659
- "pl-17",
1660
- "pl-21",
1661
- "pl-25",
1662
- "pl-29",
1663
- "pl-33"
1664
- ];
1665
- function Xn(e) {
1666
- return Yn[Math.min(e, Yn.length - 1)] ?? "pl-33";
1667
- }
1668
- function Zn(e, t) {
1669
- if (t != null && e.parameters.has(t)) return new Set(Hn(e, t));
1670
- let n = /* @__PURE__ */ new Set(), r = e.childBranches.get(null) ?? [];
1671
- for (; r.length === 1;) {
1672
- let t = r[0];
1673
- if (t == null || (n.add(t.id), (e.branchParameters.get(t.id)?.length ?? 0) > 0)) break;
1674
- r = e.childBranches.get(t.id) ?? [];
1675
- }
1676
- return n;
1677
- }
1678
- function Qn({ text: e, tokens: t }) {
1679
- return Gn(e, t).map((e, t) => e.match ? /* @__PURE__ */ V("mark", {
1680
- className: "rounded-xs bg-primary/20 text-inherit",
1681
- children: e.text
1682
- }, t) : /* @__PURE__ */ V("span", { children: e.text }, t));
1683
- }
1684
- function $n({ path: e, tokens: t = [], className: n }) {
1685
- return /* @__PURE__ */ V("span", {
1686
- className: a("flex min-w-0 items-baseline text-xs text-muted-foreground", n),
1687
- title: e.join(" › "),
1688
- children: e.map((n, r) => /* @__PURE__ */ H("span", {
1689
- className: a("flex min-w-0 items-baseline", r === e.length - 1 ? "shrink" : "shrink-4"),
1690
- children: [r === 0 ? null : /* @__PURE__ */ V("span", {
1691
- className: "shrink-0 px-1",
1692
- "aria-hidden": !0,
1693
- children: "›"
1694
- }), /* @__PURE__ */ V("span", {
1695
- className: "min-w-0 truncate",
1696
- children: /* @__PURE__ */ V(Qn, {
1697
- text: n,
1698
- tokens: t
1699
- })
1700
- })]
1701
- }, r))
1702
- });
1703
- }
1704
- function er({ parameter: e, tokens: t }) {
1705
- let n = r();
1706
- return e.mnemonic == null && e.address == null && !e.disabled ? null : /* @__PURE__ */ H("span", {
1707
- className: "flex shrink-0 items-baseline gap-2 text-xs text-muted-foreground",
1708
- children: [
1709
- e.disabled ? /* @__PURE__ */ V("span", { children: n("parameter_picker_disabled") }) : null,
1710
- e.mnemonic == null ? null : /* @__PURE__ */ V("span", {
1711
- className: "max-w-32 truncate font-mono",
1712
- children: /* @__PURE__ */ V(Qn, {
1713
- text: e.mnemonic,
1714
- tokens: t
1715
- })
1716
- }),
1717
- e.address == null ? null : /* @__PURE__ */ V("span", {
1718
- className: "\n hidden max-w-28 truncate font-mono tabular-nums\n sm:inline\n ",
1719
- children: /* @__PURE__ */ V(Qn, {
1720
- text: e.address,
1721
- tokens: t
1722
- })
1723
- })
1724
- ]
1725
- });
1726
- }
1727
- function tr({ index: e, loading: t, selectedIds: n, multiple: i = !1, preferred: o, onPick: s, onToggle: c, emptyText: l, inputRef: u, className: d, footer: f }) {
1728
- let p = r(), m = he(), [h, g] = B(""), _ = n.values().next().value ?? null, [v, y] = B(null), x = R(() => v ?? Zn(e, i ? null : _), [
1729
- v,
1730
- e,
1731
- i,
1732
- _
1733
- ]), S = R(() => je(h), [h]), C = S.length > 0, w = R(() => C ? Wn(e, h, {
1734
- limit: qn,
1735
- preferred: o
1736
- }) : null, [
1737
- e,
1738
- o,
1739
- h,
1740
- C
1741
- ]), T = R(() => w?.rows ?? Vn(e, x), [
1742
- e,
1743
- x,
1744
- w
1745
- ]), [E, D] = B(null), O = R(() => {
1746
- let e = E == null ? -1 : T.findIndex((e) => e.key === E);
1747
- if (e >= 0) return e;
1748
- if (!C && _ != null) {
1749
- let e = T.findIndex((e) => e.key === `p:${_}`);
1750
- if (e >= 0) return e;
1751
- }
1752
- return T.length > 0 ? 0 : -1;
1753
- }, [
1754
- E,
1755
- T,
1756
- C,
1757
- _
1758
- ]), k = O >= 0 ? T[O] : void 0, j = z(null), M = (e) => `${m}-${e.key}`, ae = (e, t) => {
1759
- let n = j.current, r = n?.ownerDocument.getElementById(M(e));
1760
- if (n == null || r == null) return;
1761
- let i = r.offsetTop, a = i + r.offsetHeight;
1762
- t === "center" ? n.scrollTop = i - (n.clientHeight - r.offsetHeight) / 2 : i < n.scrollTop ? n.scrollTop = i : a > n.scrollTop + n.clientHeight && (n.scrollTop = a - n.clientHeight);
1763
- }, N = z(!1);
1764
- L(() => {
1765
- let e = j.current;
1766
- if (e == null || t || k == null) return;
1767
- let n = () => {
1768
- N.current || e.scrollHeight <= e.clientHeight || (N.current = !0, ae(k, "center"));
1769
- }, r = new ResizeObserver(n);
1770
- return r.observe(e), n(), () => {
1771
- r.disconnect();
1772
- };
1773
- });
1774
- let P = (e) => {
1775
- if (N.current = !0, T.length === 0) return;
1776
- let t = Math.max(0, Math.min(T.length - 1, e)), n = T[t];
1777
- n != null && (D(n.key), ae(n, "nearest"));
1778
- }, F = (t, n, r = !1) => {
1779
- N.current = !0, y(() => {
1780
- let i = new Set(x);
1781
- for (let a of r ? Un(e, t) : [t]) n ? i.add(a) : i.delete(a);
1782
- return i;
1783
- });
1784
- }, oe = (e) => {
1785
- i ? c?.([e], !n.has(e)) : s?.(e);
1786
- }, se = (t) => {
1787
- let r = e.subtreeParameterIds.get(t) ?? [];
1788
- c?.(r, Kn(e, t, n) !== !0);
1789
- }, ce = (e, t = !1) => {
1790
- D(e.key), e.kind === "branch" ? F(e.id, !e.open, t) : oe(e.parameter.id);
1791
- }, le = (t) => {
1792
- if (!t.nativeEvent.isComposing) switch (t.key) {
1793
- case "ArrowDown":
1794
- t.preventDefault(), P(O + 1);
1795
- return;
1796
- case "ArrowUp":
1797
- t.preventDefault(), P(O - 1);
1798
- return;
1799
- case "PageDown":
1800
- t.preventDefault(), P(O + Jn);
1801
- return;
1802
- case "PageUp":
1803
- t.preventDefault(), P(O - Jn);
1804
- return;
1805
- case "Enter":
1806
- if (k == null) return;
1807
- t.preventDefault(), ce(k, t.shiftKey);
1808
- return;
1809
- case " ":
1810
- if (!i || h.length > 0 || k == null) return;
1811
- t.preventDefault(), k.kind === "branch" ? se(k.id) : oe(k.parameter.id);
1812
- break;
1813
- case "ArrowRight":
1814
- if (C || k?.kind !== "branch") return;
1815
- t.preventDefault(), k.open ? P(O + 1) : F(k.id, !0);
1816
- return;
1817
- case "ArrowLeft": {
1818
- if (C || k == null) return;
1819
- if (t.preventDefault(), k.kind === "branch" && k.open) {
1820
- F(k.id, !1);
1821
- return;
1822
- }
1823
- let n = k.kind === "branch" ? e.branches.get(k.id)?.parentId ?? null : k.parameter.branchId;
1824
- n != null && P(T.findIndex((e) => e.key === `b:${n}`));
1825
- break;
1826
- }
1827
- }
1828
- }, ue = w != null && w.matchIds.length > 0 && w.matchIds.every((e) => n.has(e)), de;
1829
- return de = t ? /* @__PURE__ */ H("div", {
1830
- className: "space-y-2 p-2",
1831
- children: [
1832
- /* @__PURE__ */ V(A, { className: "h-7 w-full" }),
1833
- /* @__PURE__ */ V(A, { className: "h-7 w-4/5" }),
1834
- /* @__PURE__ */ V(A, { className: "h-7 w-3/5" })
1835
- ]
1836
- }) : e.listed.length === 0 ? /* @__PURE__ */ V("p", {
1837
- className: "px-3 py-6 text-center text-sm text-muted-foreground",
1838
- children: l ?? p("parameter_picker_none")
1839
- }) : T.length === 0 ? /* @__PURE__ */ V("p", {
1840
- className: "px-3 py-6 text-center text-sm text-muted-foreground",
1841
- children: p("parameter_picker_empty")
1842
- }) : /* @__PURE__ */ V("div", {
1843
- className: "flex flex-col",
1844
- children: T.map((t, r) => {
1845
- let o = r === O, s = {
1846
- id: M(t),
1847
- "data-active": o ? "" : void 0,
1848
- className: a("\n flex w-full shrink-0 cursor-default items-center gap-2 rounded-md pr-2 text-sm\n outline-none select-none\n data-active:bg-accent data-active:text-accent-foreground\n ", C ? "h-13 pl-2" : `
1849
- h-9
1850
- ${Xn(t.depth)}
1851
- `),
1852
- onPointerMove: () => {
1853
- o || D(t.key);
1854
- },
1855
- onPointerDown: (e) => {
1856
- e.preventDefault();
1857
- }
1858
- };
1859
- if (t.kind === "branch") {
1860
- let r = i ? Kn(e, t.id, n) : !1;
1861
- return /* @__PURE__ */ H("div", {
1862
- ...s,
1863
- role: "treeitem",
1864
- "aria-level": t.depth + 1,
1865
- "aria-expanded": t.open,
1866
- ...i ? { "aria-checked": r === "indeterminate" ? "mixed" : r } : {},
1867
- onClick: (e) => {
1868
- ce(t, e.shiftKey);
1869
- },
1870
- children: [
1871
- /* @__PURE__ */ V(xe, {
1872
- className: a("size-4 shrink-0 text-muted-foreground transition-transform", t.open && "rotate-90"),
1873
- "aria-hidden": !0
1874
- }),
1875
- i ? /* @__PURE__ */ V(b, {
1876
- tabIndex: -1,
1877
- "aria-hidden": !0,
1878
- checked: r === !0,
1879
- indeterminate: r === "indeterminate",
1880
- onClick: (e) => {
1881
- e.stopPropagation();
1882
- },
1883
- onCheckedChange: () => {
1884
- D(t.key), se(t.id);
1885
- }
1886
- }) : null,
1887
- /* @__PURE__ */ V("span", {
1888
- className: "min-w-0 truncate font-medium",
1889
- children: t.name
1890
- }),
1891
- /* @__PURE__ */ V("span", {
1892
- className: "shrink-0 text-xs text-muted-foreground tabular-nums",
1893
- children: t.count
1894
- })
1895
- ]
1896
- }, t.key);
1897
- }
1898
- let c = t.parameter, l = n.has(c.id);
1899
- return /* @__PURE__ */ H("div", {
1900
- ...s,
1901
- role: C ? "option" : "treeitem",
1902
- ...C ? {} : { "aria-level": t.depth + 1 },
1903
- ...i ? { "aria-checked": l } : { "aria-selected": l },
1904
- onClick: () => {
1905
- ce(t);
1906
- },
1907
- children: [
1908
- C ? null : /* @__PURE__ */ V("span", {
1909
- className: "size-4 shrink-0",
1910
- "aria-hidden": !0
1911
- }),
1912
- i ? /* @__PURE__ */ V(b, {
1913
- tabIndex: -1,
1914
- "aria-hidden": !0,
1915
- checked: l
1916
- }) : null,
1917
- C ? /* @__PURE__ */ H("span", {
1918
- className: "flex min-w-0 flex-1 flex-col",
1919
- children: [/* @__PURE__ */ H("span", {
1920
- className: "flex min-w-0 items-baseline gap-2",
1921
- children: [/* @__PURE__ */ V("span", {
1922
- className: "min-w-0 flex-1 truncate",
1923
- children: /* @__PURE__ */ V(Qn, {
1924
- text: c.name,
1925
- tokens: S
1926
- })
1927
- }), /* @__PURE__ */ V(er, {
1928
- parameter: c,
1929
- tokens: S
1930
- })]
1931
- }), /* @__PURE__ */ V($n, {
1932
- path: c.path,
1933
- tokens: S
1934
- })]
1935
- }) : /* @__PURE__ */ H(ye, { children: [/* @__PURE__ */ V("span", {
1936
- className: "min-w-0 flex-1 truncate",
1937
- children: c.name
1938
- }), /* @__PURE__ */ V(er, {
1939
- parameter: c,
1940
- tokens: S
1941
- })] }),
1942
- !i && l ? /* @__PURE__ */ V(be, {
1943
- className: "size-4 shrink-0 text-primary",
1944
- "aria-hidden": !0
1945
- }) : null
1946
- ]
1947
- }, t.key);
1948
- })
1949
- }), /* @__PURE__ */ H("div", {
1950
- className: a("flex min-h-0 flex-col gap-1", d),
1951
- children: [
1952
- /* @__PURE__ */ H(ne, { children: [
1953
- /* @__PURE__ */ V(re, { children: /* @__PURE__ */ V(Ce, { "aria-hidden": !0 }) }),
1954
- /* @__PURE__ */ V(ee, {
1955
- role: "combobox",
1956
- "aria-label": p("parameter_picker_placeholder"),
1957
- "aria-controls": m,
1958
- "aria-expanded": !0,
1959
- "aria-autocomplete": "list",
1960
- "aria-activedescendant": k == null ? void 0 : M(k),
1961
- placeholder: p("parameter_picker_placeholder"),
1962
- autoComplete: "off",
1963
- spellCheck: !1,
1964
- ...u == null ? {} : { ref: u },
1965
- value: h,
1966
- onChange: (e) => {
1967
- N.current = !0, g(e.target.value), D(null), j.current?.scrollTo({ top: 0 });
1968
- },
1969
- onKeyDown: le
1970
- }),
1971
- h.length > 0 ? /* @__PURE__ */ V(re, {
1972
- align: "inline-end",
1973
- children: /* @__PURE__ */ V(te, {
1974
- size: "icon-xs",
1975
- "aria-label": p("parameter_picker_clear_search"),
1976
- onClick: () => {
1977
- g(""), D(null);
1978
- },
1979
- children: /* @__PURE__ */ V(we, {})
1980
- })
1981
- }) : null
1982
- ] }),
1983
- i && w != null && w.matchIds.length > 0 ? /* @__PURE__ */ V(ie, {
1984
- type: "button",
1985
- variant: "ghost",
1986
- size: "sm",
1987
- className: "justify-start",
1988
- onClick: () => {
1989
- c?.(w.matchIds, !ue);
1990
- },
1991
- children: p(ue ? "parameter_picker_deselect_matches" : "parameter_picker_select_matches", { count: String(w.matchIds.length) })
1992
- }) : null,
1993
- /* @__PURE__ */ V("div", {
1994
- ref: j,
1995
- id: m,
1996
- role: C ? "listbox" : "tree",
1997
- "aria-label": p("parameter_picker_list"),
1998
- ...i ? { "aria-multiselectable": !0 } : {},
1999
- className: "relative min-h-0 flex-1 overflow-y-auto overscroll-contain",
2000
- children: de
2001
- }),
2002
- w != null && w.hidden > 0 ? /* @__PURE__ */ V("p", {
2003
- className: "px-2 text-xs text-muted-foreground",
2004
- children: p("parameter_picker_more", { count: String(w.hidden) })
2005
- }) : null,
2006
- f
2007
- ]
2008
- });
2009
- }
2010
- //#endregion
2011
- //#region src/workspace/parameters/picker/picker.tsx
2012
- function nr(t, r = {}) {
2013
- let { include: i, includeDisabled: a } = r, o = n(), s = e.parameter.listTree.useQuery({ workspaceId: t });
2014
- return {
2015
- index: R(() => Bn({
2016
- branches: s.data?.branches ?? [],
2017
- parameters: s.data?.parameters ?? [],
2018
- locale: o,
2019
- include: i,
2020
- includeDisabled: a
2021
- }), [
2022
- s.data,
2023
- o,
2024
- i,
2025
- a
2026
- ]),
2027
- loading: s.isPending,
2028
- parameters: s.data?.parameters
2029
- };
2030
- }
2031
- function rr({ parameterId: e, units: t }) {
2032
- let r = n(), i = mn(), [a, o] = B({ status: "loading" });
2033
- return L(() => {
2034
- let t = !0, n = () => {
2035
- i([e]).then((n) => {
2036
- if (!t) return;
2037
- let r = n.get(e);
2038
- o(r == null || N(r) ? P : r);
2039
- });
2040
- }, r = () => {
2041
- document.visibilityState === "visible" && (document.removeEventListener("visibilitychange", r), n());
2042
- };
2043
- return document.visibilityState === "visible" ? n() : document.addEventListener("visibilitychange", r), () => {
2044
- t = !1, document.removeEventListener("visibilitychange", r);
2045
- };
2046
- }, [e, i]), /* @__PURE__ */ V(Rt, {
2047
- state: a,
2048
- locale: r,
2049
- unit: t ?? "",
2050
- skeletonClassName: "h-4 w-12",
2051
- unavailable: /* @__PURE__ */ V("span", {
2052
- className: "text-xs font-normal text-muted-foreground",
2053
- children: "—"
2054
- })
2055
- });
2056
- }
2057
- function ir({ parameter: e }) {
2058
- return /* @__PURE__ */ H(ye, { children: [/* @__PURE__ */ H("span", {
2059
- className: "@container flex min-w-0 flex-1 flex-col",
2060
- children: [/* @__PURE__ */ H("span", {
2061
- className: "flex min-w-0 items-baseline gap-2",
2062
- children: [/* @__PURE__ */ V("span", {
2063
- className: "min-w-0 truncate",
2064
- children: e.name
2065
- }), e.mnemonic == null ? null : /* @__PURE__ */ V("span", {
2066
- className: "\n hidden max-w-24 shrink-0 truncate font-mono text-xs text-muted-foreground\n @xs:inline\n ",
2067
- children: e.mnemonic
2068
- })]
2069
- }), e.path.length === 0 ? null : /* @__PURE__ */ V($n, { path: e.path })]
2070
- }), /* @__PURE__ */ V("span", {
2071
- className: "max-w-[40%] shrink-0 text-sm font-medium",
2072
- children: /* @__PURE__ */ V(an, { children: /* @__PURE__ */ V(rr, {
2073
- parameterId: e.id,
2074
- units: e.units
2075
- }, e.id) })
2076
- })] });
2077
- }
2078
- function ar({ label: e, workspaceId: t, allowEmpty: n = !0, preferred: i, description: o, labelHidden: u = !1, labelSuffix: f, name: m, value: h, onChange: _, onBlur: v, invalid: b = !1, errors: ee = [] }) {
2079
- let S = r(), te = g(), [E, ne] = B(!1), { index: re, loading: k } = nr(t), A = he(), j = z(null), M = h === "" ? void 0 : re.parameters.get(h), ae = R(() => new Set(h === "" ? [] : [h]), [h]), N = (e) => {
2080
- ne(e), e || v?.();
2081
- }, P = /* @__PURE__ */ V("button", {
2082
- type: "button",
2083
- id: A,
2084
- ...m === void 0 ? {} : { name: m },
2085
- "aria-invalid": b || void 0,
2086
- className: a("\n flex min-h-11 w-full min-w-0 cursor-pointer items-center gap-2 rounded-lg border\n border-input bg-background py-1 pl-2.5 text-left text-sm shadow-xs transition-colors\n outline-none\n focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50\n disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50\n aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20\n dark:bg-input/20\n dark:hover:bg-input/40\n dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40\n ", n && h !== "" ? "pr-16" : "pr-9"),
2087
- children: h === "" ? /* @__PURE__ */ V("span", {
2088
- className: "flex-1 truncate text-muted-foreground",
2089
- children: S("parameter_picker_choose")
2090
- }) : M == null ? /* @__PURE__ */ V("span", {
2091
- className: "flex-1 truncate text-muted-foreground",
2092
- children: k ? "…" : S("parameter_picker_missing")
2093
- }) : /* @__PURE__ */ V(ir, { parameter: M })
2094
- }), F = /* @__PURE__ */ V(tr, {
2095
- index: re,
2096
- loading: k,
2097
- selectedIds: ae,
2098
- preferred: i,
2099
- inputRef: j,
2100
- className: "h-full",
2101
- onPick: (e) => {
2102
- _(e), N(!1);
2103
- }
2104
- });
2105
- return /* @__PURE__ */ H(p, {
2106
- "data-invalid": b ? !0 : void 0,
2107
- children: [
2108
- /* @__PURE__ */ H(d, {
2109
- htmlFor: A,
2110
- className: u ? "sr-only" : void 0,
2111
- children: [e, f]
2112
- }),
2113
- /* @__PURE__ */ H("div", {
2114
- className: "relative min-w-0",
2115
- children: [
2116
- te ? /* @__PURE__ */ H(x, {
2117
- open: E,
2118
- onOpenChange: N,
2119
- children: [/* @__PURE__ */ V(c, { render: P }), /* @__PURE__ */ H(D, {
2120
- className: "h-[85dvh]",
2121
- initialFocus: j,
2122
- children: [/* @__PURE__ */ V(y, {
2123
- className: "pb-2",
2124
- children: /* @__PURE__ */ V(l, { children: e })
2125
- }), /* @__PURE__ */ V("div", {
2126
- className: "min-h-0 flex-1 px-3 pb-3",
2127
- children: F
2128
- })]
2129
- })]
2130
- }) : /* @__PURE__ */ H(C, {
2131
- open: E,
2132
- onOpenChange: N,
2133
- children: [/* @__PURE__ */ V(T, { render: P }), /* @__PURE__ */ V(w, {
2134
- align: "start",
2135
- "aria-label": e,
2136
- initialFocus: j,
2137
- className: "\n h-[min(28rem,var(--available-height))] w-[min(36rem,calc(100vw-2rem))]\n min-w-(--anchor-width) p-1.5\n ",
2138
- children: F
2139
- })]
2140
- }),
2141
- n && h !== "" ? /* @__PURE__ */ V(ie, {
2142
- type: "button",
2143
- variant: "ghost",
2144
- size: "icon-xs",
2145
- className: "absolute top-1/2 right-8 -translate-y-1/2 text-muted-foreground",
2146
- "aria-label": S("ui_clear_selection"),
2147
- onClick: () => {
2148
- _(""), v?.();
2149
- },
2150
- children: /* @__PURE__ */ V(we, {})
2151
- }) : null,
2152
- /* @__PURE__ */ V(Se, {
2153
- className: "\n pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2\n text-muted-foreground\n ",
2154
- "aria-hidden": !0
2155
- })
2156
- ]
2157
- }),
2158
- o != null && /* @__PURE__ */ V(O, { children: o }),
2159
- /* @__PURE__ */ V(s, { errors: [...ee] })
2160
- ]
2161
- });
2162
- }
2163
- //#endregion
2164
- //#region src/form/fields/parameter-picker-field.tsx
2165
- function or(e) {
2166
- let t = K();
2167
- return /* @__PURE__ */ V(ar, {
2168
- ...e,
2169
- name: t.name,
2170
- value: t.state.value,
2171
- onChange: t.handleChange,
2172
- onBlur: t.handleBlur,
2173
- invalid: !t.state.meta.isValid,
2174
- errors: Y(t.state.meta.errors, t.name)
2175
- });
2176
- }
2177
- //#endregion
2178
- //#region src/form/fields/textarea-field.tsx
2179
- function sr({ label: e, id: t, ...r }) {
2180
- n();
2181
- let i = K(), a = t ?? i.name, o = !i.state.meta.isValid, c = Y(i.state.meta.errors, i.name);
2182
- return /* @__PURE__ */ H(p, {
2183
- "data-invalid": o ? !0 : void 0,
2184
- children: [
2185
- /* @__PURE__ */ V(d, {
2186
- htmlFor: a,
2187
- children: e
2188
- }),
2189
- /* @__PURE__ */ V(k, {
2190
- id: a,
2191
- name: i.name,
2192
- value: i.state.value,
2193
- onBlur: i.handleBlur,
2194
- onChange: (e) => {
2195
- i.handleChange(e.target.value);
2196
- },
2197
- "aria-invalid": o || void 0,
2198
- ...r
2199
- }),
2200
- /* @__PURE__ */ V(s, { errors: c })
2201
- ]
2202
- });
2203
- }
2204
- //#endregion
2205
- //#region src/form/fields/text-field.tsx
2206
- function cr({ label: e, hideLabel: t = !1, id: r, description: i, ...a }) {
2207
- n();
2208
- let o = K(), c = r ?? o.name, l = !o.state.meta.isValid, u = Y(o.state.meta.errors, o.name);
2209
- return /* @__PURE__ */ H(p, {
2210
- "data-invalid": l ? !0 : void 0,
2211
- children: [
2212
- /* @__PURE__ */ V(d, {
2213
- htmlFor: c,
2214
- className: t ? "sr-only" : void 0,
2215
- children: e
2216
- }),
2217
- /* @__PURE__ */ V(S, {
2218
- id: c,
2219
- name: o.name,
2220
- value: o.state.value,
2221
- onBlur: o.handleBlur,
2222
- onChange: (e) => {
2223
- o.handleChange(e.target.value);
2224
- },
2225
- "aria-invalid": l || void 0,
2226
- ...a
2227
- }),
2228
- i == null ? null : /* @__PURE__ */ V(O, { children: i }),
2229
- /* @__PURE__ */ V(s, { errors: u })
2230
- ]
2231
- });
2232
- }
2233
- //#endregion
2234
- //#region src/form/form-error-banner.tsx
2235
- function lr(e) {
2236
- if (e instanceof q) return e.read();
2237
- if (typeof e == "string") return e;
2238
- if (typeof e != "object" || !e || !("form" in e)) return null;
2239
- let t = e.form;
2240
- return t instanceof q ? t.read() : typeof t == "string" ? t : null;
2241
- }
2242
- function ur({ className: e }) {
2243
- return n(), /* @__PURE__ */ V(tt().Subscribe, {
2244
- selector: (e) => e.errorMap.onSubmit,
2245
- children: (t) => {
2246
- let n = lr(t);
2247
- return n == null ? null : /* @__PURE__ */ V(s, {
2248
- className: e,
2249
- children: n
2250
- });
2251
- }
2252
- });
2253
- }
2254
- //#endregion
2255
- //#region src/form/focus-first-invalid-field.ts
2256
- var dr = "foldable:open";
2257
- function fr() {
2258
- if (typeof document > "u") return;
2259
- let e = document.querySelector("[aria-invalid=\"true\"]");
2260
- if (e == null) return;
2261
- let t = e;
2262
- for (; t != null;) t.hasAttribute("data-foldable-card") && t.dispatchEvent(new Event(dr)), t = t.parentElement;
2263
- requestAnimationFrame(() => {
2264
- requestAnimationFrame(() => {
2265
- e.focus();
2266
- });
2267
- });
2268
- }
2269
- //#endregion
2270
- //#region src/form/form-root.tsx
2271
- function pr(e) {
2272
- if (typeof document > "u") return;
2273
- let t = document.activeElement;
2274
- !(t instanceof HTMLElement) || !e.contains(t) || t.blur();
2275
- }
2276
- function mr({ children: e, className: t, layout: n, banner: r = !0 }) {
2277
- let i = tt();
2278
- function o(e) {
2279
- e.preventDefault(), e.stopPropagation(), pr(e.currentTarget);
2280
- for (let t of e.currentTarget.elements) if (t instanceof HTMLInputElement && t.validity.customError) {
2281
- t.reportValidity(), fr();
2282
- return;
2283
- }
2284
- i.setErrorMap({ onSubmit: { fields: {} } }), i.handleSubmit();
2285
- }
2286
- return /* @__PURE__ */ H("form", {
2287
- onSubmit: o,
2288
- noValidate: !0,
2289
- className: a(n === "dialog" && "contents", n === "dialog-fill" && "flex min-h-0 flex-1 flex-col overflow-hidden", t),
2290
- children: [n === "dialog-fill" || !r ? null : /* @__PURE__ */ V(ur, { ...n === "dialog" ? { className: "order-1" } : {} }), e]
2291
- });
2292
- }
2293
- //#endregion
2294
- //#region src/form/submit-button.tsx
2295
- function hr({ label: e, pendingLabel: t, className: n, variant: r, size: i, disabled: a = !1 }) {
2296
- return /* @__PURE__ */ V(tt().Subscribe, {
2297
- selector: (e) => e.isSubmitting,
2298
- children: (o) => /* @__PURE__ */ V(ie, {
2299
- type: "submit",
2300
- disabled: a || o,
2301
- className: n,
2302
- variant: r,
2303
- size: i,
2304
- children: o ? t ?? e : e
2305
- })
2306
- });
2307
- }
2308
- //#endregion
2309
- //#region src/form/use-app-form.ts
2310
- var { useAppForm: gr, withForm: _r, withFieldGroup: vr } = _e({
2311
- fieldContext: $e,
2312
- formContext: et,
2313
- fieldComponents: {
2314
- TextField: cr,
2315
- TextAreaField: sr,
2316
- OtpField: ut,
2317
- CheckboxField: lt,
2318
- ParameterPickerField: or,
2319
- DashboardPickerField: dt,
2320
- FormulaField: Mt
2321
- },
2322
- formComponents: {
2323
- FormRoot: mr,
2324
- FormErrorBanner: ur,
2325
- SubmitButton: hr
2326
- }
2327
- });
2328
- //#endregion
2329
- //#region src/form/map-trpc-to-form-errors.ts
2330
- function yr(e) {
2331
- return {
2332
- form: e,
2333
- fields: {}
2334
- };
2335
- }
2336
- function br(e, t) {
2337
- return { fields: { [e.field]: () => t(e) } };
2338
- }
2339
- function xr(e) {
2340
- return typeof e != "object" || !e || Array.isArray(e) ? /* @__PURE__ */ new Set() : new Set(Object.keys(e));
2341
- }
2342
- function Sr(e, t, n) {
2343
- if (e.length === 0) return null;
2344
- let r = e.join("."), i = null, a = -1;
2345
- for (let [e, o] of Object.entries(n ?? {})) (r === e || r.startsWith(`${e}.`)) && e.length > a && t.has(o) && (i = o, a = e.length);
2346
- if (i != null) return i;
2347
- let o = e[0];
2348
- if (o != null && t.has(o)) return o;
2349
- let s = e[e.length - 1];
2350
- return s != null && t.has(s) ? s : null;
2351
- }
2352
- function Cr(e, n, r) {
2353
- let i = {}, a = !1;
2354
- for (let o of e) {
2355
- let e = Sr(o.path, n, r);
2356
- e == null ? a = !0 : i[e] ??= Y([o], e)[0]?.message ?? t("error_field_invalid");
2357
- }
2358
- return a || Object.keys(i).length === 0 ? {
2359
- fields: i,
2360
- form: t("error_input_invalid")
2361
- } : { fields: i };
2362
- }
2363
- function wr(e, t, n = {}) {
2364
- let r = ue(e), i = xr(t);
2365
- if (r.message === Ee) return Cr(r.issues ?? [], i, n.fieldMap);
2366
- let a = n.message?.(e) ?? le(e), o = r.details?.field, s = typeof o == "string" ? Sr(o.split("."), i, n.fieldMap) : null;
2367
- if (s == null) {
2368
- let t = de(e) ?? r.message, a = t == null ? void 0 : n.codeFields?.[t];
2369
- s = a != null && i.has(a) ? a : null;
2370
- }
2371
- return s == null ? yr(a) : { fields: { [s]: a } };
2372
- }
2373
- //#endregion
2374
- //#region src/form/mutation-form-validators.ts
2375
- function Tr(e, t = () => e) {
2376
- let n = e.form;
2377
- return {
2378
- ...n === void 0 ? {} : { form: new q(() => {
2379
- let e = t().form ?? n;
2380
- return typeof e == "function" ? e() : e;
2381
- }) },
2382
- fields: Object.fromEntries(Object.entries(e.fields).map(([e, n]) => [e, new q(() => {
2383
- let r = t().fields[e] ?? n;
2384
- return typeof r == "function" ? r() : r;
2385
- })]))
2386
- };
2387
- }
2388
- function Er(e) {
2389
- return {
2390
- ...e.schema === void 0 ? {} : { onSubmit: e.schema },
2391
- onSubmitAsync: async ({ value: t }) => {
2392
- try {
2393
- let n = await e.submit(t);
2394
- return n == null ? null : (queueMicrotask(() => {
2395
- fr();
2396
- }), Tr(n));
2397
- } catch (n) {
2398
- e.onError?.(n), queueMicrotask(() => {
2399
- fr();
2400
- });
2401
- let r = e.mapError ?? wr;
2402
- return Tr(r(n, t), () => r(n, t));
2403
- }
2404
- }
2405
- };
2406
- }
2407
- //#endregion
2408
- export { jt as $, Tn as A, un as B, jn as C, vn as D, yn as E, En as F, Rt as G, dn as H, xn as I, Ft as J, Lt as K, rn as L, _n as M, Cn as N, wn as O, Sn as P, Mt as Q, fn as R, In as S, On as T, mn as U, hn as V, zt as W, Pt as X, Q as Y, Nt as Z, nr as _, gr as a, Y as at, Mn as b, hr as c, fr as d, Et as et, ur as f, ar as g, or as h, wr as i, lt as it, gn as j, bn as k, mr as l, sr as m, br as n, dt as nt, vr as o, K as ot, cr as p, It as q, yr as r, ut as rt, _r as s, tt as st, Er as t, Dt as tt, dr as u, tr as v, Ln as w, Pn as x, Fn as y, pn as z };