@vizhub/runtime 0.0.1 → 0.0.2

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 (52) hide show
  1. package/dist/assets/setupV3Runtime-BVr5lyKp.js +240 -0
  2. package/{src/v2Runtime/bundle/rollup.browser.js → dist/index.js} +9286 -12810
  3. package/package.json +12 -6
  4. package/src/computeSrcDoc.ts +0 -68
  5. package/src/index.ts +0 -7
  6. package/src/useRuntime.ts +0 -394
  7. package/src/v2Runtime/bundle/bubleJSXOnly.ts +0 -34
  8. package/src/v2Runtime/bundle/getLibraries.js +0 -31
  9. package/src/v2Runtime/bundle/hypothetical.js +0 -232
  10. package/src/v2Runtime/bundle/index.js +0 -88
  11. package/src/v2Runtime/bundle/packageJson.ts +0 -49
  12. package/src/v2Runtime/bundle.test.js +0 -151
  13. package/src/v2Runtime/computeSrcDocV2.test.ts +0 -163
  14. package/src/v2Runtime/computeSrcDocV2.ts +0 -34
  15. package/src/v2Runtime/getComputedIndexHtml.test.ts +0 -33
  16. package/src/v2Runtime/getComputedIndexHtml.ts +0 -106
  17. package/src/v2Runtime/getText.ts +0 -19
  18. package/src/v2Runtime/magicSandbox.js +0 -291
  19. package/src/v2Runtime/packageJson.js +0 -42
  20. package/src/v2Runtime/transformFiles.test.js +0 -18
  21. package/src/v2Runtime/transformFiles.ts +0 -15
  22. package/src/v2Runtime/v3FilesToV2Files.test.ts +0 -20
  23. package/src/v2Runtime/v3FilesToV2Files.ts +0 -14
  24. package/src/v3Runtime/build.test.ts +0 -474
  25. package/src/v3Runtime/build.ts +0 -270
  26. package/src/v3Runtime/cleanRollupErrorMessage.ts +0 -15
  27. package/src/v3Runtime/computeSrcDocV3.ts +0 -151
  28. package/src/v3Runtime/extractVizImport.test.ts +0 -41
  29. package/src/v3Runtime/extractVizImport.ts +0 -34
  30. package/src/v3Runtime/generateRollupErrorMessage.ts +0 -84
  31. package/src/v3Runtime/importFromViz.ts +0 -36
  32. package/src/v3Runtime/index.ts +0 -1
  33. package/src/v3Runtime/parseId.ts +0 -14
  34. package/src/v3Runtime/setupV3Runtime.ts +0 -478
  35. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/bundle-modified-src.js +0 -121
  36. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/bundle-modified.js +0 -121
  37. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/bundle.js +0 -239
  38. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/index.js +0 -1
  39. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/package-lock.json +0 -475
  40. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/package.json +0 -19
  41. package/src/v3Runtime/transformDSV/d3-dsv-custom-build/rollup.config.js +0 -9
  42. package/src/v3Runtime/transformDSV/index.ts +0 -71
  43. package/src/v3Runtime/transformSvelte.ts +0 -111
  44. package/src/v3Runtime/types.ts +0 -158
  45. package/src/v3Runtime/urlLoad.ts +0 -33
  46. package/src/v3Runtime/virtual.ts +0 -27
  47. package/src/v3Runtime/vizCache.test.ts +0 -126
  48. package/src/v3Runtime/vizCache.ts +0 -60
  49. package/src/v3Runtime/vizLoad.ts +0 -68
  50. package/src/v3Runtime/vizLoadSvelte.ts +0 -46
  51. package/src/v3Runtime/vizResolve.ts +0 -100
  52. package/src/v3Runtime/worker.ts +0 -231
@@ -0,0 +1,240 @@
1
+ import { cleanRollupErrorMessage, p as parseId, g as getFileText } from "../index.js";
2
+ import "buble";
3
+ import "path-posix";
4
+ import "vizhub-libraries";
5
+ import "sharedb-client-browser/dist/ot-json1-presence-umd.cjs";
6
+ import "json0-ot-diff";
7
+ import "diff-match-patch";
8
+ import "react";
9
+ function WorkerWrapper(options) {
10
+ return new Worker(
11
+ "/assets/worker-CLxqJrPo.js",
12
+ {
13
+ name: options == null ? void 0 : options.name
14
+ }
15
+ );
16
+ }
17
+ const IDLE = "IDLE";
18
+ const ENQUEUED = "ENQUEUED";
19
+ const PENDING_CLEAN = "PENDING_CLEAN";
20
+ const PENDING_DIRTY = "PENDING_DIRTY";
21
+ const setupV3Runtime = ({
22
+ vizId,
23
+ iframe,
24
+ setSrcdocErrorMessage,
25
+ getLatestContent,
26
+ resolveSlugKey,
27
+ writeFile
28
+ }) => {
29
+ const worker = new WorkerWrapper();
30
+ let state = IDLE;
31
+ let pendingBuildPromise = null;
32
+ let pendingRunPromise = null;
33
+ worker.addEventListener("message", async ({ data }) => {
34
+ const message = data;
35
+ if (message.type === "buildResponse") {
36
+ const buildResult = message.buildResult;
37
+ const error = message.error;
38
+ if (pendingBuildPromise) {
39
+ pendingBuildPromise(buildResult);
40
+ pendingBuildPromise = null;
41
+ }
42
+ if (error) {
43
+ setSrcdocErrorMessage(
44
+ cleanRollupErrorMessage({
45
+ rawMessage: error.message,
46
+ vizId
47
+ })
48
+ );
49
+ }
50
+ }
51
+ if (message.type === "contentRequest") {
52
+ const { vizId: vizId2 } = message;
53
+ const content = await getLatestContent(vizId2);
54
+ const contentResponseMessage = {
55
+ type: "contentResponse",
56
+ vizId: message.vizId,
57
+ content
58
+ };
59
+ worker.postMessage(contentResponseMessage);
60
+ }
61
+ if (message.type === "resolveSlugRequest") {
62
+ const { slugKey } = message;
63
+ const resolveSlugResponseMessage = {
64
+ type: "resolveSlugResponse",
65
+ slugKey,
66
+ requestId: message.requestId,
67
+ vizId: await resolveSlugKey(slugKey)
68
+ };
69
+ worker.postMessage(resolveSlugResponseMessage);
70
+ }
71
+ if (message.type === "invalidateVizCacheResponse") {
72
+ handleCodeChange();
73
+ }
74
+ if (message.type === "resetSrcdocResponse") {
75
+ const srcdoc = message.srcdoc;
76
+ const error = message.error;
77
+ if (error) {
78
+ setSrcdocErrorMessage(
79
+ cleanRollupErrorMessage({
80
+ rawMessage: error.message,
81
+ vizId
82
+ })
83
+ );
84
+ } else {
85
+ setSrcdocErrorMessage(null);
86
+ if (srcdoc) {
87
+ iframe.srcdoc = srcdoc;
88
+ }
89
+ }
90
+ }
91
+ });
92
+ window.addEventListener("message", ({ data }) => {
93
+ if (data.type === "runDone" || data.type === "runError") {
94
+ if (pendingRunPromise) {
95
+ pendingRunPromise();
96
+ pendingRunPromise = null;
97
+ }
98
+ }
99
+ if (data.type === "runError") {
100
+ setSrcdocErrorMessage(data.error.message);
101
+ }
102
+ if (data.type === "writeFile") {
103
+ if (data.fileName && data.content) {
104
+ writeFile(data.fileName, data.content);
105
+ }
106
+ }
107
+ });
108
+ const handleCodeChange = () => {
109
+ if (state === IDLE) {
110
+ state = ENQUEUED;
111
+ update();
112
+ } else if (state === PENDING_CLEAN) {
113
+ state = PENDING_DIRTY;
114
+ }
115
+ };
116
+ const invalidateVizCache = (changedVizIds) => {
117
+ const message = {
118
+ type: "invalidateVizCacheRequest",
119
+ changedVizIds
120
+ };
121
+ worker.postMessage(message);
122
+ };
123
+ {
124
+ setInterval(() => {
125
+ }, 1e3);
126
+ }
127
+ const build = () => {
128
+ return new Promise(
129
+ (resolve) => {
130
+ pendingBuildPromise = resolve;
131
+ const message = {
132
+ type: "buildRequest",
133
+ vizId,
134
+ enableSourcemap: true
135
+ };
136
+ worker.postMessage(message);
137
+ }
138
+ );
139
+ };
140
+ const update = async () => {
141
+ state = PENDING_CLEAN;
142
+ const buildResult = await build();
143
+ if (buildResult !== void 0) {
144
+ await run(buildResult);
145
+ }
146
+ if (state === PENDING_DIRTY) {
147
+ requestAnimationFrame(update);
148
+ state = ENQUEUED;
149
+ } else {
150
+ state = IDLE;
151
+ }
152
+ };
153
+ let previousCSSFiles = [];
154
+ const run = (buildResult) => {
155
+ return new Promise((resolve) => {
156
+ var _a;
157
+ const { src, warnings, cssFiles } = buildResult;
158
+ if (src === void 0) {
159
+ throw new Error(
160
+ "[v3 runtime] src is undefined, but no errors!"
161
+ );
162
+ }
163
+ pendingRunPromise = resolve;
164
+ if (warnings.length > 0) {
165
+ setSrcdocErrorMessage(
166
+ warnings.map((warning) => warning.message).join("\n\n")
167
+ );
168
+ } else {
169
+ setSrcdocErrorMessage(null);
170
+ }
171
+ if (iframe.contentWindow) {
172
+ for (const cssFile of cssFiles) {
173
+ const { vizId: vizId2, fileName } = parseId(cssFile);
174
+ getLatestContent(vizId2).then((content) => {
175
+ var _a2;
176
+ const src2 = getFileText(content, fileName);
177
+ if (src2 === null) {
178
+ console.warn(
179
+ `Imported CSS file ${fileName} doesn't exist.`
180
+ );
181
+ return;
182
+ }
183
+ const runCSSMessage = {
184
+ type: "runCSS",
185
+ id: cssFile,
186
+ src: src2
187
+ };
188
+ (_a2 = iframe.contentWindow) == null ? void 0 : _a2.postMessage(
189
+ runCSSMessage,
190
+ window.location.origin
191
+ );
192
+ });
193
+ }
194
+ const removedCSSFiles = previousCSSFiles.filter(
195
+ (id) => !cssFiles.includes(id)
196
+ );
197
+ previousCSSFiles = cssFiles;
198
+ for (const id of removedCSSFiles) {
199
+ const removeCSSMessage = {
200
+ type: "runCSS",
201
+ id,
202
+ src: ""
203
+ };
204
+ (_a = iframe.contentWindow) == null ? void 0 : _a.postMessage(
205
+ removeCSSMessage,
206
+ window.location.origin
207
+ );
208
+ }
209
+ console.clear();
210
+ const runJSMessage = {
211
+ type: "runJS",
212
+ src
213
+ };
214
+ iframe.contentWindow.postMessage(
215
+ runJSMessage,
216
+ window.location.origin
217
+ );
218
+ }
219
+ });
220
+ };
221
+ const resetSrcdoc = (changedVizIds) => {
222
+ state = IDLE;
223
+ pendingBuildPromise = null;
224
+ pendingRunPromise = null;
225
+ const message = {
226
+ type: "resetSrcdocRequest",
227
+ vizId,
228
+ changedVizIds
229
+ };
230
+ worker.postMessage(message);
231
+ };
232
+ return {
233
+ handleCodeChange,
234
+ invalidateVizCache,
235
+ resetSrcdoc
236
+ };
237
+ };
238
+ export {
239
+ setupV3Runtime
240
+ };