more optimization
This commit is contained in:
parent
1d45225336
commit
dce003d7f0
@ -10,7 +10,7 @@
|
|||||||
"@noble/hashes": "^1.2.0",
|
"@noble/hashes": "^1.2.0",
|
||||||
"@protobufjs/base64": "^1.1.2",
|
"@protobufjs/base64": "^1.1.2",
|
||||||
"@reduxjs/toolkit": "^1.9.1",
|
"@reduxjs/toolkit": "^1.9.1",
|
||||||
"@scure/bip32": "^1.1.5",
|
"@scure/bip32": "^1.3.0",
|
||||||
"@scure/bip39": "^1.1.1",
|
"@scure/bip39": "^1.1.1",
|
||||||
"@snort/nostr": "^1.0.0",
|
"@snort/nostr": "^1.0.0",
|
||||||
"@szhsin/react-menu": "^3.3.1",
|
"@szhsin/react-menu": "^3.3.1",
|
||||||
|
@ -3,7 +3,6 @@ import "./Textarea.css";
|
|||||||
|
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete";
|
import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete";
|
||||||
import emoji from "@jukben/emoji-search";
|
|
||||||
import TextareaAutosize from "react-textarea-autosize";
|
import TextareaAutosize from "react-textarea-autosize";
|
||||||
import { NostrPrefix } from "@snort/nostr";
|
import { NostrPrefix } from "@snort/nostr";
|
||||||
|
|
||||||
@ -61,8 +60,10 @@ const Textarea = (props: TextareaProps) => {
|
|||||||
return await UserCache.search(token);
|
return await UserCache.search(token);
|
||||||
};
|
};
|
||||||
|
|
||||||
const emojiDataProvider = (token: string) => {
|
const emojiDataProvider = async (token: string) => {
|
||||||
return emoji(token)
|
const emoji = await import("@jukben/emoji-search");
|
||||||
|
return emoji
|
||||||
|
.default(token)
|
||||||
.slice(0, 5)
|
.slice(0, 5)
|
||||||
.map(({ name, char }) => ({ name, char }));
|
.map(({ name, char }) => ({ name, char }));
|
||||||
};
|
};
|
||||||
|
@ -1,22 +1,7 @@
|
|||||||
import { type ReactNode } from "react";
|
import { useEffect, useState, type ReactNode } from "react";
|
||||||
import { IntlProvider as ReactIntlProvider } from "react-intl";
|
import { IntlProvider as ReactIntlProvider } from "react-intl";
|
||||||
|
|
||||||
import enMessages from "translations/en.json";
|
import enMessages from "translations/en.json";
|
||||||
import esMessages from "translations/es_ES.json";
|
|
||||||
import zhMessages from "translations/zh_CN.json";
|
|
||||||
import twMessages from "translations/zh_TW.json";
|
|
||||||
import jaMessages from "translations/ja_JP.json";
|
|
||||||
import frMessages from "translations/fr_FR.json";
|
|
||||||
import huMessages from "translations/hu_HU.json";
|
|
||||||
import idMessages from "translations/id_ID.json";
|
|
||||||
import arMessages from "translations/ar_SA.json";
|
|
||||||
import itMessages from "translations/it_IT.json";
|
|
||||||
import deMessages from "translations/de_DE.json";
|
|
||||||
import ruMessages from "translations/ru_RU.json";
|
|
||||||
import svMessages from "translations/sv_SE.json";
|
|
||||||
import hrMessages from "translations/hr_HR.json";
|
|
||||||
import taINMessages from "translations/ta_IN.json";
|
|
||||||
|
|
||||||
import useLogin from "Hooks/useLogin";
|
import useLogin from "Hooks/useLogin";
|
||||||
|
|
||||||
const DefaultLocale = "en-US";
|
const DefaultLocale = "en-US";
|
||||||
@ -24,65 +9,76 @@ const DefaultLocale = "en-US";
|
|||||||
const getMessages = (locale: string) => {
|
const getMessages = (locale: string) => {
|
||||||
const truncatedLocale = locale.toLowerCase().split(/[_-]+/)[0];
|
const truncatedLocale = locale.toLowerCase().split(/[_-]+/)[0];
|
||||||
|
|
||||||
const matchLang = (lng: string) => {
|
const matchLang = async (lng: string) => {
|
||||||
switch (lng) {
|
switch (lng) {
|
||||||
case "es-ES":
|
case "es-ES":
|
||||||
case "es":
|
case "es":
|
||||||
return esMessages;
|
return (await import("translations/es_ES.json")).default;
|
||||||
case "zh-CN":
|
case "zh-CN":
|
||||||
case "zh-Hans-CN":
|
case "zh-Hans-CN":
|
||||||
case "zh":
|
case "zh":
|
||||||
return zhMessages;
|
return (await import("translations/zh_CN.json")).default;
|
||||||
case "zh-TW":
|
case "zh-TW":
|
||||||
return twMessages;
|
return (await import("translations/zh_TW.json")).default;
|
||||||
case "ja-JP":
|
case "ja-JP":
|
||||||
case "ja":
|
case "ja":
|
||||||
return jaMessages;
|
return (await import("translations/ja_JP.json")).default;
|
||||||
case "fr-FR":
|
case "fr-FR":
|
||||||
case "fr":
|
case "fr":
|
||||||
return frMessages;
|
return (await import("translations/fr_FR.json")).default;
|
||||||
case "hu-HU":
|
case "hu-HU":
|
||||||
case "hu":
|
case "hu":
|
||||||
return huMessages;
|
return (await import("translations/hu_HU.json")).default;
|
||||||
case "id-ID":
|
case "id-ID":
|
||||||
case "id":
|
case "id":
|
||||||
return idMessages;
|
return (await import("translations/id_ID.json")).default;
|
||||||
case "ar-SA":
|
case "ar-SA":
|
||||||
case "ar":
|
case "ar":
|
||||||
return arMessages;
|
return (await import("translations/ar_SA.json")).default;
|
||||||
case "it-IT":
|
case "it-IT":
|
||||||
case "it":
|
case "it":
|
||||||
return itMessages;
|
return (await import("translations/it_IT.json")).default;
|
||||||
case "de-DE":
|
case "de-DE":
|
||||||
case "de":
|
case "de":
|
||||||
return deMessages;
|
return (await import("translations/de_DE.json")).default;
|
||||||
case "ru-RU":
|
case "ru-RU":
|
||||||
case "ru":
|
case "ru":
|
||||||
return ruMessages;
|
return (await import("translations/ru_RU.json")).default;
|
||||||
case "sv-SE":
|
case "sv-SE":
|
||||||
case "sv":
|
case "sv":
|
||||||
return svMessages;
|
return (await import("translations/sv_SE.json")).default;
|
||||||
case "hr-HR":
|
case "hr-HR":
|
||||||
case "hr":
|
case "hr":
|
||||||
return hrMessages;
|
return (await import("translations/hr_HR.json")).default;
|
||||||
case "ta-IN":
|
case "ta-IN":
|
||||||
case "ta":
|
case "ta":
|
||||||
return taINMessages;
|
return (await import("translations/ta_IN.json")).default;
|
||||||
case DefaultLocale:
|
case DefaultLocale:
|
||||||
case "en":
|
case "en":
|
||||||
return enMessages;
|
return enMessages;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return matchLang(locale) ?? matchLang(truncatedLocale) ?? enMessages;
|
return matchLang(locale) ?? matchLang(truncatedLocale) ?? Promise.resolve(enMessages);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IntlProvider = ({ children }: { children: ReactNode }) => {
|
export const IntlProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const { language } = useLogin().preferences;
|
const { language } = useLogin().preferences;
|
||||||
const locale = language ?? getLocale();
|
const locale = language ?? getLocale();
|
||||||
|
const [messages, setMessages] = useState<Record<string, string>>(enMessages);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getMessages(locale)
|
||||||
|
.then(x => {
|
||||||
|
if (x) {
|
||||||
|
setMessages(x);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}, [language]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactIntlProvider locale={locale} messages={getMessages(locale)}>
|
<ReactIntlProvider locale={locale} messages={messages}>
|
||||||
{children}
|
{children}
|
||||||
</ReactIntlProvider>
|
</ReactIntlProvider>
|
||||||
);
|
);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import "./Preferences.css";
|
import "./Preferences.css";
|
||||||
|
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
import emoji from "@jukben/emoji-search";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import useLogin from "Hooks/useLogin";
|
import useLogin from "Hooks/useLogin";
|
||||||
import { DefaultPreferences, updatePreferences, UserPreferences } from "Login";
|
import { DefaultPreferences, updatePreferences, UserPreferences } from "Login";
|
||||||
import { DefaultImgProxy } from "Const";
|
import { DefaultImgProxy } from "Const";
|
||||||
@ -32,6 +31,14 @@ const PreferencesPage = () => {
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
const perf = login.preferences;
|
const perf = login.preferences;
|
||||||
|
const [emoji, setEmoji] = useState<Array<{ name: string; char: string }>>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
const emoji = await import("@jukben/emoji-search");
|
||||||
|
setEmoji(emoji.default("").map(a => ({ name: a.name, char: a.char })));
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="preferences">
|
<div className="preferences">
|
||||||
@ -319,7 +326,7 @@ const PreferencesPage = () => {
|
|||||||
<option value="+">
|
<option value="+">
|
||||||
+ <FormattedMessage {...messages.Default} />
|
+ <FormattedMessage {...messages.Default} />
|
||||||
</option>
|
</option>
|
||||||
{emoji("").map(({ name, char }) => {
|
{emoji.map(({ name, char }) => {
|
||||||
return (
|
return (
|
||||||
<option value={char}>
|
<option value={char}>
|
||||||
{name} {char}
|
{name} {char}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const WorkboxWebpackPlugin = require("workbox-webpack-plugin");
|
const TerserPlugin = require("terser-webpack-plugin");
|
||||||
const ESLintPlugin = require("eslint-webpack-plugin");
|
const ESLintPlugin = require("eslint-webpack-plugin");
|
||||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||||
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
||||||
@ -78,7 +78,35 @@ const config = {
|
|||||||
optimization: {
|
optimization: {
|
||||||
usedExports: true,
|
usedExports: true,
|
||||||
chunkIds: "deterministic",
|
chunkIds: "deterministic",
|
||||||
minimizer: ["...", new CssMinimizerPlugin()],
|
minimize: isProduction,
|
||||||
|
minimizer: [
|
||||||
|
"...",
|
||||||
|
// same as https://github.com/facebook/create-react-app/blob/main/packages/react-scripts/config/webpack.config.js
|
||||||
|
new TerserPlugin({
|
||||||
|
terserOptions: {
|
||||||
|
parse: {
|
||||||
|
ecma: 8,
|
||||||
|
},
|
||||||
|
compress: {
|
||||||
|
ecma: 5,
|
||||||
|
warnings: false,
|
||||||
|
comparisons: false,
|
||||||
|
inline: 2,
|
||||||
|
},
|
||||||
|
mangle: {
|
||||||
|
safari10: true,
|
||||||
|
},
|
||||||
|
keep_classnames: isProduction,
|
||||||
|
keep_fnames: isProduction,
|
||||||
|
output: {
|
||||||
|
ecma: 5,
|
||||||
|
comments: false,
|
||||||
|
ascii_only: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new CssMinimizerPlugin(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".tsx", ".ts", ".jsx", ".js", "..."],
|
extensions: [".tsx", ".ts", ".jsx", ".js", "..."],
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
"main": "dist/lib.js",
|
"main": "dist/lib.js",
|
||||||
"types": "dist/src/index.d.ts",
|
"types": "dist/src/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf dist && webpack",
|
"build": "webpack --mode=production",
|
||||||
"watch": "rm -rf dist && webpack -w",
|
"watch": "webpack -w",
|
||||||
"clean": "rm -rf dist",
|
"clean": "rm -rf dist",
|
||||||
"test": "ts-mocha --type-check -j 1 --timeout 5s test/test.*.ts",
|
"test": "ts-mocha --type-check -j 1 --timeout 5s test/test.*.ts",
|
||||||
"test-browser": "ts-node test/browser/server.ts",
|
"test-browser": "ts-node test/browser/server.ts",
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
|
|
||||||
|
const isProduction = process.env.NODE_ENV == "production";
|
||||||
|
|
||||||
const entry = {
|
const entry = {
|
||||||
lib: "./src/index.ts",
|
lib: "./src/index.ts",
|
||||||
}
|
}
|
||||||
|
if (!isProduction) {
|
||||||
for (const file of fs.readdirSync("./test/")) {
|
for (const file of fs.readdirSync("./test/")) {
|
||||||
if (/.ts$/.test(file)) {
|
if (/.ts$/.test(file)) {
|
||||||
const name = file.replace(/.ts$/, "")
|
const name = file.replace(/.ts$/, "")
|
||||||
entry[`test/${name}`] = `./test/${file}`
|
entry[`test/${name}`] = `./test/${file}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: process.env.NODE_ENV || "development",
|
mode: process.env.NODE_ENV || "development",
|
||||||
devtool: "inline-source-map",
|
target: "browserslist",
|
||||||
|
devtool: isProduction ? "source-map" : "eval",
|
||||||
entry,
|
entry,
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".ts", ".js"],
|
extensions: [".ts", ".js"],
|
||||||
@ -27,9 +31,13 @@ module.exports = {
|
|||||||
output: {
|
output: {
|
||||||
filename: "[name].js",
|
filename: "[name].js",
|
||||||
path: `${__dirname}/dist`,
|
path: `${__dirname}/dist`,
|
||||||
|
clean: true,
|
||||||
library: {
|
library: {
|
||||||
type: "umd",
|
type: "umd",
|
||||||
name: "Nostr",
|
name: "Nostr",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
optimization: {
|
||||||
|
usedExports: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
19
yarn.lock
19
yarn.lock
@ -1565,20 +1565,13 @@
|
|||||||
"@lightninglabs/lnc-core" "0.2.3-alpha"
|
"@lightninglabs/lnc-core" "0.2.3-alpha"
|
||||||
crypto-js "4.1.1"
|
crypto-js "4.1.1"
|
||||||
|
|
||||||
"@noble/curves@^1.0.0":
|
"@noble/curves@^1.0.0", "@noble/curves@~1.0.0":
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.0.0.tgz#e40be8c7daf088aaf291887cbc73f43464a92932"
|
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.0.0.tgz#e40be8c7daf088aaf291887cbc73f43464a92932"
|
||||||
integrity sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==
|
integrity sha512-2upgEu0iLiDVDZkNLeFV2+ht0BAVgQnEmCk6JsOch9Rp8xfkMCbvbAZlA2pBHQc73dbl+vFOXfqkf4uemdn0bw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@noble/hashes" "1.3.0"
|
"@noble/hashes" "1.3.0"
|
||||||
|
|
||||||
"@noble/curves@~0.8.3":
|
|
||||||
version "0.8.3"
|
|
||||||
resolved "https://registry.npmjs.org/@noble/curves/-/curves-0.8.3.tgz"
|
|
||||||
integrity sha512-OqaOf4RWDaCRuBKJLDURrgVxjLmneGsiCXGuzYB5y95YithZMA6w4uk34DHSm0rKMrrYiaeZj48/81EvaAScLQ==
|
|
||||||
dependencies:
|
|
||||||
"@noble/hashes" "1.3.0"
|
|
||||||
|
|
||||||
"@noble/hashes@1.3.0", "@noble/hashes@^1.2.0", "@noble/hashes@~1.3.0":
|
"@noble/hashes@1.3.0", "@noble/hashes@^1.2.0", "@noble/hashes@~1.3.0":
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz"
|
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz"
|
||||||
@ -1924,12 +1917,12 @@
|
|||||||
resolved "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz"
|
resolved "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz"
|
||||||
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
|
integrity sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==
|
||||||
|
|
||||||
"@scure/bip32@^1.1.5":
|
"@scure/bip32@^1.3.0":
|
||||||
version "1.2.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.npmjs.org/@scure/bip32/-/bip32-1.2.0.tgz"
|
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.0.tgz#6c8d980ef3f290987736acd0ee2e0f0d50068d87"
|
||||||
integrity sha512-O+vT/hBVk+ag2i6j2CDemwd1E1MtGt+7O1KzrPNsaNvSsiEK55MyPIxJIMI2PS8Ijj464B2VbQlpRoQXxw1uHg==
|
integrity sha512-bcKpo1oj54hGholplGLpqPHRbIsnbixFtc06nwuNM5/dwSXOq/AAYoIBRsBmnZJSdfeNW5rnff7NTAz3ZCqR9Q==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@noble/curves" "~0.8.3"
|
"@noble/curves" "~1.0.0"
|
||||||
"@noble/hashes" "~1.3.0"
|
"@noble/hashes" "~1.3.0"
|
||||||
"@scure/base" "~1.1.0"
|
"@scure/base" "~1.1.0"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user