meowjsx 0.2.0-alpha.0 → 0.3.0-alpha.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/JSON.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  ```ts
6
6
  import { createJsonView, defineJsonComponent, jsonSchema, parseJsonView } from "meowjsx/json";
7
- import { h, signal, type MaybeSignal } from "meowjsx";
7
+ import { h } from "meowjsx";
8
+ import { signal, type MaybeSignal } from "meowjsx/signal";
8
9
 
9
10
  const Label = (props: { text: MaybeSignal<string> }) => h("span", null, props.text);
10
11
  const catalog = new Map([
package/README.md CHANGED
@@ -79,9 +79,12 @@ meowjsx (this package: core + JSX contract)
79
79
 
80
80
  ## Exports
81
81
 
82
- - `.`, `./runtime`: `h`, `Fragment`, `raw`, `signal`/`batch`/`mapSignal`/`derived`,
83
- `createRuntime`, `defaultRuntime`, `defineShadow`, `createThemePlugin`, part descriptor helpers,
84
- plus VNode/Signal/metadata, `Context` and generic ref types.
82
+ - `.`, `./runtime`: `h`, `Fragment`, `raw`, `createRuntime`, `defaultRuntime`, `defineShadow`,
83
+ `createThemePlugin`, part descriptor helpers, plus VNode/metadata, `Context` and generic ref types.
84
+ Existing reactive exports remain available and share the implementation below.
85
+ - `./signal`: `signal`, `batch`, `mapSignal`, `derived`, `isSignal`, `unwrap`, and the
86
+ `ReadableSignal`, `WritableSignal`, `Signal` and `MaybeSignal` types. This DOM-free entry loads
87
+ the reactive implementation without creating a runtime or renderer.
85
88
  - `./renderer`: `RenderStrategy<TNode>`, `createRenderer()`, `Renderer`/`Rendered`/
86
89
  `RendererOptions`, `ComponentObserver`/`ObservedComponent` and other target-seam types. `createRenderer()` injects component lifecycle,
87
90
  render hooks, overrides and `key`/`componentPart` identity; the target only implements node and attribute placement.
@@ -95,6 +98,16 @@ meowjsx (this package: core + JSX contract)
95
98
  The core root has no `render`/`renderToHtml`: `render(node, Element)` and HTML serialization are imported from
96
99
  `meowjsx/web`. The root does not import Web back; both use the same core module, and multiple explicit Runtimes can still be created independently.
97
100
 
101
+ ### API migration
102
+
103
+ - Use `defineShadow(component, part, setup)` in place of the removed `shadow` alias. It creates a
104
+ definition; register it through `createRuntime({ shadows: [...] })` or a runtime plugin. Setup runs
105
+ when the target mounts the matching part. Core keeps the host handle generic; `meowjsx/web` types
106
+ it as `Element`.
107
+ - Use `renderer.render(node, parent, before?)` on the target-neutral renderer and
108
+ `web.render(node, container)` on the Web renderer. Both return an `unmount()` handle. The `mount`
109
+ methods and top-level Web `mount` export are removed; static output remains `renderToHtml`.
110
+
98
111
  ## Invariant: core contains no platform
99
112
 
100
113
  The core source (including types) does not contain `document`, `window`, DOM `Element`/`HTMLElement`,
@@ -119,6 +132,9 @@ empty strings. They do not merge conflicting classes or interpret objects as cla
119
132
  The native `class` attribute follows the same runtime normalization.
120
133
 
121
134
  ```tsx
135
+ import { h } from "meowjsx";
136
+ import { signal } from "meowjsx/signal";
137
+
122
138
  const stateClass = signal("is-idle");
123
139
  <div className={["panel", [false, stateClass], "host-panel"]} />;
124
140
  stateClass.value = "is-active";
@@ -134,7 +150,11 @@ public `ClassValue` type is available to components that forward `className`.
134
150
  Components are ordinary functions. A static `meta` declares their stable name and finite parts;
135
151
  `Context<typeof Component>` supplies the lifecycle and a typed `parts` map. Use
136
152
  `Context<typeof Component, ComponentProps>` when setup also needs the declared types of
137
- `context.props`. Setup runs once per mount, and Signals carry later changes.
153
+ `context.props`. Setup runs once per mount, and Signals carry later changes. Import `signal`
154
+ directly from `meowjsx/signal` and create local state inside setup; each mount creates its own Signals.
155
+ `context.effect` and `context.onCleanup` manage effects and cleanup for that mount. Signals have no
156
+ dispose operation; the renderer releases its binding subscriptions on unmount. Register any manual
157
+ subscription's unsubscribe function with `context.onCleanup`.
138
158
 
139
159
  ```tsx
140
160
  import { h, type Context, type Props } from "meowjsx";
@@ -200,6 +220,36 @@ its lifecycle is managed by the consumer, and no global observation tree is crea
200
220
  Public JS artifacts preserve module relationships: the root, runtime, automatic JSX and Web entries reference the same core.
201
221
  Release builds must not copy a defaultRuntime, Context or reactive scheduler per entry.
202
222
 
223
+ ## Signal interoperability
224
+
225
+ Import reactive functions and types from `meowjsx/signal`:
226
+
227
+ ```ts
228
+ import { signal, mapSignal, derived, batch, type ReadableSignal } from "meowjsx/signal";
229
+ ```
230
+
231
+ The renderer's `SignalLike<T>` type from `meowjsx/renderer` describes its structural input protocol.
232
+ MeowJSX's `ReadableSignal<T>` and compatible external implementations satisfy that protocol. JSX
233
+ bindings accept any object with this shape; no MeowJSX constructor or brand is required:
234
+
235
+ ```ts
236
+ interface SignalLike<T> {
237
+ readonly value: T;
238
+ subscribe(listener: (value: T) => void): () => void;
239
+ }
240
+ ```
241
+
242
+ `value` returns the current value. `subscribe` reports changed values and returns an unsubscribe
243
+ function. The renderer reads the initial value, subscribes for updates and unsubscribes on unmount.
244
+ `mapSignal(source, map)` also subscribes explicitly, so it works with external implementations.
245
+ A third-party API with a different shape needs an adapter to this contract.
246
+
247
+ Automatic dependency tracking in `context.effect` and `derived` requires getters from the shared
248
+ MeowJSX reactive implementation. Reading an external Signal's `.value` alone does not register it as
249
+ a dependency; this also applies to component logic that uses those computations. Use `mapSignal`
250
+ for an explicit source, or subscribe directly and register the unsubscribe function with
251
+ `context.onCleanup`. The root, runtime and signal entries share one reactive module and scheduler.
252
+
203
253
  ## Derived signals
204
254
 
205
255
  `derived(read)` is a read-only signal. `read` runs again when any signal it read changes, and subscribers hear the value when `Object.is` says it changed. `read` must not write signals. One source can also use `mapSignal`. A computation is not stored by writing another signal from `effect`.
@@ -210,6 +260,9 @@ Release builds must not copy a defaultRuntime, Context or reactive scheduler per
210
260
  a deletion releases that row's lifecycle, and reordering moves the existing range. Whole-replacement semantics for plain arrays and Signals are unchanged.
211
261
 
212
262
  ```ts
263
+ import { h, keyed } from "meowjsx";
264
+ import { mapSignal, signal } from "meowjsx/signal";
265
+
213
266
  const items = signal([{ id: "one", label: "First" }]);
214
267
  const rows = keyed(
215
268
  items,
@@ -1,8 +1,8 @@
1
1
  import type { Cleanup, LifecycleScope, Runtime } from "./types.js";
2
2
  /**
3
3
  * Create a lifecycle scope. Components receive one per invocation; a target
4
- * that mounts a shadow uses the same primitive so signals, effects, and
5
- * cleanups follow one ownership rule.
4
+ * that mounts a shadow uses the same primitive so effects and cleanups follow
5
+ * one ownership rule.
6
6
  */
7
7
  export declare function createLifecycleScope(runtime: Runtime): LifecycleScope & {
8
8
  dispose(): void;
@@ -1,8 +1,8 @@
1
- import { createReactiveEffect, signal } from "./reactive.js";
1
+ import { createReactiveEffect } from "./reactive.js";
2
2
  /**
3
3
  * Create a lifecycle scope. Components receive one per invocation; a target
4
- * that mounts a shadow uses the same primitive so signals, effects, and
5
- * cleanups follow one ownership rule.
4
+ * that mounts a shadow uses the same primitive so effects and cleanups follow
5
+ * one ownership rule.
6
6
  */
7
7
  export function createLifecycleScope(runtime) {
8
8
  let active = true;
@@ -23,7 +23,6 @@ export function createLifecycleScope(runtime) {
23
23
  };
24
24
  return {
25
25
  runtime,
26
- signal,
27
26
  effect(run) {
28
27
  const stop = createReactiveEffect(run);
29
28
  onCleanup(stop);
@@ -116,7 +116,6 @@ export interface Renderer<TNode> {
116
116
  insert(parent: TNode, node: TNode, before?: TNode | null): void;
117
117
  remove(node: TNode): void;
118
118
  setProperty(node: TNode, name: string, value: unknown): void | RendererCleanup;
119
- mount(node: RenderableChild, parent: TNode, before?: TNode | null): Rendered<TNode>;
120
119
  render(node: RenderableChild, parent: TNode, before?: TNode | null): Rendered<TNode>;
121
120
  }
122
121
  /**
@@ -1,5 +1,5 @@
1
1
  import { isKeyedChild, readKeyedEntries } from "./keyed.js";
2
- import { signal } from "./reactive.js";
2
+ import { isAsyncIterable, isPromiseLike, isSignal, signal } from "./reactive.js";
3
3
  import { normalizeClassName } from "./style.js";
4
4
  import { isNormalizedRef, mountRefBindings } from "./parts.js";
5
5
  export { createComponentObservation, } from "./observation.js";
@@ -34,23 +34,6 @@ function tryCleanups(cleanups) {
34
34
  function isRecord(value) {
35
35
  return typeof value === "object" && value !== null;
36
36
  }
37
- function isSignal(value) {
38
- return ((typeof value === "object" || typeof value === "function") &&
39
- value !== null &&
40
- "value" in value &&
41
- "subscribe" in value &&
42
- typeof value.subscribe === "function");
43
- }
44
- function isPromiseLike(value) {
45
- return ((typeof value === "object" || typeof value === "function") &&
46
- value !== null &&
47
- typeof value.then === "function");
48
- }
49
- function isAsyncIterable(value) {
50
- return ((typeof value === "object" || typeof value === "function") &&
51
- value !== null &&
52
- typeof value[Symbol.asyncIterator] === "function");
53
- }
54
37
  function isVNode(value) {
55
38
  if (!isRecord(value) || !("type" in value) || !("props" in value))
56
39
  return false;
@@ -576,7 +559,7 @@ export function createRenderer(strategy, options = {}) {
576
559
  throw error;
577
560
  }
578
561
  }
579
- const mount = (node, parent, before = null) => {
562
+ const render = (node, parent, before = null) => {
580
563
  const mounted = mountChild(node, parent, before);
581
564
  return {
582
565
  nodes: mounted.nodes,
@@ -592,7 +575,6 @@ export function createRenderer(strategy, options = {}) {
592
575
  insert: (parent, node, before) => strategy.insert(parent, node, before),
593
576
  remove: (node) => strategy.remove(node),
594
577
  setProperty: (node, name, value) => strategy.setProperty(node, name, value),
595
- mount,
596
- render: mount,
578
+ render,
597
579
  };
598
580
  }
@@ -10,7 +10,6 @@ export { createThemePlugin, styleText } from "./style.js";
10
10
  export declare function defineShadow<C extends Component<any, any> & {
11
11
  readonly meta: ComponentMeta;
12
12
  }, Part extends C["meta"]["parts"][number], TNode = unknown>(component: C, part: Part, setup: ShadowSetup<Parameters<C>[0], C["meta"]["name"], Part, TNode>): ShadowDefinition<Parameters<C>[0], C["meta"]["name"], C["meta"]["parts"][number], Part, TNode>;
13
- export declare const shadow: typeof defineShadow;
14
13
  export declare function createRuntime(options?: RuntimeOptions): Runtime;
15
14
  export declare const defaultRuntime: Runtime;
16
15
  export declare const registry: import("./types.js").ComponentRegistry;
@@ -28,7 +28,6 @@ export function defineShadow(component, part, setup) {
28
28
  setup,
29
29
  };
30
30
  }
31
- export const shadow = defineShadow;
32
31
  export function createRuntime(options = {}) {
33
32
  const state = {
34
33
  createHooks: [],
@@ -0,0 +1,2 @@
1
+ export { batch, derived, isSignal, mapSignal, signal, unwrap } from "./reactive.js";
2
+ export type { MaybeSignal, ReadableSignal, Signal, WritableSignal } from "./types.js";
@@ -0,0 +1 @@
1
+ export { batch, derived, isSignal, mapSignal, signal, unwrap } from "./reactive.js";
@@ -49,7 +49,6 @@ export interface ComponentRegistry {
49
49
  }
50
50
  export interface LifecycleScope {
51
51
  readonly runtime: Runtime;
52
- signal<T>(initialValue: T): WritableSignal<T>;
53
52
  effect(run: Effect): Cleanup;
54
53
  onCleanup(cleanup: Cleanup): void;
55
54
  }
@@ -1,5 +1,5 @@
1
1
  export type { WebRef, WebRefCallback, WebRefCleanup, WebHostProps, WebIntrinsicElements, } from "./types.js";
2
- export { createWebRenderer, defaultWebRenderer, mount, render, renderToHtml, type WebRenderer, type WebRendererOptions, } from "./render.js";
2
+ export { createWebRenderer, defaultWebRenderer, render, renderToHtml, type WebRenderer, type WebRendererOptions, } from "./render.js";
3
3
  export { renderToHtmlWithRuntime } from "./html.js";
4
4
  export { useWebObservation } from "./observation.js";
5
5
  export { createDomStrategy, setDOMProperty, type DomNode } from "./strategy.js";
package/dist/web/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { createWebRenderer, defaultWebRenderer, mount, render, renderToHtml, } from "./render.js";
1
+ export { createWebRenderer, defaultWebRenderer, render, renderToHtml, } from "./render.js";
2
2
  export { renderToHtmlWithRuntime } from "./html.js";
3
3
  export { useWebObservation } from "./observation.js";
4
4
  export { createDomStrategy, setDOMProperty } from "./strategy.js";
@@ -9,7 +9,6 @@ import { type DomNode } from "./strategy.js";
9
9
  export interface WebRenderer {
10
10
  readonly runtime: Runtime;
11
11
  readonly render: (node: Child, container: Element) => MountResult;
12
- readonly mount: (node: Child, container: Element) => MountResult;
13
12
  readonly renderToHtml: (node: Child) => string;
14
13
  }
15
14
  export type WebRendererOptions = Pick<RendererOptions<DomNode>, "onError" | "observer"> & {
@@ -19,5 +18,4 @@ export declare function createWebRenderer(runtime?: Runtime, options?: WebRender
19
18
  /** The default runtime's Web renderer; apps that install into it use this one. */
20
19
  export declare const defaultWebRenderer: WebRenderer;
21
20
  export declare const render: (node: Child, container: Element) => MountResult;
22
- export declare const mount: (node: Child, container: Element) => MountResult;
23
21
  export declare const renderToHtml: (node: Child) => string;
@@ -25,13 +25,12 @@ export function createWebRenderer(runtime = defaultRuntime, options = {}) {
25
25
  const child = options.observation
26
26
  ? h(WebObservationContext.Provider, { value: options.observation }, node)
27
27
  : node;
28
- const mounted = renderer.mount(child, container, null);
28
+ const mounted = renderer.render(child, container, null);
29
29
  return { unmount: () => mounted.unmount() };
30
30
  };
31
31
  return {
32
32
  runtime,
33
33
  render,
34
- mount: render,
35
34
  renderToHtml: (node) => renderToHtmlWithRuntime(runtime, node),
36
35
  };
37
36
  }
@@ -43,5 +42,4 @@ function defaultMember(key) {
43
42
  return defaultWebRenderer[key];
44
43
  }
45
44
  export const render = /* @__PURE__ */ defaultMember("render");
46
- export const mount = /* @__PURE__ */ defaultMember("mount");
47
45
  export const renderToHtml = /* @__PURE__ */ defaultMember("renderToHtml");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meowjsx",
3
- "version": "0.2.0-alpha.0",
3
+ "version": "0.3.0-alpha.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -25,6 +25,10 @@
25
25
  "types": "./dist/src/runtime.d.ts",
26
26
  "import": "./dist/src/runtime.js"
27
27
  },
28
+ "./signal": {
29
+ "types": "./dist/src/signal.d.ts",
30
+ "import": "./dist/src/signal.js"
31
+ },
28
32
  "./renderer": {
29
33
  "types": "./dist/src/renderer.d.ts",
30
34
  "import": "./dist/src/renderer.js"