@pisell/materials 1.0.570 → 1.0.572

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 (34) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/index.js +1 -1
  5. package/build/lowcode/meta.js +2 -2
  6. package/build/lowcode/preview.js +6 -6
  7. package/build/lowcode/render/default/view.js +17 -17
  8. package/build/lowcode/view.js +16 -16
  9. package/es/components/cardPro/index.d.ts +1 -1
  10. package/es/components/cardPro/index.less +44 -47
  11. package/es/components/dataSourceComponents/dataSourceForm/BaseForm.js +94 -3
  12. package/es/components/dataSourceComponents/dataSourceForm/type.d.ts +8 -0
  13. package/es/components/dataSourceComponents/dataSourceForm/utils.d.ts +1 -0
  14. package/es/components/dataSourceComponents/dataSourceForm/utils.js +11 -0
  15. package/es/components/dataSourceComponents/dataSourceTable/BaseTable.js +46 -8
  16. package/es/components/dataSourceComponents/dataSourceTable/hooks/useDrawerState.d.ts +2 -2
  17. package/es/components/dataSourceComponents/provider/actions/ActionsContext.d.ts +6 -1
  18. package/es/components/dataSourceComponents/provider/actions/ActionsProvider.d.ts +4 -1
  19. package/es/components/dataSourceComponents/provider/actions/ActionsProvider.js +0 -1
  20. package/lib/components/cardPro/index.d.ts +1 -1
  21. package/lib/components/cardPro/index.js +41 -3
  22. package/lib/components/cardPro/index.less +44 -47
  23. package/lib/components/dataSourceComponents/dataSourceForm/BaseForm.js +77 -4
  24. package/lib/components/dataSourceComponents/dataSourceForm/type.d.ts +8 -0
  25. package/lib/components/dataSourceComponents/dataSourceForm/utils.d.ts +1 -0
  26. package/lib/components/dataSourceComponents/dataSourceForm/utils.js +8 -0
  27. package/lib/components/dataSourceComponents/dataSourceTable/BaseTable.js +14 -2
  28. package/lib/components/dataSourceComponents/dataSourceTable/hooks/useDrawerState.d.ts +2 -2
  29. package/lib/components/dataSourceComponents/provider/actions/ActionsContext.d.ts +6 -1
  30. package/lib/components/dataSourceComponents/provider/actions/ActionsProvider.d.ts +4 -1
  31. package/lowcode/data-source-form/meta.ts +131 -0
  32. package/lowcode/data-source-form/snippets.ts +54 -0
  33. package/lowcode/data-source-table/utils.tsx +28 -0
  34. package/package.json +2 -2
@@ -34,13 +34,19 @@ __export(BaseForm_exports, {
34
34
  module.exports = __toCommonJS(BaseForm_exports);
35
35
  var import_react = __toESM(require("react"));
36
36
  var import_classnames = __toESM(require("classnames"));
37
+ var import_ahooks = require("ahooks");
38
+ var import_pisellModal = __toESM(require("../../../components/pisellModal"));
39
+ var import_useCtxActions = __toESM(require("../hooks/useCtxActions"));
37
40
  var import_useDataSource = __toESM(require("../hooks/useDataSource"));
41
+ var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
38
42
  var import_form = __toESM(require("../../form"));
39
43
  var import_FormSettingProvider = __toESM(require("./provider/formSetting/FormSettingProvider"));
40
44
  var import_page_header = __toESM(require("../../page-header"));
45
+ var import_utils = require("./utils");
41
46
  var import_index = require("./index.less");
42
47
  var BaseForm = (0, import_react.forwardRef)(
43
48
  (props, ref) => {
49
+ var _a;
44
50
  const {
45
51
  title,
46
52
  description,
@@ -57,13 +63,17 @@ var BaseForm = (0, import_react.forwardRef)(
57
63
  formatSubmitValues,
58
64
  formatInitialValues,
59
65
  customSubmit,
66
+ leaveConfirmConfig,
60
67
  ...others
61
68
  } = props;
69
+ const context = (0, import_useEngineContext.default)();
70
+ const { setBeforeClose } = (0, import_useCtxActions.default)();
71
+ const { getApp } = (_a = context.appHelper) == null ? void 0 : _a.utils;
62
72
  const formRef = (0, import_react.useRef)(null);
63
73
  const { get } = (0, import_useDataSource.default)();
64
74
  (0, import_react.useEffect)(() => {
65
- var _a;
66
- (_a = formRef.current) == null ? void 0 : _a.resetFields();
75
+ var _a2;
76
+ (_a2 = formRef.current) == null ? void 0 : _a2.resetFields();
67
77
  }, [dataSource]);
68
78
  (0, import_react.useEffect)(() => {
69
79
  document.body.id = "body";
@@ -72,12 +82,75 @@ var BaseForm = (0, import_react.forwardRef)(
72
82
  (0, import_react.useEffect)(() => {
73
83
  if (["edit", "view"].includes(renderMode || "") && dataSource) {
74
84
  get == null ? void 0 : get.runAsync().then((res) => {
75
- var _a;
85
+ var _a2;
76
86
  const formattedValues = formatInitialValues ? formatInitialValues(res) : res;
77
- (_a = formRef.current) == null ? void 0 : _a.setFieldsValue(formattedValues);
87
+ (_a2 = formRef.current) == null ? void 0 : _a2.setFields((0, import_utils.formObjValueToArray)(formattedValues));
78
88
  });
79
89
  }
80
90
  }, [renderMode, dataSource, formatInitialValues]);
91
+ const checkFormClose = (0, import_ahooks.useMemoizedFn)(async () => {
92
+ var _a2;
93
+ const isFormChanged = (_a2 = formRef.current) == null ? void 0 : _a2.isFieldsTouched();
94
+ if (isFormChanged) {
95
+ return new Promise((resolve) => {
96
+ import_pisellModal.default.confirm({
97
+ title: leaveConfirmConfig == null ? void 0 : leaveConfirmConfig.title,
98
+ content: leaveConfirmConfig == null ? void 0 : leaveConfirmConfig.content,
99
+ okText: leaveConfirmConfig == null ? void 0 : leaveConfirmConfig.okText,
100
+ cancelText: leaveConfirmConfig == null ? void 0 : leaveConfirmConfig.cancelText,
101
+ onOk: () => {
102
+ var _a3;
103
+ (_a3 = formRef.current) == null ? void 0 : _a3.resetFields();
104
+ resolve(true);
105
+ },
106
+ onCancel: () => {
107
+ resolve(false);
108
+ }
109
+ });
110
+ });
111
+ }
112
+ return true;
113
+ });
114
+ (0, import_react.useEffect)(() => {
115
+ if (leaveConfirmConfig == null ? void 0 : leaveConfirmConfig.enable) {
116
+ setBeforeClose == null ? void 0 : setBeforeClose(checkFormClose);
117
+ }
118
+ }, [leaveConfirmConfig]);
119
+ (0, import_react.useEffect)(() => {
120
+ var _a2, _b;
121
+ if (leaveConfirmConfig == null ? void 0 : leaveConfirmConfig.enable) {
122
+ const history = (_b = (_a2 = getApp == null ? void 0 : getApp()) == null ? void 0 : _a2.history) == null ? void 0 : _b.instance;
123
+ let unblock = history == null ? void 0 : history.block((location, action) => {
124
+ var _a3;
125
+ const isFormChanged = (_a3 = formRef.current) == null ? void 0 : _a3.isFieldsTouched();
126
+ if (isFormChanged) {
127
+ import_pisellModal.default.confirm({
128
+ title: leaveConfirmConfig.title,
129
+ content: leaveConfirmConfig.content,
130
+ okText: leaveConfirmConfig.okText,
131
+ cancelText: leaveConfirmConfig.cancelText,
132
+ onOk: () => {
133
+ unblock == null ? void 0 : unblock();
134
+ if (action === "PUSH") {
135
+ history.push(location);
136
+ } else if (action === "POP") {
137
+ history.go(-1);
138
+ } else if (action === "REPLACE") {
139
+ history.replace(location);
140
+ }
141
+ },
142
+ onCancel: () => {
143
+ }
144
+ });
145
+ return false;
146
+ }
147
+ return true;
148
+ });
149
+ return () => {
150
+ unblock == null ? void 0 : unblock();
151
+ };
152
+ }
153
+ }, []);
81
154
  return /* @__PURE__ */ import_react.default.createElement(
82
155
  import_FormSettingProvider.default,
83
156
  {
@@ -20,4 +20,12 @@ export interface DataSourceFormProps {
20
20
  formatSubmitValues?: (values: Record<string, any>) => Record<string, any>;
21
21
  formatInitialValues?: (values: Record<string, any>) => Record<string, any>;
22
22
  customSubmit?: (values: Record<string, any>) => Promise<any>;
23
+ leaveConfirmConfig?: {
24
+ enable: boolean;
25
+ title: string;
26
+ content: string;
27
+ icon: React.ReactNode;
28
+ okText: string;
29
+ cancelText: string;
30
+ };
23
31
  }
@@ -50,3 +50,4 @@ export declare const getNestedValue: (obj: Record<string, any>, path: string) =>
50
50
  export declare const renderValueWithMap: (value: any, valueMap?: Record<string, string>, renderMode?: ModeType) => React.JSX.Element | null;
51
51
  export declare function toArr(str: string | number | (string | number)[]): (string | number)[];
52
52
  export declare const filterSystemFields: (params: Record<string, any>) => Record<string, any>;
53
+ export declare const formObjValueToArray: (obj: Record<string, any>) => any[];
@@ -32,6 +32,7 @@ __export(utils_exports, {
32
32
  filterSystemFields: () => filterSystemFields,
33
33
  formItemNameReplace: () => formItemNameReplace,
34
34
  formItemNameReverse: () => formItemNameReverse,
35
+ formObjValueToArray: () => formObjValueToArray,
35
36
  getNestedValue: () => getNestedValue,
36
37
  isValidDomain: () => isValidDomain,
37
38
  renderValueWithMap: () => renderValueWithMap,
@@ -394,11 +395,18 @@ var filterSystemFields = (params) => {
394
395
  return acc;
395
396
  }, {});
396
397
  };
398
+ var formObjValueToArray = (obj) => {
399
+ return Object.keys(obj).reduce((acc, key) => {
400
+ acc.push({ name: key, value: obj[key] });
401
+ return acc;
402
+ }, []);
403
+ };
397
404
  // Annotate the CommonJS export names for ESM import in node:
398
405
  0 && (module.exports = {
399
406
  filterSystemFields,
400
407
  formItemNameReplace,
401
408
  formItemNameReverse,
409
+ formObjValueToArray,
402
410
  getNestedValue,
403
411
  isValidDomain,
404
412
  renderValueWithMap,
@@ -58,6 +58,10 @@ var BaseTable = (props) => {
58
58
  const { list } = (0, import_useDataSource.default)();
59
59
  const { data } = list;
60
60
  const { dataSourceKey, dataSourceKeyRef } = (0, import_useDataSourceKey.default)();
61
+ const beforeClose = (0, import_react.useRef)();
62
+ const setBeforeClose = (0, import_react.useCallback)((fn) => {
63
+ beforeClose.current = fn;
64
+ }, []);
61
65
  const {
62
66
  drawerVisible,
63
67
  setDrawerVisible,
@@ -94,7 +98,13 @@ var BaseTable = (props) => {
94
98
  currentDataSource: dataSource
95
99
  });
96
100
  }, [dataSource]);
97
- const handleCloseDrawer = () => {
101
+ const handleCloseDrawer = async () => {
102
+ if (beforeClose.current) {
103
+ const canClose = await beforeClose.current();
104
+ if (!canClose) {
105
+ return;
106
+ }
107
+ }
98
108
  closeDrawer();
99
109
  registerValueVariable == null ? void 0 : registerValueVariable(componentId, {
100
110
  currentRecord: null
@@ -124,7 +134,9 @@ var BaseTable = (props) => {
124
134
  {
125
135
  visible: drawerVisible,
126
136
  setVisible: setDrawerVisible,
127
- refreshTableData: refreshData
137
+ refreshTableData: refreshData,
138
+ setBeforeClose,
139
+ beforeClose: beforeClose.current
128
140
  },
129
141
  /* @__PURE__ */ import_react.default.createElement(
130
142
  Container,
@@ -9,7 +9,7 @@ declare const useDrawerState: (operationContent?: {
9
9
  openDrawer: (item: OperationItem) => void;
10
10
  closeDrawer: () => void;
11
11
  drawerContent: import("react").ReactNode;
12
- Container: typeof Drawer | {
12
+ Container: {
13
13
  (props: import("../../../pisellModal").PisellModalProps): import("react").JSX.Element;
14
14
  confirm: (props: import("../../../pisellModal/components/functions").PisellModalFuncProps) => {
15
15
  destroy: () => void;
@@ -33,7 +33,7 @@ declare const useDrawerState: (operationContent?: {
33
33
  update: (configUpdate: import("antd").ModalFuncProps | ((prevConfig: import("antd").ModalFuncProps) => import("antd").ModalFuncProps)) => void;
34
34
  };
35
35
  Information: (props: import("../../../pisellModal/components/Information").InformationProps) => import("react").JSX.Element;
36
- };
36
+ } | typeof Drawer;
37
37
  containerProps: {};
38
38
  };
39
39
  export default useDrawerState;
@@ -1,6 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  export interface ActionsContextType {
3
- [key: string]: any;
3
+ visible?: boolean;
4
+ setVisible?: (visible: boolean) => void;
5
+ refreshTableData?: () => void;
6
+ onClose?: () => void;
7
+ beforeClose?: () => boolean | Promise<boolean>;
8
+ setBeforeClose?: (beforeClose: () => boolean | Promise<boolean>) => void;
4
9
  }
5
10
  declare const ActionsContext: import("react").Context<ActionsContextType>;
6
11
  export default ActionsContext;
@@ -1,9 +1,12 @@
1
1
  import React from 'react';
2
2
  import { ActionsContextType } from './ActionsContext';
3
+ interface ActionsProviderProps extends ActionsContextType {
4
+ children: React.ReactNode;
5
+ }
3
6
  /**
4
7
  * 自定义请求的provider
5
8
  * @param props
6
9
  * @constructor
7
10
  */
8
- declare const ActionsProvider: React.FC<ActionsContextType>;
11
+ declare const ActionsProvider: React.FC<ActionsProviderProps>;
9
12
  export default ActionsProvider;
@@ -472,6 +472,137 @@ const dataSourceForm: MetaType = {
472
472
  },
473
473
  ],
474
474
  },
475
+ {
476
+ type: 'group',
477
+ title: {
478
+ type: 'i18n',
479
+ 'en-US': 'Interaction behavior',
480
+ 'zh-CN': '交互行为',
481
+ },
482
+ display: 'accordion',
483
+ items: [
484
+ {
485
+ name: 'leaveConfirmConfig',
486
+ title: {
487
+ label: {
488
+ type: 'i18n',
489
+ 'en-US': 'Unsaved warning',
490
+ 'zh-CN': '未保存离开提示',
491
+ },
492
+ },
493
+ setter: {
494
+ componentName: 'ObjectSetter',
495
+ props: {
496
+ config: {
497
+ items: [
498
+ {
499
+ name: 'enable',
500
+ title: {
501
+ type: 'i18n',
502
+ 'en-US': 'Enable',
503
+ 'zh-CN': '启用',
504
+ },
505
+ setter: 'BoolSetter',
506
+ isRequired: true,
507
+ },
508
+ {
509
+ name: 'icon',
510
+ title: {
511
+ type: 'i18n',
512
+ 'en-US': 'Icon',
513
+ 'zh-CN': '图标',
514
+ },
515
+ setter: [
516
+ {
517
+ componentName: 'SlotSetter',
518
+ initialValue: {
519
+ type: 'JSSlot',
520
+ value: [
521
+ {
522
+ componentName: 'Icon',
523
+ props: {
524
+ type: 'SmileOutlined',
525
+ size: 20,
526
+ rotate: 0,
527
+ spin: false,
528
+ },
529
+ },
530
+ ],
531
+ },
532
+ defaultValue: null,
533
+ },
534
+ ],
535
+ },
536
+ {
537
+ name: 'title',
538
+ title: {
539
+ type: 'i18n',
540
+ 'en-US': 'Title',
541
+ 'zh-CN': '标题',
542
+ },
543
+ setter: ['PisellI18nSetter', 'VariableSetter'],
544
+ defaultValue: {
545
+ type: 'i18n',
546
+ en: 'Unsaved Changes',
547
+ 'zh-CN': '未保存的更改',
548
+ 'zh-HK': '未保存的更改',
549
+ },
550
+ },
551
+ {
552
+ name: 'content',
553
+ title: {
554
+ type: 'i18n',
555
+ 'en-US': 'Helper text',
556
+ 'zh-CN': '辅助文字',
557
+ },
558
+ setter: ['PisellI18nSetter', 'VariableSetter'],
559
+ defaultValue: {
560
+ type: 'i18n',
561
+ en: 'You have unsaved changes. Are you sure you want to leave?',
562
+ 'zh-CN': '您有未保存的更改,确定要离开?',
563
+ 'zh-HK': '您有未保存的更改,確定要離開?',
564
+ },
565
+ },
566
+ {
567
+ name: 'cancelText',
568
+ title: {
569
+ type: 'i18n',
570
+ 'en-US': 'Cancel button text',
571
+ 'zh-CN': '取消按钮文字',
572
+ },
573
+ setter: ['PisellI18nSetter', 'VariableSetter'],
574
+ defaultValue: {
575
+ type: 'i18n',
576
+ en: 'Cancel',
577
+ 'zh-CN': '取消',
578
+ 'zh-HK': '取消',
579
+ },
580
+ },
581
+ {
582
+ name: 'okText',
583
+ title: {
584
+ type: 'i18n',
585
+ 'en-US': 'OK button text',
586
+ 'zh-CN': '确定按钮文字',
587
+ },
588
+ setter: ['PisellI18nSetter', 'VariableSetter'],
589
+ defaultValue: {
590
+ type: 'i18n',
591
+ en: 'Leave',
592
+ 'zh-CN': '离开',
593
+ 'zh-HK': '離開',
594
+ },
595
+ },
596
+ ],
597
+ },
598
+ columns: 1,
599
+ forceInline: 1,
600
+ mode: 'popup',
601
+ },
602
+ },
603
+ },
604
+ ]
605
+ },
475
606
  ],
476
607
  configure: {
477
608
  props: [
@@ -39,6 +39,33 @@ export default [
39
39
  "function onFinishFailed({ values, errorFields, outOfDate }) {\n console.log('onFinishFailed', values, errorFields, outOfDate);\n}",
40
40
  },
41
41
  name: 'basic',
42
+ leaveConfirmConfig: {
43
+ enable: true,
44
+ title: {
45
+ type: 'i18n',
46
+ en: 'Unsaved Changes',
47
+ 'zh-CN': '未保存的更改',
48
+ 'zh-HK': '未保存的更改',
49
+ },
50
+ content: {
51
+ type: 'i18n',
52
+ en: 'You have unsaved changes. Are you sure you want to leave?',
53
+ 'zh-CN': '您有未保存的更改,确定要离开?',
54
+ 'zh-HK': '您有未保存的更改,確定要離開?',
55
+ },
56
+ okText: {
57
+ type: 'i18n',
58
+ en: 'Leave',
59
+ 'zh-CN': '离开',
60
+ 'zh-HK': '離開',
61
+ },
62
+ cancelText: {
63
+ type: 'i18n',
64
+ en: 'Cancel',
65
+ 'zh-CN': '取消',
66
+ 'zh-HK': '取消',
67
+ },
68
+ },
42
69
  },
43
70
  children: [],
44
71
  },
@@ -85,6 +112,33 @@ export default [
85
112
  "function onFinishFailed({ values, errorFields, outOfDate }) {\n console.log('onFinishFailed', values, errorFields, outOfDate);\n}",
86
113
  },
87
114
  name: 'basic',
115
+ leaveConfirmConfig: {
116
+ enable: true,
117
+ title: {
118
+ type: 'i18n',
119
+ en: 'Unsaved Changes',
120
+ 'zh-CN': '未保存的更改',
121
+ 'zh-HK': '未保存的更改',
122
+ },
123
+ content: {
124
+ type: 'i18n',
125
+ en: 'You have unsaved changes. Are you sure you want to leave?',
126
+ 'zh-CN': '您有未保存的更改,确定要离开?',
127
+ 'zh-HK': '您有未保存的更改,確定要離開?',
128
+ },
129
+ okText: {
130
+ type: 'i18n',
131
+ en: 'Leave',
132
+ 'zh-CN': '离开',
133
+ 'zh-HK': '離開',
134
+ },
135
+ cancelText: {
136
+ type: 'i18n',
137
+ en: 'Cancel',
138
+ 'zh-CN': '取消',
139
+ 'zh-HK': '取消',
140
+ },
141
+ },
88
142
  },
89
143
  children: [],
90
144
  },
@@ -272,6 +272,34 @@ export const getFormContent = (target: any, mode: 'add' | 'edit' | 'view') => {
272
272
  mode !== 'add'
273
273
  ? genDataSourceValueKey(target, 'currentRecord')
274
274
  : undefined,
275
+ leaveConfirmConfig: mode !== 'view' ? {
276
+ enable: true,
277
+ title: {
278
+ type: 'i18n',
279
+ en: 'Unsaved Changes',
280
+ 'zh-CN': '未保存的更改',
281
+ 'zh-HK': '未保存的更改',
282
+ },
283
+ content: {
284
+ type: 'i18n',
285
+ en: 'You have unsaved changes. Are you sure you want to leave?',
286
+ 'zh-CN': '您有未保存的更改,确定要离开?',
287
+ 'zh-HK': '您有未保存的更改,確定要離開?',
288
+ },
289
+ okText: {
290
+ type: 'i18n',
291
+ en: 'Leave',
292
+ 'zh-CN': '离开',
293
+ 'zh-HK': '離開',
294
+ },
295
+ cancelText: {
296
+ type: 'i18n',
297
+ en: 'Cancel',
298
+ 'zh-CN': '取消',
299
+ 'zh-HK': '取消',
300
+ },
301
+ }
302
+ : undefined,
275
303
  },
276
304
  children: childrenSchemas,
277
305
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "1.0.570",
3
+ "version": "1.0.572",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -69,8 +69,8 @@
69
69
  "libphonenumber-js": "^1.11.17",
70
70
  "swiper": "^8.4.7",
71
71
  "react-barcode": "^1.5.3",
72
- "@pisell/date-picker": "1.0.115",
73
72
  "@pisell/utils": "1.0.43",
73
+ "@pisell/date-picker": "1.0.115",
74
74
  "@pisell/icon": "0.0.10"
75
75
  },
76
76
  "peerDependencies": {