Skip to content

Commit

Permalink
Add types file in API
Browse files Browse the repository at this point in the history
  • Loading branch information
GRL78 committed Aug 27, 2021
1 parent a195870 commit 706f531
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion front/dist/service-worker-prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ self.addEventListener('update', function(event) {
});

self.addEventListener('beforeinstallprompt', (e) => {
//TODO change prompt
//TODO change prompt
});
9 changes: 3 additions & 6 deletions front/src/Api/iframe/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Popup } from "./Ui/Popup";
import { ActionMessage } from "./Ui/ActionMessage";
import { isMessageReferenceEvent } from "../Events/ui/TriggerActionMessageEvent";
import { Menu } from "./Ui/Menu";
import type { RequireOnlyOne } from "../../types";
import type { RequireOnlyOne } from "../types";

let popupId = 0;
const popups: Map<number, Popup> = new Map<number, Popup>();
Expand All @@ -26,7 +26,7 @@ interface MenuDescriptor {
allowApi?: boolean;
}

type CallbackOrIframe = RequireOnlyOne<MenuDescriptor, "callback" | "iframe">;
export type MenuOptions = RequireOnlyOne<MenuDescriptor, "callback" | "iframe">;

interface ZonedPopupOptions {
zone: string;
Expand Down Expand Up @@ -119,10 +119,7 @@ export class WorkAdventureUiCommands extends IframeApiContribution<WorkAdventure
return popup;
}

registerMenuCommand(
commandDescriptor: string,
options: CallbackOrIframe | ((commandDescriptor: string) => void)
): Menu {
registerMenuCommand(commandDescriptor: string, options: MenuOptions | ((commandDescriptor: string) => void)): Menu {
const menu = new Menu(commandDescriptor);

if (typeof options === "function") {
Expand Down
4 changes: 4 additions & 0 deletions front/src/Api/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type RequireOnlyOne<T, keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, keys>> &
{
[K in keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<keys, K>, undefined>>;
}[keys];
3 changes: 2 additions & 1 deletion front/src/Components/Menu/Menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import CustomSubMenu from "./CustomSubMenu.svelte"
import {customMenuIframe, menuVisiblilityStore, SubMenusInterface, subMenusStore} from "../../Stores/MenuStore";
import {onDestroy, onMount} from "svelte";
import {get, Unsubscriber} from "svelte/store";
import {get} from "svelte/store";
import type {Unsubscriber} from "svelte/store";
import {sendMenuClickedEvent} from "../../Api/iframe/Ui/MenuItem";
let activeSubMenu: string = SubMenusInterface.settings;
Expand Down
5 changes: 0 additions & 5 deletions front/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,3 @@ export interface IVirtualJoystick extends Phaser.GameObjects.GameObject {
visible: boolean;
createCursorKeys: () => CursorKeys;
}

export type RequireOnlyOne<T, keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, keys>> &
{
[K in keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<keys, K>, undefined>>;
}[keys];

0 comments on commit 706f531

Please sign in to comment.