@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
@@ -1,148 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import { useEffect, useRef, useState, type RefObject } from "react";
5
- import { GRID_GAP_PX } from "../Dashboard/DashboardGrid";
6
- import type { DashboardTile } from "./document";
7
-
8
- /**
9
- * The widest a tile may be dragged: the whole grid, or, for a placed tile, up
10
- * to the grid's right edge from its column. A right edge dragged past the grid
11
- * stops there; it never moves the tile's left edge.
12
- */
13
- export const widestFrom = (
14
- tile: DashboardTile | undefined,
15
- columns: number,
16
- ): number =>
17
- tile?.col === undefined ? columns : Math.max(1, columns - tile.col + 1);
18
-
19
- /** A resize in flight: the tile, the width it WOULD be, and the geometry. */
20
- export interface ResizeState {
21
- index: number;
22
- span: number;
23
- /** The width the drag started from, so a release that changed nothing writes nothing. */
24
- from: number;
25
- left: number;
26
- track: number;
27
- /** The widest it may go: to the grid's right edge from the column a placed tile starts in. */
28
- max: number;
29
- }
30
-
31
- /**
32
- * While a RESIZE is live, the page has to stop behaving like a document:
33
- * dragging an edge across a dashboard otherwise selects the text it crosses and
34
- * leaves the cursor as whatever it was over. (A MOVE gets the same from the
35
- * library's own plugins.)
36
- */
37
- const dragChrome = (on: boolean) => {
38
- const body = window.document.body;
39
- body.style.userSelect = on ? "none" : "";
40
- body.style.cursor = on ? "grabbing" : "";
41
- };
42
-
43
- /**
44
- * Dragging a tile's right edge to set its `colspan`. The width is previewed
45
- * by the caller from `resize.span` and written ONCE, on release: writing on
46
- * every pointer move would put a dozen documents in the history for one
47
- * gesture, and undo would walk back through the drag a column at a time.
48
- */
49
- export function useTileResize({
50
- tiles,
51
- columns,
52
- gridBox,
53
- onStart,
54
- commit,
55
- }: {
56
- tiles: readonly DashboardTile[];
57
- columns: number;
58
- /** Wraps the grid, so its content box IS the grid's: what a dragged edge is measured against to work out a column count. */
59
- gridBox: RefObject<HTMLDivElement | null>;
60
- /** The tile a resize begins on, which the caller selects. */
61
- onStart: (index: number) => void;
62
- /** The width to write when the drag ends. */
63
- commit: (index: number, span: number) => void;
64
- }) {
65
- const [resize, setResizeState] = useState<ResizeState | undefined>(
66
- undefined,
67
- );
68
- // The gesture as the handlers last left it. A release can arrive before the
69
- // render for the last move does, and reading state there would write the
70
- // width one column behind where the pointer let go.
71
- const live = useRef<ResizeState | undefined>(undefined);
72
- const setResize = (next: ResizeState | undefined) => {
73
- live.current = next;
74
- setResizeState(next);
75
- };
76
- // A builder unmounted mid-drag (a route change, say) must not leave the
77
- // whole page unselectable with a grabbing cursor.
78
- useEffect(() => () => dragChrome(false), []);
79
-
80
- /**
81
- * Width is the ONLY thing a resize can change.
82
- *
83
- * The format lays tiles out as a flow — `# colspan` for width, `# break` to
84
- * start a row — with no row index, no column position and no height. So a
85
- * right edge maps onto `colspan` and persists; a bottom edge has nothing to
86
- * be written as, and a left edge would mean placing the tile, which the grid
87
- * cannot express either. Offering those handles would be offering a drag the
88
- * writer then refuses, which is worse than not offering it.
89
- */
90
- const startResize = (
91
- event: React.PointerEvent<HTMLDivElement>,
92
- index: number,
93
- ) => {
94
- const grid = gridBox.current?.getBoundingClientRect();
95
- const tile = event.currentTarget.parentElement?.getBoundingClientRect();
96
- if (!grid || !tile) return;
97
- // Stops the tile's own click selecting a second time on release.
98
- event.stopPropagation();
99
- event.preventDefault();
100
- event.currentTarget.setPointerCapture(event.pointerId);
101
- dragChrome(true);
102
- onStart(index);
103
- const from = tiles[index]?.colspan ?? 1;
104
- const max = widestFrom(tiles[index], columns);
105
- setResize({
106
- index,
107
- span: from,
108
- from,
109
- left: tile.left,
110
- // One column track: the row's width less every gutter in it.
111
- track: (grid.width - GRID_GAP_PX * (columns - 1)) / columns,
112
- max,
113
- });
114
- };
115
-
116
- const onResize = (event: React.PointerEvent<HTMLDivElement>) => {
117
- const resize = live.current;
118
- if (!resize) return;
119
- const width = event.clientX - resize.left;
120
- // A tile of N tracks is N tracks plus the N-1 gutters between them, so
121
- // adding one gutter back makes the division land on whole columns.
122
- const span = Math.round(
123
- (width + GRID_GAP_PX) / (resize.track + GRID_GAP_PX),
124
- );
125
- const clamped = Math.min(Math.max(span, 1), resize.max);
126
- if (clamped !== resize.span) setResize({ ...resize, span: clamped });
127
- };
128
-
129
- const endResize = (event: React.PointerEvent<HTMLDivElement>) => {
130
- if (event.currentTarget.hasPointerCapture(event.pointerId))
131
- event.currentTarget.releasePointerCapture(event.pointerId);
132
- dragChrome(false);
133
- const resize = live.current;
134
- if (!resize) return;
135
- const { index, span, from } = resize;
136
- setResize(undefined);
137
- // A cancelled gesture (the browser took the pointer) puts the width back;
138
- // a press that moved nothing writes nothing, or a tile with no
139
- // `# colspan` would gain an explicit `colspan=1` from a click.
140
- if (event.type === "pointercancel" || span === from) return;
141
- // ONE history entry for the whole drag. Writing on every pointer move
142
- // would put a dozen documents in the stack for one gesture, and undo
143
- // would walk back through the drag a column at a time.
144
- commit(index, span);
145
- };
146
-
147
- return { resize, startResize, onResize, endResize };
148
- }