@wardic/dom 1.1.2 → 1.1.4

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 (74) hide show
  1. package/dist/ReorderController.d.ts +12 -1
  2. package/dist/ReorderController.d.ts.map +1 -1
  3. package/dist/ReorderController.js +25 -2
  4. package/dist/ReorderController.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/internal/appear.d.ts +7 -2
  8. package/dist/internal/appear.d.ts.map +1 -1
  9. package/dist/internal/appear.js +2 -2
  10. package/dist/internal/appear.js.map +1 -1
  11. package/dist/internal/clock.d.ts +3 -0
  12. package/dist/internal/clock.d.ts.map +1 -1
  13. package/dist/internal/clock.js +3 -0
  14. package/dist/internal/clock.js.map +1 -1
  15. package/dist/internal/reorder.d.ts +3 -0
  16. package/dist/internal/reorder.d.ts.map +1 -1
  17. package/dist/internal/reorder.js +1 -1
  18. package/dist/internal/reorder.js.map +1 -1
  19. package/dist/unstable/AppearAnimations.d.ts +14 -1
  20. package/dist/unstable/AppearAnimations.d.ts.map +1 -1
  21. package/dist/unstable/AppearAnimations.js +16 -3
  22. package/dist/unstable/AppearAnimations.js.map +1 -1
  23. package/dist/unstable/DragDefaults.d.ts +6 -5
  24. package/dist/unstable/DragDefaults.d.ts.map +1 -1
  25. package/dist/unstable/DragDefaults.js +2 -6
  26. package/dist/unstable/DragDefaults.js.map +1 -1
  27. package/dist/unstable/DragTrack.d.ts +8 -0
  28. package/dist/unstable/DragTrack.d.ts.map +1 -1
  29. package/dist/unstable/DragTrack.js +17 -0
  30. package/dist/unstable/DragTrack.js.map +1 -1
  31. package/dist/unstable/ElementSetup.d.ts +8 -2
  32. package/dist/unstable/ElementSetup.d.ts.map +1 -1
  33. package/dist/unstable/ElementSetup.js +14 -2
  34. package/dist/unstable/ElementSetup.js.map +1 -1
  35. package/dist/unstable/Feature.d.ts +5 -4
  36. package/dist/unstable/Feature.d.ts.map +1 -1
  37. package/dist/unstable/Feature.js +7 -4
  38. package/dist/unstable/Feature.js.map +1 -1
  39. package/dist/unstable/GestureFeatures.d.ts +132 -3
  40. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  41. package/dist/unstable/GestureFeatures.js +189 -11
  42. package/dist/unstable/GestureFeatures.js.map +1 -1
  43. package/dist/unstable/Imperative.d.ts +11 -0
  44. package/dist/unstable/Imperative.d.ts.map +1 -1
  45. package/dist/unstable/Imperative.js +37 -7
  46. package/dist/unstable/Imperative.js.map +1 -1
  47. package/dist/unstable/InstanceFeatures.d.ts +7 -0
  48. package/dist/unstable/InstanceFeatures.d.ts.map +1 -0
  49. package/dist/unstable/InstanceFeatures.js +69 -0
  50. package/dist/unstable/InstanceFeatures.js.map +1 -0
  51. package/dist/unstable/PagePoint.d.ts +43 -0
  52. package/dist/unstable/PagePoint.d.ts.map +1 -0
  53. package/dist/unstable/PagePoint.js +119 -0
  54. package/dist/unstable/PagePoint.js.map +1 -0
  55. package/dist/unstable/ReorderInput.d.ts +45 -0
  56. package/dist/unstable/ReorderInput.d.ts.map +1 -0
  57. package/dist/unstable/ReorderInput.js +116 -0
  58. package/dist/unstable/ReorderInput.js.map +1 -0
  59. package/package.json +3 -3
  60. package/src/ReorderController.ts +34 -1
  61. package/src/index.ts +1 -1
  62. package/src/internal/appear.ts +9 -4
  63. package/src/internal/clock.ts +3 -0
  64. package/src/internal/reorder.ts +1 -1
  65. package/src/unstable/AppearAnimations.ts +21 -3
  66. package/src/unstable/DragDefaults.ts +9 -9
  67. package/src/unstable/DragTrack.ts +21 -0
  68. package/src/unstable/ElementSetup.ts +14 -1
  69. package/src/unstable/Feature.ts +9 -5
  70. package/src/unstable/GestureFeatures.ts +297 -3
  71. package/src/unstable/Imperative.ts +45 -13
  72. package/src/unstable/InstanceFeatures.ts +82 -0
  73. package/src/unstable/PagePoint.ts +129 -0
  74. package/src/unstable/ReorderInput.ts +143 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * A Reorder item's input (ADR-0037), for every binding (#379): its keys, blurs and presses told to its
3
+ * driver by watches while a Scope is open, each inside its event, with no fiber at rest. Each binding
4
+ * runs it in the item's watch Scope (ADR-0055, *Amendment (#379)*). A Batch Reorder group's items (#712)
5
+ * are heard through the feeds over them instead, with no listener per item at rest.
6
+ *
7
+ * Unstable, for Wardic's own packages: public, with no semver promise.
8
+ *
9
+ * @module
10
+ */
11
+ // Unstable: ADR-0071, decision 5. #793 (PR 3): solid's `reorder-input.ts`, moved to dom for the Foldkit binding's items too.
12
+ import * as InputFeed from "@wardic/core/InputFeed";
13
+ import * as InputSource from "@wardic/core/InputSource";
14
+ import * as Report from "../Report.js";
15
+ import * as Bool from "effect/Boolean";
16
+ import * as Effect from "effect/Effect";
17
+ import * as Iter from "effect/Iterable";
18
+ import * as Predicate from "effect/Predicate";
19
+ import * as UndefinedOr from "effect/UndefinedOr";
20
+ /** A Primary pointer's down: a press the driver hears. */
21
+ const isPress = (event) => Bool.and(event.type === "down", InputSource.isPrimaryPointer(event));
22
+ /**
23
+ * Watch an item's keys, blurs and presses for its driver (ADR-0037, #379) while the Scope is open: its
24
+ * keys inside their dispatch, so the reorder's `handle()` (the page's `preventDefault`) counts. A blur
25
+ * is judged after this task's own work, one scheduler hop on (#318): a reorder can blur the node it
26
+ * moves and puts focus back after (the driver's `keepFocus`). So `fork` runs that hop on the provider
27
+ * runtime, only when a blur happens, and a blur whose judging fails is reported. A throw from the
28
+ * driver inside an event goes to `onDefect`.
29
+ */
30
+ export const watchItemInput = (el, driver, fork, onDefect) => {
31
+ const judgeBlur = judgedBlurOf(driver);
32
+ return Effect.gen(function* () {
33
+ const input = yield* InputSource.InputSource;
34
+ yield* InputFeed.watch(input.keyboard(el), { on: (event) => driver.onKey(event), onDefect });
35
+ yield* InputFeed.watch(input.focus(el), {
36
+ on: (event) => {
37
+ // The item's own blur: one inside it (#439) leaves it focused.
38
+ if (Bool.and(event.type === "blur", event.fromTarget !== false))
39
+ fork(judgeBlur);
40
+ },
41
+ onDefect,
42
+ });
43
+ yield* InputFeed.watch(input.pointer(el), {
44
+ on: (event) => {
45
+ if (isPress(event))
46
+ driver.onPress();
47
+ },
48
+ onDefect,
49
+ });
50
+ });
51
+ };
52
+ /** A blur judged after this task's own work, one scheduler hop on (#318); a judging that fails reported. */
53
+ const judgedBlurOf = (driver) => Effect.andThen(Effect.yieldNow, Effect.sync(() => driver.onBlur())).pipe(Effect.catchCause((cause) => Report.failure("wardic.reorder: judging an item's blur failed", cause)));
54
+ /** An InputSource's feed over many targets, or a defect naming it. */
55
+ const amongOf = (feed, name) => UndefinedOr.match(feed, {
56
+ onUndefined: () => Effect.die(new Error(`wardic.reorder: the Environment's InputSource has no \`${name}\`, which a Batch Reorder group's items need`)),
57
+ onDefined: Effect.succeed,
58
+ });
59
+ /** A Primary pointer's release or cancel: a press's end the group hears. */
60
+ const isPressEnd = (event) => Bool.and(Bool.or(event.type === "up", event.type === "cancel"), InputSource.isPrimaryPointer(event));
61
+ /**
62
+ * Watch a Batch Reorder group's items' keys, blurs and presses (#712, ADR-0072 decision 7, Q28) while the
63
+ * Scope is open, through the feeds over them: focus heard by `focusAmong`, and a focused item's own keys
64
+ * from its focus to its blur, as a Batch's press watch holds them (#460); presses by `pointerAmong`. So at
65
+ * rest no item listens. `memberOf` names the item a node is. Blurs are judged as {@link watchItemInput}'s are.
66
+ */
67
+ export const watchItemsInputAmong = Effect.fnUntraced(function* (memberOf, handlers) {
68
+ const input = yield* InputSource.InputSource;
69
+ const focusAmong = yield* amongOf(input.focusAmong, "focusAmong");
70
+ const pointerAmong = yield* amongOf(input.pointerAmong, "pointerAmong");
71
+ const { driverOf, onDefect } = handlers;
72
+ // The focused items' keys, each open from its focus to its blur.
73
+ const focusedKeys = new Map();
74
+ const closeKeys = (target) => {
75
+ UndefinedOr.map(focusedKeys.get(target), (keysNow) => keysNow.close());
76
+ focusedKeys.delete(target);
77
+ };
78
+ const openKeys = (target) => {
79
+ if (focusedKeys.has(target))
80
+ return;
81
+ const driver = driverOf(target);
82
+ if (Predicate.isUndefined(driver))
83
+ return;
84
+ const keysNow = InputFeed.switched(input.keyboard(target), (event) => driver.onKey(event), onDefect);
85
+ focusedKeys.set(target, keysNow);
86
+ keysNow.open();
87
+ };
88
+ yield* Effect.addFinalizer(() => Effect.sync(() => {
89
+ Iter.forEach(focusedKeys.values(), (keysNow) => keysNow.close());
90
+ focusedKeys.clear();
91
+ }));
92
+ yield* InputFeed.watch(focusAmong(memberOf), {
93
+ on: ({ target, event }) => {
94
+ if (event.type === "focus")
95
+ return openKeys(target);
96
+ closeKeys(target);
97
+ // The item's own blur: one inside it (#439) leaves it focused.
98
+ if (event.fromTarget === false)
99
+ return;
100
+ UndefinedOr.map(driverOf(target), (driver) => handlers.fork(judgedBlurOf(driver)));
101
+ },
102
+ onDefect,
103
+ });
104
+ yield* InputFeed.watch(pointerAmong(memberOf), {
105
+ on: ({ target, event }) => {
106
+ if (isPressEnd(event))
107
+ return handlers.onPressEnd(target);
108
+ if (Bool.not(isPress(event)))
109
+ return;
110
+ UndefinedOr.map(driverOf(target), (driver) => driver.onPress());
111
+ handlers.onPress(target);
112
+ },
113
+ onDefect,
114
+ });
115
+ });
116
+ //# sourceMappingURL=ReorderInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReorderInput.js","sourceRoot":"","sources":["../../src/unstable/ReorderInput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,6HAA6H;AAC7H,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,0BAA0B,CAAA;AAEvD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AAEvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAE7C,OAAO,KA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 @@
1
1
  {
2
2
  "name": "@wardic/dom",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "The browser environment for Wardic: its clock, renderer, input, probe and projection system, as Effect Layers.",
5
5
  "keywords": [
6
6
  "animation",
@@ -55,7 +55,7 @@
55
55
  "typecheck:tests": "../../node_modules/typescript-7/bin/tsc -p tsconfig.test.json"
56
56
  },
57
57
  "dependencies": {
58
- "@wardic/core": "1.1.2",
58
+ "@wardic/core": "1.1.4",
59
59
  "csstype": "^3.1.0",
60
60
  "culori": "^4.0.2"
61
61
  },
@@ -63,6 +63,6 @@
63
63
  "effect": "^4.1.4"
64
64
  },
65
65
  "devDependencies": {
66
- "@wardic/test": "1.1.2"
66
+ "@wardic/test": "1.1.4"
67
67
  }
68
68
  }
@@ -24,8 +24,14 @@
24
24
  // and `placed` where `make`'s hears a Measure pass's end.
25
25
  // Its items' drivers stay plain, each with its own `dispose`, since one is made per element.
26
26
  import * as Announcer from "@wardic/core/Announcer"
27
+ import type * as Reorder from "@wardic/core/Reorder"
28
+ import * as Arr from "effect/Array"
29
+ import * as Bool from "effect/Boolean"
27
30
  import * as Effect from "effect/Effect"
28
- import { constVoid } from "effect/Function"
31
+ import { constUndefined, constVoid, identity } from "effect/Function"
32
+ import * as Match from "effect/Match"
33
+ import * as Predicate from "effect/Predicate"
34
+ import * as UndefinedOr from "effect/UndefinedOr"
29
35
  import type * as Scope from "effect/Scope"
30
36
  import { PassEnds } from "./internal/pass-ends.ts"
31
37
  import * as internal from "./internal/reorder.ts"
@@ -41,11 +47,38 @@ export {
41
47
  type ReorderItemHandle as ItemHandle,
42
48
  DEFAULT_REORDER_INSTRUCTIONS as DEFAULT_INSTRUCTIONS,
43
49
  REORDER_GROUP_STYLE as GROUP_STYLE,
50
+ sameOrder,
44
51
  } from "./internal/reorder.ts"
45
52
 
53
+ // The keyboard reorder's settings and attributes (ADR-0037), as every binding reads and writes them (#793, PR 3):
54
+ // solid's `reorder.tsx` and `batch-reorder.ts` had them each.
55
+
56
+ /** Whether a group's `keyboard` option turns the **Keyboard reorder** on: on unless `false`. */
57
+ export const keyboardOn = (keyboard: boolean | undefined): boolean => keyboard !== false
58
+
59
+ /** A group's instructions, the English default when it gives none. */
60
+ export const instructionsOf = (instructions: string | undefined): string =>
61
+ UndefinedOr.match(instructions, { onUndefined: () => internal.DEFAULT_REORDER_INSTRUCTIONS, onDefined: identity })
62
+
63
+ /** An item's `aria-describedby`: the app's own ids, then the instructions', or none. */
64
+ export const describedByOf = (own: string | undefined, instructions: string | undefined): string | undefined => {
65
+ const ids = Arr.filter([own, instructions], Predicate.isNotUndefined)
66
+ return Bool.match(ids.length === 0, { onTrue: constUndefined, onFalse: () => ids.join(" ") })
67
+ }
68
+
69
+ /** An item's tab stop when it gives none of its own: `0` with the keyboard reorder on, or with its items pressable (a Batch Reorder group's). */
70
+ export const tabStopOf = (keyboard: boolean, pressable: boolean): 0 | undefined => Bool.match(Bool.or(keyboard, pressable), { onTrue: (): 0 => 0, onFalse: constUndefined })
71
+
46
72
  /** A **Reorder group** on the DOM: what a binding attaches its group element and items to. */
47
73
  export type ReorderController<V> = Omit<internal.ReorderController<V>, "dispose">
48
74
 
75
+ /** An item's drag axis for its gesture's axis, the group's: a grid's `"xy"` is a free drag. Built once, at module load. */
76
+ // #793 (PR 3): solid's `reorder.tsx`'s `dragAxisFor`, here for both bindings' items.
77
+ export const itemDragAxis: (axis: Reorder.Axis) => true | "x" | "y" = /*#__PURE__*/ Match.type<Reorder.Axis>().pipe(
78
+ /*#__PURE__*/ Match.when("xy", (): true => true),
79
+ /*#__PURE__*/ Match.orElse((axis) => axis as "x" | "y"),
80
+ )
81
+
49
82
  /** What a binding hands its group: the app's values, its axis, its keyboard and its announcements. */
50
83
  export type Options<V> = internal.ReorderControllerOptions<V>
51
84
 
package/src/index.ts CHANGED
@@ -38,7 +38,7 @@ import * as DomPositionalKeys from "./DomPositionalKeys.ts"
38
38
  import * as DomProbe from "./DomProbe.ts"
39
39
  import * as DomRenderer from "./DomRenderer.ts"
40
40
 
41
- export const VERSION = "1.1.2"
41
+ export const VERSION = "1.1.4"
42
42
 
43
43
  export * as DomBatch from "./DomBatch.ts"
44
44
  export * as DomClock from "./DomClock.ts"
@@ -891,8 +891,13 @@ export interface BatchSlot {
891
891
 
892
892
  /** One render's Appear rules: a slot per element, and the `<style>` text for the head and each late chunk. */
893
893
  export interface Sheet {
894
- /** A slot for the next element. */
895
- readonly slot: () => Slot
894
+ /**
895
+ * A slot for the next element: named by the sheet's count, or by `name` under `--wardic-a` when the
896
+ * binding names it (a Foldkit render names each by its element's path, the same on the server and the
897
+ * hydration render, #794). A Batch's slot (`batch`) stays on the count, in the same namespace: a
898
+ * binding naming slots keeps its names apart from the count's digits, or asks for no Batch rule.
899
+ */
900
+ readonly slot: (name?: string | undefined) => Slot
896
901
  /**
897
902
  * A slot for a Batch's members on `play`'s rule, and under `prefers-reduced-motion: reduce` `reduced`'s
898
903
  * when given (a provider's `"user"`): both rules, and the slot's `:root` lines naming each with no delay,
@@ -966,8 +971,8 @@ export const sheet = (): Sheet => {
966
971
  }),
967
972
  }
968
973
  },
969
- slot: () => {
970
- const property = `--${PREFIX}a${slots++}`
974
+ slot: (name) => {
975
+ const property = `--${PREFIX}a${UndefinedOr.match(name, { onUndefined: () => String(slots++), onDefined: identity })}`
971
976
  return {
972
977
  animation: `var(${property})`,
973
978
  define: (play, reduced, supports = []) =>
@@ -5,6 +5,9 @@
5
5
  * requests its flushes from the same member, so the Clock and the gate share the browser's
6
6
  * frames. Everything else — the ref-counted Refresh frame loop, the `dt` computation and the
7
7
  * `wardic.clock` span — lives in core, so every Environment's Clock behaves the same (ADR-0004).
8
+ * So the Clock's `frameAt` (#791) is the last tick's `requestAnimationFrame` timestamp: what
9
+ * `document.timeline.currentTime` reads inside that frame, which a binding's hint passes to the
10
+ * Frame loop (ADR-0071, decision 32).
8
11
  */
9
12
  import * as Clock from "@wardic/core/Clock"
10
13
  import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource"
@@ -623,7 +623,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
623
623
  const noop = (): void => {}
624
624
 
625
625
  /** Whether two orders hold the same items in the same order. */
626
- const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
626
+ export const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
627
627
 
628
628
  /** Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its order. */
629
629
  const isAsked = (asked: ReadonlyArray<unknown> | undefined, values: ReadonlyArray<unknown>): boolean =>
@@ -303,6 +303,8 @@ export interface ServerAppear {
303
303
  /** Its tag and its targets at mount, which name it when the provider explains (#585). */
304
304
  tag: string | undefined,
305
305
  to: Option.Option<Values.Values>,
306
+ /** Its slot's name under `--wardic-a`, when the binding names it ({@link Appear.Sheet.slot}; #794); the sheet's count without. */
307
+ slot?: string | undefined,
306
308
  ) => {
307
309
  readonly entry: Entry
308
310
  readonly animation: Option.Option<string>
@@ -376,6 +378,20 @@ export const explainerOf = (appear: boolean | "explain" | undefined): ((message:
376
378
  return (message) => Effect.runSync(Effect.logWarning(message))
377
379
  }
378
380
 
381
+ /** Why an element's own `animation` in its style rules its Appear animation out (decision 4): the one CSS animation it has would be taken. What each binding's veto says. */
382
+ export const OWN_ANIMATION = "its own style sets an animation"
383
+
384
+ /**
385
+ * A render's Appear animations from a provider's settings (decisions 3 and 5): none with `appear:
386
+ * false`; else {@link serverAppear} under `reducedMotion`, the user's preference with none set, the
387
+ * explainer `appear` asks for (#585) and the `nonce` (#618). Each binding's provider makes its own
388
+ * through it, Foldkit's walk too (#794).
389
+ */
390
+ export const serverAppearUnder = (appear: boolean | "explain" | undefined, reducedMotion: ReducedMotion.Config | undefined, nonce: string | undefined): ServerAppear | undefined => {
391
+ if (appear === false) return undefined
392
+ return serverAppear(UndefinedOr.match(reducedMotion, { onUndefined: (): ReducedMotion.Config => "user", onDefined: identity }), explainerOf(appear), nonce)
393
+ }
394
+
379
395
  /** An element as the provider's explanation names it (#585): its tag and the keys its mount animates. */
380
396
  const nameOf = (entry: Entry): string => {
381
397
  const element = UndefinedOr.match(entry.tag, { onUndefined: () => "an element", onDefined: (tag) => `<${tag}>` })
@@ -438,11 +454,11 @@ export const serverAppear = (reducedMotion: ReducedMotion.Config, explain?: (mes
438
454
  const chunkCss = (): string => write(nextBatch())
439
455
  return {
440
456
  reducedMotion,
441
- enter: (given, group, setting, skipped, tag, to) => {
457
+ enter: (given, group, setting, skipped, tag, to, name) => {
442
458
  // Skipped (#468): its one play in both slots, under no media query.
443
459
  const own = Bool.match(skipped, { onTrue: (): ReducedMotion.Config => "never", onFalse: () => settingOr(setting, reducedMotion) })
444
460
  const animation = playsUnder(given, own)
445
- const slot = Option.liftPredicate(animation, plays).pipe(Option.map(() => sheet.slot()))
461
+ const slot = Option.liftPredicate(animation, plays).pipe(Option.map(() => sheet.slot(name)))
446
462
  const entry: Entry = { plays: animation, slot, group, vetoes: [], user: own === "user", skipped, tag, to }
447
463
  // Why it plays neither: its normal play's reason, its reduced one's when that differs (#585).
448
464
  if (Predicate.isNotUndefined(explain)) {
@@ -667,6 +683,8 @@ export interface ServerElement {
667
683
  readonly reducedMotion?: ReducedMotion.Config | undefined
668
684
  /** Whether its nearest `WardicConfig` skips its animations (#468). Its transition's own `skipAnimations` counts too. */
669
685
  readonly skipAnimations?: boolean | undefined
686
+ /** Its slot's name under `--wardic-a`, when the binding names it by the element's place (#794); the sheet's count without. */
687
+ readonly slot?: string | undefined
670
688
  }
671
689
 
672
690
  /**
@@ -718,7 +736,7 @@ export const enterServer = (
718
736
  },
719
737
  onFalse: () => ({ normal: play(false), reduced: play(true) }),
720
738
  })
721
- const { entry, animation: inline, late, chunkRoot } = appear.enter(plays, el.group, el.reducedMotion, skipped, el.tag, el.to)
739
+ const { entry, animation: inline, late, chunkRoot } = appear.enter(plays, el.group, el.reducedMotion, skipped, el.tag, el.to, el.slot)
722
740
  return {
723
741
  late,
724
742
  chunkRoot,
@@ -10,25 +10,27 @@
10
10
  // Unstable: ADR-0071, decision 5. #672 (Q11, PR2-Q3): solid's `drag-defaults.ts`, out of `spine.ts` since
11
11
  // PR 2, moved to dom for every DOM binding's drag elements.
12
12
  import * as Style from "../Style.ts"
13
- import * as Arr from "effect/Array"
13
+ import * as ElementSetup from "./ElementSetup.ts"
14
14
  import * as Option from "effect/Option"
15
- import * as Rec from "effect/Record"
16
15
  import * as UndefinedOr from "effect/UndefinedOr"
17
16
  import type * as WardConfig from "./WardConfig.ts"
18
17
 
19
- /** What a `<Reorder>` item adds to an element's drag: its gesture's axis, read at each drag's start. */
20
- interface DragInternals {
18
+ /** What a Reorder item adds to an element's drag: its gesture's axis, read at each drag's start. */
19
+ export interface DragInternals {
21
20
  readonly dragAxis?: (() => boolean | "x" | "y") | undefined
22
21
  }
23
22
 
24
23
  /** A plain element's drag internals: none. */
25
24
  const NO_DRAG_INTERNALS: DragInternals = {}
26
25
 
26
+ /** The drag props the defaults are read from: whether the element drags, and whether its own presses do. */
27
+ export type DragProps = Pick<WardConfig.WardConfig, "drag" | "dragListener">
28
+
27
29
  /**
28
30
  * The drag axis a spine runs with: its static `drag` config, else `true` for a
29
31
  * `<Reorder>` item (its gesture's axis comes from `dragAxis`), else none.
30
32
  */
31
- export const dragAxisOf = (config: WardConfig.WardConfig, internal: DragInternals = NO_DRAG_INTERNALS): boolean | "x" | "y" | undefined =>
33
+ export const dragAxisOf = (config: DragProps, internal: DragInternals = NO_DRAG_INTERNALS): boolean | "x" | "y" | undefined =>
32
34
  Option.getOrUndefined(
33
35
  Option.orElse(Option.filter(Option.fromUndefinedOr(config.drag), (drag) => drag !== false), () =>
34
36
  Option.map(Option.fromUndefinedOr(internal.dragAxis), (): true => true)),
@@ -38,7 +40,7 @@ export const dragAxisOf = (config: WardConfig.WardConfig, internal: DragInternal
38
40
  * A drag element's defaults (ADR-0019 *Amendment (Reorder)*): its axis's, unless its own presses don't
39
41
  * drag it (`dragListener={false}`, #431), as Motion's come with its listener.
40
42
  */
41
- export const dragDefaultsOf = (config: WardConfig.WardConfig, internal: DragInternals = NO_DRAG_INTERNALS): Style.DragDefaults | undefined => {
43
+ export const dragDefaultsOf = (config: DragProps, internal: DragInternals = NO_DRAG_INTERNALS): Style.DragDefaults | undefined => {
42
44
  if (config.dragListener === false) return undefined
43
45
  return UndefinedOr.map(dragAxisOf(config, internal), Style.dragDefaults)
44
46
  }
@@ -50,8 +52,6 @@ export const dragDefaultsOf = (config: WardConfig.WardConfig, internal: DragInte
50
52
  * component may not pass them on.
51
53
  */
52
54
  export const applyDragDefaults = (element: HTMLElement, defaults: Style.DragDefaults): void => {
53
- Arr.forEach(Rec.keys(defaults), (key) => {
54
- if (element.style.getPropertyValue(key) === "") element.style.setProperty(key, UndefinedOr.getOrThrow(defaults[key]))
55
- })
55
+ ElementSetup.writeUnderStyle(element, defaults)
56
56
  if (!element.hasAttribute("draggable")) element.setAttribute("draggable", Style.DRAG_DEFAULT_ATTRIBUTES.draggable)
57
57
  }
@@ -142,6 +142,27 @@ export interface DragTrackConfig {
142
142
  readonly listen?: boolean | undefined
143
143
  }
144
144
 
145
+ /** The drag props a track's config is read from: an element's, its axis and its constraints resolved by the binding. */
146
+ export type DragOptions = Pick<WardConfig.WardDragConfig, "dragElastic" | "dragMomentum" | "dragSnapToOrigin" | "dragPropagation" | "dragDirectionLock" | "dragListener">
147
+
148
+ /**
149
+ * A track's config from an element's drag props (#793), for every binding: `axis` and `constraints` as
150
+ * the binding resolved them, `transition` the element's drag transition ({@link DragTransition.dragTransitionOf}),
151
+ * which its layout node shares.
152
+ */
153
+ // #793 (PR 2): solid's `create-ward.tsx`'s `trackConfig`, moved to dom for both bindings' tracks.
154
+ export const trackConfigOf = (c: DragOptions, axis: boolean | "x" | "y", constraints: Drag.Bounds | undefined, transition: ProjectionSystem.DragTransition): DragTrackConfig => ({
155
+ axis,
156
+ constraints,
157
+ elastic: c.dragElastic,
158
+ momentum: c.dragMomentum,
159
+ snapToOrigin: c.dragSnapToOrigin,
160
+ propagation: c.dragPropagation,
161
+ directionLock: c.dragDirectionLock,
162
+ transition,
163
+ listen: c.dragListener,
164
+ })
165
+
145
166
  /** What the track's watches and responses run with: the provider's services and the gestures' input (#511). */
146
167
  export type TrackServices = WardicServices.WardicServices | InputSource.InputSource
147
168
 
@@ -276,6 +276,17 @@ export const draggingWithWillChange = (live: LiveStyle.LiveStyle | undefined, se
276
276
  */
277
277
  export const claimForDrag = (element: Element): (() => void) => () => Spine.tellDrag(element, true)
278
278
 
279
+ /**
280
+ * Write `style` on `element` under its own inline style (#793): each key its inline style doesn't set,
281
+ * so the app's wins, as a drag element's defaults and a Reorder group's style go on (ADR-0019
282
+ * *Amendment (Reorder)*).
283
+ */
284
+ export const writeUnderStyle = (element: HTMLElement, style: Readonly<Record<string, string>>): void => {
285
+ Arr.forEach(Rec.keys(style), (key) => {
286
+ if (element.style.getPropertyValue(key) === "") element.style.setProperty(key, UndefinedOr.getOrThrow(style[key]))
287
+ })
288
+ }
289
+
279
290
  /** Log, once per element, that a `transform` string gave way to the transform keys in its `style` (#130). */
280
291
  export const warnDroppedTransform = (runtime: WardicServices.Runner<WardicServices.WardicServices>, id: string): void => {
281
292
  runtime.runFork(
@@ -341,7 +352,7 @@ const NO_APPEAR_ENTRY = (provided: VariantTree.WardicVariantContextValue | undef
341
352
  * values, its targets at mount (`animate`, or an inherited variant name against its `variants`),
342
353
  * its transition, its place in its parent's group, and its nearest `WardicConfig`'s reduced motion
343
354
  * (#434). `state` is the provider's, `undefined` with `appear={false}`: each binding reads it from its
344
- * own context.
355
+ * own context. `slot` names its slot when the binding names them by the element's place (#794).
345
356
  */
346
357
  export const appearEntryOf = (
347
358
  state: AppearAnimations.ServerAppear | undefined,
@@ -352,6 +363,7 @@ export const appearEntryOf = (
352
363
  quiet: boolean,
353
364
  reducedMotion: ReducedMotion.Config | undefined,
354
365
  skipAnimations = false,
366
+ slot?: string | undefined,
355
367
  ): ServerAppearOf =>
356
368
  UndefinedOr.match(state, {
357
369
  onUndefined: () => NO_APPEAR_ENTRY(node.provided),
@@ -374,6 +386,7 @@ export const appearEntryOf = (
374
386
  ownTransition: VariantTarget.transitionOfTarget(own, c.transition),
375
387
  reducedMotion,
376
388
  skipAnimations,
389
+ slot,
377
390
  })
378
391
  return {
379
392
  style: Option.match(entered.animation, { onNone: constUndefined, onSome: (animation) => ({ animation }) }),
@@ -485,10 +485,14 @@ export const wantsLayoutNode = (c: WardConfig.WardConfig): boolean =>
485
485
  c.layout === true || Predicate.isString(c.layout) || Predicate.isNotUndefined(c.layoutId) || c.layoutScroll === true || c.layoutRoot === true
486
486
 
487
487
  /**
488
- * Development's word on a missing Feature (#511, ADR-0067 decision 7): what needed it, its import from
489
- * the binding's `entry`, and where to add it. Not a Complete element, which a `strict` section makes
490
- * an error (#581).
488
+ * Development's word on a missing Feature (#511, ADR-0067 decision 7): what needed it, and `how` to
489
+ * add it: by default a Solid provider's `features`, the Feature imported from the binding's `entry`;
490
+ * a binding with another way (Foldkit's `Wardic.make`) says so. Not a Complete element, which a
491
+ * `strict` section makes an error (#581).
491
492
  */
492
- export const missingMessage = (feature: string, what: string, entry: string): string =>
493
- `wardic: ${what} needs the \`${feature}\` Feature, which no WardicProvider or LazyWardic above this element has. ` +
493
+ export const missingMessage = (feature: string, what: string, entry: string, how: string = providerHow(feature, entry)): string => `wardic: ${what} needs the \`${feature}\` Feature, ${how}`
494
+
495
+ /** How a Solid app adds a Feature (the default `how`): a provider's `features`, the Feature imported from `entry`. */
496
+ const providerHow = (feature: string, entry: string): string =>
497
+ `which no WardicProvider or LazyWardic above this element has. ` +
494
498
  `Add it: \`import { ${feature} } from "${entry}"\`, then \`<WardicProvider features={[${feature}]}>\` or \`<LazyWardic features={[${feature}]}>\`.`