1
2
3
4
5
6
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
//! Parent-owned slot fragment ABI (RFC-058 §5.5).
//!
//! Today the runtime mount captures slot content from a child
//! component's `light DOM` children, stashes the resulting
//! `DocumentFragment`s in a thread-local keyed on the child's
//! `ScopeId`, and replays them when the mount reaches the
//! child's `<slot>` placeholder. That model puts the mount in
//! the middle of every parent/child slot exchange — which is
//! the exact ownership boundary RFC-058 §5.5 wants to remove.
//!
//! The replacement: parents emit slot **fragment functions**
//! at compile time and pass them to the child's mount call.
//! When the child reaches `<slot>` it invokes the parent's
//! fragment function directly, with no mount discovery in
//! between. The fragment function runs in the parent's scope
//! (so `@click="parent_handler"` inside slotted content works
//! without scope acrobatics) and stamps directly into the
//! child's slot host.
//!
//! This module ships the **type surface** the macro-generated
//! mount code (RFC-058 Phase 3+) will populate. Phase 1 only
//! defines the shapes — the existing slots / capture path
//! continues to drive mount-mounted parents unchanged. Phase 3
//! replaces the runtime capture path for compiled parents with
//! direct fragment-function passing.
use RefCell;
use HashMap;
use ;
use ;
use crateScopeId;
/// Function pointer the macro emits per parent-authored slot.
///
/// The function is stateless and `'static` — it captures the
/// expression ASTs and constants from the parent template at
/// macro time, then runs against the live `SlotMountCtx` at
/// invocation time. Stateless `fn` (rather than `Box<dyn FnMut>`)
/// keeps the SlotSet payload compact across the eventual
/// Component Model boundary (RFC-058 §5.10).
pub type SlotFragment = fn;
/// Per-invocation context for a slot fragment. The fragment
/// appends DOM into `host` (a buffer the runtime then splices
/// before the live `<slot>` element it's materialising), and
/// receives both scope ids — the parent's (so directive
/// expressions evaluate in the right scope) and the child's
/// (so refs registered inside the slotted content participate
/// in the correct child component's `refs::register` table).
///
/// `parent_proxy` is the parent component's `js_sys::Proxy`,
/// captured at slot-set install time (RFC-058 Phase 3.5c).
/// Dynamic slot fragments — content with `pp-text` / `@click`
/// / `pp-bind` etc. that reads or writes parent state — pass
/// it to the generated install closure when stamping bindings
/// against the parent scope. Static fragments ignore it.
///
/// Using a `DocumentFragment` rather than the live slot host
/// keeps the fragment side oblivious to where in the DOM the
/// content lands — same buffer pattern the legacy mount's
/// capture/replay path uses (see [`crate::mount::materialize_slot`]).
/// One entry in a [`SlotSet`] — the macro-emitted fragment fn
/// plus optional scoped-slot metadata (the parent's `pp-let`
/// identifier when the slot was authored as
/// `<template pp-slot="N" pp-let="ident">`, RFC-058 Phase 3.5g).
/// Set of slot fragments a parent passes to a child mount call.
/// Built fluently by the macro:
///
/// ```ignore
/// SlotSet::new()
/// .default(parent_default_slot_fn)
/// .named("footer", parent_footer_slot_fn);
/// ```
///
/// Backed by a small `HashMap<&'static str, SlotEntry>` —
/// the slot-name keys are macro-emitted string literals so the
/// hash cost is negligible at typical slot counts (1-3 slots
/// per component is the canonical case).
/// Reserved slot name for the default (unnamed) slot. Matches
/// the wire-name the runtime mount uses for `default` slot
/// keying so the migration from mount-captured slots to
/// fragment-function slots can interoperate during Phase 3.
pub const DEFAULT_SLOT_NAME: &str = "default";
// ─── runtime registry ────────────────────────────────────────────
/// Stored per child instance — the parent-supplied [`SlotSet`]
/// alongside the parent's scope id + proxy captured at install
/// time. RFC-058 Phase 3.5c threads the parent context through
/// to [`SlotMountCtx`] so dynamic slot content can install
/// bindings against the parent scope.
thread_local!
/// Register the parent-supplied [`SlotSet`] for a child component
/// instance, capturing the parent's scope id + proxy alongside.
/// Idempotent — a repeat call replaces the prior set (the
/// runtime mount remounts the same scope id only after
/// teardown, so this only fires for fresh mounts).
///
/// No-op when the set is empty so an opaque mount call (every
/// `<my-tag></my-tag>` site) doesn't leak a registry entry.
/// Look up the parent entry for `(child_scope_id, name)`,
/// returning the fragment fn + scoped-slot metadata alongside
/// the parent context the installer captured. `None` when the
/// parent didn't register a [`SlotSet`] for this child, or
/// registered one without an entry for `name`. Caller (the
/// mount's slot materialiser) falls back to the legacy capture
/// path when this returns `None`.
/// Drop the fragment registration for `child_scope_id`. Hooked
/// from [`crate::scope::Scope::remove`].
/// Stamp a static HTML string into the slot fragment buffer.
///
/// RFC-058 Phase 3.5b — the macro emits one [`SlotFragment`]
/// per child-mount site whose slot content is statically
/// eligible (no `pp-*` / `@` / `:` directives, no
/// non-HTML5-native descendants); the body of that fragment
/// is just `stamp_static_html(ctx.host, "<inline html>")`. By
/// going through a `<template>` element rather than
/// `set_inner_html` directly on the buffer, the parse picks
/// up the correct content-model rules (e.g. `<tr>` inside
/// `<table>`, `<li>` outside `<ul>`) the same way the
/// browser would for any author-written markup.
/// Stamp slot HTML with directives + apply a static plan against
/// the parent scope. RFC-058 Phase 3.5c / RFC 064 §5.1 —
/// emitted by the macro for slot subtrees that carry plan-
/// eligible directives (`pp-text`, `pp-bind`, `@click`, etc.).
///
/// Goes through a temporary `<div>` host so the install pass
/// can resolve `node_path`s against a single root element.
/// `install_plan` is the macro-emitted per-fragment closure
/// that has the plan body unrolled inline; it installs every
/// directive against the parent scope using the Phase 1
/// helpers (effects subscribe to the parent proxy, listeners
/// delegate via the parent's scope). After install, the
/// just-installed children move into the slot fragment buffer
/// the runtime then splices before the live `<slot>` element.
///
/// The detached-DOM install is safe — text/html/bind/show
/// effects run synchronously at install and write to detached
/// DOM; listeners attach to detached elements and fire normally
/// once the children land in the document.
///
/// The closure boundary eliminates generic runtime plan
/// iteration for dynamic slot fragments (RFC 064 §5.1 Phase
/// 1.B). Top-level children are scope-stamped before the
/// install runs so any nested controller resolves its
/// `CTX_PARENT_KEY` against the slot owner.