Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmaa committed Oct 15, 2024
1 parent 96cfd14 commit 4c10eab
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 61 deletions.
32 changes: 20 additions & 12 deletions ext/data/recommended-settings.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
{
"en": [
{
"action": "set",
"path": "scanning.scanResolution",
"value": "word",
"modification": {
"action": "set",
"path": "scanning.scanResolution",
"value": "word"
},
"description": "English uses spaces to separate words so scanning by word (instead of character) is recommended."
},
{
"action": "set",
"path": "translation.searchResolution",
"value": "word",
"modification": {
"action": "set",
"path": "translation.searchResolution",
"value": "word"
},
"description": "English uses spaces to separate words so looking up whole words in the dictionary is recommended."
}
],
"es": [
{
"action": "set",
"path": "scanning.scanResolution",
"value": "word",
"modification": {
"action": "set",
"path": "scanning.scanResolution",
"value": "word"
},
"description": "Spanish uses spaces to separate words so scanning by word (instead of character) is recommended."
},
{
"action": "set",
"path": "translation.searchResolution",
"value": "word",
"modification": {
"action": "set",
"path": "translation.searchResolution",
"value": "word"
},
"description": "Spanish uses spaces to separate words so looking up whole words in the dictionary is recommended."
}
]
Expand Down
198 changes: 160 additions & 38 deletions ext/data/schemas/recommended-settings-schema.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,179 @@
{
"$id": "defaultOptionsOverride",
"$id": "recommendedSetttings",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Contains data for recommended default options overrides by language.",
"type": "object",
"$defs": {
"path": {
"type": "string",
"minLength": 2
},
"value": {
"anyOf": [
{
"type": "string",
"minLength": 1
},
{
"type": "number"
},
{
"type": "boolean"
},
{
"type": "array"
},
{
"type": "object"
}
]
},
"description": {
"type": "string",
"minLength": 2
}
},
"patternProperties": {
"^.{2,}$": {
"title": "Language",
"type": "array",
"items": {
"title": "Modification",
"type": "object",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"minLength": 2
},
"action": {
"type": "string",
"enum": [
"set",
"delete",
"swap",
"splice",
"push"
]
},
"value": {
"anyOf": [
{
"type": "string",
"minLength": 1
"oneOf": [
{
"type": "object",
"title": "ModificationSet",
"properties": {
"modification": {
"type": "object",
"properties": {
"action": {
"type": "string",
"const": "set"
},
"path": {
"$ref": "#/$defs/path"
},
"value": {
"$ref": "#/$defs/value"
}
}
},
{
"type": "number"
"description": {
"$ref": "#/$defs/description"
}
}
},
{
"type": "object",
"title": "ModificationDelete",
"properties": {
"modification": {
"type": "object",
"properties": {
"action": {
"type": "string",
"const": "delete"
},
"path": {
"$ref": "#/$defs/path"
},
"value": {
"$ref": "#/$defs/value"
}
}
},
{
"type": "boolean"
"description": {
"$ref": "#/$defs/description"
}
}
},
{
"type": "object",
"title": "ModificationSwap",
"properties": {
"modification": {
"type": "object",
"properties": {
"action": {
"type": "string",
"const": "swap"
},
"path1": {
"$ref": "#/$defs/path"
},
"path2": {
"$ref": "#/$defs/path"
}
}
},
{
"type": "array"
"description": {
"$ref": "#/$defs/description"
}
}
},
{
"type": "object",
"title": "ModificationSplice",
"properties": {
"modification": {
"type": "object",
"properties": {
"action": {
"type": "string",
"const": "splice"
},
"path": {
"$ref": "#/$defs/path"
},
"start": {
"type": "number"
},
"deleteCount": {
"type": "number"
},
"items": {
"type": "array",
"items": {
"$ref": "#/$defs/value"
}
}
}
},
{
"type": "object"
"description": {
"$ref": "#/$defs/description"
}
]
}
},
"description": {
"type": "string",
"minLength": 2
{
"type": "object",
"title": "ModificationPush",
"properties": {
"modification": {
"type": "object",
"properties": {
"action": {
"type": "string",
"const": "push"
},
"path": {
"$ref": "#/$defs/path"
},
"items": {
"type": "array",
"items": {
"$ref": "#/$defs/value"
}
}
}
},
"description": {
"$ref": "#/$defs/description"
}
}
}
}
]
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions ext/js/pages/settings/recommended-settings-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export class RecommendedSettingsController {
}

// Render checkbox
/** @type {HTMLInputElement} */
const checkbox = querySelectorNotNull(template, 'input[type="checkbox"]');
const checkbox = /** @type {HTMLInputElement} */ (querySelectorNotNull(template, 'input[type="checkbox"]'));
checkbox.value = path;

Check failure on line 73 in ext/js/pages/settings/recommended-settings-controller.js

View workflow job for this annotation

GitHub Actions / Static Analysis

Unsafe assignment of an `any` value

settingsList.append(template);
Expand All @@ -84,7 +83,7 @@ export class RecommendedSettingsController {
*/
_onApplyButtonClicked(e) {
e.preventDefault();
/** @type {HTMLInputElement[]} */
/** @type {NodeListOf<HTMLInputElement>} */
const enabledCheckboxes = querySelectorNotNull(document, '#recommended-settings-list').querySelectorAll('input[type="checkbox"]:checked');
if (enabledCheckboxes.length > 0) {
const recommendedSettings = this._settingsController.getRecommendedSettings(this._languageSelect.value);
Expand Down
2 changes: 1 addition & 1 deletion test/data/json.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
{
"path": "ext/data/recommended-settings.json",
"typeFile": "types/ext/settings-controller.d.ts",
"type": "LanguageSettingOverrides",
"type": "RecommendedSettingsByLanguage",
"schema": "ext/data/schemas/recommended-settings-schema.json"
}
]
Expand Down
13 changes: 6 additions & 7 deletions types/ext/settings-controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type * as Core from './core';
import type * as Settings from './settings';
import type * as SettingsModifications from './settings-modifications';
import type {EventNames, EventArgument as BaseEventArgument} from './core';
import type {Modification} from './settings-modifications';

export type PageExitPrevention = {
end: () => void;
Expand Down Expand Up @@ -58,13 +59,11 @@ export type SettingsExtraFields<THasScope extends boolean> = THasScope extends t

export type ModifyResult = Core.Response<SettingsModifications.ModificationResult>;

export type RecommendedSettingsByLanguage = {
[key: string]: RecommendedSetting[];
};

export type RecommendedSetting = {
action: string;
path: string;
value: string;
modification: Modification;
description: string;
};

export type RecommendedSettingsByLanguage = {
[key: string]: RecommendedSetting[];
};

0 comments on commit 4c10eab

Please sign in to comment.