@malloy-publisher/sdk 0.4.0 → 0.4.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/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.4.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -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 }
@@ -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(