fix deeplClone
This commit is contained in:
parent
611ac7db24
commit
1022a8b50a
|
|
@ -1,12 +1,13 @@
|
|||
import { NodeModel } from "@minoru/react-dnd-treeview";
|
||||
import { ReactElement } from "react";
|
||||
import { clientStartSync } from "../../../utils/sync/ws-client";
|
||||
import { IItem, MItem } from "../../../utils/types/item";
|
||||
import { DCode, DComp, DPage, IRoot } from "../../../utils/types/root";
|
||||
import { ISection } from "../../../utils/types/section";
|
||||
import { IText, MText } from "../../../utils/types/text";
|
||||
import { deepClone } from "web-utils";
|
||||
import { SAction } from "../../../../../srv/ws/sync/actions";
|
||||
import { ActivityList } from "../../../../../srv/ws/sync/type";
|
||||
import { clientStartSync } from "../../../utils/sync/ws-client";
|
||||
import { IItem, MItem } from "../../../utils/types/item";
|
||||
import { DComp, DPage, IRoot } from "../../../utils/types/root";
|
||||
import { ISection } from "../../../utils/types/section";
|
||||
import { IText, MText } from "../../../utils/types/text";
|
||||
|
||||
export const EmptySite = {
|
||||
id: "",
|
||||
|
|
@ -71,7 +72,7 @@ export const EDGlobal = {
|
|||
| "page-not-found"
|
||||
| "ready",
|
||||
sync: null as unknown as Awaited<ReturnType<typeof clientStartSync>>,
|
||||
site: structuredClone(EmptySite),
|
||||
site: deepClone(EmptySite),
|
||||
activity: {
|
||||
page: {} as Record<string, ActivityList>,
|
||||
comp: {} as Record<string, ActivityList>,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { compress, decompress } from "wasm-gzip";
|
||||
import { deepClone } from "web-utils";
|
||||
import { Y } from "../../../../../srv/ws/sync/entity/docs";
|
||||
import { clientStartSync } from "../../../utils/sync/ws-client";
|
||||
import { w } from "../../../utils/types/general";
|
||||
import { Loading } from "../../../utils/ui/loading";
|
||||
import { EmptySite, PG } from "./ed-global";
|
||||
import { Y } from "../../../../../srv/ws/sync/entity/docs";
|
||||
import { treeRebuild } from "./tree/build";
|
||||
import { w } from "../../../utils/types/general";
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ export const edInitSync = (p: PG) => {
|
|||
if (p.sync) {
|
||||
if (p.site.id === "--loading--") return false;
|
||||
if (params.site_id !== p.site.id) {
|
||||
p.site = structuredClone(EmptySite);
|
||||
p.site = deepClone(EmptySite);
|
||||
p.site.id = "--loading--";
|
||||
p.sync.site.load(params.site_id).then((site) => {
|
||||
if (site) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { forwardRef } from "react";
|
||||
import { useGlobal, useLocal } from "web-utils";
|
||||
import { deepClone, useGlobal, useLocal } from "web-utils";
|
||||
import { EDGlobal } from "../../../logic/ed-global";
|
||||
import { apiRef, apiUrl, checkAPI, dev, server } from "./api-utils";
|
||||
import { EdApiDB } from "./api-db";
|
||||
import { EdApiDomain } from "./api-domain";
|
||||
import { EdApiDeploy } from "./api-deploy";
|
||||
import { EdApiDomain } from "./api-domain";
|
||||
import { apiRef, apiUrl, checkAPI, dev, server } from "./api-utils";
|
||||
|
||||
export const EdApiServer = forwardRef<
|
||||
HTMLDivElement,
|
||||
|
|
@ -50,7 +50,7 @@ export const EdApiServer = forwardRef<
|
|||
if (typeof res === "object") {
|
||||
local.db = res.db;
|
||||
local.domains = res.domains;
|
||||
local.oldDB = structuredClone(res.db);
|
||||
local.oldDB = deepClone(res.db);
|
||||
local.hasDB = res.hasDB;
|
||||
local.status = "online";
|
||||
if (res.deploy) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { useGlobal, useLocal } from "web-utils";
|
||||
import { createAPI } from "../../../../../../utils/script/init-api";
|
||||
import { EditorGlobal, PG } from "../../../../logic/global";
|
||||
import { AutoHeightTextarea } from "../../../../../../utils/ui/auto-textarea";
|
||||
import { useEffect } from "react";
|
||||
import trim from "lodash.trim";
|
||||
import { formatDistance } from "date-fns/esm";
|
||||
import { format } from "date-fns";
|
||||
import { formatDistance } from "date-fns/esm";
|
||||
import trim from "lodash.trim";
|
||||
import { useEffect } from "react";
|
||||
import { deepClone, useGlobal, useLocal } from "web-utils";
|
||||
import { createAPI } from "../../../../../../utils/script/init-api";
|
||||
import { AutoHeightTextarea } from "../../../../../../utils/ui/auto-textarea";
|
||||
import { EditorGlobal } from "../../../../logic/global";
|
||||
|
||||
const server = {
|
||||
status: "ready" as
|
||||
|
|
@ -27,11 +27,11 @@ const DefaultLocal = {
|
|||
|
||||
export const ExternalDeploy = () => {
|
||||
const p = useGlobal(EditorGlobal, "EDITOR");
|
||||
const local = useLocal(structuredClone(DefaultLocal));
|
||||
const local = useLocal(deepClone(DefaultLocal));
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const newlocal = structuredClone(DefaultLocal);
|
||||
const newlocal = deepClone(DefaultLocal);
|
||||
for (const [k, v] of Object.entries(newlocal)) {
|
||||
(local as any)[k] = v;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import get from "lodash.get";
|
|||
import set from "lodash.set";
|
||||
import uniqBy from "lodash.uniqby";
|
||||
import { FC } from "react";
|
||||
import { deepClone } from "web-utils";
|
||||
import { IContent, MContent } from "../../../../../utils/types/general";
|
||||
import { NodeMeta, PG } from "../../../logic/global";
|
||||
import { fillID } from "../../../tools/fill-id";
|
||||
|
|
@ -216,7 +217,7 @@ export const selectMultiple = (p: PG, node: NodeModel<NodeMeta>) => {
|
|||
|
||||
export const flatTree = (item: Array<IContent>) => {
|
||||
const children = item as Array<IContent>;
|
||||
let ls = structuredClone(item);
|
||||
let ls = deepClone(item);
|
||||
let sitem: any = ls.map((v: IContent) => {
|
||||
if (v.type !== "text") {
|
||||
v.childs = [];
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import find from "lodash.find";
|
||||
import get from "lodash.get";
|
||||
import set from "lodash.set";
|
||||
import { deepClone } from "web-utils";
|
||||
import { IContent } from "../../../utils/types/general";
|
||||
|
||||
export const flatTree = (item: Array<IContent>) => {
|
||||
const children = item as Array<IContent>;
|
||||
let ls = structuredClone(item);
|
||||
let ls = deepClone(item);
|
||||
let sitem: any = ls.map((v: IContent) => {
|
||||
if (v.type !== "text") {
|
||||
v.childs = [];
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
import structuredClone from "@ungap/structured-clone";
|
||||
import { FC, useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { GlobalContext, defineReact, defineWindow } from "web-utils";
|
||||
import { siteLoader } from "./site-loader";
|
||||
|
||||
if (!("structuredClone" in (window as any))) {
|
||||
(window as any).structuredClone = structuredClone;
|
||||
}
|
||||
|
||||
const w = window as unknown as {
|
||||
prasiContext: any;
|
||||
rootRender: any;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/ungap__structured-clone": "^0.3.1",
|
||||
"@ungap/structured-clone": "^1.2.0",
|
||||
"brotli-wasm": "^2.0.1",
|
||||
"fdir": "^6.1.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,22 +80,22 @@ export const useGlobal = <T extends object>(
|
|||
|
||||
return res as any;
|
||||
};
|
||||
export const deepClone = (object: any): any => {
|
||||
export const deepClone = <T extends object>(object: T): T => {
|
||||
if (null == object || typeof object != "object") return object;
|
||||
// Handle Date
|
||||
if (object instanceof Date) {
|
||||
var copy = new Date();
|
||||
copy.setTime(object.getTime());
|
||||
return copy;
|
||||
return copy as T;
|
||||
}
|
||||
if (object instanceof Array) {
|
||||
return object.map((item) => deepClone(item));
|
||||
return object.map((item) => deepClone(item)) as T;
|
||||
}
|
||||
|
||||
var newObject: any = {};
|
||||
for (var key in object) {
|
||||
if (typeof object[key] === "object") {
|
||||
newObject[key] = deepClone(object[key]);
|
||||
newObject[key] = deepClone((object as any)[key]);
|
||||
} else {
|
||||
newObject[key] = object[key];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue