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.
- checksums.yaml +4 -4
- data/assets/unpoly/unpoly-migrate.js +44 -10
- data/assets/unpoly/unpoly-migrate.min.js +1 -1
- data/assets/unpoly/unpoly.es6.js +67 -72
- data/assets/unpoly/unpoly.es6.min.js +1 -1
- data/assets/unpoly/unpoly.js +66 -72
- data/assets/unpoly/unpoly.min.js +1 -1
- data/lib/unpoly/rails/version.rb +1 -1
- metadata +2 -2
data/assets/unpoly/unpoly.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
/***/ (() => {
|
6
6
|
|
7
7
|
window.up = {
|
8
|
-
version: '3.0.0-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
|
@@ -869,12 +874,6 @@ up.browser = (function () {
|
|
869
874
|
return value;
|
870
875
|
}
|
871
876
|
}
|
872
|
-
const getJQuery = function () {
|
873
|
-
if (!canJQuery()) {
|
874
|
-
up.fail('jQuery must be published as window.jQuery');
|
875
|
-
}
|
876
|
-
return jQuery;
|
877
|
-
};
|
878
877
|
function assertConfirmed(options) {
|
879
878
|
const confirmed = !options.confirm || window.confirm(options.confirm);
|
880
879
|
if (!confirmed) {
|
@@ -889,7 +888,6 @@ up.browser = (function () {
|
|
889
888
|
canEval,
|
890
889
|
assertConfirmed,
|
891
890
|
popCookie,
|
892
|
-
get jQuery() { return getJQuery(); },
|
893
891
|
};
|
894
892
|
})();
|
895
893
|
|
@@ -1874,7 +1872,7 @@ up.Change.Addition = class Addition extends up.Change {
|
|
1874
1872
|
setETag({ newElement, etag }) {
|
1875
1873
|
e.setMissingAttr(newElement, 'up-etag', etag || false);
|
1876
1874
|
}
|
1877
|
-
|
1875
|
+
setReloadAttrs(options) {
|
1878
1876
|
this.setSource(options);
|
1879
1877
|
this.setTime(options);
|
1880
1878
|
this.setETag(options);
|
@@ -2082,9 +2080,9 @@ up.Change.OpenLayer = class OpenLayer extends up.Change.Addition {
|
|
2082
2080
|
this.layer.createElements(this.content);
|
2083
2081
|
this.layer.setupHandlers();
|
2084
2082
|
this.handleHistory();
|
2085
|
-
this.
|
2083
|
+
this.setReloadAttrs({ newElement: this.content, source: this.options.source });
|
2086
2084
|
responseDoc.finalizeElement(this.content);
|
2087
|
-
up.hello(this.layer.element, {
|
2085
|
+
up.hello(this.layer.element, { ...this.options, layer: this.layer });
|
2088
2086
|
this.handleLayerChangeRequests();
|
2089
2087
|
this.handleScroll();
|
2090
2088
|
let renderResult = new up.RenderResult({
|
@@ -2244,7 +2242,7 @@ up.Change.UpdateLayer = (_a = class UpdateLayer extends up.Change.Addition {
|
|
2244
2242
|
this.renderResult.fragments.unshift(...newFragments);
|
2245
2243
|
}
|
2246
2244
|
executeStep(step) {
|
2247
|
-
this.
|
2245
|
+
this.setReloadAttrs(step);
|
2248
2246
|
switch (step.placement) {
|
2249
2247
|
case 'swap': {
|
2250
2248
|
let keepPlan = this.findKeepPlan(step);
|
@@ -2749,19 +2747,12 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
|
|
2749
2747
|
}
|
2750
2748
|
onRequestSettledWithResponse(response) {
|
2751
2749
|
this.response = response;
|
2752
|
-
|
2753
|
-
const eventProps = {
|
2754
|
-
response: this.response,
|
2755
|
-
renderOptions: this.options,
|
2756
|
-
revalidating: !!expiredResponse,
|
2757
|
-
expiredResponse,
|
2758
|
-
};
|
2759
|
-
if (up.fragment.config.skipResponse(eventProps)) {
|
2750
|
+
if (up.fragment.config.skipResponse(this.loadedEventProps())) {
|
2760
2751
|
this.skip();
|
2761
2752
|
}
|
2762
2753
|
else {
|
2763
2754
|
this.request.assertEmitted('up:fragment:loaded', {
|
2764
|
-
...
|
2755
|
+
...this.loadedEventProps(),
|
2765
2756
|
callback: this.options.onLoaded,
|
2766
2757
|
log: ['Loaded fragment from %s', this.response.description],
|
2767
2758
|
skip: () => this.skip()
|
@@ -2773,6 +2764,22 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
|
|
2773
2764
|
}
|
2774
2765
|
return this.updateContentFromResponse(this.options);
|
2775
2766
|
}
|
2767
|
+
compilerPassMeta() {
|
2768
|
+
return u.pick(this.loadedEventProps(), [
|
2769
|
+
'revalidating',
|
2770
|
+
'response'
|
2771
|
+
]);
|
2772
|
+
}
|
2773
|
+
loadedEventProps() {
|
2774
|
+
const { expiredResponse } = this.options;
|
2775
|
+
return {
|
2776
|
+
request: this.request,
|
2777
|
+
response: this.response,
|
2778
|
+
renderOptions: this.options,
|
2779
|
+
revalidating: !!expiredResponse,
|
2780
|
+
expiredResponse,
|
2781
|
+
};
|
2782
|
+
}
|
2776
2783
|
onRequestSettledWithError(error) {
|
2777
2784
|
if (error instanceof up.Offline) {
|
2778
2785
|
this.request.emit('up:fragment:offline', {
|
@@ -2795,6 +2802,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
|
|
2795
2802
|
up.puts('up.render()', 'Rendering failed response using fail-prefixed options (https://unpoly.com/failed-responses)');
|
2796
2803
|
}
|
2797
2804
|
this.augmentOptionsFromResponse(finalRenderOptions);
|
2805
|
+
finalRenderOptions.meta = this.compilerPassMeta();
|
2798
2806
|
let result = new up.Change.FromContent(finalRenderOptions).execute();
|
2799
2807
|
result.finished = this.finish(result, finalRenderOptions);
|
2800
2808
|
return result;
|
@@ -2870,6 +2878,7 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
|
|
2870
2878
|
(() => {
|
2871
2879
|
u.memoizeMethod(_a.prototype, [
|
2872
2880
|
'getRequestAttrs',
|
2881
|
+
'loadedEventProps',
|
2873
2882
|
]);
|
2874
2883
|
})(),
|
2875
2884
|
_a);
|
@@ -2881,12 +2890,14 @@ up.Change.FromURL = (_a = class FromURL extends up.Change {
|
|
2881
2890
|
|
2882
2891
|
const u = up.util;
|
2883
2892
|
up.CompilerPass = class CompilerPass {
|
2884
|
-
constructor(root, compilers, { layer, data, dataMap
|
2893
|
+
constructor(root, compilers, { layer, data, dataMap, meta }) {
|
2894
|
+
layer || (layer = up.layer.get(root) || up.layer.current);
|
2885
2895
|
this.root = root;
|
2886
2896
|
this.compilers = compilers;
|
2887
|
-
this.layer = layer
|
2897
|
+
this.layer = layer;
|
2888
2898
|
this.data = data;
|
2889
2899
|
this.dataMap = dataMap;
|
2900
|
+
this.meta = { layer, ...meta };
|
2890
2901
|
this.errors = [];
|
2891
2902
|
}
|
2892
2903
|
run() {
|
@@ -2931,11 +2942,10 @@ up.CompilerPass = class CompilerPass {
|
|
2931
2942
|
return up.migrate.postCompile?.(matches, compiler);
|
2932
2943
|
}
|
2933
2944
|
compileOneElement(compiler, element) {
|
2934
|
-
const
|
2935
|
-
const compileArgs = [elementArg];
|
2945
|
+
const compileArgs = [element];
|
2936
2946
|
if (compiler.length !== 1) {
|
2937
2947
|
const data = up.syntax.data(element);
|
2938
|
-
compileArgs.push(data);
|
2948
|
+
compileArgs.push(data, this.meta);
|
2939
2949
|
}
|
2940
2950
|
const result = this.applyCompilerFunction(compiler, element, compileArgs);
|
2941
2951
|
let destructorOrDestructors = this.destructorPresence(result);
|
@@ -2944,11 +2954,10 @@ up.CompilerPass = class CompilerPass {
|
|
2944
2954
|
}
|
2945
2955
|
}
|
2946
2956
|
compileBatch(compiler, elements) {
|
2947
|
-
const
|
2948
|
-
const compileArgs = [elementsArgs];
|
2957
|
+
const compileArgs = [elements];
|
2949
2958
|
if (compiler.length !== 1) {
|
2950
2959
|
const dataList = u.map(elements, up.syntax.data);
|
2951
|
-
compileArgs.push(dataList);
|
2960
|
+
compileArgs.push(dataList, this.meta);
|
2952
2961
|
}
|
2953
2962
|
const result = this.applyCompilerFunction(compiler, elements, compileArgs);
|
2954
2963
|
if (this.destructorPresence(result)) {
|
@@ -3250,7 +3259,6 @@ up.EventListener = class EventListener extends up.Record {
|
|
3250
3259
|
'eventType',
|
3251
3260
|
'selector',
|
3252
3261
|
'callback',
|
3253
|
-
'jQuery',
|
3254
3262
|
'guard',
|
3255
3263
|
'baseLayer',
|
3256
3264
|
'passive',
|
@@ -3297,8 +3305,7 @@ up.EventListener = class EventListener extends up.Record {
|
|
3297
3305
|
return;
|
3298
3306
|
}
|
3299
3307
|
if (element) {
|
3300
|
-
const
|
3301
|
-
const args = [event, elementArg];
|
3308
|
+
const args = [event, element];
|
3302
3309
|
const expectedArgCount = this.callback.length;
|
3303
3310
|
if (expectedArgCount !== 1 && expectedArgCount !== 2) {
|
3304
3311
|
const data = up.syntax.data(element);
|
@@ -3354,7 +3361,6 @@ up.EventListenerGroup = class EventListenerGroup extends up.Record {
|
|
3354
3361
|
'eventTypes',
|
3355
3362
|
'selector',
|
3356
3363
|
'callback',
|
3357
|
-
'jQuery',
|
3358
3364
|
'guard',
|
3359
3365
|
'baseLayer',
|
3360
3366
|
'passive',
|
@@ -4276,12 +4282,12 @@ up.Layer = class Layer extends up.Record {
|
|
4276
4282
|
return this.stack.asCurrent(this, fn);
|
4277
4283
|
}
|
4278
4284
|
updateHistory(options) {
|
4279
|
-
if (u.isString(options.title)) {
|
4280
|
-
this.title = options.title;
|
4281
|
-
}
|
4282
4285
|
if (u.isString(options.location)) {
|
4283
4286
|
this.location = options.location;
|
4284
4287
|
}
|
4288
|
+
if (u.isString(options.title)) {
|
4289
|
+
this.title = options.title;
|
4290
|
+
}
|
4285
4291
|
}
|
4286
4292
|
isHistoryVisible() {
|
4287
4293
|
return this.history && (this.isRoot() || this.parent.isHistoryVisible());
|
@@ -4314,12 +4320,14 @@ up.Layer = class Layer extends up.Record {
|
|
4314
4320
|
set location(location) {
|
4315
4321
|
const previousLocation = this.location;
|
4316
4322
|
location = up.history.normalizeURL(location);
|
4317
|
-
if (previousLocation !== location) {
|
4323
|
+
if (previousLocation !== location || this.opening) {
|
4318
4324
|
this.savedLocation = location;
|
4319
|
-
this.emit('up:layer:location:changed', { location, log: false });
|
4320
4325
|
if (this.showsLiveHistory()) {
|
4321
4326
|
up.history.push(location);
|
4322
4327
|
}
|
4328
|
+
if (!this.opening) {
|
4329
|
+
this.emit('up:layer:location:changed', { location });
|
4330
|
+
}
|
4323
4331
|
}
|
4324
4332
|
}
|
4325
4333
|
selector(part) {
|
@@ -5750,7 +5758,7 @@ up.RenderOptions = (function () {
|
|
5750
5758
|
'history',
|
5751
5759
|
'source',
|
5752
5760
|
'saveScroll',
|
5753
|
-
'navigate'
|
5761
|
+
'navigate',
|
5754
5762
|
]);
|
5755
5763
|
const CONTENT_KEYS = [
|
5756
5764
|
'url',
|
@@ -6483,23 +6491,23 @@ up.Response = class Response extends up.Record {
|
|
6483
6491
|
get ok() {
|
6484
6492
|
return !u.evalOption(this.fail ?? up.network.config.fail, this);
|
6485
6493
|
}
|
6486
|
-
|
6494
|
+
header(name) {
|
6487
6495
|
return this.headers[name] || this.xhr?.getResponseHeader(name);
|
6488
6496
|
}
|
6489
6497
|
get contentType() {
|
6490
|
-
return this.
|
6498
|
+
return this.header('Content-Type');
|
6491
6499
|
}
|
6492
6500
|
get cspNonces() {
|
6493
|
-
return up.protocol.cspNoncesFromHeader(this.
|
6501
|
+
return up.protocol.cspNoncesFromHeader(this.header('Content-Security-Policy'));
|
6494
6502
|
}
|
6495
6503
|
get lastModified() {
|
6496
|
-
let header = this.
|
6504
|
+
let header = this.header('Last-Modified');
|
6497
6505
|
if (header) {
|
6498
6506
|
return new Date(header);
|
6499
6507
|
}
|
6500
6508
|
}
|
6501
6509
|
get etag() {
|
6502
|
-
return this.
|
6510
|
+
return this.header('ETag');
|
6503
6511
|
}
|
6504
6512
|
get json() {
|
6505
6513
|
return this.parsedJSON || (this.parsedJSON = JSON.parse(this.text));
|
@@ -6509,7 +6517,8 @@ up.Response = class Response extends up.Record {
|
|
6509
6517
|
return now - this.loadedAt;
|
6510
6518
|
}
|
6511
6519
|
get expired() {
|
6512
|
-
return this.age > up.network.config.cacheExpireAge ||
|
6520
|
+
return this.age > up.network.config.cacheExpireAge ||
|
6521
|
+
this.request.expired;
|
6513
6522
|
}
|
6514
6523
|
get description() {
|
6515
6524
|
return `HTTP ${this.status} response to ${this.request.description}`;
|
@@ -6957,6 +6966,7 @@ up.framework = (function () {
|
|
6957
6966
|
readyState = 'booting';
|
6958
6967
|
up.emit('up:framework:boot', { log: false });
|
6959
6968
|
readyState = 'booted';
|
6969
|
+
up.emit('up:framework:booted', { log: false });
|
6960
6970
|
}
|
6961
6971
|
else {
|
6962
6972
|
console.error("Unpoly cannot boot: %s", issue);
|
@@ -7038,9 +7048,6 @@ up.event = (function () {
|
|
7038
7048
|
function on(...args) {
|
7039
7049
|
return buildListenerGroup(args).bind();
|
7040
7050
|
}
|
7041
|
-
function $on(...args) {
|
7042
|
-
return buildListenerGroup(args, { jQuery: true }).bind();
|
7043
|
-
}
|
7044
7051
|
function off(...args) {
|
7045
7052
|
return buildListenerGroup(args).unbind();
|
7046
7053
|
}
|
@@ -7111,7 +7118,6 @@ up.event = (function () {
|
|
7111
7118
|
on('up:framework:reset', reset);
|
7112
7119
|
return {
|
7113
7120
|
on,
|
7114
|
-
$on,
|
7115
7121
|
off,
|
7116
7122
|
build,
|
7117
7123
|
emit,
|
@@ -7124,9 +7130,7 @@ up.event = (function () {
|
|
7124
7130
|
};
|
7125
7131
|
})();
|
7126
7132
|
up.on = up.event.on;
|
7127
|
-
up.$on = up.event.$on;
|
7128
7133
|
up.off = up.event.off;
|
7129
|
-
up.$off = up.event.off;
|
7130
7134
|
up.emit = up.event.emit;
|
7131
7135
|
|
7132
7136
|
|
@@ -7377,9 +7381,6 @@ up.syntax = (function () {
|
|
7377
7381
|
const compiler = buildCompiler(args);
|
7378
7382
|
return insertCompiler(registeredCompilers, compiler);
|
7379
7383
|
}
|
7380
|
-
function registerJQueryCompiler(...args) {
|
7381
|
-
registerCompiler(...args, { jQuery: true });
|
7382
|
-
}
|
7383
7384
|
function registerMacro(...args) {
|
7384
7385
|
const macro = buildCompiler(args);
|
7385
7386
|
if (up.framework.evaling) {
|
@@ -7388,9 +7389,6 @@ up.syntax = (function () {
|
|
7388
7389
|
}
|
7389
7390
|
return insertCompiler(registeredMacros, macro);
|
7390
7391
|
}
|
7391
|
-
function registerJQueryMacro(...args) {
|
7392
|
-
registerMacro(...args, { jQuery: true });
|
7393
|
-
}
|
7394
7392
|
function detectSystemMacroPriority(macroSelector) {
|
7395
7393
|
macroSelector = u.evalOption(macroSelector);
|
7396
7394
|
for (let substr in SYSTEM_MACRO_PRIORITIES) {
|
@@ -7414,7 +7412,6 @@ up.syntax = (function () {
|
|
7414
7412
|
isDefault: up.framework.evaling,
|
7415
7413
|
priority: 0,
|
7416
7414
|
batch: false,
|
7417
|
-
jQuery: false
|
7418
7415
|
});
|
7419
7416
|
return Object.assign(callback, options);
|
7420
7417
|
}
|
@@ -7456,10 +7453,10 @@ up.syntax = (function () {
|
|
7456
7453
|
destructors.push(destructor);
|
7457
7454
|
}
|
7458
7455
|
}
|
7459
|
-
function hello(element,
|
7460
|
-
element = up.fragment.get(element);
|
7456
|
+
function hello(element, options = {}) {
|
7457
|
+
element = up.fragment.get(element, options);
|
7461
7458
|
up.puts('up.hello()', "Compiling fragment %o", element);
|
7462
|
-
compile(element,
|
7459
|
+
compile(element, options);
|
7463
7460
|
up.fragment.emitInserted(element);
|
7464
7461
|
return element;
|
7465
7462
|
}
|
@@ -7496,8 +7493,6 @@ up.syntax = (function () {
|
|
7496
7493
|
return {
|
7497
7494
|
compiler: registerCompiler,
|
7498
7495
|
macro: registerMacro,
|
7499
|
-
$compiler: registerJQueryCompiler,
|
7500
|
-
$macro: registerJQueryMacro,
|
7501
7496
|
destructor: registerDestructor,
|
7502
7497
|
hello,
|
7503
7498
|
clean,
|
@@ -7505,10 +7500,8 @@ up.syntax = (function () {
|
|
7505
7500
|
};
|
7506
7501
|
})();
|
7507
7502
|
up.compiler = up.syntax.compiler;
|
7508
|
-
up.$compiler = up.syntax.$compiler;
|
7509
7503
|
up.destructor = up.syntax.destructor;
|
7510
7504
|
up.macro = up.syntax.macro;
|
7511
|
-
up.$macro = up.syntax.$macro;
|
7512
7505
|
up.data = up.syntax.data;
|
7513
7506
|
up.hello = up.syntax.hello;
|
7514
7507
|
|
@@ -9062,6 +9055,7 @@ up.layer = (function () {
|
|
9062
9055
|
if (handleDeprecatedConfig) {
|
9063
9056
|
configs.forEach(handleDeprecatedConfig);
|
9064
9057
|
}
|
9058
|
+
options.openAnimation ?? (options.openAnimation = u.pluckKey(options, 'animation'));
|
9065
9059
|
options = u.mergeDefined(...configs, { mode, stack }, options);
|
9066
9060
|
if (beforeNew) {
|
9067
9061
|
options = beforeNew(options);
|