@faasjs/ant-design 0.0.2-beta.438 → 0.0.2-beta.439
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 +4 -2
- package/dist/index.js +39 -19
- package/dist/index.mjs +36 -17
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -121,6 +121,7 @@ declare function transferOptions(options: BaseOption[]): {
|
|
|
121
121
|
label: string;
|
|
122
122
|
value?: string | number;
|
|
123
123
|
}[];
|
|
124
|
+
declare function transferValue(type: FaasItemType, value: any): any;
|
|
124
125
|
|
|
125
126
|
declare type DatePickerProps = PickerDateProps<Dayjs>;
|
|
126
127
|
declare const DatePicker: antd_es_date_picker_generatePicker_interface.PickerComponentClass<antd_es_date_picker_generatePicker.PickerProps<Dayjs> & {
|
|
@@ -307,7 +308,8 @@ declare type FormProps<Values = any, ExtendItemProps = any> = {
|
|
|
307
308
|
footer?: JSX.Element | JSX.Element[];
|
|
308
309
|
extendTypes?: ExtendTypes;
|
|
309
310
|
children?: ReactNode;
|
|
310
|
-
|
|
311
|
+
initialValues?: Values;
|
|
312
|
+
} & Omit<FormProps$1<Values>, 'onFinish' | 'children' | 'initialValues'>;
|
|
311
313
|
/**
|
|
312
314
|
* Form component with Ant Design & FaasJS
|
|
313
315
|
*
|
|
@@ -460,4 +462,4 @@ declare type TitleProps = {
|
|
|
460
462
|
*/
|
|
461
463
|
declare function Title(props: TitleProps): JSX.Element;
|
|
462
464
|
|
|
463
|
-
export { BaseItemProps, BaseOption, Blank, BlankProps, Calendar, CalendarProps, ConfigContext, ConfigProvider, ConfigProviderProps, DatePicker, DatePickerProps, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Link, LinkProps, ModalProps, PageNotFound, Routes, RoutesProps, Table, TableItemProps, TableProps, TimePicker, TimePickerProps, Title, TitleProps, setDrawerProps, setModalProps, transferOptions, useConfigContext, useDrawer, useModal };
|
|
465
|
+
export { BaseItemProps, BaseOption, Blank, BlankProps, Calendar, CalendarProps, ConfigContext, ConfigProvider, ConfigProviderProps, DatePicker, DatePickerProps, Description, DescriptionItemProps, DescriptionProps, DrawerProps, ExtendDescriptionItemProps, ExtendDescriptionTypeProps, ExtendFormItemProps, ExtendFormTypeProps, ExtendTableItemProps, ExtendTableTypeProps, ExtendTypes, FaasItemProps, FaasItemType, FaasItemTypeValue, Form, FormItem, FormItemProps, FormProps, Link, LinkProps, ModalProps, PageNotFound, Routes, RoutesProps, Table, TableItemProps, TableProps, TimePicker, TimePickerProps, Title, TitleProps, setDrawerProps, setModalProps, transferOptions, transferValue, useConfigContext, useDrawer, useModal };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
TimePicker: () => TimePicker,
|
|
44
44
|
Title: () => Title,
|
|
45
45
|
transferOptions: () => transferOptions,
|
|
46
|
+
transferValue: () => transferValue,
|
|
46
47
|
useConfigContext: () => useConfigContext,
|
|
47
48
|
useDrawer: () => useDrawer,
|
|
48
49
|
useModal: () => useModal
|
|
@@ -146,6 +147,7 @@ var Calendar = (0, import_generateCalendar.default)(import_dayjs.default);
|
|
|
146
147
|
|
|
147
148
|
// src/data.ts
|
|
148
149
|
var import_lodash3 = require("lodash");
|
|
150
|
+
var import_dayjs2 = __toESM(require("dayjs"));
|
|
149
151
|
function transferOptions(options) {
|
|
150
152
|
if (!options)
|
|
151
153
|
return [];
|
|
@@ -154,19 +156,33 @@ function transferOptions(options) {
|
|
|
154
156
|
value: item
|
|
155
157
|
});
|
|
156
158
|
}
|
|
159
|
+
function transferValue(type, value) {
|
|
160
|
+
if (typeof value === "undefined" || value === null || value === "" || Array.isArray(value) && !value.length)
|
|
161
|
+
return null;
|
|
162
|
+
if (!type)
|
|
163
|
+
type = "string";
|
|
164
|
+
if (type.endsWith("[]") && typeof value === "string")
|
|
165
|
+
value = value.split(",");
|
|
166
|
+
if (["date", "time"].includes(type)) {
|
|
167
|
+
if (typeof value === "number" && value.toString().length === 10)
|
|
168
|
+
value = value * 1e3;
|
|
169
|
+
if (!import_dayjs2.default.isDayjs(value))
|
|
170
|
+
value = (0, import_dayjs2.default)(value);
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
157
174
|
|
|
158
175
|
// src/DatePicker.tsx
|
|
159
|
-
var
|
|
176
|
+
var import_dayjs3 = __toESM(require("rc-picker/es/generate/dayjs.js"));
|
|
160
177
|
var import_generatePicker = __toESM(require("antd/es/date-picker/generatePicker/index.js"));
|
|
161
178
|
var import_style2 = require("antd/es/date-picker/style/index.js");
|
|
162
|
-
var DatePicker = (0, import_generatePicker.default)(
|
|
179
|
+
var DatePicker = (0, import_generatePicker.default)(import_dayjs3.default);
|
|
163
180
|
|
|
164
181
|
// src/Description.tsx
|
|
165
182
|
var import_icons = require("@ant-design/icons");
|
|
166
183
|
var import_antd3 = require("antd");
|
|
167
184
|
var import_lodash4 = require("lodash");
|
|
168
185
|
var import_react3 = require("react");
|
|
169
|
-
var import_dayjs3 = __toESM(require("dayjs"));
|
|
170
186
|
var import_react4 = require("@faasjs/react");
|
|
171
187
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
172
188
|
function DescriptionItemContent(props) {
|
|
@@ -182,6 +198,7 @@ function DescriptionItemContent(props) {
|
|
|
182
198
|
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
183
199
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
184
200
|
}
|
|
201
|
+
propsCopy.value = transferValue(propsCopy.item.type, propsCopy.value);
|
|
185
202
|
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
186
203
|
if (propsCopy.item.type.endsWith("[]"))
|
|
187
204
|
propsCopy.value = propsCopy.value.map((v) => {
|
|
@@ -220,7 +237,7 @@ function DescriptionItemContent(props) {
|
|
|
220
237
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {
|
|
221
238
|
children: computedProps.item.render(computedProps.value, computedProps.values)
|
|
222
239
|
});
|
|
223
|
-
if (
|
|
240
|
+
if (computedProps.value === null)
|
|
224
241
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Blank, {});
|
|
225
242
|
switch (computedProps.item.type) {
|
|
226
243
|
case "string[]":
|
|
@@ -247,11 +264,11 @@ function DescriptionItemContent(props) {
|
|
|
247
264
|
});
|
|
248
265
|
case "time":
|
|
249
266
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {
|
|
250
|
-
children:
|
|
267
|
+
children: computedProps.value.format("YYYY-MM-DD HH:mm:ss")
|
|
251
268
|
});
|
|
252
269
|
case "date":
|
|
253
270
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, {
|
|
254
|
-
children:
|
|
271
|
+
children: computedProps.value.format("YYYY-MM-DD")
|
|
255
272
|
});
|
|
256
273
|
case "object":
|
|
257
274
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Description, {
|
|
@@ -731,8 +748,14 @@ function Form(props) {
|
|
|
731
748
|
const config = useConfigContext();
|
|
732
749
|
const [extendTypes, setExtendTypes] = (0, import_react9.useState)();
|
|
733
750
|
(0, import_react9.useEffect)(() => {
|
|
734
|
-
var _a2;
|
|
751
|
+
var _a2, _b2;
|
|
735
752
|
const propsCopy = { ...props };
|
|
753
|
+
if (propsCopy.initialValues)
|
|
754
|
+
for (const key in propsCopy.initialValues)
|
|
755
|
+
propsCopy.initialValues[key] = transferValue(
|
|
756
|
+
(_a2 = propsCopy.items.find((i) => i.id === key)) == null ? void 0 : _a2.type,
|
|
757
|
+
propsCopy.initialValues[key]
|
|
758
|
+
);
|
|
736
759
|
if (propsCopy.onFinish) {
|
|
737
760
|
propsCopy.onFinish = async (values) => {
|
|
738
761
|
var _a3;
|
|
@@ -750,7 +773,7 @@ function Form(props) {
|
|
|
750
773
|
}
|
|
751
774
|
setLoading(false);
|
|
752
775
|
};
|
|
753
|
-
} else if (propsCopy.submit && ((
|
|
776
|
+
} else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
|
|
754
777
|
propsCopy.onFinish = async (values) => {
|
|
755
778
|
setLoading(true);
|
|
756
779
|
return (0, import_react8.faas)(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
|
|
@@ -923,13 +946,12 @@ var import_react13 = require("@faasjs/react");
|
|
|
923
946
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
924
947
|
function processValue(item, value) {
|
|
925
948
|
var _a;
|
|
926
|
-
|
|
949
|
+
const transferred = transferValue(item.type, value);
|
|
950
|
+
if (transferred === null)
|
|
927
951
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Blank, {});
|
|
928
|
-
if (item.type.endsWith("[]") && typeof value === "string")
|
|
929
|
-
value = value.split(",");
|
|
930
952
|
if (item.options) {
|
|
931
953
|
if (item.type.endsWith("[]"))
|
|
932
|
-
return
|
|
954
|
+
return transferred.map((v) => {
|
|
933
955
|
var _a2;
|
|
934
956
|
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
935
957
|
}).join(", ");
|
|
@@ -938,15 +960,12 @@ function processValue(item, value) {
|
|
|
938
960
|
"number",
|
|
939
961
|
"boolean"
|
|
940
962
|
].includes(item.type))
|
|
941
|
-
return ((_a = item.options.find((option) => option.value ===
|
|
963
|
+
return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
|
|
942
964
|
}
|
|
943
965
|
if (item.type.endsWith("[]"))
|
|
944
|
-
return
|
|
945
|
-
if (["date", "time"].includes(item.type))
|
|
946
|
-
|
|
947
|
-
value = value * 1e3;
|
|
948
|
-
return (0, import_dayjs5.default)(value).format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
|
|
949
|
-
}
|
|
966
|
+
return transferred.join(", ");
|
|
967
|
+
if (["date", "time"].includes(item.type))
|
|
968
|
+
return transferred.format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
|
|
950
969
|
return value;
|
|
951
970
|
}
|
|
952
971
|
function Table(props) {
|
|
@@ -1331,6 +1350,7 @@ function Title(props) {
|
|
|
1331
1350
|
TimePicker,
|
|
1332
1351
|
Title,
|
|
1333
1352
|
transferOptions,
|
|
1353
|
+
transferValue,
|
|
1334
1354
|
useConfigContext,
|
|
1335
1355
|
useDrawer,
|
|
1336
1356
|
useModal
|
package/dist/index.mjs
CHANGED
|
@@ -100,6 +100,7 @@ var Calendar = generateCalendar(dayjsGenerateConfig);
|
|
|
100
100
|
|
|
101
101
|
// src/data.ts
|
|
102
102
|
import { upperFirst } from "lodash";
|
|
103
|
+
import dayjs from "dayjs";
|
|
103
104
|
function transferOptions(options) {
|
|
104
105
|
if (!options)
|
|
105
106
|
return [];
|
|
@@ -108,6 +109,21 @@ function transferOptions(options) {
|
|
|
108
109
|
value: item
|
|
109
110
|
});
|
|
110
111
|
}
|
|
112
|
+
function transferValue(type, value) {
|
|
113
|
+
if (typeof value === "undefined" || value === null || value === "" || Array.isArray(value) && !value.length)
|
|
114
|
+
return null;
|
|
115
|
+
if (!type)
|
|
116
|
+
type = "string";
|
|
117
|
+
if (type.endsWith("[]") && typeof value === "string")
|
|
118
|
+
value = value.split(",");
|
|
119
|
+
if (["date", "time"].includes(type)) {
|
|
120
|
+
if (typeof value === "number" && value.toString().length === 10)
|
|
121
|
+
value = value * 1e3;
|
|
122
|
+
if (!dayjs.isDayjs(value))
|
|
123
|
+
value = dayjs(value);
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
111
127
|
|
|
112
128
|
// src/DatePicker.tsx
|
|
113
129
|
import dayjsGenerateConfig2 from "rc-picker/es/generate/dayjs.js";
|
|
@@ -128,7 +144,6 @@ import {
|
|
|
128
144
|
useEffect as useEffect2,
|
|
129
145
|
useState as useState2
|
|
130
146
|
} from "react";
|
|
131
|
-
import dayjs from "dayjs";
|
|
132
147
|
import { FaasDataWrapper } from "@faasjs/react";
|
|
133
148
|
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
134
149
|
function DescriptionItemContent(props) {
|
|
@@ -144,6 +159,7 @@ function DescriptionItemContent(props) {
|
|
|
144
159
|
if ((_a2 = propsCopy.item.options) == null ? void 0 : _a2.length) {
|
|
145
160
|
propsCopy.item.options = transferOptions(propsCopy.item.options);
|
|
146
161
|
}
|
|
162
|
+
propsCopy.value = transferValue(propsCopy.item.type, propsCopy.value);
|
|
147
163
|
if (propsCopy.item.options && typeof propsCopy.value !== "undefined" && propsCopy.value !== null) {
|
|
148
164
|
if (propsCopy.item.type.endsWith("[]"))
|
|
149
165
|
propsCopy.value = propsCopy.value.map((v) => {
|
|
@@ -182,7 +198,7 @@ function DescriptionItemContent(props) {
|
|
|
182
198
|
return /* @__PURE__ */ jsx3(Fragment, {
|
|
183
199
|
children: computedProps.item.render(computedProps.value, computedProps.values)
|
|
184
200
|
});
|
|
185
|
-
if (
|
|
201
|
+
if (computedProps.value === null)
|
|
186
202
|
return /* @__PURE__ */ jsx3(Blank, {});
|
|
187
203
|
switch (computedProps.item.type) {
|
|
188
204
|
case "string[]":
|
|
@@ -209,11 +225,11 @@ function DescriptionItemContent(props) {
|
|
|
209
225
|
});
|
|
210
226
|
case "time":
|
|
211
227
|
return /* @__PURE__ */ jsx3(Fragment, {
|
|
212
|
-
children:
|
|
228
|
+
children: computedProps.value.format("YYYY-MM-DD HH:mm:ss")
|
|
213
229
|
});
|
|
214
230
|
case "date":
|
|
215
231
|
return /* @__PURE__ */ jsx3(Fragment, {
|
|
216
|
-
children:
|
|
232
|
+
children: computedProps.value.format("YYYY-MM-DD")
|
|
217
233
|
});
|
|
218
234
|
case "object":
|
|
219
235
|
return /* @__PURE__ */ jsx3(Description, {
|
|
@@ -711,8 +727,14 @@ function Form(props) {
|
|
|
711
727
|
const config = useConfigContext();
|
|
712
728
|
const [extendTypes, setExtendTypes] = useState5();
|
|
713
729
|
useEffect4(() => {
|
|
714
|
-
var _a2;
|
|
730
|
+
var _a2, _b2;
|
|
715
731
|
const propsCopy = { ...props };
|
|
732
|
+
if (propsCopy.initialValues)
|
|
733
|
+
for (const key in propsCopy.initialValues)
|
|
734
|
+
propsCopy.initialValues[key] = transferValue(
|
|
735
|
+
(_a2 = propsCopy.items.find((i) => i.id === key)) == null ? void 0 : _a2.type,
|
|
736
|
+
propsCopy.initialValues[key]
|
|
737
|
+
);
|
|
716
738
|
if (propsCopy.onFinish) {
|
|
717
739
|
propsCopy.onFinish = async (values) => {
|
|
718
740
|
var _a3;
|
|
@@ -730,7 +752,7 @@ function Form(props) {
|
|
|
730
752
|
}
|
|
731
753
|
setLoading(false);
|
|
732
754
|
};
|
|
733
|
-
} else if (propsCopy.submit && ((
|
|
755
|
+
} else if (propsCopy.submit && ((_b2 = propsCopy.submit.to) == null ? void 0 : _b2.action)) {
|
|
734
756
|
propsCopy.onFinish = async (values) => {
|
|
735
757
|
setLoading(true);
|
|
736
758
|
return faas(propsCopy.submit.to.action, propsCopy.submit.to.params ? {
|
|
@@ -921,13 +943,12 @@ import { FaasDataWrapper as FaasDataWrapper2 } from "@faasjs/react";
|
|
|
921
943
|
import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
922
944
|
function processValue(item, value) {
|
|
923
945
|
var _a;
|
|
924
|
-
|
|
946
|
+
const transferred = transferValue(item.type, value);
|
|
947
|
+
if (transferred === null)
|
|
925
948
|
return /* @__PURE__ */ jsx11(Blank, {});
|
|
926
|
-
if (item.type.endsWith("[]") && typeof value === "string")
|
|
927
|
-
value = value.split(",");
|
|
928
949
|
if (item.options) {
|
|
929
950
|
if (item.type.endsWith("[]"))
|
|
930
|
-
return
|
|
951
|
+
return transferred.map((v) => {
|
|
931
952
|
var _a2;
|
|
932
953
|
return ((_a2 = item.options.find((option) => option.value === v)) == null ? void 0 : _a2.label) || v;
|
|
933
954
|
}).join(", ");
|
|
@@ -936,15 +957,12 @@ function processValue(item, value) {
|
|
|
936
957
|
"number",
|
|
937
958
|
"boolean"
|
|
938
959
|
].includes(item.type))
|
|
939
|
-
return ((_a = item.options.find((option) => option.value ===
|
|
960
|
+
return ((_a = item.options.find((option) => option.value === transferred)) == null ? void 0 : _a.label) || transferred;
|
|
940
961
|
}
|
|
941
962
|
if (item.type.endsWith("[]"))
|
|
942
|
-
return
|
|
943
|
-
if (["date", "time"].includes(item.type))
|
|
944
|
-
|
|
945
|
-
value = value * 1e3;
|
|
946
|
-
return dayjs3(value).format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
|
|
947
|
-
}
|
|
963
|
+
return transferred.join(", ");
|
|
964
|
+
if (["date", "time"].includes(item.type))
|
|
965
|
+
return transferred.format(item.type === "date" ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
|
|
948
966
|
return value;
|
|
949
967
|
}
|
|
950
968
|
function Table(props) {
|
|
@@ -1328,6 +1346,7 @@ export {
|
|
|
1328
1346
|
TimePicker,
|
|
1329
1347
|
Title,
|
|
1330
1348
|
transferOptions,
|
|
1349
|
+
transferValue,
|
|
1331
1350
|
useConfigContext,
|
|
1332
1351
|
useDrawer,
|
|
1333
1352
|
useModal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.439",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lodash": "*",
|
|
29
29
|
"react": "*",
|
|
30
30
|
"react-dom": "*",
|
|
31
|
-
"@faasjs/react": "^0.0.2-beta.
|
|
31
|
+
"@faasjs/react": "^0.0.2-beta.439",
|
|
32
32
|
"react-router-dom": "*",
|
|
33
33
|
"dayjs": "*"
|
|
34
34
|
},
|