@dxos/app-graph 0.4.6 → 0.4.7-main.06facb4

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.
@@ -11,7 +11,7 @@ import React, { useEffect, useState } from 'react';
11
11
  import { EventSubscriptions } from '@dxos/async';
12
12
  import { faker } from '@dxos/random';
13
13
  import { Client } from '@dxos/react-client';
14
- import { Expando, type Space, SpaceProxy, SpaceState } from '@dxos/react-client/echo';
14
+ import { Expando, type Space, SpaceState } from '@dxos/react-client/echo';
15
15
  import { ClientRepeater, TestBuilder } from '@dxos/react-client/testing';
16
16
  import { Button, DensityProvider, Input, Select } from '@dxos/react-ui';
17
17
  import { getSize, mx } from '@dxos/react-ui-theme';
@@ -19,8 +19,8 @@ import { withTheme } from '@dxos/storybook-utils';
19
19
  import { safeParseInt } from '@dxos/util';
20
20
 
21
21
  import { Tree } from './Tree';
22
+ import { type Graph } from '../graph';
22
23
  import { GraphBuilder } from '../graph-builder';
23
- import { type Node } from '../node';
24
24
 
25
25
  export default {
26
26
  title: 'app-graph/EchoGraph',
@@ -36,11 +36,7 @@ await client.halo.createIdentity();
36
36
  await client.spaces.create();
37
37
  await client.spaces.create();
38
38
 
39
- const spaceNodeBuilder = (parent: Node) => {
40
- if (parent.id !== 'root') {
41
- return;
42
- }
43
-
39
+ const spaceBuilderExtension = (graph: Graph) => {
44
40
  const subscriptions = new EventSubscriptions();
45
41
  const { unsubscribe } = client.spaces.subscribe((spaces) => {
46
42
  subscriptions.clear();
@@ -48,12 +44,23 @@ const spaceNodeBuilder = (parent: Node) => {
48
44
  subscriptions.add(
49
45
  effect(() => {
50
46
  if (space.state.get() === SpaceState.READY) {
51
- parent.addNode('space', { id: space.key.toHex(), label: space.properties.name, data: space });
47
+ console.log('add space');
48
+ graph.addNodes({ id: space.key.toHex(), properties: { label: space.properties.name }, data: space });
49
+ graph.addEdge({ source: 'root', target: space.key.toHex() });
52
50
  } else {
53
- parent.removeNode(space.key.toHex());
51
+ graph.removeNode(space.key.toHex());
54
52
  }
55
53
  }),
56
54
  );
55
+
56
+ const query = space.db.query();
57
+ subscriptions.add(
58
+ effect(() => {
59
+ query.objects.forEach((object) => {
60
+ graph.addEdge({ source: space.key.toHex(), target: object.id });
61
+ });
62
+ }),
63
+ );
57
64
  });
58
65
  });
59
66
 
@@ -63,28 +70,53 @@ const spaceNodeBuilder = (parent: Node) => {
63
70
  };
64
71
  };
65
72
 
66
- const objectNodeBuilder = (parent: Node) => {
67
- if (!(parent.data instanceof SpaceProxy)) {
68
- return;
69
- }
70
-
71
- const space = parent.data;
72
- const query = space.db.query({ type: 'test' });
73
- let previousObjects: Expando[] = [];
74
- return effect(() => {
75
- const removedObjects = previousObjects.filter((object) => !query.objects.includes(object));
76
- previousObjects = query.objects;
77
-
78
- removedObjects.forEach((object) => parent.removeNode(object.id));
79
- query.objects.forEach((expando) =>
80
- parent.addNode('object', { id: expando.id, label: expando.name, data: expando }),
81
- );
73
+ // TODO(wittjosiah): Hypergraph query isn't working.
74
+ // const objectBuilderExtension = (graph: Graph) => {
75
+ // const query = client.spaces.query({ type: 'test' });
76
+ // let previousObjects: Expando[] = [];
77
+ // return effect(() => {
78
+ // const removedObjects = previousObjects.filter((object) => !query.objects.includes(object));
79
+ // previousObjects = query.objects;
80
+
81
+ // removedObjects.forEach((object) => graph.removeNode(object.id));
82
+ // query.objects.forEach((object) => {
83
+ // console.log('add object');
84
+ // graph.addNodes({ id: object.id, properties: { label: object.name }, data: object });
85
+ // });
86
+ // });
87
+ // };
88
+
89
+ const objectBuilderExtension = (graph: Graph) => {
90
+ const subscriptions = new EventSubscriptions();
91
+ const { unsubscribe } = client.spaces.subscribe((spaces) => {
92
+ subscriptions.clear();
93
+ spaces.forEach((space) => {
94
+ const query = space.db.query({ type: 'test' });
95
+ let previousObjects: Expando[] = [];
96
+ subscriptions.add(
97
+ effect(() => {
98
+ const removedObjects = previousObjects.filter((object) => !query.objects.includes(object));
99
+ previousObjects = query.objects;
100
+
101
+ removedObjects.forEach((object) => graph.removeNode(object.id));
102
+ query.objects.forEach((object) => {
103
+ console.log('add object');
104
+ graph.addNodes({ id: object.id, properties: { label: object.name }, data: object });
105
+ });
106
+ }),
107
+ );
108
+ });
82
109
  });
110
+
111
+ return () => {
112
+ unsubscribe();
113
+ subscriptions.clear();
114
+ };
83
115
  };
84
116
 
85
117
  const graph = new GraphBuilder()
86
- .addNodeBuilder('space', spaceNodeBuilder)
87
- .addNodeBuilder('object', objectNodeBuilder)
118
+ .addExtension('space', spaceBuilderExtension)
119
+ .addExtension('object', objectBuilderExtension)
88
120
  .build();
89
121
 
90
122
  enum Action {
@@ -1,98 +0,0 @@
1
- // packages/sdk/app-graph/src/testing.ts
2
- var createTestNodeBuilder = (id, depth = 1) => {
3
- const nodes = /* @__PURE__ */ new Map();
4
- const nodeBuilder = (parent) => {
5
- if (checkDepth(parent) >= depth) {
6
- return;
7
- }
8
- const [child] = parent.addNode(id, {
9
- id: `${parent.id}-${id}`,
10
- label: `${parent.id}-${id}`,
11
- data: null,
12
- parent
13
- });
14
- parent.addAction({
15
- id: `${parent.id}-${id}`,
16
- label: `${parent.id}-${id}`,
17
- invoke: () => {
18
- }
19
- });
20
- nodes.set(parent.id, parent);
21
- nodes.set(child.id, child);
22
- };
23
- const addNode = (parentId, node) => {
24
- const parent = nodes.get(parentId);
25
- if (!parent) {
26
- return;
27
- }
28
- const [child] = parent.addNode(id, node);
29
- nodes.set(child.id, child);
30
- return child;
31
- };
32
- const removeNode = (parentId, id2) => {
33
- const parent = nodes.get(parentId);
34
- if (!parent) {
35
- return;
36
- }
37
- return parent.removeNode(id2);
38
- };
39
- const addAction = (parentId, action) => {
40
- const parent = nodes.get(parentId);
41
- if (!parent) {
42
- return;
43
- }
44
- return parent.addAction(action);
45
- };
46
- const removeAction = (parentId, id2) => {
47
- const parent = nodes.get(parentId);
48
- if (!parent) {
49
- return;
50
- }
51
- return parent.removeAction(id2);
52
- };
53
- const addProperty = (parentId, key, value) => {
54
- const parent = nodes.get(parentId);
55
- if (!parent) {
56
- return;
57
- }
58
- return parent.addProperty(key, value);
59
- };
60
- const removeProperty = (parentId, key) => {
61
- const parent = nodes.get(parentId);
62
- if (!parent) {
63
- return;
64
- }
65
- return parent.removeProperty(key);
66
- };
67
- return {
68
- nodeBuilder,
69
- addNode,
70
- removeNode,
71
- addAction,
72
- removeAction,
73
- addProperty,
74
- removeProperty
75
- };
76
- };
77
- var buildGraph = (graph, id, nodes) => {
78
- addNodes(graph.root, id, nodes);
79
- return graph;
80
- };
81
- var addNodes = (root, id, nodes) => {
82
- nodes.forEach((node) => {
83
- const [child] = root.addNode(id, node);
84
- addNodes(child, id, node.children || []);
85
- node.actions?.forEach((action) => child.addAction(action));
86
- });
87
- };
88
- var checkDepth = (node, depth = 0) => {
89
- if (!node.parent) {
90
- return depth;
91
- }
92
- return checkDepth(node.parent, depth + 1);
93
- };
94
- export {
95
- buildGraph,
96
- createTestNodeBuilder
97
- };
98
- //# sourceMappingURL=testing.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/testing.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Action } from './action';\nimport { type Graph } from './graph';\nimport { type NodeBuilder, type Node } from './node';\n\n/**\n * Create a test node builder that always adds nodes and actions to the specified depth.\n *\n * @param id The id of the node builder, used to identify nodes created by this builder.\n * @param depth The depth at which to add nodes and actions.\n * @default 1\n *\n * @returns A test node builder\n */\n// TODO(burdon): Change to TestNodeBuilder class (see other builder/generator patterns in client/echo).\nexport const createTestNodeBuilder = (id: string, depth = 1) => {\n const nodes = new Map<string, Node>();\n const nodeBuilder: NodeBuilder = (parent) => {\n if (checkDepth(parent) >= depth) {\n return;\n }\n\n const [child] = parent.addNode(id, {\n id: `${parent.id}-${id}`,\n label: `${parent.id}-${id}`,\n data: null,\n parent,\n });\n\n parent.addAction({\n id: `${parent.id}-${id}`,\n label: `${parent.id}-${id}`,\n invoke: () => {},\n });\n\n nodes.set(parent.id, parent);\n nodes.set(child.id, child);\n };\n\n const addNode = (parentId: string, node: Pick<Node, 'id' | 'label'> & Partial<Node>) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n const [child] = parent.addNode(id, node);\n nodes.set(child.id, child);\n return child;\n };\n\n const removeNode = (parentId: string, id: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeNode(id);\n };\n\n const addAction = (parentId: string, action: Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Action>) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.addAction(action);\n };\n\n const removeAction = (parentId: string, id: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeAction(id);\n };\n\n const addProperty = (parentId: string, key: string, value: any) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.addProperty(key, value);\n };\n\n const removeProperty = (parentId: string, key: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeProperty(key);\n };\n\n return { nodeBuilder, addNode, removeNode, addAction, removeAction, addProperty, removeProperty };\n};\n\n/**\n * Build a graph from a nested list of nodes.\n *\n * @param graph Graph to add nodes to.\n * @param nodes Nodes to add to the\n *\n * @example\n * const graph = new GraphStore();\n * buildGraph(graph, [\n * {\n * id: 'test1',\n * label: 'test1',\n * children: [\n * {\n * id: 'test1.1',\n * label: 'test1.1',\n * },\n * {\n * id: 'test1.2',\n * label: 'test1.2',\n * },\n * ],\n * },\n * {\n * id: 'test2',\n * label: 'test2',\n * },\n * ]);\n */\n\n// TODO(wittjosiah): Type nodes.\nexport const buildGraph = (graph: Graph, id: string, nodes: any[]) => {\n addNodes(graph.root, id, nodes);\n return graph;\n};\n\nconst addNodes = (root: Node, id: string, nodes: any[]) => {\n nodes.forEach((node) => {\n const [child] = root.addNode(id, node);\n addNodes(child, id, node.children || []);\n node.actions?.forEach((action: any) => child.addAction(action));\n });\n};\n\nconst checkDepth = (node: Node, depth = 0): number => {\n if (!node.parent) {\n return depth;\n }\n\n return checkDepth(node.parent, depth + 1);\n};\n"],
5
- "mappings": ";AAkBO,IAAMA,wBAAwB,CAACC,IAAYC,QAAQ,MAAC;AACzD,QAAMC,QAAQ,oBAAIC,IAAAA;AAClB,QAAMC,cAA2B,CAACC,WAAAA;AAChC,QAAIC,WAAWD,MAAAA,KAAWJ,OAAO;AAC/B;IACF;AAEA,UAAM,CAACM,KAAAA,IAASF,OAAOG,QAAQR,IAAI;MACjCA,IAAI,GAAGK,OAAOL,EAAE,IAAIA,EAAAA;MACpBS,OAAO,GAAGJ,OAAOL,EAAE,IAAIA,EAAAA;MACvBU,MAAM;MACNL;IACF,CAAA;AAEAA,WAAOM,UAAU;MACfX,IAAI,GAAGK,OAAOL,EAAE,IAAIA,EAAAA;MACpBS,OAAO,GAAGJ,OAAOL,EAAE,IAAIA,EAAAA;MACvBY,QAAQ,MAAA;MAAO;IACjB,CAAA;AAEAV,UAAMW,IAAIR,OAAOL,IAAIK,MAAAA;AACrBH,UAAMW,IAAIN,MAAMP,IAAIO,KAAAA;EACtB;AAEA,QAAMC,UAAU,CAACM,UAAkBC,SAAAA;AACjC,UAAMV,SAASH,MAAMc,IAAIF,QAAAA;AACzB,QAAI,CAACT,QAAQ;AACX;IACF;AAEA,UAAM,CAACE,KAAAA,IAASF,OAAOG,QAAQR,IAAIe,IAAAA;AACnCb,UAAMW,IAAIN,MAAMP,IAAIO,KAAAA;AACpB,WAAOA;EACT;AAEA,QAAMU,aAAa,CAACH,UAAkBd,QAAAA;AACpC,UAAMK,SAASH,MAAMc,IAAIF,QAAAA;AACzB,QAAI,CAACT,QAAQ;AACX;IACF;AAEA,WAAOA,OAAOY,WAAWjB,GAAAA;EAC3B;AAEA,QAAMW,YAAY,CAACG,UAAkBI,WAAAA;AACnC,UAAMb,SAASH,MAAMc,IAAIF,QAAAA;AACzB,QAAI,CAACT,QAAQ;AAC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ent", "checkDepth", "child", "addNode", "label", "data", "addAction", "invoke", "set", "parentId", "node", "get", "removeNode", "action", "removeAction", "addProperty", "key", "value", "removeProperty", "buildGraph", "graph", "addNodes", "root", "forEach", "children", "actions"]
7
- }
@@ -1,122 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var testing_exports = {};
20
- __export(testing_exports, {
21
- buildGraph: () => buildGraph,
22
- createTestNodeBuilder: () => createTestNodeBuilder
23
- });
24
- module.exports = __toCommonJS(testing_exports);
25
- var createTestNodeBuilder = (id, depth = 1) => {
26
- const nodes = /* @__PURE__ */ new Map();
27
- const nodeBuilder = (parent) => {
28
- if (checkDepth(parent) >= depth) {
29
- return;
30
- }
31
- const [child] = parent.addNode(id, {
32
- id: `${parent.id}-${id}`,
33
- label: `${parent.id}-${id}`,
34
- data: null,
35
- parent
36
- });
37
- parent.addAction({
38
- id: `${parent.id}-${id}`,
39
- label: `${parent.id}-${id}`,
40
- invoke: () => {
41
- }
42
- });
43
- nodes.set(parent.id, parent);
44
- nodes.set(child.id, child);
45
- };
46
- const addNode = (parentId, node) => {
47
- const parent = nodes.get(parentId);
48
- if (!parent) {
49
- return;
50
- }
51
- const [child] = parent.addNode(id, node);
52
- nodes.set(child.id, child);
53
- return child;
54
- };
55
- const removeNode = (parentId, id2) => {
56
- const parent = nodes.get(parentId);
57
- if (!parent) {
58
- return;
59
- }
60
- return parent.removeNode(id2);
61
- };
62
- const addAction = (parentId, action) => {
63
- const parent = nodes.get(parentId);
64
- if (!parent) {
65
- return;
66
- }
67
- return parent.addAction(action);
68
- };
69
- const removeAction = (parentId, id2) => {
70
- const parent = nodes.get(parentId);
71
- if (!parent) {
72
- return;
73
- }
74
- return parent.removeAction(id2);
75
- };
76
- const addProperty = (parentId, key, value) => {
77
- const parent = nodes.get(parentId);
78
- if (!parent) {
79
- return;
80
- }
81
- return parent.addProperty(key, value);
82
- };
83
- const removeProperty = (parentId, key) => {
84
- const parent = nodes.get(parentId);
85
- if (!parent) {
86
- return;
87
- }
88
- return parent.removeProperty(key);
89
- };
90
- return {
91
- nodeBuilder,
92
- addNode,
93
- removeNode,
94
- addAction,
95
- removeAction,
96
- addProperty,
97
- removeProperty
98
- };
99
- };
100
- var buildGraph = (graph, id, nodes) => {
101
- addNodes(graph.root, id, nodes);
102
- return graph;
103
- };
104
- var addNodes = (root, id, nodes) => {
105
- nodes.forEach((node) => {
106
- const [child] = root.addNode(id, node);
107
- addNodes(child, id, node.children || []);
108
- node.actions?.forEach((action) => child.addAction(action));
109
- });
110
- };
111
- var checkDepth = (node, depth = 0) => {
112
- if (!node.parent) {
113
- return depth;
114
- }
115
- return checkDepth(node.parent, depth + 1);
116
- };
117
- // Annotate the CommonJS export names for ESM import in node:
118
- 0 && (module.exports = {
119
- buildGraph,
120
- createTestNodeBuilder
121
- });
122
- //# sourceMappingURL=testing.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/testing.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Action } from './action';\nimport { type Graph } from './graph';\nimport { type NodeBuilder, type Node } from './node';\n\n/**\n * Create a test node builder that always adds nodes and actions to the specified depth.\n *\n * @param id The id of the node builder, used to identify nodes created by this builder.\n * @param depth The depth at which to add nodes and actions.\n * @default 1\n *\n * @returns A test node builder\n */\n// TODO(burdon): Change to TestNodeBuilder class (see other builder/generator patterns in client/echo).\nexport const createTestNodeBuilder = (id: string, depth = 1) => {\n const nodes = new Map<string, Node>();\n const nodeBuilder: NodeBuilder = (parent) => {\n if (checkDepth(parent) >= depth) {\n return;\n }\n\n const [child] = parent.addNode(id, {\n id: `${parent.id}-${id}`,\n label: `${parent.id}-${id}`,\n data: null,\n parent,\n });\n\n parent.addAction({\n id: `${parent.id}-${id}`,\n label: `${parent.id}-${id}`,\n invoke: () => {},\n });\n\n nodes.set(parent.id, parent);\n nodes.set(child.id, child);\n };\n\n const addNode = (parentId: string, node: Pick<Node, 'id' | 'label'> & Partial<Node>) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n const [child] = parent.addNode(id, node);\n nodes.set(child.id, child);\n return child;\n };\n\n const removeNode = (parentId: string, id: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeNode(id);\n };\n\n const addAction = (parentId: string, action: Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Action>) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.addAction(action);\n };\n\n const removeAction = (parentId: string, id: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeAction(id);\n };\n\n const addProperty = (parentId: string, key: string, value: any) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.addProperty(key, value);\n };\n\n const removeProperty = (parentId: string, key: string) => {\n const parent = nodes.get(parentId);\n if (!parent) {\n return;\n }\n\n return parent.removeProperty(key);\n };\n\n return { nodeBuilder, addNode, removeNode, addAction, removeAction, addProperty, removeProperty };\n};\n\n/**\n * Build a graph from a nested list of nodes.\n *\n * @param graph Graph to add nodes to.\n * @param nodes Nodes to add to the\n *\n * @example\n * const graph = new GraphStore();\n * buildGraph(graph, [\n * {\n * id: 'test1',\n * label: 'test1',\n * children: [\n * {\n * id: 'test1.1',\n * label: 'test1.1',\n * },\n * {\n * id: 'test1.2',\n * label: 'test1.2',\n * },\n * ],\n * },\n * {\n * id: 'test2',\n * label: 'test2',\n * },\n * ]);\n */\n\n// TODO(wittjosiah): Type nodes.\nexport const buildGraph = (graph: Graph, id: string, nodes: any[]) => {\n addNodes(graph.root, id, nodes);\n return graph;\n};\n\nconst addNodes = (root: Node, id: string, nodes: any[]) => {\n nodes.forEach((node) => {\n const [child] = root.addNode(id, node);\n addNodes(child, id, node.children || []);\n node.actions?.forEach((action: any) => child.addAction(action));\n });\n};\n\nconst checkDepth = (node: Node, depth = 0): number => {\n if (!node.parent) {\n return depth;\n }\n\n return checkDepth(node.parent, depth + 1);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAMA,wBAAwB,CAACC,IAAYC,QAAQ,MAAC;AACzD,QAAMC,QAAQ,oBAAIC,IAAAA;AAClB,QAAMC,cAA2B,CAACC,WAAAA;AAChC,QAAIC,WAAWD,MAAAA,KAAWJ,OAAO;AAC/B;IACF;AAEA,UAAM,CAACM,KAAAA,IAASF,OAAOG,QAAQR,IAAI;MACjCA,IAAI,GAAGK,OAAOL,EAAE,IAAIA,EAAAA;MACpBS,OAAO,GAAGJ,OAAOL,EAAE,IAAIA,EAAAA;MACvBU,MAAM;MACNL;IACF,CAAA;AAEAA,WAAOM,UAAU;MACfX,IAAI,GAAGK,OAAOL,EAAE,IAAIA,EAAAA;MACpBS,OAAO,GAAGJ,OAAOL,EAAE,IAAIA,EAAAA;MACvBY,QAAQ,MAAA;MAAO;IACjB,CAAA;AAEAV,UAAMW,IAAIR,OAAOL,IAAIK,MAAAA;AACrBH,UAAMW,IAAIN,MAAMP,IAAIO,KAAAA;EACtB;AAEA,QAAMC,UAAU,CAACM,UAAkBC,SAAAA;AACjC,UAAMV,SAASH,MAAMc,IAAIF,QAAAA;AACzB,QAAI,CAACT,QAAQ;AACX;IACF;AAEA,UAAM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KnB,QAAQR,IAAIe,IAAAA;AACjCW,aAASnB,OAAOP,IAAIe,KAAKc,YAAY,CAAA,CAAE;AACvCd,SAAKe,SAASF,QAAQ,CAACV,WAAgBX,MAAMI,UAAUO,MAAAA,CAAAA;EACzD,CAAA;AACF;AAEA,IAAMZ,aAAa,CAACS,MAAYd,QAAQ,MAAC;AACvC,MAAI,CAACc,KAAKV,QAAQ;AAChB,WAAOJ;EACT;AAEA,SAAOK,WAAWS,KAAKV,QAAQJ,QAAQ,CAAA;AACzC;",
6
- "names": ["createTestNodeBuilder", "id", "depth", "nodes", "Map", "nodeBuilder", "parent", "checkDepth", "child", "addNode", "label", "data", "addAction", "invoke", "set", "parentId", "node", "get", "removeNode", "action", "removeAction", "addProperty", "key", "value", "removeProperty", "buildGraph", "graph", "addNodes", "root", "forEach", "children", "actions"]
7
- }
@@ -1,68 +0,0 @@
1
- import type { IconProps } from '@phosphor-icons/react';
2
- import type { FC } from 'react';
3
- import type { MaybePromise } from '@dxos/util';
4
- export type Label = string | [string, {
5
- ns: string;
6
- count?: number;
7
- }];
8
- export type InvokeParams = Partial<{
9
- caller: string;
10
- }>;
11
- /**
12
- * Platform-specific key binding.
13
- */
14
- export type KeyBinding = {
15
- windows?: string;
16
- macos?: string;
17
- ios?: string;
18
- linux?: string;
19
- unknown?: string;
20
- };
21
- /**
22
- * An action on a node in the graph which may be invoked by sending the associated intent.
23
- */
24
- export type Action<TProperties extends Record<string, any> = Record<string, any>> = {
25
- /**
26
- * Locally unique ID.
27
- */
28
- id: string;
29
- /**
30
- * Label to be used when displaying the node.
31
- * For default labels, use a translated string.
32
- *
33
- * @example 'Test Action'
34
- * @example ['test action label, { ns: 'example-plugin' }]
35
- */
36
- label: Label;
37
- /**
38
- * Icon to be used when displaying the node.
39
- */
40
- icon?: FC<IconProps>;
41
- /**
42
- * Key binding.
43
- */
44
- keyBinding?: string | KeyBinding;
45
- /**
46
- * Properties of the node relevant to displaying the action.
47
- *
48
- * @example { index: 'a1' }
49
- */
50
- properties: TProperties;
51
- /**
52
- * Sub-actions of the node stored by their id.
53
- */
54
- actionsMap: Record<string, Action>;
55
- /**
56
- * Actions of the node in default order.
57
- */
58
- get actions(): Action[];
59
- invoke: (params?: InvokeParams) => MaybePromise<any>;
60
- addProperty(key: string, value: any): void;
61
- removeProperty(key: string): void;
62
- addAction<TActionProperties extends Record<string, any> = Record<string, any>>(...action: ActionArg<TActionProperties>[]): Action<TActionProperties>[];
63
- removeAction(id: string): Action;
64
- };
65
- export type ActionArg<TProperties extends Record<string, any> = Record<string, any>> = Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Omit<Action<TProperties>, 'id' | 'label' | 'invoke' | 'actions'>> & {
66
- actions?: ActionArg[];
67
- };
68
- //# sourceMappingURL=action.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/action.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,M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AAC,EAAE,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC"}
@@ -1,52 +0,0 @@
1
- import { type Action } from './action';
2
- import { type Graph } from './graph';
3
- import { type NodeBuilder, type Node } from './node';
4
- /**
5
- * Create a test node builder that always adds nodes and actions to the specified depth.
6
- *
7
- * @param id The id of the node builder, used to identify nodes created by this builder.
8
- * @param depth The depth at which to add nodes and actions.
9
- * @default 1
10
- *
11
- * @returns A test node builder
12
- */
13
- export declare const createTestNodeBuilder: (id: string, depth?: number) => {
14
- nodeBuilder: NodeBuilder;
15
- addNode: (parentId: string, node: Pick<Node, 'id' | 'label'> & Partial<Node>) => Node<any, Record<string, any>> | undefined;
16
- removeNode: (parentId: string, id: string) => Node<any, Record<string, any>> | undefined;
17
- addAction: (parentId: string, action: Pick<Action, 'id' | 'label' | 'invoke'> & Partial<Action>) => Action<Record<string, any>>[] | undefined;
18
- removeAction: (parentId: string, id: string) => Action | undefined;
19
- addProperty: (parentId: string, key: string, value: any) => void;
20
- removeProperty: (parentId: string, key: string) => void;
21
- };
22
- /**
23
- * Build a graph from a nested list of nodes.
24
- *
25
- * @param graph Graph to add nodes to.
26
- * @param nodes Nodes to add to the
27
- *
28
- * @example
29
- * const graph = new GraphStore();
30
- * buildGraph(graph, [
31
- * {
32
- * id: 'test1',
33
- * label: 'test1',
34
- * children: [
35
- * {
36
- * id: 'test1.1',
37
- * label: 'test1.1',
38
- * },
39
- * {
40
- * id: 'test1.2',
41
- * label: 'test1.2',
42
- * },
43
- * ],
44
- * },
45
- * {
46
- * id: 'test2',
47
- * label: 'test2',
48
- * },
49
- * ]);
50
- */
51
- export declare const buildGraph: (graph: Graph, id: string, nodes: any[]) => Graph;
52
- //# sourceMappingURL=testing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,MAAM,QAAQ,CAAC;AAErD;;;;;;;;GAQG;AAEH,eAAO,MAAM,qBAAqB,OAAQ,MAAM;;wBAwBnB,MAAM,QAAQ,KAAK,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,QAAQ,IAAI,CAAC;2BAWrD,MAAM,MAAM,MAAM;0BASnB,MAAM,UAAU,KAAK,MAAM,EAAE,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,QAAQ,MAAM,CAAC;6BAStE,MAAM,MAAM,MAAM;4BASnB,MAAM,OAAO,MAAM,SAAS,GAAG;+BAS5B,MAAM,OAAO,MAAM;CAUtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,eAAO,MAAM,UAAU,UAAW,KAAK,MAAM,MAAM,SAAS,GAAG,EAAE,UAGhE,CAAC"}
package/src/action.ts DELETED
@@ -1,92 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import type { IconProps } from '@phosphor-icons/react';
6
- import type { FC } from 'react';
7
-
8
- import type { MaybePromise } from '@dxos/util';
9
-
10
- // TODO(thure): `Parameters<TFunction>` causes typechecking issues because `TFunction` has so many signatures.
11
- export type Label = string | [string, { ns: string; count?: number }];
12
-
13
- export type InvokeParams = Partial<{
14
- caller: string;
15
- }>;
16
-
17
- /**
18
- * Platform-specific key binding.
19
- */
20
- // NOTE: Keys come from `getHostPlatform` in `@dxos/util`.
21
- export type KeyBinding = {
22
- windows?: string;
23
- macos?: string;
24
- ios?: string;
25
- linux?: string;
26
- unknown?: string;
27
- };
28
-
29
- /**
30
- * An action on a node in the graph which may be invoked by sending the associated intent.
31
- */
32
- export type Action<TProperties extends Record<string, any> = Record<string, any>> = {
33
- /**
34
- * Locally unique ID.
35
- */
36
- id: string;
37
-
38
- /**
39
- * Label to be used when displaying the node.
40
- * For default labels, use a translated string.
41
- *
42
- * @example 'Test Action'
43
- * @example ['test action label, { ns: 'example-plugin' }]
44
- */
45
- label: Label;
46
-
47
- /**
48
- * Icon to be used when displaying the node.
49
- */
50
- icon?: FC<IconProps>;
51
-
52
- /**
53
- * Key binding.
54
- */
55
- // TODO(wittjosiah): Factor out.
56
- // TODO(burdon): Rename shortcut.
57
- keyBinding?: string | KeyBinding;
58
-
59
- /**
60
- * Properties of the node relevant to displaying the action.
61
- *
62
- * @example { index: 'a1' }
63
- */
64
- properties: TProperties;
65
-
66
- /**
67
- * Sub-actions of the node stored by their id.
68
- */
69
- actionsMap: Record<string, Action>;
70
-
71
- /**
72
- * Actions of the node in default order.
73
- */
74
- // TODO(burdon): Why get vs. prop?
75
- get actions(): Action[];
76
-
77
- invoke: (params?: InvokeParams) => MaybePromise<any>;
78
-
79
- addProperty(key: string, value: any): void;
80
- removeProperty(key: string): void;
81
-
82
- addAction<TActionProperties extends Record<string, any> = Record<string, any>>(
83
- ...action: ActionArg<TActionProperties>[]
84
- ): Action<TActionProperties>[];
85
- removeAction(id: string): Action;
86
- };
87
-
88
- export type ActionArg<TProperties extends Record<string, any> = Record<string, any>> = Pick<
89
- Action,
90
- 'id' | 'label' | 'invoke'
91
- > &
92
- Partial<Omit<Action<TProperties>, 'id' | 'label' | 'invoke' | 'actions'>> & { actions?: ActionArg[] };