@devtools-ui/action 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 +141 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +105 -0
- package/dist/index.mjs +105 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +40 -0
- package/src/components/ActionComponent.tsx +27 -0
- package/src/components/index.ts +1 -0
- package/src/dsl/Action.tsx +55 -0
- package/src/dsl/__tests__/Action.test.tsx +153 -0
- package/src/dsl/index.ts +1 -0
- package/src/index.ts +4 -0
- package/src/transform/index.ts +61 -0
- package/src/types/index.ts +39 -0
- package/types/components/ActionComponent.d.ts +4 -0
- package/types/components/index.d.ts +2 -0
- package/types/dsl/Action.d.ts +13 -0
- package/types/dsl/index.d.ts +2 -0
- package/types/index.d.ts +5 -0
- package/types/transform/index.d.ts +9 -0
- package/types/types/index.d.ts +30 -0
|
@@ -0,0 +1,141 @@
|
|
|
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/action/src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Action: () => Action,
|
|
34
|
+
ActionComponent: () => ActionComponent,
|
|
35
|
+
actionTransform: () => actionTransform,
|
|
36
|
+
expPropTransform: () => expPropTransform
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
|
|
40
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/components/ActionComponent.tsx
|
|
41
|
+
var import_react = __toESM(require("react"));
|
|
42
|
+
var import_react2 = require("@chakra-ui/react");
|
|
43
|
+
var import_react3 = require("@player-ui/react");
|
|
44
|
+
var useActionPros = (props) => {
|
|
45
|
+
return {
|
|
46
|
+
...props.label ? { children: /* @__PURE__ */ import_react.default.createElement(import_react3.ReactAsset, { ...props.label.asset }) } : {},
|
|
47
|
+
...props.icon ? {
|
|
48
|
+
[props.metaData?.iconPosition === "left" ? "leftIcon" : "rightIcon"]: /* @__PURE__ */ import_react.default.createElement(import_react3.ReactAsset, { ...props.icon.asset })
|
|
49
|
+
} : {},
|
|
50
|
+
...props.run ? { onClick: props.run } : {},
|
|
51
|
+
...props.metaData?.variant ? { variant: props.metaData.variant } : {},
|
|
52
|
+
...props.metaData?.isLoading ? { isLoading: props.metaData.isLoading } : {}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
var ActionComponent = (props) => {
|
|
56
|
+
const { children, ...buttonProps } = useActionPros(props);
|
|
57
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react2.Button, { ...buttonProps }, children);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/dsl/Action.tsx
|
|
61
|
+
var import_react4 = __toESM(require("react"));
|
|
62
|
+
var import_dsl = require("@player-tools/dsl");
|
|
63
|
+
var import_collection = require("@devtools-ui/collection");
|
|
64
|
+
var import_text = require("@devtools-ui/text");
|
|
65
|
+
var Action = (props) => {
|
|
66
|
+
const { exp, children, ...rest } = props;
|
|
67
|
+
let expValue;
|
|
68
|
+
if ((0, import_dsl.isTemplateStringInstance)(exp)) {
|
|
69
|
+
expValue = exp.toValue();
|
|
70
|
+
} else if (Array.isArray(exp)) {
|
|
71
|
+
expValue = exp.map((e) => typeof e === "string" ? e : e.toValue());
|
|
72
|
+
} else if (exp) {
|
|
73
|
+
expValue = exp;
|
|
74
|
+
}
|
|
75
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_dsl.Asset, { type: "action", ...rest, ...expValue && { exp: expValue } }, children);
|
|
76
|
+
};
|
|
77
|
+
var CollectionComp = (props) => {
|
|
78
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_collection.Collection, null, /* @__PURE__ */ import_react4.default.createElement(import_collection.Collection.Values, null, props.children));
|
|
79
|
+
};
|
|
80
|
+
Action.Label = (0, import_dsl.createSlot)({
|
|
81
|
+
name: "label",
|
|
82
|
+
TextComp: import_text.Text,
|
|
83
|
+
CollectionComp,
|
|
84
|
+
isArray: false,
|
|
85
|
+
wrapInAsset: true
|
|
86
|
+
});
|
|
87
|
+
Action.Icon = (0, import_dsl.createSlot)({
|
|
88
|
+
name: "icon",
|
|
89
|
+
TextComp: import_text.Text,
|
|
90
|
+
CollectionComp,
|
|
91
|
+
isArray: false,
|
|
92
|
+
wrapInAsset: true
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/transform/index.ts
|
|
96
|
+
var import_asset_transform_plugin = require("@player-ui/asset-transform-plugin");
|
|
97
|
+
var transform = (action, options) => {
|
|
98
|
+
return {
|
|
99
|
+
...action,
|
|
100
|
+
run() {
|
|
101
|
+
if (action.exp) {
|
|
102
|
+
options.evaluate(action.exp);
|
|
103
|
+
}
|
|
104
|
+
if (action.value) {
|
|
105
|
+
const skipValidation = action.metaData?.skipValidation;
|
|
106
|
+
options.transition?.(action.value, { force: skipValidation });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
var expPropTransform = (asset) => {
|
|
112
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
113
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
114
|
+
return asset;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
...asset,
|
|
118
|
+
plugins: {
|
|
119
|
+
...asset.plugins,
|
|
120
|
+
stringResolver: {
|
|
121
|
+
...asset?.plugins?.stringResolver,
|
|
122
|
+
propertiesToSkip: [
|
|
123
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
124
|
+
"exp"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
var actionTransform = (0, import_asset_transform_plugin.compose)(
|
|
131
|
+
transform,
|
|
132
|
+
(0, import_asset_transform_plugin.composeBefore)(expPropTransform)
|
|
133
|
+
);
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
Action,
|
|
137
|
+
ActionComponent,
|
|
138
|
+
actionTransform,
|
|
139
|
+
expPropTransform
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/components/ActionComponent.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/dsl/Action.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./components\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import React from \"react\";\nimport { Button } from \"@chakra-ui/react\";\nimport type { TransformedAction } from \"../types\";\nimport { ReactAsset } from \"@player-ui/react\";\n\nconst useActionPros = (props: TransformedAction) => {\n return {\n ...(props.label ? { children: <ReactAsset {...props.label.asset} /> } : {}),\n ...(props.icon\n ? {\n [props.metaData?.iconPosition === \"left\" ? \"leftIcon\" : \"rightIcon\"]:\n <ReactAsset {...props.icon.asset} />,\n }\n : {}),\n ...(props.run ? { onClick: props.run } : {}),\n ...(props.metaData?.variant ? { variant: props.metaData.variant } : {}),\n ...(props.metaData?.isLoading\n ? { isLoading: props.metaData.isLoading }\n : {}),\n } as const;\n};\n\nexport const ActionComponent = (props: TransformedAction) => {\n const { children, ...buttonProps } = useActionPros(props);\n\n return <Button {...buttonProps}>{children}</Button>;\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n isTemplateStringInstance,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport type { ActionAsset } from \"../types\";\nimport { Collection } from \"@devtools-ui/collection\";\nimport { Text } from \"@devtools-ui/text\";\n\nexport const Action = (props: AssetPropsWithChildren<ActionAsset>) => {\n const { exp, children, ...rest } = props;\n\n let expValue: ActionAsset[\"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=\"action\" {...rest} {...(expValue && { exp: expValue })}>\n {children}\n </Asset>\n );\n};\n\nconst CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {\n return (\n <Collection>\n <Collection.Values>{props.children}</Collection.Values>\n </Collection>\n );\n};\n\nAction.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\n});\n\nAction.Icon = createSlot({\n name: \"icon\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\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 { ActionAsset, TransformedAction } from \"../types\";\n\n/**\n * Attaches the methods to execute an action\n */\nconst transform: TransformFunction<ActionAsset, TransformedAction> = (\n action,\n options\n) => {\n return {\n ...action,\n run() {\n if (action.exp) {\n options.evaluate(action.exp);\n }\n\n if (action.value) {\n const skipValidation = action.metaData?.skipValidation;\n options.transition?.(action.value, { force: skipValidation });\n }\n },\n };\n};\n\n/**\n * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist\n *\n * @param asset - Asset to apply the transform to\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 actionTransform = compose(\n transform,\n composeBefore(expPropTransform)\n);\n"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AAM,sBAAkB;AAAA,EAC7B;AAAA,MACA,6CAAc,gBAAgB;AAChC;","names":["import_react","React","import_react","React"]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/components/ActionComponent.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Button } from "@chakra-ui/react";
|
|
4
|
+
import { ReactAsset } from "@player-ui/react";
|
|
5
|
+
var useActionPros = (props) => {
|
|
6
|
+
return {
|
|
7
|
+
...props.label ? { children: /* @__PURE__ */ React.createElement(ReactAsset, { ...props.label.asset }) } : {},
|
|
8
|
+
...props.icon ? {
|
|
9
|
+
[props.metaData?.iconPosition === "left" ? "leftIcon" : "rightIcon"]: /* @__PURE__ */ React.createElement(ReactAsset, { ...props.icon.asset })
|
|
10
|
+
} : {},
|
|
11
|
+
...props.run ? { onClick: props.run } : {},
|
|
12
|
+
...props.metaData?.variant ? { variant: props.metaData.variant } : {},
|
|
13
|
+
...props.metaData?.isLoading ? { isLoading: props.metaData.isLoading } : {}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
var ActionComponent = (props) => {
|
|
17
|
+
const { children, ...buttonProps } = useActionPros(props);
|
|
18
|
+
return /* @__PURE__ */ React.createElement(Button, { ...buttonProps }, children);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/dsl/Action.tsx
|
|
22
|
+
import React2 from "react";
|
|
23
|
+
import {
|
|
24
|
+
Asset,
|
|
25
|
+
createSlot,
|
|
26
|
+
isTemplateStringInstance
|
|
27
|
+
} from "@player-tools/dsl";
|
|
28
|
+
import { Collection } from "@devtools-ui/collection";
|
|
29
|
+
import { Text } from "@devtools-ui/text";
|
|
30
|
+
var Action = (props) => {
|
|
31
|
+
const { exp, children, ...rest } = props;
|
|
32
|
+
let expValue;
|
|
33
|
+
if (isTemplateStringInstance(exp)) {
|
|
34
|
+
expValue = exp.toValue();
|
|
35
|
+
} else if (Array.isArray(exp)) {
|
|
36
|
+
expValue = exp.map((e) => typeof e === "string" ? e : e.toValue());
|
|
37
|
+
} else if (exp) {
|
|
38
|
+
expValue = exp;
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "action", ...rest, ...expValue && { exp: expValue } }, children);
|
|
41
|
+
};
|
|
42
|
+
var CollectionComp = (props) => {
|
|
43
|
+
return /* @__PURE__ */ React2.createElement(Collection, null, /* @__PURE__ */ React2.createElement(Collection.Values, null, props.children));
|
|
44
|
+
};
|
|
45
|
+
Action.Label = createSlot({
|
|
46
|
+
name: "label",
|
|
47
|
+
TextComp: Text,
|
|
48
|
+
CollectionComp,
|
|
49
|
+
isArray: false,
|
|
50
|
+
wrapInAsset: true
|
|
51
|
+
});
|
|
52
|
+
Action.Icon = createSlot({
|
|
53
|
+
name: "icon",
|
|
54
|
+
TextComp: Text,
|
|
55
|
+
CollectionComp,
|
|
56
|
+
isArray: false,
|
|
57
|
+
wrapInAsset: true
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/transform/index.ts
|
|
61
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
62
|
+
var transform = (action, options) => {
|
|
63
|
+
return {
|
|
64
|
+
...action,
|
|
65
|
+
run() {
|
|
66
|
+
if (action.exp) {
|
|
67
|
+
options.evaluate(action.exp);
|
|
68
|
+
}
|
|
69
|
+
if (action.value) {
|
|
70
|
+
const skipValidation = action.metaData?.skipValidation;
|
|
71
|
+
options.transition?.(action.value, { force: skipValidation });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var expPropTransform = (asset) => {
|
|
77
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
78
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
79
|
+
return asset;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
...asset,
|
|
83
|
+
plugins: {
|
|
84
|
+
...asset.plugins,
|
|
85
|
+
stringResolver: {
|
|
86
|
+
...asset?.plugins?.stringResolver,
|
|
87
|
+
propertiesToSkip: [
|
|
88
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
89
|
+
"exp"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
var actionTransform = compose(
|
|
96
|
+
transform,
|
|
97
|
+
composeBefore(expPropTransform)
|
|
98
|
+
);
|
|
99
|
+
export {
|
|
100
|
+
Action,
|
|
101
|
+
ActionComponent,
|
|
102
|
+
actionTransform,
|
|
103
|
+
expPropTransform
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/components/ActionComponent.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Button } from "@chakra-ui/react";
|
|
4
|
+
import { ReactAsset } from "@player-ui/react";
|
|
5
|
+
var useActionPros = (props) => {
|
|
6
|
+
return {
|
|
7
|
+
...props.label ? { children: /* @__PURE__ */ React.createElement(ReactAsset, { ...props.label.asset }) } : {},
|
|
8
|
+
...props.icon ? {
|
|
9
|
+
[props.metaData?.iconPosition === "left" ? "leftIcon" : "rightIcon"]: /* @__PURE__ */ React.createElement(ReactAsset, { ...props.icon.asset })
|
|
10
|
+
} : {},
|
|
11
|
+
...props.run ? { onClick: props.run } : {},
|
|
12
|
+
...props.metaData?.variant ? { variant: props.metaData.variant } : {},
|
|
13
|
+
...props.metaData?.isLoading ? { isLoading: props.metaData.isLoading } : {}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
var ActionComponent = (props) => {
|
|
17
|
+
const { children, ...buttonProps } = useActionPros(props);
|
|
18
|
+
return /* @__PURE__ */ React.createElement(Button, { ...buttonProps }, children);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/dsl/Action.tsx
|
|
22
|
+
import React2 from "react";
|
|
23
|
+
import {
|
|
24
|
+
Asset,
|
|
25
|
+
createSlot,
|
|
26
|
+
isTemplateStringInstance
|
|
27
|
+
} from "@player-tools/dsl";
|
|
28
|
+
import { Collection } from "@devtools-ui/collection";
|
|
29
|
+
import { Text } from "@devtools-ui/text";
|
|
30
|
+
var Action = (props) => {
|
|
31
|
+
const { exp, children, ...rest } = props;
|
|
32
|
+
let expValue;
|
|
33
|
+
if (isTemplateStringInstance(exp)) {
|
|
34
|
+
expValue = exp.toValue();
|
|
35
|
+
} else if (Array.isArray(exp)) {
|
|
36
|
+
expValue = exp.map((e) => typeof e === "string" ? e : e.toValue());
|
|
37
|
+
} else if (exp) {
|
|
38
|
+
expValue = exp;
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "action", ...rest, ...expValue && { exp: expValue } }, children);
|
|
41
|
+
};
|
|
42
|
+
var CollectionComp = (props) => {
|
|
43
|
+
return /* @__PURE__ */ React2.createElement(Collection, null, /* @__PURE__ */ React2.createElement(Collection.Values, null, props.children));
|
|
44
|
+
};
|
|
45
|
+
Action.Label = createSlot({
|
|
46
|
+
name: "label",
|
|
47
|
+
TextComp: Text,
|
|
48
|
+
CollectionComp,
|
|
49
|
+
isArray: false,
|
|
50
|
+
wrapInAsset: true
|
|
51
|
+
});
|
|
52
|
+
Action.Icon = createSlot({
|
|
53
|
+
name: "icon",
|
|
54
|
+
TextComp: Text,
|
|
55
|
+
CollectionComp,
|
|
56
|
+
isArray: false,
|
|
57
|
+
wrapInAsset: true
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/transform/index.ts
|
|
61
|
+
import { compose, composeBefore } from "@player-ui/asset-transform-plugin";
|
|
62
|
+
var transform = (action, options) => {
|
|
63
|
+
return {
|
|
64
|
+
...action,
|
|
65
|
+
run() {
|
|
66
|
+
if (action.exp) {
|
|
67
|
+
options.evaluate(action.exp);
|
|
68
|
+
}
|
|
69
|
+
if (action.value) {
|
|
70
|
+
const skipValidation = action.metaData?.skipValidation;
|
|
71
|
+
options.transition?.(action.value, { force: skipValidation });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var expPropTransform = (asset) => {
|
|
77
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
78
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
79
|
+
return asset;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
...asset,
|
|
83
|
+
plugins: {
|
|
84
|
+
...asset.plugins,
|
|
85
|
+
stringResolver: {
|
|
86
|
+
...asset?.plugins?.stringResolver,
|
|
87
|
+
propertiesToSkip: [
|
|
88
|
+
...asset.plugins?.stringResolver?.propertiesToSkip ?? [],
|
|
89
|
+
"exp"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
var actionTransform = compose(
|
|
96
|
+
transform,
|
|
97
|
+
composeBefore(expPropTransform)
|
|
98
|
+
);
|
|
99
|
+
export {
|
|
100
|
+
Action,
|
|
101
|
+
ActionComponent,
|
|
102
|
+
actionTransform,
|
|
103
|
+
expPropTransform
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/components/ActionComponent.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/dsl/Action.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/action/src/transform/index.ts"],"sourcesContent":["import React from \"react\";\nimport { Button } from \"@chakra-ui/react\";\nimport type { TransformedAction } from \"../types\";\nimport { ReactAsset } from \"@player-ui/react\";\n\nconst useActionPros = (props: TransformedAction) => {\n return {\n ...(props.label ? { children: <ReactAsset {...props.label.asset} /> } : {}),\n ...(props.icon\n ? {\n [props.metaData?.iconPosition === \"left\" ? \"leftIcon\" : \"rightIcon\"]:\n <ReactAsset {...props.icon.asset} />,\n }\n : {}),\n ...(props.run ? { onClick: props.run } : {}),\n ...(props.metaData?.variant ? { variant: props.metaData.variant } : {}),\n ...(props.metaData?.isLoading\n ? { isLoading: props.metaData.isLoading }\n : {}),\n } as const;\n};\n\nexport const ActionComponent = (props: TransformedAction) => {\n const { children, ...buttonProps } = useActionPros(props);\n\n return <Button {...buttonProps}>{children}</Button>;\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n isTemplateStringInstance,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport type { ActionAsset } from \"../types\";\nimport { Collection } from \"@devtools-ui/collection\";\nimport { Text } from \"@devtools-ui/text\";\n\nexport const Action = (props: AssetPropsWithChildren<ActionAsset>) => {\n const { exp, children, ...rest } = props;\n\n let expValue: ActionAsset[\"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=\"action\" {...rest} {...(expValue && { exp: expValue })}>\n {children}\n </Asset>\n );\n};\n\nconst CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {\n return (\n <Collection>\n <Collection.Values>{props.children}</Collection.Values>\n </Collection>\n );\n};\n\nAction.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\n});\n\nAction.Icon = createSlot({\n name: \"icon\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\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 { ActionAsset, TransformedAction } from \"../types\";\n\n/**\n * Attaches the methods to execute an action\n */\nconst transform: TransformFunction<ActionAsset, TransformedAction> = (\n action,\n options\n) => {\n return {\n ...action,\n run() {\n if (action.exp) {\n options.evaluate(action.exp);\n }\n\n if (action.value) {\n const skipValidation = action.metaData?.skipValidation;\n options.transition?.(action.value, { force: skipValidation });\n }\n },\n };\n};\n\n/**\n * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist\n *\n * @param asset - Asset to apply the transform to\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 actionTransform = compose(\n transform,\n composeBefore(expPropTransform)\n);\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,SAAS,cAAc;AAEvB,SAAS,kBAAkB;AAE3B,IAAM,gBAAgB,CAAC,UAA6B;AAClD,SAAO;AAAA,IACL,GAAI,MAAM,QAAQ,EAAE,UAAU,oCAAC,cAAY,GAAG,MAAM,MAAM,OAAO,EAAG,IAAI,CAAC;AAAA,IACzE,GAAI,MAAM,OACN;AAAA,MACE,CAAC,MAAM,UAAU,iBAAiB,SAAS,aAAa,WAAW,GACjE,oCAAC,cAAY,GAAG,MAAM,KAAK,OAAO;AAAA,IACtC,IACA,CAAC;AAAA,IACL,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,IAAI,IAA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;;;ACjDD,SAAS,SAAS,qBAAqB;AAMvC,IAAM,YAA+D,CACnE,QACA,YACG;AACH,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AACJ,UAAI,OAAO,KAAK;AACd,gBAAQ,SAAS,OAAO,GAAG;AAAA,MAC7B;AAEA,UAAI,OAAO,OAAO;AAChB,cAAM,iBAAiB,OAAO,UAAU;AACxC,gBAAQ,aAAa,OAAO,OAAO,EAAE,OAAO,eAAe,CAAC;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AACF;AAOO,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,kBAAkB;AAAA,EAC7B;AAAA,EACA,cAAc,gBAAgB;AAChC;","names":["React"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtools-ui/action",
|
|
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/types": "0.7.1",
|
|
13
|
+
"@types/react": "^18.2.51",
|
|
14
|
+
"framer-motion": "^11.0.8",
|
|
15
|
+
"react": "^18.2.0",
|
|
16
|
+
"@player-ui/react": "^0.7.1",
|
|
17
|
+
"@player-ui/asset-transform-plugin": "^0.7.1",
|
|
18
|
+
"@player-ui/player": "0.7.1",
|
|
19
|
+
"dlv": "^1.1.3",
|
|
20
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
21
|
+
"tslib": "^2.6.2"
|
|
22
|
+
},
|
|
23
|
+
"module": "dist/index.legacy-esm.js",
|
|
24
|
+
"types": "types/index.d.ts",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./types/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"default": "./dist/cjs/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src",
|
|
37
|
+
"types"
|
|
38
|
+
],
|
|
39
|
+
"peerDependencies": {}
|
|
40
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Button } from "@chakra-ui/react";
|
|
3
|
+
import type { TransformedAction } from "../types";
|
|
4
|
+
import { ReactAsset } from "@player-ui/react";
|
|
5
|
+
|
|
6
|
+
const useActionPros = (props: TransformedAction) => {
|
|
7
|
+
return {
|
|
8
|
+
...(props.label ? { children: <ReactAsset {...props.label.asset} /> } : {}),
|
|
9
|
+
...(props.icon
|
|
10
|
+
? {
|
|
11
|
+
[props.metaData?.iconPosition === "left" ? "leftIcon" : "rightIcon"]:
|
|
12
|
+
<ReactAsset {...props.icon.asset} />,
|
|
13
|
+
}
|
|
14
|
+
: {}),
|
|
15
|
+
...(props.run ? { onClick: props.run } : {}),
|
|
16
|
+
...(props.metaData?.variant ? { variant: props.metaData.variant } : {}),
|
|
17
|
+
...(props.metaData?.isLoading
|
|
18
|
+
? { isLoading: props.metaData.isLoading }
|
|
19
|
+
: {}),
|
|
20
|
+
} as const;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const ActionComponent = (props: TransformedAction) => {
|
|
24
|
+
const { children, ...buttonProps } = useActionPros(props);
|
|
25
|
+
|
|
26
|
+
return <Button {...buttonProps}>{children}</Button>;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ActionComponent } from "./ActionComponent";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
AssetPropsWithChildren,
|
|
4
|
+
Asset,
|
|
5
|
+
createSlot,
|
|
6
|
+
isTemplateStringInstance,
|
|
7
|
+
} from "@player-tools/dsl";
|
|
8
|
+
import type { Asset as AssetType } from "@player-ui/player";
|
|
9
|
+
import type { ActionAsset } from "../types";
|
|
10
|
+
import { Collection } from "@devtools-ui/collection";
|
|
11
|
+
import { Text } from "@devtools-ui/text";
|
|
12
|
+
|
|
13
|
+
export const Action = (props: AssetPropsWithChildren<ActionAsset>) => {
|
|
14
|
+
const { exp, children, ...rest } = props;
|
|
15
|
+
|
|
16
|
+
let expValue: ActionAsset["exp"];
|
|
17
|
+
|
|
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
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Asset type="action" {...rest} {...(expValue && { exp: expValue })}>
|
|
28
|
+
{children}
|
|
29
|
+
</Asset>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {
|
|
34
|
+
return (
|
|
35
|
+
<Collection>
|
|
36
|
+
<Collection.Values>{props.children}</Collection.Values>
|
|
37
|
+
</Collection>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Action.Label = createSlot({
|
|
42
|
+
name: "label",
|
|
43
|
+
TextComp: Text,
|
|
44
|
+
CollectionComp,
|
|
45
|
+
isArray: false,
|
|
46
|
+
wrapInAsset: true,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
Action.Icon = createSlot({
|
|
50
|
+
name: "icon",
|
|
51
|
+
TextComp: Text,
|
|
52
|
+
CollectionComp,
|
|
53
|
+
isArray: false,
|
|
54
|
+
wrapInAsset: true,
|
|
55
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { render, expression as e, Asset } from "@player-tools/dsl";
|
|
4
|
+
import { Action } from "../Action";
|
|
5
|
+
|
|
6
|
+
describe("DSL: Action", () => {
|
|
7
|
+
test("Renders action", async () => {
|
|
8
|
+
const rendered = await render(<Action></Action>);
|
|
9
|
+
|
|
10
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
11
|
+
id: "root",
|
|
12
|
+
type: "action",
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("action with label", async () => {
|
|
17
|
+
const rendered = await render(
|
|
18
|
+
<Action>
|
|
19
|
+
<Action.Label>Label</Action.Label>
|
|
20
|
+
</Action>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
24
|
+
id: "root",
|
|
25
|
+
type: "action",
|
|
26
|
+
label: {
|
|
27
|
+
asset: {
|
|
28
|
+
id: "label",
|
|
29
|
+
type: "text",
|
|
30
|
+
value: "Label",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("action with exp", async () => {
|
|
37
|
+
const rendered = await render(
|
|
38
|
+
<Action exp={e`noop`}>
|
|
39
|
+
<Action.Label>Label</Action.Label>
|
|
40
|
+
</Action>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
44
|
+
id: "root",
|
|
45
|
+
type: "action",
|
|
46
|
+
exp: "noop",
|
|
47
|
+
label: {
|
|
48
|
+
asset: {
|
|
49
|
+
id: "label",
|
|
50
|
+
type: "text",
|
|
51
|
+
value: "Label",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("action with icon", async () => {
|
|
58
|
+
const rendered = await render(
|
|
59
|
+
<Action exp={e`noop`}>
|
|
60
|
+
<Action.Label>Label</Action.Label>
|
|
61
|
+
<Action.Icon>
|
|
62
|
+
<Asset type="icon">
|
|
63
|
+
<property name="value">SomeIcon</property>
|
|
64
|
+
</Asset>
|
|
65
|
+
</Action.Icon>
|
|
66
|
+
</Action>
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
70
|
+
id: "root",
|
|
71
|
+
type: "action",
|
|
72
|
+
exp: "noop",
|
|
73
|
+
label: {
|
|
74
|
+
asset: {
|
|
75
|
+
id: "label",
|
|
76
|
+
type: "text",
|
|
77
|
+
value: "Label",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
icon: {
|
|
81
|
+
asset: {
|
|
82
|
+
id: "icon",
|
|
83
|
+
type: "icon",
|
|
84
|
+
value: "SomeIcon",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("action with metadata", async () => {
|
|
91
|
+
const rendered = await render(
|
|
92
|
+
<Action
|
|
93
|
+
metaData={{
|
|
94
|
+
isLoading: true,
|
|
95
|
+
variant: "solid",
|
|
96
|
+
iconPosition: "left",
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
102
|
+
id: "root",
|
|
103
|
+
type: "action",
|
|
104
|
+
metaData: {
|
|
105
|
+
isLoading: true,
|
|
106
|
+
variant: "solid",
|
|
107
|
+
iconPosition: "left",
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("action with collection of text", async () => {
|
|
113
|
+
const rendered = await render(
|
|
114
|
+
<Action>
|
|
115
|
+
<Action.Label>
|
|
116
|
+
<Asset type="text">
|
|
117
|
+
<property name="value">Some</property>
|
|
118
|
+
</Asset>
|
|
119
|
+
<Asset type="text">
|
|
120
|
+
<property name="value">Text</property>
|
|
121
|
+
</Asset>
|
|
122
|
+
</Action.Label>
|
|
123
|
+
</Action>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
127
|
+
id: "root",
|
|
128
|
+
type: "action",
|
|
129
|
+
label: {
|
|
130
|
+
asset: {
|
|
131
|
+
id: "label",
|
|
132
|
+
type: "collection",
|
|
133
|
+
values: [
|
|
134
|
+
{
|
|
135
|
+
asset: {
|
|
136
|
+
id: "label-values-0",
|
|
137
|
+
type: "text",
|
|
138
|
+
value: "Some",
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
asset: {
|
|
143
|
+
id: "label-values-1",
|
|
144
|
+
type: "text",
|
|
145
|
+
value: "Text",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
package/src/dsl/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Action } from "./Action";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 { ActionAsset, TransformedAction } from "../types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Attaches the methods to execute an action
|
|
11
|
+
*/
|
|
12
|
+
const transform: TransformFunction<ActionAsset, TransformedAction> = (
|
|
13
|
+
action,
|
|
14
|
+
options
|
|
15
|
+
) => {
|
|
16
|
+
return {
|
|
17
|
+
...action,
|
|
18
|
+
run() {
|
|
19
|
+
if (action.exp) {
|
|
20
|
+
options.evaluate(action.exp);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (action.value) {
|
|
24
|
+
const skipValidation = action.metaData?.skipValidation;
|
|
25
|
+
options.transition?.(action.value, { force: skipValidation });
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
|
|
33
|
+
*
|
|
34
|
+
* @param asset - Asset to apply the transform to
|
|
35
|
+
*/
|
|
36
|
+
export const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {
|
|
37
|
+
const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
|
|
38
|
+
|
|
39
|
+
if (skipArray && skipArray.indexOf("exp") > 1) {
|
|
40
|
+
return asset;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
...asset,
|
|
45
|
+
plugins: {
|
|
46
|
+
...asset.plugins,
|
|
47
|
+
stringResolver: {
|
|
48
|
+
...asset?.plugins?.stringResolver,
|
|
49
|
+
propertiesToSkip: [
|
|
50
|
+
...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),
|
|
51
|
+
"exp",
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const actionTransform = compose(
|
|
59
|
+
transform,
|
|
60
|
+
composeBefore(expPropTransform)
|
|
61
|
+
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TextAsset } from "@devtools-ui/text";
|
|
2
|
+
import type { Asset, AssetWrapper, Expression } from "@player-ui/types";
|
|
3
|
+
|
|
4
|
+
export type Variant = "solid" | "outline" | "ghost" | "link";
|
|
5
|
+
|
|
6
|
+
export interface ActionAsset extends Asset<"action"> {
|
|
7
|
+
/**text value for action */
|
|
8
|
+
value?: string;
|
|
9
|
+
|
|
10
|
+
/** An optional Icon asset. */
|
|
11
|
+
icon?: AssetWrapper;
|
|
12
|
+
|
|
13
|
+
/** A text asset for the action's label */
|
|
14
|
+
label?: AssetWrapper<TextAsset>;
|
|
15
|
+
|
|
16
|
+
/** An optional expression to execute before transitioning */
|
|
17
|
+
exp?: Expression;
|
|
18
|
+
|
|
19
|
+
/** Additional optional data to assist with the action interactions on the page */
|
|
20
|
+
metaData?: {
|
|
21
|
+
/** Force transition to the next view without checking for validation */
|
|
22
|
+
skipValidation?: boolean;
|
|
23
|
+
|
|
24
|
+
/** Button variant */
|
|
25
|
+
variant?: Variant;
|
|
26
|
+
|
|
27
|
+
/** Indicate a spinner for loading */
|
|
28
|
+
isLoading?: boolean;
|
|
29
|
+
|
|
30
|
+
/** icon position */
|
|
31
|
+
iconPosition?: "left" | "right";
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A stateful instance of an action */
|
|
36
|
+
export interface TransformedAction extends ActionAsset {
|
|
37
|
+
/** A method to execute the action */
|
|
38
|
+
run: () => void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AssetPropsWithChildren } from "@player-tools/dsl";
|
|
3
|
+
import type { ActionAsset } from "../types";
|
|
4
|
+
export declare const Action: {
|
|
5
|
+
(props: AssetPropsWithChildren<ActionAsset>): React.JSX.Element;
|
|
6
|
+
Label: (props: {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}) => React.JSX.Element;
|
|
9
|
+
Icon: (props: {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
}) => React.JSX.Element;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=Action.d.ts.map
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Asset, BeforeTransformFunction } from "@player-ui/player";
|
|
2
|
+
/**
|
|
3
|
+
* Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
|
|
4
|
+
*
|
|
5
|
+
* @param asset - Asset to apply the transform to
|
|
6
|
+
*/
|
|
7
|
+
export declare const expPropTransform: BeforeTransformFunction<Asset>;
|
|
8
|
+
export declare const actionTransform: import("@player-ui/player").TransformFunctions;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TextAsset } from "@devtools-ui/text";
|
|
2
|
+
import type { Asset, AssetWrapper, Expression } from "@player-ui/types";
|
|
3
|
+
export type Variant = "solid" | "outline" | "ghost" | "link";
|
|
4
|
+
export interface ActionAsset extends Asset<"action"> {
|
|
5
|
+
/**text value for action */
|
|
6
|
+
value?: string;
|
|
7
|
+
/** An optional Icon asset. */
|
|
8
|
+
icon?: AssetWrapper;
|
|
9
|
+
/** A text asset for the action's label */
|
|
10
|
+
label?: AssetWrapper<TextAsset>;
|
|
11
|
+
/** An optional expression to execute before transitioning */
|
|
12
|
+
exp?: Expression;
|
|
13
|
+
/** Additional optional data to assist with the action interactions on the page */
|
|
14
|
+
metaData?: {
|
|
15
|
+
/** Force transition to the next view without checking for validation */
|
|
16
|
+
skipValidation?: boolean;
|
|
17
|
+
/** Button variant */
|
|
18
|
+
variant?: Variant;
|
|
19
|
+
/** Indicate a spinner for loading */
|
|
20
|
+
isLoading?: boolean;
|
|
21
|
+
/** icon position */
|
|
22
|
+
iconPosition?: "left" | "right";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** A stateful instance of an action */
|
|
26
|
+
export interface TransformedAction extends ActionAsset {
|
|
27
|
+
/** A method to execute the action */
|
|
28
|
+
run: () => void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|