@yaks/react 0.0.0-stage → 0.2.36

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @yaks/react
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
+ Render entities and kit-built views with React. The entity factory binds a view
4
+ registry and vocabulary to an entity store. Mounted entities subscribe to their
5
+ own row. A registry can contain portable renderers from @yaks/render and React
6
+ components.
7
+
8
+ The host export loads a views module into a page. Draft edits replace its
9
+ registry in place and keep the page's client, scroll and focus.
10
+
11
+ The draw export mounts a view into an element and returns its cleanup. The same
12
+ operation fills a browser element or an in-memory tree for a terminal or native
13
+ painter.
@@ -0,0 +1,11 @@
1
+ /** React drawing into a browser document or a tree a host paints. @module */ import type { ReactNode } from "@types/react";
2
+ type Surface = {
3
+ draw: (node: ReactNode) => void;
4
+ close: () => void;
5
+ };
6
+ /** Mount a React root whose draws commit before returning, so its caller can
7
+ * measure the tree or restore selection and scroll after a draft swap. */ export declare let surface: (into: Element, fell?: (error: unknown) => void, initial?: ReactNode) => Surface;
8
+ /** Draw a page island into its retained root. Null takes the island down. */ export declare let render: (view: ReactNode, into: Element) => void;
9
+ /** Attach a page island to existing HTML, retaining its root for updates. */ export declare let hydrate: (view: ReactNode, into: Element) => void;
10
+ /** Draw a view into a tree and return what takes it down. */ export declare let draw: (node: ReactNode, into: Element) => () => void;
11
+ //# sourceMappingURL=draw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draw.d.ts","sources":["../draw.ts"],"names":[],"mappings":"AAAA,2EAA2E,GAEjC,cAAc,SAAS,uBAA0B;KAItF;EAAY,OAAO,MAAM,cAAc,IAAI;EAAE,aAAa,IAAI;;AAiNnE;wEACwE,GACxE,OAAO,YAAI,UACT,MAAM,SACN,QAAQ,OAAO,OAAO,KAAK,IAAI,EAC/B,UAAU,cACT,QAoDF;AAID,2EAA2E,GAC3E,OAAO,YAAI,SAAU,MAAM,WAAW,MAAM,YAAU,IAAI,CASzD;AAED,2EAA2E,GAC3E,OAAO,YAAI,UAAW,MAAM,WAAW,MAAM,YAAU,IAAI,CAG1D;AAED,2DAA2D,GAC3D,OAAO,YAAI,OAAQ,MAAM,WAAW,MAAM,kBAAgB,IAAI,CAS7D"}
@@ -0,0 +1,9 @@
1
+ /** Draw a page from a React views module and follow its draft. @module */ import { type FunctionComponent, type ReactNode } from "@types/react";
2
+ import { type Host as PageHost, type Page as PageOf, type Views as ViewsOf } from "@yaks/render/host";
3
+ import { type EntityProps, type HostRegistry } from "./mod.js";
4
+ export { addressed, type Draft, taken } from "@yaks/render/host";
5
+ export type Views = ViewsOf<HostRegistry>;
6
+ export type Host = PageHost<HostRegistry>;
7
+ export type Page = PageOf<HostRegistry, (Entity: FunctionComponent<EntityProps>) => ReactNode>;
8
+ /** Bind the views module to the page's store and redraw when it changes. */ export declare let host: (page: Page) => Promise<Host>;
9
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sources":["../host.ts"],"names":[],"mappings":"AAAA,wEAAwE,GAC9B,SAExC,KAAK,iBAAiB,EACtB,KAAK,SAAS,uBACS;AAEzB,SACE,KAAK,QAAQ,QAAQ,EAErB,KAAK,QAAQ,MAAM,EACnB,KAAK,SAAS,OAAO,iCACc;AACrC,SAEE,KAAK,WAAW,EAChB,KAAK,YAAY,mBAGF;AAEjB,SAAS,SAAS,EAAE,KAAK,KAAK,EAAE,KAAK,iCAAsC;AAC3E,YAAY,QAAQ,QAAQ;AAC5B,YAAY,OAAO,SAAS;AAC5B,YAAY,OAAO,OACjB,eACC,QAAQ,kBAAkB,iBAAiB;AAG9C,0EAA0E,GAC1E,OAAO,YAAI,OAAQ,MAAM,SAAO,QAAQ,MAepC"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /** React bindings for portable and component renderers. @module */ import { type Context as Provided, type FunctionComponent, type ReactElement } from "@types/react";
2
+ import { type Bundle, type Context, type Registration, type Renderer, type Selection } from "@yaks/render";
3
+ import { type EntityProps, type Events, type Store, type Subscribe } from "@yaks/render/component";
4
+ export type { EntityProps, Events, Store, Subscribe } from "@yaks/render/component";
5
+ import type { Vocab } from "@yaks/vocab";
6
+ /** A native component; the host mounts it so React owns its hooks and identity. */ export type ComponentRenderer<E = Bundle> = Registration & {
7
+ Render: FunctionComponent<Context & Events & {
8
+ e: E;
9
+ }>;
10
+ };
11
+ /** Portable trees and native components share the same selection machinery. */ export type HostRegistry<E = Bundle> = Selection<Renderer | ComponentRenderer<E>>;
12
+ type Node<E = Bundle> = ReactElement<Record<string, unknown>> | ReactElement<Context & Events & {
13
+ e: E;
14
+ }>;
15
+ /** The values bound once when an application creates its Entity component. */ export type Options = {
16
+ registry: HostRegistry;
17
+ vocab: Vocab;
18
+ store: Store;
19
+ subscribe?: Subscribe;
20
+ };
21
+ /**
22
+ * Resolve a view and build a React node. Native components are passed to h,
23
+ * never invoked directly. Native props default to {e: bundle, ...ctx}; callers
24
+ * with another entity shape supply their typed props as the sixth argument.
25
+ */ export declare function render(registry: Selection<Renderer>, bundle: Bundle, view: string | undefined, vocab: Vocab, ctx?: Context & Events): ReactElement<Record<string, unknown>> | null;
26
+ export declare function render(registry: HostRegistry, bundle: Bundle, view: string | undefined, vocab: Vocab, ctx?: Context & Events): Node | null;
27
+ export declare function render<E>(registry: HostRegistry<E>, bundle: Bundle, view: string | undefined, vocab: Vocab, ctx: Context & Events, props: Context & {
28
+ e: E;
29
+ }): Node<E> | null;
30
+ /** Build the node for a renderer the host has already selected. */ export declare let renderSelected: <E>(registry: HostRegistry<E>, renderer: Renderer | ComponentRenderer<E>, bundle: Bundle, vocab: Vocab, ctx: Context & Events, props?: Context & {
31
+ e: E;
32
+ }) => Node<E> | null;
33
+ /** The vocabulary the host has most recently merged into its page graph. */ export declare let Vocabulary: Provided<Vocab | undefined>;
34
+ /** The registry selected by the page host for mounted entities. */ export declare let Registry: Provided<HostRegistry | undefined>;
35
+ /**
36
+ * Bind the application once: `let Entity = entity({registry, vocab, store,
37
+ * subscribe})`, then mount `<Entity eid='a' view='Tile'/>` through React.
38
+ * A notification re-reads the store even if it mutated a bundle in place.
39
+ */ export declare let entity: ({}: Options) => FunctionComponent<EntityProps>;
40
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA,iEAAiE,GAEvB,SACxC,KAAK,WAAW,QAAQ,EAGxB,KAAK,iBAAiB,EACtB,KAAK,YAAY,uBAIM;AACzB,SACE,KAAK,MAAM,EAEX,KAAK,OAAO,EAEZ,KAAK,YAAY,EAEjB,KAAK,QAAQ,EAGb,KAAK,SAAS,4BAEgB;AAChC,SAEE,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,SAAS,sCAC0B;AAC1C,cACE,WAAW,EACX,MAAM,EACN,KAAK,EACL,SAAS,sCAC+B;AAC1C,cAAc,KAAK,2BAAgC;AAEnD,iFAAiF,GACjF,YAAY,kBAAkB,IAAI,UAAU;EAC1C,QAAQ,kBAAkB,UAAU;IAAW,GAAG;;;AAGpD,6EAA6E,GAC7E,YAAY,aAAa,IAAI,UAAU,UACrC,WAAW,kBAAkB;KAE1B,KAAK,IAAI,UACV,aAAa,OAAO,MAAM,EAAE,OAAO,KACnC,aAAa,UAAU;EAAW,GAAG;;AAEzC,4EAA4E,GAC5E,YAAY;EACV,UAAU;EACV,OAAO;EACP,OAAO;EACP,YAAY;;AAgCd;;;;CAIC,GACD,OAAO,iBAAS,OACd,UAAU,UAAU,SAAS,EAC7B,QAAQ,MAAM,EACd,MAAM,MAAM,GAAG,SAAS,EACxB,OAAO,KAAK,EACZ,MAAM,UAAU,MAAM,GACrB,aAAa,OAAO,MAAM,EAAE,OAAO,KAAK,IAAI;AAC/C,OAAO,iBAAS,OACd,UAAU,YAAY,EACtB,QAAQ,MAAM,EACd,MAAM,MAAM,GAAG,SAAS,EACxB,OAAO,KAAK,EACZ,MAAM,UAAU,MAAM,GACrB,OAAO,IAAI;AACd,OAAO,iBAAS,OAAO,GACrB,UAAU,aAAa,EAAE,EACzB,QAAQ,MAAM,EACd,MAAM,MAAM,GAAG,SAAS,EACxB,OAAO,KAAK,EACZ,KAAK,UAAU,MAAM,EACrB,OAAO;EAAY,GAAG;CAAG,GACxB,KAAK,KAAK,IAAI;AAcjB,iEAAiE,GACjE,OAAO,YAAI,iBAAkB,GAC3B,UAAU,aAAa,IACvB,UAAU,WAAW,kBAAkB,IACvC,QAAQ,QACR,OAAO,OACP,KAAK,UAAU,QACf,QAAQ;EAAY,GAAG;MACtB,KAAK,KAAK,IAAI,CA0EhB;AAED,0EAA0E,GAC1E,OAAO,YAAI,YAAY,SAAS,QAAQ,SAAS,EAErC;AAEZ,iEAAiE,GACjE,OAAO,YAAI,UAAU,SAAS,eAAe,SAAS,EAE1C;AAEZ;;;;CAIC,GACD,OAAO,YAAI,SACT,IAAuC,OAAO,KAC7C,kBAAkB,aAuBpB"}
@@ -0,0 +1,8 @@
1
+ import { act as compatible } from "@yaks/preact/test-utils";
2
+ /** Run one synchronous fixture action and draw before the next assertion. */ export declare let actNow: <T>(run: () => T) => T;
3
+ /** Run an action and let its scheduled renders finish. */ export declare let act: typeof compatible;
4
+ /** Read mutable fixture state through React's subscription interface. */ export declare let useValue: <T>(source: {
5
+ value: T;
6
+ subscribe: (changed: () => void) => () => void;
7
+ }) => T;
8
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sources":["../testing.ts"],"names":[],"mappings":"AAIA,SAAS,OAAO,UAAU,uCAA4C;AAItE,2EAA2E,GAC3E,OAAO,YAAI,SAAU,GAAG,WAAW,MAAI,EAKtC;AAED,wDAAwD,GACxD,OAAO,YAAI,YAAY,WAqBtB;AAED,uEAAuE,GACvE,OAAO,YAAI,WAAY,GAAG;EACxB,OAAO;EACP,YAAY,eAAe,IAAI,WAAW,IAAI;MAC5C,EAID"}
package/deno-client.js ADDED
@@ -0,0 +1,35 @@
1
+ /** React DOM's client when Deno paints a document in memory. @module */ import { doc } from "@yaks/dom";
2
+ // React DOM probes for input events when the module loads. The terminal
3
+ // delivers those events and does not implement Internet Explorer's events.
4
+ let load = async ()=>{
5
+ let document = {
6
+ ...doc,
7
+ oninput: null
8
+ };
9
+ let window = Object.assign(new EventTarget(), {
10
+ document
11
+ });
12
+ let undo = Object.entries({
13
+ document,
14
+ window
15
+ }).map(([name, value])=>{
16
+ let before = Object.getOwnPropertyDescriptor(globalThis, name);
17
+ Object.defineProperty(globalThis, name, {
18
+ value,
19
+ configurable: true
20
+ });
21
+ return ()=>{
22
+ if (before) Object.defineProperty(globalThis, name, before);
23
+ else Reflect.deleteProperty(globalThis, name);
24
+ };
25
+ });
26
+ try {
27
+ return await import("react-dom/client");
28
+ } finally{
29
+ for (let restore of undo)restore();
30
+ }
31
+ };
32
+ let client = await load();
33
+ /** Start a root in the supplied document. */ export let createRoot = client.createRoot;
34
+ /** Attach a root to existing HTML. */ export let hydrateRoot = client.hydrateRoot;
35
+ //# sourceMappingURL=deno-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno-client.js","sources":["./deno-client.ts"],"names":[],"mappings":"AAAA,sEAAsE,GAEtE,SAAS,GAAG,yBAA8B;AAG1C,wEAAwE;AACxE,2EAA2E;AAC3E,IAAI,OAAO;EACT,IAAI,WAAW;IAAE,GAAG,GAAG;IAAE,SAAS;EAAK;EACvC,IAAI,SAAS,OAAO,MAAM,CAAC,IAAI,eAAe;IAAE;EAAS;EACzD,IAAI,OAAO,OAAO,OAAO,CAAC;IAAE;IAAU;EAAO,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,MAAM;IAChE,IAAI,SAAS,OAAO,wBAAwB,CAAC,YAAY;IACzD,OAAO,cAAc,CAAC,YAAY,MAAM;MAAE;MAAO,cAAc;IAAK;IACpE,OAAO;MACL,IAAI,QAAQ,OAAO,cAAc,CAAC,YAAY,MAAM;WAC/C,QAAQ,cAAc,CAAC,YAAY;IAC1C;EACF;EACA,IAAI;IACF,OAAO,MAAM,MAAM,CAAC;EACtB,SAAU;IACR,KAAK,IAAI,WAAW,KAAM;EAC5B;AACF;AAEA,IAAI,SAAS,MAAM;AAEnB,2CAA2C,GAC3C,OAAO,IAAI,aAAuC,OAAO,UAAU,CAAA;AAEnE,oCAAoC,GACpC,OAAO,IAAI,cAAyC,OAAO,WAAW,CAAA"}
package/deno-client.ts ADDED
@@ -0,0 +1,32 @@
1
+ /** React DOM's client when Deno paints a document in memory. @module */
2
+
3
+ import { doc } from '@yaks/dom'
4
+ import type * as Client from 'react-dom/client'
5
+
6
+ // React DOM probes for input events when the module loads. The terminal
7
+ // delivers those events and does not implement Internet Explorer's events.
8
+ let load = async (): Promise<typeof Client> => {
9
+ let document = { ...doc, oninput: null }
10
+ let window = Object.assign(new EventTarget(), { document })
11
+ let undo = Object.entries({ document, window }).map(([name, value]) => {
12
+ let before = Object.getOwnPropertyDescriptor(globalThis, name)
13
+ Object.defineProperty(globalThis, name, { value, configurable: true })
14
+ return () => {
15
+ if (before) Object.defineProperty(globalThis, name, before)
16
+ else Reflect.deleteProperty(globalThis, name)
17
+ }
18
+ })
19
+ try {
20
+ return await import('react-dom/client')
21
+ } finally {
22
+ for (let restore of undo) restore()
23
+ }
24
+ }
25
+
26
+ let client = await load()
27
+
28
+ /** Start a root in the supplied document. */
29
+ export let createRoot: typeof Client.createRoot = client.createRoot
30
+
31
+ /** Attach a root to existing HTML. */
32
+ export let hydrateRoot: typeof Client.hydrateRoot = client.hydrateRoot
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/react","version":"0.2.36","license":"Apache-2.0","description":"Renders registry-selected views with React and binds them to an entity store.","exports":{".":"./mod.ts","./host":"./host.ts","./draw":"./draw.ts","./testing":"./testing.ts"},"imports":{"@yaks/react":"./mod.ts","@yaks/react/host":"./host.ts","@yaks/react/draw":"./draw.ts","@yaks/react/testing":"./testing.ts"}}
package/draw.js ADDED
@@ -0,0 +1,260 @@
1
+ /** React drawing into a browser document or a tree a host paints. @module */ /* @ts-types="npm:@types/react@19.3.0" */ /* @ts-types="npm:@types/react-dom@19.3.0" */ import { flushSync, version } from "react-dom";
2
+ import { createRoot, hydrateRoot } from "./deno-client.js";
3
+ let modern = parseInt(version) >= 19;
4
+ let commit = modern ? flushSync : (draw)=>draw();
5
+ // React DOM consults window and the iframe constructor for focus restoration.
6
+ // The in-memory document has neither a window of its own nor frame elements.
7
+ let surfaces = 0;
8
+ let restore;
9
+ let documents = new WeakMap();
10
+ // A painted tree dispatches capture listeners under a separate event name.
11
+ let listening = new WeakSet();
12
+ let eventName = (type, options)=>(typeof options == 'boolean' ? options : options?.capture) ? type + 'Capture' : type;
13
+ let listen = (element)=>{
14
+ if (listening.has(element)) return;
15
+ listening.add(element);
16
+ let add = element.addEventListener;
17
+ let remove = element.removeEventListener;
18
+ element.addEventListener = (type, listener, options)=>listener && add.call(element, eventName(type, options), listener, options);
19
+ element.removeEventListener = (type, listener, options)=>listener && remove.call(element, eventName(type, options), listener, options);
20
+ };
21
+ // React sets the option properties for a controlled select. A painted tree
22
+ // reads those states from its attributes.
23
+ let controls = (doc)=>{
24
+ let create = doc.createElement;
25
+ let createNS = doc.createElementNS;
26
+ let control = (element, name)=>{
27
+ listen(element);
28
+ if (!('nodeName' in element)) {
29
+ Object.defineProperty(element, 'nodeName', {
30
+ get: ()=>element.tagName
31
+ });
32
+ }
33
+ if ([
34
+ 'input',
35
+ 'textarea',
36
+ 'select'
37
+ ].includes(name)) {
38
+ let props = name == 'input' ? [
39
+ 'type',
40
+ 'name'
41
+ ] : [
42
+ 'name'
43
+ ];
44
+ for (let prop of props){
45
+ if (prop in element) continue;
46
+ Object.defineProperty(element, prop, {
47
+ get: ()=>element.getAttribute(prop) ?? '',
48
+ set: (value)=>element.setAttribute(prop, value)
49
+ });
50
+ }
51
+ }
52
+ if (name == 'input' || name == 'textarea') {
53
+ if (!('defaultValue' in element)) {
54
+ Object.defineProperty(element, 'defaultValue', {
55
+ get: ()=>element.getAttribute('value') ?? '',
56
+ set: (value)=>{
57
+ if (!element.hasAttribute('value')) {
58
+ element.setAttribute('value', value);
59
+ }
60
+ }
61
+ });
62
+ }
63
+ }
64
+ if (name == 'select' && !('options' in element)) {
65
+ let choices = ()=>Array.from(element.querySelectorAll('option'));
66
+ Object.defineProperties(element, {
67
+ options: {
68
+ get: choices
69
+ },
70
+ value: {
71
+ get: ()=>{
72
+ let listed = choices();
73
+ return (listed.find((option)=>option.selected) ?? listed[0])?.value ?? '';
74
+ },
75
+ set: (value)=>{
76
+ for (let option of choices()){
77
+ option.selected = option.value == value;
78
+ }
79
+ }
80
+ }
81
+ });
82
+ }
83
+ if (name == 'option' && !('selected' in element)) {
84
+ for (let property of [
85
+ 'selected',
86
+ 'defaultSelected'
87
+ ]){
88
+ Object.defineProperty(element, property, {
89
+ get: ()=>element.hasAttribute('selected'),
90
+ set: (on)=>{
91
+ if (!on) return element.removeAttribute('selected');
92
+ let select = element.closest('select');
93
+ if (select && !select.multiple) {
94
+ for (let option of select.querySelectorAll('option[selected]')){
95
+ option.removeAttribute('selected');
96
+ }
97
+ }
98
+ element.setAttribute('selected', '');
99
+ }
100
+ });
101
+ }
102
+ }
103
+ return element;
104
+ };
105
+ doc.createElement = (name, options)=>control(create.call(doc, name, options), name);
106
+ doc.createElementNS = (namespace, name, options)=>control(createNS.call(doc, namespace, name, options), name);
107
+ return ()=>{
108
+ doc.createElement = create;
109
+ doc.createElementNS = createNS;
110
+ };
111
+ };
112
+ let attach = (doc)=>{
113
+ if (!modern) return ()=>{};
114
+ let current = globalThis.window;
115
+ if (typeof doc.defaultView?.HTMLIFrameElement == 'function' && typeof current?.HTMLIFrameElement == 'function' && !restore) {
116
+ return ()=>{};
117
+ }
118
+ let held = doc.defaultView ? undefined : documents.get(doc);
119
+ if (!doc.defaultView) {
120
+ if (!held) documents.set(doc, held = {
121
+ refs: 0,
122
+ close: controls(doc)
123
+ });
124
+ held.refs++;
125
+ }
126
+ let release = ()=>{
127
+ if (held && --held.refs == 0) {
128
+ held.close();
129
+ documents.delete(doc);
130
+ }
131
+ };
132
+ let view = doc.defaultView;
133
+ let frameClass = view && typeof view.HTMLIFrameElement != 'function' ? Object.getOwnPropertyDescriptor(view, 'HTMLIFrameElement') : undefined;
134
+ let absent = view && typeof view.HTMLIFrameElement != 'function';
135
+ if (absent) {
136
+ Object.defineProperty(view, 'HTMLIFrameElement', {
137
+ value: class {
138
+ },
139
+ configurable: true
140
+ });
141
+ }
142
+ surfaces++;
143
+ if (!restore) {
144
+ let frame = current ?? doc.defaultView ?? globalThis;
145
+ let undo = [];
146
+ let supply = (target, name, value)=>{
147
+ if (Reflect.get(target, name) != null) return;
148
+ let prior = Object.getOwnPropertyDescriptor(target, name);
149
+ Object.defineProperty(target, name, {
150
+ value,
151
+ configurable: true,
152
+ writable: true
153
+ });
154
+ undo.push(()=>{
155
+ if (prior) Object.defineProperty(target, name, prior);
156
+ else Reflect.deleteProperty(target, name);
157
+ });
158
+ };
159
+ supply(globalThis, 'window', frame);
160
+ supply(frame, 'HTMLIFrameElement', class {
161
+ });
162
+ restore = ()=>{
163
+ for (let reset of undo.reverse())reset();
164
+ };
165
+ }
166
+ return ()=>{
167
+ release();
168
+ if (view && absent) {
169
+ if (frameClass) {
170
+ Object.defineProperty(view, 'HTMLIFrameElement', frameClass);
171
+ } else Reflect.deleteProperty(view, 'HTMLIFrameElement');
172
+ }
173
+ if (--surfaces == 0) {
174
+ let release = restore;
175
+ let after = globalThis.setImmediate ?? setTimeout;
176
+ after(()=>{
177
+ if (surfaces || restore !== release) return;
178
+ restore = undefined;
179
+ release?.();
180
+ });
181
+ }
182
+ };
183
+ };
184
+ /** Mount a React root whose draws commit before returning, so its caller can
185
+ * measure the tree or restore selection and scroll after a draft swap. */ export let surface = (into, fell, initial)=>{
186
+ let release = attach(into.ownerDocument);
187
+ if (modern && !into.ownerDocument.defaultView) listen(into);
188
+ let root;
189
+ let committing = false;
190
+ let failure;
191
+ let open = createRoot;
192
+ let resume = hydrateRoot;
193
+ let options = {
194
+ onUncaughtError (error) {
195
+ if (committing) failure = {
196
+ error
197
+ };
198
+ else if (fell) fell(error);
199
+ else {
200
+ queueMicrotask(()=>{
201
+ throw error;
202
+ });
203
+ }
204
+ }
205
+ };
206
+ try {
207
+ root = initial === undefined ? open(into, options) : commit(()=>resume(into, initial, options));
208
+ } catch (error) {
209
+ release();
210
+ throw error;
211
+ }
212
+ let closed = false;
213
+ return {
214
+ draw: (node)=>{
215
+ failure = undefined;
216
+ committing = true;
217
+ try {
218
+ commit(()=>root.render(node));
219
+ } finally{
220
+ committing = false;
221
+ }
222
+ if (failure) throw failure.error;
223
+ },
224
+ close: ()=>{
225
+ if (closed) return;
226
+ closed = true;
227
+ try {
228
+ root.unmount();
229
+ } finally{
230
+ release();
231
+ }
232
+ }
233
+ };
234
+ };
235
+ let roots = new WeakMap();
236
+ /** Draw a page island into its retained root. Null takes the island down. */ export let render = (view, into)=>{
237
+ let held = roots.get(into);
238
+ if (view === null) {
239
+ held?.close();
240
+ roots.delete(into);
241
+ return;
242
+ }
243
+ if (!held) roots.set(into, held = surface(into));
244
+ held.draw(view);
245
+ };
246
+ /** Attach a page island to existing HTML, retaining its root for updates. */ export let hydrate = (view, into)=>{
247
+ if (roots.has(into)) return render(view, into);
248
+ roots.set(into, surface(into, undefined, view));
249
+ };
250
+ /** Draw a view into a tree and return what takes it down. */ export let draw = (node, into)=>{
251
+ let mount = surface(into);
252
+ try {
253
+ mount.draw(node);
254
+ } catch (error) {
255
+ mount.close();
256
+ throw error;
257
+ }
258
+ return mount.close;
259
+ };
260
+ //# sourceMappingURL=draw.js.map
package/draw.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draw.js","sources":["./draw.ts"],"names":[],"mappings":"AAAA,2EAA2E,GAE3E,uCAAuC,GACvC,2CAA2C,GAAG,SAAS,SAAS,EAAE,OAAO,oBAA8B;AACvG,SAAS,UAAU,EAAE,WAAW,2BAA0B;AAG1D,IAAI,SAAS,SAAS,YAAY;AAClC,IAAI,SAAS,SAAS,YAAY,CAAI,OAAkB;AAExD,8EAA8E;AAC9E,6EAA6E;AAC7E,IAAI,WAAW;AACf,IAAI;AACJ,IAAI,YAAY,IAAI;AAEpB,2EAA2E;AAC3E,IAAI,YAAY,IAAI;AACpB,IAAI,YAAY,CAAC,MAAc,UAC7B,CAAC,OAAO,WAAW,YAAY,UAAU,SAAS,OAAO,IACrD,OAAO,YACP;AACN,IAAI,SAAS,CAAC;EACZ,IAAI,UAAU,GAAG,CAAC,UAAU;EAC5B,UAAU,GAAG,CAAC;EACd,IAAI,MAAM,QAAQ,gBAAgB;EAClC,IAAI,SAAS,QAAQ,mBAAmB;EACxC,QAAQ,gBAAgB,GAAI,CAC1B,MACA,UACA,UAEA,YAAY,IAAI,IAAI,CAClB,SACA,UAAU,MAAM,UAChB,UACA;EAEJ,QAAQ,mBAAmB,GAAI,CAC7B,MACA,UACA,UAEA,YAAY,OAAO,IAAI,CACrB,SACA,UAAU,MAAM,UAChB,UACA;AAEN;AAEA,2EAA2E;AAC3E,0CAA0C;AAC1C,IAAI,WAAW,CAAC;EACd,IAAI,SAAS,IAAI,aAAa;EAC9B,IAAI,WAAW,IAAI,eAAe;EAClC,IAAI,UAAU,CAAC,SAAkB;IAC/B,OAAO;IACP,IAAI,CAAC,CAAC,cAAc,OAAO,GAAG;MAC5B,OAAO,cAAc,CAAC,SAAS,YAAY;QACzC,KAAK,IAAM,AAAC,QAAoB,OAAO;MACzC;IACF;IACA,IAAI;MAAC;MAAS;MAAY;KAAS,CAAC,Q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