@opentiny/tiny-engine-toolbar-save 1.0.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/dist/index.js +200 -0
- package/dist/style.css +1 -0
- package/package.json +24 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import "./style.css";
|
|
2
|
+
import { reactive as B, ref as P, watch as T, onBeforeMount as w, resolveComponent as r, openBlock as k, createElementBlock as E, Fragment as M, createVNode as l, withCtx as d, createElementVNode as C, normalizeClass as O, withDirectives as G, vShow as V, createTextVNode as S, createBlock as D, createCommentVNode as R } from "vue";
|
|
3
|
+
import { VueMonaco as U } from "@opentiny/tiny-engine-common";
|
|
4
|
+
import { Loading as z, Button as I, Popover as J, DialogBox as j } from "@opentiny/vue";
|
|
5
|
+
import { useCanvas as h, useLayout as x, useBlock as F, usePage as q, useNotify as H } from "@opentiny/tiny-engine-controller";
|
|
6
|
+
import { theme as K } from "@opentiny/tiny-engine-controller/adapter";
|
|
7
|
+
import { setSchema as Q, getSchema as W } from "@opentiny/tiny-engine-canvas";
|
|
8
|
+
import { constants as X } from "@opentiny/tiny-engine-utils";
|
|
9
|
+
import { handlePageUpdate as Y } from "@opentiny/tiny-engine-common/js/http";
|
|
10
|
+
const { pageState: f, isSaved: Z, isBlock: $ } = h(), { PLUGIN_NAME: ee, getPluginApi: oe } = x(), { getCurrentBlock: te } = F(), { PAGE_STATUS: a } = X, { pageSettingState: p, isTemporaryPage: g } = q(), m = B({
|
|
11
|
+
visible: !1,
|
|
12
|
+
code: "",
|
|
13
|
+
originalCode: "",
|
|
14
|
+
disabled: !1
|
|
15
|
+
}), s = P(!1), ne = async (n) => {
|
|
16
|
+
var t;
|
|
17
|
+
const e = oe(ee.BlockManage), o = te();
|
|
18
|
+
o.label = n.fileName, o.content = n, s.value = !0, o.screenshot = await e.getBlockBase64(), await ((t = e.saveBlock) == null ? void 0 : t.call(e, o)), s.value = !1;
|
|
19
|
+
}, ae = async (n) => {
|
|
20
|
+
const { currentPage: e } = f, o = {
|
|
21
|
+
page_content: n
|
|
22
|
+
};
|
|
23
|
+
s.value = !0, await Y(e.id, { ...e, ...o }), s.value = !1;
|
|
24
|
+
}, y = (n) => {
|
|
25
|
+
const e = JSON.parse(n);
|
|
26
|
+
if (f.pageSchema = e, Q(e), p != null && p.isAIPage) {
|
|
27
|
+
g.saved && (g.saved = !1), g.saved = !0;
|
|
28
|
+
const o = "page_content";
|
|
29
|
+
p.currentPageData[o] = e;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
$() ? ne(e) : ae(e);
|
|
33
|
+
}, N = async () => {
|
|
34
|
+
var c;
|
|
35
|
+
if (Z() || m.disabled)
|
|
36
|
+
return;
|
|
37
|
+
const n = (c = x().layoutState) == null ? void 0 : c.pageStatus, e = n == null ? void 0 : n.state, o = n == null ? void 0 : n.data, t = {
|
|
38
|
+
[a.Release]: "当前页面未锁定,请先锁定再保存",
|
|
39
|
+
[a.Empty]: "当前应用无页面,请先新建页面再保存",
|
|
40
|
+
[a.Guest]: "官网演示应用不能保存页面,如需体验请切换应用",
|
|
41
|
+
[a.Lock]: `当前页面被 ${o == null ? void 0 : o.username} ${o == null ? void 0 : o.resetPasswordToken} 锁定,如需编辑请先联系他解锁文件,然后再锁定该页面后编辑!`
|
|
42
|
+
};
|
|
43
|
+
if ([a.Release, a.Empty, a.Guest, a.Lock].includes(e)) {
|
|
44
|
+
H({
|
|
45
|
+
type: "error",
|
|
46
|
+
title: "保存失败",
|
|
47
|
+
message: t[e]
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
m.disabled = !0;
|
|
52
|
+
let i = z.service({
|
|
53
|
+
lock: !0,
|
|
54
|
+
text: "保存中",
|
|
55
|
+
background: "rgba(0, 0, 0, 0.5)"
|
|
56
|
+
});
|
|
57
|
+
const u = W();
|
|
58
|
+
m.code = JSON.stringify(u || {}, null, 2), y(m.code), s.value && (m.disabled = !1), T(
|
|
59
|
+
() => f.isSaved,
|
|
60
|
+
(v) => {
|
|
61
|
+
v && i.close();
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
const se = (n, e) => {
|
|
66
|
+
const o = n.__vccOpts || n;
|
|
67
|
+
for (const [t, i] of e)
|
|
68
|
+
o[t] = i;
|
|
69
|
+
return o;
|
|
70
|
+
}, ie = {
|
|
71
|
+
saveCommon: y,
|
|
72
|
+
openCommon: N
|
|
73
|
+
}, ce = {
|
|
74
|
+
components: {
|
|
75
|
+
VueMonaco: U,
|
|
76
|
+
TinyButton: I,
|
|
77
|
+
TinyPopover: J,
|
|
78
|
+
TinyDialogBox: j
|
|
79
|
+
},
|
|
80
|
+
props: {
|
|
81
|
+
icon: {
|
|
82
|
+
type: String,
|
|
83
|
+
default: "save"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
setup() {
|
|
87
|
+
const { isSaved: n } = h(), e = B({
|
|
88
|
+
visible: !1,
|
|
89
|
+
code: "",
|
|
90
|
+
originalCode: "",
|
|
91
|
+
disabled: !1,
|
|
92
|
+
timer: null
|
|
93
|
+
}), o = P(null), t = () => {
|
|
94
|
+
e.visible = !1, e.originalCode = "";
|
|
95
|
+
}, i = () => {
|
|
96
|
+
s.value || N();
|
|
97
|
+
}, u = () => {
|
|
98
|
+
y();
|
|
99
|
+
}, c = {
|
|
100
|
+
theme: K(),
|
|
101
|
+
tabSize: 2,
|
|
102
|
+
language: "json",
|
|
103
|
+
autoIndent: !0,
|
|
104
|
+
lineNumbers: !0,
|
|
105
|
+
formatOnPaste: !0,
|
|
106
|
+
automaticLayout: !0,
|
|
107
|
+
roundedSelection: !0,
|
|
108
|
+
minimap: {
|
|
109
|
+
enabled: !1
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return w(() => {
|
|
113
|
+
clearTimeout(e.timer);
|
|
114
|
+
}), {
|
|
115
|
+
state: e,
|
|
116
|
+
editor: o,
|
|
117
|
+
editorOptions: c,
|
|
118
|
+
isLoading: s,
|
|
119
|
+
close: t,
|
|
120
|
+
isSaved: n,
|
|
121
|
+
openApi: i,
|
|
122
|
+
saveApi: u
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, re = { class: "dots" };
|
|
126
|
+
function le(n, e, o, t, i, u) {
|
|
127
|
+
const c = r("svg-icon"), v = r("tiny-popover"), A = r("vue-monaco"), b = r("tiny-button"), L = r("tiny-dialog-box");
|
|
128
|
+
return k(), E(M, null, [
|
|
129
|
+
l(v, {
|
|
130
|
+
trigger: "hover",
|
|
131
|
+
"open-delay": 1e3,
|
|
132
|
+
"popper-class": "toolbar-right-popover",
|
|
133
|
+
"append-to-body": "",
|
|
134
|
+
content: t.isLoading ? "保存中" : "保存"
|
|
135
|
+
}, {
|
|
136
|
+
reference: d(() => [
|
|
137
|
+
C("span", {
|
|
138
|
+
class: O([t.isLoading ? "saving" : "icon"]),
|
|
139
|
+
onClick: e[0] || (e[0] = (..._) => t.openApi && t.openApi(..._))
|
|
140
|
+
}, [
|
|
141
|
+
G(C("span", re, null, 512), [
|
|
142
|
+
[V, !t.isSaved()]
|
|
143
|
+
]),
|
|
144
|
+
l(c, { name: o.icon }, null, 8, ["name"])
|
|
145
|
+
], 2)
|
|
146
|
+
]),
|
|
147
|
+
_: 1
|
|
148
|
+
}, 8, ["content"]),
|
|
149
|
+
l(L, {
|
|
150
|
+
class: "dialog-box",
|
|
151
|
+
modal: !1,
|
|
152
|
+
fullscreen: !0,
|
|
153
|
+
"append-to-body": !0,
|
|
154
|
+
visible: t.state.visible,
|
|
155
|
+
title: "Schema 本地与线上差异",
|
|
156
|
+
"onUpdate:visible": e[1] || (e[1] = (_) => t.state.visible = _)
|
|
157
|
+
}, {
|
|
158
|
+
footer: d(() => [
|
|
159
|
+
l(b, { onClick: t.close }, {
|
|
160
|
+
default: d(() => [
|
|
161
|
+
S("取 消")
|
|
162
|
+
]),
|
|
163
|
+
_: 1
|
|
164
|
+
}, 8, ["onClick"]),
|
|
165
|
+
l(b, {
|
|
166
|
+
type: "primary",
|
|
167
|
+
onClick: t.saveApi
|
|
168
|
+
}, {
|
|
169
|
+
default: d(() => [
|
|
170
|
+
S("保 存")
|
|
171
|
+
]),
|
|
172
|
+
_: 1
|
|
173
|
+
}, 8, ["onClick"])
|
|
174
|
+
]),
|
|
175
|
+
default: d(() => [
|
|
176
|
+
t.state.visible ? (k(), D(A, {
|
|
177
|
+
key: 0,
|
|
178
|
+
ref: "editor",
|
|
179
|
+
class: "monaco-editor",
|
|
180
|
+
diffEditor: !0,
|
|
181
|
+
options: t.editorOptions,
|
|
182
|
+
value: t.state.code,
|
|
183
|
+
original: t.state.originalCode
|
|
184
|
+
}, null, 8, ["options", "value", "original"])) : R("", !0)
|
|
185
|
+
]),
|
|
186
|
+
_: 1
|
|
187
|
+
}, 8, ["visible"])
|
|
188
|
+
], 64);
|
|
189
|
+
}
|
|
190
|
+
const de = /* @__PURE__ */ se(ce, [["render", le], ["__scopeId", "data-v-6d9e48c8"]]), ke = {
|
|
191
|
+
id: "save",
|
|
192
|
+
title: "save",
|
|
193
|
+
icon: "",
|
|
194
|
+
align: "right",
|
|
195
|
+
component: de,
|
|
196
|
+
api: ie
|
|
197
|
+
};
|
|
198
|
+
export {
|
|
199
|
+
ke as default
|
|
200
|
+
};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.dots[data-v-6d9e48c8]{width:6px;height:6px;background:var(--ti-lowcode-toolbar-dot-color);border-radius:50%;display:inline-block;position:absolute;top:4px;right:3px;z-index:100}.saving[data-v-6d9e48c8]{width:32px;height:32px;display:inline-block;cursor:not-allowed;color:var(--ti-lowcode-disabled-color);font-size:20px;margin-bottom:-2px}.dialog-box[data-v-6d9e48c8] .tiny-dialog-box{display:flex;flex-direction:column}.dialog-box[data-v-6d9e48c8] .tiny-dialog-box .tiny-dialog-box__body{flex:1}.dialog-box .monaco-editor[data-v-6d9e48c8]{width:100%;height:100%}.changeRole a{color:var(--ti-lowcode-canvas-handle-hover-bg);padding:0 5px}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opentiny/tiny-engine-toolbar-save",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "vite build"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"module": "dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@opentiny/vue": "^3.8.0",
|
|
17
|
+
"vue": "3.2.45"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
21
|
+
"@vitejs/plugin-vue-jsx": "^1.3.10",
|
|
22
|
+
"vite": "^4.3.7"
|
|
23
|
+
}
|
|
24
|
+
}
|