@rufous/ui 0.2.1 → 0.2.3

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 +99 -48
  2. package/dist/main.js +99 -48
  3. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -41672,12 +41672,6 @@ var STATUS_IMAGES = {
41672
41672
  blocked: "https://storage.googleapis.com/rufous-com-bucket-1/static/images/blocked.svg",
41673
41673
  resolved: "https://storage.googleapis.com/rufous-com-bucket-1/static/images/closed.svg"
41674
41674
  };
41675
- var STATUS_LABELS = {
41676
- todo: "Todo",
41677
- working: "Working",
41678
- blocked: "Blocked",
41679
- resolved: "Resolved"
41680
- };
41681
41675
  var STATUS_COLORS = {
41682
41676
  todo: { border: "#dc2626", bg: "#fff", color: "#dc2626" },
41683
41677
  working: { border: "#2563eb", bg: "#eff6ff", color: "#2563eb" },
@@ -41685,6 +41679,9 @@ var STATUS_COLORS = {
41685
41679
  resolved: { border: "#16a34a", bg: "#16a34a", color: "#fff" }
41686
41680
  };
41687
41681
  var CustomTaskItem = import_extension_task_item.default.extend({
41682
+ addStorage() {
41683
+ return { taskTodoEnabled: true };
41684
+ },
41688
41685
  addAttributes() {
41689
41686
  return {
41690
41687
  ...this.parent?.(),
@@ -41710,27 +41707,62 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41710
41707
  break;
41711
41708
  }
41712
41709
  }
41713
- if (taskDepth === -1) return false;
41710
+ if (taskDepth === -1) {
41711
+ if (this.editor.storage.taskTodoEnabled === true) {
41712
+ const schema2 = state.schema;
41713
+ const taskItemType = schema2.nodes.taskItem;
41714
+ const taskListType = schema2.nodes.taskList;
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));
41718
+ const newTaskList = taskListType.create(null, newTaskItem);
41719
+ const tr2 = state.tr;
41720
+ const pos = $from.pos;
41721
+ 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);
41725
+ return true;
41726
+ }
41727
+ return false;
41728
+ }
41729
+ 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());
41735
+ }
41736
+ let taskListDepth = -1;
41737
+ for (let d = taskDepth - 1; d >= 0; d--) {
41738
+ if ($from.node(d).type.name === "taskList") {
41739
+ taskListDepth = d;
41740
+ break;
41741
+ }
41742
+ }
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);
41748
+ return true;
41749
+ }
41714
41750
  const taskNode = $from.node(taskDepth);
41715
41751
  const status = taskNode.attrs.status || "todo";
41716
41752
  const schema = state.schema;
41717
41753
  const tr = state.tr;
41718
41754
  const afterContent = $from.parent.content.cut($from.parentOffset);
41719
- const cursorPos = $from.pos;
41720
- const paraEnd = $from.end();
41721
41755
  if (afterContent.size > 0) {
41722
- tr.delete(cursorPos, paraEnd);
41756
+ tr.delete($from.pos, $from.end());
41723
41757
  }
41724
- const statusLabel = STATUS_LABELS[status] || STATUS_LABELS.todo;
41725
- const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create(null, schema.text(statusLabel));
41758
+ const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create();
41726
41759
  const newItem = schema.nodes.taskItem.create(
41727
41760
  { status, checked: false },
41728
41761
  newPara
41729
41762
  );
41730
41763
  const insertPos = tr.mapping.map($from.after(taskDepth));
41731
41764
  tr.insert(insertPos, newItem);
41732
- const textLen = afterContent.size > 0 ? 0 : statusLabel.length;
41733
- tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 2 + textLen)));
41765
+ tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 2)));
41734
41766
  this.editor.view.dispatch(tr);
41735
41767
  return true;
41736
41768
  },
@@ -41770,7 +41802,10 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41770
41802
  const from = $from.before(taskItemDepth);
41771
41803
  const to = $from.after(taskItemDepth);
41772
41804
  tr.delete(from, to);
41773
- tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, from)), -1));
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));
41774
41809
  this.editor.view.dispatch(tr);
41775
41810
  return true;
41776
41811
  }
@@ -41779,13 +41814,11 @@ var CustomTaskItem = import_extension_task_item.default.extend({
41779
41814
  const tr = state.tr;
41780
41815
  const itemStart = $from.before(taskItemDepth);
41781
41816
  const itemEnd = $from.after(taskItemDepth);
41782
- const posBefore = itemStart;
41783
- if (tr.doc.resolve(posBefore).nodeBefore) {
41784
- const textContent = taskItem.textContent;
41817
+ if (tr.doc.resolve(itemStart).nodeBefore) {
41785
41818
  const contentSlice = taskItem.content;
41786
41819
  tr.delete(itemStart, itemEnd);
41787
- const prevItemEndPos = Math.max(0, itemStart - 1);
41788
- const $prevEnd = tr.doc.resolve(prevItemEndPos);
41820
+ const prevPos = Math.max(0, itemStart - 1);
41821
+ const $prevEnd = tr.doc.resolve(prevPos);
41789
41822
  const prevParaEnd = $prevEnd.end($prevEnd.depth);
41790
41823
  let insertAt = prevParaEnd;
41791
41824
  contentSlice.forEach((child) => {
@@ -42340,6 +42373,7 @@ var ColorPickerPanel = ({ editor, onClose }) => {
42340
42373
  var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTextToSpeech, onClose, onImageUpload }) => {
42341
42374
  const [, setEditorState] = (0, import_react56.useState)(0);
42342
42375
  const [isFullscreen, setIsFullscreen] = (0, import_react56.useState)(false);
42376
+ const [todoEnabled, setTodoEnabled] = (0, import_react56.useState)(false);
42343
42377
  (0, import_react56.useEffect)(() => {
42344
42378
  if (!editor) return;
42345
42379
  const onTransaction = () => setEditorState((n) => n + 1);
@@ -42840,24 +42874,25 @@ var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTe
42840
42874
  {
42841
42875
  trigger: { label: /* @__PURE__ */ import_react56.default.createElement(IconCode, null), title: "Code", className: editor.isActive("code") || editor.isActive("codeBlock") ? "is-active" : "" }
42842
42876
  },
42843
- /* @__PURE__ */ import_react56.default.createElement("button", { className: "dropdown-item", onClick: () => editor.chain().focus().toggleCode().run() }, "</>", " Inline Code"),
42844
- /* @__PURE__ */ import_react56.default.createElement("button", { className: "dropdown-item", onClick: () => editor.chain().focus().toggleCodeBlock().run() }, "{ }", " Code Block"),
42845
- editor.isActive("codeBlock") && /* @__PURE__ */ import_react56.default.createElement("button", { className: "dropdown-item", onClick: () => {
42846
- const text = (() => {
42847
- const { $from } = editor.state.selection;
42848
- for (let d = $from.depth; d > 0; d--) {
42849
- if ($from.node(d).type.name === "codeBlock") return $from.node(d).textContent;
42850
- }
42851
- return "";
42852
- })();
42853
- if (text) {
42877
+ /* @__PURE__ */ import_react56.default.createElement("button", { className: "dropdown-item", onClick: () => {
42878
+ if (editor.isActive("codeBlock")) {
42879
+ const text = (() => {
42880
+ const { $from } = editor.state.selection;
42881
+ for (let d = $from.depth; d > 0; d--) {
42882
+ if ($from.node(d).type.name === "codeBlock") return $from.node(d).textContent;
42883
+ }
42884
+ return "";
42885
+ })();
42854
42886
  editor.chain().focus().toggleCodeBlock().run();
42855
- const { from } = editor.state.selection;
42856
- editor.chain().focus().setTextSelection({ from, to: from + text.length }).toggleCode().run();
42887
+ if (text) {
42888
+ const { from } = editor.state.selection;
42889
+ editor.chain().focus().setTextSelection({ from, to: from + text.length }).toggleCode().run();
42890
+ }
42857
42891
  } else {
42858
- editor.chain().focus().toggleCodeBlock().run();
42892
+ editor.chain().focus().toggleCode().run();
42859
42893
  }
42860
- } }, "</> \u2190", " Convert to Inline Code")
42894
+ } }, "</>", " Inline Code"),
42895
+ /* @__PURE__ */ import_react56.default.createElement("button", { className: "dropdown-item", onClick: () => editor.chain().focus().toggleCodeBlock().run() }, "{ }", " Code Block")
42861
42896
  ), /* @__PURE__ */ import_react56.default.createElement(
42862
42897
  "button",
42863
42898
  {
@@ -42877,11 +42912,15 @@ var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTe
42877
42912
  ), /* @__PURE__ */ import_react56.default.createElement(Dropdown, { trigger: { label: "", title: "Translate options", className: "translate-arrow-btn" } }, /* @__PURE__ */ import_react56.default.createElement("button", { className: "dropdown-item", onClick: () => setShowTranslateModal(true) }, "Options")), translateStatus && /* @__PURE__ */ import_react56.default.createElement("span", { className: `translate-toast-popup ${translateStatus === "Please select the text" || translateStatus === "Translation failed" ? "error" : ""}` }, translateStatus)), /* @__PURE__ */ import_react56.default.createElement("div", { className: "todo-split-btn" }, /* @__PURE__ */ import_react56.default.createElement(
42878
42913
  "button",
42879
42914
  {
42880
- className: `toolbar-btn ${editor.isActive("taskList") ? "is-active" : ""}`,
42915
+ className: `toolbar-btn ${todoEnabled ? "is-active" : ""}`,
42881
42916
  onClick: () => {
42882
- if (editor.isActive("taskList")) {
42883
- editor.chain().focus().liftListItem("taskItem").run();
42917
+ if (todoEnabled) {
42918
+ setTodoEnabled(false);
42919
+ editor.storage.taskTodoEnabled = false;
42920
+ editor.chain().focus().run();
42884
42921
  } else {
42922
+ setTodoEnabled(true);
42923
+ editor.storage.taskTodoEnabled = true;
42885
42924
  const { state } = editor;
42886
42925
  const { schema } = state;
42887
42926
  const taskItemType = schema.nodes.taskItem;
@@ -42889,18 +42928,30 @@ var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTe
42889
42928
  if (!taskItemType || !taskListType) return;
42890
42929
  const statusText = schema.text("Todo");
42891
42930
  const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema.nodes.paragraph.create(null, statusText));
42892
- const newTaskList = taskListType.create(null, newTaskItem);
42893
- editor.chain().focus().command(({ tr, dispatch, state: cmdState }) => {
42894
- if (!dispatch) return true;
42895
- const pos = tr.selection.from;
42896
- tr.replaceSelectionWith(newTaskList);
42897
- const resolvedPos = tr.doc.resolve(pos + 2 + 4);
42898
- tr.setSelection(cmdState.selection.constructor.near(resolvedPos));
42899
- return true;
42900
- }).run();
42931
+ const { $from } = state.selection;
42932
+ let insideTask = false;
42933
+ for (let d = $from.depth; d > 0; d--) {
42934
+ if ($from.node(d).type.name === "taskItem") {
42935
+ insideTask = true;
42936
+ break;
42937
+ }
42938
+ }
42939
+ if (insideTask) {
42940
+ editor.chain().focus().run();
42941
+ } else {
42942
+ const newTaskList = taskListType.create(null, newTaskItem);
42943
+ editor.chain().focus().command(({ tr, dispatch, state: cmdState }) => {
42944
+ if (!dispatch) return true;
42945
+ const pos = tr.selection.from;
42946
+ tr.replaceSelectionWith(newTaskList);
42947
+ const resolvedPos = tr.doc.resolve(pos + 2 + 4);
42948
+ tr.setSelection(cmdState.selection.constructor.near(resolvedPos));
42949
+ return true;
42950
+ }).run();
42951
+ }
42901
42952
  }
42902
42953
  },
42903
- title: editor.isActive("taskList") ? "Disable Task List" : "Enable Task List"
42954
+ title: todoEnabled ? "Disable Task List" : "Enable Task List"
42904
42955
  },
42905
42956
  /* @__PURE__ */ import_react56.default.createElement(IconTaskList, null)
42906
42957
  ), /* @__PURE__ */ import_react56.default.createElement(Dropdown, { trigger: { label: "", title: "Task status", className: "todo-arrow-btn" }, keepOpen: true }, ["todo", "working", "blocked", "resolved"].map((status) => {
package/dist/main.js CHANGED
@@ -13002,12 +13002,6 @@ var STATUS_IMAGES = {
13002
13002
  blocked: "https://storage.googleapis.com/rufous-com-bucket-1/static/images/blocked.svg",
13003
13003
  resolved: "https://storage.googleapis.com/rufous-com-bucket-1/static/images/closed.svg"
13004
13004
  };
13005
- var STATUS_LABELS = {
13006
- todo: "Todo",
13007
- working: "Working",
13008
- blocked: "Blocked",
13009
- resolved: "Resolved"
13010
- };
13011
13005
  var STATUS_COLORS = {
13012
13006
  todo: { border: "#dc2626", bg: "#fff", color: "#dc2626" },
13013
13007
  working: { border: "#2563eb", bg: "#eff6ff", color: "#2563eb" },
@@ -13015,6 +13009,9 @@ var STATUS_COLORS = {
13015
13009
  resolved: { border: "#16a34a", bg: "#16a34a", color: "#fff" }
13016
13010
  };
13017
13011
  var CustomTaskItem = TaskItem.extend({
13012
+ addStorage() {
13013
+ return { taskTodoEnabled: true };
13014
+ },
13018
13015
  addAttributes() {
13019
13016
  return {
13020
13017
  ...this.parent?.(),
@@ -13040,27 +13037,62 @@ var CustomTaskItem = TaskItem.extend({
13040
13037
  break;
13041
13038
  }
13042
13039
  }
13043
- if (taskDepth === -1) return false;
13040
+ if (taskDepth === -1) {
13041
+ if (this.editor.storage.taskTodoEnabled === true) {
13042
+ const schema2 = state.schema;
13043
+ const taskItemType = schema2.nodes.taskItem;
13044
+ const taskListType = schema2.nodes.taskList;
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));
13048
+ const newTaskList = taskListType.create(null, newTaskItem);
13049
+ const tr2 = state.tr;
13050
+ const pos = $from.pos;
13051
+ 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);
13055
+ return true;
13056
+ }
13057
+ return false;
13058
+ }
13059
+ 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());
13065
+ }
13066
+ let taskListDepth = -1;
13067
+ for (let d = taskDepth - 1; d >= 0; d--) {
13068
+ if ($from.node(d).type.name === "taskList") {
13069
+ taskListDepth = d;
13070
+ break;
13071
+ }
13072
+ }
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);
13078
+ return true;
13079
+ }
13044
13080
  const taskNode = $from.node(taskDepth);
13045
13081
  const status = taskNode.attrs.status || "todo";
13046
13082
  const schema = state.schema;
13047
13083
  const tr = state.tr;
13048
13084
  const afterContent = $from.parent.content.cut($from.parentOffset);
13049
- const cursorPos = $from.pos;
13050
- const paraEnd = $from.end();
13051
13085
  if (afterContent.size > 0) {
13052
- tr.delete(cursorPos, paraEnd);
13086
+ tr.delete($from.pos, $from.end());
13053
13087
  }
13054
- const statusLabel = STATUS_LABELS[status] || STATUS_LABELS.todo;
13055
- const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create(null, schema.text(statusLabel));
13088
+ const newPara = afterContent.size > 0 ? schema.nodes.paragraph.create(null, afterContent) : schema.nodes.paragraph.create();
13056
13089
  const newItem = schema.nodes.taskItem.create(
13057
13090
  { status, checked: false },
13058
13091
  newPara
13059
13092
  );
13060
13093
  const insertPos = tr.mapping.map($from.after(taskDepth));
13061
13094
  tr.insert(insertPos, newItem);
13062
- const textLen = afterContent.size > 0 ? 0 : statusLabel.length;
13063
- tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 2 + textLen)));
13095
+ tr.setSelection(TextSelection.near(tr.doc.resolve(insertPos + 2)));
13064
13096
  this.editor.view.dispatch(tr);
13065
13097
  return true;
13066
13098
  },
@@ -13100,7 +13132,10 @@ var CustomTaskItem = TaskItem.extend({
13100
13132
  const from = $from.before(taskItemDepth);
13101
13133
  const to = $from.after(taskItemDepth);
13102
13134
  tr.delete(from, to);
13103
- tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, from)), -1));
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));
13104
13139
  this.editor.view.dispatch(tr);
13105
13140
  return true;
13106
13141
  }
@@ -13109,13 +13144,11 @@ var CustomTaskItem = TaskItem.extend({
13109
13144
  const tr = state.tr;
13110
13145
  const itemStart = $from.before(taskItemDepth);
13111
13146
  const itemEnd = $from.after(taskItemDepth);
13112
- const posBefore = itemStart;
13113
- if (tr.doc.resolve(posBefore).nodeBefore) {
13114
- const textContent = taskItem.textContent;
13147
+ if (tr.doc.resolve(itemStart).nodeBefore) {
13115
13148
  const contentSlice = taskItem.content;
13116
13149
  tr.delete(itemStart, itemEnd);
13117
- const prevItemEndPos = Math.max(0, itemStart - 1);
13118
- const $prevEnd = tr.doc.resolve(prevItemEndPos);
13150
+ const prevPos = Math.max(0, itemStart - 1);
13151
+ const $prevEnd = tr.doc.resolve(prevPos);
13119
13152
  const prevParaEnd = $prevEnd.end($prevEnd.depth);
13120
13153
  let insertAt = prevParaEnd;
13121
13154
  contentSlice.forEach((child) => {
@@ -13670,6 +13703,7 @@ var ColorPickerPanel = ({ editor, onClose }) => {
13670
13703
  var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTextToSpeech, onClose, onImageUpload }) => {
13671
13704
  const [, setEditorState] = useState31(0);
13672
13705
  const [isFullscreen, setIsFullscreen] = useState31(false);
13706
+ const [todoEnabled, setTodoEnabled] = useState31(false);
13673
13707
  useEffect24(() => {
13674
13708
  if (!editor) return;
13675
13709
  const onTransaction = () => setEditorState((n) => n + 1);
@@ -14170,24 +14204,25 @@ var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTe
14170
14204
  {
14171
14205
  trigger: { label: /* @__PURE__ */ React113.createElement(IconCode, null), title: "Code", className: editor.isActive("code") || editor.isActive("codeBlock") ? "is-active" : "" }
14172
14206
  },
14173
- /* @__PURE__ */ React113.createElement("button", { className: "dropdown-item", onClick: () => editor.chain().focus().toggleCode().run() }, "</>", " Inline Code"),
14174
- /* @__PURE__ */ React113.createElement("button", { className: "dropdown-item", onClick: () => editor.chain().focus().toggleCodeBlock().run() }, "{ }", " Code Block"),
14175
- editor.isActive("codeBlock") && /* @__PURE__ */ React113.createElement("button", { className: "dropdown-item", onClick: () => {
14176
- const text = (() => {
14177
- const { $from } = editor.state.selection;
14178
- for (let d = $from.depth; d > 0; d--) {
14179
- if ($from.node(d).type.name === "codeBlock") return $from.node(d).textContent;
14180
- }
14181
- return "";
14182
- })();
14183
- if (text) {
14207
+ /* @__PURE__ */ React113.createElement("button", { className: "dropdown-item", onClick: () => {
14208
+ if (editor.isActive("codeBlock")) {
14209
+ const text = (() => {
14210
+ const { $from } = editor.state.selection;
14211
+ for (let d = $from.depth; d > 0; d--) {
14212
+ if ($from.node(d).type.name === "codeBlock") return $from.node(d).textContent;
14213
+ }
14214
+ return "";
14215
+ })();
14184
14216
  editor.chain().focus().toggleCodeBlock().run();
14185
- const { from } = editor.state.selection;
14186
- editor.chain().focus().setTextSelection({ from, to: from + text.length }).toggleCode().run();
14217
+ if (text) {
14218
+ const { from } = editor.state.selection;
14219
+ editor.chain().focus().setTextSelection({ from, to: from + text.length }).toggleCode().run();
14220
+ }
14187
14221
  } else {
14188
- editor.chain().focus().toggleCodeBlock().run();
14222
+ editor.chain().focus().toggleCode().run();
14189
14223
  }
14190
- } }, "</> \u2190", " Convert to Inline Code")
14224
+ } }, "</>", " Inline Code"),
14225
+ /* @__PURE__ */ React113.createElement("button", { className: "dropdown-item", onClick: () => editor.chain().focus().toggleCodeBlock().run() }, "{ }", " Code Block")
14191
14226
  ), /* @__PURE__ */ React113.createElement(
14192
14227
  "button",
14193
14228
  {
@@ -14207,11 +14242,15 @@ var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTe
14207
14242
  ), /* @__PURE__ */ React113.createElement(Dropdown, { trigger: { label: "", title: "Translate options", className: "translate-arrow-btn" } }, /* @__PURE__ */ React113.createElement("button", { className: "dropdown-item", onClick: () => setShowTranslateModal(true) }, "Options")), translateStatus && /* @__PURE__ */ React113.createElement("span", { className: `translate-toast-popup ${translateStatus === "Please select the text" || translateStatus === "Translation failed" ? "error" : ""}` }, translateStatus)), /* @__PURE__ */ React113.createElement("div", { className: "todo-split-btn" }, /* @__PURE__ */ React113.createElement(
14208
14243
  "button",
14209
14244
  {
14210
- className: `toolbar-btn ${editor.isActive("taskList") ? "is-active" : ""}`,
14245
+ className: `toolbar-btn ${todoEnabled ? "is-active" : ""}`,
14211
14246
  onClick: () => {
14212
- if (editor.isActive("taskList")) {
14213
- editor.chain().focus().liftListItem("taskItem").run();
14247
+ if (todoEnabled) {
14248
+ setTodoEnabled(false);
14249
+ editor.storage.taskTodoEnabled = false;
14250
+ editor.chain().focus().run();
14214
14251
  } else {
14252
+ setTodoEnabled(true);
14253
+ editor.storage.taskTodoEnabled = true;
14215
14254
  const { state } = editor;
14216
14255
  const { schema } = state;
14217
14256
  const taskItemType = schema.nodes.taskItem;
@@ -14219,18 +14258,30 @@ var Toolbar = ({ editor, setLink, onAICommand, onTranslate, onSpeechToText, onTe
14219
14258
  if (!taskItemType || !taskListType) return;
14220
14259
  const statusText = schema.text("Todo");
14221
14260
  const newTaskItem = taskItemType.create({ status: "todo", checked: false }, schema.nodes.paragraph.create(null, statusText));
14222
- const newTaskList = taskListType.create(null, newTaskItem);
14223
- editor.chain().focus().command(({ tr, dispatch, state: cmdState }) => {
14224
- if (!dispatch) return true;
14225
- const pos = tr.selection.from;
14226
- tr.replaceSelectionWith(newTaskList);
14227
- const resolvedPos = tr.doc.resolve(pos + 2 + 4);
14228
- tr.setSelection(cmdState.selection.constructor.near(resolvedPos));
14229
- return true;
14230
- }).run();
14261
+ const { $from } = state.selection;
14262
+ let insideTask = false;
14263
+ for (let d = $from.depth; d > 0; d--) {
14264
+ if ($from.node(d).type.name === "taskItem") {
14265
+ insideTask = true;
14266
+ break;
14267
+ }
14268
+ }
14269
+ if (insideTask) {
14270
+ editor.chain().focus().run();
14271
+ } else {
14272
+ const newTaskList = taskListType.create(null, newTaskItem);
14273
+ editor.chain().focus().command(({ tr, dispatch, state: cmdState }) => {
14274
+ if (!dispatch) return true;
14275
+ const pos = tr.selection.from;
14276
+ tr.replaceSelectionWith(newTaskList);
14277
+ const resolvedPos = tr.doc.resolve(pos + 2 + 4);
14278
+ tr.setSelection(cmdState.selection.constructor.near(resolvedPos));
14279
+ return true;
14280
+ }).run();
14281
+ }
14231
14282
  }
14232
14283
  },
14233
- title: editor.isActive("taskList") ? "Disable Task List" : "Enable Task List"
14284
+ title: todoEnabled ? "Disable Task List" : "Enable Task List"
14234
14285
  },
14235
14286
  /* @__PURE__ */ React113.createElement(IconTaskList, null)
14236
14287
  ), /* @__PURE__ */ React113.createElement(Dropdown, { trigger: { label: "", title: "Task status", className: "todo-arrow-btn" }, keepOpen: true }, ["todo", "working", "blocked", "resolved"].map((status) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rufous/ui",
3
3
  "private": false,
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "type": "module",
6
6
  "description": "Experimental: A lightweight React UI component library (Beta)",
7
7
  "style": "./dist/main.css",