mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-31 20:08:35 +00:00
Prefer JS function over arrow functions (#8307)
* Prefer JS function over arrow functions * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
def8adf618
commit
97e490381f
4 changed files with 33 additions and 32 deletions
|
|
@ -5,25 +5,25 @@ import type { Message, PluginMessageEvent } from "../../src/globals";
|
|||
import type { EventTS } from "../../shared/universals";
|
||||
import { generateSlintSnippet } from "./property-parsing.js";
|
||||
|
||||
export const dispatch = (data: any, origin = "*") => {
|
||||
export function dispatch(data: any, origin = "*") {
|
||||
figma.ui.postMessage(data, {
|
||||
origin,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const dispatchTS = <Key extends keyof EventTS>(
|
||||
export function dispatchTS<Key extends keyof EventTS>(
|
||||
event: Key,
|
||||
data: EventTS[Key],
|
||||
origin = "*",
|
||||
) => {
|
||||
) {
|
||||
dispatch({ type: event, ...data }, origin);
|
||||
};
|
||||
}
|
||||
|
||||
export const listenTS = <Key extends keyof EventTS>(
|
||||
export function listenTS<Key extends keyof EventTS>(
|
||||
eventName: Key,
|
||||
callback: (data: EventTS[Key] & { type: Key }) => any,
|
||||
listenOnce = false,
|
||||
) => {
|
||||
) {
|
||||
const func = (pluginMessage: any) => {
|
||||
if (pluginMessage && pluginMessage.type === eventName) {
|
||||
callback(pluginMessage);
|
||||
|
|
@ -34,12 +34,13 @@ export const listenTS = <Key extends keyof EventTS>(
|
|||
};
|
||||
|
||||
figma.ui.on("message", func);
|
||||
};
|
||||
export const getStore = async (key: string) => {
|
||||
}
|
||||
|
||||
export async function getStore(key: string) {
|
||||
const value = await figma.clientStorage.getAsync(key);
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
export const setStore = async (key: string, value: string) => {
|
||||
export async function setStore(key: string, value: string) {
|
||||
await figma.clientStorage.setAsync(key, value);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import OnigurumaEngine from "shiki/wasm";
|
|||
import slintLang from "../../../../editors/vscode/slint.tmLanguage.json";
|
||||
|
||||
let highlighter: HighlighterCore | null = null;
|
||||
const initHighlighter = async () => {
|
||||
async function initHighlighter() {
|
||||
highlighter = await createHighlighterCore({
|
||||
themes: [
|
||||
darkSlint as ThemeRegistration,
|
||||
|
|
@ -30,7 +30,7 @@ const initHighlighter = async () => {
|
|||
langs: [slintLang as LanguageRegistration],
|
||||
engine: createOnigurumaEngine(OnigurumaEngine),
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
type HighlightTheme = "dark-slint" | "light-slint";
|
||||
|
||||
|
|
|
|||
|
|
@ -5,28 +5,28 @@ import { manifest } from "../../figma.config";
|
|||
import type { Message, PluginMessageEvent } from "../globals";
|
||||
import type { EventTS } from "../../shared/universals";
|
||||
|
||||
export const dispatch = (msg: Message, global = false, origin = "*") => {
|
||||
export function dispatch(msg: Message, global = false, origin = "*") {
|
||||
const data: PluginMessageEvent = { pluginMessage: msg };
|
||||
if (!global) {
|
||||
data.pluginId = manifest.id;
|
||||
}
|
||||
parent.postMessage(data, origin);
|
||||
};
|
||||
}
|
||||
|
||||
export const dispatchTS = <Key extends keyof EventTS>(
|
||||
export function dispatchTS<Key extends keyof EventTS>(
|
||||
event: Key, // Parameter name is 'event'
|
||||
data: EventTS[Key],
|
||||
global = false,
|
||||
origin = "*",
|
||||
) => {
|
||||
) {
|
||||
dispatch({ type: event, ...data }, global, origin);
|
||||
};
|
||||
}
|
||||
|
||||
export const listenTS = <Key extends keyof EventTS>(
|
||||
export function listenTS<Key extends keyof EventTS>(
|
||||
eventName: Key,
|
||||
callback: (data: EventTS[Key]) => any,
|
||||
listenOnce = false,
|
||||
) => {
|
||||
) {
|
||||
const func = (event: MessageEvent<any>) => {
|
||||
// --- Check for pluginMessage existence ---
|
||||
if (event.data && event.data.pluginMessage) {
|
||||
|
|
@ -43,9 +43,9 @@ export const listenTS = <Key extends keyof EventTS>(
|
|||
}
|
||||
};
|
||||
window.addEventListener("message", func);
|
||||
};
|
||||
}
|
||||
|
||||
export const getColorTheme = () => {
|
||||
export function getColorTheme(): "light" | "dark" {
|
||||
if (window?.matchMedia) {
|
||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
return "dark";
|
||||
|
|
@ -55,11 +55,11 @@ export const getColorTheme = () => {
|
|||
}
|
||||
}
|
||||
return "light";
|
||||
};
|
||||
}
|
||||
|
||||
export const subscribeColorTheme = (
|
||||
export function subscribeColorTheme(
|
||||
callback: (mode: "light" | "dark") => void,
|
||||
) => {
|
||||
) {
|
||||
if (window?.matchMedia) {
|
||||
window
|
||||
.matchMedia("(prefers-color-scheme: dark)")
|
||||
|
|
@ -71,4 +71,4 @@ export const subscribeColorTheme = (
|
|||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ export function writeTextToClipboard(str: string): boolean {
|
|||
return copySuccessful;
|
||||
}
|
||||
|
||||
export const downloadZipFile = async (
|
||||
export async function downloadZipFile(
|
||||
files: Array<{ name: string; content: string }>,
|
||||
) => {
|
||||
) {
|
||||
try {
|
||||
if (!files || files.length === 0) {
|
||||
console.error("No files to zip!");
|
||||
|
|
@ -79,9 +79,9 @@ export const downloadZipFile = async (
|
|||
}, index * 100);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const downloadFile = (filename: string, text: string) => {
|
||||
function downloadFile(filename: string, text: string) {
|
||||
const element = document.createElement("a");
|
||||
element.setAttribute(
|
||||
"href",
|
||||
|
|
@ -92,4 +92,4 @@ const downloadFile = (filename: string, text: string) => {
|
|||
document.body.appendChild(element);
|
||||
element.click();
|
||||
document.body.removeChild(element);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue