@dxos/plugin-thread 0.6.10 → 0.6.11-staging.e6894a4

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.
@@ -28,7 +28,7 @@ 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_WPPLQNMJ.ThreadAction,
31
+ ThreadAction: () => import_chunk_D5GOVXHS.ThreadAction,
32
32
  ThreadPlugin: () => ThreadPlugin,
33
33
  default: () => src_default,
34
34
  useAnalyticsCallback: () => import_chunk_5PZNPPQF.useAnalyticsCallback,
@@ -36,7 +36,7 @@ __export(node_exports, {
36
36
  useStatus: () => import_chunk_5PZNPPQF.useStatus
37
37
  });
38
38
  module.exports = __toCommonJS(node_exports);
39
- var import_chunk_WPPLQNMJ = require("./chunk-WPPLQNMJ.cjs");
39
+ var import_chunk_D5GOVXHS = require("./chunk-D5GOVXHS.cjs");
40
40
  var import_chunk_5PZNPPQF = require("./chunk-5PZNPPQF.cjs");
41
41
  var import_chunk_BWBONZGU = require("./chunk-BWBONZGU.cjs");
42
42
  var import_react = require("@phosphor-icons/react");
@@ -533,7 +533,7 @@ var ThreadPlugin = () => {
533
533
  }
534
534
  }),
535
535
  (0, import_plugin_graph.createExtension)({
536
- id: import_chunk_WPPLQNMJ.ThreadAction.CREATE,
536
+ id: import_chunk_D5GOVXHS.ThreadAction.CREATE,
537
537
  filter: (node) => !!settings.values.standalone && (0, import_plugin_graph.isActionGroup)(node) && node.id.startsWith(import_plugin_space.SpaceAction.ADD_OBJECT),
538
538
  actions: ({ node }) => {
539
539
  const id = node.id.split("/").at(-1);
@@ -551,7 +551,7 @@ var ThreadPlugin = () => {
551
551
  await dispatch2([
552
552
  {
553
553
  plugin: import_chunk_BWBONZGU.THREAD_PLUGIN,
554
- action: import_chunk_WPPLQNMJ.ThreadAction.CREATE
554
+ action: import_chunk_D5GOVXHS.ThreadAction.CREATE
555
555
  },
556
556
  {
557
557
  action: import_plugin_space.SpaceAction.ADD_OBJECT,
@@ -598,6 +598,12 @@ var ThreadPlugin = () => {
598
598
  case "article":
599
599
  case "complementary": {
600
600
  const location = navigationPlugin?.provides.location;
601
+ const providesThreadsConfig = (0, import_react2.useCallback)((plugin) => (
602
+ // TODO(Zan): More robust runtime check.
603
+ "thread" in plugin.provides ? plugin : void 0
604
+ ), []);
605
+ const threadsIntegrators = (0, import_app_framework.useResolvePlugins)(providesThreadsConfig);
606
+ const threadProvides = threadsIntegrators.map((p) => p.provides.thread);
601
607
  if (data.object instanceof import_types2.ChannelType && data.object.threads[0]) {
602
608
  const channel = data.object;
603
609
  if ((0, import_app_framework.isLayoutParts)(location?.active) && location.active.main) {
@@ -616,39 +622,27 @@ var ThreadPlugin = () => {
616
622
  thread: data.object.threads[0]
617
623
  });
618
624
  }
619
- if (data.subject instanceof import_types.DocumentType) {
620
- const doc = data.subject;
621
- const accessor = doc.content ? (0, import_echo.createDocAccessor)(doc.content, [
622
- "content"
623
- ]) : void 0;
624
- if (!accessor) {
625
- return null;
625
+ if (data.subject instanceof import_types2.ThreadType) {
626
+ return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(import_chunk_5PZNPPQF.ChatHeading, {
627
+ attendableId: data.subject.id
628
+ }), /* @__PURE__ */ import_react2.default.createElement(import_chunk_5PZNPPQF.ChatContainer, {
629
+ thread: data.subject
630
+ }));
631
+ }
632
+ if (data.subject && typeof data.subject === "object" && "threads" in data.subject && Array.isArray(data.subject.threads)) {
633
+ const threads = data.subject.threads.concat(state.staging[(0, import_echo.fullyQualifiedId)(data.subject)]).filter(import_util.nonNullable);
634
+ const createSort = threadProvides.find((p) => p.predicate(data.subject))?.createSort;
635
+ if (createSort) {
636
+ const sort = createSort(data.subject);
637
+ threads.sort((a, b) => sort(a.anchor, b.anchor));
626
638
  }
627
- const getStartPosition = (cursor) => {
628
- const range = cursor ? (0, import_echo.getRangeFromCursor)(accessor, cursor) : void 0;
629
- return range?.start ?? Number.MAX_SAFE_INTEGER;
630
- };
631
- const threads = doc.threads.concat(state.staging[data.subject.id]).filter(import_util.nonNullable).sort((a, b) => getStartPosition(a.anchor) - getStartPosition(b.anchor));
632
639
  const detached = data.subject.threads.filter(import_util.nonNullable).filter(({ anchor }) => !anchor).map((thread) => thread.id);
633
- const qualifiedSubjectId = (0, import_echo.fullyQualifiedId)(doc);
640
+ const qualifiedSubjectId = (0, import_echo.fullyQualifiedId)(data.subject);
634
641
  const attention = attentionPlugin?.provides.attention?.attended ?? /* @__PURE__ */ new Set([
635
642
  qualifiedSubjectId
636
643
  ]);
637
644
  const attendableAttrs = (0, import_react_ui_attention.createAttendableAttributes)(qualifiedSubjectId);
638
- const space = (0, import_echo.getSpace)(doc);
639
645
  const { showResolvedThreads } = getViewState(qualifiedSubjectId);
640
- const dispatchAnalytic = (name, meta) => {
641
- void dispatch?.({
642
- action: import_meta.ObservabilityAction.SEND_EVENT,
643
- data: {
644
- name,
645
- properties: {
646
- ...meta,
647
- space: space?.id
648
- }
649
- }
650
- });
651
- };
652
646
  return /* @__PURE__ */ import_react2.default.createElement("div", {
653
647
  role: "none",
654
648
  className: "contents group/attention",
@@ -678,55 +672,41 @@ var ThreadPlugin = () => {
678
672
  },
679
673
  onThreadDelete: (thread) => dispatch?.({
680
674
  plugin: import_chunk_BWBONZGU.THREAD_PLUGIN,
681
- action: import_chunk_WPPLQNMJ.ThreadAction.DELETE,
675
+ action: import_chunk_D5GOVXHS.ThreadAction.DELETE,
682
676
  data: {
683
- document: data.subject,
677
+ subject: data.subject,
684
678
  thread
685
679
  }
686
680
  }),
687
681
  onMessageDelete: (thread, messageId) => dispatch?.({
688
682
  plugin: import_chunk_BWBONZGU.THREAD_PLUGIN,
689
- action: import_chunk_WPPLQNMJ.ThreadAction.DELETE_MESSAGE,
683
+ action: import_chunk_D5GOVXHS.ThreadAction.DELETE_MESSAGE,
690
684
  data: {
691
- document: data.subject,
685
+ subject: data.subject,
692
686
  thread,
693
687
  messageId
694
688
  }
695
689
  }),
696
690
  onThreadToggleResolved: (thread) => dispatch?.({
697
691
  plugin: import_chunk_BWBONZGU.THREAD_PLUGIN,
698
- action: import_chunk_WPPLQNMJ.ThreadAction.TOGGLE_RESOLVED,
692
+ action: import_chunk_D5GOVXHS.ThreadAction.TOGGLE_RESOLVED,
699
693
  data: {
700
694
  thread
701
695
  }
702
696
  }),
703
697
  onComment: (thread) => {
704
- const doc2 = data.subject;
705
- if (state.staging[doc2.id]?.find((t) => t === thread)) {
706
- thread.status = "active";
707
- doc2.threads ? doc2.threads.push(thread) : doc2.threads = [
708
- thread
709
- ];
710
- state.staging[doc2.id] = state.staging[doc2.id]?.filter((t) => t.id !== thread.id);
711
- dispatchAnalytic("threads.thread-created", {
712
- threadId: thread.id
713
- });
714
- }
715
- dispatchAnalytic("threads.message-added", {
716
- threadId: thread.id,
717
- threadLength: thread.messages.length
698
+ void intentPlugin?.provides.intent.dispatch({
699
+ action: import_chunk_D5GOVXHS.ThreadAction.ON_MESSAGE_ADD,
700
+ data: {
701
+ thread,
702
+ subject: data.subject
703
+ }
718
704
  });
719
705
  }
720
706
  }), /* @__PURE__ */ import_react2.default.createElement("div", {
721
707
  role: "none",
722
708
  className: "bs-10"
723
709
  }), /* @__PURE__ */ import_react2.default.createElement(import_react_ui.ScrollArea.Scrollbar, null, /* @__PURE__ */ import_react2.default.createElement(import_react_ui.ScrollArea.Thumb, null)))));
724
- } else if (data.subject instanceof import_types2.ThreadType) {
725
- return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(import_chunk_5PZNPPQF.ChatHeading, {
726
- attendableId: data.subject.id
727
- }), /* @__PURE__ */ import_react2.default.createElement(import_chunk_5PZNPPQF.ChatContainer, {
728
- thread: data.subject
729
- }));
730
710
  }
731
711
  }
732
712
  }
@@ -736,25 +716,74 @@ var ThreadPlugin = () => {
736
716
  intent: {
737
717
  resolver: async (intent) => {
738
718
  switch (intent.action) {
739
- case import_chunk_WPPLQNMJ.ThreadAction.CREATE: {
740
- return {
741
- data: (0, import_echo_schema2.create)(import_types2.ChannelType, {
742
- threads: [
743
- (0, import_echo_schema2.create)(import_types2.ThreadType, {
744
- messages: []
745
- })
719
+ case import_chunk_D5GOVXHS.ThreadAction.CREATE: {
720
+ if (intent.data && intent.data.cursor !== void 0) {
721
+ const { cursor, name, subject } = intent.data;
722
+ const subjectId = (0, import_echo.fullyQualifiedId)(subject);
723
+ const thread = (0, import_echo_schema2.create)(import_types2.ThreadType, {
724
+ name,
725
+ anchor: cursor,
726
+ messages: [],
727
+ status: "staged"
728
+ });
729
+ const stagingArea = state.staging[subjectId];
730
+ if (stagingArea) {
731
+ stagingArea.push(thread);
732
+ } else {
733
+ state.staging[subjectId] = [
734
+ thread
735
+ ];
736
+ }
737
+ return {
738
+ data: thread,
739
+ intents: [
740
+ [
741
+ {
742
+ action: import_app_framework.NavigationAction.OPEN,
743
+ data: {
744
+ activeParts: {
745
+ complementary: `${subjectId}${import_app_framework.SLUG_PATH_SEPARATOR}comments${import_app_framework.SLUG_COLLECTION_INDICATOR}`
746
+ }
747
+ }
748
+ },
749
+ {
750
+ action: import_chunk_D5GOVXHS.ThreadAction.SELECT,
751
+ data: {
752
+ current: thread.id,
753
+ focus: true
754
+ }
755
+ },
756
+ {
757
+ action: import_app_framework.LayoutAction.SET_LAYOUT,
758
+ data: {
759
+ element: "complementary",
760
+ subject: subjectId,
761
+ state: true
762
+ }
763
+ }
764
+ ]
746
765
  ]
747
- })
748
- };
766
+ };
767
+ } else {
768
+ return {
769
+ data: (0, import_echo_schema2.create)(import_types2.ChannelType, {
770
+ threads: [
771
+ (0, import_echo_schema2.create)(import_types2.ThreadType, {
772
+ messages: []
773
+ })
774
+ ]
775
+ })
776
+ };
777
+ }
749
778
  }
750
- case import_chunk_WPPLQNMJ.ThreadAction.SELECT: {
779
+ case import_chunk_D5GOVXHS.ThreadAction.SELECT: {
751
780
  state.focus = intent.data?.current === state.current ? state.focus : intent.data?.focus;
752
781
  state.current = intent.data?.current;
753
782
  return {
754
783
  data: true
755
784
  };
756
785
  }
757
- case import_chunk_WPPLQNMJ.ThreadAction.TOGGLE_RESOLVED: {
786
+ case import_chunk_D5GOVXHS.ThreadAction.TOGGLE_RESOLVED: {
758
787
  const { thread } = intent.data ?? {};
759
788
  if (!(thread instanceof import_types2.ThreadType)) {
760
789
  return;
@@ -783,28 +812,29 @@ var ThreadPlugin = () => {
783
812
  ]
784
813
  };
785
814
  }
786
- case import_chunk_WPPLQNMJ.ThreadAction.DELETE: {
787
- const { document: doc, thread } = intent.data ?? {};
788
- if (!(doc instanceof import_types.DocumentType) || !(thread instanceof import_types2.ThreadType)) {
815
+ case import_chunk_D5GOVXHS.ThreadAction.DELETE: {
816
+ const { subject, thread } = intent.data ?? {};
817
+ if (!(subject instanceof import_types.DocumentType) || !(thread instanceof import_types2.ThreadType)) {
789
818
  return;
790
819
  }
791
- const stagingArea = state.staging[doc.id];
820
+ const subjectId = (0, import_echo.fullyQualifiedId)(subject);
821
+ const stagingArea = state.staging[subjectId];
792
822
  if (stagingArea) {
793
- const index = state.staging[doc.id]?.findIndex((t) => t.id === thread.id);
823
+ const index = stagingArea.findIndex((t) => t.id === thread.id);
794
824
  if (index !== -1) {
795
- state.staging[doc.id]?.splice(index, 1);
825
+ stagingArea.splice(index, 1);
796
826
  return;
797
827
  }
798
828
  }
799
829
  const space = (0, import_echo.getSpace)(thread);
800
- if (!space || !doc.threads) {
830
+ if (!space || !subject.threads) {
801
831
  return;
802
832
  }
803
833
  if (!intent.undo) {
804
- const index = doc.threads.findIndex((t) => t?.id === thread.id);
805
- const cursor = doc.threads[index]?.anchor;
834
+ const index = subject.threads.findIndex((t) => t?.id === thread.id);
835
+ const cursor = subject.threads[index]?.anchor;
806
836
  if (index !== -1) {
807
- doc.threads?.splice(index, 1);
837
+ subject.threads?.splice(index, 1);
808
838
  }
809
839
  space.db.remove(thread);
810
840
  return {
@@ -831,7 +861,7 @@ var ThreadPlugin = () => {
831
861
  };
832
862
  } else if (intent.undo) {
833
863
  const savedThread = space.db.add(thread);
834
- doc.threads.push(savedThread);
864
+ subject.threads.push(savedThread);
835
865
  return {
836
866
  data: true,
837
867
  intents: [
@@ -852,10 +882,53 @@ var ThreadPlugin = () => {
852
882
  }
853
883
  break;
854
884
  }
855
- case import_chunk_WPPLQNMJ.ThreadAction.DELETE_MESSAGE: {
856
- const { document: doc, thread, messageId } = intent.data ?? {};
857
- const space = (0, import_echo.getSpace)(doc);
858
- if (!(doc instanceof import_types.DocumentType) || !(thread instanceof import_types2.ThreadType) || !space) {
885
+ case import_chunk_D5GOVXHS.ThreadAction.ON_MESSAGE_ADD: {
886
+ const { thread, subject } = intent.data ?? {};
887
+ if (!(thread instanceof import_types2.ThreadType) || !(subject && typeof subject === "object" && "threads" in subject)) {
888
+ return;
889
+ }
890
+ const subjectId = (0, import_echo.fullyQualifiedId)(subject);
891
+ const space = (0, import_echo.getSpace)(subject);
892
+ const intents = [];
893
+ const analyticsProperties = {
894
+ threadId: thread.id,
895
+ spaceId: space?.id
896
+ };
897
+ if (state.staging[subjectId]?.find((t) => t === thread)) {
898
+ thread.status = "active";
899
+ subject.threads ? subject.threads.push(thread) : subject.threads = [
900
+ thread
901
+ ];
902
+ state.staging[subjectId] = state.staging[subjectId]?.filter((t) => t.id !== thread.id);
903
+ intents.push({
904
+ action: import_meta.ObservabilityAction.SEND_EVENT,
905
+ data: {
906
+ name: "threads.thread-created",
907
+ properties: analyticsProperties
908
+ }
909
+ });
910
+ }
911
+ intents.push({
912
+ action: import_meta.ObservabilityAction.SEND_EVENT,
913
+ data: {
914
+ name: "threads.message-added",
915
+ properties: {
916
+ ...analyticsProperties,
917
+ threadLength: thread.messages.length
918
+ }
919
+ }
920
+ });
921
+ return {
922
+ data: thread,
923
+ intents: [
924
+ intents
925
+ ]
926
+ };
927
+ }
928
+ case import_chunk_D5GOVXHS.ThreadAction.DELETE_MESSAGE: {
929
+ const { subject, thread, messageId } = intent.data ?? {};
930
+ const space = (0, import_echo.getSpace)(subject);
931
+ if (!(subject instanceof import_types.DocumentType) || !(thread instanceof import_types2.ThreadType) || !space) {
859
932
  return;
860
933
  }
861
934
  if (!intent.undo) {
@@ -869,9 +942,9 @@ var ThreadPlugin = () => {
869
942
  intents: [
870
943
  [
871
944
  {
872
- action: import_chunk_WPPLQNMJ.ThreadAction.DELETE,
945
+ action: import_chunk_D5GOVXHS.ThreadAction.DELETE,
873
946
  data: {
874
- document: doc,
947
+ subject,
875
948
  thread
876
949
  }
877
950
  }
@@ -944,7 +1017,7 @@ var ThreadPlugin = () => {
944
1017
  }
945
1018
  const threads = (0, import_signals_core.computed)(() => [
946
1019
  ...doc.threads.filter(import_util.nonNullable),
947
- ...state.staging[doc.id] ?? []
1020
+ ...state.staging[(0, import_echo.fullyQualifiedId)(doc)] ?? []
948
1021
  ].filter((thread) => !(thread?.status === "resolved")));
949
1022
  return [
950
1023
  (0, import_react_ui_editor.listener)({
@@ -973,49 +1046,17 @@ var ThreadPlugin = () => {
973
1046
  const name = doc.content && (0, import_echo.getTextInRange)((0, import_echo.createDocAccessor)(doc.content, [
974
1047
  "content"
975
1048
  ]), start, end);
976
- const thread = (0, import_echo_schema2.create)(import_types2.ThreadType, {
977
- name,
978
- anchor: cursor,
979
- messages: [],
980
- status: "staged"
981
- });
982
- const stagingArea = state.staging[doc.id];
983
- if (stagingArea) {
984
- stagingArea.push(thread);
985
- } else {
986
- state.staging[doc.id] = [
987
- thread
988
- ];
989
- }
990
- void intentPlugin?.provides.intent.dispatch([
991
- {
992
- action: import_app_framework.NavigationAction.OPEN,
993
- data: {
994
- activeParts: {
995
- complementary: `${(0, import_echo.fullyQualifiedId)(doc)}${import_app_framework.SLUG_PATH_SEPARATOR}comments${import_app_framework.SLUG_COLLECTION_INDICATOR}`
996
- }
997
- }
998
- },
999
- {
1000
- action: import_chunk_WPPLQNMJ.ThreadAction.SELECT,
1001
- data: {
1002
- current: thread.id,
1003
- focus: true
1004
- }
1005
- },
1006
- {
1007
- action: import_app_framework.LayoutAction.SET_LAYOUT,
1008
- data: {
1009
- element: "complementary",
1010
- subject: doc,
1011
- state: true
1012
- }
1049
+ void intentPlugin?.provides.intent.dispatch({
1050
+ action: import_chunk_D5GOVXHS.ThreadAction.CREATE,
1051
+ data: {
1052
+ cursor,
1053
+ name,
1054
+ subject: doc
1013
1055
  }
1014
- ]);
1015
- return thread.id;
1056
+ });
1016
1057
  },
1017
1058
  onDelete: ({ id }) => {
1018
- const stagingArea = state.staging[doc.id];
1059
+ const stagingArea = state.staging[(0, import_echo.fullyQualifiedId)(doc)];
1019
1060
  if (stagingArea) {
1020
1061
  const index = stagingArea.findIndex((thread2) => thread2.id === id);
1021
1062
  if (index !== -1) {
@@ -1028,7 +1069,7 @@ var ThreadPlugin = () => {
1028
1069
  }
1029
1070
  },
1030
1071
  onUpdate: ({ id, cursor }) => {
1031
- const thread = state.staging[doc.id]?.find((thread2) => thread2.id === id) ?? doc.threads.find((thread2) => thread2?.id === id);
1072
+ const thread = state.staging[(0, import_echo.fullyQualifiedId)(doc)]?.find((thread2) => thread2.id === id) ?? doc.threads.find((thread2) => thread2?.id === id);
1032
1073
  if (thread instanceof import_types2.ThreadType && thread.anchor) {
1033
1074
  const [start, end] = thread.anchor.split(":");
1034
1075
  thread.name = doc.content && (0, import_echo.getTextInRange)((0, import_echo.createDocAccessor)(doc.content, [
@@ -1042,7 +1083,7 @@ var ThreadPlugin = () => {
1042
1083
  if (dispatch2) {
1043
1084
  void dispatch2([
1044
1085
  {
1045
- action: import_chunk_WPPLQNMJ.ThreadAction.SELECT,
1086
+ action: import_chunk_D5GOVXHS.ThreadAction.SELECT,
1046
1087
  data: {
1047
1088
  current: current ?? closest
1048
1089
  }