@wordpress/block-library 7.10.0 → 7.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/button/edit.js +2 -1
- package/build/button/edit.js.map +1 -1
- package/build/buttons/edit.js +1 -1
- package/build/buttons/edit.js.map +1 -1
- package/build/columns/edit.native.js +1 -1
- package/build/columns/edit.native.js.map +1 -1
- package/build/comments/edit/comments-legacy.js +73 -0
- package/build/comments/edit/comments-legacy.js.map +1 -0
- package/build/comments/{edit.js → edit/index.js} +17 -38
- package/build/comments/edit/index.js.map +1 -0
- package/build/comments/edit/placeholder.js +117 -0
- package/build/comments/edit/placeholder.js.map +1 -0
- package/build/comments/edit/template.js +39 -0
- package/build/comments/edit/template.js.map +1 -0
- package/build/comments/index.js +6 -1
- package/build/comments/index.js.map +1 -1
- package/build/comments/save.js +12 -4
- package/build/comments/save.js.map +1 -1
- package/build/cover/transforms.js +3 -2
- package/build/cover/transforms.js.map +1 -1
- package/build/embed/embed-placeholder.native.js +1 -3
- package/build/embed/embed-placeholder.native.js.map +1 -1
- package/build/gallery/edit.js +2 -2
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/use-get-media.native.js +59 -0
- package/build/gallery/use-get-media.native.js.map +1 -0
- package/build/group/index.js +1 -0
- package/build/group/index.js.map +1 -1
- package/build/group/variations.js +1 -1
- package/build/group/variations.js.map +1 -1
- package/build/image/deprecated.js +77 -9
- package/build/image/deprecated.js.map +1 -1
- package/build/image/edit.js +3 -1
- package/build/image/edit.js.map +1 -1
- package/build/image/edit.native.js +18 -8
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +27 -20
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +7 -1
- package/build/image/index.js.map +1 -1
- package/build/image/save.js +8 -2
- package/build/image/save.js.map +1 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/index.native.js +3 -13
- package/build/index.native.js.map +1 -1
- package/build/list/transforms.js +4 -63
- package/build/list/transforms.js.map +1 -1
- package/build/list/v2/transforms.js +0 -27
- package/build/list/v2/transforms.js.map +1 -1
- package/build/list-item/edit.js +14 -9
- package/build/list-item/edit.js.map +1 -1
- package/build/list-item/hooks/index.js +8 -8
- package/build/list-item/hooks/index.js.map +1 -1
- package/build/list-item/hooks/use-merge.js +174 -0
- package/build/list-item/hooks/use-merge.js.map +1 -0
- package/build/list-item/hooks/use-outdent-list-item.js +86 -50
- package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
- package/build/list-item/utils.js +125 -1
- package/build/list-item/utils.js.map +1 -1
- package/build/media-text/deprecated.js +134 -7
- package/build/media-text/deprecated.js.map +1 -1
- package/build/media-text/edit.js +2 -2
- package/build/media-text/edit.js.map +1 -1
- package/build/media-text/save.js +13 -0
- package/build/media-text/save.js.map +1 -1
- package/build/more/save.js +1 -7
- package/build/more/save.js.map +1 -1
- package/build/navigation-link/edit.js +5 -4
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-submenu/edit.js +2 -1
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/page-list/edit.js +8 -1
- package/build/page-list/edit.js.map +1 -1
- package/build/paragraph/edit.js +7 -11
- package/build/paragraph/edit.js.map +1 -1
- package/build/post-comments-form/edit.js +4 -45
- package/build/post-comments-form/edit.js.map +1 -1
- package/build/post-comments-form/form.js +47 -3
- package/build/post-comments-form/form.js.map +1 -1
- package/build/post-terms/edit.js +3 -2
- package/build/post-terms/edit.js.map +1 -1
- package/build/query-no-results/edit.js +1 -1
- package/build/query-no-results/edit.js.map +1 -1
- package/build/query-pagination-next/edit.js +2 -1
- package/build/query-pagination-next/edit.js.map +1 -1
- package/build/query-pagination-previous/edit.js +2 -1
- package/build/query-pagination-previous/edit.js.map +1 -1
- package/build/quote/deprecated.js +168 -36
- package/build/quote/deprecated.js.map +1 -1
- package/build/quote/edit.js +76 -39
- package/build/quote/edit.js.map +1 -1
- package/build/quote/index.js +9 -45
- package/build/quote/index.js.map +1 -1
- package/build/quote/save.js +1 -5
- package/build/quote/save.js.map +1 -1
- package/build/quote/transforms.js +110 -158
- package/build/quote/transforms.js.map +1 -1
- package/build/social-link/icons/index.js +13 -0
- package/build/social-link/icons/index.js.map +1 -1
- package/build/social-link/icons/whatsapp.js +25 -0
- package/build/social-link/icons/whatsapp.js.map +1 -0
- package/build/social-link/variations.js +7 -0
- package/build/social-link/variations.js.map +1 -1
- package/build/template-part/edit/index.js +17 -8
- package/build/template-part/edit/index.js.map +1 -1
- package/build/template-part/edit/selection-modal.js +33 -13
- package/build/template-part/edit/selection-modal.js.map +1 -1
- package/build/template-part/edit/utils/search.js +94 -0
- package/build/template-part/edit/utils/search.js.map +1 -0
- package/build-module/button/edit.js +2 -1
- package/build-module/button/edit.js.map +1 -1
- package/build-module/buttons/edit.js +2 -2
- package/build-module/buttons/edit.js.map +1 -1
- package/build-module/columns/edit.native.js +2 -2
- package/build-module/columns/edit.native.js.map +1 -1
- package/build-module/comments/edit/comments-legacy.js +59 -0
- package/build-module/comments/edit/comments-legacy.js.map +1 -0
- package/build-module/comments/edit/index.js +37 -0
- package/build-module/comments/edit/index.js.map +1 -0
- package/build-module/comments/edit/placeholder.js +102 -0
- package/build-module/comments/edit/placeholder.js.map +1 -0
- package/build-module/comments/edit/template.js +32 -0
- package/build-module/comments/edit/template.js.map +1 -0
- package/build-module/comments/index.js +6 -1
- package/build-module/comments/index.js.map +1 -1
- package/build-module/comments/save.js +9 -4
- package/build-module/comments/save.js.map +1 -1
- package/build-module/cover/transforms.js +3 -2
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/embed/embed-placeholder.native.js +1 -2
- package/build-module/embed/embed-placeholder.native.js.map +1 -1
- package/build-module/gallery/edit.js +2 -2
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/use-get-media.native.js +50 -0
- package/build-module/gallery/use-get-media.native.js.map +1 -0
- package/build-module/group/index.js +1 -0
- package/build-module/group/index.js.map +1 -1
- package/build-module/group/variations.js +2 -2
- package/build-module/group/variations.js.map +1 -1
- package/build-module/image/deprecated.js +77 -9
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/edit.js +5 -3
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/edit.native.js +18 -8
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +29 -22
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +7 -1
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/save.js +9 -3
- package/build-module/image/save.js.map +1 -1
- package/build-module/index.js +1 -2
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +3 -13
- package/build-module/index.native.js.map +1 -1
- package/build-module/list/transforms.js +4 -63
- package/build-module/list/transforms.js.map +1 -1
- package/build-module/list/v2/transforms.js +2 -29
- package/build-module/list/v2/transforms.js.map +1 -1
- package/build-module/list-item/edit.js +14 -10
- package/build-module/list-item/edit.js.map +1 -1
- package/build-module/list-item/hooks/index.js +1 -1
- package/build-module/list-item/hooks/index.js.map +1 -1
- package/build-module/list-item/hooks/use-merge.js +160 -0
- package/build-module/list-item/hooks/use-merge.js.map +1 -0
- package/build-module/list-item/hooks/use-outdent-list-item.js +82 -46
- package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
- package/build-module/list-item/utils.js +123 -2
- package/build-module/list-item/utils.js.map +1 -1
- package/build-module/media-text/deprecated.js +134 -8
- package/build-module/media-text/deprecated.js.map +1 -1
- package/build-module/media-text/edit.js +2 -2
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/media-text/save.js +13 -0
- package/build-module/media-text/save.js.map +1 -1
- package/build-module/more/save.js +1 -6
- package/build-module/more/save.js.map +1 -1
- package/build-module/navigation-link/edit.js +5 -4
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +2 -1
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/page-list/edit.js +8 -1
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/paragraph/edit.js +8 -12
- package/build-module/paragraph/edit.js.map +1 -1
- package/build-module/post-comments-form/edit.js +5 -42
- package/build-module/post-comments-form/edit.js.map +1 -1
- package/build-module/post-comments-form/form.js +46 -5
- package/build-module/post-comments-form/form.js.map +1 -1
- package/build-module/post-terms/edit.js +3 -2
- package/build-module/post-terms/edit.js.map +1 -1
- package/build-module/query-no-results/edit.js +2 -2
- package/build-module/query-no-results/edit.js.map +1 -1
- package/build-module/query-pagination-next/edit.js +2 -1
- package/build-module/query-pagination-next/edit.js.map +1 -1
- package/build-module/query-pagination-previous/edit.js +2 -1
- package/build-module/query-pagination-previous/edit.js.map +1 -1
- package/build-module/quote/deprecated.js +162 -36
- package/build-module/quote/deprecated.js.map +1 -1
- package/build-module/quote/edit.js +77 -43
- package/build-module/quote/edit.js.map +1 -1
- package/build-module/quote/index.js +9 -39
- package/build-module/quote/index.js.map +1 -1
- package/build-module/quote/save.js +4 -8
- package/build-module/quote/save.js.map +1 -1
- package/build-module/quote/transforms.js +111 -158
- package/build-module/quote/transforms.js.map +1 -1
- package/build-module/social-link/icons/index.js +1 -0
- package/build-module/social-link/icons/index.js.map +1 -1
- package/build-module/social-link/icons/whatsapp.js +15 -0
- package/build-module/social-link/icons/whatsapp.js.map +1 -0
- package/build-module/social-link/variations.js +8 -1
- package/build-module/social-link/variations.js.map +1 -1
- package/build-module/template-part/edit/index.js +20 -11
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/template-part/edit/selection-modal.js +33 -15
- package/build-module/template-part/edit/selection-modal.js.map +1 -1
- package/build-module/template-part/edit/utils/search.js +84 -0
- package/build-module/template-part/edit/utils/search.js.map +1 -0
- package/build-style/button/style-rtl.css +1 -1
- package/build-style/button/style.css +1 -1
- package/build-style/comments/editor-rtl.css +122 -0
- package/build-style/comments/editor.css +122 -0
- package/build-style/{post-comments → comments}/style-rtl.css +1 -0
- package/build-style/{post-comments → comments}/style.css +1 -0
- package/build-style/common-rtl.css +7 -0
- package/build-style/common.css +7 -0
- package/build-style/cover/style-rtl.css +2 -2
- package/build-style/cover/style.css +2 -2
- package/build-style/{post-comments/editor.css → editor-elements-rtl.css} +8 -2
- package/build-style/{post-comments/editor-rtl.css → editor-elements.css} +8 -2
- package/build-style/editor-rtl.css +151 -10
- package/build-style/editor.css +151 -10
- package/build-style/gallery/style-rtl.css +7 -2
- package/build-style/gallery/style.css +7 -2
- package/build-style/image/editor-rtl.css +4 -3
- package/build-style/image/editor.css +4 -3
- package/build-style/image/style-rtl.css +33 -3
- package/build-style/image/style.css +33 -3
- package/build-style/post-comments-form/style-rtl.css +0 -1
- package/build-style/post-comments-form/style.css +0 -1
- package/build-style/social-link/editor-rtl.css +1 -0
- package/build-style/social-link/editor.css +1 -0
- package/build-style/social-links/style-rtl.css +8 -0
- package/build-style/social-links/style.css +8 -0
- package/build-style/style-rtl.css +170 -127
- package/build-style/style.css +170 -127
- package/build-style/template-part/editor-rtl.css +14 -3
- package/build-style/template-part/editor.css +14 -3
- package/package.json +28 -28
- package/src/button/edit.js +1 -0
- package/src/button/style.scss +3 -1
- package/src/buttons/edit.js +1 -5
- package/src/columns/edit.native.js +2 -2
- package/src/comments/block.json +6 -1
- package/src/comments/edit/comments-legacy.js +71 -0
- package/src/comments/edit/index.js +35 -0
- package/src/comments/edit/placeholder.js +124 -0
- package/src/comments/{edit.js → edit/template.js} +1 -28
- package/src/comments/editor.scss +9 -0
- package/src/comments/index.php +219 -0
- package/src/comments/save.js +8 -7
- package/src/{post-comments → comments}/style.scss +7 -0
- package/src/common.scss +2 -0
- package/src/cover/style.scss +2 -2
- package/src/cover/transforms.js +2 -2
- package/src/editor-elements.scss +10 -0
- package/src/editor.scss +2 -1
- package/src/embed/embed-placeholder.native.js +2 -3
- package/src/gallery/edit.js +4 -2
- package/src/gallery/style.scss +10 -1
- package/src/gallery/use-get-media.native.js +44 -0
- package/src/group/block.json +1 -0
- package/src/group/variations.js +2 -2
- package/src/image/block.json +7 -1
- package/src/image/deprecated.js +86 -0
- package/src/image/edit.js +6 -1
- package/src/image/edit.native.js +18 -7
- package/src/image/editor.scss +9 -4
- package/src/image/image.js +26 -16
- package/src/image/save.js +10 -1
- package/src/image/style.scss +39 -3
- package/src/index.js +0 -2
- package/src/index.native.js +2 -11
- package/src/list/transforms.js +0 -47
- package/src/list/v2/transforms.js +2 -40
- package/src/list-item/edit.js +10 -12
- package/src/list-item/hooks/index.js +1 -1
- package/src/list-item/hooks/use-merge.js +141 -0
- package/src/list-item/hooks/use-outdent-list-item.js +72 -74
- package/src/list-item/utils.js +27 -3
- package/src/media-text/deprecated.js +148 -1
- package/src/media-text/edit.js +2 -1
- package/src/media-text/save.js +18 -0
- package/src/more/save.js +3 -6
- package/src/navigation-link/edit.js +4 -3
- package/src/navigation-submenu/edit.js +1 -0
- package/src/page-list/edit.js +9 -0
- package/src/paragraph/edit.js +8 -14
- package/src/post-comments-form/edit.js +2 -71
- package/src/post-comments-form/form.js +80 -5
- package/src/post-comments-form/index.php +1 -1
- package/src/post-comments-form/style.scss +0 -1
- package/src/post-terms/edit.js +3 -2
- package/src/query-no-results/edit.js +2 -5
- package/src/query-pagination-next/edit.js +1 -0
- package/src/query-pagination-previous/edit.js +1 -0
- package/src/quote/deprecated.js +213 -99
- package/src/quote/edit.js +77 -52
- package/src/quote/index.js +10 -33
- package/src/quote/save.js +5 -5
- package/src/quote/{v2/test → test}/migrate.js +2 -7
- package/src/quote/transforms.js +117 -147
- package/src/social-link/editor.scss +3 -0
- package/src/social-link/icons/index.js +1 -0
- package/src/social-link/icons/whatsapp.js +10 -0
- package/src/social-link/index.php +4 -0
- package/src/social-link/socials-with-bg.scss +5 -0
- package/src/social-link/socials-without-bg.scss +5 -0
- package/src/social-link/variations.js +7 -0
- package/src/style.scss +1 -2
- package/src/template-part/edit/index.js +37 -24
- package/src/template-part/edit/selection-modal.js +68 -40
- package/src/template-part/edit/utils/search.js +76 -0
- package/src/template-part/editor.scss +21 -9
- package/src/template-part/index.php +56 -2
- package/build/comments/edit.js.map +0 -1
- package/build/list-item/hooks/use-backspace.js +0 -59
- package/build/list-item/hooks/use-backspace.js.map +0 -1
- package/build/post-comments/edit.js +0 -184
- package/build/post-comments/edit.js.map +0 -1
- package/build/post-comments/index.js +0 -72
- package/build/post-comments/index.js.map +0 -1
- package/build/quote/v2/deprecated.js +0 -133
- package/build/quote/v2/deprecated.js.map +0 -1
- package/build/quote/v2/edit.js +0 -139
- package/build/quote/v2/edit.js.map +0 -1
- package/build/quote/v2/index.js +0 -49
- package/build/quote/v2/index.js.map +0 -1
- package/build/quote/v2/save.js +0 -43
- package/build/quote/v2/save.js.map +0 -1
- package/build/quote/v2/transforms.js +0 -156
- package/build/quote/v2/transforms.js.map +0 -1
- package/build-module/comments/edit.js +0 -59
- package/build-module/comments/edit.js.map +0 -1
- package/build-module/list-item/hooks/use-backspace.js +0 -44
- package/build-module/list-item/hooks/use-backspace.js.map +0 -1
- package/build-module/post-comments/edit.js +0 -171
- package/build-module/post-comments/edit.js.map +0 -1
- package/build-module/post-comments/index.js +0 -59
- package/build-module/post-comments/index.js.map +0 -1
- package/build-module/quote/v2/deprecated.js +0 -116
- package/build-module/quote/v2/deprecated.js.map +0 -1
- package/build-module/quote/v2/edit.js +0 -122
- package/build-module/quote/v2/edit.js.map +0 -1
- package/build-module/quote/v2/index.js +0 -33
- package/build-module/quote/v2/index.js.map +0 -1
- package/build-module/quote/v2/save.js +0 -30
- package/build-module/quote/v2/save.js.map +0 -1
- package/build-module/quote/v2/transforms.js +0 -147
- package/build-module/quote/v2/transforms.js.map +0 -1
- package/src/list-item/hooks/use-backspace.js +0 -51
- package/src/post-comments/block.json +0 -45
- package/src/post-comments/edit.js +0 -247
- package/src/post-comments/editor.scss +0 -3
- package/src/post-comments/index.js +0 -18
- package/src/post-comments/index.php +0 -87
- package/src/quote/v2/deprecated.js +0 -107
- package/src/quote/v2/edit.js +0 -139
- package/src/quote/v2/index.js +0 -36
- package/src/quote/v2/save.js +0 -26
- package/src/quote/v2/transforms.js +0 -155
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = useMerge;
|
|
9
|
+
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
|
|
12
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
13
|
+
|
|
14
|
+
var _blocks = require("@wordpress/blocks");
|
|
15
|
+
|
|
16
|
+
var _useOutdentListItem = _interopRequireDefault(require("./use-outdent-list-item"));
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* WordPress dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
const {
|
|
26
|
+
name: listItemName
|
|
27
|
+
} = {
|
|
28
|
+
$schema: "https://schemas.wp.org/trunk/block.json",
|
|
29
|
+
apiVersion: 2,
|
|
30
|
+
__experimental: "list-v2",
|
|
31
|
+
name: "core/list-item",
|
|
32
|
+
title: "List item",
|
|
33
|
+
category: "text",
|
|
34
|
+
parent: ["core/list"],
|
|
35
|
+
description: "Create a list item.",
|
|
36
|
+
textdomain: "default",
|
|
37
|
+
attributes: {
|
|
38
|
+
placeholder: {
|
|
39
|
+
type: "string"
|
|
40
|
+
},
|
|
41
|
+
content: {
|
|
42
|
+
type: "string",
|
|
43
|
+
source: "html",
|
|
44
|
+
selector: "li",
|
|
45
|
+
"default": "",
|
|
46
|
+
__experimentalRole: "content"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
supports: {
|
|
50
|
+
className: false,
|
|
51
|
+
__experimentalSelector: "li"
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function useMerge(clientId) {
|
|
56
|
+
const registry = (0, _data.useRegistry)();
|
|
57
|
+
const {
|
|
58
|
+
getPreviousBlockClientId,
|
|
59
|
+
getNextBlockClientId,
|
|
60
|
+
getBlockOrder,
|
|
61
|
+
getBlockRootClientId,
|
|
62
|
+
getBlockName,
|
|
63
|
+
getBlock
|
|
64
|
+
} = (0, _data.useSelect)(_blockEditor.store);
|
|
65
|
+
const {
|
|
66
|
+
mergeBlocks,
|
|
67
|
+
moveBlocksToPosition,
|
|
68
|
+
replaceBlock,
|
|
69
|
+
selectBlock
|
|
70
|
+
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
71
|
+
const [, outdentListItem] = (0, _useOutdentListItem.default)(clientId);
|
|
72
|
+
|
|
73
|
+
function getTrailingId(id) {
|
|
74
|
+
const order = getBlockOrder(id);
|
|
75
|
+
|
|
76
|
+
if (!order.length) {
|
|
77
|
+
return id;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return getTrailingId(order[order.length - 1]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getParentListItemId(id) {
|
|
84
|
+
const listId = getBlockRootClientId(id);
|
|
85
|
+
const parentListItemId = getBlockRootClientId(listId);
|
|
86
|
+
if (!parentListItemId) return;
|
|
87
|
+
if (getBlockName(parentListItemId) !== listItemName) return;
|
|
88
|
+
return parentListItemId;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Return the next list item with respect to the given list item. If none,
|
|
92
|
+
* return the next list item of the parent list item if it exists.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} id A list item client ID.
|
|
95
|
+
* @return {string?} The client ID of the next list item.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
function _getNextId(id) {
|
|
100
|
+
const next = getNextBlockClientId(id);
|
|
101
|
+
if (next) return next;
|
|
102
|
+
const parentListItemId = getParentListItemId(id);
|
|
103
|
+
if (!parentListItemId) return;
|
|
104
|
+
return _getNextId(parentListItemId);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Given a client ID, return the client ID of the list item on the next
|
|
108
|
+
* line, regardless of indentation level.
|
|
109
|
+
*
|
|
110
|
+
* @param {string} id The client ID of the current list item.
|
|
111
|
+
* @return {string?} The client ID of the next list item.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
function getNextId(id) {
|
|
116
|
+
const order = getBlockOrder(id); // If the list item does not have a nested list, return the next list
|
|
117
|
+
// item.
|
|
118
|
+
|
|
119
|
+
if (!order.length) {
|
|
120
|
+
return _getNextId(id);
|
|
121
|
+
} // Get the first list item in the nested list.
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
return getBlockOrder(order[0])[0];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function switchToDefaultBlockType(forward) {
|
|
128
|
+
const rootClientId = getBlockRootClientId(clientId);
|
|
129
|
+
const replacement = (0, _blocks.switchToBlockType)(getBlock(rootClientId), (0, _blocks.getDefaultBlockName)());
|
|
130
|
+
const indexToSelect = forward ? replacement.length - 1 : 0;
|
|
131
|
+
const initialPosition = forward ? -1 : 0;
|
|
132
|
+
registry.batch(() => {
|
|
133
|
+
replaceBlock(rootClientId, replacement);
|
|
134
|
+
selectBlock(replacement[indexToSelect].clientId, initialPosition);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return forward => {
|
|
139
|
+
if (forward) {
|
|
140
|
+
const nextBlockClientId = getNextId(clientId);
|
|
141
|
+
|
|
142
|
+
if (!nextBlockClientId) {
|
|
143
|
+
switchToDefaultBlockType(forward);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (getParentListItemId(nextBlockClientId)) {
|
|
148
|
+
outdentListItem(nextBlockClientId);
|
|
149
|
+
} else {
|
|
150
|
+
registry.batch(() => {
|
|
151
|
+
moveBlocksToPosition(getBlockOrder(nextBlockClientId), nextBlockClientId, getPreviousBlockClientId(nextBlockClientId));
|
|
152
|
+
mergeBlocks(clientId, nextBlockClientId);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
// Merging is only done from the top level. For lowel levels, the
|
|
157
|
+
// list item is outdented instead.
|
|
158
|
+
const previousBlockClientId = getPreviousBlockClientId(clientId);
|
|
159
|
+
|
|
160
|
+
if (getParentListItemId(clientId)) {
|
|
161
|
+
outdentListItem(clientId);
|
|
162
|
+
} else if (previousBlockClientId) {
|
|
163
|
+
const trailingId = getTrailingId(previousBlockClientId);
|
|
164
|
+
registry.batch(() => {
|
|
165
|
+
moveBlocksToPosition(getBlockOrder(clientId), clientId, previousBlockClientId);
|
|
166
|
+
mergeBlocks(trailingId, clientId);
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
switchToDefaultBlockType(forward);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=use-merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/list-item/hooks/use-merge.js"],"names":["useMerge","clientId","registry","getPreviousBlockClientId","getNextBlockClientId","getBlockOrder","getBlockRootClientId","getBlockName","getBlock","blockEditorStore","mergeBlocks","moveBlocksToPosition","replaceBlock","selectBlock","outdentListItem","getTrailingId","id","order","length","getParentListItemId","listId","parentListItemId","listItemName","_getNextId","next","getNextId","switchToDefaultBlockType","forward","rootClientId","replacement","indexToSelect","initialPosition","batch","nextBlockClientId","previousBlockClientId","trailingId"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKe,SAASA,QAAT,CAAmBC,QAAnB,EAA8B;AAC5C,QAAMC,QAAQ,GAAG,wBAAjB;AACA,QAAM;AACLC,IAAAA,wBADK;AAELC,IAAAA,oBAFK;AAGLC,IAAAA,aAHK;AAILC,IAAAA,oBAJK;AAKLC,IAAAA,YALK;AAMLC,IAAAA;AAN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AX;AACA,SAPD;AAQA;AACD,KApBD,MAoBO;AACN;AACA;AACA,YAAMC,qBAAqB,GAAG/B,wBAAwB,CAAEF,QAAF,CAAtD;;AACA,UAAKkB,mBAAmB,CAAElB,QAAF,CAAxB,EAAuC;AACtCa,QAAAA,eAAe,CAAEb,QAAF,CAAf;AACA,OAFD,MAEO,IAAKiC,qBAAL,EAA6B;AACnC,cAAMC,UAAU,GAAGpB,aAAa,CAAEmB,qBAAF,CAAhC;AACAhC,QAAAA,QAAQ,CAAC8B,KAAT,CAAgB,MAAM;AACrBrB,UAAAA,oBAAoB,CACnBN,aAAa,CAAEJ,QAAF,CADM,EAEnBA,QAFmB,EAGnBiC,qBAHmB,CAApB;AAKAxB,UAAAA,WAAW,CAAEyB,UAAF,EAAclC,QAAd,CAAX;AACA,SAPD;AAQA,OAVM,MAUA;AACNyB,QAAAA,wBAAwB,CAAEC,OAAF,CAAxB;AACA;AACD;AACD,GAzCD;AA0CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRegistry, useDispatch, useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { getDefaultBlockName, switchToBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOutdentListItem from './use-outdent-list-item';\n\nimport { name as listItemName } from '../block.json';\n\nexport default function useMerge( clientId ) {\n\tconst registry = useRegistry();\n\tconst {\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetBlockOrder,\n\t\tgetBlockRootClientId,\n\t\tgetBlockName,\n\t\tgetBlock,\n\t} = useSelect( blockEditorStore );\n\tconst { mergeBlocks, moveBlocksToPosition, replaceBlock, selectBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst [ , outdentListItem ] = useOutdentListItem( clientId );\n\n\tfunction getTrailingId( id ) {\n\t\tconst order = getBlockOrder( id );\n\n\t\tif ( ! order.length ) {\n\t\t\treturn id;\n\t\t}\n\n\t\treturn getTrailingId( order[ order.length - 1 ] );\n\t}\n\n\tfunction getParentListItemId( id ) {\n\t\tconst listId = getBlockRootClientId( id );\n\t\tconst parentListItemId = getBlockRootClientId( listId );\n\t\tif ( ! parentListItemId ) return;\n\t\tif ( getBlockName( parentListItemId ) !== listItemName ) return;\n\t\treturn parentListItemId;\n\t}\n\n\t/**\n\t * Return the next list item with respect to the given list item. If none,\n\t * return the next list item of the parent list item if it exists.\n\t *\n\t * @param {string} id A list item client ID.\n\t * @return {string?} The client ID of the next list item.\n\t */\n\tfunction _getNextId( id ) {\n\t\tconst next = getNextBlockClientId( id );\n\t\tif ( next ) return next;\n\t\tconst parentListItemId = getParentListItemId( id );\n\t\tif ( ! parentListItemId ) return;\n\t\treturn _getNextId( parentListItemId );\n\t}\n\n\t/**\n\t * Given a client ID, return the client ID of the list item on the next\n\t * line, regardless of indentation level.\n\t *\n\t * @param {string} id The client ID of the current list item.\n\t * @return {string?} The client ID of the next list item.\n\t */\n\tfunction getNextId( id ) {\n\t\tconst order = getBlockOrder( id );\n\n\t\t// If the list item does not have a nested list, return the next list\n\t\t// item.\n\t\tif ( ! order.length ) {\n\t\t\treturn _getNextId( id );\n\t\t}\n\n\t\t// Get the first list item in the nested list.\n\t\treturn getBlockOrder( order[ 0 ] )[ 0 ];\n\t}\n\n\tfunction switchToDefaultBlockType( forward ) {\n\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\tconst replacement = switchToBlockType(\n\t\t\tgetBlock( rootClientId ),\n\t\t\tgetDefaultBlockName()\n\t\t);\n\t\tconst indexToSelect = forward ? replacement.length - 1 : 0;\n\t\tconst initialPosition = forward ? -1 : 0;\n\t\tregistry.batch( () => {\n\t\t\treplaceBlock( rootClientId, replacement );\n\t\t\tselectBlock(\n\t\t\t\treplacement[ indexToSelect ].clientId,\n\t\t\t\tinitialPosition\n\t\t\t);\n\t\t} );\n\t}\n\n\treturn ( forward ) => {\n\t\tif ( forward ) {\n\t\t\tconst nextBlockClientId = getNextId( clientId );\n\n\t\t\tif ( ! nextBlockClientId ) {\n\t\t\t\tswitchToDefaultBlockType( forward );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( getParentListItemId( nextBlockClientId ) ) {\n\t\t\t\toutdentListItem( nextBlockClientId );\n\t\t\t} else {\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\tgetBlockOrder( nextBlockClientId ),\n\t\t\t\t\t\tnextBlockClientId,\n\t\t\t\t\t\tgetPreviousBlockClientId( nextBlockClientId )\n\t\t\t\t\t);\n\t\t\t\t\tmergeBlocks( clientId, nextBlockClientId );\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\t// Merging is only done from the top level. For lowel levels, the\n\t\t\t// list item is outdented instead.\n\t\t\tconst previousBlockClientId = getPreviousBlockClientId( clientId );\n\t\t\tif ( getParentListItemId( clientId ) ) {\n\t\t\t\toutdentListItem( clientId );\n\t\t\t} else if ( previousBlockClientId ) {\n\t\t\t\tconst trailingId = getTrailingId( previousBlockClientId );\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\tgetBlockOrder( clientId ),\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tpreviousBlockClientId\n\t\t\t\t\t);\n\t\t\t\t\tmergeBlocks( trailingId, clientId );\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tswitchToDefaultBlockType( forward );\n\t\t\t}\n\t\t}\n\t};\n}\n"]}
|
|
@@ -15,8 +15,6 @@ var _blockEditor = require("@wordpress/block-editor");
|
|
|
15
15
|
|
|
16
16
|
var _blocks = require("@wordpress/blocks");
|
|
17
17
|
|
|
18
|
-
var _utils = require("../utils");
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* External dependencies
|
|
22
20
|
*/
|
|
@@ -28,7 +26,38 @@ var _utils = require("../utils");
|
|
|
28
26
|
/**
|
|
29
27
|
* Internal dependencies
|
|
30
28
|
*/
|
|
29
|
+
const {
|
|
30
|
+
name: listItemName
|
|
31
|
+
} = {
|
|
32
|
+
$schema: "https://schemas.wp.org/trunk/block.json",
|
|
33
|
+
apiVersion: 2,
|
|
34
|
+
__experimental: "list-v2",
|
|
35
|
+
name: "core/list-item",
|
|
36
|
+
title: "List item",
|
|
37
|
+
category: "text",
|
|
38
|
+
parent: ["core/list"],
|
|
39
|
+
description: "Create a list item.",
|
|
40
|
+
textdomain: "default",
|
|
41
|
+
attributes: {
|
|
42
|
+
placeholder: {
|
|
43
|
+
type: "string"
|
|
44
|
+
},
|
|
45
|
+
content: {
|
|
46
|
+
type: "string",
|
|
47
|
+
source: "html",
|
|
48
|
+
selector: "li",
|
|
49
|
+
"default": "",
|
|
50
|
+
__experimentalRole: "content"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
supports: {
|
|
54
|
+
className: false,
|
|
55
|
+
__experimentalSelector: "li"
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
31
59
|
function useOutdentListItem(clientId) {
|
|
60
|
+
const registry = (0, _data.useRegistry)();
|
|
32
61
|
const {
|
|
33
62
|
canOutdent
|
|
34
63
|
} = (0, _data.useSelect)(innerSelect => {
|
|
@@ -41,58 +70,65 @@ function useOutdentListItem(clientId) {
|
|
|
41
70
|
};
|
|
42
71
|
}, [clientId]);
|
|
43
72
|
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
moveBlocksToPosition,
|
|
74
|
+
removeBlock,
|
|
75
|
+
insertBlock,
|
|
76
|
+
updateBlockListSettings
|
|
47
77
|
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
48
78
|
const {
|
|
49
79
|
getBlockRootClientId,
|
|
50
|
-
|
|
51
|
-
|
|
80
|
+
getBlockName,
|
|
81
|
+
getBlockOrder,
|
|
52
82
|
getBlockIndex,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
getMultiSelectedBlockClientIds
|
|
83
|
+
getSelectedBlockClientIds,
|
|
84
|
+
getBlock,
|
|
85
|
+
getBlockListSettings
|
|
57
86
|
} = (0, _data.useSelect)(_blockEditor.store);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
|
|
88
|
+
function getParentListItemId(id) {
|
|
89
|
+
const listId = getBlockRootClientId(id);
|
|
90
|
+
const parentListItemId = getBlockRootClientId(listId);
|
|
91
|
+
if (!parentListItemId) return;
|
|
92
|
+
if (getBlockName(parentListItemId) !== listItemName) return;
|
|
93
|
+
return parentListItemId;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return [canOutdent, (0, _element.useCallback)(function () {
|
|
97
|
+
let clientIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getSelectedBlockClientIds();
|
|
98
|
+
clientIds = (0, _lodash.castArray)(clientIds);
|
|
99
|
+
if (!clientIds.length) return;
|
|
100
|
+
const firstClientId = (0, _lodash.first)(clientIds); // Can't outdent if it's not a list item.
|
|
101
|
+
|
|
102
|
+
if (getBlockName(firstClientId) !== listItemName) return;
|
|
103
|
+
const parentListItemId = getParentListItemId(firstClientId); // Can't outdent if it's at the top level.
|
|
104
|
+
|
|
105
|
+
if (!parentListItemId) return;
|
|
106
|
+
const parentListId = getBlockRootClientId(firstClientId);
|
|
107
|
+
const lastClientId = (0, _lodash.last)(clientIds);
|
|
108
|
+
const order = getBlockOrder(parentListId);
|
|
109
|
+
const followingListItems = order.slice(getBlockIndex(lastClientId) + 1);
|
|
110
|
+
registry.batch(() => {
|
|
111
|
+
if (followingListItems.length) {
|
|
112
|
+
let nestedListId = (0, _lodash.first)(getBlockOrder(firstClientId));
|
|
113
|
+
|
|
114
|
+
if (!nestedListId) {
|
|
115
|
+
const nestedListBlock = (0, _blocks.cloneBlock)(getBlock(parentListId), {}, []);
|
|
116
|
+
nestedListId = nestedListBlock.clientId;
|
|
117
|
+
insertBlock(nestedListBlock, 0, firstClientId, false); // Immediately update the block list settings, otherwise
|
|
118
|
+
// blocks can't be moved here due to canInsert checks.
|
|
119
|
+
|
|
120
|
+
updateBlockListSettings(nestedListId, getBlockListSettings(parentListId));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
moveBlocksToPosition(followingListItems, parentListId, nestedListId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
moveBlocksToPosition(clientIds, parentListId, getBlockRootClientId(parentListItemId), getBlockIndex(parentListItemId) + 1);
|
|
127
|
+
|
|
128
|
+
if (!getBlockOrder(parentListId).length) {
|
|
129
|
+
removeBlock(parentListId);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}, [])];
|
|
97
133
|
}
|
|
98
134
|
//# sourceMappingURL=use-outdent-list-item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/list-item/hooks/use-outdent-list-item.js"],"names":["useOutdentListItem","clientId","canOutdent","innerSelect","getBlockRootClientId","blockEditorStore","grandParentId","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/list-item/hooks/use-outdent-list-item.js"],"names":["useOutdentListItem","clientId","registry","canOutdent","innerSelect","getBlockRootClientId","blockEditorStore","grandParentId","moveBlocksToPosition","removeBlock","insertBlock","updateBlockListSettings","getBlockName","getBlockOrder","getBlockIndex","getSelectedBlockClientIds","getBlock","getBlockListSettings","getParentListItemId","id","listId","parentListItemId","listItemName","clientIds","length","firstClientId","parentListId","lastClientId","order","followingListItems","slice","batch","nestedListId","nestedListBlock"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGe,SAASA,kBAAT,CAA6BC,QAA7B,EAAwC;AACtD,QAAMC,QAAQ,GAAG,wBAAjB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAiB,qBACpBC,WAAF,IAAmB;AAClB,UAAM;AAAEC,MAAAA;AAAF,QAA2BD,WAAW,CAAEE,kBAAF,CAA5C;AACA,UAAMC,aAAa,GAAGF,oBAAoB,CACzCA,oBAAoB,CAAEJ,QAAF,CADqB,CAA1C;AAGA,WAAO;AACNE,MAAAA,UAAU,EAAE,CAAC,CAAEI;AADT,KAAP;AAGA,GATqB,EAUtB,CAAEN,QAAF,CAVsB,CAAvB;AAYA,QAAM;AACLO,IAAAA,oBADK;AAELC,IAAAA,WAFK;AAGLC,IAAAA,WAHK;AAILC,IAAAA;AAJK,MAKF,uBAAaL,kBAAb,CALJ;AAMA,QAAM;AACLD,IAAAA,oBADK;AAELO,IAAAA,YAFK;AAGLC,IAAAA,aAHK;AAILC,IAAAA,aAJK;AAKLC,IAAAA,yBALK;AAMLC,IAAAA,QANK;AAOLC,IAAAA;AAPK,MAQF,qBAAWX,kBAAX,CARJ;;AAUA,WAASY,mBAAT,CAA8BC,EAA9B,EAAmC;AAClC,UAAMC,MAAM,GAAGf,oBAAoB,CAAEc,EAAF,CAAnC;AACA,UAAME,gBAAgB,GAAGhB,oBAAoB,CAAEe,MAAF,CAA7C;AACA,QAAK,CAAEC,gBAAP,EAA0B;AAC1B,QAAKT,YAAY,CAAES,gBAAF,CAAZ,KAAqCC,YAA1C,EAAyD;AACzD,WAAOD,gBAAP;AACA;;AAED,SAAO,CACNlB,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BH,YAFmB,EAGnBM,YAHmB,CAApB;AAKA;;AACDxB,MAAAA,oBAAoB,CACnBe,SADmB,EAEnBG,YAFmB,EAGnBrB,oBAAoB,CAAEgB,gBAAF,CAHD,EAInBP,aAAa,CAAEO,gBAAF,CAAb,GAAoC,CAJjB,CAApB;;AAMA,UAAK,CAAER,aAAa,CAAEa,YAAF,CAAb,CAA8BF,MAArC,EAA8C;AAC7Cf,QAAAA,WAAW,CAAEiB,YAAF,CAAX;AACA;AACD,KAnCD;AAoCA,GA1DD,EA0DG,EA1DH,CAFM,CAAP;AA8DA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last, castArray } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { name as listItemName } from '../block.json';\n\nexport default function useOutdentListItem( clientId ) {\n\tconst registry = useRegistry();\n\tconst { canOutdent } = useSelect(\n\t\t( innerSelect ) => {\n\t\t\tconst { getBlockRootClientId } = innerSelect( blockEditorStore );\n\t\t\tconst grandParentId = getBlockRootClientId(\n\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tcanOutdent: !! grandParentId,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\tconst {\n\t\tmoveBlocksToPosition,\n\t\tremoveBlock,\n\t\tinsertBlock,\n\t\tupdateBlockListSettings,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockName,\n\t\tgetBlockOrder,\n\t\tgetBlockIndex,\n\t\tgetSelectedBlockClientIds,\n\t\tgetBlock,\n\t\tgetBlockListSettings,\n\t} = useSelect( blockEditorStore );\n\n\tfunction getParentListItemId( id ) {\n\t\tconst listId = getBlockRootClientId( id );\n\t\tconst parentListItemId = getBlockRootClientId( listId );\n\t\tif ( ! parentListItemId ) return;\n\t\tif ( getBlockName( parentListItemId ) !== listItemName ) return;\n\t\treturn parentListItemId;\n\t}\n\n\treturn [\n\t\tcanOutdent,\n\t\tuseCallback( ( clientIds = getSelectedBlockClientIds() ) => {\n\t\t\tclientIds = castArray( clientIds );\n\n\t\t\tif ( ! clientIds.length ) return;\n\n\t\t\tconst firstClientId = first( clientIds );\n\n\t\t\t// Can't outdent if it's not a list item.\n\t\t\tif ( getBlockName( firstClientId ) !== listItemName ) return;\n\n\t\t\tconst parentListItemId = getParentListItemId( firstClientId );\n\n\t\t\t// Can't outdent if it's at the top level.\n\t\t\tif ( ! parentListItemId ) return;\n\n\t\t\tconst parentListId = getBlockRootClientId( firstClientId );\n\t\t\tconst lastClientId = last( clientIds );\n\t\t\tconst order = getBlockOrder( parentListId );\n\t\t\tconst followingListItems = order.slice(\n\t\t\t\tgetBlockIndex( lastClientId ) + 1\n\t\t\t);\n\n\t\t\tregistry.batch( () => {\n\t\t\t\tif ( followingListItems.length ) {\n\t\t\t\t\tlet nestedListId = first( getBlockOrder( firstClientId ) );\n\n\t\t\t\t\tif ( ! nestedListId ) {\n\t\t\t\t\t\tconst nestedListBlock = cloneBlock(\n\t\t\t\t\t\t\tgetBlock( parentListId ),\n\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t\t[]\n\t\t\t\t\t\t);\n\t\t\t\t\t\tnestedListId = nestedListBlock.clientId;\n\t\t\t\t\t\tinsertBlock( nestedListBlock, 0, firstClientId, false );\n\t\t\t\t\t\t// Immediately update the block list settings, otherwise\n\t\t\t\t\t\t// blocks can't be moved here due to canInsert checks.\n\t\t\t\t\t\tupdateBlockListSettings(\n\t\t\t\t\t\t\tnestedListId,\n\t\t\t\t\t\t\tgetBlockListSettings( parentListId )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\t\tfollowingListItems,\n\t\t\t\t\t\tparentListId,\n\t\t\t\t\t\tnestedListId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\tclientIds,\n\t\t\t\t\tparentListId,\n\t\t\t\t\tgetBlockRootClientId( parentListItemId ),\n\t\t\t\t\tgetBlockIndex( parentListItemId ) + 1\n\t\t\t\t);\n\t\t\t\tif ( ! getBlockOrder( parentListId ).length ) {\n\t\t\t\t\tremoveBlock( parentListId );\n\t\t\t\t}\n\t\t\t} );\n\t\t}, [] ),\n\t];\n}\n"]}
|
package/build/list-item/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.convertToListItems = convertToListItems;
|
|
6
7
|
exports.createListItem = createListItem;
|
|
7
8
|
|
|
8
9
|
var _blocks = require("@wordpress/blocks");
|
|
@@ -10,7 +11,130 @@ var _blocks = require("@wordpress/blocks");
|
|
|
10
11
|
/**
|
|
11
12
|
* WordPress dependencies
|
|
12
13
|
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
const {
|
|
19
|
+
name: listItemName
|
|
20
|
+
} = {
|
|
21
|
+
$schema: "https://schemas.wp.org/trunk/block.json",
|
|
22
|
+
apiVersion: 2,
|
|
23
|
+
__experimental: "list-v2",
|
|
24
|
+
name: "core/list-item",
|
|
25
|
+
title: "List item",
|
|
26
|
+
category: "text",
|
|
27
|
+
parent: ["core/list"],
|
|
28
|
+
description: "Create a list item.",
|
|
29
|
+
textdomain: "default",
|
|
30
|
+
attributes: {
|
|
31
|
+
placeholder: {
|
|
32
|
+
type: "string"
|
|
33
|
+
},
|
|
34
|
+
content: {
|
|
35
|
+
type: "string",
|
|
36
|
+
source: "html",
|
|
37
|
+
selector: "li",
|
|
38
|
+
"default": "",
|
|
39
|
+
__experimentalRole: "content"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
supports: {
|
|
43
|
+
className: false,
|
|
44
|
+
__experimentalSelector: "li"
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const {
|
|
48
|
+
name: listName
|
|
49
|
+
} = {
|
|
50
|
+
$schema: "https://schemas.wp.org/trunk/block.json",
|
|
51
|
+
apiVersion: 2,
|
|
52
|
+
name: "core/list",
|
|
53
|
+
title: "List",
|
|
54
|
+
category: "text",
|
|
55
|
+
description: "Create a bulleted or numbered list.",
|
|
56
|
+
keywords: ["bullet list", "ordered list", "numbered list"],
|
|
57
|
+
textdomain: "default",
|
|
58
|
+
attributes: {
|
|
59
|
+
ordered: {
|
|
60
|
+
type: "boolean",
|
|
61
|
+
"default": false,
|
|
62
|
+
__experimentalRole: "content"
|
|
63
|
+
},
|
|
64
|
+
values: {
|
|
65
|
+
type: "string",
|
|
66
|
+
source: "html",
|
|
67
|
+
selector: "ol,ul",
|
|
68
|
+
multiline: "li",
|
|
69
|
+
__unstableMultilineWrapperTags: ["ol", "ul"],
|
|
70
|
+
"default": "",
|
|
71
|
+
__experimentalRole: "content"
|
|
72
|
+
},
|
|
73
|
+
type: {
|
|
74
|
+
type: "string"
|
|
75
|
+
},
|
|
76
|
+
start: {
|
|
77
|
+
type: "number"
|
|
78
|
+
},
|
|
79
|
+
reversed: {
|
|
80
|
+
type: "boolean"
|
|
81
|
+
},
|
|
82
|
+
placeholder: {
|
|
83
|
+
type: "string"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
supports: {
|
|
87
|
+
anchor: true,
|
|
88
|
+
className: false,
|
|
89
|
+
typography: {
|
|
90
|
+
fontSize: true,
|
|
91
|
+
__experimentalFontFamily: true,
|
|
92
|
+
lineHeight: true,
|
|
93
|
+
__experimentalFontStyle: true,
|
|
94
|
+
__experimentalFontWeight: true,
|
|
95
|
+
__experimentalLetterSpacing: true,
|
|
96
|
+
__experimentalTextTransform: true,
|
|
97
|
+
__experimentalDefaultControls: {
|
|
98
|
+
fontSize: true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
color: {
|
|
102
|
+
gradients: true,
|
|
103
|
+
link: true,
|
|
104
|
+
__experimentalDefaultControls: {
|
|
105
|
+
background: true,
|
|
106
|
+
text: true
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
__unstablePasteTextInline: true,
|
|
110
|
+
__experimentalSelector: "ol,ul",
|
|
111
|
+
__experimentalSlashInserter: true
|
|
112
|
+
},
|
|
113
|
+
editorStyle: "wp-block-list-editor",
|
|
114
|
+
style: "wp-block-list"
|
|
115
|
+
};
|
|
116
|
+
|
|
13
117
|
function createListItem(listItemAttributes, listAttributes, children) {
|
|
14
|
-
return (0, _blocks.createBlock)(
|
|
118
|
+
return (0, _blocks.createBlock)(listItemName, listItemAttributes, !(children !== null && children !== void 0 && children.length) ? [] : [(0, _blocks.createBlock)(listName, listAttributes, children)]);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function convertToListItems(blocks) {
|
|
122
|
+
const listItems = [];
|
|
123
|
+
|
|
124
|
+
for (let block of blocks) {
|
|
125
|
+
if (block.name === listItemName) {
|
|
126
|
+
listItems.push(block);
|
|
127
|
+
} else if (block.name === listName) {
|
|
128
|
+
listItems.push(...block.innerBlocks);
|
|
129
|
+
} else if (block = (0, _blocks.switchToBlockType)(block, listName)) {
|
|
130
|
+
for (const {
|
|
131
|
+
innerBlocks
|
|
132
|
+
} of block) {
|
|
133
|
+
listItems.push(...innerBlocks);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return listItems;
|
|
15
139
|
}
|
|
16
140
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/list-item/utils.js"],"names":["createListItem","listItemAttributes","listAttributes","children","length"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/list-item/utils.js"],"names":["createListItem","listItemAttributes","listAttributes","children","listItemName","length","listName","convertToListItems","blocks","listItems","block","name","push","innerBlocks"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,SAASA,cAAT,CAAyBC,kBAAzB,EAA6CC,cAA7C,EAA6DC,QAA7D,EAAwE;AAC9E,SAAO,yBACNC,YADM,EAENH,kBAFM,EAGN,EAAEE,QAAF,aAAEA,QAAF,eAAEA,QAAQ,CAAEE,MAAZ,IACG,EADH,GAEG,CAAE,yBAAaC,QAAb,EAAuBJ,cAAvB,EAAuCC,QAAvC,CAAF,CALG,CAAP;AAOA;;AAEM,SAASI,kBAAT,CAA6BC,MAA7B,EAAsC;AAC5C,QAAMC,SAAS,GAAG,EAAlB;;AAEA,OAAM,IAAIC,KAAV,IAAmBF,MAAnB,EAA4B;AAC3B,QAAKE,KAAK,CAACC,IAAN,KAAeP,YAApB,EAAmC;AAClCK,MAAAA,SAAS,CAACG,IAAV,CAAgBF,KAAhB;AACA,KAFD,MAEO,IAAKA,KAAK,CAACC,IAAN,KAAeL,QAApB,EAA+B;AACrCG,MAAAA,SAAS,CAACG,IAAV,CAAgB,GAAGF,KAAK,CAACG,WAAzB;AACA,KAFM,MAEA,IAAOH,KAAK,GAAG,+BAAmBA,KAAnB,EAA0BJ,QAA1B,CAAf,EAAwD;AAC9D,WAAM,MAAM;AAAEO,QAAAA;AAAF,OAAZ,IAA+BH,KAA/B,EAAuC;AACtCD,QAAAA,SAAS,CAACG,IAAV,CAAgB,GAAGC,WAAnB;AACA;AACD;AACD;;AAED,SAAOJ,SAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createBlock, switchToBlockType } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { name as listItemName } from './block.json';\nimport { name as listName } from '../list/block.json';\n\nexport function createListItem( listItemAttributes, listAttributes, children ) {\n\treturn createBlock(\n\t\tlistItemName,\n\t\tlistItemAttributes,\n\t\t! children?.length\n\t\t\t? []\n\t\t\t: [ createBlock( listName, listAttributes, children ) ]\n\t);\n}\n\nexport function convertToListItems( blocks ) {\n\tconst listItems = [];\n\n\tfor ( let block of blocks ) {\n\t\tif ( block.name === listItemName ) {\n\t\t\tlistItems.push( block );\n\t\t} else if ( block.name === listName ) {\n\t\t\tlistItems.push( ...block.innerBlocks );\n\t\t} else if ( ( block = switchToBlockType( block, listName ) ) ) {\n\t\t\tfor ( const { innerBlocks } of block ) {\n\t\t\t\tlistItems.push( ...innerBlocks );\n\t\t\t}\n\t\t}\n\t}\n\n\treturn listItems;\n}\n"]}
|