@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.css +24 -24
- package/dist/index.css.map +1 -1
- package/dist/index.js +57 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7043,13 +7043,52 @@ import { jsx as jsx76, jsxs as jsxs45 } from "react/jsx-runtime";
|
|
|
7043
7043
|
function FontFamilyDropdown() {
|
|
7044
7044
|
const { editor } = useCurrentEditor3();
|
|
7045
7045
|
const [open, setOpen] = useState28(false);
|
|
7046
|
+
const [selectedFont, setSelectedFont] = useState28(null);
|
|
7046
7047
|
useEffect18(() => {
|
|
7047
7048
|
loadGoogleFonts();
|
|
7048
7049
|
}, []);
|
|
7050
|
+
useEffect18(() => {
|
|
7051
|
+
if (!editor) return;
|
|
7052
|
+
const updateSelectedFont = () => {
|
|
7053
|
+
const currentFontFamily2 = editor.getAttributes("textStyle").fontFamily;
|
|
7054
|
+
if (currentFontFamily2) {
|
|
7055
|
+
setSelectedFont(currentFontFamily2);
|
|
7056
|
+
}
|
|
7057
|
+
};
|
|
7058
|
+
editor.on("selectionUpdate", updateSelectedFont);
|
|
7059
|
+
editor.on("transaction", updateSelectedFont);
|
|
7060
|
+
return () => {
|
|
7061
|
+
editor.off("selectionUpdate", updateSelectedFont);
|
|
7062
|
+
editor.off("transaction", updateSelectedFont);
|
|
7063
|
+
};
|
|
7064
|
+
}, [editor]);
|
|
7065
|
+
useEffect18(() => {
|
|
7066
|
+
if (!editor || !selectedFont) return;
|
|
7067
|
+
const handleUpdate = () => {
|
|
7068
|
+
const { from, to } = editor.state.selection;
|
|
7069
|
+
const currentFontFamily2 = editor.getAttributes("textStyle").fontFamily;
|
|
7070
|
+
if (!currentFontFamily2 && selectedFont) {
|
|
7071
|
+
editor.chain().focus().setFontFamily(selectedFont).run();
|
|
7072
|
+
}
|
|
7073
|
+
};
|
|
7074
|
+
editor.on("update", handleUpdate);
|
|
7075
|
+
return () => {
|
|
7076
|
+
editor.off("update", handleUpdate);
|
|
7077
|
+
};
|
|
7078
|
+
}, [editor, selectedFont]);
|
|
7049
7079
|
if (!editor) return null;
|
|
7050
|
-
const
|
|
7080
|
+
const currentFontFamily = editor.getAttributes("textStyle").fontFamily || selectedFont;
|
|
7081
|
+
const getCurrentFontLabel = () => {
|
|
7082
|
+
if (!currentFontFamily) return "Font Family";
|
|
7083
|
+
const matchedFont = FONT_OPTIONS.find(
|
|
7084
|
+
(font) => font.cssFontFamily === currentFontFamily
|
|
7085
|
+
);
|
|
7086
|
+
return matchedFont ? matchedFont.label : "Font Family";
|
|
7087
|
+
};
|
|
7088
|
+
const currentFont = getCurrentFontLabel();
|
|
7051
7089
|
const applyFont = (family) => {
|
|
7052
7090
|
if (!editor) return;
|
|
7091
|
+
setSelectedFont(family);
|
|
7053
7092
|
if (editor.state.storedMarks) {
|
|
7054
7093
|
const textStyleMark = editor.schema.marks.textStyle;
|
|
7055
7094
|
if (textStyleMark) {
|
|
@@ -7063,6 +7102,22 @@ function FontFamilyDropdown() {
|
|
|
7063
7102
|
}
|
|
7064
7103
|
}, 0);
|
|
7065
7104
|
};
|
|
7105
|
+
const resetFont = () => {
|
|
7106
|
+
if (!editor) return;
|
|
7107
|
+
setSelectedFont(null);
|
|
7108
|
+
if (editor.state.storedMarks) {
|
|
7109
|
+
const textStyleMark = editor.schema.marks.textStyle;
|
|
7110
|
+
if (textStyleMark) {
|
|
7111
|
+
editor.view.dispatch(
|
|
7112
|
+
editor.state.tr.removeStoredMark(textStyleMark)
|
|
7113
|
+
);
|
|
7114
|
+
}
|
|
7115
|
+
}
|
|
7116
|
+
setTimeout(() => {
|
|
7117
|
+
editor.chain().focus().unsetFontFamily().run();
|
|
7118
|
+
setOpen(false);
|
|
7119
|
+
}, 0);
|
|
7120
|
+
};
|
|
7066
7121
|
return /* @__PURE__ */ jsxs45(Popover2, { open, onOpenChange: setOpen, children: [
|
|
7067
7122
|
/* @__PURE__ */ jsx76(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs45(
|
|
7068
7123
|
Button,
|
|
@@ -7094,21 +7149,7 @@ function FontFamilyDropdown() {
|
|
|
7094
7149
|
/* @__PURE__ */ jsx76(
|
|
7095
7150
|
CommandItem,
|
|
7096
7151
|
{
|
|
7097
|
-
onSelect:
|
|
7098
|
-
if (!editor) return;
|
|
7099
|
-
if (editor.state.storedMarks) {
|
|
7100
|
-
const textStyleMark = editor.schema.marks.textStyle;
|
|
7101
|
-
if (textStyleMark) {
|
|
7102
|
-
editor.view.dispatch(
|
|
7103
|
-
editor.state.tr.removeStoredMark(textStyleMark)
|
|
7104
|
-
);
|
|
7105
|
-
}
|
|
7106
|
-
}
|
|
7107
|
-
setTimeout(() => {
|
|
7108
|
-
editor.chain().focus().unsetFontFamily().run();
|
|
7109
|
-
setOpen(false);
|
|
7110
|
-
}, 0);
|
|
7111
|
-
},
|
|
7152
|
+
onSelect: resetFont,
|
|
7112
7153
|
className: "font-sans",
|
|
7113
7154
|
children: "Default"
|
|
7114
7155
|
},
|