@rufous/ui 0.2.2 → 0.2.4
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/main.cjs +44 -38
- package/dist/main.js +44 -38
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -41713,7 +41713,25 @@ var CustomTaskItem = import_extension_task_item.default.extend({
|
|
|
41713
41713
|
break;
|
|
41714
41714
|
}
|
|
41715
41715
|
}
|
|
41716
|
-
if (taskDepth === -1)
|
|
41716
|
+
if (taskDepth === -1) {
|
|
41717
|
+
if (this.editor.storage.taskTodoEnabled === true) {
|
|
41718
|
+
const schema2 = state.schema;
|
|
41719
|
+
const taskItemType = schema2.nodes.taskItem;
|
|
41720
|
+
const taskListType = schema2.nodes.taskList;
|
|
41721
|
+
if (!taskItemType || !taskListType) return false;
|
|
41722
|
+
const statusText = schema2.text("Todo");
|
|
41723
|
+
const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema2.nodes.paragraph.create(null, statusText));
|
|
41724
|
+
const newTaskList = taskListType.create(null, newTaskItem);
|
|
41725
|
+
const tr2 = state.tr;
|
|
41726
|
+
const pos = $from.pos;
|
|
41727
|
+
const afterBlock = $from.after($from.depth > 0 ? 1 : 0);
|
|
41728
|
+
tr2.insert(afterBlock, newTaskList);
|
|
41729
|
+
tr2.setSelection(TextSelection.near(tr2.doc.resolve(afterBlock + 3 + 4)));
|
|
41730
|
+
this.editor.view.dispatch(tr2);
|
|
41731
|
+
return true;
|
|
41732
|
+
}
|
|
41733
|
+
return false;
|
|
41734
|
+
}
|
|
41717
41735
|
if (this.editor.storage.taskTodoEnabled === false) {
|
|
41718
41736
|
const afterContent2 = $from.parent.content.cut($from.parentOffset);
|
|
41719
41737
|
const schema2 = state.schema;
|
|
@@ -41740,10 +41758,8 @@ var CustomTaskItem = import_extension_task_item.default.extend({
|
|
|
41740
41758
|
const schema = state.schema;
|
|
41741
41759
|
const tr = state.tr;
|
|
41742
41760
|
const afterContent = $from.parent.content.cut($from.parentOffset);
|
|
41743
|
-
const cursorPos = $from.pos;
|
|
41744
|
-
const paraEnd = $from.end();
|
|
41745
41761
|
if (afterContent.size > 0) {
|
|
41746
|
-
tr.delete(
|
|
41762
|
+
tr.delete($from.pos, $from.end());
|
|
41747
41763
|
}
|
|
41748
41764
|
const statusLabel = STATUS_LABELS[status] || STATUS_LABELS.todo;
|
|
41749
41765
|
const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create(null, schema.text(statusLabel));
|
|
@@ -41753,8 +41769,8 @@ var CustomTaskItem = import_extension_task_item.default.extend({
|
|
|
41753
41769
|
);
|
|
41754
41770
|
const insertPos = tr.mapping.map($from.after(taskDepth));
|
|
41755
41771
|
tr.insert(insertPos, newItem);
|
|
41756
|
-
const
|
|
41757
|
-
tr.setSelection(TextSelection.
|
|
41772
|
+
const cursorOffset = afterContent.size > 0 ? 0 : statusLabel.length;
|
|
41773
|
+
tr.setSelection(TextSelection.create(tr.doc, insertPos + 2 + cursorOffset));
|
|
41758
41774
|
this.editor.view.dispatch(tr);
|
|
41759
41775
|
return true;
|
|
41760
41776
|
},
|
|
@@ -41785,8 +41801,8 @@ var CustomTaskItem = import_extension_task_item.default.extend({
|
|
|
41785
41801
|
const from2 = $from.before(taskListDepth);
|
|
41786
41802
|
const to2 = $from.after(taskListDepth);
|
|
41787
41803
|
tr2.replaceWith(from2, to2, state.schema.nodes.paragraph.create());
|
|
41788
|
-
const
|
|
41789
|
-
tr2.setSelection(TextSelection.near(
|
|
41804
|
+
const resolvedPos2 = tr2.doc.resolve(from2);
|
|
41805
|
+
tr2.setSelection(TextSelection.near(resolvedPos2));
|
|
41790
41806
|
this.editor.view.dispatch(tr2);
|
|
41791
41807
|
return true;
|
|
41792
41808
|
}
|
|
@@ -41794,39 +41810,12 @@ var CustomTaskItem = import_extension_task_item.default.extend({
|
|
|
41794
41810
|
const from = $from.before(taskItemDepth);
|
|
41795
41811
|
const to = $from.after(taskItemDepth);
|
|
41796
41812
|
tr.delete(from, to);
|
|
41797
|
-
const
|
|
41798
|
-
|
|
41799
|
-
const cursorPos = $prev.end($prev.depth);
|
|
41800
|
-
tr.setSelection(TextSelection.create(tr.doc, cursorPos));
|
|
41813
|
+
const resolvedPos = tr.doc.resolve(Math.max(0, from));
|
|
41814
|
+
tr.setSelection(TextSelection.near(resolvedPos, -1));
|
|
41801
41815
|
this.editor.view.dispatch(tr);
|
|
41802
41816
|
return true;
|
|
41803
41817
|
}
|
|
41804
|
-
|
|
41805
|
-
if (indexInList > 0 && taskListDepth !== -1) {
|
|
41806
|
-
const tr = state.tr;
|
|
41807
|
-
const itemStart = $from.before(taskItemDepth);
|
|
41808
|
-
const itemEnd = $from.after(taskItemDepth);
|
|
41809
|
-
const posBefore = itemStart;
|
|
41810
|
-
if (tr.doc.resolve(posBefore).nodeBefore) {
|
|
41811
|
-
const textContent = taskItem.textContent;
|
|
41812
|
-
const contentSlice = taskItem.content;
|
|
41813
|
-
tr.delete(itemStart, itemEnd);
|
|
41814
|
-
const prevItemEndPos = Math.max(0, itemStart - 1);
|
|
41815
|
-
const $prevEnd = tr.doc.resolve(prevItemEndPos);
|
|
41816
|
-
const prevParaEnd = $prevEnd.end($prevEnd.depth);
|
|
41817
|
-
let insertAt = prevParaEnd;
|
|
41818
|
-
contentSlice.forEach((child) => {
|
|
41819
|
-
child.content.forEach((inline) => {
|
|
41820
|
-
tr.insert(insertAt, inline);
|
|
41821
|
-
insertAt += inline.nodeSize;
|
|
41822
|
-
});
|
|
41823
|
-
});
|
|
41824
|
-
tr.setSelection(TextSelection.create(tr.doc, prevParaEnd));
|
|
41825
|
-
this.editor.view.dispatch(tr);
|
|
41826
|
-
return true;
|
|
41827
|
-
}
|
|
41828
|
-
}
|
|
41829
|
-
return this.editor.commands.liftListItem(this.name);
|
|
41818
|
+
return false;
|
|
41830
41819
|
},
|
|
41831
41820
|
"Shift-Tab": () => this.editor.commands.liftListItem(this.name),
|
|
41832
41821
|
...this.options.nested ? { Tab: () => this.editor.commands.sinkListItem(this.name) } : {}
|
|
@@ -43665,6 +43654,7 @@ var RufousTextEditor = ({
|
|
|
43665
43654
|
editor.off("blur", handler);
|
|
43666
43655
|
};
|
|
43667
43656
|
}, [editor]);
|
|
43657
|
+
const setLinkRef = (0, import_react59.useRef)(null);
|
|
43668
43658
|
const [linkModalOpen, setLinkModalOpen] = (0, import_react59.useState)(false);
|
|
43669
43659
|
const [linkUrl, setLinkUrl] = (0, import_react59.useState)("");
|
|
43670
43660
|
const [linkText, setLinkText] = (0, import_react59.useState)("");
|
|
@@ -43709,6 +43699,22 @@ var RufousTextEditor = ({
|
|
|
43709
43699
|
setLinkSelection({ from, to });
|
|
43710
43700
|
setLinkModalOpen(true);
|
|
43711
43701
|
}, [editor]);
|
|
43702
|
+
(0, import_react59.useEffect)(() => {
|
|
43703
|
+
setLinkRef.current = setLink;
|
|
43704
|
+
}, [setLink]);
|
|
43705
|
+
(0, import_react59.useEffect)(() => {
|
|
43706
|
+
if (!editor?.view) return;
|
|
43707
|
+
const handleKeyDown = (event) => {
|
|
43708
|
+
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
|
|
43709
|
+
event.preventDefault();
|
|
43710
|
+
setLinkRef.current?.();
|
|
43711
|
+
}
|
|
43712
|
+
};
|
|
43713
|
+
editor.view.dom.addEventListener("keydown", handleKeyDown);
|
|
43714
|
+
return () => {
|
|
43715
|
+
editor.view.dom.removeEventListener("keydown", handleKeyDown);
|
|
43716
|
+
};
|
|
43717
|
+
}, [editor]);
|
|
43712
43718
|
const handleLinkSubmit = (0, import_react59.useCallback)(() => {
|
|
43713
43719
|
if (!editor || !linkSelection) return;
|
|
43714
43720
|
editor.chain().focus().setTextSelection(linkSelection).run();
|
package/dist/main.js
CHANGED
|
@@ -13043,7 +13043,25 @@ var CustomTaskItem = TaskItem.extend({
|
|
|
13043
13043
|
break;
|
|
13044
13044
|
}
|
|
13045
13045
|
}
|
|
13046
|
-
if (taskDepth === -1)
|
|
13046
|
+
if (taskDepth === -1) {
|
|
13047
|
+
if (this.editor.storage.taskTodoEnabled === true) {
|
|
13048
|
+
const schema2 = state.schema;
|
|
13049
|
+
const taskItemType = schema2.nodes.taskItem;
|
|
13050
|
+
const taskListType = schema2.nodes.taskList;
|
|
13051
|
+
if (!taskItemType || !taskListType) return false;
|
|
13052
|
+
const statusText = schema2.text("Todo");
|
|
13053
|
+
const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema2.nodes.paragraph.create(null, statusText));
|
|
13054
|
+
const newTaskList = taskListType.create(null, newTaskItem);
|
|
13055
|
+
const tr2 = state.tr;
|
|
13056
|
+
const pos = $from.pos;
|
|
13057
|
+
const afterBlock = $from.after($from.depth > 0 ? 1 : 0);
|
|
13058
|
+
tr2.insert(afterBlock, newTaskList);
|
|
13059
|
+
tr2.setSelection(TextSelection.near(tr2.doc.resolve(afterBlock + 3 + 4)));
|
|
13060
|
+
this.editor.view.dispatch(tr2);
|
|
13061
|
+
return true;
|
|
13062
|
+
}
|
|
13063
|
+
return false;
|
|
13064
|
+
}
|
|
13047
13065
|
if (this.editor.storage.taskTodoEnabled === false) {
|
|
13048
13066
|
const afterContent2 = $from.parent.content.cut($from.parentOffset);
|
|
13049
13067
|
const schema2 = state.schema;
|
|
@@ -13070,10 +13088,8 @@ var CustomTaskItem = TaskItem.extend({
|
|
|
13070
13088
|
const schema = state.schema;
|
|
13071
13089
|
const tr = state.tr;
|
|
13072
13090
|
const afterContent = $from.parent.content.cut($from.parentOffset);
|
|
13073
|
-
const cursorPos = $from.pos;
|
|
13074
|
-
const paraEnd = $from.end();
|
|
13075
13091
|
if (afterContent.size > 0) {
|
|
13076
|
-
tr.delete(
|
|
13092
|
+
tr.delete($from.pos, $from.end());
|
|
13077
13093
|
}
|
|
13078
13094
|
const statusLabel = STATUS_LABELS[status] || STATUS_LABELS.todo;
|
|
13079
13095
|
const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create(null, schema.text(statusLabel));
|
|
@@ -13083,8 +13099,8 @@ var CustomTaskItem = TaskItem.extend({
|
|
|
13083
13099
|
);
|
|
13084
13100
|
const insertPos = tr.mapping.map($from.after(taskDepth));
|
|
13085
13101
|
tr.insert(insertPos, newItem);
|
|
13086
|
-
const
|
|
13087
|
-
tr.setSelection(TextSelection.
|
|
13102
|
+
const cursorOffset = afterContent.size > 0 ? 0 : statusLabel.length;
|
|
13103
|
+
tr.setSelection(TextSelection.create(tr.doc, insertPos + 2 + cursorOffset));
|
|
13088
13104
|
this.editor.view.dispatch(tr);
|
|
13089
13105
|
return true;
|
|
13090
13106
|
},
|
|
@@ -13115,8 +13131,8 @@ var CustomTaskItem = TaskItem.extend({
|
|
|
13115
13131
|
const from2 = $from.before(taskListDepth);
|
|
13116
13132
|
const to2 = $from.after(taskListDepth);
|
|
13117
13133
|
tr2.replaceWith(from2, to2, state.schema.nodes.paragraph.create());
|
|
13118
|
-
const
|
|
13119
|
-
tr2.setSelection(TextSelection.near(
|
|
13134
|
+
const resolvedPos2 = tr2.doc.resolve(from2);
|
|
13135
|
+
tr2.setSelection(TextSelection.near(resolvedPos2));
|
|
13120
13136
|
this.editor.view.dispatch(tr2);
|
|
13121
13137
|
return true;
|
|
13122
13138
|
}
|
|
@@ -13124,39 +13140,12 @@ var CustomTaskItem = TaskItem.extend({
|
|
|
13124
13140
|
const from = $from.before(taskItemDepth);
|
|
13125
13141
|
const to = $from.after(taskItemDepth);
|
|
13126
13142
|
tr.delete(from, to);
|
|
13127
|
-
const
|
|
13128
|
-
|
|
13129
|
-
const cursorPos = $prev.end($prev.depth);
|
|
13130
|
-
tr.setSelection(TextSelection.create(tr.doc, cursorPos));
|
|
13143
|
+
const resolvedPos = tr.doc.resolve(Math.max(0, from));
|
|
13144
|
+
tr.setSelection(TextSelection.near(resolvedPos, -1));
|
|
13131
13145
|
this.editor.view.dispatch(tr);
|
|
13132
13146
|
return true;
|
|
13133
13147
|
}
|
|
13134
|
-
|
|
13135
|
-
if (indexInList > 0 && taskListDepth !== -1) {
|
|
13136
|
-
const tr = state.tr;
|
|
13137
|
-
const itemStart = $from.before(taskItemDepth);
|
|
13138
|
-
const itemEnd = $from.after(taskItemDepth);
|
|
13139
|
-
const posBefore = itemStart;
|
|
13140
|
-
if (tr.doc.resolve(posBefore).nodeBefore) {
|
|
13141
|
-
const textContent = taskItem.textContent;
|
|
13142
|
-
const contentSlice = taskItem.content;
|
|
13143
|
-
tr.delete(itemStart, itemEnd);
|
|
13144
|
-
const prevItemEndPos = Math.max(0, itemStart - 1);
|
|
13145
|
-
const $prevEnd = tr.doc.resolve(prevItemEndPos);
|
|
13146
|
-
const prevParaEnd = $prevEnd.end($prevEnd.depth);
|
|
13147
|
-
let insertAt = prevParaEnd;
|
|
13148
|
-
contentSlice.forEach((child) => {
|
|
13149
|
-
child.content.forEach((inline) => {
|
|
13150
|
-
tr.insert(insertAt, inline);
|
|
13151
|
-
insertAt += inline.nodeSize;
|
|
13152
|
-
});
|
|
13153
|
-
});
|
|
13154
|
-
tr.setSelection(TextSelection.create(tr.doc, prevParaEnd));
|
|
13155
|
-
this.editor.view.dispatch(tr);
|
|
13156
|
-
return true;
|
|
13157
|
-
}
|
|
13158
|
-
}
|
|
13159
|
-
return this.editor.commands.liftListItem(this.name);
|
|
13148
|
+
return false;
|
|
13160
13149
|
},
|
|
13161
13150
|
"Shift-Tab": () => this.editor.commands.liftListItem(this.name),
|
|
13162
13151
|
...this.options.nested ? { Tab: () => this.editor.commands.sinkListItem(this.name) } : {}
|
|
@@ -14995,6 +14984,7 @@ var RufousTextEditor = ({
|
|
|
14995
14984
|
editor.off("blur", handler);
|
|
14996
14985
|
};
|
|
14997
14986
|
}, [editor]);
|
|
14987
|
+
const setLinkRef = useRef30(null);
|
|
14998
14988
|
const [linkModalOpen, setLinkModalOpen] = useState34(false);
|
|
14999
14989
|
const [linkUrl, setLinkUrl] = useState34("");
|
|
15000
14990
|
const [linkText, setLinkText] = useState34("");
|
|
@@ -15039,6 +15029,22 @@ var RufousTextEditor = ({
|
|
|
15039
15029
|
setLinkSelection({ from, to });
|
|
15040
15030
|
setLinkModalOpen(true);
|
|
15041
15031
|
}, [editor]);
|
|
15032
|
+
useEffect27(() => {
|
|
15033
|
+
setLinkRef.current = setLink;
|
|
15034
|
+
}, [setLink]);
|
|
15035
|
+
useEffect27(() => {
|
|
15036
|
+
if (!editor?.view) return;
|
|
15037
|
+
const handleKeyDown = (event) => {
|
|
15038
|
+
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
|
|
15039
|
+
event.preventDefault();
|
|
15040
|
+
setLinkRef.current?.();
|
|
15041
|
+
}
|
|
15042
|
+
};
|
|
15043
|
+
editor.view.dom.addEventListener("keydown", handleKeyDown);
|
|
15044
|
+
return () => {
|
|
15045
|
+
editor.view.dom.removeEventListener("keydown", handleKeyDown);
|
|
15046
|
+
};
|
|
15047
|
+
}, [editor]);
|
|
15042
15048
|
const handleLinkSubmit = useCallback13(() => {
|
|
15043
15049
|
if (!editor || !linkSelection) return;
|
|
15044
15050
|
editor.chain().focus().setTextSelection(linkSelection).run();
|