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