@weasel-js/routing 1.9.4 → 1.10.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/react.d.ts CHANGED
@@ -1,24 +1,23 @@
1
- import { U as UseGestureDispatcherOptions } from './internal-B0SsznMG.js';
2
- export { D as DispatcherChannels } from './internal-B0SsznMG.js';
1
+ import { U as UseGestureDispatcherOptions } from './internal-D0rDmi7t.js';
2
+ export { D as DispatcherChannels } from './internal-D0rDmi7t.js';
3
3
  import * as react from 'react';
4
4
  import { ReactNode, ReactElement } from 'react';
5
- import { D as DepRegistry, a as DepName, b as DepSchema, S as ScopeNode, A as ActionsRegistry, c as Action, d as DepNode, T as ToolNode, K as KernelOverlay, C as Contribution, e as AnyToolOf, O as OverlayPosition } from './index-gArM2tbt.js';
6
- export { f as ActiveToolContextProvider, g as ActiveToolContextProviderIfRoot, h as ActiveToolContextProviderProps, i as ActiveToolContextValue, u as useActiveToolContext, j as useOptionalActiveToolContext } from './index-gArM2tbt.js';
5
+ import { D as DepRegistry, a as DepName, b as DepSchema, S as ScopeNode, A as ActionsRegistry, c as Action, d as DepNode, T as ToolNode, N as NodeId, K as KernelOverlay, C as Contribution, e as Tool, O as OverlayPosition } from './index-Bm2QEV09.js';
6
+ export { f as ActiveToolContextProvider, g as ActiveToolContextProviderIfRoot, h as ActiveToolContextProviderProps, i as ActiveToolContextValue, u as useActiveToolContext, j as useOptionalActiveToolContext } from './index-Bm2QEV09.js';
7
7
  import { ModeRegistry } from '@weasel-js/modes';
8
8
  import '@weasel-js/gestures';
9
9
  import '@weasel-js/cursor';
10
10
  import '@weasel-js/geom';
11
- import '@weasel-js/history';
11
+ import '@weasel-js/registry';
12
12
  import '@weasel-js/select';
13
13
 
14
14
  /**
15
- * Attach the input pipeline to a canvas: DOM pointer, wheel, keyboard and
15
+ * Attach the input pipeline to a canvas: DOM pointer, wheel, keyboard, and
16
16
  * multitouch listeners in, normalized input events out, routed through the
17
17
  * dispatcher to whichever action a binding names.
18
18
  *
19
- * Everything it needs beyond its options — the active tool, the dep registry —
20
- * comes from context, so it must be mounted inside `<SceneCanvas>`'s
21
- * providers.
19
+ * The active tool and the dep registry come from context, so it must be
20
+ * mounted inside `<SceneCanvas>`'s providers.
22
21
  */
23
22
  declare function useGestureDispatcher(opts: UseGestureDispatcherOptions): void;
24
23
 
@@ -125,11 +124,10 @@ interface YokeProps {
125
124
  /**
126
125
  * @experimental
127
126
  * Canvases that share input on purpose: the active tool, the gesture in
128
- * flight, history and yoke-wide actions. Made once with `useYoke()` where the
129
- * sharing is decided, and passed to each canvas that joins it (`yoke={yoke}`)
130
- * and to `<Yoke value={yoke}>` around anything else that should reach it — a
131
- * toolbar, say. The members can sit anywhere in the tree: the handle, not the
132
- * tree, says who shares.
127
+ * flight, history, and yoke-wide actions. Made once with `useYoke()`, and
128
+ * passed to each canvas that joins it (`yoke={yoke}`) and to
129
+ * `<Yoke value={yoke}>` around anything else that should reach it — a
130
+ * toolbar, say. The members can sit anywhere in the tree.
133
131
  */
134
132
  interface Yoke {
135
133
  /** @internal */
@@ -180,6 +178,101 @@ interface OngoingAction {
180
178
  */
181
179
  declare function useOngoingAction(actionId: string): OngoingAction;
182
180
 
181
+ /** @experimental World-space pointer position and the view it is over — a
182
+ * view id, or `null` for a surface's own camera. `null` as a whole when the
183
+ * pointer is over no publishing surface. */
184
+ type PointerWorldPos = {
185
+ worldX: number;
186
+ worldY: number;
187
+ viewId: string | null;
188
+ } | null;
189
+ /** @experimental */
190
+ interface PointerContextValue {
191
+ /** The latest position. */
192
+ get(): PointerWorldPos;
193
+ /** Publish a position. Subscribers hear only a changed value. */
194
+ set(next: PointerWorldPos): void;
195
+ /** Called after every change; returns the unsubscribe. */
196
+ subscribe(fn: () => void): () => void;
197
+ /** Bumps on every change. */
198
+ getVersion(): number;
199
+ /** `get()` as a stable thunk, for hooks taking a drop-point option. */
200
+ readonly getDropPoint: () => PointerWorldPos;
201
+ }
202
+ /** @experimental A pointer store with no provider around it. */
203
+ declare function createPointerStore(): PointerContextValue;
204
+ /**
205
+ * @experimental
206
+ * Wrap the part of the React tree that should share one pointer.
207
+ * `<SceneCanvas>` mounts one when none is in scope, so mount it yourself only
208
+ * when two surfaces should share a pointer. Pass `store` to publish into one
209
+ * you hold elsewhere (`createPointerStore()`).
210
+ */
211
+ declare function PointerContextProvider({ children, store }: {
212
+ children: ReactNode;
213
+ store?: PointerContextValue;
214
+ }): ReactNode;
215
+ /** @experimental The surrounding pointer store, or `null` when no provider is
216
+ * in scope. */
217
+ declare function usePointerContext(): PointerContextValue | null;
218
+ /** @experimental The pointer, re-rendering the caller whenever it changes.
219
+ * `null` outside a provider. */
220
+ declare function usePointerPosition(): PointerWorldPos;
221
+
222
+ /**
223
+ * @experimental
224
+ * SelectionContext — an ambient context that publishes "what's currently
225
+ * selected" so non-canvas UI (command palette, status bar) can read it without
226
+ * threading a selection prop through the tree.
227
+ *
228
+ * **Single slot:** the context holds one selection array. Whichever publisher
229
+ * calls `publishSelection` most recently owns it, so a multi-canvas page gets
230
+ * last-writer-wins. `<SceneCanvas>` publishes automatically.
231
+ */
232
+
233
+ /** @experimental */
234
+ interface SelectionContextValue {
235
+ /** The most-recently-published selection. Empty array when no canvas
236
+ * has published or when the active canvas's selection is empty. */
237
+ readonly selection: readonly NodeId[];
238
+ /** Optional per-id kind label, parallel to `selection` (e.g. `'rectangle'`,
239
+ * `'path'`, `'group'`). Sparse entries (`undefined`) are allowed; treat it
240
+ * as best-effort. */
241
+ readonly kinds?: readonly (string | undefined)[];
242
+ /** Publish the calling canvas's selection. Calling with the same content
243
+ * does not re-render the consumer tree. */
244
+ publishSelection(ids: readonly NodeId[], kinds?: readonly (string | undefined)[]): void;
245
+ }
246
+ /**
247
+ * @experimental
248
+ * Wrap the part of the React tree that should share a selection context.
249
+ * Usually placed at the demo / app root, alongside `<ActionsProvider>`.
250
+ */
251
+ declare function SelectionContextProvider({ children }: {
252
+ children: ReactNode;
253
+ }): ReactNode;
254
+ /**
255
+ * @experimental
256
+ * The current selection-context value, or `null` when no
257
+ * `<SelectionContextProvider>` is in scope.
258
+ */
259
+ declare function useSelectionContext(): SelectionContextValue | null;
260
+ /**
261
+ * @experimental
262
+ * Mounts a `<SelectionContextProvider>` only when no parent provider is in
263
+ * scope; otherwise renders children unwrapped.
264
+ */
265
+ declare function SelectionContextProviderIfRoot({ children, }: {
266
+ children: ReactNode;
267
+ }): ReactNode;
268
+ /**
269
+ * @experimental
270
+ * Publishes `ids` into the surrounding `<SelectionContextProvider>` whenever
271
+ * their content changes, and clears the slot on unmount unless another
272
+ * publisher has written it since. No-op when there's no provider in scope.
273
+ */
274
+ declare function usePublishSelection(ids: readonly NodeId[], kinds?: readonly (string | undefined)[]): void;
275
+
183
276
  /** Options for `useTools`: which tools exist, which one starts active, and
184
277
  * which run continuously regardless of the active one. */
185
278
  interface UseToolsOptions<TOverlay = KernelOverlay> {
@@ -189,7 +282,7 @@ interface UseToolsOptions<TOverlay = KernelOverlay> {
189
282
  /** Tools eligible for the active slot or hotkey slot. The keys are the
190
283
  * tool ids; the values are the tool records. A tool with `hotkey` set
191
284
  * is wired into the hotkey slot whenever the engagement state matches. */
192
- registry: Record<string, AnyToolOf<TOverlay>>;
285
+ registry: Record<string, Tool<TOverlay>>;
193
286
  /** Always-on entries — tools or other contributions, live regardless of
194
287
  * the active slot. */
195
288
  ambient?: readonly Contribution<TOverlay>[];
@@ -205,8 +298,7 @@ interface ToolsApi<TOverlay = KernelOverlay> {
205
298
  /** Set the active-slot tool, or `null` to clear it. The gesture dispatcher
206
299
  * watches the active tool and cancels any in-flight handle itself. */
207
300
  setActive: (id: string | null) => void;
208
- /** Currently hotkey-engaged tool id (or `null`). Derived as the top of
209
- * the hotkey stack for backwards compat with the pre-stack API. */
301
+ /** Currently hotkey-engaged tool id (or `null`): the top of the hotkey stack. */
210
302
  hotkeyEngaged: string | null;
211
303
  /** Engage a hotkey-slot tool by id. */
212
304
  engageHotkey: (id: string) => void;
@@ -215,31 +307,24 @@ interface ToolsApi<TOverlay = KernelOverlay> {
215
307
  /** All always-on entries, in registration order. */
216
308
  ambient: readonly Contribution<TOverlay>[];
217
309
  /** Full registry — for userland UI (palette buttons, etc.). */
218
- registry: Readonly<Record<string, AnyToolOf<TOverlay>>>;
310
+ registry: Readonly<Record<string, Tool<TOverlay>>>;
219
311
  /** Returns true if a tool with the given id is in the registry or ambient list. */
220
312
  has(id: string): boolean;
221
- /** All overlay layers from currently-engaged tools (active slot, hotkey
222
- * slot if engaged, all ambient slot tools) that declare `position`.
223
- * Filters out tools with no `overlay` field. Order: active, then hotkey
224
- * (if engaged), then ambient (registration order). */
313
+ /** Overlay layers from currently-engaged tools that declare `position`.
314
+ * Order: active, then hotkey (if engaged), then ambient (registration order). */
225
315
  getActiveOverlays(position?: OverlayPosition): TOverlay[];
226
316
  }
227
317
  /**
228
- * Manages the active tool and hotkey slot.
229
- *
230
- * A thin shim over {@link useContributions}: the `registry` / `ambient`
231
- * arguments are restated as declared eligibility (`focus` / `always`), and
232
- * assembly happens in one place for tools and non-tool contributions alike.
318
+ * Manages the active tool and hotkey slot; a thin shim over
319
+ * {@link useContributions}.
233
320
  *
234
321
  * Requires `<ActiveToolContextProvider>` (or `<WeaselProvider>` /
235
322
  * `<SceneCanvas>`, which mount one internally) in scope: active/hotkey state
236
- * lives in the context so the gesture dispatcher and any sibling
237
- * `useTools` calls all read the same source of truth.
323
+ * lives in the context.
238
324
  *
239
- * **First-mount-wins semantics**: if the context's slot is unseeded (no
240
- * `initialActive`, nothing set yet) on first mount, `useTools` pushes
241
- * `opts.active` to the context. Subsequent mounts respect whatever the
242
- * context currently holds (the first caller wins).
325
+ * **First mount wins**: if the context's slot is unseeded on first mount,
326
+ * `useTools` pushes `opts.active` to the context. Subsequent mounts respect
327
+ * whatever the context currently holds.
243
328
  */
244
329
  declare function useTools<TOverlay = KernelOverlay>(opts: UseToolsOptions<TOverlay>): ToolsApi<TOverlay>;
245
330
 
@@ -291,4 +376,4 @@ declare function useContributions<TOverlay = KernelOverlay>(opts: UseContributio
291
376
  */
292
377
  declare function useOffhandAction(entries: readonly Contribution<unknown>[]): void;
293
378
 
294
- export { ActionsProvider, type ContributionsApi, DepRegistry, DepRegistryProvider, InputScope, type InputScopeProps, type OngoingAction, type ToolsApi, type UseContributionsOptions, UseGestureDispatcherOptions, type UseToolsOptions, Yoke, type YokeProps, useAction, useActionsRegistry, useContributions, useDepRegistry, useDepSource, useGestureDispatcher, useOffhandAction, useOngoingAction, useOptionalDepRegistry, useTools, useYoke };
379
+ export { ActionsProvider, type ContributionsApi, DepRegistry, DepRegistryProvider, InputScope, type InputScopeProps, type OngoingAction, PointerContextProvider, type PointerContextValue, type PointerWorldPos, SelectionContextProvider, SelectionContextProviderIfRoot, type SelectionContextValue, type ToolsApi, type UseContributionsOptions, UseGestureDispatcherOptions, type UseToolsOptions, Yoke, type YokeProps, createPointerStore, useAction, useActionsRegistry, useContributions, useDepRegistry, useDepSource, useGestureDispatcher, useOffhandAction, useOngoingAction, useOptionalDepRegistry, usePointerContext, usePointerPosition, usePublishSelection, useSelectionContext, useTools, useYoke };