@devtools-ui/flame-graph 0.2.0--canary.25.1169

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,87 @@
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/flame-graph/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ FlameGraph: () => FlameGraph2,
34
+ FlameGraphComponent: () => FlameGraphComponent,
35
+ flameGraphTransform: () => flameGraphTransform
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
39
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx
40
+ var import_react = __toESM(require("react"));
41
+ var import_react_flame_graph = require("react-flame-graph");
42
+
43
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/hooks/index.ts
44
+ var transformData = (data) => ({
45
+ name: data?.name || "root",
46
+ value: data?.value || 0,
47
+ ...data?.tooltip && { tooltip: data.tooltip },
48
+ children: data?.children?.map(transformData) || []
49
+ });
50
+ var useFlameGraphProps = (props) => ({
51
+ ...props,
52
+ height: props.height || 500,
53
+ width: props.width || 500,
54
+ data: transformData(props.data)
55
+ });
56
+
57
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx
58
+ var FlameGraphComponent = (props) => {
59
+ const transformedProps = useFlameGraphProps(props);
60
+ return /* @__PURE__ */ import_react.default.createElement(import_react_flame_graph.FlameGraph, { ...transformedProps });
61
+ };
62
+
63
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/dsl/index.tsx
64
+ var import_react2 = __toESM(require("react"));
65
+ var import_dsl = require("@player-tools/dsl");
66
+ var FlameGraph2 = (props) => {
67
+ const { children, binding, ...rest } = props;
68
+ return /* @__PURE__ */ import_react2.default.createElement(import_dsl.Asset, { type: "flame-graph", ...rest }, /* @__PURE__ */ import_react2.default.createElement("property", { name: "binding" }, binding.toValue()), children);
69
+ };
70
+
71
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/transform/index.ts
72
+ var flameGraphTransform = (asset, options) => {
73
+ return {
74
+ ...asset,
75
+ data: asset.binding ? options.data.model.get(asset.binding, {
76
+ includeInvalid: true,
77
+ formatted: false
78
+ }) : void 0
79
+ };
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ FlameGraph,
84
+ FlameGraphComponent,
85
+ flameGraphTransform
86
+ });
87
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/hooks/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/dsl/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./component\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import React from \"react\";\nimport { FlameGraph } from \"react-flame-graph\";\nimport { useFlameGraphProps } from \"../hooks\";\nimport type { TransformedFlameGraph } from \"../types\";\n\nexport const FlameGraphComponent = (props: TransformedFlameGraph) => {\n const transformedProps = useFlameGraphProps(props);\n\n return <FlameGraph {...transformedProps} />;\n};\n","import type { Props } from \"react-flame-graph\";\nimport type { TransformedFlameGraph } from \"../types\";\n\nconst transformData = (data: TransformedFlameGraph[\"data\"]): Props[\"data\"] => ({\n name: data?.name || \"root\",\n value: data?.value || 0,\n ...(data?.tooltip && { tooltip: data.tooltip }),\n children: data?.children?.map(transformData) || [],\n});\n\n/**\n * Hook to translate the properties we get from the Player Content (DSL > JSON > transformer)\n * into what the FlameGraph component expects.\n */\nexport const useFlameGraphProps = (props: TransformedFlameGraph): Props => ({\n ...props,\n height: props.height || 500,\n width: props.width || 500,\n data: transformData(props.data),\n});\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { FlameGraphAsset } 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 FlameGraph = (\n props: Omit<AssetPropsWithChildren<FlameGraphAsset>, \"binding\"> & {\n /** The binding as a tagged template instance */\n binding: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n\n return (\n <Asset type=\"flame-graph\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { FlameGraphAsset, TransformedFlameGraph } 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 flameGraphTransform: TransformFunction<\n FlameGraphAsset,\n TransformedFlameGraph\n> = (asset, options) => {\n return {\n ...asset,\n data: asset.binding\n ? options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n })\n : undefined,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAClB,+BAA2B;;;ACE3B,IAAM,gBAAgB,CAAC,UAAwD;AAAA,EAC7E,MAAM,MAAM,QAAQ;AAAA,EACpB,OAAO,MAAM,SAAS;AAAA,EACtB,GAAI,MAAM,WAAW,EAAE,SAAS,KAAK,QAAQ;AAAA,EAC7C,UAAU,MAAM,UAAU,IAAI,aAAa,KAAK,CAAC;AACnD;AAMO,IAAM,qBAAqB,CAAC,WAAyC;AAAA,EAC1E,GAAG;AAAA,EACH,QAAQ,MAAM,UAAU;AAAA,EACxB,OAAO,MAAM,SAAS;AAAA,EACtB,MAAM,cAAc,MAAM,IAAI;AAChC;;;ADdO,IAAM,sBAAsB,CAAC,UAAiC;AACnE,QAAM,mBAAmB,mBAAmB,KAAK;AAEjD,SAAO,6BAAAC,QAAA,cAAC,uCAAY,GAAG,kBAAkB;AAC3C;;;AETA,IAAAC,gBAAkB;AAClB,iBAIO;AAOA,IAAMC,cAAa,CACxB,UAIG;AACH,QAAM,EAAE,UAAU,SAAS,GAAG,KAAK,IAAI;AAEvC,SACE,8BAAAC,QAAA,cAAC,oBAAM,MAAK,eAAe,GAAG,QAC5B,8BAAAA,QAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GAC3C,QACH;AAEJ;;;ACnBO,IAAM,sBAGT,CAAC,OAAO,YAAY;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM,MAAM,UACR,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC,IACD;AAAA,EACN;AACF;","names":["FlameGraph","React","import_react","FlameGraph","React"]}
@@ -0,0 +1,50 @@
1
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx
2
+ import React from "react";
3
+ import { FlameGraph } from "react-flame-graph";
4
+
5
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/hooks/index.ts
6
+ var transformData = (data) => ({
7
+ name: data?.name || "root",
8
+ value: data?.value || 0,
9
+ ...data?.tooltip && { tooltip: data.tooltip },
10
+ children: data?.children?.map(transformData) || []
11
+ });
12
+ var useFlameGraphProps = (props) => ({
13
+ ...props,
14
+ height: props.height || 500,
15
+ width: props.width || 500,
16
+ data: transformData(props.data)
17
+ });
18
+
19
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx
20
+ var FlameGraphComponent = (props) => {
21
+ const transformedProps = useFlameGraphProps(props);
22
+ return /* @__PURE__ */ React.createElement(FlameGraph, { ...transformedProps });
23
+ };
24
+
25
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/dsl/index.tsx
26
+ import React2 from "react";
27
+ import {
28
+ Asset
29
+ } from "@player-tools/dsl";
30
+ var FlameGraph2 = (props) => {
31
+ const { children, binding, ...rest } = props;
32
+ return /* @__PURE__ */ React2.createElement(Asset, { type: "flame-graph", ...rest }, /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
33
+ };
34
+
35
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/transform/index.ts
36
+ var flameGraphTransform = (asset, options) => {
37
+ return {
38
+ ...asset,
39
+ data: asset.binding ? options.data.model.get(asset.binding, {
40
+ includeInvalid: true,
41
+ formatted: false
42
+ }) : void 0
43
+ };
44
+ };
45
+ export {
46
+ FlameGraph2 as FlameGraph,
47
+ FlameGraphComponent,
48
+ flameGraphTransform
49
+ };
50
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,50 @@
1
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx
2
+ import React from "react";
3
+ import { FlameGraph } from "react-flame-graph";
4
+
5
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/hooks/index.ts
6
+ var transformData = (data) => ({
7
+ name: data?.name || "root",
8
+ value: data?.value || 0,
9
+ ...data?.tooltip && { tooltip: data.tooltip },
10
+ children: data?.children?.map(transformData) || []
11
+ });
12
+ var useFlameGraphProps = (props) => ({
13
+ ...props,
14
+ height: props.height || 500,
15
+ width: props.width || 500,
16
+ data: transformData(props.data)
17
+ });
18
+
19
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx
20
+ var FlameGraphComponent = (props) => {
21
+ const transformedProps = useFlameGraphProps(props);
22
+ return /* @__PURE__ */ React.createElement(FlameGraph, { ...transformedProps });
23
+ };
24
+
25
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/dsl/index.tsx
26
+ import React2 from "react";
27
+ import {
28
+ Asset
29
+ } from "@player-tools/dsl";
30
+ var FlameGraph2 = (props) => {
31
+ const { children, binding, ...rest } = props;
32
+ return /* @__PURE__ */ React2.createElement(Asset, { type: "flame-graph", ...rest }, /* @__PURE__ */ React2.createElement("property", { name: "binding" }, binding.toValue()), children);
33
+ };
34
+
35
+ // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/transform/index.ts
36
+ var flameGraphTransform = (asset, options) => {
37
+ return {
38
+ ...asset,
39
+ data: asset.binding ? options.data.model.get(asset.binding, {
40
+ includeInvalid: true,
41
+ formatted: false
42
+ }) : void 0
43
+ };
44
+ };
45
+ export {
46
+ FlameGraph2 as FlameGraph,
47
+ FlameGraphComponent,
48
+ flameGraphTransform
49
+ };
50
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/component/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/hooks/index.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/dsl/index.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/flame-graph/src/transform/index.ts"],"sourcesContent":["import React from \"react\";\nimport { FlameGraph } from \"react-flame-graph\";\nimport { useFlameGraphProps } from \"../hooks\";\nimport type { TransformedFlameGraph } from \"../types\";\n\nexport const FlameGraphComponent = (props: TransformedFlameGraph) => {\n const transformedProps = useFlameGraphProps(props);\n\n return <FlameGraph {...transformedProps} />;\n};\n","import type { Props } from \"react-flame-graph\";\nimport type { TransformedFlameGraph } from \"../types\";\n\nconst transformData = (data: TransformedFlameGraph[\"data\"]): Props[\"data\"] => ({\n name: data?.name || \"root\",\n value: data?.value || 0,\n ...(data?.tooltip && { tooltip: data.tooltip }),\n children: data?.children?.map(transformData) || [],\n});\n\n/**\n * Hook to translate the properties we get from the Player Content (DSL > JSON > transformer)\n * into what the FlameGraph component expects.\n */\nexport const useFlameGraphProps = (props: TransformedFlameGraph): Props => ({\n ...props,\n height: props.height || 500,\n width: props.width || 500,\n data: transformData(props.data),\n});\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport type { FlameGraphAsset } 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 FlameGraph = (\n props: Omit<AssetPropsWithChildren<FlameGraphAsset>, \"binding\"> & {\n /** The binding as a tagged template instance */\n binding: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n\n return (\n <Asset type=\"flame-graph\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { FlameGraphAsset, TransformedFlameGraph } 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 flameGraphTransform: TransformFunction<\n FlameGraphAsset,\n TransformedFlameGraph\n> = (asset, options) => {\n return {\n ...asset,\n data: asset.binding\n ? options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: false,\n })\n : undefined,\n };\n};\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,SAAS,kBAAkB;;;ACE3B,IAAM,gBAAgB,CAAC,UAAwD;AAAA,EAC7E,MAAM,MAAM,QAAQ;AAAA,EACpB,OAAO,MAAM,SAAS;AAAA,EACtB,GAAI,MAAM,WAAW,EAAE,SAAS,KAAK,QAAQ;AAAA,EAC7C,UAAU,MAAM,UAAU,IAAI,aAAa,KAAK,CAAC;AACnD;AAMO,IAAM,qBAAqB,CAAC,WAAyC;AAAA,EAC1E,GAAG;AAAA,EACH,QAAQ,MAAM,UAAU;AAAA,EACxB,OAAO,MAAM,SAAS;AAAA,EACtB,MAAM,cAAc,MAAM,IAAI;AAChC;;;ADdO,IAAM,sBAAsB,CAAC,UAAiC;AACnE,QAAM,mBAAmB,mBAAmB,KAAK;AAEjD,SAAO,oCAAC,cAAY,GAAG,kBAAkB;AAC3C;;;AETA,OAAOA,YAAW;AAClB;AAAA,EAEE;AAAA,OAEK;AAOA,IAAMC,cAAa,CACxB,UAIG;AACH,QAAM,EAAE,UAAU,SAAS,GAAG,KAAK,IAAI;AAEvC,SACE,gBAAAD,OAAA,cAAC,SAAM,MAAK,eAAe,GAAG,QAC5B,gBAAAA,OAAA,cAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GAC3C,QACH;AAEJ;;;ACnBO,IAAM,sBAGT,CAAC,OAAO,YAAY;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM,MAAM,UACR,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC,IACD;AAAA,EACN;AACF;","names":["React","FlameGraph"]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@devtools-ui/flame-graph",
3
+ "version": "0.2.0--canary.25.1169",
4
+ "main": "dist/cjs/index.cjs",
5
+ "module": "dist/index.legacy-esm.js",
6
+ "types": "types/index.d.ts",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ "./dist/index.css": "./dist/index.css",
11
+ ".": {
12
+ "types": "./types/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "default": "./dist/cjs/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "types"
21
+ ],
22
+ "dependencies": {
23
+ "@chakra-ui/react": "^2.8.2",
24
+ "@emotion/react": "^11.11.4",
25
+ "@emotion/styled": "^11.11.0",
26
+ "@player-tools/dsl": "0.6.0-next.2",
27
+ "@player-ui/asset-transform-plugin": "0.7.3",
28
+ "@player-ui/player": "0.7.3",
29
+ "@player-ui/react": "0.7.3",
30
+ "@player-ui/types": "0.7.3",
31
+ "@types/react": "^18.2.51",
32
+ "dlv": "^1.1.3",
33
+ "framer-motion": "^11.0.8",
34
+ "react": "^18.2.0",
35
+ "react-flame-graph": "^1.4.0",
36
+ "tslib": "^2.6.2"
37
+ },
38
+ "peerDependencies": {}
39
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { FlameGraph } from "react-flame-graph";
3
+ import { useFlameGraphProps } from "../hooks";
4
+ import type { TransformedFlameGraph } from "../types";
5
+
6
+ export const FlameGraphComponent = (props: TransformedFlameGraph) => {
7
+ const transformedProps = useFlameGraphProps(props);
8
+
9
+ return <FlameGraph {...transformedProps} />;
10
+ };
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import { describe, expect, test } from "vitest";
3
+ import { render, binding as b } from "@player-tools/dsl";
4
+ import { FlameGraph } from "../";
5
+
6
+ describe("DSL: FlameGraph", () => {
7
+ test("Renders flameGraph", async () => {
8
+ const rendered = await render(
9
+ <FlameGraph binding={b`my_binding`} height={100} width={200} />
10
+ );
11
+
12
+ expect(rendered.jsonValue).toStrictEqual({
13
+ id: "root",
14
+ type: "flame-graph",
15
+ binding: "my_binding",
16
+ height: 100,
17
+ width: 200,
18
+ });
19
+ });
20
+ });
@@ -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 { FlameGraphAsset } 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 FlameGraph = (
14
+ props: Omit<AssetPropsWithChildren<FlameGraphAsset>, "binding"> & {
15
+ /** The binding as a tagged template instance */
16
+ binding: BindingTemplateInstance;
17
+ }
18
+ ) => {
19
+ const { children, binding, ...rest } = props;
20
+
21
+ return (
22
+ <Asset type="flame-graph" {...rest}>
23
+ <property name="binding">{binding.toValue()}</property>
24
+ {children}
25
+ </Asset>
26
+ );
27
+ };
@@ -0,0 +1,67 @@
1
+ import { useFlameGraphProps } from "..";
2
+ import { describe, expect, test } from "vitest";
3
+ import type { ProfilerNode, TransformedFlameGraph } from "../../types";
4
+
5
+ const data: ProfilerNode = {
6
+ name: "root",
7
+ value: 5,
8
+ tooltip: "tooltip",
9
+ children: [
10
+ {
11
+ name: "child1",
12
+ value: 5,
13
+ children: [
14
+ { name: "child1.1", value: 2, children: [] },
15
+ { name: "child1.2", value: 3, children: [] },
16
+ ],
17
+ },
18
+ { name: "child2", children: [] },
19
+ ],
20
+ };
21
+
22
+ const mockProps: TransformedFlameGraph = {
23
+ id: "test",
24
+ type: "flame-graph",
25
+ data,
26
+ };
27
+
28
+ describe("useFlameGraphProps", () => {
29
+ test("transforms data correctly", () => {
30
+ const result = useFlameGraphProps(mockProps);
31
+
32
+ expect(result.data).toStrictEqual({
33
+ name: "root",
34
+ value: 5,
35
+ tooltip: "tooltip",
36
+ children: [
37
+ {
38
+ name: "child1",
39
+ value: 5,
40
+ children: [
41
+ { name: "child1.1", value: 2, children: [] },
42
+ { name: "child1.2", value: 3, children: [] },
43
+ ],
44
+ },
45
+ { name: "child2", value: 0, children: [] },
46
+ ],
47
+ });
48
+ });
49
+
50
+ test("returns default height and width when not provided", () => {
51
+ const result = useFlameGraphProps(mockProps);
52
+
53
+ expect(result.height).toBe(500);
54
+ expect(result.width).toBe(500);
55
+ });
56
+
57
+ test("returns provided height and width", () => {
58
+ const result = useFlameGraphProps({
59
+ ...mockProps,
60
+ height: 300,
61
+ width: 300,
62
+ });
63
+
64
+ expect(result.height).toBe(300);
65
+ expect(result.width).toBe(300);
66
+ });
67
+ });
@@ -0,0 +1,20 @@
1
+ import type { Props } from "react-flame-graph";
2
+ import type { TransformedFlameGraph } from "../types";
3
+
4
+ const transformData = (data: TransformedFlameGraph["data"]): Props["data"] => ({
5
+ name: data?.name || "root",
6
+ value: data?.value || 0,
7
+ ...(data?.tooltip && { tooltip: data.tooltip }),
8
+ children: data?.children?.map(transformData) || [],
9
+ });
10
+
11
+ /**
12
+ * Hook to translate the properties we get from the Player Content (DSL > JSON > transformer)
13
+ * into what the FlameGraph component expects.
14
+ */
15
+ export const useFlameGraphProps = (props: TransformedFlameGraph): Props => ({
16
+ ...props,
17
+ height: props.height || 500,
18
+ width: props.width || 500,
19
+ data: transformData(props.data),
20
+ });
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,21 @@
1
+ import type { TransformFunction } from "@player-ui/player";
2
+ import { FlameGraphAsset, TransformedFlameGraph } 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 flameGraphTransform: TransformFunction<
9
+ FlameGraphAsset,
10
+ TransformedFlameGraph
11
+ > = (asset, options) => {
12
+ return {
13
+ ...asset,
14
+ data: asset.binding
15
+ ? options.data.model.get(asset.binding, {
16
+ includeInvalid: true,
17
+ formatted: false,
18
+ })
19
+ : undefined,
20
+ };
21
+ };
@@ -0,0 +1,31 @@
1
+ import type { Asset } from "@player-ui/types";
2
+
3
+ export type ProfilerNode = {
4
+ /** hook name */
5
+ name: string;
6
+ /* startTime of the hook */
7
+ startTime?: number;
8
+ /** endTime of the hook */
9
+ endTime?: number;
10
+ /** duration of hook resolution times in ms */
11
+ value?: number;
12
+ /** tooltip to be shown on hover */
13
+ tooltip?: string;
14
+ /** subhook profiler nodes */
15
+ children: ProfilerNode[];
16
+ };
17
+
18
+ export interface FlameGraphAsset extends Asset<"flame-graph"> {
19
+ /** Dot separated string Representation of a path within the data-model */
20
+ binding?: string;
21
+ /** height of the flame graph */
22
+ height?: number;
23
+ /** width of the flame graph */
24
+ width?: number;
25
+ }
26
+
27
+ /** A stateful instance of the asset */
28
+ export interface TransformedFlameGraph extends FlameGraphAsset {
29
+ // The result of the transformation (transform/index.ts)
30
+ data?: ProfilerNode;
31
+ }
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { TransformedFlameGraph } from "../types";
3
+ export declare const FlameGraphComponent: (props: TransformedFlameGraph) => React.JSX.Element;
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 { FlameGraphAsset } 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 FlameGraph: (props: Omit<AssetPropsWithChildren<FlameGraphAsset>, "binding"> & {
9
+ /** The binding as a tagged template instance */
10
+ binding: BindingTemplateInstance;
11
+ }) => React.JSX.Element;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { Props } from "react-flame-graph";
2
+ import type { TransformedFlameGraph } from "../types";
3
+ /**
4
+ * Hook to translate the properties we get from the Player Content (DSL > JSON > transformer)
5
+ * into what the FlameGraph component expects.
6
+ */
7
+ export declare const useFlameGraphProps: (props: TransformedFlameGraph) => Props;
8
+ //# 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 { FlameGraphAsset, TransformedFlameGraph } 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 flameGraphTransform: TransformFunction<FlameGraphAsset, TransformedFlameGraph>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,27 @@
1
+ import type { Asset } from "@player-ui/types";
2
+ export type ProfilerNode = {
3
+ /** hook name */
4
+ name: string;
5
+ startTime?: number;
6
+ /** endTime of the hook */
7
+ endTime?: number;
8
+ /** duration of hook resolution times in ms */
9
+ value?: number;
10
+ /** tooltip to be shown on hover */
11
+ tooltip?: string;
12
+ /** subhook profiler nodes */
13
+ children: ProfilerNode[];
14
+ };
15
+ export interface FlameGraphAsset extends Asset<"flame-graph"> {
16
+ /** Dot separated string Representation of a path within the data-model */
17
+ binding?: string;
18
+ /** height of the flame graph */
19
+ height?: number;
20
+ /** width of the flame graph */
21
+ width?: number;
22
+ }
23
+ /** A stateful instance of the asset */
24
+ export interface TransformedFlameGraph extends FlameGraphAsset {
25
+ data?: ProfilerNode;
26
+ }
27
+ //# sourceMappingURL=index.d.ts.map