@malloy-publisher/sdk 0.9.15 → 0.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.
Files changed (94) hide show
  1. package/dist/{RenderedResult-BClN_PG6.cjs.js → RenderedResult-B5f4qOjp.cjs.js} +21 -4
  2. package/dist/{RenderedResult-YBzVMVH2.es.js → RenderedResult-DiDsN6JE.es.js} +204 -187
  3. package/dist/builder/index.cjs.js +75 -75
  4. package/dist/builder/index.es.js +5304 -5156
  5. package/dist/builder-entry.d.ts +1 -1
  6. package/dist/client/api.d.ts +1 -1
  7. package/dist/components/Dashboard/DashboardGrid.d.ts +2 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
  9. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  10. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  11. package/dist/components/RenderedResult/resultSizing.d.ts +5 -0
  12. package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
  13. package/dist/components/ReportBuilder/BuilderGrid.d.ts +5 -7
  14. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
  15. package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
  16. package/dist/components/ReportBuilder/TextTileBody.d.ts +9 -2
  17. package/dist/components/ReportBuilder/TileFrame.d.ts +34 -22
  18. package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
  19. package/dist/components/ReportBuilder/placement.d.ts +48 -2
  20. package/dist/components/ReportBuilder/sortable.d.ts +9 -0
  21. package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
  22. package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
  23. package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
  24. package/dist/components/ReportBuilder/useTileReorder.d.ts +3 -0
  25. package/dist/components/legacy/malloynb/CellRunnerView.d.ts +6 -6
  26. package/dist/hooks/useSettled.d.ts +5 -8
  27. package/dist/hooks/useSettledDraft.d.ts +33 -0
  28. package/dist/index.cjs.js +10 -10
  29. package/dist/index.es.js +3861 -3870
  30. package/dist/theme/classes.d.ts +1 -1
  31. package/dist/useCompiledDocument-C995sQ3j.cjs.js +142 -0
  32. package/dist/{useCompiledDocument-BGk38oaW.es.js → useCompiledDocument-CRmmbUza.es.js} +6426 -6257
  33. package/dist/utils/malloyLiteral.d.ts +2 -0
  34. package/package.json +11 -16
  35. package/src/builder-entry.ts +1 -0
  36. package/src/components/Dashboard/DashboardGrid.tsx +2 -0
  37. package/src/components/Dashboard/DashboardTile.tsx +4 -0
  38. package/src/components/Dashboard/DashboardView.tsx +1 -0
  39. package/src/components/RenderedResult/RenderedResult.tsx +18 -0
  40. package/src/components/RenderedResult/ResultContainer.tsx +39 -3
  41. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  42. package/src/components/RenderedResult/resultSizing.ts +6 -0
  43. package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
  44. package/src/components/ReportBuilder/BuilderBar.tsx +4 -0
  45. package/src/components/ReportBuilder/BuilderDialogs.tsx +8 -1
  46. package/src/components/ReportBuilder/BuilderGrid.tsx +62 -60
  47. package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
  48. package/src/components/ReportBuilder/EditorSurface.tsx +9 -2
  49. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +99 -0
  50. package/src/components/ReportBuilder/ReportBuilder.tsx +110 -30
  51. package/src/components/ReportBuilder/TextTileBody.tsx +24 -4
  52. package/src/components/ReportBuilder/TileFrame.tsx +261 -310
  53. package/src/components/ReportBuilder/builderControls.ts +34 -0
  54. package/src/components/ReportBuilder/placement.spec.ts +235 -0
  55. package/src/components/ReportBuilder/placement.ts +179 -9
  56. package/src/components/ReportBuilder/readDocument.spec.ts +7 -17
  57. package/src/components/ReportBuilder/readDocument.ts +3 -6
  58. package/src/components/ReportBuilder/sortable.tsx +26 -2
  59. package/src/components/ReportBuilder/spliceDocument.spec.ts +0 -40
  60. package/src/components/ReportBuilder/spliceDocument.ts +0 -39
  61. package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
  62. package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
  63. package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
  64. package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
  65. package/src/components/ReportBuilder/useTileReorder.ts +1 -1
  66. package/src/components/given/GivenInput.spec.tsx +447 -2
  67. package/src/components/given/GivenInput.tsx +192 -80
  68. package/src/components/given/GivensPanel.spec.tsx +59 -0
  69. package/src/components/given/GivensPanel.tsx +14 -2
  70. package/src/components/legacy/malloynb/CellRunnerView.tsx +6 -6
  71. package/src/hooks/useDimensionFilters.ts +1 -35
  72. package/src/hooks/useDimensionFiltersQuery.ts +2 -36
  73. package/src/hooks/useDimensionalFilterRangeData.ts +1 -35
  74. package/src/hooks/useGivensState.spec.ts +106 -1
  75. package/src/hooks/useGivensState.ts +48 -13
  76. package/src/hooks/useSettled.ts +5 -8
  77. package/src/hooks/useSettledDraft.ts +127 -0
  78. package/src/theme/classes.ts +1 -1
  79. package/src/utils/malloyLiteral.spec.ts +12 -1
  80. package/src/utils/malloyLiteral.ts +32 -0
  81. package/vite.config.ts +0 -2
  82. package/.eslintrc +0 -36
  83. package/dist/components/DOMElement/DOMElement.d.ts +0 -5
  84. package/dist/components/DOMElement/index.d.ts +0 -1
  85. package/dist/components/Package/FileTreeView.d.ts +0 -9
  86. package/dist/components/ReportBuilder/useTileHeight.d.ts +0 -39
  87. package/dist/components/ReportBuilder/useTileResize.d.ts +0 -40
  88. package/dist/useCompiledDocument-D9t5ry_t.cjs.js +0 -142
  89. package/src/components/DOMElement/DOMElement.tsx +0 -22
  90. package/src/components/DOMElement/index.ts +0 -4
  91. package/src/components/Package/FileTreeView.tsx +0 -244
  92. package/src/components/ReportBuilder/useTileHeight.ts +0 -149
  93. package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
  94. package/src/components/ReportBuilder/useTileResize.ts +0 -148
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { act, renderHook } from "@testing-library/react";
5
- import { describe, expect, it } from "bun:test";
5
+ import { StrictMode } from "react";
6
+ import { afterEach, describe, expect, it, setSystemTime } from "bun:test";
6
7
  import { useGivensState } from "./useGivensState";
7
8
 
8
9
  const TYPES = new Map<string, string | undefined>([
@@ -645,6 +646,110 @@ describe("useGivensState: clearing a given that has a starting value", () => {
645
646
  expect(entries(result.current.applied)).toEqual({ REGION: "East" });
646
647
  });
647
648
 
649
+ it("keeps the newest edit when a URL two reports old arrives late", () => {
650
+ let url: Record<string, string> = {};
651
+ const { result, rerender } = renderHook(
652
+ (props: { params: Record<string, string> }) =>
653
+ useGivensState({
654
+ declaredTypes: TYPES,
655
+ params: props.params,
656
+ onParamsChange: (next) => {
657
+ url = next;
658
+ },
659
+ documentKey: "dashboard",
660
+ autorun: true,
661
+ }),
662
+ { initialProps: { params: url } },
663
+ );
664
+
665
+ const reportedUrls: Record<string, string>[] = [];
666
+ for (const typed of ["F", "Fo", "For"]) {
667
+ act(() => result.current.setGiven("REGION", typed));
668
+ reportedUrls.push(url);
669
+ }
670
+
671
+ // The host delivers them late and in order, the oldest first.
672
+ for (const arriving of reportedUrls) {
673
+ rerender({ params: arriving });
674
+ expect(entries(result.current.applied)).toEqual({ REGION: "For" });
675
+ }
676
+ });
677
+
678
+ it("keeps the newest edit through repeated renders at a stale URL", () => {
679
+ let url: Record<string, string> = {};
680
+ const { result, rerender } = renderHook(
681
+ (props: { params: Record<string, string> }) =>
682
+ useGivensState({
683
+ declaredTypes: TYPES,
684
+ params: props.params,
685
+ onParamsChange: (next) => {
686
+ url = next;
687
+ },
688
+ documentKey: "dashboard",
689
+ autorun: true,
690
+ }),
691
+ { initialProps: { params: url }, wrapper: StrictMode },
692
+ );
693
+
694
+ const reportedUrls: Record<string, string>[] = [];
695
+ for (const typed of ["F", "Fo", "For"]) {
696
+ act(() => result.current.setGiven("REGION", typed));
697
+ reportedUrls.push(url);
698
+ }
699
+
700
+ // The first report lands, and the host re-renders for its own reasons
701
+ // before the next one does.
702
+ for (let i = 0; i < 3; i++) {
703
+ rerender({ params: reportedUrls[0] });
704
+ expect(entries(result.current.applied)).toEqual({ REGION: "For" });
705
+ }
706
+ rerender({ params: reportedUrls[1] });
707
+ rerender({ params: reportedUrls[1] });
708
+ expect(entries(result.current.applied)).toEqual({ REGION: "For" });
709
+ });
710
+
711
+ describe("a report that was replaced before its URL landed", () => {
712
+ afterEach(() => setSystemTime());
713
+
714
+ const mount = (documentKey = "dashboard") => {
715
+ let url: Record<string, string> = {};
716
+ const view = renderHook(
717
+ (props: { params: Record<string, string>; documentKey: string }) =>
718
+ useGivensState({
719
+ declaredTypes: TYPES,
720
+ params: props.params,
721
+ onParamsChange: (next) => {
722
+ url = next;
723
+ },
724
+ documentKey: props.documentKey,
725
+ autorun: true,
726
+ }),
727
+ { initialProps: { params: url, documentKey } },
728
+ );
729
+ // Set, then cleared, before the URL for the first lands.
730
+ act(() => view.result.current.setGiven("REGION", "F"));
731
+ act(() => view.result.current.setGiven("REGION", null));
732
+ return view;
733
+ };
734
+
735
+ it("stops reading a later push that repeats it as an echo", () => {
736
+ setSystemTime(1_000_000);
737
+ const { result, rerender } = mount();
738
+ rerender({ params: {}, documentKey: "dashboard" });
739
+ setSystemTime(1_005_000);
740
+ rerender({ params: { REGION: "F" }, documentKey: "dashboard" });
741
+ expect(entries(result.current.applied)).toEqual({ REGION: "F" });
742
+ });
743
+
744
+ it("is forgotten when the document changes", () => {
745
+ setSystemTime(1_000_000);
746
+ const { result, rerender } = mount();
747
+ rerender({ params: {}, documentKey: "other" });
748
+ rerender({ params: { REGION: "F" }, documentKey: "other" });
749
+ expect(entries(result.current.applied)).toEqual({ REGION: "F" });
750
+ });
751
+ });
752
+
648
753
  it("Reset after a clear restores the starting value and runs once", () => {
649
754
  const host = renderWithUrlHost({
650
755
  autorun: true,
@@ -130,6 +130,11 @@ function sameDeclaredParams(
130
130
  return true;
131
131
  }
132
132
 
133
+ /** Bounds the reports remembered as in flight when a host never echoes them. */
134
+ const MAX_IN_FLIGHT_REPORTS = 32;
135
+ // How long a superseded report can still be told apart from a push that repeats it.
136
+ const IN_FLIGHT_REPORT_MS = 1500;
137
+
133
138
  /** Same entries, same values: enough for state whose values are primitives. */
134
139
  function sameParams(
135
140
  a: Record<string, string>,
@@ -163,7 +168,7 @@ export function useGivensState({
163
168
  // mount reads as an echo.
164
169
  const lastReported = useRef<Record<string, string> | null>(null);
165
170
 
166
- // The report BEFORE `lastReported`, kept only until the newer one is seen
171
+ // The reports BEFORE `lastReported`, kept only until the newer one is seen
167
172
  // coming back.
168
173
  //
169
174
  // A report does not reach `params` in the same tick: the host navigates, the
@@ -175,12 +180,18 @@ export function useGivensState({
175
180
  // the edits were discarded, and `initial` put the value the reader had just
176
181
  // cleared straight back into the control, and into the URL after it.
177
182
  //
178
- // Narrow by construction: it holds one report, only while that report is in
179
- // flight, and is dropped the moment the newer one is observed. The cost is
183
+ // Narrow by construction: it holds the reports still in flight (several when
184
+ // a control reports faster than the URL lands), and drops each as the URL
185
+ // moves past it. The cost is
180
186
  // that an external push landing in that window whose values happen to equal
181
- // the report being replaced is taken for the echo — the same values we were
187
+ // a report being replaced is taken for the echo — the same values we were
182
188
  // just showing, arriving in the few milliseconds before our own URL lands.
183
- const priorReported = useRef<Record<string, string> | null>(null);
189
+ // A value that repeats while in flight (A, B, A) matches its oldest report,
190
+ // so B stays in flight until the next report lands.
191
+ const priorReported = useRef<
192
+ { params: Record<string, string>; at: number }[]
193
+ >([]);
194
+ const lastReportedAt = useRef(0);
184
195
 
185
196
  // The URL that defines the current starting point. This is `params` EXCEPT
186
197
  // when `params` is our own report arriving back through the host, which is
@@ -211,17 +222,32 @@ export function useGivensState({
211
222
  const echoes = (reported: Record<string, string> | null) =>
212
223
  reported !== null &&
213
224
  sameDeclaredParams(params ?? {}, reported, declaredTypes);
214
- // The newest report has arrived, so the one it replaced is no longer in
215
- // flight and stops counting as an echo.
216
- if (echoes(lastReported.current)) priorReported.current = null;
225
+ // The oldest report still in flight that `params` matches. Reports are
226
+ // delivered in order, so those before it are gone for good and it stays
227
+ // until the URL moves past it: a re-render at the same URL is idempotent.
228
+ // An entry older than the window is dropped: a URL that repeats it then is
229
+ // a push (Back, a drill), not a straggler.
230
+ const now = Date.now();
231
+ priorReported.current = priorReported.current.filter(
232
+ (r) => now - r.at < IN_FLIGHT_REPORT_MS,
233
+ );
234
+ const inFlight =
235
+ lastReported.current === null
236
+ ? priorReported.current.map((r) => r.params)
237
+ : [
238
+ ...priorReported.current.map((r) => r.params),
239
+ lastReported.current,
240
+ ];
241
+ const arrived = inFlight.findIndex(echoes);
242
+ if (anchor.current.documentKey !== documentKey) priorReported.current = [];
217
243
  if (
218
244
  anchor.current.documentKey !== documentKey ||
219
- (!sameParams(params ?? {}, anchor.current.params ?? {}) &&
220
- !echoes(lastReported.current) &&
221
- !echoes(priorReported.current))
245
+ (!sameParams(params ?? {}, anchor.current.params ?? {}) && arrived < 0)
222
246
  ) {
223
247
  anchor.current = { documentKey, params };
224
248
  }
249
+ if (arrived > 0)
250
+ priorReported.current = priorReported.current.slice(arrived);
225
251
  const anchorParams = anchor.current.params;
226
252
  const startingValuesKey = JSON.stringify(startingValues);
227
253
  const anchorParamsKey = JSON.stringify(anchorParams);
@@ -363,7 +389,10 @@ export function useGivensState({
363
389
  () => givensToParams(applied, declaredTypes),
364
390
  [applied, declaredTypes],
365
391
  );
366
- if (lastReported.current === null) lastReported.current = appliedParams;
392
+ if (lastReported.current === null) {
393
+ lastReported.current = appliedParams;
394
+ lastReportedAt.current = Date.now();
395
+ }
367
396
  // Recorded only when the report is actually DELIVERED. A surface withholds
368
397
  // the callback while it is still loading — `Notebook` passes undefined until
369
398
  // the document has arrived, so that a report made in the window where it
@@ -384,8 +413,14 @@ export function useGivensState({
384
413
  useEffect(() => {
385
414
  if (!onParamsChange) return;
386
415
  if (sameParams(lastReported.current ?? {}, appliedParams)) return;
387
- priorReported.current = lastReported.current;
416
+ if (lastReported.current !== null) {
417
+ priorReported.current = [
418
+ ...priorReported.current.slice(-MAX_IN_FLIGHT_REPORTS + 1),
419
+ { params: lastReported.current, at: lastReportedAt.current },
420
+ ];
421
+ }
388
422
  lastReported.current = appliedParams;
423
+ lastReportedAt.current = Date.now();
389
424
  onParamsChange(appliedParams);
390
425
  }, [appliedParams, onParamsChange]);
391
426
 
@@ -4,15 +4,12 @@
4
4
  import { useEffect, useState } from "react";
5
5
 
6
6
  /**
7
- * How long a changed parameter has to stay changed before the notebook runs.
7
+ * How long a changed value has to stay changed before it is acted on: a given
8
+ * input commits after it, and the notebook waits it again before running.
8
9
  *
9
- * Aborting the superseded run is not enough on its own: an abort cancels the
10
- * HTTP request, but the cells already dispatched have reached the server and go
11
- * on compiling and running against the customer's warehouse, and their answers
12
- * are then thrown away. So autorun on a text control put one wave of doomed
13
- * queries on that warehouse per keystroke. `origin/main` bounded the load by
14
- * refusing to start a second run at all, which dropped the newest values;
15
- * waiting for the value to settle bounds it without making that trade.
10
+ * Aborting a superseded run is not enough on its own: an abort cancels the
11
+ * HTTP request, but cells already dispatched have reached the server and go on
12
+ * running against the customer's warehouse, and their answers are thrown away.
16
13
  */
17
14
  export const GIVEN_SETTLE_MS = 400;
18
15
 
@@ -0,0 +1,127 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ type KeyboardEvent,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ } from "react";
11
+ import { GIVEN_SETTLE_MS, useSettled } from "./useSettled";
12
+
13
+ /**
14
+ * A control's own copy of a value that is applied the moment it is committed.
15
+ *
16
+ * A draft the reader has edited is the source of truth while the field is
17
+ * focused, so a value echoing back from the URL cannot overwrite keystrokes
18
+ * typed since; a field the reader has not edited follows `committed`. An edited
19
+ * draft commits on blur, on Enter, and once it has settled (not mid-IME
20
+ * composition), each only if it differs from `committed`. A change made while
21
+ * the field is not focused (a calendar pick) commits at once. Mount and an
22
+ * untouched focus never commit.
23
+ *
24
+ * `unset` says `committed` is the empty display of a value that was never
25
+ * set, so an edit that lands back on that display still commits it: the
26
+ * reader emptied the field on purpose.
27
+ */
28
+ export function useSettledDraft<T>(
29
+ committed: T,
30
+ commit: (draft: T) => void,
31
+ {
32
+ same = Object.is,
33
+ unset = false,
34
+ }: { same?: (a: T, b: T) => boolean; unset?: boolean } = {},
35
+ ) {
36
+ const [draft, setDraft] = useState(committed);
37
+ const [focused, setFocused] = useState(false);
38
+ // A ref, set synchronously, so an unmount in the same batch as a reset sees it.
39
+ const edited = useRef(false);
40
+ // What was last committed, until `committed` catches up with it: a draft
41
+ // that equals the stale `committed` meanwhile has still been edited.
42
+ const sent = useRef<{ value: T } | null>(null);
43
+ const composing = useRef(false);
44
+ const latest = useRef({ draft, committed, focused, unset, commit, same });
45
+ useEffect(() => {
46
+ latest.current = { draft, committed, focused, unset, commit, same };
47
+ });
48
+
49
+ const due = () => {
50
+ const l = latest.current;
51
+ const shown = sent.current ? sent.current.value : l.committed;
52
+ return edited.current && (l.unset || !l.same(l.draft, shown));
53
+ };
54
+ const send = () => {
55
+ const l = latest.current;
56
+ sent.current = { value: l.draft };
57
+ l.commit(l.draft);
58
+ // The draft is already what is on screen: nothing is left to protect.
59
+ if (l.unset && l.same(l.draft, l.committed)) edited.current = false;
60
+ };
61
+ const flush = () => {
62
+ if (due()) send();
63
+ };
64
+
65
+ // Composition end bumps `gen` so a draft that settled mid-composition is
66
+ // re-armed: the confirming input event repeats the tracked text, so the
67
+ // draft alone would not change.
68
+ const [gen, setGen] = useState(0);
69
+ const pending = useMemo(() => ({ draft, gen }), [draft, gen]);
70
+ const settled = useSettled(pending, GIVEN_SETTLE_MS);
71
+ useEffect(() => {
72
+ const l = latest.current;
73
+ if (l.same(settled.draft, l.draft) && due() && !composing.current) {
74
+ send();
75
+ }
76
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `due`/`send` read refs only
77
+ }, [settled]);
78
+
79
+ // A pending draft is committed rather than dropped if the field goes away.
80
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `flush` reads refs only
81
+ useEffect(() => () => flush(), []);
82
+
83
+ useEffect(() => {
84
+ if (sent.current && same(sent.current.value, committed)) {
85
+ sent.current = null;
86
+ }
87
+ if (same(draft, committed)) {
88
+ if (!unset && !sent.current) edited.current = false;
89
+ return;
90
+ }
91
+ if (!focused || !edited.current) setDraft(committed);
92
+ }, [committed, focused, draft, unset, same]);
93
+
94
+ return {
95
+ draft,
96
+ /** Show `next` as typed; applies it now if the field is not focused. */
97
+ change: (next: T) => {
98
+ edited.current = true;
99
+ setDraft(next);
100
+ if (!latest.current.focused && !same(next, committed)) commit(next);
101
+ },
102
+ /** Drop the draft for `next` without committing, for a clear. */
103
+ reset: (next: T) => {
104
+ edited.current = false;
105
+ sent.current = null;
106
+ setDraft(next);
107
+ },
108
+ bind: {
109
+ onFocus: () => setFocused(true),
110
+ onBlur: () => {
111
+ setFocused(false);
112
+ flush();
113
+ sent.current = null;
114
+ },
115
+ onKeyDown: (e: KeyboardEvent) => {
116
+ if (e.key === "Enter" && !e.nativeEvent.isComposing) flush();
117
+ },
118
+ onCompositionStart: () => {
119
+ composing.current = true;
120
+ },
121
+ onCompositionEnd: () => {
122
+ composing.current = false;
123
+ setGen((g) => g + 1);
124
+ },
125
+ },
126
+ };
127
+ }
@@ -38,7 +38,7 @@ export const reportClasses = {
38
38
  saveStatus: "publisher-save-status",
39
39
  /** A tile as the builder draws it: selection, handle and menu around the card. */
40
40
  builderTile: "publisher-builder-tile",
41
- /** The grip on a tile's right edge that sets its width. */
41
+ /** The invisible strip along a tile's right edge that sets its width (drawn only as a focus ring). */
42
42
  widthHandle: "publisher-width-handle",
43
43
  /** The builder's menus (Add, a tile's ⋯, the save status). */
44
44
  menu: "publisher-menu",
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
- import { malloyLiteral } from "./malloyLiteral";
5
+ import { formatMalloyValue, malloyLiteral } from "./malloyLiteral";
6
6
 
7
7
  describe("malloyLiteral", () => {
8
8
  it("spells a value the way its given's type reads it", () => {
@@ -41,3 +41,14 @@ describe("malloyLiteral", () => {
41
41
  expect(malloyLiteral(new Date("nope"))).toBeUndefined();
42
42
  });
43
43
  });
44
+
45
+ describe("formatMalloyValue", () => {
46
+ it("spells filter values, dates as local-time days", () => {
47
+ expect(formatMalloyValue(null)).toBe("null");
48
+ expect(formatMalloyValue("O'Neil")).toBe("'O\\'Neil'");
49
+ expect(formatMalloyValue(42)).toBe("42");
50
+ expect(formatMalloyValue(false)).toBe("false");
51
+ expect(formatMalloyValue("2024-01-31", true)).toBe("@2024-01-31");
52
+ expect(formatMalloyValue(new Date(2024, 0, 5), true)).toBe("@2024-01-05");
53
+ });
54
+ });
@@ -74,3 +74,35 @@ function datePart(value: unknown): string | undefined {
74
74
  : value.toISOString().slice(0, 10);
75
75
  return /^(\d{4}-\d{2}-\d{2})/.exec(String(value))?.[1];
76
76
  }
77
+
78
+ /** A filter value as a Malloy literal; unlike `malloyLiteral`, a Date is spelled as a local-time day. */
79
+ export function formatMalloyValue(
80
+ value: string | number | boolean | Date | null | undefined,
81
+ isDate: boolean = false,
82
+ ): string {
83
+ if (value === null || value === undefined) {
84
+ return "null";
85
+ }
86
+
87
+ if (isDate) {
88
+ if (value instanceof Date) {
89
+ return `@${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, "0")}-${String(value.getDate()).padStart(2, "0")}`;
90
+ }
91
+ // A string is assumed to already be ISO.
92
+ return `@${value}`;
93
+ }
94
+
95
+ if (typeof value === "string") {
96
+ return `'${escapeMalloyString(value)}'`;
97
+ }
98
+
99
+ if (typeof value === "number") {
100
+ return String(value);
101
+ }
102
+
103
+ if (typeof value === "boolean") {
104
+ return value ? "true" : "false";
105
+ }
106
+
107
+ return String(value);
108
+ }
package/vite.config.ts CHANGED
@@ -70,10 +70,8 @@ export default ({ mode }) => {
70
70
  "@mui/material",
71
71
  "@mui/icons-material",
72
72
  "@mui/system",
73
- "@mui/x-tree-view",
74
73
 
75
74
  // Other large React libraries
76
- "@react-spring/web",
77
75
  "@tanstack/react-query",
78
76
 
79
77
  // Malloy dependencies (should be provided by host)
package/.eslintrc DELETED
@@ -1,36 +0,0 @@
1
- {
2
- // Specify the environments where the code will run
3
- "env": {
4
- "jest": true, // Enable Jest for testing
5
- "browser": true // Enable browser environment
6
- },
7
-
8
- // Stop ESLint from searching for configuration in parent folders
9
- "root": true,
10
-
11
- // Specify the parser for TypeScript (using @typescript-eslint/parser)
12
- "parser": "@typescript-eslint/parser", // Leverages TS ESTree to lint TypeScript
13
-
14
- // Add additional rules and configuration options
15
- "plugins": ["@typescript-eslint"],
16
-
17
- // Extend various ESLint configurations and plugins
18
- "extends": [
19
- "eslint:recommended", // ESLint recommended rules
20
- "plugin:react/recommended", // React recommended rules
21
- "plugin:@typescript-eslint/recommended", // TypeScript recommended rules
22
- "plugin:@typescript-eslint/eslint-recommended", // ESLint overrides for TypeScript
23
- "prettier", // Prettier rules
24
- "plugin:prettier/recommended", // Prettier plugin integration
25
- "plugin:react-hooks/recommended", // Recommended rules for React hooks
26
- "plugin:storybook/recommended" // Recommended rules for Storybook
27
- ],
28
- "settings": {
29
- "react": {
30
- "version": "detect"
31
- }
32
- },
33
- "rules": {
34
- "react/react-in-jsx-scope": "off",
35
- }
36
- }
@@ -1,5 +0,0 @@
1
- interface DOMElement {
2
- element: HTMLElement;
3
- }
4
- export default function DOMElement({ element }: DOMElement): import("react/jsx-runtime").JSX.Element;
5
- export {};
@@ -1 +0,0 @@
1
- export { default as DOMElement } from './DOMElement';
@@ -1,9 +0,0 @@
1
- import { Database, Model } from '../../client';
2
- import * as React from "react";
3
- interface FiieTreeViewProps {
4
- items: Model[] | Database[];
5
- defaultExpandedItems: string[];
6
- onClickTreeNode?: (to: string, event?: React.MouseEvent) => void;
7
- }
8
- export declare function FileTreeView({ items, defaultExpandedItems, onClickTreeNode, }: FiieTreeViewProps): import("react/jsx-runtime").JSX.Element;
9
- export {};
@@ -1,39 +0,0 @@
1
- import { RefObject } from 'react';
2
- import { DashboardTile } from './document';
3
- /** A height drag in flight: the tile, what it WOULD be, and where its top sits. */
4
- export interface HeightState {
5
- index: number;
6
- /** The rows it would be, or undefined for auto: no `rowspan`, as tall as its row. */
7
- rows: number | undefined;
8
- /** Its `rowspan` when the drag began: a release that changed nothing writes nothing. */
9
- from: number | undefined;
10
- top: number;
11
- /** The tile's top against the grid's, where the row guides are drawn from. */
12
- guideTop: number;
13
- }
14
- /**
15
- * Dragging a tile's bottom edge to set its `rowspan`, in whole grid rows, or
16
- * back to auto. Previewed by the caller from `height.rows` and written ONCE,
17
- * on release, so one gesture is one undo step.
18
- *
19
- * Auto is a snap point of its own. A tile with no `rowspan` is as tall as its
20
- * row, and a row of such tiles is as tall as its tallest content, which is
21
- * almost never a whole number of rows: 492px sits between 5 rows (464) and 6
22
- * (560). With rows alone a tile could never be dragged level with an auto
23
- * neighbour; snapping to the row's own height, and writing that as no
24
- * `rowspan`, is what makes level reachable.
25
- */
26
- export declare function useTileHeight({ tiles, gridBox, onStart, commit, }: {
27
- tiles: readonly DashboardTile[];
28
- /** Wraps the grid: row-mates are found in it and the row guides are placed against it. */
29
- gridBox: RefObject<HTMLDivElement | null>;
30
- /** The tile a drag begins on, which the caller selects. */
31
- onStart: (index: number) => void;
32
- /** What to write when the drag ends: rows, or undefined to take the `rowspan` off. */
33
- commit: (index: number, rows: number | undefined) => void;
34
- }): {
35
- height: HeightState;
36
- startHeight: (event: React.PointerEvent<HTMLDivElement>, index: number) => void;
37
- onHeight: (event: React.PointerEvent<HTMLDivElement>) => void;
38
- endHeight: (event: React.PointerEvent<HTMLDivElement>) => void;
39
- };
@@ -1,40 +0,0 @@
1
- import { RefObject } from 'react';
2
- import { DashboardTile } from './document';
3
- /**
4
- * The widest a tile may be dragged: the whole grid, or, for a placed tile, up
5
- * to the grid's right edge from its column. A right edge dragged past the grid
6
- * stops there; it never moves the tile's left edge.
7
- */
8
- export declare const widestFrom: (tile: DashboardTile | undefined, columns: number) => number;
9
- /** A resize in flight: the tile, the width it WOULD be, and the geometry. */
10
- export interface ResizeState {
11
- index: number;
12
- span: number;
13
- /** The width the drag started from, so a release that changed nothing writes nothing. */
14
- from: number;
15
- left: number;
16
- track: number;
17
- /** The widest it may go: to the grid's right edge from the column a placed tile starts in. */
18
- max: number;
19
- }
20
- /**
21
- * Dragging a tile's right edge to set its `colspan`. The width is previewed
22
- * by the caller from `resize.span` and written ONCE, on release: writing on
23
- * every pointer move would put a dozen documents in the history for one
24
- * gesture, and undo would walk back through the drag a column at a time.
25
- */
26
- export declare function useTileResize({ tiles, columns, gridBox, onStart, commit, }: {
27
- tiles: readonly DashboardTile[];
28
- columns: number;
29
- /** Wraps the grid, so its content box IS the grid's: what a dragged edge is measured against to work out a column count. */
30
- gridBox: RefObject<HTMLDivElement | null>;
31
- /** The tile a resize begins on, which the caller selects. */
32
- onStart: (index: number) => void;
33
- /** The width to write when the drag ends. */
34
- commit: (index: number, span: number) => void;
35
- }): {
36
- resize: ResizeState;
37
- startResize: (event: React.PointerEvent<HTMLDivElement>, index: number) => void;
38
- onResize: (event: React.PointerEvent<HTMLDivElement>) => void;
39
- endResize: (event: React.PointerEvent<HTMLDivElement>) => void;
40
- };