@mhamz.01/easyflow-texteditor 0.1.142 → 0.1.145

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
@@ -7564,11 +7564,39 @@ var FontFamilyBlock = Extension2.create({
7564
7564
  ];
7565
7565
  }
7566
7566
  });
7567
- var FontFamilyPersistence = Extension2.create({
7568
- name: "fontFamilyPersistence",
7567
+ var ColorBlock = Extension2.create({
7568
+ name: "colorBlock",
7569
+ addGlobalAttributes() {
7570
+ return [
7571
+ {
7572
+ types: [
7573
+ "paragraph",
7574
+ "heading",
7575
+ "listItem",
7576
+ "taskItem",
7577
+ "blockquote"
7578
+ ],
7579
+ attributes: {
7580
+ color: {
7581
+ default: null,
7582
+ parseHTML: (element) => element.style.color || null,
7583
+ renderHTML: (attributes) => {
7584
+ if (!attributes.color) return {};
7585
+ return {
7586
+ style: `color: ${attributes.color}`
7587
+ };
7588
+ }
7589
+ }
7590
+ }
7591
+ }
7592
+ ];
7593
+ }
7594
+ });
7595
+ var StylePersistence = Extension2.create({
7596
+ name: "stylePersistence",
7569
7597
  addOptions() {
7570
7598
  return {
7571
- // Marks that should NOT inherit font family
7599
+ // Marks that should NOT inherit font family or color
7572
7600
  excludedMarks: ["code", "codeBlock"]
7573
7601
  };
7574
7602
  },
@@ -7593,15 +7621,26 @@ var FontFamilyPersistence = Extension2.create({
7593
7621
  if (hasExcludedMarks() || isInCodeBlock()) {
7594
7622
  return;
7595
7623
  }
7596
- const font = state.selection.$from.parent.attrs.fontFamily;
7597
- if (!font) return;
7624
+ const blockFont = state.selection.$from.parent.attrs.fontFamily;
7625
+ const blockColor = state.selection.$from.parent.attrs.color;
7626
+ const existingTextStyleMark = state.selection.$from.marks().find(
7627
+ (mark) => mark.type.name === "textStyle"
7628
+ );
7629
+ const markFont = existingTextStyleMark?.attrs.fontFamily;
7630
+ const markColor = existingTextStyleMark?.attrs.color;
7631
+ const finalFont = markFont || blockFont;
7632
+ const finalColor = markColor || blockColor;
7633
+ if (!finalFont && !finalColor) return;
7598
7634
  const storedMarks = state.storedMarks || state.selection.$from.marks();
7599
7635
  const filteredMarks = storedMarks.filter(
7600
7636
  (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7601
7637
  );
7638
+ const textStyleAttrs = {};
7639
+ if (finalFont) textStyleAttrs.fontFamily = finalFont;
7640
+ if (finalColor) textStyleAttrs.color = finalColor;
7602
7641
  const newMarks = [
7603
7642
  ...filteredMarks,
7604
- state.schema.marks.textStyle.create({ fontFamily: font })
7643
+ state.schema.marks.textStyle.create(textStyleAttrs)
7605
7644
  ];
7606
7645
  editor.view.dispatch(
7607
7646
  state.tr.setStoredMarks(newMarks)
@@ -7628,15 +7667,78 @@ var FontFamilyPersistence = Extension2.create({
7628
7667
  if (hasExcludedMarks() || isInCodeBlock()) {
7629
7668
  return;
7630
7669
  }
7631
- const font = state.selection.$from.parent.attrs.fontFamily;
7632
- if (!font) return;
7670
+ const blockFont = state.selection.$from.parent.attrs.fontFamily;
7671
+ const blockColor = state.selection.$from.parent.attrs.color;
7672
+ const existingTextStyleMark = state.selection.$from.marks().find(
7673
+ (mark) => mark.type.name === "textStyle"
7674
+ );
7675
+ const markFont = existingTextStyleMark?.attrs.fontFamily;
7676
+ const markColor = existingTextStyleMark?.attrs.color;
7677
+ const finalFont = markFont || blockFont;
7678
+ const finalColor = markColor || blockColor;
7679
+ if (!finalFont && !finalColor) return;
7680
+ const storedMarks = state.storedMarks || state.selection.$from.marks();
7681
+ const filteredMarks = storedMarks.filter(
7682
+ (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7683
+ );
7684
+ const textStyleAttrs = {};
7685
+ if (finalFont) textStyleAttrs.fontFamily = finalFont;
7686
+ if (finalColor) textStyleAttrs.color = finalColor;
7687
+ const newMarks = [
7688
+ ...filteredMarks,
7689
+ state.schema.marks.textStyle.create(textStyleAttrs)
7690
+ ];
7691
+ editor.view.dispatch(
7692
+ state.tr.setStoredMarks(newMarks)
7693
+ );
7694
+ },
7695
+ // CRITICAL: Handle transaction updates to catch any textStyle changes
7696
+ onTransaction({ editor, transaction }) {
7697
+ if (!transaction.selectionSet && !transaction.docChanged) return;
7698
+ const { state } = editor;
7699
+ const excludedMarks = this.options.excludedMarks;
7700
+ const hasExcludedMarks = () => {
7701
+ const { $from } = state.selection;
7702
+ const marks = $from.marks();
7703
+ return marks.some((mark) => excludedMarks.includes(mark.type.name));
7704
+ };
7705
+ const isInCodeBlock = () => {
7706
+ const { $from } = state.selection;
7707
+ for (let depth = $from.depth; depth > 0; depth--) {
7708
+ const node = $from.node(depth);
7709
+ if (node.type.name === "codeBlock") {
7710
+ return true;
7711
+ }
7712
+ }
7713
+ return false;
7714
+ };
7715
+ if (hasExcludedMarks() || isInCodeBlock()) {
7716
+ return;
7717
+ }
7718
+ const blockFont = state.selection.$from.parent.attrs.fontFamily;
7719
+ const blockColor = state.selection.$from.parent.attrs.color;
7720
+ const existingTextStyleMark = state.selection.$from.marks().find(
7721
+ (mark) => mark.type.name === "textStyle"
7722
+ );
7723
+ const markFont = existingTextStyleMark?.attrs.fontFamily;
7724
+ const markColor = existingTextStyleMark?.attrs.color;
7725
+ const finalFont = markFont || blockFont;
7726
+ const finalColor = markColor || blockColor;
7727
+ if (!finalFont && !finalColor) return;
7633
7728
  const storedMarks = state.storedMarks || state.selection.$from.marks();
7729
+ const existingStoredTextStyle = storedMarks.find((mark) => mark.type.name === "textStyle");
7730
+ const hasCorrectFont = !finalFont || existingStoredTextStyle?.attrs.fontFamily === finalFont;
7731
+ const hasCorrectColor = !finalColor || existingStoredTextStyle?.attrs.color === finalColor;
7732
+ if (hasCorrectFont && hasCorrectColor && existingStoredTextStyle) return;
7634
7733
  const filteredMarks = storedMarks.filter(
7635
7734
  (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7636
7735
  );
7736
+ const textStyleAttrs = {};
7737
+ if (finalFont) textStyleAttrs.fontFamily = finalFont;
7738
+ if (finalColor) textStyleAttrs.color = finalColor;
7637
7739
  const newMarks = [
7638
7740
  ...filteredMarks,
7639
- state.schema.marks.textStyle.create({ fontFamily: font })
7741
+ state.schema.marks.textStyle.create(textStyleAttrs)
7640
7742
  ];
7641
7743
  editor.view.dispatch(
7642
7744
  state.tr.setStoredMarks(newMarks)
@@ -7755,7 +7857,8 @@ function SimpleEditor() {
7755
7857
  Subscript,
7756
7858
  Selection2,
7757
7859
  FontFamilyBlock,
7758
- FontFamilyPersistence,
7860
+ ColorBlock,
7861
+ StylePersistence,
7759
7862
  ImageUploadNode2.configure({
7760
7863
  accept: "image/*",
7761
7864
  maxSize: MAX_FILE_SIZE,