@tmagic/editor 1.3.7 → 1.3.9
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/style.css +19 -0
- package/dist/tmagic-editor.js +80 -30
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +80 -31
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +12 -11
- package/src/Editor.vue +5 -0
- package/src/components/Tree.vue +1 -1
- package/src/fields/PageFragmentSelect.vue +11 -3
- package/src/layouts/CodeEditor.vue +1 -1
- package/src/layouts/Framework.vue +6 -4
- package/src/layouts/PropsPanel.vue +7 -5
- package/src/services/dataSource.ts +17 -0
- package/src/services/dep.ts +4 -0
- package/src/services/editor.ts +14 -6
- package/src/services/props.ts +9 -4
- package/src/theme/page-fragment-select.scss +14 -0
- package/src/theme/theme.scss +1 -0
- package/src/theme/tree.scss +6 -0
- package/src/type.ts +1 -0
- package/src/utils/monaco-editor.ts +8 -0
- package/types/layouts/CodeEditor.vue.d.ts +1 -1
- package/types/layouts/PropsPanel.vue.d.ts +10 -1
- package/types/services/dataSource.d.ts +1 -0
- package/types/services/dep.d.ts +1 -0
- package/types/type.d.ts +1 -0
- package/types/utils/monaco-editor.d.ts +2 -0
package/dist/style.css
CHANGED
|
@@ -901,6 +901,11 @@
|
|
|
901
901
|
.m-editor-tree .m-editor-tree-node .tree-node .tree-node-tool .tmagic-design-icon {
|
|
902
902
|
margin-right: 10px;
|
|
903
903
|
}
|
|
904
|
+
.m-editor-tree .m-editor-tree-empty {
|
|
905
|
+
text-align: center;
|
|
906
|
+
color: #909399;
|
|
907
|
+
font-size: 14px;
|
|
908
|
+
}
|
|
904
909
|
.m-editor-float-box {
|
|
905
910
|
position: absolute;
|
|
906
911
|
background-color: #fff;
|
|
@@ -928,6 +933,20 @@
|
|
|
928
933
|
.m-editor-floating-box-moveable {
|
|
929
934
|
opacity: 0;
|
|
930
935
|
}
|
|
936
|
+
.m-fields-page-fragment-select {
|
|
937
|
+
width: 100%;
|
|
938
|
+
}
|
|
939
|
+
.m-fields-page-fragment-select .page-fragment-select-container {
|
|
940
|
+
width: 100%;
|
|
941
|
+
display: flex;
|
|
942
|
+
align-items: center;
|
|
943
|
+
}
|
|
944
|
+
.m-fields-page-fragment-select .page-fragment-select-container .select {
|
|
945
|
+
flex: 1;
|
|
946
|
+
}
|
|
947
|
+
.m-fields-page-fragment-select .page-fragment-select-container .icon {
|
|
948
|
+
margin-left: 10px;
|
|
949
|
+
}
|
|
931
950
|
.fade-enter-active,
|
|
932
951
|
.fade-leave-active {
|
|
933
952
|
transition: opacity 0.5s;
|
package/dist/tmagic-editor.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { defineComponent, ref, watch, onMounted, onBeforeUnmount, openBlock, createElementBlock, createBlock, Teleport, createElementVNode, normalizeClass, normalizeStyle, createVNode, unref, computed, reactive, resolveComponent, inject, withCtx, Fragment, resolveDynamicComponent, createTextVNode, createCommentVNode, toRaw, nextTick, mergeProps, toDisplayString, renderList, createStaticVNode, watchEffect, withModifiers, renderSlot, normalizeProps, resolveDirective, withDirectives, createSlots, markRaw, getCurrentInstance, vShow, provide, Transition, toHandlers, mergeDefaults } from 'vue';
|
|
2
2
|
import { FullScreen, Edit, View, Coin, Delete, Plus, Close, ArrowDown, ArrowLeftBold, ArrowRightBold, CaretBottom, DocumentCopy, Grid, Memo, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Search, ArrowRight, CopyDocument, Files, Hide, Goods, List, EditPen, Top, Bottom } from '@element-plus/icons-vue';
|
|
3
|
-
import { throttle, isEmpty, cloneDeep, mergeWith,
|
|
4
|
-
import * as monaco from 'monaco-editor';
|
|
3
|
+
import { throttle, isEmpty, cloneDeep, mergeWith, isObject, uniq, get, map, has, pick, keys } from 'lodash-es';
|
|
5
4
|
import serialize from 'serialize-javascript';
|
|
6
5
|
import { TMagicButton, TMagicCard, tMagicMessage, TMagicDialog, TMagicTag, tMagicMessageBox, TMagicIcon, getConfig as getConfig$1, TMagicSwitch, TMagicInput, TMagicTooltip, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicPopover, TMagicScrollbar, TMagicCollapse, TMagicCollapseItem } from '@tmagic/design';
|
|
6
|
+
import { emmetHTML, emmetCSS } from 'emmet-monaco-es';
|
|
7
|
+
import * as monaco from 'monaco-editor';
|
|
7
8
|
import { HookType, NodeType, ActionType } from '@tmagic/schema';
|
|
8
9
|
import { MFormBox, MFormDrawer, MForm, createValues, MSelect } from '@tmagic/form';
|
|
9
10
|
import { MagicTable } from '@tmagic/table';
|
|
10
|
-
import { guid, isPage, isPageFragment, isPop, getNodePath, isNumber, toLine, getDefaultValueFromFields, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getKeys, addClassName, removeClassName, removeClassNameByClassName, convertToNumber, getNodes } from '@tmagic/utils';
|
|
11
|
+
import { guid, isPage, isPageFragment, isPop, getNodePath, isNumber, toLine, getValueByKeyPath, setValueByKeyPath, getDefaultValueFromFields, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getKeys, addClassName, removeClassName, removeClassNameByClassName, convertToNumber, getNodes } from '@tmagic/utils';
|
|
11
12
|
import Gesto from 'gesto';
|
|
12
13
|
import Moveable from 'moveable';
|
|
13
14
|
import { Watcher, DepTargetType, createRelatedCompTarget, createCodeBlockTarget, createDataSourceTarget, createDataSourceMethodTarget, createDataSourceCondTarget } from '@tmagic/dep';
|
|
@@ -23,6 +24,9 @@ const setConfig = (option) => {
|
|
|
23
24
|
};
|
|
24
25
|
const getConfig = (key) => $TMAGIC_EDITOR[key];
|
|
25
26
|
|
|
27
|
+
emmetHTML(monaco);
|
|
28
|
+
emmetCSS(monaco, ["css", "scss"]);
|
|
29
|
+
|
|
26
30
|
const _hoisted_1$t = {
|
|
27
31
|
class: /* @__PURE__ */ normalizeClass(`magic-code-editor`)
|
|
28
32
|
};
|
|
@@ -1133,6 +1137,22 @@ class DataSource extends BaseService {
|
|
|
1133
1137
|
events: {},
|
|
1134
1138
|
methods: {}
|
|
1135
1139
|
});
|
|
1140
|
+
constructor() {
|
|
1141
|
+
super([
|
|
1142
|
+
{ name: "getFormConfig", isAsync: false },
|
|
1143
|
+
{ name: "setFormConfig", isAsync: false },
|
|
1144
|
+
{ name: "getFormValue", isAsync: false },
|
|
1145
|
+
{ name: "setFormValue", isAsync: false },
|
|
1146
|
+
{ name: "getFormEvent", isAsync: false },
|
|
1147
|
+
{ name: "setFormEvent", isAsync: false },
|
|
1148
|
+
{ name: "getFormMethod", isAsync: false },
|
|
1149
|
+
{ name: "setFormMethod", isAsync: false },
|
|
1150
|
+
{ name: "add", isAsync: false },
|
|
1151
|
+
{ name: "update", isAsync: false },
|
|
1152
|
+
{ name: "remove", isAsync: false },
|
|
1153
|
+
{ name: "createId", isAsync: false }
|
|
1154
|
+
]);
|
|
1155
|
+
}
|
|
1136
1156
|
set(name, value) {
|
|
1137
1157
|
this.state[name] = value;
|
|
1138
1158
|
}
|
|
@@ -1818,6 +1838,9 @@ class Dep extends BaseService {
|
|
|
1818
1838
|
clear(nodes) {
|
|
1819
1839
|
return this.watcher.clear(nodes);
|
|
1820
1840
|
}
|
|
1841
|
+
clearByType(type, nodes) {
|
|
1842
|
+
return this.watcher.clearByType(type, nodes);
|
|
1843
|
+
}
|
|
1821
1844
|
hasTarget(id, type = DepTargetType.DEFAULT) {
|
|
1822
1845
|
return this.watcher.hasTarget(id, type);
|
|
1823
1846
|
}
|
|
@@ -2234,11 +2257,11 @@ class Props extends BaseService {
|
|
|
2234
2257
|
if (!targetConfig)
|
|
2235
2258
|
return;
|
|
2236
2259
|
target.deps[config.id]?.keys?.forEach((fullKey) => {
|
|
2237
|
-
const relateOriginId =
|
|
2260
|
+
const relateOriginId = getValueByKeyPath(fullKey, config);
|
|
2238
2261
|
const relateTargetId = relateIdMap[relateOriginId];
|
|
2239
2262
|
if (!relateTargetId)
|
|
2240
2263
|
return;
|
|
2241
|
-
|
|
2264
|
+
setValueByKeyPath(fullKey, relateTargetId, targetConfig);
|
|
2242
2265
|
});
|
|
2243
2266
|
});
|
|
2244
2267
|
}
|
|
@@ -2764,7 +2787,7 @@ class Editor extends BaseService {
|
|
|
2764
2787
|
*/
|
|
2765
2788
|
copyWithRelated(config) {
|
|
2766
2789
|
const copyNodes = Array.isArray(config) ? config : [config];
|
|
2767
|
-
depService.
|
|
2790
|
+
depService.clearByType(DepTargetType.RELATED_COMP_WHEN_COPY);
|
|
2768
2791
|
depService.collect(copyNodes, true, DepTargetType.RELATED_COMP_WHEN_COPY);
|
|
2769
2792
|
const customTarget = depService.getTarget(
|
|
2770
2793
|
DepTargetType.RELATED_COMP_WHEN_COPY,
|
|
@@ -2878,14 +2901,19 @@ class Editor extends BaseService {
|
|
|
2878
2901
|
const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
|
|
2879
2902
|
const layout = await this.getLayout(parent, node);
|
|
2880
2903
|
const isRelative = layout === Layout.RELATIVE;
|
|
2881
|
-
|
|
2904
|
+
let offsetIndex;
|
|
2882
2905
|
if (offset === LayerOffset.TOP) {
|
|
2883
|
-
|
|
2906
|
+
offsetIndex = isRelative ? 0 : brothers.length;
|
|
2884
2907
|
} else if (offset === LayerOffset.BOTTOM) {
|
|
2885
|
-
|
|
2908
|
+
offsetIndex = isRelative ? brothers.length : 0;
|
|
2886
2909
|
} else {
|
|
2887
|
-
|
|
2910
|
+
offsetIndex = index + (isRelative ? -offset : offset);
|
|
2911
|
+
}
|
|
2912
|
+
if (offsetIndex > 0 && offsetIndex > brothers.length || offsetIndex < 0) {
|
|
2913
|
+
return;
|
|
2888
2914
|
}
|
|
2915
|
+
brothers.splice(index, 1);
|
|
2916
|
+
brothers.splice(offsetIndex, 0, node);
|
|
2889
2917
|
const grandparent = this.getParentById(parent.id);
|
|
2890
2918
|
this.get("stage")?.update({
|
|
2891
2919
|
config: cloneDeep(toRaw(parent)),
|
|
@@ -2894,6 +2922,7 @@ class Editor extends BaseService {
|
|
|
2894
2922
|
});
|
|
2895
2923
|
this.addModifiedNodeId(parent.id);
|
|
2896
2924
|
this.pushHistoryState();
|
|
2925
|
+
this.emit("move-layer", offset);
|
|
2897
2926
|
}
|
|
2898
2927
|
/**
|
|
2899
2928
|
* 移动到指定容器中
|
|
@@ -5085,8 +5114,8 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
|
|
|
5085
5114
|
options: () => {
|
|
5086
5115
|
if (pageList.value) {
|
|
5087
5116
|
return pageList.value.map((item) => ({
|
|
5088
|
-
text: `${item.name}(${item.id})`,
|
|
5089
|
-
label: `${item.name}(${item.id})`,
|
|
5117
|
+
text: `${item.devconfig?.tabName || item.title || item.name}(${item.id})`,
|
|
5118
|
+
label: `${item.devconfig?.tabName || item.title || item.name}(${item.id})`,
|
|
5090
5119
|
value: item.id
|
|
5091
5120
|
}));
|
|
5092
5121
|
}
|
|
@@ -5096,6 +5125,9 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
|
|
|
5096
5125
|
const changeHandler = async () => {
|
|
5097
5126
|
emit("change", props.model[props.name]);
|
|
5098
5127
|
};
|
|
5128
|
+
const editPageFragment = (id) => {
|
|
5129
|
+
services?.editorService.select(id);
|
|
5130
|
+
};
|
|
5099
5131
|
return (_ctx, _cache) => {
|
|
5100
5132
|
const _component_m_form_container = resolveComponent("m-form-container");
|
|
5101
5133
|
return openBlock(), createElementBlock("div", _hoisted_1$h, [
|
|
@@ -5106,7 +5138,13 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
|
|
|
5106
5138
|
model: _ctx.model,
|
|
5107
5139
|
size: _ctx.size,
|
|
5108
5140
|
onChange: changeHandler
|
|
5109
|
-
}, null, 8, ["model", "size"])
|
|
5141
|
+
}, null, 8, ["model", "size"]),
|
|
5142
|
+
_ctx.model[_ctx.name] ? (openBlock(), createBlock(_sfc_main$N, {
|
|
5143
|
+
key: 0,
|
|
5144
|
+
class: "icon",
|
|
5145
|
+
icon: unref(Edit),
|
|
5146
|
+
onClick: _cache[0] || (_cache[0] = ($event) => editPageFragment(_ctx.model[_ctx.name]))
|
|
5147
|
+
}, null, 8, ["icon"])) : createCommentVNode("", true)
|
|
5110
5148
|
])
|
|
5111
5149
|
]);
|
|
5112
5150
|
};
|
|
@@ -6182,15 +6220,17 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
6182
6220
|
page.value ? renderSlot(_ctx.$slots, "workspace", { key: 0 }) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
|
|
6183
6221
|
createVNode(_sfc_main$s, { "disabled-page-fragment": _ctx.disabledPageFragment }, null, 8, ["disabled-page-fragment"])
|
|
6184
6222
|
]),
|
|
6185
|
-
|
|
6186
|
-
"page-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6223
|
+
renderSlot(_ctx.$slots, "page-bar", {}, () => [
|
|
6224
|
+
createVNode(_sfc_main$t, { "disabled-page-fragment": _ctx.disabledPageFragment }, {
|
|
6225
|
+
"page-bar-title": withCtx(({ page: page2 }) => [
|
|
6226
|
+
renderSlot(_ctx.$slots, "page-bar-title", { page: page2 })
|
|
6227
|
+
]),
|
|
6228
|
+
"page-bar-popover": withCtx(({ page: page2 }) => [
|
|
6229
|
+
renderSlot(_ctx.$slots, "page-bar-popover", { page: page2 })
|
|
6230
|
+
]),
|
|
6231
|
+
_: 3
|
|
6232
|
+
}, 8, ["disabled-page-fragment"])
|
|
6233
|
+
])
|
|
6194
6234
|
]),
|
|
6195
6235
|
_: 2
|
|
6196
6236
|
}, [
|
|
@@ -6399,7 +6439,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
|
|
|
6399
6439
|
props: {
|
|
6400
6440
|
extendState: { type: Function }
|
|
6401
6441
|
},
|
|
6402
|
-
emits: ["mounted"],
|
|
6442
|
+
emits: ["mounted", "submit-error", "form-error"],
|
|
6403
6443
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
6404
6444
|
const emit = __emit;
|
|
6405
6445
|
const internalInstance = getCurrentInstance();
|
|
@@ -6438,11 +6478,12 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
|
|
|
6438
6478
|
const values2 = await configForm.value?.submitForm();
|
|
6439
6479
|
services?.editorService.update(values2);
|
|
6440
6480
|
} catch (e) {
|
|
6441
|
-
|
|
6442
|
-
tMagicMessage.closeAll();
|
|
6443
|
-
tMagicMessage.error(e.message);
|
|
6481
|
+
emit("submit-error", e);
|
|
6444
6482
|
}
|
|
6445
6483
|
};
|
|
6484
|
+
const errorHandler = (e) => {
|
|
6485
|
+
emit("form-error", e);
|
|
6486
|
+
};
|
|
6446
6487
|
__expose({ configForm, submit });
|
|
6447
6488
|
return (_ctx, _cache) => {
|
|
6448
6489
|
return withDirectives((openBlock(), createElementBlock("div", _hoisted_1$b, [
|
|
@@ -6456,7 +6497,8 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
|
|
|
6456
6497
|
"init-values": values.value,
|
|
6457
6498
|
config: curFormConfig.value,
|
|
6458
6499
|
"extend-state": _ctx.extendState,
|
|
6459
|
-
onChange: submit
|
|
6500
|
+
onChange: submit,
|
|
6501
|
+
onError: errorHandler
|
|
6460
6502
|
}, null, 8, ["class", "popper-class", "size", "init-values", "config", "extend-state"])
|
|
6461
6503
|
], 512)), [
|
|
6462
6504
|
[vShow, nodes.value.length === 1]
|
|
@@ -6771,7 +6813,10 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
|
|
|
6771
6813
|
}
|
|
6772
6814
|
});
|
|
6773
6815
|
|
|
6774
|
-
const _hoisted_1$9 = {
|
|
6816
|
+
const _hoisted_1$9 = {
|
|
6817
|
+
key: 1,
|
|
6818
|
+
class: "m-editor-tree-empty"
|
|
6819
|
+
};
|
|
6775
6820
|
const _sfc_main$m = /* @__PURE__ */ defineComponent({
|
|
6776
6821
|
...{
|
|
6777
6822
|
name: "MEditorTree"
|
|
@@ -10812,7 +10857,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
10812
10857
|
disabledPageFragment: { type: Boolean },
|
|
10813
10858
|
customContentMenu: { type: Function }
|
|
10814
10859
|
}, defaultEditorProps),
|
|
10815
|
-
emits: ["props-panel-mounted", "update:modelValue"],
|
|
10860
|
+
emits: ["props-panel-mounted", "update:modelValue", "props-form-error", "props-submit-error"],
|
|
10816
10861
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
10817
10862
|
const emit = __emit;
|
|
10818
10863
|
const props = __props;
|
|
@@ -10932,7 +10977,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
10932
10977
|
renderSlot(_ctx.$slots, "props-panel", {}, () => [
|
|
10933
10978
|
createVNode(_sfc_main$p, {
|
|
10934
10979
|
"extend-state": _ctx.extendFormState,
|
|
10935
|
-
onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
|
|
10980
|
+
onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance)),
|
|
10981
|
+
onFormError: _cache[1] || (_cache[1] = (e) => _ctx.$emit("props-form-error", e)),
|
|
10982
|
+
onSubmitError: _cache[2] || (_cache[2] = (e) => _ctx.$emit("props-submit-error", e))
|
|
10936
10983
|
}, {
|
|
10937
10984
|
"props-panel-header": withCtx(() => [
|
|
10938
10985
|
renderSlot(_ctx.$slots, "props-panel-header")
|
|
@@ -10950,6 +10997,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
10950
10997
|
footer: withCtx(() => [
|
|
10951
10998
|
renderSlot(_ctx.$slots, "footer")
|
|
10952
10999
|
]),
|
|
11000
|
+
"page-bar": withCtx(() => [
|
|
11001
|
+
renderSlot(_ctx.$slots, "page-bar")
|
|
11002
|
+
]),
|
|
10953
11003
|
"page-bar-title": withCtx(({ page }) => [
|
|
10954
11004
|
renderSlot(_ctx.$slots, "page-bar-title", { page })
|
|
10955
11005
|
]),
|