A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
themebuilder: fix various bugs
Abdullah Atta18d0b7278548
diff --git a/apps/theme-builder/package-lock.json b/apps/theme-builder/package-lock.jsonindex ba5e14f19..9b2058ac2 100644--- a/apps/theme-builder/package-lock.json+++ b/apps/theme-builder/package-lock.json@@ -17,6 +17,7 @@"@notesnook/web": "file:../web","@theme-ui/components": "^0.14.7","@theme-ui/core": "^0.14.7",+ "clipboard-polyfill": "^4.0.0","file-saver": "^2.0.5","katex": "^0.16.2","react": "17.0.2",@@ -1386,7 +1387,7 @@},"../web": {"name": "@notesnook/web",- "version": "2.6.0",+ "version": "2.6.1","license": "GPL-3.0-or-later","dependencies": {"@aws-sdk/util-base64-browser": "^3.208.0",@@ -2023,32 +2024,6 @@"node": ">=6.0.0"}},- "node_modules/@jridgewell/source-map": {- "version": "0.3.3",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true,- "dependencies": {- "@jridgewell/gen-mapping": "^0.3.0",- "@jridgewell/trace-mapping": "^0.3.9"- }- },- "node_modules/@jridgewell/source-map/node_modules/@jridgewell/gen-mapping": {- "version": "0.3.3",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true,- "dependencies": {- "@jridgewell/set-array": "^1.0.1",- "@jridgewell/sourcemap-codec": "^1.4.10",- "@jridgewell/trace-mapping": "^0.3.9"- },- "engines": {- "node": ">=6.0.0"- }- },"node_modules/@jridgewell/sourcemap-codec": {"version": "1.4.14","dev": true,@@ -2777,13 +2752,6 @@"ieee754": "^1.2.1"}},- "node_modules/buffer-from": {- "version": "1.1.2",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true- },"node_modules/cac": {"version": "6.7.14","dev": true,@@ -2869,6 +2837,11 @@"node": "*"}},+ "node_modules/clipboard-polyfill": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/clipboard-polyfill/-/clipboard-polyfill-4.0.0.tgz",+ "integrity": "sha512-U4KPNJqAYuyOtixCZZUyWTcj+wlI66j07g5ggMRE2DR1VFu/3ZWXkjLAslmme8i065gBSCUblHET7DKQ2Xg3RA=="+ },"node_modules/cliui": {"version": "8.0.1","dev": true,@@ -4272,27 +4245,6 @@"node": ">=0.10.0"}},- "node_modules/source-map-support": {- "version": "0.5.21",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true,- "dependencies": {- "buffer-from": "^1.0.0",- "source-map": "^0.6.0"- }- },- "node_modules/source-map-support/node_modules/source-map": {- "version": "0.6.1",- "dev": true,- "license": "BSD-3-Clause",- "optional": true,- "peer": true,- "engines": {- "node": ">=0.10.0"- }- },"node_modules/stackback": {"version": "0.0.2","dev": true,@@ -4393,32 +4345,6 @@"dev": true,"license": "MIT"},- "node_modules/terser": {- "version": "5.17.7",- "dev": true,- "license": "BSD-2-Clause",- "optional": true,- "peer": true,- "dependencies": {- "@jridgewell/source-map": "^0.3.3",- "acorn": "^8.8.2",- "commander": "^2.20.0",- "source-map-support": "~0.5.20"- },- "bin": {- "terser": "bin/terser"- },- "engines": {- "node": ">=10"- }- },- "node_modules/terser/node_modules/commander": {- "version": "2.20.3",- "dev": true,- "license": "MIT",- "optional": true,- "peer": true- },"node_modules/time-zone": {"version": "1.0.0","dev": true,diff --git a/apps/theme-builder/package.json b/apps/theme-builder/package.jsonindex 84114dd5a..f8655beb3 100644--- a/apps/theme-builder/package.json+++ b/apps/theme-builder/package.json@@ -9,13 +9,14 @@"license": "GPL-3.0-or-later","dependencies": {"@emotion/react": "11.11.1",+ "@mdi/js": "^7.2.96",+ "@mdi/react": "^1.6.1","@notesnook/common": "file:../../packages/common","@notesnook/theme": "file:../../packages/theme","@notesnook/web": "file:../web",- "@mdi/js": "^7.2.96",- "@mdi/react": "^1.6.1","@theme-ui/components": "^0.14.7","@theme-ui/core": "^0.14.7",+ "clipboard-polyfill": "^4.0.0","file-saver": "^2.0.5","katex": "^0.16.2","react": "17.0.2",diff --git a/apps/theme-builder/src/components/theme-builder/index.tsx b/apps/theme-builder/src/components/theme-builder/index.tsxindex bff2e1869..66b6ff0cc 100644--- a/apps/theme-builder/src/components/theme-builder/index.tsx+++ b/apps/theme-builder/src/components/theme-builder/index.tsx@@ -35,6 +35,10 @@ import { showFilePicker, readFile } from "@notesnook/web/src/utils/file-picker";import Field from "@notesnook/web/src/components/field";import { Close } from "@notesnook/web/src/components/icons";import { flatten, unflatten } from "../../utils/object";+import { version } from "../../../package.json";+import { writeText } from "clipboard-polyfill";+import { tryParse } from "@notesnook/web/src/utils/parse";+import { loadThemeFromJSON } from "../../utils/theme-loader";const JSON_SCHEMA_URL ="https://raw.githubusercontent.com/streetwriters/notesnook-themes/main/schemas/v1.schema.json";@@ -121,21 +125,7 @@ export default function ThemeBuilder() {}, [authors, setTheme]);return loading ? null : (- <Flex- sx={{- width: 260,- flexShrink: 0,- bg: "background",- display: "flex",- overflow: "hidden",- flexDirection: "column",- overflowY: "scroll",- pt: 2,- rowGap: 2,- borderLeft: "1px solid var(--border)",- zIndex: 999- }}- >+ <><Flexsx={{justifyContent: "space-between",@@ -143,7 +133,7 @@ export default function ThemeBuilder() {paddingX: "10px"}}>- <Text variant="title">Theme Builder 1.0</Text>+ <Text variant="title">Theme Builder {version}</Text></Flex><Flex@@ -170,6 +160,23 @@ export default function ThemeBuilder() {Export theme</Text></Button>+ <Button+ sx={{ py: "7px" }}+ variant="secondary"+ onClick={() =>+ writeText(themeToJSON(currentTheme)).then(() =>+ showToast("success", "Copied!")+ )+ }+ >+ <Text+ sx={{+ fontSize: "12px"+ }}+ >+ Copy to clipboard+ </Text>+ </Button><Buttonsx={{ py: "7px" }}variant="secondary"@@ -198,6 +205,34 @@ export default function ThemeBuilder() {</Text></Button>+ <Button+ sx={{ py: "7px" }}+ variant="secondary"+ onClick={async () => {+ try {+ setLoading(true);+ const text = window.prompt("Paste your JSON here");+ if (!text) return null;+ const theme = loadThemeFromJSON(tryParse(text));+ if (!theme) {+ showToast("error", "Please copy a valid JSON theme.");+ return;+ }+ setTheme(theme);+ } finally {+ setLoading(false);+ }+ }}+ >+ <Text+ sx={{+ fontSize: "12px"+ }}+ >+ Load from JSON+ </Text>+ </Button>+<Fieldlabel="Search & Replace"name="Search"@@ -254,7 +289,7 @@ export default function ThemeBuilder() {<Flexas="form"- key={currentTheme.id}+ key={getThemeKey(currentTheme)}id="theme-form"ref={formRef}onChange={onThemeChanged}@@ -270,7 +305,7 @@ export default function ThemeBuilder() {{Object.keys(ThemeInfoTemplate).map((key) => {return (<Field- key={key}+ key={`${getThemeKey(currentTheme)}-${key}`}label={toTitleCase(key)}name={key}defaultValue={currentThemeFlattened[key]}@@ -322,7 +357,7 @@ export default function ThemeBuilder() {{authors.map((author, index) => (<Flex- key={author.name}+ key={`${getThemeKey(currentTheme)}-${author.name}`}sx={{flexDirection: "column"}}@@ -549,7 +584,7 @@ export default function ThemeBuilder() {</>))}</Flex>- </Flex>+ </>);}@@ -604,19 +639,25 @@ function SelectItem(props: {}function exportTheme(theme: ThemeDefinition) {- const json = JSON.stringify({- ...theme,- $schema: JSON_SCHEMA_URL- });-FileSaver.saveAs(- new Blob([json], {+ new Blob([themeToJSON(theme)], {type: "text/plain"}),`${theme.id}.json`);}+function themeToJSON(theme: ThemeDefinition) {+ return JSON.stringify(+ {+ $schema: JSON_SCHEMA_URL,+ ...theme+ },+ undefined,+ 2+ );+}+const onChangeColor = (target: HTMLInputElement, sibling: HTMLInputElement) => {const value = target.value;if ((sibling as HTMLInputElement).value !== value) {@@ -660,3 +701,7 @@ function toTitleCase(value: string) {value.slice(1).replace(/([A-Z]+)*([A-Z][a-z])/g, "$1 $2"));}++function getThemeKey(theme: ThemeDefinition) {+ return `${theme.id}-${theme.version}-${theme.compatibilityVersion}`;+}