assets/unpoly/unpoly.js in unpoly-rails-3.0.0.rc1 vs assets/unpoly/unpoly.js in unpoly-rails-3.0.0.rc2
- old
+ new
@@ -3,26 +3,31 @@
/* 0 */,
/* 1 */
/***/ (() => {
window.up = {
- version: '3.0.0-rc1'
+ version: '3.0.0-rc2'
};
/***/ }),
/* 2 */
/***/ (() => {
up.mockable = function (originalFn) {
- let spy;
- const mockableFn = function () {
- return (spy || originalFn).apply(null, arguments);
- };
- mockableFn.mock = () => spy = jasmine.createSpy('mockable', originalFn);
- document.addEventListener('up:framework:reset', () => spy = null);
- return mockableFn;
+ if (window.jasmine) {
+ let name = originalFn.name;
+ let obj = { [name]: originalFn };
+ let mockableFn = function () {
+ return obj[name].apply(this, arguments);
+ };
+ mockableFn.mock = () => spyOn(obj, name);
+ return mockableFn;
+ }
+ else {
+ return originalFn;
+ }
};
/***/ }),
/* 3 */
@@ -867,16 +872,10 @@
if (value) {
document.cookie = name + '=;Max-Age=0;Path=/';
return value;
}
}
- const getJQuery = function () {
- if (!canJQuery()) {
- up.fail('jQuery must be published as window.jQuery');
- }
- return jQuery;
- };
function assertConfirmed(options) {
const confirmed = !options.confirm || window.confirm(options.confirm);
if (!confirmed) {
throw new up.Aborted('User canceled action');
}
@@ -887,11 +886,10 @@
canPushState,
canJQuery,
canEval,
assertConfirmed,
popCookie,
- get jQuery() { return getJQuery(); },
};
})();
/***/ }),
@@ -1872,11 +1870,11 @@
e.setMissingAttr(newElement, 'up-time', time ? time.toUTCString() : false);
}
setETag({ newElement, etag }) {
e.setMissingAttr(newElement, 'up-etag', etag || false);
}
- setMeta(options) {
+ setReloadAttrs(options) {
this.setSource(options);
this.setTime(options);
this.setETag(options);
}
};
@@ -2080,13 +2078,13 @@
this.layer = this.buildLayer();
up.layer.stack.push(this.layer);
this.layer.createElements(this.content);
this.layer.setupHandlers();
this.handleHistory();
- this.setMeta({ newElement: this.content, source: this.options.source });
+ this.setReloadAttrs({ newElement: this.content, source: this.options.source });
responseDoc.finalizeElement(this.content);
- up.hello(this.layer.element, { layer: this.layer, origin: this.origin });
+ up.hello(this.layer.element, { ...this.options, layer: this.layer });
this.handleLayerChangeRequests();
this.handleScroll();
let renderResult = new up.RenderResult({
layer: this.layer,
fragments: [this.content],
@@ -2242,11 +2240,11 @@
addToResult(fragment) {
let newFragments = fragment.matches('up-wrapper') ? fragment.children : [fragment];
this.renderResult.fragments.unshift(...newFragments);
}
executeStep(step) {
- this.setMeta(step);
+ this.setReloadAttrs(step);
switch (step.placement) {
case 'swap': {
let keepPlan = this.findKeepPlan(step);
if (keepPlan) {
this.handleFocus(step.oldElement, step);
@@ -2747,23 +2745,16 @@
return this.onRequestSettledWithError(response);
}
}
onRequestSettledWithResponse(response) {
this.response = response;
- const expiredResponse = this.options.expiredResponse;
- const eventProps = {
- response: this.response,
- renderOptions: this.options,
- revalidating: !!expiredResponse,
- expiredResponse,
- };
- if (up.fragment.config.skipResponse(eventProps)) {
+ if (up.fragment.config.skipResponse(this.loadedEventProps())) {
this.skip();
}
else {
this.request.assertEmitted('up:fragment:loaded', {
- ...eventProps,
+ ...this.loadedEventProps(),
callback: this.options.onLoaded,
log: ['Loaded fragment from %s', this.response.description],
skip: () => this.skip()
});
}
@@ -2771,10 +2762,26 @@
if (fail) {
throw this.updateContentFromResponse(this.deriveFailOptions());
}
return this.updateContentFromResponse(this.options);
}
+ compilerPassMeta() {
+ return u.pick(this.loadedEventProps(), [
+ 'revalidating',
+ 'response'
+ ]);
+ }
+ loadedEventProps() {
+ const { expiredResponse } = this.options;
+ return {
+ request: this.request,
+ response: this.response,
+ renderOptions: this.options,
+ revalidating: !!expiredResponse,
+ expiredResponse,
+ };
+ }
onRequestSettledWithError(error) {
if (error instanceof up.Offline) {
this.request.emit('up:fragment:offline', {
callback: this.options.onOffline,
response: this.response,
@@ -2793,10 +2800,11 @@
updateContentFromResponse(finalRenderOptions) {
if (finalRenderOptions.failPrefixForced) {
up.puts('up.render()', 'Rendering failed response using fail-prefixed options (https://unpoly.com/failed-responses)');
}
this.augmentOptionsFromResponse(finalRenderOptions);
+ finalRenderOptions.meta = this.compilerPassMeta();
let result = new up.Change.FromContent(finalRenderOptions).execute();
result.finished = this.finish(result, finalRenderOptions);
return result;
}
async finish(renderResult, originalRenderOptions) {
@@ -2868,10 +2876,11 @@
}
},
(() => {
u.memoizeMethod(_a.prototype, [
'getRequestAttrs',
+ 'loadedEventProps',
]);
})(),
_a);
@@ -2879,16 +2888,18 @@
/* 33 */
/***/ (() => {
const u = up.util;
up.CompilerPass = class CompilerPass {
- constructor(root, compilers, { layer, data, dataMap } = {}) {
+ constructor(root, compilers, { layer, data, dataMap, meta }) {
+ layer || (layer = up.layer.get(root) || up.layer.current);
this.root = root;
this.compilers = compilers;
- this.layer = layer || up.layer.get(this.root) || up.layer.current;
+ this.layer = layer;
this.data = data;
this.dataMap = dataMap;
+ this.meta = { layer, ...meta };
this.errors = [];
}
run() {
this.layer.asCurrent(() => {
this.setCompileData();
@@ -2929,28 +2940,26 @@
}
}
return up.migrate.postCompile?.(matches, compiler);
}
compileOneElement(compiler, element) {
- const elementArg = compiler.jQuery ? up.browser.jQuery(element) : element;
- const compileArgs = [elementArg];
+ const compileArgs = [element];
if (compiler.length !== 1) {
const data = up.syntax.data(element);
- compileArgs.push(data);
+ compileArgs.push(data, this.meta);
}
const result = this.applyCompilerFunction(compiler, element, compileArgs);
let destructorOrDestructors = this.destructorPresence(result);
if (destructorOrDestructors) {
up.destructor(element, destructorOrDestructors);
}
}
compileBatch(compiler, elements) {
- const elementsArgs = compiler.jQuery ? up.browser.jQuery(elements) : elements;
- const compileArgs = [elementsArgs];
+ const compileArgs = [elements];
if (compiler.length !== 1) {
const dataList = u.map(elements, up.syntax.data);
- compileArgs.push(dataList);
+ compileArgs.push(dataList, this.meta);
}
const result = this.applyCompilerFunction(compiler, elements, compileArgs);
if (this.destructorPresence(result)) {
up.fail('Compilers with { batch: true } cannot return destructors');
}
@@ -3248,11 +3257,10 @@
return [
'element',
'eventType',
'selector',
'callback',
- 'jQuery',
'guard',
'baseLayer',
'passive',
'once',
'beforeBoot',
@@ -3295,12 +3303,11 @@
}
if (this.guard && !this.guard(event)) {
return;
}
if (element) {
- const elementArg = this.jQuery ? up.browser.jQuery(element) : element;
- const args = [event, elementArg];
+ const args = [event, element];
const expectedArgCount = this.callback.length;
if (expectedArgCount !== 1 && expectedArgCount !== 2) {
const data = up.syntax.data(element);
args.push(data);
}
@@ -3352,11 +3359,10 @@
return [
'elements',
'eventTypes',
'selector',
'callback',
- 'jQuery',
'guard',
'baseLayer',
'passive',
'once',
'beforeBoot',
@@ -4274,16 +4280,16 @@
}
asCurrent(fn) {
return this.stack.asCurrent(this, fn);
}
updateHistory(options) {
- if (u.isString(options.title)) {
- this.title = options.title;
- }
if (u.isString(options.location)) {
this.location = options.location;
}
+ if (u.isString(options.title)) {
+ this.title = options.title;
+ }
}
isHistoryVisible() {
return this.history && (this.isRoot() || this.parent.isHistoryVisible());
}
showsLiveHistory() {
@@ -4312,16 +4318,18 @@
}
}
set location(location) {
const previousLocation = this.location;
location = up.history.normalizeURL(location);
- if (previousLocation !== location) {
+ if (previousLocation !== location || this.opening) {
this.savedLocation = location;
- this.emit('up:layer:location:changed', { location, log: false });
if (this.showsLiveHistory()) {
up.history.push(location);
}
+ if (!this.opening) {
+ this.emit('up:layer:location:changed', { location });
+ }
}
}
selector(part) {
return this.constructor.selector(part);
}
@@ -5748,11 +5756,11 @@
'keep',
'hungry',
'history',
'source',
'saveScroll',
- 'navigate'
+ 'navigate',
]);
const CONTENT_KEYS = [
'url',
'content',
'fragment',
@@ -6481,37 +6489,38 @@
};
}
get ok() {
return !u.evalOption(this.fail ?? up.network.config.fail, this);
}
- getHeader(name) {
+ header(name) {
return this.headers[name] || this.xhr?.getResponseHeader(name);
}
get contentType() {
- return this.getHeader('Content-Type');
+ return this.header('Content-Type');
}
get cspNonces() {
- return up.protocol.cspNoncesFromHeader(this.getHeader('Content-Security-Policy'));
+ return up.protocol.cspNoncesFromHeader(this.header('Content-Security-Policy'));
}
get lastModified() {
- let header = this.getHeader('Last-Modified');
+ let header = this.header('Last-Modified');
if (header) {
return new Date(header);
}
}
get etag() {
- return this.getHeader('ETag');
+ return this.header('ETag');
}
get json() {
return this.parsedJSON || (this.parsedJSON = JSON.parse(this.text));
}
get age() {
let now = new Date();
return now - this.loadedAt;
}
get expired() {
- return this.age > up.network.config.cacheExpireAge || this.request.expired;
+ return this.age > up.network.config.cacheExpireAge ||
+ this.request.expired;
}
get description() {
return `HTTP ${this.status} response to ${this.request.description}`;
}
};
@@ -6955,10 +6964,11 @@
let issue = supportIssue();
if (!issue) {
readyState = 'booting';
up.emit('up:framework:boot', { log: false });
readyState = 'booted';
+ up.emit('up:framework:booted', { log: false });
}
else {
console.error("Unpoly cannot boot: %s", issue);
}
}
@@ -7036,13 +7046,10 @@
}
}
function on(...args) {
return buildListenerGroup(args).bind();
}
- function $on(...args) {
- return buildListenerGroup(args, { jQuery: true }).bind();
- }
function off(...args) {
return buildListenerGroup(args).unbind();
}
function buildListenerGroup(args, options) {
return up.EventListenerGroup.fromBindArgs(args, options);
@@ -7109,11 +7116,10 @@
}
on('up:click', 'a[up-emit]', executeEmitAttr);
on('up:framework:reset', reset);
return {
on,
- $on,
off,
build,
emit,
assertEmitted,
onEscape,
@@ -7122,13 +7128,11 @@
fork,
keyModifiers,
};
})();
up.on = up.event.on;
-up.$on = up.event.$on;
up.off = up.event.off;
-up.$off = up.event.off;
up.emit = up.event.emit;
/***/ }),
/* 82 */
@@ -7375,24 +7379,18 @@
let registeredMacros = [];
function registerCompiler(...args) {
const compiler = buildCompiler(args);
return insertCompiler(registeredCompilers, compiler);
}
- function registerJQueryCompiler(...args) {
- registerCompiler(...args, { jQuery: true });
- }
function registerMacro(...args) {
const macro = buildCompiler(args);
if (up.framework.evaling) {
macro.priority || (macro.priority = detectSystemMacroPriority(macro.selector) ||
up.fail('Unregistered priority for system macro %o', macro.selector));
}
return insertCompiler(registeredMacros, macro);
}
- function registerJQueryMacro(...args) {
- registerMacro(...args, { jQuery: true });
- }
function detectSystemMacroPriority(macroSelector) {
macroSelector = u.evalOption(macroSelector);
for (let substr in SYSTEM_MACRO_PRIORITIES) {
const priority = SYSTEM_MACRO_PRIORITIES[substr];
if (macroSelector.indexOf(substr) >= 0) {
@@ -7412,11 +7410,10 @@
options = u.options(options, {
selector,
isDefault: up.framework.evaling,
priority: 0,
batch: false,
- jQuery: false
});
return Object.assign(callback, options);
}
function insertCompiler(queue, newCompiler) {
let existingCompiler;
@@ -7454,14 +7451,14 @@
}
else {
destructors.push(destructor);
}
}
- function hello(element, { layer, data, dataMap } = {}) {
- element = up.fragment.get(element);
+ function hello(element, options = {}) {
+ element = up.fragment.get(element, options);
up.puts('up.hello()', "Compiling fragment %o", element);
- compile(element, { layer, data, dataMap });
+ compile(element, options);
up.fragment.emitInserted(element);
return element;
}
function clean(fragment, options = {}) {
new up.DestructorPass(fragment, options).run();
@@ -7494,23 +7491,19 @@
}
up.on('up:framework:reset', reset);
return {
compiler: registerCompiler,
macro: registerMacro,
- $compiler: registerJQueryCompiler,
- $macro: registerJQueryMacro,
destructor: registerDestructor,
hello,
clean,
data: readData,
};
})();
up.compiler = up.syntax.compiler;
-up.$compiler = up.syntax.$compiler;
up.destructor = up.syntax.destructor;
up.macro = up.syntax.macro;
-up.$macro = up.syntax.$macro;
up.data = up.syntax.data;
up.hello = up.syntax.hello;
/***/ }),
@@ -9060,9 +9053,10 @@
const configs = u.reverse(modeConfigs(mode));
let handleDeprecatedConfig = up.migrate.handleLayerConfig;
if (handleDeprecatedConfig) {
configs.forEach(handleDeprecatedConfig);
}
+ options.openAnimation ?? (options.openAnimation = u.pluckKey(options, 'animation'));
options = u.mergeDefined(...configs, { mode, stack }, options);
if (beforeNew) {
options = beforeNew(options);
}
return new Class(options);
\ No newline at end of file