@mhamz.01/easyflow-texteditor 0.1.142 → 0.1.145
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 +113 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7590,11 +7590,39 @@ var FontFamilyBlock = import_core4.Extension.create({
|
|
|
7590
7590
|
];
|
|
7591
7591
|
}
|
|
7592
7592
|
});
|
|
7593
|
-
var
|
|
7594
|
-
name: "
|
|
7593
|
+
var ColorBlock = import_core4.Extension.create({
|
|
7594
|
+
name: "colorBlock",
|
|
7595
|
+
addGlobalAttributes() {
|
|
7596
|
+
return [
|
|
7597
|
+
{
|
|
7598
|
+
types: [
|
|
7599
|
+
"paragraph",
|
|
7600
|
+
"heading",
|
|
7601
|
+
"listItem",
|
|
7602
|
+
"taskItem",
|
|
7603
|
+
"blockquote"
|
|
7604
|
+
],
|
|
7605
|
+
attributes: {
|
|
7606
|
+
color: {
|
|
7607
|
+
default: null,
|
|
7608
|
+
parseHTML: (element) => element.style.color || null,
|
|
7609
|
+
renderHTML: (attributes) => {
|
|
7610
|
+
if (!attributes.color) return {};
|
|
7611
|
+
return {
|
|
7612
|
+
style: `color: ${attributes.color}`
|
|
7613
|
+
};
|
|
7614
|
+
}
|
|
7615
|
+
}
|
|
7616
|
+
}
|
|
7617
|
+
}
|
|
7618
|
+
];
|
|
7619
|
+
}
|
|
7620
|
+
});
|
|
7621
|
+
var StylePersistence = import_core4.Extension.create({
|
|
7622
|
+
name: "stylePersistence",
|
|
7595
7623
|
addOptions() {
|
|
7596
7624
|
return {
|
|
7597
|
-
// Marks that should NOT inherit font family
|
|
7625
|
+
// Marks that should NOT inherit font family or color
|
|
7598
7626
|
excludedMarks: ["code", "codeBlock"]
|
|
7599
7627
|
};
|
|
7600
7628
|
},
|
|
@@ -7619,15 +7647,26 @@ var FontFamilyPersistence = import_core4.Extension.create({
|
|
|
7619
7647
|
if (hasExcludedMarks() || isInCodeBlock()) {
|
|
7620
7648
|
return;
|
|
7621
7649
|
}
|
|
7622
|
-
const
|
|
7623
|
-
|
|
7650
|
+
const blockFont = state.selection.$from.parent.attrs.fontFamily;
|
|
7651
|
+
const blockColor = state.selection.$from.parent.attrs.color;
|
|
7652
|
+
const existingTextStyleMark = state.selection.$from.marks().find(
|
|
7653
|
+
(mark) => mark.type.name === "textStyle"
|
|
7654
|
+
);
|
|
7655
|
+
const markFont = existingTextStyleMark?.attrs.fontFamily;
|
|
7656
|
+
const markColor = existingTextStyleMark?.attrs.color;
|
|
7657
|
+
const finalFont = markFont || blockFont;
|
|
7658
|
+
const finalColor = markColor || blockColor;
|
|
7659
|
+
if (!finalFont && !finalColor) return;
|
|
7624
7660
|
const storedMarks = state.storedMarks || state.selection.$from.marks();
|
|
7625
7661
|
const filteredMarks = storedMarks.filter(
|
|
7626
7662
|
(mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
|
|
7627
7663
|
);
|
|
7664
|
+
const textStyleAttrs = {};
|
|
7665
|
+
if (finalFont) textStyleAttrs.fontFamily = finalFont;
|
|
7666
|
+
if (finalColor) textStyleAttrs.color = finalColor;
|
|
7628
7667
|
const newMarks = [
|
|
7629
7668
|
...filteredMarks,
|
|
7630
|
-
state.schema.marks.textStyle.create(
|
|
7669
|
+
state.schema.marks.textStyle.create(textStyleAttrs)
|
|
7631
7670
|
];
|
|
7632
7671
|
editor.view.dispatch(
|
|
7633
7672
|
state.tr.setStoredMarks(newMarks)
|
|
@@ -7654,15 +7693,78 @@ var FontFamilyPersistence = import_core4.Extension.create({
|
|
|
7654
7693
|
if (hasExcludedMarks() || isInCodeBlock()) {
|
|
7655
7694
|
return;
|
|
7656
7695
|
}
|
|
7657
|
-
const
|
|
7658
|
-
|
|
7696
|
+
const blockFont = state.selection.$from.parent.attrs.fontFamily;
|
|
7697
|
+
const blockColor = state.selection.$from.parent.attrs.color;
|
|
7698
|
+
const existingTextStyleMark = state.selection.$from.marks().find(
|
|
7699
|
+
(mark) => mark.type.name === "textStyle"
|
|
7700
|
+
);
|
|
7701
|
+
const markFont = existingTextStyleMark?.attrs.fontFamily;
|
|
7702
|
+
const markColor = existingTextStyleMark?.attrs.color;
|
|
7703
|
+
const finalFont = markFont || blockFont;
|
|
7704
|
+
const finalColor = markColor || blockColor;
|
|
7705
|
+
if (!finalFont && !finalColor) return;
|
|
7706
|
+
const storedMarks = state.storedMarks || state.selection.$from.marks();
|
|
7707
|
+
const filteredMarks = storedMarks.filter(
|
|
7708
|
+
(mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
|
|
7709
|
+
);
|
|
7710
|
+
const textStyleAttrs = {};
|
|
7711
|
+
if (finalFont) textStyleAttrs.fontFamily = finalFont;
|
|
7712
|
+
if (finalColor) textStyleAttrs.color = finalColor;
|
|
7713
|
+
const newMarks = [
|
|
7714
|
+
...filteredMarks,
|
|
7715
|
+
state.schema.marks.textStyle.create(textStyleAttrs)
|
|
7716
|
+
];
|
|
7717
|
+
editor.view.dispatch(
|
|
7718
|
+
state.tr.setStoredMarks(newMarks)
|
|
7719
|
+
);
|
|
7720
|
+
},
|
|
7721
|
+
// CRITICAL: Handle transaction updates to catch any textStyle changes
|
|
7722
|
+
onTransaction({ editor, transaction }) {
|
|
7723
|
+
if (!transaction.selectionSet && !transaction.docChanged) return;
|
|
7724
|
+
const { state } = editor;
|
|
7725
|
+
const excludedMarks = this.options.excludedMarks;
|
|
7726
|
+
const hasExcludedMarks = () => {
|
|
7727
|
+
const { $from } = state.selection;
|
|
7728
|
+
const marks = $from.marks();
|
|
7729
|
+
return marks.some((mark) => excludedMarks.includes(mark.type.name));
|
|
7730
|
+
};
|
|
7731
|
+
const isInCodeBlock = () => {
|
|
7732
|
+
const { $from } = state.selection;
|
|
7733
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
7734
|
+
const node = $from.node(depth);
|
|
7735
|
+
if (node.type.name === "codeBlock") {
|
|
7736
|
+
return true;
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
return false;
|
|
7740
|
+
};
|
|
7741
|
+
if (hasExcludedMarks() || isInCodeBlock()) {
|
|
7742
|
+
return;
|
|
7743
|
+
}
|
|
7744
|
+
const blockFont = state.selection.$from.parent.attrs.fontFamily;
|
|
7745
|
+
const blockColor = state.selection.$from.parent.attrs.color;
|
|
7746
|
+
const existingTextStyleMark = state.selection.$from.marks().find(
|
|
7747
|
+
(mark) => mark.type.name === "textStyle"
|
|
7748
|
+
);
|
|
7749
|
+
const markFont = existingTextStyleMark?.attrs.fontFamily;
|
|
7750
|
+
const markColor = existingTextStyleMark?.attrs.color;
|
|
7751
|
+
const finalFont = markFont || blockFont;
|
|
7752
|
+
const finalColor = markColor || blockColor;
|
|
7753
|
+
if (!finalFont && !finalColor) return;
|
|
7659
7754
|
const storedMarks = state.storedMarks || state.selection.$from.marks();
|
|
7755
|
+
const existingStoredTextStyle = storedMarks.find((mark) => mark.type.name === "textStyle");
|
|
7756
|
+
const hasCorrectFont = !finalFont || existingStoredTextStyle?.attrs.fontFamily === finalFont;
|
|
7757
|
+
const hasCorrectColor = !finalColor || existingStoredTextStyle?.attrs.color === finalColor;
|
|
7758
|
+
if (hasCorrectFont && hasCorrectColor && existingStoredTextStyle) return;
|
|
7660
7759
|
const filteredMarks = storedMarks.filter(
|
|
7661
7760
|
(mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
|
|
7662
7761
|
);
|
|
7762
|
+
const textStyleAttrs = {};
|
|
7763
|
+
if (finalFont) textStyleAttrs.fontFamily = finalFont;
|
|
7764
|
+
if (finalColor) textStyleAttrs.color = finalColor;
|
|
7663
7765
|
const newMarks = [
|
|
7664
7766
|
...filteredMarks,
|
|
7665
|
-
state.schema.marks.textStyle.create(
|
|
7767
|
+
state.schema.marks.textStyle.create(textStyleAttrs)
|
|
7666
7768
|
];
|
|
7667
7769
|
editor.view.dispatch(
|
|
7668
7770
|
state.tr.setStoredMarks(newMarks)
|
|
@@ -7781,7 +7883,8 @@ function SimpleEditor() {
|
|
|
7781
7883
|
import_extension_subscript.Subscript,
|
|
7782
7884
|
import_extensions.Selection,
|
|
7783
7885
|
FontFamilyBlock,
|
|
7784
|
-
|
|
7886
|
+
ColorBlock,
|
|
7887
|
+
StylePersistence,
|
|
7785
7888
|
ImageUploadNode2.configure({
|
|
7786
7889
|
accept: "image/*",
|
|
7787
7890
|
maxSize: MAX_FILE_SIZE,
|