@tachybase/client 0.23.48 → 0.23.58

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 (101) hide show
  1. package/es/application/Application.d.ts +3 -0
  2. package/es/application/Application.mjs +8 -0
  3. package/es/application/hooks/index.d.ts +1 -0
  4. package/es/application/hooks/index.mjs +1 -0
  5. package/es/application/hooks/useGlobalVariable.d.ts +1 -0
  6. package/es/application/hooks/useGlobalVariable.mjs +18 -0
  7. package/es/application/schema-settings/hooks/index.d.ts +1 -1
  8. package/es/application/schema-settings/hooks/index.mjs +6 -8
  9. package/es/block-provider/hooks/index.mjs +4 -1
  10. package/es/built-in/index.mjs +3 -0
  11. package/es/built-in/locale/LocalePlugin.mjs +5 -1
  12. package/es/built-in/system-settings/SystemSettingsProvider.d.ts +2 -3
  13. package/es/built-in/system-settings/SystemSettingsProvider.mjs +4 -3
  14. package/es/built-in/system-settings/SystemSettingsShortcut.mjs +11 -8
  15. package/es/collection-manager/Configuration/AddCollectionAction.mjs +12 -2
  16. package/es/collection-manager/Configuration/ImportXlsx/ImportXlsxMetaAction.d.ts +2 -0
  17. package/es/collection-manager/Configuration/ImportXlsx/ImportXlsxMetaAction.mjs +255 -0
  18. package/es/collection-manager/Configuration/ImportXlsx/XlsxCollectionSchema.d.ts +89 -0
  19. package/es/collection-manager/Configuration/ImportXlsx/XlsxCollectionSchema.mjs +96 -0
  20. package/es/collection-manager/Configuration/ImportXlsx/XlsxEditFieldAction.d.ts +3 -0
  21. package/es/collection-manager/Configuration/ImportXlsx/XlsxEditFieldAction.mjs +47 -0
  22. package/es/collection-manager/Configuration/ImportXlsx/setUpdateXlsxCollectionField.d.ts +3 -0
  23. package/es/collection-manager/Configuration/ImportXlsx/setUpdateXlsxCollectionField.mjs +44 -0
  24. package/es/collection-manager/Configuration/ImportXlsx/xlsxFieldsConfigure.d.ts +1 -0
  25. package/es/collection-manager/Configuration/ImportXlsx/xlsxFieldsConfigure.mjs +380 -0
  26. package/es/collection-manager/Configuration/ImportXlsx/xlsxFormValueContextProvider.d.ts +8 -0
  27. package/es/collection-manager/Configuration/ImportXlsx/xlsxFormValueContextProvider.mjs +4 -0
  28. package/es/collection-manager/Configuration/ImportXlsx/xlsxImportAction.d.ts +1 -0
  29. package/es/collection-manager/Configuration/ImportXlsx/xlsxImportAction.mjs +187 -0
  30. package/es/collection-manager/Configuration/ImportXlsx/xlsxPreviewTable.d.ts +1 -0
  31. package/es/collection-manager/Configuration/ImportXlsx/xlsxPreviewTable.mjs +30 -0
  32. package/es/collection-manager/collectionPlugin.mjs +3 -1
  33. package/es/collection-manager/templates/import.mjs +1 -1
  34. package/es/collection-manager/templates/xlsx.d.ts +11 -0
  35. package/es/collection-manager/templates/xlsx.mjs +19 -0
  36. package/es/modules/blocks/data-blocks/table/hooks/useTableBlockProps.mjs +4 -2
  37. package/es/modules/fields/component/Radio/radioComponentFieldSettings.mjs +0 -4
  38. package/es/schema-component/antd/action/Action.Designer.mjs +5 -2
  39. package/es/schema-component/antd/action/Action.Modal.mjs +20 -31
  40. package/es/schema-component/antd/action/Action.Modal.style.d.ts +4 -0
  41. package/es/schema-component/antd/action/Action.Modal.style.mjs +35 -0
  42. package/es/schema-component/antd/action/utils.d.ts +1 -1
  43. package/es/schema-component/antd/action/utils.mjs +70 -70
  44. package/es/schema-component/antd/checkbox/Checkbox.mjs +6 -1
  45. package/es/schema-component/antd/page/Page.d.ts +1 -5
  46. package/es/schema-component/antd/page/Page.mjs +227 -146
  47. package/es/schema-component/antd/page/Page.style.d.ts +5 -0
  48. package/es/schema-component/antd/page/Page.style.mjs +45 -0
  49. package/es/schema-component/antd/page/PageDesigner.d.ts +3 -0
  50. package/es/schema-component/antd/page/PageDesigner.mjs +28 -0
  51. package/es/schema-component/antd/page/PageTabDesigner.d.ts +0 -3
  52. package/es/schema-component/antd/page/PageTabDesigner.mjs +3 -50
  53. package/es/schema-component/antd/page/style.d.ts +1 -1
  54. package/es/schema-component/antd/page/style.mjs +3 -13
  55. package/es/schema-component/antd/password/Password.d.ts +1 -1
  56. package/es/schema-component/antd/scroll-area/ScrollArea.d.ts +1 -1
  57. package/es/schema-component/antd/scroll-area/ScrollArea.mjs +2 -1
  58. package/es/schema-component/antd/variable/TextArea.mjs +1 -1
  59. package/es/schema-component/antd/variable/TextAreaWithGlobalScope.d.ts +13 -0
  60. package/es/schema-component/antd/variable/TextAreaWithGlobalScope.mjs +59 -0
  61. package/es/schema-component/antd/variable/index.d.ts +1 -0
  62. package/es/schema-component/antd/variable/index.mjs +3 -0
  63. package/lib/application/Application.js +8 -0
  64. package/lib/application/hooks/index.js +9 -0
  65. package/lib/application/hooks/useGlobalVariable.js +52 -0
  66. package/lib/application/schema-settings/hooks/index.js +6 -8
  67. package/lib/block-provider/hooks/index.js +6 -3
  68. package/lib/built-in/index.js +3 -0
  69. package/lib/built-in/locale/LocalePlugin.js +5 -1
  70. package/lib/built-in/system-settings/SystemSettingsProvider.js +4 -3
  71. package/lib/built-in/system-settings/SystemSettingsShortcut.js +11 -8
  72. package/lib/collection-manager/Configuration/AddCollectionAction.js +12 -2
  73. package/lib/collection-manager/Configuration/ImportXlsx/ImportXlsxMetaAction.js +304 -0
  74. package/lib/collection-manager/Configuration/ImportXlsx/XlsxCollectionSchema.js +130 -0
  75. package/lib/collection-manager/Configuration/ImportXlsx/XlsxEditFieldAction.js +81 -0
  76. package/lib/collection-manager/Configuration/ImportXlsx/setUpdateXlsxCollectionField.js +78 -0
  77. package/lib/collection-manager/Configuration/ImportXlsx/xlsxFieldsConfigure.js +414 -0
  78. package/lib/collection-manager/Configuration/ImportXlsx/xlsxFormValueContextProvider.js +53 -0
  79. package/lib/collection-manager/Configuration/ImportXlsx/xlsxImportAction.js +235 -0
  80. package/lib/collection-manager/Configuration/ImportXlsx/xlsxPreviewTable.js +64 -0
  81. package/lib/collection-manager/collectionPlugin.js +3 -1
  82. package/lib/collection-manager/templates/import.js +1 -1
  83. package/lib/collection-manager/templates/xlsx.js +53 -0
  84. package/lib/locale/zh-CN.js +4 -1
  85. package/lib/modules/blocks/data-blocks/table/hooks/useTableBlockProps.js +4 -2
  86. package/lib/modules/fields/component/Radio/radioComponentFieldSettings.js +0 -4
  87. package/lib/schema-component/antd/action/Action.Designer.js +5 -2
  88. package/lib/schema-component/antd/action/Action.Modal.js +20 -31
  89. package/lib/schema-component/antd/action/Action.Modal.style.js +69 -0
  90. package/lib/schema-component/antd/action/utils.js +70 -70
  91. package/lib/schema-component/antd/checkbox/Checkbox.js +6 -1
  92. package/lib/schema-component/antd/page/Page.js +227 -146
  93. package/lib/schema-component/antd/page/Page.style.js +79 -0
  94. package/lib/schema-component/antd/page/PageDesigner.js +62 -0
  95. package/lib/schema-component/antd/page/PageTabDesigner.js +2 -50
  96. package/lib/schema-component/antd/page/style.js +3 -13
  97. package/lib/schema-component/antd/scroll-area/ScrollArea.js +2 -1
  98. package/lib/schema-component/antd/variable/TextArea.js +1 -1
  99. package/lib/schema-component/antd/variable/TextAreaWithGlobalScope.js +94 -0
  100. package/lib/schema-component/antd/variable/index.js +13 -1
  101. package/package.json +7 -7
@@ -70,6 +70,7 @@ export declare class Application {
70
70
  pluginContextMenu: PluginContextMenu;
71
71
  AttachmentPreviewManager: AttachmentPreviewManager;
72
72
  name: string;
73
+ globalVars: Record<string, any>;
73
74
  loading: boolean;
74
75
  maintained: boolean;
75
76
  maintaining: boolean;
@@ -105,4 +106,6 @@ export declare class Application {
105
106
  addScopes(scopes: Record<string, any>): void;
106
107
  getRootComponent(): () => import("react/jsx-runtime").JSX.Element;
107
108
  mount(containerOrSelector: Element | ShadowRoot | string): import("react-dom/client").Root;
109
+ addGlobalVar(key: string, value: any): void;
110
+ getGlobalVar(key: any): any;
108
111
  }
@@ -239,6 +239,12 @@ class Application {
239
239
  root.render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(App, {}));
240
240
  return root;
241
241
  }
242
+ addGlobalVar(key, value) {
243
+ (0, __WEBPACK_EXTERNAL_MODULE_lodash__.set)(this.globalVars, key, value);
244
+ }
245
+ getGlobalVar(key) {
246
+ return (0, __WEBPACK_EXTERNAL_MODULE_lodash__.get)(this.globalVars, key);
247
+ }
242
248
  constructor(options = {}){
243
249
  _define_property(this, "options", void 0);
244
250
  _define_property(this, "providers", void 0);
@@ -261,6 +267,7 @@ class Application {
261
267
  _define_property(this, "pluginContextMenu", void 0);
262
268
  _define_property(this, "AttachmentPreviewManager", void 0);
263
269
  _define_property(this, "name", void 0);
270
+ _define_property(this, "globalVars", void 0);
264
271
  _define_property(this, "loading", void 0);
265
272
  _define_property(this, "maintained", void 0);
266
273
  _define_property(this, "maintaining", void 0);
@@ -274,6 +281,7 @@ class Application {
274
281
  ...__WEBPACK_EXTERNAL_MODULE__schema_initializer_components_index_mjs__,
275
282
  CollectionField: __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_CollectionField_mjs__.CollectionField
276
283
  };
284
+ this.globalVars = {};
277
285
  this.loading = true;
278
286
  this.maintained = false;
279
287
  this.maintaining = false;
@@ -1,3 +1,4 @@
1
1
  export * from './useApp';
2
2
  export * from './usePlugin';
3
3
  export * from './useRouter';
4
+ export * from './useGlobalVariable';
@@ -1,3 +1,4 @@
1
1
  export * from "./useApp.mjs";
2
2
  export * from "./usePlugin.mjs";
3
3
  export * from "./useRouter.mjs";
4
+ export * from "./useGlobalVariable.mjs";
@@ -0,0 +1 @@
1
+ export declare const useGlobalVariable: (key: string) => any;
@@ -0,0 +1,18 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "./index.mjs";
4
+ const useGlobalVariable = (key)=>{
5
+ const app = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useApp)();
6
+ const variable = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>app.getGlobalVar(key), [
7
+ app,
8
+ key
9
+ ]);
10
+ if ((0, __WEBPACK_EXTERNAL_MODULE_lodash__.isFunction)(variable)) try {
11
+ return variable();
12
+ } catch (error) {
13
+ console.error("Error calling global variable function for key: ".concat(key), error);
14
+ return;
15
+ }
16
+ return variable;
17
+ };
18
+ export { useGlobalVariable };
@@ -13,6 +13,6 @@ export declare function useSchemaSettingsRender<T = {}>(name: string, options?:
13
13
  render: () => any;
14
14
  } | {
15
15
  exists: boolean;
16
- render: (options2?: UseSchemaSettingsRenderOptions) => React.FunctionComponentElement<any> | React.FunctionComponentElement<SchemaSettingOptions<any>>;
16
+ render: (options2?: UseSchemaSettingsRenderOptions) => React.FunctionComponentElement<SchemaSettingOptions<any>>;
17
17
  };
18
18
  export {};
@@ -8,7 +8,6 @@ function useSchemaSettingsRender(name, options) {
8
8
  app.schemaSettingsManager,
9
9
  name
10
10
  ]);
11
- const renderCache = __WEBPACK_EXTERNAL_MODULE_react__["default"].useRef({});
12
11
  if (!name) return {
13
12
  exists: false,
14
13
  render: ()=>null
@@ -24,17 +23,16 @@ function useSchemaSettingsRender(name, options) {
24
23
  exists: true,
25
24
  render: function() {
26
25
  let options2 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
27
- const key = JSON.stringify(options2);
28
- if (key && renderCache.current[key]) return renderCache.current[key];
29
26
  const newItems = [
30
27
  ...__WEBPACK_EXTERNAL_MODULE__SchemaSettingsDefaults_mjs__.defaultSettingItems,
31
28
  ...schemaSetting.options.items
32
29
  ];
33
- return renderCache.current[key] = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__components_index_mjs__.SchemaSettingsWrapper, {
34
- ...{
35
- ...schemaSetting.options,
36
- items: newItems
37
- },
30
+ const newOptions = {
31
+ ...schemaSetting.options,
32
+ items: newItems
33
+ };
34
+ return /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__components_index_mjs__.SchemaSettingsWrapper, {
35
+ ...newOptions,
38
36
  ...options,
39
37
  ...options2
40
38
  });
@@ -447,6 +447,7 @@ const useResetBlockActionProps = ()=>{
447
447
  const { targets, uid } = findFilterTargets(fieldSchema);
448
448
  form.reset();
449
449
  actionField.data.loading = true;
450
+ let prevMergedFilter = {};
450
451
  try {
451
452
  await Promise.all(getDataBlocks().map(async (block)=>{
452
453
  var _block_service_params, _block_service_params_, _block_service_params1;
@@ -458,8 +459,10 @@ const useResetBlockActionProps = ()=>{
458
459
  delete storedFilter[uid];
459
460
  const mergedFilter = (0, __WEBPACK_EXTERNAL_MODULE__filter_provider_utils_mjs__.mergeFilter)([
460
461
  ...Object.values(storedFilter),
461
- block.defaultFilter
462
+ block.defaultFilter,
463
+ prevMergedFilter
462
464
  ]);
465
+ prevMergedFilter = mergedFilter;
463
466
  return block.doFilter({
464
467
  ...param,
465
468
  page: 1,
@@ -229,6 +229,9 @@ const getProps = (app)=>{
229
229
  },
230
230
  'pm.remove': {
231
231
  title: 'Removing plugin'
232
+ },
233
+ refreshEventSource: {
234
+ title: 'Refreshing event source'
232
235
  }
233
236
  };
234
237
  return {
@@ -1,9 +1,9 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_dayjs__ from "dayjs";
4
- import * as __WEBPACK_EXTERNAL_MODULE__loadConstrueLocale_mjs__ from "./loadConstrueLocale.mjs";
5
4
  import * as __WEBPACK_EXTERNAL_MODULE__application_Plugin_mjs__ from "../../application/Plugin.mjs";
6
5
  import * as __WEBPACK_EXTERNAL_MODULE__locale_index_mjs__ from "../../locale/index.mjs";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__loadConstrueLocale_mjs__ from "./loadConstrueLocale.mjs";
7
7
  function _define_property(obj, key, value) {
8
8
  if (key in obj) Object.defineProperty(obj, key, {
9
9
  value: value,
@@ -60,6 +60,10 @@ class LocalePlugin extends __WEBPACK_EXTERNAL_MODULE__application_Plugin_mjs__.P
60
60
  __WEBPACK_EXTERNAL_MODULE_dayjs__["default"].updateLocale(dayjsLang, localeSetting);
61
61
  window['cronLocale'] = null == data ? void 0 : null === (_data_data4 = data.data) || void 0 === _data_data4 ? void 0 : _data_data4.cron;
62
62
  } catch (error) {
63
+ var _error_response;
64
+ if ((null == error ? void 0 : null === (_error_response = error.response) || void 0 === _error_response ? void 0 : _error_response.status) === 401) setTimeout(()=>{
65
+ window.location.href = '/signIn';
66
+ }, 1000);
63
67
  throw error;
64
68
  }
65
69
  }
@@ -1,7 +1,6 @@
1
1
  import React, { ReactNode } from 'react';
2
- import { Result } from 'ahooks/es/useRequest/src/types';
3
- export declare const SystemSettingsContext: React.Context<Result<any, any>>;
4
- export declare const useSystemSettings: () => Result<any, any>;
2
+ export declare const SystemSettingsContext: React.Context<any>;
3
+ export declare const useSystemSettings: () => any;
5
4
  export declare const SystemSettingsProvider: React.FC<{
6
5
  children?: ReactNode;
7
6
  }>;
@@ -6,11 +6,12 @@ SystemSettingsContext.displayName = 'SystemSettingsContext';
6
6
  const useSystemSettings = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(SystemSettingsContext);
7
7
  const SystemSettingsProvider = (props)=>{
8
8
  const result = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)({
9
- url: 'systemSettings:get/1?appends=logo'
9
+ url: 'systemSettings:get'
10
10
  });
11
- if (result.loading) return;
12
11
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SystemSettingsContext.Provider, {
13
- value: result,
12
+ value: {
13
+ ...result
14
+ },
14
15
  children: props.children
15
16
  });
16
17
  };
@@ -23,18 +23,18 @@ const useCloseAction = ()=>{
23
23
  const useSystemSettingsValues = (options)=>{
24
24
  const { visible } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useActionContext)();
25
25
  const result = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useSystemSettings)();
26
- return (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useRequest)(()=>Promise.resolve(result.data), {
26
+ return (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useRequest)(()=>Promise.resolve(null == result ? void 0 : result.data), {
27
27
  ...options,
28
28
  refreshDeps: [
29
- visible
29
+ visible,
30
+ null == result ? void 0 : result.data
30
31
  ]
31
32
  });
32
33
  };
33
34
  const useSaveSystemSettingsValues = ()=>{
34
35
  const { setVisible } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useActionContext)();
35
36
  const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
36
- const { message } = __WEBPACK_EXTERNAL_MODULE_antd__.App.useApp();
37
- const { mutate, data } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useSystemSettings)();
37
+ const { mutate, data } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useSystemSettings)() || {};
38
38
  const api = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useAPIClient)();
39
39
  const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
40
40
  return {
@@ -49,11 +49,11 @@ const useSaveSystemSettingsValues = ()=>{
49
49
  }
50
50
  });
51
51
  await api.request({
52
- url: 'systemSettings:update/1',
52
+ url: 'systemSettings:put',
53
53
  method: 'post',
54
54
  data: values
55
55
  });
56
- message.success(t('Saved successfully'));
56
+ __WEBPACK_EXTERNAL_MODULE_antd__.message.success(t('Saved successfully'));
57
57
  const lang = (null === (_values_enabledLanguages = values.enabledLanguages) || void 0 === _values_enabledLanguages ? void 0 : _values_enabledLanguages[0]) || 'en-US';
58
58
  if (values.enabledLanguages.length < 2 && api.auth.getLocale() !== lang) {
59
59
  api.auth.setLocale('');
@@ -74,11 +74,14 @@ const schema = {
74
74
  type: 'void',
75
75
  title: '{{t("System settings")}}',
76
76
  properties: {
77
- title: {
77
+ raw_title: {
78
78
  type: 'string',
79
79
  title: "{{t('System title')}}",
80
80
  'x-decorator': 'FormItem',
81
- 'x-component': 'Input',
81
+ 'x-component': 'TextAreaWithGlobalScope',
82
+ 'x-component-props': {
83
+ supportsLineBreak: true
84
+ },
82
85
  required: true
83
86
  },
84
87
  logo: {
@@ -15,6 +15,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__ResourceActionProvider_mjs__ from "../Res
15
15
  import * as __WEBPACK_EXTERNAL_MODULE__components_index_mjs__ from "./components/index.mjs";
16
16
  import * as __WEBPACK_EXTERNAL_MODULE__components_TemplateSummary_mjs__ from "./components/TemplateSummary.mjs";
17
17
  import * as __WEBPACK_EXTERNAL_MODULE__ImportCollectionMetaAction_mjs__ from "./ImportCollectionMetaAction.mjs";
18
+ import * as __WEBPACK_EXTERNAL_MODULE__ImportXlsx_ImportXlsxMetaAction_mjs__ from "./ImportXlsx/ImportXlsxMetaAction.mjs";
18
19
  const getSchema = (schema, category, compile)=>{
19
20
  if (!schema) return;
20
21
  const properties = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(schema.configurableProperties);
@@ -134,6 +135,7 @@ const AddCollectionAction = (props)=>{
134
135
  const compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useCompile)();
135
136
  const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
136
137
  const importRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
138
+ const importxlsxRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
137
139
  const items = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
138
140
  const result = [];
139
141
  collectionTemplates.forEach((item)=>{
@@ -158,10 +160,14 @@ const AddCollectionAction = (props)=>{
158
160
  onClick: (info)=>{
159
161
  if ('import' === info.key) {
160
162
  var _importRef_current;
161
- console.log('import', importRef.current);
162
163
  null === (_importRef_current = importRef.current) || void 0 === _importRef_current || _importRef_current.showModal();
163
164
  return;
164
165
  }
166
+ if ('importXlsx' === info.key) {
167
+ var _importxlsxRef_current;
168
+ null === (_importxlsxRef_current = importxlsxRef.current) || void 0 === _importxlsxRef_current || _importxlsxRef_current.showModal();
169
+ return;
170
+ }
165
171
  const schema = getSchema(getTemplate(info.key), category, compile);
166
172
  setSchema(schema);
167
173
  setVisible(true);
@@ -170,7 +176,8 @@ const AddCollectionAction = (props)=>{
170
176
  }), [
171
177
  category,
172
178
  items,
173
- importRef
179
+ importRef,
180
+ importxlsxRef
174
181
  ]);
175
182
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.RecordProvider, {
176
183
  record: record,
@@ -217,6 +224,9 @@ const AddCollectionAction = (props)=>{
217
224
  }),
218
225
  /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ImportCollectionMetaAction_mjs__.ImportCollectionMetaAction, {
219
226
  ref: importRef
227
+ }),
228
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ImportXlsx_ImportXlsxMetaAction_mjs__.ImportXlsxMetaAction, {
229
+ ref: importxlsxRef
220
230
  })
221
231
  ]
222
232
  });
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const ImportXlsxMetaAction: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
@@ -0,0 +1,255 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_dayjs__ from "dayjs";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
8
+ import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
9
+ import * as __WEBPACK_EXTERNAL_MODULE_xlsx__ from "xlsx";
10
+ import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../schema-component/index.mjs";
11
+ import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../hooks/index.mjs";
12
+ import * as __WEBPACK_EXTERNAL_MODULE__XlsxCollectionSchema_mjs__ from "./XlsxCollectionSchema.mjs";
13
+ import * as __WEBPACK_EXTERNAL_MODULE__XlsxEditFieldAction_mjs__ from "./XlsxEditFieldAction.mjs";
14
+ import * as __WEBPACK_EXTERNAL_MODULE__xlsxFieldsConfigure_mjs__ from "./xlsxFieldsConfigure.mjs";
15
+ import * as __WEBPACK_EXTERNAL_MODULE__xlsxPreviewTable_mjs__ from "./xlsxPreviewTable.mjs";
16
+ const { Dragger } = __WEBPACK_EXTERNAL_MODULE_antd__.Upload;
17
+ const ImportUpload = (props)=>{
18
+ const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
19
+ const { close } = props;
20
+ const { getInterface } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useCollectionManager_deprecated)();
21
+ const [fileList, setFile] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)([]);
22
+ const [filedata, setFileData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
23
+ const [visible, setVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
24
+ const [schema, setSchema] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
25
+ const inferType = (values, header)=>{
26
+ const isDateHeader = /date|time|日期/i.test(header);
27
+ const isPossibleDate = isDateHeader && values.every((value)=>(0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])(value).isValid());
28
+ if (isPossibleDate) return 'date';
29
+ const types = values.map((value)=>{
30
+ if (null != value) {
31
+ const valueLower = value.toString().toLowerCase();
32
+ if ('true' === valueLower || 'yes' === valueLower) return 'boolean';
33
+ if ('false' === valueLower || 'no' === valueLower) return 'boolean';
34
+ }
35
+ const num = Number(value);
36
+ if (!isNaN(num)) return Number.isInteger(num) ? 'integer' : 'float';
37
+ try {
38
+ JSON.parse(value);
39
+ return 'json';
40
+ } catch {}
41
+ return 'string';
42
+ });
43
+ const typeCount = types.reduce((acc, type)=>{
44
+ acc[type] = (acc[type] || 0) + 1;
45
+ return acc;
46
+ }, {});
47
+ const uniqueTypes = Object.keys(typeCount);
48
+ if (uniqueTypes.length > 1) return 'string';
49
+ return uniqueTypes[0];
50
+ };
51
+ const inferInterface = (type, header)=>{
52
+ switch(type){
53
+ case 'json':
54
+ return 'json';
55
+ case 'boolean':
56
+ return 'checkbox';
57
+ case 'string':
58
+ return 'input';
59
+ case 'integer':
60
+ return 'integer';
61
+ case 'float':
62
+ return 'number';
63
+ case 'date':
64
+ return 'datetime';
65
+ default:
66
+ return null;
67
+ }
68
+ };
69
+ const handleFileUpload = (file)=>{
70
+ const reader = new FileReader();
71
+ reader.onload = async (e)=>{
72
+ const binaryStr = e.target.result;
73
+ const workbook = __WEBPACK_EXTERNAL_MODULE_xlsx__.read(binaryStr, {
74
+ type: 'binary'
75
+ });
76
+ const firstSheetName = workbook.SheetNames[0];
77
+ const worksheet = workbook.Sheets[firstSheetName];
78
+ const jsonData = __WEBPACK_EXTERNAL_MODULE_xlsx__.utils.sheet_to_json(worksheet, {
79
+ header: 1
80
+ });
81
+ if (0 === jsonData.length) return;
82
+ const headers = jsonData[0];
83
+ const rows = jsonData.slice(1);
84
+ const fields = await Promise.all(headers.map(async (header, index)=>{
85
+ const columnValues = rows.map((row)=>row[index]);
86
+ const type = inferType(columnValues, header);
87
+ const interfaceType = type ? inferInterface(type, header) : null;
88
+ const interfaceConfig = interfaceType ? getInterface(interfaceType) : null;
89
+ const interfaceConfigValues = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(interfaceConfig);
90
+ const defaultUiSchema = (null == interfaceConfigValues ? void 0 : interfaceConfigValues.default.uiSchema) || {};
91
+ const fieldsName = "f_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
92
+ return {
93
+ name: fieldsName,
94
+ type,
95
+ interface: interfaceType,
96
+ uiSchema: {
97
+ title: header,
98
+ ...defaultUiSchema
99
+ }
100
+ };
101
+ }));
102
+ const parseValue = (value, type)=>{
103
+ try {
104
+ switch(type){
105
+ case 'boolean':
106
+ {
107
+ const valueLower = value.toString().toLowerCase();
108
+ if ('true' === valueLower || 'yes' === valueLower) return true;
109
+ if ('false' === valueLower || 'no' === valueLower) return false;
110
+ throw new Error('Invalid boolean');
111
+ }
112
+ case 'integer':
113
+ if (!/^-?\d+$/.test(value)) throw new Error('Invalid integer');
114
+ return parseInt(value, 10);
115
+ case 'float':
116
+ if (!/^-?\d+(\.\d+)?$/.test(value)) throw new Error('Invalid number');
117
+ return Number(value);
118
+ case 'json':
119
+ return JSON.parse(value);
120
+ case 'date':
121
+ if (isNaN(Date.parse(value))) throw new Error('Invalid date');
122
+ return new Date(value);
123
+ default:
124
+ if (null == value || '' === value) return '';
125
+ return value.toString();
126
+ }
127
+ } catch (error) {
128
+ throw new Error("Type conversion error: ".concat(error.message));
129
+ }
130
+ };
131
+ const convertedRows = rows.map((row, rowIndex)=>headers.reduce((acc, header, index)=>{
132
+ var _fields_index, _fields_index1;
133
+ const fieldsName = null === (_fields_index = fields[index]) || void 0 === _fields_index ? void 0 : _fields_index.name;
134
+ const type = null === (_fields_index1 = fields[index]) || void 0 === _fields_index1 ? void 0 : _fields_index1.type;
135
+ if (fieldsName && type) try {
136
+ const convertedValue = parseValue(row[index], type);
137
+ acc[fieldsName] = convertedValue;
138
+ } catch (error) {
139
+ acc[fieldsName] = null;
140
+ __WEBPACK_EXTERNAL_MODULE_antd__.message.error('Error in column "'.concat(header, '" at row ').concat(rowIndex + 1, ": ").concat(error.message));
141
+ }
142
+ return acc;
143
+ }, {}));
144
+ const fileData = {
145
+ fields: fields,
146
+ data: convertedRows
147
+ };
148
+ setFileData(fileData);
149
+ };
150
+ reader.readAsBinaryString(file);
151
+ };
152
+ const importProps = {
153
+ onRemove: (file)=>{
154
+ const index = fileList.indexOf(file);
155
+ const newFileList = fileList.slice();
156
+ newFileList.splice(index, 1);
157
+ setFile(newFileList);
158
+ },
159
+ beforeUpload: (file)=>{
160
+ const isExcel = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' === file.type || file.name.endsWith('.xlsx') || file.name.endsWith('.xls');
161
+ if (!isExcel) {
162
+ __WEBPACK_EXTERNAL_MODULE_antd__.message.error(t('You can only upload Excel files!'));
163
+ return __WEBPACK_EXTERNAL_MODULE_antd__.Upload.LIST_IGNORE;
164
+ }
165
+ handleFileUpload(file);
166
+ setFile([
167
+ file
168
+ ]);
169
+ return false;
170
+ },
171
+ fileList
172
+ };
173
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
174
+ children: [
175
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(Dragger, {
176
+ maxCount: 1,
177
+ ...importProps,
178
+ children: [
179
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("p", {
180
+ className: "ant-upload-drag-icon",
181
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.InboxOutlined, {})
182
+ }),
183
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("p", {
184
+ className: "ant-upload-text",
185
+ children: [
186
+ " ",
187
+ t('Click or drag file to this area to upload')
188
+ ]
189
+ })
190
+ ]
191
+ }),
192
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.ActionContextProvider, {
193
+ value: {
194
+ visible,
195
+ setVisible
196
+ },
197
+ children: [
198
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
199
+ type: "primary",
200
+ onClick: async ()=>{
201
+ const xlsxCollectionSchema = (0, __WEBPACK_EXTERNAL_MODULE__XlsxCollectionSchema_mjs__.createXlsxCollectionSchema)(fileList, filedata);
202
+ setSchema(xlsxCollectionSchema);
203
+ setVisible(true);
204
+ close();
205
+ },
206
+ disabled: 0 === fileList.length,
207
+ style: {
208
+ marginTop: 16
209
+ },
210
+ children: t('Upload')
211
+ }),
212
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponent, {
213
+ schema: schema,
214
+ components: {
215
+ xlsxFieldsConfigure: __WEBPACK_EXTERNAL_MODULE__xlsxFieldsConfigure_mjs__.xlsxFieldsConfigure
216
+ },
217
+ scope: {
218
+ xlsxPreviewTable: __WEBPACK_EXTERNAL_MODULE__xlsxPreviewTable_mjs__.xlsxPreviewTable,
219
+ xlsxImportAction: __WEBPACK_EXTERNAL_MODULE__XlsxEditFieldAction_mjs__.xlsxImportAction
220
+ }
221
+ })
222
+ ]
223
+ })
224
+ ]
225
+ });
226
+ };
227
+ const ImportXlsxMetaAction = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].forwardRef((props, ref)=>{
228
+ const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
229
+ const [isModalOpen, setIsModalOpen] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
230
+ const [loading, setLoading] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
231
+ const showModal = ()=>{
232
+ setIsModalOpen(true);
233
+ };
234
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useImperativeHandle)(ref, ()=>({
235
+ showModal
236
+ }));
237
+ const handleCancel = ()=>{
238
+ setIsModalOpen(false);
239
+ };
240
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
241
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Drawer, {
242
+ title: t('Import collection'),
243
+ footer: void 0,
244
+ open: isModalOpen,
245
+ onClose: handleCancel,
246
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Spin, {
247
+ spinning: loading,
248
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ImportUpload, {
249
+ close: handleCancel
250
+ })
251
+ })
252
+ })
253
+ });
254
+ });
255
+ export { ImportXlsxMetaAction };
@@ -0,0 +1,89 @@
1
+ export declare const createXlsxCollectionSchema: (filelist: any, filedata: any) => {
2
+ type: string;
3
+ properties: {
4
+ [x: string]: {
5
+ type: string;
6
+ 'x-decorator': string;
7
+ 'x-component': string;
8
+ 'x-component-props': {
9
+ width: string;
10
+ };
11
+ 'x-use-component-props': string;
12
+ properties: {
13
+ action: {
14
+ type: string;
15
+ 'x-component': string;
16
+ 'x-component-props': {
17
+ layout: string;
18
+ style: {
19
+ justifyContent: string;
20
+ };
21
+ };
22
+ properties: {
23
+ cancel: {
24
+ title: string;
25
+ 'x-component': string;
26
+ 'x-use-component-props': string;
27
+ };
28
+ submit: {
29
+ title: string;
30
+ 'x-component': string;
31
+ 'x-component-props': {
32
+ type: string;
33
+ htmlType: string;
34
+ };
35
+ 'x-use-component-props': string;
36
+ };
37
+ };
38
+ };
39
+ title: {
40
+ type: string;
41
+ default: any;
42
+ title: string;
43
+ required: boolean;
44
+ 'x-decorator': string;
45
+ 'x-component': string;
46
+ };
47
+ name: {
48
+ type: string;
49
+ title: string;
50
+ default: string;
51
+ required: boolean;
52
+ 'x-decorator': string;
53
+ 'x-component': string;
54
+ 'x-validator': string;
55
+ description: string;
56
+ };
57
+ category: {
58
+ title: string;
59
+ type: string;
60
+ name: string;
61
+ 'x-decorator': string;
62
+ 'x-component': string;
63
+ 'x-component-props': {
64
+ mode: string;
65
+ };
66
+ 'x-reactions': string[];
67
+ };
68
+ description: {
69
+ title: string;
70
+ type: string;
71
+ name: string;
72
+ 'x-decorator': string;
73
+ 'x-component': string;
74
+ };
75
+ fields: {
76
+ type: string;
77
+ title: string;
78
+ default: any;
79
+ 'x-decorator': string;
80
+ 'x-component': string;
81
+ 'x-component-props': {
82
+ filedata: any;
83
+ };
84
+ required: boolean;
85
+ };
86
+ };
87
+ };
88
+ };
89
+ };