@hai3/studio 0.2.0-alpha.0 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +34 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React3 = require('react');
|
|
4
4
|
var react = require('@hai3/react');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var uikit = require('@hai3/uikit');
|
|
@@ -8,7 +8,7 @@ var lodash = require('lodash');
|
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
12
12
|
|
|
13
13
|
var __create = Object.create;
|
|
14
14
|
var __defProp = Object.defineProperty;
|
|
@@ -903,24 +903,24 @@ var studioTranslations = react.I18nRegistry.createLoader({
|
|
|
903
903
|
[react.Language.ChineseSimplified]: () => Promise.resolve().then(() => __toESM(require_zh()))
|
|
904
904
|
});
|
|
905
905
|
react.i18nRegistry.registerLoader("studio", studioTranslations);
|
|
906
|
-
var StudioContext =
|
|
906
|
+
var StudioContext = React3.createContext(void 0);
|
|
907
907
|
var useStudioContext = () => {
|
|
908
|
-
const context =
|
|
908
|
+
const context = React3.useContext(StudioContext);
|
|
909
909
|
if (!context) {
|
|
910
910
|
throw new Error("useStudioContext must be used within StudioProvider");
|
|
911
911
|
}
|
|
912
912
|
return context;
|
|
913
913
|
};
|
|
914
914
|
var StudioProvider = ({ children }) => {
|
|
915
|
-
const [collapsed, setCollapsed] =
|
|
915
|
+
const [collapsed, setCollapsed] = React3.useState(
|
|
916
916
|
() => loadStudioState(STORAGE_KEYS.COLLAPSED, false)
|
|
917
917
|
);
|
|
918
|
-
const [portalContainer, setPortalContainer] =
|
|
919
|
-
|
|
918
|
+
const [portalContainer, setPortalContainer] = React3.useState(null);
|
|
919
|
+
React3.useEffect(() => {
|
|
920
920
|
const cleanup = initPersistenceEffects();
|
|
921
921
|
return cleanup;
|
|
922
922
|
}, []);
|
|
923
|
-
const toggleCollapsed =
|
|
923
|
+
const toggleCollapsed = React3.useCallback(() => {
|
|
924
924
|
setCollapsed((prev) => {
|
|
925
925
|
const newValue = !prev;
|
|
926
926
|
saveStudioState(STORAGE_KEYS.COLLAPSED, newValue);
|
|
@@ -946,19 +946,19 @@ var useDraggable = ({ panelSize, storageKey = STORAGE_KEYS.POSITION }) => {
|
|
|
946
946
|
x: window.innerWidth - panelSize.width - 20,
|
|
947
947
|
y: window.innerHeight - panelSize.height - 20
|
|
948
948
|
});
|
|
949
|
-
const [position, setPosition] =
|
|
949
|
+
const [position, setPosition] = React3.useState(
|
|
950
950
|
() => loadStudioState(storageKey, getDefaultPosition())
|
|
951
951
|
);
|
|
952
|
-
const [isDragging, setIsDragging] =
|
|
953
|
-
const dragStartPos =
|
|
954
|
-
const handleMouseDown =
|
|
952
|
+
const [isDragging, setIsDragging] = React3.useState(false);
|
|
953
|
+
const dragStartPos = React3.useRef({ x: 0, y: 0 });
|
|
954
|
+
const handleMouseDown = React3.useCallback((e) => {
|
|
955
955
|
setIsDragging(true);
|
|
956
956
|
dragStartPos.current = {
|
|
957
957
|
x: e.clientX - position.x,
|
|
958
958
|
y: e.clientY - position.y
|
|
959
959
|
};
|
|
960
960
|
}, [position]);
|
|
961
|
-
|
|
961
|
+
React3.useEffect(() => {
|
|
962
962
|
if (!isDragging) return;
|
|
963
963
|
const handleMouseMove = (e) => {
|
|
964
964
|
const newX = lodash.clamp(
|
|
@@ -993,15 +993,15 @@ var useDraggable = ({ panelSize, storageKey = STORAGE_KEYS.POSITION }) => {
|
|
|
993
993
|
};
|
|
994
994
|
};
|
|
995
995
|
var useResizable = () => {
|
|
996
|
-
const [size, setSize] =
|
|
996
|
+
const [size, setSize] = React3.useState(
|
|
997
997
|
() => loadStudioState(STORAGE_KEYS.SIZE, {
|
|
998
998
|
width: PANEL_CONSTRAINTS.DEFAULT_WIDTH,
|
|
999
999
|
height: PANEL_CONSTRAINTS.DEFAULT_HEIGHT
|
|
1000
1000
|
})
|
|
1001
1001
|
);
|
|
1002
|
-
const [isResizing, setIsResizing] =
|
|
1003
|
-
const resizeStartRef =
|
|
1004
|
-
const handleMouseDown =
|
|
1002
|
+
const [isResizing, setIsResizing] = React3.useState(false);
|
|
1003
|
+
const resizeStartRef = React3.useRef(null);
|
|
1004
|
+
const handleMouseDown = React3.useCallback((e) => {
|
|
1005
1005
|
e.stopPropagation();
|
|
1006
1006
|
resizeStartRef.current = {
|
|
1007
1007
|
mouseX: e.clientX,
|
|
@@ -1011,7 +1011,7 @@ var useResizable = () => {
|
|
|
1011
1011
|
};
|
|
1012
1012
|
setIsResizing(true);
|
|
1013
1013
|
}, [size.width, size.height]);
|
|
1014
|
-
|
|
1014
|
+
React3.useEffect(() => {
|
|
1015
1015
|
if (!isResizing || !resizeStartRef.current) return;
|
|
1016
1016
|
const startState = resizeStartRef.current;
|
|
1017
1017
|
document.body.style.userSelect = "none";
|
|
@@ -1145,14 +1145,18 @@ function LanguageSelector({
|
|
|
1145
1145
|
] })
|
|
1146
1146
|
] });
|
|
1147
1147
|
}
|
|
1148
|
-
var ApiModeToggle = ({
|
|
1149
|
-
|
|
1148
|
+
var ApiModeToggle = ({
|
|
1149
|
+
className
|
|
1150
|
+
}) => {
|
|
1150
1151
|
const { t } = react.useTranslation();
|
|
1152
|
+
const enabled = react.useAppSelector((state) => {
|
|
1153
|
+
const mockState = state.mock;
|
|
1154
|
+
return mockState?.enabled ?? false;
|
|
1155
|
+
});
|
|
1151
1156
|
const handleToggle = (checked) => {
|
|
1152
|
-
|
|
1153
|
-
react.apiRegistry.setMockMode(checked);
|
|
1157
|
+
react.toggleMockMode(checked);
|
|
1154
1158
|
};
|
|
1155
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex items-center justify-between h-9 ${className}`, children: [
|
|
1159
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex items-center justify-between h-9 ${className ?? ""}`, children: [
|
|
1156
1160
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1157
1161
|
"label",
|
|
1158
1162
|
{
|
|
@@ -1165,7 +1169,7 @@ var ApiModeToggle = ({ className }) => {
|
|
|
1165
1169
|
uikit.Switch,
|
|
1166
1170
|
{
|
|
1167
1171
|
id: "api-mode-toggle",
|
|
1168
|
-
checked:
|
|
1172
|
+
checked: enabled,
|
|
1169
1173
|
onCheckedChange: handleToggle
|
|
1170
1174
|
}
|
|
1171
1175
|
)
|
|
@@ -1185,9 +1189,9 @@ var buildScreensetOptions = () => {
|
|
|
1185
1189
|
};
|
|
1186
1190
|
var ControlPanel = () => {
|
|
1187
1191
|
const { currentScreenset, navigateToScreenset } = react.useNavigation();
|
|
1188
|
-
const [screensetOptions, setScreensetOptions] =
|
|
1192
|
+
const [screensetOptions, setScreensetOptions] = React3.useState([]);
|
|
1189
1193
|
const { t } = react.useTranslation();
|
|
1190
|
-
|
|
1194
|
+
React3.useEffect(() => {
|
|
1191
1195
|
const options = buildScreensetOptions();
|
|
1192
1196
|
setScreensetOptions(options);
|
|
1193
1197
|
}, []);
|
|
@@ -1224,13 +1228,13 @@ ControlPanel.displayName = "ControlPanel";
|
|
|
1224
1228
|
var StudioPanel = () => {
|
|
1225
1229
|
const { toggleCollapsed, setPortalContainer } = useStudioContext();
|
|
1226
1230
|
const { t } = react.useTranslation();
|
|
1227
|
-
const portalRef =
|
|
1231
|
+
const portalRef = React3__default.default.useRef(null);
|
|
1228
1232
|
const { size, handleMouseDown: handleResizeMouseDown } = useResizable();
|
|
1229
1233
|
const { position, isDragging, handleMouseDown: handleDragMouseDown } = useDraggable({
|
|
1230
1234
|
panelSize: size,
|
|
1231
1235
|
storageKey: STORAGE_KEYS.POSITION
|
|
1232
1236
|
});
|
|
1233
|
-
|
|
1237
|
+
React3__default.default.useEffect(() => {
|
|
1234
1238
|
setPortalContainer(portalRef.current);
|
|
1235
1239
|
return () => setPortalContainer(null);
|
|
1236
1240
|
}, [setPortalContainer]);
|
|
@@ -1321,7 +1325,7 @@ var StudioPanel = () => {
|
|
|
1321
1325
|
};
|
|
1322
1326
|
StudioPanel.displayName = "StudioPanel";
|
|
1323
1327
|
var useKeyboardShortcut = (handler) => {
|
|
1324
|
-
|
|
1328
|
+
React3.useEffect(() => {
|
|
1325
1329
|
const handleKeyDown = (e) => {
|
|
1326
1330
|
if (e.shiftKey && e.code === "Backquote") {
|
|
1327
1331
|
e.preventDefault();
|
|
@@ -1381,7 +1385,7 @@ var CollapsedButton = ({ toggleCollapsed }) => {
|
|
|
1381
1385
|
panelSize: BUTTON_SIZE,
|
|
1382
1386
|
storageKey: STORAGE_KEYS.BUTTON_POSITION
|
|
1383
1387
|
});
|
|
1384
|
-
const dragStartPosition =
|
|
1388
|
+
const dragStartPosition = React3.useRef(null);
|
|
1385
1389
|
const handleButtonMouseDown = (e) => {
|
|
1386
1390
|
dragStartPosition.current = { x: e.clientX, y: e.clientY };
|
|
1387
1391
|
handleMouseDown(e);
|