@liveblocks/react-tiptap 3.6.2 → 3.7.0
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/LiveblocksExtension.cjs +3 -1
- package/dist/LiveblocksExtension.cjs.map +1 -1
- package/dist/LiveblocksExtension.js +3 -1
- package/dist/LiveblocksExtension.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mentions/GroupMentionNode.cjs +103 -0
- package/dist/mentions/GroupMentionNode.cjs.map +1 -0
- package/dist/mentions/GroupMentionNode.js +101 -0
- package/dist/mentions/GroupMentionNode.js.map +1 -0
- package/dist/mentions/Mention.cjs +84 -20
- package/dist/mentions/Mention.cjs.map +1 -1
- package/dist/mentions/Mention.js +85 -21
- package/dist/mentions/Mention.js.map +1 -1
- package/dist/mentions/MentionExtension.cjs +39 -15
- package/dist/mentions/MentionExtension.cjs.map +1 -1
- package/dist/mentions/MentionExtension.js +41 -17
- package/dist/mentions/MentionExtension.js.map +1 -1
- package/dist/mentions/MentionsList.cjs +46 -23
- package/dist/mentions/MentionsList.cjs.map +1 -1
- package/dist/mentions/MentionsList.js +49 -26
- package/dist/mentions/MentionsList.js.map +1 -1
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.cjs +31 -7
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +32 -8
- package/dist/utils.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -6
- package/src/styles/index.css +42 -21
- package/styles.css +1 -1
- package/styles.css.map +1 -1
|
@@ -49,15 +49,25 @@ const MentionsList = react.forwardRef(
|
|
|
49
49
|
if (!mention) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
+
const notificationId = core.createInboxNotificationId();
|
|
52
53
|
switch (mention.kind) {
|
|
53
54
|
case "user":
|
|
54
55
|
props.command({
|
|
56
|
+
kind: "user",
|
|
55
57
|
id: mention.id,
|
|
56
|
-
notificationId
|
|
58
|
+
notificationId
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
case "group":
|
|
62
|
+
props.command({
|
|
63
|
+
kind: "group",
|
|
64
|
+
id: mention.id,
|
|
65
|
+
userIds: mention.userIds,
|
|
66
|
+
notificationId
|
|
57
67
|
});
|
|
58
68
|
break;
|
|
59
69
|
default:
|
|
60
|
-
return core.assertNever(mention
|
|
70
|
+
return core.assertNever(mention, "Unhandled mention kind");
|
|
61
71
|
}
|
|
62
72
|
};
|
|
63
73
|
const upHandler = () => {
|
|
@@ -118,28 +128,41 @@ const MentionsList = react.forwardRef(
|
|
|
118
128
|
children: /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
119
129
|
className: "lb-tiptap-suggestions-list lb-tiptap-mention-suggestions-list",
|
|
120
130
|
children: suggestions.map((mention, index) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
132
|
+
className: "lb-tiptap-suggestions-list-item lb-tiptap-mention-suggestion",
|
|
133
|
+
role: "option",
|
|
134
|
+
"data-highlighted": index === selectedIndex || void 0,
|
|
135
|
+
onMouseEnter: handleMouseEnter(index),
|
|
136
|
+
onClick: handleClick(index),
|
|
137
|
+
children: mention.kind === "user" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsxRuntime.jsx(_private$1.Avatar, {
|
|
140
|
+
userId: mention.id,
|
|
141
|
+
className: "lb-tiptap-mention-suggestion-avatar"
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx(_private$1.User, {
|
|
144
|
+
userId: mention.id,
|
|
145
|
+
className: "lb-tiptap-mention-suggestion-user"
|
|
146
|
+
})
|
|
147
|
+
]
|
|
148
|
+
}) : mention.kind === "group" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsxRuntime.jsx(_private$1.Avatar, {
|
|
151
|
+
groupId: mention.id,
|
|
152
|
+
className: "lb-tiptap-mention-suggestion-avatar",
|
|
153
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(_private$1.UsersIcon, {})
|
|
154
|
+
}),
|
|
155
|
+
/* @__PURE__ */ jsxRuntime.jsx(_private$1.Group, {
|
|
156
|
+
groupId: mention.id,
|
|
157
|
+
className: "lb-tiptap-mention-suggestion-group",
|
|
158
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(_private$1.GroupDescription, {
|
|
159
|
+
groupId: mention.id,
|
|
160
|
+
className: "lb-tiptap-mention-suggestion-group-description"
|
|
137
161
|
})
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
}) : core.assertNever(mention, "Unhandled mention kind")
|
|
165
|
+
}, index);
|
|
143
166
|
})
|
|
144
167
|
})
|
|
145
168
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MentionsList.cjs","sources":["../../src/mentions/MentionsList.tsx"],"sourcesContent":["import {\n autoUpdate,\n flip,\n hide,\n limitShift,\n offset,\n shift,\n size,\n useFloating,\n} from \"@floating-ui/react-dom\";\nimport { assertNever, createInboxNotificationId } from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useMentionSuggestions,\n} from \"@liveblocks/react/_private\";\nimport { Avatar, User } from \"@liveblocks/react-ui/_private\";\nimport type { HTMLAttributes, MouseEvent } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useState } from \"react\";\n\nexport const SUGGESTIONS_COLLISION_PADDING = 10;\n\nexport interface MentionsListProps extends HTMLAttributes<HTMLDivElement> {\n query: string;\n command: (otps: { id: string; notificationId: string }) => void;\n clientRect: () => DOMRect;\n hide: boolean;\n}\n\nexport type MentionsListHandle = {\n onKeyDown: ({ event }: { event: KeyboardEvent }) => boolean;\n};\n\nexport const MentionsList = forwardRef<MentionsListHandle, MentionsListProps>(\n (props, ref) => {\n const [selectedIndex, setSelectedIndex] = useState(0);\n const room = useRoom();\n const suggestions = useMentionSuggestions(room.id, props.query);\n const { onMouseEnter, onClick } = props;\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"top-start\",\n middleware: [\n flip({ padding: SUGGESTIONS_COLLISION_PADDING, crossAxis: false }),\n offset(10),\n hide({ padding: SUGGESTIONS_COLLISION_PADDING }),\n shift({\n padding: SUGGESTIONS_COLLISION_PADDING,\n limiter: limitShift(),\n }),\n size({ padding: SUGGESTIONS_COLLISION_PADDING }),\n ],\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n useLayoutEffect(() => {\n setReference({\n getBoundingClientRect: props.clientRect,\n });\n }, [setReference, props.clientRect]);\n\n const selectItem = (index: number) => {\n const mention = (suggestions ?? [])[index];\n\n if (!mention) {\n return;\n }\n\n switch (mention.kind) {\n case \"user\":\n props.command({\n id: mention.id,\n notificationId: createInboxNotificationId(),\n });\n break;\n\n default:\n return assertNever(mention.kind, \"Unhandled mention kind\");\n }\n };\n\n const upHandler = () => {\n setSelectedIndex(\n (selectedIndex + (suggestions?.length ?? 0) - 1) %\n (suggestions?.length ?? 0)\n );\n };\n\n const downHandler = () => {\n setSelectedIndex((selectedIndex + 1) % (suggestions?.length ?? 0));\n };\n\n const enterHandler = () => {\n selectItem(selectedIndex);\n };\n\n useEffect(() => setSelectedIndex(0), [suggestions]);\n\n useImperativeHandle(ref, () => ({\n onKeyDown: ({ event }: { event: KeyboardEvent }) => {\n if (event.key === \"ArrowUp\") {\n upHandler();\n return true;\n }\n\n if (event.key === \"ArrowDown\") {\n downHandler();\n return true;\n }\n\n if (event.key === \"Enter\") {\n enterHandler();\n return true;\n }\n\n return false;\n },\n }));\n\n const handleClick =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n\n if (event.isDefaultPrevented()) return;\n selectItem(index);\n };\n const handleMouseEnter =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onMouseEnter?.(event);\n\n if (event.isDefaultPrevented()) return;\n\n setSelectedIndex(index);\n };\n\n if (suggestions === undefined || suggestions.length === 0) {\n return null;\n }\n\n return (\n <div\n className=\"lb-root lb-portal lb-elevation lb-tiptap-suggestions lb-tiptap-mention-suggestions\"\n ref={setFloating}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n display: props.hide ? \"none\" : \"block\",\n }}\n >\n <div className=\"lb-tiptap-suggestions-list lb-tiptap-mention-suggestions-list\">\n {suggestions.map((mention, index) => {\n switch (mention.kind) {\n case \"user\":\n return (\n <div\n className=\"lb-tiptap-suggestions-list-item lb-tiptap-mention-suggestion\"\n key={index}\n role=\"option\"\n data-highlighted={index === selectedIndex || undefined}\n onMouseEnter={handleMouseEnter(index)}\n onClick={handleClick(index)}\n >\n <Avatar\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-avatar\"\n />\n <User\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-user\"\n />\n </div>\n );\n\n default:\n return assertNever(mention.kind, \"Unhandled mention kind\");\n }\n })}\n </div>\n </div>\n );\n }\n);\n"],"names":["forwardRef","useState","useRoom","useMentionSuggestions","useFloating","flip","offset","hide","shift","limitShift","size","autoUpdate","useLayoutEffect","createInboxNotificationId","assertNever","useEffect","useImperativeHandle","jsx","jsxs","Avatar","User"],"mappings":";;;;;;;;;;AAoBO,MAAM,6BAAgC,GAAA,GAAA;AAatC,MAAM,YAAe,GAAAA,gBAAA;AAAA,EAC1B,CAAC,OAAO,GAAQ,KAAA;AACd,IAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAIC,eAAS,CAAC,CAAA,CAAA;AACpD,IAAA,MAAM,OAAOC,eAAQ,EAAA,CAAA;AACrB,IAAA,MAAM,WAAc,GAAAC,8BAAA,CAAsB,IAAK,CAAA,EAAA,EAAI,MAAM,KAAK,CAAA,CAAA;AAC9D,IAAM,MAAA,EAAE,YAAc,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAClC,IAAM,MAAA;AAAA,MACJ,IAAA,EAAM,EAAE,YAAA,EAAc,WAAY,EAAA;AAAA,MAClC,QAAA;AAAA,MACA,CAAA;AAAA,MACA,CAAA;AAAA,QACEC,oBAAY,CAAA;AAAA,MACd,QAAU,EAAA,OAAA;AAAA,MACV,SAAW,EAAA,WAAA;AAAA,MACX,UAAY,EAAA;AAAA,QACVC,cAAK,EAAE,OAAA,EAAS,6BAA+B,EAAA,SAAA,EAAW,OAAO,CAAA;AAAA,QACjEC,gBAAO,EAAE,CAAA;AAAA,QACTC,aAAK,CAAA,EAAE,OAAS,EAAA,6BAAA,EAA+B,CAAA;AAAA,QAC/CC,cAAM,CAAA;AAAA,UACJ,OAAS,EAAA,6BAAA;AAAA,UACT,SAASC,mBAAW,EAAA;AAAA,SACrB,CAAA;AAAA,QACDC,aAAK,CAAA,EAAE,OAAS,EAAA,6BAAA,EAA+B,CAAA;AAAA,OACjD;AAAA,MACA,oBAAA,EAAsB,IAAI,IAAS,KAAA;AACjC,QAAO,OAAAC,mBAAA,CAAW,GAAG,IAAM,EAAA;AAAA,UACzB,cAAgB,EAAA,IAAA;AAAA,SACjB,CAAA,C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AY,OAAQ,CAAA,IAAA,EAAM,wBAAwB,CAAA,CAAA;AAAA,WAC7D;AAAA,SACD,CAAA;AAAA,OACH,CAAA;AAAA,KACF,CAAA,CAAA;AAAA,GAEJ;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"MentionsList.cjs","sources":["../../src/mentions/MentionsList.tsx"],"sourcesContent":["import {\n autoUpdate,\n flip,\n hide,\n limitShift,\n offset,\n shift,\n size,\n useFloating,\n} from \"@floating-ui/react-dom\";\nimport { assertNever, createInboxNotificationId } from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useMentionSuggestions,\n} from \"@liveblocks/react/_private\";\nimport {\n Avatar,\n Group,\n GroupDescription,\n User,\n UsersIcon,\n} from \"@liveblocks/react-ui/_private\";\nimport type { HTMLAttributes, MouseEvent } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useState } from \"react\";\n\nimport type { TiptapMentionData } from \"../types\";\n\nexport const SUGGESTIONS_COLLISION_PADDING = 10;\n\nexport interface MentionsListProps extends HTMLAttributes<HTMLDivElement> {\n query: string;\n command: (otps: TiptapMentionData) => void;\n clientRect: () => DOMRect;\n hide: boolean;\n}\n\nexport type MentionsListHandle = {\n onKeyDown: ({ event }: { event: KeyboardEvent }) => boolean;\n};\n\nexport const MentionsList = forwardRef<MentionsListHandle, MentionsListProps>(\n (props, ref) => {\n const [selectedIndex, setSelectedIndex] = useState(0);\n const room = useRoom();\n const suggestions = useMentionSuggestions(room.id, props.query);\n const { onMouseEnter, onClick } = props;\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"top-start\",\n middleware: [\n flip({ padding: SUGGESTIONS_COLLISION_PADDING, crossAxis: false }),\n offset(10),\n hide({ padding: SUGGESTIONS_COLLISION_PADDING }),\n shift({\n padding: SUGGESTIONS_COLLISION_PADDING,\n limiter: limitShift(),\n }),\n size({ padding: SUGGESTIONS_COLLISION_PADDING }),\n ],\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n useLayoutEffect(() => {\n setReference({\n getBoundingClientRect: props.clientRect,\n });\n }, [setReference, props.clientRect]);\n\n const selectItem = (index: number) => {\n const mention = (suggestions ?? [])[index];\n\n if (!mention) {\n return;\n }\n\n const notificationId = createInboxNotificationId();\n\n switch (mention.kind) {\n case \"user\":\n props.command({\n kind: \"user\",\n id: mention.id,\n notificationId,\n });\n break;\n\n case \"group\":\n props.command({\n kind: \"group\",\n id: mention.id,\n userIds: mention.userIds,\n notificationId,\n });\n break;\n\n default:\n return assertNever(mention, \"Unhandled mention kind\");\n }\n };\n\n const upHandler = () => {\n setSelectedIndex(\n (selectedIndex + (suggestions?.length ?? 0) - 1) %\n (suggestions?.length ?? 0)\n );\n };\n\n const downHandler = () => {\n setSelectedIndex((selectedIndex + 1) % (suggestions?.length ?? 0));\n };\n\n const enterHandler = () => {\n selectItem(selectedIndex);\n };\n\n useEffect(() => setSelectedIndex(0), [suggestions]);\n\n useImperativeHandle(ref, () => ({\n onKeyDown: ({ event }: { event: KeyboardEvent }) => {\n if (event.key === \"ArrowUp\") {\n upHandler();\n return true;\n }\n\n if (event.key === \"ArrowDown\") {\n downHandler();\n return true;\n }\n\n if (event.key === \"Enter\") {\n enterHandler();\n return true;\n }\n\n return false;\n },\n }));\n\n const handleClick =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n\n if (event.isDefaultPrevented()) return;\n selectItem(index);\n };\n const handleMouseEnter =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onMouseEnter?.(event);\n\n if (event.isDefaultPrevented()) return;\n\n setSelectedIndex(index);\n };\n\n if (suggestions === undefined || suggestions.length === 0) {\n return null;\n }\n\n return (\n <div\n className=\"lb-root lb-portal lb-elevation lb-tiptap-suggestions lb-tiptap-mention-suggestions\"\n ref={setFloating}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n display: props.hide ? \"none\" : \"block\",\n }}\n >\n <div className=\"lb-tiptap-suggestions-list lb-tiptap-mention-suggestions-list\">\n {suggestions.map((mention, index) => {\n return (\n <div\n className=\"lb-tiptap-suggestions-list-item lb-tiptap-mention-suggestion\"\n key={index}\n role=\"option\"\n data-highlighted={index === selectedIndex || undefined}\n onMouseEnter={handleMouseEnter(index)}\n onClick={handleClick(index)}\n >\n {mention.kind === \"user\" ? (\n <>\n <Avatar\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-avatar\"\n />\n <User\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-user\"\n />\n </>\n ) : mention.kind === \"group\" ? (\n <>\n <Avatar\n groupId={mention.id}\n className=\"lb-tiptap-mention-suggestion-avatar\"\n icon={<UsersIcon />}\n />\n <Group\n groupId={mention.id}\n className=\"lb-tiptap-mention-suggestion-group\"\n >\n <GroupDescription\n groupId={mention.id}\n className=\"lb-tiptap-mention-suggestion-group-description\"\n />\n </Group>\n </>\n ) : (\n assertNever(mention, \"Unhandled mention kind\")\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n }\n);\n"],"names":["forwardRef","useState","useRoom","useMentionSuggestions","useFloating","flip","offset","hide","shift","limitShift","size","autoUpdate","useLayoutEffect","createInboxNotificationId","assertNever","useEffect","useImperativeHandle","jsx","jsxs","Fragment","Avatar","User","UsersIcon","Group","GroupDescription"],"mappings":";;;;;;;;;;AA4BO,MAAM,6BAAgC,GAAA,GAAA;AAatC,MAAM,YAAe,GAAAA,gBAAA;AAAA,EAC1B,CAAC,OAAO,GAAQ,KAAA;AACd,IAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAIC,eAAS,CAAC,CAAA,CAAA;AACpD,IAAA,MAAM,OAAOC,eAAQ,EAAA,CAAA;AACrB,IAAA,MAAM,WAAc,GAAAC,8BAAA,CAAsB,IAAK,CAAA,EAAA,EA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,qCAAA;AAAA,kBACV,IAAA,iCAAOE,oBAAU,EAAA,EAAA,CAAA;AAAA,iBACnB,CAAA;AAAA,gCACCL,cAAA,CAAAM,gBAAA,EAAA;AAAA,kBACC,SAAS,OAAQ,CAAA,EAAA;AAAA,kBACjB,SAAU,EAAA,oCAAA;AAAA,kBAEV,QAAC,kBAAAN,cAAA,CAAAO,2BAAA,EAAA;AAAA,oBACC,SAAS,OAAQ,CAAA,EAAA;AAAA,oBACjB,SAAU,EAAA,gDAAA;AAAA,mBACZ,CAAA;AAAA,iBACF,CAAA;AAAA,eAAA;AAAA,aACF,CAAA,GAEAV,gBAAY,CAAA,OAAA,EAAS,wBAAwB,CAAA;AAAA,WAAA,EAnC1C,KAqCP,CAAA,CAAA;AAAA,SAEH,CAAA;AAAA,OACH,CAAA;AAAA,KACF,CAAA,CAAA;AAAA,GAEJ;AACF;;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useFloating, flip, offset, hide, shift, limitShift, size, autoUpdate } from '@floating-ui/react-dom';
|
|
3
|
-
import {
|
|
3
|
+
import { createInboxNotificationId, assertNever } from '@liveblocks/core';
|
|
4
4
|
import { useRoom } from '@liveblocks/react';
|
|
5
5
|
import { useMentionSuggestions, useLayoutEffect } from '@liveblocks/react/_private';
|
|
6
|
-
import { Avatar, User } from '@liveblocks/react-ui/_private';
|
|
6
|
+
import { Avatar, User, UsersIcon, Group, GroupDescription } from '@liveblocks/react-ui/_private';
|
|
7
7
|
import { forwardRef, useState, useEffect, useImperativeHandle } from 'react';
|
|
8
8
|
|
|
9
9
|
const SUGGESTIONS_COLLISION_PADDING = 10;
|
|
@@ -47,15 +47,25 @@ const MentionsList = forwardRef(
|
|
|
47
47
|
if (!mention) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
+
const notificationId = createInboxNotificationId();
|
|
50
51
|
switch (mention.kind) {
|
|
51
52
|
case "user":
|
|
52
53
|
props.command({
|
|
54
|
+
kind: "user",
|
|
53
55
|
id: mention.id,
|
|
54
|
-
notificationId
|
|
56
|
+
notificationId
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
case "group":
|
|
60
|
+
props.command({
|
|
61
|
+
kind: "group",
|
|
62
|
+
id: mention.id,
|
|
63
|
+
userIds: mention.userIds,
|
|
64
|
+
notificationId
|
|
55
65
|
});
|
|
56
66
|
break;
|
|
57
67
|
default:
|
|
58
|
-
return assertNever(mention
|
|
68
|
+
return assertNever(mention, "Unhandled mention kind");
|
|
59
69
|
}
|
|
60
70
|
};
|
|
61
71
|
const upHandler = () => {
|
|
@@ -116,28 +126,41 @@ const MentionsList = forwardRef(
|
|
|
116
126
|
children: /* @__PURE__ */ jsx("div", {
|
|
117
127
|
className: "lb-tiptap-suggestions-list lb-tiptap-mention-suggestions-list",
|
|
118
128
|
children: suggestions.map((mention, index) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
return /* @__PURE__ */ jsx("div", {
|
|
130
|
+
className: "lb-tiptap-suggestions-list-item lb-tiptap-mention-suggestion",
|
|
131
|
+
role: "option",
|
|
132
|
+
"data-highlighted": index === selectedIndex || void 0,
|
|
133
|
+
onMouseEnter: handleMouseEnter(index),
|
|
134
|
+
onClick: handleClick(index),
|
|
135
|
+
children: mention.kind === "user" ? /* @__PURE__ */ jsxs(Fragment, {
|
|
136
|
+
children: [
|
|
137
|
+
/* @__PURE__ */ jsx(Avatar, {
|
|
138
|
+
userId: mention.id,
|
|
139
|
+
className: "lb-tiptap-mention-suggestion-avatar"
|
|
140
|
+
}),
|
|
141
|
+
/* @__PURE__ */ jsx(User, {
|
|
142
|
+
userId: mention.id,
|
|
143
|
+
className: "lb-tiptap-mention-suggestion-user"
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
}) : mention.kind === "group" ? /* @__PURE__ */ jsxs(Fragment, {
|
|
147
|
+
children: [
|
|
148
|
+
/* @__PURE__ */ jsx(Avatar, {
|
|
149
|
+
groupId: mention.id,
|
|
150
|
+
className: "lb-tiptap-mention-suggestion-avatar",
|
|
151
|
+
icon: /* @__PURE__ */ jsx(UsersIcon, {})
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ jsx(Group, {
|
|
154
|
+
groupId: mention.id,
|
|
155
|
+
className: "lb-tiptap-mention-suggestion-group",
|
|
156
|
+
children: /* @__PURE__ */ jsx(GroupDescription, {
|
|
157
|
+
groupId: mention.id,
|
|
158
|
+
className: "lb-tiptap-mention-suggestion-group-description"
|
|
135
159
|
})
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
160
|
+
})
|
|
161
|
+
]
|
|
162
|
+
}) : assertNever(mention, "Unhandled mention kind")
|
|
163
|
+
}, index);
|
|
141
164
|
})
|
|
142
165
|
})
|
|
143
166
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MentionsList.js","sources":["../../src/mentions/MentionsList.tsx"],"sourcesContent":["import {\n autoUpdate,\n flip,\n hide,\n limitShift,\n offset,\n shift,\n size,\n useFloating,\n} from \"@floating-ui/react-dom\";\nimport { assertNever, createInboxNotificationId } from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useMentionSuggestions,\n} from \"@liveblocks/react/_private\";\nimport { Avatar, User } from \"@liveblocks/react-ui/_private\";\nimport type { HTMLAttributes, MouseEvent } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useState } from \"react\";\n\nexport const SUGGESTIONS_COLLISION_PADDING = 10;\n\nexport interface MentionsListProps extends HTMLAttributes<HTMLDivElement> {\n query: string;\n command: (otps: { id: string; notificationId: string }) => void;\n clientRect: () => DOMRect;\n hide: boolean;\n}\n\nexport type MentionsListHandle = {\n onKeyDown: ({ event }: { event: KeyboardEvent }) => boolean;\n};\n\nexport const MentionsList = forwardRef<MentionsListHandle, MentionsListProps>(\n (props, ref) => {\n const [selectedIndex, setSelectedIndex] = useState(0);\n const room = useRoom();\n const suggestions = useMentionSuggestions(room.id, props.query);\n const { onMouseEnter, onClick } = props;\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"top-start\",\n middleware: [\n flip({ padding: SUGGESTIONS_COLLISION_PADDING, crossAxis: false }),\n offset(10),\n hide({ padding: SUGGESTIONS_COLLISION_PADDING }),\n shift({\n padding: SUGGESTIONS_COLLISION_PADDING,\n limiter: limitShift(),\n }),\n size({ padding: SUGGESTIONS_COLLISION_PADDING }),\n ],\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n useLayoutEffect(() => {\n setReference({\n getBoundingClientRect: props.clientRect,\n });\n }, [setReference, props.clientRect]);\n\n const selectItem = (index: number) => {\n const mention = (suggestions ?? [])[index];\n\n if (!mention) {\n return;\n }\n\n switch (mention.kind) {\n case \"user\":\n props.command({\n id: mention.id,\n notificationId: createInboxNotificationId(),\n });\n break;\n\n default:\n return assertNever(mention.kind, \"Unhandled mention kind\");\n }\n };\n\n const upHandler = () => {\n setSelectedIndex(\n (selectedIndex + (suggestions?.length ?? 0) - 1) %\n (suggestions?.length ?? 0)\n );\n };\n\n const downHandler = () => {\n setSelectedIndex((selectedIndex + 1) % (suggestions?.length ?? 0));\n };\n\n const enterHandler = () => {\n selectItem(selectedIndex);\n };\n\n useEffect(() => setSelectedIndex(0), [suggestions]);\n\n useImperativeHandle(ref, () => ({\n onKeyDown: ({ event }: { event: KeyboardEvent }) => {\n if (event.key === \"ArrowUp\") {\n upHandler();\n return true;\n }\n\n if (event.key === \"ArrowDown\") {\n downHandler();\n return true;\n }\n\n if (event.key === \"Enter\") {\n enterHandler();\n return true;\n }\n\n return false;\n },\n }));\n\n const handleClick =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n\n if (event.isDefaultPrevented()) return;\n selectItem(index);\n };\n const handleMouseEnter =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onMouseEnter?.(event);\n\n if (event.isDefaultPrevented()) return;\n\n setSelectedIndex(index);\n };\n\n if (suggestions === undefined || suggestions.length === 0) {\n return null;\n }\n\n return (\n <div\n className=\"lb-root lb-portal lb-elevation lb-tiptap-suggestions lb-tiptap-mention-suggestions\"\n ref={setFloating}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n display: props.hide ? \"none\" : \"block\",\n }}\n >\n <div className=\"lb-tiptap-suggestions-list lb-tiptap-mention-suggestions-list\">\n {suggestions.map((mention, index) => {\n switch (mention.kind) {\n case \"user\":\n return (\n <div\n className=\"lb-tiptap-suggestions-list-item lb-tiptap-mention-suggestion\"\n key={index}\n role=\"option\"\n data-highlighted={index === selectedIndex || undefined}\n onMouseEnter={handleMouseEnter(index)}\n onClick={handleClick(index)}\n >\n <Avatar\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-avatar\"\n />\n <User\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-user\"\n />\n </div>\n );\n\n default:\n return assertNever(mention.kind, \"Unhandled mention kind\");\n }\n })}\n </div>\n </div>\n );\n }\n);\n"],"names":[],"mappings":";;;;;;;;AAoBO,MAAM,6BAAgC,GAAA,GAAA;AAatC,MAAM,YAAe,GAAA,UAAA;AAAA,EAC1B,CAAC,OAAO,GAAQ,KAAA;AACd,IAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,CAAC,CAAA,CAAA;AACpD,IAAA,MAAM,OAAO,OA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AO,MAAS,GAAA,OAAA;AAAA,OACjC;AAAA,MAEA,QAAC,kBAAA,GAAA,CAAA,KAAA,EAAA;AAAA,QAAI,SAAU,EAAA,+DAAA;AAAA,QACZ,QAAY,EAAA,WAAA,CAAA,GAAA,CAAI,CAAC,OAAA,EAAS,KAAU,KAAA;AACnC,UAAA,QAAQ,QAAQ,IAAM;AAAA,YACpB,KAAK,MAAA;AACH,cAAA,uBACG,IAAA,CAAA,KAAA,EAAA;AAAA,gBACC,SAAU,EAAA,8DAAA;AAAA,gBAEV,IAAK,EAAA,QAAA;AAAA,gBACL,kBAAA,EAAkB,UAAU,aAAiB,IAAA,KAAA,CAAA;AAAA,gBAC7C,YAAA,EAAc,iBAAiB,KAAK,CAAA;AAAA,gBACpC,OAAA,EAAS,YAAY,KAAK,CAAA;AAAA,gBAE1B,QAAA,EAAA;AAAA,kCAAC,GAAA,CAAA,MAAA,EAAA;AAAA,oBACC,QAAQ,OAAQ,CAAA,EAAA;AAAA,oBAChB,SAAU,EAAA,qCAAA;AAAA,mBACZ,CAAA;AAAA,kCACC,GAAA,CAAA,IAAA,EAAA;AAAA,oBACC,QAAQ,OAAQ,CAAA,EAAA;AAAA,oBAChB,SAAU,EAAA,mCAAA;AAAA,mBACZ,CAAA;AAAA,iBAAA;AAAA,eAAA,EAbK,KAcP,CAAA,CAAA;AAAA,YAGJ;AACE,cAAO,OAAA,WAAA,CAAY,OAAQ,CAAA,IAAA,EAAM,wBAAwB,CAAA,CAAA;AAAA,WAC7D;AAAA,SACD,CAAA;AAAA,OACH,CAAA;AAAA,KACF,CAAA,CAAA;AAAA,GAEJ;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"MentionsList.js","sources":["../../src/mentions/MentionsList.tsx"],"sourcesContent":["import {\n autoUpdate,\n flip,\n hide,\n limitShift,\n offset,\n shift,\n size,\n useFloating,\n} from \"@floating-ui/react-dom\";\nimport { assertNever, createInboxNotificationId } from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useMentionSuggestions,\n} from \"@liveblocks/react/_private\";\nimport {\n Avatar,\n Group,\n GroupDescription,\n User,\n UsersIcon,\n} from \"@liveblocks/react-ui/_private\";\nimport type { HTMLAttributes, MouseEvent } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useState } from \"react\";\n\nimport type { TiptapMentionData } from \"../types\";\n\nexport const SUGGESTIONS_COLLISION_PADDING = 10;\n\nexport interface MentionsListProps extends HTMLAttributes<HTMLDivElement> {\n query: string;\n command: (otps: TiptapMentionData) => void;\n clientRect: () => DOMRect;\n hide: boolean;\n}\n\nexport type MentionsListHandle = {\n onKeyDown: ({ event }: { event: KeyboardEvent }) => boolean;\n};\n\nexport const MentionsList = forwardRef<MentionsListHandle, MentionsListProps>(\n (props, ref) => {\n const [selectedIndex, setSelectedIndex] = useState(0);\n const room = useRoom();\n const suggestions = useMentionSuggestions(room.id, props.query);\n const { onMouseEnter, onClick } = props;\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"top-start\",\n middleware: [\n flip({ padding: SUGGESTIONS_COLLISION_PADDING, crossAxis: false }),\n offset(10),\n hide({ padding: SUGGESTIONS_COLLISION_PADDING }),\n shift({\n padding: SUGGESTIONS_COLLISION_PADDING,\n limiter: limitShift(),\n }),\n size({ padding: SUGGESTIONS_COLLISION_PADDING }),\n ],\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n useLayoutEffect(() => {\n setReference({\n getBoundingClientRect: props.clientRect,\n });\n }, [setReference, props.clientRect]);\n\n const selectItem = (index: number) => {\n const mention = (suggestions ?? [])[index];\n\n if (!mention) {\n return;\n }\n\n const notificationId = createInboxNotificationId();\n\n switch (mention.kind) {\n case \"user\":\n props.command({\n kind: \"user\",\n id: mention.id,\n notificationId,\n });\n break;\n\n case \"group\":\n props.command({\n kind: \"group\",\n id: mention.id,\n userIds: mention.userIds,\n notificationId,\n });\n break;\n\n default:\n return assertNever(mention, \"Unhandled mention kind\");\n }\n };\n\n const upHandler = () => {\n setSelectedIndex(\n (selectedIndex + (suggestions?.length ?? 0) - 1) %\n (suggestions?.length ?? 0)\n );\n };\n\n const downHandler = () => {\n setSelectedIndex((selectedIndex + 1) % (suggestions?.length ?? 0));\n };\n\n const enterHandler = () => {\n selectItem(selectedIndex);\n };\n\n useEffect(() => setSelectedIndex(0), [suggestions]);\n\n useImperativeHandle(ref, () => ({\n onKeyDown: ({ event }: { event: KeyboardEvent }) => {\n if (event.key === \"ArrowUp\") {\n upHandler();\n return true;\n }\n\n if (event.key === \"ArrowDown\") {\n downHandler();\n return true;\n }\n\n if (event.key === \"Enter\") {\n enterHandler();\n return true;\n }\n\n return false;\n },\n }));\n\n const handleClick =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n\n if (event.isDefaultPrevented()) return;\n selectItem(index);\n };\n const handleMouseEnter =\n (index: number) => (event: MouseEvent<HTMLDivElement>) => {\n onMouseEnter?.(event);\n\n if (event.isDefaultPrevented()) return;\n\n setSelectedIndex(index);\n };\n\n if (suggestions === undefined || suggestions.length === 0) {\n return null;\n }\n\n return (\n <div\n className=\"lb-root lb-portal lb-elevation lb-tiptap-suggestions lb-tiptap-mention-suggestions\"\n ref={setFloating}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n display: props.hide ? \"none\" : \"block\",\n }}\n >\n <div className=\"lb-tiptap-suggestions-list lb-tiptap-mention-suggestions-list\">\n {suggestions.map((mention, index) => {\n return (\n <div\n className=\"lb-tiptap-suggestions-list-item lb-tiptap-mention-suggestion\"\n key={index}\n role=\"option\"\n data-highlighted={index === selectedIndex || undefined}\n onMouseEnter={handleMouseEnter(index)}\n onClick={handleClick(index)}\n >\n {mention.kind === \"user\" ? (\n <>\n <Avatar\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-avatar\"\n />\n <User\n userId={mention.id}\n className=\"lb-tiptap-mention-suggestion-user\"\n />\n </>\n ) : mention.kind === \"group\" ? (\n <>\n <Avatar\n groupId={mention.id}\n className=\"lb-tiptap-mention-suggestion-avatar\"\n icon={<UsersIcon />}\n />\n <Group\n groupId={mention.id}\n className=\"lb-tiptap-mention-suggestion-group\"\n >\n <GroupDescription\n groupId={mention.id}\n className=\"lb-tiptap-mention-suggestion-group-description\"\n />\n </Group>\n </>\n ) : (\n assertNever(mention, \"Unhandled mention kind\")\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n }\n);\n"],"names":[],"mappings":";;;;;;;;AA4BO,MAAM,6BAAgC,GAAA,GAAA;AAatC,MAAM,YAAe,GAAA,UAAA;AAAA,EAC1B,CAAC,OAAO,GAAQ,KAAA;AACd,IAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,CAAC,CAAA,CAAA;AACpD,IAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,IAAA,MAAM,WAAc,GAAA,qBAAA,CAAsB,IAAK,CAAA,EAAA,EAAI,MAAM,KAAK,CAAA,CAAA;AAC9D,IAAM,MAAA,EAAE,YAAc,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAClC,IAAM,MAAA;AAAA,MACJ,IAAA,EAAM,EAAE,YAAA,EAAc,WAAY,EAAA;AAAA,MAClC,QAAA;AAAA,MACA,CAAA;AAAA,MACA,CAAA;AAAA,QACE,WAAY,CAAA;AAAA,MACd,QAAU,EAAA,OAAA;AAAA,MACV,SAAW,EAAA,WAAA;AAAA,MACX,UAAY,EAAA;AAAA,QACV,KAAK,EAAE,OAAA,EAAS,6BAA+B,EAAA,SAAA,EAAW,OAAO,CAAA;AAAA,QACjE,OAAO,EAAE,CAAA;AAAA,QACT,IAAK,CAAA,EAAE,OAAS,EAAA,6BAAA,EAA+B,CAAA;AAAA,QAC/C,KAAM,CAAA;AAAA,UACJ,OAAS,EA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+11,7 @@ const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new state.PluginKey(
|
|
|
11
11
|
);
|
|
12
12
|
const LIVEBLOCKS_MENTION_EXTENSION = "liveblocksMentionExt";
|
|
13
13
|
const LIVEBLOCKS_MENTION_TYPE = "liveblocksMention";
|
|
14
|
+
const LIVEBLOCKS_GROUP_MENTION_TYPE = "liveblocksGroupMention";
|
|
14
15
|
const THREADS_ACTIVE_SELECTION_PLUGIN = new state.PluginKey(
|
|
15
16
|
"lb-threads-active-selection-plugin"
|
|
16
17
|
);
|
|
@@ -28,6 +29,7 @@ var ThreadPluginActions = /* @__PURE__ */ ((ThreadPluginActions2) => {
|
|
|
28
29
|
|
|
29
30
|
exports.AI_TOOLBAR_SELECTION_PLUGIN = AI_TOOLBAR_SELECTION_PLUGIN;
|
|
30
31
|
exports.LIVEBLOCKS_COMMENT_MARK_TYPE = LIVEBLOCKS_COMMENT_MARK_TYPE;
|
|
32
|
+
exports.LIVEBLOCKS_GROUP_MENTION_TYPE = LIVEBLOCKS_GROUP_MENTION_TYPE;
|
|
31
33
|
exports.LIVEBLOCKS_MENTION_EXTENSION = LIVEBLOCKS_MENTION_EXTENSION;
|
|
32
34
|
exports.LIVEBLOCKS_MENTION_KEY = LIVEBLOCKS_MENTION_KEY;
|
|
33
35
|
exports.LIVEBLOCKS_MENTION_NOTIFIER_KEY = LIVEBLOCKS_MENTION_NOTIFIER_KEY;
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n Relax,\n TextEditorType,\n ThreadData,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n threads_experimental?: ThreadData[];\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n /**\n * @internal\n * For reporting another text editor type from a\n * text editor extended from `TipTap` such as our `BlockNote` integration.\n *\n * Only useful for Liveblocks developers, not for end users.\n */\n textEditorType?: TextEditorType;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n /**\n * Open the AI toolbar, with an optional prompt.\n */\n askAi: (prompt?: string) => ReturnType;\n\n /**\n * Close the AI toolbar.\n */\n closeAi: () => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n"],"names":["PluginKey","ThreadPluginActions"],"mappings":";;;;AAea,MAAA,sBAAA,GAAyB,IAAIA,eAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAIA,eAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAEhC,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAIA,eAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAIA,eAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AA+E1B,IAAA,mBAAA,qBAAAC,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n MentionData,\n Relax,\n TextEditorType,\n ThreadData,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\nexport const LIVEBLOCKS_GROUP_MENTION_TYPE = \"liveblocksGroupMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n threads_experimental?: ThreadData[];\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n /**\n * @internal\n * For reporting another text editor type from a\n * text editor extended from `TipTap` such as our `BlockNote` integration.\n *\n * Only useful for Liveblocks developers, not for end users.\n */\n textEditorType?: TextEditorType;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n /**\n * Open the AI toolbar, with an optional prompt.\n */\n askAi: (prompt?: string) => ReturnType;\n\n /**\n * Close the AI toolbar.\n */\n closeAi: () => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n\nexport type TiptapMentionData = MentionData & {\n notificationId: string;\n};\n\nexport type SerializedTiptapMentionData = TiptapMentionData extends infer T\n ? T extends { kind: \"group\" }\n ? Omit<T, \"userIds\"> & { userIds?: string }\n : T\n : never;\n"],"names":["PluginKey","ThreadPluginActions"],"mappings":";;;;AAgBa,MAAA,sBAAA,GAAyB,IAAIA,eAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAIA,eAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAChC,MAAM,6BAAgC,GAAA,yBAAA;AAEtC,MAAM,kCAAkC,IAAIA,eAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAIA,eAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAIA,eAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AA+E1B,IAAA,mBAAA,qBAAAC,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;;;;;;;;;;;"}
|
package/dist/types.js
CHANGED
|
@@ -9,6 +9,7 @@ const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(
|
|
|
9
9
|
);
|
|
10
10
|
const LIVEBLOCKS_MENTION_EXTENSION = "liveblocksMentionExt";
|
|
11
11
|
const LIVEBLOCKS_MENTION_TYPE = "liveblocksMention";
|
|
12
|
+
const LIVEBLOCKS_GROUP_MENTION_TYPE = "liveblocksGroupMention";
|
|
12
13
|
const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(
|
|
13
14
|
"lb-threads-active-selection-plugin"
|
|
14
15
|
);
|
|
@@ -24,5 +25,5 @@ var ThreadPluginActions = /* @__PURE__ */ ((ThreadPluginActions2) => {
|
|
|
24
25
|
return ThreadPluginActions2;
|
|
25
26
|
})(ThreadPluginActions || {});
|
|
26
27
|
|
|
27
|
-
export { AI_TOOLBAR_SELECTION_PLUGIN, LIVEBLOCKS_COMMENT_MARK_TYPE, LIVEBLOCKS_MENTION_EXTENSION, LIVEBLOCKS_MENTION_KEY, LIVEBLOCKS_MENTION_NOTIFIER_KEY, LIVEBLOCKS_MENTION_PASTE_KEY, LIVEBLOCKS_MENTION_TYPE, THREADS_ACTIVE_SELECTION_PLUGIN, THREADS_PLUGIN_KEY, ThreadPluginActions };
|
|
28
|
+
export { AI_TOOLBAR_SELECTION_PLUGIN, LIVEBLOCKS_COMMENT_MARK_TYPE, LIVEBLOCKS_GROUP_MENTION_TYPE, LIVEBLOCKS_MENTION_EXTENSION, LIVEBLOCKS_MENTION_KEY, LIVEBLOCKS_MENTION_NOTIFIER_KEY, LIVEBLOCKS_MENTION_PASTE_KEY, LIVEBLOCKS_MENTION_TYPE, THREADS_ACTIVE_SELECTION_PLUGIN, THREADS_PLUGIN_KEY, ThreadPluginActions };
|
|
28
29
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n Relax,\n TextEditorType,\n ThreadData,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n threads_experimental?: ThreadData[];\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n /**\n * @internal\n * For reporting another text editor type from a\n * text editor extended from `TipTap` such as our `BlockNote` integration.\n *\n * Only useful for Liveblocks developers, not for end users.\n */\n textEditorType?: TextEditorType;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n /**\n * Open the AI toolbar, with an optional prompt.\n */\n askAi: (prompt?: string) => ReturnType;\n\n /**\n * Close the AI toolbar.\n */\n closeAi: () => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n"],"names":["ThreadPluginActions"],"mappings":";;AAea,MAAA,sBAAA,GAAyB,IAAI,SAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAI,SAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAEhC,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAI,SAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAI,SAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AA+E1B,IAAA,mBAAA,qBAAAA,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type {\n ContextualPromptContext,\n ContextualPromptResponse,\n MentionData,\n Relax,\n TextEditorType,\n ThreadData,\n} from \"@liveblocks/core\";\nimport type { LiveblocksYjsProvider } from \"@liveblocks/yjs\";\nimport type { Content, Range } from \"@tiptap/core\";\nimport { PluginKey } from \"@tiptap/pm/state\";\nimport type { DecorationSet } from \"@tiptap/pm/view\";\nimport type { ChainedCommands, SingleCommands } from \"@tiptap/react\";\nimport type { ProsemirrorBinding } from \"y-prosemirror\";\nimport type { Doc, PermanentUserData, Snapshot } from \"yjs\";\n\nexport const LIVEBLOCKS_MENTION_KEY = new PluginKey(\"lb-plugin-mention\");\nexport const LIVEBLOCKS_MENTION_PASTE_KEY = new PluginKey(\n \"lb-plugin-mention-paste\"\n);\nexport const LIVEBLOCKS_MENTION_NOTIFIER_KEY = new PluginKey(\n \"lb-plugin-mention-notify\"\n);\n\nexport const LIVEBLOCKS_MENTION_EXTENSION = \"liveblocksMentionExt\";\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\nexport const LIVEBLOCKS_GROUP_MENTION_TYPE = \"liveblocksGroupMention\";\n\nexport const THREADS_ACTIVE_SELECTION_PLUGIN = new PluginKey(\n \"lb-threads-active-selection-plugin\"\n);\nexport const THREADS_PLUGIN_KEY = new PluginKey<ThreadPluginState>(\n \"lb-threads-plugin\"\n);\nexport const AI_TOOLBAR_SELECTION_PLUGIN = new PluginKey(\n \"lb-ai-toolbar-selection-plugin\"\n);\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptArgs = {\n /**\n * The prompt being requested by the user.\n */\n prompt: string;\n\n /**\n * The context of the document and its current selection.\n */\n context: ContextualPromptContext;\n\n /**\n * The previous request and its response, if this is a follow-up request.\n */\n previous?: {\n prompt: string;\n response: ContextualPromptResponse;\n };\n\n /**\n * An abort signal that can be used to cancel requests.\n */\n signal: AbortSignal;\n};\n\n/**\n * @beta\n */\nexport type ResolveContextualPromptResponse = ContextualPromptResponse;\n\nexport interface AiConfiguration {\n /**\n * The AI's name. (\"Ask {name} anything…\", \"{name} is thinking…\", etc)\n */\n name?: string;\n\n /**\n * A function that returns an a response to a contextual prompt.\n */\n resolveContextualPrompt?: (\n args: ResolveContextualPromptArgs\n ) => Promise<ContextualPromptResponse>;\n}\n\nexport type LiveblocksExtensionOptions = {\n field?: string;\n comments?: boolean; // | CommentsConfiguration\n mentions?: boolean; // | MentionsConfiguration\n ai?: boolean | AiConfiguration;\n offlineSupport_experimental?: boolean;\n threads_experimental?: ThreadData[];\n initialContent?: Content;\n enablePermanentUserData?: boolean;\n /**\n * @internal\n * For reporting another text editor type from a\n * text editor extended from `TipTap` such as our `BlockNote` integration.\n *\n * Only useful for Liveblocks developers, not for end users.\n */\n textEditorType?: TextEditorType;\n};\n\nexport type LiveblocksExtensionStorage = {\n unsubs: (() => void)[];\n doc: Doc;\n provider: LiveblocksYjsProvider;\n permanentUserData?: PermanentUserData;\n};\n\nexport type CommentsExtensionStorage = {\n pendingComment: boolean;\n};\n\nexport const enum ThreadPluginActions {\n SET_SELECTED_THREAD_ID = \"SET_SELECTED_THREAD_ID\",\n}\n\nexport type AiExtensionOptions = Required<\n Pick<AiConfiguration, \"name\" | \"resolveContextualPrompt\">\n> & {\n doc: Doc | undefined;\n pud: PermanentUserData | undefined;\n};\n\n/**\n * The state of the AI toolbar.\n *\n * ┌────────────────────────────────────────────────────────────────────────────────┐\n * │ │\n * │ ┌──────────────────────────────────────────────┐ │\n * ▼ ▼ │ │\n * ┌───────$closeAiToolbar()───────┐ │ │\n * ▼ ◇ ◇ ◇\n * ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────────┐\n * │ CLOSED │ │ ASKING │ │ THINKING │ │ REVIEWING │\n * └───────────────────────┘ └───────────────────────┘ └───────────────────────┘ └───────────────────────┘\n * ▲ ◇ ◇ ▲ ▲ ◇ ▲ ▲ ◇ ▲ ◇ ◇\n * │ │ └───$openAiToolbarAsking()──┘ │ │ └ ─ ─ ─ ─ ─ ─⚠─ ─ ─ ─ ─ ─ ─│─├── ─ ─ ─ ─ ─ ─✓─ ─ ─ ─ ─ ─ ─ ┘ │ │\n * │ │ │ ▼ │ │ │ │\n * │ └─────────────────$startAiToolbarThinking(prompt)──────────────┘ │ │ │\n * │ │ ▲ │ │ │\n * │ │ └──────────────────────────────┼───────────────────────────────┘ │\n * │ │ │ │\n * │ └───$cancelAiToolbarThinking()───┘ │\n * │ │\n * └─────────────────────────────────────$acceptAiToolbarResponse()─────────────────────────────────────┘\n *\n */\nexport type AiToolbarState = Relax<\n | {\n phase: \"closed\";\n }\n | {\n phase: \"asking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * A potential error that occurred during the last AI request.\n */\n error?: Error;\n }\n | {\n phase: \"thinking\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * An abort controller to cancel the AI request.\n */\n abortController: AbortController;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The previous response if this \"thinking\" phase is a refinement.\n */\n previousResponse?: ContextualPromptResponse;\n }\n | {\n phase: \"reviewing\";\n\n /**\n * The selection stored when opening the AI toolbar.\n */\n initialSelection: Range;\n\n /**\n * The custom prompt being written in the toolbar.\n */\n customPrompt: string;\n\n /**\n * The prompt sent to the AI.\n */\n prompt: string;\n\n /**\n * The response of the AI request.\n */\n response: ContextualPromptResponse;\n }\n>;\n\nexport type AiExtensionStorage = {\n name: string;\n state: AiToolbarState;\n snapshot?: Snapshot;\n};\n\nexport type ThreadPluginState = {\n threadPositions: Map<string, { from: number; to: number }>;\n selectedThreadId: string | null;\n selectedThreadPos: number | null;\n decorations: DecorationSet;\n};\n\nexport type FloatingPosition = \"top\" | \"bottom\";\n\nexport type ExtendedCommands<\n T extends string,\n A extends any[] = [],\n> = SingleCommands & Record<T, (...args: A) => boolean>;\n\nexport type ExtendedChainedCommands<\n T extends string,\n A extends any[] = [],\n> = ChainedCommands & Record<T, (...args: A) => ChainedCommands>;\n\nexport type ChainedAiCommands = ChainedCommands & {\n [K in keyof AiCommands]: (\n ...args: Parameters<AiCommands[K]>\n ) => ChainedCommands;\n};\n\nexport type CommentsCommands<ReturnType = boolean> = {\n /**\n * Add a comment\n */\n addComment: (id: string) => ReturnType;\n selectThread: (id: string | null) => ReturnType;\n addPendingComment: () => ReturnType;\n\n /** @internal */\n closePendingComment: () => ReturnType;\n};\n\nexport type AiCommands<ReturnType = boolean> = {\n /**\n * Open the AI toolbar, with an optional prompt.\n */\n askAi: (prompt?: string) => ReturnType;\n\n /**\n * Close the AI toolbar.\n */\n closeAi: () => ReturnType;\n\n // Transitions (see AiToolbarState)\n\n /**\n * @internal\n * @transition\n *\n * Close the AI toolbar.\n */\n $closeAiToolbar: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Accept the current AI response and close the AI toolbar.\n */\n $acceptAiToolbarResponse: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Open the AI toolbar in the \"asking\" phase.\n */\n $openAiToolbarAsking: () => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Set (and open if not already open) the AI toolbar in the \"thinking\" phase with the given prompt.\n */\n $startAiToolbarThinking: (\n prompt: string,\n withPreviousResponse?: boolean\n ) => ReturnType;\n\n /**\n * @internal\n * @transition\n *\n * Cancel the current \"thinking\" phase, going back to the \"asking\" phase.\n */\n $cancelAiToolbarThinking: () => ReturnType;\n\n // Other\n\n /**\n * @internal\n *\n * Show the diff of the current \"reviewing\" phase.\n */\n _showAiToolbarReviewingDiff: () => ReturnType;\n\n /**\n * @internal\n *\n * Handle the success of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingSuccess: (\n response: ContextualPromptResponse\n ) => ReturnType;\n\n /**\n * @internal\n *\n * Handle an error of the current \"thinking\" phase.\n */\n _handleAiToolbarThinkingError: (error: unknown) => ReturnType;\n\n /**\n * @internal\n *\n * Update the current custom AI prompt.\n */\n _updateAiToolbarCustomPrompt: (\n customPrompt: string | ((currentCustomPrompt: string) => string)\n ) => ReturnType;\n};\n\nexport type YSyncPluginState = {\n binding: ProsemirrorBinding;\n};\n\nexport type TiptapMentionData = MentionData & {\n notificationId: string;\n};\n\nexport type SerializedTiptapMentionData = TiptapMentionData extends infer T\n ? T extends { kind: \"group\" }\n ? Omit<T, \"userIds\"> & { userIds?: string }\n : T\n : never;\n"],"names":["ThreadPluginActions"],"mappings":";;AAgBa,MAAA,sBAAA,GAAyB,IAAI,SAAA,CAAU,mBAAmB,EAAA;AAChE,MAAM,+BAA+B,IAAI,SAAA;AAAA,EAC9C,yBAAA;AACF,EAAA;AACO,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,0BAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,uBAAA;AACrC,MAAM,uBAA0B,GAAA,oBAAA;AAChC,MAAM,6BAAgC,GAAA,yBAAA;AAEtC,MAAM,kCAAkC,IAAI,SAAA;AAAA,EACjD,oCAAA;AACF,EAAA;AACO,MAAM,qBAAqB,IAAI,SAAA;AAAA,EACpC,mBAAA;AACF,EAAA;AACO,MAAM,8BAA8B,IAAI,SAAA;AAAA,EAC7C,gCAAA;AACF,EAAA;AAEO,MAAM,4BAA+B,GAAA,wBAAA;AA+E1B,IAAA,mBAAA,qBAAAA,oBAAX,KAAA;AACL,EAAAA,qBAAA,wBAAyB,CAAA,GAAA,wBAAA,CAAA;AADT,EAAAA,OAAAA,oBAAAA,CAAAA;AAAA,CAAA,EAAA,mBAAA,IAAA,EAAA;;;;"}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var core = require('@liveblocks/core');
|
|
3
4
|
var model = require('@tiptap/pm/model');
|
|
4
5
|
var state = require('@tiptap/pm/state');
|
|
5
6
|
var yProsemirror = require('y-prosemirror');
|
|
@@ -34,19 +35,42 @@ const getRectFromCoords = (coords) => {
|
|
|
34
35
|
};
|
|
35
36
|
};
|
|
36
37
|
const getMentionsFromNode = (node, range) => {
|
|
37
|
-
const
|
|
38
|
+
const mentions = /* @__PURE__ */ new Map();
|
|
38
39
|
node.nodesBetween(range.from, range.to, (child) => {
|
|
39
|
-
if (child.type.name === types.LIVEBLOCKS_MENTION_TYPE) {
|
|
40
|
+
if (child.type.name === types.LIVEBLOCKS_MENTION_TYPE || child.type.name === types.LIVEBLOCKS_GROUP_MENTION_TYPE) {
|
|
40
41
|
const mention = child.attrs;
|
|
41
42
|
if (mention.id && mention.notificationId) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (child.type.name === types.LIVEBLOCKS_MENTION_TYPE) {
|
|
44
|
+
mentions.set(mention.notificationId, {
|
|
45
|
+
kind: "user",
|
|
46
|
+
id: mention.id,
|
|
47
|
+
notificationId: mention.notificationId
|
|
48
|
+
});
|
|
49
|
+
} else if (child.type.name === types.LIVEBLOCKS_GROUP_MENTION_TYPE) {
|
|
50
|
+
let userIds;
|
|
51
|
+
if (mention.userIds) {
|
|
52
|
+
try {
|
|
53
|
+
const parsedUserIds = JSON.parse(mention.userIds);
|
|
54
|
+
if (Array.isArray(parsedUserIds)) {
|
|
55
|
+
userIds = parsedUserIds;
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
userIds = void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
mentions.set(mention.notificationId, {
|
|
62
|
+
kind: "group",
|
|
63
|
+
id: mention.id,
|
|
64
|
+
userIds,
|
|
65
|
+
notificationId: mention.notificationId
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
core.assertNever(child.type.name, "Unexpected mention kind");
|
|
69
|
+
}
|
|
46
70
|
}
|
|
47
71
|
}
|
|
48
72
|
});
|
|
49
|
-
return
|
|
73
|
+
return mentions;
|
|
50
74
|
};
|
|
51
75
|
const mapFragment = (fragment, callback) => {
|
|
52
76
|
const content = [];
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import type { ClientRectObject } from \"@floating-ui/react-dom\";\nimport type { ContextualPromptContext } from \"@liveblocks/core\";\nimport type { Editor, Range } from \"@tiptap/core\";\nimport type { Node as ProseMirrorNode } from \"@tiptap/pm/model\";\nimport { Fragment } from \"@tiptap/pm/model\";\nimport {\n type EditorState,\n type Selection,\n TextSelection,\n} from \"@tiptap/pm/state\";\nimport {\n getRelativeSelection,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from \"y-prosemirror\";\nimport type { RelativePosition } from \"yjs\";\n\nimport type { YSyncPluginState } from \"./types\";\nimport { LIVEBLOCKS_MENTION_TYPE } from \"./types\";\n\nconst CONTEXT_TRUNCATION = \"[…]\";\nconst CONTEXT_BLOCK_SEPARATOR = \"\\n\";\n\nexport const getRelativeSelectionFromState = (state: EditorState) => {\n const pluginState = ySyncPluginKey.getState(state) as YSyncPluginState;\n if (!pluginState) return null;\n return getRelativeSelection(pluginState.binding, state);\n};\n\nexport const getRangeFromRelativeSelections = (\n pos: { anchor: RelativePosition; head: RelativePosition },\n state: EditorState\n) => {\n const pluginState = ySyncPluginKey.getState(state) as YSyncPluginState;\n if (!pluginState || !pluginState.binding) return { from: 0, to: 0 };\n const { doc, type, mapping } = pluginState.binding;\n const anchor =\n relativePositionToAbsolutePosition(doc, type, pos.anchor, mapping) ?? 0;\n const head =\n relativePositionToAbsolutePosition(doc, type, pos.head, mapping) ?? 0;\n\n const from = anchor > head ? head : anchor;\n const to = anchor > head ? anchor : head;\n return { from, to };\n};\n\nexport const getRectFromCoords = (coords: {\n top: number;\n left: number;\n right: number;\n bottom: number;\n}): ClientRectObject => {\n return {\n ...coords,\n x: coords.left,\n y: coords.top,\n width: coords.right - coords.left,\n height: coords.bottom - coords.top,\n };\n};\n\nexport const getMentionsFromNode = (\n node: ProseMirrorNode,\n range: Range\n): { notificationId: string; userId: string }[] => {\n const result: { notificationId: string; userId: string }[] = [];\n node.nodesBetween(range.from, range.to, (child) => {\n if (child.type.name === LIVEBLOCKS_MENTION_TYPE) {\n const mention = child.attrs as { id?: string; notificationId?: string };\n if (mention.id && mention.notificationId) {\n result.push({\n notificationId: mention.notificationId,\n userId: mention.id,\n });\n }\n }\n });\n return result;\n};\n\n// How to modify data in transformPasted, inspired by: https://discuss.prosemirror.net/t/modify-specific-node-on-copy-and-paste-in-clipboard/4901/4\nexport const mapFragment = (\n fragment: Fragment,\n callback: (\n node: ProseMirrorNode\n ) => ProseMirrorNode | ProseMirrorNode[] | Fragment | null\n): Fragment => {\n const content: ProseMirrorNode[] = [];\n fragment.forEach((node) => {\n if (node.content.childCount > 0) {\n content.push(\n node.type.create(node.attrs, mapFragment(node.content, callback))\n );\n return;\n }\n content.push(callback(node) as ProseMirrorNode);\n });\n\n return Fragment.from(content);\n};\n\nexport function getDomRangeFromSelection(editor: Editor, selection: Selection) {\n if (selection.from === selection.to) {\n const { parent, parentOffset } = selection.$from;\n\n // If the selection is collapsed and in an empty block node or at the end\n // of a text node, extend it to the entire node\n if (\n (parent.isBlock && parent.content.size === 0) ||\n (parent.isTextblock && parentOffset === parent.content.size)\n ) {\n selection = TextSelection.create(\n editor.state.doc,\n selection.$from.before(),\n selection.$from.after()\n );\n }\n }\n\n const from = editor.view.domAtPos(selection.from);\n const to = editor.view.domAtPos(selection.to);\n\n const domRange = document.createRange();\n domRange.setStart(from.node, from.offset);\n domRange.setEnd(to.node, to.offset);\n\n return domRange;\n}\n\nexport function compareSelections(\n a: Selection | null | undefined,\n b: Selection | null | undefined\n) {\n if (!a || !b) {\n return false;\n }\n\n return a.eq(b);\n}\n\nexport function getContextualPromptContext(\n editor: Editor,\n maxLength = 10_000\n): ContextualPromptContext {\n const { selection, doc } = editor.state;\n\n const selectionLength = selection.to - selection.from;\n\n if (maxLength >= doc.content.size) {\n // If the document is smaller than the maximum length, return the entire document\n return {\n beforeSelection: doc.textBetween(\n 0,\n selection.from,\n CONTEXT_BLOCK_SEPARATOR\n ),\n selection: doc.textBetween(\n selection.from,\n selection.to,\n CONTEXT_BLOCK_SEPARATOR\n ),\n afterSelection: doc.textBetween(\n selection.to,\n doc.content.size,\n CONTEXT_BLOCK_SEPARATOR\n ),\n };\n } else if (selectionLength > maxLength) {\n // If the selection is too large, truncate its middle to still allow continuations\n const selectionStart = doc.textBetween(\n selection.from,\n selection.from + Math.floor(maxLength / 2) - CONTEXT_TRUNCATION.length,\n CONTEXT_BLOCK_SEPARATOR\n );\n const selectionEnd = doc.textBetween(\n selection.to - Math.floor(maxLength / 2) + CONTEXT_TRUNCATION.length,\n selection.to,\n CONTEXT_BLOCK_SEPARATOR\n );\n\n return {\n beforeSelection: \"\",\n selection: `${selectionStart}${CONTEXT_TRUNCATION}${selectionEnd}`,\n afterSelection: \"\",\n };\n } else {\n // If the selection is smaller than (or equal to) the maximum length, extract as much as possible from the document around the selection\n\n // Start by taking as much as possible after the selection\n let beforeLength = Math.min(\n selection.from,\n Math.floor((maxLength - selectionLength) / 2)\n );\n const afterLength = Math.min(\n doc.content.size - selection.to,\n maxLength - selectionLength - beforeLength\n );\n\n // If needed (e.g. the selection is near the end), compensate before the selection\n if (beforeLength + afterLength + selectionLength < maxLength) {\n beforeLength = Math.min(\n selection.from,\n maxLength - selectionLength - afterLength\n );\n }\n\n let beforeSelection = doc.textBetween(\n Math.max(0, selection.from - beforeLength),\n selection.from,\n CONTEXT_BLOCK_SEPARATOR\n );\n let afterSelection = doc.textBetween(\n selection.to,\n Math.min(doc.content.size, selection.to + afterLength),\n CONTEXT_BLOCK_SEPARATOR\n );\n\n // Add leading truncation if `beforeSelection` doesn't contain the document's start\n if (selection.from - beforeLength > 0) {\n beforeSelection = `${CONTEXT_TRUNCATION}${beforeSelection}`;\n }\n\n // Add trailing truncation if `afterSelection` doesn't contain the document's end\n if (selection.to + afterLength < doc.content.size) {\n afterSelection = `${afterSelection}${CONTEXT_TRUNCATION}`;\n }\n\n return {\n beforeSelection,\n selection: doc.textBetween(\n selection.from,\n selection.to,\n CONTEXT_BLOCK_SEPARATOR\n ),\n afterSelection,\n };\n }\n}\n"],"names":["ySyncPluginKey","getRelativeSelection","relativePositionToAbsolutePosition","LIVEBLOCKS_MENTION_TYPE","Fragment","TextSelection"],"mappings":";;;;;;;AAoBA,MAAM,kBAAqB,GAAA,UAAA,CAAA;AAC3B,MAAM,uBAA0B,GAAA,IAAA,CAAA;AAEnB,MAAA,6BAAA,GAAgC,CAAC,KAAuB,KAAA;AACnE,EAAM,MAAA,WAAA,GAAcA,2BAAe,CAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AACjD,EAAA,IAAI,CAAC,WAAA;AAAa,IAAO,OAAA,IAAA,CAAA;AACzB,EAAO,OAAAC,iCAAA,CAAqB,WAAY,CAAA,OAAA,EAAS,KAAK,CAAA,CAAA;AACxD,EAAA;AAEa,MAAA,8BAAA,GAAiC,CAC5C,GAAA,EACA,KACG,KAAA;AACH,EAAM,MAAA,WAAA,GAAcD,2BAAe,CAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AACjD,EAAI,IAAA,CAAC,WAAe,IAAA,CAAC,WAAY,CAAA,OAAA;AAAS,IAAA,OAAO,EAAE,IAAA,EAAM,CAAG,EAAA,EAAA,EAAI,CAAE,EAAA,CAAA;AAClE,EAAA,MAAM,EAAE,GAAA,EAAK,IAAM,EAAA,OAAA,KAAY,WA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AA,YAAA,GAAe,IAAK,CAAA,GAAA;AAAA,QAClB,SAAU,CAAA,IAAA;AAAA,QACV,YAAY,eAAkB,GAAA,WAAA;AAAA,OAChC,CAAA;AAAA,KACF;AAEA,IAAA,IAAI,kBAAkB,GAAI,CAAA,WAAA;AAAA,MACxB,IAAK,CAAA,GAAA,CAAI,CAAG,EAAA,SAAA,CAAU,OAAO,YAAY,CAAA;AAAA,MACzC,SAAU,CAAA,IAAA;AAAA,MACV,uBAAA;AAAA,KACF,CAAA;AACA,IAAA,IAAI,iBAAiB,GAAI,CAAA,WAAA;AAAA,MACvB,SAAU,CAAA,EAAA;AAAA,MACV,KAAK,GAAI,CAAA,GAAA,CAAI,QAAQ,IAAM,EAAA,SAAA,CAAU,KAAK,WAAW,CAAA;AAAA,MACrD,uBAAA;AAAA,KACF,CAAA;AAGA,IAAI,IAAA,SAAA,CAAU,IAAO,GAAA,YAAA,GAAe,CAAG,EAAA;AACrC,MAAA,eAAA,GAAkB,GAAG,kBAAqB,CAAA,EAAA,eAAA,CAAA,CAAA,CAAA;AAAA,KAC5C;AAGA,IAAA,IAAI,SAAU,CAAA,EAAA,GAAK,WAAc,GAAA,GAAA,CAAI,QAAQ,IAAM,EAAA;AACjD,MAAA,cAAA,GAAiB,GAAG,cAAiB,CAAA,EAAA,kBAAA,CAAA,CAAA,CAAA;AAAA,KACvC;AAEA,IAAO,OAAA;AAAA,MACL,eAAA;AAAA,MACA,WAAW,GAAI,CAAA,WAAA;AAAA,QACb,SAAU,CAAA,IAAA;AAAA,QACV,SAAU,CAAA,EAAA;AAAA,QACV,uBAAA;AAAA,OACF;AAAA,MACA,cAAA;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../src/utils.ts"],"sourcesContent":["import type { ClientRectObject } from \"@floating-ui/react-dom\";\nimport { assertNever, type ContextualPromptContext } from \"@liveblocks/core\";\nimport type { Editor, Range } from \"@tiptap/core\";\nimport type { Node as ProseMirrorNode } from \"@tiptap/pm/model\";\nimport { Fragment } from \"@tiptap/pm/model\";\nimport {\n type EditorState,\n type Selection,\n TextSelection,\n} from \"@tiptap/pm/state\";\nimport {\n getRelativeSelection,\n relativePositionToAbsolutePosition,\n ySyncPluginKey,\n} from \"y-prosemirror\";\nimport type { RelativePosition } from \"yjs\";\n\nimport type {\n SerializedTiptapMentionData,\n TiptapMentionData,\n YSyncPluginState,\n} from \"./types\";\nimport {\n LIVEBLOCKS_GROUP_MENTION_TYPE,\n LIVEBLOCKS_MENTION_TYPE,\n} from \"./types\";\n\nconst CONTEXT_TRUNCATION = \"[…]\";\nconst CONTEXT_BLOCK_SEPARATOR = \"\\n\";\n\nexport const getRelativeSelectionFromState = (state: EditorState) => {\n const pluginState = ySyncPluginKey.getState(state) as YSyncPluginState;\n if (!pluginState) return null;\n return getRelativeSelection(pluginState.binding, state);\n};\n\nexport const getRangeFromRelativeSelections = (\n pos: { anchor: RelativePosition; head: RelativePosition },\n state: EditorState\n) => {\n const pluginState = ySyncPluginKey.getState(state) as YSyncPluginState;\n if (!pluginState || !pluginState.binding) return { from: 0, to: 0 };\n const { doc, type, mapping } = pluginState.binding;\n const anchor =\n relativePositionToAbsolutePosition(doc, type, pos.anchor, mapping) ?? 0;\n const head =\n relativePositionToAbsolutePosition(doc, type, pos.head, mapping) ?? 0;\n\n const from = anchor > head ? head : anchor;\n const to = anchor > head ? anchor : head;\n return { from, to };\n};\n\nexport const getRectFromCoords = (coords: {\n top: number;\n left: number;\n right: number;\n bottom: number;\n}): ClientRectObject => {\n return {\n ...coords,\n x: coords.left,\n y: coords.top,\n width: coords.right - coords.left,\n height: coords.bottom - coords.top,\n };\n};\n\nexport const getMentionsFromNode = (\n node: ProseMirrorNode,\n range: Range\n): Map<string, TiptapMentionData> => {\n const mentions = new Map<string, TiptapMentionData>();\n\n node.nodesBetween(range.from, range.to, (child) => {\n if (\n child.type.name === LIVEBLOCKS_MENTION_TYPE ||\n child.type.name === LIVEBLOCKS_GROUP_MENTION_TYPE\n ) {\n const mention = child.attrs as Omit<SerializedTiptapMentionData, \"kind\">;\n\n if (mention.id && mention.notificationId) {\n if (child.type.name === LIVEBLOCKS_MENTION_TYPE) {\n mentions.set(mention.notificationId, {\n kind: \"user\",\n id: mention.id,\n notificationId: mention.notificationId,\n });\n } else if (child.type.name === LIVEBLOCKS_GROUP_MENTION_TYPE) {\n let userIds: string[] | undefined;\n\n if (mention.userIds) {\n try {\n const parsedUserIds = JSON.parse(mention.userIds) as string[];\n\n if (Array.isArray(parsedUserIds)) {\n userIds = parsedUserIds;\n }\n } catch {\n userIds = undefined;\n }\n }\n\n mentions.set(mention.notificationId, {\n kind: \"group\",\n id: mention.id,\n userIds,\n notificationId: mention.notificationId,\n });\n } else {\n assertNever(child.type.name, \"Unexpected mention kind\");\n }\n }\n }\n });\n\n return mentions;\n};\n\n// How to modify data in transformPasted, inspired by: https://discuss.prosemirror.net/t/modify-specific-node-on-copy-and-paste-in-clipboard/4901/4\nexport const mapFragment = (\n fragment: Fragment,\n callback: (\n node: ProseMirrorNode\n ) => ProseMirrorNode | ProseMirrorNode[] | Fragment | null\n): Fragment => {\n const content: ProseMirrorNode[] = [];\n fragment.forEach((node) => {\n if (node.content.childCount > 0) {\n content.push(\n node.type.create(node.attrs, mapFragment(node.content, callback))\n );\n return;\n }\n content.push(callback(node) as ProseMirrorNode);\n });\n\n return Fragment.from(content);\n};\n\nexport function getDomRangeFromSelection(editor: Editor, selection: Selection) {\n if (selection.from === selection.to) {\n const { parent, parentOffset } = selection.$from;\n\n // If the selection is collapsed and in an empty block node or at the end\n // of a text node, extend it to the entire node\n if (\n (parent.isBlock && parent.content.size === 0) ||\n (parent.isTextblock && parentOffset === parent.content.size)\n ) {\n selection = TextSelection.create(\n editor.state.doc,\n selection.$from.before(),\n selection.$from.after()\n );\n }\n }\n\n const from = editor.view.domAtPos(selection.from);\n const to = editor.view.domAtPos(selection.to);\n\n const domRange = document.createRange();\n domRange.setStart(from.node, from.offset);\n domRange.setEnd(to.node, to.offset);\n\n return domRange;\n}\n\nexport function compareSelections(\n a: Selection | null | undefined,\n b: Selection | null | undefined\n) {\n if (!a || !b) {\n return false;\n }\n\n return a.eq(b);\n}\n\nexport function getContextualPromptContext(\n editor: Editor,\n maxLength = 10_000\n): ContextualPromptContext {\n const { selection, doc } = editor.state;\n\n const selectionLength = selection.to - selection.from;\n\n if (maxLength >= doc.content.size) {\n // If the document is smaller than the maximum length, return the entire document\n return {\n beforeSelection: doc.textBetween(\n 0,\n selection.from,\n CONTEXT_BLOCK_SEPARATOR\n ),\n selection: doc.textBetween(\n selection.from,\n selection.to,\n CONTEXT_BLOCK_SEPARATOR\n ),\n afterSelection: doc.textBetween(\n selection.to,\n doc.content.size,\n CONTEXT_BLOCK_SEPARATOR\n ),\n };\n } else if (selectionLength > maxLength) {\n // If the selection is too large, truncate its middle to still allow continuations\n const selectionStart = doc.textBetween(\n selection.from,\n selection.from + Math.floor(maxLength / 2) - CONTEXT_TRUNCATION.length,\n CONTEXT_BLOCK_SEPARATOR\n );\n const selectionEnd = doc.textBetween(\n selection.to - Math.floor(maxLength / 2) + CONTEXT_TRUNCATION.length,\n selection.to,\n CONTEXT_BLOCK_SEPARATOR\n );\n\n return {\n beforeSelection: \"\",\n selection: `${selectionStart}${CONTEXT_TRUNCATION}${selectionEnd}`,\n afterSelection: \"\",\n };\n } else {\n // If the selection is smaller than (or equal to) the maximum length, extract as much as possible from the document around the selection\n\n // Start by taking as much as possible after the selection\n let beforeLength = Math.min(\n selection.from,\n Math.floor((maxLength - selectionLength) / 2)\n );\n const afterLength = Math.min(\n doc.content.size - selection.to,\n maxLength - selectionLength - beforeLength\n );\n\n // If needed (e.g. the selection is near the end), compensate before the selection\n if (beforeLength + afterLength + selectionLength < maxLength) {\n beforeLength = Math.min(\n selection.from,\n maxLength - selectionLength - afterLength\n );\n }\n\n let beforeSelection = doc.textBetween(\n Math.max(0, selection.from - beforeLength),\n selection.from,\n CONTEXT_BLOCK_SEPARATOR\n );\n let afterSelection = doc.textBetween(\n selection.to,\n Math.min(doc.content.size, selection.to + afterLength),\n CONTEXT_BLOCK_SEPARATOR\n );\n\n // Add leading truncation if `beforeSelection` doesn't contain the document's start\n if (selection.from - beforeLength > 0) {\n beforeSelection = `${CONTEXT_TRUNCATION}${beforeSelection}`;\n }\n\n // Add trailing truncation if `afterSelection` doesn't contain the document's end\n if (selection.to + afterLength < doc.content.size) {\n afterSelection = `${afterSelection}${CONTEXT_TRUNCATION}`;\n }\n\n return {\n beforeSelection,\n selection: doc.textBetween(\n selection.from,\n selection.to,\n CONTEXT_BLOCK_SEPARATOR\n ),\n afterSelection,\n };\n }\n}\n"],"names":["ySyncPluginKey","getRelativeSelection","relativePositionToAbsolutePosition","LIVEBLOCKS_MENTION_TYPE","LIVEBLOCKS_GROUP_MENTION_TYPE","assertNever","Fragment","TextSelection"],"mappings":";;;;;;;;AA2BA,MAAM,kBAAqB,GAAA,UAAA,CAAA;AAC3B,MAAM,uBAA0B,GAAA,IAAA,CAAA;AAEnB,MAAA,6BAAA,GAAgC,CAAC,KAAuB,KAAA;AACnE,EAAM,MAAA,WAAA,GAAcA,2BAAe,CAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AACjD,EAAA,IAAI,CAAC,WAAA;AAAa,IAAO,OAAA,IAAA,CAAA;AACzB,EAAO,OAAAC,iCAAA,CAAqB,WAAY,CAAA,OAAA,EAAS,KAAK,CAAA,CAAA;AACxD,EAAA;AAEa,MAAA,8BAAA,GAAiC,CAC5C,GAAA,EACA,KACG,KAAA;AACH,EAAM,MAAA,WAAA,GAAcD,2BAAe,CAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AACjD,EAAI,IAAA,CAAC,WAAe,IAAA,CAAC,WAAY,CAAA,OAAA;AAAS,IAAA,OAAO,EAAE,IAAA,EAAM,CAAG,EAAA,EAAA,EAAI,CAAE,EAAA,CAAA;AAClE,EAAA,MAAM,EAAE,GAAA,EAAK,IAAM,EAA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