unpoly-rails 3.7.0.1 → 3.7.2

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.7.0'
8
+ version: '3.7.2'
9
9
  };
10
10
 
11
11
 
@@ -1989,9 +1989,6 @@ up.RenderJob = (_a = class RenderJob {
1989
1989
  this._rendered = this._executePromise();
1990
1990
  return this;
1991
1991
  }
1992
- getPreflightFragments() {
1993
- return this._getChange().getPreflightProps().fragments;
1994
- }
1995
1992
  async _executePromise() {
1996
1993
  try {
1997
1994
  this._guardRender();
@@ -3668,9 +3665,7 @@ up.FieldWatcher = class FieldWatcher {
3668
3665
  if (target !== this._root)
3669
3666
  this._watchFieldsWithin(target);
3670
3667
  });
3671
- for (let abortableElement of this._abortableElements()) {
3672
- this._unbindFns.push(up.fragment.onAborted(abortableElement, () => this._abort()));
3673
- }
3668
+ this._unbindFns.push(up.fragment.onAborted(this._scope, () => this._abort()));
3674
3669
  this._unbindFns.push(up.on(this._scope, 'reset', () => this._onFormReset()));
3675
3670
  }
3676
3671
  stop() {
@@ -3682,14 +3677,6 @@ up.FieldWatcher = class FieldWatcher {
3682
3677
  let rootOptions = u.copy(this._options);
3683
3678
  return up.form.watchOptions(field, rootOptions, { defaults: { event: 'input' } });
3684
3679
  }
3685
- _abortableElements() {
3686
- if (this._abortable === false) {
3687
- return [];
3688
- }
3689
- else {
3690
- return u.wrapList(this._abortable ?? this._scope);
3691
- }
3692
- }
3693
3680
  _watchFieldsWithin(container) {
3694
3681
  for (let field of up.form.fields(container)) {
3695
3682
  this._watchField(field);
@@ -3703,11 +3690,12 @@ up.FieldWatcher = class FieldWatcher {
3703
3690
  this._scheduledValues = null;
3704
3691
  }
3705
3692
  _scheduleValues(values, fieldOptions) {
3706
- clearTimeout(this._currentTimer);
3707
3693
  this._scheduledValues = values;
3694
+ this._scheduledFieldOptions = fieldOptions;
3708
3695
  let delay = fieldOptions.delay || 0;
3696
+ clearTimeout(this._currentTimer);
3709
3697
  this._currentTimer = u.timer(delay, () => {
3710
- this._scheduledFieldOptions = fieldOptions;
3698
+ this._currentTimer = null;
3711
3699
  this._requestCallback();
3712
3700
  });
3713
3701
  }
@@ -3719,6 +3707,8 @@ up.FieldWatcher = class FieldWatcher {
3719
3707
  return;
3720
3708
  if (this._callbackRunning)
3721
3709
  return;
3710
+ if (this._currentTimer)
3711
+ return;
3722
3712
  if (!this._scope.isConnected)
3723
3713
  return;
3724
3714
  let fieldOptions = this._scheduledFieldOptions;
@@ -3793,10 +3783,14 @@ up.FormValidator = class FormValidator {
3793
3783
  this._honorAbort();
3794
3784
  }
3795
3785
  _honorAbort() {
3796
- up.fragment.onAborted(this._form, { around: true }, ({ target }) => this._unscheduleSolutionsWithin(target));
3786
+ up.fragment.onAborted(this._form, (event) => this._onAborted(event));
3797
3787
  }
3798
- _unscheduleSolutionsWithin(container) {
3799
- this._dirtySolutions = u.reject(this._dirtySolutions, ({ element }) => container.contains(element));
3788
+ _onAborted(event) {
3789
+ if (this._dirtySolutions.length) {
3790
+ this._dirtySolutions = [];
3791
+ this._nextRenderPromise.reject(new up.Aborted(event.reason));
3792
+ this._resetNextRenderPromise();
3793
+ }
3800
3794
  }
3801
3795
  _resetNextRenderPromise() {
3802
3796
  this._nextRenderPromise = u.newDeferred();
@@ -3877,20 +3871,22 @@ up.FormValidator = class FormValidator {
3877
3871
  _scheduleNextRender() {
3878
3872
  let solutionDelays = this._dirtySolutions.map((solution) => solution.renderOptions.delay);
3879
3873
  let shortestDelay = Math.min(...solutionDelays) || 0;
3880
- this._unscheduleNextRender();
3881
- this._nextRenderTimer = u.timer(shortestDelay, () => this._renderDirtySolutions());
3882
- }
3883
- _unscheduleNextRender() {
3884
3874
  clearTimeout(this._nextRenderTimer);
3875
+ this._nextRenderTimer = u.timer(shortestDelay, () => {
3876
+ this._nextRenderTimer = null;
3877
+ this._renderDirtySolutions();
3878
+ });
3885
3879
  }
3886
3880
  _renderDirtySolutions() {
3887
3881
  up.error.muteUncriticalRejection(this._doRenderDirtySolutions());
3888
3882
  }
3889
3883
  async _doRenderDirtySolutions() {
3890
- this._dirtySolutions = u.filter(this._dirtySolutions, ({ element, origin }) => up.fragment.isAlive(element) && up.fragment.isAlive(origin));
3891
- if (!this._dirtySolutions.length || this._rendering) {
3884
+ if (!this._dirtySolutions.length)
3885
+ return;
3886
+ if (this._rendering)
3887
+ return;
3888
+ if (this._nextRenderTimer)
3892
3889
  return;
3893
- }
3894
3890
  let dirtySolutions = this._dirtySolutions;
3895
3891
  this._dirtySolutions = [];
3896
3892
  let dirtyOrigins = u.map(dirtySolutions, 'origin');
@@ -3904,6 +3900,7 @@ up.FormValidator = class FormValidator {
3904
3900
  options.origin = this._form;
3905
3901
  options.focus ??= 'keep';
3906
3902
  options.failOptions = false;
3903
+ options.defaultMaybe = true;
3907
3904
  options.params = up.Params.merge(options.params, ...u.map(dirtyRenderOptionsList, 'params'));
3908
3905
  options.headers = u.merge(...u.map(dirtyRenderOptionsList, 'headers'));
3909
3906
  this._addValidateHeader(options.headers, dirtyNames);
@@ -8541,13 +8538,14 @@ up.fragment = (function () {
8541
8538
  }
8542
8539
  function parseTargetSteps(target, options = {}) {
8543
8540
  let defaultPlacement = options.defaultPlacement || 'swap';
8541
+ let defaultMaybe = options.defaultMaybe ?? false;
8544
8542
  let steps = [];
8545
8543
  let simpleSelectors = splitTarget(target);
8546
8544
  for (let selector of simpleSelectors) {
8547
8545
  if (selector === ':none')
8548
8546
  continue;
8549
8547
  let placement = defaultPlacement;
8550
- let maybe = false;
8548
+ let maybe = defaultMaybe;
8551
8549
  selector = selector.replace(/\b::?(before|after)\b/, (_match, customPlacement) => {
8552
8550
  placement = customPlacement;
8553
8551
  return '';
@@ -8591,8 +8589,8 @@ up.fragment = (function () {
8591
8589
  return request.fromCache && u.evalAutoOption(options.revalidate, config.autoRevalidate, response);
8592
8590
  }
8593
8591
  function targetForSteps(steps) {
8594
- let requiredSteps = u.reject(steps, 'maybe');
8595
- let selectors = u.map(requiredSteps, 'selector');
8592
+ let bestSteps = steps.filter((step) => !step.maybe || step.oldElement?.isConnected);
8593
+ let selectors = u.map(bestSteps, 'selector');
8596
8594
  return selectors.join(', ') || ':none';
8597
8595
  }
8598
8596
  function isContainedByRivalStep(steps, candidateStep) {
@@ -8628,13 +8626,11 @@ up.fragment = (function () {
8628
8626
  let testFnWithAbortable = (request) => request.abortable && testFn(request);
8629
8627
  up.network.abort(testFnWithAbortable, { ...options, reason });
8630
8628
  for (let element of elements) {
8631
- up.emit(element, 'up:fragment:aborted', { newLayer, log: false });
8629
+ up.emit(element, 'up:fragment:aborted', { reason, newLayer, log: false });
8632
8630
  }
8633
8631
  }
8634
- function onAborted(fragment, ...args) {
8635
- let callback = u.extractCallback(args);
8636
- let options = u.extractOptions(args);
8637
- let guard = (event) => event.target.contains(fragment) || (options.around && fragment.contains(event.target));
8632
+ function onAborted(fragment, callback) {
8633
+ let guard = (event) => event.target.contains(fragment);
8638
8634
  let unsubscribe = up.on('up:fragment:aborted', { guard }, callback);
8639
8635
  up.destructor(fragment, unsubscribe);
8640
8636
  return unsubscribe;
@@ -10043,11 +10039,8 @@ up.form = (function () {
10043
10039
  return config.selector('submitButtonSelectors');
10044
10040
  }
10045
10041
  const submit = up.mockable((form, options) => {
10046
- return buildSubmitJob(form, options).execute();
10042
+ return up.render(submitOptions(form, options));
10047
10043
  });
10048
- function buildSubmitJob(form, options) {
10049
- return new up.RenderJob(submitOptions(form, options));
10050
- }
10051
10044
  function submitOptions(form, options, parserOptions) {
10052
10045
  form = getForm(form);
10053
10046
  options = u.options(options);
@@ -10064,9 +10057,6 @@ up.form = (function () {
10064
10057
  parser.include(up.link.followOptions);
10065
10058
  return options;
10066
10059
  }
10067
- function getPreflightFragments(form) {
10068
- return buildSubmitJob(form).getPreflightFragments();
10069
- }
10070
10060
  function watchOptions(field, options, parserOptions = {}) {
10071
10061
  options = u.options(options);
10072
10062
  let parser = new up.OptionsParser(field, options, { ...parserOptions, closest: true, attrPrefix: 'up-watch-' });
@@ -10190,10 +10180,8 @@ up.form = (function () {
10190
10180
  }
10191
10181
  }
10192
10182
  function autosubmit(target, options = {}) {
10193
- const form = getForm(target);
10194
- options.abortable ??= [form, ...getPreflightFragments(form)];
10195
- const onChange = (_value, _name, renderOptions) => submit(target, renderOptions);
10196
- return watch(target, options, onChange);
10183
+ const onChange = (_diff, renderOptions) => submit(target, renderOptions);
10184
+ return watch(target, { options, batch: true }, onChange);
10197
10185
  }
10198
10186
  function getGroupSelectors() {
10199
10187
  return up.migrate.migratedFormGroupSelectors?.() || config.groupSelectors;