@scm-manager/ui-forms 2.40.2-SNAPSHOT-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/.storybook/RemoveThemesPlugin.js +57 -0
  2. package/.storybook/main.js +92 -0
  3. package/.storybook/preview-head.html +26 -0
  4. package/.storybook/preview.js +72 -0
  5. package/.turbo/turbo-build.log +15 -0
  6. package/build/index.d.ts +124 -0
  7. package/build/index.js +639 -0
  8. package/build/index.mjs +602 -0
  9. package/package.json +50 -0
  10. package/src/ConfigurationForm.tsx +54 -0
  11. package/src/Form.stories.mdx +160 -0
  12. package/src/Form.tsx +164 -0
  13. package/src/FormRow.tsx +37 -0
  14. package/src/ScmFormContext.tsx +42 -0
  15. package/src/base/Control.tsx +34 -0
  16. package/src/base/Field.tsx +33 -0
  17. package/src/base/field-message/FieldMessage.tsx +34 -0
  18. package/src/base/help/Help.tsx +36 -0
  19. package/src/base/label/Label.tsx +33 -0
  20. package/src/checkbox/Checkbox.stories.mdx +26 -0
  21. package/src/checkbox/Checkbox.tsx +85 -0
  22. package/src/checkbox/CheckboxField.tsx +39 -0
  23. package/src/checkbox/ControlledCheckboxField.stories.mdx +36 -0
  24. package/src/checkbox/ControlledCheckboxField.tsx +76 -0
  25. package/src/index.ts +27 -0
  26. package/src/input/ControlledInputField.stories.mdx +36 -0
  27. package/src/input/ControlledInputField.tsx +77 -0
  28. package/src/input/ControlledSecretConfirmationField.stories.mdx +39 -0
  29. package/src/input/ControlledSecretConfirmationField.tsx +121 -0
  30. package/src/input/Input.stories.mdx +22 -0
  31. package/src/input/Input.tsx +46 -0
  32. package/src/input/InputField.stories.mdx +22 -0
  33. package/src/input/InputField.tsx +60 -0
  34. package/src/resourceHooks.ts +155 -0
  35. package/src/select/ControlledSelectField.tsx +77 -0
  36. package/src/select/Select.tsx +43 -0
  37. package/src/select/SelectField.tsx +59 -0
  38. package/src/variants.ts +27 -0
  39. package/tsconfig.json +3 -0
package/build/index.js ADDED
@@ -0,0 +1,639 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ ConfigurationForm: () => ConfigurationForm_default,
30
+ Form: () => Form_default,
31
+ useCreateResource: () => useCreateResource,
32
+ useDeleteResource: () => useDeleteResource,
33
+ useUpdateResource: () => useUpdateResource
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // src/Form.tsx
38
+ var import_react18 = __toESM(require("react"));
39
+ var import_react_hook_form5 = require("react-hook-form");
40
+ var import_ui_components4 = require("@scm-manager/ui-components");
41
+
42
+ // src/ScmFormContext.tsx
43
+ var import_react = __toESM(require("react"));
44
+ var ScmFormContext = import_react.default.createContext(null);
45
+ function ScmFormContextProvider({ children, ...props }) {
46
+ return /* @__PURE__ */ import_react.default.createElement(ScmFormContext.Provider, {
47
+ value: props
48
+ }, children);
49
+ }
50
+ function useScmFormContext() {
51
+ return (0, import_react.useContext)(ScmFormContext);
52
+ }
53
+
54
+ // src/Form.tsx
55
+ var import_react_i18next = require("react-i18next");
56
+ var import_ui_buttons = require("@scm-manager/ui-buttons");
57
+
58
+ // src/FormRow.tsx
59
+ var import_react2 = __toESM(require("react"));
60
+ var import_classnames = __toESM(require("classnames"));
61
+ var FormRow = import_react2.default.forwardRef(
62
+ ({ className, children, hidden, ...rest }, ref) => hidden ? null : /* @__PURE__ */ import_react2.default.createElement("div", {
63
+ ref,
64
+ className: (0, import_classnames.default)("columns", className),
65
+ ...rest
66
+ }, children)
67
+ );
68
+ var FormRow_default = FormRow;
69
+
70
+ // src/input/ControlledInputField.tsx
71
+ var import_react10 = __toESM(require("react"));
72
+ var import_react_hook_form = require("react-hook-form");
73
+ var import_classnames8 = __toESM(require("classnames"));
74
+
75
+ // src/input/InputField.tsx
76
+ var import_react9 = __toESM(require("react"));
77
+
78
+ // src/base/Field.tsx
79
+ var import_react3 = __toESM(require("react"));
80
+ var import_classnames2 = __toESM(require("classnames"));
81
+ var Field = ({ className, children, ...rest }) => /* @__PURE__ */ import_react3.default.createElement("div", {
82
+ className: (0, import_classnames2.default)("field", className),
83
+ ...rest
84
+ }, children);
85
+ var Field_default = Field;
86
+
87
+ // src/base/Control.tsx
88
+ var import_react4 = __toESM(require("react"));
89
+ var import_classnames3 = __toESM(require("classnames"));
90
+ var Control = ({ className, children, ...rest }) => /* @__PURE__ */ import_react4.default.createElement("div", {
91
+ className: (0, import_classnames3.default)("control", className),
92
+ ...rest
93
+ }, children);
94
+ var Control_default = Control;
95
+
96
+ // src/base/label/Label.tsx
97
+ var import_react5 = __toESM(require("react"));
98
+ var import_classnames4 = __toESM(require("classnames"));
99
+ var Label = ({ className, children, ...rest }) => /* @__PURE__ */ import_react5.default.createElement("label", {
100
+ className: (0, import_classnames4.default)("label", className),
101
+ ...rest
102
+ }, children);
103
+ var Label_default = Label;
104
+
105
+ // src/base/field-message/FieldMessage.tsx
106
+ var import_react6 = __toESM(require("react"));
107
+ var import_classnames5 = __toESM(require("classnames"));
108
+
109
+ // src/variants.ts
110
+ var createVariantClass = (variant) => variant ? `is-${variant}` : void 0;
111
+
112
+ // src/base/field-message/FieldMessage.tsx
113
+ var FieldMessage = ({ variant, className, children }) => /* @__PURE__ */ import_react6.default.createElement("p", {
114
+ className: (0, import_classnames5.default)("help", createVariantClass(variant), className)
115
+ }, children);
116
+ var FieldMessage_default = FieldMessage;
117
+
118
+ // src/input/Input.tsx
119
+ var import_react7 = __toESM(require("react"));
120
+ var import_classnames6 = __toESM(require("classnames"));
121
+ var import_ui_components = require("@scm-manager/ui-components");
122
+ var Input = import_react7.default.forwardRef(({ variant, className, testId, ...props }, ref) => {
123
+ return /* @__PURE__ */ import_react7.default.createElement("input", {
124
+ ref,
125
+ className: (0, import_classnames6.default)("input", createVariantClass(variant), className),
126
+ ...props,
127
+ ...(0, import_ui_components.createAttributesForTesting)(testId)
128
+ });
129
+ });
130
+ var Input_default = Input;
131
+
132
+ // src/base/help/Help.tsx
133
+ var import_react8 = __toESM(require("react"));
134
+ var import_classnames7 = __toESM(require("classnames"));
135
+ var Help = ({ text, className }) => /* @__PURE__ */ import_react8.default.createElement("span", {
136
+ className: (0, import_classnames7.default)("fas fa-fw fa-question-circle has-text-blue-light", className),
137
+ title: text
138
+ });
139
+ var Help_default = Help;
140
+
141
+ // src/input/InputField.tsx
142
+ var InputField = import_react9.default.forwardRef(
143
+ ({ label, helpText, error, className, ...props }, ref) => {
144
+ const variant = error ? "danger" : void 0;
145
+ return /* @__PURE__ */ import_react9.default.createElement(Field_default, {
146
+ className
147
+ }, /* @__PURE__ */ import_react9.default.createElement(Label_default, null, label, helpText ? /* @__PURE__ */ import_react9.default.createElement(Help_default, {
148
+ className: "ml-1",
149
+ text: helpText
150
+ }) : null), /* @__PURE__ */ import_react9.default.createElement(Control_default, null, /* @__PURE__ */ import_react9.default.createElement(Input_default, {
151
+ variant,
152
+ ref,
153
+ ...props
154
+ })), error ? /* @__PURE__ */ import_react9.default.createElement(FieldMessage_default, {
155
+ variant
156
+ }, error) : null);
157
+ }
158
+ );
159
+ var InputField_default = InputField;
160
+
161
+ // src/input/ControlledInputField.tsx
162
+ function ControlledInputField({
163
+ name,
164
+ label,
165
+ helpText,
166
+ rules,
167
+ className,
168
+ testId,
169
+ defaultValue,
170
+ readOnly,
171
+ ...props
172
+ }) {
173
+ const { control, t, readOnly: formReadonly } = useScmFormContext();
174
+ const labelTranslation = label || t(`${name}.label`) || "";
175
+ const helpTextTranslation = helpText || t(`${name}.helpText`);
176
+ return /* @__PURE__ */ import_react10.default.createElement(import_react_hook_form.Controller, {
177
+ control,
178
+ name,
179
+ rules,
180
+ defaultValue,
181
+ render: ({ field, fieldState }) => /* @__PURE__ */ import_react10.default.createElement(InputField_default, {
182
+ className: (0, import_classnames8.default)("column", className),
183
+ readOnly: readOnly ?? formReadonly,
184
+ required: rules == null ? void 0 : rules.required,
185
+ ...props,
186
+ ...field,
187
+ label: labelTranslation,
188
+ helpText: helpTextTranslation,
189
+ error: fieldState.error ? fieldState.error.message || t(`${name}.error.${fieldState.error.type}`) : void 0,
190
+ testId: testId ?? `input-${name}`
191
+ })
192
+ });
193
+ }
194
+ var ControlledInputField_default = ControlledInputField;
195
+
196
+ // src/checkbox/ControlledCheckboxField.tsx
197
+ var import_react13 = __toESM(require("react"));
198
+ var import_react_hook_form2 = require("react-hook-form");
199
+ var import_classnames9 = __toESM(require("classnames"));
200
+
201
+ // src/checkbox/CheckboxField.tsx
202
+ var import_react12 = __toESM(require("react"));
203
+
204
+ // src/checkbox/Checkbox.tsx
205
+ var import_react11 = __toESM(require("react"));
206
+ var import_ui_components2 = require("@scm-manager/ui-components");
207
+ var Checkbox = import_react11.default.forwardRef(
208
+ ({ readOnly, label, value, name, checked, defaultChecked, defaultValue, testId, helpText, ...props }, ref) => /* @__PURE__ */ import_react11.default.createElement("label", {
209
+ className: "checkbox",
210
+ disabled: readOnly || props.disabled
211
+ }, readOnly ? /* @__PURE__ */ import_react11.default.createElement(import_react11.default.Fragment, null, /* @__PURE__ */ import_react11.default.createElement("input", {
212
+ type: "hidden",
213
+ name,
214
+ value,
215
+ defaultValue,
216
+ checked,
217
+ defaultChecked,
218
+ readOnly: true
219
+ }), /* @__PURE__ */ import_react11.default.createElement("input", {
220
+ type: "checkbox",
221
+ className: "mr-1",
222
+ ref,
223
+ value,
224
+ defaultValue,
225
+ checked,
226
+ defaultChecked,
227
+ ...props,
228
+ ...(0, import_ui_components2.createAttributesForTesting)(testId),
229
+ disabled: true
230
+ })) : /* @__PURE__ */ import_react11.default.createElement("input", {
231
+ type: "checkbox",
232
+ className: "mr-1",
233
+ ref,
234
+ name,
235
+ value,
236
+ defaultValue,
237
+ checked,
238
+ defaultChecked,
239
+ ...props,
240
+ ...(0, import_ui_components2.createAttributesForTesting)(testId)
241
+ }), label, helpText ? /* @__PURE__ */ import_react11.default.createElement(Help_default, {
242
+ className: "ml-1",
243
+ text: helpText
244
+ }) : null)
245
+ );
246
+ var Checkbox_default = Checkbox;
247
+
248
+ // src/checkbox/CheckboxField.tsx
249
+ var CheckboxField = import_react12.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ import_react12.default.createElement(Field_default, {
250
+ className
251
+ }, /* @__PURE__ */ import_react12.default.createElement(Control_default, null, /* @__PURE__ */ import_react12.default.createElement(Checkbox_default, {
252
+ ref,
253
+ ...props
254
+ }))));
255
+ var CheckboxField_default = CheckboxField;
256
+
257
+ // src/checkbox/ControlledCheckboxField.tsx
258
+ function ControlledInputField2({
259
+ name,
260
+ label,
261
+ helpText,
262
+ rules,
263
+ className,
264
+ testId,
265
+ defaultChecked,
266
+ readOnly,
267
+ ...props
268
+ }) {
269
+ const { control, t, readOnly: formReadonly } = useScmFormContext();
270
+ const labelTranslation = label || t(`${name}.label`) || "";
271
+ const helpTextTranslation = helpText || t(`${name}.helpText`);
272
+ return /* @__PURE__ */ import_react13.default.createElement(import_react_hook_form2.Controller, {
273
+ control,
274
+ name,
275
+ rules,
276
+ defaultValue: defaultChecked,
277
+ render: ({ field }) => /* @__PURE__ */ import_react13.default.createElement(CheckboxField_default, {
278
+ className: (0, import_classnames9.default)("column", className),
279
+ readOnly: readOnly ?? formReadonly,
280
+ defaultChecked: field.value,
281
+ ...props,
282
+ ...field,
283
+ label: labelTranslation,
284
+ helpText: helpTextTranslation,
285
+ testId: testId ?? `checkbox-${name}`
286
+ })
287
+ });
288
+ }
289
+ var ControlledCheckboxField_default = ControlledInputField2;
290
+
291
+ // src/input/ControlledSecretConfirmationField.tsx
292
+ var import_react14 = __toESM(require("react"));
293
+ var import_react_hook_form3 = require("react-hook-form");
294
+ var import_classnames10 = __toESM(require("classnames"));
295
+ function ControlledSecretConfirmationField({
296
+ name,
297
+ label,
298
+ confirmationLabel,
299
+ helpText,
300
+ confirmationHelpText,
301
+ rules,
302
+ confirmationErrorMessage,
303
+ className,
304
+ testId,
305
+ confirmationTestId,
306
+ defaultValue,
307
+ readOnly,
308
+ ...props
309
+ }) {
310
+ const { control, watch, t, readOnly: formReadonly } = useScmFormContext();
311
+ const labelTranslation = label || t(`${name}.label`) || "";
312
+ const helpTextTranslation = helpText || t(`${name}.helpText`);
313
+ const confirmationLabelTranslation = confirmationLabel || t(`${name}.confirmation.label`) || "";
314
+ const confirmationHelpTextTranslation = confirmationHelpText || t(`${name}.confirmation.helpText`);
315
+ const confirmationErrorMessageTranslation = confirmationErrorMessage || t(`${name}.confirmation.errorMessage`);
316
+ const secretValue = watch(name);
317
+ return /* @__PURE__ */ import_react14.default.createElement(import_react14.default.Fragment, null, /* @__PURE__ */ import_react14.default.createElement(import_react_hook_form3.Controller, {
318
+ control,
319
+ name,
320
+ defaultValue,
321
+ rules: {
322
+ ...rules,
323
+ deps: [`${name}Confirmation`]
324
+ },
325
+ render: ({ field, fieldState }) => /* @__PURE__ */ import_react14.default.createElement(InputField_default, {
326
+ className: (0, import_classnames10.default)("column", className),
327
+ readOnly: readOnly ?? formReadonly,
328
+ ...props,
329
+ ...field,
330
+ required: rules == null ? void 0 : rules.required,
331
+ type: "password",
332
+ label: labelTranslation,
333
+ helpText: helpTextTranslation,
334
+ error: fieldState.error ? fieldState.error.message || t(`${name}.error.${fieldState.error.type}`) : void 0,
335
+ testId: testId ?? `input-${name}`
336
+ })
337
+ }), /* @__PURE__ */ import_react14.default.createElement(import_react_hook_form3.Controller, {
338
+ control,
339
+ name: `${name}Confirmation`,
340
+ defaultValue,
341
+ render: ({ field, fieldState }) => /* @__PURE__ */ import_react14.default.createElement(InputField_default, {
342
+ className: (0, import_classnames10.default)("column", className),
343
+ type: "password",
344
+ readOnly: readOnly ?? formReadonly,
345
+ disabled: props.disabled,
346
+ ...field,
347
+ label: confirmationLabelTranslation,
348
+ helpText: confirmationHelpTextTranslation,
349
+ error: fieldState.error ? fieldState.error.message || t(`${name}.confirmation.error.${fieldState.error.type}`) : void 0,
350
+ testId: confirmationTestId ?? `input-${name}-confirmation`
351
+ }),
352
+ rules: {
353
+ validate: (value) => secretValue === value || confirmationErrorMessageTranslation
354
+ }
355
+ }));
356
+ }
357
+
358
+ // src/select/ControlledSelectField.tsx
359
+ var import_react17 = __toESM(require("react"));
360
+ var import_react_hook_form4 = require("react-hook-form");
361
+ var import_classnames12 = __toESM(require("classnames"));
362
+
363
+ // src/select/SelectField.tsx
364
+ var import_react16 = __toESM(require("react"));
365
+
366
+ // src/select/Select.tsx
367
+ var import_react15 = __toESM(require("react"));
368
+ var import_classnames11 = __toESM(require("classnames"));
369
+ var import_ui_components3 = require("@scm-manager/ui-components");
370
+ var Select = import_react15.default.forwardRef(({ variant, children, className, testId, ...props }, ref) => /* @__PURE__ */ import_react15.default.createElement("div", {
371
+ className: (0, import_classnames11.default)("select", { "is-multiple": props.multiple }, createVariantClass(variant), className)
372
+ }, /* @__PURE__ */ import_react15.default.createElement("select", {
373
+ ref,
374
+ ...props,
375
+ ...(0, import_ui_components3.createAttributesForTesting)(testId)
376
+ }, children)));
377
+ var Select_default = Select;
378
+
379
+ // src/select/SelectField.tsx
380
+ var SelectField = import_react16.default.forwardRef(
381
+ ({ label, helpText, error, className, ...props }, ref) => {
382
+ const variant = error ? "danger" : void 0;
383
+ return /* @__PURE__ */ import_react16.default.createElement(Field_default, {
384
+ className
385
+ }, /* @__PURE__ */ import_react16.default.createElement(Label_default, null, label, helpText ? /* @__PURE__ */ import_react16.default.createElement(Help_default, {
386
+ className: "ml-1",
387
+ text: helpText
388
+ }) : null), /* @__PURE__ */ import_react16.default.createElement(Control_default, null, /* @__PURE__ */ import_react16.default.createElement(Select_default, {
389
+ variant,
390
+ ref,
391
+ ...props
392
+ })), error ? /* @__PURE__ */ import_react16.default.createElement(FieldMessage_default, {
393
+ variant
394
+ }, error) : null);
395
+ }
396
+ );
397
+ var SelectField_default = SelectField;
398
+
399
+ // src/select/ControlledSelectField.tsx
400
+ function ControlledSelectField({
401
+ name,
402
+ label,
403
+ helpText,
404
+ rules,
405
+ className,
406
+ testId,
407
+ defaultValue,
408
+ readOnly,
409
+ ...props
410
+ }) {
411
+ const { control, t, readOnly: formReadonly } = useScmFormContext();
412
+ const labelTranslation = label || t(`${name}.label`) || "";
413
+ const helpTextTranslation = helpText || t(`${name}.helpText`);
414
+ return /* @__PURE__ */ import_react17.default.createElement(import_react_hook_form4.Controller, {
415
+ control,
416
+ name,
417
+ rules,
418
+ defaultValue,
419
+ render: ({ field, fieldState }) => /* @__PURE__ */ import_react17.default.createElement(SelectField_default, {
420
+ className: (0, import_classnames12.default)("column", className),
421
+ readOnly: readOnly ?? formReadonly,
422
+ required: rules == null ? void 0 : rules.required,
423
+ ...props,
424
+ ...field,
425
+ label: labelTranslation,
426
+ helpText: helpTextTranslation,
427
+ error: fieldState.error ? fieldState.error.message || t(`${name}.error.${fieldState.error.type}`) : void 0,
428
+ testId: testId ?? `select-${name}`
429
+ })
430
+ });
431
+ }
432
+ var ControlledSelectField_default = ControlledSelectField;
433
+
434
+ // src/Form.tsx
435
+ var SuccessNotification = ({ label, hide }) => {
436
+ if (!label) {
437
+ return null;
438
+ }
439
+ return /* @__PURE__ */ import_react18.default.createElement("div", {
440
+ className: "notification is-success"
441
+ }, /* @__PURE__ */ import_react18.default.createElement("button", {
442
+ className: "delete",
443
+ onClick: hide
444
+ }), label);
445
+ };
446
+ function Form({
447
+ children,
448
+ onSubmit,
449
+ defaultValues,
450
+ translationPath,
451
+ readOnly,
452
+ submitButtonTestId
453
+ }) {
454
+ const form = (0, import_react_hook_form5.useForm)({
455
+ mode: "onChange",
456
+ defaultValues
457
+ });
458
+ const { formState, handleSubmit, reset } = form;
459
+ const [ns, prefix] = translationPath;
460
+ const { t } = (0, import_react_i18next.useTranslation)(ns, { keyPrefix: prefix });
461
+ const { isDirty, isValid, isSubmitting, isSubmitSuccessful } = formState;
462
+ const [error, setError] = (0, import_react18.useState)();
463
+ const [showSuccessNotification, setShowSuccessNotification] = (0, import_react18.useState)(false);
464
+ (0, import_react18.useEffect)(() => {
465
+ if (isSubmitSuccessful) {
466
+ setShowSuccessNotification(true);
467
+ }
468
+ }, [isSubmitSuccessful]);
469
+ (0, import_react18.useEffect)(() => reset(defaultValues), [defaultValues, reset]);
470
+ (0, import_react18.useEffect)(() => {
471
+ if (isDirty) {
472
+ setShowSuccessNotification(false);
473
+ }
474
+ }, [isDirty]);
475
+ const translateWithFallback = (0, import_react18.useCallback)(
476
+ (key, ...args) => {
477
+ const translation = t(key, ...args);
478
+ if (translation === `${prefix}.${key}`) {
479
+ return "";
480
+ }
481
+ return translation;
482
+ },
483
+ [prefix, t]
484
+ );
485
+ const submit = (0, import_react18.useCallback)(
486
+ async (data) => {
487
+ setError(null);
488
+ try {
489
+ return await onSubmit(data);
490
+ } catch (e) {
491
+ if (e instanceof Error) {
492
+ setError(e);
493
+ } else {
494
+ throw e;
495
+ }
496
+ }
497
+ },
498
+ [onSubmit]
499
+ );
500
+ return /* @__PURE__ */ import_react18.default.createElement(ScmFormContextProvider, {
501
+ ...form,
502
+ readOnly: isSubmitting || readOnly,
503
+ t: translateWithFallback
504
+ }, /* @__PURE__ */ import_react18.default.createElement("form", {
505
+ onSubmit: handleSubmit(submit)
506
+ }, showSuccessNotification ? /* @__PURE__ */ import_react18.default.createElement(SuccessNotification, {
507
+ label: translateWithFallback("submit-success-notification"),
508
+ hide: () => setShowSuccessNotification(false)
509
+ }) : null, typeof children === "function" ? children(form) : children, error ? /* @__PURE__ */ import_react18.default.createElement(import_ui_components4.ErrorNotification, {
510
+ error
511
+ }) : null, !readOnly ? /* @__PURE__ */ import_react18.default.createElement(import_ui_components4.Level, {
512
+ right: /* @__PURE__ */ import_react18.default.createElement(import_ui_buttons.Button, {
513
+ type: "submit",
514
+ variant: "primary",
515
+ testId: submitButtonTestId ?? "submit-button",
516
+ disabled: !isDirty || !isValid,
517
+ isLoading: isSubmitting
518
+ }, t("submit"))
519
+ }) : null));
520
+ }
521
+ var Form_default = Object.assign(Form, {
522
+ Row: FormRow_default,
523
+ Input: ControlledInputField_default,
524
+ Checkbox: ControlledCheckboxField_default,
525
+ SecretConfirmation: ControlledSecretConfirmationField,
526
+ Select: ControlledSelectField_default
527
+ });
528
+
529
+ // src/ConfigurationForm.tsx
530
+ var import_ui_api = require("@scm-manager/ui-api");
531
+ var import_ui_components5 = require("@scm-manager/ui-components");
532
+ var import_react19 = __toESM(require("react"));
533
+ function ConfigurationForm({ link, translationPath, children }) {
534
+ const { initialConfiguration, isReadOnly, update, isLoading } = (0, import_ui_api.useConfigLink)(link);
535
+ if (isLoading || !initialConfiguration) {
536
+ return /* @__PURE__ */ import_react19.default.createElement(import_ui_components5.Loading, null);
537
+ }
538
+ return /* @__PURE__ */ import_react19.default.createElement(Form_default, {
539
+ onSubmit: update,
540
+ translationPath,
541
+ defaultValues: initialConfiguration,
542
+ readOnly: isReadOnly
543
+ }, children);
544
+ }
545
+ var ConfigurationForm_default = ConfigurationForm;
546
+
547
+ // src/resourceHooks.ts
548
+ var import_ui_api2 = require("@scm-manager/ui-api");
549
+ var import_react_query = require("react-query");
550
+ var unwrapLink = (input, linkName) => {
551
+ if (Array.isArray(input)) {
552
+ return (0, import_ui_api2.requiredLink)(input[0], input[1]);
553
+ } else if (typeof input === "string") {
554
+ return input;
555
+ } else {
556
+ return input._links[linkName].href;
557
+ }
558
+ };
559
+ var createResource = (link, contentType) => {
560
+ return (payload) => {
561
+ return import_ui_api2.apiClient.post(link, payload, contentType).then((response) => {
562
+ const location = response.headers.get("Location");
563
+ if (!location) {
564
+ throw new Error("Server does not return required Location header");
565
+ }
566
+ return import_ui_api2.apiClient.get(location);
567
+ }).then((response) => response.json());
568
+ };
569
+ };
570
+ var useCreateResource = (link, [entityKey, collectionName], idFactory, { contentType = "application/json" } = {}) => {
571
+ const queryClient = (0, import_react_query.useQueryClient)();
572
+ const { mutateAsync, data, isLoading, error } = (0, import_react_query.useMutation)(createResource(link, contentType), {
573
+ onSuccess: (result) => {
574
+ queryClient.setQueryData([entityKey, idFactory(result)], result);
575
+ return queryClient.invalidateQueries(collectionName);
576
+ }
577
+ });
578
+ return {
579
+ submit: (payload) => mutateAsync(payload),
580
+ isLoading,
581
+ error,
582
+ submissionResult: data
583
+ };
584
+ };
585
+ var useUpdateResource = (link, idFactory, {
586
+ contentType = "application/json",
587
+ collectionName: [entityQueryKey, collectionName] = ["", ""]
588
+ } = {}) => {
589
+ const queryClient = (0, import_react_query.useQueryClient)();
590
+ const { mutateAsync, isLoading, error, data } = (0, import_react_query.useMutation)(
591
+ (resource) => import_ui_api2.apiClient.put(unwrapLink(link, "update"), resource, contentType),
592
+ {
593
+ onSuccess: async (_, payload) => {
594
+ await queryClient.invalidateQueries(entityQueryKey ? [entityQueryKey, idFactory(payload)] : idFactory(payload));
595
+ if (collectionName) {
596
+ await queryClient.invalidateQueries(collectionName);
597
+ }
598
+ }
599
+ }
600
+ );
601
+ return {
602
+ submit: (resource) => mutateAsync(resource),
603
+ isLoading,
604
+ error,
605
+ submissionResult: data
606
+ };
607
+ };
608
+ var useDeleteResource = (idFactory, { collectionName: [entityQueryKey, collectionName] = ["", ""] } = {}) => {
609
+ const queryClient = (0, import_react_query.useQueryClient)();
610
+ const { mutateAsync, isLoading, error, data } = (0, import_react_query.useMutation)(
611
+ (resource) => {
612
+ const deleteUrl = resource._links.delete.href;
613
+ return import_ui_api2.apiClient.delete(deleteUrl);
614
+ },
615
+ {
616
+ onSuccess: async (_, resource) => {
617
+ const id = idFactory(resource);
618
+ await queryClient.removeQueries(entityQueryKey ? [entityQueryKey, id] : id);
619
+ if (collectionName) {
620
+ await queryClient.invalidateQueries(collectionName);
621
+ }
622
+ }
623
+ }
624
+ );
625
+ return {
626
+ submit: (resource) => mutateAsync(resource),
627
+ isLoading,
628
+ error,
629
+ submissionResult: data
630
+ };
631
+ };
632
+ // Annotate the CommonJS export names for ESM import in node:
633
+ 0 && (module.exports = {
634
+ ConfigurationForm,
635
+ Form,
636
+ useCreateResource,
637
+ useDeleteResource,
638
+ useUpdateResource
639
+ });