@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,13 @@
1
+ import { observer } from '@formily/reactive-react';
2
+ import React, { Fragment } from 'react';
3
+ export const NodeTitleWidget = observer((props) => {
4
+ const takeNode = () => {
5
+ const { node } = props;
6
+ if (node.componentName === '$$ResourceNode$$') {
7
+ return node.children[0];
8
+ }
9
+ return node;
10
+ };
11
+ const node = takeNode();
12
+ return React.createElement(Fragment, null, node.getMessage('title') || node.componentName);
13
+ });
@@ -0,0 +1,10 @@
1
+ import type { IDesignerMiniLocales } from '@yimoka/designable-core';
2
+ import React from 'react';
3
+ export interface ITextWidgetProps {
4
+ componentName?: string;
5
+ sourceName?: string;
6
+ token?: string | IDesignerMiniLocales;
7
+ defaultMessage?: string | IDesignerMiniLocales;
8
+ children?: React.ReactNode;
9
+ }
10
+ export declare const TextWidget: React.FC<ITextWidgetProps>;
@@ -0,0 +1,36 @@
1
+ import { observer } from '@formily/reactive-react';
2
+ import { GlobalRegistry } from '@yimoka/designable-core';
3
+ import { isPlainObject, isString } from 'lodash-es';
4
+ import React, { Fragment } from 'react';
5
+ export const TextWidget = observer((props) => {
6
+ const takeLocale = (message) => {
7
+ if (isString(message))
8
+ return message;
9
+ if (isPlainObject(message)) {
10
+ const lang = GlobalRegistry.getDesignerLanguage();
11
+ const msgObj = message;
12
+ for (const key of Object.keys(msgObj)) {
13
+ if (key.toLocaleLowerCase() === lang)
14
+ return msgObj[key];
15
+ }
16
+ return null;
17
+ }
18
+ return null;
19
+ };
20
+ const takeMessage = (token) => {
21
+ if (!token)
22
+ return null;
23
+ const message = isString(token)
24
+ ? GlobalRegistry.getDesignerMessage(token)
25
+ : token;
26
+ if (message && (isString(message) || isPlainObject(message))) {
27
+ return takeLocale(message);
28
+ }
29
+ if (isString(token))
30
+ return token;
31
+ return null;
32
+ };
33
+ return (React.createElement(Fragment, null, takeMessage(props.children)
34
+ || takeMessage(props.token)
35
+ || takeMessage(props.defaultMessage)));
36
+ });
@@ -0,0 +1,11 @@
1
+ import { type WorkbenchTypes } from '@yimoka/designable-core';
2
+ import React from 'react';
3
+ export interface IViewToolsWidget {
4
+ activeType?: WorkbenchTypes;
5
+ className?: string;
6
+ onChange?: (type: WorkbenchTypes) => void;
7
+ style?: React.CSSProperties;
8
+ syncWorkbench?: boolean;
9
+ use?: WorkbenchTypes[];
10
+ }
11
+ export declare const ViewToolsWidget: React.FC<IViewToolsWidget>;
@@ -0,0 +1,76 @@
1
+ import { CodeOutlined, EditOutlined, FileTextOutlined, PlayCircleOutlined, } from '@ant-design/icons';
2
+ import { observer } from '@formily/reactive-react';
3
+ import { CursorStatus, CursorType, resetDragDropState, } from '@yimoka/designable-core';
4
+ import cls from 'classnames';
5
+ import React from 'react';
6
+ import { useUIAdapter } from "../../adapter/index.js";
7
+ import { useOperation, usePrefix, useRegistry, useWorkbench } from "../../hooks/index.js";
8
+ import { IconWidget } from "../IconWidget/index.js";
9
+ const VIEW_TOOL_OPTIONS = [
10
+ {
11
+ ariaLabel: '切换到设计视图',
12
+ iconName: 'Design',
13
+ infer: React.createElement(EditOutlined, null),
14
+ title: '设计',
15
+ type: 'DESIGNABLE',
16
+ },
17
+ {
18
+ ariaLabel: '切换到 JSON 视图',
19
+ iconName: 'JSON',
20
+ infer: React.createElement(FileTextOutlined, null),
21
+ title: 'JSON',
22
+ type: 'JSONTREE',
23
+ },
24
+ {
25
+ ariaLabel: '切换到代码视图',
26
+ iconName: 'Code',
27
+ infer: React.createElement(CodeOutlined, null),
28
+ title: '代码',
29
+ type: 'MARKUP',
30
+ },
31
+ {
32
+ ariaLabel: '切换到预览视图',
33
+ iconName: 'Play',
34
+ infer: React.createElement(PlayCircleOutlined, null),
35
+ title: '预览',
36
+ type: 'PREVIEW',
37
+ },
38
+ ];
39
+ export const ViewToolsWidget = observer(({ activeType, className, onChange, style, syncWorkbench = true, use = ['DESIGNABLE', 'JSONTREE', 'PREVIEW'], }) => {
40
+ const { Button, ButtonGroup, Tooltip } = useUIAdapter();
41
+ const workbench = useWorkbench();
42
+ const operation = useOperation();
43
+ const registry = useRegistry();
44
+ const prefix = usePrefix('view-tools');
45
+ const getIconTooltip = (iconName, fallback) => {
46
+ const token = `icons.${iconName}`;
47
+ const tooltip = registry?.getDesignerMessage(token);
48
+ if (!tooltip) {
49
+ return fallback;
50
+ }
51
+ return String(tooltip);
52
+ };
53
+ const switchWorkbenchType = (type) => {
54
+ resetDragDropState();
55
+ operation?.dragClean();
56
+ operation?.hover?.clear?.();
57
+ workbench?.engine?.cursor.setType(CursorType.Move);
58
+ workbench?.engine?.cursor.setStatus(CursorStatus.Normal);
59
+ if (syncWorkbench) {
60
+ const setWorkbenchType = workbench?.setWorkbenchType;
61
+ setWorkbenchType?.(type, { cleanTransient: false });
62
+ }
63
+ onChange?.(type);
64
+ };
65
+ return (React.createElement(ButtonGroup, { className: cls(prefix, className), style: style }, VIEW_TOOL_OPTIONS
66
+ .filter(option => use.includes(option.type))
67
+ .map((option) => {
68
+ const isCurrent = (activeType ?? workbench?.type) === option.type;
69
+ return (React.createElement(Tooltip, { key: option.type, title: getIconTooltip(option.iconName, option.title) },
70
+ React.createElement(Button, { ariaCurrent: isCurrent ? 'page' : undefined, ariaLabel: option.ariaLabel, ariaPressed: isCurrent, className: cls(`${prefix}-item`, isCurrent && `${prefix}-item-active`), disabled: isCurrent, type: isCurrent ? 'primary' : 'default', onClick: () => {
71
+ switchWorkbenchType(option.type);
72
+ } },
73
+ React.createElement(IconWidget, { infer: option.infer }))));
74
+ })));
75
+ });
76
+ ViewToolsWidget.displayName = 'ViewToolsWidget';
@@ -0,0 +1,11 @@
1
+ export * from "./IconWidget/index.js";
2
+ export * from "./TextWidget/index.js";
3
+ export * from "./NodeTitleWidget/index.js";
4
+ export * from "./GhostWidget/index.js";
5
+ export * from "./HistoryWidget/index.js";
6
+ export * from "./NodePathWidget/index.js";
7
+ export * from "./DesignerToolsWidget/index.js";
8
+ export * from "./ViewToolsWidget/index.js";
9
+ export * from "./DroppableWidget/index.js";
10
+ export * from "./EmptyWidget/index.js";
11
+ export * from "./AuxToolWidget/index.js";
@@ -0,0 +1,11 @@
1
+ export * from "./IconWidget/index.js";
2
+ export * from "./TextWidget/index.js";
3
+ export * from "./NodeTitleWidget/index.js";
4
+ export * from "./GhostWidget/index.js";
5
+ export * from "./HistoryWidget/index.js";
6
+ export * from "./NodePathWidget/index.js";
7
+ export * from "./DesignerToolsWidget/index.js";
8
+ export * from "./ViewToolsWidget/index.js";
9
+ export * from "./DroppableWidget/index.js";
10
+ export * from "./EmptyWidget/index.js";
11
+ export * from "./AuxToolWidget/index.js";
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@yimoka/designable-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "license": "MIT",
5
+ "author": {
6
+ "name": "ickeep",
7
+ "email": "i@ickeep.com",
8
+ "url": "https://github.com/ickeep"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/zhixingdx/oipivot.git",
13
+ "directory": "frontend/packages/designable-react"
14
+ },
15
+ "type": "module",
16
+ "dependencies": {
17
+ "@ant-design/icons": "^6.2.5",
18
+ "@formily/core": "^2.3.7",
19
+ "@formily/json-schema": "^2.3.7",
20
+ "@formily/path": "^2.3.7",
21
+ "@formily/reactive": "^2.3.7",
22
+ "@formily/reactive-react": "^2.3.7",
23
+ "@juggle/resize-observer": "^3.4.0",
24
+ "@yimoka/designable-core": "0.1.1",
25
+ "@yimoka/shared": "0.1.1",
26
+ "classnames": "^2.5.1",
27
+ "lodash-es": "^4.18.1"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^18.0.0 || ^19.0.0",
31
+ "react-dom": "^18.0.0 || ^19.0.0"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/src/index.d.ts",
36
+ "import": "./dist/src/index.js",
37
+ "default": "./dist/src/index.js"
38
+ },
39
+ "./adapter": {
40
+ "types": "./dist/src/adapter/index.d.ts",
41
+ "import": "./dist/src/adapter/index.js",
42
+ "default": "./dist/src/adapter/index.js"
43
+ },
44
+ "./containers": {
45
+ "types": "./dist/src/containers/index.d.ts",
46
+ "import": "./dist/src/containers/index.js",
47
+ "default": "./dist/src/containers/index.js"
48
+ },
49
+ "./hooks": {
50
+ "types": "./dist/src/hooks/index.d.ts",
51
+ "import": "./dist/src/hooks/index.js",
52
+ "default": "./dist/src/hooks/index.js"
53
+ },
54
+ "./widgets": {
55
+ "types": "./dist/src/widgets/index.d.ts",
56
+ "import": "./dist/src/widgets/index.js",
57
+ "default": "./dist/src/widgets/index.js"
58
+ }
59
+ },
60
+ "main": "./dist/src/index.js",
61
+ "module": "./dist/src/index.js",
62
+ "types": "./dist/src/index.d.ts"
63
+ }