unpoly-rails 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@
5
5
  /***/ (() => {
6
6
 
7
7
  window.up = {
8
- version: '3.1.0'
8
+ version: '3.2.0'
9
9
  };
10
10
 
11
11
 
@@ -194,6 +194,9 @@ up.util = (function () {
194
194
  function isRegExp(object) {
195
195
  return object instanceof RegExp;
196
196
  }
197
+ function isError(object) {
198
+ return object instanceof Error;
199
+ }
197
200
  function isJQuery(object) {
198
201
  return up.browser.canJQuery() && object instanceof jQuery;
199
202
  }
@@ -390,8 +393,8 @@ up.util = (function () {
390
393
  function queueMicrotask(task) {
391
394
  return Promise.resolve().then(task);
392
395
  }
393
- function last(array) {
394
- return array[array.length - 1];
396
+ function last(value) {
397
+ return value[value.length - 1];
395
398
  }
396
399
  function contains(value, subValue) {
397
400
  return value.indexOf(subValue) >= 0;
@@ -616,14 +619,20 @@ up.util = (function () {
616
619
  });
617
620
  }
618
621
  }
619
- function stringifyArg(arg) {
622
+ function stringifyArg(arg, placeholder = '%o') {
620
623
  let string;
621
624
  const maxLength = 200;
622
- let closer = '';
625
+ if (placeholder === '%c') {
626
+ return '';
627
+ }
628
+ if (placeholder === '%s' && isGiven(arg)) {
629
+ arg = arg.toString();
630
+ }
623
631
  if (isString(arg)) {
624
- string = arg.replace(/[\n\r\t ]+/g, ' ');
625
- string = string.replace(/^[\n\r\t ]+/, '');
626
- string = string.replace(/[\n\r\t ]$/, '');
632
+ string = arg.trim().replace(/[\n\r\t ]+/g, ' ');
633
+ if (placeholder === '%o') {
634
+ string = JSON.stringify(string);
635
+ }
627
636
  }
628
637
  else if (isUndefined(arg)) {
629
638
  string = 'undefined';
@@ -633,24 +642,21 @@ up.util = (function () {
633
642
  }
634
643
  else if (isArray(arg)) {
635
644
  string = `[${map(arg, stringifyArg).join(', ')}]`;
636
- closer = ']';
637
645
  }
638
646
  else if (isJQuery(arg)) {
639
647
  string = `$(${map(arg, stringifyArg).join(', ')})`;
640
- closer = ')';
641
648
  }
642
649
  else if (isElement(arg)) {
643
650
  string = `<${arg.tagName.toLowerCase()}`;
644
- for (let attr of ['id', 'name', 'class']) {
651
+ for (let attr of ['id', 'up-id', 'name', 'class']) {
645
652
  let value = arg.getAttribute(attr);
646
653
  if (value) {
647
654
  string += ` ${attr}="${value}"`;
648
655
  }
649
656
  }
650
657
  string += ">";
651
- closer = '>';
652
658
  }
653
- else if (isRegExp(arg)) {
659
+ else if (isRegExp(arg) || isError(arg)) {
654
660
  string = arg.toString();
655
661
  }
656
662
  else {
@@ -667,14 +673,13 @@ up.util = (function () {
667
673
  }
668
674
  }
669
675
  if (string.length > maxLength) {
670
- string = `${string.substr(0, maxLength)} …`;
671
- string += closer;
676
+ string = `${string.substr(0, maxLength)}…${last(string)}`;
672
677
  }
673
678
  return string;
674
679
  }
675
- const SPRINTF_PLACEHOLDERS = /%[oOdisf]/g;
680
+ const SPRINTF_PLACEHOLDERS = /%[oOdisfc]/g;
676
681
  function sprintf(message, ...args) {
677
- return message.replace(SPRINTF_PLACEHOLDERS, () => stringifyArg(args.shift()));
682
+ return message.replace(SPRINTF_PLACEHOLDERS, (placeholder) => stringifyArg(args.shift(), placeholder));
678
683
  }
679
684
  function negate(fn) {
680
685
  return function (...args) {
@@ -717,6 +722,11 @@ up.util = (function () {
717
722
  let unicodeEscape = (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4, '0');
718
723
  return string.replace(/[^\x00-\x7F]/g, unicodeEscape);
719
724
  }
725
+ function variant(source, changes = {}) {
726
+ let variant = Object.create(source);
727
+ Object.assign(variant, changes);
728
+ return variant;
729
+ }
720
730
  return {
721
731
  parseURL,
722
732
  normalizeURL,
@@ -814,6 +824,7 @@ up.util = (function () {
814
824
  negate,
815
825
  memoizeMethod,
816
826
  safeStringifyJSON,
827
+ variant,
817
828
  };
818
829
  })();
819
830
 
@@ -1582,10 +1593,7 @@ up.Record = class Record {
1582
1593
  return u.pick(source, this.keys());
1583
1594
  }
1584
1595
  [u.copy.key]() {
1585
- return this.variant();
1586
- }
1587
- variant(changes = {}) {
1588
- return new this.constructor(u.merge(this.attributes(), changes));
1596
+ return u.variant(this);
1589
1597
  }
1590
1598
  [u.isEqual.key](other) {
1591
1599
  return (this.constructor === other.constructor) && u.isEqual(this.attributes(), other.attributes());
@@ -1757,9 +1765,6 @@ up.Change = class Change {
1757
1765
  constructor(options) {
1758
1766
  this.options = options;
1759
1767
  }
1760
- cannotMatch(reason) {
1761
- throw new up.CannotMatch(reason);
1762
- }
1763
1768
  execute() {
1764
1769
  throw new up.NotImplemented();
1765
1770
  }
@@ -1775,6 +1780,9 @@ up.Change = class Change {
1775
1780
  return newValue;
1776
1781
  }
1777
1782
  }
1783
+ deriveFailOptions() {
1784
+ return up.RenderOptions.deriveFailOptions(this.options);
1785
+ }
1778
1786
  };
1779
1787
 
1780
1788
 
@@ -1786,38 +1794,40 @@ const u = up.util;
1786
1794
  const e = up.element;
1787
1795
  up.Change.Addition = class Addition extends up.Change {
1788
1796
  constructor(options) {
1797
+ var _a;
1789
1798
  super(options);
1790
1799
  this.responseDoc = options.responseDoc;
1791
1800
  this.acceptLayer = options.acceptLayer;
1792
1801
  this.dismissLayer = options.dismissLayer;
1793
1802
  this.eventPlans = options.eventPlans || [];
1803
+ this.response = (_a = options.meta) === null || _a === void 0 ? void 0 : _a.response;
1794
1804
  }
1795
1805
  handleLayerChangeRequests() {
1796
1806
  if (this.layer.isOverlay()) {
1797
1807
  this.tryAcceptLayerFromServer();
1798
1808
  this.abortWhenLayerClosed();
1799
- this.layer.tryAcceptForLocation();
1809
+ this.layer.tryAcceptForLocation(this.responseOption());
1800
1810
  this.abortWhenLayerClosed();
1801
1811
  this.tryDismissLayerFromServer();
1802
1812
  this.abortWhenLayerClosed();
1803
- this.layer.tryDismissForLocation();
1813
+ this.layer.tryDismissForLocation(this.responseOption());
1804
1814
  this.abortWhenLayerClosed();
1805
1815
  }
1806
1816
  this.layer.asCurrent(() => {
1807
1817
  for (let eventPlan of this.eventPlans) {
1808
- up.emit(eventPlan);
1818
+ up.emit(Object.assign(Object.assign({}, eventPlan), this.responseOption()));
1809
1819
  this.abortWhenLayerClosed();
1810
1820
  }
1811
1821
  });
1812
1822
  }
1813
1823
  tryAcceptLayerFromServer() {
1814
1824
  if (u.isDefined(this.acceptLayer) && this.layer.isOverlay()) {
1815
- this.layer.accept(this.acceptLayer);
1825
+ this.layer.accept(this.acceptLayer, this.responseOption());
1816
1826
  }
1817
1827
  }
1818
1828
  tryDismissLayerFromServer() {
1819
1829
  if (u.isDefined(this.dismissLayer) && this.layer.isOverlay()) {
1820
- this.layer.dismiss(this.dismissLayer);
1830
+ this.layer.dismiss(this.dismissLayer, this.responseOption());
1821
1831
  }
1822
1832
  }
1823
1833
  abortWhenLayerClosed() {
@@ -1844,6 +1854,9 @@ up.Change.Addition = class Addition extends up.Change {
1844
1854
  this.setTime(options);
1845
1855
  this.setETag(options);
1846
1856
  }
1857
+ responseOption() {
1858
+ return { response: this.response };
1859
+ }
1847
1860
  };
1848
1861
 
1849
1862
 
@@ -1915,6 +1928,10 @@ up.RenderJob = (_a = class RenderJob {
1915
1928
  let onRequest = (request) => this.handleAbortOption(request);
1916
1929
  this.change = new up.Change.FromURL(Object.assign(Object.assign({}, this.options), { onRequest }));
1917
1930
  }
1931
+ else if (this.options.response) {
1932
+ this.change = new up.Change.FromResponse(this.options);
1933
+ this.handleAbortOption(null);
1934
+ }
1918
1935
  else {
1919
1936
  this.change = new up.Change.FromContent(this.options);
1920
1937
  this.handleAbortOption(null);
@@ -2068,7 +2085,7 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2068
2085
  this.content = responseDoc.select(this.target);
2069
2086
  }
2070
2087
  if (!this.content || this.baseLayer.isClosed()) {
2071
- throw this.cannotMatch();
2088
+ throw new up.CannotMatch();
2072
2089
  }
2073
2090
  onApplicable();
2074
2091
  up.puts('up.render()', `Opening element "${this.target}" in new overlay`);
@@ -2380,7 +2397,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2380
2397
  return true;
2381
2398
  }
2382
2399
  else if (!step.maybe) {
2383
- throw this.cannotMatch(`Could not find element "${this.target}" in current page`);
2400
+ throw new up.CannotMatch();
2384
2401
  }
2385
2402
  });
2386
2403
  this.resolveOldNesting();
@@ -2396,7 +2413,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2396
2413
  return true;
2397
2414
  }
2398
2415
  else if (!step.maybe) {
2399
- throw this.cannotMatch(`Could not find element "${this.target}" in server response`);
2416
+ throw new up.CannotMatch();
2400
2417
  }
2401
2418
  });
2402
2419
  this.resolveOldNesting();
@@ -2489,6 +2506,7 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2489
2506
  this.origin = options.origin;
2490
2507
  this.value = options.value;
2491
2508
  this.preventable = (_a = options.preventable) !== null && _a !== void 0 ? _a : true;
2509
+ this.response = options.response;
2492
2510
  }
2493
2511
  execute() {
2494
2512
  if (!this.layer.isOpen()) {
@@ -2530,7 +2548,8 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2530
2548
  return up.event.build(name, {
2531
2549
  layer: this.layer,
2532
2550
  value: this.value,
2533
- origin: this.origin
2551
+ origin: this.origin,
2552
+ response: this.response,
2534
2553
  });
2535
2554
  }
2536
2555
  handleFocus(formerParent) {
@@ -2547,152 +2566,6 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2547
2566
  /* 31 */
2548
2567
  /***/ (() => {
2549
2568
 
2550
- var _a;
2551
- const u = up.util;
2552
- up.Change.FromContent = (_a = class FromContent extends up.Change {
2553
- constructor(options) {
2554
- super(options);
2555
- this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2556
- this.origin = this.options.origin;
2557
- this.preview = this.options.preview;
2558
- this.mode = this.options.mode;
2559
- if (this.origin) {
2560
- this.originLayer = up.layer.get(this.origin);
2561
- }
2562
- }
2563
- isRenderableLayer(layer) {
2564
- return (layer === 'new') || layer.isOpen();
2565
- }
2566
- getPlans() {
2567
- var _a;
2568
- let plans = [];
2569
- if (this.options.fragment) {
2570
- (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2571
- }
2572
- this.expandIntoPlans(plans, this.layers, this.options.target);
2573
- this.expandIntoPlans(plans, this.layers, this.options.fallback);
2574
- return plans;
2575
- }
2576
- expandIntoPlans(plans, layers, targets) {
2577
- for (let layer of layers) {
2578
- for (let target of this.expandTargets(targets, layer)) {
2579
- const props = Object.assign(Object.assign({}, this.options), { target, layer, defaultPlacement: this.defaultPlacement() });
2580
- const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2581
- plans.push(change);
2582
- }
2583
- }
2584
- }
2585
- expandTargets(targets, layer) {
2586
- return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2587
- }
2588
- execute() {
2589
- if (this.options.preload) {
2590
- return Promise.resolve();
2591
- }
2592
- return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2593
- }
2594
- executePlan(matchedPlan) {
2595
- let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2596
- result.options = this.options;
2597
- return result;
2598
- }
2599
- onPlanApplicable(plan) {
2600
- let primaryPlan = this.getPlans()[0];
2601
- if (plan !== primaryPlan) {
2602
- up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2603
- }
2604
- }
2605
- getResponseDoc() {
2606
- var _a, _b;
2607
- if (this.preview)
2608
- return;
2609
- const docOptions = u.pick(this.options, [
2610
- 'target',
2611
- 'content',
2612
- 'fragment',
2613
- 'document',
2614
- 'html',
2615
- 'cspNonces',
2616
- 'origin',
2617
- ]);
2618
- (_b = (_a = up.migrate).handleResponseDocOptions) === null || _b === void 0 ? void 0 : _b.call(_a, docOptions);
2619
- if (this.defaultPlacement() === 'content') {
2620
- docOptions.target = this.firstExpandedTarget(docOptions.target);
2621
- }
2622
- return new up.ResponseDoc(docOptions);
2623
- }
2624
- defaultPlacement() {
2625
- if (!this.options.document && !this.options.fragment) {
2626
- return 'content';
2627
- }
2628
- }
2629
- firstExpandedTarget(target) {
2630
- return this.expandTargets(target || ':main', this.layers[0])[0];
2631
- }
2632
- getPreflightProps(opts = {}) {
2633
- const getPlanProps = plan => plan.getPreflightProps();
2634
- return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2635
- }
2636
- cannotMatchPreflightTarget() {
2637
- this.cannotMatchTarget('Could not find target in current page');
2638
- }
2639
- cannotMatchPostflightTarget() {
2640
- this.cannotMatchTarget('Could not find common target in current page and response');
2641
- }
2642
- cannotMatchTarget(reason) {
2643
- if (this.getPlans().length) {
2644
- const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2645
- const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2646
- up.fail(reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption);
2647
- }
2648
- else if (this.layers.length) {
2649
- if (this.options.failPrefixForced) {
2650
- up.fail('No target selector given for failed responses (https://unpoly.com/failed-responses)');
2651
- }
2652
- else {
2653
- up.fail('No target selector given');
2654
- }
2655
- }
2656
- else {
2657
- up.fail('Layer %o does not exist', this.options.layer);
2658
- }
2659
- }
2660
- seekPlan(fn) {
2661
- for (let plan of this.getPlans()) {
2662
- try {
2663
- return fn(plan);
2664
- }
2665
- catch (error) {
2666
- if (!(error instanceof up.CannotMatch)) {
2667
- throw error;
2668
- }
2669
- }
2670
- }
2671
- }
2672
- },
2673
- (() => {
2674
- u.memoizeMethod(_a.prototype, [
2675
- 'getPlans',
2676
- 'getResponseDoc',
2677
- 'getPreflightProps',
2678
- ]);
2679
- })(),
2680
- _a);
2681
-
2682
-
2683
- /***/ }),
2684
- /* 32 */
2685
- /***/ (function() {
2686
-
2687
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2688
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2689
- return new (P || (P = Promise))(function (resolve, reject) {
2690
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2691
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2692
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2693
- step((generator = generator.apply(thisArg, _arguments || [])).next());
2694
- });
2695
- };
2696
2569
  var _a;
2697
2570
  const u = up.util;
2698
2571
  up.Change.FromURL = (_a = class FromURL extends up.Change {
@@ -2718,9 +2591,6 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2718
2591
  }
2719
2592
  return u.always(this.request, responseOrError => this.onRequestSettled(responseOrError));
2720
2593
  }
2721
- deriveFailOptions() {
2722
- return up.RenderOptions.deriveFailOptions(this.options);
2723
- }
2724
2594
  newPageReason() {
2725
2595
  if (u.isCrossOrigin(this.options.url)) {
2726
2596
  return 'Loading cross-origin content in new page';
@@ -2750,41 +2620,12 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2750
2620
  }
2751
2621
  }
2752
2622
  onRequestSettledWithResponse(response) {
2753
- var _a;
2754
- this.response = response;
2755
- if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2756
- this.skip();
2757
- }
2758
- else {
2759
- 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() }));
2760
- }
2761
- let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !response.ok;
2762
- if (fail) {
2763
- throw this.updateContentFromResponse(this.deriveFailOptions());
2764
- }
2765
- return this.updateContentFromResponse(this.options);
2766
- }
2767
- compilerPassMeta() {
2768
- return u.pick(this.loadedEventProps(), [
2769
- 'revalidating',
2770
- 'response'
2771
- ]);
2772
- }
2773
- loadedEventProps() {
2774
- const { expiredResponse } = this.options;
2775
- return {
2776
- request: this.request,
2777
- response: this.response,
2778
- renderOptions: this.options,
2779
- revalidating: !!expiredResponse,
2780
- expiredResponse,
2781
- };
2623
+ return new up.Change.FromResponse(Object.assign(Object.assign({}, this.options), { response })).execute();
2782
2624
  }
2783
2625
  onRequestSettledWithError(error) {
2784
2626
  if (error instanceof up.Offline) {
2785
2627
  this.request.emit('up:fragment:offline', {
2786
2628
  callback: this.options.onOffline,
2787
- response: this.response,
2788
2629
  renderOptions: this.options,
2789
2630
  retry: (retryOptions) => up.render(Object.assign(Object.assign({}, this.options), retryOptions)),
2790
2631
  log: ['Cannot load fragment from %s: %s', this.request.description, error.reason],
@@ -2792,6 +2633,50 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2792
2633
  }
2793
2634
  throw error;
2794
2635
  }
2636
+ },
2637
+ (() => {
2638
+ u.memoizeMethod(_a.prototype, [
2639
+ 'getRequestAttrs',
2640
+ ]);
2641
+ })(),
2642
+ _a);
2643
+
2644
+
2645
+ /***/ }),
2646
+ /* 32 */
2647
+ /***/ (function() {
2648
+
2649
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2650
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2651
+ return new (P || (P = Promise))(function (resolve, reject) {
2652
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2653
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2654
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2655
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2656
+ });
2657
+ };
2658
+ var _a;
2659
+ const u = up.util;
2660
+ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2661
+ constructor(options) {
2662
+ super(options);
2663
+ this.response = options.response;
2664
+ this.request = this.response.request;
2665
+ }
2666
+ execute() {
2667
+ var _a;
2668
+ if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2669
+ this.skip();
2670
+ }
2671
+ else {
2672
+ this.request.assertEmitted('up:fragment:loaded', Object.assign(Object.assign({}, this.loadedEventProps()), { callback: this.options.onLoaded, log: ['Loaded fragment from %s', this.response.description], skip: () => this.skip() }));
2673
+ }
2674
+ let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !this.response.ok;
2675
+ if (fail) {
2676
+ throw this.updateContentFromResponse(this.deriveFailOptions());
2677
+ }
2678
+ return this.updateContentFromResponse(this.options);
2679
+ }
2795
2680
  skip() {
2796
2681
  up.puts('up.render()', 'Skipping ' + this.response.description);
2797
2682
  this.options.target = ':none';
@@ -2832,6 +2717,22 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2832
2717
  return renderResult;
2833
2718
  });
2834
2719
  }
2720
+ loadedEventProps() {
2721
+ const { expiredResponse } = this.options;
2722
+ return {
2723
+ request: this.request,
2724
+ response: this.response,
2725
+ renderOptions: this.options,
2726
+ revalidating: !!expiredResponse,
2727
+ expiredResponse,
2728
+ };
2729
+ }
2730
+ compilerPassMeta() {
2731
+ return u.pick(this.loadedEventProps(), [
2732
+ 'revalidating',
2733
+ 'response'
2734
+ ]);
2735
+ }
2835
2736
  augmentOptionsFromResponse(renderOptions) {
2836
2737
  var _a, _b;
2837
2738
  const responseURL = this.response.url;
@@ -2841,44 +2742,182 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2841
2742
  renderOptions.hash = hash;
2842
2743
  serverLocation += hash;
2843
2744
  }
2844
- const isReloadable = (this.response.method === 'GET');
2845
- if (isReloadable) {
2846
- renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2745
+ const isReloadable = (this.response.method === 'GET');
2746
+ if (isReloadable) {
2747
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, responseURL);
2748
+ }
2749
+ else {
2750
+ renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2751
+ renderOptions.history = !!renderOptions.location;
2752
+ }
2753
+ renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2754
+ renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2755
+ renderOptions.eventPlans = this.response.eventPlans;
2756
+ let serverTarget = this.response.target;
2757
+ if (serverTarget) {
2758
+ renderOptions.target = serverTarget;
2759
+ }
2760
+ renderOptions.acceptLayer = this.response.acceptLayer;
2761
+ renderOptions.dismissLayer = this.response.dismissLayer;
2762
+ renderOptions.document = this.response.text;
2763
+ if (this.response.none) {
2764
+ renderOptions.target = ':none';
2765
+ }
2766
+ renderOptions.context = u.merge(renderOptions.context, this.response.context);
2767
+ renderOptions.cspNonces = this.response.cspNonces;
2768
+ (_a = renderOptions.time) !== null && _a !== void 0 ? _a : (renderOptions.time = this.response.lastModified);
2769
+ (_b = renderOptions.etag) !== null && _b !== void 0 ? _b : (renderOptions.etag = this.response.etag);
2770
+ }
2771
+ },
2772
+ (() => {
2773
+ u.memoizeMethod(_a.prototype, [
2774
+ 'loadedEventProps',
2775
+ ]);
2776
+ })(),
2777
+ _a);
2778
+
2779
+
2780
+ /***/ }),
2781
+ /* 33 */
2782
+ /***/ (() => {
2783
+
2784
+ var _a;
2785
+ const u = up.util;
2786
+ up.Change.FromContent = (_a = class FromContent extends up.Change {
2787
+ constructor(options) {
2788
+ super(options);
2789
+ this.layers = u.filter(up.layer.getAll(this.options), this.isRenderableLayer);
2790
+ this.origin = this.options.origin;
2791
+ this.preview = this.options.preview;
2792
+ this.mode = this.options.mode;
2793
+ if (this.origin) {
2794
+ this.originLayer = up.layer.get(this.origin);
2795
+ }
2796
+ }
2797
+ isRenderableLayer(layer) {
2798
+ return (layer === 'new') || layer.isOpen();
2799
+ }
2800
+ getPlans() {
2801
+ var _a;
2802
+ let plans = [];
2803
+ if (this.options.fragment) {
2804
+ (_a = this.options).target || (_a.target = this.getResponseDoc().rootSelector());
2805
+ }
2806
+ this.expandIntoPlans(plans, this.layers, this.options.target);
2807
+ this.expandIntoPlans(plans, this.layers, this.options.fallback);
2808
+ return plans;
2809
+ }
2810
+ expandIntoPlans(plans, layers, targets) {
2811
+ for (let layer of layers) {
2812
+ for (let target of this.expandTargets(targets, layer)) {
2813
+ const props = Object.assign(Object.assign({}, this.options), { target, layer, defaultPlacement: this.defaultPlacement() });
2814
+ const change = layer === 'new' ? new up.Change.OpenLayer(props) : new up.Change.UpdateLayer(props);
2815
+ plans.push(change);
2816
+ }
2817
+ }
2818
+ }
2819
+ expandTargets(targets, layer) {
2820
+ return up.fragment.expandTargets(targets, { layer, mode: this.mode, origin: this.origin });
2821
+ }
2822
+ execute() {
2823
+ if (this.options.preload) {
2824
+ return Promise.resolve();
2825
+ }
2826
+ return this.seekPlan(this.executePlan.bind(this)) || this.cannotMatchPostflightTarget();
2827
+ }
2828
+ executePlan(matchedPlan) {
2829
+ let result = matchedPlan.execute(this.getResponseDoc(), this.onPlanApplicable.bind(this, matchedPlan));
2830
+ result.options = this.options;
2831
+ return result;
2832
+ }
2833
+ onPlanApplicable(plan) {
2834
+ let primaryPlan = this.getPlans()[0];
2835
+ if (plan !== primaryPlan) {
2836
+ up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
2837
+ }
2838
+ }
2839
+ getResponseDoc() {
2840
+ var _a, _b;
2841
+ if (this.preview)
2842
+ return;
2843
+ const docOptions = u.pick(this.options, [
2844
+ 'target',
2845
+ 'content',
2846
+ 'fragment',
2847
+ 'document',
2848
+ 'html',
2849
+ 'cspNonces',
2850
+ 'origin',
2851
+ ]);
2852
+ (_b = (_a = up.migrate).handleResponseDocOptions) === null || _b === void 0 ? void 0 : _b.call(_a, docOptions);
2853
+ if (this.defaultPlacement() === 'content') {
2854
+ docOptions.target = this.firstExpandedTarget(docOptions.target);
2855
+ }
2856
+ return new up.ResponseDoc(docOptions);
2857
+ }
2858
+ defaultPlacement() {
2859
+ if (!this.options.document && !this.options.fragment) {
2860
+ return 'content';
2861
+ }
2862
+ }
2863
+ firstExpandedTarget(target) {
2864
+ return this.expandTargets(target || ':main', this.layers[0])[0];
2865
+ }
2866
+ getPreflightProps(opts = {}) {
2867
+ const getPlanProps = plan => plan.getPreflightProps();
2868
+ return this.seekPlan(getPlanProps) || opts.optional || this.cannotMatchPreflightTarget();
2869
+ }
2870
+ cannotMatchPreflightTarget() {
2871
+ this.cannotMatchTarget('Could not find target in current page');
2872
+ }
2873
+ cannotMatchPostflightTarget() {
2874
+ this.cannotMatchTarget('Could not find common target in current page and response');
2875
+ }
2876
+ cannotMatchTarget(reason) {
2877
+ let message;
2878
+ if (this.getPlans().length) {
2879
+ const planTargets = u.uniq(u.map(this.getPlans(), 'target'));
2880
+ const humanizedLayerOption = up.layer.optionToString(this.options.layer);
2881
+ message = [reason + " (tried selectors %o in %s)", planTargets, humanizedLayerOption];
2882
+ }
2883
+ else if (this.layers.length) {
2884
+ if (this.options.failPrefixForced) {
2885
+ message = 'No target selector given for failed responses (https://unpoly.com/failed-responses)';
2886
+ }
2887
+ else {
2888
+ message = 'No target selector given';
2889
+ }
2847
2890
  }
2848
2891
  else {
2849
- renderOptions.source = this.improveHistoryValue(renderOptions.source, 'keep');
2850
- renderOptions.history = !!renderOptions.location;
2851
- }
2852
- renderOptions.location = this.improveHistoryValue(renderOptions.location, serverLocation);
2853
- renderOptions.title = this.improveHistoryValue(renderOptions.title, this.response.title);
2854
- renderOptions.eventPlans = this.response.eventPlans;
2855
- let serverTarget = this.response.target;
2856
- if (serverTarget) {
2857
- renderOptions.target = serverTarget;
2892
+ message = 'Could not find a layer to render in. You may have passed a non-existing layer reference, or a detached element.';
2858
2893
  }
2859
- renderOptions.acceptLayer = this.response.acceptLayer;
2860
- renderOptions.dismissLayer = this.response.dismissLayer;
2861
- renderOptions.document = this.response.text;
2862
- if (!renderOptions.document) {
2863
- renderOptions.target = ':none';
2894
+ throw new up.CannotMatch(message);
2895
+ }
2896
+ seekPlan(fn) {
2897
+ for (let plan of this.getPlans()) {
2898
+ try {
2899
+ return fn(plan);
2900
+ }
2901
+ catch (error) {
2902
+ if (!(error instanceof up.CannotMatch)) {
2903
+ throw error;
2904
+ }
2905
+ }
2864
2906
  }
2865
- renderOptions.context = u.merge(renderOptions.context, this.response.context);
2866
- renderOptions.cspNonces = this.response.cspNonces;
2867
- (_a = renderOptions.time) !== null && _a !== void 0 ? _a : (renderOptions.time = this.response.lastModified);
2868
- (_b = renderOptions.etag) !== null && _b !== void 0 ? _b : (renderOptions.etag = this.response.etag);
2869
2907
  }
2870
2908
  },
2871
2909
  (() => {
2872
2910
  u.memoizeMethod(_a.prototype, [
2873
- 'getRequestAttrs',
2874
- 'loadedEventProps',
2911
+ 'getPlans',
2912
+ 'getResponseDoc',
2913
+ 'getPreflightProps',
2875
2914
  ]);
2876
2915
  })(),
2877
2916
  _a);
2878
2917
 
2879
2918
 
2880
2919
  /***/ }),
2881
- /* 33 */
2920
+ /* 34 */
2882
2921
  /***/ (() => {
2883
2922
 
2884
2923
  const u = up.util;
@@ -2990,7 +3029,7 @@ up.CompilerPass = class CompilerPass {
2990
3029
 
2991
3030
 
2992
3031
  /***/ }),
2993
- /* 34 */
3032
+ /* 35 */
2994
3033
  /***/ (() => {
2995
3034
 
2996
3035
  const u = up.util;
@@ -3103,7 +3142,7 @@ up.CSSTransition = class CSSTransition {
3103
3142
 
3104
3143
 
3105
3144
  /***/ }),
3106
- /* 35 */
3145
+ /* 36 */
3107
3146
  /***/ (() => {
3108
3147
 
3109
3148
  const u = up.util;
@@ -3145,7 +3184,7 @@ up.DestructorPass = class DestructorPass {
3145
3184
 
3146
3185
 
3147
3186
  /***/ }),
3148
- /* 36 */
3187
+ /* 37 */
3149
3188
  /***/ (() => {
3150
3189
 
3151
3190
  const u = up.util;
@@ -3246,7 +3285,7 @@ up.EventEmitter = class EventEmitter extends up.Record {
3246
3285
 
3247
3286
 
3248
3287
  /***/ }),
3249
- /* 37 */
3288
+ /* 38 */
3250
3289
  /***/ (() => {
3251
3290
 
3252
3291
  const u = up.util;
@@ -3349,7 +3388,7 @@ up.EventListener = class EventListener extends up.Record {
3349
3388
 
3350
3389
 
3351
3390
  /***/ }),
3352
- /* 38 */
3391
+ /* 39 */
3353
3392
  /***/ (() => {
3354
3393
 
3355
3394
  const u = up.util;
@@ -3421,7 +3460,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3421
3460
 
3422
3461
 
3423
3462
  /***/ }),
3424
- /* 39 */
3463
+ /* 40 */
3425
3464
  /***/ (function() {
3426
3465
 
3427
3466
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3548,7 +3587,7 @@ up.FieldWatcher = class FieldWatcher {
3548
3587
 
3549
3588
 
3550
3589
  /***/ }),
3551
- /* 40 */
3590
+ /* 41 */
3552
3591
  /***/ (function() {
3553
3592
 
3554
3593
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -3746,7 +3785,7 @@ up.FormValidator = class FormValidator {
3746
3785
 
3747
3786
 
3748
3787
  /***/ }),
3749
- /* 41 */
3788
+ /* 42 */
3750
3789
  /***/ (() => {
3751
3790
 
3752
3791
  up.FocusCapsule = class FocusCapsule {
@@ -3776,7 +3815,7 @@ up.FocusCapsule = class FocusCapsule {
3776
3815
 
3777
3816
 
3778
3817
  /***/ }),
3779
- /* 42 */
3818
+ /* 43 */
3780
3819
  /***/ (() => {
3781
3820
 
3782
3821
  const u = up.util;
@@ -3840,7 +3879,7 @@ up.FragmentProcessor = class FragmentProcessor extends up.Record {
3840
3879
 
3841
3880
 
3842
3881
  /***/ }),
3843
- /* 43 */
3882
+ /* 44 */
3844
3883
  /***/ (() => {
3845
3884
 
3846
3885
  const DESCENDANT_SELECTOR = /^([^ >+(]+) (.+)$/;
@@ -3883,7 +3922,7 @@ up.FragmentFinder = class FragmentFinder {
3883
3922
 
3884
3923
 
3885
3924
  /***/ }),
3886
- /* 44 */
3925
+ /* 45 */
3887
3926
  /***/ (() => {
3888
3927
 
3889
3928
  const u = up.util;
@@ -3968,7 +4007,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
3968
4007
 
3969
4008
 
3970
4009
  /***/ }),
3971
- /* 45 */
4010
+ /* 46 */
3972
4011
  /***/ (() => {
3973
4012
 
3974
4013
  const e = up.element;
@@ -4076,7 +4115,7 @@ up.FragmentPolling = class FragmentPolling {
4076
4115
 
4077
4116
 
4078
4117
  /***/ }),
4079
- /* 46 */
4118
+ /* 47 */
4080
4119
  /***/ (() => {
4081
4120
 
4082
4121
  const u = up.util;
@@ -4140,7 +4179,7 @@ up.FragmentScrolling = class FragmentScrolling extends up.FragmentProcessor {
4140
4179
 
4141
4180
 
4142
4181
  /***/ }),
4143
- /* 47 */
4182
+ /* 48 */
4144
4183
  /***/ (() => {
4145
4184
 
4146
4185
  const e = up.element;
@@ -4363,7 +4402,7 @@ up.Layer = class Layer extends up.Record {
4363
4402
 
4364
4403
 
4365
4404
  /***/ }),
4366
- /* 48 */
4405
+ /* 49 */
4367
4406
  /***/ (() => {
4368
4407
 
4369
4408
  const e = up.element;
@@ -4555,20 +4594,20 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4555
4594
  }
4556
4595
  return this.on(eventTypes, event => {
4557
4596
  event.preventDefault();
4558
- closeFn.call(this, event);
4597
+ closeFn.call(this, event, { response: event.response });
4559
4598
  });
4560
4599
  }
4561
- tryAcceptForLocation() {
4562
- this.tryCloseForLocation(this.acceptLocation, this.accept);
4600
+ tryAcceptForLocation(options) {
4601
+ this.tryCloseForLocation(this.acceptLocation, this.accept, options);
4563
4602
  }
4564
- tryDismissForLocation() {
4565
- this.tryCloseForLocation(this.dismissLocation, this.dismiss);
4603
+ tryDismissForLocation(options) {
4604
+ this.tryCloseForLocation(this.dismissLocation, this.dismiss, options);
4566
4605
  }
4567
- tryCloseForLocation(urlPattern, closeFn) {
4606
+ tryCloseForLocation(urlPattern, closeFn, options) {
4568
4607
  let location, resolution;
4569
4608
  if (urlPattern && (location = this.location) && (resolution = urlPattern.recognize(location))) {
4570
4609
  const closeValue = Object.assign(Object.assign({}, resolution), { location });
4571
- closeFn.call(this, closeValue);
4610
+ closeFn.call(this, closeValue, options);
4572
4611
  }
4573
4612
  }
4574
4613
  teardownHandlers() {
@@ -4643,7 +4682,7 @@ up.Layer.Overlay = class Overlay extends up.Layer {
4643
4682
 
4644
4683
 
4645
4684
  /***/ }),
4646
- /* 49 */
4685
+ /* 50 */
4647
4686
  /***/ (() => {
4648
4687
 
4649
4688
  up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
@@ -4680,7 +4719,7 @@ up.Layer.OverlayWithTether = class OverlayWithTether extends up.Layer.Overlay {
4680
4719
 
4681
4720
 
4682
4721
  /***/ }),
4683
- /* 50 */
4722
+ /* 51 */
4684
4723
  /***/ (() => {
4685
4724
 
4686
4725
  var _a;
@@ -4718,19 +4757,19 @@ up.Layer.OverlayWithViewport = (_a = class OverlayWithViewport extends up.Layer.
4718
4757
 
4719
4758
 
4720
4759
  /***/ }),
4721
- /* 51 */
4760
+ /* 52 */
4722
4761
  /***/ (() => {
4723
4762
 
4724
4763
  var _a;
4725
4764
  const e = up.element;
4726
4765
  up.Layer.Root = (_a = class Root extends up.Layer {
4727
- get element() {
4728
- return e.root;
4729
- }
4730
4766
  constructor(options) {
4731
4767
  super(options);
4732
4768
  this.setupHandlers();
4733
4769
  }
4770
+ get element() {
4771
+ return e.root;
4772
+ }
4734
4773
  getFirstSwappableElement() {
4735
4774
  return document.body;
4736
4775
  }
@@ -4764,7 +4803,7 @@ up.Layer.Root = (_a = class Root extends up.Layer {
4764
4803
 
4765
4804
 
4766
4805
  /***/ }),
4767
- /* 52 */
4806
+ /* 53 */
4768
4807
  /***/ (() => {
4769
4808
 
4770
4809
  var _a;
@@ -4775,7 +4814,7 @@ up.Layer.Modal = (_a = class Modal extends up.Layer.OverlayWithViewport {
4775
4814
 
4776
4815
 
4777
4816
  /***/ }),
4778
- /* 53 */
4817
+ /* 54 */
4779
4818
  /***/ (() => {
4780
4819
 
4781
4820
  var _a;
@@ -4786,7 +4825,7 @@ up.Layer.Popup = (_a = class Popup extends up.Layer.OverlayWithTether {
4786
4825
 
4787
4826
 
4788
4827
  /***/ }),
4789
- /* 54 */
4828
+ /* 55 */
4790
4829
  /***/ (() => {
4791
4830
 
4792
4831
  var _a;
@@ -4797,7 +4836,7 @@ up.Layer.Drawer = (_a = class Drawer extends up.Layer.OverlayWithViewport {
4797
4836
 
4798
4837
 
4799
4838
  /***/ }),
4800
- /* 55 */
4839
+ /* 56 */
4801
4840
  /***/ (() => {
4802
4841
 
4803
4842
  var _a;
@@ -4808,7 +4847,7 @@ up.Layer.Cover = (_a = class Cover extends up.Layer.OverlayWithViewport {
4808
4847
 
4809
4848
 
4810
4849
  /***/ }),
4811
- /* 56 */
4850
+ /* 57 */
4812
4851
  /***/ (() => {
4813
4852
 
4814
4853
  const u = up.util;
@@ -4898,7 +4937,7 @@ up.LayerLookup = class LayerLookup {
4898
4937
 
4899
4938
 
4900
4939
  /***/ }),
4901
- /* 57 */
4940
+ /* 58 */
4902
4941
  /***/ (() => {
4903
4942
 
4904
4943
  const u = up.util;
@@ -5011,7 +5050,7 @@ up.LayerStack = class LayerStack extends Array {
5011
5050
 
5012
5051
 
5013
5052
  /***/ }),
5014
- /* 58 */
5053
+ /* 59 */
5015
5054
  /***/ (() => {
5016
5055
 
5017
5056
  up.LinkFeedbackURLs = class LinkFeedbackURLs {
@@ -5042,7 +5081,7 @@ up.LinkFeedbackURLs = class LinkFeedbackURLs {
5042
5081
 
5043
5082
 
5044
5083
  /***/ }),
5045
- /* 59 */
5084
+ /* 60 */
5046
5085
  /***/ (() => {
5047
5086
 
5048
5087
  const u = up.util;
@@ -5112,7 +5151,7 @@ up.LinkPreloader = class LinkPreloader {
5112
5151
 
5113
5152
 
5114
5153
  /***/ }),
5115
- /* 60 */
5154
+ /* 61 */
5116
5155
  /***/ (function() {
5117
5156
 
5118
5157
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -5221,7 +5260,7 @@ up.MotionController = class MotionController {
5221
5260
 
5222
5261
 
5223
5262
  /***/ }),
5224
- /* 61 */
5263
+ /* 62 */
5225
5264
  /***/ (() => {
5226
5265
 
5227
5266
  const u = up.util;
@@ -5313,7 +5352,7 @@ up.NonceableCallback = class NonceableCallback {
5313
5352
 
5314
5353
 
5315
5354
  /***/ }),
5316
- /* 62 */
5355
+ /* 63 */
5317
5356
  /***/ (() => {
5318
5357
 
5319
5358
  const u = up.util;
@@ -5391,7 +5430,7 @@ up.OptionsParser = class OptionsParser {
5391
5430
 
5392
5431
 
5393
5432
  /***/ }),
5394
- /* 63 */
5433
+ /* 64 */
5395
5434
  /***/ (() => {
5396
5435
 
5397
5436
  const e = up.element;
@@ -5459,7 +5498,7 @@ up.OverlayFocus = class OverlayFocus {
5459
5498
 
5460
5499
 
5461
5500
  /***/ }),
5462
- /* 64 */
5501
+ /* 65 */
5463
5502
  /***/ (() => {
5464
5503
 
5465
5504
  const u = up.util;
@@ -5690,7 +5729,7 @@ up.Params = class Params {
5690
5729
 
5691
5730
 
5692
5731
  /***/ }),
5693
- /* 65 */
5732
+ /* 66 */
5694
5733
  /***/ (() => {
5695
5734
 
5696
5735
  const e = up.element;
@@ -5740,7 +5779,7 @@ up.ProgressBar = class ProgressBar {
5740
5779
 
5741
5780
 
5742
5781
  /***/ }),
5743
- /* 66 */
5782
+ /* 67 */
5744
5783
  /***/ (() => {
5745
5784
 
5746
5785
  const u = up.util;
@@ -5789,14 +5828,15 @@ up.RenderOptions = (function () {
5789
5828
  ]);
5790
5829
  const CONTENT_KEYS = [
5791
5830
  'url',
5831
+ 'response',
5792
5832
  'content',
5793
5833
  'fragment',
5794
- 'document'
5834
+ 'document',
5795
5835
  ];
5796
5836
  const LATE_KEYS = [
5797
5837
  'history',
5798
5838
  'focus',
5799
- 'scroll'
5839
+ 'scroll',
5800
5840
  ];
5801
5841
  function navigateDefaults(options) {
5802
5842
  if (options.navigate) {
@@ -5856,7 +5896,7 @@ up.RenderOptions = (function () {
5856
5896
 
5857
5897
 
5858
5898
  /***/ }),
5859
- /* 67 */
5899
+ /* 68 */
5860
5900
  /***/ (() => {
5861
5901
 
5862
5902
  up.RenderResult = class RenderResult extends up.Record {
@@ -5884,12 +5924,33 @@ up.RenderResult = class RenderResult extends up.Record {
5884
5924
 
5885
5925
 
5886
5926
  /***/ }),
5887
- /* 68 */
5927
+ /* 69 */
5888
5928
  /***/ (() => {
5889
5929
 
5890
5930
  var _a;
5891
5931
  const u = up.util;
5892
5932
  up.Request = (_a = class Request extends up.Record {
5933
+ constructor(options) {
5934
+ var _a;
5935
+ super(options);
5936
+ this.params = new up.Params(this.params);
5937
+ if (this.wrapMethod == null) {
5938
+ this.wrapMethod = up.network.config.wrapMethod;
5939
+ }
5940
+ this.normalize();
5941
+ if ((this.target || this.layer || this.origin) && !options.basic) {
5942
+ const layerLookupOptions = { origin: this.origin };
5943
+ this.layer = up.layer.get(this.layer, layerLookupOptions);
5944
+ this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5945
+ this.context || (this.context = this.layer.context || {});
5946
+ this.failContext || (this.failContext = this.failLayer.context || {});
5947
+ this.mode || (this.mode = this.layer.mode);
5948
+ this.failMode || (this.failMode = this.failLayer.mode);
5949
+ }
5950
+ this.deferred = u.newDeferred();
5951
+ (_a = this.badResponseTime) !== null && _a !== void 0 ? _a : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5952
+ this.addAutoHeaders();
5953
+ }
5893
5954
  keys() {
5894
5955
  return [
5895
5956
  'method',
@@ -5932,39 +5993,20 @@ up.Request = (_a = class Request extends up.Record {
5932
5993
  builtAt: new Date(),
5933
5994
  };
5934
5995
  }
5935
- constructor(options) {
5936
- var _a;
5937
- super(options);
5938
- this.params = new up.Params(this.params);
5939
- if (this.wrapMethod == null) {
5940
- this.wrapMethod = up.network.config.wrapMethod;
5941
- }
5942
- this.normalize();
5943
- if ((this.target || this.layer || this.origin) && !options.basic) {
5944
- const layerLookupOptions = { origin: this.origin };
5945
- this.layer = up.layer.get(this.layer, layerLookupOptions);
5946
- this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions);
5947
- this.context || (this.context = this.layer.context || {});
5948
- this.failContext || (this.failContext = this.failLayer.context || {});
5949
- this.mode || (this.mode = this.layer.mode);
5950
- this.failMode || (this.failMode = this.failLayer.mode);
5951
- }
5952
- this.deferred = u.newDeferred();
5953
- (_a = this.badResponseTime) !== null && _a !== void 0 ? _a : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
5954
- this.addAutoHeaders();
5955
- }
5956
5996
  get xhr() {
5957
5997
  var _a;
5958
5998
  return (_a = this._xhr) !== null && _a !== void 0 ? _a : (this._xhr = new XMLHttpRequest());
5959
5999
  }
5960
6000
  get fragments() {
5961
- if (!this._fragments && this.target) {
6001
+ if (this._fragments) {
6002
+ return this._fragments;
6003
+ }
6004
+ else if (this.target) {
5962
6005
  let steps = up.fragment.parseTargetSteps(this.target);
5963
6006
  let selectors = u.map(steps, 'selector');
5964
6007
  let lookupOpts = { origin: this.origin, layer: this.layer };
5965
- this._fragments = u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
6008
+ return u.compact(u.map(selectors, (selector) => up.fragment.get(selector, lookupOpts)));
5966
6009
  }
5967
- return this._fragments;
5968
6010
  }
5969
6011
  set fragments(value) {
5970
6012
  this._fragments = value;
@@ -6225,7 +6267,7 @@ up.Request = (_a = class Request extends up.Record {
6225
6267
 
6226
6268
 
6227
6269
  /***/ }),
6228
- /* 69 */
6270
+ /* 70 */
6229
6271
  /***/ (function() {
6230
6272
 
6231
6273
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -6328,6 +6370,7 @@ up.Request.Cache = class Cache {
6328
6370
  if (value instanceof up.Response) {
6329
6371
  if (options.force || this.isCacheCompatible(existingRequest, newRequest)) {
6330
6372
  newRequest.fromCache = true;
6373
+ value = u.variant(value, { request: newRequest });
6331
6374
  newRequest.respondWith(value);
6332
6375
  u.delegate(newRequest, ['expired', 'state'], () => existingRequest);
6333
6376
  }
@@ -6378,7 +6421,7 @@ up.Request.Cache = class Cache {
6378
6421
 
6379
6422
 
6380
6423
  /***/ }),
6381
- /* 70 */
6424
+ /* 71 */
6382
6425
  /***/ (() => {
6383
6426
 
6384
6427
  const u = up.util;
@@ -6487,7 +6530,7 @@ up.Request.Queue = class Queue {
6487
6530
 
6488
6531
 
6489
6532
  /***/ }),
6490
- /* 71 */
6533
+ /* 72 */
6491
6534
  /***/ (() => {
6492
6535
 
6493
6536
  const u = up.util;
@@ -6526,7 +6569,7 @@ up.Request.FormRenderer = class FormRenderer {
6526
6569
 
6527
6570
 
6528
6571
  /***/ }),
6529
- /* 72 */
6572
+ /* 73 */
6530
6573
  /***/ (() => {
6531
6574
 
6532
6575
  var _a;
@@ -6598,7 +6641,7 @@ up.Request.XHRRenderer = (_a = class XHRRenderer {
6598
6641
 
6599
6642
 
6600
6643
  /***/ }),
6601
- /* 73 */
6644
+ /* 74 */
6602
6645
  /***/ (() => {
6603
6646
 
6604
6647
  const u = up.util;
@@ -6634,6 +6677,12 @@ up.Response = class Response extends up.Record {
6634
6677
  var _a;
6635
6678
  return !u.evalOption((_a = this.fail) !== null && _a !== void 0 ? _a : up.network.config.fail, this);
6636
6679
  }
6680
+ get none() {
6681
+ return !this.text;
6682
+ }
6683
+ isCacheable() {
6684
+ return this.ok && !this.none;
6685
+ }
6637
6686
  header(name) {
6638
6687
  var _a;
6639
6688
  return this.headers[name] || ((_a = this.xhr) === null || _a === void 0 ? void 0 : _a.getResponseHeader(name));
@@ -6675,7 +6724,7 @@ up.Response = class Response extends up.Record {
6675
6724
 
6676
6725
 
6677
6726
  /***/ }),
6678
- /* 74 */
6727
+ /* 75 */
6679
6728
  /***/ (() => {
6680
6729
 
6681
6730
  var _a;
@@ -6756,7 +6805,7 @@ up.ResponseDoc = (_a = class ResponseDoc {
6756
6805
 
6757
6806
 
6758
6807
  /***/ }),
6759
- /* 75 */
6808
+ /* 76 */
6760
6809
  /***/ (() => {
6761
6810
 
6762
6811
  const e = up.element;
@@ -6851,7 +6900,7 @@ up.RevealMotion = class RevealMotion {
6851
6900
 
6852
6901
 
6853
6902
  /***/ }),
6854
- /* 76 */
6903
+ /* 77 */
6855
6904
  /***/ (() => {
6856
6905
 
6857
6906
  const u = up.util;
@@ -6892,7 +6941,7 @@ up.Selector = class Selector {
6892
6941
 
6893
6942
 
6894
6943
  /***/ }),
6895
- /* 77 */
6944
+ /* 78 */
6896
6945
  /***/ (() => {
6897
6946
 
6898
6947
  const u = up.util;
@@ -7013,7 +7062,7 @@ up.Tether = class Tether {
7013
7062
 
7014
7063
 
7015
7064
  /***/ }),
7016
- /* 78 */
7065
+ /* 79 */
7017
7066
  /***/ (() => {
7018
7067
 
7019
7068
  const u = up.util;
@@ -7094,7 +7143,7 @@ up.URLPattern = class URLPattern {
7094
7143
 
7095
7144
 
7096
7145
  /***/ }),
7097
- /* 79 */
7146
+ /* 80 */
7098
7147
  /***/ (() => {
7099
7148
 
7100
7149
  up.framework = (function () {
@@ -7178,7 +7227,7 @@ up.boot = up.framework.boot;
7178
7227
 
7179
7228
 
7180
7229
  /***/ }),
7181
- /* 80 */
7230
+ /* 81 */
7182
7231
  /***/ (() => {
7183
7232
 
7184
7233
  up.event = (function () {
@@ -7281,7 +7330,7 @@ up.emit = up.event.emit;
7281
7330
 
7282
7331
 
7283
7332
  /***/ }),
7284
- /* 81 */
7333
+ /* 82 */
7285
7334
  /***/ (() => {
7286
7335
 
7287
7336
  up.protocol = (function () {
@@ -7424,10 +7473,11 @@ up.protocol = (function () {
7424
7473
 
7425
7474
 
7426
7475
  /***/ }),
7427
- /* 82 */
7476
+ /* 83 */
7428
7477
  /***/ (() => {
7429
7478
 
7430
7479
  up.log = (function () {
7480
+ const u = up.util;
7431
7481
  const config = new up.LogConfig();
7432
7482
  function reset() {
7433
7483
  config.reset();
@@ -7445,13 +7495,11 @@ up.log = (function () {
7445
7495
  function printToStreamStyled(stream, trace, customStyles, message, ...args) {
7446
7496
  if (message) {
7447
7497
  if (config.format) {
7448
- args.unshift('color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;' + customStyles, '');
7449
- message = `%c${trace}%c ${message}`;
7498
+ console[stream](`%c${trace}%c ${message}`, 'color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;' + customStyles, '', ...args);
7450
7499
  }
7451
7500
  else {
7452
- message = `[${trace}] ${message}`;
7501
+ console[stream](`[${trace}] ${u.sprintf(message, ...args)}`);
7453
7502
  }
7454
- console[stream](message, ...args);
7455
7503
  }
7456
7504
  }
7457
7505
  function printUserEvent(event) {
@@ -7510,7 +7558,7 @@ up.warn = up.log.warn;
7510
7558
 
7511
7559
 
7512
7560
  /***/ }),
7513
- /* 83 */
7561
+ /* 84 */
7514
7562
  /***/ (() => {
7515
7563
 
7516
7564
  up.syntax = (function () {
@@ -7656,7 +7704,7 @@ up.hello = up.syntax.hello;
7656
7704
 
7657
7705
 
7658
7706
  /***/ }),
7659
- /* 84 */
7707
+ /* 85 */
7660
7708
  /***/ (() => {
7661
7709
 
7662
7710
  up.history = (function () {
@@ -7793,10 +7841,10 @@ up.history = (function () {
7793
7841
 
7794
7842
 
7795
7843
  /***/ }),
7796
- /* 85 */
7844
+ /* 86 */
7797
7845
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
7798
7846
 
7799
- __webpack_require__(86);
7847
+ __webpack_require__(87);
7800
7848
  const u = up.util;
7801
7849
  const e = up.element;
7802
7850
  up.fragment = (function () {
@@ -8324,16 +8372,16 @@ u.delegate(up, ['context'], () => up.layer.current);
8324
8372
 
8325
8373
 
8326
8374
  /***/ }),
8327
- /* 86 */
8375
+ /* 87 */
8328
8376
  /***/ (() => {
8329
8377
 
8330
8378
 
8331
8379
 
8332
8380
  /***/ }),
8333
- /* 87 */
8381
+ /* 88 */
8334
8382
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8335
8383
 
8336
- __webpack_require__(88);
8384
+ __webpack_require__(89);
8337
8385
  up.viewport = (function () {
8338
8386
  const u = up.util;
8339
8387
  const e = up.element;
@@ -8655,13 +8703,13 @@ up.reveal = up.viewport.reveal;
8655
8703
 
8656
8704
 
8657
8705
  /***/ }),
8658
- /* 88 */
8706
+ /* 89 */
8659
8707
  /***/ (() => {
8660
8708
 
8661
8709
 
8662
8710
 
8663
8711
  /***/ }),
8664
- /* 89 */
8712
+ /* 90 */
8665
8713
  /***/ (function() {
8666
8714
 
8667
8715
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -8927,10 +8975,10 @@ up.animate = up.motion.animate;
8927
8975
 
8928
8976
 
8929
8977
  /***/ }),
8930
- /* 90 */
8978
+ /* 91 */
8931
8979
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
8932
8980
 
8933
- __webpack_require__(91);
8981
+ __webpack_require__(92);
8934
8982
  const u = up.util;
8935
8983
  up.network = (function () {
8936
8984
  const config = new up.Config(() => ({
@@ -8999,20 +9047,20 @@ up.network = (function () {
8999
9047
  cache.put(request);
9000
9048
  request.onLoading = () => cache.put(request);
9001
9049
  }
9002
- u.always(request, function (response) {
9003
- var _a, _b, _c, _d;
9004
- let expireCache = (_b = (_a = response.expireCache) !== null && _a !== void 0 ? _a : request.expireCache) !== null && _b !== void 0 ? _b : u.evalOption(config.expireCache, request, response);
9050
+ u.always(request, function (responseOrError) {
9051
+ var _a, _b, _c, _d, _e;
9052
+ let expireCache = (_b = (_a = responseOrError.expireCache) !== null && _a !== void 0 ? _a : request.expireCache) !== null && _b !== void 0 ? _b : u.evalOption(config.expireCache, request, responseOrError);
9005
9053
  if (expireCache) {
9006
9054
  cache.expire(expireCache, { except: request });
9007
9055
  }
9008
- let evictCache = (_d = (_c = response.evictCache) !== null && _c !== void 0 ? _c : request.evictCache) !== null && _d !== void 0 ? _d : u.evalOption(config.evictCache, request, response);
9056
+ let evictCache = (_d = (_c = responseOrError.evictCache) !== null && _c !== void 0 ? _c : request.evictCache) !== null && _d !== void 0 ? _d : u.evalOption(config.evictCache, request, responseOrError);
9009
9057
  if (evictCache) {
9010
9058
  cache.evict(evictCache, { except: request });
9011
9059
  }
9012
9060
  if (cache.get(request)) {
9013
9061
  cache.put(request);
9014
9062
  }
9015
- if (!response.ok) {
9063
+ if (!((_e = responseOrError.isCacheable) === null || _e === void 0 ? void 0 : _e.call(responseOrError))) {
9016
9064
  cache.evict(request);
9017
9065
  }
9018
9066
  });
@@ -9037,7 +9085,7 @@ up.network = (function () {
9037
9085
  }
9038
9086
  function registerAliasForRedirect(request, response) {
9039
9087
  if (request.cache && response.url && request.url !== response.url) {
9040
- const newRequest = request.variant({
9088
+ const newRequest = u.variant(request, {
9041
9089
  method: response.method,
9042
9090
  url: response.url
9043
9091
  });
@@ -9076,13 +9124,13 @@ up.cache = up.network.cache;
9076
9124
 
9077
9125
 
9078
9126
  /***/ }),
9079
- /* 91 */
9127
+ /* 92 */
9080
9128
  /***/ (() => {
9081
9129
 
9082
9130
 
9083
9131
 
9084
9132
  /***/ }),
9085
- /* 92 */
9133
+ /* 93 */
9086
9134
  /***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
9087
9135
 
9088
9136
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -9094,7 +9142,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9094
9142
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9095
9143
  });
9096
9144
  };
9097
- __webpack_require__(93);
9145
+ __webpack_require__(94);
9098
9146
  const u = up.util;
9099
9147
  const e = up.element;
9100
9148
  up.layer = (function () {
@@ -9240,7 +9288,7 @@ up.layer = (function () {
9240
9288
  return e.callbackAttr(link, attr, { exposedKeys: ['layer'] });
9241
9289
  }
9242
9290
  function closeCallbackAttr(link, attr) {
9243
- return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value'] });
9291
+ return e.callbackAttr(link, attr, { exposedKeys: ['layer', 'value', 'response'] });
9244
9292
  }
9245
9293
  function reset() {
9246
9294
  config.reset();
@@ -9335,16 +9383,16 @@ up.layer = (function () {
9335
9383
 
9336
9384
 
9337
9385
  /***/ }),
9338
- /* 93 */
9386
+ /* 94 */
9339
9387
  /***/ (() => {
9340
9388
 
9341
9389
 
9342
9390
 
9343
9391
  /***/ }),
9344
- /* 94 */
9392
+ /* 95 */
9345
9393
  /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
9346
9394
 
9347
- __webpack_require__(95);
9395
+ __webpack_require__(96);
9348
9396
  up.link = (function () {
9349
9397
  const u = up.util;
9350
9398
  const e = up.element;
@@ -9352,7 +9400,7 @@ up.link = (function () {
9352
9400
  let lastMousedownTarget = null;
9353
9401
  const LINKS_WITH_LOCAL_HTML = ['a[up-content]', 'a[up-fragment]', 'a[up-document]'];
9354
9402
  const LINKS_WITH_REMOTE_HTML = ['a[href]', '[up-href]'];
9355
- const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]'];
9403
+ const ATTRIBUTES_SUGGESTING_FOLLOW = ['[up-follow]', '[up-target]', '[up-layer]', '[up-transition]', '[up-preload]', '[up-instant]', '[up-href]'];
9356
9404
  function combineFollowableSelectors(elementSelectors, attributeSelectors) {
9357
9405
  return u.flatMap(elementSelectors, elementSelector => attributeSelectors.map(attrSelector => elementSelector + attrSelector));
9358
9406
  }
@@ -9430,7 +9478,6 @@ up.link = (function () {
9430
9478
  return options;
9431
9479
  }
9432
9480
  function followOptions(link, options, parserOptions) {
9433
- var _a, _b;
9434
9481
  link = up.fragment.get(link);
9435
9482
  options = parseRequestOptions(link, options, parserOptions);
9436
9483
  const parser = new up.OptionsParser(link, options, Object.assign({ fail: true }, parserOptions));
@@ -9485,7 +9532,6 @@ up.link = (function () {
9485
9532
  parser.booleanOrString('transition');
9486
9533
  parser.string('easing');
9487
9534
  parser.number('duration');
9488
- (_b = (_a = up.migrate).parseFollowOptions) === null || _b === void 0 ? void 0 : _b.call(_a, parser);
9489
9535
  if (!options.guardEvent) {
9490
9536
  options.guardEvent = up.event.build('up:link:follow', { log: 'Following link' });
9491
9537
  }
@@ -9628,20 +9674,21 @@ up.link = (function () {
9628
9674
  convertClicks,
9629
9675
  config,
9630
9676
  combineFollowableSelectors,
9631
- preloadSelector: fullPreloadSelector
9677
+ preloadSelector: fullPreloadSelector,
9678
+ followSelector: fullFollowSelector,
9632
9679
  };
9633
9680
  })();
9634
9681
  up.follow = up.link.follow;
9635
9682
 
9636
9683
 
9637
9684
  /***/ }),
9638
- /* 95 */
9685
+ /* 96 */
9639
9686
  /***/ (() => {
9640
9687
 
9641
9688
 
9642
9689
 
9643
9690
  /***/ }),
9644
- /* 96 */
9691
+ /* 97 */
9645
9692
  /***/ (() => {
9646
9693
 
9647
9694
  up.form = (function () {
@@ -9656,7 +9703,7 @@ up.form = (function () {
9656
9703
  submitButtonSelectors: ['input[type=submit]', 'input[type=image]', 'button[type=submit]', 'button:not([type])'],
9657
9704
  watchInputEvents: ['input', 'change'],
9658
9705
  watchInputDelay: 0,
9659
- watchChangeEvents: (field) => field.matches('input[type=date]') ? ['blur'] : ['change'],
9706
+ watchChangeEvents: ['change'],
9660
9707
  }));
9661
9708
  function fullSubmitSelector() {
9662
9709
  return config.submitSelectors.join(',');
@@ -10026,6 +10073,7 @@ up.form = (function () {
10026
10073
  disable: disableContainer,
10027
10074
  group: findGroup,
10028
10075
  groupSolution: findGroupSolution,
10076
+ groupSelectors: getGroupSelectors,
10029
10077
  get: getForm,
10030
10078
  };
10031
10079
  })();
@@ -10036,7 +10084,7 @@ up.validate = up.form.validate;
10036
10084
 
10037
10085
 
10038
10086
  /***/ }),
10039
- /* 97 */
10087
+ /* 98 */
10040
10088
  /***/ (() => {
10041
10089
 
10042
10090
  up.feedback = (function () {
@@ -10153,7 +10201,7 @@ up.feedback = (function () {
10153
10201
 
10154
10202
 
10155
10203
  /***/ }),
10156
- /* 98 */
10204
+ /* 99 */
10157
10205
  /***/ (() => {
10158
10206
 
10159
10207
  up.radio = (function () {
@@ -10231,7 +10279,7 @@ up.radio = (function () {
10231
10279
 
10232
10280
 
10233
10281
  /***/ }),
10234
- /* 99 */
10282
+ /* 100 */
10235
10283
  /***/ (() => {
10236
10284
 
10237
10285
  (function () {
@@ -10369,15 +10417,16 @@ __webpack_require__(82);
10369
10417
  __webpack_require__(83);
10370
10418
  __webpack_require__(84);
10371
10419
  __webpack_require__(85);
10372
- __webpack_require__(87);
10373
- __webpack_require__(89);
10420
+ __webpack_require__(86);
10421
+ __webpack_require__(88);
10374
10422
  __webpack_require__(90);
10375
- __webpack_require__(92);
10376
- __webpack_require__(94);
10377
- __webpack_require__(96);
10423
+ __webpack_require__(91);
10424
+ __webpack_require__(93);
10425
+ __webpack_require__(95);
10378
10426
  __webpack_require__(97);
10379
10427
  __webpack_require__(98);
10380
10428
  __webpack_require__(99);
10429
+ __webpack_require__(100);
10381
10430
  up.framework.onEvaled();
10382
10431
 
10383
10432
  })();