@rufous/ui 0.2.54 → 0.2.55

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.
Files changed (3) hide show
  1. package/dist/main.cjs +39 -31
  2. package/dist/main.js +39 -31
  3. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -9706,31 +9706,32 @@ var CustomTaskItem = import_extension_task_item.default.extend({
9706
9706
  }
9707
9707
  }
9708
9708
  if (taskItemDepth === -1) {
9709
- const parentDepth = $from.depth > 0 ? $from.depth - 1 : 0;
9709
+ if ($from.depth < 1) return false;
9710
+ const parentDepth = $from.depth - 1;
9710
9711
  const indexInParent = $from.index(parentDepth);
9711
9712
  if (indexInParent > 0) {
9712
9713
  const prevNode = $from.node(parentDepth).child(indexInParent - 1);
9713
9714
  if (prevNode.type.name === "taskList") {
9714
- const lastTaskItem = prevNode.lastChild;
9715
- if (lastTaskItem) {
9715
+ try {
9716
9716
  const tr = state.tr;
9717
- const paraStart = $from.before($from.depth > 0 ? $from.depth : 1);
9718
- const paraEnd = $from.after($from.depth > 0 ? $from.depth : 1);
9717
+ const paraStart = $from.before($from.depth);
9718
+ const paraEnd = $from.after($from.depth);
9719
9719
  const paraContent = $from.parent.content;
9720
- const taskListStart = $from.before(parentDepth) !== void 0 ? paraStart - 1 : null;
9721
- if (taskListStart !== null) {
9722
- const $taskListEnd = tr.doc.resolve(taskListStart);
9723
- const lastItemParaEnd = $taskListEnd.end($taskListEnd.depth);
9724
- tr.delete(paraStart, paraEnd);
9725
- let insertAt = lastItemParaEnd;
9726
- paraContent.forEach((inline) => {
9727
- tr.insert(insertAt, inline);
9728
- insertAt += inline.nodeSize;
9729
- });
9730
- tr.setSelection(import_prosemirror_state.TextSelection.create(tr.doc, lastItemParaEnd));
9731
- this.editor.view.dispatch(tr);
9732
- return true;
9733
- }
9720
+ const taskListEndPos = paraStart - 1;
9721
+ if (taskListEndPos < 0) return false;
9722
+ const $taskListEnd = tr.doc.resolve(taskListEndPos);
9723
+ const lastItemParaEnd = $taskListEnd.end($taskListEnd.depth);
9724
+ tr.delete(paraStart, paraEnd);
9725
+ let insertAt = lastItemParaEnd;
9726
+ paraContent.forEach((inline) => {
9727
+ tr.insert(insertAt, inline);
9728
+ insertAt += inline.nodeSize;
9729
+ });
9730
+ tr.setSelection(import_prosemirror_state.TextSelection.create(tr.doc, lastItemParaEnd));
9731
+ this.editor.view.dispatch(tr);
9732
+ return true;
9733
+ } catch {
9734
+ return false;
9734
9735
  }
9735
9736
  }
9736
9737
  }
@@ -11657,6 +11658,25 @@ var RufousTextEditor = ({
11657
11658
  if ((event.ctrlKey || event.metaKey) && event.key === "k") {
11658
11659
  event.preventDefault();
11659
11660
  setLinkRef.current?.();
11661
+ return;
11662
+ }
11663
+ if (event.key === " " && editor.isActive("link")) {
11664
+ const { $from } = editor.state.selection;
11665
+ const linkMark = editor.state.schema.marks.link;
11666
+ const parent = $from.parent;
11667
+ let atLinkEnd = false;
11668
+ parent.forEach((child, offset2) => {
11669
+ if (child.isText && child.marks.some((m) => m.type === linkMark)) {
11670
+ const childEnd = offset2 + child.nodeSize;
11671
+ if ($from.parentOffset === childEnd) {
11672
+ atLinkEnd = true;
11673
+ }
11674
+ }
11675
+ });
11676
+ if (atLinkEnd) {
11677
+ event.preventDefault();
11678
+ editor.chain().focus().unsetMark("link").insertContent(" ").run();
11679
+ }
11660
11680
  }
11661
11681
  };
11662
11682
  editor.view.dom.addEventListener("keydown", handleKeyDown);
@@ -11904,18 +11924,6 @@ var RufousTextEditor = ({
11904
11924
  },
11905
11925
  placeholder: "Link text"
11906
11926
  }
11907
- )), /* @__PURE__ */ import_react58.default.createElement("div", { className: "link-modal-field" }, /* @__PURE__ */ import_react58.default.createElement("label", { className: "link-modal-label" }, "Class name"), /* @__PURE__ */ import_react58.default.createElement(
11908
- "input",
11909
- {
11910
- type: "text",
11911
- className: "link-modal-input",
11912
- value: linkClassName,
11913
- onChange: (e) => setLinkClassName(e.target.value),
11914
- onKeyDown: (e) => {
11915
- if (e.key === "Enter") handleLinkSubmit();
11916
- },
11917
- placeholder: ""
11918
- }
11919
11927
  )), /* @__PURE__ */ import_react58.default.createElement("div", { className: "link-modal-checkboxes" }, /* @__PURE__ */ import_react58.default.createElement("label", { className: "link-modal-checkbox" }, /* @__PURE__ */ import_react58.default.createElement(
11920
11928
  "input",
11921
11929
  {
package/dist/main.js CHANGED
@@ -9641,31 +9641,32 @@ var CustomTaskItem = TaskItem.extend({
9641
9641
  }
9642
9642
  }
9643
9643
  if (taskItemDepth === -1) {
9644
- const parentDepth = $from.depth > 0 ? $from.depth - 1 : 0;
9644
+ if ($from.depth < 1) return false;
9645
+ const parentDepth = $from.depth - 1;
9645
9646
  const indexInParent = $from.index(parentDepth);
9646
9647
  if (indexInParent > 0) {
9647
9648
  const prevNode = $from.node(parentDepth).child(indexInParent - 1);
9648
9649
  if (prevNode.type.name === "taskList") {
9649
- const lastTaskItem = prevNode.lastChild;
9650
- if (lastTaskItem) {
9650
+ try {
9651
9651
  const tr = state.tr;
9652
- const paraStart = $from.before($from.depth > 0 ? $from.depth : 1);
9653
- const paraEnd = $from.after($from.depth > 0 ? $from.depth : 1);
9652
+ const paraStart = $from.before($from.depth);
9653
+ const paraEnd = $from.after($from.depth);
9654
9654
  const paraContent = $from.parent.content;
9655
- const taskListStart = $from.before(parentDepth) !== void 0 ? paraStart - 1 : null;
9656
- if (taskListStart !== null) {
9657
- const $taskListEnd = tr.doc.resolve(taskListStart);
9658
- const lastItemParaEnd = $taskListEnd.end($taskListEnd.depth);
9659
- tr.delete(paraStart, paraEnd);
9660
- let insertAt = lastItemParaEnd;
9661
- paraContent.forEach((inline) => {
9662
- tr.insert(insertAt, inline);
9663
- insertAt += inline.nodeSize;
9664
- });
9665
- tr.setSelection(TextSelection.create(tr.doc, lastItemParaEnd));
9666
- this.editor.view.dispatch(tr);
9667
- return true;
9668
- }
9655
+ const taskListEndPos = paraStart - 1;
9656
+ if (taskListEndPos < 0) return false;
9657
+ const $taskListEnd = tr.doc.resolve(taskListEndPos);
9658
+ const lastItemParaEnd = $taskListEnd.end($taskListEnd.depth);
9659
+ tr.delete(paraStart, paraEnd);
9660
+ let insertAt = lastItemParaEnd;
9661
+ paraContent.forEach((inline) => {
9662
+ tr.insert(insertAt, inline);
9663
+ insertAt += inline.nodeSize;
9664
+ });
9665
+ tr.setSelection(TextSelection.create(tr.doc, lastItemParaEnd));
9666
+ this.editor.view.dispatch(tr);
9667
+ return true;
9668
+ } catch {
9669
+ return false;
9669
9670
  }
9670
9671
  }
9671
9672
  }
@@ -11592,6 +11593,25 @@ var RufousTextEditor = ({
11592
11593
  if ((event.ctrlKey || event.metaKey) && event.key === "k") {
11593
11594
  event.preventDefault();
11594
11595
  setLinkRef.current?.();
11596
+ return;
11597
+ }
11598
+ if (event.key === " " && editor.isActive("link")) {
11599
+ const { $from } = editor.state.selection;
11600
+ const linkMark = editor.state.schema.marks.link;
11601
+ const parent = $from.parent;
11602
+ let atLinkEnd = false;
11603
+ parent.forEach((child, offset2) => {
11604
+ if (child.isText && child.marks.some((m) => m.type === linkMark)) {
11605
+ const childEnd = offset2 + child.nodeSize;
11606
+ if ($from.parentOffset === childEnd) {
11607
+ atLinkEnd = true;
11608
+ }
11609
+ }
11610
+ });
11611
+ if (atLinkEnd) {
11612
+ event.preventDefault();
11613
+ editor.chain().focus().unsetMark("link").insertContent(" ").run();
11614
+ }
11595
11615
  }
11596
11616
  };
11597
11617
  editor.view.dom.addEventListener("keydown", handleKeyDown);
@@ -11839,18 +11859,6 @@ var RufousTextEditor = ({
11839
11859
  },
11840
11860
  placeholder: "Link text"
11841
11861
  }
11842
- )), /* @__PURE__ */ React115.createElement("div", { className: "link-modal-field" }, /* @__PURE__ */ React115.createElement("label", { className: "link-modal-label" }, "Class name"), /* @__PURE__ */ React115.createElement(
11843
- "input",
11844
- {
11845
- type: "text",
11846
- className: "link-modal-input",
11847
- value: linkClassName,
11848
- onChange: (e) => setLinkClassName(e.target.value),
11849
- onKeyDown: (e) => {
11850
- if (e.key === "Enter") handleLinkSubmit();
11851
- },
11852
- placeholder: ""
11853
- }
11854
11862
  )), /* @__PURE__ */ React115.createElement("div", { className: "link-modal-checkboxes" }, /* @__PURE__ */ React115.createElement("label", { className: "link-modal-checkbox" }, /* @__PURE__ */ React115.createElement(
11855
11863
  "input",
11856
11864
  {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rufous/ui",
3
3
  "private": false,
4
- "version": "0.2.54",
4
+ "version": "0.2.55",
5
5
  "type": "module",
6
6
  "description": "Experimental: A lightweight React UI component library (Beta)",
7
7
  "style": "./dist/main.css",