UNPKG

@udecode/plate-heading

Version:

Headings plugin for Plate

102 lines (97 loc) 2.86 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, { BaseHeadingPlugin: () => BaseHeadingPlugin, BaseTocPlugin: () => BaseTocPlugin, insertToc: () => insertToc, isHeading: () => isHeading }); module.exports = __toCommonJS(index_exports); // src/lib/BaseHeadingPlugin.ts var import_plate = require("@udecode/plate"); var BaseHeadingPlugin = (0, import_plate.createTSlatePlugin)({ key: "heading", options: { levels: [1, 2, 3, 4, 5, 6] } }).extend(({ plugin }) => { const { options: { levels } } = plugin; const plugins = []; const headingLevels = Array.isArray(levels) ? levels : Array.from({ length: levels || 6 }, (_, i) => i + 1); headingLevels.forEach((level) => { const plugin2 = (0, import_plate.createSlatePlugin)({ key: import_plate.KEYS.heading[level - 1], node: { isElement: true }, parsers: { html: { deserializer: { rules: [ { validNodeName: `H${level}` } ] } } }, render: { as: `h${level}` } }); plugins.push(plugin2); }); return { plugins }; }); // src/lib/BaseTocPlugin.ts var import_plate2 = require("@udecode/plate"); var BaseTocPlugin = (0, import_plate2.createTSlatePlugin)({ key: import_plate2.KEYS.toc, node: { isElement: true, isVoid: true }, options: { isScroll: true, topOffset: 80 } }); // src/lib/transforms/insertToc.ts var import_plate3 = require("@udecode/plate"); var insertToc = (editor, options) => { editor.tf.insertNodes( { children: [{ text: "" }], type: editor.getType(import_plate3.KEYS.toc) }, options ); }; // src/lib/utils/isHeading.ts var import_plate4 = require("@udecode/plate"); var isHeading = (node) => { return node.type && import_plate4.KEYS.heading.includes(node.type); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BaseHeadingPlugin, BaseTocPlugin, insertToc, isHeading }); //# sourceMappingURL=index.js.map