meowjsx 0.1.1-alpha.0 → 0.2.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 +7 -7
- package/README.md +169 -116
- package/dist/src/context.d.ts +3 -6
- package/dist/src/context.js +1 -3
- package/dist/src/json/view.d.ts +2 -2
- package/dist/src/jsx-runtime.js +13 -6
- package/dist/src/parts.d.ts +29 -0
- package/dist/src/parts.js +102 -0
- package/dist/src/reactive.d.ts +6 -0
- package/dist/src/reactive.js +92 -0
- package/dist/src/registry.d.ts +6 -5
- package/dist/src/registry.js +76 -48
- package/dist/src/renderer.d.ts +2 -2
- package/dist/src/renderer.js +8 -1
- package/dist/src/runtime.d.ts +11 -9
- package/dist/src/runtime.js +33 -44
- package/dist/src/style.d.ts +5 -1
- package/dist/src/style.js +92 -6
- package/dist/src/types.d.ts +49 -72
- package/dist/web/html.js +5 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/observation.d.ts +1 -1
- package/dist/web/render.js +9 -4
- package/dist/web/shadows.d.ts +4 -2
- package/dist/web/shadows.js +1 -1
- package/dist/web/strategy.js +2 -1
- package/dist/web/types.d.ts +22 -0
- package/dist/web/types.js +1 -0
- package/package.json +2 -1
package/JSON.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# JSON
|
|
1
|
+
# JSON description entry
|
|
2
2
|
|
|
3
|
-
`meowjsx/json`
|
|
3
|
+
`meowjsx/json` builds ordinary MeowJSX VNodes from finite JSON descriptions, using the existing runtime, Context, Signal, components and renderer lifecycle; the core root entry does not import JSON or the DOM back.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
import { createJsonView, defineJsonComponent, jsonSchema, parseJsonView } from "meowjsx/json";
|
|
@@ -23,12 +23,12 @@ const description = parseJsonView(
|
|
|
23
23
|
const child = createJsonView(description, { catalog, bindings: new Map([["label", text]]) });
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Nodes support strings, finite numbers, booleans, null, node arrays, and `{component, props?, children?}`. `component` must be an exact name in the host catalog; arbitrary HTML tags, raw HTML, refs, code, dynamic imports, expressions or object paths are not provided. A binding in a description has the exclusive shape `{$binding:"exact name"}`, and an action has `{$action:"exact name"}`. Names are looked up only as exact Map keys; dots and paths are not parsed, and no external permissions are granted.
|
|
27
27
|
|
|
28
|
-
`parseJsonView`
|
|
28
|
+
`parseJsonView` only validates, copies and freezes data; it does not execute components, actions, event projections, Signal getters or runtime hooks. `createJsonView` then validates against the given catalog, binds the host's read-only Signals and real functions, and constructs VNodes; mounting and unmounting are still managed by the original renderer. Action arguments are validated by the finite schema in metadata; the host may provide a trusted `mapArgs` in metadata to project native events into explicit arguments, while JSON cannot provide executable code. The callback's original return value is preserved.
|
|
29
29
|
|
|
30
|
-
`jsonSchema`
|
|
30
|
+
`jsonSchema` supports string/number/boolean/enum/array/object/optional/data/union, and description and validation share these definitions. Object fields are strict, and a union must match one complete branch; `data()` only promises a pure JsonValue and does not claim through generics that a complex business type has been validated. Ordinary fields named constructor, $binding or $action inside data are still data and are not recursively interpreted as controls. If a prop's outermost value happens to be an exclusive reference marker, it is kept as a reference; when that literal object is needed, the host binding provides it rather than an additional escape DSL.
|
|
31
31
|
|
|
32
|
-
`defineJsonComponent`
|
|
32
|
+
`defineJsonComponent` statically associates finite metadata with the original component's Props and excludes arbitrary index fields of open Props; it does not reflect TS types automatically and does not claim that a whole-component schema exists. A concrete component library must state its supported set explicitly. `describeJsonCatalog` and `describeJsonSchema` output the finite description from the same metadata and do not maintain a separate schema. Functions, File, class instances, accessors, circular references, sparse arrays and non-finite numbers are not JSON data; the host is still responsible for network, permissions, persistence and the real data source.
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Value metadata may provide a literal `default` that is validated against the same schema and copied and frozen, filled in only when the description omits that property; false, 0 and the empty string are not treated as missing. It does not execute actions, bindings or callbacks, and does not change the requirement that an explicit value for that property still matches the schema.
|
package/README.md
CHANGED
|
@@ -2,64 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
## Render-tree context
|
|
4
4
|
|
|
5
|
-
`createContext(defaultValue)`
|
|
6
|
-
`<Context.Provider value={value}>…</Context.Provider>`
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
不建立额外 dirty 集合或微任务。此回调抛错走 renderer 的 `onError(error, "async")`,不回滚
|
|
52
|
-
已发生的渲染;未提供错误出口则异步抛出。
|
|
53
|
-
|
|
54
|
-
工具可设置 `observer.roots`,按 child 对象引用限定观察子树;省略时观察整棵渲染树,
|
|
55
|
-
空数组时不观察实例。进入每个根后,首层组件的 `parent` 为 `null`,外层容器仍正常渲染、
|
|
56
|
-
传递 context 和执行 lifecycle,但不进入观察投影。根可为 VNode、Signal、Promise 或
|
|
57
|
-
AsyncIterable,延迟输出继续使用该范围。调用方若把内容数组展开交给容器,应传入其中的
|
|
58
|
-
实际 child 引用。此范围不增加组件调用,不影响 runtime hooks 或组件替换。
|
|
59
|
-
|
|
60
|
-
多消费者使用 `createComponentObservation<TNode>({ roots?, onError? })`,而不是各自复制
|
|
61
|
-
实例 Map。它返回 `observer`、`read(root?)`、`subscribe(listener, { root? })` 和 `dispose()`。
|
|
62
|
-
将 `observer` 接入 renderer 后,先订阅再读取即可取得当前状态和后续失效通知:
|
|
5
|
+
`createContext(defaultValue)` returns a typed Context and a `Provider` component.
|
|
6
|
+
`<Context.Provider value={value}>…</Context.Provider>` does not create a host node; descendant components read the nearest
|
|
7
|
+
ancestor value with `useContext(Context)` during synchronous render, and get the default when there is no Provider.
|
|
8
|
+
An explicitly provided `undefined` is still a value and does not fall back to the default. Siblings, independent root nodes and runtimes do not share environment.
|
|
9
|
+
|
|
10
|
+
Environment follows render-tree traversal, not the location where the VNode was created. Pre-created VNodes, arrays, host wrapper layers and subtrees replaced later by a Signal use the environment captured in the current area; deferred mounting of Promises and AsyncIterables preserves it as well.
|
|
11
|
+
Synchronous HTML output follows the same ancestor rule, but still does not support Promise / AsyncIterable content and throws when it encounters them.
|
|
12
|
+
|
|
13
|
+
`useContext` reads environment only during the component's synchronous execution. Event handlers and code after `await` must use the value captured in render beforehand; do not treat it as asynchronous local storage. Provider does not add whole-tree re-render or dependency tracking; to share a dynamic value, pass a Signal object as the value and let consumers use the existing Signal binding. Replacing a Provider's ordinary value does not automatically re-run already mounted descendants. Context's internal scope is passed by the renderer and users must not modify it.
|
|
14
|
+
|
|
15
|
+
`RuntimePlugin.resolveComponent({ component, props, runtime })` can select a replacement function before the component is called.
|
|
16
|
+
It is called in the order `pre`, normal, `post`, and within each group's registration order; the first non-`undefined` result wins, and returning the original function also stops resolution; the result is not resolved recursively. Selection happens before the lifecycle scope is created, and the selected component uses its own metadata, parts and cleanup logic while the original component does not execute. `props` is a read-only typed view and does not copy or freeze the object.
|
|
17
|
+
|
|
18
|
+
This hook belongs to the execution runtime: pre-created VNodes, Signal/Promise deferred mounts and synchronous HTML all apply. The cleanup returned by `runtime.use()` unmounts rules and does not rewrite already mounted instances; other runtimes are unaffected.
|
|
19
|
+
It does not intercept module side effects or direct function calls, and does not change the meaning of the `create` / `render` hooks.
|
|
20
|
+
|
|
21
|
+
## Development metadata and instance observation
|
|
22
|
+
|
|
23
|
+
Component functions may carry `metadata?: ComponentMetadata`. `ComponentMetadata` is an open type-extension interface; development tools register their own namespaces through declaration merging, and core does not interpret or read their tool fields.
|
|
24
|
+
`Component<Props>` preserves this constraint, and ordinary functions can use
|
|
25
|
+
`satisfies ComponentMetadata` to check assignment. Metadata is not part of props or component runtime options.
|
|
26
|
+
|
|
27
|
+
`runtime.createRenderer(strategy, { observer })` enables target-neutral instance observation:
|
|
28
|
+
`onComponent(instance)` reports creation, `onUnmount(instance)` reports unmounting; the optional
|
|
29
|
+
`onNode(instance, node, mounted)` reports node-association changes. An instance includes this renderer's `id`,
|
|
30
|
+
`parent`, the original function `originalComponent`, the actually executed function `component`, and a live read-only `nodes` collection.
|
|
31
|
+
The collection includes host and text output of that instance and its descendants, excluding internal markers; Signal, Promise and AsyncIterable updates keep the current associations.
|
|
32
|
+
Arrays and host tags do not add component levels, and direct function calls do not create component instances.
|
|
33
|
+
|
|
34
|
+
Built-in Fragment and Context Provider report `semantic` as `fragment` or
|
|
35
|
+
`context-provider` according to their actual executed function identity, not by name guessing. Replaced components use the selected function's semantic identity and metadata.
|
|
36
|
+
Observation adds no host wrapper layers; when disabled, no instance or node index is created. Callbacks run synchronously, and a throw is handled as a mount or cleanup failure; tools should handle diagnostics at their own boundary. Instances are removed from the tool projection after unmount, and `id` is not used to locate instances across runs.
|
|
37
|
+
|
|
38
|
+
The optional `onFlush(changed)` merges instance-invalidation notices in a microtask, covering component mount/unmount, node associations and updates to mounted host Signal props; exceptions and rollbacks also notify instances whose current facts may have changed. `changed` uses real instance
|
|
39
|
+
identity and includes instances unloaded in this round; it is not a successful-commit record. The set is cleared before the callback runs, and new changes caused by the callback go into the
|
|
40
|
+
next round without recursive delivery. It does not mean DOM layout, paint, all asynchronous work or application readiness; without this callback,
|
|
41
|
+
no additional dirty set or microtask is established. A throw from this callback goes through the renderer's `onError(error, "async")` and does not roll back
|
|
42
|
+
rendering that already happened; if no error outlet is provided, it is thrown asynchronously.
|
|
43
|
+
|
|
44
|
+
Tools can set `observer.roots` to limit the observed subtree by child object reference; when omitted the whole render tree is observed, and an empty array observes no instances. After entering each root, the first-level component's `parent` is `null`; outer containers still render normally,
|
|
45
|
+
pass context and run lifecycle, but do not enter the observation projection. A root may be a VNode, Signal, Promise or
|
|
46
|
+
AsyncIterable, and deferred output continues to use that scope. If the caller expands a content array into a container, it should pass the actual child references inside it. This scope adds no component calls and does not affect runtime hooks or component replacement.
|
|
47
|
+
|
|
48
|
+
Multiple consumers use `createComponentObservation<TNode>({ roots?, onError? })` instead of each copying
|
|
49
|
+
its own instance Map. It returns `observer`, `read(root?)`, `subscribe(listener, { root? })` and `dispose()`.
|
|
50
|
+
After wiring `observer` into the renderer, subscribe first and then read to obtain the current state and subsequent invalidation notices:
|
|
63
51
|
|
|
64
52
|
```ts
|
|
65
53
|
const observation = createComponentObservation<HostNode>({ onError: reportObserverError });
|
|
@@ -68,70 +56,131 @@ const unsubscribe = observation.subscribe(() => inspect(observation.read()));
|
|
|
68
56
|
const current = observation.read();
|
|
69
57
|
```
|
|
70
58
|
|
|
71
|
-
`read`
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
缺少该出口或出口再次抛错时异步报错,不静默吞错。
|
|
59
|
+
`read` returns a copy of the current instance-member array; the instance `nodes` is still the renderer-owned live collection; it is not
|
|
60
|
+
an immutable historical snapshot. `root` is the real instance object and includes itself and its descendants; reading an unmounted root is empty. Changes inside the root and ancestor changes can both invalidate subscriptions; notification may be conservative and does not promise a precise layout-impact set. Subscriptions have no implicit first replay;
|
|
61
|
+
delivery uses a snapshot of the subscriber list and re-checks validity before calling, so subscriptions cancelled in this round no longer run, and newly added
|
|
62
|
+
subscriptions begin with later notifications. A throwing consumer does not block other consumers; the error goes to the observation center's `onError`;
|
|
63
|
+
if that outlet is missing or throws again, the error is reported asynchronously rather than silently swallowed.
|
|
77
64
|
|
|
78
|
-
`dispose`
|
|
79
|
-
renderer
|
|
80
|
-
|
|
81
|
-
时读取并固定,适用于工具在创建前设置真实 child;不是运行时动态切换入口。纯宿主或文本根
|
|
82
|
-
没有组件实例,外部 DOM/样式、字体加载和浏览器尺寸变化也不属于该观察合同。
|
|
65
|
+
`dispose` only stops observation and clears the projection; it does not unmount the view. Afterwards `read` is empty and `subscribe` rejects; late notifications
|
|
66
|
+
from an existing renderer are ignored. Usually one observation center is attached to one renderer; the implementation stores by instance identity and does not overwrite because different renderers have the same numeric id. `roots` may use a getter, but the scope is read and fixed when the renderer is created, suitable for tools that set the real child before creation; it is not a runtime dynamic-switch entry. Purely host or text roots
|
|
67
|
+
have no component instances, and external DOM/styles, font loading and browser size changes also do not belong to this observation contract.
|
|
83
68
|
|
|
84
|
-
MeowJSX
|
|
85
|
-
|
|
86
|
-
`createRenderer()
|
|
69
|
+
MeowJSX core: the JSX/VNode factory, Signal/batch/effect, component metadata and part bindings, shadow/plugin/theme
|
|
70
|
+
contracts, lifecycle and context, and the target-neutral renderer seam (`RenderStrategy<TNode>` /
|
|
71
|
+
`createRenderer()`). Core does not know the target platform.
|
|
87
72
|
|
|
88
73
|
```text
|
|
89
|
-
JSX
|
|
74
|
+
JSX source / component logic
|
|
90
75
|
│
|
|
91
|
-
meowjsx
|
|
92
|
-
└─→ meowjsx/web
|
|
76
|
+
meowjsx (this package: core + JSX contract)
|
|
77
|
+
└─→ meowjsx/web the same package's DOM / event / HTML / mount modules
|
|
93
78
|
```
|
|
94
79
|
|
|
95
|
-
##
|
|
80
|
+
## Exports
|
|
96
81
|
|
|
97
|
-
-
|
|
98
|
-
`createRuntime
|
|
99
|
-
|
|
100
|
-
- `./renderer
|
|
101
|
-
`RendererOptions
|
|
102
|
-
render
|
|
103
|
-
- `./jsx-runtime
|
|
104
|
-
- `./jsx-dev-runtime
|
|
105
|
-
- `./web
|
|
106
|
-
- `./json
|
|
107
|
-
- `Runtime.targetHooks
|
|
108
|
-
|
|
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.
|
|
85
|
+
- `./renderer`: `RenderStrategy<TNode>`, `createRenderer()`, `Renderer`/`Rendered`/
|
|
86
|
+
`RendererOptions`, `ComponentObserver`/`ObservedComponent` and other target-seam types. `createRenderer()` injects component lifecycle,
|
|
87
|
+
render hooks, overrides and `key`/`componentPart` identity; the target only implements node and attribute placement.
|
|
88
|
+
- `./jsx-runtime`: `jsx`/`jsxs`/`jsxDEV`/`Fragment`.
|
|
89
|
+
- `./jsx-dev-runtime`: the `jsxDEV`/`Fragment` needed by development automatic JSX, reusing the same implementation.
|
|
90
|
+
- `./web`: DOM mount, static HTML, Web shadow, instance-observation sources and skeleton visual controls.
|
|
91
|
+
- `./json`: finite descriptions, host binding/action references, single-source metadata validation and catalog descriptions; see [JSON entry](JSON.md).
|
|
92
|
+
- `Runtime.targetHooks`: when the target owns the output path (Web's static HTML), reuse the runtime's
|
|
93
|
+
component calls, render hooks and override semantics instead of copying a set into the target.
|
|
109
94
|
|
|
110
|
-
core
|
|
111
|
-
`meowjsx/web
|
|
95
|
+
The core root has no `render`/`renderToHtml`: `render(node, Element)` and HTML serialization are imported from
|
|
96
|
+
`meowjsx/web`. The root does not import Web back; both use the same core module, and multiple explicit Runtimes can still be created independently.
|
|
112
97
|
|
|
113
|
-
##
|
|
98
|
+
## Invariant: core contains no platform
|
|
114
99
|
|
|
115
|
-
core
|
|
116
|
-
|
|
117
|
-
`dom` lib
|
|
100
|
+
The core source (including types) does not contain `document`, `window`, DOM `Element`/`HTMLElement`,
|
|
101
|
+
browser `Event`, CSS APIs or terminal APIs. `packages/meowjsx/tsconfig.core.json` checks the whole core under a configuration without the
|
|
102
|
+
`dom` lib and with `types: []`:
|
|
118
103
|
|
|
119
104
|
```sh
|
|
120
105
|
bun node_modules/typescript/bin/tsc -p packages/meowjsx/tsconfig.core.json
|
|
121
106
|
```
|
|
122
107
|
|
|
123
|
-
|
|
108
|
+
The command above runs from the repository root and only checks the DOM-free core group. The package's `bun run typecheck` runs core, renderer and Web configurations in order; the final Web group explicitly includes the DOM and is not equivalent to the DOM-free core-only check. `tsconfig.renderer.json` independently checks the target-neutral renderer seam, and behavior cases use a fake target.
|
|
124
109
|
|
|
125
|
-
`ShadowContext.element`
|
|
126
|
-
|
|
127
|
-
`ThemeStyle`
|
|
110
|
+
`ShadowContext.element` is the target-provided host handle, typed as generic `TNode` in core
|
|
111
|
+
(defaults to `unknown`); the Web module narrows it to a real element. Theme contracts (`Theme`/`ThemeRule`/
|
|
112
|
+
`ThemeStyle` and their merge rules) stay in core as planned; they carry values only and touch no style API.
|
|
128
113
|
|
|
129
|
-
##
|
|
114
|
+
## Class lists
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
`className` accepts strings, stringifiable class values, nested readonly arrays, and Signals of
|
|
117
|
+
those values. Arrays keep their order, join with spaces, and omit `false`, `null`, `undefined` and
|
|
118
|
+
empty strings. They do not merge conflicting classes or interpret objects as class dictionaries.
|
|
119
|
+
The native `class` attribute follows the same runtime normalization.
|
|
133
120
|
|
|
134
|
-
|
|
121
|
+
```tsx
|
|
122
|
+
const stateClass = signal("is-idle");
|
|
123
|
+
<div className={["panel", [false, stateClass], "host-panel"]} />;
|
|
124
|
+
stateClass.value = "is-active";
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Static HTML reads current values without subscribing. Mounted nodes subscribe to Signals at any
|
|
128
|
+
list depth, update their class attribute in place, and release replaced sources and unmount
|
|
129
|
+
subscriptions. Theme-provided class lists compose with the caller's classes in the same way. The
|
|
130
|
+
public `ClassValue` type is available to components that forward `className`.
|
|
131
|
+
|
|
132
|
+
## Components and refs
|
|
133
|
+
|
|
134
|
+
Components are ordinary functions. A static `meta` declares their stable name and finite parts;
|
|
135
|
+
`Context<typeof Component>` supplies the lifecycle and a typed `parts` map. Use
|
|
136
|
+
`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.
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { h, type Context, type Props } from "meowjsx";
|
|
141
|
+
import type { WebRef } from "meowjsx/web";
|
|
142
|
+
|
|
143
|
+
interface PanelProps extends Props {
|
|
144
|
+
title: string;
|
|
145
|
+
ref?: WebRef<HTMLElement>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function Panel({ title, children, ref, ...props }: PanelProps, ctx: Context<typeof Panel>) {
|
|
149
|
+
return (
|
|
150
|
+
<section {...props} ref={[ctx.parts.root, ref]}>
|
|
151
|
+
<h2 ref={ctx.parts.heading}>{title}</h2>
|
|
152
|
+
<div ref={ctx.parts.body}>{children}</div>
|
|
153
|
+
</section>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
Panel.meta = { name: "panel", parts: ["root", "heading", "body"] } as const;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`ref` accepts nested readonly arrays of part descriptors, node callbacks and `false`/nullish
|
|
160
|
+
omissions. Callbacks run in order at the existing host-property mount point; returned synchronous
|
|
161
|
+
cleanups run in reverse order. A failure still releases acquired cleanups. Static HTML extracts part
|
|
162
|
+
identity without running callbacks. A host node accepts one distinct part identity, and a descriptor
|
|
163
|
+
can mark several nodes. Component refs remain props and are forwarded explicitly to the intended
|
|
164
|
+
host node.
|
|
165
|
+
|
|
166
|
+
Generic ref types stay in the DOM-free root. Importing the explicit `meowjsx/web` type surface adds
|
|
167
|
+
HTML/SVG node inference for native JSX refs. Register component functions with `components: [Panel]`;
|
|
168
|
+
metadata does not register itself. The [parts and ref-binding design](../../docs/designs/2026-10-24-component-parts-ref-bindings.md)
|
|
169
|
+
records the breaking migration and theme adapter.
|
|
170
|
+
|
|
171
|
+
## Bundling
|
|
172
|
+
|
|
173
|
+
The package declares `sideEffects: false` and ships one ESM module per source file. The default
|
|
174
|
+
runtime, JSX runtime and Web renderer are created by `/* @__PURE__ */` calls, and their exported
|
|
175
|
+
members (`h`, `Fragment`, `jsx`, `render` and the rest) are pure reads, so a bundle that imports only
|
|
176
|
+
Signals, Context or types leaves the runtime and renderer out.
|
|
177
|
+
|
|
178
|
+
## Verification
|
|
179
|
+
|
|
180
|
+
- `bun test packages/meowjsx/tests/unit`: Signal, VNode, plugin, metadata, part/ref bindings, fake target seam and Web host tests.
|
|
181
|
+
- `tests/types/` checks core and Web type cases separately; the core type environment does not include the DOM.
|
|
182
|
+
|
|
183
|
+
## Web module
|
|
135
184
|
|
|
136
185
|
```ts
|
|
137
186
|
import { createRuntime, h } from "meowjsx";
|
|
@@ -142,19 +191,23 @@ const mounted = web.render(h("p", {}, "Hello"), document.querySelector("main")!)
|
|
|
142
191
|
mounted.unmount();
|
|
143
192
|
```
|
|
144
193
|
|
|
145
|
-
Web
|
|
146
|
-
`createSkeletonController`
|
|
147
|
-
|
|
148
|
-
`createWebRenderer(runtime)`
|
|
149
|
-
|
|
194
|
+
The Web source lives in `web/`, and DOM types only arrive through that entry. Static `renderToHtml` does not mount a DOM or run shadow;
|
|
195
|
+
`createSkeletonController` needs a real document and CSS Custom Highlight support only when called.
|
|
196
|
+
Importing the module creates the default Web renderer and observation Context; it does not install styles or listeners.
|
|
197
|
+
`createWebRenderer(runtime)` respects the components, themes and plugins already installed in that runtime; when an observation source is passed explicitly,
|
|
198
|
+
its lifecycle is managed by the consumer, and no global observation tree is created across renderers.
|
|
199
|
+
|
|
200
|
+
Public JS artifacts preserve module relationships: the root, runtime, automatic JSX and Web entries reference the same core.
|
|
201
|
+
Release builds must not copy a defaultRuntime, Context or reactive scheduler per entry.
|
|
202
|
+
|
|
203
|
+
## Derived signals
|
|
150
204
|
|
|
151
|
-
|
|
152
|
-
发布构建不能为每个入口复制一份 defaultRuntime、Context 或响应式调度器。
|
|
205
|
+
`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`.
|
|
153
206
|
|
|
154
|
-
##
|
|
207
|
+
## Keyed dynamic lists
|
|
155
208
|
|
|
156
|
-
`keyed(items, key, render)`
|
|
157
|
-
|
|
209
|
+
`keyed(items, key, render)` keeps rows with the same key holding the same components, nodes, Context and observation parent chain; an update only changes that row's read-only item Signal,
|
|
210
|
+
a deletion releases that row's lifecycle, and reordering moves the existing range. Whole-replacement semantics for plain arrays and Signals are unchanged.
|
|
158
211
|
|
|
159
212
|
```ts
|
|
160
213
|
const items = signal([{ id: "one", label: "First" }]);
|
|
@@ -170,7 +223,7 @@ const rows = keyed(
|
|
|
170
223
|
);
|
|
171
224
|
```
|
|
172
225
|
|
|
173
|
-
`render`
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
226
|
+
`render` constructs a Child and is not an extra lifecycle hook; when reading Signals inside a component, keep using the existing Signal properties or `mapSignal`.
|
|
227
|
+
Keys must be unique and must be strings or finite numbers; duplicate/invalid keys and new-row mount failures keep the original rows and values, and later valid updates still continue.
|
|
228
|
+
Target insert/remove failures provide no transactional rollback. Ordinary appends at either end do not move old rows; whether native focus survives arbitrary reordering depends on the target's move capability.
|
|
229
|
+
Static HTML reads the list once and does not subscribe or mount a DOM.
|
package/dist/src/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Child, Component } from "./runtime.js";
|
|
2
2
|
/** A render-tree environment. Targets carry it through deferred child regions. */
|
|
3
3
|
export type ContextScope = ReadonlyMap<symbol, unknown>;
|
|
4
|
-
export interface
|
|
4
|
+
export interface ContextValue<T> {
|
|
5
5
|
readonly key: symbol;
|
|
6
6
|
readonly defaultValue: T;
|
|
7
7
|
readonly Provider: Component<{
|
|
@@ -9,11 +9,8 @@ export interface Context<T> {
|
|
|
9
9
|
children?: Child;
|
|
10
10
|
}>;
|
|
11
11
|
}
|
|
12
|
-
/** Semantic identity for runtime observation, independent of function names. */
|
|
13
12
|
export declare function isContextProvider(component: Function): boolean;
|
|
14
|
-
export declare function createContext<T>(defaultValue: T):
|
|
15
|
-
|
|
16
|
-
export declare function useContext<T>(context: Context<T>): T;
|
|
17
|
-
/** Runtime/target seam, not a process-wide persistent provider stack. */
|
|
13
|
+
export declare function createContext<T>(defaultValue: T): ContextValue<T>;
|
|
14
|
+
export declare function useContext<T>(context: ContextValue<T>): T;
|
|
18
15
|
export declare function withContextScope<T>(scope: ContextScope | undefined, run: () => T): T;
|
|
19
16
|
export declare function contextScopeForProvider(component: Function, value: unknown, parent: ContextScope | undefined): ContextScope | undefined;
|
package/dist/src/context.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
const providers = new WeakMap();
|
|
2
2
|
let activeScope;
|
|
3
|
-
/** Semantic identity for runtime observation, independent of function names. */
|
|
4
3
|
export function isContextProvider(component) {
|
|
5
4
|
return providers.has(component);
|
|
6
5
|
}
|
|
6
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
7
7
|
export function createContext(defaultValue) {
|
|
8
8
|
const key = Symbol("meowjsx.context");
|
|
9
9
|
const Provider = ({ children }) => children ?? null;
|
|
10
10
|
providers.set(Provider, key);
|
|
11
11
|
return Object.freeze({ key, defaultValue, Provider });
|
|
12
12
|
}
|
|
13
|
-
/** Read synchronously while rendering; capture the value before an await/callback. */
|
|
14
13
|
export function useContext(context) {
|
|
15
14
|
return activeScope?.has(context.key) ? activeScope.get(context.key) : context.defaultValue;
|
|
16
15
|
}
|
|
17
|
-
/** Runtime/target seam, not a process-wide persistent provider stack. */
|
|
18
16
|
export function withContextScope(scope, run) {
|
|
19
17
|
const previous = activeScope;
|
|
20
18
|
activeScope = scope;
|
package/dist/src/json/view.d.ts
CHANGED
|
@@ -30,11 +30,11 @@ export type JsonPropsDefinition<P> = {
|
|
|
30
30
|
readonly [K in Exclude<KnownKeys<P>, "children">]?: NonNullable<P[K]> extends Callback ? JsonActionProperty<Extract<NonNullable<P[K]>, Callback>> : JsonValueProperty<P[K]>;
|
|
31
31
|
};
|
|
32
32
|
export interface JsonComponentDefinition<P extends object = any> {
|
|
33
|
-
readonly component: Component<P, any
|
|
33
|
+
readonly component: Component<P, any>;
|
|
34
34
|
readonly props: JsonPropsDefinition<P>;
|
|
35
35
|
}
|
|
36
36
|
export type JsonCatalog = ReadonlyMap<string, JsonComponentDefinition<any>>;
|
|
37
|
-
export declare function defineJsonComponent<P extends object>(component: Component<P, any
|
|
37
|
+
export declare function defineJsonComponent<P extends object>(component: Component<P, any>, props: JsonPropsDefinition<NoInfer<P>>): JsonComponentDefinition<P>;
|
|
38
38
|
export type JsonNode = string | number | boolean | null | readonly JsonNode[] | {
|
|
39
39
|
readonly component: string;
|
|
40
40
|
readonly props?: Readonly<Record<string, JsonValue>>;
|
package/dist/src/jsx-runtime.js
CHANGED
|
@@ -3,7 +3,9 @@ function createJSX(runtime, type, props, key) {
|
|
|
3
3
|
const { children, ...rest } = props ?? {};
|
|
4
4
|
if (key !== undefined)
|
|
5
5
|
rest.key = key;
|
|
6
|
-
return children === undefined
|
|
6
|
+
return children === undefined
|
|
7
|
+
? runtime.h(type, rest)
|
|
8
|
+
: runtime.h(type, rest, children);
|
|
7
9
|
}
|
|
8
10
|
export function createJSXRuntime(runtime) {
|
|
9
11
|
const jsx = (type, props, key) => createJSX(runtime, type, props, key);
|
|
@@ -15,8 +17,13 @@ export function createJSXRuntime(runtime) {
|
|
|
15
17
|
jsxDEV,
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
|
-
const defaultJSXRuntime = createJSXRuntime(defaultRuntime);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const defaultJSXRuntime = /* @__PURE__ */ createJSXRuntime(defaultRuntime);
|
|
21
|
+
// A pure read lets bundlers drop the default JSX runtime when none of these members is used.
|
|
22
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
23
|
+
function defaultMember(key) {
|
|
24
|
+
return defaultJSXRuntime[key];
|
|
25
|
+
}
|
|
26
|
+
export const Fragment = /* @__PURE__ */ defaultMember("Fragment");
|
|
27
|
+
export const jsx = /* @__PURE__ */ defaultMember("jsx");
|
|
28
|
+
export const jsxs = /* @__PURE__ */ defaultMember("jsxs");
|
|
29
|
+
export const jsxDEV = /* @__PURE__ */ defaultMember("jsxDEV");
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Cleanup } from "./types.js";
|
|
2
|
+
/** An opaque component and part identity carried by a host VNode. */
|
|
3
|
+
export interface PartDescriptor<Name extends string = string, Part extends string = string> {
|
|
4
|
+
readonly component: Name;
|
|
5
|
+
readonly part: Part;
|
|
6
|
+
readonly state?: Readonly<Record<string, unknown>>;
|
|
7
|
+
}
|
|
8
|
+
/** Create a descriptor by stable component and part names. */
|
|
9
|
+
export declare function createPartDescriptor<Name extends string, Part extends string>(component: Name, part: Part, state?: Readonly<Record<string, unknown>>): PartDescriptor<Name, Part>;
|
|
10
|
+
export declare function isPartDescriptor(value: unknown): value is PartDescriptor;
|
|
11
|
+
export type RefCleanup = () => void | {
|
|
12
|
+
readonly then?: never;
|
|
13
|
+
};
|
|
14
|
+
export type RefCallback<TNode> = (node: TNode) => void | RefCleanup;
|
|
15
|
+
export type RefBinding<TNode> = RefCallback<TNode> | PartDescriptor | false | null | undefined | readonly RefBinding<TNode>[];
|
|
16
|
+
declare const normalizedRef: unique symbol;
|
|
17
|
+
export interface NormalizedRef<TNode = unknown> {
|
|
18
|
+
readonly [normalizedRef]: true;
|
|
19
|
+
readonly callbacks: readonly RefCallback<TNode>[];
|
|
20
|
+
}
|
|
21
|
+
/** Flatten composed refs and resolve the single host part identity before hooks. */
|
|
22
|
+
export declare function normalizeRefBinding<TNode>(value: unknown): {
|
|
23
|
+
readonly ref?: NormalizedRef<TNode>;
|
|
24
|
+
readonly part?: PartDescriptor;
|
|
25
|
+
};
|
|
26
|
+
export declare function isNormalizedRef(value: unknown): value is NormalizedRef;
|
|
27
|
+
/** Invoke callbacks in order and release their successful cleanups in reverse order. */
|
|
28
|
+
export declare function mountRefBindings<TNode>(ref: NormalizedRef<TNode>, node: TNode): Cleanup;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const descriptors = new WeakSet();
|
|
2
|
+
/** Create a descriptor by stable component and part names. */
|
|
3
|
+
export function createPartDescriptor(component, part, state) {
|
|
4
|
+
const descriptor = Object.freeze({
|
|
5
|
+
component,
|
|
6
|
+
part,
|
|
7
|
+
...(state === undefined ? {} : { state }),
|
|
8
|
+
});
|
|
9
|
+
descriptors.add(descriptor);
|
|
10
|
+
return descriptor;
|
|
11
|
+
}
|
|
12
|
+
export function isPartDescriptor(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && descriptors.has(value);
|
|
14
|
+
}
|
|
15
|
+
const normalizedRef = Symbol("meowjsx.normalized-ref");
|
|
16
|
+
/** Flatten composed refs and resolve the single host part identity before hooks. */
|
|
17
|
+
export function normalizeRefBinding(value) {
|
|
18
|
+
const callbacks = [];
|
|
19
|
+
let part;
|
|
20
|
+
const visit = (entry) => {
|
|
21
|
+
if (entry === undefined || entry === null || entry === false)
|
|
22
|
+
return;
|
|
23
|
+
if (Array.isArray(entry)) {
|
|
24
|
+
for (const nested of entry)
|
|
25
|
+
visit(nested);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (isPartDescriptor(entry)) {
|
|
29
|
+
if (part && (part.component !== entry.component || part.part !== entry.part))
|
|
30
|
+
throw new Error("meowjsx host refs cannot bind multiple distinct parts");
|
|
31
|
+
if (!part || (part.state === undefined && entry.state !== undefined))
|
|
32
|
+
part = entry;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeof entry === "function") {
|
|
36
|
+
callbacks.push(entry);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
throw new Error("meowjsx ref bindings must be callbacks, part descriptors, or nested arrays");
|
|
40
|
+
};
|
|
41
|
+
visit(value);
|
|
42
|
+
return {
|
|
43
|
+
...(callbacks.length > 0
|
|
44
|
+
? {
|
|
45
|
+
ref: Object.freeze({
|
|
46
|
+
[normalizedRef]: true,
|
|
47
|
+
callbacks: Object.freeze(callbacks),
|
|
48
|
+
}),
|
|
49
|
+
}
|
|
50
|
+
: {}),
|
|
51
|
+
...(part ? { part } : {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function isNormalizedRef(value) {
|
|
55
|
+
return (typeof value === "object" &&
|
|
56
|
+
value !== null &&
|
|
57
|
+
Object.hasOwn(value, normalizedRef) &&
|
|
58
|
+
value[normalizedRef] === true);
|
|
59
|
+
}
|
|
60
|
+
/** Invoke callbacks in order and release their successful cleanups in reverse order. */
|
|
61
|
+
export function mountRefBindings(ref, node) {
|
|
62
|
+
const cleanups = [];
|
|
63
|
+
let active = true;
|
|
64
|
+
const release = () => {
|
|
65
|
+
if (!active)
|
|
66
|
+
return;
|
|
67
|
+
active = false;
|
|
68
|
+
let firstError;
|
|
69
|
+
let failed = false;
|
|
70
|
+
for (let index = cleanups.length - 1; index >= 0; index -= 1) {
|
|
71
|
+
try {
|
|
72
|
+
cleanups[index]();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (!failed) {
|
|
76
|
+
failed = true;
|
|
77
|
+
firstError = error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
cleanups.length = 0;
|
|
82
|
+
if (failed)
|
|
83
|
+
throw firstError;
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
for (const callback of ref.callbacks) {
|
|
87
|
+
const cleanup = callback(node);
|
|
88
|
+
if (typeof cleanup === "function")
|
|
89
|
+
cleanups.push(cleanup);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
try {
|
|
94
|
+
release();
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Keep the callback failure primary while attempting every rollback cleanup.
|
|
98
|
+
}
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
return release;
|
|
102
|
+
}
|
package/dist/src/reactive.d.ts
CHANGED
|
@@ -7,3 +7,9 @@ export declare function isPromiseLike<T = unknown>(value: unknown): value is Pro
|
|
|
7
7
|
export declare function isAsyncIterable<T = unknown>(value: unknown): value is AsyncIterable<T>;
|
|
8
8
|
export declare function unwrap<T>(value: MaybeSignal<T>): T;
|
|
9
9
|
export declare function mapSignal<T, M>(source: ReadableSignal<T>, map: (value: T) => M): ReadableSignal<M>;
|
|
10
|
+
/**
|
|
11
|
+
* Read-only signal. `read` runs again when any signal it touched changes.
|
|
12
|
+
* Subscribers are told only when `Object.is` sees a new value. `read` must not
|
|
13
|
+
* write signals; a cyclic read throws.
|
|
14
|
+
*/
|
|
15
|
+
export declare function derived<T>(read: () => T): ReadableSignal<T>;
|