@embeddable.com/sdk-react 3.2.0-next.9 → 3.2.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.
@@ -4,7 +4,7 @@ declare const _default: ({ globalKey, outputDir, fileName, componentFileRegex, s
4
4
  outputDir: string;
5
5
  fileName: string;
6
6
  componentFileRegex: RegExp;
7
- searchEntry?: string | undefined;
7
+ searchEntry?: string;
8
8
  }) => {
9
9
  name: string;
10
10
  moduleParsed: (moduleInfo: ModuleInfo) => Promise<void>;
package/lib/index.esm.js CHANGED
@@ -7,7 +7,9 @@ import viteReactPlugin from '@vitejs/plugin-react';
7
7
  import * as fs from 'node:fs/promises';
8
8
  import { readdir, lstat, rm } from 'node:fs/promises';
9
9
  import * as url from 'node:url';
10
+ import { GlobalRegistrator } from '@happy-dom/global-registrator';
10
11
  import 'node:child_process';
12
+ import * as crypto from 'node:crypto';
11
13
  import { z } from 'zod';
12
14
  import { parse } from '@babel/parser';
13
15
  import traverse from '@babel/traverse';
@@ -25,45 +27,16 @@ var createContext = (pluginRoot, coreCtx) => {
25
27
  };
26
28
  };
27
29
 
30
+ GlobalRegistrator.register({
31
+ url: "http://localhost:3000",
32
+ width: 1920,
33
+ height: 1080,
34
+ });
28
35
  const loadComponentMeta = async (moduleId) => {
29
36
  const module = await import(url.pathToFileURL(moduleId).href);
30
37
  return module.meta;
31
38
  };
32
39
 
33
- /**
34
- * TODO: for some reason code from @embeddable.com/extract-components-config
35
- * is being cached. Thus we use this code duplication in place. Please investigate and fix.
36
- */
37
- var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
38
- let configs = [];
39
- return {
40
- name: "extract-components-config",
41
- moduleParsed: async (moduleInfo) => {
42
- var _a;
43
- if (componentFileRegex.test(moduleInfo.id) &&
44
- ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
45
- const meta = await loadComponentMeta(moduleInfo.id);
46
- const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
47
- value !== null &&
48
- "__embeddableType" in value
49
- ? value.toString()
50
- : value);
51
- configs.push(configJSON);
52
- }
53
- },
54
- buildEnd: async () => {
55
- const template = `
56
- globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
57
- globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey} || [
58
- __PLACEHOLDER__
59
- ];
60
- `;
61
- await fs.writeFile(`${outputDir}/${fileName}`, template.replace("__PLACEHOLDER__", configs.filter(Boolean).join(",\n")));
62
- configs = [];
63
- },
64
- };
65
- };
66
-
67
40
  var findFiles = async (initialSrcDir, regex) => {
68
41
  const filesList = [];
69
42
  async function findFilesRec(srcDir) {
@@ -270,6 +243,11 @@ class ZodError extends Error {
270
243
  processError(this);
271
244
  return fieldErrors;
272
245
  }
246
+ static assert(value) {
247
+ if (!(value instanceof ZodError)) {
248
+ throw new Error(`Not a ZodError: ${value}`);
249
+ }
250
+ }
273
251
  toString() {
274
252
  return this.message;
275
253
  }
@@ -301,6 +279,11 @@ ZodError.create = (issues) => {
301
279
  const error = new ZodError(issues);
302
280
  return error;
303
281
  };
282
+
283
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
284
+ var e = new Error(message);
285
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
286
+ };
304
287
 
305
288
  var errorUtil;
306
289
  (function (errorUtil) {
@@ -376,6 +359,60 @@ const formatErrorPath = (path) => {
376
359
  return formatted;
377
360
  };
378
361
 
362
+ /**
363
+ * Get the hash of the content string. It returns the first 5 characters of the hash
364
+ * Example: getContentHash("Hello World")
365
+ * @param contentString The content string to hash
366
+ * @returns
367
+ */
368
+ const getContentHash = (contentString) => {
369
+ return crypto
370
+ .createHash("md5")
371
+ .update(contentString)
372
+ .digest("hex")
373
+ .substring(0, 5);
374
+ };
375
+
376
+ /**
377
+ * TODO: for some reason code from @embeddable.com/extract-components-config
378
+ * is being cached. Thus we use this code duplication in place. Please investigate and fix.
379
+ */
380
+ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
381
+ let configs = [];
382
+ return {
383
+ name: "extract-components-config",
384
+ moduleParsed: async (moduleInfo) => {
385
+ var _a;
386
+ if (componentFileRegex.test(moduleInfo.id) &&
387
+ ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
388
+ const meta = await loadComponentMeta(moduleInfo.id);
389
+ const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
390
+ value !== null &&
391
+ "__embeddableType" in value
392
+ ? value.toString()
393
+ : value);
394
+ configs.push(configJSON);
395
+ }
396
+ },
397
+ buildEnd: async () => {
398
+ const template = `
399
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
400
+ globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey} || [
401
+ __PLACEHOLDER__
402
+ ];
403
+ `;
404
+ // sort to make sure the hash is consistent
405
+ configs.sort((a, b) => a.localeCompare(b));
406
+ const contentString = configs.filter(Boolean).join(",\n");
407
+ const fileHash = getContentHash(contentString);
408
+ const fileHashExtention = `-${fileHash}.js`;
409
+ const fileNameHashed = `${fileName.replace(".js", fileHashExtention)}`;
410
+ await fs.writeFile(`${outputDir}/${fileNameHashed}`, template.replace("__PLACEHOLDER__", contentString));
411
+ configs = [];
412
+ },
413
+ };
414
+ };
415
+
379
416
  /******************************************************************************
380
417
  Copyright (c) Microsoft Corporation.
381
418
 
@@ -485,6 +522,9 @@ createBuiltInType("time", {
485
522
  });
486
523
  createBuiltInType("timeRange", {
487
524
  transform: function (value) {
525
+ // Return undefined instead of a null populated object
526
+ if (!value)
527
+ return undefined;
488
528
  var _a = [value === null || value === void 0 ? void 0 : value.from, value === null || value === void 0 ? void 0 : value.to], from = _a[0], to = _a[1];
489
529
  var fromDate = new Date(from);
490
530
  var toDate = new Date(to);