@faasjs/ant-design 0.0.2-beta.350 → 0.0.2-beta.354

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/dist/index.d.ts CHANGED
@@ -1,12 +1,40 @@
1
+ import * as react_use_lib_misc_hookState from 'react-use/lib/misc/hookState';
1
2
  import { DescriptionsProps, DrawerProps as DrawerProps$1, FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, FormProps as FormProps$1, TableColumnProps, TableProps as TableProps$1 } from 'antd';
2
3
  export { Drawer } from 'antd';
4
+ import { Dispatch, SetStateAction, LazyExoticComponent, ComponentType } from 'react';
3
5
  import * as antd_lib_form_Form from 'antd/lib/form/Form';
4
6
  import { RuleObject } from 'rc-field-form/lib/interface';
7
+ import { RouteProps } from 'react-router-dom';
5
8
 
6
- declare function Blank(options?: {
9
+ declare type BlankProps = {
7
10
  value?: any;
8
11
  text?: string;
9
- }): any;
12
+ };
13
+ declare function Blank(options?: BlankProps): any;
14
+
15
+ declare type FaasState = {
16
+ common: {
17
+ blank: string;
18
+ all: string;
19
+ submit: string;
20
+ };
21
+ Blank: {
22
+ text: string;
23
+ };
24
+ Form: {
25
+ submit: {
26
+ text: string;
27
+ };
28
+ };
29
+ Title: {
30
+ separator: string;
31
+ suffix: string;
32
+ };
33
+ };
34
+ declare const useFaasState: () => [FaasState, (state: react_use_lib_misc_hookState.IHookStateSetAction<FaasState>) => void];
35
+ declare function Config(props: {
36
+ config: Partial<FaasState>;
37
+ }): JSX.Element;
10
38
 
11
39
  declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean';
12
40
  declare type FaasItemTypeValue = {
@@ -37,6 +65,22 @@ declare function transferOptions(options: BaseOption[]): {
37
65
  value?: string | number;
38
66
  }[];
39
67
 
68
+ declare type FaasDataProps<T = any> = {
69
+ action: string;
70
+ params?: Record<string, any>;
71
+ data?: T;
72
+ setData?: Dispatch<SetStateAction<T>>;
73
+ };
74
+ declare type FaasDataRender<T = any> = (args: {
75
+ data: T;
76
+ }) => JSX.Element;
77
+ declare type FaasDataWrapperProps<T = any> = {
78
+ dataSource?: T;
79
+ faasData?: FaasDataProps<T>;
80
+ render?: FaasDataRender<T>;
81
+ fallback?: JSX.Element;
82
+ };
83
+
40
84
  declare type ExtendDescriptionTypeProps = {
41
85
  children?: JSX.Element | null;
42
86
  render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
@@ -48,16 +92,11 @@ declare type DescriptionItemProps<T = any> = {
48
92
  } & FaasItemProps;
49
93
  declare type DescriptionProps<T = any, ExtendItemProps = any> = {
50
94
  items: (DescriptionItemProps | ExtendItemProps)[];
51
- dataSource?: T;
52
- faasData?: {
53
- action: string;
54
- params?: Record<string, any>;
55
- };
56
95
  extendTypes?: {
57
96
  [key: string]: ExtendDescriptionTypeProps;
58
97
  };
59
- } & DescriptionsProps;
60
- declare function Description(props: DescriptionProps): JSX.Element;
98
+ } & FaasDataWrapperProps<T> & DescriptionsProps;
99
+ declare function Description<T = any>(props: DescriptionProps<T>): JSX.Element;
61
100
 
62
101
  declare type DrawerProps = DrawerProps$1 & {
63
102
  children?: JSX.Element | JSX.Element[];
@@ -102,6 +141,7 @@ declare type ExtendFormTypeProps = {
102
141
  declare type ExtendFormItemProps = BaseItemProps & FormItemProps$1;
103
142
  declare type FormItemProps<T = any> = {
104
143
  children?: JSX.Element | null;
144
+ render?: () => JSX.Element | null;
105
145
  rules?: RuleObject[];
106
146
  label?: string | false;
107
147
  extendTypes?: {
@@ -127,25 +167,37 @@ declare namespace Form {
127
167
  var Item: typeof FormItem;
128
168
  }
129
169
 
170
+ declare type RoutesProps = {
171
+ routes: (RouteProps & {
172
+ page?: LazyExoticComponent<ComponentType<any>>;
173
+ })[];
174
+ notFound?: JSX.Element;
175
+ };
176
+ declare function Routes(props: RoutesProps): JSX.Element;
177
+
130
178
  declare type TableItemProps<T = any> = {
131
179
  /** @deprecated use render */
132
180
  children?: JSX.Element | null;
133
- } & FaasItemProps & TableColumnProps<T>;
181
+ } & FaasItemProps & Omit<TableColumnProps<T>, 'children'>;
134
182
  declare type ExtendTableTypeProps = {
135
183
  children?: JSX.Element | null;
136
- render?: (value: any, values: any) => JSX.Element | string | number | boolean | null;
184
+ render?: (value: any, values: any, index: number) => JSX.Element | string | number | boolean | null;
137
185
  };
138
- declare type ExtendTableItemProps<T = any> = BaseItemProps & TableColumnProps<T>;
186
+ declare type ExtendTableItemProps<T = any> = BaseItemProps & Omit<TableColumnProps<T>, 'children'>;
139
187
  declare type TableProps<T = any, ExtendTypes = any> = {
140
188
  items: (TableItemProps | (ExtendTypes & ExtendTableItemProps))[];
141
189
  extendTypes?: {
142
190
  [key: string]: ExtendTableTypeProps;
143
191
  };
144
- faasData?: {
145
- action: string;
146
- params?: Record<string, any>;
147
- };
148
- } & TableProps$1<T>;
192
+ } & FaasDataWrapperProps<T> & TableProps$1<T>;
149
193
  declare function Table<T = any, ExtendTypes = any>(props: TableProps<T, ExtendTypes>): JSX.Element;
150
194
 
151
- export { BaseItemProps, BaseOption, Blank, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Table, TableItemProps, TableProps, transferOptions, useDrawer };
195
+ declare type TitleProps = {
196
+ title: string | string[];
197
+ /** ` - ` as default */
198
+ separator?: string;
199
+ suffix?: string;
200
+ };
201
+ declare function Title(props: TitleProps): JSX.Element;
202
+
203
+ export { BaseItemProps, BaseOption, Blank, BlankProps, Config, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, FaasItemProps, FaasItemType, FaasItemTypeValue, FaasState, Form, FormItem, FormItemProps, FormProps, Routes, RoutesProps, Table, TableItemProps, TableProps, Title, TitleProps, transferOptions, useDrawer, useFaasState };
package/dist/index.js CHANGED
@@ -47,13 +47,17 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
47
47
  var src_exports = {};
48
48
  __export(src_exports, {
49
49
  Blank: () => Blank,
50
+ Config: () => Config,
50
51
  Description: () => Description,
51
52
  Drawer: () => import_antd3.Drawer,
52
53
  Form: () => Form,
53
54
  FormItem: () => FormItem,
55
+ Routes: () => Routes,
54
56
  Table: () => Table,
57
+ Title: () => Title,
55
58
  transferOptions: () => transferOptions,
56
- useDrawer: () => useDrawer
59
+ useDrawer: () => useDrawer,
60
+ useFaasState: () => useFaasState
57
61
  });
58
62
 
59
63
  // react-shim.js
@@ -62,12 +66,39 @@ var import_react = __toESM(require("react"));
62
66
  // src/Blank.tsx
63
67
  var import_antd = require("antd");
64
68
  var import_lodash = require("lodash");
65
- var _a;
66
- var text = ((_a = navigator.language) == null ? void 0 : _a.includes("CN")) ? "\u7A7A" : "Empty";
69
+
70
+ // src/Config.tsx
71
+ var import_react2 = require("react");
72
+ var import_react_use = require("react-use");
73
+ var _a, _b, _c;
74
+ var common = {
75
+ blank: ((_a = navigator.language) == null ? void 0 : _a.includes("CN")) ? "\u7A7A" : "Empty",
76
+ all: ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u5168\u90E8" : "All",
77
+ submit: ((_c = navigator.language) == null ? void 0 : _c.includes("CN")) ? "\u63D0\u4EA4" : "Submit"
78
+ };
79
+ var useFaasState = (0, import_react_use.createGlobalState)({
80
+ common,
81
+ Blank: { text: common.blank },
82
+ Form: { submit: { text: common.submit } },
83
+ Title: {
84
+ separator: " - ",
85
+ suffix: ""
86
+ }
87
+ });
88
+ function Config(props) {
89
+ const [_, setState] = useFaasState();
90
+ (0, import_react2.useEffect)(() => {
91
+ setState((prev) => __spreadValues(__spreadValues({}, prev), props.config));
92
+ }, []);
93
+ return null;
94
+ }
95
+
96
+ // src/Blank.tsx
67
97
  function Blank(options) {
98
+ const [config] = useFaasState();
68
99
  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, {
69
100
  disabled: true
70
- }, (options == null ? void 0 : options.text) || text) : options.value;
101
+ }, (options == null ? void 0 : options.text) || config.Blank.text) : options.value;
71
102
  }
72
103
 
73
104
  // src/data.ts
@@ -85,22 +116,22 @@ function transferOptions(options) {
85
116
  var import_icons = require("@ant-design/icons");
86
117
  var import_antd2 = require("antd");
87
118
  var import_lodash3 = require("lodash");
88
- var import_react4 = require("react");
119
+ var import_react5 = require("react");
89
120
 
90
- // src/FaasWrapper.tsx
91
- var import_react2 = require("react");
92
- var import_react3 = require("@faasjs/react");
121
+ // src/FaasDataWrapper.tsx
122
+ var import_react3 = require("react");
123
+ var import_react4 = require("@faasjs/react");
93
124
  function FaasDataWrapper({
94
125
  dataSource,
95
126
  faasData,
96
127
  render,
97
128
  fallback
98
129
  }) {
99
- const [data, setData] = (0, import_react2.useState)();
100
- (0, import_react2.useEffect)(() => {
130
+ const [data, setData] = (0, import_react3.useState)();
131
+ (0, import_react3.useEffect)(() => {
101
132
  if (!faasData)
102
133
  return;
103
- (0, import_react3.getClient)().faas(faasData.action, faasData.params).then((res) => {
134
+ (0, import_react4.getClient)().faas(faasData.action, faasData.params).then((res) => {
104
135
  if (faasData.setData)
105
136
  faasData.setData(res.data);
106
137
  else
@@ -116,9 +147,9 @@ function FaasDataWrapper({
116
147
 
117
148
  // src/Description.tsx
118
149
  function DescriptionItemContent(props) {
119
- const [computedProps, setComputedProps] = (0, import_react4.useState)();
120
- (0, import_react4.useEffect)(() => {
121
- var _a2, _b;
150
+ const [computedProps, setComputedProps] = (0, import_react5.useState)();
151
+ (0, import_react5.useEffect)(() => {
152
+ var _a2, _b2;
122
153
  const propsCopy = __spreadValues({}, props);
123
154
  if (!propsCopy.item.title)
124
155
  propsCopy.item.title = (0, import_lodash3.upperFirst)(propsCopy.item.id);
@@ -134,7 +165,7 @@ function DescriptionItemContent(props) {
134
165
  return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
135
166
  });
136
167
  else
137
- propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
168
+ propsCopy.value = ((_b2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b2.label) || props.value;
138
169
  }
139
170
  setComputedProps(propsCopy);
140
171
  }, [props]);
@@ -142,7 +173,7 @@ function DescriptionItemContent(props) {
142
173
  return null;
143
174
  if (computedProps.extendTypes && computedProps.extendTypes[computedProps.item.type])
144
175
  if (computedProps.extendTypes[computedProps.item.type].children)
145
- return (0, import_react4.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
176
+ return (0, import_react5.cloneElement)(computedProps.extendTypes[computedProps.item.type].children, {
146
177
  value: computedProps.value,
147
178
  values: computedProps.values
148
179
  });
@@ -151,7 +182,7 @@ function DescriptionItemContent(props) {
151
182
  else
152
183
  throw Error(computedProps.item.type + " requires children or render");
153
184
  if (computedProps.item.children)
154
- return (0, import_react4.cloneElement)(computedProps.item.children, { value: computedProps.value });
185
+ return (0, import_react5.cloneElement)(computedProps.item.children, { value: computedProps.value });
155
186
  if (computedProps.item.render)
156
187
  return computedProps.item.render(computedProps.value, computedProps.values);
157
188
  if (typeof computedProps.value === "undefined" || computedProps.value === null)
@@ -180,9 +211,7 @@ function DescriptionItemContent(props) {
180
211
  }
181
212
  }
182
213
  function Description(props) {
183
- return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, {
184
- dataSource: props.dataSource,
185
- faasData: props.faasData,
214
+ return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, __spreadProps(__spreadValues({}, props), {
186
215
  render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(import_antd2.Descriptions.Item, {
187
216
  key: item.id,
188
217
  label: item.title || (0, import_lodash3.upperFirst)(item.id)
@@ -192,14 +221,14 @@ function Description(props) {
192
221
  values: data,
193
222
  extendTypes: props.extendTypes
194
223
  }))))
195
- });
224
+ }));
196
225
  }
197
226
 
198
227
  // src/Drawer.tsx
199
228
  var import_antd3 = require("antd");
200
- var import_react5 = require("react");
229
+ var import_react6 = require("react");
201
230
  function useDrawer(init) {
202
- const [props, setProps] = (0, import_react5.useState)(__spreadValues({
231
+ const [props, setProps] = (0, import_react6.useState)(__spreadValues({
203
232
  visible: false,
204
233
  onClose: () => setProps((prev) => __spreadProps(__spreadValues({}, prev), {
205
234
  visible: false
@@ -216,16 +245,16 @@ function useDrawer(init) {
216
245
 
217
246
  // src/Form.tsx
218
247
  var import_antd5 = require("antd");
219
- var import_react7 = require("react");
248
+ var import_react8 = require("react");
220
249
 
221
250
  // src/FormItem.tsx
222
251
  var import_antd4 = require("antd");
223
252
  var import_icons2 = require("@ant-design/icons");
224
- var import_react6 = require("react");
253
+ var import_react7 = require("react");
225
254
  var import_lodash4 = require("lodash");
226
255
  function FormItem(props) {
227
- const [computedProps, setComputedProps] = (0, import_react6.useState)();
228
- (0, import_react6.useEffect)(() => {
256
+ const [computedProps, setComputedProps] = (0, import_react7.useState)();
257
+ (0, import_react7.useEffect)(() => {
229
258
  const propsCopy = __spreadValues({}, props);
230
259
  if (!propsCopy.title)
231
260
  propsCopy.title = (0, import_lodash4.upperFirst)(propsCopy.id);
@@ -269,6 +298,8 @@ function FormItem(props) {
269
298
  return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
270
299
  if (computedProps.children)
271
300
  return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.children);
301
+ if (computedProps.render)
302
+ return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.render());
272
303
  switch (computedProps.type) {
273
304
  case "string":
274
305
  return /* @__PURE__ */ import_react.default.createElement(import_antd4.Form.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ import_react.default.createElement(import_antd4.Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ import_react.default.createElement(import_antd4.Input, __spreadValues({}, computedProps.input)));
@@ -362,10 +393,11 @@ function FormItem(props) {
362
393
 
363
394
  // src/Form.tsx
364
395
  function Form(props) {
365
- var _a2, _b;
366
- const [loading, setLoading] = (0, import_react7.useState)(false);
367
- const [computedProps, setComputedProps] = (0, import_react7.useState)();
368
- (0, import_react7.useEffect)(() => {
396
+ var _a2, _b2;
397
+ const [loading, setLoading] = (0, import_react8.useState)(false);
398
+ const [computedProps, setComputedProps] = (0, import_react8.useState)();
399
+ const [config] = useFaasState();
400
+ (0, import_react8.useEffect)(() => {
369
401
  const propsCopy = __spreadValues({}, props);
370
402
  if (propsCopy.onFinish) {
371
403
  propsCopy.onFinish = async (values) => {
@@ -380,6 +412,8 @@ function Form(props) {
380
412
  }
381
413
  setComputedProps(props);
382
414
  }, []);
415
+ if (!computedProps)
416
+ return null;
383
417
  return /* @__PURE__ */ import_react.default.createElement(import_antd5.Form, __spreadValues({}, computedProps), (_a2 = props.items) == null ? void 0 : _a2.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadProps(__spreadValues({
384
418
  key: item.id
385
419
  }, item), {
@@ -388,14 +422,41 @@ function Form(props) {
388
422
  htmlType: "submit",
389
423
  type: "primary",
390
424
  loading
391
- }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
425
+ }, ((_b2 = props.submit) == null ? void 0 : _b2.text) || config.Form.submit.text));
392
426
  }
393
427
  Form.useForm = import_antd5.Form.useForm;
394
428
  Form.Item = FormItem;
395
429
 
396
- // src/Table.tsx
397
- var import_react8 = require("react");
430
+ // src/Routers.tsx
398
431
  var import_antd6 = require("antd");
432
+ var import_react9 = require("react");
433
+ var import_react_router_dom = require("react-router-dom");
434
+ function NoMatch() {
435
+ return /* @__PURE__ */ import_react.default.createElement(import_antd6.Result, {
436
+ status: "404",
437
+ title: "404",
438
+ subTitle: "Page not found"
439
+ });
440
+ }
441
+ function Routes(props) {
442
+ return /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Routes, null, props.routes.map((r) => /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, __spreadProps(__spreadValues({
443
+ key: r.path
444
+ }, r), {
445
+ element: r.element || /* @__PURE__ */ import_react.default.createElement(import_react9.Suspense, {
446
+ fallback: /* @__PURE__ */ import_react.default.createElement(import_antd6.Skeleton, {
447
+ active: true
448
+ })
449
+ }, /* @__PURE__ */ import_react.default.createElement(r.page, null))
450
+ }))), /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Route, {
451
+ key: "*",
452
+ path: "*",
453
+ element: props.notFound || /* @__PURE__ */ import_react.default.createElement(NoMatch, null)
454
+ }));
455
+ }
456
+
457
+ // src/Table.tsx
458
+ var import_react10 = require("react");
459
+ var import_antd7 = require("antd");
399
460
  var import_icons3 = require("@ant-design/icons");
400
461
  var import_lodash5 = require("lodash");
401
462
  function processValue(item, value) {
@@ -412,8 +473,9 @@ function processValue(item, value) {
412
473
  return value;
413
474
  }
414
475
  function Table(props) {
415
- const [columns, setColumns] = (0, import_react8.useState)();
416
- (0, import_react8.useEffect)(() => {
476
+ const [columns, setColumns] = (0, import_react10.useState)();
477
+ const [config] = useFaasState();
478
+ (0, import_react10.useEffect)(() => {
417
479
  var _a2;
418
480
  for (const item of props.items) {
419
481
  if (!item.key)
@@ -437,7 +499,7 @@ function Table(props) {
437
499
  delete item.children;
438
500
  if (props.extendTypes && props.extendTypes[item.type]) {
439
501
  if (props.extendTypes[item.type].children) {
440
- item.render = (value, values) => (0, import_react8.cloneElement)(props.extendTypes[item.type].children, {
502
+ item.render = (value, values) => (0, import_react10.cloneElement)(props.extendTypes[item.type].children, {
441
503
  value,
442
504
  values
443
505
  });
@@ -482,34 +544,31 @@ function Table(props) {
482
544
  setSelectedKeys,
483
545
  selectedKeys,
484
546
  confirm
485
- }) => {
486
- var _a3, _b;
487
- return /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Group, {
488
- style: { padding: 8 },
489
- buttonStyle: "solid",
490
- value: selectedKeys[0],
491
- onChange: (e) => {
492
- setSelectedKeys(e.target.value ? [e.target.value] : []);
493
- confirm();
494
- }
495
- }, /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, null, ((_a3 = navigator.language) == null ? void 0 : _a3.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, {
496
- value: "true"
497
- }, /* @__PURE__ */ import_react.default.createElement(import_icons3.CheckOutlined, {
498
- style: {
499
- color: "#52c41a",
500
- verticalAlign: "middle"
501
- }
502
- })), /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, {
503
- value: "false"
504
- }, /* @__PURE__ */ import_react.default.createElement(import_icons3.CloseOutlined, {
505
- style: {
506
- verticalAlign: "middle",
507
- color: "#ff4d4f"
508
- }
509
- })), /* @__PURE__ */ import_react.default.createElement(import_antd6.Radio.Button, {
510
- value: "empty"
511
- }, ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u7A7A" : "Empty"));
512
- };
547
+ }) => /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Group, {
548
+ style: { padding: 8 },
549
+ buttonStyle: "solid",
550
+ value: selectedKeys[0],
551
+ onChange: (e) => {
552
+ setSelectedKeys(e.target.value ? [e.target.value] : []);
553
+ confirm();
554
+ }
555
+ }, /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, null, config.common.all), /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, {
556
+ value: "true"
557
+ }, /* @__PURE__ */ import_react.default.createElement(import_icons3.CheckOutlined, {
558
+ style: {
559
+ color: "#52c41a",
560
+ verticalAlign: "middle"
561
+ }
562
+ })), /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, {
563
+ value: "false"
564
+ }, /* @__PURE__ */ import_react.default.createElement(import_icons3.CloseOutlined, {
565
+ style: {
566
+ verticalAlign: "middle",
567
+ color: "#ff4d4f"
568
+ }
569
+ })), /* @__PURE__ */ import_react.default.createElement(import_antd7.Radio.Button, {
570
+ value: "empty"
571
+ }, config.common.blank));
513
572
  if (!item.onFilter)
514
573
  item.onFilter = (value, row) => {
515
574
  switch (value) {
@@ -535,25 +594,38 @@ function Table(props) {
535
594
  }, [props.items]);
536
595
  if (!columns)
537
596
  return null;
538
- return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, {
539
- dataSource: props.dataSource,
540
- faasData: props.faasData,
541
- render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd6.Table, __spreadProps(__spreadValues({}, props), {
597
+ return /* @__PURE__ */ import_react.default.createElement(FaasDataWrapper, __spreadValues({
598
+ render: ({ data }) => /* @__PURE__ */ import_react.default.createElement(import_antd7.Table, __spreadProps(__spreadValues({}, props), {
542
599
  rowKey: props.rowKey || "id",
543
600
  columns,
544
601
  dataSource: data
545
602
  }))
546
- });
603
+ }, props));
604
+ }
605
+
606
+ // src/Title.tsx
607
+ var import_react11 = require("react");
608
+ function Title(props) {
609
+ const [config] = useFaasState();
610
+ (0, import_react11.useEffect)(() => {
611
+ const title = Array.isArray(props.title) ? props.title : [props.title];
612
+ document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
613
+ }, []);
614
+ return null;
547
615
  }
548
616
  module.exports = __toCommonJS(src_exports);
549
617
  // Annotate the CommonJS export names for ESM import in node:
550
618
  0 && (module.exports = {
551
619
  Blank,
620
+ Config,
552
621
  Description,
553
622
  Drawer,
554
623
  Form,
555
624
  FormItem,
625
+ Routes,
556
626
  Table,
627
+ Title,
557
628
  transferOptions,
558
- useDrawer
629
+ useDrawer,
630
+ useFaasState
559
631
  });
package/dist/index.mjs CHANGED
@@ -24,12 +24,39 @@ import React from "react";
24
24
  // src/Blank.tsx
25
25
  import { Typography } from "antd";
26
26
  import { isNil } from "lodash";
27
- var _a;
28
- var text = ((_a = navigator.language) == null ? void 0 : _a.includes("CN")) ? "\u7A7A" : "Empty";
27
+
28
+ // src/Config.tsx
29
+ import { useEffect } from "react";
30
+ import { createGlobalState } from "react-use";
31
+ var _a, _b, _c;
32
+ var common = {
33
+ blank: ((_a = navigator.language) == null ? void 0 : _a.includes("CN")) ? "\u7A7A" : "Empty",
34
+ all: ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u5168\u90E8" : "All",
35
+ submit: ((_c = navigator.language) == null ? void 0 : _c.includes("CN")) ? "\u63D0\u4EA4" : "Submit"
36
+ };
37
+ var useFaasState = createGlobalState({
38
+ common,
39
+ Blank: { text: common.blank },
40
+ Form: { submit: { text: common.submit } },
41
+ Title: {
42
+ separator: " - ",
43
+ suffix: ""
44
+ }
45
+ });
46
+ function Config(props) {
47
+ const [_, setState] = useFaasState();
48
+ useEffect(() => {
49
+ setState((prev) => __spreadValues(__spreadValues({}, prev), props.config));
50
+ }, []);
51
+ return null;
52
+ }
53
+
54
+ // src/Blank.tsx
29
55
  function Blank(options) {
56
+ const [config] = useFaasState();
30
57
  return !options || isNil(options.value) || Array.isArray(options.value) && !options.value.length || options.value === "" ? /* @__PURE__ */ React.createElement(Typography.Text, {
31
58
  disabled: true
32
- }, (options == null ? void 0 : options.text) || text) : options.value;
59
+ }, (options == null ? void 0 : options.text) || config.Blank.text) : options.value;
33
60
  }
34
61
 
35
62
  // src/data.ts
@@ -49,13 +76,13 @@ import { Descriptions } from "antd";
49
76
  import { upperFirst as upperFirst2 } from "lodash";
50
77
  import {
51
78
  cloneElement,
52
- useEffect as useEffect2,
79
+ useEffect as useEffect3,
53
80
  useState as useState2
54
81
  } from "react";
55
82
 
56
- // src/FaasWrapper.tsx
83
+ // src/FaasDataWrapper.tsx
57
84
  import {
58
- useEffect,
85
+ useEffect as useEffect2,
59
86
  useState
60
87
  } from "react";
61
88
  import { getClient } from "@faasjs/react";
@@ -66,7 +93,7 @@ function FaasDataWrapper({
66
93
  fallback
67
94
  }) {
68
95
  const [data, setData] = useState();
69
- useEffect(() => {
96
+ useEffect2(() => {
70
97
  if (!faasData)
71
98
  return;
72
99
  getClient().faas(faasData.action, faasData.params).then((res) => {
@@ -86,8 +113,8 @@ function FaasDataWrapper({
86
113
  // src/Description.tsx
87
114
  function DescriptionItemContent(props) {
88
115
  const [computedProps, setComputedProps] = useState2();
89
- useEffect2(() => {
90
- var _a2, _b;
116
+ useEffect3(() => {
117
+ var _a2, _b2;
91
118
  const propsCopy = __spreadValues({}, props);
92
119
  if (!propsCopy.item.title)
93
120
  propsCopy.item.title = upperFirst2(propsCopy.item.id);
@@ -103,7 +130,7 @@ function DescriptionItemContent(props) {
103
130
  return ((_a3 = propsCopy.item.options.find((option) => option.value === v)) == null ? void 0 : _a3.label) || v;
104
131
  });
105
132
  else
106
- propsCopy.value = ((_b = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b.label) || props.value;
133
+ propsCopy.value = ((_b2 = props.item.options.find((option) => option.value === props.value)) == null ? void 0 : _b2.label) || props.value;
107
134
  }
108
135
  setComputedProps(propsCopy);
109
136
  }, [props]);
@@ -149,9 +176,7 @@ function DescriptionItemContent(props) {
149
176
  }
150
177
  }
151
178
  function Description(props) {
152
- return /* @__PURE__ */ React.createElement(FaasDataWrapper, {
153
- dataSource: props.dataSource,
154
- faasData: props.faasData,
179
+ return /* @__PURE__ */ React.createElement(FaasDataWrapper, __spreadProps(__spreadValues({}, props), {
155
180
  render: ({ data }) => /* @__PURE__ */ React.createElement(Descriptions, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(Descriptions.Item, {
156
181
  key: item.id,
157
182
  label: item.title || upperFirst2(item.id)
@@ -161,7 +186,7 @@ function Description(props) {
161
186
  values: data,
162
187
  extendTypes: props.extendTypes
163
188
  }))))
164
- });
189
+ }));
165
190
  }
166
191
 
167
192
  // src/Drawer.tsx
@@ -188,7 +213,7 @@ import {
188
213
  Button as Button2,
189
214
  Form as AntdForm2
190
215
  } from "antd";
191
- import { useEffect as useEffect4, useState as useState5 } from "react";
216
+ import { useEffect as useEffect5, useState as useState5 } from "react";
192
217
 
193
218
  // src/FormItem.tsx
194
219
  import {
@@ -202,11 +227,11 @@ import {
202
227
  Select
203
228
  } from "antd";
204
229
  import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
205
- import { useEffect as useEffect3, useState as useState4 } from "react";
230
+ import { useEffect as useEffect4, useState as useState4 } from "react";
206
231
  import { upperFirst as upperFirst3 } from "lodash";
207
232
  function FormItem(props) {
208
233
  const [computedProps, setComputedProps] = useState4();
209
- useEffect3(() => {
234
+ useEffect4(() => {
210
235
  const propsCopy = __spreadValues({}, props);
211
236
  if (!propsCopy.title)
212
237
  propsCopy.title = upperFirst3(propsCopy.id);
@@ -250,6 +275,8 @@ function FormItem(props) {
250
275
  return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.extendTypes[computedProps.type].children);
251
276
  if (computedProps.children)
252
277
  return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.children);
278
+ if (computedProps.render)
279
+ return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.render());
253
280
  switch (computedProps.type) {
254
281
  case "string":
255
282
  return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ React.createElement(Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ React.createElement(Input, __spreadValues({}, computedProps.input)));
@@ -343,10 +370,11 @@ function FormItem(props) {
343
370
 
344
371
  // src/Form.tsx
345
372
  function Form(props) {
346
- var _a2, _b;
373
+ var _a2, _b2;
347
374
  const [loading, setLoading] = useState5(false);
348
375
  const [computedProps, setComputedProps] = useState5();
349
- useEffect4(() => {
376
+ const [config] = useFaasState();
377
+ useEffect5(() => {
350
378
  const propsCopy = __spreadValues({}, props);
351
379
  if (propsCopy.onFinish) {
352
380
  propsCopy.onFinish = async (values) => {
@@ -361,6 +389,8 @@ function Form(props) {
361
389
  }
362
390
  setComputedProps(props);
363
391
  }, []);
392
+ if (!computedProps)
393
+ return null;
364
394
  return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, computedProps), (_a2 = props.items) == null ? void 0 : _a2.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadProps(__spreadValues({
365
395
  key: item.id
366
396
  }, item), {
@@ -369,15 +399,47 @@ function Form(props) {
369
399
  htmlType: "submit",
370
400
  type: "primary",
371
401
  loading
372
- }, ((_b = props.submit) == null ? void 0 : _b.text) || "Submit"));
402
+ }, ((_b2 = props.submit) == null ? void 0 : _b2.text) || config.Form.submit.text));
373
403
  }
374
404
  Form.useForm = AntdForm2.useForm;
375
405
  Form.Item = FormItem;
376
406
 
407
+ // src/Routers.tsx
408
+ import { Result, Skeleton } from "antd";
409
+ import {
410
+ Suspense
411
+ } from "react";
412
+ import {
413
+ Routes as OriginRoutes,
414
+ Route
415
+ } from "react-router-dom";
416
+ function NoMatch() {
417
+ return /* @__PURE__ */ React.createElement(Result, {
418
+ status: "404",
419
+ title: "404",
420
+ subTitle: "Page not found"
421
+ });
422
+ }
423
+ function Routes(props) {
424
+ return /* @__PURE__ */ React.createElement(OriginRoutes, null, props.routes.map((r) => /* @__PURE__ */ React.createElement(Route, __spreadProps(__spreadValues({
425
+ key: r.path
426
+ }, r), {
427
+ element: r.element || /* @__PURE__ */ React.createElement(Suspense, {
428
+ fallback: /* @__PURE__ */ React.createElement(Skeleton, {
429
+ active: true
430
+ })
431
+ }, /* @__PURE__ */ React.createElement(r.page, null))
432
+ }))), /* @__PURE__ */ React.createElement(Route, {
433
+ key: "*",
434
+ path: "*",
435
+ element: props.notFound || /* @__PURE__ */ React.createElement(NoMatch, null)
436
+ }));
437
+ }
438
+
377
439
  // src/Table.tsx
378
440
  import {
379
441
  useState as useState6,
380
- useEffect as useEffect5,
442
+ useEffect as useEffect6,
381
443
  cloneElement as cloneElement2
382
444
  } from "react";
383
445
  import {
@@ -401,7 +463,8 @@ function processValue(item, value) {
401
463
  }
402
464
  function Table(props) {
403
465
  const [columns, setColumns] = useState6();
404
- useEffect5(() => {
466
+ const [config] = useFaasState();
467
+ useEffect6(() => {
405
468
  var _a2;
406
469
  for (const item of props.items) {
407
470
  if (!item.key)
@@ -470,34 +533,31 @@ function Table(props) {
470
533
  setSelectedKeys,
471
534
  selectedKeys,
472
535
  confirm
473
- }) => {
474
- var _a3, _b;
475
- return /* @__PURE__ */ React.createElement(Radio.Group, {
476
- style: { padding: 8 },
477
- buttonStyle: "solid",
478
- value: selectedKeys[0],
479
- onChange: (e) => {
480
- setSelectedKeys(e.target.value ? [e.target.value] : []);
481
- confirm();
482
- }
483
- }, /* @__PURE__ */ React.createElement(Radio.Button, null, ((_a3 = navigator.language) == null ? void 0 : _a3.includes("CN")) ? "\u5168\u90E8" : "All"), /* @__PURE__ */ React.createElement(Radio.Button, {
484
- value: "true"
485
- }, /* @__PURE__ */ React.createElement(CheckOutlined2, {
486
- style: {
487
- color: "#52c41a",
488
- verticalAlign: "middle"
489
- }
490
- })), /* @__PURE__ */ React.createElement(Radio.Button, {
491
- value: "false"
492
- }, /* @__PURE__ */ React.createElement(CloseOutlined2, {
493
- style: {
494
- verticalAlign: "middle",
495
- color: "#ff4d4f"
496
- }
497
- })), /* @__PURE__ */ React.createElement(Radio.Button, {
498
- value: "empty"
499
- }, ((_b = navigator.language) == null ? void 0 : _b.includes("CN")) ? "\u7A7A" : "Empty"));
500
- };
536
+ }) => /* @__PURE__ */ React.createElement(Radio.Group, {
537
+ style: { padding: 8 },
538
+ buttonStyle: "solid",
539
+ value: selectedKeys[0],
540
+ onChange: (e) => {
541
+ setSelectedKeys(e.target.value ? [e.target.value] : []);
542
+ confirm();
543
+ }
544
+ }, /* @__PURE__ */ React.createElement(Radio.Button, null, config.common.all), /* @__PURE__ */ React.createElement(Radio.Button, {
545
+ value: "true"
546
+ }, /* @__PURE__ */ React.createElement(CheckOutlined2, {
547
+ style: {
548
+ color: "#52c41a",
549
+ verticalAlign: "middle"
550
+ }
551
+ })), /* @__PURE__ */ React.createElement(Radio.Button, {
552
+ value: "false"
553
+ }, /* @__PURE__ */ React.createElement(CloseOutlined2, {
554
+ style: {
555
+ verticalAlign: "middle",
556
+ color: "#ff4d4f"
557
+ }
558
+ })), /* @__PURE__ */ React.createElement(Radio.Button, {
559
+ value: "empty"
560
+ }, config.common.blank));
501
561
  if (!item.onFilter)
502
562
  item.onFilter = (value, row) => {
503
563
  switch (value) {
@@ -523,23 +583,36 @@ function Table(props) {
523
583
  }, [props.items]);
524
584
  if (!columns)
525
585
  return null;
526
- return /* @__PURE__ */ React.createElement(FaasDataWrapper, {
527
- dataSource: props.dataSource,
528
- faasData: props.faasData,
586
+ return /* @__PURE__ */ React.createElement(FaasDataWrapper, __spreadValues({
529
587
  render: ({ data }) => /* @__PURE__ */ React.createElement(AntdTable, __spreadProps(__spreadValues({}, props), {
530
588
  rowKey: props.rowKey || "id",
531
589
  columns,
532
590
  dataSource: data
533
591
  }))
534
- });
592
+ }, props));
593
+ }
594
+
595
+ // src/Title.tsx
596
+ import { useEffect as useEffect7 } from "react";
597
+ function Title(props) {
598
+ const [config] = useFaasState();
599
+ useEffect7(() => {
600
+ const title = Array.isArray(props.title) ? props.title : [props.title];
601
+ document.title = title.concat(props.suffix || config.Title.suffix).filter((t) => !!t).join(props.separator || config.Title.separator);
602
+ }, []);
603
+ return null;
535
604
  }
536
605
  export {
537
606
  Blank,
607
+ Config,
538
608
  Description,
539
609
  Drawer,
540
610
  Form,
541
611
  FormItem,
612
+ Routes,
542
613
  Table,
614
+ Title,
543
615
  transferOptions,
544
- useDrawer
616
+ useDrawer,
617
+ useFaasState
545
618
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/ant-design",
3
- "version": "0.0.2-beta.350",
3
+ "version": "0.0.2-beta.354",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,9 @@
27
27
  "lodash": "*",
28
28
  "react": "*",
29
29
  "react-dom": "*",
30
- "@faasjs/react": "^0.0.2-beta.350"
30
+ "@faasjs/react": "^0.0.2-beta.354",
31
+ "react-use": "*",
32
+ "react-router-dom": "*"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@types/lodash": "*",