@knkcs/anker 2.3.2 → 2.5.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.
@@ -1,6 +1,6 @@
1
1
  import { Progress } from '../chunk-WEP2AIQ5.js';
2
- import { IconButton } from '../chunk-JS7ZEZV3.js';
3
2
  import { Spinner } from '../chunk-5YDCDC4B.js';
3
+ import { IconButton } from '../chunk-JS7ZEZV3.js';
4
4
  import { Box, Flex, Text, Stack, HStack } from '../chunk-G4QMIXLC.js';
5
5
  import { Dialog, Portal, ButtonGroup, Button } from '@chakra-ui/react';
6
6
  import { createContext, useState, useRef, useCallback, useContext, useEffect } from 'react';
@@ -16,12 +16,17 @@ interface FormFieldProps<T extends FieldValues> {
16
16
  disabled?: boolean;
17
17
  readOnly?: boolean;
18
18
  actions?: React__default.ReactNode;
19
+ /** When false, the dirty-marker on the label is suppressed and the
20
+ * children-callback's `meta.isDirty` is forced to false. @default true */
21
+ showDirtyState?: boolean;
19
22
  children: (field: ControllerRenderProps<T, Path<T>> & {
20
23
  /** Computed aria-describedby linking to helper/description/error elements. */
21
24
  "aria-describedby"?: string;
25
+ }, meta: {
26
+ isDirty: boolean;
22
27
  }) => React__default.ReactNode;
23
28
  }
24
- declare function FormField<T extends FieldValues>({ name, label, helperText, description, required, disabled, readOnly, actions, children, }: FormFieldProps<T>): react_jsx_runtime.JSX.Element;
29
+ declare function FormField<T extends FieldValues>({ name, label, helperText, description, required, disabled, readOnly, actions, showDirtyState, children, }: FormFieldProps<T>): react_jsx_runtime.JSX.Element;
25
30
 
26
31
  interface ArrayFieldProps<T extends FieldValues> extends Omit<FormFieldProps<T>, "children"> {
27
32
  /**
@@ -52,18 +57,13 @@ declare namespace ArrayField {
52
57
  var displayName: string;
53
58
  }
54
59
 
55
- interface CheckboxFieldProps<T extends FieldValues> {
56
- name: Path<T>;
57
- label?: string;
60
+ interface CheckboxFieldProps<T extends FieldValues> extends Omit<FormFieldProps<T>, "children"> {
58
61
  /** When provided, the field is treated as an array of checked values. */
59
62
  value?: string | number;
60
- disabled?: boolean;
61
- helperText?: React__default.ReactNode;
63
+ /** Content to display after the checkbox. */
62
64
  children?: React__default.ReactNode;
63
65
  }
64
- declare function CheckboxField<T extends FieldValues>({ ref, ...props }: CheckboxFieldProps<T> & {
65
- ref?: React__default.Ref<HTMLLabelElement>;
66
- }): react_jsx_runtime.JSX.Element;
66
+ declare function CheckboxField<T extends FieldValues>({ ...props }: CheckboxFieldProps<T>): react_jsx_runtime.JSX.Element;
67
67
 
68
68
  type MonacoEditorProps = {
69
69
  value?: string;
@@ -123,6 +123,20 @@ declare function DatePickerField<T extends FieldValues>({ ref, ...props }: DateP
123
123
  ref?: React__default.Ref<HTMLInputElement>;
124
124
  }): react_jsx_runtime.JSX.Element;
125
125
 
126
+ interface DirtyCounterProps {
127
+ /**
128
+ * Label template. The literal `{count}` is replaced with the dirty
129
+ * field count. @default "{count} ungespeicherte Änderungen"
130
+ */
131
+ label?: string;
132
+ /** Render nothing when no fields are dirty. @default true */
133
+ hideWhenClean?: boolean;
134
+ }
135
+ declare function DirtyCounter({ label, hideWhenClean, }: DirtyCounterProps): react_jsx_runtime.JSX.Element | null;
136
+ declare namespace DirtyCounter {
137
+ var displayName: string;
138
+ }
139
+
126
140
  interface DirtyFormGuardProps {
127
141
  /** Dialog title. @default "You have unsaved changes" */
128
142
  title?: string;
@@ -266,4 +280,15 @@ declare function TextareaField<T extends FieldValues>({ ref, ...props }: Textare
266
280
  ref?: React__default.Ref<HTMLTextAreaElement>;
267
281
  }): react_jsx_runtime.JSX.Element;
268
282
 
269
- export { ArrayField, type ArrayFieldProps, CheckboxField, type CheckboxFieldProps, CodeField, type CodeFieldProps, ColorPickerField, type ColorPickerFieldProps, ControlledFormField, type ControlledFormFieldProps, DatePickerField, type DatePickerFieldProps, DirtyFormGuard, type DirtyFormGuardProps, FileField, type FileFieldProps, FormField, type FormFieldProps, InlineEdit, type InlineEditProps, InputField, type InputFieldProps, MarkdownField, type MarkdownFieldProps, NumberInputField, type NumberInputFieldProps, RadioGroupField, type RadioGroupFieldProps, type RadioOption, SelectField, type SelectFieldProps, SwitchField, type SwitchFieldProps, TextareaField, type TextareaFieldProps };
283
+ interface UseFieldDirtyOptions {
284
+ /** Set to false to never report dirty (opt-out per field). */
285
+ showDirtyState?: boolean;
286
+ }
287
+ /**
288
+ * useFieldDirty returns true when the field at `name` is dirty (changed
289
+ * from its react-hook-form default) AND visual marking isn't suppressed.
290
+ * Safe to call outside a FormProvider — returns false in that case.
291
+ */
292
+ declare function useFieldDirty(name: string, opts?: UseFieldDirtyOptions): boolean;
293
+
294
+ export { ArrayField, type ArrayFieldProps, CheckboxField, type CheckboxFieldProps, CodeField, type CodeFieldProps, ColorPickerField, type ColorPickerFieldProps, ControlledFormField, type ControlledFormFieldProps, DatePickerField, type DatePickerFieldProps, DirtyCounter, type DirtyCounterProps, DirtyFormGuard, type DirtyFormGuardProps, FileField, type FileFieldProps, FormField, type FormFieldProps, InlineEdit, type InlineEditProps, InputField, type InputFieldProps, MarkdownField, type MarkdownFieldProps, NumberInputField, type NumberInputFieldProps, RadioGroupField, type RadioGroupFieldProps, type RadioOption, SelectField, type SelectFieldProps, SwitchField, type SwitchFieldProps, TextareaField, type TextareaFieldProps, type UseFieldDirtyOptions, useFieldDirty };
@@ -20,6 +20,7 @@ function FormField({
20
20
  disabled,
21
21
  readOnly,
22
22
  actions,
23
+ showDirtyState = true,
23
24
  children
24
25
  }) {
25
26
  const { control } = useFormContext();
@@ -38,6 +39,7 @@ function FormField({
38
39
  helperText ? helperId : null,
39
40
  fieldState.error ? errorId : null
40
41
  ].filter(Boolean).join(" ") || void 0;
42
+ const isDirty = Boolean(showDirtyState && fieldState.isDirty);
41
43
  return /* @__PURE__ */ jsxs(
42
44
  Field.Root,
43
45
  {
@@ -45,12 +47,31 @@ function FormField({
45
47
  required,
46
48
  disabled,
47
49
  readOnly,
50
+ "data-dirty": isDirty ? "true" : void 0,
48
51
  children: [
49
52
  label && (typeof label === "string" ? /* @__PURE__ */ jsxs(HStack, { children: [
50
- /* @__PURE__ */ jsx(Field.Label, { flex: "1", htmlFor: name, children: label }),
53
+ /* @__PURE__ */ jsxs(Field.Label, { flex: "1", htmlFor: name, children: [
54
+ label,
55
+ isDirty && /* @__PURE__ */ jsx(
56
+ Box,
57
+ {
58
+ as: "span",
59
+ display: "inline-block",
60
+ width: "6px",
61
+ height: "6px",
62
+ borderRadius: "full",
63
+ bg: "yellow.500",
64
+ ml: "2",
65
+ "aria-label": "ungespeicherte \xC4nderung"
66
+ }
67
+ )
68
+ ] }),
51
69
  actions
52
70
  ] }) : label),
53
- children({ ...field, "aria-describedby": describedBy }),
71
+ children(
72
+ { ...field, "aria-describedby": describedBy },
73
+ { isDirty }
74
+ ),
54
75
  description && /* @__PURE__ */ jsx(Text, { id: descriptionId, fontSize: "xs", color: "muted", children: description }),
55
76
  helperText && (typeof helperText === "string" ? /* @__PURE__ */ jsx(Field.HelperText, { id: helperId, children: helperText }) : /* @__PURE__ */ jsx("span", { id: helperId, children: helperText })),
56
77
  fieldState.error && /* @__PURE__ */ jsx(Field.ErrorText, { id: errorId, "aria-live": "polite", children: fieldState.error.message })
@@ -73,30 +94,41 @@ function ArrayField(props) {
73
94
  addLabel = "Add Field",
74
95
  removeLabel = "Remove Item",
75
96
  readOnly,
97
+ showDirtyState,
76
98
  emptyState,
77
99
  ...rest
78
100
  } = props;
79
- return /* @__PURE__ */ jsx(FormField, { name, label, readOnly, ...rest, children: () => /* @__PURE__ */ jsx(Box, { py: 4, px: 4, bg: "bg", rounded: "md", children: mode === "dynamic" ? /* @__PURE__ */ jsx(
80
- DynamicArray,
101
+ return /* @__PURE__ */ jsx(
102
+ FormField,
81
103
  {
82
104
  name,
83
- valueHeader,
84
- keyHeader,
85
- addLabel,
86
- removeLabel,
105
+ label,
87
106
  readOnly,
88
- emptyState
89
- }
90
- ) : /* @__PURE__ */ jsx(
91
- KeyedArray,
92
- {
93
- name,
94
- valueHeader,
95
- keyHeader,
96
- keys,
97
- readOnly
107
+ showDirtyState,
108
+ ...rest,
109
+ children: () => /* @__PURE__ */ jsx(Box, { py: 4, px: 4, bg: "bg", rounded: "md", children: mode === "dynamic" ? /* @__PURE__ */ jsx(
110
+ DynamicArray,
111
+ {
112
+ name,
113
+ valueHeader,
114
+ keyHeader,
115
+ addLabel,
116
+ removeLabel,
117
+ readOnly,
118
+ emptyState
119
+ }
120
+ ) : /* @__PURE__ */ jsx(
121
+ KeyedArray,
122
+ {
123
+ name,
124
+ valueHeader,
125
+ keyHeader,
126
+ keys,
127
+ readOnly
128
+ }
129
+ ) })
98
130
  }
99
- ) }) });
131
+ );
100
132
  }
101
133
  ArrayField.displayName = "ArrayField";
102
134
  var DynamicArray = React.memo((props) => {
@@ -184,17 +216,28 @@ var KeyedArray = React.memo((props) => {
184
216
  });
185
217
  KeyedArray.displayName = "KeyedArray";
186
218
  function CheckboxField({
187
- ref,
188
219
  ...props
189
220
  }) {
190
- const { name, label, value, disabled, helperText, children } = props;
191
- const { control } = useFormContext();
221
+ const {
222
+ name,
223
+ label,
224
+ value,
225
+ disabled,
226
+ showDirtyState,
227
+ helperText,
228
+ children,
229
+ ...rest
230
+ } = props;
192
231
  return /* @__PURE__ */ jsx(
193
- Controller,
232
+ FormField,
194
233
  {
195
234
  name,
196
- control,
197
- render: ({ field, fieldState }) => {
235
+ label,
236
+ disabled,
237
+ showDirtyState,
238
+ helperText,
239
+ ...rest,
240
+ children: (field) => {
198
241
  const isArrayMode = value !== void 0;
199
242
  const isChecked = isArrayMode ? Array.isArray(field.value) && field.value.includes(value) : !!field.value;
200
243
  const handleCheckedChange = (details) => {
@@ -214,32 +257,24 @@ function CheckboxField({
214
257
  }
215
258
  };
216
259
  const uniqueId = isArrayMode ? `${name}-${String(value)}` : name;
217
- return /* @__PURE__ */ jsxs(Field.Root, { invalid: !!fieldState.error, disabled, children: [
218
- /* @__PURE__ */ jsxs(
219
- Checkbox.Root,
220
- {
221
- id: uniqueId,
222
- name: field.name,
223
- value: isArrayMode ? String(value) : void 0,
224
- invalid: !!fieldState.error,
225
- ref,
226
- checked: isChecked,
227
- onCheckedChange: handleCheckedChange,
228
- onBlur: field.onBlur,
229
- disabled,
230
- children: [
231
- /* @__PURE__ */ jsx(Checkbox.HiddenInput, {}),
232
- /* @__PURE__ */ jsx(Checkbox.Control, { children: /* @__PURE__ */ jsx(Checkbox.Indicator, {}) }),
233
- (label || children) && /* @__PURE__ */ jsxs(Checkbox.Label, { children: [
234
- label,
235
- children
236
- ] })
237
- ]
238
- }
239
- ),
240
- helperText && /* @__PURE__ */ jsx(Field.HelperText, { children: helperText }),
241
- fieldState.error && /* @__PURE__ */ jsx(Field.ErrorText, { "aria-live": "polite", children: fieldState.error.message })
242
- ] });
260
+ return /* @__PURE__ */ jsxs(
261
+ Checkbox.Root,
262
+ {
263
+ id: uniqueId,
264
+ name: field.name,
265
+ value: isArrayMode ? String(value) : void 0,
266
+ checked: isChecked,
267
+ onCheckedChange: handleCheckedChange,
268
+ onBlur: field.onBlur,
269
+ disabled,
270
+ "aria-describedby": field["aria-describedby"],
271
+ children: [
272
+ /* @__PURE__ */ jsx(Checkbox.HiddenInput, {}),
273
+ /* @__PURE__ */ jsx(Checkbox.Control, { children: /* @__PURE__ */ jsx(Checkbox.Indicator, {}) }),
274
+ (label || children) && /* @__PURE__ */ jsx(Checkbox.Label, { children })
275
+ ]
276
+ }
277
+ );
243
278
  }
244
279
  }
245
280
  );
@@ -429,6 +464,29 @@ function DatePickerField({
429
464
  );
430
465
  }
431
466
  DatePickerField.displayName = "DatePickerField";
467
+ function DirtyCounter({
468
+ label = "{count} ungespeicherte \xC4nderungen",
469
+ hideWhenClean = true
470
+ }) {
471
+ const ctx = useFormContext();
472
+ const dirty = ctx ? ctx.formState.dirtyFields : {};
473
+ const count = Object.keys(dirty).length;
474
+ if (count === 0 && hideWhenClean) return null;
475
+ return /* @__PURE__ */ jsxs(HStack, { gap: "2", fontSize: "sm", color: "yellow.700", children: [
476
+ /* @__PURE__ */ jsx(
477
+ Box,
478
+ {
479
+ width: "6px",
480
+ height: "6px",
481
+ borderRadius: "full",
482
+ bg: "yellow.500",
483
+ "aria-hidden": true
484
+ }
485
+ ),
486
+ /* @__PURE__ */ jsx(Text, { children: label.replace("{count}", String(count)) })
487
+ ] });
488
+ }
489
+ DirtyCounter.displayName = "DirtyCounter";
432
490
  var DirtyFormGuard = ({
433
491
  title,
434
492
  message,
@@ -669,6 +727,7 @@ function InputField({
669
727
  inputProps,
670
728
  readOnly,
671
729
  disabled,
730
+ showDirtyState,
672
731
  ...rest
673
732
  } = props;
674
733
  return /* @__PURE__ */ jsx(
@@ -678,8 +737,9 @@ function InputField({
678
737
  label,
679
738
  readOnly,
680
739
  disabled,
740
+ showDirtyState,
681
741
  ...rest,
682
- children: (field) => /* @__PURE__ */ jsx(
742
+ children: (field, { isDirty }) => /* @__PURE__ */ jsx(
683
743
  text_input_default,
684
744
  {
685
745
  ...field,
@@ -692,6 +752,8 @@ function InputField({
692
752
  readOnly,
693
753
  disabled,
694
754
  opacity: readOnly ? 0.8 : 1,
755
+ borderColor: isDirty ? "yellow.400" : void 0,
756
+ bg: isDirty ? "yellow.50" : void 0,
695
757
  ref,
696
758
  ...inputProps
697
759
  }
@@ -805,17 +867,34 @@ function NumberInputField2({
805
867
  }
806
868
  NumberInputField2.displayName = "NumberInputField";
807
869
  function RadioGroupField(props) {
808
- const { name, label, options, radioGroupProps, stackProps, ...rest } = props;
809
- return /* @__PURE__ */ jsx(FormField, { name, label, ...rest, children: (field) => /* @__PURE__ */ jsx(
810
- RadioGroup,
870
+ const {
871
+ name,
872
+ label,
873
+ options,
874
+ showDirtyState,
875
+ radioGroupProps,
876
+ stackProps,
877
+ ...rest
878
+ } = props;
879
+ return /* @__PURE__ */ jsx(
880
+ FormField,
811
881
  {
812
- value: String(field.value ?? ""),
813
- onValueChange: (e) => field.onChange(e.value),
814
- "aria-describedby": field["aria-describedby"],
815
- ...radioGroupProps,
816
- children: /* @__PURE__ */ jsx(Stack, { direction: "row", ...stackProps, children: options.map((option) => /* @__PURE__ */ jsx(Radio, { value: option.value, children: option.label }, option.value)) })
882
+ name,
883
+ label,
884
+ showDirtyState,
885
+ ...rest,
886
+ children: (field) => /* @__PURE__ */ jsx(
887
+ RadioGroup,
888
+ {
889
+ value: String(field.value ?? ""),
890
+ onValueChange: (e) => field.onChange(e.value),
891
+ "aria-describedby": field["aria-describedby"],
892
+ ...radioGroupProps,
893
+ children: /* @__PURE__ */ jsx(Stack, { direction: "row", ...stackProps, children: options.map((option) => /* @__PURE__ */ jsx(Radio, { value: option.value, children: option.label }, option.value)) })
894
+ }
895
+ )
817
896
  }
818
- ) });
897
+ );
819
898
  }
820
899
  RadioGroupField.displayName = "RadioGroupField";
821
900
  function SelectField({
@@ -830,6 +909,7 @@ function SelectField({
830
909
  children,
831
910
  readOnly,
832
911
  disabled,
912
+ showDirtyState,
833
913
  ...rest
834
914
  } = props;
835
915
  return /* @__PURE__ */ jsx(
@@ -839,8 +919,9 @@ function SelectField({
839
919
  label,
840
920
  readOnly,
841
921
  disabled,
922
+ showDirtyState,
842
923
  ...rest,
843
- children: (field) => /* @__PURE__ */ jsx(
924
+ children: (field, { isDirty }) => /* @__PURE__ */ jsx(
844
925
  NativeSelect,
845
926
  {
846
927
  disabled: readOnly || disabled,
@@ -849,6 +930,8 @@ function SelectField({
849
930
  value: String(field.value ?? ""),
850
931
  id: name,
851
932
  ref,
933
+ borderColor: isDirty ? "yellow.400" : void 0,
934
+ bg: isDirty ? "yellow.50" : void 0,
852
935
  ...selectProps,
853
936
  children
854
937
  }
@@ -861,7 +944,15 @@ function SwitchField({
861
944
  ref,
862
945
  ...props
863
946
  }) {
864
- const { name, label, readOnly, disabled, switchProps, ...rest } = props;
947
+ const {
948
+ name,
949
+ label,
950
+ readOnly,
951
+ disabled,
952
+ showDirtyState,
953
+ switchProps,
954
+ ...rest
955
+ } = props;
865
956
  return /* @__PURE__ */ jsx(
866
957
  FormField,
867
958
  {
@@ -869,6 +960,7 @@ function SwitchField({
869
960
  label,
870
961
  readOnly,
871
962
  disabled,
963
+ showDirtyState,
872
964
  ...rest,
873
965
  children: (field) => /* @__PURE__ */ jsx(
874
966
  Switch,
@@ -901,6 +993,7 @@ function TextareaField({
901
993
  textareaProps,
902
994
  readOnly,
903
995
  disabled,
996
+ showDirtyState,
904
997
  ...rest
905
998
  } = props;
906
999
  return /* @__PURE__ */ jsx(
@@ -910,8 +1003,9 @@ function TextareaField({
910
1003
  label,
911
1004
  readOnly,
912
1005
  disabled,
1006
+ showDirtyState,
913
1007
  ...rest,
914
- children: (field) => /* @__PURE__ */ jsx(
1008
+ children: (field, { isDirty }) => /* @__PURE__ */ jsx(
915
1009
  Textarea,
916
1010
  {
917
1011
  ...field,
@@ -921,6 +1015,8 @@ function TextareaField({
921
1015
  readOnly,
922
1016
  disabled,
923
1017
  opacity: readOnly ? 0.8 : 1,
1018
+ borderColor: isDirty ? "yellow.400" : void 0,
1019
+ bg: isDirty ? "yellow.50" : void 0,
924
1020
  ref,
925
1021
  ...textareaProps
926
1022
  }
@@ -929,7 +1025,14 @@ function TextareaField({
929
1025
  );
930
1026
  }
931
1027
  TextareaField.displayName = "TextareaField";
1028
+ function useFieldDirty(name, opts = {}) {
1029
+ const ctx = useFormContext();
1030
+ const { showDirtyState = true } = opts;
1031
+ if (!showDirtyState || !ctx) return false;
1032
+ const dirty = ctx.formState.dirtyFields;
1033
+ return Boolean(dirty[name]);
1034
+ }
932
1035
 
933
- export { ArrayField, CheckboxField, CodeField, ColorPickerField, ControlledFormField, DatePickerField, DirtyFormGuard, FileField, FormField, InlineEdit, InputField, MarkdownField, NumberInputField2 as NumberInputField, RadioGroupField, SelectField, SwitchField, TextareaField };
1036
+ export { ArrayField, CheckboxField, CodeField, ColorPickerField, ControlledFormField, DatePickerField, DirtyCounter, DirtyFormGuard, FileField, FormField, InlineEdit, InputField, MarkdownField, NumberInputField2 as NumberInputField, RadioGroupField, SelectField, SwitchField, TextareaField, useFieldDirty };
934
1037
  //# sourceMappingURL=index.js.map
935
1038
  //# sourceMappingURL=index.js.map