@pngwasi/config-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/load.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { InitInput, InitOutput } from "./pkg/config_editor.js";
2
+
3
+ /**
4
+ * Loads the WebAssembly module, once for the page: every editor, every
5
+ * `@pngwasi/config-editor/tools` function and every framework component
6
+ * share it (the components call it themselves). Await it before
7
+ * `new ConfigEditor(…)` or a tool. Pass the `.wasm` file (a URL, a
8
+ * `Response`, bytes or a compiled module) when a bundler does not serve it
9
+ * next to the package's JavaScript. A failed load is not kept: calling
10
+ * again (with the right file) retries, and components whose own load failed
11
+ * mount then.
12
+ */
13
+ export function loadConfigEditor(
14
+ input?: InitInput | Promise<InitInput> | { module_or_path: InitInput | Promise<InitInput> },
15
+ ): Promise<InitOutput>;
16
+
17
+ /** Runs `retry` after the next load that succeeds; returns what cancels it. For the bindings. */
18
+ export function whenLoaded(retry: () => void): () => void;
package/load.js ADDED
@@ -0,0 +1,57 @@
1
+ // The one WebAssembly load, shared by every entry (`.`, `./tools`,
2
+ // `./binding`) and every framework component on the page.
3
+
4
+ import init, { ConfigDocuments, ConfigEditor } from "./pkg/config_editor.js";
5
+
6
+ // Set while a host callback runs (see `count_callback` in `src/mount.rs`).
7
+ const inHostCallback = () =>
8
+ globalThis[Symbol.for("config-editor.inHostCallback")] === true;
9
+
10
+ // `free()` inside a callback the instance's own method fired (`save()`
11
+ // calling `onSave`, where a framework may unmount): wasm-bindgen refuses to
12
+ // free an object while one of its methods runs, so it is freed once the
13
+ // callback (and the method) has returned.
14
+ for (const Class of [ConfigEditor, ConfigDocuments]) {
15
+ const free = Class.prototype.free;
16
+ Class.prototype.free = function () {
17
+ if (inHostCallback()) queueMicrotask(() => free.call(this));
18
+ else free.call(this);
19
+ };
20
+ }
21
+
22
+ let loading;
23
+ // Bindings whose own load failed, retried when a later load succeeds.
24
+ const onLoaded = new Set();
25
+
26
+ function loaded(value) {
27
+ for (const retry of [...onLoaded]) retry();
28
+ return value;
29
+ }
30
+
31
+ function forget(error) {
32
+ loading = undefined;
33
+ throw error;
34
+ }
35
+
36
+ /**
37
+ * Loads the WebAssembly module once.
38
+ * @param {Parameters<typeof init>[0]} [input]
39
+ */
40
+ export function loadConfigEditor(input) {
41
+ // A URL given while a load runs: tried when that one fails (a wrong URL,
42
+ // or the default one, followed by the right one). A failed load is not
43
+ // kept: calling again (with the right URL) retries.
44
+ if (loading && input !== undefined) {
45
+ const previous = loading;
46
+ loading = previous.catch(() => init(input)).then(loaded, forget);
47
+ return loading;
48
+ }
49
+ loading ??= init(input).then(loaded, forget);
50
+ return loading;
51
+ }
52
+
53
+ /** Runs `retry` after the next load that succeeds; returns what cancels it. */
54
+ export function whenLoaded(retry) {
55
+ onLoaded.add(retry);
56
+ return () => onLoaded.delete(retry);
57
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@pngwasi/config-editor",
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": "Schema-aware config editor for YAML, JSON, TOML, HCL and XML in the browser (Rust/WebAssembly)",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "module": "index.js",
8
+ "types": "index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "default": "./index.js"
13
+ },
14
+ "./tools": {
15
+ "types": "./tools.d.ts",
16
+ "default": "./tools.js"
17
+ },
18
+ "./binding": {
19
+ "types": "./binding.d.ts",
20
+ "default": "./binding.js"
21
+ },
22
+ "./config_editor_bg.wasm": "./pkg/config_editor_bg.wasm",
23
+ "./preset.css": "./preset.css"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts",
28
+ "tools.js",
29
+ "tools.d.ts",
30
+ "binding.js",
31
+ "binding.d.ts",
32
+ "load.js",
33
+ "load.d.ts",
34
+ "setting-types.js",
35
+ "preset.css",
36
+ "pkg/config_editor.js",
37
+ "pkg/config_editor.d.ts",
38
+ "pkg/config_editor_bg.wasm",
39
+ "pkg/config_editor_bg.wasm.d.ts",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "sideEffects": false,
44
+ "scripts": {
45
+ "build": "node build.mjs",
46
+ "build:alloc-stats": "node build.mjs --alloc-stats"
47
+ },
48
+ "keywords": [
49
+ "config",
50
+ "editor",
51
+ "yaml",
52
+ "json",
53
+ "toml",
54
+ "hcl",
55
+ "xml",
56
+ "json-schema",
57
+ "wasm"
58
+ ],
59
+ "license": "MIT",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/paradoxe35/config-editor.git",
63
+ "directory": "js/config-editor"
64
+ },
65
+ "homepage": "https://github.com/paradoxe35/config-editor#readme",
66
+ "bugs": {
67
+ "url": "https://github.com/paradoxe35/config-editor/issues"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }