@rklink/components 0.1.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/README.md +23 -0
- package/dist/index.cjs +718 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.js +705 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
// src/RKConfirmAction/index.tsx
|
|
2
|
+
import { useRequest } from "ahooks";
|
|
3
|
+
import { Button, message, Modal } from "antd";
|
|
4
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var DEFAULT_FETCH_KEY = "RK_CONFIRM_DEFAULT";
|
|
7
|
+
function isResponseSuccess(result, successCode) {
|
|
8
|
+
if (result && typeof result === "object" && "code" in result) {
|
|
9
|
+
return result.code === successCode;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
function resolveConfirmConfig(confirm, params) {
|
|
14
|
+
if (typeof confirm === "function") {
|
|
15
|
+
return confirm(...params);
|
|
16
|
+
}
|
|
17
|
+
return confirm;
|
|
18
|
+
}
|
|
19
|
+
function resolveMessage(nextMessage, result, params) {
|
|
20
|
+
if (typeof nextMessage === "function") {
|
|
21
|
+
return nextMessage(result, ...params);
|
|
22
|
+
}
|
|
23
|
+
return nextMessage;
|
|
24
|
+
}
|
|
25
|
+
function resolveErrorMessage(errorMessage, error, params) {
|
|
26
|
+
if (typeof errorMessage === "function") {
|
|
27
|
+
return errorMessage(error, ...params);
|
|
28
|
+
}
|
|
29
|
+
return errorMessage;
|
|
30
|
+
}
|
|
31
|
+
function useRKConfirmRequest(options) {
|
|
32
|
+
const {
|
|
33
|
+
request,
|
|
34
|
+
confirm,
|
|
35
|
+
successMessage,
|
|
36
|
+
failureMessage,
|
|
37
|
+
errorMessage,
|
|
38
|
+
successCode = 200,
|
|
39
|
+
isSuccess,
|
|
40
|
+
getLoadingKey,
|
|
41
|
+
debounceInterval,
|
|
42
|
+
throttleInterval,
|
|
43
|
+
onSuccess,
|
|
44
|
+
onFailure,
|
|
45
|
+
onError,
|
|
46
|
+
onCancel
|
|
47
|
+
} = options;
|
|
48
|
+
const confirmOpenRef = useRef(false);
|
|
49
|
+
const [loadingKeys, setLoadingKeys] = useState({});
|
|
50
|
+
const { runAsync: requestRun, loading } = useRequest(request, {
|
|
51
|
+
manual: true,
|
|
52
|
+
debounceWait: debounceInterval,
|
|
53
|
+
throttleWait: throttleInterval
|
|
54
|
+
});
|
|
55
|
+
const setKeyLoading = useCallback((params, nextLoading) => {
|
|
56
|
+
const key = getLoadingKey == null ? void 0 : getLoadingKey(...params);
|
|
57
|
+
const loadingKey = key === void 0 ? DEFAULT_FETCH_KEY : String(key);
|
|
58
|
+
setLoadingKeys((prev) => ({
|
|
59
|
+
...prev,
|
|
60
|
+
[loadingKey]: nextLoading
|
|
61
|
+
}));
|
|
62
|
+
}, [getLoadingKey]);
|
|
63
|
+
const executeRequest = useCallback(
|
|
64
|
+
async (...params) => {
|
|
65
|
+
setKeyLoading(params, true);
|
|
66
|
+
try {
|
|
67
|
+
const result = await requestRun(...params);
|
|
68
|
+
const success = isSuccess ? isSuccess(result) : isResponseSuccess(result, successCode);
|
|
69
|
+
if (success) {
|
|
70
|
+
const nextSuccessMessage = resolveMessage(successMessage, result, params);
|
|
71
|
+
if (nextSuccessMessage) {
|
|
72
|
+
message.success(nextSuccessMessage);
|
|
73
|
+
}
|
|
74
|
+
await (onSuccess == null ? void 0 : onSuccess(result, ...params));
|
|
75
|
+
} else {
|
|
76
|
+
const nextFailureMessage = resolveMessage(failureMessage, result, params);
|
|
77
|
+
if (nextFailureMessage) {
|
|
78
|
+
message.error(nextFailureMessage);
|
|
79
|
+
}
|
|
80
|
+
await (onFailure == null ? void 0 : onFailure(result, ...params));
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const nextErrorMessage = resolveErrorMessage(errorMessage, error, params);
|
|
85
|
+
if (nextErrorMessage) {
|
|
86
|
+
message.error(nextErrorMessage);
|
|
87
|
+
}
|
|
88
|
+
await (onError == null ? void 0 : onError(error, ...params));
|
|
89
|
+
throw error;
|
|
90
|
+
} finally {
|
|
91
|
+
setKeyLoading(params, false);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[
|
|
95
|
+
errorMessage,
|
|
96
|
+
failureMessage,
|
|
97
|
+
isSuccess,
|
|
98
|
+
onError,
|
|
99
|
+
onFailure,
|
|
100
|
+
onSuccess,
|
|
101
|
+
requestRun,
|
|
102
|
+
setKeyLoading,
|
|
103
|
+
successCode,
|
|
104
|
+
successMessage
|
|
105
|
+
]
|
|
106
|
+
);
|
|
107
|
+
const run = useCallback(
|
|
108
|
+
(...params) => {
|
|
109
|
+
const confirmConfig = resolveConfirmConfig(confirm, params);
|
|
110
|
+
if (!confirmConfig) {
|
|
111
|
+
void executeRequest(...params);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (confirmOpenRef.current) return;
|
|
115
|
+
confirmOpenRef.current = true;
|
|
116
|
+
const { onOk, onCancel: onModalCancel, afterClose, ...restConfirmConfig } = confirmConfig;
|
|
117
|
+
Modal.confirm({
|
|
118
|
+
okText: "\u786E\u8BA4",
|
|
119
|
+
cancelText: "\u53D6\u6D88",
|
|
120
|
+
...restConfirmConfig,
|
|
121
|
+
onOk: async (...args) => {
|
|
122
|
+
const shouldContinue = await (onOk == null ? void 0 : onOk(...args));
|
|
123
|
+
if (shouldContinue === false) return false;
|
|
124
|
+
return executeRequest(...params);
|
|
125
|
+
},
|
|
126
|
+
onCancel: async (...args) => {
|
|
127
|
+
const shouldCancel = await (onModalCancel == null ? void 0 : onModalCancel(...args));
|
|
128
|
+
await (onCancel == null ? void 0 : onCancel(...params));
|
|
129
|
+
return shouldCancel;
|
|
130
|
+
},
|
|
131
|
+
afterClose: () => {
|
|
132
|
+
confirmOpenRef.current = false;
|
|
133
|
+
afterClose == null ? void 0 : afterClose();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
[confirm, executeRequest, onCancel]
|
|
138
|
+
);
|
|
139
|
+
const isLoading = useCallback(
|
|
140
|
+
(key) => {
|
|
141
|
+
if (key === void 0) return loading || !!loadingKeys[DEFAULT_FETCH_KEY];
|
|
142
|
+
return !!loadingKeys[String(key)];
|
|
143
|
+
},
|
|
144
|
+
[loading, loadingKeys]
|
|
145
|
+
);
|
|
146
|
+
return useMemo(
|
|
147
|
+
() => ({
|
|
148
|
+
run,
|
|
149
|
+
runRequest: executeRequest,
|
|
150
|
+
loading,
|
|
151
|
+
loadingKeys,
|
|
152
|
+
isLoading
|
|
153
|
+
}),
|
|
154
|
+
[executeRequest, isLoading, loading, loadingKeys, run]
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
var RKConfirmAction = ({
|
|
158
|
+
request,
|
|
159
|
+
confirm,
|
|
160
|
+
successMessage,
|
|
161
|
+
failureMessage,
|
|
162
|
+
errorMessage,
|
|
163
|
+
successCode,
|
|
164
|
+
isSuccess,
|
|
165
|
+
debounceInterval,
|
|
166
|
+
throttleInterval,
|
|
167
|
+
onSuccess,
|
|
168
|
+
onFailure,
|
|
169
|
+
onError,
|
|
170
|
+
onCancel,
|
|
171
|
+
stopPropagation = true,
|
|
172
|
+
children,
|
|
173
|
+
...buttonProps
|
|
174
|
+
}) => {
|
|
175
|
+
const { run, loading } = useRKConfirmRequest({
|
|
176
|
+
request,
|
|
177
|
+
confirm,
|
|
178
|
+
successMessage,
|
|
179
|
+
failureMessage,
|
|
180
|
+
errorMessage,
|
|
181
|
+
successCode,
|
|
182
|
+
isSuccess,
|
|
183
|
+
debounceInterval,
|
|
184
|
+
throttleInterval,
|
|
185
|
+
onSuccess,
|
|
186
|
+
onFailure,
|
|
187
|
+
onError,
|
|
188
|
+
onCancel
|
|
189
|
+
});
|
|
190
|
+
return /* @__PURE__ */ jsx(
|
|
191
|
+
Button,
|
|
192
|
+
{
|
|
193
|
+
type: "link",
|
|
194
|
+
...buttonProps,
|
|
195
|
+
loading,
|
|
196
|
+
onClick: (event) => {
|
|
197
|
+
if (stopPropagation) {
|
|
198
|
+
event.stopPropagation();
|
|
199
|
+
}
|
|
200
|
+
run();
|
|
201
|
+
},
|
|
202
|
+
children
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
var RKConfirmAction_default = RKConfirmAction;
|
|
207
|
+
|
|
208
|
+
// src/RKRemoteSelect/index.tsx
|
|
209
|
+
import { ProFormSelect } from "@ant-design/pro-components";
|
|
210
|
+
import { useMemo as useMemo2 } from "react";
|
|
211
|
+
|
|
212
|
+
// src/RKRemoteSelect/optionSourceRegistry.ts
|
|
213
|
+
var enumOptionSourceRegistry = {};
|
|
214
|
+
var remoteOptionSourceRegistry = {};
|
|
215
|
+
var enumOptionSourceOptions = [];
|
|
216
|
+
var remoteOptionSourceOptions = [];
|
|
217
|
+
function upsertOptionSourceDescriptor(list, descriptor) {
|
|
218
|
+
const index = list.findIndex((item) => item.value === descriptor.value);
|
|
219
|
+
if (index === -1) {
|
|
220
|
+
list.push(descriptor);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
list[index] = descriptor;
|
|
224
|
+
}
|
|
225
|
+
function registerRKRemoteSelectEnumOptionSource(key, options, descriptor) {
|
|
226
|
+
enumOptionSourceRegistry[key] = options;
|
|
227
|
+
upsertOptionSourceDescriptor(enumOptionSourceOptions, {
|
|
228
|
+
label: (descriptor == null ? void 0 : descriptor.label) || key,
|
|
229
|
+
value: key,
|
|
230
|
+
description: (descriptor == null ? void 0 : descriptor.description) || "",
|
|
231
|
+
sourceType: "enum"
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function registerRKRemoteSelectRemoteOptionSource(key, loader, descriptor) {
|
|
235
|
+
remoteOptionSourceRegistry[key] = loader;
|
|
236
|
+
upsertOptionSourceDescriptor(remoteOptionSourceOptions, {
|
|
237
|
+
label: (descriptor == null ? void 0 : descriptor.label) || key,
|
|
238
|
+
value: key,
|
|
239
|
+
description: (descriptor == null ? void 0 : descriptor.description) || "",
|
|
240
|
+
sourceType: "remote"
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function normalizeOptionLabel(value) {
|
|
244
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
if (typeof value === "boolean") {
|
|
248
|
+
return String(value);
|
|
249
|
+
}
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
252
|
+
function isOptionValue(value) {
|
|
253
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
254
|
+
}
|
|
255
|
+
function normalizeOptionItems(items, defaults, source) {
|
|
256
|
+
const labelField = (source == null ? void 0 : source.labelField) || (defaults == null ? void 0 : defaults.labelField) || "label";
|
|
257
|
+
const valueField = (source == null ? void 0 : source.valueField) || (defaults == null ? void 0 : defaults.valueField) || "value";
|
|
258
|
+
const childrenField = (source == null ? void 0 : source.childrenField) || (defaults == null ? void 0 : defaults.childrenField) || "children";
|
|
259
|
+
return items.map((item) => {
|
|
260
|
+
const label = normalizeOptionLabel(item[labelField]);
|
|
261
|
+
const value = item[valueField];
|
|
262
|
+
const children = item[childrenField];
|
|
263
|
+
if (label === void 0 || !isOptionValue(value)) {
|
|
264
|
+
return void 0;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
label,
|
|
268
|
+
value,
|
|
269
|
+
disabled: typeof item.disabled === "boolean" ? item.disabled : void 0,
|
|
270
|
+
children: Array.isArray(children) ? normalizeOptionItems(
|
|
271
|
+
children.filter(
|
|
272
|
+
(child) => typeof child === "object" && child !== null
|
|
273
|
+
),
|
|
274
|
+
defaults,
|
|
275
|
+
source
|
|
276
|
+
) : void 0
|
|
277
|
+
};
|
|
278
|
+
}).filter((item) => item !== void 0);
|
|
279
|
+
}
|
|
280
|
+
async function resolveRKRemoteSelectOptions(source) {
|
|
281
|
+
if (!(source == null ? void 0 : source.type) || !source.key) {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
if (source.type === "enum") {
|
|
285
|
+
return enumOptionSourceRegistry[source.key] || [];
|
|
286
|
+
}
|
|
287
|
+
if (source.type === "remote") {
|
|
288
|
+
const loader = remoteOptionSourceRegistry[source.key];
|
|
289
|
+
if (!loader) return [];
|
|
290
|
+
const result = await loader();
|
|
291
|
+
return normalizeOptionItems(result.items, result.defaults, source);
|
|
292
|
+
}
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/RKRemoteSelect/index.tsx
|
|
297
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
298
|
+
function isDynamicOptionSource(optionSource) {
|
|
299
|
+
return (optionSource == null ? void 0 : optionSource.type) === "enum" || (optionSource == null ? void 0 : optionSource.type) === "remote";
|
|
300
|
+
}
|
|
301
|
+
function resolveParams(optionSource, params) {
|
|
302
|
+
if (!isDynamicOptionSource(optionSource)) return params;
|
|
303
|
+
if (typeof params === "function") return params;
|
|
304
|
+
return {
|
|
305
|
+
...params,
|
|
306
|
+
...optionSource
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function isRecord(value) {
|
|
310
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
311
|
+
}
|
|
312
|
+
function isOptionValue2(value) {
|
|
313
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
314
|
+
}
|
|
315
|
+
function normalizeOptionLabel2(value) {
|
|
316
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
if (typeof value === "boolean") {
|
|
320
|
+
return String(value);
|
|
321
|
+
}
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
function resolveRequestApiItems(result) {
|
|
325
|
+
if (Array.isArray(result)) return result;
|
|
326
|
+
if (Array.isArray(result.data)) return result.data;
|
|
327
|
+
if (isRecord(result.data)) {
|
|
328
|
+
if (Array.isArray(result.data.records)) return result.data.records;
|
|
329
|
+
if (Array.isArray(result.data.list)) return result.data.list;
|
|
330
|
+
}
|
|
331
|
+
if (Array.isArray(result.records)) return result.records;
|
|
332
|
+
if (Array.isArray(result.list)) return result.list;
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
function normalizeSearchParams(params, searchKey = "keyWords") {
|
|
336
|
+
if (searchKey === "keyWords") return params;
|
|
337
|
+
const { keyWords, ...restParams } = params;
|
|
338
|
+
return {
|
|
339
|
+
...restParams,
|
|
340
|
+
...keyWords === void 0 ? {} : { [searchKey]: keyWords }
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function normalizeOptions(items, config) {
|
|
344
|
+
const labelField = config.labelField || "label";
|
|
345
|
+
const valueField = config.valueField || "value";
|
|
346
|
+
const childrenField = config.childrenField || "children";
|
|
347
|
+
return items.map((item) => {
|
|
348
|
+
const label = normalizeOptionLabel2(item[labelField]);
|
|
349
|
+
const value = item[valueField];
|
|
350
|
+
const children = item[childrenField];
|
|
351
|
+
if (label === void 0 || !isOptionValue2(value)) return void 0;
|
|
352
|
+
const optionDisabled = typeof config.disabled === "function" ? config.disabled(item) : typeof item.disabled === "boolean" ? item.disabled : void 0;
|
|
353
|
+
return {
|
|
354
|
+
...item,
|
|
355
|
+
label,
|
|
356
|
+
value,
|
|
357
|
+
disabled: optionDisabled,
|
|
358
|
+
children: Array.isArray(children) ? normalizeOptions(
|
|
359
|
+
children.filter(isRecord),
|
|
360
|
+
config
|
|
361
|
+
) : void 0
|
|
362
|
+
};
|
|
363
|
+
}).filter((item) => item !== void 0);
|
|
364
|
+
}
|
|
365
|
+
function shouldNormalizeOptions(options, config) {
|
|
366
|
+
return Array.isArray(options) && options.every(isRecord) && (!!config.labelField || !!config.valueField || !!config.childrenField || typeof config.disabled === "function");
|
|
367
|
+
}
|
|
368
|
+
function RKRemoteSelect({
|
|
369
|
+
optionSource,
|
|
370
|
+
options,
|
|
371
|
+
requestApi,
|
|
372
|
+
request,
|
|
373
|
+
params,
|
|
374
|
+
fieldProps,
|
|
375
|
+
showSearch = true,
|
|
376
|
+
labelField,
|
|
377
|
+
valueField,
|
|
378
|
+
childrenField,
|
|
379
|
+
disabled,
|
|
380
|
+
searchKey = "keyWords",
|
|
381
|
+
...restProps
|
|
382
|
+
}) {
|
|
383
|
+
const selectDisabled = typeof disabled === "boolean" ? disabled : void 0;
|
|
384
|
+
const optionConfig = useMemo2(
|
|
385
|
+
() => ({
|
|
386
|
+
labelField,
|
|
387
|
+
valueField,
|
|
388
|
+
childrenField,
|
|
389
|
+
disabled
|
|
390
|
+
}),
|
|
391
|
+
[childrenField, disabled, labelField, valueField]
|
|
392
|
+
);
|
|
393
|
+
const selectOptions = useMemo2(() => {
|
|
394
|
+
if (!shouldNormalizeOptions(options, optionConfig)) {
|
|
395
|
+
return options;
|
|
396
|
+
}
|
|
397
|
+
return normalizeOptions(
|
|
398
|
+
options,
|
|
399
|
+
optionConfig
|
|
400
|
+
);
|
|
401
|
+
}, [optionConfig, options]);
|
|
402
|
+
const selectRequest = useMemo2(() => {
|
|
403
|
+
if (isDynamicOptionSource(optionSource)) {
|
|
404
|
+
return async () => resolveRKRemoteSelectOptions(optionSource);
|
|
405
|
+
}
|
|
406
|
+
if (requestApi) {
|
|
407
|
+
return async (requestParams2) => {
|
|
408
|
+
const result = await requestApi(normalizeSearchParams(requestParams2, searchKey));
|
|
409
|
+
return normalizeOptions(resolveRequestApiItems(result), optionConfig);
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return request;
|
|
413
|
+
}, [optionConfig, optionSource, request, requestApi, searchKey]);
|
|
414
|
+
const requestParams = useMemo2(() => resolveParams(optionSource, params), [optionSource, params]);
|
|
415
|
+
return /* @__PURE__ */ jsx2(
|
|
416
|
+
ProFormSelect,
|
|
417
|
+
{
|
|
418
|
+
...restProps,
|
|
419
|
+
disabled: selectDisabled,
|
|
420
|
+
showSearch,
|
|
421
|
+
options: selectOptions,
|
|
422
|
+
request: selectRequest,
|
|
423
|
+
params: requestParams,
|
|
424
|
+
fieldProps: {
|
|
425
|
+
optionFilterProp: "label",
|
|
426
|
+
filterOption: true,
|
|
427
|
+
...fieldProps
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/RKSchemaForm/index.tsx
|
|
434
|
+
import { ProForm } from "@ant-design/pro-components";
|
|
435
|
+
|
|
436
|
+
// src/RKSchemaForm/fieldRegistry.tsx
|
|
437
|
+
import {
|
|
438
|
+
ProFormCascader,
|
|
439
|
+
ProFormCheckbox,
|
|
440
|
+
ProFormColorPicker,
|
|
441
|
+
ProFormDateMonthRangePicker,
|
|
442
|
+
ProFormDatePicker,
|
|
443
|
+
ProFormDateQuarterRangePicker,
|
|
444
|
+
ProFormDateRangePicker,
|
|
445
|
+
ProFormDateTimePicker,
|
|
446
|
+
ProFormDateTimeRangePicker,
|
|
447
|
+
ProFormDateWeekRangePicker,
|
|
448
|
+
ProFormDateYearRangePicker,
|
|
449
|
+
ProFormDigit,
|
|
450
|
+
ProFormDigitRange,
|
|
451
|
+
ProFormMoney,
|
|
452
|
+
ProFormRadio,
|
|
453
|
+
ProFormRate,
|
|
454
|
+
ProFormSegmented,
|
|
455
|
+
ProFormSelect as ProFormSelect2,
|
|
456
|
+
ProFormSlider,
|
|
457
|
+
ProFormSwitch,
|
|
458
|
+
ProFormText,
|
|
459
|
+
ProFormTextArea,
|
|
460
|
+
ProFormTimePicker,
|
|
461
|
+
ProFormTreeSelect,
|
|
462
|
+
ProFormUploadButton,
|
|
463
|
+
ProFormUploadDragger
|
|
464
|
+
} from "@ant-design/pro-components";
|
|
465
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
466
|
+
function isFieldComponentProps(value) {
|
|
467
|
+
return typeof value === "object" && value !== null;
|
|
468
|
+
}
|
|
469
|
+
function isDynamicOptionSource2(source) {
|
|
470
|
+
return ["enum", "remote"].includes((source == null ? void 0 : source.type) || "");
|
|
471
|
+
}
|
|
472
|
+
function getStaticOptions(fieldProps, optionFieldName) {
|
|
473
|
+
if (optionFieldName === "treeData") {
|
|
474
|
+
return fieldProps.treeData || fieldProps.options;
|
|
475
|
+
}
|
|
476
|
+
return fieldProps.options;
|
|
477
|
+
}
|
|
478
|
+
function asField(component) {
|
|
479
|
+
return component;
|
|
480
|
+
}
|
|
481
|
+
function createOptionField(Component, options = {}) {
|
|
482
|
+
const { optionFieldName = "options" } = options;
|
|
483
|
+
return function RKSchemaOptionsField(props) {
|
|
484
|
+
const fieldProps = isFieldComponentProps(props.fieldProps) ? props.fieldProps : {};
|
|
485
|
+
const { options: staticOptions, treeData, optionSource, ...restFieldProps } = fieldProps;
|
|
486
|
+
const shouldLoadDynamic = isDynamicOptionSource2(optionSource);
|
|
487
|
+
const resolvedStaticOptions = getStaticOptions({ ...fieldProps, options: staticOptions, treeData }, optionFieldName) || [];
|
|
488
|
+
const request = shouldLoadDynamic ? async () => resolveRKRemoteSelectOptions(optionSource) : void 0;
|
|
489
|
+
return /* @__PURE__ */ jsx3(
|
|
490
|
+
Component,
|
|
491
|
+
{
|
|
492
|
+
...props,
|
|
493
|
+
request: request || props.request,
|
|
494
|
+
params: shouldLoadDynamic ? optionSource : props.params,
|
|
495
|
+
fieldProps: {
|
|
496
|
+
...restFieldProps,
|
|
497
|
+
[optionFieldName]: shouldLoadDynamic ? void 0 : resolvedStaticOptions
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
);
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
var RKSchemaFieldRegistry = {
|
|
504
|
+
text: asField(ProFormText),
|
|
505
|
+
password: asField(ProFormText.Password),
|
|
506
|
+
textarea: asField(ProFormTextArea),
|
|
507
|
+
digit: asField(ProFormDigit),
|
|
508
|
+
digitRange: asField(ProFormDigitRange),
|
|
509
|
+
select: createOptionField(asField(ProFormSelect2)),
|
|
510
|
+
treeSelect: createOptionField(asField(ProFormTreeSelect), { optionFieldName: "treeData" }),
|
|
511
|
+
cascader: createOptionField(asField(ProFormCascader)),
|
|
512
|
+
radio: createOptionField(asField(ProFormRadio.Group)),
|
|
513
|
+
checkbox: asField(ProFormCheckbox),
|
|
514
|
+
checkboxGroup: createOptionField(asField(ProFormCheckbox.Group)),
|
|
515
|
+
switch: asField(ProFormSwitch),
|
|
516
|
+
slider: asField(ProFormSlider),
|
|
517
|
+
rate: asField(ProFormRate),
|
|
518
|
+
segmented: createOptionField(asField(ProFormSegmented)),
|
|
519
|
+
color: asField(ProFormColorPicker),
|
|
520
|
+
date: asField(ProFormDatePicker),
|
|
521
|
+
dateRange: asField(ProFormDateRangePicker),
|
|
522
|
+
dateTime: asField(ProFormDateTimePicker),
|
|
523
|
+
dateTimeRange: asField(ProFormDateTimeRangePicker),
|
|
524
|
+
dateWeekRange: asField(ProFormDateWeekRangePicker),
|
|
525
|
+
dateMonthRange: asField(ProFormDateMonthRangePicker),
|
|
526
|
+
dateQuarterRange: asField(ProFormDateQuarterRangePicker),
|
|
527
|
+
dateYearRange: asField(ProFormDateYearRangePicker),
|
|
528
|
+
time: asField(ProFormTimePicker),
|
|
529
|
+
timeRange: asField(ProFormTimePicker.RangePicker),
|
|
530
|
+
money: asField(ProFormMoney),
|
|
531
|
+
uploadButton: asField(ProFormUploadButton),
|
|
532
|
+
uploadDragger: asField(ProFormUploadDragger)
|
|
533
|
+
};
|
|
534
|
+
function registerRKSchemaField(valueType, renderer) {
|
|
535
|
+
RKSchemaFieldRegistry[valueType] = renderer;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/RKSchemaForm/index.tsx
|
|
539
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
540
|
+
var requiredRule = {
|
|
541
|
+
required: true,
|
|
542
|
+
message: "\u6B64\u9879\u4E3A\u5FC5\u586B\u9879"
|
|
543
|
+
};
|
|
544
|
+
function getColProps(columns) {
|
|
545
|
+
switch (columns) {
|
|
546
|
+
case 1:
|
|
547
|
+
return { span: 24 };
|
|
548
|
+
case 2:
|
|
549
|
+
return { lg: 12, md: 12, sm: 24 };
|
|
550
|
+
case 3:
|
|
551
|
+
return { lg: 8, md: 12, sm: 24 };
|
|
552
|
+
case 6:
|
|
553
|
+
return { lg: 4, md: 6, sm: 12 };
|
|
554
|
+
case 4:
|
|
555
|
+
default:
|
|
556
|
+
return { lg: 6, md: 8, sm: 12 };
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
function RKSchemaForm(props) {
|
|
560
|
+
const { columns, columnCount, fieldColProps, rowProps, ...formProps } = props;
|
|
561
|
+
const defaultColProps = fieldColProps || getColProps(columnCount);
|
|
562
|
+
return /* @__PURE__ */ jsx4(ProForm, { grid: true, rowProps: { gutter: 24, ...rowProps }, ...formProps, children: columns.map((column, index) => {
|
|
563
|
+
if (column.hidden === true) return null;
|
|
564
|
+
const {
|
|
565
|
+
key,
|
|
566
|
+
title,
|
|
567
|
+
dataIndex,
|
|
568
|
+
valueType = "text",
|
|
569
|
+
required,
|
|
570
|
+
disabled,
|
|
571
|
+
readonly,
|
|
572
|
+
initialValue,
|
|
573
|
+
rules,
|
|
574
|
+
tooltip,
|
|
575
|
+
extra,
|
|
576
|
+
colProps,
|
|
577
|
+
fieldProps
|
|
578
|
+
} = column;
|
|
579
|
+
const Component = RKSchemaFieldRegistry[valueType];
|
|
580
|
+
if (!Component) return null;
|
|
581
|
+
return /* @__PURE__ */ jsx4(
|
|
582
|
+
Component,
|
|
583
|
+
{
|
|
584
|
+
label: title,
|
|
585
|
+
name: dataIndex,
|
|
586
|
+
disabled,
|
|
587
|
+
readonly,
|
|
588
|
+
initialValue,
|
|
589
|
+
rules: [...required === true ? [requiredRule] : [], ...rules || []],
|
|
590
|
+
tooltip,
|
|
591
|
+
extra,
|
|
592
|
+
colProps: colProps || defaultColProps,
|
|
593
|
+
fieldProps
|
|
594
|
+
},
|
|
595
|
+
key || `${String(dataIndex)}-${index}`
|
|
596
|
+
);
|
|
597
|
+
}) });
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/RKTable/index.tsx
|
|
601
|
+
import { ProTable } from "@ant-design/pro-components";
|
|
602
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
603
|
+
function resolveRecords(response) {
|
|
604
|
+
if (Array.isArray(response.data)) return response.data;
|
|
605
|
+
if (response.data && typeof response.data === "object") {
|
|
606
|
+
if (Array.isArray(response.data.records)) return response.data.records;
|
|
607
|
+
if (Array.isArray(response.data.list)) return response.data.list;
|
|
608
|
+
}
|
|
609
|
+
if (Array.isArray(response.records)) return response.records;
|
|
610
|
+
if (Array.isArray(response.list)) return response.list;
|
|
611
|
+
return [];
|
|
612
|
+
}
|
|
613
|
+
function resolveTotal(response) {
|
|
614
|
+
if (typeof response.total === "number") return response.total;
|
|
615
|
+
if (response.data && !Array.isArray(response.data) && typeof response.data.total === "number") {
|
|
616
|
+
return response.data.total;
|
|
617
|
+
}
|
|
618
|
+
return resolveRecords(response).length;
|
|
619
|
+
}
|
|
620
|
+
function defaultRequestAdapter(response) {
|
|
621
|
+
const success = typeof response.success === "boolean" ? response.success : response.code === void 0 || response.code === 200;
|
|
622
|
+
return {
|
|
623
|
+
data: resolveRecords(response),
|
|
624
|
+
success,
|
|
625
|
+
total: resolveTotal(response)
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
var RKTable = ({
|
|
629
|
+
request,
|
|
630
|
+
requestApi,
|
|
631
|
+
requestAdapter = defaultRequestAdapter,
|
|
632
|
+
requestParamsFormatter,
|
|
633
|
+
search,
|
|
634
|
+
options,
|
|
635
|
+
pagination,
|
|
636
|
+
scroll,
|
|
637
|
+
form,
|
|
638
|
+
rowKey,
|
|
639
|
+
tableAlertRender,
|
|
640
|
+
...restProps
|
|
641
|
+
}) => {
|
|
642
|
+
const tableSearch = search === false ? false : {
|
|
643
|
+
filterType: "query",
|
|
644
|
+
defaultCollapsed: false,
|
|
645
|
+
...typeof search === "object" ? search : {}
|
|
646
|
+
};
|
|
647
|
+
const tableOptions = options === false ? false : {
|
|
648
|
+
reload: true,
|
|
649
|
+
density: false,
|
|
650
|
+
setting: false,
|
|
651
|
+
...typeof options === "object" ? options : {}
|
|
652
|
+
};
|
|
653
|
+
const tablePagination = pagination === false ? false : {
|
|
654
|
+
defaultPageSize: 20,
|
|
655
|
+
showSizeChanger: true,
|
|
656
|
+
disabled: false,
|
|
657
|
+
...typeof pagination === "object" ? pagination : {}
|
|
658
|
+
};
|
|
659
|
+
const tableForm = {
|
|
660
|
+
syncToUrl: true,
|
|
661
|
+
syncToInitialValues: false,
|
|
662
|
+
...typeof form === "object" ? form : {}
|
|
663
|
+
};
|
|
664
|
+
const tableScroll = {
|
|
665
|
+
x: "max-content",
|
|
666
|
+
...typeof scroll === "object" ? scroll : {}
|
|
667
|
+
};
|
|
668
|
+
const tableRequest = requestApi ? async (params, sort, filter) => {
|
|
669
|
+
const nextParams = requestParamsFormatter ? requestParamsFormatter(params, sort, filter) : params;
|
|
670
|
+
const response = await requestApi(nextParams);
|
|
671
|
+
return requestAdapter(response);
|
|
672
|
+
} : request;
|
|
673
|
+
return /* @__PURE__ */ jsx5(
|
|
674
|
+
ProTable,
|
|
675
|
+
{
|
|
676
|
+
rowKey: rowKey || "id",
|
|
677
|
+
tableAlertRender: tableAlertRender != null ? tableAlertRender : false,
|
|
678
|
+
options: tableOptions,
|
|
679
|
+
pagination: tablePagination,
|
|
680
|
+
scroll: tableScroll,
|
|
681
|
+
form: tableForm,
|
|
682
|
+
...restProps,
|
|
683
|
+
search: tableSearch,
|
|
684
|
+
request: tableRequest
|
|
685
|
+
}
|
|
686
|
+
);
|
|
687
|
+
};
|
|
688
|
+
var RKTable_default = RKTable;
|
|
689
|
+
export {
|
|
690
|
+
RKConfirmAction_default as RKConfirmAction,
|
|
691
|
+
RKRemoteSelect,
|
|
692
|
+
RKSchemaForm,
|
|
693
|
+
RKTable_default as RKTable,
|
|
694
|
+
enumOptionSourceOptions,
|
|
695
|
+
registerRKRemoteSelectEnumOptionSource,
|
|
696
|
+
registerRKRemoteSelectRemoteOptionSource,
|
|
697
|
+
registerRKRemoteSelectEnumOptionSource as registerRKSchemaEnumOptionSource,
|
|
698
|
+
registerRKSchemaField,
|
|
699
|
+
registerRKRemoteSelectRemoteOptionSource as registerRKSchemaRemoteOptionSource,
|
|
700
|
+
remoteOptionSourceOptions,
|
|
701
|
+
resolveRKRemoteSelectOptions,
|
|
702
|
+
resolveRKRemoteSelectOptions as resolveRKSchemaOptions,
|
|
703
|
+
useRKConfirmRequest
|
|
704
|
+
};
|
|
705
|
+
//# sourceMappingURL=index.js.map
|