@craftile/editor 1.1.1 → 1.1.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/index.js +34 -41
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -12,10 +12,12 @@ const ao = () => crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(3
|
|
|
12
12
|
return { kind: "parent", parent: i, index: c };
|
|
13
13
|
}
|
|
14
14
|
const r = ti(e, o), s = e.regions.find((i) => ne(i) === r);
|
|
15
|
+
if (!s)
|
|
16
|
+
throw new Error(`Region not found: ${r}`);
|
|
15
17
|
return {
|
|
16
18
|
kind: "region",
|
|
17
19
|
regionId: r,
|
|
18
|
-
index: gn(s
|
|
20
|
+
index: gn(s.blocks.length, n)
|
|
19
21
|
};
|
|
20
22
|
}, At = (e, t, o) => {
|
|
21
23
|
if (o > 0 && o < e.length) {
|
|
@@ -247,26 +249,23 @@ class Ya {
|
|
|
247
249
|
blockSchema;
|
|
248
250
|
insertedBlock;
|
|
249
251
|
actualIndex;
|
|
252
|
+
resolvedRegionId;
|
|
250
253
|
emit;
|
|
251
254
|
constructor(t, o) {
|
|
252
255
|
this.page = t, this.blockType = o.blockType, this.parentId = o.parentId, this.regionId = o.regionId, this.index = o.index, this.blockId = ao(), this.emit = o.emit, this.blockSchema = o.blockSchema, this.properties = this.buildProperties(o.blockSchema);
|
|
253
256
|
}
|
|
254
257
|
apply() {
|
|
255
|
-
const t = oi(this.page, this.parentId, this.regionId, this.index)
|
|
256
|
-
|
|
258
|
+
const t = oi(this.page, this.parentId, this.regionId, this.index);
|
|
259
|
+
this.resolvedRegionId = t.kind === "region" ? t.regionId : void 0;
|
|
260
|
+
const o = this.blockSchema?.meta?.name || this.blockType;
|
|
261
|
+
this.insertedBlock = {
|
|
257
262
|
type: this.blockType,
|
|
258
263
|
id: this.blockId,
|
|
259
264
|
name: o,
|
|
260
265
|
properties: this.properties,
|
|
261
266
|
children: [],
|
|
262
267
|
parentId: void 0
|
|
263
|
-
}, this.page.blocks[this.blockId] = this.insertedBlock, this.actualIndex = t.index, t.kind === "parent")
|
|
264
|
-
this.insertedBlock.parentId = t.parent.id, t.parent.children.splice(t.index, 0, this.blockId);
|
|
265
|
-
else {
|
|
266
|
-
let n = this.page.regions.find((r) => ne(r) === t.regionId);
|
|
267
|
-
n || (n = { id: t.regionId, name: t.regionId, blocks: [] }, this.page.regions.push(n)), n.blocks.splice(t.index, 0, this.blockId);
|
|
268
|
-
}
|
|
269
|
-
this.emit("block:insert", {
|
|
268
|
+
}, this.page.blocks[this.blockId] = this.insertedBlock, this.actualIndex = t.index, t.kind === "parent" ? (this.insertedBlock.parentId = t.parent.id, t.parent.children.splice(t.index, 0, this.blockId)) : this.page.regions.find((r) => ne(r) === t.regionId).blocks.splice(t.index, 0, this.blockId), this.emit("block:insert", {
|
|
270
269
|
blockId: this.blockId,
|
|
271
270
|
block: this.insertedBlock,
|
|
272
271
|
parentId: this.parentId,
|
|
@@ -279,14 +278,15 @@ class Ya {
|
|
|
279
278
|
if (delete this.page.blocks[this.blockId], this.parentId) {
|
|
280
279
|
const t = this.page.blocks[this.parentId];
|
|
281
280
|
t && this.actualIndex !== void 0 && t.children.splice(this.actualIndex, 1);
|
|
282
|
-
} else {
|
|
283
|
-
const t = this.
|
|
284
|
-
|
|
281
|
+
} else if (this.resolvedRegionId) {
|
|
282
|
+
const t = this.page.regions.find((o) => ne(o) === this.resolvedRegionId);
|
|
283
|
+
t && this.actualIndex !== void 0 && t.blocks.splice(this.actualIndex, 1);
|
|
285
284
|
}
|
|
286
285
|
this.emit("block:remove", {
|
|
287
286
|
blockId: this.blockId,
|
|
288
287
|
block: this.insertedBlock,
|
|
289
|
-
parentId: this.parentId
|
|
288
|
+
parentId: this.parentId,
|
|
289
|
+
regionId: this.resolvedRegionId
|
|
290
290
|
});
|
|
291
291
|
}
|
|
292
292
|
}
|
|
@@ -316,6 +316,7 @@ class Zr {
|
|
|
316
316
|
properties;
|
|
317
317
|
insertedBlock;
|
|
318
318
|
actualIndex;
|
|
319
|
+
resolvedRegionId;
|
|
319
320
|
blocksManager;
|
|
320
321
|
emit;
|
|
321
322
|
createdBlockIds = [];
|
|
@@ -337,7 +338,9 @@ class Zr {
|
|
|
337
338
|
this.properties = this.buildProperties(n, r);
|
|
338
339
|
}
|
|
339
340
|
apply() {
|
|
340
|
-
const t = oi(this.page, this.parentId, this.regionId, this.index)
|
|
341
|
+
const t = oi(this.page, this.parentId, this.regionId, this.index);
|
|
342
|
+
this.resolvedRegionId = t.kind === "region" ? t.regionId : void 0;
|
|
343
|
+
const o = this.blocksManager.get(this.blockType);
|
|
341
344
|
if (this.presetData)
|
|
342
345
|
this.insertedBlock = {
|
|
343
346
|
type: this.blockType,
|
|
@@ -367,13 +370,7 @@ class Zr {
|
|
|
367
370
|
}
|
|
368
371
|
if (!this.insertedBlock)
|
|
369
372
|
throw new Error("Failed to create block");
|
|
370
|
-
|
|
371
|
-
this.insertedBlock.parentId = t.parent.id, t.parent.children.splice(t.index, 0, this.blockId);
|
|
372
|
-
else {
|
|
373
|
-
let n = this.page.regions.find((r) => ne(r) === t.regionId);
|
|
374
|
-
n || (n = { id: t.regionId, name: t.regionId, blocks: [] }, this.page.regions.push(n)), n.blocks.splice(t.index, 0, this.blockId);
|
|
375
|
-
}
|
|
376
|
-
this.emit("block:insert", {
|
|
373
|
+
this.actualIndex = t.index, t.kind === "parent" ? (this.insertedBlock.parentId = t.parent.id, t.parent.children.splice(t.index, 0, this.blockId)) : this.page.regions.find((r) => ne(r) === t.regionId).blocks.splice(t.index, 0, this.blockId), this.emit("block:insert", {
|
|
377
374
|
blockId: this.blockId,
|
|
378
375
|
block: this.insertedBlock,
|
|
379
376
|
parentId: this.parentId,
|
|
@@ -388,14 +385,15 @@ class Zr {
|
|
|
388
385
|
if (this.parentId) {
|
|
389
386
|
const t = this.page.blocks[this.parentId];
|
|
390
387
|
t && this.actualIndex !== void 0 && t.children.splice(this.actualIndex, 1);
|
|
391
|
-
} else {
|
|
392
|
-
const t = this.
|
|
393
|
-
|
|
388
|
+
} else if (this.resolvedRegionId) {
|
|
389
|
+
const t = this.page.regions.find((o) => ne(o) === this.resolvedRegionId);
|
|
390
|
+
t && this.actualIndex !== void 0 && t.blocks.splice(this.actualIndex, 1);
|
|
394
391
|
}
|
|
395
392
|
this.emit("block:remove", {
|
|
396
393
|
blockId: this.blockId,
|
|
397
394
|
block: this.insertedBlock,
|
|
398
|
-
parentId: this.parentId
|
|
395
|
+
parentId: this.parentId,
|
|
396
|
+
regionId: this.resolvedRegionId
|
|
399
397
|
});
|
|
400
398
|
}
|
|
401
399
|
}
|
|
@@ -462,7 +460,8 @@ class Ja {
|
|
|
462
460
|
delete this.page.blocks[this.blockId], this.emit("block:remove", {
|
|
463
461
|
blockId: this.blockId,
|
|
464
462
|
block: this.removedBlock,
|
|
465
|
-
parentId: this.originalParentId
|
|
463
|
+
parentId: this.originalParentId,
|
|
464
|
+
regionId: this.regionId
|
|
466
465
|
});
|
|
467
466
|
}
|
|
468
467
|
revert() {
|
|
@@ -514,18 +513,11 @@ class Qa {
|
|
|
514
513
|
const o = this.page.regions.find((n) => ne(n) === this.originalRegionId);
|
|
515
514
|
o && this.originalIndex !== -1 && o.blocks.splice(this.originalIndex, 1);
|
|
516
515
|
}
|
|
517
|
-
|
|
518
|
-
this.blockToMove.parentId = t.parent.id, t.parent.children.splice(t.index, 0, this.blockId);
|
|
519
|
-
else {
|
|
520
|
-
this.blockToMove.parentId = void 0;
|
|
521
|
-
let o = this.page.regions.find((n) => ne(n) === t.regionId);
|
|
522
|
-
o || (o = { id: t.regionId, name: t.regionId, blocks: [] }, this.page.regions.push(o)), o.blocks.splice(t.index, 0, this.blockId);
|
|
523
|
-
}
|
|
524
|
-
this.emit("block:move", {
|
|
516
|
+
t.kind === "parent" ? (this.blockToMove.parentId = t.parent.id, t.parent.children.splice(t.index, 0, this.blockId)) : (this.blockToMove.parentId = void 0, this.page.regions.find((n) => ne(n) === t.regionId).blocks.splice(t.index, 0, this.blockId)), this.emit("block:move", {
|
|
525
517
|
blockId: this.blockId,
|
|
526
518
|
targetParentId: this.targetParentId,
|
|
527
519
|
targetIndex: this.targetIndex,
|
|
528
|
-
targetRegionId:
|
|
520
|
+
targetRegionId: t.kind === "region" ? t.regionId : void 0,
|
|
529
521
|
sourceParentId: this.originalParentId || null,
|
|
530
522
|
sourceRegionId: this.originalRegionId || null,
|
|
531
523
|
sourceIndex: this.originalIndex
|
|
@@ -558,7 +550,10 @@ class Qa {
|
|
|
558
550
|
);
|
|
559
551
|
return { kind: "parent", parent: s, index: l };
|
|
560
552
|
}
|
|
561
|
-
const t = ti(this.page, this.targetRegionId), o = this.page.regions.find((s) => ne(s) === t)
|
|
553
|
+
const t = ti(this.page, this.targetRegionId), o = this.page.regions.find((s) => ne(s) === t);
|
|
554
|
+
if (!o)
|
|
555
|
+
throw new Error(`Region not found: ${t}`);
|
|
556
|
+
const r = this.originalRegionId === t ? o.blocks.filter((s) => s !== this.blockId) : o.blocks;
|
|
562
557
|
return { kind: "region", regionId: t, index: gn(r.length, this.targetIndex) };
|
|
563
558
|
}
|
|
564
559
|
revert() {
|
|
@@ -760,8 +755,6 @@ class tl {
|
|
|
760
755
|
}
|
|
761
756
|
determineInsertLocation() {
|
|
762
757
|
const t = this.page.blocks[this.blockId];
|
|
763
|
-
if (!t)
|
|
764
|
-
throw new Error(`Block not found: ${this.blockId}`);
|
|
765
758
|
if (this.parentId = t.parentId || null, this.parentId) {
|
|
766
759
|
const o = this.page.blocks[this.parentId];
|
|
767
760
|
if (o) {
|
|
@@ -786,7 +779,7 @@ class tl {
|
|
|
786
779
|
throw new Error(`Parent block not found: ${this.parentId}`);
|
|
787
780
|
t.children.splice(this.insertIndex, 0, this.duplicatedBlockId);
|
|
788
781
|
} else {
|
|
789
|
-
let t = this.page.regions.find((o) => o
|
|
782
|
+
let t = this.page.regions.find((o) => ne(o) === this.regionId);
|
|
790
783
|
t || (t = { name: this.regionId || "main", blocks: [] }, this.page.regions.push(t)), t.blocks.splice(this.insertIndex, 0, this.duplicatedBlockId);
|
|
791
784
|
}
|
|
792
785
|
}
|
|
@@ -799,7 +792,7 @@ class tl {
|
|
|
799
792
|
o !== -1 && t.children.splice(o, 1);
|
|
800
793
|
}
|
|
801
794
|
} else if (this.page.regions) {
|
|
802
|
-
const t = this.page.regions.find((o) => o
|
|
795
|
+
const t = this.page.regions.find((o) => ne(o) === this.regionId);
|
|
803
796
|
if (t) {
|
|
804
797
|
const o = t.blocks.indexOf(this.duplicatedBlockId);
|
|
805
798
|
o !== -1 && t.blocks.splice(o, 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@craftile/editor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Vue.js-based editor UI components for craftile blocks engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"craftile",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"vue": "^3.5.17",
|
|
40
40
|
"vue-draggable-plus": "^0.6.0",
|
|
41
|
-
"@craftile/core": "1.1.
|
|
42
|
-
"@craftile/event-bus": "1.1.
|
|
43
|
-
"@craftile/messenger": "1.1.
|
|
44
|
-
"@craftile/types": "1.1.
|
|
41
|
+
"@craftile/core": "1.1.2",
|
|
42
|
+
"@craftile/event-bus": "1.1.2",
|
|
43
|
+
"@craftile/messenger": "1.1.2",
|
|
44
|
+
"@craftile/types": "1.1.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@ark-ui/vue": "^5.24.1",
|