tiptap-markdown
Advanced tools
Comparing version 0.8.3 to 0.8.4
@@ -0,1 +1,7 @@ | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
import { Extension, Mark, getHTMLFromFragment, Node as Node$1, extensions } from "@tiptap/core"; | ||
@@ -7,220 +13,10 @@ import { MarkdownSerializerState as MarkdownSerializerState$1, defaultMarkdownSerializer } from "prosemirror-markdown"; | ||
import { Plugin, PluginKey } from "@tiptap/pm/state"; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) | ||
descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) | ||
_defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) | ||
_defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) { | ||
return o2.__proto__ || Object.getPrototypeOf(o2); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) { | ||
o2.__proto__ = p2; | ||
return o2; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) | ||
return false; | ||
if (Reflect.construct.sham) | ||
return false; | ||
if (typeof Proxy === "function") | ||
return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { | ||
})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) | ||
break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get2(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) | ||
return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) | ||
return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) | ||
return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) | ||
return; | ||
if (typeof o === "string") | ||
return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) | ||
n = o.constructor.name; | ||
if (n === "Map" || n === "Set") | ||
return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) | ||
return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) | ||
len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) | ||
arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) | ||
return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== void 0) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") | ||
return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
var MarkdownTightLists = Extension.create({ | ||
const MarkdownTightLists = Extension.create({ | ||
name: "markdownTightLists", | ||
addOptions: function addOptions() { | ||
return { | ||
tight: true, | ||
tightClass: "tight", | ||
listTypes: ["bulletList", "orderedList"] | ||
}; | ||
}, | ||
addGlobalAttributes: function addGlobalAttributes() { | ||
var _this = this; | ||
addOptions: () => ({ | ||
tight: true, | ||
tightClass: "tight", | ||
listTypes: ["bulletList", "orderedList"] | ||
}), | ||
addGlobalAttributes() { | ||
return [{ | ||
@@ -230,12 +26,8 @@ types: this.options.listTypes, | ||
tight: { | ||
"default": this.options.tight, | ||
parseHTML: function parseHTML(element) { | ||
return element.getAttribute("data-tight") === "true" || !element.querySelector("p"); | ||
}, | ||
renderHTML: function renderHTML(attributes) { | ||
return { | ||
"class": attributes.tight ? _this.options.tightClass : null, | ||
"data-tight": attributes.tight ? "true" : null | ||
}; | ||
} | ||
default: this.options.tight, | ||
parseHTML: (element) => element.getAttribute("data-tight") === "true" || !element.querySelector("p"), | ||
renderHTML: (attributes) => ({ | ||
class: attributes.tight ? this.options.tightClass : null, | ||
"data-tight": attributes.tight ? "true" : null | ||
}) | ||
} | ||
@@ -245,14 +37,17 @@ } | ||
}, | ||
addCommands: function addCommands() { | ||
var _this2 = this; | ||
addCommands() { | ||
var _this = this; | ||
return { | ||
toggleTight: function toggleTight() { | ||
var tight = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null; | ||
return function(_ref) { | ||
var editor = _ref.editor, commands = _ref.commands; | ||
function toggleTight2(name) { | ||
toggleTight: function() { | ||
let tight = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null; | ||
return (_ref) => { | ||
let { | ||
editor, | ||
commands | ||
} = _ref; | ||
function toggleTight(name) { | ||
if (!editor.isActive(name)) { | ||
return false; | ||
} | ||
var attrs = editor.getAttributes(name); | ||
const attrs = editor.getAttributes(name); | ||
return commands.updateAttributes(name, { | ||
@@ -262,5 +57,3 @@ tight: tight !== null && tight !== void 0 ? tight : !(attrs !== null && attrs !== void 0 && attrs.tight) | ||
} | ||
return _this2.options.listTypes.some(function(name) { | ||
return toggleTight2(name); | ||
}); | ||
return _this.options.listTypes.some((name) => toggleTight(name)); | ||
}; | ||
@@ -271,3 +64,3 @@ } | ||
}); | ||
var md = markdownit(); | ||
const md = markdownit(); | ||
function scanDelims(text, pos) { | ||
@@ -278,7 +71,7 @@ md.inline.State.prototype.scanDelims.call({ | ||
}); | ||
var state = new md.inline.State(text, null, null, []); | ||
const state = new md.inline.State(text, null, null, []); | ||
return state.scanDelims(pos, true); | ||
} | ||
function shiftDelim(text, delim, start, offset) { | ||
var res = text.substring(0, start) + text.substring(start + delim.length); | ||
let res = text.substring(0, start) + text.substring(start + delim.length); | ||
res = res.substring(0, start + offset) + delim + res.substring(start + offset); | ||
@@ -288,3 +81,3 @@ return res; | ||
function trimStart(text, delim, from, to) { | ||
var pos = from, res = text; | ||
let pos = from, res = text; | ||
while (pos < to) { | ||
@@ -304,3 +97,3 @@ if (scanDelims(res, pos).can_open) { | ||
function trimEnd(text, delim, from, to) { | ||
var pos = to, res = text; | ||
let pos = to, res = text; | ||
while (pos > from) { | ||
@@ -320,3 +113,3 @@ if (scanDelims(res, pos).can_close) { | ||
function trimInline(text, delim, from, to) { | ||
var state = { | ||
let state = { | ||
text, | ||
@@ -333,57 +126,52 @@ from, | ||
} | ||
var MarkdownSerializerState = /* @__PURE__ */ function(_BaseMarkdownSerializ) { | ||
_inherits(MarkdownSerializerState2, _BaseMarkdownSerializ); | ||
var _super = _createSuper(MarkdownSerializerState2); | ||
function MarkdownSerializerState2(nodes, marks, options) { | ||
var _this; | ||
_classCallCheck(this, MarkdownSerializerState2); | ||
_this = _super.call(this, nodes, marks, options !== null && options !== void 0 ? options : {}); | ||
_this.inlines = []; | ||
return _this; | ||
class MarkdownSerializerState extends MarkdownSerializerState$1 { | ||
constructor(nodes, marks, options) { | ||
super(nodes, marks, options !== null && options !== void 0 ? options : {}); | ||
this.inlines = []; | ||
} | ||
_createClass(MarkdownSerializerState2, [{ | ||
key: "render", | ||
value: function render(node, parent, index) { | ||
_get(_getPrototypeOf(MarkdownSerializerState2.prototype), "render", this).call(this, node, parent, index); | ||
var top = this.inlines[this.inlines.length - 1]; | ||
if (top !== null && top !== void 0 && top.start && top !== null && top !== void 0 && top.end) { | ||
var _this$normalizeInline = this.normalizeInline(top), delimiter = _this$normalizeInline.delimiter, start = _this$normalizeInline.start, end = _this$normalizeInline.end; | ||
this.out = trimInline(this.out, delimiter, start, end); | ||
this.inlines.pop(); | ||
} | ||
render(node, parent, index) { | ||
super.render(node, parent, index); | ||
const top = this.inlines[this.inlines.length - 1]; | ||
if (top !== null && top !== void 0 && top.start && top !== null && top !== void 0 && top.end) { | ||
const { | ||
delimiter, | ||
start, | ||
end | ||
} = this.normalizeInline(top); | ||
this.out = trimInline(this.out, delimiter, start, end); | ||
this.inlines.pop(); | ||
} | ||
}, { | ||
key: "markString", | ||
value: function markString(mark, open, parent, index) { | ||
var info = this.marks[mark.type.name]; | ||
if (info.expelEnclosingWhitespace) { | ||
if (open) { | ||
this.inlines.push({ | ||
start: this.out.length, | ||
delimiter: info.open | ||
}); | ||
} else { | ||
var top = this.inlines.pop(); | ||
this.inlines.push(_objectSpread2(_objectSpread2({}, top), {}, { | ||
end: this.out.length | ||
})); | ||
} | ||
} | ||
markString(mark, open, parent, index) { | ||
const info = this.marks[mark.type.name]; | ||
if (info.expelEnclosingWhitespace) { | ||
if (open) { | ||
this.inlines.push({ | ||
start: this.out.length, | ||
delimiter: info.open | ||
}); | ||
} else { | ||
const top = this.inlines.pop(); | ||
this.inlines.push({ | ||
...top, | ||
end: this.out.length | ||
}); | ||
} | ||
return _get(_getPrototypeOf(MarkdownSerializerState2.prototype), "markString", this).call(this, mark, open, parent, index); | ||
} | ||
}, { | ||
key: "normalizeInline", | ||
value: function normalizeInline(inline) { | ||
var start = inline.start; | ||
inline.end; | ||
while (this.out.charAt(start).match(/\s/)) { | ||
start++; | ||
} | ||
return _objectSpread2(_objectSpread2({}, inline), {}, { | ||
start | ||
}); | ||
return super.markString(mark, open, parent, index); | ||
} | ||
normalizeInline(inline) { | ||
let { | ||
start, | ||
end | ||
} = inline; | ||
while (this.out.charAt(start).match(/\s/)) { | ||
start++; | ||
} | ||
}]); | ||
return MarkdownSerializerState2; | ||
}(MarkdownSerializerState$1); | ||
return { | ||
...inline, | ||
start | ||
}; | ||
} | ||
} | ||
const HTMLMark = Mark.create({ | ||
@@ -394,10 +182,10 @@ name: "markdownHTMLMark", | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: { | ||
open: function open(state, mark) { | ||
open(state, mark) { | ||
var _getMarkTags$, _getMarkTags; | ||
if (!this.editor.storage.markdown.options.html) { | ||
console.warn('Tiptap Markdown: "'.concat(mark.type.name, '" mark is only available in html mode')); | ||
console.warn(`Tiptap Markdown: "${mark.type.name}" mark is only available in html mode`); | ||
return ""; | ||
@@ -407,3 +195,3 @@ } | ||
}, | ||
close: function close(state, mark) { | ||
close(state, mark) { | ||
var _getMarkTags$2, _getMarkTags2; | ||
@@ -424,10 +212,10 @@ if (!this.editor.storage.markdown.options.html) { | ||
function getMarkTags(mark) { | ||
var schema = mark.type.schema; | ||
var node = schema.text(" ", [mark]); | ||
var html = getHTMLFromFragment(Fragment.from(node), schema); | ||
var match = html.match(/^(<.*?>) (<\/.*?>)$/); | ||
const schema = mark.type.schema; | ||
const node = schema.text(" ", [mark]); | ||
const html = getHTMLFromFragment(Fragment.from(node), schema); | ||
const match = html.match(/^(<.*?>) (<\/.*?>)$/); | ||
return match ? [match[1], match[2]] : null; | ||
} | ||
function elementFromString(value) { | ||
var wrappedValue = "<body>".concat(value, "</body>"); | ||
const wrappedValue = `<body>${value}</body>`; | ||
return new window.DOMParser().parseFromString(wrappedValue, "text/html").body; | ||
@@ -439,4 +227,4 @@ } | ||
function extractElement(node) { | ||
var parent = node.parentElement; | ||
var prepend = parent.cloneNode(); | ||
const parent = node.parentElement; | ||
const prepend = parent.cloneNode(); | ||
while (parent.firstChild && parent.firstChild !== node) { | ||
@@ -454,6 +242,5 @@ prepend.appendChild(parent.firstChild); | ||
function unwrapElement(node) { | ||
var parent = node.parentNode; | ||
while (node.firstChild) { | ||
const parent = node.parentNode; | ||
while (node.firstChild) | ||
parent.insertBefore(node.firstChild, node); | ||
} | ||
parent.removeChild(node); | ||
@@ -463,11 +250,11 @@ } | ||
name: "markdownHTMLNode", | ||
addStorage: function addStorage2() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state, node, parent) { | ||
serialize(state, node, parent) { | ||
if (this.editor.storage.markdown.options.html) { | ||
state.write(serializeHTML(node, parent)); | ||
} else { | ||
console.warn('Tiptap Markdown: "'.concat(node.type.name, '" node is only available in html mode')); | ||
state.write("[".concat(node.type.name, "]")); | ||
console.warn(`Tiptap Markdown: "${node.type.name}" node is only available in html mode`); | ||
state.write(`[${node.type.name}]`); | ||
} | ||
@@ -486,4 +273,4 @@ if (node.isBlock) { | ||
function serializeHTML(node, parent) { | ||
var schema = node.type.schema; | ||
var html = getHTMLFromFragment(Fragment.from(node), schema); | ||
const schema = node.type.schema; | ||
const html = getHTMLFromFragment(Fragment.from(node), schema); | ||
if (node.isBlock && (parent instanceof Fragment || parent.type.name === schema.topNodeType.name)) { | ||
@@ -495,8 +282,11 @@ return formatBlock(html); | ||
function formatBlock(html) { | ||
var dom = elementFromString(html); | ||
var element = dom.firstElementChild; | ||
element.innerHTML = element.innerHTML.trim() ? "\n".concat(element.innerHTML, "\n") : "\n"; | ||
const dom = elementFromString(html); | ||
const element = dom.firstElementChild; | ||
element.innerHTML = element.innerHTML.trim() ? ` | ||
${element.innerHTML} | ||
` : ` | ||
`; | ||
return element.outerHTML; | ||
} | ||
var Blockquote = Node$1.create({ | ||
const Blockquote = Node$1.create({ | ||
name: "blockquote" | ||
@@ -508,3 +298,3 @@ }); | ||
*/ | ||
addStorage: function addStorage3() { | ||
addStorage() { | ||
return { | ||
@@ -520,3 +310,3 @@ markdown: { | ||
}); | ||
var BulletList = Node$1.create({ | ||
const BulletList = Node$1.create({ | ||
name: "bulletList" | ||
@@ -528,10 +318,7 @@ }); | ||
*/ | ||
addStorage: function addStorage4() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state, node) { | ||
var _this = this; | ||
return state.renderList(node, " ", function() { | ||
return (_this.editor.storage.markdown.options.bulletListMarker || "-") + " "; | ||
}); | ||
serialize(state, node) { | ||
return state.renderList(node, " ", () => (this.editor.storage.markdown.options.bulletListMarker || "-") + " "); | ||
}, | ||
@@ -545,3 +332,3 @@ parse: { | ||
}); | ||
var CodeBlock = Node$1.create({ | ||
const CodeBlock = Node$1.create({ | ||
name: "codeBlock" | ||
@@ -553,6 +340,6 @@ }); | ||
*/ | ||
addStorage: function addStorage5() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state, node) { | ||
serialize(state, node) { | ||
state.write("```" + (node.attrs.language || "") + "\n"); | ||
@@ -565,3 +352,3 @@ state.text(node.textContent, false); | ||
parse: { | ||
setup: function setup(markdownit2) { | ||
setup(markdownit2) { | ||
var _this$options$languag; | ||
@@ -572,3 +359,3 @@ markdownit2.set({ | ||
}, | ||
updateDOM: function updateDOM(element) { | ||
updateDOM(element) { | ||
element.innerHTML = element.innerHTML.replace(/\n<\/code><\/pre>/g, "</code></pre>"); | ||
@@ -581,3 +368,3 @@ } | ||
}); | ||
var HardBreak = Node$1.create({ | ||
const HardBreak = Node$1.create({ | ||
name: "hardBreak" | ||
@@ -589,3 +376,3 @@ }); | ||
*/ | ||
addStorage: function addStorage6() { | ||
addStorage() { | ||
return { | ||
@@ -601,3 +388,3 @@ markdown: { | ||
}); | ||
var Heading = Node$1.create({ | ||
const Heading = Node$1.create({ | ||
name: "heading" | ||
@@ -609,3 +396,3 @@ }); | ||
*/ | ||
addStorage: function addStorage7() { | ||
addStorage() { | ||
return { | ||
@@ -621,3 +408,3 @@ markdown: { | ||
}); | ||
var HorizontalRule = Node$1.create({ | ||
const HorizontalRule = Node$1.create({ | ||
name: "horizontalRule" | ||
@@ -629,3 +416,3 @@ }); | ||
*/ | ||
addStorage: function addStorage8() { | ||
addStorage() { | ||
return { | ||
@@ -641,3 +428,3 @@ markdown: { | ||
}); | ||
var Image = Node$1.create({ | ||
const Image = Node$1.create({ | ||
name: "image" | ||
@@ -649,3 +436,3 @@ }); | ||
*/ | ||
addStorage: function addStorage9() { | ||
addStorage() { | ||
return { | ||
@@ -661,3 +448,3 @@ markdown: { | ||
}); | ||
var ListItem = Node$1.create({ | ||
const ListItem = Node$1.create({ | ||
name: "listItem" | ||
@@ -669,3 +456,3 @@ }); | ||
*/ | ||
addStorage: function addStorage10() { | ||
addStorage() { | ||
return { | ||
@@ -681,3 +468,3 @@ markdown: { | ||
}); | ||
var OrderedList = Node$1.create({ | ||
const OrderedList = Node$1.create({ | ||
name: "orderedList" | ||
@@ -689,3 +476,3 @@ }); | ||
*/ | ||
addStorage: function addStorage11() { | ||
addStorage() { | ||
return { | ||
@@ -701,3 +488,3 @@ markdown: { | ||
}); | ||
var Paragraph = Node$1.create({ | ||
const Paragraph = Node$1.create({ | ||
name: "paragraph" | ||
@@ -709,3 +496,3 @@ }); | ||
*/ | ||
addStorage: function addStorage12() { | ||
addStorage() { | ||
return { | ||
@@ -725,3 +512,3 @@ markdown: { | ||
} | ||
var Table = Node$1.create({ | ||
const Table = Node$1.create({ | ||
name: "table" | ||
@@ -733,6 +520,6 @@ }); | ||
*/ | ||
addStorage: function addStorage13() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state, node, parent) { | ||
serialize(state, node, parent) { | ||
if (!isMarkdownSerializable(node)) { | ||
@@ -742,9 +529,9 @@ HTMLNode.storage.markdown.serialize.call(this, state, node, parent); | ||
} | ||
node.forEach(function(row, p, i) { | ||
node.forEach((row, p, i) => { | ||
state.write("| "); | ||
row.forEach(function(col, p2, j) { | ||
row.forEach((col, p2, j) => { | ||
if (j) { | ||
state.write(" | "); | ||
} | ||
var cellContent = col.firstChild; | ||
const cellContent = col.firstChild; | ||
if (cellContent.textContent.trim()) { | ||
@@ -757,8 +544,6 @@ state.renderInline(cellContent); | ||
if (!i) { | ||
var delimiterRow = Array.from({ | ||
const delimiterRow = Array.from({ | ||
length: row.childCount | ||
}).map(function() { | ||
return "---"; | ||
}).join(" | "); | ||
state.write("| ".concat(delimiterRow, " |")); | ||
}).map(() => "---").join(" | "); | ||
state.write(`| ${delimiterRow} |`); | ||
state.ensureNewLine(); | ||
@@ -780,15 +565,9 @@ } | ||
function isMarkdownSerializable(node) { | ||
var rows = childNodes(node); | ||
var firstRow = rows[0]; | ||
var bodyRows = rows.slice(1); | ||
if (childNodes(firstRow).some(function(cell) { | ||
return cell.type.name !== "tableHeader" || hasSpan(cell) || cell.childCount > 1; | ||
})) { | ||
const rows = childNodes(node); | ||
const firstRow = rows[0]; | ||
const bodyRows = rows.slice(1); | ||
if (childNodes(firstRow).some((cell) => cell.type.name !== "tableHeader" || hasSpan(cell) || cell.childCount > 1)) { | ||
return false; | ||
} | ||
if (bodyRows.some(function(row) { | ||
return childNodes(row).some(function(cell) { | ||
return cell.type.name === "tableHeader" || hasSpan(cell) || cell.childCount > 1; | ||
}); | ||
})) { | ||
if (bodyRows.some((row) => childNodes(row).some((cell) => cell.type.name === "tableHeader" || hasSpan(cell) || cell.childCount > 1))) { | ||
return false; | ||
@@ -798,3 +577,3 @@ } | ||
} | ||
var TaskItem = Node$1.create({ | ||
const TaskItem = Node$1.create({ | ||
name: "taskItem" | ||
@@ -806,14 +585,14 @@ }); | ||
*/ | ||
addStorage: function addStorage14() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state, node) { | ||
var check = node.attrs.checked ? "[x]" : "[ ]"; | ||
state.write("".concat(check, " ")); | ||
serialize(state, node) { | ||
const check = node.attrs.checked ? "[x]" : "[ ]"; | ||
state.write(`${check} `); | ||
state.renderContent(node); | ||
}, | ||
parse: { | ||
updateDOM: function updateDOM(element) { | ||
_toConsumableArray(element.querySelectorAll(".task-list-item")).forEach(function(item) { | ||
var input = item.querySelector("input"); | ||
updateDOM(element) { | ||
[...element.querySelectorAll(".task-list-item")].forEach((item) => { | ||
const input = item.querySelector("input"); | ||
item.setAttribute("data-type", "taskItem"); | ||
@@ -831,3 +610,3 @@ if (input) { | ||
}); | ||
var TaskList = Node$1.create({ | ||
const TaskList = Node$1.create({ | ||
name: "taskList" | ||
@@ -839,3 +618,3 @@ }); | ||
*/ | ||
addStorage: function addStorage15() { | ||
addStorage() { | ||
return { | ||
@@ -845,7 +624,7 @@ markdown: { | ||
parse: { | ||
setup: function setup(markdownit2) { | ||
setup(markdownit2) { | ||
markdownit2.use(taskListPlugin); | ||
}, | ||
updateDOM: function updateDOM(element) { | ||
_toConsumableArray(element.querySelectorAll(".contains-task-list")).forEach(function(list) { | ||
updateDOM(element) { | ||
[...element.querySelectorAll(".contains-task-list")].forEach((list) => { | ||
list.setAttribute("data-type", "taskList"); | ||
@@ -859,3 +638,3 @@ }); | ||
}); | ||
var Text = Node$1.create({ | ||
const Text = Node$1.create({ | ||
name: "text" | ||
@@ -867,6 +646,6 @@ }); | ||
*/ | ||
addStorage: function addStorage16() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state, node) { | ||
serialize(state, node) { | ||
state.text(escapeHTML(node.text)); | ||
@@ -881,3 +660,3 @@ }, | ||
}); | ||
var Bold = Mark.create({ | ||
const Bold = Mark.create({ | ||
name: "bold" | ||
@@ -889,3 +668,3 @@ }); | ||
*/ | ||
addStorage: function addStorage17() { | ||
addStorage() { | ||
return { | ||
@@ -901,3 +680,3 @@ markdown: { | ||
}); | ||
var Code = Mark.create({ | ||
const Code = Mark.create({ | ||
name: "code" | ||
@@ -909,3 +688,3 @@ }); | ||
*/ | ||
addStorage: function addStorage18() { | ||
addStorage() { | ||
return { | ||
@@ -921,3 +700,3 @@ markdown: { | ||
}); | ||
var Italic = Mark.create({ | ||
const Italic = Mark.create({ | ||
name: "italic" | ||
@@ -929,3 +708,3 @@ }); | ||
*/ | ||
addStorage: function addStorage19() { | ||
addStorage() { | ||
return { | ||
@@ -941,3 +720,3 @@ markdown: { | ||
}); | ||
var Link = Mark.create({ | ||
const Link = Mark.create({ | ||
name: "link" | ||
@@ -949,3 +728,3 @@ }); | ||
*/ | ||
addStorage: function addStorage20() { | ||
addStorage() { | ||
return { | ||
@@ -961,3 +740,3 @@ markdown: { | ||
}); | ||
var Strike = Mark.create({ | ||
const Strike = Mark.create({ | ||
name: "strike" | ||
@@ -969,3 +748,3 @@ }); | ||
*/ | ||
addStorage: function addStorage21() { | ||
addStorage() { | ||
return { | ||
@@ -988,84 +767,79 @@ markdown: { | ||
var _extension$storage, _markdownExtensions$f; | ||
var markdownSpec = (_extension$storage = extension.storage) === null || _extension$storage === void 0 ? void 0 : _extension$storage.markdown; | ||
var defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find(function(e) { | ||
return e.name === extension.name; | ||
})) === null || _markdownExtensions$f === void 0 ? void 0 : _markdownExtensions$f.storage.markdown; | ||
const markdownSpec = (_extension$storage = extension.storage) === null || _extension$storage === void 0 ? void 0 : _extension$storage.markdown; | ||
const defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find((e) => e.name === extension.name)) === null || _markdownExtensions$f === void 0 ? void 0 : _markdownExtensions$f.storage.markdown; | ||
if (markdownSpec || defaultMarkdownSpec) { | ||
return _objectSpread2(_objectSpread2({}, defaultMarkdownSpec), markdownSpec); | ||
return { | ||
...defaultMarkdownSpec, | ||
...markdownSpec | ||
}; | ||
} | ||
return null; | ||
} | ||
var MarkdownSerializer = /* @__PURE__ */ function() { | ||
function MarkdownSerializer2(editor) { | ||
_classCallCheck(this, MarkdownSerializer2); | ||
_defineProperty(this, "editor", null); | ||
class MarkdownSerializer { | ||
constructor(editor) { | ||
/** | ||
* @type {import('@tiptap/core').Editor} | ||
*/ | ||
__publicField(this, "editor", null); | ||
this.editor = editor; | ||
} | ||
_createClass(MarkdownSerializer2, [{ | ||
key: "serialize", | ||
value: function serialize(content) { | ||
var state = new MarkdownSerializerState(this.nodes, this.marks, { | ||
hardBreakNodeName: HardBreak$1.name | ||
}); | ||
state.renderContent(content); | ||
return state.out; | ||
} | ||
}, { | ||
key: "nodes", | ||
get: function get() { | ||
var _this = this, _this$editor$extensio; | ||
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.nodes).map(function(name) { | ||
return [name, _this.serializeNode(HTMLNode)]; | ||
}))), Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter(function(extension) { | ||
return extension.type === "node" && _this.serializeNode(extension); | ||
}).map(function(extension) { | ||
return [extension.name, _this.serializeNode(extension)]; | ||
})) !== null && _this$editor$extensio !== void 0 ? _this$editor$extensio : [])); | ||
} | ||
}, { | ||
key: "marks", | ||
get: function get() { | ||
var _this2 = this, _this$editor$extensio2; | ||
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.marks).map(function(name) { | ||
return [name, _this2.serializeMark(HTMLMark)]; | ||
}))), Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter(function(extension) { | ||
return extension.type === "mark" && _this2.serializeMark(extension); | ||
}).map(function(extension) { | ||
return [extension.name, _this2.serializeMark(extension)]; | ||
})) !== null && _this$editor$extensio2 !== void 0 ? _this$editor$extensio2 : [])); | ||
} | ||
}, { | ||
key: "serializeNode", | ||
value: function serializeNode(node) { | ||
var _getMarkdownSpec, _getMarkdownSpec$seri; | ||
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$seri = _getMarkdownSpec.serialize) === null || _getMarkdownSpec$seri === void 0 ? void 0 : _getMarkdownSpec$seri.bind({ | ||
serialize(content) { | ||
const state = new MarkdownSerializerState(this.nodes, this.marks, { | ||
hardBreakNodeName: HardBreak$1.name | ||
}); | ||
state.renderContent(content); | ||
return state.out; | ||
} | ||
get nodes() { | ||
var _this$editor$extensio; | ||
return { | ||
...Object.fromEntries(Object.keys(this.editor.schema.nodes).map((name) => [name, this.serializeNode(HTMLNode)])), | ||
...Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter((extension) => extension.type === "node" && this.serializeNode(extension)).map((extension) => [extension.name, this.serializeNode(extension)])) !== null && _this$editor$extensio !== void 0 ? _this$editor$extensio : []) | ||
}; | ||
} | ||
get marks() { | ||
var _this$editor$extensio2; | ||
return { | ||
...Object.fromEntries(Object.keys(this.editor.schema.marks).map((name) => [name, this.serializeMark(HTMLMark)])), | ||
...Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter((extension) => extension.type === "mark" && this.serializeMark(extension)).map((extension) => [extension.name, this.serializeMark(extension)])) !== null && _this$editor$extensio2 !== void 0 ? _this$editor$extensio2 : []) | ||
}; | ||
} | ||
serializeNode(node) { | ||
var _getMarkdownSpec, _getMarkdownSpec$seri; | ||
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$seri = _getMarkdownSpec.serialize) === null || _getMarkdownSpec$seri === void 0 ? void 0 : _getMarkdownSpec$seri.bind({ | ||
editor: this.editor, | ||
options: node.options | ||
}); | ||
} | ||
serializeMark(mark) { | ||
var _getMarkdownSpec2; | ||
const serialize = (_getMarkdownSpec2 = getMarkdownSpec(mark)) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.serialize; | ||
return serialize ? { | ||
...serialize, | ||
open: typeof serialize.open === "function" ? serialize.open.bind({ | ||
editor: this.editor, | ||
options: node.options | ||
}); | ||
} | ||
}, { | ||
key: "serializeMark", | ||
value: function serializeMark(mark) { | ||
var _getMarkdownSpec2; | ||
var serialize = (_getMarkdownSpec2 = getMarkdownSpec(mark)) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.serialize; | ||
return serialize ? _objectSpread2(_objectSpread2({}, serialize), {}, { | ||
open: typeof serialize.open === "function" ? serialize.open.bind({ | ||
editor: this.editor, | ||
options: mark.options | ||
}) : serialize.open, | ||
close: typeof serialize.close === "function" ? serialize.close.bind({ | ||
editor: this.editor, | ||
options: mark.options | ||
}) : serialize.close | ||
}) : null; | ||
} | ||
}]); | ||
return MarkdownSerializer2; | ||
}(); | ||
var MarkdownParser = /* @__PURE__ */ function() { | ||
function MarkdownParser2(editor, _ref) { | ||
var html = _ref.html, linkify = _ref.linkify, breaks = _ref.breaks; | ||
_classCallCheck(this, MarkdownParser2); | ||
_defineProperty(this, "editor", null); | ||
_defineProperty(this, "md", null); | ||
options: mark.options | ||
}) : serialize.open, | ||
close: typeof serialize.close === "function" ? serialize.close.bind({ | ||
editor: this.editor, | ||
options: mark.options | ||
}) : serialize.close | ||
} : null; | ||
} | ||
} | ||
class MarkdownParser { | ||
constructor(editor, _ref) { | ||
/** | ||
* @type {import('@tiptap/core').Editor} | ||
*/ | ||
__publicField(this, "editor", null); | ||
/** | ||
* @type {markdownit} | ||
*/ | ||
__publicField(this, "md", null); | ||
let { | ||
html, | ||
linkify, | ||
breaks | ||
} = _ref; | ||
this.editor = editor; | ||
@@ -1078,95 +852,87 @@ this.md = markdownit({ | ||
} | ||
_createClass(MarkdownParser2, [{ | ||
key: "parse", | ||
value: function parse(content) { | ||
var _this = this; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, inline = _ref2.inline; | ||
if (typeof content === "string") { | ||
var renderer = this.md; | ||
this.editor.extensionManager.extensions.forEach(function(extension) { | ||
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2; | ||
return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$pars = _getMarkdownSpec.parse) === null || _getMarkdownSpec$pars === void 0 ? void 0 : (_getMarkdownSpec$pars2 = _getMarkdownSpec$pars.setup) === null || _getMarkdownSpec$pars2 === void 0 ? void 0 : _getMarkdownSpec$pars2.call({ | ||
editor: _this.editor, | ||
options: extension.options | ||
}, renderer); | ||
}); | ||
var renderedHTML = renderer.render(content); | ||
var element = elementFromString(renderedHTML); | ||
this.editor.extensionManager.extensions.forEach(function(extension) { | ||
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2; | ||
return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 ? void 0 : (_getMarkdownSpec2$par = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2$par === void 0 ? void 0 : (_getMarkdownSpec2$par2 = _getMarkdownSpec2$par.updateDOM) === null || _getMarkdownSpec2$par2 === void 0 ? void 0 : _getMarkdownSpec2$par2.call({ | ||
editor: _this.editor, | ||
options: extension.options | ||
}, element); | ||
}); | ||
this.normalizeDOM(element, { | ||
inline, | ||
content | ||
}); | ||
return element.innerHTML; | ||
parse(content) { | ||
let { | ||
inline | ||
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; | ||
if (typeof content === "string") { | ||
const renderer = this.md; | ||
this.editor.extensionManager.extensions.forEach((extension) => { | ||
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2; | ||
return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$pars = _getMarkdownSpec.parse) === null || _getMarkdownSpec$pars === void 0 ? void 0 : (_getMarkdownSpec$pars2 = _getMarkdownSpec$pars.setup) === null || _getMarkdownSpec$pars2 === void 0 ? void 0 : _getMarkdownSpec$pars2.call({ | ||
editor: this.editor, | ||
options: extension.options | ||
}, renderer); | ||
}); | ||
const renderedHTML = renderer.render(content); | ||
const element = elementFromString(renderedHTML); | ||
this.editor.extensionManager.extensions.forEach((extension) => { | ||
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2; | ||
return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 ? void 0 : (_getMarkdownSpec2$par = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2$par === void 0 ? void 0 : (_getMarkdownSpec2$par2 = _getMarkdownSpec2$par.updateDOM) === null || _getMarkdownSpec2$par2 === void 0 ? void 0 : _getMarkdownSpec2$par2.call({ | ||
editor: this.editor, | ||
options: extension.options | ||
}, element); | ||
}); | ||
this.normalizeDOM(element, { | ||
inline, | ||
content | ||
}); | ||
return element.innerHTML; | ||
} | ||
return content; | ||
} | ||
normalizeDOM(node, _ref2) { | ||
let { | ||
inline, | ||
content | ||
} = _ref2; | ||
this.normalizeBlocks(node); | ||
node.querySelectorAll("*").forEach((el) => { | ||
var _el$nextSibling; | ||
if (((_el$nextSibling = el.nextSibling) === null || _el$nextSibling === void 0 ? void 0 : _el$nextSibling.nodeType) === Node.TEXT_NODE && !el.closest("pre")) { | ||
el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, ""); | ||
} | ||
return content; | ||
}); | ||
if (inline) { | ||
this.normalizeInline(node, content); | ||
} | ||
}, { | ||
key: "normalizeDOM", | ||
value: function normalizeDOM(node, _ref3) { | ||
var inline = _ref3.inline, content = _ref3.content; | ||
this.normalizeBlocks(node); | ||
node.querySelectorAll("*").forEach(function(el) { | ||
var _el$nextSibling; | ||
if (((_el$nextSibling = el.nextSibling) === null || _el$nextSibling === void 0 ? void 0 : _el$nextSibling.nodeType) === Node.TEXT_NODE && !el.closest("pre")) { | ||
el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, ""); | ||
} | ||
}); | ||
if (inline) { | ||
this.normalizeInline(node, content); | ||
return node; | ||
} | ||
normalizeBlocks(node) { | ||
const blocks = Object.values(this.editor.schema.nodes).filter((node2) => node2.isBlock); | ||
const selector = blocks.map((block) => { | ||
var _block$spec$parseDOM; | ||
return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map((spec) => spec.tag); | ||
}).flat().filter(Boolean).join(","); | ||
if (!selector) { | ||
return; | ||
} | ||
[...node.querySelectorAll(selector)].forEach((el) => { | ||
if (el.parentElement.matches("p")) { | ||
extractElement(el); | ||
} | ||
return node; | ||
} | ||
}, { | ||
key: "normalizeBlocks", | ||
value: function normalizeBlocks(node) { | ||
var blocks = Object.values(this.editor.schema.nodes).filter(function(node2) { | ||
return node2.isBlock; | ||
}); | ||
var selector = blocks.map(function(block) { | ||
var _block$spec$parseDOM; | ||
return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map(function(spec) { | ||
return spec.tag; | ||
}); | ||
}).flat().filter(Boolean).join(","); | ||
if (!selector) { | ||
}); | ||
} | ||
normalizeInline(node, content) { | ||
var _node$firstElementChi; | ||
if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches("p")) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
const firstParagraph = node.firstElementChild; | ||
const { | ||
nextSibling, | ||
nextElementSibling | ||
} = firstParagraph; | ||
const startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : ""; | ||
const endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : "" : ""; | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = `${firstParagraph.innerHTML}${endSpaces}`; | ||
return; | ||
} | ||
_toConsumableArray(node.querySelectorAll(selector)).forEach(function(el) { | ||
if (el.parentElement.matches("p")) { | ||
extractElement(el); | ||
} | ||
}); | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = `${startSpaces}${node.innerHTML}${endSpaces}`; | ||
} | ||
}, { | ||
key: "normalizeInline", | ||
value: function normalizeInline(node, content) { | ||
var _node$firstElementChi; | ||
if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches("p")) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
var firstParagraph = node.firstElementChild; | ||
firstParagraph.nextSibling; | ||
var nextElementSibling = firstParagraph.nextElementSibling; | ||
var startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : ""; | ||
var endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : "" : ""; | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = "".concat(firstParagraph.innerHTML).concat(endSpaces); | ||
return; | ||
} | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = "".concat(startSpaces).concat(node.innerHTML).concat(endSpaces); | ||
} | ||
} | ||
}]); | ||
return MarkdownParser2; | ||
}(); | ||
var MarkdownClipboard = Extension.create({ | ||
} | ||
} | ||
const MarkdownClipboard = Extension.create({ | ||
name: "markdownClipboard", | ||
addOptions: function addOptions2() { | ||
addOptions() { | ||
return { | ||
@@ -1177,15 +943,14 @@ transformPastedText: false, | ||
}, | ||
addProseMirrorPlugins: function addProseMirrorPlugins() { | ||
var _this = this; | ||
addProseMirrorPlugins() { | ||
return [new Plugin({ | ||
key: new PluginKey("markdownClipboard"), | ||
props: { | ||
clipboardTextParser: function clipboardTextParser(text, context, plainText) { | ||
if (plainText || !_this.options.transformPastedText) { | ||
clipboardTextParser: (text, context, plainText) => { | ||
if (plainText || !this.options.transformPastedText) { | ||
return null; | ||
} | ||
var parsed = _this.editor.storage.markdown.parser.parse(text, { | ||
const parsed = this.editor.storage.markdown.parser.parse(text, { | ||
inline: true | ||
}); | ||
return DOMParser.fromSchema(_this.editor.schema).parseSlice(elementFromString(parsed), { | ||
return DOMParser.fromSchema(this.editor.schema).parseSlice(elementFromString(parsed), { | ||
preserveWhitespace: true, | ||
@@ -1198,7 +963,7 @@ context | ||
*/ | ||
clipboardTextSerializer: function clipboardTextSerializer(slice) { | ||
if (!_this.options.transformCopiedText) { | ||
clipboardTextSerializer: (slice) => { | ||
if (!this.options.transformCopiedText) { | ||
return null; | ||
} | ||
return _this.editor.storage.markdown.serializer.serialize(slice.content); | ||
return this.editor.storage.markdown.serializer.serialize(slice.content); | ||
} | ||
@@ -1209,6 +974,6 @@ } | ||
}); | ||
var Markdown = Extension.create({ | ||
const Markdown = Extension.create({ | ||
name: "markdown", | ||
priority: 50, | ||
addOptions: function addOptions3() { | ||
addOptions() { | ||
return { | ||
@@ -1225,27 +990,24 @@ html: true, | ||
}, | ||
addCommands: function addCommands2() { | ||
var commands = extensions.Commands.config.addCommands(); | ||
addCommands() { | ||
const commands = extensions.Commands.config.addCommands(); | ||
return { | ||
setContent: function setContent(content, emitUpdate, parseOptions) { | ||
return function(props) { | ||
return commands.setContent(props.editor.storage.markdown.parser.parse(content), emitUpdate, parseOptions)(props); | ||
}; | ||
setContent: (content, emitUpdate, parseOptions) => (props) => { | ||
return commands.setContent(props.editor.storage.markdown.parser.parse(content), emitUpdate, parseOptions)(props); | ||
}, | ||
insertContentAt: function insertContentAt(range, content, options) { | ||
return function(props) { | ||
return commands.insertContentAt(range, props.editor.storage.markdown.parser.parse(content, { | ||
inline: true | ||
}), options)(props); | ||
}; | ||
insertContentAt: (range, content, options) => (props) => { | ||
return commands.insertContentAt(range, props.editor.storage.markdown.parser.parse(content, { | ||
inline: true | ||
}), options)(props); | ||
} | ||
}; | ||
}, | ||
onBeforeCreate: function onBeforeCreate() { | ||
var _this = this; | ||
onBeforeCreate() { | ||
this.editor.storage.markdown = { | ||
options: _objectSpread2({}, this.options), | ||
options: { | ||
...this.options | ||
}, | ||
parser: new MarkdownParser(this.editor, this.options), | ||
serializer: new MarkdownSerializer(this.editor), | ||
getMarkdown: function getMarkdown() { | ||
return _this.editor.storage.markdown.serializer.serialize(_this.editor.state.doc); | ||
getMarkdown: () => { | ||
return this.editor.storage.markdown.serializer.serialize(this.editor.state.doc); | ||
} | ||
@@ -1256,7 +1018,7 @@ }; | ||
}, | ||
onCreate: function onCreate() { | ||
onCreate() { | ||
this.editor.options.content = this.editor.options.initialContent; | ||
delete this.editor.options.initialContent; | ||
}, | ||
addStorage: function addStorage22() { | ||
addStorage() { | ||
return { | ||
@@ -1266,3 +1028,3 @@ /// storage will be defined in onBeforeCreate() to prevent initial object overriding | ||
}, | ||
addExtensions: function addExtensions() { | ||
addExtensions() { | ||
return [MarkdownTightLists.configure({ | ||
@@ -1269,0 +1031,0 @@ tight: this.options.tightLists, |
(function(global, factory) { | ||
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@tiptap/core"), require("prosemirror-markdown"), require("markdown-it"), require("@tiptap/pm/model"), require("markdown-it-task-lists"), require("@tiptap/pm/state")) : typeof define === "function" && define.amd ? define(["exports", "@tiptap/core", "prosemirror-markdown", "markdown-it", "@tiptap/pm/model", "markdown-it-task-lists", "@tiptap/pm/state"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["tiptap-markdown"] = {}, global.core, global.prosemirrorMarkdown, global.markdownit, global.model, global.taskListPlugin, global.state)); | ||
})(this, function(exports2, core, prosemirrorMarkdown, markdownit, model, taskListPlugin, state) { | ||
"use strict"; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), true).forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) | ||
descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) | ||
_defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) | ||
_defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) { | ||
return o2.__proto__ || Object.getPrototypeOf(o2); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) { | ||
o2.__proto__ = p2; | ||
return o2; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) | ||
return false; | ||
if (Reflect.construct.sham) | ||
return false; | ||
if (typeof Proxy === "function") | ||
return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { | ||
})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self2) { | ||
if (self2 === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self2; | ||
} | ||
function _possibleConstructorReturn(self2, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self2); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
object = _getPrototypeOf(object); | ||
if (object === null) | ||
break; | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
} else { | ||
_get = function _get2(target, property, receiver) { | ||
var base = _superPropBase(target, property); | ||
if (!base) | ||
return; | ||
var desc = Object.getOwnPropertyDescriptor(base, property); | ||
if (desc.get) { | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) | ||
return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) | ||
return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) | ||
return; | ||
if (typeof o === "string") | ||
return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) | ||
n = o.constructor.name; | ||
if (n === "Map" || n === "Set") | ||
return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) | ||
return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) | ||
len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) | ||
arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) | ||
return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== void 0) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") | ||
return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
var MarkdownTightLists = core.Extension.create({ | ||
"use strict";var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
const MarkdownTightLists = core.Extension.create({ | ||
name: "markdownTightLists", | ||
addOptions: function addOptions() { | ||
return { | ||
tight: true, | ||
tightClass: "tight", | ||
listTypes: ["bulletList", "orderedList"] | ||
}; | ||
}, | ||
addGlobalAttributes: function addGlobalAttributes() { | ||
var _this = this; | ||
addOptions: () => ({ | ||
tight: true, | ||
tightClass: "tight", | ||
listTypes: ["bulletList", "orderedList"] | ||
}), | ||
addGlobalAttributes() { | ||
return [{ | ||
@@ -227,12 +23,8 @@ types: this.options.listTypes, | ||
tight: { | ||
"default": this.options.tight, | ||
parseHTML: function parseHTML(element) { | ||
return element.getAttribute("data-tight") === "true" || !element.querySelector("p"); | ||
}, | ||
renderHTML: function renderHTML(attributes) { | ||
return { | ||
"class": attributes.tight ? _this.options.tightClass : null, | ||
"data-tight": attributes.tight ? "true" : null | ||
}; | ||
} | ||
default: this.options.tight, | ||
parseHTML: (element) => element.getAttribute("data-tight") === "true" || !element.querySelector("p"), | ||
renderHTML: (attributes) => ({ | ||
class: attributes.tight ? this.options.tightClass : null, | ||
"data-tight": attributes.tight ? "true" : null | ||
}) | ||
} | ||
@@ -242,14 +34,17 @@ } | ||
}, | ||
addCommands: function addCommands() { | ||
var _this2 = this; | ||
addCommands() { | ||
var _this = this; | ||
return { | ||
toggleTight: function toggleTight() { | ||
var tight = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null; | ||
return function(_ref) { | ||
var editor = _ref.editor, commands = _ref.commands; | ||
function toggleTight2(name) { | ||
toggleTight: function() { | ||
let tight = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null; | ||
return (_ref) => { | ||
let { | ||
editor, | ||
commands | ||
} = _ref; | ||
function toggleTight(name) { | ||
if (!editor.isActive(name)) { | ||
return false; | ||
} | ||
var attrs = editor.getAttributes(name); | ||
const attrs = editor.getAttributes(name); | ||
return commands.updateAttributes(name, { | ||
@@ -259,5 +54,3 @@ tight: tight !== null && tight !== void 0 ? tight : !(attrs !== null && attrs !== void 0 && attrs.tight) | ||
} | ||
return _this2.options.listTypes.some(function(name) { | ||
return toggleTight2(name); | ||
}); | ||
return _this.options.listTypes.some((name) => toggleTight(name)); | ||
}; | ||
@@ -268,3 +61,3 @@ } | ||
}); | ||
var md = markdownit(); | ||
const md = markdownit(); | ||
function scanDelims(text, pos) { | ||
@@ -275,7 +68,7 @@ md.inline.State.prototype.scanDelims.call({ | ||
}); | ||
var state2 = new md.inline.State(text, null, null, []); | ||
const state2 = new md.inline.State(text, null, null, []); | ||
return state2.scanDelims(pos, true); | ||
} | ||
function shiftDelim(text, delim, start, offset) { | ||
var res = text.substring(0, start) + text.substring(start + delim.length); | ||
let res = text.substring(0, start) + text.substring(start + delim.length); | ||
res = res.substring(0, start + offset) + delim + res.substring(start + offset); | ||
@@ -285,3 +78,3 @@ return res; | ||
function trimStart(text, delim, from, to) { | ||
var pos = from, res = text; | ||
let pos = from, res = text; | ||
while (pos < to) { | ||
@@ -301,3 +94,3 @@ if (scanDelims(res, pos).can_open) { | ||
function trimEnd(text, delim, from, to) { | ||
var pos = to, res = text; | ||
let pos = to, res = text; | ||
while (pos > from) { | ||
@@ -317,3 +110,3 @@ if (scanDelims(res, pos).can_close) { | ||
function trimInline(text, delim, from, to) { | ||
var state2 = { | ||
let state2 = { | ||
text, | ||
@@ -330,57 +123,52 @@ from, | ||
} | ||
var MarkdownSerializerState = /* @__PURE__ */ function(_BaseMarkdownSerializ) { | ||
_inherits(MarkdownSerializerState2, _BaseMarkdownSerializ); | ||
var _super = _createSuper(MarkdownSerializerState2); | ||
function MarkdownSerializerState2(nodes, marks, options) { | ||
var _this; | ||
_classCallCheck(this, MarkdownSerializerState2); | ||
_this = _super.call(this, nodes, marks, options !== null && options !== void 0 ? options : {}); | ||
_this.inlines = []; | ||
return _this; | ||
class MarkdownSerializerState extends prosemirrorMarkdown.MarkdownSerializerState { | ||
constructor(nodes, marks, options) { | ||
super(nodes, marks, options !== null && options !== void 0 ? options : {}); | ||
this.inlines = []; | ||
} | ||
_createClass(MarkdownSerializerState2, [{ | ||
key: "render", | ||
value: function render(node, parent, index) { | ||
_get(_getPrototypeOf(MarkdownSerializerState2.prototype), "render", this).call(this, node, parent, index); | ||
var top = this.inlines[this.inlines.length - 1]; | ||
if (top !== null && top !== void 0 && top.start && top !== null && top !== void 0 && top.end) { | ||
var _this$normalizeInline = this.normalizeInline(top), delimiter = _this$normalizeInline.delimiter, start = _this$normalizeInline.start, end = _this$normalizeInline.end; | ||
this.out = trimInline(this.out, delimiter, start, end); | ||
this.inlines.pop(); | ||
} | ||
render(node, parent, index) { | ||
super.render(node, parent, index); | ||
const top = this.inlines[this.inlines.length - 1]; | ||
if (top !== null && top !== void 0 && top.start && top !== null && top !== void 0 && top.end) { | ||
const { | ||
delimiter, | ||
start, | ||
end | ||
} = this.normalizeInline(top); | ||
this.out = trimInline(this.out, delimiter, start, end); | ||
this.inlines.pop(); | ||
} | ||
}, { | ||
key: "markString", | ||
value: function markString(mark, open, parent, index) { | ||
var info = this.marks[mark.type.name]; | ||
if (info.expelEnclosingWhitespace) { | ||
if (open) { | ||
this.inlines.push({ | ||
start: this.out.length, | ||
delimiter: info.open | ||
}); | ||
} else { | ||
var top = this.inlines.pop(); | ||
this.inlines.push(_objectSpread2(_objectSpread2({}, top), {}, { | ||
end: this.out.length | ||
})); | ||
} | ||
} | ||
markString(mark, open, parent, index) { | ||
const info = this.marks[mark.type.name]; | ||
if (info.expelEnclosingWhitespace) { | ||
if (open) { | ||
this.inlines.push({ | ||
start: this.out.length, | ||
delimiter: info.open | ||
}); | ||
} else { | ||
const top = this.inlines.pop(); | ||
this.inlines.push({ | ||
...top, | ||
end: this.out.length | ||
}); | ||
} | ||
return _get(_getPrototypeOf(MarkdownSerializerState2.prototype), "markString", this).call(this, mark, open, parent, index); | ||
} | ||
}, { | ||
key: "normalizeInline", | ||
value: function normalizeInline(inline) { | ||
var start = inline.start; | ||
inline.end; | ||
while (this.out.charAt(start).match(/\s/)) { | ||
start++; | ||
} | ||
return _objectSpread2(_objectSpread2({}, inline), {}, { | ||
start | ||
}); | ||
return super.markString(mark, open, parent, index); | ||
} | ||
normalizeInline(inline) { | ||
let { | ||
start, | ||
end | ||
} = inline; | ||
while (this.out.charAt(start).match(/\s/)) { | ||
start++; | ||
} | ||
}]); | ||
return MarkdownSerializerState2; | ||
}(prosemirrorMarkdown.MarkdownSerializerState); | ||
return { | ||
...inline, | ||
start | ||
}; | ||
} | ||
} | ||
const HTMLMark = core.Mark.create({ | ||
@@ -391,10 +179,10 @@ name: "markdownHTMLMark", | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: { | ||
open: function open(state2, mark) { | ||
open(state2, mark) { | ||
var _getMarkTags$, _getMarkTags; | ||
if (!this.editor.storage.markdown.options.html) { | ||
console.warn('Tiptap Markdown: "'.concat(mark.type.name, '" mark is only available in html mode')); | ||
console.warn(`Tiptap Markdown: "${mark.type.name}" mark is only available in html mode`); | ||
return ""; | ||
@@ -404,3 +192,3 @@ } | ||
}, | ||
close: function close(state2, mark) { | ||
close(state2, mark) { | ||
var _getMarkTags$2, _getMarkTags2; | ||
@@ -421,10 +209,10 @@ if (!this.editor.storage.markdown.options.html) { | ||
function getMarkTags(mark) { | ||
var schema = mark.type.schema; | ||
var node = schema.text(" ", [mark]); | ||
var html = core.getHTMLFromFragment(model.Fragment.from(node), schema); | ||
var match = html.match(/^(<.*?>) (<\/.*?>)$/); | ||
const schema = mark.type.schema; | ||
const node = schema.text(" ", [mark]); | ||
const html = core.getHTMLFromFragment(model.Fragment.from(node), schema); | ||
const match = html.match(/^(<.*?>) (<\/.*?>)$/); | ||
return match ? [match[1], match[2]] : null; | ||
} | ||
function elementFromString(value) { | ||
var wrappedValue = "<body>".concat(value, "</body>"); | ||
const wrappedValue = `<body>${value}</body>`; | ||
return new window.DOMParser().parseFromString(wrappedValue, "text/html").body; | ||
@@ -436,4 +224,4 @@ } | ||
function extractElement(node) { | ||
var parent = node.parentElement; | ||
var prepend = parent.cloneNode(); | ||
const parent = node.parentElement; | ||
const prepend = parent.cloneNode(); | ||
while (parent.firstChild && parent.firstChild !== node) { | ||
@@ -451,6 +239,5 @@ prepend.appendChild(parent.firstChild); | ||
function unwrapElement(node) { | ||
var parent = node.parentNode; | ||
while (node.firstChild) { | ||
const parent = node.parentNode; | ||
while (node.firstChild) | ||
parent.insertBefore(node.firstChild, node); | ||
} | ||
parent.removeChild(node); | ||
@@ -460,11 +247,11 @@ } | ||
name: "markdownHTMLNode", | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state2, node, parent) { | ||
serialize(state2, node, parent) { | ||
if (this.editor.storage.markdown.options.html) { | ||
state2.write(serializeHTML(node, parent)); | ||
} else { | ||
console.warn('Tiptap Markdown: "'.concat(node.type.name, '" node is only available in html mode')); | ||
state2.write("[".concat(node.type.name, "]")); | ||
console.warn(`Tiptap Markdown: "${node.type.name}" node is only available in html mode`); | ||
state2.write(`[${node.type.name}]`); | ||
} | ||
@@ -483,4 +270,4 @@ if (node.isBlock) { | ||
function serializeHTML(node, parent) { | ||
var schema = node.type.schema; | ||
var html = core.getHTMLFromFragment(model.Fragment.from(node), schema); | ||
const schema = node.type.schema; | ||
const html = core.getHTMLFromFragment(model.Fragment.from(node), schema); | ||
if (node.isBlock && (parent instanceof model.Fragment || parent.type.name === schema.topNodeType.name)) { | ||
@@ -492,8 +279,11 @@ return formatBlock(html); | ||
function formatBlock(html) { | ||
var dom = elementFromString(html); | ||
var element = dom.firstElementChild; | ||
element.innerHTML = element.innerHTML.trim() ? "\n".concat(element.innerHTML, "\n") : "\n"; | ||
const dom = elementFromString(html); | ||
const element = dom.firstElementChild; | ||
element.innerHTML = element.innerHTML.trim() ? ` | ||
${element.innerHTML} | ||
` : ` | ||
`; | ||
return element.outerHTML; | ||
} | ||
var Blockquote = core.Node.create({ | ||
const Blockquote = core.Node.create({ | ||
name: "blockquote" | ||
@@ -505,3 +295,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -517,3 +307,3 @@ markdown: { | ||
}); | ||
var BulletList = core.Node.create({ | ||
const BulletList = core.Node.create({ | ||
name: "bulletList" | ||
@@ -525,10 +315,7 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state2, node) { | ||
var _this = this; | ||
return state2.renderList(node, " ", function() { | ||
return (_this.editor.storage.markdown.options.bulletListMarker || "-") + " "; | ||
}); | ||
serialize(state2, node) { | ||
return state2.renderList(node, " ", () => (this.editor.storage.markdown.options.bulletListMarker || "-") + " "); | ||
}, | ||
@@ -542,3 +329,3 @@ parse: { | ||
}); | ||
var CodeBlock = core.Node.create({ | ||
const CodeBlock = core.Node.create({ | ||
name: "codeBlock" | ||
@@ -550,6 +337,6 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state2, node) { | ||
serialize(state2, node) { | ||
state2.write("```" + (node.attrs.language || "") + "\n"); | ||
@@ -562,3 +349,3 @@ state2.text(node.textContent, false); | ||
parse: { | ||
setup: function setup(markdownit2) { | ||
setup(markdownit2) { | ||
var _this$options$languag; | ||
@@ -569,3 +356,3 @@ markdownit2.set({ | ||
}, | ||
updateDOM: function updateDOM(element) { | ||
updateDOM(element) { | ||
element.innerHTML = element.innerHTML.replace(/\n<\/code><\/pre>/g, "</code></pre>"); | ||
@@ -578,3 +365,3 @@ } | ||
}); | ||
var HardBreak = core.Node.create({ | ||
const HardBreak = core.Node.create({ | ||
name: "hardBreak" | ||
@@ -586,3 +373,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -598,3 +385,3 @@ markdown: { | ||
}); | ||
var Heading = core.Node.create({ | ||
const Heading = core.Node.create({ | ||
name: "heading" | ||
@@ -606,3 +393,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -618,3 +405,3 @@ markdown: { | ||
}); | ||
var HorizontalRule = core.Node.create({ | ||
const HorizontalRule = core.Node.create({ | ||
name: "horizontalRule" | ||
@@ -626,3 +413,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -638,3 +425,3 @@ markdown: { | ||
}); | ||
var Image = core.Node.create({ | ||
const Image = core.Node.create({ | ||
name: "image" | ||
@@ -646,3 +433,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -658,3 +445,3 @@ markdown: { | ||
}); | ||
var ListItem = core.Node.create({ | ||
const ListItem = core.Node.create({ | ||
name: "listItem" | ||
@@ -666,3 +453,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -678,3 +465,3 @@ markdown: { | ||
}); | ||
var OrderedList = core.Node.create({ | ||
const OrderedList = core.Node.create({ | ||
name: "orderedList" | ||
@@ -686,3 +473,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -698,3 +485,3 @@ markdown: { | ||
}); | ||
var Paragraph = core.Node.create({ | ||
const Paragraph = core.Node.create({ | ||
name: "paragraph" | ||
@@ -706,3 +493,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -722,3 +509,3 @@ markdown: { | ||
} | ||
var Table = core.Node.create({ | ||
const Table = core.Node.create({ | ||
name: "table" | ||
@@ -730,6 +517,6 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state2, node, parent) { | ||
serialize(state2, node, parent) { | ||
if (!isMarkdownSerializable(node)) { | ||
@@ -739,9 +526,9 @@ HTMLNode.storage.markdown.serialize.call(this, state2, node, parent); | ||
} | ||
node.forEach(function(row, p, i) { | ||
node.forEach((row, p, i) => { | ||
state2.write("| "); | ||
row.forEach(function(col, p2, j) { | ||
row.forEach((col, p2, j) => { | ||
if (j) { | ||
state2.write(" | "); | ||
} | ||
var cellContent = col.firstChild; | ||
const cellContent = col.firstChild; | ||
if (cellContent.textContent.trim()) { | ||
@@ -754,8 +541,6 @@ state2.renderInline(cellContent); | ||
if (!i) { | ||
var delimiterRow = Array.from({ | ||
const delimiterRow = Array.from({ | ||
length: row.childCount | ||
}).map(function() { | ||
return "---"; | ||
}).join(" | "); | ||
state2.write("| ".concat(delimiterRow, " |")); | ||
}).map(() => "---").join(" | "); | ||
state2.write(`| ${delimiterRow} |`); | ||
state2.ensureNewLine(); | ||
@@ -777,15 +562,9 @@ } | ||
function isMarkdownSerializable(node) { | ||
var rows = childNodes(node); | ||
var firstRow = rows[0]; | ||
var bodyRows = rows.slice(1); | ||
if (childNodes(firstRow).some(function(cell) { | ||
return cell.type.name !== "tableHeader" || hasSpan(cell) || cell.childCount > 1; | ||
})) { | ||
const rows = childNodes(node); | ||
const firstRow = rows[0]; | ||
const bodyRows = rows.slice(1); | ||
if (childNodes(firstRow).some((cell) => cell.type.name !== "tableHeader" || hasSpan(cell) || cell.childCount > 1)) { | ||
return false; | ||
} | ||
if (bodyRows.some(function(row) { | ||
return childNodes(row).some(function(cell) { | ||
return cell.type.name === "tableHeader" || hasSpan(cell) || cell.childCount > 1; | ||
}); | ||
})) { | ||
if (bodyRows.some((row) => childNodes(row).some((cell) => cell.type.name === "tableHeader" || hasSpan(cell) || cell.childCount > 1))) { | ||
return false; | ||
@@ -795,3 +574,3 @@ } | ||
} | ||
var TaskItem = core.Node.create({ | ||
const TaskItem = core.Node.create({ | ||
name: "taskItem" | ||
@@ -803,14 +582,14 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state2, node) { | ||
var check = node.attrs.checked ? "[x]" : "[ ]"; | ||
state2.write("".concat(check, " ")); | ||
serialize(state2, node) { | ||
const check = node.attrs.checked ? "[x]" : "[ ]"; | ||
state2.write(`${check} `); | ||
state2.renderContent(node); | ||
}, | ||
parse: { | ||
updateDOM: function updateDOM(element) { | ||
_toConsumableArray(element.querySelectorAll(".task-list-item")).forEach(function(item) { | ||
var input = item.querySelector("input"); | ||
updateDOM(element) { | ||
[...element.querySelectorAll(".task-list-item")].forEach((item) => { | ||
const input = item.querySelector("input"); | ||
item.setAttribute("data-type", "taskItem"); | ||
@@ -828,3 +607,3 @@ if (input) { | ||
}); | ||
var TaskList = core.Node.create({ | ||
const TaskList = core.Node.create({ | ||
name: "taskList" | ||
@@ -836,3 +615,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -842,7 +621,7 @@ markdown: { | ||
parse: { | ||
setup: function setup(markdownit2) { | ||
setup(markdownit2) { | ||
markdownit2.use(taskListPlugin); | ||
}, | ||
updateDOM: function updateDOM(element) { | ||
_toConsumableArray(element.querySelectorAll(".contains-task-list")).forEach(function(list) { | ||
updateDOM(element) { | ||
[...element.querySelectorAll(".contains-task-list")].forEach((list) => { | ||
list.setAttribute("data-type", "taskList"); | ||
@@ -856,3 +635,3 @@ }); | ||
}); | ||
var Text = core.Node.create({ | ||
const Text = core.Node.create({ | ||
name: "text" | ||
@@ -864,6 +643,6 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
markdown: { | ||
serialize: function serialize(state2, node) { | ||
serialize(state2, node) { | ||
state2.text(escapeHTML(node.text)); | ||
@@ -878,3 +657,3 @@ }, | ||
}); | ||
var Bold = core.Mark.create({ | ||
const Bold = core.Mark.create({ | ||
name: "bold" | ||
@@ -886,3 +665,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -898,3 +677,3 @@ markdown: { | ||
}); | ||
var Code = core.Mark.create({ | ||
const Code = core.Mark.create({ | ||
name: "code" | ||
@@ -906,3 +685,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -918,3 +697,3 @@ markdown: { | ||
}); | ||
var Italic = core.Mark.create({ | ||
const Italic = core.Mark.create({ | ||
name: "italic" | ||
@@ -926,3 +705,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -938,3 +717,3 @@ markdown: { | ||
}); | ||
var Link = core.Mark.create({ | ||
const Link = core.Mark.create({ | ||
name: "link" | ||
@@ -946,3 +725,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -958,3 +737,3 @@ markdown: { | ||
}); | ||
var Strike = core.Mark.create({ | ||
const Strike = core.Mark.create({ | ||
name: "strike" | ||
@@ -966,3 +745,3 @@ }); | ||
*/ | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -985,84 +764,79 @@ markdown: { | ||
var _extension$storage, _markdownExtensions$f; | ||
var markdownSpec = (_extension$storage = extension.storage) === null || _extension$storage === void 0 ? void 0 : _extension$storage.markdown; | ||
var defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find(function(e) { | ||
return e.name === extension.name; | ||
})) === null || _markdownExtensions$f === void 0 ? void 0 : _markdownExtensions$f.storage.markdown; | ||
const markdownSpec = (_extension$storage = extension.storage) === null || _extension$storage === void 0 ? void 0 : _extension$storage.markdown; | ||
const defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find((e) => e.name === extension.name)) === null || _markdownExtensions$f === void 0 ? void 0 : _markdownExtensions$f.storage.markdown; | ||
if (markdownSpec || defaultMarkdownSpec) { | ||
return _objectSpread2(_objectSpread2({}, defaultMarkdownSpec), markdownSpec); | ||
return { | ||
...defaultMarkdownSpec, | ||
...markdownSpec | ||
}; | ||
} | ||
return null; | ||
} | ||
var MarkdownSerializer = /* @__PURE__ */ function() { | ||
function MarkdownSerializer2(editor) { | ||
_classCallCheck(this, MarkdownSerializer2); | ||
_defineProperty(this, "editor", null); | ||
class MarkdownSerializer { | ||
constructor(editor) { | ||
/** | ||
* @type {import('@tiptap/core').Editor} | ||
*/ | ||
__publicField(this, "editor", null); | ||
this.editor = editor; | ||
} | ||
_createClass(MarkdownSerializer2, [{ | ||
key: "serialize", | ||
value: function serialize(content) { | ||
var state2 = new MarkdownSerializerState(this.nodes, this.marks, { | ||
hardBreakNodeName: HardBreak$1.name | ||
}); | ||
state2.renderContent(content); | ||
return state2.out; | ||
} | ||
}, { | ||
key: "nodes", | ||
get: function get() { | ||
var _this = this, _this$editor$extensio; | ||
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.nodes).map(function(name) { | ||
return [name, _this.serializeNode(HTMLNode)]; | ||
}))), Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter(function(extension) { | ||
return extension.type === "node" && _this.serializeNode(extension); | ||
}).map(function(extension) { | ||
return [extension.name, _this.serializeNode(extension)]; | ||
})) !== null && _this$editor$extensio !== void 0 ? _this$editor$extensio : [])); | ||
} | ||
}, { | ||
key: "marks", | ||
get: function get() { | ||
var _this2 = this, _this$editor$extensio2; | ||
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.marks).map(function(name) { | ||
return [name, _this2.serializeMark(HTMLMark)]; | ||
}))), Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter(function(extension) { | ||
return extension.type === "mark" && _this2.serializeMark(extension); | ||
}).map(function(extension) { | ||
return [extension.name, _this2.serializeMark(extension)]; | ||
})) !== null && _this$editor$extensio2 !== void 0 ? _this$editor$extensio2 : [])); | ||
} | ||
}, { | ||
key: "serializeNode", | ||
value: function serializeNode(node) { | ||
var _getMarkdownSpec, _getMarkdownSpec$seri; | ||
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$seri = _getMarkdownSpec.serialize) === null || _getMarkdownSpec$seri === void 0 ? void 0 : _getMarkdownSpec$seri.bind({ | ||
serialize(content) { | ||
const state2 = new MarkdownSerializerState(this.nodes, this.marks, { | ||
hardBreakNodeName: HardBreak$1.name | ||
}); | ||
state2.renderContent(content); | ||
return state2.out; | ||
} | ||
get nodes() { | ||
var _this$editor$extensio; | ||
return { | ||
...Object.fromEntries(Object.keys(this.editor.schema.nodes).map((name) => [name, this.serializeNode(HTMLNode)])), | ||
...Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter((extension) => extension.type === "node" && this.serializeNode(extension)).map((extension) => [extension.name, this.serializeNode(extension)])) !== null && _this$editor$extensio !== void 0 ? _this$editor$extensio : []) | ||
}; | ||
} | ||
get marks() { | ||
var _this$editor$extensio2; | ||
return { | ||
...Object.fromEntries(Object.keys(this.editor.schema.marks).map((name) => [name, this.serializeMark(HTMLMark)])), | ||
...Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter((extension) => extension.type === "mark" && this.serializeMark(extension)).map((extension) => [extension.name, this.serializeMark(extension)])) !== null && _this$editor$extensio2 !== void 0 ? _this$editor$extensio2 : []) | ||
}; | ||
} | ||
serializeNode(node) { | ||
var _getMarkdownSpec, _getMarkdownSpec$seri; | ||
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$seri = _getMarkdownSpec.serialize) === null || _getMarkdownSpec$seri === void 0 ? void 0 : _getMarkdownSpec$seri.bind({ | ||
editor: this.editor, | ||
options: node.options | ||
}); | ||
} | ||
serializeMark(mark) { | ||
var _getMarkdownSpec2; | ||
const serialize = (_getMarkdownSpec2 = getMarkdownSpec(mark)) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.serialize; | ||
return serialize ? { | ||
...serialize, | ||
open: typeof serialize.open === "function" ? serialize.open.bind({ | ||
editor: this.editor, | ||
options: node.options | ||
}); | ||
} | ||
}, { | ||
key: "serializeMark", | ||
value: function serializeMark(mark) { | ||
var _getMarkdownSpec2; | ||
var serialize = (_getMarkdownSpec2 = getMarkdownSpec(mark)) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.serialize; | ||
return serialize ? _objectSpread2(_objectSpread2({}, serialize), {}, { | ||
open: typeof serialize.open === "function" ? serialize.open.bind({ | ||
editor: this.editor, | ||
options: mark.options | ||
}) : serialize.open, | ||
close: typeof serialize.close === "function" ? serialize.close.bind({ | ||
editor: this.editor, | ||
options: mark.options | ||
}) : serialize.close | ||
}) : null; | ||
} | ||
}]); | ||
return MarkdownSerializer2; | ||
}(); | ||
var MarkdownParser = /* @__PURE__ */ function() { | ||
function MarkdownParser2(editor, _ref) { | ||
var html = _ref.html, linkify = _ref.linkify, breaks = _ref.breaks; | ||
_classCallCheck(this, MarkdownParser2); | ||
_defineProperty(this, "editor", null); | ||
_defineProperty(this, "md", null); | ||
options: mark.options | ||
}) : serialize.open, | ||
close: typeof serialize.close === "function" ? serialize.close.bind({ | ||
editor: this.editor, | ||
options: mark.options | ||
}) : serialize.close | ||
} : null; | ||
} | ||
} | ||
class MarkdownParser { | ||
constructor(editor, _ref) { | ||
/** | ||
* @type {import('@tiptap/core').Editor} | ||
*/ | ||
__publicField(this, "editor", null); | ||
/** | ||
* @type {markdownit} | ||
*/ | ||
__publicField(this, "md", null); | ||
let { | ||
html, | ||
linkify, | ||
breaks | ||
} = _ref; | ||
this.editor = editor; | ||
@@ -1075,95 +849,87 @@ this.md = markdownit({ | ||
} | ||
_createClass(MarkdownParser2, [{ | ||
key: "parse", | ||
value: function parse(content) { | ||
var _this = this; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, inline = _ref2.inline; | ||
if (typeof content === "string") { | ||
var renderer = this.md; | ||
this.editor.extensionManager.extensions.forEach(function(extension) { | ||
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2; | ||
return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$pars = _getMarkdownSpec.parse) === null || _getMarkdownSpec$pars === void 0 ? void 0 : (_getMarkdownSpec$pars2 = _getMarkdownSpec$pars.setup) === null || _getMarkdownSpec$pars2 === void 0 ? void 0 : _getMarkdownSpec$pars2.call({ | ||
editor: _this.editor, | ||
options: extension.options | ||
}, renderer); | ||
}); | ||
var renderedHTML = renderer.render(content); | ||
var element = elementFromString(renderedHTML); | ||
this.editor.extensionManager.extensions.forEach(function(extension) { | ||
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2; | ||
return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 ? void 0 : (_getMarkdownSpec2$par = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2$par === void 0 ? void 0 : (_getMarkdownSpec2$par2 = _getMarkdownSpec2$par.updateDOM) === null || _getMarkdownSpec2$par2 === void 0 ? void 0 : _getMarkdownSpec2$par2.call({ | ||
editor: _this.editor, | ||
options: extension.options | ||
}, element); | ||
}); | ||
this.normalizeDOM(element, { | ||
inline, | ||
content | ||
}); | ||
return element.innerHTML; | ||
parse(content) { | ||
let { | ||
inline | ||
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; | ||
if (typeof content === "string") { | ||
const renderer = this.md; | ||
this.editor.extensionManager.extensions.forEach((extension) => { | ||
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2; | ||
return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$pars = _getMarkdownSpec.parse) === null || _getMarkdownSpec$pars === void 0 ? void 0 : (_getMarkdownSpec$pars2 = _getMarkdownSpec$pars.setup) === null || _getMarkdownSpec$pars2 === void 0 ? void 0 : _getMarkdownSpec$pars2.call({ | ||
editor: this.editor, | ||
options: extension.options | ||
}, renderer); | ||
}); | ||
const renderedHTML = renderer.render(content); | ||
const element = elementFromString(renderedHTML); | ||
this.editor.extensionManager.extensions.forEach((extension) => { | ||
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2; | ||
return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 ? void 0 : (_getMarkdownSpec2$par = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2$par === void 0 ? void 0 : (_getMarkdownSpec2$par2 = _getMarkdownSpec2$par.updateDOM) === null || _getMarkdownSpec2$par2 === void 0 ? void 0 : _getMarkdownSpec2$par2.call({ | ||
editor: this.editor, | ||
options: extension.options | ||
}, element); | ||
}); | ||
this.normalizeDOM(element, { | ||
inline, | ||
content | ||
}); | ||
return element.innerHTML; | ||
} | ||
return content; | ||
} | ||
normalizeDOM(node, _ref2) { | ||
let { | ||
inline, | ||
content | ||
} = _ref2; | ||
this.normalizeBlocks(node); | ||
node.querySelectorAll("*").forEach((el) => { | ||
var _el$nextSibling; | ||
if (((_el$nextSibling = el.nextSibling) === null || _el$nextSibling === void 0 ? void 0 : _el$nextSibling.nodeType) === Node.TEXT_NODE && !el.closest("pre")) { | ||
el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, ""); | ||
} | ||
return content; | ||
}); | ||
if (inline) { | ||
this.normalizeInline(node, content); | ||
} | ||
}, { | ||
key: "normalizeDOM", | ||
value: function normalizeDOM(node, _ref3) { | ||
var inline = _ref3.inline, content = _ref3.content; | ||
this.normalizeBlocks(node); | ||
node.querySelectorAll("*").forEach(function(el) { | ||
var _el$nextSibling; | ||
if (((_el$nextSibling = el.nextSibling) === null || _el$nextSibling === void 0 ? void 0 : _el$nextSibling.nodeType) === Node.TEXT_NODE && !el.closest("pre")) { | ||
el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, ""); | ||
} | ||
}); | ||
if (inline) { | ||
this.normalizeInline(node, content); | ||
return node; | ||
} | ||
normalizeBlocks(node) { | ||
const blocks = Object.values(this.editor.schema.nodes).filter((node2) => node2.isBlock); | ||
const selector = blocks.map((block) => { | ||
var _block$spec$parseDOM; | ||
return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map((spec) => spec.tag); | ||
}).flat().filter(Boolean).join(","); | ||
if (!selector) { | ||
return; | ||
} | ||
[...node.querySelectorAll(selector)].forEach((el) => { | ||
if (el.parentElement.matches("p")) { | ||
extractElement(el); | ||
} | ||
return node; | ||
} | ||
}, { | ||
key: "normalizeBlocks", | ||
value: function normalizeBlocks(node) { | ||
var blocks = Object.values(this.editor.schema.nodes).filter(function(node2) { | ||
return node2.isBlock; | ||
}); | ||
var selector = blocks.map(function(block) { | ||
var _block$spec$parseDOM; | ||
return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map(function(spec) { | ||
return spec.tag; | ||
}); | ||
}).flat().filter(Boolean).join(","); | ||
if (!selector) { | ||
}); | ||
} | ||
normalizeInline(node, content) { | ||
var _node$firstElementChi; | ||
if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches("p")) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
const firstParagraph = node.firstElementChild; | ||
const { | ||
nextSibling, | ||
nextElementSibling | ||
} = firstParagraph; | ||
const startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : ""; | ||
const endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : "" : ""; | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = `${firstParagraph.innerHTML}${endSpaces}`; | ||
return; | ||
} | ||
_toConsumableArray(node.querySelectorAll(selector)).forEach(function(el) { | ||
if (el.parentElement.matches("p")) { | ||
extractElement(el); | ||
} | ||
}); | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = `${startSpaces}${node.innerHTML}${endSpaces}`; | ||
} | ||
}, { | ||
key: "normalizeInline", | ||
value: function normalizeInline(node, content) { | ||
var _node$firstElementChi; | ||
if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches("p")) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
var firstParagraph = node.firstElementChild; | ||
firstParagraph.nextSibling; | ||
var nextElementSibling = firstParagraph.nextElementSibling; | ||
var startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : ""; | ||
var endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : "" : ""; | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = "".concat(firstParagraph.innerHTML).concat(endSpaces); | ||
return; | ||
} | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = "".concat(startSpaces).concat(node.innerHTML).concat(endSpaces); | ||
} | ||
} | ||
}]); | ||
return MarkdownParser2; | ||
}(); | ||
var MarkdownClipboard = core.Extension.create({ | ||
} | ||
} | ||
const MarkdownClipboard = core.Extension.create({ | ||
name: "markdownClipboard", | ||
addOptions: function addOptions() { | ||
addOptions() { | ||
return { | ||
@@ -1174,15 +940,14 @@ transformPastedText: false, | ||
}, | ||
addProseMirrorPlugins: function addProseMirrorPlugins() { | ||
var _this = this; | ||
addProseMirrorPlugins() { | ||
return [new state.Plugin({ | ||
key: new state.PluginKey("markdownClipboard"), | ||
props: { | ||
clipboardTextParser: function clipboardTextParser(text, context, plainText) { | ||
if (plainText || !_this.options.transformPastedText) { | ||
clipboardTextParser: (text, context, plainText) => { | ||
if (plainText || !this.options.transformPastedText) { | ||
return null; | ||
} | ||
var parsed = _this.editor.storage.markdown.parser.parse(text, { | ||
const parsed = this.editor.storage.markdown.parser.parse(text, { | ||
inline: true | ||
}); | ||
return model.DOMParser.fromSchema(_this.editor.schema).parseSlice(elementFromString(parsed), { | ||
return model.DOMParser.fromSchema(this.editor.schema).parseSlice(elementFromString(parsed), { | ||
preserveWhitespace: true, | ||
@@ -1195,7 +960,7 @@ context | ||
*/ | ||
clipboardTextSerializer: function clipboardTextSerializer(slice) { | ||
if (!_this.options.transformCopiedText) { | ||
clipboardTextSerializer: (slice) => { | ||
if (!this.options.transformCopiedText) { | ||
return null; | ||
} | ||
return _this.editor.storage.markdown.serializer.serialize(slice.content); | ||
return this.editor.storage.markdown.serializer.serialize(slice.content); | ||
} | ||
@@ -1206,6 +971,6 @@ } | ||
}); | ||
var Markdown = core.Extension.create({ | ||
const Markdown = core.Extension.create({ | ||
name: "markdown", | ||
priority: 50, | ||
addOptions: function addOptions() { | ||
addOptions() { | ||
return { | ||
@@ -1222,27 +987,24 @@ html: true, | ||
}, | ||
addCommands: function addCommands() { | ||
var commands = core.extensions.Commands.config.addCommands(); | ||
addCommands() { | ||
const commands = core.extensions.Commands.config.addCommands(); | ||
return { | ||
setContent: function setContent(content, emitUpdate, parseOptions) { | ||
return function(props) { | ||
return commands.setContent(props.editor.storage.markdown.parser.parse(content), emitUpdate, parseOptions)(props); | ||
}; | ||
setContent: (content, emitUpdate, parseOptions) => (props) => { | ||
return commands.setContent(props.editor.storage.markdown.parser.parse(content), emitUpdate, parseOptions)(props); | ||
}, | ||
insertContentAt: function insertContentAt(range, content, options) { | ||
return function(props) { | ||
return commands.insertContentAt(range, props.editor.storage.markdown.parser.parse(content, { | ||
inline: true | ||
}), options)(props); | ||
}; | ||
insertContentAt: (range, content, options) => (props) => { | ||
return commands.insertContentAt(range, props.editor.storage.markdown.parser.parse(content, { | ||
inline: true | ||
}), options)(props); | ||
} | ||
}; | ||
}, | ||
onBeforeCreate: function onBeforeCreate() { | ||
var _this = this; | ||
onBeforeCreate() { | ||
this.editor.storage.markdown = { | ||
options: _objectSpread2({}, this.options), | ||
options: { | ||
...this.options | ||
}, | ||
parser: new MarkdownParser(this.editor, this.options), | ||
serializer: new MarkdownSerializer(this.editor), | ||
getMarkdown: function getMarkdown() { | ||
return _this.editor.storage.markdown.serializer.serialize(_this.editor.state.doc); | ||
getMarkdown: () => { | ||
return this.editor.storage.markdown.serializer.serialize(this.editor.state.doc); | ||
} | ||
@@ -1253,7 +1015,7 @@ }; | ||
}, | ||
onCreate: function onCreate() { | ||
onCreate() { | ||
this.editor.options.content = this.editor.options.initialContent; | ||
delete this.editor.options.initialContent; | ||
}, | ||
addStorage: function addStorage() { | ||
addStorage() { | ||
return { | ||
@@ -1263,3 +1025,3 @@ /// storage will be defined in onBeforeCreate() to prevent initial object overriding | ||
}, | ||
addExtensions: function addExtensions() { | ||
addExtensions() { | ||
return [MarkdownTightLists.configure({ | ||
@@ -1266,0 +1028,0 @@ tight: this.options.tightLists, |
{ | ||
"name": "tiptap-markdown", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "Edit markdown content in tiptap editor.", | ||
@@ -10,2 +10,3 @@ "scripts": { | ||
"build:example": "vite build example", | ||
"preview": "vite preview example", | ||
"preversion": "npm run build", | ||
@@ -19,2 +20,4 @@ "update:tiptap": "update-by-scope @tiptap" | ||
"module": "dist/tiptap-markdown.es.js", | ||
"type": "module", | ||
"sideEffects": false, | ||
"exports": { | ||
@@ -31,2 +34,6 @@ ".": { | ||
], | ||
"browserslist": [ | ||
"defaults", | ||
"not IE 11" | ||
], | ||
"repository": { | ||
@@ -52,5 +59,7 @@ "type": "git", | ||
"devDependencies": { | ||
"@babel/core": "^7.14.3", | ||
"@babel/preset-env": "^7.14.4", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@babel/core": "^7.23.2", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6", | ||
"@babel/plugin-proposal-optional-chaining": "^7.21.0", | ||
"@babel/preset-env": "^7.23.2", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@tiptap/core": "^2.0.3", | ||
@@ -57,0 +66,0 @@ "@tiptap/extension-highlight": "^2.0.3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
Yes
224234
25
3028