@wordpress/block-library 8.15.0 → 8.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/avatar/index.js +3 -0
- package/build/avatar/index.js.map +1 -1
- package/build/block/edit.js +2 -30
- package/build/block/edit.js.map +1 -1
- package/build/cover/index.js +2 -1
- package/build/cover/index.js.map +1 -1
- package/build/footnotes/edit.js +11 -0
- package/build/footnotes/edit.js.map +1 -1
- package/build/footnotes/format.js +101 -8
- package/build/footnotes/format.js.map +1 -1
- package/build/footnotes/index.js +45 -3
- package/build/footnotes/index.js.map +1 -1
- package/build/gallery/edit.js +7 -5
- package/build/gallery/edit.js.map +1 -1
- package/build/image/deprecated.js +106 -2
- package/build/image/deprecated.js.map +1 -1
- package/build/image/image.js +2 -2
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +2 -1
- package/build/image/index.js.map +1 -1
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/list-item/hooks/use-merge.js +10 -1
- package/build/list-item/hooks/use-merge.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +1 -1
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +4 -4
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/view-modal.js +93 -32
- package/build/navigation/view-modal.js.map +1 -1
- package/build/navigation/view.js +63 -31
- package/build/navigation/view.js.map +1 -1
- package/build/pattern/edit.js +28 -4
- package/build/pattern/edit.js.map +1 -1
- package/build/preformatted/index.js +4 -0
- package/build/preformatted/index.js.map +1 -1
- package/build/search/view.js +166 -62
- package/build/search/view.js.map +1 -1
- package/build/social-link/icons/index.js +13 -0
- package/build/social-link/icons/index.js.map +1 -1
- package/build/social-link/icons/threads.js +25 -0
- package/build/social-link/icons/threads.js.map +1 -0
- package/build/social-link/variations.js +7 -0
- package/build/social-link/variations.js.map +1 -1
- package/build/template-part/edit/import-controls.js +1 -1
- package/build/template-part/edit/import-controls.js.map +1 -1
- package/build-module/avatar/index.js +3 -0
- package/build-module/avatar/index.js.map +1 -1
- package/build-module/block/edit.js +4 -29
- package/build-module/block/edit.js.map +1 -1
- package/build-module/cover/index.js +2 -1
- package/build-module/cover/index.js.map +1 -1
- package/build-module/footnotes/edit.js +11 -0
- package/build-module/footnotes/edit.js.map +1 -1
- package/build-module/footnotes/format.js +102 -10
- package/build-module/footnotes/format.js.map +1 -1
- package/build-module/footnotes/index.js +45 -3
- package/build-module/footnotes/index.js.map +1 -1
- package/build-module/gallery/edit.js +7 -5
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/image/deprecated.js +107 -3
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/image.js +2 -2
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +2 -1
- package/build-module/image/index.js.map +1 -1
- package/build-module/index.js +3 -1
- package/build-module/index.js.map +1 -1
- package/build-module/list-item/hooks/use-merge.js +10 -1
- package/build-module/list-item/hooks/use-merge.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +4 -4
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/view-modal.js +93 -31
- package/build-module/navigation/view-modal.js.map +1 -1
- package/build-module/navigation/view.js +63 -31
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/pattern/edit.js +27 -4
- package/build-module/pattern/edit.js.map +1 -1
- package/build-module/preformatted/index.js +4 -0
- package/build-module/preformatted/index.js.map +1 -1
- package/build-module/search/view.js +166 -62
- package/build-module/search/view.js.map +1 -1
- package/build-module/social-link/icons/index.js +1 -0
- package/build-module/social-link/icons/index.js.map +1 -1
- package/build-module/social-link/icons/threads.js +15 -0
- package/build-module/social-link/icons/threads.js.map +1 -0
- package/build-module/social-link/variations.js +8 -1
- package/build-module/social-link/variations.js.map +1 -1
- package/build-module/template-part/edit/import-controls.js +2 -2
- package/build-module/template-part/edit/import-controls.js.map +1 -1
- package/build-style/preformatted/style-rtl.css +2 -1
- package/build-style/preformatted/style.css +2 -1
- package/build-style/social-links/style-rtl.css +7 -0
- package/build-style/social-links/style.css +7 -0
- package/build-style/style-rtl.css +10 -1
- package/build-style/style.css +10 -1
- package/build-style/video/style-rtl.css +1 -0
- package/build-style/video/style.css +1 -0
- package/package.json +32 -32
- package/src/audio/test/__snapshots__/edit.native.js.snap +60 -0
- package/src/avatar/block.json +3 -0
- package/src/block/edit.js +1 -39
- package/src/buttons/test/edit.native.js +4 -0
- package/src/columns/test/edit.native.js +5 -0
- package/src/comment-template/index.php +2 -0
- package/src/cover/block.json +2 -1
- package/src/cover/test/edit.native.js +8 -0
- package/src/embed/test/index.native.js +8 -0
- package/src/file/index.php +1 -1
- package/src/file/test/__snapshots__/edit.native.js.snap +61 -0
- package/src/footnotes/block.json +44 -1
- package/src/footnotes/edit.js +12 -0
- package/src/footnotes/format.js +70 -7
- package/src/footnotes/index.js +0 -1
- package/src/footnotes/index.php +207 -0
- package/src/gallery/edit.js +41 -37
- package/src/gallery/test/index.native.js +15 -3
- package/src/heading/test/index.native.js +4 -0
- package/src/image/block.json +2 -1
- package/src/image/deprecated.js +109 -3
- package/src/image/image.js +2 -2
- package/src/image/index.php +1 -3
- package/src/image/test/edit.native.js +0 -1
- package/src/index.js +5 -1
- package/src/list/test/edit.native.js +5 -0
- package/src/list-item/hooks/use-merge.js +12 -5
- package/src/missing/test/__snapshots__/edit.native.js.snap +21 -0
- package/src/navigation/edit/menu-inspector-controls.js +1 -1
- package/src/navigation/edit/navigation-menu-selector.js +8 -4
- package/src/navigation/index.php +27 -13
- package/src/navigation/view-modal.js +88 -39
- package/src/navigation/view.js +69 -36
- package/src/paragraph/test/edit.native.js +55 -35
- package/src/pattern/edit.js +21 -0
- package/src/pattern/index.php +13 -1
- package/src/post-template/index.php +2 -0
- package/src/post-title/index.php +2 -0
- package/src/preformatted/block.json +4 -0
- package/src/preformatted/style.scss +4 -1
- package/src/pullquote/test/edit.native.js +12 -4
- package/src/quote/test/edit.native.js +12 -4
- package/src/search/index.php +4 -0
- package/src/search/test/__snapshots__/edit.native.js.snap +63 -0
- package/src/search/view.js +171 -67
- package/src/social-link/icons/index.js +1 -0
- package/src/social-link/icons/threads.js +10 -0
- package/src/social-link/index.php +4 -0
- package/src/social-link/socials-with-bg.scss +5 -0
- package/src/social-link/socials-without-bg.scss +4 -0
- package/src/social-link/variations.js +7 -0
- package/src/template-part/edit/import-controls.js +2 -2
- package/src/template-part/index.php +6 -9
- package/src/video/style.scss +1 -0
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
/*eslint-env browser*/
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* External dependencies
|
|
3
5
|
*/
|
|
4
6
|
import MicroModal from 'micromodal'; // Responsive navigation toggle.
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Toggles responsive navigation.
|
|
10
|
+
*
|
|
11
|
+
* @param {HTMLDivElement} modal
|
|
12
|
+
* @param {boolean} isHidden
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function navigationToggleModal(modal, isHidden) {
|
|
7
16
|
const dialogContainer = modal.querySelector(`.wp-block-navigation__responsive-dialog`);
|
|
8
|
-
const isHidden = 'true' === modal.getAttribute('aria-hidden');
|
|
9
17
|
modal.classList.toggle('has-modal-open', !isHidden);
|
|
10
18
|
dialogContainer.toggleAttribute('aria-modal', !isHidden);
|
|
11
19
|
|
|
@@ -18,41 +26,95 @@ function navigationToggleModal(modal) {
|
|
|
18
26
|
} // Add a class to indicate the modal is open.
|
|
19
27
|
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
htmlElement.classList.toggle('has-modal-open');
|
|
29
|
+
document.documentElement.classList.toggle('has-modal-open');
|
|
23
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks whether the provided link is an anchor on the current page.
|
|
33
|
+
*
|
|
34
|
+
* @param {HTMLAnchorElement} node
|
|
35
|
+
* @return {boolean} Is anchor.
|
|
36
|
+
*/
|
|
37
|
+
|
|
24
38
|
|
|
25
39
|
function isLinkToAnchorOnCurrentPage(node) {
|
|
26
40
|
return node.hash && node.protocol === window.location.protocol && node.host === window.location.host && node.pathname === window.location.pathname && node.search === window.location.search;
|
|
27
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Handles effects after opening the modal.
|
|
44
|
+
*
|
|
45
|
+
* @param {HTMLDivElement} modal
|
|
46
|
+
*/
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const modalId = modal?.getAttribute('id');
|
|
48
|
-
link.addEventListener('click', () => {
|
|
49
|
-
// check if modal exists and is open before trying to close it
|
|
50
|
-
// otherwise Micromodal will toggle the `has-modal-open` class
|
|
51
|
-
// on the html tag which prevents scrolling
|
|
52
|
-
if (modalId && modal.classList.contains('has-modal-open')) {
|
|
53
|
-
MicroModal.close(modalId);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
48
|
+
|
|
49
|
+
function onShow(modal) {
|
|
50
|
+
navigationToggleModal(modal, false);
|
|
51
|
+
modal.addEventListener('click', handleAnchorLinkClicksInsideModal, {
|
|
52
|
+
passive: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Handles effects after closing the modal.
|
|
57
|
+
*
|
|
58
|
+
* @param {HTMLDivElement} modal
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function onClose(modal) {
|
|
63
|
+
navigationToggleModal(modal, true);
|
|
64
|
+
modal.removeEventListener('click', handleAnchorLinkClicksInsideModal, {
|
|
65
|
+
passive: true
|
|
56
66
|
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle clicks to anchor links in modal using event delegation by closing modal automatically
|
|
70
|
+
*
|
|
71
|
+
* @param {UIEvent} event
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
function handleAnchorLinkClicksInsideModal(event) {
|
|
76
|
+
const link = event.target.closest('.wp-block-navigation-item__content');
|
|
77
|
+
|
|
78
|
+
if (!(link instanceof HTMLAnchorElement)) {
|
|
79
|
+
return;
|
|
80
|
+
} // Ignore non-anchor links and anchor links which open on a new tab.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if (!isLinkToAnchorOnCurrentPage(link) || link.attributes?.target === '_blank') {
|
|
84
|
+
return;
|
|
85
|
+
} // Find the specific parent modal for this link
|
|
86
|
+
// since .close() won't work without an ID if there are
|
|
87
|
+
// multiple navigation menus in a post/page.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
const modal = link.closest('.wp-block-navigation__responsive-container');
|
|
91
|
+
const modalId = modal?.getAttribute('id');
|
|
92
|
+
|
|
93
|
+
if (!modalId) {
|
|
94
|
+
return;
|
|
95
|
+
} // check if modal exists and is open before trying to close it
|
|
96
|
+
// otherwise Micromodal will toggle the `has-modal-open` class
|
|
97
|
+
// on the html tag which prevents scrolling
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if (modalId && modal.classList.contains('has-modal-open')) {
|
|
101
|
+
MicroModal.close(modalId);
|
|
102
|
+
}
|
|
103
|
+
} // MicroModal.init() does not support event delegation for the open trigger, so here MicroModal.show() is called manually.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
document.addEventListener('click', event => {
|
|
107
|
+
/** @type {HTMLElement} */
|
|
108
|
+
const target = event.target;
|
|
109
|
+
|
|
110
|
+
if (target.dataset.micromodalTrigger) {
|
|
111
|
+
MicroModal.show(target.dataset.micromodalTrigger, {
|
|
112
|
+
onShow,
|
|
113
|
+
onClose,
|
|
114
|
+
openClass: 'is-menu-open'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
passive: true
|
|
57
119
|
});
|
|
58
120
|
//# sourceMappingURL=view-modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/navigation/view-modal.js"],"names":["MicroModal","navigationToggleModal","modal","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/navigation/view-modal.js"],"names":["MicroModal","navigationToggleModal","modal","isHidden","dialogContainer","querySelector","classList","toggle","toggleAttribute","removeAttribute","setAttribute","document","documentElement","isLinkToAnchorOnCurrentPage","node","hash","protocol","window","location","host","pathname","search","onShow","addEventListener","handleAnchorLinkClicksInsideModal","passive","onClose","removeEventListener","event","link","target","closest","HTMLAnchorElement","attributes","modalId","getAttribute","contains","close","dataset","micromodalTrigger","show","openClass"],"mappings":"AAAA;;AACA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB,C,CAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,qBAAT,CAAgCC,KAAhC,EAAuCC,QAAvC,EAAkD;AACjD,QAAMC,eAAe,GAAGF,KAAK,CAACG,aAAN,CACtB,yCADsB,CAAxB;AAIAH,EAAAA,KAAK,CAACI,SAAN,CAAgBC,MAAhB,CAAwB,gBAAxB,EAA0C,CAAEJ,QAA5C;AACAC,EAAAA,eAAe,CAACI,eAAhB,CAAiC,YAAjC,EAA+C,CAAEL,QAAjD;;AAEA,MAAKA,QAAL,EAAgB;AACfC,IAAAA,eAAe,CAACK,eAAhB,CAAiC,MAAjC;AACAL,IAAAA,eAAe,CAACK,eAAhB,CAAiC,YAAjC;AACA,GAHD,MAGO;AACNL,IAAAA,eAAe,CAACM,YAAhB,CAA8B,MAA9B,EAAsC,QAAtC;AACAN,IAAAA,eAAe,CAACM,YAAhB,CAA8B,YAA9B,EAA4C,MAA5C;AACA,GAd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AA,IAAI,CAACI,UAAL,EAAiBH,MAAjB,KAA4B,QAF7B,EAGE;AACD;AACA,GAZkD,CAcnD;AACA;AACA;;;AACA,QAAM5B,KAAK,GAAG2B,IAAI,CAACE,OAAL,CAAc,4CAAd,CAAd;AACA,QAAMG,OAAO,GAAGhC,KAAK,EAAEiC,YAAP,CAAqB,IAArB,CAAhB;;AACA,MAAK,CAAED,OAAP,EAAiB;AAChB;AACA,GArBkD,CAuBnD;AACA;AACA;;;AACA,MAAKA,OAAO,IAAIhC,KAAK,CAACI,SAAN,CAAgB8B,QAAhB,CAA0B,gBAA1B,CAAhB,EAA+D;AAC9DpC,IAAAA,UAAU,CAACqC,KAAX,CAAkBH,OAAlB;AACA;AACD,C,CAED;;;AACAvB,QAAQ,CAACY,gBAAT,CACC,OADD,EAEGK,KAAF,IAAa;AACZ;AACA,QAAME,MAAM,GAAGF,KAAK,CAACE,MAArB;;AAEA,MAAKA,MAAM,CAACQ,OAAP,CAAeC,iBAApB,EAAwC;AACvCvC,IAAAA,UAAU,CAACwC,IAAX,CAAiBV,MAAM,CAACQ,OAAP,CAAeC,iBAAhC,EAAmD;AAClDjB,MAAAA,MADkD;AAElDI,MAAAA,OAFkD;AAGlDe,MAAAA,SAAS,EAAE;AAHuC,KAAnD;AAKA;AACD,CAbF,EAcC;AAAEhB,EAAAA,OAAO,EAAE;AAAX,CAdD","sourcesContent":["/*eslint-env browser*/\n/**\n * External dependencies\n */\nimport MicroModal from 'micromodal';\n\n// Responsive navigation toggle.\n\n/**\n * Toggles responsive navigation.\n *\n * @param {HTMLDivElement} modal\n * @param {boolean} isHidden\n */\nfunction navigationToggleModal( modal, isHidden ) {\n\tconst dialogContainer = modal.querySelector(\n\t\t`.wp-block-navigation__responsive-dialog`\n\t);\n\n\tmodal.classList.toggle( 'has-modal-open', ! isHidden );\n\tdialogContainer.toggleAttribute( 'aria-modal', ! isHidden );\n\n\tif ( isHidden ) {\n\t\tdialogContainer.removeAttribute( 'role' );\n\t\tdialogContainer.removeAttribute( 'aria-modal' );\n\t} else {\n\t\tdialogContainer.setAttribute( 'role', 'dialog' );\n\t\tdialogContainer.setAttribute( 'aria-modal', 'true' );\n\t}\n\n\t// Add a class to indicate the modal is open.\n\tdocument.documentElement.classList.toggle( 'has-modal-open' );\n}\n\n/**\n * Checks whether the provided link is an anchor on the current page.\n *\n * @param {HTMLAnchorElement} node\n * @return {boolean} Is anchor.\n */\nfunction isLinkToAnchorOnCurrentPage( node ) {\n\treturn (\n\t\tnode.hash &&\n\t\tnode.protocol === window.location.protocol &&\n\t\tnode.host === window.location.host &&\n\t\tnode.pathname === window.location.pathname &&\n\t\tnode.search === window.location.search\n\t);\n}\n\n/**\n * Handles effects after opening the modal.\n *\n * @param {HTMLDivElement} modal\n */\nfunction onShow( modal ) {\n\tnavigationToggleModal( modal, false );\n\tmodal.addEventListener( 'click', handleAnchorLinkClicksInsideModal, {\n\t\tpassive: true,\n\t} );\n}\n\n/**\n * Handles effects after closing the modal.\n *\n * @param {HTMLDivElement} modal\n */\nfunction onClose( modal ) {\n\tnavigationToggleModal( modal, true );\n\tmodal.removeEventListener( 'click', handleAnchorLinkClicksInsideModal, {\n\t\tpassive: true,\n\t} );\n}\n\n/**\n * Handle clicks to anchor links in modal using event delegation by closing modal automatically\n *\n * @param {UIEvent} event\n */\nfunction handleAnchorLinkClicksInsideModal( event ) {\n\tconst link = event.target.closest( '.wp-block-navigation-item__content' );\n\tif ( ! ( link instanceof HTMLAnchorElement ) ) {\n\t\treturn;\n\t}\n\n\t// Ignore non-anchor links and anchor links which open on a new tab.\n\tif (\n\t\t! isLinkToAnchorOnCurrentPage( link ) ||\n\t\tlink.attributes?.target === '_blank'\n\t) {\n\t\treturn;\n\t}\n\n\t// Find the specific parent modal for this link\n\t// since .close() won't work without an ID if there are\n\t// multiple navigation menus in a post/page.\n\tconst modal = link.closest( '.wp-block-navigation__responsive-container' );\n\tconst modalId = modal?.getAttribute( 'id' );\n\tif ( ! modalId ) {\n\t\treturn;\n\t}\n\n\t// check if modal exists and is open before trying to close it\n\t// otherwise Micromodal will toggle the `has-modal-open` class\n\t// on the html tag which prevents scrolling\n\tif ( modalId && modal.classList.contains( 'has-modal-open' ) ) {\n\t\tMicroModal.close( modalId );\n\t}\n}\n\n// MicroModal.init() does not support event delegation for the open trigger, so here MicroModal.show() is called manually.\ndocument.addEventListener(\n\t'click',\n\t( event ) => {\n\t\t/** @type {HTMLElement} */\n\t\tconst target = event.target;\n\n\t\tif ( target.dataset.micromodalTrigger ) {\n\t\t\tMicroModal.show( target.dataset.micromodalTrigger, {\n\t\t\t\tonShow,\n\t\t\t\tonClose,\n\t\t\t\topenClass: 'is-menu-open',\n\t\t\t} );\n\t\t}\n\t},\n\t{ passive: true }\n);\n"]}
|
|
@@ -1,59 +1,91 @@
|
|
|
1
|
+
/*eslint-env browser*/
|
|
1
2
|
// Open on click functionality.
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Keep track of whether a submenu is open to short-circuit delegated event listeners.
|
|
6
|
+
*
|
|
7
|
+
* @type {boolean}
|
|
8
|
+
*/
|
|
9
|
+
let hasOpenSubmenu = false;
|
|
10
|
+
/**
|
|
11
|
+
* Close submenu items for a navigation item.
|
|
12
|
+
*
|
|
13
|
+
* @param {HTMLElement} navigationItem - Either a NAV or LI element.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function closeSubmenus(navigationItem) {
|
|
17
|
+
navigationItem.querySelectorAll('[aria-expanded="true"]').forEach(function (toggle) {
|
|
4
18
|
toggle.setAttribute('aria-expanded', 'false');
|
|
5
19
|
});
|
|
20
|
+
hasOpenSubmenu = false;
|
|
6
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Toggle submenu on click.
|
|
24
|
+
*
|
|
25
|
+
* @param {HTMLButtonElement} buttonToggle
|
|
26
|
+
*/
|
|
27
|
+
|
|
7
28
|
|
|
8
|
-
function toggleSubmenuOnClick(
|
|
9
|
-
const
|
|
10
|
-
const
|
|
29
|
+
function toggleSubmenuOnClick(buttonToggle) {
|
|
30
|
+
const isSubmenuOpen = buttonToggle.getAttribute('aria-expanded') === 'true';
|
|
31
|
+
const navigationItem = buttonToggle.closest('.wp-block-navigation-item');
|
|
11
32
|
|
|
12
|
-
if (isSubmenuOpen
|
|
13
|
-
closeSubmenus(
|
|
33
|
+
if (isSubmenuOpen) {
|
|
34
|
+
closeSubmenus(navigationItem);
|
|
14
35
|
} else {
|
|
15
36
|
// Close all sibling submenus.
|
|
16
|
-
const parentElement = buttonToggle.closest('.wp-block-navigation-item');
|
|
17
37
|
const navigationParent = buttonToggle.closest('.wp-block-navigation__submenu-container, .wp-block-navigation__container, .wp-block-page-list');
|
|
18
|
-
navigationParent.querySelectorAll('.wp-block-navigation-item').forEach(
|
|
19
|
-
if (child !==
|
|
38
|
+
navigationParent.querySelectorAll('.wp-block-navigation-item').forEach(child => {
|
|
39
|
+
if (child !== navigationItem) {
|
|
20
40
|
closeSubmenus(child);
|
|
21
41
|
}
|
|
22
42
|
}); // Open submenu.
|
|
23
43
|
|
|
24
44
|
buttonToggle.setAttribute('aria-expanded', 'true');
|
|
45
|
+
hasOpenSubmenu = true;
|
|
25
46
|
}
|
|
26
|
-
} //
|
|
27
|
-
// scripts could be loaded before the body.
|
|
47
|
+
} // Open on button click or close on click outside.
|
|
28
48
|
|
|
29
49
|
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
button.addEventListener('click', toggleSubmenuOnClick);
|
|
34
|
-
}); // Close on click outside.
|
|
50
|
+
document.addEventListener('click', function (event) {
|
|
51
|
+
const target = event.target;
|
|
52
|
+
const button = target.closest('.wp-block-navigation-submenu__toggle'); // Close any other open submenus.
|
|
35
53
|
|
|
36
|
-
|
|
54
|
+
if (hasOpenSubmenu) {
|
|
37
55
|
const navigationBlocks = document.querySelectorAll('.wp-block-navigation');
|
|
38
56
|
navigationBlocks.forEach(function (block) {
|
|
39
|
-
if (!block.contains(
|
|
57
|
+
if (!block.contains(target)) {
|
|
40
58
|
closeSubmenus(block);
|
|
41
59
|
}
|
|
42
60
|
});
|
|
43
|
-
}
|
|
61
|
+
} // Now open the submenu if one was clicked.
|
|
44
62
|
|
|
45
|
-
document.addEventListener('keyup', function (event) {
|
|
46
|
-
const submenuBlocks = document.querySelectorAll('.wp-block-navigation-item.has-child');
|
|
47
|
-
submenuBlocks.forEach(function (block) {
|
|
48
|
-
if (!block.contains(event.target)) {
|
|
49
|
-
closeSubmenus(block);
|
|
50
|
-
} else if (event.key === 'Escape') {
|
|
51
|
-
const toggle = block.querySelector('[aria-expanded="true"]');
|
|
52
|
-
closeSubmenus(block); // Focus the submenu trigger so focus does not get trapped in the closed submenu.
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
if (button instanceof HTMLButtonElement) {
|
|
65
|
+
toggleSubmenuOnClick(button);
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
passive: true
|
|
69
|
+
}); // Close on focus outside or escape key.
|
|
70
|
+
|
|
71
|
+
document.addEventListener('keyup', function (event) {
|
|
72
|
+
// Abort if there aren't any submenus open anyway.
|
|
73
|
+
if (!hasOpenSubmenu) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const submenuBlocks = document.querySelectorAll('.wp-block-navigation-item.has-child');
|
|
78
|
+
submenuBlocks.forEach(function (block) {
|
|
79
|
+
if (!block.contains(event.target)) {
|
|
80
|
+
closeSubmenus(block);
|
|
81
|
+
} else if (event.key === 'Escape') {
|
|
82
|
+
const toggle = block.querySelector('[aria-expanded="true"]');
|
|
83
|
+
closeSubmenus(block); // Focus the submenu trigger so focus does not get trapped in the closed submenu.
|
|
84
|
+
|
|
85
|
+
toggle?.focus();
|
|
86
|
+
}
|
|
57
87
|
});
|
|
88
|
+
}, {
|
|
89
|
+
passive: true
|
|
58
90
|
});
|
|
59
91
|
//# sourceMappingURL=view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/navigation/view.js"],"names":["closeSubmenus","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/navigation/view.js"],"names":["hasOpenSubmenu","closeSubmenus","navigationItem","querySelectorAll","forEach","toggle","setAttribute","toggleSubmenuOnClick","buttonToggle","isSubmenuOpen","getAttribute","closest","navigationParent","child","document","addEventListener","event","target","button","navigationBlocks","block","contains","HTMLButtonElement","passive","submenuBlocks","key","querySelector","focus"],"mappings":"AAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAIA,cAAc,GAAG,KAArB;AAEA;AACA;AACA;AACA;AACA;;AACA,SAASC,aAAT,CAAwBC,cAAxB,EAAyC;AACxCA,EAAAA,cAAc,CACZC,gBADF,CACoB,wBADpB,EAEEC,OAFF,CAEW,UAAWC,MAAX,EAAoB;AAC7BA,IAAAA,MAAM,CAACC,YAAP,CAAqB,eAArB,EAAsC,OAAtC;AACA,GAJF;AAKAN,EAAAA,cAAc,GAAG,KAAjB;AACA;AAED;AACA;AACA;AACA;AACA;;;AACA,SAASO,oBAAT,CAA+BC,YAA/B,EAA8C;AAC7C,QAAMC,aAAa,GAClBD,YAAY,CAACE,YAAb,CAA2B,eAA3B,MAAiD,MADlD;AAEA,QAAMR,cAAc,GAAGM,YAAY,CAACG,OAAb,CAAsB,2BAAtB,CAAvB;;AAEA,MAAKF,aAAL,EAAqB;AACpBR,IAAAA,aAAa,CAAEC,cAAF,CAAb;AACA,GAFD,MAEO;AACN;AACA,UAAMU,gBAAgB,GAAGJ,YAAY,CAACG,OAAb,CACxB,+FADwB,CAAzB;AAGAC,IAAAA,gBAAgB,CACdT,gBADF,CACoB,2BADpB,EAEEC,OAFF,CAEaS,KAAF,IAAa;AACtB,UAAKA,KAAK,KAAKX,cAAf,EAAgC;AAC/BD,QAAAA,aAAa,CAAEY,KAAF,CAAb;AACA;AACD,KANF,EALM,CAaN;;AACAL,IAAAA,YAAY,CAACF,YAAb,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;AACAzB,MAAAA,aAAa,CAAEmB,KAAF,CAAb,CAFoC,CAGpC;;AACAf,MAAAA,MAAM,EAAEsB,KAAR;AACA;AACD,GATD;AAUA,CArBF,EAsBC;AAAEJ,EAAAA,OAAO,EAAE;AAAX,CAtBD","sourcesContent":["/*eslint-env browser*/\n// Open on click functionality.\n\n/**\n * Keep track of whether a submenu is open to short-circuit delegated event listeners.\n *\n * @type {boolean}\n */\nlet hasOpenSubmenu = false;\n\n/**\n * Close submenu items for a navigation item.\n *\n * @param {HTMLElement} navigationItem - Either a NAV or LI element.\n */\nfunction closeSubmenus( navigationItem ) {\n\tnavigationItem\n\t\t.querySelectorAll( '[aria-expanded=\"true\"]' )\n\t\t.forEach( function ( toggle ) {\n\t\t\ttoggle.setAttribute( 'aria-expanded', 'false' );\n\t\t} );\n\thasOpenSubmenu = false;\n}\n\n/**\n * Toggle submenu on click.\n *\n * @param {HTMLButtonElement} buttonToggle\n */\nfunction toggleSubmenuOnClick( buttonToggle ) {\n\tconst isSubmenuOpen =\n\t\tbuttonToggle.getAttribute( 'aria-expanded' ) === 'true';\n\tconst navigationItem = buttonToggle.closest( '.wp-block-navigation-item' );\n\n\tif ( isSubmenuOpen ) {\n\t\tcloseSubmenus( navigationItem );\n\t} else {\n\t\t// Close all sibling submenus.\n\t\tconst navigationParent = buttonToggle.closest(\n\t\t\t'.wp-block-navigation__submenu-container, .wp-block-navigation__container, .wp-block-page-list'\n\t\t);\n\t\tnavigationParent\n\t\t\t.querySelectorAll( '.wp-block-navigation-item' )\n\t\t\t.forEach( ( child ) => {\n\t\t\t\tif ( child !== navigationItem ) {\n\t\t\t\t\tcloseSubmenus( child );\n\t\t\t\t}\n\t\t\t} );\n\n\t\t// Open submenu.\n\t\tbuttonToggle.setAttribute( 'aria-expanded', 'true' );\n\t\thasOpenSubmenu = true;\n\t}\n}\n\n// Open on button click or close on click outside.\ndocument.addEventListener(\n\t'click',\n\tfunction ( event ) {\n\t\tconst target = event.target;\n\t\tconst button = target.closest( '.wp-block-navigation-submenu__toggle' );\n\n\t\t// Close any other open submenus.\n\t\tif ( hasOpenSubmenu ) {\n\t\t\tconst navigationBlocks = document.querySelectorAll(\n\t\t\t\t'.wp-block-navigation'\n\t\t\t);\n\t\t\tnavigationBlocks.forEach( function ( block ) {\n\t\t\t\tif ( ! block.contains( target ) ) {\n\t\t\t\t\tcloseSubmenus( block );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t// Now open the submenu if one was clicked.\n\t\tif ( button instanceof HTMLButtonElement ) {\n\t\t\ttoggleSubmenuOnClick( button );\n\t\t}\n\t},\n\t{ passive: true }\n);\n\n// Close on focus outside or escape key.\ndocument.addEventListener(\n\t'keyup',\n\tfunction ( event ) {\n\t\t// Abort if there aren't any submenus open anyway.\n\t\tif ( ! hasOpenSubmenu ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst submenuBlocks = document.querySelectorAll(\n\t\t\t'.wp-block-navigation-item.has-child'\n\t\t);\n\t\tsubmenuBlocks.forEach( function ( block ) {\n\t\t\tif ( ! block.contains( event.target ) ) {\n\t\t\t\tcloseSubmenus( block );\n\t\t\t} else if ( event.key === 'Escape' ) {\n\t\t\t\tconst toggle = block.querySelector( '[aria-expanded=\"true\"]' );\n\t\t\t\tcloseSubmenus( block );\n\t\t\t\t// Focus the submenu trigger so focus does not get trapped in the closed submenu.\n\t\t\t\ttoggle?.focus();\n\t\t\t}\n\t\t} );\n\t},\n\t{ passive: true }\n);\n"]}
|
|
@@ -7,6 +7,11 @@ import { cloneBlock } from '@wordpress/blocks';
|
|
|
7
7
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
8
|
import { useEffect } from '@wordpress/element';
|
|
9
9
|
import { store as blockEditorStore, useBlockProps } from '@wordpress/block-editor';
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { unlock } from '../lock-unlock';
|
|
10
15
|
|
|
11
16
|
const PatternEdit = ({
|
|
12
17
|
attributes,
|
|
@@ -16,7 +21,14 @@ const PatternEdit = ({
|
|
|
16
21
|
const {
|
|
17
22
|
replaceBlocks,
|
|
18
23
|
__unstableMarkNextChangeAsNotPersistent
|
|
19
|
-
} = useDispatch(blockEditorStore);
|
|
24
|
+
} = useDispatch(blockEditorStore);
|
|
25
|
+
const {
|
|
26
|
+
setBlockEditingMode
|
|
27
|
+
} = unlock(useDispatch(blockEditorStore));
|
|
28
|
+
const {
|
|
29
|
+
getBlockRootClientId,
|
|
30
|
+
getBlockEditingMode
|
|
31
|
+
} = unlock(useSelect(blockEditorStore)); // Run this effect when the component loads.
|
|
20
32
|
// This adds the Pattern's contents to the post.
|
|
21
33
|
// This change won't be saved.
|
|
22
34
|
// It will continue to pull from the pattern file unless changes are made to its respective template part.
|
|
@@ -29,16 +41,27 @@ const PatternEdit = ({
|
|
|
29
41
|
// because nested pattern blocks cannot be inserted if the parent block supports
|
|
30
42
|
// inner blocks but doesn't have blockSettings in the state.
|
|
31
43
|
window.queueMicrotask(() => {
|
|
32
|
-
// Clone blocks from the pattern before insertion to ensure they receive
|
|
44
|
+
const rootClientId = getBlockRootClientId(clientId); // Clone blocks from the pattern before insertion to ensure they receive
|
|
33
45
|
// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.
|
|
46
|
+
|
|
34
47
|
const clonedBlocks = selectedPattern.blocks.map(block => cloneBlock(block));
|
|
48
|
+
const rootEditingMode = getBlockEditingMode(rootClientId); // Temporarily set the root block to default mode to allow replacing the pattern.
|
|
49
|
+
// This could happen when the page is disabling edits of non-content blocks.
|
|
50
|
+
|
|
51
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
52
|
+
|
|
53
|
+
setBlockEditingMode(rootClientId, 'default');
|
|
54
|
+
|
|
55
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
56
|
+
|
|
57
|
+
replaceBlocks(clientId, clonedBlocks); // Restore the root block's original mode.
|
|
35
58
|
|
|
36
59
|
__unstableMarkNextChangeAsNotPersistent();
|
|
37
60
|
|
|
38
|
-
|
|
61
|
+
setBlockEditingMode(rootClientId, rootEditingMode);
|
|
39
62
|
});
|
|
40
63
|
}
|
|
41
|
-
}, [clientId, selectedPattern?.blocks, __unstableMarkNextChangeAsNotPersistent, replaceBlocks]);
|
|
64
|
+
}, [clientId, selectedPattern?.blocks, __unstableMarkNextChangeAsNotPersistent, replaceBlocks, getBlockEditingMode, setBlockEditingMode, getBlockRootClientId]);
|
|
42
65
|
const props = useBlockProps();
|
|
43
66
|
return createElement("div", { ...props
|
|
44
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/pattern/edit.js"],"names":["cloneBlock","useSelect","useDispatch","useEffect","store","blockEditorStore","useBlockProps","PatternEdit","attributes","clientId","selectedPattern","select","__experimentalGetParsedPattern","slug","replaceBlocks","__unstableMarkNextChangeAsNotPersistent","blocks","window","queueMicrotask","clonedBlocks","map","block","props"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,mBAA3B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SACCC,KAAK,IAAIC,gBADV,EAECC,aAFD,QAGO,yBAHP;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/pattern/edit.js"],"names":["cloneBlock","useSelect","useDispatch","useEffect","store","blockEditorStore","useBlockProps","unlock","PatternEdit","attributes","clientId","selectedPattern","select","__experimentalGetParsedPattern","slug","replaceBlocks","__unstableMarkNextChangeAsNotPersistent","setBlockEditingMode","getBlockRootClientId","getBlockEditingMode","blocks","window","queueMicrotask","rootClientId","clonedBlocks","map","block","rootEditingMode","props"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,mBAA3B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SACCC,KAAK,IA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AAb,CAb4B,CAc5B;;AACAR,QAAAA,uCAAuC;;AACvCC,QAAAA,mBAAmB,CAAEM,YAAF,EAAgBI,eAAhB,CAAnB;AACA,OAjBD;AAkBA;AACD,GA1BQ,EA0BN,CACFjB,QADE,EAEFC,eAAe,EAAES,MAFf,EAGFJ,uCAHE,EAIFD,aAJE,EAKFI,mBALE,EAMFF,mBANE,EAOFC,oBAPE,CA1BM,CAAT;AAoCA,QAAMU,KAAK,GAAGtB,aAAa,EAA3B;AAEA,SAAO,0BAAUsB;AAAV,IAAP;AACA,CA3DD;;AA6DA,eAAepB,WAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { cloneBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport {\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst PatternEdit = ( { attributes, clientId } ) => {\n\tconst selectedPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tattributes.slug\n\t\t\t),\n\t\t[ attributes.slug ]\n\t);\n\n\tconst { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { setBlockEditingMode } = unlock( useDispatch( blockEditorStore ) );\n\tconst { getBlockRootClientId, getBlockEditingMode } = unlock(\n\t\tuseSelect( blockEditorStore )\n\t);\n\n\t// Run this effect when the component loads.\n\t// This adds the Pattern's contents to the post.\n\t// This change won't be saved.\n\t// It will continue to pull from the pattern file unless changes are made to its respective template part.\n\tuseEffect( () => {\n\t\tif ( selectedPattern?.blocks ) {\n\t\t\t// We batch updates to block list settings to avoid triggering cascading renders\n\t\t\t// for each container block included in a tree and optimize initial render.\n\t\t\t// Since the above uses microtasks, we need to use a microtask here as well,\n\t\t\t// because nested pattern blocks cannot be inserted if the parent block supports\n\t\t\t// inner blocks but doesn't have blockSettings in the state.\n\t\t\twindow.queueMicrotask( () => {\n\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\t\t// Clone blocks from the pattern before insertion to ensure they receive\n\t\t\t\t// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.\n\t\t\t\tconst clonedBlocks = selectedPattern.blocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tconst rootEditingMode = getBlockEditingMode( rootClientId );\n\t\t\t\t// Temporarily set the root block to default mode to allow replacing the pattern.\n\t\t\t\t// This could happen when the page is disabling edits of non-content blocks.\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\tsetBlockEditingMode( rootClientId, 'default' );\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceBlocks( clientId, clonedBlocks );\n\t\t\t\t// Restore the root block's original mode.\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\tsetBlockEditingMode( rootClientId, rootEditingMode );\n\t\t\t} );\n\t\t}\n\t}, [\n\t\tclientId,\n\t\tselectedPattern?.blocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\treplaceBlocks,\n\t\tgetBlockEditingMode,\n\t\tsetBlockEditingMode,\n\t\tgetBlockRootClientId,\n\t] );\n\n\tconst props = useBlockProps();\n\n\treturn <div { ...props } />;\n};\n\nexport default PatternEdit;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/preformatted/index.js"],"names":["__","preformatted","icon","initBlock","edit","save","transforms","name","metadata","settings","example","attributes","content","merge","attributesToMerge","init"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAY,IAAIC,IAAzB,QAAqC,kBAArC;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,qBAAtB;AACA,OAAOC,IAAP,MAAiB,QAAjB
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/preformatted/index.js"],"names":["__","preformatted","icon","initBlock","edit","save","transforms","name","metadata","settings","example","attributes","content","merge","attributesToMerge","init"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAY,IAAIC,IAAzB,QAAqC,kBAArC;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,qBAAtB;AACA,OAAOC,IAAP,MAAiB,QAAjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AAEA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBP,EAAAA,IADuB;AAEvBQ,EAAAA,OAAO,EAAE;AACRC,IAAAA,UAAU,EAAE;AACX;AACA;AACAC,MAAAA,OAAO,EAAEZ,EAAE,CACV,wQADU;AAGX;;AANW;AADJ,GAFc;AAYvBM,EAAAA,UAZuB;AAavBF,EAAAA,IAbuB;AAcvBC,EAAAA,IAduB;;AAevBQ,EAAAA,KAAK,CAAEF,UAAF,EAAcG,iBAAd,EAAkC;AACtC,WAAO;AACNF,MAAAA,OAAO,EAAED,UAAU,CAACC,OAAX,GAAqBE,iBAAiB,CAACF;AAD1C,KAAP;AAGA;;AAnBsB,CAAjB;AAsBP,OAAO,MAAMG,IAAI,GAAG,MAAMZ,SAAS,CAAE;AAAEI,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAF,CAA5B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { preformatted as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\t/* eslint-disable @wordpress/i18n-no-collapsible-whitespace */\n\t\t\t// translators: Sample content for the Preformatted block. Can be replaced with a more locale-adequate work.\n\t\t\tcontent: __(\n\t\t\t\t'EXT. XANADU - FAINT DAWN - 1940 (MINIATURE)\\nWindow, very small in the distance, illuminated.\\nAll around this is an almost totally black screen. Now, as the camera moves slowly towards the window which is almost a postage stamp in the frame, other forms appear;'\n\t\t\t),\n\t\t\t/* eslint-enable @wordpress/i18n-no-collapsible-whitespace */\n\t\t},\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent: attributes.content + attributesToMerge.content,\n\t\t};\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}
|