Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 739-localization-cont…
Browse files Browse the repository at this point in the history
…ributions
  • Loading branch information
tjcouch-sil committed Apr 26, 2024
2 parents 70de0f9 + a36612a commit e10caaa
Show file tree
Hide file tree
Showing 87 changed files with 1,555 additions and 1,393 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# resource-viewer
# platform-scripture-editor

Simple resource viewer extension for Paranext
Editor extension for Platform.Bible, that can also be used in read-only mode

## Summary

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"metadata": {},
"localizedStrings": {
"en": {
"%mainMenu_openPlatformScriptureEditor%": "Open Scripture Editor",
"%mainMenu_openPlatformResourceViewer%": "Open Resource Viewer",
"%webView_platformScriptureEditor_options%": "Options",
"%webView_platformScriptureEditor_info%": "Info",
"%webView_platformScriptureEditor_backgroundColor%": "Background Color",
"%webView_platformScriptureEditor_textColor%": "Text Color",
"%webView_platformScriptureEditor_thickBorders%": "Thick Borders",
"%webView_platformScriptureEditor_publisherInfo%": "Publisher Info",
"%webView_platformScriptureEditor_copyrightInfo%": "Copyright Info"
}
}
}
89 changes: 89 additions & 0 deletions extensions/src/platform-scripture-editor/contributions/menus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"mainMenu": {
"columns": {},
"groups": {},
"items": [
{
"label": "%mainMenu_openPlatformScriptureEditor%",
"localizeNotes": "Application main menu > Project > Open Scripture Editor",
"group": "platform.projectResources",
"order": -100,
"command": "platformScriptureEditor.openScriptureEditor"
},
{
"label": "%mainMenu_openPlatformResourceViewer%",
"localizeNotes": "Application main menu > Project > Open Resource Viewer",
"group": "platform.projectResources",
"order": -99,
"command": "platformScriptureEditor.openResourceViewer"
}
]
},
"webViewMenus": {
"platformScriptureEditor.react": {
"includeDefaults": true,
"topMenu": {
"columns": {
"platformScriptureEditor.options": {
"label": "%webView_platformScriptureEditor_options%",
"order": 3
},
"platformScriptureEditor.info": {
"label": "%webView_platformScriptureEditor_info%",
"order": 4
}
},
"groups": {
"platformScriptureEditor.colors": {
"column": "platformScriptureEditor.options",
"order": 1
},
"platformScriptureEditor.layout": {
"column": "platformScriptureEditor.options",
"order": 2
},
"platformScriptureEditor.general": {
"column": "platformScriptureEditor.info",
"order": 2
}
},
"items": [
{
"label": "%webView_platformScriptureEditor_backgroundColor%",
"group": "platformScriptureEditor.colors",
"order": 2,
"command": "platformScriptureEditor.changeBackgroundColor"
},
{
"label": "%webView_platformScriptureEditor_textColor%",
"group": "platformScriptureEditor.colors",
"order": 1,
"command": "platformScriptureEditor.changeTextColor"
},
{
"label": "%webView_platformScriptureEditor_thickBorders%",
"group": "platformScriptureEditor.layout",
"order": 1,
"command": "platformScriptureEditor.showThickBorders"
},
{
"label": "%webView_platformScriptureEditor_publisherInfo%",
"group": "platformScriptureEditor.general",
"order": 1,
"command": "platformScriptureEditor.showPublisherInfo"
},
{
"label": "%webView_platformScriptureEditor_copyrightInfo%",
"group": "platformScriptureEditor.general",
"order": 2,
"command": "platformScriptureEditor.showCopyrightInfo"
}
]
},
"contextMenu": {
"groups": {},
"items": []
}
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "resourceViewer",
"name": "platformScriptureEditor",
"version": "0.0.1",
"description": "Simple resource viewer extension for Platform.Bible",
"description": "Editor extension for Platform.Bible",
"author": "Paranext",
"license": "MIT",
"main": "src/main.ts",
"types": "src/types/resource-viewer.d.ts",
"types": "src/types/platform-scripture-editor.d.ts",
"menus": "contributions/menus.json",
"settings": "contributions/settings.json",
"projectSettings": "contributions/projectSettings.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "resource-viewer",
"name": "platform-scripture-editor",
"version": "0.0.2",
"description": "Simple resource viewer extension for Platform.Bible",
"description": "Editor extension for Platform.Bible",
"main": "src/main.js",
"types": "src/types/resource-viewer.d.ts",
"types": "src/types/platform-scripture-editor.d.ts",
"author": "Katherine Jensen",
"license": "MIT",
"scripts": {
Expand Down
124 changes: 124 additions & 0 deletions extensions/src/platform-scripture-editor/src/_editor-overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* Platform.Bible image protocol overrides */
/* stylelint-disable selector-no-qualifying-type */

.editor-container {
max-width: none;
}

.link-editor div.link-edit {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/pencil-fill.svg');
}

i.undo {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/arrow-counterclockwise.svg');
}

i.redo {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/arrow-clockwise.svg');
}

%paragraph {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/text-paragraph.svg');
}

%h-one {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-h1.svg');
}

%h-two {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-h2.svg');
}

%h-three {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-h3.svg');
}

%square-one {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/1-square.svg');
}

%square-two {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/2-square.svg');
}

%square-three {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/3-square.svg');
}

%square-four {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/4-square.svg');
}

%bookmark {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/bookmark.svg');
}

%file-earmark {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/file-earmark.svg');
}

.icon.bullet-list,
.icon.ul {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/list-ul.svg');
}

.icon.numbered-list,
.icon.ol {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/list-ol.svg');
}

%quote {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/chat-square-quote.svg');
}

.icon.ban {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/ban.svg');
}

.icon.code {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/code.svg');
}

i.bold {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-bold.svg');
}

i.italic {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-italic.svg');
}

i.underline {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-underline.svg');
}

i.strikethrough {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/type-strikethrough.svg');
}

i.code {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/code.svg');
}

i.link {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/link.svg');
}

i.left-align {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/text-left.svg');
}

i.center-align {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/text-center.svg');
}

i.right-align {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/text-right.svg');
}

i.justify-align {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/justify.svg');
}

i.chevron-down {
background-image: url('papi-extension://platformScriptureEditor/assets/images/icons/chevron-down.svg');
}
122 changes: 122 additions & 0 deletions extensions/src/platform-scripture-editor/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import papi, { logger } from '@papi/backend';
import type {
ExecutionActivationContext,
GetWebViewOptions,
IWebViewProvider,
SavedWebViewDefinition,
WebViewDefinition,
} from '@papi/core';
import platformScriptureEditorWebView from './platform-scripture-editor.web-view?inline';
import platformScriptureEditorWebViewStyles from './platform-scripture-editor.web-view.scss?inline';

logger.info('Scripture Editor is importing!');

const scriptureEditorWebViewType = 'platformScriptureEditor.react';

interface PlatformScriptureEditorOptions extends GetWebViewOptions {
projectId: string | undefined;
isReadOnly: boolean;
}

/** Temporary function to manually control `isReadOnly`. Registered as a command handler. */
async function openPlatformScriptureEditor(
projectId: string | undefined,
): Promise<string | undefined> {
// The second argument (isReadOnly) is hardcoded for now, but should be a parameter in the future
return open(projectId, false);
}

/** Temporary function to manually control `isReadOnly`. Registered as a command handler. */
async function openPlatformResourceViewer(
projectId: string | undefined,
): Promise<string | undefined> {
// The second argument (isReadOnly) is hardcoded for now, but should be a parameter in the future
return open(projectId, true);
}

/** Function to prompt for a project and open it in the editor */
async function open(
projectId: string | undefined,
isReadOnly: boolean,
): Promise<string | undefined> {
let projectIdForWebView = projectId;
if (!projectIdForWebView) {
projectIdForWebView = await papi.dialogs.selectProject({
title: 'Select Resource',
prompt: 'Choose the resource project:',
includeProjectTypes: '^ParatextStandard$',
});
}
if (projectIdForWebView) {
const options: PlatformScriptureEditorOptions = { projectId: projectIdForWebView, isReadOnly };
// REVIEW: If an editor is already open for the selected project, we open another.
// This matches the current behavior in P9, though it might not be what we want long-term.
return papi.webViews.getWebView(scriptureEditorWebViewType, undefined, options);
}
return undefined;
}

/** Simple web view provider that provides Resource web views when papi requests them */
const scriptureEditorWebViewProvider: IWebViewProvider = {
async getWebView(
savedWebView: SavedWebViewDefinition,
getWebViewOptions: PlatformScriptureEditorOptions,
): Promise<WebViewDefinition | undefined> {
if (savedWebView.webViewType !== scriptureEditorWebViewType)
throw new Error(
`${scriptureEditorWebViewType} provider received request to provide a ${savedWebView.webViewType} web view`,
);

// We know that the projectId (if present in the state) will be a string.
const projectId =
getWebViewOptions.projectId ||
// eslint-disable-next-line no-type-assertion/no-type-assertion
(savedWebView.state?.projectId as string) ||
undefined;
const isReadOnly = getWebViewOptions.isReadOnly || savedWebView.state?.isReadOnly;
let title = '';
if (projectId) {
title = `${(await papi.projectLookup.getMetadataForProject(projectId)).name ?? projectId}${isReadOnly ? '' : ' (Editable)'}`;
} else title = isReadOnly ? 'Resource Viewer' : 'Scripture Editor';

return {
title,
...savedWebView,
content: platformScriptureEditorWebView,
styles: platformScriptureEditorWebViewStyles,
state: {
...savedWebView.state,
projectId,
isReadOnly,
},
};
},
};

export async function activate(context: ExecutionActivationContext): Promise<void> {
logger.info('Scripture editor is activating!');

const openPlatformScriptureEditorPromise = papi.commands.registerCommand(
'platformScriptureEditor.openScriptureEditor',
openPlatformScriptureEditor,
);

const openPlatformResourceViewerPromise = papi.commands.registerCommand(
'platformScriptureEditor.openResourceViewer',
openPlatformResourceViewer,
);

const scriptureEditorWebViewProviderPromise = papi.webViewProviders.register(
scriptureEditorWebViewType,
scriptureEditorWebViewProvider,
);

// Await the registration promises at the end so we don't hold everything else up
context.registrations.add(
await scriptureEditorWebViewProviderPromise,
await openPlatformScriptureEditorPromise,
await openPlatformResourceViewerPromise,
);

logger.info('Scripture editor is finished activating!');
}
Loading

0 comments on commit e10caaa

Please sign in to comment.