@devtools-ui/table 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.
@@ -0,0 +1,106 @@
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/table/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Table: () => Table2,
34
+ TableComponent: () => TableComponent,
35
+ tableTransform: () => tableTransform
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
39
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/component/index.tsx
40
+ var import_react = require("@chakra-ui/react");
41
+ var import_react2 = __toESM(require("react"));
42
+ var useTablePros = (props) => {
43
+ const { rows } = props;
44
+ const parsedRows = rows.map(
45
+ (row) => Object.entries(row).reduce((acc, [key, value]) => {
46
+ if (key === "time") {
47
+ return {
48
+ ...acc,
49
+ [key]: new Date(value).toLocaleString()
50
+ };
51
+ }
52
+ if (value === null || value === void 0) {
53
+ return {
54
+ ...acc,
55
+ [key]: ""
56
+ };
57
+ }
58
+ if (typeof value === "object") {
59
+ return {
60
+ ...acc,
61
+ [key]: JSON.stringify(value)
62
+ };
63
+ }
64
+ return { ...acc, [key]: value };
65
+ }, {})
66
+ );
67
+ const headers = Array.from(new Set(rows.flatMap((row) => Object.keys(row))));
68
+ return {
69
+ ...props,
70
+ headers,
71
+ rows: parsedRows
72
+ };
73
+ };
74
+ var TableComponent = (props) => {
75
+ const { headers, rows } = useTablePros(props);
76
+ if (!rows.length) {
77
+ return null;
78
+ }
79
+ return /* @__PURE__ */ import_react2.default.createElement(import_react.TableContainer, null, /* @__PURE__ */ import_react2.default.createElement(import_react.Table, { variant: "simple" }, /* @__PURE__ */ import_react2.default.createElement(import_react.Thead, null, /* @__PURE__ */ import_react2.default.createElement(import_react.Tr, null, headers.map((key) => /* @__PURE__ */ import_react2.default.createElement(import_react.Th, { key }, key)))), /* @__PURE__ */ import_react2.default.createElement(import_react.Tbody, null, rows.map((row, index) => /* @__PURE__ */ import_react2.default.createElement(import_react.Tr, { key: index }, headers.map((key) => /* @__PURE__ */ import_react2.default.createElement(import_react.Td, { key }, row[key] ?? "")))))));
80
+ };
81
+
82
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/dsl/index.tsx
83
+ var import_react3 = __toESM(require("react"));
84
+ var import_dsl = require("@player-tools/dsl");
85
+ var Table2 = (props) => {
86
+ const { binding, children, ...rest } = props;
87
+ return /* @__PURE__ */ import_react3.default.createElement(import_dsl.Asset, { type: "table", ...rest }, binding && /* @__PURE__ */ import_react3.default.createElement("property", { name: "binding" }, binding.toValue()), children);
88
+ };
89
+
90
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/transform/index.ts
91
+ var tableTransform = (asset, options) => {
92
+ return {
93
+ ...asset,
94
+ rows: asset.binding === void 0 ? [] : options.data.model.get(asset.binding, {
95
+ includeInvalid: true,
96
+ formatted: false
97
+ })
98
+ };
99
+ };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ Table,
103
+ TableComponent,
104
+ tableTransform
105
+ });
106
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/component/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/dsl/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./component\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import {\n Table,\n TableContainer,\n Tbody,\n Td,\n Th,\n Thead,\n Tr,\n} from \"@chakra-ui/react\";\nimport React from \"react\";\nimport type { TransformedTable } from \"../types\";\n\n/**\n * Hook to convert the data we get from the Player Content into the properties our component expects:\n */\nconst useTablePros = (props: TransformedTable) => {\n // Translate the properties we get from the Player Content (DSL > JSON > transformer)\n // into what the elements that compose your component expect (platform-specific, for\n // platform-agnostic transformations, see the transformer):\n\n const { rows } = props;\n\n const parsedRows = rows.map((row) =>\n Object.entries(row).reduce((acc, [key, value]) => {\n if (key === \"time\") {\n return {\n ...acc,\n [key]: new Date(value).toLocaleString(),\n };\n }\n\n if (value === null || value === undefined) {\n return {\n ...acc,\n [key]: \"\",\n };\n }\n\n if (typeof value === \"object\") {\n return {\n ...acc,\n [key]: JSON.stringify(value),\n };\n }\n\n return { ...acc, [key]: value };\n }, {} as Record<string, string>)\n );\n\n // Get the keys to use as column headers (checking all the rows for cases where we have different keys):\n const headers = Array.from(new Set(rows.flatMap((row) => Object.keys(row))));\n\n return {\n ...props,\n headers,\n rows: parsedRows,\n } as const;\n};\n\nexport const TableComponent = (props: TransformedTable) => {\n const { headers, rows } = useTablePros(props);\n\n if (!rows.length) {\n return null;\n }\n\n return (\n <TableContainer>\n <Table variant=\"simple\">\n <Thead>\n <Tr>\n {headers.map((key) => (\n <Th key={key}>{key}</Th>\n ))}\n </Tr>\n </Thead>\n <Tbody>\n {rows.map((row, index) => (\n <Tr key={index}>\n {headers.map((key) => (\n <Td key={key}>{row[key] ?? \"\"}</Td>\n ))}\n </Tr>\n ))}\n </Tbody>\n </Table>\n </TableContainer>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { TableAsset } 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 Table = (\n props: Omit<AssetPropsWithChildren<TableAsset>, \"binding\"> & {\n /** The binding */\n binding?: BindingTemplateInstance;\n }\n) => {\n const { binding, children, ...rest } = props;\n\n return (\n <Asset type=\"table\" {...rest}>\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\n {children}\n </Asset>\n );\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { TableAsset, TransformedTable } 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 tableTransform: TransformFunction<TableAsset, TransformedTable> = (\n asset,\n options\n) => {\n return {\n ...asset,\n rows:\n asset.binding === undefined\n ? []\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,eAAAA;AAAA,EAAA;AAAA;AAAA;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GACA,8BAAAA,QAAA,cAAC,0BACE,KAAK,IAAI,CAAC,KAAK,UACd,8BAAAA,QAAA,cAAC,mBAAG,KAAK,SACN,QAAQ,IAAI,CAAC,QACZ,8BAAAA,QAAA,cAAC,mBAAG,OAAW,IAAI,GAAG,KAAK,EAAG,CAC/B,CACH,CACD,CACH,CACF,CACF;AAEJ;;;ACxFA,IAAAC,gBAAkB;AAClB,iBAIO;AAOA,IAAMC,SAAQ,CACnB,UAIG;AACH,QAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI;AAEvC,SACE,8BAAAC,QAAA,cAAC,oBAAM,MAAK,SAAS,GAAG,QACrB,WAAW,8BAAAA,QAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GACvD,QACH;AAEJ;;;ACnBO,IAAM,iBAAkE,CAC7E,OACA,YACG;AACH,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MACE,MAAM,YAAY,SACd,CAAC,IACD,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,EACT;AACF;","names":["Table","import_react","React","import_react","Table","React"]}
@@ -0,0 +1,77 @@
1
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/component/index.tsx
2
+ import {
3
+ Table,
4
+ TableContainer,
5
+ Tbody,
6
+ Td,
7
+ Th,
8
+ Thead,
9
+ Tr
10
+ } from "@chakra-ui/react";
11
+ import React from "react";
12
+ var useTablePros = (props) => {
13
+ const { rows } = props;
14
+ const parsedRows = rows.map(
15
+ (row) => Object.entries(row).reduce((acc, [key, value]) => {
16
+ if (key === "time") {
17
+ return {
18
+ ...acc,
19
+ [key]: new Date(value).toLocaleString()
20
+ };
21
+ }
22
+ if (value === null || value === void 0) {
23
+ return {
24
+ ...acc,
25
+ [key]: ""
26
+ };
27
+ }
28
+ if (typeof value === "object") {
29
+ return {
30
+ ...acc,
31
+ [key]: JSON.stringify(value)
32
+ };
33
+ }
34
+ return { ...acc, [key]: value };
35
+ }, {})
36
+ );
37
+ const headers = Array.from(new Set(rows.flatMap((row) => Object.keys(row))));
38
+ return {
39
+ ...props,
40
+ headers,
41
+ rows: parsedRows
42
+ };
43
+ };
44
+ var TableComponent = (props) => {
45
+ const { headers, rows } = useTablePros(props);
46
+ if (!rows.length) {
47
+ return null;
48
+ }
49
+ return /* @__PURE__ */ React.createElement(TableContainer, null, /* @__PURE__ */ React.createElement(Table, { variant: "simple" }, /* @__PURE__ */ React.createElement(Thead, null, /* @__PURE__ */ React.createElement(Tr, null, headers.map((key) => /* @__PURE__ */ React.createElement(Th, { key }, key)))), /* @__PURE__ */ React.createElement(Tbody, null, rows.map((row, index) => /* @__PURE__ */ React.createElement(Tr, { key: index }, headers.map((key) => /* @__PURE__ */ React.createElement(Td, { key }, row[key] ?? "")))))));
50
+ };
51
+
52
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/dsl/index.tsx
53
+ import React2 from "react";
54
+ import {
55
+ Asset
56
+ } from "@player-tools/dsl";
57
+ var Table2 = (props) => {
58
+ const { binding, children, ...rest } = props;
59
+ return /* @__PURE__ */ React2.createElement(Asset, { type: "table", ...rest }, binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
60
+ };
61
+
62
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/transform/index.ts
63
+ var tableTransform = (asset, options) => {
64
+ return {
65
+ ...asset,
66
+ rows: asset.binding === void 0 ? [] : options.data.model.get(asset.binding, {
67
+ includeInvalid: true,
68
+ formatted: false
69
+ })
70
+ };
71
+ };
72
+ export {
73
+ Table2 as Table,
74
+ TableComponent,
75
+ tableTransform
76
+ };
77
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,77 @@
1
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/component/index.tsx
2
+ import {
3
+ Table,
4
+ TableContainer,
5
+ Tbody,
6
+ Td,
7
+ Th,
8
+ Thead,
9
+ Tr
10
+ } from "@chakra-ui/react";
11
+ import React from "react";
12
+ var useTablePros = (props) => {
13
+ const { rows } = props;
14
+ const parsedRows = rows.map(
15
+ (row) => Object.entries(row).reduce((acc, [key, value]) => {
16
+ if (key === "time") {
17
+ return {
18
+ ...acc,
19
+ [key]: new Date(value).toLocaleString()
20
+ };
21
+ }
22
+ if (value === null || value === void 0) {
23
+ return {
24
+ ...acc,
25
+ [key]: ""
26
+ };
27
+ }
28
+ if (typeof value === "object") {
29
+ return {
30
+ ...acc,
31
+ [key]: JSON.stringify(value)
32
+ };
33
+ }
34
+ return { ...acc, [key]: value };
35
+ }, {})
36
+ );
37
+ const headers = Array.from(new Set(rows.flatMap((row) => Object.keys(row))));
38
+ return {
39
+ ...props,
40
+ headers,
41
+ rows: parsedRows
42
+ };
43
+ };
44
+ var TableComponent = (props) => {
45
+ const { headers, rows } = useTablePros(props);
46
+ if (!rows.length) {
47
+ return null;
48
+ }
49
+ return /* @__PURE__ */ React.createElement(TableContainer, null, /* @__PURE__ */ React.createElement(Table, { variant: "simple" }, /* @__PURE__ */ React.createElement(Thead, null, /* @__PURE__ */ React.createElement(Tr, null, headers.map((key) => /* @__PURE__ */ React.createElement(Th, { key }, key)))), /* @__PURE__ */ React.createElement(Tbody, null, rows.map((row, index) => /* @__PURE__ */ React.createElement(Tr, { key: index }, headers.map((key) => /* @__PURE__ */ React.createElement(Td, { key }, row[key] ?? "")))))));
50
+ };
51
+
52
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/dsl/index.tsx
53
+ import React2 from "react";
54
+ import {
55
+ Asset
56
+ } from "@player-tools/dsl";
57
+ var Table2 = (props) => {
58
+ const { binding, children, ...rest } = props;
59
+ return /* @__PURE__ */ React2.createElement(Asset, { type: "table", ...rest }, binding && /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
60
+ };
61
+
62
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/transform/index.ts
63
+ var tableTransform = (asset, options) => {
64
+ return {
65
+ ...asset,
66
+ rows: asset.binding === void 0 ? [] : options.data.model.get(asset.binding, {
67
+ includeInvalid: true,
68
+ formatted: false
69
+ })
70
+ };
71
+ };
72
+ export {
73
+ Table2 as Table,
74
+ TableComponent,
75
+ tableTransform
76
+ };
77
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/component/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/dsl/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/table/src/transform/index.ts"],"sourcesContent":["import {\n Table,\n TableContainer,\n Tbody,\n Td,\n Th,\n Thead,\n Tr,\n} from \"@chakra-ui/react\";\nimport React from \"react\";\nimport type { TransformedTable } from \"../types\";\n\n/**\n * Hook to convert the data we get from the Player Content into the properties our component expects:\n */\nconst useTablePros = (props: TransformedTable) => {\n // Translate the properties we get from the Player Content (DSL > JSON > transformer)\n // into what the elements that compose your component expect (platform-specific, for\n // platform-agnostic transformations, see the transformer):\n\n const { rows } = props;\n\n const parsedRows = rows.map((row) =>\n Object.entries(row).reduce((acc, [key, value]) => {\n if (key === \"time\") {\n return {\n ...acc,\n [key]: new Date(value).toLocaleString(),\n };\n }\n\n if (value === null || value === undefined) {\n return {\n ...acc,\n [key]: \"\",\n };\n }\n\n if (typeof value === \"object\") {\n return {\n ...acc,\n [key]: JSON.stringify(value),\n };\n }\n\n return { ...acc, [key]: value };\n }, {} as Record<string, string>)\n );\n\n // Get the keys to use as column headers (checking all the rows for cases where we have different keys):\n const headers = Array.from(new Set(rows.flatMap((row) => Object.keys(row))));\n\n return {\n ...props,\n headers,\n rows: parsedRows,\n } as const;\n};\n\nexport const TableComponent = (props: TransformedTable) => {\n const { headers, rows } = useTablePros(props);\n\n if (!rows.length) {\n return null;\n }\n\n return (\n <TableContainer>\n <Table variant=\"simple\">\n <Thead>\n <Tr>\n {headers.map((key) => (\n <Th key={key}>{key}</Th>\n ))}\n </Tr>\n </Thead>\n <Tbody>\n {rows.map((row, index) => (\n <Tr key={index}>\n {headers.map((key) => (\n <Td key={key}>{row[key] ?? \"\"}</Td>\n ))}\n </Tr>\n ))}\n </Tbody>\n </Table>\n </TableContainer>\n );\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { TableAsset } 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 Table = (\n props: Omit<AssetPropsWithChildren<TableAsset>, \"binding\"> & {\n /** The binding */\n binding?: BindingTemplateInstance;\n }\n) => {\n const { binding, children, ...rest } = props;\n\n return (\n <Asset type=\"table\" {...rest}>\n {binding && <property name=\"binding\">{binding.toValue()}</property>}\n {children}\n </Asset>\n );\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { TableAsset, TransformedTable } 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 tableTransform: TransformFunction<TableAsset, TransformedTable> = (\n asset,\n options\n) => {\n return {\n ...asset,\n rows:\n asset.binding === undefined\n ? []\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n }),\n };\n};\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,WAAW;AAMlB,IAAM,eAAe,CAAC,UAA4B;AAKhD,QAAM,EAAE,KAAK,IAAI;AAEjB,QAAM,aAAa,KAAK;AAAA,IAAI,CAAC,QAC3B,OAAO,QAAQ,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,K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,UAAU,GAAG,KAAK,IAAI;AAEvC,SACE,gBAAAD,OAAA,cAAC,SAAM,MAAK,SAAS,GAAG,QACrB,WAAW,gBAAAA,OAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GACvD,QACH;AAEJ;;;ACnBO,IAAM,iBAAkE,CAC7E,OACA,YACG;AACH,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MACE,MAAM,YAAY,SACd,CAAC,IACD,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,EACT;AACF;","names":["React","Table"]}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@devtools-ui/table",
3
+ "version": "0.0.2--canary.11.588",
4
+ "main": "dist/cjs/index.cjs",
5
+ "dependencies": {
6
+ "@devtools-ui/text": "0.0.2--canary.11.588",
7
+ "@devtools-ui/collection": "0.0.2--canary.11.588",
8
+ "@chakra-ui/react": "^2.8.2",
9
+ "@emotion/react": "^11.11.4",
10
+ "@emotion/styled": "^11.11.0",
11
+ "@player-tools/dsl": "0.5.2--canary.87.2261",
12
+ "@player-ui/asset-transform-plugin": "^0.7.1",
13
+ "@player-ui/player": "0.7.1",
14
+ "@player-ui/react": "^0.7.1",
15
+ "@player-ui/types": "0.7.1",
16
+ "@types/react": "^18.2.51",
17
+ "dlv": "^1.1.3",
18
+ "eslint-plugin-storybook": "^0.8.0",
19
+ "framer-motion": "^11.0.8",
20
+ "react": "^18.2.0",
21
+ "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,89 @@
1
+ import {
2
+ Table,
3
+ TableContainer,
4
+ Tbody,
5
+ Td,
6
+ Th,
7
+ Thead,
8
+ Tr,
9
+ } from "@chakra-ui/react";
10
+ import React from "react";
11
+ import type { TransformedTable } from "../types";
12
+
13
+ /**
14
+ * Hook to convert the data we get from the Player Content into the properties our component expects:
15
+ */
16
+ const useTablePros = (props: TransformedTable) => {
17
+ // Translate the properties we get from the Player Content (DSL > JSON > transformer)
18
+ // into what the elements that compose your component expect (platform-specific, for
19
+ // platform-agnostic transformations, see the transformer):
20
+
21
+ const { rows } = props;
22
+
23
+ const parsedRows = rows.map((row) =>
24
+ Object.entries(row).reduce((acc, [key, value]) => {
25
+ if (key === "time") {
26
+ return {
27
+ ...acc,
28
+ [key]: new Date(value).toLocaleString(),
29
+ };
30
+ }
31
+
32
+ if (value === null || value === undefined) {
33
+ return {
34
+ ...acc,
35
+ [key]: "",
36
+ };
37
+ }
38
+
39
+ if (typeof value === "object") {
40
+ return {
41
+ ...acc,
42
+ [key]: JSON.stringify(value),
43
+ };
44
+ }
45
+
46
+ return { ...acc, [key]: value };
47
+ }, {} as Record<string, string>)
48
+ );
49
+
50
+ // Get the keys to use as column headers (checking all the rows for cases where we have different keys):
51
+ const headers = Array.from(new Set(rows.flatMap((row) => Object.keys(row))));
52
+
53
+ return {
54
+ ...props,
55
+ headers,
56
+ rows: parsedRows,
57
+ } as const;
58
+ };
59
+
60
+ export const TableComponent = (props: TransformedTable) => {
61
+ const { headers, rows } = useTablePros(props);
62
+
63
+ if (!rows.length) {
64
+ return null;
65
+ }
66
+
67
+ return (
68
+ <TableContainer>
69
+ <Table variant="simple">
70
+ <Thead>
71
+ <Tr>
72
+ {headers.map((key) => (
73
+ <Th key={key}>{key}</Th>
74
+ ))}
75
+ </Tr>
76
+ </Thead>
77
+ <Tbody>
78
+ {rows.map((row, index) => (
79
+ <Tr key={index}>
80
+ {headers.map((key) => (
81
+ <Td key={key}>{row[key] ?? ""}</Td>
82
+ ))}
83
+ </Tr>
84
+ ))}
85
+ </Tbody>
86
+ </Table>
87
+ </TableContainer>
88
+ );
89
+ };
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import { describe, expect, test } from "vitest";
3
+ import { render, binding as b } from "@player-tools/dsl";
4
+ import { Table } from "../";
5
+
6
+ describe("DSL: Table", () => {
7
+ test("Renders table", async () => {
8
+ const rendered = await render(<Table binding={b`my_binding`} />);
9
+
10
+ expect(rendered.jsonValue).toStrictEqual({
11
+ id: "root",
12
+ type: "table",
13
+ binding: "my_binding",
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import {
3
+ AssetPropsWithChildren,
4
+ Asset,
5
+ BindingTemplateInstance,
6
+ } from "@player-tools/dsl";
7
+ import type { TableAsset } from "../types";
8
+
9
+ /**
10
+ * Defines the component DSL representation, so users of this plugin can author Player-UI
11
+ * content leveraging .jsx/.tsx syntax.
12
+ */
13
+ export const Table = (
14
+ props: Omit<AssetPropsWithChildren<TableAsset>, "binding"> & {
15
+ /** The binding */
16
+ binding?: BindingTemplateInstance;
17
+ }
18
+ ) => {
19
+ const { binding, children, ...rest } = props;
20
+
21
+ return (
22
+ <Asset type="table" {...rest}>
23
+ {binding && <property name="binding">{binding.toValue()}</property>}
24
+ {children}
25
+ </Asset>
26
+ );
27
+ };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./component";
3
+ export * from "./dsl";
4
+ export * from "./transform";
@@ -0,0 +1,22 @@
1
+ import type { TransformFunction } from "@player-ui/player";
2
+ import { TableAsset, TransformedTable } 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 tableTransform: TransformFunction<TableAsset, TransformedTable> = (
9
+ asset,
10
+ options
11
+ ) => {
12
+ return {
13
+ ...asset,
14
+ rows:
15
+ asset.binding === undefined
16
+ ? []
17
+ : options.data.model.get(asset.binding, {
18
+ includeInvalid: true,
19
+ formatted: false,
20
+ }),
21
+ };
22
+ };
@@ -0,0 +1,12 @@
1
+ import type { Asset } from "@player-ui/types";
2
+
3
+ export interface TableAsset extends Asset<"table"> {
4
+ /** Binding */
5
+ binding?: string;
6
+ }
7
+
8
+ /** A stateful instance of the asset */
9
+ export interface TransformedTable extends TableAsset {
10
+ /** The result of the transformation (transform/index.ts) */
11
+ rows: Array<Record<string, string>>;
12
+ }
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { TransformedTable } from "../types";
3
+ export declare const TableComponent: (props: TransformedTable) => React.JSX.Element | null;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { AssetPropsWithChildren, BindingTemplateInstance } from "@player-tools/dsl";
3
+ import type { TableAsset } 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 Table: (props: Omit<AssetPropsWithChildren<TableAsset>, "binding"> & {
9
+ /** The binding */
10
+ binding?: BindingTemplateInstance;
11
+ }) => React.JSX.Element;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from "./types";
2
+ export * from "./component";
3
+ export * from "./dsl";
4
+ export * from "./transform";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { TransformFunction } from "@player-ui/player";
2
+ import { TableAsset, TransformedTable } 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 tableTransform: TransformFunction<TableAsset, TransformedTable>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { Asset } from "@player-ui/types";
2
+ export interface TableAsset extends Asset<"table"> {
3
+ /** Binding */
4
+ binding?: string;
5
+ }
6
+ /** A stateful instance of the asset */
7
+ export interface TransformedTable extends TableAsset {
8
+ /** The result of the transformation (transform/index.ts) */
9
+ rows: Array<Record<string, string>>;
10
+ }
11
+ //# sourceMappingURL=index.d.ts.map