@wardic/solid 3.0.0-next.1 → 3.0.0-next.2
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/dist/browser/diagnostic-codes.js +23 -3
- package/dist/browser/diagnostic-codes.js.map +1 -1
- package/dist/browser/hooks/presence-scope.js.map +1 -1
- package/dist/browser/hooks/ward.js +45 -7
- package/dist/browser/hooks/ward.js.map +1 -1
- package/dist/browser/v1/index.js +1 -1
- package/dist/server/diagnostic-codes.js +23 -3
- package/dist/server/diagnostic-codes.js.map +1 -1
- package/dist/server/hooks/presence-scope.js.map +1 -1
- package/dist/server/hooks/ward.js +45 -7
- package/dist/server/hooks/ward.js.map +1 -1
- package/dist/server/v1/index.js +1 -1
- package/dist/solid/diagnostic-codes.d.ts.map +1 -1
- package/dist/solid/diagnostic-codes.js +25 -3
- package/dist/solid/diagnostic-codes.js.map +1 -1
- package/dist/solid/hooks/presence-scope.d.ts +4 -3
- package/dist/solid/hooks/presence-scope.d.ts.map +1 -1
- package/dist/solid/hooks/presence-scope.jsx.map +1 -1
- package/dist/solid/hooks/ward.d.ts +5 -3
- package/dist/solid/hooks/ward.d.ts.map +1 -1
- package/dist/solid/hooks/ward.js +51 -7
- package/dist/solid/hooks/ward.js.map +1 -1
- package/dist/solid/v1/index.d.ts +1 -1
- package/dist/solid/v1/index.jsx +1 -1
- package/package.json +5 -5
- package/skills/wardic-diagnostics/SKILL.md +84 -3
- package/skills/wardic-migrate/SKILL.md +49 -1
- package/skills/wardic-solid/SKILL.md +3 -3
- package/skills/wardic-solid/from-motion.md +1 -1
- package/skills/wardic-solid/lists-and-presence.md +7 -5
- package/src/diagnostic-codes.ts +29 -3
- package/src/hooks/presence-scope.tsx +4 -3
- package/src/hooks/ward.ts +55 -10
- package/src/v1/index.tsx +1 -1
|
@@ -43,6 +43,87 @@ An element uses something that needs a Feature its provider wasn't given: a layo
|
|
|
43
43
|
|
|
44
44
|
## Presence
|
|
45
45
|
|
|
46
|
+
### WARDIC_EXIT_FORM_MIXED
|
|
47
|
+
|
|
48
|
+
A ward a hook shows has an `exit` and an `animate` in different forms, a variant name and a values map, so its exit can't be laid over its `animate` as it leaves.
|
|
49
|
+
|
|
50
|
+
**Why:** A ward a hook shows (its `show`, a `createWards` row, a `createPresence`'s) leaves by its exit laid over the target it was shown at, so a key the exit doesn't name keeps that target. Names lay over names, and a values map over a values map, but a name and a values map can't be laid over each other without resolving the name. Such a ward leaves by its exit alone: a key the exit doesn't name falls back to its `initial`, and its followers, which follow names, are handed none.
|
|
51
|
+
|
|
52
|
+
**Fix:** Write the exit in its `animate`'s form: a variant name under a name (`exit: "gone"`, with `gone: { opacity: 0 }` among its variants), or a values map under a values map.
|
|
53
|
+
|
|
54
|
+
**Before:**
|
|
55
|
+
|
|
56
|
+
```tsx before
|
|
57
|
+
import { createRune, createWards } from "@wardic/solid/hooks"
|
|
58
|
+
|
|
59
|
+
const comesIn = createRune({
|
|
60
|
+
variants: { away: { opacity: 0, x: -12 }, here: { opacity: 1, x: 0 } },
|
|
61
|
+
initial: "away",
|
|
62
|
+
animate: "here",
|
|
63
|
+
exit: { opacity: 0 },
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const rows = createWards(items, comesIn)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**After:**
|
|
70
|
+
|
|
71
|
+
```tsx solid2
|
|
72
|
+
import { createRune, createWards } from "@wardic/solid/hooks"
|
|
73
|
+
|
|
74
|
+
const comesIn = createRune({
|
|
75
|
+
variants: { away: { opacity: 0, x: -12 }, here: { opacity: 1, x: 0 }, gone: { opacity: 0 } },
|
|
76
|
+
initial: "away",
|
|
77
|
+
animate: "here",
|
|
78
|
+
exit: "gone",
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const rows = createWards(items, comesIn)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### WARDIC_EXIT_WHEN_UNDER_PRESENCE
|
|
85
|
+
|
|
86
|
+
`when` of an exit was asked of a ward made under a `<Presence>`, so an effect over it never runs.
|
|
87
|
+
|
|
88
|
+
**Why:** What a `<Presence>` takes away, a router's page or a slot, is ended by its owner first: Solid ends the component as its exit starts, and the boundary learns it left after. An effect made in that component, over its ward's `when("exitStart")`, is ended with it, before the leave is told. The ward still hears its leave: a promise from `next`, or an `each` loop, isn't owned by the component.
|
|
89
|
+
|
|
90
|
+
**Fix:** Listen with `next("exitStart")` or `each("exitStart")`, made in the component, and take `hold()` there for work that ends later. Give `next` a rejection handler: it rejects with an `AbortError` when the ward goes without leaving, its boundary unmounted with it. A ward your own state shows (its `show`, a `createWards` row, a `createPresence`'s) keeps its component while it leaves, so an effect over its `when` runs.
|
|
91
|
+
|
|
92
|
+
**Before:**
|
|
93
|
+
|
|
94
|
+
```tsx before
|
|
95
|
+
import { createEffect } from "solid-js"
|
|
96
|
+
import { createWard } from "@wardic/solid/hooks"
|
|
97
|
+
|
|
98
|
+
export const Lesson = () => {
|
|
99
|
+
const page = createWard({ exit: { opacity: 0 } })
|
|
100
|
+
createEffect(page.when("exitStart"), () => {
|
|
101
|
+
const release = page.hold()
|
|
102
|
+
void saveDraft().finally(release)
|
|
103
|
+
})
|
|
104
|
+
return <article {...page} />
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**After:**
|
|
109
|
+
|
|
110
|
+
```tsx solid2
|
|
111
|
+
import { createWard } from "@wardic/solid/hooks"
|
|
112
|
+
|
|
113
|
+
export const Lesson = () => {
|
|
114
|
+
const page = createWard({ exit: { opacity: 0 } })
|
|
115
|
+
page.next("exitStart").then(
|
|
116
|
+
() => {
|
|
117
|
+
const release = page.hold()
|
|
118
|
+
void saveDraft().finally(release)
|
|
119
|
+
},
|
|
120
|
+
// It went without leaving: nothing to hold.
|
|
121
|
+
() => {},
|
|
122
|
+
)
|
|
123
|
+
return <article {...page} />
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
46
127
|
### WARDIC_PRESENCE_SCOPE_REUSED
|
|
47
128
|
|
|
48
129
|
A presence scope's `within` was used round a second boundary while the first is still on the page.
|
|
@@ -139,11 +220,11 @@ A function rune used a member of its ward in the rune's body, before the ward wa
|
|
|
139
220
|
|
|
140
221
|
### WARDIC_STYLE_BESIDE_SPREAD
|
|
141
222
|
|
|
142
|
-
A ward
|
|
223
|
+
A ward was handed an element that never read its `style`: a `style` beside its spread replaced it, a component didn't pass `props.style` on, or the ward was called with the element and not spread.
|
|
143
224
|
|
|
144
|
-
**Why:** A ward's spread gives its Subject a `style` too: its initial values, and the styles it keeps. A `style` written after the spread replaces it, as any later prop does, so those never reach the Subject.
|
|
225
|
+
**Why:** A ward's spread gives its Subject a `style` too: its initial values, and the styles it keeps. A `style` written after the spread replaces it, as any later prop does, so those never reach the Subject. A ward called with an element (`ward(el)`), as 2.x's could be, hands it the element with no spread at all; the check can't tell that from a replaced style.
|
|
145
226
|
|
|
146
|
-
**Fix:** Give the style through the ward, `{...ward.with({ style })}`, or as its own `style`. A component the ward is spread on passes `props.style` to the element it renders with `props.ref`.
|
|
227
|
+
**Fix:** Give the style through the ward, `{...ward.with({ style })}`, or as its own `style`. A component the ward is spread on passes `props.style` to the element it renders with `props.ref`. An element the app doesn't render, the page's root or a portal's host, is given with a rune's `subject`: `createWard({ subject: () => document.documentElement })`.
|
|
147
228
|
|
|
148
229
|
**Before:**
|
|
149
230
|
|
|
@@ -66,6 +66,26 @@ A hook's ward is spread, never given to `wardRef` (`WARDIC_HOOK_WARD_IN_WARDREF`
|
|
|
66
66
|
|
|
67
67
|
Spread the ward on the component, and have the component pass `props.ref` and `props.style` to its element. Or give the ward its Subject with a rune's `subject`, when another component renders it.
|
|
68
68
|
|
|
69
|
+
### A ward on an element the app doesn't render: `ward(config)` called with it
|
|
70
|
+
|
|
71
|
+
2.x's `const page = ward(config); page(document.documentElement)` becomes a ward given its Subject by `subject`. Nothing renders that Subject, so the ward is made in the hook that holds what it hears, and the hook gives that, as state or the ward's `when` memos, not the ward:
|
|
72
|
+
|
|
73
|
+
```tsx solid2
|
|
74
|
+
import { createEffect, createSignal } from "solid-js"
|
|
75
|
+
import { createWard } from "@wardic/solid/hooks"
|
|
76
|
+
|
|
77
|
+
// The page's pointer: a ward on the page's root, which no component renders, that only listens.
|
|
78
|
+
function createPointer() {
|
|
79
|
+
const page = createWard({ subject: () => document.documentElement })
|
|
80
|
+
const [x, setX] = createSignal(0)
|
|
81
|
+
createEffect(page.when("hover"), (info) => {
|
|
82
|
+
setX(info.point.x)
|
|
83
|
+
})
|
|
84
|
+
// What it hears, as state, and the hover's start as a memo for an effect: not the ward.
|
|
85
|
+
return { x, entered: page.when("hoverStart") }
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
69
89
|
### Variant children: `card.Provider`, `ward(config, { parent })`
|
|
70
90
|
|
|
71
91
|
```tsx before
|
|
@@ -140,16 +160,44 @@ function Panel() {
|
|
|
140
160
|
}
|
|
141
161
|
```
|
|
142
162
|
|
|
163
|
+
A ward leaves by its `exit` laid over its `animate`, so a key the exit doesn't name keeps its shown value. Port an exit in its `animate`'s form: 2.x's and Motion's common `animate="visible"` with `exit={{ opacity: 0 }}` is a name with a values map, which can't be laid (`WARDIC_EXIT_FORM_MIXED`); give the exit a variant, `exit: "gone"` with `gone: { opacity: 0 }` among the variants.
|
|
164
|
+
|
|
143
165
|
### Presence hooks
|
|
144
166
|
|
|
167
|
+
A ward hears its own leave and can hold it. Where you listen depends on whether its component outlives the leave:
|
|
168
|
+
|
|
169
|
+
- **A ward your state shows** (its own `show`, a `createWards` row, a `createPresence`'s): its component stays while it leaves, so an effect over `when("exitStart")` runs. Port the `<AnimatePresence>` round the component to one of these where you can, by the table above.
|
|
170
|
+
- **A ward kept under `<Presence>`,** for what someone else removes (a router's page): Solid ends its component as its exit starts, before the leave is told, so an effect over its `when` has ended by then (`WARDIC_EXIT_WHEN_UNDER_PRESENCE`). Listen with `next("exitStart")`, or `each` for every leave: they outlive the component.
|
|
171
|
+
|
|
145
172
|
| 2.x | The hooks |
|
|
146
173
|
| --- | --- |
|
|
147
174
|
| `useIsPresent()` | `!ward.exiting()` |
|
|
148
|
-
| `usePresence()
|
|
175
|
+
| `usePresence()`, its work as the leave starts | Where the leave is heard, above: turn the Subject inert, pause its media, move focus |
|
|
176
|
+
| `usePresence()`'s `safeToRemove` | `ward.hold()`, taken there, for work that ends later (a save, another library's exit): the release it returns is `safeToRemove`. Work done at once needs no hold |
|
|
149
177
|
| `usePresenceData()` | A function variant's `custom` |
|
|
150
178
|
| `PresenceContext`, `usePresenceContext` | Gone: a ward hears its own exits |
|
|
151
179
|
| The main entry's `createPresence()`, a handle for `<AnimatePresence ref>` | `createPresenceRef()`, for `<Presence ref>`; or a `createPresenceScope` |
|
|
152
180
|
|
|
181
|
+
```tsx solid2
|
|
182
|
+
import { createWard } from "@wardic/solid/hooks"
|
|
183
|
+
|
|
184
|
+
// A router's page, under the layout's <Presence>: told it's leaving after Solid has ended it.
|
|
185
|
+
function Lesson() {
|
|
186
|
+
const page = createWard({ exit: { opacity: 0 } })
|
|
187
|
+
page.next("exitStart").then(
|
|
188
|
+
() => {
|
|
189
|
+
const release = page.hold()
|
|
190
|
+
void saveDraft().finally(release)
|
|
191
|
+
},
|
|
192
|
+
// It went without leaving, its boundary ended with it: nothing to hold.
|
|
193
|
+
() => {},
|
|
194
|
+
)
|
|
195
|
+
return <article {...page}>…</article>
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
`next` rejects with an `AbortError` when the ward goes without leaving (its boundary unmounted, the app ended), so it's given a handler for that; `each` just ends.
|
|
200
|
+
|
|
153
201
|
### Features and settings: `createWardic`, `<LazyWardic>`, `<WardicProvider>`, `<WardicConfig>`
|
|
154
202
|
|
|
155
203
|
| 2.x | The hooks |
|
|
@@ -25,7 +25,7 @@ Ward and rune are the language. Solve a motion problem with a ward or a rune; wh
|
|
|
25
25
|
Each rule's tier says what catches it: **type** (the compiler), **code** (a `[WARDIC_…]` diagnostic in development), **review** (no tool does: you hold it).
|
|
26
26
|
|
|
27
27
|
1. **A ward is made where its Subject is drawn:** in a component's body, or a row's callback, beside the markup it's spread on. Review; a ward made with no owner at all is code, `WARDIC_WARD_WITHOUT_OWNER`.
|
|
28
|
-
2. **An app's hooks hold state and give runes:** accessors, actions, runes that close over the state, rune factories (`card(index)`), `createRuneWith` values. The ward stays in the component. Review.
|
|
28
|
+
2. **An app's hooks hold state and give runes:** accessors, actions, runes that close over the state, rune factories (`card(index)`), `createRuneWith` values. The ward stays in the component. A ward on a Subject the app doesn't render (the page's root, a portal's host, given by `subject`) is made in the hook that holds what it hears; the hook gives that, as state or the ward's `when` memos, not the ward. Review.
|
|
29
29
|
3. **A ward is one-job runes, each named for what it does:** `fadesIn`, `lifts`, `springy`. An inline config is fine for a one-job ward used once. Review.
|
|
30
30
|
4. **A rune is made once, for what it describes:** in a module when it depends on nothing, once in a hook when it depends on the hook's state, by a function for each Subject when it depends on which Subject. Never in JSX or in a spread. Review.
|
|
31
31
|
5. **A follower is written out beside its leader:** `createWard({ follow: panel }, turns)`. Review.
|
|
@@ -39,12 +39,12 @@ Each rule's tier says what catches it: **type** (the compiler), **code** (a `[WA
|
|
|
39
39
|
1. **Name the Subjects:** what moves, and where each is drawn: a component, a list's row, an element another component renders (a rune's `subject`).
|
|
40
40
|
2. **Write the runes:** one job each, named for it, made where rule 4 says. Give each key in one rune: a key several runes give is merged at every retarget.
|
|
41
41
|
3. **Hold state in a hook, if there's any:** `createX()` returns the state and the runes that read it.
|
|
42
|
-
4. **Make each ward where its Subject is drawn,** from the runes: `createWard`; `createWards` for a list; `createPresence(ward, value)` for one value at a time; `<Presence>` round what someone else removes. Followers beside their leaders.
|
|
42
|
+
4. **Make each ward where its Subject is drawn,** from the runes: `createWard`; `createWards` for a list; `createPresence(ward, value)` for one value at a time; `<Presence>` round what someone else removes. Followers beside their leaders. A ward that only listens to a Subject nothing renders, given by `subject`, in the hook that holds what it hears.
|
|
43
43
|
5. **Spread each ward on its Subject.**
|
|
44
44
|
6. **Check.** The ward is done when:
|
|
45
45
|
- the app typechecks;
|
|
46
46
|
- a development run of the change, or its tests, reports no `[WARDIC_…]` code;
|
|
47
|
-
- every `createWard`, `createWards` and `createPresence` call is in a component's body or a row's callback;
|
|
47
|
+
- every `createWard`, `createWards` and `createPresence` call is in a component's body or a row's callback, or, for a `subject` ward that only listens, in the hook that holds what it hears;
|
|
48
48
|
- no hook of the app's returns a ward.
|
|
49
49
|
|
|
50
50
|
## Where to look
|
|
@@ -39,7 +39,7 @@ function Card() {
|
|
|
39
39
|
| `<AnimatePresence mode="wait">` round one value | `createPresence(ward, value)` |
|
|
40
40
|
| `<AnimatePresence>` round children someone else removes (a router's page) | `<Presence>`: `wait` or `pop` for `mode`, `enter={false}` for `initial={false}` |
|
|
41
41
|
| `onExitComplete` | `when("exitComplete")` in an effect: on the ward, the list `createWards` returns, or a presence scope |
|
|
42
|
-
| `usePresence
|
|
42
|
+
| `usePresence`, its `safeToRemove`, `useIsPresent` | An effect over `when("exitStart")`, `ward.hold()` in it for work that ends later, `ward.exiting()`. Under `<Presence>`, `next("exitStart")` in the effect's place, with a rejection handler, as its component has ended by then: see lists-and-presence.md |
|
|
43
43
|
| `<LayoutGroup id>` | `createLayoutGroup(id)`: a rune for a ward, and `within` for what it builds |
|
|
44
44
|
| `<MotionConfig transition reducedMotion>` | `createConfigScope({ transition, reducedMotion })`, a rune and `within`; for the whole page, `setupWard` |
|
|
45
45
|
| `<LazyMotion features>`, `m.div` | Nothing: each ward loads the Features its config uses. For Features at once, `makeWard({ features })` |
|
|
@@ -10,7 +10,7 @@ Choose by who decides that the Subject comes and goes. API: https://next.wardic.
|
|
|
10
10
|
| The value now beside the one it replaced | `createWards({ value }, ...runes)` |
|
|
11
11
|
| Children someone else removes: a router's page, a slot | `<Presence>`, or `createPresenceScope` |
|
|
12
12
|
|
|
13
|
-
Each leaves by its ward's `exit` (its `initial` with none; `exit: false` leaves at once).
|
|
13
|
+
Each leaves by its ward's `exit` (its `initial` with none; `exit: false` leaves at once), laid over its `animate`: a key the exit doesn't name keeps its shown value, so `exit: "faded"`, naming opacity alone, fades the Subject where it stands, under reduced motion too. Write the exit in its `animate`'s form, a name under a name or a values map under a values map: one of each can't be laid, and is `WARDIC_EXIT_FORM_MIXED`. Under `<Presence>`, a key the exit doesn't name stays where it stood: the same, but for a Subject leaving mid-entrance, which keeps rising here and stops there.
|
|
14
14
|
|
|
15
15
|
## One Subject: `show`
|
|
16
16
|
|
|
@@ -33,7 +33,7 @@ function Notice() {
|
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
- Hidden, a `show` ward
|
|
36
|
+
- Hidden, a `show` ward leaves by its `exit`, laid over its `animate`, then sets `display: none`. `mounted()` stays true until its exit has landed, for a `<Show>` that takes the Subject off the page instead.
|
|
37
37
|
- **A `show` ward is never a `layout` ward too:** hidden, it measures as an empty box and travels in from the page's corner. Something that comes and goes inside a layout container leaves the page: `createPresence`, or `createWards({ value })`.
|
|
38
38
|
- `pop` takes a leaving `show` ward out of the flow where it is, so what's after it moves up at once.
|
|
39
39
|
|
|
@@ -86,13 +86,15 @@ function Layout(props: { children: JSX.Element }) {
|
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
- Each page's motion is its own: a ward on its own root, leaving by its `exit`.
|
|
89
|
-
- **A ward made inside what a `<Presence>` takes away
|
|
89
|
+
- **A ward made inside what a `<Presence>` takes away hears its leave after its component has ended:** Solid ends the page as its exit starts, before the leave is told. Listen with `next("exitStart")`, or `each`, which outlive the page, and take `hold()` there; an effect over `when`, made in the page, has ended with it (`WARDIC_EXIT_WHEN_UNDER_PRESENCE`). `next` rejects with an `AbortError` if the page goes without leaving (its boundary unmounted with it): give it a rejection handler, `page.next("exitStart").then(leave, () => {})`.
|
|
90
|
+
- The boundary hears every child's leave too: `ref={presence}`, a `createPresenceRef()`, or a `createPresenceScope` made in a module, with `when("exitComplete")`.
|
|
90
91
|
- `wait` (one at a time) or `pop` (out of the flow at once), not both; `enter={false}` for no entrance on the first page.
|
|
91
92
|
|
|
92
93
|
## Leaving, heard
|
|
93
94
|
|
|
94
|
-
- A ward
|
|
95
|
-
-
|
|
95
|
+
- A ward hears its own `"exitStart"` and `"exitComplete"`; a list hears its own on what `createWards` returns.
|
|
96
|
+
- What a Subject does as its leave starts (inert, media paused, focus moved) is an effect over `when("exitStart")` where its component stays: a ward a hook shows (`show`, a row, a `createPresence`'s). Under a `<Presence>`, it's a `next("exitStart")`, above.
|
|
97
|
+
- `ward.hold()`, taken there, keeps a leaving Subject on the page until the release it returns is called: for a save, a CSS transition, another library's exit. Work done at once needs none.
|
|
96
98
|
|
|
97
99
|
```tsx solid2
|
|
98
100
|
import { createEffect, createSignal } from "solid-js"
|
package/src/diagnostic-codes.ts
CHANGED
|
@@ -75,6 +75,32 @@ export const CODES: ReadonlyArray<Diagnostic.Entry> = [
|
|
|
75
75
|
why: "A presence scope is one boundary: its `exiting()`, `next` and `when` tell of what leaves inside it. Used round two at once, it tells of both as one, so a wait on one ends when the other's exit does.",
|
|
76
76
|
repair: "Make a scope for each boundary, with `createPresenceScope` where each is drawn.",
|
|
77
77
|
},
|
|
78
|
+
{
|
|
79
|
+
code: "WARDIC_EXIT_FORM_MIXED",
|
|
80
|
+
group: "Presence",
|
|
81
|
+
summary: "A ward a hook shows has an `exit` and an `animate` in different forms, a variant name and a values map, so its exit can't be laid over its `animate` as it leaves.",
|
|
82
|
+
why: "A ward a hook shows (its `show`, a `createWards` row, a `createPresence`'s) leaves by its exit laid over the target it was shown at, so a key the exit doesn't name keeps that target. Names lay over names, and a values map over a values map, but a name and a values map can't be laid over each other without resolving the name. Such a ward leaves by its exit alone: a key the exit doesn't name falls back to its `initial`, and its followers, which follow names, are handed none.",
|
|
83
|
+
repair: "Write the exit in its `animate`'s form: a variant name under a name (`exit: \"gone\"`, with `gone: { opacity: 0 }` among its variants), or a values map under a values map.",
|
|
84
|
+
example: {
|
|
85
|
+
before:
|
|
86
|
+
'import { createRune, createWards } from "@wardic/solid/hooks"\n\nconst comesIn = createRune({\n variants: { away: { opacity: 0, x: -12 }, here: { opacity: 1, x: 0 } },\n initial: "away",\n animate: "here",\n exit: { opacity: 0 },\n})\n\nconst rows = createWards(items, comesIn)',
|
|
87
|
+
after:
|
|
88
|
+
'import { createRune, createWards } from "@wardic/solid/hooks"\n\nconst comesIn = createRune({\n variants: { away: { opacity: 0, x: -12 }, here: { opacity: 1, x: 0 }, gone: { opacity: 0 } },\n initial: "away",\n animate: "here",\n exit: "gone",\n})\n\nconst rows = createWards(items, comesIn)',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
code: "WARDIC_EXIT_WHEN_UNDER_PRESENCE",
|
|
93
|
+
group: "Presence",
|
|
94
|
+
summary: "`when` of an exit was asked of a ward made under a `<Presence>`, so an effect over it never runs.",
|
|
95
|
+
why: "What a `<Presence>` takes away, a router's page or a slot, is ended by its owner first: Solid ends the component as its exit starts, and the boundary learns it left after. An effect made in that component, over its ward's `when(\"exitStart\")`, is ended with it, before the leave is told. The ward still hears its leave: a promise from `next`, or an `each` loop, isn't owned by the component.",
|
|
96
|
+
repair: "Listen with `next(\"exitStart\")` or `each(\"exitStart\")`, made in the component, and take `hold()` there for work that ends later. Give `next` a rejection handler: it rejects with an `AbortError` when the ward goes without leaving, its boundary unmounted with it. A ward your own state shows (its `show`, a `createWards` row, a `createPresence`'s) keeps its component while it leaves, so an effect over its `when` runs.",
|
|
97
|
+
example: {
|
|
98
|
+
before:
|
|
99
|
+
'import { createEffect } from "solid-js"\nimport { createWard } from "@wardic/solid/hooks"\n\nexport const Lesson = () => {\n const page = createWard({ exit: { opacity: 0 } })\n createEffect(page.when("exitStart"), () => {\n const release = page.hold()\n void saveDraft().finally(release)\n })\n return <article {...page} />\n}',
|
|
100
|
+
after:
|
|
101
|
+
'import { createWard } from "@wardic/solid/hooks"\n\nexport const Lesson = () => {\n const page = createWard({ exit: { opacity: 0 } })\n page.next("exitStart").then(\n () => {\n const release = page.hold()\n void saveDraft().finally(release)\n },\n // It went without leaving: nothing to hold.\n () => {},\n )\n return <article {...page} />\n}',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
78
104
|
{
|
|
79
105
|
code: "WARDIC_FOLLOW_LEADER_UNNAMED",
|
|
80
106
|
group: "Follow, variants and config",
|
|
@@ -220,9 +246,9 @@ export const CODES: ReadonlyArray<Diagnostic.Entry> = [
|
|
|
220
246
|
{
|
|
221
247
|
code: "WARDIC_STYLE_BESIDE_SPREAD",
|
|
222
248
|
group: "Refs and spread",
|
|
223
|
-
summary: "A ward
|
|
224
|
-
why: "A ward's spread gives its Subject a `style` too: its initial values, and the styles it keeps. A `style` written after the spread replaces it, as any later prop does, so those never reach the Subject.",
|
|
225
|
-
repair: "Give the style through the ward, `{...ward.with({ style })}`, or as its own `style`. A component the ward is spread on passes `props.style` to the element it renders with `props.ref`.",
|
|
249
|
+
summary: "A ward was handed an element that never read its `style`: a `style` beside its spread replaced it, a component didn't pass `props.style` on, or the ward was called with the element and not spread.",
|
|
250
|
+
why: "A ward's spread gives its Subject a `style` too: its initial values, and the styles it keeps. A `style` written after the spread replaces it, as any later prop does, so those never reach the Subject. A ward called with an element (`ward(el)`), as 2.x's could be, hands it the element with no spread at all; the check can't tell that from a replaced style.",
|
|
251
|
+
repair: "Give the style through the ward, `{...ward.with({ style })}`, or as its own `style`. A component the ward is spread on passes `props.style` to the element it renders with `props.ref`. An element the app doesn't render, the page's root or a portal's host, is given with a rune's `subject`: `createWard({ subject: () => document.documentElement })`.",
|
|
226
252
|
example: {
|
|
227
253
|
before: 'import { createWard } from "@wardic/solid/hooks"\n\nexport const Card = () => {\n const card = createWard({ initial: { opacity: 0 }, animate: { opacity: 1 } })\n return <div {...card} style={{ width: "40px" }} />\n}',
|
|
228
254
|
after: 'import { createWard } from "@wardic/solid/hooks"\n\nexport const Card = () => {\n const card = createWard({ initial: { opacity: 0 }, animate: { opacity: 1 } })\n return <div {...card.with({ style: { width: "40px" } })} />\n}',
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* `within(build)` builds what it's given under the scope, and keeps a child that leaves on the page
|
|
14
14
|
* until the exits of the wards inside it have landed. Each ward made there, at any depth, registers
|
|
15
15
|
* its exit with the scope as it mounts; once its child leaves, the scope runs that exit itself, from
|
|
16
|
-
* what the ward registered, so it runs after Solid has ended the child
|
|
17
|
-
*
|
|
18
|
-
* `
|
|
16
|
+
* what the ward registered, so it runs after Solid has ended the child. The scope hears each leave, by
|
|
17
|
+
* `exiting()` and its `"exitStart"` and `"exitComplete"`, and so does each ward inside, by a watch of its
|
|
18
|
+
* own (`watchedUnder`, `ward.ts`): its `next` and `each`, and its `hold()`. An effect the child made over a
|
|
19
|
+
* ward's `when` has ended with the child, before the leave is told.
|
|
19
20
|
*
|
|
20
21
|
* The value is a presence handle, so it can be a `<Presence>`'s own, or another's `ref`. It's
|
|
21
22
|
* today's presence controller as a hook: `within` is `<AnimatePresence>` round what it builds, its
|
package/src/hooks/ward.ts
CHANGED
|
@@ -50,6 +50,7 @@ import { eachOf, Waiters, whenOf } from "../waiters.ts"
|
|
|
50
50
|
import { CLIENT_ONLY, onSettledClientOnly } from "../solid-reactivity.ts"
|
|
51
51
|
import type { WardElement } from "../lifecycle.ts"
|
|
52
52
|
import type * as PresenceRecord from "@wardic/core/unstable/PresenceRecord"
|
|
53
|
+
import * as VariantTarget from "@wardic/core/unstable/VariantTarget"
|
|
53
54
|
import { misuse, report } from "../diagnostics.ts"
|
|
54
55
|
import { fixLater, GESTURE_KEYS, holderFinished, holderWard, internalsOf, keepsState, sensedOf, sharedMember, shareMembers, shareOf, SLIM, targetAgain, type Ward, type WardConfig, type WardInternals, wardWith } from "../ward.tsx"
|
|
55
56
|
import { asking, type AutoFeature, colorsOnceLoaded, featureOfEvent, wantedBy } from "./auto.ts"
|
|
@@ -73,7 +74,7 @@ export type ExitEvent = PresenceEvent
|
|
|
73
74
|
export type HookWard = Ward & WardReads & {
|
|
74
75
|
/**
|
|
75
76
|
* Whether it's leaving: true from the moment it starts to leave until it has gone, or is shown
|
|
76
|
-
* again. Always false for a ward no hook shows.
|
|
77
|
+
* again. Always false for a ward that never leaves: one no hook shows and no presence takes away.
|
|
77
78
|
*/
|
|
78
79
|
readonly exiting: Accessor<boolean>
|
|
79
80
|
/**
|
|
@@ -90,8 +91,10 @@ export type HookWard = Ward & WardReads & {
|
|
|
90
91
|
* createEffect(frame.when("exitComplete"), () => trigger.focus())
|
|
91
92
|
* ```
|
|
92
93
|
*
|
|
93
|
-
* A ward made inside what a presence component takes away
|
|
94
|
-
*
|
|
94
|
+
* A ward made inside what a presence component takes away hears its own too, after its component
|
|
95
|
+
* has ended (PW1): Solid ends it as its exit starts, before the leave is told. So listen with `next`
|
|
96
|
+
* or `each`, which outlive the component; an effect over `when`, made there, has ended with it (PW4),
|
|
97
|
+
* which development reports, `WARDIC_EXIT_WHEN_UNDER_PRESENCE`. Not told on a Stage in this probe.
|
|
95
98
|
*/
|
|
96
99
|
next<E extends ExitEvent>(name: E): Promise<ExitEvents[E]>
|
|
97
100
|
/** Every `name` of its exits from the call on, for a `for await`. */
|
|
@@ -615,6 +618,30 @@ export const showing =
|
|
|
615
618
|
state.counted(finish)
|
|
616
619
|
}
|
|
617
620
|
state.released = finish
|
|
621
|
+
// The change of `show` a mixed exit was last reported in: once a leave.
|
|
622
|
+
let mixedIn = -1
|
|
623
|
+
/**
|
|
624
|
+
* Where it goes as it leaves: its exit laid over the target it was shown at (the hook-exit grill), so a
|
|
625
|
+
* key its exit doesn't name keeps that target, as under `<Presence>` and in Motion. A name under a
|
|
626
|
+
* values map, or the other way round, can't be laid: it leaves by the exit alone, as it did, and in
|
|
627
|
+
* development its own exit is reported, once a leave. One leaving by its `initial` isn't.
|
|
628
|
+
*/
|
|
629
|
+
const laidOver = (shown: unknown, leaving: unknown): unknown => {
|
|
630
|
+
// With no `animate`, a key the exit doesn't name was never moved from its base: the exit as it is.
|
|
631
|
+
if (Predicate.isUndefined(shown)) return leaving
|
|
632
|
+
return Option.getOrElse(VariantTarget.exitOver(leaving as VariantTarget.Leave, shown as VariantTarget.Shown), () => {
|
|
633
|
+
if (DEV) warnsOfMixedExit()
|
|
634
|
+
return leaving
|
|
635
|
+
})
|
|
636
|
+
}
|
|
637
|
+
/** In development, a mixed exit of its own, once a leave: one leaving by its `initial` isn't reported. */
|
|
638
|
+
const warnsOfMixedExit = (): void => {
|
|
639
|
+
const now = turnsNow()
|
|
640
|
+
if (mixedIn === now) return
|
|
641
|
+
mixedIn = now
|
|
642
|
+
if (Predicate.isUndefined(runes.value("exit"))) return
|
|
643
|
+
report("WARDIC_EXIT_FORM_MIXED", EXIT_FORM_MIXED)
|
|
644
|
+
}
|
|
618
645
|
return {
|
|
619
646
|
animate: (shown) => {
|
|
620
647
|
if (show()) return shown
|
|
@@ -622,8 +649,8 @@ export const showing =
|
|
|
622
649
|
if (Predicate.isUndefined(leaving)) return shown
|
|
623
650
|
// A ward that ends as it goes has nowhere to rest: it stays where it left to, and whether
|
|
624
651
|
// it's mounted isn't read for it, so nothing is worked out again as it goes.
|
|
625
|
-
if (state.ends()) return leaving
|
|
626
|
-
if (mounted()) return leaving
|
|
652
|
+
if (state.ends()) return laidOver(shown, leaving)
|
|
653
|
+
if (mounted()) return laidOver(shown, leaving)
|
|
627
654
|
return rest(leaving)
|
|
628
655
|
},
|
|
629
656
|
style: (style) => {
|
|
@@ -766,8 +793,11 @@ const checked = (ward: Ward): Ward => {
|
|
|
766
793
|
return ward
|
|
767
794
|
}
|
|
768
795
|
|
|
796
|
+
const EXIT_FORM_MIXED =
|
|
797
|
+
"createWard: the ward's `exit` and its `animate` are written in different forms, a variant name and a values map, so its exit can't be laid over its `animate`: a key the exit doesn't name falls back to its `initial` as it leaves, and its followers are handed no name. Write the exit as its `animate` is: a variant (`exit: \"gone\"`, with `gone` in its variants) under a name, or a values map under a values map."
|
|
798
|
+
|
|
769
799
|
const STYLE_BESIDE =
|
|
770
|
-
"createWard: the ward
|
|
800
|
+
"createWard: the ward was handed an element that never read its `style`: a `style` beside its spread (`<div {...ward} style={…}>`), a component that doesn't pass `props.style` on, or the ward called with the element (`ward(el)`) and not spread. Give the style through the ward, `{...ward.with({ style })}`, or as its own `style`; give an element the app doesn't render, the page's root, with a rune's `subject` (`createWard({ subject: () => el })`)."
|
|
771
801
|
|
|
772
802
|
const UNFORWARDED =
|
|
773
803
|
"createWard: a ward was spread on a component that never called its `ref`, so no element is its and nothing it says will move. The component must pass `props.ref` to the element it renders (`<div ref={props.ref}>`), or spread its props on that element whole."
|
|
@@ -1534,15 +1564,30 @@ const listening = (member: "when" | "next" | "each", kept: Kept, ask: (name: Aut
|
|
|
1534
1564
|
const EXIT_NAMES: ReadonlySet<string> = new Set<string>(["exitStart", "exitComplete"])
|
|
1535
1565
|
|
|
1536
1566
|
/** `member` of `watched`'s exits, for one of their names. */
|
|
1537
|
-
const watchedExit = (member: "when" | "next" | "each", watched: Watched, event: PresenceEvent): unknown => {
|
|
1567
|
+
const watchedExit = (member: "when" | "next" | "each", kept: Kept, watched: Watched, event: PresenceEvent): unknown => {
|
|
1538
1568
|
if (member === "next") return watched.waiters.wait(event)
|
|
1539
1569
|
if (member === "each") return eachOf<PresenceEvents, PresenceEvent>(watched.waiters, event)
|
|
1570
|
+
if (DEV) warnsOfExitWhen(kept, event)
|
|
1540
1571
|
return whenOf<PresenceEvents, PresenceEvent>(watched.waiters, event)
|
|
1541
1572
|
}
|
|
1542
1573
|
|
|
1574
|
+
/**
|
|
1575
|
+
* In development, a warning for `when` of an exit asked of a ward made under a presence: an effect over it,
|
|
1576
|
+
* made in the component the presence takes away, is ended with that component, which Solid ends as the exit
|
|
1577
|
+
* starts, before the presence tells it (PW4). Its `next` and `each` outlive the component. Not for one a
|
|
1578
|
+
* presence of the hooks' has taken by then: its leave is that presence's, told while the component lives.
|
|
1579
|
+
*/
|
|
1580
|
+
const warnsOfExitWhen = (kept: Kept, event: PresenceEvent): void => {
|
|
1581
|
+
if (takenNow(kept)) return
|
|
1582
|
+
report("WARDIC_EXIT_WHEN_UNDER_PRESENCE", exitWhen(event))
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
const exitWhen = (event: PresenceEvent): string =>
|
|
1586
|
+
`createWard: \`when("${event}")\` was asked of a ward made under a \`<Presence>\`. Solid ends its component as its exit starts, before the leave is told, so an effect over it never runs. Listen with \`next("${event}")\` or \`each("${event}")\`, which outlive the component, and take \`hold()\` there.`
|
|
1587
|
+
|
|
1543
1588
|
/** `base`, its exits heard of `watched` where the ward was made under a presence. */
|
|
1544
|
-
const watchedListening = (member: "when" | "next" | "each", watched: Watched, base: Listening): Listening => (event) => {
|
|
1545
|
-
if (EXIT_NAMES.has(event)) return watchedExit(member, watched, event as PresenceEvent)
|
|
1589
|
+
const watchedListening = (member: "when" | "next" | "each", kept: Kept, watched: Watched, base: Listening): Listening => (event) => {
|
|
1590
|
+
if (EXIT_NAMES.has(event)) return watchedExit(member, kept, watched, event as PresenceEvent)
|
|
1546
1591
|
return base(event)
|
|
1547
1592
|
}
|
|
1548
1593
|
|
|
@@ -1564,7 +1609,7 @@ const sharedListening = (member: "when" | "next" | "each"): PropertyDescriptor =
|
|
|
1564
1609
|
if (Predicate.isNotUndefined(ask) && Predicate.isNotUndefined(instance)) base = listening(member, kept, ask, instance, shared)
|
|
1565
1610
|
const watched = kept.watched
|
|
1566
1611
|
let own = base
|
|
1567
|
-
if (Predicate.isNotUndefined(watched)) own = watchedListening(member, watched, base)
|
|
1612
|
+
if (Predicate.isNotUndefined(watched)) own = watchedListening(member, kept, watched, base)
|
|
1568
1613
|
if (own === shared) return shared
|
|
1569
1614
|
kept[member] = own
|
|
1570
1615
|
return own
|
package/src/v1/index.tsx
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @deprecated Solid 1's binding, deprecated and frozen: it goes at Wardic's next major. Solid 2's is `@wardic/solid` (#566).
|
|
19
19
|
*/
|
|
20
|
-
export const VERSION = "3.0.0-next.
|
|
20
|
+
export const VERSION = "3.0.0-next.2"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* `WardicProvider` (one Effect runtime + `AtomRegistry` per ADR-0006), the
|