@devtools-ui/copy-to-clipboard 0.0.2--canary.13.662
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 +110 -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 +43 -0
- package/src/component/index.tsx +38 -0
- package/src/dsl/__tests__/index.test.tsx +27 -0
- package/src/dsl/index.tsx +47 -0
- package/src/index.ts +4 -0
- package/src/transform/index.ts +24 -0
- package/src/types/index.ts +14 -0
- package/types/component/index.d.ts +4 -0
- package/types/dsl/index.d.ts +17 -0
- package/types/index.d.ts +5 -0
- package/types/transform/index.d.ts +8 -0
- package/types/types/index.d.ts +13 -0
|
@@ -0,0 +1,110 @@
|
|
|
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/copy-to-clipboard/src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
CopyToClipboard: () => CopyToClipboard2,
|
|
34
|
+
CopyToClipboardComponent: () => CopyToClipboardComponent,
|
|
35
|
+
copyToClipboardTransform: () => copyToClipboardTransform
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/component/index.tsx
|
|
40
|
+
var import_react = require("@player-ui/react");
|
|
41
|
+
var import_react2 = __toESM(require("react"));
|
|
42
|
+
var import_react_copy_to_clipboard = require("react-copy-to-clipboard");
|
|
43
|
+
var import_react3 = require("@chakra-ui/react");
|
|
44
|
+
var CopyToClipboardComponent = (props) => {
|
|
45
|
+
const { label, data } = props;
|
|
46
|
+
const toast = (0, import_react3.useToast)();
|
|
47
|
+
const handleCopy = (0, import_react2.useCallback)(
|
|
48
|
+
(_, result) => {
|
|
49
|
+
if (result) {
|
|
50
|
+
toast({
|
|
51
|
+
title: "Data copied to clipboard",
|
|
52
|
+
description: "Data copied successfully",
|
|
53
|
+
status: "success",
|
|
54
|
+
duration: 3e3,
|
|
55
|
+
isClosable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
toast({
|
|
59
|
+
title: "Failed to copy",
|
|
60
|
+
description: "Failed to copy data to clipboard",
|
|
61
|
+
status: "error",
|
|
62
|
+
duration: 3e3,
|
|
63
|
+
isClosable: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[toast]
|
|
68
|
+
);
|
|
69
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react_copy_to_clipboard.CopyToClipboard, { text: data, onCopy: handleCopy }, /* @__PURE__ */ import_react2.default.createElement(import_react3.Button, null, label && /* @__PURE__ */ import_react2.default.createElement(import_react.ReactAsset, { ...label.asset })));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/dsl/index.tsx
|
|
73
|
+
var import_react4 = __toESM(require("react"));
|
|
74
|
+
var import_dsl = require("@player-tools/dsl");
|
|
75
|
+
var import_collection = require("@devtools-ui/collection");
|
|
76
|
+
var import_text = require("@devtools-ui/text");
|
|
77
|
+
var CopyToClipboard2 = (props) => {
|
|
78
|
+
const { binding, children, ...rest } = props;
|
|
79
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_dsl.Asset, { type: "copy-to-clipboard", ...rest }, binding && /* @__PURE__ */ import_react4.default.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
80
|
+
};
|
|
81
|
+
var CollectionComp = (props) => {
|
|
82
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_collection.Collection, null, /* @__PURE__ */ import_react4.default.createElement(import_collection.Collection.Values, null, props.children));
|
|
83
|
+
};
|
|
84
|
+
CopyToClipboard2.Label = (0, import_dsl.createSlot)({
|
|
85
|
+
name: "label",
|
|
86
|
+
TextComp: import_text.Text,
|
|
87
|
+
CollectionComp,
|
|
88
|
+
isArray: false,
|
|
89
|
+
wrapInAsset: true
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/transform/index.ts
|
|
93
|
+
var copyToClipboardTransform = (asset, options) => ({
|
|
94
|
+
...asset,
|
|
95
|
+
data: asset.binding === void 0 ? "" : JSON.stringify(
|
|
96
|
+
options.data.model.get(asset.binding, {
|
|
97
|
+
includeInvalid: true,
|
|
98
|
+
formatted: false
|
|
99
|
+
}),
|
|
100
|
+
null,
|
|
101
|
+
2
|
|
102
|
+
)
|
|
103
|
+
});
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
CopyToClipboard,
|
|
107
|
+
CopyToClipboardComponent,
|
|
108
|
+
copyToClipboardTransform
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/component/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/dsl/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./component\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import { ReactAsset } from \"@player-ui/react\";\nimport React, { useCallback } from \"react\";\nimport type { TransformedCopyToClipboard } from \"../types\";\nimport { CopyToClipboard } from \"react-copy-to-clipboard\";\nimport { useToast, Button } from \"@chakra-ui/react\";\n\nexport const CopyToClipboardComponent = (props: TransformedCopyToClipboard) => {\n const { label, data } = props;\n const toast = useToast();\n const handleCopy = useCallback(\n (_: string, result: boolean) => {\n if (result) {\n toast({\n title: \"Data copied to clipboard\",\n description: \"Data copied successfully\",\n status: \"success\",\n duration: 3000,\n isClosable: true,\n });\n } else {\n toast({\n title: \"Failed to copy\",\n description: \"Failed to copy data to clipboard\",\n status: \"error\",\n duration: 3000,\n isClosable: true,\n });\n }\n },\n [toast]\n );\n\n return (\n <CopyToClipboard text={data} onCopy={handleCopy}>\n <Button>{label && <ReactAsset {...label.asset} />}</Button>\n </CopyToClipboard>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport { Collection } from \"@devtools-ui/collection\";\nimport { Text } from \"@devtools-ui/text\";\nimport type { CopyToClipboardAsset } 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 CopyToClipboard = (\n props: Omit<AssetPropsWithChildren<CopyToClipboardAsset>, \"binding\"> & {\n /** The binding */\n binding?: BindingTemplateInstance;\n }\n) => {\n const { binding, children, ...rest } = props;\n\n return (\n <Asset type=\"copy-to-clipboard\" {...rest}>\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\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\nCopyToClipboard.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { CopyToClipboardAsset, TransformedCopyToClipboard } 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 copyToClipboardTransform: TransformFunction<\n CopyToClipboardAsset,\n TransformedCopyToClipboard\n> = (asset, options) => ({\n ...asset,\n data:\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});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA2B;AAC3B,IAAAC,gBAAmC;AAEnC,qCAAgC;AAChC,IAAAA,gBAAiC;AAE1B,IAAM,2BAA2B,CAAC,UAAsC;AAC7E,QAAM,EAAE,OAAO,KAAK,IAAI;AACxB,QAAM,YAAQ,wBAAS;AACvB,QAAM,iBAAa;AAAA,IACjB,CAAC,GAAW,WAAoB;AAC9B,UAAI,QAAQ;AACV,cAAM;AAAA,UACJ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,YAAY;AAAA,QACd,CAAC;AAAA,MACH,OAAO;AACL,cAAM;AAAA,UACJ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,YAAY;AAAA,QACd,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,CAAC,KAAK;AAAA,EACR;AAEA,SACE,8BAAAC,QAAA,cAAC,kDAAgB,MAAM,MAAM,QAAQ,cACnC,8BAAAA,QAAA,cAAC,4BAAQ,SAAS,8BAAAA,QAAA,cAAC,2BAAY,GAAG,MAAM,OAAO,CAAG,CACpD;AAEJ;;;ACrCA,IAAAC,gBAAkB;AAClB,iBAKO;AAEP,wBAA2B;AAC3B,kBAAqB;AAOd,IAAMC,mBAAkB,CAC7B,UAIG;AACH,QAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI;AAEvC,SACE,8BAAAC,QAAA,cAAC,oBAAM,MAAK,qBAAqB,GAAG,QACjC,WAAW,8BAAAA,QAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GACvD,QACH;AAEJ;AAEA,IAAM,iBAAiB,CAAC,UAA6C;AACnE,SACE,8BAAAA,QAAA,cAAC,oCACC,8BAAAA,QAAA,cAAC,6BAAW,QAAX,MAAmB,MAAM,QAAS,CACrC;AAEJ;AAEAD,iBAAgB,YAAQ,uBAAW;AAAA,EACjC,MAAM;AAAA,EACN,UAAU;AAAA,EACV;AAAA,EACA,SAAS;AAAA,EACT,aAAa;AACf,CAAC;;;ACvCM,IAAM,2BAGT,CAAC,OAAO,aAAa;AAAA,EACvB,GAAG;AAAA,EACH,MACE,MAAM,YAAY,SACd,KACA,KAAK;AAAA,IACH,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,IACD;AAAA,IACA;AAAA,EACF;AACR;","names":["CopyToClipboard","import_react","React","import_react","CopyToClipboard","React"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/component/index.tsx
|
|
2
|
+
import { ReactAsset } from "@player-ui/react";
|
|
3
|
+
import React, { useCallback } from "react";
|
|
4
|
+
import { CopyToClipboard } from "react-copy-to-clipboard";
|
|
5
|
+
import { useToast, Button } from "@chakra-ui/react";
|
|
6
|
+
var CopyToClipboardComponent = (props) => {
|
|
7
|
+
const { label, data } = props;
|
|
8
|
+
const toast = useToast();
|
|
9
|
+
const handleCopy = useCallback(
|
|
10
|
+
(_, result) => {
|
|
11
|
+
if (result) {
|
|
12
|
+
toast({
|
|
13
|
+
title: "Data copied to clipboard",
|
|
14
|
+
description: "Data copied successfully",
|
|
15
|
+
status: "success",
|
|
16
|
+
duration: 3e3,
|
|
17
|
+
isClosable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
toast({
|
|
21
|
+
title: "Failed to copy",
|
|
22
|
+
description: "Failed to copy data to clipboard",
|
|
23
|
+
status: "error",
|
|
24
|
+
duration: 3e3,
|
|
25
|
+
isClosable: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
[toast]
|
|
30
|
+
);
|
|
31
|
+
return /* @__PURE__ */ React.createElement(CopyToClipboard, { text: data, onCopy: handleCopy }, /* @__PURE__ */ React.createElement(Button, null, label && /* @__PURE__ */ React.createElement(ReactAsset, { ...label.asset })));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/dsl/index.tsx
|
|
35
|
+
import React2 from "react";
|
|
36
|
+
import {
|
|
37
|
+
Asset,
|
|
38
|
+
createSlot
|
|
39
|
+
} from "@player-tools/dsl";
|
|
40
|
+
import { Collection } from "@devtools-ui/collection";
|
|
41
|
+
import { Text } from "@devtools-ui/text";
|
|
42
|
+
var CopyToClipboard2 = (props) => {
|
|
43
|
+
const { binding, children, ...rest } = props;
|
|
44
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "copy-to-clipboard", ...rest }, binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
45
|
+
};
|
|
46
|
+
var CollectionComp = (props) => {
|
|
47
|
+
return /* @__PURE__ */ React2.createElement(Collection, null, /* @__PURE__ */ React2.createElement(Collection.Values, null, props.children));
|
|
48
|
+
};
|
|
49
|
+
CopyToClipboard2.Label = createSlot({
|
|
50
|
+
name: "label",
|
|
51
|
+
TextComp: Text,
|
|
52
|
+
CollectionComp,
|
|
53
|
+
isArray: false,
|
|
54
|
+
wrapInAsset: true
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/transform/index.ts
|
|
58
|
+
var copyToClipboardTransform = (asset, options) => ({
|
|
59
|
+
...asset,
|
|
60
|
+
data: asset.binding === void 0 ? "" : JSON.stringify(
|
|
61
|
+
options.data.model.get(asset.binding, {
|
|
62
|
+
includeInvalid: true,
|
|
63
|
+
formatted: false
|
|
64
|
+
}),
|
|
65
|
+
null,
|
|
66
|
+
2
|
|
67
|
+
)
|
|
68
|
+
});
|
|
69
|
+
export {
|
|
70
|
+
CopyToClipboard2 as CopyToClipboard,
|
|
71
|
+
CopyToClipboardComponent,
|
|
72
|
+
copyToClipboardTransform
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/component/index.tsx
|
|
2
|
+
import { ReactAsset } from "@player-ui/react";
|
|
3
|
+
import React, { useCallback } from "react";
|
|
4
|
+
import { CopyToClipboard } from "react-copy-to-clipboard";
|
|
5
|
+
import { useToast, Button } from "@chakra-ui/react";
|
|
6
|
+
var CopyToClipboardComponent = (props) => {
|
|
7
|
+
const { label, data } = props;
|
|
8
|
+
const toast = useToast();
|
|
9
|
+
const handleCopy = useCallback(
|
|
10
|
+
(_, result) => {
|
|
11
|
+
if (result) {
|
|
12
|
+
toast({
|
|
13
|
+
title: "Data copied to clipboard",
|
|
14
|
+
description: "Data copied successfully",
|
|
15
|
+
status: "success",
|
|
16
|
+
duration: 3e3,
|
|
17
|
+
isClosable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
toast({
|
|
21
|
+
title: "Failed to copy",
|
|
22
|
+
description: "Failed to copy data to clipboard",
|
|
23
|
+
status: "error",
|
|
24
|
+
duration: 3e3,
|
|
25
|
+
isClosable: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
[toast]
|
|
30
|
+
);
|
|
31
|
+
return /* @__PURE__ */ React.createElement(CopyToClipboard, { text: data, onCopy: handleCopy }, /* @__PURE__ */ React.createElement(Button, null, label && /* @__PURE__ */ React.createElement(ReactAsset, { ...label.asset })));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/dsl/index.tsx
|
|
35
|
+
import React2 from "react";
|
|
36
|
+
import {
|
|
37
|
+
Asset,
|
|
38
|
+
createSlot
|
|
39
|
+
} from "@player-tools/dsl";
|
|
40
|
+
import { Collection } from "@devtools-ui/collection";
|
|
41
|
+
import { Text } from "@devtools-ui/text";
|
|
42
|
+
var CopyToClipboard2 = (props) => {
|
|
43
|
+
const { binding, children, ...rest } = props;
|
|
44
|
+
return /* @__PURE__ */ React2.createElement(Asset, { type: "copy-to-clipboard", ...rest }, binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
45
|
+
};
|
|
46
|
+
var CollectionComp = (props) => {
|
|
47
|
+
return /* @__PURE__ */ React2.createElement(Collection, null, /* @__PURE__ */ React2.createElement(Collection.Values, null, props.children));
|
|
48
|
+
};
|
|
49
|
+
CopyToClipboard2.Label = createSlot({
|
|
50
|
+
name: "label",
|
|
51
|
+
TextComp: Text,
|
|
52
|
+
CollectionComp,
|
|
53
|
+
isArray: false,
|
|
54
|
+
wrapInAsset: true
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/transform/index.ts
|
|
58
|
+
var copyToClipboardTransform = (asset, options) => ({
|
|
59
|
+
...asset,
|
|
60
|
+
data: asset.binding === void 0 ? "" : JSON.stringify(
|
|
61
|
+
options.data.model.get(asset.binding, {
|
|
62
|
+
includeInvalid: true,
|
|
63
|
+
formatted: false
|
|
64
|
+
}),
|
|
65
|
+
null,
|
|
66
|
+
2
|
|
67
|
+
)
|
|
68
|
+
});
|
|
69
|
+
export {
|
|
70
|
+
CopyToClipboard2 as CopyToClipboard,
|
|
71
|
+
CopyToClipboardComponent,
|
|
72
|
+
copyToClipboardTransform
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/component/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/dsl/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/copy-to-clipboard/src/transform/index.ts"],"sourcesContent":["import { ReactAsset } from \"@player-ui/react\";\nimport React, { useCallback } from \"react\";\nimport type { TransformedCopyToClipboard } from \"../types\";\nimport { CopyToClipboard } from \"react-copy-to-clipboard\";\nimport { useToast, Button } from \"@chakra-ui/react\";\n\nexport const CopyToClipboardComponent = (props: TransformedCopyToClipboard) => {\n const { label, data } = props;\n const toast = useToast();\n const handleCopy = useCallback(\n (_: string, result: boolean) => {\n if (result) {\n toast({\n title: \"Data copied to clipboard\",\n description: \"Data copied successfully\",\n status: \"success\",\n duration: 3000,\n isClosable: true,\n });\n } else {\n toast({\n title: \"Failed to copy\",\n description: \"Failed to copy data to clipboard\",\n status: \"error\",\n duration: 3000,\n isClosable: true,\n });\n }\n },\n [toast]\n );\n\n return (\n <CopyToClipboard text={data} onCopy={handleCopy}>\n <Button>{label && <ReactAsset {...label.asset} />}</Button>\n </CopyToClipboard>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport { Collection } from \"@devtools-ui/collection\";\nimport { Text } from \"@devtools-ui/text\";\nimport type { CopyToClipboardAsset } 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 CopyToClipboard = (\n props: Omit<AssetPropsWithChildren<CopyToClipboardAsset>, \"binding\"> & {\n /** The binding */\n binding?: BindingTemplateInstance;\n }\n) => {\n const { binding, children, ...rest } = props;\n\n return (\n <Asset type=\"copy-to-clipboard\" {...rest}>\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\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\nCopyToClipboard.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n CollectionComp,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { CopyToClipboardAsset, TransformedCopyToClipboard } 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 copyToClipboardTransform: TransformFunction<\n CopyToClipboardAsset,\n TransformedCopyToClipboard\n> = (asset, options) => ({\n ...asset,\n data:\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});\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,OAAO,SAAS,mBAAmB;AAEnC,SAAS,uBAAuB;AAChC,SAAS,UAAU,cAAc;AAE1B,IAAM,2BAA2B,CAAC,UAAsC;AAC7E,QAAM,EAAE,OAAO,KAAK,IAAI;AACxB,QAAM,QAAQ,SAAS;AACvB,QAAM,aAAa;AAAA,IACjB,CAAC,GAAW,WAAoB;AAC9B,UAAI,QAAQ;AACV,cAAM;AAAA,UACJ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,YAAY;AAAA,QACd,CAAC;AAAA,MACH,OAAO;AACL,cAAM;AAAA,UACJ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,QAAQ;AAAA,UACR,UAAU;AAAA,UACV,YAAY;AAAA,QACd,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,CAAC,KAAK;AAAA,EACR;AAEA,SACE,oCAAC,mBAAgB,MAAM,MAAM,QAAQ,cACnC,oCAAC,cAAQ,SAAS,oCAAC,cAAY,GAAG,MAAM,OAAO,CAAG,CACpD;AAEJ;;;ACrCA,OAAOA,YAAW;AAClB;AAAA,EAEE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AAOd,IAAMC,mBAAkB,CAC7B,UAIG;AACH,QAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI;AAEvC,SACE,gBAAAD,OAAA,cAAC,SAAM,MAAK,qBAAqB,GAAG,QACjC,WAAW,gBAAAA,OAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GACvD,QACH;AAEJ;AAEA,IAAM,iBAAiB,CAAC,UAA6C;AACnE,SACE,gBAAAA,OAAA,cAAC,kBACC,gBAAAA,OAAA,cAAC,WAAW,QAAX,MAAmB,MAAM,QAAS,CACrC;AAEJ;AAEAC,iBAAgB,QAAQ,WAAW;AAAA,EACjC,MAAM;AAAA,EACN,UAAU;AAAA,EACV;AAAA,EACA,SAAS;AAAA,EACT,aAAa;AACf,CAAC;;;ACvCM,IAAM,2BAGT,CAAC,OAAO,aAAa;AAAA,EACvB,GAAG;AAAA,EACH,MACE,MAAM,YAAY,SACd,KACA,KAAK;AAAA,IACH,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,IACD;AAAA,IACA;AAAA,EACF;AACR;","names":["React","CopyToClipboard"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtools-ui/copy-to-clipboard",
|
|
3
|
+
"version": "0.0.2--canary.13.662",
|
|
4
|
+
"main": "dist/cjs/index.cjs",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@devtools-ui/text": "0.0.2--canary.13.662",
|
|
7
|
+
"@devtools-ui/collection": "0.0.2--canary.13.662",
|
|
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
|
+
"react-copy-to-clipboard": "^5.1.0",
|
|
22
|
+
"@types/react-copy-to-clipboard": "^5.0.7",
|
|
23
|
+
"tslib": "^2.6.2"
|
|
24
|
+
},
|
|
25
|
+
"module": "dist/index.legacy-esm.js",
|
|
26
|
+
"types": "types/index.d.ts",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"exports": {
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
"./dist/index.css": "./dist/index.css",
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./types/index.d.ts",
|
|
33
|
+
"import": "./dist/index.mjs",
|
|
34
|
+
"default": "./dist/cjs/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"src",
|
|
40
|
+
"types"
|
|
41
|
+
],
|
|
42
|
+
"peerDependencies": {}
|
|
43
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ReactAsset } from "@player-ui/react";
|
|
2
|
+
import React, { useCallback } from "react";
|
|
3
|
+
import type { TransformedCopyToClipboard } from "../types";
|
|
4
|
+
import { CopyToClipboard } from "react-copy-to-clipboard";
|
|
5
|
+
import { useToast, Button } from "@chakra-ui/react";
|
|
6
|
+
|
|
7
|
+
export const CopyToClipboardComponent = (props: TransformedCopyToClipboard) => {
|
|
8
|
+
const { label, data } = props;
|
|
9
|
+
const toast = useToast();
|
|
10
|
+
const handleCopy = useCallback(
|
|
11
|
+
(_: string, result: boolean) => {
|
|
12
|
+
if (result) {
|
|
13
|
+
toast({
|
|
14
|
+
title: "Data copied to clipboard",
|
|
15
|
+
description: "Data copied successfully",
|
|
16
|
+
status: "success",
|
|
17
|
+
duration: 3000,
|
|
18
|
+
isClosable: true,
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
toast({
|
|
22
|
+
title: "Failed to copy",
|
|
23
|
+
description: "Failed to copy data to clipboard",
|
|
24
|
+
status: "error",
|
|
25
|
+
duration: 3000,
|
|
26
|
+
isClosable: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
[toast]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<CopyToClipboard text={data} onCopy={handleCopy}>
|
|
35
|
+
<Button>{label && <ReactAsset {...label.asset} />}</Button>
|
|
36
|
+
</CopyToClipboard>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { render, binding as b } from "@player-tools/dsl";
|
|
4
|
+
import { CopyToClipboard } from "../";
|
|
5
|
+
|
|
6
|
+
describe("DSL: CopyToClipboard", () => {
|
|
7
|
+
test("Renders copy-to-clipboard", async () => {
|
|
8
|
+
const rendered = await render(
|
|
9
|
+
<CopyToClipboard binding={b`my_binding`}>
|
|
10
|
+
<CopyToClipboard.Label>Copy to clipboard</CopyToClipboard.Label>
|
|
11
|
+
</CopyToClipboard>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(rendered.jsonValue).toStrictEqual({
|
|
15
|
+
id: "root",
|
|
16
|
+
type: "copy-to-clipboard",
|
|
17
|
+
binding: "my_binding",
|
|
18
|
+
label: {
|
|
19
|
+
asset: {
|
|
20
|
+
id: "label",
|
|
21
|
+
type: "text",
|
|
22
|
+
value: "Copy to clipboard",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
AssetPropsWithChildren,
|
|
4
|
+
Asset,
|
|
5
|
+
createSlot,
|
|
6
|
+
BindingTemplateInstance,
|
|
7
|
+
} from "@player-tools/dsl";
|
|
8
|
+
import type { Asset as AssetType } from "@player-ui/player";
|
|
9
|
+
import { Collection } from "@devtools-ui/collection";
|
|
10
|
+
import { Text } from "@devtools-ui/text";
|
|
11
|
+
import type { CopyToClipboardAsset } from "../types";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Defines the component DSL representation, so users of this plugin can author Player-UI
|
|
15
|
+
* content leveraging .jsx/.tsx syntax.
|
|
16
|
+
*/
|
|
17
|
+
export const CopyToClipboard = (
|
|
18
|
+
props: Omit<AssetPropsWithChildren<CopyToClipboardAsset>, "binding"> & {
|
|
19
|
+
/** The binding */
|
|
20
|
+
binding?: BindingTemplateInstance;
|
|
21
|
+
}
|
|
22
|
+
) => {
|
|
23
|
+
const { binding, children, ...rest } = props;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Asset type="copy-to-clipboard" {...rest}>
|
|
27
|
+
{binding && <property name="binding">{binding.toValue()}</property>}
|
|
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
|
+
CopyToClipboard.Label = createSlot({
|
|
42
|
+
name: "label",
|
|
43
|
+
TextComp: Text,
|
|
44
|
+
CollectionComp,
|
|
45
|
+
isArray: false,
|
|
46
|
+
wrapInAsset: true,
|
|
47
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TransformFunction } from "@player-ui/player";
|
|
2
|
+
import { CopyToClipboardAsset, TransformedCopyToClipboard } from "../types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)
|
|
6
|
+
* and embeds Player state and methods:
|
|
7
|
+
*/
|
|
8
|
+
export const copyToClipboardTransform: TransformFunction<
|
|
9
|
+
CopyToClipboardAsset,
|
|
10
|
+
TransformedCopyToClipboard
|
|
11
|
+
> = (asset, options) => ({
|
|
12
|
+
...asset,
|
|
13
|
+
data:
|
|
14
|
+
asset.binding === undefined
|
|
15
|
+
? ""
|
|
16
|
+
: JSON.stringify(
|
|
17
|
+
options.data.model.get(asset.binding, {
|
|
18
|
+
includeInvalid: true,
|
|
19
|
+
formatted: false,
|
|
20
|
+
}),
|
|
21
|
+
null,
|
|
22
|
+
2
|
|
23
|
+
),
|
|
24
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Asset, AssetWrapper } from "@player-ui/types";
|
|
2
|
+
|
|
3
|
+
export interface CopyToClipboardAsset extends Asset<"copy-to-clipboard"> {
|
|
4
|
+
/** Binding to the data to be copied */
|
|
5
|
+
binding?: string;
|
|
6
|
+
/** Button Label */
|
|
7
|
+
label?: AssetWrapper;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** A stateful instance of the asset */
|
|
11
|
+
export interface TransformedCopyToClipboard extends CopyToClipboardAsset {
|
|
12
|
+
/** The stringified data to be copied */
|
|
13
|
+
data: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AssetPropsWithChildren, BindingTemplateInstance } from "@player-tools/dsl";
|
|
3
|
+
import type { CopyToClipboardAsset } 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 CopyToClipboard: {
|
|
9
|
+
(props: Omit<AssetPropsWithChildren<CopyToClipboardAsset>, "binding"> & {
|
|
10
|
+
/** The binding */
|
|
11
|
+
binding?: BindingTemplateInstance;
|
|
12
|
+
}): React.JSX.Element;
|
|
13
|
+
Label: (props: {
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
}) => React.JSX.Element;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TransformFunction } from "@player-ui/player";
|
|
2
|
+
import { CopyToClipboardAsset, TransformedCopyToClipboard } 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 copyToClipboardTransform: TransformFunction<CopyToClipboardAsset, TransformedCopyToClipboard>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Asset, AssetWrapper } from "@player-ui/types";
|
|
2
|
+
export interface CopyToClipboardAsset extends Asset<"copy-to-clipboard"> {
|
|
3
|
+
/** Binding to the data to be copied */
|
|
4
|
+
binding?: string;
|
|
5
|
+
/** Button Label */
|
|
6
|
+
label?: AssetWrapper;
|
|
7
|
+
}
|
|
8
|
+
/** A stateful instance of the asset */
|
|
9
|
+
export interface TransformedCopyToClipboard extends CopyToClipboardAsset {
|
|
10
|
+
/** The stringified data to be copied */
|
|
11
|
+
data: string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|