@mhamz.01/easyflow-texteditor 0.1.88 → 0.1.90

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
@@ -7069,13 +7069,52 @@ var import_jsx_runtime76 = require("react/jsx-runtime");
7069
7069
  function FontFamilyDropdown() {
7070
7070
  const { editor } = (0, import_react85.useCurrentEditor)();
7071
7071
  const [open, setOpen] = (0, import_react86.useState)(false);
7072
+ const [selectedFont, setSelectedFont] = (0, import_react86.useState)(null);
7072
7073
  (0, import_react86.useEffect)(() => {
7073
7074
  loadGoogleFonts();
7074
7075
  }, []);
7076
+ (0, import_react86.useEffect)(() => {
7077
+ if (!editor) return;
7078
+ const updateSelectedFont = () => {
7079
+ const currentFontFamily2 = editor.getAttributes("textStyle").fontFamily;
7080
+ if (currentFontFamily2) {
7081
+ setSelectedFont(currentFontFamily2);
7082
+ }
7083
+ };
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;
7095
+ const currentFontFamily2 = editor.getAttributes("textStyle").fontFamily;
7096
+ if (!currentFontFamily2 && selectedFont) {
7097
+ editor.chain().focus().setFontFamily(selectedFont).run();
7098
+ }
7099
+ };
7100
+ editor.on("update", handleUpdate);
7101
+ return () => {
7102
+ editor.off("update", handleUpdate);
7103
+ };
7104
+ }, [editor, selectedFont]);
7075
7105
  if (!editor) return null;
7076
- const currentFont = editor.getAttributes("textStyle").fontFamily || "Font Family";
7106
+ const currentFontFamily = editor.getAttributes("textStyle").fontFamily || selectedFont;
7107
+ const getCurrentFontLabel = () => {
7108
+ if (!currentFontFamily) return "Font Family";
7109
+ const matchedFont = FONT_OPTIONS.find(
7110
+ (font) => font.cssFontFamily === currentFontFamily
7111
+ );
7112
+ return matchedFont ? matchedFont.label : "Font Family";
7113
+ };
7114
+ const currentFont = getCurrentFontLabel();
7077
7115
  const applyFont = (family) => {
7078
7116
  if (!editor) return;
7117
+ setSelectedFont(family);
7079
7118
  if (editor.state.storedMarks) {
7080
7119
  const textStyleMark = editor.schema.marks.textStyle;
7081
7120
  if (textStyleMark) {
@@ -7089,6 +7128,22 @@ function FontFamilyDropdown() {
7089
7128
  }
7090
7129
  }, 0);
7091
7130
  };
7131
+ const resetFont = () => {
7132
+ if (!editor) return;
7133
+ setSelectedFont(null);
7134
+ if (editor.state.storedMarks) {
7135
+ const textStyleMark = editor.schema.marks.textStyle;
7136
+ if (textStyleMark) {
7137
+ editor.view.dispatch(
7138
+ editor.state.tr.removeStoredMark(textStyleMark)
7139
+ );
7140
+ }
7141
+ }
7142
+ setTimeout(() => {
7143
+ editor.chain().focus().unsetFontFamily().run();
7144
+ setOpen(false);
7145
+ }, 0);
7146
+ };
7092
7147
  return /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Popover2, { open, onOpenChange: setOpen, children: [
7093
7148
  /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(
7094
7149
  Button,
@@ -7120,21 +7175,7 @@ function FontFamilyDropdown() {
7120
7175
  /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
7121
7176
  CommandItem,
7122
7177
  {
7123
- onSelect: () => {
7124
- if (!editor) return;
7125
- if (editor.state.storedMarks) {
7126
- const textStyleMark = editor.schema.marks.textStyle;
7127
- if (textStyleMark) {
7128
- editor.view.dispatch(
7129
- editor.state.tr.removeStoredMark(textStyleMark)
7130
- );
7131
- }
7132
- }
7133
- setTimeout(() => {
7134
- editor.chain().focus().unsetFontFamily().run();
7135
- setOpen(false);
7136
- }, 0);
7137
- },
7178
+ onSelect: resetFont,
7138
7179
  className: "font-sans",
7139
7180
  children: "Default"
7140
7181
  },