@diceui/tags-input 0.7.2 → 0.7.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/index.cjs +606 -719
- package/dist/index.d.cts +120 -118
- package/dist/index.d.mts +137 -0
- package/dist/index.mjs +592 -0
- package/package.json +18 -13
- package/dist/index.d.ts +0 -135
- package/dist/index.js +0 -707
package/dist/index.cjs
CHANGED
|
@@ -1,731 +1,618 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
setHighlightedIndex,
|
|
313
|
-
editingIndex,
|
|
314
|
-
setEditingIndex,
|
|
315
|
-
displayValue,
|
|
316
|
-
onItemLeave,
|
|
317
|
-
inputRef,
|
|
318
|
-
isInvalidInput,
|
|
319
|
-
addOnPaste,
|
|
320
|
-
addOnTab,
|
|
321
|
-
disabled,
|
|
322
|
-
editable,
|
|
323
|
-
loop,
|
|
324
|
-
readOnly,
|
|
325
|
-
blurBehavior,
|
|
326
|
-
delimiter,
|
|
327
|
-
max,
|
|
328
|
-
dir,
|
|
329
|
-
id,
|
|
330
|
-
inputId,
|
|
331
|
-
labelId
|
|
332
|
-
},
|
|
333
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
334
|
-
shared.Primitive.div,
|
|
335
|
-
{
|
|
336
|
-
id,
|
|
337
|
-
"data-disabled": disabled ? "" : void 0,
|
|
338
|
-
"data-invalid": isInvalidInput ? "" : void 0,
|
|
339
|
-
"data-readonly": readOnly ? "" : void 0,
|
|
340
|
-
dir,
|
|
341
|
-
...rootProps,
|
|
342
|
-
ref: composedRef,
|
|
343
|
-
onClick: shared.composeEventHandlers(rootProps.onClick, (event) => {
|
|
344
|
-
const target = event.target;
|
|
345
|
-
if (!(target instanceof HTMLElement)) return;
|
|
346
|
-
if (getIsClickedInEmptyRoot(target) && document.activeElement !== inputRef.current) {
|
|
347
|
-
event.currentTarget.focus();
|
|
348
|
-
inputRef.current?.focus();
|
|
349
|
-
}
|
|
350
|
-
}),
|
|
351
|
-
onMouseDown: shared.composeEventHandlers(rootProps.onMouseDown, (event) => {
|
|
352
|
-
const target = event.target;
|
|
353
|
-
if (!(target instanceof HTMLElement)) return;
|
|
354
|
-
if (getIsClickedInEmptyRoot(target)) {
|
|
355
|
-
event.preventDefault();
|
|
356
|
-
}
|
|
357
|
-
}),
|
|
358
|
-
onBlur: shared.composeEventHandlers(rootProps.onBlur, (event) => {
|
|
359
|
-
if (event.relatedTarget !== inputRef.current && !collectionRef.current?.contains(event.relatedTarget)) {
|
|
360
|
-
requestAnimationFrame(() => setHighlightedIndex(null));
|
|
361
|
-
}
|
|
362
|
-
})
|
|
363
|
-
},
|
|
364
|
-
typeof children === "function" ? /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, children({ value })) : children,
|
|
365
|
-
isFormControl && name && /* @__PURE__ */ React__namespace.createElement(
|
|
366
|
-
shared.VisuallyHiddenInput,
|
|
367
|
-
{
|
|
368
|
-
type: "hidden",
|
|
369
|
-
control: collectionRef.current,
|
|
370
|
-
name,
|
|
371
|
-
value,
|
|
372
|
-
disabled,
|
|
373
|
-
required
|
|
374
|
-
}
|
|
375
|
-
)
|
|
376
|
-
)
|
|
377
|
-
);
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
var __create = Object.create;
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
//#endregion
|
|
26
|
+
let _diceui_shared = require("@diceui/shared");
|
|
27
|
+
let react = require("react");
|
|
28
|
+
react = __toESM(react, 1);
|
|
29
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
//#region src/tags-input-root.tsx
|
|
31
|
+
const ROOT_NAME = "TagsInputRoot";
|
|
32
|
+
const [TagsInputProvider, useTagsInput] = (0, _diceui_shared.createContext)(ROOT_NAME);
|
|
33
|
+
const TagsInputRoot = react.forwardRef((props, ref) => {
|
|
34
|
+
const { value: valueProp, defaultValue, onValueChange, onValidate, onInvalid, displayValue = (value) => value, addOnPaste = false, addOnTab = false, disabled = false, editable = false, loop = false, blurBehavior, delimiter = ",", max = Number.POSITIVE_INFINITY, readOnly = false, required = false, name, children, dir: dirProp, id: idProp, ...rootProps } = props;
|
|
35
|
+
const [value = [], setValue] = (0, _diceui_shared.useControllableState)({
|
|
36
|
+
prop: valueProp,
|
|
37
|
+
defaultProp: defaultValue,
|
|
38
|
+
onChange: onValueChange
|
|
39
|
+
});
|
|
40
|
+
const [highlightedIndex, setHighlightedIndex] = react.useState(null);
|
|
41
|
+
const [editingIndex, setEditingIndex] = react.useState(null);
|
|
42
|
+
const [isInvalidInput, setIsInvalidInput] = react.useState(false);
|
|
43
|
+
const collectionRef = react.useRef(null);
|
|
44
|
+
const inputRef = react.useRef(null);
|
|
45
|
+
const id = (0, _diceui_shared.useId)(idProp);
|
|
46
|
+
const inputId = (0, _diceui_shared.useId)();
|
|
47
|
+
const labelId = (0, _diceui_shared.useId)();
|
|
48
|
+
const dir = (0, _diceui_shared.useDirection)(dirProp);
|
|
49
|
+
const { getEnabledItems } = (0, _diceui_shared.useItemCollection)({ ref: collectionRef });
|
|
50
|
+
const { isFormControl, onTriggerChange } = (0, _diceui_shared.useFormControl)();
|
|
51
|
+
const composedRef = (0, _diceui_shared.useComposedRefs)(ref, collectionRef, (node) => onTriggerChange(node));
|
|
52
|
+
const onItemAdd = react.useCallback((textValue, options) => {
|
|
53
|
+
if (disabled || readOnly) return false;
|
|
54
|
+
if (addOnPaste && options?.viaPaste) {
|
|
55
|
+
const splitValues = textValue.split(delimiter).map((v) => v.trim()).filter(Boolean);
|
|
56
|
+
if (value.length + splitValues.length > max && max > 0) {
|
|
57
|
+
onInvalid?.(textValue);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
let newValues = [];
|
|
61
|
+
for (const v of splitValues) if (value.includes(v)) onInvalid?.(v);
|
|
62
|
+
newValues = [...new Set(splitValues.filter((v) => !value.includes(v)))];
|
|
63
|
+
const validValues = newValues.filter((v) => !onValidate || onValidate(v));
|
|
64
|
+
if (validValues.length === 0) return false;
|
|
65
|
+
setValue([...value, ...validValues]);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (value.length >= max && max > 0) {
|
|
69
|
+
onInvalid?.(textValue);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const trimmedValue = textValue.trim();
|
|
73
|
+
if (onValidate && !onValidate(trimmedValue)) {
|
|
74
|
+
setIsInvalidInput(true);
|
|
75
|
+
onInvalid?.(trimmedValue);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (value.some((v) => {
|
|
79
|
+
return v === trimmedValue;
|
|
80
|
+
})) {
|
|
81
|
+
setIsInvalidInput(true);
|
|
82
|
+
onInvalid?.(trimmedValue);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const newValue = trimmedValue;
|
|
86
|
+
const newValues = [...value, newValue];
|
|
87
|
+
setValue(newValues);
|
|
88
|
+
setHighlightedIndex(null);
|
|
89
|
+
setEditingIndex(null);
|
|
90
|
+
setIsInvalidInput(false);
|
|
91
|
+
return true;
|
|
92
|
+
}, [
|
|
93
|
+
value,
|
|
94
|
+
max,
|
|
95
|
+
addOnPaste,
|
|
96
|
+
delimiter,
|
|
97
|
+
setValue,
|
|
98
|
+
onInvalid,
|
|
99
|
+
onValidate,
|
|
100
|
+
disabled,
|
|
101
|
+
readOnly
|
|
102
|
+
]);
|
|
103
|
+
const onItemUpdate = react.useCallback((index, newTextValue) => {
|
|
104
|
+
if (disabled || readOnly) return;
|
|
105
|
+
if (index !== -1) {
|
|
106
|
+
const trimmedValue = newTextValue.trim();
|
|
107
|
+
if (value.some((v, i) => {
|
|
108
|
+
if (i === index) return false;
|
|
109
|
+
return v === trimmedValue;
|
|
110
|
+
})) {
|
|
111
|
+
setIsInvalidInput(true);
|
|
112
|
+
onInvalid?.(trimmedValue);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (onValidate && !onValidate(trimmedValue)) {
|
|
116
|
+
setIsInvalidInput(true);
|
|
117
|
+
onInvalid?.(trimmedValue);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const updatedValue = displayValue(trimmedValue);
|
|
121
|
+
const newValues = [...value];
|
|
122
|
+
newValues[index] = updatedValue;
|
|
123
|
+
setValue(newValues);
|
|
124
|
+
setHighlightedIndex(index);
|
|
125
|
+
setEditingIndex(null);
|
|
126
|
+
setIsInvalidInput(false);
|
|
127
|
+
requestAnimationFrame(() => inputRef.current?.focus());
|
|
128
|
+
}
|
|
129
|
+
}, [
|
|
130
|
+
value,
|
|
131
|
+
setValue,
|
|
132
|
+
displayValue,
|
|
133
|
+
onInvalid,
|
|
134
|
+
onValidate,
|
|
135
|
+
disabled,
|
|
136
|
+
readOnly
|
|
137
|
+
]);
|
|
138
|
+
const onItemRemove = react.useCallback((index) => {
|
|
139
|
+
if (disabled || readOnly) return;
|
|
140
|
+
if (index !== -1) {
|
|
141
|
+
const newValues = [...value];
|
|
142
|
+
newValues.splice(index, 1);
|
|
143
|
+
setValue(newValues);
|
|
144
|
+
setHighlightedIndex(null);
|
|
145
|
+
setEditingIndex(null);
|
|
146
|
+
inputRef.current?.focus();
|
|
147
|
+
}
|
|
148
|
+
}, [
|
|
149
|
+
value,
|
|
150
|
+
setValue,
|
|
151
|
+
disabled,
|
|
152
|
+
readOnly
|
|
153
|
+
]);
|
|
154
|
+
const onItemLeave = react.useCallback(() => {
|
|
155
|
+
setHighlightedIndex(null);
|
|
156
|
+
setEditingIndex(null);
|
|
157
|
+
inputRef.current?.focus();
|
|
158
|
+
}, []);
|
|
159
|
+
const onInputKeydown = react.useCallback((event) => {
|
|
160
|
+
const target = event.target;
|
|
161
|
+
if (!(target instanceof HTMLInputElement)) return;
|
|
162
|
+
const isArrowLeft = event.key === "ArrowLeft" && dir === "ltr" || event.key === "ArrowRight" && dir === "rtl";
|
|
163
|
+
const isArrowRight = event.key === "ArrowRight" && dir === "ltr" || event.key === "ArrowLeft" && dir === "rtl";
|
|
164
|
+
if (target.value && target.selectionStart !== 0) {
|
|
165
|
+
setHighlightedIndex(null);
|
|
166
|
+
setEditingIndex(null);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
function findNextEnabledIndex(currentIndex, direction) {
|
|
170
|
+
if (!collectionRef.current) return null;
|
|
171
|
+
const enabledIndices = getEnabledItems().map((_, index) => index);
|
|
172
|
+
if (enabledIndices.length === 0) return null;
|
|
173
|
+
if (currentIndex === null) return direction === "prev" ? enabledIndices[enabledIndices.length - 1] ?? null : enabledIndices[0] ?? null;
|
|
174
|
+
const currentEnabledIndex = enabledIndices.indexOf(currentIndex);
|
|
175
|
+
if (direction === "next") return currentEnabledIndex >= enabledIndices.length - 1 ? loop ? enabledIndices[0] ?? null : null : enabledIndices[currentEnabledIndex + 1] ?? null;
|
|
176
|
+
return currentEnabledIndex <= 0 ? loop ? enabledIndices[enabledIndices.length - 1] ?? null : null : enabledIndices[currentEnabledIndex - 1] ?? null;
|
|
177
|
+
}
|
|
178
|
+
switch (event.key) {
|
|
179
|
+
case "Delete":
|
|
180
|
+
case "Backspace":
|
|
181
|
+
if (target.selectionStart !== 0 || target.selectionEnd !== 0) break;
|
|
182
|
+
if (highlightedIndex !== null) {
|
|
183
|
+
const newIndex = findNextEnabledIndex(highlightedIndex, "prev");
|
|
184
|
+
onItemRemove(highlightedIndex);
|
|
185
|
+
setHighlightedIndex(newIndex);
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
} else if (event.key === "Backspace" && value.length > 0) {
|
|
188
|
+
const lastIndex = findNextEnabledIndex(null, "prev");
|
|
189
|
+
setHighlightedIndex(lastIndex);
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
case "Enter":
|
|
194
|
+
if (highlightedIndex !== null && editable && !disabled) {
|
|
195
|
+
setEditingIndex(highlightedIndex);
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
case "ArrowLeft":
|
|
201
|
+
case "ArrowRight":
|
|
202
|
+
if (target.selectionStart === 0 && isArrowLeft && highlightedIndex === null && value.length > 0) {
|
|
203
|
+
const lastIndex = findNextEnabledIndex(null, "prev");
|
|
204
|
+
setHighlightedIndex(lastIndex);
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
} else if (highlightedIndex !== null) {
|
|
207
|
+
const nextIndex = findNextEnabledIndex(highlightedIndex, isArrowLeft ? "prev" : "next");
|
|
208
|
+
if (nextIndex !== null) {
|
|
209
|
+
setHighlightedIndex(nextIndex);
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
} else if (isArrowRight) {
|
|
212
|
+
setHighlightedIndex(null);
|
|
213
|
+
requestAnimationFrame(() => target.setSelectionRange(0, 0));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
case "Home":
|
|
218
|
+
if (highlightedIndex !== null) {
|
|
219
|
+
const firstIndex = findNextEnabledIndex(null, "next");
|
|
220
|
+
setHighlightedIndex(firstIndex);
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
case "End":
|
|
225
|
+
if (highlightedIndex !== null) {
|
|
226
|
+
const lastIndex = findNextEnabledIndex(null, "prev");
|
|
227
|
+
setHighlightedIndex(lastIndex);
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
case "Escape":
|
|
232
|
+
if (highlightedIndex !== null) setHighlightedIndex(null);
|
|
233
|
+
if (editingIndex !== null) setEditingIndex(null);
|
|
234
|
+
requestAnimationFrame(() => target.setSelectionRange(0, 0));
|
|
235
|
+
}
|
|
236
|
+
}, [
|
|
237
|
+
dir,
|
|
238
|
+
editingIndex,
|
|
239
|
+
highlightedIndex,
|
|
240
|
+
value,
|
|
241
|
+
onItemRemove,
|
|
242
|
+
getEnabledItems,
|
|
243
|
+
editable,
|
|
244
|
+
disabled,
|
|
245
|
+
loop
|
|
246
|
+
]);
|
|
247
|
+
const getIsClickedInEmptyRoot = react.useCallback((target) => {
|
|
248
|
+
return collectionRef.current?.contains(target) && !target.hasAttribute(_diceui_shared.DATA_ITEM_ATTR) && target.tagName !== "INPUT";
|
|
249
|
+
}, []);
|
|
250
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagsInputProvider, {
|
|
251
|
+
value,
|
|
252
|
+
onValueChange: setValue,
|
|
253
|
+
onItemAdd,
|
|
254
|
+
onItemRemove,
|
|
255
|
+
onItemUpdate,
|
|
256
|
+
onInputKeydown,
|
|
257
|
+
highlightedIndex,
|
|
258
|
+
setHighlightedIndex,
|
|
259
|
+
editingIndex,
|
|
260
|
+
setEditingIndex,
|
|
261
|
+
displayValue,
|
|
262
|
+
onItemLeave,
|
|
263
|
+
inputRef,
|
|
264
|
+
isInvalidInput,
|
|
265
|
+
addOnPaste,
|
|
266
|
+
addOnTab,
|
|
267
|
+
disabled,
|
|
268
|
+
editable,
|
|
269
|
+
loop,
|
|
270
|
+
readOnly,
|
|
271
|
+
blurBehavior,
|
|
272
|
+
delimiter,
|
|
273
|
+
max,
|
|
274
|
+
dir,
|
|
275
|
+
id,
|
|
276
|
+
inputId,
|
|
277
|
+
labelId,
|
|
278
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_diceui_shared.Primitive.div, {
|
|
279
|
+
id,
|
|
280
|
+
"data-disabled": disabled ? "" : void 0,
|
|
281
|
+
"data-invalid": isInvalidInput ? "" : void 0,
|
|
282
|
+
"data-readonly": readOnly ? "" : void 0,
|
|
283
|
+
dir,
|
|
284
|
+
...rootProps,
|
|
285
|
+
ref: composedRef,
|
|
286
|
+
onClick: (0, _diceui_shared.composeEventHandlers)(rootProps.onClick, (event) => {
|
|
287
|
+
const target = event.target;
|
|
288
|
+
if (!(target instanceof HTMLElement)) return;
|
|
289
|
+
if (getIsClickedInEmptyRoot(target) && document.activeElement !== inputRef.current) {
|
|
290
|
+
event.currentTarget.focus();
|
|
291
|
+
inputRef.current?.focus();
|
|
292
|
+
}
|
|
293
|
+
}),
|
|
294
|
+
onMouseDown: (0, _diceui_shared.composeEventHandlers)(rootProps.onMouseDown, (event) => {
|
|
295
|
+
const target = event.target;
|
|
296
|
+
if (!(target instanceof HTMLElement)) return;
|
|
297
|
+
if (getIsClickedInEmptyRoot(target)) event.preventDefault();
|
|
298
|
+
}),
|
|
299
|
+
onBlur: (0, _diceui_shared.composeEventHandlers)(rootProps.onBlur, (event) => {
|
|
300
|
+
if (event.relatedTarget !== inputRef.current && !collectionRef.current?.contains(event.relatedTarget)) requestAnimationFrame(() => setHighlightedIndex(null));
|
|
301
|
+
}),
|
|
302
|
+
children: [typeof children === "function" ? children({ value }) : children, isFormControl && name && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.VisuallyHiddenInput, {
|
|
303
|
+
type: "hidden",
|
|
304
|
+
control: collectionRef.current,
|
|
305
|
+
name,
|
|
306
|
+
value,
|
|
307
|
+
disabled,
|
|
308
|
+
required
|
|
309
|
+
})]
|
|
310
|
+
})
|
|
311
|
+
});
|
|
378
312
|
});
|
|
379
313
|
TagsInputRoot.displayName = ROOT_NAME;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
var TagsInputInput = React__namespace.forwardRef(
|
|
489
|
-
(props, ref) => {
|
|
490
|
-
const { autoFocus, ...inputProps } = props;
|
|
491
|
-
const context = useTagsInput(INPUT_NAME);
|
|
492
|
-
const onTab = React__namespace.useCallback(
|
|
493
|
-
(event) => {
|
|
494
|
-
if (!context.addOnTab) return;
|
|
495
|
-
onCustomKeydown(event);
|
|
496
|
-
},
|
|
497
|
-
[context.addOnTab]
|
|
498
|
-
);
|
|
499
|
-
const onCustomKeydown = React__namespace.useCallback(
|
|
500
|
-
(event) => {
|
|
501
|
-
if (event.defaultPrevented) return;
|
|
502
|
-
const value = event.currentTarget.value;
|
|
503
|
-
if (!value) return;
|
|
504
|
-
const isAdded = context.onItemAdd(value);
|
|
505
|
-
if (isAdded) {
|
|
506
|
-
event.currentTarget.value = "";
|
|
507
|
-
context.setHighlightedIndex(null);
|
|
508
|
-
}
|
|
509
|
-
event.preventDefault();
|
|
510
|
-
},
|
|
511
|
-
[context.onItemAdd, context.setHighlightedIndex]
|
|
512
|
-
);
|
|
513
|
-
React__namespace.useEffect(() => {
|
|
514
|
-
if (!autoFocus) return;
|
|
515
|
-
const animationFrameId = requestAnimationFrame(
|
|
516
|
-
() => context.inputRef.current?.focus()
|
|
517
|
-
);
|
|
518
|
-
return () => cancelAnimationFrame(animationFrameId);
|
|
519
|
-
}, [autoFocus, context.inputRef]);
|
|
520
|
-
return /* @__PURE__ */ React__namespace.createElement(
|
|
521
|
-
shared.Primitive.input,
|
|
522
|
-
{
|
|
523
|
-
type: "text",
|
|
524
|
-
id: context.inputId,
|
|
525
|
-
autoCapitalize: "off",
|
|
526
|
-
autoComplete: "off",
|
|
527
|
-
autoCorrect: "off",
|
|
528
|
-
spellCheck: "false",
|
|
529
|
-
autoFocus,
|
|
530
|
-
"aria-labelledby": context.labelId,
|
|
531
|
-
"aria-readonly": context.readOnly,
|
|
532
|
-
"data-invalid": context.isInvalidInput ? "" : void 0,
|
|
533
|
-
dir: context.dir,
|
|
534
|
-
disabled: context.disabled,
|
|
535
|
-
readOnly: context.readOnly,
|
|
536
|
-
...inputProps,
|
|
537
|
-
ref: shared.composeRefs(context.inputRef, ref),
|
|
538
|
-
onBlur: shared.composeEventHandlers(inputProps.onBlur, (event) => {
|
|
539
|
-
if (context.readOnly) return;
|
|
540
|
-
if (context.blurBehavior === "add") {
|
|
541
|
-
const value = event.target.value;
|
|
542
|
-
if (value) {
|
|
543
|
-
const isAdded = context.onItemAdd(value);
|
|
544
|
-
if (isAdded) event.target.value = "";
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
if (context.blurBehavior === "clear") {
|
|
548
|
-
event.target.value = "";
|
|
549
|
-
}
|
|
550
|
-
}),
|
|
551
|
-
onChange: shared.composeEventHandlers(inputProps.onChange, (event) => {
|
|
552
|
-
if (context.readOnly) return;
|
|
553
|
-
const target = event.target;
|
|
554
|
-
if (!(target instanceof HTMLInputElement)) return;
|
|
555
|
-
const delimiter = context.delimiter;
|
|
556
|
-
if (delimiter === target.value.slice(-1)) {
|
|
557
|
-
const value = target.value.slice(0, -1);
|
|
558
|
-
target.value = "";
|
|
559
|
-
if (value) {
|
|
560
|
-
context.onItemAdd(value);
|
|
561
|
-
context.setHighlightedIndex(null);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}),
|
|
565
|
-
onKeyDown: shared.composeEventHandlers(inputProps.onKeyDown, (event) => {
|
|
566
|
-
if (context.readOnly) return;
|
|
567
|
-
if (event.key === "Enter") onCustomKeydown(event);
|
|
568
|
-
if (event.key === "Tab") onTab(event);
|
|
569
|
-
context.onInputKeydown(event);
|
|
570
|
-
if (event.key.length === 1) context.setHighlightedIndex(null);
|
|
571
|
-
}),
|
|
572
|
-
onPaste: shared.composeEventHandlers(inputProps.onPaste, (event) => {
|
|
573
|
-
if (context.readOnly) return;
|
|
574
|
-
if (context.addOnPaste) {
|
|
575
|
-
event.preventDefault();
|
|
576
|
-
const value = event.clipboardData.getData("text");
|
|
577
|
-
context.onItemAdd(value, { viaPaste: true });
|
|
578
|
-
context.setHighlightedIndex(null);
|
|
579
|
-
}
|
|
580
|
-
})
|
|
581
|
-
}
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
);
|
|
314
|
+
const Root = TagsInputRoot;
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/tags-input-clear.tsx
|
|
317
|
+
const CLEAR_NAME = "TagsInputClear";
|
|
318
|
+
const TagsInputClear = react.forwardRef((props, ref) => {
|
|
319
|
+
const { forceMount, ...clearProps } = props;
|
|
320
|
+
const context = useTagsInput(CLEAR_NAME);
|
|
321
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Presence, {
|
|
322
|
+
present: forceMount || context.value.length > 0,
|
|
323
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.button, {
|
|
324
|
+
type: "button",
|
|
325
|
+
"aria-disabled": context.disabled,
|
|
326
|
+
"data-state": context.value.length > 0 ? "visible" : "invisible",
|
|
327
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
328
|
+
...clearProps,
|
|
329
|
+
ref,
|
|
330
|
+
onClick: (0, _diceui_shared.composeEventHandlers)(props.onClick, () => {
|
|
331
|
+
if (context.disabled) return;
|
|
332
|
+
context.onValueChange([]);
|
|
333
|
+
context.inputRef.current?.focus();
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
TagsInputClear.displayName = CLEAR_NAME;
|
|
339
|
+
const Clear = TagsInputClear;
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/tags-input-input.tsx
|
|
342
|
+
const INPUT_NAME = "TagsInputInput";
|
|
343
|
+
const TagsInputInput = react.forwardRef((props, ref) => {
|
|
344
|
+
const { autoFocus, ...inputProps } = props;
|
|
345
|
+
const context = useTagsInput(INPUT_NAME);
|
|
346
|
+
const onCustomKeydown = react.useCallback((event) => {
|
|
347
|
+
if (event.defaultPrevented) return;
|
|
348
|
+
const value = event.currentTarget.value;
|
|
349
|
+
if (!value) return;
|
|
350
|
+
if (context.onItemAdd(value)) {
|
|
351
|
+
event.currentTarget.value = "";
|
|
352
|
+
context.setHighlightedIndex(null);
|
|
353
|
+
}
|
|
354
|
+
event.preventDefault();
|
|
355
|
+
}, [context.onItemAdd, context.setHighlightedIndex]);
|
|
356
|
+
const onTab = react.useCallback((event) => {
|
|
357
|
+
if (!context.addOnTab) return;
|
|
358
|
+
onCustomKeydown(event);
|
|
359
|
+
}, [context.addOnTab, onCustomKeydown]);
|
|
360
|
+
react.useEffect(() => {
|
|
361
|
+
if (!autoFocus) return;
|
|
362
|
+
const animationFrameId = requestAnimationFrame(() => context.inputRef.current?.focus());
|
|
363
|
+
return () => cancelAnimationFrame(animationFrameId);
|
|
364
|
+
}, [autoFocus, context.inputRef]);
|
|
365
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.input, {
|
|
366
|
+
type: "text",
|
|
367
|
+
id: context.inputId,
|
|
368
|
+
autoCapitalize: "off",
|
|
369
|
+
autoComplete: "off",
|
|
370
|
+
autoCorrect: "off",
|
|
371
|
+
spellCheck: "false",
|
|
372
|
+
autoFocus,
|
|
373
|
+
"aria-labelledby": context.labelId,
|
|
374
|
+
"aria-readonly": context.readOnly,
|
|
375
|
+
"data-invalid": context.isInvalidInput ? "" : void 0,
|
|
376
|
+
dir: context.dir,
|
|
377
|
+
disabled: context.disabled,
|
|
378
|
+
readOnly: context.readOnly,
|
|
379
|
+
...inputProps,
|
|
380
|
+
ref: (0, _diceui_shared.composeRefs)(context.inputRef, ref),
|
|
381
|
+
onBlur: (0, _diceui_shared.composeEventHandlers)(inputProps.onBlur, (event) => {
|
|
382
|
+
if (context.readOnly) return;
|
|
383
|
+
if (context.blurBehavior === "add") {
|
|
384
|
+
const value = event.target.value;
|
|
385
|
+
if (value) {
|
|
386
|
+
if (context.onItemAdd(value)) event.target.value = "";
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (context.blurBehavior === "clear") event.target.value = "";
|
|
390
|
+
}),
|
|
391
|
+
onChange: (0, _diceui_shared.composeEventHandlers)(inputProps.onChange, (event) => {
|
|
392
|
+
if (context.readOnly) return;
|
|
393
|
+
const target = event.target;
|
|
394
|
+
if (!(target instanceof HTMLInputElement)) return;
|
|
395
|
+
if (context.delimiter === target.value.slice(-1)) {
|
|
396
|
+
const value = target.value.slice(0, -1);
|
|
397
|
+
target.value = "";
|
|
398
|
+
if (value) {
|
|
399
|
+
context.onItemAdd(value);
|
|
400
|
+
context.setHighlightedIndex(null);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}),
|
|
404
|
+
onKeyDown: (0, _diceui_shared.composeEventHandlers)(inputProps.onKeyDown, (event) => {
|
|
405
|
+
if (context.readOnly) return;
|
|
406
|
+
if (event.key === "Enter") onCustomKeydown(event);
|
|
407
|
+
if (event.key === "Tab") onTab(event);
|
|
408
|
+
context.onInputKeydown(event);
|
|
409
|
+
if (event.key.length === 1) context.setHighlightedIndex(null);
|
|
410
|
+
}),
|
|
411
|
+
onPaste: (0, _diceui_shared.composeEventHandlers)(inputProps.onPaste, (event) => {
|
|
412
|
+
if (context.readOnly) return;
|
|
413
|
+
if (context.addOnPaste) {
|
|
414
|
+
event.preventDefault();
|
|
415
|
+
const value = event.clipboardData.getData("text");
|
|
416
|
+
context.onItemAdd(value, { viaPaste: true });
|
|
417
|
+
context.setHighlightedIndex(null);
|
|
418
|
+
}
|
|
419
|
+
})
|
|
420
|
+
});
|
|
421
|
+
});
|
|
585
422
|
TagsInputInput.displayName = INPUT_NAME;
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
423
|
+
const Input = TagsInputInput;
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/tags-input-item.tsx
|
|
426
|
+
const ITEM_NAME = "TagsInputItem";
|
|
427
|
+
const [TagsInputItemProvider, useTagsInputItem] = (0, _diceui_shared.createContext)(ITEM_NAME);
|
|
428
|
+
const TagsInputItem = react.forwardRef((props, ref) => {
|
|
429
|
+
const { value, disabled, ...itemProps } = props;
|
|
430
|
+
const pointerTypeRef = react.useRef("touch");
|
|
431
|
+
const context = useTagsInput(ITEM_NAME);
|
|
432
|
+
const id = (0, _diceui_shared.useId)();
|
|
433
|
+
const textId = `${id}text`;
|
|
434
|
+
const index = context.value.indexOf(value);
|
|
435
|
+
const isHighlighted = index === context.highlightedIndex;
|
|
436
|
+
const isEditing = index === context.editingIndex;
|
|
437
|
+
const itemDisabled = disabled || context.disabled;
|
|
438
|
+
const displayValue = context.displayValue(value);
|
|
439
|
+
const onItemSelect = react.useCallback(() => {
|
|
440
|
+
context.setHighlightedIndex(index);
|
|
441
|
+
context.inputRef.current?.focus();
|
|
442
|
+
}, [
|
|
443
|
+
context.setHighlightedIndex,
|
|
444
|
+
context.inputRef,
|
|
445
|
+
index
|
|
446
|
+
]);
|
|
447
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagsInputItemProvider, {
|
|
448
|
+
id,
|
|
449
|
+
value,
|
|
450
|
+
index,
|
|
451
|
+
isHighlighted,
|
|
452
|
+
isEditing,
|
|
453
|
+
disabled: itemDisabled,
|
|
454
|
+
textId,
|
|
455
|
+
displayValue,
|
|
456
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.div, {
|
|
457
|
+
id,
|
|
458
|
+
"aria-labelledby": textId,
|
|
459
|
+
"aria-current": isHighlighted,
|
|
460
|
+
"aria-disabled": itemDisabled,
|
|
461
|
+
[_diceui_shared.DATA_ITEM_ATTR]: "",
|
|
462
|
+
"data-state": isHighlighted ? "active" : "inactive",
|
|
463
|
+
"data-highlighted": isHighlighted ? "" : void 0,
|
|
464
|
+
"data-editing": isEditing ? "" : void 0,
|
|
465
|
+
"data-editable": context.editable ? "" : void 0,
|
|
466
|
+
"data-disabled": itemDisabled ? "" : void 0,
|
|
467
|
+
...itemProps,
|
|
468
|
+
ref,
|
|
469
|
+
onClick: (0, _diceui_shared.composeEventHandlers)(itemProps.onClick, (event) => {
|
|
470
|
+
event.stopPropagation();
|
|
471
|
+
if (!isEditing && pointerTypeRef.current !== "mouse") onItemSelect();
|
|
472
|
+
}),
|
|
473
|
+
onDoubleClick: (0, _diceui_shared.composeEventHandlers)(itemProps.onDoubleClick, () => {
|
|
474
|
+
if (context.editable && !itemDisabled) requestAnimationFrame(() => context.setEditingIndex(index));
|
|
475
|
+
}),
|
|
476
|
+
onPointerUp: (0, _diceui_shared.composeEventHandlers)(itemProps.onPointerUp, () => {
|
|
477
|
+
if (pointerTypeRef.current === "mouse") onItemSelect();
|
|
478
|
+
}),
|
|
479
|
+
onPointerDown: (0, _diceui_shared.composeEventHandlers)(itemProps.onPointerDown, (event) => pointerTypeRef.current = event.pointerType),
|
|
480
|
+
onPointerMove: (0, _diceui_shared.composeEventHandlers)(itemProps.onPointerMove, (event) => {
|
|
481
|
+
pointerTypeRef.current = event.pointerType;
|
|
482
|
+
if (disabled) context.onItemLeave();
|
|
483
|
+
else if (pointerTypeRef.current === "mouse") event.currentTarget.focus({ preventScroll: true });
|
|
484
|
+
}),
|
|
485
|
+
onPointerLeave: (0, _diceui_shared.composeEventHandlers)(itemProps.onPointerLeave, (event) => {
|
|
486
|
+
if (event.currentTarget === document.activeElement) context.onItemLeave();
|
|
487
|
+
})
|
|
488
|
+
})
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
TagsInputItem.displayName = ITEM_NAME;
|
|
492
|
+
const Item = TagsInputItem;
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/tags-input-item-delete.tsx
|
|
495
|
+
const ITEM_DELETE_NAME = "TagsInputItemDelete";
|
|
496
|
+
const TagsInputItemDelete = react.forwardRef((props, ref) => {
|
|
497
|
+
const context = useTagsInput(ITEM_DELETE_NAME);
|
|
498
|
+
const itemContext = useTagsInputItem(ITEM_DELETE_NAME);
|
|
499
|
+
const disabled = itemContext.disabled || context.disabled;
|
|
500
|
+
if (itemContext.isEditing) return null;
|
|
501
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.button, {
|
|
502
|
+
type: "button",
|
|
503
|
+
tabIndex: disabled ? void 0 : -1,
|
|
504
|
+
"aria-labelledby": itemContext.textId,
|
|
505
|
+
"aria-controls": itemContext.id,
|
|
506
|
+
"aria-current": itemContext.isHighlighted,
|
|
507
|
+
"data-state": itemContext.isHighlighted ? "active" : "inactive",
|
|
508
|
+
"data-disabled": disabled ? "" : void 0,
|
|
509
|
+
...props,
|
|
510
|
+
ref,
|
|
511
|
+
onClick: (0, _diceui_shared.composeEventHandlers)(props.onClick, () => {
|
|
512
|
+
if (disabled) return;
|
|
513
|
+
const index = context.value.indexOf(itemContext.value);
|
|
514
|
+
context.onItemRemove(index);
|
|
515
|
+
})
|
|
516
|
+
});
|
|
612
517
|
});
|
|
613
518
|
TagsInputItemDelete.displayName = ITEM_DELETE_NAME;
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
519
|
+
const ItemDelete = TagsInputItemDelete;
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/tags-input-item-text.tsx
|
|
522
|
+
const ITEM_TEXT_NAME = "TagsInputItemText";
|
|
523
|
+
const TagsInputItemText = react.forwardRef((props, ref) => {
|
|
524
|
+
const { children, ...itemTextProps } = props;
|
|
525
|
+
const context = useTagsInput(ITEM_TEXT_NAME);
|
|
526
|
+
const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
|
|
527
|
+
if (itemContext.isEditing && context.editable && !itemContext.disabled) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagsInputEditableItemText, {});
|
|
528
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.span, {
|
|
529
|
+
id: itemContext.textId,
|
|
530
|
+
...itemTextProps,
|
|
531
|
+
ref,
|
|
532
|
+
children: children ?? itemContext.displayValue
|
|
533
|
+
});
|
|
624
534
|
});
|
|
625
|
-
|
|
535
|
+
const ItemText = TagsInputItemText;
|
|
626
536
|
function TagsInputEditableItemText() {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
onBlur,
|
|
691
|
-
style: {
|
|
692
|
-
outline: "none",
|
|
693
|
-
background: "inherit",
|
|
694
|
-
border: "none",
|
|
695
|
-
font: "inherit",
|
|
696
|
-
color: "inherit",
|
|
697
|
-
padding: 0,
|
|
698
|
-
minWidth: "1ch"
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
);
|
|
537
|
+
const context = useTagsInput(ITEM_TEXT_NAME);
|
|
538
|
+
const itemContext = useTagsInputItem(ITEM_TEXT_NAME);
|
|
539
|
+
const [editValue, setEditValue] = react.useState(itemContext.displayValue);
|
|
540
|
+
const onBlur = react.useCallback(() => {
|
|
541
|
+
setEditValue(itemContext.displayValue);
|
|
542
|
+
context.setEditingIndex(null);
|
|
543
|
+
}, [context.setEditingIndex, itemContext.displayValue]);
|
|
544
|
+
const onChange = react.useCallback((event) => {
|
|
545
|
+
const target = event.target;
|
|
546
|
+
target.style.width = "0";
|
|
547
|
+
target.style.width = `${target.scrollWidth + 4}px`;
|
|
548
|
+
setEditValue(event.target.value);
|
|
549
|
+
}, []);
|
|
550
|
+
const onFocus = react.useCallback((event) => {
|
|
551
|
+
event.target.select();
|
|
552
|
+
event.target.style.width = "0";
|
|
553
|
+
event.target.style.width = `${event.target.scrollWidth + 4}px`;
|
|
554
|
+
}, []);
|
|
555
|
+
const onKeyDown = react.useCallback((event) => {
|
|
556
|
+
if (event.key === "Enter") {
|
|
557
|
+
const index = context.value.indexOf(itemContext.value);
|
|
558
|
+
context.onItemUpdate(index, editValue);
|
|
559
|
+
} else if (event.key === "Escape") {
|
|
560
|
+
setEditValue(itemContext.displayValue);
|
|
561
|
+
context.setEditingIndex(null);
|
|
562
|
+
context.setHighlightedIndex(itemContext.index);
|
|
563
|
+
context.inputRef.current?.focus();
|
|
564
|
+
}
|
|
565
|
+
event.stopPropagation();
|
|
566
|
+
}, [
|
|
567
|
+
context.value,
|
|
568
|
+
context.onItemUpdate,
|
|
569
|
+
context.setEditingIndex,
|
|
570
|
+
itemContext.displayValue,
|
|
571
|
+
context.inputRef.current?.focus,
|
|
572
|
+
editValue,
|
|
573
|
+
itemContext.value,
|
|
574
|
+
context.setHighlightedIndex,
|
|
575
|
+
itemContext.index
|
|
576
|
+
]);
|
|
577
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.input, {
|
|
578
|
+
type: "text",
|
|
579
|
+
autoCapitalize: "off",
|
|
580
|
+
autoComplete: "off",
|
|
581
|
+
autoCorrect: "off",
|
|
582
|
+
spellCheck: "false",
|
|
583
|
+
autoFocus: true,
|
|
584
|
+
"aria-describedby": itemContext.textId,
|
|
585
|
+
value: editValue,
|
|
586
|
+
onChange,
|
|
587
|
+
onKeyDown,
|
|
588
|
+
onFocus,
|
|
589
|
+
onBlur,
|
|
590
|
+
style: {
|
|
591
|
+
outline: "none",
|
|
592
|
+
background: "inherit",
|
|
593
|
+
border: "none",
|
|
594
|
+
font: "inherit",
|
|
595
|
+
color: "inherit",
|
|
596
|
+
padding: 0,
|
|
597
|
+
minWidth: "1ch"
|
|
598
|
+
}
|
|
599
|
+
});
|
|
702
600
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (context.disabled) return;
|
|
719
|
-
context.onValueChange([]);
|
|
720
|
-
context.inputRef.current?.focus();
|
|
721
|
-
})
|
|
722
|
-
}
|
|
723
|
-
));
|
|
724
|
-
}
|
|
725
|
-
);
|
|
726
|
-
TagsInputClear.displayName = CLEAR_NAME;
|
|
727
|
-
var Clear = TagsInputClear;
|
|
728
|
-
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region src/tags-input-label.tsx
|
|
603
|
+
const LABEL_NAME = "TagsInputLabel";
|
|
604
|
+
const TagsInputLabel = react.forwardRef((props, ref) => {
|
|
605
|
+
const context = useTagsInput(LABEL_NAME);
|
|
606
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_diceui_shared.Primitive.label, {
|
|
607
|
+
id: context.labelId,
|
|
608
|
+
htmlFor: context.inputId,
|
|
609
|
+
...props,
|
|
610
|
+
ref
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
TagsInputLabel.displayName = LABEL_NAME;
|
|
614
|
+
const Label = TagsInputLabel;
|
|
615
|
+
//#endregion
|
|
729
616
|
exports.Clear = Clear;
|
|
730
617
|
exports.Input = Input;
|
|
731
618
|
exports.Item = Item;
|