@kaitify/core 0.0.1-beta.33 → 0.0.1-beta.35

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.
@@ -6095,6 +6095,8 @@ const imageResizable = (editor) => {
6095
6095
  enabled: true,
6096
6096
  //指定可以调整大小的边缘
6097
6097
  edges: { left: false, right: true, bottom: false, top: false },
6098
+ //设置可拖拽区域宽度
6099
+ margin: 5,
6098
6100
  //设置鼠标样式
6099
6101
  cursorChecker() {
6100
6102
  return editor.isEditable() ? "ew-resize" : "default";
@@ -6263,6 +6265,8 @@ const videoResizable = (editor) => {
6263
6265
  enabled: true,
6264
6266
  //指定可以调整大小的边缘
6265
6267
  edges: { left: false, right: true, bottom: false, top: false },
6268
+ //设置可拖拽区域宽度
6269
+ margin: 5,
6266
6270
  //设置鼠标样式
6267
6271
  cursorChecker() {
6268
6272
  return editor.isEditable() ? "ew-resize" : "default";
@@ -7484,6 +7488,34 @@ const IndentExtension = () => Extension.create({
7484
7488
  };
7485
7489
  }
7486
7490
  });
7491
+ const horizontalFocus = (editor) => {
7492
+ event.off(editor.$el, "click.horizontal_focus");
7493
+ event.on(editor.$el, "click.horizontal_focus", (e) => {
7494
+ if (!editor.isEditable()) {
7495
+ return;
7496
+ }
7497
+ const event2 = e;
7498
+ const elm = event2.target;
7499
+ if (elm === editor.$el) {
7500
+ return;
7501
+ }
7502
+ const node = editor.findNode(elm);
7503
+ const matchNode = node.getMatchNode({
7504
+ tag: "hr"
7505
+ });
7506
+ if (matchNode) {
7507
+ const nextSelectionNode = editor.getNextSelectionNode(matchNode);
7508
+ const previousSelectionNode = editor.getPreviousSelectionNode(matchNode);
7509
+ if (nextSelectionNode) {
7510
+ editor.setSelectionBefore(nextSelectionNode, "all");
7511
+ editor.updateRealSelection();
7512
+ } else if (previousSelectionNode) {
7513
+ editor.setSelectionAfter(previousSelectionNode, "all");
7514
+ editor.updateRealSelection();
7515
+ }
7516
+ }
7517
+ });
7518
+ };
7487
7519
  const HorizontalExtension = () => Extension.create({
7488
7520
  name: "horizontal",
7489
7521
  extraKeepTags: ["hr"],
@@ -7494,17 +7526,58 @@ const HorizontalExtension = () => Extension.create({
7494
7526
  return node;
7495
7527
  },
7496
7528
  formatRules: [
7497
- ({ node }) => {
7529
+ ({ editor, node }) => {
7498
7530
  if (node.isMatch({ tag: "hr" })) {
7499
7531
  node.type = "closed";
7532
+ if (node.hasMarks()) {
7533
+ node.marks["contenteditable"] = "false";
7534
+ } else {
7535
+ node.marks = {
7536
+ contenteditable: "false"
7537
+ };
7538
+ }
7539
+ const previousNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
7540
+ const nextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
7541
+ if (!previousNode || !previousNode.isZeroWidthText()) {
7542
+ const zeroWidthText = KNode.createZeroWidthText();
7543
+ editor.addNodeBefore(zeroWidthText, node);
7544
+ }
7545
+ if (!nextNode || !nextNode.isZeroWidthText()) {
7546
+ const zeroWidthText = KNode.createZeroWidthText();
7547
+ editor.addNodeAfter(zeroWidthText, node);
7548
+ }
7549
+ if (editor.isSelectionInTargetNode(node, "start")) {
7550
+ if (editor.selection.start && editor.selection.start.offset === 0) {
7551
+ const newTextNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
7552
+ if (newTextNode) editor.setSelectionAfter(newTextNode, "start");
7553
+ } else {
7554
+ const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
7555
+ if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
7556
+ }
7557
+ }
7558
+ if (editor.isSelectionInTargetNode(node, "end")) {
7559
+ if (editor.selection.end && editor.selection.end.offset === 0) {
7560
+ const newTextNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
7561
+ if (newTextNode) editor.setSelectionAfter(newTextNode, "end");
7562
+ } else {
7563
+ const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
7564
+ if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
7565
+ }
7566
+ }
7500
7567
  }
7501
7568
  }
7502
7569
  ],
7570
+ afterUpdateView() {
7571
+ horizontalFocus(this);
7572
+ },
7503
7573
  addCommands() {
7504
7574
  const setHorizontal = async () => {
7505
7575
  const node = KNode.create({
7506
7576
  type: "closed",
7507
- tag: "hr"
7577
+ tag: "hr",
7578
+ marks: {
7579
+ contenteditable: "false"
7580
+ }
7508
7581
  });
7509
7582
  this.insertNode(node);
7510
7583
  await this.updateView();
@@ -22727,9 +22800,13 @@ const mathFocus = (editor) => {
22727
22800
  }
22728
22801
  });
22729
22802
  if (matchNode) {
22730
- editor.setSelectionBefore(matchNode, "start");
22731
- editor.setSelectionAfter(matchNode, "end");
22732
- editor.updateRealSelection();
22803
+ const previousNode = editor.getPreviousSelectionNode(matchNode);
22804
+ const nextNode = editor.getNextSelectionNode(matchNode);
22805
+ if (previousNode && nextNode) {
22806
+ editor.setSelectionAfter(previousNode, "start");
22807
+ editor.setSelectionBefore(nextNode, "end");
22808
+ editor.updateRealSelection();
22809
+ }
22733
22810
  }
22734
22811
  });
22735
22812
  };
@@ -22813,9 +22890,7 @@ const MathExtension = () => Extension.create({
22813
22890
  }
22814
22891
  }
22815
22892
  });
22816
- if (node.marks["contenteditable"] != "false") {
22817
- node.marks["contenteditable"] = "false";
22818
- }
22893
+ node.marks["contenteditable"] = "false";
22819
22894
  const previousNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
22820
22895
  const nextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22821
22896
  if (!previousNode || !previousNode.isZeroWidthText()) {
@@ -22827,12 +22902,24 @@ const MathExtension = () => Extension.create({
22827
22902
  editor.addNodeAfter(zeroWidthText, node);
22828
22903
  }
22829
22904
  if (editor.isSelectionInTargetNode(node, "start")) {
22830
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22831
- if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
22905
+ const firstNode = editor.getFirstSelectionNode(node);
22906
+ if (firstNode && editor.selection.start && firstNode.isEqual(editor.selection.start.node) && editor.selection.start.offset === 0) {
22907
+ const newTextNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
22908
+ if (newTextNode) editor.setSelectionAfter(newTextNode, "start");
22909
+ } else {
22910
+ const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22911
+ if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
22912
+ }
22832
22913
  }
22833
22914
  if (editor.isSelectionInTargetNode(node, "end")) {
22834
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22835
- if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
22915
+ const firstNode = editor.getFirstSelectionNode(node);
22916
+ if (firstNode && editor.selection.end && firstNode.isEqual(editor.selection.end.node) && editor.selection.end.offset === 0) {
22917
+ const newTextNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
22918
+ if (newTextNode) editor.setSelectionAfter(newTextNode, "end");
22919
+ } else {
22920
+ const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22921
+ if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
22922
+ }
22836
22923
  }
22837
22924
  }
22838
22925
  }
@@ -35383,9 +35470,13 @@ const attachmentFocus = (editor) => {
35383
35470
  }
35384
35471
  });
35385
35472
  if (matchNode) {
35386
- editor.setSelectionBefore(matchNode, "start");
35387
- editor.setSelectionAfter(matchNode, "end");
35388
- editor.updateRealSelection();
35473
+ const previousNode = editor.getPreviousSelectionNode(matchNode);
35474
+ const nextNode = editor.getNextSelectionNode(matchNode);
35475
+ if (previousNode && nextNode) {
35476
+ editor.setSelectionAfter(previousNode, "start");
35477
+ editor.setSelectionBefore(nextNode, "end");
35478
+ editor.updateRealSelection();
35479
+ }
35389
35480
  }
35390
35481
  });
35391
35482
  };
@@ -35442,9 +35533,7 @@ const AttachmentExtension = (props) => Extension.create({
35442
35533
  }
35443
35534
  }
35444
35535
  });
35445
- if (node.marks["contenteditable"] != "false") {
35446
- node.marks["contenteditable"] = "false";
35447
- }
35536
+ node.marks["contenteditable"] = "false";
35448
35537
  const previousNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
35449
35538
  const nextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35450
35539
  if (!previousNode || !previousNode.isZeroWidthText()) {
@@ -35456,12 +35545,22 @@ const AttachmentExtension = (props) => Extension.create({
35456
35545
  editor.addNodeAfter(zeroWidthText, node);
35457
35546
  }
35458
35547
  if (editor.isSelectionInTargetNode(node, "start")) {
35459
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35460
- if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
35548
+ if (editor.selection.start && editor.selection.start.offset === 0) {
35549
+ const newTextNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
35550
+ if (newTextNode) editor.setSelectionAfter(newTextNode, "start");
35551
+ } else {
35552
+ const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35553
+ if (newTextNode) editor.setSelectionBefore(newTextNode, "start");
35554
+ }
35461
35555
  }
35462
35556
  if (editor.isSelectionInTargetNode(node, "end")) {
35463
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35464
- if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
35557
+ if (editor.selection.end && editor.selection.end.offset === 0) {
35558
+ const newTextNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
35559
+ if (newTextNode) editor.setSelectionAfter(newTextNode, "end");
35560
+ } else {
35561
+ const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35562
+ if (newTextNode) editor.setSelectionBefore(newTextNode, "end");
35563
+ }
35465
35564
  }
35466
35565
  }
35467
35566
  }
@@ -35833,6 +35932,8 @@ const tableResizable = (editor) => {
35833
35932
  enabled: true,
35834
35933
  //指定可以调整大小的边缘
35835
35934
  edges: { left: false, right: true, bottom: false, top: false },
35935
+ //设置可拖拽区域宽度
35936
+ margin: 5,
35836
35937
  //设置鼠标样式
35837
35938
  cursorChecker(_action, _interactable, element2, _interacting) {
35838
35939
  return editor.isEditable() && element2.nextElementSibling ? "ew-resize" : "default";