34 |
91 |
35 /** |
92 /** |
36 * Accepts a function to be memoized, and returns a new memoized function, with |
93 * Accepts a function to be memoized, and returns a new memoized function, with |
37 * optional options. |
94 * optional options. |
38 * |
95 * |
39 * @template {Function} F |
96 * @template {(...args: any[]) => any} F |
40 * |
97 * |
41 * @param {F} fn Function to memoize. |
98 * @param {F} fn Function to memoize. |
42 * @param {MemizeOptions} [options] Options object. |
99 * @param {MemizeOptions} [options] Options object. |
43 * |
100 * |
44 * @return {F & MemizeMemoizedFunction} Memoized function. |
101 * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function. |
45 */ |
102 */ |
46 function memize( fn, options ) { |
103 function memize(fn, options) { |
47 var size = 0; |
104 var size = 0; |
48 |
105 |
49 /** @type {?MemizeCacheNode|undefined} */ |
106 /** @type {?MemizeCacheNode|undefined} */ |
50 var head; |
107 var head; |
51 |
108 |
52 /** @type {?MemizeCacheNode|undefined} */ |
109 /** @type {?MemizeCacheNode|undefined} */ |
53 var tail; |
110 var tail; |
54 |
111 |
55 options = options || {}; |
112 options = options || {}; |
56 |
113 |
57 function memoized( /* ...args */ ) { |
114 function memoized(/* ...args */) { |
58 var node = head, |
115 var node = head, |
59 len = arguments.length, |
116 len = arguments.length, |
60 args, i; |
117 args, |
61 |
118 i; |
62 searchCache: while ( node ) { |
119 |
|
120 searchCache: while (node) { |
63 // Perform a shallow equality test to confirm that whether the node |
121 // Perform a shallow equality test to confirm that whether the node |
64 // under test is a candidate for the arguments passed. Two arrays |
122 // under test is a candidate for the arguments passed. Two arrays |
65 // are shallowly equal if their length matches and each entry is |
123 // are shallowly equal if their length matches and each entry is |
66 // strictly equal between the two sets. Avoid abstracting to a |
124 // strictly equal between the two sets. Avoid abstracting to a |
67 // function which could incur an arguments leaking deoptimization. |
125 // function which could incur an arguments leaking deoptimization. |
68 |
126 |
69 // Check whether node arguments match arguments length |
127 // Check whether node arguments match arguments length |
70 if ( node.args.length !== arguments.length ) { |
128 if (node.args.length !== arguments.length) { |
71 node = node.next; |
129 node = node.next; |
72 continue; |
130 continue; |
73 } |
131 } |
74 |
132 |
75 // Check whether node arguments match arguments values |
133 // Check whether node arguments match arguments values |
76 for ( i = 0; i < len; i++ ) { |
134 for (i = 0; i < len; i++) { |
77 if ( node.args[ i ] !== arguments[ i ] ) { |
135 if (node.args[i] !== arguments[i]) { |
78 node = node.next; |
136 node = node.next; |
79 continue searchCache; |
137 continue searchCache; |
80 } |
138 } |
81 } |
139 } |
82 |
140 |
83 // At this point we can assume we've found a match |
141 // At this point we can assume we've found a match |
84 |
142 |
85 // Surface matched node to head if not already |
143 // Surface matched node to head if not already |
86 if ( node !== head ) { |
144 if (node !== head) { |
87 // As tail, shift to previous. Must only shift if not also |
145 // As tail, shift to previous. Must only shift if not also |
88 // head, since if both head and tail, there is no previous. |
146 // head, since if both head and tail, there is no previous. |
89 if ( node === tail ) { |
147 if (node === tail) { |
90 tail = node.prev; |
148 tail = node.prev; |
91 } |
149 } |
92 |
150 |
93 // Adjust siblings to point to each other. If node was tail, |
151 // Adjust siblings to point to each other. If node was tail, |
94 // this also handles new tail's empty `next` assignment. |
152 // this also handles new tail's empty `next` assignment. |
95 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next; |
153 /** @type {MemizeCacheNode} */ (node.prev).next = node.next; |
96 if ( node.next ) { |
154 if (node.next) { |
97 node.next.prev = node.prev; |
155 node.next.prev = node.prev; |
98 } |
156 } |
99 |
157 |
100 node.next = head; |
158 node.next = head; |
101 node.prev = null; |
159 node.prev = null; |
102 /** @type {MemizeCacheNode} */ ( head ).prev = node; |
160 /** @type {MemizeCacheNode} */ (head).prev = node; |
103 head = node; |
161 head = node; |
104 } |
162 } |
105 |
163 |
106 // Return immediately |
164 // Return immediately |
107 return node.val; |
165 return node.val; |
108 } |
166 } |
109 |
167 |
110 // No cached value found. Continue to insertion phase: |
168 // No cached value found. Continue to insertion phase: |
111 |
169 |
112 // Create a copy of arguments (avoid leaking deoptimization) |
170 // Create a copy of arguments (avoid leaking deoptimization) |
113 args = new Array( len ); |
171 args = new Array(len); |
114 for ( i = 0; i < len; i++ ) { |
172 for (i = 0; i < len; i++) { |
115 args[ i ] = arguments[ i ]; |
173 args[i] = arguments[i]; |
116 } |
174 } |
117 |
175 |
118 node = { |
176 node = { |
119 args: args, |
177 args: args, |
120 |
178 |
121 // Generate the result from original function |
179 // Generate the result from original function |
122 val: fn.apply( null, args ), |
180 val: fn.apply(null, args), |
123 }; |
181 }; |
124 |
182 |
125 // Don't need to check whether node is already head, since it would |
183 // Don't need to check whether node is already head, since it would |
126 // have been returned above already if it was |
184 // have been returned above already if it was |
127 |
185 |
128 // Shift existing head down list |
186 // Shift existing head down list |
129 if ( head ) { |
187 if (head) { |
130 head.prev = node; |
188 head.prev = node; |
131 node.next = head; |
189 node.next = head; |
132 } else { |
190 } else { |
133 // If no head, follows that there's no tail (at initial or reset) |
191 // If no head, follows that there's no tail (at initial or reset) |
134 tail = node; |
192 tail = node; |
135 } |
193 } |
136 |
194 |
137 // Trim tail if we're reached max size and are pending cache insertion |
195 // Trim tail if we're reached max size and are pending cache insertion |
138 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) { |
196 if (size === /** @type {MemizeOptions} */ (options).maxSize) { |
139 tail = /** @type {MemizeCacheNode} */ ( tail ).prev; |
197 tail = /** @type {MemizeCacheNode} */ (tail).prev; |
140 /** @type {MemizeCacheNode} */ ( tail ).next = null; |
198 /** @type {MemizeCacheNode} */ (tail).next = null; |
141 } else { |
199 } else { |
142 size++; |
200 size++; |
143 } |
201 } |
144 |
202 |
145 head = node; |
203 head = node; |
146 |
204 |
147 return node.val; |
205 return node.val; |
148 } |
206 } |
149 |
207 |
150 memoized.clear = function() { |
208 memoized.clear = function () { |
151 head = null; |
209 head = null; |
152 tail = null; |
210 tail = null; |
153 size = 0; |
211 size = 0; |
154 }; |
212 }; |
155 |
213 |
156 if ( false ) {} |
|
157 |
|
158 // Ignore reason: There's not a clear solution to create an intersection of |
214 // Ignore reason: There's not a clear solution to create an intersection of |
159 // the function with additional properties, where the goal is to retain the |
215 // the function with additional properties, where the goal is to retain the |
160 // function signature of the incoming argument and add control properties |
216 // function signature of the incoming argument and add control properties |
161 // on the return value. |
217 // on the return value. |
162 |
218 |
163 // @ts-ignore |
219 // @ts-ignore |
164 return memoized; |
220 return memoized; |
165 } |
221 } |
166 |
222 |
167 module.exports = memize; |
223 |
168 |
|
169 |
|
170 /***/ }) |
|
171 |
|
172 /******/ }); |
|
173 /************************************************************************/ |
|
174 /******/ // The module cache |
|
175 /******/ var __webpack_module_cache__ = {}; |
|
176 /******/ |
|
177 /******/ // The require function |
|
178 /******/ function __webpack_require__(moduleId) { |
|
179 /******/ // Check if module is in cache |
|
180 /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
181 /******/ if (cachedModule !== undefined) { |
|
182 /******/ return cachedModule.exports; |
|
183 /******/ } |
|
184 /******/ // Create a new module (and put it into the cache) |
|
185 /******/ var module = __webpack_module_cache__[moduleId] = { |
|
186 /******/ // no module.id needed |
|
187 /******/ // no module.loaded needed |
|
188 /******/ exports: {} |
|
189 /******/ }; |
|
190 /******/ |
|
191 /******/ // Execute the module function |
|
192 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
193 /******/ |
|
194 /******/ // Return the exports of the module |
|
195 /******/ return module.exports; |
|
196 /******/ } |
|
197 /******/ |
|
198 /************************************************************************/ |
|
199 /******/ /* webpack/runtime/compat get default export */ |
|
200 /******/ !function() { |
|
201 /******/ // getDefaultExport function for compatibility with non-harmony modules |
|
202 /******/ __webpack_require__.n = function(module) { |
|
203 /******/ var getter = module && module.__esModule ? |
|
204 /******/ function() { return module['default']; } : |
|
205 /******/ function() { return module; }; |
|
206 /******/ __webpack_require__.d(getter, { a: getter }); |
|
207 /******/ return getter; |
|
208 /******/ }; |
|
209 /******/ }(); |
|
210 /******/ |
|
211 /******/ /* webpack/runtime/define property getters */ |
|
212 /******/ !function() { |
|
213 /******/ // define getter functions for harmony exports |
|
214 /******/ __webpack_require__.d = function(exports, definition) { |
|
215 /******/ for(var key in definition) { |
|
216 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
217 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
218 /******/ } |
|
219 /******/ } |
|
220 /******/ }; |
|
221 /******/ }(); |
|
222 /******/ |
|
223 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
224 /******/ !function() { |
|
225 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
|
226 /******/ }(); |
|
227 /******/ |
|
228 /******/ /* webpack/runtime/make namespace object */ |
|
229 /******/ !function() { |
|
230 /******/ // define __esModule on exports |
|
231 /******/ __webpack_require__.r = function(exports) { |
|
232 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
|
233 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
234 /******/ } |
|
235 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
236 /******/ }; |
|
237 /******/ }(); |
|
238 /******/ |
|
239 /************************************************************************/ |
|
240 var __webpack_exports__ = {}; |
|
241 // This entry need to be wrapped in an IIFE because it need to be in strict mode. |
|
242 !function() { |
|
243 "use strict"; |
|
244 // ESM COMPAT FLAG |
|
245 __webpack_require__.r(__webpack_exports__); |
|
246 |
|
247 // EXPORTS |
|
248 __webpack_require__.d(__webpack_exports__, { |
|
249 "PluginArea": function() { return /* reexport */ plugin_area; }, |
|
250 "getPlugin": function() { return /* reexport */ getPlugin; }, |
|
251 "getPlugins": function() { return /* reexport */ getPlugins; }, |
|
252 "registerPlugin": function() { return /* reexport */ registerPlugin; }, |
|
253 "unregisterPlugin": function() { return /* reexport */ unregisterPlugin; }, |
|
254 "withPluginContext": function() { return /* reexport */ withPluginContext; } |
|
255 }); |
|
256 |
224 |
257 ;// CONCATENATED MODULE: external ["wp","element"] |
225 ;// CONCATENATED MODULE: external ["wp","element"] |
258 var external_wp_element_namespaceObject = window["wp"]["element"]; |
226 const external_wp_element_namespaceObject = window["wp"]["element"]; |
259 ;// CONCATENATED MODULE: external "lodash" |
|
260 var external_lodash_namespaceObject = window["lodash"]; |
|
261 // EXTERNAL MODULE: ./node_modules/memize/index.js |
|
262 var memize = __webpack_require__(9756); |
|
263 var memize_default = /*#__PURE__*/__webpack_require__.n(memize); |
|
264 ;// CONCATENATED MODULE: external ["wp","hooks"] |
227 ;// CONCATENATED MODULE: external ["wp","hooks"] |
265 var external_wp_hooks_namespaceObject = window["wp"]["hooks"]; |
228 const external_wp_hooks_namespaceObject = window["wp"]["hooks"]; |
266 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
229 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"] |
267 function _extends() { |
230 const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
268 _extends = Object.assign ? Object.assign.bind() : function (target) { |
231 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
269 for (var i = 1; i < arguments.length; i++) { |
|
270 var source = arguments[i]; |
|
271 |
|
272 for (var key in source) { |
|
273 if (Object.prototype.hasOwnProperty.call(source, key)) { |
|
274 target[key] = source[key]; |
|
275 } |
|
276 } |
|
277 } |
|
278 |
|
279 return target; |
|
280 }; |
|
281 return _extends.apply(this, arguments); |
|
282 } |
|
283 ;// CONCATENATED MODULE: external ["wp","compose"] |
232 ;// CONCATENATED MODULE: external ["wp","compose"] |
284 var external_wp_compose_namespaceObject = window["wp"]["compose"]; |
233 const external_wp_compose_namespaceObject = window["wp"]["compose"]; |
|
234 ;// CONCATENATED MODULE: external "ReactJSXRuntime" |
|
235 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
285 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-context/index.js |
236 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-context/index.js |
286 |
|
287 |
|
288 |
|
289 /** |
237 /** |
290 * WordPress dependencies |
238 * WordPress dependencies |
291 */ |
239 */ |
292 |
240 |
293 |
241 |
294 const { |
242 |
295 Consumer, |
243 /** |
296 Provider |
244 * Internal dependencies |
297 } = (0,external_wp_element_namespaceObject.createContext)({ |
245 */ |
|
246 |
|
247 const Context = (0,external_wp_element_namespaceObject.createContext)({ |
298 name: null, |
248 name: null, |
299 icon: null |
249 icon: null |
300 }); |
250 }); |
|
251 const PluginContextProvider = Context.Provider; |
|
252 |
|
253 /** |
|
254 * A hook that returns the plugin context. |
|
255 * |
|
256 * @return {PluginContext} Plugin context |
|
257 */ |
|
258 function usePluginContext() { |
|
259 return (0,external_wp_element_namespaceObject.useContext)(Context); |
|
260 } |
301 |
261 |
302 /** |
262 /** |
303 * A Higher Order Component used to inject Plugin context to the |
263 * A Higher Order Component used to inject Plugin context to the |
304 * wrapped component. |
264 * wrapped component. |
305 * |
265 * |
306 * @param {Function} mapContextToProps Function called on every context change, |
266 * @param mapContextToProps Function called on every context change, |
307 * expected to return object of props to |
267 * expected to return object of props to |
308 * merge with the component's own props. |
268 * merge with the component's own props. |
309 * |
269 * |
310 * @return {WPComponent} Enhanced component with injected context as props. |
270 * @return {Component} Enhanced component with injected context as props. |
311 */ |
271 */ |
312 |
|
313 const withPluginContext = mapContextToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => { |
272 const withPluginContext = mapContextToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => { |
314 return props => (0,external_wp_element_namespaceObject.createElement)(Consumer, null, context => (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, props, mapContextToProps(context, props)))); |
273 return props => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Context.Consumer, { |
|
274 children: context => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { |
|
275 ...props, |
|
276 ...mapContextToProps(context, props) |
|
277 }) |
|
278 }); |
315 }, 'withPluginContext'); |
279 }, 'withPluginContext'); |
316 |
280 |
317 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-error-boundary/index.js |
281 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/plugin-error-boundary/index.js |
318 /** |
282 /** |
319 * WordPress dependencies |
283 * WordPress dependencies |
320 */ |
284 */ |
321 |
285 |
322 class PluginErrorBoundary extends external_wp_element_namespaceObject.Component { |
286 class PluginErrorBoundary extends external_wp_element_namespaceObject.Component { |
|
287 /** |
|
288 * @param {Object} props |
|
289 */ |
323 constructor(props) { |
290 constructor(props) { |
324 super(props); |
291 super(props); |
325 this.state = { |
292 this.state = { |
326 hasError: false |
293 hasError: false |
327 }; |
294 }; |
328 } |
295 } |
329 |
|
330 static getDerivedStateFromError() { |
296 static getDerivedStateFromError() { |
331 return { |
297 return { |
332 hasError: true |
298 hasError: true |
333 }; |
299 }; |
334 } |
300 } |
335 |
301 |
|
302 /** |
|
303 * @param {Error} error Error object passed by React. |
|
304 */ |
336 componentDidCatch(error) { |
305 componentDidCatch(error) { |
337 const { |
306 const { |
338 name, |
307 name, |
339 onError |
308 onError |
340 } = this.props; |
309 } = this.props; |
341 |
|
342 if (onError) { |
310 if (onError) { |
343 onError(name, error); |
311 onError(name, error); |
344 } |
312 } |
345 } |
313 } |
346 |
|
347 render() { |
314 render() { |
348 if (!this.state.hasError) { |
315 if (!this.state.hasError) { |
349 return this.props.children; |
316 return this.props.children; |
350 } |
317 } |
351 |
|
352 return null; |
318 return null; |
353 } |
319 } |
354 |
|
355 } |
320 } |
356 |
321 |
357 ;// CONCATENATED MODULE: external ["wp","primitives"] |
322 ;// CONCATENATED MODULE: external ["wp","primitives"] |
358 var external_wp_primitives_namespaceObject = window["wp"]["primitives"]; |
323 const external_wp_primitives_namespaceObject = window["wp"]["primitives"]; |
359 ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/plugins.js |
324 ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/plugins.js |
360 |
|
361 |
|
362 /** |
325 /** |
363 * WordPress dependencies |
326 * WordPress dependencies |
364 */ |
327 */ |
365 |
328 |
366 const plugins = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { |
329 |
|
330 const plugins = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, { |
367 xmlns: "http://www.w3.org/2000/svg", |
331 xmlns: "http://www.w3.org/2000/svg", |
368 viewBox: "0 0 24 24" |
332 viewBox: "0 0 24 24", |
369 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { |
333 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, { |
370 d: "M10.5 4v4h3V4H15v4h1.5a1 1 0 011 1v4l-3 4v2a1 1 0 01-1 1h-3a1 1 0 01-1-1v-2l-3-4V9a1 1 0 011-1H9V4h1.5zm.5 12.5v2h2v-2l3-4v-3H8v3l3 4z" |
334 d: "M10.5 4v4h3V4H15v4h1.5a1 1 0 011 1v4l-3 4v2a1 1 0 01-1 1h-3a1 1 0 01-1-1v-2l-3-4V9a1 1 0 011-1H9V4h1.5zm.5 12.5v2h2v-2l3-4v-3H8v3l3 4z" |
371 })); |
335 }) |
372 /* harmony default export */ var library_plugins = (plugins); |
336 }); |
|
337 /* harmony default export */ const library_plugins = (plugins); |
373 |
338 |
374 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/api/index.js |
339 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/api/index.js |
375 /* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */ |
340 /* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */ |
|
341 /** |
|
342 * External dependencies |
|
343 */ |
376 |
344 |
377 /** |
345 /** |
378 * WordPress dependencies |
346 * WordPress dependencies |
379 */ |
347 */ |
380 |
348 |
381 |
349 |
382 /** |
|
383 * External dependencies |
|
384 */ |
|
385 |
|
386 |
350 |
387 /** |
351 /** |
388 * Defined behavior of a plugin type. |
352 * Defined behavior of a plugin type. |
389 * |
|
390 * @typedef {Object} WPPlugin |
|
391 * |
|
392 * @property {string} name A string identifying the plugin. Must be |
|
393 * unique across all registered plugins. |
|
394 * @property {string|WPElement|Function} [icon] An icon to be shown in the UI. It can |
|
395 * be a slug of the Dashicon, or an element |
|
396 * (or function returning an element) if you |
|
397 * choose to render your own SVG. |
|
398 * @property {Function} render A component containing the UI elements |
|
399 * to be rendered. |
|
400 * @property {string} [scope] The optional scope to be used when rendering inside |
|
401 * a plugin area. No scope by default. |
|
402 */ |
353 */ |
403 |
354 |
404 /** |
355 /** |
405 * Plugin definitions keyed by plugin name. |
356 * Plugin definitions keyed by plugin name. |
406 * |
357 */ |
407 * @type {Object.<string,WPPlugin>} |
|
408 */ |
|
409 |
|
410 const api_plugins = {}; |
358 const api_plugins = {}; |
|
359 |
411 /** |
360 /** |
412 * Registers a plugin to the editor. |
361 * Registers a plugin to the editor. |
413 * |
362 * |
414 * @param {string} name A string identifying the plugin.Must be |
363 * @param name A string identifying the plugin. Must be |
415 * unique across all registered plugins. |
364 * unique across all registered plugins. |
416 * @param {WPPlugin} settings The settings for this plugin. |
365 * @param settings The settings for this plugin. |
417 * |
366 * |
418 * @example |
367 * @example |
419 * ```js |
368 * ```js |
420 * // Using ES5 syntax |
369 * // Using ES5 syntax |
421 * var el = wp.element.createElement; |
370 * var el = React.createElement; |
422 * var Fragment = wp.element.Fragment; |
371 * var Fragment = wp.element.Fragment; |
423 * var PluginSidebar = wp.editPost.PluginSidebar; |
372 * var PluginSidebar = wp.editor.PluginSidebar; |
424 * var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem; |
373 * var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem; |
425 * var registerPlugin = wp.plugins.registerPlugin; |
374 * var registerPlugin = wp.plugins.registerPlugin; |
426 * var moreIcon = wp.element.createElement( 'svg' ); //... svg element. |
375 * var moreIcon = React.createElement( 'svg' ); //... svg element. |
427 * |
376 * |
428 * function Component() { |
377 * function Component() { |
429 * return el( |
378 * return el( |
430 * Fragment, |
379 * Fragment, |
431 * {}, |
380 * {}, |
648 * <PluginArea scope="my-page" /> |
594 * <PluginArea scope="my-page" /> |
649 * </div> |
595 * </div> |
650 * ); |
596 * ); |
651 * ``` |
597 * ``` |
652 * |
598 * |
653 * @return {WPComponent} The component to be rendered. |
599 * @return {Component} The component to be rendered. |
654 */ |
600 */ |
655 |
601 function PluginArea({ |
656 class PluginArea extends external_wp_element_namespaceObject.Component { |
602 scope, |
657 constructor() { |
603 onError |
658 super(...arguments); |
604 }) { |
659 this.setPlugins = this.setPlugins.bind(this); |
605 const store = (0,external_wp_element_namespaceObject.useMemo)(() => { |
660 this.memoizedContext = memize_default()((name, icon) => { |
606 let lastValue = []; |
661 return { |
|
662 name, |
|
663 icon |
|
664 }; |
|
665 }); |
|
666 this.state = this.getCurrentPluginsState(); |
|
667 } |
|
668 |
|
669 getCurrentPluginsState() { |
|
670 return { |
607 return { |
671 plugins: (0,external_lodash_namespaceObject.map)(getPlugins(this.props.scope), _ref => { |
608 subscribe(listener) { |
672 let { |
609 (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', listener); |
673 icon, |
610 (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered', listener); |
674 name, |
611 return () => { |
675 render |
612 (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered'); |
676 } = _ref; |
613 (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered'); |
677 return { |
|
678 Plugin: render, |
|
679 context: this.memoizedContext(name, icon) |
|
680 }; |
614 }; |
|
615 }, |
|
616 getValue() { |
|
617 const nextValue = getPlugins(scope); |
|
618 if (!external_wp_isShallowEqual_default()(lastValue, nextValue)) { |
|
619 lastValue = nextValue; |
|
620 } |
|
621 return lastValue; |
|
622 } |
|
623 }; |
|
624 }, [scope]); |
|
625 const plugins = (0,external_wp_element_namespaceObject.useSyncExternalStore)(store.subscribe, store.getValue, store.getValue); |
|
626 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { |
|
627 style: { |
|
628 display: 'none' |
|
629 }, |
|
630 children: plugins.map(({ |
|
631 icon, |
|
632 name, |
|
633 render: Plugin |
|
634 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginContextProvider, { |
|
635 value: getPluginContext(icon, name), |
|
636 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PluginErrorBoundary, { |
|
637 name: name, |
|
638 onError: onError, |
|
639 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Plugin, {}) |
681 }) |
640 }) |
682 }; |
641 }, name)) |
683 } |
642 }); |
684 |
643 } |
685 componentDidMount() { |
644 /* harmony default export */ const plugin_area = (PluginArea); |
686 (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', this.setPlugins); |
|
687 (0,external_wp_hooks_namespaceObject.addAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered', this.setPlugins); |
|
688 } |
|
689 |
|
690 componentWillUnmount() { |
|
691 (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered'); |
|
692 (0,external_wp_hooks_namespaceObject.removeAction)('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered'); |
|
693 } |
|
694 |
|
695 setPlugins() { |
|
696 this.setState(this.getCurrentPluginsState); |
|
697 } |
|
698 |
|
699 render() { |
|
700 return (0,external_wp_element_namespaceObject.createElement)("div", { |
|
701 style: { |
|
702 display: 'none' |
|
703 } |
|
704 }, (0,external_lodash_namespaceObject.map)(this.state.plugins, _ref2 => { |
|
705 let { |
|
706 context, |
|
707 Plugin |
|
708 } = _ref2; |
|
709 return (0,external_wp_element_namespaceObject.createElement)(Provider, { |
|
710 key: context.name, |
|
711 value: context |
|
712 }, (0,external_wp_element_namespaceObject.createElement)(PluginErrorBoundary, { |
|
713 name: context.name, |
|
714 onError: this.props.onError |
|
715 }, (0,external_wp_element_namespaceObject.createElement)(Plugin, null))); |
|
716 })); |
|
717 } |
|
718 |
|
719 } |
|
720 |
|
721 /* harmony default export */ var plugin_area = (PluginArea); |
|
722 |
645 |
723 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/index.js |
646 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/components/index.js |
724 |
647 |
725 |
648 |
726 |
649 |
727 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/index.js |
650 ;// CONCATENATED MODULE: ./node_modules/@wordpress/plugins/build-module/index.js |
728 |
651 |
729 |
652 |
730 |
653 |
731 }(); |
|
732 (window.wp = window.wp || {}).plugins = __webpack_exports__; |
654 (window.wp = window.wp || {}).plugins = __webpack_exports__; |
733 /******/ })() |
655 /******/ })() |
734 ; |
656 ; |