@mhamz.01/easyflow-texteditor 0.1.140 → 0.1.142

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
@@ -7566,24 +7566,80 @@ var FontFamilyBlock = Extension2.create({
7566
7566
  });
7567
7567
  var FontFamilyPersistence = Extension2.create({
7568
7568
  name: "fontFamilyPersistence",
7569
+ addOptions() {
7570
+ return {
7571
+ // Marks that should NOT inherit font family
7572
+ excludedMarks: ["code", "codeBlock"]
7573
+ };
7574
+ },
7569
7575
  onSelectionUpdate({ editor }) {
7570
7576
  const { state } = editor;
7577
+ const excludedMarks = this.options.excludedMarks;
7578
+ const hasExcludedMarks = () => {
7579
+ const { $from } = state.selection;
7580
+ const marks = $from.marks();
7581
+ return marks.some((mark) => excludedMarks.includes(mark.type.name));
7582
+ };
7583
+ const isInCodeBlock = () => {
7584
+ const { $from } = state.selection;
7585
+ for (let depth = $from.depth; depth > 0; depth--) {
7586
+ const node = $from.node(depth);
7587
+ if (node.type.name === "codeBlock") {
7588
+ return true;
7589
+ }
7590
+ }
7591
+ return false;
7592
+ };
7593
+ if (hasExcludedMarks() || isInCodeBlock()) {
7594
+ return;
7595
+ }
7571
7596
  const font = state.selection.$from.parent.attrs.fontFamily;
7572
7597
  if (!font) return;
7598
+ const storedMarks = state.storedMarks || state.selection.$from.marks();
7599
+ const filteredMarks = storedMarks.filter(
7600
+ (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7601
+ );
7602
+ const newMarks = [
7603
+ ...filteredMarks,
7604
+ state.schema.marks.textStyle.create({ fontFamily: font })
7605
+ ];
7573
7606
  editor.view.dispatch(
7574
- state.tr.setStoredMarks([
7575
- state.schema.marks.textStyle.create({ fontFamily: font })
7576
- ])
7607
+ state.tr.setStoredMarks(newMarks)
7577
7608
  );
7578
7609
  },
7579
7610
  onFocus({ editor }) {
7580
7611
  const { state } = editor;
7612
+ const excludedMarks = this.options.excludedMarks;
7613
+ const hasExcludedMarks = () => {
7614
+ const { $from } = state.selection;
7615
+ const marks = $from.marks();
7616
+ return marks.some((mark) => excludedMarks.includes(mark.type.name));
7617
+ };
7618
+ const isInCodeBlock = () => {
7619
+ const { $from } = state.selection;
7620
+ for (let depth = $from.depth; depth > 0; depth--) {
7621
+ const node = $from.node(depth);
7622
+ if (node.type.name === "codeBlock") {
7623
+ return true;
7624
+ }
7625
+ }
7626
+ return false;
7627
+ };
7628
+ if (hasExcludedMarks() || isInCodeBlock()) {
7629
+ return;
7630
+ }
7581
7631
  const font = state.selection.$from.parent.attrs.fontFamily;
7582
7632
  if (!font) return;
7633
+ const storedMarks = state.storedMarks || state.selection.$from.marks();
7634
+ const filteredMarks = storedMarks.filter(
7635
+ (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7636
+ );
7637
+ const newMarks = [
7638
+ ...filteredMarks,
7639
+ state.schema.marks.textStyle.create({ fontFamily: font })
7640
+ ];
7583
7641
  editor.view.dispatch(
7584
- state.tr.setStoredMarks([
7585
- state.schema.marks.textStyle.create({ fontFamily: font })
7586
- ])
7642
+ state.tr.setStoredMarks(newMarks)
7587
7643
  );
7588
7644
  }
7589
7645
  });