unpoly-rails 3.0.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
  /***/ (() => {
6
6
 
7
7
  window.up = {
8
- version: '3.0.0'
8
+ version: '3.1.1'
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
  }
@@ -389,8 +392,8 @@ up.util = (function () {
389
392
  function queueMicrotask(task) {
390
393
  return Promise.resolve().then(task);
391
394
  }
392
- function last(array) {
393
- return array[array.length - 1];
395
+ function last(value) {
396
+ return value[value.length - 1];
394
397
  }
395
398
  function contains(value, subValue) {
396
399
  return value.indexOf(subValue) >= 0;
@@ -615,14 +618,20 @@ up.util = (function () {
615
618
  });
616
619
  }
617
620
  }
618
- function stringifyArg(arg) {
621
+ function stringifyArg(arg, placeholder = '%o') {
619
622
  let string;
620
623
  const maxLength = 200;
621
- let closer = '';
624
+ if (placeholder === '%c') {
625
+ return '';
626
+ }
627
+ if (placeholder === '%s' && isGiven(arg)) {
628
+ arg = arg.toString();
629
+ }
622
630
  if (isString(arg)) {
623
- string = arg.replace(/[\n\r\t ]+/g, ' ');
624
- string = string.replace(/^[\n\r\t ]+/, '');
625
- string = string.replace(/[\n\r\t ]$/, '');
631
+ string = arg.trim().replace(/[\n\r\t ]+/g, ' ');
632
+ if (placeholder === '%o') {
633
+ string = JSON.stringify(string);
634
+ }
626
635
  }
627
636
  else if (isUndefined(arg)) {
628
637
  string = 'undefined';
@@ -632,24 +641,21 @@ up.util = (function () {
632
641
  }
633
642
  else if (isArray(arg)) {
634
643
  string = `[${map(arg, stringifyArg).join(', ')}]`;
635
- closer = ']';
636
644
  }
637
645
  else if (isJQuery(arg)) {
638
646
  string = `$(${map(arg, stringifyArg).join(', ')})`;
639
- closer = ')';
640
647
  }
641
648
  else if (isElement(arg)) {
642
649
  string = `<${arg.tagName.toLowerCase()}`;
643
- for (let attr of ['id', 'name', 'class']) {
650
+ for (let attr of ['id', 'up-id', 'name', 'class']) {
644
651
  let value = arg.getAttribute(attr);
645
652
  if (value) {
646
653
  string += ` ${attr}="${value}"`;
647
654
  }
648
655
  }
649
656
  string += ">";
650
- closer = '>';
651
657
  }
652
- else if (isRegExp(arg)) {
658
+ else if (isRegExp(arg) || isError(arg)) {
653
659
  string = arg.toString();
654
660
  }
655
661
  else {
@@ -666,14 +672,13 @@ up.util = (function () {
666
672
  }
667
673
  }
668
674
  if (string.length > maxLength) {
669
- string = `${string.substr(0, maxLength)} …`;
670
- string += closer;
675
+ string = `${string.substr(0, maxLength)}…${last(string)}`;
671
676
  }
672
677
  return string;
673
678
  }
674
- const SPRINTF_PLACEHOLDERS = /%[oOdisf]/g;
679
+ const SPRINTF_PLACEHOLDERS = /%[oOdisfc]/g;
675
680
  function sprintf(message, ...args) {
676
- return message.replace(SPRINTF_PLACEHOLDERS, () => stringifyArg(args.shift()));
681
+ return message.replace(SPRINTF_PLACEHOLDERS, (placeholder) => stringifyArg(args.shift(), placeholder));
677
682
  }
678
683
  function negate(fn) {
679
684
  return function (...args) {
@@ -2319,7 +2324,12 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2319
2324
  let cursorProps = up.viewport.copyCursorProps(viewport);
2320
2325
  return () => up.viewport.copyCursorProps(cursorProps, viewport);
2321
2326
  });
2322
- document.body.append(keepable);
2327
+ if (this.willChangeElement(document.body)) {
2328
+ keepPlan.newElement.replaceWith(keepable);
2329
+ }
2330
+ else {
2331
+ document.body.append(keepable);
2332
+ }
2323
2333
  keepPlans.push(keepPlan);
2324
2334
  }
2325
2335
  }
@@ -2434,6 +2444,9 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2434
2444
  const oldFragments = u.map(this.steps, 'oldElement');
2435
2445
  return u.some(oldFragments, up.fragment.hasAutoHistory);
2436
2446
  }
2447
+ willChangeElement(element) {
2448
+ return u.some(this.steps, (step) => step.oldElement.contains(element));
2449
+ }
2437
2450
  },
2438
2451
  (() => {
2439
2452
  u.memoizeMethod(_a.prototype, [
@@ -3517,16 +3530,19 @@ up.FormValidator = class FormValidator {
3517
3530
  this.honorAbort();
3518
3531
  }
3519
3532
  honorAbort() {
3520
- up.fragment.onAborted(this.form, ({ target }) => {
3521
- this.dirtySolutions = u.reject(this.dirtySolutions, ({ element }) => target.contains(element));
3522
- });
3533
+ up.fragment.onAborted(this.form, { around: true }, ({ target }) => this.unscheduleSolutionsWithin(target));
3534
+ }
3535
+ unscheduleSolutionsWithin(container) {
3536
+ this.dirtySolutions = u.reject(this.dirtySolutions, ({ element }) => container.contains(element));
3523
3537
  }
3524
3538
  resetNextRenderPromise() {
3525
3539
  this.nextRenderPromise = u.newDeferred();
3526
3540
  }
3527
3541
  watchContainer(fieldOrForm) {
3528
3542
  let { event } = this.originOptions(fieldOrForm);
3529
- up.on(fieldOrForm, event, () => up.error.muteUncriticalRejection(this.validate({ origin: fieldOrForm })));
3543
+ let guard = () => up.fragment.isAlive(fieldOrForm);
3544
+ let callback = () => up.error.muteUncriticalRejection(this.validate({ origin: fieldOrForm }));
3545
+ up.on(fieldOrForm, event, { guard }, callback);
3530
3546
  }
3531
3547
  validate(options = {}) {
3532
3548
  let solutions = this.getSolutions(options);
@@ -3562,13 +3578,19 @@ up.FormValidator = class FormValidator {
3562
3578
  if (u.isString(target) && target) {
3563
3579
  up.puts('up.validate()', 'Validating target "%s"', target);
3564
3580
  let simpleSelectors = up.fragment.splitTarget(target);
3565
- return simpleSelectors.map(function (simpleSelector) {
3566
- return {
3567
- element: up.fragment.get(simpleSelector, { origin }),
3568
- target: simpleSelector,
3569
- origin
3570
- };
3571
- });
3581
+ return u.compact(simpleSelectors.map(function (simpleSelector) {
3582
+ let element = up.fragment.get(simpleSelector, { origin });
3583
+ if (element) {
3584
+ return {
3585
+ element,
3586
+ target: simpleSelector,
3587
+ origin
3588
+ };
3589
+ }
3590
+ else {
3591
+ up.fail('Validation target "%s" does not match an element', simpleSelector);
3592
+ }
3593
+ }));
3572
3594
  }
3573
3595
  }
3574
3596
  getElementSolutions(element) {
@@ -3602,7 +3624,7 @@ up.FormValidator = class FormValidator {
3602
3624
  up.error.muteUncriticalRejection(this.doRenderDirtySolutions());
3603
3625
  }
3604
3626
  async doRenderDirtySolutions() {
3605
- this.dirtySolutions = u.filter(this.dirtySolutions, ({ element, origin }) => element.isConnected && origin.isConnected);
3627
+ this.dirtySolutions = u.filter(this.dirtySolutions, ({ element, origin }) => up.fragment.isAlive(element) && up.fragment.isAlive(origin));
3606
3628
  if (!this.dirtySolutions.length || this.rendering) {
3607
3629
  return;
3608
3630
  }
@@ -5652,7 +5674,6 @@ up.RenderOptions = (function () {
5652
5674
  saveFocus: true,
5653
5675
  focus: 'keep',
5654
5676
  abort: 'target',
5655
- revalidate: 'auto',
5656
5677
  failOptions: true,
5657
5678
  };
5658
5679
  const PRELOAD_OVERRIDES = {
@@ -7306,6 +7327,7 @@ up.protocol = (function () {
7306
7327
  /***/ (() => {
7307
7328
 
7308
7329
  up.log = (function () {
7330
+ const u = up.util;
7309
7331
  const config = new up.LogConfig();
7310
7332
  function reset() {
7311
7333
  config.reset();
@@ -7323,13 +7345,11 @@ up.log = (function () {
7323
7345
  function printToStreamStyled(stream, trace, customStyles, message, ...args) {
7324
7346
  if (message) {
7325
7347
  if (config.format) {
7326
- args.unshift('color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;' + customStyles, '');
7327
- message = `%c${trace}%c ${message}`;
7348
+ 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);
7328
7349
  }
7329
7350
  else {
7330
- message = `[${trace}] ${message}`;
7351
+ console[stream](`[${trace}] ${u.sprintf(message, ...args)}`);
7331
7352
  }
7332
- console[stream](message, ...args);
7333
7353
  }
7334
7354
  }
7335
7355
  function printUserEvent(event) {
@@ -7713,12 +7733,13 @@ up.fragment = (function () {
7713
7733
  verifyDerivedTarget: true,
7714
7734
  navigateOptions: {
7715
7735
  cache: 'auto',
7736
+ revalidate: 'auto',
7716
7737
  feedback: true,
7717
7738
  fallback: true,
7718
7739
  focus: 'auto',
7719
7740
  scroll: 'auto',
7720
7741
  history: 'auto',
7721
- peel: true
7742
+ peel: true,
7722
7743
  },
7723
7744
  matchAroundOrigin: true,
7724
7745
  runScripts: true,
@@ -7785,10 +7806,12 @@ up.fragment = (function () {
7785
7806
  const parent = options.parent || document;
7786
7807
  return up.emit(parent, 'up:fragment:destroyed', { fragment, parent, log });
7787
7808
  }
7788
- function isDestroying(element) {
7789
- return !!element.closest('.up-destroying');
7809
+ function isNotDestroying(element) {
7810
+ return !element.closest('.up-destroying');
7811
+ }
7812
+ function isAlive(fragment) {
7813
+ return fragment.isConnected && isNotDestroying(fragment);
7790
7814
  }
7791
- const isNotDestroying = u.negate(isDestroying);
7792
7815
  function getSmart(...args) {
7793
7816
  const options = u.extractOptions(args);
7794
7817
  const selector = args.pop();
@@ -8138,8 +8161,10 @@ up.fragment = (function () {
8138
8161
  up.emit(element, 'up:fragment:aborted', { log: false });
8139
8162
  }
8140
8163
  }
8141
- function onAborted(fragment, callback) {
8142
- let guard = (event) => event.target.contains(fragment);
8164
+ function onAborted(fragment, ...args) {
8165
+ let callback = u.extractCallback(args);
8166
+ let options = u.extractOptions(args);
8167
+ let guard = (event) => event.target.contains(fragment) || (options.around && fragment.contains(event.target));
8143
8168
  let unsubscribe = up.on('up:fragment:aborted', { guard }, callback);
8144
8169
  up.destructor(fragment, unsubscribe);
8145
8170
  return unsubscribe;
@@ -8187,6 +8212,7 @@ up.fragment = (function () {
8187
8212
  onAborted,
8188
8213
  splitTarget,
8189
8214
  parseTargetSteps,
8215
+ isAlive,
8190
8216
  };
8191
8217
  })();
8192
8218
  up.reload = up.fragment.reload;
@@ -9345,7 +9371,6 @@ up.link = (function () {
9345
9371
  parser.booleanOrString('transition');
9346
9372
  parser.string('easing');
9347
9373
  parser.number('duration');
9348
- up.migrate.parseFollowOptions?.(parser);
9349
9374
  if (!options.guardEvent) {
9350
9375
  options.guardEvent = up.event.build('up:link:follow', { log: 'Following link' });
9351
9376
  }
@@ -9493,7 +9518,8 @@ up.link = (function () {
9493
9518
  convertClicks,
9494
9519
  config,
9495
9520
  combineFollowableSelectors,
9496
- preloadSelector: fullPreloadSelector
9521
+ preloadSelector: fullPreloadSelector,
9522
+ followSelector: fullFollowSelector,
9497
9523
  };
9498
9524
  })();
9499
9525
  up.follow = up.link.follow;
@@ -9892,6 +9918,7 @@ up.form = (function () {
9892
9918
  disable: disableContainer,
9893
9919
  group: findGroup,
9894
9920
  groupSolution: findGroupSolution,
9921
+ groupSelectors: getGroupSelectors,
9895
9922
  get: getForm,
9896
9923
  };
9897
9924
  })();