@wordpress/block-library 7.15.1-next.4d3b314fd5.0 → 7.17.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 -1
- package/build/archives/edit.js +1 -0
- package/build/archives/edit.js.map +1 -1
- package/build/code/utils.js +3 -3
- package/build/code/utils.js.map +1 -1
- package/build/comment-template/edit.js +40 -32
- package/build/comment-template/edit.js.map +1 -1
- package/build/comments/edit/placeholder.js +1 -4
- package/build/comments/edit/placeholder.js.map +1 -1
- package/build/comments/index.js +5 -1
- package/build/comments/index.js.map +1 -1
- package/build/comments-title/edit.js +18 -1
- package/build/comments-title/edit.js.map +1 -1
- package/build/cover/edit/index.js +2 -2
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/use-cover-is-dark.js +8 -7
- package/build/cover/edit/use-cover-is-dark.js.map +1 -1
- package/build/embed/variations.js +1 -1
- package/build/embed/variations.js.map +1 -1
- package/build/gallery/transforms.js +3 -3
- package/build/gallery/transforms.js.map +1 -1
- package/build/gallery/v1/edit.js +1 -1
- package/build/gallery/v1/edit.js.map +1 -1
- package/build/group/edit.js +1 -1
- package/build/group/edit.js.map +1 -1
- package/build/image/image.js +34 -10
- package/build/image/image.js.map +1 -1
- package/build/image/transforms.js +1 -7
- package/build/image/transforms.js.map +1 -1
- package/build/list/transforms.js +9 -1
- package/build/list/transforms.js.map +1 -1
- package/build/list-item/edit.js +3 -2
- package/build/list-item/edit.js.map +1 -1
- package/build/list-item/edit.native.js +3 -2
- package/build/list-item/edit.native.js.map +1 -1
- package/build/list-item/hooks/use-merge.js +19 -22
- package/build/list-item/hooks/use-merge.js.map +1 -1
- package/build/list-item/hooks/use-outdent-list-item.js +19 -3
- package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
- package/build/list-item/index.js +14 -1
- package/build/list-item/index.js.map +1 -1
- package/build/list-item/utils.js +14 -1
- package/build/list-item/utils.js.map +1 -1
- package/build/navigation/edit/index.js +46 -33
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +3 -5
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +25 -8
- package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
- package/build/navigation/index.js +4 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +1 -1
- package/build/page-list/index.js +1 -5
- package/build/page-list/index.js.map +1 -1
- package/build/paragraph/deprecated.js +49 -10
- package/build/paragraph/deprecated.js.map +1 -1
- package/build/paragraph/edit.js +22 -14
- package/build/paragraph/edit.js.map +1 -1
- package/build/paragraph/save.js +3 -1
- package/build/paragraph/save.js.map +1 -1
- package/build/pattern/edit.js +11 -4
- package/build/pattern/edit.js.map +1 -1
- package/build/post-author/edit.js +20 -2
- package/build/post-author/edit.js.map +1 -1
- package/build/post-author/index.js +8 -0
- package/build/post-author/index.js.map +1 -1
- package/build/post-comments-form/form.js +1 -2
- package/build/post-comments-form/form.js.map +1 -1
- package/build/post-featured-image/index.js +1 -1
- package/build/post-featured-image/overlay.js +2 -2
- package/build/post-featured-image/overlay.js.map +1 -1
- package/build/post-terms/index.js +4 -0
- package/build/post-terms/index.js.map +1 -1
- package/build/query/edit/inspector-controls/author-control.js +2 -1
- package/build/query/edit/inspector-controls/author-control.js.map +1 -1
- package/build/query/edit/inspector-controls/index.js +3 -3
- package/build/query/edit/inspector-controls/index.js.map +1 -1
- package/build/query/edit/inspector-controls/parent-control.js +2 -1
- package/build/query/edit/inspector-controls/parent-control.js.map +1 -1
- package/build/query/edit/inspector-controls/taxonomy-controls.js +79 -103
- package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
- package/build/query/utils.js +1 -1
- package/build/query/utils.js.map +1 -1
- package/build/quote/index.js +0 -1
- package/build/quote/index.js.map +1 -1
- package/build/search/edit.js +2 -1
- package/build/search/edit.js.map +1 -1
- package/build/site-logo/edit.js +6 -9
- package/build/site-logo/edit.js.map +1 -1
- package/build/site-title/index.js +2 -1
- package/build/site-title/index.js.map +1 -1
- package/build/table/state.js +1 -1
- package/build/table/state.js.map +1 -1
- package/build/table-of-contents/edit.js +1 -4
- package/build/table-of-contents/edit.js.map +1 -1
- package/build/tag-cloud/edit.js +1 -1
- package/build/tag-cloud/edit.js.map +1 -1
- package/build/tag-cloud/index.js +8 -0
- package/build/tag-cloud/index.js.map +1 -1
- package/build/template-part/index.js +2 -2
- package/build/template-part/index.js.map +1 -1
- package/build/video/edit.js +13 -1
- package/build/video/edit.js.map +1 -1
- package/build-module/archives/edit.js +1 -0
- package/build-module/archives/edit.js.map +1 -1
- package/build-module/code/utils.js +3 -3
- package/build-module/code/utils.js.map +1 -1
- package/build-module/comment-template/edit.js +38 -30
- package/build-module/comment-template/edit.js.map +1 -1
- package/build-module/comments/edit/placeholder.js +1 -3
- package/build-module/comments/edit/placeholder.js.map +1 -1
- package/build-module/comments/index.js +5 -1
- package/build-module/comments/index.js.map +1 -1
- package/build-module/comments-title/edit.js +18 -2
- package/build-module/comments-title/edit.js.map +1 -1
- package/build-module/cover/edit/index.js +2 -2
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/use-cover-is-dark.js +7 -7
- package/build-module/cover/edit/use-cover-is-dark.js.map +1 -1
- package/build-module/embed/variations.js +1 -1
- package/build-module/embed/variations.js.map +1 -1
- package/build-module/gallery/transforms.js +4 -4
- package/build-module/gallery/transforms.js.map +1 -1
- package/build-module/gallery/v1/edit.js +2 -2
- package/build-module/gallery/v1/edit.js.map +1 -1
- package/build-module/group/edit.js +1 -1
- package/build-module/group/edit.js.map +1 -1
- package/build-module/image/image.js +35 -11
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/transforms.js +1 -6
- package/build-module/image/transforms.js.map +1 -1
- package/build-module/list/transforms.js +9 -1
- package/build-module/list/transforms.js.map +1 -1
- package/build-module/list-item/edit.js +3 -2
- package/build-module/list-item/edit.js.map +1 -1
- package/build-module/list-item/edit.native.js +3 -2
- package/build-module/list-item/edit.native.js.map +1 -1
- package/build-module/list-item/hooks/use-merge.js +19 -21
- package/build-module/list-item/hooks/use-merge.js.map +1 -1
- package/build-module/list-item/hooks/use-outdent-list-item.js +19 -3
- package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
- package/build-module/list-item/index.js +14 -1
- package/build-module/list-item/index.js.map +1 -1
- package/build-module/list-item/utils.js +14 -1
- package/build-module/list-item/utils.js.map +1 -1
- package/build-module/navigation/edit/index.js +46 -33
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +3 -5
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +25 -8
- package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
- package/build-module/navigation/index.js +4 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation-link/edit.js +1 -1
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/page-list/index.js +1 -5
- package/build-module/page-list/index.js.map +1 -1
- package/build-module/paragraph/deprecated.js +49 -11
- package/build-module/paragraph/deprecated.js.map +1 -1
- package/build-module/paragraph/edit.js +22 -13
- package/build-module/paragraph/edit.js.map +1 -1
- package/build-module/paragraph/save.js +2 -1
- package/build-module/paragraph/save.js.map +1 -1
- package/build-module/pattern/edit.js +10 -3
- package/build-module/pattern/edit.js.map +1 -1
- package/build-module/post-author/edit.js +21 -2
- package/build-module/post-author/edit.js.map +1 -1
- package/build-module/post-author/index.js +8 -0
- package/build-module/post-author/index.js.map +1 -1
- package/build-module/post-comments-form/form.js +2 -3
- package/build-module/post-comments-form/form.js.map +1 -1
- package/build-module/post-featured-image/index.js +1 -1
- package/build-module/post-featured-image/overlay.js +2 -2
- package/build-module/post-featured-image/overlay.js.map +1 -1
- package/build-module/post-terms/index.js +4 -0
- package/build-module/post-terms/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/author-control.js +2 -1
- package/build-module/query/edit/inspector-controls/author-control.js.map +1 -1
- package/build-module/query/edit/inspector-controls/index.js +5 -5
- package/build-module/query/edit/inspector-controls/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/parent-control.js +2 -1
- package/build-module/query/edit/inspector-controls/parent-control.js.map +1 -1
- package/build-module/query/edit/inspector-controls/taxonomy-controls.js +81 -101
- package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
- package/build-module/query/utils.js +1 -1
- package/build-module/query/utils.js.map +1 -1
- package/build-module/quote/index.js +0 -1
- package/build-module/quote/index.js.map +1 -1
- package/build-module/search/edit.js +3 -2
- package/build-module/search/edit.js.map +1 -1
- package/build-module/site-logo/edit.js +6 -9
- package/build-module/site-logo/edit.js.map +1 -1
- package/build-module/site-title/index.js +2 -1
- package/build-module/site-title/index.js.map +1 -1
- package/build-module/table/state.js +2 -2
- package/build-module/table/state.js.map +1 -1
- package/build-module/table-of-contents/edit.js +1 -3
- package/build-module/table-of-contents/edit.js.map +1 -1
- package/build-module/tag-cloud/edit.js +1 -1
- package/build-module/tag-cloud/edit.js.map +1 -1
- package/build-module/tag-cloud/index.js +8 -0
- package/build-module/tag-cloud/index.js.map +1 -1
- package/build-module/template-part/index.js +2 -2
- package/build-module/template-part/index.js.map +1 -1
- package/build-module/video/edit.js +15 -3
- package/build-module/video/edit.js.map +1 -1
- package/build-style/archives/style-rtl.css +4 -0
- package/build-style/archives/style.css +4 -0
- package/build-style/code/style-rtl.css +3 -0
- package/build-style/code/style.css +3 -0
- package/build-style/comments/editor-rtl.css +1 -0
- package/build-style/comments/editor.css +1 -0
- package/build-style/comments/style-rtl.css +1 -0
- package/build-style/comments/style.css +1 -0
- package/build-style/cover/editor-rtl.css +4 -0
- package/build-style/cover/editor.css +4 -0
- package/build-style/editor-rtl.css +78 -46
- package/build-style/editor.css +78 -46
- package/build-style/group/editor-rtl.css +1 -0
- package/build-style/group/editor.css +1 -0
- package/build-style/image/editor-rtl.css +1 -1
- package/build-style/image/editor.css +1 -1
- package/build-style/navigation/editor-rtl.css +5 -0
- package/build-style/navigation/editor.css +5 -0
- package/build-style/navigation/style-rtl.css +3 -0
- package/build-style/navigation/style.css +3 -0
- package/build-style/paragraph/editor-rtl.css +0 -16
- package/build-style/paragraph/editor.css +0 -16
- package/build-style/paragraph/style-rtl.css +5 -0
- package/build-style/paragraph/style.css +5 -0
- package/build-style/post-featured-image/editor-rtl.css +39 -29
- package/build-style/post-featured-image/editor.css +39 -29
- package/build-style/post-terms/style-rtl.css +4 -1
- package/build-style/post-terms/style.css +4 -1
- package/build-style/site-logo/editor-rtl.css +1 -0
- package/build-style/site-logo/editor.css +1 -0
- package/build-style/site-title/editor-rtl.css +4 -0
- package/build-style/site-title/editor.css +4 -0
- package/build-style/site-title/style-rtl.css +79 -0
- package/build-style/site-title/style.css +79 -0
- package/build-style/style-rtl.css +27 -1
- package/build-style/style.css +27 -1
- package/build-style/tag-cloud/style-rtl.css +3 -0
- package/build-style/tag-cloud/style.css +3 -0
- package/build-style/video/editor-rtl.css +22 -0
- package/build-style/video/editor.css +22 -0
- package/package.json +28 -28
- package/src/archives/edit.js +1 -0
- package/src/archives/style.scss +5 -0
- package/src/avatar/index.php +1 -1
- package/src/categories/index.php +1 -1
- package/src/code/style.scss +12 -7
- package/src/code/test/__snapshots__/edit.native.js.snap +13 -0
- package/src/code/test/edit.native.js +46 -32
- package/src/code/utils.js +3 -3
- package/src/comment-author-name/index.php +1 -1
- package/src/comment-reply-link/index.php +1 -1
- package/src/comment-template/edit.js +47 -34
- package/src/comment-template/index.php +2 -3
- package/src/comments/block.json +5 -1
- package/src/comments/edit/placeholder.js +1 -7
- package/src/comments/style.scss +2 -0
- package/src/comments-title/edit.js +24 -1
- package/src/cover/edit/index.js +2 -7
- package/src/cover/edit/use-cover-is-dark.js +11 -11
- package/src/cover/editor.scss +7 -0
- package/src/cover/index.php +1 -1
- package/src/embed/variations.js +1 -1
- package/src/gallery/transforms.js +8 -5
- package/src/gallery/v1/edit.js +2 -2
- package/src/group/edit.js +1 -1
- package/src/group/editor.scss +1 -0
- package/src/image/editor.scss +4 -1
- package/src/image/image.js +59 -29
- package/src/image/transforms.js +1 -7
- package/src/latest-posts/index.php +1 -1
- package/src/list/test/edit.native.js +102 -3
- package/src/list/transforms.js +11 -0
- package/src/list-item/block.json +14 -1
- package/src/list-item/edit.js +2 -1
- package/src/list-item/edit.native.js +2 -1
- package/src/list-item/hooks/use-merge.js +4 -23
- package/src/list-item/hooks/use-outdent-list-item.js +6 -2
- package/src/navigation/block.json +4 -1
- package/src/navigation/edit/index.js +60 -32
- package/src/navigation/edit/inner-blocks.js +2 -5
- package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +32 -5
- package/src/navigation/edit/use-create-navigation-menu.js +2 -5
- package/src/navigation/editor.scss +7 -0
- package/src/navigation/index.php +103 -6
- package/src/navigation/style.scss +8 -0
- package/src/navigation-link/edit.js +1 -1
- package/src/navigation-link/index.php +8 -1
- package/src/navigation-submenu/index.php +8 -1
- package/src/page-list/block.json +1 -5
- package/src/page-list/index.php +10 -8
- package/src/paragraph/deprecated.js +36 -0
- package/src/paragraph/edit.js +24 -22
- package/src/paragraph/editor.scss +0 -20
- package/src/paragraph/save.js +5 -1
- package/src/paragraph/style.scss +5 -0
- package/src/pattern/edit.js +10 -3
- package/src/post-author/block.json +8 -0
- package/src/post-author/edit.js +29 -3
- package/src/post-author/index.php +7 -1
- package/src/post-comments-form/form.js +2 -3
- package/src/post-featured-image/block.json +1 -1
- package/src/post-featured-image/editor.scss +79 -72
- package/src/post-featured-image/index.php +18 -24
- package/src/post-featured-image/overlay.js +17 -14
- package/src/post-terms/block.json +4 -0
- package/src/post-terms/style.scss +7 -2
- package/src/query/edit/inspector-controls/author-control.js +1 -0
- package/src/query/edit/inspector-controls/index.js +5 -7
- package/src/query/edit/inspector-controls/parent-control.js +1 -0
- package/src/query/edit/inspector-controls/taxonomy-controls.js +82 -86
- package/src/query/utils.js +1 -1
- package/src/quote/block.json +0 -1
- package/src/rss/index.php +3 -3
- package/src/search/edit.js +6 -1
- package/src/search/index.php +21 -13
- package/src/site-logo/edit.js +10 -8
- package/src/site-logo/editor.scss +1 -0
- package/src/site-title/block.json +2 -1
- package/src/site-title/editor.scss +6 -0
- package/src/site-title/style.scss +5 -0
- package/src/style.scss +1 -0
- package/src/table/state.js +2 -2
- package/src/table-of-contents/edit.js +1 -3
- package/src/tag-cloud/block.json +8 -0
- package/src/tag-cloud/edit.js +1 -1
- package/src/tag-cloud/style.scss +3 -0
- package/src/template-part/index.js +2 -2
- package/src/template-part/index.php +4 -0
- package/src/video/edit.js +19 -0
- package/src/video/editor.scss +37 -0
- package/build/navigation-submenu/view.js +0 -56
- package/build/navigation-submenu/view.js.map +0 -1
- package/build/paragraph/drop-zone.js +0 -99
- package/build/paragraph/drop-zone.js.map +0 -1
- package/build-module/navigation-submenu/view.js +0 -54
- package/build-module/navigation-submenu/view.js.map +0 -1
- package/build-module/paragraph/drop-zone.js +0 -88
- package/build-module/paragraph/drop-zone.js.map +0 -1
- package/src/navigation-submenu/view.js +0 -67
- package/src/paragraph/drop-zone.js +0 -105
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"names":["TableOfContentsEdit","attributes","headings","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","disabledRef","canInsertList","select","getBlockRootClientId","canInsertBlockType","blockEditorStore","rootClientId","__unstableMarkNextChangeAsNotPersistent","replaceBlocks","latestHeadings","getBlockAttributes","getBlockName","getClientIdsWithDescendants","__experimentalGetGlobalBlocksByName","getGlobalBlocksByName","editorSelectors","pageBreakClientIds","isPaginated","length","allBlockClientIds","tocPage","tocIndex","indexOf","blockIndex","blockClientId","entries","_latestHeadings","headingPage","permalink","getPermalink","headingPageLink","page","blockName","headingAttributes","canBeLinked","anchor","push","content","replace","level","link","headingTree","toolbarControls","ordered","values","inspectorControls","value","icon"],"mappings":";;;;;;;;;AA0BA;;AAvBA;;AAKA;;AAOA;;AACA;;AAOA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AAnCA;AACA;AACA;;AAGA;AACA;AACA;;AAuBA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,OAIX;AAAA,MAJyC;AAC5CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,QAAQ,GAAG,EAAb;AAAiBC,MAAAA;AAAjB,KADgC;AAE5CC,IAAAA,QAF4C;AAG5CC,IAAAA;AAH4C,GAIzC;AACH,QAAMC,UAAU,GAAG,iCAAnB;AACA,QAAMC,WAAW,GAAG,2BAApB;AAEA,QAAMC,aAAa,GAAG,qBACnBC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,oBAAF;AAAwBC,MAAAA;AAAxB,QACLF,MAAM,CAAEG,kBAAF,CADP;AAEA,UAAMC,YAAY,GAAGH,oBAAoB,CAAEN,QAAF,CAAzC;AAEA,WAAOO,kBAAkB,CAAE,WAAF,EAAeE,YAAf,CAAzB;AACA,GAPoB,EAQrB,CAAET,QAAF,CARqB,CAAtB;AAWA,QAAM;AAAEU,IAAAA,uCAAF;AAA2CC,IAAAA;AAA3C,MACL,uBAAaH,kBAAb,CADD;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,QAAMI,cAAc,GAAG,qBACpBP,MAAF,IAAc;AAAA;;AACb,UAAM;AACLQ,MAAAA,kBADK;AAELC,MAAAA,YAFK;AAGLC,MAAAA,2BAHK;AAILC,MAAAA,mCAAmC,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AK,EAAC,mBAFP;AAGC,MAAA,YAAY,EAAG,cACd,4GADc;AAHhB,MADD,CADD,EAUGF,iBAVH,CADD;AAcA;;AAED,SACC,qDACC,mCAAU9C,UAAV,EACC;AAAI,IAAA,GAAG,EAAGC;AAAV,KACC,4BAAC,aAAD;AAAqB,IAAA,iBAAiB,EAAGyC;AAAzC,IADD,CADD,CADD,EAMGC,eANH,EAOGG,iBAPH,CADD;AAWA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\tPanelBody,\n\tPlaceholder,\n\tToggleControl,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useDisabled } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { renderToString, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { addQueryArgs, removeQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport icon from './icon';\nimport TableOfContentsList from './list';\nimport { linearToNestedHeadingList } from './utils';\n\n/** @typedef {import('./utils').HeadingData} HeadingData */\n\n/**\n * Table of Contents block edit component.\n *\n * @param {Object} props The props.\n * @param {Object} props.attributes The block attributes.\n * @param {HeadingData[]} props.attributes.headings A list of data for each heading in the post.\n * @param {boolean} props.attributes.onlyIncludeCurrentPage Whether to only include headings from the current page (if the post is paginated).\n * @param {string} props.clientId\n * @param {(attributes: Object) => void} props.setAttributes\n *\n * @return {WPComponent} The component.\n */\nexport default function TableOfContentsEdit( {\n\tattributes: { headings = [], onlyIncludeCurrentPage },\n\tclientId,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\tconst disabledRef = useDisabled();\n\n\tconst canInsertList = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId, canInsertBlockType } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\treturn canInsertBlockType( 'core/list', rootClientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlocks } =\n\t\tuseDispatch( blockEditorStore );\n\n\t/**\n\t * The latest heading data, or null if the new data deeply equals the saved\n\t * headings attribute.\n\t *\n\t * Since useSelect forces a re-render when its return value is shallowly\n\t * inequal to its prior call, we would be re-rendering this block every time\n\t * the stores change, even if the latest headings were deeply equal to the\n\t * ones saved in the block attributes.\n\t *\n\t * By returning null when they're equal, we reduce that to 2 renders: one\n\t * when there are new latest headings (and so it returns them), and one when\n\t * they haven't changed (so it returns null). As long as the latest heading\n\t * data remains the same, further calls of the useSelect callback will\n\t * continue to return null, thus preventing any forced re-renders.\n\t */\n\tconst latestHeadings = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetClientIdsWithDescendants,\n\t\t\t\t__experimentalGetGlobalBlocksByName: getGlobalBlocksByName,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t\t\t// Blocks can be loaded into a *non-post* block editor, so to avoid\n\t\t\t// declaring @wordpress/editor as a dependency, we must access its\n\t\t\t// store by string. When the store is not available, editorSelectors\n\t\t\t// will be null, and the block's saved markup will lack permalinks.\n\t\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\t\tconst editorSelectors = select( 'core/editor' );\n\n\t\t\tconst pageBreakClientIds = getGlobalBlocksByName( 'core/nextpage' );\n\n\t\t\tconst isPaginated = pageBreakClientIds.length !== 0;\n\n\t\t\t// Get the client ids of all blocks in the editor.\n\t\t\tconst allBlockClientIds = getClientIdsWithDescendants();\n\n\t\t\t// If onlyIncludeCurrentPage is true, calculate the page (of a paginated post) this block is part of, so we know which headings to include; otherwise, skip the calculation.\n\t\t\tlet tocPage = 1;\n\n\t\t\tif ( isPaginated && onlyIncludeCurrentPage ) {\n\t\t\t\t// We can't use getBlockIndex because it only returns the index\n\t\t\t\t// relative to sibling blocks.\n\t\t\t\tconst tocIndex = allBlockClientIds.indexOf( clientId );\n\n\t\t\t\tfor ( const [\n\t\t\t\t\tblockIndex,\n\t\t\t\t\tblockClientId,\n\t\t\t\t] of allBlockClientIds.entries() ) {\n\t\t\t\t\t// If we've reached blocks after the Table of Contents, we've\n\t\t\t\t\t// finished calculating which page the block is on.\n\t\t\t\t\tif ( blockIndex >= tocIndex ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ( getBlockName( blockClientId ) === 'core/nextpage' ) {\n\t\t\t\t\t\ttocPage++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst _latestHeadings = [];\n\n\t\t\t/** The page (of a paginated post) a heading will be part of. */\n\t\t\tlet headingPage = 1;\n\n\t\t\t/**\n\t\t\t * A permalink to the current post. If the core/editor store is\n\t\t\t * unavailable, this variable will be null.\n\t\t\t */\n\t\t\tconst permalink = editorSelectors?.getPermalink() ?? null;\n\n\t\t\tlet headingPageLink = null;\n\n\t\t\t// If the core/editor store is available, we can add permalinks to the\n\t\t\t// generated table of contents.\n\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\theadingPageLink = isPaginated\n\t\t\t\t\t? addQueryArgs( permalink, { page: headingPage } )\n\t\t\t\t\t: permalink;\n\t\t\t}\n\n\t\t\tfor ( const blockClientId of allBlockClientIds ) {\n\t\t\t\tconst blockName = getBlockName( blockClientId );\n\t\t\t\tif ( blockName === 'core/nextpage' ) {\n\t\t\t\t\theadingPage++;\n\n\t\t\t\t\t// If we're only including headings from the current page (of\n\t\t\t\t\t// a paginated post), then exit the loop if we've reached the\n\t\t\t\t\t// pages after the one with the Table of Contents block.\n\t\t\t\t\tif ( onlyIncludeCurrentPage && headingPage > tocPage ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\t\t\theadingPageLink = addQueryArgs(\n\t\t\t\t\t\t\tremoveQueryArgs( permalink, [ 'page' ] ),\n\t\t\t\t\t\t\t{ page: headingPage }\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// If we're including all headings or we've reached headings on\n\t\t\t\t// the same page as the Table of Contents block, add them to the\n\t\t\t\t// list.\n\t\t\t\telse if (\n\t\t\t\t\t! onlyIncludeCurrentPage ||\n\t\t\t\t\theadingPage === tocPage\n\t\t\t\t) {\n\t\t\t\t\tif ( blockName === 'core/heading' ) {\n\t\t\t\t\t\tconst headingAttributes =\n\t\t\t\t\t\t\tgetBlockAttributes( blockClientId );\n\n\t\t\t\t\t\tconst canBeLinked =\n\t\t\t\t\t\t\ttypeof headingPageLink === 'string' &&\n\t\t\t\t\t\t\ttypeof headingAttributes.anchor === 'string' &&\n\t\t\t\t\t\t\theadingAttributes.anchor !== '';\n\n\t\t\t\t\t\t_latestHeadings.push( {\n\t\t\t\t\t\t\t// Convert line breaks to spaces, and get rid of HTML tags in the headings.\n\t\t\t\t\t\t\tcontent: stripHTML(\n\t\t\t\t\t\t\t\theadingAttributes.content.replace(\n\t\t\t\t\t\t\t\t\t/(<br *\\/?>)+/g,\n\t\t\t\t\t\t\t\t\t' '\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tlevel: headingAttributes.level,\n\t\t\t\t\t\t\tlink: canBeLinked\n\t\t\t\t\t\t\t\t? `${ headingPageLink }#${ headingAttributes.anchor }`\n\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( isEqual( headings, _latestHeadings ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn _latestHeadings;\n\t\t},\n\t\t[ clientId, onlyIncludeCurrentPage, headings ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( latestHeadings !== null ) {\n\t\t\t// This is required to keep undo working and not create 2 undo steps\n\t\t\t// for each heading change.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { headings: latestHeadings } );\n\t\t}\n\t}, [ latestHeadings ] );\n\n\tconst headingTree = linearToNestedHeadingList( headings );\n\n\tconst toolbarControls = canInsertList && (\n\t\t<BlockControls>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tcreateBlock( 'core/list', {\n\t\t\t\t\t\t\t\tordered: true,\n\t\t\t\t\t\t\t\tvalues: renderToString(\n\t\t\t\t\t\t\t\t\t<TableOfContentsList\n\t\t\t\t\t\t\t\t\t\tnestedHeadingList={ headingTree }\n\t\t\t\t\t\t\t\t\t/>\n\t\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}\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Convert to static list' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Only include current page' ) }\n\t\t\t\t\tchecked={ onlyIncludeCurrentPage }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { onlyIncludeCurrentPage: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={\n\t\t\t\t\t\tonlyIncludeCurrentPage\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'Only including headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Toggle to only include headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n\n\t// If there are no headings or the only heading is empty.\n\t// Note that the toolbar controls are intentionally omitted since the\n\t// \"Convert to static list\" option is useless to the placeholder state.\n\tif ( headings.length === 0 ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Placeholder\n\t\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\t\tlabel=\"Table of Contents\"\n\t\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t\t'Start adding Heading blocks to create a table of contents. Headings with HTML anchors will be linked here.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t{ inspectorControls }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<nav { ...blockProps }>\n\t\t\t\t<ol ref={ disabledRef }>\n\t\t\t\t\t<TableOfContentsList nestedHeadingList={ headingTree } />\n\t\t\t\t</ol>\n\t\t\t</nav>\n\t\t\t{ toolbarControls }\n\t\t\t{ inspectorControls }\n\t\t</>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"names":["TableOfContentsEdit","attributes","headings","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","canInsertList","select","getBlockRootClientId","canInsertBlockType","blockEditorStore","rootClientId","__unstableMarkNextChangeAsNotPersistent","replaceBlocks","latestHeadings","getBlockAttributes","getBlockName","getClientIdsWithDescendants","__experimentalGetGlobalBlocksByName","getGlobalBlocksByName","editorSelectors","pageBreakClientIds","isPaginated","length","allBlockClientIds","tocPage","tocIndex","indexOf","blockIndex","blockClientId","entries","_latestHeadings","headingPage","permalink","getPermalink","headingPageLink","page","blockName","headingAttributes","canBeLinked","anchor","push","content","replace","level","link","headingTree","toolbarControls","ordered","values","inspectorControls","value","icon"],"mappings":";;;;;;;;;AAyBA;;AAtBA;;AAKA;;AAOA;;AACA;;AAOA;;AACA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AAlCA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,OAIX;AAAA,MAJyC;AAC5CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,QAAQ,GAAG,EAAb;AAAiBC,MAAAA;AAAjB,KADgC;AAE5CC,IAAAA,QAF4C;AAG5CC,IAAAA;AAH4C,GAIzC;AACH,QAAMC,UAAU,GAAG,iCAAnB;AAEA,QAAMC,aAAa,GAAG,qBACnBC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,oBAAF;AAAwBC,MAAAA;AAAxB,QACLF,MAAM,CAAEG,kBAAF,CADP;AAEA,UAAMC,YAAY,GAAGH,oBAAoB,CAAEL,QAAF,CAAzC;AAEA,WAAOM,kBAAkB,CAAE,WAAF,EAAeE,YAAf,CAAzB;AACA,GAPoB,EAQrB,CAAER,QAAF,CARqB,CAAtB;AAWA,QAAM;AAAES,IAAAA,uCAAF;AAA2CC,IAAAA;AAA3C,MACL,uBAAaH,kBAAb,CADD;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,QAAMI,cAAc,GAAG,qBACpBP,MAAF,IAAc;AAAA;;AACb,UAAM;AACLQ,MAAAA,kBADK;AAELC,MAAAA,YAFK;AAGLC,MAAAA,2BAHK;AAILC,MAAAA,mCAAmC,EAAEC;AAJhC,QAKFZ,MAAM,CAAEG,kBAAF,CALV,CADa,CAQb;AACA;AACA;AACA;AACA;AACA;;AACA,UAAMU,eAAe,GA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,qDACC,mCAAU7C,UAAV,EACC;AAAI,IAAA,KAAK,EAAC;AAAV,KACC,4BAAC,aAAD;AAAqB,IAAA,iBAAiB,EAAGyC;AAAzC,IADD,CADD,CADD,EAMGC,eANH,EAOGG,iBAPH,CADD;AAWA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\nimport {\n\tPanelBody,\n\tPlaceholder,\n\tToggleControl,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { renderToString, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { addQueryArgs, removeQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport icon from './icon';\nimport TableOfContentsList from './list';\nimport { linearToNestedHeadingList } from './utils';\n\n/** @typedef {import('./utils').HeadingData} HeadingData */\n\n/**\n * Table of Contents block edit component.\n *\n * @param {Object} props The props.\n * @param {Object} props.attributes The block attributes.\n * @param {HeadingData[]} props.attributes.headings A list of data for each heading in the post.\n * @param {boolean} props.attributes.onlyIncludeCurrentPage Whether to only include headings from the current page (if the post is paginated).\n * @param {string} props.clientId\n * @param {(attributes: Object) => void} props.setAttributes\n *\n * @return {WPComponent} The component.\n */\nexport default function TableOfContentsEdit( {\n\tattributes: { headings = [], onlyIncludeCurrentPage },\n\tclientId,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst canInsertList = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId, canInsertBlockType } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\treturn canInsertBlockType( 'core/list', rootClientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlocks } =\n\t\tuseDispatch( blockEditorStore );\n\n\t/**\n\t * The latest heading data, or null if the new data deeply equals the saved\n\t * headings attribute.\n\t *\n\t * Since useSelect forces a re-render when its return value is shallowly\n\t * inequal to its prior call, we would be re-rendering this block every time\n\t * the stores change, even if the latest headings were deeply equal to the\n\t * ones saved in the block attributes.\n\t *\n\t * By returning null when they're equal, we reduce that to 2 renders: one\n\t * when there are new latest headings (and so it returns them), and one when\n\t * they haven't changed (so it returns null). As long as the latest heading\n\t * data remains the same, further calls of the useSelect callback will\n\t * continue to return null, thus preventing any forced re-renders.\n\t */\n\tconst latestHeadings = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetClientIdsWithDescendants,\n\t\t\t\t__experimentalGetGlobalBlocksByName: getGlobalBlocksByName,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t\t\t// Blocks can be loaded into a *non-post* block editor, so to avoid\n\t\t\t// declaring @wordpress/editor as a dependency, we must access its\n\t\t\t// store by string. When the store is not available, editorSelectors\n\t\t\t// will be null, and the block's saved markup will lack permalinks.\n\t\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\t\tconst editorSelectors = select( 'core/editor' );\n\n\t\t\tconst pageBreakClientIds = getGlobalBlocksByName( 'core/nextpage' );\n\n\t\t\tconst isPaginated = pageBreakClientIds.length !== 0;\n\n\t\t\t// Get the client ids of all blocks in the editor.\n\t\t\tconst allBlockClientIds = getClientIdsWithDescendants();\n\n\t\t\t// If onlyIncludeCurrentPage is true, calculate the page (of a paginated post) this block is part of, so we know which headings to include; otherwise, skip the calculation.\n\t\t\tlet tocPage = 1;\n\n\t\t\tif ( isPaginated && onlyIncludeCurrentPage ) {\n\t\t\t\t// We can't use getBlockIndex because it only returns the index\n\t\t\t\t// relative to sibling blocks.\n\t\t\t\tconst tocIndex = allBlockClientIds.indexOf( clientId );\n\n\t\t\t\tfor ( const [\n\t\t\t\t\tblockIndex,\n\t\t\t\t\tblockClientId,\n\t\t\t\t] of allBlockClientIds.entries() ) {\n\t\t\t\t\t// If we've reached blocks after the Table of Contents, we've\n\t\t\t\t\t// finished calculating which page the block is on.\n\t\t\t\t\tif ( blockIndex >= tocIndex ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ( getBlockName( blockClientId ) === 'core/nextpage' ) {\n\t\t\t\t\t\ttocPage++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst _latestHeadings = [];\n\n\t\t\t/** The page (of a paginated post) a heading will be part of. */\n\t\t\tlet headingPage = 1;\n\n\t\t\t/**\n\t\t\t * A permalink to the current post. If the core/editor store is\n\t\t\t * unavailable, this variable will be null.\n\t\t\t */\n\t\t\tconst permalink = editorSelectors?.getPermalink() ?? null;\n\n\t\t\tlet headingPageLink = null;\n\n\t\t\t// If the core/editor store is available, we can add permalinks to the\n\t\t\t// generated table of contents.\n\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\theadingPageLink = isPaginated\n\t\t\t\t\t? addQueryArgs( permalink, { page: headingPage } )\n\t\t\t\t\t: permalink;\n\t\t\t}\n\n\t\t\tfor ( const blockClientId of allBlockClientIds ) {\n\t\t\t\tconst blockName = getBlockName( blockClientId );\n\t\t\t\tif ( blockName === 'core/nextpage' ) {\n\t\t\t\t\theadingPage++;\n\n\t\t\t\t\t// If we're only including headings from the current page (of\n\t\t\t\t\t// a paginated post), then exit the loop if we've reached the\n\t\t\t\t\t// pages after the one with the Table of Contents block.\n\t\t\t\t\tif ( onlyIncludeCurrentPage && headingPage > tocPage ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\t\t\theadingPageLink = addQueryArgs(\n\t\t\t\t\t\t\tremoveQueryArgs( permalink, [ 'page' ] ),\n\t\t\t\t\t\t\t{ page: headingPage }\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// If we're including all headings or we've reached headings on\n\t\t\t\t// the same page as the Table of Contents block, add them to the\n\t\t\t\t// list.\n\t\t\t\telse if (\n\t\t\t\t\t! onlyIncludeCurrentPage ||\n\t\t\t\t\theadingPage === tocPage\n\t\t\t\t) {\n\t\t\t\t\tif ( blockName === 'core/heading' ) {\n\t\t\t\t\t\tconst headingAttributes =\n\t\t\t\t\t\t\tgetBlockAttributes( blockClientId );\n\n\t\t\t\t\t\tconst canBeLinked =\n\t\t\t\t\t\t\ttypeof headingPageLink === 'string' &&\n\t\t\t\t\t\t\ttypeof headingAttributes.anchor === 'string' &&\n\t\t\t\t\t\t\theadingAttributes.anchor !== '';\n\n\t\t\t\t\t\t_latestHeadings.push( {\n\t\t\t\t\t\t\t// Convert line breaks to spaces, and get rid of HTML tags in the headings.\n\t\t\t\t\t\t\tcontent: stripHTML(\n\t\t\t\t\t\t\t\theadingAttributes.content.replace(\n\t\t\t\t\t\t\t\t\t/(<br *\\/?>)+/g,\n\t\t\t\t\t\t\t\t\t' '\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tlevel: headingAttributes.level,\n\t\t\t\t\t\t\tlink: canBeLinked\n\t\t\t\t\t\t\t\t? `${ headingPageLink }#${ headingAttributes.anchor }`\n\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( isEqual( headings, _latestHeadings ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn _latestHeadings;\n\t\t},\n\t\t[ clientId, onlyIncludeCurrentPage, headings ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( latestHeadings !== null ) {\n\t\t\t// This is required to keep undo working and not create 2 undo steps\n\t\t\t// for each heading change.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { headings: latestHeadings } );\n\t\t}\n\t}, [ latestHeadings ] );\n\n\tconst headingTree = linearToNestedHeadingList( headings );\n\n\tconst toolbarControls = canInsertList && (\n\t\t<BlockControls>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tcreateBlock( 'core/list', {\n\t\t\t\t\t\t\t\tordered: true,\n\t\t\t\t\t\t\t\tvalues: renderToString(\n\t\t\t\t\t\t\t\t\t<TableOfContentsList\n\t\t\t\t\t\t\t\t\t\tnestedHeadingList={ headingTree }\n\t\t\t\t\t\t\t\t\t/>\n\t\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}\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Convert to static list' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Only include current page' ) }\n\t\t\t\t\tchecked={ onlyIncludeCurrentPage }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { onlyIncludeCurrentPage: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={\n\t\t\t\t\t\tonlyIncludeCurrentPage\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'Only including headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Toggle to only include headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n\n\t// If there are no headings or the only heading is empty.\n\t// Note that the toolbar controls are intentionally omitted since the\n\t// \"Convert to static list\" option is useless to the placeholder state.\n\tif ( headings.length === 0 ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Placeholder\n\t\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\t\tlabel=\"Table of Contents\"\n\t\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t\t'Start adding Heading blocks to create a table of contents. Headings with HTML anchors will be linked here.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t{ inspectorControls }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<nav { ...blockProps }>\n\t\t\t\t<ol inert=\"true\">\n\t\t\t\t\t<TableOfContentsList nestedHeadingList={ headingTree } />\n\t\t\t\t</ol>\n\t\t\t</nav>\n\t\t\t{ toolbarControls }\n\t\t\t{ inspectorControls }\n\t\t</>\n\t);\n}\n"]}
|
package/build/tag-cloud/edit.js
CHANGED
|
@@ -154,7 +154,7 @@ function TagCloudEdit(_ref) {
|
|
|
154
154
|
max: MAX_FONT_SIZE
|
|
155
155
|
})))));
|
|
156
156
|
return (0, _element.createElement)(_element.Fragment, null, inspectorControls, (0, _element.createElement)("div", (0, _blockEditor.useBlockProps)(), (0, _element.createElement)(_serverSideRender.default, {
|
|
157
|
-
|
|
157
|
+
skipBlockSupportAttributes: true,
|
|
158
158
|
block: "core/tag-cloud",
|
|
159
159
|
attributes: attributes
|
|
160
160
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/tag-cloud/edit.js"],"names":["MIN_TAGS","MAX_TAGS","MIN_FONT_SIZE","MAX_FONT_SIZE","TagCloudEdit","attributes","setAttributes","taxonomies","taxonomy","showTagCounts","numberOfTags","smallestFontSize","largestFontSize","units","availableUnits","getTaxonomyOptions","selectOption","label","value","disabled","taxonomyOptions","item","slug","name","onFontSizeChange","fontSizeLabel","newValue","quantity","newUnit","Number","isFinite","updateObj","Object","entries","forEach","attribute","currentValue","currentQuantity","currentUnit","inspectorControls","selectedTaxonomy","select","coreStore","getTaxonomies","per_page"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AAWA;;AACA;;AACA;;AAKA;;AACA;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG,CAAjB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,QAAQ,GAAG,GAAjB;AAEA,MAAMC,aAAa,GAAG,GAAtB;AACA,MAAMC,aAAa,GAAG,GAAtB;;AAEA,SAASC,YAAT,OAAmE;AAAA,MAA5C;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,aAAd;AAA6BC,IAAAA;AAA7B,GAA4C;AAClE,QAAM;AACLC,IAAAA,QADK;AAELC,IAAAA,aAFK;AAGLC,IAAAA,YAHK;AAILC,IAAAA,gBAJK;AAKLC,IAAAA;AALK,MAMFP,UANJ;AAQA,QAAMQ,KAAK,GAAG,8CAAgB;AAC7BC,IAAAA,cAAc,EAAE,6BAAY,eAAZ,KAAiC,CAChD,GADgD,EAEhD,IAFgD,EAGhD,IAHgD,EAIhD,KAJgD;AADpB,GAAhB,CAAd;;AASA,QAAMC,kBAAkB,GAAG,MAAM;AAChC,UAAMC,YAAY,GAAG;AACpBC,MAAAA,KAAK,EAAE,cAAI,YAAJ,CADa;AAEpBC,MAAAA,KAAK,EAAE,EAFa;AAGpBC,MAAAA,QAAQ,EAAE;AAHU,KAArB;AAKA,UAAMC,eAAe,GAAG,iBACvB,oBAAQb,UAAR,EAAoB,YAApB,CADuB,EAErBc,IAAF,IAAY;AACX,aAAO;AACNH,QAAAA,KAAK,EAAEG,IAAI,CAACC,IADN;AAENL,QAAAA,KAAK,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oC,iBADH,EAEC,mCAAU,iCAAV,EACC,4BAAC,yBAAD;AACC,IAAA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/tag-cloud/edit.js"],"names":["MIN_TAGS","MAX_TAGS","MIN_FONT_SIZE","MAX_FONT_SIZE","TagCloudEdit","attributes","setAttributes","taxonomies","taxonomy","showTagCounts","numberOfTags","smallestFontSize","largestFontSize","units","availableUnits","getTaxonomyOptions","selectOption","label","value","disabled","taxonomyOptions","item","slug","name","onFontSizeChange","fontSizeLabel","newValue","quantity","newUnit","Number","isFinite","updateObj","Object","entries","forEach","attribute","currentValue","currentQuantity","currentUnit","inspectorControls","selectedTaxonomy","select","coreStore","getTaxonomies","per_page"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AAWA;;AACA;;AACA;;AAKA;;AACA;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG,CAAjB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,QAAQ,GAAG,GAAjB;AAEA,MAAMC,aAAa,GAAG,GAAtB;AACA,MAAMC,aAAa,GAAG,GAAtB;;AAEA,SAASC,YAAT,OAAmE;AAAA,MAA5C;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,aAAd;AAA6BC,IAAAA;AAA7B,GAA4C;AAClE,QAAM;AACLC,IAAAA,QADK;AAELC,IAAAA,aAFK;AAGLC,IAAAA,YAHK;AAILC,IAAAA,gBAJK;AAKLC,IAAAA;AALK,MAMFP,UANJ;AAQA,QAAMQ,KAAK,GAAG,8CAAgB;AAC7BC,IAAAA,cAAc,EAAE,6BAAY,eAAZ,KAAiC,CAChD,GADgD,EAEhD,IAFgD,EAGhD,IAHgD,EAIhD,KAJgD;AADpB,GAAhB,CAAd;;AASA,QAAMC,kBAAkB,GAAG,MAAM;AAChC,UAAMC,YAAY,GAAG;AACpBC,MAAAA,KAAK,EAAE,cAAI,YAAJ,CADa;AAEpBC,MAAA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AKM,KAAF,IAAa;AACvBM,MAAAA,gBAAgB,CAAE,iBAAF,EAAqBN,KAArB,CAAhB;AACA,KALF;AAMC,IAAA,KAAK,EAAGL,KANT;AAOC,IAAA,GAAG,EAAGX,aAPP;AAQC,IAAA,GAAG,EAAGC;AARP,IADD,CAbD,CA1BD,CADD,CADD;AA0DA,SACC,qDACGoC,iBADH,EAEC,mCAAU,iCAAV,EACC,4BAAC,yBAAD;AACC,IAAA,0BAA0B,MAD3B;AAEC,IAAA,KAAK,EAAC,gBAFP;AAGC,IAAA,UAAU,EAAGlC;AAHd,IADD,CAFD,CADD;AAYA;;eAEc,sBAAcoC,MAAF,IAAc;AACxC,SAAO;AACNlC,IAAAA,UAAU,EAAEkC,MAAM,CAAEC,eAAF,CAAN,CAAoBC,aAApB,CAAmC;AAAEC,MAAAA,QAAQ,EAAE,CAAC;AAAb,KAAnC;AADN,GAAP;AAGA,CAJc,EAIVxC,YAJU,C","sourcesContent":["/**\n * External dependencies\n */\nimport { map, filter } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tFlex,\n\tFlexItem,\n\tPanelBody,\n\tToggleControl,\n\tSelectControl,\n\tRangeControl,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n} from '@wordpress/components';\nimport { withSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tuseSetting,\n} from '@wordpress/block-editor';\nimport ServerSideRender from '@wordpress/server-side-render';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Minimum number of tags a user can show using this block.\n *\n * @type {number}\n */\nconst MIN_TAGS = 1;\n\n/**\n * Maximum number of tags a user can show using this block.\n *\n * @type {number}\n */\nconst MAX_TAGS = 100;\n\nconst MIN_FONT_SIZE = 0.1;\nconst MAX_FONT_SIZE = 100;\n\nfunction TagCloudEdit( { attributes, setAttributes, taxonomies } ) {\n\tconst {\n\t\ttaxonomy,\n\t\tshowTagCounts,\n\t\tnumberOfTags,\n\t\tsmallestFontSize,\n\t\tlargestFontSize,\n\t} = attributes;\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t],\n\t} );\n\n\tconst getTaxonomyOptions = () => {\n\t\tconst selectOption = {\n\t\t\tlabel: __( '- Select -' ),\n\t\t\tvalue: '',\n\t\t\tdisabled: true,\n\t\t};\n\t\tconst taxonomyOptions = map(\n\t\t\tfilter( taxonomies, 'show_cloud' ),\n\t\t\t( item ) => {\n\t\t\t\treturn {\n\t\t\t\t\tvalue: item.slug,\n\t\t\t\t\tlabel: item.name,\n\t\t\t\t};\n\t\t\t}\n\t\t);\n\n\t\treturn [ selectOption, ...taxonomyOptions ];\n\t};\n\n\tconst onFontSizeChange = ( fontSizeLabel, newValue ) => {\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst [ quantity, newUnit ] =\n\t\t\tparseQuantityAndUnitFromRawValue( newValue );\n\t\tif ( ! Number.isFinite( quantity ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst updateObj = { [ fontSizeLabel ]: newValue };\n\t\t// We need to keep in sync the `unit` changes to both `smallestFontSize`\n\t\t// and `largestFontSize` attributes.\n\t\tObject.entries( {\n\t\t\tsmallestFontSize,\n\t\t\tlargestFontSize,\n\t\t} ).forEach( ( [ attribute, currentValue ] ) => {\n\t\t\tconst [ currentQuantity, currentUnit ] =\n\t\t\t\tparseQuantityAndUnitFromRawValue( currentValue );\n\t\t\t// Only add an update if the other font size attribute has a different unit.\n\t\t\tif ( attribute !== fontSizeLabel && currentUnit !== newUnit ) {\n\t\t\t\tupdateObj[ attribute ] = `${ currentQuantity }${ newUnit }`;\n\t\t\t}\n\t\t} );\n\t\tsetAttributes( updateObj );\n\t};\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t<SelectControl\n\t\t\t\t\tlabel={ __( 'Taxonomy' ) }\n\t\t\t\t\toptions={ getTaxonomyOptions() }\n\t\t\t\t\tvalue={ taxonomy }\n\t\t\t\t\tonChange={ ( selectedTaxonomy ) =>\n\t\t\t\t\t\tsetAttributes( { taxonomy: selectedTaxonomy } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Show post counts' ) }\n\t\t\t\t\tchecked={ showTagCounts }\n\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\tsetAttributes( { showTagCounts: ! showTagCounts } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<RangeControl\n\t\t\t\t\tlabel={ __( 'Number of tags' ) }\n\t\t\t\t\tvalue={ numberOfTags }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { numberOfTags: value } )\n\t\t\t\t\t}\n\t\t\t\t\tmin={ MIN_TAGS }\n\t\t\t\t\tmax={ MAX_TAGS }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<Flex>\n\t\t\t\t\t<FlexItem isBlock>\n\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\tlabel={ __( 'Smallest size' ) }\n\t\t\t\t\t\t\tvalue={ smallestFontSize }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tonFontSizeChange( 'smallestFontSize', value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t\tmin={ MIN_FONT_SIZE }\n\t\t\t\t\t\t\tmax={ MAX_FONT_SIZE }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem isBlock>\n\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\tlabel={ __( 'Largest size' ) }\n\t\t\t\t\t\t\tvalue={ largestFontSize }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tonFontSizeChange( 'largestFontSize', value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t\tmin={ MIN_FONT_SIZE }\n\t\t\t\t\t\t\tmax={ MAX_FONT_SIZE }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ inspectorControls }\n\t\t\t<div { ...useBlockProps() }>\n\t\t\t\t<ServerSideRender\n\t\t\t\t\tskipBlockSupportAttributes\n\t\t\t\t\tblock=\"core/tag-cloud\"\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default withSelect( ( select ) => {\n\treturn {\n\t\ttaxonomies: select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t};\n} )( TagCloudEdit );\n"]}
|
package/build/tag-cloud/index.js
CHANGED
|
@@ -68,6 +68,14 @@ const metadata = {
|
|
|
68
68
|
spacing: {
|
|
69
69
|
margin: true,
|
|
70
70
|
padding: true
|
|
71
|
+
},
|
|
72
|
+
typography: {
|
|
73
|
+
lineHeight: true,
|
|
74
|
+
__experimentalFontFamily: true,
|
|
75
|
+
__experimentalFontWeight: true,
|
|
76
|
+
__experimentalFontStyle: true,
|
|
77
|
+
__experimentalTextTransform: true,
|
|
78
|
+
__experimentalLetterSpacing: true
|
|
71
79
|
}
|
|
72
80
|
},
|
|
73
81
|
editorStyle: "wp-block-tag-cloud-editor"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/tag-cloud/index.js"],"names":["name","metadata","settings","icon","example","edit","transforms","init"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAEA;;AAXA;AACA;AACA;;AAGA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/tag-cloud/index.js"],"names":["name","metadata","settings","icon","example","edit","transforms","init"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAEA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,UADuB;AAEvBC,EAAAA,OAAO,EAAE,EAFc;AAGvBC,EAAAA,IAAI,EAAJA,aAHuB;AAIvBC,EAAAA,UAAU,EAAVA;AAJuB,CAAjB;;;AAOA,MAAMC,IAAI,GAAG,MAAM,wBAAW;AAAEP,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAX,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { tag as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport transforms from './transforms';\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {},\n\tedit,\n\ttransforms,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}
|
|
@@ -102,14 +102,14 @@ const init = () => {
|
|
|
102
102
|
(0, _hooks.addFilter)('blocks.registerBlockType', 'core/template-part', _variations.enhanceTemplatePartVariations); // Prevent adding template parts inside post templates.
|
|
103
103
|
|
|
104
104
|
const DISALLOWED_PARENTS = ['core/post-template', 'core/post-content'];
|
|
105
|
-
(0, _hooks.addFilter)('blockEditor.__unstableCanInsertBlockType', 'removeTemplatePartsFromPostTemplates', (
|
|
105
|
+
(0, _hooks.addFilter)('blockEditor.__unstableCanInsertBlockType', 'removeTemplatePartsFromPostTemplates', (canInsert, blockType, rootClientId, _ref2) => {
|
|
106
106
|
let {
|
|
107
107
|
getBlock,
|
|
108
108
|
getBlockParentsByBlockName
|
|
109
109
|
} = _ref2;
|
|
110
110
|
|
|
111
111
|
if (blockType.name !== 'core/template-part') {
|
|
112
|
-
return
|
|
112
|
+
return canInsert;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
for (const disallowedParentType of DISALLOWED_PARENTS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/template-part/index.js"],"names":["name","metadata","settings","icon","symbolFilled","__experimentalLabel","slug","theme","entity","coreDataStore","getEntityRecord","title","rendered","edit","init","enhanceTemplatePartVariations","DISALLOWED_PARENTS","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/template-part/index.js"],"names":["name","metadata","settings","icon","symbolFilled","__experimentalLabel","slug","theme","entity","coreDataStore","getEntityRecord","title","rendered","edit","init","enhanceTemplatePartVariations","DISALLOWED_PARENTS","canInsert","blockType","rootClientId","getBlock","getBlockParentsByBlockName","disallowedParentType","hasDisallowedParent","length"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAEA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAGO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAEC,mBADiB;AAEvBC,EAAAA,mBAAmB,EAAE,QAAuB;AAAA;;AAAA,QAArB;AAAEC,MAAAA,IAAF;AAAQC,MAAAA;AAAR,KAAqB;;AAC3C;AACA;AACA,QAAK,CAAED,IAAP,EAAc;AACb;AACA;;AAED,UAAME,MAAM,GAAG,kBAAQC,eAAR,EAAwBC,eAAxB,CACd,UADc,EAEd,kBAFc,EAGdH,KAAK,GAAG,IAAR,GAAeD,IAHD,CAAf;;AAKA,QAAK,CAAEE,MAAP,EAAgB;AACf;AACA;;AAED,WACC,mDAAgBA,MAAM,CAACG,KAAvB,kDAAgB,cAAcC,QAA9B,KACA,6BAAaJ,MAAM,CAACF,IAApB,CAFD;AAIA,GAtBsB;AAuBvBO,EAAAA,IAAI,EAAJA;AAvBuB,CAAjB;;;AA0BA,MAAMC,IAAI,GAAG,MAAM;AACzB,wBACC,0BADD,EAEC,oBAFD,EAGCC,yCAHD,EADyB,CAOzB;;AACA,QAAMC,kBAAkB,GAAG,CAAE,oBAAF,EAAwB,mBAAxB,CAA3B;AACA,wBACC,0CADD,EAEC,sCAFD,EAGC,CACCC,SADD,EAECC,SAFD,EAGCC,YAHD,YAKK;AAAA,QADJ;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,KACI;;AACJ,QAAKH,SAAS,CAAClB,IAAV,KAAmB,oBAAxB,EAA+C;AAC9C,aAAOiB,SAAP;AACA;;AAED,SAAM,MAAMK,oBAAZ,IAAoCN,kBAApC,EAAyD;AAAA;;AACxD,YAAMO,mBAAmB,GACxB,cAAAH,QAAQ,CAAED,YAAF,CAAR,wDAA0BnB,IAA1B,MAAmCsB,oBAAnC,IACAD,0BAA0B,CACzBF,YADyB,EAEzBG,oBAFyB,CAA1B,CAGEE,MALH;;AAMA,UAAKD,mBAAL,EAA2B;AAC1B,eAAO,KAAP;AACA;AACD;;AACD,WAAO,IAAP;AACA,GAzBF;AA4BA,SAAO,wBAAW;AAAEvB,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA;AAAlB,GAAX,CAAP;AACA,CAtCM","sourcesContent":["/**\n * External dependencies\n */\nimport { capitalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { select } from '@wordpress/data';\nimport { symbolFilled } from '@wordpress/icons';\nimport { addFilter } from '@wordpress/hooks';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport { enhanceTemplatePartVariations } from './variations';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon: symbolFilled,\n\t__experimentalLabel: ( { slug, theme } ) => {\n\t\t// Attempt to find entity title if block is a template part.\n\t\t// Require slug to request, otherwise entity is uncreated and will throw 404.\n\t\tif ( ! slug ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst entity = select( coreDataStore ).getEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template_part',\n\t\t\ttheme + '//' + slug\n\t\t);\n\t\tif ( ! entity ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn (\n\t\t\tdecodeEntities( entity.title?.rendered ) ||\n\t\t\tcapitalCase( entity.slug )\n\t\t);\n\t},\n\tedit,\n};\n\nexport const init = () => {\n\taddFilter(\n\t\t'blocks.registerBlockType',\n\t\t'core/template-part',\n\t\tenhanceTemplatePartVariations\n\t);\n\n\t// Prevent adding template parts inside post templates.\n\tconst DISALLOWED_PARENTS = [ 'core/post-template', 'core/post-content' ];\n\taddFilter(\n\t\t'blockEditor.__unstableCanInsertBlockType',\n\t\t'removeTemplatePartsFromPostTemplates',\n\t\t(\n\t\t\tcanInsert,\n\t\t\tblockType,\n\t\t\trootClientId,\n\t\t\t{ getBlock, getBlockParentsByBlockName }\n\t\t) => {\n\t\t\tif ( blockType.name !== 'core/template-part' ) {\n\t\t\t\treturn canInsert;\n\t\t\t}\n\n\t\t\tfor ( const disallowedParentType of DISALLOWED_PARENTS ) {\n\t\t\t\tconst hasDisallowedParent =\n\t\t\t\t\tgetBlock( rootClientId )?.name === disallowedParentType ||\n\t\t\t\t\tgetBlockParentsByBlockName(\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tdisallowedParentType\n\t\t\t\t\t).length;\n\t\t\t\tif ( hasDisallowedParent ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t);\n\n\treturn initBlock( { name, metadata, settings } );\n};\n"]}
|
package/build/video/edit.js
CHANGED
|
@@ -48,6 +48,17 @@ var _tracks = _interopRequireDefault(require("./tracks"));
|
|
|
48
48
|
/**
|
|
49
49
|
* Internal dependencies
|
|
50
50
|
*/
|
|
51
|
+
// Much of this description is duplicated from MediaPlaceholder.
|
|
52
|
+
const placeholder = content => {
|
|
53
|
+
return (0, _element.createElement)(_components.Placeholder, {
|
|
54
|
+
className: "block-editor-media-placeholder",
|
|
55
|
+
withIllustration: true,
|
|
56
|
+
icon: _icons.video,
|
|
57
|
+
label: (0, _i18n.__)('Video'),
|
|
58
|
+
instructions: (0, _i18n.__)('Upload a video file, pick one from your media library, or add one with a URL.')
|
|
59
|
+
}, content);
|
|
60
|
+
};
|
|
61
|
+
|
|
51
62
|
const ALLOWED_MEDIA_TYPES = ['video'];
|
|
52
63
|
const VIDEO_POSTER_ALLOWED_MEDIA_TYPES = ['image'];
|
|
53
64
|
|
|
@@ -170,7 +181,8 @@ function VideoEdit(_ref) {
|
|
|
170
181
|
accept: "video/*",
|
|
171
182
|
allowedTypes: ALLOWED_MEDIA_TYPES,
|
|
172
183
|
value: attributes,
|
|
173
|
-
onError: onUploadError
|
|
184
|
+
onError: onUploadError,
|
|
185
|
+
placeholder: placeholder
|
|
174
186
|
}));
|
|
175
187
|
}
|
|
176
188
|
|
package/build/video/edit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/video/edit.js"],"names":["ALLOWED_MEDIA_TYPES","VIDEO_POSTER_ALLOWED_MEDIA_TYPES","VideoEdit","isSelected","attributes","className","setAttributes","insertBlocksAfter","onReplace","instanceId","videoPlayer","posterImageButton","id","caption","controls","poster","src","tracks","isTemporaryVideo","mediaUpload","select","blockEditorStore","getSettings","file","filesList","onFileChange","media","onSelectVideo","onError","onUploadError","allowedTypes","current","load","url","undefined","image","icon","onSelectURL","newSrc","embedBlock","createErrorNotice","noticesStore","message","type","classes","blockProps","onSelectPoster","onRemovePoster","focus","videoPosterDescription","newTracks","open","RichText","isEmpty","value"],"mappings":";;;;;;;;;AA6BA;;AA1BA;;AAKA;;AACA;;AAOA;;AAcA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA3CA;AACA;AACA;;AAGA;AACA;AACA;;AA8BA;AACA;AACA;AAMA,MAAMA,mBAAmB,GAAG,CAAE,OAAF,CAA5B;AACA,MAAMC,gCAAgC,GAAG,CAAE,OAAF,CAAzC;;AAEA,SAASC,SAAT,OAOI;AAAA,MAPgB;AACnBC,IAAAA,UADmB;AAEnBC,IAAAA,UAFmB;AAGnBC,IAAAA,SAHmB;AAInBC,IAAAA,aAJmB;AAKnBC,IAAAA,iBALmB;AAMnBC,IAAAA;AANmB,GAOhB;AACH,QAAMC,UAAU,GAAG,4BAAeP,SAAf,CAAnB;AACA,QAAMQ,WAAW,GAAG,sBAApB;AACA,QAAMC,iBAAiB,GAAG,sBAA1B;AACA,QAAM;AAAEC,IAAAA,EAAF;AAAMC,IAAAA,OAAN;AAAeC,IAAAA,QAAf;AAAyBC,IAAAA,MAAzB;AAAiCC,IAAAA,GAAjC;AAAsCC,IAAAA;AAAtC,MAAiDb,UAAvD;AACA,QAAMc,gBAAgB,GAAG,CAAEN,EAAF,IAAQ,qBAAWI,GAAX,CAAjC;AACA,QAAMG,WAAW,GAAG,qBACjBC,MAAF,IAAcA,MAAM,CAAEC,kBAAF,CAAN,CAA2BC,WAA3B,GAAyCH,WADpC,EAEnB,EAFmB,CAApB;AAKA,0BAAW,MAAM;AAChB,QAAK,CAAEP,EAAF,IAAQ,qBAAWI,GAAX,CAAb,EAAgC;AAC/B,YAAMO,IAAI,GAAG,wBAAcP,GAAd,CAAb;;AACA,UAAKO,IAAL,EAAY;AACXJ,QAAAA,WAAW,CAAE;AACZK,UAAAA,SAAS,EAAE,CAAED,IAAF,CADC;AAEZE,UAAAA,YAAY,EAAE;AAAA,gBAAE,CAAEC,KAAF,CAAF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classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { getBlobByURL, isBlobURL } from '@wordpress/blob';\nimport {\n\tBaseControl,\n\tButton,\n\tDisabled,\n\tPanelBody,\n\tSpinner,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tMediaPlaceholder,\n\tMediaUpload,\n\tMediaUploadCheck,\n\tMediaReplaceFlow,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\nimport { useRef, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { video as icon } from '@wordpress/icons';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { createUpgradedEmbedBlock } from '../embed/util';\nimport VideoCommonSettings from './edit-common-settings';\nimport TracksEditor from './tracks-editor';\nimport Tracks from './tracks';\n\nconst ALLOWED_MEDIA_TYPES = [ 'video' ];\nconst VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];\n\nfunction VideoEdit( {\n\tisSelected,\n\tattributes,\n\tclassName,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tonReplace,\n} ) {\n\tconst instanceId = useInstanceId( VideoEdit );\n\tconst videoPlayer = useRef();\n\tconst posterImageButton = useRef();\n\tconst { id, caption, controls, poster, src, tracks } = attributes;\n\tconst isTemporaryVideo = ! id && isBlobURL( src );\n\tconst mediaUpload = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( ! id && isBlobURL( src ) ) {\n\t\t\tconst file = getBlobByURL( src );\n\t\t\tif ( file ) {\n\t\t\t\tmediaUpload( {\n\t\t\t\t\tfilesList: [ file ],\n\t\t\t\t\tonFileChange: ( [ media ] ) => onSelectVideo( media ),\n\t\t\t\t\tonError: onUploadError,\n\t\t\t\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}, [] );\n\n\tuseEffect( () => {\n\t\t// Placeholder may be rendered.\n\t\tif ( videoPlayer.current ) {\n\t\t\tvideoPlayer.current.load();\n\t\t}\n\t}, [ poster ] );\n\n\tfunction onSelectVideo( media ) {\n\t\tif ( ! media || ! media.url ) {\n\t\t\t// In this case there was an error\n\t\t\t// previous attributes should be removed\n\t\t\t// because they may be temporary blob urls.\n\t\t\tsetAttributes( {\n\t\t\t\tsrc: undefined,\n\t\t\t\tid: undefined,\n\t\t\t\tposter: undefined,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\t// Sets the block's attribute and updates the edit component from the\n\t\t// selected media.\n\t\tsetAttributes( {\n\t\t\tsrc: media.url,\n\t\t\tid: media.id,\n\t\t\tposter:\n\t\t\t\tmedia.image?.src !== media.icon ? media.image?.src : undefined,\n\t\t} );\n\t}\n\n\tfunction onSelectURL( newSrc ) {\n\t\tif ( newSrc !== src ) {\n\t\t\t// Check if there's an embed block that handles this URL.\n\t\t\tconst embedBlock = createUpgradedEmbedBlock( {\n\t\t\t\tattributes: { url: newSrc },\n\t\t\t} );\n\t\t\tif ( undefined !== embedBlock ) {\n\t\t\t\tonReplace( embedBlock );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetAttributes( { src: newSrc, id: undefined, poster: undefined } );\n\t\t}\n\t}\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tfunction onUploadError( message ) {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t}\n\n\tconst classes = classnames( className, {\n\t\t'is-transient': isTemporaryVideo,\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classes,\n\t} );\n\n\tif ( ! src ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<MediaPlaceholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tonSelect={ onSelectVideo }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\taccept=\"video/*\"\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\tvalue={ attributes }\n\t\t\t\t\tonError={ onUploadError }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tfunction onSelectPoster( image ) {\n\t\tsetAttributes( { poster: image.url } );\n\t}\n\n\tfunction onRemovePoster() {\n\t\tsetAttributes( { poster: undefined } );\n\n\t\t// Move focus back to the Media Upload button.\n\t\tposterImageButton.current.focus();\n\t}\n\n\tconst videoPosterDescription = `video-block__poster-image-description-${ instanceId }`;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<TracksEditor\n\t\t\t\t\ttracks={ tracks }\n\t\t\t\t\tonChange={ ( newTracks ) => {\n\t\t\t\t\t\tsetAttributes( { tracks: newTracks } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\tmediaId={ id }\n\t\t\t\t\tmediaURL={ src }\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\taccept=\"video/*\"\n\t\t\t\t\tonSelect={ onSelectVideo }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonError={ onUploadError }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t<VideoCommonSettings\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t/>\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<BaseControl className=\"editor-video-poster-control\">\n\t\t\t\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t\t\t\t{ __( 'Poster image' ) }\n\t\t\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\t\ttitle={ __( 'Select poster image' ) }\n\t\t\t\t\t\t\t\tonSelect={ onSelectPoster }\n\t\t\t\t\t\t\t\tallowedTypes={\n\t\t\t\t\t\t\t\t\tVIDEO_POSTER_ALLOWED_MEDIA_TYPES\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tref={ posterImageButton }\n\t\t\t\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t\t\t\tvideoPosterDescription\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ ! poster\n\t\t\t\t\t\t\t\t\t\t\t? __( 'Select' )\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Replace' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<p id={ videoPosterDescription } hidden>\n\t\t\t\t\t\t\t\t{ poster\n\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: poster image URL. */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'The current poster image url is %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\tposter\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t'There is no poster image currently selected'\n\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t{ !! poster && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tonClick={ onRemovePoster }\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Remove' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</BaseControl>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<figure { ...blockProps }>\n\t\t\t\t{ /*\n\t\t\t\t\tDisable the video tag if the block is not selected\n\t\t\t\t\tso the user clicking on it won't play the\n\t\t\t\t\tvideo when the controls are enabled.\n\t\t\t\t*/ }\n\t\t\t\t<Disabled isDisabled={ ! isSelected }>\n\t\t\t\t\t<video\n\t\t\t\t\t\tcontrols={ controls }\n\t\t\t\t\t\tposter={ poster }\n\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\tref={ videoPlayer }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Tracks tracks={ tracks } />\n\t\t\t\t\t</video>\n\t\t\t\t</Disabled>\n\t\t\t\t{ isTemporaryVideo && <Spinner /> }\n\t\t\t\t{ ( ! RichText.isEmpty( caption ) || isSelected ) && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\t\tclassName={ __experimentalGetElementClassName(\n\t\t\t\t\t\t\t'caption'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\taria-label={ __( 'Video caption text' ) }\n\t\t\t\t\t\tplaceholder={ __( 'Add caption' ) }\n\t\t\t\t\t\tvalue={ caption }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tinlineToolbar\n\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</figure>\n\t\t</>\n\t);\n}\n\nexport default VideoEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/video/edit.js"],"names":["placeholder","content","icon","ALLOWED_MEDIA_TYPES","VIDEO_POSTER_ALLOWED_MEDIA_TYPES","VideoEdit","isSelected","attributes","className","setAttributes","insertBlocksAfter","onReplace","instanceId","videoPlayer","posterImageButton","id","caption","controls","poster","src","tracks","isTemporaryVideo","mediaUpload","select","blockEditorStore","getSettings","file","filesList","onFileChange","media","onSelectVideo","onError","onUploadError","allowedTypes","current","load","url","undefined","image","onSelectURL","newSrc","embedBlock","createErrorNotice","noticesStore","message","type","classes","blockProps","onSelectPoster","onRemovePoster","focus","videoPosterDescription","newTracks","open","RichText","isEmpty","value"],"mappings":";;;;;;;;;AA8BA;;AA3BA;;AAKA;;AACA;;AAQA;;AAcA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA5CA;AACA;AACA;;AAGA;AACA;AACA;;AA+BA;AACA;AACA;AAMA;AACA,MAAMA,WAAW,GAAKC,OAAF,IAAe;AAClC,SACC,4BAAC,uBAAD;AACC,IAAA,SAAS,EAAC,gCADX;AAEC,IAAA,gBAAgB,EAAG,IAFpB;AAGC,IAAA,IAAI,EAAGC,YAHR;AAIC,IAAA,KAAK,EAAG,cAAI,OAAJ,CAJT;AAKC,IAAA,YAAY,EAAG,cACd,+EADc;AALhB,KASGD,OATH,CADD;AAaA,CAdD;;AAgBA,MAAME,mBAAmB,GAAG,CAAE,OAAF,CAA5B;AACA,MAAMC,gCAAgC,GAAG,CAAE,OAAF,CAAzC;;AAEA,SAASC,SAAT,OAOI;AAAA,MAPgB;AACnBC,IAAAA,UADmB;AAEnBC,IAAAA,UAFmB;AAGnBC,IA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EA6EC,sCAAaF,UAAb,EAMC,4BAAC,oBAAD;AAAU,IAAA,UAAU,EAAG,CAAEzC;AAAzB,KACC;AACC,IAAA,QAAQ,EAAGW,QADZ;AAEC,IAAA,MAAM,EAAGC,MAFV;AAGC,IAAA,GAAG,EAAGC,GAHP;AAIC,IAAA,GAAG,EAAGN;AAJP,KAMC,4BAAC,eAAD;AAAQ,IAAA,MAAM,EAAGO;AAAjB,IAND,CADD,CAND,EAgBGC,gBAAgB,IAAI,4BAAC,mBAAD,OAhBvB,EAiBG,CAAE,CAAEiC,sBAASC,OAAT,CAAkBvC,OAAlB,CAAF,IAAiCV,UAAnC,KACD,4BAAC,qBAAD;AACC,IAAA,OAAO,EAAC,YADT;AAEC,IAAA,SAAS,EAAG,oDACX,SADW,CAFb;AAKC,kBAAa,cAAI,oBAAJ,CALd;AAMC,IAAA,WAAW,EAAG,cAAI,aAAJ,CANf;AAOC,IAAA,KAAK,EAAGU,OAPT;AAQC,IAAA,QAAQ,EAAKwC,KAAF,IACV/C,aAAa,CAAE;AAAEO,MAAAA,OAAO,EAAEwC;AAAX,KAAF,CATf;AAWC,IAAA,aAAa,MAXd;AAYC,IAAA,sBAAsB,EAAG,MACxB9C,iBAAiB,CAChB,yBAAa,kCAAb,CADgB;AAbnB,IAlBF,CA7ED,CADD;AAsHA;;eAEcL,S","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { getBlobByURL, isBlobURL } from '@wordpress/blob';\nimport {\n\tBaseControl,\n\tButton,\n\tDisabled,\n\tPanelBody,\n\tSpinner,\n\tPlaceholder,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tMediaPlaceholder,\n\tMediaUpload,\n\tMediaUploadCheck,\n\tMediaReplaceFlow,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\nimport { useRef, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { video as icon } from '@wordpress/icons';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { createUpgradedEmbedBlock } from '../embed/util';\nimport VideoCommonSettings from './edit-common-settings';\nimport TracksEditor from './tracks-editor';\nimport Tracks from './tracks';\n\n// Much of this description is duplicated from MediaPlaceholder.\nconst placeholder = ( content ) => {\n\treturn (\n\t\t<Placeholder\n\t\t\tclassName=\"block-editor-media-placeholder\"\n\t\t\twithIllustration={ true }\n\t\t\ticon={ icon }\n\t\t\tlabel={ __( 'Video' ) }\n\t\t\tinstructions={ __(\n\t\t\t\t'Upload a video file, pick one from your media library, or add one with a URL.'\n\t\t\t) }\n\t\t>\n\t\t\t{ content }\n\t\t</Placeholder>\n\t);\n};\n\nconst ALLOWED_MEDIA_TYPES = [ 'video' ];\nconst VIDEO_POSTER_ALLOWED_MEDIA_TYPES = [ 'image' ];\n\nfunction VideoEdit( {\n\tisSelected,\n\tattributes,\n\tclassName,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tonReplace,\n} ) {\n\tconst instanceId = useInstanceId( VideoEdit );\n\tconst videoPlayer = useRef();\n\tconst posterImageButton = useRef();\n\tconst { id, caption, controls, poster, src, tracks } = attributes;\n\tconst isTemporaryVideo = ! id && isBlobURL( src );\n\tconst mediaUpload = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( ! id && isBlobURL( src ) ) {\n\t\t\tconst file = getBlobByURL( src );\n\t\t\tif ( file ) {\n\t\t\t\tmediaUpload( {\n\t\t\t\t\tfilesList: [ file ],\n\t\t\t\t\tonFileChange: ( [ media ] ) => onSelectVideo( media ),\n\t\t\t\t\tonError: onUploadError,\n\t\t\t\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}, [] );\n\n\tuseEffect( () => {\n\t\t// Placeholder may be rendered.\n\t\tif ( videoPlayer.current ) {\n\t\t\tvideoPlayer.current.load();\n\t\t}\n\t}, [ poster ] );\n\n\tfunction onSelectVideo( media ) {\n\t\tif ( ! media || ! media.url ) {\n\t\t\t// In this case there was an error\n\t\t\t// previous attributes should be removed\n\t\t\t// because they may be temporary blob urls.\n\t\t\tsetAttributes( {\n\t\t\t\tsrc: undefined,\n\t\t\t\tid: undefined,\n\t\t\t\tposter: undefined,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\t// Sets the block's attribute and updates the edit component from the\n\t\t// selected media.\n\t\tsetAttributes( {\n\t\t\tsrc: media.url,\n\t\t\tid: media.id,\n\t\t\tposter:\n\t\t\t\tmedia.image?.src !== media.icon ? media.image?.src : undefined,\n\t\t} );\n\t}\n\n\tfunction onSelectURL( newSrc ) {\n\t\tif ( newSrc !== src ) {\n\t\t\t// Check if there's an embed block that handles this URL.\n\t\t\tconst embedBlock = createUpgradedEmbedBlock( {\n\t\t\t\tattributes: { url: newSrc },\n\t\t\t} );\n\t\t\tif ( undefined !== embedBlock ) {\n\t\t\t\tonReplace( embedBlock );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetAttributes( { src: newSrc, id: undefined, poster: undefined } );\n\t\t}\n\t}\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tfunction onUploadError( message ) {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t}\n\n\tconst classes = classnames( className, {\n\t\t'is-transient': isTemporaryVideo,\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classes,\n\t} );\n\n\tif ( ! src ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<MediaPlaceholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tonSelect={ onSelectVideo }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\taccept=\"video/*\"\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\tvalue={ attributes }\n\t\t\t\t\tonError={ onUploadError }\n\t\t\t\t\tplaceholder={ placeholder }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tfunction onSelectPoster( image ) {\n\t\tsetAttributes( { poster: image.url } );\n\t}\n\n\tfunction onRemovePoster() {\n\t\tsetAttributes( { poster: undefined } );\n\n\t\t// Move focus back to the Media Upload button.\n\t\tposterImageButton.current.focus();\n\t}\n\n\tconst videoPosterDescription = `video-block__poster-image-description-${ instanceId }`;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<TracksEditor\n\t\t\t\t\ttracks={ tracks }\n\t\t\t\t\tonChange={ ( newTracks ) => {\n\t\t\t\t\t\tsetAttributes( { tracks: newTracks } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\tmediaId={ id }\n\t\t\t\t\tmediaURL={ src }\n\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\taccept=\"video/*\"\n\t\t\t\t\tonSelect={ onSelectVideo }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonError={ onUploadError }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t<VideoCommonSettings\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t/>\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<BaseControl className=\"editor-video-poster-control\">\n\t\t\t\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t\t\t\t{ __( 'Poster image' ) }\n\t\t\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\t\ttitle={ __( 'Select poster image' ) }\n\t\t\t\t\t\t\t\tonSelect={ onSelectPoster }\n\t\t\t\t\t\t\t\tallowedTypes={\n\t\t\t\t\t\t\t\t\tVIDEO_POSTER_ALLOWED_MEDIA_TYPES\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tref={ posterImageButton }\n\t\t\t\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t\t\t\tvideoPosterDescription\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ ! poster\n\t\t\t\t\t\t\t\t\t\t\t? __( 'Select' )\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Replace' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<p id={ videoPosterDescription } hidden>\n\t\t\t\t\t\t\t\t{ poster\n\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: poster image URL. */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'The current poster image url is %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\tposter\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t'There is no poster image currently selected'\n\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t{ !! poster && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tonClick={ onRemovePoster }\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Remove' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</BaseControl>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<figure { ...blockProps }>\n\t\t\t\t{ /*\n\t\t\t\t\tDisable the video tag if the block is not selected\n\t\t\t\t\tso the user clicking on it won't play the\n\t\t\t\t\tvideo when the controls are enabled.\n\t\t\t\t*/ }\n\t\t\t\t<Disabled isDisabled={ ! isSelected }>\n\t\t\t\t\t<video\n\t\t\t\t\t\tcontrols={ controls }\n\t\t\t\t\t\tposter={ poster }\n\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\tref={ videoPlayer }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Tracks tracks={ tracks } />\n\t\t\t\t\t</video>\n\t\t\t\t</Disabled>\n\t\t\t\t{ isTemporaryVideo && <Spinner /> }\n\t\t\t\t{ ( ! RichText.isEmpty( caption ) || isSelected ) && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\t\tclassName={ __experimentalGetElementClassName(\n\t\t\t\t\t\t\t'caption'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\taria-label={ __( 'Video caption text' ) }\n\t\t\t\t\t\tplaceholder={ __( 'Add caption' ) }\n\t\t\t\t\t\tvalue={ caption }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tinlineToolbar\n\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</figure>\n\t\t</>\n\t);\n}\n\nexport default VideoEdit;\n"]}
|
|
@@ -59,6 +59,7 @@ export default function ArchivesEdit(_ref) {
|
|
|
59
59
|
})
|
|
60
60
|
}))), createElement("div", useBlockProps(), createElement(Disabled, null, createElement(ServerSideRender, {
|
|
61
61
|
block: "core/archives",
|
|
62
|
+
skipBlockSupportAttributes: true,
|
|
62
63
|
attributes: attributes
|
|
63
64
|
}))));
|
|
64
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/archives/edit.js"],"names":["PanelBody","ToggleControl","SelectControl","Disabled","__","InspectorControls","useBlockProps","ServerSideRender","ArchivesEdit","attributes","setAttributes","showLabel","showPostCounts","displayAsDropdown","type","label","value"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,SADD,EAECC,aAFD,EAGCC,aAHD,EAICC,QAJD,QAKO,uBALP;AAMA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,iBAAT,EAA4BC,aAA5B,QAAiD,yBAAjD;AACA,OAAOC,gBAAP,MAA6B,+BAA7B;AAEA,eAAe,SAASC,YAAT,OAAuD;AAAA,MAAhC;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAAgC;AACrE,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,cAAb;AAA6BC,IAAAA,iBAA7B;AAAgDC,IAAAA;AAAhD,MAAyDL,UAA/D;AAEA,SACC,8BACC,cAAC,iBAAD,QACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGL,EAAE,CAAE,UAAF;AAArB,KACC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGA,EAAE,CAAE,qBAAF,CADX;AAEC,IAAA,OAAO,EAAGS,iBAFX;AAGC,IAAA,QAAQ,EAAG,MACVH,aAAa,CAAE;AACdG,MAAAA,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/src/archives/edit.js"],"names":["PanelBody","ToggleControl","SelectControl","Disabled","__","InspectorControls","useBlockProps","ServerSideRender","ArchivesEdit","attributes","setAttributes","showLabel","showPostCounts","displayAsDropdown","type","label","value"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,SADD,EAECC,aAFD,EAGCC,aAHD,EAICC,QAJD,QAKO,uBALP;AAMA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,iBAAT,EAA4BC,aAA5B,QAAiD,yBAAjD;AACA,OAAOC,gBAAP,MAA6B,+BAA7B;AAEA,eAAe,SAASC,YAAT,OAAuD;AAAA,MAAhC;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAAgC;AACrE,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,cAAb;AAA6BC,IAAAA,iBAA7B;AAAgDC,IAAAA;AAAhD,MAAyDL,UAA/D;AAEA,SACC,8BACC,cAAC,iBAAD,QACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGL,EAAE,CAAE,UAAF;AAArB,KACC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGA,EAAE,CAAE,qBAAF,CADX;AAEC,IAAA,OAAO,EAAGS,iBAFX;AAGC,IAAA,QAAQ,EAAG,MACVH,aAAa,CAAE;AACdG,MAAAA,iBAAiB,EAAE,CAAEA;AADP,KAAF;AAJf,IADD,EAUGA,iBAAiB,IAClB,cAAC,aAAD;AACC,IAAA,KAAK,EAAGT,EAAE,CAAE,YAAF,CADX;AAEC,IAAA,OAAO,EAAGO,SAFX;AAGC,IAAA,QAAQ,EAAG,MACVD,aAAa,CAAE;AACdC,MAAAA,SAAS,EAAE,CAAEA;AADC,KAAF;AAJf,IAXF,EAqBC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGP,EAAE,CAAE,kBAAF,CADX;AAEC,IAAA,OAAO,EAAGQ,cAFX;AAGC,IAAA,QAAQ,EAAG,MACVF,aAAa,CAAE;AACdE,MAAAA,cAAc,EAAE,CAAEA;AADJ,KAAF;AAJf,IArBD,EA8BC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGR,EAAE,CAAE,WAAF,CADX;AAEC,IAAA,OAAO,EAAG,CACT;AAAEW,MAAAA,KAAK,EAAEX,EAAE,CAAE,MAAF,CAAX;AAAuBY,MAAAA,KAAK,EAAE;AAA9B,KADS,EAET;AAAED,MAAAA,KAAK,EAAEX,EAAE,CAAE,OAAF,CAAX;AAAwBY,MAAAA,KAAK,EAAE;AAA/B,KAFS,EAGT;AAAED,MAAAA,KAAK,EAAEX,EAAE,CAAE,MAAF,CAAX;AAAuBY,MAAAA,KAAK,EAAE;AAA9B,KAHS,EAIT;AAAED,MAAAA,KAAK,EAAEX,EAAE,CAAE,KAAF,CAAX;AAAsBY,MAAAA,KAAK,EAAE;AAA7B,KAJS,CAFX;AAQC,IAAA,KAAK,EAAGF,IART;AASC,IAAA,QAAQ,EAAKE,KAAF,IACVN,aAAa,CAAE;AAAEI,MAAAA,IAAI,EAAEE;AAAR,KAAF;AAVf,IA9BD,CADD,CADD,EA+CC,qBAAUV,aAAa,EAAvB,EACC,cAAC,QAAD,QACC,cAAC,gBAAD;AACC,IAAA,KAAK,EAAC,eADP;AAEC,IAAA,0BAA0B,MAF3B;AAGC,IAAA,UAAU,EAAGG;AAHd,IADD,CADD,CA/CD,CADD;AA2DA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tPanelBody,\n\tToggleControl,\n\tSelectControl,\n\tDisabled,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls, useBlockProps } from '@wordpress/block-editor';\nimport ServerSideRender from '@wordpress/server-side-render';\n\nexport default function ArchivesEdit( { attributes, setAttributes } ) {\n\tconst { showLabel, showPostCounts, displayAsDropdown, type } = attributes;\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Display as dropdown' ) }\n\t\t\t\t\t\tchecked={ displayAsDropdown }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdisplayAsDropdown: ! displayAsDropdown,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t{ displayAsDropdown && (\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Show label' ) }\n\t\t\t\t\t\t\tchecked={ showLabel }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowLabel: ! showLabel,\n\t\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) }\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Show post counts' ) }\n\t\t\t\t\t\tchecked={ showPostCounts }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowPostCounts: ! showPostCounts,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ __( 'Group by:' ) }\n\t\t\t\t\t\toptions={ [\n\t\t\t\t\t\t\t{ label: __( 'Year' ), value: 'yearly' },\n\t\t\t\t\t\t\t{ label: __( 'Month' ), value: 'monthly' },\n\t\t\t\t\t\t\t{ label: __( 'Week' ), value: 'weekly' },\n\t\t\t\t\t\t\t{ label: __( 'Day' ), value: 'daily' },\n\t\t\t\t\t\t] }\n\t\t\t\t\t\tvalue={ type }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { type: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...useBlockProps() }>\n\t\t\t\t<Disabled>\n\t\t\t\t\t<ServerSideRender\n\t\t\t\t\t\tblock=\"core/archives\"\n\t\t\t\t\t\tskipBlockSupportAttributes\n\t\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\t/>\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { pipe } from '@wordpress/compose';
|
|
5
5
|
/**
|
|
6
6
|
* Escapes ampersands, shortcodes, and links.
|
|
7
7
|
*
|
|
@@ -10,7 +10,7 @@ import { flow } from 'lodash';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
export function escape(content) {
|
|
13
|
-
return
|
|
13
|
+
return pipe(escapeOpeningSquareBrackets, escapeProtocolInIsolatedUrls)(content || '');
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Returns the given content with all opening shortcode characters converted
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/code/utils.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/code/utils.js"],"names":["pipe","escape","content","escapeOpeningSquareBrackets","escapeProtocolInIsolatedUrls","replace"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,oBAArB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,MAAT,CAAiBC,OAAjB,EAA2B;AACjC,SAAOF,IAAI,CACVG,2BADU,EAEVC,4BAFU,CAAJ,CAGJF,OAAO,IAAI,EAHP,CAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,2BAAT,CAAsCD,OAAtC,EAAgD;AAC/C,SAAOA,OAAO,CAACG,OAAR,CAAiB,KAAjB,EAAwB,OAAxB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASD,4BAAT,CAAuCF,OAAvC,EAAiD;AAChD,SAAOA,OAAO,CAACG,OAAR,CACN,mCADM,EAEN,gBAFM,CAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { pipe } from '@wordpress/compose';\n\n/**\n * Escapes ampersands, shortcodes, and links.\n *\n * @param {string} content The content of a code block.\n * @return {string} The given content with some characters escaped.\n */\nexport function escape( content ) {\n\treturn pipe(\n\t\tescapeOpeningSquareBrackets,\n\t\tescapeProtocolInIsolatedUrls\n\t)( content || '' );\n}\n\n/**\n * Returns the given content with all opening shortcode characters converted\n * into their HTML entity counterpart (i.e. [ => [). For instance, a\n * shortcode like [embed] becomes [embed]\n *\n * This function replicates the escaping of HTML tags, where a tag like\n * <strong> becomes <strong>.\n *\n * @param {string} content The content of a code block.\n * @return {string} The given content with its opening shortcode characters\n * converted into their HTML entity counterpart\n * (i.e. [ => [)\n */\nfunction escapeOpeningSquareBrackets( content ) {\n\treturn content.replace( /\\[/g, '[' );\n}\n\n/**\n * Converts the first two forward slashes of any isolated URL into their HTML\n * counterparts (i.e. // => //). For instance, https://youtube.com/watch?x\n * becomes https://youtube.com/watch?x.\n *\n * An isolated URL is a URL that sits in its own line, surrounded only by spacing\n * characters.\n *\n * See https://github.com/WordPress/wordpress-develop/blob/5.1.1/src/wp-includes/class-wp-embed.php#L403\n *\n * @param {string} content The content of a code block.\n * @return {string} The given content with its ampersands converted into\n * their HTML entity counterpart (i.e. & => &)\n */\nfunction escapeProtocolInIsolatedUrls( content ) {\n\treturn content.replace(\n\t\t/^(\\s*https?:)\\/\\/([^\\s<>\"]+\\s*)$/m,\n\t\t'$1//$2'\n\t);\n}\n"]}
|
|
@@ -25,6 +25,7 @@ const TEMPLATE = [['core/avatar'], ['core/comment-author-name'], ['core/comment-
|
|
|
25
25
|
*
|
|
26
26
|
* @param {Object} settings Discussion Settings.
|
|
27
27
|
* @param {number} [settings.perPage] - Comments per page setting or block attribute.
|
|
28
|
+
* @param {boolean} [settings.pageComments] - Enable break comments into pages setting.
|
|
28
29
|
* @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.
|
|
29
30
|
* @param {number} [settings.threadCommentsDepth] - Level deep of threaded comments.
|
|
30
31
|
*
|
|
@@ -35,44 +36,49 @@ const TEMPLATE = [['core/avatar'], ['core/comment-author-name'], ['core/comment-
|
|
|
35
36
|
const getCommentsPlaceholder = _ref => {
|
|
36
37
|
let {
|
|
37
38
|
perPage,
|
|
39
|
+
pageComments,
|
|
38
40
|
threadComments,
|
|
39
41
|
threadCommentsDepth
|
|
40
42
|
} = _ref;
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
// In case that the value is set but larger than 3 we truncate it to 3.
|
|
44
|
-
const commentsDepth = Math.min(threadCommentsDepth || 3, 3); // We set a limit in order not to overload the editor of empty comments.
|
|
43
|
+
// Limit commentsDepth to 3
|
|
44
|
+
const commentsDepth = !threadComments ? 1 : Math.min(threadCommentsDepth, 3);
|
|
45
45
|
|
|
46
|
-
const
|
|
46
|
+
const buildChildrenComment = commentsLevel => {
|
|
47
|
+
// Render children comments until commentsDepth is reached
|
|
48
|
+
if (commentsLevel < commentsDepth) {
|
|
49
|
+
const nextLevel = commentsLevel + 1;
|
|
50
|
+
return [{
|
|
51
|
+
commentId: -(commentsLevel + 3),
|
|
52
|
+
children: buildChildrenComment(nextLevel)
|
|
53
|
+
}];
|
|
54
|
+
}
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// A commentId is negative in order to avoid conflicts with the actual comments.
|
|
51
|
-
return [{
|
|
52
|
-
commentId: -1,
|
|
53
|
-
children: []
|
|
54
|
-
}];
|
|
55
|
-
} else if (defaultCommentsToShow === 2) {
|
|
56
|
-
return [{
|
|
57
|
-
commentId: -1,
|
|
58
|
-
children: [{
|
|
59
|
-
commentId: -2,
|
|
60
|
-
children: []
|
|
61
|
-
}]
|
|
62
|
-
}];
|
|
63
|
-
} // In case that the value is set but larger than 3 we truncate it to 3.
|
|
56
|
+
return [];
|
|
57
|
+
}; // Add the first comment and its children
|
|
64
58
|
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
const placeholderComments = [{
|
|
67
61
|
commentId: -1,
|
|
68
|
-
children:
|
|
62
|
+
children: buildChildrenComment(1)
|
|
63
|
+
}]; // Add a second comment unless the break comments setting is active and set to less than 2, and there is one nested comment max
|
|
64
|
+
|
|
65
|
+
if ((!pageComments || perPage >= 2) && commentsDepth < 3) {
|
|
66
|
+
placeholderComments.push({
|
|
69
67
|
commentId: -2,
|
|
70
|
-
children: [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
children: []
|
|
69
|
+
});
|
|
70
|
+
} // Add a third comment unless the break comments setting is active and set to less than 3, and there aren't nested comments
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if ((!pageComments || perPage >= 3) && commentsDepth < 2) {
|
|
74
|
+
placeholderComments.push({
|
|
75
|
+
commentId: -3,
|
|
76
|
+
children: []
|
|
77
|
+
});
|
|
78
|
+
} // In case that the value is set but larger than 3 we truncate it to 3.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
return placeholderComments;
|
|
76
82
|
};
|
|
77
83
|
/**
|
|
78
84
|
* Component which renders the inner blocks of the Comment Template.
|
|
@@ -217,7 +223,8 @@ export default function CommentTemplateEdit(_ref6) {
|
|
|
217
223
|
commentOrder,
|
|
218
224
|
threadCommentsDepth,
|
|
219
225
|
threadComments,
|
|
220
|
-
commentsPerPage
|
|
226
|
+
commentsPerPage,
|
|
227
|
+
pageComments
|
|
221
228
|
} = useSelect(select => {
|
|
222
229
|
const {
|
|
223
230
|
getSettings
|
|
@@ -254,6 +261,7 @@ export default function CommentTemplateEdit(_ref6) {
|
|
|
254
261
|
if (!postId) {
|
|
255
262
|
commentTree = getCommentsPlaceholder({
|
|
256
263
|
perPage: commentsPerPage,
|
|
264
|
+
pageComments,
|
|
257
265
|
threadComments,
|
|
258
266
|
threadCommentsDepth
|
|
259
267
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/comment-template/edit.js"],"names":["useState","memo","useSelect","__","BlockContextProvider","useBlockProps","useInnerBlocksProps","store","blockEditorStore","__experimentalUseBlockPreview","useBlockPreview","Spinner","coreStore","useCommentQueryArgs","useCommentTree","TEMPLATE","getCommentsPlaceholder","perPage","threadComments","threadCommentsDepth","commentsDepth","Math","min","defaultCommentsToShow","commentId","children","CommentTemplateInnerBlocks","comment","activeCommentId","setActiveCommentId","firstCommentId","blocks","innerBlocksProps","template","length","CommentTemplatePreview","isHidden","blockPreviewProps","handleOnClick","style","display","undefined","MemoizedCommentTemplatePreview","CommentsList","comments","blockProps","map","index","CommentTemplateEdit","clientId","context","postId","commentOrder","commentsPerPage","select","getSettings","__experimentalDiscussionSettings","commentQuery","topLevelComments","getEntityRecords","getBlocks","commentTree","reverse"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,IAAnB,QAA+B,oBAA/B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,oBADD,EAECC,aAFD,EAGCC,mBAHD,EAICC,KAAK,IAAIC,gBAJV,EAKCC,6BAA6B,IAAIC,eALlC,QAMO,yBANP;AAOA,SAASC,OAAT,QAAwB,uBAAxB;AACA,SAASJ,KAAK,IAAIK,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASC,mBAAT,EAA8BC,cAA9B,QAAoD,SAApD;AAEA,MAAMC,QAAQ,GAAG,CAChB,CAAE,aAAF,CADgB,EAEhB,CAAE,0BAAF,CAFgB,EAGhB,CAAE,mBAAF,CAHgB,EAIhB,CAAE,sBAAF,CAJgB,EAKhB,CAAE,yBAAF,CALgB,EAMhB,CAAE,wBAAF,CANgB,CAAjB;AAS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AAP,EAA0B;AACzB,WACC,mBAAQb,UAAR,EACC,cAAC,OAAD,OADD,CADD;AAKA;;AAED,MAAK,CAAEM,MAAP,EAAgB;AACfU,IAAAA,WAAW,GAAG7C,sBAAsB,CAAE;AACrCC,MAAAA,OAAO,EAAEoC,eAD4B;AAErCnC,MAAAA,cAFqC;AAGrCC,MAAAA;AAHqC,KAAF,CAApC;AAKA;;AAED,MAAK,CAAE0C,WAAW,CAAC3B,MAAnB,EAA4B;AAC3B,WAAO,mBAAQW,UAAR,EAAuB1C,EAAE,CAAE,mBAAF,CAAzB,CAAP;AACA;;AAED,SACC,cAAC,YAAD;AACC,IAAA,QAAQ,EAAG0D,WADZ;AAEC,IAAA,UAAU,EAAGhB,UAFd;AAGC,IAAA,MAAM,EAAGd,MAHV;AAIC,IAAA,eAAe,EAAGH,eAJnB;AAKC,IAAA,kBAAkB,EAAGC,kBALtB;AAMC,IAAA,cAAc,mBAAGgC,WAAW,CAAE,CAAF,CAAd,kDAAG,cAAkBrC;AANpC,IADD;AAUA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, memo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockContextProvider,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\nimport { Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useCommentQueryArgs, useCommentTree } from './hooks';\n\nconst TEMPLATE = [\n\t[ 'core/avatar' ],\n\t[ 'core/comment-author-name' ],\n\t[ 'core/comment-date' ],\n\t[ 'core/comment-content' ],\n\t[ 'core/comment-reply-link' ],\n\t[ 'core/comment-edit-link' ],\n];\n\n/**\n * Function that returns a comment structure that will be rendered with default placehoders.\n *\n * Each comment has a `commentId` property that is always a negative number in\n * case of the placeholders. This is to ensure that the comment does not\n * conflict with the actual (real) comments.\n *\n * @param {Object} settings Discussion Settings.\n * @param {number} [settings.perPage] - Comments per page setting or block attribute.\n * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.\n * @param {number} [settings.threadCommentsDepth] - Level deep of threaded comments.\n *\n * @typedef {{id: null, children: EmptyComment[]}} EmptyComment\n * @return {EmptyComment[]} \t\tInner blocks of the Comment Template\n */\nconst getCommentsPlaceholder = ( {\n\tperPage,\n\tthreadComments,\n\tthreadCommentsDepth,\n} ) => {\n\t// In case that `threadCommentsDepth` is falsy, we default to a somewhat\n\t// arbitrary value of 3.\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\tconst commentsDepth = Math.min( threadCommentsDepth || 3, 3 );\n\n\t// We set a limit in order not to overload the editor of empty comments.\n\tconst defaultCommentsToShow =\n\t\tperPage <= commentsDepth ? perPage : commentsDepth;\n\tif ( ! threadComments || defaultCommentsToShow === 1 ) {\n\t\t// If displaying threaded comments is disabled, we only show one comment\n\t\t// A commentId is negative in order to avoid conflicts with the actual comments.\n\t\treturn [ { commentId: -1, children: [] } ];\n\t} else if ( defaultCommentsToShow === 2 ) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tcommentId: -1,\n\t\t\t\tchildren: [ { commentId: -2, children: [] } ],\n\t\t\t},\n\t\t];\n\t}\n\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\treturn [\n\t\t{\n\t\t\tcommentId: -1,\n\t\t\tchildren: [\n\t\t\t\t{\n\t\t\t\t\tcommentId: -2,\n\t\t\t\t\tchildren: [ { commentId: -3, children: [] } ],\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n};\n\n/**\n * Component which renders the inner blocks of the Comment Template.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comment] - A comment object.\n * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.\n * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.\n * @param {Array} [props.firstCommentId] - ID of the first comment in the array.\n * @param {Array} [props.blocks] - Array of blocks returned from\n * getBlocks() in parent .\n * @return {WPElement} \t\tInner blocks of the Comment Template\n */\nfunction CommentTemplateInnerBlocks( {\n\tcomment,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tfirstCommentId,\n\tblocks,\n} ) {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\t{},\n\t\t{ template: TEMPLATE }\n\t);\n\n\treturn (\n\t\t<li { ...innerBlocksProps }>\n\t\t\t{ comment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t? children\n\t\t\t\t: null }\n\n\t\t\t{ /* To avoid flicker when switching active block contexts, a preview\n\t\t\tis ALWAYS rendered and the preview for the active block is hidden.\n\t\t\tThis ensures that when switching the active block, the component is not\n\t\t\tmounted again but rather it only toggles the `isHidden` prop.\n\n\t\t\tThe same strategy is used for preventing the flicker in the Post Template\n\t\t\tblock. */ }\n\t\t\t<MemoizedCommentTemplatePreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tcommentId={ comment.commentId }\n\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\tisHidden={\n\t\t\t\t\tcomment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t}\n\t\t\t/>\n\n\t\t\t{ comment?.children?.length > 0 ? (\n\t\t\t\t<CommentsList\n\t\t\t\t\tcomments={ comment.children }\n\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tfirstCommentId={ firstCommentId }\n\t\t\t\t/>\n\t\t\t) : null }\n\t\t</li>\n\t);\n}\n\nconst CommentTemplatePreview = ( {\n\tblocks,\n\tcommentId,\n\tsetActiveCommentId,\n\tisHidden,\n} ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\n\tconst handleOnClick = () => {\n\t\tsetActiveCommentId( commentId );\n\t};\n\n\t// We have to hide the preview block if the `comment` props points to\n\t// the curently active block!\n\n\t// Or, to put it differently, every preview block is visible unless it is the\n\t// currently active block - in this case we render its inner blocks.\n\tconst style = {\n\t\tdisplay: isHidden ? 'none' : undefined,\n\t};\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockPreviewProps }\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tstyle={ style }\n\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n\t\t\tonClick={ handleOnClick }\n\t\t\tonKeyPress={ handleOnClick }\n\t\t/>\n\t);\n};\n\nconst MemoizedCommentTemplatePreview = memo( CommentTemplatePreview );\n\n/**\n * Component that renders a list of (nested) comments. It is called recursively.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comments] - Array of comment objects.\n * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.\n * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.\n * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.\n * @param {Array} [props.blocks] - Array of blocks returned from getBlocks() in parent.\n * @param {Object} [props.firstCommentId] - The ID of the first comment in the array of\n * comment objects.\n * @return {WPElement} \t\tList of comments.\n */\nconst CommentsList = ( {\n\tcomments,\n\tblockProps,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tblocks,\n\tfirstCommentId,\n} ) => (\n\t<ol { ...blockProps }>\n\t\t{ comments &&\n\t\t\tcomments.map( ( { commentId, ...comment }, index ) => (\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tkey={ comment.commentId || index }\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t// If the commentId is negative it means that this comment is a\n\t\t\t\t\t\t// \"placeholder\" and that the block is most likely being used in the\n\t\t\t\t\t\t// site editor. In this case, we have to set the commentId to `null`\n\t\t\t\t\t\t// because otherwise the (non-existent) comment with a negative ID\n\t\t\t\t\t\t// would be reqested from the REST API.\n\t\t\t\t\t\tcommentId: commentId < 0 ? null : commentId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<CommentTemplateInnerBlocks\n\t\t\t\t\t\tcomment={ { commentId, ...comment } }\n\t\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tfirstCommentId={ firstCommentId }\n\t\t\t\t\t/>\n\t\t\t\t</BlockContextProvider>\n\t\t\t) ) }\n\t</ol>\n);\n\nexport default function CommentTemplateEdit( {\n\tclientId,\n\tcontext: { postId },\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst [ activeCommentId, setActiveCommentId ] = useState();\n\tconst {\n\t\tcommentOrder,\n\t\tthreadCommentsDepth,\n\t\tthreadComments,\n\t\tcommentsPerPage,\n\t} = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().__experimentalDiscussionSettings;\n\t} );\n\n\tconst commentQuery = useCommentQueryArgs( {\n\t\tpostId,\n\t} );\n\n\tconst { topLevelComments, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\t// Request only top-level comments. Replies are embedded.\n\t\t\t\ttopLevelComments: commentQuery\n\t\t\t\t\t? getEntityRecords( 'root', 'comment', commentQuery )\n\t\t\t\t\t: null,\n\t\t\t\tblocks: getBlocks( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId, commentQuery ]\n\t);\n\n\t// Generate a tree structure of comment IDs.\n\tlet commentTree = useCommentTree(\n\t\t// Reverse the order of top comments if needed.\n\t\tcommentOrder === 'desc' && topLevelComments\n\t\t\t? [ ...topLevelComments ].reverse()\n\t\t\t: topLevelComments\n\t);\n\n\tif ( ! topLevelComments ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</p>\n\t\t);\n\t}\n\n\tif ( ! postId ) {\n\t\tcommentTree = getCommentsPlaceholder( {\n\t\t\tperPage: commentsPerPage,\n\t\t\tthreadComments,\n\t\t\tthreadCommentsDepth,\n\t\t} );\n\t}\n\n\tif ( ! commentTree.length ) {\n\t\treturn <p { ...blockProps }>{ __( 'No results found.' ) }</p>;\n\t}\n\n\treturn (\n\t\t<CommentsList\n\t\t\tcomments={ commentTree }\n\t\t\tblockProps={ blockProps }\n\t\t\tblocks={ blocks }\n\t\t\tactiveCommentId={ activeCommentId }\n\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\tfirstCommentId={ commentTree[ 0 ]?.commentId }\n\t\t/>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/comment-template/edit.js"],"names":["useState","memo","useSelect","__","BlockContextProvider","useBlockProps","useInnerBlocksProps","store","blockEditorStore","__experimentalUseBlockPreview","useBlockPreview","Spinner","coreStore","useCommentQueryArgs","useCommentTree","TEMPLATE","getCommentsPlaceholder","perPage","pageComments","threadComments","threadCommentsDepth","commentsDepth","Math","min","buildChildrenComment","commentsLevel","nextLevel","commentId","children","placeholderComments","push","CommentTemplateInnerBlocks","comment","activeCommentId","setActiveCommentId","firstCommentId","blocks","innerBlocksProps","template","length","CommentTemplatePreview","isHidden","blockPreviewProps","handleOnClick","style","display","undefined","MemoizedCommentTemplatePreview","CommentsList","comments","blockProps","map","index","CommentTemplateEdit","clientId","context","postId","commentOrder","commentsPerPage","select","getSettings","__experimentalDiscussionSettings","commentQuery","topLevelComments","getEntityRecords","getBlocks","commentTree","reverse"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,IAAnB,QAA+B,oBAA/B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,oBADD,EAECC,aAFD,EAGCC,mBAHD,EAICC,KAAK,IAAIC,gBAJV,EAKCC,6BAA6B,IAAIC,eALlC,QAMO,yBANP;AAOA,SAASC,OAAT,QAAwB,uBAAxB;AACA,SAASJ,KAAK,I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dependencies\n */\nimport { useState, memo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockContextProvider,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\nimport { Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useCommentQueryArgs, useCommentTree } from './hooks';\n\nconst TEMPLATE = [\n\t[ 'core/avatar' ],\n\t[ 'core/comment-author-name' ],\n\t[ 'core/comment-date' ],\n\t[ 'core/comment-content' ],\n\t[ 'core/comment-reply-link' ],\n\t[ 'core/comment-edit-link' ],\n];\n\n/**\n * Function that returns a comment structure that will be rendered with default placehoders.\n *\n * Each comment has a `commentId` property that is always a negative number in\n * case of the placeholders. This is to ensure that the comment does not\n * conflict with the actual (real) comments.\n *\n * @param {Object} settings Discussion Settings.\n * @param {number} [settings.perPage] - Comments per page setting or block attribute.\n * @param {boolean} [settings.pageComments] - Enable break comments into pages setting.\n * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.\n * @param {number} [settings.threadCommentsDepth] - Level deep of threaded comments.\n *\n * @typedef {{id: null, children: EmptyComment[]}} EmptyComment\n * @return {EmptyComment[]} \t\tInner blocks of the Comment Template\n */\nconst getCommentsPlaceholder = ( {\n\tperPage,\n\tpageComments,\n\tthreadComments,\n\tthreadCommentsDepth,\n} ) => {\n\t// Limit commentsDepth to 3\n\tconst commentsDepth = ! threadComments\n\t\t? 1\n\t\t: Math.min( threadCommentsDepth, 3 );\n\n\tconst buildChildrenComment = ( commentsLevel ) => {\n\t\t// Render children comments until commentsDepth is reached\n\t\tif ( commentsLevel < commentsDepth ) {\n\t\t\tconst nextLevel = commentsLevel + 1;\n\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcommentId: -( commentsLevel + 3 ),\n\t\t\t\t\tchildren: buildChildrenComment( nextLevel ),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\treturn [];\n\t};\n\n\t// Add the first comment and its children\n\tconst placeholderComments = [\n\t\t{ commentId: -1, children: buildChildrenComment( 1 ) },\n\t];\n\n\t// Add a second comment unless the break comments setting is active and set to less than 2, and there is one nested comment max\n\tif ( ( ! pageComments || perPage >= 2 ) && commentsDepth < 3 ) {\n\t\tplaceholderComments.push( {\n\t\t\tcommentId: -2,\n\t\t\tchildren: [],\n\t\t} );\n\t}\n\n\t// Add a third comment unless the break comments setting is active and set to less than 3, and there aren't nested comments\n\tif ( ( ! pageComments || perPage >= 3 ) && commentsDepth < 2 ) {\n\t\tplaceholderComments.push( {\n\t\t\tcommentId: -3,\n\t\t\tchildren: [],\n\t\t} );\n\t}\n\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\treturn placeholderComments;\n};\n\n/**\n * Component which renders the inner blocks of the Comment Template.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comment] - A comment object.\n * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.\n * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.\n * @param {Array} [props.firstCommentId] - ID of the first comment in the array.\n * @param {Array} [props.blocks] - Array of blocks returned from\n * getBlocks() in parent .\n * @return {WPElement} \t\tInner blocks of the Comment Template\n */\nfunction CommentTemplateInnerBlocks( {\n\tcomment,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tfirstCommentId,\n\tblocks,\n} ) {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\t{},\n\t\t{ template: TEMPLATE }\n\t);\n\n\treturn (\n\t\t<li { ...innerBlocksProps }>\n\t\t\t{ comment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t? children\n\t\t\t\t: null }\n\n\t\t\t{ /* To avoid flicker when switching active block contexts, a preview\n\t\t\t is ALWAYS rendered and the preview for the active block is hidden.\n\t\t\t This ensures that when switching the active block, the component is not\n\t\t\t mounted again but rather it only toggles the `isHidden` prop.\n\t\t\t The same strategy is used for preventing the flicker in the Post Template\n\t\t\t block. */ }\n\t\t\t<MemoizedCommentTemplatePreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tcommentId={ comment.commentId }\n\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\tisHidden={\n\t\t\t\t\tcomment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t}\n\t\t\t/>\n\n\t\t\t{ comment?.children?.length > 0 ? (\n\t\t\t\t<CommentsList\n\t\t\t\t\tcomments={ comment.children }\n\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tfirstCommentId={ firstCommentId }\n\t\t\t\t/>\n\t\t\t) : null }\n\t\t</li>\n\t);\n}\n\nconst CommentTemplatePreview = ( {\n\tblocks,\n\tcommentId,\n\tsetActiveCommentId,\n\tisHidden,\n} ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\n\tconst handleOnClick = () => {\n\t\tsetActiveCommentId( commentId );\n\t};\n\n\t// We have to hide the preview block if the `comment` props points to\n\t// the curently active block!\n\n\t// Or, to put it differently, every preview block is visible unless it is the\n\t// currently active block - in this case we render its inner blocks.\n\tconst style = {\n\t\tdisplay: isHidden ? 'none' : undefined,\n\t};\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockPreviewProps }\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tstyle={ style }\n\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n\t\t\tonClick={ handleOnClick }\n\t\t\tonKeyPress={ handleOnClick }\n\t\t/>\n\t);\n};\n\nconst MemoizedCommentTemplatePreview = memo( CommentTemplatePreview );\n\n/**\n * Component that renders a list of (nested) comments. It is called recursively.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comments] - Array of comment objects.\n * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.\n * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.\n * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.\n * @param {Array} [props.blocks] - Array of blocks returned from getBlocks() in parent.\n * @param {Object} [props.firstCommentId] - The ID of the first comment in the array of\n * comment objects.\n * @return {WPElement} \t\tList of comments.\n */\nconst CommentsList = ( {\n\tcomments,\n\tblockProps,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tblocks,\n\tfirstCommentId,\n} ) => (\n\t<ol { ...blockProps }>\n\t\t{ comments &&\n\t\t\tcomments.map( ( { commentId, ...comment }, index ) => (\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tkey={ comment.commentId || index }\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t// If the commentId is negative it means that this comment is a\n\t\t\t\t\t\t// \"placeholder\" and that the block is most likely being used in the\n\t\t\t\t\t\t// site editor. In this case, we have to set the commentId to `null`\n\t\t\t\t\t\t// because otherwise the (non-existent) comment with a negative ID\n\t\t\t\t\t\t// would be reqested from the REST API.\n\t\t\t\t\t\tcommentId: commentId < 0 ? null : commentId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<CommentTemplateInnerBlocks\n\t\t\t\t\t\tcomment={ { commentId, ...comment } }\n\t\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tfirstCommentId={ firstCommentId }\n\t\t\t\t\t/>\n\t\t\t\t</BlockContextProvider>\n\t\t\t) ) }\n\t</ol>\n);\n\nexport default function CommentTemplateEdit( {\n\tclientId,\n\tcontext: { postId },\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst [ activeCommentId, setActiveCommentId ] = useState();\n\tconst {\n\t\tcommentOrder,\n\t\tthreadCommentsDepth,\n\t\tthreadComments,\n\t\tcommentsPerPage,\n\t\tpageComments,\n\t} = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().__experimentalDiscussionSettings;\n\t} );\n\n\tconst commentQuery = useCommentQueryArgs( {\n\t\tpostId,\n\t} );\n\n\tconst { topLevelComments, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\t// Request only top-level comments. Replies are embedded.\n\t\t\t\ttopLevelComments: commentQuery\n\t\t\t\t\t? getEntityRecords( 'root', 'comment', commentQuery )\n\t\t\t\t\t: null,\n\t\t\t\tblocks: getBlocks( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId, commentQuery ]\n\t);\n\n\t// Generate a tree structure of comment IDs.\n\tlet commentTree = useCommentTree(\n\t\t// Reverse the order of top comments if needed.\n\t\tcommentOrder === 'desc' && topLevelComments\n\t\t\t? [ ...topLevelComments ].reverse()\n\t\t\t: topLevelComments\n\t);\n\n\tif ( ! topLevelComments ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</p>\n\t\t);\n\t}\n\n\tif ( ! postId ) {\n\t\tcommentTree = getCommentsPlaceholder( {\n\t\t\tperPage: commentsPerPage,\n\t\t\tpageComments,\n\t\t\tthreadComments,\n\t\t\tthreadCommentsDepth,\n\t\t} );\n\t}\n\n\tif ( ! commentTree.length ) {\n\t\treturn <p { ...blockProps }>{ __( 'No results found.' ) }</p>;\n\t}\n\n\treturn (\n\t\t<CommentsList\n\t\t\tcomments={ commentTree }\n\t\t\tblockProps={ blockProps }\n\t\t\tblocks={ blocks }\n\t\t\tactiveCommentId={ activeCommentId }\n\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\tfirstCommentId={ commentTree[ 0 ]?.commentId }\n\t\t/>\n\t);\n}\n"]}
|
|
@@ -7,7 +7,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
|
7
7
|
import { __, sprintf } from '@wordpress/i18n';
|
|
8
8
|
import { useSelect } from '@wordpress/data';
|
|
9
9
|
import { useEntityProp } from '@wordpress/core-data';
|
|
10
|
-
import { useDisabled } from '@wordpress/compose';
|
|
11
10
|
/**
|
|
12
11
|
* Internal dependencies
|
|
13
12
|
*/
|
|
@@ -23,10 +22,9 @@ export default function PostCommentsPlaceholder(_ref) {
|
|
|
23
22
|
const {
|
|
24
23
|
avatarURL
|
|
25
24
|
} = useSelect(select => select(blockEditorStore).getSettings().__experimentalDiscussionSettings);
|
|
26
|
-
const disabledRef = useDisabled();
|
|
27
25
|
return createElement("div", {
|
|
28
26
|
className: "wp-block-comments__legacy-placeholder",
|
|
29
|
-
|
|
27
|
+
inert: "true"
|
|
30
28
|
}, createElement("h3", null,
|
|
31
29
|
/* translators: %s: Post title. */
|
|
32
30
|
sprintf(__('One response to %s'), postTitle)), createElement("div", {
|