@embeddable.com/sdk-react 2.3.4 → 2.4.0-next.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.esm.js +145 -29
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +147 -31
- package/lib/index.js.map +1 -1
- package/lib/loadComponentMeta.d.ts +1 -1
- package/lib/validate/schema/editorMetaSchema.d.ts +3 -0
- package/package.json +3 -4
package/lib/index.esm.js
CHANGED
|
@@ -7,12 +7,11 @@ 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 {
|
|
11
|
-
import generator from '@babel/generator';
|
|
12
|
-
import traverse from '@babel/traverse';
|
|
10
|
+
import { generate as generate$1 } from 'astring';
|
|
13
11
|
import 'node:child_process';
|
|
14
12
|
import { z } from 'zod';
|
|
15
|
-
import {
|
|
13
|
+
import { parse } from '@babel/parser';
|
|
14
|
+
import traverse from '@babel/traverse';
|
|
16
15
|
import * as fs$1 from 'fs';
|
|
17
16
|
|
|
18
17
|
var createContext = (pluginRoot, coreCtx) => {
|
|
@@ -27,32 +26,11 @@ var createContext = (pluginRoot, coreCtx) => {
|
|
|
27
26
|
};
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
const babelTraverse$1 = traverse.default;
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
const babelGenerate = generator.default;
|
|
34
|
-
const CORE_TYPES_IMPORT_REGEX = /@embeddable\.com\/core$/;
|
|
35
|
-
const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
|
|
36
|
-
const loadComponentMeta = async (moduleId, code) => {
|
|
37
|
-
const ast = parse(code, {
|
|
38
|
-
sourceType: "module",
|
|
39
|
-
});
|
|
40
|
-
babelTraverse$1(ast, {
|
|
41
|
-
ImportDeclaration: (path) => {
|
|
42
|
-
const isNativeTypesImport = CORE_TYPES_IMPORT_REGEX.test(path.node.source.value);
|
|
43
|
-
const isCustomTypeImport = EMB_TYPE_FILE_REGEX.test(path.node.source.value);
|
|
44
|
-
if (!(isNativeTypesImport || isCustomTypeImport)) {
|
|
45
|
-
path.remove();
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
ExportDefaultDeclaration: (path) => {
|
|
49
|
-
path.remove();
|
|
50
|
-
},
|
|
51
|
-
});
|
|
29
|
+
const loadComponentMeta = async (moduleId, ast) => {
|
|
52
30
|
const tempFilePath = moduleId
|
|
53
31
|
.replace(".emb.", ".emb-temp.")
|
|
54
32
|
.replace(/\.ts$/, ".js");
|
|
55
|
-
await fs.writeFile(tempFilePath,
|
|
33
|
+
await fs.writeFile(tempFilePath, generate$1(ast));
|
|
56
34
|
const module = await import(url.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
|
|
57
35
|
await fs.rm(tempFilePath);
|
|
58
36
|
return module.meta;
|
|
@@ -70,7 +48,7 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
|
|
|
70
48
|
var _a;
|
|
71
49
|
if (componentFileRegex.test(moduleInfo.id) &&
|
|
72
50
|
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
73
|
-
const meta = await loadComponentMeta(moduleInfo.id, moduleInfo.
|
|
51
|
+
const meta = await loadComponentMeta(moduleInfo.id, moduleInfo.ast);
|
|
74
52
|
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
75
53
|
value !== null &&
|
|
76
54
|
"__embeddableType" in value
|
|
@@ -404,6 +382,143 @@ const formatErrorPath = (path) => {
|
|
|
404
382
|
return formatted;
|
|
405
383
|
};
|
|
406
384
|
|
|
385
|
+
/******************************************************************************
|
|
386
|
+
Copyright (c) Microsoft Corporation.
|
|
387
|
+
|
|
388
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
389
|
+
purpose with or without fee is hereby granted.
|
|
390
|
+
|
|
391
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
392
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
393
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
394
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
395
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
396
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
397
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
398
|
+
***************************************************************************** */
|
|
399
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
var __assign = function() {
|
|
403
|
+
__assign = Object.assign || function __assign(t) {
|
|
404
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
405
|
+
s = arguments[i];
|
|
406
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
407
|
+
}
|
|
408
|
+
return t;
|
|
409
|
+
};
|
|
410
|
+
return __assign.apply(this, arguments);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
414
|
+
var e = new Error(message);
|
|
415
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
var DEFAULT_LOCALE = "en-US";
|
|
419
|
+
var createBuiltInType = function (name, typeConfig) {
|
|
420
|
+
if (typeConfig === void 0) { typeConfig = {}; }
|
|
421
|
+
return ({
|
|
422
|
+
__embeddableType: "built-in",
|
|
423
|
+
toString: function () { return name; },
|
|
424
|
+
typeConfig: __assign({ label: name, optionLabel: function () { return name; } }, typeConfig),
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
var STRING = "string";
|
|
428
|
+
var NUMBER = "number";
|
|
429
|
+
var BOOLEAN = "boolean";
|
|
430
|
+
var TIME = "time";
|
|
431
|
+
var TIME_RANGE = "timeRange";
|
|
432
|
+
var GRANULARITY = "granularity";
|
|
433
|
+
var DATASET = "dataset";
|
|
434
|
+
var MEASURE = "measure";
|
|
435
|
+
var DIMENSION = "dimension";
|
|
436
|
+
var DIMENSION_OR_MEASURE = "dimensionOrMeasure";
|
|
437
|
+
var ALL_NATIVE_TYPES = [
|
|
438
|
+
STRING,
|
|
439
|
+
NUMBER,
|
|
440
|
+
BOOLEAN,
|
|
441
|
+
TIME,
|
|
442
|
+
TIME_RANGE,
|
|
443
|
+
GRANULARITY,
|
|
444
|
+
DATASET,
|
|
445
|
+
MEASURE,
|
|
446
|
+
DIMENSION,
|
|
447
|
+
DIMENSION_OR_MEASURE,
|
|
448
|
+
];
|
|
449
|
+
|
|
450
|
+
createBuiltInType("string", {
|
|
451
|
+
transform: function (value) { return value; },
|
|
452
|
+
optionLabel: function (value) {
|
|
453
|
+
return Array.isArray(value)
|
|
454
|
+
? "[".concat(value.map(function (v) { return "\"".concat(v, "\""); }).join(","), "]")
|
|
455
|
+
: "\"".concat(value, "\"");
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
createBuiltInType("number", {
|
|
459
|
+
transform: function (value) {
|
|
460
|
+
return Array.isArray(value) ? value : value ? Number(value) : value;
|
|
461
|
+
},
|
|
462
|
+
optionLabel: function (value) {
|
|
463
|
+
var _a;
|
|
464
|
+
return Array.isArray(value)
|
|
465
|
+
? "[".concat(value.join(","), "]")
|
|
466
|
+
: (_a = value === null || value === void 0 ? void 0 : value.toLocaleString(DEFAULT_LOCALE)) !== null && _a !== void 0 ? _a : "";
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
createBuiltInType("boolean", {
|
|
470
|
+
transform: function (value) { return value === "true" || value === true; },
|
|
471
|
+
optionLabel: function (value) { return (value ? "true" : "false"); },
|
|
472
|
+
});
|
|
473
|
+
createBuiltInType("time", {
|
|
474
|
+
transform: function (value) {
|
|
475
|
+
var date = (value === null || value === void 0 ? void 0 : value.date) ? new Date(value.date) : undefined;
|
|
476
|
+
var isValid = date && date.toString() !== "Invalid Date";
|
|
477
|
+
return {
|
|
478
|
+
date: isValid ? date : undefined,
|
|
479
|
+
relativeTimeString: value === null || value === void 0 ? void 0 : value.relativeTimeString,
|
|
480
|
+
};
|
|
481
|
+
},
|
|
482
|
+
optionLabel: function (value) {
|
|
483
|
+
var _a, _b;
|
|
484
|
+
if (!value)
|
|
485
|
+
return "";
|
|
486
|
+
if (value === null || value === void 0 ? void 0 : value.date) {
|
|
487
|
+
return ((_b = (_a = value.date) === null || _a === void 0 ? void 0 : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== void 0 ? _b : value.date.toLocaleString());
|
|
488
|
+
}
|
|
489
|
+
return value.relativeTimeString;
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
createBuiltInType("timeRange", {
|
|
493
|
+
transform: function (value) {
|
|
494
|
+
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];
|
|
495
|
+
var fromDate = new Date(from);
|
|
496
|
+
var toDate = new Date(to);
|
|
497
|
+
return {
|
|
498
|
+
from: fromDate.toString() !== "Invalid Date" ? fromDate : undefined,
|
|
499
|
+
to: toDate.toString() !== "Invalid Date" ? toDate : undefined,
|
|
500
|
+
relativeTimeString: value === null || value === void 0 ? void 0 : value.relativeTimeString,
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
optionLabel: function (value) {
|
|
504
|
+
var _a, _b, _c, _d, _e, _f;
|
|
505
|
+
if (!value)
|
|
506
|
+
return "";
|
|
507
|
+
if ((value === null || value === void 0 ? void 0 : value.from) && (value === null || value === void 0 ? void 0 : value.to)) {
|
|
508
|
+
return "".concat((_b = (_a = value.from) === null || _a === void 0 ? void 0 : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== void 0 ? _b : (_c = value.from) === null || _c === void 0 ? void 0 : _c.toLocaleString(), ",").concat((_e = (_d = value.to) === null || _d === void 0 ? void 0 : _d.toLocaleDateString(DEFAULT_LOCALE)) !== null && _e !== void 0 ? _e : (_f = value.to) === null || _f === void 0 ? void 0 : _f.toLocaleString());
|
|
509
|
+
}
|
|
510
|
+
return value === null || value === void 0 ? void 0 : value.relativeTimeString;
|
|
511
|
+
},
|
|
512
|
+
});
|
|
513
|
+
createBuiltInType("granularity", {
|
|
514
|
+
transform: function (value) { return value; },
|
|
515
|
+
optionLabel: function (value) { return value; },
|
|
516
|
+
});
|
|
517
|
+
createBuiltInType("dataset");
|
|
518
|
+
createBuiltInType("measure");
|
|
519
|
+
createBuiltInType("dimension");
|
|
520
|
+
createBuiltInType("dimensionOrMeasure");
|
|
521
|
+
|
|
407
522
|
const embeddableTypeSchema = z
|
|
408
523
|
.object({
|
|
409
524
|
typeConfig: z.object({
|
|
@@ -418,6 +533,7 @@ const editorMetaSchema = z
|
|
|
418
533
|
name: z.string(),
|
|
419
534
|
label: z.string(),
|
|
420
535
|
type: embeddableTypeSchema,
|
|
536
|
+
config: z.object({}).optional(),
|
|
421
537
|
})
|
|
422
538
|
.strict();
|
|
423
539
|
|
|
@@ -732,7 +848,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
732
848
|
? getModuleType(moduleInfo)
|
|
733
849
|
: null;
|
|
734
850
|
if (moduleType) {
|
|
735
|
-
const meta = await loadComponentMeta(moduleInfo.id, moduleInfo.
|
|
851
|
+
const meta = await loadComponentMeta(moduleInfo.id, moduleInfo.ast);
|
|
736
852
|
metaConfigs.push({
|
|
737
853
|
moduleId: moduleInfo.id,
|
|
738
854
|
meta,
|