@dxos/plugin-thread 0.6.12-main.89e9959 → 0.6.12-main.c1d977f

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 (68) hide show
  1. package/dist/lib/browser/{ThreadArticle-4VU752F4.mjs → ThreadArticle-GBPIH47W.mjs} +3 -3
  2. package/dist/lib/browser/{ThreadMain-ML3P4XSD.mjs → ThreadMain-PGF7W5EV.mjs} +3 -3
  3. package/dist/lib/browser/{chunk-7NUYW5IW.mjs → chunk-5G3KL6TC.mjs} +4 -6
  4. package/dist/lib/browser/chunk-5G3KL6TC.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-GJRBBPXI.mjs → chunk-JFQZ5W2I.mjs} +2 -2
  6. package/dist/lib/browser/{chunk-GJRBBPXI.mjs.map → chunk-JFQZ5W2I.mjs.map} +1 -1
  7. package/dist/lib/browser/{chunk-XF5QKI75.mjs → chunk-O4YRHIZC.mjs} +2 -2
  8. package/dist/lib/browser/index.mjs +168 -148
  9. package/dist/lib/browser/index.mjs.map +4 -4
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/meta.mjs +1 -1
  12. package/dist/lib/browser/types.mjs +2 -2
  13. package/dist/lib/node/{ThreadArticle-ERUHPHVT.cjs → ThreadArticle-GH5UBWFU.cjs} +7 -7
  14. package/dist/lib/node/{ThreadMain-6DN7FDNB.cjs → ThreadMain-CO6I3DNX.cjs} +7 -7
  15. package/dist/lib/node/{chunk-PZVUW4W2.cjs → chunk-FDYRG7HE.cjs} +9 -9
  16. package/dist/lib/node/{chunk-FXD3DYMO.cjs → chunk-FOZUQZF4.cjs} +6 -6
  17. package/dist/lib/node/{chunk-FXD3DYMO.cjs.map → chunk-FOZUQZF4.cjs.map} +1 -1
  18. package/dist/lib/node/{chunk-6EVXCSDS.cjs → chunk-JIJ7Z6NO.cjs} +6 -8
  19. package/dist/lib/node/chunk-JIJ7Z6NO.cjs.map +7 -0
  20. package/dist/lib/node/index.cjs +196 -178
  21. package/dist/lib/node/index.cjs.map +4 -4
  22. package/dist/lib/node/meta.cjs +4 -4
  23. package/dist/lib/node/meta.cjs.map +1 -1
  24. package/dist/lib/node/meta.json +1 -1
  25. package/dist/lib/node/types.cjs +3 -3
  26. package/dist/lib/node/types.cjs.map +1 -1
  27. package/dist/lib/node-esm/{ThreadArticle-NKI5F4W5.mjs → ThreadArticle-ZTYD52TR.mjs} +3 -3
  28. package/dist/lib/node-esm/{ThreadMain-2A3VQLCW.mjs → ThreadMain-LEHGOF7R.mjs} +3 -3
  29. package/dist/lib/node-esm/{chunk-Y475KZTX.mjs → chunk-DC5ZA6H5.mjs} +4 -6
  30. package/dist/lib/node-esm/chunk-DC5ZA6H5.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-A44C4MTQ.mjs → chunk-XOVJ65DG.mjs} +2 -2
  32. package/dist/lib/node-esm/{chunk-YO46JGAE.mjs → chunk-ZXIPFXSA.mjs} +2 -2
  33. package/dist/lib/node-esm/{chunk-YO46JGAE.mjs.map → chunk-ZXIPFXSA.mjs.map} +1 -1
  34. package/dist/lib/node-esm/index.mjs +168 -148
  35. package/dist/lib/node-esm/index.mjs.map +4 -4
  36. package/dist/lib/node-esm/meta.json +1 -1
  37. package/dist/lib/node-esm/meta.mjs +1 -1
  38. package/dist/lib/node-esm/types.mjs +2 -2
  39. package/dist/types/src/ThreadPlugin.d.ts.map +1 -1
  40. package/dist/types/src/components/ThreadComplementary.d.ts +2 -2
  41. package/dist/types/src/components/ThreadComplementary.d.ts.map +1 -1
  42. package/dist/types/src/extensions/index.d.ts +2 -0
  43. package/dist/types/src/extensions/index.d.ts.map +1 -0
  44. package/dist/types/src/extensions/threads.d.ts +9 -0
  45. package/dist/types/src/extensions/threads.d.ts.map +1 -0
  46. package/dist/types/src/meta.d.ts +3 -6
  47. package/dist/types/src/meta.d.ts.map +1 -1
  48. package/dist/types/src/types.d.ts +5 -0
  49. package/dist/types/src/types.d.ts.map +1 -1
  50. package/package.json +28 -28
  51. package/src/ThreadPlugin.tsx +53 -136
  52. package/src/components/ThreadComplementary.tsx +4 -4
  53. package/src/extensions/index.ts +5 -0
  54. package/src/extensions/threads.ts +117 -0
  55. package/src/{meta.tsx → meta.ts} +3 -4
  56. package/src/types.ts +7 -2
  57. package/dist/lib/browser/chunk-7NUYW5IW.mjs.map +0 -7
  58. package/dist/lib/node/chunk-6EVXCSDS.cjs.map +0 -7
  59. package/dist/lib/node-esm/chunk-Y475KZTX.mjs.map +0 -7
  60. /package/dist/lib/browser/{ThreadArticle-4VU752F4.mjs.map → ThreadArticle-GBPIH47W.mjs.map} +0 -0
  61. /package/dist/lib/browser/{ThreadMain-ML3P4XSD.mjs.map → ThreadMain-PGF7W5EV.mjs.map} +0 -0
  62. /package/dist/lib/browser/{chunk-XF5QKI75.mjs.map → chunk-O4YRHIZC.mjs.map} +0 -0
  63. /package/dist/lib/node/{ThreadArticle-ERUHPHVT.cjs.map → ThreadArticle-GH5UBWFU.cjs.map} +0 -0
  64. /package/dist/lib/node/{ThreadMain-6DN7FDNB.cjs.map → ThreadMain-CO6I3DNX.cjs.map} +0 -0
  65. /package/dist/lib/node/{chunk-PZVUW4W2.cjs.map → chunk-FDYRG7HE.cjs.map} +0 -0
  66. /package/dist/lib/node-esm/{ThreadArticle-NKI5F4W5.mjs.map → ThreadArticle-ZTYD52TR.mjs.map} +0 -0
  67. /package/dist/lib/node-esm/{ThreadMain-2A3VQLCW.mjs.map → ThreadMain-LEHGOF7R.mjs.map} +0 -0
  68. /package/dist/lib/node-esm/{chunk-A44C4MTQ.mjs.map → chunk-XOVJ65DG.mjs.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
  import {
3
3
  ThreadAction
4
- } from "./chunk-YO46JGAE.mjs";
4
+ } from "./chunk-ZXIPFXSA.mjs";
5
5
  import {
6
6
  ChatContainer,
7
7
  ChatHeading,
@@ -11,17 +11,16 @@ import {
11
11
  useAnalyticsCallback,
12
12
  useOnEditAnalytics,
13
13
  useStatus
14
- } from "./chunk-A44C4MTQ.mjs";
14
+ } from "./chunk-XOVJ65DG.mjs";
15
15
  import {
16
16
  THREAD_ITEM,
17
17
  THREAD_PLUGIN,
18
18
  meta_default
19
- } from "./chunk-Y475KZTX.mjs";
19
+ } from "./chunk-DC5ZA6H5.mjs";
20
20
 
21
21
  // packages/plugins/plugin-thread/src/ThreadPlugin.tsx
22
- import { computed, effect } from "@preact/signals-core";
23
22
  import React6 from "react";
24
- import { LayoutAction as LayoutAction2, NavigationAction, parseIntentPlugin, parseNavigationPlugin, resolvePlugin, isLayoutParts, parseMetadataResolverPlugin } from "@dxos/app-framework";
23
+ import { NavigationAction, parseIntentPlugin, parseNavigationPlugin, resolvePlugin, isLayoutParts, parseMetadataResolverPlugin } from "@dxos/app-framework";
25
24
  import { getTypename } from "@dxos/echo-schema";
26
25
  import { create as create2 } from "@dxos/echo-schema";
27
26
  import { LocalStorageStore } from "@dxos/local-storage";
@@ -30,11 +29,9 @@ import { parseClientPlugin } from "@dxos/plugin-client";
30
29
  import { createExtension, isActionGroup, toSignal } from "@dxos/plugin-graph";
31
30
  import { ObservabilityAction } from "@dxos/plugin-observability/meta";
32
31
  import { SpaceAction } from "@dxos/plugin-space";
33
- import { ThreadType, MessageType as MessageType2, ChannelType } from "@dxos/plugin-space/types";
34
- import { getSpace as getSpace2, getTextInRange, createDocAccessor, fullyQualifiedId as fullyQualifiedId4, loadObjectReferences } from "@dxos/react-client/echo";
35
- import { comments, createExternalCommentSync, listener as listener2 } from "@dxos/react-ui-editor";
32
+ import { ThreadType as ThreadType2, MessageType as MessageType2, ChannelType } from "@dxos/plugin-space/types";
33
+ import { getSpace as getSpace3, fullyQualifiedId as fullyQualifiedId5, loadObjectReferences } from "@dxos/react-client/echo";
36
34
  import { translations as threadTranslations } from "@dxos/react-ui-thread";
37
- import { nonNullable as nonNullable3 } from "@dxos/util";
38
35
 
39
36
  // packages/plugins/plugin-thread/src/components/index.ts
40
37
  import React4 from "react";
@@ -210,9 +207,9 @@ import React3, { useEffect } from "react";
210
207
  import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
211
208
  import { useTranslation as useTranslation3, Trans } from "@dxos/react-ui";
212
209
  import { descriptionText, mx as mx2 } from "@dxos/react-ui-theme";
213
- var CommentsContainer = ({ threads, detached = [], currentId, showResolvedThreads, onThreadAttend, onThreadDelete, onMessageDelete, onThreadToggleResolved, ...props }) => {
210
+ var CommentsContainer = ({ threads: threads2, detached = [], currentId, showResolvedThreads, onThreadAttend, onThreadDelete, onMessageDelete, onThreadToggleResolved, ...props }) => {
214
211
  const { t } = useTranslation3(THREAD_PLUGIN);
215
- const filteredThreads = showResolvedThreads ? threads : threads.filter((thread) => !(thread?.status === "resolved"));
212
+ const filteredThreads = showResolvedThreads ? threads2 : threads2.filter((thread) => !(thread?.status === "resolved"));
216
213
  useEffect(() => {
217
214
  if (currentId) {
218
215
  document.getElementById(currentId)?.scrollIntoView({
@@ -261,8 +258,8 @@ var CommentsContainer = ({ threads, detached = [], currentId, showResolvedThread
261
258
  };
262
259
 
263
260
  // packages/plugins/plugin-thread/src/components/index.ts
264
- var ThreadMain = React4.lazy(() => import("./ThreadMain-2A3VQLCW.mjs"));
265
- var ThreadArticle = React4.lazy(() => import("./ThreadArticle-NKI5F4W5.mjs"));
261
+ var ThreadMain = React4.lazy(() => import("./ThreadMain-LEHGOF7R.mjs"));
262
+ var ThreadArticle = React4.lazy(() => import("./ThreadArticle-ZTYD52TR.mjs"));
266
263
 
267
264
  // packages/plugins/plugin-thread/src/components/ThreadComplementary.tsx
268
265
  import React5, { useEffect as useEffect2, useMemo as useMemo2 } from "react";
@@ -272,7 +269,7 @@ import { ScrollArea } from "@dxos/react-ui";
272
269
  import { useAttended } from "@dxos/react-ui-attention";
273
270
  import { nonNullable as nonNullable2 } from "@dxos/util";
274
271
  var providesThreadsConfig = (plugin) => "thread" in plugin.provides ? plugin : void 0;
275
- var ThreadComplementary = ({ role, subject, stagedThreads, current, showResolvedThreads }) => {
272
+ var ThreadComplementary = ({ role, subject, drafts, current, showResolvedThreads }) => {
276
273
  const dispatch = useIntentDispatcher();
277
274
  const threadsIntegrators = useResolvePlugins(providesThreadsConfig);
278
275
  const threadProvides = useMemo2(() => threadsIntegrators.map((p) => p.provides.thread), [
@@ -286,25 +283,25 @@ var ThreadComplementary = ({ role, subject, stagedThreads, current, showResolved
286
283
  createSort,
287
284
  subject
288
285
  ]);
289
- const threads = useMemo2(() => {
290
- return subject.threads.concat(stagedThreads ?? []).filter(nonNullable2);
286
+ const threads2 = useMemo2(() => {
287
+ return subject.threads.concat(drafts ?? []).filter(nonNullable2);
291
288
  }, [
292
289
  JSON.stringify(subject.threads),
293
- JSON.stringify(stagedThreads)
290
+ JSON.stringify(drafts)
294
291
  ]);
295
292
  const detachedIds = useMemo2(() => {
296
- return threads.filter(({ anchor }) => !anchor).map((thread) => fullyQualifiedId3(thread));
293
+ return threads2.filter(({ anchor }) => !anchor).map((thread) => fullyQualifiedId3(thread));
297
294
  }, [
298
- threads
295
+ threads2
299
296
  ]);
300
297
  useEffect2(() => {
301
298
  if (!sort) {
302
299
  return;
303
300
  }
304
- threads.sort((a, b) => sort(a?.anchor, b?.anchor));
301
+ threads2.sort((a, b) => sort(a?.anchor, b?.anchor));
305
302
  }, [
306
303
  sort,
307
- threads
304
+ threads2
308
305
  ]);
309
306
  const attended = useAttended();
310
307
  const qualifiedSubjectId = fullyQualifiedId3(subject);
@@ -314,7 +311,7 @@ var ThreadComplementary = ({ role, subject, stagedThreads, current, showResolved
314
311
  }, /* @__PURE__ */ React5.createElement(ScrollArea.Root, {
315
312
  classNames: "row-span-2"
316
313
  }, /* @__PURE__ */ React5.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React5.createElement(CommentsContainer, {
317
- threads,
314
+ threads: threads2,
318
315
  detached: detachedIds,
319
316
  currentId: attended.includes(qualifiedSubjectId) ? current : void 0,
320
317
  showResolvedThreads,
@@ -375,6 +372,95 @@ var ThreadComplementary = ({ role, subject, stagedThreads, current, showResolved
375
372
  }), /* @__PURE__ */ React5.createElement(ScrollArea.Scrollbar, null, /* @__PURE__ */ React5.createElement(ScrollArea.Thumb, null)))));
376
373
  };
377
374
 
375
+ // packages/plugins/plugin-thread/src/extensions/threads.ts
376
+ import { EditorView } from "@codemirror/view";
377
+ import { computed, effect } from "@preact/signals-core";
378
+ import { ThreadType } from "@dxos/plugin-space/types";
379
+ import { getSpace as getSpace2, getTextInRange, createDocAccessor, fullyQualifiedId as fullyQualifiedId4 } from "@dxos/react-client/echo";
380
+ import { comments, createExternalCommentSync } from "@dxos/react-ui-editor";
381
+ import { nonNullable as nonNullable3 } from "@dxos/util";
382
+ var getName = (doc, anchor) => {
383
+ if (doc.content) {
384
+ const [start, end] = anchor.split(":");
385
+ return getTextInRange(createDocAccessor(doc.content, [
386
+ "content"
387
+ ]), start, end);
388
+ }
389
+ };
390
+ var threads = (state, doc, dispatch) => {
391
+ const space = doc && getSpace2(doc);
392
+ if (!doc || !space || !dispatch) {
393
+ return [
394
+ comments()
395
+ ];
396
+ }
397
+ const threads2 = computed(() => [
398
+ ...doc.threads.filter(nonNullable3),
399
+ ...state.drafts[fullyQualifiedId4(doc)] ?? []
400
+ ].filter((thread) => !(thread?.status === "resolved")));
401
+ return [
402
+ EditorView.updateListener.of((update) => {
403
+ if (update.docChanged) {
404
+ doc.threads.forEach((thread) => {
405
+ if (thread?.anchor) {
406
+ const name = getName(doc, thread.anchor);
407
+ if (name && name !== thread.name) {
408
+ thread.name = name;
409
+ }
410
+ }
411
+ });
412
+ }
413
+ }),
414
+ createExternalCommentSync(fullyQualifiedId4(doc), (sink) => effect(() => sink()), () => threads2.value.filter((thread) => thread?.anchor).map((thread) => ({
415
+ id: fullyQualifiedId4(thread),
416
+ cursor: thread.anchor
417
+ }))),
418
+ comments({
419
+ id: fullyQualifiedId4(doc),
420
+ onCreate: ({ cursor }) => {
421
+ const name = getName(doc, cursor);
422
+ void dispatch({
423
+ action: ThreadAction.CREATE,
424
+ data: {
425
+ cursor,
426
+ name,
427
+ subject: doc
428
+ }
429
+ });
430
+ },
431
+ onDelete: ({ id }) => {
432
+ const draft = state.drafts[fullyQualifiedId4(doc)];
433
+ if (draft) {
434
+ const index = draft.findIndex((thread2) => fullyQualifiedId4(thread2) === id);
435
+ if (index !== -1) {
436
+ draft.splice(index, 1);
437
+ }
438
+ }
439
+ const thread = doc.threads.find((thread2) => thread2?.id === id);
440
+ if (thread) {
441
+ thread.anchor = void 0;
442
+ }
443
+ },
444
+ onUpdate: ({ id, cursor }) => {
445
+ const thread = state.drafts[fullyQualifiedId4(doc)]?.find((thread2) => fullyQualifiedId4(thread2) === id) ?? doc.threads.find((thread2) => thread2?.id === id);
446
+ if (thread instanceof ThreadType && thread.anchor) {
447
+ thread.name = getName(doc, thread.anchor);
448
+ thread.anchor = cursor;
449
+ }
450
+ },
451
+ onSelect: ({ selection: { current, closest } }) => {
452
+ void dispatch({
453
+ action: ThreadAction.SELECT,
454
+ data: {
455
+ current: current ?? closest,
456
+ skipOpen: true
457
+ }
458
+ });
459
+ }
460
+ })
461
+ ];
462
+ };
463
+
378
464
  // packages/plugins/plugin-thread/src/translations.ts
379
465
  var translations_default = [
380
466
  {
@@ -419,7 +505,7 @@ var initialViewState = {
419
505
  var ThreadPlugin = () => {
420
506
  const settings = new LocalStorageStore(THREAD_PLUGIN);
421
507
  const state = create2({
422
- staging: {}
508
+ drafts: {}
423
509
  });
424
510
  const viewStore = create2({});
425
511
  const getViewState = (subjectId) => {
@@ -463,7 +549,7 @@ var ThreadPlugin = () => {
463
549
  // TODO(wittjosiah): Move out of metadata.
464
550
  loadReferences: (channel) => loadObjectReferences(channel, (channel2) => channel2.threads)
465
551
  },
466
- [ThreadType.typename]: {
552
+ [ThreadType2.typename]: {
467
553
  // TODO(wittjosiah): Move out of metadata.
468
554
  loadReferences: (thread) => loadObjectReferences(thread, (thread2) => thread2.messages)
469
555
  },
@@ -499,7 +585,7 @@ var ThreadPlugin = () => {
499
585
  echo: {
500
586
  schema: [
501
587
  ChannelType,
502
- ThreadType,
588
+ ThreadType2,
503
589
  MessageType2
504
590
  ]
505
591
  },
@@ -655,8 +741,7 @@ var ThreadPlugin = () => {
655
741
  settings: settings.values
656
742
  }) : null;
657
743
  }
658
- case "article":
659
- case "complementary": {
744
+ case "article": {
660
745
  const location = navigationPlugin?.provides.location;
661
746
  if (data.object instanceof ChannelType && data.object.threads[0]) {
662
747
  const channel = data.object;
@@ -665,7 +750,7 @@ var ThreadPlugin = () => {
665
750
  const currentPosition = layoutEntries.findIndex((entry) => channel.id === entry.id);
666
751
  if (currentPosition > 0) {
667
752
  const objectToTheLeft = layoutEntries[currentPosition - 1];
668
- const context = getSpace2(data.object)?.db.getObjectById(objectToTheLeft.id);
753
+ const context = getSpace3(data.object)?.db.getObjectById(objectToTheLeft.id);
669
754
  return /* @__PURE__ */ React6.createElement(ThreadArticle, {
670
755
  thread: data.object.threads[0],
671
756
  context
@@ -676,23 +761,27 @@ var ThreadPlugin = () => {
676
761
  thread: data.object.threads[0]
677
762
  });
678
763
  }
679
- if (data.subject instanceof ThreadType) {
764
+ if (data.subject instanceof ThreadType2) {
680
765
  return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(ChatHeading, {
681
766
  attendableId: data.subject.id
682
767
  }), /* @__PURE__ */ React6.createElement(ChatContainer, {
683
768
  thread: data.subject
684
769
  }));
685
770
  }
771
+ break;
772
+ }
773
+ case "complementary--comments": {
686
774
  if (data.subject && typeof data.subject === "object" && "threads" in data.subject && Array.isArray(data.subject.threads)) {
687
- const { showResolvedThreads } = getViewState(fullyQualifiedId4(data.subject));
775
+ const { showResolvedThreads } = getViewState(fullyQualifiedId5(data.subject));
688
776
  return /* @__PURE__ */ React6.createElement(ThreadComplementary, {
689
777
  role,
690
778
  subject: data.subject,
691
- stagedThreads: state.staging[fullyQualifiedId4(data.subject)],
779
+ drafts: state.drafts[fullyQualifiedId5(data.subject)],
692
780
  current: state.current,
693
781
  showResolvedThreads
694
782
  });
695
783
  }
784
+ break;
696
785
  }
697
786
  }
698
787
  return null;
@@ -707,28 +796,28 @@ var ThreadPlugin = () => {
707
796
  if (subject?.threads === void 0) {
708
797
  try {
709
798
  subject.threads = [];
710
- } catch (e) {
799
+ } catch (err) {
711
800
  log.error("Subject does not support threads array", subject?.typename, {
712
801
  F: __dxlog_file,
713
- L: 331,
802
+ L: 322,
714
803
  S: void 0,
715
804
  C: (f, a) => f(...a)
716
805
  });
717
806
  return;
718
807
  }
719
808
  }
720
- const subjectId = fullyQualifiedId4(subject);
721
- const thread = create2(ThreadType, {
809
+ const subjectId = fullyQualifiedId5(subject);
810
+ const thread = create2(ThreadType2, {
722
811
  name,
723
812
  anchor: cursor,
724
813
  messages: [],
725
814
  status: "staged"
726
815
  });
727
- const stagingArea = state.staging[subjectId];
728
- if (stagingArea) {
729
- stagingArea.push(thread);
816
+ const draft = state.drafts[subjectId];
817
+ if (draft) {
818
+ draft.push(thread);
730
819
  } else {
731
- state.staging[subjectId] = [
820
+ state.drafts[subjectId] = [
732
821
  thread
733
822
  ];
734
823
  }
@@ -739,15 +828,17 @@ var ThreadPlugin = () => {
739
828
  {
740
829
  action: ThreadAction.SELECT,
741
830
  data: {
742
- current: fullyQualifiedId4(thread)
831
+ current: fullyQualifiedId5(thread)
743
832
  }
744
- },
833
+ }
834
+ ],
835
+ [
745
836
  {
746
- action: LayoutAction2.SET_LAYOUT,
837
+ action: NavigationAction.OPEN,
747
838
  data: {
748
- element: "complementary",
749
- subject: subjectId,
750
- state: true
839
+ activeParts: {
840
+ complementary: "comments"
841
+ }
751
842
  }
752
843
  }
753
844
  ]
@@ -757,7 +848,7 @@ var ThreadPlugin = () => {
757
848
  return {
758
849
  data: create2(ChannelType, {
759
850
  threads: [
760
- create2(ThreadType, {
851
+ create2(ThreadType2, {
761
852
  messages: []
762
853
  })
763
854
  ]
@@ -768,12 +859,24 @@ var ThreadPlugin = () => {
768
859
  case ThreadAction.SELECT: {
769
860
  state.current = intent.data?.current;
770
861
  return {
771
- data: true
862
+ data: true,
863
+ intents: !intent.data?.skipOpen ? [
864
+ [
865
+ {
866
+ action: NavigationAction.OPEN,
867
+ data: {
868
+ activeParts: {
869
+ complementary: "comments"
870
+ }
871
+ }
872
+ }
873
+ ]
874
+ ] : []
772
875
  };
773
876
  }
774
877
  case ThreadAction.TOGGLE_RESOLVED: {
775
878
  const { thread } = intent.data ?? {};
776
- if (!(thread instanceof ThreadType)) {
879
+ if (!(thread instanceof ThreadType2)) {
777
880
  return;
778
881
  }
779
882
  if (thread.status === "active" || thread.status === void 0) {
@@ -781,9 +884,10 @@ var ThreadPlugin = () => {
781
884
  } else if (thread.status === "resolved") {
782
885
  thread.status = "active";
783
886
  }
784
- const space = getSpace2(thread);
887
+ const space = getSpace3(thread);
785
888
  const spaceId = space?.id;
786
889
  return {
890
+ data: true,
787
891
  intents: [
788
892
  [
789
893
  {
@@ -802,21 +906,21 @@ var ThreadPlugin = () => {
802
906
  }
803
907
  case ThreadAction.DELETE: {
804
908
  const { subject, thread } = intent.data ?? {};
805
- if (!(thread instanceof ThreadType) || !(subject && typeof subject === "object" && "threads" in subject)) {
909
+ if (!(thread instanceof ThreadType2) || !(subject && typeof subject === "object" && "threads" in subject)) {
806
910
  return;
807
911
  }
808
- const subjectId = fullyQualifiedId4(subject);
809
- const stagingArea = state.staging[subjectId];
810
- if (stagingArea) {
811
- const index = stagingArea.findIndex((t) => t.id === thread.id);
912
+ const subjectId = fullyQualifiedId5(subject);
913
+ const draft = state.drafts[subjectId];
914
+ if (draft) {
915
+ const index = draft.findIndex((t) => t.id === thread.id);
812
916
  if (index !== -1) {
813
- stagingArea.splice(index, 1);
917
+ draft.splice(index, 1);
814
918
  return {
815
919
  data: true
816
920
  };
817
921
  }
818
922
  }
819
- const space = getSpace2(thread);
923
+ const space = getSpace3(thread);
820
924
  if (!space || !subject.threads) {
821
925
  return;
822
926
  }
@@ -874,22 +978,22 @@ var ThreadPlugin = () => {
874
978
  }
875
979
  case ThreadAction.ON_MESSAGE_ADD: {
876
980
  const { thread, subject } = intent.data ?? {};
877
- if (!(thread instanceof ThreadType) || !(subject && typeof subject === "object" && "threads" in subject && Array.isArray(subject.threads))) {
981
+ if (!(thread instanceof ThreadType2) || !(subject && typeof subject === "object" && "threads" in subject && Array.isArray(subject.threads))) {
878
982
  return;
879
983
  }
880
- const subjectId = fullyQualifiedId4(subject);
881
- const space = getSpace2(subject);
984
+ const subjectId = fullyQualifiedId5(subject);
985
+ const space = getSpace3(subject);
882
986
  const intents = [];
883
987
  const analyticsProperties = {
884
988
  threadId: thread.id,
885
989
  spaceId: space?.id
886
990
  };
887
- if (state.staging[subjectId]?.find((t) => t === thread)) {
991
+ if (state.drafts[subjectId]?.find((t) => t === thread)) {
888
992
  thread.status = "active";
889
993
  subject.threads ? subject.threads.push(thread) : subject.threads = [
890
994
  thread
891
995
  ];
892
- state.staging[subjectId] = state.staging[subjectId]?.filter((t) => t.id !== thread.id);
996
+ state.drafts[subjectId] = state.drafts[subjectId]?.filter(({ id }) => id !== thread.id);
893
997
  intents.push({
894
998
  action: ObservabilityAction.SEND_EVENT,
895
999
  data: {
@@ -917,8 +1021,8 @@ var ThreadPlugin = () => {
917
1021
  }
918
1022
  case ThreadAction.DELETE_MESSAGE: {
919
1023
  const { subject, thread, messageId } = intent.data ?? {};
920
- const space = getSpace2(subject);
921
- if (!(thread instanceof ThreadType) || !(subject && typeof subject === "object" && "threads" in subject)) {
1024
+ const space = getSpace3(subject);
1025
+ if (!(thread instanceof ThreadType2) || !(subject && typeof subject === "object" && "threads" in subject)) {
922
1026
  return;
923
1027
  }
924
1028
  if (!intent.undo) {
@@ -997,92 +1101,8 @@ var ThreadPlugin = () => {
997
1101
  }
998
1102
  },
999
1103
  markdown: {
1000
- // TODO(burdon): Factor out extension factory into separate file (for simplicity).
1001
1104
  extensions: ({ document: doc }) => {
1002
- const space = doc && getSpace2(doc);
1003
- if (!doc || !space) {
1004
- return [
1005
- comments()
1006
- ];
1007
- }
1008
- const threads = computed(() => [
1009
- ...doc.threads.filter(nonNullable3),
1010
- ...state.staging[fullyQualifiedId4(doc)] ?? []
1011
- ].filter((thread) => !(thread?.status === "resolved")));
1012
- return [
1013
- listener2({
1014
- onChange: () => {
1015
- doc.threads.forEach((thread) => {
1016
- if (thread?.anchor) {
1017
- const [start, end] = thread.anchor.split(":");
1018
- const name = doc.content && getTextInRange(createDocAccessor(doc.content, [
1019
- "content"
1020
- ]), start, end);
1021
- if (name && name !== thread.name) {
1022
- thread.name = name;
1023
- }
1024
- }
1025
- });
1026
- }
1027
- }),
1028
- createExternalCommentSync(fullyQualifiedId4(doc), (sink) => effect(() => sink()), () => threads.value.filter((thread) => thread?.anchor).map((thread) => ({
1029
- id: fullyQualifiedId4(thread),
1030
- cursor: thread.anchor
1031
- }))),
1032
- comments({
1033
- id: fullyQualifiedId4(doc),
1034
- onCreate: ({ cursor }) => {
1035
- const [start, end] = cursor.split(":");
1036
- const name = doc.content && getTextInRange(createDocAccessor(doc.content, [
1037
- "content"
1038
- ]), start, end);
1039
- void intentPlugin?.provides.intent.dispatch({
1040
- action: ThreadAction.CREATE,
1041
- data: {
1042
- cursor,
1043
- name,
1044
- subject: doc
1045
- }
1046
- });
1047
- },
1048
- onDelete: ({ id }) => {
1049
- const stagingArea = state.staging[fullyQualifiedId4(doc)];
1050
- if (stagingArea) {
1051
- const index = stagingArea.findIndex((thread2) => fullyQualifiedId4(thread2) === id);
1052
- if (index !== -1) {
1053
- stagingArea.splice(index, 1);
1054
- }
1055
- }
1056
- const thread = doc.threads.find((thread2) => thread2?.id === id);
1057
- if (thread) {
1058
- thread.anchor = void 0;
1059
- }
1060
- },
1061
- onUpdate: ({ id, cursor }) => {
1062
- const thread = state.staging[fullyQualifiedId4(doc)]?.find((thread2) => fullyQualifiedId4(thread2) === id) ?? doc.threads.find((thread2) => thread2?.id === id);
1063
- if (thread instanceof ThreadType && thread.anchor) {
1064
- const [start, end] = thread.anchor.split(":");
1065
- thread.name = doc.content && getTextInRange(createDocAccessor(doc.content, [
1066
- "content"
1067
- ]), start, end);
1068
- thread.anchor = cursor;
1069
- }
1070
- },
1071
- onSelect: ({ selection: { current, closest } }) => {
1072
- const dispatch = intentPlugin?.provides.intent.dispatch;
1073
- if (dispatch) {
1074
- void dispatch([
1075
- {
1076
- action: ThreadAction.SELECT,
1077
- data: {
1078
- current: current ?? closest
1079
- }
1080
- }
1081
- ]);
1082
- }
1083
- }
1084
- })
1085
- ];
1105
+ return threads(state, doc, intentPlugin?.provides.intent.dispatch);
1086
1106
  }
1087
1107
  }
1088
1108
  }