@dxos/plugin-thread 0.6.13 → 0.6.14-main.69511f5
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.
- package/dist/lib/browser/{ThreadArticle-O64ZECMF.mjs → ThreadArticle-2Y7UWZLA.mjs} +3 -3
- package/dist/lib/browser/{ThreadMain-ZDCRC6RG.mjs → ThreadMain-VK5UEBQ7.mjs} +3 -3
- package/dist/lib/browser/chunk-5G3KL6TC.mjs +16 -0
- package/dist/lib/browser/chunk-5G3KL6TC.mjs.map +7 -0
- package/dist/lib/browser/{chunk-P7ZE5N5M.mjs → chunk-LHT42MTJ.mjs} +16 -16
- package/dist/lib/browser/chunk-LHT42MTJ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GKPZHUT3.mjs → chunk-WKCIKGGW.mjs} +2 -2
- package/dist/lib/browser/{chunk-GKPZHUT3.mjs.map → chunk-WKCIKGGW.mjs.map} +1 -1
- package/dist/lib/browser/index.mjs +431 -383
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types.mjs +2 -2
- package/dist/lib/node/{ThreadArticle-DO56JXBU.cjs → ThreadArticle-CIYBYISR.cjs} +7 -7
- package/dist/lib/node/{ThreadMain-XJX75GHG.cjs → ThreadMain-V6KBUQLH.cjs} +7 -7
- package/dist/lib/node/{chunk-D5GOVXHS.cjs → chunk-A2IORKQK.cjs} +6 -6
- package/dist/lib/node/{chunk-D5GOVXHS.cjs.map → chunk-A2IORKQK.cjs.map} +1 -1
- package/dist/lib/node/{chunk-5PZNPPQF.cjs → chunk-HWN7Q5XK.cjs} +65 -65
- package/dist/lib/node/chunk-HWN7Q5XK.cjs.map +7 -0
- package/dist/lib/node/{chunk-BWBONZGU.cjs → chunk-JIJ7Z6NO.cjs} +7 -22
- package/dist/lib/node/chunk-JIJ7Z6NO.cjs.map +7 -0
- package/dist/lib/node/index.cjs +480 -436
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +4 -4
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +3 -3
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/ThreadArticle-PXO4ZJFU.mjs +19 -0
- package/dist/lib/node-esm/ThreadArticle-PXO4ZJFU.mjs.map +7 -0
- package/dist/lib/node-esm/ThreadMain-U7R24CN3.mjs +27 -0
- package/dist/lib/node-esm/ThreadMain-U7R24CN3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DC5ZA6H5.mjs +18 -0
- package/dist/lib/node-esm/chunk-DC5ZA6H5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KWNXG6FG.mjs +21 -0
- package/dist/lib/node-esm/chunk-KWNXG6FG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-SXXOBRAX.mjs +411 -0
- package/dist/lib/node-esm/chunk-SXXOBRAX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1151 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +12 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +9 -0
- package/dist/lib/node-esm/types.mjs.map +7 -0
- package/dist/types/src/ThreadPlugin.d.ts.map +1 -1
- package/dist/types/src/components/Chat.stories.d.ts +3 -42
- package/dist/types/src/components/Chat.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
- package/dist/types/src/components/CommentContainer.d.ts +1 -1
- package/dist/types/src/components/CommentContainer.d.ts.map +1 -1
- package/dist/types/src/components/Comments.stories.d.ts +3 -41
- package/dist/types/src/components/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/components/CommentsContainer.d.ts +1 -5
- package/dist/types/src/components/CommentsContainer.d.ts.map +1 -1
- package/dist/types/src/components/MessageContainer.d.ts.map +1 -1
- package/dist/types/src/components/ThreadComplementary.d.ts +10 -0
- package/dist/types/src/components/ThreadComplementary.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +6 -6
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +2 -0
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/components/types.d.ts +2 -2
- package/dist/types/src/components/types.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/extensions/threads.d.ts +9 -0
- package/dist/types/src/extensions/threads.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +3 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +7 -2
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +41 -46
- package/src/ThreadPlugin.tsx +146 -307
- package/src/components/Chat.stories.tsx +7 -4
- package/src/components/ChatContainer.tsx +7 -8
- package/src/components/CommentContainer.tsx +18 -19
- package/src/components/Comments.stories.tsx +9 -6
- package/src/components/CommentsContainer.tsx +18 -31
- package/src/components/MessageContainer.tsx +13 -23
- package/src/components/ThreadComplementary.tsx +113 -0
- package/src/components/ThreadSettings.tsx +3 -3
- package/src/components/index.ts +6 -6
- package/src/components/types.ts +2 -2
- package/src/extensions/index.ts +5 -0
- package/src/extensions/threads.ts +117 -0
- package/src/meta.ts +15 -0
- package/src/types.ts +9 -4
- package/dist/lib/browser/chunk-5IBJO53M.mjs +0 -21
- package/dist/lib/browser/chunk-5IBJO53M.mjs.map +0 -7
- package/dist/lib/browser/chunk-P7ZE5N5M.mjs.map +0 -7
- package/dist/lib/node/chunk-5PZNPPQF.cjs.map +0 -7
- package/dist/lib/node/chunk-BWBONZGU.cjs.map +0 -7
- package/dist/types/src/types.test.d.ts +0 -2
- package/dist/types/src/types.test.d.ts.map +0 -1
- package/src/meta.tsx +0 -20
- package/src/types.test.ts +0 -13
- /package/dist/lib/browser/{ThreadArticle-O64ZECMF.mjs.map → ThreadArticle-2Y7UWZLA.mjs.map} +0 -0
- /package/dist/lib/browser/{ThreadMain-ZDCRC6RG.mjs.map → ThreadMain-VK5UEBQ7.mjs.map} +0 -0
- /package/dist/lib/node/{ThreadArticle-DO56JXBU.cjs.map → ThreadArticle-CIYBYISR.cjs.map} +0 -0
- /package/dist/lib/node/{ThreadMain-XJX75GHG.cjs.map → ThreadMain-V6KBUQLH.cjs.map} +0 -0
|
@@ -0,0 +1,1151 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ThreadAction
|
|
4
|
+
} from "./chunk-KWNXG6FG.mjs";
|
|
5
|
+
import {
|
|
6
|
+
ChatContainer,
|
|
7
|
+
ChatHeading,
|
|
8
|
+
MessageContainer,
|
|
9
|
+
command,
|
|
10
|
+
getMessageMetadata,
|
|
11
|
+
useAnalyticsCallback,
|
|
12
|
+
useOnEditAnalytics,
|
|
13
|
+
useStatus
|
|
14
|
+
} from "./chunk-SXXOBRAX.mjs";
|
|
15
|
+
import {
|
|
16
|
+
THREAD_ITEM,
|
|
17
|
+
THREAD_PLUGIN,
|
|
18
|
+
meta_default
|
|
19
|
+
} from "./chunk-DC5ZA6H5.mjs";
|
|
20
|
+
|
|
21
|
+
// packages/plugins/plugin-thread/src/ThreadPlugin.tsx
|
|
22
|
+
import React5 from "react";
|
|
23
|
+
import { NavigationAction, isLayoutParts, parseIntentPlugin, parseNavigationPlugin, parseMetadataResolverPlugin, resolvePlugin, LayoutAction as LayoutAction2 } from "@dxos/app-framework";
|
|
24
|
+
import { LocalStorageStore } from "@dxos/local-storage";
|
|
25
|
+
import { log } from "@dxos/log";
|
|
26
|
+
import { parseClientPlugin } from "@dxos/plugin-client";
|
|
27
|
+
import { createExtension, isActionGroup, toSignal } from "@dxos/plugin-graph";
|
|
28
|
+
import { ObservabilityAction } from "@dxos/plugin-observability/meta";
|
|
29
|
+
import { SpaceAction } from "@dxos/plugin-space";
|
|
30
|
+
import { ThreadType as ThreadType2, MessageType as MessageType2, ChannelType } from "@dxos/plugin-space/types";
|
|
31
|
+
import { create as create2, getTypename } from "@dxos/react-client/echo";
|
|
32
|
+
import { getSpace as getSpace3, fullyQualifiedId as fullyQualifiedId5, loadObjectReferences, parseId } from "@dxos/react-client/echo";
|
|
33
|
+
import { translations as threadTranslations } from "@dxos/react-ui-thread";
|
|
34
|
+
|
|
35
|
+
// packages/plugins/plugin-thread/src/components/index.ts
|
|
36
|
+
import { lazy } from "react";
|
|
37
|
+
|
|
38
|
+
// packages/plugins/plugin-thread/src/components/CommentContainer.tsx
|
|
39
|
+
import { CheckCircle, X } from "@phosphor-icons/react";
|
|
40
|
+
import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
41
|
+
import { create } from "@dxos/echo-schema";
|
|
42
|
+
import { MessageType } from "@dxos/plugin-space/types";
|
|
43
|
+
import { fullyQualifiedId, getSpace, useMembers } from "@dxos/react-client/echo";
|
|
44
|
+
import { useIdentity } from "@dxos/react-client/halo";
|
|
45
|
+
import { Button, Tag, Tooltip, useThemeContext, useTranslation } from "@dxos/react-ui";
|
|
46
|
+
import { createBasicExtensions, createThemeExtensions, listener } from "@dxos/react-ui-editor";
|
|
47
|
+
import { getSize, hoverableControlItem, hoverableControls, hoverableFocusedWithinControls, mx } from "@dxos/react-ui-theme";
|
|
48
|
+
import { MessageTextbox, Thread, ThreadFooter, ThreadHeading } from "@dxos/react-ui-thread";
|
|
49
|
+
import { nonNullable } from "@dxos/util";
|
|
50
|
+
var sizeClass = getSize(4);
|
|
51
|
+
var ToggleResolvedButton = ({ isResolved, onResolve }) => {
|
|
52
|
+
const { t } = useTranslation(THREAD_PLUGIN);
|
|
53
|
+
const label = t(isResolved ? "mark as unresolved label" : "mark as resolved label");
|
|
54
|
+
return /* @__PURE__ */ React.createElement(Tooltip.Root, null, /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
55
|
+
asChild: true
|
|
56
|
+
}, /* @__PURE__ */ React.createElement(Button, {
|
|
57
|
+
variant: "ghost",
|
|
58
|
+
"data-testid": "thread.toggle-resolved",
|
|
59
|
+
onClick: onResolve,
|
|
60
|
+
classNames: [
|
|
61
|
+
"min-bs-0 p-1",
|
|
62
|
+
!isResolved && hoverableControlItem
|
|
63
|
+
]
|
|
64
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
65
|
+
className: "sr-only"
|
|
66
|
+
}, label), isResolved ? /* @__PURE__ */ React.createElement(CheckCircle, {
|
|
67
|
+
className: sizeClass,
|
|
68
|
+
weight: "fill"
|
|
69
|
+
}) : /* @__PURE__ */ React.createElement(CheckCircle, {
|
|
70
|
+
className: sizeClass
|
|
71
|
+
}))), /* @__PURE__ */ React.createElement(Tooltip.Portal, null, /* @__PURE__ */ React.createElement(Tooltip.Content, {
|
|
72
|
+
classNames: "z-[21]"
|
|
73
|
+
}, label, /* @__PURE__ */ React.createElement(Tooltip.Arrow, null))));
|
|
74
|
+
};
|
|
75
|
+
var DeleteThreadButton = ({ onDelete }) => {
|
|
76
|
+
const { t } = useTranslation(THREAD_PLUGIN);
|
|
77
|
+
const label = t("delete thread label");
|
|
78
|
+
return /* @__PURE__ */ React.createElement(Tooltip.Root, null, /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
79
|
+
asChild: true
|
|
80
|
+
}, /* @__PURE__ */ React.createElement(Button, {
|
|
81
|
+
variant: "ghost",
|
|
82
|
+
"data-testid": "thread.delete",
|
|
83
|
+
onClick: onDelete,
|
|
84
|
+
classNames: [
|
|
85
|
+
"min-bs-0 p-1",
|
|
86
|
+
hoverableControlItem
|
|
87
|
+
]
|
|
88
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
89
|
+
className: "sr-only"
|
|
90
|
+
}, label), /* @__PURE__ */ React.createElement(X, {
|
|
91
|
+
className: sizeClass
|
|
92
|
+
}))), /* @__PURE__ */ React.createElement(Tooltip.Portal, null, /* @__PURE__ */ React.createElement(Tooltip.Content, {
|
|
93
|
+
classNames: "z-[21]"
|
|
94
|
+
}, label, /* @__PURE__ */ React.createElement(Tooltip.Arrow, null))));
|
|
95
|
+
};
|
|
96
|
+
var CommentContainer = ({ thread, detached, context, current, onAttend, onThreadDelete, onMessageDelete, onResolve, onComment }) => {
|
|
97
|
+
const identity = useIdentity();
|
|
98
|
+
const space = getSpace(thread);
|
|
99
|
+
const members = useMembers(space?.key);
|
|
100
|
+
const activity = useStatus(space, fullyQualifiedId(thread));
|
|
101
|
+
const { t } = useTranslation(THREAD_PLUGIN);
|
|
102
|
+
const threadScrollRef = useRef(null);
|
|
103
|
+
const { themeMode } = useThemeContext();
|
|
104
|
+
const textboxMetadata = getMessageMetadata(fullyQualifiedId(thread), identity);
|
|
105
|
+
const [_count, _setCount] = useState(0);
|
|
106
|
+
const rerenderEditor = () => _setCount((count) => count + 1);
|
|
107
|
+
const messageRef = useRef("");
|
|
108
|
+
const extensions = useMemo(() => [
|
|
109
|
+
createBasicExtensions({
|
|
110
|
+
placeholder: t("message placeholder")
|
|
111
|
+
}),
|
|
112
|
+
createThemeExtensions({
|
|
113
|
+
themeMode
|
|
114
|
+
}),
|
|
115
|
+
listener({
|
|
116
|
+
onChange: (text) => messageRef.current = text
|
|
117
|
+
}),
|
|
118
|
+
command
|
|
119
|
+
], [
|
|
120
|
+
_count
|
|
121
|
+
]);
|
|
122
|
+
const scrollToEnd = (behavior) => setTimeout(() => threadScrollRef.current?.scrollIntoView({
|
|
123
|
+
behavior,
|
|
124
|
+
block: "end"
|
|
125
|
+
}), 10);
|
|
126
|
+
const handleCreate = useCallback(() => {
|
|
127
|
+
if (!messageRef.current) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
thread.messages.push(create(MessageType, {
|
|
131
|
+
sender: {
|
|
132
|
+
identityKey: identity.identityKey.toHex()
|
|
133
|
+
},
|
|
134
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
135
|
+
text: messageRef.current,
|
|
136
|
+
context
|
|
137
|
+
}));
|
|
138
|
+
onComment?.(thread);
|
|
139
|
+
messageRef.current = "";
|
|
140
|
+
scrollToEnd("instant");
|
|
141
|
+
rerenderEditor();
|
|
142
|
+
return true;
|
|
143
|
+
}, [
|
|
144
|
+
thread,
|
|
145
|
+
identity
|
|
146
|
+
]);
|
|
147
|
+
return /* @__PURE__ */ React.createElement(Thread, {
|
|
148
|
+
onClickCapture: onAttend,
|
|
149
|
+
onFocusCapture: onAttend,
|
|
150
|
+
current,
|
|
151
|
+
id: fullyQualifiedId(thread)
|
|
152
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
153
|
+
role: "none",
|
|
154
|
+
className: mx("col-span-2 grid grid-cols-[var(--rail-size)_1fr_min-content]", hoverableControls, hoverableFocusedWithinControls)
|
|
155
|
+
}, detached ? /* @__PURE__ */ React.createElement(Tooltip.Root, null, /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
156
|
+
asChild: true
|
|
157
|
+
}, /* @__PURE__ */ React.createElement(ThreadHeading, {
|
|
158
|
+
detached: true
|
|
159
|
+
}, thread.name ?? t("thread title placeholder"))), /* @__PURE__ */ React.createElement(Tooltip.Portal, null, /* @__PURE__ */ React.createElement(Tooltip.Content, {
|
|
160
|
+
classNames: "z-[21]",
|
|
161
|
+
side: "top"
|
|
162
|
+
}, t("detached thread label"), /* @__PURE__ */ React.createElement(Tooltip.Arrow, null)))) : /* @__PURE__ */ React.createElement(ThreadHeading, null, thread.name ?? t("thread title placeholder")), /* @__PURE__ */ React.createElement("div", {
|
|
163
|
+
className: "flex flex-row items-center pli-1"
|
|
164
|
+
}, thread.status === "staged" && /* @__PURE__ */ React.createElement(Tag, {
|
|
165
|
+
palette: "neutral"
|
|
166
|
+
}, t("draft button")), onResolve && !(thread?.status === "staged") && /* @__PURE__ */ React.createElement(ToggleResolvedButton, {
|
|
167
|
+
isResolved: thread?.status === "resolved",
|
|
168
|
+
onResolve
|
|
169
|
+
}), onThreadDelete && /* @__PURE__ */ React.createElement(DeleteThreadButton, {
|
|
170
|
+
onDelete: onThreadDelete
|
|
171
|
+
}))), thread.messages.filter(nonNullable).map((message) => /* @__PURE__ */ React.createElement(MessageContainer, {
|
|
172
|
+
key: message.id,
|
|
173
|
+
message,
|
|
174
|
+
members,
|
|
175
|
+
onDelete: (id) => onMessageDelete?.(id)
|
|
176
|
+
})), /* @__PURE__ */ React.createElement(MessageTextbox, {
|
|
177
|
+
extensions,
|
|
178
|
+
onSend: handleCreate,
|
|
179
|
+
...textboxMetadata
|
|
180
|
+
}), /* @__PURE__ */ React.createElement(ThreadFooter, {
|
|
181
|
+
activity
|
|
182
|
+
}, t("activity message")), /* @__PURE__ */ React.createElement("div", {
|
|
183
|
+
role: "none",
|
|
184
|
+
className: "bs-px -mbs-px",
|
|
185
|
+
ref: threadScrollRef
|
|
186
|
+
}));
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// packages/plugins/plugin-thread/src/components/CommentsContainer.tsx
|
|
190
|
+
import { ChatText } from "@phosphor-icons/react";
|
|
191
|
+
import React2, { useEffect } from "react";
|
|
192
|
+
import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
|
|
193
|
+
import { useTranslation as useTranslation2, Trans } from "@dxos/react-ui";
|
|
194
|
+
import { descriptionText, mx as mx2 } from "@dxos/react-ui-theme";
|
|
195
|
+
var CommentsContainer = ({ threads: threads2, detached = [], currentId, showResolvedThreads, onThreadAttend, onThreadDelete, onMessageDelete, onThreadToggleResolved, ...props }) => {
|
|
196
|
+
const { t } = useTranslation2(THREAD_PLUGIN);
|
|
197
|
+
const filteredThreads = showResolvedThreads ? threads2 : threads2.filter((thread) => !(thread?.status === "resolved"));
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (currentId) {
|
|
200
|
+
document.getElementById(currentId)?.scrollIntoView({
|
|
201
|
+
behavior: "smooth",
|
|
202
|
+
block: "end"
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}, [
|
|
206
|
+
currentId
|
|
207
|
+
]);
|
|
208
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, filteredThreads.length > 0 ? filteredThreads.map((thread) => {
|
|
209
|
+
const threadId = fullyQualifiedId2(thread);
|
|
210
|
+
return /* @__PURE__ */ React2.createElement(CommentContainer, {
|
|
211
|
+
key: threadId,
|
|
212
|
+
thread,
|
|
213
|
+
current: currentId === threadId,
|
|
214
|
+
detached: detached.includes(threadId),
|
|
215
|
+
...onThreadAttend && {
|
|
216
|
+
onAttend: () => onThreadAttend(thread)
|
|
217
|
+
},
|
|
218
|
+
...onThreadDelete && {
|
|
219
|
+
onThreadDelete: () => onThreadDelete(thread)
|
|
220
|
+
},
|
|
221
|
+
...onMessageDelete && {
|
|
222
|
+
onMessageDelete: (messageId) => onMessageDelete(thread, messageId)
|
|
223
|
+
},
|
|
224
|
+
...onThreadToggleResolved && {
|
|
225
|
+
onResolve: () => onThreadToggleResolved(thread)
|
|
226
|
+
},
|
|
227
|
+
...props
|
|
228
|
+
});
|
|
229
|
+
}) : /* @__PURE__ */ React2.createElement("div", {
|
|
230
|
+
role: "alert",
|
|
231
|
+
className: mx2(descriptionText, "place-self-center border border-dashed border-neutral-400/50 rounded-lg text-center p-4 m-4")
|
|
232
|
+
}, /* @__PURE__ */ React2.createElement("h2", {
|
|
233
|
+
className: "mbe-2 font-medium text-baseText"
|
|
234
|
+
}, t("no comments title")), /* @__PURE__ */ React2.createElement("p", null, /* @__PURE__ */ React2.createElement(Trans, {
|
|
235
|
+
t,
|
|
236
|
+
i18nKey: "no comments message",
|
|
237
|
+
components: {
|
|
238
|
+
commentIcon: /* @__PURE__ */ React2.createElement(ChatText, {
|
|
239
|
+
className: "inline-block"
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
}))));
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// packages/plugins/plugin-thread/src/components/ThreadComplementary.tsx
|
|
246
|
+
import React3, { useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
247
|
+
import { LayoutAction, useIntentDispatcher, useResolvePlugins } from "@dxos/app-framework";
|
|
248
|
+
import { fullyQualifiedId as fullyQualifiedId3 } from "@dxos/react-client/echo";
|
|
249
|
+
import { ScrollArea } from "@dxos/react-ui";
|
|
250
|
+
import { useAttended } from "@dxos/react-ui-attention";
|
|
251
|
+
import { nonNullable as nonNullable2 } from "@dxos/util";
|
|
252
|
+
var providesThreadsConfig = (plugin) => "thread" in plugin.provides ? plugin : void 0;
|
|
253
|
+
var ThreadComplementary = ({ role, subject, drafts, current, showResolvedThreads }) => {
|
|
254
|
+
const dispatch = useIntentDispatcher();
|
|
255
|
+
const threadsIntegrators = useResolvePlugins(providesThreadsConfig);
|
|
256
|
+
const threadProvides = useMemo2(() => threadsIntegrators.map((p) => p.provides.thread), [
|
|
257
|
+
threadsIntegrators
|
|
258
|
+
]);
|
|
259
|
+
const createSort = useMemo2(() => threadProvides.find((p) => p.predicate(subject))?.createSort, [
|
|
260
|
+
threadProvides,
|
|
261
|
+
subject
|
|
262
|
+
]);
|
|
263
|
+
const sort = useMemo2(() => createSort?.(subject), [
|
|
264
|
+
createSort,
|
|
265
|
+
subject
|
|
266
|
+
]);
|
|
267
|
+
const threads2 = useMemo2(() => {
|
|
268
|
+
return subject.threads.concat(drafts ?? []).filter(nonNullable2);
|
|
269
|
+
}, [
|
|
270
|
+
JSON.stringify(subject.threads),
|
|
271
|
+
JSON.stringify(drafts)
|
|
272
|
+
]);
|
|
273
|
+
const detachedIds = useMemo2(() => {
|
|
274
|
+
return threads2.filter(({ anchor }) => !anchor).map((thread) => fullyQualifiedId3(thread));
|
|
275
|
+
}, [
|
|
276
|
+
threads2
|
|
277
|
+
]);
|
|
278
|
+
useEffect2(() => {
|
|
279
|
+
if (!sort) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
threads2.sort((a, b) => sort(a?.anchor, b?.anchor));
|
|
283
|
+
}, [
|
|
284
|
+
sort,
|
|
285
|
+
threads2
|
|
286
|
+
]);
|
|
287
|
+
const attended = useAttended();
|
|
288
|
+
const qualifiedSubjectId = fullyQualifiedId3(subject);
|
|
289
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
290
|
+
role: "none",
|
|
291
|
+
className: "contents"
|
|
292
|
+
}, /* @__PURE__ */ React3.createElement(ScrollArea.Root, {
|
|
293
|
+
classNames: "row-span-2"
|
|
294
|
+
}, /* @__PURE__ */ React3.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React3.createElement(CommentsContainer, {
|
|
295
|
+
threads: threads2,
|
|
296
|
+
detached: detachedIds,
|
|
297
|
+
currentId: attended.includes(qualifiedSubjectId) ? current : void 0,
|
|
298
|
+
showResolvedThreads,
|
|
299
|
+
onThreadAttend: (thread) => {
|
|
300
|
+
const threadId = fullyQualifiedId3(thread);
|
|
301
|
+
if (current !== threadId) {
|
|
302
|
+
current = threadId;
|
|
303
|
+
void dispatch?.([
|
|
304
|
+
{
|
|
305
|
+
action: LayoutAction.SCROLL_INTO_VIEW,
|
|
306
|
+
data: {
|
|
307
|
+
id: fullyQualifiedId3(subject),
|
|
308
|
+
thread: threadId,
|
|
309
|
+
cursor: thread.anchor
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
]);
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
onThreadDelete: (thread) => {
|
|
316
|
+
return dispatch({
|
|
317
|
+
plugin: THREAD_PLUGIN,
|
|
318
|
+
action: ThreadAction.DELETE,
|
|
319
|
+
data: {
|
|
320
|
+
subject,
|
|
321
|
+
thread
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
onMessageDelete: (thread, messageId) => dispatch({
|
|
326
|
+
plugin: THREAD_PLUGIN,
|
|
327
|
+
action: ThreadAction.DELETE_MESSAGE,
|
|
328
|
+
data: {
|
|
329
|
+
subject,
|
|
330
|
+
thread,
|
|
331
|
+
messageId
|
|
332
|
+
}
|
|
333
|
+
}),
|
|
334
|
+
onThreadToggleResolved: (thread) => dispatch({
|
|
335
|
+
plugin: THREAD_PLUGIN,
|
|
336
|
+
action: ThreadAction.TOGGLE_RESOLVED,
|
|
337
|
+
data: {
|
|
338
|
+
thread
|
|
339
|
+
}
|
|
340
|
+
}),
|
|
341
|
+
onComment: (thread) => {
|
|
342
|
+
void dispatch({
|
|
343
|
+
action: ThreadAction.ON_MESSAGE_ADD,
|
|
344
|
+
data: {
|
|
345
|
+
thread,
|
|
346
|
+
subject
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}), /* @__PURE__ */ React3.createElement("div", {
|
|
351
|
+
role: "none",
|
|
352
|
+
className: "bs-10"
|
|
353
|
+
}), /* @__PURE__ */ React3.createElement(ScrollArea.Scrollbar, null, /* @__PURE__ */ React3.createElement(ScrollArea.Thumb, null)))));
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// packages/plugins/plugin-thread/src/components/ThreadSettings.tsx
|
|
357
|
+
import React4 from "react";
|
|
358
|
+
import { Input, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
359
|
+
import { FormInput } from "@dxos/react-ui-data";
|
|
360
|
+
var ThreadSettings = ({ settings }) => {
|
|
361
|
+
const { t } = useTranslation3(THREAD_PLUGIN);
|
|
362
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(FormInput, {
|
|
363
|
+
label: t("settings standalone label")
|
|
364
|
+
}, /* @__PURE__ */ React4.createElement(Input.Switch, {
|
|
365
|
+
checked: settings.standalone,
|
|
366
|
+
onCheckedChange: (checked) => settings.standalone = !!checked
|
|
367
|
+
})));
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// packages/plugins/plugin-thread/src/components/index.ts
|
|
371
|
+
var ThreadMain = lazy(() => import("./ThreadMain-U7R24CN3.mjs"));
|
|
372
|
+
var ThreadArticle = lazy(() => import("./ThreadArticle-PXO4ZJFU.mjs"));
|
|
373
|
+
|
|
374
|
+
// packages/plugins/plugin-thread/src/extensions/threads.ts
|
|
375
|
+
import { EditorView } from "@codemirror/view";
|
|
376
|
+
import { computed, effect } from "@preact/signals-core";
|
|
377
|
+
import { ThreadType } from "@dxos/plugin-space/types";
|
|
378
|
+
import { getSpace as getSpace2, getTextInRange, createDocAccessor, fullyQualifiedId as fullyQualifiedId4 } from "@dxos/react-client/echo";
|
|
379
|
+
import { comments, createExternalCommentSync } from "@dxos/react-ui-editor";
|
|
380
|
+
import { nonNullable as nonNullable3 } from "@dxos/util";
|
|
381
|
+
var getName = (doc, anchor) => {
|
|
382
|
+
if (doc.content) {
|
|
383
|
+
const [start, end] = anchor.split(":");
|
|
384
|
+
return getTextInRange(createDocAccessor(doc.content, [
|
|
385
|
+
"content"
|
|
386
|
+
]), start, end);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var threads = (state, doc, dispatch) => {
|
|
390
|
+
const space = doc && getSpace2(doc);
|
|
391
|
+
if (!doc || !space || !dispatch) {
|
|
392
|
+
return [
|
|
393
|
+
comments()
|
|
394
|
+
];
|
|
395
|
+
}
|
|
396
|
+
const threads2 = computed(() => [
|
|
397
|
+
...doc.threads.filter(nonNullable3),
|
|
398
|
+
...state.drafts[fullyQualifiedId4(doc)] ?? []
|
|
399
|
+
].filter((thread) => !(thread?.status === "resolved")));
|
|
400
|
+
return [
|
|
401
|
+
EditorView.updateListener.of((update) => {
|
|
402
|
+
if (update.docChanged) {
|
|
403
|
+
doc.threads.forEach((thread) => {
|
|
404
|
+
if (thread?.anchor) {
|
|
405
|
+
const name = getName(doc, thread.anchor);
|
|
406
|
+
if (name && name !== thread.name) {
|
|
407
|
+
thread.name = name;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}),
|
|
413
|
+
createExternalCommentSync(fullyQualifiedId4(doc), (sink) => effect(() => sink()), () => threads2.value.filter((thread) => thread?.anchor).map((thread) => ({
|
|
414
|
+
id: fullyQualifiedId4(thread),
|
|
415
|
+
cursor: thread.anchor
|
|
416
|
+
}))),
|
|
417
|
+
comments({
|
|
418
|
+
id: fullyQualifiedId4(doc),
|
|
419
|
+
onCreate: ({ cursor }) => {
|
|
420
|
+
const name = getName(doc, cursor);
|
|
421
|
+
void dispatch({
|
|
422
|
+
action: ThreadAction.CREATE,
|
|
423
|
+
data: {
|
|
424
|
+
cursor,
|
|
425
|
+
name,
|
|
426
|
+
subject: doc
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
},
|
|
430
|
+
onDelete: ({ id }) => {
|
|
431
|
+
const draft = state.drafts[fullyQualifiedId4(doc)];
|
|
432
|
+
if (draft) {
|
|
433
|
+
const index = draft.findIndex((thread2) => fullyQualifiedId4(thread2) === id);
|
|
434
|
+
if (index !== -1) {
|
|
435
|
+
draft.splice(index, 1);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const thread = doc.threads.find((thread2) => thread2?.id === id);
|
|
439
|
+
if (thread) {
|
|
440
|
+
thread.anchor = void 0;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
onUpdate: ({ id, cursor }) => {
|
|
444
|
+
const thread = state.drafts[fullyQualifiedId4(doc)]?.find((thread2) => fullyQualifiedId4(thread2) === id) ?? doc.threads.find((thread2) => thread2?.id === id);
|
|
445
|
+
if (thread instanceof ThreadType && thread.anchor) {
|
|
446
|
+
thread.name = getName(doc, thread.anchor);
|
|
447
|
+
thread.anchor = cursor;
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
onSelect: ({ selection: { current, closest } }) => {
|
|
451
|
+
void dispatch({
|
|
452
|
+
action: ThreadAction.SELECT,
|
|
453
|
+
data: {
|
|
454
|
+
current: current ?? closest,
|
|
455
|
+
skipOpen: true
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
})
|
|
460
|
+
];
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// packages/plugins/plugin-thread/src/translations.ts
|
|
464
|
+
var translations_default = [
|
|
465
|
+
{
|
|
466
|
+
"en-US": {
|
|
467
|
+
[THREAD_PLUGIN]: {
|
|
468
|
+
"plugin name": "Threads",
|
|
469
|
+
"channel name placeholder": "New channel",
|
|
470
|
+
"channel title label": "Title",
|
|
471
|
+
"delete channel label": "Delete channel",
|
|
472
|
+
"create channel label": "Create channel",
|
|
473
|
+
"message placeholder": "Reply\u2026",
|
|
474
|
+
"settings standalone label": "Enable channel creation (experimental)",
|
|
475
|
+
"activity message": "Processing\u2026",
|
|
476
|
+
"anonymous label": "Anonymous",
|
|
477
|
+
"delete message block label": "Delete message block",
|
|
478
|
+
"detached thread label": "Referenced content was removed",
|
|
479
|
+
"delete thread label": "Delete thread",
|
|
480
|
+
"thread deleted label": "You deleted a thread.",
|
|
481
|
+
"message deleted label": "You deleted a message.",
|
|
482
|
+
"comments heading": "Comments",
|
|
483
|
+
"chat heading": "Chat",
|
|
484
|
+
"draft button": "DRAFT",
|
|
485
|
+
"no comments title": "No comments (yet)",
|
|
486
|
+
"no comments message": "To start a comment thread, select a range of text in a document and click the <commentIcon></commentIcon> Create comment button in the toolbar.",
|
|
487
|
+
"toggle show resolved": "Show resolved",
|
|
488
|
+
"unnamed object threads label": "Threads",
|
|
489
|
+
"mark as resolved label": "Mark as resolved",
|
|
490
|
+
"mark as unresolved label": "Mark as unresolved",
|
|
491
|
+
"save message label": "Save",
|
|
492
|
+
"edit message label": "Edit",
|
|
493
|
+
"delete message label": "Delete message"
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
];
|
|
498
|
+
|
|
499
|
+
// packages/plugins/plugin-thread/src/ThreadPlugin.tsx
|
|
500
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-thread/src/ThreadPlugin.tsx";
|
|
501
|
+
var initialViewState = {
|
|
502
|
+
showResolvedThreads: false
|
|
503
|
+
};
|
|
504
|
+
var ThreadPlugin = () => {
|
|
505
|
+
const settings = new LocalStorageStore(THREAD_PLUGIN);
|
|
506
|
+
const state = create2({
|
|
507
|
+
drafts: {}
|
|
508
|
+
});
|
|
509
|
+
const viewStore = create2({});
|
|
510
|
+
const getViewState = (subjectId) => {
|
|
511
|
+
if (!viewStore[subjectId]) {
|
|
512
|
+
viewStore[subjectId] = {
|
|
513
|
+
...initialViewState
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return viewStore[subjectId];
|
|
517
|
+
};
|
|
518
|
+
let navigationPlugin;
|
|
519
|
+
let intentPlugin;
|
|
520
|
+
const unsubscribeCallbacks = [];
|
|
521
|
+
return {
|
|
522
|
+
meta: meta_default,
|
|
523
|
+
ready: async (plugins) => {
|
|
524
|
+
settings.prop({
|
|
525
|
+
key: "standalone",
|
|
526
|
+
type: LocalStorageStore.bool({
|
|
527
|
+
allowUndefined: true
|
|
528
|
+
})
|
|
529
|
+
});
|
|
530
|
+
navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin);
|
|
531
|
+
intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
|
|
532
|
+
},
|
|
533
|
+
unload: async () => {
|
|
534
|
+
unsubscribeCallbacks.forEach((unsubscribe) => unsubscribe());
|
|
535
|
+
},
|
|
536
|
+
provides: {
|
|
537
|
+
settings: settings.values,
|
|
538
|
+
metadata: {
|
|
539
|
+
records: {
|
|
540
|
+
[ChannelType.typename]: {
|
|
541
|
+
placeholder: [
|
|
542
|
+
"channel title placeholder",
|
|
543
|
+
{
|
|
544
|
+
ns: THREAD_PLUGIN
|
|
545
|
+
}
|
|
546
|
+
],
|
|
547
|
+
icon: "ph--chat--regular",
|
|
548
|
+
// TODO(wittjosiah): Move out of metadata.
|
|
549
|
+
loadReferences: (channel) => loadObjectReferences(channel, (channel2) => channel2.threads)
|
|
550
|
+
},
|
|
551
|
+
[ThreadType2.typename]: {
|
|
552
|
+
// TODO(wittjosiah): Move out of metadata.
|
|
553
|
+
loadReferences: (thread) => loadObjectReferences(thread, (thread2) => thread2.messages)
|
|
554
|
+
},
|
|
555
|
+
[MessageType2.typename]: {
|
|
556
|
+
// TODO(wittjosiah): Move out of metadata.
|
|
557
|
+
loadReferences: (message) => []
|
|
558
|
+
},
|
|
559
|
+
[THREAD_ITEM]: {
|
|
560
|
+
parse: (item, type) => {
|
|
561
|
+
switch (type) {
|
|
562
|
+
case "node":
|
|
563
|
+
return {
|
|
564
|
+
id: item.id,
|
|
565
|
+
label: item.title,
|
|
566
|
+
data: item
|
|
567
|
+
};
|
|
568
|
+
case "object":
|
|
569
|
+
return item;
|
|
570
|
+
case "view-object":
|
|
571
|
+
return {
|
|
572
|
+
id: `${item.id}-view`,
|
|
573
|
+
object: item
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
translations: [
|
|
581
|
+
...translations_default,
|
|
582
|
+
...threadTranslations
|
|
583
|
+
],
|
|
584
|
+
echo: {
|
|
585
|
+
schema: [
|
|
586
|
+
ChannelType,
|
|
587
|
+
ThreadType2,
|
|
588
|
+
MessageType2
|
|
589
|
+
]
|
|
590
|
+
},
|
|
591
|
+
graph: {
|
|
592
|
+
builder: (plugins) => {
|
|
593
|
+
const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
|
|
594
|
+
const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
|
|
595
|
+
const metadataResolver = resolvePlugin(plugins, parseMetadataResolverPlugin)?.provides.metadata.resolver;
|
|
596
|
+
if (!client || !dispatch || !metadataResolver) {
|
|
597
|
+
return [];
|
|
598
|
+
}
|
|
599
|
+
const type = "orphan-comments-for-subject";
|
|
600
|
+
const icon = "ph--chat-text--regular";
|
|
601
|
+
return [
|
|
602
|
+
createExtension({
|
|
603
|
+
id: `${THREAD_PLUGIN}/comments-for-subject`,
|
|
604
|
+
resolver: ({ id }) => {
|
|
605
|
+
if (!id.endsWith("~comments")) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const [subjectId] = id.split("~");
|
|
609
|
+
const { spaceId, objectId } = parseId(subjectId);
|
|
610
|
+
const space = client.spaces.get().find((space2) => space2.id === spaceId);
|
|
611
|
+
if (!objectId) {
|
|
612
|
+
return {
|
|
613
|
+
id,
|
|
614
|
+
type,
|
|
615
|
+
data: null,
|
|
616
|
+
properties: {
|
|
617
|
+
icon,
|
|
618
|
+
label: [
|
|
619
|
+
"unnamed object threads label",
|
|
620
|
+
{
|
|
621
|
+
ns: THREAD_PLUGIN
|
|
622
|
+
}
|
|
623
|
+
],
|
|
624
|
+
showResolvedThreads: false,
|
|
625
|
+
object: null,
|
|
626
|
+
space
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
const object = toSignal((onChange) => {
|
|
631
|
+
const timeout = setTimeout(async () => {
|
|
632
|
+
await space?.db.loadObjectById(objectId);
|
|
633
|
+
onChange();
|
|
634
|
+
});
|
|
635
|
+
return () => clearTimeout(timeout);
|
|
636
|
+
}, () => space?.db.getObjectById(objectId), subjectId);
|
|
637
|
+
if (!object || !subjectId) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const meta = metadataResolver(getTypename(object) ?? "");
|
|
641
|
+
const label = meta.label?.(object) || object.name || meta.placeholder || [
|
|
642
|
+
"unnamed object threads label",
|
|
643
|
+
{
|
|
644
|
+
ns: THREAD_PLUGIN
|
|
645
|
+
}
|
|
646
|
+
];
|
|
647
|
+
const viewState = getViewState(subjectId);
|
|
648
|
+
return {
|
|
649
|
+
id,
|
|
650
|
+
type,
|
|
651
|
+
data: null,
|
|
652
|
+
properties: {
|
|
653
|
+
icon,
|
|
654
|
+
label,
|
|
655
|
+
showResolvedThreads: viewState.showResolvedThreads,
|
|
656
|
+
object
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
},
|
|
660
|
+
actions: ({ node }) => {
|
|
661
|
+
const dataId = node.id.split("~").at(0);
|
|
662
|
+
if (!node.id.endsWith("~comments") || !dataId) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const [spaceId, objectId] = dataId.split(":");
|
|
666
|
+
const viewState = getViewState(dataId);
|
|
667
|
+
const toggle = () => {
|
|
668
|
+
const newToggleState = !viewState.showResolvedThreads;
|
|
669
|
+
viewState.showResolvedThreads = newToggleState;
|
|
670
|
+
void dispatch({
|
|
671
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
672
|
+
data: {
|
|
673
|
+
name: "threads.toggle-show-resolved",
|
|
674
|
+
properties: {
|
|
675
|
+
spaceId,
|
|
676
|
+
threadId: objectId,
|
|
677
|
+
showResolved: newToggleState
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
};
|
|
682
|
+
return [
|
|
683
|
+
{
|
|
684
|
+
id: `${THREAD_PLUGIN}/toggle-show-resolved/${node.id}`,
|
|
685
|
+
data: toggle,
|
|
686
|
+
properties: {
|
|
687
|
+
label: [
|
|
688
|
+
"toggle show resolved",
|
|
689
|
+
{
|
|
690
|
+
ns: THREAD_PLUGIN
|
|
691
|
+
}
|
|
692
|
+
],
|
|
693
|
+
menuItemType: "toggle",
|
|
694
|
+
isChecked: viewState.showResolvedThreads,
|
|
695
|
+
testId: "threadPlugin.toggleShowResolved",
|
|
696
|
+
icon: viewState.showResolvedThreads ? "ph--eye-slash--regular" : "ph--eye--regular"
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
];
|
|
700
|
+
}
|
|
701
|
+
}),
|
|
702
|
+
createExtension({
|
|
703
|
+
id: ThreadAction.CREATE,
|
|
704
|
+
filter: (node) => !!settings.values.standalone && isActionGroup(node) && node.id.startsWith(SpaceAction.ADD_OBJECT),
|
|
705
|
+
actions: ({ node }) => {
|
|
706
|
+
const id = node.id.split("/").at(-1);
|
|
707
|
+
const [spaceId, objectId] = id?.split(":") ?? [];
|
|
708
|
+
const space = client.spaces.get().find((space2) => space2.id === spaceId);
|
|
709
|
+
const object = objectId && space?.db.getObjectById(objectId);
|
|
710
|
+
const target = objectId ? object : space;
|
|
711
|
+
if (!target) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
return [
|
|
715
|
+
{
|
|
716
|
+
id: `${THREAD_PLUGIN}/create/${node.id}`,
|
|
717
|
+
data: async () => {
|
|
718
|
+
await dispatch([
|
|
719
|
+
{
|
|
720
|
+
plugin: THREAD_PLUGIN,
|
|
721
|
+
action: ThreadAction.CREATE
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
action: SpaceAction.ADD_OBJECT,
|
|
725
|
+
data: {
|
|
726
|
+
target
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
action: NavigationAction.OPEN
|
|
731
|
+
}
|
|
732
|
+
]);
|
|
733
|
+
},
|
|
734
|
+
properties: {
|
|
735
|
+
label: [
|
|
736
|
+
"create channel label",
|
|
737
|
+
{
|
|
738
|
+
ns: THREAD_PLUGIN
|
|
739
|
+
}
|
|
740
|
+
],
|
|
741
|
+
icon: "ph--chat--regular",
|
|
742
|
+
testId: "threadPlugin.createObject"
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
];
|
|
746
|
+
}
|
|
747
|
+
})
|
|
748
|
+
];
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
surface: {
|
|
752
|
+
component: ({ data, role }) => {
|
|
753
|
+
switch (role) {
|
|
754
|
+
case "main": {
|
|
755
|
+
return data.active instanceof ChannelType && data.active.threads[0] ? /* @__PURE__ */ React5.createElement(ThreadMain, {
|
|
756
|
+
thread: data.active.threads[0]
|
|
757
|
+
}) : null;
|
|
758
|
+
}
|
|
759
|
+
case "settings": {
|
|
760
|
+
return data.plugin === meta_default.id ? /* @__PURE__ */ React5.createElement(ThreadSettings, {
|
|
761
|
+
settings: settings.values
|
|
762
|
+
}) : null;
|
|
763
|
+
}
|
|
764
|
+
case "article": {
|
|
765
|
+
const location = navigationPlugin?.provides.location;
|
|
766
|
+
if (data.object instanceof ChannelType && data.object.threads[0]) {
|
|
767
|
+
const channel = data.object;
|
|
768
|
+
if (isLayoutParts(location?.active) && location.active.main) {
|
|
769
|
+
const layoutEntries = location.active.main;
|
|
770
|
+
const currentPosition = layoutEntries.findIndex((entry) => channel.id === entry.id);
|
|
771
|
+
if (currentPosition > 0) {
|
|
772
|
+
const objectToTheLeft = layoutEntries[currentPosition - 1];
|
|
773
|
+
const context = getSpace3(data.object)?.db.getObjectById(objectToTheLeft.id);
|
|
774
|
+
return /* @__PURE__ */ React5.createElement(ThreadArticle, {
|
|
775
|
+
thread: data.object.threads[0],
|
|
776
|
+
context
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return /* @__PURE__ */ React5.createElement(ThreadArticle, {
|
|
781
|
+
thread: data.object.threads[0]
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
if (data.subject instanceof ThreadType2) {
|
|
785
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(ChatHeading, {
|
|
786
|
+
attendableId: data.subject.id
|
|
787
|
+
}), /* @__PURE__ */ React5.createElement(ChatContainer, {
|
|
788
|
+
thread: data.subject
|
|
789
|
+
}));
|
|
790
|
+
}
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
case "complementary--comments": {
|
|
794
|
+
if (data.subject && typeof data.subject === "object" && "threads" in data.subject && Array.isArray(data.subject.threads)) {
|
|
795
|
+
const { showResolvedThreads } = getViewState(fullyQualifiedId5(data.subject));
|
|
796
|
+
return /* @__PURE__ */ React5.createElement(ThreadComplementary, {
|
|
797
|
+
role,
|
|
798
|
+
subject: data.subject,
|
|
799
|
+
drafts: state.drafts[fullyQualifiedId5(data.subject)],
|
|
800
|
+
current: state.current,
|
|
801
|
+
showResolvedThreads
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
intent: {
|
|
811
|
+
resolver: async (intent) => {
|
|
812
|
+
switch (intent.action) {
|
|
813
|
+
case ThreadAction.CREATE: {
|
|
814
|
+
if (intent.data && intent.data.cursor !== void 0) {
|
|
815
|
+
const { cursor, name, subject } = intent.data;
|
|
816
|
+
if (subject?.threads === void 0) {
|
|
817
|
+
try {
|
|
818
|
+
subject.threads = [];
|
|
819
|
+
} catch (err) {
|
|
820
|
+
log.error("Subject does not support threads array", subject?.typename, {
|
|
821
|
+
F: __dxlog_file,
|
|
822
|
+
L: 347,
|
|
823
|
+
S: void 0,
|
|
824
|
+
C: (f, a) => f(...a)
|
|
825
|
+
});
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
const subjectId = fullyQualifiedId5(subject);
|
|
830
|
+
const thread = create2(ThreadType2, {
|
|
831
|
+
name,
|
|
832
|
+
anchor: cursor,
|
|
833
|
+
messages: [],
|
|
834
|
+
status: "staged"
|
|
835
|
+
});
|
|
836
|
+
const draft = state.drafts[subjectId];
|
|
837
|
+
if (draft) {
|
|
838
|
+
draft.push(thread);
|
|
839
|
+
} else {
|
|
840
|
+
state.drafts[subjectId] = [
|
|
841
|
+
thread
|
|
842
|
+
];
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
data: thread,
|
|
846
|
+
intents: [
|
|
847
|
+
[
|
|
848
|
+
{
|
|
849
|
+
action: ThreadAction.SELECT,
|
|
850
|
+
data: {
|
|
851
|
+
current: fullyQualifiedId5(thread)
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
],
|
|
855
|
+
[
|
|
856
|
+
{
|
|
857
|
+
action: NavigationAction.OPEN,
|
|
858
|
+
data: {
|
|
859
|
+
activeParts: {
|
|
860
|
+
complementary: "comments"
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
],
|
|
865
|
+
[
|
|
866
|
+
{
|
|
867
|
+
action: LayoutAction2.SET_LAYOUT,
|
|
868
|
+
data: {
|
|
869
|
+
element: "complementary",
|
|
870
|
+
state: true
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
]
|
|
874
|
+
]
|
|
875
|
+
};
|
|
876
|
+
} else {
|
|
877
|
+
return {
|
|
878
|
+
data: create2(ChannelType, {
|
|
879
|
+
threads: [
|
|
880
|
+
create2(ThreadType2, {
|
|
881
|
+
messages: []
|
|
882
|
+
})
|
|
883
|
+
]
|
|
884
|
+
})
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
case ThreadAction.SELECT: {
|
|
889
|
+
state.current = intent.data?.current;
|
|
890
|
+
return {
|
|
891
|
+
data: true,
|
|
892
|
+
intents: !intent.data?.skipOpen ? [
|
|
893
|
+
[
|
|
894
|
+
{
|
|
895
|
+
action: NavigationAction.OPEN,
|
|
896
|
+
data: {
|
|
897
|
+
activeParts: {
|
|
898
|
+
complementary: "comments"
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
]
|
|
903
|
+
] : []
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
case ThreadAction.TOGGLE_RESOLVED: {
|
|
907
|
+
const { thread } = intent.data ?? {};
|
|
908
|
+
if (!(thread instanceof ThreadType2)) {
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
if (thread.status === "active" || thread.status === void 0) {
|
|
912
|
+
thread.status = "resolved";
|
|
913
|
+
} else if (thread.status === "resolved") {
|
|
914
|
+
thread.status = "active";
|
|
915
|
+
}
|
|
916
|
+
const space = getSpace3(thread);
|
|
917
|
+
const spaceId = space?.id;
|
|
918
|
+
return {
|
|
919
|
+
data: true,
|
|
920
|
+
intents: [
|
|
921
|
+
[
|
|
922
|
+
{
|
|
923
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
924
|
+
data: {
|
|
925
|
+
name: "threads.toggle-resolved",
|
|
926
|
+
properties: {
|
|
927
|
+
threadId: thread.id,
|
|
928
|
+
spaceId
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
]
|
|
933
|
+
]
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
case ThreadAction.DELETE: {
|
|
937
|
+
const { subject, thread } = intent.data ?? {};
|
|
938
|
+
if (!(thread instanceof ThreadType2) || !(subject && typeof subject === "object" && "threads" in subject)) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const subjectId = fullyQualifiedId5(subject);
|
|
942
|
+
const draft = state.drafts[subjectId];
|
|
943
|
+
if (draft) {
|
|
944
|
+
const index = draft.findIndex((t) => t.id === thread.id);
|
|
945
|
+
if (index !== -1) {
|
|
946
|
+
draft.splice(index, 1);
|
|
947
|
+
return {
|
|
948
|
+
data: true
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
const space = getSpace3(thread);
|
|
953
|
+
if (!space || !subject.threads) {
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
if (!intent.undo) {
|
|
957
|
+
const index = subject.threads.findIndex((t) => t?.id === thread.id);
|
|
958
|
+
const cursor = subject.threads[index]?.anchor;
|
|
959
|
+
if (index !== -1) {
|
|
960
|
+
subject.threads?.splice(index, 1);
|
|
961
|
+
}
|
|
962
|
+
space.db.remove(thread);
|
|
963
|
+
return {
|
|
964
|
+
undoable: {
|
|
965
|
+
message: translations_default[0]["en-US"][THREAD_PLUGIN]["thread deleted label"],
|
|
966
|
+
data: {
|
|
967
|
+
cursor
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
intents: [
|
|
971
|
+
[
|
|
972
|
+
{
|
|
973
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
974
|
+
data: {
|
|
975
|
+
name: "threads.delete",
|
|
976
|
+
properties: {
|
|
977
|
+
threadId: thread.id,
|
|
978
|
+
spaceId: space.id
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
]
|
|
983
|
+
]
|
|
984
|
+
};
|
|
985
|
+
} else if (intent.undo) {
|
|
986
|
+
const savedThread = space.db.add(thread);
|
|
987
|
+
subject.threads.push(savedThread);
|
|
988
|
+
return {
|
|
989
|
+
data: true,
|
|
990
|
+
intents: [
|
|
991
|
+
[
|
|
992
|
+
{
|
|
993
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
994
|
+
data: {
|
|
995
|
+
name: "threads.undo-delete",
|
|
996
|
+
properties: {
|
|
997
|
+
threadId: thread.id,
|
|
998
|
+
spaceId: space.id
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
]
|
|
1003
|
+
]
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
case ThreadAction.ON_MESSAGE_ADD: {
|
|
1009
|
+
const { thread, subject } = intent.data ?? {};
|
|
1010
|
+
if (!(thread instanceof ThreadType2) || !(subject && typeof subject === "object" && "threads" in subject && Array.isArray(subject.threads))) {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
const subjectId = fullyQualifiedId5(subject);
|
|
1014
|
+
const space = getSpace3(subject);
|
|
1015
|
+
const intents = [];
|
|
1016
|
+
const analyticsProperties = {
|
|
1017
|
+
threadId: thread.id,
|
|
1018
|
+
spaceId: space?.id
|
|
1019
|
+
};
|
|
1020
|
+
if (state.drafts[subjectId]?.find((t) => t === thread)) {
|
|
1021
|
+
thread.status = "active";
|
|
1022
|
+
subject.threads ? subject.threads.push(thread) : subject.threads = [
|
|
1023
|
+
thread
|
|
1024
|
+
];
|
|
1025
|
+
state.drafts[subjectId] = state.drafts[subjectId]?.filter(({ id }) => id !== thread.id);
|
|
1026
|
+
intents.push({
|
|
1027
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
1028
|
+
data: {
|
|
1029
|
+
name: "threads.thread-created",
|
|
1030
|
+
properties: analyticsProperties
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
intents.push({
|
|
1035
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
1036
|
+
data: {
|
|
1037
|
+
name: "threads.message-added",
|
|
1038
|
+
properties: {
|
|
1039
|
+
...analyticsProperties,
|
|
1040
|
+
threadLength: thread.messages.length
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
return {
|
|
1045
|
+
data: thread,
|
|
1046
|
+
intents: [
|
|
1047
|
+
intents
|
|
1048
|
+
]
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
case ThreadAction.DELETE_MESSAGE: {
|
|
1052
|
+
const { subject, thread, messageId } = intent.data ?? {};
|
|
1053
|
+
const space = getSpace3(subject);
|
|
1054
|
+
if (!(thread instanceof ThreadType2) || !(subject && typeof subject === "object" && "threads" in subject)) {
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (!intent.undo) {
|
|
1058
|
+
const message = thread.messages.find((m) => m?.id === messageId);
|
|
1059
|
+
const messageIndex = thread.messages.findIndex((m) => m?.id === messageId);
|
|
1060
|
+
if (messageIndex === -1 || !message) {
|
|
1061
|
+
return void 0;
|
|
1062
|
+
}
|
|
1063
|
+
if (messageIndex === 0 && thread.messages.length === 1) {
|
|
1064
|
+
return {
|
|
1065
|
+
intents: [
|
|
1066
|
+
[
|
|
1067
|
+
{
|
|
1068
|
+
action: ThreadAction.DELETE,
|
|
1069
|
+
data: {
|
|
1070
|
+
subject,
|
|
1071
|
+
thread
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
]
|
|
1075
|
+
]
|
|
1076
|
+
};
|
|
1077
|
+
} else {
|
|
1078
|
+
thread.messages.splice(messageIndex, 1);
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
1081
|
+
undoable: {
|
|
1082
|
+
message: translations_default[0]["en-US"][THREAD_PLUGIN]["message deleted label"],
|
|
1083
|
+
data: {
|
|
1084
|
+
message,
|
|
1085
|
+
messageIndex
|
|
1086
|
+
}
|
|
1087
|
+
},
|
|
1088
|
+
intents: [
|
|
1089
|
+
[
|
|
1090
|
+
{
|
|
1091
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
1092
|
+
data: {
|
|
1093
|
+
name: "threads.message.delete",
|
|
1094
|
+
properties: {
|
|
1095
|
+
threadId: thread.id,
|
|
1096
|
+
spaceId: space?.id
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
]
|
|
1101
|
+
]
|
|
1102
|
+
};
|
|
1103
|
+
} else if (intent.undo) {
|
|
1104
|
+
const message = intent.data?.message;
|
|
1105
|
+
const messageIndex = intent.data?.messageIndex;
|
|
1106
|
+
if (!(message instanceof MessageType2) || !(typeof messageIndex === "number")) {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
thread.messages.splice(messageIndex, 0, message);
|
|
1110
|
+
return {
|
|
1111
|
+
data: true,
|
|
1112
|
+
intents: [
|
|
1113
|
+
[
|
|
1114
|
+
{
|
|
1115
|
+
action: ObservabilityAction.SEND_EVENT,
|
|
1116
|
+
data: {
|
|
1117
|
+
name: "threads.message.undo-delete",
|
|
1118
|
+
properties: {
|
|
1119
|
+
threadId: thread.id,
|
|
1120
|
+
spaceId: space?.id
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
]
|
|
1125
|
+
]
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
},
|
|
1132
|
+
markdown: {
|
|
1133
|
+
extensions: ({ document: doc }) => {
|
|
1134
|
+
return threads(state, doc, intentPlugin?.provides.intent.dispatch);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
// packages/plugins/plugin-thread/src/index.ts
|
|
1142
|
+
var src_default = ThreadPlugin;
|
|
1143
|
+
export {
|
|
1144
|
+
ThreadAction,
|
|
1145
|
+
ThreadPlugin,
|
|
1146
|
+
src_default as default,
|
|
1147
|
+
useAnalyticsCallback,
|
|
1148
|
+
useOnEditAnalytics,
|
|
1149
|
+
useStatus
|
|
1150
|
+
};
|
|
1151
|
+
//# sourceMappingURL=index.mjs.map
|