@symbiote-native/svelte 3.0.5 → 3.1.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.
@@ -0,0 +1 @@
1
+ export declare function hostProps(props: Record<string, unknown>): (node: unknown) => void;
@@ -0,0 +1,9 @@
1
+ import { ShimElement } from './dom-shim/index.js';
2
+ // A dynamic tag (`<svelte:element this={...}>`) sets `p` as a plain attribute, which never reaches
3
+ // the engine, so the bag goes through an attachment that assigns the property on the raw element
4
+ export function hostProps(props) {
5
+ return node => {
6
+ if (node instanceof ShimElement)
7
+ node.p = props;
8
+ };
9
+ }
@@ -2,3 +2,4 @@ export { mount, unmount } from './render';
2
2
  export { mountDescriptorChildren, createDescriptorChildrenSync, } from './descriptor-to-svelte';
3
3
  export type { IDescriptorChildrenMount } from './descriptor-to-svelte';
4
4
  export type { ShimElement } from './dom-shim';
5
+ export { hostProps } from './host-props';
@@ -25,3 +25,4 @@
25
25
  // packages/slider/src/svelte/slider/index.svelte's header for the full reasoning.
26
26
  export { mount, unmount } from './render.js';
27
27
  export { mountDescriptorChildren, createDescriptorChildrenSync, } from './descriptor-to-svelte.js';
28
+ export { hostProps } from './host-props.js';
@@ -0,0 +1,8 @@
1
+ export type IEventValueSource<TValue, TEvent extends string = string> = {
2
+ addListener: (event: TEvent, listener: (value: TValue) => void) => {
3
+ remove: () => void;
4
+ };
5
+ };
6
+ export declare function createEventValueHook<TSource extends IEventValueSource<TValue, TEvent>, TValue, TEvent extends string = string>(event: TEvent, getValue: (source: TSource) => TValue): (getSource: () => TSource) => {
7
+ readonly current: TValue;
8
+ };
@@ -0,0 +1,20 @@
1
+ // Svelte lifecycle for a value that follows a native event, boxed getter like
2
+ // `use-color-scheme.svelte.ts`
3
+ export function createEventValueHook(event, getValue) {
4
+ return function useEventValue(getSource) {
5
+ let value = $state(getValue(getSource()));
6
+ $effect(() => {
7
+ const source = getSource();
8
+ value = getValue(source);
9
+ const subscription = source.addListener(event, next => {
10
+ value = next;
11
+ });
12
+ return () => subscription.remove();
13
+ });
14
+ return {
15
+ get current() {
16
+ return value;
17
+ },
18
+ };
19
+ };
20
+ }
@@ -0,0 +1,6 @@
1
+ import { type IPermissionHookBehavior, type IPermissionHookMethods } from '@symbiote-native/engine';
2
+ export declare function createPermissionHook<TPermission, TOptions extends object>(methods: IPermissionHookMethods<TPermission, TOptions>): (behavior?: IPermissionHookBehavior, methodOptions?: TOptions) => {
3
+ readonly status: TPermission | null;
4
+ requestPermission: () => Promise<TPermission>;
5
+ getPermission: () => Promise<TPermission>;
6
+ };
@@ -0,0 +1,23 @@
1
+ // Svelte lifecycle for the shared permission API, boxed getter because a bare `$state` can't cross
2
+ // a module boundary. Packages reach it through the `@symbiote-native/svelte/runes/*` subpath
3
+ import { createPermissionApi, fetchInitialPermission, } from '@symbiote-native/engine';
4
+ export function createPermissionHook(methods) {
5
+ return function usePermission(behavior, methodOptions) {
6
+ let status = $state(null);
7
+ const api = createPermissionApi(methods, value => {
8
+ status = value;
9
+ });
10
+ $effect(() => {
11
+ fetchInitialPermission(methods, behavior, methodOptions, response => {
12
+ status = response;
13
+ });
14
+ });
15
+ return {
16
+ get status() {
17
+ return status;
18
+ },
19
+ requestPermission: () => api.request(methodOptions),
20
+ getPermission: () => api.get(methodOptions),
21
+ };
22
+ };
23
+ }
@@ -0,0 +1,8 @@
1
+ export type IResourceHookController<TArgs extends unknown[], TResource> = {
2
+ resolve: (...args: TArgs) => TResource;
3
+ flushDispose: (current: TResource) => void;
4
+ dispose: () => void;
5
+ };
6
+ export declare function createResourceHook<TArgs extends unknown[], TResource>(createController: () => IResourceHookController<TArgs, TResource>): (getArgs: () => TArgs) => {
7
+ readonly current: TResource;
8
+ };
@@ -0,0 +1,19 @@
1
+ // Svelte lifecycle for a disposable resource derived from reactive args, boxed getter as in
2
+ // `use-color-scheme.svelte.ts`
3
+ export function createResourceHook(createController) {
4
+ return function useResource(getArgs) {
5
+ const controller = createController();
6
+ const resource = $derived(controller.resolve(...getArgs()));
7
+ $effect(() => {
8
+ controller.flushDispose(resource);
9
+ });
10
+ $effect(() => {
11
+ return () => controller.dispose();
12
+ });
13
+ return {
14
+ get current() {
15
+ return resource;
16
+ },
17
+ };
18
+ };
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbiote-native/svelte",
3
- "version": "3.0.5",
3
+ "version": "3.1.0",
4
4
  "description": "SymbioteNative's Svelte adapter — a DOM shim over stock compiled Svelte output driving real native iOS/Android views through the same engine as every other adapter.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -60,6 +60,18 @@
60
60
  "types": "./build/scope-token.d.ts",
61
61
  "default": "./build/scope-token.js"
62
62
  },
63
+ "./runes/create-permission-hook": {
64
+ "types": "./build/runes/create-permission-hook.svelte.d.ts",
65
+ "default": "./build/runes/create-permission-hook.svelte.js"
66
+ },
67
+ "./runes/create-resource-hook": {
68
+ "types": "./build/runes/create-resource-hook.svelte.d.ts",
69
+ "default": "./build/runes/create-resource-hook.svelte.js"
70
+ },
71
+ "./runes/create-event-value-hook": {
72
+ "types": "./build/runes/create-event-value-hook.svelte.d.ts",
73
+ "default": "./build/runes/create-event-value-hook.svelte.js"
74
+ },
63
75
  "./metro-svelte-transformer": "./metro-svelte-transformer.cjs",
64
76
  "./metro-css-parser": "./metro-css-parser.cjs"
65
77
  },
@@ -73,22 +85,22 @@
73
85
  },
74
86
  "dependencies": {
75
87
  "typescript": "~6.0.0",
76
- "@symbiote-native/components": "3.1.3",
77
- "@symbiote-native/css-parser": "0.5.2"
88
+ "@symbiote-native/components": "3.1.4",
89
+ "@symbiote-native/css-parser": "0.5.3"
78
90
  },
79
91
  "peerDependencies": {
80
92
  "svelte": ">=5.56.0",
81
93
  "react-native": ">=0.86",
82
- "@symbiote-native/engine": "^1.4.0"
94
+ "@symbiote-native/engine": "^1.5.0"
83
95
  },
84
96
  "devDependencies": {
85
97
  "@vue/runtime-core": "^3.5.13",
86
98
  "react": "19.2.3",
87
99
  "svelte": "^5.56.0",
88
- "@symbiote-native/engine": "1.4.0",
89
- "@symbiote-native/test-utils": "0.4.5",
90
- "@symbiote-native/react": "3.1.0",
91
- "@symbiote-native/vue": "3.1.0"
100
+ "@symbiote-native/engine": "1.5.0",
101
+ "@symbiote-native/react": "3.2.0",
102
+ "@symbiote-native/test-utils": "0.4.6",
103
+ "@symbiote-native/vue": "3.2.0"
92
104
  },
93
105
  "scripts": {
94
106
  "typecheck": "tsc --build",