@dorsk/tsumikit 0.18.0 → 0.18.1

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/index.d.ts CHANGED
@@ -53,7 +53,7 @@ export { default as Tooltip } from './components/molecules/Tooltip.svelte';
53
53
  export { default as Truncate } from './components/molecules/Truncate.svelte';
54
54
  export { type Column, default as DataTable } from './components/organisms/DataTable.svelte';
55
55
  export { default as FilterSearchBar } from './components/organisms/FilterSearchBar.svelte';
56
- export { type AndNode, activeToken, compilePredicate, defaultOperator, type ExprNode, type FieldDef, type FieldType, type FilterNode, filters, findField, freeText, type LeafNode, type NotNode, OPERATORS, type Operator, type OperatorId, type OrNode, operatorByCode, operatorById, operatorsFor, parse, type Query, type QueryNode, resolveValues, type Schema, type Suggestion, type SuggestKind, type SuggestState, serialize, serializeFilter, suggest, type TextNode, toSql, type ValueOption, type ValueProvider, walk, } from './query';
56
+ export { type AndNode, activeToken, compilePredicate, defaultOperator, type ExprNode, type FieldDef, type FieldType, type FilterNode, filters, findField, freeText, type LeafNode, type NotNode, OPERATORS, type Operator, type OperatorId, type OrNode, operatorByCode, operatorById, operatorsFor, parse, type Query, type QueryNode, resolveValues, type Schema, type Suggestion, type SuggestKind, type SuggestState, serialize, serializeFilter, suggest, type TextNode, toSql, type ValueContext, type ValueOption, type ValueProvider, walk, } from './query';
57
57
  export { fontScale, SCALE_LEVELS, type ScaleLevel } from './stores/fontscale.svelte';
58
58
  export { type Mode, THEMES, theme } from './stores/theme.svelte';
59
59
  export { type Toast, type ToastTone, toasts } from './stores/toast.svelte';
@@ -3,7 +3,7 @@ export { filters, freeText, walk } from './ast';
3
3
  export { autoQuoteEdit, backspaceEmptyQuotes, closingQuoteExit, insideQuoteAtCaret, } from './edit';
4
4
  export { parse } from './parser';
5
5
  export { compilePredicate, serialize, serializeFilter, toSql } from './query';
6
- export type { FieldDef, FieldType, Operator, OperatorId, Schema, ValueOption, ValueProvider, } from './schema';
6
+ export type { FieldDef, FieldType, Operator, OperatorId, Schema, ValueContext, ValueOption, ValueProvider, } from './schema';
7
7
  export { defaultOperator, findField, OPERATORS, operatorByCode, operatorById, operatorsFor, resolveValues, } from './schema';
8
8
  export type { Suggestion, SuggestKind, SuggestState } from './suggest';
9
9
  export { activeToken, suggest } from './suggest';
@@ -19,8 +19,22 @@ export interface ValueOption {
19
19
  /** Optional secondary line (e.g. an email under a username). */
20
20
  hint?: string;
21
21
  }
22
+ /**
23
+ * Extra context handed to a {@link ValueProvider} alongside the value fragment:
24
+ * the full raw query, the active replacement span (`[start, end)` offsets of the
25
+ * text a chosen suggestion would replace) and the caret position. Optional so
26
+ * existing providers that only read the fragment keep working unchanged.
27
+ */
28
+ export interface ValueContext {
29
+ /** The full query string the fragment was extracted from. */
30
+ rawQuery: string;
31
+ /** `[start, end)` offsets of the token region a suggestion would replace. */
32
+ span: [number, number];
33
+ /** Absolute caret index within `rawQuery`. */
34
+ caret: number;
35
+ }
22
36
  /** Resolves candidate values for a field given the user's partial input. */
23
- export type ValueProvider = (query: string) => ValueOption[] | Promise<ValueOption[]>;
37
+ export type ValueProvider = (query: string, context?: ValueContext) => ValueOption[] | Promise<ValueOption[]>;
24
38
  export interface FieldDef {
25
39
  /** Canonical name, used in the serialised query (e.g. `artist`). */
26
40
  name: string;
@@ -57,4 +71,4 @@ export declare function findField(schema: Schema, token: string): FieldDef | und
57
71
  export declare function operatorByCode(code: string): Operator | undefined;
58
72
  export declare function operatorById(id: OperatorId): Operator | undefined;
59
73
  /** Resolve a field's value options (sync wrapper that always returns a promise). */
60
- export declare function resolveValues(field: FieldDef, query: string): Promise<ValueOption[]>;
74
+ export declare function resolveValues(field: FieldDef, query: string, context?: ValueContext): Promise<ValueOption[]>;
@@ -45,9 +45,9 @@ export function operatorById(id) {
45
45
  return OPERATORS.find((op) => op.id === id);
46
46
  }
47
47
  /** Resolve a field's value options (sync wrapper that always returns a promise). */
48
- export async function resolveValues(field, query) {
48
+ export async function resolveValues(field, query, context) {
49
49
  if (field.provider)
50
- return field.provider(query);
50
+ return field.provider(query, context);
51
51
  const opts = field.options ?? [];
52
52
  const q = query.toLowerCase();
53
53
  return q ? opts.filter((o) => o.label.toLowerCase().includes(q)) : opts;
@@ -1,4 +1,4 @@
1
- import { type Schema } from './schema';
1
+ import { type Schema } from './schema.ts';
2
2
  export type SuggestKind = 'field' | 'operator' | 'value';
3
3
  export interface Suggestion {
4
4
  /** What to show on the row. */
@@ -6,7 +6,7 @@
6
6
  //
7
7
  // This is pure logic, deliberately UI-free so the Svelte organism stays dumb.
8
8
  // ─────────────────────────────────────────────────────────────────────────
9
- import { findField, operatorsFor, resolveValues, } from './schema';
9
+ import { findField, operatorsFor, resolveValues, } from './schema.ts';
10
10
  // Longest first so `>=`/`!:` win over `>`/`:`.
11
11
  const OP_CODES = ['!:', '!=', '>=', '<=', ':', '=', '>', '<'];
12
12
  /**
@@ -164,7 +164,8 @@ export async function suggest(schema, s, pos) {
164
164
  if (!field)
165
165
  return null;
166
166
  // Operator present → suggest values (async; filtered by what's typed).
167
- const opts = await resolveValues(field, unquote(value));
167
+ const context = { rawQuery: s, span, caret: pos };
168
+ const opts = await resolveValues(field, unquote(value), context);
168
169
  if (opts.length === 0)
169
170
  return null;
170
171
  return buildValueState(field, opCode, span, opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorsk/tsumikit",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Minimal, dependency-free Svelte 5 + pure-CSS UI kit. Token-driven atoms, molecules & layouts with theming out of the box.",
5
5
  "type": "module",
6
6
  "license": "MIT",