@dxos/plugin-space 0.6.12 → 0.6.13-main.548ca8d

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