From e02c6176f99418682f7a8873371ad964b026fe4c Mon Sep 17 00:00:00 2001 From: Muhammed-Rahif Date: Fri, 3 Jan 2025 20:40:19 +0530 Subject: [PATCH] refactor: code modularity --- package.json | 1 - pnpm-lock.yaml | 12 -- src/App.svelte | 13 +- src/app.css | 4 +- .../images/{favicon.png => favicon-light.png} | Bin src/lib/components/AboutDialog.svelte | 4 +- src/lib/components/EditorTabs.svelte | 6 +- src/lib/components/EditorTitle.svelte | 3 +- src/lib/components/Loading.svelte | 10 +- src/lib/components/StatusBar.svelte | 6 +- src/lib/components/editor/Editor.svelte | 7 +- src/lib/components/editor/FakeCaret.svelte | 42 +++---- .../components/font-dialog/FontDialog.svelte | 10 +- .../font-dialog/FontFamilyCombobox.svelte | 20 +-- .../font-dialog/FontSizeCombobox.svelte | 22 ++-- src/lib/components/menubar/MenuBar.svelte | 5 +- .../components/menubar/SettingsMenu.svelte | 110 ++++++++--------- src/lib/components/menubar/ViewMenu.svelte | 3 +- src/lib/components/ui/sonner/sonner.svelte | 2 - src/lib/helpers/menubar/file-options.ts | 6 +- src/lib/helpers/notpad.ts | 1 + src/lib/helpers/settings.ts | 95 +++++++++++--- src/lib/helpers/type-effect-player.ts | 14 +-- src/lib/types/GithubApiType.ts | 1 + src/lib/types/SettingsType.ts | 116 +++--------------- tailwind.config.ts | 1 - 26 files changed, 241 insertions(+), 273 deletions(-) rename src/assets/images/{favicon.png => favicon-light.png} (100%) diff --git a/package.json b/package.json index 700e0f61..2b31a3fa 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,6 @@ "lodash.debounce": "^4.0.8", "lodash.merge": "^4.6.2", "lodash.throttle": "^4.1.1", - "mode-watcher": "^0.5.0", "print-js": "^1.6.0", "quill": "^2.0.3", "screenfull": "^6.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb5d3be8..c88ca12d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,9 +47,6 @@ importers: lodash.throttle: specifier: ^4.1.1 version: 4.1.1 - mode-watcher: - specifier: ^0.5.0 - version: 0.5.0(svelte@5.3.0) print-js: specifier: ^1.6.0 version: 1.6.0 @@ -2854,11 +2851,6 @@ packages: mkdirp-classic@0.5.3: resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==} - mode-watcher@0.5.0: - resolution: {integrity: sha512-5E6fh/aXhAVv+U+DbeM0hCmskQE9u7WSmvnCRijJB/MJu7HtB73sjiCaZ9n1M8QHmzLrBFo8XBAUcWXkDm8Z9A==} - peerDependencies: - svelte: ^4.0.0 || ^5.0.0-next.1 - mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} @@ -7089,10 +7081,6 @@ snapshots: mkdirp-classic@0.5.3: {} - mode-watcher@0.5.0(svelte@5.3.0): - dependencies: - svelte: 5.3.0 - mri@1.2.0: {} ms@2.1.3: {} diff --git a/src/App.svelte b/src/App.svelte index 99c7935a..77d30cfb 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,12 +1,11 @@ {#await Notpad.init()} @@ -37,9 +40,9 @@ {/await} - + - {#if $mode == 'dark'} + {#if $settings.theme == 'dark'} {:else} diff --git a/src/app.css b/src/app.css index 4ed589e7..d59098d8 100644 --- a/src/app.css +++ b/src/app.css @@ -34,7 +34,7 @@ --sidebar-ring: 217.2 91.2% 59.8%; } - .dark { + [data-theme='dark'] { --background: 0 0% 3.9%; --foreground: 0 0% 98%; --muted: 0 0% 14.9%; @@ -81,7 +81,7 @@ body, } * { - @apply scrollbar scrollbar-track-neutral-100 scrollbar-thumb-foreground/20 scrollbar-corner-foreground/5 scrollbar-thumb-rounded-md scrollbar-w-1.5 scrollbar-h-1 [font-optical-sizing:auto] dark:scrollbar-track-neutral-900; + @apply scrollbar scrollbar-track-muted scrollbar-thumb-foreground/20 scrollbar-corner-foreground/5 scrollbar-thumb-rounded-md scrollbar-w-1.5 scrollbar-h-1 [font-optical-sizing:auto]; } /* For icons default values */ diff --git a/src/assets/images/favicon.png b/src/assets/images/favicon-light.png similarity index 100% rename from src/assets/images/favicon.png rename to src/assets/images/favicon-light.png diff --git a/src/lib/components/AboutDialog.svelte b/src/lib/components/AboutDialog.svelte index a4070b80..18968405 100644 --- a/src/lib/components/AboutDialog.svelte +++ b/src/lib/components/AboutDialog.svelte @@ -6,13 +6,13 @@ import GitHubIcon from '@/components/icons/GitHub.svelte'; import Separator from '@/components/ui/separator/separator.svelte'; import { Badge } from '@/components/ui/badge'; - import { mode } from 'mode-watcher'; import { Notpad } from '@/helpers/notpad'; import { slide } from 'svelte/transition'; import appJson from '@/src/app.json'; import { tick } from 'svelte'; const open = Notpad.dialogs.about; + const settings = Notpad.stores.settings; function closeDialog() { open.set(false); @@ -39,7 +39,7 @@
- icon + icon
Notpad
diff --git a/src/lib/components/EditorTabs.svelte b/src/lib/components/EditorTabs.svelte index 8be83cea..b3ab92dd 100644 --- a/src/lib/components/EditorTabs.svelte +++ b/src/lib/components/EditorTabs.svelte @@ -3,12 +3,14 @@ import * as Tabs from '@/components/ui/tabs'; import * as ContextMenu from '@/components/ui/context-menu'; import EditorTitle from '@/components/EditorTitle.svelte'; - import { activeTabId, editors } from '@/store/store'; import { slide } from 'svelte/transition'; import EditMenuItems from '@/components/EditMenuItems.svelte'; + import { Notpad } from '@/helpers/notpad'; - let innerWidth = $state(window.innerWidth); + const activeTabId = Notpad.stores.activeTabId; + const editors = Notpad.stores.editors; + let innerWidth = $state(window.innerWidth); let isMD = $derived(innerWidth <= 768); /** * Compact mode is disabled on mobile devices (width <= 450px) diff --git a/src/lib/components/EditorTitle.svelte b/src/lib/components/EditorTitle.svelte index b18c3d20..15bd2780 100644 --- a/src/lib/components/EditorTitle.svelte +++ b/src/lib/components/EditorTitle.svelte @@ -2,7 +2,6 @@ import { Notpad } from '@/helpers/notpad'; import { tick } from 'svelte'; import { longpress } from '@/actions/longpress'; - import { activeTabId } from '@/store/store'; import * as Tooltip from '@/components/ui/tooltip'; import CloseIcon from '@/components/icons/Close.svelte'; import Button from '@/components/ui/button/button.svelte'; @@ -15,6 +14,8 @@ } const maxlength = 54; + const activeTabId = Notpad.stores.activeTabId; + let { editor }: Props = $props(); let readonly = $state(true); let input: HTMLInputElement = $state(null!); diff --git a/src/lib/components/Loading.svelte b/src/lib/components/Loading.svelte index 5910521d..f3b51478 100644 --- a/src/lib/components/Loading.svelte +++ b/src/lib/components/Loading.svelte @@ -1,8 +1,10 @@
- icon + icon
diff --git a/src/lib/components/StatusBar.svelte b/src/lib/components/StatusBar.svelte index 50209d3a..6e419089 100644 --- a/src/lib/components/StatusBar.svelte +++ b/src/lib/components/StatusBar.svelte @@ -1,9 +1,7 @@ -{#if $settings.caret.enable} - -{/if} +