@malloy-publisher/sdk 0.9.12 → 0.9.13

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 (68) hide show
  1. package/README.md +5 -7
  2. package/dist/{RenderedResult-CDiXJAh9.es.js → RenderedResult-DnBtf-cI.es.js} +2 -2
  3. package/dist/{RenderedResult-De51QvsZ.cjs.js → RenderedResult-DtQtNV0d.cjs.js} +1 -1
  4. package/dist/ServerProvider-BIFPCzTD.cjs.js +1 -0
  5. package/dist/{ServerProvider-RvKSbvnL.es.js → ServerProvider-BV7IoDMR.es.js} +805 -606
  6. package/dist/builder/index.cjs.js +72 -72
  7. package/dist/builder/index.es.js +4156 -4219
  8. package/dist/builder-entry.d.ts +1 -0
  9. package/dist/client/api.d.ts +178 -0
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +41 -37
  12. package/dist/components/Report/telemetry.d.ts +0 -5
  13. package/dist/components/ReportBuilder/BuilderBar.d.ts +1 -1
  14. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +14 -10
  15. package/dist/components/ReportBuilder/EditorSurface.d.ts +1 -2
  16. package/dist/components/ReportBuilder/ReportBuilder.d.ts +3 -10
  17. package/dist/components/ReportBuilder/ReportEditor.d.ts +2 -9
  18. package/dist/components/ReportBuilder/SaveStatus.d.ts +16 -0
  19. package/dist/components/ReportBuilder/TileFrame.d.ts +9 -2
  20. package/dist/components/ReportBuilder/builderControls.d.ts +14 -6
  21. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  22. package/dist/components/ReportBuilder/useReportDraft.d.ts +6 -2
  23. package/dist/components/given/GivenInput.d.ts +18 -1
  24. package/dist/components/given/GivensPanel.d.ts +12 -1
  25. package/dist/components/given/useOptionSearch.d.ts +30 -0
  26. package/dist/hooks/index.d.ts +1 -1
  27. package/dist/hooks/useDocumentControls.d.ts +5 -0
  28. package/dist/hooks/useGivensState.d.ts +7 -0
  29. package/dist/hooks/useSuggestOptions.d.ts +60 -4
  30. package/dist/index.cjs.js +1 -1
  31. package/dist/index.es.js +5 -5
  32. package/dist/{useCompiledDocument-Bf4RSfB6.es.js → useCompiledDocument-B4QF1mIl.es.js} +6912 -6759
  33. package/dist/useCompiledDocument-D0OAMejE.cjs.js +142 -0
  34. package/package.json +1 -1
  35. package/src/builder-entry.ts +1 -0
  36. package/src/components/Report/ReportPage.tsx +5 -1
  37. package/src/components/Report/telemetry.ts +0 -6
  38. package/src/components/ReportBuilder/AddTileDialog.tsx +2 -2
  39. package/src/components/ReportBuilder/BuilderBar.tsx +5 -256
  40. package/src/components/ReportBuilder/BuilderHeader.tsx +9 -3
  41. package/src/components/ReportBuilder/BuilderToolbar.tsx +15 -38
  42. package/src/components/ReportBuilder/EditorSurface.tsx +0 -3
  43. package/src/components/ReportBuilder/FilterDialog.tsx +1 -1
  44. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +210 -24
  45. package/src/components/ReportBuilder/ReportBuilder.tsx +43 -85
  46. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +0 -36
  47. package/src/components/ReportBuilder/ReportEditor.tsx +2 -13
  48. package/src/components/ReportBuilder/SaveStatus.tsx +271 -0
  49. package/src/components/ReportBuilder/TileFrame.spec.ts +34 -0
  50. package/src/components/ReportBuilder/TileFrame.tsx +10 -3
  51. package/src/components/ReportBuilder/builderControls.ts +39 -13
  52. package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
  53. package/src/components/ReportBuilder/useReportDraft.ts +38 -4
  54. package/src/components/given/GivenInput.tsx +219 -104
  55. package/src/components/given/GivensPanel.spec.tsx +19 -0
  56. package/src/components/given/GivensPanel.tsx +31 -1
  57. package/src/components/given/useOptionSearch.spec.tsx +218 -0
  58. package/src/components/given/useOptionSearch.ts +100 -0
  59. package/src/hooks/index.ts +5 -1
  60. package/src/hooks/useDocumentControls.ts +12 -1
  61. package/src/hooks/useGivensState.spec.ts +54 -0
  62. package/src/hooks/useGivensState.ts +21 -1
  63. package/src/hooks/useSuggestOptions.dom.spec.ts +125 -4
  64. package/src/hooks/useSuggestOptions.spec.ts +73 -2
  65. package/src/hooks/useSuggestOptions.ts +234 -62
  66. package/dist/ServerProvider-DKrBcXL7.cjs.js +0 -1
  67. package/dist/useCompiledDocument-XsQz85Ri.cjs.js +0 -141
  68. package/src/components/ReportBuilder/ReportBuilder.layoutSwitch.spec.tsx +0 -145
@@ -1,5 +1,7 @@
1
1
  import { Given } from '../../client';
2
2
  import { GivenValue } from '../../hooks/givenValue';
3
+ import { OptionSearch } from '../../hooks/useSuggestOptions';
4
+ import { OptionSearchState } from './useOptionSearch';
3
5
  export interface GivenInputProps {
4
6
  /**
5
7
  * The declaration, which carries its own presentation (`label`, `control`,
@@ -28,6 +30,16 @@ export interface GivenInputProps {
28
30
  * Free text still works, so the control degrades rather than locking up.
29
31
  */
30
32
  optionsFailed?: boolean;
33
+ /**
34
+ * The option list was cut off: more values exist than `options` holds. The
35
+ * dropdown says so, since a value missing from it may still be in the data.
36
+ */
37
+ optionsTruncated?: boolean;
38
+ /**
39
+ * Search the whole dimension on the server as the reader types, for a list
40
+ * that was cut off. Absent, typing filters `options` in the browser.
41
+ */
42
+ optionSearch?: OptionSearch;
31
43
  }
32
44
  /**
33
45
  * Renders an input widget appropriate for the declared given type.
@@ -49,4 +61,9 @@ export interface GivenInputProps {
49
61
  * `Default: …` helper line on every widget — including the boolean checkbox,
50
62
  * which gets a wrapping FormControl for the slot.
51
63
  */
52
- export declare function GivenInput({ given, value, onChange, options, optionsLoading, optionsFailed, }: GivenInputProps): import("react/jsx-runtime").JSX.Element;
64
+ export declare function GivenInput({ given, value, onChange, options, optionsLoading, optionsFailed, optionsTruncated, optionSearch, }: GivenInputProps): import("react/jsx-runtime").JSX.Element;
65
+ /**
66
+ * What the dropdown says about its options, if anything. Only a cut-off list
67
+ * has something to say: a whole list needs no footnote.
68
+ */
69
+ export declare function optionHint(search: OptionSearchState, truncated: boolean | undefined, searchable: OptionSearch | undefined): string | undefined;
@@ -1,5 +1,6 @@
1
1
  import { Given } from '../../client';
2
2
  import { GivenValue } from '../../hooks/givenValue';
3
+ import { OptionSearch } from '../../hooks/useSuggestOptions';
3
4
  /**
4
5
  * How the control row is laid out.
5
6
  *
@@ -17,12 +18,22 @@ export interface GivensPanelProps {
17
18
  values: Map<string, GivenValue>;
18
19
  onChange: (name: string, value: GivenValue) => void;
19
20
  onReset: () => void;
21
+ /**
22
+ * Whether Reset would change anything: the controls differ from where the
23
+ * document starts them (`useGivensState`'s `atStart`). Absent, Reset is
24
+ * offered whenever a value is set, as before.
25
+ */
26
+ canReset?: boolean;
20
27
  layout?: GivensLayout;
21
28
  /** Resolved `suggest` options per given name. */
22
29
  options?: Map<string, string[]>;
23
30
  optionsLoading?: boolean;
24
31
  /** Givens whose `suggest` query failed, from `useSuggestOptions.failed`. */
25
32
  optionsFailed?: ReadonlySet<string>;
33
+ /** Givens whose option list was cut off, from `useSuggestOptions.truncated`. */
34
+ optionsTruncated?: ReadonlySet<string>;
35
+ /** Server search for a cut-off list, per given, from `useSuggestOptions.search`. */
36
+ optionSearch?: ReadonlyMap<string, OptionSearch>;
26
37
  /**
27
38
  * Set to render an Apply button, for `autorun=false`. Absent means controls
28
39
  * take effect as they change, which is the default everywhere.
@@ -45,4 +56,4 @@ export interface GivensPanelProps {
45
56
  * puts the document's starting values back rather than emptying the row, so the
46
57
  * button and the state agree on what "Reset" means.
47
58
  */
48
- export declare function GivensPanel({ givens, values, onChange, onReset, layout, options, optionsLoading, optionsFailed, apply, title, }: GivensPanelProps): import("react/jsx-runtime").JSX.Element;
59
+ export declare function GivensPanel({ givens, values, onChange, onReset, canReset, layout, options, optionsLoading, optionsFailed, optionsTruncated, optionSearch, apply, title, }: GivensPanelProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { OptionPage, OptionSearch } from '../../hooks/useSuggestOptions';
2
+ /** How long typing has to pause before the server is asked. */
3
+ export declare const OPTION_SEARCH_DEBOUNCE_MS = 250;
4
+ export interface OptionSearchState {
5
+ /** Text is typed and the list is cut off, so what is offered comes from the server. */
6
+ active: boolean;
7
+ /** Waiting on the server for the text as it is now: still debouncing, or in flight. */
8
+ searching: boolean;
9
+ /** The server's answer for exactly the text as it is now. Undefined until it has one. */
10
+ page: OptionPage | undefined;
11
+ /** The search for the text as it is now failed. */
12
+ failed: boolean;
13
+ }
14
+ /**
15
+ * Search a cut-off option list on the server as the reader types.
16
+ *
17
+ * Without `search` (a list that was not cut off, or a named query that cannot
18
+ * be searched) this is inert and sends nothing: the picker filters the list it
19
+ * has in the browser, as before.
20
+ *
21
+ * Each search is cached under the suggest's key plus the text, in the page's
22
+ * query client, so typing back to an earlier text reuses its answer. An answer
23
+ * is shown only for the text it was asked for: one arriving after the reader
24
+ * has typed on is dropped, never shown over the newer text's.
25
+ *
26
+ * Reads the query client from context rather than requiring one: a picker
27
+ * rendered outside a provider (a test, a host without react-query) has no
28
+ * cache, and gets no server search rather than an error.
29
+ */
30
+ export declare function useOptionSearch(search: OptionSearch | undefined, typed: string): OptionSearchState;
@@ -5,7 +5,7 @@ export { useDimensionalFilterRangeData, getDimensionKey, type DimensionalFilterR
5
5
  export { useModelGivens } from './useModelGivens';
6
6
  export { type GivenValue } from './givenValue';
7
7
  export { useGivensState, type UseGivensStateOptions, type UseGivensStateResult, } from './useGivensState';
8
- export { useSuggestOptions } from './useSuggestOptions';
8
+ export { type OptionPage, type OptionSearch, useSuggestOptions, } from './useSuggestOptions';
9
9
  export { useCompiledDocument, type CompiledDocumentSpec, } from './useCompiledDocument';
10
10
  export { queryResultKey, useQueryResult, type QueryRequestSpec, type QueryResultState, } from './useQueryResult';
11
11
  export { useDocumentControls, type DocumentControls, type UseDocumentControlsOptions, } from './useDocumentControls';
@@ -2,6 +2,7 @@ import { Given } from '../client';
2
2
  import { HostGivenValue } from './givenValue';
3
3
  import { GivensPanelProps } from '../components/given/GivensPanel';
4
4
  import { UseGivensStateResult } from './useGivensState';
5
+ import { OptionSearch } from './useSuggestOptions';
5
6
  /**
6
7
  * Everything a document's control row needs, from what the document declares.
7
8
  *
@@ -65,6 +66,10 @@ export interface DocumentControls extends UseGivensStateResult {
65
66
  options: Map<string, string[]>;
66
67
  optionsLoading: boolean;
67
68
  optionsFailed: ReadonlySet<string>;
69
+ /** Givens whose option list was cut off; see `useSuggestOptions`. */
70
+ optionsTruncated: ReadonlySet<string>;
71
+ /** Server search for a truncated list, per given. */
72
+ optionSearch: ReadonlyMap<string, OptionSearch>;
68
73
  /** For `useDrill`: whether a `to=self` on this given can be honoured. */
69
74
  canSelf: (given: string) => boolean;
70
75
  /** For `useDrill`: set the given to the clicked value, encoded for its type. */
@@ -60,5 +60,12 @@ export interface UseGivensStateResult {
60
60
  apply: () => void;
61
61
  /** Whether the draft differs from what is applied. */
62
62
  pending: boolean;
63
+ /**
64
+ * Whether the controls, shown and applied, are already where Reset would
65
+ * put them. A surface offers Reset only when this is false: a report that
66
+ * saves a starting value showed Reset beside it, and pressing it set the
67
+ * controls to what they already were, so the button looked broken.
68
+ */
69
+ atStart: boolean;
63
70
  }
64
71
  export declare function useGivensState({ declaredTypes, startingValues, params, onParamsChange, documentKey, autorun, }: UseGivensStateOptions): UseGivensStateResult;
@@ -7,11 +7,39 @@ import { GivenValue, HostGivenValue } from './givenValue';
7
7
  * is also 1000 but caps silently and in whatever order the warehouse returns.
8
8
  * An explicit limit with an explicit order makes a truncated list the same list
9
9
  * every time, and makes the cap something a reader of this file can see.
10
- * A dimension with more distinct values than this needs a hand-written
11
- * `suggest { query=… }`: a picker over thousands of options is the wrong
12
- * control anyway.
10
+ * The query asks for one row more than this, so a list that was cut off is
11
+ * known to be (`truncated`), not guessed from a count that happens to land on
12
+ * the limit. Past the limit, typing in the picker searches the whole dimension
13
+ * on the server instead of filtering the first thousand: see
14
+ * {@link OptionSearch}.
13
15
  */
14
16
  export declare const SUGGEST_OPTION_LIMIT = 1000;
17
+ /** How many matches a search of the server returns: enough to scan, and the hint says to keep typing past it. */
18
+ export declare const SUGGEST_SEARCH_LIMIT = 200;
19
+ /** One fetch of options: the values, and whether there were more than it holds. */
20
+ export interface OptionPage {
21
+ values: string[];
22
+ /** More rows matched than the page holds, so values past it are not offered. */
23
+ truncated: boolean;
24
+ }
25
+ /**
26
+ * Search a truncated option list on the server: for a control whose suggest
27
+ * came back cut off at {@link SUGGEST_OPTION_LIMIT}, so filtering in the
28
+ * browser would only ever find values in the first thousand.
29
+ *
30
+ * `key` identifies the suggest (its report, version, source, dimension, the
31
+ * givens it carries and a text source's definitions); a caller caches each
32
+ * search under it plus the text searched for. `run` sends the same suggest with
33
+ * a case-insensitive "contains" on the dimension.
34
+ *
35
+ * Only a suggest over a dimension has one: a named `suggest { query=… }` is a
36
+ * whole query, with nowhere to add a condition, so its list is filtered in the
37
+ * browser and says it was cut off.
38
+ */
39
+ export interface OptionSearch {
40
+ key: readonly unknown[];
41
+ run: (text: string, signal?: AbortSignal) => Promise<OptionPage>;
42
+ }
15
43
  /**
16
44
  * The query a `suggest { source=… dimension=… }` runs.
17
45
  *
@@ -20,7 +48,17 @@ export declare const SUGGEST_OPTION_LIMIT = 1000;
20
48
  * itself, and this text has already been wrong once: `order_by` takes an output
21
49
  * field name, not a path, so a joined dimension failed the query outright.
22
50
  */
23
- export declare function buildSuggestQuery(source: string, dimension: string): string;
51
+ export declare function buildSuggestQuery(source: string, dimension: string,
52
+ /** Text the values must contain, ignoring case: a search of a truncated list. */
53
+ search?: string): string;
54
+ /**
55
+ * Text as a Malloy string literal, whatever it holds: a backslash and a
56
+ * single quote escaped, in that order, so neither can end the literal early.
57
+ * Control characters are dropped: a search box has no use for them, and a raw
58
+ * newline is not legal inside a literal. Nothing else is special inside
59
+ * single quotes, so `%`, `_`, `{`, `$` and the rest stay literal text.
60
+ */
61
+ export declare function malloyStringLiteral(text: string): string;
24
62
  /**
25
63
  * Resolve the option lists behind `select` / `multiselect` controls.
26
64
  *
@@ -84,7 +122,25 @@ preamble?: string): {
84
122
  * an empty picker has no way to tell which they are looking at.
85
123
  */
86
124
  failed: Set<string>;
125
+ /**
126
+ * Givens whose list was cut off: more values exist than were fetched. For
127
+ * a suggest over a dimension, `search` can find the rest; for a named
128
+ * query it cannot, and the picker says the list is partial.
129
+ */
130
+ truncated: Set<string>;
131
+ /** Server search, per given, for a truncated suggest over a dimension. */
132
+ search: Map<string, OptionSearch>;
87
133
  };
134
+ /**
135
+ * One fetch's options and whether it was cut off. `limit` is what the page
136
+ * holds; a generated query asked for one row more, so a row past it means
137
+ * more exist. `cutOffAt` instead marks a page as cut off once it reaches that
138
+ * many rows, for a named query whose own limit is unknown.
139
+ */
140
+ export declare function readOptionPage(result: string | undefined, dimension: string | undefined, { limit, cutOffAt }: {
141
+ limit: number;
142
+ cutOffAt?: number;
143
+ }): OptionPage;
88
144
  /**
89
145
  * Pull the option strings out of a compact-JSON result.
90
146
  *