@wordpress/block-library 8.8.0 → 8.10.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 +4 -0
- package/build/comment-author-name/edit.js +1 -1
- package/build/comment-author-name/edit.js.map +1 -1
- package/build/comment-edit-link/edit.js +1 -1
- package/build/comment-edit-link/edit.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +1 -1
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/index.js +1 -1
- package/build/cover/transforms.js +10 -7
- package/build/cover/transforms.js.map +1 -1
- package/build/cover/variations.js +1 -1
- package/build/cover/variations.js.map +1 -1
- package/build/details/edit.js +19 -5
- package/build/details/edit.js.map +1 -1
- package/build/details/index.js +14 -10
- package/build/details/index.js.map +1 -1
- package/build/details/save.js +4 -1
- package/build/details/save.js.map +1 -1
- package/build/embed/variations.js +2 -2
- package/build/embed/variations.js.map +1 -1
- package/build/file/view.js +1 -1
- package/build/file/view.js.map +1 -1
- package/build/gallery/edit.js +2 -8
- package/build/gallery/edit.js.map +1 -1
- package/build/group/edit.js +3 -1
- package/build/group/edit.js.map +1 -1
- package/build/group/index.js +3 -0
- package/build/group/index.js.map +1 -1
- package/build/image/edit.js +16 -13
- package/build/image/edit.js.map +1 -1
- package/build/image/index.js +1 -1
- package/build/index.js +0 -6
- package/build/index.js.map +1 -1
- package/build/index.native.js +10 -6
- package/build/index.native.js.map +1 -1
- package/build/list-item/utils.js +5 -1
- package/build/list-item/utils.js.map +1 -1
- package/build/loginout/index.js +11 -1
- package/build/loginout/index.js.map +1 -1
- package/build/media-text/edit.js +4 -2
- package/build/media-text/edit.js.map +1 -1
- package/build/media-text/index.js +3 -0
- package/build/media-text/index.js.map +1 -1
- package/build/navigation/constants.js +13 -0
- package/build/navigation/constants.js.map +1 -0
- package/build/navigation/edit/index.js +26 -68
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +4 -7
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +4 -6
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build/navigation/interactivity.js +139 -0
- package/build/navigation/interactivity.js.map +1 -0
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-submenu/edit.js +1 -1
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/paragraph/index.js +5 -1
- package/build/paragraph/index.js.map +1 -1
- package/build/paragraph/transforms.js +5 -1
- package/build/paragraph/transforms.js.map +1 -1
- package/build/post-author-name/edit.js +1 -1
- package/build/post-author-name/edit.js.map +1 -1
- package/build/post-date/edit.js +4 -2
- package/build/post-date/edit.js.map +1 -1
- package/build/post-excerpt/edit.js +2 -2
- package/build/post-excerpt/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +6 -4
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-featured-image/overlay.js +5 -0
- package/build/post-featured-image/overlay.js.map +1 -1
- package/build/post-title/edit.js +14 -4
- package/build/post-title/edit.js.map +1 -1
- package/build/preformatted/edit.native.js +3 -2
- package/build/preformatted/edit.native.js.map +1 -1
- package/build/query/deprecated.js +8 -6
- package/build/query/deprecated.js.map +1 -1
- package/build/query/edit/inspector-controls/create-new-post-link.js +41 -0
- package/build/query/edit/inspector-controls/create-new-post-link.js.map +1 -0
- package/build/query/edit/inspector-controls/index.js +14 -6
- package/build/query/edit/inspector-controls/index.js.map +1 -1
- package/build/query/edit/pattern-selection-modal.js +2 -1
- package/build/query/edit/pattern-selection-modal.js.map +1 -1
- package/build/query/index.js +5 -12
- package/build/query/index.js.map +1 -1
- package/build/quote/transforms.js +16 -27
- package/build/quote/transforms.js.map +1 -1
- package/build/read-more/edit.js +1 -1
- package/build/read-more/edit.js.map +1 -1
- package/build/search/edit.js +9 -1
- package/build/search/edit.js.map +1 -1
- package/build/site-logo/edit.js +114 -16
- package/build/site-logo/edit.js.map +1 -1
- package/build/site-logo/index.js +1 -1
- package/build/site-title/edit/index.js +1 -1
- package/build/site-title/edit/index.js.map +1 -1
- package/build/social-link/icons/chain.js +1 -1
- package/build/social-link/icons/chain.js.map +1 -1
- package/build/social-link/icons/mail.js +1 -1
- package/build/social-link/icons/mail.js.map +1 -1
- package/build/social-links/edit.js +2 -2
- package/build/social-links/edit.js.map +1 -1
- package/build/spacer/edit.js +117 -11
- package/build/spacer/edit.js.map +1 -1
- package/build/template-part/edit/index.js +2 -1
- package/build/template-part/edit/index.js.map +1 -1
- package/build/template-part/edit/utils/hooks.js +2 -2
- package/build/template-part/edit/utils/hooks.js.map +1 -1
- package/build/utils/interactivity/constants.js +9 -0
- package/build/utils/interactivity/constants.js.map +1 -0
- package/build/utils/interactivity/directives.js +208 -0
- package/build/utils/interactivity/directives.js.map +1 -0
- package/build/utils/interactivity/hooks.js +112 -0
- package/build/utils/interactivity/hooks.js.map +1 -0
- package/build/utils/interactivity/hydration.js +34 -0
- package/build/utils/interactivity/hydration.js.map +1 -0
- package/build/utils/interactivity/index.js +34 -0
- package/build/utils/interactivity/index.js.map +1 -0
- package/build/utils/interactivity/store.js +67 -0
- package/build/utils/interactivity/store.js.map +1 -0
- package/build/utils/interactivity/utils.js +87 -0
- package/build/utils/interactivity/utils.js.map +1 -0
- package/build/utils/interactivity/vdom.js +109 -0
- package/build/utils/interactivity/vdom.js.map +1 -0
- package/build/utils/migrate-font-family.js +12 -5
- package/build/utils/migrate-font-family.js.map +1 -1
- package/build/video/edit.native.js +4 -3
- package/build/video/edit.native.js.map +1 -1
- package/build-module/comment-author-name/edit.js +1 -1
- package/build-module/comment-author-name/edit.js.map +1 -1
- package/build-module/comment-edit-link/edit.js +1 -1
- package/build-module/comment-edit-link/edit.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +1 -1
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/index.js +1 -1
- package/build-module/cover/transforms.js +5 -1
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/cover/variations.js +1 -1
- package/build-module/cover/variations.js.map +1 -1
- package/build-module/details/edit.js +20 -6
- package/build-module/details/edit.js.map +1 -1
- package/build-module/details/index.js +14 -10
- package/build-module/details/index.js.map +1 -1
- package/build-module/details/save.js +5 -2
- package/build-module/details/save.js.map +1 -1
- package/build-module/embed/variations.js +2 -2
- package/build-module/embed/variations.js.map +1 -1
- package/build-module/file/view.js +1 -1
- package/build-module/file/view.js.map +1 -1
- package/build-module/gallery/edit.js +2 -8
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/group/edit.js +3 -1
- package/build-module/group/edit.js.map +1 -1
- package/build-module/group/index.js +3 -0
- package/build-module/group/index.js.map +1 -1
- package/build-module/image/edit.js +16 -13
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/index.js +1 -1
- package/build-module/index.js +0 -4
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +10 -6
- package/build-module/index.native.js.map +1 -1
- package/build-module/list-item/utils.js +5 -1
- package/build-module/list-item/utils.js.map +1 -1
- package/build-module/loginout/index.js +11 -1
- package/build-module/loginout/index.js.map +1 -1
- package/build-module/media-text/edit.js +4 -2
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/media-text/index.js +3 -0
- package/build-module/media-text/index.js.map +1 -1
- package/build-module/navigation/constants.js +5 -0
- package/build-module/navigation/constants.js.map +1 -0
- package/build-module/navigation/edit/index.js +28 -69
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +1 -4
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +1 -4
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build-module/navigation/interactivity.js +136 -0
- package/build-module/navigation/interactivity.js.map +1 -0
- package/build-module/navigation-link/edit.js +1 -1
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +1 -1
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/paragraph/index.js +5 -1
- package/build-module/paragraph/index.js.map +1 -1
- package/build-module/paragraph/transforms.js +5 -1
- package/build-module/paragraph/transforms.js.map +1 -1
- package/build-module/post-author-name/edit.js +1 -1
- package/build-module/post-author-name/edit.js.map +1 -1
- package/build-module/post-date/edit.js +4 -2
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-excerpt/edit.js +2 -2
- package/build-module/post-excerpt/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +6 -4
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-featured-image/overlay.js +5 -0
- package/build-module/post-featured-image/overlay.js.map +1 -1
- package/build-module/post-title/edit.js +13 -4
- package/build-module/post-title/edit.js.map +1 -1
- package/build-module/preformatted/edit.native.js +3 -2
- package/build-module/preformatted/edit.native.js.map +1 -1
- package/build-module/query/deprecated.js +5 -2
- package/build-module/query/deprecated.js.map +1 -1
- package/build-module/query/edit/inspector-controls/create-new-post-link.js +33 -0
- package/build-module/query/edit/inspector-controls/create-new-post-link.js.map +1 -0
- package/build-module/query/edit/inspector-controls/index.js +12 -7
- package/build-module/query/edit/inspector-controls/index.js.map +1 -1
- package/build-module/query/edit/pattern-selection-modal.js +2 -1
- package/build-module/query/edit/pattern-selection-modal.js.map +1 -1
- package/build-module/query/index.js +5 -10
- package/build-module/query/index.js.map +1 -1
- package/build-module/quote/transforms.js +16 -27
- package/build-module/quote/transforms.js.map +1 -1
- package/build-module/read-more/edit.js +1 -1
- package/build-module/read-more/edit.js.map +1 -1
- package/build-module/search/edit.js +9 -1
- package/build-module/search/edit.js.map +1 -1
- package/build-module/site-logo/edit.js +115 -18
- package/build-module/site-logo/edit.js.map +1 -1
- package/build-module/site-logo/index.js +1 -1
- package/build-module/site-title/edit/index.js +1 -1
- package/build-module/site-title/edit/index.js.map +1 -1
- package/build-module/social-link/icons/chain.js +1 -1
- package/build-module/social-link/icons/chain.js.map +1 -1
- package/build-module/social-link/icons/mail.js +1 -1
- package/build-module/social-link/icons/mail.js.map +1 -1
- package/build-module/social-links/edit.js +2 -2
- package/build-module/social-links/edit.js.map +1 -1
- package/build-module/spacer/edit.js +118 -12
- package/build-module/spacer/edit.js.map +1 -1
- package/build-module/template-part/edit/index.js +2 -1
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/template-part/edit/utils/hooks.js +2 -2
- package/build-module/template-part/edit/utils/hooks.js.map +1 -1
- package/build-module/utils/interactivity/constants.js +2 -0
- package/build-module/utils/interactivity/constants.js.map +1 -0
- package/build-module/utils/interactivity/directives.js +193 -0
- package/build-module/utils/interactivity/directives.js.map +1 -0
- package/build-module/utils/interactivity/hooks.js +98 -0
- package/build-module/utils/interactivity/hooks.js.map +1 -0
- package/build-module/utils/interactivity/hydration.js +21 -0
- package/build-module/utils/interactivity/hydration.js.map +1 -0
- package/build-module/utils/interactivity/index.js +17 -0
- package/build-module/utils/interactivity/index.js.map +1 -0
- package/build-module/utils/interactivity/store.js +56 -0
- package/build-module/utils/interactivity/store.js.map +1 -0
- package/build-module/utils/interactivity/utils.js +75 -0
- package/build-module/utils/interactivity/utils.js.map +1 -0
- package/build-module/utils/interactivity/vdom.js +97 -0
- package/build-module/utils/interactivity/vdom.js.map +1 -0
- package/build-module/utils/migrate-font-family.js +9 -1
- package/build-module/utils/migrate-font-family.js.map +1 -1
- package/build-module/video/edit.native.js +4 -3
- package/build-module/video/edit.native.js.map +1 -1
- package/build-style/cover/editor-rtl.css +3 -3
- package/build-style/cover/editor.css +3 -3
- package/build-style/cover/style-rtl.css +2 -1
- package/build-style/cover/style.css +2 -1
- package/build-style/{details-summary → details}/editor-rtl.css +1 -1
- package/build-style/{details-summary → details}/editor.css +1 -1
- package/build-style/details/style-rtl.css +14 -0
- package/build-style/details/style.css +14 -0
- package/build-style/editor-rtl.css +74 -39
- package/build-style/editor.css +74 -39
- package/build-style/gallery/editor-rtl.css +0 -4
- package/build-style/gallery/editor.css +0 -4
- package/build-style/html/editor-rtl.css +2 -2
- package/build-style/html/editor.css +2 -2
- package/build-style/image/editor-rtl.css +1 -1
- package/build-style/image/editor.css +1 -1
- package/build-style/query/editor-rtl.css +8 -12
- package/build-style/query/editor.css +8 -12
- package/build-style/search/editor-rtl.css +1 -0
- package/build-style/search/editor.css +1 -0
- package/build-style/search/style-rtl.css +2 -0
- package/build-style/search/style.css +2 -0
- package/build-style/shortcode/editor-rtl.css +3 -4
- package/build-style/shortcode/editor.css +3 -4
- package/build-style/site-logo/editor-rtl.css +47 -0
- package/build-style/site-logo/editor.css +47 -0
- package/build-style/style-rtl.css +15 -2
- package/build-style/style.css +15 -2
- package/build-style/template-part/editor-rtl.css +8 -12
- package/build-style/template-part/editor.css +8 -12
- package/package.json +36 -32
- package/src/buttons/test/__snapshots__/edit.native.js.snap +18 -0
- package/src/buttons/test/edit.native.js +123 -2
- package/src/comment-author-name/edit.js +1 -1
- package/src/comment-edit-link/edit.js +1 -1
- package/src/comment-template/index.php +8 -7
- package/src/cover/block.json +1 -1
- package/src/cover/edit/inspector-controls.js +56 -54
- package/src/cover/editor.scss +1 -1
- package/src/cover/style.scss +4 -0
- package/src/cover/test/edit.js +56 -2
- package/src/cover/transforms.js +4 -1
- package/src/cover/variations.js +1 -3
- package/src/details/block.json +8 -6
- package/src/details/edit.js +27 -5
- package/src/details/editor.scss +3 -0
- package/src/details/index.js +10 -5
- package/src/details/save.js +5 -1
- package/src/details/style.scss +16 -0
- package/src/editor.scss +1 -1
- package/src/embed/variations.js +2 -2
- package/src/file/view.js +4 -1
- package/src/gallery/edit.js +5 -8
- package/src/gallery/editor.scss +0 -6
- package/src/gallery/test/index.native.js +52 -7
- package/src/group/block.json +3 -0
- package/src/group/edit.js +8 -2
- package/src/heading/test/__snapshots__/index.native.js.snap +12 -0
- package/src/heading/test/index.native.js +71 -0
- package/src/html/editor.scss +2 -21
- package/src/image/block.json +1 -1
- package/src/image/edit.js +21 -17
- package/src/image/editor.scss +1 -1
- package/src/image/test/edit.native.js +38 -16
- package/src/index.js +0 -4
- package/src/index.native.js +10 -5
- package/src/list/test/edit.native.js +7 -7
- package/src/loginout/block.json +11 -1
- package/src/media-text/block.json +3 -0
- package/src/media-text/edit.js +2 -1
- package/src/navigation/constants.js +16 -0
- package/src/navigation/edit/index.js +77 -163
- package/src/navigation/edit/inner-blocks.js +1 -16
- package/src/navigation/edit/unsaved-inner-blocks.js +1 -16
- package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
- package/src/navigation/index.php +210 -197
- package/src/navigation/interactivity.js +144 -0
- package/src/navigation-link/edit.js +1 -1
- package/src/navigation-submenu/edit.js +1 -1
- package/src/paragraph/block.json +5 -1
- package/src/paragraph/test/edit.native.js +288 -28
- package/src/post-author-name/edit.js +1 -1
- package/src/post-date/edit.js +4 -0
- package/src/post-date/index.php +17 -8
- package/src/post-excerpt/edit.js +1 -1
- package/src/post-featured-image/edit.js +5 -4
- package/src/post-featured-image/overlay.js +4 -0
- package/src/post-terms/index.php +2 -2
- package/src/post-title/edit.js +8 -1
- package/src/preformatted/edit.native.js +1 -3
- package/src/preformatted/test/edit.native.js +6 -9
- package/src/pullquote/test/edit.native.js +7 -12
- package/src/query/deprecated.js +4 -1
- package/src/query/edit/inspector-controls/create-new-post-link.js +26 -0
- package/src/query/edit/inspector-controls/index.js +13 -6
- package/src/query/edit/pattern-selection-modal.js +1 -0
- package/src/query/editor.scss +8 -11
- package/src/query/index.js +1 -7
- package/src/quote/test/edit.native.js +6 -10
- package/src/quote/transforms.js +0 -6
- package/src/read-more/edit.js +1 -1
- package/src/search/edit.js +9 -4
- package/src/search/editor.scss +1 -0
- package/src/search/style.scss +3 -0
- package/src/shortcode/editor.scss +1 -21
- package/src/site-logo/block.json +1 -1
- package/src/site-logo/edit.js +123 -9
- package/src/site-logo/editor.scss +58 -0
- package/src/site-title/edit/index.js +1 -1
- package/src/social-link/icons/chain.js +1 -1
- package/src/social-link/icons/mail.js +1 -1
- package/src/social-link/index.php +2 -2
- package/src/social-links/edit.js +33 -31
- package/src/spacer/edit.js +157 -18
- package/src/style.scss +0 -1
- package/src/template-part/edit/index.js +1 -0
- package/src/template-part/edit/utils/hooks.js +2 -2
- package/src/template-part/editor.scss +9 -11
- package/src/template-part/index.php +20 -5
- package/src/utils/interactivity/constants.js +1 -0
- package/src/utils/interactivity/directives.js +179 -0
- package/src/utils/interactivity/hooks.js +76 -0
- package/src/utils/interactivity/hydration.js +22 -0
- package/src/utils/interactivity/index.js +17 -0
- package/src/utils/interactivity/store.js +45 -0
- package/src/utils/interactivity/utils.js +66 -0
- package/src/utils/interactivity/vdom.js +94 -0
- package/src/utils/migrate-font-family.js +8 -1
- package/src/verse/test/edit.native.js +4 -9
- package/src/video/edit.native.js +2 -2
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/details-content/edit.js +0 -34
- package/build/details-content/edit.js.map +0 -1
- package/build/details-content/index.js +0 -94
- package/build/details-content/index.js.map +0 -1
- package/build/details-content/save.js +0 -20
- package/build/details-content/save.js.map +0 -1
- package/build/details-summary/edit.js +0 -42
- package/build/details-summary/edit.js.map +0 -1
- package/build/details-summary/index.js +0 -97
- package/build/details-summary/index.js.map +0 -1
- package/build/details-summary/save.js +0 -24
- package/build/details-summary/save.js.map +0 -1
- package/build/query/hooks.js +0 -72
- package/build/query/hooks.js.map +0 -1
- package/build/utils/clean-empty-object.js +0 -37
- package/build/utils/clean-empty-object.js.map +0 -1
- package/build-module/details-content/edit.js +0 -23
- package/build-module/details-content/edit.js.map +0 -1
- package/build-module/details-content/index.js +0 -76
- package/build-module/details-content/index.js.map +0 -1
- package/build-module/details-content/save.js +0 -11
- package/build-module/details-content/save.js.map +0 -1
- package/build-module/details-summary/edit.js +0 -30
- package/build-module/details-summary/edit.js.map +0 -1
- package/build-module/details-summary/index.js +0 -79
- package/build-module/details-summary/index.js.map +0 -1
- package/build-module/details-summary/save.js +0 -16
- package/build-module/details-summary/save.js.map +0 -1
- package/build-module/query/hooks.js +0 -59
- package/build-module/query/hooks.js.map +0 -1
- package/build-module/utils/clean-empty-object.js +0 -28
- package/build-module/utils/clean-empty-object.js.map +0 -1
- package/build-style/details-summary/style-rtl.css +0 -91
- package/build-style/details-summary/style.css +0 -91
- package/src/details-content/block.json +0 -50
- package/src/details-content/edit.js +0 -29
- package/src/details-content/index.js +0 -23
- package/src/details-content/save.js +0 -12
- package/src/details-summary/block.json +0 -53
- package/src/details-summary/edit.js +0 -27
- package/src/details-summary/editor.scss +0 -3
- package/src/details-summary/index.js +0 -23
- package/src/details-summary/save.js +0 -13
- package/src/details-summary/style.scss +0 -3
- package/src/query/hooks.js +0 -53
- package/src/utils/clean-empty-object.js +0 -28
package/src/social-links/edit.js
CHANGED
|
@@ -195,7 +195,7 @@ export function SocialLinksEdit( props ) {
|
|
|
195
195
|
</ToolbarDropdownMenu>
|
|
196
196
|
</BlockControls>
|
|
197
197
|
<InspectorControls>
|
|
198
|
-
<PanelBody title={ __( '
|
|
198
|
+
<PanelBody title={ __( 'Settings' ) }>
|
|
199
199
|
<ToggleControl
|
|
200
200
|
__nextHasNoMarginBottom
|
|
201
201
|
label={ __( 'Open links in new tab' ) }
|
|
@@ -214,37 +214,39 @@ export function SocialLinksEdit( props ) {
|
|
|
214
214
|
/>
|
|
215
215
|
</PanelBody>
|
|
216
216
|
</InspectorControls>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
217
|
+
{ colorGradientSettings.hasColorsOrGradients && (
|
|
218
|
+
<InspectorControls group="color">
|
|
219
|
+
{ colorSettings.map(
|
|
220
|
+
( { onChange, label, value, resetAllFilter } ) => (
|
|
221
|
+
<ColorGradientSettingsDropdown
|
|
222
|
+
key={ `social-links-color-${ label }` }
|
|
223
|
+
__experimentalIsRenderedInSidebar
|
|
224
|
+
settings={ [
|
|
225
|
+
{
|
|
226
|
+
colorValue: value,
|
|
227
|
+
label,
|
|
228
|
+
onColorChange: onChange,
|
|
229
|
+
isShownByDefault: true,
|
|
230
|
+
resetAllFilter,
|
|
231
|
+
enableAlpha: true,
|
|
232
|
+
},
|
|
233
|
+
] }
|
|
234
|
+
panelId={ clientId }
|
|
235
|
+
{ ...colorGradientSettings }
|
|
236
|
+
/>
|
|
237
|
+
)
|
|
238
|
+
) }
|
|
239
|
+
{ ! logosOnly && (
|
|
240
|
+
<ContrastChecker
|
|
241
|
+
{ ...{
|
|
242
|
+
textColor: iconColorValue,
|
|
243
|
+
backgroundColor: iconBackgroundColorValue,
|
|
244
|
+
} }
|
|
245
|
+
isLargeText={ false }
|
|
235
246
|
/>
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
<ContrastChecker
|
|
240
|
-
{ ...{
|
|
241
|
-
textColor: iconColorValue,
|
|
242
|
-
backgroundColor: iconBackgroundColorValue,
|
|
243
|
-
} }
|
|
244
|
-
isLargeText={ false }
|
|
245
|
-
/>
|
|
246
|
-
) }
|
|
247
|
-
</InspectorControls>
|
|
247
|
+
) }
|
|
248
|
+
</InspectorControls>
|
|
249
|
+
) }
|
|
248
250
|
<ul { ...innerBlocksProps } />
|
|
249
251
|
</>
|
|
250
252
|
);
|
package/src/spacer/edit.js
CHANGED
|
@@ -8,6 +8,8 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
10
|
useBlockProps,
|
|
11
|
+
useSetting,
|
|
12
|
+
getCustomValueFromPreset,
|
|
11
13
|
getSpacingPresetCssVar,
|
|
12
14
|
store as blockEditorStore,
|
|
13
15
|
} from '@wordpress/block-editor';
|
|
@@ -92,13 +94,20 @@ const SpacerEdit = ( {
|
|
|
92
94
|
} );
|
|
93
95
|
const { orientation } = context;
|
|
94
96
|
const { orientation: parentOrientation, type } = parentLayout || {};
|
|
97
|
+
// Check if the spacer is inside a flex container.
|
|
98
|
+
const isFlexLayout = type === 'flex';
|
|
95
99
|
// If the spacer is inside a flex container, it should either inherit the orientation
|
|
96
100
|
// of the parent or use the flex default orientation.
|
|
97
101
|
const inheritedOrientation =
|
|
98
|
-
! parentOrientation &&
|
|
102
|
+
! parentOrientation && isFlexLayout
|
|
99
103
|
? 'horizontal'
|
|
100
104
|
: parentOrientation || orientation;
|
|
101
|
-
const { height, width } = attributes;
|
|
105
|
+
const { height, width, style: blockStyle = {} } = attributes;
|
|
106
|
+
|
|
107
|
+
const { layout = {} } = blockStyle;
|
|
108
|
+
const { selfStretch, flexSize } = layout;
|
|
109
|
+
|
|
110
|
+
const spacingSizes = useSetting( 'spacing.spacingSizes' );
|
|
102
111
|
|
|
103
112
|
const [ isResizing, setIsResizing ] = useState( false );
|
|
104
113
|
const [ temporaryHeight, setTemporaryHeight ] = useState( null );
|
|
@@ -110,32 +119,80 @@ const SpacerEdit = ( {
|
|
|
110
119
|
const handleOnVerticalResizeStop = ( newHeight ) => {
|
|
111
120
|
onResizeStop();
|
|
112
121
|
|
|
122
|
+
if ( isFlexLayout ) {
|
|
123
|
+
setAttributes( {
|
|
124
|
+
style: {
|
|
125
|
+
...blockStyle,
|
|
126
|
+
layout: {
|
|
127
|
+
...layout,
|
|
128
|
+
flexSize: newHeight,
|
|
129
|
+
selfStretch: 'fixed',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
} );
|
|
133
|
+
}
|
|
134
|
+
|
|
113
135
|
setAttributes( { height: newHeight } );
|
|
114
136
|
setTemporaryHeight( null );
|
|
115
137
|
};
|
|
116
138
|
|
|
117
139
|
const handleOnHorizontalResizeStop = ( newWidth ) => {
|
|
118
140
|
onResizeStop();
|
|
141
|
+
|
|
142
|
+
if ( isFlexLayout ) {
|
|
143
|
+
setAttributes( {
|
|
144
|
+
style: {
|
|
145
|
+
...blockStyle,
|
|
146
|
+
layout: {
|
|
147
|
+
...layout,
|
|
148
|
+
flexSize: newWidth,
|
|
149
|
+
selfStretch: 'fixed',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
} );
|
|
153
|
+
}
|
|
154
|
+
|
|
119
155
|
setAttributes( { width: newWidth } );
|
|
120
156
|
setTemporaryWidth( null );
|
|
121
157
|
};
|
|
122
158
|
|
|
159
|
+
const getHeightForVerticalBlocks = () => {
|
|
160
|
+
if ( isFlexLayout ) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
return temporaryHeight || getSpacingPresetCssVar( height ) || undefined;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const getWidthForHorizontalBlocks = () => {
|
|
167
|
+
if ( isFlexLayout ) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
return temporaryWidth || getSpacingPresetCssVar( width ) || undefined;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const sizeConditionalOnOrientation =
|
|
174
|
+
inheritedOrientation === 'horizontal'
|
|
175
|
+
? temporaryWidth || flexSize
|
|
176
|
+
: temporaryHeight || flexSize;
|
|
177
|
+
|
|
123
178
|
const style = {
|
|
124
179
|
height:
|
|
125
180
|
inheritedOrientation === 'horizontal'
|
|
126
181
|
? 24
|
|
127
|
-
:
|
|
128
|
-
getSpacingPresetCssVar( height ) ||
|
|
129
|
-
undefined,
|
|
182
|
+
: getHeightForVerticalBlocks(),
|
|
130
183
|
width:
|
|
131
184
|
inheritedOrientation === 'horizontal'
|
|
132
|
-
?
|
|
185
|
+
? getWidthForHorizontalBlocks()
|
|
133
186
|
: undefined,
|
|
134
187
|
// In vertical flex containers, the spacer shrinks to nothing without a minimum width.
|
|
135
188
|
minWidth:
|
|
136
|
-
inheritedOrientation === 'vertical' &&
|
|
189
|
+
inheritedOrientation === 'vertical' && isFlexLayout
|
|
137
190
|
? 48
|
|
138
191
|
: undefined,
|
|
192
|
+
// Add flex-basis so temporary sizes are respected.
|
|
193
|
+
flexBasis: isFlexLayout ? sizeConditionalOnOrientation : undefined,
|
|
194
|
+
// Remove flex-grow when resizing.
|
|
195
|
+
flexGrow: isFlexLayout && isResizing ? 0 : undefined,
|
|
139
196
|
};
|
|
140
197
|
|
|
141
198
|
const resizableBoxWithOrientation = ( blockOrientation ) => {
|
|
@@ -191,13 +248,93 @@ const SpacerEdit = ( {
|
|
|
191
248
|
};
|
|
192
249
|
|
|
193
250
|
useEffect( () => {
|
|
194
|
-
if (
|
|
251
|
+
if (
|
|
252
|
+
isFlexLayout &&
|
|
253
|
+
selfStretch !== 'fill' &&
|
|
254
|
+
selfStretch !== 'fit' &&
|
|
255
|
+
! flexSize
|
|
256
|
+
) {
|
|
257
|
+
if ( inheritedOrientation === 'horizontal' ) {
|
|
258
|
+
// If spacer is moving from a vertical container to a horizontal container,
|
|
259
|
+
// it might not have width but have height instead.
|
|
260
|
+
const newSize =
|
|
261
|
+
getCustomValueFromPreset( width, spacingSizes ) ||
|
|
262
|
+
getCustomValueFromPreset( height, spacingSizes ) ||
|
|
263
|
+
'100px';
|
|
264
|
+
setAttributes( {
|
|
265
|
+
width: '0px',
|
|
266
|
+
style: {
|
|
267
|
+
...blockStyle,
|
|
268
|
+
layout: {
|
|
269
|
+
...layout,
|
|
270
|
+
flexSize: newSize,
|
|
271
|
+
selfStretch: 'fixed',
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
} );
|
|
275
|
+
} else {
|
|
276
|
+
const newSize =
|
|
277
|
+
getCustomValueFromPreset( height, spacingSizes ) ||
|
|
278
|
+
getCustomValueFromPreset( width, spacingSizes ) ||
|
|
279
|
+
'100px';
|
|
280
|
+
setAttributes( {
|
|
281
|
+
height: '0px',
|
|
282
|
+
style: {
|
|
283
|
+
...blockStyle,
|
|
284
|
+
layout: {
|
|
285
|
+
...layout,
|
|
286
|
+
flexSize: newSize,
|
|
287
|
+
selfStretch: 'fixed',
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
} );
|
|
291
|
+
}
|
|
292
|
+
} else if (
|
|
293
|
+
isFlexLayout &&
|
|
294
|
+
( selfStretch === 'fill' || selfStretch === 'fit' )
|
|
295
|
+
) {
|
|
296
|
+
if ( inheritedOrientation === 'horizontal' ) {
|
|
297
|
+
setAttributes( {
|
|
298
|
+
width: undefined,
|
|
299
|
+
} );
|
|
300
|
+
} else {
|
|
301
|
+
setAttributes( {
|
|
302
|
+
height: undefined,
|
|
303
|
+
} );
|
|
304
|
+
}
|
|
305
|
+
} else if ( ! isFlexLayout && ( selfStretch || flexSize ) ) {
|
|
306
|
+
if ( inheritedOrientation === 'horizontal' ) {
|
|
307
|
+
setAttributes( {
|
|
308
|
+
width: flexSize,
|
|
309
|
+
} );
|
|
310
|
+
} else {
|
|
311
|
+
setAttributes( {
|
|
312
|
+
height: flexSize,
|
|
313
|
+
} );
|
|
314
|
+
}
|
|
195
315
|
setAttributes( {
|
|
196
|
-
|
|
197
|
-
|
|
316
|
+
style: {
|
|
317
|
+
...blockStyle,
|
|
318
|
+
layout: {
|
|
319
|
+
...layout,
|
|
320
|
+
flexSize: undefined,
|
|
321
|
+
selfStretch: undefined,
|
|
322
|
+
},
|
|
323
|
+
},
|
|
198
324
|
} );
|
|
199
325
|
}
|
|
200
|
-
}, [
|
|
326
|
+
}, [
|
|
327
|
+
blockStyle,
|
|
328
|
+
flexSize,
|
|
329
|
+
height,
|
|
330
|
+
inheritedOrientation,
|
|
331
|
+
isFlexLayout,
|
|
332
|
+
layout,
|
|
333
|
+
selfStretch,
|
|
334
|
+
setAttributes,
|
|
335
|
+
spacingSizes,
|
|
336
|
+
width,
|
|
337
|
+
] );
|
|
201
338
|
|
|
202
339
|
return (
|
|
203
340
|
<>
|
|
@@ -211,13 +348,15 @@ const SpacerEdit = ( {
|
|
|
211
348
|
>
|
|
212
349
|
{ resizableBoxWithOrientation( inheritedOrientation ) }
|
|
213
350
|
</View>
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
351
|
+
{ ! isFlexLayout && (
|
|
352
|
+
<SpacerControls
|
|
353
|
+
setAttributes={ setAttributes }
|
|
354
|
+
height={ temporaryHeight || height }
|
|
355
|
+
width={ temporaryWidth || width }
|
|
356
|
+
orientation={ inheritedOrientation }
|
|
357
|
+
isResizing={ isResizing }
|
|
358
|
+
/>
|
|
359
|
+
) }
|
|
221
360
|
</>
|
|
222
361
|
);
|
|
223
362
|
};
|
package/src/style.scss
CHANGED
|
@@ -37,7 +37,7 @@ export function useAlternativeTemplateParts( area, excludedId ) {
|
|
|
37
37
|
'wp_template_part',
|
|
38
38
|
query
|
|
39
39
|
),
|
|
40
|
-
|
|
40
|
+
isResolving: _isResolving( 'getEntityRecords', [
|
|
41
41
|
'postType',
|
|
42
42
|
'wp_template_part',
|
|
43
43
|
query,
|
|
@@ -61,7 +61,7 @@ export function useAlternativeTemplateParts( area, excludedId ) {
|
|
|
61
61
|
templatePart.area === area )
|
|
62
62
|
) || []
|
|
63
63
|
);
|
|
64
|
-
}, [ templateParts, area ] );
|
|
64
|
+
}, [ templateParts, area, excludedId ] );
|
|
65
65
|
|
|
66
66
|
return {
|
|
67
67
|
templateParts: filteredTemplateParts,
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
.block-editor-template-part__selection-modal {
|
|
2
2
|
z-index: z-index(".block-editor-template-part__selection-modal");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
@include break-medium() {
|
|
12
|
-
width: $break-medium - $grid-unit-20 * 2;
|
|
4
|
+
.block-editor-block-patterns-list {
|
|
5
|
+
column-count: 2;
|
|
6
|
+
column-gap: $grid-unit-30;
|
|
7
|
+
|
|
8
|
+
@include break-wide() {
|
|
9
|
+
column-count: 3;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
|
|
12
|
+
.block-editor-block-patterns-list__list-item {
|
|
13
|
+
break-inside: avoid-column;
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
}
|
|
@@ -173,21 +173,34 @@ function render_block_core_template_part( $attributes ) {
|
|
|
173
173
|
/**
|
|
174
174
|
* Returns an array of area variation objects for the template part block.
|
|
175
175
|
*
|
|
176
|
+
* @param array $instance_variations The variations for instances.
|
|
177
|
+
*
|
|
176
178
|
* @return array Array containing the block variation objects.
|
|
177
179
|
*/
|
|
178
|
-
function build_template_part_block_area_variations() {
|
|
180
|
+
function build_template_part_block_area_variations( $instance_variations ) {
|
|
179
181
|
$variations = array();
|
|
180
182
|
$defined_areas = get_allowed_block_template_part_areas();
|
|
183
|
+
|
|
181
184
|
foreach ( $defined_areas as $area ) {
|
|
182
185
|
if ( 'uncategorized' !== $area['area'] ) {
|
|
186
|
+
$has_instance_for_area = false;
|
|
187
|
+
foreach ( $instance_variations as $variation ) {
|
|
188
|
+
if ( $variation['attributes']['area'] === $area['area'] ) {
|
|
189
|
+
$has_instance_for_area = true;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
$scope = $has_instance_for_area ? array() : array( 'inserter' );
|
|
195
|
+
|
|
183
196
|
$variations[] = array(
|
|
184
|
-
'name' => $area['area'],
|
|
197
|
+
'name' => 'area_' . $area['area'],
|
|
185
198
|
'title' => $area['label'],
|
|
186
199
|
'description' => $area['description'],
|
|
187
200
|
'attributes' => array(
|
|
188
201
|
'area' => $area['area'],
|
|
189
202
|
),
|
|
190
|
-
'scope' =>
|
|
203
|
+
'scope' => $scope,
|
|
191
204
|
'icon' => $area['icon'],
|
|
192
205
|
);
|
|
193
206
|
}
|
|
@@ -223,7 +236,7 @@ function build_template_part_block_instance_variations() {
|
|
|
223
236
|
|
|
224
237
|
foreach ( $template_parts as $template_part ) {
|
|
225
238
|
$variations[] = array(
|
|
226
|
-
'name' => sanitize_title( $template_part->slug ),
|
|
239
|
+
'name' => 'instance_' . sanitize_title( $template_part->slug ),
|
|
227
240
|
'title' => $template_part->title,
|
|
228
241
|
// If there's no description for the template part don't show the
|
|
229
242
|
// block description. This is a bit hacky, but prevent the fallback
|
|
@@ -255,7 +268,9 @@ function build_template_part_block_instance_variations() {
|
|
|
255
268
|
* @return array Array containing the block variation objects.
|
|
256
269
|
*/
|
|
257
270
|
function build_template_part_block_variations() {
|
|
258
|
-
|
|
271
|
+
$instance_variations = build_template_part_block_instance_variations();
|
|
272
|
+
$area_variations = build_template_part_block_area_variations( $instance_variations );
|
|
273
|
+
return array_merge( $area_variations, $instance_variations );
|
|
259
274
|
}
|
|
260
275
|
|
|
261
276
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const directivePrefix = 'data-wp-';
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useContext, useMemo, useEffect } from 'preact/hooks';
|
|
5
|
+
import { deepSignal, peek } from 'deepsignal';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useSignalEffect } from './utils';
|
|
11
|
+
import { directive } from './hooks';
|
|
12
|
+
|
|
13
|
+
const isObject = ( item ) =>
|
|
14
|
+
item && typeof item === 'object' && ! Array.isArray( item );
|
|
15
|
+
|
|
16
|
+
const mergeDeepSignals = ( target, source ) => {
|
|
17
|
+
for ( const k in source ) {
|
|
18
|
+
if ( typeof peek( target, k ) === 'undefined' ) {
|
|
19
|
+
target[ `$${ k }` ] = source[ `$${ k }` ];
|
|
20
|
+
} else if (
|
|
21
|
+
isObject( peek( target, k ) ) &&
|
|
22
|
+
isObject( peek( source, k ) )
|
|
23
|
+
) {
|
|
24
|
+
mergeDeepSignals(
|
|
25
|
+
target[ `$${ k }` ].peek(),
|
|
26
|
+
source[ `$${ k }` ].peek()
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default () => {
|
|
33
|
+
// data-wp-context
|
|
34
|
+
directive(
|
|
35
|
+
'context',
|
|
36
|
+
( {
|
|
37
|
+
directives: {
|
|
38
|
+
context: { default: context },
|
|
39
|
+
},
|
|
40
|
+
props: { children },
|
|
41
|
+
context: inherited,
|
|
42
|
+
} ) => {
|
|
43
|
+
const { Provider } = inherited;
|
|
44
|
+
const inheritedValue = useContext( inherited );
|
|
45
|
+
const value = useMemo( () => {
|
|
46
|
+
const localValue = deepSignal( context );
|
|
47
|
+
mergeDeepSignals( localValue, inheritedValue );
|
|
48
|
+
return localValue;
|
|
49
|
+
}, [ context, inheritedValue ] );
|
|
50
|
+
|
|
51
|
+
return <Provider value={ value }>{ children }</Provider>;
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// data-wp-effect.[name]
|
|
56
|
+
directive( 'effect', ( { directives: { effect }, context, evaluate } ) => {
|
|
57
|
+
const contextValue = useContext( context );
|
|
58
|
+
Object.values( effect ).forEach( ( path ) => {
|
|
59
|
+
useSignalEffect( () => {
|
|
60
|
+
return evaluate( path, { context: contextValue } );
|
|
61
|
+
} );
|
|
62
|
+
} );
|
|
63
|
+
} );
|
|
64
|
+
|
|
65
|
+
// data-wp-init.[name]
|
|
66
|
+
directive( 'init', ( { directives: { init }, context, evaluate } ) => {
|
|
67
|
+
const contextValue = useContext( context );
|
|
68
|
+
Object.values( init ).forEach( ( path ) => {
|
|
69
|
+
useEffect( () => {
|
|
70
|
+
return evaluate( path, { context: contextValue } );
|
|
71
|
+
}, [] );
|
|
72
|
+
} );
|
|
73
|
+
} );
|
|
74
|
+
|
|
75
|
+
// data-wp-on.[event]
|
|
76
|
+
directive( 'on', ( { directives: { on }, element, evaluate, context } ) => {
|
|
77
|
+
const contextValue = useContext( context );
|
|
78
|
+
Object.entries( on ).forEach( ( [ name, path ] ) => {
|
|
79
|
+
element.props[ `on${ name }` ] = ( event ) => {
|
|
80
|
+
evaluate( path, { event, context: contextValue } );
|
|
81
|
+
};
|
|
82
|
+
} );
|
|
83
|
+
} );
|
|
84
|
+
|
|
85
|
+
// data-wp-class.[classname]
|
|
86
|
+
directive(
|
|
87
|
+
'class',
|
|
88
|
+
( {
|
|
89
|
+
directives: { class: className },
|
|
90
|
+
element,
|
|
91
|
+
evaluate,
|
|
92
|
+
context,
|
|
93
|
+
} ) => {
|
|
94
|
+
const contextValue = useContext( context );
|
|
95
|
+
Object.keys( className )
|
|
96
|
+
.filter( ( n ) => n !== 'default' )
|
|
97
|
+
.forEach( ( name ) => {
|
|
98
|
+
const result = evaluate( className[ name ], {
|
|
99
|
+
className: name,
|
|
100
|
+
context: contextValue,
|
|
101
|
+
} );
|
|
102
|
+
const currentClass = element.props.class || '';
|
|
103
|
+
const classFinder = new RegExp(
|
|
104
|
+
`(^|\\s)${ name }(\\s|$)`,
|
|
105
|
+
'g'
|
|
106
|
+
);
|
|
107
|
+
if ( ! result )
|
|
108
|
+
element.props.class = currentClass
|
|
109
|
+
.replace( classFinder, ' ' )
|
|
110
|
+
.trim();
|
|
111
|
+
else if ( ! classFinder.test( currentClass ) )
|
|
112
|
+
element.props.class = currentClass
|
|
113
|
+
? `${ currentClass } ${ name }`
|
|
114
|
+
: name;
|
|
115
|
+
|
|
116
|
+
useEffect( () => {
|
|
117
|
+
// This seems necessary because Preact doesn't change the class
|
|
118
|
+
// names on the hydration, so we have to do it manually. It doesn't
|
|
119
|
+
// need deps because it only needs to do it the first time.
|
|
120
|
+
if ( ! result ) {
|
|
121
|
+
element.ref.current.classList.remove( name );
|
|
122
|
+
} else {
|
|
123
|
+
element.ref.current.classList.add( name );
|
|
124
|
+
}
|
|
125
|
+
}, [] );
|
|
126
|
+
} );
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// data-wp-bind.[attribute]
|
|
131
|
+
directive(
|
|
132
|
+
'bind',
|
|
133
|
+
( { directives: { bind }, element, context, evaluate } ) => {
|
|
134
|
+
const contextValue = useContext( context );
|
|
135
|
+
Object.entries( bind )
|
|
136
|
+
.filter( ( n ) => n !== 'default' )
|
|
137
|
+
.forEach( ( [ attribute, path ] ) => {
|
|
138
|
+
const result = evaluate( path, {
|
|
139
|
+
context: contextValue,
|
|
140
|
+
} );
|
|
141
|
+
element.props[ attribute ] = result;
|
|
142
|
+
|
|
143
|
+
useEffect( () => {
|
|
144
|
+
// This seems necessary because Preact doesn't change the attributes
|
|
145
|
+
// on the hydration, so we have to do it manually. It doesn't need
|
|
146
|
+
// deps because it only needs to do it the first time.
|
|
147
|
+
if ( result === false ) {
|
|
148
|
+
element.ref.current.removeAttribute( attribute );
|
|
149
|
+
} else {
|
|
150
|
+
element.ref.current.setAttribute(
|
|
151
|
+
attribute,
|
|
152
|
+
result === true ? '' : result
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}, [] );
|
|
156
|
+
} );
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// data-wp-ignore
|
|
161
|
+
directive(
|
|
162
|
+
'ignore',
|
|
163
|
+
( {
|
|
164
|
+
element: {
|
|
165
|
+
type: Type,
|
|
166
|
+
props: { innerHTML, ...rest },
|
|
167
|
+
},
|
|
168
|
+
} ) => {
|
|
169
|
+
// Preserve the initial inner HTML.
|
|
170
|
+
const cached = useMemo( () => innerHTML, [] );
|
|
171
|
+
return (
|
|
172
|
+
<Type
|
|
173
|
+
dangerouslySetInnerHTML={ { __html: cached } }
|
|
174
|
+
{ ...rest }
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { h, options, createContext } from 'preact';
|
|
5
|
+
import { useRef, useMemo } from 'preact/hooks';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { rawStore as store } from './store';
|
|
10
|
+
|
|
11
|
+
// Main context.
|
|
12
|
+
const context = createContext( {} );
|
|
13
|
+
|
|
14
|
+
// WordPress Directives.
|
|
15
|
+
const directiveMap = {};
|
|
16
|
+
export const directive = ( name, cb ) => {
|
|
17
|
+
directiveMap[ name ] = cb;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Resolve the path to some property of the store object.
|
|
21
|
+
const resolve = ( path, ctx ) => {
|
|
22
|
+
// If path starts with !, remove it and save a flag.
|
|
23
|
+
const hasNegationOperator =
|
|
24
|
+
path[ 0 ] === '!' && !! ( path = path.slice( 1 ) );
|
|
25
|
+
let current = { ...store, context: ctx };
|
|
26
|
+
path.split( '.' ).forEach( ( p ) => ( current = current[ p ] ) );
|
|
27
|
+
return hasNegationOperator ? ! current : current;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Generate the evaluate function.
|
|
31
|
+
const getEvaluate =
|
|
32
|
+
( { ref } = {} ) =>
|
|
33
|
+
( path, extraArgs = {} ) => {
|
|
34
|
+
const value = resolve( path, extraArgs.context );
|
|
35
|
+
return typeof value === 'function'
|
|
36
|
+
? value( {
|
|
37
|
+
ref: ref.current,
|
|
38
|
+
...store,
|
|
39
|
+
...extraArgs,
|
|
40
|
+
} )
|
|
41
|
+
: value;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Directive wrapper.
|
|
45
|
+
const Directive = ( { type, directives, props: originalProps } ) => {
|
|
46
|
+
const ref = useRef( null );
|
|
47
|
+
const element = h( type, { ...originalProps, ref } );
|
|
48
|
+
const props = { ...originalProps, children: element };
|
|
49
|
+
const evaluate = useMemo( () => getEvaluate( { ref } ), [] );
|
|
50
|
+
const directiveArgs = { directives, props, element, context, evaluate };
|
|
51
|
+
|
|
52
|
+
for ( const d in directives ) {
|
|
53
|
+
const wrapper = directiveMap[ d ]?.( directiveArgs );
|
|
54
|
+
if ( wrapper !== undefined ) props.children = wrapper;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return props.children;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Preact Options Hook called each time a vnode is created.
|
|
61
|
+
const old = options.vnode;
|
|
62
|
+
options.vnode = ( vnode ) => {
|
|
63
|
+
if ( vnode.props.__directives ) {
|
|
64
|
+
const props = vnode.props;
|
|
65
|
+
const directives = props.__directives;
|
|
66
|
+
delete props.__directives;
|
|
67
|
+
vnode.props = {
|
|
68
|
+
type: vnode.type,
|
|
69
|
+
directives,
|
|
70
|
+
props,
|
|
71
|
+
};
|
|
72
|
+
vnode.type = Directive;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if ( old ) old( vnode );
|
|
76
|
+
};
|