PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / extend / effects / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.2, at gutenberg/extend/effects/index.js

157 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import './reveal';
2 import './pro-effects';
3
4 import { BlockControls, InspectorControls } from '@wordpress/block-editor';
5 import { hasBlockSupport } from '@wordpress/blocks';
6 import {
7 Button,
8 __experimentalToolsPanel as ExperimentalToolsPanel,
9 MenuGroup,
10 __stableToolsPanel as StableToolsPanel,
11 ToolbarDropdownMenu,
12 } from '@wordpress/components';
13 import { addFilter } from '@wordpress/hooks';
14 import { __ } from '@wordpress/i18n';
15
16 import ApplyFilters from '../../components/apply-filters';
17 import getIcon from '../../utils/get-icon';
18
19 const ToolsPanel = StableToolsPanel || ExperimentalToolsPanel;
20
21 /**
22 * Add inspector controls.
23 *
24 * @param original
25 * @param root0
26 * @param root0.props
27 */
28 function GhostKitExtensionEffectsInspector(original, { props }) {
29 const { name, attributes, setAttributes } = props;
30
31 const hasEffectsSupport = hasBlockSupport(name, ['ghostkit', 'effects']);
32
33 if (!hasEffectsSupport) {
34 return original;
35 }
36
37 return (
38 <>
39 {original}
40 <InspectorControls group="styles">
41 <ToolsPanel
42 className="ghostkit-tools-panel-with-icon ghostkit-tools-panel-with-icon-effects"
43 label={__('Effects', 'ghostkit')}
44 resetAll={() => {
45 const ghostkitData = {
46 ...(attributes?.ghostkit || {}),
47 };
48
49 if (typeof ghostkitData?.effects !== 'undefined') {
50 delete ghostkitData?.effects;
51
52 setAttributes({ ghostkit: ghostkitData });
53 }
54 }}
55 >
56 <div className="ghostkit-tools-panel-effects">
57 <ApplyFilters
58 name="ghostkit.extension.effects.tools"
59 props={props}
60 />
61 </div>
62 </ToolsPanel>
63 </InspectorControls>
64 </>
65 );
66 }
67
68 /**
69 * Add toolbar controls.
70 *
71 * @param original
72 * @param root0
73 * @param root0.props
74 */
75 function GhostKitExtensionEffectsToolbar(original, { props }) {
76 const { name, attributes, setAttributes } = props;
77
78 const hasEffectsSupport = hasBlockSupport(name, ['ghostkit', 'effects']);
79
80 if (!hasEffectsSupport) {
81 return original;
82 }
83
84 const hasEffects = attributes?.ghostkit?.effects;
85
86 if (!hasEffects) {
87 return original;
88 }
89
90 return (
91 <>
92 {original}
93 <BlockControls group="other">
94 <ToolbarDropdownMenu
95 icon={getIcon('extension-sr')}
96 label={__('Effects', 'ghostkit')}
97 menuProps={{
98 style: { width: '260px' },
99 }}
100 popoverProps={{ focusOnMount: false }}
101 >
102 {() => (
103 <>
104 <MenuGroup>
105 {__(
106 'There are effects added to the current block. To change these options open the "Effects" block settings panel.',
107 'ghostkit'
108 )}
109 </MenuGroup>
110 <MenuGroup>
111 {__(
112 'Reset all effects of the current block:',
113 'ghostkit'
114 )}
115 <Button
116 variant="link"
117 onClick={() => {
118 const ghostkitData = {
119 ...(attributes?.ghostkit || {}),
120 };
121
122 if (
123 typeof ghostkitData?.effects !==
124 'undefined'
125 ) {
126 delete ghostkitData?.effects;
127
128 setAttributes({
129 ghostkit: ghostkitData,
130 });
131 }
132 }}
133 >
134 {__('Reset All', 'ghostkit')}
135 </Button>
136 </MenuGroup>
137 </>
138 )}
139 </ToolbarDropdownMenu>
140 </BlockControls>
141 </>
142 );
143 }
144
145 // Init filters.
146 addFilter(
147 'ghostkit.editor.extensions',
148 'ghostkit/extension/effects/inspector',
149 GhostKitExtensionEffectsInspector,
150 11
151 );
152 addFilter(
153 'ghostkit.editor.extensions',
154 'ghostkit/extension/effects/toolbar',
155 GhostKitExtensionEffectsToolbar
156 );
157