Skip to content

Commit

Permalink
Stronly type data-changed message
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Aug 29, 2024
1 parent 42eb68d commit 8cc70b7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 43 deletions.
43 changes: 1 addition & 42 deletions packages/perseus-editor/src/iframe-content-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,7 @@ import {
setIframeParameter,
} from "./iframe-utils";

import type {MessageToIFrameParent} from "./iframe-utils";
import type {
APIOptions,
DeviceType,
PerseusItem,
PerseusRenderer,
} from "@khanacademy/perseus";
import type {LinterContextProps} from "@khanacademy/perseus-linter";

type ArticleData = {
apiOptions: APIOptions;
json: Partial<PerseusRenderer>;
useNewStyles: boolean;
linterContext: LinterContextProps;
legacyPerseusLint: ReadonlyArray<string>;
};

export type NewDataMessage =
| {
type: "question";
data: {
item: PerseusItem;
apiOptions: APIOptions;
initialHintsVisible: number;
device: DeviceType;
linterContext: LinterContextProps;
reviewMode: boolean;
legacyPerseusLint: ReadonlyArray<string>;
};
}
| {
type: "hint";
data: {
hint: PerseusRenderer;
bold: boolean;
pos: number;
apiOptions?: APIOptions;
linterContext: LinterContextProps;
};
}
| {type: "article-all"; data: ReadonlyArray<ArticleData>}
| {type: "article"; data: ArticleData};
import type {MessageToIFrameParent, NewDataMessage} from "./iframe-utils";

let nextIframeID = 0;
const requestIframeData: Record<string, any> = {};
Expand Down
44 changes: 43 additions & 1 deletion packages/perseus-editor/src/iframe-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import type {
APIOptions,
DeviceType,
PerseusItem,
PerseusRenderer,
} from "@khanacademy/perseus";
import type {LinterContextProps} from "@khanacademy/perseus-linter";

/**
* Sent to the parent iframe to tell it to update the <iframe> height. This is
* used to ensure that the iframe displays the full height of the content after
Expand Down Expand Up @@ -25,13 +33,47 @@ export type MessageToIFrameParent =
| UpdateIframeHeightMessage
| RequestDataMessage;

export type ArticleData = {
apiOptions: APIOptions;
json: Partial<PerseusRenderer>;
useNewStyles: boolean;
linterContext: LinterContextProps;
legacyPerseusLint: ReadonlyArray<string>;
};

export type NewDataMessage =
| {
type: "question";
data: {
item: PerseusItem;
apiOptions: APIOptions;
initialHintsVisible: number;
device: DeviceType;
linterContext: LinterContextProps;
reviewMode: boolean;
legacyPerseusLint: ReadonlyArray<string>;
};
}
| {
type: "hint";
data: {
hint: PerseusRenderer;
bold: boolean;
pos: number;
apiOptions?: APIOptions;
linterContext: LinterContextProps;
};
}
| {type: "article-all"; data: ReadonlyArray<ArticleData>}
| {type: "article"; data: ArticleData};

/**
* Sent by the iframe host to update what is being previewed (ie. re-render).
*/
type DataChangedMessage = {
type: "perseus:data-changed";
frameID: number;
data: any;
data: NewDataMessage;
};

/**
Expand Down

0 comments on commit 8cc70b7

Please sign in to comment.