@mhamz.01/easyflow-texteditor 0.1.141 → 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
@@ -7560,6 +7560,116 @@ function useCursorVisibility({
7560
7560
  return rect;
7561
7561
  }
7562
7562
 
7563
+ // src/components/extensions/font-family-block.ts
7564
+ var import_core4 = require("@tiptap/core");
7565
+ var FontFamilyBlock = import_core4.Extension.create({
7566
+ name: "fontFamilyBlock",
7567
+ addGlobalAttributes() {
7568
+ return [
7569
+ {
7570
+ types: [
7571
+ "paragraph",
7572
+ "heading",
7573
+ "listItem",
7574
+ "taskItem",
7575
+ "blockquote"
7576
+ ],
7577
+ attributes: {
7578
+ fontFamily: {
7579
+ default: null,
7580
+ parseHTML: (element) => element.style.fontFamily?.replace(/['"]/g, "") || null,
7581
+ renderHTML: (attributes) => {
7582
+ if (!attributes.fontFamily) return {};
7583
+ return {
7584
+ style: `font-family: ${attributes.fontFamily}`
7585
+ };
7586
+ }
7587
+ }
7588
+ }
7589
+ }
7590
+ ];
7591
+ }
7592
+ });
7593
+ var FontFamilyPersistence = import_core4.Extension.create({
7594
+ name: "fontFamilyPersistence",
7595
+ addOptions() {
7596
+ return {
7597
+ // Marks that should NOT inherit font family
7598
+ excludedMarks: ["code", "codeBlock"]
7599
+ };
7600
+ },
7601
+ onSelectionUpdate({ editor }) {
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
+ }
7622
+ const font = state.selection.$from.parent.attrs.fontFamily;
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
+ ];
7632
+ editor.view.dispatch(
7633
+ state.tr.setStoredMarks(newMarks)
7634
+ );
7635
+ },
7636
+ onFocus({ editor }) {
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
+ }
7657
+ const font = state.selection.$from.parent.attrs.fontFamily;
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
+ ];
7667
+ editor.view.dispatch(
7668
+ state.tr.setStoredMarks(newMarks)
7669
+ );
7670
+ }
7671
+ });
7672
+
7563
7673
  // src/components/tiptap-templates/simple/simple-editor.tsx
7564
7674
  var import_jsx_runtime81 = require("react/jsx-runtime");
7565
7675
  var MainToolbarContent = ({
@@ -7670,6 +7780,8 @@ function SimpleEditor() {
7670
7780
  import_extension_superscript.Superscript,
7671
7781
  import_extension_subscript.Subscript,
7672
7782
  import_extensions.Selection,
7783
+ FontFamilyBlock,
7784
+ FontFamilyPersistence,
7673
7785
  ImageUploadNode2.configure({
7674
7786
  accept: "image/*",
7675
7787
  maxSize: MAX_FILE_SIZE,