PluginProbe
Gutenberg / 23.2.2
Gutenberg v23.2.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / plugins / index.js

index.js in Gutenberg 23.2.2, at build/scripts/plugins/index.js

366 lines 11.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var wp;
3 (wp ||= {}).plugins = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name in all)
15 __defProp(target, name, { get: all[name], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/element
36 var require_element = __commonJS({
37 "package-external:@wordpress/element"(exports, module) {
38 module.exports = window.wp.element;
39 }
40 });
41
42 // package-external:@wordpress/hooks
43 var require_hooks = __commonJS({
44 "package-external:@wordpress/hooks"(exports, module) {
45 module.exports = window.wp.hooks;
46 }
47 });
48
49 // package-external:@wordpress/is-shallow-equal
50 var require_is_shallow_equal = __commonJS({
51 "package-external:@wordpress/is-shallow-equal"(exports, module) {
52 module.exports = window.wp.isShallowEqual;
53 }
54 });
55
56 // package-external:@wordpress/compose
57 var require_compose = __commonJS({
58 "package-external:@wordpress/compose"(exports, module) {
59 module.exports = window.wp.compose;
60 }
61 });
62
63 // package-external:@wordpress/deprecated
64 var require_deprecated = __commonJS({
65 "package-external:@wordpress/deprecated"(exports, module) {
66 module.exports = window.wp.deprecated;
67 }
68 });
69
70 // vendor-external:react/jsx-runtime
71 var require_jsx_runtime = __commonJS({
72 "vendor-external:react/jsx-runtime"(exports, module) {
73 module.exports = window.ReactJSXRuntime;
74 }
75 });
76
77 // package-external:@wordpress/primitives
78 var require_primitives = __commonJS({
79 "package-external:@wordpress/primitives"(exports, module) {
80 module.exports = window.wp.primitives;
81 }
82 });
83
84 // packages/plugins/build-module/index.mjs
85 var index_exports = {};
86 __export(index_exports, {
87 PluginArea: () => plugin_area_default,
88 getPlugin: () => getPlugin,
89 getPlugins: () => getPlugins,
90 registerPlugin: () => registerPlugin,
91 unregisterPlugin: () => unregisterPlugin,
92 usePluginContext: () => usePluginContext,
93 withPluginContext: () => withPluginContext
94 });
95
96 // node_modules/memize/dist/index.js
97 function memize(fn, options) {
98 var size = 0;
99 var head;
100 var tail;
101 options = options || {};
102 function memoized() {
103 var node = head, len = arguments.length, args, i;
104 searchCache: while (node) {
105 if (node.args.length !== arguments.length) {
106 node = node.next;
107 continue;
108 }
109 for (i = 0; i < len; i++) {
110 if (node.args[i] !== arguments[i]) {
111 node = node.next;
112 continue searchCache;
113 }
114 }
115 if (node !== head) {
116 if (node === tail) {
117 tail = node.prev;
118 }
119 node.prev.next = node.next;
120 if (node.next) {
121 node.next.prev = node.prev;
122 }
123 node.next = head;
124 node.prev = null;
125 head.prev = node;
126 head = node;
127 }
128 return node.val;
129 }
130 args = new Array(len);
131 for (i = 0; i < len; i++) {
132 args[i] = arguments[i];
133 }
134 node = {
135 args,
136 // Generate the result from original function
137 val: fn.apply(null, args)
138 };
139 if (head) {
140 head.prev = node;
141 node.next = head;
142 } else {
143 tail = node;
144 }
145 if (size === /** @type {MemizeOptions} */
146 options.maxSize) {
147 tail = /** @type {MemizeCacheNode} */
148 tail.prev;
149 tail.next = null;
150 } else {
151 size++;
152 }
153 head = node;
154 return node.val;
155 }
156 memoized.clear = function() {
157 head = null;
158 tail = null;
159 size = 0;
160 };
161 return memoized;
162 }
163
164 // packages/plugins/build-module/components/plugin-area/index.mjs
165 var import_element3 = __toESM(require_element(), 1);
166 var import_hooks2 = __toESM(require_hooks(), 1);
167 var import_is_shallow_equal = __toESM(require_is_shallow_equal(), 1);
168
169 // packages/plugins/build-module/components/plugin-context/index.mjs
170 var import_element = __toESM(require_element(), 1);
171 var import_compose = __toESM(require_compose(), 1);
172 var import_deprecated = __toESM(require_deprecated(), 1);
173 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
174 var Context = (0, import_element.createContext)({
175 name: null,
176 icon: null
177 });
178 Context.displayName = "PluginContext";
179 var PluginContextProvider = Context.Provider;
180 function usePluginContext() {
181 return (0, import_element.useContext)(Context);
182 }
183 var withPluginContext = (mapContextToProps) => (0, import_compose.createHigherOrderComponent)((OriginalComponent) => {
184 (0, import_deprecated.default)("wp.plugins.withPluginContext", {
185 since: "6.8.0",
186 alternative: "wp.plugins.usePluginContext"
187 });
188 return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Consumer, { children: (context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
189 OriginalComponent,
190 {
191 ...props,
192 ...mapContextToProps(context, props)
193 }
194 ) });
195 }, "withPluginContext");
196
197 // packages/plugins/build-module/components/plugin-error-boundary/index.mjs
198 var import_element2 = __toESM(require_element(), 1);
199 var PluginErrorBoundary = class extends import_element2.Component {
200 constructor(props) {
201 super(props);
202 this.state = {
203 hasError: false
204 };
205 }
206 static getDerivedStateFromError() {
207 return { hasError: true };
208 }
209 componentDidCatch(error) {
210 const { name, onError } = this.props;
211 if (onError) {
212 onError(name, error);
213 }
214 }
215 render() {
216 if (!this.state.hasError) {
217 return this.props.children;
218 }
219 return null;
220 }
221 };
222
223 // packages/plugins/build-module/api/index.mjs
224 var import_hooks = __toESM(require_hooks(), 1);
225
226 // packages/icons/build-module/library/plugins.mjs
227 var import_primitives = __toESM(require_primitives(), 1);
228 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
229 var plugins_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives.Path, { 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" }) });
230
231 // packages/plugins/build-module/api/index.mjs
232 var plugins = {};
233 function registerPlugin(name, settings) {
234 if (typeof settings !== "object") {
235 console.error("No settings object provided!");
236 return null;
237 }
238 if (typeof name !== "string") {
239 console.error("Plugin name must be string.");
240 return null;
241 }
242 if (!/^[a-z][a-z0-9-]*$/.test(name)) {
243 console.error(
244 'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".'
245 );
246 return null;
247 }
248 if (plugins[name]) {
249 console.error(`Plugin "${name}" is already registered.`);
250 }
251 settings = (0, import_hooks.applyFilters)(
252 "plugins.registerPlugin",
253 settings,
254 name
255 );
256 const { render, scope } = settings;
257 if (typeof render !== "function") {
258 console.error(
259 'The "render" property must be specified and must be a valid function.'
260 );
261 return null;
262 }
263 if (scope) {
264 if (typeof scope !== "string") {
265 console.error("Plugin scope must be string.");
266 return null;
267 }
268 if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
269 console.error(
270 'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".'
271 );
272 return null;
273 }
274 }
275 plugins[name] = {
276 name,
277 icon: plugins_default,
278 ...settings
279 };
280 (0, import_hooks.doAction)("plugins.pluginRegistered", settings, name);
281 return settings;
282 }
283 function unregisterPlugin(name) {
284 if (!plugins[name]) {
285 console.error('Plugin "' + name + '" is not registered.');
286 return;
287 }
288 const oldPlugin = plugins[name];
289 delete plugins[name];
290 (0, import_hooks.doAction)("plugins.pluginUnregistered", oldPlugin, name);
291 return oldPlugin;
292 }
293 function getPlugin(name) {
294 return plugins[name];
295 }
296 function getPlugins(scope) {
297 return Object.values(plugins).filter(
298 (plugin) => plugin.scope === scope
299 );
300 }
301
302 // packages/plugins/build-module/components/plugin-area/index.mjs
303 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
304 var getPluginContext = memize(
305 (icon, name) => ({
306 icon,
307 name
308 })
309 );
310 function PluginArea({
311 scope,
312 onError
313 }) {
314 const store = (0, import_element3.useMemo)(() => {
315 let lastValue = [];
316 return {
317 subscribe(listener) {
318 (0, import_hooks2.addAction)(
319 "plugins.pluginRegistered",
320 "core/plugins/plugin-area/plugins-registered",
321 listener
322 );
323 (0, import_hooks2.addAction)(
324 "plugins.pluginUnregistered",
325 "core/plugins/plugin-area/plugins-unregistered",
326 listener
327 );
328 return () => {
329 (0, import_hooks2.removeAction)(
330 "plugins.pluginRegistered",
331 "core/plugins/plugin-area/plugins-registered"
332 );
333 (0, import_hooks2.removeAction)(
334 "plugins.pluginUnregistered",
335 "core/plugins/plugin-area/plugins-unregistered"
336 );
337 };
338 },
339 getValue() {
340 const nextValue = getPlugins(scope);
341 if (!(0, import_is_shallow_equal.isShallowEqual)(lastValue, nextValue)) {
342 lastValue = nextValue;
343 }
344 return lastValue;
345 }
346 };
347 }, [scope]);
348 const plugins2 = (0, import_element3.useSyncExternalStore)(
349 store.subscribe,
350 store.getValue,
351 store.getValue
352 );
353 return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "none" }, children: plugins2.map(({ icon, name, render: Plugin }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
354 PluginContextProvider,
355 {
356 value: getPluginContext(icon, name),
357 children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PluginErrorBoundary, { name, onError, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Plugin, {}) })
358 },
359 name
360 )) });
361 }
362 var plugin_area_default = PluginArea;
363 return __toCommonJS(index_exports);
364 })();
365 //# sourceMappingURL=index.js.map
366