112 lines
3.6 KiB
JavaScript
112 lines
3.6 KiB
JavaScript
"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, {
|
|
HorizontalRule: () => HorizontalRule,
|
|
default: () => index_default
|
|
});
|
|
module.exports = __toCommonJS(index_exports);
|
|
|
|
// src/horizontal-rule.ts
|
|
var import_core = require("@tiptap/core");
|
|
var import_state = require("@tiptap/pm/state");
|
|
var HorizontalRule = import_core.Node.create({
|
|
name: "horizontalRule",
|
|
addOptions() {
|
|
return {
|
|
HTMLAttributes: {},
|
|
nextNodeType: "paragraph"
|
|
};
|
|
},
|
|
group: "block",
|
|
parseHTML() {
|
|
return [{ tag: "hr" }];
|
|
},
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ["hr", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes)];
|
|
},
|
|
markdownTokenName: "hr",
|
|
parseMarkdown: (token, helpers) => {
|
|
return helpers.createNode("horizontalRule");
|
|
},
|
|
renderMarkdown: () => {
|
|
return "---";
|
|
},
|
|
addCommands() {
|
|
return {
|
|
setHorizontalRule: () => ({ chain, state }) => {
|
|
if (!(0, import_core.canInsertNode)(state, state.schema.nodes[this.name])) {
|
|
return false;
|
|
}
|
|
const { selection } = state;
|
|
const { $to: $originTo } = selection;
|
|
const currentChain = chain();
|
|
if ((0, import_core.isNodeSelection)(selection)) {
|
|
currentChain.insertContentAt($originTo.pos, {
|
|
type: this.name
|
|
});
|
|
} else {
|
|
currentChain.insertContent({ type: this.name });
|
|
}
|
|
return currentChain.command(({ state: chainState, tr, dispatch }) => {
|
|
if (dispatch) {
|
|
const { $to } = tr.selection;
|
|
const posAfter = $to.end();
|
|
if ($to.nodeAfter) {
|
|
if ($to.nodeAfter.isTextblock) {
|
|
tr.setSelection(import_state.TextSelection.create(tr.doc, $to.pos + 1));
|
|
} else if ($to.nodeAfter.isBlock) {
|
|
tr.setSelection(import_state.NodeSelection.create(tr.doc, $to.pos));
|
|
} else {
|
|
tr.setSelection(import_state.TextSelection.create(tr.doc, $to.pos));
|
|
}
|
|
} else {
|
|
const nodeType = chainState.schema.nodes[this.options.nextNodeType] || $to.parent.type.contentMatch.defaultType;
|
|
const node = nodeType == null ? void 0 : nodeType.create();
|
|
if (node) {
|
|
tr.insert(posAfter, node);
|
|
tr.setSelection(import_state.TextSelection.create(tr.doc, posAfter + 1));
|
|
}
|
|
}
|
|
tr.scrollIntoView();
|
|
}
|
|
return true;
|
|
}).run();
|
|
}
|
|
};
|
|
},
|
|
addInputRules() {
|
|
return [
|
|
(0, import_core.nodeInputRule)({
|
|
find: /^(?:---|—-|___\s|\*\*\*\s)$/,
|
|
type: this.type
|
|
})
|
|
];
|
|
}
|
|
});
|
|
|
|
// src/index.ts
|
|
var index_default = HorizontalRule;
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
HorizontalRule
|
|
});
|
|
//# sourceMappingURL=index.cjs.map
|