@mhamz.01/easyflow-texteditor 0.1.90 → 0.1.91

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
@@ -7074,34 +7074,55 @@ function FontFamilyDropdown() {
7074
7074
  loadGoogleFonts();
7075
7075
  }, []);
7076
7076
  (0, import_react86.useEffect)(() => {
7077
- if (!editor) return;
7078
- const updateSelectedFont = () => {
7077
+ if (!editor || !selectedFont) return;
7078
+ const handleUpdate = () => {
7079
7079
  const currentFontFamily2 = editor.getAttributes("textStyle").fontFamily;
7080
- if (currentFontFamily2) {
7081
- setSelectedFont(currentFontFamily2);
7080
+ if (!currentFontFamily2) {
7081
+ requestAnimationFrame(() => {
7082
+ editor.commands.setFontFamily(selectedFont);
7083
+ });
7082
7084
  }
7083
7085
  };
7084
- editor.on("selectionUpdate", updateSelectedFont);
7085
- editor.on("transaction", updateSelectedFont);
7086
- return () => {
7087
- editor.off("selectionUpdate", updateSelectedFont);
7088
- editor.off("transaction", updateSelectedFont);
7089
- };
7090
- }, [editor]);
7091
- (0, import_react86.useEffect)(() => {
7092
- if (!editor || !selectedFont) return;
7093
- const handleUpdate = () => {
7094
- const { from, to } = editor.state.selection;
7086
+ const handleSelectionUpdate = () => {
7095
7087
  const currentFontFamily2 = editor.getAttributes("textStyle").fontFamily;
7096
7088
  if (!currentFontFamily2 && selectedFont) {
7097
- editor.chain().focus().setFontFamily(selectedFont).run();
7089
+ requestAnimationFrame(() => {
7090
+ editor.commands.setFontFamily(selectedFont);
7091
+ });
7092
+ }
7093
+ };
7094
+ const handleTransaction = ({ transaction }) => {
7095
+ const isBlockChange = transaction.steps.some((step) => {
7096
+ return step.slice?.content?.content?.some(
7097
+ (node) => ["heading", "bulletList", "orderedList", "blockquote", "codeBlock"].includes(node.type?.name)
7098
+ );
7099
+ });
7100
+ if (isBlockChange && selectedFont) {
7101
+ requestAnimationFrame(() => {
7102
+ editor.commands.setFontFamily(selectedFont);
7103
+ });
7098
7104
  }
7099
7105
  };
7100
7106
  editor.on("update", handleUpdate);
7107
+ editor.on("selectionUpdate", handleSelectionUpdate);
7108
+ editor.on("transaction", handleTransaction);
7101
7109
  return () => {
7102
7110
  editor.off("update", handleUpdate);
7111
+ editor.off("selectionUpdate", handleSelectionUpdate);
7112
+ editor.off("transaction", handleTransaction);
7103
7113
  };
7104
7114
  }, [editor, selectedFont]);
7115
+ (0, import_react86.useEffect)(() => {
7116
+ if (!editor || !selectedFont) return;
7117
+ const { state } = editor;
7118
+ const { schema } = state;
7119
+ const textStyleMark = schema.marks.textStyle;
7120
+ if (textStyleMark) {
7121
+ const mark = textStyleMark.create({ fontFamily: selectedFont });
7122
+ const tr = state.tr.addStoredMark(mark);
7123
+ editor.view.dispatch(tr);
7124
+ }
7125
+ }, [editor, selectedFont]);
7105
7126
  if (!editor) return null;
7106
7127
  const currentFontFamily = editor.getAttributes("textStyle").fontFamily || selectedFont;
7107
7128
  const getCurrentFontLabel = () => {
@@ -7116,17 +7137,20 @@ function FontFamilyDropdown() {
7116
7137
  if (!editor) return;
7117
7138
  setSelectedFont(family);
7118
7139
  if (editor.state.storedMarks) {
7119
- const textStyleMark = editor.schema.marks.textStyle;
7120
- if (textStyleMark) {
7121
- editor.view.dispatch(editor.state.tr.removeStoredMark(textStyleMark));
7140
+ const textStyleMark2 = editor.schema.marks.textStyle;
7141
+ if (textStyleMark2) {
7142
+ editor.view.dispatch(editor.state.tr.removeStoredMark(textStyleMark2));
7122
7143
  }
7123
7144
  }
7124
- setTimeout(() => {
7125
- const success = editor.chain().focus().setFontFamily(family).run();
7126
- if (!success) {
7127
- console.warn("Font not applied:", family);
7128
- }
7129
- }, 0);
7145
+ editor.chain().focus().setFontFamily(family).run();
7146
+ const { state } = editor;
7147
+ const { schema } = state;
7148
+ const textStyleMark = schema.marks.textStyle;
7149
+ if (textStyleMark) {
7150
+ const mark = textStyleMark.create({ fontFamily: family });
7151
+ const tr = state.tr.addStoredMark(mark);
7152
+ editor.view.dispatch(tr);
7153
+ }
7130
7154
  };
7131
7155
  const resetFont = () => {
7132
7156
  if (!editor) return;
@@ -7139,10 +7163,8 @@ function FontFamilyDropdown() {
7139
7163
  );
7140
7164
  }
7141
7165
  }
7142
- setTimeout(() => {
7143
- editor.chain().focus().unsetFontFamily().run();
7144
- setOpen(false);
7145
- }, 0);
7166
+ editor.chain().focus().unsetFontFamily().run();
7167
+ setOpen(false);
7146
7168
  };
7147
7169
  return /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Popover2, { open, onOpenChange: setOpen, children: [
7148
7170
  /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(