@tachybase/client 1.6.21 → 1.6.22

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 (188) hide show
  1. package/es/api-client/APIClient.d.ts +2 -1
  2. package/es/api-client/APIClient.mjs +6 -3
  3. package/es/application/Plugin.d.ts +2 -2
  4. package/es/application/hoc/withDynamicSchemaProps.mjs +1 -1
  5. package/es/application/schema-initializer/hooks/index.mjs +4 -1
  6. package/es/application/schema-settings/components/SchemaSettingsChildren.mjs +14 -14
  7. package/es/application/utils/clientModuleRegistry.d.ts +2 -0
  8. package/es/application/utils/clientModuleRegistry.mjs +9 -0
  9. package/es/application/utils/globalDeps.mjs +3 -3
  10. package/es/block-provider/BlockProvider.d.ts +1 -27
  11. package/es/block-provider/BlockProvider.mjs +1 -3
  12. package/es/block-provider/BlockRequestContext.d.ts +27 -0
  13. package/es/block-provider/BlockRequestContext.mjs +5 -0
  14. package/es/block-provider/FormBlockContext.d.ts +32 -0
  15. package/es/block-provider/FormBlockContext.mjs +5 -0
  16. package/es/block-provider/FormBlockProvider.d.ts +1 -33
  17. package/es/block-provider/FormBlockProvider.mjs +4 -5
  18. package/es/built-in/acl/ACLCollectionFieldProvider.d.ts +1 -0
  19. package/es/built-in/acl/ACLCollectionFieldProvider.mjs +42 -0
  20. package/es/built-in/acl/ACLContext.d.ts +9 -0
  21. package/es/built-in/acl/ACLContext.mjs +24 -0
  22. package/es/built-in/acl/ACLPlugin.mjs +2 -1
  23. package/es/built-in/acl/ACLProvider.d.ts +0 -11
  24. package/es/built-in/acl/ACLProvider.mjs +6 -51
  25. package/es/built-in/acl/index.d.ts +2 -0
  26. package/es/built-in/acl/index.mjs +2 -0
  27. package/es/collection-manager/hooks/useCollectionManager_deprecated.mjs +2 -1
  28. package/es/collection-manager/sub-table.d.ts +1 -1
  29. package/es/data-source/data-source/DataSourceManager.d.ts +1 -2
  30. package/es/data-source/data-source/DataSourceManager.mjs +1 -2
  31. package/es/data-source/data-source/constants.d.ts +2 -0
  32. package/es/data-source/data-source/constants.mjs +3 -0
  33. package/es/data-source/utils.d.ts +2 -2
  34. package/es/data-source/utils.mjs +1 -1
  35. package/es/exports.d.ts +46 -0
  36. package/es/exports.mjs +46 -0
  37. package/es/filter-provider/utils.d.ts +2 -14
  38. package/es/filter-provider/utils.mjs +2 -57
  39. package/es/index.d.ts +1 -46
  40. package/es/index.mjs +4 -46
  41. package/es/modules/fields/component/SubTable/subTablePopoverComponentFieldSettings.d.ts +2 -86
  42. package/es/record-provider/index.mjs +3 -3
  43. package/es/schema-component/antd/action/Action.mjs +7 -6
  44. package/es/schema-component/antd/action/hooks.mjs +3 -2
  45. package/es/schema-component/antd/association-field/AssociationSelect.mjs +4 -3
  46. package/es/schema-component/antd/association-field/hooks.mjs +18 -1
  47. package/es/schema-component/antd/cron/CronSet.mjs +9 -3
  48. package/es/schema-component/antd/filter/conditionUtils.d.ts +2 -0
  49. package/es/schema-component/antd/filter/conditionUtils.mjs +133 -0
  50. package/es/schema-component/antd/filter/dateValueUtils.d.ts +13 -0
  51. package/es/schema-component/antd/filter/dateValueUtils.mjs +66 -0
  52. package/es/schema-component/antd/filter/useFilterActionProps.d.ts +2 -4
  53. package/es/schema-component/antd/filter/useFilterActionProps.mjs +3 -181
  54. package/es/schema-component/antd/filter/useGetFilterOptions.d.ts +2 -0
  55. package/es/schema-component/antd/filter/useGetFilterOptions.mjs +54 -0
  56. package/es/schema-component/antd/form/Form.mjs +1 -1
  57. package/es/schema-component/antd/form-item/FormItem.FilterFormDesigner.mjs +1 -1
  58. package/es/schema-component/antd/form-item/FormItem.d.ts +1 -1
  59. package/es/schema-component/antd/form-item/FormItem.mjs +14 -12
  60. package/es/schema-component/antd/form-item/SchemaSettingOptions.d.ts +1 -14
  61. package/es/schema-component/antd/form-item/SchemaSettingOptions.mjs +1 -33
  62. package/es/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.mjs +4 -3
  63. package/es/schema-component/antd/form-item/hooks/useParseDefaultValue.mjs +5 -3
  64. package/es/schema-component/antd/form-item/operatorUtils.d.ts +14 -0
  65. package/es/schema-component/antd/form-item/operatorUtils.mjs +36 -0
  66. package/es/schema-component/antd/form-v2/Form.mjs +26 -167
  67. package/es/schema-component/antd/form-v2/FormLinkageRules.d.ts +9 -0
  68. package/es/schema-component/antd/form-v2/FormLinkageRules.mjs +191 -0
  69. package/es/schema-component/antd/form-v2/Templates.mjs +1 -1
  70. package/es/schema-component/antd/grid/Grid.mjs +6 -4
  71. package/es/schema-component/antd/grid-card/GridCard.Item.mjs +2 -2
  72. package/es/schema-component/antd/icon-picker/IconFilterInput.mjs +12 -4
  73. package/es/schema-component/antd/icon-picker/IconPicker.mjs +1 -1
  74. package/es/schema-component/antd/input/Json.d.ts +1 -4
  75. package/es/schema-component/antd/input/ReadPretty.mjs +2 -2
  76. package/es/schema-component/antd/input-number/ReadPretty.mjs +1 -1
  77. package/es/schema-component/antd/markdown/Markdown.Void.Designer.mjs +2 -1
  78. package/es/schema-component/antd/markdown/Markdown.Void.mjs +10 -2
  79. package/es/schema-component/antd/markdown/Markdown.mjs +1 -1
  80. package/es/schema-component/antd/markdown/util.mjs +5 -0
  81. package/es/schema-component/antd/rich-text/RichText.mjs +1 -1
  82. package/es/schema-component/antd/select/FormulaSelect.mjs +1 -2
  83. package/es/schema-component/antd/select/ReadPretty.mjs +2 -2
  84. package/es/schema-component/antd/select/Select.mjs +1 -2
  85. package/es/schema-component/antd/select/utils.d.ts +2 -1
  86. package/es/schema-component/antd/select/utils.mjs +2 -2
  87. package/es/schema-component/antd/time-picker/ReadPretty.mjs +1 -1
  88. package/es/schema-component/antd/upload/ReadPretty.mjs +5 -5
  89. package/es/schema-component/antd/upload/Upload.mjs +6 -5
  90. package/es/schema-component/antd/variable/Input.mjs +1 -1
  91. package/es/schema-component/antd/variable/TextArea.mjs +1 -1
  92. package/es/schema-component/hooks/useDesigner.mjs +9 -3
  93. package/es/schema-component/hooks/useOptionalNavigate.d.ts +1 -0
  94. package/es/schema-component/hooks/useOptionalNavigate.mjs +2 -0
  95. package/es/schema-settings/DataTemplates/components/Designer.mjs +2 -1
  96. package/es/schema-settings/VariableInput/hooks/useBaseVariable.mjs +2 -1
  97. package/es/schema-settings/VariableInput/hooks/useBlockCollection.mjs +1 -1
  98. package/es/schema-settings/VariableInput/hooks/useContextAssociationFields.mjs +2 -1
  99. package/es/schema-settings/VariableInput/hooks/useFormVariable.mjs +1 -1
  100. package/es/schema-settings/VariableInput/hooks/useRecordVariable.mjs +1 -1
  101. package/es/style/theme/AntdAppProvider.mjs +2 -2
  102. package/es/user/ChangePassword.d.ts +4 -1
  103. package/es/user/CurrentUserContext.d.ts +2 -0
  104. package/es/user/CurrentUserContext.mjs +5 -0
  105. package/es/user/CurrentUserProvider.d.ts +0 -3
  106. package/es/user/CurrentUserProvider.mjs +3 -5
  107. package/es/user/EditProfile.d.ts +4 -1
  108. package/es/user/LanguageSettings.d.ts +4 -1
  109. package/es/user/SwitchRole.d.ts +4 -1
  110. package/es/user/index.d.ts +1 -0
  111. package/es/user/index.mjs +1 -0
  112. package/es/variables/VariablesProvider.mjs +1 -1
  113. package/lib/api-client/APIClient.js +8 -5
  114. package/lib/application/hoc/withDynamicSchemaProps.js +3 -3
  115. package/lib/application/schema-initializer/hooks/index.js +4 -1
  116. package/lib/application/schema-settings/components/SchemaSettingsChildren.js +14 -14
  117. package/lib/application/utils/clientModuleRegistry.js +46 -0
  118. package/lib/application/utils/globalDeps.js +2 -2
  119. package/lib/block-provider/BlockProvider.js +6 -8
  120. package/lib/block-provider/BlockRequestContext.js +42 -0
  121. package/lib/block-provider/FormBlockContext.js +42 -0
  122. package/lib/block-provider/FormBlockProvider.js +13 -14
  123. package/lib/built-in/acl/ACLCollectionFieldProvider.js +76 -0
  124. package/lib/built-in/acl/ACLContext.js +70 -0
  125. package/lib/built-in/acl/ACLPlugin.js +2 -1
  126. package/lib/built-in/acl/ACLProvider.js +13 -76
  127. package/lib/built-in/acl/index.js +27 -9
  128. package/lib/collection-manager/hooks/useCollectionManager_deprecated.js +4 -3
  129. package/lib/data-source/data-source/DataSourceManager.js +6 -7
  130. package/lib/data-source/data-source/constants.js +40 -0
  131. package/lib/data-source/utils.js +2 -2
  132. package/lib/exports.js +769 -0
  133. package/lib/filter-provider/utils.js +7 -63
  134. package/lib/index.js +10 -714
  135. package/lib/record-provider/index.js +6 -6
  136. package/lib/schema-component/antd/action/Action.js +9 -8
  137. package/lib/schema-component/antd/action/hooks.js +3 -2
  138. package/lib/schema-component/antd/association-field/AssociationSelect.js +3 -2
  139. package/lib/schema-component/antd/association-field/hooks.js +18 -1
  140. package/lib/schema-component/antd/cron/CronSet.js +8 -2
  141. package/lib/schema-component/antd/filter/conditionUtils.js +180 -0
  142. package/lib/schema-component/antd/filter/dateValueUtils.js +116 -0
  143. package/lib/schema-component/antd/filter/useFilterActionProps.js +7 -186
  144. package/lib/schema-component/antd/filter/useGetFilterOptions.js +91 -0
  145. package/lib/schema-component/antd/form/Form.js +4 -4
  146. package/lib/schema-component/antd/form-item/FormItem.FilterFormDesigner.js +2 -2
  147. package/lib/schema-component/antd/form-item/FormItem.js +23 -20
  148. package/lib/schema-component/antd/form-item/SchemaSettingOptions.js +6 -38
  149. package/lib/schema-component/antd/form-item/hooks/useLazyLoadDisplayAssociationFieldsOfForm.js +9 -7
  150. package/lib/schema-component/antd/form-item/hooks/useParseDefaultValue.js +12 -8
  151. package/lib/schema-component/antd/form-item/operatorUtils.js +76 -0
  152. package/lib/schema-component/antd/form-v2/Form.js +204 -317
  153. package/lib/schema-component/antd/form-v2/FormLinkageRules.js +236 -0
  154. package/lib/schema-component/antd/form-v2/Templates.js +2 -2
  155. package/lib/schema-component/antd/grid/Grid.js +11 -9
  156. package/lib/schema-component/antd/grid-card/GridCard.Item.js +2 -2
  157. package/lib/schema-component/antd/icon-picker/IconFilterInput.js +12 -4
  158. package/lib/schema-component/antd/icon-picker/IconPicker.js +1 -1
  159. package/lib/schema-component/antd/input/ReadPretty.js +10 -10
  160. package/lib/schema-component/antd/input-number/ReadPretty.js +1 -1
  161. package/lib/schema-component/antd/markdown/Markdown.Void.Designer.js +6 -5
  162. package/lib/schema-component/antd/markdown/Markdown.Void.js +138 -111
  163. package/lib/schema-component/antd/markdown/Markdown.js +2 -2
  164. package/lib/schema-component/antd/markdown/util.js +5 -0
  165. package/lib/schema-component/antd/rich-text/RichText.js +2 -2
  166. package/lib/schema-component/antd/select/FormulaSelect.js +1 -2
  167. package/lib/schema-component/antd/select/ReadPretty.js +2 -2
  168. package/lib/schema-component/antd/select/Select.js +1 -2
  169. package/lib/schema-component/antd/select/utils.js +6 -3
  170. package/lib/schema-component/antd/time-picker/ReadPretty.js +2 -2
  171. package/lib/schema-component/antd/upload/ReadPretty.js +5 -5
  172. package/lib/schema-component/antd/upload/Upload.js +6 -5
  173. package/lib/schema-component/antd/variable/Input.js +1 -1
  174. package/lib/schema-component/antd/variable/TextArea.js +1 -1
  175. package/lib/schema-component/hooks/useDesigner.js +57 -23
  176. package/lib/schema-component/hooks/useOptionalNavigate.js +36 -0
  177. package/lib/schema-settings/DataTemplates/components/Designer.js +4 -3
  178. package/lib/schema-settings/VariableInput/hooks/useBaseVariable.js +4 -3
  179. package/lib/schema-settings/VariableInput/hooks/useBlockCollection.js +2 -2
  180. package/lib/schema-settings/VariableInput/hooks/useContextAssociationFields.js +4 -3
  181. package/lib/schema-settings/VariableInput/hooks/useFormVariable.js +2 -2
  182. package/lib/schema-settings/VariableInput/hooks/useRecordVariable.js +2 -2
  183. package/lib/style/theme/AntdAppProvider.js +4 -4
  184. package/lib/user/CurrentUserContext.js +42 -0
  185. package/lib/user/CurrentUserProvider.js +6 -14
  186. package/lib/user/index.js +24 -12
  187. package/lib/variables/VariablesProvider.js +2 -2
  188. package/package.json +5 -4
@@ -11,33 +11,7 @@ import { isPatternDisabled } from "../../../schema-settings/isPatternDisabled.mj
11
11
  import { useCompile, useDesignable, useFieldModeOptions } from "../../hooks/index.mjs";
12
12
  import { useOperatorList } from "../filter/useOperators.mjs";
13
13
  import { isFileCollection } from "./FormItem.mjs";
14
- const findFilterOperators = (schema)=>{
15
- while(schema){
16
- if (schema['x-filter-operators']) return {
17
- operators: schema['x-filter-operators'],
18
- uid: schema['x-uid']
19
- };
20
- schema = schema.parent;
21
- }
22
- return {};
23
- };
24
- const getSchemaFilterComponent = (schema)=>{
25
- var _schema_xcomponentprops;
26
- return (null == schema ? void 0 : null == (_schema_xcomponentprops = schema['x-component-props']) ? void 0 : _schema_xcomponentprops.component) || (null == schema ? void 0 : schema['x-component']);
27
- };
28
- const getDefaultFilterOperatorValue = function(schema) {
29
- let operatorList = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [];
30
- var _operatorList_find, _operatorList_;
31
- const component = getSchemaFilterComponent(schema);
32
- if (component) {
33
- const matched = operatorList.find((item)=>{
34
- var _item_schema;
35
- return (null == item ? void 0 : null == (_item_schema = item.schema) ? void 0 : _item_schema['x-component']) === component;
36
- });
37
- if (null == matched ? void 0 : matched.value) return matched.value;
38
- }
39
- return (null == (_operatorList_find = operatorList.find((item)=>null == item ? void 0 : item.selected)) ? void 0 : _operatorList_find.value) || (null == (_operatorList_ = operatorList[0]) ? void 0 : _operatorList_.value);
40
- };
14
+ import { findFilterOperators, getDefaultFilterOperatorValue, useEnsureOperatorsValid } from "./operatorUtils.mjs";
41
15
  const EditTitle = ()=>{
42
16
  var _collectionField_uiSchema;
43
17
  const { getCollectionJoinField } = useCollectionManager_deprecated();
@@ -441,12 +415,6 @@ const EditPattern = ()=>{
441
415
  }
442
416
  }, "pattern");
443
417
  };
444
- const useEnsureOperatorsValid = ()=>{
445
- const fieldSchema = useFieldSchema();
446
- const operatorList = useOperatorList();
447
- const { operators: storedOperators } = findFilterOperators(fieldSchema);
448
- if (storedOperators && operatorList.length && !storedOperators[fieldSchema.name]) storedOperators[fieldSchema.name] = getDefaultFilterOperatorValue(fieldSchema, operatorList);
449
- };
450
418
  const EditOperator = ()=>{
451
419
  const compile = useCompile();
452
420
  const fieldSchema = useFieldSchema();
@@ -3,10 +3,11 @@ import { useField, useFieldSchema, useForm } from "@tachybase/schema";
3
3
  import { nextTick } from "@tego/client";
4
4
  import lodash from "lodash";
5
5
  import { useAssociationNames } from "../../../../block-provider/hooks/index.mjs";
6
- import { useCollectionManager_deprecated, useCollection_deprecated } from "../../../../collection-manager/index.mjs";
6
+ import { useCollection_deprecated } from "../../../../collection-manager/hooks/useCollection_deprecated.mjs";
7
+ import { useCollectionManager_deprecated } from "../../../../collection-manager/hooks/useCollectionManager_deprecated.mjs";
7
8
  import { useCollectionRecordData } from "../../../../data-source/collection-record/CollectionRecordProvider.mjs";
8
- import { useFlag } from "../../../../flag-provider/index.mjs";
9
- import { useVariables } from "../../../../variables/index.mjs";
9
+ import { useFlag } from "../../../../flag-provider/hooks/useFlag.mjs";
10
+ import useVariables from "../../../../variables/hooks/useVariables.mjs";
10
11
  import { transformVariableValue } from "../../../../variables/utils/transformVariableValue.mjs";
11
12
  import { useSubFormValue } from "../../association-field/hooks.mjs";
12
13
  import { isDisplayField } from "../utils.mjs";
@@ -3,10 +3,12 @@ import { reaction, useField, useFieldSchema } from "@tachybase/schema";
3
3
  import { getValuesByPath } from "@tego/client";
4
4
  import lodash from "lodash";
5
5
  import { useRecordIndex } from "../../../../record-provider/index.mjs";
6
- import { useCollection_deprecated } from "../../../../collection-manager/index.mjs";
6
+ import { useCollection_deprecated } from "../../../../collection-manager/hooks/useCollection_deprecated.mjs";
7
7
  import { useCollectionRecord } from "../../../../data-source/collection-record/CollectionRecordProvider.mjs";
8
- import { useFlag } from "../../../../flag-provider/index.mjs";
9
- import { DEBOUNCE_WAIT, useLocalVariables, useVariables } from "../../../../variables/index.mjs";
8
+ import { useFlag } from "../../../../flag-provider/hooks/useFlag.mjs";
9
+ import { DEBOUNCE_WAIT } from "../../../../variables/constants.mjs";
10
+ import useLocalVariables from "../../../../variables/hooks/useLocalVariables.mjs";
11
+ import useVariables from "../../../../variables/hooks/useVariables.mjs";
10
12
  import { getPath } from "../../../../variables/utils/getPath.mjs";
11
13
  import { getVariableName } from "../../../../variables/utils/getVariableName.mjs";
12
14
  import { isVariable } from "../../../../variables/utils/isVariable.mjs";
@@ -0,0 +1,14 @@
1
+ import { Schema } from '@tachybase/schema';
2
+ export declare const findFilterOperators: (schema: Schema) => {
3
+ operators: any;
4
+ uid: any;
5
+ } | {
6
+ operators?: undefined;
7
+ uid?: undefined;
8
+ };
9
+ export declare const getDefaultFilterOperatorValue: (schema: Schema, operatorList?: any[]) => any;
10
+ /**
11
+ * 如果用户没有手动设置过 operator,那么在筛选的时候 operator 会是空的,
12
+ * 该方法确保 operator 一定有值(需要在 FormItem 中调用)
13
+ */
14
+ export declare const useEnsureOperatorsValid: () => void;
@@ -0,0 +1,36 @@
1
+ import { useFieldSchema } from "@tachybase/schema";
2
+ import { useOperatorList } from "../filter/useOperators.mjs";
3
+ const findFilterOperators = (schema)=>{
4
+ while(schema){
5
+ if (schema['x-filter-operators']) return {
6
+ operators: schema['x-filter-operators'],
7
+ uid: schema['x-uid']
8
+ };
9
+ schema = schema.parent;
10
+ }
11
+ return {};
12
+ };
13
+ const getSchemaFilterComponent = (schema)=>{
14
+ var _schema_xcomponentprops;
15
+ return (null == schema ? void 0 : null == (_schema_xcomponentprops = schema['x-component-props']) ? void 0 : _schema_xcomponentprops.component) || (null == schema ? void 0 : schema['x-component']);
16
+ };
17
+ const getDefaultFilterOperatorValue = function(schema) {
18
+ let operatorList = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [];
19
+ var _operatorList_find, _operatorList_;
20
+ const component = getSchemaFilterComponent(schema);
21
+ if (component) {
22
+ const matched = operatorList.find((item)=>{
23
+ var _item_schema;
24
+ return (null == item ? void 0 : null == (_item_schema = item.schema) ? void 0 : _item_schema['x-component']) === component;
25
+ });
26
+ if (null == matched ? void 0 : matched.value) return matched.value;
27
+ }
28
+ return (null == (_operatorList_find = operatorList.find((item)=>null == item ? void 0 : item.selected)) ? void 0 : _operatorList_find.value) || (null == (_operatorList_ = operatorList[0]) ? void 0 : _operatorList_.value);
29
+ };
30
+ const useEnsureOperatorsValid = ()=>{
31
+ const fieldSchema = useFieldSchema();
32
+ const operatorList = useOperatorList();
33
+ const { operators: storedOperators } = findFilterOperators(fieldSchema);
34
+ if (storedOperators && operatorList.length && !storedOperators[fieldSchema.name]) storedOperators[fieldSchema.name] = getDefaultFilterOperatorValue(fieldSchema, operatorList);
35
+ };
36
+ export { findFilterOperators, getDefaultFilterOperatorValue, useEnsureOperatorsValid };
@@ -1,20 +1,14 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useMemo } from "react";
3
- import { FieldContext, FormContext, RecursionField, createForm, observer, onFieldInit, onFormInputChange, reaction, uid, useField, useFieldSchema } from "@tachybase/schema";
4
- import { FormLayout, getValuesByPath } from "@tego/client";
2
+ import react, { useEffect, useMemo } from "react";
3
+ import { FieldContext, FormContext, RecursionField, createForm, observer, onFormInputChange, uid, useField, useFieldSchema } from "@tachybase/schema";
4
+ import { FormLayout } from "@tego/client";
5
5
  import { ConfigProvider, Spin } from "antd";
6
6
  import { createStyles } from "antd-style";
7
- import { useActionContext } from "../index.mjs";
8
- import { useAttach, useComponent } from "../../index.mjs";
9
7
  import { withDynamicSchemaProps } from "../../../application/hoc/withDynamicSchemaProps.mjs";
10
- import { ActionType } from "../../../schema-settings/LinkageRules/type.mjs";
11
- import { useLocalVariables, useVariables } from "../../../variables/index.mjs";
12
- import { getPath } from "../../../variables/utils/getPath.mjs";
13
- import { getVariableName } from "../../../variables/utils/getVariableName.mjs";
14
- import { REGEX_OF_VARIABLE, isVariable } from "../../../variables/utils/isVariable.mjs";
15
- import { getInnermostKeyAndValue, getTargetField } from "../../common/utils/uitls.mjs";
8
+ import { useAttach } from "../../hooks/useAttach.mjs";
9
+ import { useComponent } from "../../hooks/useComponent.mjs";
16
10
  import { useProps } from "../../hooks/useProps.mjs";
17
- import { collectFieldStateOfLinkageRules, getTempFieldState } from "./utils.mjs";
11
+ import { useActionContext } from "../action/hooks.mjs";
18
12
  function _tagged_template_literal(strings, raw) {
19
13
  if (!raw) raw = strings.slice(0);
20
14
  return Object.freeze(Object.defineProperties(strings, {
@@ -32,6 +26,9 @@ function _templateObject() {
32
26
  };
33
27
  return data;
34
28
  }
29
+ const LazyFormLinkageRules = /*#__PURE__*/ react.lazy(()=>import("./FormLinkageRules.mjs").then((module)=>({
30
+ default: module.FormLinkageRules
31
+ })));
35
32
  const useStyles = createStyles((param)=>{
36
33
  let { css } = param;
37
34
  return {
@@ -102,15 +99,14 @@ const getLinkageRules = (fieldSchema)=>{
102
99
  return linkageRules;
103
100
  };
104
101
  const WithForm = (props)=>{
105
- var _this, _fieldSchema_parent;
102
+ var _fieldSchema_parent;
106
103
  const { form } = props;
107
104
  const fieldSchema = useFieldSchema();
108
105
  const { setFormValueChanged } = useActionContext();
109
- const variables = useVariables();
110
- const localVariables = useLocalVariables({
111
- currentForm: form
112
- });
113
- const linkageRules = (null == (_this = getLinkageRules(fieldSchema) || (null == (_fieldSchema_parent = fieldSchema.parent) ? void 0 : _fieldSchema_parent['x-linkage-rules'])) ? void 0 : _this.filter((k)=>!k.disabled)) || [];
106
+ const rawLinkageRules = getLinkageRules(fieldSchema) || (null == (_fieldSchema_parent = fieldSchema.parent) ? void 0 : _fieldSchema_parent['x-linkage-rules']);
107
+ const linkageRules = useMemo(()=>(null == rawLinkageRules ? void 0 : rawLinkageRules.filter((rule)=>!rule.disabled)) || [], [
108
+ rawLinkageRules
109
+ ]);
114
110
  useEffect(()=>{
115
111
  const id = uid();
116
112
  form.addEffects(id, ()=>{
@@ -127,71 +123,28 @@ const WithForm = (props)=>{
127
123
  props.disabled,
128
124
  setFormValueChanged
129
125
  ]);
130
- useEffect(()=>{
131
- const id = uid();
132
- const disposes = [];
133
- form.addEffects(id, ()=>{
134
- linkageRules.forEach((rule)=>{
135
- var _rule_actions;
136
- null == (_rule_actions = rule.actions) || _rule_actions.forEach((action)=>{
137
- var _action_targetFields;
138
- if (null == (_action_targetFields = action.targetFields) ? void 0 : _action_targetFields.length) {
139
- const fields = action.targetFields.join(',');
140
- onFieldInit("*(".concat(fields, ")"), (field, form)=>{
141
- var _field_initStateOfLinkageRules, _field_initStateOfLinkageRules1, _field_initStateOfLinkageRules2, _field_initStateOfLinkageRules3;
142
- field['initStateOfLinkageRules'] = {
143
- display: (null == (_field_initStateOfLinkageRules = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules.display) || getTempFieldState(true, field.display),
144
- required: (null == (_field_initStateOfLinkageRules1 = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules1.required) || getTempFieldState(true, field.required || false),
145
- pattern: (null == (_field_initStateOfLinkageRules2 = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules2.pattern) || getTempFieldState(true, field.pattern),
146
- value: (null == (_field_initStateOfLinkageRules3 = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules3.value) || getTempFieldState(true, field.value || field.initialValue)
147
- };
148
- disposes.push(reaction(()=>{
149
- const fieldValuesInCondition = getFieldValuesInCondition({
150
- linkageRules,
151
- formValues: form.values
152
- });
153
- const variableValuesInCondition = getVariableValuesInCondition({
154
- linkageRules,
155
- localVariables
156
- });
157
- const variableValuesInExpression = getVariableValuesInExpression({
158
- action,
159
- localVariables
160
- });
161
- const result = [
162
- fieldValuesInCondition,
163
- variableValuesInCondition,
164
- variableValuesInExpression
165
- ].map((item)=>JSON.stringify(item)).join(',');
166
- return result;
167
- }, getSubscriber(action, field, rule, variables, localVariables), {
168
- fireImmediately: true
169
- }));
170
- });
171
- }
172
- });
173
- });
174
- });
175
- return ()=>{
176
- form.removeEffects(id);
177
- disposes.forEach((dispose)=>{
178
- dispose();
179
- });
180
- };
181
- }, [
182
- linkageRules
183
- ]);
184
- return 'FormV2' === fieldSchema['x-decorator'] ? /*#__PURE__*/ jsx(FormDecorator, {
126
+ const formElement = 'FormV2' === fieldSchema['x-decorator'] ? /*#__PURE__*/ jsx(FormDecorator, {
185
127
  ...props
186
128
  }) : /*#__PURE__*/ jsx(FormComponent, {
187
129
  ...props
188
130
  });
131
+ if (!linkageRules.length) return formElement;
132
+ return /*#__PURE__*/ jsx(react.Suspense, {
133
+ fallback: formElement,
134
+ children: /*#__PURE__*/ jsx(LazyFormLinkageRules, {
135
+ form: form,
136
+ linkageRules: linkageRules,
137
+ children: formElement
138
+ })
139
+ });
189
140
  };
190
141
  const WithoutForm = (props)=>{
191
142
  const fieldSchema = useFieldSchema();
192
143
  const { setFormValueChanged } = useActionContext();
193
144
  const form = useMemo(()=>createForm({
194
145
  disabled: props.disabled,
146
+ initialValues: props.initialValues,
147
+ values: props.initialValues,
195
148
  effects () {
196
149
  onFormInputChange((form)=>{
197
150
  null == setFormValueChanged || setFormValueChanged(true);
@@ -232,98 +185,4 @@ const Form = withDynamicSchemaProps(observer((props)=>{
232
185
  }), {
233
186
  displayName: 'Form'
234
187
  });
235
- function getSubscriber(action, field, rule, variables, localVariables) {
236
- return ()=>{
237
- collectFieldStateOfLinkageRules({
238
- operator: action.operator,
239
- value: action.value,
240
- field,
241
- condition: rule.condition,
242
- variables,
243
- localVariables
244
- });
245
- setTimeout(async ()=>{
246
- var _field_stateOfLinkageRules;
247
- const fieldName = getFieldNameByOperator(action.operator);
248
- if (!(null == (_field_stateOfLinkageRules = field.stateOfLinkageRules) ? void 0 : _field_stateOfLinkageRules[fieldName])) return;
249
- let stateList = field.stateOfLinkageRules[fieldName];
250
- stateList = await Promise.all(stateList);
251
- stateList = stateList.filter((v)=>v.condition);
252
- const lastState = stateList[stateList.length - 1];
253
- if ('value' === fieldName) {
254
- if (stateList.length > 1) field.value = lastState.value;
255
- } else {
256
- field[fieldName] = null == lastState ? void 0 : lastState.value;
257
- if ('display' === fieldName && (null == lastState ? void 0 : lastState.value) === 'none') field.value = void 0;
258
- }
259
- field.stateOfLinkageRules[fieldName] = null;
260
- });
261
- };
262
- }
263
- function getFieldNameByOperator(operator) {
264
- switch(operator){
265
- case ActionType.Required:
266
- case ActionType.InRequired:
267
- return 'required';
268
- case ActionType.Visible:
269
- case ActionType.None:
270
- case ActionType.Hidden:
271
- return 'display';
272
- case ActionType.Editable:
273
- case ActionType.ReadOnly:
274
- case ActionType.ReadPretty:
275
- return 'pattern';
276
- case ActionType.Value:
277
- return 'value';
278
- default:
279
- return null;
280
- }
281
- }
282
- function getFieldValuesInCondition(param) {
283
- let { linkageRules, formValues } = param;
284
- return linkageRules.map((rule)=>{
285
- const run = (condition)=>{
286
- const type = Object.keys(condition)[0] || '$and';
287
- const conditions = condition[type];
288
- return conditions.map((condition)=>{
289
- if ('$and' in condition || '$or' in condition) return run(condition);
290
- const path = getTargetField(condition).join('.');
291
- return getValuesByPath(formValues, path);
292
- }).filter(Boolean);
293
- };
294
- return run(rule.condition);
295
- });
296
- }
297
- function getVariableValuesInCondition(param) {
298
- let { linkageRules, localVariables } = param;
299
- return linkageRules.map((rule)=>{
300
- const type = Object.keys(rule.condition)[0] || '$and';
301
- const conditions = rule.condition[type];
302
- return conditions.map((condition)=>{
303
- const jsonlogic = getInnermostKeyAndValue(condition);
304
- if (!jsonlogic) return null;
305
- if (isVariable(jsonlogic.value)) return getVariableValue(jsonlogic.value, localVariables);
306
- return jsonlogic.value;
307
- }).filter(Boolean);
308
- });
309
- }
310
- function getVariableValuesInExpression(param) {
311
- let { action, localVariables } = param;
312
- var _value_match;
313
- const actionValue = action.value;
314
- const mode = null == actionValue ? void 0 : actionValue.mode;
315
- const value = (null == actionValue ? void 0 : actionValue.value) || (null == actionValue ? void 0 : actionValue.result);
316
- if ('express' !== mode) return;
317
- if (null == value) return;
318
- return null == (_value_match = value.match(REGEX_OF_VARIABLE)) ? void 0 : _value_match.map((variableString)=>getVariableValue(variableString, localVariables)).filter(Boolean);
319
- }
320
- function getVariableValue(variableString, localVariables) {
321
- var _localVariables_find;
322
- if (!isVariable(variableString)) return;
323
- const variableName = getVariableName(variableString);
324
- const ctx = {
325
- [variableName]: null == (_localVariables_find = localVariables.find((item)=>item.name === variableName)) ? void 0 : _localVariables_find.ctx
326
- };
327
- return getValuesByPath(ctx, getPath(variableString));
328
- }
329
188
  export { Form };
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { Form as FormilyForm } from '@tachybase/schema';
3
+ interface FormLinkageRulesProps {
4
+ children: React.ReactNode;
5
+ form: FormilyForm;
6
+ linkageRules: any[];
7
+ }
8
+ export declare const FormLinkageRules: ({ children, form, linkageRules }: FormLinkageRulesProps) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,191 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { onFieldInit, reaction, uid } from "@tachybase/schema";
4
+ import { getValuesByPath } from "@tego/client";
5
+ import { ActionType } from "../../../schema-settings/LinkageRules/type.mjs";
6
+ import useLocalVariables from "../../../variables/hooks/useLocalVariables.mjs";
7
+ import useVariables from "../../../variables/hooks/useVariables.mjs";
8
+ import { getPath } from "../../../variables/utils/getPath.mjs";
9
+ import { getVariableName } from "../../../variables/utils/getVariableName.mjs";
10
+ import { REGEX_OF_VARIABLE, isVariable } from "../../../variables/utils/isVariable.mjs";
11
+ import { getInnermostKeyAndValue, getTargetField } from "../../common/utils/uitls.mjs";
12
+ import { collectFieldStateOfLinkageRules, getTempFieldState } from "./utils.mjs";
13
+ const FormLinkageRules = (param)=>{
14
+ let { children, form, linkageRules } = param;
15
+ const variables = useVariables();
16
+ const localVariables = useLocalVariables({
17
+ currentForm: form
18
+ });
19
+ const variablesRef = useRef(variables);
20
+ const localVariablesRef = useRef(localVariables);
21
+ variablesRef.current = variables;
22
+ localVariablesRef.current = localVariables;
23
+ useEffect(()=>{
24
+ const id = uid();
25
+ const disposes = [];
26
+ const timers = new Set();
27
+ let disposed = false;
28
+ form.addEffects(id, ()=>{
29
+ linkageRules.forEach((rule)=>{
30
+ var _rule_actions;
31
+ null == (_rule_actions = rule.actions) || _rule_actions.forEach((action)=>{
32
+ var _action_targetFields;
33
+ if (null == (_action_targetFields = action.targetFields) ? void 0 : _action_targetFields.length) {
34
+ const fields = action.targetFields.join(',');
35
+ onFieldInit("*(".concat(fields, ")"), (field, form)=>{
36
+ var _field_initStateOfLinkageRules, _field_initStateOfLinkageRules1, _field_initStateOfLinkageRules2, _field_initStateOfLinkageRules3;
37
+ field['initStateOfLinkageRules'] = {
38
+ display: (null == (_field_initStateOfLinkageRules = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules.display) || getTempFieldState(true, field.display),
39
+ required: (null == (_field_initStateOfLinkageRules1 = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules1.required) || getTempFieldState(true, field.required || false),
40
+ pattern: (null == (_field_initStateOfLinkageRules2 = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules2.pattern) || getTempFieldState(true, field.pattern),
41
+ value: (null == (_field_initStateOfLinkageRules3 = field.initStateOfLinkageRules) ? void 0 : _field_initStateOfLinkageRules3.value) || getTempFieldState(true, field.value || field.initialValue)
42
+ };
43
+ disposes.push(reaction(()=>{
44
+ const latestLocalVariables = localVariablesRef.current;
45
+ const fieldValuesInCondition = getFieldValuesInCondition({
46
+ linkageRules,
47
+ formValues: form.values
48
+ });
49
+ const variableValuesInCondition = getVariableValuesInCondition({
50
+ linkageRules,
51
+ localVariables: latestLocalVariables
52
+ });
53
+ const variableValuesInExpression = getVariableValuesInExpression({
54
+ action,
55
+ localVariables: latestLocalVariables
56
+ });
57
+ return [
58
+ fieldValuesInCondition,
59
+ variableValuesInCondition,
60
+ variableValuesInExpression
61
+ ].map((item)=>JSON.stringify(item)).join(',');
62
+ }, getSubscriber(action, field, rule, variablesRef, localVariablesRef, {
63
+ timers,
64
+ isDisposed: ()=>disposed
65
+ }), {
66
+ fireImmediately: true
67
+ }));
68
+ });
69
+ }
70
+ });
71
+ });
72
+ });
73
+ return ()=>{
74
+ disposed = true;
75
+ form.removeEffects(id);
76
+ disposes.forEach((dispose)=>{
77
+ dispose();
78
+ });
79
+ timers.forEach((timer)=>{
80
+ clearTimeout(timer);
81
+ });
82
+ timers.clear();
83
+ };
84
+ }, [
85
+ form,
86
+ linkageRules
87
+ ]);
88
+ return /*#__PURE__*/ jsx(Fragment, {
89
+ children: children
90
+ });
91
+ };
92
+ function getSubscriber(action, field, rule, variablesRef, localVariablesRef, scheduler) {
93
+ return ()=>{
94
+ if (scheduler.isDisposed()) return;
95
+ collectFieldStateOfLinkageRules({
96
+ operator: action.operator,
97
+ value: action.value,
98
+ field,
99
+ condition: rule.condition,
100
+ variables: variablesRef.current,
101
+ localVariables: localVariablesRef.current
102
+ });
103
+ const timer = setTimeout(async ()=>{
104
+ var _field_stateOfLinkageRules;
105
+ scheduler.timers.delete(timer);
106
+ if (scheduler.isDisposed()) return;
107
+ const fieldName = getFieldNameByOperator(action.operator);
108
+ if (!(null == (_field_stateOfLinkageRules = field.stateOfLinkageRules) ? void 0 : _field_stateOfLinkageRules[fieldName])) return;
109
+ let stateList = field.stateOfLinkageRules[fieldName];
110
+ stateList = await Promise.all(stateList);
111
+ if (scheduler.isDisposed()) return;
112
+ stateList = stateList.filter((v)=>v.condition);
113
+ const lastState = stateList[stateList.length - 1];
114
+ if ('value' === fieldName) {
115
+ if (stateList.length > 1) field.value = lastState.value;
116
+ } else {
117
+ field[fieldName] = null == lastState ? void 0 : lastState.value;
118
+ if ('display' === fieldName && (null == lastState ? void 0 : lastState.value) === 'none') field.value = void 0;
119
+ }
120
+ field.stateOfLinkageRules[fieldName] = null;
121
+ });
122
+ scheduler.timers.add(timer);
123
+ };
124
+ }
125
+ function getFieldNameByOperator(operator) {
126
+ switch(operator){
127
+ case ActionType.Required:
128
+ case ActionType.InRequired:
129
+ return 'required';
130
+ case ActionType.Visible:
131
+ case ActionType.None:
132
+ case ActionType.Hidden:
133
+ return 'display';
134
+ case ActionType.Editable:
135
+ case ActionType.ReadOnly:
136
+ case ActionType.ReadPretty:
137
+ return 'pattern';
138
+ case ActionType.Value:
139
+ return 'value';
140
+ default:
141
+ return null;
142
+ }
143
+ }
144
+ function getFieldValuesInCondition(param) {
145
+ let { linkageRules, formValues } = param;
146
+ return linkageRules.map((rule)=>{
147
+ const run = (condition)=>{
148
+ const type = Object.keys(condition)[0] || '$and';
149
+ const conditions = condition[type];
150
+ return conditions.map((condition)=>{
151
+ if ('$and' in condition || '$or' in condition) return run(condition);
152
+ const path = getTargetField(condition).join('.');
153
+ return getValuesByPath(formValues, path);
154
+ }).filter(Boolean);
155
+ };
156
+ return run(rule.condition);
157
+ });
158
+ }
159
+ function getVariableValuesInCondition(param) {
160
+ let { linkageRules, localVariables } = param;
161
+ return linkageRules.map((rule)=>{
162
+ const type = Object.keys(rule.condition)[0] || '$and';
163
+ const conditions = rule.condition[type];
164
+ return conditions.map((condition)=>{
165
+ const jsonlogic = getInnermostKeyAndValue(condition);
166
+ if (!jsonlogic) return null;
167
+ if (isVariable(jsonlogic.value)) return getVariableValue(jsonlogic.value, localVariables);
168
+ return jsonlogic.value;
169
+ }).filter(Boolean);
170
+ });
171
+ }
172
+ function getVariableValuesInExpression(param) {
173
+ let { action, localVariables } = param;
174
+ var _value_match;
175
+ const actionValue = action.value;
176
+ const mode = null == actionValue ? void 0 : actionValue.mode;
177
+ const value = (null == actionValue ? void 0 : actionValue.value) || (null == actionValue ? void 0 : actionValue.result);
178
+ if ('express' !== mode) return;
179
+ if (null == value) return;
180
+ return null == (_value_match = value.match(REGEX_OF_VARIABLE)) ? void 0 : _value_match.map((variableString)=>getVariableValue(variableString, localVariables)).filter(Boolean);
181
+ }
182
+ function getVariableValue(variableString, localVariables) {
183
+ var _localVariables_find;
184
+ if (!isVariable(variableString)) return;
185
+ const variableName = getVariableName(variableString);
186
+ const ctx = {
187
+ [variableName]: null == (_localVariables_find = localVariables.find((item)=>item.name === variableName)) ? void 0 : _localVariables_find.ctx
188
+ };
189
+ return getValuesByPath(ctx, getPath(variableString));
190
+ }
191
+ export { FormLinkageRules };
@@ -8,7 +8,7 @@ import { useTranslation } from "react-i18next";
8
8
  import { useToken } from "../__builtins__/index.mjs";
9
9
  import { useAPIClient } from "../../../api-client/index.mjs";
10
10
  import { findFormBlock } from "../../../block-provider/index.mjs";
11
- import { useFormBlockContext } from "../../../block-provider/FormBlockProvider.mjs";
11
+ import { useFormBlockContext } from "../../../block-provider/FormBlockContext.mjs";
12
12
  import { useCollectionManager_deprecated } from "../../../collection-manager/index.mjs";
13
13
  import { compatibleDataId } from "../../../schema-settings/DataTemplates/FormDataTemplates.mjs";
14
14
  import { RemoteSelect } from "../remote-select/index.mjs";
@@ -2,13 +2,15 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import react, { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { RecursionField, Schema, observer, uid, useField, useFieldSchema } from "@tachybase/schema";
4
4
  import { TinyColor } from "@ctrl/tinycolor";
5
- import { useDndContext, useDndMonitor, useDraggable, useDroppable } from "@dnd-kit/core";
5
+ import { DndContext, useDndContext, useDndMonitor, useDraggable, useDroppable } from "@dnd-kit/core";
6
6
  import classnames from "classnames";
7
7
  import lodash from "lodash";
8
8
  import { useToken } from "../__builtins__/index.mjs";
9
- import { SchemaComponent, useDesignable, useFormBlockContext, useSchemaInitializerRender } from "../../../index.mjs";
10
- import { useFormBlockType } from "../../../block-provider/index.mjs";
11
- import { DndContext } from "../../common/dnd-context/index.mjs";
9
+ import { useSchemaInitializerRender } from "../../../application/schema-initializer/hooks/index.mjs";
10
+ import { useFormBlockContext } from "../../../block-provider/FormBlockContext.mjs";
11
+ import { useFormBlockType } from "../../../block-provider/FormBlockProvider.mjs";
12
+ import { SchemaComponent } from "../../core/SchemaComponent.mjs";
13
+ import { useDesignable } from "../../hooks/useDesignable.mjs";
12
14
  import Grid_style from "./Grid.style.mjs";
13
15
  const GridRowContext = /*#__PURE__*/ createContext({});
14
16
  GridRowContext.displayName = 'GridRowContext';
@@ -3,11 +3,11 @@ import "react";
3
3
  import { useField, useFieldSchema } from "@tachybase/schema";
4
4
  import { Card } from "antd";
5
5
  import { createStyles } from "antd-style";
6
- import { useNavigate } from "react-router-dom";
7
6
  import { withDynamicSchemaProps } from "../../../application/hoc/withDynamicSchemaProps.mjs";
8
7
  import { useCollection } from "../../../data-source/index.mjs";
9
8
  import { useCollectionParentRecordData } from "../../../data-source/collection-record/CollectionRecordProvider.mjs";
10
9
  import { RecordProvider } from "../../../record-provider/index.mjs";
10
+ import { useOptionalNavigate } from "../../hooks/useOptionalNavigate.mjs";
11
11
  import { useGridCustomPageUrl } from "./hooks.mjs";
12
12
  function _tagged_template_literal(strings, raw) {
13
13
  if (!raw) raw = strings.slice(0);
@@ -47,7 +47,7 @@ const GridCardItem = withDynamicSchemaProps((props)=>{
47
47
  const field = useField();
48
48
  const fieldSchema = useFieldSchema();
49
49
  const parentRecordData = useCollectionParentRecordData();
50
- const navigate = useNavigate();
50
+ const navigate = useOptionalNavigate();
51
51
  const { styles } = useStyles();
52
52
  const detailUrl = useGridCustomPageUrl({
53
53
  field,
@@ -1,14 +1,22 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { useEffect, useMemo } from "react";
2
3
  import { Input } from "antd";
3
4
  import lodash from "lodash";
4
5
  import { useTranslation } from "react-i18next";
5
6
  const IconFilterInput = (props)=>{
6
7
  const { changeFilterKey } = props;
7
8
  const { t } = useTranslation();
8
- const onChange = lodash.debounce((e)=>{
9
- const inputValue = e.target.value;
10
- changeFilterKey(inputValue);
11
- }, 100);
9
+ const onChange = useMemo(()=>lodash.debounce((e)=>{
10
+ const inputValue = e.target.value;
11
+ changeFilterKey(inputValue);
12
+ }, 100), [
13
+ changeFilterKey
14
+ ]);
15
+ useEffect(()=>()=>{
16
+ onChange.cancel();
17
+ }, [
18
+ onChange
19
+ ]);
12
20
  return /*#__PURE__*/ jsx(Input, {
13
21
  allowClear: true,
14
22
  placeholder: t("The key in Antd, such as 'ApiOutlined', ignoring case"),