@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.js CHANGED
@@ -7592,24 +7592,80 @@ var FontFamilyBlock = import_core4.Extension.create({
7592
7592
  });
7593
7593
  var FontFamilyPersistence = import_core4.Extension.create({
7594
7594
  name: "fontFamilyPersistence",
7595
+ addOptions() {
7596
+ return {
7597
+ // Marks that should NOT inherit font family
7598
+ excludedMarks: ["code", "codeBlock"]
7599
+ };
7600
+ },
7595
7601
  onSelectionUpdate({ editor }) {
7596
7602
  const { state } = editor;
7603
+ const excludedMarks = this.options.excludedMarks;
7604
+ const hasExcludedMarks = () => {
7605
+ const { $from } = state.selection;
7606
+ const marks = $from.marks();
7607
+ return marks.some((mark) => excludedMarks.includes(mark.type.name));
7608
+ };
7609
+ const isInCodeBlock = () => {
7610
+ const { $from } = state.selection;
7611
+ for (let depth = $from.depth; depth > 0; depth--) {
7612
+ const node = $from.node(depth);
7613
+ if (node.type.name === "codeBlock") {
7614
+ return true;
7615
+ }
7616
+ }
7617
+ return false;
7618
+ };
7619
+ if (hasExcludedMarks() || isInCodeBlock()) {
7620
+ return;
7621
+ }
7597
7622
  const font = state.selection.$from.parent.attrs.fontFamily;
7598
7623
  if (!font) return;
7624
+ const storedMarks = state.storedMarks || state.selection.$from.marks();
7625
+ const filteredMarks = storedMarks.filter(
7626
+ (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7627
+ );
7628
+ const newMarks = [
7629
+ ...filteredMarks,
7630
+ state.schema.marks.textStyle.create({ fontFamily: font })
7631
+ ];
7599
7632
  editor.view.dispatch(
7600
- state.tr.setStoredMarks([
7601
- state.schema.marks.textStyle.create({ fontFamily: font })
7602
- ])
7633
+ state.tr.setStoredMarks(newMarks)
7603
7634
  );
7604
7635
  },
7605
7636
  onFocus({ editor }) {
7606
7637
  const { state } = editor;
7638
+ const excludedMarks = this.options.excludedMarks;
7639
+ const hasExcludedMarks = () => {
7640
+ const { $from } = state.selection;
7641
+ const marks = $from.marks();
7642
+ return marks.some((mark) => excludedMarks.includes(mark.type.name));
7643
+ };
7644
+ const isInCodeBlock = () => {
7645
+ const { $from } = state.selection;
7646
+ for (let depth = $from.depth; depth > 0; depth--) {
7647
+ const node = $from.node(depth);
7648
+ if (node.type.name === "codeBlock") {
7649
+ return true;
7650
+ }
7651
+ }
7652
+ return false;
7653
+ };
7654
+ if (hasExcludedMarks() || isInCodeBlock()) {
7655
+ return;
7656
+ }
7607
7657
  const font = state.selection.$from.parent.attrs.fontFamily;
7608
7658
  if (!font) return;
7659
+ const storedMarks = state.storedMarks || state.selection.$from.marks();
7660
+ const filteredMarks = storedMarks.filter(
7661
+ (mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
7662
+ );
7663
+ const newMarks = [
7664
+ ...filteredMarks,
7665
+ state.schema.marks.textStyle.create({ fontFamily: font })
7666
+ ];
7609
7667
  editor.view.dispatch(
7610
- state.tr.setStoredMarks([
7611
- state.schema.marks.textStyle.create({ fontFamily: font })
7612
- ])
7668
+ state.tr.setStoredMarks(newMarks)
7613
7669
  );
7614
7670
  }
7615
7671
  });