@udecode/plate-basic-marks
Version:
Basic marks plugin for Plate
315 lines (292 loc) • 8.4 kB
JavaScript
// src/react/BasicMarksPlugin.tsx
import { toPlatePlugin as toPlatePlugin8 } from "@udecode/plate/react";
// src/lib/BaseBasicMarksPlugin.ts
import { createSlatePlugin as createSlatePlugin8 } from "@udecode/plate";
// src/lib/BaseBoldPlugin.ts
import { createSlatePlugin, KEYS, someHtmlElement } from "@udecode/plate";
var BaseBoldPlugin = createSlatePlugin({
key: KEYS.bold,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["STRONG", "B"] },
{
validStyle: {
fontWeight: ["600", "700", "bold"]
}
}
],
query: ({ element }) => !someHtmlElement(
element,
(node) => node.style.fontWeight === "normal"
)
}
}
},
render: { as: "strong" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/lib/BaseCodePlugin.ts
import { createSlatePlugin as createSlatePlugin2, findHtmlParentElement, KEYS as KEYS2 } from "@udecode/plate";
var BaseCodePlugin = createSlatePlugin2({
key: KEYS2.code,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["CODE"] },
{ validStyle: { fontFamily: "Consolas" } }
],
query({ element }) {
const blockAbove = findHtmlParentElement(element, "P");
if (blockAbove?.style.fontFamily === "Consolas") return false;
return !findHtmlParentElement(element, "PRE");
}
}
}
},
render: { as: "code" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/lib/BaseItalicPlugin.ts
import { createSlatePlugin as createSlatePlugin3, KEYS as KEYS3, someHtmlElement as someHtmlElement2 } from "@udecode/plate";
var BaseItalicPlugin = createSlatePlugin3({
key: KEYS3.italic,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["EM", "I"] },
{ validStyle: { fontStyle: "italic" } }
],
query: ({ element }) => !someHtmlElement2(
element,
(node) => node.style.fontStyle === "normal"
)
}
}
},
render: { as: "em" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/lib/BaseStrikethroughPlugin.ts
import { createSlatePlugin as createSlatePlugin4, KEYS as KEYS4, someHtmlElement as someHtmlElement3 } from "@udecode/plate";
var BaseStrikethroughPlugin = createSlatePlugin4({
key: KEYS4.strikethrough,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["S", "DEL", "STRIKE"] },
{ validStyle: { textDecoration: "line-through" } }
],
query: ({ element }) => !someHtmlElement3(
element,
(node) => node.style.textDecoration === "none"
)
}
}
},
render: { as: "s" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/lib/BaseSubscriptPlugin.ts
import { createSlatePlugin as createSlatePlugin5, KEYS as KEYS5 } from "@udecode/plate";
var BaseSubscriptPlugin = createSlatePlugin5({
key: KEYS5.sub,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["SUB"] },
{ validStyle: { verticalAlign: "sub" } }
]
}
}
},
render: { as: "sub" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type, {
remove: editor.getType(KEYS5.sup)
});
}
}));
// src/lib/BaseSuperscriptPlugin.ts
import { createSlatePlugin as createSlatePlugin6, KEYS as KEYS6 } from "@udecode/plate";
var BaseSuperscriptPlugin = createSlatePlugin6({
key: KEYS6.sup,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["SUP"] },
{ validStyle: { verticalAlign: "super" } }
]
}
}
},
render: { as: "sup" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type, {
remove: editor.getType(KEYS6.sub)
});
}
}));
// src/lib/BaseUnderlinePlugin.ts
import { createSlatePlugin as createSlatePlugin7, KEYS as KEYS7, someHtmlElement as someHtmlElement4 } from "@udecode/plate";
var BaseUnderlinePlugin = createSlatePlugin7({
key: KEYS7.underline,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{ validNodeName: ["U"] },
{ validStyle: { textDecoration: ["underline"] } }
],
query: ({ element }) => !someHtmlElement4(
element,
(node) => node.style.textDecoration === "none"
)
}
}
},
render: { as: "u" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/lib/BaseBasicMarksPlugin.ts
var BaseBasicMarksPlugin = createSlatePlugin8({
plugins: [
BaseBoldPlugin,
BaseCodePlugin,
BaseItalicPlugin,
BaseStrikethroughPlugin,
BaseSubscriptPlugin,
BaseSuperscriptPlugin,
BaseUnderlinePlugin
]
});
// src/react/BoldPlugin.tsx
import { Key, toPlatePlugin } from "@udecode/plate/react";
var BoldPlugin = toPlatePlugin(BaseBoldPlugin, {
shortcuts: { toggle: { keys: [[Key.Mod, "b"]] } }
});
// src/react/CodePlugin.tsx
import { toPlatePlugin as toPlatePlugin2 } from "@udecode/plate/react";
var CodePlugin = toPlatePlugin2(BaseCodePlugin);
// src/react/ItalicPlugin.tsx
import { Key as Key2, toPlatePlugin as toPlatePlugin3 } from "@udecode/plate/react";
var ItalicPlugin = toPlatePlugin3(BaseItalicPlugin, {
shortcuts: { toggle: { keys: [[Key2.Mod, "i"]] } }
});
// src/react/StrikethroughPlugin.tsx
import { toPlatePlugin as toPlatePlugin4 } from "@udecode/plate/react";
var StrikethroughPlugin = toPlatePlugin4(BaseStrikethroughPlugin);
// src/react/SubscriptPlugin.tsx
import { toPlatePlugin as toPlatePlugin5 } from "@udecode/plate/react";
var SubscriptPlugin = toPlatePlugin5(BaseSubscriptPlugin);
// src/react/SuperscriptPlugin.tsx
import { toPlatePlugin as toPlatePlugin6 } from "@udecode/plate/react";
var SuperscriptPlugin = toPlatePlugin6(BaseSuperscriptPlugin);
// src/react/UnderlinePlugin.tsx
import { Key as Key3, toPlatePlugin as toPlatePlugin7 } from "@udecode/plate/react";
var UnderlinePlugin = toPlatePlugin7(BaseUnderlinePlugin, {
shortcuts: { toggle: { keys: [[Key3.Mod, "u"]] } }
});
// src/react/BasicMarksPlugin.tsx
var BasicMarksPlugin = toPlatePlugin8(BaseBasicMarksPlugin, {
plugins: [
BoldPlugin,
CodePlugin,
ItalicPlugin,
StrikethroughPlugin,
SubscriptPlugin,
SuperscriptPlugin,
UnderlinePlugin
]
});
// src/react/HighlightPlugin.tsx
import { toPlatePlugin as toPlatePlugin9 } from "@udecode/plate/react";
// src/lib/BaseHighlightPlugin.ts
import { createSlatePlugin as createSlatePlugin9, KEYS as KEYS8 } from "@udecode/plate";
var BaseHighlightPlugin = createSlatePlugin9({
key: KEYS8.highlight,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [
{
validNodeName: ["MARK"]
}
]
}
}
},
render: { as: "mark" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/react/HighlightPlugin.tsx
var HighlightPlugin = toPlatePlugin9(BaseHighlightPlugin);
// src/react/KbdPlugin.tsx
import { toPlatePlugin as toPlatePlugin10 } from "@udecode/plate/react";
// src/lib/BaseKbdPlugin.ts
import { createSlatePlugin as createSlatePlugin10, KEYS as KEYS9 } from "@udecode/plate";
var BaseKbdPlugin = createSlatePlugin10({
key: KEYS9.kbd,
node: { isLeaf: true },
parsers: {
html: {
deserializer: {
rules: [{ validNodeName: ["KBD"] }]
}
}
},
render: { as: "kbd" }
}).extendTransforms(({ editor, type }) => ({
toggle: () => {
editor.tf.toggleMark(type);
}
}));
// src/react/KbdPlugin.tsx
var KbdPlugin = toPlatePlugin10(BaseKbdPlugin);
export {
BasicMarksPlugin,
BoldPlugin,
CodePlugin,
HighlightPlugin,
ItalicPlugin,
KbdPlugin,
StrikethroughPlugin,
SubscriptPlugin,
SuperscriptPlugin,
UnderlinePlugin
};
//# sourceMappingURL=index.mjs.map