mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: upgrade react 18
This commit is contained in:
@ -9,13 +9,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"react": "^17.0.2",
|
"react": "^18.0.0",
|
||||||
"react-dom": "^17.0.2"
|
"react-dom": "^18.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash-es": "^4.17.5",
|
"@types/lodash-es": "^4.17.5",
|
||||||
"@types/react": "^17.0.2",
|
"@types/react": "^17.0.43",
|
||||||
"@types/react-dom": "^17.0.2",
|
"@types/react-dom": "^17.0.14",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
||||||
"@typescript-eslint/parser": "^5.6.0",
|
"@typescript-eslint/parser": "^5.6.0",
|
||||||
"@vitejs/plugin-react": "^1.0.0",
|
"@vitejs/plugin-react": "^1.0.0",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"prettier": "2.5.1",
|
"prettier": "2.5.1",
|
||||||
"tailwindcss": "^3.0.18",
|
"tailwindcss": "^3.0.18",
|
||||||
"typescript": "^4.3.2",
|
"typescript": "^4.3.2",
|
||||||
"vite": "^2.6.14"
|
"vite": "^2.9.0"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import ReactDOM from "react-dom";
|
import { createRoot } from "react-dom/client";
|
||||||
import appContext from "../stores/appContext";
|
import appContext from "../stores/appContext";
|
||||||
import Provider from "../labs/Provider";
|
import Provider from "../labs/Provider";
|
||||||
import appStore from "../stores/appStore";
|
import appStore from "../stores/appStore";
|
||||||
@ -39,6 +39,7 @@ export function showDialog<T extends DialogProps>(
|
|||||||
props?: Omit<T, "destroy">
|
props?: Omit<T, "destroy">
|
||||||
): DialogCallback {
|
): DialogCallback {
|
||||||
const tempDiv = document.createElement("div");
|
const tempDiv = document.createElement("div");
|
||||||
|
const dialog = createRoot(tempDiv);
|
||||||
document.body.append(tempDiv);
|
document.body.append(tempDiv);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -50,8 +51,8 @@ export function showDialog<T extends DialogProps>(
|
|||||||
tempDiv.firstElementChild?.classList.remove("showup");
|
tempDiv.firstElementChild?.classList.remove("showup");
|
||||||
tempDiv.firstElementChild?.classList.add("showoff");
|
tempDiv.firstElementChild?.classList.add("showoff");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
dialog.unmount();
|
||||||
tempDiv.remove();
|
tempDiv.remove();
|
||||||
ReactDOM.unmountComponentAtNode(tempDiv);
|
|
||||||
}, ANIMATION_DURATION);
|
}, ANIMATION_DURATION);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -75,7 +76,7 @@ export function showDialog<T extends DialogProps>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReactDOM.render(Fragment, tempDiv);
|
dialog.render(Fragment);
|
||||||
|
|
||||||
return cbs;
|
return cbs;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import ReactDOM from "react-dom";
|
import { createRoot, Root } from "react-dom/client";
|
||||||
import { TOAST_ANIMATION_DURATION } from "../helpers/consts";
|
import { TOAST_ANIMATION_DURATION } from "../helpers/consts";
|
||||||
import "../less/toast.less";
|
import "../less/toast.less";
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ const Toast: React.FC<ToastItemProps> = (props: ToastItemProps) => {
|
|||||||
class ToastHelper {
|
class ToastHelper {
|
||||||
private shownToastAmount = 0;
|
private shownToastAmount = 0;
|
||||||
private toastWrapper: HTMLDivElement;
|
private toastWrapper: HTMLDivElement;
|
||||||
private shownToastContainers: HTMLDivElement[] = [];
|
private shownToastContainers: [Root, HTMLDivElement][] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const wrapperClassName = "toast-list-container";
|
const wrapperClassName = "toast-list-container";
|
||||||
@ -63,10 +63,11 @@ class ToastHelper {
|
|||||||
|
|
||||||
private showToast = (config: ToastConfig) => {
|
private showToast = (config: ToastConfig) => {
|
||||||
const tempDiv = document.createElement("div");
|
const tempDiv = document.createElement("div");
|
||||||
|
const toast = createRoot(tempDiv);
|
||||||
tempDiv.className = `toast-wrapper ${config.type}`;
|
tempDiv.className = `toast-wrapper ${config.type}`;
|
||||||
this.toastWrapper.appendChild(tempDiv);
|
this.toastWrapper.appendChild(tempDiv);
|
||||||
this.shownToastAmount++;
|
this.shownToastAmount++;
|
||||||
this.shownToastContainers.push(tempDiv);
|
this.shownToastContainers.push([toast, tempDiv]);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
tempDiv.classList.add("showup");
|
tempDiv.classList.add("showup");
|
||||||
@ -83,9 +84,9 @@ class ToastHelper {
|
|||||||
|
|
||||||
this.shownToastAmount--;
|
this.shownToastAmount--;
|
||||||
if (this.shownToastAmount === 0) {
|
if (this.shownToastAmount === 0) {
|
||||||
for (const d of this.shownToastContainers) {
|
for (const [root, tempDiv] of this.shownToastContainers) {
|
||||||
ReactDOM.unmountComponentAtNode(d);
|
root.unmount();
|
||||||
d.remove();
|
tempDiv.remove();
|
||||||
}
|
}
|
||||||
this.shownToastContainers.splice(0, this.shownToastContainers.length);
|
this.shownToastContainers.splice(0, this.shownToastContainers.length);
|
||||||
}
|
}
|
||||||
@ -93,7 +94,7 @@ class ToastHelper {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ReactDOM.render(<Toast {...config} destory={cbs.destory} />, tempDiv);
|
toast.render(<Toast {...config} destory={cbs.destory} />);
|
||||||
|
|
||||||
return cbs;
|
return cbs;
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom";
|
import { createRoot } from "react-dom/client";
|
||||||
import Provider from "./labs/Provider";
|
import Provider from "./labs/Provider";
|
||||||
import appContext from "./stores/appContext";
|
import appContext from "./stores/appContext";
|
||||||
import appStore from "./stores/appStore";
|
import appStore from "./stores/appStore";
|
||||||
@ -8,11 +8,12 @@ import "./helpers/polyfill";
|
|||||||
import "./less/global.less";
|
import "./less/global.less";
|
||||||
import "./css/index.css";
|
import "./css/index.css";
|
||||||
|
|
||||||
ReactDOM.render(
|
const container = document.getElementById("root");
|
||||||
|
const root = createRoot(container as HTMLElement);
|
||||||
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Provider store={appStore} context={appContext}>
|
<Provider store={appStore} context={appContext}>
|
||||||
<App />
|
<App />
|
||||||
</Provider>
|
</Provider>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>
|
||||||
document.getElementById("root")
|
|
||||||
);
|
);
|
||||||
|
1758
web/yarn.lock
1758
web/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user