@superrouteca/sindoor-react 0.0.0-stage → 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Superroute SDK License
2
+
3
+ Copyright (c) 2026 Superroute Inc. All rights reserved, except as granted below.
4
+
5
+ 1. Permission is granted, free of charge, to any person obtaining a copy of this software and its documentation
6
+ (the "Software") to install, use, copy and distribute the Software, including as part of their own products and
7
+ services, to connect to Superroute services, on any other platform, and in their own commercial projects.
8
+
9
+ 2. The Software may not be sold on its own, whether alone or as the main part of a product whose value lies in the
10
+ Software rather than in the product built with it.
11
+
12
+ 3. The copyright notices, this license and the attribution of the Software to Superroute may not be removed or
13
+ changed, and must be kept in every copy or substantial portion of the Software that is distributed.
14
+
15
+ 4. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
16
+ THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
18
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
20
+
21
+ 5. Use of Superroute services through the Software is governed by the terms of those services.
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @superrouteca/sindoor-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ```jsx
4
+ import { SMap, useSMap } from '@superrouteca/smap-react';
5
+ import { SindoorClient } from '@superrouteca/sindoor';
6
+ import { useSindoorSite, useSindoorLocator, SindoorNavigator } from '@superrouteca/sindoor-react';
7
+
8
+ const client = new SindoorClient({ key: 'smk_…' });
9
+
10
+ function Indoor({ target }) {
11
+ const map = useSMap();
12
+ const { site } = useSindoorSite({ site: 'op-12-mall', client });
13
+ const { estimate, observe } = useSindoorLocator(site);
14
+ // feed observe({t, kind: 'scan' | 'steps' | 'heading' | 'ble' | …}) from your sensors
15
+ return <SindoorNavigator map={map} site={site} position={estimate} target={target} />;
16
+ }
17
+
18
+ export default () => <SMap apiKey="smk_…"><Indoor target="fixture:checkout" /></SMap>;
19
+ ```
20
+
21
+ Licence: Superroute SDK License (see LICENSE).
package/package.json CHANGED
@@ -1,6 +1,22 @@
1
1
  {
2
2
  "name": "@superrouteca/sindoor-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "sIndoor for React: hooks and a component for indoor navigation on sMap maps",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "module": "src/index.js",
8
+ "types": "types/index.d.ts",
9
+ "exports": { ".": { "types": "./types/index.d.ts", "import": "./src/index.js" } },
10
+ "files": ["src", "types", "README.md", "LICENSE"],
11
+ "sideEffects": false,
12
+ "license": "SEE LICENSE IN LICENSE",
13
+ "author": "Superroute Inc.",
14
+ "peerDependencies": {
15
+ "@superrouteca/sindoor": "0.1.0",
16
+ "@superrouteca/smap-react": ">=1.5.12",
17
+ "react": ">=18"
18
+ },
19
+ "peerDependenciesMeta": { "@superrouteca/smap-react": { "optional": true } },
20
+ "devDependencies": { "react": "18.3.1", "react-test-renderer": "18.3.1" },
21
+ "scripts": { "test": "node --test test/*.test.mjs" }
22
+ }
package/src/index.js ADDED
@@ -0,0 +1,88 @@
1
+ // sIndoor for React (DESIGN.md Part 2h, IK4): a site loaded once (then offline), a locator, and the navigation screen
2
+ // on an sMap map (with @superrouteca/smap-react, pass useSMap()'s map).
3
+ import { createElement, useEffect, useRef, useState } from 'react';
4
+ import { init, SindoorSite, SindoorNavigator as Navigator } from '@superrouteca/sindoor';
5
+
6
+ /** Load a site: `{site, client, form?}` downloads it, `{download}` starts from a kept one. → `{site, error, loading}`. */
7
+ export function useSindoorSite({ site: id, client, form = 'customer', download } = {}) {
8
+ const [state, setState] = useState({ site: null, error: null, loading: true });
9
+ useEffect(() => {
10
+ let live = true;
11
+ let made = null;
12
+ setState({ site: null, error: null, loading: true });
13
+ (async () => {
14
+ await init();
15
+ made = download ? SindoorSite.fromDownload(download) : await SindoorSite.load({ site: id, client, form });
16
+ if (live) setState({ site: made, error: null, loading: false });
17
+ else made.dispose();
18
+ })().catch((error) => live && setState({ site: null, error, loading: false }));
19
+ return () => {
20
+ live = false;
21
+ if (made) made.dispose();
22
+ };
23
+ }, [id, client, form, download]);
24
+ return state;
25
+ }
26
+
27
+ /** A locator on the site; `observe(obs)` returns the estimate and keeps it as `estimate`. */
28
+ export function useSindoorLocator(site, config) {
29
+ const ref = useRef(null);
30
+ const [estimate, setEstimate] = useState(null);
31
+ useEffect(() => {
32
+ if (!site) return undefined;
33
+ ref.current = site.locator(config || {});
34
+ return () => {
35
+ ref.current?.dispose();
36
+ ref.current = null;
37
+ };
38
+ }, [site]); // config is read once per site
39
+ const observe = (obs) => {
40
+ const e = ref.current?.observe(obs) ?? null;
41
+ if (e) setEstimate(e);
42
+ return e;
43
+ };
44
+ return { estimate, observe, locator: ref.current };
45
+ }
46
+
47
+ /** The navigation screen on a map you hold (`map` an sMap map). Re-created when map or site change. */
48
+ export function useSindoorNavigator(map, site, options) {
49
+ const [nav, setNav] = useState(null);
50
+ useEffect(() => {
51
+ if (!map || !site) return undefined;
52
+ let live = true;
53
+ const n = new Navigator(map, site, options || {});
54
+ n.ready.then(() => live && setNav(n)).catch(() => {});
55
+ return () => {
56
+ live = false;
57
+ n.destroy();
58
+ setNav(null);
59
+ };
60
+ }, [map, site]);
61
+ return nav;
62
+ }
63
+
64
+ /**
65
+ * `<SindoorNavigator map={map} site={site} position={estimate} target="fixture:12" />` — with smap-react, `map` is
66
+ * `useSMap()` of a component inside `<SMap>`. Draws the site, the blue dot at `position` and the route to `target`;
67
+ * `onRoute(route)` / `onError(e)`.
68
+ */
69
+ export function SindoorNavigator({ map, site, position, target, options, onRoute, onError }) {
70
+ const nav = useSindoorNavigator(map, site, options);
71
+ useEffect(() => {
72
+ if (nav) nav.showPosition(position || null);
73
+ }, [nav, position]);
74
+ useEffect(() => {
75
+ if (!nav) return;
76
+ if (!target) {
77
+ nav.clearRoute();
78
+ return;
79
+ }
80
+ try {
81
+ const r = nav.navigateTo(target, position ? {} : { from: options?.from });
82
+ onRoute?.(r);
83
+ } catch (e) {
84
+ onError?.(e);
85
+ }
86
+ }, [nav, target, position?.level, Math.round((position?.x ?? 0) / 1000), Math.round((position?.y ?? 0) / 1000)]);
87
+ return options?.panel ? null : createElement('div', { className: 'sindoor-navigator', hidden: true });
88
+ }
@@ -0,0 +1,22 @@
1
+ import type { SindoorSite, SindoorLocator, SindoorNavigator as Navigator, SindoorClient, Download, Estimate, Observation, NavigatorOptions, Place, Route } from '@superrouteca/sindoor';
2
+
3
+ export function useSindoorSite(o: { site?: string; client?: SindoorClient; form?: 'customer' | 'full'; download?: Download }): {
4
+ site: SindoorSite | null;
5
+ error: (Error & { code?: string }) | null;
6
+ loading: boolean;
7
+ };
8
+ export function useSindoorLocator(site: SindoorSite | null, config?: object): {
9
+ estimate: Estimate | null;
10
+ observe(obs: Observation | Observation[]): Estimate | null;
11
+ locator: SindoorLocator | null;
12
+ };
13
+ export function useSindoorNavigator(map: object | null, site: SindoorSite | null, options?: NavigatorOptions): Navigator | null;
14
+ export function SindoorNavigator(props: {
15
+ map: object | null;
16
+ site: SindoorSite | null;
17
+ position?: Estimate | null;
18
+ target?: Place | null;
19
+ options?: NavigatorOptions & { from?: Place };
20
+ onRoute?(route: Route): void;
21
+ onError?(e: Error): void;
22
+ }): unknown;