@wardic/solid 3.0.0-next.0 → 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.
Files changed (163) hide show
  1. package/README.md +17 -0
  2. package/dist/browser/animation-frame.js +1 -1
  3. package/dist/browser/animation-frame.js.map +1 -1
  4. package/dist/browser/config-view.js +2 -1
  5. package/dist/browser/config-view.js.map +1 -1
  6. package/dist/browser/diagnostic-codes.js +236 -0
  7. package/dist/browser/diagnostic-codes.js.map +1 -0
  8. package/dist/browser/diagnostics.js +79 -0
  9. package/dist/browser/diagnostics.js.map +1 -0
  10. package/dist/browser/element.js +7 -6
  11. package/dist/browser/element.js.map +1 -1
  12. package/dist/browser/frame-effect.js +1 -1
  13. package/dist/browser/frame-effect.js.map +1 -1
  14. package/dist/browser/gesture-callbacks.js +1 -1
  15. package/dist/browser/gesture-callbacks.js.map +1 -1
  16. package/dist/browser/hooks/drag.js +4 -3
  17. package/dist/browser/hooks/drag.js.map +1 -1
  18. package/dist/browser/hooks/presence-scope.js +2 -1
  19. package/dist/browser/hooks/presence-scope.js.map +1 -1
  20. package/dist/browser/hooks/reorder-elements.js +5 -4
  21. package/dist/browser/hooks/reorder-elements.js.map +1 -1
  22. package/dist/browser/hooks/rune.js +4 -3
  23. package/dist/browser/hooks/rune.js.map +1 -1
  24. package/dist/browser/hooks/ward.js +75 -18
  25. package/dist/browser/hooks/ward.js.map +1 -1
  26. package/dist/browser/hooks/wards.js +3 -2
  27. package/dist/browser/hooks/wards.js.map +1 -1
  28. package/dist/browser/provider.js +40 -21
  29. package/dist/browser/provider.js.map +1 -1
  30. package/dist/browser/reorder.js +5 -4
  31. package/dist/browser/reorder.js.map +1 -1
  32. package/dist/browser/runtime.js +26 -15
  33. package/dist/browser/runtime.js.map +1 -1
  34. package/dist/browser/spans-check.js +8 -3
  35. package/dist/browser/spans-check.js.map +1 -1
  36. package/dist/browser/v1/index.js +1 -1
  37. package/dist/browser/ward.js +25 -19
  38. package/dist/browser/ward.js.map +1 -1
  39. package/dist/server/animation-frame.js +1 -1
  40. package/dist/server/animation-frame.js.map +1 -1
  41. package/dist/server/config-view.js +2 -1
  42. package/dist/server/config-view.js.map +1 -1
  43. package/dist/server/diagnostic-codes.js +236 -0
  44. package/dist/server/diagnostic-codes.js.map +1 -0
  45. package/dist/server/diagnostics.js +79 -0
  46. package/dist/server/diagnostics.js.map +1 -0
  47. package/dist/server/element.js +7 -6
  48. package/dist/server/element.js.map +1 -1
  49. package/dist/server/frame-effect.js +1 -1
  50. package/dist/server/frame-effect.js.map +1 -1
  51. package/dist/server/gesture-callbacks.js +1 -1
  52. package/dist/server/gesture-callbacks.js.map +1 -1
  53. package/dist/server/hooks/drag.js +4 -3
  54. package/dist/server/hooks/drag.js.map +1 -1
  55. package/dist/server/hooks/presence-scope.js +2 -1
  56. package/dist/server/hooks/presence-scope.js.map +1 -1
  57. package/dist/server/hooks/reorder-elements.js +5 -4
  58. package/dist/server/hooks/reorder-elements.js.map +1 -1
  59. package/dist/server/hooks/rune.js +4 -3
  60. package/dist/server/hooks/rune.js.map +1 -1
  61. package/dist/server/hooks/ward.js +75 -18
  62. package/dist/server/hooks/ward.js.map +1 -1
  63. package/dist/server/hooks/wards.js +3 -2
  64. package/dist/server/hooks/wards.js.map +1 -1
  65. package/dist/server/provider.js +40 -21
  66. package/dist/server/provider.js.map +1 -1
  67. package/dist/server/reorder.js +5 -4
  68. package/dist/server/reorder.js.map +1 -1
  69. package/dist/server/runtime.js +26 -15
  70. package/dist/server/runtime.js.map +1 -1
  71. package/dist/server/spans-check.js +8 -3
  72. package/dist/server/spans-check.js.map +1 -1
  73. package/dist/server/v1/index.js +1 -1
  74. package/dist/server/ward.js +25 -19
  75. package/dist/server/ward.js.map +1 -1
  76. package/dist/solid/animation-frame.js +1 -1
  77. package/dist/solid/animation-frame.js.map +1 -1
  78. package/dist/solid/config-view.d.ts.map +1 -1
  79. package/dist/solid/config-view.js +2 -1
  80. package/dist/solid/config-view.js.map +1 -1
  81. package/dist/solid/diagnostic-codes.d.ts +10 -0
  82. package/dist/solid/diagnostic-codes.d.ts.map +1 -0
  83. package/dist/solid/diagnostic-codes.js +268 -0
  84. package/dist/solid/diagnostic-codes.js.map +1 -0
  85. package/dist/solid/diagnostics.d.ts +33 -0
  86. package/dist/solid/diagnostics.d.ts.map +1 -0
  87. package/dist/solid/diagnostics.js +76 -0
  88. package/dist/solid/diagnostics.js.map +1 -0
  89. package/dist/solid/element.d.ts.map +1 -1
  90. package/dist/solid/element.jsx +8 -8
  91. package/dist/solid/element.jsx.map +1 -1
  92. package/dist/solid/frame-effect.jsx +1 -1
  93. package/dist/solid/frame-effect.jsx.map +1 -1
  94. package/dist/solid/gesture-callbacks.js +1 -1
  95. package/dist/solid/gesture-callbacks.js.map +1 -1
  96. package/dist/solid/hooks/drag.d.ts.map +1 -1
  97. package/dist/solid/hooks/drag.js +4 -3
  98. package/dist/solid/hooks/drag.js.map +1 -1
  99. package/dist/solid/hooks/presence-scope.d.ts +4 -3
  100. package/dist/solid/hooks/presence-scope.d.ts.map +1 -1
  101. package/dist/solid/hooks/presence-scope.jsx +2 -1
  102. package/dist/solid/hooks/presence-scope.jsx.map +1 -1
  103. package/dist/solid/hooks/reorder-elements.d.ts.map +1 -1
  104. package/dist/solid/hooks/reorder-elements.jsx +5 -4
  105. package/dist/solid/hooks/reorder-elements.jsx.map +1 -1
  106. package/dist/solid/hooks/rune.d.ts.map +1 -1
  107. package/dist/solid/hooks/rune.js +4 -3
  108. package/dist/solid/hooks/rune.js.map +1 -1
  109. package/dist/solid/hooks/ward.d.ts +5 -3
  110. package/dist/solid/hooks/ward.d.ts.map +1 -1
  111. package/dist/solid/hooks/ward.js +85 -20
  112. package/dist/solid/hooks/ward.js.map +1 -1
  113. package/dist/solid/hooks/wards.d.ts.map +1 -1
  114. package/dist/solid/hooks/wards.js +3 -2
  115. package/dist/solid/hooks/wards.js.map +1 -1
  116. package/dist/solid/provider.d.ts.map +1 -1
  117. package/dist/solid/provider.jsx +41 -21
  118. package/dist/solid/provider.jsx.map +1 -1
  119. package/dist/solid/reorder.d.ts.map +1 -1
  120. package/dist/solid/reorder.jsx +5 -4
  121. package/dist/solid/reorder.jsx.map +1 -1
  122. package/dist/solid/runtime.d.ts +20 -7
  123. package/dist/solid/runtime.d.ts.map +1 -1
  124. package/dist/solid/runtime.js +25 -14
  125. package/dist/solid/runtime.js.map +1 -1
  126. package/dist/solid/spans-check.d.ts +5 -1
  127. package/dist/solid/spans-check.d.ts.map +1 -1
  128. package/dist/solid/spans-check.js +8 -3
  129. package/dist/solid/spans-check.js.map +1 -1
  130. package/dist/solid/v1/index.d.ts +1 -1
  131. package/dist/solid/v1/index.jsx +1 -1
  132. package/dist/solid/ward.d.ts.map +1 -1
  133. package/dist/solid/ward.jsx +25 -19
  134. package/dist/solid/ward.jsx.map +1 -1
  135. package/package.json +8 -6
  136. package/skills/wardic-diagnostics/SKILL.md +553 -0
  137. package/skills/wardic-migrate/SKILL.md +252 -0
  138. package/skills/wardic-solid/SKILL.md +60 -0
  139. package/skills/wardic-solid/events.md +70 -0
  140. package/skills/wardic-solid/from-motion.md +59 -0
  141. package/skills/wardic-solid/lists-and-presence.md +112 -0
  142. package/skills/wardic-solid/reorder-and-grips.md +88 -0
  143. package/skills/wardic-solid/runes.md +151 -0
  144. package/skills/wardic-solid/scopes-and-settings.md +75 -0
  145. package/src/animation-frame.ts +1 -1
  146. package/src/config-view.ts +5 -1
  147. package/src/diagnostic-codes.ts +280 -0
  148. package/src/diagnostics.ts +88 -0
  149. package/src/element.tsx +13 -10
  150. package/src/frame-effect.tsx +1 -1
  151. package/src/gesture-callbacks.ts +1 -1
  152. package/src/hooks/drag.ts +4 -3
  153. package/src/hooks/presence-scope.tsx +6 -4
  154. package/src/hooks/reorder-elements.tsx +6 -4
  155. package/src/hooks/rune.ts +4 -3
  156. package/src/hooks/ward.ts +90 -21
  157. package/src/hooks/wards.ts +4 -2
  158. package/src/provider.tsx +43 -20
  159. package/src/reorder.tsx +5 -4
  160. package/src/runtime.ts +43 -13
  161. package/src/spans-check.ts +12 -3
  162. package/src/v1/index.tsx +1 -1
  163. package/src/ward.tsx +27 -19
@@ -0,0 +1,151 @@
1
+ # Runes
2
+
3
+ A ward is made of runes, each one job: a fade, a lift, a spring, a list's place. These rules hold for a rune in any Wardic binding; the examples are Solid's hooks. API: https://next.wardic.dev/reference/solid/hooks/runes
4
+
5
+ ## The rules
6
+
7
+ Each rule's tier says what catches it, as in SKILL.md: **type**, **code**, **runtime** (an error with no Wardic code), or **review**.
8
+
9
+ 1. **A rune says one thing, and has a name for it.** A behaviour's name is a verb (`fadesIn`, `risesIn`, `lifts`, `gives`, `travels`), a transition's an adjective (`springy`, `soft`, `slow`), a factory's what it gives (`card(index)`). No `Rune` suffix. Review.
10
+ 2. **A rune is a value; a setting makes it a function.** A rune that depends on nothing is a constant. One that takes a setting is a function that returns a rune: `spring(stiffness)`, `dragToClose(close)`. Review.
11
+ 3. **A rune is fixed once made.** Its keys are the ones it has as it's made, and a plain value in it (a target, a transition, its variants) is meant to stay as it is: the rune is frozen, so setting, adding or deleting a key throws, and in development the data inside it is frozen too. What changes is an accessor, a function or a getter, read where the ward reads it (`animate: () => ({ x: x() })`), or a store. To change a rune, make another, or give the key an accessor. Runtime: a `TypeError`, with no Wardic code.
12
+ 4. **A behaviour is a rune:** a function rune for what reads or listens to its ward, a `ref` for what it does to its Subject. Never a ward, and never a handler prop. Type, for a handler in a rune's `props`; review otherwise.
13
+ 5. **Wardic's words fit any host; an Environment's words are its own.** `initial`, `animate`, `exit`, `variants`, `transition`, the `while*` targets, `show`, `follow` and `followers` say motion whatever moves. A page's rune adds the page's (`style`, `layout`, `drag`, `ref`, `props`, `subject`, `tag`, `pop`): such a rune fits a page's ward only. Type: a key a ward doesn't take is an error at its `createWard`.
14
+
15
+ ## Writing one
16
+
17
+ ```tsx solid2
18
+ import { createRune, createWard } from "@wardic/solid/hooks"
19
+
20
+ const fadesIn = createRune({ initial: { opacity: 0 }, animate: { opacity: 1 } })
21
+ const lifts = createRune({ whileHover: { y: -4 } })
22
+ const springy = createRune({ transition: { type: "spring", stiffness: 400, damping: 28 } })
23
+
24
+ function Card() {
25
+ const card = createWard(fadesIn, lifts, springy)
26
+ return <article {...card} />
27
+ }
28
+ ```
29
+
30
+ - **`createRune(config)`** checks a config where it's written, so a rune kept in a constant is checked there. A config written in a ward's own call is checked by that call; a plain object is a rune too.
31
+ - **Where it's made** (SKILL.md's rule 4): a module for a constant; once in a hook for one over the hook's state; a function for each Subject for one over which Subject it's on.
32
+
33
+ ```tsx solid2
34
+ import { createSignal } from "solid-js"
35
+ import { createRune } from "@wardic/solid/hooks"
36
+
37
+ export function createDisclosure() {
38
+ const [open, setOpen] = createSignal(false)
39
+ // Made once, over the hook's state: every ward given it follows `open`.
40
+ const opens = createRune({ initial: "closed", animate: () => (open() ? "open" : "closed"), variants: { open: { opacity: 1, y: 0 }, closed: { opacity: 0, y: -8 } } })
41
+ return { open, toggle: () => setOpen((was) => !was), opens }
42
+ }
43
+ ```
44
+
45
+ ## How runes join
46
+
47
+ A ward's runes join key by key, a later rune winning:
48
+
49
+ - `initial`, `animate`, `exit`, the `while*` targets, `transition` and `style` merge their keys when both are objects.
50
+ - `variants` merge by name, then key by key.
51
+ - Anything else is the later rune's.
52
+ - Every rune's `ref` runs; none wins.
53
+ - `props` join name by name, a later rune's winning a name.
54
+
55
+ Give each key in one rune: a key several runes give is merged each time it changes.
56
+
57
+ ## Function runes
58
+
59
+ `createRune((ward) => config)` is a hook's body for each ward it's given to: called once for that ward, as it's made and under its owner, and returning that ward's config.
60
+
61
+ ```tsx solid2
62
+ import { createEffect } from "solid-js"
63
+ import { createRune } from "@wardic/solid/hooks"
64
+
65
+ const dragToClose = (close: () => void) =>
66
+ createRune((sheet) => {
67
+ createEffect(sheet.when("dragEnd"), (release) => {
68
+ if (release.offset.y > 120) close()
69
+ })
70
+ return { drag: "y", dragSnapToOrigin: true }
71
+ })
72
+ ```
73
+
74
+ - **Its ward's reads and events are the finished ward's:** `ward.hovering()`, `ward.exiting()`, `ward.when("exitComplete")`.
75
+ - **Read them where they're followed:** in a target's accessor, a `props` value, a memo, an effect. Read bare in the body, a read is read once, and too early is `WARDIC_RUNE_READ_TOO_EARLY`.
76
+ - **Its ward alone has `drag`,** what it hears of its drag: see [reorder-and-grips.md](reorder-and-grips.md).
77
+
78
+ ## `ref`: what a rune does to its Subject
79
+
80
+ ```tsx solid2
81
+ import { createRune } from "@wardic/solid/hooks"
82
+
83
+ const closesOnEscape = (close: () => void) =>
84
+ createRune({
85
+ ref: (subject) => {
86
+ const onKey = (event: KeyboardEvent) => {
87
+ if (event.key === "Escape") close()
88
+ }
89
+ subject.addEventListener("keydown", onKey)
90
+ return () => subject.removeEventListener("keydown", onKey)
91
+ },
92
+ })
93
+ ```
94
+
95
+ - **Handed its Subject alone,** once it's on the page. What it returns undoes it, once the Subject is off show.
96
+ - **Untracked, as Solid's `ref` is:** to follow a signal, make an effect in a function rune.
97
+ - **Its listener hears an event before the page's own handlers.** Take an event with `preventDefault()`, which they then see, never `stopPropagation()`; leave an event that began in a child alone (`event.target !== subject`).
98
+
99
+ ## `props`: what a rune sets on its Subject
100
+
101
+ ```tsx solid2
102
+ import { createRune } from "@wardic/solid/hooks"
103
+
104
+ const toggles = (on: () => boolean) => createRune({ props: { role: "switch", tabindex: 0, "data-on": on } })
105
+ ```
106
+
107
+ Attributes alone: a `role`, a `tabindex`, an `aria-` state, a `data-` mark, each a value or an accessor. A handler is a `ref`'s job; `style` and `ref` are a rune's own keys; a state is a `data-` attribute a stylesheet reads, not a `class`.
108
+
109
+ ## A rune with an API: `createRuneWith`
110
+
111
+ A utility of the app's own hands back one value that's a rune where a ward is given it, and an API where the app calls it:
112
+
113
+ ```tsx solid2
114
+ import { createSignal } from "solid-js"
115
+ import { createRuneWith } from "@wardic/solid/hooks"
116
+
117
+ export const createCarousel = (count: number) => {
118
+ const [index, setIndex] = createSignal(0)
119
+ return createRuneWith(
120
+ { get animate() { return { x: `${-index() * 100}%` } }, transition: { type: "spring", bounce: 0 } },
121
+ { index, next: () => setIndex((i) => Math.min(i + 1, count - 1)), prev: () => setIndex((i) => Math.max(i - 1, 0)) },
122
+ )
123
+ }
124
+ ```
125
+
126
+ The component makes the ward, `createWard({ drag: "x" }, carousel)`, and calls `carousel.next()` from its buttons. An API member named like one of the rune's keys is refused.
127
+
128
+ ## Followers
129
+
130
+ A ward takes another's variant names with `follow`, written where it's made, beside its leader. The leader times its followers with `followers`:
131
+
132
+ ```tsx solid2
133
+ import { createSignal } from "solid-js"
134
+ import { createRune, createWard } from "@wardic/solid/hooks"
135
+
136
+ const turns = createRune({ variants: { open: { rotate: 180 }, closed: { rotate: 0 } } })
137
+ const staggered = createRune({ followers: { stagger: 0.05 } })
138
+
139
+ function Disclosure() {
140
+ const [state, setState] = createSignal<"open" | "closed">("closed")
141
+ const panel = createWard({ initial: "closed", animate: state }, staggered)
142
+ const chevron = createWard({ follow: panel }, turns)
143
+ return (
144
+ <section {...panel}>
145
+ <button onClick={() => setState((was) => (was === "open" ? "closed" : "open"))}>
146
+ <span {...chevron}>⌄</span>
147
+ </button>
148
+ </section>
149
+ )
150
+ }
151
+ ```
@@ -0,0 +1,75 @@
1
+ # Scopes and settings
2
+
3
+ API: https://next.wardic.dev/reference/solid/hooks/scopes and https://next.wardic.dev/reference/solid/hooks/make-ward
4
+
5
+ ## Nothing is set up
6
+
7
+ Importing `@wardic/solid/hooks` gives the page the DOM's Environment, `DomLive`, and every setting at its default. Each ward brings the Features its own config uses (hover, press, focus, inView, pan, drag, layout, colors), each a module fetched the first time a ward asks for it. No provider and no list of Features. A ward's `when("ready")` says when its Features are all there.
8
+
9
+ | Need | Reach for |
10
+ | --- | --- |
11
+ | Settings for the whole page: a default `transition`, `reducedMotion`, `appear`, `nonce`, `strict` | `setupWard({ … })`, once, in a module that loads before anything renders |
12
+ | Features at once, in the page's own bundle, with nothing loaded later | `makeWard({ features, … })`, once, in a module of its own; its `createWard` and `createWards` bring them |
13
+ | Settings for some wards: a default `transition`, `reducedMotion`, `skipAnimations` | `createConfigScope({ … })` |
14
+ | `layoutId`s that two copies of a component keep apart | `createLayoutGroup(id)` |
15
+ | A page of its own inside the page: a test's Environment, an embedded widget | `createWardicScope({ env, features })` |
16
+
17
+ `<WardicProvider>`, `<WardicConfig>` and `<LayoutGroup>` are utilities over these, for code written that way; new code uses the hooks.
18
+
19
+ ## `make*` once, in a module; `create*` in a component
20
+
21
+ ```tsx solid2
22
+ // src/lib/wardic.ts
23
+ import { domAnimation } from "@wardic/solid"
24
+ import { makeWard } from "@wardic/solid/hooks"
25
+
26
+ export const wardic = makeWard({ features: domAnimation, strict: true })
27
+ export const { createWard, createWards } = wardic
28
+ ```
29
+
30
+ Components then import `createWard` from that module. `wardic.with(layout)` makes the same hooks with more Features, for a module only some pages import. A page with settings and no Features calls `setupWard` instead.
31
+
32
+ ## A scope builds what's inside it: `within`
33
+
34
+ A Solid 2 component has no owner of its own, so a context set from its body would land on the owner around it and on every sibling after it. A scope is a value with `within(build)`, Solid's own provider round what it builds: every ward made in `build`, at any depth, is in the scope.
35
+
36
+ A config scope and a layout group are runes too, for a ward made beside them in the same body, which isn't inside their `within`:
37
+
38
+ ```tsx solid2
39
+ import { createConfigScope, createRune, createWard } from "@wardic/solid/hooks"
40
+
41
+ const calm = createConfigScope({ transition: { type: "tween", duration: 0.6 } })
42
+ const lifts = createRune({ whileHover: { y: -4 } })
43
+
44
+ function Shelf() {
45
+ // This ward, by the scope as a rune; every ward made in `within`, by the scope around it.
46
+ const title = createWard(calm, lifts)
47
+ return (
48
+ <section>
49
+ <h2 {...title}>New in</h2>
50
+ {calm.within(() => <Cards />)}
51
+ </section>
52
+ )
53
+ }
54
+ ```
55
+
56
+ - **Given as a rune, write the scope first:** a later rune's key wins, so `createWard(calm, { transition: fast })` keeps `fast`.
57
+ - **A ward's own key beats every scope it's inside.**
58
+ - **A layout group puts a ward's `layoutId` in its namespace:** `createWard(tabs, { layoutId: "underline" })`.
59
+
60
+ ```tsx solid2
61
+ import { createLayoutGroup, createWard } from "@wardic/solid/hooks"
62
+
63
+ function TabBar() {
64
+ const tabs = createLayoutGroup("tabs")
65
+ const underline = createWard(tabs, { layoutId: "underline" })
66
+ return (
67
+ <nav>
68
+ {tabs.within(() => <Tabs />)}
69
+ <span {...underline} />
70
+ </nav>
71
+ )
72
+ }
73
+ ```
74
+
75
+ - **A Wardic scope is no rune:** a ward is made in it, not given it. Nothing from around it reaches its wards: neither the page's settings nor a config scope's.
@@ -26,7 +26,7 @@ export const eachFrameOf = (runtime: WardicRuntime, callback: (time: number, del
26
26
  } catch (defect) {
27
27
  if (failing) return
28
28
  failing = true
29
- runtime.runFork(Report.failure("wardic.createAnimationFrame: the callback failed", Cause.die(defect)))
29
+ runtime.runFork(Report.callbackFailed("wardic.createAnimationFrame: the callback failed", Cause.die(defect)))
30
30
  }
31
31
  })
32
32
  }
@@ -27,6 +27,7 @@ import * as Predicate from "effect/Predicate"
27
27
  import * as UndefinedOr from "effect/UndefinedOr"
28
28
  import { latest, NotReadyError, runWithOwner, untrack } from "solid-js"
29
29
  import type { Accessor } from "solid-js"
30
+ import { misuse } from "./diagnostics.ts"
30
31
 
31
32
  /**
32
33
  * A config whose keys may each be an accessor (#259): a key's value, or a function returning it,
@@ -119,7 +120,10 @@ const NONE_PENDING: ReadonlyArray<never> = []
119
120
 
120
121
  /** The error for an accessor that returned a promise (#257 item 1, Q3). */
121
122
  const promiseError = (key: string): Error =>
122
- new Error(`\`${key}\`'s accessor returned a promise: give it an async memo instead, \`${key}: createMemo(() => …)\`. An accessor is called at every read of its key, so it would fetch at each.`)
123
+ misuse(
124
+ "WARDIC_ACCESSOR_RETURNED_PROMISE",
125
+ `\`${key}\`'s accessor returned a promise: give it an async memo instead, \`${key}: createMemo(() => …)\`. An accessor is called at every read of its key, so it would fetch at each.`,
126
+ )
123
127
 
124
128
 
125
129
  /**
@@ -0,0 +1,280 @@
1
+ /**
2
+ * The Solid binding's coded diagnostics (solid-next, the skill grill's Q12, Q18): each code it reports
3
+ * (`report` and `misuse`, `./diagnostics.ts`), with what the docs and the `wardic-diagnostics` skill
4
+ * say of it, both generated from here by `scripts/diagnostics.ts`. Imported by nothing an app runs.
5
+ *
6
+ * @module
7
+ */
8
+ import type * as Diagnostic from "@wardic/core/unstable/Diagnostic"
9
+
10
+ export const CODES: ReadonlyArray<Diagnostic.Entry> = [
11
+ {
12
+ code: "WARDIC_GRIP_ROW_DOESNT_DRAG",
13
+ group: "Grips and reorder",
14
+ summary: "A grip was made for a ward that doesn't drag.",
15
+ why: "A grip starts its row's drag: a press on it is one the row's drag hears. A row with no `drag` has no drag to start, so the grip does nothing, and the row can't be moved by it.",
16
+ repair: "Give the row `drag` (`createRune({ drag: \"y\" })`), or a behaviour rune whose ward drags, such as a `createReorder` list's `list.item(value)`. If the row isn't meant to move, give it no grip.",
17
+ example: {
18
+ before: 'import { createGrip, createWard } from "@wardic/solid/hooks"\n\nconst row = createWard(fadesIn)\nconst grip = createWard(createGrip(row as never))',
19
+ after: 'import { createGrip, createWard } from "@wardic/solid/hooks"\n\nconst row = createWard(fadesIn, list.item(value))\nconst grip = createWard(createGrip(row))',
20
+ },
21
+ notes: ["The behaviour-runes grill's Q14, Q20"],
22
+ },
23
+ {
24
+ code: "WARDIC_WARD_ON_TWO_SUBJECTS",
25
+ group: "Refs and spread",
26
+ summary: "One ward was spread on, or given to, a second element while the first is still on the page.",
27
+ why: "A ward drives one Subject at a time: its values, its gestures and its exits are that Subject's. Two elements on one ward would fight over them, so Wardic refuses the second.",
28
+ repair: "Make one ward for each element, where each is drawn: in the `<For>` callback, or in a component of its own. A ward that moves from one element to the next, the first gone before the second arrives, is fine.",
29
+ example: {
30
+ before: 'import { createWard } from "@wardic/solid/hooks"\n\nconst card = createWard(fadesIn)\n<div {...card} />\n<div {...card} />',
31
+ after: 'import { createWard } from "@wardic/solid/hooks"\n\nfunction Card() {\n const card = createWard(fadesIn)\n return <div {...card} />\n}',
32
+ },
33
+ notes: ["#349's Q5"],
34
+ },
35
+ {
36
+ code: "WARDIC_REF_NOT_CALLED",
37
+ group: "Refs and spread",
38
+ summary: "A ward was spread on a component that never called its `ref`, so no element is its Subject.",
39
+ why: "A ward finds its Subject through the `ref` in its spread. A component that takes the spread but doesn't pass `ref` on to the element it renders leaves the ward with nothing to move: nothing it says moves anything.",
40
+ repair: "In the component, pass `props.ref` to the element it renders (`<div ref={props.ref}>`), or spread its props on that element whole. Or spread the ward on an element of your own.",
41
+ example: {
42
+ before: "function Card(props) {\n return <div class=\"card\">{props.children}</div>\n}\n<Card {...card} />",
43
+ after: "function Card(props: { ref?: (el: HTMLElement) => void; children?: unknown }) {\n return <div class=\"card\" ref={props.ref}>{props.children as never}</div>\n}",
44
+ },
45
+ },
46
+ {
47
+ code: "WARDIC_SUBJECT_NOT_ONE_ELEMENT",
48
+ group: "Refs and spread",
49
+ summary: "A rune's `subject` didn't resolve to one element.",
50
+ why: "A ward moves one Subject. A `subject` that resolves to nothing, to text, or to several elements leaves it nothing it can drive.",
51
+ repair: "Give `subject` the one element the ward should move, or an accessor of it, or leave `subject` out and spread the ward on that element.",
52
+ },
53
+ {
54
+ code: "WARDIC_PRESENCE_WARD_HAS_SHOW",
55
+ group: "Presence",
56
+ summary: "`createPresence(ward, value)` was given a ward that has a `show` of its own, or is a list's row.",
57
+ why: "A presence decides when its ward is on the page and when it leaves. A ward with its own `show`, or a row that its list shows, already has something deciding that, and the two would fight.",
58
+ repair: "Make a ward for the presence alone, with no `show`, and let the presence show it. A list's rows leave by their list: use `createWards` for a list.",
59
+ },
60
+ {
61
+ code: "WARDIC_PRESENCE_WARD_TAKEN",
62
+ group: "Presence",
63
+ summary: "A ward given to `createPresence` already has a presence.",
64
+ why: "A presence drives its ward's coming and going. Two presences on one ward would each try to show and remove it.",
65
+ repair: "Make a ward for each presence.",
66
+ example: {
67
+ before: 'import { createPresence, createWard } from "@wardic/solid/hooks"\n\nconst panel = createWard(fadesIn)\nconst a = createPresence(panel, open)\nconst b = createPresence(panel, other)',
68
+ after: 'import { createPresence, createWard } from "@wardic/solid/hooks"\n\nconst a = createPresence(createWard(fadesIn), open)\nconst b = createPresence(createWard(fadesIn), other)',
69
+ },
70
+ },
71
+ {
72
+ code: "WARDIC_PRESENCE_SCOPE_REUSED",
73
+ group: "Presence",
74
+ summary: "A presence scope's `within` was used round a second boundary while the first is still on the page.",
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
+ repair: "Make a scope for each boundary, with `createPresenceScope` where each is drawn.",
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
+ },
104
+ {
105
+ code: "WARDIC_FOLLOW_LEADER_UNNAMED",
106
+ group: "Follow, variants and config",
107
+ summary: "A ward follows a leader that names no states.",
108
+ why: "A follower takes its leader's variant names for the values it doesn't set. A leader whose `animate` and `initial` are values, not names, has no names to give, so the follower's own `variants` never play.",
109
+ repair: "Give the leader `variants` and name its states in `animate` (`animate: \"open\"`), or give the follower values of its own instead of following.",
110
+ example: {
111
+ before: 'import { createWard } from "@wardic/solid/hooks"\n\nconst panel = createWard({ animate: { opacity: 1 } })\nconst chevron = createWard({ follow: panel, variants: { open: { rotate: 180 } } })',
112
+ after: 'import { createWard } from "@wardic/solid/hooks"\n\nconst panel = createWard({ variants: { open: { opacity: 1 } }, animate: "open" })\nconst chevron = createWard({ follow: panel, variants: { open: { rotate: 180 } } })',
113
+ },
114
+ notes: ["The follow grill's Q2, Q6"],
115
+ },
116
+ {
117
+ code: "WARDIC_GRIP_OUTSIDE_ROW",
118
+ group: "Grips and reorder",
119
+ summary: "A grip was rendered outside its row's Subject.",
120
+ why: "A press on a grip reaches its row's drag through the row's Subject. A grip outside it can't start the drag, and while it's on the page the row drags from its grips alone, so the row can't be dragged at all.",
121
+ repair: "Render the grip inside its row's Subject, as one of its children.",
122
+ },
123
+ {
124
+ code: "WARDIC_DRAG_NOT_GIVEN",
125
+ group: "Grips and reorder",
126
+ summary: "A rune listens to `ward.drag`, but nothing gives the ward a `drag`.",
127
+ why: "`ward.drag`'s samples, keys and measured box are a dragging ward's. With no `drag` key, the ward never drags, so the behaviour listening to it never hears a sample.",
128
+ repair: "Give the ward `drag` (`createRune({ drag: \"x\" })`), or have the behaviour return `drag` in the rune it makes.",
129
+ notes: ["The behaviour-runes grill's Q19"],
130
+ },
131
+ {
132
+ code: "WARDIC_COMPLETE_UNDER_STRICT",
133
+ group: "Features",
134
+ summary: "A Complete element (`wardic.*`, `wardic.create`, `ward()`) was rendered where `strict` is on.",
135
+ why: "A Complete element brings every Feature's code with it, whatever it uses. `strict` says the page ships only the Features its elements ask for, so a Complete element under it would undo that.",
136
+ repair: "Use the hooks (`createWard`), which bring only the Features a ward's config uses, or a Slim element (`w.*`, `w.create`, `w.ward()`). Or leave `strict` off.",
137
+ notes: ["#511, ADR-0067 decision 7"],
138
+ },
139
+ {
140
+ code: "WARDIC_FEATURE_MISSING",
141
+ group: "Features",
142
+ summary: "An element uses something that needs a Feature its provider wasn't given: a layout prop, a gesture, or a wide-gamut colour.",
143
+ why: "A Slim element (`w.*`, `w.create`) or a `makeWard` instance brings only the Features it's given, so the page ships only their code. A key that needs one it wasn't given does nothing: the layout doesn't animate, the gesture isn't heard, the colour isn't read as one.",
144
+ repair: "Import the Feature the message names and give it to the provider (`<WardicProvider features={[layout]}>`) or to `makeWard({ features })`.",
145
+ notes: ["#511, ADR-0067 decision 7"],
146
+ },
147
+ {
148
+ code: "WARDIC_HOOK_WARD_IN_WARDREF",
149
+ group: "Refs and spread",
150
+ summary: "A ward `createWard` made was given to a component's `wardRef`.",
151
+ why: "`wardRef` drives a ward made with `ward(config)`, or calls a function with the component's own ward. A hooks ward finds its Subject by its spread, so given to `wardRef` it never would, and nothing it says would move.",
152
+ repair: "Spread the ward on the element (`{...ward}`), or on a component that forwards its `ref`.",
153
+ },
154
+ {
155
+ code: "WARDIC_REF_NOT_FORWARDED",
156
+ group: "Refs and spread",
157
+ summary: "A component wrapped by `w.create` or `wardic.create` didn't forward its `ref`.",
158
+ why: "The wrapper reaches the element it animates through the component's `ref`. A component that doesn't pass `ref` on to the element it renders gives it nothing to animate.",
159
+ repair: "Pass `props.ref` to the element the component renders, or spread its props on that element whole.",
160
+ },
161
+ {
162
+ code: "WARDIC_WARDREF_CONFLICT",
163
+ group: "Refs and spread",
164
+ summary: "A ward given to `wardRef` and its element disagree: a key set on both, variants on the ward with its keys on the element, or the ward made outside the element's variant parent.",
165
+ why: "A ward given to `wardRef` and the element it's on make one config. A key set in both places, or a ward's variants split from the keys that read them, leaves it unclear which wins.",
166
+ repair: "Set each key in one place: in `ward({ … })`, or on the element. A ward with variants takes its variant keys too. A ward made outside its element's variant parent names it with `ward(config, { parent })`, or stands alone with `inherit: false`.",
167
+ notes: ["#349, #398"],
168
+ },
169
+ {
170
+ code: "WARDIC_WARD_MADE_IN_SPREAD",
171
+ group: "Refs and spread",
172
+ summary: "`ward(config)` was called inside a spread, so a new ward was made each time the element's props ran.",
173
+ why: "Solid 2 runs a spread's expression again on every run of the element's props. A ward made there is a new ward each time, and the one before it is lost mid-animation.",
174
+ repair: "Make the ward once, in the component's body, and spread that: `const card = ward(config)`, then `<div {...card} />`.",
175
+ },
176
+ {
177
+ code: "WARDIC_RUNE_READ_TOO_EARLY",
178
+ group: "Refs and spread",
179
+ summary: "A function rune used a member of its ward in the rune's body, before the ward was made.",
180
+ why: "A ward is made from all its runes, so it doesn't exist while one of them is still running. A member of it read there has nothing to read yet.",
181
+ repair: "Use the member where the ward is rendered, or in an effect or a callback the rune sets up, which run once the ward is made.",
182
+ },
183
+ {
184
+ code: "WARDIC_PARENT_WITHOUT_VARIANTS",
185
+ group: "Follow, variants and config",
186
+ summary: "`ward(config, { parent })` named a parent that carries no variants.",
187
+ why: "A child joins its parent's variants through the parent's variant node. A parent with no `variants` or `inherit` in its config only listens: its element's props hold its variants, so there's nothing for the child to join by `{ parent }`.",
188
+ repair: "Render the child inside that ward's element, where it joins through the tree, or put the variants in the parent's `ward({ … })`.",
189
+ notes: ["#398"],
190
+ },
191
+ {
192
+ code: "WARDIC_CONFIG_AS_ACCESSOR",
193
+ group: "Follow, variants and config",
194
+ summary: "A whole config was given as one accessor (`ward(() => ({ … }))`).",
195
+ why: "A config is read key by key, so each key follows its own source. One accessor for all of it would make every key rerun whenever any of them changed.",
196
+ repair: "Give the config as an object and make the keys that change reactive one at a time: `ward({ animate: () => ({ x: x() }) })`, a getter, a store or a component's props.",
197
+ notes: ["#259"],
198
+ },
199
+ {
200
+ code: "WARDIC_KEY_LOADING_AT_SETUP",
201
+ group: "Follow, variants and config",
202
+ summary: "A key was still loading when its ward was made.",
203
+ why: "A ward reads some keys once, as it's made: where it starts, and what it's set up with. A key whose async source hasn't resolved has nothing to read then.",
204
+ repair: "Give the key a value to start from, such as an `initial`, or make the ward once its data is in, inside the `<Loading>` that waits for it.",
205
+ notes: ["#257 item 1"],
206
+ },
207
+ {
208
+ code: "WARDIC_ACCESSOR_RETURNED_PROMISE",
209
+ group: "Follow, variants and config",
210
+ summary: "A key's accessor returned a promise.",
211
+ why: "An accessor is called at every read of its key, so one that fetches would fetch at each read. A ward can't animate to a promise either.",
212
+ repair: "Give the key an async memo, `key: createMemo(() => …)`, which fetches once and holds the value it resolves to.",
213
+ },
214
+ {
215
+ code: "WARDIC_RUNE_WITH_INVALID",
216
+ group: "Follow, variants and config",
217
+ summary: "`createRuneWith(rune, api)` was given something it can't carry: a rune that already carries an API, a bare function, or an API member named like one of the rune's keys.",
218
+ why: "`createRuneWith` joins one rune and one API into a value that's both. A second API would hide the first, a bare function isn't a rune a ward can read, and an API member named like a rune key would hide that key from the ward.",
219
+ repair: "Give it the rune as written, with one API that has every member. Write a behaviour as `createRune((ward) => …)`. Give an API member that clashes another name.",
220
+ },
221
+ {
222
+ code: "WARDIC_REORDER_REF_NOT_FUNCTION",
223
+ group: "Grips and reorder",
224
+ summary: "`<Reorder.Group>`'s `groupRef` or `<Reorder.Item>`'s `wardRef` was given a group or ward made beforehand.",
225
+ why: "These take a function the component calls with the group or ward it makes. A group or ward made beforehand isn't one the component can drive.",
226
+ repair: "Give the config as the component's props, and a function to `groupRef` or `wardRef` to be handed what it makes: `wardRef={(row) => …}`.",
227
+ },
228
+ {
229
+ code: "WARDIC_REORDER_ITEM_OUTSIDE_GROUP",
230
+ group: "Grips and reorder",
231
+ summary: "A `<Reorder.Item>` was rendered outside a `<Reorder.Group>`, or a `<Reorder.Grip>` outside a `<Reorder.Item>`.",
232
+ why: "An item finds its list through its group, and a grip its row through its item. Outside them there's no list to reorder in, or no row to drag.",
233
+ repair: "Render each item among its group's children, and each grip among its item's.",
234
+ },
235
+ {
236
+ code: "WARDIC_WARD_WITHOUT_OWNER",
237
+ group: "Refs and spread",
238
+ summary: "`createWard` was called with no owner: outside a component or a root, at a module's top or in an event handler.",
239
+ why: "A ward lives as long as the component it's made in, and ends with it. Made with no owner, nothing would end it, and it couldn't find the provider or the page around it.",
240
+ repair: "Make the ward in the component that draws its Subject, and spread it there. A hook that holds state gives runes, which the component makes its ward of.",
241
+ example: {
242
+ before: 'import { createWard } from "@wardic/solid/hooks"\n\nconst card = createWard({ animate: { opacity: 1 } })\n\nexport const Card = () => <div {...card} />',
243
+ after: 'import { createWard } from "@wardic/solid/hooks"\n\nexport const Card = () => {\n const card = createWard({ animate: { opacity: 1 } })\n return <div {...card} />\n}',
244
+ },
245
+ },
246
+ {
247
+ code: "WARDIC_STYLE_BESIDE_SPREAD",
248
+ group: "Refs and spread",
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 })`.",
252
+ example: {
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}',
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}',
255
+ },
256
+ },
257
+ {
258
+ code: "WARDIC_NO_PROVIDER",
259
+ group: "Runtime and page",
260
+ summary: "Something that reads Wardic's runtime (`useWardicRuntime`, `useAnimateLayout`, …) was called with no `<WardicProvider>` above it and no page set up.",
261
+ why: "It reads what a provider makes, or the page the hooks set up: its Effect runtime, its Features, its layout system. The hooks set the page up as they're imported, so an app that never imports them, on the 2.x components alone, has neither until it renders a provider.",
262
+ repair: "Set the page up with no provider: importing `@wardic/solid/hooks` does, with `DomLive`, and `setupWard({ env })` from it gives it your own. Or render the component inside a `<WardicProvider env={DomLive}>`; `createWardicScope({ env }).within(…)` gives part of the page its own.",
263
+ },
264
+ {
265
+ code: "WARDIC_ENV_ASYNC",
266
+ group: "Runtime and page",
267
+ summary: "The `env` given to a `<WardicProvider>` waits as it builds.",
268
+ why: "A provider builds its `env` at once, as its first element renders. A Layer that waits as it builds, such as `DevTools.layer()` waiting for its connection, can't be built there.",
269
+ repair: "Build the Layer that waits before the app renders, and give its services in the `env`: `Layer.succeedContext(await Effect.runPromise(Layer.buildWithScope(layer, scope)))`.",
270
+ notes: ["#746"],
271
+ },
272
+ {
273
+ code: "WARDIC_TRACER_WITHOUT_SPANS",
274
+ group: "Runtime and page",
275
+ summary: "The `env` installs a tracer, but gives no `WardicSpans`, so Wardic opens no spans.",
276
+ why: "Wardic's spans are the app's to give: `WardicSpans` opens them under the tracer installed. Without it, the tracer sees none of Wardic's animations.",
277
+ repair: "Merge `WardicSpans` beside the Environment, `Layer.mergeAll(DomLive, WardicSpans, …)`, or leave the tracer out if Wardic's spans aren't wanted.",
278
+ notes: ["#746, ADR-0067 decision 8"],
279
+ },
280
+ ]
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Wardic's coded diagnostics on Solid 2 (solid-next, the skill grill's Q6, Q17 and Q21): a broken rule is
3
+ * reported as Solid reports its own. In development it goes on Solid's channel (`OBSERVE.diagnostics`),
4
+ * under the owner it happened in, where `@solidjs/diagnostics`' `captureArtifact` reads it, and it's
5
+ * printed: `[WARDIC_…]` and what happened with its fix, the owners it happened under, and on its code's
6
+ * first report a footer naming its page on next.wardic.dev and its section in the `wardic-diagnostics`
7
+ * skill. Solid's own printer isn't used: its footer names Solid's docs and Solid's skill. A production
8
+ * build has no channel, and reports nothing.
9
+ *
10
+ * @module
11
+ */
12
+ import * as Diagnostic from "@wardic/core/unstable/Diagnostic"
13
+ import * as Effect from "effect/Effect"
14
+ import * as Layer from "effect/Layer"
15
+ import * as UndefinedOr from "effect/UndefinedOr"
16
+ import { DEV, type DiagnosticCode, type DiagnosticEvent, getOwner, OBSERVE } from "solid-js"
17
+
18
+ /** A Wardic diagnostic's code: `WARDIC_` and what happened, core's, dom's or the binding's own. */
19
+ export type Code = Diagnostic.Code
20
+
21
+ /** Where a code's page is, by the code in lowercase. */
22
+ const DOCS = "https://next.wardic.dev/diagnostics/"
23
+
24
+ /** Where a code's section is in the skill the package ships, by the code in lowercase. */
25
+ const SKILL = "node_modules/@wardic/solid/skills/wardic-diagnostics/SKILL.md#"
26
+
27
+ // Module state (#460, Q7): the codes whose first report has printed the footer, once a page, as Solid's footer
28
+ // is: development's alone, as `report` and `misuse` print nothing else, and a page's for its life.
29
+ const footered = new Set<string>()
30
+
31
+ /** A coded report's first line, what happened and its fix: what a thrown misuse says too. */
32
+ const coded = (code: Code, message: string): string => Diagnostic.line(code, message)
33
+
34
+ /** A code's footer, on its first report alone: its page, and its section in the skill. */
35
+ const footerOf = (code: Code): ReadonlyArray<string> => {
36
+ if (footered.has(code)) return []
37
+ footered.add(code)
38
+ const anchor = code.toLowerCase()
39
+ return [` What it means and how to fix it: ${DOCS}${anchor}`, ` For a coding agent: ${SKILL}${anchor}`]
40
+ }
41
+
42
+ /** What's printed for `event`: its line, its owners and where, and its code's footer the first time. */
43
+ const printedOf = (code: Code, event: DiagnosticEvent): string =>
44
+ [
45
+ event.message,
46
+ ...UndefinedOr.match(event.ownerPath, { onUndefined: () => [], onDefined: (path) => [` in ${path.join(" › ")}`] }),
47
+ ...UndefinedOr.match(event.loc, { onUndefined: () => [], onDefined: (loc) => [` at ${loc}`] }),
48
+ ...footerOf(code),
49
+ ].join("\n")
50
+
51
+ /**
52
+ * `code` on Solid's channel, under the current owner, at `warn` (Solid prints an `error` with its own
53
+ * footer, which names its docs and its skill), and what's printed for it. Development's alone.
54
+ */
55
+ const emittedInDev = (code: Code, message: string): string =>
56
+ UndefinedOr.match(OBSERVE, {
57
+ onUndefined: () => coded(code, message),
58
+ // Solid's codes are a closed list: a Wardic one is carried as one of its own.
59
+ onDefined: (observe) =>
60
+ printedOf(code, observe.diagnostics.emit({ code: code as unknown as DiagnosticCode, kind: "render", severity: "warn", message: coded(code, message) }, getOwner())),
61
+ })
62
+
63
+ /**
64
+ * Reports `code` in development, `message` saying what happened and its fix: on Solid's channel, under
65
+ * the current owner, and printed. Nothing in production: under `DEV`, which Solid's production build
66
+ * leaves undefined, so a bundle drops it, the footer's text with it.
67
+ */
68
+ export const report = (code: Code, message: string): void => {
69
+ if (DEV) console.warn(emittedInDev(code, message))
70
+ }
71
+
72
+ /**
73
+ * The binding's reporter, for what core and dom report on the runtime it builds (`Diagnostic.report`):
74
+ * on Solid's channel and printed, as the binding's own are. Under no owner: it runs from a fiber.
75
+ */
76
+ export const reporterLayer: Layer.Layer<never> = Layer.succeed(Diagnostic.Reporter, {
77
+ report: (code, message) => Effect.sync(() => report(code, message)),
78
+ })
79
+
80
+ /**
81
+ * A misuse that throws: on Solid's channel in development, as {@link report} puts one, and the error to
82
+ * throw, its message `code`'s line, with its owners and its code's footer the first time. In production,
83
+ * the line alone.
84
+ */
85
+ export const misuse = (code: Code, message: string): Error => {
86
+ if (DEV) return new Error(emittedInDev(code, message))
87
+ return new Error(coded(code, message))
88
+ }