From ab6701c50c88f8439464bf598788d1a01f4253c3 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Sun, 22 Oct 2023 19:05:48 +0800 Subject: [PATCH] feat: add shortcut for text save (close alist-org/alist#5396) --- package.json | 1 + pnpm-lock.yaml | 40 +++++++++++++++++++++++++ src/pages/home/previews/text-editor.tsx | 24 +++++++-------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5608cb7ce..ef5c0c629 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@monaco-editor/loader": "^1.3.2", "@motionone/solid": "^10.14.1", "@solid-primitives/i18n": "^1.1.0", + "@solid-primitives/keyboard": "^1.2.5", "@solid-primitives/storage": "^1.3.1", "@stitches/core": "^1.2.8", "aplayer": "^1.10.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c5a0744e1..452ccdf5e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ dependencies: '@solid-primitives/i18n': specifier: ^1.1.0 version: 1.1.0(solid-js@1.4.8) + '@solid-primitives/keyboard': + specifier: ^1.2.5 + version: 1.2.5(solid-js@1.4.8) '@solid-primitives/storage': specifier: ^1.3.1 version: 1.3.1(solid-js@1.4.8) @@ -627,6 +630,15 @@ packages: tslib: 2.4.0 dev: false + /@solid-primitives/event-listener@2.3.0(solid-js@1.4.8): + resolution: {integrity: sha512-0DS7DQZvCExWSpurVZC9/wjI8RmkhuOtWOy6Pp1Woq9ElMT9/bfjNpkwXsOwisLpcTqh9eUs17kp7jtpWcC20w==} + peerDependencies: + solid-js: ^1.6.12 + dependencies: + '@solid-primitives/utils': 6.2.1(solid-js@1.4.8) + solid-js: 1.4.8 + dev: false + /@solid-primitives/i18n@1.1.0(solid-js@1.4.8): resolution: {integrity: sha512-aqJttEb8rmsQTU5VqfBfaeHFMIqKu1eXHVEahtW4DGKYBz/CDis5V25psQEyspuVTmPs7RpX99Whe9jV7ib4pg==} peerDependencies: @@ -635,6 +647,17 @@ packages: solid-js: 1.4.8 dev: false + /@solid-primitives/keyboard@1.2.5(solid-js@1.4.8): + resolution: {integrity: sha512-1axfWM1T4ASzZp4D91vLtxARevlBuOQ6yFHr1/IkuM/7OhMLo/BrO2CcDu3vSwCPVOSiZ2P875bTiqVWQV6e5g==} + peerDependencies: + solid-js: ^1.6.12 + dependencies: + '@solid-primitives/event-listener': 2.3.0(solid-js@1.4.8) + '@solid-primitives/rootless': 1.4.2(solid-js@1.4.8) + '@solid-primitives/utils': 6.2.1(solid-js@1.4.8) + solid-js: 1.4.8 + dev: false + /@solid-primitives/props@2.2.2(solid-js@1.4.8): resolution: {integrity: sha512-vjRRoi/z3S2ylIJKCs+mN07oxDmt2S9gPCbTqkEx8jYHnvzocpt34UQdglLoSklTE6jI37JhW3g/Cs8Qr/peHg==} peerDependencies: @@ -644,6 +667,15 @@ packages: solid-js: 1.4.8 dev: false + /@solid-primitives/rootless@1.4.2(solid-js@1.4.8): + resolution: {integrity: sha512-ynI/2aEOPyc14IKCX6yDBqnsAYCoLbaP9V/jejEWMVKOT2ZdV2ZxdftaLimOpWPpvjyti5DUJIGTOfLaNb7jlg==} + peerDependencies: + solid-js: ^1.6.12 + dependencies: + '@solid-primitives/utils': 6.2.1(solid-js@1.4.8) + solid-js: 1.4.8 + dev: false + /@solid-primitives/storage@1.3.1(solid-js@1.4.8): resolution: {integrity: sha512-3By9cxqCGGkXrw3gYj7h2c5SCWxiDIYc2C3O6GLVyzN4JCIKzcMlm3HLK0gKMUbR/MzAs265XyAc3rqsMq1ixw==} peerDependencies: @@ -660,6 +692,14 @@ packages: solid-js: 1.4.8 dev: false + /@solid-primitives/utils@6.2.1(solid-js@1.4.8): + resolution: {integrity: sha512-TsecNzxiO5bLfzqb4OOuzfUmdOROcssuGqgh5rXMMaasoFZ3GoveUgdY1wcf17frMJM7kCNGNuK34EjErneZkg==} + peerDependencies: + solid-js: ^1.6.12 + dependencies: + solid-js: 1.4.8 + dev: false + /@stitches/core@1.2.8: resolution: {integrity: sha512-Gfkvwk9o9kE9r9XNBmJRfV8zONvXThnm1tcuojL04Uy5uRyqg93DC83lDebl0rocZCfKSjUv+fWYtMQmEDJldg==} dev: false diff --git a/src/pages/home/previews/text-editor.tsx b/src/pages/home/previews/text-editor.tsx index 1e910cf0f..b74441cf0 100644 --- a/src/pages/home/previews/text-editor.tsx +++ b/src/pages/home/previews/text-editor.tsx @@ -6,6 +6,7 @@ import { useFetch, useFetchText, useParseText, useRouter, useT } from "~/hooks" import { objStore, userCan } from "~/store" import { PEmptyResp } from "~/types" import { handleResp, notify, r } from "~/utils" +import { createShortcut } from "@solid-primitives/keyboard" function Editor(props: { data?: string | ArrayBuffer; contentType?: string }) { const { colorMode } = useColorMode() @@ -33,6 +34,15 @@ function Editor(props: { data?: string | ArrayBuffer; contentType?: string }) { }), ) + async function onSave() { + const resp = await save() + handleResp(resp, () => { + notify.success(t("global.save_success")) + }) + } + + createShortcut(["Control", "S"], onSave) + return ( @@ -47,19 +57,7 @@ function Editor(props: { data?: string | ArrayBuffer; contentType?: string }) { }} /> -