@wardic/solid 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/batch-reorder-group.js +3 -2
- package/dist/browser/batch-reorder-group.js.map +1 -1
- package/dist/browser/complete.js +3 -8
- package/dist/browser/complete.js.map +1 -1
- package/dist/browser/create-batch.js +13 -3
- package/dist/browser/create-batch.js.map +1 -1
- package/dist/browser/drag-sensor.js +44 -6
- package/dist/browser/drag-sensor.js.map +1 -1
- package/dist/browser/element.js +3 -1
- package/dist/browser/element.js.map +1 -1
- package/dist/browser/focus-sensor.js +21 -4
- package/dist/browser/focus-sensor.js.map +1 -1
- package/dist/browser/frame-effect.js +108 -0
- package/dist/browser/frame-effect.js.map +1 -0
- package/dist/browser/hover-sensor.js +21 -7
- package/dist/browser/hover-sensor.js.map +1 -1
- package/dist/browser/index.js +7 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/lifecycle.js +12 -0
- package/dist/browser/lifecycle.js.map +1 -1
- package/dist/browser/presence-hooks.js +5 -3
- package/dist/browser/presence-hooks.js.map +1 -1
- package/dist/browser/press-sensor.js +21 -7
- package/dist/browser/press-sensor.js.map +1 -1
- package/dist/browser/provider.js +7 -4
- package/dist/browser/provider.js.map +1 -1
- package/dist/browser/sensors.js +54 -3
- package/dist/browser/sensors.js.map +1 -1
- package/dist/browser/solid-reactivity.js +7 -0
- package/dist/browser/solid-reactivity.js.map +1 -1
- package/dist/browser/stage-batch.js +85 -0
- package/dist/browser/stage-batch.js.map +1 -0
- package/dist/browser/stage-graph.js +264 -0
- package/dist/browser/stage-graph.js.map +1 -0
- package/dist/browser/stage-hooks.js +61 -0
- package/dist/browser/stage-hooks.js.map +1 -0
- package/dist/browser/stage-ward.js +687 -0
- package/dist/browser/stage-ward.js.map +1 -0
- package/dist/browser/stage.js +8 -0
- package/dist/browser/stage.js.map +1 -0
- package/dist/browser/unstable/v2/index.js +9 -0
- package/dist/browser/unstable/v2/index.js.map +1 -1
- package/dist/browser/v1/index.js +1 -1
- package/dist/browser/w.js +3 -3
- package/dist/browser/w.js.map +1 -1
- package/dist/browser/ward-first.js +45 -0
- package/dist/browser/ward-first.js.map +1 -0
- package/dist/browser/ward.js +35 -6
- package/dist/browser/ward.js.map +1 -1
- package/dist/server/batch-reorder-group.js +3 -2
- package/dist/server/batch-reorder-group.js.map +1 -1
- package/dist/server/complete.js +3 -8
- package/dist/server/complete.js.map +1 -1
- package/dist/server/create-batch.js +13 -3
- package/dist/server/create-batch.js.map +1 -1
- package/dist/server/drag-sensor.js +44 -6
- package/dist/server/drag-sensor.js.map +1 -1
- package/dist/server/element.js +3 -1
- package/dist/server/element.js.map +1 -1
- package/dist/server/focus-sensor.js +21 -4
- package/dist/server/focus-sensor.js.map +1 -1
- package/dist/server/frame-effect.js +108 -0
- package/dist/server/frame-effect.js.map +1 -0
- package/dist/server/hover-sensor.js +21 -7
- package/dist/server/hover-sensor.js.map +1 -1
- package/dist/server/index.js +7 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/lifecycle.js +12 -0
- package/dist/server/lifecycle.js.map +1 -1
- package/dist/server/presence-hooks.js +5 -3
- package/dist/server/presence-hooks.js.map +1 -1
- package/dist/server/press-sensor.js +21 -7
- package/dist/server/press-sensor.js.map +1 -1
- package/dist/server/provider.js +7 -4
- package/dist/server/provider.js.map +1 -1
- package/dist/server/sensors.js +54 -3
- package/dist/server/sensors.js.map +1 -1
- package/dist/server/solid-reactivity.js +7 -0
- package/dist/server/solid-reactivity.js.map +1 -1
- package/dist/server/stage-batch.js +85 -0
- package/dist/server/stage-batch.js.map +1 -0
- package/dist/server/stage-graph.js +264 -0
- package/dist/server/stage-graph.js.map +1 -0
- package/dist/server/stage-hooks.js +61 -0
- package/dist/server/stage-hooks.js.map +1 -0
- package/dist/server/stage-ward.js +687 -0
- package/dist/server/stage-ward.js.map +1 -0
- package/dist/server/stage.js +8 -0
- package/dist/server/stage.js.map +1 -0
- package/dist/server/unstable/v2/index.js +9 -0
- package/dist/server/unstable/v2/index.js.map +1 -1
- package/dist/server/v1/index.js +1 -1
- package/dist/server/w.js +3 -3
- package/dist/server/w.js.map +1 -1
- package/dist/server/ward-first.js +45 -0
- package/dist/server/ward-first.js.map +1 -0
- package/dist/server/ward.js +35 -6
- package/dist/server/ward.js.map +1 -1
- package/dist/solid/batch-reorder-group.d.ts.map +1 -1
- package/dist/solid/batch-reorder-group.jsx +3 -2
- package/dist/solid/batch-reorder-group.jsx.map +1 -1
- package/dist/solid/complete.d.ts +8 -1
- package/dist/solid/complete.d.ts.map +1 -1
- package/dist/solid/complete.jsx +3 -9
- package/dist/solid/complete.jsx.map +1 -1
- package/dist/solid/create-batch.d.ts +5 -0
- package/dist/solid/create-batch.d.ts.map +1 -1
- package/dist/solid/create-batch.jsx +14 -3
- package/dist/solid/create-batch.jsx.map +1 -1
- package/dist/solid/drag-sensor.d.ts +18 -2
- package/dist/solid/drag-sensor.d.ts.map +1 -1
- package/dist/solid/drag-sensor.jsx +41 -6
- package/dist/solid/drag-sensor.jsx.map +1 -1
- package/dist/solid/element.d.ts.map +1 -1
- package/dist/solid/element.jsx +3 -1
- package/dist/solid/element.jsx.map +1 -1
- package/dist/solid/focus-sensor.d.ts +10 -3
- package/dist/solid/focus-sensor.d.ts.map +1 -1
- package/dist/solid/focus-sensor.jsx +25 -5
- package/dist/solid/focus-sensor.jsx.map +1 -1
- package/dist/solid/frame-effect.d.ts +3 -0
- package/dist/solid/frame-effect.d.ts.map +1 -0
- package/dist/solid/frame-effect.jsx +112 -0
- package/dist/solid/frame-effect.jsx.map +1 -0
- package/dist/solid/hover-sensor.d.ts +14 -3
- package/dist/solid/hover-sensor.d.ts.map +1 -1
- package/dist/solid/hover-sensor.jsx +20 -6
- package/dist/solid/hover-sensor.jsx.map +1 -1
- package/dist/solid/index.d.ts +8 -0
- package/dist/solid/index.d.ts.map +1 -1
- package/dist/solid/index.jsx +7 -0
- package/dist/solid/index.jsx.map +1 -1
- package/dist/solid/lifecycle.d.ts +3 -0
- package/dist/solid/lifecycle.d.ts.map +1 -1
- package/dist/solid/lifecycle.js +13 -0
- package/dist/solid/lifecycle.js.map +1 -1
- package/dist/solid/presence-hooks.d.ts +5 -3
- package/dist/solid/presence-hooks.d.ts.map +1 -1
- package/dist/solid/presence-hooks.jsx +5 -3
- package/dist/solid/presence-hooks.jsx.map +1 -1
- package/dist/solid/press-sensor.d.ts +11 -3
- package/dist/solid/press-sensor.d.ts.map +1 -1
- package/dist/solid/press-sensor.jsx +24 -6
- package/dist/solid/press-sensor.jsx.map +1 -1
- package/dist/solid/provider.d.ts.map +1 -1
- package/dist/solid/provider.jsx +7 -4
- package/dist/solid/provider.jsx.map +1 -1
- package/dist/solid/sensors.d.ts +25 -1
- package/dist/solid/sensors.d.ts.map +1 -1
- package/dist/solid/sensors.jsx +53 -3
- package/dist/solid/sensors.jsx.map +1 -1
- package/dist/solid/solid-reactivity.d.ts +7 -0
- package/dist/solid/solid-reactivity.d.ts.map +1 -1
- package/dist/solid/solid-reactivity.js +7 -0
- package/dist/solid/solid-reactivity.js.map +1 -1
- package/dist/solid/stage-batch.d.ts +6 -0
- package/dist/solid/stage-batch.d.ts.map +1 -0
- package/dist/solid/stage-batch.js +86 -0
- package/dist/solid/stage-batch.js.map +1 -0
- package/dist/solid/stage-graph.d.ts +79 -0
- package/dist/solid/stage-graph.d.ts.map +1 -0
- package/dist/solid/stage-graph.js +224 -0
- package/dist/solid/stage-graph.js.map +1 -0
- package/dist/solid/stage-hooks.d.ts +52 -0
- package/dist/solid/stage-hooks.d.ts.map +1 -0
- package/dist/solid/stage-hooks.js +44 -0
- package/dist/solid/stage-hooks.js.map +1 -0
- package/dist/solid/stage-ward.d.ts +52 -0
- package/dist/solid/stage-ward.d.ts.map +1 -0
- package/dist/solid/stage-ward.jsx +609 -0
- package/dist/solid/stage-ward.jsx.map +1 -0
- package/dist/solid/stage.d.ts +309 -0
- package/dist/solid/stage.d.ts.map +1 -0
- package/dist/solid/stage.js +8 -0
- package/dist/solid/stage.js.map +1 -0
- package/dist/solid/unstable/v2/index.d.ts +96 -0
- package/dist/solid/unstable/v2/index.d.ts.map +1 -1
- package/dist/solid/unstable/v2/index.jsx +18 -0
- package/dist/solid/unstable/v2/index.jsx.map +1 -1
- package/dist/solid/v1/index.d.ts +1 -1
- package/dist/solid/v1/index.jsx +1 -1
- package/dist/solid/w.d.ts +11 -0
- package/dist/solid/w.d.ts.map +1 -1
- package/dist/solid/w.jsx +3 -3
- package/dist/solid/w.jsx.map +1 -1
- package/dist/solid/ward-first.d.ts +21 -0
- package/dist/solid/ward-first.d.ts.map +1 -0
- package/dist/solid/ward-first.js +50 -0
- package/dist/solid/ward-first.js.map +1 -0
- package/dist/solid/ward-keys.d.ts +13 -12
- package/dist/solid/ward-keys.d.ts.map +1 -1
- package/dist/solid/ward.d.ts +49 -0
- package/dist/solid/ward.d.ts.map +1 -1
- package/dist/solid/ward.jsx +31 -6
- package/dist/solid/ward.jsx.map +1 -1
- package/package.json +5 -4
- package/src/batch-reorder-group.tsx +3 -2
- package/src/complete.tsx +16 -9
- package/src/create-batch.tsx +19 -3
- package/src/drag-sensor.tsx +54 -6
- package/src/element.tsx +3 -1
- package/src/focus-sensor.tsx +33 -6
- package/src/frame-effect.tsx +122 -0
- package/src/hover-sensor.tsx +25 -6
- package/src/index.tsx +46 -0
- package/src/lifecycle.ts +13 -0
- package/src/presence-hooks.tsx +5 -3
- package/src/press-sensor.tsx +30 -6
- package/src/provider.tsx +7 -4
- package/src/sensors.tsx +67 -2
- package/src/solid-reactivity.ts +8 -0
- package/src/stage-batch.ts +89 -0
- package/src/stage-graph.ts +264 -0
- package/src/stage-hooks.ts +100 -0
- package/src/stage-ward.tsx +795 -0
- package/src/stage.ts +337 -0
- package/src/unstable/v2/index.tsx +96 -0
- package/src/v1/index.tsx +1 -1
- package/src/w.tsx +22 -5
- package/src/ward-first.ts +67 -0
- package/src/ward-keys.ts +14 -13
- package/src/ward.tsx +42 -6
package/src/stage.ts
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Stage, as the shared hooks find it (ADR-0073 decisions 11, 12 and 20): what runs a scene for its
|
|
3
|
+
* owner, through a Solid context, `WardicStage`, which is its own provider. It names no three.js code:
|
|
4
|
+
* `@wardic/three/solid`'s `createStage` fills it for a three.js scene, and another Environment (Pixi, a
|
|
5
|
+
* terminal) would fill the same interface.
|
|
6
|
+
*
|
|
7
|
+
* Under a `WardicStage`, `ward(mesh, config)` hands a Subject the Stage says is its own to the Stage's
|
|
8
|
+
* ward, an accessor of one too, and `createFrameEffect` runs in the Stage's Host loop, before it renders.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const stage = createStage({ renderer, scene, camera })
|
|
12
|
+
* <WardicStage value={stage}>
|
|
13
|
+
* <Card />
|
|
14
|
+
* </WardicStage>
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
// #884's PR 3 (ADR-0073, *Amendment (#884)*, Q3 and Q4).
|
|
19
|
+
import type { JSX } from "@solidjs/web"
|
|
20
|
+
import type * as Drag from "@wardic/core/Drag"
|
|
21
|
+
import type * as InputFeed from "@wardic/core/InputFeed"
|
|
22
|
+
import type * as InputSource from "@wardic/core/InputSource"
|
|
23
|
+
import type * as Config from "@wardic/core/unstable/Config"
|
|
24
|
+
import type * as FrameEffects from "@wardic/core/unstable/FrameEffects"
|
|
25
|
+
import type * as Imperative from "@wardic/core/unstable/Imperative"
|
|
26
|
+
import { type Accessor, type Context, createContext } from "solid-js"
|
|
27
|
+
import type * as Effect from "effect/Effect"
|
|
28
|
+
import type * as Atom from "effect/reactivity/Atom"
|
|
29
|
+
import type * as Scope from "effect/Scope"
|
|
30
|
+
import type * as BatchMembers from "@wardic/dom/unstable/BatchMembers"
|
|
31
|
+
import type { PerKey, PerKeyApart } from "./config-view.ts"
|
|
32
|
+
import type { WardElement, WardEvents, WardSettled } from "./lifecycle.ts"
|
|
33
|
+
import type { WardCallbackKey, WardConfigValues, WardOptions } from "./ward.tsx"
|
|
34
|
+
import type { WardCheckedConfig, WardKey, WardValueOf } from "./ward-keys.ts"
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The Subjects a Stage takes, by the Environment that fills one, for `ward`'s types:
|
|
38
|
+
* `@wardic/three/solid` adds three.js's objects, as `declare module "@wardic/solid" { interface
|
|
39
|
+
* StageSubjects { three: Object3D | Material } }` does. None until one does, so a config is never taken
|
|
40
|
+
* for a Subject.
|
|
41
|
+
*/
|
|
42
|
+
// #884's PR 3: by declaration merging, so `@wardic/solid` names no three.js type.
|
|
43
|
+
export interface StageSubjects {}
|
|
44
|
+
|
|
45
|
+
/** A Stage's Subject: any an Environment has added to {@link StageSubjects}. */
|
|
46
|
+
export type StageSubject = StageSubjects[keyof StageSubjects]
|
|
47
|
+
|
|
48
|
+
/** A drag's range on one axis of its Subject's parent's space: its least, then its most. */
|
|
49
|
+
export type StageDragRange = readonly [min: number, max: number]
|
|
50
|
+
|
|
51
|
+
/** A scene drag's release: its inertia's, as `type: "inertia"`'s, Motion's `dragTransition`. */
|
|
52
|
+
export type StageDragTransition = Omit<Config.WardicInertia, "type" | "velocity" | "min" | "max">
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A scene's drag keys (#885's PR 4; ADR-0070 decision 9, kept by ADR-0073 decision 18), in a Stage ward's
|
|
56
|
+
* config in the page's drag keys' place. An Environment adds its own by declaration merging:
|
|
57
|
+
* `@wardic/three/solid` adds `dragPlane`.
|
|
58
|
+
*/
|
|
59
|
+
export interface StageDragConfig {
|
|
60
|
+
/**
|
|
61
|
+
* `true` drags its Subject on the plane through the point grabbed, facing the camera; `"x"`, `"y"` or
|
|
62
|
+
* `"z"`, along that axis of its parent's space.
|
|
63
|
+
*/
|
|
64
|
+
readonly drag?: boolean | "x" | "y" | "z" | undefined
|
|
65
|
+
/** Its ranges per axis, in its parent's space: `{ x: [-2, 2], z: [-2, 2] }`. */
|
|
66
|
+
readonly dragConstraints?: { readonly x?: StageDragRange; readonly y?: StageDragRange; readonly z?: StageDragRange } | undefined
|
|
67
|
+
/** How far it's pulled past a range: 0 stops it there, 1 lets it go freely. Default 0.35. */
|
|
68
|
+
readonly dragElastic?: number | undefined
|
|
69
|
+
/** Whether it glides on at its release's speed. Default `true`. */
|
|
70
|
+
readonly dragMomentum?: boolean | undefined
|
|
71
|
+
/** Its release's inertia. */
|
|
72
|
+
readonly dragTransition?: StageDragTransition | undefined
|
|
73
|
+
/** Whether it goes back to where it was picked up from at its release. */
|
|
74
|
+
readonly dragSnapToOrigin?: boolean | undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A Stage ward's config values: a ward's, with a scene's drag keys in the page's. */
|
|
78
|
+
export interface StageWardConfigValues extends Omit<WardConfigValues, keyof StageDragConfig>, StageDragConfig {}
|
|
79
|
+
|
|
80
|
+
/** A Stage ward's config: each key a value, or an accessor of it, read per key, as a ward's. */
|
|
81
|
+
export type StageWardConfig = PerKey<StageWardConfigValues, WardCallbackKey>
|
|
82
|
+
|
|
83
|
+
/** A Stage ward's config `C`, its transitions' entries checked against the keys each drives, as `WardChecked`. */
|
|
84
|
+
export type StageWardChecked<C> = WardCheckedConfig<C, PerKeyApart<StageWardConfigValues, WardCallbackKey>, StageValueKey>
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The values a Stage's Subjects take beyond an element's, by name, for a ward's config on one: an
|
|
88
|
+
* Environment adds its own by declaration merging, as it adds its Subjects to {@link StageSubjects}.
|
|
89
|
+
* `@wardic/three/solid` adds three.js's: a material's `roughness` and `emissive`, a light's
|
|
90
|
+
* `intensity`, a camera's `fov`. A name in neither an element's values nor these is an error naming it.
|
|
91
|
+
*/
|
|
92
|
+
// #934: the scene lab's keys were all an element's too (`opacity`, `color`); a material's own weren't.
|
|
93
|
+
export interface StageValues {}
|
|
94
|
+
|
|
95
|
+
/** The names of {@link StageValues}. */
|
|
96
|
+
export type StageValueKey = keyof StageValues & string
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* What each key of a Stage's Subject `S` reads as, by the Environment that fills one: a ward's `read` takes
|
|
100
|
+
* its Subject's keys at these types. `@wardic/three/solid` adds three.js's, as `declare module
|
|
101
|
+
* "@wardic/solid" { interface StageReads<S> { three: SceneReads<S> } }` does: a scene object's numbers,
|
|
102
|
+
* its material's and its vectors' axes, each a number. None until one does.
|
|
103
|
+
*/
|
|
104
|
+
// #939: generic, by declaration merging, so `@wardic/solid` names no three.js type; each Environment's
|
|
105
|
+
// reads of a Subject it doesn't take are `{}`, and the reads of `S` are every Environment's, as one.
|
|
106
|
+
// `Record<never, S>` is `{}`: a base that names `S`, which every declaration of it shares.
|
|
107
|
+
export interface StageReads<S> extends Record<never, S> {}
|
|
108
|
+
|
|
109
|
+
/** Each of a union's members, as one: `{ a } | { b }` as `{ a } & { b }`. */
|
|
110
|
+
type Intersected<U> = (U extends unknown ? (each: U) => void : never) extends (all: infer I) => void ? I : never
|
|
111
|
+
|
|
112
|
+
/** Every Environment's reads of `S`, as one; none with no Environment. */
|
|
113
|
+
type ReadsOf<S> = [keyof StageReads<S>] extends [never] ? {} : Intersected<StageReads<S>[keyof StageReads<S>]>
|
|
114
|
+
|
|
115
|
+
/** `undefined` where `S` can be: an accessor's Subject while it gives none. */
|
|
116
|
+
type MissingFrom<S> = undefined extends S ? undefined : never
|
|
117
|
+
|
|
118
|
+
/** The keys a ward on `S` reads at its Subject's own types. */
|
|
119
|
+
export type StageReadKey<S> = keyof ReadsOf<NonNullable<S>> & string
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* What a ward on `S` with config `C` reads for `key`: the Subject's own type for a key it has, `undefined`
|
|
123
|
+
* only while an accessor gives no Subject; any other key, as a page ward reads it.
|
|
124
|
+
*/
|
|
125
|
+
export type StageValueOf<C, S, K extends string> = K extends StageReadKey<S> ? ReadsOf<NonNullable<S>>[K] | MissingFrom<S> : WardValueOf<C, K>
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A Stage ward's `read`: completion offers the keys its config animates and its Subject's, and any other
|
|
129
|
+
* key is accepted. A key its Subject has reads at its Subject's type, from the Subject's own value until
|
|
130
|
+
* the ward or an `animate` moves it.
|
|
131
|
+
*/
|
|
132
|
+
export interface StageRead<C, S> {
|
|
133
|
+
<K extends WardKey<C> | StageReadKey<S>>(key: K): Accessor<StageValueOf<C, S, K & string>>
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The Subject a ward is given: itself, or what an accessor gives, `undefined` among it. */
|
|
137
|
+
export type StageSubjectOf<G> = G extends () => infer S ? S : G
|
|
138
|
+
|
|
139
|
+
/** What a drag tells as it goes: each pointer sample, and its release coming to rest. */
|
|
140
|
+
export interface StageDragHandlers {
|
|
141
|
+
readonly sample: (sample: Drag.Sample) => void
|
|
142
|
+
readonly released: () => void
|
|
143
|
+
readonly onDefect?: InputFeed.OnDefect | undefined
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** What a Stage drags its Subjects with (#885's PR 4): its Environment's, `@wardic/three`'s `ThreeDrag` for three's. */
|
|
147
|
+
export interface StageDrag {
|
|
148
|
+
/**
|
|
149
|
+
* Watch `subject`'s drags on the Stage's input: each gesture read with `config()` at its start, its
|
|
150
|
+
* Subject moved as it goes, and released at its end.
|
|
151
|
+
*/
|
|
152
|
+
readonly watch: (subject: object, config: () => StageDragConfig, handlers: StageDragHandlers) => Effect.Effect<void, never, Scope.Scope | InputSource.InputSource>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A scene Batch's values (#885's PR 5): its keys' numbers, three's keys (`x`, `y`, `z`, `rotateY`,
|
|
157
|
+
* `scale` and the rest), a colour key a colour, as `animate`'s. Its keys are its first targets'.
|
|
158
|
+
*/
|
|
159
|
+
export type StageBatchValues = Readonly<Record<string, unknown>>
|
|
160
|
+
|
|
161
|
+
/** A scene Batch's gesture or exit: its values, and the transition it runs on, else the Batch's. */
|
|
162
|
+
export type StageBatchTarget = StageBatchValues & { readonly transition?: BatchMembers.WardicBatchTransition | undefined }
|
|
163
|
+
|
|
164
|
+
/** What a scene Batch's members are: a three.js object each (`object`), or an `InstancedMesh`'s instances (`instances`). */
|
|
165
|
+
export type StageBatchMembers<Args extends ReadonlyArray<unknown>> =
|
|
166
|
+
| {
|
|
167
|
+
/** Each member's object, made as it enters, which joins `parent` (else its own, else the Stage's scene) and leaves once its exit lands. */
|
|
168
|
+
readonly object: (...args: Args) => object
|
|
169
|
+
readonly instances?: undefined
|
|
170
|
+
}
|
|
171
|
+
| {
|
|
172
|
+
/** An `InstancedMesh`: each member an instance, at the next free index as it enters; as one leaves, the last moves into its index. */
|
|
173
|
+
readonly instances: object
|
|
174
|
+
readonly object?: undefined
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A scene Batch's config by count (#885's PR 5; ADR-0070 decision 11): `count` members, each `animate(i)`. */
|
|
178
|
+
export type StageCountBatchConfig = StageBatchMembers<[i: number]> & {
|
|
179
|
+
readonly count: number
|
|
180
|
+
readonly initial?: false | StageBatchValues | ((i: number) => StageBatchValues) | undefined
|
|
181
|
+
readonly animate: (i: number) => StageBatchValues
|
|
182
|
+
readonly whileHover?: StageBatchTarget | ((i: number) => StageBatchValues) | undefined
|
|
183
|
+
readonly whileTap?: StageBatchTarget | ((i: number) => StageBatchValues) | undefined
|
|
184
|
+
readonly transition?: BatchMembers.WardicBatchTransition | undefined
|
|
185
|
+
/** The object its members join: else each one's own parent, else the Stage's scene. */
|
|
186
|
+
readonly parent?: object | undefined
|
|
187
|
+
/** Its keys, fixed now: else its first targets'. */
|
|
188
|
+
readonly keys?: ReadonlyArray<string> | undefined
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A scene Batch's keyed config (#885's PR 5; ADR-0070 decisions 11 and 13): a list's items, each a member by its key. */
|
|
192
|
+
export type StageKeyedBatchConfig<T> = StageBatchMembers<[item: T, i: number]> & {
|
|
193
|
+
readonly each: () => ReadonlyArray<T>
|
|
194
|
+
readonly key: keyof T | ((item: T) => unknown)
|
|
195
|
+
readonly initial?: false | StageBatchValues | ((item: T, i: number) => StageBatchValues) | undefined
|
|
196
|
+
readonly animate: (item: T, i: number) => StageBatchValues
|
|
197
|
+
/** What a leaving member plays before it leaves. */
|
|
198
|
+
readonly exit?: StageBatchTarget | ((item: T, i: number) => StageBatchValues) | undefined
|
|
199
|
+
readonly whileHover?: StageBatchTarget | ((item: T, i: number) => StageBatchValues) | undefined
|
|
200
|
+
readonly whileTap?: StageBatchTarget | ((item: T, i: number) => StageBatchValues) | undefined
|
|
201
|
+
readonly transition?: BatchMembers.WardicBatchTransition | undefined
|
|
202
|
+
readonly parent?: object | undefined
|
|
203
|
+
/** Dispose each object's geometries and materials, and its descendants', once it has left. */
|
|
204
|
+
readonly dispose?: boolean | undefined
|
|
205
|
+
readonly keys?: ReadonlyArray<string> | undefined
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** A scene Batch's member, as its gesture events tell it: its index now, a keyed one's item, and its object or instance. */
|
|
209
|
+
export interface StageBatchMemberInfo {
|
|
210
|
+
readonly i: number
|
|
211
|
+
readonly item?: unknown
|
|
212
|
+
/** Its object, or for an instance, `{ mesh, index }`. */
|
|
213
|
+
readonly element: object
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** A scene Batch's events, by name, for `next` and `when`: its landings, and its members' hovers and presses. */
|
|
217
|
+
export interface StageBatchEvents {
|
|
218
|
+
/** Every member at rest again: how many set off in the flight. */
|
|
219
|
+
readonly settled: { readonly moved: number }
|
|
220
|
+
readonly hoverStart: StageBatchMemberInfo
|
|
221
|
+
readonly hoverEnd: StageBatchMemberInfo
|
|
222
|
+
readonly pressStart: StageBatchMemberInfo
|
|
223
|
+
readonly tap: StageBatchMemberInfo
|
|
224
|
+
readonly tapCancel: StageBatchMemberInfo
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** A scene Batch: its landings, as a page's Batch's. Its members are its own: it adds and removes them. */
|
|
228
|
+
export interface StageBatch {
|
|
229
|
+
/** Its last landing, `undefined` before the first: pending while a member moves. */
|
|
230
|
+
readonly settled: () => StageBatchEvents["settled"] | undefined
|
|
231
|
+
/** A promise of its next `name`. */
|
|
232
|
+
readonly next: <E extends keyof StageBatchEvents>(name: E) => Promise<StageBatchEvents[E]>
|
|
233
|
+
/** Every `name` from now on, for an effect. */
|
|
234
|
+
readonly when: <E extends keyof StageBatchEvents>(name: E) => Accessor<StageBatchEvents[E]>
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** What a scene Batch tells its binding: a flight's start, its landing, and its members' gestures. */
|
|
238
|
+
export interface StageBatchHooks {
|
|
239
|
+
readonly started: () => void
|
|
240
|
+
readonly landed: (landing: StageBatchEvents["settled"]) => void
|
|
241
|
+
readonly gesture: <E extends Exclude<keyof StageBatchEvents, "settled">>(name: E, info: StageBatchEvents[E]) => void
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* A scene Batch bound to its Stage, as `createBatch` drives it: its targets read where they track, a
|
|
246
|
+
* compute's, then applied, its members entering and leaving, by its effect; its gestures watched once asked for.
|
|
247
|
+
*/
|
|
248
|
+
export interface StageBatchBinding {
|
|
249
|
+
readonly targetsOf: () => unknown
|
|
250
|
+
readonly apply: (targets: unknown) => void
|
|
251
|
+
readonly listen: (gesture: "hover" | "press") => void
|
|
252
|
+
readonly dispose: () => void
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** An event a ward on a Stage's Subject tells: its landings, its hovers and presses, and its drags, through the Stage's input. */
|
|
256
|
+
export type StageEvent = "settled" | "hoverStart" | "hover" | "hoverEnd" | "pressStart" | "tap" | "tapCancel" | "dragStart" | "drag" | "dragEnd" | "dragTransitionEnd"
|
|
257
|
+
|
|
258
|
+
/** An event's info on a Stage's Subject: a ward's, with the Subject as its `element`. */
|
|
259
|
+
type OnSubject<T> = T extends { readonly element: WardElement } ? Omit<T, "element"> & { readonly element: object } : T
|
|
260
|
+
|
|
261
|
+
/** Each {@link StageEvent}'s info. */
|
|
262
|
+
export type StageEvents = { readonly [E in StageEvent]: OnSubject<WardEvents[E]> }
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* A ward on a Stage's Subject: its events and values, as a ward on an element has them, and `held`,
|
|
266
|
+
* which renders nothing and joins its component's `<Loading>` while its Subject or config is still
|
|
267
|
+
* loading. Return it from a component that renders nothing else.
|
|
268
|
+
*/
|
|
269
|
+
// `C` unbounded: `ward<C>` for a page's `C extends WardConfig` instantiates the Stage's overload too.
|
|
270
|
+
// `S`, its Subject (#939): `undefined` among it while an accessor can give none.
|
|
271
|
+
export interface StageWard<C = StageWardConfig, S = StageSubject> {
|
|
272
|
+
/** Renders nothing; reads the ward's pending Subject and config, so its component's `<Loading>` and `<Reveal>` wait for them. */
|
|
273
|
+
readonly held: JSX.Element
|
|
274
|
+
/** Its last landing, as a ward's `settled`: pending while a change runs. */
|
|
275
|
+
readonly settled: Accessor<WardSettled | undefined>
|
|
276
|
+
/** Its last tap, as a ward's `tapped`: pending while a press is down. */
|
|
277
|
+
readonly tapped: Accessor<StageEvents["tap"] | undefined>
|
|
278
|
+
/** The next `name`, as a ward's `next`. */
|
|
279
|
+
readonly next: <E extends StageEvent>(name: E) => Promise<StageEvents[E]>
|
|
280
|
+
/** Every `name` from now on, as a ward's `each`. */
|
|
281
|
+
readonly each: <E extends StageEvent>(name: E) => AsyncIterable<StageEvents[E]>
|
|
282
|
+
/** Every `name`, as a memo for an effect, as a ward's `when`. */
|
|
283
|
+
readonly when: <E extends StageEvent>(name: E) => Accessor<StageEvents[E]>
|
|
284
|
+
/** Its Subject's value for `key`, as a ward's `read`: a key its Subject has, at its Subject's type. */
|
|
285
|
+
readonly read: StageRead<C, S>
|
|
286
|
+
/** The same as an `effect/reactivity` Atom, as a ward's `atom`. */
|
|
287
|
+
readonly atom: (key: string) => Atom.Atom<unknown>
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** An event a Scene object tells beside its ward's: its exit's start, and its landing, once the Subject has left. */
|
|
291
|
+
export type SceneObjectEvent = StageEvent | "exitStart" | "exitComplete"
|
|
292
|
+
|
|
293
|
+
/** A Scene object's exit: the Subject leaving, as `element`, as a Stage ward's events carry it. */
|
|
294
|
+
export interface SceneObjectExit {
|
|
295
|
+
readonly element: object
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Each {@link SceneObjectEvent}'s info. */
|
|
299
|
+
export type SceneObjectEvents = StageEvents & { readonly exitStart: SceneObjectExit; readonly exitComplete: SceneObjectExit }
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A Scene object's handle (ADR-0073 decision 15): its ward, with its membership's events, `exitStart` and
|
|
303
|
+
* `exitComplete`, which only this handle has. `next("exitComplete")` resolves after its owner has ended.
|
|
304
|
+
*/
|
|
305
|
+
export interface SceneWard<C = StageWardConfig, S = StageSubject> extends Omit<StageWard<C, S>, "next" | "each" | "when"> {
|
|
306
|
+
/** The next `name`: a ward's event, or its exit's. */
|
|
307
|
+
readonly next: <E extends SceneObjectEvent>(name: E) => Promise<SceneObjectEvents[E]>
|
|
308
|
+
/** Every `name` from now on. */
|
|
309
|
+
readonly each: <E extends SceneObjectEvent>(name: E) => AsyncIterable<SceneObjectEvents[E]>
|
|
310
|
+
/** Every `name`, as a memo for an effect. */
|
|
311
|
+
readonly when: <E extends SceneObjectEvent>(name: E) => Accessor<SceneObjectEvents[E]>
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** What runs a scene for its owner, as the shared hooks read it: its Subjects, its ward, `animate`, its Frame effects and its input. */
|
|
315
|
+
export interface Stage {
|
|
316
|
+
/** Whether `value` is one of its Environment's Subjects: a three.js object, by its `is*` flags. */
|
|
317
|
+
readonly isSubject: (value: unknown) => boolean
|
|
318
|
+
/** A ward on `subject`, one of its Subjects or an accessor of one: what `ward(subject, config)` hands it. */
|
|
319
|
+
readonly ward: (subject: unknown, config: StageWardConfig, options?: WardOptions) => StageWard
|
|
320
|
+
/** Motion's `animate`, on its Subjects. */
|
|
321
|
+
readonly animate: (subject: object, target: Readonly<Record<string, unknown>>, options?: Imperative.WardicAnimateOptions) => Imperative.WardicPlaybackControls
|
|
322
|
+
/** Its Frame effects: run in its Host loop after Wardic's writes, before it renders; `request` asks a loop that draws on demand for a frame. */
|
|
323
|
+
readonly frameEffects: Pick<FrameEffects.FrameEffects, "add" | "request">
|
|
324
|
+
/** Its pointer input, for a sensor given one of its Subjects. */
|
|
325
|
+
readonly input: InputSource.InputSource["Service"]
|
|
326
|
+
/** What it drags its Subjects with: a ward's `drag` with none is an error in development. */
|
|
327
|
+
readonly drag?: StageDrag | undefined
|
|
328
|
+
/** What makes its Batches (#885's PR 5): `createBatch` with `object` or `instances` with none is an error in development. */
|
|
329
|
+
readonly batch?: ((config: StageKeyedBatchConfig<unknown> | StageCountBatchConfig, hooks: StageBatchHooks) => StageBatchBinding) | undefined
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* The Stage the hooks under it use: Solid 2's own provider, `<WardicStage value={stage}>`, and
|
|
334
|
+
* `useContext(WardicStage)` to read it. `null` outside one.
|
|
335
|
+
*/
|
|
336
|
+
// Solid 2 reads a context made with no default as an error outside its provider: `null` is "none".
|
|
337
|
+
export const WardicStage: Context<Stage | null> = /*#__PURE__*/ createContext<Stage | null>(null)
|
|
@@ -96,6 +96,100 @@ export {
|
|
|
96
96
|
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
97
97
|
ward,
|
|
98
98
|
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
99
|
+
type HeldWard,
|
|
100
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
101
|
+
type SceneObjectEvent,
|
|
102
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
103
|
+
type SceneObjectEvents,
|
|
104
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
105
|
+
type SceneObjectExit,
|
|
106
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
107
|
+
type SceneWard,
|
|
108
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
109
|
+
type Stage,
|
|
110
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
111
|
+
type StageBatch,
|
|
112
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
113
|
+
type StageBatchBinding,
|
|
114
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
115
|
+
type StageBatchEvents,
|
|
116
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
117
|
+
type StageBatchHooks,
|
|
118
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
119
|
+
type StageBatchMemberInfo,
|
|
120
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
121
|
+
type StageBatchMembers,
|
|
122
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
123
|
+
type StageBatchTarget,
|
|
124
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
125
|
+
type StageBatchValues,
|
|
126
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
127
|
+
type StageCountBatchConfig,
|
|
128
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
129
|
+
type StageDrag,
|
|
130
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
131
|
+
type StageDragConfig,
|
|
132
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
133
|
+
type StageDragHandlers,
|
|
134
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
135
|
+
type StageDragRange,
|
|
136
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
137
|
+
type StageDragTransition,
|
|
138
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
139
|
+
type StageEvent,
|
|
140
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
141
|
+
type StageEvents,
|
|
142
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
143
|
+
stageSceneObject,
|
|
144
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
145
|
+
type StageGraph,
|
|
146
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
147
|
+
type StageMembership,
|
|
148
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
149
|
+
type StageKeyedBatchConfig,
|
|
150
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
151
|
+
type StageRead,
|
|
152
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
153
|
+
type StageReadKey,
|
|
154
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
155
|
+
type StageReads,
|
|
156
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
157
|
+
type StageSubject,
|
|
158
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
159
|
+
type StageSubjectOf,
|
|
160
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
161
|
+
type StageSubjects,
|
|
162
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
163
|
+
type StageValueKey,
|
|
164
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
165
|
+
type StageValueOf,
|
|
166
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
167
|
+
type StageValues,
|
|
168
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
169
|
+
type StageWard,
|
|
170
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
171
|
+
stageWard,
|
|
172
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
173
|
+
wardOnStage,
|
|
174
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
175
|
+
createBatchOnStage,
|
|
176
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
177
|
+
createDragOnStage,
|
|
178
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
179
|
+
createHoverOnStage,
|
|
180
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
181
|
+
createPressOnStage,
|
|
182
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
183
|
+
type StageWardChecked,
|
|
184
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
185
|
+
type StageWardConfig,
|
|
186
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
187
|
+
type StageWardConfigValues,
|
|
188
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
189
|
+
type StageWardEnvironment,
|
|
190
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
191
|
+
WardicStage,
|
|
192
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
99
193
|
type WardDragInfo,
|
|
100
194
|
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
101
195
|
type WardElement,
|
|
@@ -386,6 +480,8 @@ export {
|
|
|
386
480
|
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
387
481
|
createAnimationFrame,
|
|
388
482
|
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
483
|
+
createFrameEffect,
|
|
484
|
+
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
389
485
|
createFollowValue,
|
|
390
486
|
/** @deprecated `@wardic/solid/unstable/v2` is `@wardic/solid` since 2.0: import it from there. This alias goes at Wardic's next major (#566). */
|
|
391
487
|
createSpring,
|
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 = "2.0
|
|
20
|
+
export const VERSION = "2.1.0"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* `WardicProvider` (one Effect runtime + `AtomRegistry` per ADR-0006), the
|
package/src/w.tsx
CHANGED
|
@@ -20,23 +20,30 @@ import type * as All from "@wardic/dom/unstable/features/All"
|
|
|
20
20
|
import type { WardCheckedConfig } from "./ward-keys.ts"
|
|
21
21
|
import type { PerKeyApart } from "./config-view.ts"
|
|
22
22
|
import { createOf, type CreateFor, type FeatureProps, formOf, type OwnPropsFor, type WardicComponentFor } from "./element.tsx"
|
|
23
|
-
import
|
|
23
|
+
import type { Accessor } from "solid-js"
|
|
24
|
+
import type { StageSubject, StageSubjectOf, StageWard, StageWardChecked, StageWardConfig } from "./stage.ts"
|
|
25
|
+
import { SLIM, type Ward, type WardCallbackKey, type WardChecked, type WardConfig, type WardFor, type WardInternals, type WardOptions, type WardStyle } from "./ward.tsx"
|
|
26
|
+
import { type HeldWard, wardFrom } from "./ward-first.ts"
|
|
24
27
|
|
|
25
28
|
/** `w.ward(config, options)`: `ward()`'s ward, on a Slim element. */
|
|
26
29
|
interface SlimWard {
|
|
30
|
+
/** Its Subject first (#884): `w.ward(el, config)` is `w.ward(config)(el)`, with `held`. */
|
|
31
|
+
<const C extends WardConfig>(subject: Element, config: WardChecked<C>, options?: WardOptions): HeldWard<Ward<C>>
|
|
32
|
+
/** A Stage's Subject first, under a `<WardicStage>` (#884): the Stage's ward, which reads its Subject's keys at their types. */
|
|
33
|
+
<const C extends WardConfig | StageWardConfig, G extends StageSubject | Accessor<StageSubject | undefined>>(subject: G, config: StageWardChecked<C>, options?: WardOptions): StageWard<C, StageSubjectOf<G>>
|
|
34
|
+
// The config first, last of the generic forms, so `ReturnType` of an instantiation is still a DOM ward.
|
|
27
35
|
<const C extends WardConfig>(config: WardChecked<C>, options?: WardOptions): Ward<C>
|
|
28
36
|
(): Ward<{}>
|
|
37
|
+
// Last, so `ReturnType` of it is too.
|
|
29
38
|
(config: undefined, options: WardOptions): Ward<{}>
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
/** No config: a ward that only listens (#398), `w.ward()`. */
|
|
33
|
-
const NO_CONFIG: WardConfig = {}
|
|
34
|
-
|
|
35
42
|
/** A ward on an element of `kind`, as `w.ward` makes one. */
|
|
36
43
|
const wardOf =
|
|
37
44
|
(kind: WardInternals) =>
|
|
38
|
-
(
|
|
39
|
-
|
|
45
|
+
(first?: unknown, second?: unknown, third?: unknown): Ward | HeldWard<Ward> | StageWard =>
|
|
46
|
+
wardFrom(first, second, third, kind)
|
|
40
47
|
|
|
41
48
|
/** Every form of a `w` whose elements are of `kind` (#516): the Slim element's `w`, and a Wardic instance's. */
|
|
42
49
|
export const wOf = (kind: WardInternals): W => formOf<W>(createOf(kind), { ward: wardOf(kind) })
|
|
@@ -65,8 +72,18 @@ type MakeWardFor<FN extends string> = Feature.NamesEvery<FeatureProps, FN> exten
|
|
|
65
72
|
* `settled` and their events alone (Q19).
|
|
66
73
|
*/
|
|
67
74
|
interface MakeInstanceWard<FN extends string> {
|
|
75
|
+
/** Its Subject first (#884), with `held`. */
|
|
76
|
+
<const C extends WardConfig>(
|
|
77
|
+
subject: Element,
|
|
78
|
+
config: WardCheckedConfig<C, PerKeyApart<InstanceValues<FN>, WardCallbackKey & keyof InstanceValues<FN>>>,
|
|
79
|
+
options?: WardOptions,
|
|
80
|
+
): HeldWard<WardFor<C, FN>>
|
|
81
|
+
/** A Stage's Subject first, under a `<WardicStage>` (#884): the Stage's ward, which reads its Subject's keys at their types. */
|
|
82
|
+
<const C extends WardConfig | StageWardConfig, G extends StageSubject | Accessor<StageSubject | undefined>>(subject: G, config: StageWardChecked<C>, options?: WardOptions): StageWard<C, StageSubjectOf<G>>
|
|
83
|
+
// The config first, last of the generic forms, so `ReturnType` of an instantiation is still a DOM ward.
|
|
68
84
|
<const C extends WardConfig>(config: WardCheckedConfig<C, PerKeyApart<InstanceValues<FN>, WardCallbackKey & keyof InstanceValues<FN>>>, options?: WardOptions): WardFor<C, FN>
|
|
69
85
|
(): WardFor<{}, FN>
|
|
86
|
+
// Last, so `ReturnType` of it is too.
|
|
70
87
|
(config: undefined, options: WardOptions): WardFor<{}, FN>
|
|
71
88
|
}
|
|
72
89
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ward`'s forms with its Subject first (ADR-0073 decision 8; *Amendment (#884)*, Q4 and Q8): an element,
|
|
3
|
+
* the Stage's Subject, or an accessor of one, then its config. `ward(el, config)` is `ward(config)(el)`,
|
|
4
|
+
* with `held`; a Subject the Stage in context says is its own, or any accessor under a Stage, is the
|
|
5
|
+
* Stage's ward. Anything else first is a config, so `ward(config, { parent })` keeps its meaning.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
// #884's PR 3. The DOM's ward (`wardWith`) is untouched: a Stage's Subject goes to the Stage's own ward,
|
|
10
|
+
// so the DOM's bundle carries this hand-off and nothing of a Stage's.
|
|
11
|
+
import type { JSX } from "@solidjs/web"
|
|
12
|
+
import * as Arr from "effect/Array"
|
|
13
|
+
import * as Predicate from "effect/Predicate"
|
|
14
|
+
import * as Rec from "effect/Record"
|
|
15
|
+
import { DEV, useContext } from "solid-js"
|
|
16
|
+
import { type StageWard, type StageWardConfig, WardicStage } from "./stage.ts"
|
|
17
|
+
import { heldOf, internalsOf, type Ward, type WardConfig, type WardInternals, wardWith, type WardOptions } from "./ward.tsx"
|
|
18
|
+
|
|
19
|
+
/** No config: a ward that only listens. */
|
|
20
|
+
const NO_CONFIG: WardConfig = {}
|
|
21
|
+
|
|
22
|
+
/** A ward made Subject first on an element: the ward, with `held`. */
|
|
23
|
+
export type HeldWard<W> = W & { readonly held: JSX.Element }
|
|
24
|
+
|
|
25
|
+
/** Whether `value` is an element, by its `nodeType`. */
|
|
26
|
+
const isElement = (value: unknown): value is Element => Predicate.hasProperty(value, "nodeType")
|
|
27
|
+
|
|
28
|
+
/** Whether `value` carries a three.js-style flag, an own `is…` key set `true`: a scene's Subject, which needs a Stage. */
|
|
29
|
+
const isFlagged = (value: unknown): boolean =>
|
|
30
|
+
Predicate.isObject(value) && Arr.some(Rec.keys(value as Readonly<Record<string, unknown>>), (key) => /^is[A-Z]/.test(key) && (value as Readonly<Record<string, unknown>>)[key] === true)
|
|
31
|
+
|
|
32
|
+
/** A scene's Subject given to `ward` with no Stage above it. */
|
|
33
|
+
const NO_STAGE =
|
|
34
|
+
"ward(subject, config): its Subject is a scene's (an object with an `is…` flag, as three.js's are), and no <WardicStage> is above it. " +
|
|
35
|
+
"Give the scene's Stage to its tree, <WardicStage value={stage}>, or call the Stage itself, stage.ward(subject, config)."
|
|
36
|
+
|
|
37
|
+
/** `ward` made Subject first on `el`: `ward(config)(el)`, with `held`. */
|
|
38
|
+
const onElement = (el: Element, config: WardConfig, options: WardOptions | undefined, kind: WardInternals): HeldWard<Ward> => {
|
|
39
|
+
const made = wardWith(config, internalsOf(options, kind))
|
|
40
|
+
made(el as HTMLElement)
|
|
41
|
+
return Object.defineProperty(made, "held", { value: heldOf(made) }) as HeldWard<Ward>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** An accessor first with no Stage above: on the page, a ward given to `ref` follows each element. */
|
|
45
|
+
const NO_STAGE_ACCESSOR =
|
|
46
|
+
"ward(subject, config): an accessor Subject is a Stage's, and no <WardicStage> is above it. On the page, give the ward to the element's `ref`, which follows each element it's given: <div ref={card} />."
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The ward `ward(first, second, third)` makes for a `kind` of element (Complete or Slim): its Subject
|
|
50
|
+
* first, or its config.
|
|
51
|
+
*/
|
|
52
|
+
// Per ward made: plain checks, cheapest first, a config's path two of them and the context's read.
|
|
53
|
+
export const wardFrom = (first: unknown, second: unknown, third: unknown, kind: WardInternals): Ward | HeldWard<Ward> | StageWard => {
|
|
54
|
+
if (Predicate.isUndefined(first)) return wardWith(NO_CONFIG, internalsOf(second as WardOptions | undefined, kind))
|
|
55
|
+
if (isElement(first)) return onElement(first, second as WardConfig, third as WardOptions | undefined, kind)
|
|
56
|
+
// A whole accessor as the config, with nothing after it: the ward's own error (WHOLE_ACCESSOR) says so.
|
|
57
|
+
if (Predicate.isFunction(first) && Predicate.isUndefined(second)) return wardWith(first as WardConfig, internalsOf(undefined, kind))
|
|
58
|
+
const stage = useContext(WardicStage)
|
|
59
|
+
if (Predicate.isNotNull(stage)) {
|
|
60
|
+
if (Predicate.isFunction(first) || stage.isSubject(first)) return stage.ward(first, second as StageWardConfig, third as WardOptions | undefined)
|
|
61
|
+
}
|
|
62
|
+
// An accessor is a scene's Subject (ADR-0073 decision 10): a ward given to `ref` follows a page's
|
|
63
|
+
// elements. Said in development; in production the ward's own error for a function config is thrown.
|
|
64
|
+
if (DEV && Predicate.isFunction(first)) throw new Error(NO_STAGE_ACCESSOR)
|
|
65
|
+
if (DEV && isFlagged(first)) throw new Error(NO_STAGE)
|
|
66
|
+
return wardWith(first as WardConfig, internalsOf(second as WardOptions | undefined, kind))
|
|
67
|
+
}
|