mce 0.20.0 → 0.21.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/index.js +127 -12
- package/dist/plugins/flexLayout.d.ts +18 -0
- package/dist/typed-plugins.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Aabb2D, Animation, Camera2D, DEG_TO_RAD, DrawboardEffect, Element2D, Engine, IN_BROWSER, IN_MAC_OS, Lottie2D, Node as Node$1, Obb2D, Timeline, TimelineNode, Video2D, assets, clamp, customNodes, render } from "modern-canvas";
|
|
2
|
-
import { Fragment, Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, effectScope, getCurrentInstance, guardReactiveProps, h, inject, isReactive, isRef, markRaw, mergeModels, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, onMounted, onScopeDispose, openBlock, provide, reactive, readonly, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, shallowRef, toDisplayString, toRef, toValue, unref, useAttrs, useId, useModel, useSlots, useTemplateRef, vModelText, vShow, warn, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
2
|
+
import { Fragment, Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createTextVNode, createVNode, defineComponent, effectScope, getCurrentInstance, guardReactiveProps, h, inject, isReactive, isRef, markRaw, mergeModels, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, onMounted, onScopeDispose, openBlock, provide, reactive, readonly, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, shallowRef, toDisplayString, toRaw, toRef, toValue, unref, useAttrs, useId, useModel, useSlots, useTemplateRef, vModelText, vShow, warn, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
3
3
|
import { isClient, onClickOutside, useDebounceFn, useEventListener, useFileDialog, useImage, useLocalStorage, useResizeObserver } from "@vueuse/core";
|
|
4
4
|
import { Observable, getObjectValueByPath, idGenerator, isCRLF, isEqualObject, normalizeCRLF, normalizeTextContent, property, setObjectValueByPath, textContentToString } from "modern-idoc";
|
|
5
5
|
import { Text, measureText } from "modern-text";
|
|
@@ -8163,6 +8163,116 @@ var edit_default = definePlugin((editor, options) => {
|
|
|
8163
8163
|
};
|
|
8164
8164
|
});
|
|
8165
8165
|
//#endregion
|
|
8166
|
+
//#region src/plugins/flexLayout.ts
|
|
8167
|
+
/**
|
|
8168
|
+
* Drag-to-reorder for children of a flex/auto-layout container.
|
|
8169
|
+
*
|
|
8170
|
+
* `transform.ts` skips the absolute move for such a child; here we make it
|
|
8171
|
+
* follow the cursor (a temporary left/top offset over its flow slot), swap
|
|
8172
|
+
* order with its siblings as its centre crosses theirs, and on release drop
|
|
8173
|
+
* the offset so it snaps back into its (new) slot.
|
|
8174
|
+
*
|
|
8175
|
+
* The sibling layout is derived analytically from sizes/gap captured once at
|
|
8176
|
+
* drag start + the current children order (the order array updates
|
|
8177
|
+
* synchronously on `moveChild`, but the rendered transforms only catch up on
|
|
8178
|
+
* the next tick — so reading them back with `getObb` mid-drag is stale and
|
|
8179
|
+
* makes the swap oscillate at the boundary). Structural changes run on the raw
|
|
8180
|
+
* (non-reactive) nodes, else the canvas hands a Proxy to yoga's embind which
|
|
8181
|
+
* throws a Proxy-invariant error and drops the child.
|
|
8182
|
+
*/
|
|
8183
|
+
var flexLayout_default = definePlugin((editor) => {
|
|
8184
|
+
const { isElement, elementSelection, getObb } = editor;
|
|
8185
|
+
let drag;
|
|
8186
|
+
function flexParentOf(el) {
|
|
8187
|
+
const parent = el?.getParent();
|
|
8188
|
+
return parent && isElement(parent) && parent.style?.display === "flex" ? parent : void 0;
|
|
8189
|
+
}
|
|
8190
|
+
function elementChildren(parent) {
|
|
8191
|
+
return parent.children.filter((c) => isElement(c));
|
|
8192
|
+
}
|
|
8193
|
+
/** el's slot main-start and the siblings' main-axis centres, for one order. */
|
|
8194
|
+
function layout(d, order) {
|
|
8195
|
+
let pos = d.contentStart;
|
|
8196
|
+
let elStart = pos;
|
|
8197
|
+
const centers = [];
|
|
8198
|
+
for (const c of order) {
|
|
8199
|
+
const s = d.size.get(c.instanceId) ?? 0;
|
|
8200
|
+
if (c.equal(d.el)) elStart = pos;
|
|
8201
|
+
else centers.push(pos + s / 2);
|
|
8202
|
+
pos += s + d.gap;
|
|
8203
|
+
}
|
|
8204
|
+
return {
|
|
8205
|
+
elStart,
|
|
8206
|
+
centers
|
|
8207
|
+
};
|
|
8208
|
+
}
|
|
8209
|
+
function start() {
|
|
8210
|
+
drag = void 0;
|
|
8211
|
+
const el = elementSelection.value[0];
|
|
8212
|
+
if (elementSelection.value.length !== 1 || !el) return;
|
|
8213
|
+
const parent = flexParentOf(el);
|
|
8214
|
+
if (!parent) return;
|
|
8215
|
+
const dir = parent.style.flexDirection ?? "row";
|
|
8216
|
+
const horizontal = dir === "row" || dir === "row-reverse";
|
|
8217
|
+
const children = elementChildren(parent);
|
|
8218
|
+
const main = (o) => horizontal ? o.left : o.top;
|
|
8219
|
+
const mainSize = (o) => horizontal ? o.width : o.height;
|
|
8220
|
+
const size = /* @__PURE__ */ new Map();
|
|
8221
|
+
children.forEach((c) => size.set(c.instanceId, mainSize(getObb(c))));
|
|
8222
|
+
const first = getObb(children[0]);
|
|
8223
|
+
const gap = children[1] ? main(getObb(children[1])) - (main(first) + mainSize(first)) : 0;
|
|
8224
|
+
const elObb = getObb(el);
|
|
8225
|
+
drag = {
|
|
8226
|
+
el,
|
|
8227
|
+
parent,
|
|
8228
|
+
horizontal,
|
|
8229
|
+
reverse: typeof dir === "string" && dir.endsWith("-reverse"),
|
|
8230
|
+
gap,
|
|
8231
|
+
contentStart: main(first),
|
|
8232
|
+
crossSlot: horizontal ? elObb.top : elObb.left,
|
|
8233
|
+
size
|
|
8234
|
+
};
|
|
8235
|
+
}
|
|
8236
|
+
function move(value) {
|
|
8237
|
+
if (!drag) return;
|
|
8238
|
+
const d = drag;
|
|
8239
|
+
const dragMain = d.horizontal ? value.left + value.width / 2 : value.top + value.height / 2;
|
|
8240
|
+
let order = elementChildren(d.parent);
|
|
8241
|
+
let { elStart, centers } = layout(d, order);
|
|
8242
|
+
const before = centers.filter((c) => c < dragMain).length;
|
|
8243
|
+
const index = d.reverse ? centers.length - before : before;
|
|
8244
|
+
if (index !== order.findIndex((c) => c.equal(d.el))) {
|
|
8245
|
+
toRaw(d.parent).moveChild(toRaw(d.el), index);
|
|
8246
|
+
order = elementChildren(d.parent);
|
|
8247
|
+
({elStart} = layout(d, order));
|
|
8248
|
+
}
|
|
8249
|
+
if (d.horizontal) {
|
|
8250
|
+
d.el.style.left = value.left - elStart;
|
|
8251
|
+
d.el.style.top = value.top - d.crossSlot;
|
|
8252
|
+
} else {
|
|
8253
|
+
d.el.style.top = value.top - elStart;
|
|
8254
|
+
d.el.style.left = value.left - d.crossSlot;
|
|
8255
|
+
}
|
|
8256
|
+
}
|
|
8257
|
+
function end() {
|
|
8258
|
+
if (drag) {
|
|
8259
|
+
drag.el.style.left = 0;
|
|
8260
|
+
drag.el.style.top = 0;
|
|
8261
|
+
drag = void 0;
|
|
8262
|
+
}
|
|
8263
|
+
}
|
|
8264
|
+
return {
|
|
8265
|
+
name: "mce:flexLayout",
|
|
8266
|
+
events: {
|
|
8267
|
+
selectionTransformStarted: start,
|
|
8268
|
+
selectionTransformed: (ctx) => {
|
|
8269
|
+
if (ctx.handle === "move") move(ctx.value);
|
|
8270
|
+
},
|
|
8271
|
+
selectionTransformEnded: end
|
|
8272
|
+
}
|
|
8273
|
+
};
|
|
8274
|
+
});
|
|
8275
|
+
//#endregion
|
|
8166
8276
|
//#region src/plugins/formatPaint.ts
|
|
8167
8277
|
var formatPaint_default = definePlugin((editor) => {
|
|
8168
8278
|
const { elementSelection, exec, state } = editor;
|
|
@@ -13691,7 +13801,7 @@ var selection_default = definePlugin((editor) => {
|
|
|
13691
13801
|
selectionTransformed: () => {
|
|
13692
13802
|
elementSelection.value.forEach((el) => {
|
|
13693
13803
|
el.findAncestor((ancestor) => {
|
|
13694
|
-
if (isElement(ancestor) && !inEditorIs(ancestor, "Frame")) obbToFit(ancestor);
|
|
13804
|
+
if (isElement(ancestor) && !inEditorIs(ancestor, "Frame") && ancestor.style.display !== "flex") obbToFit(ancestor);
|
|
13695
13805
|
return false;
|
|
13696
13806
|
});
|
|
13697
13807
|
});
|
|
@@ -15481,6 +15591,16 @@ var SmartSelection_default = /* @__PURE__ */ defineComponent({
|
|
|
15481
15591
|
switch (direction) {
|
|
15482
15592
|
case "horizontal":
|
|
15483
15593
|
if (center.x < min) {
|
|
15594
|
+
if (prev) {
|
|
15595
|
+
let left = elAabb.right - prev.globalAabb.width;
|
|
15596
|
+
elAabb.x = prev.globalAabb.left;
|
|
15597
|
+
const parentAabb = prev.getParent()?.globalAabb;
|
|
15598
|
+
if (parentAabb) left -= parentAabb.x;
|
|
15599
|
+
prev.style.left = left;
|
|
15600
|
+
prev.updateGlobalTransform();
|
|
15601
|
+
update();
|
|
15602
|
+
}
|
|
15603
|
+
} else if (center.x > max) {
|
|
15484
15604
|
if (next) {
|
|
15485
15605
|
const left = next.globalAabb.right - elAabb.width;
|
|
15486
15606
|
let _left = elAabb.left;
|
|
@@ -15491,16 +15611,6 @@ var SmartSelection_default = /* @__PURE__ */ defineComponent({
|
|
|
15491
15611
|
next.updateGlobalTransform();
|
|
15492
15612
|
update();
|
|
15493
15613
|
}
|
|
15494
|
-
} else if (center.x > max) {
|
|
15495
|
-
if (prev) {
|
|
15496
|
-
let left = elAabb.right - prev.globalAabb.width;
|
|
15497
|
-
elAabb.x = prev.globalAabb.left;
|
|
15498
|
-
const parentAabb = prev.getParent()?.globalAabb;
|
|
15499
|
-
if (parentAabb) left -= parentAabb.x;
|
|
15500
|
-
prev.style.left = left;
|
|
15501
|
-
prev.updateGlobalTransform();
|
|
15502
|
-
update();
|
|
15503
|
-
}
|
|
15504
15614
|
}
|
|
15505
15615
|
break;
|
|
15506
15616
|
case "vertical":
|
|
@@ -18257,6 +18367,10 @@ var transform_default = definePlugin((editor) => {
|
|
|
18257
18367
|
};
|
|
18258
18368
|
const els = elementSelection.value;
|
|
18259
18369
|
const isMultiple = els.length > 1;
|
|
18370
|
+
if (type === "move" && els.length === 1) {
|
|
18371
|
+
const parent = els[0].getParent();
|
|
18372
|
+
if (parent && parent.style?.display === "flex") return;
|
|
18373
|
+
}
|
|
18260
18374
|
if (type === "move") {
|
|
18261
18375
|
transform.left = Math.round(transform.left);
|
|
18262
18376
|
transform.top = Math.round(transform.top);
|
|
@@ -19319,6 +19433,7 @@ var plugins = [
|
|
|
19319
19433
|
clipboard_default,
|
|
19320
19434
|
doc_default,
|
|
19321
19435
|
edit_default,
|
|
19436
|
+
flexLayout_default,
|
|
19322
19437
|
formatPaint_default,
|
|
19323
19438
|
frame_default,
|
|
19324
19439
|
history_default,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag-to-reorder for children of a flex/auto-layout container.
|
|
3
|
+
*
|
|
4
|
+
* `transform.ts` skips the absolute move for such a child; here we make it
|
|
5
|
+
* follow the cursor (a temporary left/top offset over its flow slot), swap
|
|
6
|
+
* order with its siblings as its centre crosses theirs, and on release drop
|
|
7
|
+
* the offset so it snaps back into its (new) slot.
|
|
8
|
+
*
|
|
9
|
+
* The sibling layout is derived analytically from sizes/gap captured once at
|
|
10
|
+
* drag start + the current children order (the order array updates
|
|
11
|
+
* synchronously on `moveChild`, but the rendered transforms only catch up on
|
|
12
|
+
* the next tick — so reading them back with `getObb` mid-drag is stale and
|
|
13
|
+
* makes the swap oscillate at the boundary). Structural changes run on the raw
|
|
14
|
+
* (non-reactive) nodes, else the canvas hands a Proxy to yoga's embind which
|
|
15
|
+
* throws a Proxy-invariant error and drops the child.
|
|
16
|
+
*/
|
|
17
|
+
declare const _default: import("..").Plugin;
|
|
18
|
+
export default _default;
|
package/dist/typed-plugins.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.0",
|
|
5
5
|
"description": "A headless infinite canvas editor framework built on WebGL rendering, supports exporting to image, video, and PPT. Only the ESM.",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|