@tmagic/editor 1.0.0-beta.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 (98) hide show
  1. package/dist/style.css +505 -0
  2. package/dist/tmagic-editor.es.js +4233 -0
  3. package/dist/tmagic-editor.es.js.map +1 -0
  4. package/dist/tmagic-editor.umd.js +4276 -0
  5. package/dist/tmagic-editor.umd.js.map +1 -0
  6. package/dist/types/src/Editor.vue.d.ts +136 -0
  7. package/dist/types/src/components/Icon.vue.d.ts +13 -0
  8. package/dist/types/src/components/ToolButton.vue.d.ts +35 -0
  9. package/dist/types/src/fields/Code.vue.d.ts +24 -0
  10. package/dist/types/src/fields/CodeLink.vue.d.ts +54 -0
  11. package/dist/types/src/fields/UISelect.vue.d.ts +32 -0
  12. package/dist/types/src/index.d.ts +19 -0
  13. package/dist/types/src/layouts/AddPageBox.vue.d.ts +5 -0
  14. package/dist/types/src/layouts/CodeEditor.vue.d.ts +46 -0
  15. package/dist/types/src/layouts/Framework.vue.d.ts +11 -0
  16. package/dist/types/src/layouts/NavMenu.vue.d.ts +24 -0
  17. package/dist/types/src/layouts/PropsPanel.vue.d.ts +13 -0
  18. package/dist/types/src/layouts/Resizer.vue.d.ts +13 -0
  19. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +12 -0
  20. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +31 -0
  21. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +973 -0
  22. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +27 -0
  23. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +11 -0
  24. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +153 -0
  25. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +18 -0
  26. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +37 -0
  27. package/dist/types/src/services/BaseService.d.ts +56 -0
  28. package/dist/types/src/services/editor.d.ts +122 -0
  29. package/dist/types/src/services/events.d.ts +16 -0
  30. package/dist/types/src/services/history.d.ts +51 -0
  31. package/dist/types/src/services/props.d.ts +36 -0
  32. package/dist/types/src/services/ui.d.ts +26 -0
  33. package/dist/types/src/shims-vue.d.ts +6 -0
  34. package/dist/types/src/type.d.ts +183 -0
  35. package/dist/types/src/utils/compose.d.ts +5 -0
  36. package/dist/types/src/utils/config.d.ts +4 -0
  37. package/dist/types/src/utils/editor.d.ts +45 -0
  38. package/dist/types/src/utils/index.d.ts +4 -0
  39. package/dist/types/src/utils/logger.d.ts +5 -0
  40. package/dist/types/src/utils/props.d.ts +49 -0
  41. package/dist/types/src/utils/undo-redo.d.ts +12 -0
  42. package/dist/types/src/vite-env.d.ts +1 -0
  43. package/package.json +57 -0
  44. package/src/Editor.vue +234 -0
  45. package/src/components/Icon.vue +29 -0
  46. package/src/components/ToolButton.vue +188 -0
  47. package/src/fields/Code.vue +35 -0
  48. package/src/fields/CodeLink.vue +81 -0
  49. package/src/fields/UISelect.vue +100 -0
  50. package/src/index.ts +63 -0
  51. package/src/layouts/AddPageBox.vue +41 -0
  52. package/src/layouts/CodeEditor.vue +188 -0
  53. package/src/layouts/Framework.vue +73 -0
  54. package/src/layouts/NavMenu.vue +37 -0
  55. package/src/layouts/PropsPanel.vue +81 -0
  56. package/src/layouts/Resizer.vue +61 -0
  57. package/src/layouts/sidebar/ComponentListPanel.vue +69 -0
  58. package/src/layouts/sidebar/LayerMenu.vue +117 -0
  59. package/src/layouts/sidebar/LayerPanel.vue +209 -0
  60. package/src/layouts/sidebar/Sidebar.vue +86 -0
  61. package/src/layouts/workspace/PageBar.vue +83 -0
  62. package/src/layouts/workspace/Stage.vue +221 -0
  63. package/src/layouts/workspace/ViewerMenu.vue +110 -0
  64. package/src/layouts/workspace/Workspace.vue +98 -0
  65. package/src/services/BaseService.ts +138 -0
  66. package/src/services/componentList.ts +48 -0
  67. package/src/services/editor.ts +521 -0
  68. package/src/services/events.ts +82 -0
  69. package/src/services/history.ts +124 -0
  70. package/src/services/props.ts +110 -0
  71. package/src/services/ui.ts +101 -0
  72. package/src/shims-vue.d.ts +6 -0
  73. package/src/theme/code-editor.scss +7 -0
  74. package/src/theme/common/var.scss +13 -0
  75. package/src/theme/component-list-panel.scss +102 -0
  76. package/src/theme/content-menu.scss +39 -0
  77. package/src/theme/framework.scss +72 -0
  78. package/src/theme/index.scss +13 -0
  79. package/src/theme/layer-panel.scss +68 -0
  80. package/src/theme/nav-menu.scss +69 -0
  81. package/src/theme/page-bar.scss +31 -0
  82. package/src/theme/props-panel.scss +17 -0
  83. package/src/theme/resizer.scss +51 -0
  84. package/src/theme/ruler.scss +38 -0
  85. package/src/theme/sidebar.scss +97 -0
  86. package/src/theme/stage.scss +22 -0
  87. package/src/theme/workspace.scss +5 -0
  88. package/src/type.ts +236 -0
  89. package/src/utils/compose.ts +33 -0
  90. package/src/utils/config.ts +29 -0
  91. package/src/utils/editor.ts +244 -0
  92. package/src/utils/index.ts +22 -0
  93. package/src/utils/logger.ts +47 -0
  94. package/src/utils/props.ts +218 -0
  95. package/src/utils/undo-redo.ts +76 -0
  96. package/src/vite-env.d.ts +1 -0
  97. package/tsconfig.json +9 -0
  98. package/vite.config.ts +30 -0
@@ -0,0 +1,68 @@
1
+ .magic-editor-layer-panel {
2
+ background: $--sidebar-content-background-color;
3
+
4
+ .search-input {
5
+ background: $--sidebar-content-background-color;
6
+ color: #bbbbbb;
7
+ padding: 10px;
8
+ position: absolute;
9
+ top: 0;
10
+ left: 0;
11
+ z-index: 1;
12
+
13
+ .el-input__suffix {
14
+ padding: 10px 5px;
15
+ }
16
+ }
17
+ .node-content {
18
+ flex: 1;
19
+ display: flex;
20
+ width: 100%;
21
+ > div {
22
+ width: 8px;
23
+ }
24
+ > span {
25
+ width: calc(100% - 68px);
26
+ white-space: nowrap;
27
+ overflow: hidden;
28
+ text-overflow: ellipsis;
29
+ }
30
+ > i {
31
+ margin-right: 10px;
32
+ font-size: 20px;
33
+ &.lock {
34
+ color: #bbb;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ .magic-editor-layer-panel,
40
+ .magic-editor-layer-panel .el-tree {
41
+ background-color: $--sidebar-content-background-color;
42
+ color: #313a40;
43
+ }
44
+
45
+ .magic-editor-layer-panel
46
+ .el-tree--highlight-current
47
+ .el-tree-node.is-current
48
+ > .el-tree-node__content {
49
+ background-color: $--sidebar-heder-background-color;
50
+ color: #fff;
51
+ }
52
+
53
+ .magic-editor-layer-panel .el-tree-node:focus > .el-tree-node__content {
54
+ background-color: $--sidebar-heder-background-color;
55
+ color: #fff;
56
+ }
57
+ .ui-tree-tip {
58
+ width: 100%;
59
+ height: 25px;
60
+ margin-left: 10px;
61
+ background: $--sidebar-content-background-color;
62
+ font-style: italic;
63
+ color: #555554;
64
+ position: absolute;
65
+ top: 40px;
66
+ left: 0;
67
+ z-index: 1;
68
+ }
@@ -0,0 +1,69 @@
1
+ .m-editor-nav-menu {
2
+ display: flex;
3
+ z-index: 5;
4
+ -webkit-box-pack: justify;
5
+ justify-content: space-between;
6
+ -webkit-box-align: center;
7
+ align-items: center;
8
+ background-color: $--nav--background-color;
9
+ font-size: 19.2px;
10
+ color: $--nav-color;
11
+ font-weight: 400;
12
+ box-sizing: border-box;
13
+ margin: 0px;
14
+ flex: 0 0 $--nav-height;
15
+ border-bottom: 1px solid #d8dee8;
16
+
17
+ > div {
18
+ display: flex;
19
+ height: 100%;
20
+ z-index: 1;
21
+ align-items: center;
22
+ }
23
+
24
+ .menu-left {
25
+ padding-left: 16px;
26
+ }
27
+
28
+ .menu-right {
29
+ padding-right: 16px;
30
+ }
31
+
32
+ .menu-item {
33
+ flex-direction: row;
34
+ -webkit-box-align: center;
35
+ align-items: center;
36
+ vertical-align: middle;
37
+ font-size: 14px;
38
+ line-height: 1;
39
+ height: 100%;
40
+ color: rgba(255, 255, 255, 0.7);
41
+ box-sizing: inherit;
42
+ z-index: 1;
43
+ display: flex !important;
44
+ transition: all 0.3s ease 0s;
45
+ border-bottom: 2px solid transparent;
46
+ margin: 0 5px;
47
+
48
+ .is-disabled {
49
+ opacity: 0.5;
50
+ }
51
+
52
+ .el-button--text,
53
+ i {
54
+ color: $--font-color;
55
+ }
56
+
57
+ .icon {
58
+ display: flex;
59
+ -webkit-box-align: center;
60
+ align-items: center;
61
+ height: 100%;
62
+ padding: 0px 8px;
63
+ }
64
+
65
+ .menu-item-text {
66
+ color: $--nav-color;
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,31 @@
1
+ .m-editor-page-bar {
2
+ position: fixed;
3
+ bottom: 0;
4
+ left: 0;
5
+ display: flex;
6
+ width: 100%;
7
+ height: $--page-bar-height;
8
+ line-height: $--page-bar-height;
9
+ background-color: #f3f3f3;
10
+ color: $--font-color;
11
+ border-top: 1px solid $--border-color;
12
+ z-index: 2;
13
+
14
+ .m-editor-page-bar-item {
15
+ padding: 0 10px;
16
+ cursor: pointer;
17
+ border-right: 1px solid $--border-color;
18
+ display: flex;
19
+ justify-items: center;
20
+ align-items: center;
21
+
22
+ &.active {
23
+ background-color: #fff;
24
+ cursor: text;
25
+
26
+ .m-editor-page-bar-menu-icon {
27
+ cursor: pointer;
28
+ }
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,17 @@
1
+ .m-editor-props-panel {
2
+ padding: 0 10px;
3
+
4
+ .el-form-item__label {
5
+ font-size: 12px;
6
+ }
7
+
8
+ .m-fieldset {
9
+ legend {
10
+ font-size: 12px;
11
+ }
12
+ }
13
+
14
+ .el-tabs__item {
15
+ font-size: 12px;
16
+ }
17
+ }
@@ -0,0 +1,51 @@
1
+ .m-editor-resizer {
2
+ border-left: 1px solid transparent;
3
+ border-right: 1px solid transparent;
4
+ width: 8px;
5
+ margin: 0 -5px;
6
+ height: 100%;
7
+ opacity: 0.9;
8
+ background: padding-box #d8dee8;
9
+ box-sizing: border-box;
10
+ cursor: col-resize;
11
+ z-index: 1;
12
+
13
+ &:hover {
14
+ border-color: #d8dee8;
15
+ }
16
+
17
+ .icon-container {
18
+ visibility: hidden;
19
+ opacity: 0;
20
+ transition: opacity 0.4s;
21
+ width: 20px;
22
+ height: 120px;
23
+ line-height: 120px;
24
+ text-align: center;
25
+ background: #d8dee8;
26
+ position: absolute;
27
+ top: 50%;
28
+ left: 50%;
29
+ transform: translate(-50%, -50%);
30
+ cursor: pointer;
31
+ &.position-left {
32
+ transform: translate(calc(-100% - 4px), -50%);
33
+ }
34
+ &.position-right {
35
+ transform: translate(calc(100% + 4px), -50%);
36
+ }
37
+ }
38
+ .icon {
39
+ color: #fff;
40
+ font-size: 18px;
41
+ }
42
+ }
43
+
44
+ .magic-editor-resizer:hover {
45
+ .icon-container {
46
+ visibility: visible;
47
+ opacity: 1;
48
+ }
49
+ // border-left: 5px solid rgba(0,0,0,.5);
50
+ // border-right: 5px solid rgba(0,0,0,.5);
51
+ }
@@ -0,0 +1,38 @@
1
+ #ruler-container {
2
+ width: calc(100% + 40px);
3
+ position: absolute;
4
+ top: -40px;
5
+ left: -40px;
6
+ height: 40px;
7
+ z-index: 100000;
8
+
9
+ .moveable-line {
10
+ display: none;
11
+ }
12
+
13
+ .moveable-control.moveable-origin {
14
+ display: none;
15
+ }
16
+ }
17
+
18
+ #ruler-container::after {
19
+ content: "";
20
+ position: absolute;
21
+ left: 100%;
22
+ top: 0;
23
+ width: calc(2000px - 100%);
24
+ height: 100%;
25
+ background-color: white;
26
+ }
27
+
28
+ #horizontal {
29
+ width: 2000px;
30
+ max-width: fit-content;
31
+ }
32
+
33
+ #vertical {
34
+ position: absolute;
35
+ height: 1000px;
36
+ top: 0;
37
+ left: 0;
38
+ }
@@ -0,0 +1,97 @@
1
+ .m-editor-sidebar {
2
+ height: 100%;
3
+
4
+ &.el-tabs--left .el-tabs__header {
5
+ background: $--sidebar-heder-background-color;
6
+ border: 0;
7
+
8
+ &.is-left {
9
+ width: 40px;
10
+ margin-right: 0;
11
+ }
12
+
13
+ .el-tabs__nav-wrap {
14
+ margin: 0;
15
+ }
16
+
17
+ .el-tabs__nav {
18
+ border: 0;
19
+ border-radius: 0;
20
+ }
21
+
22
+ .tab-label {
23
+ margin-left: 2px;
24
+ }
25
+
26
+ .el-tabs__item.is-left {
27
+ line-height: 15px;
28
+ border: 0;
29
+ height: auto;
30
+ padding: 8px;
31
+ color: rgb(255, 255, 255);
32
+ box-sizing: border-box;
33
+
34
+ &.is-left {
35
+ &.is-active {
36
+ background: $--sidebar-content-background-color;
37
+ border: 0;
38
+
39
+ i {
40
+ color: #353140;
41
+ }
42
+
43
+ .magic-editor-tab-panel-title {
44
+ color: #353140;
45
+ }
46
+ }
47
+
48
+ &:first-child {
49
+ border-right: 0;
50
+ }
51
+ }
52
+ }
53
+
54
+ i {
55
+ font-size: 25px;
56
+ color: rgba(255, 255, 255, 0.6);
57
+
58
+ &:hover {
59
+ color: rgb(255, 255, 255);
60
+ }
61
+ }
62
+
63
+ .magic-editor-tab-panel-title {
64
+ font-size: 12px;
65
+ white-space: normal;
66
+ }
67
+ }
68
+
69
+ .el-scrollbar {
70
+ height: 100%;
71
+ }
72
+
73
+ .el-tree {
74
+ min-height: 100%;
75
+ }
76
+
77
+ .fold-icon {
78
+ position: absolute;
79
+ bottom: 8px;
80
+ left: 0px;
81
+ width: 45px;
82
+ padding-left: 8px;
83
+ color: #fff;
84
+ font-size: 32px;
85
+ opacity: 0.8;
86
+ cursor: pointer;
87
+
88
+ &:hover {
89
+ background: rgba(0, 0, 0, 0.2);
90
+ }
91
+ }
92
+
93
+ .el-tabs__content,
94
+ .el-tab-pane {
95
+ height: 100%;
96
+ }
97
+ }
@@ -0,0 +1,22 @@
1
+ .m-editor-stage {
2
+ position: relative;
3
+ width: 100%;
4
+ height: calc(100% - $--page-bar-height);
5
+ overflow: auto;
6
+ }
7
+
8
+ .m-editor-stage-container {
9
+ transition: transform 0.3s;
10
+ transform-origin: center -50%;
11
+ z-index: 0;
12
+ top: 50%;
13
+ margin: 0 auto;
14
+ position: relative;
15
+ width: 375px;
16
+ height: 80%;
17
+ border: 1px solid $--border-color;
18
+
19
+ &::-webkit-scrollbar {
20
+ width: 0 !important;
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ .m-editor-workspace {
2
+ height: 100%;
3
+ width: 100%;
4
+ user-select: none;
5
+ }
package/src/type.ts ADDED
@@ -0,0 +1,236 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { Component } from 'vue';
20
+
21
+ import { FormConfig } from '@tmagic/form';
22
+ import { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
23
+ import StageCore from '@tmagic/stage';
24
+
25
+ import type { ComponentListService } from '@editor/services/componentList';
26
+ import type { EditorService } from '@editor/services/editor';
27
+ import type { EventsService } from '@editor/services/events';
28
+ import type { HistoryService } from '@editor/services/history';
29
+ import type { PropsService } from '@editor/services/props';
30
+ import type { UiService } from '@editor/services/ui';
31
+
32
+ export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
33
+ export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
34
+
35
+ export interface InstallOptions {
36
+ [key: string]: any;
37
+ }
38
+
39
+ export interface Services {
40
+ editorService: EditorService;
41
+ historyService: HistoryService;
42
+ eventsService: EventsService;
43
+ propsService: PropsService;
44
+ componentListService: ComponentListService;
45
+ uiService: UiService;
46
+ }
47
+
48
+ export interface StoreState {
49
+ root: MApp | null;
50
+ page: MPage | null;
51
+ parent: MContainer | null;
52
+ node: MNode | null;
53
+ stage: StageCore | null;
54
+ modifiedNodeIds: Map<Id, Id>;
55
+ }
56
+
57
+ export interface PropsState {
58
+ propsConfigMap: Record<string, FormConfig>;
59
+ propsValueMap: Record<string, MNode>;
60
+ }
61
+
62
+ export interface ComponentGroupState {
63
+ list: ComponentGroup[];
64
+ }
65
+
66
+ export interface SetColumnWidth {
67
+ left?: number;
68
+ center?: number | 'auto';
69
+ right?: number;
70
+ }
71
+
72
+ export interface GetColumnWidth {
73
+ left: number;
74
+ center: number;
75
+ right: number;
76
+ }
77
+
78
+ export interface UiState {
79
+ /** 当前点击画布是否触发选中,true: 不触发,false: 触发,默认为false */
80
+ uiSelectMode: boolean;
81
+ /** 是否显示整个配置源码, true: 显示, false: 不显示,默认为false */
82
+ showSrc: boolean;
83
+ /** 画布显示放大倍数,默认为 1 */
84
+ zoom: number;
85
+ /** 画布顶层div的样式,可用于改变画布的大小 */
86
+ stageStyle: Record<string, string | number>;
87
+ /** 编辑器列布局每一列的宽度,分为左中右三列 */
88
+ columnWidth: GetColumnWidth;
89
+ /** 是否显示画布参考线,true: 显示,false: 不显示,默认为true */
90
+ showGuides: boolean;
91
+ /** 是否显示标尺,true: 显示,false: 不显示,默认为true */
92
+ showRule: boolean;
93
+ }
94
+
95
+ export interface EditorNodeInfo {
96
+ node?: MNode;
97
+ parent?: MContainer;
98
+ page?: MPage;
99
+ }
100
+
101
+ export interface AddMNode {
102
+ type: string;
103
+ name?: string;
104
+ [key: string]: any;
105
+ }
106
+
107
+ /**
108
+ * 菜单按钮
109
+ */
110
+ export interface MenuButton {
111
+ /**
112
+ * 按钮类型
113
+ * button: 只有文字不带边框的按钮
114
+ * text: 纯文本
115
+ * dropdown: 下拉菜单
116
+ * divider: 分隔线
117
+ * zoom: 放大缩小
118
+ */
119
+ type: 'button' | 'dropdown' | 'text' | 'divider' | 'zoom';
120
+ /** 展示的文案 */
121
+ text?: string;
122
+ /** 鼠标悬浮是显示的气泡中的文案 */
123
+ tooltip?: string;
124
+ /** element-plus icon class */
125
+ icon?: string | Component<{}, {}, any>;
126
+ /** 是否置灰,默认为false */
127
+ disabled?: boolean | ((data?: Services) => boolean);
128
+ /** 是否显示,默认为true */
129
+ display?: boolean | ((data?: Services) => boolean);
130
+ /** type为button/dropdown时点击运行的方法 */
131
+ handler?: (data?: Services) => Promise<any> | any;
132
+ /** type为dropdown时,下拉的菜单列表 */
133
+ items?: {
134
+ /** 展示的文案 */
135
+ text: string;
136
+ /** 点击运行的方法 */
137
+ handler(data: Services): any;
138
+ }[];
139
+ }
140
+
141
+ export interface MenuComponent {
142
+ type: 'component';
143
+ /** Vue3组件 */
144
+ component: any;
145
+ /** 传入组件的props对象 */
146
+ props?: Record<string, any>;
147
+ /** 组件监听的事件对象,如:{ click: () => { console.log('click'); } } */
148
+ listeners?: Record<string, Function>;
149
+ slots?: Record<string, any>;
150
+ /** 是否显示,默认为true */
151
+ display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
152
+ }
153
+
154
+ /**
155
+ * '/': 分隔符
156
+ * 'delete': 删除按钮
157
+ * 'undo': 撤销按钮
158
+ * 'redo': 恢复按钮
159
+ * 'zoom-in': 放大按钮
160
+ * 'zoom-out': 缩小按钮
161
+ */
162
+ export type MenuItem =
163
+ | '/'
164
+ | 'delete'
165
+ | 'undo'
166
+ | 'redo'
167
+ | 'zoom'
168
+ | 'zoom-in'
169
+ | 'zoom-out'
170
+ | 'guides'
171
+ | 'rule'
172
+ | MenuButton
173
+ | MenuComponent;
174
+
175
+ /** 工具栏 */
176
+ export interface MenuBarData {
177
+ /** 顶部工具栏左边项 */
178
+ left?: MenuItem[];
179
+ /** 顶部工具栏中间项 */
180
+ center?: MenuItem[];
181
+ /** 顶部工具栏右边项 */
182
+ right?: MenuItem[];
183
+ }
184
+
185
+ export interface SideComponent extends MenuComponent {
186
+ /** 显示文案 */
187
+ text: string;
188
+ /** element-plus icon class */
189
+ icon: Component<{}, {}, any>;
190
+ }
191
+
192
+ /**
193
+ * component-list: 组件列表
194
+ * layer: 已选组件树
195
+ */
196
+ export type SideItem = 'component-list' | 'layer' | SideComponent;
197
+
198
+ /** 工具栏 */
199
+ export interface SideBarData {
200
+ /** 容器类型 */
201
+ type: 'tabs';
202
+ /** 默认激活的内容 */
203
+ status: string;
204
+ /** panel列表 */
205
+ items: SideItem[];
206
+ }
207
+
208
+ export interface ComponentItem {
209
+ /** 显示文案 */
210
+ text: string;
211
+ /** 组件类型 */
212
+ type: string;
213
+ /** element-plus icon class */
214
+ icon?: string | Component;
215
+ [key: string]: any;
216
+ }
217
+
218
+ export interface ComponentGroup {
219
+ /** 显示文案 */
220
+ title: string;
221
+ /** 组内列表 */
222
+ items: ComponentItem[];
223
+ }
224
+
225
+ export enum LayerOffset {
226
+ TOP = 'top',
227
+ BOTTOM = 'bottom',
228
+ }
229
+
230
+ /** 容器布局 */
231
+ export enum Layout {
232
+ FLEX = 'flex',
233
+ FIXED = 'fixed',
234
+ RELATIVE = 'relative',
235
+ ABSOLUTE = 'absolute',
236
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @param {Array} middleware
3
+ * @return {Function}
4
+ */
5
+ export const compose = (middleware: Function[]) => {
6
+ if (!Array.isArray(middleware)) throw new TypeError('Middleware 必须是一个数组!');
7
+ for (const fn of middleware) {
8
+ if (typeof fn !== 'function') throw new TypeError('Middleware 必须由函数组成!');
9
+ }
10
+
11
+ /**
12
+ * @param {Object} args
13
+ * @return {Promise}
14
+ * @api public
15
+ */
16
+ return (args: any[], next?: Function) => {
17
+ // last called middleware #
18
+ let index = -1;
19
+ return dispatch(0);
20
+ function dispatch(i: number): Promise<void> {
21
+ if (i <= index) return Promise.reject(new Error('next() 被多次调用'));
22
+ index = i;
23
+ let fn = middleware[i];
24
+ if (i === middleware.length && next) fn = next;
25
+ if (!fn) return Promise.resolve();
26
+ try {
27
+ return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
28
+ } catch (err) {
29
+ return Promise.reject(err);
30
+ }
31
+ }
32
+ };
33
+ };
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { InstallOptions } from '@editor/type';
20
+
21
+ let $TMAGIC_EDITOR: InstallOptions = {} as any;
22
+
23
+ const setConfig = (option: InstallOptions): void => {
24
+ $TMAGIC_EDITOR = option;
25
+ };
26
+
27
+ const getConfig = (key: keyof InstallOptions): unknown => $TMAGIC_EDITOR[key];
28
+
29
+ export { getConfig, setConfig };