@wordpress/block-library
Version:
Block library for the WordPress editor.
144 lines (136 loc) • 3.26 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convertToListItems = convertToListItems;
exports.createListItem = createListItem;
var _blocks = require("@wordpress/blocks");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const {
name: listItemName
} = {
$schema: "https://schemas.wp.org/trunk/block.json",
apiVersion: 2,
name: "core/list-item",
title: "List item",
category: "text",
parent: ["core/list"],
description: "Create a list item.",
textdomain: "default",
attributes: {
placeholder: {
type: "string"
},
content: {
type: "string",
source: "html",
selector: "li",
"default": "",
__experimentalRole: "content"
}
},
supports: {
className: false,
__experimentalSelector: "li"
}
};
const {
name: listName
} = {
$schema: "https://schemas.wp.org/trunk/block.json",
apiVersion: 2,
name: "core/list",
title: "List",
category: "text",
description: "Create a bulleted or numbered list.",
keywords: ["bullet list", "ordered list", "numbered list"],
textdomain: "default",
attributes: {
ordered: {
type: "boolean",
"default": false,
__experimentalRole: "content"
},
values: {
type: "string",
source: "html",
selector: "ol,ul",
multiline: "li",
__unstableMultilineWrapperTags: ["ol", "ul"],
"default": "",
__experimentalRole: "content"
},
type: {
type: "string"
},
start: {
type: "number"
},
reversed: {
type: "boolean"
},
placeholder: {
type: "string"
}
},
supports: {
anchor: true,
className: false,
typography: {
fontSize: true,
lineHeight: true,
__experimentalFontFamily: true,
__experimentalFontWeight: true,
__experimentalFontStyle: true,
__experimentalTextTransform: true,
__experimentalTextDecoration: true,
__experimentalLetterSpacing: true,
__experimentalDefaultControls: {
fontSize: true
}
},
color: {
gradients: true,
link: true,
__experimentalDefaultControls: {
background: true,
text: true
}
},
spacing: {
margin: true,
padding: true
},
__unstablePasteTextInline: true,
__experimentalSelector: "ol,ul",
__experimentalSlashInserter: true
},
editorStyle: "wp-block-list-editor",
style: "wp-block-list"
};
function createListItem(listItemAttributes, listAttributes, children) {
return (0, _blocks.createBlock)(listItemName, listItemAttributes, !(children !== null && children !== void 0 && children.length) ? [] : [(0, _blocks.createBlock)(listName, listAttributes, children)]);
}
function convertToListItems(blocks) {
const listItems = [];
for (let block of blocks) {
if (block.name === listItemName) {
listItems.push(block);
} else if (block.name === listName) {
listItems.push(...block.innerBlocks);
} else if (block = (0, _blocks.switchToBlockType)(block, listName)) {
for (const {
innerBlocks
} of block) {
listItems.push(...innerBlocks);
}
}
}
return listItems;
}
//# sourceMappingURL=utils.js.map