mce 0.12.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +52 -25
- package/dist/mixins/4.2.element.d.ts +1 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2187,25 +2187,20 @@ const _4_2_element = defineMixin((editor) => {
|
|
|
2187
2187
|
getAncestorFrame,
|
|
2188
2188
|
getAabb,
|
|
2189
2189
|
getGlobalPointer,
|
|
2190
|
-
selection
|
|
2190
|
+
selection,
|
|
2191
|
+
getScreenCenterOffset,
|
|
2192
|
+
camera,
|
|
2193
|
+
drawboardAabb
|
|
2191
2194
|
} = editor;
|
|
2192
2195
|
function addElement(value, options = {}) {
|
|
2193
2196
|
log("addElement", value, options);
|
|
2194
2197
|
let {
|
|
2195
2198
|
frame,
|
|
2196
|
-
positionToFit,
|
|
2197
2199
|
sizeToFit,
|
|
2198
2200
|
position,
|
|
2199
|
-
inPointerPosition,
|
|
2200
2201
|
active,
|
|
2201
2202
|
regenId
|
|
2202
2203
|
} = options;
|
|
2203
|
-
if (!position && inPointerPosition) {
|
|
2204
|
-
position = getGlobalPointer();
|
|
2205
|
-
}
|
|
2206
|
-
if (position) {
|
|
2207
|
-
positionToFit = false;
|
|
2208
|
-
}
|
|
2209
2204
|
if (!frame) {
|
|
2210
2205
|
if (config.value.viewMode === "frame") {
|
|
2211
2206
|
frame = currentFrame.value;
|
|
@@ -2220,8 +2215,28 @@ const _4_2_element = defineMixin((editor) => {
|
|
|
2220
2215
|
}
|
|
2221
2216
|
}
|
|
2222
2217
|
}
|
|
2223
|
-
let
|
|
2224
|
-
|
|
2218
|
+
let initPos;
|
|
2219
|
+
switch (position) {
|
|
2220
|
+
case "screenCenter": {
|
|
2221
|
+
const screenCenterOffset = getScreenCenterOffset();
|
|
2222
|
+
const { zoom, position: position2 } = camera.value;
|
|
2223
|
+
const centerOffset = {
|
|
2224
|
+
x: position2.x + screenCenterOffset.left + (drawboardAabb.value.width - screenCenterOffset.left - screenCenterOffset.right) / 2,
|
|
2225
|
+
y: position2.y + screenCenterOffset.top + (drawboardAabb.value.height - screenCenterOffset.top - screenCenterOffset.bottom) / 2
|
|
2226
|
+
};
|
|
2227
|
+
initPos = {
|
|
2228
|
+
x: centerOffset.x * zoom.x,
|
|
2229
|
+
y: centerOffset.y * zoom.y
|
|
2230
|
+
};
|
|
2231
|
+
break;
|
|
2232
|
+
}
|
|
2233
|
+
case "fit":
|
|
2234
|
+
initPos = {
|
|
2235
|
+
x: rootAabb.value.left + rootAabb.value.width + config.value.frameGap,
|
|
2236
|
+
y: rootAabb.value.top
|
|
2237
|
+
};
|
|
2238
|
+
break;
|
|
2239
|
+
}
|
|
2225
2240
|
const isArray = Array.isArray(value);
|
|
2226
2241
|
let offsetX = 0;
|
|
2227
2242
|
const elements = doc.value.transact(() => {
|
|
@@ -2250,15 +2265,15 @@ const _4_2_element = defineMixin((editor) => {
|
|
|
2250
2265
|
}
|
|
2251
2266
|
);
|
|
2252
2267
|
}
|
|
2253
|
-
if (
|
|
2268
|
+
if (position === "fit") {
|
|
2254
2269
|
el.style.left = Math.round(width - el.style.width) / 2;
|
|
2255
2270
|
el.style.top = Math.round(height - el.style.height) / 2;
|
|
2256
2271
|
}
|
|
2257
2272
|
} else {
|
|
2258
|
-
if (
|
|
2259
|
-
el.style.top = Math.round(
|
|
2260
|
-
el.style.left = Math.round(
|
|
2261
|
-
|
|
2273
|
+
if (initPos) {
|
|
2274
|
+
el.style.top = Math.round(initPos.x);
|
|
2275
|
+
el.style.left = Math.round(initPos.y);
|
|
2276
|
+
initPos.x += el.style.height + config.value.frameGap;
|
|
2262
2277
|
}
|
|
2263
2278
|
}
|
|
2264
2279
|
el.style.left += offsetX;
|
|
@@ -2266,10 +2281,11 @@ const _4_2_element = defineMixin((editor) => {
|
|
|
2266
2281
|
return el;
|
|
2267
2282
|
});
|
|
2268
2283
|
const aabb = getAabb(elements2);
|
|
2269
|
-
if (position) {
|
|
2284
|
+
if (position === "pointer") {
|
|
2285
|
+
const pointer = getGlobalPointer();
|
|
2270
2286
|
const diff = {
|
|
2271
|
-
x: Math.round(
|
|
2272
|
-
y: Math.round(
|
|
2287
|
+
x: Math.round(pointer.x - aabb.left),
|
|
2288
|
+
y: Math.round(pointer.y - aabb.top)
|
|
2273
2289
|
};
|
|
2274
2290
|
elements2.forEach((el) => {
|
|
2275
2291
|
el.style.left += diff.x;
|
|
@@ -2574,8 +2590,8 @@ const _scroll$1 = defineMixin((editor) => {
|
|
|
2574
2590
|
}
|
|
2575
2591
|
position = { x: aabb.left + aabb.width / 2, y: aabb.top + aabb.height / 2 };
|
|
2576
2592
|
offset2.x -= screenCenterOffset.left;
|
|
2577
|
-
offset2.y -= screenCenterOffset.top;
|
|
2578
2593
|
offset2.x -= (drawboardAabb.value.width - screenCenterOffset.left - screenCenterOffset.right) / 2;
|
|
2594
|
+
offset2.y -= screenCenterOffset.top;
|
|
2579
2595
|
offset2.y -= (drawboardAabb.value.height - screenCenterOffset.top - screenCenterOffset.bottom) / 2;
|
|
2580
2596
|
}
|
|
2581
2597
|
position.x *= _camera.zoom.x;
|
|
@@ -4233,7 +4249,7 @@ const _clipboard = definePlugin((editor, options) => {
|
|
|
4233
4249
|
}
|
|
4234
4250
|
if (elements.length) {
|
|
4235
4251
|
addElement(elements, {
|
|
4236
|
-
|
|
4252
|
+
position: "pointer",
|
|
4237
4253
|
active: true,
|
|
4238
4254
|
regenId: true
|
|
4239
4255
|
});
|
|
@@ -4254,6 +4270,17 @@ const _clipboard = definePlugin((editor, options) => {
|
|
|
4254
4270
|
}
|
|
4255
4271
|
break;
|
|
4256
4272
|
}
|
|
4273
|
+
case "string":
|
|
4274
|
+
switch (item.type) {
|
|
4275
|
+
case "application/json": {
|
|
4276
|
+
const json = await new Promise((r) => item.getAsString(r));
|
|
4277
|
+
const blob = new Blob([json], { type: item.type });
|
|
4278
|
+
const file = new File([blob], "data.json", { type: item.type });
|
|
4279
|
+
items.push(new ClipboardItem({ [item.type]: file }));
|
|
4280
|
+
break;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
break;
|
|
4257
4284
|
}
|
|
4258
4285
|
}
|
|
4259
4286
|
} else {
|
|
@@ -4273,7 +4300,7 @@ const _clipboard = definePlugin((editor, options) => {
|
|
|
4273
4300
|
} else if (copiedData.value) {
|
|
4274
4301
|
if (Array.isArray(copiedData.value)) {
|
|
4275
4302
|
addElement(copiedData.value?.map((el) => cloneDeep(el)) ?? [], {
|
|
4276
|
-
|
|
4303
|
+
position: "pointer",
|
|
4277
4304
|
active: true,
|
|
4278
4305
|
regenId: true
|
|
4279
4306
|
});
|
|
@@ -4669,7 +4696,7 @@ const _image = definePlugin((editor) => {
|
|
|
4669
4696
|
const insertImage = async (url, options) => {
|
|
4670
4697
|
return addElement(await createImageElement(url), {
|
|
4671
4698
|
sizeToFit: true,
|
|
4672
|
-
|
|
4699
|
+
position: "fit",
|
|
4673
4700
|
...options
|
|
4674
4701
|
});
|
|
4675
4702
|
};
|
|
@@ -4748,7 +4775,7 @@ const _import = definePlugin((editor) => {
|
|
|
4748
4775
|
return addElement((await Promise.all(files.map((file) => load(file)))).flat(), {
|
|
4749
4776
|
...options,
|
|
4750
4777
|
sizeToFit: true,
|
|
4751
|
-
|
|
4778
|
+
position: "fit"
|
|
4752
4779
|
});
|
|
4753
4780
|
};
|
|
4754
4781
|
return {
|
|
@@ -5384,7 +5411,7 @@ const _text = definePlugin((editor) => {
|
|
|
5384
5411
|
const { style, ...restOptions } = options;
|
|
5385
5412
|
return addElement(createTextElement(content, style), {
|
|
5386
5413
|
sizeToFit: true,
|
|
5387
|
-
|
|
5414
|
+
position: "fit",
|
|
5388
5415
|
...restOptions
|
|
5389
5416
|
});
|
|
5390
5417
|
};
|
|
@@ -5,10 +5,8 @@ declare global {
|
|
|
5
5
|
namespace Mce {
|
|
6
6
|
interface AddElementOptions {
|
|
7
7
|
frame?: Element2D;
|
|
8
|
-
positionToFit?: boolean;
|
|
9
8
|
sizeToFit?: boolean;
|
|
10
|
-
position?: Vector2Data;
|
|
11
|
-
inPointerPosition?: boolean;
|
|
9
|
+
position?: Vector2Data | 'fit' | 'screenCenter' | 'pointer';
|
|
12
10
|
active?: boolean;
|
|
13
11
|
regenId?: boolean;
|
|
14
12
|
}
|