@superrouteca/sindoor-editor 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 +21 -0
- package/README.md +59 -2
- package/dist/sindoor-editor-element.js +160 -0
- package/dist/sindoor-editor.js +2806 -0
- package/dist/sindoor_wasm.js +820 -0
- package/dist/sindoor_wasm_bg.wasm +0 -0
- package/package.json +16 -4
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,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sIndoor site editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The editor of a sIndoor site's routing data (connectors, regions, aisle rules, entrances, parking and delivery points,
|
|
4
|
+
beacons, codes, closures, positioning) and — for sites of their own (package mode, DESIGN.md Part 2h IK10) — its
|
|
5
|
+
geometry: levels, outlines, obstacles, access points, geo anchors. Plain JavaScript over the browser build of the
|
|
6
|
+
engine; it makes no network calls itself, the host loads the data and answers its hooks.
|
|
7
|
+
|
|
8
|
+
Build: `scripts/build-editor.sh` → `dist/editor/` (`sindoor-editor.js`, `sindoor-editor-element.js`,
|
|
9
|
+
`sindoor_wasm.js`, `sindoor_wasm_bg.wasm`). Serve the four files side by side. Check: `scripts/e2e-editor.sh`
|
|
10
|
+
(headless Chrome). Local demo: serve `dist/editor/` with `editor/demo.html` copied in; `?package=1` opens package mode.
|
|
11
|
+
|
|
12
|
+
## Class
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import { SindoorEditor } from './sindoor-editor.js';
|
|
16
|
+
const ed = new SindoorEditor(document.getElementById('editor'), {
|
|
17
|
+
wasm: './sindoor_wasm.js',
|
|
18
|
+
package: sitePackage, // a sindoor-site/1 package (or `rows`: Superroute floor plan rows)
|
|
19
|
+
overlay: { revision, overlay },
|
|
20
|
+
onSave: async (baseRevision, overlay, note) => ({ revision }),
|
|
21
|
+
onSavePackage: async (baseVersion, sitePackage, note) => ({ version }) /* or { error: 'stale_version' } */,
|
|
22
|
+
i18n: { geo_save: 'Save geometry' }, // any key of DEFAULT_TEXT
|
|
23
|
+
});
|
|
24
|
+
await ed.start();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Every option, hook and the geometry API (`addLevel`, `addObstacle`, `rotateObstacle`, `addAccessPoint`, `undo`,
|
|
28
|
+
`savePackage` …) are listed in the header comment of `sindoor-editor.js`. Geometry is edited only in package mode and
|
|
29
|
+
never with `readOnly`; sites from Superroute floor plans (rows) keep it read-only.
|
|
30
|
+
|
|
31
|
+
## Web component
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script type="module" src="/sindoor/sindoor-editor-element.js"></script>
|
|
35
|
+
<sindoor-editor id="ed" shadow events="revisions" style="height:700px"></sindoor-editor>
|
|
36
|
+
<script type="module">
|
|
37
|
+
const ed = document.getElementById('ed');
|
|
38
|
+
ed.overlay = await (await fetch('/my-api/sites/shop/overlay')).json(); // your server, holding the key
|
|
39
|
+
ed.onSavePackage = (baseVersion, pkg, note) => myApi.putPackage('shop', baseVersion, pkg, note);
|
|
40
|
+
ed.addEventListener('sindoor-save', (ev) => ev.detail.respondWith(myApi.putOverlay('shop', ...ev.detail.args)));
|
|
41
|
+
ed.addEventListener('sindoor-revisions', (ev) => ev.detail.respondWith(myApi.revisions('shop')));
|
|
42
|
+
ed.addEventListener('sindoor-state', (ev) => console.log(ev.detail)); // { dirty, packageChanged }
|
|
43
|
+
ed.package = await (await fetch('/my-api/sites/shop/package')).json(); // setting it starts the editor
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- Properties: `wasm` (default `./sindoor_wasm.js` beside `sindoor-editor.js`), `package` or `rows`, `overlay`,
|
|
48
|
+
`i18n`, `readOnly`, `options` (any other class option) and every hook as a callback property (`onSave`,
|
|
49
|
+
`onSavePackage`, `onRevisions`, `onRevert`, `onLiveList`, `onLiveCreate`, `onLiveUpdate`, `onLiveLift`,
|
|
50
|
+
`onOutdoorDraft`, `onCalibration`, `onCalibrationReset`, `onAccuracy`, `onHealth`, `onBeaconPlan`, `onCodes`,
|
|
51
|
+
`confirm`).
|
|
52
|
+
- Attributes: `wasm`, `read-only`, `shadow` (draw in a shadow root), `events` (hooks answered by events instead of
|
|
53
|
+
callbacks, by event name without the `sindoor-` prefix; `save` and `save-package` are always offered).
|
|
54
|
+
- Events (bubbling, composed): `sindoor-<hook>` with `detail = { args, respondWith(valueOrPromise) }` (no answer:
|
|
55
|
+
`{ error: 'no_handler' }`), `sindoor-ready` (`detail.editor`), `sindoor-state`, `sindoor-error`.
|
|
56
|
+
- `el.editor` is the `SindoorEditor` instance; `el.start()` restarts, `el.destroy()` ends it (removing the element
|
|
57
|
+
does too). Changing `package`, `rows`, `overlay`, `i18n`, `readOnly`, `options` or `wasm` restarts the editor.
|
|
58
|
+
|
|
59
|
+
In React or Vue set the properties on the element's ref (not as attributes: they are objects) and listen to the
|
|
60
|
+
events with `addEventListener`.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// <sindoor-editor>: the sIndoor site editor (sindoor-editor.js) as a custom element (docs/DESIGN.md Part 2h IK10), for
|
|
2
|
+
// developers who embed it in any framework. It makes no network calls itself: the host hands it the data and answers
|
|
3
|
+
// its hooks, as with the class.
|
|
4
|
+
//
|
|
5
|
+
// import './sindoor-editor-element.js'; // defines <sindoor-editor> (once)
|
|
6
|
+
// const ed = document.querySelector('sindoor-editor');
|
|
7
|
+
// ed.wasm = new URL('./sindoor_wasm.js', import.meta.url).href; // the browser build beside this file
|
|
8
|
+
// ed.overlay = { revision: 3, overlay: {...} };
|
|
9
|
+
// ed.i18n = { save: 'Save', geo_save: 'Save geometry', ... }; // any DEFAULT_TEXT key
|
|
10
|
+
// ed.onSavePackage = async (baseVersion, pkg, note) => ({ version }); // a hook as a callback property, or …
|
|
11
|
+
// ed.addEventListener('sindoor-save', (ev) => ev.detail.respondWith(saveOverlay(ev.detail.args))); // … as an event
|
|
12
|
+
// ed.package = sitePackage; // or ed.rows = superrouteRows; setting it starts the editor
|
|
13
|
+
//
|
|
14
|
+
// Properties: `wasm`, `package` | `rows`, `overlay`, `i18n`, `readOnly`, `options` (any other option of the class:
|
|
15
|
+
// basemap, snapMm, packageVersion, cameras, staleDays, positioningFeatures, outdoorDraft, showPoints …) and each hook
|
|
16
|
+
// (`onSave`, `onSavePackage`, `onRevisions`, `onRevert`, `onLiveList`, `onLiveCreate`, `onLiveUpdate`, `onLiveLift`,
|
|
17
|
+
// `onOutdoorDraft`, `onCalibration`, `onCalibrationReset`, `onAccuracy`, `onHealth`, `onBeaconPlan`, `onCodes`,
|
|
18
|
+
// `confirm`). Attributes: `wasm`, `read-only`, `shadow` (draw inside a shadow root), `events` (hooks answered through
|
|
19
|
+
// events, space-separated event names without the prefix, e.g. `events="revisions live-list"`; `save` and
|
|
20
|
+
// `save-package` are always offered as events when no callback property is set).
|
|
21
|
+
//
|
|
22
|
+
// Events (bubbling, composed): a hook answered through an event dispatches `sindoor-<name>` (`sindoor-save`,
|
|
23
|
+
// `sindoor-save-package`, `sindoor-revisions`, `sindoor-revert`, `sindoor-live-list`, … `sindoor-confirm`) with
|
|
24
|
+
// `detail = { args, respondWith(valueOrPromise) }`; the first respondWith answers the hook; without one it resolves
|
|
25
|
+
// `{ error: 'no_handler' }` (`confirm`: false). Notifications: `sindoor-ready` (`detail.editor`), `sindoor-state`
|
|
26
|
+
// (`detail = { dirty, packageChanged }`), `sindoor-error` (`detail.error`, the editor did not start).
|
|
27
|
+
// Methods: `start()` (starts or restarts with the current properties), `editor` (the SindoorEditor instance, for the
|
|
28
|
+
// geometry API: addLevel, addObstacle, undo, savePackage …), `destroy()`. Changing `package`, `rows`, `overlay`,
|
|
29
|
+
// `i18n`, `readOnly`, `options` or `wasm` after the start restarts the editor (unsaved edits are dropped); a hook's
|
|
30
|
+
// callback replaced later is used without a restart (the panels shown follow the hooks present at the start).
|
|
31
|
+
|
|
32
|
+
import { SindoorEditor, DEFAULT_TEXT } from './sindoor-editor.js';
|
|
33
|
+
|
|
34
|
+
const HOOKS = ['onSave', 'onSavePackage', 'onRevisions', 'onRevert', 'onLiveList', 'onLiveCreate', 'onLiveUpdate', 'onLiveLift',
|
|
35
|
+
'onOutdoorDraft', 'onCalibration', 'onCalibrationReset', 'onAccuracy', 'onHealth', 'onBeaconPlan', 'onCodes', 'confirm'];
|
|
36
|
+
const ALWAYS_EVENTS = ['save', 'save-package'];
|
|
37
|
+
/** `onSavePackage` → `save-package`, `confirm` → `confirm`. */
|
|
38
|
+
const eventName = (hook) => hook.replace(/^on/, '').replace(/^[A-Z]/, (c) => c.toLowerCase()).replace(/[A-Z]/g, (c) => '-' + c.toLowerCase());
|
|
39
|
+
|
|
40
|
+
export class SindoorEditorElement extends HTMLElement {
|
|
41
|
+
static get observedAttributes() { return ['wasm', 'read-only']; }
|
|
42
|
+
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
this._props = { package: null, rows: null, overlay: null, i18n: null, readOnly: null, options: null, wasm: null };
|
|
46
|
+
this._hooks = {};
|
|
47
|
+
this._editor = null;
|
|
48
|
+
this._pending = false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get editor() { return this._editor; }
|
|
52
|
+
|
|
53
|
+
/** Default: the browser build beside sindoor-editor.js (a relative path resolves against that module). */
|
|
54
|
+
get wasm() { return this._props.wasm ?? this.getAttribute('wasm') ?? './sindoor_wasm.js'; }
|
|
55
|
+
set wasm(v) { this._props.wasm = v; this._schedule(); }
|
|
56
|
+
get package() { return this._props.package; }
|
|
57
|
+
set package(v) { this._props.package = v; this._schedule(); }
|
|
58
|
+
get rows() { return this._props.rows; }
|
|
59
|
+
set rows(v) { this._props.rows = v; this._schedule(); }
|
|
60
|
+
get overlay() { return this._props.overlay; }
|
|
61
|
+
set overlay(v) { this._props.overlay = v; this._schedule(); }
|
|
62
|
+
get i18n() { return this._props.i18n; }
|
|
63
|
+
set i18n(v) { this._props.i18n = v; this._schedule(); }
|
|
64
|
+
get readOnly() { return this._props.readOnly ?? this.hasAttribute('read-only'); }
|
|
65
|
+
set readOnly(v) { this._props.readOnly = !!v; this._schedule(); }
|
|
66
|
+
get options() { return this._props.options; }
|
|
67
|
+
set options(v) { this._props.options = v; this._schedule(); }
|
|
68
|
+
|
|
69
|
+
attributeChangedCallback() { this._schedule(); }
|
|
70
|
+
|
|
71
|
+
connectedCallback() {
|
|
72
|
+
if (!this.style.display) this.style.display = 'block';
|
|
73
|
+
this._schedule();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
disconnectedCallback() {
|
|
77
|
+
// Moving the element in the page reconnects it at once; only a real removal ends the editor.
|
|
78
|
+
queueMicrotask(() => { if (!this.isConnected) this.destroy(); });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Starts (or restarts) once the current task has set its properties. */
|
|
82
|
+
_schedule() {
|
|
83
|
+
if (this._pending) return;
|
|
84
|
+
this._pending = true;
|
|
85
|
+
queueMicrotask(() => {
|
|
86
|
+
this._pending = false;
|
|
87
|
+
if (this.isConnected && this.wasm && (this._props.package || this._props.rows)) this.start();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The hook given to the editor: the callback property, else an event when it is one the host answers by events. */
|
|
92
|
+
_hook(name) {
|
|
93
|
+
// Read at call time: replacing a callback after the start takes effect without a restart.
|
|
94
|
+
if (typeof this._hooks[name] === 'function') return (...args) => this._hooks[name](...args);
|
|
95
|
+
if (typeof this._props.options?.[name] === 'function') return this._props.options[name];
|
|
96
|
+
const ev = eventName(name);
|
|
97
|
+
const listed = (this.getAttribute('events') || '').split(/\s+/).filter(Boolean);
|
|
98
|
+
if (!ALWAYS_EVENTS.includes(ev) && !listed.includes(ev)) return undefined;
|
|
99
|
+
return (...args) => new Promise((resolve) => {
|
|
100
|
+
let answered = false;
|
|
101
|
+
const detail = { args, respondWith: (v) => { if (!answered) { answered = true; resolve(v); } } };
|
|
102
|
+
this.dispatchEvent(new CustomEvent('sindoor-' + ev, { detail, bubbles: true, composed: true }));
|
|
103
|
+
if (!answered) resolve(name === 'confirm' ? false : { error: 'no_handler' });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async start() {
|
|
108
|
+
this._editor?.destroy();
|
|
109
|
+
this._editor = null;
|
|
110
|
+
let mount = this;
|
|
111
|
+
if (this.hasAttribute('shadow')) {
|
|
112
|
+
const sr = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
113
|
+
sr.innerHTML = '<div part="editor" style="height:100%"></div>';
|
|
114
|
+
mount = sr.firstElementChild;
|
|
115
|
+
} else {
|
|
116
|
+
this.innerHTML = '<div style="height:100%"></div>';
|
|
117
|
+
mount = this.firstElementChild;
|
|
118
|
+
}
|
|
119
|
+
const p = this._props;
|
|
120
|
+
const opts = { ...(p.options || {}), wasm: this.wasm, overlay: p.overlay || undefined, i18n: p.i18n || undefined, readOnly: this.readOnly,
|
|
121
|
+
...(p.rows ? { rows: p.rows } : { package: p.package }),
|
|
122
|
+
onStateChange: (state) => {
|
|
123
|
+
p.options?.onStateChange?.(state);
|
|
124
|
+
this.dispatchEvent(new CustomEvent('sindoor-state', { detail: state, bubbles: true, composed: true }));
|
|
125
|
+
} };
|
|
126
|
+
for (const h of HOOKS) {
|
|
127
|
+
const fn = this._hook(h);
|
|
128
|
+
if (fn) opts[h] = fn; else delete opts[h];
|
|
129
|
+
}
|
|
130
|
+
const ed = new SindoorEditor(mount, opts);
|
|
131
|
+
this._editor = ed;
|
|
132
|
+
try {
|
|
133
|
+
await ed.start();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
this.dispatchEvent(new CustomEvent('sindoor-error', { detail: { error }, bubbles: true, composed: true }));
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
if (this._editor === ed) this.dispatchEvent(new CustomEvent('sindoor-ready', { detail: { editor: ed }, bubbles: true, composed: true }));
|
|
139
|
+
return ed;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
destroy() {
|
|
143
|
+
this._editor?.destroy();
|
|
144
|
+
this._editor = null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Each hook as a callback property. Which panels the editor shows follows the hooks present at the start; a callback
|
|
149
|
+
// replaced later is used from then on (call start() to show a panel of a hook added later).
|
|
150
|
+
for (const h of HOOKS) {
|
|
151
|
+
Object.defineProperty(SindoorEditorElement.prototype, h, {
|
|
152
|
+
get() { return this._hooks[h]; },
|
|
153
|
+
set(fn) { this._hooks[h] = fn; },
|
|
154
|
+
configurable: true,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!customElements.get('sindoor-editor')) customElements.define('sindoor-editor', SindoorEditorElement);
|
|
159
|
+
|
|
160
|
+
export { DEFAULT_TEXT };
|