unpoly-rails 3.6.1.1 → 3.7.0.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.6.1'
8
+ version: '3.7.0'
9
9
  };
10
10
 
11
11
 
@@ -957,15 +957,8 @@ up.element = (function () {
957
957
  return Node.prototype.contains.call(root, element);
958
958
  }
959
959
  function ancestor(element, selector) {
960
- let parentElement = element.parentElement;
961
- if (parentElement) {
962
- if (parentElement.matches(selector)) {
963
- return parentElement;
964
- }
965
- else {
966
- return ancestor(parentElement, selector);
967
- }
968
- }
960
+ var _a;
961
+ return (_a = element.parentNode) === null || _a === void 0 ? void 0 : _a.closest(selector);
969
962
  }
970
963
  function around(element, selector) {
971
964
  return getList(element.closest(selector), subtree(element, selector));
@@ -2005,12 +1998,19 @@ const u = up.util;
2005
1998
  up.RenderJob = (_a = class RenderJob {
2006
1999
  constructor(options) {
2007
2000
  this.options = up.RenderOptions.preprocess(options);
2008
- this._rendered = this._execute();
2009
2001
  }
2010
- _execute() {
2002
+ execute() {
2003
+ this._rendered = this._executePromise();
2004
+ return this;
2005
+ }
2006
+ getPreflightFragments() {
2007
+ return this._getChange().getPreflightProps().fragments;
2008
+ }
2009
+ _executePromise() {
2011
2010
  return __awaiter(this, void 0, void 0, function* () {
2012
2011
  try {
2013
- let result = yield this._makeChange();
2012
+ this._guardRender();
2013
+ let result = yield this._getChange().execute();
2014
2014
  this._handleResult(result);
2015
2015
  return result;
2016
2016
  }
@@ -2035,7 +2035,7 @@ up.RenderJob = (_a = class RenderJob {
2035
2035
  _handleError(error) {
2036
2036
  let prefix = error instanceof up.Aborted ? 'Rendering was aborted' : 'Error while rendering';
2037
2037
  up.puts('up.render()', `${prefix}: ${error.name}: ${error.message}`);
2038
- up.error.guard(() => { var _a, _b; return (_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error); });
2038
+ up.error.guard(() => { var _b, _c; return (_c = (_b = this.options).onError) === null || _c === void 0 ? void 0 : _c.call(_b, error); });
2039
2039
  }
2040
2040
  get finished() {
2041
2041
  return this._awaitFinished();
@@ -2056,21 +2056,19 @@ up.RenderJob = (_a = class RenderJob {
2056
2056
  }
2057
2057
  });
2058
2058
  }
2059
- _makeChange() {
2060
- this._guardRender();
2059
+ _getChange() {
2061
2060
  if (this.options.url) {
2062
2061
  let onRequest = (request) => this._handleAbortOption(request);
2063
- this.change = new up.Change.FromURL(Object.assign(Object.assign({}, this.options), { onRequest }));
2062
+ return new up.Change.FromURL(Object.assign(Object.assign({}, this.options), { onRequest }));
2064
2063
  }
2065
2064
  else if (this.options.response) {
2066
- this.change = new up.Change.FromResponse(this.options);
2067
- this._handleAbortOption(null);
2065
+ let onRender = () => this._handleAbortOption(null);
2066
+ return new up.Change.FromResponse(Object.assign(Object.assign({}, this.options), { onRender }));
2068
2067
  }
2069
2068
  else {
2070
- this.change = new up.Change.FromContent(this.options);
2071
- this._handleAbortOption(null);
2069
+ let onRender = () => this._handleAbortOption(null);
2070
+ return new up.Change.FromContent(Object.assign(Object.assign({}, this.options), { onRender }));
2072
2071
  }
2073
- return this.change.execute();
2074
2072
  }
2075
2073
  _guardRender() {
2076
2074
  up.browser.assertConfirmed(this.options);
@@ -2087,7 +2085,7 @@ up.RenderJob = (_a = class RenderJob {
2087
2085
  let { abort } = this.options;
2088
2086
  if (!abort || !up.network.isBusy())
2089
2087
  return;
2090
- let { fragments, layer, origin, newLayer } = this.change.getPreflightProps();
2088
+ let { fragments, layer, origin, newLayer } = this._getChange().getPreflightProps();
2091
2089
  let abortOptions = {
2092
2090
  except: request,
2093
2091
  logOnce: ['up.render()', 'Change with { abort } option will abort other requests'],
@@ -2114,7 +2112,8 @@ up.RenderJob = (_a = class RenderJob {
2114
2112
  (() => {
2115
2113
  u.delegate(_a.prototype, ['then', 'catch', 'finally'], function () { return this._rendered; });
2116
2114
  u.memoizeMethod(_a.prototype, {
2117
- _awaitFinished: true
2115
+ _awaitFinished: true,
2116
+ _getChange: true,
2118
2117
  });
2119
2118
  })(),
2120
2119
  _a);
@@ -2313,7 +2312,8 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2313
2312
  const fragmentFocus = new up.FragmentFocus({
2314
2313
  fragment: this._content,
2315
2314
  layer: this.layer,
2316
- autoMeans: ['autofocus', 'layer']
2315
+ autoMeans: ['autofocus', 'layer'],
2316
+ inputDevice: this.options.inputDevice,
2317
2317
  });
2318
2318
  fragmentFocus.process(this.options.focus);
2319
2319
  }
@@ -2766,7 +2766,7 @@ up.Change.CloseLayer = class CloseLayer extends up.Change.Removal {
2766
2766
  this._layer.overlayFocus.teardown();
2767
2767
  (_a = formerParent.overlayFocus) === null || _a === void 0 ? void 0 : _a.moveToFront();
2768
2768
  let newFocusElement = this._layer.origin || formerParent.element;
2769
- newFocusElement.focus({ preventScroll: true });
2769
+ up.focus(newFocusElement, { preventScroll: true });
2770
2770
  }
2771
2771
  };
2772
2772
 
@@ -2784,7 +2784,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2784
2784
  this.options.normalizeLayerOptions = false;
2785
2785
  }
2786
2786
  execute() {
2787
- var _a, _b;
2787
+ var _b, _c;
2788
2788
  let _newPageReason = this._newPageReason();
2789
2789
  if (_newPageReason) {
2790
2790
  up.puts('up.render()', _newPageReason);
@@ -2792,7 +2792,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2792
2792
  return u.unresolvablePromise();
2793
2793
  }
2794
2794
  this.request = up.request(this._getRequestAttrs());
2795
- (_b = (_a = this.options).onRequest) === null || _b === void 0 ? void 0 : _b.call(_a, this.request);
2795
+ (_c = (_b = this.options).onRequest) === null || _c === void 0 ? void 0 : _c.call(_b, this.request);
2796
2796
  up.feedback.showAroundRequest(this.request, this.options);
2797
2797
  up.form.disableWhile(this.request, this.options);
2798
2798
  if (this.options.preload) {
@@ -2873,14 +2873,14 @@ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2873
2873
  this._request = this._response.request;
2874
2874
  }
2875
2875
  execute() {
2876
- var _a;
2876
+ var _b;
2877
2877
  if (up.fragment.config.skipResponse(this._loadedEventProps())) {
2878
2878
  this._skip();
2879
2879
  }
2880
2880
  else {
2881
2881
  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() }));
2882
2882
  }
2883
- let fail = (_a = u.evalOption(this.options.fail, this._response)) !== null && _a !== void 0 ? _a : !this._response.ok;
2883
+ let fail = (_b = u.evalOption(this.options.fail, this._response)) !== null && _b !== void 0 ? _b : !this._response.ok;
2884
2884
  if (fail) {
2885
2885
  throw this._updateContentFromResponse(this.deriveFailOptions());
2886
2886
  }
@@ -2938,13 +2938,13 @@ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2938
2938
  };
2939
2939
  }
2940
2940
  _compilerPassMeta() {
2941
- var _a, _b;
2941
+ var _b, _c;
2942
2942
  let meta = { revalidating: !!this.options.expiredResponse };
2943
- (_b = (_a = up.migrate).processCompilerPassMeta) === null || _b === void 0 ? void 0 : _b.call(_a, meta, this._response);
2943
+ (_c = (_b = up.migrate).processCompilerPassMeta) === null || _c === void 0 ? void 0 : _c.call(_b, meta, this._response);
2944
2944
  return meta;
2945
2945
  }
2946
2946
  _augmentOptionsFromResponse(renderOptions) {
2947
- var _a, _b;
2947
+ var _b, _c;
2948
2948
  const responseURL = this._response.url;
2949
2949
  let serverLocation = responseURL;
2950
2950
  let hash = this._request.hash;
@@ -2975,8 +2975,8 @@ up.Change.FromResponse = (_a = class FromResponse extends up.Change {
2975
2975
  }
2976
2976
  renderOptions.context = u.merge(renderOptions.context, this._response.context);
2977
2977
  renderOptions.cspNonces = this._response.cspNonces;
2978
- (_a = renderOptions.time) !== null && _a !== void 0 ? _a : (renderOptions.time = this._response.lastModified);
2979
- (_b = renderOptions.etag) !== null && _b !== void 0 ? _b : (renderOptions.etag = this._response.etag);
2978
+ (_b = renderOptions.time) !== null && _b !== void 0 ? _b : (renderOptions.time = this._response.lastModified);
2979
+ (_c = renderOptions.etag) !== null && _c !== void 0 ? _c : (renderOptions.etag = this._response.etag);
2980
2980
  }
2981
2981
  },
2982
2982
  (() => {
@@ -3041,6 +3041,7 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3041
3041
  return !(error instanceof up.CannotMatch);
3042
3042
  }
3043
3043
  _onPlanApplicable(plan) {
3044
+ var _b, _c;
3044
3045
  let primaryPlan = this._getPlans()[0];
3045
3046
  if (plan !== primaryPlan) {
3046
3047
  up.puts('up.render()', 'Could not match primary target "%s". Updating a fallback target "%s".', primaryPlan.target, plan.target);
@@ -3049,9 +3050,10 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3049
3050
  if (assets) {
3050
3051
  up.script.assertAssetsOK(assets, plan.options);
3051
3052
  }
3053
+ (_c = (_b = this.options).onRender) === null || _c === void 0 ? void 0 : _c.call(_b);
3052
3054
  }
3053
3055
  _getResponseDoc() {
3054
- var _a, _b;
3056
+ var _b, _c;
3055
3057
  if (this._preview)
3056
3058
  return;
3057
3059
  const docOptions = u.pick(this.options, [
@@ -3063,19 +3065,19 @@ up.Change.FromContent = (_a = class FromContent extends up.Change {
3063
3065
  'cspNonces',
3064
3066
  'origin',
3065
3067
  ]);
3066
- (_b = (_a = up.migrate).handleResponseDocOptions) === null || _b === void 0 ? void 0 : _b.call(_a, docOptions);
3068
+ (_c = (_b = up.migrate).handleResponseDocOptions) === null || _c === void 0 ? void 0 : _c.call(_b, docOptions);
3067
3069
  if (this._defaultPlacement() === 'content') {
3068
3070
  docOptions.target = this._firstExpandedTarget(docOptions.target);
3069
3071
  }
3070
3072
  return new up.ResponseDoc(docOptions);
3071
3073
  }
3072
3074
  _improveOptionsFromResponseDoc() {
3073
- var _a;
3075
+ var _b;
3074
3076
  if (this._preview)
3075
3077
  return;
3076
3078
  let responseDoc = this._getResponseDoc();
3077
3079
  if (this.options.fragment) {
3078
- (_a = this.options).target || (_a.target = responseDoc.rootSelector());
3080
+ (_b = this.options).target || (_b.target = responseDoc.rootSelector());
3079
3081
  }
3080
3082
  this.options.title = this.improveHistoryValue(this.options.title, responseDoc.title);
3081
3083
  this.options.metaTags = this.improveHistoryValue(this.options.metaTags, responseDoc.metaTags);
@@ -3504,6 +3506,7 @@ up.EventListener = class EventListener extends up.Record {
3504
3506
  'baseLayer',
3505
3507
  'passive',
3506
3508
  'once',
3509
+ 'capture',
3507
3510
  'beforeBoot',
3508
3511
  ];
3509
3512
  }
@@ -3525,7 +3528,7 @@ up.EventListener = class EventListener extends up.Record {
3525
3528
  this.element.addEventListener(...this._addListenerArg());
3526
3529
  }
3527
3530
  _addListenerArg() {
3528
- let options = u.compactObject(u.pick(this, ['once', 'passive']));
3531
+ let options = u.compactObject(u.pick(this, ['once', 'passive', 'capture']));
3529
3532
  return [this.eventType, this.nativeCallback, options];
3530
3533
  }
3531
3534
  unbind() {
@@ -3610,6 +3613,7 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3610
3613
  'baseLayer',
3611
3614
  'passive',
3612
3615
  'once',
3616
+ 'capture',
3613
3617
  'beforeBoot',
3614
3618
  ];
3615
3619
  }
@@ -3681,56 +3685,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3681
3685
  };
3682
3686
  const u = up.util;
3683
3687
  up.FieldWatcher = class FieldWatcher {
3684
- constructor(fields, options, callback) {
3685
- this._callback = callback;
3686
- this._fields = fields;
3688
+ constructor(root, options, callback) {
3687
3689
  this._options = options;
3690
+ this._root = root;
3691
+ this._scope = up.form.getScope(root);
3692
+ this._callback = callback;
3688
3693
  this._batch = options.batch;
3689
- this._unbindFns = [];
3690
- }
3691
- _fieldOptions(field) {
3692
- let options = u.copy(this._options);
3693
- return up.form.watchOptions(field, options, { defaults: { event: 'input' } });
3694
+ this._abortable = options.abortable;
3694
3695
  }
3695
3696
  start() {
3696
3697
  this._scheduledValues = null;
3697
3698
  this._processedValues = this._readFieldValues();
3698
3699
  this._currentTimer = null;
3699
3700
  this._callbackRunning = false;
3700
- for (let field of this._fields) {
3701
- this._watchField(field);
3701
+ this._unbindFns = [];
3702
+ this._watchFieldsWithin(this._root);
3703
+ this._root.addEventListener('up:fragment:inserted', ({ target }) => {
3704
+ if (target !== this._root)
3705
+ this._watchFieldsWithin(target);
3706
+ });
3707
+ for (let abortableElement of this._abortableElements()) {
3708
+ this._unbindFns.push(up.fragment.onAborted(abortableElement, () => this._abort()));
3702
3709
  }
3703
- }
3704
- _watchField(field) {
3705
- let _fieldOptions = this._fieldOptions(field);
3706
- this._unbindFns.push(up.on(field, _fieldOptions.event, (event) => this._check(event, _fieldOptions)));
3707
- this._unbindFns.push(up.fragment.onAborted(field, () => this._cancelTimer()));
3710
+ this._unbindFns.push(up.on(this._scope, 'reset', () => this._onFormReset()));
3708
3711
  }
3709
3712
  stop() {
3713
+ this._abort();
3710
3714
  for (let unbindFn of this._unbindFns)
3711
3715
  unbindFn();
3712
- this._cancelTimer();
3713
3716
  }
3714
- _cancelTimer() {
3715
- clearTimeout(this._currentTimer);
3716
- this._currentTimer = null;
3717
+ _fieldOptions(field) {
3718
+ let rootOptions = u.copy(this._options);
3719
+ return up.form.watchOptions(field, rootOptions, { defaults: { event: 'input' } });
3720
+ }
3721
+ _abortableElements() {
3722
+ var _a;
3723
+ if (this._abortable === false) {
3724
+ return [];
3725
+ }
3726
+ else {
3727
+ return u.wrapList((_a = this._abortable) !== null && _a !== void 0 ? _a : this._scope);
3728
+ }
3717
3729
  }
3718
- _isAnyFieldAttached() {
3719
- return u.some(this._fields, 'isConnected');
3730
+ _watchFieldsWithin(container) {
3731
+ for (let field of up.form.fields(container)) {
3732
+ this._watchField(field);
3733
+ }
3734
+ }
3735
+ _watchField(field) {
3736
+ let fieldOptions = this._fieldOptions(field);
3737
+ this._unbindFns.push(up.on(field, fieldOptions.event, () => this._check(fieldOptions)));
3738
+ }
3739
+ _abort() {
3740
+ this._scheduledValues = null;
3720
3741
  }
3721
- _scheduleValues(values, event, _fieldOptions) {
3722
- this._cancelTimer();
3742
+ _scheduleValues(values, fieldOptions) {
3743
+ clearTimeout(this._currentTimer);
3723
3744
  this._scheduledValues = values;
3724
- let delay = u.evalOption(_fieldOptions.delay, event);
3745
+ let delay = fieldOptions.delay || 0;
3725
3746
  this._currentTimer = u.timer(delay, () => {
3726
- this._currentTimer = null;
3727
- if (this._isAnyFieldAttached()) {
3728
- this.scheduledFieldOptions = _fieldOptions;
3729
- this._requestCallback();
3730
- }
3731
- else {
3732
- this._scheduledValues = null;
3733
- }
3747
+ this._scheduledFieldOptions = fieldOptions;
3748
+ this._requestCallback();
3734
3749
  });
3735
3750
  }
3736
3751
  _isNewValues(values) {
@@ -3738,32 +3753,36 @@ up.FieldWatcher = class FieldWatcher {
3738
3753
  }
3739
3754
  _requestCallback() {
3740
3755
  return __awaiter(this, void 0, void 0, function* () {
3741
- let _fieldOptions = this.scheduledFieldOptions;
3742
- if ((this._scheduledValues !== null) && !this._currentTimer && !this._callbackRunning) {
3743
- const diff = this._changedValues(this._processedValues, this._scheduledValues);
3744
- this._processedValues = this._scheduledValues;
3745
- this._scheduledValues = null;
3746
- this._callbackRunning = true;
3747
- this.scheduledFieldOptions = null;
3748
- let callbackOptions = Object.assign(Object.assign({}, _fieldOptions), { disable: false });
3749
- const callbackReturnValues = [];
3750
- if (this._batch) {
3751
- callbackReturnValues.push(this._runCallback(diff, callbackOptions));
3752
- }
3753
- else {
3754
- for (let name in diff) {
3755
- const value = diff[name];
3756
- callbackReturnValues.push(this._runCallback(value, name, callbackOptions));
3757
- }
3758
- }
3759
- if (u.some(callbackReturnValues, u.isPromise)) {
3760
- let callbackDone = Promise.allSettled(callbackReturnValues);
3761
- up.form.disableWhile(callbackDone, _fieldOptions);
3762
- yield callbackDone;
3756
+ if (!this._scheduledValues)
3757
+ return;
3758
+ if (this._callbackRunning)
3759
+ return;
3760
+ if (!this._scope.isConnected)
3761
+ return;
3762
+ let fieldOptions = this._scheduledFieldOptions;
3763
+ const diff = this._changedValues(this._processedValues, this._scheduledValues);
3764
+ this._processedValues = this._scheduledValues;
3765
+ this._scheduledValues = null;
3766
+ this._callbackRunning = true;
3767
+ this._scheduledFieldOptions = null;
3768
+ let callbackOptions = Object.assign(Object.assign({}, fieldOptions), { disable: false });
3769
+ const callbackReturnValues = [];
3770
+ if (this._batch) {
3771
+ callbackReturnValues.push(this._runCallback(diff, callbackOptions));
3772
+ }
3773
+ else {
3774
+ for (let name in diff) {
3775
+ const value = diff[name];
3776
+ callbackReturnValues.push(this._runCallback(value, name, callbackOptions));
3763
3777
  }
3764
- this._callbackRunning = false;
3765
- this._requestCallback();
3766
3778
  }
3779
+ if (u.some(callbackReturnValues, u.isPromise)) {
3780
+ let callbackDone = Promise.allSettled(callbackReturnValues);
3781
+ up.form.disableWhile(callbackDone, fieldOptions);
3782
+ yield callbackDone;
3783
+ }
3784
+ this._callbackRunning = false;
3785
+ this._requestCallback();
3767
3786
  });
3768
3787
  }
3769
3788
  _runCallback(...args) {
@@ -3784,14 +3803,17 @@ up.FieldWatcher = class FieldWatcher {
3784
3803
  return changes;
3785
3804
  }
3786
3805
  _readFieldValues() {
3787
- return up.Params.fromFields(this._fields).toObject();
3806
+ return up.Params.fromContainer(this._root).toObject();
3788
3807
  }
3789
- _check(event, _fieldOptions) {
3808
+ _check(fieldOptions = {}) {
3790
3809
  const values = this._readFieldValues();
3791
3810
  if (this._isNewValues(values)) {
3792
- this._scheduleValues(values, event, _fieldOptions);
3811
+ this._scheduleValues(values, fieldOptions);
3793
3812
  }
3794
3813
  }
3814
+ _onFormReset() {
3815
+ u.task(() => this._check());
3816
+ }
3795
3817
  };
3796
3818
 
3797
3819
 
@@ -4153,7 +4175,8 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
4153
4175
  keys() {
4154
4176
  return super.keys().concat([
4155
4177
  'hash',
4156
- 'focusCapsule'
4178
+ 'focusCapsule',
4179
+ 'inputDevice',
4157
4180
  ]);
4158
4181
  }
4159
4182
  processPrimitive(opt) {
@@ -4211,7 +4234,7 @@ up.FragmentFocus = class FragmentFocus extends up.FragmentProcessor {
4211
4234
  }
4212
4235
  _focusElement(element) {
4213
4236
  if (element) {
4214
- up.focus(element, Object.assign({ force: true }, PREVENT_SCROLL_OPTIONS));
4237
+ up.focus(element, Object.assign(Object.assign({ force: true }, PREVENT_SCROLL_OPTIONS), { inputDevice: this.inputDevice }));
4215
4238
  return true;
4216
4239
  }
4217
4240
  }
@@ -5889,8 +5912,11 @@ up.Params = class Params {
5889
5912
  return this.entries.length === 0;
5890
5913
  }
5891
5914
  static fromForm(form) {
5892
- form = up.fragment.get(form);
5893
- return this.fromFields(up.form.fields(form));
5915
+ return this.fromContainer(form);
5916
+ }
5917
+ static fromContainer(container) {
5918
+ let fields = up.form.fields(container);
5919
+ return this.fromFields(fields);
5894
5920
  }
5895
5921
  static fromFields(fields) {
5896
5922
  const params = new (this)();
@@ -6075,7 +6101,7 @@ up.RenderOptions = (function () {
6075
6101
  var _a, _b;
6076
6102
  (_b = (_a = up.migrate).preprocessRenderOptions) === null || _b === void 0 ? void 0 : _b.call(_a, options);
6077
6103
  const defaults = u.merge(GLOBAL_DEFAULTS, navigateDefaults(options));
6078
- return u.merge(u.omit(defaults, LATE_KEYS), { defaults }, options, preloadOverrides(options));
6104
+ return u.merge(u.omit(defaults, LATE_KEYS), { defaults }, { inputDevice: up.event.inputDevice }, options, preloadOverrides(options));
6079
6105
  }
6080
6106
  function finalize(preprocessedOptions, lateDefaults) {
6081
6107
  return u.merge(preprocessedOptions.defaults, lateDefaults, preprocessedOptions);
@@ -6227,7 +6253,7 @@ up.Request = (_a = class Request extends up.Record {
6227
6253
  };
6228
6254
  }
6229
6255
  constructor(options) {
6230
- var _a, _b, _c;
6256
+ var _b, _c, _d;
6231
6257
  super(options);
6232
6258
  this.params = new up.Params(this.params);
6233
6259
  if (this.wrapMethod == null) {
@@ -6239,17 +6265,17 @@ up.Request = (_a = class Request extends up.Record {
6239
6265
  this.layer = up.layer.get(this.layer, layerLookupOptions);
6240
6266
  this.failLayer = up.layer.get(this.failLayer, layerLookupOptions);
6241
6267
  this.context || (this.context = this.layer.context || {});
6242
- this.failContext || (this.failContext = ((_a = this.failLayer) === null || _a === void 0 ? void 0 : _a.context) || {});
6268
+ this.failContext || (this.failContext = ((_b = this.failLayer) === null || _b === void 0 ? void 0 : _b.context) || {});
6243
6269
  this.mode || (this.mode = this.layer.mode);
6244
- this.failMode || (this.failMode = (_b = this.failLayer) === null || _b === void 0 ? void 0 : _b.mode);
6270
+ this.failMode || (this.failMode = (_c = this.failLayer) === null || _c === void 0 ? void 0 : _c.mode);
6245
6271
  }
6246
6272
  this.deferred = u.newDeferred();
6247
- (_c = this.badResponseTime) !== null && _c !== void 0 ? _c : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
6273
+ (_d = this.badResponseTime) !== null && _d !== void 0 ? _d : (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this));
6248
6274
  this._addAutoHeaders();
6249
6275
  }
6250
6276
  get xhr() {
6251
- var _a;
6252
- return (_a = this._xhr) !== null && _a !== void 0 ? _a : (this._xhr = new XMLHttpRequest());
6277
+ var _b;
6278
+ return (_b = this._xhr) !== null && _b !== void 0 ? _b : (this._xhr = new XMLHttpRequest());
6253
6279
  }
6254
6280
  get fragments() {
6255
6281
  if (this._fragments) {
@@ -6266,8 +6292,8 @@ up.Request = (_a = class Request extends up.Record {
6266
6292
  this._fragments = value;
6267
6293
  }
6268
6294
  get fragment() {
6269
- var _a;
6270
- return (_a = this.fragments) === null || _a === void 0 ? void 0 : _a[0];
6295
+ var _b;
6296
+ return (_b = this.fragments) === null || _b === void 0 ? void 0 : _b[0];
6271
6297
  }
6272
6298
  _normalize() {
6273
6299
  this.method = u.normalizeMethod(this.method);
@@ -6284,8 +6310,8 @@ up.Request = (_a = class Request extends up.Record {
6284
6310
  });
6285
6311
  }
6286
6312
  _extractHashFromURL() {
6287
- var _a;
6288
- let match = (_a = this.url) === null || _a === void 0 ? void 0 : _a.match(/^([^#]*)(#.+)$/);
6313
+ var _b;
6314
+ let match = (_b = this.url) === null || _b === void 0 ? void 0 : _b.match(/^([^#]*)(#.+)$/);
6289
6315
  if (match) {
6290
6316
  this.url = match[1];
6291
6317
  return this.hash = match[2];
@@ -6311,18 +6337,18 @@ up.Request = (_a = class Request extends up.Record {
6311
6337
  return u.evalAutoOption(this.cache, up.network.config.autoCache, this);
6312
6338
  }
6313
6339
  runQueuedCallbacks() {
6314
- var _a;
6340
+ var _b;
6315
6341
  u.always(this, () => this._evictExpensiveAttrs());
6316
- (_a = this.onQueued) === null || _a === void 0 ? void 0 : _a.call(this, this);
6342
+ (_b = this.onQueued) === null || _b === void 0 ? void 0 : _b.call(this, this);
6317
6343
  }
6318
6344
  load() {
6319
- var _a;
6345
+ var _b;
6320
6346
  if (this.state !== 'new')
6321
6347
  return;
6322
6348
  if (this._emitLoad()) {
6323
6349
  this.state = 'loading';
6324
6350
  this._normalize();
6325
- (_a = this.onLoading) === null || _a === void 0 ? void 0 : _a.call(this);
6351
+ (_b = this.onLoading) === null || _b === void 0 ? void 0 : _b.call(this);
6326
6352
  this.expired = false;
6327
6353
  new up.Request.XHRRenderer(this).buildAndSend({
6328
6354
  onload: () => this._onXHRLoad(),
@@ -7064,8 +7090,8 @@ up.ResponseDoc = (_a = class ResponseDoc {
7064
7090
  return this._fromHead(up.script.findAssets);
7065
7091
  }
7066
7092
  _getTitleText(head) {
7067
- var _a;
7068
- return (_a = head.querySelector('title')) === null || _a === void 0 ? void 0 : _a.textContent;
7093
+ var _b;
7094
+ return (_b = head.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent;
7069
7095
  }
7070
7096
  select(selector) {
7071
7097
  let finder = new up.FragmentFinder({
@@ -7142,16 +7168,16 @@ const e = up.element;
7142
7168
  const u = up.util;
7143
7169
  up.RevealMotion = class RevealMotion {
7144
7170
  constructor(element, options = {}) {
7145
- var _a, _b, _c, _d, _e, _f, _g, _h;
7171
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
7146
7172
  this._element = element;
7147
- this._options = options;
7148
- this._viewport = e.get(this._options.viewport) || up.viewport.get(this._element);
7173
+ this._viewport = e.get(options.viewport) || up.viewport.get(this._element);
7149
7174
  this._obstructionsLayer = up.layer.get(this._viewport);
7175
+ this._behavior = (_a = options.behavior) !== null && _a !== void 0 ? _a : 'instant';
7150
7176
  const viewportConfig = up.viewport.config;
7151
- this._snap = (_b = (_a = this._options.snap) !== null && _a !== void 0 ? _a : this._options.revealSnap) !== null && _b !== void 0 ? _b : viewportConfig.revealSnap;
7152
- this._padding = (_d = (_c = this._options.padding) !== null && _c !== void 0 ? _c : this._options.revealPadding) !== null && _d !== void 0 ? _d : viewportConfig.revealPadding;
7153
- this._top = (_f = (_e = this._options.top) !== null && _e !== void 0 ? _e : this._options.revealTop) !== null && _f !== void 0 ? _f : viewportConfig.revealTop;
7154
- this._max = (_h = (_g = this._options.max) !== null && _g !== void 0 ? _g : this._options.revealMax) !== null && _h !== void 0 ? _h : viewportConfig.revealMax;
7177
+ this._snap = (_c = (_b = options.snap) !== null && _b !== void 0 ? _b : options.revealSnap) !== null && _c !== void 0 ? _c : viewportConfig.revealSnap;
7178
+ this._padding = (_e = (_d = options.padding) !== null && _d !== void 0 ? _d : options.revealPadding) !== null && _e !== void 0 ? _e : viewportConfig.revealPadding;
7179
+ this._top = (_g = (_f = options.top) !== null && _f !== void 0 ? _f : options.revealTop) !== null && _g !== void 0 ? _g : viewportConfig.revealTop;
7180
+ this._max = (_j = (_h = options.max) !== null && _h !== void 0 ? _h : options.revealMax) !== null && _j !== void 0 ? _j : viewportConfig.revealMax;
7155
7181
  this._topObstructionSelector = viewportConfig.selector('fixedTopSelectors');
7156
7182
  this._bottomObstructionSelector = viewportConfig.selector('fixedBottomSelectors');
7157
7183
  }
@@ -7185,7 +7211,7 @@ up.RevealMotion = class RevealMotion {
7185
7211
  newScrollTop = 0;
7186
7212
  }
7187
7213
  if (newScrollTop !== originalScrollTop) {
7188
- this._viewport.scrollTo(Object.assign(Object.assign({}, this._options), { top: newScrollTop }));
7214
+ this._viewport.scrollTo({ top: newScrollTop, behavior: this._behavior });
7189
7215
  }
7190
7216
  }
7191
7217
  _getViewportRect() {
@@ -7667,6 +7693,16 @@ up.event = (function () {
7667
7693
  up.emit(element, forkedEvent);
7668
7694
  }
7669
7695
  on('up:click', 'a[up-emit]', executeEmitAttr);
7696
+ let inputDevices = ['unknown'];
7697
+ function getInputDevice() {
7698
+ return u.last(inputDevices);
7699
+ }
7700
+ function observeInputDevice(newModality) {
7701
+ inputDevices.push(newModality);
7702
+ setTimeout(() => inputDevices.pop());
7703
+ }
7704
+ on('keydown keyup', { capture: true }, () => observeInputDevice('key'));
7705
+ on('pointerdown pointerup', { capture: true }, () => observeInputDevice('pointer'));
7670
7706
  on('up:framework:reset', reset);
7671
7707
  return {
7672
7708
  on,
@@ -7679,6 +7715,7 @@ up.event = (function () {
7679
7715
  isUnmodified,
7680
7716
  fork,
7681
7717
  keyModifiers,
7718
+ get inputDevice() { return getInputDevice(); }
7682
7719
  };
7683
7720
  })();
7684
7721
  up.on = up.event.on;
@@ -8340,7 +8377,7 @@ up.fragment = (function () {
8340
8377
  }
8341
8378
  const render = up.mockable((...args) => {
8342
8379
  let options = parseTargetAndOptions(args);
8343
- return new up.RenderJob(options);
8380
+ return new up.RenderJob(options).execute();
8344
8381
  });
8345
8382
  const navigate = up.mockable((...args) => {
8346
8383
  const options = parseTargetAndOptions(args);
@@ -8817,6 +8854,7 @@ up.viewport = (function () {
8817
8854
  revealPadding: 0,
8818
8855
  revealTop: false,
8819
8856
  revealMax() { return 0.5 * window.innerHeight; },
8857
+ autoFocusVisible({ element, inputDevice }) { return inputDevice === 'key' || up.form.isField(element); }
8820
8858
  }));
8821
8859
  const bodyShifter = new up.BodyShifter();
8822
8860
  up.compiler(config.selectorFn('anchoredRightSelectors'), function (element) {
@@ -8836,25 +8874,35 @@ up.viewport = (function () {
8836
8874
  motion.start();
8837
8875
  return ((_b = (_a = up.migrate).formerlyAsync) === null || _b === void 0 ? void 0 : _b.call(_a, 'up.reveal()')) || true;
8838
8876
  }
8839
- function doFocus(element, options = {}) {
8840
- if (options.force) {
8841
- makeFocusable(element);
8877
+ function doFocus(element, { preventScroll, force, inputDevice, focusVisible } = {}) {
8878
+ if (force) {
8879
+ if (!element.hasAttribute('tabindex') && element.tabIndex === -1) {
8880
+ element.setAttribute('tabindex', '-1');
8881
+ }
8842
8882
  }
8843
- element.focus({ preventScroll: true });
8844
- if (!options.preventScroll) {
8883
+ inputDevice !== null && inputDevice !== void 0 ? inputDevice : (inputDevice = up.event.inputDevice);
8884
+ focusVisible !== null && focusVisible !== void 0 ? focusVisible : (focusVisible = 'auto');
8885
+ focusVisible = u.evalAutoOption(focusVisible, config.autoFocusVisible, { element, inputDevice });
8886
+ element.focus({
8887
+ preventScroll: true,
8888
+ focusVisible,
8889
+ });
8890
+ removeFocusClasses(element);
8891
+ element.classList.add(focusVisible ? 'up-focus-visible' : 'up-focus-hidden');
8892
+ if (!preventScroll) {
8845
8893
  return reveal(element);
8846
8894
  }
8847
8895
  }
8896
+ function removeFocusClasses(element) {
8897
+ element === null || element === void 0 ? void 0 : element.classList.remove('up-focus-hidden', 'up-focus-visible');
8898
+ }
8899
+ up.on('focusin', function ({ relatedTarget }) {
8900
+ removeFocusClasses(relatedTarget);
8901
+ });
8848
8902
  function tryFocus(element, options) {
8849
8903
  doFocus(element, options);
8850
8904
  return element === document.activeElement;
8851
8905
  }
8852
- function makeFocusable(element) {
8853
- if (!element.hasAttribute('tabindex') && element.tabIndex === -1) {
8854
- element.setAttribute('tabindex', '-1');
8855
- element.classList.add('up-focusable-content');
8856
- }
8857
- }
8858
8906
  function revealHash(hash = location.hash, options) {
8859
8907
  let match = firstHashTarget(hash, options);
8860
8908
  if (match) {
@@ -10134,8 +10182,11 @@ up.form = (function () {
10134
10182
  return config.selector('submitButtonSelectors');
10135
10183
  }
10136
10184
  const submit = up.mockable((form, options) => {
10137
- return up.render(submitOptions(form, options));
10185
+ return buildSubmitJob(form, options).execute();
10138
10186
  });
10187
+ function buildSubmitJob(form, options) {
10188
+ return new up.RenderJob(submitOptions(form, options));
10189
+ }
10139
10190
  function submitOptions(form, options, parserOptions) {
10140
10191
  form = getForm(form);
10141
10192
  options = u.options(options);
@@ -10152,6 +10203,9 @@ up.form = (function () {
10152
10203
  parser.include(up.link.followOptions);
10153
10204
  return options;
10154
10205
  }
10206
+ function getPreflightFragments(form) {
10207
+ return buildSubmitJob(form).getPreflightFragments();
10208
+ }
10155
10209
  function watchOptions(field, options, parserOptions = {}) {
10156
10210
  var _a;
10157
10211
  options = u.options(options);
@@ -10218,7 +10272,7 @@ up.form = (function () {
10218
10272
  return u.noop;
10219
10273
  let missingOption = (key) => { up.fail("Cannot process { disable: '%s' } option without { %s }", disable, key); };
10220
10274
  let getOrigin = () => origin || missingOption('origin');
10221
- let getOriginForm = () => getContainer(getOrigin());
10275
+ let getOriginForm = () => getScope(getOrigin());
10222
10276
  let containers;
10223
10277
  if (disable === true) {
10224
10278
  containers = [getOriginForm()];
@@ -10261,17 +10315,13 @@ up.form = (function () {
10261
10315
  button.focus();
10262
10316
  }
10263
10317
  });
10264
- function watch(container, ...args) {
10265
- const fields = findFields(container);
10266
- const unnamedFields = u.reject(fields, 'name');
10267
- if (unnamedFields.length) {
10268
- up.puts('up.watch()', 'Will not watch fields without a [name]: %o', unnamedFields);
10269
- }
10270
- const callback = u.extractCallback(args) || watchCallbackFromElement(container) || up.fail('No callback given for up.watch()');
10318
+ function watch(root, ...args) {
10319
+ root = up.element.get(root);
10320
+ const callback = u.extractCallback(args) || watchCallbackFromElement(root) || up.fail('No callback given for up.watch()');
10271
10321
  let options = u.extractOptions(args);
10272
- const watch = new up.FieldWatcher(fields, options, callback);
10273
- watch.start();
10274
- return () => watch.stop();
10322
+ const watcher = new up.FieldWatcher(root, options, callback);
10323
+ watcher.start();
10324
+ return () => watcher.stop();
10275
10325
  }
10276
10326
  function watchCallbackFromElement(element) {
10277
10327
  let rawCallback = element.getAttribute('up-watch');
@@ -10279,8 +10329,12 @@ up.form = (function () {
10279
10329
  return up.NonceableCallback.fromString(rawCallback).toFunction('value', 'name').bind(element);
10280
10330
  }
10281
10331
  }
10282
- function autosubmit(target, options) {
10283
- return watch(target, options, (_value, _name, renderOptions) => submit(target, renderOptions));
10332
+ function autosubmit(target, options = {}) {
10333
+ var _a;
10334
+ const form = getForm(target);
10335
+ (_a = options.abortable) !== null && _a !== void 0 ? _a : (options.abortable = [form, ...getPreflightFragments(form)]);
10336
+ const onChange = (_value, _name, renderOptions) => submit(target, renderOptions);
10337
+ return watch(target, options, onChange);
10284
10338
  }
10285
10339
  function getGroupSelectors() {
10286
10340
  var _a, _b;
@@ -10335,7 +10389,7 @@ up.form = (function () {
10335
10389
  }
10336
10390
  }
10337
10391
  else if (field.matches('input[type=radio]')) {
10338
- const form = getContainer(field);
10392
+ const form = getScope(field);
10339
10393
  const groupName = field.getAttribute('name');
10340
10394
  const checkedButton = form.querySelector(`input[type=radio]${e.attrSelector('name', groupName)}:checked`);
10341
10395
  if (checkedButton) {
@@ -10364,7 +10418,7 @@ up.form = (function () {
10364
10418
  }
10365
10419
  function switchTargets(switcher, options = {}) {
10366
10420
  const targetSelector = options.target || options.target || switcher.getAttribute('up-switch');
10367
- const form = getContainer(switcher);
10421
+ const form = getScope(switcher);
10368
10422
  targetSelector || up.fail("No switch target given for %o", switcher);
10369
10423
  const fieldValues = switcherValues(switcher);
10370
10424
  for (let target of up.fragment.all(form, targetSelector)) {
@@ -10391,7 +10445,7 @@ up.form = (function () {
10391
10445
  return u.parseTokens(str, { json: true });
10392
10446
  }
10393
10447
  function findSwitcherForTarget(target) {
10394
- const form = getContainer(target);
10448
+ const form = getScope(target);
10395
10449
  const switchers = form.querySelectorAll('[up-switch]');
10396
10450
  const switcher = u.find(switchers, function (switcher) {
10397
10451
  const targetSelector = switcher.getAttribute('up-switch');
@@ -10403,7 +10457,7 @@ up.form = (function () {
10403
10457
  const element = up.fragment.get(elementOrSelector, options);
10404
10458
  return element.form || element.closest('form');
10405
10459
  }
10406
- function getContainer(element, options) {
10460
+ function getScope(element, options) {
10407
10461
  return getForm(element, options) || up.layer.get(element).element;
10408
10462
  }
10409
10463
  function focusedField() {
@@ -10459,6 +10513,7 @@ up.form = (function () {
10459
10513
  groupSolution: findGroupSolution,
10460
10514
  groupSelectors: getGroupSelectors,
10461
10515
  get: getForm,
10516
+ getScope,
10462
10517
  };
10463
10518
  })();
10464
10519
  up.submit = up.form.submit;