@liveblocks/react-ui 2.25.0-aiprivatebeta5 → 2.25.0-aiprivatebeta7
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/_private/index.cjs +4 -0
- package/dist/_private/index.cjs.map +1 -1
- package/dist/_private/index.d.cts +31 -94
- package/dist/_private/index.d.ts +31 -94
- package/dist/_private/index.js +2 -0
- package/dist/_private/index.js.map +1 -1
- package/dist/components/AiChat.cjs +217 -0
- package/dist/components/AiChat.cjs.map +1 -0
- package/dist/components/AiChat.js +215 -0
- package/dist/components/AiChat.js.map +1 -0
- package/dist/components/Comment.cjs +2 -2
- package/dist/components/Comment.cjs.map +1 -1
- package/dist/components/Comment.js +1 -1
- package/dist/components/Comment.js.map +1 -1
- package/dist/components/Composer.cjs +1 -2
- package/dist/components/Composer.cjs.map +1 -1
- package/dist/components/Composer.js +1 -2
- package/dist/components/Composer.js.map +1 -1
- package/dist/components/internal/AiChatAssistantMessage.cjs +83 -124
- package/dist/components/internal/AiChatAssistantMessage.cjs.map +1 -1
- package/dist/components/internal/AiChatAssistantMessage.js +81 -122
- package/dist/components/internal/AiChatAssistantMessage.js.map +1 -1
- package/dist/components/internal/AiChatComposer.cjs +30 -266
- package/dist/components/internal/AiChatComposer.cjs.map +1 -1
- package/dist/components/internal/AiChatComposer.js +35 -267
- package/dist/components/internal/AiChatComposer.js.map +1 -1
- package/dist/components/internal/AiChatUserMessage.cjs +18 -168
- package/dist/components/internal/AiChatUserMessage.cjs.map +1 -1
- package/dist/components/internal/AiChatUserMessage.js +20 -170
- package/dist/components/internal/AiChatUserMessage.js.map +1 -1
- package/dist/constants.cjs +2 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/icon.cjs +4 -0
- package/dist/icon.cjs.map +1 -1
- package/dist/icon.js +2 -0
- package/dist/icon.js.map +1 -1
- package/dist/icons/Copy.cjs +8 -9
- package/dist/icons/Copy.cjs.map +1 -1
- package/dist/icons/Copy.js +8 -9
- package/dist/icons/Copy.js.map +1 -1
- package/dist/icons/Retry.cjs +21 -0
- package/dist/icons/Retry.cjs.map +1 -0
- package/dist/icons/Retry.js +19 -0
- package/dist/icons/Retry.js.map +1 -0
- package/dist/icons/index.cjs +4 -0
- package/dist/icons/index.cjs.map +1 -1
- package/dist/icons/index.js +2 -0
- package/dist/icons/index.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -43
- package/dist/index.d.ts +32 -43
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/overrides.cjs +10 -10
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.js +10 -10
- package/dist/overrides.js.map +1 -1
- package/dist/primitives/AiChatComposer/index.cjs +203 -0
- package/dist/primitives/AiChatComposer/index.cjs.map +1 -0
- package/dist/primitives/AiChatComposer/index.js +196 -0
- package/dist/primitives/AiChatComposer/index.js.map +1 -0
- package/dist/primitives/Comment/index.cjs +2 -2
- package/dist/primitives/Comment/index.cjs.map +1 -1
- package/dist/primitives/Comment/index.js +1 -1
- package/dist/primitives/Comment/index.js.map +1 -1
- package/dist/primitives/Composer/index.cjs +19 -14
- package/dist/primitives/Composer/index.cjs.map +1 -1
- package/dist/primitives/Composer/index.js +18 -13
- package/dist/primitives/Composer/index.js.map +1 -1
- package/dist/{slate → primitives/Composer/slate}/plugins/auto-formatting.cjs +3 -3
- package/dist/primitives/Composer/slate/plugins/auto-formatting.cjs.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/auto-formatting.js +3 -3
- package/dist/primitives/Composer/slate/plugins/auto-formatting.js.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/auto-links.cjs +7 -2
- package/dist/primitives/Composer/slate/plugins/auto-links.cjs.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/auto-links.js +8 -3
- package/dist/primitives/Composer/slate/plugins/auto-links.js.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/custom-links.cjs +8 -3
- package/dist/primitives/Composer/slate/plugins/custom-links.cjs.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/custom-links.js +9 -4
- package/dist/primitives/Composer/slate/plugins/custom-links.js.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/mentions.cjs +9 -10
- package/dist/primitives/Composer/slate/plugins/mentions.cjs.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/mentions.js +6 -6
- package/dist/primitives/Composer/slate/plugins/mentions.js.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/paste.cjs +1 -1
- package/dist/primitives/Composer/slate/plugins/paste.cjs.map +1 -0
- package/dist/{slate → primitives/Composer/slate}/plugins/paste.js +1 -1
- package/dist/primitives/Composer/slate/plugins/paste.js.map +1 -0
- package/dist/primitives/Composer/utils.cjs +4 -4
- package/dist/primitives/Composer/utils.cjs.map +1 -1
- package/dist/primitives/Composer/utils.js +4 -4
- package/dist/primitives/Composer/utils.js.map +1 -1
- package/dist/primitives/index.cjs +2 -5
- package/dist/primitives/index.cjs.map +1 -1
- package/dist/primitives/index.d.cts +33 -62
- package/dist/primitives/index.d.ts +33 -62
- package/dist/primitives/index.js +6 -5
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/internal/{Collapsible.cjs → Collapsible/index.cjs} +23 -17
- package/dist/primitives/internal/Collapsible/index.cjs.map +1 -0
- package/dist/primitives/internal/{Collapsible.js → Collapsible/index.js} +23 -17
- package/dist/primitives/internal/Collapsible/index.js.map +1 -0
- package/dist/primitives/slate/plugins/empty-clear-formatting.cjs.map +1 -0
- package/dist/primitives/slate/plugins/empty-clear-formatting.js.map +1 -0
- package/dist/{slate → primitives/slate}/plugins/normalize.cjs +0 -5
- package/dist/primitives/slate/plugins/normalize.cjs.map +1 -0
- package/dist/{slate → primitives/slate}/plugins/normalize.js +0 -5
- package/dist/primitives/slate/plugins/normalize.js.map +1 -0
- package/dist/primitives/slate/utils/get-character.cjs.map +1 -0
- package/dist/primitives/slate/utils/get-character.js.map +1 -0
- package/dist/primitives/slate/utils/get-dom-range.cjs.map +1 -0
- package/dist/primitives/slate/utils/get-dom-range.js.map +1 -0
- package/dist/primitives/slate/utils/get-match-range.cjs.map +1 -0
- package/dist/primitives/slate/utils/get-match-range.js.map +1 -0
- package/dist/primitives/slate/utils/is-empty-string.cjs.map +1 -0
- package/dist/primitives/slate/utils/is-empty-string.js.map +1 -0
- package/dist/primitives/slate/utils/is-empty.cjs.map +1 -0
- package/dist/primitives/slate/utils/is-empty.js.map +1 -0
- package/dist/primitives/slate/utils/is-text.cjs.map +1 -0
- package/dist/primitives/slate/utils/is-text.js.map +1 -0
- package/dist/primitives/slate/utils/is-whitespace-character.cjs.map +1 -0
- package/dist/primitives/slate/utils/is-whitespace-character.js.map +1 -0
- package/dist/{slate → primitives/slate}/utils/marks.cjs +9 -9
- package/dist/primitives/slate/utils/marks.cjs.map +1 -0
- package/dist/{slate → primitives/slate}/utils/marks.js +9 -9
- package/dist/primitives/slate/utils/marks.js.map +1 -0
- package/dist/primitives/slate/utils/selection-contains-inlines.cjs.map +1 -0
- package/dist/primitives/slate/utils/selection-contains-inlines.js.map +1 -0
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/src/styles/index.css +119 -133
- package/src/styles/utils.css +7 -2
- package/styles.css +1 -1
- package/styles.css.map +1 -1
- package/dist/components/AiChat/AiChat.cjs +0 -211
- package/dist/components/AiChat/AiChat.cjs.map +0 -1
- package/dist/components/AiChat/AiChat.js +0 -209
- package/dist/components/AiChat/AiChat.js.map +0 -1
- package/dist/primitives/Chat/Composer/index.cjs +0 -323
- package/dist/primitives/Chat/Composer/index.cjs.map +0 -1
- package/dist/primitives/Chat/Composer/index.js +0 -315
- package/dist/primitives/Chat/Composer/index.js.map +0 -1
- package/dist/primitives/internal/Collapsible.cjs.map +0 -1
- package/dist/primitives/internal/Collapsible.js.map +0 -1
- package/dist/slate/plugins/auto-formatting.cjs.map +0 -1
- package/dist/slate/plugins/auto-formatting.js.map +0 -1
- package/dist/slate/plugins/auto-links.cjs.map +0 -1
- package/dist/slate/plugins/auto-links.js.map +0 -1
- package/dist/slate/plugins/custom-links.cjs.map +0 -1
- package/dist/slate/plugins/custom-links.js.map +0 -1
- package/dist/slate/plugins/empty-clear-formatting.cjs.map +0 -1
- package/dist/slate/plugins/empty-clear-formatting.js.map +0 -1
- package/dist/slate/plugins/mentions.cjs.map +0 -1
- package/dist/slate/plugins/mentions.js.map +0 -1
- package/dist/slate/plugins/normalize.cjs.map +0 -1
- package/dist/slate/plugins/normalize.js.map +0 -1
- package/dist/slate/plugins/paste.cjs.map +0 -1
- package/dist/slate/plugins/paste.js.map +0 -1
- package/dist/slate/utils/get-character.cjs.map +0 -1
- package/dist/slate/utils/get-character.js.map +0 -1
- package/dist/slate/utils/get-dom-range.cjs.map +0 -1
- package/dist/slate/utils/get-dom-range.js.map +0 -1
- package/dist/slate/utils/get-match-range.cjs.map +0 -1
- package/dist/slate/utils/get-match-range.js.map +0 -1
- package/dist/slate/utils/is-empty-string.cjs.map +0 -1
- package/dist/slate/utils/is-empty-string.js.map +0 -1
- package/dist/slate/utils/is-empty.cjs.map +0 -1
- package/dist/slate/utils/is-empty.js.map +0 -1
- package/dist/slate/utils/is-text.cjs.map +0 -1
- package/dist/slate/utils/is-text.js.map +0 -1
- package/dist/slate/utils/is-whitespace-character.cjs.map +0 -1
- package/dist/slate/utils/is-whitespace-character.js.map +0 -1
- package/dist/slate/utils/marks.cjs.map +0 -1
- package/dist/slate/utils/marks.js.map +0 -1
- package/dist/slate/utils/selection-contains-inlines.cjs.map +0 -1
- package/dist/slate/utils/selection-contains-inlines.js.map +0 -1
- /package/dist/{slate → primitives/slate}/plugins/empty-clear-formatting.cjs +0 -0
- /package/dist/{slate → primitives/slate}/plugins/empty-clear-formatting.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/get-character.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/get-character.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/get-dom-range.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/get-dom-range.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/get-match-range.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/get-match-range.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-empty-string.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-empty-string.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-empty.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-empty.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-text.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-text.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-whitespace-character.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/is-whitespace-character.js +0 -0
- /package/dist/{slate → primitives/slate}/utils/selection-contains-inlines.cjs +0 -0
- /package/dist/{slate → primitives/slate}/utils/selection-contains-inlines.js +0 -0
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { nanoid, kInternal, HttpError } from '@liveblocks/core';
|
|
3
|
-
import { useClient } from '@liveblocks/react';
|
|
4
|
-
import { useLayoutEffect } from '@liveblocks/react/_private';
|
|
5
|
-
import { createContext, forwardRef, useRef, useState, useCallback, useImperativeHandle, useContext, useEffect, useMemo } from 'react';
|
|
6
|
-
import { createEditor, Transforms, Editor as Editor$1 } from 'slate';
|
|
7
|
-
import { withHistory } from 'slate-history';
|
|
8
|
-
import { withReact, ReactEditor, Slate, Editable } from 'slate-react';
|
|
9
|
-
import { withNormalize } from '../../../slate/plugins/normalize.js';
|
|
10
|
-
import { isEmpty } from '../../../slate/utils/is-empty.js';
|
|
11
|
-
import { AttachmentTooLargeError } from '../../Composer/utils.js';
|
|
12
|
-
|
|
13
|
-
const ComposerContext = createContext(null);
|
|
14
|
-
const MAX_ATTACHMENTS = 10;
|
|
15
|
-
const MAX_ATTACHMENT_SIZE = 1024 * 1024 * 1024;
|
|
16
|
-
const Form = forwardRef(
|
|
17
|
-
({ onComposerSubmit, onSubmit, disabled, chatId, ...props }, forwardedRef) => {
|
|
18
|
-
const formRef = useRef(null);
|
|
19
|
-
const fileInputRef = useRef(null);
|
|
20
|
-
const editorRef = useRef(
|
|
21
|
-
null
|
|
22
|
-
);
|
|
23
|
-
if (editorRef.current === null) {
|
|
24
|
-
editorRef.current = withNormalize(withHistory(withReact(createEditor())));
|
|
25
|
-
}
|
|
26
|
-
const editor = editorRef.current;
|
|
27
|
-
const [isEditorEmpty, setIsEditorEmpty] = useState(true);
|
|
28
|
-
const [attachments, setAttachments] = useState([]);
|
|
29
|
-
const handleSubmit = useCallback(
|
|
30
|
-
(event) => {
|
|
31
|
-
if (disabled || isEmpty(editor, editor.children))
|
|
32
|
-
return;
|
|
33
|
-
onSubmit?.(event);
|
|
34
|
-
if (onComposerSubmit === void 0 || event.isDefaultPrevented()) {
|
|
35
|
-
event.preventDefault();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const content = editor.children.map((block) => {
|
|
39
|
-
if ("type" in block && block.type === "paragraph") {
|
|
40
|
-
return block.children.map((child) => {
|
|
41
|
-
if ("text" in child) {
|
|
42
|
-
return child.text;
|
|
43
|
-
}
|
|
44
|
-
return "";
|
|
45
|
-
}).join("");
|
|
46
|
-
}
|
|
47
|
-
return "";
|
|
48
|
-
}).join("\n");
|
|
49
|
-
onComposerSubmit({ text: content }, event);
|
|
50
|
-
if (event.isDefaultPrevented()) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
Transforms.delete(editor, {
|
|
55
|
-
at: {
|
|
56
|
-
anchor: Editor$1.start(editor, []),
|
|
57
|
-
focus: Editor$1.end(editor, [])
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
[disabled, editor, onSubmit, onComposerSubmit]
|
|
62
|
-
);
|
|
63
|
-
useLayoutEffect(() => {
|
|
64
|
-
setIsEditorEmpty(isEmpty(editor, editor.children));
|
|
65
|
-
}, [editor]);
|
|
66
|
-
const handleEditorValueChange = useCallback(() => {
|
|
67
|
-
setIsEditorEmpty(isEmpty(editor, editor.children));
|
|
68
|
-
}, [editor]);
|
|
69
|
-
const requestFormSubmit = useCallback(() => {
|
|
70
|
-
if (isEmpty(editor, editor.children))
|
|
71
|
-
return;
|
|
72
|
-
if (attachments.some((attachment) => attachment.status === "uploading")) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
requestAnimationFrame(() => {
|
|
76
|
-
if (formRef.current === null)
|
|
77
|
-
return;
|
|
78
|
-
if (typeof formRef.current.requestSubmit === "function") {
|
|
79
|
-
return formRef.current.requestSubmit();
|
|
80
|
-
}
|
|
81
|
-
const submitter = document.createElement("input");
|
|
82
|
-
submitter.type = "submit";
|
|
83
|
-
submitter.hidden = true;
|
|
84
|
-
formRef.current.appendChild(submitter);
|
|
85
|
-
submitter.click();
|
|
86
|
-
formRef.current.removeChild(submitter);
|
|
87
|
-
});
|
|
88
|
-
}, [editor, attachments]);
|
|
89
|
-
const handleAttachFiles = useCallback(() => {
|
|
90
|
-
if (disabled)
|
|
91
|
-
return;
|
|
92
|
-
fileInputRef.current?.click();
|
|
93
|
-
}, [disabled]);
|
|
94
|
-
const handleRemoveAttachment = useCallback((id) => {
|
|
95
|
-
setAttachments(
|
|
96
|
-
(attachments2) => attachments2.filter((attachment) => attachment.id !== id)
|
|
97
|
-
);
|
|
98
|
-
}, []);
|
|
99
|
-
useImperativeHandle(
|
|
100
|
-
forwardedRef,
|
|
101
|
-
() => formRef.current,
|
|
102
|
-
[]
|
|
103
|
-
);
|
|
104
|
-
const client = useClient();
|
|
105
|
-
return /* @__PURE__ */ jsxs(ComposerContext.Provider, {
|
|
106
|
-
value: {
|
|
107
|
-
chatId,
|
|
108
|
-
editor,
|
|
109
|
-
onEditorValueChange: handleEditorValueChange,
|
|
110
|
-
isEditorEmpty,
|
|
111
|
-
requestFormSubmit,
|
|
112
|
-
disabled: disabled || false,
|
|
113
|
-
attachments,
|
|
114
|
-
onAttachFiles: handleAttachFiles,
|
|
115
|
-
onRemoveAttachment: handleRemoveAttachment,
|
|
116
|
-
numOfAttachments: attachments.length
|
|
117
|
-
},
|
|
118
|
-
children: [
|
|
119
|
-
/* @__PURE__ */ jsx("form", {
|
|
120
|
-
onSubmit: handleSubmit,
|
|
121
|
-
...props,
|
|
122
|
-
ref: formRef
|
|
123
|
-
}),
|
|
124
|
-
/* @__PURE__ */ jsx("input", {
|
|
125
|
-
type: "file",
|
|
126
|
-
multiple: true,
|
|
127
|
-
accept: "image/png, image/jpeg",
|
|
128
|
-
ref: fileInputRef,
|
|
129
|
-
onClick: (event) => {
|
|
130
|
-
event.stopPropagation();
|
|
131
|
-
},
|
|
132
|
-
onChange: function(event) {
|
|
133
|
-
if (disabled)
|
|
134
|
-
return;
|
|
135
|
-
if (event.target.files === null)
|
|
136
|
-
return;
|
|
137
|
-
if (event.target.files.length === 0)
|
|
138
|
-
return;
|
|
139
|
-
for (const file of Array.from(event.target.files).slice(
|
|
140
|
-
0,
|
|
141
|
-
MAX_ATTACHMENTS - attachments.length
|
|
142
|
-
)) {
|
|
143
|
-
const id = `at_${nanoid()}`;
|
|
144
|
-
if (file.size > MAX_ATTACHMENT_SIZE) {
|
|
145
|
-
setAttachments((attachments2) => [
|
|
146
|
-
...attachments2,
|
|
147
|
-
{
|
|
148
|
-
id,
|
|
149
|
-
file,
|
|
150
|
-
status: "error",
|
|
151
|
-
error: new AttachmentTooLargeError("File is too large.")
|
|
152
|
-
}
|
|
153
|
-
]);
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
setAttachments((attachments2) => [
|
|
157
|
-
...attachments2,
|
|
158
|
-
{
|
|
159
|
-
id,
|
|
160
|
-
file,
|
|
161
|
-
status: "uploading"
|
|
162
|
-
}
|
|
163
|
-
]);
|
|
164
|
-
client[kInternal].httpClient.uploadChatAttachment({
|
|
165
|
-
chatId,
|
|
166
|
-
attachment: {
|
|
167
|
-
id,
|
|
168
|
-
file
|
|
169
|
-
}
|
|
170
|
-
}).then(() => {
|
|
171
|
-
setAttachments(
|
|
172
|
-
(attachments2) => attachments2.map(
|
|
173
|
-
(attachment) => attachment.id === id ? { ...attachment, status: "uploaded" } : attachment
|
|
174
|
-
)
|
|
175
|
-
);
|
|
176
|
-
}).catch((error) => {
|
|
177
|
-
if (error instanceof Error) {
|
|
178
|
-
setAttachments(
|
|
179
|
-
(attachments2) => attachments2.map(
|
|
180
|
-
(attachment) => attachment.id === id ? {
|
|
181
|
-
...attachment,
|
|
182
|
-
status: "error",
|
|
183
|
-
error: error instanceof HttpError && error.status === 413 ? new AttachmentTooLargeError(
|
|
184
|
-
"File is too large"
|
|
185
|
-
) : error
|
|
186
|
-
} : attachment
|
|
187
|
-
)
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
event.target.value = "";
|
|
193
|
-
},
|
|
194
|
-
tabIndex: -1,
|
|
195
|
-
style: { display: "none" }
|
|
196
|
-
})
|
|
197
|
-
]
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
const Editor = forwardRef(
|
|
202
|
-
({ defaultValue = "", onKeyDown, disabled, autoFocus, ...props }, forwardedRef) => {
|
|
203
|
-
const context = useContext(ComposerContext);
|
|
204
|
-
if (context === null) {
|
|
205
|
-
throw new Error("Editor must be a descendant of Form.");
|
|
206
|
-
}
|
|
207
|
-
const {
|
|
208
|
-
editor,
|
|
209
|
-
onEditorValueChange,
|
|
210
|
-
requestFormSubmit,
|
|
211
|
-
disabled: isFormDisabled
|
|
212
|
-
} = context;
|
|
213
|
-
const handleKeyDown = useCallback(
|
|
214
|
-
(event) => {
|
|
215
|
-
onKeyDown?.(event);
|
|
216
|
-
if (event.isDefaultPrevented())
|
|
217
|
-
return;
|
|
218
|
-
if (event.key === "Enter" && !event.shiftKey) {
|
|
219
|
-
event.preventDefault();
|
|
220
|
-
requestFormSubmit();
|
|
221
|
-
} else if (event.key === "Enter" && event.shiftKey) {
|
|
222
|
-
event.preventDefault();
|
|
223
|
-
editor.insertBreak();
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
[editor, onKeyDown, requestFormSubmit]
|
|
227
|
-
);
|
|
228
|
-
useImperativeHandle(
|
|
229
|
-
forwardedRef,
|
|
230
|
-
() => ReactEditor.toDOMNode(editor, editor),
|
|
231
|
-
[editor]
|
|
232
|
-
);
|
|
233
|
-
useEffect(() => {
|
|
234
|
-
if (!autoFocus)
|
|
235
|
-
return;
|
|
236
|
-
try {
|
|
237
|
-
if (!ReactEditor.isFocused(editor)) {
|
|
238
|
-
Transforms.select(editor, Editor$1.end(editor, []));
|
|
239
|
-
ReactEditor.focus(editor);
|
|
240
|
-
}
|
|
241
|
-
} catch {
|
|
242
|
-
}
|
|
243
|
-
}, [editor, autoFocus]);
|
|
244
|
-
const initialValue = useMemo(() => {
|
|
245
|
-
return defaultValue.split("\n").map((text) => ({ type: "paragraph", children: [{ text }] }));
|
|
246
|
-
}, [defaultValue]);
|
|
247
|
-
return /* @__PURE__ */ jsx(Slate, {
|
|
248
|
-
editor,
|
|
249
|
-
initialValue,
|
|
250
|
-
onValueChange: onEditorValueChange,
|
|
251
|
-
children: /* @__PURE__ */ jsx(Editable, {
|
|
252
|
-
enterKeyHint: "send",
|
|
253
|
-
autoCapitalize: "sentences",
|
|
254
|
-
onKeyDown: handleKeyDown,
|
|
255
|
-
"data-disabled": disabled || isFormDisabled || void 0,
|
|
256
|
-
...props,
|
|
257
|
-
readOnly: disabled || isFormDisabled,
|
|
258
|
-
disabled: disabled || isFormDisabled,
|
|
259
|
-
renderPlaceholder: function({ attributes, children }) {
|
|
260
|
-
const { opacity: _opacity, ...style } = attributes.style;
|
|
261
|
-
return /* @__PURE__ */ jsx("span", {
|
|
262
|
-
...attributes,
|
|
263
|
-
style,
|
|
264
|
-
"data-placeholder": "",
|
|
265
|
-
children
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
);
|
|
272
|
-
const Submit = forwardRef(
|
|
273
|
-
({ disabled, ...props }, forwardedRef) => {
|
|
274
|
-
const context = useContext(ComposerContext);
|
|
275
|
-
if (context === null) {
|
|
276
|
-
throw new Error("Submit must be a descendant of Form.");
|
|
277
|
-
}
|
|
278
|
-
const { disabled: isFormDisabled, isEditorEmpty, attachments } = context;
|
|
279
|
-
return /* @__PURE__ */ jsx("button", {
|
|
280
|
-
type: "submit",
|
|
281
|
-
...props,
|
|
282
|
-
ref: forwardedRef,
|
|
283
|
-
disabled: disabled || isFormDisabled || isEditorEmpty || attachments.some((attachment) => attachment.status === "uploading")
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
const AttachFiles = forwardRef(
|
|
288
|
-
({ onClick, disabled, ...props }, forwardedRef) => {
|
|
289
|
-
const context = useContext(ComposerContext);
|
|
290
|
-
if (context === null) {
|
|
291
|
-
throw new Error("AttachFiles must be a descendant of Form.");
|
|
292
|
-
}
|
|
293
|
-
const {
|
|
294
|
-
disabled: isFormDisabled,
|
|
295
|
-
onAttachFiles,
|
|
296
|
-
numOfAttachments
|
|
297
|
-
} = context;
|
|
298
|
-
return /* @__PURE__ */ jsx("button", {
|
|
299
|
-
type: "button",
|
|
300
|
-
...props,
|
|
301
|
-
onClick: function(event) {
|
|
302
|
-
onClick?.(event);
|
|
303
|
-
if (event.isDefaultPrevented())
|
|
304
|
-
return;
|
|
305
|
-
onAttachFiles();
|
|
306
|
-
},
|
|
307
|
-
onPointerDown: (event) => event.preventDefault(),
|
|
308
|
-
ref: forwardedRef,
|
|
309
|
-
disabled: isFormDisabled || disabled || numOfAttachments >= MAX_ATTACHMENTS
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
export { AttachFiles, ComposerContext, Editor, Form, MAX_ATTACHMENTS, MAX_ATTACHMENT_SIZE, Submit };
|
|
315
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/primitives/Chat/Composer/index.tsx"],"sourcesContent":["import { HttpError, kInternal, nanoid } from \"@liveblocks/core\";\nimport { useClient } from \"@liveblocks/react\";\nimport { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport type {\n ButtonHTMLAttributes,\n FormEvent,\n FormHTMLAttributes,\n HTMLAttributes,\n KeyboardEvent,\n} from \"react\";\nimport {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { BaseEditor, Descendant } from \"slate\";\nimport { createEditor, Editor as SlateEditor, Transforms } from \"slate\";\nimport type { HistoryEditor } from \"slate-history\";\nimport { withHistory } from \"slate-history\";\nimport { Editable, ReactEditor, Slate, withReact } from \"slate-react\";\n\nimport { withNormalize } from \"../../../slate/plugins/normalize\";\nimport { isEmpty } from \"../../../slate/utils/is-empty\";\nimport { AttachmentTooLargeError } from \"../../Composer/utils\";\n\n/* -------------------------------------------------------------------------------------------------\n * Form\n * -----------------------------------------------------------------------------------------------*/\nexport const ComposerContext = createContext<{\n chatId: string;\n\n editor: SlateEditor;\n onEditorValueChange: (value: Descendant[]) => void;\n isEditorEmpty: boolean;\n\n attachments: ({\n id: string;\n file: File;\n } & (\n | {\n status: \"uploading\" | \"uploaded\";\n }\n | {\n status: \"error\";\n error: Error;\n }\n ))[];\n onAttachFiles: () => void;\n onRemoveAttachment: (id: string) => void;\n numOfAttachments: number;\n\n requestFormSubmit: () => void;\n disabled: boolean;\n} | null>(null);\n\nexport const MAX_ATTACHMENTS = 10;\nexport const MAX_ATTACHMENT_SIZE = 1024 * 1024 * 1024; // 1 GB\n\nexport type FormProps = FormHTMLAttributes<HTMLFormElement> & {\n /**\n * The event handler called when a chat message is submitted.\n */\n onComposerSubmit?: (\n message: {\n /**\n * The submitted message text.\n */\n text: string;\n },\n event: FormEvent<HTMLFormElement>\n ) => void;\n /**\n * Whether the composer is disabled.\n */\n disabled?: boolean;\n /**\n * The id of the chat the composer belongs to.\n */\n chatId: string;\n};\n\n/**\n * Surrounds the chat composer's content and handles submissions.\n *\n * @example\n * <Form onComposerSubmit={({ text }) => {}}>\n *\t <Editor />\n * <Submit />\n * </Form>\n */\nexport const Form = forwardRef<HTMLFormElement, FormProps>(\n (\n { onComposerSubmit, onSubmit, disabled, chatId, ...props },\n forwardedRef\n ) => {\n const formRef = useRef<HTMLFormElement | null>(null);\n const fileInputRef = useRef<HTMLInputElement | null>(null);\n\n const editorRef = useRef<(BaseEditor & ReactEditor & HistoryEditor) | null>(\n null\n );\n if (editorRef.current === null) {\n editorRef.current = withNormalize(withHistory(withReact(createEditor())));\n }\n const editor = editorRef.current;\n\n const [isEditorEmpty, setIsEditorEmpty] = useState(true);\n\n const [attachments, setAttachments] = useState<\n ({\n id: string;\n file: File;\n } & (\n | {\n status: \"uploading\" | \"uploaded\";\n }\n | {\n status: \"error\";\n error: Error;\n }\n ))[]\n >([]);\n\n const handleSubmit = useCallback(\n (event: FormEvent<HTMLFormElement>) => {\n if (disabled || isEmpty(editor, editor.children)) return;\n\n onSubmit?.(event);\n\n if (onComposerSubmit === undefined || event.isDefaultPrevented()) {\n event.preventDefault();\n return;\n }\n\n // Extract the text content from the editor.\n const content = editor.children\n .map((block) => {\n if (\"type\" in block && block.type === \"paragraph\") {\n return block.children\n .map((child) => {\n if (\"text\" in child) {\n return child.text;\n }\n return \"\";\n })\n .join(\"\");\n }\n return \"\";\n })\n .join(\"\\n\");\n\n onComposerSubmit({ text: content }, event);\n\n if (event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n\n // Clear the editor after dispatching the message.\n Transforms.delete(editor, {\n at: {\n anchor: SlateEditor.start(editor, []),\n focus: SlateEditor.end(editor, []),\n },\n });\n },\n [disabled, editor, onSubmit, onComposerSubmit]\n );\n\n useLayoutEffect(() => {\n setIsEditorEmpty(isEmpty(editor, editor.children));\n }, [editor]);\n\n const handleEditorValueChange = useCallback(() => {\n setIsEditorEmpty(isEmpty(editor, editor.children));\n }, [editor]);\n\n const requestFormSubmit = useCallback(() => {\n if (isEmpty(editor, editor.children)) return;\n\n if (attachments.some((attachment) => attachment.status === \"uploading\")) {\n return;\n }\n\n // We need to wait for the next frame in some cases like when composing diacritics,\n // we want any native handling to be done first while still being handled on `keydown`.\n requestAnimationFrame(() => {\n if (formRef.current === null) return;\n if (typeof formRef.current.requestSubmit === \"function\") {\n return formRef.current.requestSubmit();\n }\n const submitter = document.createElement(\"input\");\n submitter.type = \"submit\";\n submitter.hidden = true;\n formRef.current.appendChild(submitter);\n submitter.click();\n formRef.current.removeChild(submitter);\n });\n }, [editor, attachments]);\n\n const handleAttachFiles = useCallback(() => {\n if (disabled) return;\n fileInputRef.current?.click();\n }, [disabled]);\n\n const handleRemoveAttachment = useCallback((id: string) => {\n setAttachments((attachments) =>\n attachments.filter((attachment) => attachment.id !== id)\n );\n }, []);\n\n useImperativeHandle<HTMLFormElement | null, HTMLFormElement | null>(\n forwardedRef,\n () => formRef.current,\n []\n );\n\n const client = useClient();\n\n return (\n <ComposerContext.Provider\n value={{\n chatId,\n editor,\n onEditorValueChange: handleEditorValueChange,\n isEditorEmpty,\n requestFormSubmit,\n disabled: disabled || false,\n attachments,\n onAttachFiles: handleAttachFiles,\n onRemoveAttachment: handleRemoveAttachment,\n numOfAttachments: attachments.length,\n }}\n >\n <form onSubmit={handleSubmit} {...props} ref={formRef} />\n <input\n type=\"file\"\n multiple\n accept=\"image/png, image/jpeg\"\n ref={fileInputRef}\n onClick={(event) => {\n event.stopPropagation();\n }}\n onChange={function (event) {\n if (disabled) return;\n\n if (event.target.files === null) return;\n if (event.target.files.length === 0) return;\n\n for (const file of Array.from(event.target.files).slice(\n 0,\n MAX_ATTACHMENTS - attachments.length\n )) {\n const id = `at_${nanoid()}`;\n if (file.size > MAX_ATTACHMENT_SIZE) {\n setAttachments((attachments) => [\n ...attachments,\n {\n id,\n file,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\"),\n },\n ]);\n continue;\n }\n\n setAttachments((attachments) => [\n ...attachments,\n {\n id,\n file,\n status: \"uploading\",\n },\n ]);\n\n client[kInternal].httpClient\n .uploadChatAttachment({\n chatId,\n attachment: {\n id,\n file,\n },\n })\n .then(() => {\n setAttachments((attachments) =>\n attachments.map((attachment) =>\n attachment.id === id\n ? { ...attachment, status: \"uploaded\" }\n : attachment\n )\n );\n })\n .catch((error) => {\n if (error instanceof Error) {\n setAttachments((attachments) =>\n attachments.map((attachment) =>\n attachment.id === id\n ? {\n ...attachment,\n status: \"error\",\n error:\n error instanceof HttpError &&\n error.status === 413\n ? new AttachmentTooLargeError(\n \"File is too large\"\n )\n : error,\n }\n : attachment\n )\n );\n }\n });\n }\n\n event.target.value = \"\";\n }}\n tabIndex={-1}\n style={{ display: \"none\" }}\n />\n </ComposerContext.Provider>\n );\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Editor\n * -----------------------------------------------------------------------------------------------*/\nexport type EditorProps = Omit<\n HTMLAttributes<HTMLDivElement>,\n \"defaultValue\"\n> & {\n /**\n * The editor's initial value.\n */\n defaultValue?: string;\n /**\n * The text to display when the editor is empty.\n */\n placeholder?: string;\n /**\n * Whether the editor is disabled.\n */\n disabled?: boolean;\n /**\n * Whether to focus the editor on mount.\n */\n autoFocus?: boolean;\n};\n\n/**\n * Displays the chat composer's editor.\n *\n * @example\n * <Editor placeholder=\"Write a message…\" />\n */\nexport const Editor = forwardRef<HTMLDivElement, EditorProps>(\n (\n { defaultValue = \"\", onKeyDown, disabled, autoFocus, ...props },\n forwardedRef\n ) => {\n const context = useContext(ComposerContext);\n if (context === null) {\n throw new Error(\"Editor must be a descendant of Form.\");\n }\n\n const {\n editor,\n onEditorValueChange,\n requestFormSubmit,\n disabled: isFormDisabled,\n } = context;\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n if (event.isDefaultPrevented()) return;\n\n if (event.key === \"Enter\" && !event.shiftKey) {\n event.preventDefault();\n requestFormSubmit();\n } else if (event.key === \"Enter\" && event.shiftKey) {\n event.preventDefault();\n editor.insertBreak();\n }\n },\n [editor, onKeyDown, requestFormSubmit]\n );\n\n useImperativeHandle(\n forwardedRef,\n () => ReactEditor.toDOMNode(editor, editor) as HTMLDivElement,\n [editor]\n );\n\n useEffect(() => {\n if (!autoFocus) return;\n\n try {\n if (!ReactEditor.isFocused(editor)) {\n Transforms.select(editor, SlateEditor.end(editor, []));\n ReactEditor.focus(editor);\n }\n } catch {\n // Slate's DOM-specific methods will throw if the editor's DOM node no longer exists. This action doesn't make sense on an unmounted editor so we can safely ignore it.\n }\n }, [editor, autoFocus]);\n\n const initialValue: { type: \"paragraph\"; children: { text: string }[] }[] =\n useMemo(() => {\n return defaultValue\n .split(\"\\n\")\n .map((text) => ({ type: \"paragraph\", children: [{ text }] }));\n }, [defaultValue]);\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onValueChange={onEditorValueChange}\n >\n <Editable\n enterKeyHint=\"send\"\n autoCapitalize=\"sentences\"\n onKeyDown={handleKeyDown}\n data-disabled={disabled || isFormDisabled || undefined}\n {...props}\n readOnly={disabled || isFormDisabled}\n disabled={disabled || isFormDisabled}\n renderPlaceholder={function ({ attributes, children }) {\n const { opacity: _opacity, ...style } = attributes.style;\n return (\n <span {...attributes} style={style} data-placeholder=\"\">\n {children}\n </span>\n );\n }}\n />\n </Slate>\n );\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Submit\n * -----------------------------------------------------------------------------------------------*/\nexport type SubmitProps = ButtonHTMLAttributes<HTMLButtonElement>;\n\n/**\n * A button to submit a chat message.\n *\n * @example\n * <ChatComposer.Submit>Send</ChatComposer.Submit>\n */\nexport const Submit = forwardRef<HTMLButtonElement, SubmitProps>(\n ({ disabled, ...props }, forwardedRef) => {\n const context = useContext(ComposerContext);\n if (context === null) {\n throw new Error(\"Submit must be a descendant of Form.\");\n }\n\n const { disabled: isFormDisabled, isEditorEmpty, attachments } = context;\n\n return (\n <button\n type=\"submit\"\n {...props}\n ref={forwardedRef}\n disabled={\n disabled ||\n isFormDisabled ||\n isEditorEmpty ||\n attachments.some((attachment) => attachment.status === \"uploading\")\n }\n />\n );\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * AttachFiles\n * -----------------------------------------------------------------------------------------------*/\nexport type AttachFilesProps = ButtonHTMLAttributes<HTMLButtonElement>;\n\n/**\n * A button which opens a file picker to create attachments.\n *\n * @example\n * <Composer.AttachFiles>Attach files</Composer.AttachFiles>\n */\nexport const AttachFiles = forwardRef<HTMLButtonElement, AttachFilesProps>(\n ({ onClick, disabled, ...props }, forwardedRef) => {\n const context = useContext(ComposerContext);\n if (context === null) {\n throw new Error(\"AttachFiles must be a descendant of Form.\");\n }\n\n const {\n disabled: isFormDisabled,\n onAttachFiles,\n numOfAttachments,\n } = context;\n\n return (\n <button\n type=\"button\"\n {...props}\n onClick={function (event) {\n onClick?.(event);\n if (event.isDefaultPrevented()) return;\n onAttachFiles();\n }}\n onPointerDown={(event) => event.preventDefault()}\n ref={forwardedRef}\n disabled={\n isFormDisabled || disabled || numOfAttachments >= MAX_ATTACHMENTS\n }\n />\n );\n }\n);\n"],"names":["SlateEditor","attachments"],"mappings":";;;;;;;;;;;;AAkCa,MAAA,eAAA,GAAkB,cAyBrB,IAAI,EAAA;AAEP,MAAM,eAAkB,GAAA,GAAA;AAClB,MAAA,mBAAA,GAAsB,OAAO,IAAO,GAAA,KAAA;AAkC1C,MAAM,IAAO,GAAA,UAAA;AAAA,EAClB,CACE,EAAE,gBAAkB,EAAA,QAAA,EAAU,UAAU,MAAW,EAAA,GAAA,KAAA,IACnD,YACG,K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A,CAAY,KAAK,CAAC,UAAA,KAAe,UAAW,CAAA,MAAA,KAAW,WAAW,CAAA;AAAA,KAEtE,CAAA,CAAA;AAAA,GAEJ;AACF,EAAA;AAaO,MAAM,WAAc,GAAA,UAAA;AAAA,EACzB,CAAC,EAAE,OAAA,EAAS,QAAa,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,IAAM,MAAA,OAAA,GAAU,WAAW,eAAe,CAAA,CAAA;AAC1C,IAAA,IAAI,YAAY,IAAM,EAAA;AACpB,MAAM,MAAA,IAAI,MAAM,2CAA2C,CAAA,CAAA;AAAA,KAC7D;AAEA,IAAM,MAAA;AAAA,MACJ,QAAU,EAAA,cAAA;AAAA,MACV,aAAA;AAAA,MACA,gBAAA;AAAA,KACE,GAAA,OAAA,CAAA;AAEJ,IAAA,uBACG,GAAA,CAAA,QAAA,EAAA;AAAA,MACC,IAAK,EAAA,QAAA;AAAA,MACJ,GAAG,KAAA;AAAA,MACJ,OAAA,EAAS,SAAU,KAAO,EAAA;AACxB,QAAA,OAAA,GAAU,KAAK,CAAA,CAAA;AACf,QAAA,IAAI,MAAM,kBAAmB,EAAA;AAAG,UAAA,OAAA;AAChC,QAAc,aAAA,EAAA,CAAA;AAAA,OAChB;AAAA,MACA,aAAe,EAAA,CAAC,KAAU,KAAA,KAAA,CAAM,cAAe,EAAA;AAAA,MAC/C,GAAK,EAAA,YAAA;AAAA,MACL,QAAA,EACE,cAAkB,IAAA,QAAA,IAAY,gBAAoB,IAAA,eAAA;AAAA,KAEtD,CAAA,CAAA;AAAA,GAEJ;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Collapsible.cjs","sources":["../../../src/primitives/internal/Collapsible.tsx"],"sourcesContent":["import type { HTMLAttributes } from \"react\";\nimport {\n createContext,\n forwardRef,\n useContext,\n useEffect,\n useId,\n useImperativeHandle,\n useRef,\n} from \"react\";\n\n/* -------------------------------------------------------------------------------------------------\n * Root\n * -----------------------------------------------------------------------------------------------*/\n\nconst RootContext = createContext<{\n open: boolean;\n onOpenChange(open: boolean): void;\n\n disabled: boolean;\n contentId: string;\n} | null>(null);\n\nexport interface RootProps extends HTMLAttributes<HTMLDivElement> {\n open: boolean;\n onOpenChange(open: boolean): void;\n disabled?: boolean;\n}\n\nexport const Root = forwardRef<HTMLDivElement, RootProps>(function Root(\n { open, onOpenChange, disabled = false, ...props },\n forwardedRef\n) {\n const id = useId();\n\n return (\n <RootContext.Provider\n value={{ open, onOpenChange, disabled, contentId: id }}\n >\n <div\n {...props}\n ref={forwardedRef}\n data-state={open ? \"open\" : \"closed\"}\n data-disabled={disabled ? \"\" : undefined}\n />\n </RootContext.Provider>\n );\n});\n\n/* -------------------------------------------------------------------------------------------------\n * Trigger\n * -----------------------------------------------------------------------------------------------*/\ninterface TriggerProps extends HTMLAttributes<HTMLButtonElement> {}\n\nexport const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(\n function Trigger({ onClick, ...props }, forwardedRef) {\n const context = useContext(RootContext);\n\n if (!context) {\n throw new Error(\"Collapsible.Trigger must be a descendant of Root\");\n }\n\n const { open, disabled, contentId, onOpenChange } = context;\n\n return (\n <button\n {...props}\n ref={forwardedRef}\n type=\"button\"\n aria-controls={contentId}\n aria-expanded={open || false}\n data-state={open ? \"open\" : \"closed\"}\n data-disabled={disabled ? \"\" : undefined}\n disabled={disabled}\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) return;\n if (disabled) return;\n onOpenChange(!open);\n }}\n />\n );\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Content\n * -----------------------------------------------------------------------------------------------*/\n\ninterface ContentProps extends HTMLAttributes<HTMLDivElement> {}\n\nexport const Content = forwardRef<HTMLDivElement, ContentProps>(\n function Content(props, forwardedRef) {\n const rootContext = useContext(RootContext);\n const divRef = useRef<HTMLDivElement>(null);\n\n if (!rootContext) throw new Error(\"Missing RootContext Provider\");\n\n const { open, onOpenChange, disabled, contentId } = rootContext;\n\n useEffect(() => {\n const element = divRef.current;\n if (element === null) return;\n\n const isHiddenUntilFoundSupported = \"onbeforematch\" in document.body;\n if (!isHiddenUntilFoundSupported) return;\n\n function handleBeforeMatch() {\n onOpenChange(true);\n }\n\n // https://developer.chrome.com/articles/hidden-until-found/\n element.addEventListener(\"beforematch\", handleBeforeMatch);\n return () => {\n element.removeEventListener(\"beforematch\", handleBeforeMatch);\n };\n }, [onOpenChange]);\n\n // Passing `string` to `hidden` in JSX is not currently supported: https://github.com/facebook/react/issues/24740\n useEffect(() => {\n const element = divRef.current;\n if (element === null) return;\n\n if (open) return;\n\n const isHiddenUntilFoundSupported = \"onbeforematch\" in document.body;\n if (!isHiddenUntilFoundSupported) return;\n\n element.setAttribute(\"hidden\", \"until-found\");\n return () => {\n element.removeAttribute(\"hidden\");\n };\n }, [open]);\n\n useImperativeHandle<\n HTMLDivElement | null,\n HTMLDivElement | null\n >(forwardedRef, () => {\n return divRef.current;\n }, []);\n\n return (\n <div\n {...props}\n ref={divRef}\n data-state={open ? \"open\" : \"closed\"}\n data-disabled={disabled ? \"\" : undefined}\n id={contentId}\n hidden={!open}\n />\n );\n }\n);\n"],"names":["createContext","forwardRef","Root","useId","jsx","Trigger","useContext","Content","useRef","useEffect","useImperativeHandle"],"mappings":";;;;;AAeA,MAAM,WAAA,GAAcA,oBAMV,IAAI,CAAA,CAAA;AAQD,MAAA,IAAA,GAAOC,gBAAsC,CAAA,SAASC,KACjE,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,QAAW,GAAA,KAAA,EAAA,GAAU,KAAM,EAAA,EACjD,YACA,EAAA;AACA,EAAA,MAAM,KAAKC,WAAM,EAAA,CAAA;AAEjB,EACE,uBAAAC,cAAA,CAAC,YAAY,QAAZ,EAAA;AAAA,IACC,OAAO,EAAE,IAAA,EAAM,YAAc,EAAA,QAAA,EAAU,WAAW,EAAG,EAAA;AAAA,IAErD,QAAC,kBAAAA,cAAA,CAAA,KAAA,EAAA;AAAA,MACE,GAAG,K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,QAAA,OAAA,CAAQ,gBAAgB,QAAQ,CAAA,CAAA;AAAA,OAClC,CAAA;AAAA,KACF,EAAG,CAAC,IAAI,CAAC,CAAA,CAAA;AAET,IAAAC,yBAAA,CAGE,cAAc,MAAM;AACpB,MAAA,OAAO,MAAO,CAAA,OAAA,CAAA;AAAA,KAChB,EAAG,EAAE,CAAA,CAAA;AAEL,IAAA,uBACGN,cAAA,CAAA,KAAA,EAAA;AAAA,MACE,GAAG,KAAA;AAAA,MACJ,GAAK,EAAA,MAAA;AAAA,MACL,YAAA,EAAY,OAAO,MAAS,GAAA,QAAA;AAAA,MAC5B,eAAA,EAAe,WAAW,EAAK,GAAA,KAAA,CAAA;AAAA,MAC/B,EAAI,EAAA,SAAA;AAAA,MACJ,QAAQ,CAAC,IAAA;AAAA,KACX,CAAA,CAAA;AAAA,GAEJ;AACF;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Collapsible.js","sources":["../../../src/primitives/internal/Collapsible.tsx"],"sourcesContent":["import type { HTMLAttributes } from \"react\";\nimport {\n createContext,\n forwardRef,\n useContext,\n useEffect,\n useId,\n useImperativeHandle,\n useRef,\n} from \"react\";\n\n/* -------------------------------------------------------------------------------------------------\n * Root\n * -----------------------------------------------------------------------------------------------*/\n\nconst RootContext = createContext<{\n open: boolean;\n onOpenChange(open: boolean): void;\n\n disabled: boolean;\n contentId: string;\n} | null>(null);\n\nexport interface RootProps extends HTMLAttributes<HTMLDivElement> {\n open: boolean;\n onOpenChange(open: boolean): void;\n disabled?: boolean;\n}\n\nexport const Root = forwardRef<HTMLDivElement, RootProps>(function Root(\n { open, onOpenChange, disabled = false, ...props },\n forwardedRef\n) {\n const id = useId();\n\n return (\n <RootContext.Provider\n value={{ open, onOpenChange, disabled, contentId: id }}\n >\n <div\n {...props}\n ref={forwardedRef}\n data-state={open ? \"open\" : \"closed\"}\n data-disabled={disabled ? \"\" : undefined}\n />\n </RootContext.Provider>\n );\n});\n\n/* -------------------------------------------------------------------------------------------------\n * Trigger\n * -----------------------------------------------------------------------------------------------*/\ninterface TriggerProps extends HTMLAttributes<HTMLButtonElement> {}\n\nexport const Trigger = forwardRef<HTMLButtonElement, TriggerProps>(\n function Trigger({ onClick, ...props }, forwardedRef) {\n const context = useContext(RootContext);\n\n if (!context) {\n throw new Error(\"Collapsible.Trigger must be a descendant of Root\");\n }\n\n const { open, disabled, contentId, onOpenChange } = context;\n\n return (\n <button\n {...props}\n ref={forwardedRef}\n type=\"button\"\n aria-controls={contentId}\n aria-expanded={open || false}\n data-state={open ? \"open\" : \"closed\"}\n data-disabled={disabled ? \"\" : undefined}\n disabled={disabled}\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) return;\n if (disabled) return;\n onOpenChange(!open);\n }}\n />\n );\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * Content\n * -----------------------------------------------------------------------------------------------*/\n\ninterface ContentProps extends HTMLAttributes<HTMLDivElement> {}\n\nexport const Content = forwardRef<HTMLDivElement, ContentProps>(\n function Content(props, forwardedRef) {\n const rootContext = useContext(RootContext);\n const divRef = useRef<HTMLDivElement>(null);\n\n if (!rootContext) throw new Error(\"Missing RootContext Provider\");\n\n const { open, onOpenChange, disabled, contentId } = rootContext;\n\n useEffect(() => {\n const element = divRef.current;\n if (element === null) return;\n\n const isHiddenUntilFoundSupported = \"onbeforematch\" in document.body;\n if (!isHiddenUntilFoundSupported) return;\n\n function handleBeforeMatch() {\n onOpenChange(true);\n }\n\n // https://developer.chrome.com/articles/hidden-until-found/\n element.addEventListener(\"beforematch\", handleBeforeMatch);\n return () => {\n element.removeEventListener(\"beforematch\", handleBeforeMatch);\n };\n }, [onOpenChange]);\n\n // Passing `string` to `hidden` in JSX is not currently supported: https://github.com/facebook/react/issues/24740\n useEffect(() => {\n const element = divRef.current;\n if (element === null) return;\n\n if (open) return;\n\n const isHiddenUntilFoundSupported = \"onbeforematch\" in document.body;\n if (!isHiddenUntilFoundSupported) return;\n\n element.setAttribute(\"hidden\", \"until-found\");\n return () => {\n element.removeAttribute(\"hidden\");\n };\n }, [open]);\n\n useImperativeHandle<\n HTMLDivElement | null,\n HTMLDivElement | null\n >(forwardedRef, () => {\n return divRef.current;\n }, []);\n\n return (\n <div\n {...props}\n ref={divRef}\n data-state={open ? \"open\" : \"closed\"}\n data-disabled={disabled ? \"\" : undefined}\n id={contentId}\n hidden={!open}\n />\n );\n }\n);\n"],"names":["Root","Trigger","Content"],"mappings":";;;AAeA,MAAM,WAAA,GAAc,cAMV,IAAI,CAAA,CAAA;AAQD,MAAA,IAAA,GAAO,UAAsC,CAAA,SAASA,KACjE,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,QAAW,GAAA,KAAA,EAAA,GAAU,KAAM,EAAA,EACjD,YACA,EAAA;AACA,EAAA,MAAM,KAAK,KAAM,EAAA,CAAA;AAEjB,EACE,uBAAA,GAAA,CAAC,YAAY,QAAZ,EAAA;AAAA,IACC,OAAO,EAAE,IAAA,EAAM,YAAc,EAAA,QAAA,EAAU,WAAW,EAAG,EAAA;AAAA,IAErD,QAAC,kBAAA,GAAA,CAAA,KAAA,EAAA;AAAA,MACE,GAAG,KAAA;AAAA,MACJ,GAAK,EAAA,YAAA;AAAA,MACL,YAAA,EAAY,OAAO,MAAS,GAAA,QAAA;AAAA,MAC5B,eAAA,EAAe,WAAW,EAAK,GAAA,KAAA,CAAA;AAAA,KACjC,CAAA;AAAA,GACF,CAAA,CAAA;AAEJ,CAAC,EAAA;AAOM,MAAM,OAAU,GAAA,UAAA;AAAA,EACrB,SAASC,QAAQ,CAAA,EAAE,OAAY,EAAA,GAAA,KAAA,IAAS,YAAc,EAAA;AACpD,IAAM,MAAA,OAAA,GAAU,WAAW,WAAW,CAAA,CAAA;AAEtC,IAAA,IAAI,CAAC,OAAS,EAAA;AACZ,MAAM,MAAA,IAAI,MAAM,kDAAkD,CAAA,CAAA;AAAA,KACpE;AAEA,IAAA,MAAM,EAAE,IAAA,EAAM,QAAU,EAA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J;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-formatting.cjs","sources":["../../../src/slate/plugins/auto-formatting.ts"],"sourcesContent":["import type { EditorMarks } from \"slate\";\nimport {\n Editor as SlateEditor,\n Range as SlateRange,\n Transforms as SlateTransforms,\n} from \"slate\";\n\nimport { getCharacterBefore } from \"../utils/get-character\";\nimport { getMatchRange } from \"../utils/get-match-range\";\nimport { isEmptyString } from \"../utils/is-empty-string\";\n\ninterface MarkFormatter {\n type: \"mark\";\n mark: keyof EditorMarks;\n character: string;\n}\n\ntype Formatter = MarkFormatter;\n\nconst formatters: Formatter[] = [\n {\n type: \"mark\",\n mark: \"bold\",\n character: \"*\",\n },\n {\n type: \"mark\",\n mark: \"italic\",\n character: \"_\",\n },\n {\n type: \"mark\",\n mark: \"strikethrough\",\n character: \"~\",\n },\n {\n type: \"mark\",\n mark: \"code\",\n character: \"`\",\n },\n];\nconst markFormattingCharacters = formatters\n .filter((formatter) => formatter.type === \"mark\")\n .map((formatter) => formatter.character);\n\nfunction formatMark<T extends SlateEditor>(\n editor: T,\n text: string,\n formatter: MarkFormatter\n): boolean {\n if (text !== formatter.character) {\n return false;\n }\n\n const match = getMatchRange(editor, editor.selection!, [formatter.character]);\n\n // Check if the match exists and is not empty\n if (!match || SlateRange.isCollapsed(match)) {\n return false;\n }\n\n const formattingCharacter = getCharacterBefore(editor, match);\n\n // Check if the match is preceded by the formatting character\n if (\n !formattingCharacter ||\n formattingCharacter.text !== formatter.character\n ) {\n return false;\n }\n\n const beforeCharacter = getCharacterBefore(editor, formattingCharacter.range);\n\n // Check if the formatting character is preceded by a non-whitespace character (or another formatting character)\n if (\n beforeCharacter &&\n !markFormattingCharacters.includes(beforeCharacter.text) &&\n !isEmptyString(beforeCharacter.text)\n ) {\n return false;\n }\n\n const matchText = SlateEditor.string(editor, match);\n\n // Check if the match has leading/trailing whitespace\n if (matchText.trim() !== matchText) {\n return false;\n }\n\n // Set the match to the expected mark\n SlateTransforms.select(editor, match);\n editor.addMark(formatter.mark, true);\n\n // Set the selection at the end of the match and reset formatting\n SlateTransforms.collapse(editor, { edge: \"end\" });\n editor.removeMark(formatter.mark);\n\n // Delete the formatting character\n SlateTransforms.delete(editor, {\n at: formattingCharacter.range,\n });\n\n return true;\n}\n\nexport function withAutoFormatting<T extends SlateEditor>(editor: T): T {\n const { insertText } = editor;\n\n editor.insertText = (text, options) => {\n if (!editor.selection || !SlateRange.isCollapsed(editor.selection)) {\n return insertText(text, options);\n }\n\n let shouldInsertText = true;\n\n for (const formatter of formatters) {\n if (formatter.type === \"mark\") {\n if (formatMark(editor, text, formatter)) {\n shouldInsertText = false;\n }\n }\n }\n\n if (shouldInsertText) {\n insertText(text, options);\n }\n };\n\n return editor;\n}\n"],"names":["getMatchRange","SlateRange","getCharacterBefore","isEmptyString","SlateEditor","SlateTransforms"],"mappings":";;;;;;;AAmBA,MAAM,UAA0B,GAAA;AAAA,EAC9B;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,MAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AAAA,EACA;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,QAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AAAA,EACA;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,eAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AAAA,EACA;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,MAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AACF,CAAA,CAAA;AACA,MAAM,wBAA2B,GAAA,UAAA,CAC9B,MAAO,CAAA,CAAC,SAAc,KAAA,SAAA,CAAU,IAAS,KAAA,MAAM,CAC/C,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,UAAU,SAAS,CAAA,CAAA;AAEzC,SAAS,UAAA,CACP,M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,OAAO,CAAA,CAAA;AAChD,EAAO,MAAA,CAAA,UAAA,CAAW,UAAU,IAAI,CAAA,CAAA;AAGhC,EAAAA,gBAAA,CAAgB,OAAO,MAAQ,EAAA;AAAA,IAC7B,IAAI,mBAAoB,CAAA,KAAA;AAAA,GACzB,CAAA,CAAA;AAED,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAEO,SAAS,mBAA0C,MAAc,EAAA;AACtE,EAAM,MAAA,EAAE,YAAe,GAAA,MAAA,CAAA;AAEvB,EAAO,MAAA,CAAA,UAAA,GAAa,CAAC,IAAA,EAAM,OAAY,KAAA;AACrC,IAAI,IAAA,CAAC,OAAO,SAAa,IAAA,CAACJ,YAAW,WAAY,CAAA,MAAA,CAAO,SAAS,CAAG,EAAA;AAClE,MAAO,OAAA,UAAA,CAAW,MAAM,OAAO,CAAA,CAAA;AAAA,KACjC;AAEA,IAAA,IAAI,gBAAmB,GAAA,IAAA,CAAA;AAEvB,IAAA,KAAA,MAAW,aAAa,UAAY,EAAA;AAClC,MAAI,IAAA,SAAA,CAAU,SAAS,MAAQ,EAAA;AAC7B,QAAA,IAAI,UAAW,CAAA,MAAA,EAAQ,IAAM,EAAA,SAAS,CAAG,EAAA;AACvC,UAAmB,gBAAA,GAAA,KAAA,CAAA;AAAA,SACrB;AAAA,OACF;AAAA,KACF;AAEA,IAAA,IAAI,gBAAkB,EAAA;AACpB,MAAA,UAAA,CAAW,MAAM,OAAO,CAAA,CAAA;AAAA,KAC1B;AAAA,GACF,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-formatting.js","sources":["../../../src/slate/plugins/auto-formatting.ts"],"sourcesContent":["import type { EditorMarks } from \"slate\";\nimport {\n Editor as SlateEditor,\n Range as SlateRange,\n Transforms as SlateTransforms,\n} from \"slate\";\n\nimport { getCharacterBefore } from \"../utils/get-character\";\nimport { getMatchRange } from \"../utils/get-match-range\";\nimport { isEmptyString } from \"../utils/is-empty-string\";\n\ninterface MarkFormatter {\n type: \"mark\";\n mark: keyof EditorMarks;\n character: string;\n}\n\ntype Formatter = MarkFormatter;\n\nconst formatters: Formatter[] = [\n {\n type: \"mark\",\n mark: \"bold\",\n character: \"*\",\n },\n {\n type: \"mark\",\n mark: \"italic\",\n character: \"_\",\n },\n {\n type: \"mark\",\n mark: \"strikethrough\",\n character: \"~\",\n },\n {\n type: \"mark\",\n mark: \"code\",\n character: \"`\",\n },\n];\nconst markFormattingCharacters = formatters\n .filter((formatter) => formatter.type === \"mark\")\n .map((formatter) => formatter.character);\n\nfunction formatMark<T extends SlateEditor>(\n editor: T,\n text: string,\n formatter: MarkFormatter\n): boolean {\n if (text !== formatter.character) {\n return false;\n }\n\n const match = getMatchRange(editor, editor.selection!, [formatter.character]);\n\n // Check if the match exists and is not empty\n if (!match || SlateRange.isCollapsed(match)) {\n return false;\n }\n\n const formattingCharacter = getCharacterBefore(editor, match);\n\n // Check if the match is preceded by the formatting character\n if (\n !formattingCharacter ||\n formattingCharacter.text !== formatter.character\n ) {\n return false;\n }\n\n const beforeCharacter = getCharacterBefore(editor, formattingCharacter.range);\n\n // Check if the formatting character is preceded by a non-whitespace character (or another formatting character)\n if (\n beforeCharacter &&\n !markFormattingCharacters.includes(beforeCharacter.text) &&\n !isEmptyString(beforeCharacter.text)\n ) {\n return false;\n }\n\n const matchText = SlateEditor.string(editor, match);\n\n // Check if the match has leading/trailing whitespace\n if (matchText.trim() !== matchText) {\n return false;\n }\n\n // Set the match to the expected mark\n SlateTransforms.select(editor, match);\n editor.addMark(formatter.mark, true);\n\n // Set the selection at the end of the match and reset formatting\n SlateTransforms.collapse(editor, { edge: \"end\" });\n editor.removeMark(formatter.mark);\n\n // Delete the formatting character\n SlateTransforms.delete(editor, {\n at: formattingCharacter.range,\n });\n\n return true;\n}\n\nexport function withAutoFormatting<T extends SlateEditor>(editor: T): T {\n const { insertText } = editor;\n\n editor.insertText = (text, options) => {\n if (!editor.selection || !SlateRange.isCollapsed(editor.selection)) {\n return insertText(text, options);\n }\n\n let shouldInsertText = true;\n\n for (const formatter of formatters) {\n if (formatter.type === \"mark\") {\n if (formatMark(editor, text, formatter)) {\n shouldInsertText = false;\n }\n }\n }\n\n if (shouldInsertText) {\n insertText(text, options);\n }\n };\n\n return editor;\n}\n"],"names":["SlateRange","SlateEditor","SlateTransforms"],"mappings":";;;;;AAmBA,MAAM,UAA0B,GAAA;AAAA,EAC9B;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,MAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AAAA,EACA;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,QAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AAAA,EACA;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,eAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AAAA,EACA;AAAA,IACE,IAAM,EAAA,MAAA;AAAA,IACN,IAAM,EAAA,MAAA;AAAA,IACN,SAAW,EAAA,GAAA;AAAA,GACb;AACF,CAAA,CAAA;AACA,MAAM,wBAA2B,GAAA,UAAA,CAC9B,MAAO,CAAA,CAAC,SAAc,KAAA,SAAA,CAAU,IAAS,KAAA,MAAM,CAC/C,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,UAAU,SAAS,CAAA,CAAA;AAEzC,SAAS,UAAA,CACP,MACA,EAAA,IAAA,EACA,SACS,EAAA;AACT,EAAI,IAAA,IAAA,KAAS,UAAU,SAAW,EAAA;AAChC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAM,MAAA,KAAA,GAAQ,cAAc,MAAQ,EAAA,MAAA,CAAO,WAAY,CAAC,SAAA,CAAU,SAAS,CAAC,CAAA,CAAA;AAG5E,EAAA,IAAI,CAAC,KAAA,IAASA,KAAW,CAAA,WAAA,CAAY,KAAK,CAA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A;AAEvB,EAAO,MAAA,CAAA,UAAA,GAAa,CAAC,IAAA,EAAM,OAAY,KAAA;AACrC,IAAI,IAAA,CAAC,OAAO,SAAa,IAAA,CAACF,MAAW,WAAY,CAAA,MAAA,CAAO,SAAS,CAAG,EAAA;AAClE,MAAO,OAAA,UAAA,CAAW,MAAM,OAAO,CAAA,CAAA;AAAA,KACjC;AAEA,IAAA,IAAI,gBAAmB,GAAA,IAAA,CAAA;AAEvB,IAAA,KAAA,MAAW,aAAa,UAAY,EAAA;AAClC,MAAI,IAAA,SAAA,CAAU,SAAS,MAAQ,EAAA;AAC7B,QAAA,IAAI,UAAW,CAAA,MAAA,EAAQ,IAAM,EAAA,SAAS,CAAG,EAAA;AACvC,UAAmB,gBAAA,GAAA,KAAA,CAAA;AAAA,SACrB;AAAA,OACF;AAAA,KACF;AAEA,IAAA,IAAI,gBAAkB,EAAA;AACpB,MAAA,UAAA,CAAW,MAAM,OAAO,CAAA,CAAA;AAAA,KAC1B;AAAA,GACF,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-links.cjs","sources":["../../../src/slate/plugins/auto-links.ts"],"sourcesContent":["import type { NodeEntry, Text } from \"slate\";\nimport { Editor, Element, Node, Path, Range, Transforms } from \"slate\";\n\nimport type { ComposerBodyAutoLink } from \"../../types\";\nimport { isPlainText, isText } from \"../utils/is-text\";\nimport { filterActiveMarks } from \"../utils/marks\";\nimport { isComposerBodyCustomLink } from \"./custom-links\";\n\n/**\n * This implementation is inspired by Lexical's AutoLink plugin.\n * Additional modifications and features were added to adapt it to our specific needs.\n *\n * Original Lexical AutoLink plugin can be found at [Lexical's Github Repository](https://github.com/facebook/lexical/blob/main/packages/lexical-react/src/LexicalAutoLinkPlugin.ts)\n */\nexport function withAutoLinks(editor: Editor): Editor {\n const { isInline, normalizeNode, deleteBackward } = editor;\n\n editor.isInline = (element) => {\n return element.type === \"auto-link\" ? true : isInline(element);\n };\n\n editor.normalizeNode = (entry) => {\n const [node, path] = entry;\n\n // Prevent auto links from being created inside custom links\n if (isComposerBodyCustomLink(node)) {\n return;\n }\n\n if (isText(node)) {\n const parentNode = Node.parent(editor, path);\n\n // Prevent auto links from being created inside custom links\n if (isComposerBodyCustomLink(parentNode)) {\n return;\n } else if (isComposerBodyAutoLink(parentNode)) {\n const parentPath = Path.parent(path);\n handleLinkEdit(editor, [parentNode, parentPath]);\n\n // Prevent rich text within auto links by removing all marks of inner text nodes\n if (!isPlainText(node)) {\n const marks = filterActiveMarks(node);\n\n Transforms.unsetNodes(editor, marks, { at: path });\n }\n } else {\n handleLinkCreate(editor, [node, path]);\n handleNeighbours(editor, [node, path]);\n }\n }\n\n normalizeNode(entry);\n };\n\n editor.deleteBackward = (unit) => {\n deleteBackward(unit);\n const { selection } = editor;\n if (!selection) return;\n\n if (!Range.isCollapsed(selection)) return;\n\n const [match] = Editor.nodes(editor, {\n at: selection,\n match: isComposerBodyAutoLink,\n mode: \"lowest\",\n });\n\n if (!match) return;\n\n Transforms.unwrapNodes(editor, {\n match: isComposerBodyAutoLink,\n });\n };\n\n return editor;\n}\n\nexport function isComposerBodyAutoLink(\n node: Node\n): node is ComposerBodyAutoLink {\n return Element.isElement(node) && node.type === \"auto-link\";\n}\n\n/**\n * 1. ((https?:\\/\\/(www\\.)?)|(www\\.))\n * - Matches 'http://' or 'https://' optionally followed by 'www.', or just 'www.'\n *\n * 2. [-a-zA-Z0-9@:%._+~#=]{1,256}\n * - Matches any character in the set [-a-zA-Z0-9@:%._+~#=] between 1 and 256 times, often found in the domain and subdomain part of the URL\n *\n * 3. \\.[a-zA-Z0-9()]{1,6}\n * - Matches a period followed by any character in the set [a-zA-Z0-9()] between 1 and 6 times, usually indicating the domain extension like .com, .org, etc.\n *\n * 4. \\b\n * - Represents a word boundary, ensuring that the characters following cannot be part of a different word\n *\n * 5. ([-a-zA-Z0-9().@:%_+~#?&//=]*)\n * - Matches any character in the set [-a-zA-Z0-9().@:%_+~#?&//=] between 0 and unlimited times, often found in the path, query parameters, or anchor part of the URL\n *\n * Matching URLs:\n * - http://www.example.com\n * - https://www.example.com\n * - www.example.com\n * - https://example.com/path?query=param#anchor\n *\n * Non-Matching URLs:\n * - http:/example.com (malformed scheme)\n * - example (missing scheme and domain extension)\n * - ftp://example.com (ftp scheme is not supported)\n * - example.com (missing scheme)\n */\nconst URL_REGEX =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9().@:%_+~#?&//=]*)/;\n\nconst PUNCTUATION_OR_SPACE = /[.,;!?\\s()]/;\n\nconst PERIOD_OR_QUESTION_MARK_FOLLOWED_BY_ALPHANUMERIC = /^[.?][a-zA-Z0-9]+/;\n\nconst PARENTHESES = /[()]/;\n\n/**\n * Helper function to check if a character is a separator (punctuation or space)\n * @param char The character to check\n * @returns Whether the character is a separator or not\n */\nfunction isSeparator(char: string): boolean {\n return PUNCTUATION_OR_SPACE.test(char);\n}\n\n/**\n * Helper function to check if a text content ends with a separator (punctuation or space)\n * @param textContent The text content to check\n * @returns Whether the text content ends with a separator or not\n */\nfunction endsWithSeparator(textContent: string): boolean {\n const lastCharacter = textContent[textContent.length - 1];\n\n return lastCharacter !== undefined ? isSeparator(lastCharacter) : false;\n}\n\n/**\n * Helper function to check if a text content starts with a separator (punctuation or space)\n * @param textContent The text content to check\n * @returns Whether the text content starts with a separator or not\n */\nfunction startsWithSeparator(textContent: string): boolean {\n const firstCharacter = textContent[0];\n\n return firstCharacter !== undefined ? isSeparator(firstCharacter) : false;\n}\n\n/**\n * Helper function to check if a text content ends with a period or question mark\n * @param textContent The text content to check\n * @returns Whether the text content ends with a period or not\n */\nfunction endsWithPeriodOrQuestionMark(textContent: string): boolean {\n return (\n textContent[textContent.length - 1] === \".\" ||\n textContent[textContent.length - 1] === \"?\"\n );\n}\n\n/**\n * Helper function to get the \"logical length\" of a URL, taking into account things like opening/closing parentheses\n * @param url The URL to check\n * @returns The \"logical length\" of the URL\n */\nfunction getUrlLogicalLength(url: string): number {\n if (!PARENTHESES.test(url)) {\n return url.length;\n }\n\n let logicalLength = 0;\n let parenthesesCount = 0;\n\n for (const character of url) {\n if (character === \"(\") {\n parenthesesCount++;\n }\n\n if (character === \")\") {\n parenthesesCount--;\n\n if (parenthesesCount < 0) {\n break;\n }\n }\n\n logicalLength++;\n }\n\n return logicalLength;\n}\n\n/**\n * Helper function to check if the previous node is valid (text node that ends with a separator or is empty)\n */\nfunction isPreviousNodeValid(editor: Editor, path: Path): boolean {\n const entry = Editor.previous(editor, { at: path });\n if (!entry) return true;\n\n return (\n isText(entry[0]) &&\n (endsWithSeparator(entry[0].text) || entry[0].text === \"\")\n );\n}\n\n/**\n * Helper function to check if the next node is valid (text node that starts with a separator or is empty)\n */\nfunction isNextNodeValid(editor: Editor, path: Path): boolean {\n const entry = Editor.next(editor, { at: path });\n if (!entry) return true;\n\n return (\n isText(entry[0]) &&\n (startsWithSeparator(entry[0].text) || entry[0].text === \"\")\n );\n}\n\n/**\n * Helper function to check if the content around a text node is valid.\n * @param editor\n * @param entry\n * @param start\n * @param end\n * @returns\n */\nfunction isContentAroundValid(\n editor: Editor,\n entry: NodeEntry<Text>,\n start: number,\n end: number\n): boolean {\n const [node, path] = entry;\n const text = node.text;\n\n const contentBefore = text[start - 1];\n const contentBeforeIsValid =\n start > 0 && contentBefore\n ? isSeparator(contentBefore)\n : isPreviousNodeValid(editor, path);\n\n const contentAfter = text[end];\n const contentAfterIsValid =\n end < text.length && contentAfter\n ? isSeparator(contentAfter)\n : isNextNodeValid(editor, path);\n\n return contentBeforeIsValid && contentAfterIsValid;\n}\n\nconst handleLinkEdit = (\n editor: Editor,\n entry: NodeEntry<ComposerBodyAutoLink>\n) => {\n const [node, path] = entry;\n\n // Step 1: Ensure that the Link node only contains text nodes as children\n const children = Node.children(editor, path);\n for (const [child] of children) {\n if (isText(child)) continue;\n Transforms.unwrapNodes(editor, { at: path });\n return;\n }\n // Attempt to match the text content (of the Link node) against the URL regex\n const text = Node.string(node);\n const match = URL_REGEX.exec(text);\n const matchContent = match?.[0];\n\n // Step 2: Ensure that the text content of the Link node matches the URL regex and is identical to the match\n if (!match || matchContent !== text) {\n Transforms.unwrapNodes(editor, { at: path });\n return;\n }\n\n // Step 3: Ensure that if the text content of the Link node ends with a period, we unwrap the Link node and wrap the text before the period in a new Link node\n if (endsWithPeriodOrQuestionMark(text)) {\n Transforms.unwrapNodes(editor, { at: path });\n\n const textBeforePeriod = text.slice(0, text.length - 1);\n\n // Remove the last character from the link text and wrap the remaining text in a new link node\n Transforms.wrapNodes<ComposerBodyAutoLink>(\n editor,\n {\n type: \"auto-link\",\n url: textBeforePeriod,\n children: [],\n },\n {\n at: {\n anchor: { path, offset: 0 },\n focus: { path, offset: textBeforePeriod.length },\n },\n split: true,\n }\n );\n return;\n }\n\n // Step 4: Allow some conditions to shorten the URL (e.g. supporting parentheses but only if they are balanced)\n const logicalLength = getUrlLogicalLength(text);\n\n if (logicalLength < text.length) {\n Transforms.unwrapNodes(editor, { at: path });\n\n const logicalText = text.slice(0, logicalLength);\n\n // Keep the \"logical\" text and wrap it in a new link node\n Transforms.wrapNodes<ComposerBodyAutoLink>(\n editor,\n {\n type: \"auto-link\",\n url: logicalText,\n children: [],\n },\n {\n at: {\n anchor: { path, offset: 0 },\n focus: { path, offset: logicalText.length },\n },\n split: true,\n }\n );\n return;\n }\n\n // Step 5: Ensure that the text content of the Link node is surrounded by separators or the start/end of the text content\n if (!isPreviousNodeValid(editor, path) || !isNextNodeValid(editor, path)) {\n Transforms.unwrapNodes(editor, { at: path });\n return;\n }\n\n // Step 6: Ensure that the url attribute of the Link node is identical to its text content\n if (node.url !== text) {\n Transforms.setNodes(editor, { url: matchContent }, { at: path });\n return;\n }\n};\n\nconst handleLinkCreate = (editor: Editor, entry: NodeEntry<Text>) => {\n const [node, path] = entry;\n\n // Step 1: Ensure that the text content of the node matches the URL regex\n const match = URL_REGEX.exec(node.text);\n const matchContent = match?.[0];\n\n if (!match || matchContent === undefined) {\n return;\n }\n\n const start = match.index;\n const end = start + matchContent.length;\n\n // Step 2: Ensure that the content around the node is valid\n if (!isContentAroundValid(editor, entry, start, end)) return;\n\n Transforms.wrapNodes<ComposerBodyAutoLink>(\n editor,\n {\n type: \"auto-link\",\n url: matchContent,\n children: [],\n },\n {\n at: {\n anchor: { path, offset: start },\n focus: { path, offset: end },\n },\n split: true,\n }\n );\n return;\n};\n\nconst handleNeighbours = (editor: Editor, entry: NodeEntry<Text>) => {\n const [node, path] = entry;\n const text = node.text;\n\n const previousSibling = Editor.previous(editor, { at: path });\n\n if (previousSibling && isComposerBodyAutoLink(previousSibling[0])) {\n if (PERIOD_OR_QUESTION_MARK_FOLLOWED_BY_ALPHANUMERIC.test(text)) {\n Transforms.unwrapNodes(editor, { at: previousSibling[1] });\n Transforms.mergeNodes(editor, { at: path });\n return;\n }\n\n if (!startsWithSeparator(text)) {\n Transforms.unwrapNodes(editor, { at: previousSibling[1] });\n return;\n }\n }\n\n const nextSibling = Editor.next(editor, { at: path });\n if (\n nextSibling &&\n isComposerBodyAutoLink(nextSibling[0]) &&\n !endsWithSeparator(text)\n ) {\n Transforms.unwrapNodes(editor, { at: nextSibling[1] });\n return;\n }\n};\n"],"names":["isComposerBodyCustomLink","isText","Node","Path","isPlainText","marks","filterActiveMarks","Transforms","Range","Editor","Element"],"mappings":";;;;;;;AAcO,SAAS,cAAc,MAAwB,EAAA;AACpD,EAAA,MAAM,EAAE,QAAA,EAAU,aAAe,EAAA,cAAA,EAAmB,GAAA,MAAA,CAAA;AAEpD,EAAO,MAAA,CAAA,QAAA,GAAW,CAAC,OAAY,KAAA;AAC7B,IAAA,OAAO,OAAQ,CAAA,IAAA,KAAS,WAAc,GAAA,IAAA,GAAO,SAAS,OAAO,CAAA,CAAA;AAAA,GAC/D,CAAA;AAEA,EAAO,MAAA,CAAA,aAAA,GA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,CAAA,QAAA,CAAS,QAAQ,EAAE,EAAA,EAAI,MAAM,CAAA,CAAA;AAE5D,EAAA,IAAI,eAAmB,IAAA,sBAAA,CAAuB,eAAgB,CAAA,CAAA,CAAE,CAAG,EAAA;AACjE,IAAI,IAAA,gDAAA,CAAiD,IAAK,CAAA,IAAI,CAAG,EAAA;AAC/D,MAAAF,gBAAA,CAAW,YAAY,MAAQ,EAAA,EAAE,EAAI,EAAA,eAAA,CAAgB,IAAI,CAAA,CAAA;AACzD,MAAAA,gBAAA,CAAW,UAAW,CAAA,MAAA,EAAQ,EAAE,EAAA,EAAI,MAAM,CAAA,CAAA;AAC1C,MAAA,OAAA;AAAA,KACF;AAEA,IAAI,IAAA,CAAC,mBAAoB,CAAA,IAAI,CAAG,EAAA;AAC9B,MAAAA,gBAAA,CAAW,YAAY,MAAQ,EAAA,EAAE,EAAI,EAAA,eAAA,CAAgB,IAAI,CAAA,CAAA;AACzD,MAAA,OAAA;AAAA,KACF;AAAA,GACF;AAEA,EAAA,MAAM,cAAcE,YAAO,CAAA,IAAA,CAAK,QAAQ,EAAE,EAAA,EAAI,MAAM,CAAA,CAAA;AACpD,EACE,IAAA,WAAA,IACA,uBAAuB,WAAY,CAAA,CAAA,CAAE,KACrC,CAAC,iBAAA,CAAkB,IAAI,CACvB,EAAA;AACA,IAAAF,gBAAA,CAAW,YAAY,MAAQ,EAAA,EAAE,EAAI,EAAA,WAAA,CAAY,IAAI,CAAA,CAAA;AACrD,IAAA,OAAA;AAAA,GACF;AACF,CAAA;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-links.js","sources":["../../../src/slate/plugins/auto-links.ts"],"sourcesContent":["import type { NodeEntry, Text } from \"slate\";\nimport { Editor, Element, Node, Path, Range, Transforms } from \"slate\";\n\nimport type { ComposerBodyAutoLink } from \"../../types\";\nimport { isPlainText, isText } from \"../utils/is-text\";\nimport { filterActiveMarks } from \"../utils/marks\";\nimport { isComposerBodyCustomLink } from \"./custom-links\";\n\n/**\n * This implementation is inspired by Lexical's AutoLink plugin.\n * Additional modifications and features were added to adapt it to our specific needs.\n *\n * Original Lexical AutoLink plugin can be found at [Lexical's Github Repository](https://github.com/facebook/lexical/blob/main/packages/lexical-react/src/LexicalAutoLinkPlugin.ts)\n */\nexport function withAutoLinks(editor: Editor): Editor {\n const { isInline, normalizeNode, deleteBackward } = editor;\n\n editor.isInline = (element) => {\n return element.type === \"auto-link\" ? true : isInline(element);\n };\n\n editor.normalizeNode = (entry) => {\n const [node, path] = entry;\n\n // Prevent auto links from being created inside custom links\n if (isComposerBodyCustomLink(node)) {\n return;\n }\n\n if (isText(node)) {\n const parentNode = Node.parent(editor, path);\n\n // Prevent auto links from being created inside custom links\n if (isComposerBodyCustomLink(parentNode)) {\n return;\n } else if (isComposerBodyAutoLink(parentNode)) {\n const parentPath = Path.parent(path);\n handleLinkEdit(editor, [parentNode, parentPath]);\n\n // Prevent rich text within auto links by removing all marks of inner text nodes\n if (!isPlainText(node)) {\n const marks = filterActiveMarks(node);\n\n Transforms.unsetNodes(editor, marks, { at: path });\n }\n } else {\n handleLinkCreate(editor, [node, path]);\n handleNeighbours(editor, [node, path]);\n }\n }\n\n normalizeNode(entry);\n };\n\n editor.deleteBackward = (unit) => {\n deleteBackward(unit);\n const { selection } = editor;\n if (!selection) return;\n\n if (!Range.isCollapsed(selection)) return;\n\n const [match] = Editor.nodes(editor, {\n at: selection,\n match: isComposerBodyAutoLink,\n mode: \"lowest\",\n });\n\n if (!match) return;\n\n Transforms.unwrapNodes(editor, {\n match: isComposerBodyAutoLink,\n });\n };\n\n return editor;\n}\n\nexport function isComposerBodyAutoLink(\n node: Node\n): node is ComposerBodyAutoLink {\n return Element.isElement(node) && node.type === \"auto-link\";\n}\n\n/**\n * 1. ((https?:\\/\\/(www\\.)?)|(www\\.))\n * - Matches 'http://' or 'https://' optionally followed by 'www.', or just 'www.'\n *\n * 2. [-a-zA-Z0-9@:%._+~#=]{1,256}\n * - Matches any character in the set [-a-zA-Z0-9@:%._+~#=] between 1 and 256 times, often found in the domain and subdomain part of the URL\n *\n * 3. \\.[a-zA-Z0-9()]{1,6}\n * - Matches a period followed by any character in the set [a-zA-Z0-9()] between 1 and 6 times, usually indicating the domain extension like .com, .org, etc.\n *\n * 4. \\b\n * - Represents a word boundary, ensuring that the characters following cannot be part of a different word\n *\n * 5. ([-a-zA-Z0-9().@:%_+~#?&//=]*)\n * - Matches any character in the set [-a-zA-Z0-9().@:%_+~#?&//=] between 0 and unlimited times, often found in the path, query parameters, or anchor part of the URL\n *\n * Matching URLs:\n * - http://www.example.com\n * - https://www.example.com\n * - www.example.com\n * - https://example.com/path?query=param#anchor\n *\n * Non-Matching URLs:\n * - http:/example.com (malformed scheme)\n * - example (missing scheme and domain extension)\n * - ftp://example.com (ftp scheme is not supported)\n * - example.com (missing scheme)\n */\nconst URL_REGEX =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9().@:%_+~#?&//=]*)/;\n\nconst PUNCTUATION_OR_SPACE = /[.,;!?\\s()]/;\n\nconst PERIOD_OR_QUESTION_MARK_FOLLOWED_BY_ALPHANUMERIC = /^[.?][a-zA-Z0-9]+/;\n\nconst PARENTHESES = /[()]/;\n\n/**\n * Helper function to check if a character is a separator (punctuation or space)\n * @param char The character to check\n * @returns Whether the character is a separator or not\n */\nfunction isSeparator(char: string): boolean {\n return PUNCTUATION_OR_SPACE.test(char);\n}\n\n/**\n * Helper function to check if a text content ends with a separator (punctuation or space)\n * @param textContent The text content to check\n * @returns Whether the text content ends with a separator or not\n */\nfunction endsWithSeparator(textContent: string): boolean {\n const lastCharacter = textContent[textContent.length - 1];\n\n return lastCharacter !== undefined ? isSeparator(lastCharacter) : false;\n}\n\n/**\n * Helper function to check if a text content starts with a separator (punctuation or space)\n * @param textContent The text content to check\n * @returns Whether the text content starts with a separator or not\n */\nfunction startsWithSeparator(textContent: string): boolean {\n const firstCharacter = textContent[0];\n\n return firstCharacter !== undefined ? isSeparator(firstCharacter) : false;\n}\n\n/**\n * Helper function to check if a text content ends with a period or question mark\n * @param textContent The text content to check\n * @returns Whether the text content ends with a period or not\n */\nfunction endsWithPeriodOrQuestionMark(textContent: string): boolean {\n return (\n textContent[textContent.length - 1] === \".\" ||\n textContent[textContent.length - 1] === \"?\"\n );\n}\n\n/**\n * Helper function to get the \"logical length\" of a URL, taking into account things like opening/closing parentheses\n * @param url The URL to check\n * @returns The \"logical length\" of the URL\n */\nfunction getUrlLogicalLength(url: string): number {\n if (!PARENTHESES.test(url)) {\n return url.length;\n }\n\n let logicalLength = 0;\n let parenthesesCount = 0;\n\n for (const character of url) {\n if (character === \"(\") {\n parenthesesCount++;\n }\n\n if (character === \")\") {\n parenthesesCount--;\n\n if (parenthesesCount < 0) {\n break;\n }\n }\n\n logicalLength++;\n }\n\n return logicalLength;\n}\n\n/**\n * Helper function to check if the previous node is valid (text node that ends with a separator or is empty)\n */\nfunction isPreviousNodeValid(editor: Editor, path: Path): boolean {\n const entry = Editor.previous(editor, { at: path });\n if (!entry) return true;\n\n return (\n isText(entry[0]) &&\n (endsWithSeparator(entry[0].text) || entry[0].text === \"\")\n );\n}\n\n/**\n * Helper function to check if the next node is valid (text node that starts with a separator or is empty)\n */\nfunction isNextNodeValid(editor: Editor, path: Path): boolean {\n const entry = Editor.next(editor, { at: path });\n if (!entry) return true;\n\n return (\n isText(entry[0]) &&\n (startsWithSeparator(entry[0].text) || entry[0].text === \"\")\n );\n}\n\n/**\n * Helper function to check if the content around a text node is valid.\n * @param editor\n * @param entry\n * @param start\n * @param end\n * @returns\n */\nfunction isContentAroundValid(\n editor: Editor,\n entry: NodeEntry<Text>,\n start: number,\n end: number\n): boolean {\n const [node, path] = entry;\n const text = node.text;\n\n const contentBefore = text[start - 1];\n const contentBeforeIsValid =\n start > 0 && contentBefore\n ? isSeparator(contentBefore)\n : isPreviousNodeValid(editor, path);\n\n const contentAfter = text[end];\n const contentAfterIsValid =\n end < text.length && contentAfter\n ? isSeparator(contentAfter)\n : isNextNodeValid(editor, path);\n\n return contentBeforeIsValid && contentAfterIsValid;\n}\n\nconst handleLinkEdit = (\n editor: Editor,\n entry: NodeEntry<ComposerBodyAutoLink>\n) => {\n const [node, path] = entry;\n\n // Step 1: Ensure that the Link node only contains text nodes as children\n const children = Node.children(editor, path);\n for (const [child] of children) {\n if (isText(child)) continue;\n Transforms.unwrapNodes(editor, { at: path });\n return;\n }\n // Attempt to match the text content (of the Link node) against the URL regex\n const text = Node.string(node);\n const match = URL_REGEX.exec(text);\n const matchContent = match?.[0];\n\n // Step 2: Ensure that the text content of the Link node matches the URL regex and is identical to the match\n if (!match || matchContent !== text) {\n Transforms.unwrapNodes(editor, { at: path });\n return;\n }\n\n // Step 3: Ensure that if the text content of the Link node ends with a period, we unwrap the Link node and wrap the text before the period in a new Link node\n if (endsWithPeriodOrQuestionMark(text)) {\n Transforms.unwrapNodes(editor, { at: path });\n\n const textBeforePeriod = text.slice(0, text.length - 1);\n\n // Remove the last character from the link text and wrap the remaining text in a new link node\n Transforms.wrapNodes<ComposerBodyAutoLink>(\n editor,\n {\n type: \"auto-link\",\n url: textBeforePeriod,\n children: [],\n },\n {\n at: {\n anchor: { path, offset: 0 },\n focus: { path, offset: textBeforePeriod.length },\n },\n split: true,\n }\n );\n return;\n }\n\n // Step 4: Allow some conditions to shorten the URL (e.g. supporting parentheses but only if they are balanced)\n const logicalLength = getUrlLogicalLength(text);\n\n if (logicalLength < text.length) {\n Transforms.unwrapNodes(editor, { at: path });\n\n const logicalText = text.slice(0, logicalLength);\n\n // Keep the \"logical\" text and wrap it in a new link node\n Transforms.wrapNodes<ComposerBodyAutoLink>(\n editor,\n {\n type: \"auto-link\",\n url: logicalText,\n children: [],\n },\n {\n at: {\n anchor: { path, offset: 0 },\n focus: { path, offset: logicalText.length },\n },\n split: true,\n }\n );\n return;\n }\n\n // Step 5: Ensure that the text content of the Link node is surrounded by separators or the start/end of the text content\n if (!isPreviousNodeValid(editor, path) || !isNextNodeValid(editor, path)) {\n Transforms.unwrapNodes(editor, { at: path });\n return;\n }\n\n // Step 6: Ensure that the url attribute of the Link node is identical to its text content\n if (node.url !== text) {\n Transforms.setNodes(editor, { url: matchContent }, { at: path });\n return;\n }\n};\n\nconst handleLinkCreate = (editor: Editor, entry: NodeEntry<Text>) => {\n const [node, path] = entry;\n\n // Step 1: Ensure that the text content of the node matches the URL regex\n const match = URL_REGEX.exec(node.text);\n const matchContent = match?.[0];\n\n if (!match || matchContent === undefined) {\n return;\n }\n\n const start = match.index;\n const end = start + matchContent.length;\n\n // Step 2: Ensure that the content around the node is valid\n if (!isContentAroundValid(editor, entry, start, end)) return;\n\n Transforms.wrapNodes<ComposerBodyAutoLink>(\n editor,\n {\n type: \"auto-link\",\n url: matchContent,\n children: [],\n },\n {\n at: {\n anchor: { path, offset: start },\n focus: { path, offset: end },\n },\n split: true,\n }\n );\n return;\n};\n\nconst handleNeighbours = (editor: Editor, entry: NodeEntry<Text>) => {\n const [node, path] = entry;\n const text = node.text;\n\n const previousSibling = Editor.previous(editor, { at: path });\n\n if (previousSibling && isComposerBodyAutoLink(previousSibling[0])) {\n if (PERIOD_OR_QUESTION_MARK_FOLLOWED_BY_ALPHANUMERIC.test(text)) {\n Transforms.unwrapNodes(editor, { at: previousSibling[1] });\n Transforms.mergeNodes(editor, { at: path });\n return;\n }\n\n if (!startsWithSeparator(text)) {\n Transforms.unwrapNodes(editor, { at: previousSibling[1] });\n return;\n }\n }\n\n const nextSibling = Editor.next(editor, { at: path });\n if (\n nextSibling &&\n isComposerBodyAutoLink(nextSibling[0]) &&\n !endsWithSeparator(text)\n ) {\n Transforms.unwrapNodes(editor, { at: nextSibling[1] });\n return;\n }\n};\n"],"names":[],"mappings":";;;;;AAcO,SAAS,cAAc,MAAwB,EAAA;AACpD,EAAA,MAAM,EAAE,QAAA,EAAU,aAAe,EAAA,cAAA,EAAmB,GAA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{ Element, Node, Range, Transforms } from \"slate\";\n\nimport type { ComposerBodyCustomLink } from \"../../types\";\nimport { isPlainText, isText } from \"../utils/is-text\";\nimport { filterActiveMarks } from \"../utils/marks\";\nimport { selectionContainsInlines } from \"../utils/selection-contains-inlines\";\n\nfunction isUrl(string: string) {\n try {\n new URL(string);\n return true;\n } catch (_) {\n return false;\n }\n}\n\nexport function withCustomLinks(editor: Editor): Editor {\n const { isInline, normalizeNode, insertData } = editor;\n\n editor.isInline = (element) => {\n return element.type === \"custom-link\" ? true : isInline(element);\n };\n\n editor.normalizeNode = (entry) => {\n const [node, path] = entry;\n\n if (isText(node)) {\n const parentNode = Node.parent(editor, path);\n\n // Prevent rich text within custom links by removing all marks of inner text nodes\n if (isComposerBodyCustomLink(parentNode)) {\n if (!isPlainText(node)) {\n const marks = filterActiveMarks(node);\n\n Transforms.unsetNodes(editor, marks, { at: path });\n }\n }\n }\n\n normalizeNode(entry);\n };\n\n // Create custom links when pasting URLs while some text is selected\n editor.insertData = (data) => {\n const { selection } = editor;\n const pastedText = data.getData(\"text/plain\");\n\n // Keep track of whether the default behavior should be invoked\n // This allows us to sequence multiple conditions in a performant way,\n // ordering them by likelihood/cost and stopping early whenever possible\n let shouldInvokeDefaultBehavior = true;\n\n // Check if the selection is a range\n if (selection && !Range.isCollapsed(selection)) {\n // Check if the selection is contained in a single block\n if (selection.anchor.path[0] === selection.focus.path[0]) {\n // Check if the pasted text is a valid URL\n if (isUrl(pastedText)) {\n // Check if the selection only contains (rich and/or plain) text nodes\n if (!selectionContainsInlines(editor, (node) => !isText(node))) {\n // If all conditions are met, wrap the selected nodes in a custom link\n Transforms.wrapNodes<ComposerBodyCustomLink>(\n editor,\n {\n type: \"custom-link\",\n url: pastedText,\n children: [],\n },\n {\n at: selection,\n split: true,\n match: isPlainText,\n }\n );\n shouldInvokeDefaultBehavior = false;\n }\n }\n }\n }\n\n if (shouldInvokeDefaultBehavior) {\n insertData(data);\n }\n };\n\n return editor;\n}\n\nexport function isComposerBodyCustomLink(\n node: Node\n): node is ComposerBodyCustomLink {\n return Element.isElement(node) && node.type === \"custom-link\";\n}\n"],"names":["isText","Node","isPlainText","marks","filterActiveMarks","Transforms","Range","selectionContainsInlines","Element"],"mappings":";;;;;;;AAQA,SAAS,MAAM,MAAgB,EAAA;AAC7B,EAAI,IAAA;AACF,IAAA,IAAI,IAAI,MAAM,CAAA,CAAA;AACd,IAAO,OAAA,IAAA,CAAA;AAAA,WACA,CAAP,EAAA;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA;AAEO,SAAS,gBAAgB,MAAwB,EAAA;AACtD,EAAA,MAAM,EAAE,QAAA,EAAU,aAAe,EAAA,UAAA,EAAe,GAAA,MAAA,CAAA;AAEhD,EAAO,MAAA,CAAA,QAAA,GAAW,CAAC,OAAY,KAAA;AAC7B,IAAA,OAAO,OAAQ,CAAA,IAAA,KAAS,aAAgB,GAAA,IAAA,GAAO,SAAS,OAAO,CAAA,CAAA;AAAA,GACjE,CAAA;AAEA,EAAO,MAAA,CAAA,aAAA,GAAgB,CAAC,KAAU,KAAA;AAChC,IAAM,MAAA,CAAC,IAAM,EAAA,IAAI,CAAI,GAAA,KAAA,CAAA;AAErB,IAAI,IAAAA,aAAA,CAAO,IAAI,CAAG,EAAA;AAChB,MAAA,MAAM,UAAa,GAAAC,UAAA,CAAK,MAAO,CAAA,MAAA,EAAQ,IAAI,CAAA,CAAA;AAG3C,MAAI,IAAA,wBAAA,CAAyB,UAAU,CAAG,EAAA;AACxC,QAAI,IAAA,CAACC,kBAAY,CAAA,IAAI,CAAG,EAAA;AACtB,UAAM,MAAAC,OAAA,GAAQC,wBAAkB,IAAI,CAAA,CAAA;AAEpC,UAAAC,gBAAA,CAAW,WAAW,MAAQ,EAAAF,OAAA,EAAO,EAAE,EAAA,EAAI,MAAM,CAAA,CAAA;AAAA,SACnD;AAAA,OACF;AAAA,KACF;AAEA,IAAA,aAAA,CAAc,KAAK,CAAA,CAAA;AAAA,G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,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-links.js","sources":["../../../src/slate/plugins/custom-links.ts"],"sourcesContent":["import type { Editor } from \"slate\";\nimport { Element, Node, Range, Transforms } from \"slate\";\n\nimport type { ComposerBodyCustomLink } from \"../../types\";\nimport { isPlainText, isText } from \"../utils/is-text\";\nimport { filterActiveMarks } from \"../utils/marks\";\nimport { selectionContainsInlines } from \"../utils/selection-contains-inlines\";\n\nfunction isUrl(string: string) {\n try {\n new URL(string);\n return true;\n } catch (_) {\n return false;\n }\n}\n\nexport function withCustomLinks(editor: Editor): Editor {\n const { isInline, normalizeNode, insertData } = editor;\n\n editor.isInline = (element) => {\n return element.type === \"custom-link\" ? true : isInline(element);\n };\n\n editor.normalizeNode = (entry) => {\n const [node, path] = entry;\n\n if (isText(node)) {\n const parentNode = Node.parent(editor, path);\n\n // Prevent rich text within custom links by removing all marks of inner text nodes\n if (isComposerBodyCustomLink(parentNode)) {\n if (!isPlainText(node)) {\n const marks = filterActiveMarks(node);\n\n Transforms.unsetNodes(editor, marks, { at: path });\n }\n }\n }\n\n normalizeNode(entry);\n };\n\n // Create custom links when pasting URLs while some text is selected\n editor.insertData = (data) => {\n const { selection } = editor;\n const pastedText = data.getData(\"text/plain\");\n\n // Keep track of whether the default behavior should be invoked\n // This allows us to sequence multiple conditions in a performant way,\n // ordering them by likelihood/cost and stopping early whenever possible\n let shouldInvokeDefaultBehavior = true;\n\n // Check if the selection is a range\n if (selection && !Range.isCollapsed(selection)) {\n // Check if the selection is contained in a single block\n if (selection.anchor.path[0] === selection.focus.path[0]) {\n // Check if the pasted text is a valid URL\n if (isUrl(pastedText)) {\n // Check if the selection only contains (rich and/or plain) text nodes\n if (!selectionContainsInlines(editor, (node) => !isText(node))) {\n // If all conditions are met, wrap the selected nodes in a custom link\n Transforms.wrapNodes<ComposerBodyCustomLink>(\n editor,\n {\n type: \"custom-link\",\n url: pastedText,\n children: [],\n },\n {\n at: selection,\n split: true,\n match: isPlainText,\n }\n );\n shouldInvokeDefaultBehavior = false;\n }\n }\n }\n }\n\n if (shouldInvokeDefaultBehavior) {\n insertData(data);\n }\n };\n\n return editor;\n}\n\nexport function isComposerBodyCustomLink(\n node: Node\n): node is ComposerBodyCustomLink {\n return Element.isElement(node) && node.type === \"custom-link\";\n}\n"],"names":[],"mappings":";;;;;AAQA,SAAS,MAAM,MAAgB,EAAA;AAC7B,EAAI,IAAA;AACF,IAAA,IAAI,IAAI,MAAM,CAAA,CAAA;AACd,IAAO,OAAA,IAAA,CAAA;AAAA,WACA,CAAP,EAAA;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA;AAEO,SAAS,gBAAgB,MAAwB,EAAA;AACtD,EAAA,MAAM,EAAE,QAAA,EAAU,aAAe,EAAA,UAAA,EAAe,GAAA,MAAA,CAAA;AAEhD,EAAO,MAAA,CAAA,QAAA,GAAW,CAAC,OAAY,KAAA;AAC7B,IAAA,OAAO,OAAQ,CAAA,IAAA,KAAS,aAAgB,GAAA,IAAA,GAAO,SAAS,OAAO,CAAA,CAAA;AAAA,GACjE,CAAA;AAEA,EAAO,MAAA,CAAA,aAAA,GAAgB,CAAC,KAAU,KAAA;AAChC,IAAM,MAAA,CAAC,IAAM,EAAA,IAAI,CAAI,GAAA,KAAA,CAAA;AAErB,IAAI,IAAA,MAAA,CAAO,IAAI,CAAG,EAAA;AAChB,MAAA,MAAM,UAAa,GAAA,IAAA,CAAK,MAAO,CAAA,MAAA,EAAQ,IAAI,CAAA,CAAA;AAG3C,MAAI,IAAA,wBAAA,CAAyB,UAAU,CAAG,EAAA;AACxC,QAAI,IAAA,CAAC,WAAY,CAAA,IAAI,CAAG,EAAA;AACtB,UAAM,MAAA,KAAA,GAAQ,kBAAkB,IAAI,CAAA,CAAA;AAEpC,UAAA,UAAA,CAAW,WAAW,MAAQ,EAAA,KAAA,EAAO,EAAE,EAAA,EAAI,MAAM,CAAA,CAAA;AAAA,SACnD;AAAA,OACF;AAAA,KACF;AAEA,IAA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AAA;AAClD;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"empty-clear-formatting.cjs","sources":["../../../src/slate/plugins/empty-clear-formatting.ts"],"sourcesContent":["import type { Editor as SlateEditor } from \"slate\";\n\nimport { isEmpty } from \"../utils/is-empty\";\nimport { removeMarks } from \"../utils/marks\";\n\n// This plugins clears formatting on empty blocks\n// https://github.com/ianstormtaylor/slate/issues/2908\nexport function withEmptyClearFormatting<T extends SlateEditor>(editor: T): T {\n const { onChange } = editor;\n\n editor.onChange = (options) => {\n if (isEmpty(editor, editor.children)) {\n removeMarks(editor);\n }\n\n onChange(options);\n };\n\n return editor;\n}\n"],"names":["isEmpty","removeMarks"],"mappings":";;;;;AAOO,SAAS,yBAAgD,MAAc,EAAA;AAC5E,EAAM,MAAA,EAAE,UAAa,GAAA,MAAA,CAAA;AAErB,EAAO,MAAA,CAAA,QAAA,GAAW,CAAC,OAAY,KAAA;AAC7B,IAAA,IAAIA,eAAQ,CAAA,MAAA,EAAQ,MAAO,CAAA,QAAQ,CAAG,EAAA;AACpC,MAAAC,iBAAA,CAAY,MAAM,CAAA,CAAA;AAAA,KACpB;AAEA,IAAA,QAAA,CAAS,OAAO,CAAA,CAAA;AAAA,GAClB,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"empty-clear-formatting.js","sources":["../../../src/slate/plugins/empty-clear-formatting.ts"],"sourcesContent":["import type { Editor as SlateEditor } from \"slate\";\n\nimport { isEmpty } from \"../utils/is-empty\";\nimport { removeMarks } from \"../utils/marks\";\n\n// This plugins clears formatting on empty blocks\n// https://github.com/ianstormtaylor/slate/issues/2908\nexport function withEmptyClearFormatting<T extends SlateEditor>(editor: T): T {\n const { onChange } = editor;\n\n editor.onChange = (options) => {\n if (isEmpty(editor, editor.children)) {\n removeMarks(editor);\n }\n\n onChange(options);\n };\n\n return editor;\n}\n"],"names":[],"mappings":";;;AAOO,SAAS,yBAAgD,MAAc,EAAA;AAC5E,EAAM,MAAA,EAAE,UAAa,GAAA,MAAA,CAAA;AAErB,EAAO,MAAA,CAAA,QAAA,GAAW,CAAC,OAAY,KAAA;AAC7B,IAAA,IAAI,OAAQ,CAAA,MAAA,EAAQ,MAAO,CAAA,QAAQ,CAAG,EAAA;AACpC,MAAA,WAAA,CAAY,MAAM,CAAA,CAAA;AAAA,KACpB;AAEA,IAAA,QAAA,CAAS,OAAO,CAAA,CAAA;AAAA,GAClB,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mentions.cjs","sources":["../../../src/slate/plugins/mentions.ts"],"sourcesContent":["import type { Node as SlateNode } from \"slate\";\nimport {\n Editor as SlateEditor,\n Element as SlateElement,\n Range as SlateRange,\n Transforms as SlateTransforms,\n} from \"slate\";\n\nimport type { ComposerBodyMention } from \"../../types\";\nimport { getCharacterAfter, getCharacterBefore } from \"../utils/get-character\";\nimport { getMatchRange } from \"../utils/get-match-range\";\nimport { isEmptyString } from \"../utils/is-empty-string\";\nimport { isWhitespaceCharacter } from \"../utils/is-whitespace-character\";\n\nexport const MENTION_CHARACTER = \"@\";\n\nexport type MentionDraft = {\n range: SlateRange;\n text: string;\n};\n\nexport function getMentionDraftAtSelection(\n editor: SlateEditor\n): MentionDraft | undefined {\n const { selection } = editor;\n\n if (!selection || !SlateRange.isCollapsed(selection)) {\n return;\n }\n\n // Walk backwards from the selection until \"@\" is found, unless the character\n // before isn't whitespace (or \"@\" is the block's first character)\n const match = getMatchRange(editor, selection, [\"@\"], {\n include: true,\n allowConsecutiveWhitespace: false,\n ignoreTerminator: (_, point) => {\n const characterBefore = getCharacterBefore(editor, point);\n\n // Ignore \"@\" if it's preceded by a non-whitespace character\n if (characterBefore && !isWhitespaceCharacter(characterBefore.text)) {\n return true;\n }\n\n return false;\n },\n });\n\n if (!match) {\n return;\n }\n\n const matchText = SlateEditor.string(editor, match);\n\n // Check if the match starts with the mention character (not followed by a whitespace character)\n if (\n !matchText.startsWith(MENTION_CHARACTER) ||\n (matchText.length > 1 && isWhitespaceCharacter(matchText[1]))\n ) {\n return;\n }\n\n return {\n range: match,\n // Exclude the mention character from the text\n text: matchText.substring(1),\n };\n}\n\nexport function isComposerBodyMention(\n node: SlateNode\n): node is ComposerBodyMention {\n return SlateElement.isElement(node) && node.type === \"mention\";\n}\n\nexport function insertMention(editor: SlateEditor, userId: string) {\n const mention: ComposerBodyMention = {\n type: \"mention\",\n id: userId,\n children: [{ text: \"\" }],\n };\n\n // Insert the mention\n SlateTransforms.insertNodes(editor, mention);\n SlateTransforms.move(editor);\n\n const afterCharacter = editor.selection\n ? getCharacterAfter(editor, editor.selection)\n : undefined;\n\n if (!afterCharacter || afterCharacter.void) {\n // Insert a following space if needed\n SlateTransforms.insertText(editor, \" \");\n } else if (isEmptyString(afterCharacter.text)) {\n // Move the selection if it's already followed by a space\n SlateTransforms.move(editor);\n }\n}\n\nexport function insertMentionCharacter(editor: SlateEditor) {\n if (!editor.selection) {\n return;\n }\n\n // Check if the selection is preceded or followed by a non-whitespace character\n const beforeCharacter = getCharacterBefore(editor, editor.selection, {\n filterVoids: true,\n });\n const afterCharacter = getCharacterAfter(editor, editor.selection, {\n filterVoids: true,\n });\n const shouldInsertSpaceBefore =\n beforeCharacter && !isEmptyString(beforeCharacter.text);\n const shouldInsertSpaceAfter =\n afterCharacter && !isEmptyString(afterCharacter.text);\n\n if (!SlateRange.isCollapsed(editor.selection)) {\n const text =\n (shouldInsertSpaceBefore ? \" \" : \"\") +\n MENTION_CHARACTER +\n (shouldInsertSpaceAfter ? \" \" : \"\");\n\n // If the selection is collapsed, insert the mention character at the current selection\n editor.insertText(text);\n\n // If a following space was inserted, move the selection back by one\n if (shouldInsertSpaceAfter) {\n SlateTransforms.move(editor, {\n distance: 1,\n unit: \"character\",\n reverse: true,\n });\n }\n } else {\n const beforeText = (shouldInsertSpaceBefore ? \" \" : \"\") + MENTION_CHARACTER;\n\n // If the selection is not collapsed, insert the mention character before the selection\n editor.insertText(beforeText, { at: SlateRange.start(editor.selection) });\n\n if (shouldInsertSpaceAfter) {\n editor.insertText(\" \", { at: SlateRange.end(editor.selection) });\n }\n\n // Collapse the selection at its end\n SlateTransforms.collapse(editor, { edge: \"end\" });\n }\n}\n\nexport function withMentions<T extends SlateEditor>(editor: T): T {\n const { isInline, isVoid, markableVoid, deleteBackward } = editor;\n\n editor.isInline = (element) => {\n return isComposerBodyMention(element) || isInline(element);\n };\n\n editor.isVoid = (element) => {\n return isComposerBodyMention(element) || isVoid(element);\n };\n\n editor.markableVoid = (element) => {\n return isComposerBodyMention(element) || markableVoid(element);\n };\n\n editor.deleteBackward = (unit) => {\n const { selection } = editor;\n\n if (selection && SlateRange.isCollapsed(selection)) {\n const [mention] = SlateEditor.nodes(editor, {\n at:\n unit === \"character\"\n ? SlateEditor.before(editor, selection, { unit: \"character\" })\n : selection,\n match: isComposerBodyMention,\n });\n\n deleteBackward(unit);\n\n if (mention) {\n SlateTransforms.insertText(editor, MENTION_CHARACTER);\n }\n } else {\n deleteBackward(unit);\n }\n };\n\n return editor;\n}\n"],"names":["SlateRange","getMatchRange","getCharacterBefore","isWhitespaceCharacter","SlateEditor","SlateElement","SlateTransforms","getCharacterAfter","isEmptyString"],"mappings":";;;;;;;;AAcO,MAAM,iBAAoB,GAAA,IAAA;AAO1B,SAAS,2BACd,MAC0B,EAAA;AAC1B,EAAM,MAAA,EAAE,WAAc,GAAA,MAAA,CAAA;AAEtB,EAAA,IAAI,CAAC,SAAa,IAAA,CAACA,WAAW,CAAA,WAAA,CAAY,SAAS,CAAG,EAAA;AACpD,IAAA,OAAA;AAAA,GACF;AAIA,EAAA,MAAM,QAAQC,2BAAc,CAAA,MAAA,EAAQ,SAAW,EAAA,CAAC,GAAG,CAAG,EAAA;AAAA,IACpD,OAAS,EAAA,IAAA;AAAA,IACT,0BAA4B,EAAA,KAAA;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