turbo-rails 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a154de824445dd365a26b41da3b7ecf1699e12db6931ac23b516916093c85ab
4
- data.tar.gz: fbb86806c7dfc95d8703bb447bcfcdc9c3f3802442962b619f2d976a8f68fc57
3
+ metadata.gz: ae9e55565c85d150ae5bcafa265fcf6a626f39a2e5973e84d9f6507337344ad4
4
+ data.tar.gz: f20222d0d07c40215260bc9bf27002991aca5093147df738c9e8f9d4414be9f5
5
5
  SHA512:
6
- metadata.gz: fa8e5b959bf8d751bef2a6e12abbc98165fea71db42a49f0302d3e8319d669e3476322017889cb26a3262588b9fb14d7a05ae313ac9bc16d29eb3547275a412a
7
- data.tar.gz: 1abca2f9add27efadb27e4d52aaa1185bb652309a31353ad909b74369af766a592279181a7a8aa970b9d6c720d92bbf54e3e19a5b42bec419de83e97be249e71
6
+ metadata.gz: c1207a896a07408a7b229ac7051a2ad7301469bc7d56dd3b944a83c56e847981af934f2abf975ba90ca273647fbfb2cf5fc8eaffea95109c2c39a8415f8ce103
7
+ data.tar.gz: 03fb1eca56d27e8f828d865af85e5caddd6bbccf31f4999194e13105f8aaad067a3c0870ce7a99e3a408e5126a2d814f863ea33fb30160a5f7a07ee2bd983dc3
@@ -97,11 +97,7 @@ class FrameElement extends HTMLElement {
97
97
  this.delegate.disconnect();
98
98
  }
99
99
  reload() {
100
- const {src: src} = this;
101
- this.removeAttribute("complete");
102
- this.src = null;
103
- this.src = src;
104
- return this.loaded;
100
+ return this.delegate.sourceURLReloaded();
105
101
  }
106
102
  attributeChangedCallback(name) {
107
103
  if (name == "loading") {
@@ -936,6 +932,7 @@ class FormSubmitObserver {
936
932
  const submitter = event.submitter || undefined;
937
933
  if (form && submissionDoesNotDismissDialog(form, submitter) && submissionDoesNotTargetIFrame(form, submitter) && this.delegate.willSubmitForm(form, submitter)) {
938
934
  event.preventDefault();
935
+ event.stopImmediatePropagation();
939
936
  this.delegate.formSubmitted(form, submitter);
940
937
  }
941
938
  }
@@ -1076,6 +1073,47 @@ class FrameView extends View {
1076
1073
  }
1077
1074
  }
1078
1075
 
1076
+ class LinkInterceptor {
1077
+ constructor(delegate, element) {
1078
+ this.clickBubbled = event => {
1079
+ if (this.respondsToEventTarget(event.target)) {
1080
+ this.clickEvent = event;
1081
+ } else {
1082
+ delete this.clickEvent;
1083
+ }
1084
+ };
1085
+ this.linkClicked = event => {
1086
+ if (this.clickEvent && this.respondsToEventTarget(event.target) && event.target instanceof Element) {
1087
+ if (this.delegate.shouldInterceptLinkClick(event.target, event.detail.url, event.detail.originalEvent)) {
1088
+ this.clickEvent.preventDefault();
1089
+ event.preventDefault();
1090
+ this.delegate.linkClickIntercepted(event.target, event.detail.url, event.detail.originalEvent);
1091
+ }
1092
+ }
1093
+ delete this.clickEvent;
1094
+ };
1095
+ this.willVisit = _event => {
1096
+ delete this.clickEvent;
1097
+ };
1098
+ this.delegate = delegate;
1099
+ this.element = element;
1100
+ }
1101
+ start() {
1102
+ this.element.addEventListener("click", this.clickBubbled);
1103
+ document.addEventListener("turbo:click", this.linkClicked);
1104
+ document.addEventListener("turbo:before-visit", this.willVisit);
1105
+ }
1106
+ stop() {
1107
+ this.element.removeEventListener("click", this.clickBubbled);
1108
+ document.removeEventListener("turbo:click", this.linkClicked);
1109
+ document.removeEventListener("turbo:before-visit", this.willVisit);
1110
+ }
1111
+ respondsToEventTarget(target) {
1112
+ const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
1113
+ return element && element.closest("turbo-frame, html") == this.element;
1114
+ }
1115
+ }
1116
+
1079
1117
  class LinkClickObserver {
1080
1118
  constructor(delegate, eventTarget) {
1081
1119
  this.started = false;
@@ -1134,13 +1172,13 @@ function doesNotTargetIFrame(anchor) {
1134
1172
  class FormLinkClickObserver {
1135
1173
  constructor(delegate, element) {
1136
1174
  this.delegate = delegate;
1137
- this.linkClickObserver = new LinkClickObserver(this, element);
1175
+ this.linkInterceptor = new LinkClickObserver(this, element);
1138
1176
  }
1139
1177
  start() {
1140
- this.linkClickObserver.start();
1178
+ this.linkInterceptor.start();
1141
1179
  }
1142
1180
  stop() {
1143
- this.linkClickObserver.stop();
1181
+ this.linkInterceptor.stop();
1144
1182
  }
1145
1183
  willFollowLinkToLocation(link, location, originalEvent) {
1146
1184
  return this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) && link.hasAttribute("data-turbo-method");
@@ -1668,10 +1706,11 @@ class Visit {
1668
1706
  this.delegate = delegate;
1669
1707
  this.location = location;
1670
1708
  this.restorationIdentifier = restorationIdentifier || uuid();
1671
- const {action: action, historyChanged: historyChanged, referrer: referrer, snapshotHTML: snapshotHTML, response: response, visitCachedSnapshot: visitCachedSnapshot, willRender: willRender, updateHistory: updateHistory, shouldCacheSnapshot: shouldCacheSnapshot, acceptsStreamResponse: acceptsStreamResponse} = Object.assign(Object.assign({}, defaultOptions), options);
1709
+ const {action: action, historyChanged: historyChanged, referrer: referrer, snapshot: snapshot, snapshotHTML: snapshotHTML, response: response, visitCachedSnapshot: visitCachedSnapshot, willRender: willRender, updateHistory: updateHistory, shouldCacheSnapshot: shouldCacheSnapshot, acceptsStreamResponse: acceptsStreamResponse} = Object.assign(Object.assign({}, defaultOptions), options);
1672
1710
  this.action = action;
1673
1711
  this.historyChanged = historyChanged;
1674
1712
  this.referrer = referrer;
1713
+ this.snapshot = snapshot;
1675
1714
  this.snapshotHTML = snapshotHTML;
1676
1715
  this.response = response;
1677
1716
  this.isSamePage = this.delegate.locationWithActionIsSamePage(this.location, this.action);
@@ -1956,7 +1995,7 @@ class Visit {
1956
1995
  }
1957
1996
  cacheSnapshot() {
1958
1997
  if (!this.snapshotCached) {
1959
- this.view.cacheSnapshot().then((snapshot => snapshot && this.visitCachedSnapshot(snapshot)));
1998
+ this.view.cacheSnapshot(this.snapshot).then((snapshot => snapshot && this.visitCachedSnapshot(snapshot)));
1960
1999
  this.snapshotCached = true;
1961
2000
  }
1962
2001
  }
@@ -2065,11 +2104,11 @@ class BrowserAdapter {
2065
2104
  }
2066
2105
  }
2067
2106
  reload(reason) {
2107
+ var _a;
2068
2108
  dispatch("turbo:reload", {
2069
2109
  detail: reason
2070
2110
  });
2071
- if (!this.location) return;
2072
- window.location.href = this.location.toString();
2111
+ window.location.href = ((_a = this.location) === null || _a === void 0 ? void 0 : _a.toString()) || window.location.href;
2073
2112
  }
2074
2113
  get navigator() {
2075
2114
  return this.session.navigator;
@@ -2104,24 +2143,24 @@ class FrameRedirector {
2104
2143
  constructor(session, element) {
2105
2144
  this.session = session;
2106
2145
  this.element = element;
2107
- this.linkClickObserver = new LinkClickObserver(this, element);
2146
+ this.linkInterceptor = new LinkInterceptor(this, element);
2108
2147
  this.formSubmitObserver = new FormSubmitObserver(this, element);
2109
2148
  }
2110
2149
  start() {
2111
- this.linkClickObserver.start();
2150
+ this.linkInterceptor.start();
2112
2151
  this.formSubmitObserver.start();
2113
2152
  }
2114
2153
  stop() {
2115
- this.linkClickObserver.stop();
2154
+ this.linkInterceptor.stop();
2116
2155
  this.formSubmitObserver.stop();
2117
2156
  }
2118
- willFollowLinkToLocation(element, location, event) {
2119
- return this.shouldRedirect(element) && this.frameAllowsVisitingLocation(element, location, event);
2157
+ shouldInterceptLinkClick(element, _location, _event) {
2158
+ return this.shouldRedirect(element);
2120
2159
  }
2121
- followedLinkToLocation(element, url) {
2160
+ linkClickIntercepted(element, url, event) {
2122
2161
  const frame = this.findFrameElement(element);
2123
2162
  if (frame) {
2124
- frame.delegate.followedLinkToLocation(element, url);
2163
+ frame.delegate.linkClickIntercepted(element, url, event);
2125
2164
  }
2126
2165
  }
2127
2166
  willSubmitForm(element, submitter) {
@@ -2133,17 +2172,6 @@ class FrameRedirector {
2133
2172
  frame.delegate.formSubmitted(element, submitter);
2134
2173
  }
2135
2174
  }
2136
- frameAllowsVisitingLocation(target, {href: url}, originalEvent) {
2137
- const event = dispatch("turbo:click", {
2138
- target: target,
2139
- detail: {
2140
- url: url,
2141
- originalEvent: originalEvent
2142
- },
2143
- cancelable: true
2144
- });
2145
- return !event.defaultPrevented;
2146
- }
2147
2175
  shouldSubmit(form, submitter) {
2148
2176
  var _a;
2149
2177
  const action = getAction(form, submitter);
@@ -2777,10 +2805,10 @@ class PageView extends View {
2777
2805
  clearSnapshotCache() {
2778
2806
  this.snapshotCache.clear();
2779
2807
  }
2780
- async cacheSnapshot() {
2781
- if (this.shouldCacheSnapshot) {
2808
+ async cacheSnapshot(snapshot = this.snapshot) {
2809
+ if (snapshot.isCacheable) {
2782
2810
  this.delegate.viewWillCacheSnapshot();
2783
- const {snapshot: snapshot, lastRenderedLocation: location} = this;
2811
+ const {lastRenderedLocation: location} = this;
2784
2812
  await nextEventLoopTick();
2785
2813
  const cachedSnapshot = snapshot.clone();
2786
2814
  this.snapshotCache.put(location, cachedSnapshot);
@@ -2793,9 +2821,6 @@ class PageView extends View {
2793
2821
  get snapshot() {
2794
2822
  return PageSnapshot.fromElement(this.element);
2795
2823
  }
2796
- get shouldCacheSnapshot() {
2797
- return this.snapshot.isCacheable;
2798
- }
2799
2824
  }
2800
2825
 
2801
2826
  class Preloader {
@@ -3305,7 +3330,7 @@ class FrameController {
3305
3330
  this.view = new FrameView(this, this.element);
3306
3331
  this.appearanceObserver = new AppearanceObserver(this, this.element);
3307
3332
  this.formLinkClickObserver = new FormLinkClickObserver(this, this.element);
3308
- this.linkClickObserver = new LinkClickObserver(this, this.element);
3333
+ this.linkInterceptor = new LinkInterceptor(this, this.element);
3309
3334
  this.restorationIdentifier = uuid();
3310
3335
  this.formSubmitObserver = new FormSubmitObserver(this, this.element);
3311
3336
  }
@@ -3318,7 +3343,7 @@ class FrameController {
3318
3343
  this.loadSourceURL();
3319
3344
  }
3320
3345
  this.formLinkClickObserver.start();
3321
- this.linkClickObserver.start();
3346
+ this.linkInterceptor.start();
3322
3347
  this.formSubmitObserver.start();
3323
3348
  }
3324
3349
  }
@@ -3327,7 +3352,7 @@ class FrameController {
3327
3352
  this.connected = false;
3328
3353
  this.appearanceObserver.stop();
3329
3354
  this.formLinkClickObserver.stop();
3330
- this.linkClickObserver.stop();
3355
+ this.linkInterceptor.stop();
3331
3356
  this.formSubmitObserver.stop();
3332
3357
  }
3333
3358
  }
@@ -3345,6 +3370,15 @@ class FrameController {
3345
3370
  this.loadSourceURL();
3346
3371
  }
3347
3372
  }
3373
+ sourceURLReloaded() {
3374
+ const {src: src} = this.element;
3375
+ this.ignoringChangesToAttribute("complete", (() => {
3376
+ this.element.removeAttribute("complete");
3377
+ }));
3378
+ this.element.src = null;
3379
+ this.element.src = src;
3380
+ return this.element.loaded;
3381
+ }
3348
3382
  completeChanged() {
3349
3383
  if (this.isIgnoringChangesTo("complete")) return;
3350
3384
  this.loadSourceURL();
@@ -3400,17 +3434,17 @@ class FrameController {
3400
3434
  this.loadSourceURL();
3401
3435
  }
3402
3436
  willSubmitFormLinkToLocation(link) {
3403
- return link.closest("turbo-frame") == this.element && this.shouldInterceptNavigation(link);
3437
+ return this.shouldInterceptNavigation(link);
3404
3438
  }
3405
3439
  submittedFormLinkToLocation(link, _location, form) {
3406
3440
  const frame = this.findFrameElement(link);
3407
3441
  if (frame) form.setAttribute("data-turbo-frame", frame.id);
3408
3442
  }
3409
- willFollowLinkToLocation(element, location, event) {
3410
- return this.shouldInterceptNavigation(element) && this.frameAllowsVisitingLocation(element, location, event);
3443
+ shouldInterceptLinkClick(element, _location, _event) {
3444
+ return this.shouldInterceptNavigation(element);
3411
3445
  }
3412
- followedLinkToLocation(element, location) {
3413
- this.navigateFrame(element, location.href);
3446
+ linkClickIntercepted(element, location) {
3447
+ this.navigateFrame(element, location);
3414
3448
  }
3415
3449
  willSubmitForm(element, submitter) {
3416
3450
  return element.closest("turbo-frame") == this.element && this.shouldInterceptNavigation(element, submitter);
@@ -3458,7 +3492,7 @@ class FrameController {
3458
3492
  }
3459
3493
  formSubmissionSucceededWithResponse(formSubmission, response) {
3460
3494
  const frame = this.findFrameElement(formSubmission.formElement, formSubmission.submitter);
3461
- this.proposeVisitIfNavigatedWithAction(frame, formSubmission.formElement, formSubmission.submitter);
3495
+ frame.delegate.proposeVisitIfNavigatedWithAction(frame, formSubmission.formElement, formSubmission.submitter);
3462
3496
  frame.delegate.loadResponse(response);
3463
3497
  }
3464
3498
  formSubmissionFailedWithResponse(formSubmission, fetchResponse) {
@@ -3508,14 +3542,14 @@ class FrameController {
3508
3542
  }
3509
3543
  navigateFrame(element, url, submitter) {
3510
3544
  const frame = this.findFrameElement(element, submitter);
3511
- this.proposeVisitIfNavigatedWithAction(frame, element, submitter);
3545
+ this.pageSnapshot = PageSnapshot.fromElement(frame).clone();
3546
+ frame.delegate.proposeVisitIfNavigatedWithAction(frame, element, submitter);
3512
3547
  this.withCurrentNavigationElement(element, (() => {
3513
3548
  frame.src = url;
3514
3549
  }));
3515
3550
  }
3516
3551
  proposeVisitIfNavigatedWithAction(frame, element, submitter) {
3517
3552
  this.action = getVisitAction(submitter, element, frame);
3518
- this.frame = frame;
3519
3553
  if (isAction(this.action)) {
3520
3554
  const {visitCachedSnapshot: visitCachedSnapshot} = frame.delegate;
3521
3555
  frame.delegate.fetchResponseLoaded = fetchResponse => {
@@ -3532,7 +3566,8 @@ class FrameController {
3532
3566
  visitCachedSnapshot: visitCachedSnapshot,
3533
3567
  willRender: false,
3534
3568
  updateHistory: false,
3535
- restorationIdentifier: this.restorationIdentifier
3569
+ restorationIdentifier: this.restorationIdentifier,
3570
+ snapshot: this.pageSnapshot
3536
3571
  };
3537
3572
  if (this.action) options.action = this.action;
3538
3573
  session.visit(frame.src, options);
@@ -3541,9 +3576,9 @@ class FrameController {
3541
3576
  }
3542
3577
  }
3543
3578
  changeHistory() {
3544
- if (this.action && this.frame) {
3579
+ if (this.action) {
3545
3580
  const method = getHistoryMethodForAction(this.action);
3546
- session.history.update(method, expandURL(this.frame.src || ""), this.restorationIdentifier);
3581
+ session.history.update(method, expandURL(this.element.src || ""), this.restorationIdentifier);
3547
3582
  }
3548
3583
  }
3549
3584
  willHandleFrameMissingFromResponse(fetchResponse) {
@@ -3671,17 +3706,6 @@ class FrameController {
3671
3706
  const root = (_a = meta === null || meta === void 0 ? void 0 : meta.content) !== null && _a !== void 0 ? _a : "/";
3672
3707
  return expandURL(root);
3673
3708
  }
3674
- frameAllowsVisitingLocation(target, {href: url}, originalEvent) {
3675
- const event = dispatch("turbo:click", {
3676
- target: target,
3677
- detail: {
3678
- url: url,
3679
- originalEvent: originalEvent
3680
- },
3681
- cancelable: true
3682
- });
3683
- return !event.defaultPrevented;
3684
- }
3685
3709
  isIgnoringChangesTo(attributeName) {
3686
3710
  return this.ignoredAttributes.has(attributeName);
3687
3711
  }