| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 (function() { 2 "use strict"; 3 var wp; 4 (wp ||= {}).router = (() => { 5 var __create = Object.create; 6 var __defProp = Object.defineProperty; 7 var __getOwnPropDesc = Object.getOwnPropertyDescriptor; 8 var __getOwnPropNames = Object.getOwnPropertyNames; 9 var __getProtoOf = Object.getPrototypeOf; 10 var __hasOwnProp = Object.prototype.hasOwnProperty; 11 var __commonJS = (cb, mod) => function __require() { 12 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; 13 }; 14 var __export = (target, all) => { 15 for (var name in all) 16 __defProp(target, name, { get: all[name], enumerable: true }); 17 }; 18 var __copyProps = (to2, from, except, desc) => { 19 if (from && typeof from === "object" || typeof from === "function") { 20 for (let key of __getOwnPropNames(from)) 21 if (!__hasOwnProp.call(to2, key) && key !== except) 22 __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); 23 } 24 return to2; 25 }; 26 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( 27 // If the importer is in node compatibility mode or this is not an ESM 28 // file that has been converted to a CommonJS file using a Babel- 29 // compatible transform (i.e. "__esModule" has not been set), then set 30 // "default" to the CommonJS "module.exports" for node compatibility. 31 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, 32 mod 33 )); 34 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); 35 36 // package-external:@wordpress/element 37 var require_element = __commonJS({ 38 "package-external:@wordpress/element"(exports, module) { 39 module.exports = window.wp.element; 40 } 41 }); 42 43 // package-external:@wordpress/url 44 var require_url = __commonJS({ 45 "package-external:@wordpress/url"(exports, module) { 46 module.exports = window.wp.url; 47 } 48 }); 49 50 // package-external:@wordpress/compose 51 var require_compose = __commonJS({ 52 "package-external:@wordpress/compose"(exports, module) { 53 module.exports = window.wp.compose; 54 } 55 }); 56 57 // vendor-external:react/jsx-runtime 58 var require_jsx_runtime = __commonJS({ 59 "vendor-external:react/jsx-runtime"(exports, module) { 60 module.exports = window.ReactJSXRuntime; 61 } 62 }); 63 64 // package-external:@wordpress/private-apis 65 var require_private_apis = __commonJS({ 66 "package-external:@wordpress/private-apis"(exports, module) { 67 module.exports = window.wp.privateApis; 68 } 69 }); 70 71 // packages/router/build-module/index.mjs 72 var index_exports = {}; 73 __export(index_exports, { 74 privateApis: () => privateApis 75 }); 76 77 // node_modules/route-recognizer/dist/route-recognizer.es.js 78 var createObject = Object.create; 79 function createMap() { 80 var map2 = createObject(null); 81 map2["__"] = void 0; 82 delete map2["__"]; 83 return map2; 84 } 85 var Target = function Target2(path, matcher, delegate) { 86 this.path = path; 87 this.matcher = matcher; 88 this.delegate = delegate; 89 }; 90 Target.prototype.to = function to(target, callback) { 91 var delegate = this.delegate; 92 if (delegate && delegate.willAddRoute) { 93 target = delegate.willAddRoute(this.matcher.target, target); 94 } 95 this.matcher.add(this.path, target); 96 if (callback) { 97 if (callback.length === 0) { 98 throw new Error("You must have an argument in the function passed to `to`"); 99 } 100 this.matcher.addChild(this.path, target, callback, this.delegate); 101 } 102 }; 103 var Matcher = function Matcher2(target) { 104 this.routes = createMap(); 105 this.children = createMap(); 106 this.target = target; 107 }; 108 Matcher.prototype.add = function add(path, target) { 109 this.routes[path] = target; 110 }; 111 Matcher.prototype.addChild = function addChild(path, target, callback, delegate) { 112 var matcher = new Matcher(target); 113 this.children[path] = matcher; 114 var match2 = generateMatch(path, matcher, delegate); 115 if (delegate && delegate.contextEntered) { 116 delegate.contextEntered(target, match2); 117 } 118 callback(match2); 119 }; 120 function generateMatch(startingPath, matcher, delegate) { 121 function match2(path, callback) { 122 var fullPath = startingPath + path; 123 if (callback) { 124 callback(generateMatch(fullPath, matcher, delegate)); 125 } else { 126 return new Target(fullPath, matcher, delegate); 127 } 128 } 129 return match2; 130 } 131 function addRoute(routeArray, path, handler) { 132 var len = 0; 133 for (var i = 0; i < routeArray.length; i++) { 134 len += routeArray[i].path.length; 135 } 136 path = path.substr(len); 137 var route = { path, handler }; 138 routeArray.push(route); 139 } 140 function eachRoute(baseRoute, matcher, callback, binding) { 141 var routes = matcher.routes; 142 var paths = Object.keys(routes); 143 for (var i = 0; i < paths.length; i++) { 144 var path = paths[i]; 145 var routeArray = baseRoute.slice(); 146 addRoute(routeArray, path, routes[path]); 147 var nested = matcher.children[path]; 148 if (nested) { 149 eachRoute(routeArray, nested, callback, binding); 150 } else { 151 callback.call(binding, routeArray); 152 } 153 } 154 } 155 var map = function(callback, addRouteCallback) { 156 var matcher = new Matcher(); 157 callback(generateMatch("", matcher, this.delegate)); 158 eachRoute([], matcher, function(routes) { 159 if (addRouteCallback) { 160 addRouteCallback(this, routes); 161 } else { 162 this.add(routes); 163 } 164 }, this); 165 }; 166 function normalizePath(path) { 167 return path.split("/").map(normalizeSegment).join("/"); 168 } 169 var SEGMENT_RESERVED_CHARS = /%|\//g; 170 function normalizeSegment(segment) { 171 if (segment.length < 3 || segment.indexOf("%") === -1) { 172 return segment; 173 } 174 return decodeURIComponent(segment).replace(SEGMENT_RESERVED_CHARS, encodeURIComponent); 175 } 176 var PATH_SEGMENT_ENCODINGS = /%(?:2(?:4|6|B|C)|3(?:B|D|A)|40)/g; 177 function encodePathSegment(str) { 178 return encodeURIComponent(str).replace(PATH_SEGMENT_ENCODINGS, decodeURIComponent); 179 } 180 var escapeRegex = /(\/|\.|\*|\+|\?|\||\(|\)|\[|\]|\{|\}|\\)/g; 181 var isArray = Array.isArray; 182 var hasOwnProperty = Object.prototype.hasOwnProperty; 183 function getParam(params, key) { 184 if (typeof params !== "object" || params === null) { 185 throw new Error("You must pass an object as the second argument to `generate`."); 186 } 187 if (!hasOwnProperty.call(params, key)) { 188 throw new Error("You must provide param `" + key + "` to `generate`."); 189 } 190 var value = params[key]; 191 var str = typeof value === "string" ? value : "" + value; 192 if (str.length === 0) { 193 throw new Error("You must provide a param `" + key + "`."); 194 } 195 return str; 196 } 197 var eachChar = []; 198 eachChar[ 199 0 200 /* Static */ 201 ] = function(segment, currentState) { 202 var state = currentState; 203 var value = segment.value; 204 for (var i = 0; i < value.length; i++) { 205 var ch = value.charCodeAt(i); 206 state = state.put(ch, false, false); 207 } 208 return state; 209 }; 210 eachChar[ 211 1 212 /* Dynamic */ 213 ] = function(_, currentState) { 214 return currentState.put(47, true, true); 215 }; 216 eachChar[ 217 2 218 /* Star */ 219 ] = function(_, currentState) { 220 return currentState.put(-1, false, true); 221 }; 222 eachChar[ 223 4 224 /* Epsilon */ 225 ] = function(_, currentState) { 226 return currentState; 227 }; 228 var regex = []; 229 regex[ 230 0 231 /* Static */ 232 ] = function(segment) { 233 return segment.value.replace(escapeRegex, "\\$1"); 234 }; 235 regex[ 236 1 237 /* Dynamic */ 238 ] = function() { 239 return "([^/]+)"; 240 }; 241 regex[ 242 2 243 /* Star */ 244 ] = function() { 245 return "(.+)"; 246 }; 247 regex[ 248 4 249 /* Epsilon */ 250 ] = function() { 251 return ""; 252 }; 253 var generate = []; 254 generate[ 255 0 256 /* Static */ 257 ] = function(segment) { 258 return segment.value; 259 }; 260 generate[ 261 1 262 /* Dynamic */ 263 ] = function(segment, params) { 264 var value = getParam(params, segment.value); 265 if (RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS) { 266 return encodePathSegment(value); 267 } else { 268 return value; 269 } 270 }; 271 generate[ 272 2 273 /* Star */ 274 ] = function(segment, params) { 275 return getParam(params, segment.value); 276 }; 277 generate[ 278 4 279 /* Epsilon */ 280 ] = function() { 281 return ""; 282 }; 283 var EmptyObject = Object.freeze({}); 284 var EmptyArray = Object.freeze([]); 285 function parse(segments, route, types) { 286 if (route.length > 0 && route.charCodeAt(0) === 47) { 287 route = route.substr(1); 288 } 289 var parts = route.split("/"); 290 var names = void 0; 291 var shouldDecodes = void 0; 292 for (var i = 0; i < parts.length; i++) { 293 var part = parts[i]; 294 var flags = 0; 295 var type = 0; 296 if (part === "") { 297 type = 4; 298 } else if (part.charCodeAt(0) === 58) { 299 type = 1; 300 } else if (part.charCodeAt(0) === 42) { 301 type = 2; 302 } else { 303 type = 0; 304 } 305 flags = 2 << type; 306 if (flags & 12) { 307 part = part.slice(1); 308 names = names || []; 309 names.push(part); 310 shouldDecodes = shouldDecodes || []; 311 shouldDecodes.push((flags & 4) !== 0); 312 } 313 if (flags & 14) { 314 types[type]++; 315 } 316 segments.push({ 317 type, 318 value: normalizeSegment(part) 319 }); 320 } 321 return { 322 names: names || EmptyArray, 323 shouldDecodes: shouldDecodes || EmptyArray 324 }; 325 } 326 function isEqualCharSpec(spec, char, negate) { 327 return spec.char === char && spec.negate === negate; 328 } 329 var State = function State2(states, id, char, negate, repeat) { 330 this.states = states; 331 this.id = id; 332 this.char = char; 333 this.negate = negate; 334 this.nextStates = repeat ? id : null; 335 this.pattern = ""; 336 this._regex = void 0; 337 this.handlers = void 0; 338 this.types = void 0; 339 }; 340 State.prototype.regex = function regex$1() { 341 if (!this._regex) { 342 this._regex = new RegExp(this.pattern); 343 } 344 return this._regex; 345 }; 346 State.prototype.get = function get(char, negate) { 347 var this$1 = this; 348 var nextStates = this.nextStates; 349 if (nextStates === null) { 350 return; 351 } 352 if (isArray(nextStates)) { 353 for (var i = 0; i < nextStates.length; i++) { 354 var child = this$1.states[nextStates[i]]; 355 if (isEqualCharSpec(child, char, negate)) { 356 return child; 357 } 358 } 359 } else { 360 var child$1 = this.states[nextStates]; 361 if (isEqualCharSpec(child$1, char, negate)) { 362 return child$1; 363 } 364 } 365 }; 366 State.prototype.put = function put(char, negate, repeat) { 367 var state; 368 if (state = this.get(char, negate)) { 369 return state; 370 } 371 var states = this.states; 372 state = new State(states, states.length, char, negate, repeat); 373 states[states.length] = state; 374 if (this.nextStates == null) { 375 this.nextStates = state.id; 376 } else if (isArray(this.nextStates)) { 377 this.nextStates.push(state.id); 378 } else { 379 this.nextStates = [this.nextStates, state.id]; 380 } 381 return state; 382 }; 383 State.prototype.match = function match(ch) { 384 var this$1 = this; 385 var nextStates = this.nextStates; 386 if (!nextStates) { 387 return []; 388 } 389 var returned = []; 390 if (isArray(nextStates)) { 391 for (var i = 0; i < nextStates.length; i++) { 392 var child = this$1.states[nextStates[i]]; 393 if (isMatch(child, ch)) { 394 returned.push(child); 395 } 396 } 397 } else { 398 var child$1 = this.states[nextStates]; 399 if (isMatch(child$1, ch)) { 400 returned.push(child$1); 401 } 402 } 403 return returned; 404 }; 405 function isMatch(spec, char) { 406 return spec.negate ? spec.char !== char && spec.char !== -1 : spec.char === char || spec.char === -1; 407 } 408 function sortSolutions(states) { 409 return states.sort(function(a, b) { 410 var ref = a.types || [0, 0, 0]; 411 var astatics = ref[0]; 412 var adynamics = ref[1]; 413 var astars = ref[2]; 414 var ref$1 = b.types || [0, 0, 0]; 415 var bstatics = ref$1[0]; 416 var bdynamics = ref$1[1]; 417 var bstars = ref$1[2]; 418 if (astars !== bstars) { 419 return astars - bstars; 420 } 421 if (astars) { 422 if (astatics !== bstatics) { 423 return bstatics - astatics; 424 } 425 if (adynamics !== bdynamics) { 426 return bdynamics - adynamics; 427 } 428 } 429 if (adynamics !== bdynamics) { 430 return adynamics - bdynamics; 431 } 432 if (astatics !== bstatics) { 433 return bstatics - astatics; 434 } 435 return 0; 436 }); 437 } 438 function recognizeChar(states, ch) { 439 var nextStates = []; 440 for (var i = 0, l = states.length; i < l; i++) { 441 var state = states[i]; 442 nextStates = nextStates.concat(state.match(ch)); 443 } 444 return nextStates; 445 } 446 var RecognizeResults = function RecognizeResults2(queryParams) { 447 this.length = 0; 448 this.queryParams = queryParams || {}; 449 }; 450 RecognizeResults.prototype.splice = Array.prototype.splice; 451 RecognizeResults.prototype.slice = Array.prototype.slice; 452 RecognizeResults.prototype.push = Array.prototype.push; 453 function findHandler(state, originalPath, queryParams) { 454 var handlers = state.handlers; 455 var regex2 = state.regex(); 456 if (!regex2 || !handlers) { 457 throw new Error("state not initialized"); 458 } 459 var captures = originalPath.match(regex2); 460 var currentCapture = 1; 461 var result = new RecognizeResults(queryParams); 462 result.length = handlers.length; 463 for (var i = 0; i < handlers.length; i++) { 464 var handler = handlers[i]; 465 var names = handler.names; 466 var shouldDecodes = handler.shouldDecodes; 467 var params = EmptyObject; 468 var isDynamic = false; 469 if (names !== EmptyArray && shouldDecodes !== EmptyArray) { 470 for (var j = 0; j < names.length; j++) { 471 isDynamic = true; 472 var name = names[j]; 473 var capture = captures && captures[currentCapture++]; 474 if (params === EmptyObject) { 475 params = {}; 476 } 477 if (RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS && shouldDecodes[j]) { 478 params[name] = capture && decodeURIComponent(capture); 479 } else { 480 params[name] = capture; 481 } 482 } 483 } 484 result[i] = { 485 handler: handler.handler, 486 params, 487 isDynamic 488 }; 489 } 490 return result; 491 } 492 function decodeQueryParamPart(part) { 493 part = part.replace(/\+/gm, "%20"); 494 var result; 495 try { 496 result = decodeURIComponent(part); 497 } catch (error) { 498 result = ""; 499 } 500 return result; 501 } 502 var RouteRecognizer = function RouteRecognizer2() { 503 this.names = createMap(); 504 var states = []; 505 var state = new State(states, 0, -1, true, false); 506 states[0] = state; 507 this.states = states; 508 this.rootState = state; 509 }; 510 RouteRecognizer.prototype.add = function add2(routes, options) { 511 var currentState = this.rootState; 512 var pattern = "^"; 513 var types = [0, 0, 0]; 514 var handlers = new Array(routes.length); 515 var allSegments = []; 516 var isEmpty = true; 517 var j = 0; 518 for (var i = 0; i < routes.length; i++) { 519 var route = routes[i]; 520 var ref = parse(allSegments, route.path, types); 521 var names = ref.names; 522 var shouldDecodes = ref.shouldDecodes; 523 for (; j < allSegments.length; j++) { 524 var segment = allSegments[j]; 525 if (segment.type === 4) { 526 continue; 527 } 528 isEmpty = false; 529 currentState = currentState.put(47, false, false); 530 pattern += "/"; 531 currentState = eachChar[segment.type](segment, currentState); 532 pattern += regex[segment.type](segment); 533 } 534 handlers[i] = { 535 handler: route.handler, 536 names, 537 shouldDecodes 538 }; 539 } 540 if (isEmpty) { 541 currentState = currentState.put(47, false, false); 542 pattern += "/"; 543 } 544 currentState.handlers = handlers; 545 currentState.pattern = pattern + "$"; 546 currentState.types = types; 547 var name; 548 if (typeof options === "object" && options !== null && options.as) { 549 name = options.as; 550 } 551 if (name) { 552 this.names[name] = { 553 segments: allSegments, 554 handlers 555 }; 556 } 557 }; 558 RouteRecognizer.prototype.handlersFor = function handlersFor(name) { 559 var route = this.names[name]; 560 if (!route) { 561 throw new Error("There is no route named " + name); 562 } 563 var result = new Array(route.handlers.length); 564 for (var i = 0; i < route.handlers.length; i++) { 565 var handler = route.handlers[i]; 566 result[i] = handler; 567 } 568 return result; 569 }; 570 RouteRecognizer.prototype.hasRoute = function hasRoute(name) { 571 return !!this.names[name]; 572 }; 573 RouteRecognizer.prototype.generate = function generate$1(name, params) { 574 var route = this.names[name]; 575 var output = ""; 576 if (!route) { 577 throw new Error("There is no route named " + name); 578 } 579 var segments = route.segments; 580 for (var i = 0; i < segments.length; i++) { 581 var segment = segments[i]; 582 if (segment.type === 4) { 583 continue; 584 } 585 output += "/"; 586 output += generate[segment.type](segment, params); 587 } 588 if (output.charAt(0) !== "/") { 589 output = "/" + output; 590 } 591 if (params && params.queryParams) { 592 output += this.generateQueryString(params.queryParams); 593 } 594 return output; 595 }; 596 RouteRecognizer.prototype.generateQueryString = function generateQueryString(params) { 597 var pairs = []; 598 var keys = Object.keys(params); 599 keys.sort(); 600 for (var i = 0; i < keys.length; i++) { 601 var key = keys[i]; 602 var value = params[key]; 603 if (value == null) { 604 continue; 605 } 606 var pair = encodeURIComponent(key); 607 if (isArray(value)) { 608 for (var j = 0; j < value.length; j++) { 609 var arrayPair = key + "[]=" + encodeURIComponent(value[j]); 610 pairs.push(arrayPair); 611 } 612 } else { 613 pair += "=" + encodeURIComponent(value); 614 pairs.push(pair); 615 } 616 } 617 if (pairs.length === 0) { 618 return ""; 619 } 620 return "?" + pairs.join("&"); 621 }; 622 RouteRecognizer.prototype.parseQueryString = function parseQueryString(queryString) { 623 var pairs = queryString.split("&"); 624 var queryParams = {}; 625 for (var i = 0; i < pairs.length; i++) { 626 var pair = pairs[i].split("="), key = decodeQueryParamPart(pair[0]), keyLength = key.length, isArray2 = false, value = void 0; 627 if (pair.length === 1) { 628 value = "true"; 629 } else { 630 if (keyLength > 2 && key.slice(keyLength - 2) === "[]") { 631 isArray2 = true; 632 key = key.slice(0, keyLength - 2); 633 if (!queryParams[key]) { 634 queryParams[key] = []; 635 } 636 } 637 value = pair[1] ? decodeQueryParamPart(pair[1]) : ""; 638 } 639 if (isArray2) { 640 queryParams[key].push(value); 641 } else { 642 queryParams[key] = value; 643 } 644 } 645 return queryParams; 646 }; 647 RouteRecognizer.prototype.recognize = function recognize(path) { 648 var results; 649 var states = [this.rootState]; 650 var queryParams = {}; 651 var isSlashDropped = false; 652 var hashStart = path.indexOf("#"); 653 if (hashStart !== -1) { 654 path = path.substr(0, hashStart); 655 } 656 var queryStart = path.indexOf("?"); 657 if (queryStart !== -1) { 658 var queryString = path.substr(queryStart + 1, path.length); 659 path = path.substr(0, queryStart); 660 queryParams = this.parseQueryString(queryString); 661 } 662 if (path.charAt(0) !== "/") { 663 path = "/" + path; 664 } 665 var originalPath = path; 666 if (RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS) { 667 path = normalizePath(path); 668 } else { 669 path = decodeURI(path); 670 originalPath = decodeURI(originalPath); 671 } 672 var pathLen = path.length; 673 if (pathLen > 1 && path.charAt(pathLen - 1) === "/") { 674 path = path.substr(0, pathLen - 1); 675 originalPath = originalPath.substr(0, originalPath.length - 1); 676 isSlashDropped = true; 677 } 678 for (var i = 0; i < path.length; i++) { 679 states = recognizeChar(states, path.charCodeAt(i)); 680 if (!states.length) { 681 break; 682 } 683 } 684 var solutions = []; 685 for (var i$1 = 0; i$1 < states.length; i$1++) { 686 if (states[i$1].handlers) { 687 solutions.push(states[i$1]); 688 } 689 } 690 states = sortSolutions(solutions); 691 var state = solutions[0]; 692 if (state && state.handlers) { 693 if (isSlashDropped && state.pattern && state.pattern.slice(-5) === "(.+)$") { 694 originalPath = originalPath + "/"; 695 } 696 results = findHandler(state, originalPath, queryParams); 697 } 698 return results; 699 }; 700 RouteRecognizer.VERSION = "0.3.4"; 701 RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS = true; 702 RouteRecognizer.Normalizer = { 703 normalizeSegment, 704 normalizePath, 705 encodePathSegment 706 }; 707 RouteRecognizer.prototype.map = map; 708 var route_recognizer_es_default = RouteRecognizer; 709 710 // node_modules/@babel/runtime/helpers/esm/extends.js 711 function _extends() { 712 return _extends = Object.assign ? Object.assign.bind() : function(n) { 713 for (var e = 1; e < arguments.length; e++) { 714 var t = arguments[e]; 715 for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); 716 } 717 return n; 718 }, _extends.apply(null, arguments); 719 } 720 721 // node_modules/history/index.js 722 var Action; 723 (function(Action2) { 724 Action2["Pop"] = "POP"; 725 Action2["Push"] = "PUSH"; 726 Action2["Replace"] = "REPLACE"; 727 })(Action || (Action = {})); 728 var readOnly = true ? function(obj) { 729 return Object.freeze(obj); 730 } : function(obj) { 731 return obj; 732 }; 733 function warning(cond, message) { 734 if (!cond) { 735 if (typeof console !== "undefined") console.warn(message); 736 try { 737 throw new Error(message); 738 } catch (e) { 739 } 740 } 741 } 742 var BeforeUnloadEventType = "beforeunload"; 743 var PopStateEventType = "popstate"; 744 function createBrowserHistory(options) { 745 if (options === void 0) { 746 options = {}; 747 } 748 var _options = options, _options$window = _options.window, window2 = _options$window === void 0 ? document.defaultView : _options$window; 749 var globalHistory = window2.history; 750 function getIndexAndLocation() { 751 var _window$location = window2.location, pathname = _window$location.pathname, search = _window$location.search, hash = _window$location.hash; 752 var state = globalHistory.state || {}; 753 return [state.idx, readOnly({ 754 pathname, 755 search, 756 hash, 757 state: state.usr || null, 758 key: state.key || "default" 759 })]; 760 } 761 var blockedPopTx = null; 762 function handlePop() { 763 if (blockedPopTx) { 764 blockers.call(blockedPopTx); 765 blockedPopTx = null; 766 } else { 767 var nextAction = Action.Pop; 768 var _getIndexAndLocation = getIndexAndLocation(), nextIndex = _getIndexAndLocation[0], nextLocation = _getIndexAndLocation[1]; 769 if (blockers.length) { 770 if (nextIndex != null) { 771 var delta = index - nextIndex; 772 if (delta) { 773 blockedPopTx = { 774 action: nextAction, 775 location: nextLocation, 776 retry: function retry() { 777 go(delta * -1); 778 } 779 }; 780 go(delta); 781 } 782 } else { 783 true ? warning( 784 false, 785 // TODO: Write up a doc that explains our blocking strategy in 786 // detail and link to it here so people can understand better what 787 // is going on and how to avoid it. 788 "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation." 789 ) : void 0; 790 } 791 } else { 792 applyTx(nextAction); 793 } 794 } 795 } 796 window2.addEventListener(PopStateEventType, handlePop); 797 var action = Action.Pop; 798 var _getIndexAndLocation2 = getIndexAndLocation(), index = _getIndexAndLocation2[0], location = _getIndexAndLocation2[1]; 799 var listeners = createEvents(); 800 var blockers = createEvents(); 801 if (index == null) { 802 index = 0; 803 globalHistory.replaceState(_extends({}, globalHistory.state, { 804 idx: index 805 }), ""); 806 } 807 function createHref(to2) { 808 return typeof to2 === "string" ? to2 : createPath(to2); 809 } 810 function getNextLocation(to2, state) { 811 if (state === void 0) { 812 state = null; 813 } 814 return readOnly(_extends({ 815 pathname: location.pathname, 816 hash: "", 817 search: "" 818 }, typeof to2 === "string" ? parsePath(to2) : to2, { 819 state, 820 key: createKey() 821 })); 822 } 823 function getHistoryStateAndUrl(nextLocation, index2) { 824 return [{ 825 usr: nextLocation.state, 826 key: nextLocation.key, 827 idx: index2 828 }, createHref(nextLocation)]; 829 } 830 function allowTx(action2, location2, retry) { 831 return !blockers.length || (blockers.call({ 832 action: action2, 833 location: location2, 834 retry 835 }), false); 836 } 837 function applyTx(nextAction) { 838 action = nextAction; 839 var _getIndexAndLocation3 = getIndexAndLocation(); 840 index = _getIndexAndLocation3[0]; 841 location = _getIndexAndLocation3[1]; 842 listeners.call({ 843 action, 844 location 845 }); 846 } 847 function push(to2, state) { 848 var nextAction = Action.Push; 849 var nextLocation = getNextLocation(to2, state); 850 function retry() { 851 push(to2, state); 852 } 853 if (allowTx(nextAction, nextLocation, retry)) { 854 var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1), historyState = _getHistoryStateAndUr[0], url = _getHistoryStateAndUr[1]; 855 try { 856 globalHistory.pushState(historyState, "", url); 857 } catch (error) { 858 window2.location.assign(url); 859 } 860 applyTx(nextAction); 861 } 862 } 863 function replace(to2, state) { 864 var nextAction = Action.Replace; 865 var nextLocation = getNextLocation(to2, state); 866 function retry() { 867 replace(to2, state); 868 } 869 if (allowTx(nextAction, nextLocation, retry)) { 870 var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index), historyState = _getHistoryStateAndUr2[0], url = _getHistoryStateAndUr2[1]; 871 globalHistory.replaceState(historyState, "", url); 872 applyTx(nextAction); 873 } 874 } 875 function go(delta) { 876 globalHistory.go(delta); 877 } 878 var history2 = { 879 get action() { 880 return action; 881 }, 882 get location() { 883 return location; 884 }, 885 createHref, 886 push, 887 replace, 888 go, 889 back: function back() { 890 go(-1); 891 }, 892 forward: function forward() { 893 go(1); 894 }, 895 listen: function listen(listener) { 896 return listeners.push(listener); 897 }, 898 block: function block(blocker) { 899 var unblock = blockers.push(blocker); 900 if (blockers.length === 1) { 901 window2.addEventListener(BeforeUnloadEventType, promptBeforeUnload); 902 } 903 return function() { 904 unblock(); 905 if (!blockers.length) { 906 window2.removeEventListener(BeforeUnloadEventType, promptBeforeUnload); 907 } 908 }; 909 } 910 }; 911 return history2; 912 } 913 function promptBeforeUnload(event) { 914 event.preventDefault(); 915 event.returnValue = ""; 916 } 917 function createEvents() { 918 var handlers = []; 919 return { 920 get length() { 921 return handlers.length; 922 }, 923 push: function push(fn) { 924 handlers.push(fn); 925 return function() { 926 handlers = handlers.filter(function(handler) { 927 return handler !== fn; 928 }); 929 }; 930 }, 931 call: function call(arg) { 932 handlers.forEach(function(fn) { 933 return fn && fn(arg); 934 }); 935 } 936 }; 937 } 938 function createKey() { 939 return Math.random().toString(36).substr(2, 8); 940 } 941 function createPath(_ref) { 942 var _ref$pathname = _ref.pathname, pathname = _ref$pathname === void 0 ? "/" : _ref$pathname, _ref$search = _ref.search, search = _ref$search === void 0 ? "" : _ref$search, _ref$hash = _ref.hash, hash = _ref$hash === void 0 ? "" : _ref$hash; 943 if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search; 944 if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash; 945 return pathname; 946 } 947 function parsePath(path) { 948 var parsedPath = {}; 949 if (path) { 950 var hashIndex = path.indexOf("#"); 951 if (hashIndex >= 0) { 952 parsedPath.hash = path.substr(hashIndex); 953 path = path.substr(0, hashIndex); 954 } 955 var searchIndex = path.indexOf("?"); 956 if (searchIndex >= 0) { 957 parsedPath.search = path.substr(searchIndex); 958 path = path.substr(0, searchIndex); 959 } 960 if (path) { 961 parsedPath.pathname = path; 962 } 963 } 964 return parsedPath; 965 } 966 967 // packages/router/build-module/router.mjs 968 var import_element = __toESM(require_element(), 1); 969 var import_url = __toESM(require_url(), 1); 970 var import_compose = __toESM(require_compose(), 1); 971 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); 972 var history = createBrowserHistory(); 973 var RoutesContext = (0, import_element.createContext)(null); 974 RoutesContext.displayName = "RoutesContext"; 975 var ConfigContext = (0, import_element.createContext)({ pathArg: "p" }); 976 ConfigContext.displayName = "ConfigContext"; 977 var locationMemo = /* @__PURE__ */ new WeakMap(); 978 function getLocationWithQuery() { 979 const location = history.location; 980 let locationWithQuery = locationMemo.get(location); 981 if (!locationWithQuery) { 982 locationWithQuery = { 983 ...location, 984 query: Object.fromEntries(new URLSearchParams(location.search)) 985 }; 986 locationMemo.set(location, locationWithQuery); 987 } 988 return locationWithQuery; 989 } 990 function useLocation() { 991 const context = (0, import_element.useContext)(RoutesContext); 992 if (!context) { 993 throw new Error("useLocation must be used within a RouterProvider"); 994 } 995 return context; 996 } 997 function useHistory() { 998 const { pathArg, beforeNavigate } = (0, import_element.useContext)(ConfigContext); 999 const navigate = (0, import_compose.useEvent)( 1000 async (rawPath, options = {}) => { 1001 const query = (0, import_url.getQueryArgs)(rawPath); 1002 const path = (0, import_url.getPath)("http://domain.com/" + rawPath) ?? ""; 1003 const performPush = () => { 1004 const result = beforeNavigate ? beforeNavigate({ path, query }) : { path, query }; 1005 return history[options.replace ? "replace" : "push"]( 1006 { 1007 search: (0, import_url.buildQueryString)({ 1008 [pathArg]: result.path, 1009 ...result.query 1010 }) 1011 }, 1012 options.state 1013 ); 1014 }; 1015 const isMediumOrBigger = window.matchMedia("(min-width: 782px)").matches; 1016 if (!isMediumOrBigger || !document.startViewTransition || !options.transition) { 1017 performPush(); 1018 return; 1019 } 1020 await new Promise((resolve) => { 1021 const classname = options.transition ?? ""; 1022 document.documentElement.classList.add(classname); 1023 const transition = document.startViewTransition( 1024 () => performPush() 1025 ); 1026 transition.finished.finally(() => { 1027 document.documentElement.classList.remove(classname); 1028 resolve(); 1029 }); 1030 }); 1031 } 1032 ); 1033 return (0, import_element.useMemo)( 1034 () => ({ 1035 navigate, 1036 back: history.back, 1037 invalidate: () => { 1038 history.replace({ 1039 search: history.location.search 1040 }); 1041 } 1042 }), 1043 [navigate] 1044 ); 1045 } 1046 function useMatch(location, matcher, pathArg, matchResolverArgs) { 1047 const { query: rawQuery = {} } = location; 1048 const [resolvedMatch, setMatch] = (0, import_element.useState)(); 1049 (0, import_element.useEffect)(() => { 1050 const { [pathArg]: path = "/", ...query } = rawQuery; 1051 const ret = matcher.recognize(path)?.[0]; 1052 async function resolveMatch(result) { 1053 const matchedRoute = result.handler; 1054 const resolveFunctions = async (record = {}) => { 1055 const entries = await Promise.all( 1056 Object.entries(record).map(async ([key, value]) => { 1057 if (typeof value === "function") { 1058 return [ 1059 key, 1060 await value({ 1061 query, 1062 params: result.params, 1063 ...matchResolverArgs 1064 }) 1065 ]; 1066 } 1067 return [key, value]; 1068 }) 1069 ); 1070 return Object.fromEntries(entries); 1071 }; 1072 const [resolvedAreas, resolvedWidths] = await Promise.all([ 1073 resolveFunctions(matchedRoute.areas), 1074 resolveFunctions(matchedRoute.widths) 1075 ]); 1076 setMatch({ 1077 name: matchedRoute.name, 1078 areas: resolvedAreas, 1079 widths: resolvedWidths, 1080 params: result.params, 1081 query, 1082 path: (0, import_url.addQueryArgs)(path, query) 1083 }); 1084 } 1085 if (!ret) { 1086 setMatch({ 1087 name: "404", 1088 path: (0, import_url.addQueryArgs)(path, query), 1089 areas: {}, 1090 widths: {}, 1091 query, 1092 params: {} 1093 }); 1094 } else { 1095 resolveMatch(ret); 1096 } 1097 return () => setMatch(void 0); 1098 }, [matcher, rawQuery, pathArg, matchResolverArgs]); 1099 return resolvedMatch; 1100 } 1101 function RouterProvider({ 1102 routes, 1103 pathArg, 1104 beforeNavigate, 1105 children, 1106 matchResolverArgs 1107 }) { 1108 const location = (0, import_element.useSyncExternalStore)( 1109 history.listen, 1110 getLocationWithQuery, 1111 getLocationWithQuery 1112 ); 1113 const matcher = (0, import_element.useMemo)(() => { 1114 const ret = new route_recognizer_es_default(); 1115 (routes ?? []).forEach((route) => { 1116 ret.add([{ path: route.path, handler: route }], { 1117 as: route.name 1118 }); 1119 }); 1120 return ret; 1121 }, [routes]); 1122 const match2 = useMatch(location, matcher, pathArg, matchResolverArgs); 1123 const previousMatch = (0, import_compose.usePrevious)(match2); 1124 const config = (0, import_element.useMemo)( 1125 () => ({ beforeNavigate, pathArg }), 1126 [beforeNavigate, pathArg] 1127 ); 1128 const renderedMatch = match2 || previousMatch; 1129 if (!renderedMatch) { 1130 return null; 1131 } 1132 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigContext.Provider, { value: config, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RoutesContext.Provider, { value: renderedMatch, children }) }); 1133 } 1134 1135 // packages/router/build-module/link.mjs 1136 var import_element2 = __toESM(require_element(), 1); 1137 var import_url2 = __toESM(require_url(), 1); 1138 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1); 1139 function useLink(to2, options = {}) { 1140 const history2 = useHistory(); 1141 const { pathArg, beforeNavigate } = (0, import_element2.useContext)(ConfigContext); 1142 function onClick(event) { 1143 event?.preventDefault(); 1144 history2.navigate(to2, options); 1145 } 1146 const query = (0, import_url2.getQueryArgs)(to2); 1147 const path = (0, import_url2.getPath)("http://domain.com/" + to2) ?? ""; 1148 const link = (0, import_element2.useMemo)(() => { 1149 return beforeNavigate ? beforeNavigate({ path, query }) : { path, query }; 1150 }, [path, query, beforeNavigate]); 1151 const [before] = window.location.href.split("?"); 1152 return { 1153 href: `$before}?${(0, import_url2.buildQueryString)({ 1154 [pathArg]: link.path, 1155 ...link.query 1156 })}`, 1157 onClick 1158 }; 1159 } 1160 function Link({ 1161 to: to2, 1162 options, 1163 children, 1164 ...props 1165 }) { 1166 const { href, onClick } = useLink(to2, options); 1167 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href, onClick, ...props, children }); 1168 } 1169 1170 // packages/router/build-module/lock-unlock.mjs 1171 var import_private_apis = __toESM(require_private_apis(), 1); 1172 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)( 1173 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", 1174 "@wordpress/router" 1175 ); 1176 1177 // packages/router/build-module/private-apis.mjs 1178 var privateApis = {}; 1179 lock(privateApis, { 1180 useHistory, 1181 useLocation, 1182 RouterProvider, 1183 useLink, 1184 Link 1185 }); 1186 return __toCommonJS(index_exports); 1187 })(); 1188 (window.wp ||= {}).router = wp.router; 1189 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sun Aug 23 08:20:23 2026 | Cross-referenced by PHPXref |