build/routes/template-list
content.js
720.3 KB
4 months ago
content.min.asset.php
605 B
4 months ago
content.min.js
301.1 KB
4 months ago
route.js
8.4 KB
5 months ago
route.min.asset.php
170 B
5 months ago
route.min.js
3.4 KB
5 months ago
route.js in Gutenberg 23.2.0, at build/routes/template-list/route.js
| 1 | var __create = Object.create; |
| 2 | var __defProp = Object.defineProperty; |
| 3 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 4 | var __getOwnPropNames = Object.getOwnPropertyNames; |
| 5 | var __getProtoOf = Object.getPrototypeOf; |
| 6 | var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 7 | var __commonJS = (cb, mod) => function __require() { |
| 8 | return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 9 | }; |
| 10 | var __copyProps = (to, from, except, desc) => { |
| 11 | if (from && typeof from === "object" || typeof from === "function") { |
| 12 | for (let key of __getOwnPropNames(from)) |
| 13 | if (!__hasOwnProp.call(to, key) && key !== except) |
| 14 | __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 15 | } |
| 16 | return to; |
| 17 | }; |
| 18 | var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 19 | // If the importer is in node compatibility mode or this is not an ESM |
| 20 | // file that has been converted to a CommonJS file using a Babel- |
| 21 | // compatible transform (i.e. "__esModule" has not been set), then set |
| 22 | // "default" to the CommonJS "module.exports" for node compatibility. |
| 23 | isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 24 | mod |
| 25 | )); |
| 26 | |
| 27 | // package-external:@wordpress/data |
| 28 | var require_data = __commonJS({ |
| 29 | "package-external:@wordpress/data"(exports, module) { |
| 30 | module.exports = window.wp.data; |
| 31 | } |
| 32 | }); |
| 33 | |
| 34 | // package-external:@wordpress/core-data |
| 35 | var require_core_data = __commonJS({ |
| 36 | "package-external:@wordpress/core-data"(exports, module) { |
| 37 | module.exports = window.wp.coreData; |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | // package-external:@wordpress/i18n |
| 42 | var require_i18n = __commonJS({ |
| 43 | "package-external:@wordpress/i18n"(exports, module) { |
| 44 | module.exports = window.wp.i18n; |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | // package-external:@wordpress/element |
| 49 | var require_element = __commonJS({ |
| 50 | "package-external:@wordpress/element"(exports, module) { |
| 51 | module.exports = window.wp.element; |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | // package-external:@wordpress/preferences |
| 56 | var require_preferences = __commonJS({ |
| 57 | "package-external:@wordpress/preferences"(exports, module) { |
| 58 | module.exports = window.wp.preferences; |
| 59 | } |
| 60 | }); |
| 61 | |
| 62 | // package-external:@wordpress/private-apis |
| 63 | var require_private_apis = __commonJS({ |
| 64 | "package-external:@wordpress/private-apis"(exports, module) { |
| 65 | module.exports = window.wp.privateApis; |
| 66 | } |
| 67 | }); |
| 68 | |
| 69 | // routes/template-list/route.ts |
| 70 | var import_data4 = __toESM(require_data()); |
| 71 | var import_core_data2 = __toESM(require_core_data()); |
| 72 | var import_i18n = __toESM(require_i18n()); |
| 73 | |
| 74 | // packages/views/build-module/use-view.mjs |
| 75 | var import_element = __toESM(require_element(), 1); |
| 76 | var import_data = __toESM(require_data(), 1); |
| 77 | var import_preferences = __toESM(require_preferences(), 1); |
| 78 | |
| 79 | // packages/views/build-module/preference-keys.mjs |
| 80 | function generatePreferenceKey(kind, name, slug) { |
| 81 | return `dataviews-${kind}-${name}-${slug}`; |
| 82 | } |
| 83 | |
| 84 | // packages/views/build-module/filter-utils.mjs |
| 85 | var SCALAR_VALUES = [ |
| 86 | "titleField", |
| 87 | "mediaField", |
| 88 | "descriptionField", |
| 89 | "showTitle", |
| 90 | "showMedia", |
| 91 | "showDescription", |
| 92 | "showLevels", |
| 93 | "infiniteScrollEnabled" |
| 94 | ]; |
| 95 | function mergeActiveViewOverrides(view, activeViewOverrides, defaultView) { |
| 96 | if (!activeViewOverrides) { |
| 97 | return view; |
| 98 | } |
| 99 | let result = view; |
| 100 | for (const key of SCALAR_VALUES) { |
| 101 | if (key in activeViewOverrides) { |
| 102 | result = { ...result, [key]: activeViewOverrides[key] }; |
| 103 | } |
| 104 | } |
| 105 | if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) { |
| 106 | const activeFields = new Set( |
| 107 | activeViewOverrides.filters.map((f) => f.field) |
| 108 | ); |
| 109 | const preserved = (view.filters ?? []).filter( |
| 110 | (f) => !activeFields.has(f.field) |
| 111 | ); |
| 112 | result = { |
| 113 | ...result, |
| 114 | filters: [...preserved, ...activeViewOverrides.filters] |
| 115 | }; |
| 116 | } |
| 117 | if (activeViewOverrides.sort) { |
| 118 | const isDefaultSort = defaultView && view.sort?.field === defaultView.sort?.field && view.sort?.direction === defaultView.sort?.direction; |
| 119 | if (isDefaultSort) { |
| 120 | result = { |
| 121 | ...result, |
| 122 | sort: activeViewOverrides.sort |
| 123 | }; |
| 124 | } |
| 125 | } |
| 126 | if (activeViewOverrides.layout) { |
| 127 | result = { |
| 128 | ...result, |
| 129 | layout: { |
| 130 | ...result.layout, |
| 131 | ...activeViewOverrides.layout |
| 132 | } |
| 133 | }; |
| 134 | } |
| 135 | if (activeViewOverrides.groupBy) { |
| 136 | result = { |
| 137 | ...result, |
| 138 | groupBy: activeViewOverrides.groupBy |
| 139 | }; |
| 140 | } |
| 141 | return result; |
| 142 | } |
| 143 | |
| 144 | // packages/views/build-module/load-view.mjs |
| 145 | var import_data2 = __toESM(require_data(), 1); |
| 146 | var import_preferences2 = __toESM(require_preferences(), 1); |
| 147 | async function loadView(config) { |
| 148 | const { kind, name, slug, defaultView, activeViewOverrides, queryParams } = config; |
| 149 | const preferenceKey = generatePreferenceKey(kind, name, slug); |
| 150 | const persistedView = (0, import_data2.select)(import_preferences2.store).get( |
| 151 | "core/views", |
| 152 | preferenceKey |
| 153 | ); |
| 154 | const baseView = persistedView ?? defaultView; |
| 155 | const page = queryParams?.page ?? 1; |
| 156 | const search = queryParams?.search ?? ""; |
| 157 | const rawDefaults = config.defaultLayouts?.[baseView?.type]; |
| 158 | const layoutTypeDefaults = !rawDefaults || rawDefaults === true ? {} : rawDefaults; |
| 159 | const combinedOverrides = { ...layoutTypeDefaults, ...activeViewOverrides }; |
| 160 | return mergeActiveViewOverrides( |
| 161 | { |
| 162 | ...baseView, |
| 163 | page, |
| 164 | search |
| 165 | }, |
| 166 | combinedOverrides, |
| 167 | defaultView |
| 168 | ); |
| 169 | } |
| 170 | |
| 171 | // packages/views/build-module/use-view-config.mjs |
| 172 | var import_data3 = __toESM(require_data(), 1); |
| 173 | var import_core_data = __toESM(require_core_data(), 1); |
| 174 | |
| 175 | // packages/views/build-module/lock-unlock.mjs |
| 176 | var import_private_apis = __toESM(require_private_apis(), 1); |
| 177 | var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)( |
| 178 | "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", |
| 179 | "@wordpress/views" |
| 180 | ); |
| 181 | |
| 182 | // routes/template-list/view-utils.ts |
| 183 | var DEFAULT_VIEW = { |
| 184 | type: "grid", |
| 185 | perPage: 20, |
| 186 | sort: { |
| 187 | field: "title", |
| 188 | direction: "asc" |
| 189 | }, |
| 190 | fields: ["author", "active", "slug"], |
| 191 | titleField: "title", |
| 192 | descriptionField: "description", |
| 193 | mediaField: "preview", |
| 194 | filters: [] |
| 195 | }; |
| 196 | var DEFAULT_VIEW_LEGACY = { |
| 197 | ...DEFAULT_VIEW, |
| 198 | fields: ["author"] |
| 199 | }; |
| 200 | function getActiveViewOverridesForTab(activeView) { |
| 201 | if (activeView === "user") { |
| 202 | return { |
| 203 | sort: { field: "date", direction: "desc" } |
| 204 | }; |
| 205 | } |
| 206 | if (activeView === "active") { |
| 207 | return {}; |
| 208 | } |
| 209 | return { |
| 210 | filters: [ |
| 211 | { |
| 212 | field: "author", |
| 213 | operator: "isAny", |
| 214 | value: [activeView] |
| 215 | } |
| 216 | ] |
| 217 | }; |
| 218 | } |
| 219 | async function ensureView(activeView, search) { |
| 220 | return loadView({ |
| 221 | kind: "postType", |
| 222 | name: "wp_template", |
| 223 | slug: "default-new", |
| 224 | defaultView: DEFAULT_VIEW, |
| 225 | activeViewOverrides: getActiveViewOverridesForTab( |
| 226 | activeView ?? "active" |
| 227 | ), |
| 228 | queryParams: search |
| 229 | }); |
| 230 | } |
| 231 | function viewToQuery(view) { |
| 232 | const result = {}; |
| 233 | if (void 0 !== view.perPage) { |
| 234 | result.per_page = view.perPage; |
| 235 | } |
| 236 | if (void 0 !== view.page) { |
| 237 | result.page = view.page; |
| 238 | } |
| 239 | if (![void 0, ""].includes(view.search)) { |
| 240 | result.search = view.search; |
| 241 | } |
| 242 | if (void 0 !== view.sort?.field) { |
| 243 | result.orderby = view.sort.field; |
| 244 | } |
| 245 | if (void 0 !== view.sort?.direction) { |
| 246 | result.order = view.sort.direction; |
| 247 | } |
| 248 | return result; |
| 249 | } |
| 250 | |
| 251 | // routes/template-list/route.ts |
| 252 | var route = { |
| 253 | title: () => (0, import_i18n.__)("Templates"), |
| 254 | async canvas(context) { |
| 255 | const { params, search } = context; |
| 256 | const view = await ensureView(params.activeView, { |
| 257 | page: search.page, |
| 258 | search: search.search |
| 259 | }); |
| 260 | if (view.type !== "list") { |
| 261 | return void 0; |
| 262 | } |
| 263 | if (search.postIds && search.postIds.length > 0) { |
| 264 | const postId = search.postIds[0].toString(); |
| 265 | return { |
| 266 | postType: "wp_template", |
| 267 | postId, |
| 268 | isPreview: true, |
| 269 | editLink: `/types/wp_template/edit/${encodeURIComponent( |
| 270 | postId |
| 271 | )}` |
| 272 | }; |
| 273 | } |
| 274 | const query = viewToQuery(view); |
| 275 | const posts = await (0, import_data4.resolveSelect)(import_core_data2.store).getEntityRecords( |
| 276 | "postType", |
| 277 | "wp_template", |
| 278 | { ...query, per_page: 1 } |
| 279 | ); |
| 280 | if (posts && posts.length > 0) { |
| 281 | const postId = posts[0].id.toString(); |
| 282 | return { |
| 283 | postType: "wp_template", |
| 284 | postId, |
| 285 | isPreview: true, |
| 286 | editLink: `/types/wp_template/edit/${encodeURIComponent( |
| 287 | postId |
| 288 | )}` |
| 289 | }; |
| 290 | } |
| 291 | return void 0; |
| 292 | } |
| 293 | }; |
| 294 | export { |
| 295 | route |
| 296 | }; |
| 297 |