mce 0.15.4 → 0.15.6

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.css CHANGED
@@ -204,6 +204,7 @@
204
204
  .mce-layer__name {
205
205
  position: relative;
206
206
  flex: 1;
207
+ overscroll-behavior: none;
207
208
  }
208
209
  .mce-layer__input {
209
210
  position: absolute;
@@ -219,11 +220,20 @@
219
220
  border-radius: 2px;
220
221
  }
221
222
  .mce-layer__action {
223
+ position: sticky;
224
+ right: 0;
222
225
  flex: none;
223
226
  display: flex;
224
227
  align-items: center;
228
+ background-color: var(--overlay-color, transparent);
229
+ backdrop-filter: blur(8px);
230
+ border-radius: 4px;
231
+ }
232
+ .mce-layer__action--hide {
233
+ background-color: transparent;
234
+ backdrop-filter: none;
225
235
  }
226
- .mce-layer__btn--hide {
236
+ .mce-layer__action--hide .mce-layer__btn {
227
237
  opacity: 0;
228
238
  }
229
239
  .mce-layer__btn + .mce-layer__btn {
package/dist/index.js CHANGED
@@ -693,10 +693,6 @@ class Doc extends Model {
693
693
  }
694
694
  this.transact(() => {
695
695
  this._debug(`addChild ${child.id}`, child.name, newIndex);
696
- if (!isReactive(child)) {
697
- child = reactive(child);
698
- node.children[newIndex] = child;
699
- }
700
696
  this._proxyNode(child);
701
697
  childrenIds.insert(newIndex, [child.id]);
702
698
  });
@@ -788,6 +784,12 @@ class Doc extends Model {
788
784
  this.undoManager.addToScope(yNode);
789
785
  }
790
786
  if (!this._nodeMap.has(id)) {
787
+ if (!isReactive(node)) {
788
+ node = reactive(node);
789
+ if (node.parent) {
790
+ node.parent.children[node.getIndex()] = node;
791
+ }
792
+ }
791
793
  this._nodeMap.set(id, node);
792
794
  yNode.set("parentId", node.parent?.id);
793
795
  node.on("parented", () => {
@@ -937,7 +939,7 @@ const _0_context = defineMixin((editor) => {
937
939
  function isFrame(value) {
938
940
  return isElement(value) && value.meta.inEditorIs === "Frame";
939
941
  }
940
- function isRootFrame(value) {
942
+ function isTopLevelFrame(value) {
941
943
  return isFrame(value) && Boolean(value.parent?.equal(root.value));
942
944
  }
943
945
  function isVisible(node) {
@@ -980,7 +982,7 @@ const _0_context = defineMixin((editor) => {
980
982
  isRoot,
981
983
  isElement,
982
984
  isFrame,
983
- isRootFrame,
985
+ isTopLevelFrame,
984
986
  isVisible,
985
987
  setVisible,
986
988
  isLock,
@@ -2539,7 +2541,8 @@ const _4_2_frame = defineMixin((editor) => {
2539
2541
  emit,
2540
2542
  selection,
2541
2543
  frames,
2542
- config
2544
+ config,
2545
+ isTopLevelFrame
2543
2546
  } = editor;
2544
2547
  function setCurrentFrame(index = currentFrameIndex.value) {
2545
2548
  index = Math.max(0, Math.min(frames.value.length - 1, index));
@@ -2553,31 +2556,32 @@ const _4_2_frame = defineMixin((editor) => {
2553
2556
  emit("setCurrentFrame", index, oldIndex);
2554
2557
  }
2555
2558
  function handleElementInsideFrame(element) {
2556
- const source = element.getGlobalAabb();
2557
- const aArea = source.getArea();
2559
+ const frame1 = element.findAncestor((node) => isTopLevelFrame(node));
2560
+ const aabb1 = element.getGlobalAabb();
2561
+ const area1 = aabb1.getArea();
2558
2562
  let flag = true;
2559
2563
  for (let i = 0, len = frames.value.length; i < len; i++) {
2560
- const frame = frames.value[i];
2561
- if (element.equal(frame)) {
2564
+ const frame2 = frames.value[i];
2565
+ if (frame2.equal(element)) {
2562
2566
  continue;
2563
2567
  }
2564
- const target = frame.getGlobalAabb();
2565
- if (source && target) {
2566
- if (source.getIntersectionRect(target).getArea() > aArea * 0.5) {
2567
- if (!element.findAncestor((ancestor) => ancestor.equal(frame))) {
2568
- frame.appendChild(element);
2569
- element.style.left = source.x - target.x;
2570
- element.style.top = source.y - target.y;
2568
+ const aabb2 = frame2.getGlobalAabb();
2569
+ if (aabb1 && aabb2) {
2570
+ if (aabb1.getIntersectionRect(aabb2).getArea() > area1 * 0.5) {
2571
+ if (!frame2.equal(frame1)) {
2572
+ frame2.appendChild(element);
2573
+ element.style.left = aabb1.x - aabb2.x;
2574
+ element.style.top = aabb1.y - aabb2.y;
2571
2575
  }
2572
2576
  flag = false;
2573
2577
  break;
2574
2578
  }
2575
2579
  }
2576
2580
  }
2577
- if (flag && element.parent && !element.parent.equal(root.value)) {
2581
+ if (flag && frame1) {
2578
2582
  root.value.moveChild(element, 0);
2579
- element.style.left = source.x;
2580
- element.style.top = source.y;
2583
+ element.style.left = aabb1.x;
2584
+ element.style.top = aabb1.y;
2581
2585
  }
2582
2586
  }
2583
2587
  Object.assign(editor, {
@@ -4270,7 +4274,7 @@ const defaultDoubleclickStrategy = (context) => {
4270
4274
  const { editor } = context;
4271
4275
  const { elementSelection } = editor;
4272
4276
  const element = elementSelection.value[0];
4273
- if (element) {
4277
+ if (element && !element.meta.lock) {
4274
4278
  return element.foreground.isValid() ? void 0 : "typing";
4275
4279
  }
4276
4280
  return void 0;
@@ -4401,7 +4405,8 @@ const _frame = definePlugin((editor) => {
4401
4405
  name: t("frame"),
4402
4406
  meta: {
4403
4407
  inPptIs: "GroupShape",
4404
- inEditorIs: "Frame"
4408
+ inEditorIs: "Frame",
4409
+ inCanvasIs: "Element2D"
4405
4410
  }
4406
4411
  }, {
4407
4412
  position: start,
@@ -5044,7 +5049,6 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
5044
5049
  const _hoisted_1$l = ["data-id"];
5045
5050
  const _hoisted_2$c = { class: "mce-layer__content" };
5046
5051
  const _hoisted_3$b = { class: "mce-layer__prepend" };
5047
- const _hoisted_4$5 = { class: "mce-layer__action" };
5048
5052
  const _sfc_main$x = /* @__PURE__ */ defineComponent({
5049
5053
  ...{
5050
5054
  name: "MceLayer",
@@ -5109,6 +5113,8 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5109
5113
  return false;
5110
5114
  });
5111
5115
  const isActive = computed(() => selection.value.some((v) => v.equal(props.node)));
5116
+ const children = computed(() => props.node.children);
5117
+ const childrenLength = computed(() => children.value.length);
5112
5118
  const inputDom = ref();
5113
5119
  const isHoverElement = computed(() => props.node?.equal(hoverElement.value));
5114
5120
  const hovering = ref(false);
@@ -5130,6 +5136,18 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5130
5136
  }
5131
5137
  return "$shape";
5132
5138
  });
5139
+ const thumbnailName = computed(() => {
5140
+ const node = props.node;
5141
+ let value = node.name;
5142
+ if (!value) {
5143
+ if (isElement(node)) {
5144
+ if (node.text.isValid()) {
5145
+ value = node.text.getStringContent();
5146
+ }
5147
+ }
5148
+ }
5149
+ return value || node.id;
5150
+ });
5133
5151
  function onClickExpand() {
5134
5152
  opened.value = !opened.value;
5135
5153
  }
@@ -5190,11 +5208,11 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5190
5208
  }
5191
5209
  function onDblclickName() {
5192
5210
  editing.value = true;
5193
- editValue.value = props.node.name;
5211
+ editValue.value = thumbnailName.value;
5194
5212
  nextTick().then(() => {
5195
5213
  const dom2 = inputDom.value;
5196
5214
  if (dom2) {
5197
- dom2.focus();
5215
+ dom2.focus({ preventScroll: true });
5198
5216
  dom2.select();
5199
5217
  }
5200
5218
  });
@@ -5217,10 +5235,8 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5217
5235
  }
5218
5236
  function onInputBlur() {
5219
5237
  editing.value = false;
5220
- if (editValue.value) {
5221
- props.node.name = editValue.value;
5222
- editValue.value = void 0;
5223
- }
5238
+ props.node.name = editValue.value;
5239
+ editValue.value = "";
5224
5240
  }
5225
5241
  return (_ctx, _cache) => {
5226
5242
  const _component_MceLayer = resolveComponent("MceLayer");
@@ -5250,7 +5266,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5250
5266
  _cache[6] || (_cache[6] = createElementVNode("span", { class: "mce-layer__overlay" }, null, -1)),
5251
5267
  createElementVNode("div", _hoisted_2$c, [
5252
5268
  createElementVNode("div", _hoisted_3$b, [
5253
- props.node.children.length ? (openBlock(), createBlock(unref(_sfc_main$C), {
5269
+ childrenLength.value ? (openBlock(), createBlock(unref(_sfc_main$C), {
5254
5270
  key: 0,
5255
5271
  icon: "$arrowRight",
5256
5272
  onClick: onClickExpand,
@@ -5282,15 +5298,17 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5282
5298
  ]),
5283
5299
  createElementVNode("div", {
5284
5300
  style: normalizeStyle({ visibility: editing.value ? "hidden" : void 0 })
5285
- }, toDisplayString(editValue.value || props.node.name || props.node.id), 5)
5301
+ }, toDisplayString(editValue.value || thumbnailName.value), 5)
5286
5302
  ], 32),
5287
- createElementVNode("div", _hoisted_4$5, [
5303
+ createElementVNode("div", {
5304
+ class: normalizeClass(["mce-layer__action", {
5305
+ "mce-layer__action--hide": !hovering.value && !unref(isLock)(props.node) && unref(isVisible)(props.node)
5306
+ }])
5307
+ }, [
5288
5308
  props.root ? (openBlock(), createBlock(_sfc_main$y, {
5289
5309
  key: 0,
5290
5310
  icon: "",
5291
- class: normalizeClass(["mce-layer__btn", {
5292
- "mce-layer__btn--hide": !hovering.value && !unref(isLock)(props.node)
5293
- }]),
5311
+ class: "mce-layer__btn",
5294
5312
  onClick: _cache[2] || (_cache[2] = ($event) => unref(setLock)(props.node, !unref(isLock)(props.node)))
5295
5313
  }, {
5296
5314
  default: withCtx(() => [
@@ -5299,12 +5317,10 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5299
5317
  }, null, 8, ["icon"])
5300
5318
  ]),
5301
5319
  _: 1
5302
- }, 8, ["class"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
5320
+ })) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
5303
5321
  createVNode(_sfc_main$y, {
5304
5322
  icon: "",
5305
- class: normalizeClass(["mce-layer__btn", {
5306
- "mce-layer__btn--hide": !hovering.value && !unref(isLock)(props.node)
5307
- }]),
5323
+ class: "mce-layer__btn",
5308
5324
  onClick: _cache[3] || (_cache[3] = withModifiers(($event) => unref(setLock)(props.node, !unref(isLock)(props.node)), ["prevent", "stop"]))
5309
5325
  }, {
5310
5326
  default: withCtx(() => [
@@ -5313,12 +5329,10 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5313
5329
  }, null, 8, ["icon"])
5314
5330
  ]),
5315
5331
  _: 1
5316
- }, 8, ["class"]),
5332
+ }),
5317
5333
  createVNode(_sfc_main$y, {
5318
5334
  icon: "",
5319
- class: normalizeClass(["mce-layer__btn", {
5320
- "mce-layer__btn--hide": !hovering.value && unref(isVisible)(props.node)
5321
- }]),
5335
+ class: "mce-layer__btn",
5322
5336
  onClick: _cache[4] || (_cache[4] = withModifiers(($event) => unref(setVisible)(props.node, !unref(isVisible)(props.node)), ["prevent", "stop"]))
5323
5337
  }, {
5324
5338
  default: withCtx(() => [
@@ -5327,15 +5341,15 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5327
5341
  }, null, 8, ["icon"])
5328
5342
  ]),
5329
5343
  _: 1
5330
- }, 8, ["class"])
5344
+ })
5331
5345
  ], 64))
5332
- ])
5346
+ ], 2)
5333
5347
  ])
5334
5348
  ], 46, _hoisted_1$l),
5335
- opened.value ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(props.node.children, (child, key) => {
5349
+ opened.value ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(childrenLength.value, (i) => {
5336
5350
  return openBlock(), createBlock(_component_MceLayer, {
5337
- key,
5338
- node: child,
5351
+ key: i,
5352
+ node: children.value[childrenLength.value - i],
5339
5353
  indent: __props.root ? props.indent : props.indent + 1,
5340
5354
  active: __props.active || isActive.value
5341
5355
  }, null, 8, ["node", "indent", "active"]);
@@ -5389,6 +5403,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5389
5403
  if (last) {
5390
5404
  nextTick().then(() => {
5391
5405
  domItems.get(getIdByNode(last) ?? "")?.value?.scrollIntoView({
5406
+ inline: "nearest",
5392
5407
  block: "center"
5393
5408
  });
5394
5409
  });
@@ -15134,7 +15149,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15134
15149
  const {
15135
15150
  pluginsComponents,
15136
15151
  isElement,
15137
- isRootFrame,
15152
+ isTopLevelFrame,
15138
15153
  config,
15139
15154
  drawboardDom,
15140
15155
  renderEngine,
@@ -15213,7 +15228,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15213
15228
  hovered = result;
15214
15229
  }
15215
15230
  }
15216
- if (!(isElement(hovered) && !isRootFrame(hovered))) {
15231
+ if (!(isElement(hovered) && !isTopLevelFrame(hovered))) {
15217
15232
  hovered = void 0;
15218
15233
  cursor = void 0;
15219
15234
  }
@@ -15228,7 +15243,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15228
15243
  allowRootFrame = false
15229
15244
  } = options;
15230
15245
  function isIncluded(node) {
15231
- return isElement(node) && (allowRootFrame || !isRootFrame(node));
15246
+ return isElement(node) && (allowRootFrame || !isTopLevelFrame(node));
15232
15247
  }
15233
15248
  const drawing = state.value === "drawing";
15234
15249
  const hand = state.value === "hand";
@@ -45,7 +45,7 @@ declare global {
45
45
  isRoot: (value: any) => value is Node;
46
46
  isElement: (value: any) => value is Element2D;
47
47
  isFrame: (value: any) => value is Element2D;
48
- isRootFrame: (value: any) => value is Element2D;
48
+ isTopLevelFrame: (value: any) => value is Element2D;
49
49
  isVisible: (node: Node) => boolean;
50
50
  setVisible: (node: Node, visible: boolean) => void;
51
51
  isLock: (node: Node) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.15.4",
4
+ "version": "0.15.6",
5
5
  "description": "The headless canvas editor framework. only the ESM.",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -61,11 +61,11 @@
61
61
  "diff": "^8.0.2",
62
62
  "file-saver": "^2.0.5",
63
63
  "lodash-es": "^4.17.22",
64
- "modern-canvas": "^0.14.19",
64
+ "modern-canvas": "^0.14.22",
65
65
  "modern-font": "^0.4.4",
66
- "modern-idoc": "^0.10.7",
67
- "modern-text": "^1.10.5",
68
- "yjs": "^13.6.27"
66
+ "modern-idoc": "^0.10.8",
67
+ "modern-text": "^1.10.6",
68
+ "yjs": "^13.6.28"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "lottie-web": "^5",
@@ -94,7 +94,7 @@
94
94
  "@vitejs/plugin-vue": "^6.0.3",
95
95
  "jiti": "^2.6.1",
96
96
  "modern-gif": "^2.0.4",
97
- "sass-embedded": "^1.97.0"
97
+ "sass-embedded": "^1.97.1"
98
98
  },
99
99
  "scripts": {
100
100
  "build:code": "vite build",