@devtools-ui/console 0.0.2--canary.11.588
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/dist/cjs/index.cjs +112 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +74 -0
- package/dist/index.mjs +74 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
- package/src/component/index.tsx +9 -0
- package/src/dsl/__tests__/index.test.tsx +19 -0
- package/src/dsl/index.tsx +39 -0
- package/src/index.ts +4 -0
- package/src/transform/index.ts +62 -0
- package/src/types/index.ts +30 -0
- package/types/component/index.d.ts +4 -0
- package/types/dsl/index.d.ts +12 -0
- package/types/index.d.ts +5 -0
- package/types/transform/index.d.ts +13 -0
- package/types/types/index.d.ts +25 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Console: () => Console2,
|
|
34
|
+
ConsoleComponent: () => ConsoleComponent,
|
|
35
|
+
consoleTransform: () => consoleTransform,
|
|
36
|
+
expPropTransform: () => expPropTransform,
|
|
37
|
+
transform: () => transform
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
|
|
41
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/component/index.tsx
|
|
42
|
+
var import_react = __toESM(require("react"));
|
|
43
|
+
var import_console = require("@devtools-ds/console");
|
|
44
|
+
var ConsoleComponent = (props) => {
|
|
45
|
+
const { evaluate, history } = props;
|
|
46
|
+
return /* @__PURE__ */ import_react.default.createElement(import_console.Console, { execute: evaluate, history });
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/dsl/index.tsx
|
|
50
|
+
var import_react2 = __toESM(require("react"));
|
|
51
|
+
var import_dsl = require("@player-tools/dsl");
|
|
52
|
+
var Console2 = (props) => {
|
|
53
|
+
const { exp, binding } = props;
|
|
54
|
+
let expValue;
|
|
55
|
+
if ((0, import_dsl.isTemplateStringInstance)(exp)) {
|
|
56
|
+
expValue = exp.toValue();
|
|
57
|
+
} else if (Array.isArray(exp)) {
|
|
58
|
+
expValue = exp.map((e) => typeof e === "string" ? e : e.toValue());
|
|
59
|
+
} else if (exp) {
|
|
60
|
+
expValue = exp;
|
|
61
|
+
}
|
|
62
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_dsl.Asset, { type: "console" }, exp && /* @__PURE__ */ import_react2.default.createElement("property", { name: "exp" }, expValue), binding && /* @__PURE__ */ import_react2.default.createElement("property", { name: "binding" }, binding.toValue()));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/transform/index.ts
|
|
66
|
+
var import_asset_transform_plugin = require("@player-ui/asset-transform-plugin");
|
|
67
|
+
var transform = (asset, options) => {
|
|
68
|
+
return {
|
|
69
|
+
...asset,
|
|
70
|
+
history: asset.binding === void 0 ? void 0 : options.data.model.get(asset.binding, {
|
|
71
|
+
includeInvalid: true,
|
|
72
|
+
formatted: false
|
|
73
|
+
}),
|
|
74
|
+
evaluate() {
|
|
75
|
+
if (asset.exp) {
|
|
76
|
+
options.evaluate(asset.exp);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
var expPropTransform = (asset) => {
|
|
82
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
83
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
84
|
+
return asset;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...asset,
|
|
88
|
+
plugins: {
|
|
89
|
+
...asset.plugins,
|
|
90
|
+
stringResolver: {
|
|
91
|
+
...asset?.plugins?.stringResolver,
|
|
92
|
+
propertiesToSkip: [
|
|
93
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
94
|
+
"exp"
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
var consoleTransform = (0, import_asset_transform_plugin.compose)(
|
|
101
|
+
transform,
|
|
102
|
+
(0, import_asset_transform_plugin.composeBefore)(expPropTransform)
|
|
103
|
+
);
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
Console,
|
|
107
|
+
ConsoleComponent,
|
|
108
|
+
consoleTransform,
|
|
109
|
+
expPropTransform,
|
|
110
|
+
transform
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/component/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/dsl/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./component\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import React from \"react\";\nimport { Console } from \"@devtools-ds/console\";\nimport type { TransformedConsole } from \"../types\";\n\nexport const ConsoleComponent = (props: TransformedConsole) => {\n const { evaluate, history } = props;\n\n return <Console execute={evaluate} history={history} />;\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n isTemplateStringInstance,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { ConsoleAsset } from \"../types\";\n\n/**\n * Defines the component DSL representation for the Console asset,\n * a component that emulates a REPL environment that you see in browsers.\n */\nexport const Console = (\n props: Omit<AssetPropsWithChildren<ConsoleAsset>, \"binding\"> & {\n /** Binding as template string */\n binding: BindingTemplateInstance;\n }\n) => {\n const { exp, binding } = props;\n\n // Extracting the exp value from the props\n let expValue: ConsoleAsset[\"exp\"];\n\n if (isTemplateStringInstance(exp)) {\n expValue = exp.toValue();\n } else if (Array.isArray(exp)) {\n expValue = exp.map((e) => (typeof e === \"string\" ? e : e.toValue()));\n } else if (exp) {\n expValue = exp;\n }\n\n return (\n <Asset type=\"console\">\n {exp && <property name=\"exp\">{expValue}</property>}\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\n </Asset>\n );\n};\n","import type {\n Asset,\n BeforeTransformFunction,\n TransformFunction,\n} from \"@player-ui/player\";\nimport { compose, composeBefore } from \"@player-ui/asset-transform-plugin\";\nimport { ConsoleAsset, TransformedConsole } from \"../types\";\n\n/**\n * Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)\n * and embeds Player state and methods:\n */\nexport const transform: TransformFunction<ConsoleAsset, TransformedConsole> = (\n asset,\n options\n) => {\n return {\n ...asset,\n history:\n asset.binding === undefined\n ? undefined\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n evaluate() {\n if (asset.exp) {\n options.evaluate(asset.exp);\n }\n },\n };\n};\n\n/**\n * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist\n */\nexport const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {\n const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;\n\n if (skipArray && skipArray.indexOf(\"exp\") > 1) {\n return asset;\n }\n\n return {\n ...asset,\n plugins: {\n ...asset.plugins,\n stringResolver: {\n ...asset?.plugins?.stringResolver,\n propertiesToSkip: [\n ...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),\n \"exp\",\n ],\n },\n },\n };\n};\n\nexport const consoleTransform = compose(\n transform,\n composeBefore(expPropTransform)\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,iBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAClB,qBAAwB;AAGjB,IAAM,mBAAmB,CAAC,UAA8B;AAC7D,QAAM,EAAE,UAAU,QAAQ,IAAI;AAE9B,SAAO,6BAAAC,QAAA,cAAC,0BAAQ,SAAS,UAAU,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,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,uBAAmB;AAAA,EAC9B;AAAA,MACA,6CAAc,gBAAgB;AAChC;","names":["Console","React","import_react","Console","React"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/component/index.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Console } from "@devtools-ds/console";
|
|
4
|
+
var ConsoleComponent = (props) => {
|
|
5
|
+
const { evaluate, history } = props;
|
|
6
|
+
return /* @__PURE__ */ React.createElement(Console, { execute: evaluate, history });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/dsl/index.tsx
|
|
10
|
+
import React2 from "react";
|
|
11
|
+
import {
|
|
12
|
+
Asset,
|
|
13
|
+
isTemplateStringInstance
|
|
14
|
+
} from "@player-tools/dsl";
|
|
15
|
+
var Console2 = (props) => {
|
|
16
|
+
const { exp, binding } = props;
|
|
17
|
+
let expValue;
|
|
18
|
+
if (isTemplateStringInstance(exp)) {
|
|
19
|
+
expValue = exp.toValue();
|
|
20
|
+
} else if (Array.isArray(exp)) {
|
|
21
|
+
expValue = exp.map((e) => typeof e === "string" ? e : e.toValue());
|
|
22
|
+
} else if (exp) {
|
|
23
|
+
expValue = exp;
|
|
24
|
+
}
|
|
25
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "console" }, exp && /* @__PURE__ */ React2.createElement("property", { name: "exp" }, expValue), binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/transform/index.ts
|
|
29
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
30
|
+
var transform = (asset, options) => {
|
|
31
|
+
return {
|
|
32
|
+
...asset,
|
|
33
|
+
history: asset.binding === void 0 ? void 0 : options.data.model.get(asset.binding, {
|
|
34
|
+
includeInvalid: true,
|
|
35
|
+
formatted: false
|
|
36
|
+
}),
|
|
37
|
+
evaluate() {
|
|
38
|
+
if (asset.exp) {
|
|
39
|
+
options.evaluate(asset.exp);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var expPropTransform = (asset) => {
|
|
45
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
46
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
47
|
+
return asset;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
...asset,
|
|
51
|
+
plugins: {
|
|
52
|
+
...asset.plugins,
|
|
53
|
+
stringResolver: {
|
|
54
|
+
...asset?.plugins?.stringResolver,
|
|
55
|
+
propertiesToSkip: [
|
|
56
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
57
|
+
"exp"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
var consoleTransform = compose(
|
|
64
|
+
transform,
|
|
65
|
+
composeBefore(expPropTransform)
|
|
66
|
+
);
|
|
67
|
+
export {
|
|
68
|
+
Console2 as Console,
|
|
69
|
+
ConsoleComponent,
|
|
70
|
+
consoleTransform,
|
|
71
|
+
expPropTransform,
|
|
72
|
+
transform
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/component/index.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Console } from "@devtools-ds/console";
|
|
4
|
+
var ConsoleComponent = (props) => {
|
|
5
|
+
const { evaluate, history } = props;
|
|
6
|
+
return /* @__PURE__ */ React.createElement(Console, { execute: evaluate, history });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/dsl/index.tsx
|
|
10
|
+
import React2 from "react";
|
|
11
|
+
import {
|
|
12
|
+
Asset,
|
|
13
|
+
isTemplateStringInstance
|
|
14
|
+
} from "@player-tools/dsl";
|
|
15
|
+
var Console2 = (props) => {
|
|
16
|
+
const { exp, binding } = props;
|
|
17
|
+
let expValue;
|
|
18
|
+
if (isTemplateStringInstance(exp)) {
|
|
19
|
+
expValue = exp.toValue();
|
|
20
|
+
} else if (Array.isArray(exp)) {
|
|
21
|
+
expValue = exp.map((e) => typeof e === "string" ? e : e.toValue());
|
|
22
|
+
} else if (exp) {
|
|
23
|
+
expValue = exp;
|
|
24
|
+
}
|
|
25
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "console" }, exp && /* @__PURE__ */ React2.createElement("property", { name: "exp" }, expValue), binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/transform/index.ts
|
|
29
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
30
|
+
var transform = (asset, options) => {
|
|
31
|
+
return {
|
|
32
|
+
...asset,
|
|
33
|
+
history: asset.binding === void 0 ? void 0 : options.data.model.get(asset.binding, {
|
|
34
|
+
includeInvalid: true,
|
|
35
|
+
formatted: false
|
|
36
|
+
}),
|
|
37
|
+
evaluate() {
|
|
38
|
+
if (asset.exp) {
|
|
39
|
+
options.evaluate(asset.exp);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var expPropTransform = (asset) => {
|
|
45
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
46
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
47
|
+
return asset;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
...asset,
|
|
51
|
+
plugins: {
|
|
52
|
+
...asset.plugins,
|
|
53
|
+
stringResolver: {
|
|
54
|
+
...asset?.plugins?.stringResolver,
|
|
55
|
+
propertiesToSkip: [
|
|
56
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
57
|
+
"exp"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
var consoleTransform = compose(
|
|
64
|
+
transform,
|
|
65
|
+
composeBefore(expPropTransform)
|
|
66
|
+
);
|
|
67
|
+
export {
|
|
68
|
+
Console2 as Console,
|
|
69
|
+
ConsoleComponent,
|
|
70
|
+
consoleTransform,
|
|
71
|
+
expPropTransform,
|
|
72
|
+
transform
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/component/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/dsl/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/console/src/transform/index.ts"],"sourcesContent":["import React from \"react\";\nimport { Console } from \"@devtools-ds/console\";\nimport type { TransformedConsole } from \"../types\";\n\nexport const ConsoleComponent = (props: TransformedConsole) => {\n const { evaluate, history } = props;\n\n return <Console execute={evaluate} history={history} />;\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n isTemplateStringInstance,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { ConsoleAsset } from \"../types\";\n\n/**\n * Defines the component DSL representation for the Console asset,\n * a component that emulates a REPL environment that you see in browsers.\n */\nexport const Console = (\n props: Omit<AssetPropsWithChildren<ConsoleAsset>, \"binding\"> & {\n /** Binding as template string */\n binding: BindingTemplateInstance;\n }\n) => {\n const { exp, binding } = props;\n\n // Extracting the exp value from the props\n let expValue: ConsoleAsset[\"exp\"];\n\n if (isTemplateStringInstance(exp)) {\n expValue = exp.toValue();\n } else if (Array.isArray(exp)) {\n expValue = exp.map((e) => (typeof e === \"string\" ? e : e.toValue()));\n } else if (exp) {\n expValue = exp;\n }\n\n return (\n <Asset type=\"console\">\n {exp && <property name=\"exp\">{expValue}</property>}\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\n </Asset>\n );\n};\n","import type {\n Asset,\n BeforeTransformFunction,\n TransformFunction,\n} from \"@player-ui/player\";\nimport { compose, composeBefore } from \"@player-ui/asset-transform-plugin\";\nimport { ConsoleAsset, TransformedConsole } from \"../types\";\n\n/**\n * Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)\n * and embeds Player state and methods:\n */\nexport const transform: TransformFunction<ConsoleAsset, TransformedConsole> = (\n asset,\n options\n) => {\n return {\n ...asset,\n history:\n asset.binding === undefined\n ? undefined\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n evaluate() {\n if (asset.exp) {\n options.evaluate(asset.exp);\n }\n },\n };\n};\n\n/**\n * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist\n */\nexport const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {\n const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;\n\n if (skipArray && skipArray.indexOf(\"exp\") > 1) {\n return asset;\n }\n\n return {\n ...asset,\n plugins: {\n ...asset.plugins,\n stringResolver: {\n ...asset?.plugins?.stringResolver,\n propertiesToSkip: [\n ...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),\n \"exp\",\n ],\n },\n },\n };\n};\n\nexport const consoleTransform = compose(\n transform,\n composeBefore(expPropTransform)\n);\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,SAAS,eAAe;AAGjB,IAAM,mBAAmB,CAAC,UAA8B;AAC7D,QAAM,EAAE,UAAU,QAAQ,IAAI;AAE9B,SAAO,oCAAC,WAAQ,SAAS,UAAU,SAAkB;A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AAAA,UACxD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA,cAAc,gBAAgB;AAChC;","names":["React","Console"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtools-ui/console",
|
|
3
|
+
"version": "0.0.2--canary.11.588",
|
|
4
|
+
"main": "dist/cjs/index.cjs",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@devtools-ui/text": "0.0.2--canary.11.588",
|
|
7
|
+
"@devtools-ui/collection": "0.0.2--canary.11.588",
|
|
8
|
+
"@chakra-ui/react": "^2.8.2",
|
|
9
|
+
"@emotion/react": "^11.11.4",
|
|
10
|
+
"@emotion/styled": "^11.11.0",
|
|
11
|
+
"@player-tools/dsl": "0.5.2--canary.87.2261",
|
|
12
|
+
"@player-ui/asset-transform-plugin": "^0.7.1",
|
|
13
|
+
"@player-ui/player": "0.7.1",
|
|
14
|
+
"@player-ui/react": "^0.7.1",
|
|
15
|
+
"@player-ui/types": "0.7.1",
|
|
16
|
+
"@types/react": "^18.2.51",
|
|
17
|
+
"dlv": "^1.1.3",
|
|
18
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
19
|
+
"framer-motion": "^11.0.8",
|
|
20
|
+
"react": "^18.2.0",
|
|
21
|
+
"@devtools-ds/console": "^1.2.1",
|
|
22
|
+
"tslib": "^2.6.2"
|
|
23
|
+
},
|
|
24
|
+
"module": "dist/index.legacy-esm.js",
|
|
25
|
+
"types": "types/index.d.ts",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
"./package.json": "./package.json",
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./types/index.d.ts",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"default": "./dist/cjs/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"src",
|
|
38
|
+
"types"
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {}
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Console } from "@devtools-ds/console";
|
|
3
|
+
import type { TransformedConsole } from "../types";
|
|
4
|
+
|
|
5
|
+
export const ConsoleComponent = (props: TransformedConsole) => {
|
|
6
|
+
const { evaluate, history } = props;
|
|
7
|
+
|
|
8
|
+
return <Console execute={evaluate} history={history} />;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { render, expression as e, binding as b } from "@player-tools/dsl";
|
|
4
|
+
import { Console } from "../";
|
|
5
|
+
|
|
6
|
+
describe("DSL: Console", () => {
|
|
7
|
+
test("Renders console", async () => {
|
|
8
|
+
const rendered = await render(
|
|
9
|
+
<Console exp={e`my_expression`} binding={b`my_binding`} />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
13
|
+
id: "root",
|
|
14
|
+
type: "console",
|
|
15
|
+
exp: "my_expression",
|
|
16
|
+
binding: "my_binding",
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
AssetPropsWithChildren,
|
|
4
|
+
Asset,
|
|
5
|
+
isTemplateStringInstance,
|
|
6
|
+
BindingTemplateInstance,
|
|
7
|
+
} from "@player-tools/dsl";
|
|
8
|
+
import type { ConsoleAsset } from "../types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines the component DSL representation for the Console asset,
|
|
12
|
+
* a component that emulates a REPL environment that you see in browsers.
|
|
13
|
+
*/
|
|
14
|
+
export const Console = (
|
|
15
|
+
props: Omit<AssetPropsWithChildren<ConsoleAsset>, "binding"> & {
|
|
16
|
+
/** Binding as template string */
|
|
17
|
+
binding: BindingTemplateInstance;
|
|
18
|
+
}
|
|
19
|
+
) => {
|
|
20
|
+
const { exp, binding } = props;
|
|
21
|
+
|
|
22
|
+
// Extracting the exp value from the props
|
|
23
|
+
let expValue: ConsoleAsset["exp"];
|
|
24
|
+
|
|
25
|
+
if (isTemplateStringInstance(exp)) {
|
|
26
|
+
expValue = exp.toValue();
|
|
27
|
+
} else if (Array.isArray(exp)) {
|
|
28
|
+
expValue = exp.map((e) => (typeof e === "string" ? e : e.toValue()));
|
|
29
|
+
} else if (exp) {
|
|
30
|
+
expValue = exp;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Asset type="console">
|
|
35
|
+
{exp && <property name="exp">{expValue}</property>}
|
|
36
|
+
{binding && <property name="binding">{binding.toValue()}</property>}
|
|
37
|
+
</Asset>
|
|
38
|
+
);
|
|
39
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Asset,
|
|
3
|
+
BeforeTransformFunction,
|
|
4
|
+
TransformFunction,
|
|
5
|
+
} from "@player-ui/player";
|
|
6
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
7
|
+
import { ConsoleAsset, TransformedConsole } from "../types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)
|
|
11
|
+
* and embeds Player state and methods:
|
|
12
|
+
*/
|
|
13
|
+
export const transform: TransformFunction<ConsoleAsset, TransformedConsole> = (
|
|
14
|
+
asset,
|
|
15
|
+
options
|
|
16
|
+
) => {
|
|
17
|
+
return {
|
|
18
|
+
...asset,
|
|
19
|
+
history:
|
|
20
|
+
asset.binding === undefined
|
|
21
|
+
? undefined
|
|
22
|
+
: options.data.model.get(asset.binding, {
|
|
23
|
+
includeInvalid: true,
|
|
24
|
+
formatted: false,
|
|
25
|
+
}),
|
|
26
|
+
evaluate() {
|
|
27
|
+
if (asset.exp) {
|
|
28
|
+
options.evaluate(asset.exp);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
|
|
36
|
+
*/
|
|
37
|
+
export const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {
|
|
38
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
39
|
+
|
|
40
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
41
|
+
return asset;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...asset,
|
|
46
|
+
plugins: {
|
|
47
|
+
...asset.plugins,
|
|
48
|
+
stringResolver: {
|
|
49
|
+
...asset?.plugins?.stringResolver,
|
|
50
|
+
propertiesToSkip: [
|
|
51
|
+
...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),
|
|
52
|
+
"exp",
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const consoleTransform = compose(
|
|
60
|
+
transform,
|
|
61
|
+
composeBefore(expPropTransform)
|
|
62
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Asset, Expression } from "@player-ui/types";
|
|
2
|
+
|
|
3
|
+
export interface Evaluation {
|
|
4
|
+
/** A unique key for this expression */
|
|
5
|
+
id: string;
|
|
6
|
+
|
|
7
|
+
/** The expression itself */
|
|
8
|
+
expression: string;
|
|
9
|
+
|
|
10
|
+
/** The result for a given expression */
|
|
11
|
+
result?: unknown;
|
|
12
|
+
|
|
13
|
+
/** Whether there were any errors with the result */
|
|
14
|
+
severity?: "error" | "warning";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ConsoleAsset extends Asset<"console"> {
|
|
18
|
+
/** Evaluate expression */
|
|
19
|
+
exp?: Expression;
|
|
20
|
+
/** History binding */
|
|
21
|
+
binding?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A stateful instance of the asset */
|
|
25
|
+
export interface TransformedConsole extends ConsoleAsset {
|
|
26
|
+
/** A stateful instance of an action */
|
|
27
|
+
history: Evaluation[];
|
|
28
|
+
/** A method to evaluate the expression */
|
|
29
|
+
evaluate: () => void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AssetPropsWithChildren, BindingTemplateInstance } from "@player-tools/dsl";
|
|
3
|
+
import type { ConsoleAsset } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Defines the component DSL representation for the Console asset,
|
|
6
|
+
* a component that emulates a REPL environment that you see in browsers.
|
|
7
|
+
*/
|
|
8
|
+
export declare const Console: (props: Omit<AssetPropsWithChildren<ConsoleAsset>, "binding"> & {
|
|
9
|
+
/** Binding as template string */
|
|
10
|
+
binding: BindingTemplateInstance;
|
|
11
|
+
}) => React.JSX.Element;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Asset, BeforeTransformFunction, TransformFunction } from "@player-ui/player";
|
|
2
|
+
import { ConsoleAsset, TransformedConsole } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)
|
|
5
|
+
* and embeds Player state and methods:
|
|
6
|
+
*/
|
|
7
|
+
export declare const transform: TransformFunction<ConsoleAsset, TransformedConsole>;
|
|
8
|
+
/**
|
|
9
|
+
* Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
|
|
10
|
+
*/
|
|
11
|
+
export declare const expPropTransform: BeforeTransformFunction<Asset>;
|
|
12
|
+
export declare const consoleTransform: import("@player-ui/player").TransformFunctions;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Asset, Expression } from "@player-ui/types";
|
|
2
|
+
export interface Evaluation {
|
|
3
|
+
/** A unique key for this expression */
|
|
4
|
+
id: string;
|
|
5
|
+
/** The expression itself */
|
|
6
|
+
expression: string;
|
|
7
|
+
/** The result for a given expression */
|
|
8
|
+
result?: unknown;
|
|
9
|
+
/** Whether there were any errors with the result */
|
|
10
|
+
severity?: "error" | "warning";
|
|
11
|
+
}
|
|
12
|
+
export interface ConsoleAsset extends Asset<"console"> {
|
|
13
|
+
/** Evaluate expression */
|
|
14
|
+
exp?: Expression;
|
|
15
|
+
/** History binding */
|
|
16
|
+
binding?: string;
|
|
17
|
+
}
|
|
18
|
+
/** A stateful instance of the asset */
|
|
19
|
+
export interface TransformedConsole extends ConsoleAsset {
|
|
20
|
+
/** A stateful instance of an action */
|
|
21
|
+
history: Evaluation[];
|
|
22
|
+
/** A method to evaluate the expression */
|
|
23
|
+
evaluate: () => void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|