@mhamz.01/easyflow-texteditor 0.1.89 → 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 +49 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7043,11 +7043,41 @@ 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 currentFontFamily = editor.getAttributes("textStyle").fontFamily;
|
|
7080
|
+
const currentFontFamily = editor.getAttributes("textStyle").fontFamily || selectedFont;
|
|
7051
7081
|
const getCurrentFontLabel = () => {
|
|
7052
7082
|
if (!currentFontFamily) return "Font Family";
|
|
7053
7083
|
const matchedFont = FONT_OPTIONS.find(
|
|
@@ -7058,6 +7088,7 @@ function FontFamilyDropdown() {
|
|
|
7058
7088
|
const currentFont = getCurrentFontLabel();
|
|
7059
7089
|
const applyFont = (family) => {
|
|
7060
7090
|
if (!editor) return;
|
|
7091
|
+
setSelectedFont(family);
|
|
7061
7092
|
if (editor.state.storedMarks) {
|
|
7062
7093
|
const textStyleMark = editor.schema.marks.textStyle;
|
|
7063
7094
|
if (textStyleMark) {
|
|
@@ -7071,6 +7102,22 @@ function FontFamilyDropdown() {
|
|
|
7071
7102
|
}
|
|
7072
7103
|
}, 0);
|
|
7073
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
|
+
};
|
|
7074
7121
|
return /* @__PURE__ */ jsxs45(Popover2, { open, onOpenChange: setOpen, children: [
|
|
7075
7122
|
/* @__PURE__ */ jsx76(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs45(
|
|
7076
7123
|
Button,
|
|
@@ -7102,21 +7149,7 @@ function FontFamilyDropdown() {
|
|
|
7102
7149
|
/* @__PURE__ */ jsx76(
|
|
7103
7150
|
CommandItem,
|
|
7104
7151
|
{
|
|
7105
|
-
onSelect:
|
|
7106
|
-
if (!editor) return;
|
|
7107
|
-
if (editor.state.storedMarks) {
|
|
7108
|
-
const textStyleMark = editor.schema.marks.textStyle;
|
|
7109
|
-
if (textStyleMark) {
|
|
7110
|
-
editor.view.dispatch(
|
|
7111
|
-
editor.state.tr.removeStoredMark(textStyleMark)
|
|
7112
|
-
);
|
|
7113
|
-
}
|
|
7114
|
-
}
|
|
7115
|
-
setTimeout(() => {
|
|
7116
|
-
editor.chain().focus().unsetFontFamily().run();
|
|
7117
|
-
setOpen(false);
|
|
7118
|
-
}, 0);
|
|
7119
|
-
},
|
|
7152
|
+
onSelect: resetFont,
|
|
7120
7153
|
className: "font-sans",
|
|
7121
7154
|
children: "Default"
|
|
7122
7155
|
},
|