Skip to content

Commit

Permalink
Update generated build assets (hotwired#237)
Browse files Browse the repository at this point in the history
Running `bin/test` locally yields changes to the build version of
`turbo.js`:

```
❯ bin/test
Installing Ruby dependencies
Warning: the running version of Bundler (2.2.12) is older than the version that created the lockfile (2.2.16). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.2.16`.
Installing JavasScript

app/javascript/turbo/index.js → app/assets/javascripts/turbo.js...
created app/assets/javascripts/turbo.js in 692ms
Migrating test database
Run options: --seed 20128

Running:

.............................................................

Finished in 0.556690s, 109.5762 runs/s, 192.2075 assertions/s.
61 runs, 107 assertions, 0 failures, 0 errors, 0 skips
```

This commit includes those changes.
  • Loading branch information
seanpdoyle authored Sep 17, 2021
1 parent 3e65530 commit 39ce079
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions app/assets/javascripts/turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function clickCaptured(event) {

(function() {
if ("SubmitEvent" in window) return;
if ("submitter" in Event.prototype) return;
addEventListener("click", clickCaptured, true);
Object.defineProperty(Event.prototype, "submitter", {
get() {
Expand Down Expand Up @@ -227,11 +226,11 @@ class FetchResponse {
return this.header("Content-Type");
}
get responseText() {
return this.response.clone().text();
return this.response.text();
}
get responseHTML() {
if (this.isHTML) {
return this.response.clone().text();
return this.response.text();
} else {
return Promise.resolve(undefined);
}
Expand Down Expand Up @@ -327,7 +326,7 @@ function fetchMethodFromString(method) {
}

class FetchRequest {
constructor(delegate, method, location, body = new URLSearchParams, target = null) {
constructor(delegate, method, location, body = new URLSearchParams) {
this.abortController = new AbortController;
this.resolveRequestPromise = value => {};
this.delegate = delegate;
Expand All @@ -339,7 +338,6 @@ class FetchRequest {
this.body = body;
this.url = location;
}
this.target = target;
}
get location() {
return this.url;
Expand Down Expand Up @@ -377,8 +375,7 @@ class FetchRequest {
cancelable: true,
detail: {
fetchResponse: fetchResponse
},
target: this.target
}
});
if (event.defaultPrevented) {
this.delegate.requestPreventedHandlingResponse(this, fetchResponse);
Expand Down Expand Up @@ -420,8 +417,7 @@ class FetchRequest {
fetchOptions: fetchOptions,
url: this.url.href,
resume: this.resolveRequestPromise
},
target: this.target
}
});
if (event.defaultPrevented) await requestInterception;
}
Expand Down Expand Up @@ -542,7 +538,7 @@ class FormSubmission {
this.formElement = formElement;
this.submitter = submitter;
this.formData = buildFormData(formElement, submitter);
this.fetchRequest = new FetchRequest(this, this.method, this.location, this.body, this.formElement);
this.fetchRequest = new FetchRequest(this, this.method, this.location, this.body);
this.mustRedirect = mustRedirect;
}
get method() {
Expand Down Expand Up @@ -1177,7 +1173,7 @@ ProgressBar.animationDuration = 300;
class HeadSnapshot extends Snapshot {
constructor() {
super(...arguments);
this.detailsByOuterHTML = this.children.filter((element => !elementIsNoscript(element))).map((element => elementWithoutNonce(element))).reduce(((result, element) => {
this.detailsByOuterHTML = this.children.filter((element => !elementIsNoscript(element))).reduce(((result, element) => {
const {outerHTML: outerHTML} = element;
const details = outerHTML in result ? result[outerHTML] : {
type: elementType(element),
Expand Down Expand Up @@ -1259,13 +1255,6 @@ function elementIsMetaElementWithName(element, name) {
return tagName == "meta" && element.getAttribute("name") == name;
}

function elementWithoutNonce(element) {
if (element.hasAttribute("nonce")) {
element.setAttribute("nonce", "");
}
return element;
}

class PageSnapshot extends Snapshot {
constructor(element, headSnapshot) {
super(element);
Expand Down Expand Up @@ -1816,18 +1805,18 @@ class FrameRedirector {
return this.shouldRedirect(element, submitter);
}
formSubmissionIntercepted(element, submitter) {
const frame = this.findFrameElement(element, submitter);
const frame = this.findFrameElement(element);
if (frame) {
frame.removeAttribute("reloadable");
frame.delegate.formSubmissionIntercepted(element, submitter);
}
}
shouldRedirect(element, submitter) {
const frame = this.findFrameElement(element, submitter);
const frame = this.findFrameElement(element);
return frame ? frame != element.closest("turbo-frame") : false;
}
findFrameElement(element, submitter) {
const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame");
findFrameElement(element) {
const id = element.getAttribute("data-turbo-frame");
if (id && id != "_top") {
const frame = this.element.querySelector(`#${id}:not([disabled])`);
if (frame instanceof FrameElement) {
Expand Down Expand Up @@ -2550,13 +2539,12 @@ class Session {
});
}
convertLinkWithMethodClickToFormSubmission(link) {
var _a;
const linkMethod = link.getAttribute("data-turbo-method");
if (linkMethod) {
const form = document.createElement("form");
form.method = linkMethod;
form.action = link.getAttribute("href") || "undefined";
(_a = link.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(form, link);
document.body.appendChild(form);
return dispatch("submit", {
cancelable: true,
target: form
Expand Down Expand Up @@ -2908,7 +2896,7 @@ class FrameController {
this.reloadable = false;
this.formSubmission = new FormSubmission(this, element, submitter);
if (this.formSubmission.fetchRequest.isIdempotent) {
this.navigateFrame(element, this.formSubmission.fetchRequest.url.href, submitter);
this.navigateFrame(element, this.formSubmission.fetchRequest.url.href);
} else {
const {fetchRequest: fetchRequest} = this.formSubmission;
this.prepareHeadersForRequest(fetchRequest.headers, fetchRequest);
Expand Down Expand Up @@ -2944,7 +2932,7 @@ class FrameController {
frame.setAttribute("busy", "");
}
formSubmissionSucceededWithResponse(formSubmission, response) {
const frame = this.findFrameElement(formSubmission.formElement, formSubmission.submitter);
const frame = this.findFrameElement(formSubmission.formElement);
frame.delegate.loadResponse(response);
}
formSubmissionFailedWithResponse(formSubmission, fetchResponse) {
Expand All @@ -2963,7 +2951,7 @@ class FrameController {
viewRenderedSnapshot(snapshot, isPreview) {}
viewInvalidated() {}
async visit(url) {
const request = new FetchRequest(this, FetchMethod.get, expandURL(url), undefined, this.element);
const request = new FetchRequest(this, FetchMethod.get, expandURL(url));
return new Promise((resolve => {
this.resolveVisitPromise = () => {
this.resolveVisitPromise = () => {};
Expand All @@ -2972,14 +2960,13 @@ class FrameController {
request.perform();
}));
}
navigateFrame(element, url, submitter) {
const frame = this.findFrameElement(element, submitter);
frame.setAttribute("reloadable", "");
navigateFrame(element, url) {
const frame = this.findFrameElement(element);
frame.src = url;
}
findFrameElement(element, submitter) {
findFrameElement(element) {
var _a;
const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
const id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
return (_a = getFrameElementById(id)) !== null && _a !== void 0 ? _a : this.element;
}
async extractForeignFrameElement(container) {
Expand All @@ -3000,7 +2987,7 @@ class FrameController {
return new FrameElement;
}
shouldInterceptNavigation(element, submitter) {
const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
const id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
if (!this.enabled || id == "_top") {
return false;
}
Expand Down

0 comments on commit 39ce079

Please sign in to comment.