unpoly-rails 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
  /***/ (() => {
6
6
 
7
7
  window.up = {
8
- version: '3.1.0'
8
+ version: '3.2.0'
9
9
  };
10
10
 
11
11
 
@@ -194,6 +194,9 @@ up.util = (function () {
194
194
  function isRegExp(object) {
195
195
  return object instanceof RegExp;
196
196
  }
197
+ function isError(object) {
198
+ return object instanceof Error;
199
+ }
197
200
  function isJQuery(object) {
198
201
  return up.browser.canJQuery() && object instanceof jQuery;
199
202
  }
@@ -389,8 +392,8 @@ up.util = (function () {
389
392
  function queueMicrotask(task) {
390
393
  return Promise.resolve().then(task);
391
394
  }
392
- function last(array) {
393
- return array[array.length - 1];
395
+ function last(value) {
396
+ return value[value.length - 1];
394
397
  }
395
398
  function contains(value, subValue) {
396
399
  return value.indexOf(subValue) >= 0;
@@ -615,14 +618,20 @@ up.util = (function () {
615
618
  });
616
619
  }
617
620
  }
618
- function stringifyArg(arg) {
621
+ function stringifyArg(arg, placeholder = '%o') {
619
622
  let string;
620
623
  const maxLength = 200;
621
- let closer = '';
624
+ if (placeholder === '%c') {
625
+ return '';
626
+ }
627
+ if (placeholder === '%s' && isGiven(arg)) {
628
+ arg = arg.toString();
629
+ }
622
630
  if (isString(arg)) {
623
- string = arg.replace(/[\n\r\t ]+/g, ' ');
624
- string = string.replace(/^[\n\r\t ]+/, '');
625
- string = string.replace(/[\n\r\t ]$/, '');
631
+ string = arg.trim().replace(/[\n\r\t ]+/g, ' ');
632
+ if (placeholder === '%o') {
633
+ string = JSON.stringify(string);
634
+ }
626
635
  }
627
636
  else if (isUndefined(arg)) {
628
637
  string = 'undefined';
@@ -632,24 +641,21 @@ up.util = (function () {
632
641
  }
633
642
  else if (isArray(arg)) {
634
643
  string = `[${map(arg, stringifyArg).join(', ')}]`;
635
- closer = ']';
636
644
  }
637
645
  else if (isJQuery(arg)) {
638
646
  string = `$(${map(arg, stringifyArg).join(', ')})`;
639
- closer = ')';
640
647
  }
641
648
  else if (isElement(arg)) {
642
649
  string = `<${arg.tagName.toLowerCase()}`;
643
- for (let attr of ['id', 'name', 'class']) {
650
+ for (let attr of ['id', 'up-id', 'name', 'class']) {
644
651
  let value = arg.getAttribute(attr);
645
652
  if (value) {
646
653
  string += ` ${attr}="${value}"`;
647
654
  }
648
655
  }
649
656
  string += ">";
650
- closer = '>';
651
657
  }
652
- else if (isRegExp(arg)) {
658
+ else if (isRegExp(arg) || isError(arg)) {
653
659
  string = arg.toString();
654
660
  }
655
661
  else {
@@ -666,14 +672,13 @@ up.util = (function () {
666
672
  }
667
673
  }
668
674
  if (string.length > maxLength) {
669
- string = `${string.substr(0, maxLength)} …`;
670
- string += closer;
675
+ string = `${string.substr(0, maxLength)}…${last(string)}`;
671
676
  }
672
677
  return string;
673
678
  }
674
- const SPRINTF_PLACEHOLDERS = /%[oOdisf]/g;
679
+ const SPRINTF_PLACEHOLDERS = /%[oOdisfc]/g;
675
680
  function sprintf(message, ...args) {
676
- return message.replace(SPRINTF_PLACEHOLDERS, () => stringifyArg(args.shift()));
681
+ return message.replace(SPRINTF_PLACEHOLDERS, (placeholder) => stringifyArg(args.shift(), placeholder));
677
682
  }
678
683
  function negate(fn) {
679
684
  return function (...args) {
@@ -716,6 +721,11 @@ up.util = (function () {
716
721
  let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0');
717
722
  return string.replace(/[^\x00-\x7F]/g, unicodeEscape);
718
723
  }
724
+ function variant(source, changes = {}) {
725
+ let variant = Object.create(source);
726
+ Object.assign(variant, changes);
727
+ return variant;
728
+ }
719
729
  return {
720
730
  parseURL,
721
731
  normalizeURL,
@@ -813,6 +823,7 @@ up.util = (function () {
813
823
  negate,
814
824
  memoizeMethod,
815
825
  safeStringifyJSON,
826
+ variant,
816
827
  };
817
828
  })();
818
829
 
@@ -1581,10 +1592,7 @@ up.Record = class Record {
1581
1592
  return u.pick(source, this.keys());
1582
1593
  }
1583
1594
  [u.copy.key]() {
1584
- return this.variant();
1585
- }
1586
- variant(changes = {}) {
1587
- return new this.constructor(u.merge(this.attributes(), changes));
1595
+ return u.variant(this);
1588
1596
  }
1589
1597
  [u.isEqual.key](other) {
1590
1598
  return (this.constructor === other.constructor) && u.isEqual(this.attributes(), other.attributes());
@@ -1756,9 +1764,6 @@ up.Change = class Change {
1756
1764
  constructor(options) {
1757
1765
  this.options = options;
1758
1766
  }
1759
- cannotMatch(reason) {
1760
- throw new up.CannotMatch(reason);
1761
- }
1762
1767
  execute() {
1763
1768
  throw new up.NotImplemented();
1764
1769
  }
@@ -1773,6 +1778,9 @@ up.Change = class Change {
1773
1778
  return newValue;
1774
1779
  }
1775
1780
  }
1781
+ deriveFailOptions() {
1782
+ return up.RenderOptions.deriveFailOptions(this.options);
1783
+ }
1776
1784
  };
1777
1785
 
1778
1786
 
@@ -1789,33 +1797,34 @@ up.Change.Addition = class Addition extends up.Change {
1789
1797
  this.acceptLayer = options.acceptLayer;
1790
1798
  this.dismissLayer = options.dismissLayer;
1791
1799
  this.eventPlans = options.eventPlans || [];
1800
+ this.response = options.meta?.response;
1792
1801
  }
1793
1802
  handleLayerChangeRequests() {
1794
1803
  if (this.layer.isOverlay()) {
1795
1804
  this.tryAcceptLayerFromServer();
1796
1805
  this.abortWhenLayerClosed();
1797
- this.layer.tryAcceptForLocation();
1806
+ this.layer.tryAcceptForLocation(this.responseOption());
1798
1807
  this.abortWhenLayerClosed();
1799
1808
  this.tryDismissLayerFromServer();
1800
1809
  this.abortWhenLayerClosed();
1801
- this.layer.tryDismissForLocation();
1810
+ this.layer.tryDismissForLocation(this.responseOption());
1802
1811
  this.abortWhenLayerClosed();
1803
1812
  }
1804
1813
  this.layer.asCurrent(() => {
1805
1814
  for (let eventPlan of this.eventPlans) {
1806
- up.emit(eventPlan);
1815
+ up.emit({ ...eventPlan, ...this.responseOption() });
1807
1816
  this.abortWhenLayerClosed();
1808
1817
  }
1809
1818
  });
1810
1819
  }
1811
1820
  tryAcceptLayerFromServer() {
1812
1821
  if (u.isDefined(this.acceptLayer) && this.layer.isOverlay()) {
1813
- this.layer.accept(this.acceptLayer);
1822
+ this.layer.accept(this.acceptLayer, this.responseOption());
1814
1823
  }
1815
1824
  }
1816
1825
  tryDismissLayerFromServer() {
1817
1826
  if (u.isDefined(this.dismissLayer) && this.layer.isOverlay()) {
1818
- this.layer.dismiss(this.dismissLayer);
1827
+ this.layer.dismiss(this.dismissLayer, this.responseOption());
1819
1828
  }
1820
1829
  }
1821
1830
  abortWhenLayerClosed() {
@@ -1842,6 +1851,9 @@ up.Change.Addition = class Addition extends up.Change {
1842
1851
  this.setTime(options);
1843
1852
  this.setETag(options);
1844
1853
  }
1854
+ responseOption() {
1855
+ return { response: this.response };
1856
+ }
1845
1857
  };
1846
1858
 
1847
1859
 
@@ -1898,6 +1910,10 @@ up.RenderJob = (_a = class RenderJob {
1898
1910
  let onRequest = (request) => this.handleAbortOption(request);
1899
1911
  this.change = new up.Change.FromURL({ ...this.options, onRequest });
1900
1912
  }
1913
+ else if (this.options.response) {
1914
+ this.change = new up.Change.FromResponse(this.options);
1915
+ this.handleAbortOption(null);
1916
+ }
1901
1917
  else {
1902
1918
  this.change = new up.Change.FromContent(this.options);
1903
1919
  this.handleAbortOption(null);
@@ -2031,7 +2047,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2031
2047
  this.content = responseDoc.select(this.target);
2032
2048
  }
2033
2049
  if (!this.content || this.baseLayer.isClosed()) {
2034
- throw this.cannotMatch();
2050
+ throw new up.CannotMatch();
2035
2051
  }
2036
2052
  onApplicable();
2037
2053
  up.puts('up.render()', `Opening element "${this.target}" in new overlay`);
@@ -2347,7 +2363,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2347
2363
  return true;
2348
2364
  }
2349
2365
  else if (!step.maybe) {
2350
- throw this.cannotMatch(`Could not find element "${this.target}" in current page`);
2366
+ throw new up.CannotMatch();
2351
2367
  }
2352
2368
  });
2353
2369
  this.resolveOldNesting();
@@ -2363,7 +2379,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2363
2379
  return true;
2364
2380
  }
2365
2381
  else if (!step.maybe) {
2366
- throw this.cannotMatch(`Could not find element "${this.target}" in server response`);
2382
+ throw new up.CannotMatch();
2367
2383
  }
2368
2384
  });
2369
2385
  this.resolveOldNesting();
@@ -2466,6 +2482,7 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2466
2482
  this.origin = options.origin;
2467
2483
  this.value = options.value;
2468
2484
  this.preventable = options.preventable ?? true;
2485
+ this.response = options.response;
2469
2486
  }
2470
2487
  execute() {
2471
2488
  if (!this.layer.isOpen()) {
@@ -2507,7 +2524,8 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2507
2524
  return up.event.build(name, {
2508
2525
  layer: this.layer,
2509
2526
  value: this.value,
2510
- origin: this.origin
2527
+ origin: this.origin,
2528
+ response: this.response,
2511
2529
  });
2512
2530
  }
2513
2531
  handleFocus(formerParent) {
@@ -2523,142 +2541,6 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2523
2541
  /* 31 */
2524
2542
  /***/ (() => {
2525
2543
 
2526
- var _a;
2527
- const u = up.util;
2528
- up.Change.FromContent = (_a = class FromContent extends up.Change {
2529
- constructor(options) {
2530
- super(options);
2531
- this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2532
- this.origin = this.options.origin;
2533
- this.preview = this.options.preview;
2534
- this.mode = this.options.mode;
2535
- if (this.origin) {
2536
- this.originLayer = up.layer.get(this.origin);
2537
- }
2538
- }
2539
- isRenderableLayer(layer) {
2540
- return (layer === 'new') || layer.isOpen();
2541
- }
2542
- getPlans() {
2543
- var _a;
2544
- let plans = [];
2545
- if (this.options.fragment) {
2546
- (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2547
- }
2548
- this.expandIntoPlans(plans, this.layers, this.options.target);
2549
- this.expandIntoPlans(plans, this.layers, this.options.fallback);
2550
- return plans;
2551
- }
2552
- expandIntoPlans(plans, layers, targets) {
2553
- for (let layer of layers) {
2554
- for (let target of this.expandTargets(targets, layer)) {
2555
- const props = { ...this.options, target, layer, defaultPlacement: this.defaultPlacement() };
2556
- const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2557
- plans.push(change);
2558
- }
2559
- }
2560
- }
2561
- expandTargets(targets, layer) {
2562
- return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2563
- }
2564
- execute() {
2565
- if (this.options.preload) {
2566
- return Promise.resolve();
2567
- }
2568
- return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2569
- }
2570
- executePlan(matchedPlan) {
2571
- let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2572
- result.options = this.options;
2573
- return result;
2574
- }
2575
- onPlanApplicable(plan) {
2576
- let primaryPlan = this.getPlans()[0];
2577
- if (plan !== primaryPlan) {
2578
- up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2579
- }
2580
- }
2581
- getResponseDoc() {
2582
- if (this.preview)
2583
- return;
2584
- const docOptions = u.pick(this.options, [
2585
- 'target',
2586
- 'content',
2587
- 'fragment',
2588
- 'document',
2589
- 'html',
2590
- 'cspNonces',
2591
- 'origin',
2592
- ]);
2593
- up.migrate.handleResponseDocOptions?.(docOptions);
2594
- if (this.defaultPlacement() === 'content') {
2595
- docOptions.target = this.firstExpandedTarget(docOptions.target);
2596
- }
2597
- return new up.ResponseDoc(docOptions);
2598
- }
2599
- defaultPlacement() {
2600
- if (!this.options.document && !this.options.fragment) {
2601
- return 'content';
2602
- }
2603
- }
2604
- firstExpandedTarget(target) {
2605
- return this.expandTargets(target || ':main', this.layers[0])[0];
2606
- }
2607
- getPreflightProps(opts = {}) {
2608
- const getPlanProps = plan => plan.getPreflightProps();
2609
- return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2610
- }
2611
- cannotMatchPreflightTarget() {
2612
- this.cannotMatchTarget('Could not find target in current page');
2613
- }
2614
- cannotMatchPostflightTarget() {
2615
- this.cannotMatchTarget('Could not find common target in current page and response');
2616
- }
2617
- cannotMatchTarget(reason) {
2618
- if (this.getPlans().length) {
2619
- const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2620
- const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2621
- up.fail(reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption);
2622
- }
2623
- else if (this.layers.length) {
2624
- if (this.options.failPrefixForced) {
2625
- up.fail('No target selector given for failed responses (https://unpoly.com/failed-responses)');
2626
- }
2627
- else {
2628
- up.fail('No target selector given');
2629
- }
2630
- }
2631
- else {
2632
- up.fail('Layer %o does not exist', this.options.layer);
2633
- }
2634
- }
2635
- seekPlan(fn) {
2636
- for (let plan of this.getPlans()) {
2637
- try {
2638
- return fn(plan);
2639
- }
2640
- catch (error) {
2641
- if (!(error instanceof up.CannotMatch)) {
2642
- throw error;
2643
- }
2644
- }
2645
- }
2646
- }
2647
- },
2648
- (() => {
2649
- u.memoizeMethod(_a.prototype, [
2650
- 'getPlans',
2651
- 'getResponseDoc',
2652
- 'getPreflightProps',
2653
- ]);
2654
- })(),
2655
- _a);
2656
-
2657
-
2658
- /***/ }),
2659
- /* 32 */
2660
- /***/ (() => {
2661
-
2662
2544
  var _a;
2663
2545
  const u = up.util;
2664
2546
  up.Change.FromURL = (_a = class FromURL extends up.Change {
@@ -2683,9 +2565,6 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2683
2565
  }
2684
2566
  return u.always(this.request, responseOrError => this.onRequestSettled(responseOrError));
2685
2567
  }
2686
- deriveFailOptions() {
2687
- return up.RenderOptions.deriveFailOptions(this.options);
2688
- }
2689
2568
  newPageReason() {
2690
2569
  if (u.isCrossOrigin(this.options.url)) {
2691
2570
  return 'Loading cross-origin content in new page';
@@ -2719,7 +2598,41 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2719
2598
  }
2720
2599
  }
2721
2600
  onRequestSettledWithResponse(response) {
2722
- this.response = response;
2601
+ return new up.Change.FromResponse({ ...this.options, response }).execute();
2602
+ }
2603
+ onRequestSettledWithError(error) {
2604
+ if (error instanceof up.Offline) {
2605
+ this.request.emit('up:fragment:offline', {
2606
+ callback: this.options.onOffline,
2607
+ renderOptions: this.options,
2608
+ retry: (retryOptions) => up.render({ ...this.options, ...retryOptions }),
2609
+ log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
2610
+ });
2611
+ }
2612
+ throw error;
2613
+ }
2614
+ },
2615
+ (() => {
2616
+ u.memoizeMethod(_a.prototype, [
2617
+ 'getRequestAttrs',
2618
+ ]);
2619
+ })(),
2620
+ _a);
2621
+
2622
+
2623
+ /***/ }),
2624
+ /* 32 */
2625
+ /***/ (() => {
2626
+
2627
+ var _a;
2628
+ const u = up.util;
2629
+ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2630
+ constructor(options) {
2631
+ super(options);
2632
+ this.response = options.response;
2633
+ this.request = this.response.request;
2634
+ }
2635
+ execute() {
2723
2636
  if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2724
2637
  this.skip();
2725
2638
  }
@@ -2731,40 +2644,12 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2731
2644
  skip: () => this.skip()
2732
2645
  });
2733
2646
  }
2734
- let fail = u.evalOption(this.options.fail, this.response) ?? !response.ok;
2647
+ let fail = u.evalOption(this.options.fail, this.response) ?? !this.response.ok;
2735
2648
  if (fail) {
2736
2649
  throw this.updateContentFromResponse(this.deriveFailOptions());
2737
2650
  }
2738
2651
  return this.updateContentFromResponse(this.options);
2739
2652
  }
2740
- compilerPassMeta() {
2741
- return u.pick(this.loadedEventProps(), [
2742
- 'revalidating',
2743
- 'response'
2744
- ]);
2745
- }
2746
- loadedEventProps() {
2747
- const { expiredResponse } = this.options;
2748
- return {
2749
- request: this.request,
2750
- response: this.response,
2751
- renderOptions: this.options,
2752
- revalidating: !!expiredResponse,
2753
- expiredResponse,
2754
- };
2755
- }
2756
- onRequestSettledWithError(error) {
2757
- if (error instanceof up.Offline) {
2758
- this.request.emit('up:fragment:offline', {
2759
- callback: this.options.onOffline,
2760
- response: this.response,
2761
- renderOptions: this.options,
2762
- retry: (retryOptions) => up.render({ ...this.options, ...retryOptions }),
2763
- log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
2764
- });
2765
- }
2766
- throw error;
2767
- }
2768
2653
  skip() {
2769
2654
  up.puts('up.render()', 'Skipping ' + this.response.description);
2770
2655
  this.options.target = ':none';
@@ -2813,52 +2698,205 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2813
2698
  }
2814
2699
  return renderResult;
2815
2700
  }
2816
- augmentOptionsFromResponse(renderOptions) {
2817
- const responseURL = this.response.url;
2818
- let serverLocation = responseURL;
2819
- let hash = this.request.hash;
2820
- if (hash) {
2821
- renderOptions.hash = hash;
2822
- serverLocation += hash;
2701
+ loadedEventProps() {
2702
+ const { expiredResponse } = this.options;
2703
+ return {
2704
+ request: this.request,
2705
+ response: this.response,
2706
+ renderOptions: this.options,
2707
+ revalidating: !!expiredResponse,
2708
+ expiredResponse,
2709
+ };
2710
+ }
2711
+ compilerPassMeta() {
2712
+ return u.pick(this.loadedEventProps(), [
2713
+ 'revalidating',
2714
+ 'response'
2715
+ ]);
2716
+ }
2717
+ augmentOptionsFromResponse(renderOptions) {
2718
+ const responseURL = this.response.url;
2719
+ let serverLocation = responseURL;
2720
+ let hash = this.request.hash;
2721
+ if (hash) {
2722
+ renderOptions.hash = hash;
2723
+ serverLocation += hash;
2724
+ }
2725
+ const isReloadable = (this.response.method === 'GET');
2726
+ if (isReloadable) {
2727
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2728
+ }
2729
+ else {
2730
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2731
+ renderOptions.history = !!renderOptions.location;
2732
+ }
2733
+ renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2734
+ renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2735
+ renderOptions.eventPlans = this.response.eventPlans;
2736
+ let serverTarget = this.response.target;
2737
+ if (serverTarget) {
2738
+ renderOptions.target = serverTarget;
2739
+ }
2740
+ renderOptions.acceptLayer = this.response.acceptLayer;
2741
+ renderOptions.dismissLayer = this.response.dismissLayer;
2742
+ renderOptions.document = this.response.text;
2743
+ if (this.response.none) {
2744
+ renderOptions.target = ':none';
2745
+ }
2746
+ renderOptions.context = u.merge(renderOptions.context, this.response.context);
2747
+ renderOptions.cspNonces = this.response.cspNonces;
2748
+ renderOptions.time ?? (renderOptions.time = this.response.lastModified);
2749
+ renderOptions.etag ?? (renderOptions.etag = this.response.etag);
2750
+ }
2751
+ },
2752
+ (() => {
2753
+ u.memoizeMethod(_a.prototype, [
2754
+ 'loadedEventProps',
2755
+ ]);
2756
+ })(),
2757
+ _a);
2758
+
2759
+
2760
+ /***/ }),
2761
+ /* 33 */
2762
+ /***/ (() => {
2763
+
2764
+ var _a;
2765
+ const u = up.util;
2766
+ up.Change.FromContent = (_a = class FromContent extends up.Change {
2767
+ constructor(options) {
2768
+ super(options);
2769
+ this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2770
+ this.origin = this.options.origin;
2771
+ this.preview = this.options.preview;
2772
+ this.mode = this.options.mode;
2773
+ if (this.origin) {
2774
+ this.originLayer = up.layer.get(this.origin);
2775
+ }
2776
+ }
2777
+ isRenderableLayer(layer) {
2778
+ return (layer === 'new') || layer.isOpen();
2779
+ }
2780
+ getPlans() {
2781
+ var _a;
2782
+ let plans = [];
2783
+ if (this.options.fragment) {
2784
+ (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2785
+ }
2786
+ this.expandIntoPlans(plans, this.layers, this.options.target);
2787
+ this.expandIntoPlans(plans, this.layers, this.options.fallback);
2788
+ return plans;
2789
+ }
2790
+ expandIntoPlans(plans, layers, targets) {
2791
+ for (let layer of layers) {
2792
+ for (let target of this.expandTargets(targets, layer)) {
2793
+ const props = { ...this.options, target, layer, defaultPlacement: this.defaultPlacement() };
2794
+ const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2795
+ plans.push(change);
2796
+ }
2797
+ }
2798
+ }
2799
+ expandTargets(targets, layer) {
2800
+ return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2801
+ }
2802
+ execute() {
2803
+ if (this.options.preload) {
2804
+ return Promise.resolve();
2805
+ }
2806
+ return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2807
+ }
2808
+ executePlan(matchedPlan) {
2809
+ let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2810
+ result.options = this.options;
2811
+ return result;
2812
+ }
2813
+ onPlanApplicable(plan) {
2814
+ let primaryPlan = this.getPlans()[0];
2815
+ if (plan !== primaryPlan) {
2816
+ up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2817
+ }
2818
+ }
2819
+ getResponseDoc() {
2820
+ if (this.preview)
2821
+ return;
2822
+ const docOptions = u.pick(this.options, [
2823
+ 'target',
2824
+ 'content',
2825
+ 'fragment',
2826
+ 'document',
2827
+ 'html',
2828
+ 'cspNonces',
2829
+ 'origin',
2830
+ ]);
2831
+ up.migrate.handleResponseDocOptions?.(docOptions);
2832
+ if (this.defaultPlacement() === 'content') {
2833
+ docOptions.target = this.firstExpandedTarget(docOptions.target);
2834
+ }
2835
+ return new up.ResponseDoc(docOptions);
2836
+ }
2837
+ defaultPlacement() {
2838
+ if (!this.options.document && !this.options.fragment) {
2839
+ return 'content';
2840
+ }
2841
+ }
2842
+ firstExpandedTarget(target) {
2843
+ return this.expandTargets(target || ':main', this.layers[0])[0];
2844
+ }
2845
+ getPreflightProps(opts = {}) {
2846
+ const getPlanProps = plan => plan.getPreflightProps();
2847
+ return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2848
+ }
2849
+ cannotMatchPreflightTarget() {
2850
+ this.cannotMatchTarget('Could not find target in current page');
2851
+ }
2852
+ cannotMatchPostflightTarget() {
2853
+ this.cannotMatchTarget('Could not find common target in current page and response');
2854
+ }
2855
+ cannotMatchTarget(reason) {
2856
+ let message;
2857
+ if (this.getPlans().length) {
2858
+ const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2859
+ const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2860
+ message = [reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption];
2823
2861
  }
2824
- const isReloadable = (this.response.method === 'GET');
2825
- if (isReloadable) {
2826
- renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2862
+ else if (this.layers.length) {
2863
+ if (this.options.failPrefixForced) {
2864
+ message = 'No target selector given for failed responses (https://unpoly.com/failed-responses)';
2865
+ }
2866
+ else {
2867
+ message = 'No target selector given';
2868
+ }
2827
2869
  }
2828
2870
  else {
2829
- renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2830
- renderOptions.history = !!renderOptions.location;
2831
- }
2832
- renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2833
- renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2834
- renderOptions.eventPlans = this.response.eventPlans;
2835
- let serverTarget = this.response.target;
2836
- if (serverTarget) {
2837
- renderOptions.target = serverTarget;
2871
+ message = 'Could not find a layer to render in. You may have passed a non-existing layer reference, or a detached element.';
2838
2872
  }
2839
- renderOptions.acceptLayer = this.response.acceptLayer;
2840
- renderOptions.dismissLayer = this.response.dismissLayer;
2841
- renderOptions.document = this.response.text;
2842
- if (!renderOptions.document) {
2843
- renderOptions.target = ':none';
2873
+ throw new up.CannotMatch(message);
2874
+ }
2875
+ seekPlan(fn) {
2876
+ for (let plan of this.getPlans()) {
2877
+ try {
2878
+ return fn(plan);
2879
+ }
2880
+ catch (error) {
2881
+ if (!(error instanceof up.CannotMatch)) {
2882
+ throw error;
2883
+ }
2884
+ }
2844
2885
  }
2845
- renderOptions.context = u.merge(renderOptions.context, this.response.context);
2846
- renderOptions.cspNonces = this.response.cspNonces;
2847
- renderOptions.time ?? (renderOptions.time = this.response.lastModified);
2848
- renderOptions.etag ?? (renderOptions.etag = this.response.etag);
2849
2886
  }
2850
2887
  },
2851
2888
  (() => {
2852
2889
  u.memoizeMethod(_a.prototype, [
2853
- 'getRequestAttrs',
2854
- 'loadedEventProps',
2890
+ 'getPlans',
2891
+ 'getResponseDoc',
2892
+ 'getPreflightProps',
2855
2893
  ]);
2856
2894
  })(),
2857
2895
  _a);
2858
2896
 
2859
2897
 
2860
2898
  /***/ }),
2861
- /* 33 */
2899
+ /* 34 */
2862
2900
  /***/ (() => {
2863
2901
 
2864
2902
  const u = up.util;
@@ -2969,7 +3007,7 @@ up.CompilerPass = class CompilerPass {
2969
3007
 
2970
3008
 
2971
3009
  /***/ }),
2972
- /* 34 */
3010
+ /* 35 */
2973
3011
  /***/ (() => {
2974
3012
 
2975
3013
  const u = up.util;
@@ -3080,7 +3118,7 @@ up.CSSTransition = class CSSTransition {
3080
3118
 
3081
3119
 
3082
3120
  /***/ }),
3083
- /* 35 */
3121
+ /* 36 */
3084
3122
  /***/ (() => {
3085
3123
 
3086
3124
  const u = up.util;
@@ -3122,7 +3160,7 @@ up.DestructorPass = class DestructorPass {
3122
3160
 
3123
3161
 
3124
3162
  /***/ }),
3125
- /* 36 */
3163
+ /* 37 */
3126
3164
  /***/ (() => {
3127
3165
 
3128
3166
  const u = up.util;
@@ -3221,7 +3259,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3221
3259
 
3222
3260
 
3223
3261
  /***/ }),
3224
- /* 37 */
3262
+ /* 38 */
3225
3263
  /***/ (() => {
3226
3264
 
3227
3265
  const u = up.util;
@@ -3323,7 +3361,7 @@ up.EventListener = class EventListener extends up.Record {
3323
3361
 
3324
3362
 
3325
3363
  /***/ }),
3326
- /* 38 */
3364
+ /* 39 */
3327
3365
  /***/ (() => {
3328
3366
 
3329
3367
  const u = up.util;
@@ -3395,7 +3433,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3395
3433
 
3396
3434
 
3397
3435
  /***/ }),
3398
- /* 39 */
3436
+ /* 40 */
3399
3437
  /***/ (() => {
3400
3438
 
3401
3439
  const u = up.util;
@@ -3511,7 +3549,7 @@ up.FieldWatcher = class FieldWatcher {
3511
3549
 
3512
3550
 
3513
3551
  /***/ }),
3514
- /* 40 */
3552
+ /* 41 */
3515
3553
  /***/ (() => {
3516
3554
 
3517
3555
  const u = up.util;
@@ -3685,7 +3723,7 @@ up.FormValidator = class FormValidator {
3685
3723
 
3686
3724
 
3687
3725
  /***/ }),
3688
- /* 41 */
3726
+ /* 42 */
3689
3727
  /***/ (() => {
3690
3728
 
3691
3729
  up.FocusCapsule = class FocusCapsule {
@@ -3715,7 +3753,7 @@ up.FocusCapsule = class FocusCapsule {
3715
3753
 
3716
3754
 
3717
3755
  /***/ }),
3718
- /* 42 */
3756
+ /* 43 */
3719
3757
  /***/ (() => {
3720
3758
 
3721
3759
  const u = up.util;
@@ -3779,7 +3817,7 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
3779
3817
 
3780
3818
 
3781
3819
  /***/ }),
3782
- /* 43 */
3820
+ /* 44 */
3783
3821
  /***/ (() => {
3784
3822
 
3785
3823
  const DESCENDANT_SELECTOR = /^([^ >+(]+) (.+)$/;
@@ -3822,7 +3860,7 @@ up.FragmentFinder = class FragmentFinder {
3822
3860
 
3823
3861
 
3824
3862
  /***/ }),
3825
- /* 44 */
3863
+ /* 45 */
3826
3864
  /***/ (() => {
3827
3865
 
3828
3866
  const u = up.util;
@@ -3906,7 +3944,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
3906
3944
 
3907
3945
 
3908
3946
  /***/ }),
3909
- /* 45 */
3947
+ /* 46 */
3910
3948
  /***/ (() => {
3911
3949
 
3912
3950
  const e = up.element;
@@ -4013,7 +4051,7 @@ up.FragmentPolling = class FragmentPolling {
4013
4051
 
4014
4052
 
4015
4053
  /***/ }),
4016
- /* 46 */
4054
+ /* 47 */
4017
4055
  /***/ (() => {
4018
4056
 
4019
4057
  const u = up.util;
@@ -4077,7 +4115,7 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4077
4115
 
4078
4116
 
4079
4117
  /***/ }),
4080
- /* 47 */
4118
+ /* 48 */
4081
4119
  /***/ (() => {
4082
4120
 
4083
4121
  const e = up.element;
@@ -4300,7 +4338,7 @@ up.Layer = class Layer extends up.Record {
4300
4338
 
4301
4339
 
4302
4340
  /***/ }),
4303
- /* 48 */
4341
+ /* 49 */
4304
4342
  /***/ (() => {
4305
4343
 
4306
4344
  const e = up.element;
@@ -4491,20 +4529,20 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4491
4529
  }
4492
4530
  return this.on(eventTypes, event => {
4493
4531
  event.preventDefault();
4494
- closeFn.call(this, event);
4532
+ closeFn.call(this, event, { response: event.response });
4495
4533
  });
4496
4534
  }
4497
- tryAcceptForLocation() {
4498
- this.tryCloseForLocation(this.acceptLocation, this.accept);
4535
+ tryAcceptForLocation(options) {
4536
+ this.tryCloseForLocation(this.acceptLocation, this.accept, options);
4499
4537
  }
4500
- tryDismissForLocation() {
4501
- this.tryCloseForLocation(this.dismissLocation, this.dismiss);
4538
+ tryDismissForLocation(options) {
4539
+ this.tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4502
4540
  }
4503
- tryCloseForLocation(urlPattern, closeFn) {
4541
+ tryCloseForLocation(urlPattern, closeFn, options) {
4504
4542
  let location, resolution;
4505
4543
  if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
4506
4544
  const closeValue = { ...resolution, location };
4507
- closeFn.call(this, closeValue);
4545
+ closeFn.call(this, closeValue, options);
4508
4546
  }
4509
4547
  }
4510
4548
  teardownHandlers() {
@@ -4575,7 +4613,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4575
4613
 
4576
4614
 
4577
4615
  /***/ }),
4578
- /* 49 */
4616
+ /* 50 */
4579
4617
  /***/ (() => {
4580
4618
 
4581
4619
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -4612,7 +4650,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
4612
4650
 
4613
4651
 
4614
4652
  /***/ }),
4615
- /* 50 */
4653
+ /* 51 */
4616
4654
  /***/ (() => {
4617
4655
 
4618
4656
  var _a;
@@ -4650,19 +4688,19 @@ up.Layer.OverlayWithViewport = (_a = class OverlayWithViewport extends up.Layer.
4650
4688
 
4651
4689
 
4652
4690
  /***/ }),
4653
- /* 51 */
4691
+ /* 52 */
4654
4692
  /***/ (() => {
4655
4693
 
4656
4694
  var _a;
4657
4695
  const e = up.element;
4658
4696
  up.Layer.Root = (_a = class Root extends up.Layer {
4659
- get element() {
4660
- return e.root;
4661
- }
4662
4697
  constructor(options) {
4663
4698
  super(options);
4664
4699
  this.setupHandlers();
4665
4700
  }
4701
+ get element() {
4702
+ return e.root;
4703
+ }
4666
4704
  getFirstSwappableElement() {
4667
4705
  return document.body;
4668
4706
  }
@@ -4696,7 +4734,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4696
4734
 
4697
4735
 
4698
4736
  /***/ }),
4699
- /* 52 */
4737
+ /* 53 */
4700
4738
  /***/ (() => {
4701
4739
 
4702
4740
  var _a;
@@ -4707,7 +4745,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
4707
4745
 
4708
4746
 
4709
4747
  /***/ }),
4710
- /* 53 */
4748
+ /* 54 */
4711
4749
  /***/ (() => {
4712
4750
 
4713
4751
  var _a;
@@ -4718,7 +4756,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
4718
4756
 
4719
4757
 
4720
4758
  /***/ }),
4721
- /* 54 */
4759
+ /* 55 */
4722
4760
  /***/ (() => {
4723
4761
 
4724
4762
  var _a;
@@ -4729,7 +4767,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
4729
4767
 
4730
4768
 
4731
4769
  /***/ }),
4732
- /* 55 */
4770
+ /* 56 */
4733
4771
  /***/ (() => {
4734
4772
 
4735
4773
  var _a;
@@ -4740,7 +4778,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
4740
4778
 
4741
4779
 
4742
4780
  /***/ }),
4743
- /* 56 */
4781
+ /* 57 */
4744
4782
  /***/ (() => {
4745
4783
 
4746
4784
  const u = up.util;
@@ -4830,7 +4868,7 @@ up.LayerLookup = class LayerLookup {
4830
4868
 
4831
4869
 
4832
4870
  /***/ }),
4833
- /* 57 */
4871
+ /* 58 */
4834
4872
  /***/ (() => {
4835
4873
 
4836
4874
  const u = up.util;
@@ -4943,7 +4981,7 @@ up.LayerStack = class LayerStack extends Array {
4943
4981
 
4944
4982
 
4945
4983
  /***/ }),
4946
- /* 58 */
4984
+ /* 59 */
4947
4985
  /***/ (() => {
4948
4986
 
4949
4987
  up.LinkFeedbackURLs = class LinkFeedbackURLs {
@@ -4974,7 +5012,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
4974
5012
 
4975
5013
 
4976
5014
  /***/ }),
4977
- /* 59 */
5015
+ /* 60 */
4978
5016
  /***/ (() => {
4979
5017
 
4980
5018
  const u = up.util;
@@ -5042,7 +5080,7 @@ up.LinkPreloader = class LinkPreloader {
5042
5080
 
5043
5081
 
5044
5082
  /***/ }),
5045
- /* 60 */
5083
+ /* 61 */
5046
5084
  /***/ (() => {
5047
5085
 
5048
5086
  const u = up.util;
@@ -5138,7 +5176,7 @@ up.MotionController = class MotionController {
5138
5176
 
5139
5177
 
5140
5178
  /***/ }),
5141
- /* 61 */
5179
+ /* 62 */
5142
5180
  /***/ (() => {
5143
5181
 
5144
5182
  const u = up.util;
@@ -5230,7 +5268,7 @@ up.NonceableCallback = class NonceableCallback {
5230
5268
 
5231
5269
 
5232
5270
  /***/ }),
5233
- /* 62 */
5271
+ /* 63 */
5234
5272
  /***/ (() => {
5235
5273
 
5236
5274
  const u = up.util;
@@ -5307,7 +5345,7 @@ up.OptionsParser = class OptionsParser {
5307
5345
 
5308
5346
 
5309
5347
  /***/ }),
5310
- /* 63 */
5348
+ /* 64 */
5311
5349
  /***/ (() => {
5312
5350
 
5313
5351
  const e = up.element;
@@ -5375,7 +5413,7 @@ up.OverlayFocus = class OverlayFocus {
5375
5413
 
5376
5414
 
5377
5415
  /***/ }),
5378
- /* 64 */
5416
+ /* 65 */
5379
5417
  /***/ (() => {
5380
5418
 
5381
5419
  const u = up.util;
@@ -5606,7 +5644,7 @@ up.Params = class Params {
5606
5644
 
5607
5645
 
5608
5646
  /***/ }),
5609
- /* 65 */
5647
+ /* 66 */
5610
5648
  /***/ (() => {
5611
5649
 
5612
5650
  const e = up.element;
@@ -5656,7 +5694,7 @@ up.ProgressBar = class ProgressBar {
5656
5694
 
5657
5695
 
5658
5696
  /***/ }),
5659
- /* 66 */
5697
+ /* 67 */
5660
5698
  /***/ (() => {
5661
5699
 
5662
5700
  const u = up.util;
@@ -5705,14 +5743,15 @@ up.RenderOptions = (function () {
5705
5743
  ]);
5706
5744
  const CONTENT_KEYS = [
5707
5745
  'url',
5746
+ 'response',
5708
5747
  'content',
5709
5748
  'fragment',
5710
- 'document'
5749
+ 'document',
5711
5750
  ];
5712
5751
  const LATE_KEYS = [
5713
5752
  'history',
5714
5753
  'focus',
5715
- 'scroll'
5754
+ 'scroll',
5716
5755
  ];
5717
5756
  function navigateDefaults(options) {
5718
5757
  if (options.navigate) {
@@ -5779,7 +5818,7 @@ up.RenderOptions = (function () {
5779
5818
 
5780
5819
 
5781
5820
  /***/ }),
5782
- /* 67 */
5821
+ /* 68 */
5783
5822
  /***/ (() => {
5784
5823
 
5785
5824
  up.RenderResult = class RenderResult extends up.Record {
@@ -5807,12 +5846,32 @@ up.RenderResult = class RenderResult extends up.Record {
5807
5846
 
5808
5847
 
5809
5848
  /***/ }),
5810
- /* 68 */
5849
+ /* 69 */
5811
5850
  /***/ (() => {
5812
5851
 
5813
5852
  var _a;
5814
5853
  const u = up.util;
5815
5854
  up.Request = (_a = class Request extends up.Record {
5855
+ constructor(options) {
5856
+ super(options);
5857
+ this.params = new up.Params(this.params);
5858
+ if (this.wrapMethod == null) {
5859
+ this.wrapMethod = up.network.config.wrapMethod;
5860
+ }
5861
+ this.normalize();
5862
+ if ((this.target || this.layer || this.origin) && !options.basic) {
5863
+ const layerLookupOptions = { origin: this.origin };
5864
+ this.layer = up.layer.get(this.layer, layerLookupOptions);
5865
+ this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5866
+ this.context || (this.context = this.layer.context || {});
5867
+ this.failContext || (this.failContext = this.failLayer.context || {});
5868
+ this.mode || (this.mode = this.layer.mode);
5869
+ this.failMode || (this.failMode = this.failLayer.mode);
5870
+ }
5871
+ this.deferred = u.newDeferred();
5872
+ this.badResponseTime ?? (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5873
+ this.addAutoHeaders();
5874
+ }
5816
5875
  keys() {
5817
5876
  return [
5818
5877
  'method',
@@ -5855,37 +5914,19 @@ up.Request = (_a = class Request extends up.Record {
5855
5914
  builtAt: new Date(),
5856
5915
  };
5857
5916
  }
5858
- constructor(options) {
5859
- super(options);
5860
- this.params = new up.Params(this.params);
5861
- if (this.wrapMethod == null) {
5862
- this.wrapMethod = up.network.config.wrapMethod;
5863
- }
5864
- this.normalize();
5865
- if ((this.target || this.layer || this.origin) && !options.basic) {
5866
- const layerLookupOptions = { origin: this.origin };
5867
- this.layer = up.layer.get(this.layer, layerLookupOptions);
5868
- this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5869
- this.context || (this.context = this.layer.context || {});
5870
- this.failContext || (this.failContext = this.failLayer.context || {});
5871
- this.mode || (this.mode = this.layer.mode);
5872
- this.failMode || (this.failMode = this.failLayer.mode);
5873
- }
5874
- this.deferred = u.newDeferred();
5875
- this.badResponseTime ?? (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5876
- this.addAutoHeaders();
5877
- }
5878
5917
  get xhr() {
5879
5918
  return this._xhr ?? (this._xhr = new XMLHttpRequest());
5880
5919
  }
5881
5920
  get fragments() {
5882
- if (!this._fragments && this.target) {
5921
+ if (this._fragments) {
5922
+ return this._fragments;
5923
+ }
5924
+ else if (this.target) {
5883
5925
  let steps = up.fragment.parseTargetSteps(this.target);
5884
5926
  let selectors = u.map(steps, 'selector');
5885
5927
  let lookupOpts = { origin: this.origin, layer: this.layer };
5886
- this._fragments = u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5928
+ return u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5887
5929
  }
5888
- return this._fragments;
5889
5930
  }
5890
5931
  set fragments(value) {
5891
5932
  this._fragments = value;
@@ -6142,7 +6183,7 @@ up.Request = (_a = class Request extends up.Record {
6142
6183
 
6143
6184
 
6144
6185
  /***/ }),
6145
- /* 69 */
6186
+ /* 70 */
6146
6187
  /***/ (() => {
6147
6188
 
6148
6189
  const u = up.util;
@@ -6232,6 +6273,7 @@ up.Request.Cache = class Cache {
6232
6273
  if (value instanceof up.Response) {
6233
6274
  if (options.force || this.isCacheCompatible(existingRequest, newRequest)) {
6234
6275
  newRequest.fromCache = true;
6276
+ value = u.variant(value, { request: newRequest });
6235
6277
  newRequest.respondWith(value);
6236
6278
  u.delegate(newRequest, ['expired', 'state'], () => existingRequest);
6237
6279
  }
@@ -6281,7 +6323,7 @@ up.Request.Cache = class Cache {
6281
6323
 
6282
6324
 
6283
6325
  /***/ }),
6284
- /* 70 */
6326
+ /* 71 */
6285
6327
  /***/ (() => {
6286
6328
 
6287
6329
  const u = up.util;
@@ -6389,7 +6431,7 @@ up.Request.Queue = class Queue {
6389
6431
 
6390
6432
 
6391
6433
  /***/ }),
6392
- /* 71 */
6434
+ /* 72 */
6393
6435
  /***/ (() => {
6394
6436
 
6395
6437
  const u = up.util;
@@ -6428,7 +6470,7 @@ up.Request.FormRenderer = class FormRenderer {
6428
6470
 
6429
6471
 
6430
6472
  /***/ }),
6431
- /* 72 */
6473
+ /* 73 */
6432
6474
  /***/ (() => {
6433
6475
 
6434
6476
  var _a;
@@ -6500,7 +6542,7 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6500
6542
 
6501
6543
 
6502
6544
  /***/ }),
6503
- /* 73 */
6545
+ /* 74 */
6504
6546
  /***/ (() => {
6505
6547
 
6506
6548
  const u = up.util;
@@ -6535,6 +6577,12 @@ up.Response = class Response extends up.Record {
6535
6577
  get ok() {
6536
6578
  return !u.evalOption(this.fail ?? up.network.config.fail, this);
6537
6579
  }
6580
+ get none() {
6581
+ return !this.text;
6582
+ }
6583
+ isCacheable() {
6584
+ return this.ok && !this.none;
6585
+ }
6538
6586
  header(name) {
6539
6587
  return this.headers[name] || this.xhr?.getResponseHeader(name);
6540
6588
  }
@@ -6575,7 +6623,7 @@ up.Response = class Response extends up.Record {
6575
6623
 
6576
6624
 
6577
6625
  /***/ }),
6578
- /* 74 */
6626
+ /* 75 */
6579
6627
  /***/ (() => {
6580
6628
 
6581
6629
  var _a;
@@ -6655,7 +6703,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
6655
6703
 
6656
6704
 
6657
6705
  /***/ }),
6658
- /* 75 */
6706
+ /* 76 */
6659
6707
  /***/ (() => {
6660
6708
 
6661
6709
  const e = up.element;
@@ -6749,7 +6797,7 @@ up.RevealMotion = class RevealMotion {
6749
6797
 
6750
6798
 
6751
6799
  /***/ }),
6752
- /* 76 */
6800
+ /* 77 */
6753
6801
  /***/ (() => {
6754
6802
 
6755
6803
  const u = up.util;
@@ -6790,7 +6838,7 @@ up.Selector = class Selector {
6790
6838
 
6791
6839
 
6792
6840
  /***/ }),
6793
- /* 77 */
6841
+ /* 78 */
6794
6842
  /***/ (() => {
6795
6843
 
6796
6844
  const u = up.util;
@@ -6910,7 +6958,7 @@ up.Tether = class Tether {
6910
6958
 
6911
6959
 
6912
6960
  /***/ }),
6913
- /* 78 */
6961
+ /* 79 */
6914
6962
  /***/ (() => {
6915
6963
 
6916
6964
  const u = up.util;
@@ -6990,7 +7038,7 @@ up.URLPattern = class URLPattern {
6990
7038
 
6991
7039
 
6992
7040
  /***/ }),
6993
- /* 79 */
7041
+ /* 80 */
6994
7042
  /***/ (() => {
6995
7043
 
6996
7044
  up.framework = (function () {
@@ -7074,7 +7122,7 @@ up.boot = up.framework.boot;
7074
7122
 
7075
7123
 
7076
7124
  /***/ }),
7077
- /* 80 */
7125
+ /* 81 */
7078
7126
  /***/ (() => {
7079
7127
 
7080
7128
  up.event = (function () {
@@ -7177,7 +7225,7 @@ up.emit = up.event.emit;
7177
7225
 
7178
7226
 
7179
7227
  /***/ }),
7180
- /* 81 */
7228
+ /* 82 */
7181
7229
  /***/ (() => {
7182
7230
 
7183
7231
  up.protocol = (function () {
@@ -7318,10 +7366,11 @@ up.protocol = (function () {
7318
7366
 
7319
7367
 
7320
7368
  /***/ }),
7321
- /* 82 */
7369
+ /* 83 */
7322
7370
  /***/ (() => {
7323
7371
 
7324
7372
  up.log = (function () {
7373
+ const u = up.util;
7325
7374
  const config = new up.LogConfig();
7326
7375
  function reset() {
7327
7376
  config.reset();
@@ -7339,13 +7388,11 @@ up.log = (function () {
7339
7388
  function printToStreamStyled(stream, trace, customStyles, message, ...args) {
7340
7389
  if (message) {
7341
7390
  if (config.format) {
7342
- args.unshift('color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;' + customStyles, '');
7343
- message = `%c${trace}%c ${message}`;
7391
+ console[stream](`%c${trace}%c ${message}`, 'color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;' + customStyles, '', ...args);
7344
7392
  }
7345
7393
  else {
7346
- message = `[${trace}] ${message}`;
7394
+ console[stream](`[${trace}] ${u.sprintf(message, ...args)}`);
7347
7395
  }
7348
- console[stream](message, ...args);
7349
7396
  }
7350
7397
  }
7351
7398
  function printUserEvent(event) {
@@ -7404,7 +7451,7 @@ up.warn = up.log.warn;
7404
7451
 
7405
7452
 
7406
7453
  /***/ }),
7407
- /* 83 */
7454
+ /* 84 */
7408
7455
  /***/ (() => {
7409
7456
 
7410
7457
  up.syntax = (function () {
@@ -7554,7 +7601,7 @@ up.hello = up.syntax.hello;
7554
7601
 
7555
7602
 
7556
7603
  /***/ }),
7557
- /* 84 */
7604
+ /* 85 */
7558
7605
  /***/ (() => {
7559
7606
 
7560
7607
  up.history = (function () {
@@ -7690,10 +7737,10 @@ up.history = (function () {
7690
7737
 
7691
7738
 
7692
7739
  /***/ }),
7693
- /* 85 */
7740
+ /* 86 */
7694
7741
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
7695
7742
 
7696
- __webpack_require__(86);
7743
+ __webpack_require__(87);
7697
7744
  const u = up.util;
7698
7745
  const e = up.element;
7699
7746
  up.fragment = (function () {
@@ -8220,7 +8267,7 @@ u.delegate(up, ['context'], () => up.layer.current);
8220
8267
 
8221
8268
 
8222
8269
  /***/ }),
8223
- /* 86 */
8270
+ /* 87 */
8224
8271
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8225
8272
 
8226
8273
  "use strict";
@@ -8229,10 +8276,10 @@ __webpack_require__.r(__webpack_exports__);
8229
8276
 
8230
8277
 
8231
8278
  /***/ }),
8232
- /* 87 */
8279
+ /* 88 */
8233
8280
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8234
8281
 
8235
- __webpack_require__(88);
8282
+ __webpack_require__(89);
8236
8283
  up.viewport = (function () {
8237
8284
  const u = up.util;
8238
8285
  const e = up.element;
@@ -8552,7 +8599,7 @@ up.reveal = up.viewport.reveal;
8552
8599
 
8553
8600
 
8554
8601
  /***/ }),
8555
- /* 88 */
8602
+ /* 89 */
8556
8603
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8557
8604
 
8558
8605
  "use strict";
@@ -8561,7 +8608,7 @@ __webpack_require__.r(__webpack_exports__);
8561
8608
 
8562
8609
 
8563
8610
  /***/ }),
8564
- /* 89 */
8611
+ /* 90 */
8565
8612
  /***/ (() => {
8566
8613
 
8567
8614
  up.motion = (function () {
@@ -8816,10 +8863,10 @@ up.animate = up.motion.animate;
8816
8863
 
8817
8864
 
8818
8865
  /***/ }),
8819
- /* 90 */
8866
+ /* 91 */
8820
8867
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8821
8868
 
8822
- __webpack_require__(91);
8869
+ __webpack_require__(92);
8823
8870
  const u = up.util;
8824
8871
  up.network = (function () {
8825
8872
  const config = new up.Config(() => ({
@@ -8887,19 +8934,19 @@ up.network = (function () {
8887
8934
  cache.put(request);
8888
8935
  request.onLoading = () => cache.put(request);
8889
8936
  }
8890
- u.always(request, function (response) {
8891
- let expireCache = response.expireCache ?? request.expireCache ?? u.evalOption(config.expireCache, request, response);
8937
+ u.always(request, function (responseOrError) {
8938
+ let expireCache = responseOrError.expireCache ?? request.expireCache ?? u.evalOption(config.expireCache, request, responseOrError);
8892
8939
  if (expireCache) {
8893
8940
  cache.expire(expireCache, { except: request });
8894
8941
  }
8895
- let evictCache = response.evictCache ?? request.evictCache ?? u.evalOption(config.evictCache, request, response);
8942
+ let evictCache = responseOrError.evictCache ?? request.evictCache ?? u.evalOption(config.evictCache, request, responseOrError);
8896
8943
  if (evictCache) {
8897
8944
  cache.evict(evictCache, { except: request });
8898
8945
  }
8899
8946
  if (cache.get(request)) {
8900
8947
  cache.put(request);
8901
8948
  }
8902
- if (!response.ok) {
8949
+ if (!responseOrError.isCacheable?.()) {
8903
8950
  cache.evict(request);
8904
8951
  }
8905
8952
  });
@@ -8923,7 +8970,7 @@ up.network = (function () {
8923
8970
  }
8924
8971
  function registerAliasForRedirect(request, response) {
8925
8972
  if (request.cache && response.url && request.url !== response.url) {
8926
- const newRequest = request.variant({
8973
+ const newRequest = u.variant(request, {
8927
8974
  method: response.method,
8928
8975
  url: response.url
8929
8976
  });
@@ -8962,7 +9009,7 @@ up.cache = up.network.cache;
8962
9009
 
8963
9010
 
8964
9011
  /***/ }),
8965
- /* 91 */
9012
+ /* 92 */
8966
9013
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8967
9014
 
8968
9015
  "use strict";
@@ -8971,10 +9018,10 @@ __webpack_require__.r(__webpack_exports__);
8971
9018
 
8972
9019
 
8973
9020
  /***/ }),
8974
- /* 92 */
9021
+ /* 93 */
8975
9022
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8976
9023
 
8977
- __webpack_require__(93);
9024
+ __webpack_require__(94);
8978
9025
  const u = up.util;
8979
9026
  const e = up.element;
8980
9027
  up.layer = (function () {
@@ -9118,7 +9165,7 @@ up.layer = (function () {
9118
9165
  return e.callbackAttr(link, attr, { exposedKeys: ['layer'] });
9119
9166
  }
9120
9167
  function closeCallbackAttr(link, attr) {
9121
- return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value'] });
9168
+ return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value', 'response'] });
9122
9169
  }
9123
9170
  function reset() {
9124
9171
  config.reset();
@@ -9215,7 +9262,7 @@ up.layer = (function () {
9215
9262
 
9216
9263
 
9217
9264
  /***/ }),
9218
- /* 93 */
9265
+ /* 94 */
9219
9266
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
9220
9267
 
9221
9268
  "use strict";
@@ -9224,10 +9271,10 @@ __webpack_require__.r(__webpack_exports__);
9224
9271
 
9225
9272
 
9226
9273
  /***/ }),
9227
- /* 94 */
9274
+ /* 95 */
9228
9275
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
9229
9276
 
9230
- __webpack_require__(95);
9277
+ __webpack_require__(96);
9231
9278
  up.link = (function () {
9232
9279
  const u = up.util;
9233
9280
  const e = up.element;
@@ -9235,7 +9282,7 @@ up.link = (function () {
9235
9282
  let lastMousedownTarget = null;
9236
9283
  const LINKS_WITH_LOCAL_HTML = ['a[up-content]', 'a[up-fragment]', 'a[up-document]'];
9237
9284
  const LINKS_WITH_REMOTE_HTML = ['a[href]', '[up-href]'];
9238
- const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]'];
9285
+ const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]', '[up-href]'];
9239
9286
  function combineFollowableSelectors(elementSelectors, attributeSelectors) {
9240
9287
  return u.flatMap(elementSelectors, elementSelector => attributeSelectors.map(attrSelector => elementSelector + attrSelector));
9241
9288
  }
@@ -9367,7 +9414,6 @@ up.link = (function () {
9367
9414
  parser.booleanOrString('transition');
9368
9415
  parser.string('easing');
9369
9416
  parser.number('duration');
9370
- up.migrate.parseFollowOptions?.(parser);
9371
9417
  if (!options.guardEvent) {
9372
9418
  options.guardEvent = up.event.build('up:link:follow', { log: 'Following link' });
9373
9419
  }
@@ -9515,14 +9561,15 @@ up.link = (function () {
9515
9561
  convertClicks,
9516
9562
  config,
9517
9563
  combineFollowableSelectors,
9518
- preloadSelector: fullPreloadSelector
9564
+ preloadSelector: fullPreloadSelector,
9565
+ followSelector: fullFollowSelector,
9519
9566
  };
9520
9567
  })();
9521
9568
  up.follow = up.link.follow;
9522
9569
 
9523
9570
 
9524
9571
  /***/ }),
9525
- /* 95 */
9572
+ /* 96 */
9526
9573
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
9527
9574
 
9528
9575
  "use strict";
@@ -9531,7 +9578,7 @@ __webpack_require__.r(__webpack_exports__);
9531
9578
 
9532
9579
 
9533
9580
  /***/ }),
9534
- /* 96 */
9581
+ /* 97 */
9535
9582
  /***/ (() => {
9536
9583
 
9537
9584
  up.form = (function () {
@@ -9546,7 +9593,7 @@ up.form = (function () {
9546
9593
  submitButtonSelectors: ['input[type=submit]', 'input[type=image]', 'button[type=submit]', 'button:not([type])'],
9547
9594
  watchInputEvents: ['input', 'change'],
9548
9595
  watchInputDelay: 0,
9549
- watchChangeEvents: (field) => field.matches('input[type=date]') ? ['blur'] : ['change'],
9596
+ watchChangeEvents: ['change'],
9550
9597
  }));
9551
9598
  function fullSubmitSelector() {
9552
9599
  return config.submitSelectors.join(',');
@@ -9914,6 +9961,7 @@ up.form = (function () {
9914
9961
  disable: disableContainer,
9915
9962
  group: findGroup,
9916
9963
  groupSolution: findGroupSolution,
9964
+ groupSelectors: getGroupSelectors,
9917
9965
  get: getForm,
9918
9966
  };
9919
9967
  })();
@@ -9924,7 +9972,7 @@ up.validate = up.form.validate;
9924
9972
 
9925
9973
 
9926
9974
  /***/ }),
9927
- /* 97 */
9975
+ /* 98 */
9928
9976
  /***/ (() => {
9929
9977
 
9930
9978
  up.feedback = (function () {
@@ -10041,7 +10089,7 @@ up.feedback = (function () {
10041
10089
 
10042
10090
 
10043
10091
  /***/ }),
10044
- /* 98 */
10092
+ /* 99 */
10045
10093
  /***/ (() => {
10046
10094
 
10047
10095
  up.radio = (function () {
@@ -10118,7 +10166,7 @@ up.radio = (function () {
10118
10166
 
10119
10167
 
10120
10168
  /***/ }),
10121
- /* 99 */
10169
+ /* 100 */
10122
10170
  /***/ (() => {
10123
10171
 
10124
10172
  (function () {
@@ -10267,15 +10315,16 @@ __webpack_require__(82);
10267
10315
  __webpack_require__(83);
10268
10316
  __webpack_require__(84);
10269
10317
  __webpack_require__(85);
10270
- __webpack_require__(87);
10271
- __webpack_require__(89);
10318
+ __webpack_require__(86);
10319
+ __webpack_require__(88);
10272
10320
  __webpack_require__(90);
10273
- __webpack_require__(92);
10274
- __webpack_require__(94);
10275
- __webpack_require__(96);
10321
+ __webpack_require__(91);
10322
+ __webpack_require__(93);
10323
+ __webpack_require__(95);
10276
10324
  __webpack_require__(97);
10277
10325
  __webpack_require__(98);
10278
10326
  __webpack_require__(99);
10327
+ __webpack_require__(100);
10279
10328
  up.framework.onEvaled();
10280
10329
 
10281
10330
  })();