PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.2.2
Presto Player v2.2.2
4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / blocks / blocks.js
presto-player / src / admin / blocks Last commit date
blocks 2 years ago plugins 2 years ago shared 2 years ago store 2 years ago blocks.js 5 years ago util.js 4 years ago
blocks.js
151 lines
1 /**
2 * Dynamically locate, load & register all Editor Blocks & Plugins.
3 */
4 const { registerBlockType, unregisterBlockType } = wp.blocks;
5 const { registerPlugin, unregisterPlugin } = wp.plugins;
6 const { select, dispatch } = wp.data;
7 const { render } = wp.element;
8
9 import store from "./store/player";
10
11 import "@/admin/blocks/shared/styles/gutenberg/index.scss";
12 import ProUpgradeModal from "./shared/ProUpgradeModal";
13
14 /**
15 * No-op function for use as a default argument value.
16 *
17 * @returns null
18 */
19 const noop = () => null;
20
21 /**
22 * Require a set of modules and configure them for hot module replacement.
23 *
24 * The first argument should be a function returning a `require.context()`
25 * call. All modules loaded from this context are cached, and on each rebuild
26 * the incoming updated modules are checked against the cache. Updated modules
27 * which already exist in the cache are unregistered with the provided function,
28 * then any incoming (new or updated) modules will be registered.
29 *
30 * @param {Function} getContext Execute and return a `require.context()` call.
31 * @param {Function} register Function to register accepted modules.
32 * @param {Function} unregister Function to unregister replaced modules.
33 * @param {Function} [before] Function to run before updating moules.
34 * @param {Function} [after] Function to run after updating moules.
35 */
36 const autoload = ({
37 getContext,
38 register,
39 unregister,
40 before = noop,
41 after = noop,
42 }) => {
43 const cache = {};
44 const loadModules = () => {
45 before();
46
47 const context = getContext();
48 const changedNames = [];
49 context.keys().forEach((key) => {
50 const module = context(key);
51 if (module === cache[key]) {
52 // Module unchanged: no further action needed.
53 return;
54 }
55 if (cache[key]) {
56 // Module changed, and prior copy detected: unregister old module.
57 unregister(cache[key]);
58 }
59 // Register new module and update cache.
60 register(module);
61 changedNames.push(module.name);
62 cache[key] = module;
63 });
64
65 after(changedNames);
66
67 // Return the context for HMR initialization.
68 return context;
69 };
70
71 const context = loadModules();
72
73 if (module.hot) {
74 module.hot.accept(context.id, loadModules);
75 }
76 };
77
78 // Maintain the selected block ID across HMR updates.
79 let selectedBlockId = null;
80 const storeSelectedBlock = () => {
81 selectedBlockId = select("core/editor").getSelectedBlockClientId();
82 dispatch("core/editor").clearSelectedBlock();
83 };
84 const refreshAllBlocks = (changedNames = []) => {
85 // Refresh all blocks by iteratively selecting each one.
86 select("core/editor")
87 .getBlocks()
88 .forEach(({ name, clientId }) => {
89 if (changedNames.includes(name)) {
90 dispatch("core/editor").selectBlock(clientId);
91 }
92 });
93 // Reselect whatever was selected in the beginning.
94 if (selectedBlockId) {
95 dispatch("core/editor").selectBlock(selectedBlockId);
96 } else {
97 dispatch("core/editor").clearSelectedBlock();
98 }
99 selectedBlockId = null;
100 };
101
102 // Load all block index files.
103 autoload({
104 getContext: () => require.context("./blocks", true, /index\.js$/),
105 register: ({ name, options }) => {
106 if (prestoPlayer?.isPremium) {
107 registerBlockType(name, options);
108 } else if (!options.premium) {
109 registerBlockType(name, options);
110 }
111 },
112 unregister: ({ name }) => unregisterBlockType(name),
113 before: storeSelectedBlock,
114 after: refreshAllBlocks,
115 });
116
117 // Load all plugin files.
118 autoload({
119 getContext: () => require.context("./plugins", true, /index\.js$/),
120 register: ({ name, options }) => registerPlugin(name, options),
121 unregister: ({ name }) => unregisterPlugin(name),
122 });
123
124 jQuery("body").append('<div id="presto-plugin-app"></div>');
125 render(<ProUpgradeModal />, document.getElementById("presto-plugin-app"));
126
127 // fetch settings
128 dispatch("presto-player/player").fetchOptions();
129
130 let saving = false;
131 // save the settings on post save, just in case they miss the button
132 wp.data.subscribe(function () {
133 var isSavingPost = wp.data.select("core/editor").isSavingPost();
134 var isAutosavingPost = wp.data.select("core/editor").isAutosavingPost();
135
136 if (isSavingPost && !isAutosavingPost) {
137 if (saving) {
138 return;
139 }
140 saving = true;
141 let { brandingReducer } = store.getState();
142 dispatch("presto-player/player")
143 .saveOptions({
144 branding: brandingReducer,
145 })
146 .then(() => {
147 saving = false;
148 });
149 }
150 });
151