@akinon/akifilter 1.2.0-next.7 → 1.2.0-next.9

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 +1 @@
1
- {"version":3,"file":"akifilter.d.ts","sourceRoot":"","sources":["../../src/akifilter.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAGtB,OAAO,EAIL,WAAW,EAEX,IAAI,EAGL,MAAM,iBAAiB,CAAC;AAWzB,OAAO,KAAK,MAAM,OAAO,CAAC;AA0B1B,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,SAAS,CAAC;AAY/D,KAAK,oBAAoB,GAAG,WAAW,CAAC;AA2DxC,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,oBAAoB,GAAG,oBAAoB,IAC9D;IACF;;OAEG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACtC;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IACzD;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,IAAI,CAAC;IAClE;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAkvBF,eAAO,MAAM,SAAS;KACpB,YAAY,SAAS,oBAAoB,uBAElC,cAAc,CAAC,YAAY,CAAC;;CAmBpC,CAAC"}
1
+ {"version":3,"file":"akifilter.d.ts","sourceRoot":"","sources":["../../src/akifilter.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAGtB,OAAO,EAIL,WAAW,EACX,IAAI,EAIL,MAAM,iBAAiB,CAAC;AAWzB,OAAO,KAAK,MAAM,OAAO,CAAC;AA0B1B,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,SAAS,CAAC;AAY/D,KAAK,oBAAoB,GAAG,WAAW,CAAC;AA0HxC,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,oBAAoB,GAAG,oBAAoB,IAC9D;IACF;;OAEG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACtC;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IACzD;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,IAAI,CAAC;IAClE;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AA2vBF,eAAO,MAAM,SAAS;KACpB,YAAY,SAAS,oBAAoB,uBAElC,cAAc,CAAC,YAAY,CAAC;;CAmBpC,CAAC"}
@@ -37,6 +37,32 @@ const use_debounced_value_1 = require("./hooks/use-debounced-value");
37
37
  const i18n_1 = require("./i18n");
38
38
  const schema_1 = require("./utils/schema");
39
39
  const values_1 = require("./utils/values");
40
+ const FilterFormItem = (_a) => {
41
+ var _b, _c;
42
+ var { children, control, name, valuePropName } = _a, props = __rest(_a, ["children", "control", "name", "valuePropName"]);
43
+ const { field, fieldState } = (0, akiform_1.useController)({ name, control });
44
+ const childrenWithProps = react_1.default.Children.map(children, child => {
45
+ if (react_1.default.isValidElement(child)) {
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ const typedChild = child;
48
+ return react_1.default.cloneElement(typedChild, Object.assign(Object.assign(Object.assign({}, field), {
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ onChange: (...params) => {
51
+ var _a, _b;
52
+ (_b = (_a = typedChild.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, params);
53
+ field.onChange(...params);
54
+ }, onBlur: () => {
55
+ var _a, _b;
56
+ (_b = (_a = typedChild.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a);
57
+ field.onBlur();
58
+ }, ref: undefined }), (valuePropName && {
59
+ [valuePropName]: field.value
60
+ })));
61
+ }
62
+ return child;
63
+ });
64
+ return (react_1.default.createElement(akiform_1.Akiform.Item, Object.assign({}, props, { validateStatus: fieldState.invalid ? 'error' : undefined, help: (_c = (_b = fieldState.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : props.help, className: props.className }), childrenWithProps));
65
+ };
40
66
  /**
41
67
  * Checks if a field should be disabled based on config.disabled property.
42
68
  */
@@ -187,14 +213,20 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
187
213
  (0, storage_1.writeVisibleKeys)(storageKey, visibleKeys);
188
214
  onVisibleFieldsChange === null || onVisibleFieldsChange === void 0 ? void 0 : onVisibleFieldsChange(visibleKeys);
189
215
  }, [visibleKeys, onVisibleFieldsChange, storageKey]);
190
- // Track if this is the initial mount to avoid unnecessary reset
191
- const isInitialMountRef = react_1.default.useRef(true);
216
+ // Track previous mergedDefaultValues to avoid unnecessary resets
217
+ const previousMergedDefaultValuesRef = react_1.default.useRef(null);
192
218
  react_1.default.useEffect(() => {
219
+ const serialised = JSON.stringify(mergedDefaultValues);
220
+ // Skip if the values haven't actually changed (deep comparison)
221
+ if (previousMergedDefaultValuesRef.current === serialised) {
222
+ return;
223
+ }
193
224
  // Skip reset on initial mount - useForm already uses defaultValues
194
- if (isInitialMountRef.current) {
195
- isInitialMountRef.current = false;
225
+ if (previousMergedDefaultValuesRef.current === null) {
226
+ previousMergedDefaultValuesRef.current = serialised;
196
227
  return;
197
228
  }
229
+ previousMergedDefaultValuesRef.current = serialised;
198
230
  formMethods.reset(mergedDefaultValues);
199
231
  }, [formMethods, mergedDefaultValues]);
200
232
  const normalisedValues = react_1.default.useMemo(() => (0, values_1.normaliseOutputValues)(flattenedSchema, formValues), [flattenedSchema, formValues]);
@@ -426,7 +458,7 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
426
458
  }
427
459
  };
428
460
  const renderFormField = (field) => {
429
- return (react_1.default.createElement(akiform_1.FormItem, { key: String(field.key), control: formMethods.control, name: field.key, tooltip: field.tooltip, help: field.help, labelDescription: field.labelDescription, required: Boolean(field.validation), className: "mb-0", valuePropName: field.type === 'checkbox' ? 'checked' : undefined }, renderFieldComponent(field)));
461
+ return (react_1.default.createElement(FilterFormItem, { key: String(field.key), control: formMethods.control, name: field.key, tooltip: field.tooltip, help: field.help, labelDescription: field.labelDescription, required: Boolean(field.validation), className: "mb-0", valuePropName: field.type === 'checkbox' ? 'checked' : undefined }, renderFieldComponent(field)));
430
462
  };
431
463
  return (react_1.default.createElement(ui_card_1.Card, { size: "small", className: "akinon-filter shadow", "data-testid": "akifilter-root" },
432
464
  react_1.default.createElement(antd_1.ConfigProvider, { theme: theme_overrides_1.themeOverrides },
@@ -1 +1 @@
1
- {"version":3,"file":"akifilter.d.ts","sourceRoot":"","sources":["../../src/akifilter.tsx"],"names":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B,CAAC;AAWzB,OAAO,KAAK,MAAM,OAAO,CAAC;AA0B1B,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,SAAS,CAAC;AAY/D,KAAK,oBAAoB,GAAG,WAAW,CAAC;AA0HxC,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,oBAAoB,GAAG,oBAAoB,IAC9D;IACF;;OAEG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACtC;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IACzD;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,IAAI,CAAC;IAClE;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AA2vBF,eAAO,MAAM,SAAS;KACpB,YAAY,SAAS,oBAAoB,uBAElC,cAAc,CAAC,YAAY,CAAC;;CAmBpC,CAAC"}
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import './styles.css';
13
13
  import { akidate } from '@akinon/akidate';
14
- import { Akiform, FormItem, useForm, useWatch } from '@akinon/akiform';
14
+ import { Akiform, useController, useForm, useWatch } from '@akinon/akiform';
15
15
  import { Button } from '@akinon/ui-button';
16
16
  import { Card } from '@akinon/ui-card';
17
17
  import { Checkbox } from '@akinon/ui-checkbox';
@@ -34,6 +34,32 @@ import { useDebouncedValue } from './hooks/use-debounced-value';
34
34
  import { i18n } from './i18n';
35
35
  import { deriveDefaultVisibleKeys, ensureSchemaOrder, extractDefaultValues, flattenSchema, getFieldAriaLabel, normaliseValuesBySchema, partitionSchema } from './utils/schema';
36
36
  import { normaliseOutputValues } from './utils/values';
37
+ const FilterFormItem = (_a) => {
38
+ var _b, _c;
39
+ var { children, control, name, valuePropName } = _a, props = __rest(_a, ["children", "control", "name", "valuePropName"]);
40
+ const { field, fieldState } = useController({ name, control });
41
+ const childrenWithProps = React.Children.map(children, child => {
42
+ if (React.isValidElement(child)) {
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ const typedChild = child;
45
+ return React.cloneElement(typedChild, Object.assign(Object.assign(Object.assign({}, field), {
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ onChange: (...params) => {
48
+ var _a, _b;
49
+ (_b = (_a = typedChild.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, params);
50
+ field.onChange(...params);
51
+ }, onBlur: () => {
52
+ var _a, _b;
53
+ (_b = (_a = typedChild.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a);
54
+ field.onBlur();
55
+ }, ref: undefined }), (valuePropName && {
56
+ [valuePropName]: field.value
57
+ })));
58
+ }
59
+ return child;
60
+ });
61
+ return (React.createElement(Akiform.Item, Object.assign({}, props, { validateStatus: fieldState.invalid ? 'error' : undefined, help: (_c = (_b = fieldState.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : props.help, className: props.className }), childrenWithProps));
62
+ };
37
63
  /**
38
64
  * Checks if a field should be disabled based on config.disabled property.
39
65
  */
@@ -184,14 +210,20 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
184
210
  writeVisibleKeys(storageKey, visibleKeys);
185
211
  onVisibleFieldsChange === null || onVisibleFieldsChange === void 0 ? void 0 : onVisibleFieldsChange(visibleKeys);
186
212
  }, [visibleKeys, onVisibleFieldsChange, storageKey]);
187
- // Track if this is the initial mount to avoid unnecessary reset
188
- const isInitialMountRef = React.useRef(true);
213
+ // Track previous mergedDefaultValues to avoid unnecessary resets
214
+ const previousMergedDefaultValuesRef = React.useRef(null);
189
215
  React.useEffect(() => {
216
+ const serialised = JSON.stringify(mergedDefaultValues);
217
+ // Skip if the values haven't actually changed (deep comparison)
218
+ if (previousMergedDefaultValuesRef.current === serialised) {
219
+ return;
220
+ }
190
221
  // Skip reset on initial mount - useForm already uses defaultValues
191
- if (isInitialMountRef.current) {
192
- isInitialMountRef.current = false;
222
+ if (previousMergedDefaultValuesRef.current === null) {
223
+ previousMergedDefaultValuesRef.current = serialised;
193
224
  return;
194
225
  }
226
+ previousMergedDefaultValuesRef.current = serialised;
195
227
  formMethods.reset(mergedDefaultValues);
196
228
  }, [formMethods, mergedDefaultValues]);
197
229
  const normalisedValues = React.useMemo(() => normaliseOutputValues(flattenedSchema, formValues), [flattenedSchema, formValues]);
@@ -423,7 +455,7 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
423
455
  }
424
456
  };
425
457
  const renderFormField = (field) => {
426
- return (React.createElement(FormItem, { key: String(field.key), control: formMethods.control, name: field.key, tooltip: field.tooltip, help: field.help, labelDescription: field.labelDescription, required: Boolean(field.validation), className: "mb-0", valuePropName: field.type === 'checkbox' ? 'checked' : undefined }, renderFieldComponent(field)));
458
+ return (React.createElement(FilterFormItem, { key: String(field.key), control: formMethods.control, name: field.key, tooltip: field.tooltip, help: field.help, labelDescription: field.labelDescription, required: Boolean(field.validation), className: "mb-0", valuePropName: field.type === 'checkbox' ? 'checked' : undefined }, renderFieldComponent(field)));
427
459
  };
428
460
  return (React.createElement(Card, { size: "small", className: "akinon-filter shadow", "data-testid": "akifilter-root" },
429
461
  React.createElement(ConfigProvider, { theme: themeOverrides },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/akifilter",
3
- "version": "1.2.0-next.7",
3
+ "version": "1.2.0-next.9",
4
4
  "private": false,
5
5
  "description": "Akifilter is a filtering library for Akinon frontend applications.",
6
6
  "type": "module",
@@ -12,21 +12,21 @@
12
12
  "dependencies": {
13
13
  "antd": "^5.27.0",
14
14
  "react-error-boundary": "^6.0.0",
15
- "@akinon/akidate": "1.1.3-next.0",
15
+ "@akinon/ui-card": "1.1.3-next.1",
16
16
  "@akinon/akiform": "1.1.2",
17
17
  "@akinon/akilocale": "1.2.1",
18
- "@akinon/icons": "1.1.2-next.1",
18
+ "@akinon/ui-button": "1.4.0-next.1",
19
19
  "@akinon/ui-checkbox": "1.3.3-next.1",
20
- "@akinon/ui-card": "1.1.3-next.1",
20
+ "@akinon/akidate": "1.1.3-next.0",
21
+ "@akinon/ui-input": "1.1.3-next.1",
21
22
  "@akinon/ui-collapse": "1.3.2-next.1",
22
- "@akinon/ui-button": "1.4.0-next.1",
23
- "@akinon/ui-date-picker": "1.3.3-next.1",
24
23
  "@akinon/ui-input-number": "1.3.3-next.1",
25
24
  "@akinon/ui-modal": "1.1.3-next.1",
26
- "@akinon/ui-input": "1.1.3-next.1",
27
- "@akinon/ui-pagination": "1.3.4-next.1",
28
- "@akinon/ui-select": "1.3.4-next.1",
29
25
  "@akinon/ui-typography": "1.1.2-next.0",
26
+ "@akinon/ui-date-picker": "1.3.3-next.1",
27
+ "@akinon/ui-select": "1.3.4-next.1",
28
+ "@akinon/ui-pagination": "1.3.4-next.1",
29
+ "@akinon/icons": "1.1.2-next.1",
30
30
  "@akinon/ui-space": "1.3.3-next.1"
31
31
  },
32
32
  "devDependencies": {
@@ -37,8 +37,8 @@
37
37
  "@akinon/akiform-builder": "1.3.5-next.1",
38
38
  "@akinon/typescript-config": "1.1.1",
39
39
  "@akinon/ui-theme": "1.1.3-next.1",
40
- "@akinon/vitest-config": "1.1.1",
41
- "@akinon/utils": "1.1.4-next.1"
40
+ "@akinon/utils": "1.1.4-next.1",
41
+ "@akinon/vitest-config": "1.1.1"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^18 || ^19",