turbo-rails 0.7.11 → 0.7.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fe3ad5cd094491982825ff80d21c619aab81bbcbe7e07168e467beeb3daa493
4
- data.tar.gz: 757f2faa9d39389014fc277ef75d3c806c9864b1deb87f6efae5118c604cf89b
3
+ metadata.gz: 85771aa7f175db32f70c6b54ed5ae8ef2dd5e5538bf987b40d68eb6e4699e7b0
4
+ data.tar.gz: 946d4845a3f2478c5ca443507114d9a7fc5231a86ecf17a294dbe40c28b10174
5
5
  SHA512:
6
- metadata.gz: e38bd507e3eaeeccd3e8e570e3341cdc8ae27074ba03d3e509605a13f3df4188bd54250bbbb8f6161e3d3e261e5ae6edd928d3fb2aac7fd8d9ede9e7c1810717
7
- data.tar.gz: 77f0a351ce8ab0cca1bc69413a508d6d8b790f61e18623ae16aad7d929536baa4f8c75b6407e6752d5301d022f0b49472c4376506181d1ffd31ed91b033459a2
6
+ metadata.gz: 41651d40a449a1622e479b2c2950f82149749fce699b88a1a723a77fc3c23af543e491bb2aefafa4ad0cfe5e85db95b7ea8e059d15294db22537b74a39a18ceb
7
+ data.tar.gz: 78f1a8a26ddc16fa9263eac070b7311223decaa69409715f4931f03f410435374a883759e360410f8ae8729c6fd6fdeafbe9d3b9e57211aaa5af677aa9b884a7
@@ -31,6 +31,7 @@ function clickCaptured(event) {
31
31
 
32
32
  (function() {
33
33
  if ("SubmitEvent" in window) return;
34
+ if ("submitter" in Event.prototype) return;
34
35
  addEventListener("click", clickCaptured, true);
35
36
  Object.defineProperty(Event.prototype, "submitter", {
36
37
  get() {
@@ -226,11 +227,11 @@ class FetchResponse {
226
227
  return this.header("Content-Type");
227
228
  }
228
229
  get responseText() {
229
- return this.response.text();
230
+ return this.response.clone().text();
230
231
  }
231
232
  get responseHTML() {
232
233
  if (this.isHTML) {
233
- return this.response.text();
234
+ return this.response.clone().text();
234
235
  } else {
235
236
  return Promise.resolve(undefined);
236
237
  }
@@ -326,7 +327,7 @@ function fetchMethodFromString(method) {
326
327
  }
327
328
 
328
329
  class FetchRequest {
329
- constructor(delegate, method, location, body = new URLSearchParams) {
330
+ constructor(delegate, method, location, body = new URLSearchParams, target = null) {
330
331
  this.abortController = new AbortController;
331
332
  this.resolveRequestPromise = value => {};
332
333
  this.delegate = delegate;
@@ -338,6 +339,7 @@ class FetchRequest {
338
339
  this.body = body;
339
340
  this.url = location;
340
341
  }
342
+ this.target = target;
341
343
  }
342
344
  get location() {
343
345
  return this.url;
@@ -375,7 +377,8 @@ class FetchRequest {
375
377
  cancelable: true,
376
378
  detail: {
377
379
  fetchResponse: fetchResponse
378
- }
380
+ },
381
+ target: this.target
379
382
  });
380
383
  if (event.defaultPrevented) {
381
384
  this.delegate.requestPreventedHandlingResponse(this, fetchResponse);
@@ -417,7 +420,8 @@ class FetchRequest {
417
420
  fetchOptions: fetchOptions,
418
421
  url: this.url.href,
419
422
  resume: this.resolveRequestPromise
420
- }
423
+ },
424
+ target: this.target
421
425
  });
422
426
  if (event.defaultPrevented) await requestInterception;
423
427
  }
@@ -538,7 +542,7 @@ class FormSubmission {
538
542
  this.formElement = formElement;
539
543
  this.submitter = submitter;
540
544
  this.formData = buildFormData(formElement, submitter);
541
- this.fetchRequest = new FetchRequest(this, this.method, this.location, this.body);
545
+ this.fetchRequest = new FetchRequest(this, this.method, this.location, this.body, this.formElement);
542
546
  this.mustRedirect = mustRedirect;
543
547
  }
544
548
  get method() {
@@ -1173,7 +1177,7 @@ ProgressBar.animationDuration = 300;
1173
1177
  class HeadSnapshot extends Snapshot {
1174
1178
  constructor() {
1175
1179
  super(...arguments);
1176
- this.detailsByOuterHTML = this.children.filter((element => !elementIsNoscript(element))).reduce(((result, element) => {
1180
+ this.detailsByOuterHTML = this.children.filter((element => !elementIsNoscript(element))).map((element => elementWithoutNonce(element))).reduce(((result, element) => {
1177
1181
  const {outerHTML: outerHTML} = element;
1178
1182
  const details = outerHTML in result ? result[outerHTML] : {
1179
1183
  type: elementType(element),
@@ -1255,6 +1259,13 @@ function elementIsMetaElementWithName(element, name) {
1255
1259
  return tagName == "meta" && element.getAttribute("name") == name;
1256
1260
  }
1257
1261
 
1262
+ function elementWithoutNonce(element) {
1263
+ if (element.hasAttribute("nonce")) {
1264
+ element.setAttribute("nonce", "");
1265
+ }
1266
+ return element;
1267
+ }
1268
+
1258
1269
  class PageSnapshot extends Snapshot {
1259
1270
  constructor(element, headSnapshot) {
1260
1271
  super(element);
@@ -1805,18 +1816,18 @@ class FrameRedirector {
1805
1816
  return this.shouldRedirect(element, submitter);
1806
1817
  }
1807
1818
  formSubmissionIntercepted(element, submitter) {
1808
- const frame = this.findFrameElement(element);
1819
+ const frame = this.findFrameElement(element, submitter);
1809
1820
  if (frame) {
1810
1821
  frame.removeAttribute("reloadable");
1811
1822
  frame.delegate.formSubmissionIntercepted(element, submitter);
1812
1823
  }
1813
1824
  }
1814
1825
  shouldRedirect(element, submitter) {
1815
- const frame = this.findFrameElement(element);
1826
+ const frame = this.findFrameElement(element, submitter);
1816
1827
  return frame ? frame != element.closest("turbo-frame") : false;
1817
1828
  }
1818
- findFrameElement(element) {
1819
- const id = element.getAttribute("data-turbo-frame");
1829
+ findFrameElement(element, submitter) {
1830
+ const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame");
1820
1831
  if (id && id != "_top") {
1821
1832
  const frame = this.element.querySelector(`#${id}:not([disabled])`);
1822
1833
  if (frame instanceof FrameElement) {
@@ -2539,12 +2550,13 @@ class Session {
2539
2550
  });
2540
2551
  }
2541
2552
  convertLinkWithMethodClickToFormSubmission(link) {
2553
+ var _a;
2542
2554
  const linkMethod = link.getAttribute("data-turbo-method");
2543
2555
  if (linkMethod) {
2544
2556
  const form = document.createElement("form");
2545
2557
  form.method = linkMethod;
2546
2558
  form.action = link.getAttribute("href") || "undefined";
2547
- document.body.appendChild(form);
2559
+ (_a = link.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(form, link);
2548
2560
  return dispatch("submit", {
2549
2561
  cancelable: true,
2550
2562
  target: form
@@ -2896,7 +2908,7 @@ class FrameController {
2896
2908
  this.reloadable = false;
2897
2909
  this.formSubmission = new FormSubmission(this, element, submitter);
2898
2910
  if (this.formSubmission.fetchRequest.isIdempotent) {
2899
- this.navigateFrame(element, this.formSubmission.fetchRequest.url.href);
2911
+ this.navigateFrame(element, this.formSubmission.fetchRequest.url.href, submitter);
2900
2912
  } else {
2901
2913
  const {fetchRequest: fetchRequest} = this.formSubmission;
2902
2914
  this.prepareHeadersForRequest(fetchRequest.headers, fetchRequest);
@@ -2932,7 +2944,7 @@ class FrameController {
2932
2944
  frame.setAttribute("busy", "");
2933
2945
  }
2934
2946
  formSubmissionSucceededWithResponse(formSubmission, response) {
2935
- const frame = this.findFrameElement(formSubmission.formElement);
2947
+ const frame = this.findFrameElement(formSubmission.formElement, formSubmission.submitter);
2936
2948
  frame.delegate.loadResponse(response);
2937
2949
  }
2938
2950
  formSubmissionFailedWithResponse(formSubmission, fetchResponse) {
@@ -2951,7 +2963,7 @@ class FrameController {
2951
2963
  viewRenderedSnapshot(snapshot, isPreview) {}
2952
2964
  viewInvalidated() {}
2953
2965
  async visit(url) {
2954
- const request = new FetchRequest(this, FetchMethod.get, expandURL(url));
2966
+ const request = new FetchRequest(this, FetchMethod.get, expandURL(url), undefined, this.element);
2955
2967
  return new Promise((resolve => {
2956
2968
  this.resolveVisitPromise = () => {
2957
2969
  this.resolveVisitPromise = () => {};
@@ -2960,13 +2972,14 @@ class FrameController {
2960
2972
  request.perform();
2961
2973
  }));
2962
2974
  }
2963
- navigateFrame(element, url) {
2964
- const frame = this.findFrameElement(element);
2975
+ navigateFrame(element, url, submitter) {
2976
+ const frame = this.findFrameElement(element, submitter);
2977
+ frame.setAttribute("reloadable", "");
2965
2978
  frame.src = url;
2966
2979
  }
2967
- findFrameElement(element) {
2980
+ findFrameElement(element, submitter) {
2968
2981
  var _a;
2969
- const id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
2982
+ const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
2970
2983
  return (_a = getFrameElementById(id)) !== null && _a !== void 0 ? _a : this.element;
2971
2984
  }
2972
2985
  async extractForeignFrameElement(container) {
@@ -2987,7 +3000,7 @@ class FrameController {
2987
3000
  return new FrameElement;
2988
3001
  }
2989
3002
  shouldInterceptNavigation(element, submitter) {
2990
- const id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
3003
+ const id = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-frame")) || element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
2991
3004
  if (!this.enabled || id == "_top") {
2992
3005
  return false;
2993
3006
  }
@@ -1,6 +1,6 @@
1
1
  if (cable_config_path = Rails.root.join("config/cable.yml")).exist?
2
2
  say "Enable redis in bundle"
3
- uncomment_lines "Gemfile", %(gem 'redis')
3
+ uncomment_lines "Gemfile", /gem ['"]redis['"]/
4
4
 
5
5
  say "Switch development cable to use redis"
6
6
  gsub_file cable_config_path.to_s, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
data/lib/turbo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Turbo
2
- VERSION = "0.7.11"
2
+ VERSION = "0.7.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.11
4
+ version: 0.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-09-03 00:00:00.000000000 Z
13
+ date: 2021-09-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails