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

Added extension project settings contributions #856

Merged
merged 8 commits into from
Apr 17, 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
10 changes: 9 additions & 1 deletion assets/localization/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@
"settings_platform_verseRef_label": "Current Verse Reference",
"settings_platform_interfaceLanguage_label": "Interface Language",
"settings_hello_world_group1_label": "Hello World Settings",
"settings_hello_world_personName_label": "Selected Person's Name on Hello World Web View"
"settings_hello_world_personName_label": "Selected Person's Name on Hello World Web View",
"project_settings_platform_group1_label": "Platform Settings",
"project_settings_platform_group1_description": "Project settings pertaining to the software overall",
"project_settings_platform_fullName_label": "Project Full Name",
"project_settings_platform_language_label": "Project Primary Language",
"project_settings_platformScripture_booksPresent_label": "Scripture Books Present",
"project_settings_platformScripture_booksPresent_description": "Which books of the Bible are present in this Scripture project",
"project_settings_platformScripture_versification_label": "Scripture Versification",
"project_settings_platformScripture_versification_description": "Which versification scheme this Scripture project follows"
}
6 changes: 6 additions & 0 deletions extensions/src/hello-world/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
openHelloWorldProjectWebView,
);

const helloWorldPersonNamePromise = papi.settings.registerValidator(
'hello-world.personName',
async (newValue) => typeof newValue === 'string',
);

const helloWorldProjectWebViewProviderPromise = papi.webViewProviders.register(
helloWorldProjectWebViewProvider.webViewType,
helloWorldProjectWebViewProvider,
Expand Down Expand Up @@ -249,6 +254,7 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
await helloWorldPdpefPromise,
await helloWorldProjectWebViewProviderPromise,
await openHelloWorldProjectPromise,
await helloWorldPersonNamePromise,
await htmlWebViewProviderPromise,
await reactWebViewProviderPromise,
await reactWebView2ProviderPromise,
Expand Down
28 changes: 26 additions & 2 deletions extensions/src/hello-world/src/web-views/hello-world.web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import type { WebViewProps } from '@papi/core';
import { Key, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { HelloWorldEvent } from 'hello-world';
import { debounce } from 'platform-bible-utils';
import Clock from './components/clock.component';
import Logo from '../../assets/offline.svg';

Expand Down Expand Up @@ -172,7 +173,30 @@ globalThis.webViewComponent = function HelloWorld({
),
);

const [name, setName] = useSetting('hello-world.personName', 'Kathy');
const [name, setNameInternal] = useSetting('hello-world.personName', 'Kathy');

// Name used for display and editing in the input field while debouncing the actual setting change
const [nameTemp, setNameTemp] = useState(name);

useEffect(() => {
setNameTemp(name);
}, [name]);

const debouncedSetName = useMemo(
() =>
debounce((newName) => {
setNameInternal(newName);
}, 300),
[setNameInternal],
);

const setName = useCallback(
(newName: string) => {
setNameTemp(newName);
debouncedSetName(newName);
},
[debouncedSetName],
);

const peopleDataProvider = useDataProvider('helloSomeone.people');

Expand Down Expand Up @@ -232,7 +256,7 @@ globalThis.webViewComponent = function HelloWorld({
<div>{latestVerseText}</div>
<Clock />
<div>
<input value={name} onChange={(e) => setName(e.target.value)} />
<input value={nameTemp} onChange={(e) => setName(e.target.value)} />
<Button onClick={() => peopleDataProvider?.deletePerson(name)}>Delete {name}</Button>
</div>
<div>{personGreeting}</div>
Expand Down
16 changes: 16 additions & 0 deletions extensions/src/platform-scripture/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100

[*.md]
trim_trailing_whitespace = false

[*.cs]
indent_size = 4
35 changes: 35 additions & 0 deletions extensions/src/platform-scripture/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# #region shared with https://github.com/paranext/paranext-multi-extension-template/blob/main/.eslintignore

# Please keep this file in sync with .prettierignore and .stylelintignore

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# OSX
.DS_Store

.idea
npm-debug.log.*
*.css.d.ts
*.sass.d.ts
*.scss.d.ts

# Built files
dist
release
temp-build

# generated files
package-lock.json

# #endregion
163 changes: 163 additions & 0 deletions extensions/src/platform-scripture/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// #region shared with https://github.com/paranext/paranext-multi-extension-template/blob/main/.eslintrc.cjs

module.exports = {
extends: [
// https://github.com/electron-react-boilerplate/eslint-config-erb/blob/main/index.js
// airbnb rules are embedded in erb https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb
'erb',
// Make sure this is last so it gets the chance to override other configs.
// See https://github.com/prettier/eslint-config-prettier and https://github.com/prettier/eslint-plugin-prettier
'plugin:prettier/recommended',
],

rules: {
// Some rules in this following shared region are not applied since they are overridden in subsequent regions
// #region shared with https://github.com/paranext/paranext-core/blob/main/.eslintrc.js except certain overrides

// #region ERB rules

'import/extensions': 'off',
// A temporary hack related to IDE not resolving correct package.json
'import/no-extraneous-dependencies': 'off',
'import/no-import-module-exports': 'off',
'import/no-unresolved': 'error',
'react/jsx-filename-extension': 'off',
'react/react-in-jsx-scope': 'off',

// #endregion

// #region Platform.Bible rules

// Rules in each section are generally in alphabetical order. However, several
// `@typescript-eslint` rules require disabling the equivalent ESLint rule. So in these cases
// each ESLint rule is turned off immediately above the corresponding `@typescript-eslint` rule.
'import/no-anonymous-default-export': ['error', { allowCallExpression: false }],
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': [
'error',
'always',
{ exceptAfterSingleLine: true, exceptAfterOverload: true },
],
'@typescript-eslint/member-ordering': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{
allow: ['arrowFunctions', 'functions', 'methods'],
},
],
'@typescript-eslint/no-explicit-any': 'error',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['shared/*', 'renderer/*', 'extension-host/*', 'node/*', 'client/*', 'main/*'],
message: `Importing from this path is not allowed. Try importing from @papi/core. Imports from paths like 'shared', 'renderer', 'node', 'client' and 'main' are not allowed to prevent unnecessary import break.`,
},
],
},
],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, allowNamedExports: true, typedefs: false, ignoreTypeReferences: true },
],
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'comma-dangle': ['error', 'always-multiline'],
indent: 'off',
'jsx-a11y/label-has-associated-control': [
'error',
{
assert: 'either',
},
],
// Should use our logger anytime you want logs that persist. Otherwise use console only in testing
'no-console': 'warn',
'no-null/no-null': 2,
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'no-type-assertion/no-type-assertion': 'error',
'prettier/prettier': ['warn', { tabWidth: 2, trailingComma: 'all' }],
'react/jsx-indent-props': ['warn', 2],
'react/jsx-props-no-spreading': ['error', { custom: 'ignore' }],
'react/require-default-props': 'off',

// #endregion

// #endregion

// #region Overrides to rules from paranext-core

'import/no-unresolved': ['error', { ignore: ['@papi'] }],

// #endregion
},
globals: {
globalThis: 'readonly',
},
overrides: [
{
// Allow this file to have overrides to rules from paranext-core
files: ['.eslintrc.*js'],
rules: {
'no-dupe-keys': 'off',
},
},
{
files: ['*.js'],
rules: {
strict: 'off',
},
},
{
// Don't require extensions to have a default export for "activate()"
files: ['*.ts'],
rules: {
'import/prefer-default-export': 'off',
},
},
{
files: ['./lib/*', './webpack/*'],
rules: {
// These files are scripts not running in Platform.Bible, so they can't use the logger
'no-console': 'off',
},
},
{
files: ['*.d.ts'],
rules: {
// Allow .d.ts files to self import so they can refer to their types in `papi-shared-types`
'import/no-self-import': 'off',
},
},
],
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
project: './tsconfig.lint.json',
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
plugins: ['@typescript-eslint', 'no-type-assertion', 'no-null'],
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
};

// #endregion
33 changes: 33 additions & 0 deletions extensions/src/platform-scripture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# #region shared with https://github.com/paranext/paranext-multi-extension-template/blob/main/.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
release
dist-ssr
*.local

# formatting and linting
.eslintcache

# Editor directories and files
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Temporary intermediate build files
temp-build

# #endregion
35 changes: 35 additions & 0 deletions extensions/src/platform-scripture/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# #region shared with https://github.com/paranext/paranext-multi-extension-template/blob/main/.prettierignore

# Please keep this file in sync with .eslintignore and .stylelintignore

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# OSX
.DS_Store

.idea
npm-debug.log.*
*.css.d.ts
*.sass.d.ts
*.scss.d.ts

# Built files
dist
release
temp-build

# generated files
package-lock.json

# #endregion
19 changes: 19 additions & 0 deletions extensions/src/platform-scripture/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// #region shared with https://github.com/paranext/paranext-core/blob/main/.prettierrc.js and https://github.com/paranext/paranext-multi-extension-template/blob/main/.prettierrc.js

module.exports = {
tabWidth: 2,
trailingComma: 'all',
endOfLine: 'lf',
singleQuote: true,
// prettier-plugin-jsdoc options
tsdoc: true,
plugins: ['prettier-plugin-jsdoc'],
overrides: [
{
files: '*.json',
options: { parser: 'json' },
},
],
};

// #endregion
Loading
Loading