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