-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
49 lines (43 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* WordPress dependencies
*/
import { createRoot } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import exportReusableBlock from './utils/export';
import ImportDropdown from './components/import-dropdown';
// Setup Export Links.
document.body.addEventListener( 'click', ( event ) => {
if (
! event.target.classList.contains( 'wp-list-reusable-blocks__export' )
) {
return;
}
event.preventDefault();
exportReusableBlock( event.target.dataset.id );
} );
// Setup Import Form.
document.addEventListener( 'DOMContentLoaded', () => {
const button = document.querySelector( '.page-title-action' );
if ( ! button ) {
return;
}
const showNotice = () => {
const notice = document.createElement( 'div' );
notice.className = 'notice notice-success is-dismissible';
notice.innerHTML = `<p>${ __( 'Pattern imported successfully!' ) }</p>`;
const headerEnd = document.querySelector( '.wp-header-end' );
if ( ! headerEnd ) {
return;
}
headerEnd.parentNode.insertBefore( notice, headerEnd );
};
const container = document.createElement( 'div' );
container.className = 'list-reusable-blocks__container';
button.parentNode.insertBefore( container, button );
createRoot( container ).render(
<ImportDropdown onUpload={ showNotice } />
);
} );