@alignable/bifrost 0.0.8 → 0.0.10
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.
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/getGlobalObject.d.ts +5 -0
- package/dist/lib/getGlobalObject.d.ts.map +1 -0
- package/dist/lib/getGlobalObject.js +7 -0
- package/dist/lib/turbolinks/adapter.d.ts +17 -0
- package/dist/lib/turbolinks/adapter.d.ts.map +1 -0
- package/dist/lib/turbolinks/adapter.js +1 -0
- package/dist/lib/turbolinks/browser_adapter.d.ts +28 -0
- package/dist/lib/turbolinks/browser_adapter.d.ts.map +1 -0
- package/dist/lib/turbolinks/browser_adapter.js +71 -0
- package/dist/lib/turbolinks/controller.d.ts +101 -0
- package/dist/lib/turbolinks/controller.d.ts.map +1 -0
- package/dist/lib/turbolinks/controller.js +290 -0
- package/dist/lib/turbolinks/head_details.d.ts +23 -0
- package/dist/lib/turbolinks/head_details.d.ts.map +1 -0
- package/dist/lib/turbolinks/head_details.js +92 -0
- package/dist/lib/turbolinks/history.d.ts +22 -0
- package/dist/lib/turbolinks/history.d.ts.map +1 -0
- package/dist/lib/turbolinks/history.js +60 -0
- package/dist/lib/turbolinks/index.d.ts +14 -0
- package/dist/lib/turbolinks/index.d.ts.map +1 -0
- package/dist/lib/turbolinks/index.js +55 -0
- package/dist/lib/turbolinks/location.d.ts +23 -0
- package/dist/lib/turbolinks/location.d.ts.map +1 -0
- package/dist/lib/turbolinks/location.js +75 -0
- package/dist/lib/turbolinks/namespace.d.ts +12 -0
- package/dist/lib/turbolinks/namespace.d.ts.map +1 -0
- package/dist/lib/turbolinks/namespace.js +20 -0
- package/dist/lib/turbolinks/passthrough_renderer.d.ts +32 -0
- package/dist/lib/turbolinks/passthrough_renderer.d.ts.map +1 -0
- package/dist/lib/turbolinks/passthrough_renderer.js +128 -0
- package/dist/lib/turbolinks/progress_bar.d.ts +24 -0
- package/dist/lib/turbolinks/progress_bar.d.ts.map +1 -0
- package/dist/lib/turbolinks/progress_bar.js +99 -0
- package/dist/lib/turbolinks/renderer.d.ts +14 -0
- package/dist/lib/turbolinks/renderer.d.ts.map +1 -0
- package/dist/lib/turbolinks/renderer.js +28 -0
- package/dist/lib/turbolinks/scroll_manager.d.ts +16 -0
- package/dist/lib/turbolinks/scroll_manager.d.ts.map +1 -0
- package/dist/lib/turbolinks/scroll_manager.js +32 -0
- package/dist/lib/turbolinks/snapshot.d.ts +25 -0
- package/dist/lib/turbolinks/snapshot.d.ts.map +1 -0
- package/dist/lib/turbolinks/snapshot.js +77 -0
- package/dist/lib/turbolinks/snapshot_cache.d.ts +18 -0
- package/dist/lib/turbolinks/snapshot_cache.d.ts.map +1 -0
- package/dist/lib/turbolinks/snapshot_cache.js +42 -0
- package/dist/lib/turbolinks/snapshot_renderer copy.d.ts +45 -0
- package/dist/lib/turbolinks/snapshot_renderer copy.d.ts.map +1 -0
- package/dist/lib/turbolinks/snapshot_renderer copy.js +179 -0
- package/dist/lib/turbolinks/snapshot_renderer.d.ts +43 -0
- package/dist/lib/turbolinks/snapshot_renderer.d.ts.map +1 -0
- package/dist/lib/turbolinks/snapshot_renderer.js +139 -0
- package/dist/lib/turbolinks/types.d.ts +7 -0
- package/dist/lib/turbolinks/types.d.ts.map +1 -0
- package/dist/lib/turbolinks/types.js +3 -0
- package/dist/lib/turbolinks/util.d.ts +14 -0
- package/dist/lib/turbolinks/util.d.ts.map +1 -0
- package/dist/lib/turbolinks/util.js +85 -0
- package/dist/lib/turbolinks/view.d.ts +21 -0
- package/dist/lib/turbolinks/view.d.ts.map +1 -0
- package/dist/lib/turbolinks/view.js +42 -0
- package/dist/lib/turbolinks/visit.d.ts +73 -0
- package/dist/lib/turbolinks/visit.d.ts.map +1 -0
- package/dist/lib/turbolinks/visit.js +227 -0
- package/dist/proxy/pages/+config.d.ts +4 -4
- package/dist/proxy/pages/+config.js +4 -4
- package/dist/proxy/pages/onPageTransitionStart.d.ts +3 -0
- package/dist/proxy/pages/onPageTransitionStart.d.ts.map +1 -0
- package/dist/proxy/pages/onPageTransitionStart.js +9 -0
- package/dist/proxy/pages/restorationVisit/+config.d.ts +2 -2
- package/dist/proxy/pages/restorationVisit/+config.js +2 -2
- package/dist/renderer/+config.d.ts +9 -3
- package/dist/renderer/+config.d.ts.map +1 -1
- package/dist/renderer/+config.js +6 -4
- package/dist/renderer/onRenderClient.d.ts.map +1 -1
- package/dist/renderer/onRenderClient.js +7 -1
- package/dist/renderer/onRenderHtml.d.ts.map +1 -1
- package/dist/renderer/onRenderHtml.js +9 -1
- package/dist/renderer/usePageContext.d.ts +1 -0
- package/dist/renderer/usePageContext.d.ts.map +1 -1
- package/dist/renderer/usePageContext.js +9 -1
- package/dist/renderer/utils/formatMetaObject.d.ts +4 -0
- package/dist/renderer/utils/formatMetaObject.d.ts.map +1 -0
- package/dist/renderer/utils/formatMetaObject.js +3 -0
- package/dist/renderer/utils/getGlobalObject.d.ts +5 -0
- package/dist/renderer/utils/getGlobalObject.d.ts.map +1 -0
- package/dist/renderer/utils/getGlobalObject.js +8 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Config } from "vite-plugin-ssr/types";
|
|
1
|
+
import { Config, ConfigNonHeaderFile } from "vite-plugin-ssr/types";
|
|
2
2
|
import { DocumentProps, Layout, LayoutMap } from "./types/internal";
|
|
3
3
|
import ProxyLibConfig from "./proxy/pages/+config.js";
|
|
4
4
|
import bifrostLibConfig from "./renderer/+config.js";
|
|
5
5
|
import { Turbolinks } from "./lib/turbolinks.js";
|
|
6
6
|
export { usePageContext } from "./renderer/usePageContext.js";
|
|
7
7
|
export { LayoutMap, DocumentProps };
|
|
8
|
-
type ConfigConstructor<LibConfig extends
|
|
8
|
+
type ConfigConstructor<LibConfig extends ConfigNonHeaderFile, T extends {
|
|
9
9
|
[K in keyof LibConfig["meta"]]?: any;
|
|
10
10
|
}> = Config & Partial<T>;
|
|
11
11
|
export type ProxyConfig<LayoutProps> = ConfigConstructor<typeof ProxyLibConfig, {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,cAAc,MAAM,0BAA0B,CAAC;AACtD,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI9D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;AAGpC,KAAK,iBAAiB,CACpB,SAAS,SAAS,mBAAmB,EACrC,CAAC,SAAS;KAAG,CAAC,IAAI,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG;CAAE,IAChD,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAExB,MAAM,MAAM,WAAW,CAAC,WAAW,IAAI,iBAAiB,CACtD,OAAO,cAAc,EACrB;IACE,SAAS,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;CACnC,CACF,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,WAAW,IAAI,iBAAiB,CACxD,OAAO,gBAAgB,EACvB;IACE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;CAC9B,CACF,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,OAAO,UAAU,CAAC;KAC/B;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getGlobalObject<T extends Record<string, unknown> = never>(key: `${string}.ts`, defaultValue: T): T;
|
|
2
|
+
declare global {
|
|
3
|
+
var __vite_plugin_ssr: undefined | Record<string, Record<string, unknown>>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=getGlobalObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGlobalObject.d.ts","sourceRoot":"","sources":["../../lib/getGlobalObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,EAEvE,GAAG,EAAE,GAAG,MAAM,KAAK,EACnB,YAAY,EAAE,CAAC,GACd,CAAC,CAIH;AACD,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,iBAAiB,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CAC3E"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function getGlobalObject(
|
|
2
|
+
// We use the filename as key; each `getGlobalObject()` call should live in a unique filename.
|
|
3
|
+
key, defaultValue) {
|
|
4
|
+
const allGlobalObjects = (globalThis.__vite_plugin_ssr = globalThis.__vite_plugin_ssr || {});
|
|
5
|
+
const globalObject = (allGlobalObjects[key] = allGlobalObjects[key] || defaultValue);
|
|
6
|
+
return globalObject;
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Locatable } from "./location";
|
|
2
|
+
import { Action } from "./types";
|
|
3
|
+
import { Visit } from "./visit";
|
|
4
|
+
export interface Adapter {
|
|
5
|
+
visitProposedToLocationWithAction(location: Locatable, action: Action): void;
|
|
6
|
+
visitStarted(visit: Visit): void;
|
|
7
|
+
visitCompleted(visit: Visit): void;
|
|
8
|
+
visitFailed(visit: Visit): void;
|
|
9
|
+
visitRequestStarted(visit: Visit): void;
|
|
10
|
+
visitRequestProgressed?(visit: Visit): void;
|
|
11
|
+
visitRequestCompleted(visit: Visit): void;
|
|
12
|
+
visitRequestFailedWithStatusCode(visit: Visit, statusCode: number): void;
|
|
13
|
+
visitRequestFinished(visit: Visit): void;
|
|
14
|
+
visitRendered(visit: Visit): void;
|
|
15
|
+
pageInvalidated(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../lib/turbolinks/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,OAAO;IACtB,iCAAiC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7E,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACjC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACnC,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAChC,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACxC,sBAAsB,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5C,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1C,gCAAgC,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACzE,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACzC,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAClC,eAAe,IAAI,IAAI,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Adapter } from "./adapter";
|
|
2
|
+
import { Controller } from "./controller";
|
|
3
|
+
import { Locatable } from "./location";
|
|
4
|
+
import { ProgressBar } from "./progress_bar";
|
|
5
|
+
import { Action } from "./types";
|
|
6
|
+
import { Visit } from "./visit";
|
|
7
|
+
export declare class BrowserAdapter implements Adapter {
|
|
8
|
+
readonly controller: Controller;
|
|
9
|
+
readonly progressBar: ProgressBar;
|
|
10
|
+
progressBarTimeout?: number;
|
|
11
|
+
constructor(controller: Controller);
|
|
12
|
+
visitProposedToLocationWithAction(location: Locatable, action: Action): void;
|
|
13
|
+
visitStarted(visit: Visit): void;
|
|
14
|
+
visitRequestStarted(visit: Visit): void;
|
|
15
|
+
visitRequestProgressed(visit: Visit): void;
|
|
16
|
+
visitRequestCompleted(visit: Visit): void;
|
|
17
|
+
visitRequestFailedWithStatusCode(visit: Visit, statusCode: number): void;
|
|
18
|
+
visitRequestFinished(visit: Visit): void;
|
|
19
|
+
visitCompleted(visit: Visit): void;
|
|
20
|
+
pageInvalidated(): void;
|
|
21
|
+
visitFailed(visit: Visit): void;
|
|
22
|
+
visitRendered(visit: Visit): void;
|
|
23
|
+
showProgressBarAfterDelay(): void;
|
|
24
|
+
showProgressBar: () => void;
|
|
25
|
+
hideProgressBar(): void;
|
|
26
|
+
reload(): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=browser_adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser_adapter.d.ts","sourceRoot":"","sources":["../../../lib/turbolinks/browser_adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,qBAAa,cAAe,YAAW,OAAO;IAC5C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,cAAqB;IAEzC,kBAAkB,CAAC,EAAE,MAAM,CAAC;gBAEhB,UAAU,EAAE,UAAU;IAIlC,iCAAiC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;IASrE,YAAY,CAAC,KAAK,EAAE,KAAK;IAMzB,mBAAmB,CAAC,KAAK,EAAE,KAAK;IAShC,sBAAsB,CAAC,KAAK,EAAE,KAAK;IAInC,qBAAqB,CAAC,KAAK,EAAE,KAAK;IAIlC,gCAAgC,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM;IAYjE,oBAAoB,CAAC,KAAK,EAAE,KAAK;IAIjC,cAAc,CAAC,KAAK,EAAE,KAAK;IAI3B,eAAe;IAIf,WAAW,CAAC,KAAK,EAAE,KAAK;IAExB,aAAa,CAAC,KAAK,EAAE,KAAK;IAI1B,yBAAyB;IAOzB,eAAe,aAEb;IAEF,eAAe;IAQf,MAAM;CAGP"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ProgressBar } from "./progress_bar";
|
|
2
|
+
import { uuid } from "./util";
|
|
3
|
+
export class BrowserAdapter {
|
|
4
|
+
constructor(controller) {
|
|
5
|
+
this.progressBar = new ProgressBar();
|
|
6
|
+
this.showProgressBar = () => {
|
|
7
|
+
this.progressBar.show();
|
|
8
|
+
};
|
|
9
|
+
this.controller = controller;
|
|
10
|
+
}
|
|
11
|
+
visitProposedToLocationWithAction(location, action) {
|
|
12
|
+
const restorationIdentifier = uuid();
|
|
13
|
+
this.controller.startVisitToLocationWithAction(location, action, restorationIdentifier);
|
|
14
|
+
}
|
|
15
|
+
visitStarted(visit) {
|
|
16
|
+
visit.issueRequest();
|
|
17
|
+
visit.changeHistory();
|
|
18
|
+
visit.loadCachedSnapshot();
|
|
19
|
+
}
|
|
20
|
+
visitRequestStarted(visit) {
|
|
21
|
+
this.progressBar.setValue(0);
|
|
22
|
+
if (visit.hasCachedSnapshot() || visit.action != "restore") {
|
|
23
|
+
this.showProgressBarAfterDelay();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.showProgressBar();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
visitRequestProgressed(visit) {
|
|
30
|
+
this.progressBar.setValue(visit.progress);
|
|
31
|
+
}
|
|
32
|
+
visitRequestCompleted(visit) {
|
|
33
|
+
visit.loadResponse();
|
|
34
|
+
}
|
|
35
|
+
visitRequestFailedWithStatusCode(visit, statusCode) {
|
|
36
|
+
switch (statusCode) {
|
|
37
|
+
// TODO
|
|
38
|
+
// case SystemStatusCode.networkFailure:
|
|
39
|
+
// case SystemStatusCode.timeoutFailure:
|
|
40
|
+
// case SystemStatusCode.contentTypeMismatch:
|
|
41
|
+
// return this.reload()
|
|
42
|
+
default:
|
|
43
|
+
return visit.loadResponse();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
visitRequestFinished(visit) {
|
|
47
|
+
this.hideProgressBar();
|
|
48
|
+
}
|
|
49
|
+
visitCompleted(visit) {
|
|
50
|
+
visit.followRedirect();
|
|
51
|
+
}
|
|
52
|
+
pageInvalidated() {
|
|
53
|
+
this.reload();
|
|
54
|
+
}
|
|
55
|
+
visitFailed(visit) { }
|
|
56
|
+
visitRendered(visit) { }
|
|
57
|
+
// Private
|
|
58
|
+
showProgressBarAfterDelay() {
|
|
59
|
+
this.progressBarTimeout = window.setTimeout(this.showProgressBar, this.controller.progressBarDelay);
|
|
60
|
+
}
|
|
61
|
+
hideProgressBar() {
|
|
62
|
+
this.progressBar.hide();
|
|
63
|
+
if (this.progressBarTimeout != null) {
|
|
64
|
+
window.clearTimeout(this.progressBarTimeout);
|
|
65
|
+
delete this.progressBarTimeout;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
reload() {
|
|
69
|
+
window.location.reload();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Adapter } from "./adapter";
|
|
2
|
+
import { History } from "./history";
|
|
3
|
+
import { Location, Locatable } from "./location";
|
|
4
|
+
import { RenderCallback } from "./renderer";
|
|
5
|
+
import { ScrollManager } from "./scroll_manager";
|
|
6
|
+
import { SnapshotCache } from "./snapshot_cache";
|
|
7
|
+
import { Action, Position } from "./types";
|
|
8
|
+
import { RenderOptions, View } from "./view";
|
|
9
|
+
import { Visit } from "./visit";
|
|
10
|
+
export type RestorationData = {
|
|
11
|
+
scrollPosition?: Position;
|
|
12
|
+
};
|
|
13
|
+
export type RestorationDataMap = {
|
|
14
|
+
[uuid: string]: RestorationData;
|
|
15
|
+
};
|
|
16
|
+
export type TimingData = {};
|
|
17
|
+
export type VisitOptions = {
|
|
18
|
+
action: Action;
|
|
19
|
+
};
|
|
20
|
+
export type VisitProperties = {
|
|
21
|
+
restorationIdentifier: string;
|
|
22
|
+
restorationData: RestorationData;
|
|
23
|
+
historyChanged: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare class Controller {
|
|
26
|
+
static supported: boolean;
|
|
27
|
+
readonly adapter: Adapter;
|
|
28
|
+
readonly history: History;
|
|
29
|
+
readonly restorationData: RestorationDataMap;
|
|
30
|
+
readonly scrollManager: ScrollManager;
|
|
31
|
+
readonly view: View;
|
|
32
|
+
cache: SnapshotCache;
|
|
33
|
+
currentVisit?: Visit;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
lastRenderedLocation?: Location;
|
|
36
|
+
location: Location;
|
|
37
|
+
progressBarDelay: number;
|
|
38
|
+
restorationIdentifier: string;
|
|
39
|
+
started: boolean;
|
|
40
|
+
start(): void;
|
|
41
|
+
disable(): void;
|
|
42
|
+
stop(): void;
|
|
43
|
+
clearCache(): void;
|
|
44
|
+
visit(location: Locatable, options?: Partial<VisitOptions>): void;
|
|
45
|
+
startVisitToLocationWithAction(location: Locatable, action: Action, restorationIdentifier: string): void;
|
|
46
|
+
setProgressBarDelay(delay: number): void;
|
|
47
|
+
startHistory(): void;
|
|
48
|
+
stopHistory(): void;
|
|
49
|
+
pushHistoryWithLocationAndRestorationIdentifier(locatable: Locatable, restorationIdentifier: string): void;
|
|
50
|
+
replaceHistoryWithLocationAndRestorationIdentifier(locatable: Locatable, restorationIdentifier: string): void;
|
|
51
|
+
historyPoppedToLocationWithRestorationIdentifier(location: Location, restorationIdentifier: string): void;
|
|
52
|
+
getCachedSnapshotForLocation(location: Location): import("./snapshot").Snapshot | undefined;
|
|
53
|
+
shouldCacheSnapshot(): boolean;
|
|
54
|
+
cacheSnapshot(): void;
|
|
55
|
+
scrollToAnchor(anchor: string): void;
|
|
56
|
+
scrollToElement(element: Element): void;
|
|
57
|
+
scrollToPosition(position: Position): void;
|
|
58
|
+
scrollPositionChanged(position: Position): void;
|
|
59
|
+
render(options: Partial<RenderOptions>, callback: RenderCallback): void;
|
|
60
|
+
viewInvalidated(): void;
|
|
61
|
+
viewWillRender(newBody: HTMLBodyElement): void;
|
|
62
|
+
viewRendered(): void;
|
|
63
|
+
pageLoaded: () => void;
|
|
64
|
+
clickCaptured: () => void;
|
|
65
|
+
clickBubbled: (event: MouseEvent) => void;
|
|
66
|
+
applicationAllowsFollowingLinkToLocation(link: Element, location: Location): boolean;
|
|
67
|
+
applicationAllowsVisitingLocation(location: Location): boolean;
|
|
68
|
+
notifyApplicationAfterClickingLinkToLocation(link: Element, location: Location): Event & {
|
|
69
|
+
data: any;
|
|
70
|
+
};
|
|
71
|
+
notifyApplicationBeforeVisitingLocation(location: Location): Event & {
|
|
72
|
+
data: any;
|
|
73
|
+
};
|
|
74
|
+
notifyApplicationAfterVisitingLocation(location: Location): Event & {
|
|
75
|
+
data: any;
|
|
76
|
+
};
|
|
77
|
+
notifyApplicationBeforeCachingSnapshot(): Event & {
|
|
78
|
+
data: any;
|
|
79
|
+
};
|
|
80
|
+
notifyApplicationBeforeRender(newBody: HTMLBodyElement): Event & {
|
|
81
|
+
data: any;
|
|
82
|
+
};
|
|
83
|
+
notifyApplicationAfterRender(): Event & {
|
|
84
|
+
data: any;
|
|
85
|
+
};
|
|
86
|
+
notifyApplicationAfterPageLoad(timing?: TimingData): Event & {
|
|
87
|
+
data: any;
|
|
88
|
+
};
|
|
89
|
+
startVisit(location: Location, action: Action, properties: Partial<VisitProperties>): void;
|
|
90
|
+
createVisit(location: Location, action: Action, properties: Partial<VisitProperties>): Visit;
|
|
91
|
+
visitCompleted(visit: Visit): void;
|
|
92
|
+
clickEventIsSignificant(event: MouseEvent): boolean;
|
|
93
|
+
getVisitableLinkForTarget(target: EventTarget | null): Element | null | undefined;
|
|
94
|
+
getVisitableLocationForLink(link: Element): Location | undefined;
|
|
95
|
+
getActionForLink(link: Element): Action;
|
|
96
|
+
elementIsVisitable(element: Element): boolean;
|
|
97
|
+
locationIsVisitable(location: Location): false | RegExpMatchArray | null;
|
|
98
|
+
getCurrentRestorationData(): RestorationData;
|
|
99
|
+
getRestorationDataForIdentifier(identifier: string): RestorationData;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../lib/turbolinks/controller.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { BrowserAdapter } from "./browser_adapter";
|
|
2
|
+
import { History } from "./history";
|
|
3
|
+
import { Location } from "./location";
|
|
4
|
+
import { ScrollManager } from "./scroll_manager";
|
|
5
|
+
import { SnapshotCache } from "./snapshot_cache";
|
|
6
|
+
import { isAction } from "./types";
|
|
7
|
+
import { closest, defer, dispatch, uuid } from "./util";
|
|
8
|
+
import { View } from "./view";
|
|
9
|
+
import { Visit } from "./visit";
|
|
10
|
+
class Controller {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.adapter = new BrowserAdapter(this);
|
|
13
|
+
this.history = new History(this);
|
|
14
|
+
this.restorationData = {};
|
|
15
|
+
this.scrollManager = new ScrollManager(this);
|
|
16
|
+
this.view = new View(this);
|
|
17
|
+
this.cache = new SnapshotCache(10);
|
|
18
|
+
this.enabled = true;
|
|
19
|
+
this.progressBarDelay = 500;
|
|
20
|
+
this.started = false;
|
|
21
|
+
// Event handlers
|
|
22
|
+
this.pageLoaded = () => {
|
|
23
|
+
this.lastRenderedLocation = this.location;
|
|
24
|
+
this.notifyApplicationAfterPageLoad();
|
|
25
|
+
};
|
|
26
|
+
this.clickCaptured = () => {
|
|
27
|
+
removeEventListener("click", this.clickBubbled, false);
|
|
28
|
+
addEventListener("click", this.clickBubbled, false);
|
|
29
|
+
};
|
|
30
|
+
this.clickBubbled = (event) => {
|
|
31
|
+
if (this.enabled && this.clickEventIsSignificant(event)) {
|
|
32
|
+
const link = this.getVisitableLinkForTarget(event.target);
|
|
33
|
+
if (link) {
|
|
34
|
+
const location = this.getVisitableLocationForLink(link);
|
|
35
|
+
if (location &&
|
|
36
|
+
this.applicationAllowsFollowingLinkToLocation(link, location)) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
const action = this.getActionForLink(link);
|
|
39
|
+
this.visit(location, { action });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
start() {
|
|
46
|
+
if (Controller.supported && !this.started) {
|
|
47
|
+
addEventListener("click", this.clickCaptured, true);
|
|
48
|
+
addEventListener("DOMContentLoaded", this.pageLoaded, false);
|
|
49
|
+
this.scrollManager.start();
|
|
50
|
+
this.startHistory();
|
|
51
|
+
this.started = true;
|
|
52
|
+
this.enabled = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
disable() {
|
|
56
|
+
this.enabled = false;
|
|
57
|
+
}
|
|
58
|
+
stop() {
|
|
59
|
+
if (this.started) {
|
|
60
|
+
removeEventListener("click", this.clickCaptured, true);
|
|
61
|
+
removeEventListener("DOMContentLoaded", this.pageLoaded, false);
|
|
62
|
+
this.scrollManager.stop();
|
|
63
|
+
this.stopHistory();
|
|
64
|
+
this.started = false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
clearCache() {
|
|
68
|
+
this.cache = new SnapshotCache(10);
|
|
69
|
+
}
|
|
70
|
+
visit(location, options = {}) {
|
|
71
|
+
location = Location.wrap(location);
|
|
72
|
+
if (this.applicationAllowsVisitingLocation(location)) {
|
|
73
|
+
if (this.locationIsVisitable(location)) {
|
|
74
|
+
const action = options.action || "advance";
|
|
75
|
+
this.adapter.visitProposedToLocationWithAction(location, action);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
window.location.href = location.toString();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
startVisitToLocationWithAction(location, action, restorationIdentifier) {
|
|
83
|
+
if (Controller.supported) {
|
|
84
|
+
const restorationData = this.getRestorationDataForIdentifier(restorationIdentifier);
|
|
85
|
+
this.startVisit(Location.wrap(location), action, { restorationData });
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
window.location.href = location.toString();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
setProgressBarDelay(delay) {
|
|
92
|
+
this.progressBarDelay = delay;
|
|
93
|
+
}
|
|
94
|
+
// History
|
|
95
|
+
startHistory() {
|
|
96
|
+
this.location = Location.currentLocation;
|
|
97
|
+
this.restorationIdentifier = uuid();
|
|
98
|
+
this.history.start();
|
|
99
|
+
this.history.replace(this.location, this.restorationIdentifier);
|
|
100
|
+
}
|
|
101
|
+
stopHistory() {
|
|
102
|
+
this.history.stop();
|
|
103
|
+
}
|
|
104
|
+
pushHistoryWithLocationAndRestorationIdentifier(locatable, restorationIdentifier) {
|
|
105
|
+
this.location = Location.wrap(locatable);
|
|
106
|
+
this.restorationIdentifier = restorationIdentifier;
|
|
107
|
+
this.history.push(this.location, this.restorationIdentifier);
|
|
108
|
+
}
|
|
109
|
+
replaceHistoryWithLocationAndRestorationIdentifier(locatable, restorationIdentifier) {
|
|
110
|
+
this.location = Location.wrap(locatable);
|
|
111
|
+
this.restorationIdentifier = restorationIdentifier;
|
|
112
|
+
this.history.replace(this.location, this.restorationIdentifier);
|
|
113
|
+
}
|
|
114
|
+
// History delegate
|
|
115
|
+
historyPoppedToLocationWithRestorationIdentifier(location, restorationIdentifier) {
|
|
116
|
+
if (this.enabled) {
|
|
117
|
+
this.location = location;
|
|
118
|
+
this.restorationIdentifier = restorationIdentifier;
|
|
119
|
+
const restorationData = this.getRestorationDataForIdentifier(restorationIdentifier);
|
|
120
|
+
this.startVisit(location, "restore", {
|
|
121
|
+
restorationIdentifier,
|
|
122
|
+
restorationData,
|
|
123
|
+
historyChanged: true,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.adapter.pageInvalidated();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Snapshot cache
|
|
131
|
+
getCachedSnapshotForLocation(location) {
|
|
132
|
+
const snapshot = this.cache.get(location);
|
|
133
|
+
return snapshot ? snapshot.clone() : snapshot;
|
|
134
|
+
}
|
|
135
|
+
shouldCacheSnapshot() {
|
|
136
|
+
return this.view.getSnapshot().isCacheable();
|
|
137
|
+
}
|
|
138
|
+
cacheSnapshot() {
|
|
139
|
+
if (this.shouldCacheSnapshot()) {
|
|
140
|
+
this.notifyApplicationBeforeCachingSnapshot();
|
|
141
|
+
const snapshot = this.view.getSnapshot();
|
|
142
|
+
const location = this.lastRenderedLocation || Location.currentLocation;
|
|
143
|
+
defer(() => this.cache.put(location, snapshot.clone()));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Scrolling
|
|
147
|
+
scrollToAnchor(anchor) {
|
|
148
|
+
const element = this.view.getElementForAnchor(anchor);
|
|
149
|
+
if (element) {
|
|
150
|
+
this.scrollToElement(element);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.scrollToPosition({ x: 0, y: 0 });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
scrollToElement(element) {
|
|
157
|
+
this.scrollManager.scrollToElement(element);
|
|
158
|
+
}
|
|
159
|
+
scrollToPosition(position) {
|
|
160
|
+
this.scrollManager.scrollToPosition(position);
|
|
161
|
+
}
|
|
162
|
+
// Scroll manager delegate
|
|
163
|
+
scrollPositionChanged(position) {
|
|
164
|
+
const restorationData = this.getCurrentRestorationData();
|
|
165
|
+
restorationData.scrollPosition = position;
|
|
166
|
+
}
|
|
167
|
+
// View
|
|
168
|
+
render(options, callback) {
|
|
169
|
+
this.view.render(options, callback);
|
|
170
|
+
}
|
|
171
|
+
viewInvalidated() {
|
|
172
|
+
this.adapter.pageInvalidated();
|
|
173
|
+
}
|
|
174
|
+
viewWillRender(newBody) {
|
|
175
|
+
this.notifyApplicationBeforeRender(newBody);
|
|
176
|
+
}
|
|
177
|
+
viewRendered() {
|
|
178
|
+
this.lastRenderedLocation = this.currentVisit.location;
|
|
179
|
+
this.notifyApplicationAfterRender();
|
|
180
|
+
}
|
|
181
|
+
// Application events
|
|
182
|
+
applicationAllowsFollowingLinkToLocation(link, location) {
|
|
183
|
+
const event = this.notifyApplicationAfterClickingLinkToLocation(link, location);
|
|
184
|
+
return !event.defaultPrevented;
|
|
185
|
+
}
|
|
186
|
+
applicationAllowsVisitingLocation(location) {
|
|
187
|
+
const event = this.notifyApplicationBeforeVisitingLocation(location);
|
|
188
|
+
return !event.defaultPrevented;
|
|
189
|
+
}
|
|
190
|
+
notifyApplicationAfterClickingLinkToLocation(link, location) {
|
|
191
|
+
return dispatch("turbolinks:click", {
|
|
192
|
+
target: link,
|
|
193
|
+
data: { url: location.absoluteURL },
|
|
194
|
+
cancelable: true,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
notifyApplicationBeforeVisitingLocation(location) {
|
|
198
|
+
return dispatch("turbolinks:before-visit", {
|
|
199
|
+
data: { url: location.absoluteURL },
|
|
200
|
+
cancelable: true,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
notifyApplicationAfterVisitingLocation(location) {
|
|
204
|
+
return dispatch("turbolinks:visit", {
|
|
205
|
+
data: { url: location.absoluteURL },
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
notifyApplicationBeforeCachingSnapshot() {
|
|
209
|
+
return dispatch("turbolinks:before-cache");
|
|
210
|
+
}
|
|
211
|
+
notifyApplicationBeforeRender(newBody) {
|
|
212
|
+
return dispatch("turbolinks:before-render", { data: { newBody } });
|
|
213
|
+
}
|
|
214
|
+
notifyApplicationAfterRender() {
|
|
215
|
+
return dispatch("turbolinks:render");
|
|
216
|
+
}
|
|
217
|
+
notifyApplicationAfterPageLoad(timing = {}) {
|
|
218
|
+
return dispatch("turbolinks:load", {
|
|
219
|
+
data: { url: this.location.absoluteURL, timing },
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// Private
|
|
223
|
+
startVisit(location, action, properties) {
|
|
224
|
+
if (this.currentVisit) {
|
|
225
|
+
this.currentVisit.cancel();
|
|
226
|
+
}
|
|
227
|
+
this.currentVisit = this.createVisit(location, action, properties);
|
|
228
|
+
this.currentVisit.start();
|
|
229
|
+
this.notifyApplicationAfterVisitingLocation(location);
|
|
230
|
+
}
|
|
231
|
+
createVisit(location, action, properties) {
|
|
232
|
+
const visit = new Visit(this, location, action, properties.restorationIdentifier);
|
|
233
|
+
visit.restorationData = { ...(properties.restorationData || {}) };
|
|
234
|
+
visit.historyChanged = !!properties.historyChanged;
|
|
235
|
+
visit.referrer = this.location;
|
|
236
|
+
return visit;
|
|
237
|
+
}
|
|
238
|
+
visitCompleted(visit) {
|
|
239
|
+
this.notifyApplicationAfterPageLoad(visit.getTimingMetrics());
|
|
240
|
+
}
|
|
241
|
+
clickEventIsSignificant(event) {
|
|
242
|
+
return !((event.target && event.target.isContentEditable) ||
|
|
243
|
+
event.defaultPrevented ||
|
|
244
|
+
event.which > 1 ||
|
|
245
|
+
event.altKey ||
|
|
246
|
+
event.ctrlKey ||
|
|
247
|
+
event.metaKey ||
|
|
248
|
+
event.shiftKey);
|
|
249
|
+
}
|
|
250
|
+
getVisitableLinkForTarget(target) {
|
|
251
|
+
if (target instanceof Element && this.elementIsVisitable(target)) {
|
|
252
|
+
return closest(target, "a[href]:not([target]):not([download])");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
getVisitableLocationForLink(link) {
|
|
256
|
+
const location = new Location(link.getAttribute("href") || "");
|
|
257
|
+
if (this.locationIsVisitable(location)) {
|
|
258
|
+
return location;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
getActionForLink(link) {
|
|
262
|
+
const action = link.getAttribute("data-turbolinks-action");
|
|
263
|
+
return isAction(action) ? action : "advance";
|
|
264
|
+
}
|
|
265
|
+
elementIsVisitable(element) {
|
|
266
|
+
const container = closest(element, "[data-turbolinks]");
|
|
267
|
+
if (container) {
|
|
268
|
+
return container.getAttribute("data-turbolinks") != "false";
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
locationIsVisitable(location) {
|
|
275
|
+
return (location.isPrefixedBy(this.view.getRootLocation()) && location.isHTML());
|
|
276
|
+
}
|
|
277
|
+
getCurrentRestorationData() {
|
|
278
|
+
return this.getRestorationDataForIdentifier(this.restorationIdentifier);
|
|
279
|
+
}
|
|
280
|
+
getRestorationDataForIdentifier(identifier) {
|
|
281
|
+
if (!(identifier in this.restorationData)) {
|
|
282
|
+
this.restorationData[identifier] = {};
|
|
283
|
+
}
|
|
284
|
+
return this.restorationData[identifier];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
Controller.supported = !!(window.history.pushState &&
|
|
288
|
+
window.requestAnimationFrame &&
|
|
289
|
+
window.addEventListener);
|
|
290
|
+
export { Controller };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type ElementDetailMap = {
|
|
2
|
+
[outerHTML: string]: ElementDetails;
|
|
3
|
+
};
|
|
4
|
+
type ElementDetails = {
|
|
5
|
+
type?: ElementType;
|
|
6
|
+
tracked: boolean;
|
|
7
|
+
elements: Element[];
|
|
8
|
+
};
|
|
9
|
+
type ElementType = "script" | "stylesheet";
|
|
10
|
+
export declare class HeadDetails {
|
|
11
|
+
readonly detailsByOuterHTML: ElementDetailMap;
|
|
12
|
+
static fromHeadElement(headElement: HTMLHeadElement | null): HeadDetails;
|
|
13
|
+
constructor(children: Element[]);
|
|
14
|
+
getTrackedElementSignature(): string;
|
|
15
|
+
getScriptElementsNotInDetails(headDetails: HeadDetails): Element[];
|
|
16
|
+
getStylesheetElementsNotInDetails(headDetails: HeadDetails): Element[];
|
|
17
|
+
getElementsMatchingTypeNotInDetails(matchedType: ElementType, headDetails: HeadDetails): Element[];
|
|
18
|
+
getProvisionalElements(): Element[];
|
|
19
|
+
getMetaValue(name: string): string | null;
|
|
20
|
+
findMetaElementByName(name: string): Element | undefined;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=head_details.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"head_details.d.ts","sourceRoot":"","sources":["../../../lib/turbolinks/head_details.ts"],"names":[],"mappings":"AAEA,KAAK,gBAAgB,GAAG;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,CAAC;AAEhE,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,WAAW,GAAG,QAAQ,GAAG,YAAY,CAAC;AAE3C,qBAAa,WAAW;IACtB,QAAQ,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;IAE9C,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,eAAe,GAAG,IAAI,GAAG,WAAW;gBAK5D,QAAQ,EAAE,OAAO,EAAE;IAqB/B,0BAA0B,IAAI,MAAM;IAMpC,6BAA6B,CAAC,WAAW,EAAE,WAAW;IAItD,iCAAiC,CAAC,WAAW,EAAE,WAAW;IAI1D,mCAAmC,CACjC,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW;IAS1B,sBAAsB,IAAI,OAAO,EAAE;IAanC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKzC,qBAAqB,CAAC,IAAI,EAAE,MAAM;CAQnC"}
|