@dxos/plugin-space 0.6.13 → 0.6.14-main.2b6a0f3

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.
Files changed (94) hide show
  1. package/dist/lib/browser/{chunk-DTVUOG2C.mjs → chunk-47SVNCZM.mjs} +24 -5
  2. package/dist/lib/browser/chunk-47SVNCZM.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-LZEGRS7H.mjs → chunk-AVLRQF6L.mjs} +1 -1
  4. package/dist/lib/browser/chunk-AVLRQF6L.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +609 -250
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/meta.mjs +1 -1
  9. package/dist/lib/browser/types/index.mjs +7 -3
  10. package/dist/lib/node/{chunk-CVZPI2P3.cjs → chunk-CTYDNFGG.cjs} +30 -9
  11. package/dist/lib/node/chunk-CTYDNFGG.cjs.map +7 -0
  12. package/dist/lib/node/{chunk-6CNYF6YU.cjs → chunk-P4XUXM7Y.cjs} +4 -4
  13. package/dist/lib/node/chunk-P4XUXM7Y.cjs.map +7 -0
  14. package/dist/lib/node/index.cjs +827 -471
  15. package/dist/lib/node/index.cjs.map +4 -4
  16. package/dist/lib/node/meta.cjs +5 -5
  17. package/dist/lib/node/meta.cjs.map +1 -1
  18. package/dist/lib/node/meta.json +1 -1
  19. package/dist/lib/node/types/index.cjs +14 -10
  20. package/dist/lib/node/types/index.cjs.map +2 -2
  21. package/dist/lib/node-esm/chunk-PLPMYTLC.mjs +116 -0
  22. package/dist/lib/node-esm/chunk-PLPMYTLC.mjs.map +7 -0
  23. package/dist/lib/node-esm/chunk-YPQGKWHJ.mjs +37 -0
  24. package/dist/lib/node-esm/chunk-YPQGKWHJ.mjs.map +7 -0
  25. package/dist/lib/node-esm/index.mjs +3000 -0
  26. package/dist/lib/node-esm/index.mjs.map +7 -0
  27. package/dist/lib/node-esm/meta.json +1 -0
  28. package/dist/lib/node-esm/meta.mjs +14 -0
  29. package/dist/lib/node-esm/meta.mjs.map +7 -0
  30. package/dist/lib/node-esm/types/index.mjs +26 -0
  31. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  32. package/dist/types/src/SpacePlugin.d.ts.map +1 -1
  33. package/dist/types/src/components/DefaultObjectSettings.d.ts +7 -0
  34. package/dist/types/src/components/DefaultObjectSettings.d.ts.map +1 -0
  35. package/dist/types/src/components/MenuFooter.d.ts +1 -1
  36. package/dist/types/src/components/MenuFooter.d.ts.map +1 -1
  37. package/dist/types/src/components/SaveStatus.d.ts +3 -0
  38. package/dist/types/src/components/SaveStatus.d.ts.map +1 -0
  39. package/dist/types/src/components/ShareSpaceButton.stories.d.ts +3 -91
  40. package/dist/types/src/components/ShareSpaceButton.stories.d.ts.map +1 -1
  41. package/dist/types/src/components/SpaceMain/SpaceMain.d.ts.map +1 -1
  42. package/dist/types/src/components/SpacePresence.stories.d.ts +4 -92
  43. package/dist/types/src/components/SpacePresence.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/SpaceSettings.d.ts.map +1 -1
  45. package/dist/types/src/components/SyncStatus/SyncStatus.d.ts +13 -0
  46. package/dist/types/src/components/SyncStatus/SyncStatus.d.ts.map +1 -0
  47. package/dist/types/src/components/SyncStatus/SyncStatus.stories.d.ts +24 -0
  48. package/dist/types/src/components/SyncStatus/SyncStatus.stories.d.ts.map +1 -0
  49. package/dist/types/src/components/SyncStatus/index.d.ts +2 -0
  50. package/dist/types/src/components/SyncStatus/index.d.ts.map +1 -0
  51. package/dist/types/src/components/SyncStatus/types.d.ts +14 -0
  52. package/dist/types/src/components/SyncStatus/types.d.ts.map +1 -0
  53. package/dist/types/src/components/index.d.ts +3 -2
  54. package/dist/types/src/components/index.d.ts.map +1 -1
  55. package/dist/types/src/meta.d.ts.map +1 -1
  56. package/dist/types/src/translations.d.ts +6 -0
  57. package/dist/types/src/translations.d.ts.map +1 -1
  58. package/dist/types/src/types/thread.d.ts +15 -1
  59. package/dist/types/src/types/thread.d.ts.map +1 -1
  60. package/dist/types/src/types/types.d.ts +18 -1
  61. package/dist/types/src/types/types.d.ts.map +1 -1
  62. package/dist/types/src/util.d.ts +3 -6
  63. package/dist/types/src/util.d.ts.map +1 -1
  64. package/package.json +45 -36
  65. package/src/SpacePlugin.tsx +173 -90
  66. package/src/components/DefaultObjectSettings.tsx +32 -0
  67. package/src/components/MenuFooter.tsx +2 -2
  68. package/src/components/SaveStatus.tsx +95 -0
  69. package/src/components/ShareSpaceButton.stories.tsx +11 -7
  70. package/src/components/SpaceMain/SpaceMain.tsx +1 -22
  71. package/src/components/SpacePresence.stories.tsx +11 -9
  72. package/src/components/SpacePresence.tsx +1 -1
  73. package/src/components/SpaceSettings.tsx +32 -3
  74. package/src/components/SyncStatus/SyncStatus.stories.tsx +65 -0
  75. package/src/components/SyncStatus/SyncStatus.tsx +188 -0
  76. package/src/components/SyncStatus/index.ts +5 -0
  77. package/src/components/SyncStatus/types.ts +77 -0
  78. package/src/components/index.ts +3 -2
  79. package/src/meta.ts +3 -1
  80. package/src/translations.ts +6 -0
  81. package/src/types/collection.ts +1 -1
  82. package/src/types/thread.ts +12 -2
  83. package/src/types/types.ts +25 -1
  84. package/src/util.tsx +20 -55
  85. package/dist/lib/browser/chunk-DTVUOG2C.mjs.map +0 -7
  86. package/dist/lib/browser/chunk-LZEGRS7H.mjs.map +0 -7
  87. package/dist/lib/node/chunk-6CNYF6YU.cjs.map +0 -7
  88. package/dist/lib/node/chunk-CVZPI2P3.cjs.map +0 -7
  89. package/dist/types/src/components/EmptySpace.d.ts +0 -3
  90. package/dist/types/src/components/EmptySpace.d.ts.map +0 -1
  91. package/dist/types/src/components/EmptyTree.d.ts +0 -3
  92. package/dist/types/src/components/EmptyTree.d.ts.map +0 -1
  93. package/src/components/EmptySpace.tsx +0 -25
  94. package/src/components/EmptyTree.tsx +0 -25
@@ -0,0 +1,3000 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ SPACE_PLUGIN,
4
+ SPACE_PLUGIN_SHORT_ID,
5
+ SpaceAction,
6
+ meta_default
7
+ } from "./chunk-YPQGKWHJ.mjs";
8
+ import {
9
+ ActorSchema,
10
+ ChannelType,
11
+ CollectionType,
12
+ ContactType,
13
+ MessageState,
14
+ MessageType,
15
+ SPACE_DIRECTORY_HANDLE,
16
+ ThreadStatus,
17
+ ThreadType,
18
+ parseSpaceInitPlugin
19
+ } from "./chunk-PLPMYTLC.mjs";
20
+
21
+ // packages/plugins/plugin-space/src/SpacePlugin.tsx
22
+ import { signal } from "@preact/signals-core";
23
+ import React17 from "react";
24
+ import { LayoutAction as LayoutAction2, NavigationAction as NavigationAction3, Surface as Surface2, firstIdInPart, openIds, parseGraphPlugin, parseIntentPlugin as parseIntentPlugin3, parseMetadataResolverPlugin, parseNavigationPlugin as parseNavigationPlugin2, resolvePlugin } from "@dxos/app-framework";
25
+ import { EventSubscriptions } from "@dxos/async";
26
+ import { isReactiveObject as isReactiveObject2 } from "@dxos/echo-schema";
27
+ import { scheduledEffect } from "@dxos/echo-signals/core";
28
+ import { LocalStorageStore } from "@dxos/local-storage";
29
+ import { log as log2 } from "@dxos/log";
30
+ import { Migrations as Migrations2 } from "@dxos/migrations";
31
+ import { parseAttentionPlugin } from "@dxos/plugin-attention";
32
+ import { parseClientPlugin } from "@dxos/plugin-client";
33
+ import { createExtension, memoize as memoize2, toSignal } from "@dxos/plugin-graph";
34
+ import { ObservabilityAction } from "@dxos/plugin-observability/meta";
35
+ import { PublicKey as PublicKey2 } from "@dxos/react-client";
36
+ import { Expando, Filter, SpaceState as SpaceState3, create as create2, fullyQualifiedId as fullyQualifiedId4, getSpace as getSpace4, getTypename as getTypename2, isEchoObject as isEchoObject2, isSpace as isSpace2, loadObjectReferences, parseFullyQualifiedId } from "@dxos/react-client/echo";
37
+ import { Dialog } from "@dxos/react-ui";
38
+ import { ClipboardProvider as ClipboardProvider2, InvitationManager, osTranslations } from "@dxos/shell/react";
39
+ import { ComplexMap as ComplexMap2, nonNullable, reduceGroupBy } from "@dxos/util";
40
+
41
+ // packages/plugins/plugin-space/src/components/AwaitingObject.tsx
42
+ import { CheckCircle, CircleDashed, CircleNotch } from "@phosphor-icons/react";
43
+ import React, { useEffect, useState } from "react";
44
+ import { parseIntentPlugin, useResolvePlugin, parseNavigationPlugin, NavigationAction } from "@dxos/app-framework";
45
+ import { useClient } from "@dxos/react-client";
46
+ import { fullyQualifiedId, useQuery } from "@dxos/react-client/echo";
47
+ import { Button, Toast, useTranslation } from "@dxos/react-ui";
48
+ import { getSize, mx } from "@dxos/react-ui-theme";
49
+ var WAIT_FOR_OBJECT_TIMEOUT = 18e4;
50
+ var TOAST_TIMEOUT = 24e4;
51
+ var AwaitingObject = ({ id }) => {
52
+ const [open, setOpen] = useState(true);
53
+ const [waiting, setWaiting] = useState(true);
54
+ const [found, setFound] = useState(false);
55
+ const { t } = useTranslation(SPACE_PLUGIN);
56
+ const intentPlugin = useResolvePlugin(parseIntentPlugin);
57
+ const navigationPlugin = useResolvePlugin(parseNavigationPlugin);
58
+ const client = useClient();
59
+ const objects = useQuery(client.spaces);
60
+ useEffect(() => {
61
+ if (!id) {
62
+ return;
63
+ }
64
+ const timeout = setTimeout(() => {
65
+ setWaiting(false);
66
+ }, WAIT_FOR_OBJECT_TIMEOUT);
67
+ () => clearTimeout(timeout);
68
+ }, [
69
+ id
70
+ ]);
71
+ useEffect(() => {
72
+ if (objects.findIndex((object) => fullyQualifiedId(object) === id) > -1) {
73
+ setFound(true);
74
+ if (navigationPlugin?.provides.location.active === id) {
75
+ setOpen(false);
76
+ }
77
+ }
78
+ }, [
79
+ id,
80
+ objects,
81
+ intentPlugin
82
+ ]);
83
+ const handleClose = async () => intentPlugin?.provides.intent.dispatch({
84
+ plugin: SPACE_PLUGIN,
85
+ action: SpaceAction.WAIT_FOR_OBJECT,
86
+ data: {
87
+ id: void 0
88
+ }
89
+ });
90
+ const handleNavigate = () => {
91
+ void intentPlugin?.provides.intent.dispatch({
92
+ action: NavigationAction.OPEN,
93
+ data: {
94
+ activeParts: {
95
+ main: [
96
+ id
97
+ ]
98
+ }
99
+ }
100
+ });
101
+ void handleClose();
102
+ };
103
+ return /* @__PURE__ */ React.createElement(Toast.Root, {
104
+ open,
105
+ duration: TOAST_TIMEOUT,
106
+ onOpenChange: setOpen
107
+ }, /* @__PURE__ */ React.createElement(Toast.Body, null, /* @__PURE__ */ React.createElement(Toast.Title, {
108
+ classNames: "flex items-center gap-2"
109
+ }, found ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CheckCircle, {
110
+ className: getSize(5)
111
+ }), /* @__PURE__ */ React.createElement("span", null, t("found object label"))) : waiting ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CircleNotch, {
112
+ className: mx(getSize(5), "animate-spin")
113
+ }), /* @__PURE__ */ React.createElement("span", null, t("waiting for object label"))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CircleDashed, {
114
+ className: getSize(5)
115
+ }), /* @__PURE__ */ React.createElement("span", null, t("object not found label")))), /* @__PURE__ */ React.createElement(Toast.Description, null, t(found ? "found object description" : waiting ? "waiting for object description" : "object not found description"))), /* @__PURE__ */ React.createElement(Toast.Actions, null, found ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Toast.Action, {
116
+ altText: t("go to object alt"),
117
+ asChild: true
118
+ }, /* @__PURE__ */ React.createElement(Button, {
119
+ variant: "primary",
120
+ onClick: handleNavigate
121
+ }, t("go to object label"))), /* @__PURE__ */ React.createElement(Toast.Close, {
122
+ asChild: true
123
+ }, /* @__PURE__ */ React.createElement(Button, {
124
+ onClick: handleClose
125
+ }, t("close label", {
126
+ ns: "appkit"
127
+ })))) : /* @__PURE__ */ React.createElement(Toast.Close, {
128
+ asChild: true
129
+ }, /* @__PURE__ */ React.createElement(Button, {
130
+ onClick: handleClose
131
+ }, t(waiting ? "close label" : "confirm label", {
132
+ ns: "appkit"
133
+ })))));
134
+ };
135
+
136
+ // packages/plugins/plugin-space/src/components/CollectionMain.tsx
137
+ import React2 from "react";
138
+ import { useTranslation as useTranslation2 } from "@dxos/react-ui";
139
+ import { baseSurface, descriptionText, mx as mx2 } from "@dxos/react-ui-theme";
140
+ var CollectionMain = ({ collection }) => {
141
+ const { t } = useTranslation2(SPACE_PLUGIN);
142
+ return /* @__PURE__ */ React2.createElement("div", {
143
+ role: "none",
144
+ className: mx2(baseSurface, "min-bs-screen is-full flex items-center justify-center p-8"),
145
+ "data-testid": "composer.firstRunMessage"
146
+ }, /* @__PURE__ */ React2.createElement("p", {
147
+ role: "alert",
148
+ className: mx2(descriptionText, "border border-dashed border-neutral-400/50 rounded-lg p-8 font-normal text-lg max-is-[24rem] break-words")
149
+ }, collection.name ?? t("unnamed collection label")));
150
+ };
151
+
152
+ // packages/plugins/plugin-space/src/components/CollectionSection.tsx
153
+ import React3 from "react";
154
+ import { useTranslation as useTranslation3 } from "@dxos/react-ui";
155
+ var CollectionSection = ({ collection }) => {
156
+ const { t } = useTranslation3(SPACE_PLUGIN);
157
+ return /* @__PURE__ */ React3.createElement("div", {
158
+ className: "min-bs-[3.5rem] grid grid-rows-subgrid grid-cols-subgrid items-center"
159
+ }, /* @__PURE__ */ React3.createElement("span", {
160
+ className: "truncate"
161
+ }, collection.name ?? t("unnamed collection label")));
162
+ };
163
+
164
+ // packages/plugins/plugin-space/src/components/DefaultObjectSettings.tsx
165
+ import React4 from "react";
166
+ import { Input, useTranslation as useTranslation4 } from "@dxos/react-ui";
167
+ var DefaultObjectSettings = ({ object }) => {
168
+ const { t } = useTranslation4(SPACE_PLUGIN);
169
+ return /* @__PURE__ */ React4.createElement("div", {
170
+ role: "form",
171
+ className: "flex flex-col w-full p-2 gap-1"
172
+ }, /* @__PURE__ */ React4.createElement(Input.Root, null, /* @__PURE__ */ React4.createElement(Input.Label, null, t("name label")), /* @__PURE__ */ React4.createElement(Input.TextInput, {
173
+ placeholder: t("name placeholder"),
174
+ value: object.name,
175
+ onChange: (event) => {
176
+ object.name = event.target.value;
177
+ }
178
+ })));
179
+ };
180
+
181
+ // packages/plugins/plugin-space/src/components/MenuFooter.tsx
182
+ import { Planet } from "@phosphor-icons/react";
183
+ import React5 from "react";
184
+ import { getSpace as getSpace2 } from "@dxos/client/echo";
185
+ import { useClient as useClient2 } from "@dxos/react-client";
186
+ import { DropdownMenu, toLocalizedString, useTranslation as useTranslation5 } from "@dxos/react-ui";
187
+
188
+ // packages/plugins/plugin-space/src/util.tsx
189
+ import { NavigationAction as NavigationAction2 } from "@dxos/app-framework";
190
+ import { create, isReactiveObject, getTypename, getSchema, getObjectAnnotation, EXPANDO_TYPENAME } from "@dxos/echo-schema";
191
+ import { invariant } from "@dxos/invariant";
192
+ import { Migrations } from "@dxos/migrations";
193
+ import { ACTION_TYPE, ACTION_GROUP_TYPE, actionGroupSymbol, getGraph, cleanup, memoize } from "@dxos/plugin-graph";
194
+ import { fullyQualifiedId as fullyQualifiedId2, getSpace, isEchoObject, isSpace, SpaceState } from "@dxos/react-client/echo";
195
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/util.tsx";
196
+ var SPACES = `${SPACE_PLUGIN}-spaces`;
197
+ var SPACE_TYPE = "dxos.org/type/Space";
198
+ var COMPOSER_SPACE_LOCK = "dxos.org/plugin/space/lock";
199
+ var SHARED = "shared-spaces";
200
+ var EMPTY_ARRAY = [];
201
+ var memoizeQuery = (spaceOrEcho, filter, options) => {
202
+ const key = isSpace(spaceOrEcho) ? spaceOrEcho.id : void 0;
203
+ const query = memoize(() => isSpace(spaceOrEcho) ? spaceOrEcho.db.query(filter, options) : spaceOrEcho?.query(filter, options), key);
204
+ const unsubscribe = memoize(() => query?.subscribe(), key);
205
+ cleanup(() => unsubscribe?.());
206
+ return query?.objects ?? EMPTY_ARRAY;
207
+ };
208
+ var getSpaceDisplayName = (space, { personal, namesCache = {} } = {}) => {
209
+ return space.state.get() === SpaceState.SPACE_READY && (space.properties.name?.length ?? 0) > 0 ? space.properties.name : namesCache[space.id] ? namesCache[space.id] : personal ? [
210
+ "personal space label",
211
+ {
212
+ ns: SPACE_PLUGIN
213
+ }
214
+ ] : [
215
+ "unnamed space label",
216
+ {
217
+ ns: SPACE_PLUGIN
218
+ }
219
+ ];
220
+ };
221
+ var getCollectionGraphNodePartials = ({ collection, space, resolve }) => {
222
+ return {
223
+ acceptPersistenceClass: /* @__PURE__ */ new Set([
224
+ "echo"
225
+ ]),
226
+ acceptPersistenceKey: /* @__PURE__ */ new Set([
227
+ space.id
228
+ ]),
229
+ role: "branch",
230
+ onRearrangeChildren: (nextOrder) => {
231
+ collection.objects = nextOrder.filter(isEchoObject);
232
+ },
233
+ onTransferStart: (child, index) => {
234
+ if (!collection.objects.includes(child.data)) {
235
+ if (typeof index !== "undefined") {
236
+ collection.objects.splice(index, 0, child.data);
237
+ } else {
238
+ collection.objects.push(child.data);
239
+ }
240
+ }
241
+ },
242
+ onTransferEnd: (child, destination) => {
243
+ const index = collection.objects.indexOf(child.data);
244
+ if (index > -1) {
245
+ collection.objects.splice(index, 1);
246
+ }
247
+ },
248
+ onCopy: async (child, index) => {
249
+ const newObject = await cloneObject(child.data, resolve);
250
+ space.db.add(newObject);
251
+ if (typeof index !== "undefined") {
252
+ collection.objects.splice(index, 0, newObject);
253
+ } else {
254
+ collection.objects.push(newObject);
255
+ }
256
+ }
257
+ };
258
+ };
259
+ var checkPendingMigration = (space) => {
260
+ return space.state.get() === SpaceState.SPACE_REQUIRES_MIGRATION || space.state.get() === SpaceState.SPACE_READY && !!Migrations.versionProperty && space.properties[Migrations.versionProperty] !== Migrations.targetVersion;
261
+ };
262
+ var constructSpaceNode = ({ space, personal, namesCache, resolve }) => {
263
+ const hasPendingMigration = checkPendingMigration(space);
264
+ const collection = space.state.get() === SpaceState.SPACE_READY && space.properties[CollectionType.typename];
265
+ const partials = space.state.get() === SpaceState.SPACE_READY && collection instanceof CollectionType ? getCollectionGraphNodePartials({
266
+ collection,
267
+ space,
268
+ resolve
269
+ }) : {};
270
+ return {
271
+ id: space.id,
272
+ type: SPACE_TYPE,
273
+ data: space,
274
+ properties: {
275
+ ...partials,
276
+ label: getSpaceDisplayName(space, {
277
+ personal,
278
+ namesCache
279
+ }),
280
+ description: space.state.get() === SpaceState.SPACE_READY && space.properties.description,
281
+ icon: "ph--planet--regular",
282
+ disabled: space.state.get() !== SpaceState.SPACE_READY || hasPendingMigration,
283
+ testId: "spacePlugin.space"
284
+ }
285
+ };
286
+ };
287
+ var constructSpaceActionGroups = ({ space, dispatch }) => {
288
+ const state = space.state.get();
289
+ const hasPendingMigration = checkPendingMigration(space);
290
+ const getId = (id) => `${id}/${space.id}`;
291
+ if (state !== SpaceState.SPACE_READY || hasPendingMigration) {
292
+ return [];
293
+ }
294
+ const collection = space.properties[CollectionType.typename];
295
+ const actions = [
296
+ {
297
+ id: getId(SpaceAction.ADD_OBJECT),
298
+ type: ACTION_GROUP_TYPE,
299
+ data: actionGroupSymbol,
300
+ properties: {
301
+ label: [
302
+ "create object in space label",
303
+ {
304
+ ns: SPACE_PLUGIN
305
+ }
306
+ ],
307
+ icon: "ph--plus--regular",
308
+ disposition: "toolbar",
309
+ // TODO(wittjosiah): This is currently a navtree feature. Address this with cmd+k integration.
310
+ // mainAreaDisposition: 'in-flow',
311
+ menuType: "searchList",
312
+ testId: "spacePlugin.createObject"
313
+ },
314
+ nodes: [
315
+ {
316
+ id: getId(SpaceAction.ADD_OBJECT.replace("object", "collection")),
317
+ type: ACTION_TYPE,
318
+ data: () => dispatch([
319
+ {
320
+ plugin: SPACE_PLUGIN,
321
+ action: SpaceAction.ADD_OBJECT,
322
+ data: {
323
+ target: collection,
324
+ object: create(CollectionType, {
325
+ objects: [],
326
+ views: {}
327
+ })
328
+ }
329
+ },
330
+ {
331
+ action: NavigationAction2.OPEN
332
+ }
333
+ ]),
334
+ properties: {
335
+ label: [
336
+ "create collection label",
337
+ {
338
+ ns: SPACE_PLUGIN
339
+ }
340
+ ],
341
+ icon: "ph--cards-three--regular",
342
+ testId: "spacePlugin.createCollection"
343
+ }
344
+ }
345
+ ]
346
+ }
347
+ ];
348
+ return actions;
349
+ };
350
+ var constructSpaceActions = ({ space, dispatch, personal, migrating }) => {
351
+ const state = space.state.get();
352
+ const hasPendingMigration = checkPendingMigration(space);
353
+ const getId = (id) => `${id}/${space.id}`;
354
+ const actions = [];
355
+ if (hasPendingMigration) {
356
+ actions.push({
357
+ id: getId(SpaceAction.MIGRATE),
358
+ type: ACTION_GROUP_TYPE,
359
+ data: async () => {
360
+ await dispatch({
361
+ plugin: SPACE_PLUGIN,
362
+ action: SpaceAction.MIGRATE,
363
+ data: {
364
+ space
365
+ }
366
+ });
367
+ },
368
+ properties: {
369
+ label: [
370
+ "migrate space label",
371
+ {
372
+ ns: SPACE_PLUGIN
373
+ }
374
+ ],
375
+ icon: "ph--database--regular",
376
+ disposition: "toolbar",
377
+ mainAreaDisposition: "in-flow",
378
+ disabled: migrating || Migrations.running(space)
379
+ }
380
+ });
381
+ }
382
+ if (state === SpaceState.SPACE_READY && !hasPendingMigration) {
383
+ const locked = space.properties[COMPOSER_SPACE_LOCK];
384
+ actions.push({
385
+ id: getId(SpaceAction.SHARE),
386
+ type: ACTION_TYPE,
387
+ data: async () => {
388
+ if (locked) {
389
+ return;
390
+ }
391
+ await dispatch({
392
+ plugin: SPACE_PLUGIN,
393
+ action: SpaceAction.SHARE,
394
+ data: {
395
+ spaceId: space.id
396
+ }
397
+ });
398
+ },
399
+ properties: {
400
+ label: [
401
+ "share space label",
402
+ {
403
+ ns: SPACE_PLUGIN
404
+ }
405
+ ],
406
+ icon: "ph--users--regular",
407
+ disabled: locked,
408
+ keyBinding: {
409
+ macos: "meta+.",
410
+ windows: "alt+."
411
+ },
412
+ mainAreaDisposition: "absent"
413
+ }
414
+ }, {
415
+ id: locked ? getId(SpaceAction.UNLOCK) : getId(SpaceAction.LOCK),
416
+ type: ACTION_TYPE,
417
+ data: async () => {
418
+ await dispatch({
419
+ plugin: SPACE_PLUGIN,
420
+ action: locked ? SpaceAction.UNLOCK : SpaceAction.LOCK,
421
+ data: {
422
+ space
423
+ }
424
+ });
425
+ },
426
+ properties: {
427
+ label: [
428
+ locked ? "unlock space label" : "lock space label",
429
+ {
430
+ ns: SPACE_PLUGIN
431
+ }
432
+ ],
433
+ icon: locked ? "ph--lock-simple-open--regular" : "ph--lock-simple--regular"
434
+ }
435
+ }, {
436
+ id: getId(SpaceAction.RENAME),
437
+ type: ACTION_TYPE,
438
+ data: async (params) => {
439
+ await dispatch({
440
+ plugin: SPACE_PLUGIN,
441
+ action: SpaceAction.RENAME,
442
+ data: {
443
+ space,
444
+ ...params
445
+ }
446
+ });
447
+ },
448
+ properties: {
449
+ label: [
450
+ "rename space label",
451
+ {
452
+ ns: SPACE_PLUGIN
453
+ }
454
+ ],
455
+ icon: "ph--pencil-simple-line--regular",
456
+ keyBinding: {
457
+ macos: "shift+F6",
458
+ windows: "shift+F6"
459
+ },
460
+ mainAreaDisposition: "absent"
461
+ }
462
+ });
463
+ }
464
+ if (state !== SpaceState.SPACE_INACTIVE && !hasPendingMigration) {
465
+ actions.push({
466
+ id: getId(SpaceAction.CLOSE),
467
+ type: ACTION_TYPE,
468
+ data: async () => {
469
+ await dispatch({
470
+ plugin: SPACE_PLUGIN,
471
+ action: SpaceAction.CLOSE,
472
+ data: {
473
+ space
474
+ }
475
+ });
476
+ },
477
+ properties: {
478
+ label: [
479
+ "close space label",
480
+ {
481
+ ns: SPACE_PLUGIN
482
+ }
483
+ ],
484
+ icon: "ph--x--regular",
485
+ mainAreaDisposition: "menu",
486
+ disabled: personal
487
+ }
488
+ });
489
+ }
490
+ if (state === SpaceState.SPACE_INACTIVE) {
491
+ actions.push({
492
+ id: getId(SpaceAction.OPEN),
493
+ type: ACTION_TYPE,
494
+ data: async () => {
495
+ await dispatch({
496
+ plugin: SPACE_PLUGIN,
497
+ action: SpaceAction.OPEN,
498
+ data: {
499
+ space
500
+ }
501
+ });
502
+ },
503
+ properties: {
504
+ label: [
505
+ "open space label",
506
+ {
507
+ ns: SPACE_PLUGIN
508
+ }
509
+ ],
510
+ icon: "ph--clock-counter-clockwise--regular",
511
+ disposition: "toolbar",
512
+ mainAreaDisposition: "in-flow"
513
+ }
514
+ });
515
+ }
516
+ return actions;
517
+ };
518
+ var createObjectNode = ({ object, space, resolve }) => {
519
+ const type = getTypename(object);
520
+ if (!type) {
521
+ return void 0;
522
+ }
523
+ const metadata = resolve(type);
524
+ if (Object.keys(metadata).length === 0) {
525
+ return void 0;
526
+ }
527
+ const partials = object instanceof CollectionType ? getCollectionGraphNodePartials({
528
+ collection: object,
529
+ space,
530
+ resolve
531
+ }) : metadata.graphProps;
532
+ return {
533
+ id: fullyQualifiedId2(object),
534
+ type,
535
+ data: object,
536
+ properties: {
537
+ ...partials,
538
+ label: metadata.label?.(object) || object.name || metadata.placeholder || [
539
+ "unnamed object label",
540
+ {
541
+ ns: SPACE_PLUGIN
542
+ }
543
+ ],
544
+ icon: metadata.icon ?? "ph--placeholder--regular",
545
+ testId: "spacePlugin.object",
546
+ persistenceClass: "echo",
547
+ persistenceKey: space?.id
548
+ }
549
+ };
550
+ };
551
+ var constructObjectActionGroups = ({ object, dispatch }) => {
552
+ if (!(object instanceof CollectionType)) {
553
+ return [];
554
+ }
555
+ const collection = object;
556
+ const getId = (id) => `${id}/${fullyQualifiedId2(object)}`;
557
+ const actions = [
558
+ {
559
+ id: getId(SpaceAction.ADD_OBJECT),
560
+ type: ACTION_GROUP_TYPE,
561
+ data: actionGroupSymbol,
562
+ properties: {
563
+ label: [
564
+ "create object in collection label",
565
+ {
566
+ ns: SPACE_PLUGIN
567
+ }
568
+ ],
569
+ icon: "ph--plus--regular",
570
+ disposition: "toolbar",
571
+ // TODO(wittjosiah): This is currently a navtree feature. Address this with cmd+k integration.
572
+ // mainAreaDisposition: 'in-flow',
573
+ menuType: "searchList",
574
+ testId: "spacePlugin.createObject"
575
+ },
576
+ nodes: [
577
+ {
578
+ id: getId(SpaceAction.ADD_OBJECT.replace("object", "collection")),
579
+ type: ACTION_TYPE,
580
+ data: () => dispatch([
581
+ {
582
+ plugin: SPACE_PLUGIN,
583
+ action: SpaceAction.ADD_OBJECT,
584
+ data: {
585
+ target: collection,
586
+ object: create(CollectionType, {
587
+ objects: [],
588
+ views: {}
589
+ })
590
+ }
591
+ },
592
+ {
593
+ action: NavigationAction2.OPEN
594
+ }
595
+ ]),
596
+ properties: {
597
+ label: [
598
+ "create collection label",
599
+ {
600
+ ns: SPACE_PLUGIN
601
+ }
602
+ ],
603
+ icon: "ph--cards-three--regular",
604
+ testId: "spacePlugin.createCollection"
605
+ }
606
+ }
607
+ ]
608
+ }
609
+ ];
610
+ return actions;
611
+ };
612
+ var constructObjectActions = ({ node, dispatch }) => {
613
+ const object = node.data;
614
+ const getId = (id) => `${id}/${fullyQualifiedId2(object)}`;
615
+ const actions = [
616
+ {
617
+ id: getId(SpaceAction.RENAME_OBJECT),
618
+ type: ACTION_TYPE,
619
+ data: async (params) => {
620
+ await dispatch({
621
+ action: SpaceAction.RENAME_OBJECT,
622
+ data: {
623
+ object,
624
+ ...params
625
+ }
626
+ });
627
+ },
628
+ properties: {
629
+ label: [
630
+ object instanceof CollectionType ? "rename collection label" : "rename object label",
631
+ {
632
+ ns: SPACE_PLUGIN
633
+ }
634
+ ],
635
+ icon: "ph--pencil-simple-line--regular",
636
+ // TODO(wittjosiah): Doesn't work.
637
+ // keyBinding: 'shift+F6',
638
+ testId: "spacePlugin.renameObject"
639
+ }
640
+ },
641
+ {
642
+ id: getId(SpaceAction.REMOVE_OBJECT),
643
+ type: ACTION_TYPE,
644
+ data: async () => {
645
+ const graph = getGraph(node);
646
+ const collection = graph.nodes(node, {
647
+ relation: "inbound"
648
+ }).find(({ data }) => data instanceof CollectionType)?.data;
649
+ await dispatch([
650
+ {
651
+ action: SpaceAction.REMOVE_OBJECT,
652
+ data: {
653
+ object,
654
+ collection
655
+ }
656
+ }
657
+ ]);
658
+ },
659
+ properties: {
660
+ label: [
661
+ object instanceof CollectionType ? "delete collection label" : "delete object label",
662
+ {
663
+ ns: SPACE_PLUGIN
664
+ }
665
+ ],
666
+ icon: "ph--trash--regular",
667
+ keyBinding: object instanceof CollectionType ? void 0 : "shift+meta+Backspace",
668
+ testId: "spacePlugin.deleteObject"
669
+ }
670
+ },
671
+ {
672
+ id: getId("copy-link"),
673
+ type: ACTION_TYPE,
674
+ data: async () => {
675
+ const url = `${window.location.origin}/${fullyQualifiedId2(object)}`;
676
+ await navigator.clipboard.writeText(url);
677
+ },
678
+ properties: {
679
+ label: [
680
+ "copy link label",
681
+ {
682
+ ns: SPACE_PLUGIN
683
+ }
684
+ ],
685
+ icon: "ph--link--regular",
686
+ testId: "spacePlugin.copyLink"
687
+ }
688
+ }
689
+ ];
690
+ return actions;
691
+ };
692
+ var getActiveSpace = (graph, active) => {
693
+ if (!active) {
694
+ return;
695
+ }
696
+ const node = graph.findNode(active);
697
+ if (!node || !isReactiveObject(node.data)) {
698
+ return;
699
+ }
700
+ return getSpace(node.data);
701
+ };
702
+ var getNestedObjects = async (object, resolve) => {
703
+ const type = getTypename(object);
704
+ if (!type) {
705
+ return [];
706
+ }
707
+ const metadata = resolve(type);
708
+ const loadReferences = metadata.loadReferences;
709
+ if (typeof loadReferences !== "function") {
710
+ return [];
711
+ }
712
+ const objects = await loadReferences(object);
713
+ const nested = await Promise.all(objects.map((object2) => getNestedObjects(object2, resolve)));
714
+ return [
715
+ ...objects,
716
+ ...nested.flat()
717
+ ];
718
+ };
719
+ var cloneObject = async (object, resolve) => {
720
+ const schema = getSchema(object);
721
+ const typename = schema ? getObjectAnnotation(schema)?.typename ?? EXPANDO_TYPENAME : EXPANDO_TYPENAME;
722
+ const metadata = resolve(typename);
723
+ const serializer = metadata.serializer;
724
+ invariant(serializer, `No serializer for type: ${typename}`, {
725
+ F: __dxlog_file,
726
+ L: 604,
727
+ S: void 0,
728
+ A: [
729
+ "serializer",
730
+ "`No serializer for type: ${typename}`"
731
+ ]
732
+ });
733
+ const content = await serializer.serialize({
734
+ object
735
+ });
736
+ return serializer.deserialize({
737
+ content,
738
+ newId: true
739
+ });
740
+ };
741
+
742
+ // packages/plugins/plugin-space/src/components/MenuFooter.tsx
743
+ var MenuFooter = ({ object }) => {
744
+ const { t } = useTranslation5(SPACE_PLUGIN);
745
+ const client = useClient2();
746
+ const space = getSpace2(object);
747
+ const spaceName = space ? getSpaceDisplayName(space, {
748
+ personal: client.spaces.default === space
749
+ }) : "";
750
+ return space ? /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(DropdownMenu.Separator, null), /* @__PURE__ */ React5.createElement(DropdownMenu.GroupLabel, null, t("menu footer label")), /* @__PURE__ */ React5.createElement("dl", {
751
+ className: "pis-2 mbe-2 text-xs grid grid-cols-[max-content_1fr] gap-2"
752
+ }, /* @__PURE__ */ React5.createElement("dt", {
753
+ className: "uppercase text-[.75em] tracking-wide font-medium mbs-px self-start"
754
+ }, t("location label")), /* @__PURE__ */ React5.createElement("dd", {
755
+ className: "line-clamp-3"
756
+ }, /* @__PURE__ */ React5.createElement(Planet, {
757
+ className: "inline-block mie-1"
758
+ }), toLocalizedString(spaceName, t)))) : null;
759
+ };
760
+
761
+ // packages/plugins/plugin-space/src/components/MissingObject.tsx
762
+ import React6, { useEffect as useEffect2, useState as useState2 } from "react";
763
+ import { parseIntentPlugin as parseIntentPlugin2, useResolvePlugin as useResolvePlugin2 } from "@dxos/app-framework";
764
+ import { Status, useTranslation as useTranslation6 } from "@dxos/react-ui";
765
+ import { baseSurface as baseSurface2, descriptionText as descriptionText2, mx as mx3 } from "@dxos/react-ui-theme";
766
+ var WAIT_FOR_OBJECT_TIMEOUT2 = 1e3;
767
+ var MissingObject = ({ id }) => {
768
+ const { t } = useTranslation6(SPACE_PLUGIN);
769
+ const [waiting, setWaiting] = useState2(false);
770
+ const intentPlugin = useResolvePlugin2(parseIntentPlugin2);
771
+ useEffect2(() => {
772
+ if (!intentPlugin) {
773
+ return;
774
+ }
775
+ const timeout = setTimeout(async () => {
776
+ setWaiting(true);
777
+ await intentPlugin.provides.intent.dispatch({
778
+ plugin: SPACE_PLUGIN,
779
+ action: SpaceAction.WAIT_FOR_OBJECT,
780
+ data: {
781
+ id
782
+ }
783
+ });
784
+ }, WAIT_FOR_OBJECT_TIMEOUT2);
785
+ return () => clearTimeout(timeout);
786
+ }, [
787
+ intentPlugin,
788
+ id
789
+ ]);
790
+ return /* @__PURE__ */ React6.createElement("div", {
791
+ role: "none",
792
+ className: mx3(baseSurface2, "min-bs-screen is-full flex items-center justify-center p-8")
793
+ }, waiting ? /* @__PURE__ */ React6.createElement("p", {
794
+ role: "alert",
795
+ className: mx3(descriptionText2, "border border-dashed border-neutral-400/50 rounded-lg flex items-center justify-center p-8 font-normal text-lg")
796
+ }, t("missing object message")) : /* @__PURE__ */ React6.createElement(Status, {
797
+ indeterminate: true,
798
+ "aria-label": "Initializing"
799
+ }));
800
+ };
801
+
802
+ // packages/plugins/plugin-space/src/components/PersistenceStatus.tsx
803
+ import { ArrowsCounterClockwise, CheckCircle as CheckCircle2, Warning } from "@phosphor-icons/react";
804
+ import React7, { useEffect as useEffect3, useState as useState3 } from "react";
805
+ import { debounce } from "@dxos/async";
806
+ import { Tooltip, useTranslation as useTranslation7 } from "@dxos/react-ui";
807
+ import { getSize as getSize2, mx as mx4, staticPlaceholderText, warningText } from "@dxos/react-ui-theme";
808
+ var Status2;
809
+ (function(Status3) {
810
+ Status3[Status3["PERSISTED_LOCALLY"] = 0] = "PERSISTED_LOCALLY";
811
+ Status3[Status3["PENDING"] = 1] = "PENDING";
812
+ Status3[Status3["ERROR"] = 2] = "ERROR";
813
+ })(Status2 || (Status2 = {}));
814
+ var PersistenceStatus = ({ db }) => {
815
+ const { t } = useTranslation7(SPACE_PLUGIN);
816
+ const [displayMessage, setDisplayMessage] = useState3(false);
817
+ const [status, naturalSetStatus] = useState3(0);
818
+ const [prevStatus, setPrevStatus] = useState3(0);
819
+ const _setStatus = debounce(naturalSetStatus, 500);
820
+ useEffect3(() => {
821
+ setPrevStatus(status);
822
+ if (prevStatus !== status && status === 0) {
823
+ setDisplayMessage(true);
824
+ const timeout = setTimeout(() => setDisplayMessage(false), 5e3);
825
+ return () => clearTimeout(timeout);
826
+ }
827
+ }, [
828
+ status
829
+ ]);
830
+ switch (status) {
831
+ case 2:
832
+ return /* @__PURE__ */ React7.createElement("div", {
833
+ className: "flex items-center"
834
+ }, /* @__PURE__ */ React7.createElement(Warning, {
835
+ className: mx4(getSize2(4), "me-1")
836
+ }), /* @__PURE__ */ React7.createElement("span", {
837
+ className: mx4("text-sm", warningText)
838
+ }, t("persistence error label")));
839
+ case 1:
840
+ return /* @__PURE__ */ React7.createElement("div", {
841
+ className: "flex items-center"
842
+ }, /* @__PURE__ */ React7.createElement(ArrowsCounterClockwise, {
843
+ className: mx4(getSize2(4), "me-1")
844
+ }), /* @__PURE__ */ React7.createElement("span", {
845
+ className: mx4("text-sm", staticPlaceholderText)
846
+ }, t("persistence pending label")));
847
+ case 0:
848
+ default:
849
+ return /* @__PURE__ */ React7.createElement(Tooltip.Root, {
850
+ delayDuration: 400
851
+ }, /* @__PURE__ */ React7.createElement(Tooltip.Trigger, {
852
+ role: "status",
853
+ className: "flex items-center"
854
+ }, /* @__PURE__ */ React7.createElement(CheckCircle2, {
855
+ className: mx4(getSize2(4), "me-1")
856
+ }), displayMessage && /* @__PURE__ */ React7.createElement("span", {
857
+ className: mx4("text-sm", staticPlaceholderText)
858
+ }, t("persisted locally label"))), /* @__PURE__ */ React7.createElement(Tooltip.Portal, null, /* @__PURE__ */ React7.createElement(Tooltip.Content, {
859
+ classNames: "z-10"
860
+ }, t("persisted locally message"), /* @__PURE__ */ React7.createElement(Tooltip.Arrow, null))));
861
+ }
862
+ };
863
+
864
+ // packages/plugins/plugin-space/src/components/PopoverRenameObject.tsx
865
+ import React8, { useCallback, useRef, useState as useState4 } from "react";
866
+ import { log } from "@dxos/log";
867
+ import { Button as Button2, Input as Input2, Popover, useTranslation as useTranslation8 } from "@dxos/react-ui";
868
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/PopoverRenameObject.tsx";
869
+ var PopoverRenameObject = ({ object: obj }) => {
870
+ const { t } = useTranslation8(SPACE_PLUGIN);
871
+ const doneButton = useRef(null);
872
+ const object = obj;
873
+ const [name, setName] = useState4(object.name || object.title || "");
874
+ const handleDone = useCallback(() => {
875
+ try {
876
+ object.name = name;
877
+ } catch {
878
+ try {
879
+ object.title = name;
880
+ } catch (err) {
881
+ log.error("Failed to rename object", {
882
+ err
883
+ }, {
884
+ F: __dxlog_file2,
885
+ L: 28,
886
+ S: void 0,
887
+ C: (f, a) => f(...a)
888
+ });
889
+ }
890
+ }
891
+ }, [
892
+ object,
893
+ name
894
+ ]);
895
+ return /* @__PURE__ */ React8.createElement("div", {
896
+ role: "none",
897
+ className: "p-1 flex gap-2"
898
+ }, /* @__PURE__ */ React8.createElement("div", {
899
+ role: "none",
900
+ className: "flex-1"
901
+ }, /* @__PURE__ */ React8.createElement(Input2.Root, null, /* @__PURE__ */ React8.createElement(Input2.Label, {
902
+ srOnly: true
903
+ }, t("object name label")), /* @__PURE__ */ React8.createElement(Input2.TextInput, {
904
+ placeholder: t("object title placeholder"),
905
+ value: name,
906
+ "data-testid": "spacePlugin.renameObject.input",
907
+ onChange: ({ target: { value } }) => setName(value),
908
+ onKeyDown: ({ key }) => key === "Enter" && doneButton.current?.click()
909
+ }))), /* @__PURE__ */ React8.createElement(Popover.Close, {
910
+ asChild: true
911
+ }, /* @__PURE__ */ React8.createElement(Button2, {
912
+ ref: doneButton,
913
+ classNames: "self-stretch",
914
+ onClick: handleDone
915
+ }, t("done label", {
916
+ ns: "os"
917
+ }))));
918
+ };
919
+
920
+ // packages/plugins/plugin-space/src/components/PopoverRenameSpace.tsx
921
+ import React9, { useCallback as useCallback2, useRef as useRef2, useState as useState5 } from "react";
922
+ import { Button as Button3, Input as Input3, Popover as Popover2, useTranslation as useTranslation9 } from "@dxos/react-ui";
923
+ var PopoverRenameSpace = ({ space }) => {
924
+ const { t } = useTranslation9(SPACE_PLUGIN);
925
+ const doneButton = useRef2(null);
926
+ const [name, setName] = useState5(space.properties.name ?? "");
927
+ const handleDone = useCallback2(() => {
928
+ space.properties.name = name;
929
+ }, [
930
+ space,
931
+ name
932
+ ]);
933
+ return /* @__PURE__ */ React9.createElement("div", {
934
+ role: "none",
935
+ className: "p-1 flex gap-2"
936
+ }, /* @__PURE__ */ React9.createElement("div", {
937
+ role: "none",
938
+ className: "flex-1"
939
+ }, /* @__PURE__ */ React9.createElement(Input3.Root, null, /* @__PURE__ */ React9.createElement(Input3.Label, {
940
+ srOnly: true
941
+ }, t("space name label")), /* @__PURE__ */ React9.createElement(Input3.TextInput, {
942
+ defaultValue: space.properties.name ?? "",
943
+ placeholder: t("unnamed space label"),
944
+ onChange: ({ target: { value } }) => setName(value),
945
+ // TODO(wittjosiah): Ideally this should access the popover context to close the popover.
946
+ // Currently this is not possible because Radix does not expose the popover context.
947
+ onKeyDown: ({ key }) => key === "Enter" && doneButton.current?.click()
948
+ }))), /* @__PURE__ */ React9.createElement(Popover2.Close, {
949
+ asChild: true
950
+ }, /* @__PURE__ */ React9.createElement(Button3, {
951
+ ref: doneButton,
952
+ classNames: "self-stretch",
953
+ onClick: handleDone
954
+ }, t("done label", {
955
+ ns: "os"
956
+ }))));
957
+ };
958
+
959
+ // packages/plugins/plugin-space/src/components/ShareSpaceButton.tsx
960
+ import React10 from "react";
961
+ import { useIntentDispatcher } from "@dxos/app-framework";
962
+ import { Button as Button4, useTranslation as useTranslation10 } from "@dxos/react-ui";
963
+ var ShareSpaceButton = ({ spaceId }) => {
964
+ const dispatch = useIntentDispatcher();
965
+ return /* @__PURE__ */ React10.createElement(ShareSpaceButtonImpl, {
966
+ onClick: () => dispatch({
967
+ action: SpaceAction.SHARE,
968
+ data: {
969
+ spaceId
970
+ }
971
+ })
972
+ });
973
+ };
974
+ var ShareSpaceButtonImpl = ({ onClick }) => {
975
+ const { t } = useTranslation10(SPACE_PLUGIN);
976
+ return /* @__PURE__ */ React10.createElement(Button4, {
977
+ "data-testid": "spacePlugin.shareSpaceButton",
978
+ onClick,
979
+ classNames: "mli-1"
980
+ }, t("share space label"));
981
+ };
982
+
983
+ // packages/plugins/plugin-space/src/components/SpaceMain/SpaceMain.tsx
984
+ import { Command } from "@phosphor-icons/react";
985
+ import React12 from "react";
986
+ import { Surface } from "@dxos/app-framework";
987
+ import { SpaceState as SpaceState2 } from "@dxos/react-client/echo";
988
+ import { Main, useTranslation as useTranslation12 } from "@dxos/react-ui";
989
+ import { getSize as getSize4, mx as mx6, topbarBlockPaddingStart } from "@dxos/react-ui-theme";
990
+ import { ClipboardProvider } from "@dxos/shell/react";
991
+
992
+ // packages/plugins/plugin-space/src/components/SpaceMain/SpaceMembersSection.tsx
993
+ import { CaretDown, Check, UserPlus, UsersThree } from "@phosphor-icons/react";
994
+ import React11, { useCallback as useCallback3, useState as useState6 } from "react";
995
+ import { LayoutAction, useIntent } from "@dxos/app-framework";
996
+ import { useMembers, SpaceMember, useSpaceInvitations } from "@dxos/react-client/echo";
997
+ import { InvitationEncoder } from "@dxos/react-client/invitations";
998
+ import { Invitation } from "@dxos/react-client/invitations";
999
+ import { Button as Button5, ButtonGroup, DropdownMenu as DropdownMenu2, List, useTranslation as useTranslation11 } from "@dxos/react-ui";
1000
+ import { descriptionText as descriptionText3, getSize as getSize3, mx as mx5 } from "@dxos/react-ui-theme";
1001
+ import { InvitationListItem, IdentityListItem } from "@dxos/shell/react";
1002
+ var activeActionKeyStorageKey = "dxos:react-shell/space-manager/active-action";
1003
+ var Presence = SpaceMember.PresenceState;
1004
+ var handleCreateInvitationUrl = (invitationCode) => `${origin}?spaceInvitationCode=${invitationCode}`;
1005
+ var SpaceMemberList = ({ members }) => {
1006
+ return members.length > 0 ? /* @__PURE__ */ React11.createElement(List, {
1007
+ classNames: "col-start-2 col-end-5 gap-y-1 grid grid-cols-subgrid items-center"
1008
+ }, members.map((member) => /* @__PURE__ */ React11.createElement(IdentityListItem, {
1009
+ classNames: "contents",
1010
+ key: member.identity.identityKey.toHex(),
1011
+ identity: member.identity,
1012
+ presence: member.presence
1013
+ }))) : null;
1014
+ };
1015
+ var SpaceMembersSection = ({ space }) => {
1016
+ const { t } = useTranslation11(SPACE_PLUGIN);
1017
+ const invitations = useSpaceInvitations(space.key);
1018
+ const { dispatch } = useIntent();
1019
+ const handleCloseDialog = () => dispatch({
1020
+ action: LayoutAction.SET_LAYOUT,
1021
+ data: {
1022
+ element: "dialog",
1023
+ state: false
1024
+ }
1025
+ });
1026
+ const handleInvitationSelect = ({ invitation: invitationObservable }) => {
1027
+ const invitation = invitationObservable.get();
1028
+ void dispatch({
1029
+ action: LayoutAction.SET_LAYOUT,
1030
+ data: {
1031
+ element: "dialog",
1032
+ component: "dxos.org/plugin/space/InvitationManagerDialog",
1033
+ subject: {
1034
+ invitationUrl: handleCreateInvitationUrl(InvitationEncoder.encode(invitation)),
1035
+ send: handleCloseDialog,
1036
+ status: invitation.state,
1037
+ type: invitation.type,
1038
+ authCode: invitation.authCode,
1039
+ id: invitation.invitationId
1040
+ }
1041
+ }
1042
+ });
1043
+ };
1044
+ const inviteActions = {
1045
+ inviteOne: {
1046
+ label: t("invite one label", {
1047
+ ns: "os"
1048
+ }),
1049
+ description: t("invite one description", {
1050
+ ns: "os"
1051
+ }),
1052
+ icon: UserPlus,
1053
+ onClick: useCallback3(() => {
1054
+ space.share?.({
1055
+ type: Invitation.Type.INTERACTIVE,
1056
+ authMethod: Invitation.AuthMethod.SHARED_SECRET
1057
+ });
1058
+ }, [
1059
+ space
1060
+ ])
1061
+ },
1062
+ inviteMany: {
1063
+ label: t("invite many label", {
1064
+ ns: "os"
1065
+ }),
1066
+ description: t("invite many description", {
1067
+ ns: "os"
1068
+ }),
1069
+ icon: UsersThree,
1070
+ onClick: useCallback3(() => {
1071
+ space.share?.({
1072
+ type: Invitation.Type.INTERACTIVE,
1073
+ authMethod: Invitation.AuthMethod.NONE,
1074
+ multiUse: true
1075
+ });
1076
+ }, [
1077
+ space
1078
+ ])
1079
+ }
1080
+ };
1081
+ const [activeActionKey, setInternalActiveActionKey] = useState6(localStorage.getItem(activeActionKeyStorageKey) ?? "inviteOne");
1082
+ const setActiveActionKey = (nextKey) => {
1083
+ setInternalActiveActionKey(nextKey);
1084
+ localStorage.setItem(activeActionKeyStorageKey, nextKey);
1085
+ };
1086
+ const activeAction = inviteActions[activeActionKey] ?? {};
1087
+ const members = useMembers(space.key).reduce((acc, member) => {
1088
+ acc[member.presence].push(member);
1089
+ return acc;
1090
+ }, {
1091
+ [Presence.ONLINE]: [],
1092
+ [Presence.OFFLINE]: []
1093
+ });
1094
+ return /* @__PURE__ */ React11.createElement("section", {
1095
+ className: "mbe-4 col-span-3 grid gap-y-2 grid-cols-subgrid auto-rows-min"
1096
+ }, /* @__PURE__ */ React11.createElement("h2", {
1097
+ className: "contents"
1098
+ }, /* @__PURE__ */ React11.createElement(UsersThree, {
1099
+ weight: "duotone",
1100
+ className: mx5(getSize3(5), "place-self-center")
1101
+ }), /* @__PURE__ */ React11.createElement("span", {
1102
+ className: "text-lg col-span-2"
1103
+ }, t("space members label"))), /* @__PURE__ */ React11.createElement("h3", {
1104
+ className: "col-start-2 col-span-3 text-sm italic text-description"
1105
+ }, t("invitations heading")), invitations.length > 0 && /* @__PURE__ */ React11.createElement(List, {
1106
+ classNames: "col-start-2 col-span-2 gap-y-2 grid grid-cols-[var(--rail-size)_1fr_var(--rail-action)_var(--rail-action)]"
1107
+ }, invitations.map((invitation) => /* @__PURE__ */ React11.createElement(InvitationListItem, {
1108
+ reverseEffects: true,
1109
+ classNames: "pis-0 pie-0 gap-0 col-span-4 grid grid-cols-subgrid",
1110
+ key: invitation.get().invitationId,
1111
+ invitation,
1112
+ send: handleInvitationSelect,
1113
+ createInvitationUrl: handleCreateInvitationUrl
1114
+ }))), /* @__PURE__ */ React11.createElement(ButtonGroup, {
1115
+ classNames: "col-start-2 col-end-4 grid grid-cols-[1fr_var(--rail-action)] place-self-grow gap-px"
1116
+ }, /* @__PURE__ */ React11.createElement(Button5, {
1117
+ classNames: "gap-2",
1118
+ onClick: activeAction.onClick
1119
+ }, /* @__PURE__ */ React11.createElement(activeAction.icon, {
1120
+ className: getSize3(5)
1121
+ }), /* @__PURE__ */ React11.createElement("span", null, t(activeAction.label, {
1122
+ ns: "os"
1123
+ }))), /* @__PURE__ */ React11.createElement(DropdownMenu2.Root, null, /* @__PURE__ */ React11.createElement(DropdownMenu2.Trigger, {
1124
+ asChild: true
1125
+ }, /* @__PURE__ */ React11.createElement(Button5, {
1126
+ classNames: "pli-0"
1127
+ }, /* @__PURE__ */ React11.createElement(CaretDown, {
1128
+ className: getSize3(4)
1129
+ }))), /* @__PURE__ */ React11.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React11.createElement(DropdownMenu2.Viewport, null, Object.entries(inviteActions).map(([id, action]) => {
1130
+ return /* @__PURE__ */ React11.createElement(DropdownMenu2.CheckboxItem, {
1131
+ key: id,
1132
+ "aria-labelledby": `${id}__label`,
1133
+ "aria-describedby": `${id}__description`,
1134
+ checked: activeActionKey === id,
1135
+ onCheckedChange: (checked) => checked && setActiveActionKey(id),
1136
+ classNames: "gap-2"
1137
+ }, action.icon && /* @__PURE__ */ React11.createElement(action.icon, {
1138
+ className: getSize3(5)
1139
+ }), /* @__PURE__ */ React11.createElement("div", {
1140
+ role: "none",
1141
+ className: "flex-1 min-is-0 space-b-1"
1142
+ }, /* @__PURE__ */ React11.createElement("p", {
1143
+ id: `${id}__label`
1144
+ }, t(action.label, {
1145
+ ns: "os"
1146
+ })), action.description && /* @__PURE__ */ React11.createElement("p", {
1147
+ id: `${id}__description`,
1148
+ className: descriptionText3
1149
+ }, t(action.description, {
1150
+ ns: "os"
1151
+ }))), /* @__PURE__ */ React11.createElement(DropdownMenu2.ItemIndicator, {
1152
+ asChild: true
1153
+ }, /* @__PURE__ */ React11.createElement(Check, {
1154
+ className: getSize3(4)
1155
+ })));
1156
+ })), /* @__PURE__ */ React11.createElement(DropdownMenu2.Arrow, null)))), members[Presence.ONLINE].length + members[Presence.OFFLINE].length < 1 ? /* @__PURE__ */ React11.createElement("p", {
1157
+ className: mx5(descriptionText3, "text-center is-full mlb-2")
1158
+ }, t("empty space members message", {
1159
+ ns: "os"
1160
+ })) : /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement("h3", {
1161
+ className: "col-start-2 col-end-5 text-sm italic text-description"
1162
+ }, t("active space members heading", {
1163
+ count: members[Presence.ONLINE].length
1164
+ })), /* @__PURE__ */ React11.createElement(SpaceMemberList, {
1165
+ members: members[Presence.ONLINE]
1166
+ }), /* @__PURE__ */ React11.createElement("h3", {
1167
+ className: "col-start-2 col-end-5 text-sm italic text-description"
1168
+ }, t("inactive space members heading", {
1169
+ count: members[Presence.OFFLINE].length
1170
+ })), /* @__PURE__ */ React11.createElement(SpaceMemberList, {
1171
+ members: members[Presence.OFFLINE]
1172
+ })));
1173
+ };
1174
+
1175
+ // packages/plugins/plugin-space/src/components/SpaceMain/SpaceMain.tsx
1176
+ var KeyShortcuts = () => {
1177
+ const { t } = useTranslation12(SPACE_PLUGIN);
1178
+ return /* @__PURE__ */ React12.createElement("section", {
1179
+ className: "mbe-4 col-span-4 md:col-start-5 md:col-end-7 grid grid-cols-subgrid gap-y-2 auto-rows-min"
1180
+ }, /* @__PURE__ */ React12.createElement("h2", {
1181
+ className: "contents"
1182
+ }, /* @__PURE__ */ React12.createElement(Command, {
1183
+ weight: "duotone",
1184
+ className: mx6(getSize4(5), "place-self-center")
1185
+ }), /* @__PURE__ */ React12.createElement("span", {
1186
+ className: "text-lg col-span-2 md:col-span-1"
1187
+ }, t("keyshortcuts label"))), /* @__PURE__ */ React12.createElement("div", {
1188
+ role: "none",
1189
+ className: "col-start-2 col-end-4 md:col-end-5 pie-2"
1190
+ }, /* @__PURE__ */ React12.createElement(Surface, {
1191
+ role: "keyshortcuts"
1192
+ })));
1193
+ };
1194
+ var spaceMainLayout = "grid gap-y-2 auto-rows-min before:bs-2 before:col-span-5 grid-cols-[var(--rail-size)_var(--rail-size)_1fr_var(--rail-size)] md:grid-cols-[var(--rail-size)_var(--rail-size)_minmax(max-content,1fr)_var(--rail-size)_var(--rail-size)_minmax(max-content,2fr)_var(--rail-size)]";
1195
+ var SpaceMain = ({ space, role }) => {
1196
+ const state = space.state.get();
1197
+ const ready = state === SpaceState2.SPACE_READY;
1198
+ const Root = role === "main" ? Main.Content : "div";
1199
+ return /* @__PURE__ */ React12.createElement(ClipboardProvider, null, /* @__PURE__ */ React12.createElement(Root, {
1200
+ ...role === "main" ? {
1201
+ classNames: [
1202
+ topbarBlockPaddingStart,
1203
+ "min-bs-dvh",
1204
+ spaceMainLayout
1205
+ ]
1206
+ } : {
1207
+ role: "none",
1208
+ className: mx6(topbarBlockPaddingStart, "row-span-2", spaceMainLayout)
1209
+ },
1210
+ "data-testid": `spacePlugin.${role}`,
1211
+ "data-isready": ready ? "true" : "false"
1212
+ }, ready && /* @__PURE__ */ React12.createElement(SpaceMembersSection, {
1213
+ space
1214
+ }), /* @__PURE__ */ React12.createElement(KeyShortcuts, null)));
1215
+ };
1216
+
1217
+ // packages/plugins/plugin-space/src/components/SpacePresence.tsx
1218
+ import React13, { useCallback as useCallback4, useEffect as useEffect4, useState as useState7 } from "react";
1219
+ import { usePlugin } from "@dxos/app-framework";
1220
+ import { generateName } from "@dxos/display-name";
1221
+ import { PublicKey, useClient as useClient3 } from "@dxos/react-client";
1222
+ import { getSpace as getSpace3, useMembers as useMembers2, fullyQualifiedId as fullyQualifiedId3 } from "@dxos/react-client/echo";
1223
+ import { useIdentity } from "@dxos/react-client/halo";
1224
+ import { Avatar, AvatarGroup, AvatarGroupItem, Tooltip as Tooltip2, useDensityContext, useTranslation as useTranslation13, List as List2, ListItem, useDefaultValue } from "@dxos/react-ui";
1225
+ import { AttentionGlyph } from "@dxos/react-ui-attention";
1226
+ import { ComplexMap, keyToFallback } from "@dxos/util";
1227
+ var REFRESH_INTERVAL = 5e3;
1228
+ var ACTIVITY_DURATION = 3e4;
1229
+ var noViewers = new ComplexMap(PublicKey.hash);
1230
+ var getName = (identity) => identity.profile?.displayName ?? generateName(identity.identityKey.toHex());
1231
+ var SpacePresence = ({ object, spaceKey }) => {
1232
+ const density = useDensityContext();
1233
+ const spacePlugin = usePlugin(SPACE_PLUGIN);
1234
+ const client = useClient3();
1235
+ const identity = useIdentity();
1236
+ const space = spaceKey ? client.spaces.get(spaceKey) : getSpace3(object);
1237
+ const spaceMembers = useMembers2(space?.key);
1238
+ const [_moment, setMoment] = useState7(Date.now());
1239
+ useEffect4(() => {
1240
+ const interval = setInterval(() => setMoment(Date.now()), REFRESH_INTERVAL);
1241
+ return () => clearInterval(interval);
1242
+ }, []);
1243
+ const memberOnline = useCallback4((member) => member.presence === 1, []);
1244
+ const memberIsNotSelf = useCallback4((member) => !identity?.identityKey.equals(member.identity.identityKey), [
1245
+ identity?.identityKey
1246
+ ]);
1247
+ if (!identity || !spacePlugin || !space) {
1248
+ return null;
1249
+ }
1250
+ const spaceState = spacePlugin.provides.space;
1251
+ const currentObjectViewers = spaceState.viewersByObject[fullyQualifiedId3(object)] ?? noViewers;
1252
+ const membersForObject = spaceMembers.filter((member) => memberOnline(member) && memberIsNotSelf(member)).filter((member) => currentObjectViewers.has(member.identity.identityKey)).map((member) => {
1253
+ const objectView = currentObjectViewers.get(member.identity.identityKey);
1254
+ const lastSeen = objectView?.lastSeen ?? -Infinity;
1255
+ const currentlyAttended = objectView?.currentlyAttended ?? false;
1256
+ return {
1257
+ ...member,
1258
+ currentlyAttended,
1259
+ lastSeen
1260
+ };
1261
+ }).toSorted((a, b) => a.lastSeen - b.lastSeen);
1262
+ return density === "fine" ? /* @__PURE__ */ React13.createElement(SmallPresence, {
1263
+ count: membersForObject.length
1264
+ }) : /* @__PURE__ */ React13.createElement(FullPresence, {
1265
+ members: membersForObject
1266
+ });
1267
+ };
1268
+ var FullPresence = (props) => {
1269
+ const { size = 9, onMemberClick } = props;
1270
+ const members = useDefaultValue(props.members, () => []);
1271
+ if (members.length === 0) {
1272
+ return null;
1273
+ }
1274
+ return /* @__PURE__ */ React13.createElement(AvatarGroup.Root, {
1275
+ size,
1276
+ classNames: "mbs-2 mie-4",
1277
+ "data-testid": "spacePlugin.presence"
1278
+ }, members.slice(0, 3).map((member, i) => /* @__PURE__ */ React13.createElement(Tooltip2.Root, {
1279
+ key: member.identity.identityKey.toHex()
1280
+ }, /* @__PURE__ */ React13.createElement(Tooltip2.Trigger, null, /* @__PURE__ */ React13.createElement(PrensenceAvatar, {
1281
+ identity: member.identity,
1282
+ group: true,
1283
+ match: member.currentlyAttended,
1284
+ index: members.length - i,
1285
+ onClick: () => onMemberClick?.(member)
1286
+ })), /* @__PURE__ */ React13.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React13.createElement(Tooltip2.Content, {
1287
+ side: "bottom"
1288
+ }, /* @__PURE__ */ React13.createElement("span", null, getName(member.identity)), /* @__PURE__ */ React13.createElement(Tooltip2.Arrow, null))))), members.length > 3 && /* @__PURE__ */ React13.createElement(Tooltip2.Root, null, /* @__PURE__ */ React13.createElement(Tooltip2.Trigger, null, /* @__PURE__ */ React13.createElement(AvatarGroupItem.Root, {
1289
+ status: "inactive"
1290
+ }, /* @__PURE__ */ React13.createElement(Avatar.Frame, {
1291
+ style: {
1292
+ zIndex: members.length - 4
1293
+ }
1294
+ }, /* @__PURE__ */ React13.createElement(Avatar.Fallback, {
1295
+ text: `+${members.length - 3}`
1296
+ })))), /* @__PURE__ */ React13.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React13.createElement(Tooltip2.Content, {
1297
+ side: "bottom"
1298
+ }, /* @__PURE__ */ React13.createElement(Tooltip2.Arrow, null), /* @__PURE__ */ React13.createElement(List2, {
1299
+ classNames: "max-h-56 overflow-y-auto"
1300
+ }, members.map((member) => /* @__PURE__ */ React13.createElement(ListItem.Root, {
1301
+ key: member.identity.identityKey.toHex(),
1302
+ classNames: "flex gap-2 items-center cursor-pointer mbe-2",
1303
+ onClick: () => onMemberClick?.(member),
1304
+ "data-testid": "identity-list-item"
1305
+ }, /* @__PURE__ */ React13.createElement(PrensenceAvatar, {
1306
+ identity: member.identity,
1307
+ showName: true,
1308
+ match: member.currentlyAttended
1309
+ }))))))));
1310
+ };
1311
+ var PrensenceAvatar = ({ identity, showName, match, group, index, onClick }) => {
1312
+ const Root = group ? AvatarGroupItem.Root : Avatar.Root;
1313
+ const status = match ? "current" : "active";
1314
+ const fallbackValue = keyToFallback(identity.identityKey);
1315
+ return /* @__PURE__ */ React13.createElement(Root, {
1316
+ status,
1317
+ hue: identity.profile?.data?.hue || fallbackValue.hue
1318
+ }, /* @__PURE__ */ React13.createElement(Avatar.Frame, {
1319
+ "data-testid": "spacePlugin.presence.member",
1320
+ "data-status": status,
1321
+ ...index ? {
1322
+ style: {
1323
+ zIndex: index
1324
+ }
1325
+ } : {},
1326
+ onClick: () => onClick?.()
1327
+ }, /* @__PURE__ */ React13.createElement(Avatar.Fallback, {
1328
+ text: identity.profile?.data?.emoji || fallbackValue.emoji
1329
+ })), showName && /* @__PURE__ */ React13.createElement(Avatar.Label, {
1330
+ classNames: "text-sm truncate pli-2"
1331
+ }, getName(identity)));
1332
+ };
1333
+ var SmallPresenceLive = ({ viewers }) => {
1334
+ const [moment, setMoment] = useState7(Date.now());
1335
+ useEffect4(() => {
1336
+ const interval = setInterval(() => setMoment(Date.now()), REFRESH_INTERVAL);
1337
+ return () => clearInterval(interval);
1338
+ }, []);
1339
+ const activeViewers = viewers ? Array.from(viewers.values()).filter(({ lastSeen }) => moment - lastSeen < ACTIVITY_DURATION) : [];
1340
+ return /* @__PURE__ */ React13.createElement(SmallPresence, {
1341
+ count: activeViewers.length
1342
+ });
1343
+ };
1344
+ var SmallPresence = ({ count }) => {
1345
+ const { t } = useTranslation13(SPACE_PLUGIN);
1346
+ return /* @__PURE__ */ React13.createElement(Tooltip2.Root, null, /* @__PURE__ */ React13.createElement(Tooltip2.Trigger, {
1347
+ asChild: true
1348
+ }, /* @__PURE__ */ React13.createElement(AttentionGlyph, {
1349
+ presence: count > 1 ? "many" : count === 1 ? "one" : "none",
1350
+ classNames: "self-center mie-1"
1351
+ })), /* @__PURE__ */ React13.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React13.createElement(Tooltip2.Content, {
1352
+ side: "bottom",
1353
+ classNames: "z-[70]"
1354
+ }, /* @__PURE__ */ React13.createElement("span", null, t("presence label", {
1355
+ count
1356
+ })), /* @__PURE__ */ React13.createElement(Tooltip2.Arrow, null))));
1357
+ };
1358
+
1359
+ // packages/plugins/plugin-space/src/components/SpaceSettings.tsx
1360
+ import React14 from "react";
1361
+ import { useIntentDispatcher as useIntentDispatcher2, useResolvePlugins } from "@dxos/app-framework";
1362
+ import { SettingsValue } from "@dxos/plugin-settings";
1363
+ import { Input as Input4, Select, toLocalizedString as toLocalizedString2, useTranslation as useTranslation14 } from "@dxos/react-ui";
1364
+ var SpaceSettings = ({ settings }) => {
1365
+ const { t } = useTranslation14(SPACE_PLUGIN);
1366
+ const dispatch = useIntentDispatcher2();
1367
+ const plugins = useResolvePlugins(parseSpaceInitPlugin);
1368
+ return /* @__PURE__ */ React14.createElement(React14.Fragment, null, /* @__PURE__ */ React14.createElement(SettingsValue, {
1369
+ label: t("show hidden spaces label")
1370
+ }, /* @__PURE__ */ React14.createElement(Input4.Switch, {
1371
+ checked: settings.showHidden,
1372
+ onCheckedChange: (checked) => dispatch({
1373
+ plugin: SPACE_PLUGIN,
1374
+ action: SpaceAction.TOGGLE_HIDDEN,
1375
+ data: {
1376
+ state: !!checked
1377
+ }
1378
+ })
1379
+ })), /* @__PURE__ */ React14.createElement(SettingsValue, {
1380
+ label: t("default on space create label")
1381
+ }, /* @__PURE__ */ React14.createElement(Select.Root, {
1382
+ value: settings.onSpaceCreate,
1383
+ onValueChange: (value) => {
1384
+ settings.onSpaceCreate = value;
1385
+ }
1386
+ }, /* @__PURE__ */ React14.createElement(Select.TriggerButton, null), /* @__PURE__ */ React14.createElement(Select.Portal, null, /* @__PURE__ */ React14.createElement(Select.Content, null, /* @__PURE__ */ React14.createElement(Select.Viewport, null, plugins.map(({ provides: { space: { onSpaceCreate } } }) => /* @__PURE__ */ React14.createElement(Select.Option, {
1387
+ key: onSpaceCreate.action,
1388
+ value: onSpaceCreate.action
1389
+ }, toLocalizedString2(onSpaceCreate.label, t)))))))));
1390
+ };
1391
+
1392
+ // packages/plugins/plugin-space/src/components/SaveStatus.tsx
1393
+ import React15, { useEffect as useEffect5, useState as useState8 } from "react";
1394
+ import { Context } from "@dxos/context";
1395
+ import { StatusBar } from "@dxos/plugin-status-bar";
1396
+ import { useClient as useClient4 } from "@dxos/react-client";
1397
+ import { Icon, useTranslation as useTranslation15 } from "@dxos/react-ui";
1398
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SaveStatus.tsx";
1399
+ var SaveStatus = () => {
1400
+ const { t } = useTranslation15(SPACE_PLUGIN);
1401
+ const client = useClient4();
1402
+ const [state, setState] = useState8("saved");
1403
+ useEffect5(() => {
1404
+ return createClientSaveTracker(client, (state2) => {
1405
+ setState(state2);
1406
+ });
1407
+ }, []);
1408
+ return /* @__PURE__ */ React15.createElement(StatusBar.Item, {
1409
+ title: state === "saving" ? t("saving label") : t("saved label")
1410
+ }, /* @__PURE__ */ React15.createElement(Icon, {
1411
+ icon: state === "saving" ? "ph--arrows-clockwise--regular" : "ph--check-circle--regular",
1412
+ size: 4
1413
+ }));
1414
+ };
1415
+ var createClientSaveTracker = (client, cb) => {
1416
+ const unsubscribeCallbacks = {};
1417
+ const state = {};
1418
+ const install = (spaces) => {
1419
+ for (const space of spaces) {
1420
+ if (state[space.id]) {
1421
+ continue;
1422
+ }
1423
+ state[space.id] = "saved";
1424
+ unsubscribeCallbacks[space.id] = createSpaceSaveTracker(space, (s) => {
1425
+ state[space.id] = s;
1426
+ cb(Object.values(state).some((s2) => s2 === "saving") ? "saving" : "saved");
1427
+ });
1428
+ }
1429
+ };
1430
+ client.spaces.subscribe((spaces) => {
1431
+ install(spaces);
1432
+ });
1433
+ install(client.spaces.get());
1434
+ return () => {
1435
+ for (const unsubscribe of Object.values(unsubscribeCallbacks)) {
1436
+ unsubscribe();
1437
+ }
1438
+ };
1439
+ };
1440
+ var createSpaceSaveTracker = (space, cb) => {
1441
+ const ctx = new Context(void 0, {
1442
+ F: __dxlog_file3,
1443
+ L: 64
1444
+ });
1445
+ void space.waitUntilReady().then(() => {
1446
+ if (ctx.disposed) {
1447
+ return;
1448
+ }
1449
+ let hasUnsavedChanges = false;
1450
+ let lastFlushPromise;
1451
+ space.crud.saveStateChanged.on(ctx, ({ unsavedDocuments }) => {
1452
+ hasUnsavedChanges = unsavedDocuments.length > 0;
1453
+ });
1454
+ space.crud.saveStateChanged.debounce(500).on(ctx, () => {
1455
+ if (hasUnsavedChanges) {
1456
+ lastFlushPromise = void 0;
1457
+ cb("saving");
1458
+ } else {
1459
+ const flushPromise = space.crud.flush();
1460
+ lastFlushPromise = flushPromise;
1461
+ void flushPromise.then(() => {
1462
+ if (lastFlushPromise === flushPromise) {
1463
+ cb("saved");
1464
+ }
1465
+ });
1466
+ }
1467
+ });
1468
+ });
1469
+ return () => {
1470
+ void ctx.dispose();
1471
+ };
1472
+ };
1473
+
1474
+ // packages/plugins/plugin-space/src/components/SyncStatus/SyncStatus.tsx
1475
+ import React16, { useEffect as useEffect7, useState as useState10 } from "react";
1476
+ import { StatusBar as StatusBar2 } from "@dxos/plugin-status-bar";
1477
+ import { Icon as Icon2, Popover as Popover3, useTranslation as useTranslation16 } from "@dxos/react-ui";
1478
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
1479
+ import { mx as mx7 } from "@dxos/react-ui-theme";
1480
+
1481
+ // packages/plugins/plugin-space/src/components/SyncStatus/types.ts
1482
+ import { useEffect as useEffect6, useState as useState9 } from "react";
1483
+ import { Context as Context2 } from "@dxos/context";
1484
+ import { EdgeService } from "@dxos/protocols";
1485
+ import { useClient as useClient5 } from "@dxos/react-client";
1486
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SyncStatus/types.ts";
1487
+ var createEmptyEdgeSyncState = () => ({
1488
+ missingOnLocal: 0,
1489
+ missingOnRemote: 0,
1490
+ localDocumentCount: 0,
1491
+ remoteDocumentCount: 0,
1492
+ differentDocuments: 0
1493
+ });
1494
+ var getSyncSummary = (syncMap) => {
1495
+ return Object.entries(syncMap).reduce((summary, [_spaceId, peerState]) => {
1496
+ summary.missingOnLocal += peerState.missingOnLocal;
1497
+ summary.missingOnRemote += peerState.missingOnRemote;
1498
+ summary.localDocumentCount += peerState.localDocumentCount;
1499
+ summary.remoteDocumentCount += peerState.remoteDocumentCount;
1500
+ summary.differentDocuments += peerState.differentDocuments;
1501
+ return summary;
1502
+ }, createEmptyEdgeSyncState());
1503
+ };
1504
+ var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);
1505
+ var useSyncState = () => {
1506
+ const client = useClient5();
1507
+ const [spaceState, setSpaceState] = useState9({});
1508
+ useEffect6(() => {
1509
+ const ctx = new Context2(void 0, {
1510
+ F: __dxlog_file4,
1511
+ L: 48
1512
+ });
1513
+ const createSubscriptions = (spaces) => {
1514
+ for (const space of spaces) {
1515
+ if (spaceState[space.id]) {
1516
+ continue;
1517
+ }
1518
+ ctx.onDispose(space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {
1519
+ const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
1520
+ if (syncState) {
1521
+ setSpaceState((spaceState2) => ({
1522
+ ...spaceState2,
1523
+ [space.id]: syncState
1524
+ }));
1525
+ }
1526
+ }));
1527
+ }
1528
+ };
1529
+ createSubscriptions(client.spaces.get());
1530
+ client.spaces.subscribe((spaces) => {
1531
+ createSubscriptions(spaces);
1532
+ });
1533
+ return () => {
1534
+ void ctx.dispose();
1535
+ };
1536
+ }, [
1537
+ client
1538
+ ]);
1539
+ return spaceState;
1540
+ };
1541
+
1542
+ // packages/plugins/plugin-space/src/components/SyncStatus/SyncStatus.tsx
1543
+ var SYNC_STALLED_TIMEOUT = 5e3;
1544
+ var styles = {
1545
+ barBg: "bg-neutral-50 dark:bg-green-900 text-black",
1546
+ barFg: "bg-neutral-100 bg-green-500",
1547
+ barHover: "dark:hover:bg-green-500"
1548
+ };
1549
+ var SyncStatus = () => {
1550
+ const state = useSyncState();
1551
+ return /* @__PURE__ */ React16.createElement(SyncStatusIndicator, {
1552
+ state
1553
+ });
1554
+ };
1555
+ var SyncStatusIndicator = ({ state }) => {
1556
+ const summary = getSyncSummary(state);
1557
+ const offline = false;
1558
+ const needsToUpload = summary.differentDocuments > 0 || summary.missingOnRemote > 0;
1559
+ const needsToDownload = summary.differentDocuments > 0 || summary.missingOnLocal > 0;
1560
+ const [classNames, setClassNames] = useState10();
1561
+ useEffect7(() => {
1562
+ setClassNames(void 0);
1563
+ if (!needsToUpload && !needsToDownload) {
1564
+ return;
1565
+ }
1566
+ const t = setTimeout(() => {
1567
+ setClassNames("text-orange-500");
1568
+ }, SYNC_STALLED_TIMEOUT);
1569
+ return () => clearTimeout(t);
1570
+ }, [
1571
+ needsToUpload,
1572
+ needsToDownload
1573
+ ]);
1574
+ return /* @__PURE__ */ React16.createElement(StatusBar2.Item, null, /* @__PURE__ */ React16.createElement(Popover3.Root, null, /* @__PURE__ */ React16.createElement(Popover3.Trigger, null, /* @__PURE__ */ React16.createElement(Icon2, {
1575
+ icon: offline ? "ph--cloud-x--regular" : needsToUpload ? "ph--cloud-arrow-up--regular" : needsToDownload ? "ph--cloud-arrow-down--regular" : "ph--cloud-check--regular",
1576
+ size: 4,
1577
+ classNames
1578
+ })), /* @__PURE__ */ React16.createElement(Popover3.Content, null, /* @__PURE__ */ React16.createElement(SyncStatusDetail, {
1579
+ state,
1580
+ summary,
1581
+ debug: false
1582
+ }))));
1583
+ };
1584
+ var SyncStatusDetail = ({ classNames, state, summary, debug }) => {
1585
+ const { t } = useTranslation16(SPACE_PLUGIN);
1586
+ const entries = Object.entries(state).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
1587
+ return /* @__PURE__ */ React16.createElement("div", {
1588
+ className: mx7("flex flex-col text-xs min-w-[16rem]", classNames)
1589
+ }, /* @__PURE__ */ React16.createElement("h1", {
1590
+ className: "p-2"
1591
+ }, t("sync status title")), /* @__PURE__ */ React16.createElement("div", {
1592
+ className: "flex flex-col gap-[2px] my-[2px]"
1593
+ }, entries.map(([spaceId, state2]) => /* @__PURE__ */ React16.createElement(SpaceRow, {
1594
+ key: spaceId,
1595
+ spaceId,
1596
+ state: state2
1597
+ }))), debug && /* @__PURE__ */ React16.createElement(SyntaxHighlighter, {
1598
+ language: "json"
1599
+ }, JSON.stringify(summary, null, 2)));
1600
+ };
1601
+ var useActive = (count) => {
1602
+ const [current, setCurrent] = useState10(count);
1603
+ const [active, setActive] = useState10(false);
1604
+ useEffect7(() => {
1605
+ let t;
1606
+ if (count !== current) {
1607
+ setActive(true);
1608
+ setCurrent(count);
1609
+ t && clearTimeout(t);
1610
+ t = setTimeout(() => {
1611
+ setActive(false);
1612
+ }, SYNC_STALLED_TIMEOUT);
1613
+ }
1614
+ return () => {
1615
+ setActive(false);
1616
+ clearTimeout(t);
1617
+ };
1618
+ }, [
1619
+ count,
1620
+ current
1621
+ ]);
1622
+ return active;
1623
+ };
1624
+ var SpaceRow = ({ spaceId, state: { localDocumentCount, remoteDocumentCount, missingOnLocal, missingOnRemote } }) => {
1625
+ const downActive = useActive(localDocumentCount);
1626
+ const upActive = useActive(remoteDocumentCount);
1627
+ return /* @__PURE__ */ React16.createElement("div", {
1628
+ className: mx7("flex items-center mx-[2px] gap-[2px] cursor-pointer", styles.barHover),
1629
+ title: spaceId,
1630
+ onClick: () => {
1631
+ void navigator.clipboard.writeText(spaceId);
1632
+ }
1633
+ }, /* @__PURE__ */ React16.createElement(Icon2, {
1634
+ icon: "ph--arrow-fat-line-left--regular",
1635
+ size: 3,
1636
+ classNames: mx7(downActive && "animate-[pulse_1s_infinite]")
1637
+ }), /* @__PURE__ */ React16.createElement(Candle, {
1638
+ up: {
1639
+ count: remoteDocumentCount,
1640
+ total: remoteDocumentCount + missingOnRemote
1641
+ },
1642
+ down: {
1643
+ count: localDocumentCount,
1644
+ total: localDocumentCount + missingOnLocal
1645
+ },
1646
+ title: spaceId
1647
+ }), /* @__PURE__ */ React16.createElement(Icon2, {
1648
+ icon: "ph--arrow-fat-line-right--regular",
1649
+ size: 3,
1650
+ classNames: mx7(upActive && "animate-[pulse_1s_step-start_infinite]")
1651
+ }));
1652
+ };
1653
+ var Candle = ({ classNames, up, down }) => {
1654
+ return /* @__PURE__ */ React16.createElement("div", {
1655
+ className: mx7("grid grid-cols-[1fr_2rem_1fr] w-full h-3", classNames)
1656
+ }, /* @__PURE__ */ React16.createElement(Bar, {
1657
+ classNames: "justify-end",
1658
+ ...up
1659
+ }), /* @__PURE__ */ React16.createElement("div", {
1660
+ className: "relative"
1661
+ }, /* @__PURE__ */ React16.createElement("div", {
1662
+ className: mx7("absolute inset-0 flex items-center justify-center text-xs", styles.barBg)
1663
+ }, up.total)), /* @__PURE__ */ React16.createElement(Bar, down));
1664
+ };
1665
+ var Bar = ({ classNames, count, total }) => {
1666
+ let p = count / total * 100;
1667
+ if (count < total) {
1668
+ p = Math.min(p, 95);
1669
+ }
1670
+ return /* @__PURE__ */ React16.createElement("div", {
1671
+ className: mx7("relative flex w-full", styles.barBg, classNames)
1672
+ }, /* @__PURE__ */ React16.createElement("div", {
1673
+ className: mx7("shrink-0", styles.barFg),
1674
+ style: {
1675
+ width: `${p}%`
1676
+ }
1677
+ }), count !== total && /* @__PURE__ */ React16.createElement("div", {
1678
+ className: "absolute top-0 bottom-0 flex items-center mx-0.5 text-black text-xs"
1679
+ }, count));
1680
+ };
1681
+
1682
+ // packages/plugins/plugin-space/src/translations.ts
1683
+ var translations_default = [
1684
+ {
1685
+ "en-US": {
1686
+ [SPACE_PLUGIN]: {
1687
+ "plugin name": "Spaces",
1688
+ "first run message": "Nothing selected.",
1689
+ "create space label": "Create a new space",
1690
+ "join space label": "Join a space",
1691
+ "empty space message": "No documents",
1692
+ "empty tree message": "No spaces",
1693
+ "unnamed space label": "New space",
1694
+ "closed space label": "Closed",
1695
+ "loading space label": "Loading space\u2026",
1696
+ "lock space label": "Lock space",
1697
+ "unlock space label": "Unlock space",
1698
+ "rename space label": "Rename space",
1699
+ "active space label": "Active space:",
1700
+ "space name label": "Space name",
1701
+ "object name label": "Object name",
1702
+ "close space label": "Close space",
1703
+ "open space label": "Open space",
1704
+ "export data label": "Export data",
1705
+ "import data label": "Import data",
1706
+ "migrate space label": "Migrate space",
1707
+ "share space": "Share space",
1708
+ "save space to disk label": "Save to disk",
1709
+ "load space from disk label": "Load from disk",
1710
+ "confirm restore title": "Overwrite files in this space?",
1711
+ "confirm restore body": "Restoring from a backup will overwrite the contents of any documents that match.",
1712
+ "upload file message": "Drag file here or click to browse",
1713
+ "object title placeholder": "Type a title here\u2026",
1714
+ "personal space label": "Personal Space",
1715
+ "spaces label": "Spaces",
1716
+ "show hidden spaces label": "Show closed spaces",
1717
+ "save files to directory label": "Save files to disk",
1718
+ "select path label": "Select path",
1719
+ "rename collection label": "Rename collection",
1720
+ "rename object label": "Rename item",
1721
+ "duplicate object label": "Duplicate item",
1722
+ "delete collection label": "Delete collection",
1723
+ "delete object label": "Delete item",
1724
+ "collection deleted label": "Collection deleted",
1725
+ "object deleted label": "Item deleted",
1726
+ "go to object label": "Open item",
1727
+ "found object label": "Ready.",
1728
+ "found object description": "The requested object is now available.",
1729
+ "waiting for object label": "Loading\u2026",
1730
+ "waiting for object description": "The requested object is still being synchronized.",
1731
+ "object not found label": "Nothing found.",
1732
+ "object not found description": "The requested object has not been found yet. Ensure there are enough peers online in the space with an updated copy.",
1733
+ "missing object message": "Object not available.",
1734
+ "missing object description": "The requested object has not been found yet. Ensure there are enough peers online in the space with an updated copy.",
1735
+ "create collection label": "Create collection",
1736
+ "unnamed object label": "New object",
1737
+ "unnamed collection label": "New collection",
1738
+ "create object in space label": "Add to space",
1739
+ "create object in collection label": "Add to collection",
1740
+ "share space label": "Share",
1741
+ "space members label": "Space members",
1742
+ "active space members heading": "Online ({{count}})",
1743
+ "inactive space members heading": "Offline ({{count}})",
1744
+ "presence label_zero": "No other viewers",
1745
+ "presence label_one": "1 other viewer",
1746
+ "presence label_other": "{{count}} other viewers",
1747
+ "persisted locally label": "Changes saved locally.",
1748
+ "persisted locally message": "All changes have been saved to disk on this device.",
1749
+ "persistence pending label": "Saving\u2026",
1750
+ "persistence error label": "Error saving changes.",
1751
+ "more actions label": "More actions",
1752
+ "invitations heading": "Invitations",
1753
+ "keyshortcuts label": "Keyboard shortcuts",
1754
+ "menu footer label": "Details",
1755
+ "location label": "Located in",
1756
+ "space limit label": "Space Limit Reached",
1757
+ "space limit description": "This space has reached the maximum number of objects for the beta. This limit includes deleted objects currently, but those can be permanently removed with the cleanup action.",
1758
+ "space limit close label": "Close",
1759
+ "remove deleted objects label": "Cleanup",
1760
+ "remove deleted objects alt": "Permanently remove deleted objects to free up space.",
1761
+ "copy link label": "Copy link",
1762
+ "default on space create label": "On space create",
1763
+ "sync status title": "Sync status",
1764
+ "dismiss label": "Dismiss",
1765
+ "join success label": "Successfully joined space",
1766
+ "name label": "Name",
1767
+ "name placeholder": "Name"
1768
+ }
1769
+ }
1770
+ }
1771
+ ];
1772
+
1773
+ // packages/plugins/plugin-space/src/SpacePlugin.tsx
1774
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/SpacePlugin.tsx";
1775
+ var ACTIVE_NODE_BROADCAST_INTERVAL = 3e4;
1776
+ var OBJECT_ID_LENGTH = 60;
1777
+ var SPACE_MAX_OBJECTS = 500;
1778
+ var DIRECTORY_TYPE = "text/directory";
1779
+ var parseSpacePlugin = (plugin) => Array.isArray(plugin?.provides.space?.enabled) ? plugin : void 0;
1780
+ var SpacePlugin = ({ firstRun, onFirstRun } = {}) => {
1781
+ const settings = new LocalStorageStore(SPACE_PLUGIN, {
1782
+ onSpaceCreate: "dxos.org/plugin/markdown/action/create"
1783
+ });
1784
+ const state = new LocalStorageStore(SPACE_PLUGIN, {
1785
+ awaiting: void 0,
1786
+ spaceNames: {},
1787
+ viewersByObject: {},
1788
+ viewersByIdentity: new ComplexMap2(PublicKey2.hash),
1789
+ sdkMigrationRunning: {}
1790
+ });
1791
+ const subscriptions = new EventSubscriptions();
1792
+ const spaceSubscriptions = new EventSubscriptions();
1793
+ const graphSubscriptions = /* @__PURE__ */ new Map();
1794
+ let clientPlugin;
1795
+ let intentPlugin;
1796
+ let navigationPlugin;
1797
+ let attentionPlugin;
1798
+ const onSpaceReady = async () => {
1799
+ if (!clientPlugin || !navigationPlugin || !attentionPlugin) {
1800
+ return;
1801
+ }
1802
+ const client = clientPlugin.provides.client;
1803
+ const location = navigationPlugin.provides.location;
1804
+ const attention = attentionPlugin.provides.attention;
1805
+ const defaultSpace = client.spaces.default;
1806
+ if (typeof defaultSpace.properties[COMPOSER_SPACE_LOCK] !== "boolean") {
1807
+ defaultSpace.properties[COMPOSER_SPACE_LOCK] = true;
1808
+ }
1809
+ const { objects: [spacesOrder] } = await defaultSpace.db.query(Filter.schema(Expando, {
1810
+ key: SHARED
1811
+ })).run();
1812
+ if (!spacesOrder) {
1813
+ defaultSpace.db.add(create2({
1814
+ key: SHARED,
1815
+ order: []
1816
+ }));
1817
+ }
1818
+ subscriptions.add(client.spaces.subscribe(async (spaces) => {
1819
+ if (defaultSpace.state.get() === SpaceState3.SPACE_REQUIRES_MIGRATION) {
1820
+ await defaultSpace.internal.migrate();
1821
+ }
1822
+ spaces.filter((space) => space.state.get() === SpaceState3.SPACE_READY).forEach((space) => {
1823
+ subscriptions.add(scheduledEffect(() => ({
1824
+ name: space.properties.name
1825
+ }), ({ name }) => state.values.spaceNames[space.id] = name));
1826
+ });
1827
+ }).unsubscribe);
1828
+ subscriptions.add(scheduledEffect(() => ({
1829
+ ids: openIds(location.active),
1830
+ removed: location.closed ? [
1831
+ location.closed
1832
+ ].flat() : []
1833
+ }), ({ ids, removed }) => {
1834
+ const send = () => {
1835
+ const spaces = client.spaces.get();
1836
+ const identity = client.halo.identity.get();
1837
+ if (identity && location.active) {
1838
+ const idsBySpace = reduceGroupBy(ids, (id) => {
1839
+ const [spaceId] = id.split(":");
1840
+ return spaceId;
1841
+ });
1842
+ for (const space of spaces) {
1843
+ if (!idsBySpace.has(space.id)) {
1844
+ idsBySpace.set(space.id, []);
1845
+ }
1846
+ }
1847
+ for (const [spaceId, ids2] of idsBySpace) {
1848
+ const space = spaces.find((space2) => space2.id === spaceId);
1849
+ if (!space) {
1850
+ continue;
1851
+ }
1852
+ void space.postMessage("viewing", {
1853
+ identityKey: identity.identityKey.toHex(),
1854
+ attended: attention.attended ? [
1855
+ ...attention.attended
1856
+ ] : [],
1857
+ added: ids2,
1858
+ // TODO(Zan): When we re-open a part, we should remove it from the removed list in the navigation plugin.
1859
+ removed: removed.filter((id) => !ids2.includes(id))
1860
+ }).catch((err) => {
1861
+ log2.warn("Failed to broadcast active node for presence.", {
1862
+ err: err.message
1863
+ }, {
1864
+ F: __dxlog_file5,
1865
+ L: 229,
1866
+ S: void 0,
1867
+ C: (f, a) => f(...a)
1868
+ });
1869
+ });
1870
+ }
1871
+ }
1872
+ };
1873
+ send();
1874
+ const interval = setInterval(() => send(), ACTIVE_NODE_BROADCAST_INTERVAL);
1875
+ return () => clearInterval(interval);
1876
+ }));
1877
+ subscriptions.add(client.spaces.subscribe((spaces) => {
1878
+ spaceSubscriptions.clear();
1879
+ spaces.forEach((space) => {
1880
+ spaceSubscriptions.add(space.listen("viewing", (message) => {
1881
+ const { added, removed, attended } = message.payload;
1882
+ const identityKey = PublicKey2.safeFrom(message.payload.identityKey);
1883
+ if (identityKey && Array.isArray(added) && Array.isArray(removed)) {
1884
+ added.forEach((id) => {
1885
+ if (typeof id === "string") {
1886
+ if (!(id in state.values.viewersByObject)) {
1887
+ state.values.viewersByObject[id] = new ComplexMap2(PublicKey2.hash);
1888
+ }
1889
+ state.values.viewersByObject[id].set(identityKey, {
1890
+ lastSeen: Date.now(),
1891
+ currentlyAttended: new Set(attended).has(id)
1892
+ });
1893
+ if (!state.values.viewersByIdentity.has(identityKey)) {
1894
+ state.values.viewersByIdentity.set(identityKey, /* @__PURE__ */ new Set());
1895
+ }
1896
+ state.values.viewersByIdentity.get(identityKey).add(id);
1897
+ }
1898
+ });
1899
+ removed.forEach((id) => {
1900
+ if (typeof id === "string") {
1901
+ state.values.viewersByObject[id]?.delete(identityKey);
1902
+ state.values.viewersByIdentity.get(identityKey)?.delete(id);
1903
+ }
1904
+ });
1905
+ }
1906
+ }));
1907
+ });
1908
+ }).unsubscribe);
1909
+ };
1910
+ return {
1911
+ meta: meta_default,
1912
+ ready: async (plugins) => {
1913
+ settings.prop({
1914
+ key: "showHidden",
1915
+ storageKey: "show-hidden",
1916
+ type: LocalStorageStore.bool({
1917
+ allowUndefined: true
1918
+ })
1919
+ });
1920
+ state.prop({
1921
+ key: "spaceNames",
1922
+ storageKey: "space-names",
1923
+ type: LocalStorageStore.json()
1924
+ });
1925
+ navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin2);
1926
+ attentionPlugin = resolvePlugin(plugins, parseAttentionPlugin);
1927
+ clientPlugin = resolvePlugin(plugins, parseClientPlugin);
1928
+ intentPlugin = resolvePlugin(plugins, parseIntentPlugin3);
1929
+ if (!clientPlugin || !intentPlugin) {
1930
+ return;
1931
+ }
1932
+ const client = clientPlugin.provides.client;
1933
+ const dispatch = intentPlugin.provides.intent.dispatch;
1934
+ const handleFirstRun = async () => {
1935
+ const defaultSpace = client.spaces.default;
1936
+ defaultSpace.properties[CollectionType.typename] = create2(CollectionType, {
1937
+ objects: [],
1938
+ views: {}
1939
+ });
1940
+ if (Migrations2.versionProperty) {
1941
+ defaultSpace.properties[Migrations2.versionProperty] = Migrations2.targetVersion;
1942
+ }
1943
+ await onFirstRun?.({
1944
+ client,
1945
+ dispatch
1946
+ });
1947
+ };
1948
+ client.spaces.isReady.subscribe(async (ready) => {
1949
+ if (ready) {
1950
+ await clientPlugin?.provides.client.spaces.default.waitUntilReady();
1951
+ if (firstRun) {
1952
+ void firstRun?.wait().then(handleFirstRun);
1953
+ } else {
1954
+ await handleFirstRun();
1955
+ }
1956
+ await onSpaceReady();
1957
+ }
1958
+ });
1959
+ },
1960
+ unload: async () => {
1961
+ settings.close();
1962
+ spaceSubscriptions.clear();
1963
+ subscriptions.clear();
1964
+ graphSubscriptions.forEach((cb) => cb());
1965
+ graphSubscriptions.clear();
1966
+ },
1967
+ provides: {
1968
+ space: state.values,
1969
+ settings: settings.values,
1970
+ translations: [
1971
+ ...translations_default,
1972
+ osTranslations
1973
+ ],
1974
+ root: () => state.values.awaiting ? /* @__PURE__ */ React17.createElement(AwaitingObject, {
1975
+ id: state.values.awaiting
1976
+ }) : null,
1977
+ metadata: {
1978
+ records: {
1979
+ [CollectionType.typename]: {
1980
+ placeholder: [
1981
+ "unnamed collection label",
1982
+ {
1983
+ ns: SPACE_PLUGIN
1984
+ }
1985
+ ],
1986
+ icon: "ph--cards-three--regular",
1987
+ // TODO(wittjosiah): Move out of metadata.
1988
+ loadReferences: (collection) => loadObjectReferences(collection, (collection2) => [
1989
+ ...collection2.objects,
1990
+ ...Object.values(collection2.views)
1991
+ ])
1992
+ }
1993
+ }
1994
+ },
1995
+ echo: {
1996
+ schema: [
1997
+ CollectionType
1998
+ ]
1999
+ },
2000
+ surface: {
2001
+ component: ({ data, role, ...rest }) => {
2002
+ const primary = data.active ?? data.object;
2003
+ switch (role) {
2004
+ case "article":
2005
+ case "main":
2006
+ return isSpace2(primary) && primary.state.get() === SpaceState3.SPACE_READY ? /* @__PURE__ */ React17.createElement(Surface2, {
2007
+ data: {
2008
+ active: primary.properties[CollectionType.typename],
2009
+ id: primary.id
2010
+ },
2011
+ role,
2012
+ ...rest
2013
+ }) : primary instanceof CollectionType ? {
2014
+ node: /* @__PURE__ */ React17.createElement(CollectionMain, {
2015
+ collection: primary
2016
+ }),
2017
+ disposition: "fallback"
2018
+ } : typeof primary === "string" && primary.length === OBJECT_ID_LENGTH ? /* @__PURE__ */ React17.createElement(MissingObject, {
2019
+ id: primary
2020
+ }) : null;
2021
+ case "complementary--settings":
2022
+ return isEchoObject2(data.subject) ? /* @__PURE__ */ React17.createElement(DefaultObjectSettings, {
2023
+ object: data.subject
2024
+ }) : null;
2025
+ case "dialog":
2026
+ if (data.component === "dxos.org/plugin/space/InvitationManagerDialog") {
2027
+ return /* @__PURE__ */ React17.createElement(Dialog.Content, null, /* @__PURE__ */ React17.createElement(ClipboardProvider2, null, /* @__PURE__ */ React17.createElement(InvitationManager, {
2028
+ active: true,
2029
+ ...data.subject
2030
+ })));
2031
+ } else {
2032
+ return null;
2033
+ }
2034
+ case "popover":
2035
+ if (data.component === "dxos.org/plugin/space/RenameSpacePopover" && isSpace2(data.subject)) {
2036
+ return /* @__PURE__ */ React17.createElement(PopoverRenameSpace, {
2037
+ space: data.subject
2038
+ });
2039
+ }
2040
+ if (data.component === "dxos.org/plugin/space/RenameObjectPopover" && isReactiveObject2(data.subject)) {
2041
+ return /* @__PURE__ */ React17.createElement(PopoverRenameObject, {
2042
+ object: data.subject
2043
+ });
2044
+ }
2045
+ return null;
2046
+ // TODO(burdon): Add role name syntax to minimal plugin docs.
2047
+ case "presence--glyph": {
2048
+ return isReactiveObject2(data.object) ? /* @__PURE__ */ React17.createElement(SmallPresenceLive, {
2049
+ viewers: state.values.viewersByObject[fullyQualifiedId4(data.object)]
2050
+ }) : /* @__PURE__ */ React17.createElement(SmallPresence, {
2051
+ count: 0
2052
+ });
2053
+ }
2054
+ case "navbar-start": {
2055
+ return null;
2056
+ }
2057
+ case "navbar-end": {
2058
+ if (!isEchoObject2(data.object) && !isSpace2(data.object)) {
2059
+ return null;
2060
+ }
2061
+ const space = isSpace2(data.object) ? data.object : getSpace4(data.object);
2062
+ const object = isSpace2(data.object) ? data.object.state.get() === SpaceState3.SPACE_READY ? space?.properties[CollectionType.typename] : void 0 : data.object;
2063
+ return space && object ? {
2064
+ node: /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(SpacePresence, {
2065
+ object
2066
+ }), space.properties[COMPOSER_SPACE_LOCK] ? null : /* @__PURE__ */ React17.createElement(ShareSpaceButton, {
2067
+ spaceId: space.id
2068
+ })),
2069
+ disposition: "hoist"
2070
+ } : null;
2071
+ }
2072
+ case "section":
2073
+ return data.object instanceof CollectionType ? /* @__PURE__ */ React17.createElement(CollectionSection, {
2074
+ collection: data.object
2075
+ }) : null;
2076
+ case "settings":
2077
+ return data.plugin === meta_default.id ? /* @__PURE__ */ React17.createElement(SpaceSettings, {
2078
+ settings: settings.values
2079
+ }) : null;
2080
+ case "menu-footer":
2081
+ if (!isEchoObject2(data.object)) {
2082
+ return null;
2083
+ } else {
2084
+ return /* @__PURE__ */ React17.createElement(MenuFooter, {
2085
+ object: data.object
2086
+ });
2087
+ }
2088
+ case "status": {
2089
+ return /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(SyncStatus, null), /* @__PURE__ */ React17.createElement(SaveStatus, null));
2090
+ }
2091
+ default:
2092
+ return null;
2093
+ }
2094
+ }
2095
+ },
2096
+ graph: {
2097
+ builder: (plugins) => {
2098
+ const clientPlugin2 = resolvePlugin(plugins, parseClientPlugin);
2099
+ const metadataPlugin = resolvePlugin(plugins, parseMetadataResolverPlugin);
2100
+ const graphPlugin = resolvePlugin(plugins, parseGraphPlugin);
2101
+ const client = clientPlugin2?.provides.client;
2102
+ const dispatch = intentPlugin?.provides.intent.dispatch;
2103
+ const resolve = metadataPlugin?.provides.metadata.resolver;
2104
+ const graph = graphPlugin?.provides.graph;
2105
+ if (!graph || !dispatch || !resolve || !client) {
2106
+ return [];
2107
+ }
2108
+ return [
2109
+ // Create spaces group node.
2110
+ createExtension({
2111
+ id: `${SPACE_PLUGIN}/root`,
2112
+ filter: (node) => node.id === "root",
2113
+ connector: () => {
2114
+ const isReady = toSignal((onChange) => {
2115
+ let defaultSpaceUnsubscribe;
2116
+ client.spaces.isReady.subscribe((ready) => {
2117
+ if (ready) {
2118
+ defaultSpaceUnsubscribe = client.spaces.default.state.subscribe(() => onChange()).unsubscribe;
2119
+ }
2120
+ });
2121
+ return () => defaultSpaceUnsubscribe?.();
2122
+ }, () => client.spaces.isReady.get() && client.spaces.default.state.get() === SpaceState3.SPACE_READY);
2123
+ if (!isReady) {
2124
+ return [];
2125
+ }
2126
+ return [
2127
+ {
2128
+ id: SPACES,
2129
+ type: SPACES,
2130
+ properties: {
2131
+ label: [
2132
+ "spaces label",
2133
+ {
2134
+ ns: SPACE_PLUGIN
2135
+ }
2136
+ ],
2137
+ palette: "teal",
2138
+ testId: "spacePlugin.spaces",
2139
+ role: "branch",
2140
+ childrenPersistenceClass: "echo",
2141
+ onRearrangeChildren: async (nextOrder) => {
2142
+ graph._sortEdges(SPACES, "outbound", nextOrder.map(({ id }) => id));
2143
+ const { objects: [spacesOrder] } = await client.spaces.default.db.query(Filter.schema(Expando, {
2144
+ key: SHARED
2145
+ })).run();
2146
+ if (spacesOrder) {
2147
+ spacesOrder.order = nextOrder.map(({ id }) => id);
2148
+ } else {
2149
+ log2.warn("spaces order object not found", void 0, {
2150
+ F: __dxlog_file5,
2151
+ L: 526,
2152
+ S: void 0,
2153
+ C: (f, a) => f(...a)
2154
+ });
2155
+ }
2156
+ }
2157
+ }
2158
+ }
2159
+ ];
2160
+ }
2161
+ }),
2162
+ // Create space nodes.
2163
+ createExtension({
2164
+ id: SPACES,
2165
+ filter: (node) => node.id === SPACES,
2166
+ actions: () => [
2167
+ {
2168
+ id: SpaceAction.CREATE,
2169
+ data: async () => {
2170
+ await dispatch([
2171
+ {
2172
+ plugin: SPACE_PLUGIN,
2173
+ action: SpaceAction.CREATE
2174
+ },
2175
+ {
2176
+ action: NavigationAction3.OPEN
2177
+ }
2178
+ ]);
2179
+ },
2180
+ properties: {
2181
+ label: [
2182
+ "create space label",
2183
+ {
2184
+ ns: SPACE_PLUGIN
2185
+ }
2186
+ ],
2187
+ icon: "ph--plus--regular",
2188
+ disposition: "toolbar",
2189
+ testId: "spacePlugin.createSpace"
2190
+ }
2191
+ },
2192
+ {
2193
+ id: SpaceAction.JOIN,
2194
+ data: async () => {
2195
+ await dispatch([
2196
+ {
2197
+ plugin: SPACE_PLUGIN,
2198
+ action: SpaceAction.JOIN
2199
+ },
2200
+ {
2201
+ action: NavigationAction3.OPEN
2202
+ }
2203
+ ]);
2204
+ },
2205
+ properties: {
2206
+ label: [
2207
+ "join space label",
2208
+ {
2209
+ ns: SPACE_PLUGIN
2210
+ }
2211
+ ],
2212
+ icon: "ph--sign-in--regular",
2213
+ testId: "spacePlugin.joinSpace"
2214
+ }
2215
+ }
2216
+ ],
2217
+ connector: () => {
2218
+ const spaces = toSignal((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
2219
+ const isReady = toSignal((onChange) => client.spaces.isReady.subscribe(() => onChange()).unsubscribe, () => client.spaces.isReady.get());
2220
+ if (!spaces || !isReady) {
2221
+ return;
2222
+ }
2223
+ const [spacesOrder] = memoizeQuery(client.spaces.default, Filter.schema(Expando, {
2224
+ key: SHARED
2225
+ }));
2226
+ const order = spacesOrder?.order ?? [];
2227
+ const orderMap = new Map(order.map((id, index) => [
2228
+ id,
2229
+ index
2230
+ ]));
2231
+ return [
2232
+ ...spaces.filter((space) => orderMap.has(space.id)).sort((a, b) => orderMap.get(a.id) - orderMap.get(b.id)),
2233
+ ...spaces.filter((space) => !orderMap.has(space.id))
2234
+ ].filter((space) => settings.values.showHidden ? true : space.state.get() !== SpaceState3.SPACE_INACTIVE).map((space) => constructSpaceNode({
2235
+ space,
2236
+ personal: space === client.spaces.default,
2237
+ namesCache: state.values.spaceNames,
2238
+ resolve
2239
+ }));
2240
+ }
2241
+ }),
2242
+ // Find an object by its fully qualified id.
2243
+ createExtension({
2244
+ id: `${SPACE_PLUGIN}/objects`,
2245
+ resolver: ({ id }) => {
2246
+ const [spaceId, objectId] = id.split(":");
2247
+ const space = client.spaces.get().find((space2) => space2.id === spaceId);
2248
+ if (!space) {
2249
+ return;
2250
+ }
2251
+ const state2 = toSignal((onChange) => space.state.subscribe(() => onChange()).unsubscribe, () => space.state.get(), space.id);
2252
+ if (state2 !== SpaceState3.SPACE_READY) {
2253
+ return;
2254
+ }
2255
+ const store = memoize2(() => signal(space.db.getObjectById(objectId)), id);
2256
+ memoize2(() => {
2257
+ if (!store.value) {
2258
+ void space.db.loadObjectById(objectId).then((o) => store.value = o);
2259
+ }
2260
+ }, id);
2261
+ const object = store.value;
2262
+ if (!object) {
2263
+ return;
2264
+ }
2265
+ return createObjectNode({
2266
+ object,
2267
+ space,
2268
+ resolve
2269
+ });
2270
+ }
2271
+ }),
2272
+ // Create space actions and action groups.
2273
+ createExtension({
2274
+ id: `${SPACE_PLUGIN}/actions`,
2275
+ filter: (node) => isSpace2(node.data),
2276
+ actionGroups: ({ node }) => constructSpaceActionGroups({
2277
+ space: node.data,
2278
+ dispatch
2279
+ }),
2280
+ actions: ({ node }) => {
2281
+ const space = node.data;
2282
+ return constructSpaceActions({
2283
+ space,
2284
+ dispatch,
2285
+ personal: space === client.spaces.default,
2286
+ migrating: state.values.sdkMigrationRunning[space.id]
2287
+ });
2288
+ }
2289
+ }),
2290
+ // Create nodes for objects in the root collection of a space.
2291
+ createExtension({
2292
+ id: `${SPACE_PLUGIN}/root-collection`,
2293
+ filter: (node) => isSpace2(node.data),
2294
+ connector: ({ node }) => {
2295
+ const space = node.data;
2296
+ const state2 = toSignal((onChange) => space.state.subscribe(() => onChange()).unsubscribe, () => space.state.get(), space.id);
2297
+ if (state2 !== SpaceState3.SPACE_READY) {
2298
+ return;
2299
+ }
2300
+ const collection = space.properties[CollectionType.typename];
2301
+ if (!collection) {
2302
+ return;
2303
+ }
2304
+ return collection.objects.filter(nonNullable).map((object) => createObjectNode({
2305
+ object,
2306
+ space,
2307
+ resolve
2308
+ })).filter(nonNullable);
2309
+ }
2310
+ }),
2311
+ // Create collection actions and action groups.
2312
+ createExtension({
2313
+ id: `${SPACE_PLUGIN}/object-actions`,
2314
+ filter: (node) => isEchoObject2(node.data),
2315
+ actionGroups: ({ node }) => constructObjectActionGroups({
2316
+ object: node.data,
2317
+ dispatch
2318
+ }),
2319
+ actions: ({ node }) => constructObjectActions({
2320
+ node,
2321
+ dispatch
2322
+ })
2323
+ }),
2324
+ // Create nodes for objects in collections.
2325
+ createExtension({
2326
+ id: `${SPACE_PLUGIN}/collection-objects`,
2327
+ filter: (node) => node.data instanceof CollectionType,
2328
+ connector: ({ node }) => {
2329
+ const collection = node.data;
2330
+ const space = getSpace4(collection);
2331
+ if (!space) {
2332
+ return;
2333
+ }
2334
+ return collection.objects.filter(nonNullable).map((object) => createObjectNode({
2335
+ object,
2336
+ space,
2337
+ resolve
2338
+ })).filter(nonNullable);
2339
+ }
2340
+ }),
2341
+ // Create nodes for object settings.
2342
+ createExtension({
2343
+ id: `${SPACE_PLUGIN}/settings-for-subject`,
2344
+ resolver: ({ id }) => {
2345
+ if (!id.endsWith("~settings")) {
2346
+ return;
2347
+ }
2348
+ const [subjectId] = id.split("~");
2349
+ const [spaceId, objectId] = parseFullyQualifiedId(subjectId);
2350
+ const space = client.spaces.get().find((space2) => space2.id === spaceId);
2351
+ const object = toSignal((onChange) => {
2352
+ const timeout = setTimeout(async () => {
2353
+ await space?.db.loadObjectById(objectId);
2354
+ onChange();
2355
+ });
2356
+ return () => clearTimeout(timeout);
2357
+ }, () => space?.db.getObjectById(objectId), subjectId);
2358
+ if (!object || !subjectId) {
2359
+ return;
2360
+ }
2361
+ const meta = resolve(getTypename2(object) ?? "");
2362
+ const label = meta.label?.(object) || object.name || meta.placeholder || [
2363
+ "unnamed object settings label",
2364
+ {
2365
+ ns: SPACE_PLUGIN
2366
+ }
2367
+ ];
2368
+ return {
2369
+ id,
2370
+ type: "orphan-settings-for-subject",
2371
+ data: null,
2372
+ properties: {
2373
+ icon: "ph--gear--regular",
2374
+ label,
2375
+ object
2376
+ }
2377
+ };
2378
+ }
2379
+ })
2380
+ ];
2381
+ },
2382
+ serializer: (plugins) => {
2383
+ const dispatch = resolvePlugin(plugins, parseIntentPlugin3)?.provides.intent.dispatch;
2384
+ if (!dispatch) {
2385
+ return [];
2386
+ }
2387
+ return [
2388
+ {
2389
+ inputType: SPACES,
2390
+ outputType: DIRECTORY_TYPE,
2391
+ serialize: (node) => ({
2392
+ name: translations_default[0]["en-US"][SPACE_PLUGIN]["spaces label"],
2393
+ data: translations_default[0]["en-US"][SPACE_PLUGIN]["spaces label"],
2394
+ type: DIRECTORY_TYPE
2395
+ }),
2396
+ deserialize: () => {
2397
+ }
2398
+ },
2399
+ {
2400
+ inputType: SPACE_TYPE,
2401
+ outputType: DIRECTORY_TYPE,
2402
+ serialize: (node) => ({
2403
+ name: node.data.properties.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed space label"],
2404
+ data: node.data.properties.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed space label"],
2405
+ type: DIRECTORY_TYPE
2406
+ }),
2407
+ deserialize: async (data) => {
2408
+ const result = await dispatch({
2409
+ plugin: SPACE_PLUGIN,
2410
+ action: SpaceAction.CREATE,
2411
+ data: {
2412
+ name: data.name
2413
+ }
2414
+ });
2415
+ return result?.data.space;
2416
+ }
2417
+ },
2418
+ {
2419
+ inputType: CollectionType.typename,
2420
+ outputType: DIRECTORY_TYPE,
2421
+ serialize: (node) => ({
2422
+ name: node.data.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed collection label"],
2423
+ data: node.data.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed collection label"],
2424
+ type: DIRECTORY_TYPE
2425
+ }),
2426
+ deserialize: async (data, ancestors) => {
2427
+ const space = ancestors.find(isSpace2);
2428
+ const collection = ancestors.findLast((ancestor) => ancestor instanceof CollectionType) ?? space?.properties[CollectionType.typename];
2429
+ if (!space || !collection) {
2430
+ return;
2431
+ }
2432
+ const result = await dispatch({
2433
+ plugin: SPACE_PLUGIN,
2434
+ action: SpaceAction.ADD_OBJECT,
2435
+ data: {
2436
+ target: collection,
2437
+ object: create2(CollectionType, {
2438
+ name: data.name,
2439
+ objects: [],
2440
+ views: {}
2441
+ })
2442
+ }
2443
+ });
2444
+ return result?.data.object;
2445
+ }
2446
+ }
2447
+ ];
2448
+ }
2449
+ },
2450
+ intent: {
2451
+ resolver: async (intent, plugins) => {
2452
+ const clientPlugin2 = resolvePlugin(plugins, parseClientPlugin);
2453
+ const client = clientPlugin2?.provides.client;
2454
+ switch (intent.action) {
2455
+ case SpaceAction.WAIT_FOR_OBJECT: {
2456
+ state.values.awaiting = intent.data?.id;
2457
+ return {
2458
+ data: true
2459
+ };
2460
+ }
2461
+ case SpaceAction.CREATE: {
2462
+ if (!client) {
2463
+ return;
2464
+ }
2465
+ const space = await client.spaces.create(intent.data);
2466
+ await space.waitUntilReady();
2467
+ const collection = create2(CollectionType, {
2468
+ objects: [],
2469
+ views: {}
2470
+ });
2471
+ space.properties[CollectionType.typename] = collection;
2472
+ if (Migrations2.versionProperty) {
2473
+ space.properties[Migrations2.versionProperty] = Migrations2.targetVersion;
2474
+ }
2475
+ return {
2476
+ data: {
2477
+ space,
2478
+ id: space.id,
2479
+ activeParts: {
2480
+ main: [
2481
+ space.id
2482
+ ]
2483
+ }
2484
+ },
2485
+ intents: [
2486
+ ...settings.values.onSpaceCreate ? [
2487
+ [
2488
+ {
2489
+ action: settings.values.onSpaceCreate,
2490
+ data: {
2491
+ space
2492
+ }
2493
+ },
2494
+ {
2495
+ action: SpaceAction.ADD_OBJECT,
2496
+ data: {
2497
+ target: space
2498
+ }
2499
+ },
2500
+ {
2501
+ action: NavigationAction3.EXPOSE
2502
+ }
2503
+ ]
2504
+ ] : [],
2505
+ [
2506
+ {
2507
+ action: ObservabilityAction.SEND_EVENT,
2508
+ data: {
2509
+ name: "space.create",
2510
+ properties: {
2511
+ spaceId: space.id
2512
+ }
2513
+ }
2514
+ }
2515
+ ]
2516
+ ]
2517
+ };
2518
+ }
2519
+ case SpaceAction.JOIN: {
2520
+ if (client) {
2521
+ const { space } = await client.shell.joinSpace({
2522
+ invitationCode: intent.data?.invitationCode
2523
+ });
2524
+ if (space) {
2525
+ return {
2526
+ data: {
2527
+ space,
2528
+ id: space.id,
2529
+ activeParts: {
2530
+ main: [
2531
+ space.id
2532
+ ]
2533
+ }
2534
+ },
2535
+ intents: [
2536
+ [
2537
+ {
2538
+ action: LayoutAction2.SET_LAYOUT,
2539
+ data: {
2540
+ element: "toast",
2541
+ subject: {
2542
+ id: `${SPACE_PLUGIN}/join-success`,
2543
+ duration: 1e4,
2544
+ title: translations_default[0]["en-US"][SPACE_PLUGIN]["join success label"],
2545
+ closeLabel: translations_default[0]["en-US"][SPACE_PLUGIN]["dismiss label"]
2546
+ }
2547
+ }
2548
+ }
2549
+ ],
2550
+ [
2551
+ {
2552
+ action: ObservabilityAction.SEND_EVENT,
2553
+ data: {
2554
+ name: "space.join",
2555
+ properties: {
2556
+ spaceId: space.id
2557
+ }
2558
+ }
2559
+ }
2560
+ ]
2561
+ ]
2562
+ };
2563
+ }
2564
+ }
2565
+ break;
2566
+ }
2567
+ case SpaceAction.SHARE: {
2568
+ const spaceId = intent.data?.spaceId;
2569
+ if (clientPlugin2 && typeof spaceId === "string") {
2570
+ if (!navigationPlugin?.provides.location.active) {
2571
+ return;
2572
+ }
2573
+ const target = firstIdInPart(navigationPlugin?.provides.location.active, "main");
2574
+ const result = await clientPlugin2.provides.client.shell.shareSpace({
2575
+ spaceId,
2576
+ target
2577
+ });
2578
+ return {
2579
+ data: result,
2580
+ intents: [
2581
+ [
2582
+ {
2583
+ action: ObservabilityAction.SEND_EVENT,
2584
+ data: {
2585
+ name: "space.share",
2586
+ properties: {
2587
+ spaceId,
2588
+ members: result.members?.length,
2589
+ error: result.error?.message,
2590
+ cancelled: result.cancelled
2591
+ }
2592
+ }
2593
+ }
2594
+ ]
2595
+ ]
2596
+ };
2597
+ }
2598
+ break;
2599
+ }
2600
+ case SpaceAction.LOCK: {
2601
+ const space = intent.data?.space;
2602
+ if (isSpace2(space)) {
2603
+ space.properties[COMPOSER_SPACE_LOCK] = true;
2604
+ return {
2605
+ data: true,
2606
+ intents: [
2607
+ [
2608
+ {
2609
+ action: ObservabilityAction.SEND_EVENT,
2610
+ data: {
2611
+ name: "space.lock",
2612
+ properties: {
2613
+ spaceId: space.id
2614
+ }
2615
+ }
2616
+ }
2617
+ ]
2618
+ ]
2619
+ };
2620
+ }
2621
+ break;
2622
+ }
2623
+ case SpaceAction.UNLOCK: {
2624
+ const space = intent.data?.space;
2625
+ if (isSpace2(space)) {
2626
+ space.properties[COMPOSER_SPACE_LOCK] = false;
2627
+ return {
2628
+ data: true,
2629
+ intents: [
2630
+ [
2631
+ {
2632
+ action: ObservabilityAction.SEND_EVENT,
2633
+ data: {
2634
+ name: "space.unlock",
2635
+ properties: {
2636
+ spaceId: space.id
2637
+ }
2638
+ }
2639
+ }
2640
+ ]
2641
+ ]
2642
+ };
2643
+ }
2644
+ break;
2645
+ }
2646
+ case SpaceAction.RENAME: {
2647
+ const { caller, space } = intent.data ?? {};
2648
+ if (typeof caller === "string" && isSpace2(space)) {
2649
+ return {
2650
+ intents: [
2651
+ [
2652
+ {
2653
+ action: LayoutAction2.SET_LAYOUT,
2654
+ data: {
2655
+ element: "popover",
2656
+ anchorId: `dxos.org/ui/${caller}/${space.id}`,
2657
+ component: "dxos.org/plugin/space/RenameSpacePopover",
2658
+ subject: space
2659
+ }
2660
+ }
2661
+ ]
2662
+ ]
2663
+ };
2664
+ }
2665
+ break;
2666
+ }
2667
+ case SpaceAction.OPEN: {
2668
+ const space = intent.data?.space;
2669
+ if (isSpace2(space)) {
2670
+ await space.open();
2671
+ return {
2672
+ data: true
2673
+ };
2674
+ }
2675
+ break;
2676
+ }
2677
+ case SpaceAction.CLOSE: {
2678
+ const space = intent.data?.space;
2679
+ if (isSpace2(space)) {
2680
+ await space.close();
2681
+ return {
2682
+ data: true
2683
+ };
2684
+ }
2685
+ break;
2686
+ }
2687
+ case SpaceAction.MIGRATE: {
2688
+ const space = intent.data?.space;
2689
+ if (isSpace2(space)) {
2690
+ if (space.state.get() === SpaceState3.SPACE_REQUIRES_MIGRATION) {
2691
+ state.values.sdkMigrationRunning[space.id] = true;
2692
+ await space.internal.migrate();
2693
+ state.values.sdkMigrationRunning[space.id] = false;
2694
+ }
2695
+ const result = await Migrations2.migrate(space, intent.data?.version);
2696
+ return {
2697
+ data: result,
2698
+ intents: [
2699
+ [
2700
+ {
2701
+ action: ObservabilityAction.SEND_EVENT,
2702
+ data: {
2703
+ name: "space.migrate",
2704
+ properties: {
2705
+ spaceId: space.id,
2706
+ version: intent.data?.version
2707
+ }
2708
+ }
2709
+ }
2710
+ ]
2711
+ ]
2712
+ };
2713
+ }
2714
+ break;
2715
+ }
2716
+ case SpaceAction.ADD_OBJECT: {
2717
+ const object = intent.data?.object ?? intent.data?.result;
2718
+ if (!isReactiveObject2(object)) {
2719
+ return;
2720
+ }
2721
+ const space = isSpace2(intent.data?.target) ? intent.data?.target : getSpace4(intent.data?.target);
2722
+ if (!space) {
2723
+ return;
2724
+ }
2725
+ if (space.db.coreDatabase.getAllObjectIds().length >= SPACE_MAX_OBJECTS) {
2726
+ return {
2727
+ data: false,
2728
+ intents: [
2729
+ [
2730
+ {
2731
+ action: LayoutAction2.SET_LAYOUT,
2732
+ data: {
2733
+ element: "toast",
2734
+ subject: {
2735
+ id: `${SPACE_PLUGIN}/space-limit`,
2736
+ title: translations_default[0]["en-US"][SPACE_PLUGIN]["space limit label"],
2737
+ description: translations_default[0]["en-US"][SPACE_PLUGIN]["space limit description"],
2738
+ duration: 5e3,
2739
+ icon: "ph--warning--regular",
2740
+ actionLabel: translations_default[0]["en-US"][SPACE_PLUGIN]["remove deleted objects label"],
2741
+ actionAlt: translations_default[0]["en-US"][SPACE_PLUGIN]["remove deleted objects alt"],
2742
+ // TODO(wittjosiah): Use OS namespace.
2743
+ closeLabel: translations_default[0]["en-US"][SPACE_PLUGIN]["space limit close label"],
2744
+ onAction: () => space.db.coreDatabase.unlinkDeletedObjects()
2745
+ }
2746
+ }
2747
+ }
2748
+ ],
2749
+ [
2750
+ {
2751
+ action: ObservabilityAction.SEND_EVENT,
2752
+ data: {
2753
+ name: "space.limit",
2754
+ properties: {
2755
+ spaceId: space.id
2756
+ }
2757
+ }
2758
+ }
2759
+ ]
2760
+ ]
2761
+ };
2762
+ }
2763
+ if (intent.data?.target instanceof CollectionType) {
2764
+ intent.data?.target.objects.push(object);
2765
+ } else if (isSpace2(intent.data?.target)) {
2766
+ const collection = space.properties[CollectionType.typename];
2767
+ if (collection instanceof CollectionType) {
2768
+ collection.objects.push(object);
2769
+ } else {
2770
+ const collection2 = create2(CollectionType, {
2771
+ objects: [
2772
+ object
2773
+ ],
2774
+ views: {}
2775
+ });
2776
+ space.properties[CollectionType.typename] = collection2;
2777
+ }
2778
+ }
2779
+ return {
2780
+ data: {
2781
+ id: fullyQualifiedId4(object),
2782
+ object,
2783
+ activeParts: {
2784
+ main: [
2785
+ fullyQualifiedId4(object)
2786
+ ]
2787
+ }
2788
+ },
2789
+ intents: [
2790
+ [
2791
+ {
2792
+ action: ObservabilityAction.SEND_EVENT,
2793
+ data: {
2794
+ name: "space.object.add",
2795
+ properties: {
2796
+ spaceId: space.id,
2797
+ objectId: object.id,
2798
+ typename: getTypename2(object)
2799
+ }
2800
+ }
2801
+ }
2802
+ ]
2803
+ ]
2804
+ };
2805
+ }
2806
+ case SpaceAction.REMOVE_OBJECT: {
2807
+ const object = intent.data?.object ?? intent.data?.result;
2808
+ const space = getSpace4(object);
2809
+ if (!(isEchoObject2(object) && space)) {
2810
+ return;
2811
+ }
2812
+ const resolve = resolvePlugin(plugins, parseMetadataResolverPlugin)?.provides.metadata.resolver;
2813
+ const activeParts = navigationPlugin?.provides.location.active;
2814
+ const openObjectIds = new Set(openIds(activeParts ?? {}));
2815
+ if (!intent.undo && resolve) {
2816
+ const parentCollection = intent.data?.collection ?? space.properties[CollectionType.typename];
2817
+ const nestedObjects = await getNestedObjects(object, resolve);
2818
+ const deletionData = {
2819
+ object,
2820
+ parentCollection,
2821
+ index: parentCollection instanceof CollectionType ? parentCollection.objects.indexOf(object) : -1,
2822
+ nestedObjects,
2823
+ wasActive: [
2824
+ object,
2825
+ ...nestedObjects
2826
+ ].map((obj) => fullyQualifiedId4(obj)).filter((id) => openObjectIds.has(id))
2827
+ };
2828
+ if (deletionData.wasActive.length > 0) {
2829
+ await intentPlugin?.provides.intent.dispatch({
2830
+ action: NavigationAction3.CLOSE,
2831
+ data: {
2832
+ activeParts: {
2833
+ main: deletionData.wasActive,
2834
+ sidebar: deletionData.wasActive
2835
+ }
2836
+ }
2837
+ });
2838
+ }
2839
+ if (parentCollection instanceof CollectionType) {
2840
+ const index = parentCollection.objects.indexOf(object);
2841
+ if (index !== -1) {
2842
+ parentCollection.objects.splice(index, 1);
2843
+ }
2844
+ }
2845
+ deletionData.nestedObjects.forEach((obj) => {
2846
+ space.db.remove(obj);
2847
+ });
2848
+ space.db.remove(object);
2849
+ const undoMessageKey = object instanceof CollectionType ? "collection deleted label" : "object deleted label";
2850
+ return {
2851
+ data: true,
2852
+ undoable: {
2853
+ // Consider using a translation key here.
2854
+ message: translations_default[0]["en-US"][SPACE_PLUGIN][undoMessageKey],
2855
+ data: deletionData
2856
+ }
2857
+ };
2858
+ } else {
2859
+ const undoData = intent.data;
2860
+ if (undoData && isEchoObject2(undoData.object) && undoData.parentCollection instanceof CollectionType) {
2861
+ const restoredObject = space.db.add(undoData.object);
2862
+ undoData.nestedObjects.forEach((obj) => {
2863
+ space.db.add(obj);
2864
+ });
2865
+ if (undoData.index !== -1) {
2866
+ undoData.parentCollection.objects.splice(undoData.index, 0, restoredObject);
2867
+ }
2868
+ if (undoData.wasActive.length > 0) {
2869
+ await intentPlugin?.provides.intent.dispatch({
2870
+ action: NavigationAction3.OPEN,
2871
+ data: {
2872
+ activeParts: {
2873
+ main: undoData.wasActive
2874
+ }
2875
+ }
2876
+ });
2877
+ }
2878
+ return {
2879
+ data: true
2880
+ };
2881
+ }
2882
+ return {
2883
+ data: false
2884
+ };
2885
+ }
2886
+ }
2887
+ case SpaceAction.RENAME_OBJECT: {
2888
+ const object = intent.data?.object ?? intent.data?.result;
2889
+ const caller = intent.data?.caller;
2890
+ if (isReactiveObject2(object) && caller) {
2891
+ return {
2892
+ intents: [
2893
+ [
2894
+ {
2895
+ action: LayoutAction2.SET_LAYOUT,
2896
+ data: {
2897
+ element: "popover",
2898
+ anchorId: `dxos.org/ui/${caller}/${fullyQualifiedId4(object)}`,
2899
+ component: "dxos.org/plugin/space/RenameObjectPopover",
2900
+ subject: object
2901
+ }
2902
+ }
2903
+ ]
2904
+ ]
2905
+ };
2906
+ }
2907
+ break;
2908
+ }
2909
+ case SpaceAction.DUPLICATE_OBJECT: {
2910
+ const originalObject = intent.data?.object ?? intent.data?.result;
2911
+ const resolve = resolvePlugin(plugins, parseMetadataResolverPlugin)?.provides.metadata.resolver;
2912
+ if (!isEchoObject2(originalObject) || !resolve) {
2913
+ return;
2914
+ }
2915
+ const newObject = await cloneObject(originalObject, resolve);
2916
+ return {
2917
+ intents: [
2918
+ [
2919
+ {
2920
+ action: SpaceAction.ADD_OBJECT,
2921
+ data: {
2922
+ object: newObject,
2923
+ target: intent.data?.target
2924
+ }
2925
+ }
2926
+ ]
2927
+ ]
2928
+ };
2929
+ }
2930
+ case SpaceAction.TOGGLE_HIDDEN: {
2931
+ settings.values.showHidden = intent.data?.state ?? !settings.values.showHidden;
2932
+ return {
2933
+ data: true
2934
+ };
2935
+ }
2936
+ }
2937
+ }
2938
+ }
2939
+ }
2940
+ };
2941
+ };
2942
+
2943
+ // packages/plugins/plugin-space/src/index.ts
2944
+ var src_default = SpacePlugin;
2945
+ export {
2946
+ ActorSchema,
2947
+ AwaitingObject,
2948
+ COMPOSER_SPACE_LOCK,
2949
+ ChannelType,
2950
+ CollectionMain,
2951
+ CollectionSection,
2952
+ CollectionType,
2953
+ ContactType,
2954
+ DefaultObjectSettings,
2955
+ FullPresence,
2956
+ MenuFooter,
2957
+ MessageState,
2958
+ MessageType,
2959
+ MissingObject,
2960
+ PersistenceStatus,
2961
+ PopoverRenameObject,
2962
+ PopoverRenameSpace,
2963
+ SHARED,
2964
+ SPACES,
2965
+ SPACE_DIRECTORY_HANDLE,
2966
+ SPACE_PLUGIN,
2967
+ SPACE_PLUGIN_SHORT_ID,
2968
+ SPACE_TYPE,
2969
+ SaveStatus,
2970
+ ShareSpaceButton,
2971
+ ShareSpaceButtonImpl,
2972
+ SmallPresence,
2973
+ SmallPresenceLive,
2974
+ SpaceAction,
2975
+ SpaceMain,
2976
+ SpacePlugin,
2977
+ SpacePresence,
2978
+ SpaceSettings,
2979
+ SyncStatus,
2980
+ SyncStatusDetail,
2981
+ SyncStatusIndicator,
2982
+ ThreadStatus,
2983
+ ThreadType,
2984
+ cloneObject,
2985
+ constructObjectActionGroups,
2986
+ constructObjectActions,
2987
+ constructSpaceActionGroups,
2988
+ constructSpaceActions,
2989
+ constructSpaceNode,
2990
+ createObjectNode,
2991
+ src_default as default,
2992
+ getActiveSpace,
2993
+ getNestedObjects,
2994
+ getSpaceDisplayName,
2995
+ memoizeQuery,
2996
+ parseSpaceInitPlugin,
2997
+ parseSpacePlugin,
2998
+ translations_default as translations
2999
+ };
3000
+ //# sourceMappingURL=index.mjs.map