smartrte-core 0.2.0 → 0.2.1
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/CHANGELOG.md +4 -0
- package/dist/commands/marks.js +19 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/commands/marks.js
CHANGED
|
@@ -89,11 +89,28 @@ const createMarkCommand = (id, nextMark, toggle) => ({
|
|
|
89
89
|
},
|
|
90
90
|
});
|
|
91
91
|
const toggle = (id, type) => createMarkCommand(id, () => ({ type }), true);
|
|
92
|
+
const toggleScript = (id, type) => ({
|
|
93
|
+
id,
|
|
94
|
+
isEnabled: (context) => Boolean(getTextRange(context)),
|
|
95
|
+
execute: (context) => {
|
|
96
|
+
const range = getTextRange(context);
|
|
97
|
+
if (!range)
|
|
98
|
+
throw new Error(`${id} requires text in one inline container.`);
|
|
99
|
+
const remove = range.nodes
|
|
100
|
+
.slice(range.startIndex, range.endIndex + 1)
|
|
101
|
+
.every((node) => hasMark(node.marks, type));
|
|
102
|
+
const opposite = type === "superscript" ? "subscript" : "superscript";
|
|
103
|
+
return createMarkTransaction(id, context, undefined, (marks) => {
|
|
104
|
+
const withoutOpposite = removeMark(marks, opposite);
|
|
105
|
+
return remove ? removeMark(withoutOpposite, type) : addMark(withoutOpposite, { type });
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
});
|
|
92
109
|
export const toggleBold = toggle("toggle-bold", "bold");
|
|
93
110
|
export const toggleItalic = toggle("toggle-italic", "italic");
|
|
94
111
|
export const toggleUnderline = toggle("toggle-underline", "underline");
|
|
95
|
-
export const toggleSuperscript =
|
|
96
|
-
export const toggleSubscript =
|
|
112
|
+
export const toggleSuperscript = toggleScript("toggle-superscript", "superscript");
|
|
113
|
+
export const toggleSubscript = toggleScript("toggle-subscript", "subscript");
|
|
97
114
|
export const applyTextColor = createMarkCommand("apply-text-color", (value) => ({ type: "textColor", value }), false);
|
|
98
115
|
export const applyBackgroundColor = createMarkCommand("apply-background-color", (value) => ({ type: "backgroundColor", value }), false);
|
|
99
116
|
export const applyFontSize = createMarkCommand("apply-font-size", (valuePx) => ({ type: "fontSize", valuePx }), false);
|