Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use menu contributions to build menus #790

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion assets/localization/eng.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
{
"insertNote": "Insert Note",
"mainMenu_aboutPlatformBible": "About Platform.Bible",
"mainMenu_downloadSlashInstallResources": "Download/Install Resources",
"mainMenu_downloadSlashUpdateProject": "Download/Update Project",
"mainMenu_exit": "Exit",
"mainMenu_help": "Help",
"mainMenu_layout": "Layout",
"mainMenu_openHelloWorldProject": "Open Hello World Project",
"mainMenu_openProject": "Open Project",
"mainMenu_openResourceViewer": "Open Resource Viewer",
"mainMenu_project": "Project",
"mainMenu_settings": "Settings",
"mainMenu_visitSupportBible": "Visit Support.Bible",
"mainMenu_window": "Window",
"some_localization_key": "This is the English text for %some_localization_key%.",
"submitButton": "Submit"
"submitButton": "Submit",
"webView_edit": "Edit",
"webView_project": "Project",
"webView_projectAssignmentsAndProgress": "Assignments and Progress",
"webView_projectSendReceive": "Send/Receive this project",
"wordList": "Word List"
}
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"asyncs",
"autodocs",
"biblionexus",
"camelcase",
"Consts",
"deuterocanon",
"dockbox",
"electronmon",
Expand Down
10 changes: 9 additions & 1 deletion extensions/src/hello-world/contributions/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
"mainMenu": {
"columns": {},
"groups": {},
"items": []
"items": [
{
"label": "%mainMenu_openHelloWorldProject%",
"localizeNotes": "Application main menu > Project > Open Hello World Project",
"group": "platform.projectProjects",
"order": 1000.1,
"command": "helloWorld.openProject"
}
]
},
"defaultWebViewTopMenu": {
"columns": {},
Expand Down
10 changes: 9 additions & 1 deletion extensions/src/resource-viewer/contributions/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
"mainMenu": {
"columns": {},
"groups": {},
"items": []
"items": [
{
"label": "%mainMenu_openResourceViewer%",
"localizeNotes": "Application main menu > Project > Open Resource Viewer",
"group": "platform.projectResources",
"order": -100,
"command": "resourceViewer.open"
}
]
},
"defaultWebViewTopMenu": {
"columns": {},
Expand Down
11 changes: 7 additions & 4 deletions lib/papi-dts/papi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4815,6 +4815,7 @@ declare module 'shared/services/menu-data.service-model' {
MultiColumnMenu,
ReferencedItem,
WebViewMenu,
Localized,
} from 'platform-bible-utils';
import {
DataProviderDataType,
Expand All @@ -4837,8 +4838,8 @@ declare module 'shared/services/menu-data.service-model' {
dataProviderName: 'platform.menuDataServiceDataProvider';
}>;
export type MenuDataDataTypes = {
MainMenu: DataProviderDataType<undefined, MultiColumnMenu, never>;
WebViewMenu: DataProviderDataType<ReferencedItem, WebViewMenu, never>;
MainMenu: DataProviderDataType<undefined, Localized<MultiColumnMenu>, never>;
WebViewMenu: DataProviderDataType<ReferencedItem, Localized<WebViewMenu>, never>;
};
module 'papi-shared-types' {
interface DataProviders {
Expand All @@ -4850,6 +4851,8 @@ declare module 'shared/services/menu-data.service-model' {
* Service that allows to get and store menu data
*/
export type IMenuDataService = {
/** Rebuild the menus with the latest inputs from all extensions. */
rebuildMenus(): Promise<void>;
/**
*
* Get menu content for the main menu
Expand Down Expand Up @@ -4887,7 +4890,7 @@ declare module 'shared/services/menu-data.service-model' {
*/
subscribeMainMenu(
mainMenuType: undefined,
callback: (menuContent: MultiColumnMenu) => void,
callback: (menuContent: Localized<MultiColumnMenu>) => void,
options?: DataProviderSubscriberOptions,
): Promise<UnsubscriberAsync>;
/**
Expand Down Expand Up @@ -4918,7 +4921,7 @@ declare module 'shared/services/menu-data.service-model' {
*/
subscribeWebViewMenu(
webViewType: ReferencedItem,
callback: (menuContent: WebViewMenu) => void,
callback: (menuContent: Localized<WebViewMenu>) => void,
options?: DataProviderSubscriberOptions,
): Promise<UnsubscriberAsync>;
} & OnDidDispose &
Expand Down
424 changes: 212 additions & 212 deletions lib/platform-bible-react/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-react/dist/index.cjs.map

Large diffs are not rendered by default.

37 changes: 29 additions & 8 deletions lib/platform-bible-react/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export interface ScriptureReference {
chapterNum: number;
verseNum: number;
}
/** Within type T, recursively change properties that were of type A to be of type B */
export type ReplaceType<T, A, B> = T extends A ? B : T extends object ? {
[K in keyof T]: ReplaceType<T[K], A, B>;
} : T;
/** Identifier for a string that will be localized in a menu based on the user's UI language */
export type LocalizeKey = `%${string}%`;
/** Name of some UI element (i.e., tab, column, group, menu item) or some PAPI object (i.e., command) */
Expand Down Expand Up @@ -238,10 +242,18 @@ export type MenuItemContainingCommand = MenuItemBase & {
iconPathBefore?: string;
};
/**
* Group of menu items that can be combined with other groups to form a single menu/submenu. Groups
* are separated using a line within the menu/submenu.
* Group of menu items that can be combined with other groups to form a single context menu/submenu.
* Groups are separated using a line within the menu/submenu.
*/
export type Groups = {
export type GroupsInSingleColumnMenu = {
/** Named menu group */
[property: ReferencedItem]: OrderedExtensibleContainer | MenuGroupDetailsInSubMenu;
};
/**
* Group of menu items that can be combined with other groups to form a single menu/submenu within a
* multi-column menu. Groups are separated using a line within the menu/submenu.
*/
export type GroupsInMultiColumnMenu = {
/** Named menu group */
[property: ReferencedItem]: MenuGroupDetailsInColumn | MenuGroupDetailsInSubMenu;
};
Expand All @@ -255,15 +267,24 @@ export type ColumnsWithHeaders = {
/** Menu that contains a column without a header */
export type SingleColumnMenu = {
/** Groups that belong in this menu */
groups: Groups;
groups: GroupsInSingleColumnMenu;
/** List of menu items that belong in this menu */
items: (MenuItemContainingCommand | MenuItemContainingSubmenu)[];
};
/** Menu that contains multiple columns with headers */
export type MultiColumnMenu = SingleColumnMenu & {
export type MultiColumnMenu = {
/** Columns that belong in this menu */
columns: ColumnsWithHeaders;
/** Groups that belong in this menu */
groups: GroupsInMultiColumnMenu;
/** List of menu items that belong in this menu */
items: (MenuItemContainingCommand | MenuItemContainingSubmenu)[];
};
/**
* Type that converts any menu type before it is localized to what it is after it is localized. This
* can be applied to any menu type as needed.
*/
export type Localized<T> = ReplaceType<ReplaceType<T, LocalizeKey, string>, ReferencedItem, string>;
export type MenuItemInfoBase = {
/** Text (displayable in the UI) as the name of the menu item */
label: string;
Expand All @@ -282,7 +303,7 @@ export interface CommandHandler {
(command: Command): void;
}
export type MenuPropsBase = {
menuDefinition: SingleColumnMenu;
menuDefinition: Localized<SingleColumnMenu>;
commandHandler: CommandHandler;
/**
* Additional action to perform when any menu item is clicked. Allows the caller to handle event
Expand Down Expand Up @@ -364,7 +385,7 @@ export type MenuItemInfo = (Command | SubMenu) & {
export function MenuItem(props: MenuItemProps): import("react/jsx-runtime").JSX.Element;
export type GridMenuInfo = {
/** The menu object containing information about the columns, groups, and items to display. */
multiColumnMenu: MultiColumnMenu;
multiColumnMenu: Localized<MultiColumnMenu>;
};
export type GridMenuProps = GridMenuInfo & {
/** Optional unique identifier */
Expand Down Expand Up @@ -894,7 +915,7 @@ export type TextFieldProps = {
*/
export declare function TextField({ variant, id, isDisabled, hasError, isFullWidth, helperText, label, placeholder, isRequired, className, defaultValue, value, onChange, onFocus, onBlur, }: TextFieldProps): import("react/jsx-runtime").JSX.Element;
export interface MultiColumnMenuProvider {
(isSupportAndDevelopment: boolean): MultiColumnMenu;
(isSupportAndDevelopment: boolean): Promise<Localized<MultiColumnMenu>>;
}
export type ToolbarProps = React$1.PropsWithChildren<{
/** The handler to use for menu commands (and eventually toolbar commands). */
Expand Down
Loading
Loading