Skip to content

Commit

Permalink
Strictness Checks
Browse files Browse the repository at this point in the history
Bringing over the stricter config from NBTify and my other projects :)
  • Loading branch information
Offroaders123 committed Sep 25, 2023
1 parent 78c65d3 commit 22efc71
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 160 deletions.
246 changes: 123 additions & 123 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"@stedit/num-text": "^1.0.1"
},
"devDependencies": {
"@types/prismjs": "^1.26.0",
"better-typescript": "^0.1.2",
"new-javascript": "^0.3.5",
"typescript": "^5.1.6",
"vite": "^4.4.2"
"@types/prismjs": "^1.26.1",
"better-typescript": "^0.1.6",
"new-javascript": "^0.3.6",
"typescript": "^5.2.2",
"vite": "^4.4.9"
}
}
2 changes: 1 addition & 1 deletion public/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var self = /** @type { ServiceWorkerGlobalScope } */ (/** @type { unknown } */ (globalThis));

const NAME = "Smart Text Editor";
const VERSION = "v4.27.3";
const VERSION = "v4.27.4";
const CACHE_NAME = /** @type { const } */ (`${NAME} ${VERSION}`);

const IS_MACOS_DEVICE = (/(macOS|Mac)/i.test(navigator.userAgentData?.platform ?? navigator.platform) && navigator.standalone === undefined);
Expand Down
14 changes: 7 additions & 7 deletions src/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export class Card extends HTMLElement {
if (!event.shiftKey){
if (document.activeElement != navigable[navigable.length - 1]) return;
event.preventDefault();
navigable[0].focus();
navigable[0]?.focus();
} else if (document.activeElement == navigable[0]){
event.preventDefault();
navigable[navigable.length - 1].focus();
navigable[navigable.length - 1]?.focus();
}
});
this.type = this.getAttribute("data-type");
Expand Down Expand Up @@ -76,7 +76,7 @@ export class Card extends HTMLElement {
if (card.type != "dialog" && card.type != this.type) return;
card.close();
if (!card.matches(".minimize")) return;
const transitionDuration = parseInt(`${Number(getElementStyle({ element: card, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: card, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`);
window.setTimeout(() => card.minimize(),transitionDuration);
});
}
Expand All @@ -98,7 +98,7 @@ export class Card extends HTMLElement {
STE.dialogPrevious = document.activeElement as Card;
}
document.querySelectorAll<MenuDropElement>("menu-drop[data-open]").forEach(menu => menu.close());
const transitionDuration = parseInt(`${Number(getElementStyle({ element: this, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 500}`);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: this, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 500}`);
window.setTimeout(() => {
if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
if (previous) this.querySelector<HTMLElement>(`[data-card-previous="${previous.id}"]`)!.focus();
Expand All @@ -115,7 +115,7 @@ export class Card extends HTMLElement {

this.setAttribute("data-minimize-change",changeIdentifier);
workspace_tabs.setAttribute("data-minimize-change",changeIdentifier);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: this, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: this, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`);
if (!this.matches(".minimize")){
this.classList.add("minimize");
if (this.controls === undefined) return;
Expand Down Expand Up @@ -147,7 +147,7 @@ export class Card extends HTMLElement {
close(): void {
this.classList.remove("active");
if (this.matches(".minimize")){
const transitionDuration = parseInt(`${Number(getElementStyle({ element: this, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: this, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`);
window.setTimeout(() => this.minimize(),transitionDuration);
}
if (this.type == "dialog"){
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Card extends HTMLElement {
if (!STE.activeDialog || event.key != "Tab" || document.activeElement != document.body) return;
const navigable = Card.#getNavigableElements({ container: STE.activeDialog, scope: true });
event.preventDefault();
navigable[((!event.shiftKey) ? 0 : navigable.length - 1)].focus();
navigable[((!event.shiftKey) ? 0 : navigable.length - 1)]?.focus();
}
}

Expand Down
23 changes: 13 additions & 10 deletions src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export class Editor extends NumTextElement {
*/
static open(identifier: string, options: EditorOpenOptions = {}): void {
const editor = this.#editors[identifier];
editor.open(options);
editor?.open(options);
}

/**
* Closes an Editor from a given identifier.
*/
static async close(identifier: string): Promise<void> {
const editor = this.#editors[identifier];
await editor.close();
await editor?.close();
}

/**
Expand All @@ -45,6 +45,9 @@ export class Editor extends NumTextElement {
*/
static rename(identifier: string, rename?: string): void {
const editor = this.#editors[identifier];
if (editor === undefined){
throw new Error(`Failed to rename editor '${identifier}', it may not exist`);
}
const currentName = editor.#name;

if (!rename){
Expand All @@ -62,12 +65,12 @@ export class Editor extends NumTextElement {
*
* If the active Editor is the first one in the Workspace, it will wrap around to give the last Editor in the Workspace.
*/
static getPrevious(identifier: string, wrap: boolean = true): string | null {
static getPrevious(identifier: string, _wrap: boolean = true): string | null {
const { tab } = STE.query(identifier);
if (tab === null) return tab;
const editorTabs = [...workspace_tabs.querySelectorAll(".tab:not([data-editor-change])")];
const previousTab = editorTabs[(editorTabs.indexOf(tab) || editorTabs.length) - 1];
const previousEditor = previousTab.getAttribute("data-editor-identifier");
const previousEditor = previousTab?.getAttribute("data-editor-identifier") ?? null;
return previousEditor;
}

Expand All @@ -76,12 +79,12 @@ export class Editor extends NumTextElement {
*
* If the active Editor is the last one in the Workspace, it will wrap around to give the first Editor in the Workspace.
*/
static getNext(identifier: string, wrap: boolean = true): string | null {
static getNext(identifier: string, _wrap: boolean = true): string | null {
const { tab } = STE.query(identifier);
if (tab === null) return tab;
const editorTabs = [...workspace_tabs.querySelectorAll(".tab:not([data-editor-change])")];
const nextTab = editorTabs[(editorTabs.indexOf(tab) !== editorTabs.length - 1) ? editorTabs.indexOf(tab) + 1 : 0];
const nextEditor = nextTab.getAttribute("data-editor-identifier");
const nextEditor = nextTab?.getAttribute("data-editor-identifier") ?? null;
return nextEditor;
}

Expand Down Expand Up @@ -136,7 +139,7 @@ export class Editor extends NumTextElement {
const changeIdentifier = Math.random().toString();

document.body.setAttribute("data-editor-change",changeIdentifier);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: workspace_tabs, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: workspace_tabs, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`);

this.tab.classList.add("tab");
this.tab.setAttribute("data-editor-identifier",this.identifier);
Expand Down Expand Up @@ -364,7 +367,7 @@ export class Editor extends NumTextElement {
}
}

const transitionDuration = (document.body.hasAttribute("data-editor-change")) ? parseInt(`${Number(getElementStyle({ element: workspace_tabs, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`) : 0;
const transitionDuration = (document.body.hasAttribute("data-editor-change")) ? parseInt(`${Number(getElementStyle({ element: workspace_tabs, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`) : 0;

if (this.tab === editorTabs[0] && editorTabs.length === 1){
STE.activeEditor = null;
Expand All @@ -381,11 +384,11 @@ export class Editor extends NumTextElement {
Editor.open(identifier);
}
if (this.tab === editorTabs[editorTabs.length - 1] && this.tab !== editorTabs[0] && this.tab.classList.contains("active")){
const identifier = editorTabs[editorTabs.length - 2].getAttribute("data-editor-identifier")!;
const identifier = editorTabs[editorTabs.length - 2]!.getAttribute("data-editor-identifier")!;
Editor.open(identifier);
}
if (this.tab !== editorTabs[0] && this.tab.classList.contains("active")){
const identifier = editorTabs[editorTabs.indexOf(this.tab) + 1].getAttribute("data-editor-identifier")!;
const identifier = editorTabs[editorTabs.indexOf(this.tab) + 1]!.getAttribute("data-editor-identifier")!;
Editor.open(identifier);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Tools {
},

clear(): void {
[replacer_find.value,replacer_replace.value] = "";
[replacer_find.value,replacer_replace.value] = ["",""];
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function setView(type: View, { force = false }: SetViewOptions = {}): voi
if ((STE.orientationChange && !force) || STE.scalingChange) return;
const changeIdentifier = Math.random().toString();
document.body.setAttribute("data-view-change",changeIdentifier);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: workspace, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`);
const transitionDuration = parseInt(`${Number(getElementStyle({ element: workspace, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`);
document.body.classList.remove(STE.view);
document.body.setAttribute("data-view",type);
document.body.classList.add(STE.view);
Expand All @@ -62,7 +62,7 @@ export type Orientation = "horizontal" | "vertical";
export function setOrientation(orientation?: Orientation): void {
if (STE.orientationChange || STE.scalingChange) return;
document.body.setAttribute("data-orientation-change","");
const param = (orientation), transitionDuration = ((STE.view != "split") ? 0 : parseInt(`${Number(getElementStyle({ element: workspace, property: "transition-duration" }).split(",")[0].replace(/s/g,"")) * 1000}`));
const param = (orientation), transitionDuration = ((STE.view != "split") ? 0 : parseInt(`${Number(getElementStyle({ element: workspace, property: "transition-duration" }).split(",")[0]!.replace(/s/g,"")) * 1000}`));
if (!param && STE.view == "split") setView("code",{ force: true });
if (!param && STE.orientation == "horizontal") orientation = "vertical";
if (!param && STE.orientation == "vertical") orientation = "horizontal";
Expand Down Expand Up @@ -197,8 +197,8 @@ export async function saveFile(extension?: string): Promise<void> {
});
if (!handle) return;
STE.fileHandles[identifier] = handle;
} else handle = STE.fileHandles[identifier];
const stream = await STE.fileHandles[identifier].createWritable().catch(error => {
} else handle = STE.fileHandles[identifier]!;
const stream = await STE.fileHandles[identifier]?.createWritable().catch(error => {
alert(`"${STE.query().getName()}" could not be saved.`);
if (error.toString().toLowerCase().includes("not allowed")) return;
});
Expand Down Expand Up @@ -276,8 +276,8 @@ export function setScaling(event: MouseEvent | TouchEvent): void {
};
const touchEvent = (STE.environment.touchDevice && event instanceof TouchEvent);

if (STE.orientation == "horizontal") scalingOffset = (!touchEvent) ? (event as MouseEvent).pageX : (event as TouchEvent).touches[0].pageX;
if (STE.orientation == "vertical") scalingOffset = (!touchEvent) ? (event as MouseEvent).pageY - header.offsetHeight : (event as TouchEvent).touches[0].pageY - header.offsetHeight;
if (STE.orientation == "horizontal") scalingOffset = (!touchEvent) ? (event as MouseEvent).pageX : (event as TouchEvent).touches[0]!.pageX;
if (STE.orientation == "vertical") scalingOffset = (!touchEvent) ? (event as MouseEvent).pageY - header.offsetHeight : (event as TouchEvent).touches[0]!.pageY - header.offsetHeight;
if (scalingOffset < scalingRange.minimum) scalingOffset = scalingRange.minimum;
if (scalingOffset > scalingRange.maximum) scalingOffset = scalingRange.maximum;
document.body.setAttribute("data-scaling-active","");
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ window.addEventListener("beforeinstallprompt",event => {
event.preventDefault();
STE.installPrompt = event;
document.documentElement.classList.add("install-prompt-available");
theme_button.childNodes[0].textContent = "Theme";
theme_button.childNodes[0]!.textContent = "Theme";
});

window.addEventListener("beforeunload",event => {
Expand Down
4 changes: 2 additions & 2 deletions src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function applyEditingBehavior(element: HTMLInputElement | NumTextElement)

(element as HTMLElement).addEventListener("drop",event => {
if (event.dataTransfer === null) return;
if ([...event.dataTransfer.items][0].kind === "file") return;
if ([...event.dataTransfer.items][0]?.kind === "file") return;
event.stopPropagation();
for (const menu of document.querySelectorAll<MenuDropElement>("menu-drop[data-open]")){
menu.close();
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function showInstallPrompt(): Promise<void> {
const result = await STE.installPrompt.userChoice;
if (result.outcome !== "accepted") return;
document.documentElement.classList.remove("install-prompt-available");
theme_button.childNodes[0].textContent = "Customize Theme";
theme_button.childNodes[0]!.textContent = "Customize Theme";
}

/**
Expand Down
12 changes: 8 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"module": "ESNext",
"moduleResolution": "NodeNext",
"isolatedModules": true,
"module": "NodeNext",
"target": "ESNext",
"isolatedModules": true,
"types": [
"@stedit/menu-drop",
"@stedit/num-text",
Expand All @@ -14,7 +13,12 @@
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"noImplicitOverride": true
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"allowUnreachableCode": false,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": [
"./dist"
Expand Down

0 comments on commit 22efc71

Please sign in to comment.