@dxos/plugin-space 0.7.4 → 0.7.5-labs.071a3e2

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 (257) hide show
  1. package/dist/lib/browser/app-graph-builder-TTM2YZVS.mjs +367 -0
  2. package/dist/lib/browser/app-graph-builder-TTM2YZVS.mjs.map +7 -0
  3. package/dist/lib/browser/app-graph-serializer-ZGM5NDXE.mjs +80 -0
  4. package/dist/lib/browser/app-graph-serializer-ZGM5NDXE.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-2NMUVDMZ.mjs +1715 -0
  6. package/dist/lib/browser/chunk-2NMUVDMZ.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-ENRYFGYE.mjs +133 -0
  8. package/dist/lib/browser/chunk-ENRYFGYE.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-H2AR4OLP.mjs +316 -0
  10. package/dist/lib/browser/chunk-H2AR4OLP.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-PQXZCNAU.mjs +13 -0
  12. package/dist/lib/browser/chunk-PQXZCNAU.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-RLZQJD47.mjs +22 -0
  14. package/dist/lib/browser/chunk-RLZQJD47.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-S5IGZNXJ.mjs +528 -0
  16. package/dist/lib/browser/chunk-S5IGZNXJ.mjs.map +7 -0
  17. package/dist/lib/browser/identity-created-VICTPQX7.mjs +28 -0
  18. package/dist/lib/browser/identity-created-VICTPQX7.mjs.map +7 -0
  19. package/dist/lib/browser/index.mjs +193 -3521
  20. package/dist/lib/browser/index.mjs.map +4 -4
  21. package/dist/lib/browser/intent-resolver-A5274MUR.mjs +537 -0
  22. package/dist/lib/browser/intent-resolver-A5274MUR.mjs.map +7 -0
  23. package/dist/lib/browser/meta.json +1 -1
  24. package/dist/lib/browser/react-root-N6QTWYCV.mjs +28 -0
  25. package/dist/lib/browser/react-root-N6QTWYCV.mjs.map +7 -0
  26. package/dist/lib/browser/react-surface-STMNA7W7.mjs +231 -0
  27. package/dist/lib/browser/react-surface-STMNA7W7.mjs.map +7 -0
  28. package/dist/lib/browser/settings-HN5UIYQO.mjs +24 -0
  29. package/dist/lib/browser/settings-HN5UIYQO.mjs.map +7 -0
  30. package/dist/lib/browser/spaces-ready-F57ITJDR.mjs +199 -0
  31. package/dist/lib/browser/spaces-ready-F57ITJDR.mjs.map +7 -0
  32. package/dist/lib/browser/state-6DCY5YJP.mjs +47 -0
  33. package/dist/lib/browser/state-6DCY5YJP.mjs.map +7 -0
  34. package/dist/lib/browser/types/index.mjs +14 -5
  35. package/dist/lib/node/app-graph-builder-6N4TEVHH.cjs +370 -0
  36. package/dist/lib/node/app-graph-builder-6N4TEVHH.cjs.map +7 -0
  37. package/dist/lib/node/app-graph-serializer-AWKVTYAB.cjs +88 -0
  38. package/dist/lib/node/app-graph-serializer-AWKVTYAB.cjs.map +7 -0
  39. package/dist/lib/node/chunk-2RCJT3P2.cjs +1712 -0
  40. package/dist/lib/node/chunk-2RCJT3P2.cjs.map +7 -0
  41. package/dist/lib/node/chunk-I2LRRRMV.cjs +150 -0
  42. package/dist/lib/node/chunk-I2LRRRMV.cjs.map +7 -0
  43. package/dist/lib/node/chunk-MMXP2NHE.cjs +556 -0
  44. package/dist/lib/node/chunk-MMXP2NHE.cjs.map +7 -0
  45. package/dist/lib/node/chunk-SPCSJ2CY.cjs +345 -0
  46. package/dist/lib/node/chunk-SPCSJ2CY.cjs.map +7 -0
  47. package/dist/lib/node/chunk-UX3U4RU2.cjs +42 -0
  48. package/dist/lib/node/chunk-UX3U4RU2.cjs.map +7 -0
  49. package/dist/lib/node/{meta.cjs → chunk-WZR6OAN3.cjs} +13 -13
  50. package/dist/lib/node/chunk-WZR6OAN3.cjs.map +7 -0
  51. package/dist/lib/node/identity-created-JNDKMFKI.cjs +44 -0
  52. package/dist/lib/node/identity-created-JNDKMFKI.cjs.map +7 -0
  53. package/dist/lib/node/index.cjs +176 -3506
  54. package/dist/lib/node/index.cjs.map +4 -4
  55. package/dist/lib/node/intent-resolver-NVTAESKB.cjs +536 -0
  56. package/dist/lib/node/intent-resolver-NVTAESKB.cjs.map +7 -0
  57. package/dist/lib/node/meta.json +1 -1
  58. package/dist/lib/node/react-root-YCHSAYQE.cjs +50 -0
  59. package/dist/lib/node/react-root-YCHSAYQE.cjs.map +7 -0
  60. package/dist/lib/node/react-surface-ANSZ4FKK.cjs +229 -0
  61. package/dist/lib/node/react-surface-ANSZ4FKK.cjs.map +7 -0
  62. package/dist/lib/node/settings-RBBL22DJ.cjs +38 -0
  63. package/dist/lib/node/settings-RBBL22DJ.cjs.map +7 -0
  64. package/dist/lib/node/spaces-ready-WHU4J6E5.cjs +210 -0
  65. package/dist/lib/node/spaces-ready-WHU4J6E5.cjs.map +7 -0
  66. package/dist/lib/node/state-WPZC4JXB.cjs +61 -0
  67. package/dist/lib/node/state-WPZC4JXB.cjs.map +7 -0
  68. package/dist/lib/node/types/index.cjs +23 -14
  69. package/dist/lib/node/types/index.cjs.map +2 -2
  70. package/dist/lib/node-esm/app-graph-builder-MS6BI5EW.mjs +368 -0
  71. package/dist/lib/node-esm/app-graph-builder-MS6BI5EW.mjs.map +7 -0
  72. package/dist/lib/node-esm/app-graph-serializer-AWAWDSCM.mjs +81 -0
  73. package/dist/lib/node-esm/app-graph-serializer-AWAWDSCM.mjs.map +7 -0
  74. package/dist/lib/node-esm/chunk-4HICD7AU.mjs +1716 -0
  75. package/dist/lib/node-esm/chunk-4HICD7AU.mjs.map +7 -0
  76. package/dist/lib/node-esm/chunk-77RE7Y5J.mjs +529 -0
  77. package/dist/lib/node-esm/chunk-77RE7Y5J.mjs.map +7 -0
  78. package/dist/lib/node-esm/chunk-ESWV7ICX.mjs +134 -0
  79. package/dist/lib/node-esm/chunk-ESWV7ICX.mjs.map +7 -0
  80. package/dist/lib/node-esm/chunk-ICCM4YRJ.mjs +15 -0
  81. package/dist/lib/node-esm/chunk-ICCM4YRJ.mjs.map +7 -0
  82. package/dist/lib/node-esm/chunk-LGL4A5B5.mjs +23 -0
  83. package/dist/lib/node-esm/chunk-LGL4A5B5.mjs.map +7 -0
  84. package/dist/lib/node-esm/chunk-S6VAU6VJ.mjs +317 -0
  85. package/dist/lib/node-esm/chunk-S6VAU6VJ.mjs.map +7 -0
  86. package/dist/lib/node-esm/identity-created-3AUSSVEK.mjs +29 -0
  87. package/dist/lib/node-esm/identity-created-3AUSSVEK.mjs.map +7 -0
  88. package/dist/lib/node-esm/index.mjs +193 -3521
  89. package/dist/lib/node-esm/index.mjs.map +4 -4
  90. package/dist/lib/node-esm/intent-resolver-KJ67TU34.mjs +538 -0
  91. package/dist/lib/node-esm/intent-resolver-KJ67TU34.mjs.map +7 -0
  92. package/dist/lib/node-esm/meta.json +1 -1
  93. package/dist/lib/node-esm/react-root-NBQQKAZD.mjs +29 -0
  94. package/dist/lib/node-esm/react-root-NBQQKAZD.mjs.map +7 -0
  95. package/dist/lib/node-esm/react-surface-G2H5T2D2.mjs +232 -0
  96. package/dist/lib/node-esm/react-surface-G2H5T2D2.mjs.map +7 -0
  97. package/dist/lib/node-esm/settings-VBAUB37B.mjs +25 -0
  98. package/dist/lib/node-esm/settings-VBAUB37B.mjs.map +7 -0
  99. package/dist/lib/node-esm/spaces-ready-ABADUX2P.mjs +200 -0
  100. package/dist/lib/node-esm/spaces-ready-ABADUX2P.mjs.map +7 -0
  101. package/dist/lib/node-esm/state-5GH2D5U4.mjs +48 -0
  102. package/dist/lib/node-esm/state-5GH2D5U4.mjs.map +7 -0
  103. package/dist/lib/node-esm/types/index.mjs +14 -5
  104. package/dist/types/src/SpacePlugin.d.ts +3 -22
  105. package/dist/types/src/SpacePlugin.d.ts.map +1 -1
  106. package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
  107. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
  108. package/dist/types/src/capabilities/app-graph-serializer.d.ts +4 -0
  109. package/dist/types/src/capabilities/app-graph-serializer.d.ts.map +1 -0
  110. package/dist/types/src/capabilities/capabilities.d.ts +21 -0
  111. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  112. package/dist/types/src/capabilities/identity-created.d.ts +4 -0
  113. package/dist/types/src/capabilities/identity-created.d.ts.map +1 -0
  114. package/dist/types/src/capabilities/index.d.ts +196 -0
  115. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  116. package/dist/types/src/capabilities/intent-resolver.d.ts +9 -0
  117. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
  118. package/dist/types/src/capabilities/react-root.d.ts +7 -0
  119. package/dist/types/src/capabilities/react-root.d.ts.map +1 -0
  120. package/dist/types/src/capabilities/react-surface.d.ts +7 -0
  121. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  122. package/dist/types/src/capabilities/settings.d.ts +4 -0
  123. package/dist/types/src/capabilities/settings.d.ts.map +1 -0
  124. package/dist/types/src/capabilities/spaces-ready.d.ts +4 -0
  125. package/dist/types/src/capabilities/spaces-ready.d.ts.map +1 -0
  126. package/dist/types/src/capabilities/state.d.ts +5 -0
  127. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  128. package/dist/types/src/components/AdvancedObjectSettings/AdvancedObjectSettings.d.ts +7 -0
  129. package/dist/types/src/components/AdvancedObjectSettings/AdvancedObjectSettings.d.ts.map +1 -0
  130. package/dist/types/src/components/AdvancedObjectSettings/ForeignKeys.d.ts +8 -0
  131. package/dist/types/src/components/AdvancedObjectSettings/ForeignKeys.d.ts.map +1 -0
  132. package/dist/types/src/components/AdvancedObjectSettings/index.d.ts +2 -0
  133. package/dist/types/src/components/AdvancedObjectSettings/index.d.ts.map +1 -0
  134. package/dist/types/src/components/AwaitingObject.d.ts.map +1 -1
  135. package/dist/types/src/components/BaseObjectSettings.d.ts +7 -0
  136. package/dist/types/src/components/BaseObjectSettings.d.ts.map +1 -0
  137. package/dist/types/src/components/CreateDialog/CreateObjectDialog.d.ts +5 -4
  138. package/dist/types/src/components/CreateDialog/CreateObjectDialog.d.ts.map +1 -1
  139. package/dist/types/src/components/CreateDialog/CreateObjectPanel.d.ts +9 -9
  140. package/dist/types/src/components/CreateDialog/CreateObjectPanel.d.ts.map +1 -1
  141. package/dist/types/src/components/CreateDialog/CreateSpaceDialog.d.ts +1 -0
  142. package/dist/types/src/components/CreateDialog/CreateSpaceDialog.d.ts.map +1 -1
  143. package/dist/types/src/components/JoinDialog.d.ts +1 -0
  144. package/dist/types/src/components/JoinDialog.d.ts.map +1 -1
  145. package/dist/types/src/components/PopoverRenameObject.d.ts +1 -0
  146. package/dist/types/src/components/PopoverRenameObject.d.ts.map +1 -1
  147. package/dist/types/src/components/PopoverRenameSpace.d.ts +1 -0
  148. package/dist/types/src/components/PopoverRenameSpace.d.ts.map +1 -1
  149. package/dist/types/src/components/ShareSpaceButton.d.ts.map +1 -1
  150. package/dist/types/src/components/SpacePluginSettings.d.ts.map +1 -1
  151. package/dist/types/src/components/SpacePresence.d.ts +9 -6
  152. package/dist/types/src/components/SpacePresence.d.ts.map +1 -1
  153. package/dist/types/src/components/SpacePresence.stories.d.ts +1 -1
  154. package/dist/types/src/components/SpacePresence.stories.d.ts.map +1 -1
  155. package/dist/types/src/components/SpaceSettings/SpaceSettingsDialog.d.ts +1 -0
  156. package/dist/types/src/components/SpaceSettings/SpaceSettingsDialog.d.ts.map +1 -1
  157. package/dist/types/src/components/SpaceSettings/SpaceSettingsDialog.stories.d.ts.map +1 -1
  158. package/dist/types/src/components/SpaceSettings/SpaceSettingsPanel.d.ts +4 -3
  159. package/dist/types/src/components/SpaceSettings/SpaceSettingsPanel.d.ts.map +1 -1
  160. package/dist/types/src/components/SpaceSettings/SpaceSettingsPanel.stories.d.ts.map +1 -1
  161. package/dist/types/src/components/SyncStatus/InlineSyncStatus.d.ts +3 -3
  162. package/dist/types/src/components/SyncStatus/InlineSyncStatus.d.ts.map +1 -1
  163. package/dist/types/src/components/SyncStatus/SyncStatus.d.ts.map +1 -1
  164. package/dist/types/src/components/SyncStatus/SyncStatusDetail.stories.d.ts +2 -2
  165. package/dist/types/src/components/SyncStatus/SyncStatusDetail.stories.d.ts.map +1 -1
  166. package/dist/types/src/components/index.d.ts +2 -1
  167. package/dist/types/src/components/index.d.ts.map +1 -1
  168. package/dist/types/src/events.d.ts +5 -0
  169. package/dist/types/src/events.d.ts.map +1 -0
  170. package/dist/types/src/hooks/index.d.ts +2 -0
  171. package/dist/types/src/hooks/index.d.ts.map +1 -0
  172. package/dist/types/src/hooks/usePath.d.ts +11 -0
  173. package/dist/types/src/hooks/usePath.d.ts.map +1 -0
  174. package/dist/types/src/index.d.ts +3 -5
  175. package/dist/types/src/index.d.ts.map +1 -1
  176. package/dist/types/src/meta.d.ts +2 -27
  177. package/dist/types/src/meta.d.ts.map +1 -1
  178. package/dist/types/src/translations.d.ts +18 -3
  179. package/dist/types/src/translations.d.ts.map +1 -1
  180. package/dist/types/src/types/collection.d.ts +8 -12
  181. package/dist/types/src/types/collection.d.ts.map +1 -1
  182. package/dist/types/src/types/thread.d.ts +180 -186
  183. package/dist/types/src/types/thread.d.ts.map +1 -1
  184. package/dist/types/src/types/types.d.ts +228 -16
  185. package/dist/types/src/types/types.d.ts.map +1 -1
  186. package/dist/types/src/util.d.ts +9 -8
  187. package/dist/types/src/util.d.ts.map +1 -1
  188. package/dist/types/tsconfig.tsbuildinfo +1 -0
  189. package/package.json +39 -46
  190. package/src/SpacePlugin.tsx +121 -1538
  191. package/src/capabilities/app-graph-builder.ts +393 -0
  192. package/src/capabilities/app-graph-serializer.ts +73 -0
  193. package/src/capabilities/capabilities.ts +26 -0
  194. package/src/capabilities/identity-created.ts +26 -0
  195. package/src/capabilities/index.ts +17 -0
  196. package/src/capabilities/intent-resolver.ts +518 -0
  197. package/src/capabilities/react-root.tsx +20 -0
  198. package/src/capabilities/react-surface.tsx +226 -0
  199. package/src/capabilities/settings.ts +17 -0
  200. package/src/capabilities/spaces-ready.ts +230 -0
  201. package/src/capabilities/state.ts +45 -0
  202. package/src/components/AdvancedObjectSettings/AdvancedObjectSettings.tsx +72 -0
  203. package/src/components/AdvancedObjectSettings/ForeignKeys.tsx +51 -0
  204. package/src/components/AdvancedObjectSettings/index.ts +5 -0
  205. package/src/components/AwaitingObject.tsx +15 -19
  206. package/src/components/{DefaultObjectSettings.tsx → BaseObjectSettings.tsx} +2 -2
  207. package/src/components/CreateDialog/CreateObjectDialog.tsx +49 -38
  208. package/src/components/CreateDialog/CreateObjectPanel.tsx +137 -101
  209. package/src/components/CreateDialog/CreateSpaceDialog.tsx +22 -17
  210. package/src/components/JoinDialog.tsx +40 -48
  211. package/src/components/PersistenceStatus.tsx +1 -1
  212. package/src/components/PopoverRenameObject.tsx +2 -0
  213. package/src/components/PopoverRenameSpace.tsx +2 -0
  214. package/src/components/ShareSpaceButton.tsx +5 -4
  215. package/src/components/SpacePluginSettings.tsx +5 -16
  216. package/src/components/SpacePresence.stories.tsx +27 -19
  217. package/src/components/SpacePresence.tsx +41 -21
  218. package/src/components/SpaceSettings/SpaceSettingsDialog.stories.tsx +2 -3
  219. package/src/components/SpaceSettings/SpaceSettingsDialog.tsx +19 -2
  220. package/src/components/SpaceSettings/SpaceSettingsPanel.stories.tsx +7 -5
  221. package/src/components/SpaceSettings/SpaceSettingsPanel.tsx +7 -7
  222. package/src/components/SyncStatus/InlineSyncStatus.tsx +37 -27
  223. package/src/components/SyncStatus/SyncStatus.tsx +2 -1
  224. package/src/components/SyncStatus/SyncStatusDetail.stories.tsx +55 -51
  225. package/src/components/index.ts +2 -1
  226. package/src/events.ts +12 -0
  227. package/src/hooks/index.ts +5 -0
  228. package/src/hooks/usePath.ts +44 -0
  229. package/src/index.ts +3 -7
  230. package/src/meta.ts +2 -29
  231. package/src/translations.ts +7 -2
  232. package/src/types/collection.ts +3 -3
  233. package/src/types/thread.ts +6 -6
  234. package/src/types/types.ts +177 -42
  235. package/src/util.tsx +82 -65
  236. package/dist/lib/browser/chunk-FTKV32QZ.mjs +0 -43
  237. package/dist/lib/browser/chunk-FTKV32QZ.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-MWKXNS5S.mjs +0 -124
  239. package/dist/lib/browser/chunk-MWKXNS5S.mjs.map +0 -7
  240. package/dist/lib/browser/meta.mjs +0 -15
  241. package/dist/lib/browser/meta.mjs.map +0 -7
  242. package/dist/lib/node/chunk-6SNOZF7Y.cjs +0 -152
  243. package/dist/lib/node/chunk-6SNOZF7Y.cjs.map +0 -7
  244. package/dist/lib/node/chunk-QNVEU2UD.cjs +0 -69
  245. package/dist/lib/node/chunk-QNVEU2UD.cjs.map +0 -7
  246. package/dist/lib/node/meta.cjs.map +0 -7
  247. package/dist/lib/node-esm/chunk-OHEAWSCA.mjs +0 -126
  248. package/dist/lib/node-esm/chunk-OHEAWSCA.mjs.map +0 -7
  249. package/dist/lib/node-esm/chunk-UMV7XREB.mjs +0 -45
  250. package/dist/lib/node-esm/chunk-UMV7XREB.mjs.map +0 -7
  251. package/dist/lib/node-esm/meta.mjs +0 -16
  252. package/dist/lib/node-esm/meta.mjs.map +0 -7
  253. package/dist/types/src/components/DefaultObjectSettings.d.ts +0 -7
  254. package/dist/types/src/components/DefaultObjectSettings.d.ts.map +0 -1
  255. package/dist/types/src/components/SyncStatus/InlineSyncStatus.stories.d.ts +0 -6
  256. package/dist/types/src/components/SyncStatus/InlineSyncStatus.stories.d.ts.map +0 -1
  257. package/src/components/SyncStatus/InlineSyncStatus.stories.tsx +0 -57
@@ -0,0 +1,1716 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ SpaceCapabilities
4
+ } from "./chunk-LGL4A5B5.mjs";
5
+ import {
6
+ COMPOSER_SPACE_LOCK,
7
+ getSpaceDisplayName
8
+ } from "./chunk-77RE7Y5J.mjs";
9
+ import {
10
+ CollectionType,
11
+ SpaceAction,
12
+ SpaceForm
13
+ } from "./chunk-S6VAU6VJ.mjs";
14
+ import {
15
+ SPACE_PLUGIN
16
+ } from "./chunk-ICCM4YRJ.mjs";
17
+
18
+ // packages/plugins/plugin-space/src/components/AdvancedObjectSettings/AdvancedObjectSettings.tsx
19
+ import React2, { useCallback as useCallback2, useState } from "react";
20
+ import { ForeignKeySchema } from "@dxos/echo-schema";
21
+ import { getMeta } from "@dxos/react-client/echo";
22
+ import { IconButton as IconButton2, useTranslation as useTranslation2, Separator } from "@dxos/react-ui";
23
+ import { Form } from "@dxos/react-ui-form";
24
+
25
+ // packages/plugins/plugin-space/src/components/AdvancedObjectSettings/ForeignKeys.tsx
26
+ import React, { useCallback } from "react";
27
+ import { IconButton, List, ListItem, useTranslation } from "@dxos/react-ui";
28
+ var ForeignKeys = ({ keys, onDelete }) => {
29
+ return /* @__PURE__ */ React.createElement(List, {
30
+ classNames: "flex flex-col gap-2"
31
+ }, keys.map((key) => /* @__PURE__ */ React.createElement(KeyItem, {
32
+ key: key.id,
33
+ forignKey: key,
34
+ onDelete
35
+ })));
36
+ };
37
+ var KeyItem = ({ forignKey, onDelete }) => {
38
+ const { t } = useTranslation(SPACE_PLUGIN);
39
+ const handleDelete = useCallback(() => {
40
+ onDelete?.(forignKey);
41
+ }, [
42
+ forignKey,
43
+ onDelete
44
+ ]);
45
+ return /* @__PURE__ */ React.createElement(ListItem.Root, {
46
+ classNames: "px-2"
47
+ }, /* @__PURE__ */ React.createElement(ListItem.Heading, {
48
+ classNames: "flex flex-col grow truncate"
49
+ }, /* @__PURE__ */ React.createElement("div", null, forignKey.source), /* @__PURE__ */ React.createElement("div", {
50
+ className: "text-description text-sm truncate"
51
+ }, forignKey.id)), /* @__PURE__ */ React.createElement(ListItem.Endcap, null, /* @__PURE__ */ React.createElement(IconButton, {
52
+ iconOnly: true,
53
+ icon: "ph--x--regular",
54
+ variant: "ghost",
55
+ label: t("delete key"),
56
+ onClick: handleDelete
57
+ })));
58
+ };
59
+
60
+ // packages/plugins/plugin-space/src/components/AdvancedObjectSettings/AdvancedObjectSettings.tsx
61
+ var initialValues = {
62
+ source: "",
63
+ id: ""
64
+ };
65
+ var AdvancedObjectSettings = ({ object }) => {
66
+ const { t } = useTranslation2(SPACE_PLUGIN);
67
+ const [adding, setAdding] = useState(false);
68
+ const keys = getMeta(object).keys;
69
+ const handleNew = useCallback2(() => setAdding(true), []);
70
+ const handleCancel = useCallback2(() => setAdding(false), []);
71
+ const handleSave = useCallback2((key) => {
72
+ const index = keys.findIndex(({ source, id }) => source === key.source && id === key.id);
73
+ if (index === -1) {
74
+ keys.push(key);
75
+ }
76
+ setAdding(false);
77
+ }, [
78
+ keys
79
+ ]);
80
+ const handleDelete = useCallback2((key) => {
81
+ const index = keys.findIndex(({ source, id }) => source === key.source && id === key.id);
82
+ if (index !== -1) {
83
+ keys.splice(index, 1);
84
+ }
85
+ }, [
86
+ keys
87
+ ]);
88
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Separator, null), /* @__PURE__ */ React2.createElement("div", {
89
+ className: "p-2 flex flex-col gap-4"
90
+ }, /* @__PURE__ */ React2.createElement("h2", null, t("advanced settings label")), /* @__PURE__ */ React2.createElement("div", {
91
+ className: "flex items-center"
92
+ }, /* @__PURE__ */ React2.createElement("h3", {
93
+ className: "text-sm font-semibold"
94
+ }, t("foreign keys")), /* @__PURE__ */ React2.createElement("div", {
95
+ className: "grow"
96
+ }), /* @__PURE__ */ React2.createElement(IconButton2, {
97
+ classNames: adding && "invisible",
98
+ icon: "ph--plus--regular",
99
+ label: t("add key"),
100
+ onClick: handleNew
101
+ })), !adding && /* @__PURE__ */ React2.createElement(ForeignKeys, {
102
+ keys,
103
+ onDelete: handleDelete
104
+ })), adding && /* @__PURE__ */ React2.createElement(Form, {
105
+ schema: ForeignKeySchema,
106
+ values: initialValues,
107
+ onSave: handleSave,
108
+ onCancel: handleCancel
109
+ }));
110
+ };
111
+
112
+ // packages/plugins/plugin-space/src/components/AwaitingObject.tsx
113
+ import { CheckCircle, CircleDashed, CircleNotch } from "@phosphor-icons/react";
114
+ import React3, { useCallback as useCallback3, useEffect, useState as useState2 } from "react";
115
+ import { createIntent, LayoutAction, useIntentDispatcher, useLayout } from "@dxos/app-framework";
116
+ import { useClient } from "@dxos/react-client";
117
+ import { Filter, fullyQualifiedId, useQuery } from "@dxos/react-client/echo";
118
+ import { Button, Toast, useTranslation as useTranslation3 } from "@dxos/react-ui";
119
+ import { getSize, mx } from "@dxos/react-ui-theme";
120
+ var WAIT_FOR_OBJECT_TIMEOUT = 18e4;
121
+ var TOAST_TIMEOUT = 24e4;
122
+ var AwaitingObject = ({ id }) => {
123
+ const [open, setOpen] = useState2(true);
124
+ const [waiting, setWaiting] = useState2(true);
125
+ const [found, setFound] = useState2(false);
126
+ const { t } = useTranslation3(SPACE_PLUGIN);
127
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
128
+ const layout = useLayout();
129
+ const client = useClient();
130
+ const objects = useQuery(client.spaces, Filter.all());
131
+ useEffect(() => {
132
+ if (!id) {
133
+ return;
134
+ }
135
+ const timeout = setTimeout(() => {
136
+ setWaiting(false);
137
+ }, WAIT_FOR_OBJECT_TIMEOUT);
138
+ () => clearTimeout(timeout);
139
+ }, [
140
+ id
141
+ ]);
142
+ useEffect(() => {
143
+ if (objects.findIndex((object) => fullyQualifiedId(object) === id) > -1) {
144
+ setFound(true);
145
+ if (layout.active.includes(id)) {
146
+ setOpen(false);
147
+ }
148
+ }
149
+ }, [
150
+ id,
151
+ objects,
152
+ layout
153
+ ]);
154
+ const handleClose = useCallback3(async () => dispatch(createIntent(SpaceAction.WaitForObject, {
155
+ id: void 0
156
+ })), [
157
+ dispatch
158
+ ]);
159
+ const handleNavigate = useCallback3(() => {
160
+ void dispatch(createIntent(LayoutAction.Open, {
161
+ part: "main",
162
+ subject: [
163
+ id
164
+ ]
165
+ }));
166
+ void handleClose();
167
+ }, [
168
+ id,
169
+ handleClose,
170
+ dispatch
171
+ ]);
172
+ return /* @__PURE__ */ React3.createElement(Toast.Root, {
173
+ open,
174
+ duration: TOAST_TIMEOUT,
175
+ onOpenChange: setOpen
176
+ }, /* @__PURE__ */ React3.createElement(Toast.Body, null, /* @__PURE__ */ React3.createElement(Toast.Title, {
177
+ classNames: "flex items-center gap-2"
178
+ }, found ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CheckCircle, {
179
+ className: getSize(5)
180
+ }), /* @__PURE__ */ React3.createElement("span", null, t("found object label"))) : waiting ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CircleNotch, {
181
+ className: mx(getSize(5), "animate-spin")
182
+ }), /* @__PURE__ */ React3.createElement("span", null, t("waiting for object label"))) : /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CircleDashed, {
183
+ className: getSize(5)
184
+ }), /* @__PURE__ */ React3.createElement("span", null, t("object not found label")))), /* @__PURE__ */ React3.createElement(Toast.Description, null, t(found ? "found object description" : waiting ? "waiting for object description" : "object not found description"))), /* @__PURE__ */ React3.createElement(Toast.Actions, null, found ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Toast.Action, {
185
+ altText: t("go to object alt"),
186
+ asChild: true
187
+ }, /* @__PURE__ */ React3.createElement(Button, {
188
+ variant: "primary",
189
+ onClick: handleNavigate
190
+ }, t("go to object label"))), /* @__PURE__ */ React3.createElement(Toast.Close, {
191
+ asChild: true
192
+ }, /* @__PURE__ */ React3.createElement(Button, {
193
+ onClick: handleClose
194
+ }, t("close label", {
195
+ ns: "appkit"
196
+ })))) : /* @__PURE__ */ React3.createElement(Toast.Close, {
197
+ asChild: true
198
+ }, /* @__PURE__ */ React3.createElement(Button, {
199
+ onClick: handleClose
200
+ }, t(waiting ? "close label" : "confirm label", {
201
+ ns: "appkit"
202
+ })))));
203
+ };
204
+
205
+ // packages/plugins/plugin-space/src/components/BaseObjectSettings.tsx
206
+ import React4 from "react";
207
+ import { Input, useTranslation as useTranslation4 } from "@dxos/react-ui";
208
+ var BaseObjectSettings = ({ object }) => {
209
+ const { t } = useTranslation4(SPACE_PLUGIN);
210
+ return /* @__PURE__ */ React4.createElement("div", {
211
+ role: "form",
212
+ className: "flex flex-col w-full p-2 gap-1"
213
+ }, /* @__PURE__ */ React4.createElement(Input.Root, null, /* @__PURE__ */ React4.createElement(Input.Label, null, t("name label")), /* @__PURE__ */ React4.createElement(Input.TextInput, {
214
+ placeholder: t("name placeholder"),
215
+ value: object.name ?? "",
216
+ onChange: (event) => {
217
+ object.name = event.target.value;
218
+ }
219
+ })));
220
+ };
221
+
222
+ // packages/plugins/plugin-space/src/components/CreateDialog/CreateObjectDialog.tsx
223
+ import { pipe } from "effect";
224
+ import React6, { useCallback as useCallback5, useRef } from "react";
225
+ import { chain, createIntent as createIntent2, LayoutAction as LayoutAction2, useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
226
+ import { useClient as useClient2 } from "@dxos/react-client";
227
+ import { getSpace, isReactiveObject, isSpace, useSpaces } from "@dxos/react-client/echo";
228
+ import { Button as Button2, Dialog, Icon as Icon2, useTranslation as useTranslation6 } from "@dxos/react-ui";
229
+
230
+ // packages/plugins/plugin-space/src/components/CreateDialog/CreateObjectPanel.tsx
231
+ import React5, { useCallback as useCallback4, useMemo, useState as useState3 } from "react";
232
+ import { Surface, isSurfaceAvailable, usePluginManager } from "@dxos/app-framework";
233
+ import { getObjectAnnotation, S } from "@dxos/echo-schema";
234
+ import { Icon, toLocalizedString, useTranslation as useTranslation5 } from "@dxos/react-ui";
235
+ import { Form as Form2 } from "@dxos/react-ui-form";
236
+ import { SearchList } from "@dxos/react-ui-searchlist";
237
+ import { mx as mx2 } from "@dxos/react-ui-theme";
238
+ import { nonNullable } from "@dxos/util";
239
+ var useInputSurfaceLookup = (baseData) => {
240
+ const pluginManager = usePluginManager();
241
+ return useCallback4(({ prop, schema, inputProps }) => {
242
+ const composedData = {
243
+ prop,
244
+ schema,
245
+ ...baseData
246
+ };
247
+ if (!isSurfaceAvailable(pluginManager.context, {
248
+ role: "form-input",
249
+ data: composedData
250
+ })) {
251
+ return void 0;
252
+ }
253
+ return /* @__PURE__ */ React5.createElement(Surface, {
254
+ role: "form-input",
255
+ data: composedData,
256
+ ...inputProps
257
+ });
258
+ }, [
259
+ pluginManager,
260
+ baseData
261
+ ]);
262
+ };
263
+ var CreateObjectPanel = ({ classNames, schemas, spaces, typename: initialTypename, target: initialTarget, name: initialName, defaultSpaceId, resolve, onCreateObject }) => {
264
+ const { t } = useTranslation5(SPACE_PLUGIN);
265
+ const [typename, setTypename] = useState3(initialTypename);
266
+ const [target, setTarget] = useState3(initialTarget);
267
+ const schema = schemas.find((schema2) => getObjectAnnotation(schema2)?.typename === typename);
268
+ const options = schemas.map(getObjectAnnotation).filter(nonNullable).sort((a, b) => {
269
+ const nameA = t("typename label", {
270
+ ns: a.typename,
271
+ defaultValue: a.typename
272
+ });
273
+ const nameB = t("typename label", {
274
+ ns: b.typename,
275
+ defaultValue: b.typename
276
+ });
277
+ return nameA.localeCompare(nameB);
278
+ });
279
+ const handleCreateObject = useCallback4(async (props) => {
280
+ if (!schema || !target) {
281
+ return;
282
+ }
283
+ await onCreateObject?.({
284
+ schema,
285
+ target,
286
+ data: props
287
+ });
288
+ }, [
289
+ onCreateObject,
290
+ schema,
291
+ target
292
+ ]);
293
+ const metadata = useMemo(() => {
294
+ if (!typename) {
295
+ return;
296
+ }
297
+ return resolve?.(typename);
298
+ }, [
299
+ resolve,
300
+ typename
301
+ ]);
302
+ const inputSurfaceLookup = useInputSurfaceLookup({
303
+ target
304
+ });
305
+ const form = useMemo(() => {
306
+ const schema2 = metadata?.creationSchema ?? S.Struct({
307
+ name: S.optional(S.String)
308
+ });
309
+ return /* @__PURE__ */ React5.createElement(Form2, {
310
+ classNames: "!p-0",
311
+ autoFocus: true,
312
+ values: {
313
+ name: initialName
314
+ },
315
+ schema: schema2,
316
+ testId: "create-object-form",
317
+ onSave: handleCreateObject,
318
+ lookupComponent: inputSurfaceLookup
319
+ });
320
+ }, [
321
+ initialName,
322
+ handleCreateObject,
323
+ metadata
324
+ ]);
325
+ return /* @__PURE__ */ React5.createElement("div", {
326
+ role: "form",
327
+ className: mx2("flex flex-col gap-2", classNames)
328
+ }, !schema ? /* @__PURE__ */ React5.createElement(SelectSchema, {
329
+ options,
330
+ resolve,
331
+ onChange: setTypename
332
+ }) : !target ? /* @__PURE__ */ React5.createElement(SelectSpace, {
333
+ spaces,
334
+ defaultSpaceId,
335
+ onChange: setTarget
336
+ }) : form);
337
+ };
338
+ var SelectSpace = ({ spaces, defaultSpaceId, onChange }) => {
339
+ const { t } = useTranslation5(SPACE_PLUGIN);
340
+ return /* @__PURE__ */ React5.createElement(SearchList.Root, {
341
+ label: t("space input label"),
342
+ classNames: "flex flex-col grow overflow-hidden"
343
+ }, /* @__PURE__ */ React5.createElement(SearchList.Input, {
344
+ autoFocus: true,
345
+ "data-testid": "create-object-form.space-input",
346
+ placeholder: t("space input placeholder"),
347
+ classNames: "px-1 my-2"
348
+ }), /* @__PURE__ */ React5.createElement(SearchList.Content, {
349
+ classNames: "max-bs-[24rem] overflow-auto"
350
+ }, spaces.sort((a, b) => {
351
+ const aName = toLocalizedString(getSpaceDisplayName(a, {
352
+ personal: a.id === defaultSpaceId
353
+ }), t);
354
+ const bName = toLocalizedString(getSpaceDisplayName(b, {
355
+ personal: b.id === defaultSpaceId
356
+ }), t);
357
+ return aName.localeCompare(bName);
358
+ }).map((space) => /* @__PURE__ */ React5.createElement(SearchList.Item, {
359
+ key: space.id,
360
+ value: toLocalizedString(getSpaceDisplayName(space, {
361
+ personal: space.id === defaultSpaceId
362
+ }), t),
363
+ onSelect: () => onChange(space),
364
+ classNames: "flex items-center gap-2"
365
+ }, /* @__PURE__ */ React5.createElement("span", {
366
+ className: "grow truncate"
367
+ }, toLocalizedString(getSpaceDisplayName(space, {
368
+ personal: space.id === defaultSpaceId
369
+ }), t))))));
370
+ };
371
+ var SelectSchema = ({ options, resolve, onChange }) => {
372
+ const { t } = useTranslation5(SPACE_PLUGIN);
373
+ return /* @__PURE__ */ React5.createElement(SearchList.Root, {
374
+ label: t("schema input label"),
375
+ classNames: "flex flex-col grow overflow-hidden"
376
+ }, /* @__PURE__ */ React5.createElement(SearchList.Input, {
377
+ autoFocus: true,
378
+ "data-testid": "create-object-form.schema-input",
379
+ placeholder: t("schema input placeholder"),
380
+ classNames: "px-1 my-2"
381
+ }), /* @__PURE__ */ React5.createElement(SearchList.Content, {
382
+ classNames: "max-bs-[24rem] overflow-auto"
383
+ }, options.map((option) => /* @__PURE__ */ React5.createElement(SearchList.Item, {
384
+ key: option.typename,
385
+ value: t("typename label", {
386
+ ns: option.typename,
387
+ defaultValue: option.typename
388
+ }),
389
+ onSelect: () => onChange(option.typename),
390
+ classNames: "flex items-center gap-2"
391
+ }, /* @__PURE__ */ React5.createElement("span", {
392
+ className: "flex gap-2 items-center grow truncate"
393
+ }, /* @__PURE__ */ React5.createElement(Icon, {
394
+ icon: resolve?.(option.typename).icon ?? "ph--placeholder--regular",
395
+ size: 5
396
+ }), t("typename label", {
397
+ ns: option.typename,
398
+ defaultValue: option.typename
399
+ }))))));
400
+ };
401
+
402
+ // packages/plugins/plugin-space/src/components/CreateDialog/CreateObjectDialog.tsx
403
+ var CREATE_OBJECT_DIALOG = `${SPACE_PLUGIN}/CreateObjectDialog`;
404
+ var CreateObjectDialog = ({ schemas, target, typename, name, shouldNavigate: _shouldNavigate, resolve }) => {
405
+ const closeRef = useRef(null);
406
+ const { t } = useTranslation6(SPACE_PLUGIN);
407
+ const client = useClient2();
408
+ const spaces = useSpaces();
409
+ const { dispatchPromise: dispatch } = useIntentDispatcher2();
410
+ const handleCreateObject = useCallback5(async ({ schema, target: _target, data }) => {
411
+ const target2 = isSpace(_target) ? _target.properties[CollectionType.typename]?.target : _target;
412
+ const createObjectIntent = resolve?.(schema.typename)?.createObject;
413
+ if (!createObjectIntent || !target2) {
414
+ return;
415
+ }
416
+ closeRef.current?.click();
417
+ const space = isSpace(target2) ? target2 : getSpace(target2);
418
+ const result = await dispatch(createObjectIntent(data, {
419
+ space
420
+ }));
421
+ const object = result.data?.object;
422
+ if (isReactiveObject(object)) {
423
+ const addObjectIntent = createIntent2(SpaceAction.AddObject, {
424
+ target: target2,
425
+ object
426
+ });
427
+ const shouldNavigate = _shouldNavigate ?? (() => true);
428
+ if (shouldNavigate(object)) {
429
+ await dispatch(pipe(addObjectIntent, chain(LayoutAction2.Open, {
430
+ part: "main"
431
+ })));
432
+ } else {
433
+ await dispatch(addObjectIntent);
434
+ }
435
+ }
436
+ }, [
437
+ dispatch,
438
+ resolve
439
+ ]);
440
+ return (
441
+ // TODO(wittjosiah): The tablist dialog pattern is copied from @dxos/plugin-manager.
442
+ // Consider factoring it out to the tabs package.
443
+ /* @__PURE__ */ React6.createElement(Dialog.Content, {
444
+ classNames: "p-0 bs-content max-bs-full md:max-is-[40rem] overflow-hidden"
445
+ }, /* @__PURE__ */ React6.createElement("div", {
446
+ role: "none",
447
+ className: "flex justify-between pbs-2 pis-2 pie-2 @md:pbs-4 @md:pis-4 @md:pie-4"
448
+ }, /* @__PURE__ */ React6.createElement(Dialog.Title, null, t("create object dialog title")), /* @__PURE__ */ React6.createElement(Dialog.Close, {
449
+ asChild: true
450
+ }, /* @__PURE__ */ React6.createElement(Button2, {
451
+ ref: closeRef,
452
+ density: "fine",
453
+ variant: "ghost",
454
+ autoFocus: true
455
+ }, /* @__PURE__ */ React6.createElement(Icon2, {
456
+ icon: "ph--x--regular",
457
+ size: 4
458
+ })))), /* @__PURE__ */ React6.createElement(CreateObjectPanel, {
459
+ classNames: "p-4",
460
+ schemas,
461
+ spaces,
462
+ target,
463
+ typename,
464
+ name,
465
+ defaultSpaceId: client.spaces.default.id,
466
+ resolve,
467
+ onCreateObject: handleCreateObject
468
+ }))
469
+ );
470
+ };
471
+
472
+ // packages/plugins/plugin-space/src/components/CreateDialog/CreateSpaceDialog.tsx
473
+ import { Effect } from "effect";
474
+ import React7, { useCallback as useCallback6, useRef as useRef2 } from "react";
475
+ import { createIntent as createIntent3, LayoutAction as LayoutAction3, useIntentDispatcher as useIntentDispatcher3 } from "@dxos/app-framework";
476
+ import { Button as Button3, Dialog as Dialog2, Icon as Icon3, useTranslation as useTranslation7 } from "@dxos/react-ui";
477
+ import { Form as Form3 } from "@dxos/react-ui-form";
478
+ var CREATE_SPACE_DIALOG = `${SPACE_PLUGIN}/CreateSpaceDialog`;
479
+ var initialValues2 = {
480
+ edgeReplication: true
481
+ };
482
+ var CreateSpaceDialog = () => {
483
+ const closeRef = useRef2(null);
484
+ const { t } = useTranslation7(SPACE_PLUGIN);
485
+ const { dispatch } = useIntentDispatcher3();
486
+ const handleCreateSpace = useCallback6(async (data) => {
487
+ const program = Effect.gen(function* () {
488
+ const { space } = yield* dispatch(createIntent3(SpaceAction.Create, data));
489
+ yield* dispatch(createIntent3(LayoutAction3.SwitchWorkspace, {
490
+ part: "workspace",
491
+ subject: space.id
492
+ }));
493
+ yield* dispatch(createIntent3(SpaceAction.OpenCreateObject, {
494
+ target: space
495
+ }));
496
+ });
497
+ await Effect.runPromise(program);
498
+ }, [
499
+ dispatch
500
+ ]);
501
+ return (
502
+ // TODO(wittjosiah): The tablist dialog pattern is copied from @dxos/plugin-manager.
503
+ // Consider factoring it out to the tabs package.
504
+ /* @__PURE__ */ React7.createElement(Dialog2.Content, {
505
+ classNames: "p-0 bs-content min-bs-[16rem] max-bs-full md:max-is-[32rem] overflow-hidden"
506
+ }, /* @__PURE__ */ React7.createElement("div", {
507
+ role: "none",
508
+ className: "flex justify-between pbs-2 pis-2 pie-2 @md:pbs-4 @md:pis-4 @md:pie-4"
509
+ }, /* @__PURE__ */ React7.createElement(Dialog2.Title, null, t("create space dialog title")), /* @__PURE__ */ React7.createElement(Dialog2.Close, {
510
+ asChild: true
511
+ }, /* @__PURE__ */ React7.createElement(Button3, {
512
+ ref: closeRef,
513
+ density: "fine",
514
+ variant: "ghost",
515
+ autoFocus: true
516
+ }, /* @__PURE__ */ React7.createElement(Icon3, {
517
+ icon: "ph--x--regular",
518
+ size: 4
519
+ })))), /* @__PURE__ */ React7.createElement("div", {
520
+ className: "p-4"
521
+ }, /* @__PURE__ */ React7.createElement(Form3, {
522
+ testId: "create-space-form",
523
+ classNames: "!p-0",
524
+ autoFocus: true,
525
+ values: initialValues2,
526
+ schema: SpaceForm,
527
+ onSave: handleCreateSpace
528
+ })))
529
+ );
530
+ };
531
+
532
+ // packages/plugins/plugin-space/src/components/CollectionMain.tsx
533
+ import React8 from "react";
534
+ import { useTranslation as useTranslation8 } from "@dxos/react-ui";
535
+ import { baseSurface, descriptionText, mx as mx3 } from "@dxos/react-ui-theme";
536
+ var CollectionMain = ({ collection }) => {
537
+ const { t } = useTranslation8(SPACE_PLUGIN);
538
+ return /* @__PURE__ */ React8.createElement("div", {
539
+ role: "none",
540
+ className: mx3(baseSurface, "min-bs-screen is-full flex items-center justify-center p-8"),
541
+ "data-testid": "composer.firstRunMessage"
542
+ }, /* @__PURE__ */ React8.createElement("p", {
543
+ role: "alert",
544
+ className: mx3(descriptionText, "border border-dashed border-neutral-400/50 rounded-lg p-8 font-normal text-lg max-is-[24rem] break-words")
545
+ }, collection.name ?? t("unnamed collection label")));
546
+ };
547
+
548
+ // packages/plugins/plugin-space/src/components/CollectionSection.tsx
549
+ import React9 from "react";
550
+ import { useTranslation as useTranslation9 } from "@dxos/react-ui";
551
+ var CollectionSection = ({ collection }) => {
552
+ const { t } = useTranslation9(SPACE_PLUGIN);
553
+ return /* @__PURE__ */ React9.createElement("div", {
554
+ className: "min-bs-[3.5rem] grid grid-rows-subgrid grid-cols-subgrid items-center"
555
+ }, /* @__PURE__ */ React9.createElement("span", {
556
+ className: "truncate"
557
+ }, collection.name ?? t("unnamed collection label")));
558
+ };
559
+
560
+ // packages/plugins/plugin-space/src/components/JoinDialog.tsx
561
+ import React10, { useCallback as useCallback7 } from "react";
562
+ import { createIntent as createIntent4, LayoutAction as LayoutAction4, useAppGraph, useIntentDispatcher as useIntentDispatcher4 } from "@dxos/app-framework";
563
+ import { log } from "@dxos/log";
564
+ import { ObservabilityAction } from "@dxos/plugin-observability/types";
565
+ import { useClient as useClient3 } from "@dxos/react-client";
566
+ import { Dialog as Dialog3 } from "@dxos/react-ui";
567
+ import { JoinPanel } from "@dxos/shell/react";
568
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/JoinDialog.tsx";
569
+ var JOIN_DIALOG = `${SPACE_PLUGIN}/JoinDialog`;
570
+ var JoinDialog = ({ navigableCollections, onDone, ...props }) => {
571
+ const { dispatchPromise: dispatch } = useIntentDispatcher4();
572
+ const client = useClient3();
573
+ const { graph } = useAppGraph();
574
+ const handleDone = useCallback7(async (result) => {
575
+ if (result?.spaceKey) {
576
+ await Promise.all([
577
+ dispatch(createIntent4(LayoutAction4.AddToast, {
578
+ part: "toast",
579
+ subject: {
580
+ id: `${SPACE_PLUGIN}/join-success`,
581
+ duration: 5e3,
582
+ title: [
583
+ "join success label",
584
+ {
585
+ ns: SPACE_PLUGIN
586
+ }
587
+ ],
588
+ closeLabel: [
589
+ "dismiss label",
590
+ {
591
+ ns: SPACE_PLUGIN
592
+ }
593
+ ]
594
+ }
595
+ })),
596
+ dispatch(createIntent4(LayoutAction4.UpdateDialog, {
597
+ part: "dialog",
598
+ options: {
599
+ state: false
600
+ }
601
+ }))
602
+ ]);
603
+ }
604
+ const space = result?.spaceKey ? client.spaces.get(result.spaceKey) : void 0;
605
+ if (!space) {
606
+ log.warn("Space not found", result?.spaceKey, {
607
+ F: __dxlog_file,
608
+ L: 56,
609
+ S: void 0,
610
+ C: (f, a) => f(...a)
611
+ });
612
+ return;
613
+ }
614
+ await dispatch(createIntent4(LayoutAction4.SwitchWorkspace, {
615
+ part: "workspace",
616
+ subject: space.id
617
+ }));
618
+ const target = result?.target || (navigableCollections ? space?.id : void 0);
619
+ if (target) {
620
+ await graph.waitForPath({
621
+ target
622
+ }).catch(() => {
623
+ });
624
+ await Promise.all([
625
+ dispatch(createIntent4(LayoutAction4.Open, {
626
+ part: "main",
627
+ subject: [
628
+ target
629
+ ]
630
+ })),
631
+ dispatch(createIntent4(LayoutAction4.Expose, {
632
+ part: "navigation",
633
+ subject: target
634
+ }))
635
+ ]);
636
+ }
637
+ await onDone?.(result);
638
+ if (space) {
639
+ await dispatch(createIntent4(ObservabilityAction.SendEvent, {
640
+ name: "space.join",
641
+ properties: {
642
+ spaceId: space.id
643
+ }
644
+ }));
645
+ }
646
+ }, [
647
+ dispatch,
648
+ client,
649
+ graph
650
+ ]);
651
+ return /* @__PURE__ */ React10.createElement(Dialog3.Content, null, /* @__PURE__ */ React10.createElement(JoinPanel, {
652
+ ...props,
653
+ exitActionParent: /* @__PURE__ */ React10.createElement(Dialog3.Close, {
654
+ asChild: true
655
+ }),
656
+ doneActionParent: /* @__PURE__ */ React10.createElement(Dialog3.Close, {
657
+ asChild: true
658
+ }),
659
+ onDone: handleDone
660
+ }));
661
+ };
662
+
663
+ // packages/plugins/plugin-space/src/components/MenuFooter.tsx
664
+ import { Planet } from "@phosphor-icons/react";
665
+ import React11 from "react";
666
+ import { getSpace as getSpace2 } from "@dxos/client/echo";
667
+ import { useClient as useClient4 } from "@dxos/react-client";
668
+ import { DropdownMenu, toLocalizedString as toLocalizedString2, useTranslation as useTranslation10 } from "@dxos/react-ui";
669
+ var MenuFooter = ({ object }) => {
670
+ const { t } = useTranslation10(SPACE_PLUGIN);
671
+ const client = useClient4();
672
+ const space = getSpace2(object);
673
+ const spaceName = space ? getSpaceDisplayName(space, {
674
+ personal: client.spaces.default === space
675
+ }) : "";
676
+ return space ? /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(DropdownMenu.Separator, null), /* @__PURE__ */ React11.createElement(DropdownMenu.GroupLabel, null, t("menu footer label")), /* @__PURE__ */ React11.createElement("dl", {
677
+ className: "pis-2 mbe-2 text-xs grid grid-cols-[max-content_1fr] gap-2"
678
+ }, /* @__PURE__ */ React11.createElement("dt", {
679
+ className: "uppercase text-[.75em] tracking-wide font-medium mbs-px self-start"
680
+ }, t("location label")), /* @__PURE__ */ React11.createElement("dd", {
681
+ className: "line-clamp-3"
682
+ }, /* @__PURE__ */ React11.createElement(Planet, {
683
+ className: "inline-block mie-1"
684
+ }), toLocalizedString2(spaceName, t)))) : null;
685
+ };
686
+
687
+ // packages/plugins/plugin-space/src/components/PersistenceStatus.tsx
688
+ import { ArrowsCounterClockwise, CheckCircle as CheckCircle2, Warning } from "@phosphor-icons/react";
689
+ import React12, { useEffect as useEffect2, useState as useState4 } from "react";
690
+ import { debounce } from "@dxos/async";
691
+ import { Tooltip, useTranslation as useTranslation11 } from "@dxos/react-ui";
692
+ import { getSize as getSize2, mx as mx4, staticPlaceholderText, warningText } from "@dxos/react-ui-theme";
693
+ var Status;
694
+ (function(Status2) {
695
+ Status2[Status2["PERSISTED_LOCALLY"] = 0] = "PERSISTED_LOCALLY";
696
+ Status2[Status2["PENDING"] = 1] = "PENDING";
697
+ Status2[Status2["ERROR"] = 2] = "ERROR";
698
+ })(Status || (Status = {}));
699
+ var PersistenceStatus = ({ db }) => {
700
+ const { t } = useTranslation11(SPACE_PLUGIN);
701
+ const [displayMessage, setDisplayMessage] = useState4(false);
702
+ const [status, naturalSetStatus] = useState4(0);
703
+ const [prevStatus, setPrevStatus] = useState4(0);
704
+ const _setStatus = debounce(naturalSetStatus, 500);
705
+ useEffect2(() => {
706
+ setPrevStatus(status);
707
+ if (prevStatus !== status && status === 0) {
708
+ setDisplayMessage(true);
709
+ const timeout = setTimeout(() => setDisplayMessage(false), 5e3);
710
+ return () => clearTimeout(timeout);
711
+ }
712
+ }, [
713
+ status
714
+ ]);
715
+ switch (status) {
716
+ case 2:
717
+ return /* @__PURE__ */ React12.createElement("div", {
718
+ className: "flex items-center"
719
+ }, /* @__PURE__ */ React12.createElement(Warning, {
720
+ className: mx4(getSize2(4), "me-1")
721
+ }), /* @__PURE__ */ React12.createElement("span", {
722
+ className: mx4("text-sm", warningText)
723
+ }, t("persistence error label")));
724
+ case 1:
725
+ return /* @__PURE__ */ React12.createElement("div", {
726
+ className: "flex items-center"
727
+ }, /* @__PURE__ */ React12.createElement(ArrowsCounterClockwise, {
728
+ className: mx4(getSize2(4), "me-1")
729
+ }), /* @__PURE__ */ React12.createElement("span", {
730
+ className: mx4("text-sm", staticPlaceholderText)
731
+ }, t("persistence pending label")));
732
+ case 0:
733
+ default:
734
+ return /* @__PURE__ */ React12.createElement(Tooltip.Root, {
735
+ delayDuration: 400
736
+ }, /* @__PURE__ */ React12.createElement(Tooltip.Trigger, {
737
+ role: "status",
738
+ className: "flex items-center"
739
+ }, /* @__PURE__ */ React12.createElement(CheckCircle2, {
740
+ className: mx4(getSize2(4), "me-1")
741
+ }), displayMessage && /* @__PURE__ */ React12.createElement("span", {
742
+ className: mx4("text-sm", staticPlaceholderText)
743
+ }, t("persisted locally label"))), /* @__PURE__ */ React12.createElement(Tooltip.Portal, null, /* @__PURE__ */ React12.createElement(Tooltip.Content, null, t("persisted locally message"), /* @__PURE__ */ React12.createElement(Tooltip.Arrow, null))));
744
+ }
745
+ };
746
+
747
+ // packages/plugins/plugin-space/src/components/PopoverRenameObject.tsx
748
+ import React13, { useCallback as useCallback8, useRef as useRef3, useState as useState5 } from "react";
749
+ import { log as log2 } from "@dxos/log";
750
+ import { Button as Button4, Input as Input2, Popover, useTranslation as useTranslation12 } from "@dxos/react-ui";
751
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/PopoverRenameObject.tsx";
752
+ var POPOVER_RENAME_OBJECT = `${SPACE_PLUGIN}/PopoverRenameObject`;
753
+ var PopoverRenameObject = ({ object: obj }) => {
754
+ const { t } = useTranslation12(SPACE_PLUGIN);
755
+ const doneButton = useRef3(null);
756
+ const object = obj;
757
+ const [name, setName] = useState5(object.name || object.title || "");
758
+ const handleDone = useCallback8(() => {
759
+ try {
760
+ object.name = name;
761
+ } catch {
762
+ try {
763
+ object.title = name;
764
+ } catch (err) {
765
+ log2.error("Failed to rename object", {
766
+ err
767
+ }, {
768
+ F: __dxlog_file2,
769
+ L: 30,
770
+ S: void 0,
771
+ C: (f, a) => f(...a)
772
+ });
773
+ }
774
+ }
775
+ }, [
776
+ object,
777
+ name
778
+ ]);
779
+ return /* @__PURE__ */ React13.createElement("div", {
780
+ role: "none",
781
+ className: "p-1 flex gap-2"
782
+ }, /* @__PURE__ */ React13.createElement("div", {
783
+ role: "none",
784
+ className: "flex-1"
785
+ }, /* @__PURE__ */ React13.createElement(Input2.Root, null, /* @__PURE__ */ React13.createElement(Input2.Label, {
786
+ srOnly: true
787
+ }, t("object name label")), /* @__PURE__ */ React13.createElement(Input2.TextInput, {
788
+ placeholder: t("object title placeholder"),
789
+ value: name,
790
+ "data-testid": "spacePlugin.renameObject.input",
791
+ onChange: ({ target: { value } }) => setName(value),
792
+ onKeyDown: ({ key }) => key === "Enter" && doneButton.current?.click()
793
+ }))), /* @__PURE__ */ React13.createElement(Popover.Close, {
794
+ asChild: true
795
+ }, /* @__PURE__ */ React13.createElement(Button4, {
796
+ ref: doneButton,
797
+ classNames: "self-stretch",
798
+ onClick: handleDone
799
+ }, t("done label", {
800
+ ns: "os"
801
+ }))));
802
+ };
803
+
804
+ // packages/plugins/plugin-space/src/components/PopoverRenameSpace.tsx
805
+ import React14, { useCallback as useCallback9, useRef as useRef4, useState as useState6 } from "react";
806
+ import { Button as Button5, Input as Input3, Popover as Popover2, useTranslation as useTranslation13 } from "@dxos/react-ui";
807
+ var POPOVER_RENAME_SPACE = `${SPACE_PLUGIN}/PopoverRenameSpace`;
808
+ var PopoverRenameSpace = ({ space }) => {
809
+ const { t } = useTranslation13(SPACE_PLUGIN);
810
+ const doneButton = useRef4(null);
811
+ const [name, setName] = useState6(space.properties.name ?? "");
812
+ const handleDone = useCallback9(() => {
813
+ space.properties.name = name;
814
+ }, [
815
+ space,
816
+ name
817
+ ]);
818
+ return /* @__PURE__ */ React14.createElement("div", {
819
+ role: "none",
820
+ className: "p-1 flex gap-2"
821
+ }, /* @__PURE__ */ React14.createElement("div", {
822
+ role: "none",
823
+ className: "flex-1"
824
+ }, /* @__PURE__ */ React14.createElement(Input3.Root, null, /* @__PURE__ */ React14.createElement(Input3.Label, {
825
+ srOnly: true
826
+ }, t("space name label")), /* @__PURE__ */ React14.createElement(Input3.TextInput, {
827
+ defaultValue: space.properties.name ?? "",
828
+ placeholder: t("unnamed space label"),
829
+ onChange: ({ target: { value } }) => setName(value),
830
+ // TODO(wittjosiah): Ideally this should access the popover context to close the popover.
831
+ // Currently this is not possible because Radix does not expose the popover context.
832
+ onKeyDown: ({ key }) => key === "Enter" && doneButton.current?.click()
833
+ }))), /* @__PURE__ */ React14.createElement(Popover2.Close, {
834
+ asChild: true
835
+ }, /* @__PURE__ */ React14.createElement(Button5, {
836
+ ref: doneButton,
837
+ classNames: "self-stretch",
838
+ onClick: handleDone
839
+ }, t("done label", {
840
+ ns: "os"
841
+ }))));
842
+ };
843
+
844
+ // packages/plugins/plugin-space/src/components/ShareSpaceButton.tsx
845
+ import React15 from "react";
846
+ import { createIntent as createIntent5, useIntentDispatcher as useIntentDispatcher5 } from "@dxos/app-framework";
847
+ import { IconButton as IconButton3, useTranslation as useTranslation14 } from "@dxos/react-ui";
848
+ var ShareSpaceButton = ({ space }) => {
849
+ const { dispatchPromise: dispatch } = useIntentDispatcher5();
850
+ return /* @__PURE__ */ React15.createElement(ShareSpaceButtonImpl, {
851
+ onClick: () => dispatch(createIntent5(SpaceAction.Share, {
852
+ space
853
+ }))
854
+ });
855
+ };
856
+ var ShareSpaceButtonImpl = ({ onClick }) => {
857
+ const { t } = useTranslation14(SPACE_PLUGIN);
858
+ return /* @__PURE__ */ React15.createElement(IconButton3, {
859
+ "data-testid": "spacePlugin.shareSpaceButton",
860
+ icon: "ph--users--regular",
861
+ label: t("share space label"),
862
+ onClick
863
+ });
864
+ };
865
+
866
+ // packages/plugins/plugin-space/src/components/SpacePresence.tsx
867
+ import React16, { useCallback as useCallback10, useEffect as useEffect4, useState as useState8 } from "react";
868
+ import { useAppGraph as useAppGraph2, useCapability } from "@dxos/app-framework";
869
+ import { generateName } from "@dxos/display-name";
870
+ import { PublicKey, useClient as useClient5 } from "@dxos/react-client";
871
+ import { getSpace as getSpace3, useMembers, fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
872
+ import { useIdentity } from "@dxos/react-client/halo";
873
+ import { Avatar, AvatarGroup, AvatarGroupItem, Tooltip as Tooltip2, useTranslation as useTranslation15, List as List2, ListItem as ListItem2, useDefaultValue } from "@dxos/react-ui";
874
+ import { AttentionGlyph, useAttended, useAttention } from "@dxos/react-ui-attention";
875
+ import { ComplexMap, keyToFallback } from "@dxos/util";
876
+
877
+ // packages/plugins/plugin-space/src/capabilities/index.ts
878
+ import { lazy } from "@dxos/app-framework";
879
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-MS6BI5EW.mjs"));
880
+ var AppGraphSerializer = lazy(() => import("./app-graph-serializer-AWAWDSCM.mjs"));
881
+ var IdentityCreated = lazy(() => import("./identity-created-3AUSSVEK.mjs"));
882
+ var IntentResolver = lazy(() => import("./intent-resolver-KJ67TU34.mjs"));
883
+ var ReactRoot = lazy(() => import("./react-root-NBQQKAZD.mjs"));
884
+ var ReactSurface = lazy(() => import("./react-surface-G2H5T2D2.mjs"));
885
+ var SpaceSettings = lazy(() => import("./settings-VBAUB37B.mjs"));
886
+ var SpaceState = lazy(() => import("./state-5GH2D5U4.mjs"));
887
+ var SpacesReady = lazy(() => import("./spaces-ready-ABADUX2P.mjs"));
888
+
889
+ // packages/plugins/plugin-space/src/hooks/usePath.ts
890
+ import { useEffect as useEffect3, useState as useState7 } from "react";
891
+ var usePath = (graph, id, timeout) => {
892
+ const [pathState, setPathState] = useState7(id ? graph.getPath({
893
+ target: id
894
+ }) : void 0);
895
+ useEffect3(() => {
896
+ if (!id && pathState) {
897
+ setPathState(void 0);
898
+ }
899
+ if (pathState?.at(-1) === id || !id) {
900
+ return;
901
+ }
902
+ const frame = requestAnimationFrame(async () => {
903
+ try {
904
+ const path = await graph.waitForPath({
905
+ target: id
906
+ }, {
907
+ timeout
908
+ });
909
+ if (path) {
910
+ setPathState(path);
911
+ }
912
+ } catch {
913
+ }
914
+ });
915
+ return () => cancelAnimationFrame(frame);
916
+ }, [
917
+ graph,
918
+ id,
919
+ timeout,
920
+ pathState
921
+ ]);
922
+ return pathState;
923
+ };
924
+
925
+ // packages/plugins/plugin-space/src/components/SpacePresence.tsx
926
+ var REFRESH_INTERVAL = 5e3;
927
+ var ACTIVITY_DURATION = 3e4;
928
+ var noViewers = new ComplexMap(PublicKey.hash);
929
+ var getName = (identity) => identity.profile?.displayName ?? generateName(identity.identityKey.toHex());
930
+ var SpacePresence = ({ object, spaceKey }) => {
931
+ const spaceState = useCapability(SpaceCapabilities.MutableState);
932
+ const client = useClient5();
933
+ const identity = useIdentity();
934
+ const space = spaceKey ? client.spaces.get(spaceKey) : getSpace3(object);
935
+ const spaceMembers = useMembers(space?.key);
936
+ const [_moment, setMoment] = useState8(Date.now());
937
+ useEffect4(() => {
938
+ const interval = setInterval(() => setMoment(Date.now()), REFRESH_INTERVAL);
939
+ return () => clearInterval(interval);
940
+ }, []);
941
+ const memberOnline = useCallback10((member) => member.presence === 1, []);
942
+ const memberIsNotSelf = useCallback10((member) => !identity?.identityKey.equals(member.identity.identityKey), [
943
+ identity?.identityKey
944
+ ]);
945
+ if (!identity || !spaceState || !space) {
946
+ return null;
947
+ }
948
+ const currentObjectViewers = spaceState.viewersByObject[fullyQualifiedId2(object)] ?? noViewers;
949
+ const membersForObject = spaceMembers.filter((member) => memberOnline(member) && memberIsNotSelf(member)).filter((member) => currentObjectViewers.has(member.identity.identityKey)).map((member) => {
950
+ const objectView = currentObjectViewers.get(member.identity.identityKey);
951
+ const lastSeen = objectView?.lastSeen ?? -Infinity;
952
+ const currentlyAttended = objectView?.currentlyAttended ?? false;
953
+ return {
954
+ ...member,
955
+ currentlyAttended,
956
+ lastSeen
957
+ };
958
+ }).toSorted((a, b) => a.lastSeen - b.lastSeen);
959
+ return /* @__PURE__ */ React16.createElement(FullPresence, {
960
+ members: membersForObject
961
+ });
962
+ };
963
+ var FullPresence = (props) => {
964
+ const { size = 9, onMemberClick } = props;
965
+ const members = useDefaultValue(props.members, () => []);
966
+ if (members.length === 0) {
967
+ return null;
968
+ }
969
+ return /* @__PURE__ */ React16.createElement(AvatarGroup.Root, {
970
+ size,
971
+ classNames: "mbs-2 mie-4",
972
+ "data-testid": "spacePlugin.presence"
973
+ }, members.slice(0, 3).map((member, i) => /* @__PURE__ */ React16.createElement(Tooltip2.Root, {
974
+ key: member.identity.identityKey.toHex()
975
+ }, /* @__PURE__ */ React16.createElement(Tooltip2.Trigger, null, /* @__PURE__ */ React16.createElement(PrensenceAvatar, {
976
+ identity: member.identity,
977
+ group: true,
978
+ match: member.currentlyAttended,
979
+ index: members.length - i,
980
+ onClick: () => onMemberClick?.(member)
981
+ })), /* @__PURE__ */ React16.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React16.createElement(Tooltip2.Content, {
982
+ side: "bottom"
983
+ }, /* @__PURE__ */ React16.createElement("span", null, getName(member.identity)), /* @__PURE__ */ React16.createElement(Tooltip2.Arrow, null))))), members.length > 3 && /* @__PURE__ */ React16.createElement(Tooltip2.Root, null, /* @__PURE__ */ React16.createElement(Tooltip2.Trigger, null, /* @__PURE__ */ React16.createElement(AvatarGroupItem.Root, {
984
+ status: "inactive"
985
+ }, /* @__PURE__ */ React16.createElement(Avatar.Frame, {
986
+ style: {
987
+ zIndex: members.length - 4
988
+ }
989
+ }, /* @__PURE__ */ React16.createElement(Avatar.Fallback, {
990
+ text: `+${members.length - 3}`
991
+ })))), /* @__PURE__ */ React16.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React16.createElement(Tooltip2.Content, {
992
+ side: "bottom"
993
+ }, /* @__PURE__ */ React16.createElement(Tooltip2.Arrow, null), /* @__PURE__ */ React16.createElement(List2, {
994
+ classNames: "max-h-56 overflow-y-auto"
995
+ }, members.map((member) => /* @__PURE__ */ React16.createElement(ListItem2.Root, {
996
+ key: member.identity.identityKey.toHex(),
997
+ classNames: "flex gap-2 items-center cursor-pointer mbe-2",
998
+ onClick: () => onMemberClick?.(member),
999
+ "data-testid": "identity-list-item"
1000
+ }, /* @__PURE__ */ React16.createElement(PrensenceAvatar, {
1001
+ identity: member.identity,
1002
+ showName: true,
1003
+ match: member.currentlyAttended
1004
+ }))))))));
1005
+ };
1006
+ var PrensenceAvatar = ({ identity, showName, match, group, index, onClick }) => {
1007
+ const Root = group ? AvatarGroupItem.Root : Avatar.Root;
1008
+ const status = match ? "current" : "active";
1009
+ const fallbackValue = keyToFallback(identity.identityKey);
1010
+ return /* @__PURE__ */ React16.createElement(Root, {
1011
+ status,
1012
+ hue: identity.profile?.data?.hue || fallbackValue.hue
1013
+ }, /* @__PURE__ */ React16.createElement(Avatar.Frame, {
1014
+ "data-testid": "spacePlugin.presence.member",
1015
+ "data-status": status,
1016
+ ...index ? {
1017
+ style: {
1018
+ zIndex: index
1019
+ }
1020
+ } : {},
1021
+ onClick: () => onClick?.()
1022
+ }, /* @__PURE__ */ React16.createElement(Avatar.Fallback, {
1023
+ text: identity.profile?.data?.emoji || fallbackValue.emoji
1024
+ })), showName && /* @__PURE__ */ React16.createElement(Avatar.Label, {
1025
+ classNames: "text-sm truncate pli-2"
1026
+ }, getName(identity)));
1027
+ };
1028
+ var SmallPresenceLive = ({ id, open, viewers }) => {
1029
+ const { hasAttention, isAncestor, isRelated } = useAttention(id);
1030
+ const isAttended = hasAttention || isAncestor || isRelated;
1031
+ const { graph } = useAppGraph2();
1032
+ const attended = useAttended();
1033
+ const startOfAttention = attended.at(-1);
1034
+ const path = usePath(graph, startOfAttention);
1035
+ const containsAttended = !open && !isAttended && id && path ? path.includes(id) : false;
1036
+ const getActiveViewers = (viewers2) => {
1037
+ const moment = Date.now();
1038
+ return Array.from(viewers2.values()).filter((viewer) => moment - viewer.lastSeen < ACTIVITY_DURATION);
1039
+ };
1040
+ const [activeViewers, setActiveViewers] = useState8(viewers ? getActiveViewers(viewers) : []);
1041
+ useEffect4(() => {
1042
+ if (viewers) {
1043
+ setActiveViewers(getActiveViewers(viewers));
1044
+ const interval = setInterval(() => {
1045
+ setActiveViewers(getActiveViewers(viewers));
1046
+ }, REFRESH_INTERVAL);
1047
+ return () => clearInterval(interval);
1048
+ }
1049
+ }, [
1050
+ viewers
1051
+ ]);
1052
+ return /* @__PURE__ */ React16.createElement(SmallPresence, {
1053
+ count: activeViewers.length,
1054
+ attended: isAttended,
1055
+ containsAttended
1056
+ });
1057
+ };
1058
+ var SmallPresence = ({ count = 0, attended, containsAttended }) => {
1059
+ const { t } = useTranslation15(SPACE_PLUGIN);
1060
+ return /* @__PURE__ */ React16.createElement(Tooltip2.Root, null, /* @__PURE__ */ React16.createElement(Tooltip2.Trigger, {
1061
+ asChild: true
1062
+ }, /* @__PURE__ */ React16.createElement(AttentionGlyph, {
1063
+ attended,
1064
+ containsAttended,
1065
+ presence: count > 1 ? "many" : count === 1 ? "one" : "none",
1066
+ classNames: "self-center mie-1"
1067
+ })), /* @__PURE__ */ React16.createElement(Tooltip2.Portal, null, /* @__PURE__ */ React16.createElement(Tooltip2.Content, {
1068
+ side: "bottom"
1069
+ }, /* @__PURE__ */ React16.createElement("span", null, t("presence label", {
1070
+ count
1071
+ })), /* @__PURE__ */ React16.createElement(Tooltip2.Arrow, null))));
1072
+ };
1073
+
1074
+ // packages/plugins/plugin-space/src/components/SpacePluginSettings.tsx
1075
+ import React17 from "react";
1076
+ import { Input as Input4, useTranslation as useTranslation16 } from "@dxos/react-ui";
1077
+ import { DeprecatedFormContainer, DeprecatedFormInput } from "@dxos/react-ui-form";
1078
+ var SpacePluginSettings = ({ settings }) => {
1079
+ const { t } = useTranslation16(SPACE_PLUGIN);
1080
+ return /* @__PURE__ */ React17.createElement(DeprecatedFormContainer, null, /* @__PURE__ */ React17.createElement(DeprecatedFormInput, {
1081
+ label: t("show hidden spaces label")
1082
+ }, /* @__PURE__ */ React17.createElement(Input4.Switch, {
1083
+ checked: settings.showHidden,
1084
+ onCheckedChange: (checked) => settings.showHidden = !!checked
1085
+ })));
1086
+ };
1087
+
1088
+ // packages/plugins/plugin-space/src/components/SpaceSettings/SpaceSettingsPanel.tsx
1089
+ import React18, { useCallback as useCallback11, useState as useState9 } from "react";
1090
+ import { log as log3 } from "@dxos/log";
1091
+ import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
1092
+ import { useClient as useClient6 } from "@dxos/react-client";
1093
+ import { Input as Input5, useTranslation as useTranslation17 } from "@dxos/react-ui";
1094
+ import { DeprecatedFormContainer as DeprecatedFormContainer2, DeprecatedFormInput as DeprecatedFormInput2 } from "@dxos/react-ui-form";
1095
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SpaceSettings/SpaceSettingsPanel.tsx";
1096
+ var SpaceSettingsPanel = ({ classNames, space }) => {
1097
+ const { t } = useTranslation17(SPACE_PLUGIN);
1098
+ const client = useClient6();
1099
+ const edgeEnabled = Boolean(client.config.values.runtime?.client?.edgeFeatures?.echoReplicator);
1100
+ const [edgeReplication, setEdgeReplication] = useState9(space.internal.data.edgeReplication === EdgeReplicationSetting.ENABLED);
1101
+ const toggleEdgeReplication = useCallback11(async (next) => {
1102
+ setEdgeReplication(next);
1103
+ await space?.internal.setEdgeReplicationPreference(next ? EdgeReplicationSetting.ENABLED : EdgeReplicationSetting.DISABLED).catch((err) => {
1104
+ log3.catch(err, void 0, {
1105
+ F: __dxlog_file3,
1106
+ L: 35,
1107
+ S: void 0,
1108
+ C: (f, a) => f(...a)
1109
+ });
1110
+ setEdgeReplication(!next);
1111
+ });
1112
+ }, [
1113
+ space
1114
+ ]);
1115
+ return /* @__PURE__ */ React18.createElement(DeprecatedFormContainer2, null, /* @__PURE__ */ React18.createElement(DeprecatedFormInput2, {
1116
+ label: t("name label")
1117
+ }, /* @__PURE__ */ React18.createElement(Input5.TextInput, {
1118
+ placeholder: t("unnamed space label"),
1119
+ value: space.properties.name ?? "",
1120
+ onChange: (event) => {
1121
+ space.properties.name = event.target.value;
1122
+ }
1123
+ })), edgeEnabled && /* @__PURE__ */ React18.createElement(DeprecatedFormInput2, {
1124
+ label: t("edge replication label")
1125
+ }, /* @__PURE__ */ React18.createElement(Input5.Switch, {
1126
+ checked: edgeReplication,
1127
+ onCheckedChange: toggleEdgeReplication
1128
+ })));
1129
+ };
1130
+
1131
+ // packages/plugins/plugin-space/src/components/SpaceSettings/SpaceSettingsDialog.tsx
1132
+ import React19, { useMemo as useMemo2, useState as useState10 } from "react";
1133
+ import { Surface as Surface2, useCapabilities } from "@dxos/app-framework";
1134
+ import { useClient as useClient7 } from "@dxos/react-client";
1135
+ import { Button as Button6, Clipboard, Dialog as Dialog4, Icon as Icon4, toLocalizedString as toLocalizedString3, useTranslation as useTranslation18 } from "@dxos/react-ui";
1136
+ import { Tabs } from "@dxos/react-ui-tabs";
1137
+ import { SpacePanel } from "@dxos/shell/react";
1138
+ var SPACE_SETTINGS_DIALOG = `${SPACE_PLUGIN}/SpaceSettingsDialog`;
1139
+ var SpaceSettingsDialog = ({ space, target, createInvitationUrl, initialTab = "members", namesCache }) => {
1140
+ const { t } = useTranslation18(SPACE_PLUGIN);
1141
+ const client = useClient7();
1142
+ const [tabsActivePart, setTabsActivePart] = useState10("list");
1143
+ const [selected, setSelected] = useState10(initialTab);
1144
+ const locked = space.properties[COMPOSER_SPACE_LOCK];
1145
+ const name = getSpaceDisplayName(space, {
1146
+ personal: client.spaces.default === space,
1147
+ namesCache
1148
+ });
1149
+ const panels = useCapabilities(SpaceCapabilities.SettingsPanel);
1150
+ const data = useMemo2(() => ({
1151
+ subject: space
1152
+ }), [
1153
+ space
1154
+ ]);
1155
+ return (
1156
+ // TODO(wittjosiah): The tablist dialog pattern is copied from @dxos/plugin-manager.
1157
+ // Consider factoring it out to the tabs package.
1158
+ /* @__PURE__ */ React19.createElement(Dialog4.Content, {
1159
+ classNames: "p-0 bs-content min-bs-[15rem] max-bs-full md:max-is-[40rem] overflow-hidden"
1160
+ }, /* @__PURE__ */ React19.createElement("div", {
1161
+ role: "none",
1162
+ className: "flex justify-between pbs-2 pis-2 pie-2 @md:pbs-4 @md:pis-4 @md:pie-4"
1163
+ }, /* @__PURE__ */ React19.createElement(Dialog4.Title, {
1164
+ onClick: () => setTabsActivePart("list"),
1165
+ "aria-description": t("click to return to tablist description"),
1166
+ classNames: "flex cursor-pointer items-center group/title"
1167
+ }, /* @__PURE__ */ React19.createElement(Icon4, {
1168
+ icon: "ph--caret-left--regular",
1169
+ size: 4,
1170
+ classNames: [
1171
+ "@md:hidden",
1172
+ tabsActivePart === "list" && "invisible"
1173
+ ]
1174
+ }), /* @__PURE__ */ React19.createElement("span", {
1175
+ className: tabsActivePart !== "list" ? "group-hover/title:underline @md:group-hover/title:no-underline underline-offset-4 decoration-1" : ""
1176
+ }, toLocalizedString3(name, t))), /* @__PURE__ */ React19.createElement(Dialog4.Close, {
1177
+ asChild: true
1178
+ }, /* @__PURE__ */ React19.createElement(Button6, {
1179
+ density: "fine",
1180
+ variant: "ghost",
1181
+ autoFocus: true
1182
+ }, /* @__PURE__ */ React19.createElement(Icon4, {
1183
+ icon: "ph--x--regular",
1184
+ size: 4
1185
+ })))), /* @__PURE__ */ React19.createElement(Tabs.Root, {
1186
+ orientation: "vertical",
1187
+ value: selected,
1188
+ onValueChange: setSelected,
1189
+ activePart: tabsActivePart,
1190
+ onActivePartChange: setTabsActivePart,
1191
+ classNames: "flex flex-col flex-1 mbs-2"
1192
+ }, /* @__PURE__ */ React19.createElement(Tabs.Viewport, {
1193
+ classNames: "flex-1 min-bs-0"
1194
+ }, /* @__PURE__ */ React19.createElement("div", {
1195
+ role: "none",
1196
+ className: "overflow-y-auto pli-3 @md:pis-2 @md:pie-0 mbe-4 border-r border-separator"
1197
+ }, /* @__PURE__ */ React19.createElement(Tabs.Tablist, {
1198
+ classNames: "flex flex-col max-bs-none min-is-[200px] gap-4 overflow-y-auto"
1199
+ }, /* @__PURE__ */ React19.createElement("div", {
1200
+ role: "none",
1201
+ className: "flex flex-col ml-1"
1202
+ }, /* @__PURE__ */ React19.createElement(Tabs.Tab, {
1203
+ value: "settings"
1204
+ }, t("settings tab label")), /* @__PURE__ */ React19.createElement(Tabs.Tab, {
1205
+ value: "members",
1206
+ disabled: locked
1207
+ }, t("members tab label")), panels.map((panel) => /* @__PURE__ */ React19.createElement(Tabs.Tab, {
1208
+ key: panel.id,
1209
+ value: panel.id
1210
+ }, toLocalizedString3(panel.label, t)))))), /* @__PURE__ */ React19.createElement(Tabs.Tabpanel, {
1211
+ value: "settings",
1212
+ classNames: "pli-3 @md:pli-5 max-bs-dvh overflow-y-auto"
1213
+ }, /* @__PURE__ */ React19.createElement(SpaceSettingsPanel, {
1214
+ space
1215
+ })), /* @__PURE__ */ React19.createElement(Tabs.Tabpanel, {
1216
+ value: "members",
1217
+ classNames: "pli-3 @md:pli-5 max-bs-dvh overflow-y-auto"
1218
+ }, /* @__PURE__ */ React19.createElement(Clipboard.Provider, null, /* @__PURE__ */ React19.createElement(SpacePanel, {
1219
+ space,
1220
+ hideHeading: true,
1221
+ target,
1222
+ createInvitationUrl
1223
+ }))), panels.map((panel) => /* @__PURE__ */ React19.createElement(Tabs.Tabpanel, {
1224
+ key: panel.id,
1225
+ value: panel.id,
1226
+ classNames: "pli-3 @md:pli-5 max-bs-dvh overflow-y-auto"
1227
+ }, /* @__PURE__ */ React19.createElement(Surface2, {
1228
+ role: `space-settings--${panel.id}`,
1229
+ data
1230
+ }))))))
1231
+ );
1232
+ };
1233
+
1234
+ // packages/plugins/plugin-space/src/components/SyncStatus/InlineSyncStatus.tsx
1235
+ import React20, { useEffect as useEffect6, useState as useState12 } from "react";
1236
+ import { useAppGraph as useAppGraph3 } from "@dxos/app-framework";
1237
+ import { QueryEdgeStatusResponse } from "@dxos/protocols/proto/dxos/client/services";
1238
+ import { EdgeReplicationSetting as EdgeReplicationSetting2 } from "@dxos/protocols/proto/dxos/echo/metadata";
1239
+ import { useClient as useClient9 } from "@dxos/react-client";
1240
+ import { Tooltip as Tooltip3, useTranslation as useTranslation19 } from "@dxos/react-ui";
1241
+ import { AttentionGlyph as AttentionGlyph2, useAttended as useAttended2, useAttention as useAttention2 } from "@dxos/react-ui-attention";
1242
+
1243
+ // packages/plugins/plugin-space/src/components/SyncStatus/sync-state.ts
1244
+ import { useEffect as useEffect5, useState as useState11 } from "react";
1245
+ import { Context } from "@dxos/context";
1246
+ import { EdgeService } from "@dxos/protocols";
1247
+ import { useClient as useClient8 } from "@dxos/react-client";
1248
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SyncStatus/sync-state.ts";
1249
+ var createEmptyEdgeSyncState = () => ({
1250
+ missingOnLocal: 0,
1251
+ missingOnRemote: 0,
1252
+ localDocumentCount: 0,
1253
+ remoteDocumentCount: 0,
1254
+ differentDocuments: 0
1255
+ });
1256
+ var getSyncSummary = (syncMap) => {
1257
+ return Object.entries(syncMap).reduce((summary, [_spaceId, peerState]) => {
1258
+ summary.missingOnLocal += peerState.missingOnLocal;
1259
+ summary.missingOnRemote += peerState.missingOnRemote;
1260
+ summary.localDocumentCount += peerState.localDocumentCount;
1261
+ summary.remoteDocumentCount += peerState.remoteDocumentCount;
1262
+ summary.differentDocuments += peerState.differentDocuments;
1263
+ return summary;
1264
+ }, createEmptyEdgeSyncState());
1265
+ };
1266
+ var isEdgePeerId = (peerId, spaceId) => peerId.startsWith(`${EdgeService.AUTOMERGE_REPLICATOR}:${spaceId}`);
1267
+ var useSyncState = () => {
1268
+ const client = useClient8();
1269
+ const [spaceState, setSpaceState] = useState11({});
1270
+ useEffect5(() => {
1271
+ const ctx = new Context(void 0, {
1272
+ F: __dxlog_file4,
1273
+ L: 48
1274
+ });
1275
+ const createSubscriptions = (spaces) => {
1276
+ for (const space of spaces) {
1277
+ if (spaceState[space.id]) {
1278
+ continue;
1279
+ }
1280
+ ctx.onDispose(space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {
1281
+ const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
1282
+ if (syncState) {
1283
+ setSpaceState((spaceState2) => ({
1284
+ ...spaceState2,
1285
+ [space.id]: syncState
1286
+ }));
1287
+ }
1288
+ }));
1289
+ }
1290
+ };
1291
+ createSubscriptions(client.spaces.get());
1292
+ client.spaces.subscribe((spaces) => {
1293
+ createSubscriptions(spaces);
1294
+ });
1295
+ return () => {
1296
+ void ctx.dispose();
1297
+ };
1298
+ }, [
1299
+ client
1300
+ ]);
1301
+ return spaceState;
1302
+ };
1303
+ var useSpaceSyncState = (space) => {
1304
+ const [spaceState, setSpaceState] = useState11();
1305
+ useEffect5(() => {
1306
+ const ctx = new Context(void 0, {
1307
+ F: __dxlog_file4,
1308
+ L: 87
1309
+ });
1310
+ space.crud.subscribeToSyncState(ctx, ({ peers = [] }) => {
1311
+ const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));
1312
+ if (syncState) {
1313
+ setSpaceState(syncState);
1314
+ }
1315
+ });
1316
+ return () => {
1317
+ void ctx.dispose();
1318
+ };
1319
+ }, [
1320
+ space
1321
+ ]);
1322
+ return spaceState;
1323
+ };
1324
+
1325
+ // packages/plugins/plugin-space/src/components/SyncStatus/InlineSyncStatus.tsx
1326
+ var useEdgeStatus = () => {
1327
+ const [status, setStatus] = useState12(QueryEdgeStatusResponse.EdgeStatus.NOT_CONNECTED);
1328
+ const client = useClient9();
1329
+ useEffect6(() => {
1330
+ client.services.services.EdgeAgentService?.queryEdgeStatus().subscribe(({ status: status2 }) => {
1331
+ setStatus(status2);
1332
+ });
1333
+ }, [
1334
+ client
1335
+ ]);
1336
+ return status;
1337
+ };
1338
+ var InlineSyncStatus = ({ space, open }) => {
1339
+ const { t } = useTranslation19(SPACE_PLUGIN);
1340
+ const id = space.id;
1341
+ const { hasAttention, isAncestor, isRelated } = useAttention2(id);
1342
+ const isAttended = hasAttention || isAncestor || isRelated;
1343
+ const { graph } = useAppGraph3();
1344
+ const attended = useAttended2();
1345
+ const startOfAttention = attended.at(-1);
1346
+ const path = usePath(graph, startOfAttention);
1347
+ const containsAttended = !open && !isAttended && id && path ? path.includes(id) : false;
1348
+ const connectedToEdge = useEdgeStatus() === QueryEdgeStatusResponse.EdgeStatus.CONNECTED;
1349
+ const edgeSyncEnabled = space.internal.data.edgeReplication === EdgeReplicationSetting2.ENABLED;
1350
+ const syncState = useSpaceSyncState(space);
1351
+ const syncing = connectedToEdge && edgeSyncEnabled && syncState && syncState.missingOnLocal > 0;
1352
+ return /* @__PURE__ */ React20.createElement(Tooltip3.Root, null, /* @__PURE__ */ React20.createElement(Tooltip3.Trigger, {
1353
+ asChild: true
1354
+ }, /* @__PURE__ */ React20.createElement(AttentionGlyph2, {
1355
+ syncing,
1356
+ attended: isAttended,
1357
+ containsAttended,
1358
+ classNames: "self-center mie-1"
1359
+ })), /* @__PURE__ */ React20.createElement(Tooltip3.Portal, null, /* @__PURE__ */ React20.createElement(Tooltip3.Content, {
1360
+ side: "bottom",
1361
+ classNames: "z-[70]"
1362
+ }, /* @__PURE__ */ React20.createElement("span", null, t("syncing label")), /* @__PURE__ */ React20.createElement(Tooltip3.Arrow, null))));
1363
+ };
1364
+
1365
+ // packages/plugins/plugin-space/src/components/SyncStatus/SyncStatus.tsx
1366
+ import React22, { useCallback as useCallback12, useEffect as useEffect8, useState as useState14 } from "react";
1367
+ import { StatusBar } from "@dxos/plugin-status-bar";
1368
+ import { useClient as useClient11 } from "@dxos/react-client";
1369
+ import { Icon as Icon6, Input as Input6, Popover as Popover3, useTranslation as useTranslation21 } from "@dxos/react-ui";
1370
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
1371
+ import { mx as mx6 } from "@dxos/react-ui-theme";
1372
+
1373
+ // packages/plugins/plugin-space/src/components/SyncStatus/Space.tsx
1374
+ import React21, { useEffect as useEffect7, useState as useState13 } from "react";
1375
+ import { useClient as useClient10 } from "@dxos/react-client";
1376
+ import { useSpace } from "@dxos/react-client/echo";
1377
+ import { Icon as Icon5, toLocalizedString as toLocalizedString4, useTranslation as useTranslation20 } from "@dxos/react-ui";
1378
+ import { mx as mx5 } from "@dxos/react-ui-theme";
1379
+ var SYNC_STALLED_TIMEOUT = 5e3;
1380
+ var styles = {
1381
+ barBg: "bg-neutral-50 dark:bg-green-900 text-black",
1382
+ barFg: "bg-neutral-100 bg-green-500",
1383
+ barHover: "dark:hover:bg-green-500"
1384
+ };
1385
+ var useActive = (count) => {
1386
+ const [current, setCurrent] = useState13(count);
1387
+ const [active, setActive] = useState13(false);
1388
+ useEffect7(() => {
1389
+ let t;
1390
+ if (count !== current) {
1391
+ setActive(true);
1392
+ setCurrent(count);
1393
+ t && clearTimeout(t);
1394
+ t = setTimeout(() => {
1395
+ setActive(false);
1396
+ }, SYNC_STALLED_TIMEOUT);
1397
+ }
1398
+ return () => {
1399
+ setActive(false);
1400
+ clearTimeout(t);
1401
+ };
1402
+ }, [
1403
+ count,
1404
+ current
1405
+ ]);
1406
+ return active;
1407
+ };
1408
+ var SpaceRowContainer = ({ spaceId, state }) => {
1409
+ const { t } = useTranslation20(SPACE_PLUGIN);
1410
+ const client = useClient10();
1411
+ const space = useSpace(spaceId);
1412
+ if (!space) {
1413
+ return null;
1414
+ }
1415
+ const spaceName = toLocalizedString4(getSpaceDisplayName(space, {
1416
+ personal: space === client.spaces.default
1417
+ }), t);
1418
+ return /* @__PURE__ */ React21.createElement(SpaceRow, {
1419
+ spaceId,
1420
+ spaceName,
1421
+ state
1422
+ });
1423
+ };
1424
+ var SpaceRow = ({ spaceId, spaceName, state: { localDocumentCount, remoteDocumentCount, missingOnLocal, missingOnRemote } }) => {
1425
+ const downActive = useActive(localDocumentCount);
1426
+ const upActive = useActive(remoteDocumentCount);
1427
+ return /* @__PURE__ */ React21.createElement("div", {
1428
+ className: "flex items-center mx-0.5 gap-0.5 cursor-pointer",
1429
+ title: spaceId,
1430
+ onClick: () => {
1431
+ void navigator.clipboard.writeText(spaceId);
1432
+ }
1433
+ }, /* @__PURE__ */ React21.createElement("span", {
1434
+ className: "is-1/2 truncate"
1435
+ }, spaceName), /* @__PURE__ */ React21.createElement(Icon5, {
1436
+ icon: "ph--arrow-fat-line-left--regular",
1437
+ size: 3,
1438
+ classNames: mx5(downActive && "animate-[pulse_1s_infinite]")
1439
+ }), /* @__PURE__ */ React21.createElement(Candle, {
1440
+ up: {
1441
+ count: remoteDocumentCount,
1442
+ total: remoteDocumentCount + missingOnRemote
1443
+ },
1444
+ down: {
1445
+ count: localDocumentCount,
1446
+ total: localDocumentCount + missingOnLocal
1447
+ },
1448
+ title: spaceId
1449
+ }), /* @__PURE__ */ React21.createElement(Icon5, {
1450
+ icon: "ph--arrow-fat-line-right--regular",
1451
+ size: 3,
1452
+ classNames: mx5(upActive && "animate-[pulse_1s_step-start_infinite]")
1453
+ }));
1454
+ };
1455
+ var Candle = ({ classNames, up, down }) => {
1456
+ return /* @__PURE__ */ React21.createElement("div", {
1457
+ className: mx5("grid grid-cols-[1fr_2rem_1fr] w-full h-3", classNames)
1458
+ }, /* @__PURE__ */ React21.createElement(Bar, {
1459
+ classNames: "justify-end",
1460
+ ...up
1461
+ }), /* @__PURE__ */ React21.createElement("div", {
1462
+ className: "relative"
1463
+ }, /* @__PURE__ */ React21.createElement("div", {
1464
+ className: mx5("absolute inset-0 flex items-center justify-center text-xs", styles.barBg)
1465
+ }, up.total)), /* @__PURE__ */ React21.createElement(Bar, down));
1466
+ };
1467
+ var Bar = ({ classNames, count, total }) => {
1468
+ let p = count / total * 100;
1469
+ if (count < total) {
1470
+ p = Math.min(p, 95);
1471
+ }
1472
+ return /* @__PURE__ */ React21.createElement("div", {
1473
+ className: mx5("relative flex w-full", styles.barBg, classNames)
1474
+ }, /* @__PURE__ */ React21.createElement("div", {
1475
+ className: mx5("shrink-0", styles.barFg),
1476
+ style: {
1477
+ width: `${p}%`
1478
+ }
1479
+ }), count !== total && /* @__PURE__ */ React21.createElement("div", {
1480
+ className: "absolute top-0 bottom-0 flex items-center mx-0.5 text-black text-xs"
1481
+ }, count));
1482
+ };
1483
+
1484
+ // packages/plugins/plugin-space/src/components/SyncStatus/save-tracker.ts
1485
+ import { Context as Context2 } from "@dxos/context";
1486
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-space/src/components/SyncStatus/save-tracker.ts";
1487
+ var createClientSaveTracker = (client, cb) => {
1488
+ const unsubscribeCallbacks = {};
1489
+ const state = {};
1490
+ const install = (spaces) => {
1491
+ for (const space of spaces) {
1492
+ if (state[space.id]) {
1493
+ continue;
1494
+ }
1495
+ state[space.id] = "saved";
1496
+ unsubscribeCallbacks[space.id] = createSpaceSaveTracker(space, (s) => {
1497
+ state[space.id] = s;
1498
+ cb(Object.values(state).some((s2) => s2 === "saving") ? "saving" : "saved");
1499
+ });
1500
+ }
1501
+ };
1502
+ client.spaces.subscribe((spaces) => {
1503
+ install(spaces);
1504
+ });
1505
+ install(client.spaces.get());
1506
+ return () => {
1507
+ for (const unsubscribe of Object.values(unsubscribeCallbacks)) {
1508
+ unsubscribe();
1509
+ }
1510
+ };
1511
+ };
1512
+ var createSpaceSaveTracker = (space, cb) => {
1513
+ const ctx = new Context2(void 0, {
1514
+ F: __dxlog_file5,
1515
+ L: 40
1516
+ });
1517
+ void space.waitUntilReady().then(() => {
1518
+ if (ctx.disposed) {
1519
+ return;
1520
+ }
1521
+ let hasUnsavedChanges = false;
1522
+ let lastFlushPromise;
1523
+ space.crud.saveStateChanged.on(ctx, ({ unsavedDocuments }) => {
1524
+ hasUnsavedChanges = unsavedDocuments.length > 0;
1525
+ });
1526
+ space.crud.saveStateChanged.debounce(500).on(ctx, () => {
1527
+ if (hasUnsavedChanges) {
1528
+ lastFlushPromise = void 0;
1529
+ cb("saving");
1530
+ } else {
1531
+ const flushPromise = space.crud.flush();
1532
+ lastFlushPromise = flushPromise;
1533
+ void flushPromise.then(() => {
1534
+ if (lastFlushPromise === flushPromise) {
1535
+ cb("saved");
1536
+ }
1537
+ });
1538
+ }
1539
+ });
1540
+ });
1541
+ return () => {
1542
+ void ctx.dispose();
1543
+ };
1544
+ };
1545
+
1546
+ // packages/plugins/plugin-space/src/components/SyncStatus/status.ts
1547
+ var getStatus = ({ offline, saved, needsToUpload, needsToDownload }) => {
1548
+ if (!saved) {
1549
+ return "saving locally";
1550
+ } else if (!offline && needsToDownload) {
1551
+ return "downloading";
1552
+ } else if (!offline && needsToUpload) {
1553
+ return "uploading";
1554
+ } else if (offline && !needsToUpload && !needsToDownload) {
1555
+ return "offline persisted";
1556
+ } else {
1557
+ return "remote synced";
1558
+ }
1559
+ };
1560
+ var getIcon = (status) => {
1561
+ switch (status) {
1562
+ case "saving locally":
1563
+ return "ph--download--regular";
1564
+ case "downloading":
1565
+ return "ph--cloud-arrow-down--regular";
1566
+ case "uploading":
1567
+ return "ph--cloud-arrow-up--regular";
1568
+ case "offline persisted":
1569
+ return "ph--check-circle--regular";
1570
+ case "remote synced":
1571
+ return "ph--cloud-check--regular";
1572
+ }
1573
+ };
1574
+
1575
+ // packages/plugins/plugin-space/src/components/SyncStatus/SyncStatus.tsx
1576
+ var SyncStatus = () => {
1577
+ const client = useClient11();
1578
+ const state = useSyncState();
1579
+ const [saved, setSaved] = useState14(true);
1580
+ useEffect8(() => {
1581
+ return createClientSaveTracker(client, (state2) => {
1582
+ setSaved(state2 === "saved");
1583
+ });
1584
+ }, []);
1585
+ return /* @__PURE__ */ React22.createElement(SyncStatusIndicator, {
1586
+ state,
1587
+ saved
1588
+ });
1589
+ };
1590
+ var SyncStatusIndicator = ({ state, saved }) => {
1591
+ const { t } = useTranslation21(SPACE_PLUGIN);
1592
+ const summary = getSyncSummary(state);
1593
+ const offline = Object.values(state).length === 0;
1594
+ const needsToUpload = summary.differentDocuments > 0 || summary.missingOnRemote > 0;
1595
+ const needsToDownload = summary.differentDocuments > 0 || summary.missingOnLocal > 0;
1596
+ const status = getStatus({
1597
+ offline,
1598
+ saved,
1599
+ needsToUpload,
1600
+ needsToDownload
1601
+ });
1602
+ const [classNames, setClassNames] = useState14();
1603
+ useEffect8(() => {
1604
+ setClassNames(void 0);
1605
+ if (offline || !needsToUpload && !needsToDownload) {
1606
+ return;
1607
+ }
1608
+ const t2 = setTimeout(() => {
1609
+ setClassNames("text-orange-500");
1610
+ }, SYNC_STALLED_TIMEOUT);
1611
+ return () => clearTimeout(t2);
1612
+ }, [
1613
+ offline,
1614
+ needsToUpload,
1615
+ needsToDownload
1616
+ ]);
1617
+ const title = t(`${status} label`);
1618
+ const icon = /* @__PURE__ */ React22.createElement(Icon6, {
1619
+ icon: getIcon(status),
1620
+ size: 4,
1621
+ classNames
1622
+ });
1623
+ if (offline) {
1624
+ return /* @__PURE__ */ React22.createElement(StatusBar.Item, {
1625
+ title
1626
+ }, icon);
1627
+ } else {
1628
+ return /* @__PURE__ */ React22.createElement(Popover3.Root, null, /* @__PURE__ */ React22.createElement(Popover3.Trigger, {
1629
+ asChild: true
1630
+ }, /* @__PURE__ */ React22.createElement(StatusBar.Button, {
1631
+ title
1632
+ }, icon)), /* @__PURE__ */ React22.createElement(Popover3.Portal, null, /* @__PURE__ */ React22.createElement(Popover3.Content, null, /* @__PURE__ */ React22.createElement(SyncStatusDetail, {
1633
+ state,
1634
+ summary,
1635
+ debug: false
1636
+ }), /* @__PURE__ */ React22.createElement(Popover3.Arrow, null))));
1637
+ }
1638
+ };
1639
+ var SyncStatusDetail = ({ classNames, state, summary, debug }) => {
1640
+ const [showAll, setShowAll] = useState14(false);
1641
+ const { t } = useTranslation21(SPACE_PLUGIN);
1642
+ const entries = Object.entries(state).filter(([_, value]) => showAll || value.missingOnLocal + value.missingOnRemote > 0).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
1643
+ const handleCheckedChange = useCallback12((state2) => setShowAll(state2), [
1644
+ setShowAll
1645
+ ]);
1646
+ return /* @__PURE__ */ React22.createElement("div", {
1647
+ className: mx6("flex flex-col gap-3 p-2 text-xs min-w-96", classNames)
1648
+ }, /* @__PURE__ */ React22.createElement("div", {
1649
+ role: "none",
1650
+ className: "flex items-center"
1651
+ }, /* @__PURE__ */ React22.createElement("h1", {
1652
+ className: "flex-1"
1653
+ }, t("sync status title")), /* @__PURE__ */ React22.createElement("div", {
1654
+ className: "flex items-center gap-2"
1655
+ }, /* @__PURE__ */ React22.createElement(Input6.Root, null, /* @__PURE__ */ React22.createElement(Input6.Label, {
1656
+ classNames: "text-xs"
1657
+ }, t("show all label")), /* @__PURE__ */ React22.createElement(Input6.Checkbox, {
1658
+ checked: showAll,
1659
+ onCheckedChange: handleCheckedChange
1660
+ })))), /* @__PURE__ */ React22.createElement("div", {
1661
+ className: "flex flex-col gap-2"
1662
+ }, entries.length === 0 && /* @__PURE__ */ React22.createElement("div", {
1663
+ role: "none",
1664
+ className: "flex justify-center"
1665
+ }, t("no sync status label")), entries.map(([spaceId, state2]) => /* @__PURE__ */ React22.createElement(SpaceRowContainer, {
1666
+ key: spaceId,
1667
+ spaceId,
1668
+ state: state2
1669
+ }))), debug && /* @__PURE__ */ React22.createElement(SyntaxHighlighter, {
1670
+ language: "json"
1671
+ }, JSON.stringify(summary, null, 2)));
1672
+ };
1673
+
1674
+ export {
1675
+ AdvancedObjectSettings,
1676
+ AwaitingObject,
1677
+ BaseObjectSettings,
1678
+ CREATE_OBJECT_DIALOG,
1679
+ CreateObjectDialog,
1680
+ CREATE_SPACE_DIALOG,
1681
+ CreateSpaceDialog,
1682
+ CollectionMain,
1683
+ CollectionSection,
1684
+ JOIN_DIALOG,
1685
+ JoinDialog,
1686
+ MenuFooter,
1687
+ PersistenceStatus,
1688
+ POPOVER_RENAME_OBJECT,
1689
+ PopoverRenameObject,
1690
+ POPOVER_RENAME_SPACE,
1691
+ PopoverRenameSpace,
1692
+ ShareSpaceButton,
1693
+ ShareSpaceButtonImpl,
1694
+ SpacePresence,
1695
+ FullPresence,
1696
+ SmallPresenceLive,
1697
+ SmallPresence,
1698
+ SpacePluginSettings,
1699
+ SpaceSettingsPanel,
1700
+ SPACE_SETTINGS_DIALOG,
1701
+ SpaceSettingsDialog,
1702
+ InlineSyncStatus,
1703
+ SyncStatus,
1704
+ SyncStatusIndicator,
1705
+ SyncStatusDetail,
1706
+ AppGraphBuilder,
1707
+ AppGraphSerializer,
1708
+ IdentityCreated,
1709
+ IntentResolver,
1710
+ ReactRoot,
1711
+ ReactSurface,
1712
+ SpaceSettings,
1713
+ SpaceState,
1714
+ SpacesReady
1715
+ };
1716
+ //# sourceMappingURL=chunk-4HICD7AU.mjs.map