@vuer-ai/vuer-uikit 0.0.23 → 0.0.25
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/chunk-4FOSHIMU.mjs +1 -0
- package/dist/{chunk-FUQCOZWA.js → chunk-6RTJSAVW.js} +92 -62
- package/dist/chunk-CCGCEN7Z.js +79 -0
- package/dist/{chunk-Q5KEB4UK.mjs → chunk-GXZZGOXX.mjs} +19 -22
- package/dist/{chunk-7JAADHQO.mjs → chunk-H5C3BWSK.mjs} +82 -56
- package/dist/{chunk-QZVQRU25.mjs → chunk-I55IRAYH.mjs} +1 -1
- package/dist/chunk-LHWH4GP5.mjs +77 -0
- package/dist/chunk-Q3GXSHJV.mjs +214 -0
- package/dist/{chunk-C7VFXWS6.js → chunk-QSW45JZH.js} +1 -1
- package/dist/chunk-UOFJLQ72.js +2 -0
- package/dist/chunk-ZTNXAV64.js +217 -0
- package/dist/{chunk-EOFYA6CS.js → chunk-ZX6K2A3O.js} +18 -21
- package/dist/highlight-cursor/enhanced-components.js +9 -9
- package/dist/highlight-cursor/enhanced-components.mjs +4 -4
- package/dist/highlight-cursor/index.js +9 -9
- package/dist/highlight-cursor/index.mjs +4 -4
- package/dist/index.css +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +141 -139
- package/dist/index.mjs +17 -15
- package/dist/ui/avatar.js +1 -1
- package/dist/ui/avatar.mjs +1 -1
- package/dist/ui/badge.js +1 -1
- package/dist/ui/badge.mjs +1 -1
- package/dist/ui/button.js +1 -1
- package/dist/ui/button.mjs +1 -1
- package/dist/ui/card.js +1 -1
- package/dist/ui/card.mjs +1 -1
- package/dist/ui/checkbox.js +1 -1
- package/dist/ui/checkbox.mjs +1 -1
- package/dist/ui/collapsible.js +1 -1
- package/dist/ui/collapsible.mjs +1 -1
- package/dist/ui/dropdown.js +1 -1
- package/dist/ui/dropdown.mjs +1 -1
- package/dist/ui/index.d.mts +2 -1
- package/dist/ui/index.d.ts +2 -1
- package/dist/ui/index.js +127 -125
- package/dist/ui/index.mjs +16 -14
- package/dist/ui/input-numbers.d.mts +2 -3
- package/dist/ui/input-numbers.d.ts +2 -3
- package/dist/ui/input-numbers.js +3 -3
- package/dist/ui/input-numbers.mjs +2 -2
- package/dist/ui/input.d.mts +1 -1
- package/dist/ui/input.d.ts +1 -1
- package/dist/ui/input.js +1 -1
- package/dist/ui/input.mjs +1 -1
- package/dist/ui/layout.js +1 -1
- package/dist/ui/layout.mjs +1 -1
- package/dist/ui/modal.js +1 -1
- package/dist/ui/modal.mjs +1 -1
- package/dist/ui/popover.js +1 -1
- package/dist/ui/popover.mjs +1 -1
- package/dist/ui/radio-group.js +1 -1
- package/dist/ui/radio-group.mjs +1 -1
- package/dist/ui/select.d.mts +1 -1
- package/dist/ui/select.d.ts +1 -1
- package/dist/ui/select.js +1 -1
- package/dist/ui/select.mjs +1 -1
- package/dist/ui/slider.js +1 -1
- package/dist/ui/slider.mjs +1 -1
- package/dist/ui/switch.js +1 -1
- package/dist/ui/switch.mjs +1 -1
- package/dist/ui/tabs.js +1 -1
- package/dist/ui/tabs.mjs +1 -1
- package/dist/ui/textarea.d.mts +1 -1
- package/dist/ui/textarea.d.ts +1 -1
- package/dist/ui/textarea.js +1 -1
- package/dist/ui/textarea.mjs +1 -1
- package/dist/ui/theme-context/index.d.mts +4 -0
- package/dist/ui/theme-context/index.d.ts +4 -0
- package/dist/ui/theme-context/index.js +16 -0
- package/dist/ui/theme-context/index.mjs +3 -0
- package/dist/ui/theme-context/theme-context.d.mts +8 -0
- package/dist/ui/theme-context/theme-context.d.ts +8 -0
- package/dist/ui/theme-context/theme-context.js +15 -0
- package/dist/ui/theme-context/theme-context.mjs +2 -0
- package/dist/ui/theme-context/theme-script.d.mts +13 -0
- package/dist/ui/theme-context/theme-script.d.ts +13 -0
- package/dist/ui/theme-context/theme-script.js +10 -0
- package/dist/ui/theme-context/theme-script.mjs +1 -0
- package/dist/ui/theme-context/theme-types.d.mts +47 -0
- package/dist/ui/theme-context/theme-types.d.ts +47 -0
- package/dist/ui/theme-context/theme-types.js +2 -0
- package/dist/ui/theme-context/theme-types.mjs +1 -0
- package/dist/ui/timeline.js +1 -1
- package/dist/ui/timeline.mjs +1 -1
- package/dist/ui/toggle-group.js +1 -1
- package/dist/ui/toggle-group.mjs +1 -1
- package/dist/ui/toggle.js +1 -1
- package/dist/ui/toggle.mjs +1 -1
- package/dist/ui/tooltip.js +1 -1
- package/dist/ui/tooltip.mjs +1 -1
- package/dist/ui/tree-view-v2.js +1 -1
- package/dist/ui/tree-view-v2.mjs +1 -1
- package/dist/ui/version-badge.js +3 -3
- package/dist/ui/version-badge.mjs +2 -2
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/use-local-storage.js +2 -2
- package/dist/utils/use-local-storage.mjs +1 -1
- package/package.json +1 -2
- package/src/ui/input-numbers.tsx +101 -65
- package/src/ui/theme-context/index.ts +3 -0
- package/src/ui/theme-context/theme-context.tsx +266 -0
- package/src/ui/theme-context/theme-script.tsx +101 -0
- package/src/ui/theme-context/theme-types.ts +50 -0
- package/src/utils/use-local-storage.ts +23 -25
- package/dist/chunk-LEPXSM36.mjs +0 -46
- package/dist/chunk-PVRQNCSJ.js +0 -49
- package/dist/ui/theme-context.d.mts +0 -17
- package/dist/ui/theme-context.d.ts +0 -17
- package/dist/ui/theme-context.js +0 -17
- package/dist/ui/theme-context.mjs +0 -4
- package/src/ui/theme-context.tsx +0 -80
- package/dist/{chunk-ALTUOIWV.mjs → chunk-HLJ7PQA7.mjs} +2 -2
- package/dist/{chunk-W7D57QE6.js → chunk-V4KNORQN.js} +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkSKO72K64_js = require('./chunk-SKO72K64.js');
|
|
4
4
|
var chunkXXWQ4RVP_js = require('./chunk-XXWQ4RVP.js');
|
|
5
|
-
var
|
|
6
|
-
var react = require('react');
|
|
5
|
+
var React = require('react');
|
|
7
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
11
|
+
|
|
9
12
|
var getHoverElementAndIndex = (element, inputs) => {
|
|
10
13
|
if (!element) return null;
|
|
11
14
|
const container = element == null ? void 0 : element.closest("[data-input]");
|
|
@@ -26,12 +29,14 @@ var changeElementsHoverState = (inputs, range, changed) => {
|
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
31
|
};
|
|
29
|
-
var InputNumbers =
|
|
30
|
-
const inputs =
|
|
31
|
-
const selectRange =
|
|
32
|
-
const inputChange =
|
|
33
|
-
const
|
|
34
|
-
|
|
32
|
+
var InputNumbers = React.forwardRef(function InputNumbers2({ size, value, onValuesChange, prefix, step = 0.1 }, ref) {
|
|
33
|
+
const inputs = React.useRef(/* @__PURE__ */ new Map());
|
|
34
|
+
const selectRange = React.useRef([null, null]);
|
|
35
|
+
const inputChange = React.useRef(false);
|
|
36
|
+
const [isDragging, setIsDragging] = React.useState(false);
|
|
37
|
+
const dragStart = React.useRef({ x: 0, y: 0 });
|
|
38
|
+
const accumulatedDelta = React.useRef(0);
|
|
39
|
+
const stopClick = React.useCallback(() => {
|
|
35
40
|
const stopClick2 = (e) => {
|
|
36
41
|
e.stopPropagation();
|
|
37
42
|
e.preventDefault();
|
|
@@ -39,59 +44,84 @@ var InputNumbers = react.forwardRef(function InputNumbers2({ size, value, onValu
|
|
|
39
44
|
};
|
|
40
45
|
document.addEventListener("click", stopClick2, true);
|
|
41
46
|
}, []);
|
|
42
|
-
const
|
|
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
|
-
|
|
47
|
+
const handleMouseDown = React.useCallback((e) => {
|
|
48
|
+
if (e.button !== 0) return;
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
setIsDragging(true);
|
|
52
|
+
dragStart.current = { x: e.clientX, y: e.clientY };
|
|
53
|
+
accumulatedDelta.current = 0;
|
|
54
|
+
inputChange.current = false;
|
|
55
|
+
selectRange.current[0] = getHoverElementAndIndex(
|
|
56
|
+
document.elementFromPoint(e.clientX, e.clientY),
|
|
57
|
+
inputs.current
|
|
58
|
+
);
|
|
59
|
+
}, []);
|
|
60
|
+
const handleMouseMove = React.useCallback(
|
|
61
|
+
(e) => {
|
|
62
|
+
if (!isDragging) return;
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
const deltaX = e.clientX - dragStart.current.x;
|
|
66
|
+
const deltaY = e.clientY - dragStart.current.y;
|
|
67
|
+
accumulatedDelta.current += deltaX / 2;
|
|
68
|
+
dragStart.current = { x: e.clientX, y: e.clientY };
|
|
69
|
+
if (Math.abs(accumulatedDelta.current) >= (inputChange.current ? 1 : 5)) {
|
|
70
|
+
const multiplyStep = e.shiftKey ? 5 : e.altKey ? 1 / 5 : 1;
|
|
71
|
+
const newValue = value.map((v, i) => {
|
|
72
|
+
const [first, last] = selectRange.current;
|
|
73
|
+
if (first === null || last === null) {
|
|
74
|
+
return v;
|
|
75
|
+
} else if (i <= Math.max(first, last) && i >= Math.min(first, last)) {
|
|
76
|
+
return Number(
|
|
77
|
+
((v || 0) + Math.floor(accumulatedDelta.current) * step * multiplyStep).toPrecision(
|
|
78
|
+
6
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
} else {
|
|
82
|
+
return v;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
onValuesChange == null ? void 0 : onValuesChange(newValue);
|
|
86
|
+
accumulatedDelta.current = 0;
|
|
87
|
+
inputChange.current = true;
|
|
88
|
+
changeElementsHoverState(inputs.current, selectRange.current, "x");
|
|
89
|
+
stopClick();
|
|
90
|
+
}
|
|
91
|
+
if (!inputChange.current) {
|
|
92
|
+
const currentElement = document.elementFromPoint(e.clientX, e.clientY);
|
|
93
|
+
const currentIndex = getHoverElementAndIndex(currentElement, inputs.current);
|
|
94
|
+
selectRange.current[1] = currentIndex ?? selectRange.current[1];
|
|
95
|
+
changeElementsHoverState(inputs.current, selectRange.current, deltaY !== 0 ? "y" : "none");
|
|
96
|
+
stopClick();
|
|
87
97
|
}
|
|
88
98
|
},
|
|
89
|
-
|
|
90
|
-
// Pass config options to make gesture library SSR-safe
|
|
91
|
-
enabled: typeof document !== "undefined"
|
|
92
|
-
}
|
|
99
|
+
[isDragging, value, onValuesChange, step, stopClick]
|
|
93
100
|
);
|
|
94
|
-
const
|
|
101
|
+
const handleMouseUp = React.useCallback(() => {
|
|
102
|
+
if (!isDragging) return;
|
|
103
|
+
setIsDragging(false);
|
|
104
|
+
selectRange.current = [null, null];
|
|
105
|
+
inputChange.current = false;
|
|
106
|
+
changeElementsHoverState(inputs.current, selectRange.current, "none");
|
|
107
|
+
}, [isDragging]);
|
|
108
|
+
React__default.default.useEffect(() => {
|
|
109
|
+
if (isDragging) {
|
|
110
|
+
const handleGlobalMouseMove = (e) => {
|
|
111
|
+
handleMouseMove(e);
|
|
112
|
+
};
|
|
113
|
+
const handleGlobalMouseUp = () => {
|
|
114
|
+
handleMouseUp();
|
|
115
|
+
};
|
|
116
|
+
document.addEventListener("mousemove", handleGlobalMouseMove);
|
|
117
|
+
document.addEventListener("mouseup", handleGlobalMouseUp);
|
|
118
|
+
return () => {
|
|
119
|
+
document.removeEventListener("mousemove", handleGlobalMouseMove);
|
|
120
|
+
document.removeEventListener("mouseup", handleGlobalMouseUp);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
124
|
+
const valueChangeHandler = React.useCallback(
|
|
95
125
|
(index) => {
|
|
96
126
|
return (e) => {
|
|
97
127
|
const inputValue = e.target.value;
|
|
@@ -115,7 +145,7 @@ var InputNumbers = react.forwardRef(function InputNumbers2({ size, value, onValu
|
|
|
115
145
|
"div",
|
|
116
146
|
{
|
|
117
147
|
ref,
|
|
118
|
-
|
|
148
|
+
onMouseDown: handleMouseDown,
|
|
119
149
|
className: chunkXXWQ4RVP_js.cn("gap-xs flex cursor-crosshair touch-none flex-col select-none"),
|
|
120
150
|
children: value.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
121
151
|
chunkSKO72K64_js.InputRoot,
|
|
@@ -142,13 +172,13 @@ var InputNumbers = react.forwardRef(function InputNumbers2({ size, value, onValu
|
|
|
142
172
|
"data-[hover=y]:bg-bg-tertiary",
|
|
143
173
|
"data-[hover=down]:cursor-move",
|
|
144
174
|
"data-[hover=x]:cursor-col-resize",
|
|
145
|
-
"data-[hover=y]:cursor-
|
|
175
|
+
"data-[hover=y]:cursor-row-resize"
|
|
146
176
|
]),
|
|
147
177
|
inputClassName: chunkXXWQ4RVP_js.cn([
|
|
148
178
|
"cursor-crosshair",
|
|
149
179
|
"group-data-[hover=down]/number-input:cursor-move",
|
|
150
180
|
"group-data-[hover=x]/number-input:cursor-col-resize",
|
|
151
|
-
"group-data-[hover=y]/number-input:cursor-
|
|
181
|
+
"group-data-[hover=y]/number-input:cursor-row-resize"
|
|
152
182
|
]),
|
|
153
183
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
154
184
|
chunkSKO72K64_js.InputSlot,
|
|
@@ -157,7 +187,7 @@ var InputNumbers = react.forwardRef(function InputNumbers2({ size, value, onValu
|
|
|
157
187
|
"cursor-crosshair",
|
|
158
188
|
"group-data-[hover=down]/number-input:cursor-move",
|
|
159
189
|
"group-data-[hover=x]/number-input:cursor-col-resize",
|
|
160
|
-
"group-data-[hover=y]/number-input:cursor-
|
|
190
|
+
"group-data-[hover=y]/number-input:cursor-row-resize"
|
|
161
191
|
),
|
|
162
192
|
children: prefix == null ? void 0 : prefix[index]
|
|
163
193
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// src/ui/theme-context/theme-script.tsx
|
|
7
|
+
var themeScript = (defaultTheme, storageKey, attribute, themes, value, forcedTheme, enableSystem, enableColorScheme) => {
|
|
8
|
+
const el = document.documentElement;
|
|
9
|
+
const systemThemes = ["light", "dark"];
|
|
10
|
+
function updateDOM(theme) {
|
|
11
|
+
const attributes = Array.isArray(attribute) ? attribute : [attribute];
|
|
12
|
+
attributes.forEach((attr) => {
|
|
13
|
+
const isClass = attr === "class";
|
|
14
|
+
const classes = isClass && value ? themes.map((t) => value[t] || t) : themes;
|
|
15
|
+
if (isClass) {
|
|
16
|
+
el.classList.remove(...classes);
|
|
17
|
+
el.classList.add(value && value[theme] ? value[theme] : theme);
|
|
18
|
+
} else {
|
|
19
|
+
el.setAttribute(attr, theme);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
setColorScheme(theme);
|
|
23
|
+
}
|
|
24
|
+
function setColorScheme(theme) {
|
|
25
|
+
if (enableColorScheme && systemThemes.includes(theme)) {
|
|
26
|
+
el.style.colorScheme = theme;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function getSystemTheme() {
|
|
30
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
31
|
+
}
|
|
32
|
+
if (forcedTheme) {
|
|
33
|
+
updateDOM(forcedTheme);
|
|
34
|
+
} else {
|
|
35
|
+
try {
|
|
36
|
+
const themeName = localStorage.getItem(storageKey ?? "") || defaultTheme;
|
|
37
|
+
const isSystem = enableSystem && themeName === "system";
|
|
38
|
+
const theme = isSystem ? getSystemTheme() : themeName;
|
|
39
|
+
updateDOM(theme);
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var ThemeScript = react.memo(
|
|
45
|
+
({
|
|
46
|
+
forcedTheme,
|
|
47
|
+
storageKey,
|
|
48
|
+
attribute,
|
|
49
|
+
enableSystem,
|
|
50
|
+
enableColorScheme,
|
|
51
|
+
defaultTheme,
|
|
52
|
+
value,
|
|
53
|
+
themes,
|
|
54
|
+
nonce,
|
|
55
|
+
scriptProps
|
|
56
|
+
}) => {
|
|
57
|
+
const scriptArgs = JSON.stringify([
|
|
58
|
+
defaultTheme,
|
|
59
|
+
storageKey,
|
|
60
|
+
attribute,
|
|
61
|
+
themes,
|
|
62
|
+
value,
|
|
63
|
+
forcedTheme,
|
|
64
|
+
enableSystem,
|
|
65
|
+
enableColorScheme
|
|
66
|
+
]).slice(1, -1);
|
|
67
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
68
|
+
"script",
|
|
69
|
+
{
|
|
70
|
+
...scriptProps,
|
|
71
|
+
suppressHydrationWarning: true,
|
|
72
|
+
nonce: typeof window === "undefined" ? nonce : "",
|
|
73
|
+
dangerouslySetInnerHTML: { __html: `(${themeScript.toString()})(${scriptArgs})` }
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
exports.ThemeScript = ThemeScript;
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
// src/utils/use-local-storage.ts
|
|
4
4
|
function useLocalStorage(key, initialValue) {
|
|
5
|
-
const [storedValue, setStoredValue] = useState(
|
|
6
|
-
if (typeof window === "undefined") {
|
|
7
|
-
return initialValue;
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
const item = window.localStorage.getItem(key);
|
|
11
|
-
if (item === null) return initialValue;
|
|
12
|
-
if (typeof initialValue === "string") {
|
|
13
|
-
return item;
|
|
14
|
-
} else if (typeof initialValue === "number") {
|
|
15
|
-
return parseFloat(item) || initialValue;
|
|
16
|
-
} else if (typeof initialValue === "boolean") {
|
|
17
|
-
return item === "true";
|
|
18
|
-
} else {
|
|
19
|
-
return JSON.parse(item);
|
|
20
|
-
}
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.warn(`Error reading localStorage key "${key}":`, error);
|
|
23
|
-
return initialValue;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
5
|
+
const [storedValue, setStoredValue] = useState(initialValue);
|
|
26
6
|
const setValue = useCallback(
|
|
27
7
|
(value) => {
|
|
28
8
|
try {
|
|
@@ -45,6 +25,23 @@ function useLocalStorage(key, initialValue) {
|
|
|
45
25
|
},
|
|
46
26
|
[key, storedValue]
|
|
47
27
|
);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
try {
|
|
30
|
+
const item = window.localStorage.getItem(key);
|
|
31
|
+
if (item === null) return;
|
|
32
|
+
if (typeof initialValue === "string") {
|
|
33
|
+
setStoredValue(item);
|
|
34
|
+
} else if (typeof initialValue === "number") {
|
|
35
|
+
return setStoredValue(parseFloat(item) || initialValue);
|
|
36
|
+
} else if (typeof initialValue === "boolean") {
|
|
37
|
+
return setStoredValue(item === "true");
|
|
38
|
+
} else {
|
|
39
|
+
return setStoredValue(JSON.parse(item));
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn(`Error reading localStorage key "${key}":`, error);
|
|
43
|
+
}
|
|
44
|
+
}, [initialValue, key]);
|
|
48
45
|
return [storedValue, setValue];
|
|
49
46
|
}
|
|
50
47
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { InputRoot, InputSlot } from './chunk-QYRRQ65X.mjs';
|
|
2
2
|
import { cn } from './chunk-KTNZSZ5Y.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import { forwardRef, useRef, useCallback } from 'react';
|
|
3
|
+
import React, { forwardRef, useRef, useState, useCallback } from 'react';
|
|
5
4
|
import { jsx } from 'react/jsx-runtime';
|
|
6
5
|
|
|
7
6
|
var getHoverElementAndIndex = (element, inputs) => {
|
|
@@ -28,8 +27,10 @@ var InputNumbers = forwardRef(function InputNumbers2({ size, value, onValuesChan
|
|
|
28
27
|
const inputs = useRef(/* @__PURE__ */ new Map());
|
|
29
28
|
const selectRange = useRef([null, null]);
|
|
30
29
|
const inputChange = useRef(false);
|
|
30
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
31
|
+
const dragStart = useRef({ x: 0, y: 0 });
|
|
32
|
+
const accumulatedDelta = useRef(0);
|
|
31
33
|
const stopClick = useCallback(() => {
|
|
32
|
-
if (typeof document === "undefined") return;
|
|
33
34
|
const stopClick2 = (e) => {
|
|
34
35
|
e.stopPropagation();
|
|
35
36
|
e.preventDefault();
|
|
@@ -37,58 +38,83 @@ var InputNumbers = forwardRef(function InputNumbers2({ size, value, onValuesChan
|
|
|
37
38
|
};
|
|
38
39
|
document.addEventListener("click", stopClick2, true);
|
|
39
40
|
}, []);
|
|
40
|
-
const
|
|
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
|
-
|
|
41
|
+
const handleMouseDown = useCallback((e) => {
|
|
42
|
+
if (e.button !== 0) return;
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
e.stopPropagation();
|
|
45
|
+
setIsDragging(true);
|
|
46
|
+
dragStart.current = { x: e.clientX, y: e.clientY };
|
|
47
|
+
accumulatedDelta.current = 0;
|
|
48
|
+
inputChange.current = false;
|
|
49
|
+
selectRange.current[0] = getHoverElementAndIndex(
|
|
50
|
+
document.elementFromPoint(e.clientX, e.clientY),
|
|
51
|
+
inputs.current
|
|
52
|
+
);
|
|
53
|
+
}, []);
|
|
54
|
+
const handleMouseMove = useCallback(
|
|
55
|
+
(e) => {
|
|
56
|
+
if (!isDragging) return;
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
const deltaX = e.clientX - dragStart.current.x;
|
|
60
|
+
const deltaY = e.clientY - dragStart.current.y;
|
|
61
|
+
accumulatedDelta.current += deltaX / 2;
|
|
62
|
+
dragStart.current = { x: e.clientX, y: e.clientY };
|
|
63
|
+
if (Math.abs(accumulatedDelta.current) >= (inputChange.current ? 1 : 5)) {
|
|
64
|
+
const multiplyStep = e.shiftKey ? 5 : e.altKey ? 1 / 5 : 1;
|
|
65
|
+
const newValue = value.map((v, i) => {
|
|
66
|
+
const [first, last] = selectRange.current;
|
|
67
|
+
if (first === null || last === null) {
|
|
68
|
+
return v;
|
|
69
|
+
} else if (i <= Math.max(first, last) && i >= Math.min(first, last)) {
|
|
70
|
+
return Number(
|
|
71
|
+
((v || 0) + Math.floor(accumulatedDelta.current) * step * multiplyStep).toPrecision(
|
|
72
|
+
6
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
} else {
|
|
76
|
+
return v;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
onValuesChange == null ? void 0 : onValuesChange(newValue);
|
|
80
|
+
accumulatedDelta.current = 0;
|
|
81
|
+
inputChange.current = true;
|
|
82
|
+
changeElementsHoverState(inputs.current, selectRange.current, "x");
|
|
83
|
+
stopClick();
|
|
84
|
+
}
|
|
85
|
+
if (!inputChange.current) {
|
|
86
|
+
const currentElement = document.elementFromPoint(e.clientX, e.clientY);
|
|
87
|
+
const currentIndex = getHoverElementAndIndex(currentElement, inputs.current);
|
|
88
|
+
selectRange.current[1] = currentIndex ?? selectRange.current[1];
|
|
89
|
+
changeElementsHoverState(inputs.current, selectRange.current, deltaY !== 0 ? "y" : "none");
|
|
90
|
+
stopClick();
|
|
85
91
|
}
|
|
86
92
|
},
|
|
87
|
-
|
|
88
|
-
// Pass config options to make gesture library SSR-safe
|
|
89
|
-
enabled: typeof document !== "undefined"
|
|
90
|
-
}
|
|
93
|
+
[isDragging, value, onValuesChange, step, stopClick]
|
|
91
94
|
);
|
|
95
|
+
const handleMouseUp = useCallback(() => {
|
|
96
|
+
if (!isDragging) return;
|
|
97
|
+
setIsDragging(false);
|
|
98
|
+
selectRange.current = [null, null];
|
|
99
|
+
inputChange.current = false;
|
|
100
|
+
changeElementsHoverState(inputs.current, selectRange.current, "none");
|
|
101
|
+
}, [isDragging]);
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
if (isDragging) {
|
|
104
|
+
const handleGlobalMouseMove = (e) => {
|
|
105
|
+
handleMouseMove(e);
|
|
106
|
+
};
|
|
107
|
+
const handleGlobalMouseUp = () => {
|
|
108
|
+
handleMouseUp();
|
|
109
|
+
};
|
|
110
|
+
document.addEventListener("mousemove", handleGlobalMouseMove);
|
|
111
|
+
document.addEventListener("mouseup", handleGlobalMouseUp);
|
|
112
|
+
return () => {
|
|
113
|
+
document.removeEventListener("mousemove", handleGlobalMouseMove);
|
|
114
|
+
document.removeEventListener("mouseup", handleGlobalMouseUp);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
92
118
|
const valueChangeHandler = useCallback(
|
|
93
119
|
(index) => {
|
|
94
120
|
return (e) => {
|
|
@@ -113,7 +139,7 @@ var InputNumbers = forwardRef(function InputNumbers2({ size, value, onValuesChan
|
|
|
113
139
|
"div",
|
|
114
140
|
{
|
|
115
141
|
ref,
|
|
116
|
-
|
|
142
|
+
onMouseDown: handleMouseDown,
|
|
117
143
|
className: cn("gap-xs flex cursor-crosshair touch-none flex-col select-none"),
|
|
118
144
|
children: value.map((item, index) => /* @__PURE__ */ jsx(
|
|
119
145
|
InputRoot,
|
|
@@ -140,13 +166,13 @@ var InputNumbers = forwardRef(function InputNumbers2({ size, value, onValuesChan
|
|
|
140
166
|
"data-[hover=y]:bg-bg-tertiary",
|
|
141
167
|
"data-[hover=down]:cursor-move",
|
|
142
168
|
"data-[hover=x]:cursor-col-resize",
|
|
143
|
-
"data-[hover=y]:cursor-
|
|
169
|
+
"data-[hover=y]:cursor-row-resize"
|
|
144
170
|
]),
|
|
145
171
|
inputClassName: cn([
|
|
146
172
|
"cursor-crosshair",
|
|
147
173
|
"group-data-[hover=down]/number-input:cursor-move",
|
|
148
174
|
"group-data-[hover=x]/number-input:cursor-col-resize",
|
|
149
|
-
"group-data-[hover=y]/number-input:cursor-
|
|
175
|
+
"group-data-[hover=y]/number-input:cursor-row-resize"
|
|
150
176
|
]),
|
|
151
177
|
children: /* @__PURE__ */ jsx(
|
|
152
178
|
InputSlot,
|
|
@@ -155,7 +181,7 @@ var InputNumbers = forwardRef(function InputNumbers2({ size, value, onValuesChan
|
|
|
155
181
|
"cursor-crosshair",
|
|
156
182
|
"group-data-[hover=down]/number-input:cursor-move",
|
|
157
183
|
"group-data-[hover=x]/number-input:cursor-col-resize",
|
|
158
|
-
"group-data-[hover=y]/number-input:cursor-
|
|
184
|
+
"group-data-[hover=y]/number-input:cursor-row-resize"
|
|
159
185
|
),
|
|
160
186
|
children: prefix == null ? void 0 : prefix[index]
|
|
161
187
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/ui/theme-context/theme-script.tsx
|
|
5
|
+
var themeScript = (defaultTheme, storageKey, attribute, themes, value, forcedTheme, enableSystem, enableColorScheme) => {
|
|
6
|
+
const el = document.documentElement;
|
|
7
|
+
const systemThemes = ["light", "dark"];
|
|
8
|
+
function updateDOM(theme) {
|
|
9
|
+
const attributes = Array.isArray(attribute) ? attribute : [attribute];
|
|
10
|
+
attributes.forEach((attr) => {
|
|
11
|
+
const isClass = attr === "class";
|
|
12
|
+
const classes = isClass && value ? themes.map((t) => value[t] || t) : themes;
|
|
13
|
+
if (isClass) {
|
|
14
|
+
el.classList.remove(...classes);
|
|
15
|
+
el.classList.add(value && value[theme] ? value[theme] : theme);
|
|
16
|
+
} else {
|
|
17
|
+
el.setAttribute(attr, theme);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
setColorScheme(theme);
|
|
21
|
+
}
|
|
22
|
+
function setColorScheme(theme) {
|
|
23
|
+
if (enableColorScheme && systemThemes.includes(theme)) {
|
|
24
|
+
el.style.colorScheme = theme;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function getSystemTheme() {
|
|
28
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
29
|
+
}
|
|
30
|
+
if (forcedTheme) {
|
|
31
|
+
updateDOM(forcedTheme);
|
|
32
|
+
} else {
|
|
33
|
+
try {
|
|
34
|
+
const themeName = localStorage.getItem(storageKey ?? "") || defaultTheme;
|
|
35
|
+
const isSystem = enableSystem && themeName === "system";
|
|
36
|
+
const theme = isSystem ? getSystemTheme() : themeName;
|
|
37
|
+
updateDOM(theme);
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var ThemeScript = memo(
|
|
43
|
+
({
|
|
44
|
+
forcedTheme,
|
|
45
|
+
storageKey,
|
|
46
|
+
attribute,
|
|
47
|
+
enableSystem,
|
|
48
|
+
enableColorScheme,
|
|
49
|
+
defaultTheme,
|
|
50
|
+
value,
|
|
51
|
+
themes,
|
|
52
|
+
nonce,
|
|
53
|
+
scriptProps
|
|
54
|
+
}) => {
|
|
55
|
+
const scriptArgs = JSON.stringify([
|
|
56
|
+
defaultTheme,
|
|
57
|
+
storageKey,
|
|
58
|
+
attribute,
|
|
59
|
+
themes,
|
|
60
|
+
value,
|
|
61
|
+
forcedTheme,
|
|
62
|
+
enableSystem,
|
|
63
|
+
enableColorScheme
|
|
64
|
+
]).slice(1, -1);
|
|
65
|
+
return /* @__PURE__ */ jsx(
|
|
66
|
+
"script",
|
|
67
|
+
{
|
|
68
|
+
...scriptProps,
|
|
69
|
+
suppressHydrationWarning: true,
|
|
70
|
+
nonce: typeof window === "undefined" ? nonce : "",
|
|
71
|
+
dangerouslySetInnerHTML: { __html: `(${themeScript.toString()})(${scriptArgs})` }
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export { ThemeScript };
|