mechanica 1.0.0
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/editor.d.ts +26 -0
- package/dist/editor.js +2671 -0
- package/dist/editor.js.map +1 -0
- package/dist/main.d.ts +40 -0
- package/dist/main.js +40 -0
- package/dist/main.js.map +1 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +322 -0
- package/dist/plugin.js.map +1 -0
- package/dist/style.css +697 -0
- package/package.json +50 -0
package/dist/editor.js
ADDED
|
@@ -0,0 +1,2671 @@
|
|
|
1
|
+
import { watch, defineComponent, computed, inject, openBlock, createElementBlock, Fragment, renderList, createElementVNode, toDisplayString, getCurrentScope, onScopeDispose, toRef as toRef$1, readonly, customRef, ref, toValue, nextTick, getCurrentInstance, onMounted, createBlock, Teleport, createVNode, Transition, withCtx, unref, mergeProps, withModifiers, renderSlot, createCommentVNode, resolveDynamicComponent, normalizeClass, shallowRef, isRef, createTextVNode, reactive, shallowReactive, normalizeStyle, normalizeProps, guardReactiveProps, TransitionGroup, useSlots, createSlots, withDirectives, vModelText, vModelDynamic, createStaticVNode, mergeModels, useModel, resolveComponent, provide, createApp } from "vue";
|
|
2
|
+
import { blocksList as blocksList$1 } from "virtual:builder-blocks";
|
|
3
|
+
import { registerAlias, unfoldSchema } from "compact-json-schema";
|
|
4
|
+
const findParent = (el, callback) => {
|
|
5
|
+
if (callback(el)) return el;
|
|
6
|
+
if (!el.parentElement) return null;
|
|
7
|
+
return findParent(el.parentElement, callback);
|
|
8
|
+
};
|
|
9
|
+
const clickOnIgnore = (target, ignoreEl) => {
|
|
10
|
+
if (!ignoreEl) return false;
|
|
11
|
+
return !!findParent(target, (el) => {
|
|
12
|
+
if (!Array.isArray(ignoreEl)) return el === ignoreEl.value;
|
|
13
|
+
for (const item of ignoreEl) {
|
|
14
|
+
if (item.value === el) return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const useMouseDownOutside = (condition, onMouseDown, ignoreEl) => {
|
|
20
|
+
const clickOutside = (e) => {
|
|
21
|
+
if (e.defaultPrevented) return;
|
|
22
|
+
if (clickOnIgnore(e.target, ignoreEl)) return;
|
|
23
|
+
onMouseDown();
|
|
24
|
+
};
|
|
25
|
+
watch(condition, (value) => {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
if (value) {
|
|
28
|
+
document.addEventListener("mousedown", clickOutside);
|
|
29
|
+
} else {
|
|
30
|
+
document.removeEventListener("mousedown", clickOutside);
|
|
31
|
+
}
|
|
32
|
+
}, 50);
|
|
33
|
+
}, { flush: "post" });
|
|
34
|
+
};
|
|
35
|
+
const isTouchEvent = (e) => {
|
|
36
|
+
return "touches" in e;
|
|
37
|
+
};
|
|
38
|
+
function getPos(_e, relativeRect, type, touchIndex = -1) {
|
|
39
|
+
const e = isTouchEvent(_e) ? _e.touches[touchIndex < 0 ? _e.touches.length - 1 : touchIndex] : _e;
|
|
40
|
+
if (!e) return { x: 0, y: 0 };
|
|
41
|
+
if (relativeRect && type !== "absolute") {
|
|
42
|
+
if (type === "threejs") {
|
|
43
|
+
const _x = (e.clientX - relativeRect.left) / relativeRect.width * 2 - 1;
|
|
44
|
+
const _y = -(e.clientY - relativeRect.top) / relativeRect.height * 2 + 1;
|
|
45
|
+
return { x: _x, y: _y };
|
|
46
|
+
} else {
|
|
47
|
+
return { x: e.clientX - relativeRect.x, y: e.clientY - relativeRect.y };
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
return { x: e.clientX, y: e.clientY };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const getTouch = (e, touchId) => {
|
|
54
|
+
if (isTouchEvent(e) && touchId !== null) {
|
|
55
|
+
for (let touch of e.touches) {
|
|
56
|
+
if (touch.identifier === touchId) return touch;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return e;
|
|
60
|
+
};
|
|
61
|
+
function handleMove(e, { onStart, onMove, onEnd, relativeRect, type, prevent, threshold } = {}) {
|
|
62
|
+
const box = relativeRect ?? e.currentTarget.getBoundingClientRect();
|
|
63
|
+
const touchId = isTouchEvent(e) ? (e.changedTouches[0] ?? e.touches[e.touches.length - 1]).identifier : null;
|
|
64
|
+
const startPos = getPos(getTouch(e, touchId), box, type ?? "absolute");
|
|
65
|
+
let lastPos = startPos;
|
|
66
|
+
let moving = false;
|
|
67
|
+
const move = (e2) => {
|
|
68
|
+
const pos = getPos(getTouch(e2, touchId), box, type ?? "absolute");
|
|
69
|
+
if (moving === false && threshold && Math.abs(pos.x - startPos.x) < threshold) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (moving === false && threshold) {
|
|
73
|
+
startPos.x = pos.x;
|
|
74
|
+
startPos.y = pos.y;
|
|
75
|
+
moving = true;
|
|
76
|
+
}
|
|
77
|
+
if (!e2.defaultPrevented && prevent !== false) {
|
|
78
|
+
e2.preventDefault();
|
|
79
|
+
e2.stopImmediatePropagation();
|
|
80
|
+
}
|
|
81
|
+
if (onMove) {
|
|
82
|
+
const deltaPos = { x: pos.x - lastPos.x, y: pos.y - lastPos.y };
|
|
83
|
+
onMove({ e: e2, pos, deltaPos, startPos });
|
|
84
|
+
}
|
|
85
|
+
lastPos = pos;
|
|
86
|
+
};
|
|
87
|
+
const end = (e2) => {
|
|
88
|
+
if (isTouchEvent(e2) && e2.touches.length > 0 && e2.changedTouches[0].identifier !== touchId) return;
|
|
89
|
+
if (!e2.defaultPrevented && prevent !== false) {
|
|
90
|
+
e2.preventDefault();
|
|
91
|
+
e2.stopImmediatePropagation();
|
|
92
|
+
}
|
|
93
|
+
dispose(e2);
|
|
94
|
+
};
|
|
95
|
+
const dispose = (e2) => {
|
|
96
|
+
document.removeEventListener("touchmove", move);
|
|
97
|
+
document.removeEventListener("mousemove", move);
|
|
98
|
+
document.removeEventListener("touchend", end);
|
|
99
|
+
document.removeEventListener("touchcancel", end);
|
|
100
|
+
document.removeEventListener("mouseup", end);
|
|
101
|
+
if (onEnd) {
|
|
102
|
+
const pos = getPos(getTouch(e2, touchId), box, type ?? "absolute");
|
|
103
|
+
if (pos.x === 0 && pos.y === 0) {
|
|
104
|
+
onEnd({ e: e2, pos: lastPos, startPos, deltaPos: { x: 0, y: 0 } });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const deltaPos = { x: pos.x - lastPos.x, y: pos.y - lastPos.y };
|
|
108
|
+
onEnd({ e: e2, pos, startPos, deltaPos });
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
if (onStart) {
|
|
112
|
+
onStart({ e, pos: startPos, deltaPos: { x: 0, y: 0 }, startPos });
|
|
113
|
+
}
|
|
114
|
+
move(e);
|
|
115
|
+
if (isTouchEvent(e)) {
|
|
116
|
+
document.addEventListener("touchmove", move, { passive: prevent !== true });
|
|
117
|
+
document.addEventListener("touchend", end, { passive: prevent !== true });
|
|
118
|
+
document.addEventListener("touchcancel", end, { passive: prevent !== true });
|
|
119
|
+
} else {
|
|
120
|
+
document.addEventListener("mousemove", move);
|
|
121
|
+
document.addEventListener("mouseup", end);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const useDraggableItem = () => {
|
|
125
|
+
let clonedItem;
|
|
126
|
+
const drag = (e, options) => {
|
|
127
|
+
if (clonedItem) {
|
|
128
|
+
clonedItem.remove();
|
|
129
|
+
clonedItem = null;
|
|
130
|
+
}
|
|
131
|
+
const el = e.currentTarget;
|
|
132
|
+
const rect = el.getBoundingClientRect();
|
|
133
|
+
const offset = { left: rect.left - e.clientX, top: rect.top - e.clientY };
|
|
134
|
+
const width = el.clientWidth;
|
|
135
|
+
const onStart = () => {
|
|
136
|
+
var _a;
|
|
137
|
+
clonedItem = el.cloneNode(true);
|
|
138
|
+
clonedItem.setAttribute("style", "position: fixed; pointer-events: none;");
|
|
139
|
+
document.body.append(clonedItem);
|
|
140
|
+
(_a = options.onStart) == null ? void 0 : _a.call(options, clonedItem);
|
|
141
|
+
};
|
|
142
|
+
const threshold = options.threshold ?? 10;
|
|
143
|
+
handleMove(e, {
|
|
144
|
+
onMove({ e: e2, pos, startPos }) {
|
|
145
|
+
var _a;
|
|
146
|
+
if (!clonedItem) {
|
|
147
|
+
if (Math.abs(pos.x - startPos.x) > threshold || Math.abs(pos.y - startPos.y) > threshold) {
|
|
148
|
+
onStart();
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
clonedItem.setAttribute(
|
|
153
|
+
"style",
|
|
154
|
+
`position: fixed; top: ${pos.y + offset.top}px; left: ${pos.x + offset.left}px; width: ${width}px; pointer-events: none;`
|
|
155
|
+
);
|
|
156
|
+
(_a = options.onMove) == null ? void 0 : _a.call(options, e2, clonedItem);
|
|
157
|
+
},
|
|
158
|
+
onEnd({ e: e2 }) {
|
|
159
|
+
var _a;
|
|
160
|
+
if (!clonedItem) return;
|
|
161
|
+
clonedItem.remove();
|
|
162
|
+
clonedItem = null;
|
|
163
|
+
(_a = options.onEnd) == null ? void 0 : _a.call(options, e2);
|
|
164
|
+
},
|
|
165
|
+
type: "absolute"
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
return drag;
|
|
169
|
+
};
|
|
170
|
+
const cloneDeep = (obj) => {
|
|
171
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
172
|
+
if (Array.isArray(obj)) {
|
|
173
|
+
return [...obj.map(cloneDeep)];
|
|
174
|
+
}
|
|
175
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, cloneDeep(value)]));
|
|
176
|
+
};
|
|
177
|
+
class MultiMap {
|
|
178
|
+
constructor() {
|
|
179
|
+
this._map = /* @__PURE__ */ new Map();
|
|
180
|
+
}
|
|
181
|
+
get size() {
|
|
182
|
+
return this._map.size;
|
|
183
|
+
}
|
|
184
|
+
add(key, value) {
|
|
185
|
+
const arr = this._map.get(key);
|
|
186
|
+
if (!arr) {
|
|
187
|
+
this._map.set(key, [value]);
|
|
188
|
+
} else {
|
|
189
|
+
arr.push(value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
remove(key, value) {
|
|
193
|
+
const arr = this._map.get(key);
|
|
194
|
+
if (!arr) return false;
|
|
195
|
+
const newArr = arr.filter((item) => item !== value);
|
|
196
|
+
if (newArr.length === arr.length) return false;
|
|
197
|
+
if (newArr.length === 0) {
|
|
198
|
+
this._map.delete(key);
|
|
199
|
+
} else {
|
|
200
|
+
this._map.set(key, newArr);
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
has(key) {
|
|
205
|
+
return this._map.has(key);
|
|
206
|
+
}
|
|
207
|
+
get(key) {
|
|
208
|
+
return this._map.get(key) || [];
|
|
209
|
+
}
|
|
210
|
+
forEach(key, callback) {
|
|
211
|
+
const arr = this._map.get(key);
|
|
212
|
+
if (!arr) return;
|
|
213
|
+
arr.forEach(callback);
|
|
214
|
+
}
|
|
215
|
+
clear() {
|
|
216
|
+
this._map.clear();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const listeners = new MultiMap();
|
|
220
|
+
let hasEvent = false;
|
|
221
|
+
const useKeyDownLayer = (key, watcher, callback) => {
|
|
222
|
+
const onKeyDown = (e) => {
|
|
223
|
+
if (!listeners.has(e.code)) return;
|
|
224
|
+
const _listeners = listeners.get(e.code);
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
const callback2 = _listeners[_listeners.length - 1];
|
|
227
|
+
callback2(e);
|
|
228
|
+
};
|
|
229
|
+
watch(watcher, (value) => {
|
|
230
|
+
if (value) {
|
|
231
|
+
listeners.add(key, callback);
|
|
232
|
+
} else {
|
|
233
|
+
listeners.remove(key, callback);
|
|
234
|
+
}
|
|
235
|
+
if (listeners.size > 0 && !hasEvent) {
|
|
236
|
+
document.addEventListener("keydown", onKeyDown);
|
|
237
|
+
hasEvent = true;
|
|
238
|
+
}
|
|
239
|
+
if (listeners.size === 0) {
|
|
240
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
241
|
+
hasEvent = false;
|
|
242
|
+
}
|
|
243
|
+
}, { immediate: true });
|
|
244
|
+
};
|
|
245
|
+
class BlockDropEvent extends Event {
|
|
246
|
+
constructor(block, content = null) {
|
|
247
|
+
super("blockdrop", { bubbles: true });
|
|
248
|
+
this.content = null;
|
|
249
|
+
this.block = block;
|
|
250
|
+
this.content = content;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const _hoisted_1$g = { class: "blocks-list" };
|
|
254
|
+
const _hoisted_2$5 = { class: "page-editor-blocks__group" };
|
|
255
|
+
const _hoisted_3$4 = { class: "title" };
|
|
256
|
+
const _hoisted_4$4 = { class: "blocks-list__blocks" };
|
|
257
|
+
const _hoisted_5$2 = ["onMousedown"];
|
|
258
|
+
const _sfc_main$m = /* @__PURE__ */ defineComponent({
|
|
259
|
+
__name: "BlocksList",
|
|
260
|
+
props: {
|
|
261
|
+
blocks: {}
|
|
262
|
+
},
|
|
263
|
+
setup(__props) {
|
|
264
|
+
const props = __props;
|
|
265
|
+
const groupBlocks = computed(() => {
|
|
266
|
+
const groups = new MultiMap();
|
|
267
|
+
for (let block of props.blocks) {
|
|
268
|
+
if (block.hidden || block.isDev) continue;
|
|
269
|
+
groups.add(block.group ?? "default", block);
|
|
270
|
+
}
|
|
271
|
+
const output = [];
|
|
272
|
+
for (let [groupName, blocks] of groups._map) {
|
|
273
|
+
blocks.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
274
|
+
output.push({ name: groupName, blocks });
|
|
275
|
+
}
|
|
276
|
+
return output;
|
|
277
|
+
});
|
|
278
|
+
const groupNames = {
|
|
279
|
+
default: "Доступные блоки",
|
|
280
|
+
layout: "Макет"
|
|
281
|
+
};
|
|
282
|
+
const drag = useDraggableItem();
|
|
283
|
+
const dragMode = inject("dragMode");
|
|
284
|
+
const onItemMouseDown = (e, item) => {
|
|
285
|
+
drag(e, {
|
|
286
|
+
onStart(item2) {
|
|
287
|
+
item2.classList.add("drag");
|
|
288
|
+
document.body.classList.add("mousedrag");
|
|
289
|
+
dragMode.value = true;
|
|
290
|
+
},
|
|
291
|
+
onEnd(e2) {
|
|
292
|
+
var _a;
|
|
293
|
+
document.body.classList.remove("mousedrag");
|
|
294
|
+
(_a = e2.target) == null ? void 0 : _a.dispatchEvent(new BlockDropEvent(item));
|
|
295
|
+
dragMode.value = false;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
return (_ctx, _cache) => {
|
|
300
|
+
return openBlock(), createElementBlock("div", _hoisted_1$g, [
|
|
301
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(groupBlocks.value, (group) => {
|
|
302
|
+
return openBlock(), createElementBlock("div", _hoisted_2$5, [
|
|
303
|
+
createElementVNode("div", _hoisted_3$4, toDisplayString(groupNames[group.name] ?? group.name), 1),
|
|
304
|
+
createElementVNode("div", _hoisted_4$4, [
|
|
305
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(group.blocks, (item) => {
|
|
306
|
+
return openBlock(), createElementBlock("button", {
|
|
307
|
+
class: "blocks-list__block editor-component",
|
|
308
|
+
key: item.id,
|
|
309
|
+
onMousedown: ($event) => onItemMouseDown($event, item)
|
|
310
|
+
}, toDisplayString(item.name), 41, _hoisted_5$2);
|
|
311
|
+
}), 128))
|
|
312
|
+
])
|
|
313
|
+
]);
|
|
314
|
+
}), 256))
|
|
315
|
+
]);
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const defaultImageSrc = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAMAAAANIilAAAAAUVBMVEUAAADy8vLy8vLy8vLy8vLv7+/v7+/x8fHz8/Py8vJtbW2fn5/h4eGvr6+wsLDq6uqoqKh+fn7Jycm4uLiOjo51dXWGhoaWlpbZ2dnAwMDY2NgSuPoLAAAACXRSTlMA38+/XyAQgH+A/hFhAAABBUlEQVRIx+3X3YqDMBCG4ala3XwxJv5E273/C90RlLAodBxPWup7IFF80BwYCRGVP7k5XFbQ3P1mVN3ujNkqdUmFUVdRpsc5mRNd+MLfhDu7LTxF2A/YbfQCbIHBbpqAIMBAb3ZyiP4lroF6I5frn4DrE9jBqXEPwCnxA2hZq3DdovUNawX2bPnOVff9ETwBD2NW7fgoxxbgZ626A+fEGGh4sOqIsWEtxlM6DZinz9oKcevT6YjIZtZC/Pvvwd3y/oc/DJemHyTYx7RkdEhjBwhWkpCWoQjYpYGHAuxH7DZ40dL7DHZb9/Z/jAtf+F1wrrcZVXpcUKnfGp3clHFFdpzmVUn0B/oSge0dVY8uAAAAAElFTkSuQmCC";
|
|
320
|
+
const getDefaultValue = (schema) => {
|
|
321
|
+
if (schema.default) return schema.default;
|
|
322
|
+
if (schema.nullable) return null;
|
|
323
|
+
if (schema.type === "object" && schema.format === "image") {
|
|
324
|
+
return { src: defaultImageSrc, previewSrc: defaultImageSrc };
|
|
325
|
+
}
|
|
326
|
+
if (schema.type === "number" || schema.type === "integer") return 0;
|
|
327
|
+
if (schema.type === "object") return {};
|
|
328
|
+
if (schema.type === "array") return [];
|
|
329
|
+
if (schema.type === "boolean") return false;
|
|
330
|
+
return "";
|
|
331
|
+
};
|
|
332
|
+
const passDefaultValue = (state, schema) => {
|
|
333
|
+
if (!schema) return state;
|
|
334
|
+
if (schema.type === "object" && state) {
|
|
335
|
+
for (let key in schema.properties) {
|
|
336
|
+
if (!(key in state) && !schema.required.includes(key)) continue;
|
|
337
|
+
state[key] = passDefaultValue(state[key], schema.properties[key]);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return state ?? getDefaultValue(schema);
|
|
341
|
+
};
|
|
342
|
+
const walkTree = (blocks, callback) => {
|
|
343
|
+
for (let block of blocks) {
|
|
344
|
+
callback(block);
|
|
345
|
+
if (!block.children) continue;
|
|
346
|
+
if (Array.isArray(block.children)) {
|
|
347
|
+
walkTree(block.children, callback);
|
|
348
|
+
} else {
|
|
349
|
+
for (let value of Object.values(block.children)) {
|
|
350
|
+
walkTree(value, callback);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const walkSchema = (obj, schema, callback) => {
|
|
356
|
+
if (schema.type === "object") {
|
|
357
|
+
if (!obj) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
for (let [key, value] of Object.entries(obj)) {
|
|
361
|
+
const childSchema = schema.properties[key];
|
|
362
|
+
if (!childSchema) continue;
|
|
363
|
+
const isRequired = schema.required.includes(key);
|
|
364
|
+
callback(value, childSchema, key, obj, isRequired);
|
|
365
|
+
if (childSchema.type === "array" || childSchema.type === "object") {
|
|
366
|
+
walkSchema(value, childSchema, callback);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (schema.type === "array" && schema.items) {
|
|
371
|
+
for (let value of obj) {
|
|
372
|
+
callback(value, schema.items);
|
|
373
|
+
if (schema.items.type === "array" || schema.items.type === "object") {
|
|
374
|
+
walkSchema(value, schema.items, callback);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const findBlock = (blocks, callback) => {
|
|
380
|
+
for (let block of blocks) {
|
|
381
|
+
if (callback(block)) {
|
|
382
|
+
return block;
|
|
383
|
+
}
|
|
384
|
+
if (!block.children) continue;
|
|
385
|
+
if (Array.isArray(block.children)) {
|
|
386
|
+
const result = findBlock(block.children, callback);
|
|
387
|
+
if (result) return result;
|
|
388
|
+
} else {
|
|
389
|
+
for (let value of Object.values(block.children)) {
|
|
390
|
+
const result = findBlock(value, callback);
|
|
391
|
+
if (result) return result;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return null;
|
|
396
|
+
};
|
|
397
|
+
const hasSlots = (block) => {
|
|
398
|
+
return !!block.slots && Object.keys(block.slots).length > 0;
|
|
399
|
+
};
|
|
400
|
+
const hasMultipleSlots = (block) => {
|
|
401
|
+
if (!block.slots || Object.keys(block.slots).length === 0) return false;
|
|
402
|
+
return Object.keys(block.slots).length > 1 || Object.keys(block.slots)[0] !== "default";
|
|
403
|
+
};
|
|
404
|
+
const forEachChildren = (block, content, callback) => {
|
|
405
|
+
if (!hasSlots(block)) {
|
|
406
|
+
if (content.children) {
|
|
407
|
+
delete content.children;
|
|
408
|
+
}
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (hasMultipleSlots(block)) {
|
|
412
|
+
if (!content.children) content.children = {};
|
|
413
|
+
if (Array.isArray(content.children)) content.children = { default: content.children };
|
|
414
|
+
for (let key in block.slots) {
|
|
415
|
+
if (!content.children[key]) content.children[key] = [];
|
|
416
|
+
callback(content.children[key]);
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
if (!content.children) content.children = [];
|
|
420
|
+
if (!Array.isArray(content.children)) content.children = content.children.default ?? [];
|
|
421
|
+
callback(content.children);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const deleteBlock = (blocks, target) => {
|
|
425
|
+
let isDeleted = false;
|
|
426
|
+
walkTree(blocks, (block) => {
|
|
427
|
+
if (!block.children) return;
|
|
428
|
+
if (Array.isArray(block.children)) {
|
|
429
|
+
if (deleteFromArray(block.children, target)) {
|
|
430
|
+
isDeleted = true;
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
for (let children of Object.values(block.children)) {
|
|
434
|
+
if (deleteFromArray(children, target)) {
|
|
435
|
+
isDeleted = true;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
if (!isDeleted) {
|
|
441
|
+
deleteFromArray(blocks, target);
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
const createContentBlockChild = (blocksMap2, contentBlock, parent, index = -1) => {
|
|
445
|
+
const parentBlock = blocksMap2.get(parent.blockId);
|
|
446
|
+
if (!parentBlock.slots) return;
|
|
447
|
+
if (Object.keys(parentBlock.slots).length === 1 && Object.keys(parentBlock.slots)[0] === "default") {
|
|
448
|
+
if (!parent.children) parent.children = [];
|
|
449
|
+
if (!Array.isArray(parent.children)) parent.children = parent.children.default ?? [];
|
|
450
|
+
if (index < 0) {
|
|
451
|
+
parent.children.push(contentBlock);
|
|
452
|
+
} else {
|
|
453
|
+
parent.children.splice(index, 0, contentBlock);
|
|
454
|
+
}
|
|
455
|
+
} else {
|
|
456
|
+
if (!parent.children || Array.isArray(parent.children)) parent.children = {};
|
|
457
|
+
if (index < 0) {
|
|
458
|
+
const key = "default" in parentBlock.slots ? "default" : Object.keys(parentBlock.slots)[0];
|
|
459
|
+
if (!parent.children[key]) parent.children[key] = [];
|
|
460
|
+
parent.children[key].push(contentBlock);
|
|
461
|
+
} else {
|
|
462
|
+
let startIndex = 0;
|
|
463
|
+
for (let children of Object.values(parent.children)) {
|
|
464
|
+
if (index - startIndex <= children.length) {
|
|
465
|
+
children.splice(index - startIndex, 0, contentBlock);
|
|
466
|
+
}
|
|
467
|
+
startIndex += children.length;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
const getBlockIndex = (parent, target) => {
|
|
473
|
+
if (!parent.children) return -1;
|
|
474
|
+
if (Array.isArray(parent.children)) {
|
|
475
|
+
return parent.children.indexOf(target);
|
|
476
|
+
} else {
|
|
477
|
+
let startIndex = 0;
|
|
478
|
+
for (let children of Object.values(parent.children)) {
|
|
479
|
+
const index = children.indexOf(target);
|
|
480
|
+
if (index >= 0) {
|
|
481
|
+
return startIndex + index;
|
|
482
|
+
}
|
|
483
|
+
startIndex += children.length;
|
|
484
|
+
}
|
|
485
|
+
return -1;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
const createContentBlock = (block) => {
|
|
489
|
+
const id = uid();
|
|
490
|
+
return {
|
|
491
|
+
id,
|
|
492
|
+
blockId: block.id,
|
|
493
|
+
data: {
|
|
494
|
+
...passDefaultValue({}, block.props),
|
|
495
|
+
"data-block-id": id
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
};
|
|
499
|
+
const deleteFromArray = (arr, item) => {
|
|
500
|
+
const index = arr.indexOf(item);
|
|
501
|
+
if (index < 0) return false;
|
|
502
|
+
arr.splice(index, 1);
|
|
503
|
+
return true;
|
|
504
|
+
};
|
|
505
|
+
const uid = () => {
|
|
506
|
+
return Math.trunc(Math.random() * 1e5).toString(16);
|
|
507
|
+
};
|
|
508
|
+
function tryOnScopeDispose(fn) {
|
|
509
|
+
if (getCurrentScope()) {
|
|
510
|
+
onScopeDispose(fn);
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
function createEventHook() {
|
|
516
|
+
const fns = /* @__PURE__ */ new Set();
|
|
517
|
+
const off = (fn) => {
|
|
518
|
+
fns.delete(fn);
|
|
519
|
+
};
|
|
520
|
+
const clear = () => {
|
|
521
|
+
fns.clear();
|
|
522
|
+
};
|
|
523
|
+
const on = (fn) => {
|
|
524
|
+
fns.add(fn);
|
|
525
|
+
const offFn = () => off(fn);
|
|
526
|
+
tryOnScopeDispose(offFn);
|
|
527
|
+
return {
|
|
528
|
+
off: offFn
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
const trigger = (...args) => {
|
|
532
|
+
return Promise.all(Array.from(fns).map((fn) => fn(...args)));
|
|
533
|
+
};
|
|
534
|
+
return {
|
|
535
|
+
on,
|
|
536
|
+
off,
|
|
537
|
+
trigger,
|
|
538
|
+
clear
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
542
|
+
typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
543
|
+
const isDef = (val) => typeof val !== "undefined";
|
|
544
|
+
const toString = Object.prototype.toString;
|
|
545
|
+
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
546
|
+
const noop = () => {
|
|
547
|
+
};
|
|
548
|
+
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
549
|
+
function createFilterWrapper(filter, fn) {
|
|
550
|
+
function wrapper(...args) {
|
|
551
|
+
return new Promise((resolve, reject) => {
|
|
552
|
+
Promise.resolve(filter(() => fn.apply(this, args), { fn, thisArg: this, args })).then(resolve).catch(reject);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
return wrapper;
|
|
556
|
+
}
|
|
557
|
+
const bypassFilter = (invoke) => {
|
|
558
|
+
return invoke();
|
|
559
|
+
};
|
|
560
|
+
function debounceFilter(ms, options = {}) {
|
|
561
|
+
let timer;
|
|
562
|
+
let maxTimer;
|
|
563
|
+
let lastRejector = noop;
|
|
564
|
+
const _clearTimeout = (timer2) => {
|
|
565
|
+
clearTimeout(timer2);
|
|
566
|
+
lastRejector();
|
|
567
|
+
lastRejector = noop;
|
|
568
|
+
};
|
|
569
|
+
const filter = (invoke) => {
|
|
570
|
+
const duration = toValue(ms);
|
|
571
|
+
const maxDuration = toValue(options.maxWait);
|
|
572
|
+
if (timer)
|
|
573
|
+
_clearTimeout(timer);
|
|
574
|
+
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
575
|
+
if (maxTimer) {
|
|
576
|
+
_clearTimeout(maxTimer);
|
|
577
|
+
maxTimer = null;
|
|
578
|
+
}
|
|
579
|
+
return Promise.resolve(invoke());
|
|
580
|
+
}
|
|
581
|
+
return new Promise((resolve, reject) => {
|
|
582
|
+
lastRejector = options.rejectOnCancel ? reject : resolve;
|
|
583
|
+
if (maxDuration && !maxTimer) {
|
|
584
|
+
maxTimer = setTimeout(() => {
|
|
585
|
+
if (timer)
|
|
586
|
+
_clearTimeout(timer);
|
|
587
|
+
maxTimer = null;
|
|
588
|
+
resolve(invoke());
|
|
589
|
+
}, maxDuration);
|
|
590
|
+
}
|
|
591
|
+
timer = setTimeout(() => {
|
|
592
|
+
if (maxTimer)
|
|
593
|
+
_clearTimeout(maxTimer);
|
|
594
|
+
maxTimer = null;
|
|
595
|
+
resolve(invoke());
|
|
596
|
+
}, duration);
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
return filter;
|
|
600
|
+
}
|
|
601
|
+
function toArray(value) {
|
|
602
|
+
return Array.isArray(value) ? value : [value];
|
|
603
|
+
}
|
|
604
|
+
function toRef(...args) {
|
|
605
|
+
if (args.length !== 1)
|
|
606
|
+
return toRef$1(...args);
|
|
607
|
+
const r = args[0];
|
|
608
|
+
return typeof r === "function" ? readonly(customRef(() => ({ get: r, set: noop }))) : ref(r);
|
|
609
|
+
}
|
|
610
|
+
function watchWithFilter(source, cb, options = {}) {
|
|
611
|
+
const {
|
|
612
|
+
eventFilter = bypassFilter,
|
|
613
|
+
...watchOptions
|
|
614
|
+
} = options;
|
|
615
|
+
return watch(
|
|
616
|
+
source,
|
|
617
|
+
createFilterWrapper(
|
|
618
|
+
eventFilter,
|
|
619
|
+
cb
|
|
620
|
+
),
|
|
621
|
+
watchOptions
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
function watchDebounced(source, cb, options = {}) {
|
|
625
|
+
const {
|
|
626
|
+
debounce = 0,
|
|
627
|
+
maxWait = void 0,
|
|
628
|
+
...watchOptions
|
|
629
|
+
} = options;
|
|
630
|
+
return watchWithFilter(
|
|
631
|
+
source,
|
|
632
|
+
cb,
|
|
633
|
+
{
|
|
634
|
+
...watchOptions,
|
|
635
|
+
eventFilter: debounceFilter(debounce, { maxWait })
|
|
636
|
+
}
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
const defaultWindow = isClient ? window : void 0;
|
|
640
|
+
const defaultDocument = isClient ? window.document : void 0;
|
|
641
|
+
function unrefElement(elRef) {
|
|
642
|
+
var _a;
|
|
643
|
+
const plain = toValue(elRef);
|
|
644
|
+
return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
|
|
645
|
+
}
|
|
646
|
+
function useEventListener(...args) {
|
|
647
|
+
let target;
|
|
648
|
+
let events;
|
|
649
|
+
let listeners2;
|
|
650
|
+
let options;
|
|
651
|
+
if (typeof args[0] === "string" || Array.isArray(args[0])) {
|
|
652
|
+
[events, listeners2, options] = args;
|
|
653
|
+
target = defaultWindow;
|
|
654
|
+
} else {
|
|
655
|
+
[target, events, listeners2, options] = args;
|
|
656
|
+
}
|
|
657
|
+
if (!target)
|
|
658
|
+
return noop;
|
|
659
|
+
events = toArray(events);
|
|
660
|
+
listeners2 = toArray(listeners2);
|
|
661
|
+
const cleanups = [];
|
|
662
|
+
const cleanup = () => {
|
|
663
|
+
cleanups.forEach((fn) => fn());
|
|
664
|
+
cleanups.length = 0;
|
|
665
|
+
};
|
|
666
|
+
const register = (el, event, listener, options2) => {
|
|
667
|
+
el.addEventListener(event, listener, options2);
|
|
668
|
+
return () => el.removeEventListener(event, listener, options2);
|
|
669
|
+
};
|
|
670
|
+
const stopWatch = watch(
|
|
671
|
+
() => [unrefElement(target), toValue(options)],
|
|
672
|
+
([el, options2]) => {
|
|
673
|
+
cleanup();
|
|
674
|
+
if (!el)
|
|
675
|
+
return;
|
|
676
|
+
const optionsClone = isObject(options2) ? { ...options2 } : options2;
|
|
677
|
+
cleanups.push(
|
|
678
|
+
...events.flatMap((event) => {
|
|
679
|
+
return listeners2.map((listener) => register(el, event, listener, optionsClone));
|
|
680
|
+
})
|
|
681
|
+
);
|
|
682
|
+
},
|
|
683
|
+
{ immediate: true, flush: "post" }
|
|
684
|
+
);
|
|
685
|
+
const stop = () => {
|
|
686
|
+
stopWatch();
|
|
687
|
+
cleanup();
|
|
688
|
+
};
|
|
689
|
+
tryOnScopeDispose(stop);
|
|
690
|
+
return stop;
|
|
691
|
+
}
|
|
692
|
+
function useMounted() {
|
|
693
|
+
const isMounted = ref(false);
|
|
694
|
+
const instance = getCurrentInstance();
|
|
695
|
+
if (instance) {
|
|
696
|
+
onMounted(() => {
|
|
697
|
+
isMounted.value = true;
|
|
698
|
+
}, instance);
|
|
699
|
+
}
|
|
700
|
+
return isMounted;
|
|
701
|
+
}
|
|
702
|
+
function useSupported(callback) {
|
|
703
|
+
const isMounted = useMounted();
|
|
704
|
+
return computed(() => {
|
|
705
|
+
isMounted.value;
|
|
706
|
+
return Boolean(callback());
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
function cloneFnJSON(source) {
|
|
710
|
+
return JSON.parse(JSON.stringify(source));
|
|
711
|
+
}
|
|
712
|
+
function useResizeObserver(target, callback, options = {}) {
|
|
713
|
+
const { window: window2 = defaultWindow, ...observerOptions } = options;
|
|
714
|
+
let observer;
|
|
715
|
+
const isSupported = useSupported(() => window2 && "ResizeObserver" in window2);
|
|
716
|
+
const cleanup = () => {
|
|
717
|
+
if (observer) {
|
|
718
|
+
observer.disconnect();
|
|
719
|
+
observer = void 0;
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
const targets = computed(() => {
|
|
723
|
+
const _targets = toValue(target);
|
|
724
|
+
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
725
|
+
});
|
|
726
|
+
const stopWatch = watch(
|
|
727
|
+
targets,
|
|
728
|
+
(els) => {
|
|
729
|
+
cleanup();
|
|
730
|
+
if (isSupported.value && window2) {
|
|
731
|
+
observer = new ResizeObserver(callback);
|
|
732
|
+
for (const _el of els) {
|
|
733
|
+
if (_el)
|
|
734
|
+
observer.observe(_el, observerOptions);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
{ immediate: true, flush: "post" }
|
|
739
|
+
);
|
|
740
|
+
const stop = () => {
|
|
741
|
+
cleanup();
|
|
742
|
+
stopWatch();
|
|
743
|
+
};
|
|
744
|
+
tryOnScopeDispose(stop);
|
|
745
|
+
return {
|
|
746
|
+
isSupported,
|
|
747
|
+
stop
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
const DEFAULT_OPTIONS = {
|
|
751
|
+
multiple: true,
|
|
752
|
+
accept: "*",
|
|
753
|
+
reset: false,
|
|
754
|
+
directory: false
|
|
755
|
+
};
|
|
756
|
+
function useFileDialog(options = {}) {
|
|
757
|
+
const {
|
|
758
|
+
document: document2 = defaultDocument
|
|
759
|
+
} = options;
|
|
760
|
+
const files = ref(null);
|
|
761
|
+
const { on: onChange, trigger: changeTrigger } = createEventHook();
|
|
762
|
+
const { on: onCancel, trigger: cancelTrigger } = createEventHook();
|
|
763
|
+
let input;
|
|
764
|
+
if (document2) {
|
|
765
|
+
input = document2.createElement("input");
|
|
766
|
+
input.type = "file";
|
|
767
|
+
input.onchange = (event) => {
|
|
768
|
+
const result = event.target;
|
|
769
|
+
files.value = result.files;
|
|
770
|
+
changeTrigger(files.value);
|
|
771
|
+
};
|
|
772
|
+
input.oncancel = () => {
|
|
773
|
+
cancelTrigger();
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
const reset = () => {
|
|
777
|
+
files.value = null;
|
|
778
|
+
if (input && input.value) {
|
|
779
|
+
input.value = "";
|
|
780
|
+
changeTrigger(null);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
const open = (localOptions) => {
|
|
784
|
+
if (!input)
|
|
785
|
+
return;
|
|
786
|
+
const _options = {
|
|
787
|
+
...DEFAULT_OPTIONS,
|
|
788
|
+
...options,
|
|
789
|
+
...localOptions
|
|
790
|
+
};
|
|
791
|
+
input.multiple = _options.multiple;
|
|
792
|
+
input.accept = _options.accept;
|
|
793
|
+
input.webkitdirectory = _options.directory;
|
|
794
|
+
if (hasOwn(_options, "capture"))
|
|
795
|
+
input.capture = _options.capture;
|
|
796
|
+
if (_options.reset)
|
|
797
|
+
reset();
|
|
798
|
+
input.click();
|
|
799
|
+
};
|
|
800
|
+
return {
|
|
801
|
+
files: readonly(files),
|
|
802
|
+
open,
|
|
803
|
+
reset,
|
|
804
|
+
onCancel,
|
|
805
|
+
onChange
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
function useTextareaAutosize(options) {
|
|
809
|
+
var _a, _b;
|
|
810
|
+
const textarea = toRef(options == null ? void 0 : options.element);
|
|
811
|
+
const input = toRef((_a = options == null ? void 0 : options.input) != null ? _a : "");
|
|
812
|
+
const styleProp = (_b = options == null ? void 0 : options.styleProp) != null ? _b : "height";
|
|
813
|
+
const textareaScrollHeight = ref(1);
|
|
814
|
+
const textareaOldWidth = ref(0);
|
|
815
|
+
function triggerResize() {
|
|
816
|
+
var _a2;
|
|
817
|
+
if (!textarea.value)
|
|
818
|
+
return;
|
|
819
|
+
let height = "";
|
|
820
|
+
textarea.value.style[styleProp] = "1px";
|
|
821
|
+
textareaScrollHeight.value = (_a2 = textarea.value) == null ? void 0 : _a2.scrollHeight;
|
|
822
|
+
const _styleTarget = toValue(options == null ? void 0 : options.styleTarget);
|
|
823
|
+
if (_styleTarget)
|
|
824
|
+
_styleTarget.style[styleProp] = `${textareaScrollHeight.value}px`;
|
|
825
|
+
else
|
|
826
|
+
height = `${textareaScrollHeight.value}px`;
|
|
827
|
+
textarea.value.style[styleProp] = height;
|
|
828
|
+
}
|
|
829
|
+
watch([input, textarea], () => nextTick(triggerResize), { immediate: true });
|
|
830
|
+
watch(textareaScrollHeight, () => {
|
|
831
|
+
var _a2;
|
|
832
|
+
return (_a2 = options == null ? void 0 : options.onResize) == null ? void 0 : _a2.call(options);
|
|
833
|
+
});
|
|
834
|
+
useResizeObserver(textarea, ([{ contentRect }]) => {
|
|
835
|
+
if (textareaOldWidth.value === contentRect.width)
|
|
836
|
+
return;
|
|
837
|
+
textareaOldWidth.value = contentRect.width;
|
|
838
|
+
triggerResize();
|
|
839
|
+
});
|
|
840
|
+
if (options == null ? void 0 : options.watch)
|
|
841
|
+
watch(options.watch, triggerResize, { immediate: true, deep: true });
|
|
842
|
+
return {
|
|
843
|
+
textarea,
|
|
844
|
+
input,
|
|
845
|
+
triggerResize
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
function useVModel(props, key, emit, options = {}) {
|
|
849
|
+
var _a, _b, _c;
|
|
850
|
+
const {
|
|
851
|
+
clone = false,
|
|
852
|
+
passive = false,
|
|
853
|
+
eventName,
|
|
854
|
+
deep = false,
|
|
855
|
+
defaultValue,
|
|
856
|
+
shouldEmit
|
|
857
|
+
} = options;
|
|
858
|
+
const vm = getCurrentInstance();
|
|
859
|
+
const _emit = emit || (vm == null ? void 0 : vm.emit) || ((_a = vm == null ? void 0 : vm.$emit) == null ? void 0 : _a.bind(vm)) || ((_c = (_b = vm == null ? void 0 : vm.proxy) == null ? void 0 : _b.$emit) == null ? void 0 : _c.bind(vm == null ? void 0 : vm.proxy));
|
|
860
|
+
let event = eventName;
|
|
861
|
+
if (!key) {
|
|
862
|
+
key = "modelValue";
|
|
863
|
+
}
|
|
864
|
+
event = event || `update:${key.toString()}`;
|
|
865
|
+
const cloneFn = (val) => !clone ? val : typeof clone === "function" ? clone(val) : cloneFnJSON(val);
|
|
866
|
+
const getValue = () => isDef(props[key]) ? cloneFn(props[key]) : defaultValue;
|
|
867
|
+
const triggerEmit = (value) => {
|
|
868
|
+
if (shouldEmit) {
|
|
869
|
+
if (shouldEmit(value))
|
|
870
|
+
_emit(event, value);
|
|
871
|
+
} else {
|
|
872
|
+
_emit(event, value);
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
if (passive) {
|
|
876
|
+
const initialValue = getValue();
|
|
877
|
+
const proxy = ref(initialValue);
|
|
878
|
+
let isUpdating = false;
|
|
879
|
+
watch(
|
|
880
|
+
() => props[key],
|
|
881
|
+
(v) => {
|
|
882
|
+
if (!isUpdating) {
|
|
883
|
+
isUpdating = true;
|
|
884
|
+
proxy.value = cloneFn(v);
|
|
885
|
+
nextTick(() => isUpdating = false);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
);
|
|
889
|
+
watch(
|
|
890
|
+
proxy,
|
|
891
|
+
(v) => {
|
|
892
|
+
if (!isUpdating && (v !== props[key] || deep))
|
|
893
|
+
triggerEmit(v);
|
|
894
|
+
},
|
|
895
|
+
{ deep }
|
|
896
|
+
);
|
|
897
|
+
return proxy;
|
|
898
|
+
} else {
|
|
899
|
+
return computed({
|
|
900
|
+
get() {
|
|
901
|
+
return getValue();
|
|
902
|
+
},
|
|
903
|
+
set(value) {
|
|
904
|
+
triggerEmit(value);
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
const margin = 8;
|
|
910
|
+
const _sfc_main$l = /* @__PURE__ */ defineComponent({
|
|
911
|
+
...{
|
|
912
|
+
inheritAttrs: false
|
|
913
|
+
},
|
|
914
|
+
__name: "VPopover",
|
|
915
|
+
props: {
|
|
916
|
+
open: { type: Boolean },
|
|
917
|
+
element: {},
|
|
918
|
+
placement: {},
|
|
919
|
+
offset: {},
|
|
920
|
+
fitAnchor: { type: Boolean },
|
|
921
|
+
class: {},
|
|
922
|
+
anchorPosition: {}
|
|
923
|
+
},
|
|
924
|
+
emits: ["update:open"],
|
|
925
|
+
setup(__props, { emit: __emit }) {
|
|
926
|
+
const props = __props;
|
|
927
|
+
const emit = __emit;
|
|
928
|
+
const popoverRef = ref();
|
|
929
|
+
const position = ref({ top: 0, left: 0 });
|
|
930
|
+
const origin = ref("center");
|
|
931
|
+
const open = useVModel(props, "open", emit, { passive: true });
|
|
932
|
+
const activatorElement = ref();
|
|
933
|
+
const clamp = (value, min, max) => {
|
|
934
|
+
if (value < min) return min;
|
|
935
|
+
if (value > max) return max;
|
|
936
|
+
return value;
|
|
937
|
+
};
|
|
938
|
+
const calcPrimary = (pos, start, end, size, min, max) => {
|
|
939
|
+
const fitStart = start - size >= min;
|
|
940
|
+
const fitEnd = end + size <= max;
|
|
941
|
+
if ((!fitEnd || pos === "start") && fitStart) return start - size;
|
|
942
|
+
if ((!fitStart || pos === "end") && fitEnd) return end;
|
|
943
|
+
return pos === "start" ? min : max - size;
|
|
944
|
+
};
|
|
945
|
+
const calcSub = (pos, start, end, size, min, max) => {
|
|
946
|
+
if (pos === "start") return clamp(start, min, max - size);
|
|
947
|
+
if (pos === "end") return clamp(end - size, min, max - size);
|
|
948
|
+
return clamp((start + end) / 2 - size / 2, min, max - size);
|
|
949
|
+
};
|
|
950
|
+
const calcOrigin = (start, end, point) => {
|
|
951
|
+
return clamp(Math.round((point - start) / (end - start) * 100), 0, 100) + "%";
|
|
952
|
+
};
|
|
953
|
+
const getRect = () => {
|
|
954
|
+
if (props.anchorPosition) {
|
|
955
|
+
return {
|
|
956
|
+
top: props.anchorPosition.y,
|
|
957
|
+
bottom: props.anchorPosition.y,
|
|
958
|
+
left: props.anchorPosition.x,
|
|
959
|
+
right: props.anchorPosition.x,
|
|
960
|
+
width: 0,
|
|
961
|
+
height: 0
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
const element = props.element ?? activatorElement.value;
|
|
965
|
+
if (!element) return null;
|
|
966
|
+
return element.getBoundingClientRect();
|
|
967
|
+
};
|
|
968
|
+
const isHorizontal = computed(() => props.placement.startsWith("left") || props.placement.startsWith("right"));
|
|
969
|
+
const calcPosition = () => {
|
|
970
|
+
if (!popoverRef.value) return;
|
|
971
|
+
const rect = getRect();
|
|
972
|
+
if (!rect) return;
|
|
973
|
+
const placement = props.placement.split("-");
|
|
974
|
+
const offset = props.offset ?? 0;
|
|
975
|
+
const width = popoverRef.value.clientWidth;
|
|
976
|
+
const height = popoverRef.value.clientHeight;
|
|
977
|
+
if (placement[0] === "top" || placement[0] === "bottom") {
|
|
978
|
+
const top = calcPrimary(placement[0] === "top" ? "start" : "end", rect.top - offset, rect.bottom + offset, height, margin, window.innerHeight - margin);
|
|
979
|
+
if (props.fitAnchor) {
|
|
980
|
+
position.value = {
|
|
981
|
+
top,
|
|
982
|
+
left: calcSub("start", rect.left, rect.right, rect.width, margin, window.innerWidth - margin),
|
|
983
|
+
width: rect.width
|
|
984
|
+
};
|
|
985
|
+
} else {
|
|
986
|
+
position.value = { top, left: calcSub(placement[1], rect.left, rect.right, width, margin, window.innerWidth - margin) };
|
|
987
|
+
}
|
|
988
|
+
} else {
|
|
989
|
+
const left = calcPrimary(placement[0] === "left" ? "start" : "end", rect.left - offset, rect.right + offset, width, margin, window.innerWidth - margin);
|
|
990
|
+
if (props.fitAnchor) {
|
|
991
|
+
position.value = {
|
|
992
|
+
left,
|
|
993
|
+
top: calcSub("start", rect.top, rect.bottom, rect.height, margin, window.innerHeight - margin),
|
|
994
|
+
height: rect.height
|
|
995
|
+
};
|
|
996
|
+
} else {
|
|
997
|
+
position.value = { left, top: calcSub(placement[1], rect.top, rect.bottom, height, margin, window.innerHeight - margin) };
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
origin.value = calcOrigin(position.value.left, position.value.left + width, rect.left + rect.width / 2) + calcOrigin(position.value.top, position.value.top + height, rect.top + rect.height / 2);
|
|
1001
|
+
};
|
|
1002
|
+
watch([() => props.element, () => props.anchorPosition], () => {
|
|
1003
|
+
calcPosition();
|
|
1004
|
+
});
|
|
1005
|
+
useResizeObserver(popoverRef, calcPosition);
|
|
1006
|
+
useEventListener(window, "resize", calcPosition);
|
|
1007
|
+
const close = () => {
|
|
1008
|
+
open.value = false;
|
|
1009
|
+
};
|
|
1010
|
+
const closeDelayed = () => {
|
|
1011
|
+
setTimeout(close, 0);
|
|
1012
|
+
};
|
|
1013
|
+
useKeyDownLayer("Escape", open, close);
|
|
1014
|
+
useMouseDownOutside(open, closeDelayed, popoverRef);
|
|
1015
|
+
watch(open, (open2) => {
|
|
1016
|
+
if (!props.element) return;
|
|
1017
|
+
if (open2) {
|
|
1018
|
+
props.element.classList.add("popoverHover");
|
|
1019
|
+
} else {
|
|
1020
|
+
props.element.classList.remove("popoverHover");
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
const activatorProps = {
|
|
1024
|
+
onMousedown: (e) => {
|
|
1025
|
+
open.value = !open.value;
|
|
1026
|
+
if (open.value) {
|
|
1027
|
+
activatorElement.value = e.currentTarget;
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
onTouchstart: (e) => {
|
|
1031
|
+
open.value = !open.value;
|
|
1032
|
+
if (open.value) {
|
|
1033
|
+
activatorElement.value = e.currentTarget;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
const style = computed(() => {
|
|
1038
|
+
return {
|
|
1039
|
+
left: position.value.left + "px",
|
|
1040
|
+
top: position.value.top + "px",
|
|
1041
|
+
width: position.value.width ? position.value.width + "px" : void 0,
|
|
1042
|
+
height: position.value.height ? position.value.height + "px" : void 0,
|
|
1043
|
+
transformOrigin: origin.value
|
|
1044
|
+
};
|
|
1045
|
+
});
|
|
1046
|
+
return (_ctx, _cache) => {
|
|
1047
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
1048
|
+
(openBlock(), createBlock(Teleport, { to: "body" }, [
|
|
1049
|
+
createVNode(Transition, null, {
|
|
1050
|
+
default: withCtx(() => [
|
|
1051
|
+
unref(open) ? (openBlock(), createElementBlock("div", mergeProps({ key: 0 }, _ctx.$attrs, {
|
|
1052
|
+
class: ["v-popover editor-component", [isHorizontal.value ? "horizontal" : "vertical", props.fitAnchor && "fit-anchor", props.class]],
|
|
1053
|
+
style: style.value,
|
|
1054
|
+
ref_key: "popoverRef",
|
|
1055
|
+
ref: popoverRef,
|
|
1056
|
+
onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {
|
|
1057
|
+
}, ["stop"]))
|
|
1058
|
+
}), [
|
|
1059
|
+
renderSlot(_ctx.$slots, "default")
|
|
1060
|
+
], 16)) : createCommentVNode("", true)
|
|
1061
|
+
]),
|
|
1062
|
+
_: 3
|
|
1063
|
+
})
|
|
1064
|
+
])),
|
|
1065
|
+
renderSlot(_ctx.$slots, "activator", { props: activatorProps })
|
|
1066
|
+
], 64);
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
const _sfc_main$k = /* @__PURE__ */ defineComponent({
|
|
1071
|
+
__name: "VButton",
|
|
1072
|
+
props: {
|
|
1073
|
+
component: {},
|
|
1074
|
+
disabled: { type: Boolean },
|
|
1075
|
+
flat: { type: Boolean },
|
|
1076
|
+
outline: { type: Boolean },
|
|
1077
|
+
large: { type: Boolean }
|
|
1078
|
+
},
|
|
1079
|
+
setup(__props) {
|
|
1080
|
+
return (_ctx, _cache) => {
|
|
1081
|
+
return openBlock(), createBlock(resolveDynamicComponent(_ctx.component ?? "button"), {
|
|
1082
|
+
class: normalizeClass(["v-button", { disabled: _ctx.disabled, flat: _ctx.flat, outline: _ctx.outline, large: _ctx.large }])
|
|
1083
|
+
}, {
|
|
1084
|
+
default: withCtx(() => [
|
|
1085
|
+
renderSlot(_ctx.$slots, "default")
|
|
1086
|
+
]),
|
|
1087
|
+
_: 3
|
|
1088
|
+
}, 8, ["class"]);
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
const useContextMenu = (creator) => {
|
|
1093
|
+
let target = null;
|
|
1094
|
+
const props = reactive({
|
|
1095
|
+
items: [],
|
|
1096
|
+
open: false,
|
|
1097
|
+
anchorPosition: { x: 0, y: 0 },
|
|
1098
|
+
"onUpdate:open": (value) => {
|
|
1099
|
+
if (value === false && target !== null) {
|
|
1100
|
+
target.removeAttribute("data-popover-target");
|
|
1101
|
+
target = null;
|
|
1102
|
+
}
|
|
1103
|
+
props.open = value;
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
const open = (e, ...args) => {
|
|
1107
|
+
e.preventDefault();
|
|
1108
|
+
props.items = creator(...args);
|
|
1109
|
+
props.anchorPosition = { x: e.clientX, y: e.clientY };
|
|
1110
|
+
props.open = true;
|
|
1111
|
+
if (target !== null) {
|
|
1112
|
+
target.removeAttribute("data-popover-target");
|
|
1113
|
+
target = null;
|
|
1114
|
+
}
|
|
1115
|
+
target = e.currentTarget;
|
|
1116
|
+
target.setAttribute("data-popover-target", "true");
|
|
1117
|
+
};
|
|
1118
|
+
return {
|
|
1119
|
+
props,
|
|
1120
|
+
open
|
|
1121
|
+
};
|
|
1122
|
+
};
|
|
1123
|
+
const _sfc_main$j = /* @__PURE__ */ defineComponent({
|
|
1124
|
+
__name: "VContextMenu",
|
|
1125
|
+
props: {
|
|
1126
|
+
open: { type: Boolean },
|
|
1127
|
+
placement: {},
|
|
1128
|
+
anchorPosition: {},
|
|
1129
|
+
offset: {},
|
|
1130
|
+
items: { type: [Array, Function] }
|
|
1131
|
+
},
|
|
1132
|
+
emits: ["update:open"],
|
|
1133
|
+
setup(__props, { emit: __emit }) {
|
|
1134
|
+
const props = __props;
|
|
1135
|
+
const activatorElement = ref();
|
|
1136
|
+
const emit = __emit;
|
|
1137
|
+
const open = useVModel(props, "open", emit, { passive: true });
|
|
1138
|
+
const items = shallowRef([]);
|
|
1139
|
+
watch(open, (open2) => {
|
|
1140
|
+
if (!open2) return;
|
|
1141
|
+
const _items = typeof props.items === "function" ? props.items() : props.items;
|
|
1142
|
+
items.value = _items.filter((item) => !!item);
|
|
1143
|
+
});
|
|
1144
|
+
const activatorProps = {
|
|
1145
|
+
onClick: (e) => {
|
|
1146
|
+
open.value = true;
|
|
1147
|
+
activatorElement.value = e.currentTarget;
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
const onItemClick = (item) => {
|
|
1151
|
+
var _a, _b;
|
|
1152
|
+
if (item.onClick) {
|
|
1153
|
+
item.onClick();
|
|
1154
|
+
open.value = false;
|
|
1155
|
+
}
|
|
1156
|
+
if (((_a = item.props) == null ? void 0 : _a.to) || ((_b = item.props) == null ? void 0 : _b.href)) {
|
|
1157
|
+
open.value = false;
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
return (_ctx, _cache) => {
|
|
1161
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
1162
|
+
renderSlot(_ctx.$slots, "activator", { props: activatorProps }),
|
|
1163
|
+
createVNode(_sfc_main$l, {
|
|
1164
|
+
open: unref(open),
|
|
1165
|
+
"onUpdate:open": _cache[0] || (_cache[0] = ($event) => isRef(open) ? open.value = $event : null),
|
|
1166
|
+
element: activatorElement.value,
|
|
1167
|
+
anchorPosition: props.anchorPosition,
|
|
1168
|
+
placement: props.placement ?? "bottom-start",
|
|
1169
|
+
offset: _ctx.offset,
|
|
1170
|
+
class: "v-context-menu"
|
|
1171
|
+
}, {
|
|
1172
|
+
default: withCtx(() => [
|
|
1173
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(items.value, (item) => {
|
|
1174
|
+
return openBlock(), createBlock(_sfc_main$k, mergeProps({ ref_for: true }, item.props, {
|
|
1175
|
+
class: "v-context-menu__item",
|
|
1176
|
+
onClick: ($event) => onItemClick(item)
|
|
1177
|
+
}), {
|
|
1178
|
+
default: withCtx(() => [
|
|
1179
|
+
createTextVNode(toDisplayString(item.title), 1)
|
|
1180
|
+
]),
|
|
1181
|
+
_: 2
|
|
1182
|
+
}, 1040, ["onClick"]);
|
|
1183
|
+
}), 256))
|
|
1184
|
+
]),
|
|
1185
|
+
_: 1
|
|
1186
|
+
}, 8, ["open", "element", "anchorPosition", "placement", "offset"])
|
|
1187
|
+
], 64);
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
const _hoisted_1$f = ["onBlockdrop", "onMousedown", "onMouseenter", "onClick", "onContextmenu"];
|
|
1192
|
+
const _hoisted_2$4 = ["onBlockdrop"];
|
|
1193
|
+
const _sfc_main$i = /* @__PURE__ */ defineComponent({
|
|
1194
|
+
__name: "ContentHierarchy",
|
|
1195
|
+
props: {
|
|
1196
|
+
contentBlocks: {},
|
|
1197
|
+
blocksMap: {},
|
|
1198
|
+
hoverBlockId: {},
|
|
1199
|
+
activeBlockId: {}
|
|
1200
|
+
},
|
|
1201
|
+
emits: ["update:hoverBlockId", "update:activeBlockId"],
|
|
1202
|
+
setup(__props, { emit: __emit }) {
|
|
1203
|
+
const props = __props;
|
|
1204
|
+
const emit = __emit;
|
|
1205
|
+
const flatBlocks = computed(() => {
|
|
1206
|
+
const arr = [];
|
|
1207
|
+
const collectBlocks = (items, intent = 0, parent = null) => {
|
|
1208
|
+
for (let i = 0; i < items.length; i++) {
|
|
1209
|
+
const data = items[i];
|
|
1210
|
+
const block = props.blocksMap.get(data.blockId);
|
|
1211
|
+
if (!block) {
|
|
1212
|
+
arr.push({
|
|
1213
|
+
content: data,
|
|
1214
|
+
key: data.id,
|
|
1215
|
+
intent,
|
|
1216
|
+
hasSlots: false,
|
|
1217
|
+
hasMultipleSlots: false,
|
|
1218
|
+
block: {},
|
|
1219
|
+
parent
|
|
1220
|
+
});
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
arr.push({
|
|
1224
|
+
content: data,
|
|
1225
|
+
key: data.id,
|
|
1226
|
+
intent,
|
|
1227
|
+
hasSlots: hasSlots(block),
|
|
1228
|
+
hasMultipleSlots: hasMultipleSlots(block),
|
|
1229
|
+
block,
|
|
1230
|
+
parent
|
|
1231
|
+
});
|
|
1232
|
+
forEachChildren(block, data, (blocks) => {
|
|
1233
|
+
collectBlocks(blocks, intent + 1, data);
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
collectBlocks(props.contentBlocks);
|
|
1238
|
+
return arr;
|
|
1239
|
+
});
|
|
1240
|
+
const drag = useDraggableItem();
|
|
1241
|
+
const dragMode = inject("dragMode");
|
|
1242
|
+
const onItemMouseDown = (e, item) => {
|
|
1243
|
+
if (e.button !== 0) return;
|
|
1244
|
+
const target = e.currentTarget;
|
|
1245
|
+
drag(e, {
|
|
1246
|
+
onStart(item2) {
|
|
1247
|
+
target.setAttribute("data-source-drag", "");
|
|
1248
|
+
item2.classList.add("drag");
|
|
1249
|
+
document.body.classList.add("mousedrag");
|
|
1250
|
+
dragMode.value = true;
|
|
1251
|
+
},
|
|
1252
|
+
onEnd(e2) {
|
|
1253
|
+
var _a;
|
|
1254
|
+
document.body.classList.remove("mousedrag");
|
|
1255
|
+
target.removeAttribute("data-source-drag");
|
|
1256
|
+
if (e2.target !== target) {
|
|
1257
|
+
(_a = e2.target) == null ? void 0 : _a.dispatchEvent(new BlockDropEvent(item.block, item.content));
|
|
1258
|
+
}
|
|
1259
|
+
dragMode.value = false;
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
};
|
|
1263
|
+
const containerRef = ref();
|
|
1264
|
+
const places = shallowReactive([]);
|
|
1265
|
+
watch(dragMode, (dragMode2) => {
|
|
1266
|
+
if (!dragMode2 || !containerRef.value) {
|
|
1267
|
+
places.length = 0;
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
const containerRect = containerRef.value.getBoundingClientRect();
|
|
1271
|
+
places.length = 0;
|
|
1272
|
+
const children = Array.from(containerRef.value.children).filter((child) => child.classList.contains("page-editor-hierarchy__item"));
|
|
1273
|
+
let lastRectHeight = 0;
|
|
1274
|
+
let lastRectBottom = containerRect.top;
|
|
1275
|
+
for (let i = 0; i < children.length + 1; i++) {
|
|
1276
|
+
const child = children[i];
|
|
1277
|
+
const rect = i === children.length ? { top: lastRectBottom, height: containerRect.bottom - lastRectBottom, bottom: 0 } : child.getBoundingClientRect();
|
|
1278
|
+
let top = lastRectHeight * 0.2;
|
|
1279
|
+
let bottom = rect.height * 0.2;
|
|
1280
|
+
if (i > 0 && !flatBlocks.value[i - 1].hasSlots) {
|
|
1281
|
+
top = lastRectHeight * 0.5;
|
|
1282
|
+
}
|
|
1283
|
+
if (i === children.length) {
|
|
1284
|
+
bottom = rect.height;
|
|
1285
|
+
} else if (!flatBlocks.value[i].hasSlots) {
|
|
1286
|
+
bottom = rect.height * 0.5;
|
|
1287
|
+
}
|
|
1288
|
+
places.push({
|
|
1289
|
+
index: i,
|
|
1290
|
+
style: {
|
|
1291
|
+
top: rect.top - containerRect.top + containerRef.value.scrollTop - top + "px",
|
|
1292
|
+
paddingTop: top - 1 + "px",
|
|
1293
|
+
height: top + bottom + "px"
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
lastRectHeight = rect.height;
|
|
1297
|
+
lastRectBottom = rect.bottom;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
const onItemBlockDrop = (e, item) => {
|
|
1301
|
+
if (e.content) {
|
|
1302
|
+
deleteBlock(props.contentBlocks, e.content);
|
|
1303
|
+
}
|
|
1304
|
+
if (item.hasSlots) {
|
|
1305
|
+
const contentBlock = e.content ?? { id: uid(), blockId: e.block.id, data: {} };
|
|
1306
|
+
createContentBlockChild(props.blocksMap, contentBlock, item.content, -1);
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
const onPlaceBlockDrop = (e, _index, dublicate = false) => {
|
|
1310
|
+
e.stopPropagation();
|
|
1311
|
+
let index = _index;
|
|
1312
|
+
let content = e.content;
|
|
1313
|
+
if (content && !dublicate) {
|
|
1314
|
+
const sourceIndex = flatBlocks.value.findIndex((item) => item.content === content);
|
|
1315
|
+
if (sourceIndex === index || sourceIndex === index - 1) return;
|
|
1316
|
+
if (index > sourceIndex && sourceIndex !== -1) index--;
|
|
1317
|
+
deleteBlock(props.contentBlocks, content);
|
|
1318
|
+
}
|
|
1319
|
+
if (content && dublicate) {
|
|
1320
|
+
content = cloneDeep(content);
|
|
1321
|
+
content.id = uid();
|
|
1322
|
+
content.data["data-block-id"] = content.id;
|
|
1323
|
+
forEachChildren(e.block, content, (contents) => {
|
|
1324
|
+
for (let content2 of contents) {
|
|
1325
|
+
content2.id = uid();
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
const contentBlock = content ?? createContentBlock(e.block);
|
|
1330
|
+
if (index >= flatBlocks.value.length) {
|
|
1331
|
+
props.contentBlocks.push(contentBlock);
|
|
1332
|
+
} else {
|
|
1333
|
+
const blockEntry = flatBlocks.value[index];
|
|
1334
|
+
if (blockEntry.parent === null) {
|
|
1335
|
+
const index2 = props.contentBlocks.indexOf(blockEntry.content);
|
|
1336
|
+
props.contentBlocks.splice(index2, 0, contentBlock);
|
|
1337
|
+
} else {
|
|
1338
|
+
const index2 = getBlockIndex(blockEntry.parent, blockEntry.content);
|
|
1339
|
+
createContentBlockChild(props.blocksMap, contentBlock, blockEntry.parent, index2);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
const contextMenu = useContextMenu((content) => [
|
|
1344
|
+
content !== null && { title: "Дублировать блок", onClick() {
|
|
1345
|
+
const index = flatBlocks.value.findIndex((item) => item.content === content);
|
|
1346
|
+
const block = props.blocksMap.get(content.blockId);
|
|
1347
|
+
onPlaceBlockDrop(new BlockDropEvent(block, content), index, true);
|
|
1348
|
+
} },
|
|
1349
|
+
content !== null && { title: "Копировать блок", async onClick() {
|
|
1350
|
+
const blob = new Blob([JSON.stringify(content)], { type: "text/plain" });
|
|
1351
|
+
await navigator.clipboard.write([
|
|
1352
|
+
new ClipboardItem({ "text/plain": blob })
|
|
1353
|
+
]);
|
|
1354
|
+
} },
|
|
1355
|
+
{
|
|
1356
|
+
title: "Вставить блок",
|
|
1357
|
+
onClick: () => placeBlockFromClipboard(content)
|
|
1358
|
+
},
|
|
1359
|
+
content !== null && {
|
|
1360
|
+
title: "Удалить блок",
|
|
1361
|
+
onClick: () => deleteBlock(props.contentBlocks, content)
|
|
1362
|
+
}
|
|
1363
|
+
]);
|
|
1364
|
+
const placeBlockFromClipboard = async (content) => {
|
|
1365
|
+
const resp = await navigator.clipboard.read();
|
|
1366
|
+
if (!resp[0].types.includes("text/plain")) return;
|
|
1367
|
+
const entry = await resp[0].getType("text/plain");
|
|
1368
|
+
const text = await entry.text();
|
|
1369
|
+
if (!text.startsWith("{")) return;
|
|
1370
|
+
try {
|
|
1371
|
+
const contentData = JSON.parse(text);
|
|
1372
|
+
contentData.id = uid();
|
|
1373
|
+
const block = props.blocksMap.get(contentData.blockId);
|
|
1374
|
+
if (!block) return;
|
|
1375
|
+
if (content !== null) {
|
|
1376
|
+
const index = flatBlocks.value.findIndex((item) => item.content === content);
|
|
1377
|
+
if (flatBlocks.value[index].hasSlots) {
|
|
1378
|
+
onItemBlockDrop(new BlockDropEvent(block, contentData), flatBlocks.value[index]);
|
|
1379
|
+
} else {
|
|
1380
|
+
onPlaceBlockDrop(new BlockDropEvent(block, contentData), index);
|
|
1381
|
+
}
|
|
1382
|
+
} else {
|
|
1383
|
+
onPlaceBlockDrop(new BlockDropEvent(block, contentData), flatBlocks.value.length);
|
|
1384
|
+
}
|
|
1385
|
+
} catch (e) {
|
|
1386
|
+
console.warn(e);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
return (_ctx, _cache) => {
|
|
1390
|
+
return openBlock(), createElementBlock("div", {
|
|
1391
|
+
ref_key: "containerRef",
|
|
1392
|
+
ref: containerRef,
|
|
1393
|
+
class: "page-editor-hierarchy",
|
|
1394
|
+
onClick: _cache[1] || (_cache[1] = withModifiers(($event) => emit("update:activeBlockId", null), ["self"]))
|
|
1395
|
+
}, [
|
|
1396
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(flatBlocks.value, (item) => {
|
|
1397
|
+
return openBlock(), createElementBlock("div", {
|
|
1398
|
+
class: normalizeClass(["page-editor-hierarchy__item", { active: props.activeBlockId === item.content.id, hover: props.hoverBlockId === item.content.id }]),
|
|
1399
|
+
style: normalizeStyle({ paddingLeft: `${16 + item.intent * 16}px` }),
|
|
1400
|
+
onBlockdrop: ($event) => onItemBlockDrop($event, item),
|
|
1401
|
+
onMousedown: ($event) => onItemMouseDown($event, item),
|
|
1402
|
+
onMouseenter: ($event) => emit("update:hoverBlockId", item.content.id),
|
|
1403
|
+
onMouseleave: _cache[0] || (_cache[0] = ($event) => emit("update:hoverBlockId", null)),
|
|
1404
|
+
onClick: ($event) => emit("update:activeBlockId", item.content.id),
|
|
1405
|
+
onContextmenu: withModifiers(($event) => unref(contextMenu).open($event, item.content), ["stop"])
|
|
1406
|
+
}, toDisplayString(item.block.name), 47, _hoisted_1$f);
|
|
1407
|
+
}), 256)),
|
|
1408
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(places), (item) => {
|
|
1409
|
+
return openBlock(), createElementBlock("div", {
|
|
1410
|
+
class: "page-editor-hierarhy__place",
|
|
1411
|
+
style: normalizeStyle(item.style),
|
|
1412
|
+
onBlockdrop: ($event) => onPlaceBlockDrop($event, item.index)
|
|
1413
|
+
}, null, 44, _hoisted_2$4);
|
|
1414
|
+
}), 256)),
|
|
1415
|
+
createVNode(_sfc_main$j, normalizeProps(guardReactiveProps(unref(contextMenu).props)), null, 16)
|
|
1416
|
+
], 512);
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
const _sfc_main$h = /* @__PURE__ */ defineComponent({
|
|
1421
|
+
__name: "HoverFrame",
|
|
1422
|
+
props: {
|
|
1423
|
+
element: {},
|
|
1424
|
+
resizable: { type: Boolean }
|
|
1425
|
+
},
|
|
1426
|
+
setup(__props) {
|
|
1427
|
+
const props = __props;
|
|
1428
|
+
const style = ref({ display: "none" });
|
|
1429
|
+
const updateStyle = () => {
|
|
1430
|
+
if (props.element) {
|
|
1431
|
+
const rect = props.element.getBoundingClientRect();
|
|
1432
|
+
style.value = {
|
|
1433
|
+
top: rect.top + document.documentElement.scrollTop + "px",
|
|
1434
|
+
left: rect.left + document.documentElement.scrollLeft + "px",
|
|
1435
|
+
width: rect.width + "px",
|
|
1436
|
+
height: rect.height + "px"
|
|
1437
|
+
};
|
|
1438
|
+
} else {
|
|
1439
|
+
style.value = { display: "none" };
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
const resizeObserver = new ResizeObserver(updateStyle);
|
|
1443
|
+
watch(() => props.element, (element, lastElement) => {
|
|
1444
|
+
updateStyle();
|
|
1445
|
+
if (element) {
|
|
1446
|
+
resizeObserver.observe(element);
|
|
1447
|
+
} else if (lastElement) {
|
|
1448
|
+
resizeObserver.unobserve(lastElement);
|
|
1449
|
+
}
|
|
1450
|
+
}, { immediate: true });
|
|
1451
|
+
return (_ctx, _cache) => {
|
|
1452
|
+
return openBlock(), createElementBlock("div", {
|
|
1453
|
+
class: "editor-component editor-hover-frame",
|
|
1454
|
+
style: normalizeStyle(style.value)
|
|
1455
|
+
}, null, 4);
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
const _hoisted_1$e = ["onClick"];
|
|
1460
|
+
const _sfc_main$g = /* @__PURE__ */ defineComponent({
|
|
1461
|
+
__name: "VTabs",
|
|
1462
|
+
props: {
|
|
1463
|
+
items: {},
|
|
1464
|
+
modelValue: {}
|
|
1465
|
+
},
|
|
1466
|
+
emits: ["update:modelValue"],
|
|
1467
|
+
setup(__props, { emit: __emit }) {
|
|
1468
|
+
const props = __props;
|
|
1469
|
+
const emit = __emit;
|
|
1470
|
+
const model = useVModel(props, "modelValue", emit, { passive: true });
|
|
1471
|
+
watch(() => props.items, (items) => {
|
|
1472
|
+
if ((model.value === void 0 || model.value === null) && items.length > 0) {
|
|
1473
|
+
model.value = items[0].id;
|
|
1474
|
+
}
|
|
1475
|
+
}, { immediate: true });
|
|
1476
|
+
const tabsRef = ref();
|
|
1477
|
+
const markerStyle = ref({});
|
|
1478
|
+
const placeMarker = () => {
|
|
1479
|
+
const id = model.value;
|
|
1480
|
+
if (!tabsRef.value) return;
|
|
1481
|
+
const index = props.items.findIndex((item) => item.id === id);
|
|
1482
|
+
if (index < 0) {
|
|
1483
|
+
markerStyle.value = { width: "0px" };
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1486
|
+
const child = tabsRef.value.children[index];
|
|
1487
|
+
const p = 8;
|
|
1488
|
+
markerStyle.value = { left: child.offsetLeft + p + "px", width: child.clientWidth - p * 2 + "px" };
|
|
1489
|
+
for (let child2 of tabsRef.value.children) {
|
|
1490
|
+
const item = child2;
|
|
1491
|
+
item.style.left = item.offsetLeft + "px";
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
onMounted(() => {
|
|
1495
|
+
placeMarker();
|
|
1496
|
+
});
|
|
1497
|
+
watch(() => props.items, () => {
|
|
1498
|
+
placeMarker();
|
|
1499
|
+
}, { deep: true, flush: "post" });
|
|
1500
|
+
watch(model, placeMarker, { flush: "post" });
|
|
1501
|
+
return (_ctx, _cache) => {
|
|
1502
|
+
return openBlock(), createElementBlock("div", {
|
|
1503
|
+
ref_key: "tabsRef",
|
|
1504
|
+
ref: tabsRef,
|
|
1505
|
+
class: "v-tabs"
|
|
1506
|
+
}, [
|
|
1507
|
+
createVNode(TransitionGroup, null, {
|
|
1508
|
+
default: withCtx(() => [
|
|
1509
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(props.items, (item) => {
|
|
1510
|
+
return openBlock(), createElementBlock("button", {
|
|
1511
|
+
key: item.id,
|
|
1512
|
+
class: normalizeClass(["v-tabs__tab", { active: unref(model) === item.id }]),
|
|
1513
|
+
onClick: ($event) => model.value = item.id
|
|
1514
|
+
}, toDisplayString(item.title), 11, _hoisted_1$e);
|
|
1515
|
+
}), 128))
|
|
1516
|
+
]),
|
|
1517
|
+
_: 1
|
|
1518
|
+
}),
|
|
1519
|
+
createElementVNode("div", {
|
|
1520
|
+
class: "v-tabs__marker",
|
|
1521
|
+
style: normalizeStyle(markerStyle.value)
|
|
1522
|
+
}, null, 4)
|
|
1523
|
+
], 512);
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
const _hoisted_1$d = { class: "v-tabs-pages" };
|
|
1528
|
+
const _sfc_main$f = /* @__PURE__ */ defineComponent({
|
|
1529
|
+
__name: "VTabsPages",
|
|
1530
|
+
props: {
|
|
1531
|
+
page: {},
|
|
1532
|
+
"page:class": {}
|
|
1533
|
+
},
|
|
1534
|
+
setup(__props) {
|
|
1535
|
+
const props = __props;
|
|
1536
|
+
const slots = useSlots();
|
|
1537
|
+
const transitionClass = ref("slide-right");
|
|
1538
|
+
watch(() => props.page, (value, lastValue) => {
|
|
1539
|
+
const keys = Object.keys(slots);
|
|
1540
|
+
if (keys.indexOf(value) > keys.indexOf(lastValue)) {
|
|
1541
|
+
transitionClass.value = "slide-left";
|
|
1542
|
+
} else {
|
|
1543
|
+
transitionClass.value = "slide-right";
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
return (_ctx, _cache) => {
|
|
1547
|
+
return openBlock(), createElementBlock("div", _hoisted_1$d, [
|
|
1548
|
+
createVNode(Transition, { name: transitionClass.value }, {
|
|
1549
|
+
default: withCtx(() => [
|
|
1550
|
+
(openBlock(), createElementBlock("div", {
|
|
1551
|
+
key: props.page,
|
|
1552
|
+
class: normalizeClass(["v-tabs-pages__page", props["page:class"]])
|
|
1553
|
+
}, [
|
|
1554
|
+
renderSlot(_ctx.$slots, props.page)
|
|
1555
|
+
], 2))
|
|
1556
|
+
]),
|
|
1557
|
+
_: 3
|
|
1558
|
+
}, 8, ["name"])
|
|
1559
|
+
]);
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
const _hoisted_1$c = {
|
|
1564
|
+
key: 0,
|
|
1565
|
+
class: "v-form-control__label"
|
|
1566
|
+
};
|
|
1567
|
+
const _hoisted_2$3 = {
|
|
1568
|
+
key: 0,
|
|
1569
|
+
class: "v-form-control__required-marker"
|
|
1570
|
+
};
|
|
1571
|
+
const _hoisted_3$3 = {
|
|
1572
|
+
key: 1,
|
|
1573
|
+
class: "v-form-control__outline"
|
|
1574
|
+
};
|
|
1575
|
+
const _hoisted_4$3 = {
|
|
1576
|
+
key: 3,
|
|
1577
|
+
class: "v-form-control__actions"
|
|
1578
|
+
};
|
|
1579
|
+
const _hoisted_5$1 = {
|
|
1580
|
+
key: 0,
|
|
1581
|
+
class: "v-form-control__error"
|
|
1582
|
+
};
|
|
1583
|
+
const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
1584
|
+
__name: "VFormControl",
|
|
1585
|
+
props: {
|
|
1586
|
+
error: {},
|
|
1587
|
+
label: {},
|
|
1588
|
+
required: { type: Boolean },
|
|
1589
|
+
disabled: { type: Boolean },
|
|
1590
|
+
outline: { type: Boolean }
|
|
1591
|
+
},
|
|
1592
|
+
setup(__props) {
|
|
1593
|
+
const props = __props;
|
|
1594
|
+
const error = computed(() => {
|
|
1595
|
+
if (!props.error) return "";
|
|
1596
|
+
const code = props.error["code"];
|
|
1597
|
+
if (code) {
|
|
1598
|
+
return props.error.message ?? "";
|
|
1599
|
+
}
|
|
1600
|
+
return props.error.message ?? "Произошла ошибка";
|
|
1601
|
+
});
|
|
1602
|
+
return (_ctx, _cache) => {
|
|
1603
|
+
return openBlock(), createElementBlock("div", {
|
|
1604
|
+
class: normalizeClass(["v-form-control", { error: !!props.error, disabled: props.disabled }])
|
|
1605
|
+
}, [
|
|
1606
|
+
!!props.label ? (openBlock(), createElementBlock("label", _hoisted_1$c, [
|
|
1607
|
+
createTextVNode(toDisplayString(props.label), 1),
|
|
1608
|
+
props.required ? (openBlock(), createElementBlock("span", _hoisted_2$3, "*")) : createCommentVNode("", true)
|
|
1609
|
+
])) : createCommentVNode("", true),
|
|
1610
|
+
props.outline ? (openBlock(), createElementBlock("div", _hoisted_3$3, [
|
|
1611
|
+
renderSlot(_ctx.$slots, "default")
|
|
1612
|
+
])) : renderSlot(_ctx.$slots, "default", { key: 2 }),
|
|
1613
|
+
_ctx.$slots.actions ? (openBlock(), createElementBlock("div", _hoisted_4$3, [
|
|
1614
|
+
renderSlot(_ctx.$slots, "actions")
|
|
1615
|
+
])) : createCommentVNode("", true),
|
|
1616
|
+
createVNode(Transition, null, {
|
|
1617
|
+
default: withCtx(() => [
|
|
1618
|
+
!!props.error ? (openBlock(), createElementBlock("div", _hoisted_5$1, toDisplayString(error.value), 1)) : createCommentVNode("", true)
|
|
1619
|
+
]),
|
|
1620
|
+
_: 1
|
|
1621
|
+
})
|
|
1622
|
+
], 2);
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
const _hoisted_1$b = {
|
|
1627
|
+
key: 0,
|
|
1628
|
+
class: "v-input__start-adornment"
|
|
1629
|
+
};
|
|
1630
|
+
const _hoisted_2$2 = ["placeholder", "rows", "name"];
|
|
1631
|
+
const _hoisted_3$2 = ["placeholder", "type", "name"];
|
|
1632
|
+
const _hoisted_4$2 = {
|
|
1633
|
+
key: 3,
|
|
1634
|
+
class: "v-input__max-length"
|
|
1635
|
+
};
|
|
1636
|
+
const _sfc_main$d = /* @__PURE__ */ defineComponent({
|
|
1637
|
+
__name: "VInput",
|
|
1638
|
+
props: {
|
|
1639
|
+
modelValue: {},
|
|
1640
|
+
multiline: { type: Boolean },
|
|
1641
|
+
autofocus: { type: Boolean },
|
|
1642
|
+
rows: {},
|
|
1643
|
+
placeholder: {},
|
|
1644
|
+
type: {},
|
|
1645
|
+
name: {},
|
|
1646
|
+
large: { type: Boolean },
|
|
1647
|
+
maxLength: {},
|
|
1648
|
+
validator: { type: Function },
|
|
1649
|
+
error: {},
|
|
1650
|
+
label: {},
|
|
1651
|
+
required: { type: Boolean },
|
|
1652
|
+
disabled: { type: Boolean }
|
|
1653
|
+
},
|
|
1654
|
+
emits: ["update:modelValue"],
|
|
1655
|
+
setup(__props, { emit: __emit }) {
|
|
1656
|
+
const props = __props;
|
|
1657
|
+
const emit = __emit;
|
|
1658
|
+
const parse = (value) => {
|
|
1659
|
+
if (props.validator) {
|
|
1660
|
+
return props.validator(value);
|
|
1661
|
+
}
|
|
1662
|
+
if (props.type === "number") {
|
|
1663
|
+
const val = parseFloat(value);
|
|
1664
|
+
if (isNaN(val)) return null;
|
|
1665
|
+
return val;
|
|
1666
|
+
}
|
|
1667
|
+
if (props.type === "integer") {
|
|
1668
|
+
const val = parseInt(value);
|
|
1669
|
+
if (isNaN(val)) return null;
|
|
1670
|
+
return val;
|
|
1671
|
+
}
|
|
1672
|
+
return value;
|
|
1673
|
+
};
|
|
1674
|
+
let lastValue = "";
|
|
1675
|
+
const model = ref("");
|
|
1676
|
+
watch(() => props.modelValue, (value) => {
|
|
1677
|
+
if (value === lastValue) return;
|
|
1678
|
+
model.value = (value ?? "").toString();
|
|
1679
|
+
}, { immediate: true });
|
|
1680
|
+
watch(() => model.value, (modelValue) => {
|
|
1681
|
+
const val = parse(modelValue);
|
|
1682
|
+
lastValue = val;
|
|
1683
|
+
emit("update:modelValue", val);
|
|
1684
|
+
});
|
|
1685
|
+
const error = computed(() => {
|
|
1686
|
+
if ((props.type === "number" || props.type === "integer") && model.value && props.modelValue === null) {
|
|
1687
|
+
return { message: "Введите числовое значение" };
|
|
1688
|
+
}
|
|
1689
|
+
return props.error;
|
|
1690
|
+
});
|
|
1691
|
+
const inputType = computed(() => {
|
|
1692
|
+
if (props.type !== "phone" && props.type !== "number" && props.type !== "integer") return props.type;
|
|
1693
|
+
return void 0;
|
|
1694
|
+
});
|
|
1695
|
+
const inputRef = ref();
|
|
1696
|
+
onMounted(() => {
|
|
1697
|
+
var _a;
|
|
1698
|
+
if (props.autofocus || props.error) {
|
|
1699
|
+
(_a = inputRef.value) == null ? void 0 : _a.focus();
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
if (props.multiline) {
|
|
1703
|
+
useTextareaAutosize({ element: inputRef, input: model });
|
|
1704
|
+
}
|
|
1705
|
+
return (_ctx, _cache) => {
|
|
1706
|
+
return openBlock(), createBlock(_sfc_main$e, {
|
|
1707
|
+
class: normalizeClass(["v-input", { large: _ctx.large, multiline: _ctx.multiline }]),
|
|
1708
|
+
error: error.value,
|
|
1709
|
+
label: _ctx.label,
|
|
1710
|
+
required: _ctx.required,
|
|
1711
|
+
disabled: _ctx.disabled,
|
|
1712
|
+
outline: ""
|
|
1713
|
+
}, createSlots({
|
|
1714
|
+
default: withCtx(() => [
|
|
1715
|
+
renderSlot(_ctx.$slots, "start-adornment"),
|
|
1716
|
+
_ctx.type === "phone" ? (openBlock(), createElementBlock("div", _hoisted_1$b, "+7")) : createCommentVNode("", true),
|
|
1717
|
+
props.multiline ? withDirectives((openBlock(), createElementBlock("textarea", {
|
|
1718
|
+
key: 1,
|
|
1719
|
+
ref_key: "inputRef",
|
|
1720
|
+
ref: inputRef,
|
|
1721
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => model.value = $event),
|
|
1722
|
+
placeholder: props.placeholder,
|
|
1723
|
+
rows: props.rows,
|
|
1724
|
+
class: "scroll",
|
|
1725
|
+
name: props.name
|
|
1726
|
+
}, null, 8, _hoisted_2$2)), [
|
|
1727
|
+
[vModelText, model.value]
|
|
1728
|
+
]) : withDirectives((openBlock(), createElementBlock("input", {
|
|
1729
|
+
key: 2,
|
|
1730
|
+
ref_key: "inputRef",
|
|
1731
|
+
ref: inputRef,
|
|
1732
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => model.value = $event),
|
|
1733
|
+
placeholder: props.placeholder,
|
|
1734
|
+
type: inputType.value,
|
|
1735
|
+
name: props.name
|
|
1736
|
+
}, null, 8, _hoisted_3$2)), [
|
|
1737
|
+
[vModelDynamic, model.value]
|
|
1738
|
+
]),
|
|
1739
|
+
props.maxLength ? (openBlock(), createElementBlock("div", _hoisted_4$2, toDisplayString(model.value.length) + " / " + toDisplayString(props.maxLength), 1)) : createCommentVNode("", true),
|
|
1740
|
+
renderSlot(_ctx.$slots, "end-adornment")
|
|
1741
|
+
]),
|
|
1742
|
+
_: 2
|
|
1743
|
+
}, [
|
|
1744
|
+
_ctx.$slots.actions ? {
|
|
1745
|
+
name: "actions",
|
|
1746
|
+
fn: withCtx(() => [
|
|
1747
|
+
renderSlot(_ctx.$slots, "actions")
|
|
1748
|
+
]),
|
|
1749
|
+
key: "0"
|
|
1750
|
+
} : void 0
|
|
1751
|
+
]), 1032, ["error", "label", "required", "disabled", "class"]);
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
const _export_sfc = (sfc, props) => {
|
|
1756
|
+
const target = sfc.__vccOpts || sfc;
|
|
1757
|
+
for (const [key, val] of props) {
|
|
1758
|
+
target[key] = val;
|
|
1759
|
+
}
|
|
1760
|
+
return target;
|
|
1761
|
+
};
|
|
1762
|
+
const _sfc_main$c = {};
|
|
1763
|
+
const _hoisted_1$a = {
|
|
1764
|
+
width: "20",
|
|
1765
|
+
height: "20",
|
|
1766
|
+
viewBox: "0 0 20 20",
|
|
1767
|
+
fill: "none",
|
|
1768
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
1769
|
+
};
|
|
1770
|
+
function _sfc_render$5(_ctx, _cache) {
|
|
1771
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$a, _cache[0] || (_cache[0] = [
|
|
1772
|
+
createElementVNode("path", {
|
|
1773
|
+
"fill-rule": "evenodd",
|
|
1774
|
+
"clip-rule": "evenodd",
|
|
1775
|
+
d: "M7.5001 14.1665C7.50013 14.3313 7.54902 14.4924 7.64059 14.6294C7.73217 14.7664 7.8623 14.8732 8.01455 14.9362C8.1668 14.9993 8.33433 15.0158 8.49596 14.9836C8.65758 14.9515 8.80605 14.8722 8.9226 14.7557L13.0893 10.589C13.2455 10.4327 13.3333 10.2208 13.3333 9.99982C13.3333 9.77885 13.2455 9.56693 13.0893 9.41066L8.9226 5.24399C8.80605 5.12748 8.65758 5.04814 8.49596 5.016C8.33433 4.98386 8.1668 5.00037 8.01455 5.06342C7.8623 5.12648 7.73217 5.23327 7.6406 5.37027C7.54902 5.50728 7.50013 5.66836 7.5001 5.83316L7.5001 14.1665Z",
|
|
1776
|
+
fill: "currentColor"
|
|
1777
|
+
}, null, -1)
|
|
1778
|
+
]));
|
|
1779
|
+
}
|
|
1780
|
+
const CollapseArrowIcon = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$5]]);
|
|
1781
|
+
const _sfc_main$b = /* @__PURE__ */ defineComponent({
|
|
1782
|
+
__name: "VCollapse",
|
|
1783
|
+
props: {
|
|
1784
|
+
open: { type: Boolean },
|
|
1785
|
+
label: {},
|
|
1786
|
+
withPadding: { type: Boolean }
|
|
1787
|
+
},
|
|
1788
|
+
emits: ["update:open"],
|
|
1789
|
+
setup(__props, { emit: __emit }) {
|
|
1790
|
+
const props = __props;
|
|
1791
|
+
const emit = __emit;
|
|
1792
|
+
const height = ref(0);
|
|
1793
|
+
const open = ref(props.open ?? false);
|
|
1794
|
+
const transition = ref(false);
|
|
1795
|
+
const innerRef = ref();
|
|
1796
|
+
let hideTimeout = null;
|
|
1797
|
+
const setOpen = async (value) => {
|
|
1798
|
+
open.value = value;
|
|
1799
|
+
if (hideTimeout !== null) {
|
|
1800
|
+
clearTimeout(hideTimeout);
|
|
1801
|
+
hideTimeout = null;
|
|
1802
|
+
}
|
|
1803
|
+
if (open.value === false && innerRef.value) {
|
|
1804
|
+
height.value = innerRef.value.clientHeight;
|
|
1805
|
+
}
|
|
1806
|
+
transition.value = true;
|
|
1807
|
+
await nextTick();
|
|
1808
|
+
await new Promise((res) => requestAnimationFrame(res));
|
|
1809
|
+
if (open.value) {
|
|
1810
|
+
height.value = innerRef.value.clientHeight;
|
|
1811
|
+
} else {
|
|
1812
|
+
height.value = 0;
|
|
1813
|
+
}
|
|
1814
|
+
hideTimeout = setTimeout(() => {
|
|
1815
|
+
transition.value = false;
|
|
1816
|
+
}, 200);
|
|
1817
|
+
setTimeout(() => mouseMove = true, 0);
|
|
1818
|
+
emit("update:open", open.value);
|
|
1819
|
+
};
|
|
1820
|
+
const onClick = async () => {
|
|
1821
|
+
setOpen(!open.value);
|
|
1822
|
+
};
|
|
1823
|
+
watch(() => props.open, (value) => {
|
|
1824
|
+
if (typeof value !== "boolean" || open.value === value) return;
|
|
1825
|
+
setOpen(value);
|
|
1826
|
+
});
|
|
1827
|
+
let mouseMove = false;
|
|
1828
|
+
useEventListener("mousedown", () => mouseMove = false);
|
|
1829
|
+
const onMouseEnter = (e) => {
|
|
1830
|
+
if (e.buttons > 0 && !mouseMove && !document.body.classList.contains("mousedrag")) {
|
|
1831
|
+
mouseMove = true;
|
|
1832
|
+
onClick();
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
return (_ctx, _cache) => {
|
|
1836
|
+
return openBlock(), createElementBlock("div", {
|
|
1837
|
+
class: normalizeClass(["v-collapse", { open: open.value }])
|
|
1838
|
+
}, [
|
|
1839
|
+
renderSlot(_ctx.$slots, "activator", {
|
|
1840
|
+
props: { onClick, open: open.value }
|
|
1841
|
+
}, () => [
|
|
1842
|
+
createElementVNode("div", {
|
|
1843
|
+
class: normalizeClass(["v-collapse__activator", { open: open.value }]),
|
|
1844
|
+
onMousedown: onClick,
|
|
1845
|
+
onMouseenter: onMouseEnter
|
|
1846
|
+
}, [
|
|
1847
|
+
createVNode(CollapseArrowIcon),
|
|
1848
|
+
createElementVNode("div", null, toDisplayString(props.label), 1)
|
|
1849
|
+
], 34)
|
|
1850
|
+
]),
|
|
1851
|
+
createElementVNode("div", {
|
|
1852
|
+
class: normalizeClass(["v-collapse__content", { "v-transition": transition.value, withPadding: props.withPadding }]),
|
|
1853
|
+
style: normalizeStyle(transition.value ? { height: `${height.value}px` } : void 0)
|
|
1854
|
+
}, [
|
|
1855
|
+
transition.value || open.value ? (openBlock(), createElementBlock("div", {
|
|
1856
|
+
key: 0,
|
|
1857
|
+
ref_key: "innerRef",
|
|
1858
|
+
ref: innerRef,
|
|
1859
|
+
class: "v-collapse__content-inner"
|
|
1860
|
+
}, [
|
|
1861
|
+
renderSlot(_ctx.$slots, "default")
|
|
1862
|
+
], 512)) : createCommentVNode("", true)
|
|
1863
|
+
], 6)
|
|
1864
|
+
], 2);
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
const _sfc_main$a = {};
|
|
1869
|
+
const _hoisted_1$9 = {
|
|
1870
|
+
width: "16",
|
|
1871
|
+
height: "16",
|
|
1872
|
+
viewBox: "0 0 16 16",
|
|
1873
|
+
fill: "none",
|
|
1874
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
1875
|
+
};
|
|
1876
|
+
function _sfc_render$4(_ctx, _cache) {
|
|
1877
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$9, _cache[0] || (_cache[0] = [
|
|
1878
|
+
createElementVNode("path", {
|
|
1879
|
+
d: "M14.364 5.293C14.1764 5.10553 13.9221 5.00021 13.657 5.00021C13.3918 5.00021 13.1375 5.10553 12.95 5.293L7.99995 10.243L3.04995 5.293C2.86135 5.11084 2.60875 5.01005 2.34655 5.01232C2.08435 5.0146 1.83354 5.11977 1.64813 5.30518C1.46272 5.49059 1.35756 5.7414 1.35528 6.0036C1.353 6.26579 1.45379 6.5184 1.63595 6.707L7.29295 12.364C7.48048 12.5515 7.73479 12.6568 7.99995 12.6568C8.26512 12.6568 8.51942 12.5515 8.70695 12.364L14.364 6.707C14.5514 6.51947 14.6567 6.26516 14.6567 6C14.6567 5.73483 14.5514 5.48053 14.364 5.293Z",
|
|
1880
|
+
fill: "currentColor"
|
|
1881
|
+
}, null, -1)
|
|
1882
|
+
]));
|
|
1883
|
+
}
|
|
1884
|
+
const ArrowDownIcon = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$4]]);
|
|
1885
|
+
const _hoisted_1$8 = { key: 0 };
|
|
1886
|
+
const _hoisted_2$1 = {
|
|
1887
|
+
key: 1,
|
|
1888
|
+
class: "v-select__placeholder"
|
|
1889
|
+
};
|
|
1890
|
+
const _hoisted_3$1 = { class: "v-select__menu" };
|
|
1891
|
+
const _hoisted_4$1 = {
|
|
1892
|
+
key: 0,
|
|
1893
|
+
class: "group-title"
|
|
1894
|
+
};
|
|
1895
|
+
const _hoisted_5 = ["onClick"];
|
|
1896
|
+
const _sfc_main$9 = /* @__PURE__ */ defineComponent({
|
|
1897
|
+
__name: "VSelect",
|
|
1898
|
+
props: {
|
|
1899
|
+
items: {},
|
|
1900
|
+
modelValue: {},
|
|
1901
|
+
placeholder: {},
|
|
1902
|
+
nullable: { type: Boolean },
|
|
1903
|
+
error: {},
|
|
1904
|
+
label: {},
|
|
1905
|
+
required: { type: Boolean },
|
|
1906
|
+
disabled: { type: Boolean }
|
|
1907
|
+
},
|
|
1908
|
+
emits: ["update:modelValue"],
|
|
1909
|
+
setup(__props, { emit: __emit }) {
|
|
1910
|
+
const props = __props;
|
|
1911
|
+
const emit = __emit;
|
|
1912
|
+
const model = useVModel(props, "modelValue", emit, { passive: true, defaultValue: null });
|
|
1913
|
+
const currentItem = computed(() => {
|
|
1914
|
+
if (model.value === null) return null;
|
|
1915
|
+
return props.items.find((item) => typeof item !== "string" && item.id === model.value) ?? null;
|
|
1916
|
+
});
|
|
1917
|
+
const items = computed(() => {
|
|
1918
|
+
return props.items;
|
|
1919
|
+
});
|
|
1920
|
+
const opened = ref(false);
|
|
1921
|
+
const onItemClick = (item) => {
|
|
1922
|
+
model.value = item.id;
|
|
1923
|
+
opened.value = false;
|
|
1924
|
+
};
|
|
1925
|
+
const resetValue = () => {
|
|
1926
|
+
model.value = null;
|
|
1927
|
+
opened.value = false;
|
|
1928
|
+
};
|
|
1929
|
+
return (_ctx, _cache) => {
|
|
1930
|
+
return openBlock(), createBlock(_sfc_main$e, {
|
|
1931
|
+
outline: "",
|
|
1932
|
+
class: "v-select",
|
|
1933
|
+
label: props.label,
|
|
1934
|
+
error: props.error,
|
|
1935
|
+
disabled: props.disabled,
|
|
1936
|
+
required: props.required
|
|
1937
|
+
}, {
|
|
1938
|
+
default: withCtx(() => [
|
|
1939
|
+
createVNode(_sfc_main$l, {
|
|
1940
|
+
open: opened.value,
|
|
1941
|
+
"onUpdate:open": _cache[0] || (_cache[0] = ($event) => opened.value = $event),
|
|
1942
|
+
placement: "bottom",
|
|
1943
|
+
"fit-anchor": "",
|
|
1944
|
+
offset: 8
|
|
1945
|
+
}, {
|
|
1946
|
+
activator: withCtx(({ props: activatorProps }) => [
|
|
1947
|
+
createElementVNode("button", mergeProps({
|
|
1948
|
+
class: ["v-select__activator", { opened: opened.value }]
|
|
1949
|
+
}, activatorProps), [
|
|
1950
|
+
currentItem.value ? (openBlock(), createElementBlock("div", _hoisted_1$8, toDisplayString(currentItem.value.title), 1)) : (openBlock(), createElementBlock("div", _hoisted_2$1, toDisplayString(props.placeholder ?? "Выберите значение"), 1)),
|
|
1951
|
+
createVNode(ArrowDownIcon)
|
|
1952
|
+
], 16)
|
|
1953
|
+
]),
|
|
1954
|
+
default: withCtx(() => [
|
|
1955
|
+
createElementVNode("div", _hoisted_3$1, [
|
|
1956
|
+
props.nullable ? (openBlock(), createElementBlock("button", {
|
|
1957
|
+
key: 0,
|
|
1958
|
+
class: "nullable-item",
|
|
1959
|
+
onClick: resetValue
|
|
1960
|
+
}, " Пустое значение ")) : createCommentVNode("", true),
|
|
1961
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(items.value, (item) => {
|
|
1962
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
1963
|
+
typeof item === "string" ? (openBlock(), createElementBlock("div", _hoisted_4$1, toDisplayString(item), 1)) : (openBlock(), createElementBlock("button", {
|
|
1964
|
+
key: 1,
|
|
1965
|
+
onClick: ($event) => onItemClick(item)
|
|
1966
|
+
}, [
|
|
1967
|
+
renderSlot(_ctx.$slots, "item", { item }, () => [
|
|
1968
|
+
createTextVNode(toDisplayString(item.title), 1)
|
|
1969
|
+
])
|
|
1970
|
+
], 8, _hoisted_5))
|
|
1971
|
+
], 64);
|
|
1972
|
+
}), 256))
|
|
1973
|
+
])
|
|
1974
|
+
]),
|
|
1975
|
+
_: 3
|
|
1976
|
+
}, 8, ["open"])
|
|
1977
|
+
]),
|
|
1978
|
+
_: 3
|
|
1979
|
+
}, 8, ["label", "error", "disabled", "required"]);
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
const _hoisted_1$7 = { class: "json-editor__array" };
|
|
1984
|
+
const _sfc_main$8 = /* @__PURE__ */ defineComponent({
|
|
1985
|
+
__name: "JsonEditorArray",
|
|
1986
|
+
props: {
|
|
1987
|
+
label: {},
|
|
1988
|
+
schema: {},
|
|
1989
|
+
modelValue: {},
|
|
1990
|
+
expanded: { type: Boolean }
|
|
1991
|
+
},
|
|
1992
|
+
emits: ["update:modelValue"],
|
|
1993
|
+
setup(__props, { emit: __emit }) {
|
|
1994
|
+
var _a;
|
|
1995
|
+
const props = __props;
|
|
1996
|
+
const emit = __emit;
|
|
1997
|
+
const childExpanded = ((_a = props.schema.items) == null ? void 0 : _a.type) === "object" && Object.keys(props.schema.items.properties).length < 2;
|
|
1998
|
+
const length = ref(0);
|
|
1999
|
+
const tempArray = ref([]);
|
|
2000
|
+
if (props.schema.type === "array" && props.modelValue) {
|
|
2001
|
+
length.value = props.modelValue.length ?? 0;
|
|
2002
|
+
tempArray.value = [...props.modelValue];
|
|
2003
|
+
}
|
|
2004
|
+
watch(tempArray, () => {
|
|
2005
|
+
var _a2;
|
|
2006
|
+
if (((_a2 = props.schema.items) == null ? void 0 : _a2.type) === "object" && props.modelValue[0] === tempArray.value[0]) return;
|
|
2007
|
+
emit("update:modelValue", tempArray.value.slice(0, length.value));
|
|
2008
|
+
}, { deep: true });
|
|
2009
|
+
watch(length, (length2) => {
|
|
2010
|
+
for (let i = tempArray.value.length; i < length2; i++) {
|
|
2011
|
+
tempArray.value[i] = props.schema.items ? getDefaultValue(props.schema.items) : null;
|
|
2012
|
+
}
|
|
2013
|
+
emit("update:modelValue", tempArray.value.slice(0, length2));
|
|
2014
|
+
});
|
|
2015
|
+
const label = computed(() => {
|
|
2016
|
+
return `${props.label} (${length.value})`;
|
|
2017
|
+
});
|
|
2018
|
+
return (_ctx, _cache) => {
|
|
2019
|
+
return openBlock(), createElementBlock("div", _hoisted_1$7, [
|
|
2020
|
+
createVNode(_sfc_main$b, {
|
|
2021
|
+
label: label.value,
|
|
2022
|
+
open: props.expanded
|
|
2023
|
+
}, {
|
|
2024
|
+
default: withCtx(() => [
|
|
2025
|
+
createVNode(_sfc_main$d, {
|
|
2026
|
+
label: "Количество элементов",
|
|
2027
|
+
modelValue: length.value,
|
|
2028
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => length.value = $event),
|
|
2029
|
+
type: "number"
|
|
2030
|
+
}, null, 8, ["modelValue"]),
|
|
2031
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(length.value, (index) => {
|
|
2032
|
+
return openBlock(), createBlock(_sfc_main$4, {
|
|
2033
|
+
key: index,
|
|
2034
|
+
schema: props.schema.items,
|
|
2035
|
+
name: `${props.schema.itemName ?? "Элемент"} ${index}`,
|
|
2036
|
+
modelValue: tempArray.value[index - 1],
|
|
2037
|
+
"onUpdate:modelValue": ($event) => tempArray.value[index - 1] = $event,
|
|
2038
|
+
expanded: unref(childExpanded)
|
|
2039
|
+
}, null, 8, ["schema", "name", "modelValue", "onUpdate:modelValue", "expanded"]);
|
|
2040
|
+
}), 128))
|
|
2041
|
+
]),
|
|
2042
|
+
_: 1
|
|
2043
|
+
}, 8, ["label", "open"])
|
|
2044
|
+
]);
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
const _sfc_main$7 = {};
|
|
2049
|
+
const _hoisted_1$6 = {
|
|
2050
|
+
width: "46",
|
|
2051
|
+
height: "28",
|
|
2052
|
+
viewBox: "0 0 46 28",
|
|
2053
|
+
fill: "none",
|
|
2054
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
2055
|
+
};
|
|
2056
|
+
function _sfc_render$3(_ctx, _cache) {
|
|
2057
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$6, _cache[0] || (_cache[0] = [
|
|
2058
|
+
createStaticVNode('<mask id="mask0_1044_6" style="mask-type:luminance;" maskUnits="userSpaceOnUse" x="0" y="0" width="46" height="28"><path d="M45.5 0H0.5V28H45.5V0Z" fill="white"></path></mask><g mask="url(#mask0_1044_6)"><path d="M23.5 27.8537C35.9264 27.8537 46 25.6664 46 22.9683C46 20.2702 35.9264 18.083 23.5 18.083C11.0736 18.083 1 20.2702 1 22.9683C1 25.6664 11.0736 27.8537 23.5 27.8537Z" fill="#D7D7D7"></path><path d="M39.6719 9.5459L32.538 1.51859C32.1955 0.971432 31.6956 0.640625 31.169 0.640625H15.831C15.3044 0.640625 14.8045 0.971432 14.462 1.51789L7.32812 9.5466V15.9946H39.6719V9.5459Z" stroke="#A0A0A0" stroke-width="0.703125"></path><path d="M30.2591 11.7594C30.2591 10.6393 30.958 9.71457 31.825 9.71387H39.6719V22.3718C39.6719 23.8534 38.7437 25.0678 37.5977 25.0678H9.40234C8.25625 25.0678 7.32812 23.8527 7.32812 22.3718V9.71387H15.175C16.042 9.71387 16.7409 10.6372 16.7409 11.7573V11.7727C16.7409 12.8928 17.4475 13.7973 18.3138 13.7973H28.6862C29.5525 13.7973 30.2591 12.8845 30.2591 11.7643V11.7594Z" fill="#FAFAFA" stroke="#A0A0A0" stroke-width="0.703125"></path></g>', 2)
|
|
2059
|
+
]));
|
|
2060
|
+
}
|
|
2061
|
+
const EmptyFileIcon = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$3]]);
|
|
2062
|
+
const _sfc_main$6 = {};
|
|
2063
|
+
const _hoisted_1$5 = {
|
|
2064
|
+
width: "16",
|
|
2065
|
+
height: "16",
|
|
2066
|
+
viewBox: "0 0 16 16",
|
|
2067
|
+
fill: "none",
|
|
2068
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
2069
|
+
};
|
|
2070
|
+
function _sfc_render$2(_ctx, _cache) {
|
|
2071
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$5, _cache[0] || (_cache[0] = [
|
|
2072
|
+
createElementVNode("path", {
|
|
2073
|
+
d: "M9.31382 7.9L12.8488 4.364C12.9443 4.27176 13.0205 4.16141 13.0729 4.03941C13.1253 3.9174 13.1529 3.78618 13.1541 3.6534C13.1552 3.52062 13.1299 3.38894 13.0796 3.26605C13.0294 3.14315 12.9551 3.0315 12.8612 2.93761C12.7673 2.84371 12.6557 2.76946 12.5328 2.71918C12.4099 2.6689 12.2782 2.6436 12.1454 2.64475C12.0126 2.64591 11.8814 2.67349 11.7594 2.7259C11.6374 2.77831 11.5271 2.85449 11.4348 2.95L7.89882 6.485L4.36382 2.95C4.27157 2.85449 4.16123 2.77831 4.03922 2.7259C3.91722 2.67349 3.786 2.64591 3.65322 2.64475C3.52044 2.6436 3.38876 2.6689 3.26587 2.71918C3.14297 2.76946 3.03132 2.84371 2.93742 2.93761C2.84353 3.0315 2.76928 3.14315 2.719 3.26605C2.66872 3.38894 2.64342 3.52062 2.64457 3.6534C2.64572 3.78618 2.67331 3.9174 2.72572 4.03941C2.77813 4.16141 2.85431 4.27176 2.94982 4.364L6.48482 7.899L2.94982 11.435C2.85431 11.5273 2.77813 11.6376 2.72572 11.7596C2.67331 11.8816 2.64572 12.0128 2.64457 12.1456C2.64342 12.2784 2.66872 12.4101 2.719 12.533C2.76928 12.6559 2.84353 12.7675 2.93742 12.8614C3.03132 12.9553 3.14297 13.0295 3.26587 13.0798C3.38876 13.1301 3.52044 13.1554 3.65322 13.1543C3.786 13.1531 3.91722 13.1255 4.03922 13.0731C4.16123 13.0207 4.27157 12.9445 4.36382 12.849L7.89882 9.314L11.4348 12.849C11.5271 12.9445 11.6374 13.0207 11.7594 13.0731C11.8814 13.1255 12.0126 13.1531 12.1454 13.1543C12.2782 13.1554 12.4099 13.1301 12.5328 13.0798C12.6557 13.0295 12.7673 12.9553 12.8612 12.8614C12.9551 12.7675 13.0294 12.6559 13.0796 12.533C13.1299 12.4101 13.1552 12.2784 13.1541 12.1456C13.1529 12.0128 13.1253 11.8816 13.0729 11.7596C13.0205 11.6376 12.9443 11.5273 12.8488 11.435L9.31382 7.9Z",
|
|
2074
|
+
fill: "currentColor"
|
|
2075
|
+
}, null, -1)
|
|
2076
|
+
]));
|
|
2077
|
+
}
|
|
2078
|
+
const CloseMinIcon = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$2]]);
|
|
2079
|
+
const _hoisted_1$4 = {
|
|
2080
|
+
key: 0,
|
|
2081
|
+
class: "v-image-uploader__drag-label"
|
|
2082
|
+
};
|
|
2083
|
+
const _hoisted_2 = { class: "v-image-uploader__image-preview" };
|
|
2084
|
+
const _hoisted_3 = ["src"];
|
|
2085
|
+
const _hoisted_4 = { class: "v-image-uploader__image-info" };
|
|
2086
|
+
const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
2087
|
+
__name: "VImageUploader",
|
|
2088
|
+
props: {
|
|
2089
|
+
accept: {},
|
|
2090
|
+
schema: {},
|
|
2091
|
+
modelValue: {},
|
|
2092
|
+
error: {},
|
|
2093
|
+
label: {},
|
|
2094
|
+
required: { type: Boolean },
|
|
2095
|
+
disabled: { type: Boolean }
|
|
2096
|
+
},
|
|
2097
|
+
emits: ["update:modelValue"],
|
|
2098
|
+
setup(__props, { emit: __emit }) {
|
|
2099
|
+
const props = __props;
|
|
2100
|
+
const emit = __emit;
|
|
2101
|
+
const fileUploader = inject("fileUploader");
|
|
2102
|
+
const addFile = async (file) => {
|
|
2103
|
+
emit("update:modelValue", { src: URL.createObjectURL(file), file, name: file.name });
|
|
2104
|
+
if (fileUploader) {
|
|
2105
|
+
const resp = await fileUploader(file);
|
|
2106
|
+
emit("update:modelValue", { src: resp.src, previewSrc: resp.previewSrc, name: resp.name });
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
const drag = ref(false);
|
|
2110
|
+
const onDragOver = (e) => {
|
|
2111
|
+
var _a, _b, _c;
|
|
2112
|
+
if ((_c = (_b = (_a = e.dataTransfer) == null ? void 0 : _a.types) == null ? void 0 : _b[0]) == null ? void 0 : _c.startsWith("text")) return;
|
|
2113
|
+
e.preventDefault();
|
|
2114
|
+
drag.value = true;
|
|
2115
|
+
};
|
|
2116
|
+
const onDragLeave = (e) => {
|
|
2117
|
+
var _a;
|
|
2118
|
+
if (e.relatedTarget === e.currentTarget || ((_a = e.relatedTarget) == null ? void 0 : _a.parentElement) === e.currentTarget) return;
|
|
2119
|
+
drag.value = false;
|
|
2120
|
+
};
|
|
2121
|
+
const onDrop = (e) => {
|
|
2122
|
+
e.preventDefault();
|
|
2123
|
+
drag.value = false;
|
|
2124
|
+
for (const item of e.dataTransfer.items) {
|
|
2125
|
+
if (item.kind !== "file") continue;
|
|
2126
|
+
const file = item.getAsFile();
|
|
2127
|
+
if (!file) continue;
|
|
2128
|
+
addFile(file);
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
const fileDialog = useFileDialog({
|
|
2132
|
+
accept: props.accept ?? "image/*",
|
|
2133
|
+
multiple: false
|
|
2134
|
+
});
|
|
2135
|
+
fileDialog.onChange((files) => {
|
|
2136
|
+
if (!files || files.length === 0) return;
|
|
2137
|
+
for (const file of files) {
|
|
2138
|
+
addFile(file);
|
|
2139
|
+
}
|
|
2140
|
+
fileDialog.reset();
|
|
2141
|
+
});
|
|
2142
|
+
const removeImage = () => {
|
|
2143
|
+
emit("update:modelValue", getDefaultValue(props.schema));
|
|
2144
|
+
};
|
|
2145
|
+
return (_ctx, _cache) => {
|
|
2146
|
+
return openBlock(), createBlock(_sfc_main$e, {
|
|
2147
|
+
class: normalizeClass(["v-image-uploader", { drag: drag.value }]),
|
|
2148
|
+
error: _ctx.error,
|
|
2149
|
+
label: _ctx.label,
|
|
2150
|
+
required: _ctx.required,
|
|
2151
|
+
disabled: _ctx.disabled,
|
|
2152
|
+
outline: "",
|
|
2153
|
+
onDrop,
|
|
2154
|
+
onDragover: onDragOver,
|
|
2155
|
+
onDragleave: onDragLeave
|
|
2156
|
+
}, {
|
|
2157
|
+
default: withCtx(() => [
|
|
2158
|
+
drag.value ? (openBlock(), createElementBlock("div", _hoisted_1$4, "Отпустите файл здесь")) : !props.modelValue || props.modelValue.src === unref(defaultImageSrc) ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2159
|
+
createVNode(EmptyFileIcon),
|
|
2160
|
+
createElementVNode("div", null, [
|
|
2161
|
+
createElementVNode("a", {
|
|
2162
|
+
onClick: _cache[0] || (_cache[0] = ($event) => unref(fileDialog).open())
|
|
2163
|
+
}, "Загрузите изображение"),
|
|
2164
|
+
_cache[1] || (_cache[1] = createElementVNode("br", null, null, -1)),
|
|
2165
|
+
_cache[2] || (_cache[2] = createTextVNode("или перетащите сюда "))
|
|
2166
|
+
])
|
|
2167
|
+
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
2168
|
+
createElementVNode("div", _hoisted_2, [
|
|
2169
|
+
createElementVNode("img", {
|
|
2170
|
+
src: props.modelValue.previewSrc ?? props.modelValue.src,
|
|
2171
|
+
alt: "Preview Image"
|
|
2172
|
+
}, null, 8, _hoisted_3),
|
|
2173
|
+
createElementVNode("button", { onClick: removeImage }, [
|
|
2174
|
+
createVNode(CloseMinIcon)
|
|
2175
|
+
])
|
|
2176
|
+
]),
|
|
2177
|
+
createElementVNode("div", _hoisted_4, [
|
|
2178
|
+
createElementVNode("div", null, toDisplayString(props.modelValue.name), 1)
|
|
2179
|
+
])
|
|
2180
|
+
], 64))
|
|
2181
|
+
]),
|
|
2182
|
+
_: 1
|
|
2183
|
+
}, 8, ["class", "error", "label", "required", "disabled"]);
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
const getBlockName = (path) => {
|
|
2188
|
+
if (!path) return void 0;
|
|
2189
|
+
const str = path.split("/").at(-1);
|
|
2190
|
+
return (str == null ? void 0 : str.split(".", 1)[0].replace(/([A-Z])/g, " $1").trimStart()) ?? "Unnamed block";
|
|
2191
|
+
};
|
|
2192
|
+
const capitalize = (text) => {
|
|
2193
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
2194
|
+
};
|
|
2195
|
+
const spaceCamelCase = (str) => {
|
|
2196
|
+
return capitalize(str.replace(/([A-Z])/g, " $1").trimStart());
|
|
2197
|
+
};
|
|
2198
|
+
const _hoisted_1$3 = {
|
|
2199
|
+
key: 1,
|
|
2200
|
+
class: "json-editor__object"
|
|
2201
|
+
};
|
|
2202
|
+
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
2203
|
+
__name: "JsonEditor",
|
|
2204
|
+
props: /* @__PURE__ */ mergeModels({
|
|
2205
|
+
schema: {},
|
|
2206
|
+
name: {},
|
|
2207
|
+
flat: { type: Boolean },
|
|
2208
|
+
expanded: { type: Boolean }
|
|
2209
|
+
}, {
|
|
2210
|
+
"modelValue": {},
|
|
2211
|
+
"modelModifiers": {}
|
|
2212
|
+
}),
|
|
2213
|
+
emits: ["update:modelValue"],
|
|
2214
|
+
setup(__props) {
|
|
2215
|
+
const props = __props;
|
|
2216
|
+
const childExpanded = props.schema.type === "object" && Object.keys(props.schema.properties).length < 2;
|
|
2217
|
+
const vModel = useModel(__props, "modelValue");
|
|
2218
|
+
const getItems = (schema) => {
|
|
2219
|
+
return schema.enum.map((item, index) => {
|
|
2220
|
+
var _a;
|
|
2221
|
+
return {
|
|
2222
|
+
id: item,
|
|
2223
|
+
title: ((_a = schema.enumAlias) == null ? void 0 : _a[index]) ?? spaceCamelCase(item)
|
|
2224
|
+
};
|
|
2225
|
+
});
|
|
2226
|
+
};
|
|
2227
|
+
return (_ctx, _cache) => {
|
|
2228
|
+
const _component_JsonEditor = resolveComponent("JsonEditor", true);
|
|
2229
|
+
return props.schema.type === "object" && props.schema.format === "image" ? (openBlock(), createBlock(_sfc_main$5, {
|
|
2230
|
+
key: 0,
|
|
2231
|
+
modelValue: vModel.value,
|
|
2232
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => vModel.value = $event),
|
|
2233
|
+
label: props.schema.name ?? props.name,
|
|
2234
|
+
schema: props.schema
|
|
2235
|
+
}, null, 8, ["modelValue", "label", "schema"])) : props.schema.type === "object" ? (openBlock(), createElementBlock("div", _hoisted_1$3, [
|
|
2236
|
+
props.flat ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(props.schema.properties, (item, key) => {
|
|
2237
|
+
return openBlock(), createBlock(_component_JsonEditor, {
|
|
2238
|
+
modelValue: vModel.value[key],
|
|
2239
|
+
"onUpdate:modelValue": ($event) => vModel.value[key] = $event,
|
|
2240
|
+
key,
|
|
2241
|
+
schema: item,
|
|
2242
|
+
expanded: unref(childExpanded),
|
|
2243
|
+
name: unref(spaceCamelCase)(key)
|
|
2244
|
+
}, null, 8, ["modelValue", "onUpdate:modelValue", "schema", "expanded", "name"]);
|
|
2245
|
+
}), 128)) : (openBlock(), createBlock(_sfc_main$b, {
|
|
2246
|
+
key: 1,
|
|
2247
|
+
label: props.schema.name ?? props.name,
|
|
2248
|
+
open: props.expanded
|
|
2249
|
+
}, {
|
|
2250
|
+
default: withCtx(() => [
|
|
2251
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(props.schema.properties, (item, key) => {
|
|
2252
|
+
return openBlock(), createBlock(_component_JsonEditor, {
|
|
2253
|
+
modelValue: vModel.value[key],
|
|
2254
|
+
"onUpdate:modelValue": ($event) => vModel.value[key] = $event,
|
|
2255
|
+
key,
|
|
2256
|
+
schema: item,
|
|
2257
|
+
expanded: unref(childExpanded),
|
|
2258
|
+
name: unref(spaceCamelCase)(key)
|
|
2259
|
+
}, null, 8, ["modelValue", "onUpdate:modelValue", "schema", "expanded", "name"]);
|
|
2260
|
+
}), 128))
|
|
2261
|
+
]),
|
|
2262
|
+
_: 1
|
|
2263
|
+
}, 8, ["label", "open"]))
|
|
2264
|
+
])) : props.schema.type === "array" ? (openBlock(), createBlock(_sfc_main$8, {
|
|
2265
|
+
key: 2,
|
|
2266
|
+
modelValue: vModel.value,
|
|
2267
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => vModel.value = $event),
|
|
2268
|
+
schema: props.schema,
|
|
2269
|
+
label: props.schema.name ?? props.name,
|
|
2270
|
+
expanded: props.expanded
|
|
2271
|
+
}, null, 8, ["modelValue", "schema", "label", "expanded"])) : props.schema.type === "string" && props.schema.enum ? (openBlock(), createBlock(_sfc_main$9, {
|
|
2272
|
+
key: 3,
|
|
2273
|
+
items: getItems(props.schema),
|
|
2274
|
+
modelValue: vModel.value,
|
|
2275
|
+
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => vModel.value = $event),
|
|
2276
|
+
label: props.schema.name ?? props.name
|
|
2277
|
+
}, null, 8, ["items", "modelValue", "label"])) : (openBlock(), createBlock(_sfc_main$d, {
|
|
2278
|
+
key: 4,
|
|
2279
|
+
modelValue: vModel.value,
|
|
2280
|
+
"onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => vModel.value = $event),
|
|
2281
|
+
label: props.schema.name ?? props.name,
|
|
2282
|
+
multiline: props.schema.multiline
|
|
2283
|
+
}, null, 8, ["modelValue", "label", "multiline"]));
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2287
|
+
const _sfc_main$3 = {};
|
|
2288
|
+
const _hoisted_1$2 = {
|
|
2289
|
+
width: "16",
|
|
2290
|
+
height: "16",
|
|
2291
|
+
viewBox: "0 0 16 16",
|
|
2292
|
+
fill: "none",
|
|
2293
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
2294
|
+
};
|
|
2295
|
+
function _sfc_render$1(_ctx, _cache) {
|
|
2296
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$2, _cache[0] || (_cache[0] = [
|
|
2297
|
+
createElementVNode("path", {
|
|
2298
|
+
d: "M10.707 14.364C10.8945 14.1764 10.9998 13.9221 10.9998 13.657C10.9998 13.3918 10.8945 13.1375 10.707 12.95L5.75705 7.99995L10.707 3.04995C10.8892 2.86135 10.99 2.60875 10.9877 2.34655C10.9854 2.08435 10.8803 1.83354 10.6949 1.64813C10.5095 1.46272 10.2586 1.35756 9.99645 1.35528C9.73425 1.353 9.48165 1.45379 9.29305 1.63595L3.63605 7.29295C3.44858 7.48048 3.34326 7.73479 3.34326 7.99995C3.34326 8.26512 3.44858 8.51942 3.63605 8.70695L9.29305 14.364C9.48058 14.5514 9.73488 14.6567 10 14.6567C10.2652 14.6567 10.5195 14.5514 10.707 14.364Z",
|
|
2299
|
+
fill: "currentColor"
|
|
2300
|
+
}, null, -1)
|
|
2301
|
+
]));
|
|
2302
|
+
}
|
|
2303
|
+
const ChevronLeftIcon = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$1]]);
|
|
2304
|
+
const _sfc_main$2 = {};
|
|
2305
|
+
const _hoisted_1$1 = {
|
|
2306
|
+
width: "16",
|
|
2307
|
+
height: "16",
|
|
2308
|
+
viewBox: "0 0 16 16",
|
|
2309
|
+
fill: "none",
|
|
2310
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
2311
|
+
};
|
|
2312
|
+
function _sfc_render(_ctx, _cache) {
|
|
2313
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$1, _cache[0] || (_cache[0] = [
|
|
2314
|
+
createElementVNode("path", {
|
|
2315
|
+
d: "M5.29295 1.63605C5.10548 1.82358 5.00017 2.07788 5.00017 2.34305C5.00017 2.60821 5.10548 2.86252 5.29295 3.05005L10.243 8.00005L5.29295 12.95C5.11079 13.1387 5.01 13.3913 5.01228 13.6534C5.01456 13.9156 5.11972 14.1665 5.30513 14.3519C5.49054 14.5373 5.74135 14.6424 6.00355 14.6447C6.26575 14.647 6.51835 14.5462 6.70695 14.364L12.364 8.70705C12.5514 8.51952 12.6567 8.26521 12.6567 8.00005C12.6567 7.73488 12.5514 7.48058 12.364 7.29305L6.70695 1.63605C6.51942 1.44858 6.26512 1.34326 5.99995 1.34326C5.73479 1.34326 5.48048 1.44858 5.29295 1.63605Z",
|
|
2316
|
+
fill: "currentColor"
|
|
2317
|
+
}, null, -1)
|
|
2318
|
+
]));
|
|
2319
|
+
}
|
|
2320
|
+
const ChevronRightIcon = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render]]);
|
|
2321
|
+
const useControlComponent = (_activeBlockId) => {
|
|
2322
|
+
let lastRoot = document.body;
|
|
2323
|
+
const hoverBlockId = shallowRef(null);
|
|
2324
|
+
const activeBlockId = shallowRef(_activeBlockId ?? null);
|
|
2325
|
+
const hoverBlockElement = shallowRef(null);
|
|
2326
|
+
const activeBlockElement = shallowRef(null);
|
|
2327
|
+
let lastStateKey = "";
|
|
2328
|
+
let blocksHover = [];
|
|
2329
|
+
const onIframeBlockMouseEnter = (e) => {
|
|
2330
|
+
hoverBlockElement.value = e.currentTarget;
|
|
2331
|
+
const blockId = hoverBlockElement.value.getAttribute("data-block-id") ?? null;
|
|
2332
|
+
hoverBlockId.value = blockId;
|
|
2333
|
+
blocksHover.push(e.currentTarget);
|
|
2334
|
+
};
|
|
2335
|
+
const onIframeBlockMouseLeave = (e) => {
|
|
2336
|
+
const el = e.currentTarget;
|
|
2337
|
+
if (el && blocksHover.indexOf(el) >= 0) {
|
|
2338
|
+
blocksHover = blocksHover.slice(0, blocksHover.indexOf(el));
|
|
2339
|
+
}
|
|
2340
|
+
setTimeout(() => {
|
|
2341
|
+
var _a;
|
|
2342
|
+
if (hoverBlockElement.value !== el) return;
|
|
2343
|
+
hoverBlockElement.value = blocksHover[blocksHover.length - 1] ?? null;
|
|
2344
|
+
const blockId = ((_a = hoverBlockElement.value) == null ? void 0 : _a.getAttribute("data-block-id")) ?? null;
|
|
2345
|
+
hoverBlockId.value = blockId;
|
|
2346
|
+
}, 0);
|
|
2347
|
+
};
|
|
2348
|
+
const onIframeBlockClick = (e) => {
|
|
2349
|
+
hoverBlockElement.value = e.currentTarget;
|
|
2350
|
+
const blockId = hoverBlockElement.value.getAttribute("data-block-id") ?? null;
|
|
2351
|
+
hoverBlockId.value = blockId;
|
|
2352
|
+
activeBlockId.value = blockId;
|
|
2353
|
+
if (!blockId) return;
|
|
2354
|
+
activeBlockElement.value = hoverBlockElement.value;
|
|
2355
|
+
e.stopPropagation();
|
|
2356
|
+
e.preventDefault();
|
|
2357
|
+
};
|
|
2358
|
+
const update = (root) => {
|
|
2359
|
+
lastRoot = root;
|
|
2360
|
+
const arr = Array.from(root.querySelectorAll("[data-block-id]"));
|
|
2361
|
+
const key = arr.map((item) => item.getAttribute("data-block-id") ?? "").join(",");
|
|
2362
|
+
if (lastStateKey === key) return;
|
|
2363
|
+
for (let item of arr) {
|
|
2364
|
+
if (item.hasAttribute("data-dev")) continue;
|
|
2365
|
+
item.addEventListener("mouseenter", onIframeBlockMouseEnter);
|
|
2366
|
+
item.addEventListener("mouseleave", onIframeBlockMouseLeave);
|
|
2367
|
+
item.addEventListener("click", onIframeBlockClick);
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
2370
|
+
watch(hoverBlockId, (hoverBlockId2) => {
|
|
2371
|
+
var _a;
|
|
2372
|
+
if (hoverBlockId2 === null) {
|
|
2373
|
+
hoverBlockElement.value = null;
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
if (hoverBlockId2 === ((_a = hoverBlockElement.value) == null ? void 0 : _a.getAttribute("data-block-id"))) {
|
|
2377
|
+
return;
|
|
2378
|
+
}
|
|
2379
|
+
hoverBlockElement.value = (lastRoot == null ? void 0 : lastRoot.querySelector(`[data-block-id="${hoverBlockId2}"]`)) ?? null;
|
|
2380
|
+
});
|
|
2381
|
+
watch(activeBlockId, (activeBlockId2) => {
|
|
2382
|
+
var _a;
|
|
2383
|
+
if (activeBlockId2 === null) {
|
|
2384
|
+
activeBlockElement.value = null;
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
if (activeBlockId2 === ((_a = activeBlockElement.value) == null ? void 0 : _a.getAttribute("data-block-id"))) {
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
activeBlockElement.value = lastRoot.querySelector(`[data-block-id="${activeBlockId2}"]`) ?? null;
|
|
2391
|
+
}, { immediate: true });
|
|
2392
|
+
return {
|
|
2393
|
+
update,
|
|
2394
|
+
hoverBlockElement,
|
|
2395
|
+
activeBlockElement,
|
|
2396
|
+
activeBlockId,
|
|
2397
|
+
hoverBlockId
|
|
2398
|
+
};
|
|
2399
|
+
};
|
|
2400
|
+
registerAlias("image", { type: "object", format: "image", properties: { src: "string", previewSrc: "string?" } });
|
|
2401
|
+
registerAlias("file", { type: "object", format: "file", properties: { src: "string" } });
|
|
2402
|
+
const blocksList = blocksList$1.map((file) => ({
|
|
2403
|
+
...file.blockSchema,
|
|
2404
|
+
id: file.blockSchema.id ?? file.__name,
|
|
2405
|
+
order: file.blockSchema.order,
|
|
2406
|
+
name: file.blockSchema.name ?? getBlockName(file.__name) ?? "Unnamed block",
|
|
2407
|
+
props: file.blockSchema.props ? unfoldSchema(file.blockSchema.props) : {}
|
|
2408
|
+
}));
|
|
2409
|
+
const blocksMap = new Map(blocksList.map((item) => [item.id, item]));
|
|
2410
|
+
const processState = (state) => {
|
|
2411
|
+
walkTree(state.content, (block) => {
|
|
2412
|
+
if (block.id) {
|
|
2413
|
+
block.id = uid();
|
|
2414
|
+
}
|
|
2415
|
+
if (!block.data) {
|
|
2416
|
+
block.data = {};
|
|
2417
|
+
}
|
|
2418
|
+
block.data["data-block-id"] = block.id;
|
|
2419
|
+
const schema = blocksMap.get(block.blockId);
|
|
2420
|
+
if (!schema) return;
|
|
2421
|
+
walkSchema(block.data, schema.props, (value, schema2, key, parent, isRequired) => {
|
|
2422
|
+
if (key && isRequired && !schema2.nullable && (value === null || value === void 0)) {
|
|
2423
|
+
parent[key] = getDefaultValue(schema2);
|
|
2424
|
+
}
|
|
2425
|
+
});
|
|
2426
|
+
});
|
|
2427
|
+
return state;
|
|
2428
|
+
};
|
|
2429
|
+
const saveState = (newState) => {
|
|
2430
|
+
const state = cloneDeep(newState);
|
|
2431
|
+
walkTree(state.content, (block) => {
|
|
2432
|
+
if (!block.data) return;
|
|
2433
|
+
delete block.data["data-block-id"];
|
|
2434
|
+
const schema = blocksMap.get(block.blockId);
|
|
2435
|
+
if (!schema) return;
|
|
2436
|
+
walkSchema(block.data, schema.props, (value, schema2, key, parent) => {
|
|
2437
|
+
if (schema2.type === "object" && schema2.format === "image" && value.src === defaultImageSrc && key && parent) {
|
|
2438
|
+
parent[key] = null;
|
|
2439
|
+
}
|
|
2440
|
+
});
|
|
2441
|
+
});
|
|
2442
|
+
return state;
|
|
2443
|
+
};
|
|
2444
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
2445
|
+
__name: "PageSelector",
|
|
2446
|
+
setup(__props) {
|
|
2447
|
+
const currentPage = ref(window.state.dev.currentPage);
|
|
2448
|
+
const availablePages = window.state.dev.availablePages;
|
|
2449
|
+
const pages = availablePages.map((item) => ({
|
|
2450
|
+
id: item,
|
|
2451
|
+
title: item
|
|
2452
|
+
}));
|
|
2453
|
+
if (!availablePages.includes(currentPage.value)) {
|
|
2454
|
+
pages.push({
|
|
2455
|
+
id: currentPage.value,
|
|
2456
|
+
title: currentPage.value
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
watch(currentPage, async (newPage) => {
|
|
2460
|
+
var _a;
|
|
2461
|
+
const resp = await fetch(`/${newPage}`);
|
|
2462
|
+
const html = await resp.text();
|
|
2463
|
+
const _state = (_a = html.match(/window\.state=({.+})/)) == null ? void 0 : _a[1];
|
|
2464
|
+
const state = _state && JSON.parse(_state);
|
|
2465
|
+
processState(state);
|
|
2466
|
+
Object.assign(window.state, state);
|
|
2467
|
+
window.history.pushState({}, "", newPage === "index" ? "/" : `/${newPage}`);
|
|
2468
|
+
});
|
|
2469
|
+
return (_ctx, _cache) => {
|
|
2470
|
+
return openBlock(), createBlock(_sfc_main$9, {
|
|
2471
|
+
modelValue: currentPage.value,
|
|
2472
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => currentPage.value = $event),
|
|
2473
|
+
items: unref(pages)
|
|
2474
|
+
}, null, 8, ["modelValue", "items"]);
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
});
|
|
2478
|
+
const _hoisted_1 = { key: 1 };
|
|
2479
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
2480
|
+
__name: "EditorApp",
|
|
2481
|
+
setup(__props) {
|
|
2482
|
+
var _a, _b;
|
|
2483
|
+
const controlsOpened = ref(true);
|
|
2484
|
+
const dragMode = ref(false);
|
|
2485
|
+
provide("dragMode", dragMode);
|
|
2486
|
+
const contentBlocks = computed(() => window.state.content);
|
|
2487
|
+
useEventListener(document, "blockdrop", (e) => {
|
|
2488
|
+
if (e.content) {
|
|
2489
|
+
return;
|
|
2490
|
+
}
|
|
2491
|
+
contentBlocks.value.push(createContentBlock(e.block));
|
|
2492
|
+
});
|
|
2493
|
+
const control = useControlComponent((_a = import.meta.hot) == null ? void 0 : _a.data.activeBlockId);
|
|
2494
|
+
watch(contentBlocks, () => {
|
|
2495
|
+
control.update(window.document.body);
|
|
2496
|
+
}, { deep: true, flush: "post" });
|
|
2497
|
+
onMounted(() => {
|
|
2498
|
+
control.update(window.document.body);
|
|
2499
|
+
});
|
|
2500
|
+
const currentContentBlock = computed(() => {
|
|
2501
|
+
if (!control.activeBlockId.value) return null;
|
|
2502
|
+
return findBlock(contentBlocks.value, (block) => block.id === control.activeBlockId.value);
|
|
2503
|
+
});
|
|
2504
|
+
const currentBlock = computed(() => {
|
|
2505
|
+
if (!currentContentBlock.value) return null;
|
|
2506
|
+
return blocksMap.get(currentContentBlock.value.blockId);
|
|
2507
|
+
});
|
|
2508
|
+
const currentTab = ref(((_b = import.meta.hot) == null ? void 0 : _b.data.currentTab) ?? "blocks");
|
|
2509
|
+
const tabs = computed(() => {
|
|
2510
|
+
var _a2;
|
|
2511
|
+
const arr = [
|
|
2512
|
+
{ id: "blocks", title: "Блоки" }
|
|
2513
|
+
];
|
|
2514
|
+
if (currentContentBlock.value) {
|
|
2515
|
+
arr.push({
|
|
2516
|
+
id: "blockEdit",
|
|
2517
|
+
title: ((_a2 = currentBlock.value) == null ? void 0 : _a2.name) ?? "Unknown Block"
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
return arr;
|
|
2521
|
+
});
|
|
2522
|
+
watch(currentContentBlock, (block) => {
|
|
2523
|
+
if (block) {
|
|
2524
|
+
currentTab.value = "blockEdit";
|
|
2525
|
+
} else {
|
|
2526
|
+
if (currentTab.value === "blockEdit") {
|
|
2527
|
+
currentTab.value = "blocks";
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
});
|
|
2531
|
+
watch(currentTab, (currentTab2) => {
|
|
2532
|
+
Object.assign(import.meta.hot.data, { currentTab: currentTab2 });
|
|
2533
|
+
});
|
|
2534
|
+
watch(control.activeBlockId, (activeBlockId) => {
|
|
2535
|
+
Object.assign(import.meta.hot.data, { activeBlockId });
|
|
2536
|
+
});
|
|
2537
|
+
useKeyDownLayer("Escape", () => !!control.activeBlockId.value, () => control.activeBlockId.value = null);
|
|
2538
|
+
watchDebounced(window.state, (newState, oldState) => {
|
|
2539
|
+
var _a2, _b2;
|
|
2540
|
+
if (((_a2 = newState == null ? void 0 : newState.dev) == null ? void 0 : _a2.currentPage) !== ((_b2 = oldState == null ? void 0 : oldState.dev) == null ? void 0 : _b2.currentPage)) {
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2543
|
+
const state = saveState(newState);
|
|
2544
|
+
fetch("/@mechanica/save", {
|
|
2545
|
+
method: "POST",
|
|
2546
|
+
body: JSON.stringify(state),
|
|
2547
|
+
headers: { "content-type": "application-json" }
|
|
2548
|
+
});
|
|
2549
|
+
}, { debounce: 500 });
|
|
2550
|
+
provide("fileUploader", async (file) => {
|
|
2551
|
+
const resp = await fetch("/@mechanica/upload", {
|
|
2552
|
+
method: "POST",
|
|
2553
|
+
body: file,
|
|
2554
|
+
headers: { "x-file-name": file.name, "content-type": "application/octet-stream" }
|
|
2555
|
+
});
|
|
2556
|
+
const obj = await resp.json();
|
|
2557
|
+
return obj;
|
|
2558
|
+
});
|
|
2559
|
+
return (_ctx, _cache) => {
|
|
2560
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
2561
|
+
createVNode(Transition, null, {
|
|
2562
|
+
default: withCtx(() => [
|
|
2563
|
+
controlsOpened.value ? (openBlock(), createElementBlock("div", {
|
|
2564
|
+
key: 0,
|
|
2565
|
+
class: "editor-sidebar-left editor-hierarchy editor-component",
|
|
2566
|
+
onBlockdrop: _cache[3] || (_cache[3] = withModifiers(() => {
|
|
2567
|
+
}, ["stop"]))
|
|
2568
|
+
}, [
|
|
2569
|
+
createVNode(_sfc_main$1),
|
|
2570
|
+
_cache[10] || (_cache[10] = createElementVNode("div", { class: "title" }, "Блоки", -1)),
|
|
2571
|
+
createVNode(_sfc_main$i, {
|
|
2572
|
+
"hover-block-id": unref(control).hoverBlockId.value,
|
|
2573
|
+
"onUpdate:hoverBlockId": _cache[0] || (_cache[0] = ($event) => unref(control).hoverBlockId.value = $event),
|
|
2574
|
+
"active-block-id": unref(control).activeBlockId.value,
|
|
2575
|
+
"onUpdate:activeBlockId": _cache[1] || (_cache[1] = ($event) => unref(control).activeBlockId.value = $event),
|
|
2576
|
+
"content-blocks": contentBlocks.value,
|
|
2577
|
+
"blocks-map": unref(blocksMap)
|
|
2578
|
+
}, null, 8, ["hover-block-id", "active-block-id", "content-blocks", "blocks-map"]),
|
|
2579
|
+
createElementVNode("button", {
|
|
2580
|
+
class: "editor-sidebar__close-button",
|
|
2581
|
+
onClick: _cache[2] || (_cache[2] = ($event) => controlsOpened.value = false)
|
|
2582
|
+
}, [
|
|
2583
|
+
createVNode(ChevronLeftIcon)
|
|
2584
|
+
])
|
|
2585
|
+
], 32)) : createCommentVNode("", true)
|
|
2586
|
+
]),
|
|
2587
|
+
_: 1
|
|
2588
|
+
}),
|
|
2589
|
+
controlsOpened.value ? (openBlock(), createBlock(_sfc_main$h, {
|
|
2590
|
+
key: 0,
|
|
2591
|
+
element: unref(control).hoverBlockElement.value
|
|
2592
|
+
}, null, 8, ["element"])) : createCommentVNode("", true),
|
|
2593
|
+
controlsOpened.value ? (openBlock(), createBlock(_sfc_main$h, {
|
|
2594
|
+
key: 1,
|
|
2595
|
+
element: unref(control).activeBlockElement.value,
|
|
2596
|
+
resizable: ""
|
|
2597
|
+
}, null, 8, ["element"])) : createCommentVNode("", true),
|
|
2598
|
+
createVNode(Transition, null, {
|
|
2599
|
+
default: withCtx(() => [
|
|
2600
|
+
controlsOpened.value ? (openBlock(), createElementBlock("div", {
|
|
2601
|
+
key: 0,
|
|
2602
|
+
class: "editor-sidebar-right editor-blocks-sidebar editor-component",
|
|
2603
|
+
onBlockdrop: _cache[7] || (_cache[7] = withModifiers(() => {
|
|
2604
|
+
}, ["stop"]))
|
|
2605
|
+
}, [
|
|
2606
|
+
createElementVNode("button", {
|
|
2607
|
+
class: "editor-sidebar__close-button right",
|
|
2608
|
+
onClick: _cache[4] || (_cache[4] = ($event) => controlsOpened.value = false)
|
|
2609
|
+
}, [
|
|
2610
|
+
createVNode(ChevronRightIcon)
|
|
2611
|
+
]),
|
|
2612
|
+
createVNode(_sfc_main$g, {
|
|
2613
|
+
modelValue: currentTab.value,
|
|
2614
|
+
"onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => currentTab.value = $event),
|
|
2615
|
+
items: tabs.value
|
|
2616
|
+
}, null, 8, ["modelValue", "items"]),
|
|
2617
|
+
createVNode(_sfc_main$f, { page: currentTab.value }, {
|
|
2618
|
+
blocks: withCtx(() => [
|
|
2619
|
+
createVNode(_sfc_main$m, { blocks: unref(blocksList) }, null, 8, ["blocks"])
|
|
2620
|
+
]),
|
|
2621
|
+
blockEdit: withCtx(() => [
|
|
2622
|
+
currentBlock.value && currentContentBlock.value ? (openBlock(), createBlock(_sfc_main$4, {
|
|
2623
|
+
key: currentContentBlock.value.id,
|
|
2624
|
+
schema: currentBlock.value.props,
|
|
2625
|
+
modelValue: currentContentBlock.value.data,
|
|
2626
|
+
"onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => currentContentBlock.value.data = $event),
|
|
2627
|
+
flat: ""
|
|
2628
|
+
}, null, 8, ["schema", "modelValue"])) : (openBlock(), createElementBlock("div", _hoisted_1, "Схема для блока не найдена"))
|
|
2629
|
+
]),
|
|
2630
|
+
_: 1
|
|
2631
|
+
}, 8, ["page"])
|
|
2632
|
+
], 32)) : createCommentVNode("", true)
|
|
2633
|
+
]),
|
|
2634
|
+
_: 1
|
|
2635
|
+
}),
|
|
2636
|
+
createVNode(Transition, null, {
|
|
2637
|
+
default: withCtx(() => [
|
|
2638
|
+
!controlsOpened.value ? (openBlock(), createElementBlock("div", {
|
|
2639
|
+
key: 0,
|
|
2640
|
+
class: "editor-sidebar__close-button editor-component fixed",
|
|
2641
|
+
onClick: _cache[8] || (_cache[8] = ($event) => controlsOpened.value = true)
|
|
2642
|
+
}, [
|
|
2643
|
+
createVNode(ChevronRightIcon)
|
|
2644
|
+
])) : createCommentVNode("", true)
|
|
2645
|
+
]),
|
|
2646
|
+
_: 1
|
|
2647
|
+
}),
|
|
2648
|
+
createVNode(Transition, null, {
|
|
2649
|
+
default: withCtx(() => [
|
|
2650
|
+
!controlsOpened.value ? (openBlock(), createElementBlock("div", {
|
|
2651
|
+
key: 0,
|
|
2652
|
+
class: "editor-sidebar__close-button editor-component right fixed",
|
|
2653
|
+
onClick: _cache[9] || (_cache[9] = ($event) => controlsOpened.value = true)
|
|
2654
|
+
}, [
|
|
2655
|
+
createVNode(ChevronLeftIcon)
|
|
2656
|
+
])) : createCommentVNode("", true)
|
|
2657
|
+
]),
|
|
2658
|
+
_: 1
|
|
2659
|
+
})
|
|
2660
|
+
], 64);
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
window.state = reactive(processState(window.state));
|
|
2665
|
+
const mountDiv = document.createElement("div");
|
|
2666
|
+
mountDiv.id = "data-mechanics-editor";
|
|
2667
|
+
document.body.append(mountDiv);
|
|
2668
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
2669
|
+
createApp(_sfc_main).mount(mountDiv);
|
|
2670
|
+
});
|
|
2671
|
+
//# sourceMappingURL=editor.js.map
|