@mhamz.01/easyflow-texteditor 0.1.141 → 0.1.142
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 +112 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7534,6 +7534,116 @@ function useCursorVisibility({
|
|
|
7534
7534
|
return rect;
|
|
7535
7535
|
}
|
|
7536
7536
|
|
|
7537
|
+
// src/components/extensions/font-family-block.ts
|
|
7538
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
7539
|
+
var FontFamilyBlock = Extension2.create({
|
|
7540
|
+
name: "fontFamilyBlock",
|
|
7541
|
+
addGlobalAttributes() {
|
|
7542
|
+
return [
|
|
7543
|
+
{
|
|
7544
|
+
types: [
|
|
7545
|
+
"paragraph",
|
|
7546
|
+
"heading",
|
|
7547
|
+
"listItem",
|
|
7548
|
+
"taskItem",
|
|
7549
|
+
"blockquote"
|
|
7550
|
+
],
|
|
7551
|
+
attributes: {
|
|
7552
|
+
fontFamily: {
|
|
7553
|
+
default: null,
|
|
7554
|
+
parseHTML: (element) => element.style.fontFamily?.replace(/['"]/g, "") || null,
|
|
7555
|
+
renderHTML: (attributes) => {
|
|
7556
|
+
if (!attributes.fontFamily) return {};
|
|
7557
|
+
return {
|
|
7558
|
+
style: `font-family: ${attributes.fontFamily}`
|
|
7559
|
+
};
|
|
7560
|
+
}
|
|
7561
|
+
}
|
|
7562
|
+
}
|
|
7563
|
+
}
|
|
7564
|
+
];
|
|
7565
|
+
}
|
|
7566
|
+
});
|
|
7567
|
+
var FontFamilyPersistence = Extension2.create({
|
|
7568
|
+
name: "fontFamilyPersistence",
|
|
7569
|
+
addOptions() {
|
|
7570
|
+
return {
|
|
7571
|
+
// Marks that should NOT inherit font family
|
|
7572
|
+
excludedMarks: ["code", "codeBlock"]
|
|
7573
|
+
};
|
|
7574
|
+
},
|
|
7575
|
+
onSelectionUpdate({ editor }) {
|
|
7576
|
+
const { state } = editor;
|
|
7577
|
+
const excludedMarks = this.options.excludedMarks;
|
|
7578
|
+
const hasExcludedMarks = () => {
|
|
7579
|
+
const { $from } = state.selection;
|
|
7580
|
+
const marks = $from.marks();
|
|
7581
|
+
return marks.some((mark) => excludedMarks.includes(mark.type.name));
|
|
7582
|
+
};
|
|
7583
|
+
const isInCodeBlock = () => {
|
|
7584
|
+
const { $from } = state.selection;
|
|
7585
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
7586
|
+
const node = $from.node(depth);
|
|
7587
|
+
if (node.type.name === "codeBlock") {
|
|
7588
|
+
return true;
|
|
7589
|
+
}
|
|
7590
|
+
}
|
|
7591
|
+
return false;
|
|
7592
|
+
};
|
|
7593
|
+
if (hasExcludedMarks() || isInCodeBlock()) {
|
|
7594
|
+
return;
|
|
7595
|
+
}
|
|
7596
|
+
const font = state.selection.$from.parent.attrs.fontFamily;
|
|
7597
|
+
if (!font) return;
|
|
7598
|
+
const storedMarks = state.storedMarks || state.selection.$from.marks();
|
|
7599
|
+
const filteredMarks = storedMarks.filter(
|
|
7600
|
+
(mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
|
|
7601
|
+
);
|
|
7602
|
+
const newMarks = [
|
|
7603
|
+
...filteredMarks,
|
|
7604
|
+
state.schema.marks.textStyle.create({ fontFamily: font })
|
|
7605
|
+
];
|
|
7606
|
+
editor.view.dispatch(
|
|
7607
|
+
state.tr.setStoredMarks(newMarks)
|
|
7608
|
+
);
|
|
7609
|
+
},
|
|
7610
|
+
onFocus({ editor }) {
|
|
7611
|
+
const { state } = editor;
|
|
7612
|
+
const excludedMarks = this.options.excludedMarks;
|
|
7613
|
+
const hasExcludedMarks = () => {
|
|
7614
|
+
const { $from } = state.selection;
|
|
7615
|
+
const marks = $from.marks();
|
|
7616
|
+
return marks.some((mark) => excludedMarks.includes(mark.type.name));
|
|
7617
|
+
};
|
|
7618
|
+
const isInCodeBlock = () => {
|
|
7619
|
+
const { $from } = state.selection;
|
|
7620
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
7621
|
+
const node = $from.node(depth);
|
|
7622
|
+
if (node.type.name === "codeBlock") {
|
|
7623
|
+
return true;
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7626
|
+
return false;
|
|
7627
|
+
};
|
|
7628
|
+
if (hasExcludedMarks() || isInCodeBlock()) {
|
|
7629
|
+
return;
|
|
7630
|
+
}
|
|
7631
|
+
const font = state.selection.$from.parent.attrs.fontFamily;
|
|
7632
|
+
if (!font) return;
|
|
7633
|
+
const storedMarks = state.storedMarks || state.selection.$from.marks();
|
|
7634
|
+
const filteredMarks = storedMarks.filter(
|
|
7635
|
+
(mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
|
|
7636
|
+
);
|
|
7637
|
+
const newMarks = [
|
|
7638
|
+
...filteredMarks,
|
|
7639
|
+
state.schema.marks.textStyle.create({ fontFamily: font })
|
|
7640
|
+
];
|
|
7641
|
+
editor.view.dispatch(
|
|
7642
|
+
state.tr.setStoredMarks(newMarks)
|
|
7643
|
+
);
|
|
7644
|
+
}
|
|
7645
|
+
});
|
|
7646
|
+
|
|
7537
7647
|
// src/components/tiptap-templates/simple/simple-editor.tsx
|
|
7538
7648
|
import { Fragment as Fragment12, jsx as jsx81, jsxs as jsxs48 } from "react/jsx-runtime";
|
|
7539
7649
|
var MainToolbarContent = ({
|
|
@@ -7644,6 +7754,8 @@ function SimpleEditor() {
|
|
|
7644
7754
|
Superscript,
|
|
7645
7755
|
Subscript,
|
|
7646
7756
|
Selection2,
|
|
7757
|
+
FontFamilyBlock,
|
|
7758
|
+
FontFamilyPersistence,
|
|
7647
7759
|
ImageUploadNode2.configure({
|
|
7648
7760
|
accept: "image/*",
|
|
7649
7761
|
maxSize: MAX_FILE_SIZE,
|