diff --git a/src/components/CompletionCard/CompletionCard.tsx b/src/components/CompletionCard/CompletionCard.tsx
index 195b614..8d970ad 100644
--- a/src/components/CompletionCard/CompletionCard.tsx
+++ b/src/components/CompletionCard/CompletionCard.tsx
@@ -1,95 +1,34 @@
import React from "react";
import { ICompletionDetail } from "../../logic/completionMapping";
-import { CompletionTypes } from "../../types/engine262-stubs";
+import { getCompletionClassname } from "./utils";
-import { InlineResultViewer } from "../InlineResultViewer";
-import { CompletionIcon } from "./CompletionIcon";
+import { CompletionCardContext } from "./CompletionCardContext";
-function getCompletionClassname(inputCompletion: ICompletionDetail) {
- const typeToClassnameMapping: { [key in CompletionTypes]: string } = {
- [CompletionTypes.Normal]: "bg-gray-300",
- [CompletionTypes.Return]: "bg-green-200",
- [CompletionTypes.Continue]: "bg-yellow-100",
- [CompletionTypes.Break]: "bg-yellow-300",
- [CompletionTypes.Throw]: "bg-red-300",
- };
-
- return typeToClassnameMapping[inputCompletion.completionType];
-}
-
-function getCodeTextFromCompletion(
- code: string,
- completion: ICompletionDetail
-) {
- return code.substring(completion.start, completion.end);
-}
+import { CompletionCardFullRecord } from "./CompletionCardFullRecord";
+import { CompletionCardSourceSnippet } from "./CompletionCardSourceSnippet";
+import { CompletionCardSummary } from "./CompletionCardSummary";
export interface ICompletionCardProps {
completionDetail: ICompletionDetail;
code: string;
}
-export function CompletionCard(props: ICompletionCardProps) {
+// TODO: have diff version to be shown as tooltip over source code
+
+export function CompletionCardFull(props: ICompletionCardProps) {
const { completionDetail, code } = props;
- // TODO: have diff version to be shown as tooltip over source code
return (
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
- From source
-
- ⤵️
-
-
-
-
-
-
-
- Full completion record
-
- ⤵️
-
-
-
-
-
- | [[Type]] |
- {completionDetail.completionType} |
-
-
- | [[Value]] |
-
- {completionDetail.completionValueString}
- |
-
-
- | [[Target]] |
-
- {completionDetail.completionTargetString}
- |
-
-
-
-
+
);
}
diff --git a/src/components/CompletionCard/CompletionCardContext.tsx b/src/components/CompletionCard/CompletionCardContext.tsx
new file mode 100644
index 0000000..871b20e
--- /dev/null
+++ b/src/components/CompletionCard/CompletionCardContext.tsx
@@ -0,0 +1,31 @@
+import { createContext, useContext } from "react";
+import { ICompletionDetail } from "../../logic/completionMapping";
+
+export interface ICompletionCardContext {
+ completionDetail?: ICompletionDetail;
+ code?: string;
+}
+
+const initialValue: ICompletionCardContext = {};
+
+export const CompletionCardContext = createContext
(
+ initialValue
+);
+
+export class CompletionCardContextEmptyError extends TypeError {}
+
+export function useCompletionCardContext() {
+ const contextValue = useContext(CompletionCardContext);
+ const { completionDetail, code } = contextValue;
+ if (completionDetail === undefined || code === undefined) {
+ throw new CompletionCardContextEmptyError(
+ `CompletionCard Context value is not available in consumer. Provider might be missing.\n Value is ${JSON.stringify(
+ contextValue,
+ null,
+ 2
+ )}`
+ );
+ }
+
+ return { completionDetail, code };
+}
diff --git a/src/components/CompletionCard/CompletionCardFullRecord.tsx b/src/components/CompletionCard/CompletionCardFullRecord.tsx
new file mode 100644
index 0000000..afa9843
--- /dev/null
+++ b/src/components/CompletionCard/CompletionCardFullRecord.tsx
@@ -0,0 +1,36 @@
+import React from "react";
+import { useCompletionCardContext } from "./CompletionCardContext";
+
+export function CompletionCardFullRecord() {
+ const { completionDetail } = useCompletionCardContext();
+
+ return (
+
+
+ Full completion record
+
+ ⤵️
+
+
+
+
+
+ | [[Type]] |
+ {completionDetail.completionType} |
+
+
+ | [[Value]] |
+
+ {completionDetail.completionValueString}
+ |
+
+
+ | [[Target]] |
+
+ {completionDetail.completionTargetString}
+ |
+
+
+
+ );
+}
diff --git a/src/components/CompletionCard/CompletionCardSourceSnippet.tsx b/src/components/CompletionCard/CompletionCardSourceSnippet.tsx
new file mode 100644
index 0000000..db28f61
--- /dev/null
+++ b/src/components/CompletionCard/CompletionCardSourceSnippet.tsx
@@ -0,0 +1,26 @@
+import React from "react";
+
+import { InlineResultViewer } from "../InlineResultViewer";
+
+import { useCompletionCardContext } from "./CompletionCardContext";
+import { getCodeTextFromCompletion } from "./utils";
+
+export function CompletionCardSourceSnippet() {
+ const { completionDetail, code } = useCompletionCardContext();
+
+ return (
+
+
+ From source
+
+ ⤵️
+
+
+
+
+
+ );
+}
diff --git a/src/components/CompletionCard/CompletionCardSummary.tsx b/src/components/CompletionCard/CompletionCardSummary.tsx
new file mode 100644
index 0000000..e6ba39e
--- /dev/null
+++ b/src/components/CompletionCard/CompletionCardSummary.tsx
@@ -0,0 +1,24 @@
+import React from "react";
+
+import { InlineResultViewer } from "../InlineResultViewer";
+
+import { CompletionIcon } from "./CompletionIcon";
+import { useCompletionCardContext } from "./CompletionCardContext";
+
+export function CompletionCardSummary() {
+ const { completionDetail } = useCompletionCardContext();
+
+ return (
+
+ );
+}
diff --git a/src/components/CompletionCard/index.ts b/src/components/CompletionCard/index.ts
index dd240fa..de03b80 100644
--- a/src/components/CompletionCard/index.ts
+++ b/src/components/CompletionCard/index.ts
@@ -1,3 +1,3 @@
-import { CompletionCard } from "./CompletionCard";
+import { CompletionCardFull } from "./CompletionCard";
-export { CompletionCard };
+export { CompletionCardFull };
diff --git a/src/components/CompletionCard/utils.ts b/src/components/CompletionCard/utils.ts
new file mode 100644
index 0000000..b738bb6
--- /dev/null
+++ b/src/components/CompletionCard/utils.ts
@@ -0,0 +1,21 @@
+import { ICompletionDetail } from "../../logic/completionMapping";
+import { CompletionTypes } from "../../types/engine262-stubs";
+
+export function getCompletionClassname(inputCompletion: ICompletionDetail) {
+ const typeToClassnameMapping: { [key in CompletionTypes]: string } = {
+ [CompletionTypes.Normal]: "bg-gray-300",
+ [CompletionTypes.Return]: "bg-green-200",
+ [CompletionTypes.Continue]: "bg-yellow-100",
+ [CompletionTypes.Break]: "bg-yellow-300",
+ [CompletionTypes.Throw]: "bg-red-300",
+ };
+
+ return typeToClassnameMapping[inputCompletion.completionType];
+}
+
+export function getCodeTextFromCompletion(
+ code: string,
+ completion: ICompletionDetail
+) {
+ return code.substring(completion.start, completion.end);
+}
diff --git a/src/components/CompletionViewer/CompletionViewer.tsx b/src/components/CompletionViewer/CompletionViewer.tsx
index 7b1bdaf..178e71c 100644
--- a/src/components/CompletionViewer/CompletionViewer.tsx
+++ b/src/components/CompletionViewer/CompletionViewer.tsx
@@ -2,7 +2,7 @@ import React from "react";
import { ICompletionDetail } from "../../logic/completionMapping";
import { TSourceMapping } from "../../logic/sourceMapping";
-import { CompletionCard } from "../CompletionCard";
+import { CompletionCardFull } from "../CompletionCard";
export function CompletionViewer(props: {
code: string;
@@ -21,10 +21,10 @@ export function CompletionViewer(props: {
{completionDetails.map((tmpCompletion) => (
// Card for each completion record
-
+ >
))}