PluginProbe
LoftLoader / 2.1.9
LoftLoader v2.1.9
trunk 1.0.0 1.0.1 1.0.2 2.0.0 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3 2.3.1 2.3.2 2.3.3 All 34 releases
loftloader / inc / any-page / gutenberg / plugin.js

plugin.js in LoftLoader 2.1.9, at inc/any-page/gutenberg/plugin.js

120 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( editor, components, i18n, element, $ ) {
2 "use strict";
3
4 const __ = i18n.__;
5 const el = element.createElement;
6 const compose = wp.compose.compose;
7 const registerPlugin = wp.plugins.registerPlugin;
8
9 const {
10 Fragment,
11 Component
12 } = element;
13
14
15 const {
16 TextareaControl,
17 PanelBody
18 } = components;
19
20 const {
21 dispatch,
22 withSelect,
23 withDispatch
24 } = wp.data;
25
26 const {
27 PluginSidebar,
28 PluginSidebarMoreMenuItem
29 } = wp.editPost;
30
31 const Icon = el( 'svg', {
32 height: '20px',
33 width: '20px',
34 viewBox: '0 0 17.39 17.39'
35 }, el ( 'polygon', {
36 points: '14.77 11.19 17.3 8.65 14.77 6.12 14.77 2.53 11.19 2.53 8.65 0 6.12 2.53 2.53 2.53 2.53 6.12 0 8.65 2.53 11.19 2.53 14.77 6.12 14.77 8.65 17.3 11.19 14.77 14.77 14.77 14.77 11.19'
37 } )
38 );
39
40 class LoftLoaderPlugin extends Component {
41 constructor() {
42 super( ...arguments );
43
44 this.state = this.props.meta;
45 }
46 onSaveMeta( newValue ) {
47 dispatch( 'core/editor' ).editPost( { meta: { 'loftload-saving': 1 } } );
48 this.setState( newValue );
49 }
50 static getDerivedStateFromProps( nextProps, state ) {
51 if ( ( nextProps.isPublishing || nextProps.isSaving ) && ! nextProps.isAutoSaving ) {
52 wp.apiRequest( { path: '/loftloader/v2/update-meta?id=' + nextProps.postId, method: 'POST', data: state } ).then(
53 ( data ) => {
54 return data;
55 }, ( err ) => {
56 return err;
57 }
58 );
59 }
60 }
61 render() {
62 return el( Fragment, {},
63 el( PluginSidebarMoreMenuItem, { target: 'loftloader-any-page' }, __( 'LoftLoader Any Page Shortcode' ) ),
64 el( PluginSidebar, { name: 'loftloader-any-page', title: __( 'LoftLoader Any Page Shortcode' ) },
65 el( PanelBody, {
66 className: 'loftloader-any-page-sidebar',
67 initialOpen: true
68 },
69 el( TextareaControl, {
70 label: __( 'Paste LoftLoader shortcode into the box below' ),
71 value: this.state.loftloader_page_shortcode,
72 onChange: ( value ) => {
73 this.onSaveMeta( { loftloader_page_shortcode: value } );
74 }
75 } )
76 ),
77 el( 'input', {
78 type: 'hidden',
79 name: 'loftloader_gutenberg_enabled',
80 value: 'on'
81 } )
82 )
83 );
84 }
85 }
86
87 // Fetch the post meta.
88 const applyWithSelect = withSelect( ( select, { forceIsSaving } ) => {
89 const {
90 getEditedPostAttribute,
91 getCurrentPostId,
92 isSavingPost,
93 isPublishingPost,
94 isAutosavingPost,
95 } = select( 'core/editor' );
96
97 return {
98 meta: getEditedPostAttribute( 'meta' ),
99 postId: getCurrentPostId(),
100 isSaving: forceIsSaving || isSavingPost(),
101 isAutoSaving: isAutosavingPost(),
102 isPublishing: isPublishingPost(),
103 };
104 } );
105
106 const render = compose( [
107 applyWithSelect
108 ] )( LoftLoaderPlugin );
109
110 registerPlugin( 'loftloader-any-page', {
111 icon: Icon,
112 render
113 } );
114 } )(
115 window.wp.editor,
116 window.wp.components,
117 window.wp.i18n,
118 window.wp.element,
119 jQuery
120 );