@mhamz.01/easyflow-texteditor 0.1.90 → 0.1.92
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 +61 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1270,7 +1270,7 @@ function EditorLayout({ children, onChange, initialTabs, onTabsChange }) {
|
|
|
1270
1270
|
}
|
|
1271
1271
|
|
|
1272
1272
|
// src/components/tiptap-templates/simple/simple-editor.tsx
|
|
1273
|
-
import { useEffect as useEffect24, useRef as
|
|
1273
|
+
import { useEffect as useEffect24, useRef as useRef8, useState as useState33 } from "react";
|
|
1274
1274
|
import { EditorContent, EditorContext, useEditor } from "@tiptap/react";
|
|
1275
1275
|
import { StarterKit } from "@tiptap/starter-kit";
|
|
1276
1276
|
import Image from "@tiptap/extension-image";
|
|
@@ -6711,7 +6711,7 @@ function useUndoRedo(config) {
|
|
|
6711
6711
|
|
|
6712
6712
|
// src/components/tiptap-ui/font-family-dropdown/font-family-dropdown.tsx
|
|
6713
6713
|
import { useCurrentEditor as useCurrentEditor3 } from "@tiptap/react";
|
|
6714
|
-
import { useState as useState28, useEffect as useEffect18 } from "react";
|
|
6714
|
+
import { useState as useState28, useEffect as useEffect18, useRef as useRef6 } from "react";
|
|
6715
6715
|
|
|
6716
6716
|
// src/lib/colors.ts
|
|
6717
6717
|
var GRADIENT_ROWS_70 = [
|
|
@@ -7044,37 +7044,49 @@ function FontFamilyDropdown() {
|
|
|
7044
7044
|
const { editor } = useCurrentEditor3();
|
|
7045
7045
|
const [open, setOpen] = useState28(false);
|
|
7046
7046
|
const [selectedFont, setSelectedFont] = useState28(null);
|
|
7047
|
+
const isApplyingFont = useRef6(false);
|
|
7047
7048
|
useEffect18(() => {
|
|
7048
7049
|
loadGoogleFonts();
|
|
7049
7050
|
}, []);
|
|
7050
7051
|
useEffect18(() => {
|
|
7051
|
-
if (!editor) return;
|
|
7052
|
-
const
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7052
|
+
if (!editor || !selectedFont) return;
|
|
7053
|
+
const handleTransaction = ({ transaction }) => {
|
|
7054
|
+
if (isApplyingFont.current) return;
|
|
7055
|
+
const hasTextChanges = transaction.steps.some(
|
|
7056
|
+
(step) => step.slice || step.from !== void 0
|
|
7057
|
+
);
|
|
7058
|
+
if (!hasTextChanges) return;
|
|
7059
|
+
const { $from } = transaction.selection;
|
|
7060
|
+
const marks = $from.marks();
|
|
7061
|
+
const hasFontFamily = marks.some(
|
|
7062
|
+
(mark) => mark.type.name === "textStyle" && mark.attrs.fontFamily
|
|
7063
|
+
);
|
|
7064
|
+
if (!hasFontFamily) {
|
|
7065
|
+
const { state } = editor;
|
|
7066
|
+
const textStyleMark = state.schema.marks.textStyle;
|
|
7067
|
+
if (textStyleMark) {
|
|
7068
|
+
isApplyingFont.current = true;
|
|
7069
|
+
const mark = textStyleMark.create({ fontFamily: selectedFont });
|
|
7070
|
+
state.storedMarks = [mark];
|
|
7071
|
+
setTimeout(() => {
|
|
7072
|
+
isApplyingFont.current = false;
|
|
7073
|
+
}, 50);
|
|
7074
|
+
}
|
|
7056
7075
|
}
|
|
7057
7076
|
};
|
|
7058
|
-
editor.on("
|
|
7059
|
-
editor.on("transaction", updateSelectedFont);
|
|
7077
|
+
editor.on("transaction", handleTransaction);
|
|
7060
7078
|
return () => {
|
|
7061
|
-
editor.off("
|
|
7062
|
-
editor.off("transaction", updateSelectedFont);
|
|
7079
|
+
editor.off("transaction", handleTransaction);
|
|
7063
7080
|
};
|
|
7064
|
-
}, [editor]);
|
|
7081
|
+
}, [editor, selectedFont]);
|
|
7065
7082
|
useEffect18(() => {
|
|
7066
7083
|
if (!editor || !selectedFont) return;
|
|
7067
|
-
const
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
};
|
|
7074
|
-
editor.on("update", handleUpdate);
|
|
7075
|
-
return () => {
|
|
7076
|
-
editor.off("update", handleUpdate);
|
|
7077
|
-
};
|
|
7084
|
+
const { state } = editor;
|
|
7085
|
+
const textStyleMark = state.schema.marks.textStyle;
|
|
7086
|
+
if (textStyleMark) {
|
|
7087
|
+
const mark = textStyleMark.create({ fontFamily: selectedFont });
|
|
7088
|
+
state.storedMarks = [mark];
|
|
7089
|
+
}
|
|
7078
7090
|
}, [editor, selectedFont]);
|
|
7079
7091
|
if (!editor) return null;
|
|
7080
7092
|
const currentFontFamily = editor.getAttributes("textStyle").fontFamily || selectedFont;
|
|
@@ -7088,35 +7100,45 @@ function FontFamilyDropdown() {
|
|
|
7088
7100
|
const currentFont = getCurrentFontLabel();
|
|
7089
7101
|
const applyFont = (family) => {
|
|
7090
7102
|
if (!editor) return;
|
|
7103
|
+
isApplyingFont.current = true;
|
|
7091
7104
|
setSelectedFont(family);
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7105
|
+
const { state, view } = editor;
|
|
7106
|
+
const { from, to } = state.selection;
|
|
7107
|
+
const textStyleMark = state.schema.marks.textStyle;
|
|
7108
|
+
if (!textStyleMark) {
|
|
7109
|
+
isApplyingFont.current = false;
|
|
7110
|
+
return;
|
|
7097
7111
|
}
|
|
7112
|
+
const mark = textStyleMark.create({ fontFamily: family });
|
|
7113
|
+
if (from !== to) {
|
|
7114
|
+
const tr = state.tr.addMark(from, to, mark);
|
|
7115
|
+
view.dispatch(tr);
|
|
7116
|
+
}
|
|
7117
|
+
state.storedMarks = [mark];
|
|
7118
|
+
editor.commands.focus(void 0, { scrollIntoView: false });
|
|
7098
7119
|
setTimeout(() => {
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
console.warn("Font not applied:", family);
|
|
7102
|
-
}
|
|
7103
|
-
}, 0);
|
|
7120
|
+
isApplyingFont.current = false;
|
|
7121
|
+
}, 50);
|
|
7104
7122
|
};
|
|
7105
7123
|
const resetFont = () => {
|
|
7106
7124
|
if (!editor) return;
|
|
7125
|
+
isApplyingFont.current = true;
|
|
7107
7126
|
setSelectedFont(null);
|
|
7108
|
-
|
|
7109
|
-
|
|
7127
|
+
const { state, view } = editor;
|
|
7128
|
+
const { from, to } = state.selection;
|
|
7129
|
+
if (from !== to) {
|
|
7130
|
+
const textStyleMark = state.schema.marks.textStyle;
|
|
7110
7131
|
if (textStyleMark) {
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
);
|
|
7132
|
+
const tr = state.tr.removeMark(from, to, textStyleMark);
|
|
7133
|
+
view.dispatch(tr);
|
|
7114
7134
|
}
|
|
7115
7135
|
}
|
|
7136
|
+
state.storedMarks = null;
|
|
7137
|
+
editor.commands.focus(void 0, { scrollIntoView: false });
|
|
7138
|
+
setOpen(false);
|
|
7116
7139
|
setTimeout(() => {
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
}, 0);
|
|
7140
|
+
isApplyingFont.current = false;
|
|
7141
|
+
}, 50);
|
|
7120
7142
|
};
|
|
7121
7143
|
return /* @__PURE__ */ jsxs45(Popover2, { open, onOpenChange: setOpen, children: [
|
|
7122
7144
|
/* @__PURE__ */ jsx76(PopoverTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs45(
|
|
@@ -7475,9 +7497,9 @@ import { useEffect as useEffect21, useState as useState31 } from "react";
|
|
|
7475
7497
|
import throttle from "lodash.throttle";
|
|
7476
7498
|
|
|
7477
7499
|
// src/hooks/use-unmount.ts
|
|
7478
|
-
import { useRef as
|
|
7500
|
+
import { useRef as useRef7, useEffect as useEffect20 } from "react";
|
|
7479
7501
|
var useUnmount = (callback) => {
|
|
7480
|
-
const ref =
|
|
7502
|
+
const ref = useRef7(callback);
|
|
7481
7503
|
ref.current = callback;
|
|
7482
7504
|
useEffect20(
|
|
7483
7505
|
() => () => {
|
|
@@ -7746,7 +7768,7 @@ function SimpleEditor() {
|
|
|
7746
7768
|
const [mobileView, setMobileView] = useState33(
|
|
7747
7769
|
"main"
|
|
7748
7770
|
);
|
|
7749
|
-
const toolbarRef =
|
|
7771
|
+
const toolbarRef = useRef8(null);
|
|
7750
7772
|
const editor = useEditor({
|
|
7751
7773
|
immediatelyRender: false,
|
|
7752
7774
|
editorProps: {
|