unpoly-rails 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@
5
5
  /***/ (() => {
6
6
 
7
7
  window.up = {
8
- version: '3.1.1'
8
+ version: '3.2.0'
9
9
  };
10
10
 
11
11
 
@@ -722,6 +722,11 @@ up.util = (function () {
722
722
  let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0');
723
723
  return string.replace(/[^\x00-\x7F]/g, unicodeEscape);
724
724
  }
725
+ function variant(source, changes = {}) {
726
+ let variant = Object.create(source);
727
+ Object.assign(variant, changes);
728
+ return variant;
729
+ }
725
730
  return {
726
731
  parseURL,
727
732
  normalizeURL,
@@ -819,6 +824,7 @@ up.util = (function () {
819
824
  negate,
820
825
  memoizeMethod,
821
826
  safeStringifyJSON,
827
+ variant,
822
828
  };
823
829
  })();
824
830
 
@@ -1587,10 +1593,7 @@ up.Record = class Record {
1587
1593
  return u.pick(source, this.keys());
1588
1594
  }
1589
1595
  [u.copy.key]() {
1590
- return this.variant();
1591
- }
1592
- variant(changes = {}) {
1593
- return new this.constructor(u.merge(this.attributes(), changes));
1596
+ return u.variant(this);
1594
1597
  }
1595
1598
  [u.isEqual.key](other) {
1596
1599
  return (this.constructor === other.constructor) && u.isEqual(this.attributes(), other.attributes());
@@ -1762,9 +1765,6 @@ up.Change = class Change {
1762
1765
  constructor(options) {
1763
1766
  this.options = options;
1764
1767
  }
1765
- cannotMatch(reason) {
1766
- throw new up.CannotMatch(reason);
1767
- }
1768
1768
  execute() {
1769
1769
  throw new up.NotImplemented();
1770
1770
  }
@@ -1780,6 +1780,9 @@ up.Change = class Change {
1780
1780
  return newValue;
1781
1781
  }
1782
1782
  }
1783
+ deriveFailOptions() {
1784
+ return up.RenderOptions.deriveFailOptions(this.options);
1785
+ }
1783
1786
  };
1784
1787
 
1785
1788
 
@@ -1791,38 +1794,40 @@ const u = up.util;
1791
1794
  const e = up.element;
1792
1795
  up.Change.Addition = class Addition extends up.Change {
1793
1796
  constructor(options) {
1797
+ var _a;
1794
1798
  super(options);
1795
1799
  this.responseDoc = options.responseDoc;
1796
1800
  this.acceptLayer = options.acceptLayer;
1797
1801
  this.dismissLayer = options.dismissLayer;
1798
1802
  this.eventPlans = options.eventPlans || [];
1803
+ this.response = (_a = options.meta) === null || _a === void 0 ? void 0 : _a.response;
1799
1804
  }
1800
1805
  handleLayerChangeRequests() {
1801
1806
  if (this.layer.isOverlay()) {
1802
1807
  this.tryAcceptLayerFromServer();
1803
1808
  this.abortWhenLayerClosed();
1804
- this.layer.tryAcceptForLocation();
1809
+ this.layer.tryAcceptForLocation(this.responseOption());
1805
1810
  this.abortWhenLayerClosed();
1806
1811
  this.tryDismissLayerFromServer();
1807
1812
  this.abortWhenLayerClosed();
1808
- this.layer.tryDismissForLocation();
1813
+ this.layer.tryDismissForLocation(this.responseOption());
1809
1814
  this.abortWhenLayerClosed();
1810
1815
  }
1811
1816
  this.layer.asCurrent(() => {
1812
1817
  for (let eventPlan of this.eventPlans) {
1813
- up.emit(eventPlan);
1818
+ up.emit(Object.assign(Object.assign({}, eventPlan), this.responseOption()));
1814
1819
  this.abortWhenLayerClosed();
1815
1820
  }
1816
1821
  });
1817
1822
  }
1818
1823
  tryAcceptLayerFromServer() {
1819
1824
  if (u.isDefined(this.acceptLayer) && this.layer.isOverlay()) {
1820
- this.layer.accept(this.acceptLayer);
1825
+ this.layer.accept(this.acceptLayer, this.responseOption());
1821
1826
  }
1822
1827
  }
1823
1828
  tryDismissLayerFromServer() {
1824
1829
  if (u.isDefined(this.dismissLayer) && this.layer.isOverlay()) {
1825
- this.layer.dismiss(this.dismissLayer);
1830
+ this.layer.dismiss(this.dismissLayer, this.responseOption());
1826
1831
  }
1827
1832
  }
1828
1833
  abortWhenLayerClosed() {
@@ -1849,6 +1854,9 @@ up.Change.Addition = class Addition extends up.Change {
1849
1854
  this.setTime(options);
1850
1855
  this.setETag(options);
1851
1856
  }
1857
+ responseOption() {
1858
+ return { response: this.response };
1859
+ }
1852
1860
  };
1853
1861
 
1854
1862
 
@@ -1920,6 +1928,10 @@ up.RenderJob = (_a = class RenderJob {
1920
1928
  let onRequest = (request) => this.handleAbortOption(request);
1921
1929
  this.change = new up.Change.FromURL(Object.assign(Object.assign({}, this.options), { onRequest }));
1922
1930
  }
1931
+ else if (this.options.response) {
1932
+ this.change = new up.Change.FromResponse(this.options);
1933
+ this.handleAbortOption(null);
1934
+ }
1923
1935
  else {
1924
1936
  this.change = new up.Change.FromContent(this.options);
1925
1937
  this.handleAbortOption(null);
@@ -2073,7 +2085,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2073
2085
  this.content = responseDoc.select(this.target);
2074
2086
  }
2075
2087
  if (!this.content || this.baseLayer.isClosed()) {
2076
- throw this.cannotMatch();
2088
+ throw new up.CannotMatch();
2077
2089
  }
2078
2090
  onApplicable();
2079
2091
  up.puts('up.render()', `Opening element "${this.target}" in new overlay`);
@@ -2385,7 +2397,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2385
2397
  return true;
2386
2398
  }
2387
2399
  else if (!step.maybe) {
2388
- throw this.cannotMatch(`Could not find element "${this.target}" in current page`);
2400
+ throw new up.CannotMatch();
2389
2401
  }
2390
2402
  });
2391
2403
  this.resolveOldNesting();
@@ -2401,7 +2413,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2401
2413
  return true;
2402
2414
  }
2403
2415
  else if (!step.maybe) {
2404
- throw this.cannotMatch(`Could not find element "${this.target}" in server response`);
2416
+ throw new up.CannotMatch();
2405
2417
  }
2406
2418
  });
2407
2419
  this.resolveOldNesting();
@@ -2494,6 +2506,7 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2494
2506
  this.origin = options.origin;
2495
2507
  this.value = options.value;
2496
2508
  this.preventable = (_a = options.preventable) !== null && _a !== void 0 ? _a : true;
2509
+ this.response = options.response;
2497
2510
  }
2498
2511
  execute() {
2499
2512
  if (!this.layer.isOpen()) {
@@ -2535,7 +2548,8 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2535
2548
  return up.event.build(name, {
2536
2549
  layer: this.layer,
2537
2550
  value: this.value,
2538
- origin: this.origin
2551
+ origin: this.origin,
2552
+ response: this.response,
2539
2553
  });
2540
2554
  }
2541
2555
  handleFocus(formerParent) {
@@ -2552,152 +2566,6 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2552
2566
  /* 31 */
2553
2567
  /***/ (() => {
2554
2568
 
2555
- var _a;
2556
- const u = up.util;
2557
- up.Change.FromContent = (_a = class FromContent extends up.Change {
2558
- constructor(options) {
2559
- super(options);
2560
- this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2561
- this.origin = this.options.origin;
2562
- this.preview = this.options.preview;
2563
- this.mode = this.options.mode;
2564
- if (this.origin) {
2565
- this.originLayer = up.layer.get(this.origin);
2566
- }
2567
- }
2568
- isRenderableLayer(layer) {
2569
- return (layer === 'new') || layer.isOpen();
2570
- }
2571
- getPlans() {
2572
- var _a;
2573
- let plans = [];
2574
- if (this.options.fragment) {
2575
- (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2576
- }
2577
- this.expandIntoPlans(plans, this.layers, this.options.target);
2578
- this.expandIntoPlans(plans, this.layers, this.options.fallback);
2579
- return plans;
2580
- }
2581
- expandIntoPlans(plans, layers, targets) {
2582
- for (let layer of layers) {
2583
- for (let target of this.expandTargets(targets, layer)) {
2584
- const props = Object.assign(Object.assign({}, this.options), { target, layer, defaultPlacement: this.defaultPlacement() });
2585
- const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2586
- plans.push(change);
2587
- }
2588
- }
2589
- }
2590
- expandTargets(targets, layer) {
2591
- return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2592
- }
2593
- execute() {
2594
- if (this.options.preload) {
2595
- return Promise.resolve();
2596
- }
2597
- return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2598
- }
2599
- executePlan(matchedPlan) {
2600
- let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2601
- result.options = this.options;
2602
- return result;
2603
- }
2604
- onPlanApplicable(plan) {
2605
- let primaryPlan = this.getPlans()[0];
2606
- if (plan !== primaryPlan) {
2607
- up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2608
- }
2609
- }
2610
- getResponseDoc() {
2611
- var _a, _b;
2612
- if (this.preview)
2613
- return;
2614
- const docOptions = u.pick(this.options, [
2615
- 'target',
2616
- 'content',
2617
- 'fragment',
2618
- 'document',
2619
- 'html',
2620
- 'cspNonces',
2621
- 'origin',
2622
- ]);
2623
- (_b = (_a = up.migrate).handleResponseDocOptions) === null || _b === void 0 ? void 0 : _b.call(_a, docOptions);
2624
- if (this.defaultPlacement() === 'content') {
2625
- docOptions.target = this.firstExpandedTarget(docOptions.target);
2626
- }
2627
- return new up.ResponseDoc(docOptions);
2628
- }
2629
- defaultPlacement() {
2630
- if (!this.options.document && !this.options.fragment) {
2631
- return 'content';
2632
- }
2633
- }
2634
- firstExpandedTarget(target) {
2635
- return this.expandTargets(target || ':main', this.layers[0])[0];
2636
- }
2637
- getPreflightProps(opts = {}) {
2638
- const getPlanProps = plan => plan.getPreflightProps();
2639
- return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2640
- }
2641
- cannotMatchPreflightTarget() {
2642
- this.cannotMatchTarget('Could not find target in current page');
2643
- }
2644
- cannotMatchPostflightTarget() {
2645
- this.cannotMatchTarget('Could not find common target in current page and response');
2646
- }
2647
- cannotMatchTarget(reason) {
2648
- if (this.getPlans().length) {
2649
- const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2650
- const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2651
- up.fail(reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption);
2652
- }
2653
- else if (this.layers.length) {
2654
- if (this.options.failPrefixForced) {
2655
- up.fail('No target selector given for failed responses (https://unpoly.com/failed-responses)');
2656
- }
2657
- else {
2658
- up.fail('No target selector given');
2659
- }
2660
- }
2661
- else {
2662
- up.fail('Layer %o does not exist', this.options.layer);
2663
- }
2664
- }
2665
- seekPlan(fn) {
2666
- for (let plan of this.getPlans()) {
2667
- try {
2668
- return fn(plan);
2669
- }
2670
- catch (error) {
2671
- if (!(error instanceof up.CannotMatch)) {
2672
- throw error;
2673
- }
2674
- }
2675
- }
2676
- }
2677
- },
2678
- (() => {
2679
- u.memoizeMethod(_a.prototype, [
2680
- 'getPlans',
2681
- 'getResponseDoc',
2682
- 'getPreflightProps',
2683
- ]);
2684
- })(),
2685
- _a);
2686
-
2687
-
2688
- /***/ }),
2689
- /* 32 */
2690
- /***/ (function() {
2691
-
2692
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2693
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2694
- return new (P || (P = Promise))(function (resolve, reject) {
2695
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2696
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2697
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2698
- step((generator = generator.apply(thisArg, _arguments || [])).next());
2699
- });
2700
- };
2701
2569
  var _a;
2702
2570
  const u = up.util;
2703
2571
  up.Change.FromURL = (_a = class FromURL extends up.Change {
@@ -2723,9 +2591,6 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2723
2591
  }
2724
2592
  return u.always(this.request, responseOrError => this.onRequestSettled(responseOrError));
2725
2593
  }
2726
- deriveFailOptions() {
2727
- return up.RenderOptions.deriveFailOptions(this.options);
2728
- }
2729
2594
  newPageReason() {
2730
2595
  if (u.isCrossOrigin(this.options.url)) {
2731
2596
  return 'Loading cross-origin content in new page';
@@ -2755,25 +2620,102 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2755
2620
  }
2756
2621
  }
2757
2622
  onRequestSettledWithResponse(response) {
2623
+ return new up.Change.FromResponse(Object.assign(Object.assign({}, this.options), { response })).execute();
2624
+ }
2625
+ onRequestSettledWithError(error) {
2626
+ if (error instanceof up.Offline) {
2627
+ this.request.emit('up:fragment:offline', {
2628
+ callback: this.options.onOffline,
2629
+ renderOptions: this.options,
2630
+ retry: (retryOptions) => up.render(Object.assign(Object.assign({}, this.options), retryOptions)),
2631
+ log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
2632
+ });
2633
+ }
2634
+ throw error;
2635
+ }
2636
+ },
2637
+ (() => {
2638
+ u.memoizeMethod(_a.prototype, [
2639
+ 'getRequestAttrs',
2640
+ ]);
2641
+ })(),
2642
+ _a);
2643
+
2644
+
2645
+ /***/ }),
2646
+ /* 32 */
2647
+ /***/ (function() {
2648
+
2649
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2650
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2651
+ return new (P || (P = Promise))(function (resolve, reject) {
2652
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2653
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2654
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2655
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2656
+ });
2657
+ };
2658
+ var _a;
2659
+ const u = up.util;
2660
+ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2661
+ constructor(options) {
2662
+ super(options);
2663
+ this.response = options.response;
2664
+ this.request = this.response.request;
2665
+ }
2666
+ execute() {
2758
2667
  var _a;
2759
- this.response = response;
2760
2668
  if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2761
2669
  this.skip();
2762
2670
  }
2763
2671
  else {
2764
2672
  this.request.assertEmitted('up:fragment:loaded', Object.assign(Object.assign({}, this.loadedEventProps()), { callback: this.options.onLoaded, log: ['Loaded fragment from %s', this.response.description], skip: () => this.skip() }));
2765
2673
  }
2766
- let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !response.ok;
2674
+ let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !this.response.ok;
2767
2675
  if (fail) {
2768
2676
  throw this.updateContentFromResponse(this.deriveFailOptions());
2769
2677
  }
2770
2678
  return this.updateContentFromResponse(this.options);
2771
2679
  }
2772
- compilerPassMeta() {
2773
- return u.pick(this.loadedEventProps(), [
2774
- 'revalidating',
2775
- 'response'
2776
- ]);
2680
+ skip() {
2681
+ up.puts('up.render()', 'Skipping ' + this.response.description);
2682
+ this.options.target = ':none';
2683
+ this.options.failTarget = ':none';
2684
+ }
2685
+ updateContentFromResponse(finalRenderOptions) {
2686
+ if (finalRenderOptions.failPrefixForced) {
2687
+ up.puts('up.render()', 'Rendering failed response using fail-prefixed options (https://unpoly.com/failed-responses)');
2688
+ }
2689
+ this.augmentOptionsFromResponse(finalRenderOptions);
2690
+ finalRenderOptions.meta = this.compilerPassMeta();
2691
+ let result = new up.Change.FromContent(finalRenderOptions).execute();
2692
+ result.finished = this.finish(result, finalRenderOptions);
2693
+ return result;
2694
+ }
2695
+ finish(renderResult, originalRenderOptions) {
2696
+ return __awaiter(this, void 0, void 0, function* () {
2697
+ renderResult = yield renderResult.finished;
2698
+ if (up.fragment.shouldRevalidate(this.request, this.response, originalRenderOptions)) {
2699
+ renderResult = yield this.revalidate(renderResult, originalRenderOptions);
2700
+ }
2701
+ return renderResult;
2702
+ });
2703
+ }
2704
+ revalidate(renderResult, originalRenderOptions) {
2705
+ return __awaiter(this, void 0, void 0, function* () {
2706
+ let target = originalRenderOptions.target;
2707
+ if (/:(before|after)/.test(target)) {
2708
+ up.warn('up.render()', 'Cannot revalidate cache when prepending/appending (target %s)', target);
2709
+ }
2710
+ else {
2711
+ up.puts('up.render()', 'Revalidating cached response for target "%s"', target);
2712
+ let verifyResult = yield up.reload(renderResult.target, Object.assign(Object.assign({}, originalRenderOptions), { layer: renderResult.layer, onFinished: null, scroll: false, focus: 'keep', transition: false, cache: false, confirm: false, feedback: false, abort: false, expiredResponse: this.response }));
2713
+ if (!verifyResult.none) {
2714
+ renderResult = verifyResult;
2715
+ }
2716
+ }
2717
+ return renderResult;
2718
+ });
2777
2719
  }
2778
2720
  loadedEventProps() {
2779
2721
  const { expiredResponse } = this.options;
@@ -2785,105 +2727,197 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2785
2727
  expiredResponse,
2786
2728
  };
2787
2729
  }
2788
- onRequestSettledWithError(error) {
2789
- if (error instanceof up.Offline) {
2790
- this.request.emit('up:fragment:offline', {
2791
- callback: this.options.onOffline,
2792
- response: this.response,
2793
- renderOptions: this.options,
2794
- retry: (retryOptions) => up.render(Object.assign(Object.assign({}, this.options), retryOptions)),
2795
- log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
2796
- });
2730
+ compilerPassMeta() {
2731
+ return u.pick(this.loadedEventProps(), [
2732
+ 'revalidating',
2733
+ 'response'
2734
+ ]);
2735
+ }
2736
+ augmentOptionsFromResponse(renderOptions) {
2737
+ var _a, _b;
2738
+ const responseURL = this.response.url;
2739
+ let serverLocation = responseURL;
2740
+ let hash = this.request.hash;
2741
+ if (hash) {
2742
+ renderOptions.hash = hash;
2743
+ serverLocation += hash;
2744
+ }
2745
+ const isReloadable = (this.response.method === 'GET');
2746
+ if (isReloadable) {
2747
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2748
+ }
2749
+ else {
2750
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2751
+ renderOptions.history = !!renderOptions.location;
2752
+ }
2753
+ renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2754
+ renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2755
+ renderOptions.eventPlans = this.response.eventPlans;
2756
+ let serverTarget = this.response.target;
2757
+ if (serverTarget) {
2758
+ renderOptions.target = serverTarget;
2759
+ }
2760
+ renderOptions.acceptLayer = this.response.acceptLayer;
2761
+ renderOptions.dismissLayer = this.response.dismissLayer;
2762
+ renderOptions.document = this.response.text;
2763
+ if (this.response.none) {
2764
+ renderOptions.target = ':none';
2765
+ }
2766
+ renderOptions.context = u.merge(renderOptions.context, this.response.context);
2767
+ renderOptions.cspNonces = this.response.cspNonces;
2768
+ (_a = renderOptions.time) !== null && _a !== void 0 ? _a : (renderOptions.time = this.response.lastModified);
2769
+ (_b = renderOptions.etag) !== null && _b !== void 0 ? _b : (renderOptions.etag = this.response.etag);
2770
+ }
2771
+ },
2772
+ (() => {
2773
+ u.memoizeMethod(_a.prototype, [
2774
+ 'loadedEventProps',
2775
+ ]);
2776
+ })(),
2777
+ _a);
2778
+
2779
+
2780
+ /***/ }),
2781
+ /* 33 */
2782
+ /***/ (() => {
2783
+
2784
+ var _a;
2785
+ const u = up.util;
2786
+ up.Change.FromContent = (_a = class FromContent extends up.Change {
2787
+ constructor(options) {
2788
+ super(options);
2789
+ this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2790
+ this.origin = this.options.origin;
2791
+ this.preview = this.options.preview;
2792
+ this.mode = this.options.mode;
2793
+ if (this.origin) {
2794
+ this.originLayer = up.layer.get(this.origin);
2795
+ }
2796
+ }
2797
+ isRenderableLayer(layer) {
2798
+ return (layer === 'new') || layer.isOpen();
2799
+ }
2800
+ getPlans() {
2801
+ var _a;
2802
+ let plans = [];
2803
+ if (this.options.fragment) {
2804
+ (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2805
+ }
2806
+ this.expandIntoPlans(plans, this.layers, this.options.target);
2807
+ this.expandIntoPlans(plans, this.layers, this.options.fallback);
2808
+ return plans;
2809
+ }
2810
+ expandIntoPlans(plans, layers, targets) {
2811
+ for (let layer of layers) {
2812
+ for (let target of this.expandTargets(targets, layer)) {
2813
+ const props = Object.assign(Object.assign({}, this.options), { target, layer, defaultPlacement: this.defaultPlacement() });
2814
+ const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2815
+ plans.push(change);
2816
+ }
2817
+ }
2818
+ }
2819
+ expandTargets(targets, layer) {
2820
+ return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2821
+ }
2822
+ execute() {
2823
+ if (this.options.preload) {
2824
+ return Promise.resolve();
2825
+ }
2826
+ return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2827
+ }
2828
+ executePlan(matchedPlan) {
2829
+ let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2830
+ result.options = this.options;
2831
+ return result;
2832
+ }
2833
+ onPlanApplicable(plan) {
2834
+ let primaryPlan = this.getPlans()[0];
2835
+ if (plan !== primaryPlan) {
2836
+ up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2837
+ }
2838
+ }
2839
+ getResponseDoc() {
2840
+ var _a, _b;
2841
+ if (this.preview)
2842
+ return;
2843
+ const docOptions = u.pick(this.options, [
2844
+ 'target',
2845
+ 'content',
2846
+ 'fragment',
2847
+ 'document',
2848
+ 'html',
2849
+ 'cspNonces',
2850
+ 'origin',
2851
+ ]);
2852
+ (_b = (_a = up.migrate).handleResponseDocOptions) === null || _b === void 0 ? void 0 : _b.call(_a, docOptions);
2853
+ if (this.defaultPlacement() === 'content') {
2854
+ docOptions.target = this.firstExpandedTarget(docOptions.target);
2855
+ }
2856
+ return new up.ResponseDoc(docOptions);
2857
+ }
2858
+ defaultPlacement() {
2859
+ if (!this.options.document && !this.options.fragment) {
2860
+ return 'content';
2797
2861
  }
2798
- throw error;
2799
2862
  }
2800
- skip() {
2801
- up.puts('up.render()', 'Skipping ' + this.response.description);
2802
- this.options.target = ':none';
2803
- this.options.failTarget = ':none';
2863
+ firstExpandedTarget(target) {
2864
+ return this.expandTargets(target || ':main', this.layers[0])[0];
2804
2865
  }
2805
- updateContentFromResponse(finalRenderOptions) {
2806
- if (finalRenderOptions.failPrefixForced) {
2807
- up.puts('up.render()', 'Rendering failed response using fail-prefixed options (https://unpoly.com/failed-responses)');
2808
- }
2809
- this.augmentOptionsFromResponse(finalRenderOptions);
2810
- finalRenderOptions.meta = this.compilerPassMeta();
2811
- let result = new up.Change.FromContent(finalRenderOptions).execute();
2812
- result.finished = this.finish(result, finalRenderOptions);
2813
- return result;
2866
+ getPreflightProps(opts = {}) {
2867
+ const getPlanProps = plan => plan.getPreflightProps();
2868
+ return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2814
2869
  }
2815
- finish(renderResult, originalRenderOptions) {
2816
- return __awaiter(this, void 0, void 0, function* () {
2817
- renderResult = yield renderResult.finished;
2818
- if (up.fragment.shouldRevalidate(this.request, this.response, originalRenderOptions)) {
2819
- renderResult = yield this.revalidate(renderResult, originalRenderOptions);
2820
- }
2821
- return renderResult;
2822
- });
2870
+ cannotMatchPreflightTarget() {
2871
+ this.cannotMatchTarget('Could not find target in current page');
2823
2872
  }
2824
- revalidate(renderResult, originalRenderOptions) {
2825
- return __awaiter(this, void 0, void 0, function* () {
2826
- let target = originalRenderOptions.target;
2827
- if (/:(before|after)/.test(target)) {
2828
- up.warn('up.render()', 'Cannot revalidate cache when prepending/appending (target %s)', target);
2873
+ cannotMatchPostflightTarget() {
2874
+ this.cannotMatchTarget('Could not find common target in current page and response');
2875
+ }
2876
+ cannotMatchTarget(reason) {
2877
+ let message;
2878
+ if (this.getPlans().length) {
2879
+ const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2880
+ const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2881
+ message = [reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption];
2882
+ }
2883
+ else if (this.layers.length) {
2884
+ if (this.options.failPrefixForced) {
2885
+ message = 'No target selector given for failed responses (https://unpoly.com/failed-responses)';
2829
2886
  }
2830
2887
  else {
2831
- up.puts('up.render()', 'Revalidating cached response for target "%s"', target);
2832
- let verifyResult = yield up.reload(renderResult.target, Object.assign(Object.assign({}, originalRenderOptions), { layer: renderResult.layer, onFinished: null, scroll: false, focus: 'keep', transition: false, cache: false, confirm: false, feedback: false, abort: false, expiredResponse: this.response }));
2833
- if (!verifyResult.none) {
2834
- renderResult = verifyResult;
2835
- }
2888
+ message = 'No target selector given';
2836
2889
  }
2837
- return renderResult;
2838
- });
2839
- }
2840
- augmentOptionsFromResponse(renderOptions) {
2841
- var _a, _b;
2842
- const responseURL = this.response.url;
2843
- let serverLocation = responseURL;
2844
- let hash = this.request.hash;
2845
- if (hash) {
2846
- renderOptions.hash = hash;
2847
- serverLocation += hash;
2848
- }
2849
- const isReloadable = (this.response.method === 'GET');
2850
- if (isReloadable) {
2851
- renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2852
2890
  }
2853
2891
  else {
2854
- renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2855
- renderOptions.history = !!renderOptions.location;
2856
- }
2857
- renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2858
- renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2859
- renderOptions.eventPlans = this.response.eventPlans;
2860
- let serverTarget = this.response.target;
2861
- if (serverTarget) {
2862
- renderOptions.target = serverTarget;
2892
+ message = 'Could not find a layer to render in. You may have passed a non-existing layer reference, or a detached element.';
2863
2893
  }
2864
- renderOptions.acceptLayer = this.response.acceptLayer;
2865
- renderOptions.dismissLayer = this.response.dismissLayer;
2866
- renderOptions.document = this.response.text;
2867
- if (!renderOptions.document) {
2868
- renderOptions.target = ':none';
2894
+ throw new up.CannotMatch(message);
2895
+ }
2896
+ seekPlan(fn) {
2897
+ for (let plan of this.getPlans()) {
2898
+ try {
2899
+ return fn(plan);
2900
+ }
2901
+ catch (error) {
2902
+ if (!(error instanceof up.CannotMatch)) {
2903
+ throw error;
2904
+ }
2905
+ }
2869
2906
  }
2870
- renderOptions.context = u.merge(renderOptions.context, this.response.context);
2871
- renderOptions.cspNonces = this.response.cspNonces;
2872
- (_a = renderOptions.time) !== null && _a !== void 0 ? _a : (renderOptions.time = this.response.lastModified);
2873
- (_b = renderOptions.etag) !== null && _b !== void 0 ? _b : (renderOptions.etag = this.response.etag);
2874
2907
  }
2875
2908
  },
2876
2909
  (() => {
2877
2910
  u.memoizeMethod(_a.prototype, [
2878
- 'getRequestAttrs',
2879
- 'loadedEventProps',
2911
+ 'getPlans',
2912
+ 'getResponseDoc',
2913
+ 'getPreflightProps',
2880
2914
  ]);
2881
2915
  })(),
2882
2916
  _a);
2883
2917
 
2884
2918
 
2885
2919
  /***/ }),
2886
- /* 33 */
2920
+ /* 34 */
2887
2921
  /***/ (() => {
2888
2922
 
2889
2923
  const u = up.util;
@@ -2995,7 +3029,7 @@ up.CompilerPass = class CompilerPass {
2995
3029
 
2996
3030
 
2997
3031
  /***/ }),
2998
- /* 34 */
3032
+ /* 35 */
2999
3033
  /***/ (() => {
3000
3034
 
3001
3035
  const u = up.util;
@@ -3108,7 +3142,7 @@ up.CSSTransition = class CSSTransition {
3108
3142
 
3109
3143
 
3110
3144
  /***/ }),
3111
- /* 35 */
3145
+ /* 36 */
3112
3146
  /***/ (() => {
3113
3147
 
3114
3148
  const u = up.util;
@@ -3150,7 +3184,7 @@ up.DestructorPass = class DestructorPass {
3150
3184
 
3151
3185
 
3152
3186
  /***/ }),
3153
- /* 36 */
3187
+ /* 37 */
3154
3188
  /***/ (() => {
3155
3189
 
3156
3190
  const u = up.util;
@@ -3251,7 +3285,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3251
3285
 
3252
3286
 
3253
3287
  /***/ }),
3254
- /* 37 */
3288
+ /* 38 */
3255
3289
  /***/ (() => {
3256
3290
 
3257
3291
  const u = up.util;
@@ -3354,7 +3388,7 @@ up.EventListener = class EventListener extends up.Record {
3354
3388
 
3355
3389
 
3356
3390
  /***/ }),
3357
- /* 38 */
3391
+ /* 39 */
3358
3392
  /***/ (() => {
3359
3393
 
3360
3394
  const u = up.util;
@@ -3426,7 +3460,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3426
3460
 
3427
3461
 
3428
3462
  /***/ }),
3429
- /* 39 */
3463
+ /* 40 */
3430
3464
  /***/ (function() {
3431
3465
 
3432
3466
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3553,7 +3587,7 @@ up.FieldWatcher = class FieldWatcher {
3553
3587
 
3554
3588
 
3555
3589
  /***/ }),
3556
- /* 40 */
3590
+ /* 41 */
3557
3591
  /***/ (function() {
3558
3592
 
3559
3593
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3751,7 +3785,7 @@ up.FormValidator = class FormValidator {
3751
3785
 
3752
3786
 
3753
3787
  /***/ }),
3754
- /* 41 */
3788
+ /* 42 */
3755
3789
  /***/ (() => {
3756
3790
 
3757
3791
  up.FocusCapsule = class FocusCapsule {
@@ -3781,7 +3815,7 @@ up.FocusCapsule = class FocusCapsule {
3781
3815
 
3782
3816
 
3783
3817
  /***/ }),
3784
- /* 42 */
3818
+ /* 43 */
3785
3819
  /***/ (() => {
3786
3820
 
3787
3821
  const u = up.util;
@@ -3845,7 +3879,7 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
3845
3879
 
3846
3880
 
3847
3881
  /***/ }),
3848
- /* 43 */
3882
+ /* 44 */
3849
3883
  /***/ (() => {
3850
3884
 
3851
3885
  const DESCENDANT_SELECTOR = /^([^ >+(]+) (.+)$/;
@@ -3888,7 +3922,7 @@ up.FragmentFinder = class FragmentFinder {
3888
3922
 
3889
3923
 
3890
3924
  /***/ }),
3891
- /* 44 */
3925
+ /* 45 */
3892
3926
  /***/ (() => {
3893
3927
 
3894
3928
  const u = up.util;
@@ -3973,7 +4007,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
3973
4007
 
3974
4008
 
3975
4009
  /***/ }),
3976
- /* 45 */
4010
+ /* 46 */
3977
4011
  /***/ (() => {
3978
4012
 
3979
4013
  const e = up.element;
@@ -4081,7 +4115,7 @@ up.FragmentPolling = class FragmentPolling {
4081
4115
 
4082
4116
 
4083
4117
  /***/ }),
4084
- /* 46 */
4118
+ /* 47 */
4085
4119
  /***/ (() => {
4086
4120
 
4087
4121
  const u = up.util;
@@ -4145,7 +4179,7 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4145
4179
 
4146
4180
 
4147
4181
  /***/ }),
4148
- /* 47 */
4182
+ /* 48 */
4149
4183
  /***/ (() => {
4150
4184
 
4151
4185
  const e = up.element;
@@ -4368,7 +4402,7 @@ up.Layer = class Layer extends up.Record {
4368
4402
 
4369
4403
 
4370
4404
  /***/ }),
4371
- /* 48 */
4405
+ /* 49 */
4372
4406
  /***/ (() => {
4373
4407
 
4374
4408
  const e = up.element;
@@ -4560,20 +4594,20 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4560
4594
  }
4561
4595
  return this.on(eventTypes, event => {
4562
4596
  event.preventDefault();
4563
- closeFn.call(this, event);
4597
+ closeFn.call(this, event, { response: event.response });
4564
4598
  });
4565
4599
  }
4566
- tryAcceptForLocation() {
4567
- this.tryCloseForLocation(this.acceptLocation, this.accept);
4600
+ tryAcceptForLocation(options) {
4601
+ this.tryCloseForLocation(this.acceptLocation, this.accept, options);
4568
4602
  }
4569
- tryDismissForLocation() {
4570
- this.tryCloseForLocation(this.dismissLocation, this.dismiss);
4603
+ tryDismissForLocation(options) {
4604
+ this.tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4571
4605
  }
4572
- tryCloseForLocation(urlPattern, closeFn) {
4606
+ tryCloseForLocation(urlPattern, closeFn, options) {
4573
4607
  let location, resolution;
4574
4608
  if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
4575
4609
  const closeValue = Object.assign(Object.assign({}, resolution), { location });
4576
- closeFn.call(this, closeValue);
4610
+ closeFn.call(this, closeValue, options);
4577
4611
  }
4578
4612
  }
4579
4613
  teardownHandlers() {
@@ -4648,7 +4682,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4648
4682
 
4649
4683
 
4650
4684
  /***/ }),
4651
- /* 49 */
4685
+ /* 50 */
4652
4686
  /***/ (() => {
4653
4687
 
4654
4688
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -4685,7 +4719,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
4685
4719
 
4686
4720
 
4687
4721
  /***/ }),
4688
- /* 50 */
4722
+ /* 51 */
4689
4723
  /***/ (() => {
4690
4724
 
4691
4725
  var _a;
@@ -4723,7 +4757,7 @@ up.Layer.OverlayWithViewport = (_a = class OverlayWithViewport extends up.Layer.
4723
4757
 
4724
4758
 
4725
4759
  /***/ }),
4726
- /* 51 */
4760
+ /* 52 */
4727
4761
  /***/ (() => {
4728
4762
 
4729
4763
  var _a;
@@ -4769,7 +4803,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4769
4803
 
4770
4804
 
4771
4805
  /***/ }),
4772
- /* 52 */
4806
+ /* 53 */
4773
4807
  /***/ (() => {
4774
4808
 
4775
4809
  var _a;
@@ -4780,7 +4814,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
4780
4814
 
4781
4815
 
4782
4816
  /***/ }),
4783
- /* 53 */
4817
+ /* 54 */
4784
4818
  /***/ (() => {
4785
4819
 
4786
4820
  var _a;
@@ -4791,7 +4825,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
4791
4825
 
4792
4826
 
4793
4827
  /***/ }),
4794
- /* 54 */
4828
+ /* 55 */
4795
4829
  /***/ (() => {
4796
4830
 
4797
4831
  var _a;
@@ -4802,7 +4836,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
4802
4836
 
4803
4837
 
4804
4838
  /***/ }),
4805
- /* 55 */
4839
+ /* 56 */
4806
4840
  /***/ (() => {
4807
4841
 
4808
4842
  var _a;
@@ -4813,7 +4847,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
4813
4847
 
4814
4848
 
4815
4849
  /***/ }),
4816
- /* 56 */
4850
+ /* 57 */
4817
4851
  /***/ (() => {
4818
4852
 
4819
4853
  const u = up.util;
@@ -4903,7 +4937,7 @@ up.LayerLookup = class LayerLookup {
4903
4937
 
4904
4938
 
4905
4939
  /***/ }),
4906
- /* 57 */
4940
+ /* 58 */
4907
4941
  /***/ (() => {
4908
4942
 
4909
4943
  const u = up.util;
@@ -5016,7 +5050,7 @@ up.LayerStack = class LayerStack extends Array {
5016
5050
 
5017
5051
 
5018
5052
  /***/ }),
5019
- /* 58 */
5053
+ /* 59 */
5020
5054
  /***/ (() => {
5021
5055
 
5022
5056
  up.LinkFeedbackURLs = class LinkFeedbackURLs {
@@ -5047,7 +5081,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
5047
5081
 
5048
5082
 
5049
5083
  /***/ }),
5050
- /* 59 */
5084
+ /* 60 */
5051
5085
  /***/ (() => {
5052
5086
 
5053
5087
  const u = up.util;
@@ -5117,7 +5151,7 @@ up.LinkPreloader = class LinkPreloader {
5117
5151
 
5118
5152
 
5119
5153
  /***/ }),
5120
- /* 60 */
5154
+ /* 61 */
5121
5155
  /***/ (function() {
5122
5156
 
5123
5157
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -5226,7 +5260,7 @@ up.MotionController = class MotionController {
5226
5260
 
5227
5261
 
5228
5262
  /***/ }),
5229
- /* 61 */
5263
+ /* 62 */
5230
5264
  /***/ (() => {
5231
5265
 
5232
5266
  const u = up.util;
@@ -5318,7 +5352,7 @@ up.NonceableCallback = class NonceableCallback {
5318
5352
 
5319
5353
 
5320
5354
  /***/ }),
5321
- /* 62 */
5355
+ /* 63 */
5322
5356
  /***/ (() => {
5323
5357
 
5324
5358
  const u = up.util;
@@ -5396,7 +5430,7 @@ up.OptionsParser = class OptionsParser {
5396
5430
 
5397
5431
 
5398
5432
  /***/ }),
5399
- /* 63 */
5433
+ /* 64 */
5400
5434
  /***/ (() => {
5401
5435
 
5402
5436
  const e = up.element;
@@ -5464,7 +5498,7 @@ up.OverlayFocus = class OverlayFocus {
5464
5498
 
5465
5499
 
5466
5500
  /***/ }),
5467
- /* 64 */
5501
+ /* 65 */
5468
5502
  /***/ (() => {
5469
5503
 
5470
5504
  const u = up.util;
@@ -5695,7 +5729,7 @@ up.Params = class Params {
5695
5729
 
5696
5730
 
5697
5731
  /***/ }),
5698
- /* 65 */
5732
+ /* 66 */
5699
5733
  /***/ (() => {
5700
5734
 
5701
5735
  const e = up.element;
@@ -5745,7 +5779,7 @@ up.ProgressBar = class ProgressBar {
5745
5779
 
5746
5780
 
5747
5781
  /***/ }),
5748
- /* 66 */
5782
+ /* 67 */
5749
5783
  /***/ (() => {
5750
5784
 
5751
5785
  const u = up.util;
@@ -5794,14 +5828,15 @@ up.RenderOptions = (function () {
5794
5828
  ]);
5795
5829
  const CONTENT_KEYS = [
5796
5830
  'url',
5831
+ 'response',
5797
5832
  'content',
5798
5833
  'fragment',
5799
- 'document'
5834
+ 'document',
5800
5835
  ];
5801
5836
  const LATE_KEYS = [
5802
5837
  'history',
5803
5838
  'focus',
5804
- 'scroll'
5839
+ 'scroll',
5805
5840
  ];
5806
5841
  function navigateDefaults(options) {
5807
5842
  if (options.navigate) {
@@ -5861,7 +5896,7 @@ up.RenderOptions = (function () {
5861
5896
 
5862
5897
 
5863
5898
  /***/ }),
5864
- /* 67 */
5899
+ /* 68 */
5865
5900
  /***/ (() => {
5866
5901
 
5867
5902
  up.RenderResult = class RenderResult extends up.Record {
@@ -5889,7 +5924,7 @@ up.RenderResult = class RenderResult extends up.Record {
5889
5924
 
5890
5925
 
5891
5926
  /***/ }),
5892
- /* 68 */
5927
+ /* 69 */
5893
5928
  /***/ (() => {
5894
5929
 
5895
5930
  var _a;
@@ -5963,13 +5998,15 @@ up.Request = (_a = class Request extends up.Record {
5963
5998
  return (_a = this._xhr) !== null && _a !== void 0 ? _a : (this._xhr = new XMLHttpRequest());
5964
5999
  }
5965
6000
  get fragments() {
5966
- if (!this._fragments && this.target) {
6001
+ if (this._fragments) {
6002
+ return this._fragments;
6003
+ }
6004
+ else if (this.target) {
5967
6005
  let steps = up.fragment.parseTargetSteps(this.target);
5968
6006
  let selectors = u.map(steps, 'selector');
5969
6007
  let lookupOpts = { origin: this.origin, layer: this.layer };
5970
- this._fragments = u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
6008
+ return u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5971
6009
  }
5972
- return this._fragments;
5973
6010
  }
5974
6011
  set fragments(value) {
5975
6012
  this._fragments = value;
@@ -6230,7 +6267,7 @@ up.Request = (_a = class Request extends up.Record {
6230
6267
 
6231
6268
 
6232
6269
  /***/ }),
6233
- /* 69 */
6270
+ /* 70 */
6234
6271
  /***/ (function() {
6235
6272
 
6236
6273
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -6333,6 +6370,7 @@ up.Request.Cache = class Cache {
6333
6370
  if (value instanceof up.Response) {
6334
6371
  if (options.force || this.isCacheCompatible(existingRequest, newRequest)) {
6335
6372
  newRequest.fromCache = true;
6373
+ value = u.variant(value, { request: newRequest });
6336
6374
  newRequest.respondWith(value);
6337
6375
  u.delegate(newRequest, ['expired', 'state'], () => existingRequest);
6338
6376
  }
@@ -6383,7 +6421,7 @@ up.Request.Cache = class Cache {
6383
6421
 
6384
6422
 
6385
6423
  /***/ }),
6386
- /* 70 */
6424
+ /* 71 */
6387
6425
  /***/ (() => {
6388
6426
 
6389
6427
  const u = up.util;
@@ -6492,7 +6530,7 @@ up.Request.Queue = class Queue {
6492
6530
 
6493
6531
 
6494
6532
  /***/ }),
6495
- /* 71 */
6533
+ /* 72 */
6496
6534
  /***/ (() => {
6497
6535
 
6498
6536
  const u = up.util;
@@ -6531,7 +6569,7 @@ up.Request.FormRenderer = class FormRenderer {
6531
6569
 
6532
6570
 
6533
6571
  /***/ }),
6534
- /* 72 */
6572
+ /* 73 */
6535
6573
  /***/ (() => {
6536
6574
 
6537
6575
  var _a;
@@ -6603,7 +6641,7 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6603
6641
 
6604
6642
 
6605
6643
  /***/ }),
6606
- /* 73 */
6644
+ /* 74 */
6607
6645
  /***/ (() => {
6608
6646
 
6609
6647
  const u = up.util;
@@ -6639,6 +6677,12 @@ up.Response = class Response extends up.Record {
6639
6677
  var _a;
6640
6678
  return !u.evalOption((_a = this.fail) !== null && _a !== void 0 ? _a : up.network.config.fail, this);
6641
6679
  }
6680
+ get none() {
6681
+ return !this.text;
6682
+ }
6683
+ isCacheable() {
6684
+ return this.ok && !this.none;
6685
+ }
6642
6686
  header(name) {
6643
6687
  var _a;
6644
6688
  return this.headers[name] || ((_a = this.xhr) === null || _a === void 0 ? void 0 : _a.getResponseHeader(name));
@@ -6680,7 +6724,7 @@ up.Response = class Response extends up.Record {
6680
6724
 
6681
6725
 
6682
6726
  /***/ }),
6683
- /* 74 */
6727
+ /* 75 */
6684
6728
  /***/ (() => {
6685
6729
 
6686
6730
  var _a;
@@ -6761,7 +6805,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
6761
6805
 
6762
6806
 
6763
6807
  /***/ }),
6764
- /* 75 */
6808
+ /* 76 */
6765
6809
  /***/ (() => {
6766
6810
 
6767
6811
  const e = up.element;
@@ -6856,7 +6900,7 @@ up.RevealMotion = class RevealMotion {
6856
6900
 
6857
6901
 
6858
6902
  /***/ }),
6859
- /* 76 */
6903
+ /* 77 */
6860
6904
  /***/ (() => {
6861
6905
 
6862
6906
  const u = up.util;
@@ -6897,7 +6941,7 @@ up.Selector = class Selector {
6897
6941
 
6898
6942
 
6899
6943
  /***/ }),
6900
- /* 77 */
6944
+ /* 78 */
6901
6945
  /***/ (() => {
6902
6946
 
6903
6947
  const u = up.util;
@@ -7018,7 +7062,7 @@ up.Tether = class Tether {
7018
7062
 
7019
7063
 
7020
7064
  /***/ }),
7021
- /* 78 */
7065
+ /* 79 */
7022
7066
  /***/ (() => {
7023
7067
 
7024
7068
  const u = up.util;
@@ -7099,7 +7143,7 @@ up.URLPattern = class URLPattern {
7099
7143
 
7100
7144
 
7101
7145
  /***/ }),
7102
- /* 79 */
7146
+ /* 80 */
7103
7147
  /***/ (() => {
7104
7148
 
7105
7149
  up.framework = (function () {
@@ -7183,7 +7227,7 @@ up.boot = up.framework.boot;
7183
7227
 
7184
7228
 
7185
7229
  /***/ }),
7186
- /* 80 */
7230
+ /* 81 */
7187
7231
  /***/ (() => {
7188
7232
 
7189
7233
  up.event = (function () {
@@ -7286,7 +7330,7 @@ up.emit = up.event.emit;
7286
7330
 
7287
7331
 
7288
7332
  /***/ }),
7289
- /* 81 */
7333
+ /* 82 */
7290
7334
  /***/ (() => {
7291
7335
 
7292
7336
  up.protocol = (function () {
@@ -7429,7 +7473,7 @@ up.protocol = (function () {
7429
7473
 
7430
7474
 
7431
7475
  /***/ }),
7432
- /* 82 */
7476
+ /* 83 */
7433
7477
  /***/ (() => {
7434
7478
 
7435
7479
  up.log = (function () {
@@ -7514,7 +7558,7 @@ up.warn = up.log.warn;
7514
7558
 
7515
7559
 
7516
7560
  /***/ }),
7517
- /* 83 */
7561
+ /* 84 */
7518
7562
  /***/ (() => {
7519
7563
 
7520
7564
  up.syntax = (function () {
@@ -7660,7 +7704,7 @@ up.hello = up.syntax.hello;
7660
7704
 
7661
7705
 
7662
7706
  /***/ }),
7663
- /* 84 */
7707
+ /* 85 */
7664
7708
  /***/ (() => {
7665
7709
 
7666
7710
  up.history = (function () {
@@ -7797,10 +7841,10 @@ up.history = (function () {
7797
7841
 
7798
7842
 
7799
7843
  /***/ }),
7800
- /* 85 */
7844
+ /* 86 */
7801
7845
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
7802
7846
 
7803
- __webpack_require__(86);
7847
+ __webpack_require__(87);
7804
7848
  const u = up.util;
7805
7849
  const e = up.element;
7806
7850
  up.fragment = (function () {
@@ -8328,16 +8372,16 @@ u.delegate(up, ['context'], () => up.layer.current);
8328
8372
 
8329
8373
 
8330
8374
  /***/ }),
8331
- /* 86 */
8375
+ /* 87 */
8332
8376
  /***/ (() => {
8333
8377
 
8334
8378
 
8335
8379
 
8336
8380
  /***/ }),
8337
- /* 87 */
8381
+ /* 88 */
8338
8382
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8339
8383
 
8340
- __webpack_require__(88);
8384
+ __webpack_require__(89);
8341
8385
  up.viewport = (function () {
8342
8386
  const u = up.util;
8343
8387
  const e = up.element;
@@ -8659,13 +8703,13 @@ up.reveal = up.viewport.reveal;
8659
8703
 
8660
8704
 
8661
8705
  /***/ }),
8662
- /* 88 */
8706
+ /* 89 */
8663
8707
  /***/ (() => {
8664
8708
 
8665
8709
 
8666
8710
 
8667
8711
  /***/ }),
8668
- /* 89 */
8712
+ /* 90 */
8669
8713
  /***/ (function() {
8670
8714
 
8671
8715
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -8931,10 +8975,10 @@ up.animate = up.motion.animate;
8931
8975
 
8932
8976
 
8933
8977
  /***/ }),
8934
- /* 90 */
8978
+ /* 91 */
8935
8979
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8936
8980
 
8937
- __webpack_require__(91);
8981
+ __webpack_require__(92);
8938
8982
  const u = up.util;
8939
8983
  up.network = (function () {
8940
8984
  const config = new up.Config(() => ({
@@ -9003,20 +9047,20 @@ up.network = (function () {
9003
9047
  cache.put(request);
9004
9048
  request.onLoading = () => cache.put(request);
9005
9049
  }
9006
- u.always(request, function (response) {
9007
- var _a, _b, _c, _d;
9008
- let expireCache = (_b = (_a = response.expireCache) !== null && _a !== void 0 ? _a : request.expireCache) !== null && _b !== void 0 ? _b : u.evalOption(config.expireCache, request, response);
9050
+ u.always(request, function (responseOrError) {
9051
+ var _a, _b, _c, _d, _e;
9052
+ let expireCache = (_b = (_a = responseOrError.expireCache) !== null && _a !== void 0 ? _a : request.expireCache) !== null && _b !== void 0 ? _b : u.evalOption(config.expireCache, request, responseOrError);
9009
9053
  if (expireCache) {
9010
9054
  cache.expire(expireCache, { except: request });
9011
9055
  }
9012
- let evictCache = (_d = (_c = response.evictCache) !== null && _c !== void 0 ? _c : request.evictCache) !== null && _d !== void 0 ? _d : u.evalOption(config.evictCache, request, response);
9056
+ let evictCache = (_d = (_c = responseOrError.evictCache) !== null && _c !== void 0 ? _c : request.evictCache) !== null && _d !== void 0 ? _d : u.evalOption(config.evictCache, request, responseOrError);
9013
9057
  if (evictCache) {
9014
9058
  cache.evict(evictCache, { except: request });
9015
9059
  }
9016
9060
  if (cache.get(request)) {
9017
9061
  cache.put(request);
9018
9062
  }
9019
- if (!response.ok) {
9063
+ if (!((_e = responseOrError.isCacheable) === null || _e === void 0 ? void 0 : _e.call(responseOrError))) {
9020
9064
  cache.evict(request);
9021
9065
  }
9022
9066
  });
@@ -9041,7 +9085,7 @@ up.network = (function () {
9041
9085
  }
9042
9086
  function registerAliasForRedirect(request, response) {
9043
9087
  if (request.cache && response.url && request.url !== response.url) {
9044
- const newRequest = request.variant({
9088
+ const newRequest = u.variant(request, {
9045
9089
  method: response.method,
9046
9090
  url: response.url
9047
9091
  });
@@ -9080,13 +9124,13 @@ up.cache = up.network.cache;
9080
9124
 
9081
9125
 
9082
9126
  /***/ }),
9083
- /* 91 */
9127
+ /* 92 */
9084
9128
  /***/ (() => {
9085
9129
 
9086
9130
 
9087
9131
 
9088
9132
  /***/ }),
9089
- /* 92 */
9133
+ /* 93 */
9090
9134
  /***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
9091
9135
 
9092
9136
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -9098,7 +9142,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9098
9142
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9099
9143
  });
9100
9144
  };
9101
- __webpack_require__(93);
9145
+ __webpack_require__(94);
9102
9146
  const u = up.util;
9103
9147
  const e = up.element;
9104
9148
  up.layer = (function () {
@@ -9244,7 +9288,7 @@ up.layer = (function () {
9244
9288
  return e.callbackAttr(link, attr, { exposedKeys: ['layer'] });
9245
9289
  }
9246
9290
  function closeCallbackAttr(link, attr) {
9247
- return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value'] });
9291
+ return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value', 'response'] });
9248
9292
  }
9249
9293
  function reset() {
9250
9294
  config.reset();
@@ -9339,16 +9383,16 @@ up.layer = (function () {
9339
9383
 
9340
9384
 
9341
9385
  /***/ }),
9342
- /* 93 */
9386
+ /* 94 */
9343
9387
  /***/ (() => {
9344
9388
 
9345
9389
 
9346
9390
 
9347
9391
  /***/ }),
9348
- /* 94 */
9392
+ /* 95 */
9349
9393
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
9350
9394
 
9351
- __webpack_require__(95);
9395
+ __webpack_require__(96);
9352
9396
  up.link = (function () {
9353
9397
  const u = up.util;
9354
9398
  const e = up.element;
@@ -9356,7 +9400,7 @@ up.link = (function () {
9356
9400
  let lastMousedownTarget = null;
9357
9401
  const LINKS_WITH_LOCAL_HTML = ['a[up-content]', 'a[up-fragment]', 'a[up-document]'];
9358
9402
  const LINKS_WITH_REMOTE_HTML = ['a[href]', '[up-href]'];
9359
- const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]'];
9403
+ const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]', '[up-href]'];
9360
9404
  function combineFollowableSelectors(elementSelectors, attributeSelectors) {
9361
9405
  return u.flatMap(elementSelectors, elementSelector => attributeSelectors.map(attrSelector => elementSelector + attrSelector));
9362
9406
  }
@@ -9638,13 +9682,13 @@ up.follow = up.link.follow;
9638
9682
 
9639
9683
 
9640
9684
  /***/ }),
9641
- /* 95 */
9685
+ /* 96 */
9642
9686
  /***/ (() => {
9643
9687
 
9644
9688
 
9645
9689
 
9646
9690
  /***/ }),
9647
- /* 96 */
9691
+ /* 97 */
9648
9692
  /***/ (() => {
9649
9693
 
9650
9694
  up.form = (function () {
@@ -9659,7 +9703,7 @@ up.form = (function () {
9659
9703
  submitButtonSelectors: ['input[type=submit]', 'input[type=image]', 'button[type=submit]', 'button:not([type])'],
9660
9704
  watchInputEvents: ['input', 'change'],
9661
9705
  watchInputDelay: 0,
9662
- watchChangeEvents: (field) => field.matches('input[type=date]') ? ['blur'] : ['change'],
9706
+ watchChangeEvents: ['change'],
9663
9707
  }));
9664
9708
  function fullSubmitSelector() {
9665
9709
  return config.submitSelectors.join(',');
@@ -10040,7 +10084,7 @@ up.validate = up.form.validate;
10040
10084
 
10041
10085
 
10042
10086
  /***/ }),
10043
- /* 97 */
10087
+ /* 98 */
10044
10088
  /***/ (() => {
10045
10089
 
10046
10090
  up.feedback = (function () {
@@ -10157,7 +10201,7 @@ up.feedback = (function () {
10157
10201
 
10158
10202
 
10159
10203
  /***/ }),
10160
- /* 98 */
10204
+ /* 99 */
10161
10205
  /***/ (() => {
10162
10206
 
10163
10207
  up.radio = (function () {
@@ -10235,7 +10279,7 @@ up.radio = (function () {
10235
10279
 
10236
10280
 
10237
10281
  /***/ }),
10238
- /* 99 */
10282
+ /* 100 */
10239
10283
  /***/ (() => {
10240
10284
 
10241
10285
  (function () {
@@ -10373,15 +10417,16 @@ __webpack_require__(82);
10373
10417
  __webpack_require__(83);
10374
10418
  __webpack_require__(84);
10375
10419
  __webpack_require__(85);
10376
- __webpack_require__(87);
10377
- __webpack_require__(89);
10420
+ __webpack_require__(86);
10421
+ __webpack_require__(88);
10378
10422
  __webpack_require__(90);
10379
- __webpack_require__(92);
10380
- __webpack_require__(94);
10381
- __webpack_require__(96);
10423
+ __webpack_require__(91);
10424
+ __webpack_require__(93);
10425
+ __webpack_require__(95);
10382
10426
  __webpack_require__(97);
10383
10427
  __webpack_require__(98);
10384
10428
  __webpack_require__(99);
10429
+ __webpack_require__(100);
10385
10430
  up.framework.onEvaled();
10386
10431
 
10387
10432
  })();