PluginProbe ʕ •ᴥ•ʔ
Presto Player / trunk
Presto Player vtrunk
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 3 days ago hooks 9 months ago plugins 9 months ago scripts 9 months ago shared 3 days ago store 2 years ago blocks.js 3 days ago util.js 1 year ago
blocks.js
146 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 import "./hooks/apply-popup-preview-toggle";
14 import "./hooks/apply-popup-image-trigger-placeholder";
15 import "./hooks/apply-popup-button-trigger-ui";
16
17 /**
18 * No-op function for use as a default argument value.
19 *
20 * @returns null
21 */
22 const noop = () => null;
23
24 /**
25 * Require a set of modules and configure them for hot module replacement.
26 *
27 * The first argument should be a function returning a `require.context()`
28 * call. All modules loaded from this context are cached, and on each rebuild
29 * the incoming updated modules are checked against the cache. Updated modules
30 * which already exist in the cache are unregistered with the provided function,
31 * then any incoming (new or updated) modules will be registered.
32 *
33 * @param {Function} getContext Execute and return a `require.context()` call.
34 * @param {Function} register Function to register accepted modules.
35 * @param {Function} unregister Function to unregister replaced modules.
36 * @param {Function} [before] Function to run before updating moules.
37 * @param {Function} [after] Function to run after updating moules.
38 */
39 const autoload = ({
40 getContext,
41 register,
42 unregister,
43 before = noop,
44 after = noop,
45 }) => {
46 const cache = {};
47 const loadModules = () => {
48 before();
49
50 const context = getContext();
51 const changedNames = [];
52 context.keys().forEach((key) => {
53 const module = context(key);
54 if (module === cache[key]) {
55 // Module unchanged: no further action needed.
56 return;
57 }
58 if (cache[key]) {
59 // Module changed, and prior copy detected: unregister old module.
60 unregister(cache[key]);
61 }
62 // Register new module and update cache.
63 register(module);
64 changedNames.push(module.name);
65 cache[key] = module;
66 });
67
68 after(changedNames);
69
70 // Return the context for HMR initialization.
71 return context;
72 };
73
74 const context = loadModules();
75
76 if (module.hot) {
77 module.hot.accept(context.id, loadModules);
78 }
79 };
80
81 // Maintain the selected block ID across HMR updates.
82 let selectedBlockId = null;
83 const storeSelectedBlock = () => {
84 selectedBlockId = select("core/editor").getSelectedBlockClientId();
85 dispatch("core/editor").clearSelectedBlock();
86 };
87 const refreshAllBlocks = (changedNames = []) => {
88 // Refresh all blocks by iteratively selecting each one.
89 select("core/editor")
90 .getBlocks()
91 .forEach(({ name, clientId }) => {
92 if (changedNames.includes(name)) {
93 dispatch("core/editor").selectBlock(clientId);
94 }
95 });
96 // Reselect whatever was selected in the beginning.
97 if (selectedBlockId) {
98 dispatch("core/editor").selectBlock(selectedBlockId);
99 } else {
100 dispatch("core/editor").clearSelectedBlock();
101 }
102 selectedBlockId = null;
103 };
104
105 // Load all block index files.
106 autoload({
107 getContext: () => require.context("./blocks", true, /index\.js$/),
108 register: ({ name, metadata, options }) => {
109 const blockId = metadata ? { name, ...metadata } : name;
110 if (prestoPlayer?.isPremium) {
111 registerBlockType(blockId, options);
112 } else if (!options.premium) {
113 registerBlockType(blockId, options);
114 }
115 },
116 unregister: ({ name }) => unregisterBlockType(name),
117 before: storeSelectedBlock,
118 after: refreshAllBlocks,
119 });
120
121 // Load all plugin files.
122 autoload({
123 getContext: () => require.context("./plugins", true, /index\.js$/),
124 register: ({ name, options }) => registerPlugin(name, options),
125 unregister: ({ name }) => unregisterPlugin(name),
126 });
127
128 jQuery("body").append('<div id="presto-plugin-app"></div>');
129 render(<ProUpgradeModal />, document.getElementById("presto-plugin-app"));
130
131 // fetch settings
132 dispatch("presto-player/player").fetchOptions();
133
134 // Manage the is-editing-pp-video-block class for styling/functionality
135 wp.data.subscribe(function () {
136 const settings = wp.data.select("core/editor").getEditorSettings();
137 if (
138 !!settings?.onNavigateToPreviousEntityRecord &&
139 wp.data.select("core/editor").getCurrentPostType() === "pp_video_block"
140 ) {
141 document.body.classList.add("is-editing-pp-video-block");
142 } else {
143 document.body.classList.remove("is-editing-pp-video-block");
144 }
145 });
146