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
 
@@ -721,6 +721,11 @@ up.util = (function () {
721
721
  let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0');
722
722
  return string.replace(/[^\x00-\x7F]/g, unicodeEscape);
723
723
  }
724
+ function variant(source, changes = {}) {
725
+ let variant = Object.create(source);
726
+ Object.assign(variant, changes);
727
+ return variant;
728
+ }
724
729
  return {
725
730
  parseURL,
726
731
  normalizeURL,
@@ -818,6 +823,7 @@ up.util = (function () {
818
823
  negate,
819
824
  memoizeMethod,
820
825
  safeStringifyJSON,
826
+ variant,
821
827
  };
822
828
  })();
823
829
 
@@ -827,10 +833,6 @@ up.util = (function () {
827
833
  /***/ (() => {
828
834
 
829
835
  up.error = (function () {
830
- function emitGlobal(error) {
831
- const { message } = error;
832
- up.emit(window, 'error', { message, error, log: false });
833
- }
834
836
  function fail(...args) {
835
837
  throw new up.Error(args);
836
838
  }
@@ -838,17 +840,27 @@ up.error = (function () {
838
840
  return (typeof error !== 'object') || ((error.name !== 'AbortError') && !(error instanceof up.RenderResult) && !(error instanceof up.Response));
839
841
  }
840
842
  function muteUncriticalRejection(promise) {
841
- return promise.catch(function (reason) {
842
- if (isCritical(reason)) {
843
- throw reason;
844
- }
845
- });
843
+ return promise.catch(rethrowCritical);
844
+ }
845
+ function muteUncriticalSync(block) {
846
+ try {
847
+ return block();
848
+ }
849
+ catch (e) {
850
+ rethrowCritical(e);
851
+ }
852
+ }
853
+ function rethrowCritical(value) {
854
+ if (isCritical(value)) {
855
+ throw value;
856
+ }
846
857
  }
847
858
  return {
848
859
  fail,
849
- emitGlobal,
860
+ rethrowCritical,
850
861
  isCritical,
851
862
  muteUncriticalRejection,
863
+ muteUncriticalSync,
852
864
  };
853
865
  })();
854
866
  up.fail = up.error.fail;
@@ -931,7 +943,7 @@ up.element = (function () {
931
943
  }
932
944
  function isInSubtree(root, selectorOrElement) {
933
945
  const element = getOne(selectorOrElement);
934
- return root.contains(element);
946
+ return Node.prototype.contains.call(root, element);
935
947
  }
936
948
  function ancestor(element, selector) {
937
949
  let parentElement = element.parentElement;
@@ -1173,7 +1185,7 @@ up.element = (function () {
1173
1185
  }
1174
1186
  }
1175
1187
  function classSelector(klass) {
1176
- klass = klass.replace(/:/g, '\\:');
1188
+ klass = klass.replace(/[^\w-]/g, '\\$&');
1177
1189
  return `.${klass}`;
1178
1190
  }
1179
1191
  function createBrokenDocumentFromHTML(html) {
@@ -1586,10 +1598,7 @@ up.Record = class Record {
1586
1598
  return u.pick(source, this.keys());
1587
1599
  }
1588
1600
  [u.copy.key]() {
1589
- return this.variant();
1590
- }
1591
- variant(changes = {}) {
1592
- return new this.constructor(u.merge(this.attributes(), changes));
1601
+ return u.variant(this);
1593
1602
  }
1594
1603
  [u.isEqual.key](other) {
1595
1604
  return (this.constructor === other.constructor) && u.isEqual(this.attributes(), other.attributes());
@@ -1761,9 +1770,6 @@ up.Change = class Change {
1761
1770
  constructor(options) {
1762
1771
  this.options = options;
1763
1772
  }
1764
- cannotMatch(reason) {
1765
- throw new up.CannotMatch(reason);
1766
- }
1767
1773
  execute() {
1768
1774
  throw new up.NotImplemented();
1769
1775
  }
@@ -1778,6 +1784,9 @@ up.Change = class Change {
1778
1784
  return newValue;
1779
1785
  }
1780
1786
  }
1787
+ deriveFailOptions() {
1788
+ return up.RenderOptions.deriveFailOptions(this.options);
1789
+ }
1781
1790
  };
1782
1791
 
1783
1792
 
@@ -1794,33 +1803,34 @@ up.Change.Addition = class Addition extends up.Change {
1794
1803
  this.acceptLayer = options.acceptLayer;
1795
1804
  this.dismissLayer = options.dismissLayer;
1796
1805
  this.eventPlans = options.eventPlans || [];
1806
+ this.response = options.meta?.response;
1797
1807
  }
1798
1808
  handleLayerChangeRequests() {
1799
1809
  if (this.layer.isOverlay()) {
1800
1810
  this.tryAcceptLayerFromServer();
1801
1811
  this.abortWhenLayerClosed();
1802
- this.layer.tryAcceptForLocation();
1812
+ this.layer.tryAcceptForLocation(this.responseOption());
1803
1813
  this.abortWhenLayerClosed();
1804
1814
  this.tryDismissLayerFromServer();
1805
1815
  this.abortWhenLayerClosed();
1806
- this.layer.tryDismissForLocation();
1816
+ this.layer.tryDismissForLocation(this.responseOption());
1807
1817
  this.abortWhenLayerClosed();
1808
1818
  }
1809
1819
  this.layer.asCurrent(() => {
1810
1820
  for (let eventPlan of this.eventPlans) {
1811
- up.emit(eventPlan);
1821
+ up.emit({ ...eventPlan, ...this.responseOption() });
1812
1822
  this.abortWhenLayerClosed();
1813
1823
  }
1814
1824
  });
1815
1825
  }
1816
1826
  tryAcceptLayerFromServer() {
1817
1827
  if (u.isDefined(this.acceptLayer) && this.layer.isOverlay()) {
1818
- this.layer.accept(this.acceptLayer);
1828
+ this.layer.accept(this.acceptLayer, this.responseOption());
1819
1829
  }
1820
1830
  }
1821
1831
  tryDismissLayerFromServer() {
1822
1832
  if (u.isDefined(this.dismissLayer) && this.layer.isOverlay()) {
1823
- this.layer.dismiss(this.dismissLayer);
1833
+ this.layer.dismiss(this.dismissLayer, this.responseOption());
1824
1834
  }
1825
1835
  }
1826
1836
  abortWhenLayerClosed() {
@@ -1847,6 +1857,9 @@ up.Change.Addition = class Addition extends up.Change {
1847
1857
  this.setTime(options);
1848
1858
  this.setETag(options);
1849
1859
  }
1860
+ responseOption() {
1861
+ return { response: this.response };
1862
+ }
1850
1863
  };
1851
1864
 
1852
1865
 
@@ -1876,7 +1889,7 @@ up.RenderJob = (_a = class RenderJob {
1876
1889
  if (result instanceof up.RenderResult) {
1877
1890
  if (!result.none)
1878
1891
  result.options.onRendered?.(result);
1879
- result.finished.then(result.options.onFinished);
1892
+ result.finished.then(result.options.onFinished, u.noop);
1880
1893
  return true;
1881
1894
  }
1882
1895
  }
@@ -1903,6 +1916,10 @@ up.RenderJob = (_a = class RenderJob {
1903
1916
  let onRequest = (request) => this.handleAbortOption(request);
1904
1917
  this.change = new up.Change.FromURL({ ...this.options, onRequest });
1905
1918
  }
1919
+ else if (this.options.response) {
1920
+ this.change = new up.Change.FromResponse(this.options);
1921
+ this.handleAbortOption(null);
1922
+ }
1906
1923
  else {
1907
1924
  this.change = new up.Change.FromContent(this.options);
1908
1925
  this.handleAbortOption(null);
@@ -2036,7 +2053,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2036
2053
  this.content = responseDoc.select(this.target);
2037
2054
  }
2038
2055
  if (!this.content || this.baseLayer.isClosed()) {
2039
- throw this.cannotMatch();
2056
+ throw new up.CannotMatch();
2040
2057
  }
2041
2058
  onApplicable();
2042
2059
  up.puts('up.render()', `Opening element "${this.target}" in new overlay`);
@@ -2044,8 +2061,8 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2044
2061
  if (this.emitOpenEvent().defaultPrevented) {
2045
2062
  throw new up.Aborted('Open event was prevented');
2046
2063
  }
2047
- this.baseLayer.peel();
2048
2064
  this.layer = this.buildLayer();
2065
+ this.baseLayer.peel({ history: !this.layer.history });
2049
2066
  up.layer.stack.push(this.layer);
2050
2067
  this.layer.createElements(this.content);
2051
2068
  this.layer.setupHandlers();
@@ -2179,7 +2196,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2179
2196
  up.viewport.saveFocus({ layer: this.layer });
2180
2197
  }
2181
2198
  if (this.options.peel) {
2182
- this.layer.peel();
2199
+ this.layer.peel({ history: !this.hasHistory() });
2183
2200
  }
2184
2201
  if (this.options.abort !== false) {
2185
2202
  up.fragment.abort(this.getFragments(), { reason: 'Fragment is being replaced' });
@@ -2352,7 +2369,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2352
2369
  return true;
2353
2370
  }
2354
2371
  else if (!step.maybe) {
2355
- throw this.cannotMatch(`Could not find element "${this.target}" in current page`);
2372
+ throw new up.CannotMatch();
2356
2373
  }
2357
2374
  });
2358
2375
  this.resolveOldNesting();
@@ -2368,7 +2385,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2368
2385
  return true;
2369
2386
  }
2370
2387
  else if (!step.maybe) {
2371
- throw this.cannotMatch(`Could not find element "${this.target}" in server response`);
2388
+ throw new up.CannotMatch();
2372
2389
  }
2373
2390
  });
2374
2391
  this.resolveOldNesting();
@@ -2471,6 +2488,8 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2471
2488
  this.origin = options.origin;
2472
2489
  this.value = options.value;
2473
2490
  this.preventable = options.preventable ?? true;
2491
+ this.response = options.response;
2492
+ this.history = options.history ?? true;
2474
2493
  }
2475
2494
  execute() {
2476
2495
  if (!this.layer.isOpen()) {
@@ -2484,7 +2503,9 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2484
2503
  const { parent } = this.layer;
2485
2504
  this.layer.peel();
2486
2505
  this.layer.stack.remove(this.layer);
2487
- parent.restoreHistory();
2506
+ if (this.history) {
2507
+ parent.restoreHistory();
2508
+ }
2488
2509
  this.handleFocus(parent);
2489
2510
  this.layer.teardownHandlers();
2490
2511
  this.layer.destroyElements(this.options);
@@ -2512,7 +2533,8 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2512
2533
  return up.event.build(name, {
2513
2534
  layer: this.layer,
2514
2535
  value: this.value,
2515
- origin: this.origin
2536
+ origin: this.origin,
2537
+ response: this.response,
2516
2538
  });
2517
2539
  }
2518
2540
  handleFocus(formerParent) {
@@ -2528,142 +2550,6 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2528
2550
  /* 31 */
2529
2551
  /***/ (() => {
2530
2552
 
2531
- var _a;
2532
- const u = up.util;
2533
- up.Change.FromContent = (_a = class FromContent extends up.Change {
2534
- constructor(options) {
2535
- super(options);
2536
- this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2537
- this.origin = this.options.origin;
2538
- this.preview = this.options.preview;
2539
- this.mode = this.options.mode;
2540
- if (this.origin) {
2541
- this.originLayer = up.layer.get(this.origin);
2542
- }
2543
- }
2544
- isRenderableLayer(layer) {
2545
- return (layer === 'new') || layer.isOpen();
2546
- }
2547
- getPlans() {
2548
- var _a;
2549
- let plans = [];
2550
- if (this.options.fragment) {
2551
- (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2552
- }
2553
- this.expandIntoPlans(plans, this.layers, this.options.target);
2554
- this.expandIntoPlans(plans, this.layers, this.options.fallback);
2555
- return plans;
2556
- }
2557
- expandIntoPlans(plans, layers, targets) {
2558
- for (let layer of layers) {
2559
- for (let target of this.expandTargets(targets, layer)) {
2560
- const props = { ...this.options, target, layer, defaultPlacement: this.defaultPlacement() };
2561
- const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2562
- plans.push(change);
2563
- }
2564
- }
2565
- }
2566
- expandTargets(targets, layer) {
2567
- return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2568
- }
2569
- execute() {
2570
- if (this.options.preload) {
2571
- return Promise.resolve();
2572
- }
2573
- return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2574
- }
2575
- executePlan(matchedPlan) {
2576
- let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2577
- result.options = this.options;
2578
- return result;
2579
- }
2580
- onPlanApplicable(plan) {
2581
- let primaryPlan = this.getPlans()[0];
2582
- if (plan !== primaryPlan) {
2583
- up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2584
- }
2585
- }
2586
- getResponseDoc() {
2587
- if (this.preview)
2588
- return;
2589
- const docOptions = u.pick(this.options, [
2590
- 'target',
2591
- 'content',
2592
- 'fragment',
2593
- 'document',
2594
- 'html',
2595
- 'cspNonces',
2596
- 'origin',
2597
- ]);
2598
- up.migrate.handleResponseDocOptions?.(docOptions);
2599
- if (this.defaultPlacement() === 'content') {
2600
- docOptions.target = this.firstExpandedTarget(docOptions.target);
2601
- }
2602
- return new up.ResponseDoc(docOptions);
2603
- }
2604
- defaultPlacement() {
2605
- if (!this.options.document && !this.options.fragment) {
2606
- return 'content';
2607
- }
2608
- }
2609
- firstExpandedTarget(target) {
2610
- return this.expandTargets(target || ':main', this.layers[0])[0];
2611
- }
2612
- getPreflightProps(opts = {}) {
2613
- const getPlanProps = plan => plan.getPreflightProps();
2614
- return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2615
- }
2616
- cannotMatchPreflightTarget() {
2617
- this.cannotMatchTarget('Could not find target in current page');
2618
- }
2619
- cannotMatchPostflightTarget() {
2620
- this.cannotMatchTarget('Could not find common target in current page and response');
2621
- }
2622
- cannotMatchTarget(reason) {
2623
- if (this.getPlans().length) {
2624
- const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2625
- const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2626
- up.fail(reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption);
2627
- }
2628
- else if (this.layers.length) {
2629
- if (this.options.failPrefixForced) {
2630
- up.fail('No target selector given for failed responses (https://unpoly.com/failed-responses)');
2631
- }
2632
- else {
2633
- up.fail('No target selector given');
2634
- }
2635
- }
2636
- else {
2637
- up.fail('Layer %o does not exist', this.options.layer);
2638
- }
2639
- }
2640
- seekPlan(fn) {
2641
- for (let plan of this.getPlans()) {
2642
- try {
2643
- return fn(plan);
2644
- }
2645
- catch (error) {
2646
- if (!(error instanceof up.CannotMatch)) {
2647
- throw error;
2648
- }
2649
- }
2650
- }
2651
- }
2652
- },
2653
- (() => {
2654
- u.memoizeMethod(_a.prototype, [
2655
- 'getPlans',
2656
- 'getResponseDoc',
2657
- 'getPreflightProps',
2658
- ]);
2659
- })(),
2660
- _a);
2661
-
2662
-
2663
- /***/ }),
2664
- /* 32 */
2665
- /***/ (() => {
2666
-
2667
2553
  var _a;
2668
2554
  const u = up.util;
2669
2555
  up.Change.FromURL = (_a = class FromURL extends up.Change {
@@ -2688,9 +2574,6 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2688
2574
  }
2689
2575
  return u.always(this.request, responseOrError => this.onRequestSettled(responseOrError));
2690
2576
  }
2691
- deriveFailOptions() {
2692
- return up.RenderOptions.deriveFailOptions(this.options);
2693
- }
2694
2577
  newPageReason() {
2695
2578
  if (u.isCrossOrigin(this.options.url)) {
2696
2579
  return 'Loading cross-origin content in new page';
@@ -2724,7 +2607,41 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2724
2607
  }
2725
2608
  }
2726
2609
  onRequestSettledWithResponse(response) {
2727
- this.response = response;
2610
+ return new up.Change.FromResponse({ ...this.options, response }).execute();
2611
+ }
2612
+ onRequestSettledWithError(error) {
2613
+ if (error instanceof up.Offline) {
2614
+ this.request.emit('up:fragment:offline', {
2615
+ callback: this.options.onOffline,
2616
+ renderOptions: this.options,
2617
+ retry: (retryOptions) => up.render({ ...this.options, ...retryOptions }),
2618
+ log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
2619
+ });
2620
+ }
2621
+ throw error;
2622
+ }
2623
+ },
2624
+ (() => {
2625
+ u.memoizeMethod(_a.prototype, [
2626
+ 'getRequestAttrs',
2627
+ ]);
2628
+ })(),
2629
+ _a);
2630
+
2631
+
2632
+ /***/ }),
2633
+ /* 32 */
2634
+ /***/ (() => {
2635
+
2636
+ var _a;
2637
+ const u = up.util;
2638
+ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2639
+ constructor(options) {
2640
+ super(options);
2641
+ this.response = options.response;
2642
+ this.request = this.response.request;
2643
+ }
2644
+ execute() {
2728
2645
  if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2729
2646
  this.skip();
2730
2647
  }
@@ -2736,40 +2653,12 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2736
2653
  skip: () => this.skip()
2737
2654
  });
2738
2655
  }
2739
- let fail = u.evalOption(this.options.fail, this.response) ?? !response.ok;
2656
+ let fail = u.evalOption(this.options.fail, this.response) ?? !this.response.ok;
2740
2657
  if (fail) {
2741
2658
  throw this.updateContentFromResponse(this.deriveFailOptions());
2742
2659
  }
2743
2660
  return this.updateContentFromResponse(this.options);
2744
2661
  }
2745
- compilerPassMeta() {
2746
- return u.pick(this.loadedEventProps(), [
2747
- 'revalidating',
2748
- 'response'
2749
- ]);
2750
- }
2751
- loadedEventProps() {
2752
- const { expiredResponse } = this.options;
2753
- return {
2754
- request: this.request,
2755
- response: this.response,
2756
- renderOptions: this.options,
2757
- revalidating: !!expiredResponse,
2758
- expiredResponse,
2759
- };
2760
- }
2761
- onRequestSettledWithError(error) {
2762
- if (error instanceof up.Offline) {
2763
- this.request.emit('up:fragment:offline', {
2764
- callback: this.options.onOffline,
2765
- response: this.response,
2766
- renderOptions: this.options,
2767
- retry: (retryOptions) => up.render({ ...this.options, ...retryOptions }),
2768
- log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
2769
- });
2770
- }
2771
- throw error;
2772
- }
2773
2662
  skip() {
2774
2663
  up.puts('up.render()', 'Skipping ' + this.response.description);
2775
2664
  this.options.target = ':none';
@@ -2818,6 +2707,22 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2818
2707
  }
2819
2708
  return renderResult;
2820
2709
  }
2710
+ loadedEventProps() {
2711
+ const { expiredResponse } = this.options;
2712
+ return {
2713
+ request: this.request,
2714
+ response: this.response,
2715
+ renderOptions: this.options,
2716
+ revalidating: !!expiredResponse,
2717
+ expiredResponse,
2718
+ };
2719
+ }
2720
+ compilerPassMeta() {
2721
+ return u.pick(this.loadedEventProps(), [
2722
+ 'revalidating',
2723
+ 'response'
2724
+ ]);
2725
+ }
2821
2726
  augmentOptionsFromResponse(renderOptions) {
2822
2727
  const responseURL = this.response.url;
2823
2728
  let serverLocation = responseURL;
@@ -2826,44 +2731,181 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2826
2731
  renderOptions.hash = hash;
2827
2732
  serverLocation += hash;
2828
2733
  }
2829
- const isReloadable = (this.response.method === 'GET');
2830
- if (isReloadable) {
2831
- renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2734
+ const isReloadable = (this.response.method === 'GET');
2735
+ if (isReloadable) {
2736
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2737
+ }
2738
+ else {
2739
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2740
+ renderOptions.history = !!renderOptions.location;
2741
+ }
2742
+ renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2743
+ renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2744
+ renderOptions.eventPlans = this.response.eventPlans;
2745
+ let serverTarget = this.response.target;
2746
+ if (serverTarget) {
2747
+ renderOptions.target = serverTarget;
2748
+ }
2749
+ renderOptions.acceptLayer = this.response.acceptLayer;
2750
+ renderOptions.dismissLayer = this.response.dismissLayer;
2751
+ renderOptions.document = this.response.text;
2752
+ if (this.response.none) {
2753
+ renderOptions.target = ':none';
2754
+ }
2755
+ renderOptions.context = u.merge(renderOptions.context, this.response.context);
2756
+ renderOptions.cspNonces = this.response.cspNonces;
2757
+ renderOptions.time ?? (renderOptions.time = this.response.lastModified);
2758
+ renderOptions.etag ?? (renderOptions.etag = this.response.etag);
2759
+ }
2760
+ },
2761
+ (() => {
2762
+ u.memoizeMethod(_a.prototype, [
2763
+ 'loadedEventProps',
2764
+ ]);
2765
+ })(),
2766
+ _a);
2767
+
2768
+
2769
+ /***/ }),
2770
+ /* 33 */
2771
+ /***/ (() => {
2772
+
2773
+ var _a;
2774
+ const u = up.util;
2775
+ up.Change.FromContent = (_a = class FromContent extends up.Change {
2776
+ constructor(options) {
2777
+ super(options);
2778
+ this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2779
+ this.origin = this.options.origin;
2780
+ this.preview = this.options.preview;
2781
+ this.mode = this.options.mode;
2782
+ if (this.origin) {
2783
+ this.originLayer = up.layer.get(this.origin);
2784
+ }
2785
+ }
2786
+ isRenderableLayer(layer) {
2787
+ return (layer === 'new') || layer.isOpen();
2788
+ }
2789
+ getPlans() {
2790
+ var _a;
2791
+ let plans = [];
2792
+ if (this.options.fragment) {
2793
+ (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2794
+ }
2795
+ this.expandIntoPlans(plans, this.layers, this.options.target);
2796
+ this.expandIntoPlans(plans, this.layers, this.options.fallback);
2797
+ return plans;
2798
+ }
2799
+ expandIntoPlans(plans, layers, targets) {
2800
+ for (let layer of layers) {
2801
+ for (let target of this.expandTargets(targets, layer)) {
2802
+ const props = { ...this.options, target, layer, defaultPlacement: this.defaultPlacement() };
2803
+ const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2804
+ plans.push(change);
2805
+ }
2806
+ }
2807
+ }
2808
+ expandTargets(targets, layer) {
2809
+ return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2810
+ }
2811
+ execute() {
2812
+ if (this.options.preload) {
2813
+ return Promise.resolve();
2814
+ }
2815
+ return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2816
+ }
2817
+ executePlan(matchedPlan) {
2818
+ let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2819
+ result.options = this.options;
2820
+ return result;
2821
+ }
2822
+ onPlanApplicable(plan) {
2823
+ let primaryPlan = this.getPlans()[0];
2824
+ if (plan !== primaryPlan) {
2825
+ up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2826
+ }
2827
+ }
2828
+ getResponseDoc() {
2829
+ if (this.preview)
2830
+ return;
2831
+ const docOptions = u.pick(this.options, [
2832
+ 'target',
2833
+ 'content',
2834
+ 'fragment',
2835
+ 'document',
2836
+ 'html',
2837
+ 'cspNonces',
2838
+ 'origin',
2839
+ ]);
2840
+ up.migrate.handleResponseDocOptions?.(docOptions);
2841
+ if (this.defaultPlacement() === 'content') {
2842
+ docOptions.target = this.firstExpandedTarget(docOptions.target);
2843
+ }
2844
+ return new up.ResponseDoc(docOptions);
2845
+ }
2846
+ defaultPlacement() {
2847
+ if (!this.options.document && !this.options.fragment) {
2848
+ return 'content';
2849
+ }
2850
+ }
2851
+ firstExpandedTarget(target) {
2852
+ return this.expandTargets(target || ':main', this.layers[0])[0];
2853
+ }
2854
+ getPreflightProps(opts = {}) {
2855
+ const getPlanProps = plan => plan.getPreflightProps();
2856
+ return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2857
+ }
2858
+ cannotMatchPreflightTarget() {
2859
+ this.cannotMatchTarget('Could not find target in current page');
2860
+ }
2861
+ cannotMatchPostflightTarget() {
2862
+ this.cannotMatchTarget('Could not find common target in current page and response');
2863
+ }
2864
+ cannotMatchTarget(reason) {
2865
+ let message;
2866
+ if (this.getPlans().length) {
2867
+ const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2868
+ const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2869
+ message = [reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption];
2870
+ }
2871
+ else if (this.layers.length) {
2872
+ if (this.options.failPrefixForced) {
2873
+ message = 'No target selector given for failed responses (https://unpoly.com/failed-responses)';
2874
+ }
2875
+ else {
2876
+ message = 'No target selector given';
2877
+ }
2832
2878
  }
2833
2879
  else {
2834
- renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2835
- renderOptions.history = !!renderOptions.location;
2836
- }
2837
- renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2838
- renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2839
- renderOptions.eventPlans = this.response.eventPlans;
2840
- let serverTarget = this.response.target;
2841
- if (serverTarget) {
2842
- renderOptions.target = serverTarget;
2880
+ message = 'Could not find a layer to render in. You may have passed a non-existing layer reference, or a detached element.';
2843
2881
  }
2844
- renderOptions.acceptLayer = this.response.acceptLayer;
2845
- renderOptions.dismissLayer = this.response.dismissLayer;
2846
- renderOptions.document = this.response.text;
2847
- if (!renderOptions.document) {
2848
- renderOptions.target = ':none';
2882
+ throw new up.CannotMatch(message);
2883
+ }
2884
+ seekPlan(fn) {
2885
+ for (let plan of this.getPlans()) {
2886
+ try {
2887
+ return fn(plan);
2888
+ }
2889
+ catch (error) {
2890
+ if (!(error instanceof up.CannotMatch)) {
2891
+ throw error;
2892
+ }
2893
+ }
2849
2894
  }
2850
- renderOptions.context = u.merge(renderOptions.context, this.response.context);
2851
- renderOptions.cspNonces = this.response.cspNonces;
2852
- renderOptions.time ?? (renderOptions.time = this.response.lastModified);
2853
- renderOptions.etag ?? (renderOptions.etag = this.response.etag);
2854
2895
  }
2855
2896
  },
2856
2897
  (() => {
2857
2898
  u.memoizeMethod(_a.prototype, [
2858
- 'getRequestAttrs',
2859
- 'loadedEventProps',
2899
+ 'getPlans',
2900
+ 'getResponseDoc',
2901
+ 'getPreflightProps',
2860
2902
  ]);
2861
2903
  })(),
2862
2904
  _a);
2863
2905
 
2864
2906
 
2865
2907
  /***/ }),
2866
- /* 33 */
2908
+ /* 34 */
2867
2909
  /***/ (() => {
2868
2910
 
2869
2911
  const u = up.util;
@@ -2949,7 +2991,6 @@ up.CompilerPass = class CompilerPass {
2949
2991
  catch (error) {
2950
2992
  this.errors.push(error);
2951
2993
  up.log.error('up.hello()', 'While compiling %o: %o', elementOrElements, error);
2952
- up.error.emitGlobal(error);
2953
2994
  }
2954
2995
  }
2955
2996
  destructorPresence(result) {
@@ -2974,7 +3015,7 @@ up.CompilerPass = class CompilerPass {
2974
3015
 
2975
3016
 
2976
3017
  /***/ }),
2977
- /* 34 */
3018
+ /* 35 */
2978
3019
  /***/ (() => {
2979
3020
 
2980
3021
  const u = up.util;
@@ -3085,7 +3126,7 @@ up.CSSTransition = class CSSTransition {
3085
3126
 
3086
3127
 
3087
3128
  /***/ }),
3088
- /* 35 */
3129
+ /* 36 */
3089
3130
  /***/ (() => {
3090
3131
 
3091
3132
  const u = up.util;
@@ -3120,14 +3161,13 @@ up.DestructorPass = class DestructorPass {
3120
3161
  catch (error) {
3121
3162
  this.errors.push(error);
3122
3163
  up.log.error('up.destroy()', 'While destroying %o: %o', element, error);
3123
- up.error.emitGlobal(error);
3124
3164
  }
3125
3165
  }
3126
3166
  };
3127
3167
 
3128
3168
 
3129
3169
  /***/ }),
3130
- /* 36 */
3170
+ /* 37 */
3131
3171
  /***/ (() => {
3132
3172
 
3133
3173
  const u = up.util;
@@ -3226,7 +3266,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3226
3266
 
3227
3267
 
3228
3268
  /***/ }),
3229
- /* 37 */
3269
+ /* 38 */
3230
3270
  /***/ (() => {
3231
3271
 
3232
3272
  const u = up.util;
@@ -3289,6 +3329,9 @@ up.EventListener = class EventListener extends up.Record {
3289
3329
  const data = up.syntax.data(element);
3290
3330
  args.push(data);
3291
3331
  }
3332
+ if (this.eventType === 'click' && element.disabled) {
3333
+ return;
3334
+ }
3292
3335
  const applyCallback = this.callback.bind(element, ...args);
3293
3336
  if (this.baseLayer) {
3294
3337
  this.baseLayer.asCurrent(applyCallback);
@@ -3328,7 +3371,7 @@ up.EventListener = class EventListener extends up.Record {
3328
3371
 
3329
3372
 
3330
3373
  /***/ }),
3331
- /* 38 */
3374
+ /* 39 */
3332
3375
  /***/ (() => {
3333
3376
 
3334
3377
  const u = up.util;
@@ -3400,7 +3443,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3400
3443
 
3401
3444
 
3402
3445
  /***/ }),
3403
- /* 39 */
3446
+ /* 40 */
3404
3447
  /***/ (() => {
3405
3448
 
3406
3449
  const u = up.util;
@@ -3516,7 +3559,7 @@ up.FieldWatcher = class FieldWatcher {
3516
3559
 
3517
3560
 
3518
3561
  /***/ }),
3519
- /* 40 */
3562
+ /* 41 */
3520
3563
  /***/ (() => {
3521
3564
 
3522
3565
  const u = up.util;
@@ -3690,7 +3733,7 @@ up.FormValidator = class FormValidator {
3690
3733
 
3691
3734
 
3692
3735
  /***/ }),
3693
- /* 41 */
3736
+ /* 42 */
3694
3737
  /***/ (() => {
3695
3738
 
3696
3739
  up.FocusCapsule = class FocusCapsule {
@@ -3720,7 +3763,7 @@ up.FocusCapsule = class FocusCapsule {
3720
3763
 
3721
3764
 
3722
3765
  /***/ }),
3723
- /* 42 */
3766
+ /* 43 */
3724
3767
  /***/ (() => {
3725
3768
 
3726
3769
  const u = up.util;
@@ -3784,7 +3827,7 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
3784
3827
 
3785
3828
 
3786
3829
  /***/ }),
3787
- /* 43 */
3830
+ /* 44 */
3788
3831
  /***/ (() => {
3789
3832
 
3790
3833
  const DESCENDANT_SELECTOR = /^([^ >+(]+) (.+)$/;
@@ -3827,7 +3870,7 @@ up.FragmentFinder = class FragmentFinder {
3827
3870
 
3828
3871
 
3829
3872
  /***/ }),
3830
- /* 44 */
3873
+ /* 45 */
3831
3874
  /***/ (() => {
3832
3875
 
3833
3876
  const u = up.util;
@@ -3911,7 +3954,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
3911
3954
 
3912
3955
 
3913
3956
  /***/ }),
3914
- /* 45 */
3957
+ /* 46 */
3915
3958
  /***/ (() => {
3916
3959
 
3917
3960
  const e = up.element;
@@ -3995,9 +4038,7 @@ up.FragmentPolling = class FragmentPolling {
3995
4038
  }
3996
4039
  onReloadFailure(reason) {
3997
4040
  this.scheduleReload();
3998
- if (up.error.isCritical(reason)) {
3999
- throw reason;
4000
- }
4041
+ up.error.rethrowCritical(reason);
4001
4042
  }
4002
4043
  onFragmentSwapped(newFragment) {
4003
4044
  this.stop();
@@ -4018,7 +4059,7 @@ up.FragmentPolling = class FragmentPolling {
4018
4059
 
4019
4060
 
4020
4061
  /***/ }),
4021
- /* 46 */
4062
+ /* 47 */
4022
4063
  /***/ (() => {
4023
4064
 
4024
4065
  const u = up.util;
@@ -4082,7 +4123,7 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4082
4123
 
4083
4124
 
4084
4125
  /***/ }),
4085
- /* 47 */
4126
+ /* 48 */
4086
4127
  /***/ (() => {
4087
4128
 
4088
4129
  const e = up.element;
@@ -4305,7 +4346,7 @@ up.Layer = class Layer extends up.Record {
4305
4346
 
4306
4347
 
4307
4348
  /***/ }),
4308
- /* 48 */
4349
+ /* 49 */
4309
4350
  /***/ (() => {
4310
4351
 
4311
4352
  const e = up.element;
@@ -4487,7 +4528,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4487
4528
  parser.string('easing');
4488
4529
  parser.number('duration');
4489
4530
  parser.string('confirm');
4490
- closeFn(value, closeOptions);
4531
+ up.error.muteUncriticalSync(() => closeFn(value, closeOptions));
4491
4532
  });
4492
4533
  }
4493
4534
  registerEventCloser(eventTypes, closeFn) {
@@ -4496,20 +4537,20 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4496
4537
  }
4497
4538
  return this.on(eventTypes, event => {
4498
4539
  event.preventDefault();
4499
- closeFn.call(this, event);
4540
+ closeFn.call(this, event, { response: event.response });
4500
4541
  });
4501
4542
  }
4502
- tryAcceptForLocation() {
4503
- this.tryCloseForLocation(this.acceptLocation, this.accept);
4543
+ tryAcceptForLocation(options) {
4544
+ this.tryCloseForLocation(this.acceptLocation, this.accept, options);
4504
4545
  }
4505
- tryDismissForLocation() {
4506
- this.tryCloseForLocation(this.dismissLocation, this.dismiss);
4546
+ tryDismissForLocation(options) {
4547
+ this.tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4507
4548
  }
4508
- tryCloseForLocation(urlPattern, closeFn) {
4549
+ tryCloseForLocation(urlPattern, closeFn, options) {
4509
4550
  let location, resolution;
4510
4551
  if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
4511
4552
  const closeValue = { ...resolution, location };
4512
- closeFn.call(this, closeValue);
4553
+ closeFn.call(this, closeValue, options);
4513
4554
  }
4514
4555
  }
4515
4556
  teardownHandlers() {
@@ -4580,7 +4621,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4580
4621
 
4581
4622
 
4582
4623
  /***/ }),
4583
- /* 49 */
4624
+ /* 50 */
4584
4625
  /***/ (() => {
4585
4626
 
4586
4627
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -4617,7 +4658,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
4617
4658
 
4618
4659
 
4619
4660
  /***/ }),
4620
- /* 50 */
4661
+ /* 51 */
4621
4662
  /***/ (() => {
4622
4663
 
4623
4664
  var _a;
@@ -4655,19 +4696,19 @@ up.Layer.OverlayWithViewport = (_a = class OverlayWithViewport extends up.Layer.
4655
4696
 
4656
4697
 
4657
4698
  /***/ }),
4658
- /* 51 */
4699
+ /* 52 */
4659
4700
  /***/ (() => {
4660
4701
 
4661
4702
  var _a;
4662
4703
  const e = up.element;
4663
4704
  up.Layer.Root = (_a = class Root extends up.Layer {
4705
+ get element() {
4706
+ return e.root;
4707
+ }
4664
4708
  constructor(options) {
4665
4709
  super(options);
4666
4710
  this.setupHandlers();
4667
4711
  }
4668
- get element() {
4669
- return e.root;
4670
- }
4671
4712
  getFirstSwappableElement() {
4672
4713
  return document.body;
4673
4714
  }
@@ -4701,7 +4742,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4701
4742
 
4702
4743
 
4703
4744
  /***/ }),
4704
- /* 52 */
4745
+ /* 53 */
4705
4746
  /***/ (() => {
4706
4747
 
4707
4748
  var _a;
@@ -4712,7 +4753,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
4712
4753
 
4713
4754
 
4714
4755
  /***/ }),
4715
- /* 53 */
4756
+ /* 54 */
4716
4757
  /***/ (() => {
4717
4758
 
4718
4759
  var _a;
@@ -4723,7 +4764,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
4723
4764
 
4724
4765
 
4725
4766
  /***/ }),
4726
- /* 54 */
4767
+ /* 55 */
4727
4768
  /***/ (() => {
4728
4769
 
4729
4770
  var _a;
@@ -4734,7 +4775,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
4734
4775
 
4735
4776
 
4736
4777
  /***/ }),
4737
- /* 55 */
4778
+ /* 56 */
4738
4779
  /***/ (() => {
4739
4780
 
4740
4781
  var _a;
@@ -4745,7 +4786,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
4745
4786
 
4746
4787
 
4747
4788
  /***/ }),
4748
- /* 56 */
4789
+ /* 57 */
4749
4790
  /***/ (() => {
4750
4791
 
4751
4792
  const u = up.util;
@@ -4835,7 +4876,7 @@ up.LayerLookup = class LayerLookup {
4835
4876
 
4836
4877
 
4837
4878
  /***/ }),
4838
- /* 57 */
4879
+ /* 58 */
4839
4880
  /***/ (() => {
4840
4881
 
4841
4882
  const u = up.util;
@@ -4948,7 +4989,7 @@ up.LayerStack = class LayerStack extends Array {
4948
4989
 
4949
4990
 
4950
4991
  /***/ }),
4951
- /* 58 */
4992
+ /* 59 */
4952
4993
  /***/ (() => {
4953
4994
 
4954
4995
  up.LinkFeedbackURLs = class LinkFeedbackURLs {
@@ -4979,7 +5020,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
4979
5020
 
4980
5021
 
4981
5022
  /***/ }),
4982
- /* 59 */
5023
+ /* 60 */
4983
5024
  /***/ (() => {
4984
5025
 
4985
5026
  const u = up.util;
@@ -5047,7 +5088,7 @@ up.LinkPreloader = class LinkPreloader {
5047
5088
 
5048
5089
 
5049
5090
  /***/ }),
5050
- /* 60 */
5091
+ /* 61 */
5051
5092
  /***/ (() => {
5052
5093
 
5053
5094
  const u = up.util;
@@ -5143,7 +5184,7 @@ up.MotionController = class MotionController {
5143
5184
 
5144
5185
 
5145
5186
  /***/ }),
5146
- /* 61 */
5187
+ /* 62 */
5147
5188
  /***/ (() => {
5148
5189
 
5149
5190
  const u = up.util;
@@ -5235,7 +5276,7 @@ up.NonceableCallback = class NonceableCallback {
5235
5276
 
5236
5277
 
5237
5278
  /***/ }),
5238
- /* 62 */
5279
+ /* 63 */
5239
5280
  /***/ (() => {
5240
5281
 
5241
5282
  const u = up.util;
@@ -5312,7 +5353,7 @@ up.OptionsParser = class OptionsParser {
5312
5353
 
5313
5354
 
5314
5355
  /***/ }),
5315
- /* 63 */
5356
+ /* 64 */
5316
5357
  /***/ (() => {
5317
5358
 
5318
5359
  const e = up.element;
@@ -5380,7 +5421,7 @@ up.OverlayFocus = class OverlayFocus {
5380
5421
 
5381
5422
 
5382
5423
  /***/ }),
5383
- /* 64 */
5424
+ /* 65 */
5384
5425
  /***/ (() => {
5385
5426
 
5386
5427
  const u = up.util;
@@ -5611,7 +5652,7 @@ up.Params = class Params {
5611
5652
 
5612
5653
 
5613
5654
  /***/ }),
5614
- /* 65 */
5655
+ /* 66 */
5615
5656
  /***/ (() => {
5616
5657
 
5617
5658
  const e = up.element;
@@ -5661,7 +5702,7 @@ up.ProgressBar = class ProgressBar {
5661
5702
 
5662
5703
 
5663
5704
  /***/ }),
5664
- /* 66 */
5705
+ /* 67 */
5665
5706
  /***/ (() => {
5666
5707
 
5667
5708
  const u = up.util;
@@ -5710,14 +5751,15 @@ up.RenderOptions = (function () {
5710
5751
  ]);
5711
5752
  const CONTENT_KEYS = [
5712
5753
  'url',
5754
+ 'response',
5713
5755
  'content',
5714
5756
  'fragment',
5715
- 'document'
5757
+ 'document',
5716
5758
  ];
5717
5759
  const LATE_KEYS = [
5718
5760
  'history',
5719
5761
  'focus',
5720
- 'scroll'
5762
+ 'scroll',
5721
5763
  ];
5722
5764
  function navigateDefaults(options) {
5723
5765
  if (options.navigate) {
@@ -5784,7 +5826,7 @@ up.RenderOptions = (function () {
5784
5826
 
5785
5827
 
5786
5828
  /***/ }),
5787
- /* 67 */
5829
+ /* 68 */
5788
5830
  /***/ (() => {
5789
5831
 
5790
5832
  up.RenderResult = class RenderResult extends up.Record {
@@ -5812,32 +5854,12 @@ up.RenderResult = class RenderResult extends up.Record {
5812
5854
 
5813
5855
 
5814
5856
  /***/ }),
5815
- /* 68 */
5857
+ /* 69 */
5816
5858
  /***/ (() => {
5817
5859
 
5818
5860
  var _a;
5819
5861
  const u = up.util;
5820
5862
  up.Request = (_a = class Request extends up.Record {
5821
- constructor(options) {
5822
- super(options);
5823
- this.params = new up.Params(this.params);
5824
- if (this.wrapMethod == null) {
5825
- this.wrapMethod = up.network.config.wrapMethod;
5826
- }
5827
- this.normalize();
5828
- if ((this.target || this.layer || this.origin) && !options.basic) {
5829
- const layerLookupOptions = { origin: this.origin };
5830
- this.layer = up.layer.get(this.layer, layerLookupOptions);
5831
- this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5832
- this.context || (this.context = this.layer.context || {});
5833
- this.failContext || (this.failContext = this.failLayer.context || {});
5834
- this.mode || (this.mode = this.layer.mode);
5835
- this.failMode || (this.failMode = this.failLayer.mode);
5836
- }
5837
- this.deferred = u.newDeferred();
5838
- this.badResponseTime ?? (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5839
- this.addAutoHeaders();
5840
- }
5841
5863
  keys() {
5842
5864
  return [
5843
5865
  'method',
@@ -5880,17 +5902,39 @@ up.Request = (_a = class Request extends up.Record {
5880
5902
  builtAt: new Date(),
5881
5903
  };
5882
5904
  }
5905
+ constructor(options) {
5906
+ super(options);
5907
+ this.params = new up.Params(this.params);
5908
+ if (this.wrapMethod == null) {
5909
+ this.wrapMethod = up.network.config.wrapMethod;
5910
+ }
5911
+ this.normalize();
5912
+ if ((this.target || this.layer || this.origin) && !options.basic) {
5913
+ const layerLookupOptions = { origin: this.origin };
5914
+ this.layer = up.layer.get(this.layer, layerLookupOptions);
5915
+ this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5916
+ this.context || (this.context = this.layer.context || {});
5917
+ this.failContext || (this.failContext = this.failLayer.context || {});
5918
+ this.mode || (this.mode = this.layer.mode);
5919
+ this.failMode || (this.failMode = this.failLayer.mode);
5920
+ }
5921
+ this.deferred = u.newDeferred();
5922
+ this.badResponseTime ?? (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5923
+ this.addAutoHeaders();
5924
+ }
5883
5925
  get xhr() {
5884
5926
  return this._xhr ?? (this._xhr = new XMLHttpRequest());
5885
5927
  }
5886
5928
  get fragments() {
5887
- if (!this._fragments && this.target) {
5929
+ if (this._fragments) {
5930
+ return this._fragments;
5931
+ }
5932
+ else if (this.target) {
5888
5933
  let steps = up.fragment.parseTargetSteps(this.target);
5889
5934
  let selectors = u.map(steps, 'selector');
5890
5935
  let lookupOpts = { origin: this.origin, layer: this.layer };
5891
- this._fragments = u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5936
+ return u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5892
5937
  }
5893
- return this._fragments;
5894
5938
  }
5895
5939
  set fragments(value) {
5896
5940
  this._fragments = value;
@@ -6147,7 +6191,7 @@ up.Request = (_a = class Request extends up.Record {
6147
6191
 
6148
6192
 
6149
6193
  /***/ }),
6150
- /* 69 */
6194
+ /* 70 */
6151
6195
  /***/ (() => {
6152
6196
 
6153
6197
  const u = up.util;
@@ -6237,6 +6281,7 @@ up.Request.Cache = class Cache {
6237
6281
  if (value instanceof up.Response) {
6238
6282
  if (options.force || this.isCacheCompatible(existingRequest, newRequest)) {
6239
6283
  newRequest.fromCache = true;
6284
+ value = u.variant(value, { request: newRequest });
6240
6285
  newRequest.respondWith(value);
6241
6286
  u.delegate(newRequest, ['expired', 'state'], () => existingRequest);
6242
6287
  }
@@ -6286,7 +6331,7 @@ up.Request.Cache = class Cache {
6286
6331
 
6287
6332
 
6288
6333
  /***/ }),
6289
- /* 70 */
6334
+ /* 71 */
6290
6335
  /***/ (() => {
6291
6336
 
6292
6337
  const u = up.util;
@@ -6394,7 +6439,7 @@ up.Request.Queue = class Queue {
6394
6439
 
6395
6440
 
6396
6441
  /***/ }),
6397
- /* 71 */
6442
+ /* 72 */
6398
6443
  /***/ (() => {
6399
6444
 
6400
6445
  const u = up.util;
@@ -6433,7 +6478,7 @@ up.Request.FormRenderer = class FormRenderer {
6433
6478
 
6434
6479
 
6435
6480
  /***/ }),
6436
- /* 72 */
6481
+ /* 73 */
6437
6482
  /***/ (() => {
6438
6483
 
6439
6484
  var _a;
@@ -6505,7 +6550,7 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6505
6550
 
6506
6551
 
6507
6552
  /***/ }),
6508
- /* 73 */
6553
+ /* 74 */
6509
6554
  /***/ (() => {
6510
6555
 
6511
6556
  const u = up.util;
@@ -6540,6 +6585,12 @@ up.Response = class Response extends up.Record {
6540
6585
  get ok() {
6541
6586
  return !u.evalOption(this.fail ?? up.network.config.fail, this);
6542
6587
  }
6588
+ get none() {
6589
+ return !this.text;
6590
+ }
6591
+ isCacheable() {
6592
+ return this.ok && !this.none;
6593
+ }
6543
6594
  header(name) {
6544
6595
  return this.headers[name] || this.xhr?.getResponseHeader(name);
6545
6596
  }
@@ -6580,7 +6631,7 @@ up.Response = class Response extends up.Record {
6580
6631
 
6581
6632
 
6582
6633
  /***/ }),
6583
- /* 74 */
6634
+ /* 75 */
6584
6635
  /***/ (() => {
6585
6636
 
6586
6637
  var _a;
@@ -6660,7 +6711,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
6660
6711
 
6661
6712
 
6662
6713
  /***/ }),
6663
- /* 75 */
6714
+ /* 76 */
6664
6715
  /***/ (() => {
6665
6716
 
6666
6717
  const e = up.element;
@@ -6754,7 +6805,7 @@ up.RevealMotion = class RevealMotion {
6754
6805
 
6755
6806
 
6756
6807
  /***/ }),
6757
- /* 76 */
6808
+ /* 77 */
6758
6809
  /***/ (() => {
6759
6810
 
6760
6811
  const u = up.util;
@@ -6795,7 +6846,7 @@ up.Selector = class Selector {
6795
6846
 
6796
6847
 
6797
6848
  /***/ }),
6798
- /* 77 */
6849
+ /* 78 */
6799
6850
  /***/ (() => {
6800
6851
 
6801
6852
  const u = up.util;
@@ -6915,7 +6966,7 @@ up.Tether = class Tether {
6915
6966
 
6916
6967
 
6917
6968
  /***/ }),
6918
- /* 78 */
6969
+ /* 79 */
6919
6970
  /***/ (() => {
6920
6971
 
6921
6972
  const u = up.util;
@@ -6995,7 +7046,7 @@ up.URLPattern = class URLPattern {
6995
7046
 
6996
7047
 
6997
7048
  /***/ }),
6998
- /* 79 */
7049
+ /* 80 */
6999
7050
  /***/ (() => {
7000
7051
 
7001
7052
  up.framework = (function () {
@@ -7079,7 +7130,7 @@ up.boot = up.framework.boot;
7079
7130
 
7080
7131
 
7081
7132
  /***/ }),
7082
- /* 80 */
7133
+ /* 81 */
7083
7134
  /***/ (() => {
7084
7135
 
7085
7136
  up.event = (function () {
@@ -7182,7 +7233,7 @@ up.emit = up.event.emit;
7182
7233
 
7183
7234
 
7184
7235
  /***/ }),
7185
- /* 81 */
7236
+ /* 82 */
7186
7237
  /***/ (() => {
7187
7238
 
7188
7239
  up.protocol = (function () {
@@ -7323,7 +7374,7 @@ up.protocol = (function () {
7323
7374
 
7324
7375
 
7325
7376
  /***/ }),
7326
- /* 82 */
7377
+ /* 83 */
7327
7378
  /***/ (() => {
7328
7379
 
7329
7380
  up.log = (function () {
@@ -7408,7 +7459,7 @@ up.warn = up.log.warn;
7408
7459
 
7409
7460
 
7410
7461
  /***/ }),
7411
- /* 83 */
7462
+ /* 84 */
7412
7463
  /***/ (() => {
7413
7464
 
7414
7465
  up.syntax = (function () {
@@ -7558,7 +7609,7 @@ up.hello = up.syntax.hello;
7558
7609
 
7559
7610
 
7560
7611
  /***/ }),
7561
- /* 84 */
7612
+ /* 85 */
7562
7613
  /***/ (() => {
7563
7614
 
7564
7615
  up.history = (function () {
@@ -7651,6 +7702,7 @@ up.history = (function () {
7651
7702
  }
7652
7703
  function onPop(event) {
7653
7704
  trackCurrentLocation();
7705
+ let location = currentLocation();
7654
7706
  emitLocationChanged({ location, reason: 'pop', log: `Navigated to history entry ${location}` });
7655
7707
  up.viewport.saveFocus({ location: previousLocation });
7656
7708
  up.viewport.saveScroll({ location: previousLocation });
@@ -7694,10 +7746,10 @@ up.history = (function () {
7694
7746
 
7695
7747
 
7696
7748
  /***/ }),
7697
- /* 85 */
7749
+ /* 86 */
7698
7750
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
7699
7751
 
7700
- __webpack_require__(86);
7752
+ __webpack_require__(87);
7701
7753
  const u = up.util;
7702
7754
  const e = up.element;
7703
7755
  up.fragment = (function () {
@@ -8224,7 +8276,7 @@ u.delegate(up, ['context'], () => up.layer.current);
8224
8276
 
8225
8277
 
8226
8278
  /***/ }),
8227
- /* 86 */
8279
+ /* 87 */
8228
8280
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8229
8281
 
8230
8282
  "use strict";
@@ -8233,10 +8285,10 @@ __webpack_require__.r(__webpack_exports__);
8233
8285
 
8234
8286
 
8235
8287
  /***/ }),
8236
- /* 87 */
8288
+ /* 88 */
8237
8289
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8238
8290
 
8239
- __webpack_require__(88);
8291
+ __webpack_require__(89);
8240
8292
  up.viewport = (function () {
8241
8293
  const u = up.util;
8242
8294
  const e = up.element;
@@ -8556,7 +8608,7 @@ up.reveal = up.viewport.reveal;
8556
8608
 
8557
8609
 
8558
8610
  /***/ }),
8559
- /* 88 */
8611
+ /* 89 */
8560
8612
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8561
8613
 
8562
8614
  "use strict";
@@ -8565,7 +8617,7 @@ __webpack_require__.r(__webpack_exports__);
8565
8617
 
8566
8618
 
8567
8619
  /***/ }),
8568
- /* 89 */
8620
+ /* 90 */
8569
8621
  /***/ (() => {
8570
8622
 
8571
8623
  up.motion = (function () {
@@ -8758,8 +8810,11 @@ up.motion = (function () {
8758
8810
  function translateCSS(dx, dy) {
8759
8811
  return { transform: `translate(${dx}px, ${dy}px)` };
8760
8812
  }
8813
+ function noTranslateCSS() {
8814
+ return { transform: null };
8815
+ }
8761
8816
  function untranslatedBox(element) {
8762
- e.setStyle(element, translateCSS(0, 0));
8817
+ e.setStyle(element, noTranslateCSS());
8763
8818
  return element.getBoundingClientRect();
8764
8819
  }
8765
8820
  function registerMoveAnimations(direction, boxToTransform) {
@@ -8774,7 +8829,7 @@ up.motion = (function () {
8774
8829
  const box = untranslatedBox(element);
8775
8830
  const transform = boxToTransform(box);
8776
8831
  e.setStyle(element, transform);
8777
- return animateNow(element, translateCSS(0, 0), options);
8832
+ return animateNow(element, noTranslateCSS(), options);
8778
8833
  });
8779
8834
  }
8780
8835
  registerMoveAnimations('top', function (box) {
@@ -8820,10 +8875,10 @@ up.animate = up.motion.animate;
8820
8875
 
8821
8876
 
8822
8877
  /***/ }),
8823
- /* 90 */
8878
+ /* 91 */
8824
8879
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8825
8880
 
8826
- __webpack_require__(91);
8881
+ __webpack_require__(92);
8827
8882
  const u = up.util;
8828
8883
  up.network = (function () {
8829
8884
  const config = new up.Config(() => ({
@@ -8891,19 +8946,19 @@ up.network = (function () {
8891
8946
  cache.put(request);
8892
8947
  request.onLoading = () => cache.put(request);
8893
8948
  }
8894
- u.always(request, function (response) {
8895
- let expireCache = response.expireCache ?? request.expireCache ?? u.evalOption(config.expireCache, request, response);
8949
+ u.always(request, function (responseOrError) {
8950
+ let expireCache = responseOrError.expireCache ?? request.expireCache ?? u.evalOption(config.expireCache, request, responseOrError);
8896
8951
  if (expireCache) {
8897
8952
  cache.expire(expireCache, { except: request });
8898
8953
  }
8899
- let evictCache = response.evictCache ?? request.evictCache ?? u.evalOption(config.evictCache, request, response);
8954
+ let evictCache = responseOrError.evictCache ?? request.evictCache ?? u.evalOption(config.evictCache, request, responseOrError);
8900
8955
  if (evictCache) {
8901
8956
  cache.evict(evictCache, { except: request });
8902
8957
  }
8903
8958
  if (cache.get(request)) {
8904
8959
  cache.put(request);
8905
8960
  }
8906
- if (!response.ok) {
8961
+ if (!responseOrError.isCacheable?.()) {
8907
8962
  cache.evict(request);
8908
8963
  }
8909
8964
  });
@@ -8927,7 +8982,7 @@ up.network = (function () {
8927
8982
  }
8928
8983
  function registerAliasForRedirect(request, response) {
8929
8984
  if (request.cache && response.url && request.url !== response.url) {
8930
- const newRequest = request.variant({
8985
+ const newRequest = u.variant(request, {
8931
8986
  method: response.method,
8932
8987
  url: response.url
8933
8988
  });
@@ -8966,7 +9021,7 @@ up.cache = up.network.cache;
8966
9021
 
8967
9022
 
8968
9023
  /***/ }),
8969
- /* 91 */
9024
+ /* 92 */
8970
9025
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8971
9026
 
8972
9027
  "use strict";
@@ -8975,10 +9030,10 @@ __webpack_require__.r(__webpack_exports__);
8975
9030
 
8976
9031
 
8977
9032
  /***/ }),
8978
- /* 92 */
9033
+ /* 93 */
8979
9034
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8980
9035
 
8981
- __webpack_require__(93);
9036
+ __webpack_require__(94);
8982
9037
  const u = up.util;
8983
9038
  const e = up.element;
8984
9039
  up.layer = (function () {
@@ -9122,7 +9177,7 @@ up.layer = (function () {
9122
9177
  return e.callbackAttr(link, attr, { exposedKeys: ['layer'] });
9123
9178
  }
9124
9179
  function closeCallbackAttr(link, attr) {
9125
- return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value'] });
9180
+ return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value', 'response'] });
9126
9181
  }
9127
9182
  function reset() {
9128
9183
  config.reset();
@@ -9219,7 +9274,7 @@ up.layer = (function () {
9219
9274
 
9220
9275
 
9221
9276
  /***/ }),
9222
- /* 93 */
9277
+ /* 94 */
9223
9278
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
9224
9279
 
9225
9280
  "use strict";
@@ -9228,10 +9283,10 @@ __webpack_require__.r(__webpack_exports__);
9228
9283
 
9229
9284
 
9230
9285
  /***/ }),
9231
- /* 94 */
9286
+ /* 95 */
9232
9287
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
9233
9288
 
9234
- __webpack_require__(95);
9289
+ __webpack_require__(96);
9235
9290
  up.link = (function () {
9236
9291
  const u = up.util;
9237
9292
  const e = up.element;
@@ -9239,7 +9294,7 @@ up.link = (function () {
9239
9294
  let lastMousedownTarget = null;
9240
9295
  const LINKS_WITH_LOCAL_HTML = ['a[up-content]', 'a[up-fragment]', 'a[up-document]'];
9241
9296
  const LINKS_WITH_REMOTE_HTML = ['a[href]', '[up-href]'];
9242
- const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]'];
9297
+ const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]', '[up-href]'];
9243
9298
  function combineFollowableSelectors(elementSelectors, attributeSelectors) {
9244
9299
  return u.flatMap(elementSelectors, elementSelector => attributeSelectors.map(attrSelector => elementSelector + attrSelector));
9245
9300
  }
@@ -9526,7 +9581,7 @@ up.follow = up.link.follow;
9526
9581
 
9527
9582
 
9528
9583
  /***/ }),
9529
- /* 95 */
9584
+ /* 96 */
9530
9585
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
9531
9586
 
9532
9587
  "use strict";
@@ -9535,7 +9590,7 @@ __webpack_require__.r(__webpack_exports__);
9535
9590
 
9536
9591
 
9537
9592
  /***/ }),
9538
- /* 96 */
9593
+ /* 97 */
9539
9594
  /***/ (() => {
9540
9595
 
9541
9596
  up.form = (function () {
@@ -9550,7 +9605,7 @@ up.form = (function () {
9550
9605
  submitButtonSelectors: ['input[type=submit]', 'input[type=image]', 'button[type=submit]', 'button:not([type])'],
9551
9606
  watchInputEvents: ['input', 'change'],
9552
9607
  watchInputDelay: 0,
9553
- watchChangeEvents: (field) => field.matches('input[type=date]') ? ['blur'] : ['change'],
9608
+ watchChangeEvents: ['change'],
9554
9609
  }));
9555
9610
  function fullSubmitSelector() {
9556
9611
  return config.submitSelectors.join(',');
@@ -9580,13 +9635,13 @@ up.form = (function () {
9580
9635
  }
9581
9636
  function submittingButton(form) {
9582
9637
  const selector = submitButtonSelector();
9583
- const focusedElement = up.viewport.focusedElementWithin(form);
9584
- if (focusedElement && focusedElement.matches(selector)) {
9585
- return focusedElement;
9586
- }
9587
- else {
9588
- return e.get(form, selector);
9638
+ const focusedElement = document.activeElement;
9639
+ if (focusedElement && focusedElement.form === form) {
9640
+ if (focusedElement.matches(selector)) {
9641
+ return focusedElement;
9642
+ }
9589
9643
  }
9644
+ return e.get(form, selector);
9590
9645
  }
9591
9646
  function submitButtonSelector() {
9592
9647
  return config.submitButtonSelectors.join(',');
@@ -9929,7 +9984,7 @@ up.validate = up.form.validate;
9929
9984
 
9930
9985
 
9931
9986
  /***/ }),
9932
- /* 97 */
9987
+ /* 98 */
9933
9988
  /***/ (() => {
9934
9989
 
9935
9990
  up.feedback = (function () {
@@ -10046,7 +10101,7 @@ up.feedback = (function () {
10046
10101
 
10047
10102
 
10048
10103
  /***/ }),
10049
- /* 98 */
10104
+ /* 99 */
10050
10105
  /***/ (() => {
10051
10106
 
10052
10107
  up.radio = (function () {
@@ -10123,7 +10178,7 @@ up.radio = (function () {
10123
10178
 
10124
10179
 
10125
10180
  /***/ }),
10126
- /* 99 */
10181
+ /* 100 */
10127
10182
  /***/ (() => {
10128
10183
 
10129
10184
  (function () {
@@ -10272,15 +10327,16 @@ __webpack_require__(82);
10272
10327
  __webpack_require__(83);
10273
10328
  __webpack_require__(84);
10274
10329
  __webpack_require__(85);
10275
- __webpack_require__(87);
10276
- __webpack_require__(89);
10330
+ __webpack_require__(86);
10331
+ __webpack_require__(88);
10277
10332
  __webpack_require__(90);
10278
- __webpack_require__(92);
10279
- __webpack_require__(94);
10280
- __webpack_require__(96);
10333
+ __webpack_require__(91);
10334
+ __webpack_require__(93);
10335
+ __webpack_require__(95);
10281
10336
  __webpack_require__(97);
10282
10337
  __webpack_require__(98);
10283
10338
  __webpack_require__(99);
10339
+ __webpack_require__(100);
10284
10340
  up.framework.onEvaled();
10285
10341
 
10286
10342
  })();