@parallelworks/ui 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/assets/editor.worker-CuBRIwi-.js +14776 -0
  2. package/dist/assets/json.worker-8ytS02vz.js +22161 -0
  3. package/dist/assets/yaml.worker-DJC-VUcv.js +48367 -0
  4. package/dist/chunks/CodePreviewEditor-CSPRILMp.js +61 -0
  5. package/dist/chunks/Indicator-hBSIxOPK.js +39 -0
  6. package/dist/chunks/Loader-DQiZ75fa.js +25 -0
  7. package/dist/chunks/Markdown-C5Re2ezs.js +101 -0
  8. package/dist/chunks/MarkdownImpl-Bq4QhrtA.js +33 -0
  9. package/dist/chunks/Modal-sOUEwebV.js +121 -0
  10. package/dist/chunks/Monaco-CC4ak1JG.js +717 -0
  11. package/dist/chunks/Provider-DvVvScTQ.js +391 -0
  12. package/dist/chunks/StatusBadge-DXp4zkSd.js +46 -0
  13. package/dist/chunks/SwitchToggle-2uRw8ZeJ.js +725 -0
  14. package/dist/chunks/SwitchToggleSmall-FcsaYSTs.js +14 -0
  15. package/dist/chunks/Table-C5z6qWjM.js +91 -0
  16. package/dist/chunks/Tooltip-WgbiC_nd.js +71 -0
  17. package/dist/chunks/editor-D55tumuZ.js +372 -0
  18. package/dist/chunks/lib-DTgL8klR.js +191 -0
  19. package/dist/chunks/list-7PyDF1tz.js +465 -0
  20. package/dist/components/CollapsiblePanel.d.ts +27 -0
  21. package/dist/components/CopyToClipboard.d.ts +17 -0
  22. package/dist/components/Dropdown.d.ts +24 -0
  23. package/dist/components/Indicator.d.ts +4 -0
  24. package/dist/components/Listbox.d.ts +18 -0
  25. package/dist/components/Markdown.d.ts +7 -0
  26. package/dist/components/MarkdownImpl.d.ts +2 -0
  27. package/dist/components/MultiSelect.d.ts +19 -0
  28. package/dist/components/Overview.d.ts +12 -0
  29. package/dist/components/Provider.d.ts +438 -0
  30. package/dist/components/SectionHeader.d.ts +6 -0
  31. package/dist/components/SwitchToggle.d.ts +12 -0
  32. package/dist/components/SwitchToggleSmall.d.ts +6 -0
  33. package/dist/components/dropdownUtils.d.ts +18 -0
  34. package/dist/editor/Editor.d.ts +2 -0
  35. package/dist/editor/EditorField.d.ts +11 -0
  36. package/dist/editor/FormCodePanel.d.ts +8 -0
  37. package/dist/editor/Monaco.d.ts +31 -0
  38. package/dist/editor/index.d.ts +7 -0
  39. package/dist/editor/index.js +2 -0
  40. package/dist/editor/themes.d.ts +4 -0
  41. package/dist/editor/useCssIsDark.d.ts +6 -0
  42. package/dist/editor/workers.d.ts +6 -0
  43. package/dist/file-explorer/FileExplorer.d.ts +23 -0
  44. package/dist/file-explorer/FileExplorerContext.d.ts +17 -0
  45. package/dist/file-explorer/FilePreview/CodePreviewEditor.d.ts +6 -0
  46. package/dist/file-explorer/FilePreview/Inline.d.ts +13 -0
  47. package/dist/file-explorer/FilePreview/StreamedBadge.d.ts +1 -0
  48. package/dist/file-explorer/FilePreview/Viewer.d.ts +15 -0
  49. package/dist/file-explorer/FilePreview/index.d.ts +15 -0
  50. package/dist/file-explorer/FilePreview/parse.d.ts +24 -0
  51. package/dist/file-explorer/FilePreview/previewCache.d.ts +26 -0
  52. package/dist/file-explorer/FilePreview/previewType.d.ts +21 -0
  53. package/dist/file-explorer/FilePreview/readCappedBytes.d.ts +37 -0
  54. package/dist/file-explorer/FilePreview/useObjectBlobUrl.d.ts +16 -0
  55. package/dist/file-explorer/FilePreview/useObjectText.d.ts +23 -0
  56. package/dist/file-explorer/FilePreview/usePresignedUrl.d.ts +12 -0
  57. package/dist/file-explorer/FileRow.d.ts +35 -0
  58. package/dist/file-explorer/FileRowsWindow.d.ts +43 -0
  59. package/dist/file-explorer/FileTable.d.ts +26 -0
  60. package/dist/file-explorer/FileTableHeaders.d.ts +13 -0
  61. package/dist/file-explorer/LoadMoreRow.d.ts +15 -0
  62. package/dist/file-explorer/TreeView.d.ts +28 -0
  63. package/dist/file-explorer/helpers.d.ts +47 -0
  64. package/dist/file-explorer/index.d.ts +10 -0
  65. package/dist/file-explorer/index.js +5646 -0
  66. package/dist/file-explorer/lib/batch.d.ts +3 -0
  67. package/dist/file-explorer/lib/errors.d.ts +3 -0
  68. package/dist/file-explorer/lib/fileExplorer.d.ts +32 -0
  69. package/dist/file-explorer/lib/paging.d.ts +93 -0
  70. package/dist/file-explorer/lib/types.d.ts +92 -0
  71. package/dist/file-explorer/lib/utils.d.ts +37 -0
  72. package/dist/file-explorer/toasts.d.ts +9 -0
  73. package/dist/file-explorer/treeRows.d.ts +35 -0
  74. package/dist/file-explorer/useNearEnd.d.ts +7 -0
  75. package/dist/form/FieldWrapper.d.ts +10 -0
  76. package/dist/form/Fields/BooleanField.d.ts +12 -0
  77. package/dist/form/Fields/BucketReadOnlyField.d.ts +7 -0
  78. package/dist/form/Fields/CheckboxGroupField.d.ts +18 -0
  79. package/dist/form/Fields/ColorField.d.ts +8 -0
  80. package/dist/form/Fields/DropdownField.d.ts +24 -0
  81. package/dist/form/Fields/DurationField.d.ts +13 -0
  82. package/dist/form/Fields/LabelField.d.ts +9 -0
  83. package/dist/form/Fields/MultiDropdownField.d.ts +18 -0
  84. package/dist/form/Fields/NumberField.d.ts +13 -0
  85. package/dist/form/Fields/ObjectField.d.ts +8 -0
  86. package/dist/form/Fields/RadioField.d.ts +9 -0
  87. package/dist/form/Fields/RangeField.d.ts +11 -0
  88. package/dist/form/Fields/ResourceOptionIcon.d.ts +11 -0
  89. package/dist/form/Fields/StepField.d.ts +3 -0
  90. package/dist/form/Fields/StringField.d.ts +17 -0
  91. package/dist/form/Fields/TextAreaField.d.ts +8 -0
  92. package/dist/form/Fields/durationValidity.d.ts +2 -0
  93. package/dist/form/Form.d.ts +105 -0
  94. package/dist/form/SpecialTypes/DropdownWrapper.d.ts +14 -0
  95. package/dist/form/SpecialTypes/FormikCustomDropdown.d.ts +53 -0
  96. package/dist/form/SpecialTypes/FormikCustomInput.d.ts +17 -0
  97. package/dist/form/SpecialTypes/FormikMultiSelectDropdown.d.ts +13 -0
  98. package/dist/form/SpecialTypes/FormikNumericInput.d.ts +9 -0
  99. package/dist/form/SpecialTypes/index.d.ts +3 -0
  100. package/dist/form/Wizard/WizardContainer.d.ts +5 -0
  101. package/dist/form/Wizard/WizardNavigation.d.ts +2 -0
  102. package/dist/form/Wizard/WizardStepContent.d.ts +8 -0
  103. package/dist/form/Wizard/WizardStepIndicator.d.ts +2 -0
  104. package/dist/form/Wizard/types.d.ts +171 -0
  105. package/dist/form/Wizard/useWizardState.d.ts +28 -0
  106. package/dist/form/Wizard/utils.d.ts +2 -0
  107. package/dist/form/fieldRegistry.d.ts +7 -0
  108. package/dist/form/index.d.ts +16 -0
  109. package/dist/form/index.js +2319 -0
  110. package/dist/form/lib.d.ts +15 -0
  111. package/dist/form/types/fieldComponentTypes.d.ts +32 -0
  112. package/dist/form/types/fieldTypes.d.ts +80 -0
  113. package/dist/form/types/workflow-schema.d.ts +1107 -0
  114. package/dist/form/useParsedOpts.d.ts +5 -0
  115. package/dist/form/usePrevious.d.ts +1 -0
  116. package/dist/form/utils/checkShowIfObject.d.ts +1 -0
  117. package/dist/form/utils/getParentValue.d.ts +1 -0
  118. package/dist/form/utils/getPlaceholder.d.ts +2 -0
  119. package/dist/form/utils/getValueUsingPath.d.ts +1 -0
  120. package/dist/form/utils/pwResolver.d.ts +18 -0
  121. package/dist/form/utils/secondaryField.d.ts +8 -0
  122. package/dist/form/utils/slurmDuration.d.ts +15 -0
  123. package/dist/icons.d.ts +1 -1
  124. package/dist/icons.js +2 -2
  125. package/dist/index.d.ts +17 -0
  126. package/dist/index.js +42 -350
  127. package/dist/list/ListTable.d.ts +63 -0
  128. package/dist/list/RowContextMenu.d.ts +113 -0
  129. package/dist/list/index.d.ts +2 -0
  130. package/dist/list/index.js +2 -0
  131. package/dist/logviewer/LogViewer.d.ts +18 -0
  132. package/dist/logviewer/index.d.ts +1 -0
  133. package/dist/logviewer/index.js +534 -0
  134. package/dist/logviewer/logviewer.css +70 -0
  135. package/dist/styles/theme.css +30 -0
  136. package/dist/styles.css +1 -1
  137. package/dist/workflow/AnnotationBanner.d.ts +5 -0
  138. package/dist/workflow/Collapse.d.ts +6 -0
  139. package/dist/workflow/DependencyGraph.d.ts +15 -0
  140. package/dist/workflow/JobSummary.d.ts +38 -0
  141. package/dist/workflow/MatrixGroup.d.ts +41 -0
  142. package/dist/workflow/Reveal.d.ts +7 -0
  143. package/dist/workflow/TreeView.d.ts +42 -0
  144. package/dist/workflow/index.d.ts +1 -0
  145. package/dist/workflow/index.js +2331 -0
  146. package/package.json +71 -6
@@ -0,0 +1,2319 @@
1
+ import { AngleRightIcon, EyeIcon, EyeOffIcon, SuccessCheckmark, TrashIcon } from "../icons.js";
2
+ import { c as useStrings, s as useSlots } from "../chunks/Provider-DvVvScTQ.js";
3
+ import { n as TOOLTIP_ID, r as TooltipInfo } from "../chunks/Tooltip-WgbiC_nd.js";
4
+ import { a as UncontrolledCollapsiblePanel, c as Dropdown, f as isCategory, n as SectionHeader, o as MultiSelectDropdown, r as ControlledCollapsiblePanel, s as CustomListbox, t as SwitchToggle } from "../chunks/SwitchToggle-2uRw8ZeJ.js";
5
+ import { t as Loader } from "../chunks/Loader-DQiZ75fa.js";
6
+ import { n as StatusDot } from "../chunks/StatusBadge-DXp4zkSd.js";
7
+ import { n as Table } from "../chunks/Table-C5z6qWjM.js";
8
+ import { a as resolvedFlag, c as FieldWrapper, i as initializeValues, n as flattenGroups, o as applySecondaryField, r as impureSetValueFromPath, s as findSecondaryOption, t as enforceOneMustBeTrue } from "../chunks/lib-DTgL8klR.js";
9
+ import cx from "classnames";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ import React, { Suspense, createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
12
+ import deepEqual from "fast-deep-equal";
13
+ import { callWhenParserInitialized, convertToDynamicForm, extractInputDeps, initializeParseStringsOfObj, parseStringsOfObj, parseStringsOfObjReady } from "@parallelworks/workflow-parser";
14
+ import { Duration } from "luxon";
15
+ import { Field, Form, Formik, getIn, useField, useFormikContext } from "formik";
16
+ import { NumericFormat } from "react-number-format";
17
+ //#region src/form/utils/getValueUsingPath.ts
18
+ function getValueUsingPath(obj, path) {
19
+ if (typeof path !== "string" || !path) return;
20
+ const keys = path.split(".");
21
+ let current = obj;
22
+ for (const key of keys) {
23
+ if (!current || typeof current !== "object") return;
24
+ if (key.includes("[")) {
25
+ const [arrayKey, indexStr] = key.split("[");
26
+ const index = parseInt(indexStr.slice(0, -1), 10);
27
+ if (!Array.isArray(current[arrayKey]) || isNaN(index)) return;
28
+ current = current[arrayKey][index];
29
+ } else {
30
+ if (!(key in current)) return;
31
+ current = current[key];
32
+ }
33
+ }
34
+ return current;
35
+ }
36
+ //#endregion
37
+ //#region src/form/utils/checkShowIfObject.ts
38
+ function checkShowIfObject(showIfObject, formValues, index) {
39
+ const valueList = [];
40
+ for (let [key, value] of Object.entries(showIfObject)) {
41
+ if (index !== void 0) key = key.replace("[index]", `[${index}]`);
42
+ const dependsOnValue = getValueUsingPath(formValues, key);
43
+ if (typeof value === "boolean" || typeof value === "string" || typeof value === "number") valueList.push(dependsOnValue?.toString() === value.toString());
44
+ else if (Array.isArray(value)) valueList.push(value.includes(dependsOnValue));
45
+ }
46
+ return valueList;
47
+ }
48
+ //#endregion
49
+ //#region src/form/utils/getParentValue.ts
50
+ function getParentValue(index, targetField, values, dependentPath, field) {
51
+ let parentValue;
52
+ if (typeof targetField === "object" && !Array.isArray(targetField)) parentValue = !checkShowIfObject(targetField, values, index).includes(false);
53
+ else if (field.depends_on) {
54
+ dependentPath = field.depends_on;
55
+ if (index !== void 0) dependentPath = field.depends_on.replace("[index]", `[${index}]`);
56
+ const dependsOnValue = getValueUsingPath(values, dependentPath);
57
+ parentValue = targetField.includes(dependsOnValue) || targetField.includes(dependsOnValue?.toString());
58
+ } else {
59
+ dependentPath = targetField;
60
+ if (index !== void 0) dependentPath = targetField.replace("[index]", `[${index}]`);
61
+ parentValue = getValueUsingPath(values, dependentPath);
62
+ }
63
+ return parentValue;
64
+ }
65
+ //#endregion
66
+ //#region src/form/useParsedOpts.ts
67
+ var EMPTY_VARS = {};
68
+ var EMPTY_KEYS = [];
69
+ /**
70
+ * useMemo won't work here — Formik values changes on every keystroke, so this hook extracts which inputs.* keys the schema references and re-parses only when those change. Defaults `userVars`/`secretKeys` to empty — callers in React scope should pass them from `useUserVars()` so the parser leaves `${{ var.SECRET }}` literal during template eval (otherwise the recursive substitution turns `"https://${{ var.PAT }}@host/"` into `"https://@host/"`).
71
+ */
72
+ function useParsedOpts(rawOptions, values, organizationVariables, userVars = EMPTY_VARS, secretKeys = EMPTY_KEYS) {
73
+ const c = useRef({
74
+ rawOptions: null,
75
+ orgVars: void 0,
76
+ userVars: null,
77
+ secretKeys: null,
78
+ converted: null,
79
+ inputDeps: /* @__PURE__ */ new Set(),
80
+ hasExpressions: false,
81
+ relevantSnapshot: {},
82
+ result: null
83
+ }).current;
84
+ if (rawOptions !== c.rawOptions) {
85
+ c.rawOptions = rawOptions;
86
+ c.converted = convertToDynamicForm(rawOptions);
87
+ const { inputDeps, hasExpressions } = extractInputDeps(c.converted);
88
+ c.inputDeps = inputDeps;
89
+ c.hasExpressions = hasExpressions;
90
+ c.result = null;
91
+ }
92
+ if (organizationVariables !== c.orgVars) {
93
+ c.orgVars = organizationVariables;
94
+ c.result = null;
95
+ }
96
+ if (userVars !== c.userVars || secretKeys !== c.secretKeys) {
97
+ c.userVars = userVars;
98
+ c.secretKeys = secretKeys;
99
+ c.result = null;
100
+ }
101
+ if (c.result !== null) {
102
+ if (c.inputDeps.size === 0) return c.result;
103
+ let inputsChanged = false;
104
+ for (const key of c.inputDeps) if (!deepEqual(values[key], c.relevantSnapshot[key])) {
105
+ inputsChanged = true;
106
+ break;
107
+ }
108
+ if (!inputsChanged) return c.result;
109
+ }
110
+ c.result = parseStringsOfObj({
111
+ inputs: values,
112
+ obj: c.converted,
113
+ orgVars: organizationVariables,
114
+ userVars,
115
+ secretKeys
116
+ });
117
+ c.relevantSnapshot = {};
118
+ for (const key of c.inputDeps) c.relevantSnapshot[key] = values[key];
119
+ return c.result;
120
+ }
121
+ //#endregion
122
+ //#region src/form/usePrevious.ts
123
+ function usePrevious(value) {
124
+ const ref = useRef(void 0);
125
+ useEffect(() => {
126
+ ref.current = value;
127
+ });
128
+ return ref.current;
129
+ }
130
+ //#endregion
131
+ //#region src/form/Wizard/WizardNavigation.tsx
132
+ function WizardNavigation({ currentStep, stepOrder, canGoToNext, canGoBack, isCurrentStepValid, nextLabel, prevLabel, submitLabel = "Submit", onNext, onPrevious, onSubmit }) {
133
+ const [isLoading, setIsLoading] = useState(false);
134
+ const [error, setError] = useState(null);
135
+ const isLastStep = stepOrder.indexOf(currentStep) === stepOrder.length - 1;
136
+ const handleNext = async () => {
137
+ setIsLoading(true);
138
+ setError(null);
139
+ try {
140
+ if (!await onNext()) setError("Please fix errors before proceeding");
141
+ } catch (err) {
142
+ setError(err instanceof Error ? err.message : "An error occurred");
143
+ } finally {
144
+ setIsLoading(false);
145
+ }
146
+ };
147
+ const handleSubmit = async () => {
148
+ setIsLoading(true);
149
+ setError(null);
150
+ try {
151
+ await onSubmit();
152
+ } catch (err) {
153
+ setError(err instanceof Error ? err.message : "An error occurred");
154
+ } finally {
155
+ setIsLoading(false);
156
+ }
157
+ };
158
+ return /* @__PURE__ */ jsxs("div", { children: [error && /* @__PURE__ */ jsx("div", {
159
+ className: "mb-4 p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700",
160
+ children: error
161
+ }), /* @__PURE__ */ jsxs("div", {
162
+ className: "flex gap-3 justify-between pt-4",
163
+ children: [/* @__PURE__ */ jsx("button", {
164
+ type: "button",
165
+ onClick: onPrevious,
166
+ disabled: !canGoBack || isLoading,
167
+ className: "px-6 py-3 rounded-lg font-medium transition-all duration-200 border flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",
168
+ style: {
169
+ color: "var(--theme-app)",
170
+ borderColor: "var(--theme-border)",
171
+ backgroundColor: "var(--theme-app-bg)"
172
+ },
173
+ onMouseEnter: (e) => {
174
+ if (!(!canGoBack || isLoading)) e.currentTarget.style.backgroundColor = "var(--theme-hover)";
175
+ },
176
+ onMouseLeave: (e) => {
177
+ e.currentTarget.style.backgroundColor = "var(--theme-app-bg)";
178
+ },
179
+ "aria-label": "Go to previous step",
180
+ children: prevLabel || "← Previous"
181
+ }), isLastStep ? /* @__PURE__ */ jsxs("button", {
182
+ type: "button",
183
+ onClick: handleSubmit,
184
+ disabled: !isCurrentStepValid || isLoading,
185
+ className: "px-8 py-3 rounded-lg font-medium transition-all duration-200 text-white flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed shadow-md hover:shadow-lg",
186
+ style: { backgroundColor: "var(--theme-element)" },
187
+ onMouseEnter: (e) => {
188
+ if (!(!isCurrentStepValid || isLoading)) e.currentTarget.style.filter = "brightness(0.9)";
189
+ },
190
+ onMouseLeave: (e) => {
191
+ e.currentTarget.style.filter = "brightness(1)";
192
+ },
193
+ "aria-label": submitLabel,
194
+ children: [isLoading && /* @__PURE__ */ jsx(Loader, {
195
+ size: 16,
196
+ full: false
197
+ }), submitLabel]
198
+ }) : /* @__PURE__ */ jsxs("button", {
199
+ type: "button",
200
+ onClick: handleNext,
201
+ disabled: !canGoToNext || isLoading,
202
+ className: "px-8 py-3 rounded-lg font-medium transition-all duration-200 text-white flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed shadow-md hover:shadow-lg",
203
+ style: { backgroundColor: "var(--theme-element)" },
204
+ onMouseEnter: (e) => {
205
+ if (!(!canGoToNext || isLoading)) e.currentTarget.style.filter = "brightness(0.9)";
206
+ },
207
+ onMouseLeave: (e) => {
208
+ e.currentTarget.style.filter = "brightness(1)";
209
+ },
210
+ "aria-label": "Go to next step",
211
+ children: [isLoading && /* @__PURE__ */ jsx(Loader, {
212
+ size: 16,
213
+ full: false
214
+ }), nextLabel || "Next →"]
215
+ })]
216
+ })] });
217
+ }
218
+ //#endregion
219
+ //#region src/form/Wizard/WizardStepContent.tsx
220
+ function WizardStepContent({ currentStep, stepConfig, flatten = true, values, onValuesChange, setFormDirty, setFieldValue, setFieldTouched, ...fieldsProps }) {
221
+ if (!stepConfig?.options) return null;
222
+ return /* @__PURE__ */ jsxs("div", {
223
+ className: "mb-4 w-full",
224
+ children: [
225
+ stepConfig.title && /* @__PURE__ */ jsx("h2", {
226
+ className: "text-2xl font-bold mb-2",
227
+ style: { color: "var(--theme-app)" },
228
+ children: stepConfig.title
229
+ }),
230
+ stepConfig.description && /* @__PURE__ */ jsx("p", {
231
+ className: "mb-4 leading-relaxed",
232
+ style: { color: "var(--theme-muted-text-color)" },
233
+ children: stepConfig.description
234
+ }),
235
+ /* @__PURE__ */ jsx(FieldsFromOptions, {
236
+ options: stepConfig.options,
237
+ values,
238
+ setFormDirty,
239
+ setFieldValue,
240
+ setFieldTouched,
241
+ ...flatten === false ? { parentInfo: {
242
+ parentName: currentStep,
243
+ fieldNamePrefix: `${currentStep}.`
244
+ } } : {},
245
+ ...fieldsProps
246
+ }, currentStep)
247
+ ]
248
+ });
249
+ }
250
+ //#endregion
251
+ //#region src/form/Wizard/WizardStepIndicator.tsx
252
+ function WizardStepIndicator({ stepOrder, currentStep, steps, visitedSteps, invalidSteps, onStepClick, allowJump = false, hideStepNumbers = false }) {
253
+ const currentIndex = useMemo(() => stepOrder.indexOf(currentStep), [stepOrder, currentStep]);
254
+ const getStepStatus = (stepKey, index) => {
255
+ if (stepKey === currentStep) return "active";
256
+ if (index < currentIndex) return "completed";
257
+ return "upcoming";
258
+ };
259
+ const handleStepClick = (stepKey) => {
260
+ if (!allowJump || !visitedSteps.has(stepKey)) return;
261
+ onStepClick?.(stepKey);
262
+ };
263
+ const isClickable = (stepKey) => {
264
+ return allowJump && visitedSteps.has(stepKey) && stepKey !== currentStep;
265
+ };
266
+ return /* @__PURE__ */ jsx("div", {
267
+ className: "flex items-start justify-between w-full mb-2 gap-4 py-2",
268
+ children: stepOrder.map((stepKey, index) => {
269
+ const stepConfig = steps[stepKey];
270
+ const status = getStepStatus(stepKey, index);
271
+ const isInvalid = invalidSteps.has(stepKey);
272
+ const isClickable_ = isClickable(stepKey);
273
+ const isDotActive = status === "active";
274
+ const isDotCompleted = status === "completed";
275
+ const isDotUpcoming = status === "upcoming";
276
+ return /* @__PURE__ */ jsxs("div", {
277
+ className: "flex flex-col items-center flex-1 relative",
278
+ children: [
279
+ /* @__PURE__ */ jsxs("button", {
280
+ type: "button",
281
+ onClick: () => handleStepClick(stepKey),
282
+ disabled: !isClickable_,
283
+ className: cx("w-12 h-12 rounded-full border-3 flex items-center justify-center font-bold text-base transition-all duration-300 flex-shrink-0 relative", {
284
+ "cursor-pointer": isClickable_,
285
+ "cursor-not-allowed": !isClickable_
286
+ }, {
287
+ "text-white": isDotActive,
288
+ "bg-green-500 border-green-600 text-white shadow-md": isDotCompleted && !isInvalid,
289
+ "bg-(--theme-border) theme-border theme-muted-text shadow-sm": isDotUpcoming && !isInvalid,
290
+ "bg-(--theme-muted-panel-bg) theme-border theme-muted-text shadow-sm": !isDotActive && !isDotCompleted && !isDotUpcoming && !isInvalid,
291
+ "bg-red-50 border-red-500 text-red-600 shadow-sm": isInvalid && status !== "active"
292
+ }),
293
+ style: isDotActive ? {
294
+ backgroundColor: "var(--theme-element)",
295
+ borderColor: "var(--theme-element)",
296
+ color: "var(--theme-element-text)",
297
+ boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
298
+ zIndex: 10
299
+ } : { zIndex: 10 },
300
+ "aria-label": `Step ${index + 1}: ${stepConfig?.title}`,
301
+ title: stepConfig?.title,
302
+ children: [!hideStepNumbers && /* @__PURE__ */ jsx("span", {
303
+ className: cx({ hidden: status === "completed" }),
304
+ children: index + 1
305
+ }), status === "completed" && /* @__PURE__ */ jsx("svg", {
306
+ className: "w-4 h-4",
307
+ fill: "none",
308
+ stroke: "currentColor",
309
+ viewBox: "0 0 24 24",
310
+ children: /* @__PURE__ */ jsx("path", {
311
+ strokeLinecap: "round",
312
+ strokeLinejoin: "round",
313
+ strokeWidth: 3,
314
+ d: "M5 13l4 4L19 7"
315
+ })
316
+ })]
317
+ }),
318
+ index < stepOrder.length - 1 && /* @__PURE__ */ jsx("div", {
319
+ className: cx("absolute h-1 transition-all duration-300", {
320
+ "bg-green-500": index < currentIndex,
321
+ "bg-(--theme-border)": index >= currentIndex,
322
+ "opacity-25": index >= currentIndex
323
+ }),
324
+ style: {
325
+ top: "24px",
326
+ left: "calc(50% + 24px)",
327
+ right: "-50%",
328
+ boxShadow: index < currentIndex ? "0 1px 2px rgba(34, 197, 94, 0.2)" : "none"
329
+ },
330
+ "aria-hidden": "true"
331
+ }),
332
+ /* @__PURE__ */ jsxs("div", {
333
+ className: "mt-2 text-center",
334
+ children: [/* @__PURE__ */ jsx("div", {
335
+ className: cx("text-sm text-center transition-colors duration-300 max-w-30", {
336
+ "font-bold text-green-600": isDotCompleted && !isInvalid,
337
+ "font-bold text-red-600": isInvalid && status !== "active",
338
+ "font-semibold theme-muted-text": !isDotActive && !isDotCompleted && !isInvalid,
339
+ "font-bold text-white": isDotActive
340
+ }),
341
+ style: isDotActive ? { color: "var(--theme-element)" } : {},
342
+ children: stepConfig?.title
343
+ }), stepConfig?.description && /* @__PURE__ */ jsx("div", {
344
+ className: "text-xs theme-muted-text mt-1 text-center max-w-30",
345
+ children: stepConfig.description
346
+ })]
347
+ })
348
+ ]
349
+ }, stepKey);
350
+ })
351
+ });
352
+ }
353
+ //#endregion
354
+ //#region src/form/Wizard/useWizardState.ts
355
+ function useWizardState({ stepOrder, steps, validateStep, initialStep }) {
356
+ const firstStep = initialStep || stepOrder[0];
357
+ const [currentStep, setCurrentStep] = useState(firstStep);
358
+ const [visitedSteps, setVisitedSteps] = useState(new Set([firstStep]));
359
+ const [invalidSteps, setInvalidSteps] = useState(/* @__PURE__ */ new Set());
360
+ const currentStepIndex = stepOrder.indexOf(currentStep);
361
+ const isLastStep = currentStepIndex === stepOrder.length - 1;
362
+ const canGoBack = currentStepIndex > 0;
363
+ /**
364
+ * Mark step as visited
365
+ */
366
+ const markStepVisited = useCallback((stepKey) => {
367
+ setVisitedSteps((prev) => new Set([...prev, stepKey]));
368
+ }, []);
369
+ /**
370
+ * Mark step as invalid
371
+ */
372
+ const markStepInvalid = useCallback((stepKey, invalid) => {
373
+ setInvalidSteps((prev) => {
374
+ const next = new Set(prev);
375
+ if (invalid) next.add(stepKey);
376
+ else next.delete(stepKey);
377
+ return next;
378
+ });
379
+ }, []);
380
+ const goToNext = useCallback(async () => {
381
+ if (isLastStep) return false;
382
+ if (steps[currentStep]?.validateOnNext !== false) {
383
+ if (!await validateStep(currentStep)) {
384
+ markStepInvalid(currentStep, true);
385
+ return false;
386
+ }
387
+ }
388
+ markStepInvalid(currentStep, false);
389
+ const nextStepKey = stepOrder[currentStepIndex + 1];
390
+ setCurrentStep(nextStepKey);
391
+ markStepVisited(nextStepKey);
392
+ return true;
393
+ }, [
394
+ currentStep,
395
+ currentStepIndex,
396
+ isLastStep,
397
+ steps,
398
+ stepOrder,
399
+ validateStep,
400
+ markStepInvalid,
401
+ markStepVisited
402
+ ]);
403
+ const goToPrevious = useCallback(() => {
404
+ if (!canGoBack) return;
405
+ const prevStepKey = stepOrder[currentStepIndex - 1];
406
+ setCurrentStep(prevStepKey);
407
+ }, [
408
+ canGoBack,
409
+ currentStepIndex,
410
+ stepOrder
411
+ ]);
412
+ const jumpToStep = useCallback((stepKey) => {
413
+ if (!stepOrder.includes(stepKey)) return false;
414
+ if (!visitedSteps.has(stepKey) && stepKey !== currentStep) return false;
415
+ setCurrentStep(stepKey);
416
+ return true;
417
+ }, [
418
+ stepOrder,
419
+ visitedSteps,
420
+ currentStep
421
+ ]);
422
+ /**
423
+ * Reset wizard to initial state
424
+ */
425
+ const reset = useCallback(() => {
426
+ setCurrentStep(firstStep);
427
+ setVisitedSteps(new Set([firstStep]));
428
+ setInvalidSteps(/* @__PURE__ */ new Set());
429
+ }, [firstStep]);
430
+ /**
431
+ * Get current wizard state
432
+ */
433
+ const getState = useCallback(() => {
434
+ return {
435
+ currentStep,
436
+ visitedSteps,
437
+ invalidSteps,
438
+ stepOrder,
439
+ totalSteps: stepOrder.length,
440
+ isLastStep,
441
+ canProceedToNext: !isLastStep,
442
+ canGoBack
443
+ };
444
+ }, [
445
+ currentStep,
446
+ visitedSteps,
447
+ invalidSteps,
448
+ stepOrder,
449
+ isLastStep,
450
+ canGoBack
451
+ ]);
452
+ return {
453
+ currentStep,
454
+ visitedSteps,
455
+ invalidSteps,
456
+ isLastStep,
457
+ canGoBack,
458
+ currentStepIndex,
459
+ totalSteps: stepOrder.length,
460
+ goToNext,
461
+ goToPrevious,
462
+ jumpToStep,
463
+ reset,
464
+ markStepVisited,
465
+ markStepInvalid,
466
+ getState
467
+ };
468
+ }
469
+ //#endregion
470
+ //#region src/form/Wizard/WizardContainer.tsx
471
+ function WizardContainer({ wizardConfig, values, onChange, onSubmit, className = "", labelPosition = "left", missingFields = [], spaceCompact = false, workflowForm = false, setFieldValue, setFieldTouched }) {
472
+ const { validateForm, setTouched, touched } = useFormikContext();
473
+ const { config, steps, stepOrder } = wizardConfig;
474
+ const { currentStep, visitedSteps, invalidSteps, isLastStep, canGoBack, goToNext, goToPrevious, jumpToStep } = useWizardState({
475
+ stepOrder,
476
+ steps,
477
+ validateStep: useCallback(async (stepKey) => {
478
+ const stepConfig = steps[stepKey];
479
+ if (!stepConfig?.options) return true;
480
+ const stepFieldNames = Object.keys(stepConfig.options);
481
+ const shouldFlatten = config.flatten !== false;
482
+ const errors = await validateForm();
483
+ const hasStepErrors = shouldFlatten ? stepFieldNames.some((fieldName) => errors[fieldName]) : stepFieldNames.some((fieldName) => errors[stepKey]?.[fieldName]);
484
+ if (hasStepErrors) {
485
+ const touchedFields = stepFieldNames.reduce((acc, fieldName) => {
486
+ acc[fieldName] = true;
487
+ return acc;
488
+ }, {});
489
+ if (shouldFlatten) setTouched({
490
+ ...touched,
491
+ ...touchedFields
492
+ }, false);
493
+ else setTouched({
494
+ ...touched,
495
+ [stepKey]: touchedFields
496
+ }, false);
497
+ }
498
+ return !hasStepErrors;
499
+ }, [
500
+ steps,
501
+ validateForm,
502
+ setTouched,
503
+ touched
504
+ ])
505
+ });
506
+ const currentStepConfig = steps[currentStep];
507
+ const config_ = config.navigation || {};
508
+ const handleGoToNext = useCallback(async () => {
509
+ const success = await goToNext();
510
+ if (success) onChange?.(values);
511
+ return success;
512
+ }, [
513
+ goToNext,
514
+ values,
515
+ onChange
516
+ ]);
517
+ const handleJumpToStep = useCallback((stepKey) => {
518
+ if (!config_.allowJump || !visitedSteps.has(stepKey)) return false;
519
+ return jumpToStep(stepKey);
520
+ }, [
521
+ jumpToStep,
522
+ config_.allowJump,
523
+ visitedSteps
524
+ ]);
525
+ const handleSubmit = useCallback(async () => {
526
+ if (!isLastStep) return;
527
+ const errors = await validateForm();
528
+ if (Object.keys(errors).length > 0) {
529
+ const touchedFields = Object.keys(values).reduce((acc, fieldName) => {
530
+ acc[fieldName] = true;
531
+ return acc;
532
+ }, {});
533
+ setTouched({
534
+ ...touched,
535
+ ...touchedFields
536
+ }, false);
537
+ throw new Error("Please fix errors before submitting");
538
+ }
539
+ await onSubmit?.(values);
540
+ }, [
541
+ isLastStep,
542
+ validateForm,
543
+ values,
544
+ setTouched,
545
+ touched,
546
+ onSubmit
547
+ ]);
548
+ return /* @__PURE__ */ jsxs("div", {
549
+ className,
550
+ children: [
551
+ config_.showSteps !== false && /* @__PURE__ */ jsx(WizardStepIndicator, {
552
+ stepOrder,
553
+ currentStep,
554
+ steps,
555
+ visitedSteps,
556
+ invalidSteps,
557
+ onStepClick: handleJumpToStep,
558
+ allowJump: config_.allowJump,
559
+ hideStepNumbers: config_.hideStepNumbers
560
+ }),
561
+ currentStepConfig && /* @__PURE__ */ jsx("div", {
562
+ className: "mb-4",
563
+ children: /* @__PURE__ */ jsx(WizardStepContent, {
564
+ currentStep,
565
+ stepConfig: currentStepConfig,
566
+ flatten: config.flatten,
567
+ values,
568
+ onValuesChange: onChange,
569
+ labelPosition,
570
+ missingFields,
571
+ spaceCompact,
572
+ setFormDirty: () => onChange?.(values),
573
+ workflowForm,
574
+ setFieldValue,
575
+ setFieldTouched
576
+ })
577
+ }),
578
+ /* @__PURE__ */ jsx(WizardNavigation, {
579
+ currentStep,
580
+ stepOrder,
581
+ canGoToNext: !isLastStep,
582
+ canGoBack,
583
+ isCurrentStepValid: !invalidSteps.has(currentStep),
584
+ nextLabel: currentStepConfig?.nextLabel,
585
+ prevLabel: currentStepConfig?.prevLabel,
586
+ submitLabel: config.submitLabel || "Execute",
587
+ onNext: handleGoToNext,
588
+ onPrevious: goToPrevious,
589
+ onSubmit: handleSubmit
590
+ })
591
+ ]
592
+ });
593
+ }
594
+ //#endregion
595
+ //#region src/form/Wizard/utils.ts
596
+ function parseWizardConfig(options) {
597
+ const wizardConfig = options.$meta?.wizard;
598
+ if (!wizardConfig || wizardConfig.mode !== "wizard") return null;
599
+ const steps = {};
600
+ const stepOrder = [];
601
+ const otherFields = {};
602
+ Object.entries(options).forEach(([key, field]) => {
603
+ if (key === "$meta") return;
604
+ const fieldConfig = field;
605
+ if (fieldConfig?.type === "step") {
606
+ steps[key] = fieldConfig;
607
+ stepOrder.push(key);
608
+ } else otherFields[key] = field;
609
+ });
610
+ if (stepOrder.length === 0) {
611
+ console.warn("Wizard mode enabled but no steps found");
612
+ return null;
613
+ }
614
+ return {
615
+ config: wizardConfig,
616
+ steps,
617
+ stepOrder,
618
+ otherFields
619
+ };
620
+ }
621
+ //#endregion
622
+ //#region src/form/SpecialTypes/FormikCustomDropdown.tsx
623
+ function toComparableOptions(options) {
624
+ return options?.map((option) => {
625
+ if (typeof option === "string") return option;
626
+ if (isCategory(option)) return {
627
+ category: option.category,
628
+ options: option.options.map((o) => {
629
+ const base = {
630
+ label: o.label,
631
+ value: o.value,
632
+ disabled: o.disabled
633
+ };
634
+ return o.description !== void 0 ? {
635
+ ...base,
636
+ description: o.description
637
+ } : base;
638
+ })
639
+ };
640
+ const base = {
641
+ label: option.label,
642
+ value: option.value,
643
+ disabled: option.disabled
644
+ };
645
+ return option.description !== void 0 ? {
646
+ ...base,
647
+ description: option.description
648
+ } : base;
649
+ });
650
+ }
651
+ function arePropsEqual(prev, next) {
652
+ for (const key of Object.keys(next)) if (key === "options") {
653
+ if (!deepEqual(toComparableOptions(prev.options), toComparableOptions(next.options))) return false;
654
+ } else if (prev[key] !== next[key]) return false;
655
+ return true;
656
+ }
657
+ var FormikCustomDropdown_default = memo(function FormikCustomDropdown({ name, ariaLabel, options, setFormDirty, onChange, parentValue, className, secondaryField, disabled = false, loading = false, invalid = false, autoselect, value, allowCustomValue = false, customValueLabel, placeholder, currentValue, setFieldValue, setFieldTouched }) {
658
+ const prevParentRef = useRef(parentValue);
659
+ const handleChange = (val) => {
660
+ if (secondaryField && typeof options[0] !== "string") {
661
+ const option = findSecondaryOption(options, val);
662
+ if (option) applySecondaryField(secondaryField, option.secondaryValue, setFieldValue);
663
+ }
664
+ if (onChange) onChange(val);
665
+ setFieldValue(name, val);
666
+ setFieldTouched(name, true);
667
+ setFormDirty(true);
668
+ };
669
+ useEffect(() => {
670
+ prevParentRef.current = parentValue;
671
+ });
672
+ const prevOptions = useRef(null);
673
+ useEffect(() => {
674
+ if (deepEqual(prevOptions.current, toComparableOptions(options))) return;
675
+ if (prevOptions.current === null && currentValue !== void 0 && currentValue !== null) {
676
+ prevOptions.current = toComparableOptions(options);
677
+ return;
678
+ }
679
+ prevOptions.current = toComparableOptions(options);
680
+ if (autoselect === false || !options?.length) return;
681
+ if (autoselect === void 0) {
682
+ if (options.length && isCategory(options[0])) {
683
+ let optionCount = 0;
684
+ for (const category of options) {
685
+ if (isCategory(category)) optionCount += category.options.length;
686
+ if (optionCount > 1) return;
687
+ }
688
+ } else if (options.length !== 1) return;
689
+ }
690
+ if (!options?.find((option) => {
691
+ if (typeof option === "string") return option === currentValue;
692
+ else if (isCategory(option)) return option.options.some((subOption) => {
693
+ return subOption.value === currentValue;
694
+ });
695
+ return option.value === currentValue;
696
+ }) || autoselect) {
697
+ let val;
698
+ for (const option of options) if (typeof option === "string") {
699
+ val = option;
700
+ break;
701
+ } else if (isCategory(option)) {
702
+ const enabled = option.options.find((o) => !o.disabled);
703
+ if (enabled) {
704
+ val = enabled.value;
705
+ break;
706
+ }
707
+ } else if (!option.disabled) {
708
+ val = option.value;
709
+ break;
710
+ }
711
+ if (val !== void 0) handleChange(val);
712
+ }
713
+ }, [
714
+ parentValue,
715
+ options,
716
+ autoselect
717
+ ]);
718
+ return /* @__PURE__ */ jsx(Dropdown, {
719
+ textBoxClassName: cx(className, invalid && "invalid"),
720
+ ariaLabel,
721
+ onChange: (val) => handleChange(val),
722
+ value: options?.length === 0 && !allowCustomValue ? value : currentValue,
723
+ options,
724
+ placeholder,
725
+ disabled,
726
+ loading,
727
+ allowCustomValue,
728
+ customValueLabel
729
+ });
730
+ }, arePropsEqual);
731
+ //#endregion
732
+ //#region src/form/SpecialTypes/FormikCustomInput.tsx
733
+ var DEBOUNCE_MS$2 = 500;
734
+ function FormikCustomInput({ name, type, step, placeholder, onChange, disabled, min, max, sanitize, invalid = false, lowercase = false, minLength, maxLength, defaultValue = "", value }) {
735
+ const [field] = useField(name);
736
+ const { setFieldValue, setFieldTouched } = useFormikContext();
737
+ const [showPassword, setShowPassword] = useState(false);
738
+ const isPassword = type === "password";
739
+ const [localValue, setLocalValue] = useState(value ?? field.value);
740
+ const isFocused = useRef(false);
741
+ const debounceRef = useRef(null);
742
+ useEffect(() => {
743
+ if (!isFocused.current) setLocalValue(value ?? field.value);
744
+ }, [field.value, value]);
745
+ const sanitizeName = useCallback((val) => {
746
+ if (sanitize === void 0) return lowercase ? val.toLowerCase() : val;
747
+ try {
748
+ const regexp = new RegExp(sanitize);
749
+ if (lowercase) val = val.toLowerCase();
750
+ return val.replace(regexp, "");
751
+ } catch {
752
+ console.error("Invalid regex for sanitization:", sanitize);
753
+ }
754
+ return val;
755
+ }, [sanitize, lowercase]);
756
+ const flushToFormik = useCallback((val) => {
757
+ if (onChange) onChange(val);
758
+ setFieldTouched(name, true);
759
+ setFieldValue(name, val);
760
+ }, [
761
+ name,
762
+ onChange,
763
+ setFieldTouched,
764
+ setFieldValue
765
+ ]);
766
+ const handleChange = (e) => {
767
+ let val = e.target.value;
768
+ if (sanitize) val = sanitizeName(val);
769
+ if (type === "number") {
770
+ const parsed = parseFloat(val);
771
+ val = isNaN(parsed) ? void 0 : parsed;
772
+ }
773
+ if (type === "password" && val === "") val = defaultValue;
774
+ setLocalValue(val);
775
+ clearTimeout(debounceRef.current ?? void 0);
776
+ debounceRef.current = setTimeout(() => flushToFormik(val), DEBOUNCE_MS$2);
777
+ };
778
+ const handleFocus = () => {
779
+ isFocused.current = true;
780
+ };
781
+ const handleBlur = () => {
782
+ isFocused.current = false;
783
+ clearTimeout(debounceRef.current ?? void 0);
784
+ const current = localValue;
785
+ if (current === void 0 || current === null) return;
786
+ let val = current.toString();
787
+ if (type === "number") {
788
+ const parsed = parseFloat(val);
789
+ if (Number.isNaN(parsed)) val = void 0;
790
+ else if (min !== void 0 && parsed < min) val = min;
791
+ else if (max !== void 0 && parsed > max) val = max;
792
+ else val = parsed;
793
+ }
794
+ setLocalValue(val);
795
+ flushToFormik(val);
796
+ };
797
+ const displayValue = isPassword && localValue === defaultValue ? "" : localValue ?? "";
798
+ const resolvedType = isPassword ? showPassword ? "text" : "password" : type === "string" ? "text" : type;
799
+ const input = /* @__PURE__ */ jsx("input", {
800
+ "data-1p-ignore": true,
801
+ className: cx("w-full", disabled && "disabled", invalid && "invalid", isPassword && "pr-8"),
802
+ name,
803
+ value: displayValue,
804
+ type: resolvedType,
805
+ disabled,
806
+ placeholder,
807
+ minLength,
808
+ maxLength,
809
+ onChange: handleChange,
810
+ onFocus: handleFocus,
811
+ onBlur: handleBlur,
812
+ min,
813
+ max,
814
+ step
815
+ });
816
+ if (!isPassword) return input;
817
+ return /* @__PURE__ */ jsxs("div", {
818
+ className: "relative w-full",
819
+ children: [input, /* @__PURE__ */ jsx("button", {
820
+ type: "button",
821
+ className: "absolute right-2 top-1/2 -translate-y-1/2 theme-muted-text",
822
+ onClick: () => setShowPassword((prev) => !prev),
823
+ disabled,
824
+ tabIndex: -1,
825
+ "aria-label": showPassword ? "Hide value" : "Show value",
826
+ children: showPassword ? /* @__PURE__ */ jsx(EyeOffIcon, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(EyeIcon, { className: "h-4 w-4" })
827
+ })]
828
+ });
829
+ }
830
+ //#endregion
831
+ //#region src/form/SpecialTypes/FormikNumericInput.tsx
832
+ var DEBOUNCE_MS$1 = 500;
833
+ function FormikNumericInput({ name, placeholder, onChange, disabled, min, max, invalid = false }) {
834
+ const [field] = useField(name);
835
+ const { setFieldValue, setFieldTouched } = useFormikContext();
836
+ const [localValue, setLocalValue] = useState(field.value);
837
+ const isFocused = useRef(false);
838
+ const debounceRef = useRef(null);
839
+ useEffect(() => {
840
+ if (!isFocused.current) setLocalValue(field.value);
841
+ }, [field.value]);
842
+ const flush = (val) => {
843
+ onChange?.(val);
844
+ setFieldTouched(name, true);
845
+ setFieldValue(name, val);
846
+ };
847
+ const handleBlur = () => {
848
+ isFocused.current = false;
849
+ clearTimeout(debounceRef.current ?? void 0);
850
+ let val = localValue;
851
+ if (val !== void 0) {
852
+ if (min !== void 0 && val < min) val = min;
853
+ if (max !== void 0 && val > max) val = max;
854
+ }
855
+ setLocalValue(val);
856
+ flush(val);
857
+ };
858
+ return /* @__PURE__ */ jsx(NumericFormat, {
859
+ "data-1p-ignore": true,
860
+ className: cx("w-full", disabled && "disabled", invalid && "invalid"),
861
+ name,
862
+ value: localValue,
863
+ thousandSeparator: ",",
864
+ decimalScale: 20,
865
+ allowNegative: true,
866
+ disabled,
867
+ placeholder,
868
+ onValueChange: (v) => {
869
+ setLocalValue(v.floatValue);
870
+ clearTimeout(debounceRef.current ?? void 0);
871
+ debounceRef.current = setTimeout(() => flush(v.floatValue), DEBOUNCE_MS$1);
872
+ },
873
+ onFocus: () => {
874
+ isFocused.current = true;
875
+ },
876
+ onBlur: handleBlur
877
+ });
878
+ }
879
+ //#endregion
880
+ //#region src/form/utils/getPlaceholder.ts
881
+ /** `placeholder=""` (empty string) intentionally overrides the default; undefined does not. */
882
+ function getPlaceholder(placeholder, defaultValue) {
883
+ if (placeholder !== void 0) return placeholder;
884
+ if (defaultValue && (typeof defaultValue === "string" || typeof defaultValue === "number")) return defaultValue.toString();
885
+ return "";
886
+ }
887
+ //#endregion
888
+ //#region src/form/Fields/StringField.tsx
889
+ var StringField_default = memo(function StringField(props) {
890
+ const { field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact, currentValue } = props;
891
+ const value = field.prefillDefault ? currentValue : void 0;
892
+ return /* @__PURE__ */ jsx(FieldWrapper, {
893
+ optional: field.optional,
894
+ label,
895
+ tooltipComponent,
896
+ description: field.description,
897
+ labelPosition,
898
+ spaceCompact,
899
+ children: /* @__PURE__ */ jsx(FormikCustomInput, {
900
+ invalid: missing,
901
+ name: field.name,
902
+ type: field.type,
903
+ lowercase: field.lowercase,
904
+ placeholder: field.type === "password" && field.placeholder === void 0 ? "•".repeat((field.default ?? "").toString().length > 0 ? 16 : 0) : getPlaceholder(field.placeholder, field.default),
905
+ disabled,
906
+ step: field.step,
907
+ min: field.min,
908
+ max: field.max,
909
+ minLength: field.minLength,
910
+ maxLength: field.maxLength,
911
+ sanitize: field.sanitize,
912
+ defaultValue: field.default,
913
+ value,
914
+ ...onChange && { onChange }
915
+ }, field.name)
916
+ });
917
+ });
918
+ //#endregion
919
+ //#region src/form/Fields/NumberField.tsx
920
+ function NumberField(props) {
921
+ const { field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact } = props;
922
+ const [fieldState] = useField(field.name);
923
+ const { setFieldValue } = useFormikContext();
924
+ useEffect(() => {
925
+ if (field.prefillDefault && field.default !== void 0 && (fieldState.value === void 0 || fieldState.value === null || fieldState.value === "")) setFieldValue(field.name, field.default);
926
+ }, [
927
+ field.prefillDefault,
928
+ field.default,
929
+ field.name,
930
+ fieldState.value,
931
+ setFieldValue
932
+ ]);
933
+ return /* @__PURE__ */ jsx(FieldWrapper, {
934
+ optional: field.optional,
935
+ label,
936
+ tooltipComponent,
937
+ labelPosition,
938
+ spaceCompact,
939
+ children: field.thousandsSeparator ? /* @__PURE__ */ jsx(FormikNumericInput, {
940
+ invalid: missing,
941
+ name: field.name,
942
+ placeholder: getPlaceholder(field.placeholder, field.default),
943
+ disabled,
944
+ min: field.min,
945
+ max: field.max,
946
+ ...onChange && { onChange }
947
+ }, field.name) : /* @__PURE__ */ jsx(FormikCustomInput, {
948
+ invalid: missing,
949
+ name: field.name,
950
+ type: "number",
951
+ placeholder: getPlaceholder(field.placeholder, field.default),
952
+ disabled,
953
+ step: field.step,
954
+ min: field.min,
955
+ max: field.max,
956
+ defaultValue: field.default,
957
+ ...onChange && { onChange }
958
+ }, field.name)
959
+ });
960
+ }
961
+ //#endregion
962
+ //#region src/form/Fields/BooleanField.tsx
963
+ function BooleanField(props) {
964
+ const { field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact, setFormDirty } = props;
965
+ const [fieldState] = useField(field.name);
966
+ const { setFieldValue, setFieldTouched } = useFormikContext();
967
+ const handleChange = (val) => {
968
+ if (disabled) return;
969
+ if (onChange) onChange(val);
970
+ setFieldTouched(field.name, true);
971
+ setFieldValue(field.name, val);
972
+ setFormDirty(true);
973
+ };
974
+ const value = fieldState.value;
975
+ const options = field.options ? {
976
+ onOption: String(field.options.onOption ?? true),
977
+ offOption: String(field.options.offOption ?? false)
978
+ } : void 0;
979
+ const displayLabel = (option) => option.charAt(0).toUpperCase() + option.slice(1).toLowerCase();
980
+ return /* @__PURE__ */ jsx(FieldWrapper, {
981
+ optional: true,
982
+ label,
983
+ tooltipComponent: /* @__PURE__ */ jsx("div", { children: tooltipComponent }),
984
+ description: field.description,
985
+ labelPosition,
986
+ spaceCompact,
987
+ children: options ? /* @__PURE__ */ jsx(SwitchToggle, {
988
+ onChange: (on) => handleChange(on ? options.onOption : options.offOption),
989
+ value: value === true || value === options.onOption,
990
+ yesLabel: displayLabel(options.onOption),
991
+ noLabel: displayLabel(options.offOption),
992
+ disabled,
993
+ invalid: missing
994
+ }) : /* @__PURE__ */ jsx(SwitchToggle, {
995
+ datatip: field.disabled_message,
996
+ onChange: handleChange,
997
+ value: value === true || value === "true",
998
+ disabled,
999
+ invalid: missing
1000
+ })
1001
+ });
1002
+ }
1003
+ //#endregion
1004
+ //#region src/form/Fields/DropdownField.tsx
1005
+ function DropdownField(props) {
1006
+ const { field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact, setFieldValue, setFieldTouched, currentValue } = props;
1007
+ let parentValue = field.parentValue;
1008
+ let options = Array.isArray(field.options) && field.options || [];
1009
+ if (field.depends_on) {
1010
+ parentValue = field.depends_on;
1011
+ if (!Array.isArray(field.options)) options = field.options[parentValue];
1012
+ }
1013
+ const secondaryField = Array.isArray(field.secondaryField) ? field.secondaryField[0] : field.secondaryField;
1014
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1015
+ optional: field.optional,
1016
+ label,
1017
+ tooltipComponent,
1018
+ description: field.description,
1019
+ labelPosition,
1020
+ spaceCompact,
1021
+ children: /* @__PURE__ */ jsx("div", {
1022
+ className: "grow min-w-0",
1023
+ children: /* @__PURE__ */ jsx(FormikCustomDropdown_default, {
1024
+ invalid: missing,
1025
+ className: "w-full",
1026
+ name: field.name,
1027
+ ariaLabel: label,
1028
+ options,
1029
+ setFormDirty: props.setFormDirty,
1030
+ parentValue,
1031
+ onChange,
1032
+ secondaryField,
1033
+ disabled,
1034
+ resetOnChange: field.resetOnChange ? field.name : "",
1035
+ loading: false,
1036
+ autoselect: field.autoselect,
1037
+ allowCustomValue: field.allowCustomValue,
1038
+ customValueLabel: field.customValueLabel,
1039
+ placeholder: getPlaceholder(field.placeholder, typeof field.default === "string" ? field.default : void 0),
1040
+ currentValue,
1041
+ setFieldValue,
1042
+ setFieldTouched
1043
+ }, field.name)
1044
+ })
1045
+ });
1046
+ }
1047
+ //#endregion
1048
+ //#region src/form/Fields/TextAreaField.tsx
1049
+ function TextAreaField(props) {
1050
+ const { field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact } = props;
1051
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1052
+ optional: field.optional,
1053
+ label,
1054
+ tooltipComponent,
1055
+ description: field.description,
1056
+ labelPosition,
1057
+ spaceCompact,
1058
+ children: /* @__PURE__ */ jsx(Field, {
1059
+ className: cx("theme-input h-[82px] w-full rounded leading-4 overflow-y-scroll", disabled && "disabled", missing && "border-red-600 focus:border-red-600 focus:ring-red-500"),
1060
+ as: "textarea",
1061
+ name: field.name,
1062
+ type: "search",
1063
+ placeholder: getPlaceholder(field.placeholder, field.default),
1064
+ disabled,
1065
+ ...onChange && { onChange }
1066
+ }, field.name)
1067
+ });
1068
+ }
1069
+ //#endregion
1070
+ //#region src/form/Fields/RangeField.tsx
1071
+ function RangeField(props) {
1072
+ const { field, label, labelPosition, disabled, onChange, tooltipComponent, spaceCompact, setFormDirty } = props;
1073
+ const [fieldState] = useField(field.name);
1074
+ const { setFieldValue, setFieldTouched } = useFormikContext();
1075
+ const handleChange = (e) => {
1076
+ let val = e.target.valueAsNumber;
1077
+ if (!isNaN(val)) {
1078
+ val = Math.max(field.min, Math.min(field.max, val));
1079
+ setFieldValue(field.name, val);
1080
+ if (onChange) onChange(val);
1081
+ setFieldTouched(field.name, true);
1082
+ setFormDirty(true);
1083
+ }
1084
+ };
1085
+ const seedValue = field.default ?? field.min;
1086
+ if ((fieldState.value === void 0 || fieldState.value === null) && seedValue !== void 0) setFieldValue(field.name, seedValue);
1087
+ const currentValue = fieldState.value !== void 0 ? fieldState.value : seedValue;
1088
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1089
+ optional: field.optional,
1090
+ label,
1091
+ tooltipComponent,
1092
+ labelPosition,
1093
+ spaceCompact,
1094
+ children: /* @__PURE__ */ jsxs("div", {
1095
+ className: "flex items-center",
1096
+ children: [/* @__PURE__ */ jsx(Field, {
1097
+ className: cx("theme-input h-7 w-1/3 mr-5 text-center rounded border text-[14px]", disabled && "disabled"),
1098
+ type: "number",
1099
+ value: currentValue,
1100
+ min: field.min,
1101
+ max: field.max,
1102
+ step: field.step || 1,
1103
+ disabled,
1104
+ onChange: handleChange
1105
+ }), /* @__PURE__ */ jsx(Field, {
1106
+ className: cx("rounded w-full", disabled && "disabled"),
1107
+ name: field.name,
1108
+ value: currentValue,
1109
+ type: "range",
1110
+ min: field.min,
1111
+ max: field.max,
1112
+ step: field.step || 1,
1113
+ disabled,
1114
+ onChange: handleChange
1115
+ })]
1116
+ })
1117
+ });
1118
+ }
1119
+ //#endregion
1120
+ //#region src/form/utils/slurmDuration.ts
1121
+ var WITH_DAYS = /^(\d+)-(\d{1,2})(?::(\d{1,2})(?::(\d{1,2}))?)?$/;
1122
+ var WITHOUT_DAYS = /^(\d+):(\d{1,2}):(\d{1,2})$/;
1123
+ function parseSlurmDuration(text) {
1124
+ const trimmed = text.trim();
1125
+ let days = 0;
1126
+ let hours;
1127
+ let minutes;
1128
+ let seconds;
1129
+ const withDays = trimmed.match(WITH_DAYS);
1130
+ if (withDays) {
1131
+ days = Number(withDays[1]);
1132
+ hours = Number(withDays[2]);
1133
+ minutes = Number(withDays[3] ?? 0);
1134
+ seconds = Number(withDays[4] ?? 0);
1135
+ if (hours > 23) return null;
1136
+ } else {
1137
+ const withoutDays = trimmed.match(WITHOUT_DAYS);
1138
+ if (!withoutDays) return null;
1139
+ hours = Number(withoutDays[1]);
1140
+ minutes = Number(withoutDays[2]);
1141
+ seconds = Number(withoutDays[3]);
1142
+ }
1143
+ if (minutes > 59 || seconds > 59) return null;
1144
+ return days * 86400 + hours * 3600 + minutes * 60 + seconds;
1145
+ }
1146
+ function formatSecondsAsSlurmDuration(totalSeconds) {
1147
+ if (!Number.isFinite(totalSeconds) || totalSeconds < 0) return "";
1148
+ const parts = Duration.fromObject({ seconds: Math.floor(totalSeconds) }).shiftTo("days", "hours", "minutes", "seconds");
1149
+ const pad = (n) => String(n).padStart(2, "0");
1150
+ const time = `${pad(parts.hours)}:${pad(parts.minutes)}:${pad(parts.seconds)}`;
1151
+ return parts.days > 0 ? `${parts.days}-${time}` : time;
1152
+ }
1153
+ var FLEX_MAX_DURATION_RANGE = {
1154
+ min: 600,
1155
+ max: 604800
1156
+ };
1157
+ var FLEX_WAIT_TIME_RANGE = {
1158
+ min: 30,
1159
+ max: 604800
1160
+ };
1161
+ var STANDARD_MAX_DURATION_RANGE = {
1162
+ min: 30,
1163
+ max: 10368e3
1164
+ };
1165
+ var DURATION_PATH = /^partitions\[\d+\]\.(maxDuration|flexStartWaitTime|suspendTime)$/;
1166
+ function collectPartitionDurationIssues(partitions, invalidDurationPaths) {
1167
+ const issues = new Set(invalidDurationPaths.filter((path) => DURATION_PATH.test(path)));
1168
+ (partitions ?? []).forEach((partition, i) => {
1169
+ const p = partition;
1170
+ const check = (fieldName, range, required) => {
1171
+ const raw = p?.[fieldName];
1172
+ if (raw === void 0 || raw === null || raw === "") {
1173
+ if (required) issues.add(`partitions[${i}].${fieldName}`);
1174
+ return;
1175
+ }
1176
+ const value = Number(raw);
1177
+ if (!Number.isFinite(value) || value < range.min || value > range.max) issues.add(`partitions[${i}].${fieldName}`);
1178
+ };
1179
+ if (p?.provisioningMode === "flex") {
1180
+ check("maxDuration", FLEX_MAX_DURATION_RANGE, true);
1181
+ check("flexStartWaitTime", FLEX_WAIT_TIME_RANGE, true);
1182
+ } else check("maxDuration", STANDARD_MAX_DURATION_RANGE, false);
1183
+ });
1184
+ return [...issues];
1185
+ }
1186
+ //#endregion
1187
+ //#region src/form/Fields/durationValidity.ts
1188
+ var invalidPaths = /* @__PURE__ */ new Set();
1189
+ function setDurationValidity(path, valid) {
1190
+ if (valid) invalidPaths.delete(path);
1191
+ else invalidPaths.add(path);
1192
+ }
1193
+ function getInvalidDurationPaths() {
1194
+ return [...invalidPaths];
1195
+ }
1196
+ //#endregion
1197
+ //#region src/form/Fields/DurationField.tsx
1198
+ var DEBOUNCE_MS = 500;
1199
+ var isNumericString = (value) => typeof value === "string" && /^\d+$/.test(value.trim());
1200
+ var toDisplay = (value) => {
1201
+ if (typeof value === "number") return formatSecondsAsSlurmDuration(value);
1202
+ if (isNumericString(value)) return formatSecondsAsSlurmDuration(Number(value));
1203
+ return "";
1204
+ };
1205
+ var DurationField_default = memo(function DurationField({ field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact, setFormDirty, currentValue, setFieldValue, setFieldTouched }) {
1206
+ const { form: t } = useStrings();
1207
+ const name = field.name;
1208
+ const min = field.min !== void 0 ? Number(field.min) : Number.NEGATIVE_INFINITY;
1209
+ const max = field.max !== void 0 ? Number(field.max) : Number.POSITIVE_INFINITY;
1210
+ const disableValue = field.disableValue;
1211
+ const hasDisableCheckbox = disableValue !== void 0 && field.disableLabel !== void 0;
1212
+ const isSentinel = hasDisableCheckbox && currentValue !== "" && Number(currentValue) === disableValue;
1213
+ const [text, setText] = useState(() => toDisplay(currentValue));
1214
+ const focusedRef = useRef(false);
1215
+ const debounceRef = useRef(null);
1216
+ useEffect(() => {
1217
+ if (isSentinel) {
1218
+ if (typeof currentValue !== "number") setFieldValue?.(name, disableValue);
1219
+ } else if (isNumericString(currentValue)) setFieldValue?.(name, Number(currentValue));
1220
+ else if ((currentValue === void 0 || currentValue === null || currentValue === "") && typeof field.default === "number") setFieldValue?.(name, field.default);
1221
+ }, []);
1222
+ useEffect(() => {
1223
+ if (!focusedRef.current) setText(toDisplay(currentValue));
1224
+ }, [currentValue]);
1225
+ const trimmed = text.trim();
1226
+ const parsed = trimmed === "" ? null : parseSlurmDuration(trimmed);
1227
+ let error = null;
1228
+ if (!isSentinel && trimmed !== "") {
1229
+ if (parsed === null) error = t.invalidDuration;
1230
+ else if (parsed < min || parsed > max) error = Number.isFinite(max) ? t.durationOutOfRange(formatSecondsAsSlurmDuration(Math.max(min, 0)), formatSecondsAsSlurmDuration(max)) : t.durationBelowMin(formatSecondsAsSlurmDuration(Math.max(min, 0)));
1231
+ }
1232
+ useEffect(() => {
1233
+ setDurationValidity(name, error === null);
1234
+ }, [name, error]);
1235
+ useEffect(() => () => {
1236
+ setDurationValidity(name, true);
1237
+ clearTimeout(debounceRef.current ?? void 0);
1238
+ }, [name]);
1239
+ const flushToFormik = (val) => {
1240
+ setFieldValue?.(name, val);
1241
+ onChange?.(val);
1242
+ setFieldTouched?.(name, true);
1243
+ };
1244
+ const handleDisableToggle = (checked) => {
1245
+ clearTimeout(debounceRef.current ?? void 0);
1246
+ setFormDirty(true);
1247
+ if (checked) {
1248
+ setText("");
1249
+ flushToFormik(disableValue);
1250
+ } else flushToFormik(typeof field.default === "number" ? field.default : "");
1251
+ };
1252
+ const handleChange = (e) => {
1253
+ const raw = e.target.value;
1254
+ setText(raw);
1255
+ setFormDirty(true);
1256
+ clearTimeout(debounceRef.current ?? void 0);
1257
+ const rawTrimmed = raw.trim();
1258
+ const value = rawTrimmed === "" ? "" : parseSlurmDuration(rawTrimmed);
1259
+ if (value === "" || typeof value === "number" && value >= min && value <= max) debounceRef.current = setTimeout(() => flushToFormik(value), DEBOUNCE_MS);
1260
+ };
1261
+ const handleFocus = () => {
1262
+ focusedRef.current = true;
1263
+ };
1264
+ const handleBlur = () => {
1265
+ focusedRef.current = false;
1266
+ clearTimeout(debounceRef.current ?? void 0);
1267
+ if (trimmed === "") {
1268
+ setText("");
1269
+ flushToFormik("");
1270
+ } else if (parsed !== null && parsed >= min && parsed <= max) {
1271
+ setText(formatSecondsAsSlurmDuration(parsed));
1272
+ flushToFormik(parsed);
1273
+ }
1274
+ };
1275
+ return /* @__PURE__ */ jsxs(FieldWrapper, {
1276
+ optional: field.optional ?? false,
1277
+ label,
1278
+ tooltipComponent,
1279
+ labelPosition,
1280
+ spaceCompact: spaceCompact ?? false,
1281
+ ...field.description !== void 0 && { description: field.description },
1282
+ children: [
1283
+ !isSentinel && /* @__PURE__ */ jsx("input", {
1284
+ "data-1p-ignore": true,
1285
+ className: cx("w-full", disabled && "disabled", (missing || error !== null) && "invalid"),
1286
+ name,
1287
+ value: text,
1288
+ type: "text",
1289
+ disabled,
1290
+ placeholder: field.placeholder ?? "DD-HH:MM:SS",
1291
+ onChange: handleChange,
1292
+ onFocus: handleFocus,
1293
+ onBlur: handleBlur
1294
+ }),
1295
+ error && /* @__PURE__ */ jsx("div", {
1296
+ className: "text-xs text-red-500 mt-1",
1297
+ children: error
1298
+ }),
1299
+ hasDisableCheckbox && /* @__PURE__ */ jsxs("label", {
1300
+ className: cx("flex items-center gap-2 mt-1", disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer"),
1301
+ children: [/* @__PURE__ */ jsx("input", {
1302
+ type: "checkbox",
1303
+ checked: isSentinel,
1304
+ disabled,
1305
+ onChange: (e) => handleDisableToggle(e.target.checked),
1306
+ className: cx("h-4 w-4 accent-(--theme-link)", disabled ? "cursor-not-allowed" : "cursor-pointer")
1307
+ }), /* @__PURE__ */ jsx("span", {
1308
+ className: "text-sm theme-text",
1309
+ children: field.disableLabel
1310
+ })]
1311
+ })
1312
+ ]
1313
+ });
1314
+ });
1315
+ //#endregion
1316
+ //#region src/form/Fields/RadioField.tsx
1317
+ function RadioField(props) {
1318
+ const { field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact, setFormDirty } = props;
1319
+ const { setFieldValue, setFieldTouched } = useFormikContext();
1320
+ const handleChange = (val) => {
1321
+ if (disabled) return;
1322
+ if (onChange) onChange(val);
1323
+ setFieldTouched(field.name, true);
1324
+ setFieldValue(field.name, val);
1325
+ setFormDirty(true);
1326
+ };
1327
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1328
+ optional: field.optional,
1329
+ label,
1330
+ tooltipComponent,
1331
+ labelPosition,
1332
+ spaceCompact,
1333
+ children: /* @__PURE__ */ jsx("div", {
1334
+ className: cx("flex", field.optionLabelPosition === "top" ? "flex-col" : "flex-row"),
1335
+ children: field.options?.map((option) => /* @__PURE__ */ jsxs("label", {
1336
+ className: "capitalize",
1337
+ children: [/* @__PURE__ */ jsx(Field, {
1338
+ className: cx("theme-input mr-1", disabled && "disabled", missing && "invalid"),
1339
+ name: field.name,
1340
+ type: "radio",
1341
+ value: option,
1342
+ disabled,
1343
+ onChange: (e) => {
1344
+ handleChange(e.target.value);
1345
+ }
1346
+ }), option]
1347
+ }, field.name + option))
1348
+ })
1349
+ });
1350
+ }
1351
+ //#endregion
1352
+ //#region src/form/Fields/LabelField.tsx
1353
+ function LabelField(props) {
1354
+ const { field, label } = props;
1355
+ return /* @__PURE__ */ jsx("div", {
1356
+ className: "flex items-center w-full",
1357
+ children: /* @__PURE__ */ jsx("h3", {
1358
+ style: field.size ? {
1359
+ fontSize: field.size.toString() + "px",
1360
+ whiteSpace: "pre-wrap"
1361
+ } : { whiteSpace: "pre-wrap" },
1362
+ className: cx("relative", "text-md", field.bold !== false ? "font-bold" : ""),
1363
+ children: field.text && field.text.toString().replace(/(\r)/g, "").replace(/(\\n)/g, "\n") || label
1364
+ })
1365
+ });
1366
+ }
1367
+ //#endregion
1368
+ //#region src/form/Fields/ColorField.tsx
1369
+ function ColorField(props) {
1370
+ const { field, label, labelPosition, onChange, tooltipComponent, spaceCompact } = props;
1371
+ const [fieldState] = useField(field.name);
1372
+ const { setFieldValue, setFieldTouched } = useFormikContext();
1373
+ const handleChange = (e) => {
1374
+ const val = e.target.value;
1375
+ if (onChange) onChange(val);
1376
+ setFieldTouched(field.name, true);
1377
+ setFieldValue(field.name, val);
1378
+ };
1379
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1380
+ optional: field.optional,
1381
+ label,
1382
+ tooltipComponent,
1383
+ labelPosition,
1384
+ spaceCompact,
1385
+ children: /* @__PURE__ */ jsx(Field, {
1386
+ className: "theme-input h-8 w-18 rounded border border-neutral-400 text-[14px] placeholder:text-xs",
1387
+ name: field.name,
1388
+ value: fieldState.value || "#fbbf24",
1389
+ type: "color",
1390
+ onChange: handleChange
1391
+ })
1392
+ });
1393
+ }
1394
+ //#endregion
1395
+ //#region src/form/Fields/MultiDropdownField.tsx
1396
+ function MultiDropdownField({ field, label, tooltipComponent, labelPosition, spaceCompact, disabled, missing, setFormDirty, onChange }) {
1397
+ let parentValue = field.parentValue;
1398
+ let options = field.options;
1399
+ if (field.depends_on) {
1400
+ parentValue = field.depends_on;
1401
+ if (!Array.isArray(field.options)) options = field.options[parentValue] || [];
1402
+ }
1403
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1404
+ optional: field.optional,
1405
+ label,
1406
+ tooltipComponent,
1407
+ labelPosition,
1408
+ spaceCompact,
1409
+ children: disabled ? /* @__PURE__ */ jsx(Field, {
1410
+ className: "theme-input h-7 w-full rounded border text-[14px] placeholder:text-xs",
1411
+ type: "search",
1412
+ name: field.name,
1413
+ disabled: true,
1414
+ onChange
1415
+ }, field.name) : /* @__PURE__ */ jsx(MultiSelectionDropdown, {
1416
+ className: "themee-input h-7 w-full rounded border text-[14px] flex items-center px-3 py-2",
1417
+ name: field.name,
1418
+ label: field.label || label,
1419
+ options: Array.isArray(options) ? options : [],
1420
+ setFormDirty,
1421
+ parentValue,
1422
+ onChange,
1423
+ secondaryField: typeof field.secondaryField === "string" ? field.secondaryField : void 0,
1424
+ invalid: missing
1425
+ }, field.name)
1426
+ });
1427
+ }
1428
+ //#endregion
1429
+ //#region src/form/Fields/CheckboxGroupField.tsx
1430
+ function impliedFrom(values, implies = {}) {
1431
+ const result = /* @__PURE__ */ new Set();
1432
+ for (const value of values) for (const target of implies[value] ?? []) result.add(target);
1433
+ return result;
1434
+ }
1435
+ function union(manual, forced) {
1436
+ return [...manual, ...[...forced].filter((v) => !manual.includes(v))];
1437
+ }
1438
+ function CheckboxGroupField({ field, label, labelPosition, missing, disabled, onChange, tooltipComponent, spaceCompact, setFormDirty }) {
1439
+ const [fieldState] = useField(field.name);
1440
+ const { setFieldValue, setFieldTouched } = useFormikContext();
1441
+ const implies = field.implies;
1442
+ const [manual, setManual] = useState(() => {
1443
+ const saved = fieldState.value || [];
1444
+ const impliedBySaved = impliedFrom(saved, implies);
1445
+ return saved.filter((v) => !impliedBySaved.has(v));
1446
+ });
1447
+ const forced = impliedFrom(manual, implies);
1448
+ const handleToggle = (value) => {
1449
+ if (disabled) return;
1450
+ const nextManual = manual.includes(value) ? manual.filter((v) => v !== value) : [...manual, value];
1451
+ const next = union(nextManual, impliedFrom(nextManual, implies));
1452
+ setManual(nextManual);
1453
+ setFieldTouched(field.name, true);
1454
+ setFieldValue(field.name, next);
1455
+ if (onChange) onChange(next);
1456
+ setFormDirty(true);
1457
+ };
1458
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1459
+ optional: field.optional,
1460
+ label,
1461
+ tooltipComponent,
1462
+ labelPosition,
1463
+ spaceCompact,
1464
+ children: /* @__PURE__ */ jsx("div", {
1465
+ className: "flex max-w-lg flex-col gap-1",
1466
+ children: field.options?.map((option) => {
1467
+ const locked = forced.has(option.value);
1468
+ const optionDisabled = disabled || locked;
1469
+ return /* @__PURE__ */ jsxs("label", {
1470
+ className: cx("flex items-start gap-2 rounded px-2 py-1 transition-colors", optionDisabled ? "cursor-not-allowed opacity-60" : "cursor-pointer hover:bg-(--theme-hover) has-[:focus-visible]:bg-(--theme-hover)"),
1471
+ children: [/* @__PURE__ */ jsx("input", {
1472
+ type: "checkbox",
1473
+ checked: manual.includes(option.value) || locked,
1474
+ disabled: optionDisabled,
1475
+ onChange: () => handleToggle(option.value),
1476
+ className: cx("mt-0.5 h-4 w-4 accent-(--theme-link)", optionDisabled ? "cursor-not-allowed" : "cursor-pointer", missing && "invalid")
1477
+ }), /* @__PURE__ */ jsxs("div", {
1478
+ className: "flex flex-col",
1479
+ children: [/* @__PURE__ */ jsx("span", {
1480
+ className: "font-medium theme-text",
1481
+ children: option.label
1482
+ }), option.description && /* @__PURE__ */ jsx("span", {
1483
+ className: "text-xs theme-muted-text leading-relaxed",
1484
+ children: option.description
1485
+ })]
1486
+ })]
1487
+ }, field.name + option.value);
1488
+ })
1489
+ })
1490
+ });
1491
+ }
1492
+ //#endregion
1493
+ //#region src/form/Fields/ObjectField.tsx
1494
+ function ObjectField({ field, label, tooltipComponent, missingFields, setFormDirty, workflowForm, labelPosition, spaceCompact }) {
1495
+ const [open, setOpen] = useState(field.collapsed !== void 0 ? !field.collapsed : true);
1496
+ const { values, setFieldValue, setFieldTouched } = useFormikContext();
1497
+ const meta = resolveMetaOverrides(field.options, labelPosition, spaceCompact ?? false);
1498
+ const HeaderElement = field.noCollapse ? React.Fragment : ControlledCollapsiblePanel;
1499
+ return /* @__PURE__ */ jsxs("div", {
1500
+ className: "flex flex-col w-full",
1501
+ children: [field.noCollapse && /* @__PURE__ */ jsx("div", {
1502
+ className: "flex items-center w-full mb-[15px]",
1503
+ children: /* @__PURE__ */ jsxs("h3", {
1504
+ className: "flex items-center gap-1 text-md font-bold",
1505
+ children: [
1506
+ label,
1507
+ " ",
1508
+ tooltipComponent
1509
+ ]
1510
+ })
1511
+ }), /* @__PURE__ */ jsx(HeaderElement, {
1512
+ open,
1513
+ setOpen,
1514
+ title: /* @__PURE__ */ jsx(GroupHeader, {
1515
+ open,
1516
+ setOpen,
1517
+ title: field.label || label
1518
+ }),
1519
+ children: /* @__PURE__ */ jsx("div", {
1520
+ className: "w-full",
1521
+ children: /* @__PURE__ */ jsx(FieldsFromOptions, {
1522
+ options: field.options,
1523
+ values,
1524
+ setFormDirty,
1525
+ setFieldValue,
1526
+ setFieldTouched,
1527
+ missingFields,
1528
+ workflowForm,
1529
+ labelPosition: meta.labelPosition,
1530
+ spaceCompact: meta.spaceCompact,
1531
+ parentInfo: {
1532
+ parentName: field.name,
1533
+ fieldNamePrefix: `${field.name}.`
1534
+ }
1535
+ })
1536
+ })
1537
+ })]
1538
+ });
1539
+ }
1540
+ //#endregion
1541
+ //#region src/form/Fields/StepField.tsx
1542
+ function StepField(_props) {
1543
+ return null;
1544
+ }
1545
+ //#endregion
1546
+ //#region src/form/Fields/BucketReadOnlyField.tsx
1547
+ function BucketReadOnlyField({ field, disabled, missing, labelPosition, setFormDirty }) {
1548
+ const { form: t } = useStrings();
1549
+ const [fieldState] = useField(field.name);
1550
+ const { setFieldTouched, setFieldValue, values } = useFormikContext();
1551
+ const accessFieldName = field.name?.replace(/readOnly$/, "bucketAccessWritable");
1552
+ const forced = fieldState.value === true && !!accessFieldName && getIn(values, accessFieldName) === false;
1553
+ return /* @__PURE__ */ jsx(FieldWrapper, {
1554
+ optional: true,
1555
+ label: t.readOnly,
1556
+ description: t.readOnlyDescription,
1557
+ labelPosition,
1558
+ children: /* @__PURE__ */ jsxs("div", {
1559
+ className: "flex flex-col gap-2",
1560
+ children: [/* @__PURE__ */ jsx(SwitchToggle, {
1561
+ onChange: (value) => {
1562
+ if (disabled) return;
1563
+ setFieldTouched(field.name, true);
1564
+ setFieldValue(field.name, value);
1565
+ setFormDirty(true);
1566
+ },
1567
+ value: fieldState.value === true,
1568
+ disabled,
1569
+ invalid: missing,
1570
+ yesLabel: t.readOnly,
1571
+ noLabel: t.readWrite
1572
+ }), /* @__PURE__ */ jsx("p", {
1573
+ className: cx("text-sm theme-muted-text max-w-[65ch]", !forced && "hidden"),
1574
+ children: t.readOnlyForced
1575
+ })]
1576
+ })
1577
+ });
1578
+ }
1579
+ //#endregion
1580
+ //#region src/form/fieldRegistry.tsx
1581
+ var CORE_FIELD_COMPONENTS = {
1582
+ string: StringField_default,
1583
+ password: StringField_default,
1584
+ number: NumberField,
1585
+ boolean: BooleanField,
1586
+ dropdown: DropdownField,
1587
+ textarea: TextAreaField,
1588
+ range: RangeField,
1589
+ duration: DurationField_default,
1590
+ radio: RadioField,
1591
+ label: LabelField,
1592
+ color: ColorField,
1593
+ "multi-dropdown": MultiDropdownField,
1594
+ "checkbox-group": CheckboxGroupField,
1595
+ object: ObjectField,
1596
+ step: StepField,
1597
+ "bucket-read-only": BucketReadOnlyField
1598
+ };
1599
+ var FieldRegistryContext = createContext({});
1600
+ /** Returns null for field types no registry knows. Per-form `fields` win over
1601
+ * the provider's `slots.formFields`, which win over the core registry. */
1602
+ function Registry(props) {
1603
+ const injected = useContext(FieldRegistryContext);
1604
+ const { formFields } = useSlots();
1605
+ const Component = injected[props.field.type] ?? formFields?.[props.field.type] ?? CORE_FIELD_COMPONENTS[props.field.type];
1606
+ if (!Component) return null;
1607
+ return /* @__PURE__ */ jsx(Suspense, {
1608
+ fallback: null,
1609
+ children: /* @__PURE__ */ jsx(Component, { ...props })
1610
+ });
1611
+ }
1612
+ //#endregion
1613
+ //#region src/form/Form.tsx
1614
+ /** Applies `$meta` overrides for `labelPosition` / `spaceCompact`. */
1615
+ function resolveMetaOverrides(options, labelPosition, spaceCompact) {
1616
+ return {
1617
+ labelPosition: options?.$meta?.labelPosition ?? labelPosition,
1618
+ spaceCompact: options?.$meta?.spaceCompact ?? spaceCompact
1619
+ };
1620
+ }
1621
+ /** Cheap signature of every list's length; gates the expensive collect walk. */
1622
+ function listLengthsSignature(options, values = {}, prefix = "") {
1623
+ if (!options || typeof options !== "object") return "";
1624
+ const parts = [];
1625
+ for (const [fieldName, field] of Object.entries(options)) {
1626
+ if (fieldName === "$meta" || !field || typeof field !== "object") continue;
1627
+ const fullName = prefix ? `${prefix}${fieldName}` : fieldName;
1628
+ if (field.type === "list") {
1629
+ const items = values?.[fieldName];
1630
+ const len = Array.isArray(items) ? items.length : 0;
1631
+ parts.push(`${fullName}:${len}`);
1632
+ const template = field.template || field.options;
1633
+ if (template && Array.isArray(items)) for (let i = 0; i < items.length; i++) parts.push(listLengthsSignature(template, items[i] || {}, `${fullName}[${i}].`));
1634
+ } else if (field.type === "group" || field.type === "object") {
1635
+ const groupItems = field.items || field.options;
1636
+ if (groupItems) {
1637
+ const nestedValues = values?.[fieldName] || {};
1638
+ parts.push(listLengthsSignature(groupItems, nestedValues, `${fullName}.`));
1639
+ }
1640
+ }
1641
+ }
1642
+ return parts.join("|");
1643
+ }
1644
+ /** Collects every field with a `default` for the form-level sync to track. */
1645
+ function collectFieldsWithDefaults(options, values = {}, prefix = "") {
1646
+ const result = [];
1647
+ if (!options || typeof options !== "object") return result;
1648
+ for (const [fieldName, field] of Object.entries(options)) {
1649
+ if (!field || typeof field !== "object") continue;
1650
+ if (fieldName === "$meta") continue;
1651
+ const fullName = prefix ? `${prefix}${fieldName}` : fieldName;
1652
+ if (field.type === "group" || field.type === "object") {
1653
+ const groupItems = field.items || field.options;
1654
+ if (groupItems) {
1655
+ const nestedValues = values?.[fieldName] || {};
1656
+ result.push(...collectFieldsWithDefaults(groupItems, nestedValues, `${fullName}.`));
1657
+ }
1658
+ continue;
1659
+ }
1660
+ if (field.type === "list") {
1661
+ const listTemplate = field.template || field.options;
1662
+ const listValues = values?.[fieldName];
1663
+ if (listTemplate && Array.isArray(listValues)) for (let i = 0; i < listValues.length; i++) {
1664
+ const itemValues = listValues[i] || {};
1665
+ result.push(...collectFieldsWithDefaults(listTemplate, itemValues, `${fullName}[${i}].`));
1666
+ }
1667
+ continue;
1668
+ }
1669
+ if (field.default !== void 0) result.push({
1670
+ name: fullName,
1671
+ defaultValue: field.default
1672
+ });
1673
+ }
1674
+ return result;
1675
+ }
1676
+ function defaultReferencesField(defaultValue, fieldPath) {
1677
+ if (typeof defaultValue !== "string" || !defaultValue.includes("${{")) return false;
1678
+ const escaped = fieldPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1679
+ return new RegExp(`\\binputs\\.${escaped}(?![\\w.[-])`).test(defaultValue);
1680
+ }
1681
+ function findSelfReferencingFieldNames(schema, values = {}) {
1682
+ return collectFieldsWithDefaults(schema, values).filter(({ name, defaultValue }) => defaultReferencesField(defaultValue, name)).map(({ name }) => name);
1683
+ }
1684
+ /**
1685
+ * Re-syncs each field's value when its resolved default changes between
1686
+ * renders, unless `meta.touched` (this session) or a synth-touched marker
1687
+ * (cross-session, set on first-seen when saved ≠ default) is set. Must be
1688
+ * remounted via `key` when the run/config context changes.
1689
+ */
1690
+ function DynamicDefaultsSync({ options }) {
1691
+ const { setFieldValue, getFieldMeta, values } = useFormikContext();
1692
+ const fieldsWithDefaults = useMemo(() => collectFieldsWithDefaults(options, values), [options, useMemo(() => listLengthsSignature(options, values), [options, values])]);
1693
+ const prevDefaultsRef = useRef(/* @__PURE__ */ new Map());
1694
+ const synthTouchedRef = useRef(/* @__PURE__ */ new Set());
1695
+ const fieldsWithDefaultsRef = useRef(null);
1696
+ if (!deepEqual(fieldsWithDefaultsRef.current, fieldsWithDefaults)) {
1697
+ fieldsWithDefaultsRef.current = fieldsWithDefaults;
1698
+ const currentNames = new Set(fieldsWithDefaults.map((f) => f.name));
1699
+ for (const name of prevDefaultsRef.current.keys()) if (!currentNames.has(name)) {
1700
+ prevDefaultsRef.current.delete(name);
1701
+ synthTouchedRef.current.delete(name);
1702
+ }
1703
+ for (const { name, defaultValue } of fieldsWithDefaults) {
1704
+ if (synthTouchedRef.current.has(name)) continue;
1705
+ if (getFieldMeta(name).touched) continue;
1706
+ const wasSeen = prevDefaultsRef.current.has(name);
1707
+ const serializedDefault = JSON.stringify(defaultValue ?? null);
1708
+ const prevDefault = prevDefaultsRef.current.get(name);
1709
+ prevDefaultsRef.current.set(name, serializedDefault);
1710
+ if (!wasSeen) {
1711
+ const currVal = JSON.stringify(getValueUsingPath(values, name));
1712
+ if (currVal !== void 0 && currVal !== serializedDefault) synthTouchedRef.current.add(name);
1713
+ continue;
1714
+ }
1715
+ if (prevDefault === serializedDefault) continue;
1716
+ if (defaultValue === null || defaultValue === void 0) continue;
1717
+ if (JSON.stringify(getValueUsingPath(values, name)) !== serializedDefault) setFieldValue(name, defaultValue);
1718
+ }
1719
+ }
1720
+ return null;
1721
+ }
1722
+ function GroupHeader({ children, open, setOpen, title }) {
1723
+ return /* @__PURE__ */ jsxs(SectionHeader, {
1724
+ className: "flex items-center justify-between pb-1 mb-2 border-b",
1725
+ children: [/* @__PURE__ */ jsxs("div", {
1726
+ className: cx("w-full flex items-center transform ease-in transition cursor-pointer"),
1727
+ onClick: () => setOpen((open) => !open),
1728
+ children: [/* @__PURE__ */ jsx(AngleRightIcon, { className: cx(open && "transform rotate-90 ", "px-1 text-[1.25rem] transition ease-in ") }), /* @__PURE__ */ jsx("span", { children: title })]
1729
+ }), children]
1730
+ });
1731
+ }
1732
+ function deleteFieldByPath(obj, path) {
1733
+ if (!path) return;
1734
+ const parts = path.replaceAll("[", ".").replaceAll("]", "").split(".");
1735
+ const fieldToRemove = parts.pop();
1736
+ if (!fieldToRemove) {
1737
+ console.error("Invalid path");
1738
+ return;
1739
+ }
1740
+ const parent = parts.reduce((acc, curr) => {
1741
+ if (acc && typeof acc === "object") return acc[curr];
1742
+ return {};
1743
+ }, obj);
1744
+ if (parent && typeof parent === "object" && Object.prototype.hasOwnProperty.call(parent, fieldToRemove)) delete parent[fieldToRemove];
1745
+ }
1746
+ function getClosestParentIndex(parentPath) {
1747
+ for (let i = parentPath.length - 1; i >= 0; i--) if (parentPath[i] === "]") {
1748
+ let j = i - 1;
1749
+ while (j >= 0 && parentPath[j] !== "[") j--;
1750
+ return parseInt(parentPath.slice(j + 1, i));
1751
+ }
1752
+ }
1753
+ function getInstanceTypesForForm(instances) {
1754
+ return Object.keys(instances).reduce((acc, key) => {
1755
+ const validInstances = [];
1756
+ Object.keys(instances[key]).forEach((item) => {
1757
+ const instance = instances[key][item];
1758
+ const secondaryValue = [
1759
+ instances[key][item].Arch,
1760
+ !!instance.AcceleratedNetworking,
1761
+ !!instance.AcceleratedNetworking,
1762
+ !!instance.LocalDiskSizeGb,
1763
+ !!instance.isFlex
1764
+ ];
1765
+ const flexLabel = instance.isFlex ? ", Flex" : "";
1766
+ if (instance.LocalDiskSizeGb) validInstances.push({
1767
+ value: item,
1768
+ label: `${item} (${instance.vCPUs} vCPUs, ${instance["Mem (GB)"]} GB Memory, ${instance.Arch} , ${instance.LocalDiskSizeGb} GB Local Disk${flexLabel})`,
1769
+ secondaryValue
1770
+ });
1771
+ else validInstances.push({
1772
+ value: item,
1773
+ label: `${item} (${instance.vCPUs} vCPUs, ${instance["Mem (GB)"]} GB Memory, ${instance.Arch}${flexLabel})`,
1774
+ secondaryValue
1775
+ });
1776
+ });
1777
+ return {
1778
+ ...acc,
1779
+ [key]: validInstances
1780
+ };
1781
+ }, {});
1782
+ }
1783
+ function StatusBlock({ status }) {
1784
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", {
1785
+ "data-tooltip-id": TOOLTIP_ID,
1786
+ "data-tooltip-content": status ? "Storage has been attached." : "Attaching the storage to cluster...",
1787
+ children: status ? /* @__PURE__ */ jsx(SuccessCheckmark, {}) : /* @__PURE__ */ jsx(Loader, {
1788
+ size: 13,
1789
+ full: false
1790
+ })
1791
+ }) });
1792
+ }
1793
+ function MultiSelectionDropdown({ name, label = "", invalid = false, options: initialOptions = [], setFormDirty, onChange, parentValue }) {
1794
+ const [field] = useField(name);
1795
+ const { setFieldValue } = useFormikContext();
1796
+ const options = useMemo(() => {
1797
+ return initialOptions.map((option) => {
1798
+ const op = typeof option === "string" ? {
1799
+ label: option,
1800
+ value: option,
1801
+ selected: false
1802
+ } : { ...option };
1803
+ if (field.value?.includes(op.value)) op.selected = true;
1804
+ return op;
1805
+ });
1806
+ }, [initialOptions, field.value]);
1807
+ const handleOptionSelected = (selectedValue) => {
1808
+ let selected = [];
1809
+ if (field.value) selected = [...field.value];
1810
+ selected.push(selectedValue);
1811
+ setFieldValue(name, selected);
1812
+ if (onChange) onChange(options);
1813
+ setFormDirty(true);
1814
+ };
1815
+ const handleRemoveOption = (key) => {
1816
+ setFieldValue(name, [...field.value.filter((item) => item !== key)]);
1817
+ if (onChange) onChange(options);
1818
+ setFormDirty(true);
1819
+ };
1820
+ const prevParent = usePrevious(parentValue);
1821
+ useEffect(() => {
1822
+ if (prevParent && parentValue && prevParent !== parentValue) setFieldValue(name, []);
1823
+ }, [parentValue]);
1824
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CustomListbox, {
1825
+ options,
1826
+ type: label.toLowerCase(),
1827
+ handleOptionSelected,
1828
+ className: "mb-3",
1829
+ invalid,
1830
+ closeOnSelect: false
1831
+ }), /* @__PURE__ */ jsx(Table, { children: field.value && field.value.length > 0 ? options.filter((option) => option.selected).map((option, index) => {
1832
+ return /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx(Table.Item, {
1833
+ className: "w-full",
1834
+ children: option?.label
1835
+ }), /* @__PURE__ */ jsx(Table.Item, { children: /* @__PURE__ */ jsx(TrashIcon, {
1836
+ className: "link mr-4",
1837
+ onClick: () => handleRemoveOption(option.value)
1838
+ }) })] }, index);
1839
+ }) : /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsxs(Table.Item, { children: [
1840
+ "No ",
1841
+ label !== "" ? label.toLowerCase() : "options",
1842
+ " selected"
1843
+ ] }) }) })] });
1844
+ }
1845
+ var InputField = React.memo(function InputField({ label, field, setFormDirty, onChange, disabled = false, labelPosition = "left", missingFields = [], computeOn, spaceCompact = false, workflowForm = false, setFieldValue, setFieldTouched, values, currentValue }) {
1846
+ const prevField = useRef(field);
1847
+ const fieldObj = useMemo(() => {
1848
+ if (deepEqual(prevField.current, field)) return prevField.current;
1849
+ prevField.current = field;
1850
+ return { ...field };
1851
+ }, [field]);
1852
+ const tooltipComponent = useMemo(() => {
1853
+ if (!fieldObj.tooltip) return null;
1854
+ return /* @__PURE__ */ jsx(TooltipInfo, {
1855
+ className: "pr-2",
1856
+ place: "top",
1857
+ text: typeof fieldObj.tooltip === "string" ? fieldObj.tooltip.replace(/\r/g, "") : fieldObj.tooltip.join("\n")
1858
+ });
1859
+ }, [fieldObj.tooltip]);
1860
+ return /* @__PURE__ */ jsx(Registry, {
1861
+ field: fieldObj,
1862
+ label,
1863
+ labelPosition,
1864
+ missing: missingFields.includes(fieldObj.name),
1865
+ missingFields,
1866
+ values,
1867
+ setFormDirty,
1868
+ onChange,
1869
+ disabled,
1870
+ computeOn,
1871
+ spaceCompact,
1872
+ tooltipComponent,
1873
+ workflowForm,
1874
+ setFieldTouched,
1875
+ setFieldValue,
1876
+ currentValue
1877
+ });
1878
+ }, (prev, next) => {
1879
+ if (!deepEqual(prev.field, next.field)) return false;
1880
+ for (const key of Object.keys(prev)) {
1881
+ if (key === "field" || key === "values") continue;
1882
+ if (prev[key] !== next[key]) return false;
1883
+ }
1884
+ return true;
1885
+ });
1886
+ function FormikStateBridge({ onChange }) {
1887
+ const { values } = useFormikContext();
1888
+ const prevEmitted = useRef(null);
1889
+ useEffect(() => {
1890
+ const { editorKeyPostfix: _, ...next } = values;
1891
+ if (prevEmitted.current !== null && prevEmitted.current !== void 0 && deepEqual(prevEmitted.current, next)) return;
1892
+ prevEmitted.current = next;
1893
+ onChange(next);
1894
+ }, [values, onChange]);
1895
+ return null;
1896
+ }
1897
+ function DirtyStateBridge({ setFormDirty }) {
1898
+ const { dirty } = useFormikContext();
1899
+ useEffect(() => {
1900
+ setFormDirty(dirty);
1901
+ }, [dirty, setFormDirty]);
1902
+ return null;
1903
+ }
1904
+ /** Three-tier cache: no expressions → raw pass-through; input-dep expressions → re-parse on dep change; org-var/path expressions → parse once. */
1905
+ function useFieldParse(optionsField, values, arrayIndex) {
1906
+ const c = useRef({
1907
+ lastOptField: null,
1908
+ convertedField: null,
1909
+ inputDeps: /* @__PURE__ */ new Set(),
1910
+ hasExpressions: false,
1911
+ lastRelevant: {},
1912
+ lastIndex: void 0,
1913
+ result: null
1914
+ }).current;
1915
+ if (optionsField !== c.lastOptField) {
1916
+ c.lastOptField = optionsField;
1917
+ c.convertedField = convertToDynamicForm(optionsField);
1918
+ const { inputDeps, hasExpressions } = extractInputDeps(c.convertedField);
1919
+ c.inputDeps = inputDeps;
1920
+ c.hasExpressions = hasExpressions;
1921
+ c.result = null;
1922
+ }
1923
+ if (!c.hasExpressions) return optionsField;
1924
+ if (c.inputDeps.size === 0) {
1925
+ if (c.result !== null) return c.result;
1926
+ }
1927
+ if (c.result !== null) {
1928
+ let changed = arrayIndex !== c.lastIndex;
1929
+ if (!changed) {
1930
+ for (const key of c.inputDeps) if (!deepEqual(values[key], c.lastRelevant[key])) {
1931
+ changed = true;
1932
+ break;
1933
+ }
1934
+ }
1935
+ if (!changed) return c.result;
1936
+ }
1937
+ c.result = parseStringsOfObj({
1938
+ inputs: values,
1939
+ obj: c.convertedField,
1940
+ orgVars: {},
1941
+ index: arrayIndex
1942
+ });
1943
+ c.lastIndex = arrayIndex;
1944
+ c.lastRelevant = {};
1945
+ for (const key of c.inputDeps) c.lastRelevant[key] = values[key];
1946
+ return c.result;
1947
+ }
1948
+ var FormField = React.memo(function FormField({ id, optionsField, fieldName, values, setFormDirty, setFieldValue, setFieldTouched, parentInfo, labelPosition = "left", missingFields = [], spaceCompact = false, workflowForm = false }) {
1949
+ const parsedField = useFieldParse(optionsField, values, parentInfo?.arrayIndex);
1950
+ const field = parentInfo ? parsedField : optionsField;
1951
+ if (field === null || field === void 0) return field;
1952
+ const fieldNamePrefix = parentInfo?.fieldNamePrefix || "";
1953
+ const fieldObj = {
1954
+ ...field,
1955
+ label: field.label || fieldName.charAt(0).toUpperCase() + fieldName.slice(1),
1956
+ name: fieldNamePrefix + fieldName,
1957
+ optional: resolvedFlag(field.optional) ?? field.default !== void 0
1958
+ };
1959
+ if (!fieldObj.name || fieldName === "v3") return null;
1960
+ if (field.hidden === true || !field.type) {
1961
+ if (resolvedFlag(field.ignore) && !workflowForm) deleteFieldByPath(values, fieldObj.name);
1962
+ return null;
1963
+ }
1964
+ if (!field.type && field.options) fieldObj.type = "dropdown";
1965
+ let onChange;
1966
+ if (field.one_must_be_true && parentInfo?.onChange) {
1967
+ const parentOnChange = parentInfo.onChange;
1968
+ const parentArrayIndex = parentInfo.arrayIndex ?? 0;
1969
+ onChange = (val) => parentOnChange(fieldName, parentArrayIndex, fieldObj.options?.offOption || false, fieldObj.options?.onOption || true, val);
1970
+ }
1971
+ if (field.show_if !== void 0 || field.show_if_not !== void 0) {
1972
+ let index;
1973
+ if (parentInfo) if (!parentInfo?.arrayIndex) index = getClosestParentIndex(parentInfo.fieldNamePrefix);
1974
+ else index = parentInfo.arrayIndex;
1975
+ let shouldShowField = true;
1976
+ if (field.show_if !== void 0) shouldShowField = !!getParentValue(index, field.show_if, values, "", field);
1977
+ if (shouldShowField && field.show_if_not !== void 0) shouldShowField = !getParentValue(index, field.show_if_not, values, "", field);
1978
+ if (!shouldShowField) {
1979
+ if (!workflowForm) deleteFieldByPath(values, fieldObj.name);
1980
+ return null;
1981
+ }
1982
+ }
1983
+ if (field.depends_on) {
1984
+ if (parentInfo?.arrayIndex !== void 0) fieldObj.depends_on = field.depends_on.replace("[index]", `[${parentInfo.arrayIndex}]`);
1985
+ }
1986
+ if (field.enable_if && field.disabled === false) {
1987
+ if (typeof field.enable_if === "string") {
1988
+ let path = field.enable_if;
1989
+ if (parentInfo?.arrayIndex !== void 0) path = field.enable_if.replace("[index]", `[${parentInfo.arrayIndex}]`);
1990
+ if (getValueUsingPath(values, path) === false) fieldObj.disabled = true;
1991
+ }
1992
+ }
1993
+ if (field.type === "group") {
1994
+ const hideHeader = field.noCollapse;
1995
+ const HeaderElement = hideHeader ? React.Fragment : UncontrolledCollapsiblePanel;
1996
+ const meta = resolveMetaOverrides(field.options, labelPosition, spaceCompact);
1997
+ return /* @__PURE__ */ jsx("div", {
1998
+ className: "flex flex-col w-full",
1999
+ children: /* @__PURE__ */ jsx(HeaderElement, {
2000
+ ...!hideHeader && {
2001
+ title: (open, setOpen) => /* @__PURE__ */ jsx(GroupHeader, {
2002
+ open,
2003
+ setOpen,
2004
+ title: field.label
2005
+ }),
2006
+ initialState: field.collapsed !== void 0 ? !field.collapsed : true
2007
+ },
2008
+ children: /* @__PURE__ */ jsx("div", {
2009
+ className: "w-full",
2010
+ children: /* @__PURE__ */ jsx(FieldsFromOptions, {
2011
+ options: field.options,
2012
+ setFormDirty,
2013
+ setFieldValue,
2014
+ setFieldTouched,
2015
+ values,
2016
+ parentInfo,
2017
+ workflowForm,
2018
+ labelPosition: meta.labelPosition,
2019
+ spaceCompact: meta.spaceCompact,
2020
+ missingFields
2021
+ })
2022
+ })
2023
+ })
2024
+ }, fieldObj.name);
2025
+ }
2026
+ if (typeof field.type === "object" && field.depends_on) {
2027
+ const parentValue = getValueUsingPath(values, field.depends_on);
2028
+ if (!field.type[parentValue]) return null;
2029
+ fieldObj.type = field.type[parentValue];
2030
+ }
2031
+ if (field.type === "range" && field.depends_on) {
2032
+ const parentValue = getValueUsingPath(values, field.depends_on);
2033
+ if (typeof field?.min === "object" && typeof field?.max === "object") {
2034
+ fieldObj.min = field.min[parentValue];
2035
+ fieldObj.max = field.max[parentValue];
2036
+ }
2037
+ }
2038
+ if (field.resetOnChange) {
2039
+ const parentValue = getValueUsingPath(values, field.resetOnChange);
2040
+ const prevParentValue = field.prevParentValue;
2041
+ if (prevParentValue !== void 0 && prevParentValue !== parentValue) deleteFieldByPath(values, fieldObj.name);
2042
+ field.prevParentValue = parentValue;
2043
+ }
2044
+ if (field.secondaryField) if (Array.isArray(field.secondaryField)) fieldObj.secondaryField = field.secondaryField.map((secondaryField) => fieldNamePrefix + secondaryField);
2045
+ else fieldObj.secondaryField = fieldNamePrefix + field.secondaryField;
2046
+ return /* @__PURE__ */ jsx("div", {
2047
+ className: cx("flex w-full", labelPosition === "left" ? "mb-[15px]" : "mb-[5px]"),
2048
+ children: /* @__PURE__ */ jsx(InputField, {
2049
+ field: fieldObj,
2050
+ label: fieldObj.label,
2051
+ setFormDirty,
2052
+ setFieldValue,
2053
+ setFieldTouched,
2054
+ values,
2055
+ currentValue: getValueUsingPath(values, fieldObj.name),
2056
+ onChange,
2057
+ disabled: fieldObj.disabled,
2058
+ computeOn: parentInfo?.computeOn || fieldObj.computeOn,
2059
+ labelPosition,
2060
+ missingFields,
2061
+ spaceCompact,
2062
+ workflowForm
2063
+ })
2064
+ }, `field-${id}`);
2065
+ }, (prev, next) => {
2066
+ if (!deepEqual(prev.optionsField, next.optionsField)) return false;
2067
+ if (prev.values !== next.values) return false;
2068
+ if (!deepEqual(prev.parentInfo, next.parentInfo)) return false;
2069
+ if (!deepEqual(prev.missingFields, next.missingFields)) return false;
2070
+ if (prev.labelPosition !== next.labelPosition) return false;
2071
+ if (prev.spaceCompact !== next.spaceCompact) return false;
2072
+ if (prev.workflowForm !== next.workflowForm) return false;
2073
+ return true;
2074
+ });
2075
+ function FieldsFromOptions({ options = {}, values, setFormDirty, setFieldValue, setFieldTouched, parentInfo, labelPosition = "left", missingFields = [], spaceCompact = false, workflowForm = false }) {
2076
+ return Object.keys(options).map((fieldName, idx) => /* @__PURE__ */ jsx(FormField, {
2077
+ id: idx,
2078
+ optionsField: options[fieldName],
2079
+ fieldName,
2080
+ values,
2081
+ setFormDirty,
2082
+ setFieldValue,
2083
+ setFieldTouched,
2084
+ parentInfo,
2085
+ labelPosition,
2086
+ missingFields,
2087
+ spaceCompact,
2088
+ workflowForm
2089
+ }, idx));
2090
+ }
2091
+ var noop = () => {};
2092
+ function DynamicFormContent({ options, setValues, setFormDirty, labelPosition, missingFields, spaceCompact, organizationVariables, workflowForm, onSubmit, submitLabel, values, contextKey }) {
2093
+ const { setFieldValue, setFieldTouched } = useFormikContext();
2094
+ const opts = useParsedOpts(options, values, organizationVariables);
2095
+ const handleChange = useCallback((state) => {
2096
+ if (setValues) setValues(state);
2097
+ }, [setValues]);
2098
+ const wizardConfig = parseWizardConfig(opts);
2099
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2100
+ /* @__PURE__ */ jsx(DirtyStateBridge, { setFormDirty }),
2101
+ /* @__PURE__ */ jsx(FormikStateBridge, { onChange: handleChange }),
2102
+ workflowForm && /* @__PURE__ */ jsx(DynamicDefaultsSync, { options: opts }, contextKey ?? ""),
2103
+ wizardConfig !== null && wizardConfig ? /* @__PURE__ */ jsx(WizardContainer, {
2104
+ wizardConfig,
2105
+ values,
2106
+ onChange: handleChange,
2107
+ onSubmit,
2108
+ className: "w-full",
2109
+ ...resolveMetaOverrides(options, labelPosition, spaceCompact),
2110
+ missingFields,
2111
+ workflowForm,
2112
+ setFieldValue,
2113
+ setFieldTouched
2114
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FieldsFromOptions, {
2115
+ ...resolveMetaOverrides(options, labelPosition, spaceCompact),
2116
+ options: opts,
2117
+ values,
2118
+ setFormDirty,
2119
+ setFieldValue,
2120
+ setFieldTouched,
2121
+ missingFields,
2122
+ workflowForm
2123
+ }), onSubmit !== void 0 && !workflowForm && /* @__PURE__ */ jsx("div", {
2124
+ className: "mt-4",
2125
+ children: /* @__PURE__ */ jsx("input", {
2126
+ type: "submit",
2127
+ className: "btn btn-info",
2128
+ value: submitLabel
2129
+ })
2130
+ })] })
2131
+ ] });
2132
+ }
2133
+ var NO_FIELDS = {};
2134
+ function DynamicForm({ formJSONs: options = {}, reinitialize = false, initialValues, setValues, setFormDirty = noop, formikRef, labelPosition = "left", missingFields = [], spaceCompact = false, organizationVariables, needsOrganizationVariables = false, onSubmit = void 0, submitLabel = "Submit", className = "w-full", workflowForm = false, contextKey, skipValueParse = false, fields = NO_FIELDS }) {
2135
+ const [parseReady, setParseReady] = useState(parseStringsOfObjReady);
2136
+ useEffect(() => {
2137
+ initializeParseStringsOfObj();
2138
+ return callWhenParserInitialized(setParseReady);
2139
+ }, []);
2140
+ if (!parseReady) return /* @__PURE__ */ jsx(Loader, {});
2141
+ const parsedInitVals = skipValueParse ? initialValues : initialValues && parseStringsOfObj({
2142
+ inputs: initialValues,
2143
+ obj: initialValues,
2144
+ orgVars: organizationVariables
2145
+ });
2146
+ return /* @__PURE__ */ jsx(FieldRegistryContext.Provider, {
2147
+ value: fields,
2148
+ children: /* @__PURE__ */ jsx("div", {
2149
+ className,
2150
+ children: (!needsOrganizationVariables || organizationVariables) && initialValues && /* @__PURE__ */ jsx(Formik, {
2151
+ enableReinitialize: reinitialize,
2152
+ initialValues: parsedInitVals,
2153
+ onSubmit: onSubmit ?? (() => {}),
2154
+ onReset: () => {
2155
+ setFormDirty(false);
2156
+ },
2157
+ innerRef: formikRef,
2158
+ children: ({ values }) => /* @__PURE__ */ jsx(Form, {
2159
+ className: "w-full text-sm",
2160
+ children: /* @__PURE__ */ jsx(DynamicFormContent, {
2161
+ values,
2162
+ options,
2163
+ setValues,
2164
+ setFormDirty,
2165
+ labelPosition,
2166
+ missingFields,
2167
+ spaceCompact,
2168
+ organizationVariables,
2169
+ workflowForm,
2170
+ onSubmit,
2171
+ submitLabel,
2172
+ contextKey
2173
+ })
2174
+ })
2175
+ })
2176
+ })
2177
+ });
2178
+ }
2179
+ //#endregion
2180
+ //#region src/form/SpecialTypes/DropdownWrapper.tsx
2181
+ function DropdownWrapper({ options, onChange, fieldObj, setFormDirty, invalid = false, loading = false, disabled = void 0, allowCustomValue = void 0, currentValue, setFieldValue, setFieldTouched }) {
2182
+ return /* @__PURE__ */ jsx(FormikCustomDropdown_default, {
2183
+ invalid,
2184
+ className: "w-full",
2185
+ onChange,
2186
+ loading,
2187
+ setFormDirty,
2188
+ options,
2189
+ disabled: disabled ?? fieldObj.disabled ?? false,
2190
+ placeholder: getPlaceholder(fieldObj.placeholder, typeof fieldObj.default === "string" ? fieldObj.default : void 0),
2191
+ name: fieldObj.name,
2192
+ ariaLabel: fieldObj.label,
2193
+ parentValue: fieldObj.parentValue,
2194
+ secondaryField: fieldObj.secondaryField,
2195
+ resetOnChange: fieldObj.resetOnChange,
2196
+ value: fieldObj.value,
2197
+ autoselect: fieldObj.autoselect,
2198
+ allowCustomValue: allowCustomValue ?? fieldObj.allowCustomValue,
2199
+ customValueLabel: fieldObj.customValueLabel,
2200
+ currentValue,
2201
+ setFieldValue,
2202
+ setFieldTouched
2203
+ });
2204
+ }
2205
+ //#endregion
2206
+ //#region src/form/SpecialTypes/FormikMultiSelectDropdown.tsx
2207
+ function FormikMultiSelectDropdown({ name, options, setFormDirty, onChange, disabled = false, loading = false, invalid = false, placeholder, compareBy }) {
2208
+ const [field] = useField(name);
2209
+ const { setFieldValue, setFieldTouched } = useFormikContext();
2210
+ const handleChange = (next) => {
2211
+ setFieldValue(name, next);
2212
+ setFieldTouched(name, true);
2213
+ setFormDirty(true);
2214
+ onChange?.(next);
2215
+ };
2216
+ return /* @__PURE__ */ jsx(MultiSelectDropdown, {
2217
+ textBoxClassName: invalid ? "invalid" : void 0,
2218
+ options,
2219
+ value: Array.isArray(field.value) ? field.value : [],
2220
+ onChange: handleChange,
2221
+ disabled,
2222
+ loading,
2223
+ placeholder,
2224
+ compareBy
2225
+ });
2226
+ }
2227
+ //#endregion
2228
+ //#region src/form/utils/pwResolver.ts
2229
+ function resolvePwString(raw, options, fallbackUsername, opts) {
2230
+ let inputForm = null;
2231
+ let owner;
2232
+ let name;
2233
+ if (typeof raw === "string" && raw.startsWith("pw://")) {
2234
+ const parts = raw.slice(5).split("/");
2235
+ if (parts.length === 1 && parts[0]) {
2236
+ inputForm = "shorthand";
2237
+ name = parts[0];
2238
+ owner = fallbackUsername;
2239
+ } else if (parts.length === 2 && parts[0] && parts[1]) {
2240
+ inputForm = "full";
2241
+ owner = parts[0];
2242
+ name = parts[1];
2243
+ }
2244
+ } else if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
2245
+ const obj = raw;
2246
+ if (typeof obj.uri === "string" && obj.uri.startsWith("pw://")) {
2247
+ const parts = obj.uri.slice(5).split("/");
2248
+ if (parts.length === 1 && parts[0]) {
2249
+ inputForm = "shorthand";
2250
+ name = parts[0];
2251
+ owner = fallbackUsername;
2252
+ } else if (parts.length === 2 && parts[0] && parts[1]) {
2253
+ inputForm = "full";
2254
+ owner = parts[0];
2255
+ name = parts[1];
2256
+ }
2257
+ } else if (typeof obj.name === "string") {
2258
+ name = obj.name;
2259
+ const ownerVal = typeof obj.user === "string" ? obj.user : typeof obj.namespace === "string" ? obj.namespace : void 0;
2260
+ if (obj.type === "managed-cluster" || !ownerVal) {
2261
+ inputForm = "shorthand";
2262
+ owner = fallbackUsername;
2263
+ } else {
2264
+ inputForm = "full";
2265
+ owner = ownerVal;
2266
+ }
2267
+ } else if (typeof obj.id === "string" && obj.id) {
2268
+ inputForm = "shorthand";
2269
+ name = obj.id;
2270
+ owner = fallbackUsername;
2271
+ }
2272
+ }
2273
+ if (!inputForm || !name || !owner) return raw;
2274
+ const special = opts.specialCase?.(name, owner);
2275
+ if (special !== void 0) return special;
2276
+ const find = (pred) => {
2277
+ for (const category of options) for (const opt of category.options) if (opt.value && pred(opt.value)) return opt.value;
2278
+ };
2279
+ if (inputForm === "full") return find((v) => v.name === name && v[opts.ownerKey] === owner) ?? raw;
2280
+ const managed = find((v) => v.name === name && v.type === "managed-cluster");
2281
+ if (managed) return managed;
2282
+ const ownedByCaller = find((v) => v.name === name && v[opts.ownerKey] === fallbackUsername);
2283
+ if (ownedByCaller) return ownedByCaller;
2284
+ const sharedWithCaller = find((v) => v.name === name && typeof v[opts.ownerKey] === "string" && v[opts.ownerKey] !== fallbackUsername);
2285
+ if (sharedWithCaller) return sharedWithCaller;
2286
+ return raw;
2287
+ }
2288
+ function resolvePwValue(currentValue, options, fallbackUsername, opts) {
2289
+ if (Array.isArray(currentValue)) {
2290
+ let changed = false;
2291
+ const next = currentValue.map((v) => {
2292
+ const resolved = resolvePwString(v, options, fallbackUsername, opts);
2293
+ if (resolved !== v) changed = true;
2294
+ return resolved;
2295
+ });
2296
+ return changed ? next : currentValue;
2297
+ }
2298
+ return resolvePwString(currentValue, options, fallbackUsername, opts);
2299
+ }
2300
+ //#endregion
2301
+ //#region src/form/Fields/ResourceOptionIcon.tsx
2302
+ function ResourceOptionIcon({ imageUrl, fallbackIcon, alt, variant = "success", dotSize = 6 }) {
2303
+ return /* @__PURE__ */ jsxs("span", {
2304
+ className: "flex items-center gap-1.5 shrink-0",
2305
+ children: [/* @__PURE__ */ jsx(StatusDot, {
2306
+ variant,
2307
+ size: dotSize
2308
+ }), /* @__PURE__ */ jsx("img", {
2309
+ src: imageUrl || fallbackIcon,
2310
+ alt,
2311
+ className: "h-4 w-4 object-contain",
2312
+ onError: (e) => {
2313
+ e.currentTarget.src = fallbackIcon;
2314
+ }
2315
+ })]
2316
+ });
2317
+ }
2318
+ //#endregion
2319
+ export { DropdownWrapper, DynamicDefaultsSync, DynamicForm, FLEX_MAX_DURATION_RANGE, FLEX_WAIT_TIME_RANGE, FieldRegistryContext, FieldWrapper, FieldsFromOptions, FormikCustomDropdown_default as FormikCustomDropdown, FormikCustomInput, FormikMultiSelectDropdown, FormikNumericInput, GroupHeader, MultiSelectionDropdown, NumberField, Registry, ResourceOptionIcon, STANDARD_MAX_DURATION_RANGE, StatusBlock, applySecondaryField, collectFieldsWithDefaults, collectPartitionDurationIssues, enforceOneMustBeTrue, findSelfReferencingFieldNames, flattenGroups, formatSecondsAsSlurmDuration, getInstanceTypesForForm, getInvalidDurationPaths, impureSetValueFromPath, initializeValues, parseSlurmDuration, resolveMetaOverrides, resolvePwString, resolvePwValue, resolvedFlag, setDurationValidity, useParsedOpts };