@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.
Files changed (142) hide show
  1. package/README.md +6 -2
  2. package/dist/src/adapter/UIAdapterProvider.d.ts +7 -0
  3. package/dist/src/adapter/UIAdapterProvider.js +10 -0
  4. package/dist/src/adapter/context-core.d.ts +2 -0
  5. package/dist/src/adapter/context-core.js +3 -0
  6. package/dist/src/adapter/context.d.ts +6 -0
  7. package/dist/src/adapter/context.js +9 -0
  8. package/dist/src/adapter/default-components.d.ts +8 -0
  9. package/dist/src/adapter/default-components.js +38 -0
  10. package/dist/src/adapter/default.d.ts +2 -0
  11. package/dist/src/adapter/default.js +9 -0
  12. package/dist/src/adapter/index.d.ts +3 -0
  13. package/dist/src/adapter/index.js +3 -0
  14. package/dist/src/adapter/types.d.ts +63 -0
  15. package/dist/src/adapter/types.js +1 -0
  16. package/dist/src/containers/Designer.d.ts +3 -0
  17. package/dist/src/containers/Designer.js +63 -0
  18. package/dist/src/containers/Sandbox.d.ts +4 -0
  19. package/dist/src/containers/Sandbox.js +3 -0
  20. package/dist/src/containers/SandboxComponent.d.ts +3 -0
  21. package/dist/src/containers/SandboxComponent.js +15 -0
  22. package/dist/src/containers/Simulator.d.ts +3 -0
  23. package/dist/src/containers/Simulator.js +70 -0
  24. package/dist/src/containers/Viewport.d.ts +6 -0
  25. package/dist/src/containers/Viewport.js +71 -0
  26. package/dist/src/containers/Workbench.d.ts +2 -0
  27. package/dist/src/containers/Workbench.js +9 -0
  28. package/dist/src/containers/Workspace.d.ts +7 -0
  29. package/dist/src/containers/Workspace.js +39 -0
  30. package/dist/src/containers/index.d.ts +6 -0
  31. package/dist/src/containers/index.js +6 -0
  32. package/dist/src/containers/sandbox-types.d.ts +7 -0
  33. package/dist/src/containers/sandbox-types.js +1 -0
  34. package/dist/src/containers/sandbox-utils.d.ts +6 -0
  35. package/dist/src/containers/sandbox-utils.js +40 -0
  36. package/dist/src/containers/useSandbox.d.ts +3 -0
  37. package/dist/src/containers/useSandbox.js +77 -0
  38. package/dist/src/context.d.ts +7 -0
  39. package/dist/src/context.js +6 -0
  40. package/dist/src/hooks/index.d.ts +26 -0
  41. package/dist/src/hooks/index.js +26 -0
  42. package/dist/src/hooks/useComponents.d.ts +2 -0
  43. package/dist/src/hooks/useComponents.js +3 -0
  44. package/dist/src/hooks/useCurrentNode.d.ts +2 -0
  45. package/dist/src/hooks/useCurrentNode.js +7 -0
  46. package/dist/src/hooks/useCurrentNodeSelected.d.ts +1 -0
  47. package/dist/src/hooks/useCurrentNodeSelected.js +7 -0
  48. package/dist/src/hooks/useCursor.d.ts +2 -0
  49. package/dist/src/hooks/useCursor.js +5 -0
  50. package/dist/src/hooks/useDesigner.d.ts +3 -0
  51. package/dist/src/hooks/useDesigner.js +15 -0
  52. package/dist/src/hooks/useHistory.d.ts +2 -0
  53. package/dist/src/hooks/useHistory.js +5 -0
  54. package/dist/src/hooks/useHover.d.ts +2 -0
  55. package/dist/src/hooks/useHover.js +5 -0
  56. package/dist/src/hooks/useLayout.d.ts +2 -0
  57. package/dist/src/hooks/useLayout.js +8 -0
  58. package/dist/src/hooks/useNodeIdProps.d.ts +2 -0
  59. package/dist/src/hooks/useNodeIdProps.js +17 -0
  60. package/dist/src/hooks/useOperation.d.ts +2 -0
  61. package/dist/src/hooks/useOperation.js +5 -0
  62. package/dist/src/hooks/useOutline.d.ts +2 -0
  63. package/dist/src/hooks/useOutline.js +5 -0
  64. package/dist/src/hooks/useOutlineDragon.d.ts +2 -0
  65. package/dist/src/hooks/useOutlineDragon.js +5 -0
  66. package/dist/src/hooks/usePosition.d.ts +1 -0
  67. package/dist/src/hooks/usePosition.js +2 -0
  68. package/dist/src/hooks/usePrefix.d.ts +1 -0
  69. package/dist/src/hooks/usePrefix.js +5 -0
  70. package/dist/src/hooks/useRegistry.d.ts +2 -0
  71. package/dist/src/hooks/useRegistry.js +6 -0
  72. package/dist/src/hooks/useScreen.d.ts +2 -0
  73. package/dist/src/hooks/useScreen.js +2 -0
  74. package/dist/src/hooks/useSelected.d.ts +1 -0
  75. package/dist/src/hooks/useSelected.js +5 -0
  76. package/dist/src/hooks/useSelection.d.ts +2 -0
  77. package/dist/src/hooks/useSelection.js +5 -0
  78. package/dist/src/hooks/useTheme.d.ts +1 -0
  79. package/dist/src/hooks/useTheme.js +2 -0
  80. package/dist/src/hooks/useTree.d.ts +2 -0
  81. package/dist/src/hooks/useTree.js +5 -0
  82. package/dist/src/hooks/useTreeNode.d.ts +2 -0
  83. package/dist/src/hooks/useTreeNode.js +3 -0
  84. package/dist/src/hooks/useValidNodeOffsetRect.d.ts +2 -0
  85. package/dist/src/hooks/useValidNodeOffsetRect.js +81 -0
  86. package/dist/src/hooks/useViewport.d.ts +2 -0
  87. package/dist/src/hooks/useViewport.js +5 -0
  88. package/dist/src/hooks/useViewportDragon.d.ts +3 -0
  89. package/dist/src/hooks/useViewportDragon.js +6 -0
  90. package/dist/src/hooks/useWorkbench.d.ts +2 -0
  91. package/dist/src/hooks/useWorkbench.js +5 -0
  92. package/dist/src/hooks/useWorkspace.d.ts +2 -0
  93. package/dist/src/hooks/useWorkspace.js +17 -0
  94. package/dist/src/index.d.ts +8 -0
  95. package/dist/src/index.js +8 -0
  96. package/dist/src/locales/global.d.ts +17 -0
  97. package/dist/src/locales/global.js +16 -0
  98. package/dist/src/locales/icons.d.ts +157 -0
  99. package/dist/src/locales/icons.js +156 -0
  100. package/dist/src/locales/index.d.ts +5 -0
  101. package/dist/src/locales/index.js +7 -0
  102. package/dist/src/locales/operations.d.ts +57 -0
  103. package/dist/src/locales/operations.js +56 -0
  104. package/dist/src/locales/panels.d.ts +19 -0
  105. package/dist/src/locales/panels.js +18 -0
  106. package/dist/src/shared/globals.d.ts +5 -0
  107. package/dist/src/shared/globals.js +5 -0
  108. package/dist/src/types.d.ts +36 -0
  109. package/dist/src/types.js +1 -0
  110. package/dist/src/widgets/AuxToolWidget/Cover.d.ts +2 -0
  111. package/dist/src/widgets/AuxToolWidget/Cover.js +48 -0
  112. package/dist/src/widgets/AuxToolWidget/Helpers.d.ts +6 -0
  113. package/dist/src/widgets/AuxToolWidget/Helpers.js +74 -0
  114. package/dist/src/widgets/AuxToolWidget/Insertion.d.ts +2 -0
  115. package/dist/src/widgets/AuxToolWidget/Insertion.js +99 -0
  116. package/dist/src/widgets/AuxToolWidget/Selection.d.ts +7 -0
  117. package/dist/src/widgets/AuxToolWidget/Selection.js +61 -0
  118. package/dist/src/widgets/AuxToolWidget/index.d.ts +5 -0
  119. package/dist/src/widgets/AuxToolWidget/index.js +35 -0
  120. package/dist/src/widgets/DesignerToolsWidget/index.d.ts +9 -0
  121. package/dist/src/widgets/DesignerToolsWidget/index.js +179 -0
  122. package/dist/src/widgets/DroppableWidget/index.d.ts +9 -0
  123. package/dist/src/widgets/DroppableWidget/index.js +20 -0
  124. package/dist/src/widgets/EmptyWidget/index.d.ts +5 -0
  125. package/dist/src/widgets/EmptyWidget/index.js +25 -0
  126. package/dist/src/widgets/GhostWidget/index.d.ts +2 -0
  127. package/dist/src/widgets/GhostWidget/index.js +47 -0
  128. package/dist/src/widgets/HistoryWidget/index.d.ts +2 -0
  129. package/dist/src/widgets/HistoryWidget/index.js +409 -0
  130. package/dist/src/widgets/IconWidget/index.d.ts +26 -0
  131. package/dist/src/widgets/IconWidget/index.js +203 -0
  132. package/dist/src/widgets/NodePathWidget/index.d.ts +6 -0
  133. package/dist/src/widgets/NodePathWidget/index.js +32 -0
  134. package/dist/src/widgets/NodeTitleWidget/index.d.ts +6 -0
  135. package/dist/src/widgets/NodeTitleWidget/index.js +13 -0
  136. package/dist/src/widgets/TextWidget/index.d.ts +10 -0
  137. package/dist/src/widgets/TextWidget/index.js +36 -0
  138. package/dist/src/widgets/ViewToolsWidget/index.d.ts +11 -0
  139. package/dist/src/widgets/ViewToolsWidget/index.js +76 -0
  140. package/dist/src/widgets/index.d.ts +11 -0
  141. package/dist/src/widgets/index.js +11 -0
  142. 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,2 @@
1
+ import type { IDesignerComponents } from "../types.js";
2
+ export declare const useComponents: () => IDesignerComponents;
@@ -0,0 +1,3 @@
1
+ import { useContext } from 'react';
2
+ import { DesignerComponentsContext } from "../context.js";
3
+ export const useComponents = () => useContext(DesignerComponentsContext);
@@ -0,0 +1,2 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ export declare const useCurrentNode: (workspaceId?: string) => TreeNode | undefined;
@@ -0,0 +1,7 @@
1
+ import { useSelected } from "./useSelected.js";
2
+ import { useTree } from "./useTree.js";
3
+ export const useCurrentNode = (workspaceId) => {
4
+ const selected = useSelected(workspaceId);
5
+ const tree = useTree(workspaceId);
6
+ return tree?.findById?.(selected[0]);
7
+ };
@@ -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,2 @@
1
+ import type { Cursor } from '@yimoka/designable-core';
2
+ export declare const useCursor: () => Cursor | undefined;
@@ -0,0 +1,5 @@
1
+ import { useDesigner } from "./useDesigner.js";
2
+ export const useCursor = () => {
3
+ const designer = useDesigner();
4
+ return designer?.cursor;
5
+ };
@@ -0,0 +1,3 @@
1
+ import type { Engine } from '@yimoka/designable-core';
2
+ export type IEffects = (engine: Engine) => void | (() => void);
3
+ export declare const useDesigner: (effects?: IEffects) => Engine | null;
@@ -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,2 @@
1
+ import type { Workspace } from '@yimoka/designable-core';
2
+ export declare const useHistory: (workspaceId?: string) => Workspace["history"] | undefined;
@@ -0,0 +1,5 @@
1
+ import { useWorkspace } from "./useWorkspace.js";
2
+ export const useHistory = (workspaceId) => {
3
+ const workspace = useWorkspace(workspaceId);
4
+ return workspace?.history;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { Hover } from '@yimoka/designable-core';
2
+ export declare const useHover: (workspaceId?: string) => Hover | undefined;
@@ -0,0 +1,5 @@
1
+ import { useOperation } from "./useOperation.js";
2
+ export const useHover = (workspaceId) => {
3
+ const operation = useOperation(workspaceId);
4
+ return operation?.hover;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { IDesignerLayoutContext } from "../types.js";
2
+ export declare const useLayout: () => IDesignerLayoutContext | null;
@@ -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,2 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ export declare const useNodeIdProps: (node?: TreeNode) => Record<string, string>;
@@ -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,2 @@
1
+ import type { Operation } from '@yimoka/designable-core';
2
+ export declare const useOperation: (workspaceId?: string) => Operation | undefined;
@@ -0,0 +1,5 @@
1
+ import { useWorkspace } from "./useWorkspace.js";
2
+ export const useOperation = (workspaceId) => {
3
+ const workspace = useWorkspace(workspaceId);
4
+ return workspace?.operation;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { Viewport } from '@yimoka/designable-core';
2
+ export declare const useOutline: (workspaceId?: string) => Viewport | undefined;
@@ -0,0 +1,5 @@
1
+ import { useWorkspace } from "./useWorkspace.js";
2
+ export const useOutline = (workspaceId) => {
3
+ const workspace = useWorkspace(workspaceId);
4
+ return workspace?.outline;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { Dragon } from '@yimoka/designable-core';
2
+ export declare const useOutlineDragon: (workspaceId?: string) => Dragon | undefined;
@@ -0,0 +1,5 @@
1
+ import { useOperation } from "./useOperation.js";
2
+ export const useOutlineDragon = (workspaceId) => {
3
+ const operation = useOperation(workspaceId);
4
+ return operation?.outlineDragon;
5
+ };
@@ -0,0 +1 @@
1
+ export declare const usePosition: () => "fixed" | "absolute" | "relative" | undefined;
@@ -0,0 +1,2 @@
1
+ import { useLayout } from "./useLayout.js";
2
+ export const usePosition = () => useLayout()?.position;
@@ -0,0 +1 @@
1
+ export declare const usePrefix: (after?: string) => string;
@@ -0,0 +1,5 @@
1
+ import { useLayout } from "./useLayout.js";
2
+ export const usePrefix = (after = '') => {
3
+ const layout = useLayout();
4
+ return (layout?.prefixCls ?? '') + after;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { IDesignerRegistry } from '@yimoka/designable-core';
2
+ export declare const useRegistry: () => IDesignerRegistry;
@@ -0,0 +1,6 @@
1
+ import { GlobalRegistry } from '@yimoka/designable-core';
2
+ import { DESIGNER_REGISTRY_KEY } from "../shared/globals.js";
3
+ export const useRegistry = () => {
4
+ const registry = Reflect.get(globalThis, DESIGNER_REGISTRY_KEY);
5
+ return registry ?? GlobalRegistry;
6
+ };
@@ -0,0 +1,2 @@
1
+ import type { Screen } from '@yimoka/designable-core';
2
+ export declare const useScreen: () => Screen | undefined;
@@ -0,0 +1,2 @@
1
+ import { useDesigner } from "./useDesigner.js";
2
+ export const useScreen = () => useDesigner()?.screen;
@@ -0,0 +1 @@
1
+ export declare const useSelected: (workspaceId?: string) => string[];
@@ -0,0 +1,5 @@
1
+ import { useSelection } from "./useSelection.js";
2
+ export const useSelected = (workspaceId) => {
3
+ const selection = useSelection(workspaceId);
4
+ return selection?.selected ?? [];
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { Selection } from '@yimoka/designable-core';
2
+ export declare const useSelection: (workspaceId?: string) => Selection | undefined;
@@ -0,0 +1,5 @@
1
+ import { useOperation } from "./useOperation.js";
2
+ export const useSelection = (workspaceId) => {
3
+ const operation = useOperation(workspaceId);
4
+ return operation?.selection;
5
+ };
@@ -0,0 +1 @@
1
+ export declare const useTheme: () => string | undefined;
@@ -0,0 +1,2 @@
1
+ import { useLayout } from "./useLayout.js";
2
+ export const useTheme = () => useLayout()?.theme;
@@ -0,0 +1,2 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ export declare const useTree: (workspaceId?: string) => TreeNode | undefined;
@@ -0,0 +1,5 @@
1
+ import { useOperation } from "./useOperation.js";
2
+ export const useTree = (workspaceId) => {
3
+ const operation = useOperation(workspaceId);
4
+ return operation?.tree;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ export declare const useTreeNode: () => TreeNode | null;
@@ -0,0 +1,3 @@
1
+ import { useContext } from 'react';
2
+ import { TreeNodeContext } from "../context.js";
3
+ export const useTreeNode = () => useContext(TreeNodeContext);
@@ -0,0 +1,2 @@
1
+ import type { TreeNode } from '@yimoka/designable-core';
2
+ export declare const useValidNodeOffsetRect: (node: TreeNode) => DOMRect | 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,2 @@
1
+ import type { Viewport } from '@yimoka/designable-core';
2
+ export declare const useViewport: (workspaceId?: string) => Viewport | undefined;
@@ -0,0 +1,5 @@
1
+ import { useWorkspace } from "./useWorkspace.js";
2
+ export const useViewport = (workspaceId) => {
3
+ const workspace = useWorkspace(workspaceId);
4
+ return workspace?.viewport;
5
+ };
@@ -0,0 +1,3 @@
1
+ import type { Dragon } from '@yimoka/designable-core';
2
+ export declare const useViewportDragon: (workspaceId?: string) => Dragon | undefined;
3
+ export declare const useDragon: (workspaceId?: string) => Dragon | undefined;
@@ -0,0 +1,6 @@
1
+ import { useOperation } from "./useOperation.js";
2
+ export const useViewportDragon = (workspaceId) => {
3
+ const operation = useOperation(workspaceId);
4
+ return operation?.viewportDragon;
5
+ };
6
+ export const useDragon = useViewportDragon;
@@ -0,0 +1,2 @@
1
+ import type { Workbench } from '@yimoka/designable-core';
2
+ export declare const useWorkbench: () => Workbench | undefined;
@@ -0,0 +1,5 @@
1
+ import { useDesigner } from "./useDesigner.js";
2
+ export const useWorkbench = () => {
3
+ const designer = useDesigner();
4
+ return designer?.workbench;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { Workspace } from '@yimoka/designable-core';
2
+ export declare const useWorkspace: (id?: string) => Workspace | undefined;
@@ -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;
@@ -0,0 +1,16 @@
1
+ export default {
2
+ 'zh-CN': {
3
+ save: '保存',
4
+ submit: '提交',
5
+ cancel: '取消',
6
+ reset: '重置',
7
+ publish: '发布',
8
+ },
9
+ 'en-US': {
10
+ save: 'Save',
11
+ submit: 'Submit',
12
+ cancel: 'Cancel',
13
+ reset: 'Reset',
14
+ publish: 'Publish',
15
+ },
16
+ };