tauri-plugin-live-activity 0.6.0 → 0.7.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.
@@ -1,6 +1,7 @@
1
1
  // Layout components for TSX. Each returns the plain node object of its `layout` builder; nothing here
2
- // imports Tauri or React, so a server can build the same layout.
3
- import { bound, button, custom, divider, gauge, hstack, image, path, progress, spacer, symbol, text, timerText, vstack, zstack, } from '../layout.js';
2
+ // imports Tauri or React, so a server can build the same layout. Every component takes the members any node
3
+ // may carry as props: `style`, `if` or `unless`, `ifStale`, `accessibility`, `transition` and `privacy`.
4
+ import { bound, button, custom, divider, gauge, hstack, image, link, path, progress, spacer, symbol, text, timerText, toggle, vstack, zstack, } from '../layout.js';
4
5
  export { bind } from '../layout.js';
5
6
  /** Children from top to bottom. */
6
7
  export function VStack({ children, ...options }) {
@@ -61,10 +62,18 @@ export function TimerText({ start, end, ...options }) {
61
62
  }
62
63
  /** A button around its one child; a tap reports `actionId` to `onAction`. */
63
64
  export function Button({ actionId, children, ...options }) {
64
- const child = Array.isArray(children) && children.length === 1 ? children[0] : children;
65
- if (!isNode(child))
66
- throw new TypeError('Button: needs exactly one node as its child');
67
- return button(actionId, child, options);
65
+ return button(actionId, only('Button', children), options);
66
+ }
67
+ /** A link around its one child; a tap opens the app with `url`, a URL or `bind(key)` for a text value that is one. */
68
+ export function Link({ url, children, ...options }) {
69
+ return link(url, only('Link', children), options);
70
+ }
71
+ /**
72
+ * A switch that shows the boolean value of `bind` beside its one child, the label; a tap reports `actionId` to
73
+ * `onAction` with `on`, the state the person asked for.
74
+ */
75
+ export function Toggle({ actionId, bind, children, ...options }) {
76
+ return toggle(actionId, bind, only('Toggle', children), options);
68
77
  }
69
78
  /** A SwiftUI view that the app registers under `name`; `props` are its inputs. */
70
79
  export function Custom({ name, ...options }) {
@@ -74,6 +83,13 @@ function isNode(value) {
74
83
  return typeof value === 'object' && value !== null && !Array.isArray(value)
75
84
  && typeof value.type === 'string';
76
85
  }
86
+ /** The one child of a button, a link or a toggle; it may come as an array of one. */
87
+ function only(component, children) {
88
+ const child = Array.isArray(children) && children.length === 1 ? children[0] : children;
89
+ if (!isNode(child))
90
+ throw new TypeError(`${component}: needs exactly one node as its child`);
91
+ return child;
92
+ }
77
93
  function nodes(component, children) {
78
94
  const found = [];
79
95
  const visit = (child) => {
@@ -1,4 +1,4 @@
1
- import type { LayoutBound, LayoutButtonNode, LayoutCustomNode, LayoutDividerNode, LayoutGaugeNode, LayoutHStackNode, LayoutImageNode, LayoutImageSource, LayoutNode, LayoutPathNode, LayoutProgressNode, LayoutSpacerNode, LayoutSymbolNode, LayoutTextNode, LayoutTimerTextNode, LayoutVStackNode, LayoutZStackNode } from './types.js';
1
+ import type { LayoutBindable, LayoutBound, LayoutButtonNode, LayoutCustomNode, LayoutDividerNode, LayoutGaugeNode, LayoutHStackNode, LayoutImageNode, LayoutImageSource, LayoutLinkNode, LayoutNode, LayoutPathNode, LayoutProgressNode, LayoutSpacerNode, LayoutSymbolNode, LayoutTextNode, LayoutTimerTextNode, LayoutToggleNode, LayoutVStackNode, LayoutZStackNode } from './types.js';
2
2
  /** The members of a node that its builder does not take as arguments. */
3
3
  type Options<N extends LayoutNode, Argument extends keyof N = never> = N extends unknown ? Omit<N, 'type' | Argument> : never;
4
4
  /** Children from top to bottom. */
@@ -32,12 +32,23 @@ export declare function gauge(key: string, options?: Options<LayoutGaugeNode, 'b
32
32
  export declare function timerText(start: string, end: string, options?: Options<LayoutTimerTextNode, 'start' | 'end'>): LayoutTimerTextNode;
33
33
  /** A button around `child`; a tap reports `actionId` to `onAction`. */
34
34
  export declare function button(actionId: string, child: LayoutNode, options?: Options<LayoutButtonNode, 'actionId' | 'child'>): LayoutButtonNode;
35
+ /**
36
+ * A link around `child`: a tap opens the app with `url`, a URL such as `myapp://delivery/7` or `bind(key)` for a
37
+ * text value that is one.
38
+ */
39
+ export declare function link(url: LayoutBindable<string>, child: LayoutNode, options?: Options<LayoutLinkNode, 'url' | 'child'>): LayoutLinkNode;
40
+ /**
41
+ * A switch that shows the boolean value of `key` beside `child`, its label; a tap reports `actionId` to `onAction`
42
+ * with `on`, the state the person asked for.
43
+ */
44
+ export declare function toggle(actionId: string, key: string, child: LayoutNode, options?: Options<LayoutToggleNode, 'actionId' | 'bind' | 'child'>): LayoutToggleNode;
35
45
  /** A SwiftUI view that the app registers under `name` in LiveActivityCustomViews.swift; `props` are its inputs. */
36
46
  export declare function custom(name: string, options?: Options<LayoutCustomNode, 'name'>): LayoutCustomNode;
37
47
  /**
38
- * A style member, `layout.background` or `layout.keyline` that reads the value of `key` on every render,
39
- * so an update can change it: `{ color: bind('tone') }`. Only `color`, `background`, `tint`, `opacity`,
40
- * `size`, `weight` and `cornerRadius` can be bound, and the props of a `custom` node.
48
+ * A member that reads the value of `key` on every render, so an update can change it: `{ color: bind('tone') }`.
49
+ * Only these can be bound: `color`, `background`, `tint`, `opacity`, `size`, `weight` and `cornerRadius` of a style,
50
+ * `layout.background`, `layout.keyline` and `layout.url`, the `url` of a link, the `label`, `value` and `hint` of a
51
+ * node's `accessibility`, and the props of a `custom` node.
41
52
  */
42
53
  export declare function bind(key: string): LayoutBound;
43
54
  export {};
package/dist-js/layout.js CHANGED
@@ -2,7 +2,9 @@
2
2
  function given(options) {
3
3
  return Object.fromEntries(Object.entries(options ?? {}).filter(([, value]) => value !== undefined));
4
4
  }
5
- // The builders return plain node objects. They do not validate: the plugin checks the whole request.
5
+ // The builders return plain node objects. They do not validate: the plugin checks the whole request. The options
6
+ // of every builder take the members any node may carry: `style`, `if` or `unless`, `ifStale`, `accessibility`,
7
+ // `transition` and `privacy`.
6
8
  /** Children from top to bottom. */
7
9
  export function vstack(children, options) {
8
10
  return { type: 'vstack', children, ...given(options) };
@@ -62,14 +64,29 @@ export function timerText(start, end, options) {
62
64
  export function button(actionId, child, options) {
63
65
  return { type: 'button', actionId, child, ...given(options) };
64
66
  }
67
+ /**
68
+ * A link around `child`: a tap opens the app with `url`, a URL such as `myapp://delivery/7` or `bind(key)` for a
69
+ * text value that is one.
70
+ */
71
+ export function link(url, child, options) {
72
+ return { type: 'link', url, child, ...given(options) };
73
+ }
74
+ /**
75
+ * A switch that shows the boolean value of `key` beside `child`, its label; a tap reports `actionId` to `onAction`
76
+ * with `on`, the state the person asked for.
77
+ */
78
+ export function toggle(actionId, key, child, options) {
79
+ return { type: 'toggle', actionId, bind: key, child, ...given(options) };
80
+ }
65
81
  /** A SwiftUI view that the app registers under `name` in LiveActivityCustomViews.swift; `props` are its inputs. */
66
82
  export function custom(name, options) {
67
83
  return { type: 'custom', name, ...given(options) };
68
84
  }
69
85
  /**
70
- * A style member, `layout.background` or `layout.keyline` that reads the value of `key` on every render,
71
- * so an update can change it: `{ color: bind('tone') }`. Only `color`, `background`, `tint`, `opacity`,
72
- * `size`, `weight` and `cornerRadius` can be bound, and the props of a `custom` node.
86
+ * A member that reads the value of `key` on every render, so an update can change it: `{ color: bind('tone') }`.
87
+ * Only these can be bound: `color`, `background`, `tint`, `opacity`, `size`, `weight` and `cornerRadius` of a style,
88
+ * `layout.background`, `layout.keyline` and `layout.url`, the `url` of a link, the `label`, `value` and `hint` of a
89
+ * node's `accessibility`, and the props of a `custom` node.
73
90
  */
74
91
  export function bind(key) {
75
92
  return { bind: key };
@@ -1,4 +1,4 @@
1
- import type { EndPolicy, Fallback, Layout, LayoutActivityRecord, LayoutAndroidOptions, LayoutEndInput, LayoutPush, LayoutStartInput, LayoutStyle, LayoutUpdateInput, LayoutValues, LiveActivityError, PushTokenEvent, UpdatedEvent } from '../types.js';
1
+ import type { EndPolicy, Fallback, Layout, LayoutActivityRecord, LayoutAndroidOptions, LayoutEndInput, LayoutIosOptions, LayoutPush, LayoutStartInput, LayoutStyle, LayoutUpdateInput, LayoutValues, LiveActivityError, PushTokenEvent, UpdatedEvent } from '../types.js';
2
2
  export interface SessionOptions {
3
3
  /** The app's key of the activity; another key ends the running activity and starts one for it. */
4
4
  readonly activityKey: string;
@@ -14,6 +14,8 @@ export interface SessionOptions {
14
14
  readonly fallback?: Fallback;
15
15
  /** Read at start. */
16
16
  readonly android?: LayoutAndroidOptions;
17
+ /** Read at start: what only iOS reads, such as a transient activity. */
18
+ readonly ios?: LayoutIosOptions;
17
19
  /** Read at start: what the activity asks ActivityKit for, a push token or a channel (iOS). */
18
20
  readonly push?: LayoutPush;
19
21
  /** False ends the activity, and true starts it again. Defaults to true. */
@@ -95,6 +95,7 @@ export class Session {
95
95
  snapshot: { revision: 0, values },
96
96
  ...(options.styles === undefined ? {} : { styles: options.styles }),
97
97
  ...(options.android === undefined ? {} : { android: options.android }),
98
+ ...(options.ios === undefined ? {} : { ios: options.ios }),
98
99
  ...(options.push === undefined ? {} : { push: options.push }),
99
100
  };
100
101
  this.failedKey = undefined;