@seed-ship/mcp-ui-solid 2.6.1 → 2.6.3
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/components/FormFieldRenderer.cjs +214 -89
- package/dist/components/FormFieldRenderer.cjs.map +1 -1
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +214 -89
- package/dist/components/FormFieldRenderer.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FormFieldRenderer.tsx +134 -38
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { delegateEvents, createComponent, getNextElement, template, getNextMarker, insert, effect, setAttribute, memo, setProperty, className, runHydrationEvents } from "solid-js/web";
|
|
2
2
|
import { Show, Switch, Match, For, createSignal, onCleanup } from "solid-js";
|
|
3
3
|
import { useConditionalField } from "../hooks/useConditionalField.js";
|
|
4
|
-
var _tmpl$ = /* @__PURE__ */ template(`<span class="text-red-500 ml-1"aria-hidden=true>*`), _tmpl$2 = /* @__PURE__ */ template(`<label class="block text-sm font-medium text-gray-700 dark:text-gray-300"><!$><!/><!$><!/>`), _tmpl$3 = /* @__PURE__ */ template(`<input>`), _tmpl$4 = /* @__PURE__ */ template(`<input type=number>`), _tmpl$5 = /* @__PURE__ */ template(`<input type=date>`), _tmpl$6 = /* @__PURE__ */ template(`<textarea>`), _tmpl$7 = /* @__PURE__ */ template(`<option value disabled>`), _tmpl$8 = /* @__PURE__ */ template(`<select><!$><!/><!$><!/>`), _tmpl$9 = /* @__PURE__ */ template(`<label class="flex items-center gap-2 cursor-pointer"><input type=checkbox class="w-4 h-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"><span class="text-sm text-gray-700 dark:text-gray-300"><!$><!/><!$><!/>`), _tmpl$0 = /* @__PURE__ */ template(`<div class=space-y-2 role=radiogroup>`), _tmpl$1 = /* @__PURE__ */ template(`<p class="text-xs text-gray-500 dark:text-gray-400">`), _tmpl$
|
|
4
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span class="text-red-500 ml-1"aria-hidden=true>*`), _tmpl$2 = /* @__PURE__ */ template(`<label class="block text-sm font-medium text-gray-700 dark:text-gray-300"><!$><!/><!$><!/>`), _tmpl$3 = /* @__PURE__ */ template(`<input>`), _tmpl$4 = /* @__PURE__ */ template(`<input type=number>`), _tmpl$5 = /* @__PURE__ */ template(`<input type=date>`), _tmpl$6 = /* @__PURE__ */ template(`<textarea>`), _tmpl$7 = /* @__PURE__ */ template(`<option value disabled>`), _tmpl$8 = /* @__PURE__ */ template(`<select><!$><!/><!$><!/>`), _tmpl$9 = /* @__PURE__ */ template(`<label class="flex items-center gap-2 cursor-pointer"><input type=checkbox class="w-4 h-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"><span class="text-sm text-gray-700 dark:text-gray-300"><!$><!/><!$><!/>`), _tmpl$0 = /* @__PURE__ */ template(`<div class=space-y-2 role=radiogroup>`), _tmpl$1 = /* @__PURE__ */ template(`<input type=text>`), _tmpl$10 = /* @__PURE__ */ template(`<p class="text-xs text-amber-500 mt-0.5">Unknown field type: <!$><!/>`), _tmpl$11 = /* @__PURE__ */ template(`<p class="text-xs text-gray-500 dark:text-gray-400">`), _tmpl$12 = /* @__PURE__ */ template(`<p role=alert class="text-xs text-red-600 dark:text-red-400">`), _tmpl$13 = /* @__PURE__ */ template(`<div class=space-y-1><!$><!/><!$><!/><!$><!/><!$><!/>`), _tmpl$14 = /* @__PURE__ */ template(`<option>`), _tmpl$15 = /* @__PURE__ */ template(`<label class="flex items-center gap-2 cursor-pointer"><input type=radio class="w-4 h-4 border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600"><span class="text-sm text-gray-700 dark:text-gray-300">`), _tmpl$16 = /* @__PURE__ */ template(`<div class="flex flex-wrap gap-1 mb-1">`), _tmpl$17 = /* @__PURE__ */ template(`<div class="p-2 border-b border-gray-200 dark:border-gray-600"><input type=text placeholder=Filter... class="w-full px-2 py-1 text-sm border border-gray-200 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:border-blue-400 outline-none"autofocus>`), _tmpl$18 = /* @__PURE__ */ template(`<p class="px-3 py-2 text-sm text-gray-400">No matches`), _tmpl$19 = /* @__PURE__ */ template(`<div class="absolute z-20 mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-md shadow-lg overflow-hidden"><!$><!/><div class="max-h-72 overflow-y-auto"><!$><!/><!$><!/>`), _tmpl$20 = /* @__PURE__ */ template(`<div class=relative><!$><!/><button type=button><span></span><svg class="w-4 h-4 text-gray-400"fill=none viewBox="0 0 24 24"stroke=currentColor><path stroke-linecap=round stroke-linejoin=round stroke-width=2 d="M19 9l-7 7-7-7"></path></svg></button><!$><!/>`), _tmpl$21 = /* @__PURE__ */ template(`<span class="inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 rounded-full"><!$><!/><button type=button class="hover:text-blue-900 dark:hover:text-blue-100">×`), _tmpl$22 = /* @__PURE__ */ template(`<label class="flex items-center gap-2 px-3 py-2 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer text-sm"><input type=checkbox class="w-4 h-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600"><span class="text-gray-900 dark:text-white">`), _tmpl$23 = /* @__PURE__ */ template(`<div class="absolute z-20 mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-md shadow-lg max-h-72 overflow-y-auto">`), _tmpl$24 = /* @__PURE__ */ template(`<div class=relative><!$><!/><input type=text autocomplete=off><!$><!/>`), _tmpl$25 = /* @__PURE__ */ template(`<span class="ml-2 text-xs">✓`), _tmpl$26 = /* @__PURE__ */ template(`<button type=button><!$><!/><!$><!/>`);
|
|
5
5
|
const FormFieldRenderer = (props) => {
|
|
6
6
|
const {
|
|
7
7
|
isVisible
|
|
@@ -23,7 +23,7 @@ const FormFieldRenderer = (props) => {
|
|
|
23
23
|
return isVisible();
|
|
24
24
|
},
|
|
25
25
|
get children() {
|
|
26
|
-
var _el$ = getNextElement(_tmpl$
|
|
26
|
+
var _el$ = getNextElement(_tmpl$13), _el$32 = _el$.firstChild, [_el$33, _co$8] = getNextMarker(_el$32.nextSibling), _el$34 = _el$33.nextSibling, [_el$35, _co$9] = getNextMarker(_el$34.nextSibling), _el$36 = _el$35.nextSibling, [_el$37, _co$0] = getNextMarker(_el$36.nextSibling), _el$38 = _el$37.nextSibling, [_el$39, _co$1] = getNextMarker(_el$38.nextSibling);
|
|
27
27
|
insert(_el$, createComponent(Show, {
|
|
28
28
|
get when() {
|
|
29
29
|
return memo(() => !!props.field.label)() && props.field.type !== "checkbox";
|
|
@@ -42,7 +42,7 @@ const FormFieldRenderer = (props) => {
|
|
|
42
42
|
effect(() => setAttribute(_el$2, "for", fieldId()));
|
|
43
43
|
return _el$2;
|
|
44
44
|
}
|
|
45
|
-
}), _el$
|
|
45
|
+
}), _el$33, _co$8);
|
|
46
46
|
insert(_el$, createComponent(Switch, {
|
|
47
47
|
get children() {
|
|
48
48
|
return [createComponent(Match, {
|
|
@@ -217,11 +217,11 @@ const FormFieldRenderer = (props) => {
|
|
|
217
217
|
return props.field.options;
|
|
218
218
|
},
|
|
219
219
|
children: (option) => (() => {
|
|
220
|
-
var _el$
|
|
221
|
-
insert(_el$
|
|
222
|
-
effect(() => setProperty(_el$
|
|
223
|
-
effect(() => setProperty(_el$
|
|
224
|
-
return _el$
|
|
220
|
+
var _el$40 = getNextElement(_tmpl$14);
|
|
221
|
+
insert(_el$40, () => option.label);
|
|
222
|
+
effect(() => setProperty(_el$40, "disabled", option.disabled));
|
|
223
|
+
effect(() => setProperty(_el$40, "value", option.value));
|
|
224
|
+
return _el$40;
|
|
225
225
|
})()
|
|
226
226
|
}), _el$15, _co$4);
|
|
227
227
|
effect((_p$) => {
|
|
@@ -337,23 +337,23 @@ const FormFieldRenderer = (props) => {
|
|
|
337
337
|
return props.field.options;
|
|
338
338
|
},
|
|
339
339
|
children: (option, index) => (() => {
|
|
340
|
-
var _el$
|
|
341
|
-
_el$
|
|
342
|
-
insert(_el$
|
|
340
|
+
var _el$41 = getNextElement(_tmpl$15), _el$42 = _el$41.firstChild, _el$43 = _el$42.nextSibling;
|
|
341
|
+
_el$42.addEventListener("change", () => props.onChange(option.value));
|
|
342
|
+
insert(_el$43, () => option.label);
|
|
343
343
|
effect((_p$) => {
|
|
344
|
-
var _v$
|
|
345
|
-
_v$
|
|
346
|
-
_v$
|
|
347
|
-
_v$
|
|
344
|
+
var _v$62 = props.field.name, _v$63 = `${fieldId()}-${index()}`, _v$64 = props.disabled || option.disabled;
|
|
345
|
+
_v$62 !== _p$.e && setAttribute(_el$42, "name", _p$.e = _v$62);
|
|
346
|
+
_v$63 !== _p$.t && setAttribute(_el$42, "id", _p$.t = _v$63);
|
|
347
|
+
_v$64 !== _p$.a && setProperty(_el$42, "disabled", _p$.a = _v$64);
|
|
348
348
|
return _p$;
|
|
349
349
|
}, {
|
|
350
350
|
e: void 0,
|
|
351
351
|
t: void 0,
|
|
352
352
|
a: void 0
|
|
353
353
|
});
|
|
354
|
-
effect(() => setProperty(_el$
|
|
355
|
-
effect(() => setProperty(_el$
|
|
356
|
-
return _el$
|
|
354
|
+
effect(() => setProperty(_el$42, "value", option.value));
|
|
355
|
+
effect(() => setProperty(_el$42, "checked", props.value === option.value));
|
|
356
|
+
return _el$41;
|
|
357
357
|
})()
|
|
358
358
|
}));
|
|
359
359
|
effect((_p$) => {
|
|
@@ -369,36 +369,67 @@ const FormFieldRenderer = (props) => {
|
|
|
369
369
|
});
|
|
370
370
|
return _el$24;
|
|
371
371
|
}
|
|
372
|
+
}), createComponent(Match, {
|
|
373
|
+
when: true,
|
|
374
|
+
get children() {
|
|
375
|
+
return [(() => {
|
|
376
|
+
var _el$25 = getNextElement(_tmpl$1);
|
|
377
|
+
_el$25.$$input = (e) => props.onChange(e.currentTarget.value);
|
|
378
|
+
effect((_p$) => {
|
|
379
|
+
var _v$57 = fieldId(), _v$58 = props.field.name, _v$59 = props.field.placeholder || `(${props.field.type})`, _v$60 = props.disabled, _v$61 = baseInputClass();
|
|
380
|
+
_v$57 !== _p$.e && setAttribute(_el$25, "id", _p$.e = _v$57);
|
|
381
|
+
_v$58 !== _p$.t && setAttribute(_el$25, "name", _p$.t = _v$58);
|
|
382
|
+
_v$59 !== _p$.a && setAttribute(_el$25, "placeholder", _p$.a = _v$59);
|
|
383
|
+
_v$60 !== _p$.o && setProperty(_el$25, "disabled", _p$.o = _v$60);
|
|
384
|
+
_v$61 !== _p$.i && className(_el$25, _p$.i = _v$61);
|
|
385
|
+
return _p$;
|
|
386
|
+
}, {
|
|
387
|
+
e: void 0,
|
|
388
|
+
t: void 0,
|
|
389
|
+
a: void 0,
|
|
390
|
+
o: void 0,
|
|
391
|
+
i: void 0
|
|
392
|
+
});
|
|
393
|
+
effect(() => setProperty(_el$25, "value", props.value || ""));
|
|
394
|
+
runHydrationEvents();
|
|
395
|
+
return _el$25;
|
|
396
|
+
})(), (() => {
|
|
397
|
+
var _el$26 = getNextElement(_tmpl$10), _el$27 = _el$26.firstChild, _el$28 = _el$27.nextSibling, [_el$29, _co$7] = getNextMarker(_el$28.nextSibling);
|
|
398
|
+
insert(_el$26, () => props.field.type, _el$29, _co$7);
|
|
399
|
+
return _el$26;
|
|
400
|
+
})()];
|
|
401
|
+
}
|
|
372
402
|
})];
|
|
373
403
|
}
|
|
374
|
-
}), _el$
|
|
404
|
+
}), _el$35, _co$9);
|
|
375
405
|
insert(_el$, createComponent(Show, {
|
|
376
406
|
get when() {
|
|
377
407
|
return memo(() => !!props.field.helpText)() && !props.error;
|
|
378
408
|
},
|
|
379
409
|
get children() {
|
|
380
|
-
var _el$
|
|
381
|
-
insert(_el$
|
|
382
|
-
return _el$
|
|
410
|
+
var _el$30 = getNextElement(_tmpl$11);
|
|
411
|
+
insert(_el$30, () => props.field.helpText);
|
|
412
|
+
return _el$30;
|
|
383
413
|
}
|
|
384
|
-
}), _el$
|
|
414
|
+
}), _el$37, _co$0);
|
|
385
415
|
insert(_el$, createComponent(Show, {
|
|
386
416
|
get when() {
|
|
387
417
|
return props.error;
|
|
388
418
|
},
|
|
389
419
|
get children() {
|
|
390
|
-
var _el$
|
|
391
|
-
insert(_el$
|
|
392
|
-
effect(() => setAttribute(_el$
|
|
393
|
-
return _el$
|
|
420
|
+
var _el$31 = getNextElement(_tmpl$12);
|
|
421
|
+
insert(_el$31, () => props.error);
|
|
422
|
+
effect(() => setAttribute(_el$31, "id", errorId()));
|
|
423
|
+
return _el$31;
|
|
394
424
|
}
|
|
395
|
-
}), _el$
|
|
425
|
+
}), _el$39, _co$1);
|
|
396
426
|
return _el$;
|
|
397
427
|
}
|
|
398
428
|
});
|
|
399
429
|
};
|
|
400
430
|
const MultiSelectField = (props) => {
|
|
401
431
|
const [open, setOpen] = createSignal(false);
|
|
432
|
+
const [filter, setFilter] = createSignal("");
|
|
402
433
|
const toggle = (val) => {
|
|
403
434
|
const current = props.value || [];
|
|
404
435
|
if (current.includes(val)) {
|
|
@@ -414,61 +445,90 @@ const MultiSelectField = (props) => {
|
|
|
414
445
|
var _a, _b;
|
|
415
446
|
return ((_b = (_a = props.field.options) == null ? void 0 : _a.find((o) => o.value === val)) == null ? void 0 : _b.label) || val;
|
|
416
447
|
};
|
|
448
|
+
const filteredOptions = () => {
|
|
449
|
+
const q = filter().toLowerCase();
|
|
450
|
+
if (!q) return props.field.options || [];
|
|
451
|
+
return (props.field.options || []).filter((o) => o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q));
|
|
452
|
+
};
|
|
417
453
|
return (() => {
|
|
418
|
-
var _el$
|
|
419
|
-
insert(_el$
|
|
454
|
+
var _el$44 = getNextElement(_tmpl$20), _el$59 = _el$44.firstChild, [_el$60, _co$13] = getNextMarker(_el$59.nextSibling), _el$46 = _el$60.nextSibling, _el$47 = _el$46.firstChild, _el$61 = _el$46.nextSibling, [_el$62, _co$14] = getNextMarker(_el$61.nextSibling);
|
|
455
|
+
insert(_el$44, createComponent(Show, {
|
|
420
456
|
get when() {
|
|
421
457
|
return props.value.length > 0;
|
|
422
458
|
},
|
|
423
459
|
get children() {
|
|
424
|
-
var _el$
|
|
425
|
-
insert(_el$
|
|
460
|
+
var _el$45 = getNextElement(_tmpl$16);
|
|
461
|
+
insert(_el$45, createComponent(For, {
|
|
426
462
|
get each() {
|
|
427
463
|
return props.value;
|
|
428
464
|
},
|
|
429
465
|
children: (val) => (() => {
|
|
430
|
-
var _el$
|
|
431
|
-
insert(_el$
|
|
432
|
-
_el$
|
|
433
|
-
effect(() => setAttribute(_el$
|
|
466
|
+
var _el$63 = getNextElement(_tmpl$21), _el$65 = _el$63.firstChild, [_el$66, _co$15] = getNextMarker(_el$65.nextSibling), _el$64 = _el$66.nextSibling;
|
|
467
|
+
insert(_el$63, () => getLabel(val), _el$66, _co$15);
|
|
468
|
+
_el$64.$$click = () => removeChip(val);
|
|
469
|
+
effect(() => setAttribute(_el$64, "aria-label", `Remove ${getLabel(val)}`));
|
|
434
470
|
runHydrationEvents();
|
|
435
|
-
return _el$
|
|
471
|
+
return _el$63;
|
|
436
472
|
})()
|
|
437
473
|
}));
|
|
438
|
-
return _el$
|
|
474
|
+
return _el$45;
|
|
439
475
|
}
|
|
440
|
-
}), _el$
|
|
441
|
-
_el$
|
|
442
|
-
|
|
476
|
+
}), _el$60, _co$13);
|
|
477
|
+
_el$46.$$click = () => {
|
|
478
|
+
setOpen(!open());
|
|
479
|
+
if (!open()) setFilter("");
|
|
480
|
+
};
|
|
481
|
+
insert(_el$47, (() => {
|
|
443
482
|
var _c$ = memo(() => !!props.value.length);
|
|
444
483
|
return () => _c$() ? `${props.value.length} selected` : props.field.placeholder || "Select...";
|
|
445
484
|
})());
|
|
446
|
-
insert(_el$
|
|
485
|
+
insert(_el$44, createComponent(Show, {
|
|
447
486
|
get when() {
|
|
448
487
|
return open();
|
|
449
488
|
},
|
|
450
489
|
get children() {
|
|
451
|
-
var _el$
|
|
452
|
-
insert(_el$
|
|
490
|
+
var _el$48 = getNextElement(_tmpl$19), _el$57 = _el$48.firstChild, [_el$58, _co$12] = getNextMarker(_el$57.nextSibling), _el$51 = _el$58.nextSibling, _el$53 = _el$51.firstChild, [_el$54, _co$10] = getNextMarker(_el$53.nextSibling), _el$55 = _el$54.nextSibling, [_el$56, _co$11] = getNextMarker(_el$55.nextSibling);
|
|
491
|
+
insert(_el$48, createComponent(Show, {
|
|
492
|
+
get when() {
|
|
493
|
+
var _a;
|
|
494
|
+
return (((_a = props.field.options) == null ? void 0 : _a.length) || 0) > 10;
|
|
495
|
+
},
|
|
496
|
+
get children() {
|
|
497
|
+
var _el$49 = getNextElement(_tmpl$17), _el$50 = _el$49.firstChild;
|
|
498
|
+
_el$50.$$input = (e) => setFilter(e.currentTarget.value);
|
|
499
|
+
effect(() => setProperty(_el$50, "value", filter()));
|
|
500
|
+
runHydrationEvents();
|
|
501
|
+
return _el$49;
|
|
502
|
+
}
|
|
503
|
+
}), _el$58, _co$12);
|
|
504
|
+
insert(_el$51, createComponent(For, {
|
|
453
505
|
get each() {
|
|
454
|
-
return
|
|
506
|
+
return filteredOptions();
|
|
455
507
|
},
|
|
456
508
|
children: (option) => (() => {
|
|
457
|
-
var _el$
|
|
458
|
-
_el$
|
|
459
|
-
insert(_el$
|
|
460
|
-
effect(() => setProperty(_el$
|
|
461
|
-
return _el$
|
|
509
|
+
var _el$67 = getNextElement(_tmpl$22), _el$68 = _el$67.firstChild, _el$69 = _el$68.nextSibling;
|
|
510
|
+
_el$68.addEventListener("change", () => toggle(option.value));
|
|
511
|
+
insert(_el$69, () => option.label);
|
|
512
|
+
effect(() => setProperty(_el$68, "checked", (props.value || []).includes(option.value)));
|
|
513
|
+
return _el$67;
|
|
462
514
|
})()
|
|
463
|
-
}));
|
|
464
|
-
|
|
515
|
+
}), _el$54, _co$10);
|
|
516
|
+
insert(_el$51, createComponent(Show, {
|
|
517
|
+
get when() {
|
|
518
|
+
return filteredOptions().length === 0;
|
|
519
|
+
},
|
|
520
|
+
get children() {
|
|
521
|
+
return getNextElement(_tmpl$18);
|
|
522
|
+
}
|
|
523
|
+
}), _el$56, _co$11);
|
|
524
|
+
return _el$48;
|
|
465
525
|
}
|
|
466
|
-
}), _el$
|
|
526
|
+
}), _el$62, _co$14);
|
|
467
527
|
effect((_p$) => {
|
|
468
|
-
var _v$
|
|
469
|
-
_v$
|
|
470
|
-
_v$
|
|
471
|
-
_v$
|
|
528
|
+
var _v$65 = props.disabled, _v$66 = `${props.baseClass} text-left flex items-center justify-between`, _v$67 = props.value.length ? "text-gray-900 dark:text-white" : "text-gray-400";
|
|
529
|
+
_v$65 !== _p$.e && setProperty(_el$46, "disabled", _p$.e = _v$65);
|
|
530
|
+
_v$66 !== _p$.t && className(_el$46, _p$.t = _v$66);
|
|
531
|
+
_v$67 !== _p$.a && className(_el$47, _p$.a = _v$67);
|
|
472
532
|
return _p$;
|
|
473
533
|
}, {
|
|
474
534
|
e: void 0,
|
|
@@ -476,15 +536,17 @@ const MultiSelectField = (props) => {
|
|
|
476
536
|
a: void 0
|
|
477
537
|
});
|
|
478
538
|
runHydrationEvents();
|
|
479
|
-
return _el$
|
|
539
|
+
return _el$44;
|
|
480
540
|
})();
|
|
481
541
|
};
|
|
482
542
|
const AutocompleteField = (props) => {
|
|
483
543
|
const [query, setQuery] = createSignal("");
|
|
484
544
|
const [suggestions, setSuggestions] = createSignal([]);
|
|
485
545
|
const [isOpen, setIsOpen] = createSignal(false);
|
|
486
|
-
const [
|
|
546
|
+
const [selectedLabels, setSelectedLabels] = createSignal(/* @__PURE__ */ new Map());
|
|
487
547
|
let debounceTimer = null;
|
|
548
|
+
const isMultiple = () => props.field.multiple === true;
|
|
549
|
+
const selectedValues = () => isMultiple() ? Array.isArray(props.value) ? props.value : [] : [];
|
|
488
550
|
const minChars = () => props.field.minChars ?? 2;
|
|
489
551
|
const debounceMs = () => props.field.debounceMs ?? 300;
|
|
490
552
|
const fetchSuggestions = async (q) => {
|
|
@@ -515,8 +577,9 @@ const AutocompleteField = (props) => {
|
|
|
515
577
|
};
|
|
516
578
|
const handleInput = (value) => {
|
|
517
579
|
setQuery(value);
|
|
518
|
-
|
|
519
|
-
|
|
580
|
+
if (!isMultiple()) {
|
|
581
|
+
props.onChange("");
|
|
582
|
+
}
|
|
520
583
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
521
584
|
if (value.length < minChars()) {
|
|
522
585
|
setSuggestions([]);
|
|
@@ -526,58 +589,120 @@ const AutocompleteField = (props) => {
|
|
|
526
589
|
debounceTimer = setTimeout(() => fetchSuggestions(value), debounceMs());
|
|
527
590
|
};
|
|
528
591
|
const selectSuggestion = (item) => {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
592
|
+
if (isMultiple()) {
|
|
593
|
+
const current = selectedValues();
|
|
594
|
+
if (!current.includes(item.value)) {
|
|
595
|
+
props.onChange([...current, item.value]);
|
|
596
|
+
setSelectedLabels((prev) => new Map(prev).set(item.value, item.label));
|
|
597
|
+
}
|
|
598
|
+
setQuery("");
|
|
599
|
+
setSuggestions([]);
|
|
600
|
+
setIsOpen(false);
|
|
601
|
+
} else {
|
|
602
|
+
props.onChange(item.value);
|
|
603
|
+
setSelectedLabels((prev) => new Map(prev).set(item.value, item.label));
|
|
604
|
+
setQuery(item.label);
|
|
605
|
+
setIsOpen(false);
|
|
606
|
+
setSuggestions([]);
|
|
607
|
+
}
|
|
534
608
|
};
|
|
609
|
+
const removeChip = (val) => {
|
|
610
|
+
props.onChange(selectedValues().filter((v) => v !== val));
|
|
611
|
+
setSelectedLabels((prev) => {
|
|
612
|
+
const m = new Map(prev);
|
|
613
|
+
m.delete(val);
|
|
614
|
+
return m;
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
const getLabel = (val) => selectedLabels().get(val) || val;
|
|
535
618
|
onCleanup(() => {
|
|
536
619
|
if (debounceTimer) clearTimeout(debounceTimer);
|
|
537
620
|
});
|
|
538
621
|
return (() => {
|
|
539
|
-
var _el$
|
|
540
|
-
_el$
|
|
541
|
-
|
|
622
|
+
var _el$70 = getNextElement(_tmpl$24), _el$74 = _el$70.firstChild, [_el$75, _co$16] = getNextMarker(_el$74.nextSibling), _el$72 = _el$75.nextSibling, _el$76 = _el$72.nextSibling, [_el$77, _co$17] = getNextMarker(_el$76.nextSibling);
|
|
623
|
+
insert(_el$70, createComponent(Show, {
|
|
624
|
+
get when() {
|
|
625
|
+
return memo(() => !!isMultiple())() && selectedValues().length > 0;
|
|
626
|
+
},
|
|
627
|
+
get children() {
|
|
628
|
+
var _el$71 = getNextElement(_tmpl$16);
|
|
629
|
+
insert(_el$71, createComponent(For, {
|
|
630
|
+
get each() {
|
|
631
|
+
return selectedValues();
|
|
632
|
+
},
|
|
633
|
+
children: (val) => (() => {
|
|
634
|
+
var _el$78 = getNextElement(_tmpl$21), _el$80 = _el$78.firstChild, [_el$81, _co$18] = getNextMarker(_el$80.nextSibling), _el$79 = _el$81.nextSibling;
|
|
635
|
+
insert(_el$78, () => getLabel(val), _el$81, _co$18);
|
|
636
|
+
_el$79.$$click = () => removeChip(val);
|
|
637
|
+
effect(() => setAttribute(_el$79, "aria-label", `Remove ${getLabel(val)}`));
|
|
638
|
+
runHydrationEvents();
|
|
639
|
+
return _el$78;
|
|
640
|
+
})()
|
|
641
|
+
}));
|
|
642
|
+
return _el$71;
|
|
643
|
+
}
|
|
644
|
+
}), _el$75, _co$16);
|
|
645
|
+
_el$72.addEventListener("blur", () => setTimeout(() => setIsOpen(false), 200));
|
|
646
|
+
_el$72.addEventListener("focus", () => {
|
|
542
647
|
if (suggestions().length) setIsOpen(true);
|
|
543
648
|
});
|
|
544
|
-
_el$
|
|
545
|
-
insert(_el$
|
|
649
|
+
_el$72.$$input = (e) => handleInput(e.currentTarget.value);
|
|
650
|
+
insert(_el$70, createComponent(Show, {
|
|
546
651
|
get when() {
|
|
547
652
|
return memo(() => !!isOpen())() && suggestions().length > 0;
|
|
548
653
|
},
|
|
549
654
|
get children() {
|
|
550
|
-
var _el$
|
|
551
|
-
insert(_el$
|
|
655
|
+
var _el$73 = getNextElement(_tmpl$23);
|
|
656
|
+
insert(_el$73, createComponent(For, {
|
|
552
657
|
get each() {
|
|
553
658
|
return suggestions();
|
|
554
659
|
},
|
|
555
|
-
children: (item) =>
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
660
|
+
children: (item) => {
|
|
661
|
+
const isSelected = () => isMultiple() && selectedValues().includes(item.value);
|
|
662
|
+
return (() => {
|
|
663
|
+
var _el$82 = getNextElement(_tmpl$26), _el$84 = _el$82.firstChild, [_el$85, _co$19] = getNextMarker(_el$84.nextSibling), _el$86 = _el$85.nextSibling, [_el$87, _co$20] = getNextMarker(_el$86.nextSibling);
|
|
664
|
+
_el$82.$$click = () => selectSuggestion(item);
|
|
665
|
+
_el$82.$$mousedown = (e) => e.preventDefault();
|
|
666
|
+
insert(_el$82, () => item.label, _el$85, _co$19);
|
|
667
|
+
insert(_el$82, createComponent(Show, {
|
|
668
|
+
get when() {
|
|
669
|
+
return isSelected();
|
|
670
|
+
},
|
|
671
|
+
get children() {
|
|
672
|
+
return getNextElement(_tmpl$25);
|
|
673
|
+
}
|
|
674
|
+
}), _el$87, _co$20);
|
|
675
|
+
effect((_p$) => {
|
|
676
|
+
var _v$71 = `w-full text-left px-3 py-2 text-sm hover:bg-blue-50 dark:hover:bg-blue-900/20 ${isSelected() ? "text-blue-600 dark:text-blue-400 bg-blue-50/50 dark:bg-blue-900/10" : "text-gray-900 dark:text-white"}`, _v$72 = isSelected();
|
|
677
|
+
_v$71 !== _p$.e && className(_el$82, _p$.e = _v$71);
|
|
678
|
+
_v$72 !== _p$.t && setProperty(_el$82, "disabled", _p$.t = _v$72);
|
|
679
|
+
return _p$;
|
|
680
|
+
}, {
|
|
681
|
+
e: void 0,
|
|
682
|
+
t: void 0
|
|
683
|
+
});
|
|
684
|
+
runHydrationEvents();
|
|
685
|
+
return _el$82;
|
|
686
|
+
})();
|
|
687
|
+
}
|
|
563
688
|
}));
|
|
564
|
-
return _el$
|
|
689
|
+
return _el$73;
|
|
565
690
|
}
|
|
566
|
-
}), _el$
|
|
691
|
+
}), _el$77, _co$17);
|
|
567
692
|
effect((_p$) => {
|
|
568
|
-
var _v$
|
|
569
|
-
_v$
|
|
570
|
-
_v$
|
|
571
|
-
_v$
|
|
693
|
+
var _v$68 = isMultiple() && selectedValues().length ? "Add more..." : props.field.placeholder, _v$69 = props.disabled, _v$70 = props.baseClass;
|
|
694
|
+
_v$68 !== _p$.e && setAttribute(_el$72, "placeholder", _p$.e = _v$68);
|
|
695
|
+
_v$69 !== _p$.t && setProperty(_el$72, "disabled", _p$.t = _v$69);
|
|
696
|
+
_v$70 !== _p$.a && className(_el$72, _p$.a = _v$70);
|
|
572
697
|
return _p$;
|
|
573
698
|
}, {
|
|
574
699
|
e: void 0,
|
|
575
700
|
t: void 0,
|
|
576
701
|
a: void 0
|
|
577
702
|
});
|
|
578
|
-
effect(() => setProperty(_el$
|
|
703
|
+
effect(() => setProperty(_el$72, "value", query()));
|
|
579
704
|
runHydrationEvents();
|
|
580
|
-
return _el$
|
|
705
|
+
return _el$70;
|
|
581
706
|
})();
|
|
582
707
|
};
|
|
583
708
|
delegateEvents(["input", "click", "mousedown"]);
|