@wordpress/blocks
Version:
Block API for WordPress.
76 lines (74 loc) • 2.4 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/blocks/src/api/matchers.js
var matchers_exports = {};
__export(matchers_exports, {
attr: () => import_hpq.attr,
children: () => import_children.matcher,
html: () => html,
node: () => import_node.matcher,
prop: () => import_hpq.prop,
query: () => import_hpq.query,
richText: () => richText,
text: () => import_hpq.text
});
module.exports = __toCommonJS(matchers_exports);
var import_hpq = require("hpq");
var import_rich_text = require("@wordpress/rich-text");
var import_node = require("./node");
var import_children = require("./children");
function html(selector, multilineTag) {
return (domNode) => {
let match = domNode;
if (selector) {
match = domNode.querySelector(selector);
}
if (!match) {
return "";
}
if (multilineTag) {
let value = "";
const length = match.children.length;
for (let index = 0; index < length; index++) {
const child = match.children[index];
if (child.nodeName.toLowerCase() !== multilineTag) {
continue;
}
value += child.outerHTML;
}
return value;
}
return match.innerHTML;
};
}
var richText = (selector, preserveWhiteSpace) => (el) => {
const target = selector ? el.querySelector(selector) : el;
return target ? import_rich_text.RichTextData.fromHTMLElement(target, { preserveWhiteSpace }) : import_rich_text.RichTextData.empty();
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
attr,
children,
html,
node,
prop,
query,
richText,
text
});
//# sourceMappingURL=matchers.js.map