@fjader/svelte 0.2.0 → 0.2.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.
@@ -5,24 +5,33 @@
5
5
  * import { setQueryContext } from './';
6
6
  * setQueryContext(wasm.getConnection()); // Promise OK — resolves lazily
7
7
  *
8
- * Usage in spec renderer:
9
- * context.set('query-engine', new QueryEngine(connection));
10
- * context.set('filter-groups', new FilterGroupRegistry());
8
+ * Usage outside a component (the spec renderer), passing contexts to mount():
9
+ * const { filterGroups } = createQueryServices(queryEngine);
10
+ * context.set('query-engine', queryEngine);
11
+ * context.set('filter-groups', filterGroups);
11
12
  */
12
13
  import { setContext, getContext } from 'svelte';
13
14
  import { QueryEngine } from './QueryEngine';
14
15
  import { FilterGroupRegistry } from './FilterGroupRegistry.svelte';
15
16
  import { tableSchemaService } from '../data/TableSchemaService.svelte';
17
+ /**
18
+ * Create the FilterGroupRegistry for an engine and wire both to the schema
19
+ * service. Brushes and toggles reach the engine only through this wiring:
20
+ * a FilterGroup without an engine updates its selection but never re-queries.
21
+ */
22
+ export function createQueryServices(queryEngine) {
23
+ const filterGroups = new FilterGroupRegistry();
24
+ filterGroups.setEngine(queryEngine);
25
+ tableSchemaService.setQueryEngine(queryEngine);
26
+ return { queryEngine, filterGroups };
27
+ }
16
28
  /**
17
29
  * Create QueryEngine + FilterGroupRegistry and set Svelte contexts.
18
30
  * Call this synchronously in a component's <script> block.
19
31
  * Accepts a Promise<DuckDBConnection> — queries defer until it resolves.
20
32
  */
21
33
  export function setQueryContext(connection) {
22
- const queryEngine = new QueryEngine(connection);
23
- const filterGroups = new FilterGroupRegistry();
24
- filterGroups.setEngine(queryEngine);
25
- tableSchemaService.setQueryEngine(queryEngine);
34
+ const { queryEngine, filterGroups } = createQueryServices(new QueryEngine(connection));
26
35
  setContext('query-engine', queryEngine);
27
36
  setContext('filter-groups', filterGroups);
28
37
  return { queryEngine, filterGroups };
@@ -17,8 +17,7 @@
17
17
  import { mount, unmount } from 'svelte';
18
18
  import { ScaleRegistry } from '../scales/ScaleRegistry.svelte';
19
19
  import { GPUCoordinator } from '../gpu/GPUCoordinator.svelte';
20
- import { FilterGroupRegistry } from '../query-engine/FilterGroupRegistry.svelte';
21
- import { tableSchemaService } from '../data/TableSchemaService.svelte';
20
+ import { createQueryServices } from '../query-engine';
22
21
  import { getOrCreateQueryEngine, loadData } from './LazyQueryEngine';
23
22
  import LayoutFromSpec from './LayoutFromSpec.svelte';
24
23
  /**
@@ -47,8 +46,7 @@ export async function render(target, spec, options = {}) {
47
46
  }
48
47
  // 4. Build context map — injected into Svelte mount() so child components
49
48
  // find these via getContext() calls (same keys as initFjader())
50
- const filterGroups = new FilterGroupRegistry();
51
- tableSchemaService.setQueryEngine(queryEngine);
49
+ const { filterGroups } = createQueryServices(queryEngine);
52
50
  const context = new Map();
53
51
  context.set('query-engine', queryEngine);
54
52
  context.set('filter-groups', filterGroups);
package/dist/types.d.ts CHANGED
@@ -338,12 +338,34 @@ export interface ChartContext {
338
338
  readonly fxDomain?: DimValue[] | null;
339
339
  readonly config: ChartConfig;
340
340
  onChartClick: ((event: PointerEvent) => void) | null;
341
- onInteractorPointerDown: ((event: PointerEvent, innerPoint: Point) => boolean) | null;
341
+ /**
342
+ * A press, offered to the interactor before the chart pans. `target` is the
343
+ * element under the pointer, which a brush reads for the handle it is on
344
+ * (brushHandleAt); `innerPoint` is in plot-area coordinates. Returns true when
345
+ * the interactor takes the press. Called again when the chart re-routes a
346
+ * press under way (reroutePress).
347
+ */
348
+ onInteractorPointerDown: ((target: Element, pointerId: number, innerPoint: Point) => boolean) | null;
342
349
  /** Every pointer move but a pan; `innerPoint` is the pointer in plot-area coordinates (a
343
350
  * shared buffer: read it before calling back into the layout). Returns true when the
344
351
  * interactor handled the move (a drag it captured). */
345
352
  onInteractorPointerMove: ((event: PointerEvent, innerPoint: Point) => boolean) | null;
346
353
  onInteractorPointerUp: ((event: PointerEvent) => boolean) | null;
354
+ /**
355
+ * End the interactor's drag where it is, as a pointer up would but without
356
+ * treating a drag that never moved as a click (which clears a brush). The
357
+ * chart calls it when it re-routes the press.
358
+ */
359
+ onInteractorDragEnd: (() => void) | null;
360
+ /**
361
+ * Route the press under way again, as if it began now where the pointer is:
362
+ * end what it is doing (a pan, or the interactor's drag), then offer it to
363
+ * the interactor and pan if declined, as a new press would be. Brushes call
364
+ * it when Space changes, since one press can outlast that: with three-finger
365
+ * drag on a trackpad it goes on for seconds after the fingers lift. Without a
366
+ * press under way it does nothing.
367
+ */
368
+ reroutePress: () => void;
347
369
  /**
348
370
  * Selection sources to activate when the pointer enters the chart, so their
349
371
  * preagg tables exist before the first gesture. Interactors add their
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/dlyngman/fjader.git"
20
20
  },
21
- "version": "0.2.0",
21
+ "version": "0.2.2",
22
22
  "type": "module",
23
23
  "svelte": "./dist/index.js",
24
24
  "exports": {