@mhamz.01/easyflow-texteditor 0.1.157 → 0.1.158

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
@@ -7300,23 +7300,32 @@ function ColorPicker({ type = "text" }) {
7300
7300
  (value) => {
7301
7301
  if (!editor) return;
7302
7302
  const { state } = editor;
7303
- const { $from, $to, empty } = state.selection;
7303
+ const { $from } = state.selection;
7304
7304
  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
- });
7305
+ const tr = editor.state.tr;
7306
+ let trDirty = false;
7307
+ for (let depth = $from.depth; depth >= 1; depth--) {
7308
+ const node = $from.node(depth);
7309
+ const pos = $from.before(depth);
7310
+ const supportsColor = [
7311
+ "paragraph",
7312
+ "heading",
7313
+ "listItem",
7314
+ "taskItem",
7315
+ "blockquote"
7316
+ ].includes(node.type.name);
7317
+ if (supportsColor && node.attrs.color !== value) {
7318
+ tr.setNodeMarkup(pos, void 0, {
7319
+ ...node.attrs,
7320
+ color: value
7321
+ });
7322
+ trDirty = true;
7323
+ }
7324
+ if (node.type.name === "listItem" || node.type.name === "taskItem") {
7325
+ break;
7326
+ }
7327
+ }
7328
+ if (trDirty) {
7320
7329
  editor.view.dispatch(tr);
7321
7330
  }
7322
7331
  setTimeout(() => {
@@ -7397,7 +7406,7 @@ function ColorPicker({ type = "text" }) {
7397
7406
  {
7398
7407
  className: "flex flex-col gap-3",
7399
7408
  onMouseDown: (e) => e.stopPropagation(),
7400
- onMouseUp: ((e) => e.stopPropagation()),
7409
+ onMouseUp: (e) => e.stopPropagation(),
7401
7410
  onPointerDown: (e) => e.stopPropagation(),
7402
7411
  onPointerUp: (e) => e.stopPropagation(),
7403
7412
  onClick: (e) => e.stopPropagation(),
@@ -7827,6 +7836,7 @@ var ColorBlock = Extension3.create({
7827
7836
  }
7828
7837
  });
7829
7838
  var stylePersistenceKey = new PluginKey("stylePersistence");
7839
+ var STYLED_NODES = ["paragraph", "heading", "listItem", "taskItem", "blockquote"];
7830
7840
  var StylePersistence = Extension3.create({
7831
7841
  name: "stylePersistence",
7832
7842
  addOptions() {
@@ -7854,8 +7864,7 @@ var StylePersistence = Extension3.create({
7854
7864
  );
7855
7865
  let isInCodeBlock = false;
7856
7866
  for (let depth = $from.depth; depth > 0; depth--) {
7857
- const node = $from.node(depth);
7858
- if (node.type.name === "codeBlock") {
7867
+ if ($from.node(depth).type.name === "codeBlock") {
7859
7868
  isInCodeBlock = true;
7860
7869
  break;
7861
7870
  }
@@ -7863,16 +7872,17 @@ var StylePersistence = Extension3.create({
7863
7872
  if (hasExcludedMarks || isInCodeBlock) {
7864
7873
  return value;
7865
7874
  }
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;
7875
+ let font = null;
7876
+ let color = null;
7877
+ for (let depth = $from.depth; depth >= 1; depth--) {
7878
+ const node = $from.node(depth);
7879
+ if (!font && node.attrs?.fontFamily) font = node.attrs.fontFamily;
7880
+ if (!color && node.attrs?.color) color = node.attrs.color;
7881
+ if (font && color) break;
7875
7882
  }
7883
+ const textStyleMark = marks.find((m) => m.type.name === "textStyle");
7884
+ if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
7885
+ if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
7876
7886
  return {
7877
7887
  lastFont: font || value.lastFont,
7878
7888
  lastColor: color || value.lastColor
@@ -7888,15 +7898,13 @@ var StylePersistence = Extension3.create({
7888
7898
  return null;
7889
7899
  }
7890
7900
  const { $from } = newState.selection;
7891
- const parentNode = $from.parent;
7892
7901
  const marks = $from.marks();
7893
7902
  const hasExcludedMarks = marks.some(
7894
7903
  (mark) => excludedMarks.includes(mark.type.name)
7895
7904
  );
7896
7905
  let isInCodeBlock = false;
7897
7906
  for (let depth = $from.depth; depth > 0; depth--) {
7898
- const node = $from.node(depth);
7899
- if (node.type.name === "codeBlock") {
7907
+ if ($from.node(depth).type.name === "codeBlock") {
7900
7908
  isInCodeBlock = true;
7901
7909
  break;
7902
7910
  }
@@ -7904,32 +7912,30 @@ var StylePersistence = Extension3.create({
7904
7912
  if (hasExcludedMarks || isInCodeBlock) {
7905
7913
  return null;
7906
7914
  }
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
7915
  const tr = newState.tr;
7925
- try {
7926
- const depth = $from.depth;
7927
- const pos = $from.before(depth);
7916
+ let trDirty = false;
7917
+ for (let depth = $from.depth; depth >= 1; depth--) {
7928
7918
  const node = $from.node(depth);
7919
+ if (!STYLED_NODES.includes(node.type.name)) continue;
7920
+ const pos = $from.before(depth);
7921
+ const needsFont = !node.attrs.fontFamily && pluginState.lastFont;
7922
+ const needsColor = !node.attrs.color && pluginState.lastColor;
7923
+ if (!needsFont && !needsColor) {
7924
+ break;
7925
+ }
7929
7926
  const newAttrs = { ...node.attrs };
7930
7927
  if (needsFont) newAttrs.fontFamily = pluginState.lastFont;
7931
7928
  if (needsColor) newAttrs.color = pluginState.lastColor;
7932
7929
  tr.setNodeMarkup(pos, void 0, newAttrs);
7930
+ trDirty = true;
7931
+ if (node.type.name === "listItem" || node.type.name === "taskItem") {
7932
+ break;
7933
+ }
7934
+ }
7935
+ if (!trDirty) {
7936
+ return null;
7937
+ }
7938
+ try {
7933
7939
  const storedMarks = newState.storedMarks || $from.marks();
7934
7940
  const filteredMarks = storedMarks.filter(
7935
7941
  (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
@@ -7942,11 +7948,9 @@ var StylePersistence = Extension3.create({
7942
7948
  newState.schema.marks.textStyle.create(textStyleAttrs)
7943
7949
  ];
7944
7950
  tr.setStoredMarks(newMarks);
7945
- return tr;
7946
- } catch (error) {
7947
- console.error("StylePersistence error:", error);
7948
- return null;
7951
+ } catch (e) {
7949
7952
  }
7953
+ return tr;
7950
7954
  },
7951
7955
  props: {
7952
7956
  handleKeyDown(view, event) {
@@ -7954,33 +7958,28 @@ var StylePersistence = Extension3.create({
7954
7958
  const { state } = view;
7955
7959
  const { $from } = state.selection;
7956
7960
  const marks = $from.marks();
7957
- const hasExcludedMarks = marks.some(
7958
- (mark) => excludedMarks.includes(mark.type.name)
7959
- );
7960
- if (hasExcludedMarks) {
7961
+ if (marks.some((mark) => excludedMarks.includes(mark.type.name))) {
7961
7962
  return false;
7962
7963
  }
7963
7964
  let isInCodeBlock = false;
7964
7965
  for (let depth = $from.depth; depth > 0; depth--) {
7965
- const node = $from.node(depth);
7966
- if (node.type.name === "codeBlock") {
7966
+ if ($from.node(depth).type.name === "codeBlock") {
7967
7967
  isInCodeBlock = true;
7968
7968
  break;
7969
7969
  }
7970
7970
  }
7971
- if (isInCodeBlock) {
7972
- return false;
7971
+ if (isInCodeBlock) return false;
7972
+ let font = null;
7973
+ let color = null;
7974
+ for (let depth = $from.depth; depth >= 1; depth--) {
7975
+ const node = $from.node(depth);
7976
+ if (!font && node.attrs?.fontFamily) font = node.attrs.fontFamily;
7977
+ if (!color && node.attrs?.color) color = node.attrs.color;
7978
+ if (font && color) break;
7973
7979
  }
7974
- const parentNode = $from.parent;
7975
- let font = parentNode.attrs.fontFamily;
7976
- let color = parentNode.attrs.color;
7977
7980
  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
- }
7981
+ if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
7982
+ if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
7984
7983
  if (font || color) {
7985
7984
  const pluginState = stylePersistenceKey.getState(state);
7986
7985
  pluginState.lastFont = font || pluginState.lastFont;