unpoly-rails 3.1.1 → 3.2.1

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.1'
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
 
@@ -828,10 +834,6 @@ up.util = (function () {
828
834
  /***/ (() => {
829
835
 
830
836
  up.error = (function () {
831
- function emitGlobal(error) {
832
- const { message } = error;
833
- up.emit(window, 'error', { message, error, log: false });
834
- }
835
837
  function fail(...args) {
836
838
  throw new up.Error(args);
837
839
  }
@@ -839,17 +841,27 @@ up.error = (function () {
839
841
  return (typeof error !== 'object') || ((error.name !== 'AbortError') && !(error instanceof up.RenderResult) && !(error instanceof up.Response));
840
842
  }
841
843
  function muteUncriticalRejection(promise) {
842
- return promise.catch(function (reason) {
843
- if (isCritical(reason)) {
844
- throw reason;
845
- }
846
- });
844
+ return promise.catch(rethrowCritical);
845
+ }
846
+ function muteUncriticalSync(block) {
847
+ try {
848
+ return block();
849
+ }
850
+ catch (e) {
851
+ rethrowCritical(e);
852
+ }
853
+ }
854
+ function rethrowCritical(value) {
855
+ if (isCritical(value)) {
856
+ throw value;
857
+ }
847
858
  }
848
859
  return {
849
860
  fail,
850
- emitGlobal,
861
+ rethrowCritical,
851
862
  isCritical,
852
863
  muteUncriticalRejection,
864
+ muteUncriticalSync,
853
865
  };
854
866
  })();
855
867
  up.fail = up.error.fail;
@@ -933,7 +945,7 @@ up.element = (function () {
933
945
  }
934
946
  function isInSubtree(root, selectorOrElement) {
935
947
  const element = getOne(selectorOrElement);
936
- return root.contains(element);
948
+ return Node.prototype.contains.call(root, element);
937
949
  }
938
950
  function ancestor(element, selector) {
939
951
  let parentElement = element.parentElement;
@@ -1176,7 +1188,7 @@ up.element = (function () {
1176
1188
  }
1177
1189
  }
1178
1190
  function classSelector(klass) {
1179
- klass = klass.replace(/:/g, '\\:');
1191
+ klass = klass.replace(/[^\w-]/g, '\\$&');
1180
1192
  return `.${klass}`;
1181
1193
  }
1182
1194
  function createBrokenDocumentFromHTML(html) {
@@ -1587,10 +1599,7 @@ up.Record = class Record {
1587
1599
  return u.pick(source, this.keys());
1588
1600
  }
1589
1601
  [u.copy.key]() {
1590
- return this.variant();
1591
- }
1592
- variant(changes = {}) {
1593
- return new this.constructor(u.merge(this.attributes(), changes));
1602
+ return u.variant(this);
1594
1603
  }
1595
1604
  [u.isEqual.key](other) {
1596
1605
  return (this.constructor === other.constructor) && u.isEqual(this.attributes(), other.attributes());
@@ -1762,9 +1771,6 @@ up.Change = class Change {
1762
1771
  constructor(options) {
1763
1772
  this.options = options;
1764
1773
  }
1765
- cannotMatch(reason) {
1766
- throw new up.CannotMatch(reason);
1767
- }
1768
1774
  execute() {
1769
1775
  throw new up.NotImplemented();
1770
1776
  }
@@ -1780,6 +1786,9 @@ up.Change = class Change {
1780
1786
  return newValue;
1781
1787
  }
1782
1788
  }
1789
+ deriveFailOptions() {
1790
+ return up.RenderOptions.deriveFailOptions(this.options);
1791
+ }
1783
1792
  };
1784
1793
 
1785
1794
 
@@ -1791,38 +1800,40 @@ const u = up.util;
1791
1800
  const e = up.element;
1792
1801
  up.Change.Addition = class Addition extends up.Change {
1793
1802
  constructor(options) {
1803
+ var _a;
1794
1804
  super(options);
1795
1805
  this.responseDoc = options.responseDoc;
1796
1806
  this.acceptLayer = options.acceptLayer;
1797
1807
  this.dismissLayer = options.dismissLayer;
1798
1808
  this.eventPlans = options.eventPlans || [];
1809
+ this.response = (_a = options.meta) === null || _a === void 0 ? void 0 : _a.response;
1799
1810
  }
1800
1811
  handleLayerChangeRequests() {
1801
1812
  if (this.layer.isOverlay()) {
1802
1813
  this.tryAcceptLayerFromServer();
1803
1814
  this.abortWhenLayerClosed();
1804
- this.layer.tryAcceptForLocation();
1815
+ this.layer.tryAcceptForLocation(this.responseOption());
1805
1816
  this.abortWhenLayerClosed();
1806
1817
  this.tryDismissLayerFromServer();
1807
1818
  this.abortWhenLayerClosed();
1808
- this.layer.tryDismissForLocation();
1819
+ this.layer.tryDismissForLocation(this.responseOption());
1809
1820
  this.abortWhenLayerClosed();
1810
1821
  }
1811
1822
  this.layer.asCurrent(() => {
1812
1823
  for (let eventPlan of this.eventPlans) {
1813
- up.emit(eventPlan);
1824
+ up.emit(Object.assign(Object.assign({}, eventPlan), this.responseOption()));
1814
1825
  this.abortWhenLayerClosed();
1815
1826
  }
1816
1827
  });
1817
1828
  }
1818
1829
  tryAcceptLayerFromServer() {
1819
1830
  if (u.isDefined(this.acceptLayer) && this.layer.isOverlay()) {
1820
- this.layer.accept(this.acceptLayer);
1831
+ this.layer.accept(this.acceptLayer, this.responseOption());
1821
1832
  }
1822
1833
  }
1823
1834
  tryDismissLayerFromServer() {
1824
1835
  if (u.isDefined(this.dismissLayer) && this.layer.isOverlay()) {
1825
- this.layer.dismiss(this.dismissLayer);
1836
+ this.layer.dismiss(this.dismissLayer, this.responseOption());
1826
1837
  }
1827
1838
  }
1828
1839
  abortWhenLayerClosed() {
@@ -1849,6 +1860,9 @@ up.Change.Addition = class Addition extends up.Change {
1849
1860
  this.setTime(options);
1850
1861
  this.setETag(options);
1851
1862
  }
1863
+ responseOption() {
1864
+ return { response: this.response };
1865
+ }
1852
1866
  };
1853
1867
 
1854
1868
 
@@ -1891,7 +1905,7 @@ up.RenderJob = (_a = class RenderJob {
1891
1905
  if (result instanceof up.RenderResult) {
1892
1906
  if (!result.none)
1893
1907
  (_b = (_a = result.options).onRendered) === null || _b === void 0 ? void 0 : _b.call(_a, result);
1894
- result.finished.then(result.options.onFinished);
1908
+ result.finished.then(result.options.onFinished, u.noop);
1895
1909
  return true;
1896
1910
  }
1897
1911
  }
@@ -1920,6 +1934,10 @@ up.RenderJob = (_a = class RenderJob {
1920
1934
  let onRequest = (request) => this.handleAbortOption(request);
1921
1935
  this.change = new up.Change.FromURL(Object.assign(Object.assign({}, this.options), { onRequest }));
1922
1936
  }
1937
+ else if (this.options.response) {
1938
+ this.change = new up.Change.FromResponse(this.options);
1939
+ this.handleAbortOption(null);
1940
+ }
1923
1941
  else {
1924
1942
  this.change = new up.Change.FromContent(this.options);
1925
1943
  this.handleAbortOption(null);
@@ -2073,7 +2091,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2073
2091
  this.content = responseDoc.select(this.target);
2074
2092
  }
2075
2093
  if (!this.content || this.baseLayer.isClosed()) {
2076
- throw this.cannotMatch();
2094
+ throw new up.CannotMatch();
2077
2095
  }
2078
2096
  onApplicable();
2079
2097
  up.puts('up.render()', `Opening element "${this.target}" in new overlay`);
@@ -2081,8 +2099,8 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2081
2099
  if (this.emitOpenEvent().defaultPrevented) {
2082
2100
  throw new up.Aborted('Open event was prevented');
2083
2101
  }
2084
- this.baseLayer.peel();
2085
2102
  this.layer = this.buildLayer();
2103
+ this.baseLayer.peel({ history: !this.layer.history });
2086
2104
  up.layer.stack.push(this.layer);
2087
2105
  this.layer.createElements(this.content);
2088
2106
  this.layer.setupHandlers();
@@ -2223,7 +2241,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2223
2241
  up.viewport.saveFocus({ layer: this.layer });
2224
2242
  }
2225
2243
  if (this.options.peel) {
2226
- this.layer.peel();
2244
+ this.layer.peel({ history: !this.hasHistory() });
2227
2245
  }
2228
2246
  if (this.options.abort !== false) {
2229
2247
  up.fragment.abort(this.getFragments(), { reason: 'Fragment is being replaced' });
@@ -2385,7 +2403,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2385
2403
  return true;
2386
2404
  }
2387
2405
  else if (!step.maybe) {
2388
- throw this.cannotMatch(`Could not find element "${this.target}" in current page`);
2406
+ throw new up.CannotMatch();
2389
2407
  }
2390
2408
  });
2391
2409
  this.resolveOldNesting();
@@ -2401,7 +2419,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2401
2419
  return true;
2402
2420
  }
2403
2421
  else if (!step.maybe) {
2404
- throw this.cannotMatch(`Could not find element "${this.target}" in server response`);
2422
+ throw new up.CannotMatch();
2405
2423
  }
2406
2424
  });
2407
2425
  this.resolveOldNesting();
@@ -2487,13 +2505,15 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2487
2505
  const u = up.util;
2488
2506
  up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2489
2507
  constructor(options) {
2490
- var _a;
2508
+ var _a, _b;
2491
2509
  super(options);
2492
2510
  this.verb = options.verb;
2493
2511
  this.layer = up.layer.get(options);
2494
2512
  this.origin = options.origin;
2495
2513
  this.value = options.value;
2496
2514
  this.preventable = (_a = options.preventable) !== null && _a !== void 0 ? _a : true;
2515
+ this.response = options.response;
2516
+ this.history = (_b = options.history) !== null && _b !== void 0 ? _b : true;
2497
2517
  }
2498
2518
  execute() {
2499
2519
  if (!this.layer.isOpen()) {
@@ -2507,7 +2527,9 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2507
2527
  const { parent } = this.layer;
2508
2528
  this.layer.peel();
2509
2529
  this.layer.stack.remove(this.layer);
2510
- parent.restoreHistory();
2530
+ if (this.history) {
2531
+ parent.restoreHistory();
2532
+ }
2511
2533
  this.handleFocus(parent);
2512
2534
  this.layer.teardownHandlers();
2513
2535
  this.layer.destroyElements(this.options);
@@ -2535,7 +2557,8 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2535
2557
  return up.event.build(name, {
2536
2558
  layer: this.layer,
2537
2559
  value: this.value,
2538
- origin: this.origin
2560
+ origin: this.origin,
2561
+ response: this.response,
2539
2562
  });
2540
2563
  }
2541
2564
  handleFocus(formerParent) {
@@ -2552,152 +2575,6 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2552
2575
  /* 31 */
2553
2576
  /***/ (() => {
2554
2577
 
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
2578
  var _a;
2702
2579
  const u = up.util;
2703
2580
  up.Change.FromURL = (_a = class FromURL extends up.Change {
@@ -2723,9 +2600,6 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2723
2600
  }
2724
2601
  return u.always(this.request, responseOrError => this.onRequestSettled(responseOrError));
2725
2602
  }
2726
- deriveFailOptions() {
2727
- return up.RenderOptions.deriveFailOptions(this.options);
2728
- }
2729
2603
  newPageReason() {
2730
2604
  if (u.isCrossOrigin(this.options.url)) {
2731
2605
  return 'Loading cross-origin content in new page';
@@ -2755,41 +2629,12 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2755
2629
  }
2756
2630
  }
2757
2631
  onRequestSettledWithResponse(response) {
2758
- var _a;
2759
- this.response = response;
2760
- if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2761
- this.skip();
2762
- }
2763
- else {
2764
- 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
- }
2766
- let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !response.ok;
2767
- if (fail) {
2768
- throw this.updateContentFromResponse(this.deriveFailOptions());
2769
- }
2770
- return this.updateContentFromResponse(this.options);
2771
- }
2772
- compilerPassMeta() {
2773
- return u.pick(this.loadedEventProps(), [
2774
- 'revalidating',
2775
- 'response'
2776
- ]);
2777
- }
2778
- loadedEventProps() {
2779
- const { expiredResponse } = this.options;
2780
- return {
2781
- request: this.request,
2782
- response: this.response,
2783
- renderOptions: this.options,
2784
- revalidating: !!expiredResponse,
2785
- expiredResponse,
2786
- };
2632
+ return new up.Change.FromResponse(Object.assign(Object.assign({}, this.options), { response })).execute();
2787
2633
  }
2788
2634
  onRequestSettledWithError(error) {
2789
2635
  if (error instanceof up.Offline) {
2790
2636
  this.request.emit('up:fragment:offline', {
2791
2637
  callback: this.options.onOffline,
2792
- response: this.response,
2793
2638
  renderOptions: this.options,
2794
2639
  retry: (retryOptions) => up.render(Object.assign(Object.assign({}, this.options), retryOptions)),
2795
2640
  log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
@@ -2797,6 +2642,50 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2797
2642
  }
2798
2643
  throw error;
2799
2644
  }
2645
+ },
2646
+ (() => {
2647
+ u.memoizeMethod(_a.prototype, [
2648
+ 'getRequestAttrs',
2649
+ ]);
2650
+ })(),
2651
+ _a);
2652
+
2653
+
2654
+ /***/ }),
2655
+ /* 32 */
2656
+ /***/ (function() {
2657
+
2658
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2659
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2660
+ return new (P || (P = Promise))(function (resolve, reject) {
2661
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2662
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2663
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2664
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2665
+ });
2666
+ };
2667
+ var _a;
2668
+ const u = up.util;
2669
+ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2670
+ constructor(options) {
2671
+ super(options);
2672
+ this.response = options.response;
2673
+ this.request = this.response.request;
2674
+ }
2675
+ execute() {
2676
+ var _a;
2677
+ if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2678
+ this.skip();
2679
+ }
2680
+ else {
2681
+ 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() }));
2682
+ }
2683
+ let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !this.response.ok;
2684
+ if (fail) {
2685
+ throw this.updateContentFromResponse(this.deriveFailOptions());
2686
+ }
2687
+ return this.updateContentFromResponse(this.options);
2688
+ }
2800
2689
  skip() {
2801
2690
  up.puts('up.render()', 'Skipping ' + this.response.description);
2802
2691
  this.options.target = ':none';
@@ -2837,6 +2726,22 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2837
2726
  return renderResult;
2838
2727
  });
2839
2728
  }
2729
+ loadedEventProps() {
2730
+ const { expiredResponse } = this.options;
2731
+ return {
2732
+ request: this.request,
2733
+ response: this.response,
2734
+ renderOptions: this.options,
2735
+ revalidating: !!expiredResponse,
2736
+ expiredResponse,
2737
+ };
2738
+ }
2739
+ compilerPassMeta() {
2740
+ return u.pick(this.loadedEventProps(), [
2741
+ 'revalidating',
2742
+ 'response'
2743
+ ]);
2744
+ }
2840
2745
  augmentOptionsFromResponse(renderOptions) {
2841
2746
  var _a, _b;
2842
2747
  const responseURL = this.response.url;
@@ -2846,44 +2751,182 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2846
2751
  renderOptions.hash = hash;
2847
2752
  serverLocation += hash;
2848
2753
  }
2849
- const isReloadable = (this.response.method === 'GET');
2850
- if (isReloadable) {
2851
- renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2754
+ const isReloadable = (this.response.method === 'GET');
2755
+ if (isReloadable) {
2756
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2757
+ }
2758
+ else {
2759
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2760
+ renderOptions.history = !!renderOptions.location;
2761
+ }
2762
+ renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2763
+ renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2764
+ renderOptions.eventPlans = this.response.eventPlans;
2765
+ let serverTarget = this.response.target;
2766
+ if (serverTarget) {
2767
+ renderOptions.target = serverTarget;
2768
+ }
2769
+ renderOptions.acceptLayer = this.response.acceptLayer;
2770
+ renderOptions.dismissLayer = this.response.dismissLayer;
2771
+ renderOptions.document = this.response.text;
2772
+ if (this.response.none) {
2773
+ renderOptions.target = ':none';
2774
+ }
2775
+ renderOptions.context = u.merge(renderOptions.context, this.response.context);
2776
+ renderOptions.cspNonces = this.response.cspNonces;
2777
+ (_a = renderOptions.time) !== null && _a !== void 0 ? _a : (renderOptions.time = this.response.lastModified);
2778
+ (_b = renderOptions.etag) !== null && _b !== void 0 ? _b : (renderOptions.etag = this.response.etag);
2779
+ }
2780
+ },
2781
+ (() => {
2782
+ u.memoizeMethod(_a.prototype, [
2783
+ 'loadedEventProps',
2784
+ ]);
2785
+ })(),
2786
+ _a);
2787
+
2788
+
2789
+ /***/ }),
2790
+ /* 33 */
2791
+ /***/ (() => {
2792
+
2793
+ var _a;
2794
+ const u = up.util;
2795
+ up.Change.FromContent = (_a = class FromContent extends up.Change {
2796
+ constructor(options) {
2797
+ super(options);
2798
+ this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2799
+ this.origin = this.options.origin;
2800
+ this.preview = this.options.preview;
2801
+ this.mode = this.options.mode;
2802
+ if (this.origin) {
2803
+ this.originLayer = up.layer.get(this.origin);
2804
+ }
2805
+ }
2806
+ isRenderableLayer(layer) {
2807
+ return (layer === 'new') || layer.isOpen();
2808
+ }
2809
+ getPlans() {
2810
+ var _a;
2811
+ let plans = [];
2812
+ if (this.options.fragment) {
2813
+ (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2814
+ }
2815
+ this.expandIntoPlans(plans, this.layers, this.options.target);
2816
+ this.expandIntoPlans(plans, this.layers, this.options.fallback);
2817
+ return plans;
2818
+ }
2819
+ expandIntoPlans(plans, layers, targets) {
2820
+ for (let layer of layers) {
2821
+ for (let target of this.expandTargets(targets, layer)) {
2822
+ const props = Object.assign(Object.assign({}, this.options), { target, layer, defaultPlacement: this.defaultPlacement() });
2823
+ const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2824
+ plans.push(change);
2825
+ }
2826
+ }
2827
+ }
2828
+ expandTargets(targets, layer) {
2829
+ return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2830
+ }
2831
+ execute() {
2832
+ if (this.options.preload) {
2833
+ return Promise.resolve();
2834
+ }
2835
+ return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2836
+ }
2837
+ executePlan(matchedPlan) {
2838
+ let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2839
+ result.options = this.options;
2840
+ return result;
2841
+ }
2842
+ onPlanApplicable(plan) {
2843
+ let primaryPlan = this.getPlans()[0];
2844
+ if (plan !== primaryPlan) {
2845
+ up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2846
+ }
2847
+ }
2848
+ getResponseDoc() {
2849
+ var _a, _b;
2850
+ if (this.preview)
2851
+ return;
2852
+ const docOptions = u.pick(this.options, [
2853
+ 'target',
2854
+ 'content',
2855
+ 'fragment',
2856
+ 'document',
2857
+ 'html',
2858
+ 'cspNonces',
2859
+ 'origin',
2860
+ ]);
2861
+ (_b = (_a = up.migrate).handleResponseDocOptions) === null || _b === void 0 ? void 0 : _b.call(_a, docOptions);
2862
+ if (this.defaultPlacement() === 'content') {
2863
+ docOptions.target = this.firstExpandedTarget(docOptions.target);
2864
+ }
2865
+ return new up.ResponseDoc(docOptions);
2866
+ }
2867
+ defaultPlacement() {
2868
+ if (!this.options.document && !this.options.fragment) {
2869
+ return 'content';
2870
+ }
2871
+ }
2872
+ firstExpandedTarget(target) {
2873
+ return this.expandTargets(target || ':main', this.layers[0])[0];
2874
+ }
2875
+ getPreflightProps(opts = {}) {
2876
+ const getPlanProps = plan => plan.getPreflightProps();
2877
+ return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2878
+ }
2879
+ cannotMatchPreflightTarget() {
2880
+ this.cannotMatchTarget('Could not find target in current page');
2881
+ }
2882
+ cannotMatchPostflightTarget() {
2883
+ this.cannotMatchTarget('Could not find common target in current page and response');
2884
+ }
2885
+ cannotMatchTarget(reason) {
2886
+ let message;
2887
+ if (this.getPlans().length) {
2888
+ const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2889
+ const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2890
+ message = [reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption];
2891
+ }
2892
+ else if (this.layers.length) {
2893
+ if (this.options.failPrefixForced) {
2894
+ message = 'No target selector given for failed responses (https://unpoly.com/failed-responses)';
2895
+ }
2896
+ else {
2897
+ message = 'No target selector given';
2898
+ }
2852
2899
  }
2853
2900
  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;
2901
+ message = 'Could not find a layer to render in. You may have passed a non-existing layer reference, or a detached element.';
2863
2902
  }
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';
2903
+ throw new up.CannotMatch(message);
2904
+ }
2905
+ seekPlan(fn) {
2906
+ for (let plan of this.getPlans()) {
2907
+ try {
2908
+ return fn(plan);
2909
+ }
2910
+ catch (error) {
2911
+ if (!(error instanceof up.CannotMatch)) {
2912
+ throw error;
2913
+ }
2914
+ }
2869
2915
  }
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
2916
  }
2875
2917
  },
2876
2918
  (() => {
2877
2919
  u.memoizeMethod(_a.prototype, [
2878
- 'getRequestAttrs',
2879
- 'loadedEventProps',
2920
+ 'getPlans',
2921
+ 'getResponseDoc',
2922
+ 'getPreflightProps',
2880
2923
  ]);
2881
2924
  })(),
2882
2925
  _a);
2883
2926
 
2884
2927
 
2885
2928
  /***/ }),
2886
- /* 33 */
2929
+ /* 34 */
2887
2930
  /***/ (() => {
2888
2931
 
2889
2932
  const u = up.util;
@@ -2970,7 +3013,6 @@ up.CompilerPass = class CompilerPass {
2970
3013
  catch (error) {
2971
3014
  this.errors.push(error);
2972
3015
  up.log.error('up.hello()', 'While compiling %o: %o', elementOrElements, error);
2973
- up.error.emitGlobal(error);
2974
3016
  }
2975
3017
  }
2976
3018
  destructorPresence(result) {
@@ -2995,7 +3037,7 @@ up.CompilerPass = class CompilerPass {
2995
3037
 
2996
3038
 
2997
3039
  /***/ }),
2998
- /* 34 */
3040
+ /* 35 */
2999
3041
  /***/ (() => {
3000
3042
 
3001
3043
  const u = up.util;
@@ -3108,7 +3150,7 @@ up.CSSTransition = class CSSTransition {
3108
3150
 
3109
3151
 
3110
3152
  /***/ }),
3111
- /* 35 */
3153
+ /* 36 */
3112
3154
  /***/ (() => {
3113
3155
 
3114
3156
  const u = up.util;
@@ -3143,14 +3185,13 @@ up.DestructorPass = class DestructorPass {
3143
3185
  catch (error) {
3144
3186
  this.errors.push(error);
3145
3187
  up.log.error('up.destroy()', 'While destroying %o: %o', element, error);
3146
- up.error.emitGlobal(error);
3147
3188
  }
3148
3189
  }
3149
3190
  };
3150
3191
 
3151
3192
 
3152
3193
  /***/ }),
3153
- /* 36 */
3194
+ /* 37 */
3154
3195
  /***/ (() => {
3155
3196
 
3156
3197
  const u = up.util;
@@ -3251,7 +3292,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3251
3292
 
3252
3293
 
3253
3294
  /***/ }),
3254
- /* 37 */
3295
+ /* 38 */
3255
3296
  /***/ (() => {
3256
3297
 
3257
3298
  const u = up.util;
@@ -3315,6 +3356,9 @@ up.EventListener = class EventListener extends up.Record {
3315
3356
  const data = up.syntax.data(element);
3316
3357
  args.push(data);
3317
3358
  }
3359
+ if (this.eventType === 'click' && element.disabled) {
3360
+ return;
3361
+ }
3318
3362
  const applyCallback = this.callback.bind(element, ...args);
3319
3363
  if (this.baseLayer) {
3320
3364
  this.baseLayer.asCurrent(applyCallback);
@@ -3354,7 +3398,7 @@ up.EventListener = class EventListener extends up.Record {
3354
3398
 
3355
3399
 
3356
3400
  /***/ }),
3357
- /* 38 */
3401
+ /* 39 */
3358
3402
  /***/ (() => {
3359
3403
 
3360
3404
  const u = up.util;
@@ -3426,7 +3470,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3426
3470
 
3427
3471
 
3428
3472
  /***/ }),
3429
- /* 39 */
3473
+ /* 40 */
3430
3474
  /***/ (function() {
3431
3475
 
3432
3476
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3553,7 +3597,7 @@ up.FieldWatcher = class FieldWatcher {
3553
3597
 
3554
3598
 
3555
3599
  /***/ }),
3556
- /* 40 */
3600
+ /* 41 */
3557
3601
  /***/ (function() {
3558
3602
 
3559
3603
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3751,7 +3795,7 @@ up.FormValidator = class FormValidator {
3751
3795
 
3752
3796
 
3753
3797
  /***/ }),
3754
- /* 41 */
3798
+ /* 42 */
3755
3799
  /***/ (() => {
3756
3800
 
3757
3801
  up.FocusCapsule = class FocusCapsule {
@@ -3781,7 +3825,7 @@ up.FocusCapsule = class FocusCapsule {
3781
3825
 
3782
3826
 
3783
3827
  /***/ }),
3784
- /* 42 */
3828
+ /* 43 */
3785
3829
  /***/ (() => {
3786
3830
 
3787
3831
  const u = up.util;
@@ -3845,7 +3889,7 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
3845
3889
 
3846
3890
 
3847
3891
  /***/ }),
3848
- /* 43 */
3892
+ /* 44 */
3849
3893
  /***/ (() => {
3850
3894
 
3851
3895
  const DESCENDANT_SELECTOR = /^([^ >+(]+) (.+)$/;
@@ -3888,7 +3932,7 @@ up.FragmentFinder = class FragmentFinder {
3888
3932
 
3889
3933
 
3890
3934
  /***/ }),
3891
- /* 44 */
3935
+ /* 45 */
3892
3936
  /***/ (() => {
3893
3937
 
3894
3938
  const u = up.util;
@@ -3973,7 +4017,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
3973
4017
 
3974
4018
 
3975
4019
  /***/ }),
3976
- /* 45 */
4020
+ /* 46 */
3977
4021
  /***/ (() => {
3978
4022
 
3979
4023
  const e = up.element;
@@ -4057,9 +4101,7 @@ up.FragmentPolling = class FragmentPolling {
4057
4101
  }
4058
4102
  onReloadFailure(reason) {
4059
4103
  this.scheduleReload();
4060
- if (up.error.isCritical(reason)) {
4061
- throw reason;
4062
- }
4104
+ up.error.rethrowCritical(reason);
4063
4105
  }
4064
4106
  onFragmentSwapped(newFragment) {
4065
4107
  this.stop();
@@ -4081,7 +4123,7 @@ up.FragmentPolling = class FragmentPolling {
4081
4123
 
4082
4124
 
4083
4125
  /***/ }),
4084
- /* 46 */
4126
+ /* 47 */
4085
4127
  /***/ (() => {
4086
4128
 
4087
4129
  const u = up.util;
@@ -4145,7 +4187,7 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4145
4187
 
4146
4188
 
4147
4189
  /***/ }),
4148
- /* 47 */
4190
+ /* 48 */
4149
4191
  /***/ (() => {
4150
4192
 
4151
4193
  const e = up.element;
@@ -4368,7 +4410,7 @@ up.Layer = class Layer extends up.Record {
4368
4410
 
4369
4411
 
4370
4412
  /***/ }),
4371
- /* 48 */
4413
+ /* 49 */
4372
4414
  /***/ (() => {
4373
4415
 
4374
4416
  const e = up.element;
@@ -4551,7 +4593,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4551
4593
  parser.string('easing');
4552
4594
  parser.number('duration');
4553
4595
  parser.string('confirm');
4554
- closeFn(value, closeOptions);
4596
+ up.error.muteUncriticalSync(() => closeFn(value, closeOptions));
4555
4597
  });
4556
4598
  }
4557
4599
  registerEventCloser(eventTypes, closeFn) {
@@ -4560,20 +4602,20 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4560
4602
  }
4561
4603
  return this.on(eventTypes, event => {
4562
4604
  event.preventDefault();
4563
- closeFn.call(this, event);
4605
+ closeFn.call(this, event, { response: event.response });
4564
4606
  });
4565
4607
  }
4566
- tryAcceptForLocation() {
4567
- this.tryCloseForLocation(this.acceptLocation, this.accept);
4608
+ tryAcceptForLocation(options) {
4609
+ this.tryCloseForLocation(this.acceptLocation, this.accept, options);
4568
4610
  }
4569
- tryDismissForLocation() {
4570
- this.tryCloseForLocation(this.dismissLocation, this.dismiss);
4611
+ tryDismissForLocation(options) {
4612
+ this.tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4571
4613
  }
4572
- tryCloseForLocation(urlPattern, closeFn) {
4614
+ tryCloseForLocation(urlPattern, closeFn, options) {
4573
4615
  let location, resolution;
4574
4616
  if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
4575
4617
  const closeValue = Object.assign(Object.assign({}, resolution), { location });
4576
- closeFn.call(this, closeValue);
4618
+ closeFn.call(this, closeValue, options);
4577
4619
  }
4578
4620
  }
4579
4621
  teardownHandlers() {
@@ -4648,7 +4690,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4648
4690
 
4649
4691
 
4650
4692
  /***/ }),
4651
- /* 49 */
4693
+ /* 50 */
4652
4694
  /***/ (() => {
4653
4695
 
4654
4696
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -4685,7 +4727,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
4685
4727
 
4686
4728
 
4687
4729
  /***/ }),
4688
- /* 50 */
4730
+ /* 51 */
4689
4731
  /***/ (() => {
4690
4732
 
4691
4733
  var _a;
@@ -4723,19 +4765,19 @@ up.Layer.OverlayWithViewport = (_a = class OverlayWithViewport extends up.Layer.
4723
4765
 
4724
4766
 
4725
4767
  /***/ }),
4726
- /* 51 */
4768
+ /* 52 */
4727
4769
  /***/ (() => {
4728
4770
 
4729
4771
  var _a;
4730
4772
  const e = up.element;
4731
4773
  up.Layer.Root = (_a = class Root extends up.Layer {
4774
+ get element() {
4775
+ return e.root;
4776
+ }
4732
4777
  constructor(options) {
4733
4778
  super(options);
4734
4779
  this.setupHandlers();
4735
4780
  }
4736
- get element() {
4737
- return e.root;
4738
- }
4739
4781
  getFirstSwappableElement() {
4740
4782
  return document.body;
4741
4783
  }
@@ -4769,7 +4811,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4769
4811
 
4770
4812
 
4771
4813
  /***/ }),
4772
- /* 52 */
4814
+ /* 53 */
4773
4815
  /***/ (() => {
4774
4816
 
4775
4817
  var _a;
@@ -4780,7 +4822,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
4780
4822
 
4781
4823
 
4782
4824
  /***/ }),
4783
- /* 53 */
4825
+ /* 54 */
4784
4826
  /***/ (() => {
4785
4827
 
4786
4828
  var _a;
@@ -4791,7 +4833,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
4791
4833
 
4792
4834
 
4793
4835
  /***/ }),
4794
- /* 54 */
4836
+ /* 55 */
4795
4837
  /***/ (() => {
4796
4838
 
4797
4839
  var _a;
@@ -4802,7 +4844,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
4802
4844
 
4803
4845
 
4804
4846
  /***/ }),
4805
- /* 55 */
4847
+ /* 56 */
4806
4848
  /***/ (() => {
4807
4849
 
4808
4850
  var _a;
@@ -4813,7 +4855,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
4813
4855
 
4814
4856
 
4815
4857
  /***/ }),
4816
- /* 56 */
4858
+ /* 57 */
4817
4859
  /***/ (() => {
4818
4860
 
4819
4861
  const u = up.util;
@@ -4903,7 +4945,7 @@ up.LayerLookup = class LayerLookup {
4903
4945
 
4904
4946
 
4905
4947
  /***/ }),
4906
- /* 57 */
4948
+ /* 58 */
4907
4949
  /***/ (() => {
4908
4950
 
4909
4951
  const u = up.util;
@@ -5016,7 +5058,7 @@ up.LayerStack = class LayerStack extends Array {
5016
5058
 
5017
5059
 
5018
5060
  /***/ }),
5019
- /* 58 */
5061
+ /* 59 */
5020
5062
  /***/ (() => {
5021
5063
 
5022
5064
  up.LinkFeedbackURLs = class LinkFeedbackURLs {
@@ -5047,7 +5089,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
5047
5089
 
5048
5090
 
5049
5091
  /***/ }),
5050
- /* 59 */
5092
+ /* 60 */
5051
5093
  /***/ (() => {
5052
5094
 
5053
5095
  const u = up.util;
@@ -5117,7 +5159,7 @@ up.LinkPreloader = class LinkPreloader {
5117
5159
 
5118
5160
 
5119
5161
  /***/ }),
5120
- /* 60 */
5162
+ /* 61 */
5121
5163
  /***/ (function() {
5122
5164
 
5123
5165
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -5226,7 +5268,7 @@ up.MotionController = class MotionController {
5226
5268
 
5227
5269
 
5228
5270
  /***/ }),
5229
- /* 61 */
5271
+ /* 62 */
5230
5272
  /***/ (() => {
5231
5273
 
5232
5274
  const u = up.util;
@@ -5318,7 +5360,7 @@ up.NonceableCallback = class NonceableCallback {
5318
5360
 
5319
5361
 
5320
5362
  /***/ }),
5321
- /* 62 */
5363
+ /* 63 */
5322
5364
  /***/ (() => {
5323
5365
 
5324
5366
  const u = up.util;
@@ -5396,7 +5438,7 @@ up.OptionsParser = class OptionsParser {
5396
5438
 
5397
5439
 
5398
5440
  /***/ }),
5399
- /* 63 */
5441
+ /* 64 */
5400
5442
  /***/ (() => {
5401
5443
 
5402
5444
  const e = up.element;
@@ -5464,7 +5506,7 @@ up.OverlayFocus = class OverlayFocus {
5464
5506
 
5465
5507
 
5466
5508
  /***/ }),
5467
- /* 64 */
5509
+ /* 65 */
5468
5510
  /***/ (() => {
5469
5511
 
5470
5512
  const u = up.util;
@@ -5695,7 +5737,7 @@ up.Params = class Params {
5695
5737
 
5696
5738
 
5697
5739
  /***/ }),
5698
- /* 65 */
5740
+ /* 66 */
5699
5741
  /***/ (() => {
5700
5742
 
5701
5743
  const e = up.element;
@@ -5745,7 +5787,7 @@ up.ProgressBar = class ProgressBar {
5745
5787
 
5746
5788
 
5747
5789
  /***/ }),
5748
- /* 66 */
5790
+ /* 67 */
5749
5791
  /***/ (() => {
5750
5792
 
5751
5793
  const u = up.util;
@@ -5794,14 +5836,15 @@ up.RenderOptions = (function () {
5794
5836
  ]);
5795
5837
  const CONTENT_KEYS = [
5796
5838
  'url',
5839
+ 'response',
5797
5840
  'content',
5798
5841
  'fragment',
5799
- 'document'
5842
+ 'document',
5800
5843
  ];
5801
5844
  const LATE_KEYS = [
5802
5845
  'history',
5803
5846
  'focus',
5804
- 'scroll'
5847
+ 'scroll',
5805
5848
  ];
5806
5849
  function navigateDefaults(options) {
5807
5850
  if (options.navigate) {
@@ -5861,7 +5904,7 @@ up.RenderOptions = (function () {
5861
5904
 
5862
5905
 
5863
5906
  /***/ }),
5864
- /* 67 */
5907
+ /* 68 */
5865
5908
  /***/ (() => {
5866
5909
 
5867
5910
  up.RenderResult = class RenderResult extends up.Record {
@@ -5889,33 +5932,12 @@ up.RenderResult = class RenderResult extends up.Record {
5889
5932
 
5890
5933
 
5891
5934
  /***/ }),
5892
- /* 68 */
5935
+ /* 69 */
5893
5936
  /***/ (() => {
5894
5937
 
5895
5938
  var _a;
5896
5939
  const u = up.util;
5897
5940
  up.Request = (_a = class Request extends up.Record {
5898
- constructor(options) {
5899
- var _a;
5900
- super(options);
5901
- this.params = new up.Params(this.params);
5902
- if (this.wrapMethod == null) {
5903
- this.wrapMethod = up.network.config.wrapMethod;
5904
- }
5905
- this.normalize();
5906
- if ((this.target || this.layer || this.origin) && !options.basic) {
5907
- const layerLookupOptions = { origin: this.origin };
5908
- this.layer = up.layer.get(this.layer, layerLookupOptions);
5909
- this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5910
- this.context || (this.context = this.layer.context || {});
5911
- this.failContext || (this.failContext = this.failLayer.context || {});
5912
- this.mode || (this.mode = this.layer.mode);
5913
- this.failMode || (this.failMode = this.failLayer.mode);
5914
- }
5915
- this.deferred = u.newDeferred();
5916
- (_a = this.badResponseTime) !== null && _a !== void 0 ? _a : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5917
- this.addAutoHeaders();
5918
- }
5919
5941
  keys() {
5920
5942
  return [
5921
5943
  'method',
@@ -5958,18 +5980,41 @@ up.Request = (_a = class Request extends up.Record {
5958
5980
  builtAt: new Date(),
5959
5981
  };
5960
5982
  }
5983
+ constructor(options) {
5984
+ var _a;
5985
+ super(options);
5986
+ this.params = new up.Params(this.params);
5987
+ if (this.wrapMethod == null) {
5988
+ this.wrapMethod = up.network.config.wrapMethod;
5989
+ }
5990
+ this.normalize();
5991
+ if ((this.target || this.layer || this.origin) && !options.basic) {
5992
+ const layerLookupOptions = { origin: this.origin };
5993
+ this.layer = up.layer.get(this.layer, layerLookupOptions);
5994
+ this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5995
+ this.context || (this.context = this.layer.context || {});
5996
+ this.failContext || (this.failContext = this.failLayer.context || {});
5997
+ this.mode || (this.mode = this.layer.mode);
5998
+ this.failMode || (this.failMode = this.failLayer.mode);
5999
+ }
6000
+ this.deferred = u.newDeferred();
6001
+ (_a = this.badResponseTime) !== null && _a !== void 0 ? _a : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
6002
+ this.addAutoHeaders();
6003
+ }
5961
6004
  get xhr() {
5962
6005
  var _a;
5963
6006
  return (_a = this._xhr) !== null && _a !== void 0 ? _a : (this._xhr = new XMLHttpRequest());
5964
6007
  }
5965
6008
  get fragments() {
5966
- if (!this._fragments && this.target) {
6009
+ if (this._fragments) {
6010
+ return this._fragments;
6011
+ }
6012
+ else if (this.target) {
5967
6013
  let steps = up.fragment.parseTargetSteps(this.target);
5968
6014
  let selectors = u.map(steps, 'selector');
5969
6015
  let lookupOpts = { origin: this.origin, layer: this.layer };
5970
- this._fragments = u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
6016
+ return u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5971
6017
  }
5972
- return this._fragments;
5973
6018
  }
5974
6019
  set fragments(value) {
5975
6020
  this._fragments = value;
@@ -6230,7 +6275,7 @@ up.Request = (_a = class Request extends up.Record {
6230
6275
 
6231
6276
 
6232
6277
  /***/ }),
6233
- /* 69 */
6278
+ /* 70 */
6234
6279
  /***/ (function() {
6235
6280
 
6236
6281
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -6333,6 +6378,7 @@ up.Request.Cache = class Cache {
6333
6378
  if (value instanceof up.Response) {
6334
6379
  if (options.force || this.isCacheCompatible(existingRequest, newRequest)) {
6335
6380
  newRequest.fromCache = true;
6381
+ value = u.variant(value, { request: newRequest });
6336
6382
  newRequest.respondWith(value);
6337
6383
  u.delegate(newRequest, ['expired', 'state'], () => existingRequest);
6338
6384
  }
@@ -6383,7 +6429,7 @@ up.Request.Cache = class Cache {
6383
6429
 
6384
6430
 
6385
6431
  /***/ }),
6386
- /* 70 */
6432
+ /* 71 */
6387
6433
  /***/ (() => {
6388
6434
 
6389
6435
  const u = up.util;
@@ -6492,7 +6538,7 @@ up.Request.Queue = class Queue {
6492
6538
 
6493
6539
 
6494
6540
  /***/ }),
6495
- /* 71 */
6541
+ /* 72 */
6496
6542
  /***/ (() => {
6497
6543
 
6498
6544
  const u = up.util;
@@ -6531,7 +6577,7 @@ up.Request.FormRenderer = class FormRenderer {
6531
6577
 
6532
6578
 
6533
6579
  /***/ }),
6534
- /* 72 */
6580
+ /* 73 */
6535
6581
  /***/ (() => {
6536
6582
 
6537
6583
  var _a;
@@ -6603,7 +6649,7 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6603
6649
 
6604
6650
 
6605
6651
  /***/ }),
6606
- /* 73 */
6652
+ /* 74 */
6607
6653
  /***/ (() => {
6608
6654
 
6609
6655
  const u = up.util;
@@ -6639,6 +6685,12 @@ up.Response = class Response extends up.Record {
6639
6685
  var _a;
6640
6686
  return !u.evalOption((_a = this.fail) !== null && _a !== void 0 ? _a : up.network.config.fail, this);
6641
6687
  }
6688
+ get none() {
6689
+ return !this.text;
6690
+ }
6691
+ isCacheable() {
6692
+ return this.ok && !this.none;
6693
+ }
6642
6694
  header(name) {
6643
6695
  var _a;
6644
6696
  return this.headers[name] || ((_a = this.xhr) === null || _a === void 0 ? void 0 : _a.getResponseHeader(name));
@@ -6680,7 +6732,7 @@ up.Response = class Response extends up.Record {
6680
6732
 
6681
6733
 
6682
6734
  /***/ }),
6683
- /* 74 */
6735
+ /* 75 */
6684
6736
  /***/ (() => {
6685
6737
 
6686
6738
  var _a;
@@ -6761,7 +6813,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
6761
6813
 
6762
6814
 
6763
6815
  /***/ }),
6764
- /* 75 */
6816
+ /* 76 */
6765
6817
  /***/ (() => {
6766
6818
 
6767
6819
  const e = up.element;
@@ -6856,7 +6908,7 @@ up.RevealMotion = class RevealMotion {
6856
6908
 
6857
6909
 
6858
6910
  /***/ }),
6859
- /* 76 */
6911
+ /* 77 */
6860
6912
  /***/ (() => {
6861
6913
 
6862
6914
  const u = up.util;
@@ -6897,7 +6949,7 @@ up.Selector = class Selector {
6897
6949
 
6898
6950
 
6899
6951
  /***/ }),
6900
- /* 77 */
6952
+ /* 78 */
6901
6953
  /***/ (() => {
6902
6954
 
6903
6955
  const u = up.util;
@@ -7018,7 +7070,7 @@ up.Tether = class Tether {
7018
7070
 
7019
7071
 
7020
7072
  /***/ }),
7021
- /* 78 */
7073
+ /* 79 */
7022
7074
  /***/ (() => {
7023
7075
 
7024
7076
  const u = up.util;
@@ -7099,7 +7151,7 @@ up.URLPattern = class URLPattern {
7099
7151
 
7100
7152
 
7101
7153
  /***/ }),
7102
- /* 79 */
7154
+ /* 80 */
7103
7155
  /***/ (() => {
7104
7156
 
7105
7157
  up.framework = (function () {
@@ -7183,7 +7235,7 @@ up.boot = up.framework.boot;
7183
7235
 
7184
7236
 
7185
7237
  /***/ }),
7186
- /* 80 */
7238
+ /* 81 */
7187
7239
  /***/ (() => {
7188
7240
 
7189
7241
  up.event = (function () {
@@ -7286,7 +7338,7 @@ up.emit = up.event.emit;
7286
7338
 
7287
7339
 
7288
7340
  /***/ }),
7289
- /* 81 */
7341
+ /* 82 */
7290
7342
  /***/ (() => {
7291
7343
 
7292
7344
  up.protocol = (function () {
@@ -7429,7 +7481,7 @@ up.protocol = (function () {
7429
7481
 
7430
7482
 
7431
7483
  /***/ }),
7432
- /* 82 */
7484
+ /* 83 */
7433
7485
  /***/ (() => {
7434
7486
 
7435
7487
  up.log = (function () {
@@ -7514,7 +7566,7 @@ up.warn = up.log.warn;
7514
7566
 
7515
7567
 
7516
7568
  /***/ }),
7517
- /* 83 */
7569
+ /* 84 */
7518
7570
  /***/ (() => {
7519
7571
 
7520
7572
  up.syntax = (function () {
@@ -7660,7 +7712,7 @@ up.hello = up.syntax.hello;
7660
7712
 
7661
7713
 
7662
7714
  /***/ }),
7663
- /* 84 */
7715
+ /* 85 */
7664
7716
  /***/ (() => {
7665
7717
 
7666
7718
  up.history = (function () {
@@ -7754,6 +7806,7 @@ up.history = (function () {
7754
7806
  }
7755
7807
  function onPop(event) {
7756
7808
  trackCurrentLocation();
7809
+ let location = currentLocation();
7757
7810
  emitLocationChanged({ location, reason: 'pop', log: `Navigated to history entry ${location}` });
7758
7811
  up.viewport.saveFocus({ location: previousLocation });
7759
7812
  up.viewport.saveScroll({ location: previousLocation });
@@ -7797,10 +7850,10 @@ up.history = (function () {
7797
7850
 
7798
7851
 
7799
7852
  /***/ }),
7800
- /* 85 */
7853
+ /* 86 */
7801
7854
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
7802
7855
 
7803
- __webpack_require__(86);
7856
+ __webpack_require__(87);
7804
7857
  const u = up.util;
7805
7858
  const e = up.element;
7806
7859
  up.fragment = (function () {
@@ -8328,16 +8381,16 @@ u.delegate(up, ['context'], () => up.layer.current);
8328
8381
 
8329
8382
 
8330
8383
  /***/ }),
8331
- /* 86 */
8384
+ /* 87 */
8332
8385
  /***/ (() => {
8333
8386
 
8334
8387
 
8335
8388
 
8336
8389
  /***/ }),
8337
- /* 87 */
8390
+ /* 88 */
8338
8391
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8339
8392
 
8340
- __webpack_require__(88);
8393
+ __webpack_require__(89);
8341
8394
  up.viewport = (function () {
8342
8395
  const u = up.util;
8343
8396
  const e = up.element;
@@ -8659,13 +8712,13 @@ up.reveal = up.viewport.reveal;
8659
8712
 
8660
8713
 
8661
8714
  /***/ }),
8662
- /* 88 */
8715
+ /* 89 */
8663
8716
  /***/ (() => {
8664
8717
 
8665
8718
 
8666
8719
 
8667
8720
  /***/ }),
8668
- /* 89 */
8721
+ /* 90 */
8669
8722
  /***/ (function() {
8670
8723
 
8671
8724
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -8869,8 +8922,11 @@ up.motion = (function () {
8869
8922
  function translateCSS(dx, dy) {
8870
8923
  return { transform: `translate(${dx}px, ${dy}px)` };
8871
8924
  }
8925
+ function noTranslateCSS() {
8926
+ return { transform: null };
8927
+ }
8872
8928
  function untranslatedBox(element) {
8873
- e.setStyle(element, translateCSS(0, 0));
8929
+ e.setStyle(element, noTranslateCSS());
8874
8930
  return element.getBoundingClientRect();
8875
8931
  }
8876
8932
  function registerMoveAnimations(direction, boxToTransform) {
@@ -8885,7 +8941,7 @@ up.motion = (function () {
8885
8941
  const box = untranslatedBox(element);
8886
8942
  const transform = boxToTransform(box);
8887
8943
  e.setStyle(element, transform);
8888
- return animateNow(element, translateCSS(0, 0), options);
8944
+ return animateNow(element, noTranslateCSS(), options);
8889
8945
  });
8890
8946
  }
8891
8947
  registerMoveAnimations('top', function (box) {
@@ -8931,10 +8987,10 @@ up.animate = up.motion.animate;
8931
8987
 
8932
8988
 
8933
8989
  /***/ }),
8934
- /* 90 */
8990
+ /* 91 */
8935
8991
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8936
8992
 
8937
- __webpack_require__(91);
8993
+ __webpack_require__(92);
8938
8994
  const u = up.util;
8939
8995
  up.network = (function () {
8940
8996
  const config = new up.Config(() => ({
@@ -9003,20 +9059,20 @@ up.network = (function () {
9003
9059
  cache.put(request);
9004
9060
  request.onLoading = () => cache.put(request);
9005
9061
  }
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);
9062
+ u.always(request, function (responseOrError) {
9063
+ var _a, _b, _c, _d, _e;
9064
+ 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
9065
  if (expireCache) {
9010
9066
  cache.expire(expireCache, { except: request });
9011
9067
  }
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);
9068
+ 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
9069
  if (evictCache) {
9014
9070
  cache.evict(evictCache, { except: request });
9015
9071
  }
9016
9072
  if (cache.get(request)) {
9017
9073
  cache.put(request);
9018
9074
  }
9019
- if (!response.ok) {
9075
+ if (!((_e = responseOrError.isCacheable) === null || _e === void 0 ? void 0 : _e.call(responseOrError))) {
9020
9076
  cache.evict(request);
9021
9077
  }
9022
9078
  });
@@ -9041,7 +9097,7 @@ up.network = (function () {
9041
9097
  }
9042
9098
  function registerAliasForRedirect(request, response) {
9043
9099
  if (request.cache && response.url && request.url !== response.url) {
9044
- const newRequest = request.variant({
9100
+ const newRequest = u.variant(request, {
9045
9101
  method: response.method,
9046
9102
  url: response.url
9047
9103
  });
@@ -9080,13 +9136,13 @@ up.cache = up.network.cache;
9080
9136
 
9081
9137
 
9082
9138
  /***/ }),
9083
- /* 91 */
9139
+ /* 92 */
9084
9140
  /***/ (() => {
9085
9141
 
9086
9142
 
9087
9143
 
9088
9144
  /***/ }),
9089
- /* 92 */
9145
+ /* 93 */
9090
9146
  /***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
9091
9147
 
9092
9148
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -9098,7 +9154,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9098
9154
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9099
9155
  });
9100
9156
  };
9101
- __webpack_require__(93);
9157
+ __webpack_require__(94);
9102
9158
  const u = up.util;
9103
9159
  const e = up.element;
9104
9160
  up.layer = (function () {
@@ -9244,7 +9300,7 @@ up.layer = (function () {
9244
9300
  return e.callbackAttr(link, attr, { exposedKeys: ['layer'] });
9245
9301
  }
9246
9302
  function closeCallbackAttr(link, attr) {
9247
- return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value'] });
9303
+ return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value', 'response'] });
9248
9304
  }
9249
9305
  function reset() {
9250
9306
  config.reset();
@@ -9339,16 +9395,16 @@ up.layer = (function () {
9339
9395
 
9340
9396
 
9341
9397
  /***/ }),
9342
- /* 93 */
9398
+ /* 94 */
9343
9399
  /***/ (() => {
9344
9400
 
9345
9401
 
9346
9402
 
9347
9403
  /***/ }),
9348
- /* 94 */
9404
+ /* 95 */
9349
9405
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
9350
9406
 
9351
- __webpack_require__(95);
9407
+ __webpack_require__(96);
9352
9408
  up.link = (function () {
9353
9409
  const u = up.util;
9354
9410
  const e = up.element;
@@ -9356,7 +9412,7 @@ up.link = (function () {
9356
9412
  let lastMousedownTarget = null;
9357
9413
  const LINKS_WITH_LOCAL_HTML = ['a[up-content]', 'a[up-fragment]', 'a[up-document]'];
9358
9414
  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]'];
9415
+ const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]', '[up-href]'];
9360
9416
  function combineFollowableSelectors(elementSelectors, attributeSelectors) {
9361
9417
  return u.flatMap(elementSelectors, elementSelector => attributeSelectors.map(attrSelector => elementSelector + attrSelector));
9362
9418
  }
@@ -9638,13 +9694,13 @@ up.follow = up.link.follow;
9638
9694
 
9639
9695
 
9640
9696
  /***/ }),
9641
- /* 95 */
9697
+ /* 96 */
9642
9698
  /***/ (() => {
9643
9699
 
9644
9700
 
9645
9701
 
9646
9702
  /***/ }),
9647
- /* 96 */
9703
+ /* 97 */
9648
9704
  /***/ (() => {
9649
9705
 
9650
9706
  up.form = (function () {
@@ -9659,7 +9715,7 @@ up.form = (function () {
9659
9715
  submitButtonSelectors: ['input[type=submit]', 'input[type=image]', 'button[type=submit]', 'button:not([type])'],
9660
9716
  watchInputEvents: ['input', 'change'],
9661
9717
  watchInputDelay: 0,
9662
- watchChangeEvents: (field) => field.matches('input[type=date]') ? ['blur'] : ['change'],
9718
+ watchChangeEvents: ['change'],
9663
9719
  }));
9664
9720
  function fullSubmitSelector() {
9665
9721
  return config.submitSelectors.join(',');
@@ -9689,13 +9745,13 @@ up.form = (function () {
9689
9745
  }
9690
9746
  function submittingButton(form) {
9691
9747
  const selector = submitButtonSelector();
9692
- const focusedElement = up.viewport.focusedElementWithin(form);
9693
- if (focusedElement && focusedElement.matches(selector)) {
9694
- return focusedElement;
9695
- }
9696
- else {
9697
- return e.get(form, selector);
9748
+ const focusedElement = document.activeElement;
9749
+ if (focusedElement && focusedElement.form === form) {
9750
+ if (focusedElement.matches(selector)) {
9751
+ return focusedElement;
9752
+ }
9698
9753
  }
9754
+ return e.get(form, selector);
9699
9755
  }
9700
9756
  function submitButtonSelector() {
9701
9757
  return config.submitButtonSelectors.join(',');
@@ -10040,7 +10096,7 @@ up.validate = up.form.validate;
10040
10096
 
10041
10097
 
10042
10098
  /***/ }),
10043
- /* 97 */
10099
+ /* 98 */
10044
10100
  /***/ (() => {
10045
10101
 
10046
10102
  up.feedback = (function () {
@@ -10157,7 +10213,7 @@ up.feedback = (function () {
10157
10213
 
10158
10214
 
10159
10215
  /***/ }),
10160
- /* 98 */
10216
+ /* 99 */
10161
10217
  /***/ (() => {
10162
10218
 
10163
10219
  up.radio = (function () {
@@ -10235,7 +10291,7 @@ up.radio = (function () {
10235
10291
 
10236
10292
 
10237
10293
  /***/ }),
10238
- /* 99 */
10294
+ /* 100 */
10239
10295
  /***/ (() => {
10240
10296
 
10241
10297
  (function () {
@@ -10373,15 +10429,16 @@ __webpack_require__(82);
10373
10429
  __webpack_require__(83);
10374
10430
  __webpack_require__(84);
10375
10431
  __webpack_require__(85);
10376
- __webpack_require__(87);
10377
- __webpack_require__(89);
10432
+ __webpack_require__(86);
10433
+ __webpack_require__(88);
10378
10434
  __webpack_require__(90);
10379
- __webpack_require__(92);
10380
- __webpack_require__(94);
10381
- __webpack_require__(96);
10435
+ __webpack_require__(91);
10436
+ __webpack_require__(93);
10437
+ __webpack_require__(95);
10382
10438
  __webpack_require__(97);
10383
10439
  __webpack_require__(98);
10384
10440
  __webpack_require__(99);
10441
+ __webpack_require__(100);
10385
10442
  up.framework.onEvaled();
10386
10443
 
10387
10444
  })();