mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 09:18:11 +08:00
Clean up camelCase and snake_case in frontend code
This commit is contained in:
@@ -4,15 +4,15 @@ import { UpdateImageData } from "@/wasm-communication/messages";
|
||||
export function createBlobManager(editor: Editor): void {
|
||||
// Subscribe to process backend event
|
||||
editor.subscriptions.subscribeJsMessage(UpdateImageData, (updateImageData) => {
|
||||
updateImageData.image_data.forEach(async (element) => {
|
||||
// Using updateImageData.image_data.buffer returns undefined for some reason?
|
||||
const blob = new Blob([new Uint8Array(element.image_data.values()).buffer], { type: element.mime });
|
||||
updateImageData.imageData.forEach(async (element) => {
|
||||
// Using updateImageData.imageData.buffer returns undefined for some reason?
|
||||
const blob = new Blob([new Uint8Array(element.imageData.values()).buffer], { type: element.mime });
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const image = await createImageBitmap(blob);
|
||||
|
||||
editor.instance.set_image_blob_url(element.path, url, image.width, image.height);
|
||||
editor.instance.setImageBlobUrl(element.path, url, image.width, image.height);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ export function createClipboardManager(editor: Editor): void {
|
||||
// Subscribe to process backend event
|
||||
editor.subscriptions.subscribeJsMessage(TriggerTextCopy, (triggerTextCopy) => {
|
||||
// If the Clipboard API is supported in the browser, copy text to the clipboard
|
||||
navigator.clipboard?.writeText?.(triggerTextCopy.copy_text);
|
||||
navigator.clipboard?.writeText?.(triggerTextCopy.copyText);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
if (await shouldRedirectKeyboardEventToBackend(e)) {
|
||||
e.preventDefault();
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_key_down(key, modifiers);
|
||||
editor.instance.onKeyDown(key, modifiers);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
if (await shouldRedirectKeyboardEventToBackend(e)) {
|
||||
e.preventDefault();
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_key_up(key, modifiers);
|
||||
editor.instance.onKeyUp(key, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
}
|
||||
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_mouse_move(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
editor.instance.onMouseMove(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
}
|
||||
|
||||
function onPointerDown(e: PointerEvent): void {
|
||||
@@ -162,13 +162,13 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
}
|
||||
|
||||
if (!inTextInput) {
|
||||
if (textInput) editor.instance.on_change_text(textInputCleanup(textInput.innerText));
|
||||
if (textInput) editor.instance.onChangeText(textInputCleanup(textInput.innerText));
|
||||
else viewportPointerInteractionOngoing = isTargetingCanvas instanceof Element;
|
||||
}
|
||||
|
||||
if (viewportPointerInteractionOngoing) {
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_mouse_down(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
editor.instance.onMouseDown(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
|
||||
if (!textInput) {
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_mouse_up(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
editor.instance.onMouseUp(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
|
||||
if (!textInput) {
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_double_click(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
editor.instance.onDoubleClick(e.clientX, e.clientY, e.buttons, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
if (isTargetingCanvas) {
|
||||
e.preventDefault();
|
||||
const modifiers = makeKeyboardModifiersBitfield(e);
|
||||
editor.instance.on_wheel_scroll(e.clientX, e.clientY, e.buttons, e.deltaX, e.deltaY, e.deltaZ, modifiers);
|
||||
editor.instance.onWheelScroll(e.clientX, e.clientY, e.buttons, e.deltaX, e.deltaY, e.deltaZ, modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,20 +233,20 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
const flattened = boundsOfViewports.flat();
|
||||
const data = Float64Array.from(flattened);
|
||||
|
||||
if (boundsOfViewports.length > 0) editor.instance.bounds_of_viewports(data);
|
||||
if (boundsOfViewports.length > 0) editor.instance.boundsOfViewports(data);
|
||||
}
|
||||
|
||||
function onBeforeUnload(e: BeforeUnloadEvent): void {
|
||||
const activeDocument = document.state.documents[document.state.activeDocumentIndex];
|
||||
if (!activeDocument.is_saved) editor.instance.trigger_auto_save(activeDocument.id);
|
||||
if (!activeDocument.isSaved) editor.instance.triggerAutoSave(activeDocument.id);
|
||||
|
||||
// Skip the message if the editor crashed, since work is already lost
|
||||
if (editor.instance.has_crashed()) return;
|
||||
if (editor.instance.hasCrashed()) return;
|
||||
|
||||
// Skip the message during development, since it's annoying when testing
|
||||
if (process.env.NODE_ENV === "development") return;
|
||||
|
||||
const allDocumentsSaved = document.state.documents.reduce((acc, doc) => acc && doc.is_saved, true);
|
||||
const allDocumentsSaved = document.state.documents.reduce((acc, doc) => acc && doc.isSaved, true);
|
||||
if (!allDocumentsSaved) {
|
||||
e.returnValue = "Unsaved work will be lost if the web browser tab is closed. Close anyway?";
|
||||
e.preventDefault();
|
||||
@@ -262,7 +262,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
if (item.type === "text/plain") {
|
||||
item.getAsString((text) => {
|
||||
if (text.startsWith("graphite/layer: ")) {
|
||||
editor.instance.paste_serialized_data(text.substring(16, text.length));
|
||||
editor.instance.pasteSerializedData(text.substring(16, text.length));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -272,7 +272,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
file.arrayBuffer().then((buffer): void => {
|
||||
const u8Array = new Uint8Array(buffer);
|
||||
|
||||
editor.instance.paste_image(file.type, u8Array);
|
||||
editor.instance.pasteImage(file.type, u8Array);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -305,7 +305,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
const text = reader.result as string;
|
||||
|
||||
if (text.startsWith("graphite/layer: ")) {
|
||||
editor.instance.paste_serialized_data(text.substring(16, text.length));
|
||||
editor.instance.pasteSerializedData(text.substring(16, text.length));
|
||||
}
|
||||
};
|
||||
reader.readAsText(blob);
|
||||
@@ -319,7 +319,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
reader.onload = (): void => {
|
||||
const u8Array = new Uint8Array(reader.result as ArrayBuffer);
|
||||
|
||||
editor.instance.paste_image(imageType, u8Array);
|
||||
editor.instance.pasteImage(imageType, u8Array);
|
||||
};
|
||||
reader.readAsArrayBuffer(blob);
|
||||
}
|
||||
@@ -343,7 +343,7 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
|
||||
};
|
||||
const message = Object.entries(matchMessage).find(([key]) => String(err).includes(key))?.[1] || String(err);
|
||||
|
||||
editor.instance.error_dialog("Cannot access clipboard", message);
|
||||
editor.instance.errorDialog("Cannot access clipboard", message);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ export function createLocalizationManager(editor: Editor): void {
|
||||
|
||||
// Subscribe to process backend event
|
||||
editor.subscriptions.subscribeJsMessage(TriggerAboutGraphiteLocalizedCommitDate, (triggerAboutGraphiteLocalizedCommitDate) => {
|
||||
const localized = localizeTimestamp(triggerAboutGraphiteLocalizedCommitDate.commit_date);
|
||||
editor.instance.request_about_graphite_dialog_with_localized_commit_date(localized);
|
||||
const localized = localizeTimestamp(triggerAboutGraphiteLocalizedCommitDate.commitDate);
|
||||
editor.instance.requestAboutGraphiteDialogWithLocalizedCommitDate(localized);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export function createPanicManager(editor: Editor, dialogState: DialogState): vo
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(Error as any).stackTraceLimit = Infinity;
|
||||
const stackTrace = new Error().stack || "";
|
||||
const panicDetails = `${displayDialogPanic.panic_info}${stackTrace ? `\n\n${stackTrace}` : ""}`;
|
||||
const panicDetails = `${displayDialogPanic.panicInfo}${stackTrace ? `\n\n${stackTrace}` : ""}`;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(panicDetails);
|
||||
@@ -29,8 +29,7 @@ function preparePanicDialog(header: string, details: string, panicDetails: strin
|
||||
{ rowWidgets: [new Widget({ kind: "TextLabel", value: header, bold: true, italic: false, tableAlign: false, multiline: false }, 0n)] },
|
||||
{ rowWidgets: [new Widget({ kind: "TextLabel", value: details, bold: false, italic: false, tableAlign: false, multiline: true }, 1n)] },
|
||||
],
|
||||
// eslint-disable-next-line camelcase
|
||||
layout_target: null,
|
||||
layoutTarget: null,
|
||||
};
|
||||
|
||||
const reloadButton: TextButtonWidget = {
|
||||
|
||||
@@ -36,7 +36,7 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
|
||||
storeDocumentOrder();
|
||||
});
|
||||
editor.subscriptions.subscribeJsMessage(TriggerIndexedDbRemoveDocument, async (removeAutoSaveDocument) => {
|
||||
removeDocument(removeAutoSaveDocument.document_id);
|
||||
removeDocument(removeAutoSaveDocument.documentId);
|
||||
});
|
||||
|
||||
// Open the IndexedDB database connection and save it to this variable, which is a promise that resolves once the connection is open
|
||||
@@ -61,7 +61,7 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
|
||||
Error on opening IndexDB:
|
||||
${dbOpenRequest.error}
|
||||
`;
|
||||
editor.instance.error_dialog("Document auto-save doesn't work in this browser", errorText);
|
||||
editor.instance.errorDialog("Document auto-save doesn't work in this browser", errorText);
|
||||
};
|
||||
|
||||
dbOpenRequest.onsuccess = (): void => {
|
||||
@@ -82,10 +82,10 @@ export async function createPersistenceManager(editor: Editor, portfolio: Portfo
|
||||
.map((id) => previouslySavedDocuments.find((autoSave) => autoSave.details.id === id))
|
||||
.filter((x) => x !== undefined) as TriggerIndexedDbWriteDocument[];
|
||||
|
||||
const currentDocumentVersion = editor.instance.graphite_document_version();
|
||||
const currentDocumentVersion = editor.instance.graphiteDocumentVersion();
|
||||
orderedSavedDocuments.forEach((doc: TriggerIndexedDbWriteDocument) => {
|
||||
if (doc.version === currentDocumentVersion) {
|
||||
editor.instance.open_auto_saved_document(BigInt(doc.details.id), doc.details.name, doc.details.is_saved, doc.document);
|
||||
editor.instance.openAutoSavedDocument(BigInt(doc.details.id), doc.details.name, doc.details.isSaved, doc.document);
|
||||
} else {
|
||||
removeDocument(doc.details.id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user