@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
|
@@ -752,26 +752,53 @@
|
|
|
752
752
|
pendingClearClose = undefined;
|
|
753
753
|
searchBeforeClose = false;
|
|
754
754
|
}
|
|
755
|
-
function change(next: string
|
|
755
|
+
function change(next: string) {
|
|
756
|
+
const before = actualValue;
|
|
756
757
|
innerValue = next;
|
|
757
758
|
if (next !== before) {
|
|
758
|
-
const option =
|
|
759
|
-
onChange?.(next,
|
|
759
|
+
const option = selectionOption(next);
|
|
760
|
+
onChange?.(next, copySelectData(option));
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function editQuery(next: string, componentInput = false) {
|
|
765
|
+
preview = undefined;
|
|
766
|
+
if (next !== text) {
|
|
767
|
+
const search = searchConfig;
|
|
768
|
+
const notifySearch = search.onSearch;
|
|
769
|
+
change(next);
|
|
770
|
+
notifySearch?.call(componentInput ? undefined : search, next);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
if (!next) {
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// rc-select resolves opening after the query callbacks. If they removed the field,
|
|
778
|
+
// the last committed listener can still receive the request.
|
|
779
|
+
if (componentDestroyed) {
|
|
780
|
+
const { visible: wasVisible, onOpenChange: notifyOpen } = committedComponentState;
|
|
781
|
+
if (!wasVisible) notifyOpen?.(true);
|
|
782
|
+
}
|
|
783
|
+
else if (componentInput) {
|
|
784
|
+
requestComponentOpen(true);
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
requestOpen(true);
|
|
760
788
|
}
|
|
761
789
|
}
|
|
790
|
+
|
|
762
791
|
function handleInput(event: Event) {
|
|
763
792
|
const control = event.currentTarget as HTMLInputElement | HTMLTextAreaElement;
|
|
764
793
|
if (blocked || readonly) {
|
|
765
794
|
return;
|
|
766
795
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
searchConfig.onSearch?.(next);
|
|
796
|
+
|
|
797
|
+
editQuery(control.value);
|
|
798
|
+
if (componentDestroyed) {
|
|
799
|
+
return;
|
|
772
800
|
}
|
|
773
|
-
|
|
774
|
-
requestOpen(true);
|
|
801
|
+
|
|
775
802
|
void tick().then(() => {
|
|
776
803
|
if (control.isConnected && value !== undefined && control.value !== text)
|
|
777
804
|
control.value = text;
|
|
@@ -810,20 +837,33 @@
|
|
|
810
837
|
const overridden = Boolean(rootSlot) || Boolean(inputSlot);
|
|
811
838
|
const before = actualValue;
|
|
812
839
|
const beforeText = text;
|
|
840
|
+
// Keep the callbacks and empty option from before a synchronous owner update.
|
|
841
|
+
const notifyChange = onChange;
|
|
842
|
+
const search = searchConfig;
|
|
843
|
+
const notifySearch = search.onSearch;
|
|
844
|
+
const emptyOption = beforeText && notifyChange ? selectionOption('') : undefined;
|
|
845
|
+
|
|
813
846
|
onClear?.();
|
|
814
|
-
if (
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
847
|
+
if (!componentDestroyed) {
|
|
848
|
+
if (overridden) {
|
|
849
|
+
focus();
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
editor?.focus({ preventScroll: true });
|
|
853
|
+
}
|
|
819
854
|
}
|
|
820
|
-
|
|
855
|
+
|
|
856
|
+
if (!componentDestroyed) innerValue = undefined;
|
|
857
|
+
if (before !== undefined) notifyChange?.(undefined, undefined);
|
|
858
|
+
|
|
821
859
|
// Rc-select uses a separate search path after clearing the display values.
|
|
822
860
|
if (beforeText) {
|
|
823
|
-
|
|
824
|
-
|
|
861
|
+
if (!componentDestroyed) innerValue = '';
|
|
862
|
+
if (before !== '') notifyChange?.('', copySelectData(emptyOption));
|
|
863
|
+
notifySearch?.call(search, '');
|
|
825
864
|
}
|
|
826
|
-
|
|
865
|
+
|
|
866
|
+
if (!componentDestroyed) preview = undefined;
|
|
827
867
|
}
|
|
828
868
|
function handleKeydown(event: KeyboardEvent) {
|
|
829
869
|
const alreadyPrevented = event.defaultPrevented;
|
|
@@ -884,13 +924,21 @@
|
|
|
884
924
|
}
|
|
885
925
|
}
|
|
886
926
|
function handleBlur(event: FocusEvent) {
|
|
927
|
+
// Removal can dispatch native blur after Svelte pauses the rendered branch.
|
|
928
|
+
const state = committedComponentState;
|
|
887
929
|
focused = false;
|
|
888
930
|
enterLock = false;
|
|
889
931
|
preview = undefined;
|
|
890
|
-
|
|
891
|
-
|
|
932
|
+
const target = event.relatedTarget;
|
|
933
|
+
if (!state.customPopup || !(target instanceof Node && state.popup?.contains(target))) {
|
|
934
|
+
cancelClearClose();
|
|
935
|
+
const notifyOpen = state.onOpenChange;
|
|
936
|
+
if (state.visible) notifyOpen?.(false);
|
|
937
|
+
innerOpen = false;
|
|
938
|
+
}
|
|
892
939
|
field?.onBlur();
|
|
893
|
-
onBlur
|
|
940
|
+
const notifyBlur = state.onBlur;
|
|
941
|
+
notifyBlur?.(event);
|
|
894
942
|
}
|
|
895
943
|
function handlePopupFocusOut(event: FocusEvent & { currentTarget: HTMLDivElement }) {
|
|
896
944
|
if (!customPopup || !event.currentTarget.isConnected) {
|
|
@@ -1185,14 +1233,12 @@
|
|
|
1185
1233
|
let componentInputChangeToken = 0;
|
|
1186
1234
|
function componentInputChange(event: Event) {
|
|
1187
1235
|
const node = event.currentTarget as HTMLInputElement | HTMLTextAreaElement;
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
change(next);
|
|
1193
|
-
searchCallback?.(next);
|
|
1236
|
+
|
|
1237
|
+
editQuery(node.value, true);
|
|
1238
|
+
if (componentDestroyed) {
|
|
1239
|
+
return;
|
|
1194
1240
|
}
|
|
1195
|
-
|
|
1241
|
+
|
|
1196
1242
|
const token = ++componentInputChangeToken, registration = componentInputRegistrationToken;
|
|
1197
1243
|
void tick().then(() => {
|
|
1198
1244
|
if (!node.isConnected || token !== componentInputChangeToken || registration !== componentInputRegistrationToken) {
|
|
@@ -1276,7 +1322,7 @@
|
|
|
1276
1322
|
let rootContext = $derived.by(componentRootContext);
|
|
1277
1323
|
let componentEditorContext = $derived.by(componentInputContext);
|
|
1278
1324
|
function readComponentState() {
|
|
1279
|
-
return { visible, blocked, readonly, openOnFocus, active, rows: optionList.items, popup,
|
|
1325
|
+
return { visible, blocked, readonly, openOnFocus, active, rows: optionList.items, popup, customPopup,
|
|
1280
1326
|
onFocus, onBlur, onKeyDown, onKeyUp, onClick, onMouseDown, onOpenChange };
|
|
1281
1327
|
}
|
|
1282
1328
|
let committedComponentState = untrack(readComponentState);
|
|
@@ -329,6 +329,12 @@
|
|
|
329
329
|
let committedInputValue: string | undefined;
|
|
330
330
|
let disposed = false;
|
|
331
331
|
let closeTimer: ReturnType<typeof setTimeout> | undefined;
|
|
332
|
+
function readControlState() {
|
|
333
|
+
return { visible, blocked, multiple: isMultiple, onChange, onOpenChange, onBlur, onblur };
|
|
334
|
+
}
|
|
335
|
+
let committedControl: ReturnType<typeof readControlState> | undefined;
|
|
336
|
+
$effect(() => { committedControl = readControlState(); });
|
|
337
|
+
|
|
332
338
|
onDestroy(() => {
|
|
333
339
|
disposed = true;
|
|
334
340
|
cancelScheduledClose();
|
|
@@ -715,15 +721,22 @@
|
|
|
715
721
|
function publish(next: CascaderInternalPath[]) {
|
|
716
722
|
internalValue = next;
|
|
717
723
|
const selected = next.map(path => cascaderPathOptions(path, options, fields));
|
|
718
|
-
|
|
719
|
-
|
|
724
|
+
notifyPaths(next, selected, isMultiple, onChange);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
type Change = NonNullable<CascaderProps<OptionType, Multiple, ValueField>['onChange']>;
|
|
728
|
+
function notifyPaths(
|
|
729
|
+
paths: CascaderInternalPath[],
|
|
730
|
+
selected: (OptionType | undefined)[][],
|
|
731
|
+
multiple: boolean,
|
|
732
|
+
callback: Change | undefined
|
|
733
|
+
) {
|
|
734
|
+
const value = multiple ? paths : paths[0];
|
|
735
|
+
const options = multiple ? selected : selected[0];
|
|
720
736
|
type ChangeArguments = Parameters<Change>;
|
|
721
737
|
|
|
722
|
-
// The configured field supplies the path segments
|
|
723
|
-
|
|
724
|
-
result as ChangeArguments[0],
|
|
725
|
-
(isMultiple ? selected : selected[0]) as ChangeArguments[1]
|
|
726
|
-
);
|
|
738
|
+
// The configured field supplies the path segments. The mode selects the callback shape.
|
|
739
|
+
callback?.(value as ChangeArguments[0], options as ChangeArguments[1]);
|
|
727
740
|
}
|
|
728
741
|
function choose(path: CascaderInternalPath) {
|
|
729
742
|
if (blocked) {
|
|
@@ -780,32 +793,34 @@
|
|
|
780
793
|
const suffix = index.collidingValues.has(row.pathValue) ? `:${encodeURIComponent(row.key)}` : '';
|
|
781
794
|
return `${listId}-${value}${suffix}`;
|
|
782
795
|
}
|
|
783
|
-
function
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
796
|
+
function readSearchState() {
|
|
797
|
+
const separators = tokenSeparators;
|
|
798
|
+
const capacity = separators !== undefined && maxCount !== undefined && !Number.isNaN(maxCount)
|
|
799
|
+
? maxCount - displayPaths.length : undefined;
|
|
800
|
+
return { query: search, config: searchConfig, separators, capacity };
|
|
787
801
|
}
|
|
802
|
+
type SearchState = ReturnType<typeof readSearchState>;
|
|
788
803
|
|
|
789
|
-
function
|
|
790
|
-
if (
|
|
791
|
-
|
|
792
|
-
|
|
804
|
+
function changeSearch(next: string, state: SearchState) {
|
|
805
|
+
if (!disposed) internalSearch = next;
|
|
806
|
+
if (state.query !== next) state.config.onSearch?.(next);
|
|
807
|
+
}
|
|
793
808
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
return parts !== null;
|
|
809
|
+
function splitsSearch(text: string, state: SearchState) {
|
|
810
|
+
return state.separators !== undefined
|
|
811
|
+
&& splitSelectTokens(text, state.separators, state.capacity) !== null;
|
|
798
812
|
}
|
|
799
813
|
|
|
800
814
|
/** Single selection runs a search pass on the empty text when the raw popup closes. */
|
|
801
815
|
function resetClosedSearch() {
|
|
802
|
-
const
|
|
816
|
+
const state = readSearchState();
|
|
817
|
+
const split = splitsSearch('', state);
|
|
803
818
|
if (disposed) {
|
|
804
819
|
return;
|
|
805
820
|
}
|
|
806
821
|
|
|
807
822
|
if (split) scheduleClose();
|
|
808
|
-
changeSearch('');
|
|
823
|
+
changeSearch('', state);
|
|
809
824
|
}
|
|
810
825
|
|
|
811
826
|
const composingEditors = new WeakSet<HTMLElement>();
|
|
@@ -841,18 +856,16 @@
|
|
|
841
856
|
return;
|
|
842
857
|
}
|
|
843
858
|
|
|
859
|
+
const state = readSearchState();
|
|
844
860
|
const composing = composingEditors.has(input) || event instanceof InputEvent && event.isComposing;
|
|
845
|
-
const split = !composing && splitsSearch(next);
|
|
846
|
-
if (disposed) {
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
861
|
+
const split = !composing && splitsSearch(next, state);
|
|
849
862
|
if (split) {
|
|
850
863
|
scheduleClose();
|
|
851
|
-
changeSearch('');
|
|
864
|
+
changeSearch('', state);
|
|
852
865
|
return;
|
|
853
866
|
}
|
|
854
867
|
|
|
855
|
-
changeSearch(next);
|
|
868
|
+
changeSearch(next, state);
|
|
856
869
|
if (next && !disposed) requestOpen(true);
|
|
857
870
|
}
|
|
858
871
|
|
|
@@ -861,9 +874,14 @@
|
|
|
861
874
|
return;
|
|
862
875
|
}
|
|
863
876
|
|
|
864
|
-
|
|
877
|
+
const input = event.currentTarget;
|
|
878
|
+
searchFromEditor(input, event);
|
|
879
|
+
if (disposed) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
|
|
865
883
|
void tick().then(() => {
|
|
866
|
-
if (defaultEditor)
|
|
884
|
+
if (!disposed && defaultEditor === input && input.isConnected) input.value = inputValue;
|
|
867
885
|
});
|
|
868
886
|
}
|
|
869
887
|
|
|
@@ -910,6 +928,10 @@
|
|
|
910
928
|
}
|
|
911
929
|
const current = registration;
|
|
912
930
|
searchFromEditor(input, event);
|
|
931
|
+
if (disposed) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
|
|
913
935
|
void tick().then(() => {
|
|
914
936
|
if (disposed || registration !== current || !input.isConnected) {
|
|
915
937
|
return;
|
|
@@ -959,9 +981,13 @@
|
|
|
959
981
|
onfocus?.(event);
|
|
960
982
|
}
|
|
961
983
|
function blurEditor(event: EditorFocusEvent) {
|
|
984
|
+
const state = committedControl;
|
|
962
985
|
enterHeld = false;
|
|
963
|
-
if (
|
|
964
|
-
if (!blocked)
|
|
986
|
+
if (state?.multiple) internalSearch = '';
|
|
987
|
+
if (state && !state.blocked) {
|
|
988
|
+
const callback = state.onblur;
|
|
989
|
+
callback?.(event);
|
|
990
|
+
}
|
|
965
991
|
}
|
|
966
992
|
/** Merges the caller's editor props with attributes for the live Cascader menu. */
|
|
967
993
|
function createInputContext() {
|
|
@@ -998,12 +1024,45 @@
|
|
|
998
1024
|
if (blocked) {
|
|
999
1025
|
return;
|
|
1000
1026
|
}
|
|
1027
|
+
|
|
1028
|
+
const searchState = readSearchState();
|
|
1029
|
+
const splitAllowed = !searchLimitReached;
|
|
1030
|
+
const closeAfterClear = !isMultiple;
|
|
1001
1031
|
onClear?.();
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1032
|
+
|
|
1033
|
+
if (!disposed) focus();
|
|
1034
|
+
publishClear();
|
|
1035
|
+
|
|
1036
|
+
if (splitAllowed && splitsSearch('', searchState)) scheduleClose();
|
|
1037
|
+
changeSearch('', searchState);
|
|
1038
|
+
if (closeAfterClear) finishClearClose();
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
function publishClear() {
|
|
1042
|
+
// rc-cascader uses the current change handler and mode after onClear and focus.
|
|
1043
|
+
if (!disposed) {
|
|
1044
|
+
publish([]);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
const state = committedControl;
|
|
1049
|
+
if (state) notifyPaths([], [], state.multiple, state.onChange);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function finishClearClose() {
|
|
1053
|
+
if (!disposed) {
|
|
1054
|
+
requestOpen(false);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// Single clear can finish closing the committed popup after the owner removes it.
|
|
1059
|
+
const state = committedControl;
|
|
1060
|
+
if (state?.visible) {
|
|
1061
|
+
const callback = state.onOpenChange;
|
|
1062
|
+
callback?.(false);
|
|
1063
|
+
}
|
|
1006
1064
|
}
|
|
1065
|
+
|
|
1007
1066
|
function removeTag(path: CascaderInternalPath) {
|
|
1008
1067
|
choose(path);
|
|
1009
1068
|
}
|
|
@@ -1120,15 +1179,15 @@
|
|
|
1120
1179
|
}
|
|
1121
1180
|
|
|
1122
1181
|
/** Focus in an owned popup belongs to the popup even with a local container. */
|
|
1123
|
-
function isTriggerFocusEvent(event: Event): event is FocusEvent {
|
|
1124
|
-
if (disposed ||
|
|
1182
|
+
function isTriggerFocusEvent(event: Event, disabled: boolean | undefined): event is FocusEvent {
|
|
1183
|
+
if (disposed || disabled || !root?.isConnected || !(event instanceof FocusEvent)) {
|
|
1125
1184
|
return false;
|
|
1126
1185
|
}
|
|
1127
1186
|
return !isPopupEvent(event);
|
|
1128
1187
|
}
|
|
1129
1188
|
/** Handles focus on authored triggers and selector controls outside the editor. */
|
|
1130
1189
|
function triggerFocus(event: Event) {
|
|
1131
|
-
if (!isTriggerFocusEvent(event)) {
|
|
1190
|
+
if (disposed || !isTriggerFocusEvent(event, blocked)) {
|
|
1132
1191
|
return;
|
|
1133
1192
|
}
|
|
1134
1193
|
if (showAction.includes('focus') && (!editor || !event.composedPath().includes(editor))) {
|
|
@@ -1138,7 +1197,12 @@
|
|
|
1138
1197
|
}
|
|
1139
1198
|
/** Reports the trigger's blur before any deferred popup dismissal. */
|
|
1140
1199
|
function triggerBlur(event: Event) {
|
|
1141
|
-
|
|
1200
|
+
// The focused editor can blur after Svelte has paused its reactive branch.
|
|
1201
|
+
const state = committedControl;
|
|
1202
|
+
if (state && isTriggerFocusEvent(event, state.blocked)) {
|
|
1203
|
+
const callback = state.onBlur;
|
|
1204
|
+
callback?.(event);
|
|
1205
|
+
}
|
|
1142
1206
|
}
|
|
1143
1207
|
function blurWithin(event: FocusEvent) {
|
|
1144
1208
|
const element = root;
|
|
@@ -1163,7 +1227,7 @@
|
|
|
1163
1227
|
enterHeld = false;
|
|
1164
1228
|
field?.onBlur();
|
|
1165
1229
|
requestOpen(false);
|
|
1166
|
-
if (isMultiple)
|
|
1230
|
+
if (isMultiple) internalSearch = '';
|
|
1167
1231
|
});
|
|
1168
1232
|
}
|
|
1169
1233
|
let enterHeld = false;
|
|
@@ -1219,7 +1283,7 @@
|
|
|
1219
1283
|
event: KeyboardEvent,
|
|
1220
1284
|
replacement?: { textarea: boolean; cancelled: boolean; }
|
|
1221
1285
|
) {
|
|
1222
|
-
if (blocked || event.isComposing || (replacement?.cancelled ?? event.defaultPrevented)) {
|
|
1286
|
+
if (disposed || blocked || event.isComposing || (replacement?.cancelled ?? event.defaultPrevented)) {
|
|
1223
1287
|
return;
|
|
1224
1288
|
}
|
|
1225
1289
|
const key = event.key;
|
|
@@ -1267,12 +1331,12 @@
|
|
|
1267
1331
|
if (next.close) requestOpen(false);
|
|
1268
1332
|
}
|
|
1269
1333
|
}
|
|
1270
|
-
else if (!visible && canSearch &&
|
|
1334
|
+
else if (!visible && canSearch && event.currentTarget === defaultEditor
|
|
1271
1335
|
&& opensFromEditorKey(event, false)) {
|
|
1272
|
-
// The key
|
|
1336
|
+
// The key opens the columns before the text input, including with a full selection.
|
|
1273
1337
|
requestOpen(true);
|
|
1274
1338
|
}
|
|
1275
|
-
onkeydown?.(event);
|
|
1339
|
+
if (!disposed) onkeydown?.(event);
|
|
1276
1340
|
}
|
|
1277
1341
|
function handleKeyUp(event: KeyboardEvent) {
|
|
1278
1342
|
if (event.key === 'Enter') enterHeld = false;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Emits changes from the multiline editor, clearing, and FormItem. Focus and ref belong to one
|
|
3
3
|
// textarea.
|
|
4
4
|
import { onDestroy, tick, untrack } from 'svelte';
|
|
5
|
+
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
5
6
|
import { useConfig } from '../config-provider/config-context';
|
|
6
7
|
import { useVariant } from '../config-provider/variant.svelte';
|
|
7
8
|
import { useComponentTheme } from '../theme/theme-component.svelte';
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
textAreaResizeStyle
|
|
19
20
|
} from './textarea.engine';
|
|
20
21
|
import { createTextAreaMeasure, textAreaChangeEvent } from './textarea.dom';
|
|
22
|
+
import { createNativeTextareaValue } from './textarea-value.svelte';
|
|
21
23
|
import { createInputValue } from './input-value.svelte';
|
|
22
24
|
import { getInputPrefixCss } from './input-prefix.engine';
|
|
23
25
|
import { inlineStyleText } from '../style/inline-style-layers.engine';
|
|
@@ -105,9 +107,6 @@
|
|
|
105
107
|
let measure: ReturnType<typeof createTextAreaMeasure> | undefined;
|
|
106
108
|
let removeMouseUp: (() => void) | undefined;
|
|
107
109
|
let text = $derived(String(fieldValue.current ?? (useDefault ? initialDefault : '') ?? ''));
|
|
108
|
-
let explicitResetValue = $derived(attributes.defaultvalue);
|
|
109
|
-
// The native default must populate the editor before its first live value assignment.
|
|
110
|
-
let resetValue = $derived(explicitResetValue === undefined ? text : explicitResetValue);
|
|
111
110
|
let resolvedSize = $derived(size ?? compact?.size ?? config.componentSize);
|
|
112
111
|
let resolvedStatus = $derived(status ?? ('status' in itemStatus ? itemStatus.status : field?.status));
|
|
113
112
|
|
|
@@ -215,6 +214,57 @@
|
|
|
215
214
|
dirty && `${componentPrefix}-textarea-affix-wrapper-resize-dirty`
|
|
216
215
|
]
|
|
217
216
|
);
|
|
217
|
+
const editorAttributes = $derived.by(() => {
|
|
218
|
+
const { defaultvalue: _nativeDefault, ...nativeAttributes } = attributes;
|
|
219
|
+
return {
|
|
220
|
+
...nativeAttributes,
|
|
221
|
+
id: id ?? field?.id,
|
|
222
|
+
name: name ?? field?.name,
|
|
223
|
+
'data-ant-input-node': true,
|
|
224
|
+
'data-ant-input-prefix': hasCustomPrefix ? componentPrefix : undefined,
|
|
225
|
+
'data-ant-input-mouse-active': mouseDown || undefined,
|
|
226
|
+
required: attributes.required ?? field?.required,
|
|
227
|
+
disabled: blocked,
|
|
228
|
+
readonly: read,
|
|
229
|
+
maxlength: maximum,
|
|
230
|
+
hidden: wrapped ? undefined : hidden,
|
|
231
|
+
autocomplete: attributes.autocomplete ?? autoComplete ?? config.textArea?.autoComplete,
|
|
232
|
+
...(attributes.autofocus !== undefined || autoFocus !== undefined
|
|
233
|
+
? { autofocus: attributes.autofocus ?? autoFocus } : {}),
|
|
234
|
+
dir: attributes.dir ?? config.direction,
|
|
235
|
+
'aria-invalid': field?.invalid || resolvedStatus === 'error'
|
|
236
|
+
|| attributes['aria-invalid'] || undefined,
|
|
237
|
+
'aria-describedby': [attributes['aria-describedby'], field?.describedBy].filter(Boolean)
|
|
238
|
+
.join(' ') || undefined,
|
|
239
|
+
oninput: handleInput,
|
|
240
|
+
onkeydown: handleKeyDown,
|
|
241
|
+
onfocus: handleFocus,
|
|
242
|
+
onblur: handleBlur,
|
|
243
|
+
onmousedown: handleMouseDown,
|
|
244
|
+
oncompositionstart: handleCompositionStart,
|
|
245
|
+
oncompositionend: handleCompositionEnd,
|
|
246
|
+
style: leafStyle,
|
|
247
|
+
class: [
|
|
248
|
+
componentPrefix,
|
|
249
|
+
blocked && `${componentPrefix}-disabled`,
|
|
250
|
+
resolvedSize === 'large' && `${componentPrefix}-lg`,
|
|
251
|
+
resolvedSize === 'small' && `${componentPrefix}-sm`,
|
|
252
|
+
mouseDown && `${componentPrefix}-mouse-active`,
|
|
253
|
+
contextClasses?.textarea,
|
|
254
|
+
localClasses?.textarea,
|
|
255
|
+
!wrapped && variantClasses,
|
|
256
|
+
!wrapped && rootClasses
|
|
257
|
+
]
|
|
258
|
+
} satisfies HTMLTextareaAttributes;
|
|
259
|
+
});
|
|
260
|
+
const nativeEditorValue = createNativeTextareaValue(
|
|
261
|
+
() => text,
|
|
262
|
+
() => attributes.defaultvalue,
|
|
263
|
+
() => {
|
|
264
|
+
void focused;
|
|
265
|
+
void editorAttributes;
|
|
266
|
+
}
|
|
267
|
+
);
|
|
218
268
|
|
|
219
269
|
$effect(() => {
|
|
220
270
|
rootElement = wrapper ?? nativeElement;
|
|
@@ -292,6 +342,35 @@
|
|
|
292
342
|
publish(event, event.currentTarget.value, true);
|
|
293
343
|
oninput?.(event);
|
|
294
344
|
}
|
|
345
|
+
function handleKeyDown(event: KeyboardEvent & { currentTarget: HTMLTextAreaElement; }) {
|
|
346
|
+
if (event.key === 'Enter' && !event.isComposing) {
|
|
347
|
+
onPressEnter?.(event);
|
|
348
|
+
}
|
|
349
|
+
onKeyDown?.(event);
|
|
350
|
+
onkeydown?.(event);
|
|
351
|
+
}
|
|
352
|
+
function handleFocus(event: FocusEvent & { currentTarget: HTMLTextAreaElement; }) {
|
|
353
|
+
focused = true;
|
|
354
|
+
onFocus?.(event);
|
|
355
|
+
onfocus?.(event);
|
|
356
|
+
}
|
|
357
|
+
function handleBlur(event: FocusEvent & { currentTarget: HTMLTextAreaElement; }) {
|
|
358
|
+
focused = false;
|
|
359
|
+
field?.onBlur();
|
|
360
|
+
onBlur?.(event);
|
|
361
|
+
onblur?.(event);
|
|
362
|
+
}
|
|
363
|
+
function handleCompositionStart(event: CompositionEvent & { currentTarget: HTMLTextAreaElement; }) {
|
|
364
|
+
composing = true;
|
|
365
|
+
onCompositionStart?.(event);
|
|
366
|
+
oncompositionstart?.(event);
|
|
367
|
+
}
|
|
368
|
+
function handleCompositionEnd(event: CompositionEvent & { currentTarget: HTMLTextAreaElement; }) {
|
|
369
|
+
composing = false;
|
|
370
|
+
publish(event, event.currentTarget.value);
|
|
371
|
+
onCompositionEnd?.(event);
|
|
372
|
+
oncompositionend?.(event);
|
|
373
|
+
}
|
|
295
374
|
function handleClear(event: MouseEvent) {
|
|
296
375
|
const element = nativeElement;
|
|
297
376
|
if (!element) {
|
|
@@ -342,66 +421,21 @@
|
|
|
342
421
|
</style>
|
|
343
422
|
|
|
344
423
|
{#snippet control()}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Boolean
|
|
361
|
-
)
|
|
362
|
-
.join(
|
|
363
|
-
' '
|
|
364
|
-
)
|
|
365
|
-
|| undefined}
|
|
366
|
-
oninput={handleInput} onkeydown={event => {
|
|
367
|
-
if (event.key === 'Enter' && !event.isComposing)
|
|
368
|
-
onPressEnter?.(event);
|
|
369
|
-
onKeyDown?.(event);
|
|
370
|
-
onkeydown?.(event);
|
|
371
|
-
}}
|
|
372
|
-
onfocus={event => {
|
|
373
|
-
focused = true;
|
|
374
|
-
onFocus?.(event);
|
|
375
|
-
onfocus?.(event);
|
|
376
|
-
}}
|
|
377
|
-
onblur={event => {
|
|
378
|
-
focused = false;
|
|
379
|
-
field?.onBlur();
|
|
380
|
-
onBlur?.(event);
|
|
381
|
-
onblur?.(event);
|
|
382
|
-
}} onmousedown={handleMouseDown}
|
|
383
|
-
oncompositionstart={event => {
|
|
384
|
-
composing = true;
|
|
385
|
-
onCompositionStart?.(event);
|
|
386
|
-
oncompositionstart?.(event);
|
|
387
|
-
}}
|
|
388
|
-
oncompositionend={event => {
|
|
389
|
-
composing = false;
|
|
390
|
-
publish(event, event.currentTarget.value);
|
|
391
|
-
onCompositionEnd?.(event);
|
|
392
|
-
oncompositionend?.(event);
|
|
393
|
-
}}
|
|
394
|
-
style={leafStyle} class={[
|
|
395
|
-
componentPrefix,
|
|
396
|
-
blocked && `${componentPrefix}-disabled`,
|
|
397
|
-
resolvedSize === 'large' && `${componentPrefix}-lg`,
|
|
398
|
-
resolvedSize === 'small' && `${componentPrefix}-sm`,
|
|
399
|
-
mouseDown && `${componentPrefix}-mouse-active`,
|
|
400
|
-
contextClasses?.textarea,
|
|
401
|
-
localClasses?.textarea,
|
|
402
|
-
!wrapped && variantClasses,
|
|
403
|
-
!wrapped && rootClasses
|
|
404
|
-
]}></textarea>
|
|
424
|
+
{@const initial = untrack(nativeEditorValue.prepare)}
|
|
425
|
+
{#if initial.value === ''}
|
|
426
|
+
<!-- A hydration marker inside an empty textarea changes its selection direction. -->
|
|
427
|
+
<textarea {...editorAttributes} bind:this={nativeElement}
|
|
428
|
+
{@attach nativeEditorValue.connect}></textarea>
|
|
429
|
+
{:else}
|
|
430
|
+
<!-- A literal textarea loses its SSR text before Svelte initializes its value. -->
|
|
431
|
+
<svelte:element
|
|
432
|
+
this={'textarea'}
|
|
433
|
+
{...editorAttributes}
|
|
434
|
+
{...initial.valueAttributes}
|
|
435
|
+
bind:this={nativeElement}
|
|
436
|
+
{@attach nativeEditorValue.connect}
|
|
437
|
+
>{initial.body}</svelte:element>
|
|
438
|
+
{/if}
|
|
405
439
|
{/snippet}
|
|
406
440
|
|
|
407
441
|
{#if prefixCss}<ThemeScopeStyle css={prefixCss} scope={`input-prefix:${componentPrefix}`} />{/if}{#if wrapped}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HTMLTextareaAttributes } from 'svelte/elements';
|
|
2
|
+
/** Creates a native value connection for a textarea whose owner manages the model. */
|
|
3
|
+
export declare function createNativeTextareaValue(readValue: () => string, readDefault: () => HTMLTextareaAttributes['defaultvalue'], trackDraftUpdates: () => void): {
|
|
4
|
+
prepare: () => {
|
|
5
|
+
value: string;
|
|
6
|
+
body: string;
|
|
7
|
+
valueAttributes: {
|
|
8
|
+
value?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
connect: (element: HTMLTextAreaElement) => void;
|
|
14
|
+
};
|