Skip to content

Commit

Permalink
[widgets] Add support for JavaScript script tag types (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
styu authored Nov 21, 2024
1 parent bbf4647 commit 7c13070
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .changeset/rude-spoons-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/widget-api.unstable": minor
"@osdk/widget-manifest-vite-plugin": minor
---

Change manifest to support script types for entrypoint JS
4 changes: 2 additions & 2 deletions packages/e2e.sandbox.todowidget/src/main.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export default defineConfig({
events: {
updateHeader: {
displayName: "Update header",
parameterIds: ["headerText"],
parameterUpdateIds: ["headerText"],
},
updateTodoItems: {
displayName: "Update todo items",
parameterIds: ["todoItems"],
parameterUpdateIds: ["todoItems"],
},
},
});
2 changes: 1 addition & 1 deletion packages/e2e.sandbox.todowidget/src/second.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Config = defineConfig({
events: {
updateHeader: {
displayName: "Update header",
parameterIds: ["headerText"],
parameterUpdateIds: ["headerText"],
},
},
});
Expand Down
12 changes: 6 additions & 6 deletions packages/widget.api.unstable/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("WidgetConfig", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test"],
parameterUpdateIds: ["test"],
},
},
});
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("WidgetConfig", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test4"],
parameterUpdateIds: ["test4"],
},
},
});
Expand Down Expand Up @@ -210,11 +210,11 @@ describe("WidgetConfig", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test", "test2"],
parameterUpdateIds: ["test", "test2"],
},
myEvent2: {
displayName: "My second event",
parameterIds: [],
parameterUpdateIds: [],
},
},
});
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("WidgetConfig", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test", "test2"],
parameterUpdateIds: ["test", "test2"],
},
},
});
Expand Down Expand Up @@ -280,7 +280,7 @@ describe("WidgetConfig", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test", "test2"],
parameterUpdateIds: ["test", "test2"],
},
},
});
Expand Down
6 changes: 3 additions & 3 deletions packages/widget.api.unstable/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type ParameterDefinition =

export interface EventDefinition<P extends ParameterConfig> {
displayName: string;
parameterIds: Array<ParameterId<P>>;
parameterUpdateIds: Array<ParameterId<P>>;
}

export type ParameterConfig = Record<string, ParameterDefinition>;
Expand Down Expand Up @@ -107,8 +107,8 @@ export type EventId<C extends WidgetConfig<C["parameters"]>> =
export type EventParameterIdList<
C extends WidgetConfig<C["parameters"]>,
K extends EventId<C>,
> = C["events"][K]["parameterIds"] extends Array<ParameterId<C["parameters"]>>
? C["events"][K]["parameterIds"]
> = C["events"][K]["parameterUpdateIds"] extends
Array<ParameterId<C["parameters"]>> ? C["events"][K]["parameterUpdateIds"]
: never;

/**
Expand Down
13 changes: 11 additions & 2 deletions packages/widget.api.unstable/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ export interface WidgetManifestConfigV1 {
/**
* List of entrypoint JS files to be loaded, in order. These will be placed on the page in script tags
*/
entrypointJs: string[];
entrypointJs: Array<{
/** Relative path of the JS file to load */
path: string;

/** The type to use in the script tag when loading this JS file */
type: "module" | "text/javascript";
}>;

/**
* Any CSS files to be loaded, in order.
* @optional
*/
entrypointCss?: string[];
entrypointCss?: Array<{
/** Relative path of the CSS file to load */
path: string;
}>;

/**
* The map of parameter IDs to their definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ describe("WidgetMessages", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test"],
parameterUpdateIds: ["test"],
},
myEvent2: {
displayName: "My Event 2",
parameterIds: ["test", "test2"],
parameterUpdateIds: ["test", "test2"],
},
},
});
Expand Down Expand Up @@ -90,11 +90,11 @@ describe("WidgetMessages", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test"],
parameterUpdateIds: ["test"],
},
myEvent2: {
displayName: "My Event 2",
parameterIds: ["test", "test2"],
parameterUpdateIds: ["test", "test2"],
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/widget.vite-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default defineConfig({
events: {
updateHeader: {
displayName: "Update header",
parameterIds: ["headerText"],
parameterUpdateIds: ["headerText"],
},
updateTodoItems: {
displayName: "Update todo items",
parameterIds: ["todoItems"],
parameterUpdateIds: ["todoItems"],
},
},
});
Expand Down
9 changes: 7 additions & 2 deletions packages/widget.vite-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,14 @@ export function FoundryWidgetVitePlugin(options: Options = {}): Plugin {
);
}
const widgetConfig: WidgetManifestConfig = {
entrypointJs: [chunk.fileName],
entrypointJs: [{
path: chunk.fileName,
type: "module",
}],
entrypointCss: chunk.viteMetadata?.importedCss.size
? [...chunk.viteMetadata.importedCss]
? [...chunk.viteMetadata.importedCss].map((css) => ({
path: css,
}))
: [],
rid: entrypointFileIdToConfigMap[chunk.facadeModuleId].rid,
version: packageJsonFile.version ?? "0.0.0",
Expand Down

0 comments on commit 7c13070

Please sign in to comment.