@malloy-publisher/sdk 0.4.0 → 0.5.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 (72) hide show
  1. package/README.md +19 -0
  2. package/dist/{DocumentStorageProvider-CyOJ0hqf.es.js → DocumentStorage-B04sZ5Ie.es.js} +2307 -2334
  3. package/dist/{DocumentStorageProvider-DGPQEd_l.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +20 -20
  4. package/dist/{RenderedResult-BnPzJ9Jf.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
  5. package/dist/RenderedResult-DVuGhatg.cjs.js +135 -0
  6. package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
  7. package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
  8. package/dist/builder/index.cjs.js +57 -52
  9. package/dist/builder/index.es.js +4421 -3738
  10. package/dist/client/api.d.ts +14 -1
  11. package/dist/client/index.cjs.js +1 -1
  12. package/dist/client/index.es.js +1 -1
  13. package/dist/components/Dashboard/TileCard.d.ts +7 -3
  14. package/dist/components/Dashboard/telemetry.d.ts +20 -8
  15. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +16 -4
  16. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +31 -8
  17. package/dist/components/DashboardBuilder/controls.d.ts +8 -6
  18. package/dist/components/DashboardBuilder/document.d.ts +19 -5
  19. package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
  20. package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
  21. package/dist/components/DashboardBuilder/preview.d.ts +17 -0
  22. package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
  23. package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
  24. package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
  25. package/dist/components/DocumentStorage/index.d.ts +1 -0
  26. package/dist/index.cjs.js +9 -9
  27. package/dist/index.es.js +508 -506
  28. package/dist/theme/resolveTheme.d.ts +1 -1
  29. package/dist/theme/types.d.ts +12 -2
  30. package/package.json +1 -1
  31. package/src/components/Dashboard/TileCard.tsx +8 -4
  32. package/src/components/Dashboard/telemetry.ts +20 -8
  33. package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
  34. package/src/components/DashboardBuilder/DashboardBuilder.tsx +21 -3
  35. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
  36. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
  37. package/src/components/DashboardBuilder/DashboardEditor.tsx +468 -103
  38. package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
  39. package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
  40. package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
  41. package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
  42. package/src/components/DashboardBuilder/controls.spec.ts +53 -3
  43. package/src/components/DashboardBuilder/controls.ts +9 -7
  44. package/src/components/DashboardBuilder/document.ts +17 -5
  45. package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
  46. package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
  47. package/src/components/DashboardBuilder/malloyText.ts +4 -109
  48. package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
  49. package/src/components/DashboardBuilder/malloyTree.ts +954 -0
  50. package/src/components/DashboardBuilder/preview.spec.ts +18 -0
  51. package/src/components/DashboardBuilder/preview.ts +24 -6
  52. package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
  53. package/src/components/DashboardBuilder/readDocument.ts +144 -165
  54. package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
  55. package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
  56. package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
  57. package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
  58. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
  59. package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
  60. package/src/components/DocumentStorage/index.ts +1 -0
  61. package/src/components/Package/Package.tsx +12 -7
  62. package/src/components/RenderedResult/RenderedResult.tsx +21 -1
  63. package/src/components/given/GivensPanel.tsx +15 -3
  64. package/src/theme/buildTableCssVars.spec.ts +3 -0
  65. package/src/theme/buildTableCssVars.ts +6 -0
  66. package/src/theme/defaults.ts +16 -12
  67. package/src/theme/resolveTheme.spec.ts +14 -7
  68. package/src/theme/resolveTheme.ts +14 -8
  69. package/src/theme/types.ts +12 -2
  70. package/tsconfig.spec.json +5 -1
  71. package/dist/RenderedResult-Dp22kZsQ.cjs.js +0 -115
  72. package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
@@ -7,7 +7,7 @@ import { ResolvedTheme, Theme, ThemeMode } from './types';
7
7
  * (a layer that sets only `palette.tile.dark` doesn't clobber the
8
8
  * instance-level `palette.tile.light`).
9
9
  *
10
- * The derived fields on ResolvedTheme (border, pinnedBorder,
10
+ * The derived fields on ResolvedTheme (border, cardBorder, pinnedBorder,
11
11
  * valueColor, foreground, axisFaint) are computed once here from the
12
12
  * active mode so the three builders that consume the theme stop
13
13
  * recomputing them with duplicated hex literals.
@@ -10,8 +10,8 @@ export type ThemeMode = "light" | "dark";
10
10
  *
11
11
  * The seven `palette.*` colour keys are stored per-mode on the raw Theme
12
12
  * (one of light/dark per field) and collapse to the active mode here.
13
- * The five "derived" fields (border, pinnedBorder, valueColor,
14
- * foreground, axisFaint) are computed once from the resolved mode so
13
+ * The six "derived" fields (border, cardBorder, pinnedBorder,
14
+ * valueColor, foreground, axisFaint) are computed once from the resolved mode so
15
15
  * the same hex literal isn't repeated across three builders.
16
16
  */
17
17
  export interface ResolvedTheme {
@@ -34,6 +34,16 @@ export interface ResolvedTheme {
34
34
  */
35
35
  mapColor: string;
36
36
  border: string;
37
+ /**
38
+ * The edge of a dashboard CARD, kept off `border` on purpose. `border` is
39
+ * the gridline inside a table, where a hairline is right because there are
40
+ * dozens of them and they only have to separate rows. A card's edge has one
41
+ * job — say where the card stops — and at the gridline's weight, on a page
42
+ * whose ground and tile are both white, it did not do it: the cards read as
43
+ * floating content rather than as cards. A step down the same slate ramp,
44
+ * so the two still read as one system.
45
+ */
46
+ cardBorder: string;
37
47
  pinnedBorder: string;
38
48
  valueColor: string;
39
49
  foreground: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -17,9 +17,13 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
17
17
  * draws a stand-in tile when it has no server to run one, draws the same card
18
18
  * the reader does rather than restating its geometry.
19
19
  *
20
- * The instance theme's border, not MUI's `divider`: the renderer card's edge is
21
- * this same value, and a card that agrees with the theme everywhere except its
22
- * outline still reads as a different card. Radius stays on the host's
20
+ * The instance theme's `cardBorder`, not MUI's `divider` and not the `border`
21
+ * a table's gridlines take: the renderer card's edge is this same value, and a
22
+ * card that agrees with the theme everywhere except its outline still reads as
23
+ * a different card. Both surfaces moved together when the edge was darkened;
24
+ * either one left behind is a dashboard whose tiles are outlined two ways.
25
+ *
26
+ * Radius stays on the host's
23
27
  * `shape.borderRadius`, which the renderer card is pointed at too. The
24
28
  * background is `theme.tile`, the value the renderer card paints — left unset,
25
29
  * on a theme whose page is also white the composite tiles lost the tint that
@@ -51,7 +55,7 @@ export function TileCard({
51
55
  elevation={0}
52
56
  sx={[
53
57
  {
54
- border: borderless ? "none" : theme.border,
58
+ border: borderless ? "none" : theme.cardBorder,
55
59
  borderRadius: borderless ? 0 : 1,
56
60
  background: borderless ? "none" : theme.tile,
57
61
  overflow: "hidden",
@@ -12,8 +12,12 @@
12
12
  export type DashboardEvent =
13
13
  | {
14
14
  type: "dashboard.opened";
15
- /** The package file, or a draft the host had saved. */
16
- from: "package" | "draft";
15
+ /**
16
+ * The package file, a draft the host had saved beside it, or the
17
+ * host's own copy when that copy is the record. A record open is not a
18
+ * "draft" open: nothing was resumed and nothing is pending.
19
+ */
20
+ from: "package" | "draft" | "record";
17
21
  tiles: number;
18
22
  durationMs: number;
19
23
  }
@@ -24,13 +28,21 @@ export type DashboardEvent =
24
28
  /** Whether a tile was added or removed, which moves declarations. */
25
29
  structural: boolean;
26
30
  /**
27
- * Where it went. A save into the package is a change every reader of
28
- * that server sees; a browser save is one person's copy on one
29
- * machine. Counting them together makes "dashboards are being edited"
30
- * unreadable, because a read-only server reports exactly as much
31
- * saving as a writable one.
31
+ * Where it went, named by which storage took the write rather than by
32
+ * where that storage happens to keep things, since "browser" and
33
+ * "host" do not divide by English: `package` is the package file on
34
+ * the server, `browser` is the Console's own browser store, and `host`
35
+ * is a host storage that holds the record.
36
+ *
37
+ * Separate because they are not the same event. A save into the
38
+ * package or the record is a change every reader sees; a browser save
39
+ * is one person's copy on one machine. Counting them together makes
40
+ * "dashboards are being edited" unreadable, because a read-only server
41
+ * reports exactly as much saving as a writable one.
32
42
  */
33
- where: "package" | "browser";
43
+ where: "package" | "browser" | "host";
44
+ /** The workspace that took the write, so the event says so itself. */
45
+ workspace?: string;
34
46
  durationMs: number;
35
47
  }
36
48
  | { type: "dashboard.save_refused"; reason: string }
@@ -2,7 +2,6 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import AddIcon from "@mui/icons-material/Add";
5
- import CheckIcon from "@mui/icons-material/Check";
6
5
  import TuneIcon from "@mui/icons-material/Tune";
7
6
  import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
8
7
  import RedoIcon from "@mui/icons-material/Redo";
@@ -136,13 +135,13 @@ export function BuilderToolbar({
136
135
  variant={dirty ? "contained" : "outlined"}
137
136
  disabled={!dirty || saving}
138
137
  onClick={onSave}
139
- startIcon={
140
- !dirty && !saving ? <CheckIcon /> : undefined
141
- }
138
+ // Wide enough for the longest of the three labels, so
139
+ // the bar does not reflow as the state cycles.
142
140
  sx={{ minWidth: 124 }}
143
141
  >
144
142
  {/* Says what will happen, then that it is happening,
145
- then what did. */}
143
+ then what did. One tick in the bar, on "Done
144
+ editing"; here the word carries the state. */}
146
145
  {saving ? "Saving…" : dirty ? "Save changes" : "Saved"}
147
146
  </Button>
148
147
  </span>
@@ -146,12 +146,24 @@ export interface DashboardBuilderProps {
146
146
  dashboards?: string[];
147
147
  /** Saves and refusals, for the host to log; see `DashboardEvent`. */
148
148
  onEvent?: DashboardEventHandler;
149
+ /**
150
+ * Whether the document differs from what was last saved, on every change
151
+ * and on mount.
152
+ *
153
+ * For a host that has to decide whether it may replace what is open — a
154
+ * newer version arriving from its store, a navigation away. `onChange`
155
+ * cannot answer that: the saved baseline lives in this hook, so a parent
156
+ * comparing the document it is handed against the one it passed in reads
157
+ * dirty immediately after a successful save.
158
+ */
159
+ onDirtyChange?: (dirty: boolean) => void;
149
160
  /**
150
161
  * Where `onSave` puts the file, for the event it reports. The builder
151
- * cannot tell — it is handed a function — and a save into the package and a
152
- * save into this browser are not the same event.
162
+ * cannot tell — it is handed a function — and a save into the package, into
163
+ * this browser, and into a host store that holds the record are not the
164
+ * same event.
153
165
  */
154
- savesTo?: "package" | "browser";
166
+ savesTo?: "package" | "browser" | "host";
155
167
  /**
156
168
  * The host's own actions for the edit bar — Done — rendered beside
157
169
  * undo, redo and save. The builder owns the edits; where the file goes
@@ -165,6 +177,7 @@ export function DashboardBuilder({
165
177
  document,
166
178
  onSave,
167
179
  onChange,
180
+ onDirtyChange,
168
181
  renderTile,
169
182
  controls,
170
183
  givens,
@@ -225,6 +238,11 @@ export function DashboardBuilder({
225
238
  useEffect(() => {
226
239
  onChange?.(editor.document);
227
240
  }, [editor.document, onChange]);
241
+ // Also on mount, so a host that remounted the builder on new text is told
242
+ // the slate is clean rather than carrying the previous mount's answer.
243
+ useEffect(() => {
244
+ onDirtyChange?.(editor.dirty);
245
+ }, [editor.dirty, onDirtyChange]);
228
246
  // One object per document, or the popover's draft would reset on every
229
247
  // render of the builder while it is open.
230
248
  const settings = useMemo(