@yimoka/designable-react 0.0.0-stage → 0.1.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/README.md +6 -2
- package/dist/src/adapter/UIAdapterProvider.d.ts +7 -0
- package/dist/src/adapter/UIAdapterProvider.js +10 -0
- package/dist/src/adapter/context-core.d.ts +2 -0
- package/dist/src/adapter/context-core.js +3 -0
- package/dist/src/adapter/context.d.ts +6 -0
- package/dist/src/adapter/context.js +9 -0
- package/dist/src/adapter/default-components.d.ts +8 -0
- package/dist/src/adapter/default-components.js +38 -0
- package/dist/src/adapter/default.d.ts +2 -0
- package/dist/src/adapter/default.js +9 -0
- package/dist/src/adapter/index.d.ts +3 -0
- package/dist/src/adapter/index.js +3 -0
- package/dist/src/adapter/types.d.ts +63 -0
- package/dist/src/adapter/types.js +1 -0
- package/dist/src/containers/Designer.d.ts +3 -0
- package/dist/src/containers/Designer.js +63 -0
- package/dist/src/containers/Sandbox.d.ts +4 -0
- package/dist/src/containers/Sandbox.js +3 -0
- package/dist/src/containers/SandboxComponent.d.ts +3 -0
- package/dist/src/containers/SandboxComponent.js +15 -0
- package/dist/src/containers/Simulator.d.ts +3 -0
- package/dist/src/containers/Simulator.js +70 -0
- package/dist/src/containers/Viewport.d.ts +6 -0
- package/dist/src/containers/Viewport.js +71 -0
- package/dist/src/containers/Workbench.d.ts +2 -0
- package/dist/src/containers/Workbench.js +9 -0
- package/dist/src/containers/Workspace.d.ts +7 -0
- package/dist/src/containers/Workspace.js +39 -0
- package/dist/src/containers/index.d.ts +6 -0
- package/dist/src/containers/index.js +6 -0
- package/dist/src/containers/sandbox-types.d.ts +7 -0
- package/dist/src/containers/sandbox-types.js +1 -0
- package/dist/src/containers/sandbox-utils.d.ts +6 -0
- package/dist/src/containers/sandbox-utils.js +40 -0
- package/dist/src/containers/useSandbox.d.ts +3 -0
- package/dist/src/containers/useSandbox.js +77 -0
- package/dist/src/context.d.ts +7 -0
- package/dist/src/context.js +6 -0
- package/dist/src/hooks/index.d.ts +26 -0
- package/dist/src/hooks/index.js +26 -0
- package/dist/src/hooks/useComponents.d.ts +2 -0
- package/dist/src/hooks/useComponents.js +3 -0
- package/dist/src/hooks/useCurrentNode.d.ts +2 -0
- package/dist/src/hooks/useCurrentNode.js +7 -0
- package/dist/src/hooks/useCurrentNodeSelected.d.ts +1 -0
- package/dist/src/hooks/useCurrentNodeSelected.js +7 -0
- package/dist/src/hooks/useCursor.d.ts +2 -0
- package/dist/src/hooks/useCursor.js +5 -0
- package/dist/src/hooks/useDesigner.d.ts +3 -0
- package/dist/src/hooks/useDesigner.js +15 -0
- package/dist/src/hooks/useHistory.d.ts +2 -0
- package/dist/src/hooks/useHistory.js +5 -0
- package/dist/src/hooks/useHover.d.ts +2 -0
- package/dist/src/hooks/useHover.js +5 -0
- package/dist/src/hooks/useLayout.d.ts +2 -0
- package/dist/src/hooks/useLayout.js +8 -0
- package/dist/src/hooks/useNodeIdProps.d.ts +2 -0
- package/dist/src/hooks/useNodeIdProps.js +17 -0
- package/dist/src/hooks/useOperation.d.ts +2 -0
- package/dist/src/hooks/useOperation.js +5 -0
- package/dist/src/hooks/useOutline.d.ts +2 -0
- package/dist/src/hooks/useOutline.js +5 -0
- package/dist/src/hooks/useOutlineDragon.d.ts +2 -0
- package/dist/src/hooks/useOutlineDragon.js +5 -0
- package/dist/src/hooks/usePosition.d.ts +1 -0
- package/dist/src/hooks/usePosition.js +2 -0
- package/dist/src/hooks/usePrefix.d.ts +1 -0
- package/dist/src/hooks/usePrefix.js +5 -0
- package/dist/src/hooks/useRegistry.d.ts +2 -0
- package/dist/src/hooks/useRegistry.js +6 -0
- package/dist/src/hooks/useScreen.d.ts +2 -0
- package/dist/src/hooks/useScreen.js +2 -0
- package/dist/src/hooks/useSelected.d.ts +1 -0
- package/dist/src/hooks/useSelected.js +5 -0
- package/dist/src/hooks/useSelection.d.ts +2 -0
- package/dist/src/hooks/useSelection.js +5 -0
- package/dist/src/hooks/useTheme.d.ts +1 -0
- package/dist/src/hooks/useTheme.js +2 -0
- package/dist/src/hooks/useTree.d.ts +2 -0
- package/dist/src/hooks/useTree.js +5 -0
- package/dist/src/hooks/useTreeNode.d.ts +2 -0
- package/dist/src/hooks/useTreeNode.js +3 -0
- package/dist/src/hooks/useValidNodeOffsetRect.d.ts +2 -0
- package/dist/src/hooks/useValidNodeOffsetRect.js +81 -0
- package/dist/src/hooks/useViewport.d.ts +2 -0
- package/dist/src/hooks/useViewport.js +5 -0
- package/dist/src/hooks/useViewportDragon.d.ts +3 -0
- package/dist/src/hooks/useViewportDragon.js +6 -0
- package/dist/src/hooks/useWorkbench.d.ts +2 -0
- package/dist/src/hooks/useWorkbench.js +5 -0
- package/dist/src/hooks/useWorkspace.d.ts +2 -0
- package/dist/src/hooks/useWorkspace.js +17 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +8 -0
- package/dist/src/locales/global.d.ts +17 -0
- package/dist/src/locales/global.js +16 -0
- package/dist/src/locales/icons.d.ts +157 -0
- package/dist/src/locales/icons.js +156 -0
- package/dist/src/locales/index.d.ts +5 -0
- package/dist/src/locales/index.js +7 -0
- package/dist/src/locales/operations.d.ts +57 -0
- package/dist/src/locales/operations.js +56 -0
- package/dist/src/locales/panels.d.ts +19 -0
- package/dist/src/locales/panels.js +18 -0
- package/dist/src/shared/globals.d.ts +5 -0
- package/dist/src/shared/globals.js +5 -0
- package/dist/src/types.d.ts +36 -0
- package/dist/src/types.js +1 -0
- package/dist/src/widgets/AuxToolWidget/Cover.d.ts +2 -0
- package/dist/src/widgets/AuxToolWidget/Cover.js +48 -0
- package/dist/src/widgets/AuxToolWidget/Helpers.d.ts +6 -0
- package/dist/src/widgets/AuxToolWidget/Helpers.js +74 -0
- package/dist/src/widgets/AuxToolWidget/Insertion.d.ts +2 -0
- package/dist/src/widgets/AuxToolWidget/Insertion.js +99 -0
- package/dist/src/widgets/AuxToolWidget/Selection.d.ts +7 -0
- package/dist/src/widgets/AuxToolWidget/Selection.js +61 -0
- package/dist/src/widgets/AuxToolWidget/index.d.ts +5 -0
- package/dist/src/widgets/AuxToolWidget/index.js +35 -0
- package/dist/src/widgets/DesignerToolsWidget/index.d.ts +9 -0
- package/dist/src/widgets/DesignerToolsWidget/index.js +179 -0
- package/dist/src/widgets/DroppableWidget/index.d.ts +9 -0
- package/dist/src/widgets/DroppableWidget/index.js +20 -0
- package/dist/src/widgets/EmptyWidget/index.d.ts +5 -0
- package/dist/src/widgets/EmptyWidget/index.js +25 -0
- package/dist/src/widgets/GhostWidget/index.d.ts +2 -0
- package/dist/src/widgets/GhostWidget/index.js +47 -0
- package/dist/src/widgets/HistoryWidget/index.d.ts +2 -0
- package/dist/src/widgets/HistoryWidget/index.js +409 -0
- package/dist/src/widgets/IconWidget/index.d.ts +26 -0
- package/dist/src/widgets/IconWidget/index.js +203 -0
- package/dist/src/widgets/NodePathWidget/index.d.ts +6 -0
- package/dist/src/widgets/NodePathWidget/index.js +32 -0
- package/dist/src/widgets/NodeTitleWidget/index.d.ts +6 -0
- package/dist/src/widgets/NodeTitleWidget/index.js +13 -0
- package/dist/src/widgets/TextWidget/index.d.ts +10 -0
- package/dist/src/widgets/TextWidget/index.js +36 -0
- package/dist/src/widgets/ViewToolsWidget/index.d.ts +11 -0
- package/dist/src/widgets/ViewToolsWidget/index.js +76 -0
- package/dist/src/widgets/index.d.ts +11 -0
- package/dist/src/widgets/index.js +11 -0
- package/package.json +61 -4
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { useDesigner, useLayout, usePrefix, useWorkspace } from "../hooks/index.js";
|
|
3
|
+
import { DESIGNABLE_ENGINE_KEY, DESIGNABLE_LAYOUT_KEY, DESIGNABLE_SANDBOX_SCOPE_KEY, DESIGNABLE_WORKSPACE_KEY, } from "../shared/globals.js";
|
|
4
|
+
import { renderSandboxScriptAssets, renderSandboxStyleAssets, } from "./sandbox-utils.js";
|
|
5
|
+
const EMPTY_ASSETS = [];
|
|
6
|
+
export const useSandbox = (props) => {
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
const appCls = usePrefix('app');
|
|
9
|
+
const designer = useDesigner();
|
|
10
|
+
const workspace = useWorkspace();
|
|
11
|
+
const layout = useLayout();
|
|
12
|
+
const cssAssets = props.cssAssets ?? EMPTY_ASSETS;
|
|
13
|
+
const jsAssets = props.jsAssets ?? EMPTY_ASSETS;
|
|
14
|
+
const getCSSVar = useCallback((name) => {
|
|
15
|
+
const el = document.querySelector(`.${appCls}`);
|
|
16
|
+
if (!el)
|
|
17
|
+
return '';
|
|
18
|
+
return getComputedStyle(el).getPropertyValue(name);
|
|
19
|
+
}, [appCls]);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (ref.current && workspace) {
|
|
22
|
+
const styles = renderSandboxStyleAssets(cssAssets);
|
|
23
|
+
const scripts = renderSandboxScriptAssets(jsAssets);
|
|
24
|
+
const contentWindow = ref.current.contentWindow;
|
|
25
|
+
Reflect.set(contentWindow, DESIGNABLE_SANDBOX_SCOPE_KEY, props.scope);
|
|
26
|
+
Reflect.set(contentWindow, DESIGNABLE_LAYOUT_KEY, layout);
|
|
27
|
+
Reflect.set(contentWindow, DESIGNABLE_ENGINE_KEY, designer);
|
|
28
|
+
Reflect.set(contentWindow, DESIGNABLE_WORKSPACE_KEY, workspace);
|
|
29
|
+
contentWindow.Formily = globalThis.Formily;
|
|
30
|
+
contentWindow.Designable = globalThis.Designable;
|
|
31
|
+
ref.current.contentDocument?.open();
|
|
32
|
+
ref.current.contentDocument?.write(`
|
|
33
|
+
<!DOCTYPE html>
|
|
34
|
+
<head>
|
|
35
|
+
${styles}
|
|
36
|
+
</head>
|
|
37
|
+
<style>
|
|
38
|
+
html{
|
|
39
|
+
overflow: overlay;
|
|
40
|
+
}
|
|
41
|
+
::-webkit-scrollbar {
|
|
42
|
+
width: 5px;
|
|
43
|
+
height: 5px;
|
|
44
|
+
}
|
|
45
|
+
::-webkit-scrollbar-thumb {
|
|
46
|
+
background-color:${getCSSVar('--dn-scrollbar-color')};
|
|
47
|
+
border-radius: 0;
|
|
48
|
+
transition: all .25s ease-in-out;
|
|
49
|
+
}
|
|
50
|
+
::-webkit-scrollbar-thumb:hover {
|
|
51
|
+
background-color: ${getCSSVar('--dn-scrollbar-hover-color')};
|
|
52
|
+
}
|
|
53
|
+
body{
|
|
54
|
+
margin:0;
|
|
55
|
+
padding:0;
|
|
56
|
+
overflow-anchor: none;
|
|
57
|
+
user-select:none;
|
|
58
|
+
background-color:${layout?.theme === 'light' ? '#fff' : 'transparent'} !important;
|
|
59
|
+
}
|
|
60
|
+
html{
|
|
61
|
+
overflow-anchor: none;
|
|
62
|
+
}
|
|
63
|
+
.inherit-cursor * {
|
|
64
|
+
cursor: inherit !important;
|
|
65
|
+
}
|
|
66
|
+
</style>
|
|
67
|
+
<body>
|
|
68
|
+
<div id="__SANDBOX_ROOT__"></div>
|
|
69
|
+
${scripts}
|
|
70
|
+
</body>
|
|
71
|
+
</html>
|
|
72
|
+
`);
|
|
73
|
+
ref.current.contentDocument?.close();
|
|
74
|
+
}
|
|
75
|
+
}, [workspace, cssAssets, jsAssets, props.scope, layout, designer, getCSSVar]);
|
|
76
|
+
return ref;
|
|
77
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Engine, TreeNode } from '@yimoka/designable-core';
|
|
2
|
+
import type { IDesignerComponents, IDesignerLayoutContext, IWorkspaceContext } from "./types.js";
|
|
3
|
+
export declare const DesignerComponentsContext: import("react").Context<IDesignerComponents>;
|
|
4
|
+
export declare const DesignerLayoutContext: import("react").Context<IDesignerLayoutContext | null>;
|
|
5
|
+
export declare const DesignerEngineContext: import("react").Context<Engine | null>;
|
|
6
|
+
export declare const TreeNodeContext: import("react").Context<TreeNode | null>;
|
|
7
|
+
export declare const WorkspaceContext: import("react").Context<IWorkspaceContext | null>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
export const DesignerComponentsContext = createContext({});
|
|
3
|
+
export const DesignerLayoutContext = createContext(null);
|
|
4
|
+
export const DesignerEngineContext = createContext(null);
|
|
5
|
+
export const TreeNodeContext = createContext(null);
|
|
6
|
+
export const WorkspaceContext = createContext(null);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./useComponents.js";
|
|
2
|
+
export * from "./useCurrentNode.js";
|
|
3
|
+
export * from "./useCurrentNodeSelected.js";
|
|
4
|
+
export * from "./useCursor.js";
|
|
5
|
+
export * from "./useDesigner.js";
|
|
6
|
+
export * from "./useHistory.js";
|
|
7
|
+
export * from "./useHover.js";
|
|
8
|
+
export * from "./useLayout.js";
|
|
9
|
+
export * from "./useNodeIdProps.js";
|
|
10
|
+
export * from "./useOperation.js";
|
|
11
|
+
export * from "./useOutline.js";
|
|
12
|
+
export * from "./useOutlineDragon.js";
|
|
13
|
+
export * from "./usePosition.js";
|
|
14
|
+
export * from "./usePrefix.js";
|
|
15
|
+
export * from "./useRegistry.js";
|
|
16
|
+
export * from "./useScreen.js";
|
|
17
|
+
export * from "./useSelected.js";
|
|
18
|
+
export * from "./useSelection.js";
|
|
19
|
+
export * from "./useTheme.js";
|
|
20
|
+
export * from "./useTree.js";
|
|
21
|
+
export * from "./useTreeNode.js";
|
|
22
|
+
export * from "./useValidNodeOffsetRect.js";
|
|
23
|
+
export * from "./useViewport.js";
|
|
24
|
+
export * from "./useViewportDragon.js";
|
|
25
|
+
export * from "./useWorkbench.js";
|
|
26
|
+
export * from "./useWorkspace.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./useComponents.js";
|
|
2
|
+
export * from "./useCurrentNode.js";
|
|
3
|
+
export * from "./useCurrentNodeSelected.js";
|
|
4
|
+
export * from "./useCursor.js";
|
|
5
|
+
export * from "./useDesigner.js";
|
|
6
|
+
export * from "./useHistory.js";
|
|
7
|
+
export * from "./useHover.js";
|
|
8
|
+
export * from "./useLayout.js";
|
|
9
|
+
export * from "./useNodeIdProps.js";
|
|
10
|
+
export * from "./useOperation.js";
|
|
11
|
+
export * from "./useOutline.js";
|
|
12
|
+
export * from "./useOutlineDragon.js";
|
|
13
|
+
export * from "./usePosition.js";
|
|
14
|
+
export * from "./usePrefix.js";
|
|
15
|
+
export * from "./useRegistry.js";
|
|
16
|
+
export * from "./useScreen.js";
|
|
17
|
+
export * from "./useSelected.js";
|
|
18
|
+
export * from "./useSelection.js";
|
|
19
|
+
export * from "./useTheme.js";
|
|
20
|
+
export * from "./useTree.js";
|
|
21
|
+
export * from "./useTreeNode.js";
|
|
22
|
+
export * from "./useValidNodeOffsetRect.js";
|
|
23
|
+
export * from "./useViewport.js";
|
|
24
|
+
export * from "./useViewportDragon.js";
|
|
25
|
+
export * from "./useWorkbench.js";
|
|
26
|
+
export * from "./useWorkspace.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCurrentNodeSelected: () => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useCurrentNode } from "./useCurrentNode.js";
|
|
2
|
+
import { useSelected } from "./useSelected.js";
|
|
3
|
+
export const useCurrentNodeSelected = () => {
|
|
4
|
+
const node = useCurrentNode();
|
|
5
|
+
const selected = useSelected();
|
|
6
|
+
return selected.length === 1 && node?.id === selected[0];
|
|
7
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isFunction } from 'lodash-es';
|
|
2
|
+
import { useContext, useEffect } from 'react';
|
|
3
|
+
import { DesignerEngineContext } from "../context.js";
|
|
4
|
+
import { DESIGNABLE_ENGINE_KEY } from "../shared/globals.js";
|
|
5
|
+
export const useDesigner = (effects) => {
|
|
6
|
+
const contextEngine = useContext(DesignerEngineContext);
|
|
7
|
+
const globalEngine = Reflect.get(globalThis, DESIGNABLE_ENGINE_KEY);
|
|
8
|
+
const designer = globalEngine ?? contextEngine;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (isFunction(effects) && designer) {
|
|
11
|
+
return effects(designer);
|
|
12
|
+
}
|
|
13
|
+
}, []);
|
|
14
|
+
return designer;
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { DesignerLayoutContext } from "../context.js";
|
|
3
|
+
import { DESIGNABLE_LAYOUT_KEY } from "../shared/globals.js";
|
|
4
|
+
export const useLayout = () => {
|
|
5
|
+
const contextLayout = useContext(DesignerLayoutContext);
|
|
6
|
+
const globalLayout = Reflect.get(globalThis, DESIGNABLE_LAYOUT_KEY);
|
|
7
|
+
return globalLayout ?? contextLayout;
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useDesigner } from "./useDesigner.js";
|
|
2
|
+
import { useTreeNode } from "./useTreeNode.js";
|
|
3
|
+
export const useNodeIdProps = (node) => {
|
|
4
|
+
const target = useTreeNode();
|
|
5
|
+
const designer = useDesigner();
|
|
6
|
+
if (!designer) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
const nodeId = node?.id ?? target?.id;
|
|
10
|
+
const attrName = designer.props.nodeIdAttrName;
|
|
11
|
+
if (!nodeId || !attrName) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
[attrName]: nodeId,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePosition: () => "fixed" | "absolute" | "relative" | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePrefix: (after?: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSelected: (workspaceId?: string) => string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useTheme: () => string | undefined;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ResizeObserver } from '@juggle/resize-observer';
|
|
2
|
+
import { CursorStatus, ScreenStatus, cancelIdle, requestIdle } from '@yimoka/designable-core';
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
import { useDesigner } from "./useDesigner.js";
|
|
5
|
+
import { useViewport } from "./useViewport.js";
|
|
6
|
+
const isEqualRect = (rect1, rect2) => {
|
|
7
|
+
if (!rect1 || !rect2)
|
|
8
|
+
return rect1 === rect2;
|
|
9
|
+
return rect1.x === rect2.x
|
|
10
|
+
&& rect1.y === rect2.y
|
|
11
|
+
&& rect1.width === rect2.width
|
|
12
|
+
&& rect1.height === rect2.height;
|
|
13
|
+
};
|
|
14
|
+
const isDraggingCursorStatus = (status) => (status === CursorStatus.DragStart || status === CursorStatus.Dragging);
|
|
15
|
+
export const useValidNodeOffsetRect = (node) => {
|
|
16
|
+
const engine = useDesigner();
|
|
17
|
+
const viewport = useViewport();
|
|
18
|
+
const [rect, setRect] = useState(() => viewport?.getValidNodeOffsetRect(node));
|
|
19
|
+
const rectRef = useRef(rect);
|
|
20
|
+
const idleTaskRef = useRef(null);
|
|
21
|
+
const unmountRef = useRef(false);
|
|
22
|
+
const observerRef = useRef(null);
|
|
23
|
+
const element = viewport?.findElementById(node?.id);
|
|
24
|
+
const compute = useCallback(() => {
|
|
25
|
+
if (unmountRef.current)
|
|
26
|
+
return;
|
|
27
|
+
if (isDraggingCursorStatus(engine?.cursor.status)
|
|
28
|
+
&& engine?.screen.status === ScreenStatus.Normal) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const nextRect = viewport?.getValidNodeOffsetRect(node);
|
|
32
|
+
if (!isEqualRect(rectRef.current, nextRect) && nextRect) {
|
|
33
|
+
rectRef.current = nextRect;
|
|
34
|
+
setRect(nextRect);
|
|
35
|
+
}
|
|
36
|
+
}, [viewport, node, engine]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!element?.isConnected)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (observerRef.current) {
|
|
41
|
+
observerRef.current.disconnect();
|
|
42
|
+
}
|
|
43
|
+
observerRef.current = new ResizeObserver(() => {
|
|
44
|
+
compute();
|
|
45
|
+
});
|
|
46
|
+
observerRef.current.observe(element);
|
|
47
|
+
return () => {
|
|
48
|
+
observerRef.current?.disconnect();
|
|
49
|
+
observerRef.current = null;
|
|
50
|
+
};
|
|
51
|
+
}, [element, viewport, compute]);
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
compute();
|
|
54
|
+
}, [compute]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
unmountRef.current = false;
|
|
57
|
+
const requestIdleTask = () => {
|
|
58
|
+
if (unmountRef.current)
|
|
59
|
+
return;
|
|
60
|
+
if (idleTaskRef.current !== null) {
|
|
61
|
+
cancelIdle(idleTaskRef.current);
|
|
62
|
+
}
|
|
63
|
+
idleTaskRef.current = requestIdle(() => {
|
|
64
|
+
idleTaskRef.current = null;
|
|
65
|
+
if (unmountRef.current)
|
|
66
|
+
return;
|
|
67
|
+
compute();
|
|
68
|
+
requestIdleTask();
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
requestIdleTask();
|
|
72
|
+
return () => {
|
|
73
|
+
unmountRef.current = true;
|
|
74
|
+
if (idleTaskRef.current !== null) {
|
|
75
|
+
cancelIdle(idleTaskRef.current);
|
|
76
|
+
idleTaskRef.current = null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}, [node, compute]);
|
|
80
|
+
return rect;
|
|
81
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { WorkspaceContext } from "../context.js";
|
|
3
|
+
import { DESIGNABLE_WORKSPACE_KEY } from "../shared/globals.js";
|
|
4
|
+
import { useDesigner } from "./useDesigner.js";
|
|
5
|
+
export const useWorkspace = (id) => {
|
|
6
|
+
const designer = useDesigner();
|
|
7
|
+
const contextWorkspaceId = useContext(WorkspaceContext)?.id;
|
|
8
|
+
const workspaceId = id ?? contextWorkspaceId;
|
|
9
|
+
if (workspaceId) {
|
|
10
|
+
return designer?.workbench.findWorkspaceById(workspaceId);
|
|
11
|
+
}
|
|
12
|
+
const globalWorkspace = Reflect.get(globalThis, DESIGNABLE_WORKSPACE_KEY);
|
|
13
|
+
if (globalWorkspace) {
|
|
14
|
+
return globalWorkspace;
|
|
15
|
+
}
|
|
16
|
+
return designer?.workbench.currentWorkspace ?? undefined;
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./locales/index.js";
|
|
2
|
+
export * from "./adapter/index.js";
|
|
3
|
+
export * from "./containers/index.js";
|
|
4
|
+
export * from "./context.js";
|
|
5
|
+
export * from "./hooks/index.js";
|
|
6
|
+
export * as locales from "./locales/index.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./widgets/index.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./locales/index.js";
|
|
2
|
+
export * from "./adapter/index.js";
|
|
3
|
+
export * from "./containers/index.js";
|
|
4
|
+
export * from "./context.js";
|
|
5
|
+
export * from "./hooks/index.js";
|
|
6
|
+
export * as locales from "./locales/index.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./widgets/index.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
'zh-CN': {
|
|
3
|
+
save: string;
|
|
4
|
+
submit: string;
|
|
5
|
+
cancel: string;
|
|
6
|
+
reset: string;
|
|
7
|
+
publish: string;
|
|
8
|
+
};
|
|
9
|
+
'en-US': {
|
|
10
|
+
save: string;
|
|
11
|
+
submit: string;
|
|
12
|
+
cancel: string;
|
|
13
|
+
reset: string;
|
|
14
|
+
publish: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|