@react-fabric/form 1.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/builder/FileField.js +131 -0
- package/dist/cjs/builder/FormField.js +119 -0
- package/dist/cjs/form/Controller.js +64 -0
- package/dist/cjs/form/Form.js +128 -0
- package/dist/cjs/hooks/useFileUploader.js +204 -0
- package/dist/cjs/hooks/useFormBuilder.js +87 -0
- package/dist/cjs/i18n/ar.json.js +37 -0
- package/dist/cjs/i18n/en.json.js +38 -0
- package/dist/cjs/i18n/index.js +33 -0
- package/dist/cjs/index.js +56 -0
- package/dist/cjs/input/ArrayInput.js +189 -0
- package/dist/cjs/input/ArrayInput.module.css +1 -0
- package/dist/cjs/input/AvatarInput.js +141 -0
- package/dist/cjs/input/Checkbox.js +83 -0
- package/dist/cjs/input/ColorInput.js +100 -0
- package/dist/cjs/input/ColorPicker.js +122 -0
- package/dist/cjs/input/ColorPicker.module.css +1 -0
- package/dist/cjs/input/Field.js +31 -0
- package/dist/cjs/input/File.js +165 -0
- package/dist/cjs/input/File.module.css +1 -0
- package/dist/cjs/input/Hidden.js +54 -0
- package/dist/cjs/input/Input.js +79 -0
- package/dist/cjs/input/Number.js +80 -0
- package/dist/cjs/input/Password.js +104 -0
- package/dist/cjs/input/Radio.js +70 -0
- package/dist/cjs/input/RadioGroup.js +31 -0
- package/dist/cjs/input/Range.js +169 -0
- package/dist/cjs/input/Search.js +109 -0
- package/dist/cjs/input/Slider.js +172 -0
- package/dist/cjs/input/Switch.js +79 -0
- package/dist/cjs/input/Textarea.js +87 -0
- package/dist/cjs/internal/ErrorIcon.js +32 -0
- package/dist/cjs/internal/Field.module.css +1 -0
- package/dist/cjs/internal/FieldWrapper.js +78 -0
- package/dist/cjs/internal/InputWrapper.js +113 -0
- package/dist/cjs/ranger/index.js +352 -0
- package/dist/cjs/ranger/utils.js +49 -0
- package/dist/cjs/select/AutoComplete.js +268 -0
- package/dist/cjs/select/DualList.js +238 -0
- package/dist/cjs/select/List.js +241 -0
- package/dist/cjs/select/Options.js +76 -0
- package/dist/cjs/select/Select.js +283 -0
- package/dist/cjs/select/helpers.js +41 -0
- package/dist/cjs/select/useSelect.js +337 -0
- package/dist/cjs/utils/eventHandlers.js +50 -0
- package/dist/cjs/utils/getColor.js +40 -0
- package/dist/esm/builder/FileField.js +131 -0
- package/dist/esm/builder/FormField.js +119 -0
- package/dist/esm/form/Controller.js +64 -0
- package/dist/esm/form/Form.js +128 -0
- package/dist/esm/hooks/useFileUploader.js +204 -0
- package/dist/esm/hooks/useFormBuilder.js +87 -0
- package/dist/esm/i18n/ar.json.js +31 -0
- package/dist/esm/i18n/en.json.js +32 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/input/ArrayInput.js +189 -0
- package/dist/esm/input/ArrayInput.module.css +1 -0
- package/dist/esm/input/AvatarInput.js +141 -0
- package/dist/esm/input/Checkbox.js +83 -0
- package/dist/esm/input/ColorInput.js +100 -0
- package/dist/esm/input/ColorPicker.js +122 -0
- package/dist/esm/input/ColorPicker.module.css +1 -0
- package/dist/esm/input/Field.js +31 -0
- package/dist/esm/input/File.js +165 -0
- package/dist/esm/input/File.module.css +1 -0
- package/dist/esm/input/Hidden.js +54 -0
- package/dist/esm/input/Input.js +79 -0
- package/dist/esm/input/Number.js +80 -0
- package/dist/esm/input/Password.js +104 -0
- package/dist/esm/input/Radio.js +70 -0
- package/dist/esm/input/RadioGroup.js +31 -0
- package/dist/esm/input/Range.js +169 -0
- package/dist/esm/input/Search.js +109 -0
- package/dist/esm/input/Slider.js +172 -0
- package/dist/esm/input/Switch.js +79 -0
- package/dist/esm/input/Textarea.js +87 -0
- package/dist/esm/internal/ErrorIcon.js +32 -0
- package/dist/esm/internal/Field.module.css +1 -0
- package/dist/esm/internal/FieldWrapper.js +78 -0
- package/dist/esm/internal/InputWrapper.js +113 -0
- package/dist/esm/ranger/index.js +352 -0
- package/dist/esm/ranger/utils.js +47 -0
- package/dist/esm/select/AutoComplete.js +268 -0
- package/dist/esm/select/DualList.js +238 -0
- package/dist/esm/select/List.js +241 -0
- package/dist/esm/select/Options.js +76 -0
- package/dist/esm/select/Select.js +283 -0
- package/dist/esm/select/helpers.js +40 -0
- package/dist/esm/select/useSelect.js +337 -0
- package/dist/esm/utils/eventHandlers.js +50 -0
- package/dist/esm/utils/getColor.js +39 -0
- package/dist/types/builder/FileField.d.ts +8 -0
- package/dist/types/builder/FormField.d.ts +9 -0
- package/dist/types/form/Controller.d.ts +20 -0
- package/dist/types/form/Form.d.ts +33 -0
- package/dist/types/hooks/useFileUploader.d.ts +23 -0
- package/dist/types/hooks/useFormBuilder.d.ts +16 -0
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/input/ArrayInput.d.ts +64 -0
- package/dist/types/input/AvatarInput.d.ts +31 -0
- package/dist/types/input/Checkbox.d.ts +46 -0
- package/dist/types/input/ColorInput.d.ts +10 -0
- package/dist/types/input/ColorPicker.d.ts +24 -0
- package/dist/types/input/Field.d.ts +41 -0
- package/dist/types/input/File.d.ts +17 -0
- package/dist/types/input/Hidden.d.ts +16 -0
- package/dist/types/input/Input.d.ts +9 -0
- package/dist/types/input/Number.d.ts +17 -0
- package/dist/types/input/Password.d.ts +13 -0
- package/dist/types/input/Radio.d.ts +42 -0
- package/dist/types/input/RadioGroup.d.ts +30 -0
- package/dist/types/input/Range.d.ts +59 -0
- package/dist/types/input/Search.d.ts +17 -0
- package/dist/types/input/Slider.d.ts +63 -0
- package/dist/types/input/Switch.d.ts +42 -0
- package/dist/types/input/Textarea.d.ts +17 -0
- package/dist/types/internal/ErrorIcon.d.ts +1 -0
- package/dist/types/internal/FieldWrapper.d.ts +1 -0
- package/dist/types/internal/InputWrapper.d.ts +1 -0
- package/dist/types/ranger/index.d.ts +70 -0
- package/dist/types/ranger/utils.d.ts +25 -0
- package/dist/types/select/AutoComplete.d.ts +17 -0
- package/dist/types/select/DualList.d.ts +38 -0
- package/dist/types/select/List.d.ts +4 -0
- package/dist/types/select/Options.d.ts +14 -0
- package/dist/types/select/Select.d.ts +2 -0
- package/dist/types/select/helpers.d.ts +2 -0
- package/dist/types/select/useSelect.d.ts +50 -0
- package/dist/types/types/index.d.ts +169 -0
- package/dist/types/types/schema.d.ts +59 -0
- package/dist/types/utils/eventHandlers.d.ts +11 -0
- package/dist/types/utils/getColor.d.ts +4 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/package.json +64 -0
- package/src/builder/FileField.tsx +122 -0
- package/src/builder/FormField.tsx +161 -0
- package/src/form/Controller.tsx +103 -0
- package/src/form/Form.tsx +160 -0
- package/src/hooks/useFileUploader.ts +234 -0
- package/src/hooks/useFormBuilder.tsx +128 -0
- package/src/i18n/ar.json +23 -0
- package/src/i18n/en.json +24 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +54 -0
- package/src/input/ArrayInput.module.css +41 -0
- package/src/input/ArrayInput.tsx +318 -0
- package/src/input/AvatarInput.tsx +150 -0
- package/src/input/Checkbox.tsx +165 -0
- package/src/input/ColorInput.tsx +157 -0
- package/src/input/ColorPicker.module.css +51 -0
- package/src/input/ColorPicker.tsx +210 -0
- package/src/input/Field.tsx +96 -0
- package/src/input/File.module.css +42 -0
- package/src/input/File.tsx +224 -0
- package/src/input/Hidden.tsx +65 -0
- package/src/input/Input.tsx +114 -0
- package/src/input/Number.tsx +126 -0
- package/src/input/Password.tsx +150 -0
- package/src/input/Radio.tsx +146 -0
- package/src/input/RadioGroup.tsx +75 -0
- package/src/input/Range.tsx +276 -0
- package/src/input/Search.tsx +160 -0
- package/src/input/Slider.tsx +282 -0
- package/src/input/Switch.tsx +168 -0
- package/src/input/Textarea.tsx +127 -0
- package/src/internal/ErrorIcon.tsx +61 -0
- package/src/internal/Field.module.css +139 -0
- package/src/internal/FieldWrapper.tsx +84 -0
- package/src/internal/InputWrapper.tsx +187 -0
- package/src/ranger/index.tsx +514 -0
- package/src/ranger/utils.ts +48 -0
- package/src/select/AutoComplete.tsx +354 -0
- package/src/select/DualList.tsx +286 -0
- package/src/select/List.tsx +288 -0
- package/src/select/Options.tsx +121 -0
- package/src/select/Select.tsx +350 -0
- package/src/select/helpers.ts +36 -0
- package/src/select/useSelect.tsx +413 -0
- package/src/types/index.ts +203 -0
- package/src/types/schema.ts +100 -0
- package/src/utils/eventHandlers.ts +72 -0
- package/src/utils/getColor.ts +47 -0
- package/src/utils/index.ts +25 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
5
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
|
+
var core = require('@react-fabric/core');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var utils = require('./utils.js');
|
|
9
|
+
|
|
10
|
+
var useGetLatest = function useGetLatest(val) {
|
|
11
|
+
var ref = react.useRef(val);
|
|
12
|
+
ref.current = val;
|
|
13
|
+
return react.useCallback(function () {
|
|
14
|
+
return ref.current;
|
|
15
|
+
}, []);
|
|
16
|
+
};
|
|
17
|
+
var useRanger = function useRanger(opts) {
|
|
18
|
+
var _opts$tickSize;
|
|
19
|
+
var tickSize = (_opts$tickSize = opts.tickSize) !== null && _opts$tickSize !== void 0 ? _opts$tickSize : 10;
|
|
20
|
+
var values = opts.values;
|
|
21
|
+
var min = opts.min;
|
|
22
|
+
var max = opts.max;
|
|
23
|
+
var isVertical = opts.vertical;
|
|
24
|
+
var controlledTicks = opts.ticks;
|
|
25
|
+
var steps = "steps" in opts ? opts.steps : undefined;
|
|
26
|
+
var onChange = opts.onChange;
|
|
27
|
+
var onDrag = opts.onDrag;
|
|
28
|
+
var onDragStart = opts.onDragStart;
|
|
29
|
+
var onDragEnd = opts.onDragEnd;
|
|
30
|
+
var stepSize = "stepSize" in opts ? opts.stepSize : 1;
|
|
31
|
+
var _useState = react.useState(),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
activeHandleIndex = _useState2[0],
|
|
34
|
+
setActiveHandleIndex = _useState2[1];
|
|
35
|
+
var _useState3 = react.useState(),
|
|
36
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
37
|
+
segmentStart = _useState4[0],
|
|
38
|
+
setSegmentStart = _useState4[1];
|
|
39
|
+
var _useState5 = react.useState(),
|
|
40
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
41
|
+
tempValues = _useState6[0],
|
|
42
|
+
setTempValues = _useState6[1];
|
|
43
|
+
var isRtl = core.useIsRtl();
|
|
44
|
+
var positionProp = react.useMemo(function () {
|
|
45
|
+
return isVertical ? "bottom" : isRtl ? "right" : "left";
|
|
46
|
+
}, [isVertical, isRtl]);
|
|
47
|
+
var marginProp = react.useMemo(function () {
|
|
48
|
+
return isVertical ? "marginBottom" : isRtl ? "marginRight" : "marginLeft";
|
|
49
|
+
}, [isVertical, isRtl]);
|
|
50
|
+
var getLatest = useGetLatest({
|
|
51
|
+
activeHandleIndex: activeHandleIndex,
|
|
52
|
+
segmentStart: segmentStart,
|
|
53
|
+
onChange: onChange,
|
|
54
|
+
onDrag: onDrag,
|
|
55
|
+
onDragStart: onDragStart,
|
|
56
|
+
onDragEnd: onDragEnd,
|
|
57
|
+
values: values,
|
|
58
|
+
tempValues: tempValues
|
|
59
|
+
});
|
|
60
|
+
var trackElRef = react.useRef(null);
|
|
61
|
+
var segmentElRef = react.useRef(null);
|
|
62
|
+
var getValueForClientX = react.useCallback(function (clientX) {
|
|
63
|
+
var trackDims = utils.getBoundingClientRect(trackElRef.current);
|
|
64
|
+
return utils.linearInterpolator.getValueForClientX(clientX, trackDims, min, max, isRtl);
|
|
65
|
+
}, [max, min, isRtl]);
|
|
66
|
+
var getValueForClientY = react.useCallback(function (clientY) {
|
|
67
|
+
var trackDims = utils.getBoundingClientRect(trackElRef.current);
|
|
68
|
+
return utils.linearInterpolator.getValueForClientY(clientY, trackDims, min, max);
|
|
69
|
+
}, [max, min]);
|
|
70
|
+
var getNextStep = react.useCallback(function (val, direction) {
|
|
71
|
+
if (steps) {
|
|
72
|
+
var currIndex = steps.indexOf(val);
|
|
73
|
+
var nextIndex = currIndex + direction;
|
|
74
|
+
if (nextIndex >= 0 && nextIndex < steps.length) {
|
|
75
|
+
return steps[nextIndex];
|
|
76
|
+
} else {
|
|
77
|
+
return val;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
if (process.env.NODE_ENV !== "production") {
|
|
81
|
+
if (typeof stepSize === "undefined") {
|
|
82
|
+
throw new Error("Warning: The option `stepSize` is expected in `useRanger`, but its value is `undefined`");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
var nextVal = val + stepSize * direction;
|
|
86
|
+
if (nextVal >= min && nextVal <= max) {
|
|
87
|
+
return nextVal;
|
|
88
|
+
} else {
|
|
89
|
+
return val;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [max, min, stepSize, steps]);
|
|
93
|
+
var roundToStep = react.useCallback(function (val) {
|
|
94
|
+
var left = min;
|
|
95
|
+
var right = max;
|
|
96
|
+
if (steps) {
|
|
97
|
+
steps.forEach(function (step) {
|
|
98
|
+
if (step <= val && step > left) {
|
|
99
|
+
left = step;
|
|
100
|
+
}
|
|
101
|
+
if (step >= val && step < right) {
|
|
102
|
+
right = step;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
if (process.env.NODE_ENV !== "production") {
|
|
107
|
+
if (typeof stepSize === "undefined") {
|
|
108
|
+
throw new Error("Warning: The option `stepSize` is expected in `useRanger`, but its value is `undefined`");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
while (left < val && left + stepSize < val) {
|
|
112
|
+
left += stepSize;
|
|
113
|
+
}
|
|
114
|
+
right = Math.min(left + stepSize, max);
|
|
115
|
+
}
|
|
116
|
+
if (val - left < right - val) {
|
|
117
|
+
return +left.toFixed(3);
|
|
118
|
+
}
|
|
119
|
+
return +right.toFixed(3);
|
|
120
|
+
}, [max, min, stepSize, steps]);
|
|
121
|
+
var handleDrag = react.useCallback(function (e) {
|
|
122
|
+
var _getLatest = getLatest(),
|
|
123
|
+
activeHandleIndex = _getLatest.activeHandleIndex,
|
|
124
|
+
onDrag = _getLatest.onDrag;
|
|
125
|
+
var clientX =
|
|
126
|
+
// @ts-expect-error ignore
|
|
127
|
+
e.type === "touchmove" ? e.changedTouches[0].clientX : e.clientX;
|
|
128
|
+
var clientY =
|
|
129
|
+
// @ts-expect-error ignore
|
|
130
|
+
e.type === "touchmove" ? e.changedTouches[0].clientY : e.clientY;
|
|
131
|
+
var newValue = isVertical ? getValueForClientY(clientY) : getValueForClientX(clientX);
|
|
132
|
+
var newRoundedValue = roundToStep(newValue);
|
|
133
|
+
var newValues = [].concat(_toConsumableArray(values.slice(0, activeHandleIndex)), [newRoundedValue], _toConsumableArray(values.slice(+activeHandleIndex + 1)));
|
|
134
|
+
onDrag === null || onDrag === void 0 || onDrag(newValues);
|
|
135
|
+
setTempValues(newValues);
|
|
136
|
+
}, [getLatest, getValueForClientX, getValueForClientY, roundToStep, values, isVertical]);
|
|
137
|
+
var handleSegmentDrag = react.useCallback(function (e) {
|
|
138
|
+
var _getLatest2 = getLatest(),
|
|
139
|
+
_getLatest2$segmentSt = _slicedToArray(_getLatest2.segmentStart, 2),
|
|
140
|
+
segX = _getLatest2$segmentSt[0],
|
|
141
|
+
segY = _getLatest2$segmentSt[1],
|
|
142
|
+
tempValues = _getLatest2.tempValues,
|
|
143
|
+
onDrag = _getLatest2.onDrag;
|
|
144
|
+
var _getBoundingClientRec = utils.getBoundingClientRect(segmentElRef.current),
|
|
145
|
+
left = _getBoundingClientRec.left,
|
|
146
|
+
bottom = _getBoundingClientRec.bottom;
|
|
147
|
+
var clientX =
|
|
148
|
+
// @ts-expect-error ignore
|
|
149
|
+
e.type === "touchmove" ? e.changedTouches[0].clientX : e.clientX;
|
|
150
|
+
var clientY =
|
|
151
|
+
// @ts-expect-error ignore
|
|
152
|
+
e.type === "touchmove" ? e.changedTouches[0].clientY : e.clientY;
|
|
153
|
+
var start = isVertical ? getValueForClientX(bottom + (clientY - segY)) : getValueForClientX(left + (clientX - segX));
|
|
154
|
+
var diff = roundToStep(start) - tempValues[0];
|
|
155
|
+
if (+tempValues[1] + diff > max) diff = 0;
|
|
156
|
+
var newValues = [+tempValues[0] + diff, +tempValues[1] + diff];
|
|
157
|
+
if (tempValues[0] !== newValues[0] || tempValues[1] !== newValues[1]) {
|
|
158
|
+
onDrag === null || onDrag === void 0 || onDrag(newValues);
|
|
159
|
+
setTempValues(newValues);
|
|
160
|
+
setSegmentStart([clientX, clientY]);
|
|
161
|
+
}
|
|
162
|
+
}, [getLatest, getValueForClientX, getValueForClientY, roundToStep, values, isVertical, max]);
|
|
163
|
+
var handleKeyDown = react.useCallback(function (e, i) {
|
|
164
|
+
var _getLatest3 = getLatest(),
|
|
165
|
+
values = _getLatest3.values,
|
|
166
|
+
onChange = _getLatest3.onChange;
|
|
167
|
+
if (["ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown"].includes(e.key)) {
|
|
168
|
+
setActiveHandleIndex(i);
|
|
169
|
+
var direction = ["ArrowLeft", "ArrowDown"].includes(e.key) ? -1 : 1;
|
|
170
|
+
var _newValue = +getNextStep(values[i], direction).toFixed(3);
|
|
171
|
+
var newValues = [].concat(_toConsumableArray(values.slice(0, i)), [_newValue], _toConsumableArray(values.slice(i + 1)));
|
|
172
|
+
var sortedValues = utils.sortNumList(newValues);
|
|
173
|
+
onChange === null || onChange === void 0 || onChange(sortedValues);
|
|
174
|
+
e.stopPropagation();
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
}
|
|
177
|
+
}, [getLatest, getNextStep]);
|
|
178
|
+
var handlePress = react.useCallback(function (e, i) {
|
|
179
|
+
var _getLatest4 = getLatest(),
|
|
180
|
+
onDragStart = _getLatest4.onDragStart,
|
|
181
|
+
values = _getLatest4.values;
|
|
182
|
+
if (i === -1) {
|
|
183
|
+
var clientX = e.type === "touchmove" ?
|
|
184
|
+
// @ts-expect-error ignore
|
|
185
|
+
e.nativeEvent.changedTouches[0].clientX :
|
|
186
|
+
// @ts-expect-error ignore
|
|
187
|
+
e.nativeEvent.clientX;
|
|
188
|
+
var clientY = e.type === "touchmove" ?
|
|
189
|
+
// @ts-expect-error ignore
|
|
190
|
+
e.nativeEvent.changedTouches[0].clientY :
|
|
191
|
+
// @ts-expect-error ignore
|
|
192
|
+
e.nativeEvent.clientY;
|
|
193
|
+
setTempValues(values);
|
|
194
|
+
setSegmentStart([clientX, clientY]);
|
|
195
|
+
} else {
|
|
196
|
+
setActiveHandleIndex(i);
|
|
197
|
+
}
|
|
198
|
+
var handleRelease = function handleRelease(e) {
|
|
199
|
+
var _getLatest5 = getLatest(),
|
|
200
|
+
tempValues = _getLatest5.tempValues,
|
|
201
|
+
onChange = _getLatest5.onChange,
|
|
202
|
+
onDragEnd = _getLatest5.onDragEnd;
|
|
203
|
+
document.removeEventListener("mousemove", i === -1 ? handleSegmentDrag : handleDrag);
|
|
204
|
+
document.removeEventListener("touchmove", i === -1 ? handleSegmentDrag : handleDrag);
|
|
205
|
+
document.removeEventListener("mouseup", handleRelease, {
|
|
206
|
+
capture: true
|
|
207
|
+
});
|
|
208
|
+
document.removeEventListener("touchend", handleRelease, {
|
|
209
|
+
capture: true
|
|
210
|
+
});
|
|
211
|
+
var sortedValues = utils.sortNumList(tempValues || values);
|
|
212
|
+
onDragEnd === null || onDragEnd === void 0 || onDragEnd();
|
|
213
|
+
onChange === null || onChange === void 0 || onChange(sortedValues);
|
|
214
|
+
setActiveHandleIndex(undefined);
|
|
215
|
+
setSegmentStart(undefined);
|
|
216
|
+
setTempValues(undefined);
|
|
217
|
+
};
|
|
218
|
+
onDragStart === null || onDragStart === void 0 || onDragStart();
|
|
219
|
+
document.addEventListener("mousemove", i === -1 ? handleSegmentDrag : handleDrag);
|
|
220
|
+
document.addEventListener("touchmove", i === -1 ? handleSegmentDrag : handleDrag);
|
|
221
|
+
document.addEventListener("mouseup", handleRelease, {
|
|
222
|
+
capture: true
|
|
223
|
+
});
|
|
224
|
+
document.addEventListener("touchend", handleRelease, {
|
|
225
|
+
capture: true
|
|
226
|
+
});
|
|
227
|
+
}, [getLatest, handleDrag]);
|
|
228
|
+
var getPercentageForValue = react.useCallback(function (val) {
|
|
229
|
+
return utils.linearInterpolator.getPercentageForValue(val, min, max);
|
|
230
|
+
}, [max, min]);
|
|
231
|
+
var trackClicked = react.useCallback(function (e) {
|
|
232
|
+
var _getLatest6 = getLatest(),
|
|
233
|
+
onChange = _getLatest6.onChange,
|
|
234
|
+
values = _getLatest6.values;
|
|
235
|
+
var clientX = e.type === "touchmove" ?
|
|
236
|
+
// @ts-expect-error ignore
|
|
237
|
+
e.changedTouches[0].clientX :
|
|
238
|
+
// @ts-expect-error ignore
|
|
239
|
+
e.clientX;
|
|
240
|
+
var clientY = e.type === "touchmove" ?
|
|
241
|
+
// @ts-expect-error ignore
|
|
242
|
+
e.changedTouches[0].clientY :
|
|
243
|
+
// @ts-expect-error ignore
|
|
244
|
+
e.clientY;
|
|
245
|
+
var newValue = isVertical ? getValueForClientY(clientY) : getValueForClientX(clientX);
|
|
246
|
+
var newRoundedValue = roundToStep(newValue);
|
|
247
|
+
var newValues = [newRoundedValue];
|
|
248
|
+
if (values.length === 2) {
|
|
249
|
+
if (values[0] > newRoundedValue) newValues = [newRoundedValue, values[1]];else if (values[1] < newRoundedValue) newValues = [values[0], newRoundedValue];else {
|
|
250
|
+
var diff = (values[1] - values[0]) / 2;
|
|
251
|
+
if (values[0] + diff >= newRoundedValue) newValues = [newRoundedValue, values[1]];
|
|
252
|
+
if (values[1] - diff <= newRoundedValue) newValues = [values[0], newRoundedValue];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
onChange(newValues);
|
|
256
|
+
}, [getLatest, getValueForClientX, getValueForClientY, isVertical]);
|
|
257
|
+
react.useEffect(function () {
|
|
258
|
+
var _trackElRef$current;
|
|
259
|
+
(_trackElRef$current = trackElRef.current) === null || _trackElRef$current === void 0 || _trackElRef$current.addEventListener("mousedown", trackClicked);
|
|
260
|
+
}, [trackClicked]);
|
|
261
|
+
// Build the ticks
|
|
262
|
+
var ticks = react.useMemo(function () {
|
|
263
|
+
var ticks = controlledTicks !== null && controlledTicks !== void 0 ? controlledTicks : steps;
|
|
264
|
+
if (!ticks) {
|
|
265
|
+
ticks = [min];
|
|
266
|
+
var count = tickSize - tickSize % stepSize;
|
|
267
|
+
while (ticks[ticks.length - 1] < max - count) {
|
|
268
|
+
ticks.push(ticks[ticks.length - 1] + count);
|
|
269
|
+
}
|
|
270
|
+
ticks.push(max);
|
|
271
|
+
}
|
|
272
|
+
return ticks.map(function (value, i) {
|
|
273
|
+
return {
|
|
274
|
+
key: i,
|
|
275
|
+
value: value,
|
|
276
|
+
percentage: getPercentageForValue(value),
|
|
277
|
+
styles: _defineProperty(_defineProperty({}, positionProp, "".concat(getPercentageForValue(value), "%")), marginProp, "-0.125rem")
|
|
278
|
+
};
|
|
279
|
+
});
|
|
280
|
+
}, [controlledTicks, getPercentageForValue, max, min, steps, tickSize, positionProp, marginProp]);
|
|
281
|
+
var segments = react.useMemo(function () {
|
|
282
|
+
var sortedValues = utils.sortNumList(tempValues !== null && tempValues !== void 0 ? tempValues : values);
|
|
283
|
+
return [].concat(_toConsumableArray(sortedValues), [max]).map(function (value, i) {
|
|
284
|
+
var active = i === sortedValues.length - 1;
|
|
285
|
+
return {
|
|
286
|
+
key: i,
|
|
287
|
+
value: value,
|
|
288
|
+
active: active,
|
|
289
|
+
props: active ? {
|
|
290
|
+
ref: segmentElRef,
|
|
291
|
+
onMouseDownCapture: function onMouseDownCapture(e) {
|
|
292
|
+
e.stopPropagation();
|
|
293
|
+
e.persist();
|
|
294
|
+
handlePress(e, -1);
|
|
295
|
+
},
|
|
296
|
+
onTouchStartCapture: function onTouchStartCapture(e) {
|
|
297
|
+
e.stopPropagation();
|
|
298
|
+
e.persist();
|
|
299
|
+
handlePress(e, -1);
|
|
300
|
+
}
|
|
301
|
+
} : {},
|
|
302
|
+
styles: function () {
|
|
303
|
+
var left = getPercentageForValue(sortedValues[i - 1] ? sortedValues[i - 1] : min);
|
|
304
|
+
var width = getPercentageForValue(value) - left;
|
|
305
|
+
return _defineProperty(_defineProperty({}, positionProp, "".concat(left, "%")), isVertical ? "height" : "width", "".concat(width, "%"));
|
|
306
|
+
}()
|
|
307
|
+
};
|
|
308
|
+
});
|
|
309
|
+
}, [getPercentageForValue, max, min, tempValues, values, positionProp, marginProp]);
|
|
310
|
+
var handles = react.useMemo(function () {
|
|
311
|
+
return (tempValues !== null && tempValues !== void 0 ? tempValues : values).map(function (value, i) {
|
|
312
|
+
return {
|
|
313
|
+
key: i,
|
|
314
|
+
value: value,
|
|
315
|
+
percentage: getPercentageForValue(value),
|
|
316
|
+
active: i === activeHandleIndex,
|
|
317
|
+
props: {
|
|
318
|
+
role: "slider",
|
|
319
|
+
"aria-valuemin": min,
|
|
320
|
+
"aria-valuemax": max,
|
|
321
|
+
"aria-valuenow": value,
|
|
322
|
+
onKeyDown: function onKeyDown(e) {
|
|
323
|
+
e.stopPropagation();
|
|
324
|
+
e.persist();
|
|
325
|
+
handleKeyDown(e, i);
|
|
326
|
+
},
|
|
327
|
+
onMouseDownCapture: function onMouseDownCapture(e) {
|
|
328
|
+
e.stopPropagation();
|
|
329
|
+
e.persist();
|
|
330
|
+
handlePress(e, i);
|
|
331
|
+
},
|
|
332
|
+
onTouchStartCapture: function onTouchStartCapture(e) {
|
|
333
|
+
e.stopPropagation();
|
|
334
|
+
e.persist();
|
|
335
|
+
handlePress(e, i);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
styles: _defineProperty(_defineProperty({}, positionProp, "".concat(getPercentageForValue(value), "%")), marginProp, "-0.375rem"),
|
|
339
|
+
valueStyles: _defineProperty({}, positionProp, "".concat(getPercentageForValue(value), "%"))
|
|
340
|
+
};
|
|
341
|
+
});
|
|
342
|
+
}, [activeHandleIndex, getPercentageForValue, handleKeyDown, handlePress, min, max, tempValues, values, positionProp, marginProp]);
|
|
343
|
+
return {
|
|
344
|
+
trackElRef: trackElRef,
|
|
345
|
+
activeHandleIndex: activeHandleIndex,
|
|
346
|
+
ticks: ticks,
|
|
347
|
+
segments: segments,
|
|
348
|
+
handles: handles
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
exports.useRanger = useRanger;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* react-ranger
|
|
7
|
+
* https://github.com/TanStack/ranger
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var getBoundingClientRect = function getBoundingClientRect(element) {
|
|
11
|
+
var rect = element.getBoundingClientRect();
|
|
12
|
+
return {
|
|
13
|
+
top: Math.ceil(rect.top),
|
|
14
|
+
left: Math.ceil(rect.left),
|
|
15
|
+
right: Math.ceil(rect.right),
|
|
16
|
+
width: Math.ceil(rect.width),
|
|
17
|
+
bottom: Math.ceil(rect.bottom),
|
|
18
|
+
height: Math.ceil(rect.height)
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var sortNumList = function sortNumList(arr) {
|
|
22
|
+
return _toConsumableArray(arr).map(Number).sort(function (a, b) {
|
|
23
|
+
return a - b;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var linearInterpolator = {
|
|
27
|
+
getPercentageForValue: function getPercentageForValue(val, min, max) {
|
|
28
|
+
return Math.max(0, Math.min(100, (val - min) / (max - min) * 100));
|
|
29
|
+
},
|
|
30
|
+
getValueForClientX: function getValueForClientX(clientX, trackDims, min, max, isRtl) {
|
|
31
|
+
var left = trackDims.left,
|
|
32
|
+
right = trackDims.right,
|
|
33
|
+
width = trackDims.width;
|
|
34
|
+
var percentageValue = (isRtl ? right - clientX : clientX - left) / width;
|
|
35
|
+
var value = (max - min) * percentageValue;
|
|
36
|
+
return value + min;
|
|
37
|
+
},
|
|
38
|
+
getValueForClientY: function getValueForClientY(clientY, trackDims, min, max) {
|
|
39
|
+
var height = trackDims.height,
|
|
40
|
+
bottom = trackDims.bottom;
|
|
41
|
+
var percentageValue = (bottom - clientY) / height;
|
|
42
|
+
var value = (max - min) * percentageValue;
|
|
43
|
+
return value + min;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.getBoundingClientRect = getBoundingClientRect;
|
|
48
|
+
exports.linearInterpolator = linearInterpolator;
|
|
49
|
+
exports.sortNumList = sortNumList;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
5
|
+
var react$1 = require('@floating-ui/react');
|
|
6
|
+
var core = require('@react-fabric/core');
|
|
7
|
+
var utilities = require('@react-fabric/utilities');
|
|
8
|
+
var classNames = require('classnames');
|
|
9
|
+
var react = require('react');
|
|
10
|
+
var InputWrapper = require('../internal/InputWrapper.js');
|
|
11
|
+
var Options = require('./Options.js');
|
|
12
|
+
var useSelect = require('./useSelect.js');
|
|
13
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
+
|
|
15
|
+
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "expandOnEdit", "error", "history", "multiple", "onChange", "onSelect", "onInput", "onFocus", "onBlur", "onEnterPressed"];
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
var AutoComplete = function AutoComplete(_ref) {
|
|
19
|
+
var _refs$reference$curre;
|
|
20
|
+
_ref.ref;
|
|
21
|
+
var name = _ref.name,
|
|
22
|
+
value = _ref.value,
|
|
23
|
+
invalid = _ref.invalid,
|
|
24
|
+
readOnly = _ref.readOnly,
|
|
25
|
+
disabled = _ref.disabled,
|
|
26
|
+
required = _ref.required,
|
|
27
|
+
placeholder = _ref.placeholder;
|
|
28
|
+
_ref.autoFocus;
|
|
29
|
+
var expandOnEdit = _ref.expandOnEdit,
|
|
30
|
+
error = _ref.error,
|
|
31
|
+
history = _ref.history,
|
|
32
|
+
multiple = _ref.multiple,
|
|
33
|
+
onChange = _ref.onChange,
|
|
34
|
+
onSelect = _ref.onSelect,
|
|
35
|
+
onInput = _ref.onInput,
|
|
36
|
+
onFocus = _ref.onFocus,
|
|
37
|
+
_onBlur = _ref.onBlur,
|
|
38
|
+
onEnterPressed = _ref.onEnterPressed,
|
|
39
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
var options = react.useRef(history);
|
|
41
|
+
var submitRef = react.useRef(null);
|
|
42
|
+
var _useSelect = useSelect.useSelect({
|
|
43
|
+
value: value,
|
|
44
|
+
autoComplete: true,
|
|
45
|
+
options: options.current,
|
|
46
|
+
multiple: multiple,
|
|
47
|
+
onChange: onChange,
|
|
48
|
+
onSelect: onSelect
|
|
49
|
+
}),
|
|
50
|
+
state = _useSelect.state,
|
|
51
|
+
listRef = _useSelect.listRef,
|
|
52
|
+
listContentRef = _useSelect.listContentRef,
|
|
53
|
+
setOpen = _useSelect.setOpen,
|
|
54
|
+
macthOption = _useSelect.macthOption,
|
|
55
|
+
handleChange = _useSelect.handleChange,
|
|
56
|
+
handleRemove = _useSelect.handleRemove,
|
|
57
|
+
handleQuery = _useSelect.handleQuery,
|
|
58
|
+
setItemRef = _useSelect.setItemRef,
|
|
59
|
+
setActiveIndex = _useSelect.setActiveIndex;
|
|
60
|
+
var dropdownKey = react.useId();
|
|
61
|
+
var _useFloating = react$1.useFloating({
|
|
62
|
+
open: state.open,
|
|
63
|
+
onOpenChange: function onOpenChange(open, evt, reason) {
|
|
64
|
+
!open && (listRef.current = []);
|
|
65
|
+
setOpen(open);
|
|
66
|
+
},
|
|
67
|
+
strategy: "fixed",
|
|
68
|
+
placement: "bottom",
|
|
69
|
+
whileElementsMounted: react$1.autoUpdate,
|
|
70
|
+
middleware: [react$1.shift({
|
|
71
|
+
padding: 8
|
|
72
|
+
}), react$1.flip(), react$1.offset(2)]
|
|
73
|
+
}),
|
|
74
|
+
context = _useFloating.context,
|
|
75
|
+
floatingStyles = _useFloating.floatingStyles,
|
|
76
|
+
refs = _useFloating.refs;
|
|
77
|
+
|
|
78
|
+
// floating interactions
|
|
79
|
+
var dismiss = react$1.useDismiss(context, {
|
|
80
|
+
// referencePress: true,
|
|
81
|
+
});
|
|
82
|
+
var navigation = react$1.useListNavigation(context, {
|
|
83
|
+
listRef: listRef,
|
|
84
|
+
activeIndex: state.activeIndex,
|
|
85
|
+
selectedIndex: state.selectedIndex,
|
|
86
|
+
loop: true,
|
|
87
|
+
virtual: true,
|
|
88
|
+
focusItemOnOpen: false,
|
|
89
|
+
onNavigate: setActiveIndex
|
|
90
|
+
});
|
|
91
|
+
var typeahead = react$1.useTypeahead(context, {
|
|
92
|
+
listRef: listContentRef,
|
|
93
|
+
activeIndex: state.activeIndex,
|
|
94
|
+
selectedIndex: state.selectedIndex,
|
|
95
|
+
findMatch: function findMatch(list, typedString) {
|
|
96
|
+
return list.find(function (item) {
|
|
97
|
+
return macthOption(item, typedString);
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
onMatch: function onMatch(index) {
|
|
101
|
+
state.open && setActiveIndex(index);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
var _useInteractions = react$1.useInteractions([dismiss, navigation, typeahead]),
|
|
105
|
+
getReferenceProps = _useInteractions.getReferenceProps,
|
|
106
|
+
getFloatingProps = _useInteractions.getFloatingProps,
|
|
107
|
+
getItemProps = _useInteractions.getItemProps;
|
|
108
|
+
var referenceProps = react.useMemo(function () {
|
|
109
|
+
var props = getReferenceProps();
|
|
110
|
+
return _objectSpread(_objectSpread({}, props), {}, {
|
|
111
|
+
onFocus: onFocus,
|
|
112
|
+
onBlur: function onBlur(evt) {
|
|
113
|
+
var _evt$relatedTarget;
|
|
114
|
+
if ((_evt$relatedTarget = evt.relatedTarget) !== null && _evt$relatedTarget !== void 0 && _evt$relatedTarget.closest("[data-select-dropdown=\"".concat(dropdownKey, "\"]"))) {
|
|
115
|
+
var _refs$domReference$cu;
|
|
116
|
+
(_refs$domReference$cu = refs.domReference.current) === null || _refs$domReference$cu === void 0 || (_refs$domReference$cu = _refs$domReference$cu.querySelector("input")) === null || _refs$domReference$cu === void 0 || _refs$domReference$cu.focus();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
state.open && handleChange(state.query);
|
|
120
|
+
handleQuery("");
|
|
121
|
+
setOpen(false);
|
|
122
|
+
_onBlur === null || _onBlur === void 0 || _onBlur(evt);
|
|
123
|
+
},
|
|
124
|
+
onKeyDown: function onKeyDown(evt) {
|
|
125
|
+
if (evt.key === "Enter") {
|
|
126
|
+
evt.preventDefault();
|
|
127
|
+
if (state.activeIndex !== null) {
|
|
128
|
+
handleChange(listContentRef.current[state.activeIndex]);
|
|
129
|
+
evt.stopPropagation();
|
|
130
|
+
return false;
|
|
131
|
+
} else if (state.query !== undefined) {
|
|
132
|
+
handleChange("");
|
|
133
|
+
return false;
|
|
134
|
+
} else {
|
|
135
|
+
var _submitRef$current;
|
|
136
|
+
onEnterPressed === null || onEnterPressed === void 0 || onEnterPressed(evt);
|
|
137
|
+
(_submitRef$current = submitRef.current) === null || _submitRef$current === void 0 || _submitRef$current.click();
|
|
138
|
+
}
|
|
139
|
+
} else if (evt.key === "Backspace") {
|
|
140
|
+
!state.query && multiple && handleRemove();
|
|
141
|
+
} else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
|
|
142
|
+
if (["ArrowUp", "ArrowDown"].includes(evt.key) && state.activeIndex === null) {
|
|
143
|
+
setActiveIndex(state.selectedIndex);
|
|
144
|
+
}
|
|
145
|
+
setTimeout(function () {
|
|
146
|
+
var _props$onKeyDown;
|
|
147
|
+
(_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 || _props$onKeyDown.call(props, evt);
|
|
148
|
+
}, 50);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}, [getReferenceProps, onEnterPressed, handleQuery, onFocus, _onBlur, multiple, refs, state.query, state.activeIndex]);
|
|
153
|
+
var floatingProps = react.useMemo(function () {
|
|
154
|
+
return getFloatingProps({
|
|
155
|
+
"data-select-dropdown": dropdownKey
|
|
156
|
+
});
|
|
157
|
+
}, [getFloatingProps]);
|
|
158
|
+
var makeItemProps = react.useCallback(function (item) {
|
|
159
|
+
var _state$value, _state$value$includes;
|
|
160
|
+
var selected = utilities.isArray(state.value) ? (_state$value = state.value) === null || _state$value === void 0 || (_state$value$includes = _state$value.includes) === null || _state$value$includes === void 0 ? void 0 : _state$value$includes.call(_state$value, item) : state.value === item;
|
|
161
|
+
return getItemProps({
|
|
162
|
+
"data-selected": selected ? true : undefined,
|
|
163
|
+
onClick: function onClick() {
|
|
164
|
+
handleChange(item);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}, [getItemProps, handleChange, state.value]);
|
|
168
|
+
var displayValue = react.useMemo(function () {
|
|
169
|
+
if (utilities.isArray(state.value)) {
|
|
170
|
+
return state.value.map(function (item, index) {
|
|
171
|
+
return /*#__PURE__*/jsxRuntime.jsx(core.Chip, {
|
|
172
|
+
onRemove: function onRemove() {
|
|
173
|
+
return handleRemove(index);
|
|
174
|
+
},
|
|
175
|
+
children: item
|
|
176
|
+
}, index);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}, [state.value, state.query, placeholder]);
|
|
180
|
+
react.useLayoutEffect(function () {
|
|
181
|
+
state.open && setTimeout(function () {
|
|
182
|
+
var _listRef$current$stat;
|
|
183
|
+
state.selectedIndex && ((_listRef$current$stat = listRef.current[state.selectedIndex]) === null || _listRef$current$stat === void 0 ? void 0 : _listRef$current$stat.scrollIntoView({
|
|
184
|
+
block: "center"
|
|
185
|
+
}));
|
|
186
|
+
}, 100);
|
|
187
|
+
}, [state.open]);
|
|
188
|
+
var inputValue = react.useMemo(function () {
|
|
189
|
+
var _state$query, _ref2, _state$query2;
|
|
190
|
+
if (multiple) return (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "";
|
|
191
|
+
return (_ref2 = (_state$query2 = state.query) !== null && _state$query2 !== void 0 ? _state$query2 : state.value) !== null && _ref2 !== void 0 ? _ref2 : "";
|
|
192
|
+
}, [multiple, state.query, state.value]);
|
|
193
|
+
return /*#__PURE__*/jsxRuntime.jsxs(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
194
|
+
showClear: !utilities.isEmpty(state.value),
|
|
195
|
+
onClear: handleChange,
|
|
196
|
+
invalid: invalid,
|
|
197
|
+
readOnly: readOnly,
|
|
198
|
+
disabled: disabled,
|
|
199
|
+
required: required,
|
|
200
|
+
error: error,
|
|
201
|
+
wrapperRef: refs.setReference,
|
|
202
|
+
className: !multiple && expandOnEdit && state.open ? "!z-[99]" : "",
|
|
203
|
+
floatingExpand: !multiple && expandOnEdit && state.open
|
|
204
|
+
}, rest), {}, {
|
|
205
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
206
|
+
role: "none",
|
|
207
|
+
"data-select-display": "true",
|
|
208
|
+
className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden"),
|
|
209
|
+
onMouseUp: function onMouseUp(e) {
|
|
210
|
+
var _e$currentTarget$quer;
|
|
211
|
+
return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
|
|
212
|
+
},
|
|
213
|
+
children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("textarea", _objectSpread(_objectSpread({
|
|
214
|
+
readOnly: readOnly,
|
|
215
|
+
disabled: disabled,
|
|
216
|
+
value: inputValue,
|
|
217
|
+
"aria-invalid": invalid,
|
|
218
|
+
"data-testid": name,
|
|
219
|
+
name: name,
|
|
220
|
+
size: 1,
|
|
221
|
+
onInput: onInput,
|
|
222
|
+
rows: !multiple && expandOnEdit && state.open ? 5 : 1,
|
|
223
|
+
className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 resize-none", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24 overflow-hidden", !state.open && "overflow-hidden whitespace-nowrap"),
|
|
224
|
+
placeholder: utilities.isEmpty(state.value) ? placeholder : ""
|
|
225
|
+
}, referenceProps), {}, {
|
|
226
|
+
onChange: function onChange(evt) {
|
|
227
|
+
return handleQuery(evt.target.value);
|
|
228
|
+
}
|
|
229
|
+
})), /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
230
|
+
type: "submit",
|
|
231
|
+
ref: submitRef,
|
|
232
|
+
tabIndex: -1,
|
|
233
|
+
className: "opacity-0 absolute"
|
|
234
|
+
})]
|
|
235
|
+
}), state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
236
|
+
animate: "spin",
|
|
237
|
+
className: classNames("flex-content p-2 z-0 order-9 text-muted pointer-events-none"),
|
|
238
|
+
icon: core.CoreIcons.spinner
|
|
239
|
+
}), state.open && !state.loading && /*#__PURE__*/jsxRuntime.jsx(react$1.FloatingPortal, {
|
|
240
|
+
children: /*#__PURE__*/jsxRuntime.jsx(react$1.FloatingFocusManager, {
|
|
241
|
+
context: context,
|
|
242
|
+
initialFocus: -1,
|
|
243
|
+
visuallyHiddenDismiss: true,
|
|
244
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Options.Options, _objectSpread(_objectSpread({
|
|
245
|
+
ref: refs.setFloating,
|
|
246
|
+
className: "outline shadow-lg max-h-[40vh] z-[var(--z-popover)]",
|
|
247
|
+
style: _objectSpread({
|
|
248
|
+
width: (_refs$reference$curre = refs.reference.current) === null || _refs$reference$curre === void 0 ? void 0 : _refs$reference$curre.getBoundingClientRect().width
|
|
249
|
+
}, floatingStyles)
|
|
250
|
+
}, floatingProps), {}, {
|
|
251
|
+
items: state.items,
|
|
252
|
+
active: state.activeIndex,
|
|
253
|
+
itemRef: setItemRef,
|
|
254
|
+
itemProps: makeItemProps,
|
|
255
|
+
empty: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
256
|
+
className: "text-muted text-sm px-2 py-1",
|
|
257
|
+
children: "No history available"
|
|
258
|
+
}),
|
|
259
|
+
children: function children(item) {
|
|
260
|
+
return item;
|
|
261
|
+
}
|
|
262
|
+
}))
|
|
263
|
+
})
|
|
264
|
+
})]
|
|
265
|
+
}));
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
exports.AutoComplete = AutoComplete;
|