@akinon/akifilter 1.9.1 → 1.10.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 (54) hide show
  1. package/README.md +24 -0
  2. package/dist/cjs/akifilter.d.ts +11 -0
  3. package/dist/cjs/akifilter.d.ts.map +1 -1
  4. package/dist/cjs/akifilter.js +5 -3
  5. package/dist/cjs/common/storage.d.ts +0 -1
  6. package/dist/cjs/common/storage.d.ts.map +1 -1
  7. package/dist/cjs/common/storage.js +1 -12
  8. package/dist/cjs/components/section-fieldset.d.ts +6 -1
  9. package/dist/cjs/components/section-fieldset.d.ts.map +1 -1
  10. package/dist/cjs/components/section-fieldset.js +18 -3
  11. package/dist/cjs/hooks/use-field-visibility.d.ts +7 -1
  12. package/dist/cjs/hooks/use-field-visibility.d.ts.map +1 -1
  13. package/dist/cjs/hooks/use-field-visibility.js +17 -9
  14. package/dist/cjs/hooks/use-visibility-cleanup.d.ts +10 -3
  15. package/dist/cjs/hooks/use-visibility-cleanup.d.ts.map +1 -1
  16. package/dist/cjs/hooks/use-visibility-cleanup.js +13 -9
  17. package/dist/cjs/i18n/translations/en.d.ts +0 -1
  18. package/dist/cjs/i18n/translations/en.d.ts.map +1 -1
  19. package/dist/cjs/i18n/translations/en.js +0 -1
  20. package/dist/cjs/i18n/translations/tr.d.ts +0 -1
  21. package/dist/cjs/i18n/translations/tr.d.ts.map +1 -1
  22. package/dist/cjs/i18n/translations/tr.js +0 -1
  23. package/dist/cjs/types.d.ts +11 -3
  24. package/dist/cjs/types.d.ts.map +1 -1
  25. package/dist/cjs/utils/schema.d.ts +7 -1
  26. package/dist/cjs/utils/schema.d.ts.map +1 -1
  27. package/dist/cjs/utils/schema.js +34 -10
  28. package/dist/esm/akifilter.d.ts +11 -0
  29. package/dist/esm/akifilter.d.ts.map +1 -1
  30. package/dist/esm/akifilter.js +5 -3
  31. package/dist/esm/common/storage.d.ts +0 -1
  32. package/dist/esm/common/storage.d.ts.map +1 -1
  33. package/dist/esm/common/storage.js +0 -10
  34. package/dist/esm/components/section-fieldset.d.ts +6 -1
  35. package/dist/esm/components/section-fieldset.d.ts.map +1 -1
  36. package/dist/esm/components/section-fieldset.js +18 -3
  37. package/dist/esm/hooks/use-field-visibility.d.ts +7 -1
  38. package/dist/esm/hooks/use-field-visibility.d.ts.map +1 -1
  39. package/dist/esm/hooks/use-field-visibility.js +18 -10
  40. package/dist/esm/hooks/use-visibility-cleanup.d.ts +10 -3
  41. package/dist/esm/hooks/use-visibility-cleanup.d.ts.map +1 -1
  42. package/dist/esm/hooks/use-visibility-cleanup.js +13 -9
  43. package/dist/esm/i18n/translations/en.d.ts +0 -1
  44. package/dist/esm/i18n/translations/en.d.ts.map +1 -1
  45. package/dist/esm/i18n/translations/en.js +0 -1
  46. package/dist/esm/i18n/translations/tr.d.ts +0 -1
  47. package/dist/esm/i18n/translations/tr.d.ts.map +1 -1
  48. package/dist/esm/i18n/translations/tr.js +0 -1
  49. package/dist/esm/types.d.ts +11 -3
  50. package/dist/esm/types.d.ts.map +1 -1
  51. package/dist/esm/utils/schema.d.ts +7 -1
  52. package/dist/esm/utils/schema.d.ts.map +1 -1
  53. package/dist/esm/utils/schema.js +32 -8
  54. package/package.json +17 -17
package/README.md CHANGED
@@ -99,6 +99,30 @@ dropped rather than restored — e.g. an array left behind by a
99
99
  fields are never restored at all, since a `File` cannot survive JSON
100
100
  serialisation.
101
101
 
102
+ ### Section field visibility
103
+
104
+ `onVisibleFieldsChange` reports the top-level fields only. To follow what a
105
+ section renders, pass `onSectionVisibleFieldsChange` — it receives the section's
106
+ `key` and the keys of its visible fields, on mount and whenever the list changes.
107
+
108
+ ```tsx
109
+ const handleSectionVisibleFieldsChange = useCallback(
110
+ (sectionKey: string, keys: string[]) =>
111
+ setSectionVisibleKeys(current => ({ ...current, [sectionKey]: keys })),
112
+ []
113
+ );
114
+
115
+ <Akifilter
116
+ filterSchema={filterSchema}
117
+ onSectionVisibleFieldsChange={handleSectionVisibleFieldsChange}
118
+ />;
119
+ ```
120
+
121
+ For a `selectableFields` section the keys follow the section's visibility modal;
122
+ any other section renders all of its fields and reports every key. Keep the
123
+ handler's identity stable, as with `onVisibleFieldsChange`: a new function on
124
+ every render re-notifies with an unchanged list.
125
+
102
126
  ### Section-level CSV / XLS import
103
127
 
104
128
  A section can expose its own file-import buttons in the collapse header — the
@@ -90,6 +90,17 @@ export type AkifilterProps<TFieldValues extends AkifilterFieldValues = Akifilter
90
90
  * The button only renders for sections that set `enableImportXls: true`.
91
91
  */
92
92
  onSectionImportXls?: (sectionKey: string, file: File) => void;
93
+ /**
94
+ * Notified whenever a section's visible field keys change, including on the
95
+ * first render. Receives the section's `key` and the keys of the fields it
96
+ * currently renders, so one handler can serve every section.
97
+ *
98
+ * For a `selectableFields` section this is the user's selection from the
99
+ * section's visibility modal; any other section renders all of its fields,
100
+ * so it reports every field key. Keep the handler's identity stable — a new
101
+ * function on every render re-notifies with an unchanged list.
102
+ */
103
+ onSectionVisibleFieldsChange?: (sectionKey: string, keys: Array<Path<TFieldValues>>) => void;
93
104
  };
94
105
  export declare const Akifilter: {
95
106
  <TFieldValues extends AkifilterFieldValues = FieldValues>(props: AkifilterProps<TFieldValues>): React.JSX.Element;
@@ -1 +1 @@
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;AAYzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAc1B,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,8BAA8B,CAAC;AAgBtC,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EAEf,eAAe,EAChB,MAAM,SAAS,CAAC;AAYjB,KAAK,oBAAoB,GAAG,WAAW,CAAC;AAiLxC,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,oBAAoB,GAAG,oBAAoB,I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,MAAM,IAAI,CAAC;IACxB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAClD;;;OAGG;IACH,sBAAsB,CAAC,EAAE,aAAa,EAAE,CAAC;IACzC;;OAEG;IACH,sBAAsB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C;;;;;OAKG;IACH,aAAa,CAAC,EAAE,eAAe,EAAE,CAAC;IAClC;;OAEG;IACH,qBAAqB,CAAC,EAAE,CAAC,aAAa,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACnE;;;;;;;;;;OAUG;IACH,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9D;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9D;;;;;;;;;OASG;IACH,4BAA4B,CAAC,EAAE,CAC7B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAC5B,IAAI,CAAC;CACX,CAAC;AAu9BF,eAAO,MAAM,SAAS;KACpB,YAAY,SAAS,oBAAoB,uBAElC,cAAc,CAAC,YAAY,CAAC;;CAoBpC,CAAC"}
@@ -134,7 +134,7 @@ const resolveClearedFieldValue = (field, defaultValue) => {
134
134
  return undefined;
135
135
  }
136
136
  };
137
- const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onValuesChange, onVisibleFieldsChange, onImportCsv, onImportXls, onClearAll, enableImportCsv, enableImportXls, filterActionsRef, externalAppliedFilters, onRemoveExternalFilter, filterButtons, onFilterButtonsChange, onSectionImportCsv, onSectionImportXls }) => {
137
+ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onValuesChange, onVisibleFieldsChange, onImportCsv, onImportXls, onClearAll, enableImportCsv, enableImportXls, filterActionsRef, externalAppliedFilters, onRemoveExternalFilter, filterButtons, onFilterButtonsChange, onSectionImportCsv, onSectionImportXls, onSectionVisibleFieldsChange }) => {
138
138
  // Separate regular fields from section fields
139
139
  const { regularFields, sectionFields } = react_1.default.useMemo(() => (0, schema_1.partitionSchema)(filterSchema), [filterSchema]);
140
140
  const excludeSectionKeys = react_1.default.useMemo(() => (0, schema_1.deriveExcludeSectionKeys)(sectionFields), [sectionFields]);
@@ -311,6 +311,7 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
311
311
  const { visibleKeys, setVisibleKeys, visibleFields, openModal, modalProps } = (0, use_field_visibility_1.useFieldVisibility)({
312
312
  fields: regularFields,
313
313
  storageKey,
314
+ initialValues: mergedDefaultValues,
314
315
  onVisibleKeysChange: handleVisibleKeysChange
315
316
  });
316
317
  const normalisedValues = react_1.default.useMemo(() => (0, values_1.normaliseOutputValues)(flattenedSchema, formValues), [flattenedSchema, formValues]);
@@ -559,6 +560,7 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
559
560
  (0, use_visibility_cleanup_1.useVisibilityCleanup)({
560
561
  visibleKeys,
561
562
  regularFields,
563
+ initialValues: mergedDefaultValues,
562
564
  onRemove: handleRemoveFilter
563
565
  });
564
566
  const handleAppliedFilterRemove = react_1.default.useCallback((key) => {
@@ -613,7 +615,7 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
613
615
  case constants_1.FIELD_TYPES.CHECKBOX:
614
616
  return react_1.default.createElement(ui_checkbox_1.Checkbox, { disabled: isDisabled }, field.label);
615
617
  case constants_1.FIELD_TYPES.DATE:
616
- return (react_1.default.createElement(ui_date_picker_1.DatePicker, { placeholder: field.placeholder, showTime: field.showTime, suffixIcon: "calendar", suffixIconSize: "16px", "aria-label": ariaLabel, disabled: isDisabled }));
618
+ return (react_1.default.createElement(ui_date_picker_1.DatePicker, { placeholder: field.placeholder, size: "large", showTime: field.showTime, suffixIcon: "calendar", suffixIconSize: "16px", "aria-label": ariaLabel, disabled: isDisabled }));
617
619
  case constants_1.FIELD_TYPES.TEXTAREA:
618
620
  return (react_1.default.createElement(ui_input_1.InputTextArea, { placeholder: field.placeholder, autoSize: { minRows: 3, maxRows: 6 }, "aria-label": ariaLabel, disabled: isDisabled }));
619
621
  case constants_1.FIELD_TYPES.FILE:
@@ -656,7 +658,7 @@ const AkifilterContent = ({ filterSchema, storageNamespace, defaultValues, onVal
656
658
  visibleFields.length === 0 && regularFields.length > 0 ? (react_1.default.createElement("div", { className: "akinon-filter__empty" }, i18n_1.i18n.t('form.noVisibleFields'))) : null),
657
659
  sectionFields.length > 0 && (react_1.default.createElement("div", { className: "akinon-filter__section-fields" }, sectionFields.map(section => (react_1.default.createElement(section_fieldset_1.SectionFieldset, { key: String(section.key), section: section, storageKey: storageKey, renderFormField: renderFormField, onRemoveField: handleRemoveFilter, formValues: normalisedValues, onImportCsv: onSectionImportCsv &&
658
660
  (file => onSectionImportCsv(String(section.key), file)), onImportXls: onSectionImportXls &&
659
- (file => onSectionImportXls(String(section.key), file)) }))))))),
661
+ (file => onSectionImportXls(String(section.key), file)), onVisibleFieldsChange: onSectionVisibleFieldsChange }))))))),
660
662
  react_1.default.createElement(visibility_modal_1.VisibilityModal, Object.assign({}, modalProps)))));
661
663
  };
662
664
  const AkifilterEmptyState = () => {
@@ -4,7 +4,6 @@ export declare const buildStorageKey: <TFieldValues extends FieldValues>(schema:
4
4
  export declare const readVisibleKeys: <TFieldValues extends FieldValues>(schema: AkifilterField<TFieldValues>[], storageKey: string) => string[] | null;
5
5
  export declare const writeVisibleKeys: (storageKey: string, keys: string[]) => void;
6
6
  export declare const buildSectionVisibilityKey: (storageKey: string, sectionKey: string | number) => string;
7
- export declare const clearVisibleKeys: (storageKey: string) => void;
8
7
  export declare const readStoredValues: <TFieldValues extends FieldValues>(schema: AkifilterField<TFieldValues>[], storageKey: string) => Partial<TFieldValues> | null;
9
8
  export declare const writeStoredValues: <TFieldValues extends FieldValues>(storageKey: string, values: Partial<TFieldValues>) => void;
10
9
  export declare const clearStoredValues: (storageKey: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/common/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA4B/C,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,WAAW,EAC9D,QAAQ,cAAc,CAAC,YAAY,CAAC,EAAE,EACtC,YAAY,MAAM,KACjB,MAKF,CAAC;AAIF,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,WAAW,EAC9D,QAAQ,cAAc,CAAC,YAAY,CAAC,EAAE,EACtC,YAAY,MAAM,KACjB,MAAM,EAAE,GAAG,IAoBb,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,EAAE,MAAM,MAAM,EAAE,KAAG,IAQrE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,YAAY,MAAM,EAClB,YAAY,MAAM,GAAG,MAAM,KAC1B,MAAuD,CAAC;AAE3D,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,KAAG,IAQrD,CAAC;AA0DF,eAAO,MAAM,gBAAgB,GAAI,YAAY,SAAS,WAAW,EAC/D,QAAQ,cAAc,CAAC,YAAY,CAAC,EAAE,EACtC,YAAY,MAAM,KACjB,OAAO,CAAC,YAAY,CAAC,GAAG,IAqC1B,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,YAAY,SAAS,WAAW,EAChE,YAAY,MAAM,EAClB,QAAQ,OAAO,CAAC,YAAY,CAAC,KAC5B,IAeF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,YA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,KAC5B,IAeF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,IAQtD,CAAC;AAKF,eAAO,MAAM,sBAAsB,GACjC,YAAY,MAAM,KACjB,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAwB3B,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,YAAY,MAAM,EAClB,QAAQ,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,KAC7B,IAcF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,YAAY,MAAM,KAAG,IAQ5D,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clearStoredButtonValues = exports.writeStoredButtonValues = exports.readStoredButtonValues = exports.clearStoredValues = exports.writeStoredValues = exports.readStoredValues = exports.clearVisibleKeys = exports.buildSectionVisibilityKey = exports.writeVisibleKeys = exports.readVisibleKeys = exports.buildStorageKey = void 0;
3
+ exports.clearStoredButtonValues = exports.writeStoredButtonValues = exports.readStoredButtonValues = exports.clearStoredValues = exports.writeStoredValues = exports.readStoredValues = exports.buildSectionVisibilityKey = exports.writeVisibleKeys = exports.readVisibleKeys = exports.buildStorageKey = void 0;
4
4
  const constants_1 = require("../constants");
5
5
  const i18n_1 = require("../i18n");
6
6
  const STORAGE_PREFIX = 'akifilter:v1';
@@ -65,17 +65,6 @@ const writeVisibleKeys = (storageKey, keys) => {
65
65
  exports.writeVisibleKeys = writeVisibleKeys;
66
66
  const buildSectionVisibilityKey = (storageKey, sectionKey) => `${storageKey}:section:${String(sectionKey)}`;
67
67
  exports.buildSectionVisibilityKey = buildSectionVisibilityKey;
68
- const clearVisibleKeys = (storageKey) => {
69
- if (!isBrowser)
70
- return;
71
- try {
72
- window.localStorage.removeItem(storageKey);
73
- }
74
- catch (error) {
75
- console.warn(i18n_1.i18n.t('errors.storage.clearVisibility'), error);
76
- }
77
- };
78
- exports.clearVisibleKeys = clearVisibleKeys;
79
68
  const buildValuesStorageKey = (storageKey) => `${storageKey}${VALUES_SUFFIX}`;
80
69
  /**
81
70
  * Guards a persisted value against schema drift.
@@ -1,4 +1,4 @@
1
- import type { FieldValues } from '@akinon/akiform';
1
+ import type { FieldValues, Path } from '@akinon/akiform';
2
2
  import React from 'react';
3
3
  import type { AkifilterField, AkifilterSectionField } from '../types';
4
4
  type SectionImportHandlers = {
@@ -30,6 +30,11 @@ type SectionFieldsetProps<TFieldValues extends FieldValues = FieldValues> = Sect
30
30
  * Current normalised form values, needed to resolve dynamic visibility.
31
31
  */
32
32
  formValues: Partial<TFieldValues> | undefined;
33
+ /**
34
+ * Notified with the section's key and the keys of the fields it currently
35
+ * renders, on mount and whenever that list changes.
36
+ */
37
+ onVisibleFieldsChange?: (sectionKey: string, keys: Array<Path<TFieldValues>>) => void;
33
38
  };
34
39
  /**
35
40
  * Renders a single section field. Sections flagged with `selectableFields`
@@ -1 +1 @@
1
- {"version":3,"file":"section-fieldset.d.ts","sourceRoot":"","sources":["../../../src/components/section-fieldset.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA+CtE,KAAK,qBAAqB,GAAG;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACnC;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CACpC,CAAC;AA8JF,KAAK,oBAAoB,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,IACtE,qBAAqB,GAAG;IACtB,OAAO,EAAE,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAC7C;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,CAA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AC;IAC9C;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAC5B,IAAI,CAAC;CACX,CAAC;AAkJJ;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,WAAW,GAAG,WAAW,EAC5E,OAAO,oBAAoB,CAAC,YAAY,CAAC,sBAO1C,CAAC"}
@@ -5,6 +5,7 @@ const icons_1 = require("@akinon/icons");
5
5
  const ui_button_1 = require("@akinon/ui-button");
6
6
  const ui_collapse_1 = require("@akinon/ui-collapse");
7
7
  const ui_typography_1 = require("@akinon/ui-typography");
8
+ const lodash_es_1 = require("lodash-es");
8
9
  const react_1 = require("react");
9
10
  const storage_1 = require("../common/storage");
10
11
  const constants_1 = require("../constants");
@@ -111,11 +112,16 @@ const SectionActionsCollapse = ({ sectionKey, label, defaultExpanded, actions, i
111
112
  * mirroring the top-level filter field-selection behaviour. Import buttons are
112
113
  * rendered alongside the funnel when the section opts into them.
113
114
  */
114
- const SelectableSectionFieldset = ({ section, storageKey, renderFormField, onRemoveField, formValues, onImportCsv, onImportXls }) => {
115
+ const SelectableSectionFieldset = ({ section, storageKey, renderFormField, onRemoveField, formValues, onImportCsv, onImportXls, onVisibleFieldsChange }) => {
115
116
  const sectionStorageKey = react_1.default.useMemo(() => (0, storage_1.buildSectionVisibilityKey)(storageKey, section.key), [storageKey, section.key]);
117
+ const handleVisibleKeysChange = react_1.default.useCallback((keys) => {
118
+ onVisibleFieldsChange === null || onVisibleFieldsChange === void 0 ? void 0 : onVisibleFieldsChange(String(section.key), keys);
119
+ }, [onVisibleFieldsChange, section.key]);
116
120
  const { visibleKeys, setVisibleKeys, visibleFields, openModal, modalProps } = (0, use_field_visibility_1.useFieldVisibility)({
117
121
  fields: section.fields,
118
- storageKey: sectionStorageKey
122
+ storageKey: sectionStorageKey,
123
+ initialValues: formValues,
124
+ onVisibleKeysChange: handleVisibleKeysChange
119
125
  });
120
126
  (0, use_dynamic_visibility_1.useDynamicVisibility)({
121
127
  regularFields: section.fields,
@@ -125,6 +131,7 @@ const SelectableSectionFieldset = ({ section, storageKey, renderFormField, onRem
125
131
  (0, use_visibility_cleanup_1.useVisibilityCleanup)({
126
132
  visibleKeys,
127
133
  regularFields: section.fields,
134
+ initialValues: formValues,
128
135
  onRemove: onRemoveField
129
136
  });
130
137
  const actions = resolveSectionHeaderActions({
@@ -141,7 +148,15 @@ const SelectableSectionFieldset = ({ section, storageKey, renderFormField, onRem
141
148
  * A section that always renders every one of its fields. Falls back to the
142
149
  * plain collapse markup unless the header needs action buttons (e.g. import).
143
150
  */
144
- const PlainSectionFieldset = ({ section, renderFormField, onImportCsv, onImportXls }) => {
151
+ const PlainSectionFieldset = ({ section, renderFormField, onImportCsv, onImportXls, onVisibleFieldsChange }) => {
152
+ const [fieldKeys, setFieldKeys] = react_1.default.useState(() => section.fields.map(field => String(field.key)));
153
+ react_1.default.useEffect(() => {
154
+ const nextFieldKeys = section.fields.map(field => String(field.key));
155
+ setFieldKeys(previous => (0, lodash_es_1.isEqual)(previous, nextFieldKeys) ? previous : nextFieldKeys);
156
+ }, [section.fields]);
157
+ react_1.default.useEffect(() => {
158
+ onVisibleFieldsChange === null || onVisibleFieldsChange === void 0 ? void 0 : onVisibleFieldsChange(String(section.key), fieldKeys);
159
+ }, [fieldKeys, onVisibleFieldsChange, section.key]);
145
160
  const actions = resolveSectionHeaderActions({
146
161
  section,
147
162
  onImportCsv,
@@ -12,6 +12,12 @@ type UseFieldVisibilityParams<TFieldValues extends FieldValues> = {
12
12
  * pass distinct keys per group so selections never collide.
13
13
  */
14
14
  storageKey: string;
15
+ /**
16
+ * Form values as of the first render. A `config.visible` function is resolved
17
+ * against these, so a field whose visibility depends on a restored value is
18
+ * visible from the very first render instead of appearing one commit later.
19
+ */
20
+ initialValues?: Partial<TFieldValues>;
15
21
  /**
16
22
  * Notified whenever the resolved visible keys change.
17
23
  */
@@ -22,7 +28,7 @@ type UseFieldVisibilityParams<TFieldValues extends FieldValues> = {
22
28
  * a single group of fields. Used both for the top-level filters and for each
23
29
  * selectable section so the two share one implementation.
24
30
  */
25
- export declare const useFieldVisibility: <TFieldValues extends FieldValues = FieldValues>({ fields, storageKey, onVisibleKeysChange }: UseFieldVisibilityParams<TFieldValues>) => {
31
+ export declare const useFieldVisibility: <TFieldValues extends FieldValues = FieldValues>({ fields, storageKey, initialValues, onVisibleKeysChange }: UseFieldVisibilityParams<TFieldValues>) => {
26
32
  visibleKeys: string[];
27
33
  setVisibleKeys: React.Dispatch<React.SetStateAction<string[]>>;
28
34
  visibleFields: import("../types").AkifilterField<TFieldValues>[];
@@ -1 +1 @@
1
- {"version":3,"file":"use-field-visibility.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-field-visibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAOhD,KAAK,wBAAwB,CAAC,YAAY,SAAS,WAAW,IAAI;IAChE;;;OAGG;IACH,MAAM,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IACtC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,6CAIC,wBAAwB,CAAC,YAAY,CAAC;;;;;;;;;;;;oCA0HP,MAAM;kCA3D9B,MAAM;mCAgEiB,MAAM,YAAY,MAAM;;;;CA6BxD,CAAC"}
1
+ {"version":3,"file":"use-field-visibility.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-field-visibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAQhD,KAAK,wBAAwB,CAAC,YAAY,SAAS,WAAW,IAAI;IAChE;;;OAGG;IACH,MAAM,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IACtC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACtC;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,4DAKC,wBAAwB,CAAC,YAAY,CAAC;;;;;;;;;;;;oCAsIP,MAAM;kCA7D9B,MAAM;mCAkEiB,MAAM,YAAY,MAAM;;;;CA6BxD,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useFieldVisibility = void 0;
4
+ const lodash_es_1 = require("lodash-es");
4
5
  const react_1 = require("react");
5
6
  const storage_1 = require("../common/storage");
6
7
  const constants_1 = require("../constants");
@@ -10,26 +11,25 @@ const schema_1 = require("../utils/schema");
10
11
  * a single group of fields. Used both for the top-level filters and for each
11
12
  * selectable section so the two share one implementation.
12
13
  */
13
- const useFieldVisibility = ({ fields, storageKey, onVisibleKeysChange }) => {
14
+ const useFieldVisibility = ({ fields, storageKey, initialValues, onVisibleKeysChange }) => {
15
+ const initialValuesRef = react_1.default.useRef(initialValues);
14
16
  const [isModalOpen, setIsModalOpen] = react_1.default.useState(false);
15
17
  const [searchTerm, setSearchTerm] = react_1.default.useState('');
16
18
  const [modalPage, setModalPage] = react_1.default.useState(1);
17
19
  const [modalPageSize, setModalPageSize] = react_1.default.useState(constants_1.DEFAULT_MODAL_PAGE_SIZE);
18
20
  const resolveInitialVisibleKeys = react_1.default.useCallback(() => {
19
21
  const storedKeys = (0, storage_1.readVisibleKeys)(fields, storageKey);
20
- const defaultKeys = (0, schema_1.deriveDefaultVisibleKeys)(fields);
21
22
  const baseKeys = storedKeys && storedKeys.length > 0
22
23
  ? (0, schema_1.ensureSchemaOrder)(fields, storedKeys)
23
- : defaultKeys;
24
+ : (0, schema_1.deriveDefaultVisibleKeys)(fields);
24
25
  return fields.reduce((acc, field) => {
25
26
  const key = String(field.key);
26
- const explicitVisibility = (0, schema_1.resolveFieldVisibility)(field);
27
- if (explicitVisibility !== undefined) {
28
- if (explicitVisibility)
27
+ if ((0, schema_1.hasDynamicVisibility)(field)) {
28
+ const visibility = (0, schema_1.resolveFieldVisibility)(field, initialValuesRef.current);
29
+ if (visibility)
29
30
  acc.push(key);
30
31
  return acc;
31
32
  }
32
- // No explicit boolean visibility, use stored/default
33
33
  if (baseKeys.includes(key)) {
34
34
  acc.push(key);
35
35
  }
@@ -41,13 +41,20 @@ const useFieldVisibility = ({ fields, storageKey, onVisibleKeysChange }) => {
41
41
  setVisibleKeys(previous => {
42
42
  const ordered = (0, schema_1.ensureSchemaOrder)(fields, previous);
43
43
  if (ordered.length) {
44
- return ordered;
44
+ return (0, lodash_es_1.isEqual)(ordered, previous) ? previous : ordered;
45
45
  }
46
46
  return resolveInitialVisibleKeys();
47
47
  });
48
48
  }, [fields, resolveInitialVisibleKeys]);
49
+ // Only a real toggle is persisted. Writing the derived set on mount would
50
+ // make every user look like they had made a choice, and the storage key is
51
+ // hashed from the field signature alone — so a later `config.visible` change
52
+ // would never reach anyone who had simply rendered the filter once.
53
+ const hasUserSelectionRef = react_1.default.useRef(false);
49
54
  react_1.default.useEffect(() => {
50
- (0, storage_1.writeVisibleKeys)(storageKey, visibleKeys);
55
+ if (hasUserSelectionRef.current) {
56
+ (0, storage_1.writeVisibleKeys)(storageKey, visibleKeys);
57
+ }
51
58
  onVisibleKeysChange === null || onVisibleKeysChange === void 0 ? void 0 : onVisibleKeysChange(visibleKeys);
52
59
  }, [visibleKeys, onVisibleKeysChange, storageKey]);
53
60
  const openModal = react_1.default.useCallback(() => {
@@ -59,6 +66,7 @@ const useFieldVisibility = ({ fields, storageKey, onVisibleKeysChange }) => {
59
66
  setIsModalOpen(false);
60
67
  }, []);
61
68
  const handleToggleVisibility = react_1.default.useCallback((key) => {
69
+ hasUserSelectionRef.current = true;
62
70
  setVisibleKeys(prev => {
63
71
  const exists = prev.includes(key);
64
72
  if (exists && prev.length === 1) {
@@ -2,12 +2,19 @@ import type { FieldValues } from '@akinon/akiform';
2
2
  import type { AkifilterSchema } from '../types';
3
3
  /**
4
4
  * Cleans up form values when fields become hidden.
5
- * On first render, clears fields explicitly marked as invisible.
6
- * On subsequent renders, clears fields that were removed from visibleKeys.
5
+ * On first render, clears fields resolving to `visible: false` that the user
6
+ * has not turned back on. On subsequent renders, clears fields that were
7
+ * removed from visibleKeys.
7
8
  */
8
- export declare const useVisibilityCleanup: <TFieldValues extends FieldValues = FieldValues>({ visibleKeys, regularFields, onRemove }: {
9
+ export declare const useVisibilityCleanup: <TFieldValues extends FieldValues = FieldValues>({ visibleKeys, regularFields, initialValues, onRemove }: {
9
10
  visibleKeys: string[];
10
11
  regularFields: AkifilterSchema<TFieldValues>;
12
+ /**
13
+ * Form values as of the first render, so a `config.visible` function is
14
+ * resolved against restored values rather than an empty object — otherwise
15
+ * the value that makes the field visible is the one this hook deletes.
16
+ */
17
+ initialValues?: Partial<TFieldValues>;
11
18
  onRemove: (key: string) => void;
12
19
  }) => void;
13
20
  //# sourceMappingURL=use-visibility-cleanup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-visibility-cleanup.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-visibility-cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AA+BhD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,0CAIC;IACD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,SAcA,CAAC"}
1
+ {"version":3,"file":"use-visibility-cleanup.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-visibility-cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAoChD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,yDAKC;IACD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACtC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,SAgBA,CAAC"}
@@ -4,34 +4,38 @@ exports.useVisibilityCleanup = void 0;
4
4
  const lodash_es_1 = require("lodash-es");
5
5
  const react_1 = require("react");
6
6
  const schema_1 = require("../utils/schema");
7
- const getInitialKeysToClean = (fields) => fields
8
- .filter(field => (0, schema_1.resolveFieldVisibility)(field) === false)
9
- .map(field => String(field.key));
7
+ const getInitialKeysToClean = (fields, visibleKeys, formValues) => fields
8
+ .filter(field => (0, schema_1.resolveFieldVisibility)(field, formValues) === false)
9
+ .map(field => String(field.key))
10
+ .filter(key => !visibleKeys.includes(key));
10
11
  const getRemovedKeys = (prev, current) => prev.filter(key => !current.includes(key));
11
12
  const cleanupKeys = (keys, onRemove) => {
12
13
  keys.forEach(key => onRemove(key));
13
14
  };
14
- const resolveKeysToClean = ({ prev, current, fields }) => {
15
+ const resolveKeysToClean = ({ prev, current, fields, formValues }) => {
15
16
  if (prev === null)
16
- return getInitialKeysToClean(fields);
17
+ return getInitialKeysToClean(fields, current, formValues);
17
18
  if ((0, lodash_es_1.isEqual)(prev, current))
18
19
  return [];
19
20
  return getRemovedKeys(prev, current);
20
21
  };
21
22
  /**
22
23
  * Cleans up form values when fields become hidden.
23
- * On first render, clears fields explicitly marked as invisible.
24
- * On subsequent renders, clears fields that were removed from visibleKeys.
24
+ * On first render, clears fields resolving to `visible: false` that the user
25
+ * has not turned back on. On subsequent renders, clears fields that were
26
+ * removed from visibleKeys.
25
27
  */
26
- const useVisibilityCleanup = ({ visibleKeys, regularFields, onRemove }) => {
28
+ const useVisibilityCleanup = ({ visibleKeys, regularFields, initialValues, onRemove }) => {
27
29
  const previousVisibleKeysRef = (0, react_1.useRef)(null);
30
+ const initialValuesRef = (0, react_1.useRef)(initialValues);
28
31
  (0, react_1.useEffect)(() => {
29
32
  const prev = previousVisibleKeysRef.current;
30
33
  previousVisibleKeysRef.current = visibleKeys;
31
34
  const keysToClean = resolveKeysToClean({
32
35
  prev,
33
36
  current: visibleKeys,
34
- fields: regularFields
37
+ fields: regularFields,
38
+ formValues: initialValuesRef.current
35
39
  });
36
40
  cleanupKeys(keysToClean, onRemove);
37
41
  }, [visibleKeys, onRemove, regularFields]);
@@ -40,7 +40,6 @@ declare const translations: {
40
40
  readonly storage: {
41
41
  readonly readVisibility: "Akifilter: unable to read visibility state from storage";
42
42
  readonly writeVisibility: "Akifilter: unable to persist visibility state";
43
- readonly clearVisibility: "Akifilter: unable to clear visibility state";
44
43
  readonly readValues: "Akifilter: unable to read values from storage";
45
44
  readonly writeValues: "Akifilter: unable to persist values";
46
45
  readonly clearValues: "Akifilter: unable to clear stored values";
@@ -1 +1 @@
1
- {"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../src/i18n/translations/en.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDR,CAAC;AAEX,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../../../src/i18n/translations/en.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDR,CAAC;AAEX,eAAe,YAAY,CAAC"}
@@ -42,7 +42,6 @@ const translations = {
42
42
  storage: {
43
43
  readVisibility: 'Akifilter: unable to read visibility state from storage',
44
44
  writeVisibility: 'Akifilter: unable to persist visibility state',
45
- clearVisibility: 'Akifilter: unable to clear visibility state',
46
45
  readValues: 'Akifilter: unable to read values from storage',
47
46
  writeValues: 'Akifilter: unable to persist values',
48
47
  clearValues: 'Akifilter: unable to clear stored values',
@@ -40,7 +40,6 @@ declare const translations: {
40
40
  readonly storage: {
41
41
  readonly readVisibility: "Akifilter: görünürlük durumu depodan okunamadı";
42
42
  readonly writeVisibility: "Akifilter: görünürlük durumu kalıcı hale getirilemedi";
43
- readonly clearVisibility: "Akifilter: görünürlük durumu temizlenemedi";
44
43
  readonly readValues: "Akifilter: değerler depodan okunamadı";
45
44
  readonly writeValues: "Akifilter: değerler kalıcı hale getirilemedi";
46
45
  readonly clearValues: "Akifilter: kayıtlı değerler temizlenemedi";
@@ -1 +1 @@
1
- {"version":3,"file":"tr.d.ts","sourceRoot":"","sources":["../../../../src/i18n/translations/tr.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDR,CAAC;AAEX,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"tr.d.ts","sourceRoot":"","sources":["../../../../src/i18n/translations/tr.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDR,CAAC;AAEX,eAAe,YAAY,CAAC"}
@@ -42,7 +42,6 @@ const translations = {
42
42
  storage: {
43
43
  readVisibility: 'Akifilter: görünürlük durumu depodan okunamadı',
44
44
  writeVisibility: 'Akifilter: görünürlük durumu kalıcı hale getirilemedi',
45
- clearVisibility: 'Akifilter: görünürlük durumu temizlenemedi',
46
45
  readValues: 'Akifilter: değerler depodan okunamadı',
47
46
  writeValues: 'Akifilter: değerler kalıcı hale getirilemedi',
48
47
  clearValues: 'Akifilter: kayıtlı değerler temizlenemedi',
@@ -9,7 +9,15 @@ export interface AkifilterFieldConfig<TFieldValues extends FieldValues = FieldVa
9
9
  disabled?: boolean | ((formValues: TFieldValues) => boolean);
10
10
  /**
11
11
  * Controls whether the field is visible.
12
- * Can be a boolean or a function that receives form values and returns a boolean.
12
+ *
13
+ * A boolean seeds the first render only: it decides whether the field is part
14
+ * of the default visible set, and from then on the user's selection in the
15
+ * "Select visible filters" modal wins and is restored on every later mount.
16
+ *
17
+ * A function is dynamic and stays authoritative: it is re-evaluated on every
18
+ * form value change and receives the field's current visibility. A constant
19
+ * function (`() => true`) is therefore how a field opts out of the picker
20
+ * altogether.
13
21
  */
14
22
  visible?: boolean | ((formValues: TFieldValues, currentVisible?: boolean) => boolean);
15
23
  }
@@ -106,14 +114,14 @@ type AkifilterFieldExtras<TFieldValues extends FieldValues = FieldValues> = {
106
114
  /**
107
115
  * Overrides `label` for this field's applied-filter chip only.
108
116
  *
109
- * The form input and the "select visible filters" modal keep using `label`.
117
+ * The form input and the "Select visible filters" modal keep using `label`.
110
118
  * Use this when the chip needs a shorter or more explicit name than the form
111
119
  * does (e.g. `label: 'Created At'` next to a date range, `appliedLabel:
112
120
  * 'Order date'` in the chip).
113
121
  */
114
122
  appliedLabel?: string;
115
123
  /**
116
- * Overrides `label` for this field's row in the "select visible filters"
124
+ * Overrides `label` for this field's row in the "Select visible filters"
117
125
  * modal only. Also what the modal's search box matches against.
118
126
  *
119
127
  * The form input and the applied-filter chip keep using `label`. Use this
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,oBAAoB,CACnC,YAAY,SAAS,WAAW,GAAG,WAAW;IAE9C;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,UAAU,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC;IAC7D;;;OAGG;IACH,OAAO,CAAC,EACJ,OAAO,GACP,CAAC,CAAC,UAAU,EAAE,YAAY,EAAE,cAAc,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;CACvE;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;;OAMG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,KAAK,oBAAoB,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,IAAI;IAC1E;;OAEG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAC5C;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EA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AA0C;QAC1C,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;CACF"}
@@ -30,8 +30,14 @@ export declare const ensureSchemaOrder: <TFieldValues extends FieldValues = Fiel
30
30
  * Resolves the visibility of a field.
31
31
  */
32
32
  export declare const resolveFieldVisibility: <TFieldValues extends FieldValues = FieldValues>(field: AkifilterField<TFieldValues>, formValues?: TFieldValues, currentVisible?: boolean) => boolean | undefined;
33
+ export declare const hasDynamicVisibility: <TFieldValues extends FieldValues>(field: AkifilterField<TFieldValues>) => boolean;
34
+ /**
35
+ * The visible set of a first render: the fields statically marked
36
+ * `config.visible: true` if the schema marks any, otherwise the first
37
+ * `DEFAULT_VISIBLE_COUNT` fields. Fields with a dynamic `config.visible` take
38
+ * no part in it.
39
+ */
33
40
  export declare const deriveDefaultVisibleKeys: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>) => string[];
34
41
  export declare const extractDefaultValues: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>) => Partial<TFieldValues>;
35
- export declare const hasDynamicVisibility: <TFieldValues extends FieldValues>(field: AkifilterField<TFieldValues>) => boolean;
36
42
  export declare const normaliseValuesBySchema: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>, values?: Partial<TFieldValues>) => Partial<TFieldValues>;
37
43
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/utils/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,YAAY,SAAS,WAAW,GAAG,WAAW,EAC1E,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,eAAe,CAAC,YAAY,CAW9B,CAAC;AAEF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QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,OAAO,CAAC,YAAY,CAQtB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,EACrC,SAAS,OAAO,CAAC,YAAY,CAAC,KAC7B,OAAO,CAAC,YAAY,CA0CtB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normaliseValuesBySchema = exports.hasDynamicVisibility = exports.extractDefaultValues = exports.deriveDefaultVisibleKeys = exports.resolveFieldVisibility = exports.ensureSchemaOrder = exports.getFieldAriaLabel = exports.getVisibilityLabel = exports.getAppliedLabel = exports.getDisplayLabel = exports.deriveExcludeSectionKeys = exports.partitionSchema = exports.flattenSchema = void 0;
3
+ exports.normaliseValuesBySchema = exports.extractDefaultValues = exports.deriveDefaultVisibleKeys = exports.hasDynamicVisibility = exports.resolveFieldVisibility = exports.ensureSchemaOrder = exports.getFieldAriaLabel = exports.getVisibilityLabel = exports.getAppliedLabel = exports.getDisplayLabel = exports.deriveExcludeSectionKeys = exports.partitionSchema = exports.flattenSchema = void 0;
4
4
  const akidate_1 = require("@akinon/akidate");
5
5
  const lodash_es_1 = require("lodash-es");
6
6
  const constants_1 = require("../constants");
@@ -79,14 +79,40 @@ const resolveVisibilityValue = (value, formValues, currentVisible) => {
79
79
  */
80
80
  const resolveFieldVisibility = (field, formValues, currentVisible) => { var _a; return resolveVisibilityValue((_a = field.config) === null || _a === void 0 ? void 0 : _a.visible, formValues, currentVisible); };
81
81
  exports.resolveFieldVisibility = resolveFieldVisibility;
82
+ const hasDynamicVisibility = (field) => { var _a; return (0, lodash_es_1.isFunction)((_a = field.config) === null || _a === void 0 ? void 0 : _a.visible); };
83
+ exports.hasDynamicVisibility = hasDynamicVisibility;
84
+ /*
85
+ * Both helpers below skip fields with a dynamic `config.visible`. Such a field
86
+ * declares nothing about the default set: `useFieldVisibility` resolves it from
87
+ * its own function and never consults the default set for it. Resolving the
88
+ * function here would only mean asking it the wrong question — its answer is
89
+ * "am I visible for these values", not "am I part of the default set" — and a
90
+ * `() => true` field would silently switch the whole schema to the explicit
91
+ * branch, dropping the fallback for every other field.
92
+ */
93
+ const explicitVisibleKeys = (schema) => schema
94
+ .filter(field => !(0, exports.hasDynamicVisibility)(field) && (0, exports.resolveFieldVisibility)(field) === true)
95
+ .map(field => String(field.key));
96
+ /**
97
+ * The first `DEFAULT_VISIBLE_COUNT` fields, minus the ones asking to be hidden.
98
+ * `config.visible: false` never reaches the picker's initial selection, so the
99
+ * fallback has to drop those keys itself.
100
+ */
101
+ const fallbackVisibleKeys = (schema) => schema
102
+ .slice(0, constants_1.DEFAULT_VISIBLE_COUNT)
103
+ .filter(field => !(0, exports.hasDynamicVisibility)(field) && (0, exports.resolveFieldVisibility)(field) !== false)
104
+ .map(field => String(field.key));
105
+ /**
106
+ * The visible set of a first render: the fields statically marked
107
+ * `config.visible: true` if the schema marks any, otherwise the first
108
+ * `DEFAULT_VISIBLE_COUNT` fields. Fields with a dynamic `config.visible` take
109
+ * no part in it.
110
+ */
82
111
  const deriveDefaultVisibleKeys = (schema) => {
83
- const explicitKeys = schema
84
- .filter(field => (0, exports.resolveFieldVisibility)(field) === true)
85
- .map(field => String(field.key));
86
- if (explicitKeys.length > 0) {
87
- return (0, exports.ensureSchemaOrder)(schema, explicitKeys);
88
- }
89
- return schema.slice(0, constants_1.DEFAULT_VISIBLE_COUNT).map(field => String(field.key));
112
+ const explicitKeys = explicitVisibleKeys(schema);
113
+ return explicitKeys.length > 0
114
+ ? (0, exports.ensureSchemaOrder)(schema, explicitKeys)
115
+ : fallbackVisibleKeys(schema);
90
116
  };
91
117
  exports.deriveDefaultVisibleKeys = deriveDefaultVisibleKeys;
92
118
  const extractDefaultValues = (schema) => {
@@ -99,8 +125,6 @@ const extractDefaultValues = (schema) => {
99
125
  }, {});
100
126
  };
101
127
  exports.extractDefaultValues = extractDefaultValues;
102
- const hasDynamicVisibility = (field) => { var _a; return (0, lodash_es_1.isFunction)((_a = field.config) === null || _a === void 0 ? void 0 : _a.visible); };
103
- exports.hasDynamicVisibility = hasDynamicVisibility;
104
128
  const normaliseValuesBySchema = (schema, values) => {
105
129
  if (!values) {
106
130
  return {};