@enableai-base/form 1.0.0
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/form.cjs.js +733 -0
- package/dist/form.cjs.prod.js +733 -0
- package/dist/form.css +70 -0
- package/dist/form.d.ts +144 -0
- package/dist/form.esm-bundler.mjs +710 -0
- package/index.js +7 -0
- package/package.json +45 -0
package/dist/form.cjs.js
ADDED
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enableai-base/form v1.0.0
|
|
3
|
+
* (c) 2024-present Enableai
|
|
4
|
+
* @license Proprietary
|
|
5
|
+
**/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
var React = require('react');
|
|
11
|
+
var antd = require('antd');
|
|
12
|
+
var proComponents = require('@ant-design/pro-components');
|
|
13
|
+
var ui = require('@enableai-base/ui');
|
|
14
|
+
var reactHooks = require('@enableai-sdk-common/react-hooks');
|
|
15
|
+
var lodash = require('lodash');
|
|
16
|
+
var dayjs = require('dayjs');
|
|
17
|
+
var ReactMonacoEditor = require('@monaco-editor/react');
|
|
18
|
+
var core = require('@enableai-base/core');
|
|
19
|
+
var icons = require('@ant-design/icons');
|
|
20
|
+
var timezone = require('dayjs/plugin/timezone');
|
|
21
|
+
var utc = require('dayjs/plugin/utc');
|
|
22
|
+
var baseModal = require('@enableai-sdk-ui/base-modal');
|
|
23
|
+
|
|
24
|
+
const FeatureCustomOptions = ({ features, onChange, freeze }) => {
|
|
25
|
+
reactHooks.useMount(() => {
|
|
26
|
+
if (!features.options) onChange({ options: [] });
|
|
27
|
+
});
|
|
28
|
+
const initialValues = React.useMemo(() => {
|
|
29
|
+
return Array.isArray(features?.options) ? features?.options : [];
|
|
30
|
+
}, [features?.options]);
|
|
31
|
+
const [height, setHeight] = React.useState(0);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
const initHeight = initialValues.length >= 4 ? 160 : initialValues.length * 40;
|
|
34
|
+
if (height !== initHeight) {
|
|
35
|
+
setHeight(initHeight);
|
|
36
|
+
}
|
|
37
|
+
}, [height, initialValues, setHeight]);
|
|
38
|
+
const debounceChange = reactHooks.useDebounce(onChange, 500);
|
|
39
|
+
const onValuesChange = (values) => {
|
|
40
|
+
if (values.length === initialValues.length) {
|
|
41
|
+
debounceChange({ options: values });
|
|
42
|
+
} else {
|
|
43
|
+
onChange({ options: values });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(antd.Divider, { className: "custom-form-divider" }), /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { className: "custom-form-item", key: "options", name: "options", label: "\u9009\u9879\u5185\u5BB9" }), /* @__PURE__ */ React.createElement(antd.Flex, { className: "custom-options-container" }, /* @__PURE__ */ React.createElement(
|
|
47
|
+
ui.OptionEditor,
|
|
48
|
+
{
|
|
49
|
+
initialValues,
|
|
50
|
+
onValuesChange,
|
|
51
|
+
virtualConfig: { height },
|
|
52
|
+
disabled: freeze
|
|
53
|
+
}
|
|
54
|
+
)));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const FeatureDateFormat = ({ features, onChange }) => {
|
|
58
|
+
reactHooks.useMount(() => {
|
|
59
|
+
if (!features.dateFormat) onChange({ dateFormat: "YYYY/MM/DD" });
|
|
60
|
+
});
|
|
61
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "dateFormat", name: "dateFormat", label: "\u65E5\u671F\u683C\u5F0F" }, /* @__PURE__ */ React.createElement(
|
|
62
|
+
antd.Select,
|
|
63
|
+
{
|
|
64
|
+
style: { width: "100%" },
|
|
65
|
+
options: [
|
|
66
|
+
{ label: "2025/01/30", value: "YYYY/MM/DD" },
|
|
67
|
+
{ label: "2025/01/30 14:00 (GMT+8)", value: "YYYY/MM/DD HH:mm (GMT+8)" },
|
|
68
|
+
{ label: "2025/01/30 14:00", value: "YYYY/MM/DD HH:mm" },
|
|
69
|
+
{ label: "2025-01-30", value: "YYYY-MM-DD" },
|
|
70
|
+
{ label: "2025-01-30 14:00", value: "YYYY-MM-DD HH:mm" },
|
|
71
|
+
{ label: "2025-01-30 14:00 (GMT+8)", value: "YYYY-MM-DD HH:mm (GMT+8)" },
|
|
72
|
+
{ label: "01-30", value: "MM-DD" },
|
|
73
|
+
{ label: "30/01/2025", value: "DD/MM/YYYY" },
|
|
74
|
+
{ label: "01/30/2025", value: "MM/DD/YYYY" }
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const CustomDatePickerV2 = ({ formatType, onChangeDate }) => {
|
|
81
|
+
const hasGMTLabel = formatType?.includes("GMT+");
|
|
82
|
+
const GMTLabel = "GMT+8";
|
|
83
|
+
const pureFormat = formatType?.replace(` (GMT+8)`, "") ?? "YYYY-MM-DD";
|
|
84
|
+
const customFormat = (value) => {
|
|
85
|
+
return `${value.format(pureFormat)}${hasGMTLabel ? ` (${GMTLabel})` : ""} `;
|
|
86
|
+
};
|
|
87
|
+
return /* @__PURE__ */ React.createElement(
|
|
88
|
+
antd.DatePicker,
|
|
89
|
+
{
|
|
90
|
+
style: { width: "100%" },
|
|
91
|
+
className: "column-setting-date-picker",
|
|
92
|
+
showTime: pureFormat.includes("HH:mm") ? { format: pureFormat } : false,
|
|
93
|
+
format: customFormat,
|
|
94
|
+
key: "datePicker",
|
|
95
|
+
placement: "bottomLeft",
|
|
96
|
+
onChange: (date) => {
|
|
97
|
+
if (date) {
|
|
98
|
+
onChangeDate(date);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onOk: (date) => {
|
|
102
|
+
if (date) {
|
|
103
|
+
onChangeDate(date);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const CREATE_DATE$1 = "record_create_date";
|
|
111
|
+
const FeatureDefaultDateV2 = ({ features, onChange }) => {
|
|
112
|
+
const formatType = features?.dateFormat || "YYYY/MM/DD";
|
|
113
|
+
const initialValue = features?.defaultValue;
|
|
114
|
+
const isCreateDate = initialValue === CREATE_DATE$1;
|
|
115
|
+
const [date, setDate] = React.useState(null);
|
|
116
|
+
const debouncedOnChange = reactHooks.useDebounce(onChange);
|
|
117
|
+
const onChangeDate = React.useCallback(
|
|
118
|
+
(selected) => {
|
|
119
|
+
const time = selected.format(formatType);
|
|
120
|
+
setDate(selected);
|
|
121
|
+
debouncedOnChange({ defaultValue: time });
|
|
122
|
+
},
|
|
123
|
+
[formatType, debouncedOnChange]
|
|
124
|
+
);
|
|
125
|
+
React.useEffect(() => {
|
|
126
|
+
if (isCreateDate) return;
|
|
127
|
+
let dateValue = "";
|
|
128
|
+
if (!date) {
|
|
129
|
+
const date2 = dayjs(initialValue + "");
|
|
130
|
+
dateValue = date2.format(formatType);
|
|
131
|
+
} else {
|
|
132
|
+
dateValue = date.format(formatType);
|
|
133
|
+
}
|
|
134
|
+
if (dateValue === "Invalid Date") {
|
|
135
|
+
onChange({ defaultValue: void 0 });
|
|
136
|
+
} else if (dateValue !== initialValue) {
|
|
137
|
+
onChange({ defaultValue: dateValue });
|
|
138
|
+
}
|
|
139
|
+
}, [formatType]);
|
|
140
|
+
React.useEffect(() => {
|
|
141
|
+
return () => {
|
|
142
|
+
onChange({ defaultValue: "" });
|
|
143
|
+
};
|
|
144
|
+
}, []);
|
|
145
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "defaultValue", name: "defaultValue", label: "\u9ED8\u8BA4\u503C" }, /* @__PURE__ */ React.createElement(CustomDatePickerV2, { onChangeDate, formatType }));
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const FeatureDefaultInput = ({ onChange }) => {
|
|
149
|
+
React.useEffect(() => {
|
|
150
|
+
return () => {
|
|
151
|
+
onChange({ defaultValue: void 0 });
|
|
152
|
+
};
|
|
153
|
+
}, []);
|
|
154
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "defaultValue", name: "defaultValue", label: "\u9ED8\u8BA4\u503C" }, /* @__PURE__ */ React.createElement(antd.Input, { placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9" }));
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
ReactMonacoEditor.loader.config({
|
|
158
|
+
paths: {
|
|
159
|
+
// vs: '/monaco-assets/vs',
|
|
160
|
+
}
|
|
161
|
+
// 'vs/nls': { availableLanguages: { '*': 'zh-cn' } },
|
|
162
|
+
});
|
|
163
|
+
const FeatureDefaultJson = ({ features, onChange }) => {
|
|
164
|
+
const initialValue = features?.defaultValue;
|
|
165
|
+
const monacoEditorRef = React.useRef(null);
|
|
166
|
+
const monacoRef = React.useRef(null);
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
return () => {
|
|
169
|
+
onChange({ defaultValue: void 0 });
|
|
170
|
+
};
|
|
171
|
+
}, []);
|
|
172
|
+
const format = () => {
|
|
173
|
+
monacoEditorRef.current?.getAction("editor.action.formatDocument")?.run();
|
|
174
|
+
};
|
|
175
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "defaultValue", name: "defaultValue", label: "\u9ED8\u8BA4\u503C" }, /* @__PURE__ */ React.createElement("div", { style: { position: "relative", width: "100%", height: "302px", border: "1px solid #6c6c6c" } }, /* @__PURE__ */ React.createElement(
|
|
176
|
+
ReactMonacoEditor,
|
|
177
|
+
{
|
|
178
|
+
height: "300px",
|
|
179
|
+
defaultLanguage: "json",
|
|
180
|
+
value: initialValue,
|
|
181
|
+
loading: /* @__PURE__ */ React.createElement(antd.Spin, null),
|
|
182
|
+
theme: "light",
|
|
183
|
+
onChange: (value) => {
|
|
184
|
+
onChange({ defaultValue: value });
|
|
185
|
+
},
|
|
186
|
+
beforeMount: (monaco) => {
|
|
187
|
+
monacoRef.current = monaco;
|
|
188
|
+
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
189
|
+
validate: true,
|
|
190
|
+
schemas: [
|
|
191
|
+
{
|
|
192
|
+
uri: "test-schema",
|
|
193
|
+
fileMatch: ["*"],
|
|
194
|
+
schema: {
|
|
195
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
196
|
+
type: "object"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
});
|
|
201
|
+
format();
|
|
202
|
+
},
|
|
203
|
+
onMount: (monacoEditor) => {
|
|
204
|
+
monacoEditorRef.current = monacoEditor;
|
|
205
|
+
format();
|
|
206
|
+
},
|
|
207
|
+
options: {
|
|
208
|
+
lineNumbers: "off",
|
|
209
|
+
minimap: { enabled: false }
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
)));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const sanitizeInput = (value) => {
|
|
216
|
+
let sanitized = value.replace(/[^\d.-]/g, "");
|
|
217
|
+
const parts = sanitized.split(".");
|
|
218
|
+
if (parts.length > 2) sanitized = parts[0] + "." + parts.slice(1).join("");
|
|
219
|
+
if (sanitized.includes("-") && sanitized.indexOf("-") > 0) sanitized = sanitized.replace(/-/g, "");
|
|
220
|
+
return sanitized;
|
|
221
|
+
};
|
|
222
|
+
const FeatureDefaultNumber = ({ features, onChange }) => {
|
|
223
|
+
const formatType = features?.numberFormat || "integer";
|
|
224
|
+
const initialValue = features?.defaultValue;
|
|
225
|
+
const [rawValue, setRawValue] = React.useState("");
|
|
226
|
+
const [displayValue, setDisplayValue] = React.useState("");
|
|
227
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
228
|
+
const debounceOnChange = reactHooks.useDebounce(onChange, 300);
|
|
229
|
+
const onChangeInput = (e) => {
|
|
230
|
+
const input = sanitizeInput(e.target.value);
|
|
231
|
+
setRawValue(input);
|
|
232
|
+
debounceOnChange({ defaultValue: input });
|
|
233
|
+
if (isFocused) setDisplayValue(input);
|
|
234
|
+
};
|
|
235
|
+
const onFocus = () => {
|
|
236
|
+
setIsFocused(true);
|
|
237
|
+
setDisplayValue(rawValue);
|
|
238
|
+
};
|
|
239
|
+
const onBlur = () => {
|
|
240
|
+
setIsFocused(false);
|
|
241
|
+
setDisplayValue(core.formatValue(rawValue, formatType));
|
|
242
|
+
};
|
|
243
|
+
React.useEffect(() => {
|
|
244
|
+
if (typeof initialValue !== "string") return;
|
|
245
|
+
const input = sanitizeInput(initialValue);
|
|
246
|
+
setRawValue(input);
|
|
247
|
+
if (!isFocused) setDisplayValue(core.formatValue(input, formatType));
|
|
248
|
+
}, [formatType]);
|
|
249
|
+
React.useEffect(() => {
|
|
250
|
+
return () => {
|
|
251
|
+
onChange({ defaultValue: void 0 });
|
|
252
|
+
};
|
|
253
|
+
}, []);
|
|
254
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "defaultValue", name: "defaultValue", label: "\u9ED8\u8BA4\u503C" }, /* @__PURE__ */ React.createElement(antd.Input, { placeholder: "\u8BF7\u8F93\u5165\u6570\u5B57", value: displayValue, onChange: onChangeInput, onFocus, onBlur }));
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const FeatureDefaultSelect = ({ tableConfig, features, onChange }) => {
|
|
258
|
+
const mode = React.useMemo(() => {
|
|
259
|
+
const custom = tableConfig?.customOptions;
|
|
260
|
+
return typeof custom === "object" && custom.multiSelect ? "multiple" : "single";
|
|
261
|
+
}, [tableConfig]);
|
|
262
|
+
const options = React.useMemo(
|
|
263
|
+
() => Array.isArray(features?.options) ? features.options.map((opt) => ({ ...opt, label: opt.label || " " })) : [],
|
|
264
|
+
[features?.options]
|
|
265
|
+
);
|
|
266
|
+
React.useEffect(() => {
|
|
267
|
+
const defaultValue = features?.defaultValue;
|
|
268
|
+
if (!defaultValue) return;
|
|
269
|
+
const optionIdSet = new Set(options.map((opt) => opt.value));
|
|
270
|
+
const resetDefault = (value) => {
|
|
271
|
+
onChange({ defaultValue: value });
|
|
272
|
+
};
|
|
273
|
+
if (!Array.isArray(defaultValue) || !defaultValue.every((v) => typeof v === "string")) {
|
|
274
|
+
return resetDefault(void 0);
|
|
275
|
+
}
|
|
276
|
+
let filtered = defaultValue.filter((id) => optionIdSet.has(id));
|
|
277
|
+
if (mode === "single") filtered = filtered.slice(filtered.length - 1);
|
|
278
|
+
if (filtered.length !== defaultValue.length) {
|
|
279
|
+
resetDefault(filtered);
|
|
280
|
+
}
|
|
281
|
+
}, [mode, features?.defaultValue, options, onChange]);
|
|
282
|
+
const handleChange = (value) => {
|
|
283
|
+
if (mode === "single") {
|
|
284
|
+
onChange({ defaultValue: value.slice(value.length - 1) });
|
|
285
|
+
} else {
|
|
286
|
+
onChange({ defaultValue: value });
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
React.useEffect(() => {
|
|
290
|
+
return () => {
|
|
291
|
+
onChange({ defaultValue: void 0 });
|
|
292
|
+
};
|
|
293
|
+
}, []);
|
|
294
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { className: "custom-form-item", key: "defaultValue", name: "defaultValue", label: "\u9ED8\u8BA4\u503C" }), /* @__PURE__ */ React.createElement(
|
|
295
|
+
antd.Select,
|
|
296
|
+
{
|
|
297
|
+
className: "custom-form-container",
|
|
298
|
+
mode: "multiple",
|
|
299
|
+
value: features?.defaultValue,
|
|
300
|
+
fieldNames: { label: "label", value: "value" },
|
|
301
|
+
style: { width: "100%" },
|
|
302
|
+
placeholder: "\u8BF7\u9009\u62E9\u9009\u9879",
|
|
303
|
+
onChange: handleChange,
|
|
304
|
+
options
|
|
305
|
+
}
|
|
306
|
+
));
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const FeatureDefaultField = ({ tableConfig, features, onChange }) => {
|
|
310
|
+
const Component = React.useMemo(() => {
|
|
311
|
+
let DefaultComponent;
|
|
312
|
+
if (tableConfig.customOptions) {
|
|
313
|
+
DefaultComponent = FeatureDefaultSelect;
|
|
314
|
+
} else if (tableConfig.date) {
|
|
315
|
+
DefaultComponent = FeatureDefaultDateV2;
|
|
316
|
+
} else if (tableConfig.numberSelect) {
|
|
317
|
+
DefaultComponent = FeatureDefaultNumber;
|
|
318
|
+
} else if (tableConfig.json) {
|
|
319
|
+
DefaultComponent = FeatureDefaultJson;
|
|
320
|
+
} else {
|
|
321
|
+
DefaultComponent = FeatureDefaultInput;
|
|
322
|
+
}
|
|
323
|
+
return DefaultComponent;
|
|
324
|
+
}, [tableConfig]);
|
|
325
|
+
return /* @__PURE__ */ React.createElement(Component, { features, onChange, tableConfig });
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const FeatureNumberFormat = ({ features, onChange }) => {
|
|
329
|
+
reactHooks.useMount(() => {
|
|
330
|
+
if (!features.numberFormat) onChange({ numberFormat: "integer" });
|
|
331
|
+
});
|
|
332
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "numberFormat", name: "numberFormat", label: "\u6570\u5B57\u683C\u5F0F" }, /* @__PURE__ */ React.createElement(
|
|
333
|
+
antd.Select,
|
|
334
|
+
{
|
|
335
|
+
style: { width: "100%" },
|
|
336
|
+
options: [
|
|
337
|
+
{
|
|
338
|
+
label: "\u6574\u6570",
|
|
339
|
+
value: "integer"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
label: "\u5343\u5206\u4F4D",
|
|
343
|
+
value: "thousands_separator"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
label: "\u5343\u5206\u4F4D(\u5C0F\u6570\u70B9)",
|
|
347
|
+
value: "thousands_separator_decimal"
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
label: "\u4FDD\u75591\u4F4D\u5C0F\u6570",
|
|
351
|
+
value: "one_decimal_decimal"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
label: "\u4FDD\u75592\u4F4D\u5C0F\u6570",
|
|
355
|
+
value: "two_decimal_decimal"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
label: "\u4FDD\u75593\u4F4D\u5C0F\u6570",
|
|
359
|
+
value: "three_decimal_decimal"
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
label: "\u4FDD\u75594\u4F4D\u5C0F\u6570",
|
|
363
|
+
value: "four_decimal_decimal"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
label: "\u4FDD\u75595\u4F4D\u5C0F\u6570",
|
|
367
|
+
value: "five_decimal_decimal"
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
label: "\u4FDD\u75596\u4F4D\u5C0F\u6570",
|
|
371
|
+
value: "six_decimal_decimal"
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
label: "\u767E\u5206\u6BD4",
|
|
375
|
+
value: "percentage"
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
label: "\u767E\u5206\u6BD4(\u5C0F\u6570\u70B9)",
|
|
379
|
+
value: "percentage_decimal"
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
));
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const FeatureTypeSelect = ({ feature, tools, selectProps }) => {
|
|
387
|
+
const options = React.useMemo(() => {
|
|
388
|
+
if (!tools) return [];
|
|
389
|
+
return tools.map((item) => ({
|
|
390
|
+
...item,
|
|
391
|
+
label: /* @__PURE__ */ React.createElement(antd.Flex, { gap: 4, align: "center" }, /* @__PURE__ */ React.createElement(ui.IconFont, { name: core.TOOL_ICON[item.value], size: 16, color: "#000" }), item.label)
|
|
392
|
+
}));
|
|
393
|
+
}, [tools]);
|
|
394
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: feature.name, name: feature.name, label: feature.label }, /* @__PURE__ */ React.createElement(antd.Select, { style: { width: "100%" }, options, ...selectProps }));
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const FeatureField = ({ features, tools, onChange, selectProps, freeze }) => {
|
|
398
|
+
const tableConfig = React.useMemo(() => {
|
|
399
|
+
if (!tools) return void 0;
|
|
400
|
+
return tools.find((item) => item.value === Number(features["type"]))?.table;
|
|
401
|
+
}, [features, tools]);
|
|
402
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
403
|
+
FeatureTypeSelect,
|
|
404
|
+
{
|
|
405
|
+
feature: { name: "type", label: "\u5B57\u6BB5\u7C7B\u578B", value: 29 },
|
|
406
|
+
tools,
|
|
407
|
+
selectProps
|
|
408
|
+
}
|
|
409
|
+
), tableConfig?.customOptions && /* @__PURE__ */ React.createElement(FeatureCustomOptions, { features, onChange, freeze }), tableConfig?.date && /* @__PURE__ */ React.createElement(FeatureDateFormat, { features, onChange }), tableConfig?.numberSelect && /* @__PURE__ */ React.createElement(FeatureNumberFormat, { features, onChange }), tableConfig?.defaultValue && /* @__PURE__ */ React.createElement(FeatureDefaultField, { tableConfig, features, onChange }));
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const FeatureInput = ({ feature, freeze }) => {
|
|
413
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: feature.name, name: feature.name, label: feature.label }, /* @__PURE__ */ React.createElement(antd.Input, { disabled: freeze })));
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const ColumnFieldFrom = ({
|
|
417
|
+
formRef,
|
|
418
|
+
selectProps,
|
|
419
|
+
columnId,
|
|
420
|
+
tools,
|
|
421
|
+
initValues,
|
|
422
|
+
onFinish,
|
|
423
|
+
onCancel,
|
|
424
|
+
freeze,
|
|
425
|
+
bodyRef
|
|
426
|
+
}) => {
|
|
427
|
+
const [form] = antd.Form.useForm();
|
|
428
|
+
const [fields, setFields] = React.useState(initValues);
|
|
429
|
+
const blinkRef = React.useRef(null);
|
|
430
|
+
const isModifiedRef = React.useRef(false);
|
|
431
|
+
const [loading, setLoading] = React.useState(false);
|
|
432
|
+
React.useEffect(() => {
|
|
433
|
+
form.setFieldsValue(initValues);
|
|
434
|
+
setFields(initValues);
|
|
435
|
+
}, [form, initValues]);
|
|
436
|
+
const onChange = (changed) => {
|
|
437
|
+
form.setFieldsValue(changed);
|
|
438
|
+
const oldValues = initValues;
|
|
439
|
+
const newValues = form.getFieldsValue();
|
|
440
|
+
setFields(newValues);
|
|
441
|
+
const isModified = !lodash.isEqual(newValues, oldValues);
|
|
442
|
+
isModifiedRef.current = isModified;
|
|
443
|
+
};
|
|
444
|
+
const onValuesChange = reactHooks.useDebounce(onChange, 200);
|
|
445
|
+
const checkChange = () => {
|
|
446
|
+
if (isModifiedRef.current) blinkRef.current?.blink();
|
|
447
|
+
return isModifiedRef.current;
|
|
448
|
+
};
|
|
449
|
+
React.useImperativeHandle(formRef, () => {
|
|
450
|
+
return {
|
|
451
|
+
checkChange
|
|
452
|
+
};
|
|
453
|
+
});
|
|
454
|
+
return /* @__PURE__ */ React.createElement(
|
|
455
|
+
proComponents.ProForm,
|
|
456
|
+
{
|
|
457
|
+
id: columnId,
|
|
458
|
+
form,
|
|
459
|
+
className: "column-setting-form",
|
|
460
|
+
formKey: "column-setting-form",
|
|
461
|
+
style: { width: "100%" },
|
|
462
|
+
initialValues: initValues,
|
|
463
|
+
onValuesChange,
|
|
464
|
+
onFinish: async (values) => {
|
|
465
|
+
setLoading(true);
|
|
466
|
+
try {
|
|
467
|
+
return await onFinish(values);
|
|
468
|
+
} finally {
|
|
469
|
+
setLoading(false);
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
submitter: {
|
|
473
|
+
render: false
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
/* @__PURE__ */ React.createElement("div", { ref: bodyRef }, /* @__PURE__ */ React.createElement(
|
|
477
|
+
FeatureInput,
|
|
478
|
+
{
|
|
479
|
+
feature: {
|
|
480
|
+
name: "title",
|
|
481
|
+
value: " ",
|
|
482
|
+
label: "\u6807\u9898"
|
|
483
|
+
},
|
|
484
|
+
freeze
|
|
485
|
+
}
|
|
486
|
+
), /* @__PURE__ */ React.createElement(FeatureField, { features: fields, tools, onChange, selectProps, freeze })),
|
|
487
|
+
/* @__PURE__ */ React.createElement(proComponents.ProForm.Item, { className: "form-button-container footer" }, /* @__PURE__ */ React.createElement(antd.Flex, { gap: 8, align: "center", justify: "end" }, /* @__PURE__ */ React.createElement(antd.Button, { type: "default", disabled: loading, onClick: onCancel }, /* @__PURE__ */ React.createElement("span", null, "\u53D6\u6D88")), /* @__PURE__ */ React.createElement(ui.BlinkButton, { type: "primary", htmlType: "submit", ref: blinkRef, loading }, /* @__PURE__ */ React.createElement("span", null, "\u786E\u8BA4"))))
|
|
488
|
+
);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const FeatureFileFormat = ({ features, onChange, freeze, type }) => {
|
|
492
|
+
reactHooks.useMount(() => {
|
|
493
|
+
if (!features.fileFormat) onChange({ fileFormat: "image" });
|
|
494
|
+
});
|
|
495
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "fileFormat", name: "fileFormat", label: "\u9644\u4EF6\u683C\u5F0F" }, /* @__PURE__ */ React.createElement(
|
|
496
|
+
antd.Select,
|
|
497
|
+
{
|
|
498
|
+
style: { width: "100%" },
|
|
499
|
+
disabled: freeze || type === "update",
|
|
500
|
+
options: [
|
|
501
|
+
{
|
|
502
|
+
label: "\u56FE\u7247",
|
|
503
|
+
value: "image"
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
label: "\u6587\u6863",
|
|
507
|
+
value: "document"
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
label: "\u89C6\u9891",
|
|
511
|
+
value: "video"
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
}
|
|
515
|
+
));
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const FeaturePeople = ({ features, onChange }) => {
|
|
519
|
+
reactHooks.useMount(() => {
|
|
520
|
+
if (!features.allowMultiPeople) onChange({ allowMultiPeople: false });
|
|
521
|
+
});
|
|
522
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "allowMultiPeople", name: "allowMultiPeople", label: "\u5141\u8BB8\u6DFB\u52A0\u591A\u4E2A\u6210\u5458" }, /* @__PURE__ */ React.createElement(antd.Switch, null)));
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
const CustomDatePicker = ({ formatType = "YYYY-MM-DD", onChangeDate }) => {
|
|
526
|
+
const [showDatePicker, setShowDatePicker] = React.useState(false);
|
|
527
|
+
const { baseFormat, showGmt8 } = core.parseDateFormat(formatType);
|
|
528
|
+
const showTimeConfig = core.inferShowTimeFromFormat(baseFormat);
|
|
529
|
+
return /* @__PURE__ */ React.createElement(
|
|
530
|
+
antd.Popover,
|
|
531
|
+
{
|
|
532
|
+
trigger: "hover",
|
|
533
|
+
open: showDatePicker,
|
|
534
|
+
className: "date-panel-popover",
|
|
535
|
+
rootClassName: "date-panel-popover-root",
|
|
536
|
+
onOpenChange: setShowDatePicker,
|
|
537
|
+
placement: "right",
|
|
538
|
+
mouseEnterDelay: 0,
|
|
539
|
+
mouseLeaveDelay: 0.15,
|
|
540
|
+
content: /* @__PURE__ */ React.createElement(
|
|
541
|
+
antd.DatePicker,
|
|
542
|
+
{
|
|
543
|
+
style: { width: formatType?.includes("HH:mm") ? "401px" : "288px" },
|
|
544
|
+
className: "column-setting-date-picker",
|
|
545
|
+
format: (date) => {
|
|
546
|
+
if (!date) return "";
|
|
547
|
+
const text = date.format(baseFormat);
|
|
548
|
+
return showGmt8 ? `${text} (${core.TZ_LABEL})` : text;
|
|
549
|
+
},
|
|
550
|
+
showTime: showTimeConfig,
|
|
551
|
+
key: "datePicker",
|
|
552
|
+
autoFocus: true,
|
|
553
|
+
open: true,
|
|
554
|
+
placement: "topRight",
|
|
555
|
+
getPopupContainer: (trigger) => trigger,
|
|
556
|
+
onChange: (date) => {
|
|
557
|
+
if (date) {
|
|
558
|
+
onChangeDate(date.format(baseFormat));
|
|
559
|
+
}
|
|
560
|
+
setShowDatePicker(false);
|
|
561
|
+
},
|
|
562
|
+
onOk: (date) => {
|
|
563
|
+
if (date) {
|
|
564
|
+
onChangeDate(date.format(baseFormat));
|
|
565
|
+
}
|
|
566
|
+
setShowDatePicker(false);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
)
|
|
570
|
+
},
|
|
571
|
+
/* @__PURE__ */ React.createElement(
|
|
572
|
+
antd.Flex,
|
|
573
|
+
{
|
|
574
|
+
style: { width: "100%", height: 22 },
|
|
575
|
+
onClick: (e) => {
|
|
576
|
+
e.stopPropagation();
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
/* @__PURE__ */ React.createElement(antd.Flex, { style: { width: "100%", height: "100%" }, justify: "space-between" }, /* @__PURE__ */ React.createElement("div", null, "\u8BF7\u9009\u62E9\u5177\u4F53\u65E5\u671F"), /* @__PURE__ */ React.createElement(icons.RightOutlined, null))
|
|
580
|
+
)
|
|
581
|
+
);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const CREATE_DATE = "record_create_date";
|
|
585
|
+
const FeatureDefaultDate = ({ features, onChange }) => {
|
|
586
|
+
const formatType = features?.dateFormat || "YYYY/MM/DD";
|
|
587
|
+
const initialValue = features?.defaultValue;
|
|
588
|
+
const isCreateDate = initialValue === CREATE_DATE;
|
|
589
|
+
const [date, setDate] = React.useState(null);
|
|
590
|
+
const [value, setValue] = React.useState(void 0);
|
|
591
|
+
const [open, setOpen] = React.useState(false);
|
|
592
|
+
const { showGmt8, baseFormat } = core.parseDateFormat(formatType);
|
|
593
|
+
const debouncedOnChange = reactHooks.useDebounce(onChange);
|
|
594
|
+
const onChangeDate = React.useCallback(
|
|
595
|
+
(selected) => {
|
|
596
|
+
setDate(dayjs(selected));
|
|
597
|
+
setValue(selected);
|
|
598
|
+
setOpen(false);
|
|
599
|
+
debouncedOnChange({ defaultValue: selected });
|
|
600
|
+
},
|
|
601
|
+
[debouncedOnChange]
|
|
602
|
+
);
|
|
603
|
+
React.useEffect(() => {
|
|
604
|
+
if (isCreateDate) return;
|
|
605
|
+
let dateValue = "";
|
|
606
|
+
if (!date) {
|
|
607
|
+
const date2 = dayjs(initialValue + "");
|
|
608
|
+
dateValue = date2.format(baseFormat);
|
|
609
|
+
} else {
|
|
610
|
+
dateValue = date.format(baseFormat);
|
|
611
|
+
}
|
|
612
|
+
if (dateValue === "Invalid Date") {
|
|
613
|
+
onChange({ defaultValue: void 0 });
|
|
614
|
+
} else if (dateValue !== initialValue) {
|
|
615
|
+
onChange({ defaultValue: dateValue });
|
|
616
|
+
setValue(dateValue);
|
|
617
|
+
}
|
|
618
|
+
}, [baseFormat]);
|
|
619
|
+
const handleSelectChange = (value2) => {
|
|
620
|
+
if (value2 === CREATE_DATE) {
|
|
621
|
+
setValue(value2);
|
|
622
|
+
setOpen(false);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
React.useEffect(() => {
|
|
626
|
+
return () => {
|
|
627
|
+
onChange({ defaultValue: "" });
|
|
628
|
+
};
|
|
629
|
+
}, []);
|
|
630
|
+
return /* @__PURE__ */ React.createElement(proComponents.ProFormItem, { key: "defaultValue", name: "defaultValue", label: "\u9ED8\u8BA4\u503C" }, /* @__PURE__ */ React.createElement(
|
|
631
|
+
antd.Select,
|
|
632
|
+
{
|
|
633
|
+
style: { width: "100%" },
|
|
634
|
+
placeholder: "\u8BF7\u9009\u62E9\u65E5\u671F",
|
|
635
|
+
open,
|
|
636
|
+
value: showGmt8 && value ? value + ` (${core.TZ_LABEL})` : value,
|
|
637
|
+
onOpenChange: setOpen,
|
|
638
|
+
onChange: handleSelectChange,
|
|
639
|
+
options: [
|
|
640
|
+
{ label: "\u6DFB\u52A0\u65B0\u8BB0\u5F55\u7684\u521B\u5EFA\u65F6\u95F4", value: CREATE_DATE },
|
|
641
|
+
{ label: /* @__PURE__ */ React.createElement(CustomDatePicker, { onChangeDate, formatType }), value: "date_specific" }
|
|
642
|
+
]
|
|
643
|
+
}
|
|
644
|
+
));
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
dayjs.extend(utc);
|
|
648
|
+
dayjs.extend(timezone);
|
|
649
|
+
const getCurrentGMTLabel = () => {
|
|
650
|
+
const offsetMinutes = dayjs().utcOffset();
|
|
651
|
+
const offsetHours = offsetMinutes / 60;
|
|
652
|
+
return `GMT${offsetHours >= 0 ? "+" : ""}${offsetHours}`;
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const ColumnSettingModal = React.forwardRef(
|
|
656
|
+
({
|
|
657
|
+
selectProps,
|
|
658
|
+
columnId,
|
|
659
|
+
offsetParent,
|
|
660
|
+
width = 320,
|
|
661
|
+
isOpen = false,
|
|
662
|
+
position,
|
|
663
|
+
tools,
|
|
664
|
+
initValues,
|
|
665
|
+
className,
|
|
666
|
+
onClose,
|
|
667
|
+
onFinish,
|
|
668
|
+
onPositionChange,
|
|
669
|
+
contentRef,
|
|
670
|
+
bodyRef,
|
|
671
|
+
freeze
|
|
672
|
+
}, ref) => {
|
|
673
|
+
const formRef = React.useRef(null);
|
|
674
|
+
const onCancel = () => {
|
|
675
|
+
if (onClose) onClose();
|
|
676
|
+
};
|
|
677
|
+
React.useImperativeHandle(ref, () => {
|
|
678
|
+
return {
|
|
679
|
+
formRef: formRef.current
|
|
680
|
+
};
|
|
681
|
+
});
|
|
682
|
+
return /* @__PURE__ */ React.createElement(
|
|
683
|
+
baseModal.BaseModal,
|
|
684
|
+
{
|
|
685
|
+
offsetParent,
|
|
686
|
+
width,
|
|
687
|
+
open: isOpen,
|
|
688
|
+
onClose,
|
|
689
|
+
value: position,
|
|
690
|
+
onChange: onPositionChange,
|
|
691
|
+
className: `column-setting-modal ${className}`
|
|
692
|
+
},
|
|
693
|
+
/* @__PURE__ */ React.createElement(antd.Flex, { className: "field-form-container", onClick: (e) => e.stopPropagation(), ref: contentRef }, isOpen && /* @__PURE__ */ React.createElement(
|
|
694
|
+
ColumnFieldFrom,
|
|
695
|
+
{
|
|
696
|
+
bodyRef,
|
|
697
|
+
formRef,
|
|
698
|
+
columnId,
|
|
699
|
+
tools,
|
|
700
|
+
initValues,
|
|
701
|
+
onFinish: (values) => onFinish(values).then((success) => {
|
|
702
|
+
if (success && onClose) onClose();
|
|
703
|
+
return success;
|
|
704
|
+
}),
|
|
705
|
+
onCancel,
|
|
706
|
+
selectProps,
|
|
707
|
+
freeze
|
|
708
|
+
}
|
|
709
|
+
))
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
);
|
|
713
|
+
|
|
714
|
+
exports.ColumnFieldFrom = ColumnFieldFrom;
|
|
715
|
+
exports.ColumnSettingModal = ColumnSettingModal;
|
|
716
|
+
exports.CustomDatePicker = CustomDatePicker;
|
|
717
|
+
exports.CustomDatePickerV2 = CustomDatePickerV2;
|
|
718
|
+
exports.FeatureCustomOptions = FeatureCustomOptions;
|
|
719
|
+
exports.FeatureDateFormat = FeatureDateFormat;
|
|
720
|
+
exports.FeatureDefaultDate = FeatureDefaultDate;
|
|
721
|
+
exports.FeatureDefaultDateV2 = FeatureDefaultDateV2;
|
|
722
|
+
exports.FeatureDefaultField = FeatureDefaultField;
|
|
723
|
+
exports.FeatureDefaultInput = FeatureDefaultInput;
|
|
724
|
+
exports.FeatureDefaultJson = FeatureDefaultJson;
|
|
725
|
+
exports.FeatureDefaultNumber = FeatureDefaultNumber;
|
|
726
|
+
exports.FeatureDefaultSelect = FeatureDefaultSelect;
|
|
727
|
+
exports.FeatureField = FeatureField;
|
|
728
|
+
exports.FeatureFileFormat = FeatureFileFormat;
|
|
729
|
+
exports.FeatureInput = FeatureInput;
|
|
730
|
+
exports.FeatureNumberFormat = FeatureNumberFormat;
|
|
731
|
+
exports.FeaturePeople = FeaturePeople;
|
|
732
|
+
exports.FeatureTypeSelect = FeatureTypeSelect;
|
|
733
|
+
exports.getCurrentGMTLabel = getCurrentGMTLabel;
|