@lingxia/vue 0.20.1 → 0.21.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/dist/hook.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type Ref } from "vue";
1
+ import { type MaybeRefOrGetter, type Ref } from "vue";
2
2
  import type { LxChannel, LxBridgeError, LxStream } from "@lingxia/bridge";
3
- import { type LxHost } from "@lingxia/bridge";
3
+ import { type LxHost, type LxLeaveHandler } from "@lingxia/bridge";
4
4
  import { type ChannelIn, type ChannelOut, type MethodParams, type OptionsArg, type ParamsOption, type ParamsSource, type StreamData, type StreamResult } from "@lingxia/bridge/invocation";
5
5
  import { type ActionMap, type PageActions, type DeepReadonly, type Snapshot } from "@lingxia/page-runtime";
6
6
  type MethodSource<T> = T | Ref<T>;
@@ -24,6 +24,14 @@ export declare function useLxPage<TData = Snapshot, TActions extends ActionMap =
24
24
  * `--lx-page-chrome-*` and container queries. Callable anywhere.
25
25
  */
26
26
  export declare function useLxHost(): Readonly<LxHost>;
27
+ /**
28
+ * Hold the page against user back and home while `dirty` — unsaved changes.
29
+ * When the user tries to leave, `onRequest` is asked: return `true` to let
30
+ * them go, `false` to stay (or a promise of either, after a dialog).
31
+ * Released when `dirty` turns false or the component unmounts. Call from
32
+ * `setup`.
33
+ */
34
+ export declare function useLxLeaveGuard(dirty: MaybeRefOrGetter<boolean>, onRequest: LxLeaveHandler): void;
27
35
  type StreamMethod = (...args: any[]) => LxStream<any, any>;
28
36
  type ChannelMethod = (...args: any[]) => Promise<LxChannel<any, any>>;
29
37
  export type LxStreamOptions<TMethod> = ParamsOption<TMethod, ParamsSource<MethodParams<TMethod>>> & {
package/dist/hook.js CHANGED
@@ -1,5 +1,5 @@
1
- import { onUnmounted, reactive, readonly, ref, unref, watch, } from "vue";
2
- import { getHost, subscribeHost } from "@lingxia/bridge";
1
+ import { onUnmounted, reactive, readonly, ref, toValue, unref, watch, } from "vue";
2
+ import { getHost, holdLeaveGuard, subscribeHost, } from "@lingxia/bridge";
3
3
  import { getMethodKey, invokeMethod, resolveParams, stableParamKey, toBridgeError, } from "@lingxia/bridge/invocation";
4
4
  import { getPageActions, getPageSnapshot, subscribePageSnapshot, } from "@lingxia/page-runtime";
5
5
  function resolveMethod(source) {
@@ -58,6 +58,31 @@ export function useLxHost() {
58
58
  }
59
59
  return readonly(hostState);
60
60
  }
61
+ /**
62
+ * Hold the page against user back and home while `dirty` — unsaved changes.
63
+ * When the user tries to leave, `onRequest` is asked: return `true` to let
64
+ * them go, `false` to stay (or a promise of either, after a dialog).
65
+ * Released when `dirty` turns false or the component unmounts. Call from
66
+ * `setup`.
67
+ */
68
+ export function useLxLeaveGuard(dirty, onRequest) {
69
+ let release;
70
+ const stop = watch(() => toValue(dirty), (value) => {
71
+ if (value) {
72
+ if (!release)
73
+ release = holdLeaveGuard(onRequest);
74
+ }
75
+ else if (release) {
76
+ release();
77
+ release = undefined;
78
+ }
79
+ }, { immediate: true });
80
+ onUnmounted(() => {
81
+ stop();
82
+ if (release)
83
+ release();
84
+ });
85
+ }
61
86
  export function useLxStream(method, options) {
62
87
  const data = ref((options?.reduce ? options.initial : undefined));
63
88
  const result = ref(undefined);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { useLxPage, useLxHost, useLxStream, useLxChannel, type LxStreamOptions, type LxReducedStreamOptions, type LxStreamState, type LxChannelOptions, type LxChannelState, } from "./hook.js";
2
- export type { LxHost } from "@lingxia/bridge";
1
+ export { useLxPage, useLxHost, useLxLeaveGuard, useLxStream, useLxChannel, type LxStreamOptions, type LxReducedStreamOptions, type LxStreamState, type LxChannelOptions, type LxChannelState, } from "./hook.js";
2
+ export type { LxHost, LxLeaveHandler, LxLeaveReason, LxLeaveRequest } from "@lingxia/bridge";
3
3
  export type { DeepReadonly } from "@lingxia/page-runtime";
4
4
  export { default as LxVideo } from "./LxVideo.vue";
5
5
  export { default as LxNativeRoot } from "./LxNativeRoot.vue";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { useLxPage, useLxHost, useLxStream, useLxChannel, } from "./hook.js";
1
+ export { useLxPage, useLxHost, useLxLeaveGuard, useLxStream, useLxChannel, } from "./hook.js";
2
2
  export { default as LxVideo } from "./LxVideo.vue";
3
3
  export { default as LxNativeRoot } from "./LxNativeRoot.vue";
4
4
  export { default as LxNativeView } from "./LxNativeView.vue";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxia/vue",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "LingXia Vue runtime and components for lxapp pages",
6
6
  "type": "module",
@@ -25,9 +25,9 @@
25
25
  "test:hooks": "rolldown -c tests/rolldown.hooks.config.mjs && node tests/page-hooks.mjs"
26
26
  },
27
27
  "dependencies": {
28
- "@lingxia/bridge": "~0.20.1",
29
- "@lingxia/elements": "~0.20.1",
30
- "@lingxia/page-runtime": "~0.20.1"
28
+ "@lingxia/bridge": "~0.21.0",
29
+ "@lingxia/elements": "~0.21.0",
30
+ "@lingxia/page-runtime": "~0.21.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "vue": ">=3.5.0"