@dxos/plugin-space 0.6.13 → 0.6.14-main.1366248

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 (108) 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-WZAM3FNP.mjs} +24 -5
  4. package/dist/lib/browser/chunk-WZAM3FNP.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +852 -348
  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-HTAM5LQD.cjs} +30 -9
  11. package/dist/lib/node/chunk-HTAM5LQD.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 +1046 -550
  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-TRJKV4PK.mjs +116 -0
  22. package/dist/lib/node-esm/chunk-TRJKV4PK.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 +3145 -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/ShareSpaceButton.stories.d.ts +3 -91
  38. package/dist/types/src/components/ShareSpaceButton.stories.d.ts.map +1 -1
  39. package/dist/types/src/components/SpaceMain/SpaceMain.d.ts.map +1 -1
  40. package/dist/types/src/components/SpacePresence.d.ts +4 -2
  41. package/dist/types/src/components/SpacePresence.d.ts.map +1 -1
  42. package/dist/types/src/components/SpacePresence.stories.d.ts +4 -92
  43. package/dist/types/src/components/SpacePresence.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/SpaceSettings.d.ts.map +1 -1
  45. package/dist/types/src/components/SpaceSettingsPanel.d.ts +7 -0
  46. package/dist/types/src/components/SpaceSettingsPanel.d.ts.map +1 -0
  47. package/dist/types/src/components/SyncStatus/Space.d.ts +8 -0
  48. package/dist/types/src/components/SyncStatus/Space.d.ts.map +1 -0
  49. package/dist/types/src/components/SyncStatus/SyncStatus.d.ts +14 -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 +9 -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/save-tracker.d.ts +3 -0
  56. package/dist/types/src/components/SyncStatus/save-tracker.d.ts.map +1 -0
  57. package/dist/types/src/components/SyncStatus/status.d.ts +9 -0
  58. package/dist/types/src/components/SyncStatus/status.d.ts.map +1 -0
  59. package/dist/types/src/components/SyncStatus/sync-state.d.ts +14 -0
  60. package/dist/types/src/components/SyncStatus/sync-state.d.ts.map +1 -0
  61. package/dist/types/src/components/index.d.ts +3 -3
  62. package/dist/types/src/components/index.d.ts.map +1 -1
  63. package/dist/types/src/meta.d.ts.map +1 -1
  64. package/dist/types/src/translations.d.ts +14 -0
  65. package/dist/types/src/translations.d.ts.map +1 -1
  66. package/dist/types/src/types/thread.d.ts +15 -1
  67. package/dist/types/src/types/thread.d.ts.map +1 -1
  68. package/dist/types/src/types/types.d.ts +23 -2
  69. package/dist/types/src/types/types.d.ts.map +1 -1
  70. package/dist/types/src/util.d.ts +4 -7
  71. package/dist/types/src/util.d.ts.map +1 -1
  72. package/package.json +46 -45
  73. package/src/SpacePlugin.tsx +275 -137
  74. package/src/components/DefaultObjectSettings.tsx +33 -0
  75. package/src/components/MenuFooter.tsx +2 -2
  76. package/src/components/ShareSpaceButton.stories.tsx +11 -7
  77. package/src/components/SpaceMain/SpaceMain.tsx +1 -22
  78. package/src/components/SpacePresence.stories.tsx +11 -9
  79. package/src/components/SpacePresence.tsx +34 -23
  80. package/src/components/SpaceSettings.tsx +35 -6
  81. package/src/components/SpaceSettingsPanel.tsx +69 -0
  82. package/src/components/SyncStatus/Space.tsx +109 -0
  83. package/src/components/SyncStatus/SyncStatus.stories.tsx +74 -0
  84. package/src/components/SyncStatus/SyncStatus.tsx +102 -0
  85. package/src/components/SyncStatus/index.ts +5 -0
  86. package/src/components/SyncStatus/save-tracker.ts +71 -0
  87. package/src/components/SyncStatus/status.ts +44 -0
  88. package/src/components/SyncStatus/sync-state.ts +77 -0
  89. package/src/components/index.ts +3 -3
  90. package/src/meta.ts +3 -1
  91. package/src/translations.ts +16 -2
  92. package/src/types/collection.ts +1 -1
  93. package/src/types/thread.ts +12 -2
  94. package/src/types/types.ts +31 -3
  95. package/src/util.tsx +23 -58
  96. package/dist/lib/browser/chunk-DTVUOG2C.mjs.map +0 -7
  97. package/dist/lib/browser/chunk-LZEGRS7H.mjs.map +0 -7
  98. package/dist/lib/node/chunk-6CNYF6YU.cjs.map +0 -7
  99. package/dist/lib/node/chunk-CVZPI2P3.cjs.map +0 -7
  100. package/dist/types/src/components/EmptySpace.d.ts +0 -3
  101. package/dist/types/src/components/EmptySpace.d.ts.map +0 -1
  102. package/dist/types/src/components/EmptyTree.d.ts +0 -3
  103. package/dist/types/src/components/EmptyTree.d.ts.map +0 -1
  104. package/dist/types/src/components/MissingObject.d.ts +0 -5
  105. package/dist/types/src/components/MissingObject.d.ts.map +0 -1
  106. package/src/components/EmptySpace.tsx +0 -25
  107. package/src/components/EmptyTree.tsx +0 -25
  108. package/src/components/MissingObject.tsx +0 -54
@@ -0,0 +1,3145 @@
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-TRJKV4PK.mjs";
20
+
21
+ // packages/plugins/plugin-space/src/SpacePlugin.tsx
22
+ import { signal } from "@preact/signals-core";
23
+ import React17 from "react";
24
+ import { LayoutAction as LayoutAction2, NavigationAction as NavigationAction3, Surface as Surface2, firstIdInPart, openIds, parseGraphPlugin, parseIntentPlugin as parseIntentPlugin2, parseLayoutPlugin, 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, FQ_ID_LENGTH } 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/PersistenceStatus.tsx
763
+ import { ArrowsCounterClockwise, CheckCircle as CheckCircle2, Warning } from "@phosphor-icons/react";
764
+ import React6, { useEffect as useEffect2, useState as useState2 } from "react";
765
+ import { debounce } from "@dxos/async";
766
+ import { Tooltip, useTranslation as useTranslation6 } from "@dxos/react-ui";
767
+ import { getSize as getSize2, mx as mx3, staticPlaceholderText, warningText } from "@dxos/react-ui-theme";
768
+ var Status;
769
+ (function(Status2) {
770
+ Status2[Status2["PERSISTED_LOCALLY"] = 0] = "PERSISTED_LOCALLY";
771
+ Status2[Status2["PENDING"] = 1] = "PENDING";
772
+ Status2[Status2["ERROR"] = 2] = "ERROR";
773
+ })(Status || (Status = {}));
774
+ var PersistenceStatus = ({ db }) => {
775
+ const { t } = useTranslation6(SPACE_PLUGIN);
776
+ const [displayMessage, setDisplayMessage] = useState2(false);
777
+ const [status, naturalSetStatus] = useState2(0);
778
+ const [prevStatus, setPrevStatus] = useState2(0);
779
+ const _setStatus = debounce(naturalSetStatus, 500);
780
+ useEffect2(() => {
781
+ setPrevStatus(status);
782
+ if (prevStatus !== status && status === 0) {
783
+ setDisplayMessage(true);
784
+ const timeout = setTimeout(() => setDisplayMessage(false), 5e3);
785
+ return () => clearTimeout(timeout);
786
+ }
787
+ }, [
788
+ status
789
+ ]);
790
+ switch (status) {
791
+ case 2:
792
+ return /* @__PURE__ */ React6.createElement("div", {
793
+ className: "flex items-center"
794
+ }, /* @__PURE__ */ React6.createElement(Warning, {
795
+ className: mx3(getSize2(4), "me-1")
796
+ }), /* @__PURE__ */ React6.createElement("span", {
797
+ className: mx3("text-sm", warningText)
798
+ }, t("persistence error label")));
799
+ case 1:
800
+ return /* @__PURE__ */ React6.createElement("div", {
801
+ className: "flex items-center"
802
+ }, /* @__PURE__ */ React6.createElement(ArrowsCounterClockwise, {
803
+ className: mx3(getSize2(4), "me-1")
804
+ }), /* @__PURE__ */ React6.createElement("span", {
805
+ className: mx3("text-sm", staticPlaceholderText)
806
+ }, t("persistence pending label")));
807
+ case 0:
808
+ default:
809
+ return /* @__PURE__ */ React6.createElement(Tooltip.Root, {
810
+ delayDuration: 400
811
+ }, /* @__PURE__ */ React6.createElement(Tooltip.Trigger, {
812
+ role: "status",
813
+ className: "flex items-center"
814
+ }, /* @__PURE__ */ React6.createElement(CheckCircle2, {
815
+ className: mx3(getSize2(4), "me-1")
816
+ }), displayMessage && /* @__PURE__ */ React6.createElement("span", {
817
+ className: mx3("text-sm", staticPlaceholderText)
818
+ }, t("persisted locally label"))), /* @__PURE__ */ React6.createElement(Tooltip.Portal, null, /* @__PURE__ */ React6.createElement(Tooltip.Content, {
819
+ classNames: "z-10"
820
+ }, t("persisted locally message"), /* @__PURE__ */ React6.createElement(Tooltip.Arrow, null))));
821
+ }
822
+ };
823
+
824
+ // packages/plugins/plugin-space/src/components/PopoverRenameObject.tsx
825
+ import React7, { useCallback, useRef, useState as useState3 } from "react";
826
+ import { log } from "@dxos/log";
827
+ import { Button as Button2, Input as Input2, Popover, useTranslation as useTranslation7 } from "@dxos/react-ui";
828
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/PopoverRenameObject.tsx";
829
+ var PopoverRenameObject = ({ object: obj }) => {
830
+ const { t } = useTranslation7(SPACE_PLUGIN);
831
+ const doneButton = useRef(null);
832
+ const object = obj;
833
+ const [name, setName] = useState3(object.name || object.title || "");
834
+ const handleDone = useCallback(() => {
835
+ try {
836
+ object.name = name;
837
+ } catch {
838
+ try {
839
+ object.title = name;
840
+ } catch (err) {
841
+ log.error("Failed to rename object", {
842
+ err
843
+ }, {
844
+ F: __dxlog_file2,
845
+ L: 28,
846
+ S: void 0,
847
+ C: (f, a) => f(...a)
848
+ });
849
+ }
850
+ }
851
+ }, [
852
+ object,
853
+ name
854
+ ]);
855
+ return /* @__PURE__ */ React7.createElement("div", {
856
+ role: "none",
857
+ className: "p-1 flex gap-2"
858
+ }, /* @__PURE__ */ React7.createElement("div", {
859
+ role: "none",
860
+ className: "flex-1"
861
+ }, /* @__PURE__ */ React7.createElement(Input2.Root, null, /* @__PURE__ */ React7.createElement(Input2.Label, {
862
+ srOnly: true
863
+ }, t("object name label")), /* @__PURE__ */ React7.createElement(Input2.TextInput, {
864
+ placeholder: t("object title placeholder"),
865
+ value: name,
866
+ "data-testid": "spacePlugin.renameObject.input",
867
+ onChange: ({ target: { value } }) => setName(value),
868
+ onKeyDown: ({ key }) => key === "Enter" && doneButton.current?.click()
869
+ }))), /* @__PURE__ */ React7.createElement(Popover.Close, {
870
+ asChild: true
871
+ }, /* @__PURE__ */ React7.createElement(Button2, {
872
+ ref: doneButton,
873
+ classNames: "self-stretch",
874
+ onClick: handleDone
875
+ }, t("done label", {
876
+ ns: "os"
877
+ }))));
878
+ };
879
+
880
+ // packages/plugins/plugin-space/src/components/PopoverRenameSpace.tsx
881
+ import React8, { useCallback as useCallback2, useRef as useRef2, useState as useState4 } from "react";
882
+ import { Button as Button3, Input as Input3, Popover as Popover2, useTranslation as useTranslation8 } from "@dxos/react-ui";
883
+ var PopoverRenameSpace = ({ space }) => {
884
+ const { t } = useTranslation8(SPACE_PLUGIN);
885
+ const doneButton = useRef2(null);
886
+ const [name, setName] = useState4(space.properties.name ?? "");
887
+ const handleDone = useCallback2(() => {
888
+ space.properties.name = name;
889
+ }, [
890
+ space,
891
+ name
892
+ ]);
893
+ return /* @__PURE__ */ React8.createElement("div", {
894
+ role: "none",
895
+ className: "p-1 flex gap-2"
896
+ }, /* @__PURE__ */ React8.createElement("div", {
897
+ role: "none",
898
+ className: "flex-1"
899
+ }, /* @__PURE__ */ React8.createElement(Input3.Root, null, /* @__PURE__ */ React8.createElement(Input3.Label, {
900
+ srOnly: true
901
+ }, t("space name label")), /* @__PURE__ */ React8.createElement(Input3.TextInput, {
902
+ defaultValue: space.properties.name ?? "",
903
+ placeholder: t("unnamed space label"),
904
+ onChange: ({ target: { value } }) => setName(value),
905
+ // TODO(wittjosiah): Ideally this should access the popover context to close the popover.
906
+ // Currently this is not possible because Radix does not expose the popover context.
907
+ onKeyDown: ({ key }) => key === "Enter" && doneButton.current?.click()
908
+ }))), /* @__PURE__ */ React8.createElement(Popover2.Close, {
909
+ asChild: true
910
+ }, /* @__PURE__ */ React8.createElement(Button3, {
911
+ ref: doneButton,
912
+ classNames: "self-stretch",
913
+ onClick: handleDone
914
+ }, t("done label", {
915
+ ns: "os"
916
+ }))));
917
+ };
918
+
919
+ // packages/plugins/plugin-space/src/components/ShareSpaceButton.tsx
920
+ import React9 from "react";
921
+ import { useIntentDispatcher } from "@dxos/app-framework";
922
+ import { Button as Button4, useTranslation as useTranslation9 } from "@dxos/react-ui";
923
+ var ShareSpaceButton = ({ spaceId }) => {
924
+ const dispatch = useIntentDispatcher();
925
+ return /* @__PURE__ */ React9.createElement(ShareSpaceButtonImpl, {
926
+ onClick: () => dispatch({
927
+ action: SpaceAction.SHARE,
928
+ data: {
929
+ spaceId
930
+ }
931
+ })
932
+ });
933
+ };
934
+ var ShareSpaceButtonImpl = ({ onClick }) => {
935
+ const { t } = useTranslation9(SPACE_PLUGIN);
936
+ return /* @__PURE__ */ React9.createElement(Button4, {
937
+ "data-testid": "spacePlugin.shareSpaceButton",
938
+ onClick,
939
+ classNames: "mli-1"
940
+ }, t("share space label"));
941
+ };
942
+
943
+ // packages/plugins/plugin-space/src/components/SpaceMain/SpaceMain.tsx
944
+ import { Command } from "@phosphor-icons/react";
945
+ import React11 from "react";
946
+ import { Surface } from "@dxos/app-framework";
947
+ import { SpaceState as SpaceState2 } from "@dxos/react-client/echo";
948
+ import { Main, useTranslation as useTranslation11 } from "@dxos/react-ui";
949
+ import { getSize as getSize4, mx as mx5, topbarBlockPaddingStart } from "@dxos/react-ui-theme";
950
+ import { ClipboardProvider } from "@dxos/shell/react";
951
+
952
+ // packages/plugins/plugin-space/src/components/SpaceMain/SpaceMembersSection.tsx
953
+ import { CaretDown, Check, UserPlus, UsersThree } from "@phosphor-icons/react";
954
+ import React10, { useCallback as useCallback3, useState as useState5 } from "react";
955
+ import { LayoutAction, useIntent } from "@dxos/app-framework";
956
+ import { useMembers, SpaceMember, useSpaceInvitations } from "@dxos/react-client/echo";
957
+ import { InvitationEncoder } from "@dxos/react-client/invitations";
958
+ import { Invitation } from "@dxos/react-client/invitations";
959
+ import { Button as Button5, ButtonGroup, DropdownMenu as DropdownMenu2, List, useTranslation as useTranslation10 } from "@dxos/react-ui";
960
+ import { descriptionText as descriptionText2, getSize as getSize3, mx as mx4 } from "@dxos/react-ui-theme";
961
+ import { InvitationListItem, IdentityListItem } from "@dxos/shell/react";
962
+ var activeActionKeyStorageKey = "dxos:react-shell/space-manager/active-action";
963
+ var Presence = SpaceMember.PresenceState;
964
+ var handleCreateInvitationUrl = (invitationCode) => `${origin}?spaceInvitationCode=${invitationCode}`;
965
+ var SpaceMemberList = ({ members }) => {
966
+ return members.length > 0 ? /* @__PURE__ */ React10.createElement(List, {
967
+ classNames: "col-start-2 col-end-5 gap-y-1 grid grid-cols-subgrid items-center"
968
+ }, members.map((member) => /* @__PURE__ */ React10.createElement(IdentityListItem, {
969
+ classNames: "contents",
970
+ key: member.identity.identityKey.toHex(),
971
+ identity: member.identity,
972
+ presence: member.presence
973
+ }))) : null;
974
+ };
975
+ var SpaceMembersSection = ({ space }) => {
976
+ const { t } = useTranslation10(SPACE_PLUGIN);
977
+ const invitations = useSpaceInvitations(space.key);
978
+ const { dispatch } = useIntent();
979
+ const handleCloseDialog = () => dispatch({
980
+ action: LayoutAction.SET_LAYOUT,
981
+ data: {
982
+ element: "dialog",
983
+ state: false
984
+ }
985
+ });
986
+ const handleInvitationSelect = ({ invitation: invitationObservable }) => {
987
+ const invitation = invitationObservable.get();
988
+ void dispatch({
989
+ action: LayoutAction.SET_LAYOUT,
990
+ data: {
991
+ element: "dialog",
992
+ component: "dxos.org/plugin/space/InvitationManagerDialog",
993
+ subject: {
994
+ invitationUrl: handleCreateInvitationUrl(InvitationEncoder.encode(invitation)),
995
+ send: handleCloseDialog,
996
+ status: invitation.state,
997
+ type: invitation.type,
998
+ authCode: invitation.authCode,
999
+ id: invitation.invitationId
1000
+ }
1001
+ }
1002
+ });
1003
+ };
1004
+ const inviteActions = {
1005
+ inviteOne: {
1006
+ label: t("invite one label", {
1007
+ ns: "os"
1008
+ }),
1009
+ description: t("invite one description", {
1010
+ ns: "os"
1011
+ }),
1012
+ icon: UserPlus,
1013
+ onClick: useCallback3(() => {
1014
+ space.share?.({
1015
+ type: Invitation.Type.INTERACTIVE,
1016
+ authMethod: Invitation.AuthMethod.SHARED_SECRET
1017
+ });
1018
+ }, [
1019
+ space
1020
+ ])
1021
+ },
1022
+ inviteMany: {
1023
+ label: t("invite many label", {
1024
+ ns: "os"
1025
+ }),
1026
+ description: t("invite many description", {
1027
+ ns: "os"
1028
+ }),
1029
+ icon: UsersThree,
1030
+ onClick: useCallback3(() => {
1031
+ space.share?.({
1032
+ type: Invitation.Type.INTERACTIVE,
1033
+ authMethod: Invitation.AuthMethod.NONE,
1034
+ multiUse: true
1035
+ });
1036
+ }, [
1037
+ space
1038
+ ])
1039
+ }
1040
+ };
1041
+ const [activeActionKey, setInternalActiveActionKey] = useState5(localStorage.getItem(activeActionKeyStorageKey) ?? "inviteOne");
1042
+ const setActiveActionKey = (nextKey) => {
1043
+ setInternalActiveActionKey(nextKey);
1044
+ localStorage.setItem(activeActionKeyStorageKey, nextKey);
1045
+ };
1046
+ const activeAction = inviteActions[activeActionKey] ?? {};
1047
+ const members = useMembers(space.key).reduce((acc, member) => {
1048
+ acc[member.presence].push(member);
1049
+ return acc;
1050
+ }, {
1051
+ [Presence.ONLINE]: [],
1052
+ [Presence.OFFLINE]: []
1053
+ });
1054
+ return /* @__PURE__ */ React10.createElement("section", {
1055
+ className: "mbe-4 col-span-3 grid gap-y-2 grid-cols-subgrid auto-rows-min"
1056
+ }, /* @__PURE__ */ React10.createElement("h2", {
1057
+ className: "contents"
1058
+ }, /* @__PURE__ */ React10.createElement(UsersThree, {
1059
+ weight: "duotone",
1060
+ className: mx4(getSize3(5), "place-self-center")
1061
+ }), /* @__PURE__ */ React10.createElement("span", {
1062
+ className: "text-lg col-span-2"
1063
+ }, t("space members label"))), /* @__PURE__ */ React10.createElement("h3", {
1064
+ className: "col-start-2 col-span-3 text-sm italic text-description"
1065
+ }, t("invitations heading")), invitations.length > 0 && /* @__PURE__ */ React10.createElement(List, {
1066
+ classNames: "col-start-2 col-span-2 gap-y-2 grid grid-cols-[var(--rail-size)_1fr_var(--rail-action)_var(--rail-action)]"
1067
+ }, invitations.map((invitation) => /* @__PURE__ */ React10.createElement(InvitationListItem, {
1068
+ reverseEffects: true,
1069
+ classNames: "pis-0 pie-0 gap-0 col-span-4 grid grid-cols-subgrid",
1070
+ key: invitation.get().invitationId,
1071
+ invitation,
1072
+ send: handleInvitationSelect,
1073
+ createInvitationUrl: handleCreateInvitationUrl
1074
+ }))), /* @__PURE__ */ React10.createElement(ButtonGroup, {
1075
+ classNames: "col-start-2 col-end-4 grid grid-cols-[1fr_var(--rail-action)] place-self-grow gap-px"
1076
+ }, /* @__PURE__ */ React10.createElement(Button5, {
1077
+ classNames: "gap-2",
1078
+ onClick: activeAction.onClick
1079
+ }, /* @__PURE__ */ React10.createElement(activeAction.icon, {
1080
+ className: getSize3(5)
1081
+ }), /* @__PURE__ */ React10.createElement("span", null, t(activeAction.label, {
1082
+ ns: "os"
1083
+ }))), /* @__PURE__ */ React10.createElement(DropdownMenu2.Root, null, /* @__PURE__ */ React10.createElement(DropdownMenu2.Trigger, {
1084
+ asChild: true
1085
+ }, /* @__PURE__ */ React10.createElement(Button5, {
1086
+ classNames: "pli-0"
1087
+ }, /* @__PURE__ */ React10.createElement(CaretDown, {
1088
+ className: getSize3(4)
1089
+ }))), /* @__PURE__ */ React10.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React10.createElement(DropdownMenu2.Viewport, null, Object.entries(inviteActions).map(([id, action]) => {
1090
+ return /* @__PURE__ */ React10.createElement(DropdownMenu2.CheckboxItem, {
1091
+ key: id,
1092
+ "aria-labelledby": `${id}__label`,
1093
+ "aria-describedby": `${id}__description`,
1094
+ checked: activeActionKey === id,
1095
+ onCheckedChange: (checked) => checked && setActiveActionKey(id),
1096
+ classNames: "gap-2"
1097
+ }, action.icon && /* @__PURE__ */ React10.createElement(action.icon, {
1098
+ className: getSize3(5)
1099
+ }), /* @__PURE__ */ React10.createElement("div", {
1100
+ role: "none",
1101
+ className: "flex-1 min-is-0 space-b-1"
1102
+ }, /* @__PURE__ */ React10.createElement("p", {
1103
+ id: `${id}__label`
1104
+ }, t(action.label, {
1105
+ ns: "os"
1106
+ })), action.description && /* @__PURE__ */ React10.createElement("p", {
1107
+ id: `${id}__description`,
1108
+ className: descriptionText2
1109
+ }, t(action.description, {
1110
+ ns: "os"
1111
+ }))), /* @__PURE__ */ React10.createElement(DropdownMenu2.ItemIndicator, {
1112
+ asChild: true
1113
+ }, /* @__PURE__ */ React10.createElement(Check, {
1114
+ className: getSize3(4)
1115
+ })));
1116
+ })), /* @__PURE__ */ React10.createElement(DropdownMenu2.Arrow, null)))), members[Presence.ONLINE].length + members[Presence.OFFLINE].length < 1 ? /* @__PURE__ */ React10.createElement("p", {
1117
+ className: mx4(descriptionText2, "text-center is-full mlb-2")
1118
+ }, t("empty space members message", {
1119
+ ns: "os"
1120
+ })) : /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement("h3", {
1121
+ className: "col-start-2 col-end-5 text-sm italic text-description"
1122
+ }, t("active space members heading", {
1123
+ count: members[Presence.ONLINE].length
1124
+ })), /* @__PURE__ */ React10.createElement(SpaceMemberList, {
1125
+ members: members[Presence.ONLINE]
1126
+ }), /* @__PURE__ */ React10.createElement("h3", {
1127
+ className: "col-start-2 col-end-5 text-sm italic text-description"
1128
+ }, t("inactive space members heading", {
1129
+ count: members[Presence.OFFLINE].length
1130
+ })), /* @__PURE__ */ React10.createElement(SpaceMemberList, {
1131
+ members: members[Presence.OFFLINE]
1132
+ })));
1133
+ };
1134
+
1135
+ // packages/plugins/plugin-space/src/components/SpaceMain/SpaceMain.tsx
1136
+ var KeyShortcuts = () => {
1137
+ const { t } = useTranslation11(SPACE_PLUGIN);
1138
+ return /* @__PURE__ */ React11.createElement("section", {
1139
+ className: "mbe-4 col-span-4 md:col-start-5 md:col-end-7 grid grid-cols-subgrid gap-y-2 auto-rows-min"
1140
+ }, /* @__PURE__ */ React11.createElement("h2", {
1141
+ className: "contents"
1142
+ }, /* @__PURE__ */ React11.createElement(Command, {
1143
+ weight: "duotone",
1144
+ className: mx5(getSize4(5), "place-self-center")
1145
+ }), /* @__PURE__ */ React11.createElement("span", {
1146
+ className: "text-lg col-span-2 md:col-span-1"
1147
+ }, t("keyshortcuts label"))), /* @__PURE__ */ React11.createElement("div", {
1148
+ role: "none",
1149
+ className: "col-start-2 col-end-4 md:col-end-5 pie-2"
1150
+ }, /* @__PURE__ */ React11.createElement(Surface, {
1151
+ role: "keyshortcuts"
1152
+ })));
1153
+ };
1154
+ 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)]";
1155
+ var SpaceMain = ({ space, role }) => {
1156
+ const state = space.state.get();
1157
+ const ready = state === SpaceState2.SPACE_READY;
1158
+ const Root = role === "main" ? Main.Content : "div";
1159
+ return /* @__PURE__ */ React11.createElement(ClipboardProvider, null, /* @__PURE__ */ React11.createElement(Root, {
1160
+ ...role === "main" ? {
1161
+ classNames: [
1162
+ topbarBlockPaddingStart,
1163
+ "min-bs-dvh",
1164
+ spaceMainLayout
1165
+ ]
1166
+ } : {
1167
+ role: "none",
1168
+ className: mx5(topbarBlockPaddingStart, "row-span-2", spaceMainLayout)
1169
+ },
1170
+ "data-testid": `spacePlugin.${role}`,
1171
+ "data-isready": ready ? "true" : "false"
1172
+ }, ready && /* @__PURE__ */ React11.createElement(SpaceMembersSection, {
1173
+ space
1174
+ }), /* @__PURE__ */ React11.createElement(KeyShortcuts, null)));
1175
+ };
1176
+
1177
+ // packages/plugins/plugin-space/src/components/SpacePresence.tsx
1178
+ import React12, { useCallback as useCallback4, useEffect as useEffect3, useState as useState6 } from "react";
1179
+ import { usePlugin } from "@dxos/app-framework";
1180
+ import { generateName } from "@dxos/display-name";
1181
+ import { PublicKey, useClient as useClient3 } from "@dxos/react-client";
1182
+ import { getSpace as getSpace3, useMembers as useMembers2, fullyQualifiedId as fullyQualifiedId3 } from "@dxos/react-client/echo";
1183
+ import { useIdentity } from "@dxos/react-client/halo";
1184
+ import { Avatar, AvatarGroup, AvatarGroupItem, Tooltip as Tooltip2, useTranslation as useTranslation12, List as List2, ListItem, useDefaultValue } from "@dxos/react-ui";
1185
+ import { AttentionGlyph, useAttention } from "@dxos/react-ui-attention";
1186
+ import { ComplexMap, keyToFallback } from "@dxos/util";
1187
+ var REFRESH_INTERVAL = 5e3;
1188
+ var ACTIVITY_DURATION = 3e4;
1189
+ var noViewers = new ComplexMap(PublicKey.hash);
1190
+ var getName = (identity) => identity.profile?.displayName ?? generateName(identity.identityKey.toHex());
1191
+ var SpacePresence = ({ object, spaceKey }) => {
1192
+ const spacePlugin = usePlugin(SPACE_PLUGIN);
1193
+ const client = useClient3();
1194
+ const identity = useIdentity();
1195
+ const space = spaceKey ? client.spaces.get(spaceKey) : getSpace3(object);
1196
+ const spaceMembers = useMembers2(space?.key);
1197
+ const [_moment, setMoment] = useState6(Date.now());
1198
+ useEffect3(() => {
1199
+ const interval = setInterval(() => setMoment(Date.now()), REFRESH_INTERVAL);
1200
+ return () => clearInterval(interval);
1201
+ }, []);
1202
+ const memberOnline = useCallback4((member) => member.presence === 1, []);
1203
+ const memberIsNotSelf = useCallback4((member) => !identity?.identityKey.equals(member.identity.identityKey), [
1204
+ identity?.identityKey
1205
+ ]);
1206
+ if (!identity || !spacePlugin || !space) {
1207
+ return null;
1208
+ }
1209
+ const spaceState = spacePlugin.provides.space;
1210
+ const currentObjectViewers = spaceState.viewersByObject[fullyQualifiedId3(object)] ?? noViewers;
1211
+ const membersForObject = spaceMembers.filter((member) => memberOnline(member) && memberIsNotSelf(member)).filter((member) => currentObjectViewers.has(member.identity.identityKey)).map((member) => {
1212
+ const objectView = currentObjectViewers.get(member.identity.identityKey);
1213
+ const lastSeen = objectView?.lastSeen ?? -Infinity;
1214
+ const currentlyAttended = objectView?.currentlyAttended ?? false;
1215
+ return {
1216
+ ...member,
1217
+ currentlyAttended,
1218
+ lastSeen
1219
+ };
1220
+ }).toSorted((a, b) => a.lastSeen - b.lastSeen);
1221
+ return /* @__PURE__ */ React12.createElement(FullPresence, {
1222
+ members: membersForObject
1223
+ });
1224
+ };
1225
+ var FullPresence = (props) => {
1226
+ const { size = 9, onMemberClick } = props;
1227
+ const members = useDefaultValue(props.members, () => []);
1228
+ if (members.length === 0) {
1229
+ return null;
1230
+ }
1231
+ return /* @__PURE__ */ React12.createElement(AvatarGroup.Root, {
1232
+ size,
1233
+ classNames: "mbs-2 mie-4",
1234
+ "data-testid": "spacePlugin.presence"
1235
+ }, members.slice(0, 3).map((member, i) => /* @__PURE__ */ React12.createElement(Tooltip2.Root, {
1236
+ key: member.identity.identityKey.toHex()
1237
+ }, /* @__PURE__ */ React12.createElement(Tooltip2.Trigger, null, /* @__PURE__ */ React12.createElement(PrensenceAvatar, {
1238
+ identity: member.identity,
1239
+ group: true,
1240
+ match: member.currentlyAttended,
1241
+ index: members.length - i,
1242
+ onClick: () => onMemberClick?.(member)
1243
+ })), /* @__PURE__ */ React12.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React12.createElement(Tooltip2.Content, {
1244
+ side: "bottom"
1245
+ }, /* @__PURE__ */ React12.createElement("span", null, getName(member.identity)), /* @__PURE__ */ React12.createElement(Tooltip2.Arrow, null))))), members.length > 3 && /* @__PURE__ */ React12.createElement(Tooltip2.Root, null, /* @__PURE__ */ React12.createElement(Tooltip2.Trigger, null, /* @__PURE__ */ React12.createElement(AvatarGroupItem.Root, {
1246
+ status: "inactive"
1247
+ }, /* @__PURE__ */ React12.createElement(Avatar.Frame, {
1248
+ style: {
1249
+ zIndex: members.length - 4
1250
+ }
1251
+ }, /* @__PURE__ */ React12.createElement(Avatar.Fallback, {
1252
+ text: `+${members.length - 3}`
1253
+ })))), /* @__PURE__ */ React12.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React12.createElement(Tooltip2.Content, {
1254
+ side: "bottom"
1255
+ }, /* @__PURE__ */ React12.createElement(Tooltip2.Arrow, null), /* @__PURE__ */ React12.createElement(List2, {
1256
+ classNames: "max-h-56 overflow-y-auto"
1257
+ }, members.map((member) => /* @__PURE__ */ React12.createElement(ListItem.Root, {
1258
+ key: member.identity.identityKey.toHex(),
1259
+ classNames: "flex gap-2 items-center cursor-pointer mbe-2",
1260
+ onClick: () => onMemberClick?.(member),
1261
+ "data-testid": "identity-list-item"
1262
+ }, /* @__PURE__ */ React12.createElement(PrensenceAvatar, {
1263
+ identity: member.identity,
1264
+ showName: true,
1265
+ match: member.currentlyAttended
1266
+ }))))))));
1267
+ };
1268
+ var PrensenceAvatar = ({ identity, showName, match, group, index, onClick }) => {
1269
+ const Root = group ? AvatarGroupItem.Root : Avatar.Root;
1270
+ const status = match ? "current" : "active";
1271
+ const fallbackValue = keyToFallback(identity.identityKey);
1272
+ return /* @__PURE__ */ React12.createElement(Root, {
1273
+ status,
1274
+ hue: identity.profile?.data?.hue || fallbackValue.hue
1275
+ }, /* @__PURE__ */ React12.createElement(Avatar.Frame, {
1276
+ "data-testid": "spacePlugin.presence.member",
1277
+ "data-status": status,
1278
+ ...index ? {
1279
+ style: {
1280
+ zIndex: index
1281
+ }
1282
+ } : {},
1283
+ onClick: () => onClick?.()
1284
+ }, /* @__PURE__ */ React12.createElement(Avatar.Fallback, {
1285
+ text: identity.profile?.data?.emoji || fallbackValue.emoji
1286
+ })), showName && /* @__PURE__ */ React12.createElement(Avatar.Label, {
1287
+ classNames: "text-sm truncate pli-2"
1288
+ }, getName(identity)));
1289
+ };
1290
+ var SmallPresenceLive = ({ id, viewers }) => {
1291
+ const getActiveViewers = (viewers2) => {
1292
+ const moment = Date.now();
1293
+ return Array.from(viewers2.values()).filter(({ lastSeen }) => moment - lastSeen < ACTIVITY_DURATION);
1294
+ };
1295
+ const [activeViewers, setActiveViewers] = useState6(viewers ? getActiveViewers(viewers) : []);
1296
+ useEffect3(() => {
1297
+ if (viewers) {
1298
+ setActiveViewers(getActiveViewers(viewers));
1299
+ const interval = setInterval(() => {
1300
+ setActiveViewers(getActiveViewers(viewers));
1301
+ }, REFRESH_INTERVAL);
1302
+ return () => clearInterval(interval);
1303
+ }
1304
+ }, [
1305
+ viewers
1306
+ ]);
1307
+ return /* @__PURE__ */ React12.createElement(SmallPresence, {
1308
+ id,
1309
+ count: activeViewers.length
1310
+ });
1311
+ };
1312
+ var SmallPresence = ({ id, count }) => {
1313
+ const { t } = useTranslation12(SPACE_PLUGIN);
1314
+ const { hasAttention, isAncestor, isRelated } = useAttention(id);
1315
+ const attention = hasAttention || isAncestor || isRelated;
1316
+ return /* @__PURE__ */ React12.createElement(Tooltip2.Root, null, /* @__PURE__ */ React12.createElement(Tooltip2.Trigger, {
1317
+ asChild: true
1318
+ }, /* @__PURE__ */ React12.createElement("div", {
1319
+ role: "none",
1320
+ className: "flex",
1321
+ "data-attention": attention
1322
+ }, /* @__PURE__ */ React12.createElement(AttentionGlyph, {
1323
+ presence: count > 1 ? "many" : count === 1 ? "one" : "none",
1324
+ classNames: "self-center mie-1"
1325
+ }))), /* @__PURE__ */ React12.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React12.createElement(Tooltip2.Content, {
1326
+ side: "bottom",
1327
+ classNames: "z-[70]"
1328
+ }, /* @__PURE__ */ React12.createElement("span", null, t("presence label", {
1329
+ count
1330
+ })), /* @__PURE__ */ React12.createElement(Tooltip2.Arrow, null))));
1331
+ };
1332
+
1333
+ // packages/plugins/plugin-space/src/components/SpaceSettings.tsx
1334
+ import React13 from "react";
1335
+ import { useIntentDispatcher as useIntentDispatcher2, useResolvePlugins } from "@dxos/app-framework";
1336
+ import { Input as Input4, Select, toLocalizedString as toLocalizedString2, useTranslation as useTranslation13 } from "@dxos/react-ui";
1337
+ import { DeprecatedFormInput } from "@dxos/react-ui-data";
1338
+ var SpaceSettings = ({ settings }) => {
1339
+ const { t } = useTranslation13(SPACE_PLUGIN);
1340
+ const dispatch = useIntentDispatcher2();
1341
+ const plugins = useResolvePlugins(parseSpaceInitPlugin);
1342
+ return /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement(DeprecatedFormInput, {
1343
+ label: t("show hidden spaces label")
1344
+ }, /* @__PURE__ */ React13.createElement(Input4.Switch, {
1345
+ checked: settings.showHidden,
1346
+ onCheckedChange: (checked) => dispatch({
1347
+ plugin: SPACE_PLUGIN,
1348
+ action: SpaceAction.TOGGLE_HIDDEN,
1349
+ data: {
1350
+ state: !!checked
1351
+ }
1352
+ })
1353
+ })), /* @__PURE__ */ React13.createElement(DeprecatedFormInput, {
1354
+ label: t("default on space create label")
1355
+ }, /* @__PURE__ */ React13.createElement(Select.Root, {
1356
+ value: settings.onSpaceCreate,
1357
+ onValueChange: (value) => {
1358
+ settings.onSpaceCreate = value;
1359
+ }
1360
+ }, /* @__PURE__ */ React13.createElement(Select.TriggerButton, null), /* @__PURE__ */ React13.createElement(Select.Portal, null, /* @__PURE__ */ React13.createElement(Select.Content, null, /* @__PURE__ */ React13.createElement(Select.Viewport, null, plugins.map(({ provides: { space: { onSpaceCreate } } }) => /* @__PURE__ */ React13.createElement(Select.Option, {
1361
+ key: onSpaceCreate.action,
1362
+ value: onSpaceCreate.action
1363
+ }, toLocalizedString2(onSpaceCreate.label, t)))))))));
1364
+ };
1365
+
1366
+ // packages/plugins/plugin-space/src/components/SpaceSettingsPanel.tsx
1367
+ import React14, { useCallback as useCallback5, useState as useState7 } from "react";
1368
+ import { log as log2 } from "@dxos/log";
1369
+ import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
1370
+ import { useClient as useClient4 } from "@dxos/react-client";
1371
+ import { DeviceType, useDevices } from "@dxos/react-client/halo";
1372
+ import { Input as Input5, useTranslation as useTranslation14 } from "@dxos/react-ui";
1373
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SpaceSettingsPanel.tsx";
1374
+ var SpaceSettingsPanel = ({ space }) => {
1375
+ const { t } = useTranslation14(SPACE_PLUGIN);
1376
+ const client = useClient4();
1377
+ const devices = useDevices();
1378
+ const managedDeviceAvailable = devices.find((device) => device.profile?.type === DeviceType.AGENT_MANAGED);
1379
+ const edgeAgents = Boolean(client.config.values.runtime?.client?.edgeFeatures?.agents);
1380
+ const edgeReplicationAvailable = edgeAgents && managedDeviceAvailable;
1381
+ const [edgeReplication, setEdgeReplication] = useState7(space.internal.data.edgeReplication === EdgeReplicationSetting.ENABLED);
1382
+ const toggleEdgeReplication = useCallback5(async (next) => {
1383
+ setEdgeReplication(next);
1384
+ await space?.internal.setEdgeReplicationPreference(next ? EdgeReplicationSetting.ENABLED : EdgeReplicationSetting.DISABLED).catch((err) => {
1385
+ log2.catch(err, void 0, {
1386
+ F: __dxlog_file3,
1387
+ L: 38,
1388
+ S: void 0,
1389
+ C: (f, a) => f(...a)
1390
+ });
1391
+ setEdgeReplication(!next);
1392
+ });
1393
+ }, [
1394
+ space
1395
+ ]);
1396
+ return /* @__PURE__ */ React14.createElement("div", {
1397
+ role: "form",
1398
+ className: "flex flex-col w-full p-2 gap-4"
1399
+ }, /* @__PURE__ */ React14.createElement(Input5.Root, null, /* @__PURE__ */ React14.createElement("div", {
1400
+ role: "none",
1401
+ className: "flex flex-col gap-1"
1402
+ }, /* @__PURE__ */ React14.createElement(Input5.Label, null, t("name label")), /* @__PURE__ */ React14.createElement(Input5.TextInput, {
1403
+ placeholder: t("name placeholder"),
1404
+ value: space.properties.name ?? "",
1405
+ onChange: (event) => {
1406
+ space.properties.name = event.target.value;
1407
+ }
1408
+ }))), edgeReplicationAvailable && /* @__PURE__ */ React14.createElement(Input5.Root, null, /* @__PURE__ */ React14.createElement("div", {
1409
+ role: "none",
1410
+ className: "flex justify-between"
1411
+ }, /* @__PURE__ */ React14.createElement(Input5.Label, null, t("edge replication label")), /* @__PURE__ */ React14.createElement(Input5.Switch, {
1412
+ checked: edgeReplication,
1413
+ onCheckedChange: toggleEdgeReplication
1414
+ }))));
1415
+ };
1416
+
1417
+ // packages/plugins/plugin-space/src/components/SyncStatus/SyncStatus.tsx
1418
+ import React16, { useEffect as useEffect6, useState as useState10 } from "react";
1419
+ import { StatusBar } from "@dxos/plugin-status-bar";
1420
+ import { useClient as useClient6 } from "@dxos/react-client";
1421
+ import { Icon as Icon2, Popover as Popover3, useTranslation as useTranslation15 } from "@dxos/react-ui";
1422
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
1423
+ import { mx as mx7 } from "@dxos/react-ui-theme";
1424
+
1425
+ // packages/plugins/plugin-space/src/components/SyncStatus/Space.tsx
1426
+ import React15, { useEffect as useEffect4, useState as useState8 } from "react";
1427
+ import { Icon } from "@dxos/react-ui";
1428
+ import { mx as mx6 } from "@dxos/react-ui-theme";
1429
+ var SYNC_STALLED_TIMEOUT = 5e3;
1430
+ var styles = {
1431
+ barBg: "bg-neutral-50 dark:bg-green-900 text-black",
1432
+ barFg: "bg-neutral-100 bg-green-500",
1433
+ barHover: "dark:hover:bg-green-500"
1434
+ };
1435
+ var useActive = (count) => {
1436
+ const [current, setCurrent] = useState8(count);
1437
+ const [active, setActive] = useState8(false);
1438
+ useEffect4(() => {
1439
+ let t;
1440
+ if (count !== current) {
1441
+ setActive(true);
1442
+ setCurrent(count);
1443
+ t && clearTimeout(t);
1444
+ t = setTimeout(() => {
1445
+ setActive(false);
1446
+ }, SYNC_STALLED_TIMEOUT);
1447
+ }
1448
+ return () => {
1449
+ setActive(false);
1450
+ clearTimeout(t);
1451
+ };
1452
+ }, [
1453
+ count,
1454
+ current
1455
+ ]);
1456
+ return active;
1457
+ };
1458
+ var SpaceRow = ({ spaceId, state: { localDocumentCount, remoteDocumentCount, missingOnLocal, missingOnRemote } }) => {
1459
+ const downActive = useActive(localDocumentCount);
1460
+ const upActive = useActive(remoteDocumentCount);
1461
+ return /* @__PURE__ */ React15.createElement("div", {
1462
+ className: mx6("flex items-center mx-[2px] gap-[2px] cursor-pointer", styles.barHover),
1463
+ title: spaceId,
1464
+ onClick: () => {
1465
+ void navigator.clipboard.writeText(spaceId);
1466
+ }
1467
+ }, /* @__PURE__ */ React15.createElement(Icon, {
1468
+ icon: "ph--arrow-fat-line-left--regular",
1469
+ size: 3,
1470
+ classNames: mx6(downActive && "animate-[pulse_1s_infinite]")
1471
+ }), /* @__PURE__ */ React15.createElement(Candle, {
1472
+ up: {
1473
+ count: remoteDocumentCount,
1474
+ total: remoteDocumentCount + missingOnRemote
1475
+ },
1476
+ down: {
1477
+ count: localDocumentCount,
1478
+ total: localDocumentCount + missingOnLocal
1479
+ },
1480
+ title: spaceId
1481
+ }), /* @__PURE__ */ React15.createElement(Icon, {
1482
+ icon: "ph--arrow-fat-line-right--regular",
1483
+ size: 3,
1484
+ classNames: mx6(upActive && "animate-[pulse_1s_step-start_infinite]")
1485
+ }));
1486
+ };
1487
+ var Candle = ({ classNames, up, down }) => {
1488
+ return /* @__PURE__ */ React15.createElement("div", {
1489
+ className: mx6("grid grid-cols-[1fr_2rem_1fr] w-full h-3", classNames)
1490
+ }, /* @__PURE__ */ React15.createElement(Bar, {
1491
+ classNames: "justify-end",
1492
+ ...up
1493
+ }), /* @__PURE__ */ React15.createElement("div", {
1494
+ className: "relative"
1495
+ }, /* @__PURE__ */ React15.createElement("div", {
1496
+ className: mx6("absolute inset-0 flex items-center justify-center text-xs", styles.barBg)
1497
+ }, up.total)), /* @__PURE__ */ React15.createElement(Bar, down));
1498
+ };
1499
+ var Bar = ({ classNames, count, total }) => {
1500
+ let p = count / total * 100;
1501
+ if (count < total) {
1502
+ p = Math.min(p, 95);
1503
+ }
1504
+ return /* @__PURE__ */ React15.createElement("div", {
1505
+ className: mx6("relative flex w-full", styles.barBg, classNames)
1506
+ }, /* @__PURE__ */ React15.createElement("div", {
1507
+ className: mx6("shrink-0", styles.barFg),
1508
+ style: {
1509
+ width: `${p}%`
1510
+ }
1511
+ }), count !== total && /* @__PURE__ */ React15.createElement("div", {
1512
+ className: "absolute top-0 bottom-0 flex items-center mx-0.5 text-black text-xs"
1513
+ }, count));
1514
+ };
1515
+
1516
+ // packages/plugins/plugin-space/src/components/SyncStatus/save-tracker.ts
1517
+ import { Context } from "@dxos/context";
1518
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SyncStatus/save-tracker.ts";
1519
+ var createClientSaveTracker = (client, cb) => {
1520
+ const unsubscribeCallbacks = {};
1521
+ const state = {};
1522
+ const install = (spaces) => {
1523
+ for (const space of spaces) {
1524
+ if (state[space.id]) {
1525
+ continue;
1526
+ }
1527
+ state[space.id] = "saved";
1528
+ unsubscribeCallbacks[space.id] = createSpaceSaveTracker(space, (s) => {
1529
+ state[space.id] = s;
1530
+ cb(Object.values(state).some((s2) => s2 === "saving") ? "saving" : "saved");
1531
+ });
1532
+ }
1533
+ };
1534
+ client.spaces.subscribe((spaces) => {
1535
+ install(spaces);
1536
+ });
1537
+ install(client.spaces.get());
1538
+ return () => {
1539
+ for (const unsubscribe of Object.values(unsubscribeCallbacks)) {
1540
+ unsubscribe();
1541
+ }
1542
+ };
1543
+ };
1544
+ var createSpaceSaveTracker = (space, cb) => {
1545
+ const ctx = new Context(void 0, {
1546
+ F: __dxlog_file4,
1547
+ L: 40
1548
+ });
1549
+ void space.waitUntilReady().then(() => {
1550
+ if (ctx.disposed) {
1551
+ return;
1552
+ }
1553
+ let hasUnsavedChanges = false;
1554
+ let lastFlushPromise;
1555
+ space.crud.saveStateChanged.on(ctx, ({ unsavedDocuments }) => {
1556
+ hasUnsavedChanges = unsavedDocuments.length > 0;
1557
+ });
1558
+ space.crud.saveStateChanged.debounce(500).on(ctx, () => {
1559
+ if (hasUnsavedChanges) {
1560
+ lastFlushPromise = void 0;
1561
+ cb("saving");
1562
+ } else {
1563
+ const flushPromise = space.crud.flush();
1564
+ lastFlushPromise = flushPromise;
1565
+ void flushPromise.then(() => {
1566
+ if (lastFlushPromise === flushPromise) {
1567
+ cb("saved");
1568
+ }
1569
+ });
1570
+ }
1571
+ });
1572
+ });
1573
+ return () => {
1574
+ void ctx.dispose();
1575
+ };
1576
+ };
1577
+
1578
+ // packages/plugins/plugin-space/src/components/SyncStatus/status.ts
1579
+ var getStatus = ({ offline, saved, needsToUpload, needsToDownload }) => {
1580
+ if (!saved) {
1581
+ return "saving locally";
1582
+ } else if (!offline && needsToDownload) {
1583
+ return "downloading";
1584
+ } else if (!offline && needsToUpload) {
1585
+ return "uploading";
1586
+ } else if (offline && !needsToUpload && !needsToDownload) {
1587
+ return "offline persisted";
1588
+ } else {
1589
+ return "remote synced";
1590
+ }
1591
+ };
1592
+ var getIcon = (status) => {
1593
+ switch (status) {
1594
+ case "saving locally":
1595
+ return "ph--download--regular";
1596
+ case "downloading":
1597
+ return "ph--cloud-arrow-down--regular";
1598
+ case "uploading":
1599
+ return "ph--cloud-arrow-up--regular";
1600
+ case "offline persisted":
1601
+ return "ph--check-circle--regular";
1602
+ case "remote synced":
1603
+ return "ph--cloud-check--regular";
1604
+ }
1605
+ };
1606
+
1607
+ // packages/plugins/plugin-space/src/components/SyncStatus/sync-state.ts
1608
+ import { useEffect as useEffect5, useState as useState9 } from "react";
1609
+ import { Context as Context2 } from "@dxos/context";
1610
+ import { EdgeService } from "@dxos/protocols";
1611
+ import { useClient as useClient5 } from "@dxos/react-client";
1612
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SyncStatus/sync-state.ts";
1613
+ var createEmptyEdgeSyncState = () => ({
1614
+ missingOnLocal: 0,
1615
+ missingOnRemote: 0,
1616
+ localDocumentCount: 0,
1617
+ remoteDocumentCount: 0,
1618
+ differentDocuments: 0
1619
+ });
1620
+ var getSyncSummary = (syncMap) => {
1621
+ return Object.entries(syncMap).reduce((summary, [_spaceId, peerState]) => {
1622
+ summary.missingOnLocal += peerState.missingOnLocal;
1623
+ summary.missingOnRemote += peerState.missingOnRemote;
1624
+ summary.localDocumentCount += peerState.localDocumentCount;
1625
+ summary.remoteDocumentCount += peerState.remoteDocumentCount;
1626
+ summary.differentDocuments += peerState.differentDocuments;
1627
+ return summary;
1628
+ }, createEmptyEdgeSyncState());
1629
+ };
1630
+ var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);
1631
+ var useSyncState = () => {
1632
+ const client = useClient5();
1633
+ const [spaceState, setSpaceState] = useState9({});
1634
+ useEffect5(() => {
1635
+ const ctx = new Context2(void 0, {
1636
+ F: __dxlog_file5,
1637
+ L: 48
1638
+ });
1639
+ const createSubscriptions = (spaces) => {
1640
+ for (const space of spaces) {
1641
+ if (spaceState[space.id]) {
1642
+ continue;
1643
+ }
1644
+ ctx.onDispose(space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {
1645
+ const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
1646
+ if (syncState) {
1647
+ setSpaceState((spaceState2) => ({
1648
+ ...spaceState2,
1649
+ [space.id]: syncState
1650
+ }));
1651
+ }
1652
+ }));
1653
+ }
1654
+ };
1655
+ createSubscriptions(client.spaces.get());
1656
+ client.spaces.subscribe((spaces) => {
1657
+ createSubscriptions(spaces);
1658
+ });
1659
+ return () => {
1660
+ void ctx.dispose();
1661
+ };
1662
+ }, [
1663
+ client
1664
+ ]);
1665
+ return spaceState;
1666
+ };
1667
+
1668
+ // packages/plugins/plugin-space/src/components/SyncStatus/SyncStatus.tsx
1669
+ var SyncStatus = () => {
1670
+ const client = useClient6();
1671
+ const state = useSyncState();
1672
+ const [saved, setSaved] = useState10(true);
1673
+ useEffect6(() => {
1674
+ return createClientSaveTracker(client, (state2) => {
1675
+ setSaved(state2 === "saved");
1676
+ });
1677
+ }, []);
1678
+ return /* @__PURE__ */ React16.createElement(SyncStatusIndicator, {
1679
+ state,
1680
+ saved
1681
+ });
1682
+ };
1683
+ var SyncStatusIndicator = ({ state, saved }) => {
1684
+ const { t } = useTranslation15(SPACE_PLUGIN);
1685
+ const summary = getSyncSummary(state);
1686
+ const offline = Object.values(state).length === 0;
1687
+ const needsToUpload = summary.differentDocuments > 0 || summary.missingOnRemote > 0;
1688
+ const needsToDownload = summary.differentDocuments > 0 || summary.missingOnLocal > 0;
1689
+ const status = getStatus({
1690
+ offline,
1691
+ saved,
1692
+ needsToUpload,
1693
+ needsToDownload
1694
+ });
1695
+ const [classNames, setClassNames] = useState10();
1696
+ useEffect6(() => {
1697
+ setClassNames(void 0);
1698
+ if (offline || !needsToUpload && !needsToDownload) {
1699
+ return;
1700
+ }
1701
+ const t2 = setTimeout(() => {
1702
+ setClassNames("text-orange-500");
1703
+ }, SYNC_STALLED_TIMEOUT);
1704
+ return () => clearTimeout(t2);
1705
+ }, [
1706
+ offline,
1707
+ needsToUpload,
1708
+ needsToDownload
1709
+ ]);
1710
+ const title = t(`${status} label`);
1711
+ const icon = /* @__PURE__ */ React16.createElement(Icon2, {
1712
+ icon: getIcon(status),
1713
+ size: 4,
1714
+ classNames
1715
+ });
1716
+ if (offline) {
1717
+ return /* @__PURE__ */ React16.createElement(StatusBar.Item, {
1718
+ title
1719
+ }, icon);
1720
+ } else {
1721
+ return /* @__PURE__ */ React16.createElement(Popover3.Root, null, /* @__PURE__ */ React16.createElement(Popover3.Trigger, {
1722
+ asChild: true
1723
+ }, /* @__PURE__ */ React16.createElement(StatusBar.Button, {
1724
+ title
1725
+ }, icon)), /* @__PURE__ */ React16.createElement(Popover3.Portal, null, /* @__PURE__ */ React16.createElement(Popover3.Content, {
1726
+ sideOffset: 16
1727
+ }, /* @__PURE__ */ React16.createElement(SyncStatusDetail, {
1728
+ state,
1729
+ summary,
1730
+ debug: false
1731
+ }))));
1732
+ }
1733
+ };
1734
+ var SyncStatusDetail = ({ classNames, state, summary, debug }) => {
1735
+ const { t } = useTranslation15(SPACE_PLUGIN);
1736
+ const entries = Object.entries(state).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
1737
+ return /* @__PURE__ */ React16.createElement("div", {
1738
+ className: mx7("flex flex-col gap-3 p-2 text-xs min-w-[16rem]", classNames)
1739
+ }, /* @__PURE__ */ React16.createElement("h1", null, t("sync status title")), /* @__PURE__ */ React16.createElement("div", {
1740
+ className: "flex flex-col gap-2"
1741
+ }, entries.map(([spaceId, state2]) => /* @__PURE__ */ React16.createElement(SpaceRow, {
1742
+ key: spaceId,
1743
+ spaceId,
1744
+ state: state2
1745
+ }))), debug && /* @__PURE__ */ React16.createElement(SyntaxHighlighter, {
1746
+ language: "json"
1747
+ }, JSON.stringify(summary, null, 2)));
1748
+ };
1749
+
1750
+ // packages/plugins/plugin-space/src/translations.ts
1751
+ var translations_default = [
1752
+ {
1753
+ "en-US": {
1754
+ [SPACE_PLUGIN]: {
1755
+ "plugin name": "Spaces",
1756
+ "first run message": "Nothing selected.",
1757
+ "create space label": "Create space",
1758
+ "join space label": "Join space",
1759
+ "empty space message": "No documents",
1760
+ "empty tree message": "No spaces",
1761
+ "unnamed space label": "New space",
1762
+ "closed space label": "Closed",
1763
+ "loading space label": "Loading space\u2026",
1764
+ "lock space label": "Lock space",
1765
+ "unlock space label": "Unlock space",
1766
+ "rename space label": "Rename space",
1767
+ "active space label": "Active space:",
1768
+ "space name label": "Space name",
1769
+ "object name label": "Object name",
1770
+ "close space label": "Close space",
1771
+ "open space label": "Open space",
1772
+ "export data label": "Export data",
1773
+ "import data label": "Import data",
1774
+ "migrate space label": "Migrate space",
1775
+ "share space": "Share space",
1776
+ "save space to disk label": "Save to disk",
1777
+ "load space from disk label": "Load from disk",
1778
+ "confirm restore title": "Overwrite files in this space?",
1779
+ "confirm restore body": "Restoring from a backup will overwrite the contents of any documents that match.",
1780
+ "upload file message": "Drag file here or click to browse",
1781
+ "object title placeholder": "Type a title here\u2026",
1782
+ "personal space label": "Personal Space",
1783
+ "spaces label": "Spaces",
1784
+ "show hidden spaces label": "Show closed spaces",
1785
+ "save files to directory label": "Save files to disk",
1786
+ "select path label": "Select path",
1787
+ "rename collection label": "Rename collection",
1788
+ "rename object label": "Rename item",
1789
+ "duplicate object label": "Duplicate item",
1790
+ "delete collection label": "Delete collection",
1791
+ "delete object label": "Delete item",
1792
+ "collection deleted label": "Collection deleted",
1793
+ "object deleted label": "Item deleted",
1794
+ "go to object label": "Open item",
1795
+ "found object label": "Ready.",
1796
+ "found object description": "The requested object is now available.",
1797
+ "waiting for object label": "Loading\u2026",
1798
+ "waiting for object description": "The requested object is still being synchronized.",
1799
+ "object not found label": "Nothing found.",
1800
+ "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.",
1801
+ "missing object message": "Object not available.",
1802
+ "missing object description": "The requested object has not been found yet. Ensure there are enough peers online in the space with an updated copy.",
1803
+ "create collection label": "Create collection",
1804
+ "unnamed object label": "New object",
1805
+ "unnamed collection label": "New collection",
1806
+ "create object in space label": "Add to space",
1807
+ "create object in collection label": "Add to collection",
1808
+ "share space label": "Share",
1809
+ "space members label": "Space members",
1810
+ "active space members heading": "Online ({{count}})",
1811
+ "inactive space members heading": "Offline ({{count}})",
1812
+ "presence label_zero": "No other viewers",
1813
+ "presence label_one": "1 other viewer",
1814
+ "presence label_other": "{{count}} other viewers",
1815
+ "persisted locally label": "Changes saved locally.",
1816
+ "persisted locally message": "All changes have been saved to disk on this device.",
1817
+ "persistence pending label": "Saving\u2026",
1818
+ "persistence error label": "Error saving changes.",
1819
+ "more actions label": "More actions",
1820
+ "invitations heading": "Invitations",
1821
+ "keyshortcuts label": "Keyboard shortcuts",
1822
+ "menu footer label": "Details",
1823
+ "location label": "Located in",
1824
+ "space limit label": "Space Limit Reached",
1825
+ "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.",
1826
+ "space limit close label": "Close",
1827
+ "remove deleted objects label": "Cleanup",
1828
+ "remove deleted objects alt": "Permanently remove deleted objects to free up space.",
1829
+ "copy link label": "Copy link",
1830
+ "default on space create label": "On space create",
1831
+ "sync status title": "Sync status",
1832
+ "dismiss label": "Dismiss",
1833
+ "join success label": "Successfully joined space",
1834
+ "name label": "Name",
1835
+ "name placeholder": "Name",
1836
+ "unnamed object settings label": "Settings",
1837
+ "edge replication label": "Enable EDGE Replication",
1838
+ "saving locally label": "Writing to disk",
1839
+ "downloading label": "Replicating from peers",
1840
+ "uploading label": "Replicating to peers",
1841
+ "offline persisted label": "Saved to disk (offline)",
1842
+ "remote synced label": "Synced with peers",
1843
+ "open settings panel label": "Show Settings"
1844
+ }
1845
+ }
1846
+ }
1847
+ ];
1848
+
1849
+ // packages/plugins/plugin-space/src/SpacePlugin.tsx
1850
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/SpacePlugin.tsx";
1851
+ var ACTIVE_NODE_BROADCAST_INTERVAL = 3e4;
1852
+ var SPACE_MAX_OBJECTS = 500;
1853
+ var DIRECTORY_TYPE = "text/directory";
1854
+ var parseSpacePlugin = (plugin) => Array.isArray(plugin?.provides.space?.enabled) ? plugin : void 0;
1855
+ var SpacePlugin = ({ firstRun, onFirstRun } = {}) => {
1856
+ const settings = new LocalStorageStore(SPACE_PLUGIN, {
1857
+ onSpaceCreate: "dxos.org/plugin/markdown/action/create"
1858
+ });
1859
+ const state = new LocalStorageStore(SPACE_PLUGIN, {
1860
+ awaiting: void 0,
1861
+ spaceNames: {},
1862
+ viewersByObject: {},
1863
+ // TODO(wittjosiah): Stop using (Complex)Map inside reactive object.
1864
+ viewersByIdentity: new ComplexMap2(PublicKey2.hash),
1865
+ sdkMigrationRunning: {}
1866
+ });
1867
+ const subscriptions = new EventSubscriptions();
1868
+ const spaceSubscriptions = new EventSubscriptions();
1869
+ const graphSubscriptions = /* @__PURE__ */ new Map();
1870
+ let clientPlugin;
1871
+ let graphPlugin;
1872
+ let intentPlugin;
1873
+ let layoutPlugin;
1874
+ let navigationPlugin;
1875
+ let attentionPlugin;
1876
+ const onSpaceReady = async () => {
1877
+ if (!clientPlugin || !intentPlugin || !graphPlugin || !navigationPlugin || !layoutPlugin || !attentionPlugin) {
1878
+ return;
1879
+ }
1880
+ const client = clientPlugin.provides.client;
1881
+ const dispatch = intentPlugin.provides.intent.dispatch;
1882
+ const graph = graphPlugin.provides.graph;
1883
+ const location = navigationPlugin.provides.location;
1884
+ const layout = layoutPlugin.provides.layout;
1885
+ const attention = attentionPlugin.provides.attention;
1886
+ const defaultSpace = client.spaces.default;
1887
+ if (typeof defaultSpace.properties[COMPOSER_SPACE_LOCK] !== "boolean") {
1888
+ defaultSpace.properties[COMPOSER_SPACE_LOCK] = true;
1889
+ }
1890
+ const { objects: [spacesOrder] } = await defaultSpace.db.query(Filter.schema(Expando, {
1891
+ key: SHARED
1892
+ })).run();
1893
+ if (!spacesOrder) {
1894
+ defaultSpace.db.add(create2({
1895
+ key: SHARED,
1896
+ order: []
1897
+ }));
1898
+ }
1899
+ subscriptions.add(scheduledEffect(() => ({
1900
+ layoutMode: layout.layoutMode,
1901
+ soloPart: location.active.solo?.[0]
1902
+ }), ({ layoutMode, soloPart }) => {
1903
+ if (layoutMode !== "solo" || !soloPart) {
1904
+ return;
1905
+ }
1906
+ const node = graph.findNode(soloPart.id);
1907
+ if (!node && soloPart.id.length === FQ_ID_LENGTH) {
1908
+ void dispatch({
1909
+ plugin: SPACE_PLUGIN,
1910
+ action: SpaceAction.WAIT_FOR_OBJECT,
1911
+ data: {
1912
+ id: soloPart.id
1913
+ }
1914
+ });
1915
+ }
1916
+ }));
1917
+ subscriptions.add(client.spaces.subscribe(async (spaces) => {
1918
+ if (defaultSpace.state.get() === SpaceState3.SPACE_REQUIRES_MIGRATION) {
1919
+ await defaultSpace.internal.migrate();
1920
+ }
1921
+ spaces.filter((space) => space.state.get() === SpaceState3.SPACE_READY).forEach((space) => {
1922
+ subscriptions.add(scheduledEffect(() => ({
1923
+ name: space.properties.name
1924
+ }), ({ name }) => state.values.spaceNames[space.id] = name));
1925
+ });
1926
+ }).unsubscribe);
1927
+ subscriptions.add(scheduledEffect(() => ({
1928
+ ids: openIds(location.active),
1929
+ removed: location.closed ? [
1930
+ location.closed
1931
+ ].flat() : []
1932
+ }), ({ ids, removed }) => {
1933
+ const send = () => {
1934
+ const spaces = client.spaces.get();
1935
+ const identity = client.halo.identity.get();
1936
+ if (identity && location.active) {
1937
+ const idsBySpace = reduceGroupBy(ids, (id) => {
1938
+ const [spaceId] = id.split(":");
1939
+ return spaceId;
1940
+ });
1941
+ for (const space of spaces) {
1942
+ if (!idsBySpace.has(space.id)) {
1943
+ idsBySpace.set(space.id, []);
1944
+ }
1945
+ }
1946
+ for (const [spaceId, ids2] of idsBySpace) {
1947
+ const space = spaces.find((space2) => space2.id === spaceId);
1948
+ if (!space) {
1949
+ continue;
1950
+ }
1951
+ void space.postMessage("viewing", {
1952
+ identityKey: identity.identityKey.toHex(),
1953
+ attended: attention.attended ? [
1954
+ ...attention.attended
1955
+ ] : [],
1956
+ added: ids2,
1957
+ // TODO(Zan): When we re-open a part, we should remove it from the removed list in the navigation plugin.
1958
+ removed: removed.filter((id) => !ids2.includes(id))
1959
+ }).catch((err) => {
1960
+ log3.warn("Failed to broadcast active node for presence.", {
1961
+ err: err.message
1962
+ }, {
1963
+ F: __dxlog_file6,
1964
+ L: 257,
1965
+ S: void 0,
1966
+ C: (f, a) => f(...a)
1967
+ });
1968
+ });
1969
+ }
1970
+ }
1971
+ };
1972
+ send();
1973
+ const interval = setInterval(() => send(), ACTIVE_NODE_BROADCAST_INTERVAL);
1974
+ return () => clearInterval(interval);
1975
+ }));
1976
+ subscriptions.add(client.spaces.subscribe((spaces) => {
1977
+ spaceSubscriptions.clear();
1978
+ spaces.forEach((space) => {
1979
+ spaceSubscriptions.add(space.listen("viewing", (message) => {
1980
+ const { added, removed, attended } = message.payload;
1981
+ const identityKey = PublicKey2.safeFrom(message.payload.identityKey);
1982
+ if (identityKey && Array.isArray(added) && Array.isArray(removed)) {
1983
+ added.forEach((id) => {
1984
+ if (typeof id === "string") {
1985
+ if (!(id in state.values.viewersByObject)) {
1986
+ state.values.viewersByObject[id] = new ComplexMap2(PublicKey2.hash);
1987
+ }
1988
+ state.values.viewersByObject[id].set(identityKey, {
1989
+ lastSeen: Date.now(),
1990
+ currentlyAttended: new Set(attended).has(id)
1991
+ });
1992
+ if (!state.values.viewersByIdentity.has(identityKey)) {
1993
+ state.values.viewersByIdentity.set(identityKey, /* @__PURE__ */ new Set());
1994
+ }
1995
+ state.values.viewersByIdentity.get(identityKey).add(id);
1996
+ }
1997
+ });
1998
+ removed.forEach((id) => {
1999
+ if (typeof id === "string") {
2000
+ state.values.viewersByObject[id]?.delete(identityKey);
2001
+ state.values.viewersByIdentity.get(identityKey)?.delete(id);
2002
+ }
2003
+ });
2004
+ }
2005
+ }));
2006
+ });
2007
+ }).unsubscribe);
2008
+ };
2009
+ return {
2010
+ meta: meta_default,
2011
+ ready: async (plugins) => {
2012
+ settings.prop({
2013
+ key: "showHidden",
2014
+ type: LocalStorageStore.bool({
2015
+ allowUndefined: true
2016
+ })
2017
+ });
2018
+ state.prop({
2019
+ key: "spaceNames",
2020
+ type: LocalStorageStore.json()
2021
+ });
2022
+ graphPlugin = resolvePlugin(plugins, parseGraphPlugin);
2023
+ layoutPlugin = resolvePlugin(plugins, parseLayoutPlugin);
2024
+ navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin2);
2025
+ attentionPlugin = resolvePlugin(plugins, parseAttentionPlugin);
2026
+ clientPlugin = resolvePlugin(plugins, parseClientPlugin);
2027
+ intentPlugin = resolvePlugin(plugins, parseIntentPlugin2);
2028
+ if (!clientPlugin || !intentPlugin) {
2029
+ return;
2030
+ }
2031
+ const client = clientPlugin.provides.client;
2032
+ const dispatch = intentPlugin.provides.intent.dispatch;
2033
+ const handleFirstRun = async () => {
2034
+ const defaultSpace = client.spaces.default;
2035
+ defaultSpace.properties[CollectionType.typename] = create2(CollectionType, {
2036
+ objects: [],
2037
+ views: {}
2038
+ });
2039
+ if (Migrations2.versionProperty) {
2040
+ defaultSpace.properties[Migrations2.versionProperty] = Migrations2.targetVersion;
2041
+ }
2042
+ await onFirstRun?.({
2043
+ client,
2044
+ dispatch
2045
+ });
2046
+ };
2047
+ subscriptions.add(client.spaces.isReady.subscribe(async (ready) => {
2048
+ if (ready) {
2049
+ await clientPlugin?.provides.client.spaces.default.waitUntilReady();
2050
+ if (firstRun) {
2051
+ void firstRun?.wait().then(handleFirstRun);
2052
+ } else {
2053
+ await handleFirstRun();
2054
+ }
2055
+ await onSpaceReady();
2056
+ }
2057
+ }).unsubscribe);
2058
+ },
2059
+ unload: async () => {
2060
+ settings.close();
2061
+ spaceSubscriptions.clear();
2062
+ subscriptions.clear();
2063
+ graphSubscriptions.forEach((cb) => cb());
2064
+ graphSubscriptions.clear();
2065
+ },
2066
+ provides: {
2067
+ space: state.values,
2068
+ settings: settings.values,
2069
+ translations: [
2070
+ ...translations_default,
2071
+ osTranslations
2072
+ ],
2073
+ complementary: {
2074
+ panels: [
2075
+ {
2076
+ id: "settings",
2077
+ label: [
2078
+ "open settings panel label",
2079
+ {
2080
+ ns: SPACE_PLUGIN
2081
+ }
2082
+ ],
2083
+ icon: "ph--gear--regular"
2084
+ }
2085
+ ]
2086
+ },
2087
+ root: () => state.values.awaiting ? /* @__PURE__ */ React17.createElement(AwaitingObject, {
2088
+ id: state.values.awaiting
2089
+ }) : null,
2090
+ metadata: {
2091
+ records: {
2092
+ [CollectionType.typename]: {
2093
+ placeholder: [
2094
+ "unnamed collection label",
2095
+ {
2096
+ ns: SPACE_PLUGIN
2097
+ }
2098
+ ],
2099
+ icon: "ph--cards-three--regular",
2100
+ // TODO(wittjosiah): Move out of metadata.
2101
+ loadReferences: (collection) => loadObjectReferences(collection, (collection2) => [
2102
+ ...collection2.objects,
2103
+ ...Object.values(collection2.views)
2104
+ ])
2105
+ }
2106
+ }
2107
+ },
2108
+ echo: {
2109
+ schema: [
2110
+ CollectionType
2111
+ ]
2112
+ },
2113
+ surface: {
2114
+ component: ({ data, role, ...rest }) => {
2115
+ switch (role) {
2116
+ case "article":
2117
+ return isSpace2(data.object) && data.object.state.get() === SpaceState3.SPACE_READY ? /* @__PURE__ */ React17.createElement(Surface2, {
2118
+ data: {
2119
+ object: data.object.properties[CollectionType.typename],
2120
+ id: data.object.id
2121
+ },
2122
+ role,
2123
+ ...rest
2124
+ }) : data.object instanceof CollectionType ? {
2125
+ node: /* @__PURE__ */ React17.createElement(CollectionMain, {
2126
+ collection: data.object
2127
+ }),
2128
+ disposition: "fallback"
2129
+ } : null;
2130
+ case "complementary--settings":
2131
+ return isSpace2(data.subject) ? /* @__PURE__ */ React17.createElement(SpaceSettingsPanel, {
2132
+ space: data.subject
2133
+ }) : isEchoObject2(data.subject) ? {
2134
+ node: /* @__PURE__ */ React17.createElement(DefaultObjectSettings, {
2135
+ object: data.subject
2136
+ }),
2137
+ disposition: "fallback"
2138
+ } : null;
2139
+ case "dialog":
2140
+ if (data.component === "dxos.org/plugin/space/InvitationManagerDialog") {
2141
+ return /* @__PURE__ */ React17.createElement(Dialog.Content, null, /* @__PURE__ */ React17.createElement(ClipboardProvider2, null, /* @__PURE__ */ React17.createElement(InvitationManager, {
2142
+ active: true,
2143
+ ...data.subject
2144
+ })));
2145
+ }
2146
+ return null;
2147
+ case "popover": {
2148
+ if (data.component === "dxos.org/plugin/space/RenameSpacePopover" && isSpace2(data.subject)) {
2149
+ return /* @__PURE__ */ React17.createElement(PopoverRenameSpace, {
2150
+ space: data.subject
2151
+ });
2152
+ }
2153
+ if (data.component === "dxos.org/plugin/space/RenameObjectPopover" && isReactiveObject2(data.subject)) {
2154
+ return /* @__PURE__ */ React17.createElement(PopoverRenameObject, {
2155
+ object: data.subject
2156
+ });
2157
+ }
2158
+ return null;
2159
+ }
2160
+ // TODO(burdon): Add role name syntax to minimal plugin docs.
2161
+ case "presence--glyph": {
2162
+ return isReactiveObject2(data.object) ? /* @__PURE__ */ React17.createElement(SmallPresenceLive, {
2163
+ id: data.id,
2164
+ viewers: state.values.viewersByObject[fullyQualifiedId4(data.object)]
2165
+ }) : /* @__PURE__ */ React17.createElement(SmallPresence, {
2166
+ id: data.id,
2167
+ count: 0
2168
+ });
2169
+ }
2170
+ case "navbar-start": {
2171
+ return null;
2172
+ }
2173
+ case "navbar-end": {
2174
+ if (!isEchoObject2(data.object) && !isSpace2(data.object)) {
2175
+ return null;
2176
+ }
2177
+ const space = isSpace2(data.object) ? data.object : getSpace4(data.object);
2178
+ const object = isSpace2(data.object) ? data.object.state.get() === SpaceState3.SPACE_READY ? space?.properties[CollectionType.typename] : void 0 : data.object;
2179
+ return space && object ? {
2180
+ node: /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(SpacePresence, {
2181
+ object
2182
+ }), space.properties[COMPOSER_SPACE_LOCK] ? null : /* @__PURE__ */ React17.createElement(ShareSpaceButton, {
2183
+ spaceId: space.id
2184
+ })),
2185
+ disposition: "hoist"
2186
+ } : null;
2187
+ }
2188
+ case "section":
2189
+ return data.object instanceof CollectionType ? /* @__PURE__ */ React17.createElement(CollectionSection, {
2190
+ collection: data.object
2191
+ }) : null;
2192
+ case "settings":
2193
+ return data.plugin === meta_default.id ? /* @__PURE__ */ React17.createElement(SpaceSettings, {
2194
+ settings: settings.values
2195
+ }) : null;
2196
+ case "menu-footer":
2197
+ if (isEchoObject2(data.object)) {
2198
+ return /* @__PURE__ */ React17.createElement(MenuFooter, {
2199
+ object: data.object
2200
+ });
2201
+ } else {
2202
+ return null;
2203
+ }
2204
+ case "status": {
2205
+ return /* @__PURE__ */ React17.createElement(SyncStatus, null);
2206
+ }
2207
+ default:
2208
+ return null;
2209
+ }
2210
+ }
2211
+ },
2212
+ graph: {
2213
+ builder: (plugins) => {
2214
+ const clientPlugin2 = resolvePlugin(plugins, parseClientPlugin);
2215
+ const metadataPlugin = resolvePlugin(plugins, parseMetadataResolverPlugin);
2216
+ const graphPlugin2 = resolvePlugin(plugins, parseGraphPlugin);
2217
+ const client = clientPlugin2?.provides.client;
2218
+ const dispatch = intentPlugin?.provides.intent.dispatch;
2219
+ const resolve = metadataPlugin?.provides.metadata.resolver;
2220
+ const graph = graphPlugin2?.provides.graph;
2221
+ if (!client || !dispatch || !resolve || !graph) {
2222
+ return [];
2223
+ }
2224
+ return [
2225
+ // Create spaces group node.
2226
+ createExtension({
2227
+ id: `${SPACE_PLUGIN}/root`,
2228
+ filter: (node) => node.id === "root",
2229
+ connector: () => {
2230
+ const isReady = toSignal((onChange) => {
2231
+ let defaultSpaceUnsubscribe;
2232
+ client.spaces.isReady.subscribe((ready) => {
2233
+ if (ready) {
2234
+ defaultSpaceUnsubscribe = client.spaces.default.state.subscribe(() => onChange()).unsubscribe;
2235
+ }
2236
+ });
2237
+ return () => defaultSpaceUnsubscribe?.();
2238
+ }, () => client.spaces.isReady.get() && client.spaces.default.state.get() === SpaceState3.SPACE_READY);
2239
+ if (!isReady) {
2240
+ return [];
2241
+ }
2242
+ return [
2243
+ {
2244
+ id: SPACES,
2245
+ type: SPACES,
2246
+ properties: {
2247
+ label: [
2248
+ "spaces label",
2249
+ {
2250
+ ns: SPACE_PLUGIN
2251
+ }
2252
+ ],
2253
+ testId: "spacePlugin.spaces",
2254
+ role: "branch",
2255
+ childrenPersistenceClass: "echo",
2256
+ onRearrangeChildren: async (nextOrder) => {
2257
+ graph._sortEdges(SPACES, "outbound", nextOrder.map(({ id }) => id));
2258
+ const { objects: [spacesOrder] } = await client.spaces.default.db.query(Filter.schema(Expando, {
2259
+ key: SHARED
2260
+ })).run();
2261
+ if (spacesOrder) {
2262
+ spacesOrder.order = nextOrder.map(({ id }) => id);
2263
+ } else {
2264
+ log3.warn("spaces order object not found", void 0, {
2265
+ F: __dxlog_file6,
2266
+ L: 553,
2267
+ S: void 0,
2268
+ C: (f, a) => f(...a)
2269
+ });
2270
+ }
2271
+ }
2272
+ }
2273
+ }
2274
+ ];
2275
+ }
2276
+ }),
2277
+ // Create space nodes.
2278
+ createExtension({
2279
+ id: SPACES,
2280
+ filter: (node) => node.id === SPACES,
2281
+ actions: () => [
2282
+ {
2283
+ id: SpaceAction.CREATE,
2284
+ data: async () => {
2285
+ await dispatch([
2286
+ {
2287
+ plugin: SPACE_PLUGIN,
2288
+ action: SpaceAction.CREATE
2289
+ },
2290
+ {
2291
+ action: NavigationAction3.OPEN
2292
+ }
2293
+ ]);
2294
+ },
2295
+ properties: {
2296
+ label: [
2297
+ "create space label",
2298
+ {
2299
+ ns: SPACE_PLUGIN
2300
+ }
2301
+ ],
2302
+ icon: "ph--plus--regular",
2303
+ disposition: "item",
2304
+ testId: "spacePlugin.createSpace",
2305
+ className: "pbs-4"
2306
+ }
2307
+ },
2308
+ {
2309
+ id: SpaceAction.JOIN,
2310
+ data: async () => {
2311
+ await dispatch([
2312
+ {
2313
+ plugin: SPACE_PLUGIN,
2314
+ action: SpaceAction.JOIN
2315
+ },
2316
+ {
2317
+ action: NavigationAction3.OPEN
2318
+ }
2319
+ ]);
2320
+ },
2321
+ properties: {
2322
+ label: [
2323
+ "join space label",
2324
+ {
2325
+ ns: SPACE_PLUGIN
2326
+ }
2327
+ ],
2328
+ icon: "ph--sign-in--regular",
2329
+ disposition: "item",
2330
+ testId: "spacePlugin.joinSpace",
2331
+ className: "pbe-4"
2332
+ }
2333
+ }
2334
+ ],
2335
+ connector: () => {
2336
+ const spaces = toSignal((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
2337
+ const isReady = toSignal((onChange) => client.spaces.isReady.subscribe(() => onChange()).unsubscribe, () => client.spaces.isReady.get());
2338
+ if (!spaces || !isReady) {
2339
+ return;
2340
+ }
2341
+ const [spacesOrder] = memoizeQuery(client.spaces.default, Filter.schema(Expando, {
2342
+ key: SHARED
2343
+ }));
2344
+ const order = spacesOrder?.order ?? [];
2345
+ const orderMap = new Map(order.map((id, index) => [
2346
+ id,
2347
+ index
2348
+ ]));
2349
+ return [
2350
+ ...spaces.filter((space) => orderMap.has(space.id)).sort((a, b) => orderMap.get(a.id) - orderMap.get(b.id)),
2351
+ ...spaces.filter((space) => !orderMap.has(space.id))
2352
+ ].filter((space) => settings.values.showHidden ? true : space.state.get() !== SpaceState3.SPACE_INACTIVE).map((space) => constructSpaceNode({
2353
+ space,
2354
+ personal: space === client.spaces.default,
2355
+ namesCache: state.values.spaceNames,
2356
+ resolve
2357
+ }));
2358
+ }
2359
+ }),
2360
+ // Find an object by its fully qualified id.
2361
+ createExtension({
2362
+ id: `${SPACE_PLUGIN}/objects`,
2363
+ resolver: ({ id }) => {
2364
+ const [spaceId, objectId] = id.split(":");
2365
+ const space = client.spaces.get().find((space2) => space2.id === spaceId);
2366
+ if (!space) {
2367
+ return;
2368
+ }
2369
+ const state2 = toSignal((onChange) => space.state.subscribe(() => onChange()).unsubscribe, () => space.state.get(), space.id);
2370
+ if (state2 !== SpaceState3.SPACE_READY) {
2371
+ return;
2372
+ }
2373
+ const store = memoize2(() => signal(space.db.getObjectById(objectId)), id);
2374
+ memoize2(() => {
2375
+ if (!store.value) {
2376
+ void space.db.loadObjectById(objectId).then((o) => store.value = o);
2377
+ }
2378
+ }, id);
2379
+ const object = store.value;
2380
+ if (!object) {
2381
+ return;
2382
+ }
2383
+ return createObjectNode({
2384
+ object,
2385
+ space,
2386
+ resolve
2387
+ });
2388
+ }
2389
+ }),
2390
+ // Create space actions and action groups.
2391
+ createExtension({
2392
+ id: `${SPACE_PLUGIN}/actions`,
2393
+ filter: (node) => isSpace2(node.data),
2394
+ actionGroups: ({ node }) => constructSpaceActionGroups({
2395
+ space: node.data,
2396
+ dispatch
2397
+ }),
2398
+ actions: ({ node }) => {
2399
+ const space = node.data;
2400
+ return constructSpaceActions({
2401
+ space,
2402
+ dispatch,
2403
+ personal: space === client.spaces.default,
2404
+ migrating: state.values.sdkMigrationRunning[space.id]
2405
+ });
2406
+ }
2407
+ }),
2408
+ // Create nodes for objects in the root collection of a space.
2409
+ createExtension({
2410
+ id: `${SPACE_PLUGIN}/root-collection`,
2411
+ filter: (node) => isSpace2(node.data),
2412
+ connector: ({ node }) => {
2413
+ const space = node.data;
2414
+ const state2 = toSignal((onChange) => space.state.subscribe(() => onChange()).unsubscribe, () => space.state.get(), space.id);
2415
+ if (state2 !== SpaceState3.SPACE_READY) {
2416
+ return;
2417
+ }
2418
+ const collection = space.properties[CollectionType.typename];
2419
+ if (!collection) {
2420
+ return;
2421
+ }
2422
+ return collection.objects.filter(nonNullable).map((object) => createObjectNode({
2423
+ object,
2424
+ space,
2425
+ resolve
2426
+ })).filter(nonNullable);
2427
+ }
2428
+ }),
2429
+ // Create collection actions and action groups.
2430
+ createExtension({
2431
+ id: `${SPACE_PLUGIN}/object-actions`,
2432
+ filter: (node) => isEchoObject2(node.data),
2433
+ actionGroups: ({ node }) => constructObjectActionGroups({
2434
+ object: node.data,
2435
+ dispatch
2436
+ }),
2437
+ actions: ({ node }) => constructObjectActions({
2438
+ node,
2439
+ dispatch
2440
+ })
2441
+ }),
2442
+ // Create nodes for objects in collections.
2443
+ createExtension({
2444
+ id: `${SPACE_PLUGIN}/collection-objects`,
2445
+ filter: (node) => node.data instanceof CollectionType,
2446
+ connector: ({ node }) => {
2447
+ const collection = node.data;
2448
+ const space = getSpace4(collection);
2449
+ if (!space) {
2450
+ return;
2451
+ }
2452
+ return collection.objects.filter(nonNullable).map((object) => createObjectNode({
2453
+ object,
2454
+ space,
2455
+ resolve
2456
+ })).filter(nonNullable);
2457
+ }
2458
+ }),
2459
+ // Create nodes for object settings.
2460
+ createExtension({
2461
+ id: `${SPACE_PLUGIN}/settings-for-subject`,
2462
+ resolver: ({ id }) => {
2463
+ if (!id.endsWith("~settings")) {
2464
+ return;
2465
+ }
2466
+ const type = "orphan-settings-for-subject";
2467
+ const icon = "ph--gear--regular";
2468
+ const [subjectId] = id.split("~");
2469
+ const { spaceId, objectId } = parseId(subjectId);
2470
+ const space = client.spaces.get().find((space2) => space2.id === spaceId);
2471
+ if (!objectId) {
2472
+ const label2 = space ? space.properties.name || [
2473
+ "unnamed space label",
2474
+ {
2475
+ ns: SPACE_PLUGIN
2476
+ }
2477
+ ] : [
2478
+ "unnamed object settings label",
2479
+ {
2480
+ ns: SPACE_PLUGIN
2481
+ }
2482
+ ];
2483
+ return {
2484
+ id,
2485
+ type,
2486
+ data: null,
2487
+ properties: {
2488
+ icon,
2489
+ label: label2,
2490
+ showResolvedThreads: false,
2491
+ object: null,
2492
+ space
2493
+ }
2494
+ };
2495
+ }
2496
+ const object = toSignal((onChange) => {
2497
+ const timeout = setTimeout(async () => {
2498
+ await space?.db.loadObjectById(objectId);
2499
+ onChange();
2500
+ });
2501
+ return () => clearTimeout(timeout);
2502
+ }, () => space?.db.getObjectById(objectId), subjectId);
2503
+ if (!object || !subjectId) {
2504
+ return;
2505
+ }
2506
+ const meta = resolve(getTypename2(object) ?? "");
2507
+ const label = meta.label?.(object) || object.name || meta.placeholder || [
2508
+ "unnamed object settings label",
2509
+ {
2510
+ ns: SPACE_PLUGIN
2511
+ }
2512
+ ];
2513
+ return {
2514
+ id,
2515
+ type,
2516
+ data: null,
2517
+ properties: {
2518
+ icon,
2519
+ label,
2520
+ object
2521
+ }
2522
+ };
2523
+ }
2524
+ })
2525
+ ];
2526
+ },
2527
+ serializer: (plugins) => {
2528
+ const dispatch = resolvePlugin(plugins, parseIntentPlugin2)?.provides.intent.dispatch;
2529
+ if (!dispatch) {
2530
+ return [];
2531
+ }
2532
+ return [
2533
+ {
2534
+ inputType: SPACES,
2535
+ outputType: DIRECTORY_TYPE,
2536
+ serialize: (node) => ({
2537
+ name: translations_default[0]["en-US"][SPACE_PLUGIN]["spaces label"],
2538
+ data: translations_default[0]["en-US"][SPACE_PLUGIN]["spaces label"],
2539
+ type: DIRECTORY_TYPE
2540
+ }),
2541
+ deserialize: () => {
2542
+ }
2543
+ },
2544
+ {
2545
+ inputType: SPACE_TYPE,
2546
+ outputType: DIRECTORY_TYPE,
2547
+ serialize: (node) => ({
2548
+ name: node.data.properties.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed space label"],
2549
+ data: node.data.properties.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed space label"],
2550
+ type: DIRECTORY_TYPE
2551
+ }),
2552
+ deserialize: async (data) => {
2553
+ const result = await dispatch({
2554
+ plugin: SPACE_PLUGIN,
2555
+ action: SpaceAction.CREATE,
2556
+ data: {
2557
+ name: data.name
2558
+ }
2559
+ });
2560
+ return result?.data.space;
2561
+ }
2562
+ },
2563
+ {
2564
+ inputType: CollectionType.typename,
2565
+ outputType: DIRECTORY_TYPE,
2566
+ serialize: (node) => ({
2567
+ name: node.data.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed collection label"],
2568
+ data: node.data.name ?? translations_default[0]["en-US"][SPACE_PLUGIN]["unnamed collection label"],
2569
+ type: DIRECTORY_TYPE
2570
+ }),
2571
+ deserialize: async (data, ancestors) => {
2572
+ const space = ancestors.find(isSpace2);
2573
+ const collection = ancestors.findLast((ancestor) => ancestor instanceof CollectionType) ?? space?.properties[CollectionType.typename];
2574
+ if (!space || !collection) {
2575
+ return;
2576
+ }
2577
+ const result = await dispatch({
2578
+ plugin: SPACE_PLUGIN,
2579
+ action: SpaceAction.ADD_OBJECT,
2580
+ data: {
2581
+ target: collection,
2582
+ object: create2(CollectionType, {
2583
+ name: data.name,
2584
+ objects: [],
2585
+ views: {}
2586
+ })
2587
+ }
2588
+ });
2589
+ return result?.data.object;
2590
+ }
2591
+ }
2592
+ ];
2593
+ }
2594
+ },
2595
+ intent: {
2596
+ resolver: async (intent, plugins) => {
2597
+ const clientPlugin2 = resolvePlugin(plugins, parseClientPlugin);
2598
+ const client = clientPlugin2?.provides.client;
2599
+ switch (intent.action) {
2600
+ case SpaceAction.WAIT_FOR_OBJECT: {
2601
+ state.values.awaiting = intent.data?.id;
2602
+ return {
2603
+ data: true
2604
+ };
2605
+ }
2606
+ case SpaceAction.CREATE: {
2607
+ if (!client) {
2608
+ return;
2609
+ }
2610
+ const space = await client.spaces.create(intent.data);
2611
+ await space.waitUntilReady();
2612
+ const collection = create2(CollectionType, {
2613
+ objects: [],
2614
+ views: {}
2615
+ });
2616
+ space.properties[CollectionType.typename] = collection;
2617
+ if (Migrations2.versionProperty) {
2618
+ space.properties[Migrations2.versionProperty] = Migrations2.targetVersion;
2619
+ }
2620
+ return {
2621
+ data: {
2622
+ space,
2623
+ id: space.id,
2624
+ activeParts: {
2625
+ main: [
2626
+ space.id
2627
+ ]
2628
+ }
2629
+ },
2630
+ intents: [
2631
+ ...settings.values.onSpaceCreate ? [
2632
+ [
2633
+ {
2634
+ action: settings.values.onSpaceCreate,
2635
+ data: {
2636
+ space
2637
+ }
2638
+ },
2639
+ {
2640
+ action: SpaceAction.ADD_OBJECT,
2641
+ data: {
2642
+ target: space
2643
+ }
2644
+ },
2645
+ {
2646
+ action: NavigationAction3.EXPOSE
2647
+ }
2648
+ ]
2649
+ ] : [],
2650
+ [
2651
+ {
2652
+ action: ObservabilityAction.SEND_EVENT,
2653
+ data: {
2654
+ name: "space.create",
2655
+ properties: {
2656
+ spaceId: space.id
2657
+ }
2658
+ }
2659
+ }
2660
+ ]
2661
+ ]
2662
+ };
2663
+ }
2664
+ case SpaceAction.JOIN: {
2665
+ if (client) {
2666
+ const { space } = await client.shell.joinSpace({
2667
+ invitationCode: intent.data?.invitationCode
2668
+ });
2669
+ if (space) {
2670
+ return {
2671
+ data: {
2672
+ space,
2673
+ id: space.id,
2674
+ activeParts: {
2675
+ main: [
2676
+ space.id
2677
+ ]
2678
+ }
2679
+ },
2680
+ intents: [
2681
+ [
2682
+ {
2683
+ action: LayoutAction2.SET_LAYOUT,
2684
+ data: {
2685
+ element: "toast",
2686
+ subject: {
2687
+ id: `${SPACE_PLUGIN}/join-success`,
2688
+ duration: 1e4,
2689
+ title: translations_default[0]["en-US"][SPACE_PLUGIN]["join success label"],
2690
+ closeLabel: translations_default[0]["en-US"][SPACE_PLUGIN]["dismiss label"]
2691
+ }
2692
+ }
2693
+ }
2694
+ ],
2695
+ [
2696
+ {
2697
+ action: ObservabilityAction.SEND_EVENT,
2698
+ data: {
2699
+ name: "space.join",
2700
+ properties: {
2701
+ spaceId: space.id
2702
+ }
2703
+ }
2704
+ }
2705
+ ]
2706
+ ]
2707
+ };
2708
+ }
2709
+ }
2710
+ break;
2711
+ }
2712
+ case SpaceAction.SHARE: {
2713
+ const spaceId = intent.data?.spaceId;
2714
+ if (clientPlugin2 && typeof spaceId === "string") {
2715
+ if (!navigationPlugin?.provides.location.active) {
2716
+ return;
2717
+ }
2718
+ const target = firstIdInPart(navigationPlugin?.provides.location.active, "main");
2719
+ const result = await clientPlugin2.provides.client.shell.shareSpace({
2720
+ spaceId,
2721
+ target
2722
+ });
2723
+ return {
2724
+ data: result,
2725
+ intents: [
2726
+ [
2727
+ {
2728
+ action: ObservabilityAction.SEND_EVENT,
2729
+ data: {
2730
+ name: "space.share",
2731
+ properties: {
2732
+ spaceId,
2733
+ members: result.members?.length,
2734
+ error: result.error?.message,
2735
+ cancelled: result.cancelled
2736
+ }
2737
+ }
2738
+ }
2739
+ ]
2740
+ ]
2741
+ };
2742
+ }
2743
+ break;
2744
+ }
2745
+ case SpaceAction.LOCK: {
2746
+ const space = intent.data?.space;
2747
+ if (isSpace2(space)) {
2748
+ space.properties[COMPOSER_SPACE_LOCK] = true;
2749
+ return {
2750
+ data: true,
2751
+ intents: [
2752
+ [
2753
+ {
2754
+ action: ObservabilityAction.SEND_EVENT,
2755
+ data: {
2756
+ name: "space.lock",
2757
+ properties: {
2758
+ spaceId: space.id
2759
+ }
2760
+ }
2761
+ }
2762
+ ]
2763
+ ]
2764
+ };
2765
+ }
2766
+ break;
2767
+ }
2768
+ case SpaceAction.UNLOCK: {
2769
+ const space = intent.data?.space;
2770
+ if (isSpace2(space)) {
2771
+ space.properties[COMPOSER_SPACE_LOCK] = false;
2772
+ return {
2773
+ data: true,
2774
+ intents: [
2775
+ [
2776
+ {
2777
+ action: ObservabilityAction.SEND_EVENT,
2778
+ data: {
2779
+ name: "space.unlock",
2780
+ properties: {
2781
+ spaceId: space.id
2782
+ }
2783
+ }
2784
+ }
2785
+ ]
2786
+ ]
2787
+ };
2788
+ }
2789
+ break;
2790
+ }
2791
+ case SpaceAction.RENAME: {
2792
+ const { caller, space } = intent.data ?? {};
2793
+ if (typeof caller === "string" && isSpace2(space)) {
2794
+ return {
2795
+ intents: [
2796
+ [
2797
+ {
2798
+ action: LayoutAction2.SET_LAYOUT,
2799
+ data: {
2800
+ element: "popover",
2801
+ anchorId: `dxos.org/ui/${caller}/${space.id}`,
2802
+ component: "dxos.org/plugin/space/RenameSpacePopover",
2803
+ subject: space
2804
+ }
2805
+ }
2806
+ ]
2807
+ ]
2808
+ };
2809
+ }
2810
+ break;
2811
+ }
2812
+ case SpaceAction.OPEN: {
2813
+ const space = intent.data?.space;
2814
+ if (isSpace2(space)) {
2815
+ await space.open();
2816
+ return {
2817
+ data: true
2818
+ };
2819
+ }
2820
+ break;
2821
+ }
2822
+ case SpaceAction.CLOSE: {
2823
+ const space = intent.data?.space;
2824
+ if (isSpace2(space)) {
2825
+ await space.close();
2826
+ return {
2827
+ data: true
2828
+ };
2829
+ }
2830
+ break;
2831
+ }
2832
+ case SpaceAction.MIGRATE: {
2833
+ const space = intent.data?.space;
2834
+ if (isSpace2(space)) {
2835
+ if (space.state.get() === SpaceState3.SPACE_REQUIRES_MIGRATION) {
2836
+ state.values.sdkMigrationRunning[space.id] = true;
2837
+ await space.internal.migrate();
2838
+ state.values.sdkMigrationRunning[space.id] = false;
2839
+ }
2840
+ const result = await Migrations2.migrate(space, intent.data?.version);
2841
+ return {
2842
+ data: result,
2843
+ intents: [
2844
+ [
2845
+ {
2846
+ action: ObservabilityAction.SEND_EVENT,
2847
+ data: {
2848
+ name: "space.migrate",
2849
+ properties: {
2850
+ spaceId: space.id,
2851
+ version: intent.data?.version
2852
+ }
2853
+ }
2854
+ }
2855
+ ]
2856
+ ]
2857
+ };
2858
+ }
2859
+ break;
2860
+ }
2861
+ case SpaceAction.ADD_OBJECT: {
2862
+ const object = intent.data?.object ?? intent.data?.result;
2863
+ if (!isReactiveObject2(object)) {
2864
+ return;
2865
+ }
2866
+ const space = isSpace2(intent.data?.target) ? intent.data?.target : getSpace4(intent.data?.target);
2867
+ if (!space) {
2868
+ return;
2869
+ }
2870
+ if (space.db.coreDatabase.getAllObjectIds().length >= SPACE_MAX_OBJECTS) {
2871
+ return {
2872
+ data: false,
2873
+ intents: [
2874
+ [
2875
+ {
2876
+ action: LayoutAction2.SET_LAYOUT,
2877
+ data: {
2878
+ element: "toast",
2879
+ subject: {
2880
+ id: `${SPACE_PLUGIN}/space-limit`,
2881
+ title: translations_default[0]["en-US"][SPACE_PLUGIN]["space limit label"],
2882
+ description: translations_default[0]["en-US"][SPACE_PLUGIN]["space limit description"],
2883
+ duration: 5e3,
2884
+ icon: "ph--warning--regular",
2885
+ actionLabel: translations_default[0]["en-US"][SPACE_PLUGIN]["remove deleted objects label"],
2886
+ actionAlt: translations_default[0]["en-US"][SPACE_PLUGIN]["remove deleted objects alt"],
2887
+ // TODO(wittjosiah): Use OS namespace.
2888
+ closeLabel: translations_default[0]["en-US"][SPACE_PLUGIN]["space limit close label"],
2889
+ onAction: () => space.db.coreDatabase.unlinkDeletedObjects()
2890
+ }
2891
+ }
2892
+ }
2893
+ ],
2894
+ [
2895
+ {
2896
+ action: ObservabilityAction.SEND_EVENT,
2897
+ data: {
2898
+ name: "space.limit",
2899
+ properties: {
2900
+ spaceId: space.id
2901
+ }
2902
+ }
2903
+ }
2904
+ ]
2905
+ ]
2906
+ };
2907
+ }
2908
+ if (intent.data?.target instanceof CollectionType) {
2909
+ intent.data?.target.objects.push(object);
2910
+ } else if (isSpace2(intent.data?.target)) {
2911
+ const collection = space.properties[CollectionType.typename];
2912
+ if (collection instanceof CollectionType) {
2913
+ collection.objects.push(object);
2914
+ } else {
2915
+ const collection2 = create2(CollectionType, {
2916
+ objects: [
2917
+ object
2918
+ ],
2919
+ views: {}
2920
+ });
2921
+ space.properties[CollectionType.typename] = collection2;
2922
+ }
2923
+ }
2924
+ return {
2925
+ data: {
2926
+ id: fullyQualifiedId4(object),
2927
+ object,
2928
+ activeParts: {
2929
+ main: [
2930
+ fullyQualifiedId4(object)
2931
+ ]
2932
+ }
2933
+ },
2934
+ intents: [
2935
+ [
2936
+ {
2937
+ action: ObservabilityAction.SEND_EVENT,
2938
+ data: {
2939
+ name: "space.object.add",
2940
+ properties: {
2941
+ spaceId: space.id,
2942
+ objectId: object.id,
2943
+ typename: getTypename2(object)
2944
+ }
2945
+ }
2946
+ }
2947
+ ]
2948
+ ]
2949
+ };
2950
+ }
2951
+ case SpaceAction.REMOVE_OBJECT: {
2952
+ const object = intent.data?.object ?? intent.data?.result;
2953
+ const space = getSpace4(object);
2954
+ if (!(isEchoObject2(object) && space)) {
2955
+ return;
2956
+ }
2957
+ const resolve = resolvePlugin(plugins, parseMetadataResolverPlugin)?.provides.metadata.resolver;
2958
+ const activeParts = navigationPlugin?.provides.location.active;
2959
+ const openObjectIds = new Set(openIds(activeParts ?? {}));
2960
+ if (!intent.undo && resolve) {
2961
+ const parentCollection = intent.data?.collection ?? space.properties[CollectionType.typename];
2962
+ const nestedObjects = await getNestedObjects(object, resolve);
2963
+ const deletionData = {
2964
+ object,
2965
+ parentCollection,
2966
+ index: parentCollection instanceof CollectionType ? parentCollection.objects.indexOf(object) : -1,
2967
+ nestedObjects,
2968
+ wasActive: [
2969
+ object,
2970
+ ...nestedObjects
2971
+ ].map((obj) => fullyQualifiedId4(obj)).filter((id) => openObjectIds.has(id))
2972
+ };
2973
+ if (deletionData.wasActive.length > 0) {
2974
+ await intentPlugin?.provides.intent.dispatch({
2975
+ action: NavigationAction3.CLOSE,
2976
+ data: {
2977
+ activeParts: {
2978
+ main: deletionData.wasActive,
2979
+ sidebar: deletionData.wasActive
2980
+ }
2981
+ }
2982
+ });
2983
+ }
2984
+ if (parentCollection instanceof CollectionType) {
2985
+ const index = parentCollection.objects.indexOf(object);
2986
+ if (index !== -1) {
2987
+ parentCollection.objects.splice(index, 1);
2988
+ }
2989
+ }
2990
+ deletionData.nestedObjects.forEach((obj) => {
2991
+ space.db.remove(obj);
2992
+ });
2993
+ space.db.remove(object);
2994
+ const undoMessageKey = object instanceof CollectionType ? "collection deleted label" : "object deleted label";
2995
+ return {
2996
+ data: true,
2997
+ undoable: {
2998
+ // Consider using a translation key here.
2999
+ message: translations_default[0]["en-US"][SPACE_PLUGIN][undoMessageKey],
3000
+ data: deletionData
3001
+ }
3002
+ };
3003
+ } else {
3004
+ const undoData = intent.data;
3005
+ if (undoData && isEchoObject2(undoData.object) && undoData.parentCollection instanceof CollectionType) {
3006
+ const restoredObject = space.db.add(undoData.object);
3007
+ undoData.nestedObjects.forEach((obj) => {
3008
+ space.db.add(obj);
3009
+ });
3010
+ if (undoData.index !== -1) {
3011
+ undoData.parentCollection.objects.splice(undoData.index, 0, restoredObject);
3012
+ }
3013
+ if (undoData.wasActive.length > 0) {
3014
+ await intentPlugin?.provides.intent.dispatch({
3015
+ action: NavigationAction3.OPEN,
3016
+ data: {
3017
+ activeParts: {
3018
+ main: undoData.wasActive
3019
+ }
3020
+ }
3021
+ });
3022
+ }
3023
+ return {
3024
+ data: true
3025
+ };
3026
+ }
3027
+ return {
3028
+ data: false
3029
+ };
3030
+ }
3031
+ }
3032
+ case SpaceAction.RENAME_OBJECT: {
3033
+ const object = intent.data?.object ?? intent.data?.result;
3034
+ const caller = intent.data?.caller;
3035
+ if (isReactiveObject2(object) && caller) {
3036
+ return {
3037
+ intents: [
3038
+ [
3039
+ {
3040
+ action: LayoutAction2.SET_LAYOUT,
3041
+ data: {
3042
+ element: "popover",
3043
+ anchorId: `dxos.org/ui/${caller}/${fullyQualifiedId4(object)}`,
3044
+ component: "dxos.org/plugin/space/RenameObjectPopover",
3045
+ subject: object
3046
+ }
3047
+ }
3048
+ ]
3049
+ ]
3050
+ };
3051
+ }
3052
+ break;
3053
+ }
3054
+ case SpaceAction.DUPLICATE_OBJECT: {
3055
+ const originalObject = intent.data?.object ?? intent.data?.result;
3056
+ const resolve = resolvePlugin(plugins, parseMetadataResolverPlugin)?.provides.metadata.resolver;
3057
+ const space = isSpace2(intent.data?.target) ? intent.data?.target : getSpace4(intent.data?.target);
3058
+ if (!isEchoObject2(originalObject) || !resolve || !space) {
3059
+ return;
3060
+ }
3061
+ const newObject = await cloneObject(originalObject, resolve, space);
3062
+ return {
3063
+ intents: [
3064
+ [
3065
+ {
3066
+ action: SpaceAction.ADD_OBJECT,
3067
+ data: {
3068
+ object: newObject,
3069
+ target: intent.data?.target
3070
+ }
3071
+ }
3072
+ ]
3073
+ ]
3074
+ };
3075
+ }
3076
+ case SpaceAction.TOGGLE_HIDDEN: {
3077
+ settings.values.showHidden = intent.data?.state ?? !settings.values.showHidden;
3078
+ return {
3079
+ data: true
3080
+ };
3081
+ }
3082
+ }
3083
+ }
3084
+ }
3085
+ }
3086
+ };
3087
+ };
3088
+
3089
+ // packages/plugins/plugin-space/src/index.ts
3090
+ var src_default = SpacePlugin;
3091
+ export {
3092
+ ActorSchema,
3093
+ AwaitingObject,
3094
+ COMPOSER_SPACE_LOCK,
3095
+ ChannelType,
3096
+ CollectionMain,
3097
+ CollectionSection,
3098
+ CollectionType,
3099
+ ContactType,
3100
+ DefaultObjectSettings,
3101
+ FullPresence,
3102
+ MenuFooter,
3103
+ MessageState,
3104
+ MessageType,
3105
+ PersistenceStatus,
3106
+ PopoverRenameObject,
3107
+ PopoverRenameSpace,
3108
+ SHARED,
3109
+ SPACES,
3110
+ SPACE_DIRECTORY_HANDLE,
3111
+ SPACE_PLUGIN,
3112
+ SPACE_PLUGIN_SHORT_ID,
3113
+ SPACE_TYPE,
3114
+ ShareSpaceButton,
3115
+ ShareSpaceButtonImpl,
3116
+ SmallPresence,
3117
+ SmallPresenceLive,
3118
+ SpaceAction,
3119
+ SpaceMain,
3120
+ SpacePlugin,
3121
+ SpacePresence,
3122
+ SpaceSettings,
3123
+ SpaceSettingsPanel,
3124
+ SyncStatus,
3125
+ SyncStatusDetail,
3126
+ SyncStatusIndicator,
3127
+ ThreadStatus,
3128
+ ThreadType,
3129
+ cloneObject,
3130
+ constructObjectActionGroups,
3131
+ constructObjectActions,
3132
+ constructSpaceActionGroups,
3133
+ constructSpaceActions,
3134
+ constructSpaceNode,
3135
+ createObjectNode,
3136
+ src_default as default,
3137
+ getActiveSpace,
3138
+ getNestedObjects,
3139
+ getSpaceDisplayName,
3140
+ memoizeQuery,
3141
+ parseSpaceInitPlugin,
3142
+ parseSpacePlugin,
3143
+ translations_default as translations
3144
+ };
3145
+ //# sourceMappingURL=index.mjs.map