@kaitify/core 0.0.1-beta.34 → 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.
@@ -7488,6 +7488,34 @@ const IndentExtension = () => Extension.create({
7488
7488
  };
7489
7489
  }
7490
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
+ };
7491
7519
  const HorizontalExtension = () => Extension.create({
7492
7520
  name: "horizontal",
7493
7521
  extraKeepTags: ["hr"],
@@ -7498,17 +7526,58 @@ const HorizontalExtension = () => Extension.create({
7498
7526
  return node;
7499
7527
  },
7500
7528
  formatRules: [
7501
- ({ node }) => {
7529
+ ({ editor, node }) => {
7502
7530
  if (node.isMatch({ tag: "hr" })) {
7503
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
+ }
7504
7567
  }
7505
7568
  }
7506
7569
  ],
7570
+ afterUpdateView() {
7571
+ horizontalFocus(this);
7572
+ },
7507
7573
  addCommands() {
7508
7574
  const setHorizontal = async () => {
7509
7575
  const node = KNode.create({
7510
7576
  type: "closed",
7511
- tag: "hr"
7577
+ tag: "hr",
7578
+ marks: {
7579
+ contenteditable: "false"
7580
+ }
7512
7581
  });
7513
7582
  this.insertNode(node);
7514
7583
  await this.updateView();
@@ -22731,9 +22800,13 @@ const mathFocus = (editor) => {
22731
22800
  }
22732
22801
  });
22733
22802
  if (matchNode) {
22734
- editor.setSelectionBefore(matchNode, "start");
22735
- editor.setSelectionAfter(matchNode, "end");
22736
- 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
+ }
22737
22810
  }
22738
22811
  });
22739
22812
  };
@@ -22817,9 +22890,7 @@ const MathExtension = () => Extension.create({
22817
22890
  }
22818
22891
  }
22819
22892
  });
22820
- if (node.marks["contenteditable"] != "false") {
22821
- node.marks["contenteditable"] = "false";
22822
- }
22893
+ node.marks["contenteditable"] = "false";
22823
22894
  const previousNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
22824
22895
  const nextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22825
22896
  if (!previousNode || !previousNode.isZeroWidthText()) {
@@ -22831,12 +22902,24 @@ const MathExtension = () => Extension.create({
22831
22902
  editor.addNodeAfter(zeroWidthText, node);
22832
22903
  }
22833
22904
  if (editor.isSelectionInTargetNode(node, "start")) {
22834
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22835
- 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
+ }
22836
22913
  }
22837
22914
  if (editor.isSelectionInTargetNode(node, "end")) {
22838
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
22839
- 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
+ }
22840
22923
  }
22841
22924
  }
22842
22925
  }
@@ -35387,9 +35470,13 @@ const attachmentFocus = (editor) => {
35387
35470
  }
35388
35471
  });
35389
35472
  if (matchNode) {
35390
- editor.setSelectionBefore(matchNode, "start");
35391
- editor.setSelectionAfter(matchNode, "end");
35392
- 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
+ }
35393
35480
  }
35394
35481
  });
35395
35482
  };
@@ -35446,9 +35533,7 @@ const AttachmentExtension = (props) => Extension.create({
35446
35533
  }
35447
35534
  }
35448
35535
  });
35449
- if (node.marks["contenteditable"] != "false") {
35450
- node.marks["contenteditable"] = "false";
35451
- }
35536
+ node.marks["contenteditable"] = "false";
35452
35537
  const previousNode = node.getPrevious(node.parent ? node.parent.children : editor.stackNodes);
35453
35538
  const nextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35454
35539
  if (!previousNode || !previousNode.isZeroWidthText()) {
@@ -35460,12 +35545,22 @@ const AttachmentExtension = (props) => Extension.create({
35460
35545
  editor.addNodeAfter(zeroWidthText, node);
35461
35546
  }
35462
35547
  if (editor.isSelectionInTargetNode(node, "start")) {
35463
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35464
- 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
+ }
35465
35555
  }
35466
35556
  if (editor.isSelectionInTargetNode(node, "end")) {
35467
- const newTextNode = node.getNext(node.parent ? node.parent.children : editor.stackNodes);
35468
- 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
+ }
35469
35564
  }
35470
35565
  }
35471
35566
  }