From 90ae22e54b2806c3a175688446aa3f6664294c33 Mon Sep 17 00:00:00 2001
From: Offroaders123 <65947371+Offroaders123@users.noreply.github.com>
Date: Mon, 10 Jul 2023 21:07:44 -0700
Subject: [PATCH] Further Module Types
Forgot to type out one of the modules, guess I missed it because it looked I had already edited it, while looking at the edited files diff in VSCode's Explorer. Going to push these changes to production now!
---
public/service-worker.js | 2 +-
src/Editor.ts | 10 ++++------
src/STE.ts | 2 +-
src/Workspace.ts | 41 ++++++++++++++++++++--------------------
4 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/public/service-worker.js b/public/service-worker.js
index 5bcb4d7..4d044da 100644
--- a/public/service-worker.js
+++ b/public/service-worker.js
@@ -4,7 +4,7 @@
var self = /** @type { ServiceWorkerGlobalScope } */ (/** @type { unknown } */ (globalThis));
const NAME = "Smart Text Editor";
-const VERSION = "v4.25.0";
+const VERSION = "v4.27.1";
const CACHE_NAME = /** @type { const } */ (`${NAME} ${VERSION}`);
const IS_MACOS_DEVICE = (/(macOS|Mac)/i.test(navigator.userAgentData?.platform ?? navigator.platform) && navigator.standalone === undefined);
diff --git a/src/Editor.ts b/src/Editor.ts
index 9317c15..be897b3 100644
--- a/src/Editor.ts
+++ b/src/Editor.ts
@@ -173,12 +173,10 @@ export class Editor extends NumTextElement {
return editorRename.blur();
}
- Object.assign(editorRename,{
- type: "text",
- placeholder: this.#name,
- tabIndex: -1,
- value: this.#name
- });
+ editorRename.type = "text";
+ editorRename.placeholder = this.#name;
+ editorRename.tabIndex = -1;
+ editorRename.value = this.#name;
editorRename.setAttribute("data-editor-rename","");
editorRename.style.setProperty("--editor-name-width",`${this.editorName.offsetWidth}px`);
diff --git a/src/STE.ts b/src/STE.ts
index 7a30299..9322f84 100644
--- a/src/STE.ts
+++ b/src/STE.ts
@@ -76,7 +76,7 @@ export class STE {
* Gets the inset values for the screen Safe Area.
*/
get safeAreaInsets(): SafeAreaInsets {
- function getSafeAreaInset(section: string){
+ function getSafeAreaInset(section: string): number {
return parseInt(getComputedStyle(document.documentElement).getPropertyValue(`--safe-area-inset-${section}`),10);
}
return {
diff --git a/src/Workspace.ts b/src/Workspace.ts
index be3a592..b67df36 100644
--- a/src/Workspace.ts
+++ b/src/Workspace.ts
@@ -3,6 +3,8 @@ import Editor from "./Editor.js";
import { workspace, view_menu, scaler, preview, preview_menu, workspace_tabs, header, getElementStyle } from "./dom.js";
import { read, stringify } from "nbtify";
+import type { EditorOptions } from "./Editor.js";
+
declare global {
interface Window {
setView: typeof setView;
@@ -34,7 +36,7 @@ export interface SetViewOptions {
/**
* Sets the View state of the app. If a View change is already in progress, and the force option is not set to `true`, the call will be skipped.
*/
-export function setView(type: View, { force = false }: SetViewOptions = {}){
+export function setView(type: View, { force = false }: SetViewOptions = {}): void {
if ((STE.orientationChange && !force) || STE.scalingChange) return;
const changeIdentifier = Math.random().toString();
document.body.setAttribute("data-view-change",changeIdentifier);
@@ -58,7 +60,7 @@ export type Orientation = "horizontal" | "vertical";
*
* @param orientation If an Orientation type is not provided, the current state will be toggled to the other option.
*/
-export function setOrientation(orientation?: Orientation){
+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}`));
@@ -78,7 +80,7 @@ export function setOrientation(orientation?: Orientation){
window.setTimeout(() => document.body.removeAttribute("data-orientation-change"),transitionDuration);
},transitionDuration);
- function setTransitionDurations(state: "on" | "off"){
+ function setTransitionDurations(state: "on" | "off"): void {
if (state == "on"){
workspace.style.removeProperty("transition-duration");
scaler.style.removeProperty("transition-duration");
@@ -99,7 +101,7 @@ export type SetPreviewSourceOptions =
/**
* Sets the source for the Preview to a given Editor.
*/
-export function setPreviewSource(options: SetPreviewSourceOptions){
+export function setPreviewSource(options: SetPreviewSourceOptions): void {
if ("activeEditor" in options || STE.previewEditor === options.identifier){
STE.previewEditor = "active-editor";
preview_menu.select("active-editor");
@@ -113,7 +115,7 @@ export function setPreviewSource(options: SetPreviewSourceOptions){
/**
* Creates a new Smart Text Editor window.
*/
-export function createWindow(){
+export function createWindow(): void {
const features = (STE.appearance.standalone || STE.appearance.fullscreen) ? "popup" : "",
win = window.open(window.location.href,"_blank",features);
@@ -132,12 +134,11 @@ export function createWindow(){
*
* If the File System Access API is supported in the user's browser, it will use that. If not, it will fall back to using an `` element.
*/
-export async function openFiles(){
+export async function openFiles(): Promise {
if (!STE.support.fileSystem){
- const input = Object.assign(document.createElement("input"),{
- type: "file",
- multiple: true
- });
+ const input = document.createElement("input");
+ input.type = "file";
+ input.multiple = true;
await new Promise(resolve => {
input.addEventListener("change",resolve,{ once: true });
@@ -146,15 +147,15 @@ export async function openFiles(){
if (input.files === null) return;
- const results = await Promise.allSettled([...input.files].map(async file => {
+ const results: PromiseSettledResult[] = await Promise.allSettled([...input.files].map(async file => {
const { name } = file;
const value = (name.match(/.(nbt|dat)$/)) ? await file.arrayBuffer().then(read).then(({ data }) => stringify(data,{ space: 2 })) : await file.text();
return { name, value };
}));
- const files = results
- .filter(/** @returns { result is PromiseFulfilledResult<{ name: string; value: string; }> } */
- (result): result is PromiseFulfilledResult<{ name: string; value: string; }> => result.status === "fulfilled")
+ const files: EditorOptions[] = results
+ .filter(
+ (result): result is PromiseFulfilledResult => result.status === "fulfilled")
.map(result => result.value);
for (const file of files){
@@ -179,7 +180,7 @@ export async function openFiles(){
*
* If the File System Access API is not supported, or if a custom file extension is provided for the current file, a Save As dialog will be shown using an `` element.
*/
-export async function saveFile(extension?: string){
+export async function saveFile(extension?: string): Promise {
if (extension || !STE.support.fileSystem){
if (!extension) extension = STE.query().getName("extension") ?? "";
const anchor = document.createElement("a"), link = window.URL.createObjectURL(new Blob([STE.query().textarea?.value ?? ""]));
@@ -216,7 +217,7 @@ export async function saveFile(extension?: string){
/**
* Creates a new Display window for the active Editor.
*/
-export function createDisplay(){
+export function createDisplay(): void {
const width = window.screen.availWidth * 2/3,
height = window.screen.availHeight * 2/3,
left = window.screen.availWidth / 2 + window.screen.availLeft - width / 2,
@@ -246,7 +247,7 @@ export interface RefreshPreviewOptions {
/**
* Refreshes the Preview with the latest source from the source Editor.
*/
-export function refreshPreview({ force = false }: RefreshPreviewOptions = {}){
+export function refreshPreview({ force = false }: RefreshPreviewOptions = {}): void {
if (STE.view == "code") return;
const editor = (STE.previewEditor == "active-editor") ? STE.query() : STE.query(STE.previewEditor);
if (!editor.tab || !editor.textarea) return;
@@ -267,7 +268,7 @@ export function refreshPreview({ force = false }: RefreshPreviewOptions = {}){
/**
* Sets the Split mode scaling when called from the Scaler's moving event listeners.
*/
-export function setScaling(event: MouseEvent | TouchEvent){
+export function setScaling(event: MouseEvent | TouchEvent): void {
const { safeAreaInsets } = STE.appearance;
let scalingOffset = 0;
const scalingRange = {
@@ -289,7 +290,7 @@ export function setScaling(event: MouseEvent | TouchEvent){
/**
* Removes the Split mode scale handling when the user finishes moving the Scaler.
*/
-export function disableScaling(event: MouseEvent | TouchEvent){
+export function disableScaling(event: MouseEvent | TouchEvent): void {
const touchEvent = (STE.environment.touchDevice && event instanceof TouchEvent);
document.removeEventListener((!touchEvent) ? "mousemove" : "touchmove",setScaling);
document.removeEventListener((!touchEvent) ? "mouseup" : "touchend",disableScaling);
@@ -299,7 +300,7 @@ export function disableScaling(event: MouseEvent | TouchEvent){
/**
* Resets the Split mode scaling offsets, making the Workspace responsive again.
*/
-function removeScaling(){
+function removeScaling(): void {
if (!document.body.hasAttribute("data-scaling-active")) return;
document.body.removeAttribute("data-scaling-active");
workspace.style.removeProperty("--scaling-offset");