@devtools-ui/code-editor 0.1.0--canary.17.811
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 +124 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +85 -0
- package/dist/index.mjs +85 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
- package/src/component/index.tsx +24 -0
- package/src/dsl/__tests__/index.test.tsx +19 -0
- package/src/dsl/index.tsx +33 -0
- package/src/index.ts +4 -0
- package/src/transform/index.ts +72 -0
- package/src/types/index.ts +16 -0
- package/types/component/index.d.ts +4 -0
- package/types/dsl/index.d.ts +14 -0
- package/types/index.d.ts +5 -0
- package/types/transform/index.d.ts +13 -0
- package/types/types/index.d.ts +15 -0
|
@@ -0,0 +1,124 @@
|
|
|
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/code-editor/src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
CodeEditor: () => CodeEditor,
|
|
34
|
+
CodeEditorComponent: () => CodeEditorComponent,
|
|
35
|
+
codeEditorTransform: () => codeEditorTransform,
|
|
36
|
+
expPropTransform: () => expPropTransform,
|
|
37
|
+
transform: () => transform
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
|
|
41
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/component/index.tsx
|
|
42
|
+
var import_react = __toESM(require("react"));
|
|
43
|
+
var import_react2 = __toESM(require("@monaco-editor/react"));
|
|
44
|
+
var import_react3 = require("@chakra-ui/react");
|
|
45
|
+
var CodeEditorComponent = (props) => {
|
|
46
|
+
const { code, run } = props;
|
|
47
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react3.Flex, { h: "50vh" }, /* @__PURE__ */ import_react.default.createElement(
|
|
48
|
+
import_react2.default,
|
|
49
|
+
{
|
|
50
|
+
theme: "vs-dark",
|
|
51
|
+
value: code,
|
|
52
|
+
language: "json",
|
|
53
|
+
options: {
|
|
54
|
+
formatOnPaste: true
|
|
55
|
+
},
|
|
56
|
+
onChange: (val) => {
|
|
57
|
+
run(val);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/dsl/index.tsx
|
|
64
|
+
var import_react4 = __toESM(require("react"));
|
|
65
|
+
var import_dsl = require("@player-tools/dsl");
|
|
66
|
+
var CodeEditor = (props) => {
|
|
67
|
+
const { exp, binding, ...rest } = props;
|
|
68
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_dsl.Asset, { type: "code-editor", ...rest }, /* @__PURE__ */ import_react4.default.createElement("property", { name: "binding" }, binding.toValue()), /* @__PURE__ */ import_react4.default.createElement("property", { name: "exp" }, exp.toValue()));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/transform/index.ts
|
|
72
|
+
var import_asset_transform_plugin = require("@player-ui/asset-transform-plugin");
|
|
73
|
+
var transform = (asset, options) => {
|
|
74
|
+
return {
|
|
75
|
+
...asset,
|
|
76
|
+
code: asset.binding === void 0 ? "" : JSON.stringify(
|
|
77
|
+
options.data.model.get(asset.binding, {
|
|
78
|
+
includeInvalid: true,
|
|
79
|
+
formatted: false
|
|
80
|
+
}),
|
|
81
|
+
null,
|
|
82
|
+
2
|
|
83
|
+
),
|
|
84
|
+
run(code) {
|
|
85
|
+
if (asset.exp) {
|
|
86
|
+
const referencedExpression = asset.exp.match(/{{\s*(.*?)\s*}}/);
|
|
87
|
+
referencedExpression && options.data.model.set([[referencedExpression[1], code]]);
|
|
88
|
+
options.evaluate(asset.exp);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
var expPropTransform = (asset) => {
|
|
94
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
95
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
96
|
+
return asset;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...asset,
|
|
100
|
+
plugins: {
|
|
101
|
+
...asset.plugins,
|
|
102
|
+
stringResolver: {
|
|
103
|
+
...asset?.plugins?.stringResolver,
|
|
104
|
+
propertiesToSkip: [
|
|
105
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
106
|
+
"exp"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
var codeEditorTransform = (0, import_asset_transform_plugin.compose)(
|
|
113
|
+
transform,
|
|
114
|
+
(0, import_asset_transform_plugin.composeBefore)(expPropTransform)
|
|
115
|
+
);
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
CodeEditor,
|
|
119
|
+
CodeEditorComponent,
|
|
120
|
+
codeEditorTransform,
|
|
121
|
+
expPropTransform,
|
|
122
|
+
transform
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/component/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/dsl/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./component\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import React from \"react\";\nimport Editor from \"@monaco-editor/react\";\nimport type { TransformedCodeEditor } from \"../types\";\nimport { Flex } from \"@chakra-ui/react\";\n\nexport const CodeEditorComponent = (props: TransformedCodeEditor) => {\n const { code, run } = props;\n\n return (\n <Flex h=\"50vh\">\n <Editor\n theme=\"vs-dark\"\n value={code}\n language=\"json\"\n options={{\n formatOnPaste: true,\n }}\n onChange={(val) => {\n run(val);\n }}\n />\n </Flex>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { CodeEditorAsset } from \"../types\";\n\n/**\n * Defines the component DSL representation, so users of this plugin can author Player-UI\n * content leveraging .jsx/.tsx syntax.\n */\nexport const CodeEditor = (\n props: Omit<\n AssetPropsWithChildren<CodeEditorAsset>,\n \"binding\" | \"expression\"\n > & {\n /** The binding */\n binding: BindingTemplateInstance;\n /** Expression as template string */\n exp: ExpressionTemplateInstance;\n }\n) => {\n const { exp, binding, ...rest } = props;\n\n return (\n <Asset type=\"code-editor\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n <property name=\"exp\">{exp.toValue()}</property>\n </Asset>\n );\n};\n","import type {\n Asset,\n BeforeTransformFunction,\n TransformFunction,\n} from \"@player-ui/player\";\nimport type { CodeEditorAsset, TransformedCodeEditor } from \"../types\";\nimport { compose, composeBefore } from \"@player-ui/asset-transform-plugin\";\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<\n CodeEditorAsset,\n TransformedCodeEditor\n> = (asset, options) => {\n return {\n ...asset,\n code:\n asset.binding === undefined\n ? \"\"\n : JSON.stringify(\n options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n null,\n 2\n ),\n run(code?: string) {\n if (asset.exp) {\n // get the referenced expression property holder from the expression\n const referencedExpression = asset.exp.match(/{{\\s*(.*?)\\s*}}/);\n // set the referenced expression property to the new expression\n // so it is available to the asset.exp\n referencedExpression &&\n options.data.model.set([[referencedExpression[1], code]]);\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 codeEditorTransform = compose(\n transform,\n composeBefore(expPropTransform)\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAClB,IAAAA,gBAAmB;AAEnB,IAAAA,gBAAqB;AAEd,IAAM,sBAAsB,CAAC,UAAiC;AACnE,QAAM,EAAE,MAAM,IAAI,IAAI;AAEtB,SACE,6BAAAC,QAAA,cAAC,sBAAK,GAAE,UACN,6BAAAA,QAAA;AAAA,IAAC,cAAAC;AAAA,IAAA;AAAA,MACC,OAAM;AAAA,MACN,OAAO;AAAA,MACP,UAAS;AAAA,MACT,SAAS;AAAA,QACP,eAAe;AAAA,MACjB;AAAA,MACA,UAAU,CAAC,QAAQ;AACjB,YAAI,GAAG;AAAA,MACT;AAAA;AAAA,EACF,CACF;AAEJ;;;ACvBA,IAAAC,gBAAkB;AAClB,iBAKO;AAOA,IAAM,aAAa,CACxB,UASG;AACH,QAAM,EAAE,KAAK,SAAS,GAAG,KAAK,IAAI;AAElC,SACE,8BAAAC,QAAA,cAAC,oBAAM,MAAK,eAAe,GAAG,QAC5B,8BAAAA,QAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GAC5C,8BAAAA,QAAA,cAAC,cAAS,MAAK,SAAO,IAAI,QAAQ,CAAE,CACtC;AAEJ;;;AC1BA,oCAAuC;AAMhC,IAAM,YAGT,CAAC,OAAO,YAAY;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MACE,MAAM,YAAY,SACd,KACA,KAAK;AAAA,MACH,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,QACpC,gBAAgB;AAAA,QAChB,WAAW;AAAA,MACb,CAAC;AAAA,MACD;AAAA,MACA;AAAA,IACF;AAAA,IACN,IAAI,MAAe;AACjB,UAAI,MAAM,KAAK;AAEb,cAAM,uBAAuB,MAAM,IAAI,MAAM,iBAAiB;AAG9D,gCACE,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,CAAC;AAC1D,gBAAQ,SAAS,MAAM,GAAG;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;AAKO,IAAM,mBAAmD,CAAC,UAAU;AACzE,QAAM,YAAY,MAAM,SAAS,gBAAgB;AAEjD,MAAI,aAAa,UAAU,QAAQ,KAAK,IAAI,GAAG;AAC7C,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,MAAM;AAAA,MACT,gBAAgB;AAAA,QACd,GAAG,OAAO,SAAS;AAAA,QACnB,kBAAkB;AAAA,UAChB,GAAI,MAAM,SAAS,gBAAgB,oBAAoB,CAAC;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,0BAAsB;AAAA,EACjC;AAAA,MACA,6CAAc,gBAAgB;AAChC;","names":["import_react","React","Editor","import_react","React"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/component/index.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import Editor from "@monaco-editor/react";
|
|
4
|
+
import { Flex } from "@chakra-ui/react";
|
|
5
|
+
var CodeEditorComponent = (props) => {
|
|
6
|
+
const { code, run } = props;
|
|
7
|
+
return /* @__PURE__ */ React.createElement(Flex, { h: "50vh" }, /* @__PURE__ */ React.createElement(
|
|
8
|
+
Editor,
|
|
9
|
+
{
|
|
10
|
+
theme: "vs-dark",
|
|
11
|
+
value: code,
|
|
12
|
+
language: "json",
|
|
13
|
+
options: {
|
|
14
|
+
formatOnPaste: true
|
|
15
|
+
},
|
|
16
|
+
onChange: (val) => {
|
|
17
|
+
run(val);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/dsl/index.tsx
|
|
24
|
+
import React2 from "react";
|
|
25
|
+
import {
|
|
26
|
+
Asset
|
|
27
|
+
} from "@player-tools/dsl";
|
|
28
|
+
var CodeEditor = (props) => {
|
|
29
|
+
const { exp, binding, ...rest } = props;
|
|
30
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "code-editor", ...rest }, /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), /* @__PURE__ */ React2.createElement("property", { name: "exp" }, exp.toValue()));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/transform/index.ts
|
|
34
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
35
|
+
var transform = (asset, options) => {
|
|
36
|
+
return {
|
|
37
|
+
...asset,
|
|
38
|
+
code: asset.binding === void 0 ? "" : JSON.stringify(
|
|
39
|
+
options.data.model.get(asset.binding, {
|
|
40
|
+
includeInvalid: true,
|
|
41
|
+
formatted: false
|
|
42
|
+
}),
|
|
43
|
+
null,
|
|
44
|
+
2
|
|
45
|
+
),
|
|
46
|
+
run(code) {
|
|
47
|
+
if (asset.exp) {
|
|
48
|
+
const referencedExpression = asset.exp.match(/{{\s*(.*?)\s*}}/);
|
|
49
|
+
referencedExpression && options.data.model.set([[referencedExpression[1], code]]);
|
|
50
|
+
options.evaluate(asset.exp);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
var expPropTransform = (asset) => {
|
|
56
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
57
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
58
|
+
return asset;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...asset,
|
|
62
|
+
plugins: {
|
|
63
|
+
...asset.plugins,
|
|
64
|
+
stringResolver: {
|
|
65
|
+
...asset?.plugins?.stringResolver,
|
|
66
|
+
propertiesToSkip: [
|
|
67
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
68
|
+
"exp"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var codeEditorTransform = compose(
|
|
75
|
+
transform,
|
|
76
|
+
composeBefore(expPropTransform)
|
|
77
|
+
);
|
|
78
|
+
export {
|
|
79
|
+
CodeEditor,
|
|
80
|
+
CodeEditorComponent,
|
|
81
|
+
codeEditorTransform,
|
|
82
|
+
expPropTransform,
|
|
83
|
+
transform
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/component/index.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import Editor from "@monaco-editor/react";
|
|
4
|
+
import { Flex } from "@chakra-ui/react";
|
|
5
|
+
var CodeEditorComponent = (props) => {
|
|
6
|
+
const { code, run } = props;
|
|
7
|
+
return /* @__PURE__ */ React.createElement(Flex, { h: "50vh" }, /* @__PURE__ */ React.createElement(
|
|
8
|
+
Editor,
|
|
9
|
+
{
|
|
10
|
+
theme: "vs-dark",
|
|
11
|
+
value: code,
|
|
12
|
+
language: "json",
|
|
13
|
+
options: {
|
|
14
|
+
formatOnPaste: true
|
|
15
|
+
},
|
|
16
|
+
onChange: (val) => {
|
|
17
|
+
run(val);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/dsl/index.tsx
|
|
24
|
+
import React2 from "react";
|
|
25
|
+
import {
|
|
26
|
+
Asset
|
|
27
|
+
} from "@player-tools/dsl";
|
|
28
|
+
var CodeEditor = (props) => {
|
|
29
|
+
const { exp, binding, ...rest } = props;
|
|
30
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "code-editor", ...rest }, /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), /* @__PURE__ */ React2.createElement("property", { name: "exp" }, exp.toValue()));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/transform/index.ts
|
|
34
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
35
|
+
var transform = (asset, options) => {
|
|
36
|
+
return {
|
|
37
|
+
...asset,
|
|
38
|
+
code: asset.binding === void 0 ? "" : JSON.stringify(
|
|
39
|
+
options.data.model.get(asset.binding, {
|
|
40
|
+
includeInvalid: true,
|
|
41
|
+
formatted: false
|
|
42
|
+
}),
|
|
43
|
+
null,
|
|
44
|
+
2
|
|
45
|
+
),
|
|
46
|
+
run(code) {
|
|
47
|
+
if (asset.exp) {
|
|
48
|
+
const referencedExpression = asset.exp.match(/{{\s*(.*?)\s*}}/);
|
|
49
|
+
referencedExpression && options.data.model.set([[referencedExpression[1], code]]);
|
|
50
|
+
options.evaluate(asset.exp);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
var expPropTransform = (asset) => {
|
|
56
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
57
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
58
|
+
return asset;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
...asset,
|
|
62
|
+
plugins: {
|
|
63
|
+
...asset.plugins,
|
|
64
|
+
stringResolver: {
|
|
65
|
+
...asset?.plugins?.stringResolver,
|
|
66
|
+
propertiesToSkip: [
|
|
67
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
68
|
+
"exp"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var codeEditorTransform = compose(
|
|
75
|
+
transform,
|
|
76
|
+
composeBefore(expPropTransform)
|
|
77
|
+
);
|
|
78
|
+
export {
|
|
79
|
+
CodeEditor,
|
|
80
|
+
CodeEditorComponent,
|
|
81
|
+
codeEditorTransform,
|
|
82
|
+
expPropTransform,
|
|
83
|
+
transform
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/component/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/dsl/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/code-editor/src/transform/index.ts"],"sourcesContent":["import React from \"react\";\nimport Editor from \"@monaco-editor/react\";\nimport type { TransformedCodeEditor } from \"../types\";\nimport { Flex } from \"@chakra-ui/react\";\n\nexport const CodeEditorComponent = (props: TransformedCodeEditor) => {\n const { code, run } = props;\n\n return (\n <Flex h=\"50vh\">\n <Editor\n theme=\"vs-dark\"\n value={code}\n language=\"json\"\n options={{\n formatOnPaste: true,\n }}\n onChange={(val) => {\n run(val);\n }}\n />\n </Flex>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { CodeEditorAsset } from \"../types\";\n\n/**\n * Defines the component DSL representation, so users of this plugin can author Player-UI\n * content leveraging .jsx/.tsx syntax.\n */\nexport const CodeEditor = (\n props: Omit<\n AssetPropsWithChildren<CodeEditorAsset>,\n \"binding\" | \"expression\"\n > & {\n /** The binding */\n binding: BindingTemplateInstance;\n /** Expression as template string */\n exp: ExpressionTemplateInstance;\n }\n) => {\n const { exp, binding, ...rest } = props;\n\n return (\n <Asset type=\"code-editor\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n <property name=\"exp\">{exp.toValue()}</property>\n </Asset>\n );\n};\n","import type {\n Asset,\n BeforeTransformFunction,\n TransformFunction,\n} from \"@player-ui/player\";\nimport type { CodeEditorAsset, TransformedCodeEditor } from \"../types\";\nimport { compose, composeBefore } from \"@player-ui/asset-transform-plugin\";\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<\n CodeEditorAsset,\n TransformedCodeEditor\n> = (asset, options) => {\n return {\n ...asset,\n code:\n asset.binding === undefined\n ? \"\"\n : JSON.stringify(\n options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n null,\n 2\n ),\n run(code?: string) {\n if (asset.exp) {\n // get the referenced expression property holder from the expression\n const referencedExpression = asset.exp.match(/{{\\s*(.*?)\\s*}}/);\n // set the referenced expression property to the new expression\n // so it is available to the asset.exp\n referencedExpression &&\n options.data.model.set([[referencedExpression[1], code]]);\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 codeEditorTransform = compose(\n transform,\n composeBefore(expPropTransform)\n);\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,OAAO,YAAY;AAEnB,SAAS,YAAY;AAEd,IAAM,sBAAsB,CAAC,UAAiC;AACnE,QAAM,EAAE,MAAM,IAAI,IAAI;AAEtB,SACE,oCAAC,QAAK,GAAE,UACN;AAAA,IAAC;AAAA;AAAA,MACC,OAAM;AAAA,MACN,OAAO;AAAA,MACP,UAAS;AAAA,MACT,SAAS;AAAA,QACP,eAAe;AAAA,MACjB;AAAA,MACA,UAAU,CAAC,QAAQ;AACjB,YAAI,GAAG;AAAA,MACT;AAAA;AAAA,EACF,CACF;AAEJ;;;ACvBA,OAAOA,YAAW;AAClB;AAAA,EAEE;AAAA,OAGK;AAOA,IAAM,aAAa,CACxB,UASG;AACH,QAAM,EAAE,KAAK,SAAS,GAAG,KAAK,IAAI;AAElC,SACE,gBAAAA,OAAA,cAAC,SAAM,MAAK,eAAe,GAAG,QAC5B,gBAAAA,OAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GAC5C,gBAAAA,OAAA,cAAC,cAAS,MAAK,SAAO,IAAI,QAAQ,CAAE,CACtC;AAEJ;;;AC1BA,SAAS,SAAS,qBAAqB;AAMhC,IAAM,YAGT,CAAC,OAAO,YAAY;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MACE,MAAM,YAAY,SACd,KACA,KAAK;AAAA,MACH,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,QACpC,gBAAgB;AAAA,QAChB,WAAW;AAAA,MACb,CAAC;AAAA,MACD;AAAA,MACA;AAAA,IACF;AAAA,IACN,IAAI,MAAe;AACjB,UAAI,MAAM,KAAK;AAEb,cAAM,uBAAuB,MAAM,IAAI,MAAM,iBAAiB;AAG9D,gCACE,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,CAAC;AAC1D,gBAAQ,SAAS,MAAM,GAAG;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;AAKO,IAAM,mBAAmD,CAAC,UAAU;AACzE,QAAM,YAAY,MAAM,SAAS,gBAAgB;AAEjD,MAAI,aAAa,UAAU,QAAQ,KAAK,IAAI,GAAG;AAC7C,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,SAAS;AAAA,MACP,GAAG,MAAM;AAAA,MACT,gBAAgB;AAAA,QACd,GAAG,OAAO,SAAS;AAAA,QACnB,kBAAkB;AAAA,UAChB,GAAI,MAAM,SAAS,gBAAgB,oBAAoB,CAAC;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA,cAAc,gBAAgB;AAChC;","names":["React"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtools-ui/code-editor",
|
|
3
|
+
"version": "0.1.0--canary.17.811",
|
|
4
|
+
"main": "dist/cjs/index.cjs",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@devtools-ui/text": "0.1.0--canary.17.811",
|
|
7
|
+
"@devtools-ui/collection": "0.1.0--canary.17.811",
|
|
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.2-next.4",
|
|
13
|
+
"@player-ui/player": "0.7.2-next.4",
|
|
14
|
+
"@player-ui/react": "0.7.2-next.4",
|
|
15
|
+
"@player-ui/types": "0.7.2-next.4",
|
|
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
|
+
"@monaco-editor/react": "^4.6.0",
|
|
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
|
+
"./dist/index.css": "./dist/index.css",
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./types/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs",
|
|
33
|
+
"default": "./dist/cjs/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"src",
|
|
39
|
+
"types"
|
|
40
|
+
],
|
|
41
|
+
"peerDependencies": {}
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Editor from "@monaco-editor/react";
|
|
3
|
+
import type { TransformedCodeEditor } from "../types";
|
|
4
|
+
import { Flex } from "@chakra-ui/react";
|
|
5
|
+
|
|
6
|
+
export const CodeEditorComponent = (props: TransformedCodeEditor) => {
|
|
7
|
+
const { code, run } = props;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Flex h="50vh">
|
|
11
|
+
<Editor
|
|
12
|
+
theme="vs-dark"
|
|
13
|
+
value={code}
|
|
14
|
+
language="json"
|
|
15
|
+
options={{
|
|
16
|
+
formatOnPaste: true,
|
|
17
|
+
}}
|
|
18
|
+
onChange={(val) => {
|
|
19
|
+
run(val);
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
</Flex>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -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 { CodeEditor } from "../";
|
|
5
|
+
|
|
6
|
+
describe("DSL: CodeEditor", () => {
|
|
7
|
+
test("Renders code-editor", async () => {
|
|
8
|
+
const rendered = await render(
|
|
9
|
+
<CodeEditor exp={e`my_expression`} binding={b`my_binding`} />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
13
|
+
id: "root",
|
|
14
|
+
type: "code-editor",
|
|
15
|
+
exp: "my_expression",
|
|
16
|
+
binding: "my_binding",
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
AssetPropsWithChildren,
|
|
4
|
+
Asset,
|
|
5
|
+
BindingTemplateInstance,
|
|
6
|
+
ExpressionTemplateInstance,
|
|
7
|
+
} from "@player-tools/dsl";
|
|
8
|
+
import type { CodeEditorAsset } from "../types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines the component DSL representation, so users of this plugin can author Player-UI
|
|
12
|
+
* content leveraging .jsx/.tsx syntax.
|
|
13
|
+
*/
|
|
14
|
+
export const CodeEditor = (
|
|
15
|
+
props: Omit<
|
|
16
|
+
AssetPropsWithChildren<CodeEditorAsset>,
|
|
17
|
+
"binding" | "expression"
|
|
18
|
+
> & {
|
|
19
|
+
/** The binding */
|
|
20
|
+
binding: BindingTemplateInstance;
|
|
21
|
+
/** Expression as template string */
|
|
22
|
+
exp: ExpressionTemplateInstance;
|
|
23
|
+
}
|
|
24
|
+
) => {
|
|
25
|
+
const { exp, binding, ...rest } = props;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Asset type="code-editor" {...rest}>
|
|
29
|
+
<property name="binding">{binding.toValue()}</property>
|
|
30
|
+
<property name="exp">{exp.toValue()}</property>
|
|
31
|
+
</Asset>
|
|
32
|
+
);
|
|
33
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Asset,
|
|
3
|
+
BeforeTransformFunction,
|
|
4
|
+
TransformFunction,
|
|
5
|
+
} from "@player-ui/player";
|
|
6
|
+
import type { CodeEditorAsset, TransformedCodeEditor } from "../types";
|
|
7
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
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<
|
|
14
|
+
CodeEditorAsset,
|
|
15
|
+
TransformedCodeEditor
|
|
16
|
+
> = (asset, options) => {
|
|
17
|
+
return {
|
|
18
|
+
...asset,
|
|
19
|
+
code:
|
|
20
|
+
asset.binding === undefined
|
|
21
|
+
? ""
|
|
22
|
+
: JSON.stringify(
|
|
23
|
+
options.data.model.get(asset.binding, {
|
|
24
|
+
includeInvalid: true,
|
|
25
|
+
formatted: false,
|
|
26
|
+
}),
|
|
27
|
+
null,
|
|
28
|
+
2
|
|
29
|
+
),
|
|
30
|
+
run(code?: string) {
|
|
31
|
+
if (asset.exp) {
|
|
32
|
+
// get the referenced expression property holder from the expression
|
|
33
|
+
const referencedExpression = asset.exp.match(/{{\s*(.*?)\s*}}/);
|
|
34
|
+
// set the referenced expression property to the new expression
|
|
35
|
+
// so it is available to the asset.exp
|
|
36
|
+
referencedExpression &&
|
|
37
|
+
options.data.model.set([[referencedExpression[1], code]]);
|
|
38
|
+
options.evaluate(asset.exp);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
|
|
46
|
+
*/
|
|
47
|
+
export const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {
|
|
48
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
49
|
+
|
|
50
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
51
|
+
return asset;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...asset,
|
|
56
|
+
plugins: {
|
|
57
|
+
...asset.plugins,
|
|
58
|
+
stringResolver: {
|
|
59
|
+
...asset?.plugins?.stringResolver,
|
|
60
|
+
propertiesToSkip: [
|
|
61
|
+
...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),
|
|
62
|
+
"exp",
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const codeEditorTransform = compose(
|
|
70
|
+
transform,
|
|
71
|
+
composeBefore(expPropTransform)
|
|
72
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Asset } from "@player-ui/types";
|
|
2
|
+
|
|
3
|
+
export interface CodeEditorAsset extends Asset<"code-editor"> {
|
|
4
|
+
/** binding pointing to the JSON object to edit */
|
|
5
|
+
binding?: string;
|
|
6
|
+
/** An expression to execute on the code change */
|
|
7
|
+
exp?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** A stateful instance of the asset */
|
|
11
|
+
export interface TransformedCodeEditor extends CodeEditorAsset {
|
|
12
|
+
/** The JSON object to edit as string */
|
|
13
|
+
code: string;
|
|
14
|
+
/** Transformed expression to execute on the code change */
|
|
15
|
+
run: (code: string | undefined) => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AssetPropsWithChildren, BindingTemplateInstance, ExpressionTemplateInstance } from "@player-tools/dsl";
|
|
3
|
+
import type { CodeEditorAsset } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Defines the component DSL representation, so users of this plugin can author Player-UI
|
|
6
|
+
* content leveraging .jsx/.tsx syntax.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CodeEditor: (props: Omit<AssetPropsWithChildren<CodeEditorAsset>, "binding" | "expression"> & {
|
|
9
|
+
/** The binding */
|
|
10
|
+
binding: BindingTemplateInstance;
|
|
11
|
+
/** Expression as template string */
|
|
12
|
+
exp: ExpressionTemplateInstance;
|
|
13
|
+
}) => React.JSX.Element;
|
|
14
|
+
//# 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 type { CodeEditorAsset, TransformedCodeEditor } 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<CodeEditorAsset, TransformedCodeEditor>;
|
|
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 codeEditorTransform: import("@player-ui/player").TransformFunctions;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Asset } from "@player-ui/types";
|
|
2
|
+
export interface CodeEditorAsset extends Asset<"code-editor"> {
|
|
3
|
+
/** binding pointing to the JSON object to edit */
|
|
4
|
+
binding?: string;
|
|
5
|
+
/** An expression to execute on the code change */
|
|
6
|
+
exp?: string;
|
|
7
|
+
}
|
|
8
|
+
/** A stateful instance of the asset */
|
|
9
|
+
export interface TransformedCodeEditor extends CodeEditorAsset {
|
|
10
|
+
/** The JSON object to edit as string */
|
|
11
|
+
code: string;
|
|
12
|
+
/** Transformed expression to execute on the code change */
|
|
13
|
+
run: (code: string | undefined) => void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|