@rufous/ui 0.2.3 → 0.2.5

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 +73 -69
  2. package/dist/main.js +73 -69
  3. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -41709,29 +41709,28 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41709
41709
  }
41710
41710
  if (taskDepth === -1) {
41711
41711
  if (this.editor.storage.taskTodoEnabled === true) {
41712
- const schema2 = state.schema;
41713
- const taskItemType = schema2.nodes.taskItem;
41714
- const taskListType = schema2.nodes.taskList;
41712
+ const schema = state.schema;
41713
+ const taskItemType = schema.nodes.taskItem;
41714
+ const taskListType = schema.nodes.taskList;
41715
41715
  if (!taskItemType || !taskListType) return false;
41716
- const statusText = schema2.text("Todo");
41717
- const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema2.nodes.paragraph.create(null, statusText));
41716
+ const statusText = schema.text("Todo");
41717
+ const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema.nodes.paragraph.create(null, statusText));
41718
41718
  const newTaskList = taskListType.create(null, newTaskItem);
41719
- const tr2 = state.tr;
41720
- const pos = $from.pos;
41719
+ const tr = state.tr;
41721
41720
  const afterBlock = $from.after($from.depth > 0 ? 1 : 0);
41722
- tr2.insert(afterBlock, newTaskList);
41723
- tr2.setSelection(TextSelection.near(tr2.doc.resolve(afterBlock + 3 + 4)));
41724
- this.editor.view.dispatch(tr2);
41721
+ tr.insert(afterBlock, newTaskList);
41722
+ tr.setSelection(TextSelection.near(tr.doc.resolve(afterBlock + 3 + 4)));
41723
+ this.editor.view.dispatch(tr);
41725
41724
  return true;
41726
41725
  }
41727
41726
  return false;
41728
41727
  }
41729
41728
  if (this.editor.storage.taskTodoEnabled === false) {
41730
- const afterContent2 = $from.parent.content.cut($from.parentOffset);
41731
- const schema2 = state.schema;
41732
- const tr2 = state.tr;
41733
- if (afterContent2.size > 0) {
41734
- tr2.delete($from.pos, $from.end());
41729
+ const afterContent = $from.parent.content.cut($from.parentOffset);
41730
+ const schema = state.schema;
41731
+ const tr = state.tr;
41732
+ if (afterContent.size > 0) {
41733
+ tr.delete($from.pos, $from.end());
41735
41734
  }
41736
41735
  let taskListDepth = -1;
41737
41736
  for (let d = taskDepth - 1; d >= 0; d--) {
@@ -41740,31 +41739,14 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41740
41739
  break;
41741
41740
  }
41742
41741
  }
41743
- const insertPos2 = taskListDepth !== -1 ? tr2.mapping.map($from.after(taskListDepth)) : tr2.mapping.map($from.after(taskDepth));
41744
- const newPara2 = afterContent2.size > 0 ? schema2.nodes.paragraph.create(null, afterContent2) : schema2.nodes.paragraph.create();
41745
- tr2.insert(insertPos2, newPara2);
41746
- tr2.setSelection(TextSelection.near(tr2.doc.resolve(insertPos2 + 1)));
41747
- this.editor.view.dispatch(tr2);
41742
+ const insertPos = taskListDepth !== -1 ? tr.mapping.map($from.after(taskListDepth)) : tr.mapping.map($from.after(taskDepth));
41743
+ const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create();
41744
+ tr.insert(insertPos, newPara);
41745
+ tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 1)));
41746
+ this.editor.view.dispatch(tr);
41748
41747
  return true;
41749
41748
  }
41750
- const taskNode = $from.node(taskDepth);
41751
- const status = taskNode.attrs.status || "todo";
41752
- const schema = state.schema;
41753
- const tr = state.tr;
41754
- const afterContent = $from.parent.content.cut($from.parentOffset);
41755
- if (afterContent.size > 0) {
41756
- tr.delete($from.pos, $from.end());
41757
- }
41758
- const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create();
41759
- const newItem = schema.nodes.taskItem.create(
41760
- { status, checked: false },
41761
- newPara
41762
- );
41763
- const insertPos = tr.mapping.map($from.after(taskDepth));
41764
- tr.insert(insertPos, newItem);
41765
- tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 2)));
41766
- this.editor.view.dispatch(tr);
41767
- return true;
41749
+ return this.editor.commands.splitListItem(this.name);
41768
41750
  },
41769
41751
  Backspace: () => {
41770
41752
  const { state } = this.editor;
@@ -41778,7 +41760,37 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41778
41760
  break;
41779
41761
  }
41780
41762
  }
41781
- if (taskItemDepth === -1) return false;
41763
+ if (taskItemDepth === -1) {
41764
+ const parentDepth = $from.depth > 0 ? $from.depth - 1 : 0;
41765
+ const indexInParent = $from.index(parentDepth);
41766
+ if (indexInParent > 0) {
41767
+ const prevNode = $from.node(parentDepth).child(indexInParent - 1);
41768
+ if (prevNode.type.name === "taskList") {
41769
+ const lastTaskItem = prevNode.lastChild;
41770
+ if (lastTaskItem) {
41771
+ const tr = state.tr;
41772
+ const paraStart = $from.before($from.depth > 0 ? $from.depth : 1);
41773
+ const paraEnd = $from.after($from.depth > 0 ? $from.depth : 1);
41774
+ const paraContent = $from.parent.content;
41775
+ const taskListStart = $from.before(parentDepth) !== void 0 ? paraStart - 1 : null;
41776
+ if (taskListStart !== null) {
41777
+ const $taskListEnd = tr.doc.resolve(taskListStart);
41778
+ const lastItemParaEnd = $taskListEnd.end($taskListEnd.depth);
41779
+ tr.delete(paraStart, paraEnd);
41780
+ let insertAt = lastItemParaEnd;
41781
+ paraContent.forEach((inline) => {
41782
+ tr.insert(insertAt, inline);
41783
+ insertAt += inline.nodeSize;
41784
+ });
41785
+ tr.setSelection(TextSelection.create(tr.doc, lastItemParaEnd));
41786
+ this.editor.view.dispatch(tr);
41787
+ return true;
41788
+ }
41789
+ }
41790
+ }
41791
+ }
41792
+ return false;
41793
+ }
41782
41794
  const taskItem = $from.node(taskItemDepth);
41783
41795
  let taskListDepth = -1;
41784
41796
  for (let d = taskItemDepth - 1; d >= 0; d--) {
@@ -41793,8 +41805,8 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41793
41805
  const from2 = $from.before(taskListDepth);
41794
41806
  const to2 = $from.after(taskListDepth);
41795
41807
  tr2.replaceWith(from2, to2, state.schema.nodes.paragraph.create());
41796
- const resolvedPos = tr2.doc.resolve(from2);
41797
- tr2.setSelection(TextSelection.near(resolvedPos));
41808
+ const resolvedPos2 = tr2.doc.resolve(from2);
41809
+ tr2.setSelection(TextSelection.near(resolvedPos2));
41798
41810
  this.editor.view.dispatch(tr2);
41799
41811
  return true;
41800
41812
  }
@@ -41802,37 +41814,12 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41802
41814
  const from = $from.before(taskItemDepth);
41803
41815
  const to = $from.after(taskItemDepth);
41804
41816
  tr.delete(from, to);
41805
- const prevPos = Math.max(0, from - 1);
41806
- const $prev = tr.doc.resolve(prevPos);
41807
- const cursorPos = $prev.end($prev.depth);
41808
- tr.setSelection(TextSelection.create(tr.doc, cursorPos));
41817
+ const resolvedPos = tr.doc.resolve(Math.max(0, from));
41818
+ tr.setSelection(TextSelection.near(resolvedPos, -1));
41809
41819
  this.editor.view.dispatch(tr);
41810
41820
  return true;
41811
41821
  }
41812
- const indexInList = taskListDepth !== -1 ? $from.index(taskListDepth) : -1;
41813
- if (indexInList > 0 && taskListDepth !== -1) {
41814
- const tr = state.tr;
41815
- const itemStart = $from.before(taskItemDepth);
41816
- const itemEnd = $from.after(taskItemDepth);
41817
- if (tr.doc.resolve(itemStart).nodeBefore) {
41818
- const contentSlice = taskItem.content;
41819
- tr.delete(itemStart, itemEnd);
41820
- const prevPos = Math.max(0, itemStart - 1);
41821
- const $prevEnd = tr.doc.resolve(prevPos);
41822
- const prevParaEnd = $prevEnd.end($prevEnd.depth);
41823
- let insertAt = prevParaEnd;
41824
- contentSlice.forEach((child) => {
41825
- child.content.forEach((inline) => {
41826
- tr.insert(insertAt, inline);
41827
- insertAt += inline.nodeSize;
41828
- });
41829
- });
41830
- tr.setSelection(TextSelection.create(tr.doc, prevParaEnd));
41831
- this.editor.view.dispatch(tr);
41832
- return true;
41833
- }
41834
- }
41835
- return this.editor.commands.liftListItem(this.name);
41822
+ return false;
41836
41823
  },
41837
41824
  "Shift-Tab": () => this.editor.commands.liftListItem(this.name),
41838
41825
  ...this.options.nested ? { Tab: () => this.editor.commands.sinkListItem(this.name) } : {}
@@ -43671,6 +43658,7 @@ var RufousTextEditor = ({
43671
43658
  editor.off("blur", handler);
43672
43659
  };
43673
43660
  }, [editor]);
43661
+ const setLinkRef = (0, import_react59.useRef)(null);
43674
43662
  const [linkModalOpen, setLinkModalOpen] = (0, import_react59.useState)(false);
43675
43663
  const [linkUrl, setLinkUrl] = (0, import_react59.useState)("");
43676
43664
  const [linkText, setLinkText] = (0, import_react59.useState)("");
@@ -43715,6 +43703,22 @@ var RufousTextEditor = ({
43715
43703
  setLinkSelection({ from, to });
43716
43704
  setLinkModalOpen(true);
43717
43705
  }, [editor]);
43706
+ (0, import_react59.useEffect)(() => {
43707
+ setLinkRef.current = setLink;
43708
+ }, [setLink]);
43709
+ (0, import_react59.useEffect)(() => {
43710
+ if (!editor?.view) return;
43711
+ const handleKeyDown = (event) => {
43712
+ if ((event.ctrlKey || event.metaKey) && event.key === "k") {
43713
+ event.preventDefault();
43714
+ setLinkRef.current?.();
43715
+ }
43716
+ };
43717
+ editor.view.dom.addEventListener("keydown", handleKeyDown);
43718
+ return () => {
43719
+ editor.view.dom.removeEventListener("keydown", handleKeyDown);
43720
+ };
43721
+ }, [editor]);
43718
43722
  const handleLinkSubmit = (0, import_react59.useCallback)(() => {
43719
43723
  if (!editor || !linkSelection) return;
43720
43724
  editor.chain().focus().setTextSelection(linkSelection).run();
package/dist/main.js CHANGED
@@ -13039,29 +13039,28 @@ var CustomTaskItem = TaskItem.extend({
13039
13039
  }
13040
13040
  if (taskDepth === -1) {
13041
13041
  if (this.editor.storage.taskTodoEnabled === true) {
13042
- const schema2 = state.schema;
13043
- const taskItemType = schema2.nodes.taskItem;
13044
- const taskListType = schema2.nodes.taskList;
13042
+ const schema = state.schema;
13043
+ const taskItemType = schema.nodes.taskItem;
13044
+ const taskListType = schema.nodes.taskList;
13045
13045
  if (!taskItemType || !taskListType) return false;
13046
- const statusText = schema2.text("Todo");
13047
- const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema2.nodes.paragraph.create(null, statusText));
13046
+ const statusText = schema.text("Todo");
13047
+ const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema.nodes.paragraph.create(null, statusText));
13048
13048
  const newTaskList = taskListType.create(null, newTaskItem);
13049
- const tr2 = state.tr;
13050
- const pos = $from.pos;
13049
+ const tr = state.tr;
13051
13050
  const afterBlock = $from.after($from.depth > 0 ? 1 : 0);
13052
- tr2.insert(afterBlock, newTaskList);
13053
- tr2.setSelection(TextSelection.near(tr2.doc.resolve(afterBlock + 3 + 4)));
13054
- this.editor.view.dispatch(tr2);
13051
+ tr.insert(afterBlock, newTaskList);
13052
+ tr.setSelection(TextSelection.near(tr.doc.resolve(afterBlock + 3 + 4)));
13053
+ this.editor.view.dispatch(tr);
13055
13054
  return true;
13056
13055
  }
13057
13056
  return false;
13058
13057
  }
13059
13058
  if (this.editor.storage.taskTodoEnabled === false) {
13060
- const afterContent2 = $from.parent.content.cut($from.parentOffset);
13061
- const schema2 = state.schema;
13062
- const tr2 = state.tr;
13063
- if (afterContent2.size > 0) {
13064
- tr2.delete($from.pos, $from.end());
13059
+ const afterContent = $from.parent.content.cut($from.parentOffset);
13060
+ const schema = state.schema;
13061
+ const tr = state.tr;
13062
+ if (afterContent.size > 0) {
13063
+ tr.delete($from.pos, $from.end());
13065
13064
  }
13066
13065
  let taskListDepth = -1;
13067
13066
  for (let d = taskDepth - 1; d >= 0; d--) {
@@ -13070,31 +13069,14 @@ var CustomTaskItem = TaskItem.extend({
13070
13069
  break;
13071
13070
  }
13072
13071
  }
13073
- const insertPos2 = taskListDepth !== -1 ? tr2.mapping.map($from.after(taskListDepth)) : tr2.mapping.map($from.after(taskDepth));
13074
- const newPara2 = afterContent2.size > 0 ? schema2.nodes.paragraph.create(null, afterContent2) : schema2.nodes.paragraph.create();
13075
- tr2.insert(insertPos2, newPara2);
13076
- tr2.setSelection(TextSelection.near(tr2.doc.resolve(insertPos2 + 1)));
13077
- this.editor.view.dispatch(tr2);
13072
+ const insertPos = taskListDepth !== -1 ? tr.mapping.map($from.after(taskListDepth)) : tr.mapping.map($from.after(taskDepth));
13073
+ const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create();
13074
+ tr.insert(insertPos, newPara);
13075
+ tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 1)));
13076
+ this.editor.view.dispatch(tr);
13078
13077
  return true;
13079
13078
  }
13080
- const taskNode = $from.node(taskDepth);
13081
- const status = taskNode.attrs.status || "todo";
13082
- const schema = state.schema;
13083
- const tr = state.tr;
13084
- const afterContent = $from.parent.content.cut($from.parentOffset);
13085
- if (afterContent.size > 0) {
13086
- tr.delete($from.pos, $from.end());
13087
- }
13088
- const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create();
13089
- const newItem = schema.nodes.taskItem.create(
13090
- { status, checked: false },
13091
- newPara
13092
- );
13093
- const insertPos = tr.mapping.map($from.after(taskDepth));
13094
- tr.insert(insertPos, newItem);
13095
- tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 2)));
13096
- this.editor.view.dispatch(tr);
13097
- return true;
13079
+ return this.editor.commands.splitListItem(this.name);
13098
13080
  },
13099
13081
  Backspace: () => {
13100
13082
  const { state } = this.editor;
@@ -13108,7 +13090,37 @@ var CustomTaskItem = TaskItem.extend({
13108
13090
  break;
13109
13091
  }
13110
13092
  }
13111
- if (taskItemDepth === -1) return false;
13093
+ if (taskItemDepth === -1) {
13094
+ const parentDepth = $from.depth > 0 ? $from.depth - 1 : 0;
13095
+ const indexInParent = $from.index(parentDepth);
13096
+ if (indexInParent > 0) {
13097
+ const prevNode = $from.node(parentDepth).child(indexInParent - 1);
13098
+ if (prevNode.type.name === "taskList") {
13099
+ const lastTaskItem = prevNode.lastChild;
13100
+ if (lastTaskItem) {
13101
+ const tr = state.tr;
13102
+ const paraStart = $from.before($from.depth > 0 ? $from.depth : 1);
13103
+ const paraEnd = $from.after($from.depth > 0 ? $from.depth : 1);
13104
+ const paraContent = $from.parent.content;
13105
+ const taskListStart = $from.before(parentDepth) !== void 0 ? paraStart - 1 : null;
13106
+ if (taskListStart !== null) {
13107
+ const $taskListEnd = tr.doc.resolve(taskListStart);
13108
+ const lastItemParaEnd = $taskListEnd.end($taskListEnd.depth);
13109
+ tr.delete(paraStart, paraEnd);
13110
+ let insertAt = lastItemParaEnd;
13111
+ paraContent.forEach((inline) => {
13112
+ tr.insert(insertAt, inline);
13113
+ insertAt += inline.nodeSize;
13114
+ });
13115
+ tr.setSelection(TextSelection.create(tr.doc, lastItemParaEnd));
13116
+ this.editor.view.dispatch(tr);
13117
+ return true;
13118
+ }
13119
+ }
13120
+ }
13121
+ }
13122
+ return false;
13123
+ }
13112
13124
  const taskItem = $from.node(taskItemDepth);
13113
13125
  let taskListDepth = -1;
13114
13126
  for (let d = taskItemDepth - 1; d >= 0; d--) {
@@ -13123,8 +13135,8 @@ var CustomTaskItem = TaskItem.extend({
13123
13135
  const from2 = $from.before(taskListDepth);
13124
13136
  const to2 = $from.after(taskListDepth);
13125
13137
  tr2.replaceWith(from2, to2, state.schema.nodes.paragraph.create());
13126
- const resolvedPos = tr2.doc.resolve(from2);
13127
- tr2.setSelection(TextSelection.near(resolvedPos));
13138
+ const resolvedPos2 = tr2.doc.resolve(from2);
13139
+ tr2.setSelection(TextSelection.near(resolvedPos2));
13128
13140
  this.editor.view.dispatch(tr2);
13129
13141
  return true;
13130
13142
  }
@@ -13132,37 +13144,12 @@ var CustomTaskItem = TaskItem.extend({
13132
13144
  const from = $from.before(taskItemDepth);
13133
13145
  const to = $from.after(taskItemDepth);
13134
13146
  tr.delete(from, to);
13135
- const prevPos = Math.max(0, from - 1);
13136
- const $prev = tr.doc.resolve(prevPos);
13137
- const cursorPos = $prev.end($prev.depth);
13138
- tr.setSelection(TextSelection.create(tr.doc, cursorPos));
13147
+ const resolvedPos = tr.doc.resolve(Math.max(0, from));
13148
+ tr.setSelection(TextSelection.near(resolvedPos, -1));
13139
13149
  this.editor.view.dispatch(tr);
13140
13150
  return true;
13141
13151
  }
13142
- const indexInList = taskListDepth !== -1 ? $from.index(taskListDepth) : -1;
13143
- if (indexInList > 0 && taskListDepth !== -1) {
13144
- const tr = state.tr;
13145
- const itemStart = $from.before(taskItemDepth);
13146
- const itemEnd = $from.after(taskItemDepth);
13147
- if (tr.doc.resolve(itemStart).nodeBefore) {
13148
- const contentSlice = taskItem.content;
13149
- tr.delete(itemStart, itemEnd);
13150
- const prevPos = Math.max(0, itemStart - 1);
13151
- const $prevEnd = tr.doc.resolve(prevPos);
13152
- const prevParaEnd = $prevEnd.end($prevEnd.depth);
13153
- let insertAt = prevParaEnd;
13154
- contentSlice.forEach((child) => {
13155
- child.content.forEach((inline) => {
13156
- tr.insert(insertAt, inline);
13157
- insertAt += inline.nodeSize;
13158
- });
13159
- });
13160
- tr.setSelection(TextSelection.create(tr.doc, prevParaEnd));
13161
- this.editor.view.dispatch(tr);
13162
- return true;
13163
- }
13164
- }
13165
- return this.editor.commands.liftListItem(this.name);
13152
+ return false;
13166
13153
  },
13167
13154
  "Shift-Tab": () => this.editor.commands.liftListItem(this.name),
13168
13155
  ...this.options.nested ? { Tab: () => this.editor.commands.sinkListItem(this.name) } : {}
@@ -15001,6 +14988,7 @@ var RufousTextEditor = ({
15001
14988
  editor.off("blur", handler);
15002
14989
  };
15003
14990
  }, [editor]);
14991
+ const setLinkRef = useRef30(null);
15004
14992
  const [linkModalOpen, setLinkModalOpen] = useState34(false);
15005
14993
  const [linkUrl, setLinkUrl] = useState34("");
15006
14994
  const [linkText, setLinkText] = useState34("");
@@ -15045,6 +15033,22 @@ var RufousTextEditor = ({
15045
15033
  setLinkSelection({ from, to });
15046
15034
  setLinkModalOpen(true);
15047
15035
  }, [editor]);
15036
+ useEffect27(() => {
15037
+ setLinkRef.current = setLink;
15038
+ }, [setLink]);
15039
+ useEffect27(() => {
15040
+ if (!editor?.view) return;
15041
+ const handleKeyDown = (event) => {
15042
+ if ((event.ctrlKey || event.metaKey) && event.key === "k") {
15043
+ event.preventDefault();
15044
+ setLinkRef.current?.();
15045
+ }
15046
+ };
15047
+ editor.view.dom.addEventListener("keydown", handleKeyDown);
15048
+ return () => {
15049
+ editor.view.dom.removeEventListener("keydown", handleKeyDown);
15050
+ };
15051
+ }, [editor]);
15048
15052
  const handleLinkSubmit = useCallback13(() => {
15049
15053
  if (!editor || !linkSelection) return;
15050
15054
  editor.chain().focus().setTextSelection(linkSelection).run();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rufous/ui",
3
3
  "private": false,
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
5
5
  "type": "module",
6
6
  "description": "Experimental: A lightweight React UI component library (Beta)",
7
7
  "style": "./dist/main.css",