PluginProbe
LoftLoader / 2.1.6
LoftLoader v2.1.6
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.6, at inc/any-page/gutenberg/plugin.js

117 lines 2.7 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
47 static getDerivedStateFromProps( nextProps, state ) {
48 if ( ( nextProps.isPublishing || nextProps.isSaving ) && ! nextProps.isAutoSaving ) {
49 wp.apiRequest( { path: '/loftloader/v2/update-meta?id=' + nextProps.postId, method: 'POST', data: state } ).then(
50 ( data ) => {
51 return data;
52 }, ( err ) => {
53 return err;
54 }
55 );
56 }
57 }
58 render() {
59 return el( Fragment, {},
60 el( PluginSidebarMoreMenuItem, { target: 'loftloader-any-page' }, __( 'LoftLoader Any Page Shortcode' ) ),
61 el( PluginSidebar, { name: 'loftloader-any-page', title: __( 'LoftLoader Any Page Shortcode' ) },
62 el( PanelBody, {
63 className: 'loftloader-any-page-sidebar',
64 initialOpen: true
65 },
66 el( TextareaControl, {
67 label: __( 'Paste LoftLoader shortcode into the box below' ),
68 value: this.state.loftloader_page_shortcode,
69 onChange: ( value ) => {
70 this.setState( { loftloader_page_shortcode: value } );
71 }
72 } )
73 ),
74 el( 'input', {
75 type: 'hidden',
76 name: 'loftloader_gutenberg_enabled',
77 value: 'on'
78 } )
79 )
80 );
81 }
82 }
83
84 // Fetch the post meta.
85 const applyWithSelect = withSelect( ( select, { forceIsSaving } ) => {
86 const {
87 getEditedPostAttribute,
88 getCurrentPostId,
89 isSavingPost,
90 isPublishingPost,
91 isAutosavingPost,
92 } = select( 'core/editor' );
93
94 return {
95 meta: getEditedPostAttribute( 'meta' ),
96 postId: getCurrentPostId(),
97 isSaving: forceIsSaving || isSavingPost(),
98 isAutoSaving: isAutosavingPost(),
99 isPublishing: isPublishingPost(),
100 };
101 } );
102
103 const render = compose( [
104 applyWithSelect
105 ] )( LoftLoaderPlugin );
106
107 registerPlugin( 'loftloader-any-page', {
108 icon: Icon,
109 render
110 } );
111 } )(
112 window.wp.editor,
113 window.wp.components,
114 window.wp.i18n,
115 window.wp.element,
116 jQuery
117 );