@dxos/plugin-space 0.6.13 → 0.6.14-main.69511f5

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