UNPKG

@udecode/plate-basic-marks

Version:

Basic marks plugin for Plate

289 lines (277 loc) 7.76 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { BaseBasicMarksPlugin: () => BaseBasicMarksPlugin, BaseBoldPlugin: () => BaseBoldPlugin, BaseCodePlugin: () => BaseCodePlugin, BaseHighlightPlugin: () => BaseHighlightPlugin, BaseItalicPlugin: () => BaseItalicPlugin, BaseKbdPlugin: () => BaseKbdPlugin, BaseStrikethroughPlugin: () => BaseStrikethroughPlugin, BaseSubscriptPlugin: () => BaseSubscriptPlugin, BaseSuperscriptPlugin: () => BaseSuperscriptPlugin, BaseUnderlinePlugin: () => BaseUnderlinePlugin }); module.exports = __toCommonJS(index_exports); // src/lib/BaseBasicMarksPlugin.ts var import_plate8 = require("@udecode/plate"); // src/lib/BaseBoldPlugin.ts var import_plate = require("@udecode/plate"); var BaseBoldPlugin = (0, import_plate.createSlatePlugin)({ key: import_plate.KEYS.bold, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: ["STRONG", "B"] }, { validStyle: { fontWeight: ["600", "700", "bold"] } } ], query: ({ element }) => !(0, import_plate.someHtmlElement)( element, (node) => node.style.fontWeight === "normal" ) } } }, render: { as: "strong" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // src/lib/BaseCodePlugin.ts var import_plate2 = require("@udecode/plate"); var BaseCodePlugin = (0, import_plate2.createSlatePlugin)({ key: import_plate2.KEYS.code, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: ["CODE"] }, { validStyle: { fontFamily: "Consolas" } } ], query({ element }) { const blockAbove = (0, import_plate2.findHtmlParentElement)(element, "P"); if (blockAbove?.style.fontFamily === "Consolas") return false; return !(0, import_plate2.findHtmlParentElement)(element, "PRE"); } } } }, render: { as: "code" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // src/lib/BaseItalicPlugin.ts var import_plate3 = require("@udecode/plate"); var BaseItalicPlugin = (0, import_plate3.createSlatePlugin)({ key: import_plate3.KEYS.italic, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: ["EM", "I"] }, { validStyle: { fontStyle: "italic" } } ], query: ({ element }) => !(0, import_plate3.someHtmlElement)( element, (node) => node.style.fontStyle === "normal" ) } } }, render: { as: "em" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // src/lib/BaseStrikethroughPlugin.ts var import_plate4 = require("@udecode/plate"); var BaseStrikethroughPlugin = (0, import_plate4.createSlatePlugin)({ key: import_plate4.KEYS.strikethrough, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: ["S", "DEL", "STRIKE"] }, { validStyle: { textDecoration: "line-through" } } ], query: ({ element }) => !(0, import_plate4.someHtmlElement)( element, (node) => node.style.textDecoration === "none" ) } } }, render: { as: "s" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // src/lib/BaseSubscriptPlugin.ts var import_plate5 = require("@udecode/plate"); var BaseSubscriptPlugin = (0, import_plate5.createSlatePlugin)({ key: import_plate5.KEYS.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(import_plate5.KEYS.sup) }); } })); // src/lib/BaseSuperscriptPlugin.ts var import_plate6 = require("@udecode/plate"); var BaseSuperscriptPlugin = (0, import_plate6.createSlatePlugin)({ key: import_plate6.KEYS.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(import_plate6.KEYS.sub) }); } })); // src/lib/BaseUnderlinePlugin.ts var import_plate7 = require("@udecode/plate"); var BaseUnderlinePlugin = (0, import_plate7.createSlatePlugin)({ key: import_plate7.KEYS.underline, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: ["U"] }, { validStyle: { textDecoration: ["underline"] } } ], query: ({ element }) => !(0, import_plate7.someHtmlElement)( element, (node) => node.style.textDecoration === "none" ) } } }, render: { as: "u" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // src/lib/BaseBasicMarksPlugin.ts var BaseBasicMarksPlugin = (0, import_plate8.createSlatePlugin)({ plugins: [ BaseBoldPlugin, BaseCodePlugin, BaseItalicPlugin, BaseStrikethroughPlugin, BaseSubscriptPlugin, BaseSuperscriptPlugin, BaseUnderlinePlugin ] }); // src/lib/BaseHighlightPlugin.ts var import_plate9 = require("@udecode/plate"); var BaseHighlightPlugin = (0, import_plate9.createSlatePlugin)({ key: import_plate9.KEYS.highlight, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: ["MARK"] } ] } } }, render: { as: "mark" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // src/lib/BaseKbdPlugin.ts var import_plate10 = require("@udecode/plate"); var BaseKbdPlugin = (0, import_plate10.createSlatePlugin)({ key: import_plate10.KEYS.kbd, node: { isLeaf: true }, parsers: { html: { deserializer: { rules: [{ validNodeName: ["KBD"] }] } } }, render: { as: "kbd" } }).extendTransforms(({ editor, type }) => ({ toggle: () => { editor.tf.toggleMark(type); } })); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BaseBasicMarksPlugin, BaseBoldPlugin, BaseCodePlugin, BaseHighlightPlugin, BaseItalicPlugin, BaseKbdPlugin, BaseStrikethroughPlugin, BaseSubscriptPlugin, BaseSuperscriptPlugin, BaseUnderlinePlugin }); //# sourceMappingURL=index.js.map