PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.0
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 / viewport / index.js

index.js in Gutenberg 22.9.0, at build/scripts/viewport/index.js

199 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var wp;
2 (wp ||= {}).viewport = (() => {
3 var __create = Object.create;
4 var __defProp = Object.defineProperty;
5 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6 var __getOwnPropNames = Object.getOwnPropertyNames;
7 var __getProtoOf = Object.getPrototypeOf;
8 var __hasOwnProp = Object.prototype.hasOwnProperty;
9 var __commonJS = (cb, mod) => function __require() {
10 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11 };
12 var __export = (target, all) => {
13 for (var name in all)
14 __defProp(target, name, { get: all[name], enumerable: true });
15 };
16 var __copyProps = (to, from, except, desc) => {
17 if (from && typeof from === "object" || typeof from === "function") {
18 for (let key of __getOwnPropNames(from))
19 if (!__hasOwnProp.call(to, key) && key !== except)
20 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21 }
22 return to;
23 };
24 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25 // If the importer is in node compatibility mode or this is not an ESM
26 // file that has been converted to a CommonJS file using a Babel-
27 // compatible transform (i.e. "__esModule" has not been set), then set
28 // "default" to the CommonJS "module.exports" for node compatibility.
29 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30 mod
31 ));
32 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
34 // package-external:@wordpress/compose
35 var require_compose = __commonJS({
36 "package-external:@wordpress/compose"(exports, module) {
37 module.exports = window.wp.compose;
38 }
39 });
40
41 // package-external:@wordpress/data
42 var require_data = __commonJS({
43 "package-external:@wordpress/data"(exports, module) {
44 module.exports = window.wp.data;
45 }
46 });
47
48 // vendor-external:react/jsx-runtime
49 var require_jsx_runtime = __commonJS({
50 "vendor-external:react/jsx-runtime"(exports, module) {
51 module.exports = window.ReactJSXRuntime;
52 }
53 });
54
55 // packages/viewport/build-module/index.mjs
56 var index_exports = {};
57 __export(index_exports, {
58 ifViewportMatches: () => if_viewport_matches_default,
59 store: () => store,
60 withViewportMatch: () => with_viewport_match_default
61 });
62
63 // packages/viewport/build-module/listener.mjs
64 var import_compose = __toESM(require_compose(), 1);
65 var import_data2 = __toESM(require_data(), 1);
66
67 // packages/viewport/build-module/store/index.mjs
68 var import_data = __toESM(require_data(), 1);
69
70 // packages/viewport/build-module/store/reducer.mjs
71 function reducer(state = {}, action) {
72 switch (action.type) {
73 case "SET_IS_MATCHING":
74 return action.values;
75 }
76 return state;
77 }
78 var reducer_default = reducer;
79
80 // packages/viewport/build-module/store/actions.mjs
81 var actions_exports = {};
82 __export(actions_exports, {
83 setIsMatching: () => setIsMatching
84 });
85 function setIsMatching(values) {
86 return {
87 type: "SET_IS_MATCHING",
88 values
89 };
90 }
91
92 // packages/viewport/build-module/store/selectors.mjs
93 var selectors_exports = {};
94 __export(selectors_exports, {
95 isViewportMatch: () => isViewportMatch
96 });
97 function isViewportMatch(state, query) {
98 if (query.indexOf(" ") === -1) {
99 query = ">= " + query;
100 }
101 return !!state[query];
102 }
103
104 // packages/viewport/build-module/store/index.mjs
105 var STORE_NAME = "core/viewport";
106 var store = (0, import_data.createReduxStore)(STORE_NAME, {
107 reducer: reducer_default,
108 actions: actions_exports,
109 selectors: selectors_exports
110 });
111 (0, import_data.register)(store);
112
113 // packages/viewport/build-module/listener.mjs
114 var addDimensionsEventListener = (breakpoints, operators) => {
115 const setIsMatching2 = (0, import_compose.debounce)(
116 () => {
117 const values = Object.fromEntries(
118 queries.map(([key, query]) => [key, query.matches])
119 );
120 (0, import_data2.dispatch)(store).setIsMatching(values);
121 },
122 0,
123 { leading: true }
124 );
125 const operatorEntries = Object.entries(operators);
126 const queries = Object.entries(breakpoints).flatMap(
127 ([name, width]) => {
128 return operatorEntries.map(([operator, condition]) => {
129 const list = window.matchMedia(
130 `(${condition}: ${width}px)`
131 );
132 list.addEventListener("change", setIsMatching2);
133 return [`${operator} ${name}`, list];
134 });
135 }
136 );
137 window.addEventListener("orientationchange", setIsMatching2);
138 setIsMatching2();
139 setIsMatching2.flush();
140 };
141 var listener_default = addDimensionsEventListener;
142
143 // packages/viewport/build-module/if-viewport-matches.mjs
144 var import_compose3 = __toESM(require_compose(), 1);
145
146 // packages/viewport/build-module/with-viewport-match.mjs
147 var import_compose2 = __toESM(require_compose(), 1);
148 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
149 var withViewportMatch = (queries) => {
150 const queryEntries = Object.entries(queries);
151 const useViewPortQueriesResult = () => Object.fromEntries(
152 queryEntries.map(([key, query]) => {
153 let [operator, breakpointName] = query.split(" ");
154 if (breakpointName === void 0) {
155 breakpointName = operator;
156 operator = ">=";
157 }
158 return [key, (0, import_compose2.useViewportMatch)(breakpointName, operator)];
159 })
160 );
161 return (0, import_compose2.createHigherOrderComponent)((WrappedComponent) => {
162 return (0, import_compose2.pure)((props) => {
163 const queriesResult = useViewPortQueriesResult();
164 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...props, ...queriesResult });
165 });
166 }, "withViewportMatch");
167 };
168 var with_viewport_match_default = withViewportMatch;
169
170 // packages/viewport/build-module/if-viewport-matches.mjs
171 var ifViewportMatches = (query) => (0, import_compose3.createHigherOrderComponent)(
172 (0, import_compose3.compose)([
173 with_viewport_match_default({
174 isViewportMatch: query
175 }),
176 (0, import_compose3.ifCondition)((props) => props.isViewportMatch)
177 ]),
178 "ifViewportMatches"
179 );
180 var if_viewport_matches_default = ifViewportMatches;
181
182 // packages/viewport/build-module/index.mjs
183 var BREAKPOINTS = {
184 huge: 1440,
185 wide: 1280,
186 large: 960,
187 medium: 782,
188 small: 600,
189 mobile: 480
190 };
191 var OPERATORS = {
192 "<": "max-width",
193 ">=": "min-width"
194 };
195 listener_default(BREAKPOINTS, OPERATORS);
196 return __toCommonJS(index_exports);
197 })();
198 //# sourceMappingURL=index.js.map
199