-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
187458550 v3 DI Initial Component Requests (#1225)
- Loading branch information
1 parent
4773826
commit 83541a8
Showing
12 changed files
with
169 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
v3/src/data-interactive/data-interactive-component-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { kCalculatorTileType } from "../components/calculator/calculator-defs" | ||
import { kCaseTableTileType } from "../components/case-table/case-table-defs" | ||
import { kGraphTileType } from "../components/graph/graph-defs" | ||
import { kMapTileType } from "../components/map/map-defs" | ||
import { kSliderTileType } from "../components/slider/slider-defs" | ||
import { kWebViewTileType } from "../components/web-view/web-view-defs" | ||
|
||
export const kV2CalculatorType = "calculator" | ||
export const kV2CaseTableType = "caseTable" | ||
export const kV2CaseCardType = "caseCard" | ||
export const kV2GameType = "game" | ||
export const kV2GraphType = "graph" | ||
export const kV2GuideViewType = "guideView" | ||
export const kV2ImageType = "image" | ||
export const kV2MapType = "map" | ||
export const kV2SliderType = "slider" | ||
export const kV2TextType = "text" | ||
export const kV2WebViewType = "webView" | ||
|
||
export const kComponentTypeV3ToV2Map: Record<string, string> = { | ||
[kCalculatorTileType]: kV2CalculatorType, | ||
[kCaseTableTileType]: kV2CaseTableType, | ||
// kV2CaseCardType | ||
[kGraphTileType]: kV2GraphType, | ||
// kV2GuideViewType | ||
// kV2ImageType | ||
[kMapTileType]: kV2MapType, | ||
[kSliderTileType]: kV2SliderType, | ||
// kV2TextType | ||
[kWebViewTileType]: kV2WebViewType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { t } from "../../utilities/translation/translate" | ||
import { registerDIHandler } from "../data-interactive-handler" | ||
import { DIHandler, DINotification, DIResources, DIValues } from "../data-interactive-types" | ||
import { uiState } from "../../models/ui-state" | ||
import { appState } from "../../models/app-state" | ||
|
||
const componentNotFoundResult = { success: false, values: { error: t("V3.DI.Error.componentNotFound") } } as const | ||
|
||
export const diComponentHandler: DIHandler = { | ||
delete(resources: DIResources) { | ||
const { component } = resources | ||
if (!component) return componentNotFoundResult | ||
|
||
appState.document.deleteTile(component.id) | ||
|
||
return { success: true } | ||
}, | ||
notify(resources: DIResources, values?: DIValues) { | ||
const { component } = resources | ||
if (!component) return componentNotFoundResult | ||
|
||
if (!values) return { success: false, values: { error: t("V3.DI.Error.valuesRequired") } } | ||
|
||
const { request } = values as DINotification | ||
if (request === "select") { | ||
uiState.setFocusedTile(component.id) | ||
// } else if (request === "autoScale") { // TODO Handle autoScale requests | ||
} | ||
|
||
return { success: true } | ||
} | ||
} | ||
|
||
registerDIHandler("component", diComponentHandler) |
26 changes: 26 additions & 0 deletions
26
v3/src/data-interactive/handlers/component-list-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { isWebViewModel } from "../../components/web-view/web-view-model" | ||
import { appState } from "../../models/app-state" | ||
import { kComponentTypeV3ToV2Map, kV2GameType, kV2WebViewType } from "../data-interactive-component-types" | ||
import { registerDIHandler } from "../data-interactive-handler" | ||
import { DIComponentInfo, DIHandler, DIResources } from "../data-interactive-types" | ||
|
||
export const diComponentListHandler: DIHandler = { | ||
get(_resources: DIResources) { | ||
const values: DIComponentInfo[] = [] | ||
appState.document.content?.tileMap.forEach(tile => { | ||
// TODO Should we add names to tiles? | ||
// TODO Tiles sometimes show titles different than tile.title. Should we return those? | ||
const { content, id, title } = tile | ||
const type = isWebViewModel(content) | ||
? content.isPlugin | ||
? kV2GameType | ||
: kV2WebViewType | ||
: kComponentTypeV3ToV2Map[content.type] | ||
values.push({ id, title, type }) | ||
}) | ||
|
||
return { success: true, values } | ||
} | ||
} | ||
|
||
registerDIHandler("componentList", diComponentListHandler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters