mechanica 1.0.0 → 1.0.2
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.js +36 -29
- package/dist/editor.js.map +1 -1
- package/dist/plugin.js +24 -21
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/editor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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";
|
|
2
|
+
import { blocksList as blocksList$1, addUpdateListener } from "virtual:builder-blocks";
|
|
3
3
|
import { registerAlias, unfoldSchema } from "compact-json-schema";
|
|
4
4
|
const findParent = (el, callback) => {
|
|
5
5
|
if (callback(el)) return el;
|
|
@@ -2321,7 +2321,7 @@ const ChevronRightIcon = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _s
|
|
|
2321
2321
|
const useControlComponent = (_activeBlockId) => {
|
|
2322
2322
|
let lastRoot = document.body;
|
|
2323
2323
|
const hoverBlockId = shallowRef(null);
|
|
2324
|
-
const activeBlockId = shallowRef(
|
|
2324
|
+
const activeBlockId = shallowRef(null);
|
|
2325
2325
|
const hoverBlockElement = shallowRef(null);
|
|
2326
2326
|
const activeBlockElement = shallowRef(null);
|
|
2327
2327
|
let lastStateKey = "";
|
|
@@ -2387,26 +2387,41 @@ const useControlComponent = (_activeBlockId) => {
|
|
|
2387
2387
|
if (activeBlockId2 === ((_a = activeBlockElement.value) == null ? void 0 : _a.getAttribute("data-block-id"))) {
|
|
2388
2388
|
return;
|
|
2389
2389
|
}
|
|
2390
|
-
|
|
2390
|
+
updateActiveElement();
|
|
2391
2391
|
}, { immediate: true });
|
|
2392
|
+
const updateActiveElement = () => {
|
|
2393
|
+
const blockId = activeBlockId.value;
|
|
2394
|
+
if (!blockId) return;
|
|
2395
|
+
activeBlockElement.value = lastRoot.querySelector(`[data-block-id="${blockId}"]`) ?? null;
|
|
2396
|
+
};
|
|
2392
2397
|
return {
|
|
2393
2398
|
update,
|
|
2394
2399
|
hoverBlockElement,
|
|
2395
2400
|
activeBlockElement,
|
|
2396
2401
|
activeBlockId,
|
|
2397
|
-
hoverBlockId
|
|
2402
|
+
hoverBlockId,
|
|
2403
|
+
updateActiveElement
|
|
2398
2404
|
};
|
|
2399
2405
|
};
|
|
2400
2406
|
registerAlias("image", { type: "object", format: "image", properties: { src: "string", previewSrc: "string?" } });
|
|
2401
2407
|
registerAlias("file", { type: "object", format: "file", properties: { src: "string" } });
|
|
2402
|
-
const blocksList = blocksList$1.map((file) => ({
|
|
2408
|
+
const blocksList = shallowRef(blocksList$1.map((file) => ({
|
|
2403
2409
|
...file.blockSchema,
|
|
2404
2410
|
id: file.blockSchema.id ?? file.__name,
|
|
2405
2411
|
order: file.blockSchema.order,
|
|
2406
2412
|
name: file.blockSchema.name ?? getBlockName(file.__name) ?? "Unnamed block",
|
|
2407
2413
|
props: file.blockSchema.props ? unfoldSchema(file.blockSchema.props) : {}
|
|
2408
|
-
}));
|
|
2409
|
-
const blocksMap = new Map(blocksList.map((item) => [item.id, item]));
|
|
2414
|
+
})));
|
|
2415
|
+
const blocksMap = computed(() => new Map(blocksList.value.map((item) => [item.id, item])));
|
|
2416
|
+
addUpdateListener((module) => {
|
|
2417
|
+
blocksList.value = module.blocksList.map((file) => ({
|
|
2418
|
+
...file.blockSchema,
|
|
2419
|
+
id: file.blockSchema.id ?? file.__name,
|
|
2420
|
+
order: file.blockSchema.order,
|
|
2421
|
+
name: file.blockSchema.name ?? getBlockName(file.__name) ?? "Unnamed block",
|
|
2422
|
+
props: file.blockSchema.props ? unfoldSchema(file.blockSchema.props) : {}
|
|
2423
|
+
}));
|
|
2424
|
+
});
|
|
2410
2425
|
const processState = (state) => {
|
|
2411
2426
|
walkTree(state.content, (block) => {
|
|
2412
2427
|
if (block.id) {
|
|
@@ -2416,7 +2431,7 @@ const processState = (state) => {
|
|
|
2416
2431
|
block.data = {};
|
|
2417
2432
|
}
|
|
2418
2433
|
block.data["data-block-id"] = block.id;
|
|
2419
|
-
const schema = blocksMap.get(block.blockId);
|
|
2434
|
+
const schema = blocksMap.value.get(block.blockId);
|
|
2420
2435
|
if (!schema) return;
|
|
2421
2436
|
walkSchema(block.data, schema.props, (value, schema2, key, parent, isRequired) => {
|
|
2422
2437
|
if (key && isRequired && !schema2.nullable && (value === null || value === void 0)) {
|
|
@@ -2431,7 +2446,7 @@ const saveState = (newState) => {
|
|
|
2431
2446
|
walkTree(state.content, (block) => {
|
|
2432
2447
|
if (!block.data) return;
|
|
2433
2448
|
delete block.data["data-block-id"];
|
|
2434
|
-
const schema = blocksMap.get(block.blockId);
|
|
2449
|
+
const schema = blocksMap.value.get(block.blockId);
|
|
2435
2450
|
if (!schema) return;
|
|
2436
2451
|
walkSchema(block.data, schema.props, (value, schema2, key, parent) => {
|
|
2437
2452
|
if (schema2.type === "object" && schema2.format === "image" && value.src === defaultImageSrc && key && parent) {
|
|
@@ -2479,7 +2494,6 @@ const _hoisted_1 = { key: 1 };
|
|
|
2479
2494
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
2480
2495
|
__name: "EditorApp",
|
|
2481
2496
|
setup(__props) {
|
|
2482
|
-
var _a, _b;
|
|
2483
2497
|
const controlsOpened = ref(true);
|
|
2484
2498
|
const dragMode = ref(false);
|
|
2485
2499
|
provide("dragMode", dragMode);
|
|
@@ -2490,10 +2504,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2490
2504
|
}
|
|
2491
2505
|
contentBlocks.value.push(createContentBlock(e.block));
|
|
2492
2506
|
});
|
|
2493
|
-
const control = useControlComponent(
|
|
2507
|
+
const control = useControlComponent();
|
|
2494
2508
|
watch(contentBlocks, () => {
|
|
2495
2509
|
control.update(window.document.body);
|
|
2496
2510
|
}, { deep: true, flush: "post" });
|
|
2511
|
+
watch(blocksList, () => {
|
|
2512
|
+
control.update(window.document.body);
|
|
2513
|
+
control.updateActiveElement();
|
|
2514
|
+
}, { flush: "post" });
|
|
2497
2515
|
onMounted(() => {
|
|
2498
2516
|
control.update(window.document.body);
|
|
2499
2517
|
});
|
|
@@ -2503,18 +2521,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2503
2521
|
});
|
|
2504
2522
|
const currentBlock = computed(() => {
|
|
2505
2523
|
if (!currentContentBlock.value) return null;
|
|
2506
|
-
return blocksMap.get(currentContentBlock.value.blockId);
|
|
2524
|
+
return blocksMap.value.get(currentContentBlock.value.blockId);
|
|
2507
2525
|
});
|
|
2508
|
-
const currentTab = ref(
|
|
2526
|
+
const currentTab = ref("blocks");
|
|
2509
2527
|
const tabs = computed(() => {
|
|
2510
|
-
var
|
|
2528
|
+
var _a;
|
|
2511
2529
|
const arr = [
|
|
2512
2530
|
{ id: "blocks", title: "Блоки" }
|
|
2513
2531
|
];
|
|
2514
2532
|
if (currentContentBlock.value) {
|
|
2515
2533
|
arr.push({
|
|
2516
2534
|
id: "blockEdit",
|
|
2517
|
-
title: ((
|
|
2535
|
+
title: ((_a = currentBlock.value) == null ? void 0 : _a.name) ?? "Unknown Block"
|
|
2518
2536
|
});
|
|
2519
2537
|
}
|
|
2520
2538
|
return arr;
|
|
@@ -2528,24 +2546,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2528
2546
|
}
|
|
2529
2547
|
}
|
|
2530
2548
|
});
|
|
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
2549
|
useKeyDownLayer("Escape", () => !!control.activeBlockId.value, () => control.activeBlockId.value = null);
|
|
2538
2550
|
watchDebounced(window.state, (newState, oldState) => {
|
|
2539
|
-
var
|
|
2540
|
-
if (((
|
|
2551
|
+
var _a, _b;
|
|
2552
|
+
if (((_a = newState == null ? void 0 : newState.dev) == null ? void 0 : _a.currentPage) !== ((_b = oldState == null ? void 0 : oldState.dev) == null ? void 0 : _b.currentPage)) {
|
|
2541
2553
|
return;
|
|
2542
2554
|
}
|
|
2543
|
-
|
|
2544
|
-
fetch("/@mechanica/save", {
|
|
2545
|
-
method: "POST",
|
|
2546
|
-
body: JSON.stringify(state),
|
|
2547
|
-
headers: { "content-type": "application-json" }
|
|
2548
|
-
});
|
|
2555
|
+
saveState(newState);
|
|
2549
2556
|
}, { debounce: 500 });
|
|
2550
2557
|
provide("fileUploader", async (file) => {
|
|
2551
2558
|
const resp = await fetch("/@mechanica/upload", {
|