assets/unpoly/unpoly.js in unpoly-rails-3.0.0 vs assets/unpoly/unpoly.js in unpoly-rails-3.1.0

- old
+ new

@@ -3,11 +3,11 @@ /* 0 */, /* 1 */ /***/ (() => { window.up = { - version: '3.0.0' + version: '3.1.0' }; /***/ }), /* 2 */ @@ -2317,11 +2317,16 @@ let viewports = up.viewport.subtree(keepPlan.oldElement); keepPlan.revivers = viewports.map(function (viewport) { let cursorProps = up.viewport.copyCursorProps(viewport); return () => up.viewport.copyCursorProps(cursorProps, viewport); }); - document.body.append(keepable); + if (this.willChangeElement(document.body)) { + keepPlan.newElement.replaceWith(keepable); + } + else { + document.body.append(keepable); + } keepPlans.push(keepPlan); } } } step.keepPlans = keepPlans; @@ -2432,10 +2437,13 @@ } hasAutoHistory() { const oldFragments = u.map(this.steps, 'oldElement'); return u.some(oldFragments, up.fragment.hasAutoHistory); } + willChangeElement(element) { + return u.some(this.steps, (step) => step.oldElement.contains(element)); + } }, (() => { u.memoizeMethod(_a.prototype, [ 'matchPreflight', 'matchPostflight', @@ -3515,20 +3523,23 @@ this.rendering = false; this.resetNextRenderPromise(); this.honorAbort(); } honorAbort() { - up.fragment.onAborted(this.form, ({ target }) => { - this.dirtySolutions = u.reject(this.dirtySolutions, ({ element }) => target.contains(element)); - }); + up.fragment.onAborted(this.form, { around: true }, ({ target }) => this.unscheduleSolutionsWithin(target)); } + unscheduleSolutionsWithin(container) { + this.dirtySolutions = u.reject(this.dirtySolutions, ({ element }) => container.contains(element)); + } resetNextRenderPromise() { this.nextRenderPromise = u.newDeferred(); } watchContainer(fieldOrForm) { let { event } = this.originOptions(fieldOrForm); - up.on(fieldOrForm, event, () => up.error.muteUncriticalRejection(this.validate({ origin: fieldOrForm }))); + let guard = () => up.fragment.isAlive(fieldOrForm); + let callback = () => up.error.muteUncriticalRejection(this.validate({ origin: fieldOrForm })); + up.on(fieldOrForm, event, { guard }, callback); } validate(options = {}) { let solutions = this.getSolutions(options); this.dirtySolutions.push(...solutions); this.scheduleNextRender(); @@ -3560,17 +3571,23 @@ } getTargetSelectorSolutions({ target, origin }) { if (u.isString(target) && target) { up.puts('up.validate()', 'Validating target "%s"', target); let simpleSelectors = up.fragment.splitTarget(target); - return simpleSelectors.map(function (simpleSelector) { - return { - element: up.fragment.get(simpleSelector, { origin }), - target: simpleSelector, - origin - }; - }); + return u.compact(simpleSelectors.map(function (simpleSelector) { + let element = up.fragment.get(simpleSelector, { origin }); + if (element) { + return { + element, + target: simpleSelector, + origin + }; + } + else { + up.fail('Validation target "%s" does not match an element', simpleSelector); + } + })); } } getElementSolutions(element) { up.puts('up.validate()', 'Validating element %o', element); return [{ @@ -3600,11 +3617,11 @@ } renderDirtySolutions() { up.error.muteUncriticalRejection(this.doRenderDirtySolutions()); } async doRenderDirtySolutions() { - this.dirtySolutions = u.filter(this.dirtySolutions, ({ element, origin }) => element.isConnected && origin.isConnected); + this.dirtySolutions = u.filter(this.dirtySolutions, ({ element, origin }) => up.fragment.isAlive(element) && up.fragment.isAlive(origin)); if (!this.dirtySolutions.length || this.rendering) { return; } let dirtySolutions = this.dirtySolutions; this.dirtySolutions = []; @@ -4637,17 +4654,17 @@ /***/ (() => { var _a; const e = up.element; up.Layer.Root = (_a = class Root extends up.Layer { + get element() { + return e.root; + } constructor(options) { super(options); this.setupHandlers(); } - get element() { - return e.root; - } getFirstSwappableElement() { return document.body; } static selector() { return 'html'; @@ -5650,11 +5667,10 @@ source: true, saveScroll: true, saveFocus: true, focus: 'keep', abort: 'target', - revalidate: 'auto', failOptions: true, }; const PRELOAD_OVERRIDES = { abort: false, confirm: false, @@ -5795,30 +5811,10 @@ /***/ (() => { var _a; const u = up.util; up.Request = (_a = class Request extends up.Record { - constructor(options) { - super(options); - this.params = new up.Params(this.params); - if (this.wrapMethod == null) { - this.wrapMethod = up.network.config.wrapMethod; - } - this.normalize(); - if ((this.target || this.layer || this.origin) && !options.basic) { - const layerLookupOptions = { origin: this.origin }; - this.layer = up.layer.get(this.layer, layerLookupOptions); - this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions); - this.context || (this.context = this.layer.context || {}); - this.failContext || (this.failContext = this.failLayer.context || {}); - this.mode || (this.mode = this.layer.mode); - this.failMode || (this.failMode = this.failLayer.mode); - } - this.deferred = u.newDeferred(); - this.badResponseTime ?? (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this)); - this.addAutoHeaders(); - } keys() { return [ 'method', 'url', 'hash', @@ -5857,10 +5853,30 @@ headers: {}, timeout: up.network.config.timeout, builtAt: new Date(), }; } + constructor(options) { + super(options); + this.params = new up.Params(this.params); + if (this.wrapMethod == null) { + this.wrapMethod = up.network.config.wrapMethod; + } + this.normalize(); + if ((this.target || this.layer || this.origin) && !options.basic) { + const layerLookupOptions = { origin: this.origin }; + this.layer = up.layer.get(this.layer, layerLookupOptions); + this.failLayer = up.layer.get(this.failLayer || this.layer, layerLookupOptions); + this.context || (this.context = this.layer.context || {}); + this.failContext || (this.failContext = this.failLayer.context || {}); + this.mode || (this.mode = this.layer.mode); + this.failMode || (this.failMode = this.failLayer.mode); + } + this.deferred = u.newDeferred(); + this.badResponseTime ?? (this.badResponseTime = u.evalOption(up.network.config.badResponseTime, this)); + this.addAutoHeaders(); + } get xhr() { return this._xhr ?? (this._xhr = new XMLHttpRequest()); } get fragments() { if (!this._fragments && this.target) { @@ -7711,16 +7727,17 @@ 'form', ], verifyDerivedTarget: true, navigateOptions: { cache: 'auto', + revalidate: 'auto', feedback: true, fallback: true, focus: 'auto', scroll: 'auto', history: 'auto', - peel: true + peel: true, }, matchAroundOrigin: true, runScripts: true, autoHistoryTargets: [':main'], autoFocus: ['hash', 'autofocus', 'main-if-main', 'keep', 'target-if-lost'], @@ -7783,14 +7800,16 @@ function emitFragmentDestroyed(fragment, options) { const log = options.log ?? ['Destroyed fragment %o', fragment]; const parent = options.parent || document; return up.emit(parent, 'up:fragment:destroyed', { fragment, parent, log }); } - function isDestroying(element) { - return !!element.closest('.up-destroying'); + function isNotDestroying(element) { + return !element.closest('.up-destroying'); } - const isNotDestroying = u.negate(isDestroying); + function isAlive(fragment) { + return fragment.isConnected && isNotDestroying(fragment); + } function getSmart(...args) { const options = u.extractOptions(args); const selector = args.pop(); const root = args[0]; if (u.isElementish(selector)) { @@ -8136,12 +8155,14 @@ up.network.abort(testFnWithAbortable, { ...options, reason }); for (let element of elements) { up.emit(element, 'up:fragment:aborted', { log: false }); } } - function onAborted(fragment, callback) { - let guard = (event) => event.target.contains(fragment); + function onAborted(fragment, ...args) { + let callback = u.extractCallback(args); + let options = u.extractOptions(args); + let guard = (event) => event.target.contains(fragment) || (options.around && fragment.contains(event.target)); let unsubscribe = up.on('up:fragment:aborted', { guard }, callback); up.destructor(fragment, unsubscribe); return unsubscribe; } up.on('up:framework:boot', function () { @@ -8185,9 +8206,10 @@ shouldRevalidate, abort, onAborted, splitTarget, parseTargetSteps, + isAlive, }; })(); up.reload = up.fragment.reload; up.destroy = up.fragment.destroy; up.render = up.fragment.render; \ No newline at end of file