@dxos/plugin-space 0.6.11 → 0.6.12-main.15a606f

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