@inglorious/web 6.29.0 → 6.30.0

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/types/mount.d.ts CHANGED
@@ -42,7 +42,7 @@ declare module "@inglorious/store" {
42
42
  export type { Api }
43
43
 
44
44
  /**
45
- * Root error-boundary options for `mount`.
45
+ * Options for `mount`.
46
46
  */
47
47
  export interface MountOptions<
48
48
  TEntity extends BaseEntity = BaseEntity,
@@ -59,6 +59,11 @@ export interface MountOptions<
59
59
  error: unknown,
60
60
  api: Api<TEntity, TState>,
61
61
  ) => TemplateResult | null
62
+ /**
63
+ * Whether markup already in the element, as a server-rendered page has, is hydrated
64
+ * rather than replaced. Defaults to `true`.
65
+ */
66
+ hydrate?: boolean
62
67
  /**
63
68
  * Whether navigations are announced to screen readers and move focus to the top of the
64
69
  * new page. Only apps with the `Router` type navigate. Defaults to `true`.
@@ -72,12 +77,13 @@ export interface MountOptions<
72
77
  }
73
78
 
74
79
  /**
75
- * Mounts a lit-html template to the DOM and subscribes to a store for re-rendering.
80
+ * Mounts a lit-html template to the DOM and subscribes to a store for re-rendering,
81
+ * hydrating markup already in the element. Once mounted, it notifies `init`.
76
82
  * @param store The application state store.
77
83
  * @param renderFn The root render function that receives the API and returns a template.
78
84
  * @param element The DOM element to mount the template to.
79
- * @param options Root error-boundary options (`onError`, `fallback`).
80
- * @returns An unsubscribe function.
85
+ * @param options Error-boundary, hydration and navigation options.
86
+ * @returns An unsubscribe function, once mounted.
81
87
  */
82
88
  export function mount<
83
89
  TEntity extends BaseEntity = BaseEntity,
@@ -88,4 +94,4 @@ export function mount<
88
94
  renderFn: (api: Api<TEntity, TState, TEvents>) => TemplateResult | null,
89
95
  element: HTMLElement | DocumentFragment,
90
96
  options?: MountOptions<TEntity, TState>,
91
- ): () => void
97
+ ): Promise<() => void>
@@ -1,7 +1,5 @@
1
- import { Api } from "../mount"
2
-
3
- /** What `watchAppLinks` needs of `App` from `@capacitor/app`. */
4
- export interface AppLinksApp {
1
+ /** What `createAppLinks` needs of `App` from `@capacitor/app`. */
2
+ export interface AppLinksPlugin {
5
3
  getLaunchUrl(): Promise<{ url: string } | undefined>
6
4
  addListener(
7
5
  event: "appUrlOpen",
@@ -9,19 +7,29 @@ export interface AppLinksApp {
9
7
  ): Promise<{ remove(): Promise<void> }>
10
8
  }
11
9
 
12
- export interface WatchAppLinksOptions {
10
+ export interface AppLinksConfig {
11
+ plugin: AppLinksPlugin
13
12
  /** The router entity to notify. Defaults to `router`. */
13
+ router?: string
14
+ }
15
+
16
+ export interface AppLinksEntity {
14
17
  id?: string
18
+ type: string
19
+ /** The last link opened, or `null`. */
20
+ url: string | null
21
+ }
22
+
23
+ export type AppLinksType = {
24
+ create(entity: AppLinksEntity): void
25
+ destroy(entity: AppLinksEntity): void
26
+ /** Sends the router to the link's path. */
27
+ appLinkOpen(entity: AppLinksEntity, url: string): void
15
28
  }
16
29
 
17
30
  /**
18
- * Opens Universal Links and App Links in the router, both the link that
19
- * started the app and those that arrive while it runs, notifying
20
- * `#${id}:navigate`. Does nothing outside a native app.
21
- * @returns A function that stops listening.
31
+ * The type that opens Universal Links and App Links in the router, both the
32
+ * link that started the app and those that arrive while it runs. Does nothing
33
+ * outside a native app.
22
34
  */
23
- export declare function watchAppLinks(
24
- app: AppLinksApp,
25
- store: Pick<Api, "notify">,
26
- options?: WatchAppLinksOptions,
27
- ): () => Promise<void>
35
+ export declare function createAppLinks(config: AppLinksConfig): AppLinksType
@@ -1,5 +1,5 @@
1
- /** What `watchBackButton` needs of `App` from `@capacitor/app`. */
2
- export interface BackButtonApp {
1
+ /** What `createBackButton` needs of `App` from `@capacitor/app`. */
2
+ export interface BackButtonPlugin {
3
3
  exitApp(): Promise<void>
4
4
  addListener(
5
5
  event: "backButton",
@@ -7,18 +7,28 @@ export interface BackButtonApp {
7
7
  ): Promise<{ remove(): Promise<void> }>
8
8
  }
9
9
 
10
- export interface WatchBackButtonOptions {
10
+ export interface BackButtonConfig {
11
+ plugin: BackButtonPlugin
12
+ }
13
+
14
+ export interface BackButtonEntity {
15
+ id?: string
16
+ type: string
11
17
  /** The top-level paths, where back closes the app. Defaults to `["/"]`. */
12
- rootPaths?: string[]
18
+ rootPaths: string[]
19
+ }
20
+
21
+ export type BackButtonType = {
22
+ create(entity: BackButtonEntity): void
23
+ destroy(entity: BackButtonEntity): void
24
+ /** Back in history, or closes the app on a root path or with no history left. */
25
+ backButtonPress(entity: BackButtonEntity, event: { canGoBack: boolean }): void
13
26
  }
14
27
 
15
28
  /**
16
- * Android's back button and back gesture: back in history, or closes the app
17
- * on a root path or when there is no history left. Does nothing outside a
18
- * native app.
19
- * @returns A function that stops listening.
29
+ * The type behind Android's back button and back gesture. Does nothing outside
30
+ * a native app.
20
31
  */
21
- export declare function watchBackButton(
22
- app: BackButtonApp,
23
- options?: WatchBackButtonOptions,
24
- ): () => Promise<void>
32
+ export declare function createBackButton(
33
+ config: BackButtonConfig,
34
+ ): BackButtonType
@@ -1,5 +1,3 @@
1
- import { Api } from "../mount"
2
-
3
1
  /** What a publisher puts at the manifest URL. */
4
2
  export interface LiveUpdateManifest {
5
3
  /** Grows with every bundle: newer than the running release means wanted. */
@@ -14,7 +12,7 @@ export interface LiveUpdateManifest {
14
12
  signature?: string
15
13
  }
16
14
 
17
- /** What the live update types need of `LiveUpdate` from `@capawesome/capacitor-live-update`. */
15
+ /** What `createLiveUpdate` needs of `LiveUpdate` from `@capawesome/capacitor-live-update`. */
18
16
  export interface LiveUpdatePlugin {
19
17
  ready(): Promise<unknown>
20
18
  reload(): Promise<void>
@@ -29,7 +27,7 @@ export interface LiveUpdatePlugin {
29
27
  setNextBundle(options: { bundleId: string | null }): Promise<void>
30
28
  }
31
29
 
32
- /** What `watchLiveUpdate` needs of `App` from `@capacitor/app`. */
30
+ /** What `createLiveUpdate` needs of `App` from `@capacitor/app`. */
33
31
  export interface LiveUpdateApp {
34
32
  getInfo(): Promise<{ build: string }>
35
33
  addListener(
@@ -38,50 +36,45 @@ export interface LiveUpdateApp {
38
36
  ): Promise<{ remove(): Promise<void> }>
39
37
  }
40
38
 
39
+ export interface LiveUpdateConfig {
40
+ plugin: LiveUpdatePlugin
41
+ /** Needed to check for bundles; without it the type only offers `liveUpdateApply`. */
42
+ app?: LiveUpdateApp
43
+ manifestUrl?: string
44
+ /** The release of the running web code. None for a development build. */
45
+ release?: number
46
+ /** How often to check for a new bundle. Defaults to one hour. */
47
+ checkEveryMs?: number
48
+ }
49
+
41
50
  export interface LiveUpdateEntity {
42
51
  id?: string
43
52
  type: string
44
53
  /** A bundle is downloaded and waits for the next trip to the background. */
45
54
  isUpdateReady: boolean
55
+ /** The release of the downloaded bundle, or `null`. */
56
+ pendingRelease: number | null
46
57
  }
47
58
 
48
59
  export type LiveUpdateType = {
49
60
  create(entity: LiveUpdateEntity): void
50
- liveUpdateReady(entity: LiveUpdateEntity): void
61
+ destroy(entity: LiveUpdateEntity): void
62
+ liveUpdateReady(entity: LiveUpdateEntity, release: number): void
51
63
  /** Moves over to the downloaded bundle now, reloading the app. */
52
64
  liveUpdateApply(): void
53
65
  }
54
66
 
55
- /** The type that offers a downloaded live update. */
56
- export declare function createLiveUpdate(config: {
57
- plugin: Pick<LiveUpdatePlugin, "reload">
58
- }): LiveUpdateType
67
+ /**
68
+ * The type that keeps a native app on its latest published web code, applying
69
+ * a downloaded bundle on the next trip to the background. Does nothing outside
70
+ * a native app.
71
+ */
72
+ export declare function createLiveUpdate(
73
+ config: LiveUpdateConfig,
74
+ ): LiveUpdateType
59
75
 
60
76
  /** Whether a published bundle should replace the running one. */
61
77
  export declare function isLiveUpdateWanted(
62
78
  manifest: Pick<LiveUpdateManifest, "release" | "minBuild"> | null,
63
79
  installed: { release: number; build: number },
64
80
  ): boolean
65
-
66
- export interface WatchLiveUpdateOptions {
67
- plugin: LiveUpdatePlugin
68
- app: LiveUpdateApp
69
- /** Where to announce a downloaded bundle. */
70
- store?: Pick<Api, "notify">
71
- manifestUrl: string
72
- /** The release of the running web code. */
73
- release: number
74
- /** The LiveUpdate entity to announce to. Defaults to `liveUpdate`. */
75
- id?: string
76
- /** How often to check for a new bundle. Defaults to one hour. */
77
- checkEveryMs?: number
78
- }
79
-
80
- /**
81
- * Keeps a native app on its latest published web code, applying a downloaded
82
- * bundle on the next trip to the background. Does nothing outside a native app.
83
- * @returns A function that stops watching.
84
- */
85
- export declare function watchLiveUpdate(
86
- options: WatchLiveUpdateOptions,
87
- ): () => Promise<void>
@@ -1,4 +1,4 @@
1
- /** What `watchSystemBars` needs of `SystemBars` from `@capacitor/core`. */
1
+ /** What `createSystemBars` needs of `SystemBars` from `@capacitor/core`. */
2
2
  export interface SystemBarsPlugin {
3
3
  setStyle(options: { style: SystemBarsStyle }): Promise<void>
4
4
  }
@@ -6,15 +6,31 @@ export interface SystemBarsPlugin {
6
6
  /** `SystemBarsStyle` from `@capacitor/core`: the colour of the background. */
7
7
  export type SystemBarsStyle = "DARK" | "LIGHT" | "DEFAULT"
8
8
 
9
+ export interface SystemBarsConfig {
10
+ plugin: SystemBarsPlugin
11
+ }
12
+
13
+ export interface SystemBarsEntity {
14
+ id?: string
15
+ type: string
16
+ /** The bars' current style, or `null` outside a native app. */
17
+ style: SystemBarsStyle | null
18
+ }
19
+
20
+ export type SystemBarsType = {
21
+ create(entity: SystemBarsEntity): void
22
+ destroy(entity: SystemBarsEntity): void
23
+ systemBarsStyleChange(entity: SystemBarsEntity, style: SystemBarsStyle): void
24
+ }
25
+
9
26
  /**
10
- * Keeps the status and navigation bars readable on the app's own colours, as
11
- * its `color-scheme` sets them, and follows theme changes. Does nothing
12
- * outside a native app.
13
- * @returns A function that stops following.
27
+ * The type that keeps the status and navigation bars readable on the app's own
28
+ * colours, as its `color-scheme` sets them, and follows theme changes. Does
29
+ * nothing outside a native app.
14
30
  */
15
- export declare function watchSystemBars(
16
- systemBars: SystemBarsPlugin,
17
- ): () => void
31
+ export declare function createSystemBars(
32
+ config: SystemBarsConfig,
33
+ ): SystemBarsType
18
34
 
19
35
  /**
20
36
  * The bars' style for a `color-scheme` value: `"DARK"` on a dark-only page,
@@ -17,8 +17,19 @@ export interface NativeUpdateAdapter {
17
17
  ): Promise<NativeUpdateRequirement | null>
18
18
  }
19
19
 
20
+ /** What `createNativeUpdate` needs of `App` from `@capacitor/app`. */
21
+ export interface NativeUpdatePlugin {
22
+ getInfo(): Promise<{ build: string }>
23
+ addListener(
24
+ event: "resume",
25
+ listener: () => void,
26
+ ): Promise<{ remove(): Promise<void> }>
27
+ }
28
+
20
29
  export interface NativeUpdateConfig {
21
30
  adapter: NativeUpdateAdapter
31
+ /** Checks the installed build at launch and on every resume, in a native app. */
32
+ plugin?: NativeUpdatePlugin
22
33
  }
23
34
 
24
35
  export interface NativeUpdateEntity {
@@ -36,6 +47,7 @@ export interface NativeUpdateCheckPayload {
36
47
 
37
48
  export type NativeUpdateType = {
38
49
  create(entity: NativeUpdateEntity): void
50
+ destroy(entity: NativeUpdateEntity): void
39
51
  /** Compares the installed build with the platform's minimum. */
40
52
  nativeUpdateCheck(
41
53
  entity: NativeUpdateEntity,
@@ -55,28 +67,3 @@ export type NativeUpdateType = {
55
67
  export declare function createNativeUpdate(
56
68
  config: NativeUpdateConfig,
57
69
  ): NativeUpdateType
58
-
59
- /** What `watchNativeUpdate` needs of `App` from `@capacitor/app`. */
60
- export interface NativeApp {
61
- getInfo(): Promise<{ build: string }>
62
- addListener(
63
- event: "resume",
64
- listener: () => void,
65
- ): Promise<{ remove(): Promise<void> }>
66
- }
67
-
68
- export interface WatchNativeUpdateOptions {
69
- /** The NativeUpdate entity to notify. Defaults to `nativeUpdate`. */
70
- id?: string
71
- }
72
-
73
- /**
74
- * Checks the installed build at launch and on every resume, notifying
75
- * `#${id}:nativeUpdateCheck`. Does nothing outside a native app.
76
- * @returns A function that stops watching.
77
- */
78
- export declare function watchNativeUpdate(
79
- app: NativeApp,
80
- store: Pick<Api, "notify">,
81
- options?: WatchNativeUpdateOptions,
82
- ): () => Promise<void>
package/types/pwa.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { Api } from "./mount"
1
+ export interface PwaUpdateConfig {
2
+ /** How often to check for a new version. Defaults to one hour. */
3
+ checkEveryMs?: number
4
+ }
2
5
 
3
6
  export interface PwaUpdateEntity {
4
7
  id?: string
@@ -9,31 +12,19 @@ export interface PwaUpdateEntity {
9
12
 
10
13
  export type PwaUpdateType = {
11
14
  create(entity: PwaUpdateEntity): void
15
+ destroy(entity: PwaUpdateEntity): void
16
+ pwaUpdateReady(entity: PwaUpdateEntity): void
12
17
  /** Moves over to the waiting version now, reloading the page. */
13
18
  pwaUpdateApply(): void
14
- pwaUpdateReady(entity: PwaUpdateEntity): void
15
- }
16
-
17
- export declare const PwaUpdate: PwaUpdateType
18
-
19
- export interface WatchPwaUpdateOptions {
20
- /** The PwaUpdate entity to announce to. Defaults to `pwaUpdate`. */
21
- id?: string
22
- /** How often to check for a new version. Defaults to one hour. */
23
- checkEveryMs?: number
24
19
  }
25
20
 
26
21
  /**
27
- * Keeps an installed PWA on its latest version, applying a downloaded one at
28
- * boot and on each trip to or from the background. A version that lands
29
- * mid-session is announced to `store` as `#${id}:pwaUpdateReady`.
30
- * @returns A function that stops watching.
22
+ * The type that keeps an installed PWA on its latest version, applying a
23
+ * downloaded one at boot and on each trip to or from the background, and
24
+ * setting `isUpdateReady` when a version lands mid-session. Does nothing in a
25
+ * native app or without a service worker.
31
26
  */
32
- export declare function watchPwaUpdate(
33
- registration: ServiceWorkerRegistration,
34
- store?: Pick<Api, "notify">,
35
- options?: WatchPwaUpdateOptions,
36
- ): () => void
27
+ export declare function createPwaUpdate(config?: PwaUpdateConfig): PwaUpdateType
37
28
 
38
29
  /** Moves the page over to the waiting version and reloads. */
39
30
  export declare function applyPwaUpdate(
@@ -1,17 +0,0 @@
1
- /**
2
- * @typedef {import("../../types/pwa.js").PwaUpdateEntity} PwaUpdateEntity
3
- */
4
-
5
- import { applyPwaUpdate } from "./update.js"
6
-
7
- export function create(entity) {
8
- entity.isUpdateReady ??= false
9
- }
10
-
11
- export function pwaUpdateApply() {
12
- applyPwaUpdate()
13
- }
14
-
15
- export function pwaUpdateReady(entity) {
16
- entity.isUpdateReady = true
17
- }