unpoly-rails 3.0.0.rc1 → 3.0.0.rc2

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-rc1'
8
+ version: '3.0.0-rc2'
9
9
  };
10
10
 
11
11
 
@@ -14,13 +14,18 @@ window.up = {
14
14
  /***/ (() => {
15
15
 
16
16
  up.mockable = function (originalFn) {
17
- let spy;
18
- const mockableFn = function () {
19
- return (spy || originalFn).apply(null, arguments);
20
- };
21
- mockableFn.mock = () => spy = jasmine.createSpy('mockable', originalFn);
22
- document.addEventListener('up:framework:reset', () => spy = null);
23
- return mockableFn;
17
+ if (window.jasmine) {
18
+ let name = originalFn.name;
19
+ let obj = { [name]: originalFn };
20
+ let mockableFn = function () {
21
+ return obj[name].apply(this, arguments);
22
+ };
23
+ mockableFn.mock = () => spyOn(obj, name);
24
+ return mockableFn;
25
+ }
26
+ else {
27
+ return originalFn;
28
+ }
24
29
  };
25
30
 
26
31
 
@@ -871,12 +876,6 @@ up.browser = (function () {
871
876
  return value;
872
877
  }
873
878
  }
874
- const getJQuery = function () {
875
- if (!canJQuery()) {
876
- up.fail('jQuery must be published as window.jQuery');
877
- }
878
- return jQuery;
879
- };
880
879
  function assertConfirmed(options) {
881
880
  const confirmed = !options.confirm || window.confirm(options.confirm);
882
881
  if (!confirmed) {
@@ -891,7 +890,6 @@ up.browser = (function () {
891
890
  canEval,
892
891
  assertConfirmed,
893
892
  popCookie,
894
- get jQuery() { return getJQuery(); },
895
893
  };
896
894
  })();
897
895
 
@@ -1876,7 +1874,7 @@ up.Change.Addition = class Addition extends up.Change {
1876
1874
  setETag({ newElement, etag }) {
1877
1875
  e.setMissingAttr(newElement, 'up-etag', etag || false);
1878
1876
  }
1879
- setMeta(options) {
1877
+ setReloadAttrs(options) {
1880
1878
  this.setSource(options);
1881
1879
  this.setTime(options);
1882
1880
  this.setETag(options);
@@ -2119,9 +2117,9 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
2119
2117
  this.layer.createElements(this.content);
2120
2118
  this.layer.setupHandlers();
2121
2119
  this.handleHistory();
2122
- this.setMeta({ newElement: this.content, source: this.options.source });
2120
+ this.setReloadAttrs({ newElement: this.content, source: this.options.source });
2123
2121
  responseDoc.finalizeElement(this.content);
2124
- up.hello(this.layer.element, { layer: this.layer, origin: this.origin });
2122
+ up.hello(this.layer.element, Object.assign(Object.assign({}, this.options), { layer: this.layer }));
2125
2123
  this.handleLayerChangeRequests();
2126
2124
  this.handleScroll();
2127
2125
  let renderResult = new up.RenderResult({
@@ -2290,7 +2288,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
2290
2288
  this.renderResult.fragments.unshift(...newFragments);
2291
2289
  }
2292
2290
  executeStep(step) {
2293
- this.setMeta(step);
2291
+ this.setReloadAttrs(step);
2294
2292
  switch (step.placement) {
2295
2293
  case 'swap': {
2296
2294
  let keepPlan = this.findKeepPlan(step);
@@ -2781,18 +2779,11 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2781
2779
  onRequestSettledWithResponse(response) {
2782
2780
  var _a;
2783
2781
  this.response = response;
2784
- const expiredResponse = this.options.expiredResponse;
2785
- const eventProps = {
2786
- response: this.response,
2787
- renderOptions: this.options,
2788
- revalidating: !!expiredResponse,
2789
- expiredResponse,
2790
- };
2791
- if (up.fragment.config.skipResponse(eventProps)) {
2782
+ if (up.fragment.config.skipResponse(this.loadedEventProps())) {
2792
2783
  this.skip();
2793
2784
  }
2794
2785
  else {
2795
- this.request.assertEmitted('up:fragment:loaded', Object.assign(Object.assign({}, eventProps), { callback: this.options.onLoaded, log: ['Loaded fragment from %s', this.response.description], skip: () => this.skip() }));
2786
+ 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() }));
2796
2787
  }
2797
2788
  let fail = (_a = u.evalOption(this.options.fail, this.response)) !== null && _a !== void 0 ? _a : !response.ok;
2798
2789
  if (fail) {
@@ -2800,6 +2791,22 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2800
2791
  }
2801
2792
  return this.updateContentFromResponse(this.options);
2802
2793
  }
2794
+ compilerPassMeta() {
2795
+ return u.pick(this.loadedEventProps(), [
2796
+ 'revalidating',
2797
+ 'response'
2798
+ ]);
2799
+ }
2800
+ loadedEventProps() {
2801
+ const { expiredResponse } = this.options;
2802
+ return {
2803
+ request: this.request,
2804
+ response: this.response,
2805
+ renderOptions: this.options,
2806
+ revalidating: !!expiredResponse,
2807
+ expiredResponse,
2808
+ };
2809
+ }
2803
2810
  onRequestSettledWithError(error) {
2804
2811
  if (error instanceof up.Offline) {
2805
2812
  this.request.emit('up:fragment:offline', {
@@ -2822,6 +2829,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2822
2829
  up.puts('up.render()', 'Rendering failed response using fail-prefixed options (https://unpoly.com/failed-responses)');
2823
2830
  }
2824
2831
  this.augmentOptionsFromResponse(finalRenderOptions);
2832
+ finalRenderOptions.meta = this.compilerPassMeta();
2825
2833
  let result = new up.Change.FromContent(finalRenderOptions).execute();
2826
2834
  result.finished = this.finish(result, finalRenderOptions);
2827
2835
  return result;
@@ -2890,6 +2898,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2890
2898
  (() => {
2891
2899
  u.memoizeMethod(_a.prototype, [
2892
2900
  'getRequestAttrs',
2901
+ 'loadedEventProps',
2893
2902
  ]);
2894
2903
  })(),
2895
2904
  _a);
@@ -2901,12 +2910,14 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
2901
2910
 
2902
2911
  const u = up.util;
2903
2912
  up.CompilerPass = class CompilerPass {
2904
- constructor(root, compilers, { layer, data, dataMap } = {}) {
2913
+ constructor(root, compilers, { layer, data, dataMap, meta }) {
2914
+ layer || (layer = up.layer.get(root) || up.layer.current);
2905
2915
  this.root = root;
2906
2916
  this.compilers = compilers;
2907
- this.layer = layer || up.layer.get(this.root) || up.layer.current;
2917
+ this.layer = layer;
2908
2918
  this.data = data;
2909
2919
  this.dataMap = dataMap;
2920
+ this.meta = Object.assign({ layer }, meta);
2910
2921
  this.errors = [];
2911
2922
  }
2912
2923
  run() {
@@ -2952,11 +2963,10 @@ up.CompilerPass = class CompilerPass {
2952
2963
  return (_b = (_a = up.migrate).postCompile) === null || _b === void 0 ? void 0 : _b.call(_a, matches, compiler);
2953
2964
  }
2954
2965
  compileOneElement(compiler, element) {
2955
- const elementArg = compiler.jQuery ? up.browser.jQuery(element) : element;
2956
- const compileArgs = [elementArg];
2966
+ const compileArgs = [element];
2957
2967
  if (compiler.length !== 1) {
2958
2968
  const data = up.syntax.data(element);
2959
- compileArgs.push(data);
2969
+ compileArgs.push(data, this.meta);
2960
2970
  }
2961
2971
  const result = this.applyCompilerFunction(compiler, element, compileArgs);
2962
2972
  let destructorOrDestructors = this.destructorPresence(result);
@@ -2965,11 +2975,10 @@ up.CompilerPass = class CompilerPass {
2965
2975
  }
2966
2976
  }
2967
2977
  compileBatch(compiler, elements) {
2968
- const elementsArgs = compiler.jQuery ? up.browser.jQuery(elements) : elements;
2969
- const compileArgs = [elementsArgs];
2978
+ const compileArgs = [elements];
2970
2979
  if (compiler.length !== 1) {
2971
2980
  const dataList = u.map(elements, up.syntax.data);
2972
- compileArgs.push(dataList);
2981
+ compileArgs.push(dataList, this.meta);
2973
2982
  }
2974
2983
  const result = this.applyCompilerFunction(compiler, elements, compileArgs);
2975
2984
  if (this.destructorPresence(result)) {
@@ -3275,7 +3284,6 @@ up.EventListener = class EventListener extends up.Record {
3275
3284
  'eventType',
3276
3285
  'selector',
3277
3286
  'callback',
3278
- 'jQuery',
3279
3287
  'guard',
3280
3288
  'baseLayer',
3281
3289
  'passive',
@@ -3323,8 +3331,7 @@ up.EventListener = class EventListener extends up.Record {
3323
3331
  return;
3324
3332
  }
3325
3333
  if (element) {
3326
- const elementArg = this.jQuery ? up.browser.jQuery(element) : element;
3327
- const args = [event, elementArg];
3334
+ const args = [event, element];
3328
3335
  const expectedArgCount = this.callback.length;
3329
3336
  if (expectedArgCount !== 1 && expectedArgCount !== 2) {
3330
3337
  const data = up.syntax.data(element);
@@ -3380,7 +3387,6 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
3380
3387
  'eventTypes',
3381
3388
  'selector',
3382
3389
  'callback',
3383
- 'jQuery',
3384
3390
  'guard',
3385
3391
  'baseLayer',
3386
3392
  'passive',
@@ -4339,12 +4345,12 @@ up.Layer = class Layer extends up.Record {
4339
4345
  return this.stack.asCurrent(this, fn);
4340
4346
  }
4341
4347
  updateHistory(options) {
4342
- if (u.isString(options.title)) {
4343
- this.title = options.title;
4344
- }
4345
4348
  if (u.isString(options.location)) {
4346
4349
  this.location = options.location;
4347
4350
  }
4351
+ if (u.isString(options.title)) {
4352
+ this.title = options.title;
4353
+ }
4348
4354
  }
4349
4355
  isHistoryVisible() {
4350
4356
  return this.history && (this.isRoot() || this.parent.isHistoryVisible());
@@ -4377,12 +4383,14 @@ up.Layer = class Layer extends up.Record {
4377
4383
  set location(location) {
4378
4384
  const previousLocation = this.location;
4379
4385
  location = up.history.normalizeURL(location);
4380
- if (previousLocation !== location) {
4386
+ if (previousLocation !== location || this.opening) {
4381
4387
  this.savedLocation = location;
4382
- this.emit('up:layer:location:changed', { location, log: false });
4383
4388
  if (this.showsLiveHistory()) {
4384
4389
  up.history.push(location);
4385
4390
  }
4391
+ if (!this.opening) {
4392
+ this.emit('up:layer:location:changed', { location });
4393
+ }
4386
4394
  }
4387
4395
  }
4388
4396
  selector(part) {
@@ -5834,7 +5842,7 @@ up.RenderOptions = (function () {
5834
5842
  'history',
5835
5843
  'source',
5836
5844
  'saveScroll',
5837
- 'navigate'
5845
+ 'navigate',
5838
5846
  ]);
5839
5847
  const CONTENT_KEYS = [
5840
5848
  'url',
@@ -6567,24 +6575,24 @@ up.Response = class Response extends up.Record {
6567
6575
  var _a;
6568
6576
  return !u.evalOption((_a = this.fail) !== null && _a !== void 0 ? _a : up.network.config.fail, this);
6569
6577
  }
6570
- getHeader(name) {
6578
+ header(name) {
6571
6579
  var _a;
6572
6580
  return this.headers[name] || ((_a = this.xhr) === null || _a === void 0 ? void 0 : _a.getResponseHeader(name));
6573
6581
  }
6574
6582
  get contentType() {
6575
- return this.getHeader('Content-Type');
6583
+ return this.header('Content-Type');
6576
6584
  }
6577
6585
  get cspNonces() {
6578
- return up.protocol.cspNoncesFromHeader(this.getHeader('Content-Security-Policy'));
6586
+ return up.protocol.cspNoncesFromHeader(this.header('Content-Security-Policy'));
6579
6587
  }
6580
6588
  get lastModified() {
6581
- let header = this.getHeader('Last-Modified');
6589
+ let header = this.header('Last-Modified');
6582
6590
  if (header) {
6583
6591
  return new Date(header);
6584
6592
  }
6585
6593
  }
6586
6594
  get etag() {
6587
- return this.getHeader('ETag');
6595
+ return this.header('ETag');
6588
6596
  }
6589
6597
  get json() {
6590
6598
  return this.parsedJSON || (this.parsedJSON = JSON.parse(this.text));
@@ -6594,7 +6602,8 @@ up.Response = class Response extends up.Record {
6594
6602
  return now - this.loadedAt;
6595
6603
  }
6596
6604
  get expired() {
6597
- return this.age > up.network.config.cacheExpireAge || this.request.expired;
6605
+ return this.age > up.network.config.cacheExpireAge ||
6606
+ this.request.expired;
6598
6607
  }
6599
6608
  get description() {
6600
6609
  return `HTTP ${this.status} response to ${this.request.description}`;
@@ -7046,6 +7055,7 @@ up.framework = (function () {
7046
7055
  readyState = 'booting';
7047
7056
  up.emit('up:framework:boot', { log: false });
7048
7057
  readyState = 'booted';
7058
+ up.emit('up:framework:booted', { log: false });
7049
7059
  }
7050
7060
  else {
7051
7061
  console.error("Unpoly cannot boot: %s", issue);
@@ -7127,9 +7137,6 @@ up.event = (function () {
7127
7137
  function on(...args) {
7128
7138
  return buildListenerGroup(args).bind();
7129
7139
  }
7130
- function $on(...args) {
7131
- return buildListenerGroup(args, { jQuery: true }).bind();
7132
- }
7133
7140
  function off(...args) {
7134
7141
  return buildListenerGroup(args).unbind();
7135
7142
  }
@@ -7200,7 +7207,6 @@ up.event = (function () {
7200
7207
  on('up:framework:reset', reset);
7201
7208
  return {
7202
7209
  on,
7203
- $on,
7204
7210
  off,
7205
7211
  build,
7206
7212
  emit,
@@ -7213,9 +7219,7 @@ up.event = (function () {
7213
7219
  };
7214
7220
  })();
7215
7221
  up.on = up.event.on;
7216
- up.$on = up.event.$on;
7217
7222
  up.off = up.event.off;
7218
- up.$off = up.event.off;
7219
7223
  up.emit = up.event.emit;
7220
7224
 
7221
7225
 
@@ -7467,9 +7471,6 @@ up.syntax = (function () {
7467
7471
  const compiler = buildCompiler(args);
7468
7472
  return insertCompiler(registeredCompilers, compiler);
7469
7473
  }
7470
- function registerJQueryCompiler(...args) {
7471
- registerCompiler(...args, { jQuery: true });
7472
- }
7473
7474
  function registerMacro(...args) {
7474
7475
  const macro = buildCompiler(args);
7475
7476
  if (up.framework.evaling) {
@@ -7478,9 +7479,6 @@ up.syntax = (function () {
7478
7479
  }
7479
7480
  return insertCompiler(registeredMacros, macro);
7480
7481
  }
7481
- function registerJQueryMacro(...args) {
7482
- registerMacro(...args, { jQuery: true });
7483
- }
7484
7482
  function detectSystemMacroPriority(macroSelector) {
7485
7483
  macroSelector = u.evalOption(macroSelector);
7486
7484
  for (let substr in SYSTEM_MACRO_PRIORITIES) {
@@ -7504,7 +7502,6 @@ up.syntax = (function () {
7504
7502
  isDefault: up.framework.evaling,
7505
7503
  priority: 0,
7506
7504
  batch: false,
7507
- jQuery: false
7508
7505
  });
7509
7506
  return Object.assign(callback, options);
7510
7507
  }
@@ -7546,10 +7543,10 @@ up.syntax = (function () {
7546
7543
  destructors.push(destructor);
7547
7544
  }
7548
7545
  }
7549
- function hello(element, { layer, data, dataMap } = {}) {
7550
- element = up.fragment.get(element);
7546
+ function hello(element, options = {}) {
7547
+ element = up.fragment.get(element, options);
7551
7548
  up.puts('up.hello()', "Compiling fragment %o", element);
7552
- compile(element, { layer, data, dataMap });
7549
+ compile(element, options);
7553
7550
  up.fragment.emitInserted(element);
7554
7551
  return element;
7555
7552
  }
@@ -7582,8 +7579,6 @@ up.syntax = (function () {
7582
7579
  return {
7583
7580
  compiler: registerCompiler,
7584
7581
  macro: registerMacro,
7585
- $compiler: registerJQueryCompiler,
7586
- $macro: registerJQueryMacro,
7587
7582
  destructor: registerDestructor,
7588
7583
  hello,
7589
7584
  clean,
@@ -7591,10 +7586,8 @@ up.syntax = (function () {
7591
7586
  };
7592
7587
  })();
7593
7588
  up.compiler = up.syntax.compiler;
7594
- up.$compiler = up.syntax.$compiler;
7595
7589
  up.destructor = up.syntax.destructor;
7596
7590
  up.macro = up.syntax.macro;
7597
- up.$macro = up.syntax.$macro;
7598
7591
  up.data = up.syntax.data;
7599
7592
  up.hello = up.syntax.hello;
7600
7593
 
@@ -9160,6 +9153,7 @@ up.layer = (function () {
9160
9153
  options.baseLayer = stack.get('current', Object.assign(Object.assign({}, options), { normalizeLayerOptions: false }));
9161
9154
  }
9162
9155
  function build(options, beforeNew) {
9156
+ var _a;
9163
9157
  const { mode } = options;
9164
9158
  const { Class } = config[mode];
9165
9159
  const configs = u.reverse(modeConfigs(mode));
@@ -9167,6 +9161,7 @@ up.layer = (function () {
9167
9161
  if (handleDeprecatedConfig) {
9168
9162
  configs.forEach(handleDeprecatedConfig);
9169
9163
  }
9164
+ (_a = options.openAnimation) !== null && _a !== void 0 ? _a : (options.openAnimation = u.pluckKey(options, 'animation'));
9170
9165
  options = u.mergeDefined(...configs, { mode, stack }, options);
9171
9166
  if (beforeNew) {
9172
9167
  options = beforeNew(options);