@dxos/app-graph 0.8.3 → 0.8.4-main.3f58842
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/index.mjs +8 -8
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +8 -8
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/node.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts +3 -8
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -26
- package/src/node.ts +4 -2
- package/src/stories/EchoGraph.stories.tsx +13 -129
- package/dist/lib/node/index.cjs +0 -816
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/app-graph",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.3f58842",
|
|
4
4
|
"description": "Constructs knowledge graphs for the purpose of building applications on top of",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -26,44 +26,42 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@preact/signals-core": "^1.9.0",
|
|
28
28
|
"main-thread-scheduling": "^14.1.1",
|
|
29
|
-
"@dxos/async": "0.8.
|
|
30
|
-
"@dxos/debug": "0.8.
|
|
31
|
-
"@dxos/echo": "0.8.
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/echo-signals": "0.8.
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/live-object": "0.8.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
29
|
+
"@dxos/async": "0.8.4-main.3f58842",
|
|
30
|
+
"@dxos/debug": "0.8.4-main.3f58842",
|
|
31
|
+
"@dxos/echo": "0.8.4-main.3f58842",
|
|
32
|
+
"@dxos/echo-schema": "0.8.4-main.3f58842",
|
|
33
|
+
"@dxos/echo-signals": "0.8.4-main.3f58842",
|
|
34
|
+
"@dxos/invariant": "0.8.4-main.3f58842",
|
|
35
|
+
"@dxos/live-object": "0.8.4-main.3f58842",
|
|
36
|
+
"@dxos/log": "0.8.4-main.3f58842",
|
|
37
|
+
"@dxos/util": "0.8.4-main.3f58842"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@effect-rx/rx-react": "
|
|
41
|
-
"@effect/platform": "0.
|
|
42
|
-
"@phosphor-icons/react": "^2.1.5",
|
|
40
|
+
"@effect-rx/rx-react": "0.38.0",
|
|
41
|
+
"@effect/platform": "0.89.0",
|
|
43
42
|
"@types/react": "~18.2.0",
|
|
44
43
|
"@types/react-dom": "~18.2.0",
|
|
45
|
-
"effect": "3.
|
|
44
|
+
"effect": "3.17.0",
|
|
46
45
|
"react": "~18.2.0",
|
|
47
46
|
"react-dom": "~18.2.0",
|
|
48
47
|
"vite": "5.4.7",
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/react-
|
|
52
|
-
"@dxos/react-ui
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/react-ui-tabs": "0.8.
|
|
55
|
-
"@dxos/react-ui-theme": "0.8.
|
|
56
|
-
"@dxos/storybook-utils": "0.8.
|
|
48
|
+
"@dxos/echo-db": "0.8.4-main.3f58842",
|
|
49
|
+
"@dxos/random": "0.8.4-main.3f58842",
|
|
50
|
+
"@dxos/react-client": "0.8.4-main.3f58842",
|
|
51
|
+
"@dxos/react-ui": "0.8.4-main.3f58842",
|
|
52
|
+
"@dxos/react-ui-list": "0.8.4-main.3f58842",
|
|
53
|
+
"@dxos/react-ui-tabs": "0.8.4-main.3f58842",
|
|
54
|
+
"@dxos/react-ui-theme": "0.8.4-main.3f58842",
|
|
55
|
+
"@dxos/storybook-utils": "0.8.4-main.3f58842"
|
|
57
56
|
},
|
|
58
57
|
"peerDependencies": {
|
|
59
58
|
"@effect-rx/rx-react": "^0.34.1",
|
|
60
|
-
"@effect/platform": "0.80.12",
|
|
61
|
-
"@phosphor-icons/react": "^2.1.5",
|
|
59
|
+
"@effect/platform": "^0.80.12",
|
|
62
60
|
"effect": "3.14.21",
|
|
63
61
|
"react": "~18.2.0",
|
|
64
62
|
"react-dom": "~18.2.0",
|
|
65
|
-
"@dxos/react-ui": "0.8.
|
|
66
|
-
"@dxos/react-ui-theme": "0.8.
|
|
63
|
+
"@dxos/react-ui": "0.8.4-main.3f58842",
|
|
64
|
+
"@dxos/react-ui-theme": "0.8.4-main.3f58842"
|
|
67
65
|
},
|
|
68
66
|
"publishConfig": {
|
|
69
67
|
"access": "public"
|
package/src/node.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { type MaybePromise, type MakeOptional } from '@dxos/util';
|
|
6
6
|
|
|
7
|
+
import { ACTION_GROUP_TYPE, ACTION_TYPE } from './graph';
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Represents a node in the graph.
|
|
9
11
|
*/
|
|
@@ -84,7 +86,7 @@ export type Action<TProperties extends Record<string, any> = Record<string, any>
|
|
|
84
86
|
>;
|
|
85
87
|
|
|
86
88
|
export const isAction = (data: unknown): data is Action =>
|
|
87
|
-
isGraphNode(data) ? typeof data.data === 'function' : false;
|
|
89
|
+
isGraphNode(data) ? typeof data.data === 'function' && data.type === ACTION_TYPE : false;
|
|
88
90
|
|
|
89
91
|
export const actionGroupSymbol = Symbol('ActionGroup');
|
|
90
92
|
|
|
@@ -95,7 +97,7 @@ export type ActionGroup<TProperties extends Record<string, any> = Record<string,
|
|
|
95
97
|
>;
|
|
96
98
|
|
|
97
99
|
export const isActionGroup = (data: unknown): data is ActionGroup =>
|
|
98
|
-
isGraphNode(data) ? data.data === actionGroupSymbol : false;
|
|
100
|
+
isGraphNode(data) ? data.data === actionGroupSymbol && data.type === ACTION_GROUP_TYPE : false;
|
|
99
101
|
|
|
100
102
|
export type ActionLike = Action | ActionGroup;
|
|
101
103
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
7
|
import { type Registry, RegistryContext, Rx, useRxValue } from '@effect-rx/rx-react';
|
|
8
|
-
import {
|
|
8
|
+
import { type Meta } from '@storybook/react-vite';
|
|
9
9
|
import { Option, pipe } from 'effect';
|
|
10
10
|
import React, { type PropsWithChildren, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
11
11
|
|
|
@@ -24,9 +24,8 @@ import { Obj, Type } from '@dxos/echo';
|
|
|
24
24
|
import { faker } from '@dxos/random';
|
|
25
25
|
import { type Client, useClient } from '@dxos/react-client';
|
|
26
26
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
27
|
-
import {
|
|
27
|
+
import { Input, Select, Icon, IconButton } from '@dxos/react-ui';
|
|
28
28
|
import { Path, Tree } from '@dxos/react-ui-list';
|
|
29
|
-
import { Tabs } from '@dxos/react-ui-tabs';
|
|
30
29
|
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
31
30
|
import { withTheme } from '@dxos/storybook-utils';
|
|
32
31
|
import { byPosition, isNonNullable, safeParseInt } from '@dxos/util';
|
|
@@ -205,7 +204,11 @@ const Controls = ({ children }: PropsWithChildren) => {
|
|
|
205
204
|
return (
|
|
206
205
|
<>
|
|
207
206
|
<div className='flex shrink-0 p-2 space-x-2'>
|
|
208
|
-
<
|
|
207
|
+
<IconButton
|
|
208
|
+
icon={generating ? 'ph--pause--regular' : 'ph--play--regular'}
|
|
209
|
+
label={generating ? 'Pause' : 'Play'}
|
|
210
|
+
onClick={() => setGenerating((generating) => !generating)}
|
|
211
|
+
/>
|
|
209
212
|
<div className='relative' title='mutation period'>
|
|
210
213
|
<Input.Root>
|
|
211
214
|
<Input.TextInput
|
|
@@ -217,11 +220,9 @@ const Controls = ({ children }: PropsWithChildren) => {
|
|
|
217
220
|
onChange={({ target: { value } }) => setActionInterval(value)}
|
|
218
221
|
/>
|
|
219
222
|
</Input.Root>
|
|
220
|
-
<
|
|
223
|
+
<Icon icon='ph--timer--regular' classNames={mx('absolute inline-end-1 block-start-1 mt-[6px]', getSize(3))} />
|
|
221
224
|
</div>
|
|
222
|
-
<
|
|
223
|
-
<Plus />
|
|
224
|
-
</Button>
|
|
225
|
+
<IconButton icon='ph--plus--regular' label='Add' onClick={() => action && runAction(client, action)} />
|
|
225
226
|
<Select.Root value={action?.toString()} onValueChange={(action) => setAction(action as unknown as Action)}>
|
|
226
227
|
<Select.TriggerButton placeholder='Select value' />
|
|
227
228
|
<Select.Portal>
|
|
@@ -245,10 +246,9 @@ const Controls = ({ children }: PropsWithChildren) => {
|
|
|
245
246
|
);
|
|
246
247
|
};
|
|
247
248
|
|
|
248
|
-
|
|
249
|
+
const meta: Meta = {
|
|
249
250
|
title: 'sdk/app-graph/EchoGraph',
|
|
250
251
|
decorators: [
|
|
251
|
-
withTheme,
|
|
252
252
|
withClientProvider({
|
|
253
253
|
createIdentity: true,
|
|
254
254
|
onIdentityCreated: async ({ client }) => {
|
|
@@ -256,9 +256,12 @@ export default {
|
|
|
256
256
|
await client.spaces.create();
|
|
257
257
|
},
|
|
258
258
|
}),
|
|
259
|
+
withTheme,
|
|
259
260
|
],
|
|
260
261
|
};
|
|
261
262
|
|
|
263
|
+
export default meta;
|
|
264
|
+
|
|
262
265
|
export const JsonView = {
|
|
263
266
|
render: () => {
|
|
264
267
|
const client = useClient();
|
|
@@ -372,122 +375,3 @@ export const TreeView = {
|
|
|
372
375
|
);
|
|
373
376
|
},
|
|
374
377
|
};
|
|
375
|
-
|
|
376
|
-
// TODO(wittjosiah): Remove.
|
|
377
|
-
export const TabTreeView = {
|
|
378
|
-
render: () => {
|
|
379
|
-
const client = useClient();
|
|
380
|
-
const registry = useContext(RegistryContext);
|
|
381
|
-
const graph = useMemo(() => createGraph(client, registry), [client, registry]);
|
|
382
|
-
const state = useMemo(() => new Map<string, Live<{ open: boolean; current: boolean }>>(), []);
|
|
383
|
-
|
|
384
|
-
const useItems = useCallback(
|
|
385
|
-
(node?: Node, options?: { disposition?: string; sort?: boolean }) => {
|
|
386
|
-
const connections = useRxValue(graph.connections(node?.id ?? ROOT_ID));
|
|
387
|
-
return options?.sort ? connections.toSorted((a, b) => byPosition(a.properties, b.properties)) : connections;
|
|
388
|
-
},
|
|
389
|
-
[graph],
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
const getProps = useCallback(
|
|
393
|
-
(node: Node, path: string[]) => {
|
|
394
|
-
const children = graph
|
|
395
|
-
.getConnections(node.id, 'outbound')
|
|
396
|
-
.map((n) => {
|
|
397
|
-
// Break cycles.
|
|
398
|
-
const nextPath = [...path, node.id];
|
|
399
|
-
return nextPath.includes(n.id) ? undefined : (n as Node);
|
|
400
|
-
})
|
|
401
|
-
.filter(isNonNullable) as Node[];
|
|
402
|
-
const parentOf =
|
|
403
|
-
children.length > 0 ? children.map(({ id }) => id) : node.properties.role === 'branch' ? [] : undefined;
|
|
404
|
-
return {
|
|
405
|
-
id: node.id,
|
|
406
|
-
label: node.id,
|
|
407
|
-
icon: node.type === 'dxos.org/type/Space' ? 'ph--planet--regular' : 'ph--placeholder--regular',
|
|
408
|
-
parentOf,
|
|
409
|
-
};
|
|
410
|
-
},
|
|
411
|
-
[graph],
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
const isOpen = useCallback(
|
|
415
|
-
(_path: string[]) => {
|
|
416
|
-
const path = Path.create(..._path);
|
|
417
|
-
const object = state.get(path) ?? live({ open: true, current: false });
|
|
418
|
-
if (!state.has(path)) {
|
|
419
|
-
state.set(path, object);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return object.open;
|
|
423
|
-
},
|
|
424
|
-
[state],
|
|
425
|
-
);
|
|
426
|
-
|
|
427
|
-
const isCurrent = useCallback(
|
|
428
|
-
(_path: string[]) => {
|
|
429
|
-
const path = Path.create(..._path);
|
|
430
|
-
const object = state.get(path) ?? live({ open: false, current: false });
|
|
431
|
-
if (!state.has(path)) {
|
|
432
|
-
state.set(path, object);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return object.current;
|
|
436
|
-
},
|
|
437
|
-
[state],
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
const onOpenChange = useCallback(
|
|
441
|
-
({ path: _path, open }: { path: string[]; open: boolean }) => {
|
|
442
|
-
const path = Path.create(..._path);
|
|
443
|
-
const object = state.get(path);
|
|
444
|
-
object!.open = open;
|
|
445
|
-
},
|
|
446
|
-
[state],
|
|
447
|
-
);
|
|
448
|
-
|
|
449
|
-
const onSelect = useCallback(
|
|
450
|
-
({ path: _path, current }: { path: string[]; current: boolean }) => {
|
|
451
|
-
const path = Path.create(..._path);
|
|
452
|
-
const object = state.get(path);
|
|
453
|
-
object!.current = current;
|
|
454
|
-
},
|
|
455
|
-
[state],
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
const spaces = useItems(graph.root);
|
|
459
|
-
|
|
460
|
-
return (
|
|
461
|
-
<>
|
|
462
|
-
<Controls />
|
|
463
|
-
<Tabs.Root defaultValue={spaces[0].id}>
|
|
464
|
-
<Tabs.Tablist>
|
|
465
|
-
{spaces.map((space) => {
|
|
466
|
-
return (
|
|
467
|
-
<Tabs.Tab key={space.id} value={space.id}>
|
|
468
|
-
{space.id}
|
|
469
|
-
</Tabs.Tab>
|
|
470
|
-
);
|
|
471
|
-
})}
|
|
472
|
-
</Tabs.Tablist>
|
|
473
|
-
{spaces.map((space) => {
|
|
474
|
-
return (
|
|
475
|
-
<Tabs.Tabpanel key={space.id} value={space.id}>
|
|
476
|
-
<Tree
|
|
477
|
-
id={space.id}
|
|
478
|
-
root={space}
|
|
479
|
-
useItems={useItems}
|
|
480
|
-
getProps={getProps}
|
|
481
|
-
isOpen={isOpen}
|
|
482
|
-
isCurrent={isCurrent}
|
|
483
|
-
onOpenChange={onOpenChange}
|
|
484
|
-
onSelect={onSelect}
|
|
485
|
-
/>
|
|
486
|
-
</Tabs.Tabpanel>
|
|
487
|
-
);
|
|
488
|
-
})}
|
|
489
|
-
</Tabs.Root>
|
|
490
|
-
</>
|
|
491
|
-
);
|
|
492
|
-
},
|
|
493
|
-
};
|