@mhamz.01/easyflow-texteditor 0.1.157 → 0.1.159

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/index.mjs CHANGED
@@ -1173,9 +1173,13 @@ function EditorLayout({ children, onChange, initialTabs, onTabsChange }) {
1173
1173
  );
1174
1174
  const renameTab = useCallback5(
1175
1175
  (id, title) => {
1176
- setTabs((prev) => prev.map((t) => t.id === id ? { ...t, title } : t));
1176
+ setTabs((prev) => {
1177
+ const updated = prev.map((t) => t.id === id ? { ...t, title } : t);
1178
+ emitChangeDebounced({ tabs: updated, activeTabId, activeSubTabId, source: "rename-tab" });
1179
+ return updated;
1180
+ });
1177
1181
  },
1178
- []
1182
+ [emitChangeDebounced, activeTabId, activeSubTabId]
1179
1183
  );
1180
1184
  const deleteTab = useCallback5(
1181
1185
  (id) => {
@@ -1219,18 +1223,15 @@ function EditorLayout({ children, onChange, initialTabs, onTabsChange }) {
1219
1223
  );
1220
1224
  const renameSubTab = useCallback5(
1221
1225
  (tabId, subTabId, title) => {
1222
- setTabs(
1223
- (prev) => prev.map(
1224
- (tab) => tab.id === tabId ? {
1225
- ...tab,
1226
- subtabs: tab.subtabs.map(
1227
- (st) => st.id === subTabId ? { ...st, title } : st
1228
- )
1229
- } : tab
1230
- )
1231
- );
1226
+ setTabs((prev) => {
1227
+ const updated = prev.map(
1228
+ (tab) => tab.id === tabId ? { ...tab, subtabs: tab.subtabs.map((st) => st.id === subTabId ? { ...st, title } : st) } : tab
1229
+ );
1230
+ emitChangeDebounced({ tabs: updated, activeTabId, activeSubTabId, source: "rename-subtab" });
1231
+ return updated;
1232
+ });
1232
1233
  },
1233
- []
1234
+ [emitChangeDebounced, activeTabId, activeSubTabId]
1234
1235
  );
1235
1236
  const editorActions = useMemo2(
1236
1237
  () => ({
@@ -1831,7 +1832,7 @@ var FONT_SIZES = [
1831
1832
  "64px"
1832
1833
  ];
1833
1834
  var FontSizeExtension = Extension2.create({
1834
- name: "fontSize",
1835
+ name: "customFontSize",
1835
1836
  addOptions() {
1836
1837
  return {
1837
1838
  types: ["textStyle"]
@@ -1866,15 +1867,15 @@ var FontSizeExtension = Extension2.create({
1866
1867
  increaseFontSize: () => ({ editor }) => {
1867
1868
  const currentSize = editor.getAttributes("textStyle").fontSize;
1868
1869
  const currentIndex = FONT_SIZES.indexOf(currentSize || "16px");
1869
- const nextIndex = Math.min(currentIndex + 1, FONT_SIZES.length - 1);
1870
- const nextSize = FONT_SIZES[nextIndex];
1870
+ const fromIndex = currentIndex === -1 ? FONT_SIZES.indexOf("16px") : currentIndex;
1871
+ const nextSize = FONT_SIZES[Math.min(fromIndex + 1, FONT_SIZES.length - 1)];
1871
1872
  return editor.chain().focus().setFontSize(nextSize).run();
1872
1873
  },
1873
1874
  decreaseFontSize: () => ({ editor }) => {
1874
1875
  const currentSize = editor.getAttributes("textStyle").fontSize;
1875
1876
  const currentIndex = FONT_SIZES.indexOf(currentSize || "16px");
1876
- const nextIndex = Math.max(currentIndex - 1, 0);
1877
- const nextSize = FONT_SIZES[nextIndex];
1877
+ const fromIndex = currentIndex === -1 ? FONT_SIZES.indexOf("16px") : currentIndex;
1878
+ const nextSize = FONT_SIZES[Math.max(fromIndex - 1, 0)];
1878
1879
  return editor.chain().focus().setFontSize(nextSize).run();
1879
1880
  }
1880
1881
  };
@@ -7300,23 +7301,32 @@ function ColorPicker({ type = "text" }) {
7300
7301
  (value) => {
7301
7302
  if (!editor) return;
7302
7303
  const { state } = editor;
7303
- const { $from, $to, empty } = state.selection;
7304
+ const { $from } = state.selection;
7304
7305
  editor.chain().focus().setColor(value).run();
7305
- const depth = $from.depth;
7306
- const nodePos = $from.before(depth);
7307
- const node = $from.node(depth);
7308
- const supportsColor = [
7309
- "paragraph",
7310
- "heading",
7311
- "listItem",
7312
- "taskItem",
7313
- "blockquote"
7314
- ].includes(node.type.name);
7315
- if (supportsColor) {
7316
- const tr = state.tr.setNodeMarkup(nodePos, void 0, {
7317
- ...node.attrs,
7318
- color: value
7319
- });
7306
+ const tr = editor.state.tr;
7307
+ let trDirty = false;
7308
+ for (let depth = $from.depth; depth >= 1; depth--) {
7309
+ const node = $from.node(depth);
7310
+ const pos = $from.before(depth);
7311
+ const supportsColor = [
7312
+ "paragraph",
7313
+ "heading",
7314
+ "listItem",
7315
+ "taskItem",
7316
+ "blockquote"
7317
+ ].includes(node.type.name);
7318
+ if (supportsColor && node.attrs.color !== value) {
7319
+ tr.setNodeMarkup(pos, void 0, {
7320
+ ...node.attrs,
7321
+ color: value
7322
+ });
7323
+ trDirty = true;
7324
+ }
7325
+ if (node.type.name === "listItem" || node.type.name === "taskItem") {
7326
+ break;
7327
+ }
7328
+ }
7329
+ if (trDirty) {
7320
7330
  editor.view.dispatch(tr);
7321
7331
  }
7322
7332
  setTimeout(() => {
@@ -7397,7 +7407,7 @@ function ColorPicker({ type = "text" }) {
7397
7407
  {
7398
7408
  className: "flex flex-col gap-3",
7399
7409
  onMouseDown: (e) => e.stopPropagation(),
7400
- onMouseUp: ((e) => e.stopPropagation()),
7410
+ onMouseUp: (e) => e.stopPropagation(),
7401
7411
  onPointerDown: (e) => e.stopPropagation(),
7402
7412
  onPointerUp: (e) => e.stopPropagation(),
7403
7413
  onClick: (e) => e.stopPropagation(),
@@ -7827,6 +7837,7 @@ var ColorBlock = Extension3.create({
7827
7837
  }
7828
7838
  });
7829
7839
  var stylePersistenceKey = new PluginKey("stylePersistence");
7840
+ var STYLED_NODES = ["paragraph", "heading", "listItem", "taskItem", "blockquote"];
7830
7841
  var StylePersistence = Extension3.create({
7831
7842
  name: "stylePersistence",
7832
7843
  addOptions() {
@@ -7854,8 +7865,7 @@ var StylePersistence = Extension3.create({
7854
7865
  );
7855
7866
  let isInCodeBlock = false;
7856
7867
  for (let depth = $from.depth; depth > 0; depth--) {
7857
- const node = $from.node(depth);
7858
- if (node.type.name === "codeBlock") {
7868
+ if ($from.node(depth).type.name === "codeBlock") {
7859
7869
  isInCodeBlock = true;
7860
7870
  break;
7861
7871
  }
@@ -7863,16 +7873,17 @@ var StylePersistence = Extension3.create({
7863
7873
  if (hasExcludedMarks || isInCodeBlock) {
7864
7874
  return value;
7865
7875
  }
7866
- const parentNode = $from.parent;
7867
- let font = parentNode.attrs.fontFamily;
7868
- let color = parentNode.attrs.color;
7869
- const textStyleMark = marks.find((m) => m.type.name === "textStyle");
7870
- if (!font && textStyleMark?.attrs.fontFamily) {
7871
- font = textStyleMark.attrs.fontFamily;
7872
- }
7873
- if (!color && textStyleMark?.attrs.color) {
7874
- color = textStyleMark.attrs.color;
7876
+ let font = null;
7877
+ let color = null;
7878
+ for (let depth = $from.depth; depth >= 1; depth--) {
7879
+ const node = $from.node(depth);
7880
+ if (!font && node.attrs?.fontFamily) font = node.attrs.fontFamily;
7881
+ if (!color && node.attrs?.color) color = node.attrs.color;
7882
+ if (font && color) break;
7875
7883
  }
7884
+ const textStyleMark = marks.find((m) => m.type.name === "textStyle");
7885
+ if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
7886
+ if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
7876
7887
  return {
7877
7888
  lastFont: font || value.lastFont,
7878
7889
  lastColor: color || value.lastColor
@@ -7888,15 +7899,13 @@ var StylePersistence = Extension3.create({
7888
7899
  return null;
7889
7900
  }
7890
7901
  const { $from } = newState.selection;
7891
- const parentNode = $from.parent;
7892
7902
  const marks = $from.marks();
7893
7903
  const hasExcludedMarks = marks.some(
7894
7904
  (mark) => excludedMarks.includes(mark.type.name)
7895
7905
  );
7896
7906
  let isInCodeBlock = false;
7897
7907
  for (let depth = $from.depth; depth > 0; depth--) {
7898
- const node = $from.node(depth);
7899
- if (node.type.name === "codeBlock") {
7908
+ if ($from.node(depth).type.name === "codeBlock") {
7900
7909
  isInCodeBlock = true;
7901
7910
  break;
7902
7911
  }
@@ -7904,32 +7913,30 @@ var StylePersistence = Extension3.create({
7904
7913
  if (hasExcludedMarks || isInCodeBlock) {
7905
7914
  return null;
7906
7915
  }
7907
- const supportsAttributes = [
7908
- "paragraph",
7909
- "heading",
7910
- "listItem",
7911
- "taskItem",
7912
- "blockquote"
7913
- ].includes(parentNode.type.name);
7914
- if (!supportsAttributes) {
7915
- return null;
7916
- }
7917
- const currentFont = parentNode.attrs.fontFamily;
7918
- const currentColor = parentNode.attrs.color;
7919
- const needsFont = !currentFont && pluginState.lastFont;
7920
- const needsColor = !currentColor && pluginState.lastColor;
7921
- if (!needsFont && !needsColor) {
7922
- return null;
7923
- }
7924
7916
  const tr = newState.tr;
7925
- try {
7926
- const depth = $from.depth;
7927
- const pos = $from.before(depth);
7917
+ let trDirty = false;
7918
+ for (let depth = $from.depth; depth >= 1; depth--) {
7928
7919
  const node = $from.node(depth);
7920
+ if (!STYLED_NODES.includes(node.type.name)) continue;
7921
+ const pos = $from.before(depth);
7922
+ const needsFont = !node.attrs.fontFamily && pluginState.lastFont;
7923
+ const needsColor = !node.attrs.color && pluginState.lastColor;
7924
+ if (!needsFont && !needsColor) {
7925
+ break;
7926
+ }
7929
7927
  const newAttrs = { ...node.attrs };
7930
7928
  if (needsFont) newAttrs.fontFamily = pluginState.lastFont;
7931
7929
  if (needsColor) newAttrs.color = pluginState.lastColor;
7932
7930
  tr.setNodeMarkup(pos, void 0, newAttrs);
7931
+ trDirty = true;
7932
+ if (node.type.name === "listItem" || node.type.name === "taskItem") {
7933
+ break;
7934
+ }
7935
+ }
7936
+ if (!trDirty) {
7937
+ return null;
7938
+ }
7939
+ try {
7933
7940
  const storedMarks = newState.storedMarks || $from.marks();
7934
7941
  const filteredMarks = storedMarks.filter(
7935
7942
  (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
@@ -7942,11 +7949,9 @@ var StylePersistence = Extension3.create({
7942
7949
  newState.schema.marks.textStyle.create(textStyleAttrs)
7943
7950
  ];
7944
7951
  tr.setStoredMarks(newMarks);
7945
- return tr;
7946
- } catch (error) {
7947
- console.error("StylePersistence error:", error);
7948
- return null;
7952
+ } catch (e) {
7949
7953
  }
7954
+ return tr;
7950
7955
  },
7951
7956
  props: {
7952
7957
  handleKeyDown(view, event) {
@@ -7954,33 +7959,28 @@ var StylePersistence = Extension3.create({
7954
7959
  const { state } = view;
7955
7960
  const { $from } = state.selection;
7956
7961
  const marks = $from.marks();
7957
- const hasExcludedMarks = marks.some(
7958
- (mark) => excludedMarks.includes(mark.type.name)
7959
- );
7960
- if (hasExcludedMarks) {
7962
+ if (marks.some((mark) => excludedMarks.includes(mark.type.name))) {
7961
7963
  return false;
7962
7964
  }
7963
7965
  let isInCodeBlock = false;
7964
7966
  for (let depth = $from.depth; depth > 0; depth--) {
7965
- const node = $from.node(depth);
7966
- if (node.type.name === "codeBlock") {
7967
+ if ($from.node(depth).type.name === "codeBlock") {
7967
7968
  isInCodeBlock = true;
7968
7969
  break;
7969
7970
  }
7970
7971
  }
7971
- if (isInCodeBlock) {
7972
- return false;
7972
+ if (isInCodeBlock) return false;
7973
+ let font = null;
7974
+ let color = null;
7975
+ for (let depth = $from.depth; depth >= 1; depth--) {
7976
+ const node = $from.node(depth);
7977
+ if (!font && node.attrs?.fontFamily) font = node.attrs.fontFamily;
7978
+ if (!color && node.attrs?.color) color = node.attrs.color;
7979
+ if (font && color) break;
7973
7980
  }
7974
- const parentNode = $from.parent;
7975
- let font = parentNode.attrs.fontFamily;
7976
- let color = parentNode.attrs.color;
7977
7981
  const textStyleMark = marks.find((m) => m.type.name === "textStyle");
7978
- if (!font && textStyleMark?.attrs.fontFamily) {
7979
- font = textStyleMark.attrs.fontFamily;
7980
- }
7981
- if (!color && textStyleMark?.attrs.color) {
7982
- color = textStyleMark.attrs.color;
7983
- }
7982
+ if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
7983
+ if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
7984
7984
  if (font || color) {
7985
7985
  const pluginState = stylePersistenceKey.getState(state);
7986
7986
  pluginState.lastFont = font || pluginState.lastFont;