@mhamz.01/easyflow-texteditor 0.1.156 → 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(),
@@ -7826,50 +7835,8 @@ var ColorBlock = Extension3.create({
7826
7835
  ];
7827
7836
  }
7828
7837
  });
7829
- var ListMarkerColor2 = Extension3.create({
7830
- name: "listMarkerColor",
7831
- onCreate() {
7832
- if (typeof document !== "undefined") {
7833
- const styleId = "tiptap-list-marker-color";
7834
- if (!document.getElementById(styleId)) {
7835
- const style = document.createElement("style");
7836
- style.id = styleId;
7837
- style.textContent = `
7838
- /* Bullet list markers inherit color */
7839
- .ProseMirror ul > li[style*="color"]::marker {
7840
- color: inherit !important;
7841
- }
7842
-
7843
- /* Ordered list numbers inherit color */
7844
- .ProseMirror ol > li[style*="color"]::marker {
7845
- color: inherit !important;
7846
- }
7847
-
7848
- /* Task list checkboxes inherit color */
7849
- .ProseMirror ul[data-type="taskList"] > li[style*="color"] > label > input[type="checkbox"] {
7850
- accent-color: currentColor;
7851
- }
7852
-
7853
- /* Ensure nested lists also inherit */
7854
- .ProseMirror li[style*="color"] ul > li::marker,
7855
- .ProseMirror li[style*="color"] ol > li::marker {
7856
- color: inherit !important;
7857
- }
7858
- `;
7859
- document.head.appendChild(style);
7860
- }
7861
- }
7862
- },
7863
- onDestroy() {
7864
- if (typeof document !== "undefined") {
7865
- const styleElement = document.getElementById("tiptap-list-marker-color");
7866
- if (styleElement) {
7867
- styleElement.remove();
7868
- }
7869
- }
7870
- }
7871
- });
7872
7838
  var stylePersistenceKey = new PluginKey("stylePersistence");
7839
+ var STYLED_NODES = ["paragraph", "heading", "listItem", "taskItem", "blockquote"];
7873
7840
  var StylePersistence = Extension3.create({
7874
7841
  name: "stylePersistence",
7875
7842
  addOptions() {
@@ -7897,8 +7864,7 @@ var StylePersistence = Extension3.create({
7897
7864
  );
7898
7865
  let isInCodeBlock = false;
7899
7866
  for (let depth = $from.depth; depth > 0; depth--) {
7900
- const node = $from.node(depth);
7901
- if (node.type.name === "codeBlock") {
7867
+ if ($from.node(depth).type.name === "codeBlock") {
7902
7868
  isInCodeBlock = true;
7903
7869
  break;
7904
7870
  }
@@ -7906,16 +7872,17 @@ var StylePersistence = Extension3.create({
7906
7872
  if (hasExcludedMarks || isInCodeBlock) {
7907
7873
  return value;
7908
7874
  }
7909
- const parentNode = $from.parent;
7910
- let font = parentNode.attrs.fontFamily;
7911
- let color = parentNode.attrs.color;
7912
- const textStyleMark = marks.find((m) => m.type.name === "textStyle");
7913
- if (!font && textStyleMark?.attrs.fontFamily) {
7914
- font = textStyleMark.attrs.fontFamily;
7915
- }
7916
- if (!color && textStyleMark?.attrs.color) {
7917
- 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;
7918
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;
7919
7886
  return {
7920
7887
  lastFont: font || value.lastFont,
7921
7888
  lastColor: color || value.lastColor
@@ -7931,15 +7898,13 @@ var StylePersistence = Extension3.create({
7931
7898
  return null;
7932
7899
  }
7933
7900
  const { $from } = newState.selection;
7934
- const parentNode = $from.parent;
7935
7901
  const marks = $from.marks();
7936
7902
  const hasExcludedMarks = marks.some(
7937
7903
  (mark) => excludedMarks.includes(mark.type.name)
7938
7904
  );
7939
7905
  let isInCodeBlock = false;
7940
7906
  for (let depth = $from.depth; depth > 0; depth--) {
7941
- const node = $from.node(depth);
7942
- if (node.type.name === "codeBlock") {
7907
+ if ($from.node(depth).type.name === "codeBlock") {
7943
7908
  isInCodeBlock = true;
7944
7909
  break;
7945
7910
  }
@@ -7947,32 +7912,30 @@ var StylePersistence = Extension3.create({
7947
7912
  if (hasExcludedMarks || isInCodeBlock) {
7948
7913
  return null;
7949
7914
  }
7950
- const supportsAttributes = [
7951
- "paragraph",
7952
- "heading",
7953
- "listItem",
7954
- "taskItem",
7955
- "blockquote"
7956
- ].includes(parentNode.type.name);
7957
- if (!supportsAttributes) {
7958
- return null;
7959
- }
7960
- const currentFont = parentNode.attrs.fontFamily;
7961
- const currentColor = parentNode.attrs.color;
7962
- const needsFont = !currentFont && pluginState.lastFont;
7963
- const needsColor = !currentColor && pluginState.lastColor;
7964
- if (!needsFont && !needsColor) {
7965
- return null;
7966
- }
7967
7915
  const tr = newState.tr;
7968
- try {
7969
- const depth = $from.depth;
7970
- const pos = $from.before(depth);
7916
+ let trDirty = false;
7917
+ for (let depth = $from.depth; depth >= 1; depth--) {
7971
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
+ }
7972
7926
  const newAttrs = { ...node.attrs };
7973
7927
  if (needsFont) newAttrs.fontFamily = pluginState.lastFont;
7974
7928
  if (needsColor) newAttrs.color = pluginState.lastColor;
7975
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 {
7976
7939
  const storedMarks = newState.storedMarks || $from.marks();
7977
7940
  const filteredMarks = storedMarks.filter(
7978
7941
  (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
@@ -7985,11 +7948,9 @@ var StylePersistence = Extension3.create({
7985
7948
  newState.schema.marks.textStyle.create(textStyleAttrs)
7986
7949
  ];
7987
7950
  tr.setStoredMarks(newMarks);
7988
- return tr;
7989
- } catch (error) {
7990
- console.error("StylePersistence error:", error);
7991
- return null;
7951
+ } catch (e) {
7992
7952
  }
7953
+ return tr;
7993
7954
  },
7994
7955
  props: {
7995
7956
  handleKeyDown(view, event) {
@@ -7997,33 +7958,28 @@ var StylePersistence = Extension3.create({
7997
7958
  const { state } = view;
7998
7959
  const { $from } = state.selection;
7999
7960
  const marks = $from.marks();
8000
- const hasExcludedMarks = marks.some(
8001
- (mark) => excludedMarks.includes(mark.type.name)
8002
- );
8003
- if (hasExcludedMarks) {
7961
+ if (marks.some((mark) => excludedMarks.includes(mark.type.name))) {
8004
7962
  return false;
8005
7963
  }
8006
7964
  let isInCodeBlock = false;
8007
7965
  for (let depth = $from.depth; depth > 0; depth--) {
8008
- const node = $from.node(depth);
8009
- if (node.type.name === "codeBlock") {
7966
+ if ($from.node(depth).type.name === "codeBlock") {
8010
7967
  isInCodeBlock = true;
8011
7968
  break;
8012
7969
  }
8013
7970
  }
8014
- if (isInCodeBlock) {
8015
- 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;
8016
7979
  }
8017
- const parentNode = $from.parent;
8018
- let font = parentNode.attrs.fontFamily;
8019
- let color = parentNode.attrs.color;
8020
7980
  const textStyleMark = marks.find((m) => m.type.name === "textStyle");
8021
- if (!font && textStyleMark?.attrs.fontFamily) {
8022
- font = textStyleMark.attrs.fontFamily;
8023
- }
8024
- if (!color && textStyleMark?.attrs.color) {
8025
- color = textStyleMark.attrs.color;
8026
- }
7981
+ if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
7982
+ if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
8027
7983
  if (font || color) {
8028
7984
  const pluginState = stylePersistenceKey.getState(state);
8029
7985
  pluginState.lastFont = font || pluginState.lastFont;