@tachybase/client 1.6.17 → 1.6.19

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 (30) hide show
  1. package/es/block-provider/hooks/index.mjs +2 -8
  2. package/es/data-source/data-block/DataBlockRequestProvider.mjs +5 -5
  3. package/es/filter-provider/utils.d.ts +10 -0
  4. package/es/filter-provider/utils.mjs +68 -16
  5. package/es/modules/fields/component/DrawerSubTable/drawerSubTableComponentFieldSettings.mjs +2 -3
  6. package/es/modules/fields/component/Nester/subformComponentFieldSettings.mjs +1 -2
  7. package/es/modules/fields/component/Picker/recordPickerComponentFieldSettings.mjs +2 -3
  8. package/es/modules/fields/component/PopoverNester/subformPopoverComponentFieldSettings.mjs +1 -2
  9. package/es/modules/fields/component/Select/selectComponentFieldSettings.mjs +1 -2
  10. package/es/schema-component/antd/association-select/AssociationSelect.mjs +3 -3
  11. package/es/schema-component/antd/date-picker/util.d.ts +18 -0
  12. package/es/schema-component/antd/date-picker/util.mjs +62 -5
  13. package/es/schema-component/antd/filter/useFilterActionProps.mjs +85 -7
  14. package/es/schema-component/antd/form-item/FormItem.Settings.mjs +1 -2
  15. package/es/schema-initializer/utils.d.ts +1 -0
  16. package/es/schema-initializer/utils.mjs +7 -6
  17. package/lib/block-provider/hooks/index.js +2 -8
  18. package/lib/data-source/data-block/DataBlockRequestProvider.js +5 -5
  19. package/lib/filter-provider/utils.js +73 -15
  20. package/lib/modules/fields/component/DrawerSubTable/drawerSubTableComponentFieldSettings.js +2 -3
  21. package/lib/modules/fields/component/Nester/subformComponentFieldSettings.js +1 -2
  22. package/lib/modules/fields/component/Picker/recordPickerComponentFieldSettings.js +2 -3
  23. package/lib/modules/fields/component/PopoverNester/subformPopoverComponentFieldSettings.js +1 -2
  24. package/lib/modules/fields/component/Select/selectComponentFieldSettings.js +1 -2
  25. package/lib/schema-component/antd/association-select/AssociationSelect.js +3 -3
  26. package/lib/schema-component/antd/date-picker/util.js +81 -6
  27. package/lib/schema-component/antd/filter/useFilterActionProps.js +84 -6
  28. package/lib/schema-component/antd/form-item/FormItem.Settings.js +1 -2
  29. package/lib/schema-initializer/utils.js +9 -5
  30. package/package.json +1 -1
@@ -424,7 +424,6 @@ const useFilterBlockActionProps = ()=>{
424
424
  async onClick () {
425
425
  const { targets = [], uid } = findFilterTargets(fieldSchema);
426
426
  actionField.data.loading = true;
427
- let prevMergedFilter = {};
428
427
  try {
429
428
  await Promise.all(getDataBlocks().map(async (block)=>{
430
429
  var _block_service_params, _block_service_params_, _block_service_params1, _Object_keys;
@@ -461,11 +460,9 @@ const useFilterBlockActionProps = ()=>{
461
460
  ...Object.values(storedFilter).map((filter)=>removeNullCondition(filter)),
462
461
  getFilterSourceDefaultFilter(getDataBlocks(), uid),
463
462
  block.defaultFilter,
464
- filter.customFilter,
465
- prevMergedFilter
463
+ filter.customFilter
466
464
  ]);
467
465
  const currFilter = filterByCleanedFields(mergedFilter);
468
- prevMergedFilter = currFilter;
469
466
  if ('manual' === block.dataLoadingMode && lodash.isEmpty(currFilter)) return block.clearData();
470
467
  return block.doFilter({
471
468
  ...param,
@@ -493,7 +490,6 @@ const useResetBlockActionProps = ()=>{
493
490
  const { targets, uid } = findFilterTargets(fieldSchema);
494
491
  form.reset();
495
492
  actionField.data.loading = true;
496
- let prevMergedFilter = {};
497
493
  try {
498
494
  await Promise.all(getDataBlocks().map(async (block)=>{
499
495
  var _block_service_params, _block_service_params_, _block_service_params1;
@@ -506,11 +502,9 @@ const useResetBlockActionProps = ()=>{
506
502
  const currFilter = utils_mjs_mergeFilter([
507
503
  ...Object.values(storedFilter),
508
504
  getFilterSourceDefaultFilter(getDataBlocks(), uid),
509
- block.defaultFilter,
510
- prevMergedFilter
505
+ block.defaultFilter
511
506
  ]);
512
507
  const mergedFilter = filterByCleanedFields(currFilter);
513
- prevMergedFilter = mergedFilter;
514
508
  return block.doFilter({
515
509
  ...param,
516
510
  page: 1,
@@ -52,14 +52,14 @@ function useParentRequest(options) {
52
52
  if (parentRecord) return Promise.resolve({
53
53
  data: parentRecord
54
54
  });
55
- if (!association || !sourceKey) return Promise.resolve({
55
+ if (!association || !sourceKey || null == sourceId) return Promise.resolve({
56
56
  data: void 0
57
57
  });
58
58
  const arr = association.split('.');
59
- const url = "".concat(arr[0], ":get?filter[").concat(sourceKey, "]=").concat(sourceId);
60
- const res = await api.request({
61
- url,
62
- headers
59
+ const res = await api.resource(arr[0], void 0, headers).get({
60
+ filter: {
61
+ [sourceKey]: sourceId
62
+ }
63
63
  });
64
64
  return res.data;
65
65
  }, {
@@ -1,6 +1,7 @@
1
1
  import { Schema } from '@tachybase/schema';
2
2
  import { FilterTarget } from '../block-provider/hooks';
3
3
  import { Collection_deprecated, CollectionFieldOptions_deprecated, FieldOptions, useCollection_deprecated } from '../collection-manager';
4
+ import { type DatePickerRangeValueMode, type DatePickerRangeValueSource } from '../schema-component/antd/date-picker/util';
4
5
  import { DataBlock } from './FilterProvider';
5
6
  export declare enum FilterBlockType {
6
7
  FORM = 0,
@@ -21,6 +22,14 @@ export declare const getSupportFieldsByForeignKey: (filterBlockCollection: Retur
21
22
  * @returns
22
23
  */
23
24
  export declare const useSupportedBlocks: (filterBlockType: FilterBlockType) => DataBlock[];
25
+ type NormalizeDateBetweenOptions = {
26
+ useDefaultDateBoundary?: boolean;
27
+ valueMode?: DatePickerRangeValueMode;
28
+ valueSource?: DatePickerRangeValueSource;
29
+ preferDateBoundaryFallback?: boolean;
30
+ };
31
+ export declare const normalizeDateBetweenValue: (value: any[], options?: NormalizeDateBetweenOptions) => any[];
32
+ export declare const shouldUseDefaultDateBoundary: (fieldSchema?: any) => boolean;
24
33
  export declare const transformToFilter: (values: Record<string, any>, fieldSchema: Schema, getCollectionJoinField: (name: string) => CollectionFieldOptions_deprecated, collectionName: string, getOperatorList?: (path: string, options: {
25
34
  fieldSchema?: Schema;
26
35
  collectionField?: CollectionFieldOptions_deprecated;
@@ -49,3 +58,4 @@ export declare const useFilterAPI: () => {
49
58
  doFilter: (value: any, field?: string | ((target: FilterTarget["targets"][0]) => string), operator?: string | ((target: FilterTarget["targets"][0]) => string)) => void;
50
59
  };
51
60
  export declare const isInFilterFormBlock: (fieldSchema: Schema) => boolean;
61
+ export {};
@@ -6,6 +6,7 @@ import lodash from "lodash";
6
6
  import { findFilterTargets } from "../block-provider/hooks/index.mjs";
7
7
  import { useCollectionManager_deprecated, useCollection_deprecated } from "../collection-manager/index.mjs";
8
8
  import { removeNullCondition } from "../schema-component/index.mjs";
9
+ import { isDatePickerDefaultRangeBoundaryValue, resolveDatePickerRangeValueInfo } from "../schema-component/antd/date-picker/util.mjs";
9
10
  import { findFilterOperators, getDefaultFilterOperatorValue } from "../schema-component/antd/form-item/SchemaSettingOptions.mjs";
10
11
  import { useFilterBlock } from "./FilterProvider.mjs";
11
12
  import { getFilterSourceDefaultFilter } from "./incomingFilterFromSources.mjs";
@@ -62,6 +63,7 @@ const findSchemaByName = (schema, name)=>{
62
63
  if (schema.name === name) return schema;
63
64
  const properties = schema.properties || {};
64
65
  for (const key of Object.keys(properties)){
66
+ if (key === name) return properties[key];
65
67
  const found = findSchemaByName(properties[key], name);
66
68
  if (found) return found;
67
69
  }
@@ -87,6 +89,58 @@ const resolveFilterOperator = function(schema, path) {
87
89
  if (!operatorList.length || !fieldSchema) return;
88
90
  return getDefaultFilterOperatorValue(fieldSchema, operatorList);
89
91
  };
92
+ const getDatePickerComponent = (fieldSchema)=>{
93
+ var _fieldSchema_xcomponentprops;
94
+ return (null == fieldSchema ? void 0 : fieldSchema['x-component']) || (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.component);
95
+ };
96
+ const getDatePickerShowTime = (fieldSchema)=>{
97
+ var _fieldSchema_xcomponentprops;
98
+ return null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.showTime;
99
+ };
100
+ const isDateOnlyString = (value)=>'string' == typeof value && /^\d{4}-\d{2}-\d{2}$/.test(value);
101
+ const hasExplicitTime = (value)=>'string' == typeof value && /[T\s]\d{2}:\d{2}/.test(value);
102
+ const normalizeLocalDateBoundaryInput = (value)=>{
103
+ if ('string' != typeof value) return value;
104
+ return value.replace(/Z$/, '').replace(/[+-]\d\d:\d\d$/, '');
105
+ };
106
+ const normalizeDateBetweenBoundary = function(value, boundary) {
107
+ let options = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
108
+ const m = dayjs(value);
109
+ if (!m.isValid()) return value;
110
+ if (isDateOnlyString(value)) return ('start' === boundary ? m.startOf('day') : m.endOf('day')).toISOString();
111
+ if ('date' === options.valueMode) {
112
+ if ('retained-local-date-boundary' === options.valueSource) return m.toISOString();
113
+ const localBoundary = dayjs(normalizeLocalDateBoundaryInput(value));
114
+ return ('start' === boundary ? localBoundary.startOf('day') : localBoundary.endOf('day')).toISOString();
115
+ }
116
+ if (hasExplicitTime(value)) return m.toISOString();
117
+ if (!options.useDefaultDateBoundary) return m.toISOString();
118
+ return ('start' === boundary ? m.startOf('day') : m.endOf('day')).toISOString();
119
+ };
120
+ const shouldApplyDefaultDateBoundary = function(start, end, value) {
121
+ let options = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {};
122
+ if ('datetime' === options.valueMode) return false;
123
+ if ('date' === options.valueMode) return true;
124
+ if (!options.useDefaultDateBoundary) return false;
125
+ if (isDateOnlyString(start) || isDateOnlyString(end)) return true;
126
+ return options.preferDateBoundaryFallback && 'date' === options.valueMode && isDatePickerDefaultRangeBoundaryValue(start, 'start') && isDatePickerDefaultRangeBoundaryValue(end, 'end');
127
+ };
128
+ const normalizeDateBetweenValue = function(value) {
129
+ let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
130
+ const normalized = value.filter(Boolean);
131
+ if (0 === normalized.length) return null;
132
+ const start = normalized[0];
133
+ const end = 1 === normalized.length ? normalized[0] : normalized[normalized.length - 1];
134
+ const boundaryOptions = {
135
+ ...options,
136
+ useDefaultDateBoundary: shouldApplyDefaultDateBoundary(start, end, value, options)
137
+ };
138
+ return [
139
+ normalizeDateBetweenBoundary(start, 'start', boundaryOptions),
140
+ normalizeDateBetweenBoundary(end, 'end', boundaryOptions)
141
+ ];
142
+ };
143
+ const shouldUseDefaultDateBoundary = (fieldSchema)=>'DatePicker.RangePicker' === getDatePickerComponent(fieldSchema);
90
144
  const transformToFilter = (values, fieldSchema, getCollectionJoinField, collectionName, getOperatorList)=>{
91
145
  const { operators } = findFilterOperators(fieldSchema);
92
146
  values = flatten(values, {
@@ -108,6 +162,7 @@ const transformToFilter = (values, fieldSchema, getCollectionJoinField, collecti
108
162
  const defKey = key;
109
163
  let value = lodash.get(values, key);
110
164
  const collectionField = getCollectionJoinField("".concat(collectionName, ".").concat(key));
165
+ const currentFieldSchema = findSchemaByName(getFilterSchemaRoot(fieldSchema), defKey);
111
166
  const operator = resolveFilterOperator(fieldSchema, defKey, operators, getOperatorList, collectionField);
112
167
  if (null == collectionField ? void 0 : collectionField.target) {
113
168
  value = getValuesByPath(value, collectionField.targetKey || 'id');
@@ -127,21 +182,18 @@ const transformToFilter = (values, fieldSchema, getCollectionJoinField, collecti
127
182
  };
128
183
  } else if ('$dateBetween' === operator) {
129
184
  if (Array.isArray(value)) {
130
- const normalized = [];
131
- for(const index in value){
132
- if (!value[index]) continue;
133
- let v = value[index];
134
- if ('string' != typeof v && !(v instanceof Date)) v = dayjs(v).toISOString();
135
- normalized.push(v);
136
- }
137
- if (0 === normalized.length) return null;
138
- value = 1 === normalized.length ? [
139
- normalized[0],
140
- normalized[0]
141
- ] : [
142
- normalized[0],
143
- normalized[normalized.length - 1]
144
- ];
185
+ const valueInfo = resolveDatePickerRangeValueInfo(value, {
186
+ component: getDatePickerComponent(currentFieldSchema),
187
+ showTime: getDatePickerShowTime(currentFieldSchema),
188
+ preferDateBoundaryFallback: shouldUseDefaultDateBoundary(currentFieldSchema)
189
+ });
190
+ value = normalizeDateBetweenValue(value, {
191
+ useDefaultDateBoundary: shouldUseDefaultDateBoundary(currentFieldSchema),
192
+ valueMode: valueInfo.mode,
193
+ valueSource: valueInfo.source,
194
+ preferDateBoundaryFallback: 'retained-date-boundary' === valueInfo.source
195
+ });
196
+ if (!value) return null;
145
197
  }
146
198
  }
147
199
  return {
@@ -231,4 +283,4 @@ const isInFilterFormBlock = (fieldSchema)=>{
231
283
  }
232
284
  return false;
233
285
  };
234
- export { FILTER_OPERATORS_WITH_ARRAY_VALUES, utils_FilterBlockType as FilterBlockType, getSupportFieldsByAssociation, getSupportFieldsByForeignKey, isAssocField, isInFilterFormBlock, isSameCollection, mergeFilter, transformToFilter, useAssociatedFields, useFilterAPI, useSupportedBlocks };
286
+ export { FILTER_OPERATORS_WITH_ARRAY_VALUES, utils_FilterBlockType as FilterBlockType, getSupportFieldsByAssociation, getSupportFieldsByForeignKey, isAssocField, isInFilterFormBlock, isSameCollection, mergeFilter, normalizeDateBetweenValue, shouldUseDefaultDateBoundary, transformToFilter, useAssociatedFields, useFilterAPI, useSupportedBlocks };
@@ -20,14 +20,13 @@ const allowMultiple = {
20
20
  ].includes(null == collectionField ? void 0 : collectionField.type);
21
21
  },
22
22
  useComponentProps () {
23
- var _fieldSchema_xcomponentprops;
24
23
  const { t } = useTranslation();
25
24
  const field = useField();
26
25
  const fieldSchema = useFieldSchema();
27
26
  const { dn, refresh } = useDesignable();
28
27
  return {
29
28
  title: t('Allow multiple'),
30
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
29
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
31
30
  onChange (value) {
32
31
  const schema = {
33
32
  ['x-uid']: fieldSchema['x-uid']
@@ -126,7 +125,7 @@ const drawerSubTableComponentFieldSettings = new SchemaSettings({
126
125
  value: 'large'
127
126
  }
128
127
  ],
129
- value: null != (_fieldSchema_xcomponentprops_openSize = null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['openSize']) ? _fieldSchema_xcomponentprops_openSize : (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1['openMode']) == 'modal' ? 'large' : 'middle',
128
+ value: null != (_fieldSchema_xcomponentprops_openSize = null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['openSize']) ? _fieldSchema_xcomponentprops_openSize : (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1['openMode']) === 'modal' ? 'large' : 'middle',
130
129
  onChange: (value)=>{
131
130
  field.componentProps.openSize = value;
132
131
  fieldSchema['x-component-props'] = {
@@ -19,14 +19,13 @@ const allowMultiple = {
19
19
  ].includes(null == collectionField ? void 0 : collectionField.type);
20
20
  },
21
21
  useComponentProps () {
22
- var _fieldSchema_xcomponentprops;
23
22
  const { t } = useTranslation();
24
23
  const field = useField();
25
24
  const fieldSchema = useFieldSchema();
26
25
  const { dn, refresh } = useDesignable();
27
26
  return {
28
27
  title: t('Allow multiple'),
29
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
28
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
30
29
  onChange (value) {
31
30
  const schema = {
32
31
  ['x-uid']: fieldSchema['x-uid']
@@ -60,14 +60,13 @@ const allowMultiple = {
60
60
  ].includes(null == collectionField ? void 0 : collectionField.type);
61
61
  },
62
62
  useComponentProps () {
63
- var _fieldSchema_xcomponentprops;
64
63
  const { t } = useTranslation();
65
64
  const field = useField();
66
65
  const fieldSchema = useFieldSchema();
67
66
  const { dn, refresh } = useDesignable();
68
67
  return {
69
68
  title: t('Allow multiple'),
70
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
69
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
71
70
  onChange (value) {
72
71
  const schema = {
73
72
  ['x-uid']: fieldSchema['x-uid']
@@ -165,7 +164,7 @@ const recordPickerComponentFieldSettings = new SchemaSettings({
165
164
  value: 'large'
166
165
  }
167
166
  ],
168
- value: null != (_fieldSchema_xcomponentprops_openSize = null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['openSize']) ? _fieldSchema_xcomponentprops_openSize : (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1['openMode']) == 'modal' ? 'large' : 'middle',
167
+ value: null != (_fieldSchema_xcomponentprops_openSize = null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['openSize']) ? _fieldSchema_xcomponentprops_openSize : (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1['openMode']) === 'modal' ? 'large' : 'middle',
169
168
  onChange: (value)=>{
170
169
  field.componentProps.openSize = value;
171
170
  fieldSchema['x-component-props'] = {
@@ -20,14 +20,13 @@ const allowMultiple = {
20
20
  ].includes(null == collectionField ? void 0 : collectionField.type);
21
21
  },
22
22
  useComponentProps () {
23
- var _fieldSchema_xcomponentprops;
24
23
  const { t } = useTranslation();
25
24
  const field = useField();
26
25
  const fieldSchema = useFieldSchema();
27
26
  const { dn, refresh } = useDesignable();
28
27
  return {
29
28
  title: t('Allow multiple'),
30
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
29
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
31
30
  onChange (value) {
32
31
  const schema = {
33
32
  ['x-uid']: fieldSchema['x-uid']
@@ -123,7 +123,6 @@ const allowMultiple = {
123
123
  ].includes(null == collectionField ? void 0 : collectionField.type);
124
124
  },
125
125
  useComponentProps () {
126
- var _fieldSchema_xcomponentprops;
127
126
  const { t } = useTranslation();
128
127
  const field = useField();
129
128
  const { fieldSchema: tableColumnSchema } = useColumnSchema();
@@ -132,7 +131,7 @@ const allowMultiple = {
132
131
  const { dn, refresh } = useDesignable();
133
132
  return {
134
133
  title: t('Allow multiple'),
135
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
134
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
136
135
  onChange (value) {
137
136
  const schema = {
138
137
  ['x-uid']: fieldSchema['x-uid']
@@ -1,8 +1,8 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useMemo } from "react";
3
3
  import { connect, mapProps, mapReadPretty, uid, useField, useFieldSchema } from "@tachybase/schema";
4
- import { LoadingOutlined } from "@ant-design/icons";
5
4
  import { ArrayCollapse, ArrayItems, FormLayout } from "@tego/client";
5
+ import { LoadingOutlined } from "@ant-design/icons";
6
6
  import lodash from "lodash";
7
7
  import { useTranslation } from "react-i18next";
8
8
  import { useFilterByTk, useFormBlockContext } from "../../../block-provider/index.mjs";
@@ -66,7 +66,7 @@ const InternalAssociationSelect = connect((props)=>{
66
66
  })), mapReadPretty(ReadPretty));
67
67
  const AssociationSelect = InternalAssociationSelect;
68
68
  AssociationSelect.Designer = function() {
69
- var _interfaceConfig_validateSchema, _collectionField_uiSchema, _field_componentProps_service_params, _field_componentProps_service, _field_componentProps, _fieldSchema_xcomponentprops, _field_componentProps_service_params1, _field_componentProps_service1, _field_componentProps1, _field_componentProps_fieldNames, _field_componentProps2;
69
+ var _interfaceConfig_validateSchema, _collectionField_uiSchema, _field_componentProps_service_params, _field_componentProps_service, _field_componentProps, _field_componentProps_service_params1, _field_componentProps_service1, _field_componentProps1, _field_componentProps_fieldNames, _field_componentProps2;
70
70
  const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } = useCollectionManager_deprecated();
71
71
  const { getField } = useCollection_deprecated();
72
72
  const { form } = useFormBlockContext();
@@ -318,7 +318,7 @@ AssociationSelect.Designer = function() {
318
318
  }),
319
319
  IsShowMultipleSwitch() ? /*#__PURE__*/ jsx(SchemaSettingsSwitchItem, {
320
320
  title: t('Allow multiple'),
321
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
321
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
322
322
  onChange: (value)=>{
323
323
  const schema = {
324
324
  ['x-uid']: fieldSchema['x-uid']
@@ -4,7 +4,25 @@ export interface Moment2strOptions {
4
4
  gmt?: boolean;
5
5
  utc?: boolean;
6
6
  picker?: 'year' | 'month' | 'week' | 'quarter';
7
+ value?: any;
8
+ component?: string;
7
9
  }
10
+ export declare const DATE_PICKER_RANGE_VALUE_MODE: unique symbol;
11
+ export type DatePickerRangeValueMode = 'date' | 'datetime';
12
+ export type DatePickerRangeValueSource = 'metadata' | 'schema' | 'retained-date-boundary' | 'retained-local-date-boundary' | 'unknown';
13
+ export interface DatePickerRangeValueInfo {
14
+ mode?: DatePickerRangeValueMode;
15
+ source: DatePickerRangeValueSource;
16
+ }
17
+ export declare const getRangeValueMode: (value: any) => DatePickerRangeValueMode | undefined;
18
+ export declare const markRangeValueMode: (value: any[], mode: DatePickerRangeValueMode) => any[];
19
+ export declare const isDatePickerDefaultRangeBoundaryValue: (value: any, boundary: "start" | "end") => boolean;
20
+ export declare const isDatePickerDefaultRangeBoundaryPair: (value: any) => boolean;
21
+ export declare const resolveDatePickerRangeValueInfo: (value: any, options?: {
22
+ showTime?: boolean;
23
+ component?: string;
24
+ preferDateBoundaryFallback?: boolean;
25
+ }) => DatePickerRangeValueInfo;
8
26
  export declare const normalizeDatePickerParseOptions: (options?: Moment2strOptions) => Moment2strOptions;
9
27
  export declare const moment2str: (value?: Dayjs | null, options?: Moment2strOptions) => any;
10
28
  export declare const mapDatePicker: () => (props: any) => any;
@@ -20,9 +20,63 @@ const toLocalByPicker = (value, picker)=>{
20
20
  if (!value || !dayjs.isDayjs(value)) return value;
21
21
  return toStringByPicker(value, picker, 'local');
22
22
  };
23
+ const DATE_PICKER_RANGE_VALUE_MODE = Symbol.for('tachybase.datePicker.rangeValueMode');
24
+ const getRangeValueMode = (value)=>Array.isArray(value) ? value[DATE_PICKER_RANGE_VALUE_MODE] : void 0;
25
+ const markRangeValueMode = (value, mode)=>{
26
+ Object.defineProperty(value, DATE_PICKER_RANGE_VALUE_MODE, {
27
+ configurable: true,
28
+ enumerable: false,
29
+ value: mode
30
+ });
31
+ return value;
32
+ };
33
+ const isDatePickerDefaultRangeBoundaryValue = (value, boundary)=>{
34
+ if ('string' != typeof value) return false;
35
+ const match = value.match(/^\d{4}-\d{2}-\d{2}[T\s](\d{2}:\d{2}:\d{2})(?:\.\d{3})?(?:Z|[+-]\d\d:\d\d)?$/);
36
+ if (!match) return false;
37
+ return 'start' === boundary ? '00:00:00' === match[1] : '23:59:59' === match[1];
38
+ };
39
+ const isDatePickerDefaultRangeBoundaryPair = (value)=>Array.isArray(value) && value.length >= 2 && isDatePickerDefaultRangeBoundaryValue(value[0], 'start') && isDatePickerDefaultRangeBoundaryValue(value[value.length - 1], 'end');
40
+ const isDatePickerLocalRangeBoundaryValue = (value, boundary)=>{
41
+ const m = dayjs(value);
42
+ if (!m.isValid()) return false;
43
+ return 'start' === boundary ? '00:00:00' === m.format('HH:mm:ss') : '23:59:59' === m.format('HH:mm:ss');
44
+ };
45
+ const isDatePickerRetainedLocalBoundaryPair = (value)=>Array.isArray(value) && value.length >= 2 && isDatePickerLocalRangeBoundaryValue(value[0], 'start') && isDatePickerLocalRangeBoundaryValue(value[value.length - 1], 'end');
46
+ const resolveDatePickerRangeValueInfo = function(value) {
47
+ let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
48
+ const metadataMode = getRangeValueMode(value);
49
+ if (metadataMode) return {
50
+ mode: metadataMode,
51
+ source: 'metadata'
52
+ };
53
+ if ('DatePicker.RangePicker' === options.component && !options.showTime) return {
54
+ mode: 'date',
55
+ source: 'schema'
56
+ };
57
+ if (options.preferDateBoundaryFallback && options.showTime && isDatePickerRetainedLocalBoundaryPair(value)) return {
58
+ mode: 'date',
59
+ source: 'retained-local-date-boundary'
60
+ };
61
+ if (options.preferDateBoundaryFallback && isDatePickerDefaultRangeBoundaryPair(value)) return {
62
+ mode: 'date',
63
+ source: 'retained-date-boundary'
64
+ };
65
+ return {
66
+ source: 'unknown'
67
+ };
68
+ };
23
69
  const normalizeDatePickerParseOptions = function() {
24
70
  let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
25
- if (false === options.utc || options.showTime || 'boolean' == typeof options.gmt || options.picker) return options;
71
+ if (false === options.utc || 'boolean' == typeof options.gmt || options.picker) return options;
72
+ const rangeValueInfo = resolveDatePickerRangeValueInfo(options.value, {
73
+ component: options.component,
74
+ showTime: options.showTime,
75
+ preferDateBoundaryFallback: 'DatePicker.RangePicker' === options.component
76
+ });
77
+ if (options.showTime) {
78
+ if ('date' !== rangeValueInfo.mode || 'retained-local-date-boundary' === rangeValueInfo.source) return options;
79
+ }
26
80
  return {
27
81
  ...options,
28
82
  gmt: true
@@ -64,12 +118,15 @@ const mapRangePicker = function() {
64
118
  return {
65
119
  ...props,
66
120
  format: format,
67
- value: str2moment(props.value, normalizeDatePickerParseOptions(props)),
121
+ value: str2moment(props.value, normalizeDatePickerParseOptions({
122
+ ...props,
123
+ component: 'DatePicker.RangePicker'
124
+ })),
68
125
  onChange: (value)=>{
69
- if (onChange) onChange(value ? [
126
+ if (onChange) onChange(value ? markRangeValueMode([
70
127
  moment2str(getRangeStart(value[0], props), props),
71
128
  moment2str(getRangeEnd(value[1], props), props)
72
- ] : []);
129
+ ], props.showTime ? 'datetime' : 'date') : []);
73
130
  }
74
131
  };
75
132
  };
@@ -198,4 +255,4 @@ const getDateExact = ()=>({
198
255
  tomorrowLocal: ()=>dayjs().add(1, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
199
256
  tomorrowDate: ()=>dayjs().add(1, 'day').format('YYYY-MM-DD')
200
257
  });
201
- export { getDateExact, getDateRanges, mapDatePicker, mapRangePicker, moment2str, normalizeDatePickerParseOptions };
258
+ export { DATE_PICKER_RANGE_VALUE_MODE, getDateExact, getDateRanges, getRangeValueMode, isDatePickerDefaultRangeBoundaryPair, isDatePickerDefaultRangeBoundaryValue, mapDatePicker, mapRangePicker, markRangeValueMode, moment2str, normalizeDatePickerParseOptions, resolveDatePickerRangeValueInfo };
@@ -4,8 +4,9 @@ import lodash from "lodash";
4
4
  import { useTranslation } from "react-i18next";
5
5
  import { useBlockRequestContext } from "../../../block-provider/index.mjs";
6
6
  import { useCollectionManager_deprecated, useCollection_deprecated } from "../../../collection-manager/index.mjs";
7
- import { mergeFilter } from "../../../filter-provider/utils.mjs";
7
+ import { FILTER_OPERATORS_WITH_ARRAY_VALUES, mergeFilter, normalizeDateBetweenValue, shouldUseDefaultDateBoundary } from "../../../filter-provider/utils.mjs";
8
8
  import { useDataLoadingMode } from "../../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem.mjs";
9
+ import { resolveDatePickerRangeValueInfo } from "../date-picker/util.mjs";
9
10
  import { hasDuplicateKeys } from "./utils.mjs";
10
11
  const useGetFilterOptions = ()=>{
11
12
  const { getCollectionFields } = useCollectionManager_deprecated();
@@ -106,6 +107,81 @@ const useFilterFieldOptions = (fields)=>{
106
107
  return getOptions(fields, 1);
107
108
  };
108
109
  const isEmpty = (obj)=>Array.isArray(obj) && 0 === obj.length || obj && 0 === Object.keys(obj).length && Object.getPrototypeOf(obj) === Object.prototype;
110
+ const CUSTOM_FILTER_VARIABLE_REGEXP = /^\{\{\$nFilter\.([^}]+)\}\}$/;
111
+ const getCustomFilterValue = function(items, key) {
112
+ let rawItems = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
113
+ if (rawItems && key in rawItems) return rawItems[key];
114
+ if (key in items) return items[key];
115
+ const arrayItems = Object.keys(items).filter((itemKey)=>itemKey.startsWith("".concat(key, ".")) && /^\d+$/.test(itemKey.slice(key.length + 1))).sort((a, b)=>Number(a.slice(key.length + 1)) - Number(b.slice(key.length + 1))).map((itemKey)=>items[itemKey]);
116
+ return arrayItems.length ? arrayItems : void 0;
117
+ };
118
+ const findCustomFieldSchemaInTree = (schema, key)=>{
119
+ if (!schema) return null;
120
+ if (schema.name === "__custom.".concat(key) || schema.name === key) return schema;
121
+ const properties = schema.properties || {};
122
+ for (const propertyKey of Object.keys(properties)){
123
+ if (propertyKey === "__custom.".concat(key) || propertyKey === key) return properties[propertyKey];
124
+ const found = findCustomFieldSchemaInTree(properties[propertyKey], key);
125
+ if (found) return found;
126
+ }
127
+ return null;
128
+ };
129
+ const findCustomFieldSchema = (schema, key)=>{
130
+ let current = schema;
131
+ while(current){
132
+ const found = findCustomFieldSchemaInTree(current, key);
133
+ if (found) return found;
134
+ current = current.parent;
135
+ }
136
+ return null;
137
+ };
138
+ const getDatePickerComponent = (fieldSchema)=>{
139
+ var _fieldSchema_xcomponentprops;
140
+ return (null == fieldSchema ? void 0 : fieldSchema['x-component']) || (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.component);
141
+ };
142
+ const getDatePickerShowTime = (fieldSchema)=>{
143
+ var _fieldSchema_xcomponentprops;
144
+ return null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.showTime;
145
+ };
146
+ const expandArrayValueFilter = function(filterSchemaItem, filterKey, value, customFlat) {
147
+ let options = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {};
148
+ const pathParts = filterKey.split('.');
149
+ const operator = pathParts.pop();
150
+ if ('$dateBetween' === operator && Array.isArray(value)) {
151
+ const valueInfo = resolveDatePickerRangeValueInfo(value, {
152
+ component: options.component,
153
+ showTime: options.showTime,
154
+ preferDateBoundaryFallback: options.useDefaultDateBoundary
155
+ });
156
+ filterSchemaItem[filterKey] = normalizeDateBetweenValue(value, {
157
+ useDefaultDateBoundary: options.useDefaultDateBoundary,
158
+ valueMode: valueInfo.mode,
159
+ valueSource: valueInfo.source,
160
+ preferDateBoundaryFallback: 'retained-date-boundary' === valueInfo.source
161
+ });
162
+ return;
163
+ }
164
+ if (!Array.isArray(value) || FILTER_OPERATORS_WITH_ARRAY_VALUES.has(operator || '')) {
165
+ filterSchemaItem[filterKey] = value;
166
+ return;
167
+ }
168
+ if (0 === value.length) return void delete filterSchemaItem[filterKey];
169
+ let branchEndIndex = -1;
170
+ for(let index = pathParts.length - 2; index >= 0; index--)if ([
171
+ '$and',
172
+ '$or'
173
+ ].includes(pathParts[index]) && /^\d+$/.test(pathParts[index + 1])) {
174
+ branchEndIndex = index;
175
+ break;
176
+ }
177
+ const branchPath = branchEndIndex >= 0 ? pathParts.slice(0, branchEndIndex + 2).join('.') : '';
178
+ const fieldPath = pathParts.slice(branchEndIndex + 2).join('.');
179
+ const conditions = value.map((item)=>customFlat.unflatten({
180
+ ["".concat(fieldPath, ".").concat(operator)]: item
181
+ }));
182
+ delete filterSchemaItem[filterKey];
183
+ filterSchemaItem[branchPath ? "".concat(branchPath, ".$or") : '$or'] = conditions;
184
+ };
109
185
  const getCustomCondition = function(filter, fieldSchema) {
110
186
  let customFlat = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : flat;
111
187
  var _filterSchema_$and, _filterSchema_$or;
@@ -119,12 +195,14 @@ const getCustomCondition = function(filter, fieldSchema) {
119
195
  {
120
196
  var _flatFieldSchema_$and, _flatFieldSchema_$or;
121
197
  for(const filterKey in filterSchemaItem){
122
- var _filterSchemaItem_filterKey;
123
- const match = null == (_filterSchemaItem_filterKey = filterSchemaItem[filterKey]) ? void 0 : _filterSchemaItem_filterKey.slice(11, -2);
124
- const collection = null == match ? void 0 : match.split('.')[0];
125
- const filterItems = Object.keys(items).filter((item)=>item.includes(collection));
126
- if (filterItems.length > 1) filterSchemaItem[filterKey] = filterItems.map((key)=>items[key]);
127
- else filterSchemaItem[filterKey] = items[filterItems[0]];
198
+ const match = 'string' == typeof filterSchemaItem[filterKey] && filterSchemaItem[filterKey].match(CUSTOM_FILTER_VARIABLE_REGEXP);
199
+ if (!match) continue;
200
+ const customFieldSchema = findCustomFieldSchema(fieldSchema, match[1]);
201
+ expandArrayValueFilter(filterSchemaItem, filterKey, getCustomFilterValue(items, match[1], filter || {}), customFlat, {
202
+ useDefaultDateBoundary: shouldUseDefaultDateBoundary(customFieldSchema),
203
+ component: getDatePickerComponent(customFieldSchema),
204
+ showTime: getDatePickerShowTime(customFieldSchema)
205
+ });
128
206
  }
129
207
  for(const item in filterSchemaItem)if (!filterSchemaItem[item] || filterSchemaItem[item].includes('$nFilter')) delete filterSchemaItem[item];
130
208
  const flatFieldSchema = customFlat.unflatten(filterSchemaItem);
@@ -836,14 +836,13 @@ const formItemSettings = new SchemaSettings({
836
836
  return isAssociationField && IsShowMultipleSwitch();
837
837
  },
838
838
  useComponentProps () {
839
- var _fieldSchema_xcomponentprops;
840
839
  const { t } = useTranslation();
841
840
  const field = useField();
842
841
  const fieldSchema = useFieldSchema();
843
842
  const { dn, refresh } = useDesignable();
844
843
  return {
845
844
  title: t('Allow multiple'),
846
- checked: (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.multiple) === void 0 ? true : fieldSchema['x-component-props'].multiple,
845
+ checked: void 0 === (fieldSchema['x-component-props'] || {}).multiple ? true : fieldSchema['x-component-props'].multiple,
847
846
  onChange (value) {
848
847
  const schema = {
849
848
  ['x-uid']: fieldSchema['x-uid']
@@ -83,6 +83,7 @@ export declare const useInheritsTableColumnInitializerFields: () => {
83
83
  export declare const useFormItemInitializerFields: (options?: any) => SchemaInitializerItemType[];
84
84
  export declare const useFilterFormItemInitializerFields: (options?: any) => SchemaInitializerItemType[];
85
85
  export declare const useAssociatedFormItemInitializerFields: (options?: any) => SchemaInitializerItemType[];
86
+ export declare const createFilterAssociatedResultSchema: (schemaName: any, field: any, collectionName: any, fieldPath: any) => SchemaInitializerItemType;
86
87
  export declare const useFilterAssociatedFormItemInitializerFields: () => SchemaInitializerItemType[];
87
88
  export declare const useInheritsFormItemInitializerFields: (options?: any) => {
88
89
  [x: string]: SchemaInitializerItemType[];