@embeddable.com/sdk-react 3.2.0-next.8 → 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.
package/lib/index.js CHANGED
@@ -7,7 +7,9 @@ var vite = require('vite');
7
7
  var viteReactPlugin = require('@vitejs/plugin-react');
8
8
  var fs = require('node:fs/promises');
9
9
  var url = require('node:url');
10
+ var globalRegistrator = require('@happy-dom/global-registrator');
10
11
  require('node:child_process');
12
+ var crypto = require('node:crypto');
11
13
  var zod = require('zod');
12
14
  var parser = require('@babel/parser');
13
15
  var traverse = require('@babel/traverse');
@@ -36,6 +38,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
36
38
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
37
39
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
38
40
  var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
41
+ var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
39
42
  var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
40
43
 
41
44
  var createContext = (pluginRoot, coreCtx) => {
@@ -50,45 +53,16 @@ var createContext = (pluginRoot, coreCtx) => {
50
53
  };
51
54
  };
52
55
 
56
+ globalRegistrator.GlobalRegistrator.register({
57
+ url: "http://localhost:3000",
58
+ width: 1920,
59
+ height: 1080,
60
+ });
53
61
  const loadComponentMeta = async (moduleId) => {
54
62
  const module = await import(url__namespace.pathToFileURL(moduleId).href);
55
63
  return module.meta;
56
64
  };
57
65
 
58
- /**
59
- * TODO: for some reason code from @embeddable.com/extract-components-config
60
- * is being cached. Thus we use this code duplication in place. Please investigate and fix.
61
- */
62
- var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
63
- let configs = [];
64
- return {
65
- name: "extract-components-config",
66
- moduleParsed: async (moduleInfo) => {
67
- var _a;
68
- if (componentFileRegex.test(moduleInfo.id) &&
69
- ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
70
- const meta = await loadComponentMeta(moduleInfo.id);
71
- const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
72
- value !== null &&
73
- "__embeddableType" in value
74
- ? value.toString()
75
- : value);
76
- configs.push(configJSON);
77
- }
78
- },
79
- buildEnd: async () => {
80
- const template = `
81
- globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
82
- globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey} || [
83
- __PLACEHOLDER__
84
- ];
85
- `;
86
- await fs__namespace.writeFile(`${outputDir}/${fileName}`, template.replace("__PLACEHOLDER__", configs.filter(Boolean).join(",\n")));
87
- configs = [];
88
- },
89
- };
90
- };
91
-
92
66
  var findFiles = async (initialSrcDir, regex) => {
93
67
  const filesList = [];
94
68
  async function findFilesRec(srcDir) {
@@ -295,6 +269,11 @@ class ZodError extends Error {
295
269
  processError(this);
296
270
  return fieldErrors;
297
271
  }
272
+ static assert(value) {
273
+ if (!(value instanceof ZodError)) {
274
+ throw new Error(`Not a ZodError: ${value}`);
275
+ }
276
+ }
298
277
  toString() {
299
278
  return this.message;
300
279
  }
@@ -326,6 +305,11 @@ ZodError.create = (issues) => {
326
305
  const error = new ZodError(issues);
327
306
  return error;
328
307
  };
308
+
309
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
310
+ var e = new Error(message);
311
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
312
+ };
329
313
 
330
314
  var errorUtil;
331
315
  (function (errorUtil) {
@@ -401,6 +385,60 @@ const formatErrorPath = (path) => {
401
385
  return formatted;
402
386
  };
403
387
 
388
+ /**
389
+ * Get the hash of the content string. It returns the first 5 characters of the hash
390
+ * Example: getContentHash("Hello World")
391
+ * @param contentString The content string to hash
392
+ * @returns
393
+ */
394
+ const getContentHash = (contentString) => {
395
+ return crypto__namespace
396
+ .createHash("md5")
397
+ .update(contentString)
398
+ .digest("hex")
399
+ .substring(0, 5);
400
+ };
401
+
402
+ /**
403
+ * TODO: for some reason code from @embeddable.com/extract-components-config
404
+ * is being cached. Thus we use this code duplication in place. Please investigate and fix.
405
+ */
406
+ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
407
+ let configs = [];
408
+ return {
409
+ name: "extract-components-config",
410
+ moduleParsed: async (moduleInfo) => {
411
+ var _a;
412
+ if (componentFileRegex.test(moduleInfo.id) &&
413
+ ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
414
+ const meta = await loadComponentMeta(moduleInfo.id);
415
+ const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
416
+ value !== null &&
417
+ "__embeddableType" in value
418
+ ? value.toString()
419
+ : value);
420
+ configs.push(configJSON);
421
+ }
422
+ },
423
+ buildEnd: async () => {
424
+ const template = `
425
+ globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
426
+ globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey} || [
427
+ __PLACEHOLDER__
428
+ ];
429
+ `;
430
+ // sort to make sure the hash is consistent
431
+ configs.sort((a, b) => a.localeCompare(b));
432
+ const contentString = configs.filter(Boolean).join(",\n");
433
+ const fileHash = getContentHash(contentString);
434
+ const fileHashExtention = `-${fileHash}.js`;
435
+ const fileNameHashed = `${fileName.replace(".js", fileHashExtention)}`;
436
+ await fs__namespace.writeFile(`${outputDir}/${fileNameHashed}`, template.replace("__PLACEHOLDER__", contentString));
437
+ configs = [];
438
+ },
439
+ };
440
+ };
441
+
404
442
  /******************************************************************************
405
443
  Copyright (c) Microsoft Corporation.
406
444
 
@@ -510,6 +548,9 @@ createBuiltInType("time", {
510
548
  });
511
549
  createBuiltInType("timeRange", {
512
550
  transform: function (value) {
551
+ // Return undefined instead of a null populated object
552
+ if (!value)
553
+ return undefined;
513
554
  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];
514
555
  var fromDate = new Date(from);
515
556
  var toDate = new Date(to);