@woodger/antd 0.1.3 → 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/auto-complete/AutoComplete.svelte +76 -30
- package/dist/cascader/CascaderCore.svelte +108 -44
- package/dist/input/TextArea.svelte +97 -63
- package/dist/input/textarea-value.svelte.d.ts +14 -0
- package/dist/input/textarea-value.svelte.js +48 -0
- package/dist/input/textarea.dom.d.ts +2 -0
- package/dist/input/textarea.dom.js +17 -0
- package/dist/mentions/Mentions.svelte +71 -52
- package/dist/mentions/mentions.dom.d.ts +0 -2
- package/dist/mentions/mentions.dom.js +0 -54
- package/dist/picker/RangePicker.svelte +3 -1
- package/dist/picker/RangePickerCore.svelte +206 -67
- package/dist/picker/SinglePicker.svelte +191 -77
- package/dist/picker/date-picker.types.d.ts +6 -0
- package/dist/picker/picker-components.types.d.ts +2 -2
- package/dist/picker/picker-editor.model.svelte.d.ts +13 -0
- package/dist/picker/picker-editor.model.svelte.js +40 -0
- package/dist/picker/picker-mask-input.model.svelte.js +2 -1
- package/dist/picker/picker-popup.dom.js +2 -0
- package/dist/picker/picker-popup.model.svelte.d.ts +3 -0
- package/dist/picker/picker-popup.model.svelte.js +35 -2
- package/dist/picker/time-picker.types.d.ts +2 -1
- package/dist/select/Select.svelte +112 -44
- package/dist/tree-select/TreeSelectControl.svelte +180 -69
- package/package.json +1 -1
- package/readme.md +15 -15
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
import { normalizePickerFieldFormat } from './picker-mask.engine';
|
|
12
12
|
import { createPickerMaskInput, type PickerMaskSharedKey } from './picker-mask-input.model.svelte.js';
|
|
13
13
|
import {
|
|
14
|
-
createPickerEditor, isPickerInputEvent, pickerEditorMaskEvents,
|
|
14
|
+
createPickerEditor, isPickerInputEvent, pickerEditorMaskEvents, pickerEditorServerAutofocus,
|
|
15
|
+
pickerEditorSize, pickerInputNeedsHelp, usePickerEditorAutofocus, type PickerEditorEvent
|
|
15
16
|
} from './picker-editor.model.svelte.js';
|
|
16
17
|
import type { DatePickerEditorAttributes, DatePickerPanelContext } from './picker-components.types';
|
|
17
18
|
import { createPickerPanelEngine, pickerPanelClock, pickerPanelSlot } from './picker-panel.engine';
|
|
@@ -89,6 +90,9 @@
|
|
|
89
90
|
maxDate,
|
|
90
91
|
needConfirm,
|
|
91
92
|
allowClear,
|
|
93
|
+
autoFocus,
|
|
94
|
+
tabIndex,
|
|
95
|
+
autoComplete,
|
|
92
96
|
inputReadOnly,
|
|
93
97
|
preserveInvalidOnBlur = false,
|
|
94
98
|
showNow: providedShowNow,
|
|
@@ -223,6 +227,9 @@
|
|
|
223
227
|
disabled ?? field?.disabled ?? form?.disabled ?? config.componentDisabled
|
|
224
228
|
);
|
|
225
229
|
let visible = $derived((open ?? internalOpen) && !blocked);
|
|
230
|
+
let committedOpenRequest = untrack(captureOpenRequest);
|
|
231
|
+
$effect(() => { committedOpenRequest = captureOpenRequest(); });
|
|
232
|
+
|
|
226
233
|
let actualLocale = $derived(
|
|
227
234
|
{ ...datePickerEnUS.lang, ...config.locale.datePicker?.lang, ...locale?.lang }
|
|
228
235
|
);
|
|
@@ -230,10 +237,9 @@
|
|
|
230
237
|
let formats = $derived(time ? timePickerFormats(time, actualLocale)
|
|
231
238
|
: pickerFormats({ format, showTime, picker }, actualLocale));
|
|
232
239
|
let maskFormat = $derived(normalizePickerFieldFormat<DateType>(time ? time.format : format, '').mask);
|
|
233
|
-
let
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
);
|
|
240
|
+
let firstFormat = $derived(formats[0]);
|
|
241
|
+
let readOnly = $derived(typeof firstFormat === 'function'
|
|
242
|
+
|| (inputReadOnly ?? (attributes.readonly || formats.length === 0)));
|
|
237
243
|
let confirm = $derived(needConfirm ?? Boolean(showTime));
|
|
238
244
|
let showNow = $derived(providedShowNow === undefined ? true : providedShowNow);
|
|
239
245
|
let resolvedSize = $derived(size ?? compact?.size ?? config.componentSize);
|
|
@@ -287,6 +293,8 @@
|
|
|
287
293
|
let nativeInput = $state<HTMLInputElement>();
|
|
288
294
|
const customInput = createPickerEditor(node => maskInput.attach(node, true));
|
|
289
295
|
let input = $derived(!multipleOptions && components?.input ? customInput.element : nativeInput);
|
|
296
|
+
let autofocusRequest = $derived(attributes.autofocus == null ? autoFocus : null);
|
|
297
|
+
usePickerEditorAutofocus(() => input, () => autofocusRequest);
|
|
290
298
|
let rootElement = $state<HTMLDivElement>();
|
|
291
299
|
let popup = $state<HTMLDivElement>();
|
|
292
300
|
const panelFocus = preservePickerPanelFocus(() => ({
|
|
@@ -403,20 +411,16 @@
|
|
|
403
411
|
? formatPicker(hoverValue, actualLocale.locale, formats) : text);
|
|
404
412
|
let formattedTimeDraft = $derived(time
|
|
405
413
|
? formatPicker(draft, actualLocale.locale, formats) : undefined);
|
|
406
|
-
let
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const first = formats[0];
|
|
411
|
-
const length = typeof first === 'function' ? first(now).length : first.length;
|
|
412
|
-
return Math.max(8, length) + 2;
|
|
413
|
-
});
|
|
414
|
+
let committedInputDraft = untrack(captureInputDraft);
|
|
415
|
+
$effect(() => { committedInputDraft = captureInputDraft(); });
|
|
416
|
+
|
|
417
|
+
let editorSize = $derived(pickerEditorSize(firstFormat, Boolean(time), () => adapter.getNow()));
|
|
414
418
|
const maskInput = createPickerMaskInput(() => ({
|
|
415
419
|
text: displayText, mask: maskFormat, active: focused, helped: !!hoverValue,
|
|
416
420
|
readOnly, preserveInvalidOnBlur,
|
|
417
421
|
validateText: next => !!parsePicker(next, actualLocale.locale, formats),
|
|
418
422
|
acceptInput: next => inputChange(next, true),
|
|
419
|
-
onHelp: () =>
|
|
423
|
+
onHelp: () => completeEditorOpen(true)
|
|
420
424
|
}));
|
|
421
425
|
const maskEvents = pickerEditorMaskEvents(maskInput, () => attributes);
|
|
422
426
|
const multiplePicker = createMultiplePicker({
|
|
@@ -569,7 +573,10 @@
|
|
|
569
573
|
return;
|
|
570
574
|
}
|
|
571
575
|
|
|
572
|
-
|
|
576
|
+
const rendered = formatted ?? formatPicker(mergedValue, actualLocale.locale, formats);
|
|
577
|
+
const keepText = !switchedEditorMode && untrack(() => preserveInvalidOnBlur && !visible
|
|
578
|
+
&& formatPicker(draft, actualLocale.locale, formats) === rendered);
|
|
579
|
+
if (!keepText) text = rendered;
|
|
573
580
|
draft = mergedValue;
|
|
574
581
|
dirty = false;
|
|
575
582
|
retainedDateSelection = undefined;
|
|
@@ -608,6 +615,9 @@
|
|
|
608
615
|
}
|
|
609
616
|
});
|
|
610
617
|
$effect(() => {
|
|
618
|
+
if (container.processingOutsideClose) {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
611
621
|
const next = visible;
|
|
612
622
|
if (wasVisible && !next) {
|
|
613
623
|
hoverValue = null;
|
|
@@ -618,16 +628,7 @@
|
|
|
618
628
|
untrack(() => multiplePicker.close(confirm));
|
|
619
629
|
}
|
|
620
630
|
else {
|
|
621
|
-
untrack(
|
|
622
|
-
// A controlled close can finish while the editor still owns native focus.
|
|
623
|
-
const datetimeDraft = open === false && showTime && dirty && draftSource === 'panel';
|
|
624
|
-
if (retainedDateSelection || datetimeDraft) {
|
|
625
|
-
dateSelectionInteraction.trigger(0, 'popupClose');
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
628
|
-
dateSelectionInteraction.reset();
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
+
untrack(settleClosedDateSelection);
|
|
631
632
|
}
|
|
632
633
|
}
|
|
633
634
|
wasVisible = next;
|
|
@@ -660,10 +661,15 @@
|
|
|
660
661
|
alignedPlacement = next;
|
|
661
662
|
},
|
|
662
663
|
onDismiss: reason => {
|
|
664
|
+
if (reason === 'outside') {
|
|
665
|
+
container.scheduleClose(anchor, () => requestOpen(false));
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
|
|
663
669
|
const keepSelection = !time && retainedDateSelection;
|
|
664
|
-
const cancelPanel =
|
|
670
|
+
const cancelPanel = retainedDateSelection === 'panel';
|
|
665
671
|
if (time) {
|
|
666
|
-
|
|
672
|
+
cancelTimePanel();
|
|
667
673
|
}
|
|
668
674
|
else if (cancelPanel) {
|
|
669
675
|
dateSelectionInteraction.trigger(0, 'esc');
|
|
@@ -675,7 +681,7 @@
|
|
|
675
681
|
else {
|
|
676
682
|
finish(false);
|
|
677
683
|
}
|
|
678
|
-
if (
|
|
684
|
+
if (!destroyed && (!keepSelection || cancelPanel))
|
|
679
685
|
input?.focus();
|
|
680
686
|
}
|
|
681
687
|
}));
|
|
@@ -710,6 +716,7 @@
|
|
|
710
716
|
return !disabled && !pickerTimeDisabled(next, rules.timeRules);
|
|
711
717
|
}
|
|
712
718
|
function requestOpen(next: boolean, options?: { preserveDraft?: boolean; opened?: boolean; }) {
|
|
719
|
+
container.cancelClose();
|
|
713
720
|
if (blocked || (options?.opened ?? visible) === next) {
|
|
714
721
|
return;
|
|
715
722
|
}
|
|
@@ -726,6 +733,22 @@
|
|
|
726
733
|
onOpenChange?.(next);
|
|
727
734
|
}
|
|
728
735
|
|
|
736
|
+
/** Retains the committed visibility and handler if an action removes its editor. */
|
|
737
|
+
function captureOpenRequest() {
|
|
738
|
+
return { allowed: !blocked, wasOpen: visible, notify: onOpenChange?.bind(callbackOwner) };
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** Completes an opening requested by a click or edit, including after native removal. */
|
|
742
|
+
function completeEditorOpen(preserveDraft = false) {
|
|
743
|
+
if (!destroyed) {
|
|
744
|
+
requestOpen(true, { preserveDraft });
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const { allowed, wasOpen, notify } = committedOpenRequest;
|
|
749
|
+
if (allowed && !wasOpen) notify?.(true);
|
|
750
|
+
}
|
|
751
|
+
|
|
729
752
|
/** Keeps the close request available even if the owner removes the picker during a callback. */
|
|
730
753
|
function captureClose(opened?: boolean) {
|
|
731
754
|
const notify = onOpenChange?.bind(callbackOwner);
|
|
@@ -742,12 +765,12 @@
|
|
|
742
765
|
}
|
|
743
766
|
|
|
744
767
|
/** When cancelling a selection set, the close event precedes restoring the tags. */
|
|
745
|
-
function
|
|
746
|
-
if (
|
|
768
|
+
function cancelTimePanel() {
|
|
769
|
+
if (!multipleOptions) {
|
|
747
770
|
timeInteraction.trigger(0, 'esc');
|
|
748
771
|
}
|
|
749
772
|
requestOpen(false);
|
|
750
|
-
if (
|
|
773
|
+
if (multipleOptions) {
|
|
751
774
|
timeInteraction.trigger(0, 'esc');
|
|
752
775
|
}
|
|
753
776
|
}
|
|
@@ -799,7 +822,7 @@
|
|
|
799
822
|
publication.notify?.(next, formatPicker(next, publication.locale, publication.formats));
|
|
800
823
|
}
|
|
801
824
|
}
|
|
802
|
-
function commit(next: DateType | null, accepted?: DateType | null) {
|
|
825
|
+
function commit(next: DateType | null, accepted?: DateType | null, keepEditorText = false) {
|
|
803
826
|
if (!time) dateSelectionInteraction.reset();
|
|
804
827
|
if (!time && blocked || next && !valid(next)) {
|
|
805
828
|
return false;
|
|
@@ -822,9 +845,31 @@
|
|
|
822
845
|
dirty = false;
|
|
823
846
|
if (changed)
|
|
824
847
|
onChange?.(next, formatPicker(next, actualLocale.locale, formats));
|
|
825
|
-
if (!destroyed && !time) void tick().then(resetText);
|
|
848
|
+
if (!destroyed && !time && !keepEditorText) void tick().then(resetText);
|
|
826
849
|
return true;
|
|
827
850
|
}
|
|
851
|
+
/** A typed value keeps its editor display even if the owner declines the submitted value. */
|
|
852
|
+
function submitClosedDraft(_index: number, all: boolean) {
|
|
853
|
+
if (all) commit(draft, undefined, draftSource === 'input');
|
|
854
|
+
}
|
|
855
|
+
/** Rolling back to the same formatted value preserves raw input when the editor opts in. */
|
|
856
|
+
function settleClosedDateSelection() {
|
|
857
|
+
if (retainedDateSelection || dirty && draftSource === 'panel') {
|
|
858
|
+
dateSelectionInteraction.trigger(0, 'popupClose');
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
// Tab can finish the interaction while moving focus to the internal clear button.
|
|
862
|
+
if (!dirty || dateSelectionInteraction.currentIndex === null) {
|
|
863
|
+
dateSelectionInteraction.reset();
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
const retainText = preserveInvalidOnBlur && draftSource === 'input'
|
|
868
|
+
&& formatPicker(draft, actualLocale.locale, formats) === formattedDateValue;
|
|
869
|
+
const rawText = text;
|
|
870
|
+
dateSelectionInteraction.trigger(0, 'popupClose', undefined, submitClosedDraft);
|
|
871
|
+
if (!destroyed && retainText) text = rawText;
|
|
872
|
+
}
|
|
828
873
|
/** Single-value confirmation replaces the accepted list with one date. */
|
|
829
874
|
function storeDate(next: DateType | null) {
|
|
830
875
|
dateValues = next ? [next] : [];
|
|
@@ -1385,26 +1430,80 @@
|
|
|
1385
1430
|
};
|
|
1386
1431
|
}
|
|
1387
1432
|
|
|
1433
|
+
/** Captures the calendar listener and its formatting while the editor is mounted. */
|
|
1434
|
+
function captureInputDraft() {
|
|
1435
|
+
const source = time ? 'time' as const : 'date' as const;
|
|
1436
|
+
const compare = time ? timePickerSameValue : dates.sameValue;
|
|
1437
|
+
return {
|
|
1438
|
+
previous: draft,
|
|
1439
|
+
source,
|
|
1440
|
+
compare,
|
|
1441
|
+
locale: actualLocale.locale,
|
|
1442
|
+
formats,
|
|
1443
|
+
restrictions: time ? undefined : validationRules(),
|
|
1444
|
+
notify: onCalendarChange?.bind(callbackOwner)
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/** Completes the parsed draft without writing back to a removed field or panel. */
|
|
1449
|
+
function completeRemovedInputDraft(next: DateType | null) {
|
|
1450
|
+
const state = committedInputDraft;
|
|
1451
|
+
if (!next || !fields.isValidate(next) || state.compare(state.previous, next)) {
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
if (state.restrictions && !selectionIsAllowed(next, state.restrictions)) {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
state.notify?.(next, formatPicker(next, state.locale, state.formats), { source: state.source });
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1388
1461
|
function inputChange(next: string, masked = false) {
|
|
1389
|
-
if (
|
|
1390
|
-
|
|
1391
|
-
retainedDateSelection = undefined;
|
|
1392
|
-
dateSelectionInteraction.trigger(0, 'input');
|
|
1462
|
+
if (destroyed) {
|
|
1463
|
+
return;
|
|
1393
1464
|
}
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1465
|
+
|
|
1466
|
+
const inputLocale = actualLocale.locale;
|
|
1467
|
+
const inputFormats = formats;
|
|
1468
|
+
if (!masked && !visible && next !== ''
|
|
1469
|
+
&& pickerInputNeedsHelp(next, formatPicker(hoverValue ?? draft, inputLocale, inputFormats))) {
|
|
1470
|
+
completeEditorOpen(true);
|
|
1471
|
+
}
|
|
1472
|
+
if (!destroyed) recordInputText(next);
|
|
1473
|
+
|
|
1474
|
+
const parsed = parsePicker(next, inputLocale, inputFormats);
|
|
1475
|
+
if (destroyed) {
|
|
1476
|
+
completeRemovedInputDraft(parsed);
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1399
1480
|
if (time) {
|
|
1400
|
-
invalidTimeInput =
|
|
1481
|
+
invalidTimeInput = next !== '' && !(parsed && fields.isValidate(parsed));
|
|
1401
1482
|
timeInteraction.trigger(0, 'input', parsed && fields.isValidate(parsed) ? [parsed] : undefined);
|
|
1483
|
+
return;
|
|
1402
1484
|
}
|
|
1403
|
-
|
|
1485
|
+
if (picker === 'date' || picker === 'quarter' || picker === 'week') quarterInputValue = parsed;
|
|
1486
|
+
if (parsed && valid(parsed)) {
|
|
1404
1487
|
setDraft(parsed, 'date');
|
|
1488
|
+
if (destroyed) {
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
if (firstFormat !== inputFormats[0] || actualLocale.locale !== inputLocale) {
|
|
1493
|
+
text = formatPicker(draft, actualLocale.locale, formats);
|
|
1494
|
+
}
|
|
1405
1495
|
if (picker === 'date' && !defaultPickerValue) internalPanel = parsed;
|
|
1406
1496
|
}
|
|
1407
1497
|
}
|
|
1498
|
+
function recordInputText(next: string) {
|
|
1499
|
+
if (!time) {
|
|
1500
|
+
retainedDateSelection = undefined;
|
|
1501
|
+
dateSelectionInteraction.trigger(0, 'input');
|
|
1502
|
+
}
|
|
1503
|
+
text = next;
|
|
1504
|
+
dirty = true;
|
|
1505
|
+
draftSource = 'input';
|
|
1506
|
+
}
|
|
1408
1507
|
function keyboard(event: PickerEditorEvent<KeyboardEvent>) {
|
|
1409
1508
|
const shared = (_event: KeyboardEvent, maskKey?: PickerMaskSharedKey) => {
|
|
1410
1509
|
if (isPickerInputEvent(event)) {
|
|
@@ -1572,13 +1671,30 @@
|
|
|
1572
1671
|
else {
|
|
1573
1672
|
dateSelectionInteraction.trigger(0, 'field-switch');
|
|
1574
1673
|
}
|
|
1674
|
+
notifyEditorFocus(event);
|
|
1675
|
+
}
|
|
1676
|
+
function notifyEditorFocus(event: PickerEditorEvent<FocusEvent>) {
|
|
1677
|
+
if (destroyed) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
container.cancelClose();
|
|
1682
|
+
const retainedFocus = onFocus?.bind(callbackOwner);
|
|
1575
1683
|
if (isPickerInputEvent(event)) {
|
|
1576
1684
|
onfocus?.(event);
|
|
1577
1685
|
}
|
|
1578
|
-
|
|
1686
|
+
if (destroyed) {
|
|
1687
|
+
retainedFocus?.(event, {});
|
|
1688
|
+
}
|
|
1689
|
+
else {
|
|
1690
|
+
onFocus?.(event, {});
|
|
1691
|
+
}
|
|
1579
1692
|
}
|
|
1580
1693
|
function editorBlur(event: PickerEditorEvent<FocusEvent>) {
|
|
1581
1694
|
maskInput.blur();
|
|
1695
|
+
notifyEditorBlur(event);
|
|
1696
|
+
}
|
|
1697
|
+
function notifyEditorBlur(event: PickerEditorEvent<FocusEvent>) {
|
|
1582
1698
|
// Removal can fire native blur while the props of the connected editor are paused.
|
|
1583
1699
|
if (isPickerInputEvent(event)) {
|
|
1584
1700
|
committedNativeBlur?.(event);
|
|
@@ -1589,6 +1705,7 @@
|
|
|
1589
1705
|
|
|
1590
1706
|
/** Panel descendants use the container as currentTarget, including a custom panel. */
|
|
1591
1707
|
function panelFocusIn(event: DatePickerFocusEvent) {
|
|
1708
|
+
container.cancelClose();
|
|
1592
1709
|
focused = true;
|
|
1593
1710
|
onFocus?.(event, {});
|
|
1594
1711
|
}
|
|
@@ -1612,6 +1729,8 @@
|
|
|
1612
1729
|
const describedBy = [attributes['aria-describedby'], field?.describedBy].filter(Boolean);
|
|
1613
1730
|
return {
|
|
1614
1731
|
...nativeAttributes,
|
|
1732
|
+
...pickerEditorServerAutofocus(autofocusRequest),
|
|
1733
|
+
tabindex: attributes.tabindex ?? tabIndex,
|
|
1615
1734
|
id: id ?? field?.id,
|
|
1616
1735
|
name: name ?? field?.name,
|
|
1617
1736
|
placeholder: placeholderText,
|
|
@@ -1625,11 +1744,11 @@
|
|
|
1625
1744
|
'aria-describedby': describedBy.join(' ') || undefined,
|
|
1626
1745
|
class: semantic?.classes.input,
|
|
1627
1746
|
style: semantic?.styles.input,
|
|
1628
|
-
size:
|
|
1747
|
+
size: editorSize,
|
|
1629
1748
|
disabled: blocked,
|
|
1630
1749
|
readonly: readOnly,
|
|
1631
1750
|
required: attributes.required ?? field?.required,
|
|
1632
|
-
autocomplete: 'off',
|
|
1751
|
+
autocomplete: attributes.autocomplete ?? autoComplete ?? 'off',
|
|
1633
1752
|
value: maskInput.value,
|
|
1634
1753
|
defaultValue: maskInput.value,
|
|
1635
1754
|
oninput: editorInput,
|
|
@@ -1641,6 +1760,10 @@
|
|
|
1641
1760
|
};
|
|
1642
1761
|
}
|
|
1643
1762
|
function blurWithin(event?: FocusEvent) {
|
|
1763
|
+
if (destroyed) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1644
1767
|
if (event?.relatedTarget instanceof Node
|
|
1645
1768
|
&& (rootElement?.contains(event.relatedTarget)
|
|
1646
1769
|
|| popup?.contains(
|
|
@@ -1649,10 +1772,10 @@
|
|
|
1649
1772
|
return;
|
|
1650
1773
|
}
|
|
1651
1774
|
const authoredControl = pickerBlurredAuthoredControl(event, popup);
|
|
1652
|
-
|
|
1775
|
+
container.scheduleClose(rootElement, () => {
|
|
1653
1776
|
// A removed component no longer owns focus or the derived editor ref.
|
|
1654
1777
|
const root = rootElement;
|
|
1655
|
-
if (!root?.isConnected) {
|
|
1778
|
+
if (destroyed || !root?.isConnected) {
|
|
1656
1779
|
return;
|
|
1657
1780
|
}
|
|
1658
1781
|
const editor = input;
|
|
@@ -1668,24 +1791,20 @@
|
|
|
1668
1791
|
}
|
|
1669
1792
|
focused = false;
|
|
1670
1793
|
field?.onBlur();
|
|
1671
|
-
if (
|
|
1672
|
-
|
|
1673
|
-
closeDateSelection();
|
|
1674
|
-
}
|
|
1675
|
-
else {
|
|
1676
|
-
finish(false);
|
|
1677
|
-
}
|
|
1794
|
+
if (destroyed) {
|
|
1795
|
+
return;
|
|
1678
1796
|
}
|
|
1679
|
-
if (
|
|
1797
|
+
if (!preserveInvalidOnBlur) {
|
|
1680
1798
|
text = formatPicker(draft, actualLocale.locale, formats);
|
|
1681
|
-
invalidTimeInput = false;
|
|
1799
|
+
if (time) invalidTimeInput = false;
|
|
1682
1800
|
}
|
|
1801
|
+
requestOpen(false);
|
|
1683
1802
|
});
|
|
1684
1803
|
}
|
|
1685
1804
|
function resetTimeValue() {
|
|
1686
1805
|
const changed = !timePickerSameValue(draft, mergedValue);
|
|
1687
1806
|
setDraft(mergedValue, 'time');
|
|
1688
|
-
if (changed) text = formatPicker(draft, actualLocale.locale, formats);
|
|
1807
|
+
if (!destroyed && changed) text = formatPicker(draft, actualLocale.locale, formats);
|
|
1689
1808
|
dirty = false;
|
|
1690
1809
|
}
|
|
1691
1810
|
function syncTimePickerValue(
|
|
@@ -1783,19 +1902,19 @@
|
|
|
1783
1902
|
if (!pickerSelectorEventPath(event, popup)) {
|
|
1784
1903
|
return;
|
|
1785
1904
|
}
|
|
1786
|
-
|
|
1905
|
+
const enabled = !blocked;
|
|
1906
|
+
const clock = rootTimeProps ? undefined : time;
|
|
1907
|
+
const notifyClick = clock ? clock.onclick ?? clock.onClick : onClick?.bind(callbackOwner);
|
|
1908
|
+
if (enabled) {
|
|
1787
1909
|
const root = event.currentTarget;
|
|
1788
1910
|
if (!root.contains(getPopupActiveElement(root))) {
|
|
1789
1911
|
input?.focus();
|
|
1790
1912
|
}
|
|
1791
|
-
|
|
1913
|
+
completeEditorOpen();
|
|
1792
1914
|
}
|
|
1793
1915
|
|
|
1794
|
-
if (
|
|
1795
|
-
|
|
1796
|
-
}
|
|
1797
|
-
else {
|
|
1798
|
-
onClick?.(event);
|
|
1916
|
+
if (notifyClick && (enabled || !clock)) {
|
|
1917
|
+
publishScalarAction(() => notifyClick(event));
|
|
1799
1918
|
}
|
|
1800
1919
|
}
|
|
1801
1920
|
/** Pressing an adornment keeps the editor focused until the click is complete. */
|
|
@@ -1861,7 +1980,7 @@
|
|
|
1861
1980
|
if (time && event.key === 'Escape' && visible) {
|
|
1862
1981
|
event.preventDefault();
|
|
1863
1982
|
event.stopPropagation();
|
|
1864
|
-
|
|
1983
|
+
cancelTimePanel();
|
|
1865
1984
|
}
|
|
1866
1985
|
else if (time && event.key === 'Tab' && visible) {
|
|
1867
1986
|
timeInteraction.trigger(0, 'keyboard-submit-weak');
|
|
@@ -2132,9 +2251,7 @@
|
|
|
2132
2251
|
>
|
|
2133
2252
|
{#if time?.renderExtraFooter}
|
|
2134
2253
|
<div class={`${prefix}-footer-extra`} data-picker-authored-content>
|
|
2135
|
-
{
|
|
2136
|
-
{@render time.renderExtraFooter(mode)}
|
|
2137
|
-
{:else}{@render time.renderExtraFooter()}{/if}
|
|
2254
|
+
{@render time.renderExtraFooter(mode)}
|
|
2138
2255
|
</div>
|
|
2139
2256
|
{/if}
|
|
2140
2257
|
{#if panelConfirm || showCurrent}<ul class={`${prefix}-ranges`}>
|
|
@@ -2260,6 +2377,7 @@
|
|
|
2260
2377
|
/>
|
|
2261
2378
|
<input
|
|
2262
2379
|
{...attributes}
|
|
2380
|
+
{...pickerEditorServerAutofocus(autofocusRequest)}
|
|
2263
2381
|
bind:this={nativeInput}
|
|
2264
2382
|
id={id ?? field?.id}
|
|
2265
2383
|
name={name ?? field?.name}
|
|
@@ -2278,20 +2396,16 @@
|
|
|
2278
2396
|
value={multipleText}
|
|
2279
2397
|
defaultValue={multipleText}
|
|
2280
2398
|
autocomplete="off"
|
|
2399
|
+
tabindex={attributes.tabindex ?? tabIndex}
|
|
2281
2400
|
disabled={blocked}
|
|
2282
2401
|
readonly
|
|
2283
2402
|
{onclick}
|
|
2284
2403
|
onkeydown={multipleKeyboard}
|
|
2285
2404
|
onfocus={event => {
|
|
2286
2405
|
focused = true;
|
|
2287
|
-
|
|
2288
|
-
onFocus?.(event, {});
|
|
2289
|
-
}}
|
|
2290
|
-
onblur={event => {
|
|
2291
|
-
onblur?.(event);
|
|
2292
|
-
onBlur?.(event, {});
|
|
2293
|
-
blurWithin(event);
|
|
2406
|
+
notifyEditorFocus(event);
|
|
2294
2407
|
}}
|
|
2408
|
+
onblur={notifyEditorBlur}
|
|
2295
2409
|
/>
|
|
2296
2410
|
{@render pickerSuffix()}
|
|
2297
2411
|
{:else}
|
|
@@ -153,6 +153,12 @@ export interface DatePickerProps<DateType extends object = Dayjs> extends Omit<H
|
|
|
153
153
|
needConfirm?: boolean;
|
|
154
154
|
/** @defaultValue true */
|
|
155
155
|
allowClear?: DatePickerAllowClear;
|
|
156
|
+
/** Focuses the editor when it mounts. Native autofocus takes precedence. */
|
|
157
|
+
autoFocus?: boolean;
|
|
158
|
+
/** Tab order of the editor, overridden by native tabindex. */
|
|
159
|
+
tabIndex?: number;
|
|
160
|
+
/** Autocomplete hint for the single or range editor. Defaults to off. */
|
|
161
|
+
autoComplete?: HTMLInputAttributes['autocomplete'];
|
|
156
162
|
inputReadOnly?: boolean;
|
|
157
163
|
/** @defaultValue false */
|
|
158
164
|
preserveInvalidOnBlur?: boolean;
|
|
@@ -74,9 +74,9 @@ export interface DatePickerPanelContext<DateType extends object = Dayjs> extends
|
|
|
74
74
|
onHover: (date: DateType | null) => void;
|
|
75
75
|
}
|
|
76
76
|
export type DatePickerPanel<DateType extends object = Dayjs> = Snippet<[DatePickerPanelContext<DateType>]>;
|
|
77
|
-
/** The
|
|
77
|
+
/** The shared core accepts footers typed for the modes of each public picker. */
|
|
78
78
|
export type PickerModeFooter<Mode extends DatePickerMode> = {
|
|
79
|
-
render(mode
|
|
79
|
+
render(mode: Mode): ReturnType<Snippet>;
|
|
80
80
|
}['render'];
|
|
81
81
|
/** Replacing the field elements and the opened panel. */
|
|
82
82
|
export interface DatePickerComponents<DateType extends object = Dayjs> extends Partial<Record<DatePickerPanelMode, DatePickerPanel<DateType>>> {
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
import type { DatePickerFormat } from './date-picker.types';
|
|
1
2
|
import type { DatePickerEditorElement, DatePickerEditorRegistration } from './picker-components.types';
|
|
2
3
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
4
|
import type { createPickerMaskInput } from './picker-mask-input.model.svelte';
|
|
4
5
|
export type PickerEditorEvent<EventType extends Event> = EventType & {
|
|
5
6
|
currentTarget: EventTarget & DatePickerEditorElement;
|
|
6
7
|
};
|
|
8
|
+
/** A changed draft requests the panel. Empty text and the mask template are editor states. */
|
|
9
|
+
export declare function pickerInputNeedsHelp(text: string, accepted: string, mask?: string | null): boolean;
|
|
10
|
+
/** Reserve space for the first format and the picker's minimum editor width. */
|
|
11
|
+
export declare function pickerEditorSize<DateType extends object>(format: DatePickerFormat<DateType> | undefined, time: boolean, getNow: () => DateType): number;
|
|
12
|
+
/** Let the browser apply autofocus when it parses the server-rendered editor. */
|
|
13
|
+
export declare function pickerEditorServerAutofocus(requested: boolean | null | undefined): {
|
|
14
|
+
autofocus: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
autofocus?: undefined;
|
|
17
|
+
};
|
|
18
|
+
/** Focuses each new editor once. A null request leaves the native attribute in charge. */
|
|
19
|
+
export declare function usePickerEditorAutofocus(readEditor: () => DatePickerEditorElement | undefined, readRequest: () => boolean | null | undefined): void;
|
|
7
20
|
/** Old native callbacks and refs belong to input elements. */
|
|
8
21
|
export declare function isPickerInput(element: DatePickerEditorElement | undefined): element is HTMLInputElement;
|
|
9
22
|
/** Narrowing currentTarget for public events HTMLInputAttributes. */
|
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
// Manages picker editor sizing, registration, mount focus, and native mask events.
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
/** A changed draft requests the panel. Empty text and the mask template are editor states. */
|
|
4
|
+
export function pickerInputNeedsHelp(text, accepted, mask) {
|
|
5
|
+
return text !== '' && text !== accepted && text !== mask;
|
|
6
|
+
}
|
|
7
|
+
/** Reserve space for the first format and the picker's minimum editor width. */
|
|
8
|
+
export function pickerEditorSize(format, time, getNow) {
|
|
9
|
+
const text = typeof format === 'function' ? format(getNow()) : format;
|
|
10
|
+
return Math.max(time ? 8 : 10, text?.length ?? 0) + 2;
|
|
11
|
+
}
|
|
12
|
+
/** Let the browser apply autofocus when it parses the server-rendered editor. */
|
|
13
|
+
export function pickerEditorServerAutofocus(requested) {
|
|
14
|
+
return requested && typeof document === 'undefined' ? { autofocus: true } : {};
|
|
15
|
+
}
|
|
16
|
+
/** Focuses each new editor once. A null request leaves the native attribute in charge. */
|
|
17
|
+
export function usePickerEditorAutofocus(readEditor, readRequest) {
|
|
18
|
+
let previous;
|
|
19
|
+
$effect(() => {
|
|
20
|
+
const editor = readEditor();
|
|
21
|
+
const request = readRequest();
|
|
22
|
+
if (!editor?.isConnected) {
|
|
23
|
+
previous = undefined;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const last = previous;
|
|
27
|
+
previous = { editor, request };
|
|
28
|
+
if (request === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (last?.editor === editor) {
|
|
32
|
+
if (last.request !== request) {
|
|
33
|
+
editor.toggleAttribute('autofocus', request === true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (request && !editor.autofocus) {
|
|
37
|
+
untrack(() => editor.focus());
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
1
41
|
/** Old native callbacks and refs belong to input elements. */
|
|
2
42
|
export function isPickerInput(element) {
|
|
3
43
|
return element?.localName === 'input';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { untrack } from 'svelte';
|
|
2
|
+
import { pickerInputNeedsHelp } from './picker-editor.model.svelte';
|
|
2
3
|
import { createPickerMask, editPickerMask, pickerMaskIndexAt, pickerMaskMatches, pickerMaskSelection } from './picker-mask.engine';
|
|
3
4
|
/** Call sync() in the core's post-DOM $effect; attach() owns only its existing input. */
|
|
4
5
|
export function createPickerMaskInput(getOptions) {
|
|
@@ -37,7 +38,7 @@ export function createPickerMaskInput(getOptions) {
|
|
|
37
38
|
}
|
|
38
39
|
function change(next, options = getOptions()) {
|
|
39
40
|
// Keep the current event's prop snapshot through the synchronous core callback.
|
|
40
|
-
const modified =
|
|
41
|
+
const modified = pickerInputNeedsHelp(next, options.text, options.mask);
|
|
41
42
|
if (options.validateText(next))
|
|
42
43
|
options.acceptInput(next);
|
|
43
44
|
text = next;
|
|
@@ -243,6 +243,8 @@ export function connectPickerPopup(popup, anchor, props, options) {
|
|
|
243
243
|
...options,
|
|
244
244
|
get interactive() { return options.interactive; },
|
|
245
245
|
placement: 'bottom',
|
|
246
|
+
// rc-trigger waits for the mouse event after a touch gesture.
|
|
247
|
+
outsideEvents: 'mouse',
|
|
246
248
|
autoAdjustOverflow: true,
|
|
247
249
|
maxWidth: false,
|
|
248
250
|
anchorWidthVariable: pickerPopupAnchorWidth,
|
|
@@ -43,8 +43,11 @@ export declare function createPickerPopup(getOptions: () => PickerPopupContainer
|
|
|
43
43
|
connect: (popup: HTMLElement, root: HTMLElement, props: Parameters<typeof connectPickerPopup>[2], options: Pick<Parameters<typeof connectPickerPopup>[3], "preserveFocus" | "onDismiss" | "onVisibilityChange" | "onPlacement">) => () => void;
|
|
44
44
|
attachStyle: (node: HTMLElement) => () => void;
|
|
45
45
|
attachMotion: (node: HTMLElement) => () => void;
|
|
46
|
+
scheduleClose: (root: HTMLElement | undefined, close: () => void) => void;
|
|
47
|
+
cancelClose: () => void;
|
|
46
48
|
readonly style: string | undefined;
|
|
47
49
|
readonly target: HTMLElement | ShadowRoot | undefined;
|
|
50
|
+
readonly processingOutsideClose: boolean;
|
|
48
51
|
readonly frame: import("../popup/popup-css-motion.dom.js").PopupCssMotionState;
|
|
49
52
|
readonly present: boolean;
|
|
50
53
|
};
|