PluginProbe
Extendify / 0.6.0
Extendify v0.6.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / buttons.js

buttons.js in Extendify 0.6.0, at src/buttons.js

102 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { PluginSidebarMoreMenuItem } from '@wordpress/edit-post'
2 import { render } from '@wordpress/element'
3 import { __ } from '@wordpress/i18n'
4 import { Icon } from '@wordpress/icons'
5 import { registerPlugin } from '@wordpress/plugins'
6 import LibraryAccessModal from '@extendify/components/LibraryAccessModal'
7 import { CtaButton, MainButtonWrapper } from '@extendify/components/MainButtons'
8 import { brandMark } from '@extendify/components/icons/'
9
10 const userState = window.extendifyData?.user?.state
11 const isAdmin = () => window.extendifyData.user === null || userState?.isAdmin
12 const isGlobalLibraryEnabled = () =>
13 window.extendifyData.sitesettings === null ||
14 window.extendifyData?.sitesettings?.state?.enabled
15 const isLibraryEnabled = () =>
16 window.extendifyData.user === null
17 ? isGlobalLibraryEnabled()
18 : userState?.enabled
19
20 // Add the MAIN button when Gutenberg is available and ready
21 if (window._wpLoadBlockEditor) {
22 const finish = window.wp.data.subscribe(() => {
23 requestAnimationFrame(() => {
24 if (!isGlobalLibraryEnabled() && !isAdmin()) {
25 return
26 }
27 if (document.getElementById('extendify-templates-inserter')) {
28 return
29 }
30 if (!document.querySelector('.edit-post-header-toolbar')) {
31 return
32 }
33 const buttonContainer = Object.assign(
34 document.createElement('div'),
35 { id: 'extendify-templates-inserter' },
36 )
37 document
38 .querySelector('.edit-post-header-toolbar')
39 .append(buttonContainer)
40 render(<MainButtonWrapper />, buttonContainer)
41
42 if (!isLibraryEnabled()) {
43 document
44 .getElementById('extendify-templates-inserter-btn')
45 .classList.add('hidden')
46 }
47 finish()
48 })
49 })
50 }
51
52 // The CTA button inside patterns
53 if (window._wpLoadBlockEditor) {
54 window.wp.data.subscribe(() => {
55 requestAnimationFrame(() => {
56 if (!isGlobalLibraryEnabled() && !isAdmin()) {
57 return
58 }
59 if (!document.querySelector('[id$=patterns-view]')) {
60 return
61 }
62 if (document.getElementById('extendify-cta-button')) {
63 return
64 }
65 const ctaButtonContainer = Object.assign(
66 document.createElement('div'),
67 { id: 'extendify-cta-button-container' },
68 )
69
70 document
71 .querySelector('[id$=patterns-view]')
72 .prepend(ctaButtonContainer)
73 render(<CtaButton />, ctaButtonContainer)
74 })
75 })
76 }
77
78 // This will add a button to enable or disable the library button
79 const LibraryEnableDisable = () => {
80 function setOpenSiteSettingsModal() {
81 const util = document.getElementById('extendify-util')
82 render(<LibraryAccessModal />, util)
83 }
84
85 return (
86 <>
87 <PluginSidebarMoreMenuItem
88 onClick={setOpenSiteSettingsModal}
89 icon={<Icon icon={brandMark} size={24} />}>
90 {' '}
91 {__('Extendify', 'extendify')}
92 </PluginSidebarMoreMenuItem>
93 </>
94 )
95 }
96
97 // Load this button always, which is used to enable or disable
98 window._wpLoadBlockEditor &&
99 registerPlugin('extendify-settings-enable-disable', {
100 render: LibraryEnableDisable,
101 })
102