New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/block-tools

Package Overview
Dependencies
Maintainers
0
Versions
1293
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/block-tools - npm Package Compare versions

Comparing version 3.66.2-corel.439 to 3.66.2-upgrade-vite-v5.30

461

lib/index.esm.js

@@ -39,2 +39,10 @@ import flatten from "lodash/flatten.js";

}
var __defProp$7 = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$6.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
if (__getOwnPropSymbols$6)
for (var prop of __getOwnPropSymbols$6(b))
__propIsEnum$6.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
return a;
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
const PRESERVE_WHITESPACE_TAGS = ["pre", "textarea", "code"], BLOCK_DEFAULT_STYLE = "normal", DEFAULT_BLOCK = Object.freeze({

@@ -49,3 +57,3 @@ _type: "block",

p: DEFAULT_BLOCK,
blockquote: { ...DEFAULT_BLOCK, style: "blockquote" }
blockquote: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "blockquote" })
}, HTML_SPAN_TAGS = {

@@ -57,10 +65,10 @@ span: { object: "text" }

}, HTML_HEADER_TAGS = {
h1: { ...DEFAULT_BLOCK, style: "h1" },
h2: { ...DEFAULT_BLOCK, style: "h2" },
h3: { ...DEFAULT_BLOCK, style: "h3" },
h4: { ...DEFAULT_BLOCK, style: "h4" },
h5: { ...DEFAULT_BLOCK, style: "h5" },
h6: { ...DEFAULT_BLOCK, style: "h6" }
h1: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h1" }),
h2: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h2" }),
h3: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h3" }),
h4: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h4" }),
h5: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h5" }),
h6: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h6" })
}, HTML_MISC_TAGS = {
br: { ...DEFAULT_BLOCK, style: BLOCK_DEFAULT_STYLE }
br: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: BLOCK_DEFAULT_STYLE })
}, HTML_DECORATOR_TAGS = {

@@ -82,16 +90,8 @@ b: "strong",

}, HTML_LIST_ITEM_TAGS = {
li: {
...DEFAULT_BLOCK,
li: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), {
style: BLOCK_DEFAULT_STYLE,
level: 1,
listItem: "bullet"
}
}, ELEMENT_MAP = {
...HTML_BLOCK_TAGS,
...HTML_SPAN_TAGS,
...HTML_LIST_CONTAINER_TAGS,
...HTML_LIST_ITEM_TAGS,
...HTML_HEADER_TAGS,
...HTML_MISC_TAGS
};
})
}, ELEMENT_MAP = __spreadValues$6(__spreadValues$6(__spreadValues$6(__spreadValues$6(__spreadValues$6(__spreadValues$6({}, HTML_BLOCK_TAGS), HTML_SPAN_TAGS), HTML_LIST_CONTAINER_TAGS), HTML_LIST_ITEM_TAGS), HTML_HEADER_TAGS), HTML_MISC_TAGS);
uniq(

@@ -102,2 +102,3 @@ Object.values(ELEMENT_MAP).filter((tag) => "style" in tag).map((tag) => tag.style)

function blockContentFeatures(blockContentType) {
var _a, _b;
if (!blockContentType)

@@ -108,3 +109,3 @@ throw new Error("Parameter 'blockContentType' required");

throw new Error("'block' type is not defined in this schema (required).");
const ofType = blockType.fields.find(isBlockChildrenObjectField)?.type?.of;
const ofType = (_b = (_a = blockType.fields.find(isBlockChildrenObjectField)) == null ? void 0 : _a.type) == null ? void 0 : _b.of;
if (!ofType)

@@ -181,3 +182,4 @@ throw new Error("No `of` declaration found for blocks `children` field");

var preprocessGDocs = (html, doc, options) => {
const whitespaceOnPasteMode = options?.unstable_whitespaceOnPasteMode || "preserve";
var _a;
const whitespaceOnPasteMode = (options == null ? void 0 : options.unstable_whitespaceOnPasteMode) || "preserve";
let gDocsRootOrSiblingNode = doc.evaluate(

@@ -209,5 +211,5 @@ '//*[@id and contains(@id, "docs-internal-guid")]',

const elm = childNodes.snapshotItem(i);
elm?.setAttribute("data-is-google-docs", "true"), (elm?.parentElement === gDocsRootOrSiblingNode || !isWrappedRootTag && elm.parentElement === doc.body) && (elm?.setAttribute("data-is-root-node", "true"), tagName(elm)), tagName(elm) === "li" && elm.firstChild && tagName(elm?.firstChild) === "img" && elm.removeChild(elm.firstChild);
elm == null || elm.setAttribute("data-is-google-docs", "true"), ((elm == null ? void 0 : elm.parentElement) === gDocsRootOrSiblingNode || !isWrappedRootTag && elm.parentElement === doc.body) && (elm == null || elm.setAttribute("data-is-root-node", "true"), tagName(elm)), tagName(elm) === "li" && elm.firstChild && tagName(elm == null ? void 0 : elm.firstChild) === "img" && elm.removeChild(elm.firstChild);
}
return isWrappedRootTag && doc.body.firstElementChild?.replaceWith(...Array.from(gDocsRootOrSiblingNode.childNodes)), doc;
return isWrappedRootTag && ((_a = doc.body.firstElementChild) == null || _a.replaceWith(...Array.from(gDocsRootOrSiblingNode.childNodes))), doc;
}

@@ -230,2 +232,3 @@ return doc;

var preprocessHTML = (html, doc) => {
var _a, _b, _c;
const bodyTextNodes = doc.evaluate(

@@ -242,5 +245,5 @@ "/html/body/text()",

const newNode = doc.createElement("span");
newNode.appendChild(doc.createTextNode(text)), node.parentNode?.replaceChild(newNode, node);
newNode.appendChild(doc.createTextNode(text)), (_a = node.parentNode) == null || _a.replaceChild(newNode, node);
} else
node.parentNode?.removeChild(node);
(_b = node.parentNode) == null || _b.removeChild(node);
}

@@ -256,3 +259,3 @@ const unwantedNodes = doc.evaluate(

const unwanted = unwantedNodes.snapshotItem(i);
unwanted && unwanted.parentNode?.removeChild(unwanted);
unwanted && ((_c = unwanted.parentNode) == null || _c.removeChild(unwanted));
}

@@ -270,4 +273,6 @@ return doc;

);
for (let i = childNodes.snapshotLength - 1; i >= 0; i--)
childNodes.snapshotItem(i)?.setAttribute("data-is-notion", "true");
for (let i = childNodes.snapshotLength - 1; i >= 0; i--) {
const elm = childNodes.snapshotItem(i);
elm == null || elm.setAttribute("data-is-notion", "true");
}
return doc;

@@ -278,4 +283,5 @@ }

function processNode(node) {
if (node.nodeType === _XPathResult.BOOLEAN_TYPE && !PRESERVE_WHITESPACE_TAGS.includes(node.parentElement?.tagName.toLowerCase() || ""))
node.textContent = node.textContent?.replace(/\s\s+/g, " ").replace(/[\r\n]+/g, " ") || "";
var _a, _b;
if (node.nodeType === _XPathResult.BOOLEAN_TYPE && !PRESERVE_WHITESPACE_TAGS.includes(((_a = node.parentElement) == null ? void 0 : _a.tagName.toLowerCase()) || ""))
node.textContent = ((_b = node.textContent) == null ? void 0 : _b.replace(/\s\s+/g, " ").replace(/[\r\n]+/g, " ")) || "";
else

@@ -311,2 +317,3 @@ for (let i = 0; i < node.childNodes.length; i++)

var preprocessWord = (html, doc) => {
var _a;
if (!isWordHtml(html))

@@ -323,3 +330,3 @@ return doc;

const unwanted = unwantedNodes.snapshotItem(i);
unwanted?.parentNode && unwanted.parentNode.removeChild(unwanted);
unwanted != null && unwanted.parentNode && unwanted.parentNode.removeChild(unwanted);
}

@@ -341,3 +348,3 @@ const mappedElements = doc.evaluate(

child = doc.createElement(tag), parent.appendChild(child), parent = child;
}), child.appendChild(text), mappedElm?.parentNode?.replaceChild(parentElement, mappedElm);
}), child.appendChild(text), (_a = mappedElm == null ? void 0 : mappedElm.parentNode) == null || _a.replaceChild(parentElement, mappedElm);
}

@@ -351,3 +358,10 @@ return doc;

preprocessHTML
];
], __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$5.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
if (__getOwnPropSymbols$5)
for (var prop of __getOwnPropSymbols$5(b))
__propIsEnum$5.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
return a;
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
function createRuleOptions(blockContentType) {

@@ -424,6 +438,5 @@ const features = blockContentFeatures(blockContentType), enabledBlockStyles = features.styles.map((item) => item.value || item.title), enabledSpanDecorators = features.decorators.map((item) => item.value || item.title), enabledBlockAnnotations = features.annotations.map((item) => item.value || item.title || ""), enabledListTypes = features.lists.map((item) => item.value || item.title || "");

return lastBlock.children.push(node), memo;
const block = {
...DEFAULT_BLOCK,
const block = __spreadProps$5(__spreadValues$5({}, DEFAULT_BLOCK), {
children: [node]
};
});
return memo.push(block), memo;

@@ -461,3 +474,6 @@ }, []);

}
nodesToRemove.forEach((node) => node.parentElement?.removeChild(node));
nodesToRemove.forEach((node) => {
var _a;
return (_a = node.parentElement) == null ? void 0 : _a.removeChild(node);
});
}

@@ -467,2 +483,3 @@ function removeAllWhitespace(rootNode) {

function collectNodesToRemove(currentNode) {
var _a, _b;
if (isElement(currentNode)) {

@@ -474,3 +491,3 @@ const elm = currentNode;

}
if ((tagName(elm) === "p" || tagName(elm) === "br") && elm?.firstChild?.textContent?.trim() === "") {
if ((tagName(elm) === "p" || tagName(elm) === "br") && ((_b = (_a = elm == null ? void 0 : elm.firstChild) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim()) === "") {
nodesToRemove.push(elm);

@@ -483,7 +500,19 @@ return;

}
collectNodesToRemove(rootNode), nodesToRemove.forEach((node) => node.parentElement?.removeChild(node));
collectNodesToRemove(rootNode), nodesToRemove.forEach((node) => {
var _a;
return (_a = node.parentElement) == null ? void 0 : _a.removeChild(node);
});
}
function isWhitespaceBlock(elm) {
return ["p", "br"].includes(tagName(elm) || "") && !elm.textContent?.trim();
var _a;
return ["p", "br"].includes(tagName(elm) || "") && !((_a = elm.textContent) != null && _a.trim());
}
var __defProp$5 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$4.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
if (__getOwnPropSymbols$4)
for (var prop of __getOwnPropSymbols$4(b))
__propIsEnum$4.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
return a;
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
const LIST_CONTAINER_TAGS = Object.keys(HTML_LIST_CONTAINER_TAGS);

@@ -531,6 +560,3 @@ function isEmphasis$1(el) {

}
const blocks = {
...HTML_BLOCK_TAGS,
...HTML_HEADER_TAGS
};
const blocks = __spreadValues$4(__spreadValues$4({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS);
function getBlockStyle(el, enabledBlockStyles) {

@@ -545,7 +571,6 @@ const childTag = tagName(el.firstChild), block = childTag && blocks[childTag];

if (isElement(el) && tagName(el) === "span" && isGoogleDocs(el)) {
const span = {
...DEFAULT_SPAN,
const span = __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
marks: [],
text: el.textContent
};
});
return isStrong$1(el) && span.marks.push("strong"), isUnderline$1(el) && span.marks.push("underline"), isStrikethrough(el) && span.marks.push("strike-through"), isEmphasis$1(el) && span.marks.push("em"), span;

@@ -557,10 +582,10 @@ }

deserialize(el, next) {
var _a;
if (tagName(el) === "li" && isGoogleDocs(el))
return {
...DEFAULT_BLOCK,
return __spreadProps$4(__spreadValues$4({}, DEFAULT_BLOCK), {
listItem: getListItemStyle$1(el),
level: getListItemLevel$1(el),
style: getBlockStyle(el, options.enabledBlockStyles),
children: next(el.firstChild?.childNodes || [])
};
children: next(((_a = el.firstChild) == null ? void 0 : _a.childNodes) || [])
});
}

@@ -570,17 +595,15 @@ },

deserialize(el) {
var _a;
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && el.classList.contains("apple-interchange-newline"))
return {
...DEFAULT_SPAN,
return __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
text: ""
};
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && el?.parentNode?.textContent === "")
return {
...DEFAULT_SPAN,
});
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && ((_a = el == null ? void 0 : el.parentNode) == null ? void 0 : _a.textContent) === "")
return __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
text: ""
};
});
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && isRootNode(el))
return {
...DEFAULT_SPAN,
return __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
text: ""
};
});
}

@@ -600,2 +623,10 @@ }

}
var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$3.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
if (__getOwnPropSymbols$3)
for (var prop of __getOwnPropSymbols$3(b))
__propIsEnum$3.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
return a;
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
function resolveListItem(listNodeTagName, enabledListTypes) {

@@ -616,7 +647,6 @@ if (listNodeTagName === "ul" && enabledListTypes.includes("bullet"))

if (el.nodeName === "#text" && isValidText)
return {
...DEFAULT_SPAN,
return __spreadProps$3(__spreadValues$3({}, DEFAULT_SPAN), {
marks: [],
text: (el.textContent || "").replace(/\s\s+/g, " ")
};
});
}

@@ -635,7 +665,6 @@ },

children: [
{
...DEFAULT_SPAN,
__spreadProps$3(__spreadValues$3({}, DEFAULT_SPAN), {
marks: isCodeEnabled ? ["code"] : [],
text: el.textContent || ""
}
})
]

@@ -650,6 +679,3 @@ };

return;
const blocks2 = {
...HTML_BLOCK_TAGS,
...HTML_HEADER_TAGS
};
const blocks2 = __spreadValues$3(__spreadValues$3({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS);
delete blocks2.blockquote;

@@ -678,12 +704,8 @@ const children = [];

deserialize(el, next) {
const blocks2 = {
...HTML_BLOCK_TAGS,
...HTML_HEADER_TAGS
}, tag = tagName(el);
const blocks2 = __spreadValues$3(__spreadValues$3({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS), tag = tagName(el);
let block = tag ? blocks2[tag] : void 0;
if (block)
return el.parentNode && tagName(el.parentNode) === "li" ? next(el.childNodes) : (options.enabledBlockStyles.includes(block.style) || (block = DEFAULT_BLOCK), {
...block,
return el.parentNode && tagName(el.parentNode) === "li" ? next(el.childNodes) : (options.enabledBlockStyles.includes(block.style) || (block = DEFAULT_BLOCK), __spreadProps$3(__spreadValues$3({}, block), {
children: next(el.childNodes)
});
}));
}

@@ -718,7 +740,6 @@ },

if (tagName(el) === "br")
return {
...DEFAULT_SPAN,
return __spreadProps$3(__spreadValues$3({}, DEFAULT_SPAN), {
text: `
`
};
});
}

@@ -733,6 +754,5 @@ },

const enabledListItem = resolveListItem(parentTag, options.enabledListTypes);
return enabledListItem ? (listItem.listItem = enabledListItem, {
...listItem,
return enabledListItem ? (listItem.listItem = enabledListItem, __spreadProps$3(__spreadValues$3({}, listItem), {
children: next(el.childNodes)
}) : block({ _type: "block", children: next(el.childNodes) });
})) : block({ _type: "block", children: next(el.childNodes) });
}

@@ -775,2 +795,10 @@ },

}
var __defProp$3 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$2.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
if (__getOwnPropSymbols$2)
for (var prop of __getOwnPropSymbols$2(b))
__propIsEnum$2.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
return a;
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
function isEmphasis(el) {

@@ -791,2 +819,3 @@ const style = isElement(el) && el.getAttribute("style");

}
__spreadValues$2(__spreadValues$2({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS);
function createNotionRules(_blockContentType) {

@@ -797,7 +826,6 @@ return [

if (isElement(el) && tagName(el) === "span" && isNotion(el)) {
const span = {
...DEFAULT_SPAN,
const span = __spreadProps$2(__spreadValues$2({}, DEFAULT_SPAN), {
marks: [],
text: el.textContent
};
});
return isStrong(el) && span.marks.push("strong"), isUnderline(el) && span.marks.push("underline"), isEmphasis(el) && span.marks.push("em"), span;

@@ -809,2 +837,10 @@ }

}
var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$1.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
if (__getOwnPropSymbols$1)
for (var prop of __getOwnPropSymbols$1(b))
__propIsEnum$1.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
return a;
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
function getListItemStyle(el) {

@@ -833,4 +869,3 @@ const style = isElement(el) && el.getAttribute("style");

if (tagName(el) === "p" && isWordListElement(el))
return {
...DEFAULT_BLOCK,
return __spreadProps$1(__spreadValues$1({}, DEFAULT_BLOCK), {
listItem: getListItemStyle(el),

@@ -840,3 +875,3 @@ level: getListItemLevel(el),

children: next(el.childNodes)
};
});
}

@@ -854,7 +889,4 @@ }

}
var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value);
class HtmlDeserializer {
blockContentType;
rules;
parseHtml;
_markDefs = [];
/**

@@ -867,2 +899,95 @@ * Create a new serializer respecting a Sanity block content type's schema

constructor(blockContentType, options = {}) {
__publicField(this, "blockContentType"), __publicField(this, "rules"), __publicField(this, "parseHtml"), __publicField(this, "_markDefs", []), __publicField(this, "deserialize", (html) => {
this._markDefs = [];
const { parseHtml: parseHtml2 } = this, fragment = parseHtml2(html), children = Array.from(fragment.childNodes), blocks2 = trimWhitespace(
flattenNestedBlocks(ensureRootIsBlocks(this.deserializeElements(children)))
);
this._markDefs.length > 0 && blocks2.filter((block) => block._type === "block").forEach((block) => {
block.markDefs = block.markDefs || [], block.markDefs = block.markDefs.concat(
this._markDefs.filter((def) => flatten(block.children.map((child) => child.marks || [])).includes(def._key))
);
});
const type = this.blockContentType.of.find(findBlockType);
return type ? blocks2.map((block) => (block._type === "block" && (block._type = type.name), block)) : blocks2;
}), __publicField(this, "deserializeElements", (elements = []) => {
let nodes = [];
return elements.forEach((element) => {
nodes = nodes.concat(this.deserializeElement(element));
}), nodes;
}), __publicField(this, "deserializeElement", (element) => {
var _a, _b;
const next = (elements) => {
if (isNodeList(elements))
return this.deserializeElements(Array.from(elements));
if (Array.isArray(elements))
return this.deserializeElements(elements);
if (elements)
return this.deserializeElement(elements);
}, block = (props) => ({
_type: "__block",
block: props
});
let node;
for (let i = 0; i < this.rules.length; i++) {
const rule = this.rules[i];
if (!rule.deserialize)
continue;
const ret = rule.deserialize(element, next, block), type = resolveJsType(ret);
if (type !== "array" && type !== "object" && type !== "null" && type !== "undefined")
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`);
if (ret !== void 0) {
{
if (ret === null)
throw new Error("Deserializer rule returned `null`");
Array.isArray(ret) ? node = ret : isPlaceholderDecorator(ret) ? node = this.deserializeDecorator(ret) : isPlaceholderAnnotation(ret) ? node = this.deserializeAnnotation(ret) : node = ret;
}
if (ret && !Array.isArray(ret) && isMinimalBlock(ret) && "listItem" in ret) {
let parent = (_a = element.parentNode) == null ? void 0 : _a.parentNode;
for (; parent && tagName(parent) === "li"; )
parent = (_b = parent.parentNode) == null ? void 0 : _b.parentNode, ret.level = ret.level ? ret.level + 1 : 1;
}
ret && !Array.isArray(ret) && isMinimalBlock(ret) && ret.style === "blockquote" && ret.children.forEach((child, index) => {
isMinimalSpan(child) && child.text === "\r" && (child.text = `
`, (index === 0 || index === ret.children.length - 1) && ret.children.splice(index, 1));
});
break;
}
}
return node || next(element.childNodes) || [];
}), __publicField(this, "deserializeDecorator", (decorator) => {
const { name } = decorator, applyDecorator = (node) => {
if (isPlaceholderDecorator(node))
return this.deserializeDecorator(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(name);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyDecorator);
}
return node;
};
return decorator.children.reduce((children, node) => {
const ret = applyDecorator(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
}), __publicField(this, "deserializeAnnotation", (annotation) => {
const { markDef } = annotation;
this._markDefs.push(markDef);
const applyAnnotation = (node) => {
if (isPlaceholderAnnotation(node))
return this.deserializeAnnotation(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(markDef._key);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyAnnotation);
}
return node;
};
return annotation.children.reduce((children, node) => {
const ret = applyAnnotation(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
});
const { rules = [], unstable_whitespaceOnPasteMode = "preserve" } = options;

@@ -876,140 +1001,19 @@ if (!blockContentType)

}
/**
* Deserialize HTML.
*
* @param html - The HTML to deserialize, as a string
* @returns Array of blocks - either portable text blocks or other allowed blocks
*/
deserialize = (html) => {
this._markDefs = [];
const { parseHtml } = this, fragment = parseHtml(html), children = Array.from(fragment.childNodes), blocks2 = trimWhitespace(
flattenNestedBlocks(ensureRootIsBlocks(this.deserializeElements(children)))
);
this._markDefs.length > 0 && blocks2.filter((block) => block._type === "block").forEach((block) => {
block.markDefs = block.markDefs || [], block.markDefs = block.markDefs.concat(
this._markDefs.filter((def) => flatten(block.children.map((child) => child.marks || [])).includes(def._key))
);
});
const type = this.blockContentType.of.find(findBlockType);
return type ? blocks2.map((block) => (block._type === "block" && (block._type = type.name), block)) : blocks2;
};
/**
* Deserialize an array of DOM elements.
*
* @param elements - Array of DOM elements to deserialize
* @returns
*/
deserializeElements = (elements = []) => {
let nodes = [];
return elements.forEach((element) => {
nodes = nodes.concat(this.deserializeElement(element));
}), nodes;
};
/**
* Deserialize a DOM element
*
* @param element - Deserialize a DOM element
* @returns
*/
deserializeElement = (element) => {
const next = (elements) => {
if (isNodeList(elements))
return this.deserializeElements(Array.from(elements));
if (Array.isArray(elements))
return this.deserializeElements(elements);
if (elements)
return this.deserializeElement(elements);
}, block = (props) => ({
_type: "__block",
block: props
});
let node;
for (let i = 0; i < this.rules.length; i++) {
const rule = this.rules[i];
if (!rule.deserialize)
continue;
const ret = rule.deserialize(element, next, block), type = resolveJsType(ret);
if (type !== "array" && type !== "object" && type !== "null" && type !== "undefined")
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`);
if (ret !== void 0) {
{
if (ret === null)
throw new Error("Deserializer rule returned `null`");
Array.isArray(ret) ? node = ret : isPlaceholderDecorator(ret) ? node = this.deserializeDecorator(ret) : isPlaceholderAnnotation(ret) ? node = this.deserializeAnnotation(ret) : node = ret;
}
if (ret && !Array.isArray(ret) && isMinimalBlock(ret) && "listItem" in ret) {
let parent = element.parentNode?.parentNode;
for (; parent && tagName(parent) === "li"; )
parent = parent.parentNode?.parentNode, ret.level = ret.level ? ret.level + 1 : 1;
}
ret && !Array.isArray(ret) && isMinimalBlock(ret) && ret.style === "blockquote" && ret.children.forEach((child, index) => {
isMinimalSpan(child) && child.text === "\r" && (child.text = `
`, (index === 0 || index === ret.children.length - 1) && ret.children.splice(index, 1));
});
break;
}
}
return node || next(element.childNodes) || [];
};
/**
* Deserialize a `__decorator` type
* (an internal made up type to process decorators exclusively)
*
* @param decorator -
* @returns array of ...
*/
deserializeDecorator = (decorator) => {
const { name } = decorator, applyDecorator = (node) => {
if (isPlaceholderDecorator(node))
return this.deserializeDecorator(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(name);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyDecorator);
}
return node;
};
return decorator.children.reduce((children, node) => {
const ret = applyDecorator(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
};
/**
* Deserialize a `__annotation` object.
* (an internal made up type to process annotations exclusively)
*
* @param annotation -
* @returns Array of...
*/
deserializeAnnotation = (annotation) => {
const { markDef } = annotation;
this._markDefs.push(markDef);
const applyAnnotation = (node) => {
if (isPlaceholderAnnotation(node))
return this.deserializeAnnotation(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(markDef._key);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyAnnotation);
}
return node;
};
return annotation.children.reduce((children, node) => {
const ret = applyAnnotation(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
};
}
var __defProp = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b))
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
return a;
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
function normalizeBlock(node, options = {}) {
if (node._type !== (options.blockTypeName || "block"))
return "_key" in node ? node : { ...node, _key: randomKey(12) };
const block = {
return "_key" in node ? node : __spreadProps(__spreadValues({}, node), { _key: randomKey(12) });
const block = __spreadValues({
_key: randomKey(12),
children: [],
markDefs: [],
...node
}, lastChild = block.children[block.children.length - 1];
markDefs: []
}, node), lastChild = block.children[block.children.length - 1];
if (!lastChild)

@@ -1035,3 +1039,4 @@ return block.children = [

return child._key = `${block._key}${index}`, isPortableTextSpan(child) && (child.marks ? allowedDecorators && (child.marks = child.marks.filter((mark) => {
const isAllowed = allowedDecorators.includes(mark), isUsed = block.markDefs?.some((def) => def._key === mark);
var _a;
const isAllowed = allowedDecorators.includes(mark), isUsed = (_a = block.markDefs) == null ? void 0 : _a.some((def) => def._key === mark);
return isAllowed || isUsed;

@@ -1038,0 +1043,0 @@ })) : child.marks = [], usedMarkDefs.push(...child.marks)), child;

@@ -41,2 +41,10 @@ "use strict";

}
var __defProp$7 = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$6.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
if (__getOwnPropSymbols$6)
for (var prop of __getOwnPropSymbols$6(b))
__propIsEnum$6.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
return a;
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
const PRESERVE_WHITESPACE_TAGS = ["pre", "textarea", "code"], BLOCK_DEFAULT_STYLE = "normal", DEFAULT_BLOCK = Object.freeze({

@@ -51,3 +59,3 @@ _type: "block",

p: DEFAULT_BLOCK,
blockquote: { ...DEFAULT_BLOCK, style: "blockquote" }
blockquote: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "blockquote" })
}, HTML_SPAN_TAGS = {

@@ -59,10 +67,10 @@ span: { object: "text" }

}, HTML_HEADER_TAGS = {
h1: { ...DEFAULT_BLOCK, style: "h1" },
h2: { ...DEFAULT_BLOCK, style: "h2" },
h3: { ...DEFAULT_BLOCK, style: "h3" },
h4: { ...DEFAULT_BLOCK, style: "h4" },
h5: { ...DEFAULT_BLOCK, style: "h5" },
h6: { ...DEFAULT_BLOCK, style: "h6" }
h1: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h1" }),
h2: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h2" }),
h3: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h3" }),
h4: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h4" }),
h5: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h5" }),
h6: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: "h6" })
}, HTML_MISC_TAGS = {
br: { ...DEFAULT_BLOCK, style: BLOCK_DEFAULT_STYLE }
br: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), { style: BLOCK_DEFAULT_STYLE })
}, HTML_DECORATOR_TAGS = {

@@ -84,16 +92,8 @@ b: "strong",

}, HTML_LIST_ITEM_TAGS = {
li: {
...DEFAULT_BLOCK,
li: __spreadProps$6(__spreadValues$6({}, DEFAULT_BLOCK), {
style: BLOCK_DEFAULT_STYLE,
level: 1,
listItem: "bullet"
}
}, ELEMENT_MAP = {
...HTML_BLOCK_TAGS,
...HTML_SPAN_TAGS,
...HTML_LIST_CONTAINER_TAGS,
...HTML_LIST_ITEM_TAGS,
...HTML_HEADER_TAGS,
...HTML_MISC_TAGS
};
})
}, ELEMENT_MAP = __spreadValues$6(__spreadValues$6(__spreadValues$6(__spreadValues$6(__spreadValues$6(__spreadValues$6({}, HTML_BLOCK_TAGS), HTML_SPAN_TAGS), HTML_LIST_CONTAINER_TAGS), HTML_LIST_ITEM_TAGS), HTML_HEADER_TAGS), HTML_MISC_TAGS);
uniq__default.default(

@@ -104,2 +104,3 @@ Object.values(ELEMENT_MAP).filter((tag) => "style" in tag).map((tag) => tag.style)

function blockContentFeatures(blockContentType) {
var _a, _b;
if (!blockContentType)

@@ -110,3 +111,3 @@ throw new Error("Parameter 'blockContentType' required");

throw new Error("'block' type is not defined in this schema (required).");
const ofType = blockType.fields.find(types.isBlockChildrenObjectField)?.type?.of;
const ofType = (_b = (_a = blockType.fields.find(types.isBlockChildrenObjectField)) == null ? void 0 : _a.type) == null ? void 0 : _b.of;
if (!ofType)

@@ -183,3 +184,4 @@ throw new Error("No `of` declaration found for blocks `children` field");

var preprocessGDocs = (html, doc, options) => {
const whitespaceOnPasteMode = options?.unstable_whitespaceOnPasteMode || "preserve";
var _a;
const whitespaceOnPasteMode = (options == null ? void 0 : options.unstable_whitespaceOnPasteMode) || "preserve";
let gDocsRootOrSiblingNode = doc.evaluate(

@@ -211,5 +213,5 @@ '//*[@id and contains(@id, "docs-internal-guid")]',

const elm = childNodes.snapshotItem(i);
elm?.setAttribute("data-is-google-docs", "true"), (elm?.parentElement === gDocsRootOrSiblingNode || !isWrappedRootTag && elm.parentElement === doc.body) && (elm?.setAttribute("data-is-root-node", "true"), tagName(elm)), tagName(elm) === "li" && elm.firstChild && tagName(elm?.firstChild) === "img" && elm.removeChild(elm.firstChild);
elm == null || elm.setAttribute("data-is-google-docs", "true"), ((elm == null ? void 0 : elm.parentElement) === gDocsRootOrSiblingNode || !isWrappedRootTag && elm.parentElement === doc.body) && (elm == null || elm.setAttribute("data-is-root-node", "true"), tagName(elm)), tagName(elm) === "li" && elm.firstChild && tagName(elm == null ? void 0 : elm.firstChild) === "img" && elm.removeChild(elm.firstChild);
}
return isWrappedRootTag && doc.body.firstElementChild?.replaceWith(...Array.from(gDocsRootOrSiblingNode.childNodes)), doc;
return isWrappedRootTag && ((_a = doc.body.firstElementChild) == null || _a.replaceWith(...Array.from(gDocsRootOrSiblingNode.childNodes))), doc;
}

@@ -232,2 +234,3 @@ return doc;

var preprocessHTML = (html, doc) => {
var _a, _b, _c;
const bodyTextNodes = doc.evaluate(

@@ -244,5 +247,5 @@ "/html/body/text()",

const newNode = doc.createElement("span");
newNode.appendChild(doc.createTextNode(text)), node.parentNode?.replaceChild(newNode, node);
newNode.appendChild(doc.createTextNode(text)), (_a = node.parentNode) == null || _a.replaceChild(newNode, node);
} else
node.parentNode?.removeChild(node);
(_b = node.parentNode) == null || _b.removeChild(node);
}

@@ -258,3 +261,3 @@ const unwantedNodes = doc.evaluate(

const unwanted = unwantedNodes.snapshotItem(i);
unwanted && unwanted.parentNode?.removeChild(unwanted);
unwanted && ((_c = unwanted.parentNode) == null || _c.removeChild(unwanted));
}

@@ -272,4 +275,6 @@ return doc;

);
for (let i = childNodes.snapshotLength - 1; i >= 0; i--)
childNodes.snapshotItem(i)?.setAttribute("data-is-notion", "true");
for (let i = childNodes.snapshotLength - 1; i >= 0; i--) {
const elm = childNodes.snapshotItem(i);
elm == null || elm.setAttribute("data-is-notion", "true");
}
return doc;

@@ -280,4 +285,5 @@ }

function processNode(node) {
if (node.nodeType === _XPathResult.BOOLEAN_TYPE && !PRESERVE_WHITESPACE_TAGS.includes(node.parentElement?.tagName.toLowerCase() || ""))
node.textContent = node.textContent?.replace(/\s\s+/g, " ").replace(/[\r\n]+/g, " ") || "";
var _a, _b;
if (node.nodeType === _XPathResult.BOOLEAN_TYPE && !PRESERVE_WHITESPACE_TAGS.includes(((_a = node.parentElement) == null ? void 0 : _a.tagName.toLowerCase()) || ""))
node.textContent = ((_b = node.textContent) == null ? void 0 : _b.replace(/\s\s+/g, " ").replace(/[\r\n]+/g, " ")) || "";
else

@@ -313,2 +319,3 @@ for (let i = 0; i < node.childNodes.length; i++)

var preprocessWord = (html, doc) => {
var _a;
if (!isWordHtml(html))

@@ -325,3 +332,3 @@ return doc;

const unwanted = unwantedNodes.snapshotItem(i);
unwanted?.parentNode && unwanted.parentNode.removeChild(unwanted);
unwanted != null && unwanted.parentNode && unwanted.parentNode.removeChild(unwanted);
}

@@ -343,3 +350,3 @@ const mappedElements = doc.evaluate(

child = doc.createElement(tag), parent.appendChild(child), parent = child;
}), child.appendChild(text), mappedElm?.parentNode?.replaceChild(parentElement, mappedElm);
}), child.appendChild(text), (_a = mappedElm == null ? void 0 : mappedElm.parentNode) == null || _a.replaceChild(parentElement, mappedElm);
}

@@ -353,3 +360,10 @@ return doc;

preprocessHTML
];
], __defProp$6 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$5.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
if (__getOwnPropSymbols$5)
for (var prop of __getOwnPropSymbols$5(b))
__propIsEnum$5.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
return a;
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
function createRuleOptions(blockContentType) {

@@ -426,6 +440,5 @@ const features = blockContentFeatures(blockContentType), enabledBlockStyles = features.styles.map((item) => item.value || item.title), enabledSpanDecorators = features.decorators.map((item) => item.value || item.title), enabledBlockAnnotations = features.annotations.map((item) => item.value || item.title || ""), enabledListTypes = features.lists.map((item) => item.value || item.title || "");

return lastBlock.children.push(node), memo;
const block = {
...DEFAULT_BLOCK,
const block = __spreadProps$5(__spreadValues$5({}, DEFAULT_BLOCK), {
children: [node]
};
});
return memo.push(block), memo;

@@ -463,3 +476,6 @@ }, []);

}
nodesToRemove.forEach((node) => node.parentElement?.removeChild(node));
nodesToRemove.forEach((node) => {
var _a;
return (_a = node.parentElement) == null ? void 0 : _a.removeChild(node);
});
}

@@ -469,2 +485,3 @@ function removeAllWhitespace(rootNode) {

function collectNodesToRemove(currentNode) {
var _a, _b;
if (isElement(currentNode)) {

@@ -476,3 +493,3 @@ const elm = currentNode;

}
if ((tagName(elm) === "p" || tagName(elm) === "br") && elm?.firstChild?.textContent?.trim() === "") {
if ((tagName(elm) === "p" || tagName(elm) === "br") && ((_b = (_a = elm == null ? void 0 : elm.firstChild) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim()) === "") {
nodesToRemove.push(elm);

@@ -485,7 +502,19 @@ return;

}
collectNodesToRemove(rootNode), nodesToRemove.forEach((node) => node.parentElement?.removeChild(node));
collectNodesToRemove(rootNode), nodesToRemove.forEach((node) => {
var _a;
return (_a = node.parentElement) == null ? void 0 : _a.removeChild(node);
});
}
function isWhitespaceBlock(elm) {
return ["p", "br"].includes(tagName(elm) || "") && !elm.textContent?.trim();
var _a;
return ["p", "br"].includes(tagName(elm) || "") && !((_a = elm.textContent) != null && _a.trim());
}
var __defProp$5 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$4.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
if (__getOwnPropSymbols$4)
for (var prop of __getOwnPropSymbols$4(b))
__propIsEnum$4.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
return a;
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
const LIST_CONTAINER_TAGS = Object.keys(HTML_LIST_CONTAINER_TAGS);

@@ -533,6 +562,3 @@ function isEmphasis$1(el) {

}
const blocks = {
...HTML_BLOCK_TAGS,
...HTML_HEADER_TAGS
};
const blocks = __spreadValues$4(__spreadValues$4({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS);
function getBlockStyle(el, enabledBlockStyles) {

@@ -547,7 +573,6 @@ const childTag = tagName(el.firstChild), block = childTag && blocks[childTag];

if (isElement(el) && tagName(el) === "span" && isGoogleDocs(el)) {
const span = {
...DEFAULT_SPAN,
const span = __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
marks: [],
text: el.textContent
};
});
return isStrong$1(el) && span.marks.push("strong"), isUnderline$1(el) && span.marks.push("underline"), isStrikethrough(el) && span.marks.push("strike-through"), isEmphasis$1(el) && span.marks.push("em"), span;

@@ -559,10 +584,10 @@ }

deserialize(el, next) {
var _a;
if (tagName(el) === "li" && isGoogleDocs(el))
return {
...DEFAULT_BLOCK,
return __spreadProps$4(__spreadValues$4({}, DEFAULT_BLOCK), {
listItem: getListItemStyle$1(el),
level: getListItemLevel$1(el),
style: getBlockStyle(el, options.enabledBlockStyles),
children: next(el.firstChild?.childNodes || [])
};
children: next(((_a = el.firstChild) == null ? void 0 : _a.childNodes) || [])
});
}

@@ -572,17 +597,15 @@ },

deserialize(el) {
var _a;
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && el.classList.contains("apple-interchange-newline"))
return {
...DEFAULT_SPAN,
return __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
text: ""
};
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && el?.parentNode?.textContent === "")
return {
...DEFAULT_SPAN,
});
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && ((_a = el == null ? void 0 : el.parentNode) == null ? void 0 : _a.textContent) === "")
return __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
text: ""
};
});
if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && isRootNode(el))
return {
...DEFAULT_SPAN,
return __spreadProps$4(__spreadValues$4({}, DEFAULT_SPAN), {
text: ""
};
});
}

@@ -602,2 +625,10 @@ }

}
var __defProp$4 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$3.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
if (__getOwnPropSymbols$3)
for (var prop of __getOwnPropSymbols$3(b))
__propIsEnum$3.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
return a;
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
function resolveListItem(listNodeTagName, enabledListTypes) {

@@ -618,7 +649,6 @@ if (listNodeTagName === "ul" && enabledListTypes.includes("bullet"))

if (el.nodeName === "#text" && isValidText)
return {
...DEFAULT_SPAN,
return __spreadProps$3(__spreadValues$3({}, DEFAULT_SPAN), {
marks: [],
text: (el.textContent || "").replace(/\s\s+/g, " ")
};
});
}

@@ -637,7 +667,6 @@ },

children: [
{
...DEFAULT_SPAN,
__spreadProps$3(__spreadValues$3({}, DEFAULT_SPAN), {
marks: isCodeEnabled ? ["code"] : [],
text: el.textContent || ""
}
})
]

@@ -652,6 +681,3 @@ };

return;
const blocks2 = {
...HTML_BLOCK_TAGS,
...HTML_HEADER_TAGS
};
const blocks2 = __spreadValues$3(__spreadValues$3({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS);
delete blocks2.blockquote;

@@ -680,12 +706,8 @@ const children = [];

deserialize(el, next) {
const blocks2 = {
...HTML_BLOCK_TAGS,
...HTML_HEADER_TAGS
}, tag = tagName(el);
const blocks2 = __spreadValues$3(__spreadValues$3({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS), tag = tagName(el);
let block = tag ? blocks2[tag] : void 0;
if (block)
return el.parentNode && tagName(el.parentNode) === "li" ? next(el.childNodes) : (options.enabledBlockStyles.includes(block.style) || (block = DEFAULT_BLOCK), {
...block,
return el.parentNode && tagName(el.parentNode) === "li" ? next(el.childNodes) : (options.enabledBlockStyles.includes(block.style) || (block = DEFAULT_BLOCK), __spreadProps$3(__spreadValues$3({}, block), {
children: next(el.childNodes)
});
}));
}

@@ -720,7 +742,6 @@ },

if (tagName(el) === "br")
return {
...DEFAULT_SPAN,
return __spreadProps$3(__spreadValues$3({}, DEFAULT_SPAN), {
text: `
`
};
});
}

@@ -735,6 +756,5 @@ },

const enabledListItem = resolveListItem(parentTag, options.enabledListTypes);
return enabledListItem ? (listItem.listItem = enabledListItem, {
...listItem,
return enabledListItem ? (listItem.listItem = enabledListItem, __spreadProps$3(__spreadValues$3({}, listItem), {
children: next(el.childNodes)
}) : block({ _type: "block", children: next(el.childNodes) });
})) : block({ _type: "block", children: next(el.childNodes) });
}

@@ -777,2 +797,10 @@ },

}
var __defProp$3 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$2.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
if (__getOwnPropSymbols$2)
for (var prop of __getOwnPropSymbols$2(b))
__propIsEnum$2.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
return a;
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
function isEmphasis(el) {

@@ -793,2 +821,3 @@ const style = isElement(el) && el.getAttribute("style");

}
__spreadValues$2(__spreadValues$2({}, HTML_BLOCK_TAGS), HTML_HEADER_TAGS);
function createNotionRules(_blockContentType) {

@@ -799,7 +828,6 @@ return [

if (isElement(el) && tagName(el) === "span" && isNotion(el)) {
const span = {
...DEFAULT_SPAN,
const span = __spreadProps$2(__spreadValues$2({}, DEFAULT_SPAN), {
marks: [],
text: el.textContent
};
});
return isStrong(el) && span.marks.push("strong"), isUnderline(el) && span.marks.push("underline"), isEmphasis(el) && span.marks.push("em"), span;

@@ -811,2 +839,10 @@ }

}
var __defProp$2 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp$1.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
if (__getOwnPropSymbols$1)
for (var prop of __getOwnPropSymbols$1(b))
__propIsEnum$1.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
return a;
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
function getListItemStyle(el) {

@@ -835,4 +871,3 @@ const style = isElement(el) && el.getAttribute("style");

if (tagName(el) === "p" && isWordListElement(el))
return {
...DEFAULT_BLOCK,
return __spreadProps$1(__spreadValues$1({}, DEFAULT_BLOCK), {
listItem: getListItemStyle(el),

@@ -842,3 +877,3 @@ level: getListItemLevel(el),

children: next(el.childNodes)
};
});
}

@@ -856,7 +891,4 @@ }

}
var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value);
class HtmlDeserializer {
blockContentType;
rules;
parseHtml;
_markDefs = [];
/**

@@ -869,2 +901,95 @@ * Create a new serializer respecting a Sanity block content type's schema

constructor(blockContentType, options = {}) {
__publicField(this, "blockContentType"), __publicField(this, "rules"), __publicField(this, "parseHtml"), __publicField(this, "_markDefs", []), __publicField(this, "deserialize", (html) => {
this._markDefs = [];
const { parseHtml: parseHtml2 } = this, fragment = parseHtml2(html), children = Array.from(fragment.childNodes), blocks2 = trimWhitespace(
flattenNestedBlocks(ensureRootIsBlocks(this.deserializeElements(children)))
);
this._markDefs.length > 0 && blocks2.filter((block) => block._type === "block").forEach((block) => {
block.markDefs = block.markDefs || [], block.markDefs = block.markDefs.concat(
this._markDefs.filter((def) => flatten__default.default(block.children.map((child) => child.marks || [])).includes(def._key))
);
});
const type = this.blockContentType.of.find(findBlockType);
return type ? blocks2.map((block) => (block._type === "block" && (block._type = type.name), block)) : blocks2;
}), __publicField(this, "deserializeElements", (elements = []) => {
let nodes = [];
return elements.forEach((element) => {
nodes = nodes.concat(this.deserializeElement(element));
}), nodes;
}), __publicField(this, "deserializeElement", (element) => {
var _a, _b;
const next = (elements) => {
if (isNodeList(elements))
return this.deserializeElements(Array.from(elements));
if (Array.isArray(elements))
return this.deserializeElements(elements);
if (elements)
return this.deserializeElement(elements);
}, block = (props) => ({
_type: "__block",
block: props
});
let node;
for (let i = 0; i < this.rules.length; i++) {
const rule = this.rules[i];
if (!rule.deserialize)
continue;
const ret = rule.deserialize(element, next, block), type = resolveJsType(ret);
if (type !== "array" && type !== "object" && type !== "null" && type !== "undefined")
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`);
if (ret !== void 0) {
{
if (ret === null)
throw new Error("Deserializer rule returned `null`");
Array.isArray(ret) ? node = ret : isPlaceholderDecorator(ret) ? node = this.deserializeDecorator(ret) : isPlaceholderAnnotation(ret) ? node = this.deserializeAnnotation(ret) : node = ret;
}
if (ret && !Array.isArray(ret) && isMinimalBlock(ret) && "listItem" in ret) {
let parent = (_a = element.parentNode) == null ? void 0 : _a.parentNode;
for (; parent && tagName(parent) === "li"; )
parent = (_b = parent.parentNode) == null ? void 0 : _b.parentNode, ret.level = ret.level ? ret.level + 1 : 1;
}
ret && !Array.isArray(ret) && isMinimalBlock(ret) && ret.style === "blockquote" && ret.children.forEach((child, index) => {
isMinimalSpan(child) && child.text === "\r" && (child.text = `
`, (index === 0 || index === ret.children.length - 1) && ret.children.splice(index, 1));
});
break;
}
}
return node || next(element.childNodes) || [];
}), __publicField(this, "deserializeDecorator", (decorator) => {
const { name } = decorator, applyDecorator = (node) => {
if (isPlaceholderDecorator(node))
return this.deserializeDecorator(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(name);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyDecorator);
}
return node;
};
return decorator.children.reduce((children, node) => {
const ret = applyDecorator(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
}), __publicField(this, "deserializeAnnotation", (annotation) => {
const { markDef } = annotation;
this._markDefs.push(markDef);
const applyAnnotation = (node) => {
if (isPlaceholderAnnotation(node))
return this.deserializeAnnotation(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(markDef._key);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyAnnotation);
}
return node;
};
return annotation.children.reduce((children, node) => {
const ret = applyAnnotation(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
});
const { rules = [], unstable_whitespaceOnPasteMode = "preserve" } = options;

@@ -878,140 +1003,19 @@ if (!blockContentType)

}
/**
* Deserialize HTML.
*
* @param html - The HTML to deserialize, as a string
* @returns Array of blocks - either portable text blocks or other allowed blocks
*/
deserialize = (html) => {
this._markDefs = [];
const { parseHtml } = this, fragment = parseHtml(html), children = Array.from(fragment.childNodes), blocks2 = trimWhitespace(
flattenNestedBlocks(ensureRootIsBlocks(this.deserializeElements(children)))
);
this._markDefs.length > 0 && blocks2.filter((block) => block._type === "block").forEach((block) => {
block.markDefs = block.markDefs || [], block.markDefs = block.markDefs.concat(
this._markDefs.filter((def) => flatten__default.default(block.children.map((child) => child.marks || [])).includes(def._key))
);
});
const type = this.blockContentType.of.find(findBlockType);
return type ? blocks2.map((block) => (block._type === "block" && (block._type = type.name), block)) : blocks2;
};
/**
* Deserialize an array of DOM elements.
*
* @param elements - Array of DOM elements to deserialize
* @returns
*/
deserializeElements = (elements = []) => {
let nodes = [];
return elements.forEach((element) => {
nodes = nodes.concat(this.deserializeElement(element));
}), nodes;
};
/**
* Deserialize a DOM element
*
* @param element - Deserialize a DOM element
* @returns
*/
deserializeElement = (element) => {
const next = (elements) => {
if (isNodeList(elements))
return this.deserializeElements(Array.from(elements));
if (Array.isArray(elements))
return this.deserializeElements(elements);
if (elements)
return this.deserializeElement(elements);
}, block = (props) => ({
_type: "__block",
block: props
});
let node;
for (let i = 0; i < this.rules.length; i++) {
const rule = this.rules[i];
if (!rule.deserialize)
continue;
const ret = rule.deserialize(element, next, block), type = resolveJsType(ret);
if (type !== "array" && type !== "object" && type !== "null" && type !== "undefined")
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`);
if (ret !== void 0) {
{
if (ret === null)
throw new Error("Deserializer rule returned `null`");
Array.isArray(ret) ? node = ret : isPlaceholderDecorator(ret) ? node = this.deserializeDecorator(ret) : isPlaceholderAnnotation(ret) ? node = this.deserializeAnnotation(ret) : node = ret;
}
if (ret && !Array.isArray(ret) && isMinimalBlock(ret) && "listItem" in ret) {
let parent = element.parentNode?.parentNode;
for (; parent && tagName(parent) === "li"; )
parent = parent.parentNode?.parentNode, ret.level = ret.level ? ret.level + 1 : 1;
}
ret && !Array.isArray(ret) && isMinimalBlock(ret) && ret.style === "blockquote" && ret.children.forEach((child, index) => {
isMinimalSpan(child) && child.text === "\r" && (child.text = `
`, (index === 0 || index === ret.children.length - 1) && ret.children.splice(index, 1));
});
break;
}
}
return node || next(element.childNodes) || [];
};
/**
* Deserialize a `__decorator` type
* (an internal made up type to process decorators exclusively)
*
* @param decorator -
* @returns array of ...
*/
deserializeDecorator = (decorator) => {
const { name } = decorator, applyDecorator = (node) => {
if (isPlaceholderDecorator(node))
return this.deserializeDecorator(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(name);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyDecorator);
}
return node;
};
return decorator.children.reduce((children, node) => {
const ret = applyDecorator(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
};
/**
* Deserialize a `__annotation` object.
* (an internal made up type to process annotations exclusively)
*
* @param annotation -
* @returns Array of...
*/
deserializeAnnotation = (annotation) => {
const { markDef } = annotation;
this._markDefs.push(markDef);
const applyAnnotation = (node) => {
if (isPlaceholderAnnotation(node))
return this.deserializeAnnotation(node);
if (isMinimalSpan(node))
node.marks = node.marks || [], node.text.trim() && node.marks.unshift(markDef._key);
else if ("children" in node && Array.isArray(node.children)) {
const block = node;
block.children = block.children.map(applyAnnotation);
}
return node;
};
return annotation.children.reduce((children, node) => {
const ret = applyAnnotation(node);
return Array.isArray(ret) ? children.concat(ret) : (children.push(ret), children);
}, []);
};
}
var __defProp = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b))
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
return a;
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
function normalizeBlock(node, options = {}) {
if (node._type !== (options.blockTypeName || "block"))
return "_key" in node ? node : { ...node, _key: randomKey(12) };
const block = {
return "_key" in node ? node : __spreadProps(__spreadValues({}, node), { _key: randomKey(12) });
const block = __spreadValues({
_key: randomKey(12),
children: [],
markDefs: [],
...node
}, lastChild = block.children[block.children.length - 1];
markDefs: []
}, node), lastChild = block.children[block.children.length - 1];
if (!lastChild)

@@ -1037,3 +1041,4 @@ return block.children = [

return child._key = `${block._key}${index}`, types.isPortableTextSpan(child) && (child.marks ? allowedDecorators && (child.marks = child.marks.filter((mark) => {
const isAllowed = allowedDecorators.includes(mark), isUsed = block.markDefs?.some((def) => def._key === mark);
var _a;
const isAllowed = allowedDecorators.includes(mark), isUsed = (_a = block.markDefs) == null ? void 0 : _a.some((def) => def._key === mark);
return isAllowed || isUsed;

@@ -1040,0 +1045,0 @@ })) : child.marks = [], usedMarkDefs.push(...child.marks)), child;

{
"name": "@sanity/block-tools",
"version": "3.66.2-corel.439+4f2194bd06",
"version": "3.66.2-upgrade-vite-v5.30+0e85ab82a2",
"description": "Can format HTML, Slate JSON or Sanity block array into any other format.",

@@ -52,3 +52,3 @@ "keywords": [

"dependencies": {
"@sanity/types": "3.66.2-corel.439+4f2194bd06",
"@sanity/types": "3.66.2-upgrade-vite-v5.30+0e85ab82a2",
"@types/react": "^18.3.5",

@@ -61,3 +61,3 @@ "get-random-values-esm": "1.0.2",

"@repo/test-config": "3.66.1",
"@sanity/schema": "3.66.2-corel.439+4f2194bd06",
"@sanity/schema": "3.66.2-upgrade-vite-v5.30+0e85ab82a2",
"@types/jsdom": "^20.0.0",

@@ -73,3 +73,3 @@ "@types/lodash": "^4.17.7",

},
"gitHead": "4f2194bd064856db2fdaeeae631d4aacfec2ca07"
"gitHead": "0e85ab82a23bdf5d6607fc463114d9e9547fcb57"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc