unpoly-rails 3.0.0 → 3.1.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.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
  }
@@ -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) {
@@ -2352,7 +2357,12 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2352
2357
  let cursorProps = up.viewport.copyCursorProps(viewport);
2353
2358
  return () => up.viewport.copyCursorProps(cursorProps, viewport);
2354
2359
  });
2355
- document.body.append(keepable);
2360
+ if (this.willChangeElement(document.body)) {
2361
+ keepPlan.newElement.replaceWith(keepable);
2362
+ }
2363
+ else {
2364
+ document.body.append(keepable);
2365
+ }
2356
2366
  keepPlans.push(keepPlan);
2357
2367
  }
2358
2368
  }
@@ -2456,6 +2466,9 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2456
2466
  const oldFragments = u.map(this.steps, 'oldElement');
2457
2467
  return u.some(oldFragments, up.fragment.hasAutoHistory);
2458
2468
  }
2469
+ willChangeElement(element) {
2470
+ return u.some(this.steps, (step) => step.oldElement.contains(element));
2471
+ }
2459
2472
  },
2460
2473
  (() => {
2461
2474
  u.memoizeMethod(_a.prototype, [
@@ -3574,16 +3587,19 @@ up.FormValidator = class FormValidator {
3574
3587
  this.honorAbort();
3575
3588
  }
3576
3589
  honorAbort() {
3577
- up.fragment.onAborted(this.form, ({ target }) => {
3578
- this.dirtySolutions = u.reject(this.dirtySolutions, ({ element }) => target.contains(element));
3579
- });
3590
+ up.fragment.onAborted(this.form, { around: true }, ({ target }) => this.unscheduleSolutionsWithin(target));
3591
+ }
3592
+ unscheduleSolutionsWithin(container) {
3593
+ this.dirtySolutions = u.reject(this.dirtySolutions, ({ element }) => container.contains(element));
3580
3594
  }
3581
3595
  resetNextRenderPromise() {
3582
3596
  this.nextRenderPromise = u.newDeferred();
3583
3597
  }
3584
3598
  watchContainer(fieldOrForm) {
3585
3599
  let { event } = this.originOptions(fieldOrForm);
3586
- up.on(fieldOrForm, event, () => up.error.muteUncriticalRejection(this.validate({ origin: fieldOrForm })));
3600
+ let guard = () => up.fragment.isAlive(fieldOrForm);
3601
+ let callback = () => up.error.muteUncriticalRejection(this.validate({ origin: fieldOrForm }));
3602
+ up.on(fieldOrForm, event, { guard }, callback);
3587
3603
  }
3588
3604
  validate(options = {}) {
3589
3605
  let solutions = this.getSolutions(options);
@@ -3620,13 +3636,19 @@ up.FormValidator = class FormValidator {
3620
3636
  if (u.isString(target) && target) {
3621
3637
  up.puts('up.validate()', 'Validating target "%s"', target);
3622
3638
  let simpleSelectors = up.fragment.splitTarget(target);
3623
- return simpleSelectors.map(function (simpleSelector) {
3624
- return {
3625
- element: up.fragment.get(simpleSelector, { origin }),
3626
- target: simpleSelector,
3627
- origin
3628
- };
3629
- });
3639
+ return u.compact(simpleSelectors.map(function (simpleSelector) {
3640
+ let element = up.fragment.get(simpleSelector, { origin });
3641
+ if (element) {
3642
+ return {
3643
+ element,
3644
+ target: simpleSelector,
3645
+ origin
3646
+ };
3647
+ }
3648
+ else {
3649
+ up.fail('Validation target "%s" does not match an element', simpleSelector);
3650
+ }
3651
+ }));
3630
3652
  }
3631
3653
  }
3632
3654
  getElementSolutions(element) {
@@ -3662,7 +3684,7 @@ up.FormValidator = class FormValidator {
3662
3684
  doRenderDirtySolutions() {
3663
3685
  var _a;
3664
3686
  return __awaiter(this, void 0, void 0, function* () {
3665
- this.dirtySolutions = u.filter(this.dirtySolutions, ({ element, origin }) => element.isConnected && origin.isConnected);
3687
+ this.dirtySolutions = u.filter(this.dirtySolutions, ({ element, origin }) => up.fragment.isAlive(element) && up.fragment.isAlive(origin));
3666
3688
  if (!this.dirtySolutions.length || this.rendering) {
3667
3689
  return;
3668
3690
  }
@@ -5736,7 +5758,6 @@ up.RenderOptions = (function () {
5736
5758
  saveFocus: true,
5737
5759
  focus: 'keep',
5738
5760
  abort: 'target',
5739
- revalidate: 'auto',
5740
5761
  failOptions: true,
5741
5762
  };
5742
5763
  const PRELOAD_OVERRIDES = {
@@ -7412,6 +7433,7 @@ up.protocol = (function () {
7412
7433
  /***/ (() => {
7413
7434
 
7414
7435
  up.log = (function () {
7436
+ const u = up.util;
7415
7437
  const config = new up.LogConfig();
7416
7438
  function reset() {
7417
7439
  config.reset();
@@ -7429,13 +7451,11 @@ up.log = (function () {
7429
7451
  function printToStreamStyled(stream, trace, customStyles, message, ...args) {
7430
7452
  if (message) {
7431
7453
  if (config.format) {
7432
- args.unshift('color: #666666; padding: 1px 3px; border: 1px solid #bbbbbb; border-radius: 2px; font-size: 90%; display: inline-block;' + customStyles, '');
7433
- message = `%c${trace}%c ${message}`;
7454
+ 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);
7434
7455
  }
7435
7456
  else {
7436
- message = `[${trace}] ${message}`;
7457
+ console[stream](`[${trace}] ${u.sprintf(message, ...args)}`);
7437
7458
  }
7438
- console[stream](message, ...args);
7439
7459
  }
7440
7460
  }
7441
7461
  function printUserEvent(event) {
@@ -7816,12 +7836,13 @@ up.fragment = (function () {
7816
7836
  verifyDerivedTarget: true,
7817
7837
  navigateOptions: {
7818
7838
  cache: 'auto',
7839
+ revalidate: 'auto',
7819
7840
  feedback: true,
7820
7841
  fallback: true,
7821
7842
  focus: 'auto',
7822
7843
  scroll: 'auto',
7823
7844
  history: 'auto',
7824
- peel: true
7845
+ peel: true,
7825
7846
  },
7826
7847
  matchAroundOrigin: true,
7827
7848
  runScripts: true,
@@ -7889,10 +7910,12 @@ up.fragment = (function () {
7889
7910
  const parent = options.parent || document;
7890
7911
  return up.emit(parent, 'up:fragment:destroyed', { fragment, parent, log });
7891
7912
  }
7892
- function isDestroying(element) {
7893
- return !!element.closest('.up-destroying');
7913
+ function isNotDestroying(element) {
7914
+ return !element.closest('.up-destroying');
7915
+ }
7916
+ function isAlive(fragment) {
7917
+ return fragment.isConnected && isNotDestroying(fragment);
7894
7918
  }
7895
- const isNotDestroying = u.negate(isDestroying);
7896
7919
  function getSmart(...args) {
7897
7920
  const options = u.extractOptions(args);
7898
7921
  const selector = args.pop();
@@ -8242,8 +8265,10 @@ up.fragment = (function () {
8242
8265
  up.emit(element, 'up:fragment:aborted', { log: false });
8243
8266
  }
8244
8267
  }
8245
- function onAborted(fragment, callback) {
8246
- let guard = (event) => event.target.contains(fragment);
8268
+ function onAborted(fragment, ...args) {
8269
+ let callback = u.extractCallback(args);
8270
+ let options = u.extractOptions(args);
8271
+ let guard = (event) => event.target.contains(fragment) || (options.around && fragment.contains(event.target));
8247
8272
  let unsubscribe = up.on('up:fragment:aborted', { guard }, callback);
8248
8273
  up.destructor(fragment, unsubscribe);
8249
8274
  return unsubscribe;
@@ -8291,6 +8316,7 @@ up.fragment = (function () {
8291
8316
  onAborted,
8292
8317
  splitTarget,
8293
8318
  parseTargetSteps,
8319
+ isAlive,
8294
8320
  };
8295
8321
  })();
8296
8322
  up.reload = up.fragment.reload;
@@ -9408,7 +9434,6 @@ up.link = (function () {
9408
9434
  return options;
9409
9435
  }
9410
9436
  function followOptions(link, options, parserOptions) {
9411
- var _a, _b;
9412
9437
  link = up.fragment.get(link);
9413
9438
  options = parseRequestOptions(link, options, parserOptions);
9414
9439
  const parser = new up.OptionsParser(link, options, Object.assign({ fail: true }, parserOptions));
@@ -9463,7 +9488,6 @@ up.link = (function () {
9463
9488
  parser.booleanOrString('transition');
9464
9489
  parser.string('easing');
9465
9490
  parser.number('duration');
9466
- (_b = (_a = up.migrate).parseFollowOptions) === null || _b === void 0 ? void 0 : _b.call(_a, parser);
9467
9491
  if (!options.guardEvent) {
9468
9492
  options.guardEvent = up.event.build('up:link:follow', { log: 'Following link' });
9469
9493
  }
@@ -9606,7 +9630,8 @@ up.link = (function () {
9606
9630
  convertClicks,
9607
9631
  config,
9608
9632
  combineFollowableSelectors,
9609
- preloadSelector: fullPreloadSelector
9633
+ preloadSelector: fullPreloadSelector,
9634
+ followSelector: fullFollowSelector,
9610
9635
  };
9611
9636
  })();
9612
9637
  up.follow = up.link.follow;
@@ -10004,6 +10029,7 @@ up.form = (function () {
10004
10029
  disable: disableContainer,
10005
10030
  group: findGroup,
10006
10031
  groupSolution: findGroupSolution,
10032
+ groupSelectors: getGroupSelectors,
10007
10033
  get: getForm,
10008
10034
  };
10009
10035
  })();