@hotwired/turbo 7.0.0-rc.5 → 7.1.0-rc.2

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.
@@ -1,3954 +0,0 @@
1
- /*
2
- Turbo 7.0.0-beta.7
3
- Copyright © 2021 Basecamp, LLC
4
- */
5
- (function (global, factory) {
6
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
7
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
8
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Turbo = {}));
9
- }(this, (function (exports) { 'use strict';
10
-
11
- (function () {
12
- if (window.Reflect === undefined || window.customElements === undefined ||
13
- window.customElements.polyfillWrapFlushCallback) {
14
- return;
15
- }
16
- var BuiltInHTMLElement = HTMLElement;
17
- var wrapperForTheName = {
18
- 'HTMLElement': function HTMLElement() {
19
- return Reflect.construct(BuiltInHTMLElement, [], this.constructor);
20
- }
21
- };
22
- window.HTMLElement =
23
- wrapperForTheName['HTMLElement'];
24
- HTMLElement.prototype = BuiltInHTMLElement.prototype;
25
- HTMLElement.prototype.constructor = HTMLElement;
26
- Object.setPrototypeOf(HTMLElement, BuiltInHTMLElement);
27
- })();
28
-
29
- var submittersByForm = new WeakMap;
30
- function findSubmitterFromClickTarget(target) {
31
- var element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
32
- var candidate = element ? element.closest("input, button") : null;
33
- return (candidate === null || candidate === void 0 ? void 0 : candidate.type) == "submit" ? candidate : null;
34
- }
35
- function clickCaptured(event) {
36
- var submitter = findSubmitterFromClickTarget(event.target);
37
- if (submitter && submitter.form) {
38
- submittersByForm.set(submitter.form, submitter);
39
- }
40
- }
41
- (function () {
42
- if ("SubmitEvent" in window)
43
- return;
44
- addEventListener("click", clickCaptured, true);
45
- Object.defineProperty(Event.prototype, "submitter", {
46
- get: function () {
47
- if (this.type == "submit" && this.target instanceof HTMLFormElement) {
48
- return submittersByForm.get(this.target);
49
- }
50
- }
51
- });
52
- })();
53
-
54
- /*! *****************************************************************************
55
- Copyright (c) Microsoft Corporation.
56
-
57
- Permission to use, copy, modify, and/or distribute this software for any
58
- purpose with or without fee is hereby granted.
59
-
60
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
61
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
62
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
63
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
64
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
65
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
66
- PERFORMANCE OF THIS SOFTWARE.
67
- ***************************************************************************** */
68
- /* global Reflect, Promise */
69
-
70
- var extendStatics = function(d, b) {
71
- extendStatics = Object.setPrototypeOf ||
72
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
73
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
74
- return extendStatics(d, b);
75
- };
76
-
77
- function __extends(d, b) {
78
- extendStatics(d, b);
79
- function __() { this.constructor = d; }
80
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
81
- }
82
-
83
- var __assign = function() {
84
- __assign = Object.assign || function __assign(t) {
85
- for (var s, i = 1, n = arguments.length; i < n; i++) {
86
- s = arguments[i];
87
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
88
- }
89
- return t;
90
- };
91
- return __assign.apply(this, arguments);
92
- };
93
-
94
- function __awaiter(thisArg, _arguments, P, generator) {
95
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
96
- return new (P || (P = Promise))(function (resolve, reject) {
97
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
98
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
99
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
100
- step((generator = generator.apply(thisArg, _arguments || [])).next());
101
- });
102
- }
103
-
104
- function __generator(thisArg, body) {
105
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
106
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
107
- function verb(n) { return function (v) { return step([n, v]); }; }
108
- function step(op) {
109
- if (f) throw new TypeError("Generator is already executing.");
110
- while (_) try {
111
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
112
- if (y = 0, t) op = [op[0] & 2, t.value];
113
- switch (op[0]) {
114
- case 0: case 1: t = op; break;
115
- case 4: _.label++; return { value: op[1], done: false };
116
- case 5: _.label++; y = op[1]; op = [0]; continue;
117
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
118
- default:
119
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
120
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
121
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
122
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
123
- if (t[2]) _.ops.pop();
124
- _.trys.pop(); continue;
125
- }
126
- op = body.call(thisArg, _);
127
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
128
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
129
- }
130
- }
131
-
132
- function __values(o) {
133
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
134
- if (m) return m.call(o);
135
- if (o && typeof o.length === "number") return {
136
- next: function () {
137
- if (o && i >= o.length) o = void 0;
138
- return { value: o && o[i++], done: !o };
139
- }
140
- };
141
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
142
- }
143
-
144
- function __read(o, n) {
145
- var m = typeof Symbol === "function" && o[Symbol.iterator];
146
- if (!m) return o;
147
- var i = m.call(o), r, ar = [], e;
148
- try {
149
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
150
- }
151
- catch (error) { e = { error: error }; }
152
- finally {
153
- try {
154
- if (r && !r.done && (m = i["return"])) m.call(i);
155
- }
156
- finally { if (e) throw e.error; }
157
- }
158
- return ar;
159
- }
160
-
161
- function __spread() {
162
- for (var ar = [], i = 0; i < arguments.length; i++)
163
- ar = ar.concat(__read(arguments[i]));
164
- return ar;
165
- }
166
-
167
- function __makeTemplateObject(cooked, raw) {
168
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
169
- return cooked;
170
- }
171
-
172
- var FrameLoadingStyle;
173
- (function (FrameLoadingStyle) {
174
- FrameLoadingStyle["eager"] = "eager";
175
- FrameLoadingStyle["lazy"] = "lazy";
176
- })(FrameLoadingStyle || (FrameLoadingStyle = {}));
177
- var FrameElement = (function (_super) {
178
- __extends(FrameElement, _super);
179
- function FrameElement() {
180
- var _this = _super.call(this) || this;
181
- _this.loaded = Promise.resolve();
182
- _this.delegate = new FrameElement.delegateConstructor(_this);
183
- return _this;
184
- }
185
- Object.defineProperty(FrameElement, "observedAttributes", {
186
- get: function () {
187
- return ["disabled", "loading", "src"];
188
- },
189
- enumerable: false,
190
- configurable: true
191
- });
192
- FrameElement.prototype.connectedCallback = function () {
193
- this.delegate.connect();
194
- };
195
- FrameElement.prototype.disconnectedCallback = function () {
196
- this.delegate.disconnect();
197
- };
198
- FrameElement.prototype.attributeChangedCallback = function (name) {
199
- if (name == "loading") {
200
- this.delegate.loadingStyleChanged();
201
- }
202
- else if (name == "src") {
203
- this.delegate.sourceURLChanged();
204
- }
205
- else {
206
- this.delegate.disabledChanged();
207
- }
208
- };
209
- Object.defineProperty(FrameElement.prototype, "src", {
210
- get: function () {
211
- return this.getAttribute("src");
212
- },
213
- set: function (value) {
214
- if (value) {
215
- this.setAttribute("src", value);
216
- }
217
- else {
218
- this.removeAttribute("src");
219
- }
220
- },
221
- enumerable: false,
222
- configurable: true
223
- });
224
- Object.defineProperty(FrameElement.prototype, "loading", {
225
- get: function () {
226
- return frameLoadingStyleFromString(this.getAttribute("loading") || "");
227
- },
228
- set: function (value) {
229
- if (value) {
230
- this.setAttribute("loading", value);
231
- }
232
- else {
233
- this.removeAttribute("loading");
234
- }
235
- },
236
- enumerable: false,
237
- configurable: true
238
- });
239
- Object.defineProperty(FrameElement.prototype, "disabled", {
240
- get: function () {
241
- return this.hasAttribute("disabled");
242
- },
243
- set: function (value) {
244
- if (value) {
245
- this.setAttribute("disabled", "");
246
- }
247
- else {
248
- this.removeAttribute("disabled");
249
- }
250
- },
251
- enumerable: false,
252
- configurable: true
253
- });
254
- Object.defineProperty(FrameElement.prototype, "autoscroll", {
255
- get: function () {
256
- return this.hasAttribute("autoscroll");
257
- },
258
- set: function (value) {
259
- if (value) {
260
- this.setAttribute("autoscroll", "");
261
- }
262
- else {
263
- this.removeAttribute("autoscroll");
264
- }
265
- },
266
- enumerable: false,
267
- configurable: true
268
- });
269
- Object.defineProperty(FrameElement.prototype, "complete", {
270
- get: function () {
271
- return !this.delegate.isLoading;
272
- },
273
- enumerable: false,
274
- configurable: true
275
- });
276
- Object.defineProperty(FrameElement.prototype, "isActive", {
277
- get: function () {
278
- return this.ownerDocument === document && !this.isPreview;
279
- },
280
- enumerable: false,
281
- configurable: true
282
- });
283
- Object.defineProperty(FrameElement.prototype, "isPreview", {
284
- get: function () {
285
- var _a, _b;
286
- return (_b = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.documentElement) === null || _b === void 0 ? void 0 : _b.hasAttribute("data-turbo-preview");
287
- },
288
- enumerable: false,
289
- configurable: true
290
- });
291
- return FrameElement;
292
- }(HTMLElement));
293
- function frameLoadingStyleFromString(style) {
294
- switch (style.toLowerCase()) {
295
- case "lazy": return FrameLoadingStyle.lazy;
296
- default: return FrameLoadingStyle.eager;
297
- }
298
- }
299
-
300
- function expandURL(locatable) {
301
- return new URL(locatable.toString(), document.baseURI);
302
- }
303
- function getAnchor(url) {
304
- var anchorMatch;
305
- if (url.hash) {
306
- return url.hash.slice(1);
307
- }
308
- else if (anchorMatch = url.href.match(/#(.*)$/)) {
309
- return anchorMatch[1];
310
- }
311
- else {
312
- return "";
313
- }
314
- }
315
- function getExtension(url) {
316
- return (getLastPathComponent(url).match(/\.[^.]*$/) || [])[0] || "";
317
- }
318
- function isHTML(url) {
319
- return !!getExtension(url).match(/^(?:|\.(?:htm|html|xhtml))$/);
320
- }
321
- function isPrefixedBy(baseURL, url) {
322
- var prefix = getPrefix(url);
323
- return baseURL.href === expandURL(prefix).href || baseURL.href.startsWith(prefix);
324
- }
325
- function toCacheKey(url) {
326
- var anchorLength = url.hash.length;
327
- if (anchorLength < 2) {
328
- return url.href;
329
- }
330
- else {
331
- return url.href.slice(0, -anchorLength);
332
- }
333
- }
334
- function urlsAreEqual(left, right) {
335
- return expandURL(left).href == expandURL(right).href;
336
- }
337
- function getPathComponents(url) {
338
- return url.pathname.split("/").slice(1);
339
- }
340
- function getLastPathComponent(url) {
341
- return getPathComponents(url).slice(-1)[0];
342
- }
343
- function getPrefix(url) {
344
- return addTrailingSlash(url.origin + url.pathname);
345
- }
346
- function addTrailingSlash(value) {
347
- return value.endsWith("/") ? value : value + "/";
348
- }
349
-
350
- var FetchResponse = (function () {
351
- function FetchResponse(response) {
352
- this.response = response;
353
- }
354
- Object.defineProperty(FetchResponse.prototype, "succeeded", {
355
- get: function () {
356
- return this.response.ok;
357
- },
358
- enumerable: false,
359
- configurable: true
360
- });
361
- Object.defineProperty(FetchResponse.prototype, "failed", {
362
- get: function () {
363
- return !this.succeeded;
364
- },
365
- enumerable: false,
366
- configurable: true
367
- });
368
- Object.defineProperty(FetchResponse.prototype, "clientError", {
369
- get: function () {
370
- return this.statusCode >= 400 && this.statusCode <= 499;
371
- },
372
- enumerable: false,
373
- configurable: true
374
- });
375
- Object.defineProperty(FetchResponse.prototype, "serverError", {
376
- get: function () {
377
- return this.statusCode >= 500 && this.statusCode <= 599;
378
- },
379
- enumerable: false,
380
- configurable: true
381
- });
382
- Object.defineProperty(FetchResponse.prototype, "redirected", {
383
- get: function () {
384
- return this.response.redirected;
385
- },
386
- enumerable: false,
387
- configurable: true
388
- });
389
- Object.defineProperty(FetchResponse.prototype, "location", {
390
- get: function () {
391
- return expandURL(this.response.url);
392
- },
393
- enumerable: false,
394
- configurable: true
395
- });
396
- Object.defineProperty(FetchResponse.prototype, "isHTML", {
397
- get: function () {
398
- return this.contentType && this.contentType.match(/^(?:text\/([^\s;,]+\b)?html|application\/xhtml\+xml)\b/);
399
- },
400
- enumerable: false,
401
- configurable: true
402
- });
403
- Object.defineProperty(FetchResponse.prototype, "statusCode", {
404
- get: function () {
405
- return this.response.status;
406
- },
407
- enumerable: false,
408
- configurable: true
409
- });
410
- Object.defineProperty(FetchResponse.prototype, "contentType", {
411
- get: function () {
412
- return this.header("Content-Type");
413
- },
414
- enumerable: false,
415
- configurable: true
416
- });
417
- Object.defineProperty(FetchResponse.prototype, "responseText", {
418
- get: function () {
419
- return this.response.text();
420
- },
421
- enumerable: false,
422
- configurable: true
423
- });
424
- Object.defineProperty(FetchResponse.prototype, "responseHTML", {
425
- get: function () {
426
- if (this.isHTML) {
427
- return this.response.text();
428
- }
429
- else {
430
- return Promise.resolve(undefined);
431
- }
432
- },
433
- enumerable: false,
434
- configurable: true
435
- });
436
- FetchResponse.prototype.header = function (name) {
437
- return this.response.headers.get(name);
438
- };
439
- return FetchResponse;
440
- }());
441
-
442
- function dispatch(eventName, _a) {
443
- var _b = _a === void 0 ? {} : _a, target = _b.target, cancelable = _b.cancelable, detail = _b.detail;
444
- var event = new CustomEvent(eventName, { cancelable: cancelable, bubbles: true, detail: detail });
445
- void (target || document.documentElement).dispatchEvent(event);
446
- return event;
447
- }
448
- function nextAnimationFrame() {
449
- return new Promise(function (resolve) { return requestAnimationFrame(function () { return resolve(); }); });
450
- }
451
- function nextEventLoopTick() {
452
- return new Promise(function (resolve) { return setTimeout(function () { return resolve(); }, 0); });
453
- }
454
- function nextMicrotask() {
455
- return Promise.resolve();
456
- }
457
- function parseHTMLDocument(html) {
458
- if (html === void 0) { html = ""; }
459
- return new DOMParser().parseFromString(html, "text/html");
460
- }
461
- function unindent(strings) {
462
- var values = [];
463
- for (var _i = 1; _i < arguments.length; _i++) {
464
- values[_i - 1] = arguments[_i];
465
- }
466
- var lines = interpolate(strings, values).replace(/^\n/, "").split("\n");
467
- var match = lines[0].match(/^\s+/);
468
- var indent = match ? match[0].length : 0;
469
- return lines.map(function (line) { return line.slice(indent); }).join("\n");
470
- }
471
- function interpolate(strings, values) {
472
- return strings.reduce(function (result, string, i) {
473
- var value = values[i] == undefined ? "" : values[i];
474
- return result + string + value;
475
- }, "");
476
- }
477
- function uuid() {
478
- return Array.apply(null, { length: 36 }).map(function (_, i) {
479
- if (i == 8 || i == 13 || i == 18 || i == 23) {
480
- return "-";
481
- }
482
- else if (i == 14) {
483
- return "4";
484
- }
485
- else if (i == 19) {
486
- return (Math.floor(Math.random() * 4) + 8).toString(16);
487
- }
488
- else {
489
- return Math.floor(Math.random() * 15).toString(16);
490
- }
491
- }).join("");
492
- }
493
-
494
- var FetchMethod;
495
- (function (FetchMethod) {
496
- FetchMethod[FetchMethod["get"] = 0] = "get";
497
- FetchMethod[FetchMethod["post"] = 1] = "post";
498
- FetchMethod[FetchMethod["put"] = 2] = "put";
499
- FetchMethod[FetchMethod["patch"] = 3] = "patch";
500
- FetchMethod[FetchMethod["delete"] = 4] = "delete";
501
- })(FetchMethod || (FetchMethod = {}));
502
- function fetchMethodFromString(method) {
503
- switch (method.toLowerCase()) {
504
- case "get": return FetchMethod.get;
505
- case "post": return FetchMethod.post;
506
- case "put": return FetchMethod.put;
507
- case "patch": return FetchMethod.patch;
508
- case "delete": return FetchMethod.delete;
509
- }
510
- }
511
- var FetchRequest = (function () {
512
- function FetchRequest(delegate, method, location, body) {
513
- if (body === void 0) { body = new URLSearchParams; }
514
- this.abortController = new AbortController;
515
- this.delegate = delegate;
516
- this.method = method;
517
- this.headers = this.defaultHeaders;
518
- if (this.isIdempotent) {
519
- this.url = mergeFormDataEntries(location, __spread(body.entries()));
520
- }
521
- else {
522
- this.body = body;
523
- this.url = location;
524
- }
525
- }
526
- Object.defineProperty(FetchRequest.prototype, "location", {
527
- get: function () {
528
- return this.url;
529
- },
530
- enumerable: false,
531
- configurable: true
532
- });
533
- Object.defineProperty(FetchRequest.prototype, "params", {
534
- get: function () {
535
- return this.url.searchParams;
536
- },
537
- enumerable: false,
538
- configurable: true
539
- });
540
- Object.defineProperty(FetchRequest.prototype, "entries", {
541
- get: function () {
542
- return this.body ? Array.from(this.body.entries()) : [];
543
- },
544
- enumerable: false,
545
- configurable: true
546
- });
547
- FetchRequest.prototype.cancel = function () {
548
- this.abortController.abort();
549
- };
550
- FetchRequest.prototype.perform = function () {
551
- var _a, _b;
552
- return __awaiter(this, void 0, void 0, function () {
553
- var fetchOptions, response, error_1;
554
- return __generator(this, function (_c) {
555
- switch (_c.label) {
556
- case 0:
557
- fetchOptions = this.fetchOptions;
558
- (_b = (_a = this.delegate).prepareHeadersForRequest) === null || _b === void 0 ? void 0 : _b.call(_a, this.headers, this);
559
- dispatch("turbo:before-fetch-request", { detail: { fetchOptions: fetchOptions } });
560
- _c.label = 1;
561
- case 1:
562
- _c.trys.push([1, 4, 5, 6]);
563
- this.delegate.requestStarted(this);
564
- return [4, fetch(this.url.href, fetchOptions)];
565
- case 2:
566
- response = _c.sent();
567
- return [4, this.receive(response)];
568
- case 3: return [2, _c.sent()];
569
- case 4:
570
- error_1 = _c.sent();
571
- this.delegate.requestErrored(this, error_1);
572
- throw error_1;
573
- case 5:
574
- this.delegate.requestFinished(this);
575
- return [7];
576
- case 6: return [2];
577
- }
578
- });
579
- });
580
- };
581
- FetchRequest.prototype.receive = function (response) {
582
- return __awaiter(this, void 0, void 0, function () {
583
- var fetchResponse, event;
584
- return __generator(this, function (_a) {
585
- fetchResponse = new FetchResponse(response);
586
- event = dispatch("turbo:before-fetch-response", { cancelable: true, detail: { fetchResponse: fetchResponse } });
587
- if (event.defaultPrevented) {
588
- this.delegate.requestPreventedHandlingResponse(this, fetchResponse);
589
- }
590
- else if (fetchResponse.succeeded) {
591
- this.delegate.requestSucceededWithResponse(this, fetchResponse);
592
- }
593
- else {
594
- this.delegate.requestFailedWithResponse(this, fetchResponse);
595
- }
596
- return [2, fetchResponse];
597
- });
598
- });
599
- };
600
- Object.defineProperty(FetchRequest.prototype, "fetchOptions", {
601
- get: function () {
602
- return {
603
- method: FetchMethod[this.method].toUpperCase(),
604
- credentials: "same-origin",
605
- headers: this.headers,
606
- redirect: "follow",
607
- body: this.body,
608
- signal: this.abortSignal
609
- };
610
- },
611
- enumerable: false,
612
- configurable: true
613
- });
614
- Object.defineProperty(FetchRequest.prototype, "defaultHeaders", {
615
- get: function () {
616
- return {
617
- "Accept": "text/html, application/xhtml+xml"
618
- };
619
- },
620
- enumerable: false,
621
- configurable: true
622
- });
623
- Object.defineProperty(FetchRequest.prototype, "isIdempotent", {
624
- get: function () {
625
- return this.method == FetchMethod.get;
626
- },
627
- enumerable: false,
628
- configurable: true
629
- });
630
- Object.defineProperty(FetchRequest.prototype, "abortSignal", {
631
- get: function () {
632
- return this.abortController.signal;
633
- },
634
- enumerable: false,
635
- configurable: true
636
- });
637
- return FetchRequest;
638
- }());
639
- function mergeFormDataEntries(url, entries) {
640
- var e_1, _a;
641
- var currentSearchParams = new URLSearchParams(url.search);
642
- try {
643
- for (var entries_1 = __values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
644
- var _b = __read(entries_1_1.value, 2), name_1 = _b[0], value = _b[1];
645
- if (value instanceof File)
646
- continue;
647
- if (currentSearchParams.has(name_1)) {
648
- currentSearchParams.delete(name_1);
649
- url.searchParams.set(name_1, value);
650
- }
651
- else {
652
- url.searchParams.append(name_1, value);
653
- }
654
- }
655
- }
656
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
657
- finally {
658
- try {
659
- if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
660
- }
661
- finally { if (e_1) throw e_1.error; }
662
- }
663
- return url;
664
- }
665
-
666
- var AppearanceObserver = (function () {
667
- function AppearanceObserver(delegate, element) {
668
- var _this = this;
669
- this.started = false;
670
- this.intersect = function (entries) {
671
- var lastEntry = entries.slice(-1)[0];
672
- if (lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.isIntersecting) {
673
- _this.delegate.elementAppearedInViewport(_this.element);
674
- }
675
- };
676
- this.delegate = delegate;
677
- this.element = element;
678
- this.intersectionObserver = new IntersectionObserver(this.intersect);
679
- }
680
- AppearanceObserver.prototype.start = function () {
681
- if (!this.started) {
682
- this.started = true;
683
- this.intersectionObserver.observe(this.element);
684
- }
685
- };
686
- AppearanceObserver.prototype.stop = function () {
687
- if (this.started) {
688
- this.started = false;
689
- this.intersectionObserver.unobserve(this.element);
690
- }
691
- };
692
- return AppearanceObserver;
693
- }());
694
-
695
- var StreamMessage = (function () {
696
- function StreamMessage(html) {
697
- this.templateElement = document.createElement("template");
698
- this.templateElement.innerHTML = html;
699
- }
700
- StreamMessage.wrap = function (message) {
701
- if (typeof message == "string") {
702
- return new this(message);
703
- }
704
- else {
705
- return message;
706
- }
707
- };
708
- Object.defineProperty(StreamMessage.prototype, "fragment", {
709
- get: function () {
710
- var e_1, _a;
711
- var fragment = document.createDocumentFragment();
712
- try {
713
- for (var _b = __values(this.foreignElements), _c = _b.next(); !_c.done; _c = _b.next()) {
714
- var element = _c.value;
715
- fragment.appendChild(document.importNode(element, true));
716
- }
717
- }
718
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
719
- finally {
720
- try {
721
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
722
- }
723
- finally { if (e_1) throw e_1.error; }
724
- }
725
- return fragment;
726
- },
727
- enumerable: false,
728
- configurable: true
729
- });
730
- Object.defineProperty(StreamMessage.prototype, "foreignElements", {
731
- get: function () {
732
- return this.templateChildren.reduce(function (streamElements, child) {
733
- if (child.tagName.toLowerCase() == "turbo-stream") {
734
- return __spread(streamElements, [child]);
735
- }
736
- else {
737
- return streamElements;
738
- }
739
- }, []);
740
- },
741
- enumerable: false,
742
- configurable: true
743
- });
744
- Object.defineProperty(StreamMessage.prototype, "templateChildren", {
745
- get: function () {
746
- return Array.from(this.templateElement.content.children);
747
- },
748
- enumerable: false,
749
- configurable: true
750
- });
751
- StreamMessage.contentType = "text/vnd.turbo-stream.html";
752
- return StreamMessage;
753
- }());
754
-
755
- var FormSubmissionState;
756
- (function (FormSubmissionState) {
757
- FormSubmissionState[FormSubmissionState["initialized"] = 0] = "initialized";
758
- FormSubmissionState[FormSubmissionState["requesting"] = 1] = "requesting";
759
- FormSubmissionState[FormSubmissionState["waiting"] = 2] = "waiting";
760
- FormSubmissionState[FormSubmissionState["receiving"] = 3] = "receiving";
761
- FormSubmissionState[FormSubmissionState["stopping"] = 4] = "stopping";
762
- FormSubmissionState[FormSubmissionState["stopped"] = 5] = "stopped";
763
- })(FormSubmissionState || (FormSubmissionState = {}));
764
- var FormEnctype;
765
- (function (FormEnctype) {
766
- FormEnctype["urlEncoded"] = "application/x-www-form-urlencoded";
767
- FormEnctype["multipart"] = "multipart/form-data";
768
- FormEnctype["plain"] = "text/plain";
769
- })(FormEnctype || (FormEnctype = {}));
770
- function formEnctypeFromString(encoding) {
771
- switch (encoding.toLowerCase()) {
772
- case FormEnctype.multipart: return FormEnctype.multipart;
773
- case FormEnctype.plain: return FormEnctype.plain;
774
- default: return FormEnctype.urlEncoded;
775
- }
776
- }
777
- var FormSubmission = (function () {
778
- function FormSubmission(delegate, formElement, submitter, mustRedirect) {
779
- if (mustRedirect === void 0) { mustRedirect = false; }
780
- this.state = FormSubmissionState.initialized;
781
- this.delegate = delegate;
782
- this.formElement = formElement;
783
- this.submitter = submitter;
784
- this.formData = buildFormData(formElement, submitter);
785
- this.fetchRequest = new FetchRequest(this, this.method, this.location, this.body);
786
- this.mustRedirect = mustRedirect;
787
- }
788
- Object.defineProperty(FormSubmission.prototype, "method", {
789
- get: function () {
790
- var _a;
791
- var method = ((_a = this.submitter) === null || _a === void 0 ? void 0 : _a.getAttribute("formmethod")) || this.formElement.getAttribute("method") || "";
792
- return fetchMethodFromString(method.toLowerCase()) || FetchMethod.get;
793
- },
794
- enumerable: false,
795
- configurable: true
796
- });
797
- Object.defineProperty(FormSubmission.prototype, "action", {
798
- get: function () {
799
- var _a;
800
- return ((_a = this.submitter) === null || _a === void 0 ? void 0 : _a.getAttribute("formaction")) || this.formElement.action;
801
- },
802
- enumerable: false,
803
- configurable: true
804
- });
805
- Object.defineProperty(FormSubmission.prototype, "location", {
806
- get: function () {
807
- return expandURL(this.action);
808
- },
809
- enumerable: false,
810
- configurable: true
811
- });
812
- Object.defineProperty(FormSubmission.prototype, "body", {
813
- get: function () {
814
- if (this.enctype == FormEnctype.urlEncoded || this.method == FetchMethod.get) {
815
- return new URLSearchParams(this.stringFormData);
816
- }
817
- else {
818
- return this.formData;
819
- }
820
- },
821
- enumerable: false,
822
- configurable: true
823
- });
824
- Object.defineProperty(FormSubmission.prototype, "enctype", {
825
- get: function () {
826
- var _a;
827
- return formEnctypeFromString(((_a = this.submitter) === null || _a === void 0 ? void 0 : _a.getAttribute("formenctype")) || this.formElement.enctype);
828
- },
829
- enumerable: false,
830
- configurable: true
831
- });
832
- Object.defineProperty(FormSubmission.prototype, "isIdempotent", {
833
- get: function () {
834
- return this.fetchRequest.isIdempotent;
835
- },
836
- enumerable: false,
837
- configurable: true
838
- });
839
- Object.defineProperty(FormSubmission.prototype, "stringFormData", {
840
- get: function () {
841
- return __spread(this.formData).reduce(function (entries, _a) {
842
- var _b = __read(_a, 2), name = _b[0], value = _b[1];
843
- return entries.concat(typeof value == "string" ? [[name, value]] : []);
844
- }, []);
845
- },
846
- enumerable: false,
847
- configurable: true
848
- });
849
- FormSubmission.prototype.start = function () {
850
- return __awaiter(this, void 0, void 0, function () {
851
- var initialized, requesting;
852
- return __generator(this, function (_a) {
853
- initialized = FormSubmissionState.initialized, requesting = FormSubmissionState.requesting;
854
- if (this.state == initialized) {
855
- this.state = requesting;
856
- return [2, this.fetchRequest.perform()];
857
- }
858
- return [2];
859
- });
860
- });
861
- };
862
- FormSubmission.prototype.stop = function () {
863
- var stopping = FormSubmissionState.stopping, stopped = FormSubmissionState.stopped;
864
- if (this.state != stopping && this.state != stopped) {
865
- this.state = stopping;
866
- this.fetchRequest.cancel();
867
- return true;
868
- }
869
- };
870
- FormSubmission.prototype.prepareHeadersForRequest = function (headers, request) {
871
- if (!request.isIdempotent) {
872
- var token = getCookieValue(getMetaContent("csrf-param")) || getMetaContent("csrf-token");
873
- if (token) {
874
- headers["X-CSRF-Token"] = token;
875
- }
876
- headers["Accept"] = [StreamMessage.contentType, headers["Accept"]].join(", ");
877
- }
878
- };
879
- FormSubmission.prototype.requestStarted = function (request) {
880
- this.state = FormSubmissionState.waiting;
881
- dispatch("turbo:submit-start", { target: this.formElement, detail: { formSubmission: this } });
882
- this.delegate.formSubmissionStarted(this);
883
- };
884
- FormSubmission.prototype.requestPreventedHandlingResponse = function (request, response) {
885
- this.result = { success: response.succeeded, fetchResponse: response };
886
- };
887
- FormSubmission.prototype.requestSucceededWithResponse = function (request, response) {
888
- if (response.clientError || response.serverError) {
889
- this.delegate.formSubmissionFailedWithResponse(this, response);
890
- }
891
- else if (this.requestMustRedirect(request) && responseSucceededWithoutRedirect(response)) {
892
- var error = new Error("Form responses must redirect to another location");
893
- this.delegate.formSubmissionErrored(this, error);
894
- }
895
- else {
896
- this.state = FormSubmissionState.receiving;
897
- this.result = { success: true, fetchResponse: response };
898
- this.delegate.formSubmissionSucceededWithResponse(this, response);
899
- }
900
- };
901
- FormSubmission.prototype.requestFailedWithResponse = function (request, response) {
902
- this.result = { success: false, fetchResponse: response };
903
- this.delegate.formSubmissionFailedWithResponse(this, response);
904
- };
905
- FormSubmission.prototype.requestErrored = function (request, error) {
906
- this.result = { success: false, error: error };
907
- this.delegate.formSubmissionErrored(this, error);
908
- };
909
- FormSubmission.prototype.requestFinished = function (request) {
910
- this.state = FormSubmissionState.stopped;
911
- dispatch("turbo:submit-end", { target: this.formElement, detail: __assign({ formSubmission: this }, this.result) });
912
- this.delegate.formSubmissionFinished(this);
913
- };
914
- FormSubmission.prototype.requestMustRedirect = function (request) {
915
- return !request.isIdempotent && this.mustRedirect;
916
- };
917
- return FormSubmission;
918
- }());
919
- function buildFormData(formElement, submitter) {
920
- var formData = new FormData(formElement);
921
- var name = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("name");
922
- var value = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("value");
923
- if (name && value != null && formData.get(name) != value) {
924
- formData.append(name, value);
925
- }
926
- return formData;
927
- }
928
- function getCookieValue(cookieName) {
929
- if (cookieName != null) {
930
- var cookies = document.cookie ? document.cookie.split("; ") : [];
931
- var cookie = cookies.find(function (cookie) { return cookie.startsWith(cookieName); });
932
- if (cookie) {
933
- var value = cookie.split("=").slice(1).join("=");
934
- return value ? decodeURIComponent(value) : undefined;
935
- }
936
- }
937
- }
938
- function getMetaContent(name) {
939
- var element = document.querySelector("meta[name=\"" + name + "\"]");
940
- return element && element.content;
941
- }
942
- function responseSucceededWithoutRedirect(response) {
943
- return response.statusCode == 200 && !response.redirected;
944
- }
945
-
946
- var Snapshot = (function () {
947
- function Snapshot(element) {
948
- this.element = element;
949
- }
950
- Object.defineProperty(Snapshot.prototype, "children", {
951
- get: function () {
952
- return __spread(this.element.children);
953
- },
954
- enumerable: false,
955
- configurable: true
956
- });
957
- Snapshot.prototype.hasAnchor = function (anchor) {
958
- return this.getElementForAnchor(anchor) != null;
959
- };
960
- Snapshot.prototype.getElementForAnchor = function (anchor) {
961
- try {
962
- return this.element.querySelector("[id='" + anchor + "'], a[name='" + anchor + "']");
963
- }
964
- catch (_a) {
965
- return null;
966
- }
967
- };
968
- Object.defineProperty(Snapshot.prototype, "isConnected", {
969
- get: function () {
970
- return this.element.isConnected;
971
- },
972
- enumerable: false,
973
- configurable: true
974
- });
975
- Object.defineProperty(Snapshot.prototype, "firstAutofocusableElement", {
976
- get: function () {
977
- return this.element.querySelector("[autofocus]");
978
- },
979
- enumerable: false,
980
- configurable: true
981
- });
982
- Object.defineProperty(Snapshot.prototype, "permanentElements", {
983
- get: function () {
984
- return __spread(this.element.querySelectorAll("[id][data-turbo-permanent]"));
985
- },
986
- enumerable: false,
987
- configurable: true
988
- });
989
- Snapshot.prototype.getPermanentElementById = function (id) {
990
- return this.element.querySelector("#" + id + "[data-turbo-permanent]");
991
- };
992
- Snapshot.prototype.getPermanentElementMapForSnapshot = function (snapshot) {
993
- var e_1, _a;
994
- var permanentElementMap = {};
995
- try {
996
- for (var _b = __values(this.permanentElements), _c = _b.next(); !_c.done; _c = _b.next()) {
997
- var currentPermanentElement = _c.value;
998
- var id = currentPermanentElement.id;
999
- var newPermanentElement = snapshot.getPermanentElementById(id);
1000
- if (newPermanentElement) {
1001
- permanentElementMap[id] = [currentPermanentElement, newPermanentElement];
1002
- }
1003
- }
1004
- }
1005
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1006
- finally {
1007
- try {
1008
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1009
- }
1010
- finally { if (e_1) throw e_1.error; }
1011
- }
1012
- return permanentElementMap;
1013
- };
1014
- return Snapshot;
1015
- }());
1016
-
1017
- var FormInterceptor = (function () {
1018
- function FormInterceptor(delegate, element) {
1019
- var _this = this;
1020
- this.submitBubbled = (function (event) {
1021
- if (event.target instanceof HTMLFormElement) {
1022
- var form = event.target;
1023
- var submitter = event.submitter || undefined;
1024
- if (_this.delegate.shouldInterceptFormSubmission(form, submitter)) {
1025
- event.preventDefault();
1026
- event.stopImmediatePropagation();
1027
- _this.delegate.formSubmissionIntercepted(form, submitter);
1028
- }
1029
- }
1030
- });
1031
- this.delegate = delegate;
1032
- this.element = element;
1033
- }
1034
- FormInterceptor.prototype.start = function () {
1035
- this.element.addEventListener("submit", this.submitBubbled);
1036
- };
1037
- FormInterceptor.prototype.stop = function () {
1038
- this.element.removeEventListener("submit", this.submitBubbled);
1039
- };
1040
- return FormInterceptor;
1041
- }());
1042
-
1043
- var View = (function () {
1044
- function View(delegate, element) {
1045
- this.delegate = delegate;
1046
- this.element = element;
1047
- }
1048
- View.prototype.scrollToAnchor = function (anchor) {
1049
- var element = this.snapshot.getElementForAnchor(anchor);
1050
- if (element) {
1051
- this.scrollToElement(element);
1052
- }
1053
- else {
1054
- this.scrollToPosition({ x: 0, y: 0 });
1055
- }
1056
- };
1057
- View.prototype.scrollToElement = function (element) {
1058
- element.scrollIntoView();
1059
- };
1060
- View.prototype.scrollToPosition = function (_a) {
1061
- var x = _a.x, y = _a.y;
1062
- this.scrollRoot.scrollTo(x, y);
1063
- };
1064
- Object.defineProperty(View.prototype, "scrollRoot", {
1065
- get: function () {
1066
- return window;
1067
- },
1068
- enumerable: false,
1069
- configurable: true
1070
- });
1071
- View.prototype.render = function (renderer) {
1072
- return __awaiter(this, void 0, void 0, function () {
1073
- var isPreview, shouldRender, snapshot;
1074
- return __generator(this, function (_a) {
1075
- switch (_a.label) {
1076
- case 0:
1077
- if (this.renderer) {
1078
- throw new Error("rendering is already in progress");
1079
- }
1080
- isPreview = renderer.isPreview, shouldRender = renderer.shouldRender, snapshot = renderer.newSnapshot;
1081
- if (!shouldRender) return [3, 5];
1082
- _a.label = 1;
1083
- case 1:
1084
- _a.trys.push([1, , 3, 4]);
1085
- this.renderer = renderer;
1086
- this.prepareToRenderSnapshot(renderer);
1087
- this.delegate.viewWillRenderSnapshot(snapshot, isPreview);
1088
- return [4, this.renderSnapshot(renderer)];
1089
- case 2:
1090
- _a.sent();
1091
- this.delegate.viewRenderedSnapshot(snapshot, isPreview);
1092
- this.finishRenderingSnapshot(renderer);
1093
- return [3, 4];
1094
- case 3:
1095
- delete this.renderer;
1096
- return [7];
1097
- case 4: return [3, 6];
1098
- case 5:
1099
- this.invalidate();
1100
- _a.label = 6;
1101
- case 6: return [2];
1102
- }
1103
- });
1104
- });
1105
- };
1106
- View.prototype.invalidate = function () {
1107
- this.delegate.viewInvalidated();
1108
- };
1109
- View.prototype.prepareToRenderSnapshot = function (renderer) {
1110
- this.markAsPreview(renderer.isPreview);
1111
- renderer.prepareToRender();
1112
- };
1113
- View.prototype.markAsPreview = function (isPreview) {
1114
- if (isPreview) {
1115
- this.element.setAttribute("data-turbo-preview", "");
1116
- }
1117
- else {
1118
- this.element.removeAttribute("data-turbo-preview");
1119
- }
1120
- };
1121
- View.prototype.renderSnapshot = function (renderer) {
1122
- return __awaiter(this, void 0, void 0, function () {
1123
- return __generator(this, function (_a) {
1124
- switch (_a.label) {
1125
- case 0: return [4, renderer.render()];
1126
- case 1:
1127
- _a.sent();
1128
- return [2];
1129
- }
1130
- });
1131
- });
1132
- };
1133
- View.prototype.finishRenderingSnapshot = function (renderer) {
1134
- renderer.finishRendering();
1135
- };
1136
- return View;
1137
- }());
1138
-
1139
- var FrameView = (function (_super) {
1140
- __extends(FrameView, _super);
1141
- function FrameView() {
1142
- return _super !== null && _super.apply(this, arguments) || this;
1143
- }
1144
- FrameView.prototype.invalidate = function () {
1145
- this.element.innerHTML = "";
1146
- };
1147
- Object.defineProperty(FrameView.prototype, "snapshot", {
1148
- get: function () {
1149
- return new Snapshot(this.element);
1150
- },
1151
- enumerable: false,
1152
- configurable: true
1153
- });
1154
- return FrameView;
1155
- }(View));
1156
-
1157
- var LinkInterceptor = (function () {
1158
- function LinkInterceptor(delegate, element) {
1159
- var _this = this;
1160
- this.clickBubbled = function (event) {
1161
- if (_this.respondsToEventTarget(event.target)) {
1162
- _this.clickEvent = event;
1163
- }
1164
- else {
1165
- delete _this.clickEvent;
1166
- }
1167
- };
1168
- this.linkClicked = (function (event) {
1169
- if (_this.clickEvent && _this.respondsToEventTarget(event.target) && event.target instanceof Element) {
1170
- if (_this.delegate.shouldInterceptLinkClick(event.target, event.detail.url)) {
1171
- _this.clickEvent.preventDefault();
1172
- event.preventDefault();
1173
- _this.convertLinkWithMethodClickToFormSubmission(event.target) ||
1174
- _this.delegate.linkClickIntercepted(event.target, event.detail.url);
1175
- }
1176
- }
1177
- delete _this.clickEvent;
1178
- });
1179
- this.willVisit = function () {
1180
- delete _this.clickEvent;
1181
- };
1182
- this.delegate = delegate;
1183
- this.element = element;
1184
- }
1185
- LinkInterceptor.prototype.start = function () {
1186
- this.element.addEventListener("click", this.clickBubbled);
1187
- document.addEventListener("turbo:click", this.linkClicked);
1188
- document.addEventListener("turbo:before-visit", this.willVisit);
1189
- };
1190
- LinkInterceptor.prototype.stop = function () {
1191
- this.element.removeEventListener("click", this.clickBubbled);
1192
- document.removeEventListener("turbo:click", this.linkClicked);
1193
- document.removeEventListener("turbo:before-visit", this.willVisit);
1194
- };
1195
- LinkInterceptor.prototype.convertLinkWithMethodClickToFormSubmission = function (link) {
1196
- var _a;
1197
- var linkMethod = link.getAttribute("data-turbo-method") || link.getAttribute("data-method");
1198
- if (linkMethod) {
1199
- var form = document.createElement("form");
1200
- form.method = linkMethod;
1201
- form.action = link.getAttribute("href") || "undefined";
1202
- (_a = link.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(form, link);
1203
- return dispatch("submit", { target: form });
1204
- }
1205
- else {
1206
- return false;
1207
- }
1208
- };
1209
- LinkInterceptor.prototype.respondsToEventTarget = function (target) {
1210
- var element = target instanceof Element
1211
- ? target
1212
- : target instanceof Node
1213
- ? target.parentElement
1214
- : null;
1215
- return element && element.closest("turbo-frame, html") == this.element;
1216
- };
1217
- return LinkInterceptor;
1218
- }());
1219
-
1220
- var Bardo = (function () {
1221
- function Bardo(permanentElementMap) {
1222
- this.permanentElementMap = permanentElementMap;
1223
- }
1224
- Bardo.preservingPermanentElements = function (permanentElementMap, callback) {
1225
- var bardo = new this(permanentElementMap);
1226
- bardo.enter();
1227
- callback();
1228
- bardo.leave();
1229
- };
1230
- Bardo.prototype.enter = function () {
1231
- for (var id in this.permanentElementMap) {
1232
- var _a = __read(this.permanentElementMap[id], 2), newPermanentElement = _a[1];
1233
- this.replaceNewPermanentElementWithPlaceholder(newPermanentElement);
1234
- }
1235
- };
1236
- Bardo.prototype.leave = function () {
1237
- for (var id in this.permanentElementMap) {
1238
- var _a = __read(this.permanentElementMap[id], 1), currentPermanentElement = _a[0];
1239
- this.replaceCurrentPermanentElementWithClone(currentPermanentElement);
1240
- this.replacePlaceholderWithPermanentElement(currentPermanentElement);
1241
- }
1242
- };
1243
- Bardo.prototype.replaceNewPermanentElementWithPlaceholder = function (permanentElement) {
1244
- var placeholder = createPlaceholderForPermanentElement(permanentElement);
1245
- permanentElement.replaceWith(placeholder);
1246
- };
1247
- Bardo.prototype.replaceCurrentPermanentElementWithClone = function (permanentElement) {
1248
- var clone = permanentElement.cloneNode(true);
1249
- permanentElement.replaceWith(clone);
1250
- };
1251
- Bardo.prototype.replacePlaceholderWithPermanentElement = function (permanentElement) {
1252
- var placeholder = this.getPlaceholderById(permanentElement.id);
1253
- placeholder === null || placeholder === void 0 ? void 0 : placeholder.replaceWith(permanentElement);
1254
- };
1255
- Bardo.prototype.getPlaceholderById = function (id) {
1256
- return this.placeholders.find(function (element) { return element.content == id; });
1257
- };
1258
- Object.defineProperty(Bardo.prototype, "placeholders", {
1259
- get: function () {
1260
- return __spread(document.querySelectorAll("meta[name=turbo-permanent-placeholder][content]"));
1261
- },
1262
- enumerable: false,
1263
- configurable: true
1264
- });
1265
- return Bardo;
1266
- }());
1267
- function createPlaceholderForPermanentElement(permanentElement) {
1268
- var element = document.createElement("meta");
1269
- element.setAttribute("name", "turbo-permanent-placeholder");
1270
- element.setAttribute("content", permanentElement.id);
1271
- return element;
1272
- }
1273
-
1274
- var Renderer = (function () {
1275
- function Renderer(currentSnapshot, newSnapshot, isPreview) {
1276
- var _this = this;
1277
- this.currentSnapshot = currentSnapshot;
1278
- this.newSnapshot = newSnapshot;
1279
- this.isPreview = isPreview;
1280
- this.promise = new Promise(function (resolve, reject) { return _this.resolvingFunctions = { resolve: resolve, reject: reject }; });
1281
- }
1282
- Object.defineProperty(Renderer.prototype, "shouldRender", {
1283
- get: function () {
1284
- return true;
1285
- },
1286
- enumerable: false,
1287
- configurable: true
1288
- });
1289
- Renderer.prototype.prepareToRender = function () {
1290
- return;
1291
- };
1292
- Renderer.prototype.finishRendering = function () {
1293
- if (this.resolvingFunctions) {
1294
- this.resolvingFunctions.resolve();
1295
- delete this.resolvingFunctions;
1296
- }
1297
- };
1298
- Renderer.prototype.createScriptElement = function (element) {
1299
- if (element.getAttribute("data-turbo-eval") == "false") {
1300
- return element;
1301
- }
1302
- else {
1303
- var createdScriptElement = document.createElement("script");
1304
- createdScriptElement.textContent = element.textContent;
1305
- createdScriptElement.async = false;
1306
- copyElementAttributes(createdScriptElement, element);
1307
- return createdScriptElement;
1308
- }
1309
- };
1310
- Renderer.prototype.preservingPermanentElements = function (callback) {
1311
- Bardo.preservingPermanentElements(this.permanentElementMap, callback);
1312
- };
1313
- Renderer.prototype.focusFirstAutofocusableElement = function () {
1314
- var element = this.connectedSnapshot.firstAutofocusableElement;
1315
- if (elementIsFocusable(element)) {
1316
- element.focus();
1317
- }
1318
- };
1319
- Object.defineProperty(Renderer.prototype, "connectedSnapshot", {
1320
- get: function () {
1321
- return this.newSnapshot.isConnected ? this.newSnapshot : this.currentSnapshot;
1322
- },
1323
- enumerable: false,
1324
- configurable: true
1325
- });
1326
- Object.defineProperty(Renderer.prototype, "currentElement", {
1327
- get: function () {
1328
- return this.currentSnapshot.element;
1329
- },
1330
- enumerable: false,
1331
- configurable: true
1332
- });
1333
- Object.defineProperty(Renderer.prototype, "newElement", {
1334
- get: function () {
1335
- return this.newSnapshot.element;
1336
- },
1337
- enumerable: false,
1338
- configurable: true
1339
- });
1340
- Object.defineProperty(Renderer.prototype, "permanentElementMap", {
1341
- get: function () {
1342
- return this.currentSnapshot.getPermanentElementMapForSnapshot(this.newSnapshot);
1343
- },
1344
- enumerable: false,
1345
- configurable: true
1346
- });
1347
- return Renderer;
1348
- }());
1349
- function copyElementAttributes(destinationElement, sourceElement) {
1350
- var e_1, _a;
1351
- try {
1352
- for (var _b = __values(__spread(sourceElement.attributes)), _c = _b.next(); !_c.done; _c = _b.next()) {
1353
- var _d = _c.value, name_1 = _d.name, value = _d.value;
1354
- destinationElement.setAttribute(name_1, value);
1355
- }
1356
- }
1357
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1358
- finally {
1359
- try {
1360
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1361
- }
1362
- finally { if (e_1) throw e_1.error; }
1363
- }
1364
- }
1365
- function elementIsFocusable(element) {
1366
- return element && typeof element.focus == "function";
1367
- }
1368
-
1369
- var FrameRenderer = (function (_super) {
1370
- __extends(FrameRenderer, _super);
1371
- function FrameRenderer() {
1372
- return _super !== null && _super.apply(this, arguments) || this;
1373
- }
1374
- Object.defineProperty(FrameRenderer.prototype, "shouldRender", {
1375
- get: function () {
1376
- return true;
1377
- },
1378
- enumerable: false,
1379
- configurable: true
1380
- });
1381
- FrameRenderer.prototype.render = function () {
1382
- return __awaiter(this, void 0, void 0, function () {
1383
- var _this = this;
1384
- return __generator(this, function (_a) {
1385
- switch (_a.label) {
1386
- case 0: return [4, nextAnimationFrame()];
1387
- case 1:
1388
- _a.sent();
1389
- this.preservingPermanentElements(function () {
1390
- _this.loadFrameElement();
1391
- });
1392
- this.scrollFrameIntoView();
1393
- return [4, nextAnimationFrame()];
1394
- case 2:
1395
- _a.sent();
1396
- this.focusFirstAutofocusableElement();
1397
- return [2];
1398
- }
1399
- });
1400
- });
1401
- };
1402
- FrameRenderer.prototype.loadFrameElement = function () {
1403
- var _a;
1404
- var destinationRange = document.createRange();
1405
- destinationRange.selectNodeContents(this.currentElement);
1406
- destinationRange.deleteContents();
1407
- var frameElement = this.newElement;
1408
- var sourceRange = (_a = frameElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.createRange();
1409
- if (sourceRange) {
1410
- sourceRange.selectNodeContents(frameElement);
1411
- this.currentElement.appendChild(sourceRange.extractContents());
1412
- }
1413
- };
1414
- FrameRenderer.prototype.scrollFrameIntoView = function () {
1415
- if (this.currentElement.autoscroll || this.newElement.autoscroll) {
1416
- var element = this.currentElement.firstElementChild;
1417
- var block = readScrollLogicalPosition(this.currentElement.getAttribute("data-autoscroll-block"), "end");
1418
- if (element) {
1419
- element.scrollIntoView({ block: block });
1420
- return true;
1421
- }
1422
- }
1423
- return false;
1424
- };
1425
- return FrameRenderer;
1426
- }(Renderer));
1427
- function readScrollLogicalPosition(value, defaultValue) {
1428
- if (value == "end" || value == "start" || value == "center" || value == "nearest") {
1429
- return value;
1430
- }
1431
- else {
1432
- return defaultValue;
1433
- }
1434
- }
1435
-
1436
- var ProgressBar = (function () {
1437
- function ProgressBar() {
1438
- var _this = this;
1439
- this.hiding = false;
1440
- this.value = 0;
1441
- this.visible = false;
1442
- this.trickle = function () {
1443
- _this.setValue(_this.value + Math.random() / 100);
1444
- };
1445
- this.stylesheetElement = this.createStylesheetElement();
1446
- this.progressElement = this.createProgressElement();
1447
- this.installStylesheetElement();
1448
- this.setValue(0);
1449
- }
1450
- Object.defineProperty(ProgressBar, "defaultCSS", {
1451
- get: function () {
1452
- return unindent(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .turbo-progress-bar {\n position: fixed;\n display: block;\n top: 0;\n left: 0;\n height: 3px;\n background: #0076ff;\n z-index: 9999;\n transition:\n width ", "ms ease-out,\n opacity ", "ms ", "ms ease-in;\n transform: translate3d(0, 0, 0);\n }\n "], ["\n .turbo-progress-bar {\n position: fixed;\n display: block;\n top: 0;\n left: 0;\n height: 3px;\n background: #0076ff;\n z-index: 9999;\n transition:\n width ", "ms ease-out,\n opacity ", "ms ", "ms ease-in;\n transform: translate3d(0, 0, 0);\n }\n "])), ProgressBar.animationDuration, ProgressBar.animationDuration / 2, ProgressBar.animationDuration / 2);
1453
- },
1454
- enumerable: false,
1455
- configurable: true
1456
- });
1457
- ProgressBar.prototype.show = function () {
1458
- if (!this.visible) {
1459
- this.visible = true;
1460
- this.installProgressElement();
1461
- this.startTrickling();
1462
- }
1463
- };
1464
- ProgressBar.prototype.hide = function () {
1465
- var _this = this;
1466
- if (this.visible && !this.hiding) {
1467
- this.hiding = true;
1468
- this.fadeProgressElement(function () {
1469
- _this.uninstallProgressElement();
1470
- _this.stopTrickling();
1471
- _this.visible = false;
1472
- _this.hiding = false;
1473
- });
1474
- }
1475
- };
1476
- ProgressBar.prototype.setValue = function (value) {
1477
- this.value = value;
1478
- this.refresh();
1479
- };
1480
- ProgressBar.prototype.installStylesheetElement = function () {
1481
- document.head.insertBefore(this.stylesheetElement, document.head.firstChild);
1482
- };
1483
- ProgressBar.prototype.installProgressElement = function () {
1484
- this.progressElement.style.width = "0";
1485
- this.progressElement.style.opacity = "1";
1486
- document.documentElement.insertBefore(this.progressElement, document.body);
1487
- this.refresh();
1488
- };
1489
- ProgressBar.prototype.fadeProgressElement = function (callback) {
1490
- this.progressElement.style.opacity = "0";
1491
- setTimeout(callback, ProgressBar.animationDuration * 1.5);
1492
- };
1493
- ProgressBar.prototype.uninstallProgressElement = function () {
1494
- if (this.progressElement.parentNode) {
1495
- document.documentElement.removeChild(this.progressElement);
1496
- }
1497
- };
1498
- ProgressBar.prototype.startTrickling = function () {
1499
- if (!this.trickleInterval) {
1500
- this.trickleInterval = window.setInterval(this.trickle, ProgressBar.animationDuration);
1501
- }
1502
- };
1503
- ProgressBar.prototype.stopTrickling = function () {
1504
- window.clearInterval(this.trickleInterval);
1505
- delete this.trickleInterval;
1506
- };
1507
- ProgressBar.prototype.refresh = function () {
1508
- var _this = this;
1509
- requestAnimationFrame(function () {
1510
- _this.progressElement.style.width = 10 + (_this.value * 90) + "%";
1511
- });
1512
- };
1513
- ProgressBar.prototype.createStylesheetElement = function () {
1514
- var element = document.createElement("style");
1515
- element.type = "text/css";
1516
- element.textContent = ProgressBar.defaultCSS;
1517
- return element;
1518
- };
1519
- ProgressBar.prototype.createProgressElement = function () {
1520
- var element = document.createElement("div");
1521
- element.className = "turbo-progress-bar";
1522
- return element;
1523
- };
1524
- ProgressBar.animationDuration = 300;
1525
- return ProgressBar;
1526
- }());
1527
- var templateObject_1;
1528
-
1529
- var HeadSnapshot = (function (_super) {
1530
- __extends(HeadSnapshot, _super);
1531
- function HeadSnapshot() {
1532
- var _this = _super !== null && _super.apply(this, arguments) || this;
1533
- _this.detailsByOuterHTML = _this.children.reduce(function (result, element) {
1534
- var _a;
1535
- var outerHTML = element.outerHTML;
1536
- var details = outerHTML in result
1537
- ? result[outerHTML]
1538
- : {
1539
- type: elementType(element),
1540
- tracked: elementIsTracked(element),
1541
- elements: []
1542
- };
1543
- return __assign(__assign({}, result), (_a = {}, _a[outerHTML] = __assign(__assign({}, details), { elements: __spread(details.elements, [element]) }), _a));
1544
- }, {});
1545
- return _this;
1546
- }
1547
- Object.defineProperty(HeadSnapshot.prototype, "trackedElementSignature", {
1548
- get: function () {
1549
- var _this = this;
1550
- return Object.keys(this.detailsByOuterHTML)
1551
- .filter(function (outerHTML) { return _this.detailsByOuterHTML[outerHTML].tracked; })
1552
- .join("");
1553
- },
1554
- enumerable: false,
1555
- configurable: true
1556
- });
1557
- HeadSnapshot.prototype.getScriptElementsNotInSnapshot = function (snapshot) {
1558
- return this.getElementsMatchingTypeNotInSnapshot("script", snapshot);
1559
- };
1560
- HeadSnapshot.prototype.getStylesheetElementsNotInSnapshot = function (snapshot) {
1561
- return this.getElementsMatchingTypeNotInSnapshot("stylesheet", snapshot);
1562
- };
1563
- HeadSnapshot.prototype.getElementsMatchingTypeNotInSnapshot = function (matchedType, snapshot) {
1564
- var _this = this;
1565
- return Object.keys(this.detailsByOuterHTML)
1566
- .filter(function (outerHTML) { return !(outerHTML in snapshot.detailsByOuterHTML); })
1567
- .map(function (outerHTML) { return _this.detailsByOuterHTML[outerHTML]; })
1568
- .filter(function (_a) {
1569
- var type = _a.type;
1570
- return type == matchedType;
1571
- })
1572
- .map(function (_a) {
1573
- var _b = __read(_a.elements, 1), element = _b[0];
1574
- return element;
1575
- });
1576
- };
1577
- Object.defineProperty(HeadSnapshot.prototype, "provisionalElements", {
1578
- get: function () {
1579
- var _this = this;
1580
- return Object.keys(this.detailsByOuterHTML).reduce(function (result, outerHTML) {
1581
- var _a = _this.detailsByOuterHTML[outerHTML], type = _a.type, tracked = _a.tracked, elements = _a.elements;
1582
- if (type == null && !tracked) {
1583
- return __spread(result, elements);
1584
- }
1585
- else if (elements.length > 1) {
1586
- return __spread(result, elements.slice(1));
1587
- }
1588
- else {
1589
- return result;
1590
- }
1591
- }, []);
1592
- },
1593
- enumerable: false,
1594
- configurable: true
1595
- });
1596
- HeadSnapshot.prototype.getMetaValue = function (name) {
1597
- var element = this.findMetaElementByName(name);
1598
- return element
1599
- ? element.getAttribute("content")
1600
- : null;
1601
- };
1602
- HeadSnapshot.prototype.findMetaElementByName = function (name) {
1603
- var _this = this;
1604
- return Object.keys(this.detailsByOuterHTML).reduce(function (result, outerHTML) {
1605
- var _a = __read(_this.detailsByOuterHTML[outerHTML].elements, 1), element = _a[0];
1606
- return elementIsMetaElementWithName(element, name) ? element : result;
1607
- }, undefined);
1608
- };
1609
- return HeadSnapshot;
1610
- }(Snapshot));
1611
- function elementType(element) {
1612
- if (elementIsScript(element)) {
1613
- return "script";
1614
- }
1615
- else if (elementIsStylesheet(element)) {
1616
- return "stylesheet";
1617
- }
1618
- }
1619
- function elementIsTracked(element) {
1620
- return element.getAttribute("data-turbo-track") == "reload";
1621
- }
1622
- function elementIsScript(element) {
1623
- var tagName = element.tagName.toLowerCase();
1624
- return tagName == "script";
1625
- }
1626
- function elementIsStylesheet(element) {
1627
- var tagName = element.tagName.toLowerCase();
1628
- return tagName == "style" || (tagName == "link" && element.getAttribute("rel") == "stylesheet");
1629
- }
1630
- function elementIsMetaElementWithName(element, name) {
1631
- var tagName = element.tagName.toLowerCase();
1632
- return tagName == "meta" && element.getAttribute("name") == name;
1633
- }
1634
-
1635
- var PageSnapshot = (function (_super) {
1636
- __extends(PageSnapshot, _super);
1637
- function PageSnapshot(element, headSnapshot) {
1638
- var _this = _super.call(this, element) || this;
1639
- _this.headSnapshot = headSnapshot;
1640
- return _this;
1641
- }
1642
- PageSnapshot.fromHTMLString = function (html) {
1643
- if (html === void 0) { html = ""; }
1644
- return this.fromDocument(parseHTMLDocument(html));
1645
- };
1646
- PageSnapshot.fromElement = function (element) {
1647
- return this.fromDocument(element.ownerDocument);
1648
- };
1649
- PageSnapshot.fromDocument = function (_a) {
1650
- var head = _a.head, body = _a.body;
1651
- return new this(body, new HeadSnapshot(head));
1652
- };
1653
- PageSnapshot.prototype.clone = function () {
1654
- return new PageSnapshot(this.element.cloneNode(true), this.headSnapshot);
1655
- };
1656
- Object.defineProperty(PageSnapshot.prototype, "headElement", {
1657
- get: function () {
1658
- return this.headSnapshot.element;
1659
- },
1660
- enumerable: false,
1661
- configurable: true
1662
- });
1663
- Object.defineProperty(PageSnapshot.prototype, "rootLocation", {
1664
- get: function () {
1665
- var _a;
1666
- var root = (_a = this.getSetting("root")) !== null && _a !== void 0 ? _a : "/";
1667
- return expandURL(root);
1668
- },
1669
- enumerable: false,
1670
- configurable: true
1671
- });
1672
- Object.defineProperty(PageSnapshot.prototype, "cacheControlValue", {
1673
- get: function () {
1674
- return this.getSetting("cache-control");
1675
- },
1676
- enumerable: false,
1677
- configurable: true
1678
- });
1679
- Object.defineProperty(PageSnapshot.prototype, "isPreviewable", {
1680
- get: function () {
1681
- return this.cacheControlValue != "no-preview";
1682
- },
1683
- enumerable: false,
1684
- configurable: true
1685
- });
1686
- Object.defineProperty(PageSnapshot.prototype, "isCacheable", {
1687
- get: function () {
1688
- return this.cacheControlValue != "no-cache";
1689
- },
1690
- enumerable: false,
1691
- configurable: true
1692
- });
1693
- Object.defineProperty(PageSnapshot.prototype, "isVisitable", {
1694
- get: function () {
1695
- return this.getSetting("visit-control") != "reload";
1696
- },
1697
- enumerable: false,
1698
- configurable: true
1699
- });
1700
- PageSnapshot.prototype.getSetting = function (name) {
1701
- return this.headSnapshot.getMetaValue("turbo-" + name);
1702
- };
1703
- return PageSnapshot;
1704
- }(Snapshot));
1705
-
1706
- var TimingMetric;
1707
- (function (TimingMetric) {
1708
- TimingMetric["visitStart"] = "visitStart";
1709
- TimingMetric["requestStart"] = "requestStart";
1710
- TimingMetric["requestEnd"] = "requestEnd";
1711
- TimingMetric["visitEnd"] = "visitEnd";
1712
- })(TimingMetric || (TimingMetric = {}));
1713
- var VisitState;
1714
- (function (VisitState) {
1715
- VisitState["initialized"] = "initialized";
1716
- VisitState["started"] = "started";
1717
- VisitState["canceled"] = "canceled";
1718
- VisitState["failed"] = "failed";
1719
- VisitState["completed"] = "completed";
1720
- })(VisitState || (VisitState = {}));
1721
- var defaultOptions = {
1722
- action: "advance",
1723
- historyChanged: false
1724
- };
1725
- var SystemStatusCode;
1726
- (function (SystemStatusCode) {
1727
- SystemStatusCode[SystemStatusCode["networkFailure"] = 0] = "networkFailure";
1728
- SystemStatusCode[SystemStatusCode["timeoutFailure"] = -1] = "timeoutFailure";
1729
- SystemStatusCode[SystemStatusCode["contentTypeMismatch"] = -2] = "contentTypeMismatch";
1730
- })(SystemStatusCode || (SystemStatusCode = {}));
1731
- var Visit = (function () {
1732
- function Visit(delegate, location, restorationIdentifier, options) {
1733
- if (options === void 0) { options = {}; }
1734
- this.identifier = uuid();
1735
- this.timingMetrics = {};
1736
- this.followedRedirect = false;
1737
- this.historyChanged = false;
1738
- this.scrolled = false;
1739
- this.snapshotCached = false;
1740
- this.state = VisitState.initialized;
1741
- this.delegate = delegate;
1742
- this.location = location;
1743
- this.restorationIdentifier = restorationIdentifier || uuid();
1744
- var _a = __assign(__assign({}, defaultOptions), options), action = _a.action, historyChanged = _a.historyChanged, referrer = _a.referrer, snapshotHTML = _a.snapshotHTML, response = _a.response;
1745
- this.action = action;
1746
- this.historyChanged = historyChanged;
1747
- this.referrer = referrer;
1748
- this.snapshotHTML = snapshotHTML;
1749
- this.response = response;
1750
- }
1751
- Object.defineProperty(Visit.prototype, "adapter", {
1752
- get: function () {
1753
- return this.delegate.adapter;
1754
- },
1755
- enumerable: false,
1756
- configurable: true
1757
- });
1758
- Object.defineProperty(Visit.prototype, "view", {
1759
- get: function () {
1760
- return this.delegate.view;
1761
- },
1762
- enumerable: false,
1763
- configurable: true
1764
- });
1765
- Object.defineProperty(Visit.prototype, "history", {
1766
- get: function () {
1767
- return this.delegate.history;
1768
- },
1769
- enumerable: false,
1770
- configurable: true
1771
- });
1772
- Object.defineProperty(Visit.prototype, "restorationData", {
1773
- get: function () {
1774
- return this.history.getRestorationDataForIdentifier(this.restorationIdentifier);
1775
- },
1776
- enumerable: false,
1777
- configurable: true
1778
- });
1779
- Visit.prototype.start = function () {
1780
- if (this.state == VisitState.initialized) {
1781
- this.recordTimingMetric(TimingMetric.visitStart);
1782
- this.state = VisitState.started;
1783
- this.adapter.visitStarted(this);
1784
- this.delegate.visitStarted(this);
1785
- }
1786
- };
1787
- Visit.prototype.cancel = function () {
1788
- if (this.state == VisitState.started) {
1789
- if (this.request) {
1790
- this.request.cancel();
1791
- }
1792
- this.cancelRender();
1793
- this.state = VisitState.canceled;
1794
- }
1795
- };
1796
- Visit.prototype.complete = function () {
1797
- if (this.state == VisitState.started) {
1798
- this.recordTimingMetric(TimingMetric.visitEnd);
1799
- this.state = VisitState.completed;
1800
- this.adapter.visitCompleted(this);
1801
- this.delegate.visitCompleted(this);
1802
- }
1803
- };
1804
- Visit.prototype.fail = function () {
1805
- if (this.state == VisitState.started) {
1806
- this.state = VisitState.failed;
1807
- this.adapter.visitFailed(this);
1808
- }
1809
- };
1810
- Visit.prototype.changeHistory = function () {
1811
- var _a;
1812
- if (!this.historyChanged) {
1813
- var actionForHistory = this.location.href === ((_a = this.referrer) === null || _a === void 0 ? void 0 : _a.href) ? "replace" : this.action;
1814
- var method = this.getHistoryMethodForAction(actionForHistory);
1815
- this.history.update(method, this.location, this.restorationIdentifier);
1816
- this.historyChanged = true;
1817
- }
1818
- };
1819
- Visit.prototype.issueRequest = function () {
1820
- if (this.hasPreloadedResponse()) {
1821
- this.simulateRequest();
1822
- }
1823
- else if (this.shouldIssueRequest() && !this.request) {
1824
- this.request = new FetchRequest(this, FetchMethod.get, this.location);
1825
- this.request.perform();
1826
- }
1827
- };
1828
- Visit.prototype.simulateRequest = function () {
1829
- if (this.response) {
1830
- this.startRequest();
1831
- this.recordResponse();
1832
- this.finishRequest();
1833
- }
1834
- };
1835
- Visit.prototype.startRequest = function () {
1836
- this.recordTimingMetric(TimingMetric.requestStart);
1837
- this.adapter.visitRequestStarted(this);
1838
- };
1839
- Visit.prototype.recordResponse = function (response) {
1840
- if (response === void 0) { response = this.response; }
1841
- this.response = response;
1842
- if (response) {
1843
- var statusCode = response.statusCode;
1844
- if (isSuccessful(statusCode)) {
1845
- this.adapter.visitRequestCompleted(this);
1846
- }
1847
- else {
1848
- this.adapter.visitRequestFailedWithStatusCode(this, statusCode);
1849
- }
1850
- }
1851
- };
1852
- Visit.prototype.finishRequest = function () {
1853
- this.recordTimingMetric(TimingMetric.requestEnd);
1854
- this.adapter.visitRequestFinished(this);
1855
- };
1856
- Visit.prototype.loadResponse = function () {
1857
- var _this = this;
1858
- if (this.response) {
1859
- var _a = this.response, statusCode_1 = _a.statusCode, responseHTML_1 = _a.responseHTML;
1860
- this.render(function () { return __awaiter(_this, void 0, void 0, function () {
1861
- return __generator(this, function (_a) {
1862
- switch (_a.label) {
1863
- case 0:
1864
- this.cacheSnapshot();
1865
- if (!(isSuccessful(statusCode_1) && responseHTML_1 != null)) return [3, 2];
1866
- return [4, this.view.renderPage(PageSnapshot.fromHTMLString(responseHTML_1))];
1867
- case 1:
1868
- _a.sent();
1869
- this.adapter.visitRendered(this);
1870
- this.complete();
1871
- return [3, 4];
1872
- case 2: return [4, this.view.renderError(PageSnapshot.fromHTMLString(responseHTML_1))];
1873
- case 3:
1874
- _a.sent();
1875
- this.adapter.visitRendered(this);
1876
- this.fail();
1877
- _a.label = 4;
1878
- case 4: return [2];
1879
- }
1880
- });
1881
- }); });
1882
- }
1883
- };
1884
- Visit.prototype.getCachedSnapshot = function () {
1885
- var snapshot = this.view.getCachedSnapshotForLocation(this.location) || this.getPreloadedSnapshot();
1886
- if (snapshot && (!getAnchor(this.location) || snapshot.hasAnchor(getAnchor(this.location)))) {
1887
- if (this.action == "restore" || snapshot.isPreviewable) {
1888
- return snapshot;
1889
- }
1890
- }
1891
- };
1892
- Visit.prototype.getPreloadedSnapshot = function () {
1893
- if (this.snapshotHTML) {
1894
- return PageSnapshot.fromHTMLString(this.snapshotHTML);
1895
- }
1896
- };
1897
- Visit.prototype.hasCachedSnapshot = function () {
1898
- return this.getCachedSnapshot() != null;
1899
- };
1900
- Visit.prototype.loadCachedSnapshot = function () {
1901
- var _this = this;
1902
- var snapshot = this.getCachedSnapshot();
1903
- if (snapshot) {
1904
- var isPreview_1 = this.shouldIssueRequest();
1905
- this.render(function () { return __awaiter(_this, void 0, void 0, function () {
1906
- return __generator(this, function (_a) {
1907
- switch (_a.label) {
1908
- case 0:
1909
- this.cacheSnapshot();
1910
- return [4, this.view.renderPage(snapshot, isPreview_1)];
1911
- case 1:
1912
- _a.sent();
1913
- this.adapter.visitRendered(this);
1914
- if (!isPreview_1) {
1915
- this.complete();
1916
- }
1917
- return [2];
1918
- }
1919
- });
1920
- }); });
1921
- }
1922
- };
1923
- Visit.prototype.followRedirect = function () {
1924
- if (this.redirectedToLocation && !this.followedRedirect) {
1925
- this.location = this.redirectedToLocation;
1926
- this.history.replace(this.redirectedToLocation, this.restorationIdentifier);
1927
- this.followedRedirect = true;
1928
- }
1929
- };
1930
- Visit.prototype.requestStarted = function () {
1931
- this.startRequest();
1932
- };
1933
- Visit.prototype.requestPreventedHandlingResponse = function (request, response) {
1934
- };
1935
- Visit.prototype.requestSucceededWithResponse = function (request, response) {
1936
- return __awaiter(this, void 0, void 0, function () {
1937
- var responseHTML;
1938
- return __generator(this, function (_a) {
1939
- switch (_a.label) {
1940
- case 0: return [4, response.responseHTML];
1941
- case 1:
1942
- responseHTML = _a.sent();
1943
- if (responseHTML == undefined) {
1944
- this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch });
1945
- }
1946
- else {
1947
- this.redirectedToLocation = response.redirected ? response.location : undefined;
1948
- this.recordResponse({ statusCode: response.statusCode, responseHTML: responseHTML });
1949
- }
1950
- return [2];
1951
- }
1952
- });
1953
- });
1954
- };
1955
- Visit.prototype.requestFailedWithResponse = function (request, response) {
1956
- return __awaiter(this, void 0, void 0, function () {
1957
- var responseHTML;
1958
- return __generator(this, function (_a) {
1959
- switch (_a.label) {
1960
- case 0: return [4, response.responseHTML];
1961
- case 1:
1962
- responseHTML = _a.sent();
1963
- if (responseHTML == undefined) {
1964
- this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch });
1965
- }
1966
- else {
1967
- this.recordResponse({ statusCode: response.statusCode, responseHTML: responseHTML });
1968
- }
1969
- return [2];
1970
- }
1971
- });
1972
- });
1973
- };
1974
- Visit.prototype.requestErrored = function (request, error) {
1975
- this.recordResponse({ statusCode: SystemStatusCode.networkFailure });
1976
- };
1977
- Visit.prototype.requestFinished = function () {
1978
- this.finishRequest();
1979
- };
1980
- Visit.prototype.performScroll = function () {
1981
- if (!this.scrolled) {
1982
- if (this.action == "restore") {
1983
- this.scrollToRestoredPosition() || this.scrollToTop();
1984
- }
1985
- else {
1986
- this.scrollToAnchor() || this.scrollToTop();
1987
- }
1988
- this.scrolled = true;
1989
- }
1990
- };
1991
- Visit.prototype.scrollToRestoredPosition = function () {
1992
- var scrollPosition = this.restorationData.scrollPosition;
1993
- if (scrollPosition) {
1994
- this.view.scrollToPosition(scrollPosition);
1995
- return true;
1996
- }
1997
- };
1998
- Visit.prototype.scrollToAnchor = function () {
1999
- if (getAnchor(this.location)) {
2000
- this.view.scrollToAnchor(getAnchor(this.location));
2001
- return true;
2002
- }
2003
- };
2004
- Visit.prototype.scrollToTop = function () {
2005
- this.view.scrollToPosition({ x: 0, y: 0 });
2006
- };
2007
- Visit.prototype.recordTimingMetric = function (metric) {
2008
- this.timingMetrics[metric] = new Date().getTime();
2009
- };
2010
- Visit.prototype.getTimingMetrics = function () {
2011
- return __assign({}, this.timingMetrics);
2012
- };
2013
- Visit.prototype.getHistoryMethodForAction = function (action) {
2014
- switch (action) {
2015
- case "replace": return history.replaceState;
2016
- case "advance":
2017
- case "restore": return history.pushState;
2018
- }
2019
- };
2020
- Visit.prototype.hasPreloadedResponse = function () {
2021
- return typeof this.response == "object";
2022
- };
2023
- Visit.prototype.shouldIssueRequest = function () {
2024
- return this.action == "restore"
2025
- ? !this.hasCachedSnapshot()
2026
- : true;
2027
- };
2028
- Visit.prototype.cacheSnapshot = function () {
2029
- if (!this.snapshotCached) {
2030
- this.view.cacheSnapshot();
2031
- this.snapshotCached = true;
2032
- }
2033
- };
2034
- Visit.prototype.render = function (callback) {
2035
- return __awaiter(this, void 0, void 0, function () {
2036
- var _this = this;
2037
- return __generator(this, function (_a) {
2038
- switch (_a.label) {
2039
- case 0:
2040
- this.cancelRender();
2041
- return [4, new Promise(function (resolve) {
2042
- _this.frame = requestAnimationFrame(function () { return resolve(); });
2043
- })];
2044
- case 1:
2045
- _a.sent();
2046
- callback();
2047
- delete this.frame;
2048
- this.performScroll();
2049
- return [2];
2050
- }
2051
- });
2052
- });
2053
- };
2054
- Visit.prototype.cancelRender = function () {
2055
- if (this.frame) {
2056
- cancelAnimationFrame(this.frame);
2057
- delete this.frame;
2058
- }
2059
- };
2060
- return Visit;
2061
- }());
2062
- function isSuccessful(statusCode) {
2063
- return statusCode >= 200 && statusCode < 300;
2064
- }
2065
-
2066
- var BrowserAdapter = (function () {
2067
- function BrowserAdapter(session) {
2068
- var _this = this;
2069
- this.progressBar = new ProgressBar;
2070
- this.showProgressBar = function () {
2071
- _this.progressBar.show();
2072
- };
2073
- this.session = session;
2074
- }
2075
- BrowserAdapter.prototype.visitProposedToLocation = function (location, options) {
2076
- this.navigator.startVisit(location, uuid(), options);
2077
- };
2078
- BrowserAdapter.prototype.visitStarted = function (visit) {
2079
- visit.issueRequest();
2080
- visit.changeHistory();
2081
- visit.loadCachedSnapshot();
2082
- };
2083
- BrowserAdapter.prototype.visitRequestStarted = function (visit) {
2084
- this.progressBar.setValue(0);
2085
- if (visit.hasCachedSnapshot() || visit.action != "restore") {
2086
- this.showProgressBarAfterDelay();
2087
- }
2088
- else {
2089
- this.showProgressBar();
2090
- }
2091
- };
2092
- BrowserAdapter.prototype.visitRequestCompleted = function (visit) {
2093
- visit.loadResponse();
2094
- };
2095
- BrowserAdapter.prototype.visitRequestFailedWithStatusCode = function (visit, statusCode) {
2096
- switch (statusCode) {
2097
- case SystemStatusCode.networkFailure:
2098
- case SystemStatusCode.timeoutFailure:
2099
- case SystemStatusCode.contentTypeMismatch:
2100
- return this.reload();
2101
- default:
2102
- return visit.loadResponse();
2103
- }
2104
- };
2105
- BrowserAdapter.prototype.visitRequestFinished = function (visit) {
2106
- this.progressBar.setValue(1);
2107
- this.hideProgressBar();
2108
- };
2109
- BrowserAdapter.prototype.visitCompleted = function (visit) {
2110
- visit.followRedirect();
2111
- };
2112
- BrowserAdapter.prototype.pageInvalidated = function () {
2113
- this.reload();
2114
- };
2115
- BrowserAdapter.prototype.visitFailed = function (visit) {
2116
- };
2117
- BrowserAdapter.prototype.visitRendered = function (visit) {
2118
- };
2119
- BrowserAdapter.prototype.showProgressBarAfterDelay = function () {
2120
- this.progressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
2121
- };
2122
- BrowserAdapter.prototype.hideProgressBar = function () {
2123
- this.progressBar.hide();
2124
- if (this.progressBarTimeout != null) {
2125
- window.clearTimeout(this.progressBarTimeout);
2126
- delete this.progressBarTimeout;
2127
- }
2128
- };
2129
- BrowserAdapter.prototype.reload = function () {
2130
- window.location.reload();
2131
- };
2132
- Object.defineProperty(BrowserAdapter.prototype, "navigator", {
2133
- get: function () {
2134
- return this.session.navigator;
2135
- },
2136
- enumerable: false,
2137
- configurable: true
2138
- });
2139
- return BrowserAdapter;
2140
- }());
2141
-
2142
- var CacheObserver = (function () {
2143
- function CacheObserver() {
2144
- this.started = false;
2145
- }
2146
- CacheObserver.prototype.start = function () {
2147
- if (!this.started) {
2148
- this.started = true;
2149
- addEventListener("turbo:before-cache", this.removeStaleElements, false);
2150
- }
2151
- };
2152
- CacheObserver.prototype.stop = function () {
2153
- if (this.started) {
2154
- this.started = false;
2155
- removeEventListener("turbo:before-cache", this.removeStaleElements, false);
2156
- }
2157
- };
2158
- CacheObserver.prototype.removeStaleElements = function () {
2159
- var e_1, _a;
2160
- var staleElements = __spread(document.querySelectorAll('[data-turbo-cache="false"]'));
2161
- try {
2162
- for (var staleElements_1 = __values(staleElements), staleElements_1_1 = staleElements_1.next(); !staleElements_1_1.done; staleElements_1_1 = staleElements_1.next()) {
2163
- var element = staleElements_1_1.value;
2164
- element.remove();
2165
- }
2166
- }
2167
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2168
- finally {
2169
- try {
2170
- if (staleElements_1_1 && !staleElements_1_1.done && (_a = staleElements_1.return)) _a.call(staleElements_1);
2171
- }
2172
- finally { if (e_1) throw e_1.error; }
2173
- }
2174
- };
2175
- return CacheObserver;
2176
- }());
2177
-
2178
- var FormSubmitObserver = (function () {
2179
- function FormSubmitObserver(delegate) {
2180
- var _this = this;
2181
- this.started = false;
2182
- this.submitCaptured = function () {
2183
- removeEventListener("submit", _this.submitBubbled, false);
2184
- addEventListener("submit", _this.submitBubbled, false);
2185
- };
2186
- this.submitBubbled = (function (event) {
2187
- if (!event.defaultPrevented) {
2188
- var form = event.target instanceof HTMLFormElement ? event.target : undefined;
2189
- var submitter = event.submitter || undefined;
2190
- if (form) {
2191
- var method = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("formmethod")) || form.method;
2192
- if (method != "dialog" && _this.delegate.willSubmitForm(form, submitter)) {
2193
- event.preventDefault();
2194
- _this.delegate.formSubmitted(form, submitter);
2195
- }
2196
- }
2197
- }
2198
- });
2199
- this.delegate = delegate;
2200
- }
2201
- FormSubmitObserver.prototype.start = function () {
2202
- if (!this.started) {
2203
- addEventListener("submit", this.submitCaptured, true);
2204
- this.started = true;
2205
- }
2206
- };
2207
- FormSubmitObserver.prototype.stop = function () {
2208
- if (this.started) {
2209
- removeEventListener("submit", this.submitCaptured, true);
2210
- this.started = false;
2211
- }
2212
- };
2213
- return FormSubmitObserver;
2214
- }());
2215
-
2216
- var FrameRedirector = (function () {
2217
- function FrameRedirector(element) {
2218
- this.element = element;
2219
- this.linkInterceptor = new LinkInterceptor(this, element);
2220
- this.formInterceptor = new FormInterceptor(this, element);
2221
- }
2222
- FrameRedirector.prototype.start = function () {
2223
- this.linkInterceptor.start();
2224
- this.formInterceptor.start();
2225
- };
2226
- FrameRedirector.prototype.stop = function () {
2227
- this.linkInterceptor.stop();
2228
- this.formInterceptor.stop();
2229
- };
2230
- FrameRedirector.prototype.shouldInterceptLinkClick = function (element, url) {
2231
- return this.shouldRedirect(element);
2232
- };
2233
- FrameRedirector.prototype.linkClickIntercepted = function (element, url) {
2234
- var frame = this.findFrameElement(element);
2235
- if (frame) {
2236
- frame.src = url;
2237
- }
2238
- };
2239
- FrameRedirector.prototype.shouldInterceptFormSubmission = function (element, submitter) {
2240
- return this.shouldRedirect(element, submitter);
2241
- };
2242
- FrameRedirector.prototype.formSubmissionIntercepted = function (element, submitter) {
2243
- var frame = this.findFrameElement(element);
2244
- if (frame) {
2245
- frame.delegate.formSubmissionIntercepted(element, submitter);
2246
- }
2247
- };
2248
- FrameRedirector.prototype.shouldRedirect = function (element, submitter) {
2249
- var frame = this.findFrameElement(element);
2250
- return frame ? frame != element.closest("turbo-frame") : false;
2251
- };
2252
- FrameRedirector.prototype.findFrameElement = function (element) {
2253
- var id = element.getAttribute("data-turbo-frame");
2254
- if (id && id != "_top") {
2255
- var frame = this.element.querySelector("#" + id + ":not([disabled])");
2256
- if (frame instanceof FrameElement) {
2257
- return frame;
2258
- }
2259
- }
2260
- };
2261
- return FrameRedirector;
2262
- }());
2263
-
2264
- var History = (function () {
2265
- function History(delegate) {
2266
- var _this = this;
2267
- this.restorationIdentifier = uuid();
2268
- this.restorationData = {};
2269
- this.started = false;
2270
- this.pageLoaded = false;
2271
- this.onPopState = function (event) {
2272
- if (_this.shouldHandlePopState()) {
2273
- var turbo = (event.state || {}).turbo;
2274
- if (turbo) {
2275
- _this.location = new URL(window.location.href);
2276
- var restorationIdentifier = turbo.restorationIdentifier;
2277
- _this.restorationIdentifier = restorationIdentifier;
2278
- _this.delegate.historyPoppedToLocationWithRestorationIdentifier(_this.location, restorationIdentifier);
2279
- }
2280
- }
2281
- };
2282
- this.onPageLoad = function (event) { return __awaiter(_this, void 0, void 0, function () {
2283
- return __generator(this, function (_a) {
2284
- switch (_a.label) {
2285
- case 0: return [4, nextMicrotask()];
2286
- case 1:
2287
- _a.sent();
2288
- this.pageLoaded = true;
2289
- return [2];
2290
- }
2291
- });
2292
- }); };
2293
- this.delegate = delegate;
2294
- }
2295
- History.prototype.start = function () {
2296
- if (!this.started) {
2297
- addEventListener("popstate", this.onPopState, false);
2298
- addEventListener("load", this.onPageLoad, false);
2299
- this.started = true;
2300
- this.replace(new URL(window.location.href));
2301
- }
2302
- };
2303
- History.prototype.stop = function () {
2304
- if (this.started) {
2305
- removeEventListener("popstate", this.onPopState, false);
2306
- removeEventListener("load", this.onPageLoad, false);
2307
- this.started = false;
2308
- }
2309
- };
2310
- History.prototype.push = function (location, restorationIdentifier) {
2311
- this.update(history.pushState, location, restorationIdentifier);
2312
- };
2313
- History.prototype.replace = function (location, restorationIdentifier) {
2314
- this.update(history.replaceState, location, restorationIdentifier);
2315
- };
2316
- History.prototype.update = function (method, location, restorationIdentifier) {
2317
- if (restorationIdentifier === void 0) { restorationIdentifier = uuid(); }
2318
- var state = { turbo: { restorationIdentifier: restorationIdentifier } };
2319
- method.call(history, state, "", location.href);
2320
- this.location = location;
2321
- this.restorationIdentifier = restorationIdentifier;
2322
- };
2323
- History.prototype.getRestorationDataForIdentifier = function (restorationIdentifier) {
2324
- return this.restorationData[restorationIdentifier] || {};
2325
- };
2326
- History.prototype.updateRestorationData = function (additionalData) {
2327
- var restorationIdentifier = this.restorationIdentifier;
2328
- var restorationData = this.restorationData[restorationIdentifier];
2329
- this.restorationData[restorationIdentifier] = __assign(__assign({}, restorationData), additionalData);
2330
- };
2331
- History.prototype.assumeControlOfScrollRestoration = function () {
2332
- var _a;
2333
- if (!this.previousScrollRestoration) {
2334
- this.previousScrollRestoration = (_a = history.scrollRestoration) !== null && _a !== void 0 ? _a : "auto";
2335
- history.scrollRestoration = "manual";
2336
- }
2337
- };
2338
- History.prototype.relinquishControlOfScrollRestoration = function () {
2339
- if (this.previousScrollRestoration) {
2340
- history.scrollRestoration = this.previousScrollRestoration;
2341
- delete this.previousScrollRestoration;
2342
- }
2343
- };
2344
- History.prototype.shouldHandlePopState = function () {
2345
- return this.pageIsLoaded();
2346
- };
2347
- History.prototype.pageIsLoaded = function () {
2348
- return this.pageLoaded || document.readyState == "complete";
2349
- };
2350
- return History;
2351
- }());
2352
-
2353
- var LinkClickObserver = (function () {
2354
- function LinkClickObserver(delegate) {
2355
- var _this = this;
2356
- this.started = false;
2357
- this.clickCaptured = function () {
2358
- removeEventListener("click", _this.clickBubbled, false);
2359
- addEventListener("click", _this.clickBubbled, false);
2360
- };
2361
- this.clickBubbled = function (event) {
2362
- if (_this.clickEventIsSignificant(event)) {
2363
- var link = _this.findLinkFromClickTarget(event.target);
2364
- if (link) {
2365
- var location_1 = _this.getLocationForLink(link);
2366
- if (_this.delegate.willFollowLinkToLocation(link, location_1)) {
2367
- event.preventDefault();
2368
- _this.delegate.followedLinkToLocation(link, location_1);
2369
- }
2370
- }
2371
- }
2372
- };
2373
- this.delegate = delegate;
2374
- }
2375
- LinkClickObserver.prototype.start = function () {
2376
- if (!this.started) {
2377
- addEventListener("click", this.clickCaptured, true);
2378
- this.started = true;
2379
- }
2380
- };
2381
- LinkClickObserver.prototype.stop = function () {
2382
- if (this.started) {
2383
- removeEventListener("click", this.clickCaptured, true);
2384
- this.started = false;
2385
- }
2386
- };
2387
- LinkClickObserver.prototype.clickEventIsSignificant = function (event) {
2388
- return !((event.target && event.target.isContentEditable)
2389
- || event.defaultPrevented
2390
- || event.which > 1
2391
- || event.altKey
2392
- || event.ctrlKey
2393
- || event.metaKey
2394
- || event.shiftKey);
2395
- };
2396
- LinkClickObserver.prototype.findLinkFromClickTarget = function (target) {
2397
- if (target instanceof Element) {
2398
- return target.closest("a[href]:not([target^=_]):not([download])");
2399
- }
2400
- };
2401
- LinkClickObserver.prototype.getLocationForLink = function (link) {
2402
- return expandURL(link.getAttribute("href") || "");
2403
- };
2404
- return LinkClickObserver;
2405
- }());
2406
-
2407
- function isAction(action) {
2408
- return action == "advance" || action == "replace" || action == "restore";
2409
- }
2410
-
2411
- var Navigator = (function () {
2412
- function Navigator(delegate) {
2413
- this.delegate = delegate;
2414
- }
2415
- Navigator.prototype.proposeVisit = function (location, options) {
2416
- if (options === void 0) { options = {}; }
2417
- if (this.delegate.allowsVisitingLocation(location)) {
2418
- this.delegate.visitProposedToLocation(location, options);
2419
- }
2420
- };
2421
- Navigator.prototype.startVisit = function (locatable, restorationIdentifier, options) {
2422
- if (options === void 0) { options = {}; }
2423
- this.stop();
2424
- this.currentVisit = new Visit(this, expandURL(locatable), restorationIdentifier, __assign({ referrer: this.location }, options));
2425
- this.currentVisit.start();
2426
- };
2427
- Navigator.prototype.submitForm = function (form, submitter) {
2428
- this.stop();
2429
- this.formSubmission = new FormSubmission(this, form, submitter, true);
2430
- if (this.formSubmission.isIdempotent) {
2431
- this.proposeVisit(this.formSubmission.fetchRequest.url, { action: this.getActionForFormSubmission(this.formSubmission) });
2432
- }
2433
- else {
2434
- this.formSubmission.start();
2435
- }
2436
- };
2437
- Navigator.prototype.stop = function () {
2438
- if (this.formSubmission) {
2439
- this.formSubmission.stop();
2440
- delete this.formSubmission;
2441
- }
2442
- if (this.currentVisit) {
2443
- this.currentVisit.cancel();
2444
- delete this.currentVisit;
2445
- }
2446
- };
2447
- Object.defineProperty(Navigator.prototype, "adapter", {
2448
- get: function () {
2449
- return this.delegate.adapter;
2450
- },
2451
- enumerable: false,
2452
- configurable: true
2453
- });
2454
- Object.defineProperty(Navigator.prototype, "view", {
2455
- get: function () {
2456
- return this.delegate.view;
2457
- },
2458
- enumerable: false,
2459
- configurable: true
2460
- });
2461
- Object.defineProperty(Navigator.prototype, "history", {
2462
- get: function () {
2463
- return this.delegate.history;
2464
- },
2465
- enumerable: false,
2466
- configurable: true
2467
- });
2468
- Navigator.prototype.formSubmissionStarted = function (formSubmission) {
2469
- };
2470
- Navigator.prototype.formSubmissionSucceededWithResponse = function (formSubmission, fetchResponse) {
2471
- return __awaiter(this, void 0, void 0, function () {
2472
- var responseHTML, statusCode, visitOptions;
2473
- return __generator(this, function (_a) {
2474
- switch (_a.label) {
2475
- case 0:
2476
- if (!(formSubmission == this.formSubmission)) return [3, 2];
2477
- return [4, fetchResponse.responseHTML];
2478
- case 1:
2479
- responseHTML = _a.sent();
2480
- if (responseHTML) {
2481
- if (formSubmission.method != FetchMethod.get) {
2482
- this.view.clearSnapshotCache();
2483
- }
2484
- statusCode = fetchResponse.statusCode;
2485
- visitOptions = { response: { statusCode: statusCode, responseHTML: responseHTML } };
2486
- this.proposeVisit(fetchResponse.location, visitOptions);
2487
- }
2488
- _a.label = 2;
2489
- case 2: return [2];
2490
- }
2491
- });
2492
- });
2493
- };
2494
- Navigator.prototype.formSubmissionFailedWithResponse = function (formSubmission, fetchResponse) {
2495
- return __awaiter(this, void 0, void 0, function () {
2496
- var responseHTML, snapshot;
2497
- return __generator(this, function (_a) {
2498
- switch (_a.label) {
2499
- case 0: return [4, fetchResponse.responseHTML];
2500
- case 1:
2501
- responseHTML = _a.sent();
2502
- if (!responseHTML) return [3, 3];
2503
- snapshot = PageSnapshot.fromHTMLString(responseHTML);
2504
- return [4, this.view.renderPage(snapshot)];
2505
- case 2:
2506
- _a.sent();
2507
- this.view.clearSnapshotCache();
2508
- _a.label = 3;
2509
- case 3: return [2];
2510
- }
2511
- });
2512
- });
2513
- };
2514
- Navigator.prototype.formSubmissionErrored = function (formSubmission, error) {
2515
- console.error(error);
2516
- };
2517
- Navigator.prototype.formSubmissionFinished = function (formSubmission) {
2518
- };
2519
- Navigator.prototype.visitStarted = function (visit) {
2520
- this.delegate.visitStarted(visit);
2521
- };
2522
- Navigator.prototype.visitCompleted = function (visit) {
2523
- this.delegate.visitCompleted(visit);
2524
- };
2525
- Object.defineProperty(Navigator.prototype, "location", {
2526
- get: function () {
2527
- return this.history.location;
2528
- },
2529
- enumerable: false,
2530
- configurable: true
2531
- });
2532
- Object.defineProperty(Navigator.prototype, "restorationIdentifier", {
2533
- get: function () {
2534
- return this.history.restorationIdentifier;
2535
- },
2536
- enumerable: false,
2537
- configurable: true
2538
- });
2539
- Navigator.prototype.getActionForFormSubmission = function (formSubmission) {
2540
- var formElement = formSubmission.formElement, submitter = formSubmission.submitter;
2541
- var action = (submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute("data-turbo-action")) || formElement.getAttribute("data-turbo-action");
2542
- return isAction(action) ? action : "advance";
2543
- };
2544
- return Navigator;
2545
- }());
2546
-
2547
- var PageStage;
2548
- (function (PageStage) {
2549
- PageStage[PageStage["initial"] = 0] = "initial";
2550
- PageStage[PageStage["loading"] = 1] = "loading";
2551
- PageStage[PageStage["interactive"] = 2] = "interactive";
2552
- PageStage[PageStage["complete"] = 3] = "complete";
2553
- })(PageStage || (PageStage = {}));
2554
- var PageObserver = (function () {
2555
- function PageObserver(delegate) {
2556
- var _this = this;
2557
- this.stage = PageStage.initial;
2558
- this.started = false;
2559
- this.interpretReadyState = function () {
2560
- var readyState = _this.readyState;
2561
- if (readyState == "interactive") {
2562
- _this.pageIsInteractive();
2563
- }
2564
- else if (readyState == "complete") {
2565
- _this.pageIsComplete();
2566
- }
2567
- };
2568
- this.pageWillUnload = function () {
2569
- _this.delegate.pageWillUnload();
2570
- };
2571
- this.delegate = delegate;
2572
- }
2573
- PageObserver.prototype.start = function () {
2574
- if (!this.started) {
2575
- if (this.stage == PageStage.initial) {
2576
- this.stage = PageStage.loading;
2577
- }
2578
- document.addEventListener("readystatechange", this.interpretReadyState, false);
2579
- addEventListener("pagehide", this.pageWillUnload, false);
2580
- this.started = true;
2581
- }
2582
- };
2583
- PageObserver.prototype.stop = function () {
2584
- if (this.started) {
2585
- document.removeEventListener("readystatechange", this.interpretReadyState, false);
2586
- removeEventListener("pagehide", this.pageWillUnload, false);
2587
- this.started = false;
2588
- }
2589
- };
2590
- PageObserver.prototype.pageIsInteractive = function () {
2591
- if (this.stage == PageStage.loading) {
2592
- this.stage = PageStage.interactive;
2593
- this.delegate.pageBecameInteractive();
2594
- }
2595
- };
2596
- PageObserver.prototype.pageIsComplete = function () {
2597
- this.pageIsInteractive();
2598
- if (this.stage == PageStage.interactive) {
2599
- this.stage = PageStage.complete;
2600
- this.delegate.pageLoaded();
2601
- }
2602
- };
2603
- Object.defineProperty(PageObserver.prototype, "readyState", {
2604
- get: function () {
2605
- return document.readyState;
2606
- },
2607
- enumerable: false,
2608
- configurable: true
2609
- });
2610
- return PageObserver;
2611
- }());
2612
-
2613
- var ScrollObserver = (function () {
2614
- function ScrollObserver(delegate) {
2615
- var _this = this;
2616
- this.started = false;
2617
- this.onScroll = function () {
2618
- _this.updatePosition({ x: window.pageXOffset, y: window.pageYOffset });
2619
- };
2620
- this.delegate = delegate;
2621
- }
2622
- ScrollObserver.prototype.start = function () {
2623
- if (!this.started) {
2624
- addEventListener("scroll", this.onScroll, false);
2625
- this.onScroll();
2626
- this.started = true;
2627
- }
2628
- };
2629
- ScrollObserver.prototype.stop = function () {
2630
- if (this.started) {
2631
- removeEventListener("scroll", this.onScroll, false);
2632
- this.started = false;
2633
- }
2634
- };
2635
- ScrollObserver.prototype.updatePosition = function (position) {
2636
- this.delegate.scrollPositionChanged(position);
2637
- };
2638
- return ScrollObserver;
2639
- }());
2640
-
2641
- var StreamObserver = (function () {
2642
- function StreamObserver(delegate) {
2643
- var _this = this;
2644
- this.sources = new Set;
2645
- this.started = false;
2646
- this.inspectFetchResponse = (function (event) {
2647
- var response = fetchResponseFromEvent(event);
2648
- if (response && fetchResponseIsStream(response)) {
2649
- event.preventDefault();
2650
- _this.receiveMessageResponse(response);
2651
- }
2652
- });
2653
- this.receiveMessageEvent = function (event) {
2654
- if (_this.started && typeof event.data == "string") {
2655
- _this.receiveMessageHTML(event.data);
2656
- }
2657
- };
2658
- this.delegate = delegate;
2659
- }
2660
- StreamObserver.prototype.start = function () {
2661
- if (!this.started) {
2662
- this.started = true;
2663
- addEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false);
2664
- }
2665
- };
2666
- StreamObserver.prototype.stop = function () {
2667
- if (this.started) {
2668
- this.started = false;
2669
- removeEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false);
2670
- }
2671
- };
2672
- StreamObserver.prototype.connectStreamSource = function (source) {
2673
- if (!this.streamSourceIsConnected(source)) {
2674
- this.sources.add(source);
2675
- source.addEventListener("message", this.receiveMessageEvent, false);
2676
- }
2677
- };
2678
- StreamObserver.prototype.disconnectStreamSource = function (source) {
2679
- if (this.streamSourceIsConnected(source)) {
2680
- this.sources.delete(source);
2681
- source.removeEventListener("message", this.receiveMessageEvent, false);
2682
- }
2683
- };
2684
- StreamObserver.prototype.streamSourceIsConnected = function (source) {
2685
- return this.sources.has(source);
2686
- };
2687
- StreamObserver.prototype.receiveMessageResponse = function (response) {
2688
- return __awaiter(this, void 0, void 0, function () {
2689
- var html;
2690
- return __generator(this, function (_a) {
2691
- switch (_a.label) {
2692
- case 0: return [4, response.responseHTML];
2693
- case 1:
2694
- html = _a.sent();
2695
- if (html) {
2696
- this.receiveMessageHTML(html);
2697
- }
2698
- return [2];
2699
- }
2700
- });
2701
- });
2702
- };
2703
- StreamObserver.prototype.receiveMessageHTML = function (html) {
2704
- this.delegate.receivedMessageFromStream(new StreamMessage(html));
2705
- };
2706
- return StreamObserver;
2707
- }());
2708
- function fetchResponseFromEvent(event) {
2709
- var _a;
2710
- var fetchResponse = (_a = event.detail) === null || _a === void 0 ? void 0 : _a.fetchResponse;
2711
- if (fetchResponse instanceof FetchResponse) {
2712
- return fetchResponse;
2713
- }
2714
- }
2715
- function fetchResponseIsStream(response) {
2716
- var _a;
2717
- var contentType = (_a = response.contentType) !== null && _a !== void 0 ? _a : "";
2718
- return contentType.startsWith(StreamMessage.contentType);
2719
- }
2720
-
2721
- var ErrorRenderer = (function (_super) {
2722
- __extends(ErrorRenderer, _super);
2723
- function ErrorRenderer() {
2724
- return _super !== null && _super.apply(this, arguments) || this;
2725
- }
2726
- ErrorRenderer.prototype.render = function () {
2727
- return __awaiter(this, void 0, void 0, function () {
2728
- return __generator(this, function (_a) {
2729
- this.replaceHeadAndBody();
2730
- this.activateScriptElements();
2731
- return [2];
2732
- });
2733
- });
2734
- };
2735
- ErrorRenderer.prototype.replaceHeadAndBody = function () {
2736
- var documentElement = document.documentElement, head = document.head, body = document.body;
2737
- documentElement.replaceChild(this.newHead, head);
2738
- documentElement.replaceChild(this.newElement, body);
2739
- };
2740
- ErrorRenderer.prototype.activateScriptElements = function () {
2741
- var e_1, _a;
2742
- try {
2743
- for (var _b = __values(this.scriptElements), _c = _b.next(); !_c.done; _c = _b.next()) {
2744
- var replaceableElement = _c.value;
2745
- var parentNode = replaceableElement.parentNode;
2746
- if (parentNode) {
2747
- var element = this.createScriptElement(replaceableElement);
2748
- parentNode.replaceChild(element, replaceableElement);
2749
- }
2750
- }
2751
- }
2752
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2753
- finally {
2754
- try {
2755
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2756
- }
2757
- finally { if (e_1) throw e_1.error; }
2758
- }
2759
- };
2760
- Object.defineProperty(ErrorRenderer.prototype, "newHead", {
2761
- get: function () {
2762
- return this.newSnapshot.headSnapshot.element;
2763
- },
2764
- enumerable: false,
2765
- configurable: true
2766
- });
2767
- Object.defineProperty(ErrorRenderer.prototype, "scriptElements", {
2768
- get: function () {
2769
- return __spread(document.documentElement.querySelectorAll("script"));
2770
- },
2771
- enumerable: false,
2772
- configurable: true
2773
- });
2774
- return ErrorRenderer;
2775
- }(Renderer));
2776
-
2777
- var PageRenderer = (function (_super) {
2778
- __extends(PageRenderer, _super);
2779
- function PageRenderer() {
2780
- return _super !== null && _super.apply(this, arguments) || this;
2781
- }
2782
- Object.defineProperty(PageRenderer.prototype, "shouldRender", {
2783
- get: function () {
2784
- return this.newSnapshot.isVisitable && this.trackedElementsAreIdentical;
2785
- },
2786
- enumerable: false,
2787
- configurable: true
2788
- });
2789
- PageRenderer.prototype.prepareToRender = function () {
2790
- this.mergeHead();
2791
- };
2792
- PageRenderer.prototype.render = function () {
2793
- return __awaiter(this, void 0, void 0, function () {
2794
- return __generator(this, function (_a) {
2795
- this.replaceBody();
2796
- return [2];
2797
- });
2798
- });
2799
- };
2800
- PageRenderer.prototype.finishRendering = function () {
2801
- _super.prototype.finishRendering.call(this);
2802
- if (!this.isPreview) {
2803
- this.focusFirstAutofocusableElement();
2804
- }
2805
- };
2806
- Object.defineProperty(PageRenderer.prototype, "currentHeadSnapshot", {
2807
- get: function () {
2808
- return this.currentSnapshot.headSnapshot;
2809
- },
2810
- enumerable: false,
2811
- configurable: true
2812
- });
2813
- Object.defineProperty(PageRenderer.prototype, "newHeadSnapshot", {
2814
- get: function () {
2815
- return this.newSnapshot.headSnapshot;
2816
- },
2817
- enumerable: false,
2818
- configurable: true
2819
- });
2820
- Object.defineProperty(PageRenderer.prototype, "newElement", {
2821
- get: function () {
2822
- return this.newSnapshot.element;
2823
- },
2824
- enumerable: false,
2825
- configurable: true
2826
- });
2827
- PageRenderer.prototype.mergeHead = function () {
2828
- this.copyNewHeadStylesheetElements();
2829
- this.copyNewHeadScriptElements();
2830
- this.removeCurrentHeadProvisionalElements();
2831
- this.copyNewHeadProvisionalElements();
2832
- };
2833
- PageRenderer.prototype.replaceBody = function () {
2834
- var _this = this;
2835
- this.preservingPermanentElements(function () {
2836
- _this.activateNewBody();
2837
- _this.assignNewBody();
2838
- });
2839
- };
2840
- Object.defineProperty(PageRenderer.prototype, "trackedElementsAreIdentical", {
2841
- get: function () {
2842
- return this.currentHeadSnapshot.trackedElementSignature == this.newHeadSnapshot.trackedElementSignature;
2843
- },
2844
- enumerable: false,
2845
- configurable: true
2846
- });
2847
- PageRenderer.prototype.copyNewHeadStylesheetElements = function () {
2848
- var e_1, _a;
2849
- try {
2850
- for (var _b = __values(this.newHeadStylesheetElements), _c = _b.next(); !_c.done; _c = _b.next()) {
2851
- var element = _c.value;
2852
- document.head.appendChild(element);
2853
- }
2854
- }
2855
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2856
- finally {
2857
- try {
2858
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2859
- }
2860
- finally { if (e_1) throw e_1.error; }
2861
- }
2862
- };
2863
- PageRenderer.prototype.copyNewHeadScriptElements = function () {
2864
- var e_2, _a;
2865
- try {
2866
- for (var _b = __values(this.newHeadScriptElements), _c = _b.next(); !_c.done; _c = _b.next()) {
2867
- var element = _c.value;
2868
- document.head.appendChild(this.createScriptElement(element));
2869
- }
2870
- }
2871
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2872
- finally {
2873
- try {
2874
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2875
- }
2876
- finally { if (e_2) throw e_2.error; }
2877
- }
2878
- };
2879
- PageRenderer.prototype.removeCurrentHeadProvisionalElements = function () {
2880
- var e_3, _a;
2881
- try {
2882
- for (var _b = __values(this.currentHeadProvisionalElements), _c = _b.next(); !_c.done; _c = _b.next()) {
2883
- var element = _c.value;
2884
- document.head.removeChild(element);
2885
- }
2886
- }
2887
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
2888
- finally {
2889
- try {
2890
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2891
- }
2892
- finally { if (e_3) throw e_3.error; }
2893
- }
2894
- };
2895
- PageRenderer.prototype.copyNewHeadProvisionalElements = function () {
2896
- var e_4, _a;
2897
- try {
2898
- for (var _b = __values(this.newHeadProvisionalElements), _c = _b.next(); !_c.done; _c = _b.next()) {
2899
- var element = _c.value;
2900
- document.head.appendChild(element);
2901
- }
2902
- }
2903
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
2904
- finally {
2905
- try {
2906
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2907
- }
2908
- finally { if (e_4) throw e_4.error; }
2909
- }
2910
- };
2911
- PageRenderer.prototype.activateNewBody = function () {
2912
- document.adoptNode(this.newElement);
2913
- this.activateNewBodyScriptElements();
2914
- };
2915
- PageRenderer.prototype.activateNewBodyScriptElements = function () {
2916
- var e_5, _a;
2917
- try {
2918
- for (var _b = __values(this.newBodyScriptElements), _c = _b.next(); !_c.done; _c = _b.next()) {
2919
- var inertScriptElement = _c.value;
2920
- var activatedScriptElement = this.createScriptElement(inertScriptElement);
2921
- inertScriptElement.replaceWith(activatedScriptElement);
2922
- }
2923
- }
2924
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
2925
- finally {
2926
- try {
2927
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2928
- }
2929
- finally { if (e_5) throw e_5.error; }
2930
- }
2931
- };
2932
- PageRenderer.prototype.assignNewBody = function () {
2933
- if (document.body && this.newElement instanceof HTMLBodyElement) {
2934
- document.body.replaceWith(this.newElement);
2935
- }
2936
- else {
2937
- document.documentElement.appendChild(this.newElement);
2938
- }
2939
- };
2940
- Object.defineProperty(PageRenderer.prototype, "newHeadStylesheetElements", {
2941
- get: function () {
2942
- return this.newHeadSnapshot.getStylesheetElementsNotInSnapshot(this.currentHeadSnapshot);
2943
- },
2944
- enumerable: false,
2945
- configurable: true
2946
- });
2947
- Object.defineProperty(PageRenderer.prototype, "newHeadScriptElements", {
2948
- get: function () {
2949
- return this.newHeadSnapshot.getScriptElementsNotInSnapshot(this.currentHeadSnapshot);
2950
- },
2951
- enumerable: false,
2952
- configurable: true
2953
- });
2954
- Object.defineProperty(PageRenderer.prototype, "currentHeadProvisionalElements", {
2955
- get: function () {
2956
- return this.currentHeadSnapshot.provisionalElements;
2957
- },
2958
- enumerable: false,
2959
- configurable: true
2960
- });
2961
- Object.defineProperty(PageRenderer.prototype, "newHeadProvisionalElements", {
2962
- get: function () {
2963
- return this.newHeadSnapshot.provisionalElements;
2964
- },
2965
- enumerable: false,
2966
- configurable: true
2967
- });
2968
- Object.defineProperty(PageRenderer.prototype, "newBodyScriptElements", {
2969
- get: function () {
2970
- return __spread(this.newElement.querySelectorAll("script"));
2971
- },
2972
- enumerable: false,
2973
- configurable: true
2974
- });
2975
- return PageRenderer;
2976
- }(Renderer));
2977
-
2978
- var SnapshotCache = (function () {
2979
- function SnapshotCache(size) {
2980
- this.keys = [];
2981
- this.snapshots = {};
2982
- this.size = size;
2983
- }
2984
- SnapshotCache.prototype.has = function (location) {
2985
- return toCacheKey(location) in this.snapshots;
2986
- };
2987
- SnapshotCache.prototype.get = function (location) {
2988
- if (this.has(location)) {
2989
- var snapshot = this.read(location);
2990
- this.touch(location);
2991
- return snapshot;
2992
- }
2993
- };
2994
- SnapshotCache.prototype.put = function (location, snapshot) {
2995
- this.write(location, snapshot);
2996
- this.touch(location);
2997
- return snapshot;
2998
- };
2999
- SnapshotCache.prototype.clear = function () {
3000
- this.snapshots = {};
3001
- };
3002
- SnapshotCache.prototype.read = function (location) {
3003
- return this.snapshots[toCacheKey(location)];
3004
- };
3005
- SnapshotCache.prototype.write = function (location, snapshot) {
3006
- this.snapshots[toCacheKey(location)] = snapshot;
3007
- };
3008
- SnapshotCache.prototype.touch = function (location) {
3009
- var key = toCacheKey(location);
3010
- var index = this.keys.indexOf(key);
3011
- if (index > -1)
3012
- this.keys.splice(index, 1);
3013
- this.keys.unshift(key);
3014
- this.trim();
3015
- };
3016
- SnapshotCache.prototype.trim = function () {
3017
- var e_1, _a;
3018
- try {
3019
- for (var _b = __values(this.keys.splice(this.size)), _c = _b.next(); !_c.done; _c = _b.next()) {
3020
- var key = _c.value;
3021
- delete this.snapshots[key];
3022
- }
3023
- }
3024
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3025
- finally {
3026
- try {
3027
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3028
- }
3029
- finally { if (e_1) throw e_1.error; }
3030
- }
3031
- };
3032
- return SnapshotCache;
3033
- }());
3034
-
3035
- var PageView = (function (_super) {
3036
- __extends(PageView, _super);
3037
- function PageView() {
3038
- var _this = _super !== null && _super.apply(this, arguments) || this;
3039
- _this.snapshotCache = new SnapshotCache(10);
3040
- _this.lastRenderedLocation = new URL(location.href);
3041
- return _this;
3042
- }
3043
- PageView.prototype.renderPage = function (snapshot, isPreview) {
3044
- if (isPreview === void 0) { isPreview = false; }
3045
- var renderer = new PageRenderer(this.snapshot, snapshot, isPreview);
3046
- return this.render(renderer);
3047
- };
3048
- PageView.prototype.renderError = function (snapshot) {
3049
- var renderer = new ErrorRenderer(this.snapshot, snapshot, false);
3050
- this.render(renderer);
3051
- };
3052
- PageView.prototype.clearSnapshotCache = function () {
3053
- this.snapshotCache.clear();
3054
- };
3055
- PageView.prototype.cacheSnapshot = function () {
3056
- return __awaiter(this, void 0, void 0, function () {
3057
- var _a, snapshot, location_1;
3058
- return __generator(this, function (_b) {
3059
- switch (_b.label) {
3060
- case 0:
3061
- if (!this.shouldCacheSnapshot) return [3, 2];
3062
- this.delegate.viewWillCacheSnapshot();
3063
- _a = this, snapshot = _a.snapshot, location_1 = _a.lastRenderedLocation;
3064
- return [4, nextEventLoopTick()];
3065
- case 1:
3066
- _b.sent();
3067
- this.snapshotCache.put(location_1, snapshot.clone());
3068
- _b.label = 2;
3069
- case 2: return [2];
3070
- }
3071
- });
3072
- });
3073
- };
3074
- PageView.prototype.getCachedSnapshotForLocation = function (location) {
3075
- return this.snapshotCache.get(location);
3076
- };
3077
- Object.defineProperty(PageView.prototype, "snapshot", {
3078
- get: function () {
3079
- return PageSnapshot.fromElement(this.element);
3080
- },
3081
- enumerable: false,
3082
- configurable: true
3083
- });
3084
- Object.defineProperty(PageView.prototype, "shouldCacheSnapshot", {
3085
- get: function () {
3086
- return this.snapshot.isCacheable;
3087
- },
3088
- enumerable: false,
3089
- configurable: true
3090
- });
3091
- return PageView;
3092
- }(View));
3093
-
3094
- var Session = (function () {
3095
- function Session() {
3096
- this.navigator = new Navigator(this);
3097
- this.history = new History(this);
3098
- this.view = new PageView(this, document.documentElement);
3099
- this.adapter = new BrowserAdapter(this);
3100
- this.pageObserver = new PageObserver(this);
3101
- this.cacheObserver = new CacheObserver();
3102
- this.linkClickObserver = new LinkClickObserver(this);
3103
- this.formSubmitObserver = new FormSubmitObserver(this);
3104
- this.scrollObserver = new ScrollObserver(this);
3105
- this.streamObserver = new StreamObserver(this);
3106
- this.frameRedirector = new FrameRedirector(document.documentElement);
3107
- this.enabled = true;
3108
- this.progressBarDelay = 500;
3109
- this.started = false;
3110
- }
3111
- Session.prototype.start = function () {
3112
- if (!this.started) {
3113
- this.pageObserver.start();
3114
- this.cacheObserver.start();
3115
- this.linkClickObserver.start();
3116
- this.formSubmitObserver.start();
3117
- this.scrollObserver.start();
3118
- this.streamObserver.start();
3119
- this.frameRedirector.start();
3120
- this.history.start();
3121
- this.started = true;
3122
- this.enabled = true;
3123
- }
3124
- };
3125
- Session.prototype.disable = function () {
3126
- this.enabled = false;
3127
- };
3128
- Session.prototype.stop = function () {
3129
- if (this.started) {
3130
- this.pageObserver.stop();
3131
- this.cacheObserver.stop();
3132
- this.linkClickObserver.stop();
3133
- this.formSubmitObserver.stop();
3134
- this.scrollObserver.stop();
3135
- this.streamObserver.stop();
3136
- this.frameRedirector.stop();
3137
- this.history.stop();
3138
- this.started = false;
3139
- }
3140
- };
3141
- Session.prototype.registerAdapter = function (adapter) {
3142
- this.adapter = adapter;
3143
- };
3144
- Session.prototype.visit = function (location, options) {
3145
- if (options === void 0) { options = {}; }
3146
- this.navigator.proposeVisit(expandURL(location), options);
3147
- };
3148
- Session.prototype.connectStreamSource = function (source) {
3149
- this.streamObserver.connectStreamSource(source);
3150
- };
3151
- Session.prototype.disconnectStreamSource = function (source) {
3152
- this.streamObserver.disconnectStreamSource(source);
3153
- };
3154
- Session.prototype.renderStreamMessage = function (message) {
3155
- document.documentElement.appendChild(StreamMessage.wrap(message).fragment);
3156
- };
3157
- Session.prototype.clearCache = function () {
3158
- this.view.clearSnapshotCache();
3159
- };
3160
- Session.prototype.setProgressBarDelay = function (delay) {
3161
- this.progressBarDelay = delay;
3162
- };
3163
- Object.defineProperty(Session.prototype, "location", {
3164
- get: function () {
3165
- return this.history.location;
3166
- },
3167
- enumerable: false,
3168
- configurable: true
3169
- });
3170
- Object.defineProperty(Session.prototype, "restorationIdentifier", {
3171
- get: function () {
3172
- return this.history.restorationIdentifier;
3173
- },
3174
- enumerable: false,
3175
- configurable: true
3176
- });
3177
- Session.prototype.historyPoppedToLocationWithRestorationIdentifier = function (location) {
3178
- if (this.enabled) {
3179
- this.navigator.proposeVisit(location, { action: "restore", historyChanged: true });
3180
- }
3181
- else {
3182
- this.adapter.pageInvalidated();
3183
- }
3184
- };
3185
- Session.prototype.scrollPositionChanged = function (position) {
3186
- this.history.updateRestorationData({ scrollPosition: position });
3187
- };
3188
- Session.prototype.willFollowLinkToLocation = function (link, location) {
3189
- return elementIsNavigable(link)
3190
- && this.locationIsVisitable(location)
3191
- && this.applicationAllowsFollowingLinkToLocation(link, location);
3192
- };
3193
- Session.prototype.followedLinkToLocation = function (link, location) {
3194
- var action = this.getActionForLink(link);
3195
- this.visit(location.href, { action: action });
3196
- };
3197
- Session.prototype.allowsVisitingLocation = function (location) {
3198
- return this.applicationAllowsVisitingLocation(location);
3199
- };
3200
- Session.prototype.visitProposedToLocation = function (location, options) {
3201
- extendURLWithDeprecatedProperties(location);
3202
- this.adapter.visitProposedToLocation(location, options);
3203
- };
3204
- Session.prototype.visitStarted = function (visit) {
3205
- extendURLWithDeprecatedProperties(visit.location);
3206
- this.notifyApplicationAfterVisitingLocation(visit.location);
3207
- };
3208
- Session.prototype.visitCompleted = function (visit) {
3209
- this.notifyApplicationAfterPageLoad(visit.getTimingMetrics());
3210
- };
3211
- Session.prototype.willSubmitForm = function (form, submitter) {
3212
- return elementIsNavigable(form) && elementIsNavigable(submitter);
3213
- };
3214
- Session.prototype.formSubmitted = function (form, submitter) {
3215
- this.navigator.submitForm(form, submitter);
3216
- };
3217
- Session.prototype.pageBecameInteractive = function () {
3218
- this.view.lastRenderedLocation = this.location;
3219
- this.notifyApplicationAfterPageLoad();
3220
- };
3221
- Session.prototype.pageLoaded = function () {
3222
- this.history.assumeControlOfScrollRestoration();
3223
- };
3224
- Session.prototype.pageWillUnload = function () {
3225
- this.history.relinquishControlOfScrollRestoration();
3226
- };
3227
- Session.prototype.receivedMessageFromStream = function (message) {
3228
- this.renderStreamMessage(message);
3229
- };
3230
- Session.prototype.viewWillCacheSnapshot = function () {
3231
- this.notifyApplicationBeforeCachingSnapshot();
3232
- };
3233
- Session.prototype.viewWillRenderSnapshot = function (_a, isPreview) {
3234
- var element = _a.element;
3235
- this.notifyApplicationBeforeRender(element);
3236
- };
3237
- Session.prototype.viewRenderedSnapshot = function (snapshot, isPreview) {
3238
- this.view.lastRenderedLocation = this.history.location;
3239
- this.notifyApplicationAfterRender();
3240
- };
3241
- Session.prototype.viewInvalidated = function () {
3242
- this.adapter.pageInvalidated();
3243
- };
3244
- Session.prototype.applicationAllowsFollowingLinkToLocation = function (link, location) {
3245
- var event = this.notifyApplicationAfterClickingLinkToLocation(link, location);
3246
- return !event.defaultPrevented;
3247
- };
3248
- Session.prototype.applicationAllowsVisitingLocation = function (location) {
3249
- var event = this.notifyApplicationBeforeVisitingLocation(location);
3250
- return !event.defaultPrevented;
3251
- };
3252
- Session.prototype.notifyApplicationAfterClickingLinkToLocation = function (link, location) {
3253
- return dispatch("turbo:click", { target: link, detail: { url: location.href }, cancelable: true });
3254
- };
3255
- Session.prototype.notifyApplicationBeforeVisitingLocation = function (location) {
3256
- return dispatch("turbo:before-visit", { detail: { url: location.href }, cancelable: true });
3257
- };
3258
- Session.prototype.notifyApplicationAfterVisitingLocation = function (location) {
3259
- return dispatch("turbo:visit", { detail: { url: location.href } });
3260
- };
3261
- Session.prototype.notifyApplicationBeforeCachingSnapshot = function () {
3262
- return dispatch("turbo:before-cache");
3263
- };
3264
- Session.prototype.notifyApplicationBeforeRender = function (newBody) {
3265
- return dispatch("turbo:before-render", { detail: { newBody: newBody } });
3266
- };
3267
- Session.prototype.notifyApplicationAfterRender = function () {
3268
- return dispatch("turbo:render");
3269
- };
3270
- Session.prototype.notifyApplicationAfterPageLoad = function (timing) {
3271
- if (timing === void 0) { timing = {}; }
3272
- return dispatch("turbo:load", { detail: { url: this.location.href, timing: timing } });
3273
- };
3274
- Session.prototype.getActionForLink = function (link) {
3275
- var action = link.getAttribute("data-turbo-action");
3276
- return isAction(action) ? action : "advance";
3277
- };
3278
- Session.prototype.locationIsVisitable = function (location) {
3279
- return isPrefixedBy(location, this.snapshot.rootLocation) && isHTML(location);
3280
- };
3281
- Object.defineProperty(Session.prototype, "snapshot", {
3282
- get: function () {
3283
- return this.view.snapshot;
3284
- },
3285
- enumerable: false,
3286
- configurable: true
3287
- });
3288
- return Session;
3289
- }());
3290
- function elementIsNavigable(element) {
3291
- var container = element === null || element === void 0 ? void 0 : element.closest("[data-turbo]");
3292
- if (container) {
3293
- return container.getAttribute("data-turbo") != "false";
3294
- }
3295
- else {
3296
- return true;
3297
- }
3298
- }
3299
- function extendURLWithDeprecatedProperties(url) {
3300
- Object.defineProperties(url, deprecatedLocationPropertyDescriptors);
3301
- }
3302
- var deprecatedLocationPropertyDescriptors = {
3303
- absoluteURL: {
3304
- get: function () {
3305
- return this.toString();
3306
- }
3307
- }
3308
- };
3309
-
3310
- var FrameController = (function () {
3311
- function FrameController(element) {
3312
- this.resolveVisitPromise = function () { };
3313
- this.connected = false;
3314
- this.hasBeenLoaded = false;
3315
- this.settingSourceURL = false;
3316
- this.element = element;
3317
- this.view = new FrameView(this, this.element);
3318
- this.appearanceObserver = new AppearanceObserver(this, this.element);
3319
- this.linkInterceptor = new LinkInterceptor(this, this.element);
3320
- this.formInterceptor = new FormInterceptor(this, this.element);
3321
- }
3322
- FrameController.prototype.connect = function () {
3323
- if (!this.connected) {
3324
- this.connected = true;
3325
- if (this.loadingStyle == FrameLoadingStyle.lazy) {
3326
- this.appearanceObserver.start();
3327
- }
3328
- this.linkInterceptor.start();
3329
- this.formInterceptor.start();
3330
- this.sourceURLChanged();
3331
- }
3332
- };
3333
- FrameController.prototype.disconnect = function () {
3334
- if (this.connected) {
3335
- this.connected = false;
3336
- this.appearanceObserver.stop();
3337
- this.linkInterceptor.stop();
3338
- this.formInterceptor.stop();
3339
- }
3340
- };
3341
- FrameController.prototype.disabledChanged = function () {
3342
- if (this.loadingStyle == FrameLoadingStyle.eager) {
3343
- this.loadSourceURL();
3344
- }
3345
- };
3346
- FrameController.prototype.sourceURLChanged = function () {
3347
- if (this.loadingStyle == FrameLoadingStyle.eager || this.hasBeenLoaded) {
3348
- this.loadSourceURL();
3349
- }
3350
- };
3351
- FrameController.prototype.loadingStyleChanged = function () {
3352
- if (this.loadingStyle == FrameLoadingStyle.lazy) {
3353
- this.appearanceObserver.start();
3354
- }
3355
- else {
3356
- this.appearanceObserver.stop();
3357
- this.loadSourceURL();
3358
- }
3359
- };
3360
- FrameController.prototype.loadSourceURL = function () {
3361
- return __awaiter(this, void 0, void 0, function () {
3362
- var previousURL, error_1;
3363
- return __generator(this, function (_a) {
3364
- switch (_a.label) {
3365
- case 0:
3366
- if (!(!this.settingSourceURL && this.enabled && this.isActive && this.sourceURL != this.currentURL)) return [3, 4];
3367
- previousURL = this.currentURL;
3368
- this.currentURL = this.sourceURL;
3369
- if (!this.sourceURL) return [3, 4];
3370
- _a.label = 1;
3371
- case 1:
3372
- _a.trys.push([1, 3, , 4]);
3373
- this.element.loaded = this.visit(this.sourceURL);
3374
- this.appearanceObserver.stop();
3375
- return [4, this.element.loaded];
3376
- case 2:
3377
- _a.sent();
3378
- this.hasBeenLoaded = true;
3379
- return [3, 4];
3380
- case 3:
3381
- error_1 = _a.sent();
3382
- this.currentURL = previousURL;
3383
- throw error_1;
3384
- case 4: return [2];
3385
- }
3386
- });
3387
- });
3388
- };
3389
- FrameController.prototype.loadResponse = function (fetchResponse) {
3390
- return __awaiter(this, void 0, void 0, function () {
3391
- var html, body, snapshot, _a, renderer, error_2;
3392
- return __generator(this, function (_b) {
3393
- switch (_b.label) {
3394
- case 0:
3395
- if (fetchResponse.redirected) {
3396
- this.sourceURL = fetchResponse.response.url;
3397
- }
3398
- _b.label = 1;
3399
- case 1:
3400
- _b.trys.push([1, 6, , 7]);
3401
- return [4, fetchResponse.responseHTML];
3402
- case 2:
3403
- html = _b.sent();
3404
- if (!html) return [3, 5];
3405
- body = parseHTMLDocument(html).body;
3406
- _a = Snapshot.bind;
3407
- return [4, this.extractForeignFrameElement(body)];
3408
- case 3:
3409
- snapshot = new (_a.apply(Snapshot, [void 0, _b.sent()]))();
3410
- renderer = new FrameRenderer(this.view.snapshot, snapshot, false);
3411
- return [4, this.view.render(renderer)];
3412
- case 4:
3413
- _b.sent();
3414
- _b.label = 5;
3415
- case 5: return [3, 7];
3416
- case 6:
3417
- error_2 = _b.sent();
3418
- console.error(error_2);
3419
- this.view.invalidate();
3420
- return [3, 7];
3421
- case 7: return [2];
3422
- }
3423
- });
3424
- });
3425
- };
3426
- FrameController.prototype.elementAppearedInViewport = function (element) {
3427
- this.loadSourceURL();
3428
- };
3429
- FrameController.prototype.shouldInterceptLinkClick = function (element, url) {
3430
- return this.shouldInterceptNavigation(element);
3431
- };
3432
- FrameController.prototype.linkClickIntercepted = function (element, url) {
3433
- this.navigateFrame(element, url);
3434
- };
3435
- FrameController.prototype.shouldInterceptFormSubmission = function (element, submitter) {
3436
- return this.shouldInterceptNavigation(element, submitter);
3437
- };
3438
- FrameController.prototype.formSubmissionIntercepted = function (element, submitter) {
3439
- if (this.formSubmission) {
3440
- this.formSubmission.stop();
3441
- }
3442
- this.formSubmission = new FormSubmission(this, element, submitter);
3443
- if (this.formSubmission.fetchRequest.isIdempotent) {
3444
- this.navigateFrame(element, this.formSubmission.fetchRequest.url.href);
3445
- }
3446
- else {
3447
- var fetchRequest = this.formSubmission.fetchRequest;
3448
- this.prepareHeadersForRequest(fetchRequest.headers, fetchRequest);
3449
- this.formSubmission.start();
3450
- }
3451
- };
3452
- FrameController.prototype.prepareHeadersForRequest = function (headers, request) {
3453
- headers["Turbo-Frame"] = this.id;
3454
- };
3455
- FrameController.prototype.requestStarted = function (request) {
3456
- this.element.setAttribute("busy", "");
3457
- };
3458
- FrameController.prototype.requestPreventedHandlingResponse = function (request, response) {
3459
- this.resolveVisitPromise();
3460
- };
3461
- FrameController.prototype.requestSucceededWithResponse = function (request, response) {
3462
- return __awaiter(this, void 0, void 0, function () {
3463
- return __generator(this, function (_a) {
3464
- switch (_a.label) {
3465
- case 0: return [4, this.loadResponse(response)];
3466
- case 1:
3467
- _a.sent();
3468
- this.resolveVisitPromise();
3469
- return [2];
3470
- }
3471
- });
3472
- });
3473
- };
3474
- FrameController.prototype.requestFailedWithResponse = function (request, response) {
3475
- console.error(response);
3476
- this.resolveVisitPromise();
3477
- };
3478
- FrameController.prototype.requestErrored = function (request, error) {
3479
- console.error(error);
3480
- this.resolveVisitPromise();
3481
- };
3482
- FrameController.prototype.requestFinished = function (request) {
3483
- this.element.removeAttribute("busy");
3484
- };
3485
- FrameController.prototype.formSubmissionStarted = function (formSubmission) {
3486
- var frame = this.findFrameElement(formSubmission.formElement);
3487
- frame.setAttribute("busy", "");
3488
- };
3489
- FrameController.prototype.formSubmissionSucceededWithResponse = function (formSubmission, response) {
3490
- var frame = this.findFrameElement(formSubmission.formElement);
3491
- frame.delegate.loadResponse(response);
3492
- };
3493
- FrameController.prototype.formSubmissionFailedWithResponse = function (formSubmission, fetchResponse) {
3494
- this.element.delegate.loadResponse(fetchResponse);
3495
- };
3496
- FrameController.prototype.formSubmissionErrored = function (formSubmission, error) {
3497
- console.error(error);
3498
- };
3499
- FrameController.prototype.formSubmissionFinished = function (formSubmission) {
3500
- var frame = this.findFrameElement(formSubmission.formElement);
3501
- frame.removeAttribute("busy");
3502
- };
3503
- FrameController.prototype.viewWillRenderSnapshot = function (snapshot, isPreview) {
3504
- };
3505
- FrameController.prototype.viewRenderedSnapshot = function (snapshot, isPreview) {
3506
- };
3507
- FrameController.prototype.viewInvalidated = function () {
3508
- };
3509
- FrameController.prototype.visit = function (url) {
3510
- return __awaiter(this, void 0, void 0, function () {
3511
- var request;
3512
- var _this = this;
3513
- return __generator(this, function (_a) {
3514
- request = new FetchRequest(this, FetchMethod.get, expandURL(url));
3515
- return [2, new Promise(function (resolve) {
3516
- _this.resolveVisitPromise = function () {
3517
- _this.resolveVisitPromise = function () { };
3518
- resolve();
3519
- };
3520
- request.perform();
3521
- })];
3522
- });
3523
- });
3524
- };
3525
- FrameController.prototype.navigateFrame = function (element, url) {
3526
- var frame = this.findFrameElement(element);
3527
- frame.src = url;
3528
- };
3529
- FrameController.prototype.findFrameElement = function (element) {
3530
- var _a;
3531
- var id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
3532
- return (_a = getFrameElementById(id)) !== null && _a !== void 0 ? _a : this.element;
3533
- };
3534
- FrameController.prototype.extractForeignFrameElement = function (container) {
3535
- return __awaiter(this, void 0, void 0, function () {
3536
- var element, id, error_3;
3537
- return __generator(this, function (_a) {
3538
- switch (_a.label) {
3539
- case 0:
3540
- id = CSS.escape(this.id);
3541
- _a.label = 1;
3542
- case 1:
3543
- _a.trys.push([1, 5, , 6]);
3544
- if (element = activateElement(container.querySelector("turbo-frame#" + id), this.currentURL)) {
3545
- return [2, element];
3546
- }
3547
- if (!(element = activateElement(container.querySelector("turbo-frame[src][recurse~=" + id + "]"), this.currentURL))) return [3, 4];
3548
- return [4, element.loaded];
3549
- case 2:
3550
- _a.sent();
3551
- return [4, this.extractForeignFrameElement(element)];
3552
- case 3: return [2, _a.sent()];
3553
- case 4:
3554
- console.error("Response has no matching <turbo-frame id=\"" + id + "\"> element");
3555
- return [3, 6];
3556
- case 5:
3557
- error_3 = _a.sent();
3558
- console.error(error_3);
3559
- return [3, 6];
3560
- case 6: return [2, new FrameElement()];
3561
- }
3562
- });
3563
- });
3564
- };
3565
- FrameController.prototype.shouldInterceptNavigation = function (element, submitter) {
3566
- var id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target");
3567
- if (!this.enabled || id == "_top") {
3568
- return false;
3569
- }
3570
- if (id) {
3571
- var frameElement_1 = getFrameElementById(id);
3572
- if (frameElement_1) {
3573
- return !frameElement_1.disabled;
3574
- }
3575
- }
3576
- if (!elementIsNavigable(element)) {
3577
- return false;
3578
- }
3579
- if (submitter && !elementIsNavigable(submitter)) {
3580
- return false;
3581
- }
3582
- return true;
3583
- };
3584
- Object.defineProperty(FrameController.prototype, "id", {
3585
- get: function () {
3586
- return this.element.id;
3587
- },
3588
- enumerable: false,
3589
- configurable: true
3590
- });
3591
- Object.defineProperty(FrameController.prototype, "enabled", {
3592
- get: function () {
3593
- return !this.element.disabled;
3594
- },
3595
- enumerable: false,
3596
- configurable: true
3597
- });
3598
- Object.defineProperty(FrameController.prototype, "sourceURL", {
3599
- get: function () {
3600
- if (this.element.src) {
3601
- return this.element.src;
3602
- }
3603
- },
3604
- set: function (sourceURL) {
3605
- this.settingSourceURL = true;
3606
- this.element.src = sourceURL !== null && sourceURL !== void 0 ? sourceURL : null;
3607
- this.currentURL = this.element.src;
3608
- this.settingSourceURL = false;
3609
- },
3610
- enumerable: false,
3611
- configurable: true
3612
- });
3613
- Object.defineProperty(FrameController.prototype, "loadingStyle", {
3614
- get: function () {
3615
- return this.element.loading;
3616
- },
3617
- enumerable: false,
3618
- configurable: true
3619
- });
3620
- Object.defineProperty(FrameController.prototype, "isLoading", {
3621
- get: function () {
3622
- return this.formSubmission !== undefined || this.resolveVisitPromise() !== undefined;
3623
- },
3624
- enumerable: false,
3625
- configurable: true
3626
- });
3627
- Object.defineProperty(FrameController.prototype, "isActive", {
3628
- get: function () {
3629
- return this.element.isActive && this.connected;
3630
- },
3631
- enumerable: false,
3632
- configurable: true
3633
- });
3634
- return FrameController;
3635
- }());
3636
- function getFrameElementById(id) {
3637
- if (id != null) {
3638
- var element = document.getElementById(id);
3639
- if (element instanceof FrameElement) {
3640
- return element;
3641
- }
3642
- }
3643
- }
3644
- function activateElement(element, currentURL) {
3645
- if (element) {
3646
- var src = element.getAttribute("src");
3647
- if (src != null && currentURL != null && urlsAreEqual(src, currentURL)) {
3648
- throw new Error("Matching <turbo-frame id=\"" + element.id + "\"> element has a source URL which references itself");
3649
- }
3650
- if (element.ownerDocument !== document) {
3651
- element = document.importNode(element, true);
3652
- }
3653
- if (element instanceof FrameElement) {
3654
- element.connectedCallback();
3655
- return element;
3656
- }
3657
- }
3658
- }
3659
-
3660
- var StreamActions = {
3661
- after: function () {
3662
- var _this = this;
3663
- this.targetElements.forEach(function (e) { var _a; return (_a = e.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(_this.templateContent, e.nextSibling); });
3664
- },
3665
- append: function () {
3666
- var _this = this;
3667
- this.removeDuplicateTargetChildren();
3668
- this.targetElements.forEach(function (e) { return e.append(_this.templateContent); });
3669
- },
3670
- before: function () {
3671
- var _this = this;
3672
- this.targetElements.forEach(function (e) { var _a; return (_a = e.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(_this.templateContent, e); });
3673
- },
3674
- prepend: function () {
3675
- var _this = this;
3676
- this.removeDuplicateTargetChildren();
3677
- this.targetElements.forEach(function (e) { return e.prepend(_this.templateContent); });
3678
- },
3679
- remove: function () {
3680
- this.targetElements.forEach(function (e) { return e.remove(); });
3681
- },
3682
- replace: function () {
3683
- var _this = this;
3684
- this.targetElements.forEach(function (e) { return e.replaceWith(_this.templateContent); });
3685
- },
3686
- update: function () {
3687
- var _this = this;
3688
- this.targetElements.forEach(function (e) {
3689
- e.innerHTML = "";
3690
- e.append(_this.templateContent);
3691
- });
3692
- }
3693
- };
3694
-
3695
- var StreamElement = (function (_super) {
3696
- __extends(StreamElement, _super);
3697
- function StreamElement() {
3698
- return _super !== null && _super.apply(this, arguments) || this;
3699
- }
3700
- StreamElement.prototype.connectedCallback = function () {
3701
- return __awaiter(this, void 0, void 0, function () {
3702
- var error_1;
3703
- return __generator(this, function (_a) {
3704
- switch (_a.label) {
3705
- case 0:
3706
- _a.trys.push([0, 2, 3, 4]);
3707
- return [4, this.render()];
3708
- case 1:
3709
- _a.sent();
3710
- return [3, 4];
3711
- case 2:
3712
- error_1 = _a.sent();
3713
- console.error(error_1);
3714
- return [3, 4];
3715
- case 3:
3716
- this.disconnect();
3717
- return [7];
3718
- case 4: return [2];
3719
- }
3720
- });
3721
- });
3722
- };
3723
- StreamElement.prototype.render = function () {
3724
- var _a;
3725
- return __awaiter(this, void 0, void 0, function () {
3726
- var _this = this;
3727
- return __generator(this, function (_b) {
3728
- return [2, (_a = this.renderPromise) !== null && _a !== void 0 ? _a : (this.renderPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
3729
- return __generator(this, function (_a) {
3730
- switch (_a.label) {
3731
- case 0:
3732
- if (!this.dispatchEvent(this.beforeRenderEvent)) return [3, 2];
3733
- return [4, nextAnimationFrame()];
3734
- case 1:
3735
- _a.sent();
3736
- this.performAction();
3737
- _a.label = 2;
3738
- case 2: return [2];
3739
- }
3740
- });
3741
- }); })())];
3742
- });
3743
- });
3744
- };
3745
- StreamElement.prototype.disconnect = function () {
3746
- try {
3747
- this.remove();
3748
- }
3749
- catch (_a) { }
3750
- };
3751
- StreamElement.prototype.removeDuplicateTargetChildren = function () {
3752
- this.duplicateChildren.forEach(function (c) { return c.remove(); });
3753
- };
3754
- Object.defineProperty(StreamElement.prototype, "duplicateChildren", {
3755
- get: function () {
3756
- var _a;
3757
- var existingChildren = this.targetElements.flatMap(function (e) { return __spread(e.children); }).filter(function (c) { return !!c.id; });
3758
- var newChildrenIds = __spread((_a = this.templateContent) === null || _a === void 0 ? void 0 : _a.children).filter(function (c) { return !!c.id; }).map(function (c) { return c.id; });
3759
- return existingChildren.filter(function (c) { return newChildrenIds.includes(c.id); });
3760
- },
3761
- enumerable: false,
3762
- configurable: true
3763
- });
3764
- Object.defineProperty(StreamElement.prototype, "performAction", {
3765
- get: function () {
3766
- if (this.action) {
3767
- var actionFunction = StreamActions[this.action];
3768
- if (actionFunction) {
3769
- return actionFunction;
3770
- }
3771
- this.raise("unknown action");
3772
- }
3773
- this.raise("action attribute is missing");
3774
- },
3775
- enumerable: false,
3776
- configurable: true
3777
- });
3778
- Object.defineProperty(StreamElement.prototype, "targetElements", {
3779
- get: function () {
3780
- if (this.target) {
3781
- return this.targetElementsById;
3782
- }
3783
- else if (this.targets) {
3784
- return this.targetElementsByQuery;
3785
- }
3786
- else {
3787
- this.raise("target or targets attribute is missing");
3788
- }
3789
- },
3790
- enumerable: false,
3791
- configurable: true
3792
- });
3793
- Object.defineProperty(StreamElement.prototype, "templateContent", {
3794
- get: function () {
3795
- return this.templateElement.content.cloneNode(true);
3796
- },
3797
- enumerable: false,
3798
- configurable: true
3799
- });
3800
- Object.defineProperty(StreamElement.prototype, "templateElement", {
3801
- get: function () {
3802
- if (this.firstElementChild instanceof HTMLTemplateElement) {
3803
- return this.firstElementChild;
3804
- }
3805
- this.raise("first child element must be a <template> element");
3806
- },
3807
- enumerable: false,
3808
- configurable: true
3809
- });
3810
- Object.defineProperty(StreamElement.prototype, "action", {
3811
- get: function () {
3812
- return this.getAttribute("action");
3813
- },
3814
- enumerable: false,
3815
- configurable: true
3816
- });
3817
- Object.defineProperty(StreamElement.prototype, "target", {
3818
- get: function () {
3819
- return this.getAttribute("target");
3820
- },
3821
- enumerable: false,
3822
- configurable: true
3823
- });
3824
- Object.defineProperty(StreamElement.prototype, "targets", {
3825
- get: function () {
3826
- return this.getAttribute("targets");
3827
- },
3828
- enumerable: false,
3829
- configurable: true
3830
- });
3831
- StreamElement.prototype.raise = function (message) {
3832
- throw new Error(this.description + ": " + message);
3833
- };
3834
- Object.defineProperty(StreamElement.prototype, "description", {
3835
- get: function () {
3836
- var _a, _b;
3837
- return (_b = ((_a = this.outerHTML.match(/<[^>]+>/)) !== null && _a !== void 0 ? _a : [])[0]) !== null && _b !== void 0 ? _b : "<turbo-stream>";
3838
- },
3839
- enumerable: false,
3840
- configurable: true
3841
- });
3842
- Object.defineProperty(StreamElement.prototype, "beforeRenderEvent", {
3843
- get: function () {
3844
- return new CustomEvent("turbo:before-stream-render", { bubbles: true, cancelable: true });
3845
- },
3846
- enumerable: false,
3847
- configurable: true
3848
- });
3849
- Object.defineProperty(StreamElement.prototype, "targetElementsById", {
3850
- get: function () {
3851
- var _a;
3852
- var element = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.getElementById(this.target);
3853
- if (element !== null) {
3854
- return [element];
3855
- }
3856
- else {
3857
- return [];
3858
- }
3859
- },
3860
- enumerable: false,
3861
- configurable: true
3862
- });
3863
- Object.defineProperty(StreamElement.prototype, "targetElementsByQuery", {
3864
- get: function () {
3865
- var _a;
3866
- var elements = (_a = this.ownerDocument) === null || _a === void 0 ? void 0 : _a.querySelectorAll(this.targets);
3867
- if (elements.length !== 0) {
3868
- return Array.prototype.slice.call(elements);
3869
- }
3870
- else {
3871
- return [];
3872
- }
3873
- },
3874
- enumerable: false,
3875
- configurable: true
3876
- });
3877
- return StreamElement;
3878
- }(HTMLElement));
3879
-
3880
- FrameElement.delegateConstructor = FrameController;
3881
- customElements.define("turbo-frame", FrameElement);
3882
- customElements.define("turbo-stream", StreamElement);
3883
-
3884
- (function () {
3885
- var element = document.currentScript;
3886
- if (!element)
3887
- return;
3888
- if (element.hasAttribute("data-turbo-suppress-warning"))
3889
- return;
3890
- while (element = element.parentElement) {
3891
- if (element == document.body) {
3892
- return console.warn(unindent(templateObject_1$1 || (templateObject_1$1 = __makeTemplateObject(["\n You are loading Turbo from a <script> element inside the <body> element. This is probably not what you meant to do!\n\n Load your application\u2019s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change.\n\n For more information, see: https://turbo.hotwire.dev/handbook/building#working-with-script-elements\n\n \u2014\u2014\n Suppress this warning by adding a \"data-turbo-suppress-warning\" attribute to: %s\n "], ["\n You are loading Turbo from a <script> element inside the <body> element. This is probably not what you meant to do!\n\n Load your application\u2019s JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change.\n\n For more information, see: https://turbo.hotwire.dev/handbook/building#working-with-script-elements\n\n \u2014\u2014\n Suppress this warning by adding a \"data-turbo-suppress-warning\" attribute to: %s\n "]))), element.outerHTML);
3893
- }
3894
- }
3895
- })();
3896
- var templateObject_1$1;
3897
-
3898
- var session = new Session;
3899
- var navigator = session.navigator;
3900
- function start() {
3901
- session.start();
3902
- }
3903
- function registerAdapter(adapter) {
3904
- session.registerAdapter(adapter);
3905
- }
3906
- function visit(location, options) {
3907
- session.visit(location, options);
3908
- }
3909
- function connectStreamSource(source) {
3910
- session.connectStreamSource(source);
3911
- }
3912
- function disconnectStreamSource(source) {
3913
- session.disconnectStreamSource(source);
3914
- }
3915
- function renderStreamMessage(message) {
3916
- session.renderStreamMessage(message);
3917
- }
3918
- function clearCache() {
3919
- session.clearCache();
3920
- }
3921
- function setProgressBarDelay(delay) {
3922
- session.setProgressBarDelay(delay);
3923
- }
3924
-
3925
- var Turbo = /*#__PURE__*/Object.freeze({
3926
- __proto__: null,
3927
- navigator: navigator,
3928
- start: start,
3929
- registerAdapter: registerAdapter,
3930
- visit: visit,
3931
- connectStreamSource: connectStreamSource,
3932
- disconnectStreamSource: disconnectStreamSource,
3933
- renderStreamMessage: renderStreamMessage,
3934
- clearCache: clearCache,
3935
- setProgressBarDelay: setProgressBarDelay
3936
- });
3937
-
3938
- window.Turbo = Turbo;
3939
- start();
3940
-
3941
- exports.clearCache = clearCache;
3942
- exports.connectStreamSource = connectStreamSource;
3943
- exports.disconnectStreamSource = disconnectStreamSource;
3944
- exports.navigator = navigator;
3945
- exports.registerAdapter = registerAdapter;
3946
- exports.renderStreamMessage = renderStreamMessage;
3947
- exports.setProgressBarDelay = setProgressBarDelay;
3948
- exports.start = start;
3949
- exports.visit = visit;
3950
-
3951
- Object.defineProperty(exports, '__esModule', { value: true });
3952
-
3953
- })));
3954
- //# sourceMappingURL=turbo.es5-umd.js.map