@mhamz.01/easyflow-texteditor 0.1.157 → 0.1.158
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 +71 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7326,23 +7326,32 @@ function ColorPicker({ type = "text" }) {
|
|
|
7326
7326
|
(value) => {
|
|
7327
7327
|
if (!editor) return;
|
|
7328
7328
|
const { state } = editor;
|
|
7329
|
-
const { $from
|
|
7329
|
+
const { $from } = state.selection;
|
|
7330
7330
|
editor.chain().focus().setColor(value).run();
|
|
7331
|
-
const
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7331
|
+
const tr = editor.state.tr;
|
|
7332
|
+
let trDirty = false;
|
|
7333
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
7334
|
+
const node = $from.node(depth);
|
|
7335
|
+
const pos = $from.before(depth);
|
|
7336
|
+
const supportsColor = [
|
|
7337
|
+
"paragraph",
|
|
7338
|
+
"heading",
|
|
7339
|
+
"listItem",
|
|
7340
|
+
"taskItem",
|
|
7341
|
+
"blockquote"
|
|
7342
|
+
].includes(node.type.name);
|
|
7343
|
+
if (supportsColor && node.attrs.color !== value) {
|
|
7344
|
+
tr.setNodeMarkup(pos, void 0, {
|
|
7345
|
+
...node.attrs,
|
|
7346
|
+
color: value
|
|
7347
|
+
});
|
|
7348
|
+
trDirty = true;
|
|
7349
|
+
}
|
|
7350
|
+
if (node.type.name === "listItem" || node.type.name === "taskItem") {
|
|
7351
|
+
break;
|
|
7352
|
+
}
|
|
7353
|
+
}
|
|
7354
|
+
if (trDirty) {
|
|
7346
7355
|
editor.view.dispatch(tr);
|
|
7347
7356
|
}
|
|
7348
7357
|
setTimeout(() => {
|
|
@@ -7423,7 +7432,7 @@ function ColorPicker({ type = "text" }) {
|
|
|
7423
7432
|
{
|
|
7424
7433
|
className: "flex flex-col gap-3",
|
|
7425
7434
|
onMouseDown: (e) => e.stopPropagation(),
|
|
7426
|
-
onMouseUp: (
|
|
7435
|
+
onMouseUp: (e) => e.stopPropagation(),
|
|
7427
7436
|
onPointerDown: (e) => e.stopPropagation(),
|
|
7428
7437
|
onPointerUp: (e) => e.stopPropagation(),
|
|
7429
7438
|
onClick: (e) => e.stopPropagation(),
|
|
@@ -7853,6 +7862,7 @@ var ColorBlock = import_core5.Extension.create({
|
|
|
7853
7862
|
}
|
|
7854
7863
|
});
|
|
7855
7864
|
var stylePersistenceKey = new import_state5.PluginKey("stylePersistence");
|
|
7865
|
+
var STYLED_NODES = ["paragraph", "heading", "listItem", "taskItem", "blockquote"];
|
|
7856
7866
|
var StylePersistence = import_core5.Extension.create({
|
|
7857
7867
|
name: "stylePersistence",
|
|
7858
7868
|
addOptions() {
|
|
@@ -7880,8 +7890,7 @@ var StylePersistence = import_core5.Extension.create({
|
|
|
7880
7890
|
);
|
|
7881
7891
|
let isInCodeBlock = false;
|
|
7882
7892
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
7883
|
-
|
|
7884
|
-
if (node.type.name === "codeBlock") {
|
|
7893
|
+
if ($from.node(depth).type.name === "codeBlock") {
|
|
7885
7894
|
isInCodeBlock = true;
|
|
7886
7895
|
break;
|
|
7887
7896
|
}
|
|
@@ -7889,16 +7898,17 @@ var StylePersistence = import_core5.Extension.create({
|
|
|
7889
7898
|
if (hasExcludedMarks || isInCodeBlock) {
|
|
7890
7899
|
return value;
|
|
7891
7900
|
}
|
|
7892
|
-
|
|
7893
|
-
let
|
|
7894
|
-
let
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
if (!color && textStyleMark?.attrs.color) {
|
|
7900
|
-
color = textStyleMark.attrs.color;
|
|
7901
|
+
let font = null;
|
|
7902
|
+
let color = null;
|
|
7903
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
7904
|
+
const node = $from.node(depth);
|
|
7905
|
+
if (!font && node.attrs?.fontFamily) font = node.attrs.fontFamily;
|
|
7906
|
+
if (!color && node.attrs?.color) color = node.attrs.color;
|
|
7907
|
+
if (font && color) break;
|
|
7901
7908
|
}
|
|
7909
|
+
const textStyleMark = marks.find((m) => m.type.name === "textStyle");
|
|
7910
|
+
if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
|
|
7911
|
+
if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
|
|
7902
7912
|
return {
|
|
7903
7913
|
lastFont: font || value.lastFont,
|
|
7904
7914
|
lastColor: color || value.lastColor
|
|
@@ -7914,15 +7924,13 @@ var StylePersistence = import_core5.Extension.create({
|
|
|
7914
7924
|
return null;
|
|
7915
7925
|
}
|
|
7916
7926
|
const { $from } = newState.selection;
|
|
7917
|
-
const parentNode = $from.parent;
|
|
7918
7927
|
const marks = $from.marks();
|
|
7919
7928
|
const hasExcludedMarks = marks.some(
|
|
7920
7929
|
(mark) => excludedMarks.includes(mark.type.name)
|
|
7921
7930
|
);
|
|
7922
7931
|
let isInCodeBlock = false;
|
|
7923
7932
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
7924
|
-
|
|
7925
|
-
if (node.type.name === "codeBlock") {
|
|
7933
|
+
if ($from.node(depth).type.name === "codeBlock") {
|
|
7926
7934
|
isInCodeBlock = true;
|
|
7927
7935
|
break;
|
|
7928
7936
|
}
|
|
@@ -7930,32 +7938,30 @@ var StylePersistence = import_core5.Extension.create({
|
|
|
7930
7938
|
if (hasExcludedMarks || isInCodeBlock) {
|
|
7931
7939
|
return null;
|
|
7932
7940
|
}
|
|
7933
|
-
const supportsAttributes = [
|
|
7934
|
-
"paragraph",
|
|
7935
|
-
"heading",
|
|
7936
|
-
"listItem",
|
|
7937
|
-
"taskItem",
|
|
7938
|
-
"blockquote"
|
|
7939
|
-
].includes(parentNode.type.name);
|
|
7940
|
-
if (!supportsAttributes) {
|
|
7941
|
-
return null;
|
|
7942
|
-
}
|
|
7943
|
-
const currentFont = parentNode.attrs.fontFamily;
|
|
7944
|
-
const currentColor = parentNode.attrs.color;
|
|
7945
|
-
const needsFont = !currentFont && pluginState.lastFont;
|
|
7946
|
-
const needsColor = !currentColor && pluginState.lastColor;
|
|
7947
|
-
if (!needsFont && !needsColor) {
|
|
7948
|
-
return null;
|
|
7949
|
-
}
|
|
7950
7941
|
const tr = newState.tr;
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
const pos = $from.before(depth);
|
|
7942
|
+
let trDirty = false;
|
|
7943
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
7954
7944
|
const node = $from.node(depth);
|
|
7945
|
+
if (!STYLED_NODES.includes(node.type.name)) continue;
|
|
7946
|
+
const pos = $from.before(depth);
|
|
7947
|
+
const needsFont = !node.attrs.fontFamily && pluginState.lastFont;
|
|
7948
|
+
const needsColor = !node.attrs.color && pluginState.lastColor;
|
|
7949
|
+
if (!needsFont && !needsColor) {
|
|
7950
|
+
break;
|
|
7951
|
+
}
|
|
7955
7952
|
const newAttrs = { ...node.attrs };
|
|
7956
7953
|
if (needsFont) newAttrs.fontFamily = pluginState.lastFont;
|
|
7957
7954
|
if (needsColor) newAttrs.color = pluginState.lastColor;
|
|
7958
7955
|
tr.setNodeMarkup(pos, void 0, newAttrs);
|
|
7956
|
+
trDirty = true;
|
|
7957
|
+
if (node.type.name === "listItem" || node.type.name === "taskItem") {
|
|
7958
|
+
break;
|
|
7959
|
+
}
|
|
7960
|
+
}
|
|
7961
|
+
if (!trDirty) {
|
|
7962
|
+
return null;
|
|
7963
|
+
}
|
|
7964
|
+
try {
|
|
7959
7965
|
const storedMarks = newState.storedMarks || $from.marks();
|
|
7960
7966
|
const filteredMarks = storedMarks.filter(
|
|
7961
7967
|
(mark) => mark.type.name !== "textStyle" && !excludedMarks.includes(mark.type.name)
|
|
@@ -7968,11 +7974,9 @@ var StylePersistence = import_core5.Extension.create({
|
|
|
7968
7974
|
newState.schema.marks.textStyle.create(textStyleAttrs)
|
|
7969
7975
|
];
|
|
7970
7976
|
tr.setStoredMarks(newMarks);
|
|
7971
|
-
|
|
7972
|
-
} catch (error) {
|
|
7973
|
-
console.error("StylePersistence error:", error);
|
|
7974
|
-
return null;
|
|
7977
|
+
} catch (e) {
|
|
7975
7978
|
}
|
|
7979
|
+
return tr;
|
|
7976
7980
|
},
|
|
7977
7981
|
props: {
|
|
7978
7982
|
handleKeyDown(view, event) {
|
|
@@ -7980,33 +7984,28 @@ var StylePersistence = import_core5.Extension.create({
|
|
|
7980
7984
|
const { state } = view;
|
|
7981
7985
|
const { $from } = state.selection;
|
|
7982
7986
|
const marks = $from.marks();
|
|
7983
|
-
|
|
7984
|
-
(mark) => excludedMarks.includes(mark.type.name)
|
|
7985
|
-
);
|
|
7986
|
-
if (hasExcludedMarks) {
|
|
7987
|
+
if (marks.some((mark) => excludedMarks.includes(mark.type.name))) {
|
|
7987
7988
|
return false;
|
|
7988
7989
|
}
|
|
7989
7990
|
let isInCodeBlock = false;
|
|
7990
7991
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
7991
|
-
|
|
7992
|
-
if (node.type.name === "codeBlock") {
|
|
7992
|
+
if ($from.node(depth).type.name === "codeBlock") {
|
|
7993
7993
|
isInCodeBlock = true;
|
|
7994
7994
|
break;
|
|
7995
7995
|
}
|
|
7996
7996
|
}
|
|
7997
|
-
if (isInCodeBlock)
|
|
7998
|
-
|
|
7997
|
+
if (isInCodeBlock) return false;
|
|
7998
|
+
let font = null;
|
|
7999
|
+
let color = null;
|
|
8000
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
8001
|
+
const node = $from.node(depth);
|
|
8002
|
+
if (!font && node.attrs?.fontFamily) font = node.attrs.fontFamily;
|
|
8003
|
+
if (!color && node.attrs?.color) color = node.attrs.color;
|
|
8004
|
+
if (font && color) break;
|
|
7999
8005
|
}
|
|
8000
|
-
const parentNode = $from.parent;
|
|
8001
|
-
let font = parentNode.attrs.fontFamily;
|
|
8002
|
-
let color = parentNode.attrs.color;
|
|
8003
8006
|
const textStyleMark = marks.find((m) => m.type.name === "textStyle");
|
|
8004
|
-
if (!font && textStyleMark?.attrs.fontFamily)
|
|
8005
|
-
|
|
8006
|
-
}
|
|
8007
|
-
if (!color && textStyleMark?.attrs.color) {
|
|
8008
|
-
color = textStyleMark.attrs.color;
|
|
8009
|
-
}
|
|
8007
|
+
if (!font && textStyleMark?.attrs.fontFamily) font = textStyleMark.attrs.fontFamily;
|
|
8008
|
+
if (!color && textStyleMark?.attrs.color) color = textStyleMark.attrs.color;
|
|
8010
8009
|
if (font || color) {
|
|
8011
8010
|
const pluginState = stylePersistenceKey.getState(state);
|
|
8012
8011
|
pluginState.lastFont = font || pluginState.lastFont;
|