@antelopejs/dms 0.25.8 → 0.25.9-next.1170.g0f31f2d

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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/e2e/backend-ready.d.mts +10 -0
  3. package/dist/e2e/index.d.mts +2 -1
  4. package/dist/e2e/journeys-config.d.mts +9 -0
  5. package/dist/e2e/mongo.d.mts +22 -0
  6. package/dist/e2e/waits.d.mts +6 -4
  7. package/dist/implementations/dms-auth/index.js +1 -1
  8. package/dist/implementations/dms-auth/index.js.map +1 -1
  9. package/dist/mockup/capture-drawing.d.ts +5 -0
  10. package/dist/mockup/capture-drawing.js +39 -0
  11. package/dist/mockup/capture-drawing.js.map +1 -0
  12. package/dist/mockup/capture-routes.js +10 -14
  13. package/dist/mockup/capture-routes.js.map +1 -1
  14. package/dist/mockup/capture.d.ts +3 -1
  15. package/dist/mockup/capture.js +36 -1
  16. package/dist/mockup/capture.js.map +1 -1
  17. package/dist/mockup/files.d.ts +1 -0
  18. package/dist/mockup/files.js +2 -1
  19. package/dist/mockup/files.js.map +1 -1
  20. package/dist/mockup/model.d.ts +2 -0
  21. package/dist/mockup/model.js.map +1 -1
  22. package/dist/mockup/store.js +15 -3
  23. package/dist/mockup/store.js.map +1 -1
  24. package/dist/pages/settings/users/member-invite-batch.d.ts +7 -1
  25. package/dist/pages/settings/users/member-invite-batch.js +53 -2
  26. package/dist/pages/settings/users/member-invite-batch.js.map +1 -1
  27. package/dist/pages/settings/users/profile.js +1 -1
  28. package/dist/pages/settings/users/profile.js.map +1 -1
  29. package/e2e/backend-ready.mjs +22 -0
  30. package/e2e/backend.mjs +3 -3
  31. package/e2e/index.mjs +27 -13
  32. package/e2e/journeys-config.mjs +16 -0
  33. package/e2e/mongo.mjs +58 -0
  34. package/e2e/stack.mjs +3 -2
  35. package/e2e/waits.mjs +21 -4
  36. package/e2e/weighted-shards.mjs +164 -0
  37. package/e2e/weights.mjs +67 -0
  38. package/frontend-vue/layers/dms-core/i18n/locales/core-en-GB.json +17 -2
  39. package/frontend-vue/layers/dms-core/i18n/locales/core-fr-FR.json +17 -2
  40. package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupOverviewSlot.vue +29 -24
  41. package/frontend-vue/layers/dms-ui/app/build/components/block-preview/MockupWorkbench.vue +5 -0
  42. package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/previewNavigation.ts +8 -0
  43. package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useBlockPreviewEmbed.ts +5 -10
  44. package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupCaptureRelease.ts +35 -0
  45. package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupOverview.ts +2 -0
  46. package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useOverviewCaptures.ts +20 -14
  47. package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/usePreviewFrame.ts +3 -2
  48. package/frontend-vue/layers/dms-ui/app/build/mockups/MockupCards.vue +6 -2
  49. package/frontend-vue/layers/dms-ui/app/build/mockups/manage.ts +28 -2
  50. package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewMessages.ts +19 -4
  51. package/frontend-vue/layers/dms-ui/app/build/utils/mockup.ts +15 -7
  52. package/frontend-vue/layers/dms-ui/app/build/utils/mockupCaptures.ts +24 -0
  53. package/frontend-vue/package.json +1 -1
  54. package/package.json +3 -3
@@ -0,0 +1,164 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { decode, isNumber, isString, objectOf, recordOf } from "./json.mjs";
3
+
4
+ /**
5
+ * @typedef {import("@playwright/test/reporter").Reporter} Reporter
6
+ * @typedef {import("@playwright/test/reporter").FullConfig} FullConfig
7
+ * @typedef {import("@playwright/test/reporter").Suite} Suite
8
+ * @typedef {import("@playwright/test/reporter").TestCase} TestCase
9
+ * @typedef {import("@playwright/test/reporter").TestResult} TestResult
10
+ * @typedef {import("@playwright/test/reporter").TestRun} TestRun
11
+ */
12
+
13
+ const isOptions = objectOf({ weights: isString });
14
+
15
+ /**
16
+ * The seconds per test in the weights file, none when the file does not exist.
17
+ *
18
+ * @param {string} file The absolute path of `test-weights.json`
19
+ * @returns {Record<string, number>}
20
+ */
21
+ function readWeights(file) {
22
+ if (!existsSync(file)) return {};
23
+ return decode(
24
+ recordOf(isNumber),
25
+ JSON.parse(readFileSync(file, "utf8")),
26
+ file,
27
+ "seconds per test",
28
+ );
29
+ }
30
+
31
+ /**
32
+ * The key of a test in `test-weights.json`: its file, describe blocks and
33
+ * title, joined by ` › `.
34
+ *
35
+ * @param {TestCase} test The test
36
+ * @returns {string}
37
+ */
38
+ export function weightKey(test) {
39
+ return test.titlePath().slice(2).join(" › ");
40
+ }
41
+
42
+ /**
43
+ * The shard (1-based) of each of `seconds`, in order: the suite cut into
44
+ * `count` contiguous runs of about equal seconds, each test in the run that
45
+ * holds its midpoint. A test with no seconds counts as the median of the
46
+ * known ones, or 1 when none is known. Shard 1 starts with `headStart`
47
+ * seconds of other work; when that is its whole share, it takes no test and
48
+ * the others split the suite.
49
+ *
50
+ * @param {(number | undefined)[]} seconds The seconds of each test, in the suite's order
51
+ * @param {number} count How many shards
52
+ * @param {number} [headStart] The seconds shard 1 spends on other work
53
+ * @returns {number[]}
54
+ */
55
+ export function contiguousShards(seconds, count, headStart = 0) {
56
+ const known = seconds
57
+ .filter((value) => value !== undefined)
58
+ .sort((left, right) => left - right);
59
+ const middle = Math.floor(known.length / 2);
60
+ const fallback =
61
+ known.length === 0
62
+ ? 1
63
+ : known.length % 2 === 1
64
+ ? known[middle]
65
+ : (known[middle - 1] + known[middle]) / 2;
66
+ const weights = seconds.map((value) => value ?? fallback);
67
+ const total = weights.reduce((sum, value) => sum + value, headStart);
68
+ if (count > 1 && headStart * count >= total) {
69
+ return contiguousShards(seconds, count - 1).map((shard) => shard + 1);
70
+ }
71
+ let elapsed = headStart;
72
+ return weights.map((weight) => {
73
+ const midpoint = elapsed + weight / 2;
74
+ elapsed += weight;
75
+ return Math.min(count, Math.floor((midpoint * count) / total) + 1);
76
+ });
77
+ }
78
+
79
+ /** @returns {number} The seconds of `DMS_E2E_FIRST_SHARD_EXTRA`, 0 when unset */
80
+ function firstShardExtra() {
81
+ const value = process.env["DMS_E2E_FIRST_SHARD_EXTRA"];
82
+ if (value === undefined) return 0;
83
+ const seconds = Number(value);
84
+ if (!Number.isFinite(seconds) || seconds < 0) {
85
+ throw new Error(
86
+ `DMS_E2E_FIRST_SHARD_EXTRA is ${JSON.stringify(value)}, not a count of seconds`,
87
+ );
88
+ }
89
+ return seconds;
90
+ }
91
+
92
+ /**
93
+ * Replaces Playwright's `--shard`, which cuts the suite into contiguous runs
94
+ * of equal count, with `contiguousShards`' runs of equal seconds by the
95
+ * `test-weights.json` its `weights` option names. Without that file every
96
+ * test counts as one second, so the shards are contiguous runs of equal count. The workers of a shard take its journeys in the
97
+ * suite's order, so a shard stays a contiguous run of that order, as with
98
+ * `--shard`. `DMS_E2E_FIRST_SHARD_EXTRA` is the wall-clock seconds shard 1
99
+ * spends after the suite, which its workers would have spent on journeys.
100
+ * With `DMS_E2E_DURATIONS` set to a path, it writes there the seconds each
101
+ * test of the run took, which `weights.mjs` averages into the weights.
102
+ *
103
+ * @implements {Reporter}
104
+ */
105
+ export default class WeightedShards {
106
+ /** @type {Map<string, number>} */
107
+ #seconds = new Map();
108
+
109
+ /** @type {string} */
110
+ #weights;
111
+
112
+ /**
113
+ * @param {unknown} options The reporter options: `weights`, the absolute path of `test-weights.json`
114
+ * @throws When `options` has no `weights` path
115
+ */
116
+ constructor(options) {
117
+ this.#weights = decode(
118
+ isOptions,
119
+ options,
120
+ "the weighted-shards reporter options",
121
+ "{ weights: <the path of test-weights.json> }",
122
+ ).weights;
123
+ }
124
+
125
+ /**
126
+ * @param {{ config: FullConfig, suite: Suite, testRun: TestRun }} params The run before it starts
127
+ * @returns {Promise<void>}
128
+ */
129
+ async preprocess({ config, suite, testRun }) {
130
+ if (!config.shard) return;
131
+ testRun.skipSharding();
132
+ const weights = readWeights(this.#weights);
133
+ const tests = suite.allTests();
134
+ const shards = contiguousShards(
135
+ tests.map((test) => weights[weightKey(test)]),
136
+ config.shard.total,
137
+ firstShardExtra() * config.workers,
138
+ );
139
+ for (const [index, test] of tests.entries()) {
140
+ if (shards[index] !== config.shard.current) testRun.exclude(test);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * @param {TestCase} test The test
146
+ * @param {TestResult} result Its result
147
+ */
148
+ onTestEnd(test, result) {
149
+ this.#seconds.set(weightKey(test), result.duration / 1000);
150
+ }
151
+
152
+ onEnd() {
153
+ const output = process.env["DMS_E2E_DURATIONS"];
154
+ if (!output) return;
155
+ const seconds = Object.fromEntries(
156
+ [...this.#seconds].sort(([left], [right]) => (left < right ? -1 : 1)),
157
+ );
158
+ writeFileSync(output, `${JSON.stringify(seconds, null, 2)}\n`);
159
+ }
160
+
161
+ printsToStdio() {
162
+ return false;
163
+ }
164
+ }
@@ -0,0 +1,67 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
+ import { decode, isNumber, recordOf } from "./json.mjs";
4
+
5
+ const USAGE =
6
+ "usage: node weights.mjs <weights-out> <durations.json>... (each file is a DMS_E2E_DURATIONS output)";
7
+
8
+ /**
9
+ * The mean seconds per test or file over every run, to one decimal place,
10
+ * sorted by key.
11
+ *
12
+ * @param {Record<string, number>[]} measurements One `{ key: seconds }` object per shard run
13
+ * @returns {Record<string, number>}
14
+ */
15
+ export function meanWeights(measurements) {
16
+ /** @type {Map<string, number[]>} */
17
+ const samples = new Map();
18
+ for (const measurement of measurements) {
19
+ for (const [file, seconds] of Object.entries(measurement)) {
20
+ samples.set(file, [...(samples.get(file) ?? []), seconds]);
21
+ }
22
+ }
23
+ return Object.fromEntries(
24
+ [...samples]
25
+ .sort(([left], [right]) => (left < right ? -1 : 1))
26
+ .map(([file, seconds]) => [
27
+ file,
28
+ Math.round(
29
+ (seconds.reduce((sum, value) => sum + value, 0) / seconds.length) *
30
+ 10,
31
+ ) / 10,
32
+ ]),
33
+ );
34
+ }
35
+
36
+ /**
37
+ * Reads the `DMS_E2E_DURATIONS` files and writes their mean seconds per test
38
+ * to `output`, the `test-weights.json` the kit's shards read.
39
+ *
40
+ * @param {string} output The weights file to write
41
+ * @param {string[]} durations The durations files
42
+ */
43
+ export function writeMeanWeights(output, durations) {
44
+ const weights = meanWeights(
45
+ durations.map((file) =>
46
+ decode(
47
+ recordOf(isNumber),
48
+ JSON.parse(readFileSync(file, "utf8")),
49
+ file,
50
+ "seconds per test",
51
+ ),
52
+ ),
53
+ );
54
+ writeFileSync(output, `${JSON.stringify(weights, null, 2)}\n`);
55
+ }
56
+
57
+ if (
58
+ process.argv[1] &&
59
+ import.meta.url === pathToFileURL(process.argv[1]).href
60
+ ) {
61
+ const [output, ...durations] = process.argv.slice(2);
62
+ if (output === undefined || durations.length === 0) {
63
+ process.stderr.write(`${USAGE}\n`);
64
+ process.exit(1);
65
+ }
66
+ writeMeanWeights(output, durations);
67
+ }
@@ -649,7 +649,8 @@
649
649
  "no_token_provided": "No JWT token provided",
650
650
  "email_not_validated": "Email not validated",
651
651
  "owner_only": "Owner-only",
652
- "authentication_required": "Authentication required"
652
+ "authentication_required": "Authentication required",
653
+ "invalid_tenant_assignment_token": "Invalid tenant assignment token"
653
654
  },
654
655
  "export": {
655
656
  "not_accessible": "Export not accessible",
@@ -712,7 +713,9 @@
712
713
  "different_decision": "Invitation already has a different terminal decision",
713
714
  "different_replacement": "Invitation already has a different replacement",
714
715
  "expired_before_acceptance": "Invitation expired before acceptance",
715
- "created_concurrently": "Invitation for this email was created concurrently with other content"
716
+ "created_concurrently": "Invitation for this email was created concurrently with other content",
717
+ "another_invite_pending": "Invitation for this email was created concurrently: cancel invitation {inviteId}, created {createdAt}, first",
718
+ "email_invited_concurrently": "Invitation for this email was created concurrently"
716
719
  },
717
720
  "mockup": {
718
721
  "not_found": "Mockup not found",
@@ -727,9 +730,11 @@
727
730
  "row_not_found": "Row not found",
728
731
  "route_not_found": "Route not found",
729
732
  "lock_not_found": "Lock not found",
733
+ "capture_drawing_missing": "Give the digest of the drawing the image shows in the drawing query",
730
734
  "capture_not_found": "This mockup has no captured image",
731
735
  "capture_not_image": "The body is not a WebP or PNG image",
732
736
  "capture_not_first_page": "The image is not of the first page of the mockup",
737
+ "capture_stale": "The image is a stale drawing: the first page changed since it was captured",
733
738
  "capture_page_missing": "Give the page the image shows in the page query",
734
739
  "spec_not_object": "spec.json holds no JSON object",
735
740
  "spec_changed": "spec.json changed since it was read",
@@ -746,6 +751,16 @@
746
751
  },
747
752
  "system": {
748
753
  "state_not_found": "System state not found"
754
+ },
755
+ "period": {
756
+ "not_an_instant": "The period's \"{name}\" must be an ISO instant such as 2026-10-01T00:00:00.000Z, not \"{text}\".",
757
+ "bound_missing": "The period sends \"{sent}\" without \"{missing}\": a window needs both.",
758
+ "bounds_reversed": "The period's \"{from}\" falls after its \"{to}\".",
759
+ "unknown_preset": "The period names the preset \"{preset}\", which is none of {presets}.",
760
+ "unknown_comparison": "The period names the comparison \"{comparison}\", which is none of {comparisons}.",
761
+ "none_with_window": "The period compares with nothing but sends \"compareFrom\" and \"compareTo\".",
762
+ "all_with_bounds": "The period \"all\" has no bounds, but it sends \"from\" and \"to\".",
763
+ "preset_without_bounds": "The period \"{preset}\" sends no \"from\" and \"to\": the selector sends the window it resolved."
749
764
  }
750
765
  }
751
766
  }
@@ -649,7 +649,8 @@
649
649
  "no_token_provided": "Aucun jeton JWT fourni",
650
650
  "email_not_validated": "Adresse e-mail non validée",
651
651
  "owner_only": "Réservé aux propriétaires",
652
- "authentication_required": "Authentification requise"
652
+ "authentication_required": "Authentification requise",
653
+ "invalid_tenant_assignment_token": "Jeton d'affectation à l'espace de travail invalide"
653
654
  },
654
655
  "export": {
655
656
  "not_accessible": "Export inaccessible",
@@ -712,7 +713,9 @@
712
713
  "different_decision": "L'invitation a déjà une autre décision finale",
713
714
  "different_replacement": "L'invitation a déjà un autre remplacement",
714
715
  "expired_before_acceptance": "L'invitation a expiré avant d'être acceptée",
715
- "created_concurrently": "Une invitation pour cette adresse e-mail a été créée en parallèle avec un autre contenu"
716
+ "created_concurrently": "Une invitation pour cette adresse e-mail a été créée en parallèle avec un autre contenu",
717
+ "another_invite_pending": "Une invitation pour cette adresse e-mail a été créée en parallèle : annulez d'abord l'invitation {inviteId}, créée le {createdAt}",
718
+ "email_invited_concurrently": "Une invitation pour cette adresse e-mail a été créée en parallèle"
716
719
  },
717
720
  "mockup": {
718
721
  "not_found": "Maquette introuvable",
@@ -727,9 +730,11 @@
727
730
  "row_not_found": "Ligne introuvable",
728
731
  "route_not_found": "Route introuvable",
729
732
  "lock_not_found": "Verrou introuvable",
733
+ "capture_drawing_missing": "Indiquez l'empreinte du dessin que montre l'image dans le paramètre drawing",
730
734
  "capture_not_found": "Cette maquette n'a aucune image capturée",
731
735
  "capture_not_image": "Le corps n'est pas une image WebP ou PNG",
732
736
  "capture_not_first_page": "L'image n'est pas celle de la première page de la maquette",
737
+ "capture_stale": "L'image montre une version périmée : la première page a changé depuis sa capture",
733
738
  "capture_page_missing": "Indiquez la page que montre l'image dans le paramètre page",
734
739
  "spec_not_object": "spec.json ne contient aucun objet JSON",
735
740
  "spec_changed": "spec.json a changé depuis sa lecture",
@@ -746,6 +751,16 @@
746
751
  },
747
752
  "system": {
748
753
  "state_not_found": "État du système introuvable"
754
+ },
755
+ "period": {
756
+ "not_an_instant": "Le paramètre « {name} » de la période doit être un instant ISO tel que 2026-10-01T00:00:00.000Z, et non « {text} ».",
757
+ "bound_missing": "La période envoie « {sent} » sans « {missing} » : une fenêtre a besoin des deux.",
758
+ "bounds_reversed": "Le paramètre « {from} » de la période tombe après son « {to} ».",
759
+ "unknown_preset": "La période nomme le préréglage « {preset} », qui ne fait pas partie de {presets}.",
760
+ "unknown_comparison": "La période nomme la comparaison « {comparison} », qui ne fait pas partie de {comparisons}.",
761
+ "none_with_window": "La période ne compare à rien mais envoie « compareFrom » et « compareTo ».",
762
+ "all_with_bounds": "La période « all » n'a pas de bornes, mais elle envoie « from » et « to ».",
763
+ "preset_without_bounds": "La période « {preset} » n'envoie ni « from » ni « to » : le sélecteur envoie la fenêtre qu'il a résolue."
749
764
  }
750
765
  }
751
766
  }
@@ -24,25 +24,26 @@ import { mockupDataTree, mockupPreviewPath } from "../../utils/mockupRealData";
24
24
 
25
25
  /**
26
26
  * One live frame of the Overview: the real `/dms-preview`, on the mockup's
27
- * fixtures or, for a page on real data, its live routes, drawing `page` at the desktop width and its full height, at least
28
- * a desktop window's. The iframe stays when `page` changes and redraws in
29
- * place, so the Overview moves a few iframes around instead of booting one
30
- * per page. It reports the page's height and where its blocks sit, for the
31
- * frame's size and its pins, and says once it booted, which lets the next
32
- * iframe of the Overview boot: on its preview's first `ready`, or after a
33
- * while without one, so a preview that fails does not hold the others back.
34
- * The iframe stays invisible until its preview reported the page it was
35
- * handed laid out, so a slot that moves to another page never shows a blank
36
- * frame, or the page it drew before, over the new frame: the frame's image
37
- * shows meanwhile. Once the page is drawn for `captureKey`, and while the
38
- * camera rests, a page that `wantsCapture` has its preview draw it to an
39
- * image, which the slot hands up; a capture the iframe was asked to draw
40
- * another page during is dropped, since it may show that page.
41
- * The pointer never reaches the iframe: the canvas pans and zooms, and the frame
42
- * around it opens the page. The iframe is a compositing layer of its own:
43
- * without it, every move of the canvas has the browser sort the painted
44
- * pieces of every live page into layers again, about 26 ms a frame with ten
45
- * pages, where the layer only moves on the screen.
27
+ * fixtures or, for a page on real data, its live routes, drawing `page` at
28
+ * the desktop width and its full height, at least a desktop window's. The
29
+ * iframe stays when `page` changes and redraws in place, so the Overview
30
+ * moves a few iframes around instead of booting one per page. It reports the
31
+ * page's height and where its blocks sit, for the frame's size and its pins,
32
+ * and says once it booted, which lets the next iframe of the Overview boot:
33
+ * on its preview's first `ready`, or after a while without one, so a preview
34
+ * that fails does not hold the others back. The iframe stays invisible until
35
+ * its preview reported the page it was handed laid out, in a layout that
36
+ * names the render it was last handed, so a slot that moves to another page
37
+ * never shows a blank frame, or the page it drew before, over the new frame:
38
+ * the frame's image shows meanwhile. Once the page is drawn for
39
+ * `captureKey`, and while the camera rests, a page that `wantsCapture` has
40
+ * its preview draw it to an image, which the slot hands up; a capture the
41
+ * iframe was asked to draw another page during is dropped, since it may show
42
+ * that page. The pointer never reaches the iframe: the canvas pans and
43
+ * zooms, and the frame around it opens the page. The iframe is a compositing
44
+ * layer of its own: without it, every move of the canvas has the browser
45
+ * sort the painted pieces of every live page into layers again, about 26 ms
46
+ * a frame with ten pages, where the layer only moves on the screen.
46
47
  */
47
48
  const props = defineProps<{
48
49
  page: MockupPageState;
@@ -94,6 +95,8 @@ const navigation = computed(() =>
94
95
  interface Drawing {
95
96
  page: string;
96
97
  key: string;
98
+ /** The render that asked for it: only a layout that names it answers it. */
99
+ render: number;
97
100
  }
98
101
 
99
102
  const drawn = shallowRef<Drawing>();
@@ -122,15 +125,16 @@ const drawTimeout = useTimeoutFn(
122
125
 
123
126
  function sync(): void {
124
127
  renders += 1;
125
- asked = { page: props.page.id, key: props.captureKey };
128
+ asked = { page: props.page.id, key: props.captureKey, render: renders };
126
129
  drawTimeout.start();
127
- bridge.post(
128
- mockupPageRender(
130
+ bridge.post({
131
+ ...mockupPageRender(
129
132
  props.page,
130
133
  mockupDataTree(props.page, props.realData),
131
134
  navigation.value,
132
135
  ),
133
- );
136
+ renderId: renders,
137
+ });
134
138
  bridge.post(previewInspectMessage(true));
135
139
  bridge.post(previewMinHeightMessage(OVERVIEW_MIN_HEIGHT));
136
140
  }
@@ -147,7 +151,8 @@ const bridge = usePreviewFrame({
147
151
  sync();
148
152
  },
149
153
  onSelect: () => undefined,
150
- onLayout: (blocks) => {
154
+ onLayout: (blocks, renderId) => {
155
+ if (asked && renderId !== asked.render) return;
151
156
  emit("report", props.page.id, { blocks, height: bridge.height.value });
152
157
  if (asked) {
153
158
  drawn.value = asked;
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, ref } from "vue";
3
+ import { useMockupCaptureRelease } from "../../composables/block-preview/useMockupCaptureRelease";
3
4
  import { useMockupCatalog } from "../../composables/block-preview/useMockupCatalog";
4
5
  import { useMockupDocument } from "../../composables/block-preview/useMockupDocument";
5
6
  import { useMockupEditing } from "../../composables/block-preview/useMockupEditing";
@@ -75,6 +76,7 @@ const session = useMockupSession({
75
76
  authFetch: $authFetch,
76
77
  });
77
78
  const { state, isConnected, hasRequestFailed } = session;
79
+ useMockupCaptureRelease(props.name, state);
78
80
  const heldBlock = ref<string>();
79
81
  const { editor, history } = useMockupDocument({
80
82
  name: props.name,
@@ -157,6 +159,9 @@ const overview = useMockupOverview({
157
159
  pages,
158
160
  categories,
159
161
  dataMode: choice,
162
+ drawing: computed(() =>
163
+ history.previewing.value ? undefined : state.value?.firstPageDrawing,
164
+ ),
160
165
  });
161
166
  const pins = useMockupPins({
162
167
  session,
@@ -3,6 +3,7 @@ import {
3
3
  previewNavigateMessage,
4
4
  previewSectionEditMessage,
5
5
  type PreviewNavigation,
6
+ type PreviewRenderMessage,
6
7
  } from "../../utils/blockPreviewMessages";
7
8
  import type { PreviewHeader } from "../../utils/previewHeader";
8
9
  import type { PreviewPageLayout } from "../../utils/previewPageLayout";
@@ -26,6 +27,13 @@ export const previewHeader = shallowRef<PreviewHeader>();
26
27
  */
27
28
  export const previewPageLayout = shallowRef<PreviewPageLayout>();
28
29
 
30
+ /** Takes the sidebar, header and layout `message` asks for, in place of the last render's. */
31
+ export function takeRenderChrome(message: PreviewRenderMessage): void {
32
+ previewNavigation.value = message.navigation;
33
+ previewHeader.value = message.header;
34
+ previewPageLayout.value = message.pageLayout;
35
+ }
36
+
29
37
  /** Marks the page header, whose click picks the page while inspecting. */
30
38
  export const PREVIEW_HEADER_ATTRIBUTE = "data-dms-preview-header";
31
39
 
@@ -30,12 +30,7 @@ import {
30
30
  } from "../../utils/blockPreviewMessages";
31
31
  import { capturePreviewFrame } from "./previewCapture";
32
32
  import { blockRects, documentRect, fontOf } from "./previewGeometry";
33
- import {
34
- PREVIEW_FRAME_ATTRIBUTE,
35
- previewHeader,
36
- previewPageLayout,
37
- previewNavigation,
38
- } from "./previewNavigation";
33
+ import { PREVIEW_FRAME_ATTRIBUTE, takeRenderChrome } from "./previewNavigation";
39
34
  import { useBlockInspector } from "./useBlockInspector";
40
35
  import { usePreviewLinks } from "./usePreviewLinks";
41
36
  import { applyFixturesOnlyPolicy } from "../../utils/previewFixturesOnly";
@@ -192,6 +187,7 @@ export function useBlockPreviewEmbed(options: EmbedOptions): BlockPreviewEmbed {
192
187
  let layoutFrame: number | undefined;
193
188
  let lastLayout: string | undefined;
194
189
  let isForced = false;
190
+ let renderId: number | undefined;
195
191
 
196
192
  function reportLayout(force = false): void {
197
193
  if (!inspecting.value) return;
@@ -206,7 +202,7 @@ export function useBlockPreviewEmbed(options: EmbedOptions): BlockPreviewEmbed {
206
202
  const layout = JSON.stringify(blocks);
207
203
  if (!forced && layout === lastLayout) return;
208
204
  lastLayout = layout;
209
- postToParent(previewLayoutMessage(blocks));
205
+ postToParent(previewLayoutMessage(blocks, renderId));
210
206
  });
211
207
  }
212
208
 
@@ -230,10 +226,9 @@ export function useBlockPreviewEmbed(options: EmbedOptions): BlockPreviewEmbed {
230
226
  locale.value = message.locale ?? locale.value;
231
227
  transparent.value = message.transparent ?? transparent.value;
232
228
  padding.value = message.padding ?? padding.value;
233
- previewNavigation.value = message.navigation;
234
- previewHeader.value = message.header;
235
- previewPageLayout.value = message.pageLayout;
229
+ takeRenderChrome(message);
236
230
  [params.value, query.value] = [message.params, message.query];
231
+ renderId = message.renderId;
237
232
  revision.value += 1;
238
233
  },
239
234
  theme: (message) => {
@@ -0,0 +1,35 @@
1
+ import { onBeforeUnmount, watch, type ShallowRef } from "vue";
2
+ import type { MockupState } from "../../utils/mockup";
3
+ import {
4
+ clearMockupCaptures,
5
+ keepPageCaptures,
6
+ } from "../../utils/mockupCaptures";
7
+
8
+ /**
9
+ * Releases the Overview's captures of the mockup `name` that its live state
10
+ * no longer calls for: a page the state stopped listing, and every capture
11
+ * once the state says `spec.json` is gone, as it does for a mockup deleted or
12
+ * renamed through MCP or on disk. Captures a missing mockup's frames still
13
+ * draw are released when the viewer closes.
14
+ */
15
+ export function useMockupCaptureRelease(
16
+ name: string,
17
+ state: Readonly<ShallowRef<MockupState | undefined>>,
18
+ ): void {
19
+ watch(
20
+ state,
21
+ (next) => {
22
+ if (!next) return;
23
+ if (next.specMissing) clearMockupCaptures(name);
24
+ else
25
+ keepPageCaptures(
26
+ name,
27
+ next.pages.map((page) => page.id),
28
+ );
29
+ },
30
+ { immediate: true },
31
+ );
32
+ onBeforeUnmount(() => {
33
+ if (state.value?.specMissing) clearMockupCaptures(name);
34
+ });
35
+ }
@@ -82,6 +82,8 @@ interface OverviewOptions {
82
82
  categories: ComputedRef<readonly MockupCategory[]>;
83
83
  /** The developer's Real data choice, if any: each page draws, and is captured, by it. */
84
84
  dataMode: Readonly<Ref<MockupDataMode | undefined>>;
85
+ /** What draws the first page as the server holds the spec; undefined while a past version is previewed. */
86
+ drawing: Readonly<Ref<string | undefined>>;
85
87
  }
86
88
 
87
89
  /** What labels a section's row: its category, none for the default section. */
@@ -28,6 +28,8 @@ export interface OverviewCaptureOptions {
28
28
  pages: Readonly<Ref<readonly MockupPageState[]>>;
29
29
  /** The developer's Real data choice, if any: each page is captured by it. */
30
30
  dataMode: Readonly<Ref<MockupDataMode | undefined>>;
31
+ /** What draws the first page of `pages` as the server holds the spec, or undefined while `pages` are not the spec's own, as when a past version is previewed: nothing is sent then. */
32
+ drawing: Readonly<Ref<string | undefined>>;
31
33
  }
32
34
 
33
35
  /**
@@ -36,14 +38,16 @@ export interface OverviewCaptureOptions {
36
38
  * step of the browser's history, so a viewer built again finds them, with
37
39
  * the height and blocks each page had when it was captured. A capture is
38
40
  * current while its key is the page's own, which leaves out the sidebar, so
39
- * changing one page recaptures that page alone. A page whose live frame could
40
- * not draw its image is not asked again for the same key until
41
+ * changing one page recaptures that page alone. A page whose live frame
42
+ * could not draw its image is not asked again for the same key until
41
43
  * {@link CAPTURE_RETRY_MS} passed, or the Overview opens again. The capture
42
44
  * of the first page, once current and drawn from fixtures, is also sent to
43
- * the server, which keeps it beside the spec for the cards of the Mockups
44
- * page. A drawing of real rows is never sent, since `mockups/` is committed
45
- * and read by the AI. A newer capture cancels the send of an older one, a
46
- * failed send is dropped, and a send outlives the Overview.
45
+ * the server with the drawing it shows, which keeps it beside the spec for
46
+ * the cards of the Mockups page, and refuses it when the spec changed since.
47
+ * The same capture is sent again when the drawing moves without its key. A
48
+ * drawing of real rows is never sent, since `mockups/` is committed and read
49
+ * by the AI. A newer capture cancels the send of an older one, a failed send
50
+ * is dropped, and a send outlives the Overview.
47
51
  */
48
52
  export function useOverviewCaptures(
49
53
  options: OverviewCaptureOptions,
@@ -77,17 +81,19 @@ export function useOverviewCaptures(
77
81
  );
78
82
  const firstCapture = computed(() => {
79
83
  const first = options.pages.value[0];
80
- if (!first || readsRealData(first, options.dataMode.value))
84
+ const drawing = options.drawing.value;
85
+ if (!first || !drawing || readsRealData(first, options.dataMode.value))
81
86
  return undefined;
82
87
  const page = first.id;
83
88
  const key = keys.value.get(page);
84
89
  return key !== undefined && captures.value.get(page)?.key === key
85
- ? { page, key }
90
+ ? { page, key, drawing }
86
91
  : undefined;
87
92
  });
88
- function send(page: string, key: string): void {
93
+ function send(page: string, key: string, drawing: string): void {
89
94
  const url = captures.value.get(page)?.url;
90
- if (!url || !claimCaptureUpload(options.name, page, key)) return;
95
+ const claim = JSON.stringify([key, drawing]);
96
+ if (!url || !claimCaptureUpload(options.name, page, claim)) return;
91
97
  upload?.abort();
92
98
  const current = new AbortController();
93
99
  upload = current;
@@ -96,21 +102,21 @@ export function useOverviewCaptures(
96
102
  .then((image) =>
97
103
  $authFetch(mockupEndpoint(options.name, MOCKUP_CAPTURE_SUFFIX), {
98
104
  method: "PUT",
99
- query: { page },
105
+ query: { page, drawing },
100
106
  body: image,
101
107
  signal: current.signal,
102
108
  }),
103
109
  )
104
- .catch(() => releaseCaptureUpload(options.name, page, key));
110
+ .catch(() => releaseCaptureUpload(options.name, page, claim));
105
111
  }
106
112
  watch(
107
113
  () => {
108
114
  const first = firstCapture.value;
109
- return first && JSON.stringify([first.page, first.key]);
115
+ return first && JSON.stringify([first.page, first.key, first.drawing]);
110
116
  },
111
117
  () => {
112
118
  const first = firstCapture.value;
113
- if (first) send(first.page, first.key);
119
+ if (first) send(first.page, first.key, first.drawing);
114
120
  },
115
121
  { immediate: true },
116
122
  );