@akinon/akifilter 1.3.6 → 1.4.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.
- package/dist/cjs/akifilter.d.ts +16 -4
- package/dist/cjs/akifilter.d.ts.map +1 -1
- package/dist/cjs/akifilter.js +93 -26
- package/dist/cjs/common/storage.d.ts.map +1 -1
- package/dist/cjs/common/storage.js +6 -1
- package/dist/cjs/components/applied-filters.d.ts.map +1 -1
- package/dist/cjs/components/applied-filters.js +2 -2
- package/dist/cjs/components/filter-toolbar.d.ts +2 -2
- package/dist/cjs/components/filter-toolbar.d.ts.map +1 -1
- package/dist/cjs/components/filter-toolbar.js +18 -2
- package/dist/cjs/filter-builder.d.ts +3 -3
- package/dist/cjs/filter-builder.d.ts.map +1 -1
- package/dist/cjs/filter-builder.js +5 -8
- package/dist/cjs/hooks/use-dynamic-visibility.d.ts +8 -0
- package/dist/cjs/hooks/use-dynamic-visibility.d.ts.map +1 -0
- package/dist/cjs/hooks/use-dynamic-visibility.js +36 -0
- package/dist/cjs/hooks/use-visibility-cleanup.d.ts +13 -0
- package/dist/cjs/hooks/use-visibility-cleanup.d.ts.map +1 -0
- package/dist/cjs/hooks/use-visibility-cleanup.js +39 -0
- package/dist/cjs/i18n/translations/en.d.ts +2 -2
- package/dist/cjs/i18n/translations/en.js +2 -2
- package/dist/cjs/i18n/translations/tr.d.ts +2 -2
- package/dist/cjs/i18n/translations/tr.js +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/styles.css +15 -3
- package/dist/cjs/styles.d.ts +1 -0
- package/dist/cjs/types.d.ts +9 -6
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/utils/schema.d.ts +5 -0
- package/dist/cjs/utils/schema.d.ts.map +1 -1
- package/dist/cjs/utils/schema.js +25 -3
- package/dist/cjs/utils/values.d.ts.map +1 -1
- package/dist/cjs/utils/values.js +3 -0
- package/dist/esm/akifilter.d.ts +16 -4
- package/dist/esm/akifilter.d.ts.map +1 -1
- package/dist/esm/akifilter.js +94 -27
- package/dist/esm/common/storage.d.ts.map +1 -1
- package/dist/esm/common/storage.js +6 -1
- package/dist/esm/components/applied-filters.d.ts.map +1 -1
- package/dist/esm/components/applied-filters.js +2 -2
- package/dist/esm/components/filter-toolbar.d.ts +2 -2
- package/dist/esm/components/filter-toolbar.d.ts.map +1 -1
- package/dist/esm/components/filter-toolbar.js +18 -2
- package/dist/esm/filter-builder.d.ts +3 -3
- package/dist/esm/filter-builder.d.ts.map +1 -1
- package/dist/esm/filter-builder.js +5 -8
- package/dist/esm/hooks/use-dynamic-visibility.d.ts +8 -0
- package/dist/esm/hooks/use-dynamic-visibility.d.ts.map +1 -0
- package/dist/esm/hooks/use-dynamic-visibility.js +32 -0
- package/dist/esm/hooks/use-visibility-cleanup.d.ts +13 -0
- package/dist/esm/hooks/use-visibility-cleanup.d.ts.map +1 -0
- package/dist/esm/hooks/use-visibility-cleanup.js +35 -0
- package/dist/esm/i18n/translations/en.d.ts +2 -2
- package/dist/esm/i18n/translations/en.js +2 -2
- package/dist/esm/i18n/translations/tr.d.ts +2 -2
- package/dist/esm/i18n/translations/tr.js +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/styles.css +15 -3
- package/dist/esm/styles.d.ts +1 -0
- package/dist/esm/types.d.ts +9 -6
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/utils/schema.d.ts +5 -0
- package/dist/esm/utils/schema.d.ts.map +1 -1
- package/dist/esm/utils/schema.js +22 -2
- package/dist/esm/utils/values.d.ts.map +1 -1
- package/dist/esm/utils/values.js +3 -0
- package/package.json +25 -22
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { ensureSchemaOrder, hasDynamicVisibility, resolveFieldVisibility } from '../utils/schema';
|
|
3
|
+
const computeDynamicKeys = (fields, prev, formValues) => {
|
|
4
|
+
const prevSet = new Set(prev);
|
|
5
|
+
const fieldKeySet = new Set(fields.map(f => String(f.key)));
|
|
6
|
+
const { keys, changed } = fields.reduce((acc, field) => {
|
|
7
|
+
const key = String(field.key);
|
|
8
|
+
const isCurrentlyVisible = prevSet.has(key);
|
|
9
|
+
if (!hasDynamicVisibility(field)) {
|
|
10
|
+
if (isCurrentlyVisible)
|
|
11
|
+
acc.keys.push(key);
|
|
12
|
+
return acc;
|
|
13
|
+
}
|
|
14
|
+
const shouldBeVisible = resolveFieldVisibility(field, formValues, isCurrentlyVisible);
|
|
15
|
+
if (shouldBeVisible)
|
|
16
|
+
acc.keys.push(key);
|
|
17
|
+
if (shouldBeVisible !== isCurrentlyVisible)
|
|
18
|
+
acc.changed = true;
|
|
19
|
+
return acc;
|
|
20
|
+
}, { keys: prev.filter(k => !fieldKeySet.has(k)), changed: false });
|
|
21
|
+
return changed ? ensureSchemaOrder(fields, keys) : null;
|
|
22
|
+
};
|
|
23
|
+
export const useDynamicVisibility = ({ regularFields, formValues, setVisibleKeys }) => {
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!regularFields.some(hasDynamicVisibility))
|
|
26
|
+
return;
|
|
27
|
+
setVisibleKeys(prev => {
|
|
28
|
+
var _a;
|
|
29
|
+
return ((_a = computeDynamicKeys(regularFields, prev, (formValues !== null && formValues !== void 0 ? formValues : {}))) !== null && _a !== void 0 ? _a : prev);
|
|
30
|
+
});
|
|
31
|
+
}, [regularFields, formValues, setVisibleKeys]);
|
|
32
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FieldValues } from '@akinon/akiform';
|
|
2
|
+
import type { AkifilterSchema } from '../types';
|
|
3
|
+
/**
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useVisibilityCleanup: <TFieldValues extends FieldValues = FieldValues>({ visibleKeys, regularFields, onRemove }: {
|
|
9
|
+
visibleKeys: string[];
|
|
10
|
+
regularFields: AkifilterSchema<TFieldValues>;
|
|
11
|
+
onRemove: (key: string) => void;
|
|
12
|
+
}) => void;
|
|
13
|
+
//# sourceMappingURL=use-visibility-cleanup.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { resolveFieldVisibility } from '../utils/schema';
|
|
4
|
+
const getInitialKeysToClean = (fields) => fields
|
|
5
|
+
.filter(field => resolveFieldVisibility(field) === false)
|
|
6
|
+
.map(field => String(field.key));
|
|
7
|
+
const getRemovedKeys = (prev, current) => prev.filter(key => !current.includes(key));
|
|
8
|
+
const cleanupKeys = (keys, onRemove) => {
|
|
9
|
+
keys.forEach(key => onRemove(key));
|
|
10
|
+
};
|
|
11
|
+
const resolveKeysToClean = ({ prev, current, fields }) => {
|
|
12
|
+
if (prev === null)
|
|
13
|
+
return getInitialKeysToClean(fields);
|
|
14
|
+
if (isEqual(prev, current))
|
|
15
|
+
return [];
|
|
16
|
+
return getRemovedKeys(prev, current);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Cleans up form values when fields become hidden.
|
|
20
|
+
* On first render, clears fields explicitly marked as invisible.
|
|
21
|
+
* On subsequent renders, clears fields that were removed from visibleKeys.
|
|
22
|
+
*/
|
|
23
|
+
export const useVisibilityCleanup = ({ visibleKeys, regularFields, onRemove }) => {
|
|
24
|
+
const previousVisibleKeysRef = useRef(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const prev = previousVisibleKeysRef.current;
|
|
27
|
+
previousVisibleKeysRef.current = visibleKeys;
|
|
28
|
+
const keysToClean = resolveKeysToClean({
|
|
29
|
+
prev,
|
|
30
|
+
current: visibleKeys,
|
|
31
|
+
fields: regularFields
|
|
32
|
+
});
|
|
33
|
+
cleanupKeys(keysToClean, onRemove);
|
|
34
|
+
}, [visibleKeys, onRemove, regularFields]);
|
|
35
|
+
};
|
|
@@ -3,8 +3,8 @@ declare const translations: {
|
|
|
3
3
|
readonly title: "Filters";
|
|
4
4
|
readonly actions: {
|
|
5
5
|
readonly selectFilters: "Select filters";
|
|
6
|
-
readonly importCsv: "
|
|
7
|
-
readonly importXls: "
|
|
6
|
+
readonly importCsv: "CSV";
|
|
7
|
+
readonly importXls: "XLS";
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
readonly applied: {
|
|
@@ -3,8 +3,8 @@ declare const translations: {
|
|
|
3
3
|
readonly title: "Filtreler";
|
|
4
4
|
readonly actions: {
|
|
5
5
|
readonly selectFilters: "Filtreleri seç";
|
|
6
|
-
readonly importCsv: "CSV
|
|
7
|
-
readonly importXls: "XLS
|
|
6
|
+
readonly importCsv: "CSV";
|
|
7
|
+
readonly importXls: "XLS";
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
readonly applied: {
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/styles.css
CHANGED
|
@@ -22,13 +22,24 @@
|
|
|
22
22
|
height: 36px;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
.akinon-filter__toolbar-item--file {
|
|
26
|
+
width: 36px;
|
|
27
|
+
font-size: 11px;
|
|
28
|
+
font-weight: bold;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
justify-content: flex-end;
|
|
31
|
+
gap: 2px;
|
|
32
|
+
padding-inline: 0;
|
|
33
|
+
padding-block-end: 4px;
|
|
34
|
+
}
|
|
35
|
+
|
|
25
36
|
.akinon-filter__applied {
|
|
26
37
|
display: flex;
|
|
27
38
|
align-items: center;
|
|
28
39
|
padding: 6px;
|
|
29
40
|
background-color: var(--color-ebonyClay-500);
|
|
30
41
|
border-radius: 6px;
|
|
31
|
-
box-shadow: inset 0 1px 4px 0
|
|
42
|
+
box-shadow: inset 0 1px 4px 0 var(--color-neutral-1000-20);
|
|
32
43
|
margin-bottom: 1rem;
|
|
33
44
|
}
|
|
34
45
|
|
|
@@ -89,12 +100,13 @@
|
|
|
89
100
|
color: var(--color-gray-500);
|
|
90
101
|
}
|
|
91
102
|
|
|
92
|
-
.akinon-filter__section-fields
|
|
103
|
+
.akinon-filter__section-fields
|
|
104
|
+
.akinon-collapse-expand-icon
|
|
105
|
+
.akinon-collapse-arrow {
|
|
93
106
|
font-size: 1rem !important;
|
|
94
107
|
color: var(--color-gray-500) !important;
|
|
95
108
|
}
|
|
96
109
|
|
|
97
|
-
|
|
98
110
|
@media (max-width: 1024px) {
|
|
99
111
|
.akinon-filter__form-grid {
|
|
100
112
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.css';
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -10,17 +10,19 @@ export interface AkifilterFieldConfig<TFieldValues extends FieldValues = FieldVa
|
|
|
10
10
|
* Controls whether the field is visible.
|
|
11
11
|
* Can be a boolean or a function that receives form values and returns a boolean.
|
|
12
12
|
*/
|
|
13
|
-
visible?: boolean | ((formValues: TFieldValues) => boolean);
|
|
13
|
+
visible?: boolean | ((formValues: TFieldValues, currentVisible?: boolean) => boolean);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* Controls whether the field is shown in the main filter form by default.
|
|
18
|
-
*/
|
|
19
|
-
isVisible?: boolean;
|
|
15
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
16
|
+
export type AkifilterField<TFieldValues extends FieldValues = FieldValues> = DistributiveOmit<FormField<TFieldValues>, 'config'> & {
|
|
20
17
|
/**
|
|
21
18
|
* Configuration options for field behavior (disabled, visible).
|
|
22
19
|
*/
|
|
23
20
|
config?: AkifilterFieldConfig<TFieldValues>;
|
|
21
|
+
/**
|
|
22
|
+
* Accepted file types for file fields (e.g. '.csv,.xls').
|
|
23
|
+
* Only applicable when `type` is `'file'`.
|
|
24
|
+
*/
|
|
25
|
+
fileAccept?: string;
|
|
24
26
|
};
|
|
25
27
|
export type AkifilterFieldKey<TFieldValues extends FieldValues = FieldValues> = Path<TFieldValues>;
|
|
26
28
|
export type AkifilterSchema<TFieldValues extends FieldValues = FieldValues> = AkifilterField<TFieldValues>[];
|
|
@@ -34,4 +36,5 @@ export interface AkifilterActionsRef {
|
|
|
34
36
|
*/
|
|
35
37
|
clearValue: (keys: string | string[]) => void;
|
|
36
38
|
}
|
|
39
|
+
export {};
|
|
37
40
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -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,MAAM,yBAAyB,CAAC;AAEzD,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,
|
|
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,MAAM,yBAAyB,CAAC;AAEzD,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,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,OAAO,GAC/D,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACV,KAAK,CAAC;AAEV,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,IACvE,gBAAgB,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,GAAG;IACpD;;OAEG;IACH,MAAM,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAC5C;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEJ,MAAM,MAAM,iBAAiB,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,IAC1E,IAAI,CAAC,YAAY,CAAC,CAAC;AAErB,MAAM,MAAM,eAAe,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,IACxE,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC;CAC/C"}
|
|
@@ -17,7 +17,12 @@ export declare const partitionSchema: <TFieldValues extends FieldValues = FieldV
|
|
|
17
17
|
export declare const getDisplayLabel: <TFieldValues extends FieldValues = FieldValues>(field: AkifilterField<TFieldValues>) => string;
|
|
18
18
|
export declare const getFieldAriaLabel: <TFieldValues extends FieldValues = FieldValues>(field: AkifilterField<TFieldValues>) => string;
|
|
19
19
|
export declare const ensureSchemaOrder: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>, keys: string[]) => string[];
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the visibility of a field.
|
|
22
|
+
*/
|
|
23
|
+
export declare const resolveFieldVisibility: <TFieldValues extends FieldValues = FieldValues>(field: AkifilterField<TFieldValues>, formValues?: TFieldValues, currentVisible?: boolean) => boolean | undefined;
|
|
20
24
|
export declare const deriveDefaultVisibleKeys: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>) => string[];
|
|
21
25
|
export declare const extractDefaultValues: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>) => Partial<TFieldValues>;
|
|
26
|
+
export declare const hasDynamicVisibility: <TFieldValues extends FieldValues>(field: AkifilterField<TFieldValues>) => boolean;
|
|
22
27
|
export declare const normaliseValuesBySchema: <TFieldValues extends FieldValues = FieldValues>(schema: AkifilterSchema<TFieldValues>, values?: Partial<TFieldValues>) => Partial<TFieldValues>;
|
|
23
28
|
//# 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;
|
|
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,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,YAAY,SAAS,WAAW,GAAG,WAAW,EAC1E,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,eAAe,CAAC,YAAY,CAW9B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,WAAW,GAAG,WAAW,EAC5E,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC;IACD,aAAa,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C,aAAa,EAAE,KAAK,CAClB,cAAc,CAAC,YAAY,CAAC,GAAG;QAC7B,MAAM,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;KACvC,CACF,CAAC;CAwBH,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,WAAW,GAAG,WAAW,EAC5E,OAAO,cAAc,CAAC,YAAY,CAAC,KAClC,MAEF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,OAAO,cAAc,CAAC,YAAY,CAAC,KAClC,MAEF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,EACrC,MAAM,MAAM,EAAE,KACb,MAAM,EAGR,CAAC;AAkBF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,OAAO,cAAc,CAAC,YAAY,CAAC,EACnC,aAAa,YAAY,EACzB,iBAAiB,OAAO,KACvB,OAAO,GAAG,SAC8D,CAAC;AAE5E,eAAO,MAAM,wBAAwB,GACnC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,MAAM,EAUR,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,KACpC,OAAO,CAAC,YAAY,CAQtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,YAAY,SAAS,WAAW,EACnE,OAAO,cAAc,CAAC,YAAY,CAAC,KAClC,OAA4C,CAAC;AAEhD,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,CAyCtB,CAAC"}
|
package/dist/esm/utils/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { akidate } from '@akinon/akidate';
|
|
2
|
+
import { isBoolean, isFunction } from 'lodash-es';
|
|
2
3
|
import { DEFAULT_VISIBLE_COUNT } from '../constants';
|
|
3
4
|
/**
|
|
4
5
|
* Flattens schema by extracting all nested fields from section fields.
|
|
@@ -42,12 +43,23 @@ export const ensureSchemaOrder = (schema, keys) => {
|
|
|
42
43
|
const keySet = new Set(keys.map(String));
|
|
43
44
|
return schema.map(field => String(field.key)).filter(key => keySet.has(key));
|
|
44
45
|
};
|
|
46
|
+
const resolveVisibilityValue = (value, formValues, currentVisible) => {
|
|
47
|
+
if (isBoolean(value))
|
|
48
|
+
return value;
|
|
49
|
+
if (isFunction(value))
|
|
50
|
+
return value(formValues !== null && formValues !== void 0 ? formValues : {}, currentVisible !== null && currentVisible !== void 0 ? currentVisible : false);
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the visibility of a field.
|
|
55
|
+
*/
|
|
56
|
+
export const resolveFieldVisibility = (field, formValues, currentVisible) => { var _a; return resolveVisibilityValue((_a = field.config) === null || _a === void 0 ? void 0 : _a.visible, formValues, currentVisible); };
|
|
45
57
|
export const deriveDefaultVisibleKeys = (schema) => {
|
|
46
58
|
const explicitKeys = schema
|
|
47
|
-
.filter(field => field
|
|
59
|
+
.filter(field => resolveFieldVisibility(field) === true)
|
|
48
60
|
.map(field => String(field.key));
|
|
49
61
|
if (explicitKeys.length > 0) {
|
|
50
|
-
return ensureSchemaOrder(schema,
|
|
62
|
+
return ensureSchemaOrder(schema, explicitKeys);
|
|
51
63
|
}
|
|
52
64
|
return schema.slice(0, DEFAULT_VISIBLE_COUNT).map(field => String(field.key));
|
|
53
65
|
};
|
|
@@ -60,6 +72,7 @@ export const extractDefaultValues = (schema) => {
|
|
|
60
72
|
return acc;
|
|
61
73
|
}, {});
|
|
62
74
|
};
|
|
75
|
+
export const hasDynamicVisibility = (field) => { var _a; return isFunction((_a = field.config) === null || _a === void 0 ? void 0 : _a.visible); };
|
|
63
76
|
export const normaliseValuesBySchema = (schema, values) => {
|
|
64
77
|
if (!values) {
|
|
65
78
|
return {};
|
|
@@ -78,6 +91,13 @@ export const normaliseValuesBySchema = (schema, values) => {
|
|
|
78
91
|
return acc;
|
|
79
92
|
}
|
|
80
93
|
}
|
|
94
|
+
if (field.type === 'select' &&
|
|
95
|
+
(field.mode === 'multiple' || field.mode === 'tags') &&
|
|
96
|
+
currentValue != null &&
|
|
97
|
+
!Array.isArray(currentValue)) {
|
|
98
|
+
acc[key] = [currentValue];
|
|
99
|
+
return acc;
|
|
100
|
+
}
|
|
81
101
|
acc[key] = currentValue;
|
|
82
102
|
return acc;
|
|
83
103
|
}, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../src/utils/values.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAC7B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,OAAO,cAAc,CAAC,YAAY,CAAC,GAAG,SAAS,EAC/C,OAAO,OAAO,KACb,
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../src/utils/values.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAC7B,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,OAAO,cAAc,CAAC,YAAY,CAAC,GAAG,SAAS,EAC/C,OAAO,OAAO,KACb,OAsBF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,QAAQ,eAAe,CAAC,YAAY,CAAC,EACrC,SAAS,OAAO,CAAC,YAAY,CAAC,GAAG,WAAW,KAC3C,OAAO,CAAC,YAAY,CAkCtB,CAAC"}
|
package/dist/esm/utils/values.js
CHANGED
|
@@ -13,6 +13,9 @@ export const shouldPersistValue = (field, value) => {
|
|
|
13
13
|
if ((field === null || field === void 0 ? void 0 : field.type) === 'checkbox' && value !== true) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === 'file') {
|
|
17
|
+
return value instanceof File;
|
|
18
|
+
}
|
|
16
19
|
return true;
|
|
17
20
|
};
|
|
18
21
|
export const normaliseOutputValues = (schema, values) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/akifilter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Akifilter is a filtering library for Akinon frontend applications.",
|
|
6
6
|
"type": "module",
|
|
@@ -12,33 +12,36 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"antd": "^5.27.0",
|
|
14
14
|
"react-error-boundary": "^6.0.0",
|
|
15
|
-
"
|
|
16
|
-
"@akinon/
|
|
17
|
-
"@akinon/
|
|
18
|
-
"@akinon/akilocale": "1.2.
|
|
19
|
-
"@akinon/
|
|
20
|
-
"@akinon/
|
|
21
|
-
"@akinon/ui-
|
|
22
|
-
"@akinon/ui-
|
|
23
|
-
"@akinon/ui-date-picker": "1.
|
|
24
|
-
"@akinon/ui-
|
|
25
|
-
"@akinon/ui-input
|
|
26
|
-
"@akinon/ui-
|
|
27
|
-
"@akinon/ui-
|
|
28
|
-
"@akinon/ui-
|
|
29
|
-
"@akinon/ui-
|
|
30
|
-
"@akinon/ui-
|
|
15
|
+
"lodash-es": "^4.17.21",
|
|
16
|
+
"@akinon/akiform": "1.1.9",
|
|
17
|
+
"@akinon/akidate": "1.2.7",
|
|
18
|
+
"@akinon/akilocale": "1.2.8",
|
|
19
|
+
"@akinon/ui-button": "1.5.0",
|
|
20
|
+
"@akinon/icons": "1.2.8",
|
|
21
|
+
"@akinon/ui-card": "1.2.9",
|
|
22
|
+
"@akinon/ui-checkbox": "1.4.9",
|
|
23
|
+
"@akinon/ui-date-picker": "1.5.0",
|
|
24
|
+
"@akinon/ui-collapse": "1.4.7",
|
|
25
|
+
"@akinon/ui-input": "1.2.9",
|
|
26
|
+
"@akinon/ui-input-number": "1.4.9",
|
|
27
|
+
"@akinon/ui-modal": "1.2.9",
|
|
28
|
+
"@akinon/ui-pagination": "1.4.10",
|
|
29
|
+
"@akinon/ui-select": "1.4.10",
|
|
30
|
+
"@akinon/ui-space": "1.4.9",
|
|
31
|
+
"@akinon/ui-typography": "1.2.7",
|
|
32
|
+
"@akinon/ui-upload": "1.5.0"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
35
|
+
"@types/lodash-es": "^4.17.12",
|
|
33
36
|
"clean-package": "2.2.0",
|
|
34
37
|
"copyfiles": "^2.4.1",
|
|
35
38
|
"rimraf": "^5.0.5",
|
|
36
39
|
"typescript": "*",
|
|
37
|
-
"@akinon/
|
|
38
|
-
"@akinon/
|
|
39
|
-
"@akinon/
|
|
40
|
-
"@akinon/
|
|
41
|
-
"@akinon/
|
|
40
|
+
"@akinon/akiform-builder": "1.5.8",
|
|
41
|
+
"@akinon/typescript-config": "1.1.8",
|
|
42
|
+
"@akinon/utils": "1.2.10",
|
|
43
|
+
"@akinon/ui-theme": "1.3.0",
|
|
44
|
+
"@akinon/vitest-config": "1.1.8"
|
|
42
45
|
},
|
|
43
46
|
"peerDependencies": {
|
|
44
47
|
"react": "^18 || ^19",
|