@easy-editor/setters 0.1.2 → 0.1.4

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.esm.js DELETED
@@ -1,3321 +0,0 @@
1
- import React$1, { useRef, useState, useEffect, forwardRef, createElement, useCallback, useMemo, Fragment } from 'react';
2
- import { createPortal } from 'react-dom';
3
- import { jsx, jsxs } from 'react/jsx-runtime';
4
-
5
- /**
6
- * Popover - 共享弹窗组件
7
- * - 使用 Portal 渲染到 document.body,避免被父容器遮挡
8
- * - 自动匹配触发器宽度
9
- */
10
- const Popover = props => {
11
- const {
12
- open,
13
- onClose,
14
- trigger,
15
- children,
16
- width = 'trigger'
17
- } = props;
18
- const triggerRef = useRef(null);
19
- const [position, setPosition] = useState({
20
- top: 0,
21
- left: 0
22
- });
23
- const [popoverWidth, setPopoverWidth] = useState(0);
24
-
25
- // 计算弹窗位置
26
- useEffect(() => {
27
- if (open && triggerRef.current) {
28
- const triggerRect = triggerRef.current.getBoundingClientRect();
29
- const triggerWidth = triggerRect.width;
30
-
31
- // 设置弹窗宽度
32
- if (width === 'trigger') {
33
- setPopoverWidth(triggerWidth);
34
- }
35
- setPosition({
36
- top: triggerRect.bottom + 4,
37
- left: triggerRect.left
38
- });
39
- }
40
- }, [open, width]);
41
-
42
- // 点击外部关闭
43
- useEffect(() => {
44
- const handleClickOutside = event => {
45
- const target = event.target;
46
- const popoverEl = document.querySelector('.es-popover-portal');
47
- if (popoverEl && !popoverEl.contains(target) && triggerRef.current && !triggerRef.current.contains(target)) {
48
- onClose();
49
- }
50
- };
51
- if (open) {
52
- document.addEventListener('mousedown', handleClickOutside);
53
- return () => document.removeEventListener('mousedown', handleClickOutside);
54
- }
55
- }, [open, onClose]);
56
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
57
- ref: triggerRef
58
- }, trigger), open ? /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", {
59
- className: "es-popover-portal",
60
- style: {
61
- position: 'fixed',
62
- top: position.top,
63
- left: position.left,
64
- width: popoverWidth || 'auto',
65
- zIndex: 1000
66
- }
67
- }, children), document.body) : '');
68
- };
69
-
70
- function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
71
-
72
- function cn(...inputs) {
73
- return clsx(inputs);
74
- }
75
-
76
- /**
77
- * @license lucide-react v0.561.0 - ISC
78
- *
79
- * This source code is licensed under the ISC license.
80
- * See the LICENSE file in the root directory of this source tree.
81
- */
82
- const toKebabCase = string => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
83
- const toCamelCase = string => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
84
- const toPascalCase = string => {
85
- const camelCase = toCamelCase(string);
86
- return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
87
- };
88
- const mergeClasses = (...classes) => classes.filter((className, index, array) => {
89
- return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
90
- }).join(" ").trim();
91
- const hasA11yProp = props => {
92
- for (const prop in props) {
93
- if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
94
- return true;
95
- }
96
- }
97
- };
98
-
99
- /**
100
- * @license lucide-react v0.561.0 - ISC
101
- *
102
- * This source code is licensed under the ISC license.
103
- * See the LICENSE file in the root directory of this source tree.
104
- */
105
- var defaultAttributes = {
106
- xmlns: "http://www.w3.org/2000/svg",
107
- width: 24,
108
- height: 24,
109
- viewBox: "0 0 24 24",
110
- fill: "none",
111
- stroke: "currentColor",
112
- strokeWidth: 2,
113
- strokeLinecap: "round",
114
- strokeLinejoin: "round"
115
- };
116
-
117
- /**
118
- * @license lucide-react v0.561.0 - ISC
119
- *
120
- * This source code is licensed under the ISC license.
121
- * See the LICENSE file in the root directory of this source tree.
122
- */
123
- const Icon = /*#__PURE__*/forwardRef(({
124
- color = "currentColor",
125
- size = 24,
126
- strokeWidth = 2,
127
- absoluteStrokeWidth,
128
- className = "",
129
- children,
130
- iconNode,
131
- ...rest
132
- }, ref) => /*#__PURE__*/createElement("svg", {
133
- ref,
134
- ...defaultAttributes,
135
- width: size,
136
- height: size,
137
- stroke: color,
138
- strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
139
- className: mergeClasses("lucide", className),
140
- ...(!children && !hasA11yProp(rest) && {
141
- "aria-hidden": "true"
142
- }),
143
- ...rest
144
- }, [...iconNode.map(([tag, attrs]) => /*#__PURE__*/createElement(tag, attrs)), ...(Array.isArray(children) ? children : [children])]));
145
-
146
- /**
147
- * @license lucide-react v0.561.0 - ISC
148
- *
149
- * This source code is licensed under the ISC license.
150
- * See the LICENSE file in the root directory of this source tree.
151
- */
152
- const createLucideIcon = (iconName, iconNode) => {
153
- const Component = /*#__PURE__*/forwardRef(({
154
- className,
155
- ...props
156
- }, ref) => /*#__PURE__*/createElement(Icon, {
157
- ref,
158
- iconNode,
159
- className: mergeClasses(`lucide-${toKebabCase(toPascalCase(iconName))}`, `lucide-${iconName}`, className),
160
- ...props
161
- }));
162
- Component.displayName = toPascalCase(iconName);
163
- return Component;
164
- };
165
-
166
- /**
167
- * @license lucide-react v0.561.0 - ISC
168
- *
169
- * This source code is licensed under the ISC license.
170
- * See the LICENSE file in the root directory of this source tree.
171
- */
172
- const __iconNode$m = [["rect", {
173
- width: "6",
174
- height: "16",
175
- x: "4",
176
- y: "2",
177
- rx: "2",
178
- key: "z5wdxg"
179
- }], ["rect", {
180
- width: "6",
181
- height: "9",
182
- x: "14",
183
- y: "9",
184
- rx: "2",
185
- key: "um7a8w"
186
- }], ["path", {
187
- d: "M22 22H2",
188
- key: "19qnx5"
189
- }]];
190
- const AlignEndHorizontal = createLucideIcon("align-end-horizontal", __iconNode$m);
191
-
192
- /**
193
- * @license lucide-react v0.561.0 - ISC
194
- *
195
- * This source code is licensed under the ISC license.
196
- * See the LICENSE file in the root directory of this source tree.
197
- */
198
- const __iconNode$l = [["rect", {
199
- width: "16",
200
- height: "6",
201
- x: "2",
202
- y: "4",
203
- rx: "2",
204
- key: "10wcwx"
205
- }], ["rect", {
206
- width: "9",
207
- height: "6",
208
- x: "9",
209
- y: "14",
210
- rx: "2",
211
- key: "4p5bwg"
212
- }], ["path", {
213
- d: "M22 22V2",
214
- key: "12ipfv"
215
- }]];
216
- const AlignEndVertical = createLucideIcon("align-end-vertical", __iconNode$l);
217
-
218
- /**
219
- * @license lucide-react v0.561.0 - ISC
220
- *
221
- * This source code is licensed under the ISC license.
222
- * See the LICENSE file in the root directory of this source tree.
223
- */
224
- const __iconNode$k = [["rect", {
225
- width: "6",
226
- height: "14",
227
- x: "4",
228
- y: "5",
229
- rx: "2",
230
- key: "1wwnby"
231
- }], ["rect", {
232
- width: "6",
233
- height: "10",
234
- x: "14",
235
- y: "7",
236
- rx: "2",
237
- key: "1fe6j6"
238
- }], ["path", {
239
- d: "M17 22v-5",
240
- key: "4b6g73"
241
- }], ["path", {
242
- d: "M17 7V2",
243
- key: "hnrr36"
244
- }], ["path", {
245
- d: "M7 22v-3",
246
- key: "1r4jpn"
247
- }], ["path", {
248
- d: "M7 5V2",
249
- key: "liy1u9"
250
- }]];
251
- const AlignHorizontalDistributeCenter = createLucideIcon("align-horizontal-distribute-center", __iconNode$k);
252
-
253
- /**
254
- * @license lucide-react v0.561.0 - ISC
255
- *
256
- * This source code is licensed under the ISC license.
257
- * See the LICENSE file in the root directory of this source tree.
258
- */
259
- const __iconNode$j = [["rect", {
260
- width: "6",
261
- height: "16",
262
- x: "4",
263
- y: "6",
264
- rx: "2",
265
- key: "1n4dg1"
266
- }], ["rect", {
267
- width: "6",
268
- height: "9",
269
- x: "14",
270
- y: "6",
271
- rx: "2",
272
- key: "17khns"
273
- }], ["path", {
274
- d: "M22 2H2",
275
- key: "fhrpnj"
276
- }]];
277
- const AlignStartHorizontal = createLucideIcon("align-start-horizontal", __iconNode$j);
278
-
279
- /**
280
- * @license lucide-react v0.561.0 - ISC
281
- *
282
- * This source code is licensed under the ISC license.
283
- * See the LICENSE file in the root directory of this source tree.
284
- */
285
- const __iconNode$i = [["rect", {
286
- width: "9",
287
- height: "6",
288
- x: "6",
289
- y: "14",
290
- rx: "2",
291
- key: "lpm2y7"
292
- }], ["rect", {
293
- width: "16",
294
- height: "6",
295
- x: "6",
296
- y: "4",
297
- rx: "2",
298
- key: "rdj6ps"
299
- }], ["path", {
300
- d: "M2 2v20",
301
- key: "1ivd8o"
302
- }]];
303
- const AlignStartVertical = createLucideIcon("align-start-vertical", __iconNode$i);
304
-
305
- /**
306
- * @license lucide-react v0.561.0 - ISC
307
- *
308
- * This source code is licensed under the ISC license.
309
- * See the LICENSE file in the root directory of this source tree.
310
- */
311
- const __iconNode$h = [["path", {
312
- d: "M22 17h-3",
313
- key: "1lwga1"
314
- }], ["path", {
315
- d: "M22 7h-5",
316
- key: "o2endc"
317
- }], ["path", {
318
- d: "M5 17H2",
319
- key: "1gx9xc"
320
- }], ["path", {
321
- d: "M7 7H2",
322
- key: "6bq26l"
323
- }], ["rect", {
324
- x: "5",
325
- y: "14",
326
- width: "14",
327
- height: "6",
328
- rx: "2",
329
- key: "1qrzuf"
330
- }], ["rect", {
331
- x: "7",
332
- y: "4",
333
- width: "10",
334
- height: "6",
335
- rx: "2",
336
- key: "we8e9z"
337
- }]];
338
- const AlignVerticalDistributeCenter = createLucideIcon("align-vertical-distribute-center", __iconNode$h);
339
-
340
- /**
341
- * @license lucide-react v0.561.0 - ISC
342
- *
343
- * This source code is licensed under the ISC license.
344
- * See the LICENSE file in the root directory of this source tree.
345
- */
346
- const __iconNode$g = [["path", {
347
- d: "M5 12h14",
348
- key: "1ays0h"
349
- }], ["path", {
350
- d: "m12 5 7 7-7 7",
351
- key: "xquz4c"
352
- }]];
353
- const ArrowRight = createLucideIcon("arrow-right", __iconNode$g);
354
-
355
- /**
356
- * @license lucide-react v0.561.0 - ISC
357
- *
358
- * This source code is licensed under the ISC license.
359
- * See the LICENSE file in the root directory of this source tree.
360
- */
361
- const __iconNode$f = [["path", {
362
- d: "M20 6 9 17l-5-5",
363
- key: "1gmf2c"
364
- }]];
365
- const Check = createLucideIcon("check", __iconNode$f);
366
-
367
- /**
368
- * @license lucide-react v0.561.0 - ISC
369
- *
370
- * This source code is licensed under the ISC license.
371
- * See the LICENSE file in the root directory of this source tree.
372
- */
373
- const __iconNode$e = [["path", {
374
- d: "m6 9 6 6 6-6",
375
- key: "qrunsl"
376
- }]];
377
- const ChevronDown = createLucideIcon("chevron-down", __iconNode$e);
378
-
379
- /**
380
- * @license lucide-react v0.561.0 - ISC
381
- *
382
- * This source code is licensed under the ISC license.
383
- * See the LICENSE file in the root directory of this source tree.
384
- */
385
- const __iconNode$d = [["path", {
386
- d: "m7 15 5 5 5-5",
387
- key: "1hf1tw"
388
- }], ["path", {
389
- d: "m7 9 5-5 5 5",
390
- key: "sgt6xg"
391
- }]];
392
- const ChevronsUpDown = createLucideIcon("chevrons-up-down", __iconNode$d);
393
-
394
- /**
395
- * @license lucide-react v0.561.0 - ISC
396
- *
397
- * This source code is licensed under the ISC license.
398
- * See the LICENSE file in the root directory of this source tree.
399
- */
400
- const __iconNode$c = [["path", {
401
- d: "m16 18 6-6-6-6",
402
- key: "eg8j8"
403
- }], ["path", {
404
- d: "m8 6-6 6 6 6",
405
- key: "ppft3o"
406
- }]];
407
- const Code = createLucideIcon("code", __iconNode$c);
408
-
409
- /**
410
- * @license lucide-react v0.561.0 - ISC
411
- *
412
- * This source code is licensed under the ISC license.
413
- * See the LICENSE file in the root directory of this source tree.
414
- */
415
- const __iconNode$b = [["ellipse", {
416
- cx: "12",
417
- cy: "5",
418
- rx: "9",
419
- ry: "3",
420
- key: "msslwz"
421
- }], ["path", {
422
- d: "M3 5V19A9 3 0 0 0 21 19V5",
423
- key: "1wlel7"
424
- }], ["path", {
425
- d: "M3 12A9 3 0 0 0 21 12",
426
- key: "mv7ke4"
427
- }]];
428
- const Database = createLucideIcon("database", __iconNode$b);
429
-
430
- /**
431
- * @license lucide-react v0.561.0 - ISC
432
- *
433
- * This source code is licensed under the ISC license.
434
- * See the LICENSE file in the root directory of this source tree.
435
- */
436
- const __iconNode$a = [["path", {
437
- d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
438
- key: "1oefj6"
439
- }], ["path", {
440
- d: "M14 2v5a1 1 0 0 0 1 1h5",
441
- key: "wfsgrz"
442
- }], ["path", {
443
- d: "M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",
444
- key: "1oajmo"
445
- }], ["path", {
446
- d: "M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",
447
- key: "mpwhp6"
448
- }]];
449
- const FileBraces = createLucideIcon("file-braces", __iconNode$a);
450
-
451
- /**
452
- * @license lucide-react v0.561.0 - ISC
453
- *
454
- * This source code is licensed under the ISC license.
455
- * See the LICENSE file in the root directory of this source tree.
456
- */
457
- const __iconNode$9 = [["circle", {
458
- cx: "9",
459
- cy: "12",
460
- r: "1",
461
- key: "1vctgf"
462
- }], ["circle", {
463
- cx: "9",
464
- cy: "5",
465
- r: "1",
466
- key: "hp0tcf"
467
- }], ["circle", {
468
- cx: "9",
469
- cy: "19",
470
- r: "1",
471
- key: "fkjjf6"
472
- }], ["circle", {
473
- cx: "15",
474
- cy: "12",
475
- r: "1",
476
- key: "1tmaij"
477
- }], ["circle", {
478
- cx: "15",
479
- cy: "5",
480
- r: "1",
481
- key: "19l28e"
482
- }], ["circle", {
483
- cx: "15",
484
- cy: "19",
485
- r: "1",
486
- key: "f4zoj3"
487
- }]];
488
- const GripVertical = createLucideIcon("grip-vertical", __iconNode$9);
489
-
490
- /**
491
- * @license lucide-react v0.561.0 - ISC
492
- *
493
- * This source code is licensed under the ISC license.
494
- * See the LICENSE file in the root directory of this source tree.
495
- */
496
- const __iconNode$8 = [["path", {
497
- d: "M9 17H7A5 5 0 0 1 7 7h2",
498
- key: "8i5ue5"
499
- }], ["path", {
500
- d: "M15 7h2a5 5 0 1 1 0 10h-2",
501
- key: "1b9ql8"
502
- }], ["line", {
503
- x1: "8",
504
- x2: "16",
505
- y1: "12",
506
- y2: "12",
507
- key: "1jonct"
508
- }]];
509
- const Link2 = createLucideIcon("link-2", __iconNode$8);
510
-
511
- /**
512
- * @license lucide-react v0.561.0 - ISC
513
- *
514
- * This source code is licensed under the ISC license.
515
- * See the LICENSE file in the root directory of this source tree.
516
- */
517
- const __iconNode$7 = [["path", {
518
- d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",
519
- key: "1cjeqo"
520
- }], ["path", {
521
- d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",
522
- key: "19qd67"
523
- }]];
524
- const Link = createLucideIcon("link", __iconNode$7);
525
-
526
- /**
527
- * @license lucide-react v0.561.0 - ISC
528
- *
529
- * This source code is licensed under the ISC license.
530
- * See the LICENSE file in the root directory of this source tree.
531
- */
532
- const __iconNode$6 = [["path", {
533
- d: "M15 3h6v6",
534
- key: "1q9fwt"
535
- }], ["path", {
536
- d: "m21 3-7 7",
537
- key: "1l2asr"
538
- }], ["path", {
539
- d: "m3 21 7-7",
540
- key: "tjx5ai"
541
- }], ["path", {
542
- d: "M9 21H3v-6",
543
- key: "wtvkvv"
544
- }]];
545
- const Maximize2 = createLucideIcon("maximize-2", __iconNode$6);
546
-
547
- /**
548
- * @license lucide-react v0.561.0 - ISC
549
- *
550
- * This source code is licensed under the ISC license.
551
- * See the LICENSE file in the root directory of this source tree.
552
- */
553
- const __iconNode$5 = [["path", {
554
- d: "M5 12h14",
555
- key: "1ays0h"
556
- }], ["path", {
557
- d: "M12 5v14",
558
- key: "s699le"
559
- }]];
560
- const Plus = createLucideIcon("plus", __iconNode$5);
561
-
562
- /**
563
- * @license lucide-react v0.561.0 - ISC
564
- *
565
- * This source code is licensed under the ISC license.
566
- * See the LICENSE file in the root directory of this source tree.
567
- */
568
- const __iconNode$4 = [["path", {
569
- d: "M14 17H5",
570
- key: "gfn3mx"
571
- }], ["path", {
572
- d: "M19 7h-9",
573
- key: "6i9tg"
574
- }], ["circle", {
575
- cx: "17",
576
- cy: "17",
577
- r: "3",
578
- key: "18b49y"
579
- }], ["circle", {
580
- cx: "7",
581
- cy: "7",
582
- r: "3",
583
- key: "dfmy0x"
584
- }]];
585
- const Settings2 = createLucideIcon("settings-2", __iconNode$4);
586
-
587
- /**
588
- * @license lucide-react v0.561.0 - ISC
589
- *
590
- * This source code is licensed under the ISC license.
591
- * See the LICENSE file in the root directory of this source tree.
592
- */
593
- const __iconNode$3 = [["path", {
594
- d: "M10 11v6",
595
- key: "nco0om"
596
- }], ["path", {
597
- d: "M14 11v6",
598
- key: "outv1u"
599
- }], ["path", {
600
- d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",
601
- key: "miytrc"
602
- }], ["path", {
603
- d: "M3 6h18",
604
- key: "d0wm0j"
605
- }], ["path", {
606
- d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",
607
- key: "e791ji"
608
- }]];
609
- const Trash2 = createLucideIcon("trash-2", __iconNode$3);
610
-
611
- /**
612
- * @license lucide-react v0.561.0 - ISC
613
- *
614
- * This source code is licensed under the ISC license.
615
- * See the LICENSE file in the root directory of this source tree.
616
- */
617
- const __iconNode$2 = [["path", {
618
- d: "m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",
619
- key: "yqzxt4"
620
- }], ["path", {
621
- d: "m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",
622
- key: "4qinb0"
623
- }], ["line", {
624
- x1: "8",
625
- x2: "8",
626
- y1: "2",
627
- y2: "5",
628
- key: "1041cp"
629
- }], ["line", {
630
- x1: "2",
631
- x2: "5",
632
- y1: "8",
633
- y2: "8",
634
- key: "14m1p5"
635
- }], ["line", {
636
- x1: "16",
637
- x2: "16",
638
- y1: "19",
639
- y2: "22",
640
- key: "rzdirn"
641
- }], ["line", {
642
- x1: "19",
643
- x2: "22",
644
- y1: "16",
645
- y2: "16",
646
- key: "ox905f"
647
- }]];
648
- const Unlink = createLucideIcon("unlink", __iconNode$2);
649
-
650
- /**
651
- * @license lucide-react v0.561.0 - ISC
652
- *
653
- * This source code is licensed under the ISC license.
654
- * See the LICENSE file in the root directory of this source tree.
655
- */
656
- const __iconNode$1 = [["path", {
657
- d: "M12 3v12",
658
- key: "1x0j5s"
659
- }], ["path", {
660
- d: "m17 8-5-5-5 5",
661
- key: "7q97r8"
662
- }], ["path", {
663
- d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",
664
- key: "ih7n3h"
665
- }]];
666
- const Upload = createLucideIcon("upload", __iconNode$1);
667
-
668
- /**
669
- * @license lucide-react v0.561.0 - ISC
670
- *
671
- * This source code is licensed under the ISC license.
672
- * See the LICENSE file in the root directory of this source tree.
673
- */
674
- const __iconNode = [["path", {
675
- d: "M18 6 6 18",
676
- key: "1bl5f8"
677
- }], ["path", {
678
- d: "m6 6 12 12",
679
- key: "d8bk6v"
680
- }]];
681
- const X = createLucideIcon("x", __iconNode);
682
-
683
- var styles$j = {"container":"es-container-K2hFq","visualWrapper":"es-visualWrapper-4dHVX","previewBox":"es-previewBox-LDujZ","previewElement":"es-previewElement-Bu8GM","grid":"es-grid-BmRRU","gridButton":"es-gridButton-6Vtr7","gridButtonSelected":"es-gridButtonSelected-fOpOm","section":"es-section-SaHDo","sectionLabel":"es-sectionLabel-hDWO0","buttonGroup":"es-buttonGroup-Nj258","alignButton":"es-alignButton-zAvz2","alignButtonSelected":"es-alignButtonSelected-kGGHJ","alignIcon":"es-alignIcon-mFjSX","alignIconRotated":"es-alignIconRotated-z4AwW"};
684
-
685
- const defaultValue$3 = {
686
- horizontal: 'left',
687
- vertical: 'top'
688
- };
689
- const horizontalOptions = [{
690
- value: 'left',
691
- icon: AlignStartVertical,
692
- label: '左对齐'
693
- }, {
694
- value: 'center',
695
- icon: AlignVerticalDistributeCenter,
696
- label: '水平居中'
697
- }, {
698
- value: 'right',
699
- icon: AlignEndVertical,
700
- label: '右对齐'
701
- }, {
702
- value: 'stretch',
703
- icon: Maximize2,
704
- label: '水平拉伸'
705
- }];
706
- const verticalOptions = [{
707
- value: 'top',
708
- icon: AlignStartHorizontal,
709
- label: '顶部对齐'
710
- }, {
711
- value: 'center',
712
- icon: AlignHorizontalDistributeCenter,
713
- label: '垂直居中'
714
- }, {
715
- value: 'bottom',
716
- icon: AlignEndHorizontal,
717
- label: '底部对齐'
718
- }, {
719
- value: 'stretch',
720
- icon: Maximize2,
721
- label: '垂直拉伸'
722
- }];
723
-
724
- // 9宫格位置映射
725
- const gridPositions = [{
726
- h: 'left',
727
- v: 'top'
728
- }, {
729
- h: 'center',
730
- v: 'top'
731
- }, {
732
- h: 'right',
733
- v: 'top'
734
- }, {
735
- h: 'left',
736
- v: 'center'
737
- }, {
738
- h: 'center',
739
- v: 'center'
740
- }, {
741
- h: 'right',
742
- v: 'center'
743
- }, {
744
- h: 'left',
745
- v: 'bottom'
746
- }, {
747
- h: 'center',
748
- v: 'bottom'
749
- }, {
750
- h: 'right',
751
- v: 'bottom'
752
- }];
753
-
754
- // 获取元素在容器中的位置样式
755
- const getElementPosition = (h, v) => {
756
- const style = {
757
- position: 'absolute'
758
- };
759
-
760
- // 水平位置
761
- if (h === 'left') {
762
- style.left = '4px';
763
- style.width = '30%';
764
- } else if (h === 'center') {
765
- style.left = '50%';
766
- style.transform = 'translateX(-50%)';
767
- style.width = '30%';
768
- } else if (h === 'right') {
769
- style.right = '4px';
770
- style.width = '30%';
771
- } else {
772
- style.left = '4px';
773
- style.right = '4px';
774
- style.width = 'auto';
775
- }
776
-
777
- // 垂直位置
778
- if (v === 'top') {
779
- style.top = '4px';
780
- style.height = '30%';
781
- } else if (v === 'center') {
782
- style.top = '50%';
783
- style.transform = h === 'center' ? 'translate(-50%, -50%)' : 'translateY(-50%)';
784
- style.height = '30%';
785
- } else if (v === 'bottom') {
786
- style.bottom = '4px';
787
- style.height = '30%';
788
- } else {
789
- style.top = '4px';
790
- style.bottom = '4px';
791
- style.height = 'auto';
792
- }
793
- return style;
794
- };
795
- const AlignSetter = props => {
796
- const {
797
- value,
798
- initialValue,
799
- onChange,
800
- showHorizontal = true,
801
- showVertical = true
802
- } = props;
803
- const currentValue = value ?? initialValue ?? defaultValue$3;
804
- const updateAlign = useCallback(updates => {
805
- onChange({
806
- ...currentValue,
807
- ...updates
808
- });
809
- }, [currentValue, onChange]);
810
- const handleGridClick = useCallback((h, v) => {
811
- onChange({
812
- horizontal: h,
813
- vertical: v
814
- });
815
- }, [onChange]);
816
- const isGridSelected = (h, v) => currentValue.horizontal === h && currentValue.vertical === v;
817
- return /*#__PURE__*/React.createElement("div", {
818
- className: styles$j.container
819
- }, showHorizontal === true && showVertical === true ? /*#__PURE__*/React.createElement("div", {
820
- className: styles$j.visualWrapper
821
- }, /*#__PURE__*/React.createElement("div", {
822
- className: styles$j.previewBox
823
- }, /*#__PURE__*/React.createElement("div", {
824
- className: styles$j.previewElement,
825
- style: getElementPosition(currentValue.horizontal, currentValue.vertical)
826
- })), /*#__PURE__*/React.createElement("div", {
827
- className: styles$j.grid
828
- }, gridPositions.map(pos => /*#__PURE__*/React.createElement("button", {
829
- "aria-label": `Align ${pos.h} ${pos.v}`,
830
- className: cn(styles$j.gridButton, isGridSelected(pos.h, pos.v) ? styles$j.gridButtonSelected : ''),
831
- key: `${pos.h}-${pos.v}`,
832
- onClick: () => handleGridClick(pos.h, pos.v),
833
- type: "button"
834
- })))) : null, showHorizontal === true ? /*#__PURE__*/React.createElement("div", {
835
- className: styles$j.section
836
- }, /*#__PURE__*/React.createElement("span", {
837
- className: styles$j.sectionLabel
838
- }, "\u6C34\u5E73\u5BF9\u9F50"), /*#__PURE__*/React.createElement("div", {
839
- className: styles$j.buttonGroup
840
- }, horizontalOptions.map(option => {
841
- const Icon = option.icon;
842
- const isRotated = option.value === 'stretch';
843
- return /*#__PURE__*/React.createElement("button", {
844
- "aria-label": option.label,
845
- className: cn(styles$j.alignButton, currentValue.horizontal === option.value ? styles$j.alignButtonSelected : ''),
846
- key: option.value,
847
- onClick: () => updateAlign({
848
- horizontal: option.value
849
- }),
850
- title: option.label,
851
- type: "button"
852
- }, /*#__PURE__*/React.createElement(Icon, {
853
- className: cn(styles$j.alignIcon, isRotated ? styles$j.alignIconRotated : '')
854
- }));
855
- }))) : null, showVertical === true ? /*#__PURE__*/React.createElement("div", {
856
- className: styles$j.section
857
- }, /*#__PURE__*/React.createElement("span", {
858
- className: styles$j.sectionLabel
859
- }, "\u5782\u76F4\u5BF9\u9F50"), /*#__PURE__*/React.createElement("div", {
860
- className: styles$j.buttonGroup
861
- }, verticalOptions.map(option => {
862
- const Icon = option.icon;
863
- return /*#__PURE__*/React.createElement("button", {
864
- "aria-label": option.label,
865
- className: cn(styles$j.alignButton, currentValue.vertical === option.value ? styles$j.alignButtonSelected : ''),
866
- key: option.value,
867
- onClick: () => updateAlign({
868
- vertical: option.value
869
- }),
870
- title: option.label,
871
- type: "button"
872
- }, /*#__PURE__*/React.createElement(Icon, {
873
- className: styles$j.alignIcon
874
- }));
875
- }))) : null);
876
- };
877
-
878
- var styles$i = {"container":"es-container-KSlB-","item":"es-item-xDCpZ","dragHandle":"es-dragHandle-lOaFv","input":"es-input-ItzPT","removeButton":"es-removeButton-ymAlo","removeIcon":"es-removeIcon-ld51f","addButton":"es-addButton-U1VQX","addIcon":"es-addIcon-6qJub"};
879
-
880
- const ArraySetter = props => {
881
- const {
882
- value,
883
- initialValue,
884
- itemSetter = 'string',
885
- maxItems,
886
- minItems = 0,
887
- placeholder,
888
- addButtonText = '添加项',
889
- onChange
890
- } = props;
891
- const items = value ?? initialValue ?? [];
892
- const handleAdd = useCallback(() => {
893
- if (maxItems && items.length >= maxItems) {
894
- return;
895
- }
896
- const newItem = itemSetter === 'number' ? 0 : '';
897
- onChange([...items, newItem]);
898
- }, [items, maxItems, itemSetter, onChange]);
899
- const handleRemove = useCallback(index => {
900
- if (items.length <= minItems) {
901
- return;
902
- }
903
- const newItems = items.filter((_, i) => i !== index);
904
- onChange(newItems);
905
- }, [items, minItems, onChange]);
906
- const handleChange = useCallback((index, newValue) => {
907
- const newItems = [...items];
908
- newItems[index] = newValue;
909
- onChange(newItems);
910
- }, [items, onChange]);
911
- const canAdd = !maxItems || items.length < maxItems;
912
- const canRemove = items.length > minItems;
913
- return /*#__PURE__*/React.createElement("div", {
914
- className: styles$i.container
915
- }, items.map((item, index) => /*#__PURE__*/React.createElement("div", {
916
- className: styles$i.item,
917
- key: `item-${String(item)}-${index}`
918
- }, /*#__PURE__*/React.createElement(GripVertical, {
919
- className: styles$i.dragHandle
920
- }), /*#__PURE__*/React.createElement("input", {
921
- className: styles$i.input,
922
- onChange: e => {
923
- const val = itemSetter === 'number' ? +e.target.value : e.target.value;
924
- handleChange(index, val);
925
- },
926
- placeholder: placeholder,
927
- type: itemSetter === 'number' ? 'number' : 'text',
928
- value: item
929
- }), /*#__PURE__*/React.createElement("button", {
930
- className: styles$i.removeButton,
931
- disabled: !canRemove,
932
- onClick: () => handleRemove(index),
933
- type: "button"
934
- }, /*#__PURE__*/React.createElement(Trash2, {
935
- className: styles$i.removeIcon
936
- })))), /*#__PURE__*/React.createElement("button", {
937
- className: styles$i.addButton,
938
- disabled: !canAdd,
939
- onClick: handleAdd,
940
- type: "button"
941
- }, /*#__PURE__*/React.createElement(Plus, {
942
- className: styles$i.addIcon
943
- }), addButtonText));
944
- };
945
-
946
- function _extends() {
947
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
948
- for (var e = 1; e < arguments.length; e++) {
949
- var t = arguments[e];
950
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
951
- }
952
- return n;
953
- }, _extends.apply(null, arguments);
954
- }
955
-
956
- function _objectWithoutPropertiesLoose(r, e) {
957
- if (null == r) return {};
958
- var t = {};
959
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
960
- if (-1 !== e.indexOf(n)) continue;
961
- t[n] = r[n];
962
- }
963
- return t;
964
- }
965
-
966
- var RGB_MAX = 255;
967
- var SV_MAX = 100;
968
- var rgbaToHsva = _ref => {
969
- var {
970
- r,
971
- g,
972
- b,
973
- a
974
- } = _ref;
975
- var max = Math.max(r, g, b);
976
- var delta = max - Math.min(r, g, b);
977
- var hh = delta ? max === r ? (g - b) / delta : max === g ? 2 + (b - r) / delta : 4 + (r - g) / delta : 0;
978
- return {
979
- h: 60 * (hh < 0 ? hh + 6 : hh),
980
- s: max ? delta / max * SV_MAX : 0,
981
- v: max / RGB_MAX * SV_MAX,
982
- a
983
- };
984
- };
985
- var hsvaToHslaString = hsva => {
986
- var {
987
- h,
988
- s,
989
- l,
990
- a
991
- } = hsvaToHsla(hsva);
992
- return "hsla(" + h + ", " + s + "%, " + l + "%, " + a + ")";
993
- };
994
- var hsvaToHsla = _ref5 => {
995
- var {
996
- h,
997
- s,
998
- v,
999
- a
1000
- } = _ref5;
1001
- var hh = (200 - s) * v / SV_MAX;
1002
- return {
1003
- h,
1004
- s: hh > 0 && hh < 200 ? s * v / SV_MAX / (hh <= SV_MAX ? hh : 200 - hh) * SV_MAX : 0,
1005
- l: hh / 2,
1006
- a
1007
- };
1008
- };
1009
- var rgbToHex = _ref7 => {
1010
- var {
1011
- r,
1012
- g,
1013
- b
1014
- } = _ref7;
1015
- var bin = r << 16 | g << 8 | b;
1016
- return "#" + (h => new Array(7 - h.length).join('0') + h)(bin.toString(16));
1017
- };
1018
- var rgbaToHexa = _ref8 => {
1019
- var {
1020
- r,
1021
- g,
1022
- b,
1023
- a
1024
- } = _ref8;
1025
- var alpha = typeof a === 'number' && (a * 255 | 1 << 8).toString(16).slice(1);
1026
- return "" + rgbToHex({
1027
- r,
1028
- g,
1029
- b
1030
- }) + (alpha ? alpha : '');
1031
- };
1032
- var hexToHsva = hex => rgbaToHsva(hexToRgba(hex));
1033
- var hexToRgba = hex => {
1034
- var htemp = hex.replace('#', '');
1035
- if (/^#?/.test(hex) && htemp.length === 3) {
1036
- hex = "#" + htemp.charAt(0) + htemp.charAt(0) + htemp.charAt(1) + htemp.charAt(1) + htemp.charAt(2) + htemp.charAt(2);
1037
- }
1038
- var reg = new RegExp("[A-Za-z0-9]{2}", 'g');
1039
- var [r, g, b = 0, a] = hex.match(reg).map(v => parseInt(v, 16));
1040
- return {
1041
- r,
1042
- g,
1043
- b,
1044
- a: (a != null ? a : 255) / RGB_MAX
1045
- };
1046
- };
1047
- var hsvaToRgba = _ref9 => {
1048
- var {
1049
- h,
1050
- s,
1051
- v,
1052
- a
1053
- } = _ref9;
1054
- var _h = h / 60,
1055
- _s = s / SV_MAX,
1056
- _v = v / SV_MAX,
1057
- hi = Math.floor(_h) % 6;
1058
- var f = _h - Math.floor(_h),
1059
- _p = RGB_MAX * _v * (1 - _s),
1060
- _q = RGB_MAX * _v * (1 - _s * f),
1061
- _t = RGB_MAX * _v * (1 - _s * (1 - f));
1062
- _v *= RGB_MAX;
1063
- var rgba = {};
1064
- switch (hi) {
1065
- case 0:
1066
- rgba.r = _v;
1067
- rgba.g = _t;
1068
- rgba.b = _p;
1069
- break;
1070
- case 1:
1071
- rgba.r = _q;
1072
- rgba.g = _v;
1073
- rgba.b = _p;
1074
- break;
1075
- case 2:
1076
- rgba.r = _p;
1077
- rgba.g = _v;
1078
- rgba.b = _t;
1079
- break;
1080
- case 3:
1081
- rgba.r = _p;
1082
- rgba.g = _q;
1083
- rgba.b = _v;
1084
- break;
1085
- case 4:
1086
- rgba.r = _t;
1087
- rgba.g = _p;
1088
- rgba.b = _v;
1089
- break;
1090
- case 5:
1091
- rgba.r = _v;
1092
- rgba.g = _p;
1093
- rgba.b = _q;
1094
- break;
1095
- }
1096
- rgba.r = Math.round(rgba.r);
1097
- rgba.g = Math.round(rgba.g);
1098
- rgba.b = Math.round(rgba.b);
1099
- return _extends({}, rgba, {
1100
- a
1101
- });
1102
- };
1103
- var hsvaToRgbaString = hsva => {
1104
- var {
1105
- r,
1106
- g,
1107
- b,
1108
- a
1109
- } = hsvaToRgba(hsva);
1110
- return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
1111
- };
1112
- var rgbaToRgb = _ref0 => {
1113
- var {
1114
- r,
1115
- g,
1116
- b
1117
- } = _ref0;
1118
- return {
1119
- r,
1120
- g,
1121
- b
1122
- };
1123
- };
1124
- var hslaToHsl = _ref1 => {
1125
- var {
1126
- h,
1127
- s,
1128
- l
1129
- } = _ref1;
1130
- return {
1131
- h,
1132
- s,
1133
- l
1134
- };
1135
- };
1136
- var hsvaToHex = hsva => rgbToHex(hsvaToRgba(hsva));
1137
- var hsvaToHsv = _ref10 => {
1138
- var {
1139
- h,
1140
- s,
1141
- v
1142
- } = _ref10;
1143
- return {
1144
- h,
1145
- s,
1146
- v
1147
- };
1148
- };
1149
- var rgbToXY = _ref12 => {
1150
- var {
1151
- r,
1152
- g,
1153
- b
1154
- } = _ref12;
1155
- var translateColor = function translateColor(color) {
1156
- return color <= 0.04045 ? color / 12.92 : Math.pow((color + 0.055) / 1.055, 2.4);
1157
- };
1158
- var red = translateColor(r / 255);
1159
- var green = translateColor(g / 255);
1160
- var blue = translateColor(b / 255);
1161
- var xyz = {};
1162
- xyz.x = red * 0.4124 + green * 0.3576 + blue * 0.1805;
1163
- xyz.y = red * 0.2126 + green * 0.7152 + blue * 0.0722;
1164
- xyz.bri = red * 0.0193 + green * 0.1192 + blue * 0.9505;
1165
- return xyz;
1166
- };
1167
- var color = str => {
1168
- var rgb;
1169
- var hsl;
1170
- var hsv;
1171
- var rgba;
1172
- var hsla;
1173
- var hsva;
1174
- var xy;
1175
- var hex;
1176
- var hexa;
1177
- if (typeof str === 'string' && validHex$1(str)) {
1178
- hsva = hexToHsva(str);
1179
- hex = str;
1180
- } else if (typeof str !== 'string') {
1181
- hsva = str;
1182
- }
1183
- if (hsva) {
1184
- hsv = hsvaToHsv(hsva);
1185
- hsla = hsvaToHsla(hsva);
1186
- rgba = hsvaToRgba(hsva);
1187
- hexa = rgbaToHexa(rgba);
1188
- hex = hsvaToHex(hsva);
1189
- hsl = hslaToHsl(hsla);
1190
- rgb = rgbaToRgb(rgba);
1191
- xy = rgbToXY(rgb);
1192
- }
1193
- return {
1194
- rgb,
1195
- hsl,
1196
- hsv,
1197
- rgba,
1198
- hsla,
1199
- hsva,
1200
- hex,
1201
- hexa,
1202
- xy
1203
- };
1204
- };
1205
- var validHex$1 = hex => /^#?([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
1206
-
1207
- function useEventCallback(handler) {
1208
- var callbackRef = useRef(handler);
1209
- useEffect(() => {
1210
- callbackRef.current = handler;
1211
- });
1212
- return useCallback((value, event) => callbackRef.current && callbackRef.current(value, event), []);
1213
- }
1214
- var isTouch = event => 'touches' in event;
1215
- var preventDefaultMove = event => {
1216
- !isTouch(event) && event.preventDefault && event.preventDefault();
1217
- };
1218
- var clamp = function clamp(number, min, max) {
1219
- if (min === void 0) {
1220
- min = 0;
1221
- }
1222
- if (max === void 0) {
1223
- max = 1;
1224
- }
1225
- return number > max ? max : number < min ? min : number;
1226
- };
1227
- var getRelativePosition = (node, event) => {
1228
- var rect = node.getBoundingClientRect();
1229
- var pointer = isTouch(event) ? event.touches[0] : event;
1230
- return {
1231
- left: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
1232
- top: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height),
1233
- width: rect.width,
1234
- height: rect.height,
1235
- x: pointer.pageX - (rect.left + window.pageXOffset),
1236
- y: pointer.pageY - (rect.top + window.pageYOffset)
1237
- };
1238
- };
1239
-
1240
- var _excluded$8 = ["prefixCls", "className", "onMove", "onDown"];
1241
- var Interactive = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1242
- var {
1243
- prefixCls = 'w-color-interactive',
1244
- className,
1245
- onMove,
1246
- onDown
1247
- } = props,
1248
- reset = _objectWithoutPropertiesLoose(props, _excluded$8);
1249
- var container = useRef(null);
1250
- var hasTouched = useRef(false);
1251
- var [isDragging, setDragging] = useState(false);
1252
- var onMoveCallback = useEventCallback(onMove);
1253
- var onKeyCallback = useEventCallback(onDown);
1254
- var isValid = event => {
1255
- if (hasTouched.current && !isTouch(event)) return false;
1256
- hasTouched.current = isTouch(event);
1257
- return true;
1258
- };
1259
- var handleMove = useCallback(event => {
1260
- preventDefaultMove(event);
1261
- if (!container.current) return;
1262
- var isDown = isTouch(event) ? event.touches.length > 0 : event.buttons > 0;
1263
- if (!isDown) {
1264
- setDragging(false);
1265
- return;
1266
- }
1267
- onMoveCallback == null || onMoveCallback(getRelativePosition(container.current, event), event);
1268
- }, [onMoveCallback]);
1269
- var handleMoveEnd = useCallback(() => setDragging(false), []);
1270
- var toggleDocumentEvents = useCallback(state => {
1271
- if (state) {
1272
- window.addEventListener(hasTouched.current ? 'touchmove' : 'mousemove', handleMove);
1273
- window.addEventListener(hasTouched.current ? 'touchend' : 'mouseup', handleMoveEnd);
1274
- } else {
1275
- window.removeEventListener('mousemove', handleMove);
1276
- window.removeEventListener('mouseup', handleMoveEnd);
1277
- window.removeEventListener('touchmove', handleMove);
1278
- window.removeEventListener('touchend', handleMoveEnd);
1279
- }
1280
- }, [handleMove, handleMoveEnd]);
1281
- useEffect(() => {
1282
- toggleDocumentEvents(isDragging);
1283
- return () => {
1284
- toggleDocumentEvents(false);
1285
- };
1286
- }, [isDragging, handleMove, handleMoveEnd, toggleDocumentEvents]);
1287
- var handleMoveStart = useCallback(event => {
1288
- var activeEl = document.activeElement;
1289
- activeEl == null || activeEl.blur();
1290
- preventDefaultMove(event.nativeEvent);
1291
- if (!isValid(event.nativeEvent)) return;
1292
- if (!container.current) return;
1293
- onKeyCallback == null || onKeyCallback(getRelativePosition(container.current, event.nativeEvent), event.nativeEvent);
1294
- setDragging(true);
1295
- }, [onKeyCallback]);
1296
- return /*#__PURE__*/jsx("div", _extends({}, reset, {
1297
- className: [prefixCls, className || ''].filter(Boolean).join(' '),
1298
- style: _extends({}, reset.style, {
1299
- touchAction: 'none'
1300
- }),
1301
- ref: container,
1302
- tabIndex: 0,
1303
- onMouseDown: handleMoveStart,
1304
- onTouchStart: handleMoveStart
1305
- }));
1306
- });
1307
- Interactive.displayName = 'Interactive';
1308
-
1309
- var Pointer$1 = _ref => {
1310
- var {
1311
- className,
1312
- color,
1313
- left,
1314
- top,
1315
- prefixCls
1316
- } = _ref;
1317
- var style = {
1318
- position: 'absolute',
1319
- top,
1320
- left
1321
- };
1322
- var stylePointer = {
1323
- '--saturation-pointer-box-shadow': 'rgb(255 255 255) 0px 0px 0px 1.5px, rgb(0 0 0 / 30%) 0px 0px 1px 1px inset, rgb(0 0 0 / 40%) 0px 0px 1px 2px',
1324
- width: 6,
1325
- height: 6,
1326
- transform: 'translate(-3px, -3px)',
1327
- boxShadow: 'var(--saturation-pointer-box-shadow)',
1328
- borderRadius: '50%',
1329
- backgroundColor: color
1330
- };
1331
- return useMemo(() => /*#__PURE__*/jsx("div", {
1332
- className: prefixCls + "-pointer " + (className || ''),
1333
- style: style,
1334
- children: /*#__PURE__*/jsx("div", {
1335
- className: prefixCls + "-fill",
1336
- style: stylePointer
1337
- })
1338
- }), [top, left, color, className, prefixCls]);
1339
- };
1340
-
1341
- var _excluded$7 = ["prefixCls", "radius", "pointer", "className", "hue", "style", "hsva", "onChange"];
1342
- var Saturation = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1343
- var _hsva$h;
1344
- var {
1345
- prefixCls = 'w-color-saturation',
1346
- radius = 0,
1347
- pointer,
1348
- className,
1349
- hue = 0,
1350
- style,
1351
- hsva,
1352
- onChange
1353
- } = props,
1354
- other = _objectWithoutPropertiesLoose(props, _excluded$7);
1355
- var containerStyle = _extends({
1356
- width: 200,
1357
- height: 200,
1358
- borderRadius: radius
1359
- }, style, {
1360
- position: 'relative'
1361
- });
1362
- var handleChange = (interaction, event) => {
1363
- onChange && hsva && onChange({
1364
- h: hsva.h,
1365
- s: interaction.left * 100,
1366
- v: (1 - interaction.top) * 100,
1367
- a: hsva.a
1368
- });
1369
- };
1370
- var handleKeyDown = useCallback(event => {
1371
- if (!hsva || !onChange) return;
1372
- var step = 1;
1373
- var newS = hsva.s;
1374
- var newV = hsva.v;
1375
- var changed = false;
1376
- switch (event.key) {
1377
- case 'ArrowLeft':
1378
- newS = Math.max(0, hsva.s - step);
1379
- changed = true;
1380
- event.preventDefault();
1381
- break;
1382
- case 'ArrowRight':
1383
- newS = Math.min(100, hsva.s + step);
1384
- changed = true;
1385
- event.preventDefault();
1386
- break;
1387
- case 'ArrowUp':
1388
- newV = Math.min(100, hsva.v + step);
1389
- changed = true;
1390
- event.preventDefault();
1391
- break;
1392
- case 'ArrowDown':
1393
- newV = Math.max(0, hsva.v - step);
1394
- changed = true;
1395
- event.preventDefault();
1396
- break;
1397
- default:
1398
- return;
1399
- }
1400
- if (changed) {
1401
- onChange({
1402
- h: hsva.h,
1403
- s: newS,
1404
- v: newV,
1405
- a: hsva.a
1406
- });
1407
- }
1408
- }, [hsva, onChange]);
1409
- var pointerElement = useMemo(() => {
1410
- if (!hsva) return null;
1411
- var comProps = {
1412
- top: 100 - hsva.v + "%",
1413
- left: hsva.s + "%",
1414
- color: hsvaToHslaString(hsva)
1415
- };
1416
- if (pointer && typeof pointer === 'function') {
1417
- return pointer(_extends({
1418
- prefixCls
1419
- }, comProps));
1420
- }
1421
- return /*#__PURE__*/jsx(Pointer$1, _extends({
1422
- prefixCls: prefixCls
1423
- }, comProps));
1424
- }, [hsva, pointer, prefixCls]);
1425
- var handleClick = useCallback(event => {
1426
- event.target.focus();
1427
- }, []);
1428
- return /*#__PURE__*/jsx(Interactive, _extends({
1429
- className: [prefixCls, className || ''].filter(Boolean).join(' ')
1430
- }, other, {
1431
- style: _extends({
1432
- position: 'absolute',
1433
- inset: 0,
1434
- cursor: 'crosshair',
1435
- backgroundImage: "linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, hsl(" + ((_hsva$h = hsva == null ? void 0 : hsva.h) != null ? _hsva$h : hue) + ", 100%, 50%))"
1436
- }, containerStyle, {
1437
- outline: 'none'
1438
- }),
1439
- ref: ref,
1440
- onMove: handleChange,
1441
- onDown: handleChange,
1442
- onKeyDown: handleKeyDown,
1443
- onClick: handleClick,
1444
- children: pointerElement
1445
- }));
1446
- });
1447
- Saturation.displayName = 'Saturation';
1448
-
1449
- var _excluded$6 = ["className", "prefixCls", "left", "top", "style", "fillProps"];
1450
- var Pointer = _ref => {
1451
- var {
1452
- className,
1453
- prefixCls,
1454
- left,
1455
- top,
1456
- style,
1457
- fillProps
1458
- } = _ref,
1459
- reset = _objectWithoutPropertiesLoose(_ref, _excluded$6);
1460
- var styleWrapper = _extends({}, style, {
1461
- position: 'absolute',
1462
- left,
1463
- top
1464
- });
1465
- var stylePointer = _extends({
1466
- width: 18,
1467
- height: 18,
1468
- boxShadow: 'var(--alpha-pointer-box-shadow)',
1469
- borderRadius: '50%',
1470
- backgroundColor: 'var(--alpha-pointer-background-color)'
1471
- }, fillProps == null ? void 0 : fillProps.style, {
1472
- transform: left ? 'translate(-9px, -1px)' : 'translate(-1px, -9px)'
1473
- });
1474
- return /*#__PURE__*/jsx("div", _extends({
1475
- className: prefixCls + "-pointer " + (className || ''),
1476
- style: styleWrapper
1477
- }, reset, {
1478
- children: /*#__PURE__*/jsx("div", _extends({
1479
- className: prefixCls + "-fill"
1480
- }, fillProps, {
1481
- style: stylePointer
1482
- }))
1483
- }));
1484
- };
1485
-
1486
- var _excluded$5 = ["prefixCls", "className", "hsva", "background", "bgProps", "innerProps", "pointerProps", "radius", "width", "height", "direction", "style", "onChange", "pointer"];
1487
- var BACKGROUND_IMG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==';
1488
- var Alpha = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1489
- var {
1490
- prefixCls = 'w-color-alpha',
1491
- className,
1492
- hsva,
1493
- background,
1494
- bgProps = {},
1495
- innerProps = {},
1496
- pointerProps = {},
1497
- radius = 0,
1498
- width,
1499
- height = 16,
1500
- direction = 'horizontal',
1501
- style,
1502
- onChange,
1503
- pointer
1504
- } = props,
1505
- other = _objectWithoutPropertiesLoose(props, _excluded$5);
1506
- var handleChange = offset => {
1507
- onChange && onChange(_extends({}, hsva, {
1508
- a: direction === 'horizontal' ? offset.left : offset.top
1509
- }), offset);
1510
- };
1511
- var colorTo = hsvaToHslaString(Object.assign({}, hsva, {
1512
- a: 1
1513
- }));
1514
- var innerBackground = "linear-gradient(to " + (direction === 'horizontal' ? 'right' : 'bottom') + ", rgba(244, 67, 54, 0) 0%, " + colorTo + " 100%)";
1515
- var comProps = {};
1516
- if (direction === 'horizontal') {
1517
- comProps.left = hsva.a * 100 + "%";
1518
- } else {
1519
- comProps.top = hsva.a * 100 + "%";
1520
- }
1521
- var styleWrapper = _extends({
1522
- '--alpha-background-color': '#fff',
1523
- '--alpha-pointer-background-color': 'rgb(248, 248, 248)',
1524
- '--alpha-pointer-box-shadow': 'rgb(0 0 0 / 37%) 0px 1px 4px 0px',
1525
- borderRadius: radius,
1526
- background: "url(" + BACKGROUND_IMG + ") left center",
1527
- backgroundColor: 'var(--alpha-background-color)'
1528
- }, {
1529
- width,
1530
- height
1531
- }, style, {
1532
- position: 'relative'
1533
- });
1534
- var handleKeyDown = useCallback(event => {
1535
- var step = 0.01;
1536
- var currentAlpha = hsva.a;
1537
- var newAlpha = currentAlpha;
1538
- switch (event.key) {
1539
- case 'ArrowLeft':
1540
- if (direction === 'horizontal') {
1541
- newAlpha = Math.max(0, currentAlpha - step);
1542
- event.preventDefault();
1543
- }
1544
- break;
1545
- case 'ArrowRight':
1546
- if (direction === 'horizontal') {
1547
- newAlpha = Math.min(1, currentAlpha + step);
1548
- event.preventDefault();
1549
- }
1550
- break;
1551
- case 'ArrowUp':
1552
- if (direction === 'vertical') {
1553
- newAlpha = Math.max(0, currentAlpha - step);
1554
- event.preventDefault();
1555
- }
1556
- break;
1557
- case 'ArrowDown':
1558
- if (direction === 'vertical') {
1559
- newAlpha = Math.min(1, currentAlpha + step);
1560
- event.preventDefault();
1561
- }
1562
- break;
1563
- default:
1564
- return;
1565
- }
1566
- if (newAlpha !== currentAlpha) {
1567
- var syntheticOffset = {
1568
- left: direction === 'horizontal' ? newAlpha : hsva.a,
1569
- top: direction === 'vertical' ? newAlpha : hsva.a,
1570
- width: 0,
1571
- height: 0,
1572
- x: 0,
1573
- y: 0
1574
- };
1575
- onChange && onChange(_extends({}, hsva, {
1576
- a: newAlpha
1577
- }), syntheticOffset);
1578
- }
1579
- }, [hsva, direction, onChange]);
1580
- var handleClick = useCallback(event => {
1581
- event.target.focus();
1582
- }, []);
1583
- var pointerElement = pointer && typeof pointer === 'function' ? pointer(_extends({
1584
- prefixCls
1585
- }, pointerProps, comProps)) : /*#__PURE__*/jsx(Pointer, _extends({}, pointerProps, {
1586
- prefixCls: prefixCls
1587
- }, comProps));
1588
- return /*#__PURE__*/jsxs("div", _extends({}, other, {
1589
- className: [prefixCls, prefixCls + "-" + direction, className || ''].filter(Boolean).join(' '),
1590
- style: styleWrapper,
1591
- ref: ref,
1592
- children: [/*#__PURE__*/jsx("div", _extends({}, bgProps, {
1593
- style: _extends({
1594
- inset: 0,
1595
- position: 'absolute',
1596
- background: background || innerBackground,
1597
- borderRadius: radius
1598
- }, bgProps.style)
1599
- })), /*#__PURE__*/jsx(Interactive, _extends({}, innerProps, {
1600
- style: _extends({}, innerProps.style, {
1601
- inset: 0,
1602
- zIndex: 1,
1603
- position: 'absolute',
1604
- outline: 'none'
1605
- }),
1606
- onMove: handleChange,
1607
- onDown: handleChange,
1608
- onClick: handleClick,
1609
- onKeyDown: handleKeyDown,
1610
- children: pointerElement
1611
- }))]
1612
- }));
1613
- });
1614
- Alpha.displayName = 'Alpha';
1615
-
1616
- var _excluded$4 = ["prefixCls", "placement", "label", "value", "className", "style", "labelStyle", "inputStyle", "onChange", "onBlur", "renderInput"];
1617
- var validHex = hex => /^#?([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
1618
- var getNumberValue = value => Number(String(value).replace(/%/g, ''));
1619
- var EditableInput = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1620
- var {
1621
- prefixCls = 'w-color-editable-input',
1622
- placement = 'bottom',
1623
- label,
1624
- value: initValue,
1625
- className,
1626
- style,
1627
- labelStyle,
1628
- inputStyle,
1629
- onChange,
1630
- onBlur,
1631
- renderInput
1632
- } = props,
1633
- other = _objectWithoutPropertiesLoose(props, _excluded$4);
1634
- var [value, setValue] = useState(initValue);
1635
- var isFocus = useRef(false);
1636
- useEffect(() => {
1637
- if (props.value !== value) {
1638
- if (!isFocus.current) {
1639
- setValue(props.value);
1640
- }
1641
- }
1642
- }, [props.value]);
1643
- function handleChange(evn, valInit) {
1644
- var value = (valInit || evn.target.value).trim().replace(/^#/, '');
1645
- if (validHex(value)) {
1646
- onChange && onChange(evn, value);
1647
- }
1648
- var val = getNumberValue(value);
1649
- if (!isNaN(val)) {
1650
- onChange && onChange(evn, val);
1651
- }
1652
- setValue(value);
1653
- }
1654
- function handleBlur(evn) {
1655
- isFocus.current = false;
1656
- setValue(props.value);
1657
- onBlur && onBlur(evn);
1658
- }
1659
- var placementStyle = {};
1660
- if (placement === 'bottom') {
1661
- placementStyle['flexDirection'] = 'column';
1662
- }
1663
- if (placement === 'top') {
1664
- placementStyle['flexDirection'] = 'column-reverse';
1665
- }
1666
- if (placement === 'left') {
1667
- placementStyle['flexDirection'] = 'row-reverse';
1668
- }
1669
- var wrapperStyle = _extends({
1670
- '--editable-input-label-color': 'rgb(153, 153, 153)',
1671
- '--editable-input-box-shadow': 'rgb(204 204 204) 0px 0px 0px 1px inset',
1672
- '--editable-input-color': '#666',
1673
- position: 'relative',
1674
- alignItems: 'center',
1675
- display: 'flex',
1676
- fontSize: 11
1677
- }, placementStyle, style);
1678
- var editableStyle = _extends({
1679
- width: '100%',
1680
- paddingTop: 2,
1681
- paddingBottom: 2,
1682
- paddingLeft: 3,
1683
- paddingRight: 3,
1684
- fontSize: 11,
1685
- background: 'transparent',
1686
- boxSizing: 'border-box',
1687
- border: 'none',
1688
- color: 'var(--editable-input-color)',
1689
- boxShadow: 'var(--editable-input-box-shadow)'
1690
- }, inputStyle);
1691
- var inputProps = _extends({
1692
- value,
1693
- onChange: handleChange,
1694
- onBlur: handleBlur,
1695
- autoComplete: 'off',
1696
- onFocus: () => isFocus.current = true
1697
- }, other, {
1698
- style: editableStyle,
1699
- onFocusCapture: e => {
1700
- var elm = e.target;
1701
- elm.setSelectionRange(elm.value.length, elm.value.length);
1702
- }
1703
- });
1704
- return /*#__PURE__*/jsxs("div", {
1705
- className: [prefixCls, className || ''].filter(Boolean).join(' '),
1706
- style: wrapperStyle,
1707
- children: [renderInput ? renderInput(inputProps, ref) : /*#__PURE__*/jsx("input", _extends({
1708
- ref: ref
1709
- }, inputProps)), label && /*#__PURE__*/jsx("span", {
1710
- style: _extends({
1711
- color: 'var(--editable-input-label-color)',
1712
- textTransform: 'capitalize'
1713
- }, labelStyle),
1714
- children: label
1715
- })]
1716
- });
1717
- });
1718
- EditableInput.displayName = 'EditableInput';
1719
-
1720
- var _excluded$3 = ["prefixCls", "hsva", "placement", "rProps", "gProps", "bProps", "aProps", "className", "style", "onChange"];
1721
- var EditableInputRGBA = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1722
- var {
1723
- prefixCls = 'w-color-editable-input-rgba',
1724
- hsva,
1725
- placement = 'bottom',
1726
- rProps = {},
1727
- gProps = {},
1728
- bProps = {},
1729
- aProps = {},
1730
- className,
1731
- style,
1732
- onChange
1733
- } = props,
1734
- other = _objectWithoutPropertiesLoose(props, _excluded$3);
1735
- var rgba = hsva ? hsvaToRgba(hsva) : {};
1736
- function handleBlur(evn) {
1737
- var value = Number(evn.target.value);
1738
- if (value && value > 255) {
1739
- evn.target.value = '255';
1740
- }
1741
- if (value && value < 0) {
1742
- evn.target.value = '0';
1743
- }
1744
- }
1745
- var handleAlphaBlur = evn => {
1746
- var value = Number(evn.target.value);
1747
- if (value && value > 100) {
1748
- evn.target.value = '100';
1749
- }
1750
- if (value && value < 0) {
1751
- evn.target.value = '0';
1752
- }
1753
- };
1754
- var handleChange = (value, type, evn) => {
1755
- if (typeof value === 'number') {
1756
- if (type === 'a') {
1757
- if (value < 0) value = 0;
1758
- if (value > 100) value = 100;
1759
- onChange && onChange(color(rgbaToHsva(_extends({}, rgba, {
1760
- a: value / 100
1761
- }))));
1762
- }
1763
- if (value > 255) {
1764
- value = 255;
1765
- evn.target.value = '255';
1766
- }
1767
- if (value < 0) {
1768
- value = 0;
1769
- evn.target.value = '0';
1770
- }
1771
- if (type === 'r') {
1772
- onChange && onChange(color(rgbaToHsva(_extends({}, rgba, {
1773
- r: value
1774
- }))));
1775
- }
1776
- if (type === 'g') {
1777
- onChange && onChange(color(rgbaToHsva(_extends({}, rgba, {
1778
- g: value
1779
- }))));
1780
- }
1781
- if (type === 'b') {
1782
- onChange && onChange(color(rgbaToHsva(_extends({}, rgba, {
1783
- b: value
1784
- }))));
1785
- }
1786
- }
1787
- };
1788
- var roundedAlpha = rgba.a ? Math.round(rgba.a * 100) / 100 : 0;
1789
- return /*#__PURE__*/jsxs("div", _extends({
1790
- ref: ref,
1791
- className: [prefixCls, className || ''].filter(Boolean).join(' ')
1792
- }, other, {
1793
- style: _extends({
1794
- fontSize: 11,
1795
- display: 'flex'
1796
- }, style),
1797
- children: [/*#__PURE__*/jsx(EditableInput, _extends({
1798
- label: "R",
1799
- value: rgba.r || 0,
1800
- onBlur: handleBlur,
1801
- placement: placement,
1802
- onChange: (evn, val) => handleChange(val, 'r', evn)
1803
- }, rProps, {
1804
- style: _extends({}, rProps.style)
1805
- })), /*#__PURE__*/jsx(EditableInput, _extends({
1806
- label: "G",
1807
- value: rgba.g || 0,
1808
- onBlur: handleBlur,
1809
- placement: placement,
1810
- onChange: (evn, val) => handleChange(val, 'g', evn)
1811
- }, gProps, {
1812
- style: _extends({
1813
- marginLeft: 5
1814
- }, rProps.style)
1815
- })), /*#__PURE__*/jsx(EditableInput, _extends({
1816
- label: "B",
1817
- value: rgba.b || 0,
1818
- onBlur: handleBlur,
1819
- placement: placement,
1820
- onChange: (evn, val) => handleChange(val, 'b', evn)
1821
- }, bProps, {
1822
- style: _extends({
1823
- marginLeft: 5
1824
- }, bProps.style)
1825
- })), aProps && /*#__PURE__*/jsx(EditableInput, _extends({
1826
- label: "A",
1827
- value: parseInt(String(roundedAlpha * 100), 10),
1828
- onBlur: handleAlphaBlur,
1829
- placement: placement,
1830
- onChange: (evn, val) => handleChange(val, 'a', evn)
1831
- }, aProps, {
1832
- style: _extends({
1833
- marginLeft: 5
1834
- }, aProps.style)
1835
- }))]
1836
- }));
1837
- });
1838
- EditableInputRGBA.displayName = 'EditableInputRGBA';
1839
-
1840
- var _excluded$2 = ["prefixCls", "className", "hue", "onChange", "direction"];
1841
- var Hue = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1842
- var {
1843
- prefixCls = 'w-color-hue',
1844
- className,
1845
- hue = 0,
1846
- onChange: _onChange,
1847
- direction = 'horizontal'
1848
- } = props,
1849
- other = _objectWithoutPropertiesLoose(props, _excluded$2);
1850
- return /*#__PURE__*/jsx(Alpha, _extends({
1851
- ref: ref,
1852
- className: prefixCls + " " + (className || '')
1853
- }, other, {
1854
- direction: direction,
1855
- background: "linear-gradient(to " + (direction === 'horizontal' ? 'right' : 'bottom') + ", rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)",
1856
- hsva: {
1857
- h: hue,
1858
- s: 100,
1859
- v: 100,
1860
- a: hue / 360
1861
- },
1862
- onChange: (_, interaction) => {
1863
- _onChange && _onChange({
1864
- h: direction === 'horizontal' ? 360 * interaction.left : 360 * interaction.top
1865
- });
1866
- }
1867
- }));
1868
- });
1869
- Hue.displayName = 'Hue';
1870
-
1871
- var _excluded$1 = ["prefixCls", "className", "color", "colors", "style", "rectProps", "onChange", "addonAfter", "addonBefore", "rectRender"];
1872
- var Swatch = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1873
- var {
1874
- prefixCls = 'w-color-swatch',
1875
- className,
1876
- color: color$1,
1877
- colors = [],
1878
- style,
1879
- rectProps = {},
1880
- onChange,
1881
- addonAfter,
1882
- addonBefore,
1883
- rectRender
1884
- } = props,
1885
- other = _objectWithoutPropertiesLoose(props, _excluded$1);
1886
- var rectStyle = _extends({
1887
- '--swatch-background-color': 'rgb(144, 19, 254)',
1888
- background: 'var(--swatch-background-color)',
1889
- height: 15,
1890
- width: 15,
1891
- marginRight: 5,
1892
- marginBottom: 5,
1893
- cursor: 'pointer',
1894
- position: 'relative',
1895
- outline: 'none',
1896
- borderRadius: 2
1897
- }, rectProps.style);
1898
- var handleClick = (hex, evn) => {
1899
- onChange && onChange(hexToHsva(hex), color(hexToHsva(hex)), evn);
1900
- };
1901
- return /*#__PURE__*/jsxs("div", _extends({
1902
- ref: ref
1903
- }, other, {
1904
- className: [prefixCls, className || ''].filter(Boolean).join(' '),
1905
- style: _extends({
1906
- display: 'flex',
1907
- flexWrap: 'wrap',
1908
- position: 'relative'
1909
- }, style),
1910
- children: [addonBefore && /*#__PURE__*/React$1.isValidElement(addonBefore) && addonBefore, colors && Array.isArray(colors) && colors.map((item, idx) => {
1911
- var title = '';
1912
- var background = '';
1913
- if (typeof item === 'string') {
1914
- title = item;
1915
- background = item;
1916
- }
1917
- if (typeof item === 'object' && item.color) {
1918
- title = item.title || item.color;
1919
- background = item.color;
1920
- }
1921
- var checked = color$1 && color$1.toLocaleLowerCase() === background.toLocaleLowerCase();
1922
- var render = rectRender && rectRender({
1923
- title,
1924
- color: background,
1925
- checked: !!checked,
1926
- style: _extends({}, rectStyle, {
1927
- background
1928
- }),
1929
- onClick: evn => handleClick(background, evn)
1930
- });
1931
- if (render) {
1932
- return /*#__PURE__*/jsx(Fragment, {
1933
- children: render
1934
- }, idx);
1935
- }
1936
- var child = rectProps.children && /*#__PURE__*/React$1.isValidElement(rectProps.children) ? /*#__PURE__*/React$1.cloneElement(rectProps.children, {
1937
- color: background,
1938
- checked
1939
- }) : null;
1940
- return /*#__PURE__*/jsx("div", _extends({
1941
- tabIndex: 0,
1942
- title: title,
1943
- onClick: evn => handleClick(background, evn)
1944
- }, rectProps, {
1945
- children: child,
1946
- style: _extends({}, rectStyle, {
1947
- background
1948
- })
1949
- }), idx);
1950
- }), addonAfter && /*#__PURE__*/React$1.isValidElement(addonAfter) && addonAfter]
1951
- }));
1952
- });
1953
- Swatch.displayName = 'Swatch';
1954
-
1955
- var _excluded = ["prefixCls", "className", "onChange", "width", "presetColors", "color", "editableDisable", "disableAlpha", "style"];
1956
- var PRESET_COLORS = ['#D0021B', '#F5A623', '#f8e61b', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF'];
1957
- var Bar = props => /*#__PURE__*/jsx("div", {
1958
- style: {
1959
- boxShadow: 'rgb(0 0 0 / 60%) 0px 0px 2px',
1960
- width: 4,
1961
- top: 1,
1962
- bottom: 1,
1963
- left: props.left,
1964
- borderRadius: 1,
1965
- position: 'absolute',
1966
- backgroundColor: '#fff'
1967
- }
1968
- });
1969
- var Sketch = /*#__PURE__*/React$1.forwardRef((props, ref) => {
1970
- var {
1971
- prefixCls = 'w-color-sketch',
1972
- className,
1973
- onChange,
1974
- width = 218,
1975
- presetColors = PRESET_COLORS,
1976
- color: color$1,
1977
- editableDisable = true,
1978
- disableAlpha = false,
1979
- style
1980
- } = props,
1981
- other = _objectWithoutPropertiesLoose(props, _excluded);
1982
- var [hsva, setHsva] = useState({
1983
- h: 209,
1984
- s: 36,
1985
- v: 90,
1986
- a: 1
1987
- });
1988
- useEffect(() => {
1989
- if (typeof color$1 === 'string' && validHex$1(color$1)) {
1990
- setHsva(hexToHsva(color$1));
1991
- }
1992
- if (typeof color$1 === 'object') {
1993
- setHsva(color$1);
1994
- }
1995
- }, [color$1]);
1996
- var handleChange = hsv => {
1997
- setHsva(hsv);
1998
- onChange && onChange(color(hsv));
1999
- };
2000
- var handleHex = (value, evn) => {
2001
- if (typeof value === 'string' && validHex$1(value) && /(3|6)/.test(String(value.length))) {
2002
- handleChange(hexToHsva(value));
2003
- }
2004
- };
2005
- var handleAlphaChange = newAlpha => handleChange(_extends({}, hsva, {
2006
- a: newAlpha.a
2007
- }));
2008
- var handleSaturationChange = newColor => handleChange(_extends({}, hsva, newColor, {
2009
- a: hsva.a
2010
- }));
2011
- var styleMain = _extends({
2012
- '--sketch-background': 'rgb(255, 255, 255)',
2013
- '--sketch-box-shadow': 'rgb(0 0 0 / 15%) 0px 0px 0px 1px, rgb(0 0 0 / 15%) 0px 8px 16px',
2014
- '--sketch-swatch-box-shadow': 'rgb(0 0 0 / 15%) 0px 0px 0px 1px inset',
2015
- '--sketch-alpha-box-shadow': 'rgb(0 0 0 / 15%) 0px 0px 0px 1px inset, rgb(0 0 0 / 25%) 0px 0px 4px inset',
2016
- '--sketch-swatch-border-top': '1px solid rgb(238, 238, 238)',
2017
- background: 'var(--sketch-background)',
2018
- borderRadius: 4,
2019
- boxShadow: 'var(--sketch-box-shadow)',
2020
- width
2021
- }, style);
2022
- var styleAlpha = {
2023
- borderRadius: 2,
2024
- background: hsvaToRgbaString(hsva),
2025
- boxShadow: 'var(--sketch-alpha-box-shadow)'
2026
- };
2027
- var styleSwatch = {
2028
- borderTop: 'var(--sketch-swatch-border-top)',
2029
- paddingTop: 10,
2030
- paddingLeft: 10
2031
- };
2032
- var styleSwatchRect = {
2033
- marginRight: 10,
2034
- marginBottom: 10,
2035
- borderRadius: 3,
2036
- boxShadow: 'var(--sketch-swatch-box-shadow)'
2037
- };
2038
- return /*#__PURE__*/jsxs("div", _extends({}, other, {
2039
- className: prefixCls + " " + (className || ''),
2040
- ref: ref,
2041
- style: styleMain,
2042
- children: [/*#__PURE__*/jsxs("div", {
2043
- style: {
2044
- padding: '10px 10px 8px'
2045
- },
2046
- children: [/*#__PURE__*/jsx(Saturation, {
2047
- hsva: hsva,
2048
- style: {
2049
- width: 'auto',
2050
- height: 150
2051
- },
2052
- onChange: handleSaturationChange
2053
- }), /*#__PURE__*/jsxs("div", {
2054
- style: {
2055
- display: 'flex',
2056
- marginTop: 4
2057
- },
2058
- children: [/*#__PURE__*/jsxs("div", {
2059
- style: {
2060
- flex: 1
2061
- },
2062
- children: [/*#__PURE__*/jsx(Hue, {
2063
- width: "auto",
2064
- height: 10,
2065
- hue: hsva.h,
2066
- pointer: Bar,
2067
- innerProps: {
2068
- style: {
2069
- marginLeft: 1,
2070
- marginRight: 5
2071
- }
2072
- },
2073
- onChange: newHue => handleChange(_extends({}, hsva, newHue))
2074
- }), !disableAlpha && /*#__PURE__*/jsx(Alpha, {
2075
- width: "auto",
2076
- height: 10,
2077
- hsva: hsva,
2078
- pointer: Bar,
2079
- style: {
2080
- marginTop: 4
2081
- },
2082
- innerProps: {
2083
- style: {
2084
- marginLeft: 1,
2085
- marginRight: 5
2086
- }
2087
- },
2088
- onChange: handleAlphaChange
2089
- })]
2090
- }), !disableAlpha && /*#__PURE__*/jsx(Alpha, {
2091
- width: 24,
2092
- height: 24,
2093
- hsva: hsva,
2094
- radius: 2,
2095
- style: {
2096
- marginLeft: 4
2097
- },
2098
- bgProps: {
2099
- style: {
2100
- background: 'transparent'
2101
- }
2102
- },
2103
- innerProps: {
2104
- style: styleAlpha
2105
- },
2106
- pointer: () => /*#__PURE__*/jsx(Fragment, {})
2107
- })]
2108
- })]
2109
- }), editableDisable && /*#__PURE__*/jsxs("div", {
2110
- style: {
2111
- display: 'flex',
2112
- margin: '0 10px 3px 10px'
2113
- },
2114
- children: [/*#__PURE__*/jsx(EditableInput, {
2115
- label: "Hex",
2116
- value: hsvaToHex(hsva).replace(/^#/, '').toLocaleUpperCase(),
2117
- onChange: (evn, val) => handleHex(val),
2118
- style: {
2119
- minWidth: 58
2120
- }
2121
- }), /*#__PURE__*/jsx(EditableInputRGBA, {
2122
- hsva: hsva,
2123
- style: {
2124
- marginLeft: 6
2125
- },
2126
- aProps: !disableAlpha ? {} : false,
2127
- onChange: result => handleChange(result.hsva)
2128
- })]
2129
- }), presetColors && presetColors.length > 0 && /*#__PURE__*/jsx(Swatch, {
2130
- style: styleSwatch,
2131
- colors: presetColors,
2132
- color: hsvaToHex(hsva),
2133
- onChange: hsvColor => handleChange(hsvColor),
2134
- rectProps: {
2135
- style: styleSwatchRect
2136
- }
2137
- })]
2138
- }));
2139
- });
2140
- Sketch.displayName = 'Sketch';
2141
-
2142
- var styles$h = {"trigger":"es-trigger-w-aUi","colorPreview":"es-colorPreview-SUgiJ","colorValue":"es-colorValue-cYdRP","popover":"es-popover-SfIUB"};
2143
-
2144
- const ColorSetter = props => {
2145
- const {
2146
- value,
2147
- initialValue,
2148
- onChange,
2149
- disableAlpha = false
2150
- } = props;
2151
- const [open, setOpen] = useState(false);
2152
- return /*#__PURE__*/React.createElement(Popover, {
2153
- onClose: () => setOpen(false),
2154
- open: open,
2155
- trigger: /*#__PURE__*/React.createElement("button", {
2156
- "aria-label": "Select color",
2157
- className: styles$h.trigger,
2158
- onClick: () => setOpen(true),
2159
- type: "button"
2160
- }, /*#__PURE__*/React.createElement("div", {
2161
- "aria-label": "Current color",
2162
- className: styles$h.colorPreview,
2163
- style: {
2164
- backgroundColor: value ?? initialValue
2165
- }
2166
- }), /*#__PURE__*/React.createElement("span", {
2167
- className: styles$h.colorValue
2168
- }, value ?? initialValue))
2169
- }, /*#__PURE__*/React.createElement("div", {
2170
- className: styles$h.popover
2171
- }, /*#__PURE__*/React.createElement(Sketch, {
2172
- color: value,
2173
- disableAlpha: disableAlpha,
2174
- onChange: res => onChange(res.hexa),
2175
- presetColors: []
2176
- })));
2177
- };
2178
-
2179
- var styles$g = {"trigger":"es-trigger-fTNvQ","triggerIcon":"es-triggerIcon-1mdQ0","triggerIconPrimary":"es-triggerIconPrimary-opifh","triggerIconMuted":"es-triggerIconMuted-CWgDl","triggerText":"es-triggerText-WeQRu","popoverContent":"es-popoverContent-6qE--","tabsList":"es-tabsList-liSeY","tabTrigger":"es-tabTrigger-6j7K-","tabTriggerActive":"es-tabTriggerActive-g6hcl","tabTriggerIcon":"es-tabTriggerIcon-dRSAp","tabContent":"es-tabContent--H166","tabContentActive":"es-tabContentActive-Fjdu5","section":"es-section-eDYxd","sectionLabel":"es-sectionLabel--LHE8","input":"es-input--OymK","inputMono":"es-inputMono-pCJz3","textarea":"es-textarea-iurkc","booleanButtons":"es-booleanButtons-0bM8P","booleanButton":"es-booleanButton-3fXcB","booleanButtonActive":"es-booleanButtonActive-zGWrZ","datasourceList":"es-datasourceList-VIRXb","datasourceButton":"es-datasourceButton-giz6D","datasourceButtonActive":"es-datasourceButtonActive-m5WPP","datasourceIcon":"es-datasourceIcon-q9Omt","emptyState":"es-emptyState-rI2si","hint":"es-hint-zfWLZ","preview":"es-preview-tUInw"};
2180
-
2181
- const defaultValue$2 = {
2182
- type: 'static',
2183
- staticValue: ''
2184
- };
2185
- const DataBindingSetter = props => {
2186
- const {
2187
- value,
2188
- initialValue,
2189
- onChange,
2190
- dataType = 'any',
2191
- showPreview = true,
2192
- dataSources = []
2193
- } = props;
2194
- const currentValue = value ?? initialValue ?? defaultValue$2;
2195
- const [open, setOpen] = useState(false);
2196
- const [activeTab, setActiveTab] = useState(currentValue.type);
2197
- const updateBinding = useCallback(updates => {
2198
- onChange({
2199
- ...currentValue,
2200
- ...updates
2201
- });
2202
- }, [currentValue, onChange]);
2203
- const handleTypeChange = useCallback(type => {
2204
- setActiveTab(type);
2205
- updateBinding({
2206
- type
2207
- });
2208
- }, [updateBinding]);
2209
- const handleStaticValueChange = useCallback(staticValue => {
2210
- updateBinding({
2211
- staticValue
2212
- });
2213
- }, [updateBinding]);
2214
- const handleDatasourceChange = useCallback(datasourceId => {
2215
- updateBinding({
2216
- datasourceId,
2217
- datasourcePath: ''
2218
- });
2219
- }, [updateBinding]);
2220
- const handlePathChange = useCallback(datasourcePath => {
2221
- updateBinding({
2222
- datasourcePath
2223
- });
2224
- }, [updateBinding]);
2225
-
2226
- // 渲染静态值输入
2227
- const renderStaticInput = useMemo(() => {
2228
- switch (dataType) {
2229
- case 'number':
2230
- return /*#__PURE__*/React.createElement("input", {
2231
- className: styles$g.input,
2232
- onChange: e => handleStaticValueChange(Number(e.target.value)),
2233
- placeholder: "\u8F93\u5165\u6570\u503C",
2234
- type: "number",
2235
- value: currentValue.staticValue ?? ''
2236
- });
2237
- case 'boolean':
2238
- return /*#__PURE__*/React.createElement("div", {
2239
- className: styles$g.booleanButtons
2240
- }, /*#__PURE__*/React.createElement("button", {
2241
- className: cn(styles$g.booleanButton, currentValue.staticValue === true ? styles$g.booleanButtonActive : ''),
2242
- onClick: () => handleStaticValueChange(true),
2243
- type: "button"
2244
- }, "True"), /*#__PURE__*/React.createElement("button", {
2245
- className: cn(styles$g.booleanButton, currentValue.staticValue === false ? styles$g.booleanButtonActive : ''),
2246
- onClick: () => handleStaticValueChange(false),
2247
- type: "button"
2248
- }, "False"));
2249
- case 'array':
2250
- case 'object':
2251
- return /*#__PURE__*/React.createElement("textarea", {
2252
- className: styles$g.textarea,
2253
- onChange: e => {
2254
- try {
2255
- const parsed = JSON.parse(e.target.value);
2256
- handleStaticValueChange(parsed);
2257
- } catch {
2258
- handleStaticValueChange(e.target.value);
2259
- }
2260
- },
2261
- placeholder: dataType === 'array' ? '["item1", "item2"]' : '{"key": "value"}',
2262
- value: typeof currentValue.staticValue === 'string' ? currentValue.staticValue : JSON.stringify(currentValue.staticValue, null, 2) ?? ''
2263
- });
2264
- default:
2265
- return /*#__PURE__*/React.createElement("input", {
2266
- className: styles$g.input,
2267
- onChange: e => handleStaticValueChange(e.target.value),
2268
- placeholder: "\u8F93\u5165\u503C",
2269
- type: "text",
2270
- value: currentValue.staticValue ?? ''
2271
- });
2272
- }
2273
- }, [dataType, currentValue.staticValue, handleStaticValueChange]);
2274
-
2275
- // 绑定状态显示
2276
- const bindingStatus = useMemo(() => {
2277
- if (currentValue.type === 'datasource' && currentValue.datasourceId) {
2278
- const ds = dataSources.find(d => d.id === currentValue.datasourceId);
2279
- return {
2280
- icon: /*#__PURE__*/React.createElement(Link2, {
2281
- className: cn(styles$g.triggerIcon, styles$g.triggerIconPrimary)
2282
- }),
2283
- text: `${ds?.name ?? currentValue.datasourceId}${currentValue.datasourcePath ? `.${currentValue.datasourcePath}` : ''}`
2284
- };
2285
- }
2286
- return {
2287
- icon: /*#__PURE__*/React.createElement(FileBraces, {
2288
- className: cn(styles$g.triggerIcon, styles$g.triggerIconMuted)
2289
- }),
2290
- text: '静态数据'
2291
- };
2292
- }, [currentValue, dataSources]);
2293
- return /*#__PURE__*/React.createElement(Popover, {
2294
- onClose: () => setOpen(false),
2295
- open: open,
2296
- trigger: /*#__PURE__*/React.createElement("button", {
2297
- "aria-label": "Data binding",
2298
- className: styles$g.trigger,
2299
- onClick: () => setOpen(true),
2300
- type: "button"
2301
- }, bindingStatus.icon, /*#__PURE__*/React.createElement("span", {
2302
- className: styles$g.triggerText
2303
- }, bindingStatus.text)),
2304
- width: 300
2305
- }, /*#__PURE__*/React.createElement("div", {
2306
- className: styles$g.popoverContent
2307
- }, /*#__PURE__*/React.createElement("div", {
2308
- className: styles$g.tabsList,
2309
- role: "tablist"
2310
- }, /*#__PURE__*/React.createElement("button", {
2311
- "aria-selected": activeTab === 'static',
2312
- className: cn(styles$g.tabTrigger, activeTab === 'static' ? styles$g.tabTriggerActive : ''),
2313
- onClick: () => handleTypeChange('static'),
2314
- role: "tab",
2315
- type: "button"
2316
- }, /*#__PURE__*/React.createElement(FileBraces, {
2317
- className: styles$g.tabTriggerIcon
2318
- }), "\u9759\u6001\u6570\u636E"), /*#__PURE__*/React.createElement("button", {
2319
- "aria-selected": activeTab === 'datasource',
2320
- className: cn(styles$g.tabTrigger, activeTab === 'datasource' ? styles$g.tabTriggerActive : ''),
2321
- onClick: () => handleTypeChange('datasource'),
2322
- role: "tab",
2323
- type: "button"
2324
- }, /*#__PURE__*/React.createElement(Database, {
2325
- className: styles$g.tabTriggerIcon
2326
- }), "\u6570\u636E\u6E90")), /*#__PURE__*/React.createElement("div", {
2327
- className: cn(styles$g.tabContent, activeTab === 'static' ? styles$g.tabContentActive : ''),
2328
- role: "tabpanel"
2329
- }, /*#__PURE__*/React.createElement("div", {
2330
- className: styles$g.section
2331
- }, /*#__PURE__*/React.createElement("span", {
2332
- className: styles$g.sectionLabel
2333
- }, "\u503C (", dataType, ")"), renderStaticInput)), /*#__PURE__*/React.createElement("div", {
2334
- className: cn(styles$g.tabContent, activeTab === 'datasource' ? styles$g.tabContentActive : ''),
2335
- role: "tabpanel"
2336
- }, /*#__PURE__*/React.createElement("div", {
2337
- className: styles$g.section
2338
- }, /*#__PURE__*/React.createElement("span", {
2339
- className: styles$g.sectionLabel
2340
- }, "\u6570\u636E\u6E90"), dataSources.length > 0 ? /*#__PURE__*/React.createElement("div", {
2341
- className: styles$g.datasourceList
2342
- }, dataSources.map(ds => /*#__PURE__*/React.createElement("button", {
2343
- className: cn(styles$g.datasourceButton, currentValue.datasourceId === ds.id ? styles$g.datasourceButtonActive : ''),
2344
- key: ds.id,
2345
- onClick: () => handleDatasourceChange(ds.id),
2346
- type: "button"
2347
- }, /*#__PURE__*/React.createElement(Database, {
2348
- className: styles$g.datasourceIcon
2349
- }), ds.name))) : /*#__PURE__*/React.createElement("div", {
2350
- className: styles$g.emptyState
2351
- }, "\u6682\u65E0\u53EF\u7528\u6570\u636E\u6E90"), currentValue.datasourceId ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
2352
- className: styles$g.sectionLabel
2353
- }, "\u6570\u636E\u8DEF\u5F84"), /*#__PURE__*/React.createElement("input", {
2354
- className: cn(styles$g.input, styles$g.inputMono),
2355
- onChange: e => handlePathChange(e.target.value),
2356
- placeholder: "data.list[0].name",
2357
- type: "text",
2358
- value: currentValue.datasourcePath ?? ''
2359
- }), /*#__PURE__*/React.createElement("span", {
2360
- className: styles$g.hint
2361
- }, "\u4F7F\u7528\u70B9\u53F7\u8BBF\u95EE\u5D4C\u5957\u5C5E\u6027\uFF0C\u5982: data.items[0].value")) : null, showPreview === true && currentValue.datasourceId ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
2362
- className: styles$g.sectionLabel
2363
- }, "\u6570\u636E\u9884\u89C8"), /*#__PURE__*/React.createElement("div", {
2364
- className: styles$g.preview
2365
- }, "\u7ED1\u5B9A\u540E\u53EF\u5728\u9884\u89C8\u6A21\u5F0F\u67E5\u770B\u6570\u636E")) : null))));
2366
- };
2367
-
2368
- var styles$f = {"trigger":"es-trigger-rmYLl","triggerIcon":"es-triggerIcon-ktlTS","triggerText":"es-triggerText-B63By","popoverContent":"es-popoverContent-IIcFY","header":"es-header-VoKF3","headerTitle":"es-headerTitle-vDZR8","headerCount":"es-headerCount-stTlN","mappingList":"es-mappingList-SLqhN","mappingItem":"es-mappingItem-xtRLl","mappingHeader":"es-mappingHeader-LwKiY","mappingTitle":"es-mappingTitle-IMhzw","mappingRequired":"es-mappingRequired-tP6L-","mappingType":"es-mappingType-nyqrh","mappingRow":"es-mappingRow-lFfhT","select":"es-select-R4pIl","input":"es-input--LohJ","arrowIcon":"es-arrowIcon-QqWMM","targetField":"es-targetField-gSvGk","transformRow":"es-transformRow-O6MAG","transformIcon":"es-transformIcon-beXzy","transformInput":"es-transformInput-SyN2q","clearButton":"es-clearButton-Pm-uP","helpText":"es-helpText-IHqjo"};
2369
-
2370
- const defaultValue$1 = {
2371
- mappings: []
2372
- };
2373
- const DataMappingSetter = props => {
2374
- const {
2375
- value,
2376
- initialValue,
2377
- onChange,
2378
- targetFields,
2379
- sourceFields = []
2380
- } = props;
2381
- const currentValue = value ?? initialValue ?? defaultValue$1;
2382
- const [open, setOpen] = useState(false);
2383
-
2384
- // 获取字段的映射
2385
- const getMapping = useCallback(targetField => currentValue.mappings.find(m => m.targetField === targetField), [currentValue.mappings]);
2386
-
2387
- // 更新映射
2388
- const updateMapping = useCallback((targetField, updates) => {
2389
- const existingIndex = currentValue.mappings.findIndex(m => m.targetField === targetField);
2390
- const newMappings = [...currentValue.mappings];
2391
- if (existingIndex >= 0) {
2392
- newMappings[existingIndex] = {
2393
- ...newMappings[existingIndex],
2394
- ...updates
2395
- };
2396
- } else {
2397
- newMappings.push({
2398
- targetField,
2399
- sourceField: updates.sourceField ?? '',
2400
- transform: updates.transform
2401
- });
2402
- }
2403
- onChange({
2404
- mappings: newMappings
2405
- });
2406
- }, [currentValue.mappings, onChange]);
2407
-
2408
- // 清除映射
2409
- const clearMapping = useCallback(targetField => {
2410
- const newMappings = currentValue.mappings.filter(m => m.targetField !== targetField);
2411
- onChange({
2412
- mappings: newMappings
2413
- });
2414
- }, [currentValue.mappings, onChange]);
2415
-
2416
- // 统计已映射字段数
2417
- const mappedCount = currentValue.mappings.filter(m => m.sourceField).length;
2418
- return /*#__PURE__*/React.createElement(Popover, {
2419
- onClose: () => setOpen(false),
2420
- open: open,
2421
- trigger: /*#__PURE__*/React.createElement("button", {
2422
- "aria-label": "Data mapping",
2423
- className: styles$f.trigger,
2424
- onClick: () => setOpen(true),
2425
- type: "button"
2426
- }, /*#__PURE__*/React.createElement(Settings2, {
2427
- className: styles$f.triggerIcon
2428
- }), /*#__PURE__*/React.createElement("span", {
2429
- className: styles$f.triggerText
2430
- }, "\u5B57\u6BB5\u6620\u5C04 (", mappedCount, "/", targetFields.length, ")")),
2431
- width: 320
2432
- }, /*#__PURE__*/React.createElement("div", {
2433
- className: styles$f.popoverContent
2434
- }, /*#__PURE__*/React.createElement("div", {
2435
- className: styles$f.header
2436
- }, /*#__PURE__*/React.createElement("span", {
2437
- className: styles$f.headerTitle
2438
- }, "\u5B57\u6BB5\u6620\u5C04\u914D\u7F6E"), /*#__PURE__*/React.createElement("span", {
2439
- className: styles$f.headerCount
2440
- }, mappedCount, "/", targetFields.length, " \u5DF2\u6620\u5C04")), /*#__PURE__*/React.createElement("div", {
2441
- className: styles$f.mappingList
2442
- }, targetFields.map(field => {
2443
- const mapping = getMapping(field.name);
2444
- return /*#__PURE__*/React.createElement("div", {
2445
- className: styles$f.mappingItem,
2446
- key: field.name
2447
- }, /*#__PURE__*/React.createElement("div", {
2448
- className: styles$f.mappingHeader
2449
- }, /*#__PURE__*/React.createElement("span", {
2450
- className: styles$f.mappingTitle
2451
- }, field.label, field.required ? /*#__PURE__*/React.createElement("span", {
2452
- className: styles$f.mappingRequired
2453
- }, "*") : null), /*#__PURE__*/React.createElement("span", {
2454
- className: styles$f.mappingType
2455
- }, field.type)), /*#__PURE__*/React.createElement("div", {
2456
- className: styles$f.mappingRow
2457
- }, sourceFields.length > 0 ? /*#__PURE__*/React.createElement("select", {
2458
- className: styles$f.select,
2459
- onChange: e => updateMapping(field.name, {
2460
- sourceField: e.target.value
2461
- }),
2462
- value: mapping?.sourceField ?? ''
2463
- }, /*#__PURE__*/React.createElement("option", {
2464
- value: ""
2465
- }, "\u9009\u62E9\u5B57\u6BB5"), sourceFields.map(sf => /*#__PURE__*/React.createElement("option", {
2466
- key: sf,
2467
- value: sf
2468
- }, sf))) : /*#__PURE__*/React.createElement("input", {
2469
- className: styles$f.input,
2470
- onChange: e => updateMapping(field.name, {
2471
- sourceField: e.target.value
2472
- }),
2473
- placeholder: "\u6E90\u5B57\u6BB5\u8DEF\u5F84",
2474
- type: "text",
2475
- value: mapping?.sourceField ?? ''
2476
- }), /*#__PURE__*/React.createElement(ArrowRight, {
2477
- className: styles$f.arrowIcon
2478
- }), /*#__PURE__*/React.createElement("div", {
2479
- className: styles$f.targetField
2480
- }, field.name)), mapping?.sourceField ? /*#__PURE__*/React.createElement("div", {
2481
- className: styles$f.transformRow
2482
- }, /*#__PURE__*/React.createElement(Code, {
2483
- className: styles$f.transformIcon
2484
- }), /*#__PURE__*/React.createElement("input", {
2485
- className: styles$f.transformInput,
2486
- onChange: e => updateMapping(field.name, {
2487
- transform: e.target.value
2488
- }),
2489
- placeholder: "\u8F6C\u6362\u8868\u8FBE\u5F0F (\u53EF\u9009)",
2490
- type: "text",
2491
- value: mapping?.transform ?? ''
2492
- })) : null, mapping?.sourceField ? /*#__PURE__*/React.createElement("button", {
2493
- className: styles$f.clearButton,
2494
- onClick: () => clearMapping(field.name),
2495
- type: "button"
2496
- }, "\u6E05\u9664\u6620\u5C04") : null);
2497
- })), /*#__PURE__*/React.createElement("div", {
2498
- className: styles$f.helpText
2499
- }, /*#__PURE__*/React.createElement("p", null, "\u2022 \u6E90\u5B57\u6BB5: \u6570\u636E\u6E90\u4E2D\u7684\u5B57\u6BB5\u8DEF\u5F84"), /*#__PURE__*/React.createElement("p", null, "\u2022 \u8F6C\u6362\u8868\u8FBE\u5F0F: \u5982 value * 100, value.toFixed(2)"))));
2500
- };
2501
-
2502
- var styles$e = {"container":"es-container-CUmyq","textarea":"es-textarea-hn1hD","textareaError":"es-textareaError-O2GWs","error":"es-error-wjKcS"};
2503
-
2504
- const JsonSetter = props => {
2505
- const {
2506
- value,
2507
- initialValue,
2508
- placeholder,
2509
- rows = 6,
2510
- onChange
2511
- } = props;
2512
- const [text, setText] = useState('');
2513
- const [error, setError] = useState(null);
2514
-
2515
- // Sync value to text
2516
- useEffect(() => {
2517
- const currentValue = value ?? initialValue;
2518
- if (currentValue !== undefined) {
2519
- try {
2520
- setText(JSON.stringify(currentValue, null, 2));
2521
- setError(null);
2522
- } catch {
2523
- setText(String(currentValue));
2524
- }
2525
- } else {
2526
- setText('');
2527
- }
2528
- }, [value, initialValue]);
2529
- const handleChange = useCallback(newText => {
2530
- setText(newText);
2531
- if (!newText.trim()) {
2532
- setError(null);
2533
- onChange(undefined);
2534
- return;
2535
- }
2536
- try {
2537
- const parsed = JSON.parse(newText);
2538
- setError(null);
2539
- onChange(parsed);
2540
- } catch (e) {
2541
- setError(e.message);
2542
- }
2543
- }, [onChange]);
2544
- const lineHeight = 1.5;
2545
- const minHeight = rows * lineHeight * 14; // 14px base font size
2546
-
2547
- return /*#__PURE__*/React.createElement("div", {
2548
- className: styles$e.container
2549
- }, /*#__PURE__*/React.createElement("textarea", {
2550
- className: cn(styles$e.textarea, error ? styles$e.textareaError : null),
2551
- onChange: e => handleChange(e.target.value),
2552
- placeholder: placeholder || '输入 JSON 数据',
2553
- spellCheck: false,
2554
- style: {
2555
- minHeight
2556
- },
2557
- value: text
2558
- }), error ? /*#__PURE__*/React.createElement("div", {
2559
- className: styles$e.error
2560
- }, error) : null);
2561
- };
2562
-
2563
- var styles$d = {"container":"es-container-som8X","id":"es-id-VnRzV","title":"es-title-B-JkN"};
2564
-
2565
- const NodeIdSetter = props => {
2566
- const {
2567
- selected
2568
- } = props;
2569
- return /*#__PURE__*/React.createElement("div", {
2570
- className: styles$d.container
2571
- }, /*#__PURE__*/React.createElement("p", {
2572
- className: styles$d.id
2573
- }, selected.id), /*#__PURE__*/React.createElement("p", {
2574
- className: styles$d.title
2575
- }, selected.componentMeta.title));
2576
- };
2577
-
2578
- var styles$c = {"container":"es-container-d6iPo","input":"es-input-hzqco","inputWithSuffix":"es-inputWithSuffix-dzHIR","suffix":"es-suffix--jLoo"};
2579
-
2580
- const NumberSetter = props => {
2581
- const {
2582
- value,
2583
- initialValue,
2584
- placeholder,
2585
- onChange,
2586
- suffix
2587
- } = props;
2588
- return /*#__PURE__*/React.createElement("div", {
2589
- className: styles$c.container
2590
- }, /*#__PURE__*/React.createElement("input", {
2591
- className: cn(styles$c.input, suffix ? styles$c.inputWithSuffix : ''),
2592
- onChange: e => onChange(+e.target.value),
2593
- placeholder: placeholder || '',
2594
- type: "number",
2595
- value: value ?? initialValue ?? ''
2596
- }), suffix ? /*#__PURE__*/React.createElement("span", {
2597
- "aria-label": `Unit: ${suffix}`,
2598
- className: styles$c.suffix
2599
- }, suffix) : null);
2600
- };
2601
-
2602
- var styles$b = {"container":"es-container-RzrEe","field":"es-field-AaNu3","label":"es-label-zWfmB","input":"es-input-fv7wH","customField":"es-customField-hV2yY","customFieldInputs":"es-customFieldInputs-efA5X","keyInput":"es-keyInput-MXoPV","removeButton":"es-removeButton-s7K9l","removeIcon":"es-removeIcon-Ostpz","addButton":"es-addButton-Wgly5","addIcon":"es-addIcon-61nc3"};
2603
-
2604
- const ObjectSetter = props => {
2605
- const {
2606
- value,
2607
- initialValue,
2608
- fields = [],
2609
- allowCustomFields = false,
2610
- addFieldText = '添加字段',
2611
- onChange
2612
- } = props;
2613
- const currentValue = value ?? initialValue ?? {};
2614
- const handleFieldChange = useCallback((key, newValue) => {
2615
- onChange({
2616
- ...currentValue,
2617
- [key]: newValue
2618
- });
2619
- }, [currentValue, onChange]);
2620
- const handleAddField = useCallback(() => {
2621
- const newKey = `field_${Date.now()}`;
2622
- onChange({
2623
- ...currentValue,
2624
- [newKey]: ''
2625
- });
2626
- }, [currentValue, onChange]);
2627
- const handleRemoveField = useCallback(key => {
2628
- const newValue = {
2629
- ...currentValue
2630
- };
2631
- delete newValue[key];
2632
- onChange(newValue);
2633
- }, [currentValue, onChange]);
2634
-
2635
- // Get all keys: defined fields + custom fields
2636
- const definedKeys = fields.map(f => f.key);
2637
- const customKeys = Object.keys(currentValue).filter(k => !definedKeys.includes(k));
2638
- return /*#__PURE__*/React.createElement("div", {
2639
- className: styles$b.container
2640
- }, fields.map(field => /*#__PURE__*/React.createElement("div", {
2641
- className: styles$b.field,
2642
- key: field.key
2643
- }, /*#__PURE__*/React.createElement("span", {
2644
- className: styles$b.label
2645
- }, field.label), /*#__PURE__*/React.createElement("input", {
2646
- className: styles$b.input,
2647
- onChange: e => {
2648
- const val = field.type === 'number' ? +e.target.value : e.target.value;
2649
- handleFieldChange(field.key, val);
2650
- },
2651
- placeholder: field.placeholder,
2652
- type: field.type === 'number' ? 'number' : 'text',
2653
- value: currentValue[field.key] ?? ''
2654
- }))), customKeys.map(key => /*#__PURE__*/React.createElement("div", {
2655
- className: styles$b.customField,
2656
- key: key
2657
- }, /*#__PURE__*/React.createElement("div", {
2658
- className: styles$b.customFieldInputs
2659
- }, /*#__PURE__*/React.createElement("input", {
2660
- className: styles$b.keyInput,
2661
- onChange: e => {
2662
- const newKey = e.target.value;
2663
- if (newKey && newKey !== key) {
2664
- const newValue = {
2665
- ...currentValue
2666
- };
2667
- newValue[newKey] = newValue[key];
2668
- delete newValue[key];
2669
- onChange(newValue);
2670
- }
2671
- },
2672
- placeholder: "\u5B57\u6BB5\u540D",
2673
- type: "text",
2674
- value: key
2675
- }), /*#__PURE__*/React.createElement("input", {
2676
- className: styles$b.input,
2677
- onChange: e => handleFieldChange(key, e.target.value),
2678
- placeholder: "\u503C",
2679
- type: "text",
2680
- value: currentValue[key] ?? ''
2681
- })), /*#__PURE__*/React.createElement("button", {
2682
- className: styles$b.removeButton,
2683
- onClick: () => handleRemoveField(key),
2684
- type: "button"
2685
- }, /*#__PURE__*/React.createElement(Trash2, {
2686
- className: styles$b.removeIcon
2687
- })))), allowCustomFields ? /*#__PURE__*/React.createElement("button", {
2688
- className: styles$b.addButton,
2689
- onClick: handleAddField,
2690
- type: "button"
2691
- }, /*#__PURE__*/React.createElement(Plus, {
2692
- className: styles$b.addIcon
2693
- }), addFieldText) : null);
2694
- };
2695
-
2696
- var styles$a = {"container":"es-container-YWSlG","inputWrapper":"es-inputWrapper-B2wKI","input":"es-input--qUrU","suffix":"es-suffix-2c3Cd"};
2697
-
2698
- const RectSetter = props => {
2699
- const {
2700
- value,
2701
- onChange
2702
- } = props;
2703
- const handleChange = (key, newValue) => {
2704
- onChange({
2705
- ...value,
2706
- [key]: newValue
2707
- });
2708
- };
2709
- return /*#__PURE__*/React.createElement("div", {
2710
- className: styles$a.container
2711
- }, /*#__PURE__*/React.createElement("div", {
2712
- className: styles$a.inputWrapper
2713
- }, /*#__PURE__*/React.createElement("input", {
2714
- className: styles$a.input,
2715
- onChange: e => handleChange('x', Number(e.target.value)),
2716
- type: "number",
2717
- value: formatDecimal(value.x)
2718
- }), /*#__PURE__*/React.createElement("span", {
2719
- "aria-label": "Unit: X",
2720
- className: styles$a.suffix
2721
- }, "X")), /*#__PURE__*/React.createElement("div", {
2722
- className: styles$a.inputWrapper
2723
- }, /*#__PURE__*/React.createElement("input", {
2724
- className: styles$a.input,
2725
- onChange: e => handleChange('y', Number(e.target.value)),
2726
- type: "number",
2727
- value: formatDecimal(value.y)
2728
- }), /*#__PURE__*/React.createElement("span", {
2729
- "aria-label": "Unit: Y",
2730
- className: styles$a.suffix
2731
- }, "Y")), /*#__PURE__*/React.createElement("div", {
2732
- className: styles$a.inputWrapper
2733
- }, /*#__PURE__*/React.createElement("input", {
2734
- className: styles$a.input,
2735
- onChange: e => handleChange('width', Number(e.target.value)),
2736
- type: "number",
2737
- value: formatDecimal(value.width)
2738
- }), /*#__PURE__*/React.createElement("span", {
2739
- "aria-label": "Unit: W",
2740
- className: styles$a.suffix
2741
- }, "W")), /*#__PURE__*/React.createElement("div", {
2742
- className: styles$a.inputWrapper
2743
- }, /*#__PURE__*/React.createElement("input", {
2744
- className: styles$a.input,
2745
- onChange: e => handleChange('height', Number(e.target.value)),
2746
- type: "number",
2747
- value: formatDecimal(value.height)
2748
- }), /*#__PURE__*/React.createElement("span", {
2749
- "aria-label": "Unit: H",
2750
- className: styles$a.suffix
2751
- }, "H")));
2752
- };
2753
- const decimalRegex = /(\.\d{2})\d+$/;
2754
- const formatDecimal = num => num.toString().replace(decimalRegex, '$1');
2755
-
2756
- var styles$9 = {"container":"es-container-lamwH","containerSm":"es-containerSm-mndNj","segment":"es-segment-JmKWl","segmentSelected":"es-segmentSelected-fumXM","segmentDisabled":"es-segmentDisabled-Md5LF"};
2757
-
2758
- /**
2759
- * SegmentedSetter - 分段控制器
2760
- * 用于在多个选项之间切换,类似于 iOS 的 UISegmentedControl
2761
- */
2762
- const SegmentedSetter = props => {
2763
- const {
2764
- value,
2765
- initialValue,
2766
- options = [],
2767
- onChange,
2768
- size = 'md'
2769
- } = props;
2770
- const currentValue = value ?? initialValue ?? options[0]?.value ?? '';
2771
- return /*#__PURE__*/React.createElement("div", {
2772
- className: cn(styles$9.container, size === 'sm' ? styles$9.containerSm : '')
2773
- }, options.map(option => /*#__PURE__*/React.createElement("button", {
2774
- className: cn(styles$9.segment, currentValue === option.value ? styles$9.segmentSelected : '', option.disabled === true ? styles$9.segmentDisabled : ''),
2775
- disabled: option.disabled,
2776
- key: option.value,
2777
- onClick: () => !option.disabled && onChange(option.value),
2778
- type: "button"
2779
- }, option.label)));
2780
- };
2781
-
2782
- var styles$8 = {"trigger":"es-trigger-YRz9p","triggerValue":"es-triggerValue-k-g2-","placeholder":"es-placeholder-F8-XP","chevron":"es-chevron-UbZv-","chevronOpen":"es-chevronOpen-Yui-r","dropdown":"es-dropdown-l2sra","option":"es-option-cv-7C","optionSelected":"es-optionSelected-K4e5h","optionDisabled":"es-optionDisabled-72jrC"};
2783
-
2784
- const SelectSetter = props => {
2785
- const {
2786
- value,
2787
- initialValue,
2788
- options = [],
2789
- placeholder,
2790
- onChange
2791
- } = props;
2792
- const [open, setOpen] = useState(false);
2793
- const currentValue = value ?? initialValue ?? '';
2794
- const selectedOption = options.find(opt => opt.value === currentValue);
2795
- const handleSelect = (optionValue, disabled) => {
2796
- if (disabled) {
2797
- return;
2798
- }
2799
- onChange(optionValue);
2800
- setOpen(false);
2801
- };
2802
- return /*#__PURE__*/React.createElement(Popover, {
2803
- onClose: () => setOpen(false),
2804
- open: open,
2805
- trigger: /*#__PURE__*/React.createElement("button", {
2806
- "aria-expanded": open,
2807
- "aria-haspopup": "listbox",
2808
- className: styles$8.trigger,
2809
- onClick: () => setOpen(true),
2810
- type: "button"
2811
- }, /*#__PURE__*/React.createElement("span", {
2812
- className: cn(styles$8.triggerValue, selectedOption ? '' : styles$8.placeholder)
2813
- }, selectedOption?.label || placeholder || '请选择'), /*#__PURE__*/React.createElement(ChevronDown, {
2814
- className: cn(styles$8.chevron, open ? styles$8.chevronOpen : '')
2815
- }))
2816
- }, /*#__PURE__*/React.createElement("div", {
2817
- className: styles$8.dropdown,
2818
- role: "listbox"
2819
- }, options.map(option => /*#__PURE__*/React.createElement("button", {
2820
- "aria-selected": option.value === currentValue,
2821
- className: cn(styles$8.option, option.value === currentValue ? styles$8.optionSelected : '', option.disabled === true ? styles$8.optionDisabled : ''),
2822
- key: option.value,
2823
- onClick: () => handleSelect(option.value, option.disabled),
2824
- role: "option",
2825
- type: "button"
2826
- }, option.label))));
2827
- };
2828
-
2829
- var styles$7 = {"container":"es-container-PG1Uy","slider":"es-slider-pypb6","track":"es-track-X2NtH","range":"es-range-AVV8x","thumb":"es-thumb-YMQR-","value":"es-value-JiWPV"};
2830
-
2831
- const SliderSetter = props => {
2832
- const {
2833
- value,
2834
- initialValue,
2835
- min = 0,
2836
- max = 100,
2837
- step = 1,
2838
- showValue = true,
2839
- suffix,
2840
- onChange
2841
- } = props;
2842
- const currentValue = value ?? initialValue ?? min;
2843
- const trackRef = useRef(null);
2844
- const percentage = (currentValue - min) / (max - min) * 100;
2845
- const handleChange = useCallback(clientX => {
2846
- if (!trackRef.current) {
2847
- return;
2848
- }
2849
- const rect = trackRef.current.getBoundingClientRect();
2850
- const percent = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
2851
- const rawValue = min + percent * (max - min);
2852
- const steppedValue = Math.round(rawValue / step) * step;
2853
- const clampedValue = Math.max(min, Math.min(max, steppedValue));
2854
- onChange(clampedValue);
2855
- }, [min, max, step, onChange]);
2856
- const handleMouseDown = event => {
2857
- handleChange(event.clientX);
2858
- const handleMouseMove = moveEvent => {
2859
- handleChange(moveEvent.clientX);
2860
- };
2861
- const handleMouseUp = () => {
2862
- document.removeEventListener('mousemove', handleMouseMove);
2863
- document.removeEventListener('mouseup', handleMouseUp);
2864
- };
2865
- document.addEventListener('mousemove', handleMouseMove);
2866
- document.addEventListener('mouseup', handleMouseUp);
2867
- };
2868
- return /*#__PURE__*/React.createElement("div", {
2869
- className: styles$7.container
2870
- }, /*#__PURE__*/React.createElement("div", {
2871
- className: styles$7.slider
2872
- }, /*#__PURE__*/React.createElement("div", {
2873
- className: styles$7.track,
2874
- onMouseDown: handleMouseDown,
2875
- ref: trackRef,
2876
- role: "presentation"
2877
- }, /*#__PURE__*/React.createElement("div", {
2878
- className: styles$7.range,
2879
- style: {
2880
- width: `${percentage}%`
2881
- }
2882
- }), /*#__PURE__*/React.createElement("div", {
2883
- "aria-valuemax": max,
2884
- "aria-valuemin": min,
2885
- "aria-valuenow": currentValue,
2886
- className: styles$7.thumb,
2887
- role: "slider",
2888
- style: {
2889
- left: `${percentage}%`
2890
- },
2891
- tabIndex: 0
2892
- }))), showValue === true ? /*#__PURE__*/React.createElement("span", {
2893
- className: styles$7.value
2894
- }, currentValue, suffix) : null);
2895
- };
2896
-
2897
- var styles$6 = {"container":"es-container-XqQza","boxModel":"es-boxModel-8RFjI","inputTop":"es-inputTop-bqsmI","inputRight":"es-inputRight-TV3E-","inputBottom":"es-inputBottom-dP-wA","inputLeft":"es-inputLeft-sygc3","spacingInput":"es-spacingInput-KAWdK","linkButton":"es-linkButton-v1n0k","linkButtonActive":"es-linkButtonActive-Vge1n","linkIcon":"es-linkIcon-K0j9e","presets":"es-presets-CPVVc","presetButton":"es-presetButton-vUc7S","modeLabel":"es-modeLabel-Vh1Cf"};
2898
-
2899
- const defaultValue = {
2900
- top: 0,
2901
- right: 0,
2902
- bottom: 0,
2903
- left: 0
2904
- };
2905
- const presetValues = [0, 4, 8, 12, 16, 24, 32];
2906
- const SpacingSetter = props => {
2907
- const {
2908
- value,
2909
- initialValue,
2910
- onChange,
2911
- mode = 'padding',
2912
- linked: initialLinked = false,
2913
- min = 0,
2914
- max = 100
2915
- } = props;
2916
- const currentValue = value ?? initialValue ?? defaultValue;
2917
- const [isLinked, setIsLinked] = useState(initialLinked);
2918
- const updateSpacing = useCallback(updates => {
2919
- if (isLinked) {
2920
- const newValue = Object.values(updates)[0];
2921
- onChange({
2922
- top: newValue,
2923
- right: newValue,
2924
- bottom: newValue,
2925
- left: newValue
2926
- });
2927
- } else {
2928
- onChange({
2929
- ...currentValue,
2930
- ...updates
2931
- });
2932
- }
2933
- }, [currentValue, isLinked, onChange]);
2934
- const handlePresetClick = useCallback(presetValue => {
2935
- onChange({
2936
- top: presetValue,
2937
- right: presetValue,
2938
- bottom: presetValue,
2939
- left: presetValue
2940
- });
2941
- }, [onChange]);
2942
- const toggleLinked = useCallback(() => {
2943
- setIsLinked(prev => !prev);
2944
- }, []);
2945
- return /*#__PURE__*/React.createElement("div", {
2946
- className: styles$6.container
2947
- }, /*#__PURE__*/React.createElement("div", {
2948
- className: styles$6.boxModel
2949
- }, /*#__PURE__*/React.createElement("div", {
2950
- className: styles$6.inputTop
2951
- }, /*#__PURE__*/React.createElement("input", {
2952
- className: styles$6.spacingInput,
2953
- max: max,
2954
- min: min,
2955
- onChange: e => updateSpacing({
2956
- top: Number(e.target.value)
2957
- }),
2958
- type: "number",
2959
- value: currentValue.top
2960
- })), /*#__PURE__*/React.createElement("div", {
2961
- className: styles$6.inputRight
2962
- }, /*#__PURE__*/React.createElement("input", {
2963
- className: styles$6.spacingInput,
2964
- max: max,
2965
- min: min,
2966
- onChange: e => updateSpacing({
2967
- right: Number(e.target.value)
2968
- }),
2969
- type: "number",
2970
- value: currentValue.right
2971
- })), /*#__PURE__*/React.createElement("div", {
2972
- className: styles$6.inputBottom
2973
- }, /*#__PURE__*/React.createElement("input", {
2974
- className: styles$6.spacingInput,
2975
- max: max,
2976
- min: min,
2977
- onChange: e => updateSpacing({
2978
- bottom: Number(e.target.value)
2979
- }),
2980
- type: "number",
2981
- value: currentValue.bottom
2982
- })), /*#__PURE__*/React.createElement("div", {
2983
- className: styles$6.inputLeft
2984
- }, /*#__PURE__*/React.createElement("input", {
2985
- className: styles$6.spacingInput,
2986
- max: max,
2987
- min: min,
2988
- onChange: e => updateSpacing({
2989
- left: Number(e.target.value)
2990
- }),
2991
- type: "number",
2992
- value: currentValue.left
2993
- })), /*#__PURE__*/React.createElement("button", {
2994
- "aria-label": isLinked ? 'Unlink values' : 'Link values',
2995
- className: cn(styles$6.linkButton, isLinked ? styles$6.linkButtonActive : ''),
2996
- onClick: toggleLinked,
2997
- type: "button"
2998
- }, isLinked ? /*#__PURE__*/React.createElement(Link, {
2999
- className: styles$6.linkIcon
3000
- }) : /*#__PURE__*/React.createElement(Unlink, {
3001
- className: styles$6.linkIcon
3002
- }))), /*#__PURE__*/React.createElement("div", {
3003
- className: styles$6.presets
3004
- }, presetValues.map(presetValue => /*#__PURE__*/React.createElement("button", {
3005
- className: styles$6.presetButton,
3006
- key: presetValue,
3007
- onClick: () => handlePresetClick(presetValue),
3008
- type: "button"
3009
- }, presetValue))), /*#__PURE__*/React.createElement("div", {
3010
- className: styles$6.modeLabel
3011
- }, mode === 'padding' ? '内边距' : '外边距', " (px)"));
3012
- };
3013
-
3014
- var styles$5 = {"container":"es-container-weN0F","input":"es-input-C8N67","inputWithSuffix":"es-inputWithSuffix-tdJcI","suffix":"es-suffix-HGRiQ"};
3015
-
3016
- const StringSetter = props => {
3017
- const {
3018
- value,
3019
- initialValue,
3020
- placeholder,
3021
- onChange,
3022
- suffix
3023
- } = props;
3024
- return /*#__PURE__*/React.createElement("div", {
3025
- className: styles$5.container
3026
- }, /*#__PURE__*/React.createElement("input", {
3027
- className: cn(styles$5.input, suffix ? styles$5.inputWithSuffix : ''),
3028
- onChange: e => onChange(e.target.value),
3029
- placeholder: placeholder || '',
3030
- type: "text",
3031
- value: value || initialValue || ''
3032
- }), suffix ? /*#__PURE__*/React.createElement("span", {
3033
- "aria-label": `Unit: ${suffix}`,
3034
- className: styles$5.suffix
3035
- }, suffix) : null);
3036
- };
3037
-
3038
- var styles$4 = {"switch":"es-switch-2DV6T","switchChecked":"es-switchChecked-eI65V","switchThumb":"es-switchThumb-GDlBx","switchThumbChecked":"es-switchThumbChecked-uA5kV","checkboxWrapper":"es-checkboxWrapper-l-KtW","checkboxInput":"es-checkboxInput-4Z9KK","checkbox":"es-checkbox-G1P36","checkboxChecked":"es-checkboxChecked-7XJoC","checkIcon":"es-checkIcon-3KIBH","segmented":"es-segmented-IaxAM","segmentedButton":"es-segmentedButton-mbZ5z","segmentedButtonSelected":"es-segmentedButtonSelected-u4m2T"};
3039
-
3040
- /**
3041
- * SwitchSetter - 布尔值设置器
3042
- * 提供多种 UI 模式:switch(开关)、checkbox(复选框)、segmented(分段)
3043
- */
3044
- const SwitchSetter = props => {
3045
- const {
3046
- value,
3047
- initialValue,
3048
- onChange,
3049
- mode = 'switch',
3050
- trueLabel = '是',
3051
- falseLabel = '否'
3052
- } = props;
3053
- const currentValue = value ?? initialValue ?? false;
3054
-
3055
- // 分段模式
3056
- if (mode === 'segmented') {
3057
- return /*#__PURE__*/React.createElement("div", {
3058
- className: styles$4.segmented
3059
- }, /*#__PURE__*/React.createElement("button", {
3060
- className: cn(styles$4.segmentedButton, currentValue === false ? styles$4.segmentedButtonSelected : ''),
3061
- onClick: () => onChange(false),
3062
- type: "button"
3063
- }, falseLabel), /*#__PURE__*/React.createElement("button", {
3064
- className: cn(styles$4.segmentedButton, currentValue === true ? styles$4.segmentedButtonSelected : ''),
3065
- onClick: () => onChange(true),
3066
- type: "button"
3067
- }, trueLabel));
3068
- }
3069
-
3070
- // 复选框模式
3071
- if (mode === 'checkbox') {
3072
- return /*#__PURE__*/React.createElement("label", {
3073
- className: styles$4.checkboxWrapper
3074
- }, /*#__PURE__*/React.createElement("input", {
3075
- checked: currentValue,
3076
- className: styles$4.checkboxInput,
3077
- onChange: e => onChange(e.target.checked),
3078
- type: "checkbox"
3079
- }), /*#__PURE__*/React.createElement("span", {
3080
- className: cn(styles$4.checkbox, currentValue ? styles$4.checkboxChecked : '')
3081
- }, currentValue ? /*#__PURE__*/React.createElement(Check, {
3082
- className: styles$4.checkIcon
3083
- }) : null));
3084
- }
3085
-
3086
- // 开关模式(默认)
3087
- return /*#__PURE__*/React.createElement("button", {
3088
- "aria-checked": currentValue,
3089
- className: cn(styles$4.switch, currentValue ? styles$4.switchChecked : ''),
3090
- onClick: () => onChange(!currentValue),
3091
- role: "switch",
3092
- type: "button"
3093
- }, /*#__PURE__*/React.createElement("span", {
3094
- className: cn(styles$4.switchThumb, currentValue ? styles$4.switchThumbChecked : '')
3095
- }));
3096
- };
3097
-
3098
- var styles$3 = {"container":"es-container-ftwPX","textarea":"es-textarea-sJPy9","counter":"es-counter-02NEu"};
3099
-
3100
- const TextAreaSetter = props => {
3101
- const {
3102
- value,
3103
- initialValue,
3104
- placeholder,
3105
- rows = 3,
3106
- maxLength,
3107
- onChange
3108
- } = props;
3109
- return /*#__PURE__*/React.createElement("div", {
3110
- className: styles$3.container
3111
- }, /*#__PURE__*/React.createElement("textarea", {
3112
- className: styles$3.textarea,
3113
- maxLength: maxLength,
3114
- onChange: e => onChange(e.target.value),
3115
- placeholder: placeholder || '',
3116
- rows: rows,
3117
- value: value ?? initialValue ?? ''
3118
- }), maxLength ? /*#__PURE__*/React.createElement("div", {
3119
- className: styles$3.counter
3120
- }, (value ?? initialValue ?? '').length, "/", maxLength) : null);
3121
- };
3122
-
3123
- var styles$2 = {"container":"es-container-EDh0-","row":"es-row-MOm-T","label":"es-label-1o-jT","hiddenInput":"es-hiddenInput-03Dx-","uploadArea":"es-uploadArea-1HYbh","uploadIcon":"es-uploadIcon-Ck7gF","clearButton":"es-clearButton-N-9cs","clearIcon":"es-clearIcon-LHlF6","fileInfo":"es-fileInfo-71Jtf","fileName":"es-fileName-B2hHy","fileSize":"es-fileSize-pINcz","error":"es-error-A8MID"};
3124
-
3125
- const UploadSetter = props => {
3126
- const {
3127
- value,
3128
- onChange,
3129
- accept = '.jpg,.jpeg,.png,.gif',
3130
- maxSize = 10 * 1024 * 1024
3131
- } = props;
3132
- const [error, setError] = useState('');
3133
- const inputRef = useRef(null);
3134
- const handleFileChange = async e => {
3135
- const file = e.target.files?.[0];
3136
- setError('');
3137
- if (!file) {
3138
- onChange(null);
3139
- return;
3140
- }
3141
- const ext = `.${file.name.split('.').pop()?.toLowerCase()}`;
3142
- if (!accept.includes(ext)) {
3143
- setError(`仅支持 ${accept} 格式文件`);
3144
- onChange(null);
3145
- return;
3146
- }
3147
- if (file.size > maxSize) {
3148
- setError(`文件大小不能超过 ${maxSize / 1024 / 1024}MB`);
3149
- onChange(null);
3150
- return;
3151
- }
3152
- try {
3153
- const [base64, dimensions] = await Promise.all([new Promise((resolve, reject) => {
3154
- const reader = new FileReader();
3155
- reader.onload = () => resolve(reader.result);
3156
- reader.onerror = err => reject(err);
3157
- reader.readAsDataURL(file);
3158
- }), new Promise((resolve, reject) => {
3159
- const img = new Image();
3160
- img.onload = () => resolve({
3161
- width: img.naturalWidth,
3162
- height: img.naturalHeight
3163
- });
3164
- img.onerror = reject;
3165
- img.src = URL.createObjectURL(file);
3166
- })]);
3167
- onChange({
3168
- raw: {
3169
- name: file.name,
3170
- size: file.size,
3171
- type: file.type,
3172
- width: dimensions.width,
3173
- height: dimensions.height
3174
- },
3175
- base64
3176
- });
3177
- } catch (_) {
3178
- setError('文件读取失败,请重试');
3179
- onChange(null);
3180
- }
3181
- };
3182
- const handleClear = () => {
3183
- onChange(null);
3184
- if (inputRef.current) {
3185
- inputRef.current.value = '';
3186
- }
3187
- };
3188
- return /*#__PURE__*/React.createElement("div", {
3189
- className: styles$2.container
3190
- }, /*#__PURE__*/React.createElement("div", {
3191
- className: styles$2.row
3192
- }, /*#__PURE__*/React.createElement("label", {
3193
- className: styles$2.label
3194
- }, /*#__PURE__*/React.createElement("input", {
3195
- accept: accept,
3196
- className: styles$2.hiddenInput,
3197
- onChange: handleFileChange,
3198
- ref: inputRef,
3199
- type: "file"
3200
- }), /*#__PURE__*/React.createElement("div", {
3201
- className: styles$2.uploadArea
3202
- }, /*#__PURE__*/React.createElement(Upload, {
3203
- className: styles$2.uploadIcon
3204
- }), /*#__PURE__*/React.createElement("span", null, value ? '更换文件' : '点击上传'))), value ? /*#__PURE__*/React.createElement("button", {
3205
- "aria-label": "\u6E05\u9664\u6587\u4EF6",
3206
- className: styles$2.clearButton,
3207
- onClick: handleClear,
3208
- type: "button"
3209
- }, /*#__PURE__*/React.createElement(X, {
3210
- className: styles$2.clearIcon
3211
- })) : null), value ? /*#__PURE__*/React.createElement("div", {
3212
- className: styles$2.fileInfo
3213
- }, /*#__PURE__*/React.createElement("span", {
3214
- className: styles$2.fileName
3215
- }, value.raw?.name), /*#__PURE__*/React.createElement("span", {
3216
- className: styles$2.fileSize
3217
- }, (value.raw?.size / 1024).toFixed(1), "KB")) : null, error ? /*#__PURE__*/React.createElement("p", {
3218
- className: styles$2.error,
3219
- role: "alert"
3220
- }, error) : null);
3221
- };
3222
-
3223
- var styles$1 = {"container":"es-container-gjha7","header":"es-header-iE--w","title":"es-title-qTdCp","toggleButton":"es-toggleButton-g6dI2","toggleIcon":"es-toggleIcon-cjnM4","content":"es-content-GYYgk","contentHidden":"es-contentHidden-WAYSW","srOnly":"es-srOnly-EI1Tc"};
3224
-
3225
- const CollapseSetter = props => {
3226
- const {
3227
- field,
3228
- children,
3229
- initialValue,
3230
- icon = true
3231
- } = props;
3232
- const [isOpen, setIsOpen] = useState(initialValue ?? true);
3233
- return /*#__PURE__*/React.createElement("div", {
3234
- className: styles$1.container
3235
- }, /*#__PURE__*/React.createElement("div", {
3236
- className: styles$1.header
3237
- }, /*#__PURE__*/React.createElement("h4", {
3238
- className: styles$1.title
3239
- }, field.title), icon ? /*#__PURE__*/React.createElement("button", {
3240
- "aria-expanded": isOpen,
3241
- className: styles$1.toggleButton,
3242
- onClick: () => setIsOpen(!isOpen),
3243
- type: "button"
3244
- }, /*#__PURE__*/React.createElement(ChevronsUpDown, {
3245
- className: styles$1.toggleIcon
3246
- }), /*#__PURE__*/React.createElement("span", {
3247
- className: styles$1.srOnly
3248
- }, "Toggle")) : null), /*#__PURE__*/React.createElement("div", {
3249
- className: cn(styles$1.content, isOpen === false ? styles$1.contentHidden : '')
3250
- }, children));
3251
- };
3252
-
3253
- var styles = {"container":"es-container-4LWRO","tabsList":"es-tabsList-L72im","tabTrigger":"es-tabTrigger-u3S3S","tabTriggerActive":"es-tabTriggerActive-xCpU6","tabContent":"es-tabContent-Pj2Us","tabContentActive":"es-tabContentActive-NJtXh"};
3254
-
3255
- const TabSetter = props => {
3256
- const {
3257
- tabs,
3258
- initialValue,
3259
- children
3260
- } = props;
3261
- const tabsList = React$1.useMemo(() => {
3262
- if (tabs) {
3263
- return tabs;
3264
- }
3265
- if (Array.isArray(children) && children.length > 0) {
3266
- return children.map(child => ({
3267
- label: child.props.field.config.title,
3268
- value: child.props.field.config.key
3269
- }));
3270
- }
3271
- throw new Error('TabSetter: children or tabs must be an array');
3272
- }, [tabs, children]);
3273
- const firstTabValue = React$1.useMemo(() => tabsList[0]?.value, [tabsList]);
3274
- const [activeTab, setActiveTab] = useState(initialValue ?? firstTabValue);
3275
- return /*#__PURE__*/React$1.createElement("div", {
3276
- className: styles.container
3277
- }, /*#__PURE__*/React$1.createElement("div", {
3278
- className: styles.tabsList,
3279
- role: "tablist",
3280
- style: {
3281
- gridTemplateColumns: `repeat(${tabsList.length}, minmax(0, 1fr))`
3282
- }
3283
- }, tabsList.map(tab => /*#__PURE__*/React$1.createElement("button", {
3284
- "aria-selected": activeTab === tab.value,
3285
- className: cn(styles.tabTrigger, activeTab === tab.value ? styles.tabTriggerActive : ''),
3286
- key: tab.value,
3287
- onClick: () => setActiveTab(tab.value),
3288
- role: "tab",
3289
- type: "button"
3290
- }, tab.label))), Array.isArray(children) ? children.map(child => /*#__PURE__*/React$1.createElement("div", {
3291
- className: cn(styles.tabContent, activeTab === child.props.field.config.key ? styles.tabContentActive : ''),
3292
- key: child.props.field.config.key,
3293
- role: "tabpanel"
3294
- }, child)) : null);
3295
- };
3296
-
3297
- const setterMap = {
3298
- ColorSetter,
3299
- NodeIdSetter,
3300
- NumberSetter,
3301
- RectSetter,
3302
- StringSetter,
3303
- SwitchSetter,
3304
- UploadSetter,
3305
- SegmentedSetter,
3306
- CollapseSetter,
3307
- TabSetter,
3308
- SpacingSetter,
3309
- AlignSetter,
3310
- DataBindingSetter,
3311
- DataMappingSetter,
3312
- SelectSetter,
3313
- SliderSetter,
3314
- TextAreaSetter,
3315
- ArraySetter,
3316
- JsonSetter,
3317
- ObjectSetter
3318
- };
3319
-
3320
- export { AlignSetter, ArraySetter, CollapseSetter, ColorSetter, DataBindingSetter, DataMappingSetter, JsonSetter, NodeIdSetter, NumberSetter, ObjectSetter, Popover, RectSetter, SegmentedSetter, SelectSetter, SliderSetter, SpacingSetter, StringSetter, SwitchSetter, TabSetter, TextAreaSetter, UploadSetter, setterMap as default, setterMap };
3321
- //# sourceMappingURL=index.esm.js.map