@dxos/plugin-explorer 0.8.4-main.67995b8 → 0.8.4-main.ae835ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/ExplorerContainer-L5RVUJRL.mjs +50 -0
- package/dist/lib/browser/ExplorerContainer-L5RVUJRL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-OAOY7SHY.mjs → chunk-2MKBRIUT.mjs} +6 -5
- package/dist/lib/browser/chunk-2MKBRIUT.mjs.map +7 -0
- package/dist/lib/browser/{chunk-J2BBZOSF.mjs → chunk-6BVXZQPP.mjs} +9 -8
- package/dist/lib/browser/chunk-6BVXZQPP.mjs.map +7 -0
- package/dist/lib/browser/chunk-BGNRYZUN.mjs +79 -0
- package/dist/lib/browser/chunk-BGNRYZUN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-PVFZFKQ6.mjs → chunk-CRN65FY3.mjs} +6 -246
- package/dist/lib/browser/{chunk-PVFZFKQ6.mjs.map → chunk-CRN65FY3.mjs.map} +3 -3
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/chunk-UBHZGWZQ.mjs +24 -0
- package/dist/lib/browser/chunk-UBHZGWZQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +27 -20
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/intent-resolver-FX5H52QN.mjs +31 -0
- package/dist/lib/browser/intent-resolver-FX5H52QN.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +2 -3
- package/dist/lib/browser/react-surface-VS3ZFL2Y.mjs +35 -0
- package/dist/lib/browser/react-surface-VS3ZFL2Y.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +7 -6
- package/dist/lib/node-esm/ExplorerContainer-BBLPHH7K.mjs +51 -0
- package/dist/lib/node-esm/ExplorerContainer-BBLPHH7K.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PPBUWC7F.mjs → chunk-3ODK27PU.mjs} +6 -5
- package/dist/lib/node-esm/chunk-3ODK27PU.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-4VMSNXYL.mjs → chunk-CRSVAZNA.mjs} +9 -8
- package/dist/lib/node-esm/chunk-CRSVAZNA.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-S5A2EUSJ.mjs → chunk-RSZFBKZM.mjs} +6 -246
- package/dist/lib/node-esm/{chunk-S5A2EUSJ.mjs.map → chunk-RSZFBKZM.mjs.map} +3 -3
- package/dist/lib/node-esm/chunk-TQESRBUJ.mjs +80 -0
- package/dist/lib/node-esm/chunk-TQESRBUJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PIAXA43R.mjs → chunk-UXZM5VJB.mjs} +8 -5
- package/dist/lib/node-esm/chunk-UXZM5VJB.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +27 -20
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/intent-resolver-RGBBXXYM.mjs +32 -0
- package/dist/lib/node-esm/intent-resolver-RGBBXXYM.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/meta.mjs +2 -3
- package/dist/lib/node-esm/react-surface-SXPT2T37.mjs +36 -0
- package/dist/lib/node-esm/react-surface-SXPT2T37.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +7 -6
- package/dist/types/src/ExplorerPlugin.d.ts +1 -1
- package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +2 -2
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +2 -2
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/Chart/Chart.d.ts.map +1 -1
- package/dist/types/src/components/Chart/Chart.stories.d.ts +8 -4
- package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
- package/dist/types/src/components/ExplorerContainer.d.ts +2 -2
- package/dist/types/src/components/ExplorerContainer.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +8 -4
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts +2 -2
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts +13 -4
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +13 -4
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/testing.d.ts +1 -1
- package/dist/types/src/components/Graph/testing.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts +13 -16
- package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tree/types/tree.d.ts +1 -1
- package/dist/types/src/components/Tree/types/tree.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/hooks/useGraphModel.d.ts +2 -2
- package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +14 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/ExplorerAction.d.ts +23 -0
- package/dist/types/src/types/ExplorerAction.d.ts.map +1 -0
- package/dist/types/src/types/Graph.d.ts +33 -0
- package/dist/types/src/types/Graph.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -42
- package/src/ExplorerPlugin.tsx +49 -47
- package/src/capabilities/intent-resolver.ts +10 -8
- package/src/capabilities/react-surface.tsx +9 -5
- package/src/components/Chart/Chart.stories.tsx +9 -7
- package/src/components/Chart/Chart.tsx +1 -1
- package/src/components/ExplorerContainer.tsx +24 -6
- package/src/components/Globe/Globe.stories.tsx +14 -12
- package/src/components/Globe/Globe.tsx +1 -1
- package/src/components/Graph/D3ForceGraph.stories.tsx +30 -17
- package/src/components/Graph/D3ForceGraph.tsx +5 -5
- package/src/components/Graph/ForceGraph.stories.tsx +30 -17
- package/src/components/Graph/ForceGraph.tsx +4 -4
- package/src/components/Graph/testing.ts +2 -2
- package/src/components/Tree/Tree.stories.tsx +28 -22
- package/src/components/Tree/Tree.tsx +3 -3
- package/src/components/Tree/types/tree.test.ts +2 -1
- package/src/components/Tree/types/tree.ts +1 -1
- package/src/hooks/useGraphModel.ts +5 -4
- package/src/meta.ts +7 -4
- package/src/translations.ts +4 -2
- package/src/types/ExplorerAction.ts +29 -0
- package/src/types/Graph.ts +45 -0
- package/src/types/index.ts +2 -2
- package/dist/lib/browser/ExplorerContainer-OGHSHZD5.mjs +0 -37
- package/dist/lib/browser/ExplorerContainer-OGHSHZD5.mjs.map +0 -7
- package/dist/lib/browser/chunk-EF4BFHTI.mjs +0 -38
- package/dist/lib/browser/chunk-EF4BFHTI.mjs.map +0 -7
- package/dist/lib/browser/chunk-J2BBZOSF.mjs.map +0 -7
- package/dist/lib/browser/chunk-OAOY7SHY.mjs.map +0 -7
- package/dist/lib/browser/chunk-UL5EDJPE.mjs +0 -21
- package/dist/lib/browser/chunk-UL5EDJPE.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-XH2UO2FM.mjs +0 -24
- package/dist/lib/browser/intent-resolver-XH2UO2FM.mjs.map +0 -7
- package/dist/lib/browser/react-surface-65VQ42HX.mjs +0 -31
- package/dist/lib/browser/react-surface-65VQ42HX.mjs.map +0 -7
- package/dist/lib/node-esm/ExplorerContainer-6ON5NA2P.mjs +0 -38
- package/dist/lib/node-esm/ExplorerContainer-6ON5NA2P.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4VMSNXYL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PIAXA43R.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PPBUWC7F.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VKCOKQRG.mjs +0 -39
- package/dist/lib/node-esm/chunk-VKCOKQRG.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-AGBBNA67.mjs +0 -25
- package/dist/lib/node-esm/intent-resolver-AGBBNA67.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-IJIMYAST.mjs +0 -32
- package/dist/lib/node-esm/react-surface-IJIMYAST.mjs.map +0 -7
- package/dist/types/src/types/schema.d.ts +0 -12
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -18
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/types/schema.ts +0 -16
- package/src/types/types.ts +0 -21
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useGraphModel
|
|
3
|
+
} from "./chunk-2MKBRIUT.mjs";
|
|
4
|
+
import {
|
|
5
|
+
D3ForceGraph
|
|
6
|
+
} from "./chunk-6BVXZQPP.mjs";
|
|
7
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
8
|
+
|
|
9
|
+
// src/components/ExplorerContainer.tsx
|
|
10
|
+
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
11
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
12
|
+
import { QueryBuilder } from "@dxos/echo-query";
|
|
13
|
+
import { useGlobalSearch } from "@dxos/plugin-search";
|
|
14
|
+
import { getSpace } from "@dxos/react-client/echo";
|
|
15
|
+
import { Toolbar } from "@dxos/react-ui";
|
|
16
|
+
import { QueryEditor } from "@dxos/react-ui-components";
|
|
17
|
+
import { StackItem } from "@dxos/react-ui-stack";
|
|
18
|
+
var ExplorerContainer = ({ role, view }) => {
|
|
19
|
+
var _effect = _useSignals();
|
|
20
|
+
try {
|
|
21
|
+
const space = getSpace(view);
|
|
22
|
+
const [filter, setFilter] = useState();
|
|
23
|
+
const model = useGraphModel(space, filter);
|
|
24
|
+
const { match } = useGlobalSearch();
|
|
25
|
+
const builder = useMemo(() => new QueryBuilder(), []);
|
|
26
|
+
const handleChange = useCallback((value) => {
|
|
27
|
+
setFilter(builder.build(value).filter);
|
|
28
|
+
}, []);
|
|
29
|
+
const showToolbar = role === "article";
|
|
30
|
+
if (!space || !model) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
34
|
+
toolbar: showToolbar
|
|
35
|
+
}, showToolbar && /* @__PURE__ */ React.createElement(Toolbar.Root, null, /* @__PURE__ */ React.createElement(QueryEditor, {
|
|
36
|
+
db: space.db,
|
|
37
|
+
onChange: handleChange
|
|
38
|
+
})), /* @__PURE__ */ React.createElement(D3ForceGraph, {
|
|
39
|
+
model,
|
|
40
|
+
match
|
|
41
|
+
}));
|
|
42
|
+
} finally {
|
|
43
|
+
_effect.f();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var ExplorerContainer_default = ExplorerContainer;
|
|
47
|
+
export {
|
|
48
|
+
ExplorerContainer_default as default
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=ExplorerContainer-L5RVUJRL.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ExplorerContainer.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useCallback, useMemo, useState } from 'react';\n\nimport { type Filter } from '@dxos/echo';\nimport { QueryBuilder } from '@dxos/echo-query';\nimport { useGlobalSearch } from '@dxos/plugin-search';\nimport { getSpace } from '@dxos/react-client/echo';\nimport { Toolbar } from '@dxos/react-ui';\nimport { QueryEditor, type QueryEditorProps } from '@dxos/react-ui-components';\nimport { StackItem } from '@dxos/react-ui-stack';\nimport { type DataType } from '@dxos/schema';\n\nimport { useGraphModel } from '../hooks';\n\nimport { D3ForceGraph } from './Graph';\n\ntype ExplorerContainerProps = {\n role: string;\n view: DataType.View;\n};\n\nconst ExplorerContainer = ({ role, view }: ExplorerContainerProps) => {\n const space = getSpace(view);\n const [filter, setFilter] = useState<Filter.Any>();\n const model = useGraphModel(space, filter);\n const { match } = useGlobalSearch();\n\n const builder = useMemo(() => new QueryBuilder(), []);\n const handleChange = useCallback<NonNullable<QueryEditorProps['onChange']>>((value) => {\n setFilter(builder.build(value).filter);\n }, []);\n\n const showToolbar = role === 'article';\n\n if (!space || !model) {\n return null;\n }\n\n return (\n <StackItem.Content toolbar={showToolbar}>\n {showToolbar && (\n <Toolbar.Root>\n <QueryEditor db={space.db} onChange={handleChange} />\n </Toolbar.Root>\n )}\n <D3ForceGraph model={model} match={match} />\n </StackItem.Content>\n );\n};\n\nexport default ExplorerContainer;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAIA,OAAOA,SAASC,aAAaC,SAASC,gBAAgB;AAGtD,SAASC,oBAAoB;AAC7B,SAASC,uBAAuB;AAChC,SAASC,gBAAgB;AACzB,SAASC,eAAe;AACxB,SAASC,mBAA0C;AACnD,SAASC,iBAAiB;AAY1B,IAAMC,oBAAoB,CAAC,EAAEC,MAAMC,KAAI,MAA0B;;;AAC/D,UAAMC,QAAQC,SAASF,IAAAA;AACvB,UAAM,CAACG,QAAQC,SAAAA,IAAaC,SAAAA;AAC5B,UAAMC,QAAQC,cAAcN,OAAOE,MAAAA;AACnC,UAAM,EAAEK,MAAK,IAAKC,gBAAAA;AAElB,UAAMC,UAAUC,QAAQ,MAAM,IAAIC,aAAAA,GAAgB,CAAA,CAAE;AACpD,UAAMC,eAAeC,YAAuD,CAACC,UAAAA;AAC3EX,gBAAUM,QAAQM,MAAMD,KAAAA,EAAOZ,MAAM;IACvC,GAAG,CAAA,CAAE;AAEL,UAAMc,cAAclB,SAAS;AAE7B,QAAI,CAACE,SAAS,CAACK,OAAO;AACpB,aAAO;IACT;AAEA,WACE,sBAAA,cAACY,UAAUC,SAAO;MAACC,SAASH;OACzBA,eACC,sBAAA,cAACI,QAAQC,MAAI,MACX,sBAAA,cAACC,aAAAA;MAAYC,IAAIvB,MAAMuB;MAAIC,UAAUZ;SAGzC,sBAAA,cAACa,cAAAA;MAAapB;MAAcE;;;;;AAGlC;AAEA,IAAA,4BAAeV;",
|
|
6
|
+
"names": ["React", "useCallback", "useMemo", "useState", "QueryBuilder", "useGlobalSearch", "getSpace", "Toolbar", "QueryEditor", "StackItem", "ExplorerContainer", "role", "view", "space", "getSpace", "filter", "setFilter", "useState", "model", "useGraphModel", "match", "useGlobalSearch", "builder", "useMemo", "QueryBuilder", "handleChange", "useCallback", "value", "build", "showToolbar", "StackItem", "Content", "toolbar", "Toolbar", "Root", "QueryEditor", "db", "onChange", "D3ForceGraph"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/hooks/useGraphModel.ts
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
import { SpaceGraphModel } from "@dxos/schema";
|
|
4
|
-
var useGraphModel = (space, filter, options) => {
|
|
4
|
+
var useGraphModel = (space, filter, options, queue) => {
|
|
5
5
|
const [model, setModel] = useState(void 0);
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
if (!space) {
|
|
@@ -9,9 +9,9 @@ var useGraphModel = (space, filter, options) => {
|
|
|
9
9
|
setModel(void 0);
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
if (!model) {
|
|
12
|
+
if (!model || model.queue !== queue) {
|
|
13
13
|
const model2 = new SpaceGraphModel().setFilter(filter).setOptions(options);
|
|
14
|
-
void model2.open(space);
|
|
14
|
+
void model2.open(space, queue);
|
|
15
15
|
setModel(model2);
|
|
16
16
|
} else {
|
|
17
17
|
model.setFilter(filter).setOptions(options);
|
|
@@ -19,7 +19,8 @@ var useGraphModel = (space, filter, options) => {
|
|
|
19
19
|
}, [
|
|
20
20
|
space,
|
|
21
21
|
filter,
|
|
22
|
-
options
|
|
22
|
+
options,
|
|
23
|
+
queue
|
|
23
24
|
]);
|
|
24
25
|
return model;
|
|
25
26
|
};
|
|
@@ -27,4 +28,4 @@ var useGraphModel = (space, filter, options) => {
|
|
|
27
28
|
export {
|
|
28
29
|
useGraphModel
|
|
29
30
|
};
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-2MKBRIUT.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useGraphModel.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Filter, type Queue, type Space } from '@dxos/client/echo';\nimport { SpaceGraphModel, type SpaceGraphModelOptions } from '@dxos/schema';\n\n// TODO(burdon): Factor out.\nexport const useGraphModel = (\n space: Space | undefined,\n filter?: Filter.Any | undefined,\n options?: SpaceGraphModelOptions,\n queue?: Queue,\n): SpaceGraphModel | undefined => {\n const [model, setModel] = useState<SpaceGraphModel | undefined>(undefined);\n useEffect(() => {\n if (!space) {\n void model?.close();\n setModel(undefined);\n return;\n }\n\n // TODO(burdon): Does this need to be a dependency?\n if (!model || model.queue !== queue) {\n const model = new SpaceGraphModel().setFilter(filter).setOptions(options);\n void model.open(space, queue);\n setModel(model);\n } else {\n model.setFilter(filter).setOptions(options);\n }\n }, [space, filter, options, queue]);\n\n return model;\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,WAAWC,gBAAgB;AAGpC,SAASC,uBAAoD;AAGtD,IAAMC,gBAAgB,CAC3BC,OACAC,QACAC,SACAC,UAAAA;AAEA,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAsCC,MAAAA;AAChEC,YAAU,MAAA;AACR,QAAI,CAACR,OAAO;AACV,WAAKI,OAAOK,MAAAA;AACZJ,eAASE,MAAAA;AACT;IACF;AAGA,QAAI,CAACH,SAASA,MAAMD,UAAUA,OAAO;AACnC,YAAMC,SAAQ,IAAIM,gBAAAA,EAAkBC,UAAUV,MAAAA,EAAQW,WAAWV,OAAAA;AACjE,WAAKE,OAAMS,KAAKb,OAAOG,KAAAA;AACvBE,eAASD,MAAAA;IACX,OAAO;AACLA,YAAMO,UAAUV,MAAAA,EAAQW,WAAWV,OAAAA;IACrC;EACF,GAAG;IAACF;IAAOC;IAAQC;IAASC;GAAM;AAElC,SAAOC;AACT;",
|
|
6
|
+
"names": ["useEffect", "useState", "SpaceGraphModel", "useGraphModel", "space", "filter", "options", "queue", "model", "setModel", "useState", "undefined", "useEffect", "close", "SpaceGraphModel", "setFilter", "setOptions", "open"]
|
|
7
|
+
}
|
|
@@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
|
4
4
|
import { Obj } from "@dxos/echo";
|
|
5
5
|
import { SelectionModel } from "@dxos/graph";
|
|
6
6
|
import { GraphForceProjector, SVG } from "@dxos/react-ui-graph";
|
|
7
|
-
import {
|
|
7
|
+
import { getHashStyles } from "@dxos/react-ui-theme";
|
|
8
8
|
import "@dxos/react-ui-graph/styles/graph.css";
|
|
9
9
|
var D3ForceGraph = ({ classNames, model, selection: _selection, grid, ...props }) => {
|
|
10
10
|
var _effect = _useSignals();
|
|
@@ -69,7 +69,7 @@ var D3ForceGraph = ({ classNames, model, selection: _selection, grid, ...props }
|
|
|
69
69
|
const obj = node.data?.data.object;
|
|
70
70
|
return {
|
|
71
71
|
data: {
|
|
72
|
-
color:
|
|
72
|
+
color: getHashStyles(obj && Obj.getTypename(obj))?.hue
|
|
73
73
|
},
|
|
74
74
|
classes: {
|
|
75
75
|
"dx-selected": selection.contains(node.id)
|
|
@@ -94,10 +94,11 @@ import { filterObjectsSync } from "@dxos/plugin-search";
|
|
|
94
94
|
|
|
95
95
|
// src/components/Graph/adapter.ts
|
|
96
96
|
var GraphAdapter = class {
|
|
97
|
+
graph;
|
|
98
|
+
_nodes = [];
|
|
99
|
+
_links = [];
|
|
97
100
|
constructor(graph) {
|
|
98
101
|
this.graph = graph;
|
|
99
|
-
this._nodes = [];
|
|
100
|
-
this._links = [];
|
|
101
102
|
this._nodes = graph.nodes.map((node) => ({
|
|
102
103
|
id: node.id,
|
|
103
104
|
type: node.type,
|
|
@@ -126,8 +127,8 @@ var ForceGraph = ({ model, match }) => {
|
|
|
126
127
|
refreshRate: 200
|
|
127
128
|
});
|
|
128
129
|
const rootRef = useRef2(null);
|
|
129
|
-
const forceGraph = useRef2();
|
|
130
|
-
const filteredRef = useRef2();
|
|
130
|
+
const forceGraph = useRef2(null);
|
|
131
|
+
const filteredRef = useRef2([]);
|
|
131
132
|
filteredRef.current = filterObjectsSync(model?.objects ?? [], match);
|
|
132
133
|
const [data, setData] = useState();
|
|
133
134
|
useEffect2(() => {
|
|
@@ -146,7 +147,7 @@ var ForceGraph = ({ model, match }) => {
|
|
|
146
147
|
nodes: [],
|
|
147
148
|
links: []
|
|
148
149
|
});
|
|
149
|
-
forceGraph.current =
|
|
150
|
+
forceGraph.current = null;
|
|
150
151
|
};
|
|
151
152
|
}, []);
|
|
152
153
|
useEffect2(() => {
|
|
@@ -184,4 +185,4 @@ export {
|
|
|
184
185
|
D3ForceGraph,
|
|
185
186
|
ForceGraph
|
|
186
187
|
};
|
|
187
|
-
//# sourceMappingURL=chunk-
|
|
188
|
+
//# sourceMappingURL=chunk-6BVXZQPP.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Graph/D3ForceGraph.tsx", "../../../src/components/Graph/ForceGraph.tsx", "../../../src/components/Graph/adapter.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\nimport { Obj } from '@dxos/echo';\nimport { SelectionModel } from '@dxos/graph';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport {\n type GraphController,\n GraphForceProjector,\n type GraphLayoutNode,\n type GraphProps,\n SVG,\n type SVGContext,\n} from '@dxos/react-ui-graph';\nimport { getHashStyles } from '@dxos/react-ui-theme';\nimport { type SpaceGraphEdge, type SpaceGraphModel, type SpaceGraphNode } from '@dxos/schema';\n\nimport '@dxos/react-ui-graph/styles/graph.css';\n\nexport type D3ForceGraphProps = ThemedClassName<\n {\n model?: SpaceGraphModel;\n match?: RegExp;\n selection?: SelectionModel;\n grid?: boolean;\n } & Pick<GraphProps, 'drag'>\n>;\n\nexport const D3ForceGraph = ({ classNames, model, selection: _selection, grid, ...props }: D3ForceGraphProps) => {\n const context = useRef<SVGContext>(null);\n const projector = useMemo<GraphForceProjector | undefined>(() => {\n if (context.current) {\n return new GraphForceProjector(context.current, {\n attributes: {\n linkForce: (edge) => {\n // TODO(burdon): Check type (currently assumes Employee property).\n // Edge shouldn't contribute to force if it's not active.\n return edge.data?.object?.active !== false;\n },\n },\n forces: {\n point: {\n strength: 0.01,\n },\n },\n });\n }\n }, [context.current]);\n\n const graph = useRef<GraphController>(null);\n const selection = useMemo(() => _selection ?? new SelectionModel(), [_selection]);\n useEffect(() => graph.current?.repaint(), [selection.selected.value]);\n\n const handleSelect = useCallback<NonNullable<GraphProps['onSelect']>>(\n (node) => {\n if (selection.contains(node.id)) {\n selection.remove(node.id);\n } else {\n selection.add(node.id);\n }\n },\n [selection],\n );\n\n return (\n <SVG.Root ref={context} classNames={classNames}>\n <SVG.Markers />\n {grid && <SVG.Grid axis />}\n <SVG.Zoom extent={[1 / 2, 2]}>\n <SVG.Graph<SpaceGraphNode, SpaceGraphEdge>\n {...props}\n ref={graph}\n model={model}\n projector={projector}\n labels={{\n text: (node) => {\n return node.data?.data.label ?? node.id;\n },\n }}\n attributes={{\n node: (node: GraphLayoutNode<SpaceGraphNode>) => {\n const obj = node.data?.data.object;\n return {\n data: {\n color: getHashStyles(obj && Obj.getTypename(obj))?.hue,\n },\n classes: {\n 'dx-selected': selection.contains(node.id),\n },\n };\n },\n }}\n onSelect={handleSelect}\n />\n </SVG.Zoom>\n </SVG.Root>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { forceLink, forceManyBody } from 'd3';\nimport NativeForceGraph from 'force-graph';\nimport React, { type FC, useEffect, useRef, useState } from 'react';\nimport { useResizeDetector } from 'react-resize-detector';\n\nimport { type SearchResult, filterObjectsSync } from '@dxos/plugin-search';\nimport { type SpaceGraphModel } from '@dxos/schema';\n\nimport { GraphAdapter } from './adapter';\n\nexport type ForceGraphProps = {\n model?: SpaceGraphModel;\n match?: RegExp;\n};\n\nexport const ForceGraph: FC<ForceGraphProps> = ({ model, match }) => {\n const { ref, width, height } = useResizeDetector({ refreshRate: 200 });\n const rootRef = useRef<HTMLDivElement>(null);\n const forceGraph = useRef<NativeForceGraph>(null);\n\n const filteredRef = useRef<SearchResult[]>([]);\n filteredRef.current = filterObjectsSync(model?.objects ?? [], match);\n\n const [data, setData] = useState<GraphAdapter>();\n useEffect(() => {\n return model?.subscribe((model) => {\n setData(new GraphAdapter(model.graph));\n });\n }, [model]);\n\n useEffect(() => {\n if (rootRef.current) {\n // https://github.com/vasturiano/force-graph\n // https://github.com/vasturiano/3d-force-graph\n forceGraph.current = new NativeForceGraph(rootRef.current)\n // https://github.com/vasturiano/force-graph?tab=readme-ov-file#node-styling\n .nodeRelSize(6)\n .nodeLabel((node: any) => (node.type === 'schema' ? node.data.typename : (node.data.label ?? node.id)))\n .nodeAutoColorBy((node: any) => (node.type === 'schema' ? 'schema' : node.data.typename))\n\n // https://github.com/vasturiano/force-graph?tab=readme-ov-file#link-styling\n .linkAutoColorBy((link: any) => link.type);\n }\n\n return () => {\n forceGraph.current?.pauseAnimation().graphData({ nodes: [], links: [] });\n forceGraph.current = null;\n };\n }, []);\n\n useEffect(() => {\n if (!data || !width || !height || !forceGraph.current) {\n return;\n }\n\n // https://github.com/vasturiano/force-graph?tab=readme-ov-file#container-layout\n forceGraph.current\n .pauseAnimation()\n .width(width)\n .height(height)\n .onEngineStop(() => {\n handleZoomToFit();\n })\n .onNodeClick((node: any) => {\n forceGraph.current?.emitParticle(node);\n })\n\n // https://github.com/vasturiano/force-graph?tab=readme-ov-file#force-engine-d3-force-configuration\n // .d3Force('center', forceCenter().strength(0.9))\n .d3Force('link', forceLink().distance(160).strength(0.5))\n .d3Force('charge', forceManyBody().strength(-30))\n\n .graphData(data)\n .warmupTicks(100)\n .cooldownTime(1_000)\n .resumeAnimation();\n }, [data, width, height, forceGraph.current]);\n\n const handleZoomToFit = () => {\n forceGraph.current?.zoomToFit(400, 40);\n };\n\n return (\n <div ref={ref} className='relative grow' onClick={handleZoomToFit}>\n <div ref={rootRef} className='absolute inset-0' />\n </div>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Graph } from '@dxos/graph';\n\nexport type GraphNode = {\n id?: string;\n};\n\nexport type GraphLink = {\n source?: string;\n target?: string;\n};\n\nexport type GraphData = {\n nodes: GraphNode[];\n links: GraphLink[];\n};\n\n/**\n * Map common graph to force-graph format.\n */\nexport class GraphAdapter implements GraphData {\n private readonly _nodes: GraphNode[] = [];\n private readonly _links: GraphLink[] = [];\n\n constructor(private readonly graph: Graph) {\n this._nodes = graph.nodes.map((node) => ({\n id: node.id,\n type: node.type,\n data: node.data,\n }));\n\n this._links = graph.edges.map((edge) => ({\n type: edge.type,\n source: edge.source,\n target: edge.target,\n data: edge.data,\n }));\n }\n\n get nodes() {\n return this._nodes;\n }\n\n get links() {\n return this._links;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAIA,OAAOA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gBD,SAAS,GAAC,CAAA,EAE5CV,UAAUnB,IAAAA,EACV+B,YAAY,GAAA,EACZC,aAAa,GAAA,EACbC,gBAAe;IACpB,GAAG;MAACjC;MAAMX;MAAOC;MAAQK,WAAWE;KAAQ;AAE5C,UAAM0B,kBAAkB,MAAA;AACtB5B,iBAAWE,SAASqC,UAAU,KAAK,EAAA;IACrC;AAEA,WACE,gBAAAC,OAAA,cAACC,OAAAA;MAAIhD;MAAUiD,WAAU;MAAgBC,SAASf;OAChD,gBAAAY,OAAA,cAACC,OAAAA;MAAIhD,KAAKK;MAAS4C,WAAU;;;;;AAGnC;",
|
|
6
|
+
"names": ["React", "useCallback", "useEffect", "useMemo", "useRef", "Obj", "SelectionModel", "GraphForceProjector", "SVG", "getHashStyles", "D3ForceGraph", "classNames", "model", "selection", "_selection", "grid", "props", "context", "useRef", "projector", "useMemo", "current", "GraphForceProjector", "attributes", "linkForce", "edge", "data", "object", "active", "forces", "point", "strength", "graph", "SelectionModel", "useEffect", "repaint", "selected", "value", "handleSelect", "useCallback", "node", "contains", "id", "remove", "add", "SVG", "Root", "ref", "Markers", "Grid", "axis", "Zoom", "extent", "Graph", "labels", "text", "label", "obj", "color", "getHashStyles", "Obj", "getTypename", "hue", "classes", "onSelect", "forceLink", "forceManyBody", "NativeForceGraph", "React", "useEffect", "useRef", "useState", "useResizeDetector", "filterObjectsSync", "GraphAdapter", "_nodes", "_links", "graph", "nodes", "map", "node", "id", "type", "data", "edges", "edge", "source", "target", "links", "ForceGraph", "model", "match", "ref", "width", "height", "useResizeDetector", "refreshRate", "rootRef", "useRef", "forceGraph", "filteredRef", "current", "filterObjectsSync", "objects", "data", "setData", "useState", "useEffect", "subscribe", "GraphAdapter", "graph", "NativeForceGraph", "nodeRelSize", "nodeLabel", "node", "type", "typename", "label", "id", "nodeAutoColorBy", "linkAutoColorBy", "link", "pauseAnimation", "graphData", "nodes", "links", "onEngineStop", "handleZoomToFit", "onNodeClick", "emitParticle", "d3Force", "forceLink", "distance", "strength", "forceManyBody", "warmupTicks", "cooldownTime", "resumeAnimation", "zoomToFit", "React", "div", "className", "onClick"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
meta
|
|
3
|
+
} from "./chunk-UBHZGWZQ.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
7
|
+
|
|
8
|
+
// src/types/ExplorerAction.ts
|
|
9
|
+
var ExplorerAction_exports = {};
|
|
10
|
+
__export(ExplorerAction_exports, {
|
|
11
|
+
CreateGraph: () => CreateGraph,
|
|
12
|
+
GraphProps: () => GraphProps
|
|
13
|
+
});
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import { SpaceSchema } from "@dxos/react-client/echo";
|
|
16
|
+
import { DataType, TypenameAnnotationId } from "@dxos/schema";
|
|
17
|
+
var EXPLORER_ACTION = `${meta.id}/action`;
|
|
18
|
+
var GraphProps = Schema.Struct({
|
|
19
|
+
name: Schema.optional(Schema.String),
|
|
20
|
+
typename: Schema.String.annotations({
|
|
21
|
+
[TypenameAnnotationId]: [
|
|
22
|
+
"used-static",
|
|
23
|
+
"dynamic"
|
|
24
|
+
],
|
|
25
|
+
title: "Select graph record type"
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
var CreateGraph = class extends Schema.TaggedClass()(`${EXPLORER_ACTION}/create-graph`, {
|
|
29
|
+
input: Schema.Struct({
|
|
30
|
+
space: SpaceSchema
|
|
31
|
+
}).pipe(Schema.extend(GraphProps)),
|
|
32
|
+
output: Schema.Struct({
|
|
33
|
+
object: DataType.View
|
|
34
|
+
})
|
|
35
|
+
}) {
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/types/Graph.ts
|
|
39
|
+
var Graph_exports = {};
|
|
40
|
+
__export(Graph_exports, {
|
|
41
|
+
Graph: () => Graph,
|
|
42
|
+
make: () => make,
|
|
43
|
+
makeView: () => makeView
|
|
44
|
+
});
|
|
45
|
+
import * as Schema2 from "effect/Schema";
|
|
46
|
+
import { Filter, Obj, Query, QueryAST, Type } from "@dxos/echo";
|
|
47
|
+
import { LabelAnnotation, ViewAnnotation } from "@dxos/echo/internal";
|
|
48
|
+
import { createViewFromSpace } from "@dxos/schema";
|
|
49
|
+
var Graph = Schema2.Struct({
|
|
50
|
+
name: Schema2.optional(Schema2.String),
|
|
51
|
+
query: Schema2.Struct({
|
|
52
|
+
raw: Schema2.optional(Schema2.String),
|
|
53
|
+
ast: QueryAST.Query
|
|
54
|
+
}).pipe(Schema2.mutable)
|
|
55
|
+
}).pipe(Type.Obj({
|
|
56
|
+
typename: "dxos.org/type/Graph",
|
|
57
|
+
version: "0.1.0"
|
|
58
|
+
}), LabelAnnotation.set([
|
|
59
|
+
"name"
|
|
60
|
+
]), ViewAnnotation.set(true));
|
|
61
|
+
var make = (props = {
|
|
62
|
+
query: {
|
|
63
|
+
raw: "",
|
|
64
|
+
ast: Query.select(Filter.nothing()).ast
|
|
65
|
+
}
|
|
66
|
+
}) => Obj.make(Graph, props);
|
|
67
|
+
var makeView = async ({ presentation, ...props }) => {
|
|
68
|
+
const graph = make(presentation);
|
|
69
|
+
return createViewFromSpace({
|
|
70
|
+
...props,
|
|
71
|
+
presentation: graph
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
ExplorerAction_exports,
|
|
77
|
+
Graph_exports
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=chunk-BGNRYZUN.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/ExplorerAction.ts", "../../../src/types/Graph.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { SpaceSchema } from '@dxos/react-client/echo';\nimport { DataType, TypenameAnnotationId } from '@dxos/schema';\n\nimport { meta } from '../meta';\n\nconst EXPLORER_ACTION = `${meta.id}/action`;\n\nexport const GraphProps = Schema.Struct({\n name: Schema.optional(Schema.String),\n typename: Schema.String.annotations({\n [TypenameAnnotationId]: ['used-static', 'dynamic'],\n title: 'Select graph record type',\n }),\n});\n\nexport class CreateGraph extends Schema.TaggedClass<CreateGraph>()(`${EXPLORER_ACTION}/create-graph`, {\n input: Schema.Struct({\n space: SpaceSchema,\n }).pipe(Schema.extend(GraphProps)),\n output: Schema.Struct({\n object: DataType.View,\n }),\n}) {}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Filter, Obj, Query, QueryAST, Type } from '@dxos/echo';\nimport { LabelAnnotation, ViewAnnotation } from '@dxos/echo/internal';\nimport { type CreateViewFromSpaceProps, createViewFromSpace } from '@dxos/schema';\n\nexport const Graph = Schema.Struct({\n name: Schema.optional(Schema.String),\n query: Schema.Struct({\n raw: Schema.optional(Schema.String),\n ast: QueryAST.Query,\n }).pipe(Schema.mutable),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Graph',\n version: '0.1.0',\n }),\n LabelAnnotation.set(['name']),\n ViewAnnotation.set(true),\n);\n\nexport type Graph = Schema.Schema.Type<typeof Graph>;\n\n/**\n * Make a graph object.\n */\nexport const make = (\n props: Obj.MakeProps<typeof Graph> = { query: { raw: '', ast: Query.select(Filter.nothing()).ast } },\n) => Obj.make(Graph, props);\n\ntype MakeViewProps = Omit<CreateViewFromSpaceProps, 'presentation'> & {\n presentation?: Omit<Obj.MakeProps<typeof Graph>, 'name'>;\n};\n\n/**\n * Make a graph as a view of a data set.\n */\nexport const makeView = async ({ presentation, ...props }: MakeViewProps) => {\n const graph = make(presentation);\n return createViewFromSpace({ ...props, presentation: graph });\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAAA;;;;;AAIA,YAAYA,YAAY;AAExB,SAASC,mBAAmB;AAC5B,SAASC,UAAUC,4BAA4B;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ema", "DataType", "TypenameAnnotationId", "EXPLORER_ACTION", "meta", "id", "GraphProps", "Struct", "name", "optional", "String", "typename", "annotations", "TypenameAnnotationId", "title", "CreateGraph", "TaggedClass", "input", "space", "SpaceSchema", "pipe", "extend", "output", "object", "DataType", "View", "Schema", "Filter", "Obj", "Query", "QueryAST", "Type", "LabelAnnotation", "ViewAnnotation", "createViewFromSpace", "Graph", "Struct", "name", "optional", "String", "query", "raw", "ast", "QueryAST", "Query", "pipe", "mutable", "Type", "Obj", "typename", "version", "LabelAnnotation", "set", "ViewAnnotation", "make", "props", "select", "Filter", "nothing", "makeView", "presentation", "graph", "createViewFromSpace"]
|
|
7
|
+
}
|
|
@@ -10973,10 +10973,9 @@ var TidyTree = (s, data, options) => {
|
|
|
10973
10973
|
var TidyTree_default = TidyTree;
|
|
10974
10974
|
|
|
10975
10975
|
// src/components/Tree/types/tree.ts
|
|
10976
|
-
import
|
|
10976
|
+
import * as Schema from "effect/Schema";
|
|
10977
10977
|
import { Key, Obj, Type } from "@dxos/echo";
|
|
10978
10978
|
import { invariant } from "@dxos/invariant";
|
|
10979
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-explorer/src/components/Tree/types/tree.ts";
|
|
10980
10979
|
var TreeNodeType = Schema.Struct({
|
|
10981
10980
|
id: Key.ObjectId,
|
|
10982
10981
|
children: Schema.mutable(Schema.Array(Key.ObjectId)),
|
|
@@ -10996,245 +10995,6 @@ var TreeType = Schema.Struct({
|
|
|
10996
10995
|
typename: "dxos.org/type/Tree",
|
|
10997
10996
|
version: "0.1.0"
|
|
10998
10997
|
}));
|
|
10999
|
-
var Tree = class _Tree {
|
|
11000
|
-
static {
|
|
11001
|
-
this.create = () => {
|
|
11002
|
-
const id = Key.ObjectId.random();
|
|
11003
|
-
return Obj.make(TreeType, {
|
|
11004
|
-
root: id,
|
|
11005
|
-
nodes: {
|
|
11006
|
-
[id]: {
|
|
11007
|
-
id,
|
|
11008
|
-
children: [],
|
|
11009
|
-
data: {
|
|
11010
|
-
text: ""
|
|
11011
|
-
}
|
|
11012
|
-
}
|
|
11013
|
-
}
|
|
11014
|
-
});
|
|
11015
|
-
};
|
|
11016
|
-
}
|
|
11017
|
-
constructor(tree3) {
|
|
11018
|
-
this._tree = tree3 ?? _Tree.create();
|
|
11019
|
-
}
|
|
11020
|
-
get tree() {
|
|
11021
|
-
return this._tree;
|
|
11022
|
-
}
|
|
11023
|
-
// TODO(burdon): Make reactive.
|
|
11024
|
-
get size() {
|
|
11025
|
-
return Object.keys(this._tree.nodes).length;
|
|
11026
|
-
}
|
|
11027
|
-
get root() {
|
|
11028
|
-
return this.getNode(this._tree.root);
|
|
11029
|
-
}
|
|
11030
|
-
//
|
|
11031
|
-
// Traversal
|
|
11032
|
-
//
|
|
11033
|
-
/**
|
|
11034
|
-
* Recursively traverse the tree until the callback returns a value.
|
|
11035
|
-
*/
|
|
11036
|
-
tranverse(callback, root = this._tree.root, depth = 0) {
|
|
11037
|
-
const node = this._tree.nodes[root];
|
|
11038
|
-
const result = callback(node, depth);
|
|
11039
|
-
if (result !== void 0) {
|
|
11040
|
-
return result;
|
|
11041
|
-
}
|
|
11042
|
-
for (const childId of node.children) {
|
|
11043
|
-
const result2 = this.tranverse(callback, childId, depth + 1);
|
|
11044
|
-
if (result2 !== void 0) {
|
|
11045
|
-
return result2;
|
|
11046
|
-
}
|
|
11047
|
-
}
|
|
11048
|
-
}
|
|
11049
|
-
getNode(id) {
|
|
11050
|
-
const node = this._tree.nodes[id];
|
|
11051
|
-
invariant(node, void 0, {
|
|
11052
|
-
F: __dxlog_file,
|
|
11053
|
-
L: 98,
|
|
11054
|
-
S: this,
|
|
11055
|
-
A: [
|
|
11056
|
-
"node",
|
|
11057
|
-
""
|
|
11058
|
-
]
|
|
11059
|
-
});
|
|
11060
|
-
return node;
|
|
11061
|
-
}
|
|
11062
|
-
/**
|
|
11063
|
-
* Get the children of a node.
|
|
11064
|
-
*/
|
|
11065
|
-
getChildNodes(node) {
|
|
11066
|
-
return node.children.map((id) => this.getNode(id));
|
|
11067
|
-
}
|
|
11068
|
-
/**
|
|
11069
|
-
* Get the parent of a node.
|
|
11070
|
-
*/
|
|
11071
|
-
getParent(node) {
|
|
11072
|
-
const parent = this.tranverse((n) => {
|
|
11073
|
-
if (n.children.includes(node.id)) {
|
|
11074
|
-
return n;
|
|
11075
|
-
}
|
|
11076
|
-
});
|
|
11077
|
-
return parent ?? null;
|
|
11078
|
-
}
|
|
11079
|
-
/**
|
|
11080
|
-
* Get the next node in the tree.
|
|
11081
|
-
*/
|
|
11082
|
-
getNext(node, hierarchical = true) {
|
|
11083
|
-
if (hierarchical && node.children.length) {
|
|
11084
|
-
return this.getChildNodes(node)[0];
|
|
11085
|
-
} else {
|
|
11086
|
-
const parent = this.getParent(node);
|
|
11087
|
-
if (parent) {
|
|
11088
|
-
const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
|
|
11089
|
-
if (idx < parent.children.length - 1) {
|
|
11090
|
-
return this.getNode(parent.children[idx + 1]);
|
|
11091
|
-
} else {
|
|
11092
|
-
return this.getNext(parent, false);
|
|
11093
|
-
}
|
|
11094
|
-
}
|
|
11095
|
-
}
|
|
11096
|
-
}
|
|
11097
|
-
/**
|
|
11098
|
-
* Get the previous node in the tree.
|
|
11099
|
-
*/
|
|
11100
|
-
getPrevious(node, hierarchical = true) {
|
|
11101
|
-
const parent = this.getParent(node);
|
|
11102
|
-
const idx = this.getChildNodes(parent).findIndex(({ id }) => id === node.id);
|
|
11103
|
-
if (idx === 0) {
|
|
11104
|
-
if (hierarchical) {
|
|
11105
|
-
return parent;
|
|
11106
|
-
}
|
|
11107
|
-
} else {
|
|
11108
|
-
const previous = this.getNode(parent.children[idx - 1]);
|
|
11109
|
-
if (hierarchical && previous.children.length) {
|
|
11110
|
-
return this.getLastDescendent(previous);
|
|
11111
|
-
}
|
|
11112
|
-
return previous;
|
|
11113
|
-
}
|
|
11114
|
-
}
|
|
11115
|
-
/**
|
|
11116
|
-
* Get the last descendent of a node.
|
|
11117
|
-
*/
|
|
11118
|
-
getLastDescendent(node) {
|
|
11119
|
-
const children = this.getChildNodes(node);
|
|
11120
|
-
const last = children.length ? children[children.length - 1] : void 0;
|
|
11121
|
-
if (last) {
|
|
11122
|
-
return this.getLastDescendent(last);
|
|
11123
|
-
}
|
|
11124
|
-
return node;
|
|
11125
|
-
}
|
|
11126
|
-
//
|
|
11127
|
-
// Mutations
|
|
11128
|
-
//
|
|
11129
|
-
/**
|
|
11130
|
-
* Clear tree.
|
|
11131
|
-
*/
|
|
11132
|
-
clear() {
|
|
11133
|
-
const root = this._tree.nodes[this._tree.root];
|
|
11134
|
-
root.children.length = 0;
|
|
11135
|
-
this._tree.nodes = {
|
|
11136
|
-
[root.id]: root
|
|
11137
|
-
};
|
|
11138
|
-
}
|
|
11139
|
-
/**
|
|
11140
|
-
* Add node.
|
|
11141
|
-
*/
|
|
11142
|
-
addNode(parent, node, index) {
|
|
11143
|
-
if (!node) {
|
|
11144
|
-
const id = Key.ObjectId.random();
|
|
11145
|
-
node = {
|
|
11146
|
-
id,
|
|
11147
|
-
children: [],
|
|
11148
|
-
data: {
|
|
11149
|
-
text: ""
|
|
11150
|
-
}
|
|
11151
|
-
};
|
|
11152
|
-
}
|
|
11153
|
-
this._tree.nodes[node.id] = node;
|
|
11154
|
-
parent.children.splice(index ?? parent.children.length, 0, node.id);
|
|
11155
|
-
return node;
|
|
11156
|
-
}
|
|
11157
|
-
/**
|
|
11158
|
-
* Delete node.
|
|
11159
|
-
*/
|
|
11160
|
-
deleteNode(parent, id) {
|
|
11161
|
-
const node = this._tree.nodes[id];
|
|
11162
|
-
if (!node) {
|
|
11163
|
-
return void 0;
|
|
11164
|
-
}
|
|
11165
|
-
delete this._tree.nodes[node.id];
|
|
11166
|
-
const idx = parent.children.findIndex((child) => child === id);
|
|
11167
|
-
if (idx !== -1) {
|
|
11168
|
-
parent.children.splice(idx, 1);
|
|
11169
|
-
}
|
|
11170
|
-
return node;
|
|
11171
|
-
}
|
|
11172
|
-
/**
|
|
11173
|
-
* Move child node.
|
|
11174
|
-
*/
|
|
11175
|
-
moveNode(node, from, to) {
|
|
11176
|
-
invariant(from >= 0 && from < node.children.length, void 0, {
|
|
11177
|
-
F: __dxlog_file,
|
|
11178
|
-
L: 228,
|
|
11179
|
-
S: this,
|
|
11180
|
-
A: [
|
|
11181
|
-
"from >= 0 && from < node.children.length",
|
|
11182
|
-
""
|
|
11183
|
-
]
|
|
11184
|
-
});
|
|
11185
|
-
invariant(to >= 0 && to < node.children.length, void 0, {
|
|
11186
|
-
F: __dxlog_file,
|
|
11187
|
-
L: 229,
|
|
11188
|
-
S: this,
|
|
11189
|
-
A: [
|
|
11190
|
-
"to >= 0 && to < node.children.length",
|
|
11191
|
-
""
|
|
11192
|
-
]
|
|
11193
|
-
});
|
|
11194
|
-
if (from === to) {
|
|
11195
|
-
return null;
|
|
11196
|
-
}
|
|
11197
|
-
const child = node.children[from];
|
|
11198
|
-
node.children.splice(from, 1);
|
|
11199
|
-
node.children.splice(to, 0, child);
|
|
11200
|
-
return this.getNode(child);
|
|
11201
|
-
}
|
|
11202
|
-
/**
|
|
11203
|
-
* Indent node.
|
|
11204
|
-
*/
|
|
11205
|
-
indentNode(node) {
|
|
11206
|
-
const parent = this.getParent(node);
|
|
11207
|
-
if (!parent) {
|
|
11208
|
-
return;
|
|
11209
|
-
}
|
|
11210
|
-
const idx = parent.children.findIndex((child) => child === node.id);
|
|
11211
|
-
if (idx < 1 || idx >= parent.children.length) {
|
|
11212
|
-
return;
|
|
11213
|
-
}
|
|
11214
|
-
const previous = this.getNode(parent.children[idx - 1]);
|
|
11215
|
-
parent.children.splice(idx, 1);
|
|
11216
|
-
previous.children.push(node.id);
|
|
11217
|
-
}
|
|
11218
|
-
/**
|
|
11219
|
-
* Unindent node.
|
|
11220
|
-
*/
|
|
11221
|
-
unindentNode(node) {
|
|
11222
|
-
const parent = this.getParent(node);
|
|
11223
|
-
if (!parent) {
|
|
11224
|
-
return;
|
|
11225
|
-
}
|
|
11226
|
-
const ancestor = this.getParent(parent);
|
|
11227
|
-
if (!ancestor) {
|
|
11228
|
-
return;
|
|
11229
|
-
}
|
|
11230
|
-
const nodeIdx = parent.children.findIndex((id) => id === node.id);
|
|
11231
|
-
const [_, ...rest] = parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
|
|
11232
|
-
parent.children.splice(nodeIdx, parent.children.length - nodeIdx);
|
|
11233
|
-
const parentIdx = this.getChildNodes(ancestor).findIndex((n) => n.id === parent.id);
|
|
11234
|
-
ancestor.children.splice(parentIdx + 1, 0, node.id);
|
|
11235
|
-
node.children.push(...rest);
|
|
11236
|
-
}
|
|
11237
|
-
};
|
|
11238
10998
|
|
|
11239
10999
|
// src/components/Tree/types/types.ts
|
|
11240
11000
|
var mapGraphToTreeData = (model, maxDepth = 8) => {
|
|
@@ -11262,7 +11022,7 @@ var renderers = /* @__PURE__ */ new Map([
|
|
|
11262
11022
|
HierarchicalEdgeBundling_default
|
|
11263
11023
|
]
|
|
11264
11024
|
]);
|
|
11265
|
-
var
|
|
11025
|
+
var Tree = ({ space, selected, variant = "tidy", onNodeClick }) => {
|
|
11266
11026
|
var _effect = _useSignals3();
|
|
11267
11027
|
try {
|
|
11268
11028
|
const [model] = useAsyncState(async () => space ? new SpaceGraphModel().open(space) : void 0, [
|
|
@@ -11280,7 +11040,7 @@ var Tree2 = ({ space, selected, variant = "tidy", onNodeClick }) => {
|
|
|
11280
11040
|
]);
|
|
11281
11041
|
const context = useRef(null);
|
|
11282
11042
|
useEffect3(() => {
|
|
11283
|
-
if (context.current) {
|
|
11043
|
+
if (context.current?.size) {
|
|
11284
11044
|
const { width, height } = context.current.size;
|
|
11285
11045
|
const size = Math.min(width, height);
|
|
11286
11046
|
const radius = size * 0.4;
|
|
@@ -11317,13 +11077,13 @@ var Tree2 = ({ space, selected, variant = "tidy", onNodeClick }) => {
|
|
|
11317
11077
|
|
|
11318
11078
|
// src/components/index.ts
|
|
11319
11079
|
import { lazy } from "react";
|
|
11320
|
-
var ExplorerContainer = lazy(() => import("./ExplorerContainer-
|
|
11080
|
+
var ExplorerContainer = lazy(() => import("./ExplorerContainer-L5RVUJRL.mjs"));
|
|
11321
11081
|
|
|
11322
11082
|
export {
|
|
11323
11083
|
Chart,
|
|
11324
11084
|
Globe,
|
|
11325
11085
|
defaultTreeLayoutSlots,
|
|
11326
|
-
|
|
11086
|
+
Tree,
|
|
11327
11087
|
ExplorerContainer
|
|
11328
11088
|
};
|
|
11329
|
-
//# sourceMappingURL=chunk-
|
|
11089
|
+
//# sourceMappingURL=chunk-CRN65FY3.mjs.map
|