@pritzlaff/nano-elements 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
+ MIT License
2
+
3
+ Copyright (c) 2026 Aaron Pritzlaff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # @pritzlaff/nano-elements
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
+ Lit elements over `@pritzlaff/nano-core` components.
4
+
5
+ - **`ModelElement`:** shows and drives one model. Give it a `registry` and a `model` (an instance id), and
6
+ optionally a `watch` list of more instances whose sources it reads. It joins the registry as a hidden
7
+ subscriber of each, re-renders when they publish, and calls the model's actions through its own handle:
8
+ `this.read(op)` gives the latest value, and `this.act(op, arg)` calls an action, keeping a refusal in
9
+ `this.problem`.
10
+ - **`PlacedElement`:** a ModelElement that brings its own component (`static component`).
11
+ - **On the page,** it shows the instance named by its `name` attribute, in the registry provided for the
12
+ document. If no instance has that name, it creates one and removes it when the element goes.
13
+ - **Moving it** (as a dock does) keeps the instance.
14
+ - **Without a `name`,** it gets a generated one.
15
+ - **`provide(document, registry)`:** sets the registry that placed elements use.
16
+ - **`base`:** the shared styles (the puzzle prototype's palette).
package/catalog.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { Component } from '@pritzlaff/nano-core';
2
+ /** One kind of component: the component, a title for people, and the tag of the element that shows it. */
3
+ export type CatalogEntry = {
4
+ component: Component;
5
+ title: string;
6
+ tag?: string;
7
+ };
8
+ /** A package's kinds of component, by kind. A host merges these to list everything it can make. */
9
+ export type Catalog = Record<string, CatalogEntry>;
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { ModelElement } from './model-element.js';
2
+ export { PlacedElement, provide, providedRegistry } from './placed-element.js';
3
+ export { base } from './styles.js';
4
+ export type { Catalog, CatalogEntry } from './catalog.js';
package/index.js ADDED
@@ -0,0 +1,130 @@
1
+ // packages/elements/src/model-element.ts
2
+ import { LitElement } from "lit";
3
+ import { Type } from "typebox";
4
+ import { Components, Ops } from "@pritzlaff/nano-core";
5
+ var n = 0;
6
+
7
+ class ModelElement extends LitElement {
8
+ static properties = { registry: { attribute: false }, model: {}, watch: { attribute: false }, problem: { state: true } };
9
+ #values = new Map;
10
+ #view;
11
+ connectedCallback() {
12
+ super.connectedCallback();
13
+ if (this.hasUpdated)
14
+ this.#attach();
15
+ }
16
+ disconnectedCallback() {
17
+ super.disconnectedCallback();
18
+ this.#detach();
19
+ }
20
+ willUpdate(changed) {
21
+ if (changed.has("registry") || changed.has("model") || changed.has("watch")) {
22
+ this.#detach();
23
+ this.#attach();
24
+ }
25
+ }
26
+ read(op) {
27
+ return this.#values.get(Ops.key(op));
28
+ }
29
+ async act(op, arg = null) {
30
+ if (!this.#view || !this.model)
31
+ return { error: "not attached to a model" };
32
+ const r = await this.#view.handle.call(this.model, op, arg);
33
+ this.problem = "error" in r ? r.error : undefined;
34
+ return r;
35
+ }
36
+ #attach() {
37
+ const reg = this.registry;
38
+ if (!reg || !this.model || !reg.get(this.model) || this.#view || !this.isConnected)
39
+ return;
40
+ const sources = [this.model, ...this.watch ?? []].flatMap((i) => [...reg.get(i)?.actions.values() ?? []].filter((a) => a.op.output && !a.op.input).map((a) => [i, a]));
41
+ const id = `${this.model}~view-${n++}`;
42
+ const view = Components.create({ ns: "composable.editor", name: "view" }, () => this);
43
+ for (const [, a] of sources) {
44
+ const key = Ops.key(a.op);
45
+ view.action(Ops.sink("composable.editor/view", key, Type.Unknown()), (el, data) => {
46
+ el.#values.set(key, data);
47
+ el.requestUpdate();
48
+ });
49
+ }
50
+ reg.add(id, Components.instantiate(view));
51
+ for (const [i, a] of sources)
52
+ reg.subscribe({ source: i, op: Ops.key(a.op), listener: id, target: `composable.editor/view/${Ops.key(a.op)}` });
53
+ this.#view = { id, handle: reg.get(id).env.handles()[0], registry: reg };
54
+ for (const [i, a] of sources)
55
+ if (a.run)
56
+ this.#view.handle.call(i, a.op, null).then((r) => {
57
+ if ("value" in r && this.#view?.id === id) {
58
+ this.#values.set(Ops.key(a.op), r.value);
59
+ this.requestUpdate();
60
+ }
61
+ });
62
+ }
63
+ #detach() {
64
+ this.#view?.registry.remove(this.#view.id);
65
+ this.#view = undefined;
66
+ this.#values.clear();
67
+ }
68
+ }
69
+ // packages/elements/src/placed-element.ts
70
+ import { Components as Components2 } from "@pritzlaff/nano-core";
71
+ var provided = new WeakMap;
72
+ var n2 = 0;
73
+ var provide = (doc, registry) => {
74
+ provided.set(doc, registry);
75
+ };
76
+ var providedRegistry = (doc) => provided.get(doc);
77
+
78
+ class PlacedElement extends ModelElement {
79
+ static component;
80
+ #mine;
81
+ connectedCallback() {
82
+ this.registry ??= providedRegistry(this.ownerDocument);
83
+ this.model ??= this.getAttribute("name") ?? `${this.localName}-${n2++}`;
84
+ const reg = this.registry;
85
+ if (reg && !reg.get(this.model)) {
86
+ const inst = Components2.instantiate(this.constructor.component);
87
+ if (!("error" in reg.add(this.model, inst)))
88
+ this.#mine = { id: this.model, inst, registry: reg };
89
+ }
90
+ super.connectedCallback();
91
+ }
92
+ disconnectedCallback() {
93
+ super.disconnectedCallback();
94
+ queueMicrotask(() => {
95
+ const mine = this.#mine;
96
+ if (this.isConnected || !mine || this.hasAttribute("keep"))
97
+ return;
98
+ if (mine.registry.get(mine.id) === mine.inst)
99
+ mine.registry.remove(mine.id);
100
+ this.#mine = undefined;
101
+ });
102
+ }
103
+ }
104
+ // packages/elements/src/styles.ts
105
+ import { css } from "lit";
106
+ var base = css`
107
+ :host { display: block; font-family: Inter, system-ui, sans-serif; font-size: 13px; color: #E7E9EE }
108
+ button { font: inherit; font-size: 12px; color: #E7E9EE; background: transparent; border: 1px solid #3A4150; border-radius: 6px; padding: 5px 10px; cursor: pointer }
109
+ button.primary { color: #0D0F13; background: #6FA8FF; border: 0; font-weight: 600 }
110
+ button.danger { color: #FFB4A8; border-color: #5A3A3A }
111
+ button.dashed { border-style: dashed; border-color: #4A5263; font-weight: 600 }
112
+ button[aria-pressed='true'] { background: #212632; border-color: #6FA8FF }
113
+ input, select { font: inherit; font-size: 12px; color: #E7E9EE; background: #0D0F13; border: 1px solid #3A4150; border-radius: 5px; padding: 4px 6px }
114
+ .muted { color: #A3AAB8 }
115
+ .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px }
116
+ .problem { color: #FFB4A8; font-size: 12px }
117
+ .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap }
118
+ .col { display: flex; flex-direction: column; gap: 8px }
119
+ .card { background: #14171D; border: 1px solid #2A303C; border-radius: 8px; padding: 10px }
120
+ `;
121
+ export {
122
+ providedRegistry,
123
+ provide,
124
+ base,
125
+ PlacedElement,
126
+ ModelElement
127
+ };
128
+
129
+ //# debugId=B432BAB1B5BC587A64756E2164756E21
130
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/model-element.ts", "../src/placed-element.ts", "../src/styles.ts"],
4
+ "sourcesContent": [
5
+ "// A Lit element over one model instance. It joins the model's registry as an ordinary subscriber (a hidden view\n// instance), re-renders when the model publishes, and acts by calling the model through its own handle.\nimport { LitElement } from 'lit'\nimport { Type } from 'typebox'\nimport { Components, Ops, type Handle, type Op, type Registry, type Result } from '@pritzlaff/nano-core'\n\nlet n = 0\n\n/** Base class for an element that shows and drives one model: set `registry` and `model` (the instance id).\n * `watch` names more instances whose sources it reads too (it acts only on `model`). */\nexport abstract class ModelElement extends LitElement {\n static properties = { registry: { attribute: false }, model: {}, watch: { attribute: false }, problem: { state: true } }\n declare registry?: Registry\n declare model?: string\n declare watch?: string[]\n /** The last refusal from `act`, for rendering. */\n declare problem?: string\n #values = new Map<string, unknown>()\n #view?: { id: string; handle: Handle; registry: Registry }\n\n // before the first update, willUpdate attaches (registry and model arrive as changes); after it, reconnecting does\n connectedCallback() { super.connectedCallback(); if (this.hasUpdated) this.#attach() }\n disconnectedCallback() { super.disconnectedCallback(); this.#detach() }\n willUpdate(changed: Map<string, unknown>) {\n if (changed.has('registry') || changed.has('model') || changed.has('watch')) { this.#detach(); this.#attach() }\n }\n\n /** The model's latest value for a source op. */\n read<T>(op: Op): T | undefined { return this.#values.get(Ops.key(op)) as T | undefined }\n\n /** Calls an action on the model; a refusal is kept in `problem`. */\n async act(op: Op, arg: unknown = null): Promise<Result> {\n if (!this.#view || !this.model) return { error: 'not attached to a model' }\n const r = await this.#view.handle.call(this.model, op, arg)\n this.problem = 'error' in r ? r.error : undefined\n return r\n }\n\n #attach() {\n const reg = this.registry\n if (!reg || !this.model || !reg.get(this.model) || this.#view || !this.isConnected) return\n // every source op of the model and the watched instances: [instance, action]\n const sources = [this.model, ...(this.watch ?? [])].flatMap(i =>\n [...(reg.get(i)?.actions.values() ?? [])].filter(a => a.op.output && !a.op.input).map(a => [i, a] as const))\n const id = `${this.model}~view-${n++}`\n const view = Components.create({ ns: 'composable.editor', name: 'view' }, () => this)\n for (const [, a] of sources) {\n const key = Ops.key(a.op) // ponytail: two watched instances of one component would share a key\n view.action(Ops.sink('composable.editor/view', key, Type.Unknown()), (el, data) => { el.#values.set(key, data); el.requestUpdate() })\n }\n reg.add(id, Components.instantiate(view))\n for (const [i, a] of sources) reg.subscribe({ source: i, op: Ops.key(a.op), listener: id, target: `composable.editor/view/${Ops.key(a.op)}` })\n this.#view = { id, handle: reg.get(id)!.env.handles()[0]!, registry: reg }\n // read what each holds now: sources with a reader answer a call\n for (const [i, a] of sources) if (a.run) void this.#view.handle.call(i, a.op, null).then(r => {\n // only for the current view: one replaced since the call started must not write\n if ('value' in r && this.#view?.id === id) { this.#values.set(Ops.key(a.op), r.value); this.requestUpdate() }\n })\n }\n\n #detach() {\n this.#view?.registry.remove(this.#view.id) // from the registry it joined, even if `registry` has changed since\n this.#view = undefined\n this.#values.clear()\n }\n}\n",
6
+ "// An element that places its own component: by its `name`, in the registry provided for its document.\nimport { Components, type Component, type Instance, type Registry } from '@pritzlaff/nano-core'\nimport { ModelElement } from './model-element'\n\nconst provided = new WeakMap<Document, Registry>()\nlet n = 0\n\n/** Sets the registry that placed elements in `doc` use. */\nexport const provide = (doc: Document, registry: Registry) => { provided.set(doc, registry) }\n/** The registry provided for `doc`, if any. */\nexport const providedRegistry = (doc: Document) => provided.get(doc)\n\n/**\n * A ModelElement that brings its own component (`static component`). On the page it shows the instance named by\n * its `name` attribute, creating it if it doesn't exist; an instance it created goes when the element does,\n * unless the element has a `keep` attribute (a dock panel: closing it leaves the component in the system).\n */\nexport abstract class PlacedElement extends ModelElement {\n static component: Component\n /** The instance this element made, and where: only that one is ever removed by it. */\n #mine?: { id: string; inst: Instance; registry: Registry }\n\n connectedCallback() {\n this.registry ??= providedRegistry(this.ownerDocument)\n this.model ??= this.getAttribute('name') ?? `${this.localName}-${n++}`\n const reg = this.registry\n if (reg && !reg.get(this.model)) {\n const inst = Components.instantiate((this.constructor as typeof PlacedElement).component)\n if (!('error' in reg.add(this.model, inst))) this.#mine = { id: this.model, inst, registry: reg }\n }\n super.connectedCallback()\n }\n\n disconnectedCallback() {\n super.disconnectedCallback()\n // wait a moment: moving the element (as a dock does) disconnects and reconnects it, and keeps the instance\n queueMicrotask(() => {\n const mine = this.#mine\n if (this.isConnected || !mine || this.hasAttribute('keep')) return\n if (mine.registry.get(mine.id) === mine.inst) mine.registry.remove(mine.id) // not one that replaced it\n this.#mine = undefined\n })\n }\n}\n",
7
+ "// The prototype's look, shared by every element: dark surfaces, Inter for text, JetBrains Mono for code.\nimport { css } from 'lit'\n\n/** Base styles for every editor element. */\nexport const base = css`\n :host { display: block; font-family: Inter, system-ui, sans-serif; font-size: 13px; color: #E7E9EE }\n button { font: inherit; font-size: 12px; color: #E7E9EE; background: transparent; border: 1px solid #3A4150; border-radius: 6px; padding: 5px 10px; cursor: pointer }\n button.primary { color: #0D0F13; background: #6FA8FF; border: 0; font-weight: 600 }\n button.danger { color: #FFB4A8; border-color: #5A3A3A }\n button.dashed { border-style: dashed; border-color: #4A5263; font-weight: 600 }\n button[aria-pressed='true'] { background: #212632; border-color: #6FA8FF }\n input, select { font: inherit; font-size: 12px; color: #E7E9EE; background: #0D0F13; border: 1px solid #3A4150; border-radius: 5px; padding: 4px 6px }\n .muted { color: #A3AAB8 }\n .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 11px }\n .problem { color: #FFB4A8; font-size: 12px }\n .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap }\n .col { display: flex; flex-direction: column; gap: 8px }\n .card { background: #14171D; border: 1px solid #2A303C; border-radius: 8px; padding: 10px }\n`\n"
8
+ ],
9
+ "mappings": ";AAEA;AACA;AACA;AAEA,IAAI,IAAI;AAAA;AAID,MAAe,qBAAqB,WAAW;AAAA,SAC7C,aAAa,EAAE,UAAU,EAAE,WAAW,MAAM,GA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5BC587A64756E2164756E21",
11
+ "names": []
12
+ }
@@ -0,0 +1,31 @@
1
+ import { LitElement } from 'lit';
2
+ import { type Op, type Registry, type Result } from '@pritzlaff/nano-core';
3
+ /** Base class for an element that shows and drives one model: set `registry` and `model` (the instance id).
4
+ * `watch` names more instances whose sources it reads too (it acts only on `model`). */
5
+ export declare abstract class ModelElement extends LitElement {
6
+ #private;
7
+ static properties: {
8
+ registry: {
9
+ attribute: boolean;
10
+ };
11
+ model: {};
12
+ watch: {
13
+ attribute: boolean;
14
+ };
15
+ problem: {
16
+ state: boolean;
17
+ };
18
+ };
19
+ registry?: Registry;
20
+ model?: string;
21
+ watch?: string[];
22
+ /** The last refusal from `act`, for rendering. */
23
+ problem?: string;
24
+ connectedCallback(): void;
25
+ disconnectedCallback(): void;
26
+ willUpdate(changed: Map<string, unknown>): void;
27
+ /** The model's latest value for a source op. */
28
+ read<T>(op: Op): T | undefined;
29
+ /** Calls an action on the model; a refusal is kept in `problem`. */
30
+ act(op: Op, arg?: unknown): Promise<Result>;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@pritzlaff/nano-elements",
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": "Lit elements over core components: show and drive a model, or place a component by name.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/aaronp/nano.git",
10
+ "directory": "packages/elements"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./index.d.ts",
15
+ "import": "./index.js"
16
+ }
17
+ },
18
+ "types": "./index.d.ts",
19
+ "module": "./index.js",
20
+ "sideEffects": false,
21
+ "peerDependencies": {
22
+ "@pritzlaff/nano-core": "^0.1.0",
23
+ "lit": "^3.0.0",
24
+ "typebox": "^1.4.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
@@ -0,0 +1,17 @@
1
+ import { type Component, type Registry } from '@pritzlaff/nano-core';
2
+ import { ModelElement } from './model-element.js';
3
+ /** Sets the registry that placed elements in `doc` use. */
4
+ export declare const provide: (doc: Document, registry: Registry) => void;
5
+ /** The registry provided for `doc`, if any. */
6
+ export declare const providedRegistry: (doc: Document) => Registry | undefined;
7
+ /**
8
+ * A ModelElement that brings its own component (`static component`). On the page it shows the instance named by
9
+ * its `name` attribute, creating it if it doesn't exist; an instance it created goes when the element does,
10
+ * unless the element has a `keep` attribute (a dock panel: closing it leaves the component in the system).
11
+ */
12
+ export declare abstract class PlacedElement extends ModelElement {
13
+ #private;
14
+ static component: Component;
15
+ connectedCallback(): void;
16
+ disconnectedCallback(): void;
17
+ }
package/styles.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** Base styles for every editor element. */
2
+ export declare const base: import("lit").CSSResult;