xmlui 0.9.10 → 0.9.12
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/{apiInterceptorWorker-BJYj3y8V.mjs → apiInterceptorWorker-dYrfbzdh.mjs} +1 -1
- package/dist/{index-6PAZN2xn.mjs → index-Dh2MThrK.mjs} +2127 -2300
- package/dist/index.css +112 -198
- package/dist/language-server-web-worker.mjs +1 -1
- package/dist/language-server.mjs +1 -1
- package/dist/{lint-DmJOJSJa.mjs → lint-Cd70ckJ6.mjs} +1 -11
- package/dist/{parser-B3m9ZEAK.mjs → parser-CBXS8ft2.mjs} +7 -5
- package/dist/scripts/bin/build-lib.js +42 -1
- package/dist/scripts/bin/vite-xmlui-plugin.js +2 -22
- package/dist/scripts/bin/viteConfig.js +3 -1
- package/dist/scripts/src/abstractions/ComponentDefs.js +2 -20
- package/dist/scripts/src/components/App/App.js +61 -21
- package/dist/scripts/src/components/Button/Button.js +5 -1
- package/dist/scripts/src/components/Button/ButtonNative.js +9 -2
- package/dist/scripts/src/components/Checkbox/Checkbox.js +2 -2
- package/dist/scripts/src/components/ComponentProvider.js +2 -0
- package/dist/scripts/src/components/Footer/Footer.js +1 -1
- package/dist/scripts/src/components/Form/FormContext.js +2 -0
- package/dist/scripts/src/components/FormItem/FormItemNative.js +9 -0
- package/dist/scripts/src/components/Items/Items.js +2 -1
- package/dist/scripts/src/components/List/List.js +2 -1
- package/dist/scripts/src/components/Markdown/Markdown.js +2 -0
- package/dist/scripts/src/components/NavPanel/NavPanel.js +2 -2
- package/dist/scripts/src/components/NumberBox/NumberBox2.js +85 -0
- package/dist/scripts/src/components/NumberBox/NumberBox2Native.js +395 -0
- package/dist/scripts/src/components/NumberBox/numberbox-abstractions.js +35 -0
- package/dist/scripts/src/components/Option/Option.js +2 -1
- package/dist/scripts/src/components/Select/Select.js +8 -0
- package/dist/scripts/src/components/Select/SelectNative.js +24 -10
- package/dist/scripts/src/components/Theme/ThemeNative.js +1 -0
- package/dist/scripts/src/components/VisuallyHidden.js +21 -0
- package/dist/scripts/src/components-core/InspectorContext.js +15 -4
- package/dist/scripts/src/components-core/loader/DataLoader.js +110 -3
- package/dist/scripts/src/components-core/loader/Loader.js +29 -7
- package/dist/scripts/src/components-core/rendering/ComponentAdapter.js +4 -1
- package/dist/scripts/src/components-core/rendering/ComponentWrapper.js +23 -5
- package/dist/scripts/src/components-core/rendering/Container.js +23 -26
- package/dist/scripts/src/components-core/rendering/StateContainer.js +2 -4
- package/dist/scripts/src/components-core/rendering/reducer.js +6 -5
- package/dist/scripts/src/components-core/utils/extractParam.js +24 -7
- package/dist/scripts/src/components-core/xmlui-parser.js +1 -1
- package/dist/scripts/src/parsers/xmlui-parser/parser.js +1 -1
- package/dist/scripts/src/parsers/xmlui-parser/transform.js +0 -10
- package/dist/scripts/src/parsers/xmlui-parser/utils.js +6 -9
- package/dist/{server-common-oCD2CuF9.mjs → server-common-DW5h7Q34.mjs} +122 -64
- package/dist/style.css +112 -98
- package/dist/xmlui-metadata.mjs +688 -229
- package/dist/xmlui-metadata.umd.js +687 -230
- package/dist/xmlui-parser.d.ts +14 -9
- package/dist/xmlui-parser.mjs +3 -3
- package/dist/xmlui-standalone.umd.js +4483 -7327
- package/dist/xmlui.d.ts +14 -1
- package/dist/xmlui.mjs +2 -1
- package/package.json +6 -4
- package/dist/scripts/src/components-core/devtools/DevTools.js +0 -225
- package/dist/scripts/src/syntax/monaco/grammar.monacoLanguage.js +0 -286
- package/dist/scripts/src/syntax/monaco/xmlui-dark.js +0 -27
- package/dist/scripts/src/syntax/monaco/xmlui-light.js +0 -26
- package/dist/scripts/src/syntax/monaco/xmluiscript.monacoLanguage.js +0 -310
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.NumberBox2 = void 0;
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const react_1 = __importStar(require("react"));
|
|
42
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
43
|
+
const NumberBox_module_scss_1 = __importDefault(require("./NumberBox.module.scss"));
|
|
44
|
+
const constants_1 = require("../../components-core/constants");
|
|
45
|
+
const misc_1 = require("../../components-core/utils/misc");
|
|
46
|
+
const numberbox_abstractions_1 = require("./numberbox-abstractions");
|
|
47
|
+
const IconNative_1 = require("../Icon/IconNative");
|
|
48
|
+
const InputAdornment_1 = require("../Input/InputAdornment");
|
|
49
|
+
const ButtonNative_1 = require("../Button/ButtonNative");
|
|
50
|
+
const ItemWithLabel_1 = require("../FormItem/ItemWithLabel");
|
|
51
|
+
const lodash_es_1 = require("lodash-es");
|
|
52
|
+
const number_1 = require("@internationalized/number");
|
|
53
|
+
exports.NumberBox2 = (0, react_1.forwardRef)(function NumberBox2({ id, style, value, initialValue, zeroOrPositive = false, min = zeroOrPositive ? 0 : -numberbox_abstractions_1.NUMBERBOX_MAX_VALUE, max = numberbox_abstractions_1.NUMBERBOX_MAX_VALUE, maxFractionDigits = 3, enabled = true, placeholder, step, integersOnly = false, validationStatus = "none", hasSpinBox = true, updateState = constants_1.noop, onDidChange = constants_1.noop, onFocus = constants_1.noop, onBlur = constants_1.noop, registerComponentApi, startText, startIcon, endText, endIcon, autoFocus, readOnly, required, label, labelPosition, labelWidth, labelBreak, }, forwardedRef) {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
56
|
+
const upButton = (0, react_1.useRef)(null);
|
|
57
|
+
const downButton = (0, react_1.useRef)(null);
|
|
58
|
+
// Formatter & Parser
|
|
59
|
+
const locale = "en-US";
|
|
60
|
+
const formatOptions = (0, react_1.useMemo)(() => {
|
|
61
|
+
return {
|
|
62
|
+
useGrouping: false,
|
|
63
|
+
minimumFractionDigits: 0,
|
|
64
|
+
maximumFractionDigits: integersOnly ? 0 : maxFractionDigits,
|
|
65
|
+
};
|
|
66
|
+
}, [maxFractionDigits, integersOnly]);
|
|
67
|
+
const formatter = useNumberFormatter(locale, formatOptions);
|
|
68
|
+
const parser = useNumberParser(locale, formatOptions);
|
|
69
|
+
min = (0, numberbox_abstractions_1.clamp)((_a = (0, numberbox_abstractions_1.toUsableNumber)(min, true)) !== null && _a !== void 0 ? _a : (zeroOrPositive ? 0 : -numberbox_abstractions_1.NUMBERBOX_MAX_VALUE), (zeroOrPositive ? 0 : -numberbox_abstractions_1.NUMBERBOX_MAX_VALUE), numberbox_abstractions_1.NUMBERBOX_MAX_VALUE);
|
|
70
|
+
max = (0, numberbox_abstractions_1.clamp)((_b = (0, numberbox_abstractions_1.toUsableNumber)(max, true)) !== null && _b !== void 0 ? _b : (zeroOrPositive ? 0 : -numberbox_abstractions_1.NUMBERBOX_MAX_VALUE), (zeroOrPositive ? 0 : -numberbox_abstractions_1.NUMBERBOX_MAX_VALUE), numberbox_abstractions_1.NUMBERBOX_MAX_VALUE);
|
|
71
|
+
const initializeValue = (0, react_1.useCallback)((value, defaultValue = "") => {
|
|
72
|
+
return (0, numberbox_abstractions_1.isEmptyLike)(value) || (0, lodash_es_1.isNaN)(parser.parse(value.toString()))
|
|
73
|
+
? defaultValue
|
|
74
|
+
: formatter.format((0, numberbox_abstractions_1.clamp)(+value, min, max));
|
|
75
|
+
}, [formatter, parser, min, max]);
|
|
76
|
+
// --- Convert to representable string value (from number | null | undefined)
|
|
77
|
+
const [valueStrRep, setValueStrRep] = react_1.default.useState(initializeValue(value));
|
|
78
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
79
|
+
setValueStrRep(initializeValue(value));
|
|
80
|
+
}, [value, initializeValue]);
|
|
81
|
+
const onFixCursorPosition = useCursorCorrection(valueStrRep, inputRef);
|
|
82
|
+
const _step = (_c = (0, numberbox_abstractions_1.toUsableNumber)(step, true)) !== null && _c !== void 0 ? _c : numberbox_abstractions_1.DEFAULT_STEP;
|
|
83
|
+
const inputMode = (0, react_1.useMemo)(() => {
|
|
84
|
+
// The inputMode attribute influences the software keyboard that is shown on touch devices.
|
|
85
|
+
// Browsers and operating systems are quite inconsistent about what keys are available.
|
|
86
|
+
// We choose between numeric and decimal based on whether we allow negative and fractional numbers,
|
|
87
|
+
// and based on testing on various devices to determine what keys are available in each inputMode.
|
|
88
|
+
const hasDecimals = formatter.resolvedOptions().maximumFractionDigits > 0;
|
|
89
|
+
return hasDecimals ? "decimal" : "numeric";
|
|
90
|
+
}, [formatter]);
|
|
91
|
+
// --- Initialize the related field with the input's initial value
|
|
92
|
+
(0, react_1.useEffect)(() => {
|
|
93
|
+
updateState({ value: initialValue }, { initial: true });
|
|
94
|
+
}, [initialValue, updateState]);
|
|
95
|
+
const clampInputValue = (0, react_1.useCallback)((value) => {
|
|
96
|
+
return (0, numberbox_abstractions_1.clamp)(value, min, max);
|
|
97
|
+
}, [min, max]);
|
|
98
|
+
const clampAndSaveInput = (0, react_1.useCallback)((value) => {
|
|
99
|
+
if ((0, numberbox_abstractions_1.isEmptyLike)(value)) {
|
|
100
|
+
updateState({ value: null });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
value = value.toString();
|
|
104
|
+
// Set to empty state if input value is empty
|
|
105
|
+
if (!value.length) {
|
|
106
|
+
updateState({ value: null });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let parsedValue = parser.parse(value);
|
|
110
|
+
parsedValue = clampInputValue(parsedValue);
|
|
111
|
+
// if it failed to parse, then reset input to formatted version of current number
|
|
112
|
+
if ((0, lodash_es_1.isNaN)(parsedValue)) {
|
|
113
|
+
updateState({ value });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
// value representation needs to be synchronized with the last parsed value
|
|
117
|
+
setValueStrRep((lastVal) => {
|
|
118
|
+
const formatted = formatter.format(parsedValue);
|
|
119
|
+
if (lastVal !== formatted) {
|
|
120
|
+
return formatted;
|
|
121
|
+
}
|
|
122
|
+
return lastVal;
|
|
123
|
+
});
|
|
124
|
+
updateState({ value: parsedValue });
|
|
125
|
+
}, [clampInputValue, updateState, parser, formatter]);
|
|
126
|
+
// --- Stepper logic
|
|
127
|
+
const increment = (0, react_1.useCallback)(() => {
|
|
128
|
+
if (!enabled)
|
|
129
|
+
return;
|
|
130
|
+
if (readOnly)
|
|
131
|
+
return;
|
|
132
|
+
const currentValue = (0, numberbox_abstractions_1.isEmptyLike)(value) || (0, lodash_es_1.isNaN)(value) ? "0" : value.toString();
|
|
133
|
+
const newValue = handleChangingValue(currentValue, parser, "increase", _step, min, max);
|
|
134
|
+
updateState({ value: newValue });
|
|
135
|
+
}, [value, enabled, readOnly, parser, _step, min, max, updateState]);
|
|
136
|
+
const decrement = (0, react_1.useCallback)(() => {
|
|
137
|
+
if (!enabled)
|
|
138
|
+
return;
|
|
139
|
+
if (readOnly)
|
|
140
|
+
return;
|
|
141
|
+
const currentValue = (0, numberbox_abstractions_1.isEmptyLike)(value) || (0, lodash_es_1.isNaN)(value) ? "0" : value.toString();
|
|
142
|
+
const newValue = handleChangingValue(currentValue, parser, "decrease", _step, min, max);
|
|
143
|
+
updateState({ value: newValue });
|
|
144
|
+
}, [value, enabled, readOnly, parser, _step, min, max, updateState]);
|
|
145
|
+
// --- Register stepper logic to buttons
|
|
146
|
+
useLongPress(upButton.current, increment);
|
|
147
|
+
useLongPress(downButton.current, decrement);
|
|
148
|
+
// --- Handle input
|
|
149
|
+
const _onBeforeInput = (0, react_1.useCallback)((event) => {
|
|
150
|
+
var _a, _b, _c;
|
|
151
|
+
const target = event.target;
|
|
152
|
+
const nextValue = parser.parse(target.value.slice(0, (_a = target.selectionStart) !== null && _a !== void 0 ? _a : undefined) +
|
|
153
|
+
((_b = event.nativeEvent.data) !== null && _b !== void 0 ? _b : "") +
|
|
154
|
+
target.value.slice((_c = target.selectionEnd) !== null && _c !== void 0 ? _c : undefined)).toString();
|
|
155
|
+
// pre-validate
|
|
156
|
+
if (!parser.isValidPartialNumber(nextValue, min, max)) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
}
|
|
159
|
+
}, [parser, min, max]);
|
|
160
|
+
const _onChange = (0, react_1.useCallback)((event) => {
|
|
161
|
+
const strValue = event.target.value;
|
|
162
|
+
let parsed = clampInputValue(parser.parse(event.target.value));
|
|
163
|
+
if (integersOnly && Number.isInteger(parsed)) {
|
|
164
|
+
parsed = Math.trunc(parsed);
|
|
165
|
+
}
|
|
166
|
+
// NOTE: This is the most important part.
|
|
167
|
+
// We only synchronize values when they are a valid number
|
|
168
|
+
// Otherwise we only update the local string representation and
|
|
169
|
+
// synchronize the value from state when the input is blurred.
|
|
170
|
+
if (canSynchronizeValue(strValue, locale, formatOptions)) {
|
|
171
|
+
updateState({ value: parsed });
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
setValueStrRep(strValue);
|
|
175
|
+
}
|
|
176
|
+
// TODO: this needs to be adjusted based on the number of group separators (no group separators yet)
|
|
177
|
+
onFixCursorPosition(event);
|
|
178
|
+
onDidChange(parsed);
|
|
179
|
+
}, [
|
|
180
|
+
clampInputValue,
|
|
181
|
+
parser,
|
|
182
|
+
onDidChange,
|
|
183
|
+
locale,
|
|
184
|
+
formatOptions,
|
|
185
|
+
onFixCursorPosition,
|
|
186
|
+
updateState,
|
|
187
|
+
integersOnly,
|
|
188
|
+
]);
|
|
189
|
+
const _onFocus = (0, react_1.useCallback)(() => {
|
|
190
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
191
|
+
}, [onFocus]);
|
|
192
|
+
const _onBlur = (0, react_1.useCallback)((event) => {
|
|
193
|
+
const value = event.target.value;
|
|
194
|
+
clampAndSaveInput(value);
|
|
195
|
+
onBlur();
|
|
196
|
+
}, [clampAndSaveInput, onBlur]);
|
|
197
|
+
const _onKeyDown = (0, react_1.useCallback)((event) => {
|
|
198
|
+
if (event.key === "Enter") {
|
|
199
|
+
clampAndSaveInput(value);
|
|
200
|
+
}
|
|
201
|
+
if (event.code === "ArrowUp") {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
increment();
|
|
204
|
+
}
|
|
205
|
+
if (event.code === "ArrowDown") {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
decrement();
|
|
208
|
+
}
|
|
209
|
+
}, [clampAndSaveInput, increment, decrement, value]);
|
|
210
|
+
// --- Register API events
|
|
211
|
+
const focus = (0, react_1.useCallback)(() => {
|
|
212
|
+
var _a;
|
|
213
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
214
|
+
}, []);
|
|
215
|
+
(0, react_1.useEffect)(() => {
|
|
216
|
+
if (autoFocus) {
|
|
217
|
+
setTimeout(() => {
|
|
218
|
+
var _a;
|
|
219
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
220
|
+
}, 0);
|
|
221
|
+
}
|
|
222
|
+
}, [autoFocus]);
|
|
223
|
+
const setValue = (0, misc_1.useEvent)((newValue) => {
|
|
224
|
+
updateState({ value: newValue });
|
|
225
|
+
});
|
|
226
|
+
(0, react_1.useEffect)(() => {
|
|
227
|
+
registerComponentApi === null || registerComponentApi === void 0 ? void 0 : registerComponentApi({
|
|
228
|
+
focus,
|
|
229
|
+
setValue,
|
|
230
|
+
});
|
|
231
|
+
}, [focus, registerComponentApi, setValue]);
|
|
232
|
+
return ((0, jsx_runtime_1.jsx)(ItemWithLabel_1.ItemWithLabel, { ref: forwardedRef, labelPosition: labelPosition, label: label, labelWidth: labelWidth, labelBreak: labelBreak, required: required, enabled: enabled, onFocus: onFocus, onBlur: onBlur, style: style, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)(NumberBox_module_scss_1.default.inputRoot, {
|
|
233
|
+
[NumberBox_module_scss_1.default.readOnly]: readOnly,
|
|
234
|
+
[NumberBox_module_scss_1.default.disabled]: !enabled,
|
|
235
|
+
[NumberBox_module_scss_1.default.noSpinBox]: !hasSpinBox,
|
|
236
|
+
[NumberBox_module_scss_1.default.error]: validationStatus === "error",
|
|
237
|
+
[NumberBox_module_scss_1.default.warning]: validationStatus === "warning",
|
|
238
|
+
[NumberBox_module_scss_1.default.valid]: validationStatus === "valid",
|
|
239
|
+
}), tabIndex: -1, onFocus: () => {
|
|
240
|
+
var _a;
|
|
241
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
242
|
+
}, children: [(0, jsx_runtime_1.jsx)(InputAdornment_1.Adornment, { text: startText, iconName: startIcon, className: NumberBox_module_scss_1.default.adornment }), (0, jsx_runtime_1.jsx)("input", { id: id, ref: inputRef, type: "text", placeholder: placeholder, required: required, readOnly: readOnly, disabled: !enabled, inputMode: inputMode, className: (0, classnames_1.default)(NumberBox_module_scss_1.default.input), value: valueStrRep, min: min, max: max, autoFocus: autoFocus, onBeforeInput: _onBeforeInput, onChange: _onChange, onFocus: _onFocus, onBlur: _onBlur, onKeyDown: _onKeyDown }), (0, jsx_runtime_1.jsx)(InputAdornment_1.Adornment, { text: endText, iconName: endIcon, className: NumberBox_module_scss_1.default.adornment }), hasSpinBox && ((0, jsx_runtime_1.jsxs)("div", { className: NumberBox_module_scss_1.default.spinnerBox, children: [(0, jsx_runtime_1.jsx)(ButtonNative_1.Button, { "data-spinner": "up", type: "button", variant: "ghost", themeColor: "secondary", tabIndex: -1, className: NumberBox_module_scss_1.default.spinnerButton, disabled: !enabled || readOnly, ref: upButton, children: (0, jsx_runtime_1.jsx)(IconNative_1.Icon, { name: "chevronup", size: "sm" }) }), (0, jsx_runtime_1.jsx)(ButtonNative_1.Button, { "data-spinner": "down", type: "button", tabIndex: -1, variant: "ghost", themeColor: "secondary", className: NumberBox_module_scss_1.default.spinnerButton, disabled: !enabled || readOnly, ref: downButton, children: (0, jsx_runtime_1.jsx)(IconNative_1.Icon, { name: "chevrondown", size: "sm" }) })] }))] }) }));
|
|
243
|
+
});
|
|
244
|
+
function useNumberFormatter(locale, options) {
|
|
245
|
+
return (0, react_1.useMemo)(() => {
|
|
246
|
+
return new number_1.NumberFormatter(locale, options);
|
|
247
|
+
}, [locale, options]);
|
|
248
|
+
}
|
|
249
|
+
function useNumberParser(locale, options) {
|
|
250
|
+
return (0, react_1.useMemo)(() => {
|
|
251
|
+
return new number_1.NumberParser(locale, options);
|
|
252
|
+
}, [locale, options]);
|
|
253
|
+
}
|
|
254
|
+
function useLongPress(elementRef, action, delay = 500) {
|
|
255
|
+
const timeoutId = (0, react_1.useRef)(0);
|
|
256
|
+
const intervalId = (0, react_1.useRef)(0);
|
|
257
|
+
const savedAction = (0, react_1.useRef)(action);
|
|
258
|
+
// Remember the latest action callback, since it is different every render
|
|
259
|
+
(0, react_1.useEffect)(() => {
|
|
260
|
+
savedAction.current = action;
|
|
261
|
+
}, [action]);
|
|
262
|
+
(0, react_1.useEffect)(() => {
|
|
263
|
+
const onMouseDown = () => {
|
|
264
|
+
var _a;
|
|
265
|
+
(_a = savedAction.current) === null || _a === void 0 ? void 0 : _a.call(savedAction);
|
|
266
|
+
timeoutId.current = window.setTimeout(() => {
|
|
267
|
+
intervalId.current = window.setInterval(() => {
|
|
268
|
+
var _a;
|
|
269
|
+
(_a = savedAction.current) === null || _a === void 0 ? void 0 : _a.call(savedAction);
|
|
270
|
+
}, 100);
|
|
271
|
+
}, delay);
|
|
272
|
+
};
|
|
273
|
+
const onMouseUp = () => {
|
|
274
|
+
clearTimeout(timeoutId.current);
|
|
275
|
+
clearInterval(intervalId.current);
|
|
276
|
+
};
|
|
277
|
+
const onMouseOut = () => {
|
|
278
|
+
clearTimeout(timeoutId.current);
|
|
279
|
+
clearInterval(intervalId.current);
|
|
280
|
+
};
|
|
281
|
+
elementRef === null || elementRef === void 0 ? void 0 : elementRef.addEventListener("mousedown", onMouseDown);
|
|
282
|
+
elementRef === null || elementRef === void 0 ? void 0 : elementRef.addEventListener("mouseup", onMouseUp);
|
|
283
|
+
elementRef === null || elementRef === void 0 ? void 0 : elementRef.addEventListener("mouseout", onMouseOut);
|
|
284
|
+
return () => {
|
|
285
|
+
elementRef === null || elementRef === void 0 ? void 0 : elementRef.removeEventListener("mousedown", onMouseDown);
|
|
286
|
+
elementRef === null || elementRef === void 0 ? void 0 : elementRef.removeEventListener("mouseup", onMouseUp);
|
|
287
|
+
elementRef === null || elementRef === void 0 ? void 0 : elementRef.removeEventListener("mouseout", onMouseOut);
|
|
288
|
+
};
|
|
289
|
+
}, [elementRef, action, delay]);
|
|
290
|
+
}
|
|
291
|
+
function handleChangingValue(value, parser, type, step = 1, min = -numberbox_abstractions_1.NUMBERBOX_MAX_VALUE, max = numberbox_abstractions_1.NUMBERBOX_MAX_VALUE) {
|
|
292
|
+
const currentInputValue = parser.parse(value !== null && value !== void 0 ? value : "");
|
|
293
|
+
if ((0, lodash_es_1.isNaN)(currentInputValue)) {
|
|
294
|
+
return min !== null && min !== void 0 ? min : 0;
|
|
295
|
+
}
|
|
296
|
+
if (type === "increase") {
|
|
297
|
+
return (0, numberbox_abstractions_1.clamp)(currentInputValue + (step !== null && step !== void 0 ? step : 1), min, max);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return (0, numberbox_abstractions_1.clamp)(currentInputValue - (step !== null && step !== void 0 ? step : 1), min, max);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function canSynchronizeValue(value, locale, options) {
|
|
304
|
+
if (value.trim() === "")
|
|
305
|
+
return true;
|
|
306
|
+
if ((0, lodash_es_1.isNaN)(value))
|
|
307
|
+
return false;
|
|
308
|
+
if (hasLeadingZeros(value, locale, options))
|
|
309
|
+
return false;
|
|
310
|
+
if (isFloatWithTrailingZeros(value, locale, options))
|
|
311
|
+
return false;
|
|
312
|
+
if (overMaximumFractionDigits(value, locale, options))
|
|
313
|
+
return false;
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
function hasLeadingZeros(input, locale = "en-US", options) {
|
|
317
|
+
var _a, _b;
|
|
318
|
+
// Create a formatter to detect locale-specific separators
|
|
319
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
320
|
+
const parts = formatter.formatToParts(1234.5);
|
|
321
|
+
const group = ((_a = parts.find((p) => p.type === "group")) === null || _a === void 0 ? void 0 : _a.value) || "";
|
|
322
|
+
const decimal = ((_b = parts.find((p) => p.type === "decimal")) === null || _b === void 0 ? void 0 : _b.value) || "";
|
|
323
|
+
// Normalize separators for parsing
|
|
324
|
+
const normalized = (group === "" ? input : input.replace(new RegExp(`\\${group}`, "g"), "")).replace(decimal, ".");
|
|
325
|
+
if (!/^-?\d*\.?\d*$/.test(normalized))
|
|
326
|
+
return false;
|
|
327
|
+
const [integer, fraction] = normalized.split(".");
|
|
328
|
+
// Integer validation
|
|
329
|
+
if (!fraction) {
|
|
330
|
+
return integer.length > 1 && integer.startsWith("0");
|
|
331
|
+
}
|
|
332
|
+
// Float validation
|
|
333
|
+
const leadingIntegerZeros = integer.startsWith("0") && integer.length >= 1;
|
|
334
|
+
const leadingFractionZeros = (fraction.match(/^0+/) || [""])[0].length >= 2;
|
|
335
|
+
return leadingIntegerZeros || leadingFractionZeros;
|
|
336
|
+
}
|
|
337
|
+
function isFloatWithTrailingZeros(input, locale = "en-US", options) {
|
|
338
|
+
var _a, _b;
|
|
339
|
+
// Create formatter to detect locale-specific separators
|
|
340
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
341
|
+
const parts = formatter.formatToParts(1234.5);
|
|
342
|
+
const group = ((_a = parts.find((p) => p.type === "group")) === null || _a === void 0 ? void 0 : _a.value) || "";
|
|
343
|
+
const decimal = ((_b = parts.find((p) => p.type === "decimal")) === null || _b === void 0 ? void 0 : _b.value) || ".";
|
|
344
|
+
// Normalize separators for parsing
|
|
345
|
+
const normalized = (group === "" ? input : input.replace(new RegExp(`\\${group}`, "g"), "")).replace(decimal, ".");
|
|
346
|
+
// Validate numeric format
|
|
347
|
+
if (!/^-?\d*\.?\d*$/.test(normalized))
|
|
348
|
+
return false;
|
|
349
|
+
// Check if it's a float (has decimal point)
|
|
350
|
+
if (!normalized.includes("."))
|
|
351
|
+
return false;
|
|
352
|
+
// Split into integer and fractional parts
|
|
353
|
+
const [_, fraction] = normalized.split(".");
|
|
354
|
+
// Must have fractional digits to be a float -> integers get a pass
|
|
355
|
+
if (!fraction || fraction.length === 0)
|
|
356
|
+
return true;
|
|
357
|
+
// Check for trailing zeros in the fractional part
|
|
358
|
+
return /0+$/.test(fraction);
|
|
359
|
+
}
|
|
360
|
+
function overMaximumFractionDigits(input, locale = "en-US", options) {
|
|
361
|
+
var _a, _b;
|
|
362
|
+
// Create a formatter to detect locale-specific separators
|
|
363
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
364
|
+
const parts = formatter.formatToParts(1234.5);
|
|
365
|
+
const group = ((_a = parts.find((p) => p.type === "group")) === null || _a === void 0 ? void 0 : _a.value) || "";
|
|
366
|
+
const decimal = ((_b = parts.find((p) => p.type === "decimal")) === null || _b === void 0 ? void 0 : _b.value) || "";
|
|
367
|
+
// Normalize separators for parsing
|
|
368
|
+
const normalized = (group === "" ? input : input.replace(new RegExp(`\\${group}`, "g"), "")).replace(decimal, ".");
|
|
369
|
+
if (!/^-?\d*\.?\d*$/.test(normalized))
|
|
370
|
+
return false;
|
|
371
|
+
const [_, fraction] = normalized.split(".");
|
|
372
|
+
// Integer validation
|
|
373
|
+
if (!fraction) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
// Float validation
|
|
377
|
+
return fraction.length > options.maximumFractionDigits;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Solution comes from: https://giacomocerquone.com/blog/keep-input-cursor-still/
|
|
381
|
+
*/
|
|
382
|
+
function useCursorCorrection(value, inputRef) {
|
|
383
|
+
const position = (0, react_1.useRef)({
|
|
384
|
+
beforeStart: 0,
|
|
385
|
+
beforeEnd: 0,
|
|
386
|
+
});
|
|
387
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
388
|
+
inputRef.current.setSelectionRange(position.current.beforeStart, position.current.beforeEnd);
|
|
389
|
+
}, [value]);
|
|
390
|
+
const onInputChange = (event) => {
|
|
391
|
+
position.current.beforeStart = event.target.selectionStart;
|
|
392
|
+
position.current.beforeEnd = event.target.selectionEnd;
|
|
393
|
+
};
|
|
394
|
+
return onInputChange;
|
|
395
|
+
}
|
|
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DEFAULT_STEP = exports.FLOAT_REGEXP = exports.INT_REGEXP = exports.EXPONENTIAL_SEPARATOR = exports.DECIMAL_SEPARATOR = exports.NUMBERBOX_MAX_VALUE = void 0;
|
|
4
4
|
exports.isEmptyLike = isEmptyLike;
|
|
5
5
|
exports.mapToRepresentation = mapToRepresentation;
|
|
6
|
+
exports.isOutOfBounds = isOutOfBounds;
|
|
6
7
|
exports.clamp = clamp;
|
|
7
8
|
exports.toUsableNumber = toUsableNumber;
|
|
9
|
+
exports.isUsableFloat = isUsableFloat;
|
|
10
|
+
exports.isUsableInteger = isUsableInteger;
|
|
8
11
|
exports.NUMBERBOX_MAX_VALUE = 999999999999999;
|
|
9
12
|
exports.DECIMAL_SEPARATOR = ".";
|
|
10
13
|
exports.EXPONENTIAL_SEPARATOR = "e";
|
|
@@ -21,6 +24,9 @@ function mapToRepresentation(value) {
|
|
|
21
24
|
return value.toString();
|
|
22
25
|
return "";
|
|
23
26
|
}
|
|
27
|
+
function isOutOfBounds(value, min, max) {
|
|
28
|
+
return value < min || value > max;
|
|
29
|
+
}
|
|
24
30
|
function clamp(value, min, max) {
|
|
25
31
|
let clamped = value;
|
|
26
32
|
if (value < min)
|
|
@@ -72,3 +78,32 @@ function isUsableInteger(value) {
|
|
|
72
78
|
}
|
|
73
79
|
return false;
|
|
74
80
|
}
|
|
81
|
+
// TODO:
|
|
82
|
+
class NumberFormatter2 {
|
|
83
|
+
constructor(locale, options) {
|
|
84
|
+
this.locale = locale;
|
|
85
|
+
this.options = options;
|
|
86
|
+
this.formatter = new Intl.NumberFormat(locale, options);
|
|
87
|
+
}
|
|
88
|
+
set input(value) {
|
|
89
|
+
}
|
|
90
|
+
buildModel() {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const parts = this.formatter.formatToParts(1234.5);
|
|
93
|
+
this.model.group = ((_a = parts.find((p) => p.type === "group")) === null || _a === void 0 ? void 0 : _a.value) || "";
|
|
94
|
+
this.model.decimal = ((_b = parts.find((p) => p.type === "decimal")) === null || _b === void 0 ? void 0 : _b.value) || "";
|
|
95
|
+
}
|
|
96
|
+
parse(value) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
format(value) {
|
|
100
|
+
return this.formatter.format(value);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Strip all non-numeric characters but keep the type of string
|
|
104
|
+
* @param value
|
|
105
|
+
*/
|
|
106
|
+
sanitize(value) {
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -21,6 +21,7 @@ exports.OptionMd = (0, ComponentDefs_1.createMetadata)({
|
|
|
21
21
|
enabled: (0, metadata_helpers_1.dEnabled)(),
|
|
22
22
|
optionTemplate: (0, ComponentDefs_1.d)("This property is used to define a custom option template"),
|
|
23
23
|
},
|
|
24
|
+
childrenAsTemplate: "optionTemplate"
|
|
24
25
|
});
|
|
25
26
|
const OptionNative = (0, react_1.memo)((props) => {
|
|
26
27
|
const OptionType = (0, OptionTypeProvider_1.useOptionType)();
|
|
@@ -31,7 +32,7 @@ const OptionNative = (0, react_1.memo)((props) => {
|
|
|
31
32
|
});
|
|
32
33
|
OptionNative.displayName = "OptionNative";
|
|
33
34
|
exports.optionComponentRenderer = (0, renderers_1.createComponentRenderer)(COMP, exports.OptionMd, ({ node, extractValue, layoutCss, renderChild, layoutContext }) => {
|
|
34
|
-
const optionTemplate = node.
|
|
35
|
+
const optionTemplate = node.props.optionTemplate;
|
|
35
36
|
return ((0, jsx_runtime_1.jsx)(OptionNative, { optionRenderer: optionTemplate
|
|
36
37
|
? (contextVars) => ((0, jsx_runtime_1.jsx)(container_helpers_1.MemoizedItem, { node: optionTemplate, renderChild: renderChild, contextVars: contextVars, layoutContext: layoutContext }))
|
|
37
38
|
: undefined, value: extractValue(node.props.value), label: extractValue.asOptionalString(node.props.label) || renderChild(node.children), enabled: extractValue.asOptionalBoolean(node.props.enabled), style: layoutCss }));
|
|
@@ -30,6 +30,7 @@ exports.SelectMd = (0, ComponentDefs_1.createMetadata)({
|
|
|
30
30
|
labelWidth: (0, metadata_helpers_1.dLabelWidth)(COMP),
|
|
31
31
|
labelBreak: (0, metadata_helpers_1.dLabelBreak)(COMP),
|
|
32
32
|
optionLabelTemplate: (0, metadata_helpers_1.dComponent)(`This property allows replacing the default template to display an option in the dropdown list.`),
|
|
33
|
+
optionTemplate: (0, metadata_helpers_1.dComponent)(`This property allows replacing the default template to display an option in the dropdown list.`),
|
|
33
34
|
valueTemplate: (0, metadata_helpers_1.dComponent)(`This property allows replacing the default template to display a selected value when ` +
|
|
34
35
|
`multiple selections (\`multiSelect\` is \`true\`) are enabled.`),
|
|
35
36
|
dropdownHeight: (0, ComponentDefs_1.d)("This property sets the height of the dropdown list."),
|
|
@@ -49,6 +50,7 @@ exports.SelectMd = (0, ComponentDefs_1.createMetadata)({
|
|
|
49
50
|
focus: (0, metadata_helpers_1.dFocus)(COMP),
|
|
50
51
|
setValue: (0, metadata_helpers_1.dSetValueApi)(),
|
|
51
52
|
value: (0, metadata_helpers_1.dValue)(),
|
|
53
|
+
reset: (0, ComponentDefs_1.d)(`This method resets the component to its initial value, or clears the selection if no initial value was provided.`),
|
|
52
54
|
},
|
|
53
55
|
contextVars: {
|
|
54
56
|
$item: (0, ComponentDefs_1.d)(`This property represents the value of an item in the dropdown list.`),
|
|
@@ -69,6 +71,8 @@ exports.SelectMd = (0, ComponentDefs_1.createMetadata)({
|
|
|
69
71
|
[`fontSize-${COMP}-badge`]: "$fontSize-small",
|
|
70
72
|
[`paddingHorizontal-${COMP}-badge`]: "$space-1",
|
|
71
73
|
[`paddingVertical-${COMP}-badge`]: "$space-1",
|
|
74
|
+
[`paddingHorizontal-item-${COMP}`]: "$space-2",
|
|
75
|
+
[`paddingVertical-item-${COMP}`]: "$space-2",
|
|
72
76
|
[`opacity-text-item-${COMP}--disabled`]: "0.5",
|
|
73
77
|
[`opacity-${COMP}--disabled`]: "0.5",
|
|
74
78
|
[`backgroundColor-${COMP}-badge--hover`]: "$color-primary-400",
|
|
@@ -82,6 +86,10 @@ exports.selectComponentRenderer = (0, renderers_1.createComponentRenderer)(COMP,
|
|
|
82
86
|
? (item) => {
|
|
83
87
|
return ((0, jsx_runtime_1.jsx)(container_helpers_1.MemoizedItem, { node: node.props.optionLabelTemplate, item: item, renderChild: renderChild }));
|
|
84
88
|
}
|
|
89
|
+
: undefined, optionRenderer: node.props.optionTemplate
|
|
90
|
+
? (item) => {
|
|
91
|
+
return ((0, jsx_runtime_1.jsx)(container_helpers_1.MemoizedItem, { node: node.props.optionTemplate, item: item, renderChild: renderChild }));
|
|
92
|
+
}
|
|
85
93
|
: undefined, valueRenderer: node.props.valueTemplate
|
|
86
94
|
? (item, removeItem) => {
|
|
87
95
|
return ((0, jsx_runtime_1.jsx)(container_helpers_1.MemoizedItem, { contextVars: {
|
|
@@ -59,20 +59,19 @@ const SimpleSelect = (0, react_1.forwardRef)(function SimpleSelect(props, forwar
|
|
|
59
59
|
const { root } = (0, ThemeContext_1.useTheme)();
|
|
60
60
|
const { enabled, onBlur, autoFocus, onValueChange, validationStatus, children, value, height, style, placeholder, id, triggerRef, onFocus, options, } = props;
|
|
61
61
|
const ref = forwardedRef ? (0, react_compose_refs_1.composeRefs)(triggerRef, forwardedRef) : triggerRef;
|
|
62
|
-
const stringValue = value ? value + "" :
|
|
62
|
+
const stringValue = value != undefined ? value + "" : null;
|
|
63
63
|
const onValChange = (0, react_1.useCallback)((val) => {
|
|
64
64
|
var _a;
|
|
65
65
|
const valueWithMatchingType = (_a = Array.from(options.values()).find((o) => o.value + "" === val)) === null || _a === void 0 ? void 0 : _a.value;
|
|
66
66
|
onValueChange(valueWithMatchingType);
|
|
67
67
|
}, [onValueChange, options]);
|
|
68
|
-
(0, react_1.useEffect)(() => { }, []);
|
|
69
68
|
return ((0, jsx_runtime_1.jsx)(OptionTypeProvider_1.default, { Component: SelectOption, children: (0, jsx_runtime_1.jsxs)(react_select_1.Root, { value: stringValue, onValueChange: onValChange, children: [(0, jsx_runtime_1.jsxs)(react_select_1.Trigger, { id: id, style: style, onFocus: onFocus, onBlur: onBlur, disabled: !enabled, className: (0, classnames_1.default)(Select_module_scss_1.default.selectTrigger, {
|
|
70
69
|
[Select_module_scss_1.default.error]: validationStatus === "error",
|
|
71
70
|
[Select_module_scss_1.default.warning]: validationStatus === "warning",
|
|
72
71
|
[Select_module_scss_1.default.valid]: validationStatus === "valid",
|
|
73
72
|
}), ref: ref, autoFocus: autoFocus, children: [(0, jsx_runtime_1.jsx)("div", { className: Select_module_scss_1.default.selectValue, children: (0, jsx_runtime_1.jsx)(react_select_1.Value, { placeholder: placeholder }) }), (0, jsx_runtime_1.jsx)(react_select_1.Icon, { asChild: true, children: (0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "chevrondown" }) })] }), (0, jsx_runtime_1.jsx)(react_select_1.Portal, { container: root, children: (0, jsx_runtime_1.jsxs)(react_select_1.Content, { className: Select_module_scss_1.default.selectContent, position: "popper", style: { height: height }, children: [(0, jsx_runtime_1.jsx)(react_select_1.ScrollUpButton, { className: Select_module_scss_1.default.selectScrollUpButton, children: (0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "chevronup" }) }), (0, jsx_runtime_1.jsx)(react_select_1.Viewport, { className: (0, classnames_1.default)(Select_module_scss_1.default.selectViewport), children: children }), (0, jsx_runtime_1.jsx)(react_select_1.ScrollDownButton, { className: Select_module_scss_1.default.selectScrollDownButton, children: (0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "chevrondown" }) })] }) })] }) }));
|
|
74
73
|
});
|
|
75
|
-
exports.Select = (0, react_1.forwardRef)(function Select({ id, initialValue, value, enabled = true, placeholder, updateState = constants_1.noop, validationStatus = "none", onDidChange = constants_1.noop, onFocus = constants_1.noop, onBlur = constants_1.noop, registerComponentApi, emptyListTemplate, optionLabelRenderer, valueRenderer, style, dropdownHeight, children, autoFocus = false, searchable = false, multiSelect = false, label, labelPosition, labelWidth, labelBreak, required = false, inProgress = false, inProgressNotificationMessage = "Loading...", }, ref) {
|
|
74
|
+
exports.Select = (0, react_1.forwardRef)(function Select({ id, initialValue, value, enabled = true, placeholder, updateState = constants_1.noop, validationStatus = "none", onDidChange = constants_1.noop, onFocus = constants_1.noop, onBlur = constants_1.noop, registerComponentApi, emptyListTemplate, optionLabelRenderer, optionRenderer, valueRenderer, style, dropdownHeight, children, autoFocus = false, searchable = false, multiSelect = false, label, labelPosition, labelWidth, labelBreak, required = false, inProgress = false, inProgressNotificationMessage = "Loading...", }, ref) {
|
|
76
75
|
var _a;
|
|
77
76
|
const [referenceElement, setReferenceElement] = (0, react_1.useState)(null);
|
|
78
77
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
@@ -128,12 +127,22 @@ exports.Select = (0, react_1.forwardRef)(function Select({ id, initialValue, val
|
|
|
128
127
|
const setValue = (0, misc_1.useEvent)((newValue) => {
|
|
129
128
|
toggleOption(newValue);
|
|
130
129
|
});
|
|
130
|
+
const reset = (0, misc_1.useEvent)(() => {
|
|
131
|
+
if (initialValue !== undefined) {
|
|
132
|
+
updateState({ value: initialValue });
|
|
133
|
+
onDidChange(initialValue);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
clearValue();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
131
139
|
(0, react_1.useEffect)(() => {
|
|
132
140
|
registerComponentApi === null || registerComponentApi === void 0 ? void 0 : registerComponentApi({
|
|
133
141
|
focus,
|
|
134
142
|
setValue,
|
|
143
|
+
reset,
|
|
135
144
|
});
|
|
136
|
-
}, [focus, registerComponentApi, setValue]);
|
|
145
|
+
}, [focus, registerComponentApi, setValue, reset]);
|
|
137
146
|
// Render the "empty list" message
|
|
138
147
|
const emptyListNode = (0, react_1.useMemo)(() => emptyListTemplate !== null && emptyListTemplate !== void 0 ? emptyListTemplate : ((0, jsx_runtime_1.jsxs)("div", { className: Select_module_scss_1.default.selectEmpty, children: [(0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "noresult" }), (0, jsx_runtime_1.jsx)("span", { children: "List is empty" })] })), [emptyListTemplate]);
|
|
139
148
|
const onOptionAdd = (0, react_1.useCallback)((option) => {
|
|
@@ -154,8 +163,9 @@ exports.Select = (0, react_1.forwardRef)(function Select({ id, initialValue, val
|
|
|
154
163
|
multiSelect,
|
|
155
164
|
value,
|
|
156
165
|
optionLabelRenderer,
|
|
166
|
+
optionRenderer,
|
|
157
167
|
onChange: toggleOption,
|
|
158
|
-
}), [multiSelect, toggleOption, value, optionLabelRenderer]);
|
|
168
|
+
}), [multiSelect, toggleOption, value, optionLabelRenderer, optionRenderer]);
|
|
159
169
|
return ((0, jsx_runtime_1.jsx)(SelectContext_1.SelectContext.Provider, { value: selectContextValue, children: (0, jsx_runtime_1.jsx)(OptionContext_1.OptionContext.Provider, { value: optionContextValue, children: searchable || multiSelect ? ((0, jsx_runtime_1.jsxs)(OptionTypeProvider_1.default, { Component: HiddenOption, children: [children, (0, jsx_runtime_1.jsx)(ItemWithLabel_1.ItemWithLabel, { ref: ref, labelPosition: labelPosition, label: label, labelWidth: labelWidth, labelBreak: labelBreak, required: required, enabled: enabled, onFocus: onFocus, onBlur: onBlur, style: style, children: (0, jsx_runtime_1.jsxs)(react_popover_1.Popover, { open: open, onOpenChange: setOpen, modal: false, children: [(0, jsx_runtime_1.jsx)(react_popover_1.PopoverTrigger, { asChild: true, children: (0, jsx_runtime_1.jsxs)("button", { id: id, ref: setReferenceElement, onFocus: onFocus, onBlur: onBlur, disabled: !enabled, "aria-expanded": open, onClick: () => setOpen((prev) => !prev), className: (0, classnames_1.default)(Select_module_scss_1.default.selectTrigger, Select_module_scss_1.default[validationStatus], {
|
|
160
170
|
[Select_module_scss_1.default.disabled]: !enabled,
|
|
161
171
|
[Select_module_scss_1.default.multi]: multiSelect,
|
|
@@ -182,15 +192,15 @@ exports.Select = (0, react_1.forwardRef)(function Select({ id, initialValue, val
|
|
|
182
192
|
exports.ComboboxOption = (0, react_1.forwardRef)(function Combobox(option, forwardedRef) {
|
|
183
193
|
const id = (0, react_1.useId)();
|
|
184
194
|
const { label, value, enabled = true, keywords } = option;
|
|
185
|
-
const { value: selectedValue, onChange, multiSelect, optionLabelRenderer } = (0, SelectContext_1.useSelect)();
|
|
195
|
+
const { value: selectedValue, onChange, multiSelect, optionLabelRenderer, optionRenderer, } = (0, SelectContext_1.useSelect)();
|
|
186
196
|
const selected = (0, react_1.useMemo)(() => {
|
|
187
197
|
return Array.isArray(selectedValue) && multiSelect
|
|
188
198
|
? selectedValue.includes(value)
|
|
189
199
|
: selectedValue === value;
|
|
190
200
|
}, [selectedValue, value, multiSelect]);
|
|
191
|
-
return ((0, jsx_runtime_1.
|
|
201
|
+
return ((0, jsx_runtime_1.jsx)(cmdk_1.CommandItem, { id: id, ref: forwardedRef, disabled: !enabled, value: `${value}`, className: Select_module_scss_1.default.multiComboboxOption, onSelect: () => {
|
|
192
202
|
onChange(value);
|
|
193
|
-
}, "data-state": selected ? "checked" : undefined, keywords: keywords, children: [optionLabelRenderer ? optionLabelRenderer({ label, value }) : label, selected && (0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "checkmark" })] }, id));
|
|
203
|
+
}, "data-state": selected ? "checked" : undefined, keywords: keywords, children: (0, jsx_runtime_1.jsx)("div", { className: Select_module_scss_1.default.multiComboboxOptionContent, children: optionRenderer ? (optionRenderer({ label, value, enabled, keywords })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [optionLabelRenderer ? optionLabelRenderer({ label, value }) : label, selected && (0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "checkmark" })] })) }) }, id));
|
|
194
204
|
});
|
|
195
205
|
function HiddenOption(option) {
|
|
196
206
|
const { onOptionRemove, onOptionAdd } = (0, OptionContext_1.useOption)();
|
|
@@ -208,11 +218,15 @@ function HiddenOption(option) {
|
|
|
208
218
|
const SelectOption = react_1.default.forwardRef((option, ref) => {
|
|
209
219
|
const { value, label, enabled = true } = option;
|
|
210
220
|
const { onOptionRemove, onOptionAdd } = (0, OptionContext_1.useOption)();
|
|
211
|
-
const { optionLabelRenderer } = (0, SelectContext_1.useSelect)();
|
|
221
|
+
const { optionLabelRenderer, optionRenderer } = (0, SelectContext_1.useSelect)();
|
|
212
222
|
(0, react_1.useLayoutEffect)(() => {
|
|
213
223
|
onOptionAdd(option);
|
|
214
224
|
return () => onOptionRemove(option);
|
|
215
225
|
}, [option, onOptionAdd, onOptionRemove]);
|
|
216
|
-
return ((0, jsx_runtime_1.
|
|
226
|
+
return ((0, jsx_runtime_1.jsx)(react_select_1.Item, { ref: ref, className: Select_module_scss_1.default.selectItem, value: value + "", disabled: !enabled, children: (0, jsx_runtime_1.jsx)("div", { className: Select_module_scss_1.default.selectItemContent, children: optionRenderer ? (optionRenderer({
|
|
227
|
+
label: (0, jsx_runtime_1.jsx)(react_select_1.ItemText, { children: label }),
|
|
228
|
+
value,
|
|
229
|
+
enabled,
|
|
230
|
+
})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_select_1.ItemText, { className: Select_module_scss_1.default.selectItemContent, children: optionLabelRenderer ? optionLabelRenderer({ value, label }) : label }), (0, jsx_runtime_1.jsx)("span", { className: Select_module_scss_1.default.selectItemIndicator, children: (0, jsx_runtime_1.jsx)(react_select_1.ItemIndicator, { children: (0, jsx_runtime_1.jsx)(IconNative_1.default, { name: "checkmark" }) }) })] })) }) }));
|
|
217
231
|
});
|
|
218
232
|
SelectOption.displayName = "SelectOption";
|
|
@@ -61,6 +61,7 @@ function Theme({ id, isRoot = false, renderChild, node, tone, toastDuration = 50
|
|
|
61
61
|
let rangeClassName;
|
|
62
62
|
if (!isRoot) {
|
|
63
63
|
rangeClassName = `${fromClass} ~ *:has(~ .${toClass})`;
|
|
64
|
+
css += `color: var(${(0, themeVars_1.getVarKey)("textColor-primary")});`;
|
|
64
65
|
}
|
|
65
66
|
return {
|
|
66
67
|
className,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.VisuallyHidden = void 0;
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const react_visually_hidden_1 = require("@radix-ui/react-visually-hidden");
|
|
17
|
+
const VisuallyHidden = (_a) => {
|
|
18
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(react_visually_hidden_1.VisuallyHidden, Object.assign({}, props, { children: children })));
|
|
20
|
+
};
|
|
21
|
+
exports.VisuallyHidden = VisuallyHidden;
|