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