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