@opentf/afw 0.0.0-stage → 0.33.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -2
  3. package/components/Link.d.ts +12 -0
  4. package/components/Link.jsx +54 -0
  5. package/core/context.d.ts +7 -0
  6. package/core/context.js +60 -0
  7. package/core/dev.js +27 -0
  8. package/core/errors.d.ts +14 -0
  9. package/core/errors.js +48 -0
  10. package/core/html.js +10 -0
  11. package/core/metadata.js +186 -0
  12. package/core/reactive.d.ts +5 -0
  13. package/core/reactive.js +190 -0
  14. package/core/render-context.js +11 -0
  15. package/core/signals.d.ts +8 -0
  16. package/core/signals.js +264 -0
  17. package/index.d.ts +5 -0
  18. package/index.js +13 -0
  19. package/jsx-runtime.d.ts +37 -0
  20. package/package.json +66 -4
  21. package/runtime/clipboard.d.ts +7 -0
  22. package/runtime/clipboard.js +47 -0
  23. package/runtime/code-block.d.ts +14 -0
  24. package/runtime/code-block.js +76 -0
  25. package/runtime/context.browser.js +163 -0
  26. package/runtime/context.d.ts +13 -0
  27. package/runtime/context.js +44 -0
  28. package/runtime/dom.browser.js +423 -0
  29. package/runtime/dom.d.ts +142 -0
  30. package/runtime/dom.js +670 -0
  31. package/runtime/error-boundary.browser.js +140 -0
  32. package/runtime/error-boundary.d.ts +19 -0
  33. package/runtime/error-boundary.js +123 -0
  34. package/runtime/events.browser.js +29 -0
  35. package/runtime/events.d.ts +1 -0
  36. package/runtime/events.js +17 -0
  37. package/runtime/head.js +29 -0
  38. package/runtime/hmr.js +199 -0
  39. package/runtime/hydrate.browser.js +144 -0
  40. package/runtime/hydrate.d.ts +179 -0
  41. package/runtime/hydrate.js +584 -0
  42. package/runtime/index.d.ts +14 -0
  43. package/runtime/index.js +24 -0
  44. package/runtime/lifecycle.d.ts +6 -0
  45. package/runtime/lifecycle.js +14 -0
  46. package/runtime/mount.d.ts +20 -0
  47. package/runtime/mount.js +88 -0
  48. package/runtime/portal.browser.js +85 -0
  49. package/runtime/portal.d.ts +12 -0
  50. package/runtime/portal.js +74 -0
  51. package/runtime/raw-html.d.ts +11 -0
  52. package/runtime/raw-html.js +55 -0
  53. package/runtime/resource.d.ts +9 -0
  54. package/runtime/resource.js +139 -0
  55. package/runtime/route-data.d.ts +15 -0
  56. package/runtime/route-data.js +64 -0
  57. package/runtime/router.d.ts +149 -0
  58. package/runtime/router.js +807 -0
  59. package/server/adapters/node.d.ts +28 -0
  60. package/server/adapters/node.js +74 -0
  61. package/server/api.d.ts +175 -0
  62. package/server/api.js +233 -0
  63. package/server/builtins.js +42 -0
  64. package/server/cookies.d.ts +44 -0
  65. package/server/cookies.js +122 -0
  66. package/server/head.js +9 -0
  67. package/server/index.d.ts +155 -0
  68. package/server/index.js +31 -0
  69. package/server/loader.js +201 -0
  70. package/server/middleware.js +119 -0
  71. package/server/render-context.js +30 -0
  72. package/server/render.js +175 -0
  73. package/server/ssg-runtime.js +297 -0
@@ -0,0 +1,190 @@
1
+ //! Deep reactive store — a fine-grained, signal-backed reactive object.
2
+ //
3
+ // `reactive(obj)` returns a deep proxy over plain data. Reading a property
4
+ // inside an effect/computed subscribes to *just that path*; writing a property
5
+ // notifies *only* the effects that read it. Object/array nodes are wrapped
6
+ // lazily on access, so a 100-field store costs nothing until a field is touched.
7
+ //
8
+ // This is the public primitive SPEC §1.1 requires to live in `@opentf/afw`:
9
+ // apps `import { reactive }` and read values directly (no provider object), and
10
+ // `@opentf/afw-form` builds its values/errors trees on top of it instead of a
11
+ // private proxy. It is forward-compatible with the `$signal()` compiler bridge
12
+ // (SPEC §3.5): each node is itself reactive, so a future First-Access unwrap can
13
+ // read `store.user.value` without changing this runtime.
14
+ //
15
+ // Model (mirrors the signals core, one level up):
16
+ // - per *key* signal → fine-grained leaf subscription (read `a.b.c`)
17
+ // - per *node* "struct" signal → bumped on key add/remove so `in`, `ownKeys`,
18
+ // iteration and array `length` stay reactive.
19
+ // State is mutated in place (the store owns it); reads always go through the
20
+ // proxy, so callers never observe the raw object directly. No per-write tree
21
+ // clone, no broadcast — the two costs the old form proxy paid on every keystroke.
22
+
23
+ import { signal, untracked, batch } from "./signals.js";
24
+
25
+ /** Unwrap a reactive proxy back to its underlying plain object. */
26
+ const RAW = Symbol.for("afw.reactive.raw");
27
+ /** Brand a proxy so `isReactive` is a cheap, collision-free check. */
28
+ const IS_REACTIVE = Symbol.for("afw.reactive.is");
29
+
30
+ // Per raw-object bookkeeping, kept off the data itself so the data stays clean.
31
+ const proxyCache = new WeakMap(); // raw object → its proxy (stable identity)
32
+ const keySignals = new WeakMap(); // raw object → Map<key, signal(value)>
33
+ const structSignals = new WeakMap(); // raw object → signal(int) bumped on shape change
34
+
35
+ // Array methods that mutate in place; routed through a `batch` so the many
36
+ // internal index/length writes collapse into a single notification.
37
+ const ARRAY_MUTATORS = new Set([
38
+ "push", "pop", "shift", "unshift", "splice", "reverse", "sort", "fill", "copyWithin",
39
+ ]);
40
+
41
+ /** Only plain objects and arrays are wrapped; class instances, Dates, etc. pass through. */
42
+ function isWrappable(v) {
43
+ if (v === null || typeof v !== "object") return false;
44
+ if (Array.isArray(v)) return true;
45
+ const proto = Object.getPrototypeOf(v);
46
+ return proto === Object.prototype || proto === null;
47
+ }
48
+
49
+ function getKeySig(target, key) {
50
+ let map = keySignals.get(target);
51
+ if (!map) keySignals.set(target, (map = new Map()));
52
+ let sig = map.get(key);
53
+ if (!sig) map.set(key, (sig = signal(target[key])));
54
+ return sig;
55
+ }
56
+
57
+ function getStructSig(target) {
58
+ let sig = structSignals.get(target);
59
+ if (!sig) structSignals.set(target, (sig = signal(0)));
60
+ return sig;
61
+ }
62
+
63
+ /** Strip a reactive wrapper from a value before it is stored. */
64
+ function toRaw(v) {
65
+ return v && typeof v === "object" && v[RAW] !== undefined ? v[RAW] : v;
66
+ }
67
+
68
+ const handler = {
69
+ get(target, key, receiver) {
70
+ if (key === RAW) return target;
71
+ if (key === IS_REACTIVE) return true;
72
+
73
+ if (typeof key === "symbol") {
74
+ // Spreading/iterating walks length+indices through the proxy, but the
75
+ // iterator lookup itself should subscribe to shape so a re-spread re-runs.
76
+ if (key === Symbol.iterator) getStructSig(target).value;
77
+ return Reflect.get(target, key, receiver);
78
+ }
79
+
80
+ // `length` is structural for arrays — push/splice change it.
81
+ if (key === "length" && Array.isArray(target)) {
82
+ getStructSig(target).value;
83
+ return target.length;
84
+ }
85
+
86
+ const value = target[key];
87
+
88
+ if (typeof value === "function") {
89
+ if (Array.isArray(target)) {
90
+ // Mutators re-enter the `set` trap via `receiver`; batch their internal
91
+ // writes so an effect re-runs once.
92
+ if (ARRAY_MUTATORS.has(key)) {
93
+ return (...args) => batch(() => value.apply(receiver, args));
94
+ }
95
+ // Read methods (map/filter/forEach/…) subscribe to *structure* only and
96
+ // run over the raw array, so they re-run when the list grows/shrinks but
97
+ // not when an individual element's value changes. This is what keeps a
98
+ // `list.map(i => <input/>)` from re-rendering (and dropping focus) on
99
+ // every keystroke — the element's own binding handles its value.
100
+ getStructSig(target).value;
101
+ return value.bind(target);
102
+ }
103
+ return value.bind(receiver);
104
+ }
105
+
106
+ getKeySig(target, key).value; // subscribe to this leaf/branch
107
+ return isWrappable(value) ? wrap(value) : value;
108
+ },
109
+
110
+ set(target, key, value) {
111
+ const raw = toRaw(value);
112
+
113
+ if (key === "length" && Array.isArray(target)) {
114
+ if (target.length !== raw) {
115
+ target.length = raw;
116
+ getStructSig(target).value++;
117
+ }
118
+ return true;
119
+ }
120
+
121
+ const had = Object.prototype.hasOwnProperty.call(target, key);
122
+ if (had && Object.is(target[key], raw)) return true;
123
+
124
+ target[key] = raw;
125
+ const map = keySignals.get(target);
126
+ const sig = map && map.get(key);
127
+ if (sig) sig.value = raw; // notify only if someone is listening
128
+ if (!had) getStructSig(target).value++; // new key → shape changed
129
+ return true;
130
+ },
131
+
132
+ deleteProperty(target, key) {
133
+ if (!Object.prototype.hasOwnProperty.call(target, key)) return true;
134
+ delete target[key];
135
+ const map = keySignals.get(target);
136
+ const sig = map && map.get(key);
137
+ if (sig) sig.value = undefined;
138
+ getStructSig(target).value++;
139
+ return true;
140
+ },
141
+
142
+ has(target, key) {
143
+ getStructSig(target).value;
144
+ return Reflect.has(target, key);
145
+ },
146
+
147
+ ownKeys(target) {
148
+ getStructSig(target).value;
149
+ return Reflect.ownKeys(target);
150
+ },
151
+ };
152
+
153
+ function wrap(target) {
154
+ const cached = proxyCache.get(target);
155
+ if (cached) return cached;
156
+ const proxy = new Proxy(target, handler);
157
+ proxyCache.set(target, proxy);
158
+ return proxy;
159
+ }
160
+
161
+ /**
162
+ * Create a deep reactive store over a plain object/array. Property reads inside
163
+ * an effect subscribe fine-grained; writes (`s.a.b = x`, `s.items.push(y)`)
164
+ * notify only dependents of the touched paths.
165
+ */
166
+ export function reactive(init = {}) {
167
+ if (!isWrappable(init)) {
168
+ throw new TypeError("reactive() expects a plain object or array");
169
+ }
170
+ return wrap(init);
171
+ }
172
+
173
+ /** Whether `v` is a store created by `reactive()`. */
174
+ export function isReactive(v) {
175
+ return !!(v && typeof v === "object" && v[IS_REACTIVE]);
176
+ }
177
+
178
+ /** The underlying plain object of a store (live, not a copy); identity for non-stores. */
179
+ export function toRawValue(v) {
180
+ return isReactive(v) ? v[RAW] : v;
181
+ }
182
+
183
+ /**
184
+ * A plain, non-reactive deep copy of a store's current value — for submit
185
+ * payloads, validation input, or persistence. Reads are untracked, so taking a
186
+ * snapshot never subscribes the caller.
187
+ */
188
+ export function snapshot(v) {
189
+ return untracked(() => structuredClone(toRawValue(v)));
190
+ }
@@ -0,0 +1,11 @@
1
+ // Browser-safe bridge to the server's async render context. Importing the client
2
+ // router must never load a server runtime module.
3
+ let readContext = () => undefined;
4
+
5
+ export function getRenderContext() {
6
+ return readContext();
7
+ }
8
+
9
+ export function setRenderContextReader(reader) {
10
+ readContext = reader;
11
+ }
@@ -0,0 +1,8 @@
1
+ /** Writable reactive value. */
2
+ export interface Signal<T> { value: T; peek(): T }
3
+ export function signal<T>(initial: T): Signal<T>;
4
+ export function computed<T>(fn: () => T): { readonly value: T; dispose(): void };
5
+ export function effect(fn: () => void | (() => void)): () => void;
6
+ export function untracked<T>(fn: () => T): T;
7
+ export function batch<T>(fn: () => T): T;
8
+ export function scope<T>(fn: () => T): { result: T; dispose(): void };
@@ -0,0 +1,264 @@
1
+ //! Fine-grained reactivity — our own signals core.
2
+ //
3
+ // This replaces the previous `@preact/signals-core` dependency to remove a
4
+ // third-party supply-chain risk (SPEC §1.1). The public surface is the
5
+ // industry-standard `signal` / `computed` / `effect` with a `.value` accessor;
6
+ // more APIs (peek/untracked/subscribe) are added only when a consumer needs them.
7
+ //
8
+ // Model: producers (signals, computeds) hold a set of subscribers; consumers
9
+ // (effects, computeds) track the producers they read. Reads register a
10
+ // dependency on the active consumer; writes mark dependent computeds stale and
11
+ // queue dependent effects, which run once per change/batch (glitch-free: an
12
+ // effect that depends on a signal both directly and via a computed runs once).
13
+
14
+ import { reportError } from "./errors.js";
15
+
16
+ /** The consumer (effect or computed) currently executing, if any. */
17
+ let activeConsumer = null;
18
+ /** Disposer collector of the innermost `scope()` currently building, if any. */
19
+ let activeScope = null;
20
+ /** Depth of nested `batch()` calls; effects flush when this returns to 0. */
21
+ let batchDepth = 0;
22
+ /** Re-entrancy guard for the flush loop. */
23
+ let flushing = false;
24
+ /** Effects queued to run on the next flush. A Set so each runs at most once. */
25
+ const pendingEffects = new Set();
26
+
27
+ /** Register `producer` as a dependency of the consumer currently running. */
28
+ function track(producer) {
29
+ if (activeConsumer) {
30
+ activeConsumer.sources.add(producer);
31
+ producer.subscribers.add(activeConsumer);
32
+ }
33
+ }
34
+
35
+ /** Detach a consumer from all producers it previously read. */
36
+ function clearSources(consumer) {
37
+ for (const source of consumer.sources) {
38
+ source.subscribers.delete(consumer);
39
+ }
40
+ consumer.sources.clear();
41
+ }
42
+
43
+ /** Mark dependents stale: computeds recursively, effects into the run queue. */
44
+ function propagate(producer) {
45
+ for (const sub of producer.subscribers) {
46
+ if (sub.kind === "computed") {
47
+ if (!sub.stale) {
48
+ sub.stale = true;
49
+ propagate(sub);
50
+ }
51
+ } else {
52
+ pendingEffects.add(sub);
53
+ }
54
+ }
55
+ }
56
+
57
+ /** Run all queued effects, including any they queue in turn. */
58
+ function flush() {
59
+ if (flushing) return;
60
+ flushing = true;
61
+ try {
62
+ while (pendingEffects.size > 0) {
63
+ const batch = [...pendingEffects];
64
+ pendingEffects.clear();
65
+ for (const effectNode of batch) {
66
+ if (effectNode.disposed) continue;
67
+ // A throwing reactive update is reported but must not break the scheduler
68
+ // (other queued effects still run). Build-time (initial) runs propagate so
69
+ // the surrounding component/page catch can handle them.
70
+ try {
71
+ effectNode.run();
72
+ } catch (e) {
73
+ reportError(e, { phase: "effect" });
74
+ }
75
+ }
76
+ }
77
+ } finally {
78
+ flushing = false;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * A writable reactive value. Reading `.value` inside an effect/computed
84
+ * subscribes to it; writing a changed `.value` notifies dependents.
85
+ */
86
+ export function signal(initial) {
87
+ const node = { kind: "signal", value: initial, subscribers: new Set() };
88
+ return {
89
+ get value() {
90
+ track(node);
91
+ return node.value;
92
+ },
93
+ set value(next) {
94
+ if (Object.is(next, node.value)) return;
95
+ node.value = next;
96
+ propagate(node);
97
+ if (batchDepth === 0) flush();
98
+ },
99
+ /** Read the current value without subscribing the active consumer. */
100
+ peek() {
101
+ return node.value;
102
+ },
103
+ };
104
+ }
105
+
106
+ /**
107
+ * Run `fn` without subscribing the active consumer to any signals it reads.
108
+ * Use inside an effect/computed to read reactive state without depending on it
109
+ * (e.g. validation that reads many fields but should not re-run on each).
110
+ */
111
+ export function untracked(fn) {
112
+ const prev = activeConsumer;
113
+ activeConsumer = null;
114
+ try {
115
+ return fn();
116
+ } finally {
117
+ activeConsumer = prev;
118
+ }
119
+ }
120
+
121
+ /**
122
+ * A derived, read-only reactive value. Lazy and cached: the compute function
123
+ * runs only when `.value` is read while stale, and recomputes only after a
124
+ * dependency changes.
125
+ */
126
+ export function computed(fn) {
127
+ const node = {
128
+ kind: "computed",
129
+ fn,
130
+ value: undefined,
131
+ stale: true,
132
+ disposed: false,
133
+ sources: new Set(),
134
+ subscribers: new Set(),
135
+ };
136
+ const value = {
137
+ get value() {
138
+ if (node.disposed) return node.value;
139
+ if (node.stale) {
140
+ const prev = activeConsumer;
141
+ clearSources(node);
142
+ activeConsumer = node;
143
+ try {
144
+ node.value = node.fn();
145
+ node.stale = false;
146
+ } finally {
147
+ activeConsumer = prev;
148
+ }
149
+ }
150
+ track(node);
151
+ return node.value;
152
+ },
153
+ /** Detach an owned derived value when its view is replaced or removed. */
154
+ dispose() {
155
+ if (node.disposed) return;
156
+ node.disposed = true;
157
+ clearSources(node);
158
+ node.subscribers.clear();
159
+ node.fn = null;
160
+ },
161
+ };
162
+ if (activeScope) activeScope.push(value.dispose);
163
+ return value;
164
+ }
165
+
166
+ /**
167
+ * Collect ownership of effects and derived values created while `fn` runs. Returns
168
+ * `{ result, dispose }`: `dispose()` stops every owned consumer (including
169
+ * ones created in nested calls, unless an inner `scope()` claimed them first).
170
+ *
171
+ * This is how dynamic regions own their bindings: a keyed-list item, a
172
+ * conditional branch, or a mounted page builds its DOM inside a scope, and
173
+ * evicting/swapping/unmounting disposes the scope — otherwise the bindings'
174
+ * effects would stay subscribed to their signals forever (a leak that also
175
+ * makes every later write pay for dead subscribers).
176
+ */
177
+ export function scope(fn) {
178
+ const disposers = [];
179
+ const prev = activeScope;
180
+ activeScope = disposers;
181
+ let result;
182
+ try {
183
+ result = fn();
184
+ } finally {
185
+ activeScope = prev;
186
+ }
187
+ return {
188
+ result,
189
+ dispose() {
190
+ const owned = disposers.splice(0);
191
+ let failed = false, failure;
192
+ for (const dispose of owned) {
193
+ try { dispose(); }
194
+ catch (error) { if (!failed) { failed = true; failure = error; } }
195
+ }
196
+ if (failed) throw failure;
197
+ },
198
+ };
199
+ }
200
+
201
+ /**
202
+ * Run `fn` immediately, tracking the signals it reads, and re-run it whenever
203
+ * any of them change. `fn` may return a cleanup function, which runs before the
204
+ * next re-run and on dispose. Returns a disposer that stops the effect.
205
+ */
206
+ export function effect(fn) {
207
+ const node = {
208
+ kind: "effect",
209
+ fn,
210
+ cleanup: undefined,
211
+ sources: new Set(),
212
+ disposed: false,
213
+ run() {
214
+ if (node.disposed) return;
215
+ runCleanup(node);
216
+ clearSources(node);
217
+ const prev = activeConsumer;
218
+ const prevScope = activeScope;
219
+ // Effects created during a run belong to whoever the run's body says they
220
+ // do (an explicit inner scope()), never to whatever scope happens to be
221
+ // ambient — a flush-time re-run must not donate its children to an
222
+ // unrelated scope that was open when the write occurred.
223
+ activeConsumer = node;
224
+ activeScope = null;
225
+ try {
226
+ const result = node.fn();
227
+ if (typeof result === "function") node.cleanup = result;
228
+ } finally {
229
+ activeConsumer = prev;
230
+ activeScope = prevScope;
231
+ }
232
+ },
233
+ };
234
+ node.run();
235
+ const dispose = function dispose() {
236
+ if (node.disposed) return;
237
+ node.disposed = true;
238
+ try { runCleanup(node); } finally { clearSources(node); }
239
+ };
240
+ if (activeScope) activeScope.push(dispose);
241
+ return dispose;
242
+ }
243
+
244
+ function runCleanup(node) {
245
+ if (node.cleanup) {
246
+ const fn = node.cleanup;
247
+ node.cleanup = undefined;
248
+ fn();
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Group multiple writes so dependent effects run once after the outermost batch
254
+ * completes, instead of after each write.
255
+ */
256
+ export function batch(fn) {
257
+ batchDepth++;
258
+ try {
259
+ return fn();
260
+ } finally {
261
+ batchDepth--;
262
+ if (batchDepth === 0) flush();
263
+ }
264
+ }
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./core/signals.js";
2
+ export * from "./core/reactive.js";
3
+ export * from "./core/errors.js";
4
+ export * from "./runtime/index.js";
5
+ export { default as Link } from "./components/Link.jsx";
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ // Public entry for the AFW runtime: reactivity + DOM operations.
2
+ // CSR-generated modules import their helpers (signal/computed/bindText/…) from here.
3
+ export * from "./core/signals.js";
4
+ export * from "./core/reactive.js";
5
+ export * from "./core/errors.js";
6
+ export * from "./runtime/index.js";
7
+ // `Link` is shipped as JSX source and compiled by the consuming app's pipeline
8
+ // (the `.jsx` lands in the module graph and afwc transforms it). Its compiled
9
+ // module self-registers `afw-link` (CSR `customElements.define` / SSG `defineSSG`).
10
+ // The bare import forces that registration to be retained — `<Link>` is used as a
11
+ // tag, so the `Link` binding alone would be tree-shaken.
12
+ import "./components/Link.jsx";
13
+ export { default as Link } from "./components/Link.jsx";
@@ -0,0 +1,37 @@
1
+ /** Type-only JSX entry for the AFW compiler (`jsx: "preserve"`). */
2
+ export namespace JSX {
3
+ type Element = Node;
4
+ interface ElementChildrenAttribute { children: unknown }
5
+ interface IntrinsicAttributes { key?: string | number }
6
+
7
+ type Handler<E, T extends Event> = (event: T & { currentTarget: E }) => void;
8
+ type Events<E> = {
9
+ [K in keyof GlobalEventHandlersEventMap as `on${K}`]?: Handler<E, GlobalEventHandlersEventMap[K]>;
10
+ } & {
11
+ [K in keyof GlobalEventHandlersEventMap as `on${Capitalize<K>}`]?: Handler<E, GlobalEventHandlersEventMap[K]>;
12
+ };
13
+ type Common<E> = Events<E> & {
14
+ children?: unknown;
15
+ class?: string | Record<string, unknown> | unknown[];
16
+ className?: string;
17
+ style?: string | Record<string, string | number | undefined>;
18
+ ref?: { value: E | null | undefined };
19
+ tabindex?: number;
20
+ autofocus?: boolean;
21
+ readonly?: boolean;
22
+ contenteditable?: boolean | "true" | "false" | "plaintext-only";
23
+ spellcheck?: boolean;
24
+ for?: string;
25
+ role?: string;
26
+ [attribute: `data-${string}`]: unknown;
27
+ [attribute: `aria-${string}`]: string | number | boolean | undefined;
28
+ };
29
+ type Properties<E> = {
30
+ [K in keyof E as E[K] extends Function ? never : K extends `on${string}` | keyof Common<E> ? never : K]?: E[K];
31
+ };
32
+ type HTML = { [K in keyof HTMLElementTagNameMap]: Properties<HTMLElementTagNameMap[K]> & Common<HTMLElementTagNameMap[K]> };
33
+ type SVG = { [K in Exclude<keyof SVGElementTagNameMap, keyof HTML>]: Common<SVGElementTagNameMap[K]> & { [attribute: string]: unknown } };
34
+ type IntrinsicElements = HTML & SVG & {
35
+ [tag: `${string}-${string}`]: Common<HTMLElement> & { [attribute: string]: unknown };
36
+ };
37
+ }
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@opentf/afw",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.33.0",
4
+ "description": "The AFW runtime: signals and zero-VDOM DOM bindings, with routing and server rendering.",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "cp ../../LICENSE LICENSE"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "default": "./index.js"
13
+ },
14
+ "./signals": {
15
+ "types": "./core/signals.d.ts",
16
+ "default": "./core/signals.js"
17
+ },
18
+ "./runtime": {
19
+ "types": "./runtime/index.d.ts",
20
+ "default": "./runtime/index.js"
21
+ },
22
+ "./server": {
23
+ "types": "./server/index.d.ts",
24
+ "default": "./server/index.js"
25
+ },
26
+ "./server/adapters/node": {
27
+ "types": "./server/adapters/node.d.ts",
28
+ "default": "./server/adapters/node.js"
29
+ },
30
+ "./hmr": "./runtime/hmr.js",
31
+ "./jsx-runtime": {
32
+ "types": "./jsx-runtime.d.ts"
33
+ }
34
+ },
35
+ "files": [
36
+ "index.js",
37
+ "index.d.ts",
38
+ "jsx-runtime.d.ts",
39
+ "core",
40
+ "runtime",
41
+ "components",
42
+ "server",
43
+ "!**/*.test.js"
44
+ ],
45
+ "keywords": [
46
+ "afw",
47
+ "opentf",
48
+ "signals",
49
+ "reactivity",
50
+ "web-components",
51
+ "custom-elements",
52
+ "jsx",
53
+ "ssr",
54
+ "ssg"
55
+ ],
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/Open-Tech-Foundation/afw.git",
59
+ "directory": "packages/afw"
60
+ },
61
+ "homepage": "https://afw.opentechf.org",
62
+ "bugs": "https://github.com/Open-Tech-Foundation/afw/issues",
63
+ "license": "MIT",
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "types": "./index.d.ts"
68
+ }
@@ -0,0 +1,7 @@
1
+ export function copyText(text: any): void;
2
+ /**
3
+ * Copy `text`, then give `button` the standard "Copied" feedback: add `is-copied`,
4
+ * swap its `.afw-copy-label` to "Copied", and revert after 2s. Idempotent across
5
+ * rapid clicks (the pending revert is reset each time).
6
+ */
7
+ export function copyWithFeedback(button: any, text: any): void;
@@ -0,0 +1,47 @@
1
+ //! Clipboard helpers for "copy" affordances (code blocks, etc.).
2
+ //
3
+ // Behavior travels with the component that needs it — these are imported by the
4
+ // `afw-internal-code-block` built-in and by `@opentf/afw-docs`'s `CodeBlock`, so a
5
+ // copy button works wherever it's rendered, with no cooperation from an ancestor
6
+ // layout. `copyText` prefers the async Clipboard API and falls back to a hidden
7
+ // `<textarea>` + `execCommand` for non-secure contexts / older browsers.
8
+
9
+ export function copyText(text) {
10
+ if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
11
+ navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
12
+ } else {
13
+ fallbackCopy(text);
14
+ }
15
+ }
16
+
17
+ function fallbackCopy(text) {
18
+ try {
19
+ const ta = document.createElement("textarea");
20
+ ta.value = text;
21
+ ta.style.position = "fixed";
22
+ ta.style.opacity = "0";
23
+ document.body.appendChild(ta);
24
+ ta.select();
25
+ document.execCommand("copy");
26
+ document.body.removeChild(ta);
27
+ } catch {
28
+ /* clipboard unavailable */
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Copy `text`, then give `button` the standard "Copied" feedback: add `is-copied`,
34
+ * swap its `.afw-copy-label` to "Copied", and revert after 2s. Idempotent across
35
+ * rapid clicks (the pending revert is reset each time).
36
+ */
37
+ export function copyWithFeedback(button, text) {
38
+ copyText(text);
39
+ const label = button.querySelector(".afw-copy-label");
40
+ button.classList.add("is-copied");
41
+ if (label) label.textContent = "Copied";
42
+ clearTimeout(button._afwCopyT);
43
+ button._afwCopyT = setTimeout(() => {
44
+ button.classList.remove("is-copied");
45
+ if (label) label.textContent = "Copy";
46
+ }, 2000);
47
+ }
@@ -0,0 +1,14 @@
1
+ export class CodeBlockElement extends HTMLElement {
2
+ set html(v: any);
3
+ get html(): any;
4
+ _html: any;
5
+ _adopted: boolean | undefined;
6
+ _applied: any;
7
+ connectedCallback(): void;
8
+ _rendered: boolean | undefined;
9
+ render(): void;
10
+ /** Wire the copy button to the block's `<pre>` text (idempotent). */
11
+ wireCopy(): void;
12
+ }
13
+ /** JSX props consumed by the compiler-generated custom-element host. */
14
+ export const CodeFence: { new(props: { html: string }): CodeBlockElement; prototype: CodeBlockElement };