@dxos/plugin-thread 0.7.4 → 0.7.5-main.9cb18ac

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 (72) hide show
  1. package/dist/lib/browser/{ThreadArticle-6IXTL7CH.mjs → ThreadArticle-EWLTNU6Z.mjs} +2 -2
  2. package/dist/lib/browser/{ThreadMain-4IAS67KE.mjs → ThreadMain-ABEDFWHC.mjs} +2 -2
  3. package/dist/lib/browser/chunk-6KTMQPL4.mjs +77 -0
  4. package/dist/lib/browser/chunk-6KTMQPL4.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-52HWDLBR.mjs → chunk-OD2IZKRP.mjs} +23 -45
  6. package/dist/lib/browser/chunk-OD2IZKRP.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +323 -480
  8. package/dist/lib/browser/index.mjs.map +3 -3
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/types.mjs +1 -1
  11. package/dist/lib/node/{ThreadArticle-I7ADXDW3.cjs → ThreadArticle-ZCNMFBAO.cjs} +6 -6
  12. package/dist/lib/node/{ThreadMain-MRNJC3TI.cjs → ThreadMain-5AYGCXXP.cjs} +6 -6
  13. package/dist/lib/node/{chunk-YCDM2SZM.cjs → chunk-2CB5AVBL.cjs} +27 -50
  14. package/dist/lib/node/chunk-2CB5AVBL.cjs.map +7 -0
  15. package/dist/lib/node/chunk-VW2P26MZ.cjs +96 -0
  16. package/dist/lib/node/chunk-VW2P26MZ.cjs.map +7 -0
  17. package/dist/lib/node/index.cjs +336 -491
  18. package/dist/lib/node/index.cjs.map +3 -3
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/types.cjs +2 -2
  21. package/dist/lib/node/types.cjs.map +1 -1
  22. package/dist/lib/node-esm/{ThreadArticle-CJHYMF2W.mjs → ThreadArticle-F37HYTOU.mjs} +2 -2
  23. package/dist/lib/node-esm/{ThreadMain-VISGW4IF.mjs → ThreadMain-OL6ZHNZY.mjs} +2 -2
  24. package/dist/lib/node-esm/{chunk-JG7MXH6O.mjs → chunk-AQ74G3GY.mjs} +23 -45
  25. package/dist/lib/node-esm/chunk-AQ74G3GY.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-RMYATBXM.mjs +78 -0
  27. package/dist/lib/node-esm/chunk-RMYATBXM.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +323 -480
  29. package/dist/lib/node-esm/index.mjs.map +3 -3
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/types.mjs +1 -1
  32. package/dist/types/src/ThreadPlugin.d.ts.map +1 -1
  33. package/dist/types/src/components/Chat.stories.d.ts.map +1 -1
  34. package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
  35. package/dist/types/src/components/CommentContainer.d.ts.map +1 -1
  36. package/dist/types/src/components/MessageContainer.d.ts.map +1 -1
  37. package/dist/types/src/components/ThreadComplementary.d.ts +1 -2
  38. package/dist/types/src/components/ThreadComplementary.d.ts.map +1 -1
  39. package/dist/types/src/components/testing.d.ts +50 -66
  40. package/dist/types/src/components/testing.d.ts.map +1 -1
  41. package/dist/types/src/extensions/threads.d.ts +2 -2
  42. package/dist/types/src/extensions/threads.d.ts.map +1 -1
  43. package/dist/types/src/hooks/analytics.d.ts.map +1 -1
  44. package/dist/types/src/types.d.ts +76 -8
  45. package/dist/types/src/types.d.ts.map +1 -1
  46. package/dist/types/tsconfig.tsbuildinfo +1 -0
  47. package/package.json +30 -30
  48. package/src/ThreadPlugin.tsx +215 -361
  49. package/src/components/Chat.stories.tsx +10 -8
  50. package/src/components/ChatContainer.tsx +13 -11
  51. package/src/components/CommentContainer.tsx +14 -11
  52. package/src/components/MessageContainer.tsx +7 -5
  53. package/src/components/ThreadComplementary.tsx +18 -32
  54. package/src/components/testing.ts +26 -22
  55. package/src/extensions/threads.ts +16 -25
  56. package/src/hooks/analytics.ts +6 -10
  57. package/src/types.ts +60 -9
  58. package/dist/lib/browser/chunk-52HWDLBR.mjs.map +0 -7
  59. package/dist/lib/browser/chunk-XUHNZID5.mjs +0 -20
  60. package/dist/lib/browser/chunk-XUHNZID5.mjs.map +0 -7
  61. package/dist/lib/node/chunk-XFO6D2LG.cjs +0 -39
  62. package/dist/lib/node/chunk-XFO6D2LG.cjs.map +0 -7
  63. package/dist/lib/node/chunk-YCDM2SZM.cjs.map +0 -7
  64. package/dist/lib/node-esm/chunk-I5MU54RT.mjs +0 -21
  65. package/dist/lib/node-esm/chunk-I5MU54RT.mjs.map +0 -7
  66. package/dist/lib/node-esm/chunk-JG7MXH6O.mjs.map +0 -7
  67. /package/dist/lib/browser/{ThreadArticle-6IXTL7CH.mjs.map → ThreadArticle-EWLTNU6Z.mjs.map} +0 -0
  68. /package/dist/lib/browser/{ThreadMain-4IAS67KE.mjs.map → ThreadMain-ABEDFWHC.mjs.map} +0 -0
  69. /package/dist/lib/node/{ThreadArticle-I7ADXDW3.cjs.map → ThreadArticle-ZCNMFBAO.cjs.map} +0 -0
  70. /package/dist/lib/node/{ThreadMain-MRNJC3TI.cjs.map → ThreadMain-5AYGCXXP.cjs.map} +0 -0
  71. /package/dist/lib/node-esm/{ThreadArticle-CJHYMF2W.mjs.map → ThreadArticle-F37HYTOU.mjs.map} +0 -0
  72. /package/dist/lib/node-esm/{ThreadMain-VISGW4IF.mjs.map → ThreadMain-OL6ZHNZY.mjs.map} +0 -0
@@ -28,33 +28,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var node_exports = {};
30
30
  __export(node_exports, {
31
- ThreadAction: () => import_chunk_XFO6D2LG.ThreadAction,
31
+ ThreadAction: () => import_chunk_VW2P26MZ.ThreadAction,
32
32
  ThreadPlugin: () => ThreadPlugin,
33
33
  default: () => src_default,
34
- useAnalyticsCallback: () => import_chunk_YCDM2SZM.useAnalyticsCallback,
35
- useOnEditAnalytics: () => import_chunk_YCDM2SZM.useOnEditAnalytics,
36
- useStatus: () => import_chunk_YCDM2SZM.useStatus
34
+ useAnalyticsCallback: () => import_chunk_2CB5AVBL.useAnalyticsCallback,
35
+ useOnEditAnalytics: () => import_chunk_2CB5AVBL.useOnEditAnalytics,
36
+ useStatus: () => import_chunk_2CB5AVBL.useStatus
37
37
  });
38
38
  module.exports = __toCommonJS(node_exports);
39
- var import_chunk_XFO6D2LG = require("./chunk-XFO6D2LG.cjs");
40
- var import_chunk_YCDM2SZM = require("./chunk-YCDM2SZM.cjs");
39
+ var import_chunk_VW2P26MZ = require("./chunk-VW2P26MZ.cjs");
40
+ var import_chunk_2CB5AVBL = require("./chunk-2CB5AVBL.cjs");
41
41
  var import_chunk_IC2NICNC = require("./chunk-IC2NICNC.cjs");
42
42
  var import_react = __toESM(require("react"));
43
43
  var import_app_framework = require("@dxos/app-framework");
44
+ var import_echo_schema = require("@dxos/echo-schema");
44
45
  var import_local_storage = require("@dxos/local-storage");
45
46
  var import_log = require("@dxos/log");
46
- var import_plugin_client = require("@dxos/plugin-client");
47
+ var import_types = require("@dxos/plugin-client/types");
47
48
  var import_plugin_graph = require("@dxos/plugin-graph");
48
- var import_meta = require("@dxos/plugin-observability/meta");
49
+ var import_types2 = require("@dxos/plugin-observability/types");
49
50
  var import_plugin_space = require("@dxos/plugin-space");
50
- var import_types = require("@dxos/plugin-space/types");
51
+ var import_types3 = require("@dxos/plugin-space/types");
51
52
  var import_echo = require("@dxos/react-client/echo");
52
53
  var import_react_ui_thread = require("@dxos/react-ui-thread");
53
54
  var import_react2 = require("react");
54
55
  var import_react3 = require("@phosphor-icons/react");
55
56
  var import_react4 = __toESM(require("react"));
56
57
  var import_live_object = require("@dxos/live-object");
57
- var import_types2 = require("@dxos/plugin-space/types");
58
+ var import_types4 = require("@dxos/plugin-space/types");
58
59
  var import_echo2 = require("@dxos/react-client/echo");
59
60
  var import_halo = require("@dxos/react-client/halo");
60
61
  var import_react_ui = require("@dxos/react-ui");
@@ -77,11 +78,13 @@ var import_react_ui3 = require("@dxos/react-ui");
77
78
  var import_react_ui_form = require("@dxos/react-ui-form");
78
79
  var import_view = require("@codemirror/view");
79
80
  var import_signals_core = require("@preact/signals-core");
80
- var import_types3 = require("@dxos/plugin-space/types");
81
+ var import_app_framework3 = require("@dxos/app-framework");
82
+ var import_echo_schema2 = require("@dxos/echo-schema");
83
+ var import_live_object2 = require("@dxos/live-object");
84
+ var import_types5 = require("@dxos/plugin-space/types");
81
85
  var import_echo5 = require("@dxos/react-client/echo");
82
86
  var import_react_ui_editor2 = require("@dxos/react-ui-editor");
83
- var import_util3 = require("@dxos/util");
84
- var import_types4 = require("@dxos/plugin-space/types");
87
+ var import_types6 = require("@dxos/plugin-space/types");
85
88
  var sizeClass = (0, import_react_ui_theme.getSize)(4);
86
89
  var commentControlClassNames = "!p-1 !min-bs-0 transition-opacity";
87
90
  var ToggleResolvedButton = ({ isResolved, onResolve }) => {
@@ -104,9 +107,7 @@ var ToggleResolvedButton = ({ isResolved, onResolve }) => {
104
107
  weight: "fill"
105
108
  }) : /* @__PURE__ */ import_react4.default.createElement(import_react3.CheckCircle, {
106
109
  className: sizeClass
107
- }))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Portal, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Content, {
108
- classNames: "z-[21]"
109
- }, label, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Arrow, null))));
110
+ }))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Portal, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Content, null, label, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Arrow, null))));
110
111
  };
111
112
  var DeleteThreadButton = ({ onDelete }) => {
112
113
  const { t } = (0, import_react_ui.useTranslation)(import_chunk_IC2NICNC.THREAD_PLUGIN);
@@ -126,18 +127,18 @@ var DeleteThreadButton = ({ onDelete }) => {
126
127
  }, label), /* @__PURE__ */ import_react4.default.createElement(import_react3.X, {
127
128
  className: sizeClass
128
129
  }))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Portal, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Content, {
129
- classNames: "z-[21]"
130
+ classNames: "z-30"
130
131
  }, label, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Arrow, null))));
131
132
  };
132
133
  var CommentContainer = ({ thread, detached, context, current, onAttend, onThreadDelete, onMessageDelete, onResolve, onComment }) => {
133
134
  const identity = (0, import_halo.useIdentity)();
134
135
  const space = (0, import_echo2.getSpace)(thread);
135
136
  const members = (0, import_echo2.useMembers)(space?.key);
136
- const activity = (0, import_chunk_YCDM2SZM.useStatus)(space, (0, import_echo2.fullyQualifiedId)(thread));
137
+ const activity = (0, import_chunk_2CB5AVBL.useStatus)(space, (0, import_echo2.fullyQualifiedId)(thread));
137
138
  const { t } = (0, import_react_ui.useTranslation)(import_chunk_IC2NICNC.THREAD_PLUGIN);
138
139
  const threadScrollRef = (0, import_react4.useRef)(null);
139
140
  const { themeMode } = (0, import_react_ui.useThemeContext)();
140
- const textboxMetadata = (0, import_chunk_YCDM2SZM.getMessageMetadata)((0, import_echo2.fullyQualifiedId)(thread), identity);
141
+ const textboxMetadata = (0, import_chunk_2CB5AVBL.getMessageMetadata)((0, import_echo2.fullyQualifiedId)(thread), identity);
141
142
  const [_count, _setCount] = (0, import_react4.useState)(0);
142
143
  const rerenderEditor = () => _setCount((count) => count + 1);
143
144
  const messageRef = (0, import_react4.useRef)("");
@@ -151,7 +152,7 @@ var CommentContainer = ({ thread, detached, context, current, onAttend, onThread
151
152
  (0, import_react_ui_editor.listener)({
152
153
  onChange: (text) => messageRef.current = text
153
154
  }),
154
- import_chunk_YCDM2SZM.command
155
+ import_chunk_2CB5AVBL.command
155
156
  ], [
156
157
  _count
157
158
  ]);
@@ -163,14 +164,14 @@ var CommentContainer = ({ thread, detached, context, current, onAttend, onThread
163
164
  if (!messageRef.current) {
164
165
  return false;
165
166
  }
166
- thread.messages.push((0, import_live_object.create)(import_types2.MessageType, {
167
+ thread.messages.push((0, import_live_object.makeRef)((0, import_live_object.create)(import_types4.MessageType, {
167
168
  sender: {
168
169
  identityKey: identity.identityKey.toHex()
169
170
  },
170
171
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
171
172
  text: messageRef.current,
172
- context
173
- }));
173
+ context: context ? (0, import_live_object.makeRef)(context) : void 0
174
+ })));
174
175
  onComment?.(thread);
175
176
  messageRef.current = "";
176
177
  scrollToEnd("instant");
@@ -193,7 +194,7 @@ var CommentContainer = ({ thread, detached, context, current, onAttend, onThread
193
194
  }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui_thread2.ThreadHeading, {
194
195
  detached: true
195
196
  }, thread.name)), /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Portal, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Content, {
196
- classNames: "z-[21]",
197
+ classNames: "z-30",
197
198
  side: "top"
198
199
  }, t("detached thread label"), /* @__PURE__ */ import_react4.default.createElement(import_react_ui.Tooltip.Arrow, null)))) : /* @__PURE__ */ import_react4.default.createElement(import_react_ui_thread2.ThreadHeading, null, thread.name), /* @__PURE__ */ import_react4.default.createElement("div", {
199
200
  className: "flex flex-row items-center pli-1"
@@ -204,7 +205,7 @@ var CommentContainer = ({ thread, detached, context, current, onAttend, onThread
204
205
  onResolve
205
206
  }), onThreadDelete && /* @__PURE__ */ import_react4.default.createElement(DeleteThreadButton, {
206
207
  onDelete: onThreadDelete
207
- }))), thread.messages.filter(import_util.nonNullable).map((message) => /* @__PURE__ */ import_react4.default.createElement(import_chunk_YCDM2SZM.MessageContainer, {
208
+ }))), import_live_object.RefArray.allResolvedTargets(thread.messages?.filter(import_util.nonNullable) ?? []).map((message) => /* @__PURE__ */ import_react4.default.createElement(import_chunk_2CB5AVBL.MessageContainer, {
208
209
  key: message.id,
209
210
  message,
210
211
  members,
@@ -271,8 +272,8 @@ var CommentsContainer = ({ threads: threads2, detached = [], currentId, showReso
271
272
  }))));
272
273
  };
273
274
  var providesThreadsConfig = (plugin) => "thread" in plugin.provides ? plugin : void 0;
274
- var ThreadComplementary = ({ role, subject, drafts, current, showResolvedThreads }) => {
275
- const dispatch = (0, import_app_framework2.useIntentDispatcher)();
275
+ var ThreadComplementary = ({ subject, drafts, current, showResolvedThreads }) => {
276
+ const { dispatchPromise: dispatch } = (0, import_app_framework2.useIntentDispatcher)();
276
277
  const threadsIntegrators = (0, import_app_framework2.useResolvePlugins)(providesThreadsConfig);
277
278
  const threadProvides = (0, import_react7.useMemo)(() => threadsIntegrators.map((p) => p.provides.thread), [
278
279
  threadsIntegrators
@@ -285,10 +286,11 @@ var ThreadComplementary = ({ role, subject, drafts, current, showResolvedThreads
285
286
  createSort,
286
287
  subject
287
288
  ]);
289
+ const threadObjects = import_echo4.RefArray.allResolvedTargets(subject.threads ?? []);
288
290
  const threads2 = (0, import_react7.useMemo)(() => {
289
- return subject.threads.concat(drafts ?? []).filter(import_util2.nonNullable);
291
+ return threadObjects.concat(drafts ?? []).filter(import_util2.nonNullable);
290
292
  }, [
291
- JSON.stringify(subject.threads),
293
+ JSON.stringify(threadObjects),
292
294
  JSON.stringify(drafts)
293
295
  ]);
294
296
  const detachedIds = (0, import_react7.useMemo)(() => {
@@ -316,53 +318,29 @@ var ThreadComplementary = ({ role, subject, drafts, current, showResolvedThreads
316
318
  const threadId = (0, import_echo4.fullyQualifiedId)(thread);
317
319
  if (current !== threadId) {
318
320
  current = threadId;
319
- void dispatch?.([
320
- {
321
- action: import_app_framework2.LayoutAction.SCROLL_INTO_VIEW,
322
- data: {
323
- id: (0, import_echo4.fullyQualifiedId)(subject),
324
- thread: threadId,
325
- cursor: thread.anchor
326
- }
327
- }
328
- ]);
321
+ void dispatch?.((0, import_app_framework2.createIntent)(import_app_framework2.LayoutAction.ScrollIntoView, {
322
+ id: (0, import_echo4.fullyQualifiedId)(subject),
323
+ cursor: thread.anchor,
324
+ ref: threadId
325
+ }));
329
326
  }
330
327
  },
331
- onThreadDelete: (thread) => {
332
- return dispatch({
333
- plugin: import_chunk_IC2NICNC.THREAD_PLUGIN,
334
- action: import_chunk_XFO6D2LG.ThreadAction.DELETE,
335
- data: {
336
- subject,
337
- thread
338
- }
339
- });
340
- },
341
- onMessageDelete: (thread, messageId) => dispatch({
342
- plugin: import_chunk_IC2NICNC.THREAD_PLUGIN,
343
- action: import_chunk_XFO6D2LG.ThreadAction.DELETE_MESSAGE,
344
- data: {
345
- subject,
346
- thread,
347
- messageId
348
- }
349
- }),
350
- onThreadToggleResolved: (thread) => dispatch({
351
- plugin: import_chunk_IC2NICNC.THREAD_PLUGIN,
352
- action: import_chunk_XFO6D2LG.ThreadAction.TOGGLE_RESOLVED,
353
- data: {
354
- thread
355
- }
356
- }),
357
- onComment: (thread) => {
358
- void dispatch({
359
- action: import_chunk_XFO6D2LG.ThreadAction.ON_MESSAGE_ADD,
360
- data: {
361
- thread,
362
- subject
363
- }
364
- });
365
- }
328
+ onThreadDelete: (thread) => dispatch((0, import_app_framework2.createIntent)(import_chunk_VW2P26MZ.ThreadAction.Delete, {
329
+ thread,
330
+ subject
331
+ })),
332
+ onMessageDelete: (thread, messageId) => dispatch((0, import_app_framework2.createIntent)(import_chunk_VW2P26MZ.ThreadAction.DeleteMessage, {
333
+ thread,
334
+ subject,
335
+ messageId
336
+ })),
337
+ onThreadToggleResolved: (thread) => dispatch((0, import_app_framework2.createIntent)(import_chunk_VW2P26MZ.ThreadAction.ToggleResolved, {
338
+ thread
339
+ })),
340
+ onComment: (thread) => dispatch((0, import_app_framework2.createIntent)(import_chunk_VW2P26MZ.ThreadAction.OnMessageAdd, {
341
+ thread,
342
+ subject
343
+ }))
366
344
  });
367
345
  };
368
346
  var ThreadSettings = ({ settings }) => {
@@ -374,12 +352,12 @@ var ThreadSettings = ({ settings }) => {
374
352
  onCheckedChange: (checked) => settings.standalone = !!checked
375
353
  })));
376
354
  };
377
- var ThreadMain = (0, import_react2.lazy)(() => import("./ThreadMain-MRNJC3TI.cjs"));
378
- var ThreadArticle = (0, import_react2.lazy)(() => import("./ThreadArticle-I7ADXDW3.cjs"));
355
+ var ThreadMain = (0, import_react2.lazy)(() => import("./ThreadMain-5AYGCXXP.cjs"));
356
+ var ThreadArticle = (0, import_react2.lazy)(() => import("./ThreadArticle-ZCNMFBAO.cjs"));
379
357
  var getName = (doc, anchor) => {
380
358
  if (doc.content) {
381
359
  const [start, end] = anchor.split(":");
382
- return (0, import_echo5.getTextInRange)((0, import_echo5.createDocAccessor)(doc.content, [
360
+ return (0, import_echo5.getTextInRange)((0, import_echo5.createDocAccessor)(doc.content.target, [
383
361
  "content"
384
362
  ]), start, end);
385
363
  }
@@ -392,14 +370,14 @@ var threads = (state, doc, dispatch) => {
392
370
  ];
393
371
  }
394
372
  const threads2 = (0, import_signals_core.computed)(() => [
395
- ...doc.threads.filter(import_util3.nonNullable),
373
+ ...import_live_object2.RefArray.allResolvedTargets(doc.threads),
396
374
  ...state.drafts[(0, import_echo5.fullyQualifiedId)(doc)] ?? []
397
375
  ].filter((thread) => !(thread?.status === "resolved")));
398
376
  return [
399
377
  import_view.EditorView.updateListener.of((update) => {
400
378
  if (update.docChanged) {
401
- doc.threads.forEach((thread) => {
402
- if (thread?.anchor) {
379
+ import_live_object2.RefArray.allResolvedTargets(doc.threads).forEach((thread) => {
380
+ if (thread.anchor) {
403
381
  const name = getName(doc, thread.anchor);
404
382
  if (name && name !== thread.name) {
405
383
  thread.name = name;
@@ -416,14 +394,11 @@ var threads = (state, doc, dispatch) => {
416
394
  id: (0, import_echo5.fullyQualifiedId)(doc),
417
395
  onCreate: ({ cursor }) => {
418
396
  const name = getName(doc, cursor);
419
- void dispatch({
420
- action: import_chunk_XFO6D2LG.ThreadAction.CREATE,
421
- data: {
422
- cursor,
423
- name,
424
- subject: doc
425
- }
426
- });
397
+ void dispatch((0, import_app_framework3.createIntent)(import_chunk_VW2P26MZ.ThreadAction.Create, {
398
+ cursor,
399
+ name,
400
+ subject: doc
401
+ }));
427
402
  },
428
403
  onDelete: ({ id }) => {
429
404
  const draft = state.drafts[(0, import_echo5.fullyQualifiedId)(doc)];
@@ -433,26 +408,26 @@ var threads = (state, doc, dispatch) => {
433
408
  draft.splice(index, 1);
434
409
  }
435
410
  }
436
- const thread = doc.threads.find((thread2) => thread2?.id === id);
411
+ const thread = doc.threads.find(import_echo_schema2.Ref.hasObjectId(id))?.target;
437
412
  if (thread) {
438
413
  thread.anchor = void 0;
439
414
  }
440
415
  },
441
416
  onUpdate: ({ id, cursor }) => {
442
- const thread = state.drafts[(0, import_echo5.fullyQualifiedId)(doc)]?.find((thread2) => (0, import_echo5.fullyQualifiedId)(thread2) === id) ?? doc.threads.find((thread2) => thread2?.id === id);
443
- if (thread instanceof import_types3.ThreadType && thread.anchor) {
417
+ const thread = state.drafts[(0, import_echo5.fullyQualifiedId)(doc)]?.find((thread2) => (0, import_echo5.fullyQualifiedId)(thread2) === id) ?? doc.threads.find(import_echo_schema2.Ref.hasObjectId(id))?.target;
418
+ if (thread instanceof import_types5.ThreadType && thread.anchor) {
444
419
  thread.name = getName(doc, thread.anchor);
445
420
  thread.anchor = cursor;
446
421
  }
447
422
  },
448
- onSelect: ({ selection: { current, closest } }) => {
449
- void dispatch({
450
- action: import_chunk_XFO6D2LG.ThreadAction.SELECT,
451
- data: {
452
- current: current ?? closest,
423
+ onSelect: ({ selection }) => {
424
+ const current = selection.current ?? selection.closest;
425
+ if (current) {
426
+ void dispatch((0, import_app_framework3.createIntent)(import_chunk_VW2P26MZ.ThreadAction.Select, {
427
+ current,
453
428
  skipOpen: true
454
- }
455
- });
429
+ }));
430
+ }
456
431
  }
457
432
  })
458
433
  ];
@@ -460,7 +435,7 @@ var threads = (state, doc, dispatch) => {
460
435
  var translations_default = [
461
436
  {
462
437
  "en-US": {
463
- [import_types4.ChannelType.typename]: {
438
+ [import_types6.ChannelType.typename]: {
464
439
  "typename label": "Channel"
465
440
  },
466
441
  [import_chunk_IC2NICNC.THREAD_PLUGIN]: {
@@ -513,7 +488,6 @@ var ThreadPlugin = () => {
513
488
  }
514
489
  return viewStore[subjectId];
515
490
  };
516
- let navigationPlugin;
517
491
  let intentPlugin;
518
492
  const unsubscribeCallbacks = [];
519
493
  return {
@@ -528,20 +502,19 @@ var ThreadPlugin = () => {
528
502
  return {
529
503
  echo: {
530
504
  system: [
531
- import_types.ThreadType,
532
- import_types.MessageType
505
+ import_types3.ThreadType,
506
+ import_types3.MessageType
533
507
  ],
534
508
  // TODO(wittjosiah): Requires reload.
535
509
  ...settings.values.standalone ? {
536
510
  schema: [
537
- import_types.ChannelType
511
+ import_types3.ChannelType
538
512
  ]
539
513
  } : {}
540
514
  }
541
515
  };
542
516
  },
543
- ready: async (plugins) => {
544
- navigationPlugin = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseNavigationPlugin);
517
+ ready: async ({ plugins }) => {
545
518
  intentPlugin = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseIntentPlugin);
546
519
  },
547
520
  unload: async () => {
@@ -551,8 +524,8 @@ var ThreadPlugin = () => {
551
524
  settings: settings.values,
552
525
  metadata: {
553
526
  records: {
554
- [import_types.ChannelType.typename]: {
555
- createObject: import_chunk_XFO6D2LG.ThreadAction.CREATE,
527
+ [import_types3.ChannelType.typename]: {
528
+ createObject: (props) => (0, import_app_framework.createIntent)(import_chunk_VW2P26MZ.ThreadAction.Create, props),
556
529
  placeholder: [
557
530
  "channel name placeholder",
558
531
  {
@@ -561,13 +534,13 @@ var ThreadPlugin = () => {
561
534
  ],
562
535
  icon: "ph--chat--regular",
563
536
  // TODO(wittjosiah): Move out of metadata.
564
- loadReferences: (channel) => (0, import_echo.loadObjectReferences)(channel, (channel2) => channel2.threads)
537
+ loadReferences: async (channel) => await import_echo.RefArray.loadAll(channel.threads ?? [])
565
538
  },
566
- [import_types.ThreadType.typename]: {
539
+ [import_types3.ThreadType.typename]: {
567
540
  // TODO(wittjosiah): Move out of metadata.
568
- loadReferences: (thread) => (0, import_echo.loadObjectReferences)(thread, (thread2) => thread2.messages)
541
+ loadReferences: async (thread) => await import_echo.RefArray.loadAll(thread.messages ?? [])
569
542
  },
570
- [import_types.MessageType.typename]: {
543
+ [import_types3.MessageType.typename]: {
571
544
  // TODO(wittjosiah): Move out of metadata.
572
545
  loadReferences: (message) => []
573
546
  },
@@ -612,8 +585,8 @@ var ThreadPlugin = () => {
612
585
  },
613
586
  graph: {
614
587
  builder: (plugins) => {
615
- const client = (0, import_app_framework.resolvePlugin)(plugins, import_plugin_client.parseClientPlugin)?.provides.client;
616
- const dispatch = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseIntentPlugin)?.provides.intent.dispatch;
588
+ const client = (0, import_app_framework.resolvePlugin)(plugins, import_types.parseClientPlugin)?.provides.client;
589
+ const dispatch = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseIntentPlugin)?.provides.intent.dispatchPromise;
617
590
  const metadataResolver = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseMetadataResolverPlugin)?.provides.metadata.resolver;
618
591
  if (!client || !dispatch || !metadataResolver) {
619
592
  return [];
@@ -683,20 +656,17 @@ var ThreadPlugin = () => {
683
656
  }
684
657
  const [spaceId, objectId] = dataId.split(":");
685
658
  const viewState = getViewState(dataId);
686
- const toggle = () => {
659
+ const toggle = async () => {
687
660
  const newToggleState = !viewState.showResolvedThreads;
688
661
  viewState.showResolvedThreads = newToggleState;
689
- void dispatch({
690
- action: import_meta.ObservabilityAction.SEND_EVENT,
691
- data: {
692
- name: "threads.toggle-show-resolved",
693
- properties: {
694
- spaceId,
695
- threadId: objectId,
696
- showResolved: newToggleState
697
- }
662
+ await dispatch((0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
663
+ name: "threads.toggle-show-resolved",
664
+ properties: {
665
+ spaceId,
666
+ threadId: objectId,
667
+ showResolved: newToggleState
698
668
  }
699
- });
669
+ }));
700
670
  };
701
671
  return [
702
672
  {
@@ -717,440 +687,315 @@ var ThreadPlugin = () => {
717
687
  }
718
688
  ];
719
689
  }
720
- }),
721
- (0, import_plugin_graph.createExtension)({
722
- id: import_chunk_XFO6D2LG.ThreadAction.CREATE,
723
- filter: (node) => !!settings.values.standalone && (0, import_plugin_graph.isActionGroup)(node) && node.id.startsWith(import_plugin_space.SpaceAction.ADD_OBJECT),
724
- actions: ({ node }) => {
725
- const id = node.id.split("/").at(-1);
726
- const [spaceId, objectId] = id?.split(":") ?? [];
727
- const space = client.spaces.get().find((space2) => space2.id === spaceId);
728
- const object = objectId && space?.db.getObjectById(objectId);
729
- const target = objectId ? object : space;
730
- if (!target) {
731
- return;
732
- }
733
- return [
734
- {
735
- id: `${import_chunk_IC2NICNC.THREAD_PLUGIN}/create/${node.id}`,
736
- data: async () => {
737
- await dispatch([
738
- {
739
- plugin: import_chunk_IC2NICNC.THREAD_PLUGIN,
740
- action: import_chunk_XFO6D2LG.ThreadAction.CREATE
741
- },
742
- {
743
- action: import_plugin_space.SpaceAction.ADD_OBJECT,
744
- data: {
745
- target
746
- }
747
- },
748
- {
749
- action: import_app_framework.NavigationAction.OPEN
750
- }
751
- ]);
752
- },
753
- properties: {
754
- label: [
755
- "create channel label",
756
- {
757
- ns: import_chunk_IC2NICNC.THREAD_PLUGIN
758
- }
759
- ],
760
- icon: "ph--chat--regular",
761
- testId: "threadPlugin.createObject"
762
- }
763
- }
764
- ];
765
- }
766
690
  })
767
691
  ];
768
692
  }
769
693
  },
770
694
  surface: {
771
- component: ({ data, role }) => {
772
- switch (role) {
773
- case "main": {
774
- return data.active instanceof import_types.ChannelType && data.active.threads[0] ? /* @__PURE__ */ import_react.default.createElement(ThreadMain, {
775
- thread: data.active.threads[0]
776
- }) : null;
777
- }
778
- case "settings": {
779
- return data.plugin === import_chunk_IC2NICNC.meta_default.id ? /* @__PURE__ */ import_react.default.createElement(ThreadSettings, {
780
- settings: settings.values
781
- }) : null;
782
- }
783
- case "article": {
784
- const location = navigationPlugin?.provides.location;
785
- if (data.object instanceof import_types.ChannelType && data.object.threads[0]) {
786
- const channel = data.object;
695
+ definitions: ({ plugins }) => {
696
+ const location = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseNavigationPlugin)?.provides.location;
697
+ return [
698
+ (0, import_app_framework.createSurface)({
699
+ id: `${import_chunk_IC2NICNC.THREAD_PLUGIN}/channel`,
700
+ role: "article",
701
+ filter: (data) => data.subject instanceof import_types3.ChannelType && !!data.subject.threads[0],
702
+ component: ({ data }) => {
703
+ const channel = data.subject;
704
+ const thread = channel.threads[0].target;
787
705
  if ((0, import_app_framework.isLayoutParts)(location?.active) && location.active.main) {
788
706
  const layoutEntries = location.active.main;
789
707
  const currentPosition = layoutEntries.findIndex((entry) => channel.id === entry.id);
790
708
  if (currentPosition > 0) {
791
709
  const objectToTheLeft = layoutEntries[currentPosition - 1];
792
- const context = (0, import_echo.getSpace)(data.object)?.db.getObjectById(objectToTheLeft.id);
710
+ const context = (0, import_echo.getSpace)(channel)?.db.getObjectById(objectToTheLeft.id);
793
711
  return /* @__PURE__ */ import_react.default.createElement(ThreadArticle, {
794
- thread: data.object.threads[0],
712
+ thread,
795
713
  context
796
714
  });
797
715
  }
798
716
  }
799
717
  return /* @__PURE__ */ import_react.default.createElement(ThreadArticle, {
800
- thread: data.object.threads[0]
718
+ thread
801
719
  });
802
720
  }
803
- if (data.subject instanceof import_types.ThreadType) {
804
- return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_chunk_YCDM2SZM.ChatHeading, {
805
- attendableId: data.subject.id
806
- }), /* @__PURE__ */ import_react.default.createElement(import_chunk_YCDM2SZM.ChatContainer, {
807
- thread: data.subject
808
- }));
809
- }
810
- break;
811
- }
812
- case "complementary--comments": {
813
- if (data.subject && typeof data.subject === "object" && "threads" in data.subject && Array.isArray(data.subject.threads) && !(data.subject instanceof import_types.ChannelType)) {
721
+ }),
722
+ (0, import_app_framework.createSurface)({
723
+ id: `${import_chunk_IC2NICNC.THREAD_PLUGIN}/thread`,
724
+ role: "complementary--comments",
725
+ filter: (data) => !!data.subject && typeof data.subject === "object" && "threads" in data.subject && Array.isArray(data.subject.threads) && !(data.subject instanceof import_types3.ChannelType),
726
+ component: ({ data }) => {
814
727
  const { showResolvedThreads } = getViewState((0, import_echo.fullyQualifiedId)(data.subject));
815
728
  return /* @__PURE__ */ import_react.default.createElement(ThreadComplementary, {
816
- role,
817
729
  subject: data.subject,
818
730
  drafts: state.drafts[(0, import_echo.fullyQualifiedId)(data.subject)],
819
731
  current: state.current,
820
732
  showResolvedThreads
821
733
  });
822
734
  }
823
- break;
824
- }
825
- }
826
- return null;
735
+ }),
736
+ (0, import_app_framework.createSurface)({
737
+ id: `${import_chunk_IC2NICNC.THREAD_PLUGIN}/settings`,
738
+ role: "settings",
739
+ filter: (data) => data.plugin === import_chunk_IC2NICNC.THREAD_PLUGIN,
740
+ component: () => /* @__PURE__ */ import_react.default.createElement(ThreadSettings, {
741
+ settings: settings.values
742
+ })
743
+ })
744
+ ];
827
745
  }
828
746
  },
829
747
  intent: {
830
- resolver: async (intent) => {
831
- switch (intent.action) {
832
- case import_chunk_XFO6D2LG.ThreadAction.CREATE: {
833
- if (intent.data && intent.data.cursor !== void 0) {
834
- const { cursor, name, subject } = intent.data;
835
- if (subject?.threads === void 0) {
836
- try {
837
- subject.threads = [];
838
- } catch (err) {
839
- import_log.log.error("Subject does not support threads array", subject?.typename, {
840
- F: __dxlog_file,
841
- L: 371,
842
- S: void 0,
843
- C: (f, a) => f(...a)
844
- });
845
- return;
846
- }
847
- }
848
- const subjectId = (0, import_echo.fullyQualifiedId)(subject);
849
- const thread = (0, import_echo.create)(import_types.ThreadType, {
850
- name,
851
- anchor: cursor,
852
- messages: [],
853
- status: "staged"
854
- });
855
- const draft = state.drafts[subjectId];
856
- if (draft) {
857
- draft.push(thread);
858
- } else {
859
- state.drafts[subjectId] = [
860
- thread
861
- ];
748
+ resolvers: () => [
749
+ (0, import_app_framework.createResolver)(import_chunk_VW2P26MZ.ThreadAction.Create, ({ name, cursor, subject }) => {
750
+ if (cursor && subject) {
751
+ if (subject?.threads === void 0) {
752
+ try {
753
+ subject.threads = [];
754
+ } catch (err) {
755
+ import_log.log.error("Subject does not support threads array", subject?.typename, {
756
+ F: __dxlog_file,
757
+ L: 314,
758
+ S: void 0,
759
+ C: (f, a) => f(...a)
760
+ });
761
+ return;
862
762
  }
863
- return {
864
- data: thread,
865
- intents: [
866
- [
867
- {
868
- action: import_chunk_XFO6D2LG.ThreadAction.SELECT,
869
- data: {
870
- current: (0, import_echo.fullyQualifiedId)(thread)
871
- }
872
- }
873
- ],
874
- [
875
- {
876
- action: import_app_framework.NavigationAction.OPEN,
877
- data: {
878
- activeParts: {
879
- complementary: "comments"
880
- }
881
- }
882
- }
883
- ],
884
- [
885
- {
886
- action: import_app_framework.LayoutAction.SET_LAYOUT,
887
- data: {
888
- element: "complementary",
889
- state: true
890
- }
891
- }
892
- ]
893
- ]
894
- };
763
+ }
764
+ const subjectId = (0, import_echo.fullyQualifiedId)(subject);
765
+ const thread = (0, import_echo.create)(import_types3.ThreadType, {
766
+ name,
767
+ anchor: cursor,
768
+ messages: [],
769
+ status: "staged"
770
+ });
771
+ const draft = state.drafts[subjectId];
772
+ if (draft) {
773
+ draft.push(thread);
895
774
  } else {
896
- return {
897
- data: (0, import_echo.create)(import_types.ChannelType, {
775
+ state.drafts[subjectId] = [
776
+ thread
777
+ ];
778
+ }
779
+ return {
780
+ data: {
781
+ object: thread
782
+ },
783
+ intents: [
784
+ (0, import_app_framework.createIntent)(import_chunk_VW2P26MZ.ThreadAction.Select, {
785
+ current: (0, import_echo.fullyQualifiedId)(thread)
786
+ }),
787
+ (0, import_app_framework.createIntent)(import_app_framework.NavigationAction.Open, {
788
+ activeParts: {
789
+ complementary: "comments"
790
+ }
791
+ }),
792
+ (0, import_app_framework.createIntent)(import_app_framework.LayoutAction.SetLayout, {
793
+ element: "complementary",
794
+ state: true
795
+ })
796
+ ]
797
+ };
798
+ } else {
799
+ return {
800
+ data: {
801
+ object: (0, import_echo.create)(import_types3.ChannelType, {
898
802
  threads: [
899
- (0, import_echo.create)(import_types.ThreadType, {
803
+ (0, import_echo.makeRef)((0, import_echo.create)(import_types3.ThreadType, {
900
804
  messages: []
901
- })
805
+ }))
902
806
  ]
903
807
  })
904
- };
808
+ }
809
+ };
810
+ }
811
+ }),
812
+ (0, import_app_framework.createResolver)(import_chunk_VW2P26MZ.ThreadAction.Select, ({ current, skipOpen }) => {
813
+ state.current = current;
814
+ return {
815
+ intents: !skipOpen ? [
816
+ (0, import_app_framework.createIntent)(import_app_framework.NavigationAction.Open, {
817
+ activeParts: {
818
+ complementary: "comments"
819
+ }
820
+ })
821
+ ] : void 0
822
+ };
823
+ }),
824
+ (0, import_app_framework.createResolver)(import_chunk_VW2P26MZ.ThreadAction.ToggleResolved, ({ thread }) => {
825
+ if (thread.status === "active" || thread.status === void 0) {
826
+ thread.status = "resolved";
827
+ } else if (thread.status === "resolved") {
828
+ thread.status = "active";
829
+ }
830
+ const space = (0, import_echo.getSpace)(thread);
831
+ const spaceId = space?.id;
832
+ return {
833
+ intents: [
834
+ (0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
835
+ name: "threads.toggle-resolved",
836
+ properties: {
837
+ threadId: thread.id,
838
+ spaceId
839
+ }
840
+ })
841
+ ]
842
+ };
843
+ }),
844
+ (0, import_app_framework.createResolver)(import_chunk_VW2P26MZ.ThreadAction.Delete, ({ subject, thread }, undo) => {
845
+ const subjectId = (0, import_echo.fullyQualifiedId)(subject);
846
+ const draft = state.drafts[subjectId];
847
+ if (draft) {
848
+ const index = draft.findIndex((t) => t.id === thread.id);
849
+ if (index !== -1) {
850
+ draft.splice(index, 1);
851
+ return;
905
852
  }
906
853
  }
907
- case import_chunk_XFO6D2LG.ThreadAction.SELECT: {
908
- state.current = intent.data?.current;
854
+ const space = (0, import_echo.getSpace)(thread);
855
+ if (!space || !subject.threads) {
856
+ return;
857
+ }
858
+ if (!undo) {
859
+ const index = subject.threads.findIndex((t) => t?.id === thread.id);
860
+ const cursor = subject.threads[index]?.anchor;
861
+ if (index !== -1) {
862
+ subject.threads?.splice(index, 1);
863
+ }
864
+ space.db.remove(thread);
909
865
  return {
910
- data: true,
911
- intents: !intent.data?.skipOpen ? [
912
- [
866
+ undoable: {
867
+ message: [
868
+ "thread deleted label",
913
869
  {
914
- action: import_app_framework.NavigationAction.OPEN,
915
- data: {
916
- activeParts: {
917
- complementary: "comments"
918
- }
919
- }
870
+ ns: import_chunk_IC2NICNC.THREAD_PLUGIN
920
871
  }
921
- ]
922
- ] : []
872
+ ],
873
+ data: {
874
+ cursor
875
+ }
876
+ },
877
+ intents: [
878
+ (0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
879
+ name: "threads.delete",
880
+ properties: {
881
+ threadId: thread.id,
882
+ spaceId: space.id
883
+ }
884
+ })
885
+ ]
923
886
  };
924
- }
925
- case import_chunk_XFO6D2LG.ThreadAction.TOGGLE_RESOLVED: {
926
- const { thread } = intent.data ?? {};
927
- if (!(thread instanceof import_types.ThreadType)) {
928
- return;
929
- }
930
- if (thread.status === "active" || thread.status === void 0) {
931
- thread.status = "resolved";
932
- } else if (thread.status === "resolved") {
933
- thread.status = "active";
934
- }
935
- const space = (0, import_echo.getSpace)(thread);
936
- const spaceId = space?.id;
887
+ } else {
888
+ const savedThread = space.db.add(thread);
889
+ subject.threads.push(savedThread);
937
890
  return {
938
- data: true,
939
891
  intents: [
940
- [
941
- {
942
- action: import_meta.ObservabilityAction.SEND_EVENT,
943
- data: {
944
- name: "threads.toggle-resolved",
945
- properties: {
946
- threadId: thread.id,
947
- spaceId
948
- }
949
- }
892
+ (0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
893
+ name: "threads.undo-delete",
894
+ properties: {
895
+ threadId: thread.id,
896
+ spaceId: space.id
950
897
  }
951
- ]
898
+ })
952
899
  ]
953
900
  };
954
901
  }
955
- case import_chunk_XFO6D2LG.ThreadAction.DELETE: {
956
- const { subject, thread } = intent.data ?? {};
957
- if (!(thread instanceof import_types.ThreadType) || !(subject && typeof subject === "object" && "threads" in subject)) {
958
- return;
959
- }
960
- const subjectId = (0, import_echo.fullyQualifiedId)(subject);
961
- const draft = state.drafts[subjectId];
962
- if (draft) {
963
- const index = draft.findIndex((t) => t.id === thread.id);
964
- if (index !== -1) {
965
- draft.splice(index, 1);
966
- return {
967
- data: true
968
- };
969
- }
902
+ }),
903
+ (0, import_app_framework.createResolver)(import_chunk_VW2P26MZ.ThreadAction.OnMessageAdd, ({ thread, subject }) => {
904
+ const subjectId = (0, import_echo.fullyQualifiedId)(subject);
905
+ const space = (0, import_echo.getSpace)(subject);
906
+ const intents = [];
907
+ const analyticsProperties = {
908
+ threadId: thread.id,
909
+ spaceId: space?.id
910
+ };
911
+ if (state.drafts[subjectId]?.find((t) => t === thread)) {
912
+ thread.status = "active";
913
+ subject.threads ? subject.threads.push((0, import_echo.makeRef)(thread)) : subject.threads = [
914
+ (0, import_echo.makeRef)(thread)
915
+ ];
916
+ state.drafts[subjectId] = state.drafts[subjectId]?.filter(({ id }) => id !== thread.id);
917
+ intents.push((0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
918
+ name: "threads.thread-created",
919
+ properties: analyticsProperties
920
+ }));
921
+ }
922
+ intents.push((0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
923
+ name: "threads.message-added",
924
+ properties: {
925
+ ...analyticsProperties,
926
+ threadLength: thread.messages.length
970
927
  }
971
- const space = (0, import_echo.getSpace)(thread);
972
- if (!space || !subject.threads) {
928
+ }));
929
+ return {
930
+ intents
931
+ };
932
+ }),
933
+ (0, import_app_framework.createResolver)(import_chunk_VW2P26MZ.ThreadAction.DeleteMessage, ({ subject, thread, messageId, message, messageIndex }, undo) => {
934
+ const space = (0, import_echo.getSpace)(subject);
935
+ if (!undo) {
936
+ const messageIndex2 = thread.messages.findIndex(import_echo_schema.Ref.hasObjectId(messageId));
937
+ const message2 = thread.messages[messageIndex2]?.target;
938
+ if (!message2) {
973
939
  return;
974
940
  }
975
- if (!intent.undo) {
976
- const index = subject.threads.findIndex((t) => t?.id === thread.id);
977
- const cursor = subject.threads[index]?.anchor;
978
- if (index !== -1) {
979
- subject.threads?.splice(index, 1);
980
- }
981
- space.db.remove(thread);
941
+ if (messageIndex2 === 0 && thread.messages.length === 1) {
982
942
  return {
983
- undoable: {
984
- message: translations_default[0]["en-US"][import_chunk_IC2NICNC.THREAD_PLUGIN]["thread deleted label"],
985
- data: {
986
- cursor
987
- }
988
- },
989
943
  intents: [
990
- [
991
- {
992
- action: import_meta.ObservabilityAction.SEND_EVENT,
993
- data: {
994
- name: "threads.delete",
995
- properties: {
996
- threadId: thread.id,
997
- spaceId: space.id
998
- }
999
- }
1000
- }
1001
- ]
1002
- ]
1003
- };
1004
- } else if (intent.undo) {
1005
- const savedThread = space.db.add(thread);
1006
- subject.threads.push(savedThread);
1007
- return {
1008
- data: true,
1009
- intents: [
1010
- [
1011
- {
1012
- action: import_meta.ObservabilityAction.SEND_EVENT,
1013
- data: {
1014
- name: "threads.undo-delete",
1015
- properties: {
1016
- threadId: thread.id,
1017
- spaceId: space.id
1018
- }
1019
- }
1020
- }
1021
- ]
944
+ (0, import_app_framework.createIntent)(import_chunk_VW2P26MZ.ThreadAction.Delete, {
945
+ subject,
946
+ thread
947
+ })
1022
948
  ]
1023
949
  };
950
+ } else {
951
+ thread.messages.splice(messageIndex2, 1);
1024
952
  }
1025
- break;
1026
- }
1027
- case import_chunk_XFO6D2LG.ThreadAction.ON_MESSAGE_ADD: {
1028
- const { thread, subject } = intent.data ?? {};
1029
- if (!(thread instanceof import_types.ThreadType) || !(subject && typeof subject === "object" && "threads" in subject && Array.isArray(subject.threads))) {
1030
- return;
1031
- }
1032
- const subjectId = (0, import_echo.fullyQualifiedId)(subject);
1033
- const space = (0, import_echo.getSpace)(subject);
1034
- const intents = [];
1035
- const analyticsProperties = {
1036
- threadId: thread.id,
1037
- spaceId: space?.id
1038
- };
1039
- if (state.drafts[subjectId]?.find((t) => t === thread)) {
1040
- thread.status = "active";
1041
- subject.threads ? subject.threads.push(thread) : subject.threads = [
1042
- thread
1043
- ];
1044
- state.drafts[subjectId] = state.drafts[subjectId]?.filter(({ id }) => id !== thread.id);
1045
- intents.push({
1046
- action: import_meta.ObservabilityAction.SEND_EVENT,
953
+ return {
954
+ undoable: {
955
+ message: [
956
+ "message deleted label",
957
+ {
958
+ ns: import_chunk_IC2NICNC.THREAD_PLUGIN
959
+ }
960
+ ],
1047
961
  data: {
1048
- name: "threads.thread-created",
1049
- properties: analyticsProperties
962
+ message: message2,
963
+ messageIndex: messageIndex2
1050
964
  }
1051
- });
1052
- }
1053
- intents.push({
1054
- action: import_meta.ObservabilityAction.SEND_EVENT,
1055
- data: {
1056
- name: "threads.message-added",
1057
- properties: {
1058
- ...analyticsProperties,
1059
- threadLength: thread.messages.length
1060
- }
1061
- }
1062
- });
1063
- return {
1064
- data: thread,
965
+ },
1065
966
  intents: [
1066
- intents
967
+ (0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
968
+ name: "threads.message.delete",
969
+ properties: {
970
+ threadId: thread.id,
971
+ spaceId: space?.id
972
+ }
973
+ })
1067
974
  ]
1068
975
  };
1069
- }
1070
- case import_chunk_XFO6D2LG.ThreadAction.DELETE_MESSAGE: {
1071
- const { subject, thread, messageId } = intent.data ?? {};
1072
- const space = (0, import_echo.getSpace)(subject);
1073
- if (!(thread instanceof import_types.ThreadType) || !(subject && typeof subject === "object" && "threads" in subject)) {
976
+ } else {
977
+ if (!messageIndex || !message) {
1074
978
  return;
1075
979
  }
1076
- if (!intent.undo) {
1077
- const message = thread.messages.find((m) => m?.id === messageId);
1078
- const messageIndex = thread.messages.findIndex((m) => m?.id === messageId);
1079
- if (messageIndex === -1 || !message) {
1080
- return void 0;
1081
- }
1082
- if (messageIndex === 0 && thread.messages.length === 1) {
1083
- return {
1084
- intents: [
1085
- [
1086
- {
1087
- action: import_chunk_XFO6D2LG.ThreadAction.DELETE,
1088
- data: {
1089
- subject,
1090
- thread
1091
- }
1092
- }
1093
- ]
1094
- ]
1095
- };
1096
- } else {
1097
- thread.messages.splice(messageIndex, 1);
1098
- }
1099
- return {
1100
- undoable: {
1101
- message: translations_default[0]["en-US"][import_chunk_IC2NICNC.THREAD_PLUGIN]["message deleted label"],
1102
- data: {
1103
- message,
1104
- messageIndex
980
+ thread.messages.splice(messageIndex, 0, (0, import_echo.makeRef)(message));
981
+ return {
982
+ intents: [
983
+ (0, import_app_framework.createIntent)(import_types2.ObservabilityAction.SendEvent, {
984
+ name: "threads.message.undo-delete",
985
+ properties: {
986
+ threadId: thread.id,
987
+ spaceId: space?.id
1105
988
  }
1106
- },
1107
- intents: [
1108
- [
1109
- {
1110
- action: import_meta.ObservabilityAction.SEND_EVENT,
1111
- data: {
1112
- name: "threads.message.delete",
1113
- properties: {
1114
- threadId: thread.id,
1115
- spaceId: space?.id
1116
- }
1117
- }
1118
- }
1119
- ]
1120
- ]
1121
- };
1122
- } else if (intent.undo) {
1123
- const message = intent.data?.message;
1124
- const messageIndex = intent.data?.messageIndex;
1125
- if (!(message instanceof import_types.MessageType) || !(typeof messageIndex === "number")) {
1126
- return;
1127
- }
1128
- thread.messages.splice(messageIndex, 0, message);
1129
- return {
1130
- data: true,
1131
- intents: [
1132
- [
1133
- {
1134
- action: import_meta.ObservabilityAction.SEND_EVENT,
1135
- data: {
1136
- name: "threads.message.undo-delete",
1137
- properties: {
1138
- threadId: thread.id,
1139
- spaceId: space?.id
1140
- }
1141
- }
1142
- }
1143
- ]
1144
- ]
1145
- };
1146
- }
989
+ })
990
+ ]
991
+ };
1147
992
  }
1148
- }
1149
- }
993
+ })
994
+ ]
1150
995
  },
1151
996
  markdown: {
1152
997
  extensions: ({ document: doc }) => {
1153
- return threads(state, doc, intentPlugin?.provides.intent.dispatch);
998
+ return threads(state, doc, intentPlugin?.provides.intent.dispatchPromise);
1154
999
  }
1155
1000
  }
1156
1001
  }