Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions copy-to-clipboard/src/transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import type { TransformFunction } from "@player-ui/player";
import type { TransformFunction, Resolve } from "@player-ui/player";
import { CopyToClipboardAsset, TransformedCopyToClipboard } from "../types";

const getData = (
asset: CopyToClipboardAsset,
options: Resolve.NodeResolveOptions
): string => {
if (asset.binding === undefined) {
return "";
}
const obj = options.data.model.get(asset.binding, {
includeInvalid: true,
formatted: false,
});
return typeof obj === "string" ? obj : JSON.stringify(obj, null, 2);
};

/**
* Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)
* and embeds Player state and methods:
Expand All @@ -10,15 +24,5 @@ export const copyToClipboardTransform: TransformFunction<
TransformedCopyToClipboard
> = (asset, options) => ({
...asset,
data:
asset.binding === undefined
? ""
: JSON.stringify(
options.data.model.get(asset.binding, {
includeInvalid: true,
formatted: false,
}),
null,
2
),
data: getData(asset, options),
});