@faasjs/ant-design 0.0.2-beta.387 → 0.0.2-beta.390

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,6 +74,7 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
74
74
 
75
75
  ### Variables
76
76
 
77
+ - [ConfigContext](#configcontext)
77
78
  - [DatePicker](#datepicker)
78
79
  - [TimePicker](#timepicker)
79
80
 
@@ -81,7 +82,7 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
81
82
 
82
83
  - [Blank](#blank)
83
84
  - [Calendar](#calendar)
84
- - [Config](#config)
85
+ - [ConfigProvider](#configprovider)
85
86
  - [Description](#description)
86
87
  - [Form](#form)
87
88
  - [FormItem](#formitem)
@@ -89,8 +90,8 @@ Form are based on [Ant Design's Form.Item component](https://ant.design/componen
89
90
  - [Table](#table)
90
91
  - [Title](#title)
91
92
  - [transferOptions](#transferoptions)
93
+ - [useConfigContext](#useconfigcontext)
92
94
  - [useDrawer](#usedrawer)
93
- - [useFaasState](#usefaasstate)
94
95
  - [useModal](#usemodal)
95
96
 
96
97
  ## Type aliases
@@ -425,6 +426,12 @@ ___
425
426
 
426
427
  ## Variables
427
428
 
429
+ ### ConfigContext
430
+
431
+ • `Const` **ConfigContext**: `Context`<[`FaasState`](#faasstate)\>
432
+
433
+ ___
434
+
428
435
  ### DatePicker
429
436
 
430
437
  • `Const` **DatePicker**: `PickerComponentClass`<`Omit`<`PickerBaseProps`<`Dayjs`\>, ``"locale"`` \| ``"generateConfig"`` \| ``"hideHeader"`` \| ``"components"``\> & {} & {} & `Omit`<`PickerDateProps`<`Dayjs`\>, ``"locale"`` \| ``"generateConfig"`` \| ``"hideHeader"`` \| ``"components"``\> & {} & {} & `Omit`<`PickerTimeProps`<`Dayjs`\>, ``"locale"`` \| ``"generateConfig"`` \| ``"hideHeader"`` \| ``"components"``\> & {} & {}, `unknown`\> & {}
@@ -475,29 +482,32 @@ ___
475
482
 
476
483
  ___
477
484
 
478
- ### Config
485
+ ### ConfigProvider
479
486
 
480
- ▸ **Config**(`props`): `JSX.Element`
487
+ ▸ **ConfigProvider**(`props`): `Element`
481
488
 
482
- Config for all @faasjs/ant-design components.
489
+ Config for @faasjs/ant-design components.
483
490
 
484
491
  #### Parameters
485
492
 
486
493
  | Name | Type |
487
494
  | :------ | :------ |
488
495
  | `props` | `Object` |
496
+ | `props.children` | `ReactNode` |
489
497
  | `props.config` | `Partial`<[`FaasState`](#faasstate)\> |
490
498
 
491
499
  #### Returns
492
500
 
493
- `JSX.Element`
501
+ `Element`
494
502
 
495
503
  ```ts
496
- <Config config={{
504
+ <ConfigProvider config={{
497
505
  common: {
498
506
  blank: '空',
499
507
  },
500
- }} />
508
+ }}>
509
+ <Blank />
510
+ </ConfigProvider>
501
511
  ```
502
512
 
503
513
  ___
@@ -667,6 +677,16 @@ ___
667
677
 
668
678
  ___
669
679
 
680
+ ### useConfigContext
681
+
682
+ ▸ **useConfigContext**(): [`FaasState`](#faasstate)
683
+
684
+ #### Returns
685
+
686
+ [`FaasState`](#faasstate)
687
+
688
+ ___
689
+
670
690
  ### useDrawer
671
691
 
672
692
  ▸ **useDrawer**(`init?`): `Object`
@@ -691,16 +711,6 @@ Hook style drawer.
691
711
 
692
712
  ___
693
713
 
694
- ### useFaasState
695
-
696
- ▸ **useFaasState**(): [[`FaasState`](#faasstate), (`state`: `IHookStateSetAction`<[`FaasState`](#faasstate)\>) => `void`]
697
-
698
- #### Returns
699
-
700
- [[`FaasState`](#faasstate), (`state`: `IHookStateSetAction`<[`FaasState`](#faasstate)\>) => `void`]
701
-
702
- ___
703
-
704
714
  ### useModal
705
715
 
706
716
  ▸ **useModal**(`init?`): `Object`
package/dist/index.d.ts CHANGED
@@ -2,15 +2,14 @@ import * as antd_es_calendar_generateCalendar_js from 'antd/es/calendar/generate
2
2
  import { Dayjs } from 'dayjs';
3
3
  import { CalendarProps as CalendarProps$1, DescriptionsProps, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, DatePickerProps as DatePickerProps$1, TimePickerProps as TimePickerProps$1, SelectProps, FormProps as FormProps$1, ModalProps as ModalProps$1, TableColumnProps, TablePaginationConfig, TableProps as TableProps$1 } from 'antd';
4
4
  export { Drawer, Modal } from 'antd';
5
- import * as react_use_lib_misc_hookState from 'react-use/lib/misc/hookState';
5
+ import * as react from 'react';
6
+ import { LazyExoticComponent, ComponentType } from 'react';
6
7
  import * as antd_es_date_picker_generatePicker_interface from 'antd/es/date-picker/generatePicker/interface';
7
8
  import * as antd_es_date_picker_generatePicker from 'antd/es/date-picker/generatePicker';
8
9
  import { PickerDateProps, PickerTimeProps } from 'antd/es/date-picker/generatePicker';
9
10
  import { FaasDataWrapperProps } from '@faasjs/react';
10
11
  import * as antd_lib_form_Form from 'antd/lib/form/Form';
11
12
  import { RuleObject } from 'rc-field-form/lib/interface';
12
- import * as react from 'react';
13
- import { LazyExoticComponent, ComponentType } from 'react';
14
13
  import { RouteProps } from 'react-router-dom';
15
14
  import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/lib/table/interface';
16
15
 
@@ -59,24 +58,28 @@ declare type FaasState = {
59
58
  suffix: string;
60
59
  };
61
60
  };
62
- declare const useFaasState: () => [FaasState, (state: react_use_lib_misc_hookState.IHookStateSetAction<FaasState>) => void];
61
+ declare const ConfigContext: react.Context<FaasState>;
63
62
  /**
64
- * Config for all @faasjs/ant-design components.
63
+ * Config for @faasjs/ant-design components.
65
64
  * @param props {object}
66
65
  * @param props.config {Partial<FaasState>}
67
66
  * @returns {null}
68
67
  *
69
68
  * ```ts
70
- * <Config config={{
69
+ * <ConfigProvider config={{
71
70
  * common: {
72
71
  * blank: '空',
73
72
  * },
74
- * }} />
73
+ * }}>
74
+ * <Blank />
75
+ * </ConfigProvider>
75
76
  * ```
76
77
  */
77
- declare function Config(props: {
78
+ declare function ConfigProvider({ config, children }: {
78
79
  config: Partial<FaasState>;
80
+ children: React.ReactNode;
79
81
  }): JSX.Element;
82
+ declare function useConfigContext(): FaasState;
80
83
 
81
84
  declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean' | 'date' | 'time' | 'object' | 'object[]';
82
85
  declare type FaasItemTypeValue = {
@@ -389,4 +392,4 @@ declare type TitleProps = {
389
392
  */
390
393
  declare function Title(props: TitleProps): JSX.Element;
391
394
 
392
- export { BaseItemProps, BaseOption, Blank, BlankProps, Calendar, CalendarProps, Config, DatePicker, DatePickerProps, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, FaasState, Form, FormItem, FormItemProps, FormProps, ModalProps, Routes, RoutesProps, Table, TableItemProps, TableProps, TimePicker, TimePickerProps, Title, TitleProps, setDrawerProps, setModalProps, transferOptions, useDrawer, useFaasState, useModal };
395
+ export { BaseItemProps, BaseOption, Blank, BlankProps, Calendar, CalendarProps, ConfigContext, ConfigProvider, DatePicker, DatePickerProps, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, FaasState, Form, FormItem, FormItemProps, FormProps, ModalProps, Routes, RoutesProps, Table, TableItemProps, TableProps, TimePicker, TimePickerProps, Title, TitleProps, setDrawerProps, setModalProps, transferOptions, useConfigContext, useDrawer, useModal };
package/dist/index.js CHANGED
@@ -41,7 +41,8 @@ var src_exports = {};
41
41
  __export(src_exports, {
42
42
  Blank: () => Blank,
43
43
  Calendar: () => Calendar,
44
- Config: () => Config,
44
+ ConfigContext: () => ConfigContext,
45
+ ConfigProvider: () => ConfigProvider,
45
46
  DatePicker: () => DatePicker,
46
47
  Description: () => Description,
47
48
  Drawer: () => import_antd3.Drawer,
@@ -53,8 +54,8 @@ __export(src_exports, {
53
54
  TimePicker: () => TimePicker,
54
55
  Title: () => Title,
55
56
  transferOptions: () => transferOptions,
57
+ useConfigContext: () => useConfigContext,
56
58
  useDrawer: () => useDrawer,
57
- useFaasState: () => useFaasState,
58
59
  useModal: () => useModal
59
60
  });
60
61
  module.exports = __toCommonJS(src_exports);
@@ -68,7 +69,6 @@ var import_lodash = require("lodash");
68
69
 
69
70
  // src/Config.tsx
70
71
  var import_react2 = require("react");
71
- var import_react_use = require("react-use");
72
72
  var isZH = /^zh/i.test(navigator.language);
73
73
  var common = isZH ? {
74
74
  lang: "zh",
@@ -89,7 +89,7 @@ var common = isZH ? {
89
89
  delete: "Delete",
90
90
  required: "is required"
91
91
  };
92
- var useFaasState = (0, import_react_use.createGlobalState)({
92
+ var baseConfig = {
93
93
  lang: "en",
94
94
  common,
95
95
  Blank: { text: common.blank },
@@ -98,18 +98,23 @@ var useFaasState = (0, import_react_use.createGlobalState)({
98
98
  separator: " - ",
99
99
  suffix: ""
100
100
  }
101
- });
102
- function Config(props) {
103
- const [_, setState] = useFaasState();
104
- (0, import_react2.useEffect)(() => {
105
- setState((prev) => __spreadValues(__spreadValues({}, prev), props.config));
106
- }, []);
107
- return null;
101
+ };
102
+ var ConfigContext = (0, import_react2.createContext)(baseConfig);
103
+ function ConfigProvider({
104
+ config,
105
+ children
106
+ }) {
107
+ return /* @__PURE__ */ import_react.default.createElement(ConfigContext.Provider, {
108
+ value: __spreadValues(__spreadValues({}, baseConfig), config)
109
+ }, children);
110
+ }
111
+ function useConfigContext() {
112
+ return (0, import_react2.useContext)(ConfigContext);
108
113
  }
109
114
 
110
115
  // src/Blank.tsx
111
116
  function Blank(options) {
112
- const [config] = useFaasState();
117
+ const config = useConfigContext();
113
118
  return !options || (0, import_lodash.isNil)(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ import_react.default.createElement(import_antd.Typography.Text, {
114
119
  disabled: true
115
120
  }, (options == null ? void 0 : options.text) || config.Blank.text) : options.value;
@@ -335,7 +340,7 @@ function processProps(propsCopy, config) {
335
340
  function FormItem(props) {
336
341
  var _a;
337
342
  const [computedProps, setComputedProps] = (0, import_react7.useState)();
338
- const [config] = useFaasState();
343
+ const config = useConfigContext();
339
344
  (0, import_react7.useEffect)(() => {
340
345
  setComputedProps(processProps(__spreadValues({}, props), config));
341
346
  }, [props]);
@@ -494,7 +499,7 @@ function Form(props) {
494
499
  var _a, _b;
495
500
  const [loading, setLoading] = (0, import_react9.useState)(false);
496
501
  const [computedProps, setComputedProps] = (0, import_react9.useState)();
497
- const [config] = useFaasState();
502
+ const config = useConfigContext();
498
503
  (0, import_react9.useEffect)(() => {
499
504
  var _a2;
500
505
  const propsCopy = __spreadValues({}, props);
@@ -558,7 +563,7 @@ var import_antd7 = require("antd");
558
563
  var import_react11 = require("react");
559
564
  var import_react_router_dom = require("react-router-dom");
560
565
  function NotFound() {
561
- const [config] = useFaasState();
566
+ const config = useConfigContext();
562
567
  return /* @__PURE__ */ import_react.default.createElement(import_antd7.Result, {
563
568
  status: "404",
564
569
  title: config.common.pageNotFound
@@ -620,7 +625,7 @@ function processValue(item, value) {
620
625
  }
621
626
  function Table(props) {
622
627
  const [columns, setColumns] = (0, import_react12.useState)();
623
- const [config] = useFaasState();
628
+ const config = useConfigContext();
624
629
  (0, import_react12.useEffect)(() => {
625
630
  var _a;
626
631
  for (const item of props.items) {
@@ -806,7 +811,7 @@ function Table(props) {
806
811
  // src/Title.tsx
807
812
  var import_react14 = require("react");
808
813
  function Title(props) {
809
- const [config] = useFaasState();
814
+ const config = useConfigContext();
810
815
  (0, import_react14.useEffect)(() => {
811
816
  const title = Array.isArray(props.title) ? props.title : [props.title];
812
817
  document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
@@ -827,7 +832,8 @@ function Title(props) {
827
832
  0 && (module.exports = {
828
833
  Blank,
829
834
  Calendar,
830
- Config,
835
+ ConfigContext,
836
+ ConfigProvider,
831
837
  DatePicker,
832
838
  Description,
833
839
  Drawer,
@@ -839,7 +845,7 @@ function Title(props) {
839
845
  TimePicker,
840
846
  Title,
841
847
  transferOptions,
848
+ useConfigContext,
842
849
  useDrawer,
843
- useFaasState,
844
850
  useModal
845
851
  });
package/dist/index.mjs CHANGED
@@ -26,8 +26,7 @@ import { Typography } from "antd";
26
26
  import { isNil } from "lodash";
27
27
 
28
28
  // src/Config.tsx
29
- import { useEffect } from "react";
30
- import { createGlobalState } from "react-use";
29
+ import { createContext, useContext } from "react";
31
30
  var isZH = /^zh/i.test(navigator.language);
32
31
  var common = isZH ? {
33
32
  lang: "zh",
@@ -48,7 +47,7 @@ var common = isZH ? {
48
47
  delete: "Delete",
49
48
  required: "is required"
50
49
  };
51
- var useFaasState = createGlobalState({
50
+ var baseConfig = {
52
51
  lang: "en",
53
52
  common,
54
53
  Blank: { text: common.blank },
@@ -57,18 +56,23 @@ var useFaasState = createGlobalState({
57
56
  separator: " - ",
58
57
  suffix: ""
59
58
  }
60
- });
61
- function Config(props) {
62
- const [_, setState] = useFaasState();
63
- useEffect(() => {
64
- setState((prev) => __spreadValues(__spreadValues({}, prev), props.config));
65
- }, []);
66
- return null;
59
+ };
60
+ var ConfigContext = createContext(baseConfig);
61
+ function ConfigProvider({
62
+ config,
63
+ children
64
+ }) {
65
+ return /* @__PURE__ */ React.createElement(ConfigContext.Provider, {
66
+ value: __spreadValues(__spreadValues({}, baseConfig), config)
67
+ }, children);
68
+ }
69
+ function useConfigContext() {
70
+ return useContext(ConfigContext);
67
71
  }
68
72
 
69
73
  // src/Blank.tsx
70
74
  function Blank(options) {
71
- const [config] = useFaasState();
75
+ const config = useConfigContext();
72
76
  return !options || isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ React.createElement(Typography.Text, {
73
77
  disabled: true
74
78
  }, (options == null ? void 0 : options.text) || config.Blank.text) : options.value;
@@ -106,14 +110,14 @@ import {
106
110
  import { upperFirst as upperFirst2 } from "lodash";
107
111
  import {
108
112
  cloneElement,
109
- useEffect as useEffect2,
113
+ useEffect,
110
114
  useState
111
115
  } from "react";
112
116
  import dayjs from "dayjs";
113
117
  import { FaasDataWrapper } from "@faasjs/react";
114
118
  function DescriptionItemContent(props) {
115
119
  const [computedProps, setComputedProps] = useState();
116
- useEffect2(() => {
120
+ useEffect(() => {
117
121
  var _a, _b;
118
122
  const propsCopy = __spreadValues({}, props);
119
123
  if (!propsCopy.item.title)
@@ -235,7 +239,7 @@ import {
235
239
  Button as Button2,
236
240
  Form as AntdForm2
237
241
  } from "antd";
238
- import { useEffect as useEffect4, useState as useState4 } from "react";
242
+ import { useEffect as useEffect3, useState as useState4 } from "react";
239
243
 
240
244
  // src/FormItem.tsx
241
245
  import {
@@ -249,7 +253,7 @@ import {
249
253
  Select
250
254
  } from "antd";
251
255
  import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
252
- import { useEffect as useEffect3, useState as useState3 } from "react";
256
+ import { useEffect as useEffect2, useState as useState3 } from "react";
253
257
  import { upperFirst as upperFirst3 } from "lodash";
254
258
 
255
259
  // src/TimePicker.tsx
@@ -313,8 +317,8 @@ function processProps(propsCopy, config) {
313
317
  function FormItem(props) {
314
318
  var _a;
315
319
  const [computedProps, setComputedProps] = useState3();
316
- const [config] = useFaasState();
317
- useEffect3(() => {
320
+ const config = useConfigContext();
321
+ useEffect2(() => {
318
322
  setComputedProps(processProps(__spreadValues({}, props), config));
319
323
  }, [props]);
320
324
  if (!computedProps)
@@ -472,8 +476,8 @@ function Form(props) {
472
476
  var _a, _b;
473
477
  const [loading, setLoading] = useState4(false);
474
478
  const [computedProps, setComputedProps] = useState4();
475
- const [config] = useFaasState();
476
- useEffect4(() => {
479
+ const config = useConfigContext();
480
+ useEffect3(() => {
477
481
  var _a2;
478
482
  const propsCopy = __spreadValues({}, props);
479
483
  if (propsCopy.onFinish) {
@@ -541,7 +545,7 @@ import {
541
545
  Route
542
546
  } from "react-router-dom";
543
547
  function NotFound() {
544
- const [config] = useFaasState();
548
+ const config = useConfigContext();
545
549
  return /* @__PURE__ */ React.createElement(Result, {
546
550
  status: "404",
547
551
  title: config.common.pageNotFound
@@ -568,7 +572,7 @@ function Routes(props) {
568
572
  // src/Table.tsx
569
573
  import {
570
574
  useState as useState6,
571
- useEffect as useEffect5,
575
+ useEffect as useEffect4,
572
576
  cloneElement as cloneElement2
573
577
  } from "react";
574
578
  import {
@@ -611,8 +615,8 @@ function processValue(item, value) {
611
615
  }
612
616
  function Table(props) {
613
617
  const [columns, setColumns] = useState6();
614
- const [config] = useFaasState();
615
- useEffect5(() => {
618
+ const config = useConfigContext();
619
+ useEffect4(() => {
616
620
  var _a;
617
621
  for (const item of props.items) {
618
622
  if (!item.key)
@@ -795,10 +799,10 @@ function Table(props) {
795
799
  }
796
800
 
797
801
  // src/Title.tsx
798
- import { useEffect as useEffect6, cloneElement as cloneElement3 } from "react";
802
+ import { useEffect as useEffect5, cloneElement as cloneElement3 } from "react";
799
803
  function Title(props) {
800
- const [config] = useFaasState();
801
- useEffect6(() => {
804
+ const config = useConfigContext();
805
+ useEffect5(() => {
802
806
  const title = Array.isArray(props.title) ? props.title : [props.title];
803
807
  document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
804
808
  }, []);
@@ -817,7 +821,8 @@ function Title(props) {
817
821
  export {
818
822
  Blank,
819
823
  Calendar,
820
- Config,
824
+ ConfigContext,
825
+ ConfigProvider,
821
826
  DatePicker,
822
827
  Description,
823
828
  Drawer,
@@ -829,7 +834,7 @@ export {
829
834
  TimePicker,
830
835
  Title,
831
836
  transferOptions,
837
+ useConfigContext,
832
838
  useDrawer,
833
- useFaasState,
834
839
  useModal
835
840
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.387",
3
+ "version": "0.0.2-beta.390",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -26,10 +26,9 @@
26
26
  "@ant-design/icons": "*",
27
27
  "antd": "*",
28
28
  "lodash": "*",
29
- "react": "*",
30
- "react-dom": "*",
31
- "@faasjs/react": "^0.0.2-beta.387",
32
- "react-use": "*",
29
+ "react": "^17.0.0",
30
+ "react-dom": "^17.0.0",
31
+ "@faasjs/react": "^0.0.2-beta.390",
33
32
  "react-router-dom": "*",
34
33
  "dayjs": "*"
35
34
  },