@liveblocks/react-ui 2.18.4-uns2 → 2.20.0-blocknote
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/components/Comment.cjs.map +1 -1
- package/dist/components/Comment.js.map +1 -1
- package/dist/components/Composer.cjs +2 -1
- package/dist/components/Composer.cjs.map +1 -1
- package/dist/components/Composer.js +3 -2
- package/dist/components/Composer.js.map +1 -1
- package/dist/components/HistoryVersionSummary.cjs.map +1 -1
- package/dist/components/HistoryVersionSummary.js.map +1 -1
- package/dist/components/HistoryVersionSummaryList.cjs.map +1 -1
- package/dist/components/HistoryVersionSummaryList.js.map +1 -1
- package/dist/components/InboxNotification.cjs.map +1 -1
- package/dist/components/InboxNotification.js.map +1 -1
- package/dist/components/InboxNotificationList.cjs.map +1 -1
- package/dist/components/InboxNotificationList.js.map +1 -1
- package/dist/components/Thread.cjs.map +1 -1
- package/dist/components/Thread.js.map +1 -1
- package/dist/components/internal/Attachment.cjs.map +1 -1
- package/dist/components/internal/Attachment.js.map +1 -1
- package/dist/components/internal/Avatar.cjs.map +1 -1
- package/dist/components/internal/Avatar.js.map +1 -1
- package/dist/components/internal/Button.cjs.map +1 -1
- package/dist/components/internal/Button.js.map +1 -1
- package/dist/components/internal/Dropdown.cjs.map +1 -1
- package/dist/components/internal/Dropdown.js.map +1 -1
- package/dist/components/internal/Room.cjs.map +1 -1
- package/dist/components/internal/Room.js.map +1 -1
- package/dist/components/internal/Tooltip.cjs.map +1 -1
- package/dist/components/internal/Tooltip.js.map +1 -1
- package/dist/components/internal/User.cjs.map +1 -1
- package/dist/components/internal/User.js.map +1 -1
- package/dist/components.cjs.map +1 -1
- package/dist/components.js.map +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.js.map +1 -1
- package/dist/primitives/Composer/index.cjs +43 -3
- package/dist/primitives/Composer/index.cjs.map +1 -1
- package/dist/primitives/Composer/index.js +44 -4
- package/dist/primitives/Composer/index.js.map +1 -1
- package/dist/primitives/EmojiPicker/index.cjs.map +1 -1
- package/dist/primitives/EmojiPicker/index.js.map +1 -1
- package/dist/primitives/FileSize.cjs.map +1 -1
- package/dist/primitives/FileSize.js.map +1 -1
- package/dist/primitives/Timestamp.cjs.map +1 -1
- package/dist/primitives/Timestamp.js.map +1 -1
- package/dist/slate/plugins/mentions.cjs +1 -8
- package/dist/slate/plugins/mentions.cjs.map +1 -1
- package/dist/slate/plugins/mentions.js +1 -8
- package/dist/slate/plugins/mentions.js.map +1 -1
- package/dist/slate/plugins/paste.cjs +8 -1
- package/dist/slate/plugins/paste.cjs.map +1 -1
- package/dist/slate/plugins/paste.js +8 -1
- package/dist/slate/plugins/paste.js.map +1 -1
- package/dist/slate/utils/get-match-range.cjs +2 -2
- package/dist/slate/utils/get-match-range.cjs.map +1 -1
- package/dist/slate/utils/get-match-range.js +2 -2
- package/dist/slate/utils/get-match-range.js.map +1 -1
- package/dist/utils/Persist.cjs.map +1 -1
- package/dist/utils/Persist.js.map +1 -1
- package/dist/utils/Portal.cjs.map +1 -1
- package/dist/utils/Portal.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timestamp.js","sources":["../../src/primitives/Timestamp.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport { forwardRef, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { capitalize } from \"../utils/capitalize\";\nimport { dateTimeFormat, relativeTimeFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst DYNAMIC_DATE_THRESHOLD = 3 * 24 * 60 * 60 * 1000; // 3 days\nconst RENDER_INTERVAL = 30 * 1000; // 30 seconds\n\nconst TIMESTAMP_NAME = \"Timestamp\";\n\nexport interface TimestampProps\n extends Omit<ComponentPropsWithSlot<\"time\">, \"children\" | \"title\"> {\n /**\n * The date to display.\n */\n date: Date | string | number;\n\n /**\n * A function to format the displayed date.\n */\n children?: (date: Date, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((date: Date, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the date.\n */\n locale?: string;\n}\n\nconst relativeUnits = {\n seconds: 60,\n minutes: 60,\n hours: 24,\n days: 7,\n weeks: 4.34524,\n months: 12,\n};\n\n/**\n * Formats a date absolutely.\n */\nfunction formatVerboseDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n/**\n * Formats a date absolutely with only the day and month.\n */\nfunction formatShortDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n month: \"short\",\n day: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n// Some locales' relative formatting can be broken (e.g. \"-1h\") when using the narrow style.\nconst localesWithBrokenNarrowRelativeFormatting = [\n \"br\",\n \"fr\",\n \"nb\",\n \"nn\",\n \"no\",\n \"ro\",\n \"sv\",\n];\n\n/**\n * Formats a date relatively.\n */\nfunction formatRelativeDate(date: Date, locale?: string) {\n let resolvedLocale: string;\n\n if (locale) {\n resolvedLocale = locale;\n } else {\n const formatter = relativeTimeFormat();\n\n resolvedLocale = formatter.resolvedOptions().locale;\n }\n\n const isBrokenWhenNarrow = localesWithBrokenNarrowRelativeFormatting.some(\n (locale) =>\n resolvedLocale === locale || resolvedLocale.startsWith(`${locale}-`)\n );\n\n const formatter = relativeTimeFormat(resolvedLocale, {\n style: isBrokenWhenNarrow ? \"short\" : \"narrow\",\n numeric: \"auto\",\n });\n\n let difference = (date.getTime() - Date.now()) / 1000;\n\n if (\n difference > -relativeUnits.seconds &&\n difference < relativeUnits.seconds\n ) {\n return formatter.format(0, \"seconds\");\n }\n\n for (const [unit, length] of Object.entries(relativeUnits)) {\n if (Math.abs(difference) < length) {\n return formatter.format(\n Math.round(difference),\n unit as Intl.RelativeTimeFormatUnit\n );\n }\n\n difference /= length;\n }\n\n return capitalize(formatter.format(Math.round(difference), \"years\"));\n}\n\n/**\n * Formats a date relatively if it's recent,\n * otherwise absolutely with only the day and month.\n */\nfunction formatDynamicDate(date: Date, locale?: string) {\n return date.getTime() > Date.now() - DYNAMIC_DATE_THRESHOLD\n ? formatRelativeDate(date, locale)\n : formatShortDate(date, locale);\n}\n\n/**\n * Displays a formatted date, and automatically re-renders to support relative\n * formatting. Defaults to relative formatting for recent dates and a short\n * absolute formatting for older ones.\n *\n * @example\n * <Timestamp date={new Date()} />\n *\n * @example\n * <Timestamp date={new Date()} title={(date) => date.toISOString()} interval={false}>\n * {(date) => date.toLocaleDateString()}\n * </Timestamp>\n */\nexport const Timestamp = forwardRef<HTMLTimeElement, TimestampProps>(\n (\n {\n date,\n locale,\n children: renderChildren = formatDynamicDate,\n title: renderTitle = formatVerboseDate,\n dateTime,\n interval = RENDER_INTERVAL,\n asChild,\n ...props\n },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"time\";\n const [rerender, key] = useRerender();\n const parsedDate = useMemo(() => new Date(date), [date]);\n const normalizedDate = useMemo(\n () => parsedDate.toISOString(),\n [parsedDate]\n );\n const title = useMemo(\n () =>\n typeof renderTitle === \"function\"\n ? renderTitle(parsedDate, locale)\n : renderTitle,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderTitle, parsedDate, key]\n );\n const children = useMemo(\n () =>\n typeof renderChildren === \"function\"\n ? renderChildren(parsedDate, locale)\n : renderChildren,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderChildren, parsedDate, key]\n );\n\n useInterval(rerender, interval);\n\n return (\n <Component\n {...props}\n ref={forwardedRef}\n dateTime={dateTime ?? normalizedDate}\n title={title}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Timestamp.displayName = TIMESTAMP_NAME;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Timestamp.js","sources":["../../src/primitives/Timestamp.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport { forwardRef, useMemo } from \"react\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\nimport { capitalize } from \"../utils/capitalize\";\nimport { dateTimeFormat, relativeTimeFormat } from \"../utils/intl\";\nimport { useInterval } from \"../utils/use-interval\";\nimport { useRerender } from \"../utils/use-rerender\";\n\nconst DYNAMIC_DATE_THRESHOLD = 3 * 24 * 60 * 60 * 1000; // 3 days\nconst RENDER_INTERVAL = 30 * 1000; // 30 seconds\n\nconst TIMESTAMP_NAME = \"Timestamp\";\n\nexport interface TimestampProps\n extends Omit<ComponentPropsWithSlot<\"time\">, \"children\" | \"title\"> {\n /**\n * The date to display.\n */\n date: Date | string | number;\n\n /**\n * A function to format the displayed date.\n */\n children?: (date: Date, locale?: string) => ReactNode;\n\n /**\n * The `title` attribute's value or a function to format it.\n */\n title?: string | ((date: Date, locale?: string) => string);\n\n /**\n * The interval in milliseconds at which the component will re-render.\n * Can be set to `false` to disable re-rendering.\n */\n interval?: number | false;\n\n /**\n * The locale used when formatting the date.\n */\n locale?: string;\n}\n\nconst relativeUnits = {\n seconds: 60,\n minutes: 60,\n hours: 24,\n days: 7,\n weeks: 4.34524,\n months: 12,\n};\n\n/**\n * Formats a date absolutely.\n */\nfunction formatVerboseDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n year: \"numeric\",\n month: \"numeric\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n/**\n * Formats a date absolutely with only the day and month.\n */\nfunction formatShortDate(date: Date, locale?: string) {\n const formatter = dateTimeFormat(locale, {\n month: \"short\",\n day: \"numeric\",\n });\n\n return capitalize(formatter.format(date));\n}\n\n// Some locales' relative formatting can be broken (e.g. \"-1h\") when using the narrow style.\nconst localesWithBrokenNarrowRelativeFormatting = [\n \"br\",\n \"fr\",\n \"nb\",\n \"nn\",\n \"no\",\n \"ro\",\n \"sv\",\n];\n\n/**\n * Formats a date relatively.\n */\nfunction formatRelativeDate(date: Date, locale?: string) {\n let resolvedLocale: string;\n\n if (locale) {\n resolvedLocale = locale;\n } else {\n const formatter = relativeTimeFormat();\n\n resolvedLocale = formatter.resolvedOptions().locale;\n }\n\n const isBrokenWhenNarrow = localesWithBrokenNarrowRelativeFormatting.some(\n (locale) =>\n resolvedLocale === locale || resolvedLocale.startsWith(`${locale}-`)\n );\n\n const formatter = relativeTimeFormat(resolvedLocale, {\n style: isBrokenWhenNarrow ? \"short\" : \"narrow\",\n numeric: \"auto\",\n });\n\n let difference = (date.getTime() - Date.now()) / 1000;\n\n if (\n difference > -relativeUnits.seconds &&\n difference < relativeUnits.seconds\n ) {\n return formatter.format(0, \"seconds\");\n }\n\n for (const [unit, length] of Object.entries(relativeUnits)) {\n if (Math.abs(difference) < length) {\n return formatter.format(\n Math.round(difference),\n unit as Intl.RelativeTimeFormatUnit\n );\n }\n\n difference /= length;\n }\n\n return capitalize(formatter.format(Math.round(difference), \"years\"));\n}\n\n/**\n * Formats a date relatively if it's recent,\n * otherwise absolutely with only the day and month.\n */\nfunction formatDynamicDate(date: Date, locale?: string) {\n return date.getTime() > Date.now() - DYNAMIC_DATE_THRESHOLD\n ? formatRelativeDate(date, locale)\n : formatShortDate(date, locale);\n}\n\n/**\n * Displays a formatted date, and automatically re-renders to support relative\n * formatting. Defaults to relative formatting for recent dates and a short\n * absolute formatting for older ones.\n *\n * @example\n * <Timestamp date={new Date()} />\n *\n * @example\n * <Timestamp date={new Date()} title={(date) => date.toISOString()} interval={false}>\n * {(date) => date.toLocaleDateString()}\n * </Timestamp>\n */\nexport const Timestamp = forwardRef<HTMLTimeElement, TimestampProps>(\n (\n {\n date,\n locale,\n children: renderChildren = formatDynamicDate,\n title: renderTitle = formatVerboseDate,\n dateTime,\n interval = RENDER_INTERVAL,\n asChild,\n ...props\n },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"time\";\n const [rerender, key] = useRerender();\n const parsedDate = useMemo(() => new Date(date), [date]);\n const normalizedDate = useMemo(\n () => parsedDate.toISOString(),\n [parsedDate]\n );\n const title = useMemo(\n () =>\n typeof renderTitle === \"function\"\n ? renderTitle(parsedDate, locale)\n : renderTitle,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderTitle, parsedDate, key]\n );\n const children = useMemo(\n () =>\n typeof renderChildren === \"function\"\n ? renderChildren(parsedDate, locale)\n : renderChildren,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [renderChildren, parsedDate, key]\n );\n\n useInterval(rerender, interval);\n\n return (\n <Component\n {...props}\n ref={forwardedRef}\n dateTime={dateTime ?? normalizedDate}\n title={title}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Timestamp.displayName = TIMESTAMP_NAME;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAYA;AACA;AAEA;AA+BA;AAAsB;AACX;AACA;AACF;AACD;AACC;AAET;AAKA;AACE;AAAyC;AACjC;AACC;AACF;AACC;AACE;AAGV;AACF;AAKA;AACE;AAAyC;AAChC;AACF;AAGP;AACF;AAGA;AAAkD;AAChD;AACA;AACA;AACA;AACA;AACA;AAEF;AAKA;AACE;AAEA;AACE;AAAiB;AAEjB;AAEA;AAA6C;AAG/C;AAAqE;AAEE;AAGvE;AAAqD;AACb;AAC7B;AAGX;AAEA;AAIE;AAAoC;AAGtC;AACE;AACE;AAAiB;AACM;AACrB;AACF;AAGF;AAAc;AAGhB;AACF;AAMA;AACE;AAGF;AAeO;AAAkB;AAErB;AACE;AACA;AAC2B;AACN;AACrB;AACW;AACX;AACG;AAIL;AACA;AACA;AACA;AAAuB;AACQ;AAClB;AAEb;AAAc;AAIN;AAEuB;AAE/B;AAAiB;AAIT;AAE0B;AAGlC;AAEA;AACG;AACK;AACC;AACiB;AACtB;AAEC;AACH;AAGN;AAEA;AACE;AACF;;"}
|
|
@@ -20,13 +20,6 @@ function getMentionDraftAtSelection(editor) {
|
|
|
20
20
|
if (characterBefore && !isWhitespaceCharacter.isWhitespaceCharacter(characterBefore.text)) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
-
const after = slate.Editor.after(editor, point, { unit: "character" });
|
|
24
|
-
if (after) {
|
|
25
|
-
const characterAfter = getCharacter.getCharacterAfter(editor, after);
|
|
26
|
-
if (isWhitespaceCharacter.isWhitespaceCharacter(characterAfter?.text)) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
23
|
return false;
|
|
31
24
|
}
|
|
32
25
|
});
|
|
@@ -34,7 +27,7 @@ function getMentionDraftAtSelection(editor) {
|
|
|
34
27
|
return;
|
|
35
28
|
}
|
|
36
29
|
const matchText = slate.Editor.string(editor, match);
|
|
37
|
-
if (!matchText.startsWith(MENTION_CHARACTER) || isWhitespaceCharacter.isWhitespaceCharacter(matchText[1])) {
|
|
30
|
+
if (!matchText.startsWith(MENTION_CHARACTER) || matchText.length > 1 && isWhitespaceCharacter.isWhitespaceCharacter(matchText[1])) {
|
|
38
31
|
return;
|
|
39
32
|
}
|
|
40
33
|
return {
|
|
@@ -1 +1 @@
|
|
|
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 const after = SlateEditor.after(editor, point, { unit: \"character\" });\n\n if (after) {\n const characterAfter = getCharacterAfter(editor, after);\n\n // Ignore \"@\" if it's followed by a whitespace character\n if (isWhitespaceCharacter(characterAfter?.text)) {\n return true;\n }\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 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","getCharacterAfter","SlateElement","SlateTransforms","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;AAAA,IAC5B,gBAAA,EAAkB,CAAC,CAAA,EAAG,KAAU,KAAA;AAC9B,MAAM,MAAA,eAAA,GAAkBC,+BAAmB,CAAA,MAAA,EAAQ,KAAK,CAAA,CAAA;AAGxD,MAAA,IAAI,eAAmB,IAAA,CAACC,2CAAsB,CAAA,eAAA,CAAgB,IAAI,CAAG,EAAA;AACnE,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAEA,MAAM,MAAA,KAAA,GAAQC,aAAY,KAAM,CAAA,MAAA,EAAQ,OAAO,EAAE,IAAA,EAAM,aAAa,CAAA,CAAA;AAEpE,MAAA,IAAI,KAAO,EAAA;AACT,QAAM,MAAA,cAAA,GAAiBC,8BAAkB,CAAA,MAAA,EAAQ,KAAK,CA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,IAAAP,WAAA,CAAW,WAAY,CAAA,SAAS,CAAG,EAAA;AAClD,MAAA,MAAM,CAAC,OAAO,CAAI,GAAAI,YAAA,CAAY,MAAM,MAAQ,EAAA;AAAA,QAC1C,EAAA,EACE,IAAS,KAAA,WAAA,GACLA,YAAY,CAAA,MAAA,CAAO,MAAQ,EAAA,SAAA,EAAW,EAAE,IAAA,EAAM,WAAY,EAAC,CAC3D,GAAA,SAAA;AAAA,QACN,KAAO,EAAA,qBAAA;AAAA,OACR,CAAA,CAAA;AAED,MAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAEnB,MAAA,IAAI,OAAS,EAAA;AACX,QAAgBG,gBAAA,CAAA,UAAA,CAAW,QAAQ,iBAAiB,CAAA,CAAA;AAAA,OACtD;AAAA,KACK,MAAA;AACL,MAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAAA,KACrB;AAAA,GACF,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;;;;;;"}
|
|
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,CAA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,CAAC,OAAY,KAAA;AAC3B,IAAA,OAAO,qBAAsB,CAAA,OAAO,CAAK,IAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAAA,GACzD,CAAA;AAEA,EAAO,MAAA,CAAA,YAAA,GAAe,CAAC,OAAY,KAAA;AACjC,IAAA,OAAO,qBAAsB,CAAA,OAAO,CAAK,IAAA,YAAA,CAAa,OAAO,CAAA,CAAA;AAAA,GAC/D,CAAA;AAEA,EAAO,MAAA,CAAA,cAAA,GAAiB,CAAC,IAAS,KAAA;AAChC,IAAM,MAAA,EAAE,WAAc,GAAA,MAAA,CAAA;AAEtB,IAAA,IAAI,SAAa,IAAAN,WAAA,CAAW,WAAY,CAAA,SAAS,CAAG,EAAA;AAClD,MAAA,MAAM,CAAC,OAAO,CAAI,GAAAI,YAAA,CAAY,MAAM,MAAQ,EAAA;AAAA,QAC1C,EAAA,EACE,IAAS,KAAA,WAAA,GACLA,YAAY,CAAA,MAAA,CAAO,MAAQ,EAAA,SAAA,EAAW,EAAE,IAAA,EAAM,WAAY,EAAC,CAC3D,GAAA,SAAA;AAAA,QACN,KAAO,EAAA,qBAAA;AAAA,OACR,CAAA,CAAA;AAED,MAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAEnB,MAAA,IAAI,OAAS,EAAA;AACX,QAAgBE,gBAAA,CAAA,UAAA,CAAW,QAAQ,iBAAiB,CAAA,CAAA;AAAA,OACtD;AAAA,KACK,MAAA;AACL,MAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAAA,KACrB;AAAA,GACF,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;;;;;;"}
|
|
@@ -18,13 +18,6 @@ function getMentionDraftAtSelection(editor) {
|
|
|
18
18
|
if (characterBefore && !isWhitespaceCharacter(characterBefore.text)) {
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
const after = Editor.after(editor, point, { unit: "character" });
|
|
22
|
-
if (after) {
|
|
23
|
-
const characterAfter = getCharacterAfter(editor, after);
|
|
24
|
-
if (isWhitespaceCharacter(characterAfter?.text)) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
21
|
return false;
|
|
29
22
|
}
|
|
30
23
|
});
|
|
@@ -32,7 +25,7 @@ function getMentionDraftAtSelection(editor) {
|
|
|
32
25
|
return;
|
|
33
26
|
}
|
|
34
27
|
const matchText = Editor.string(editor, match);
|
|
35
|
-
if (!matchText.startsWith(MENTION_CHARACTER) || isWhitespaceCharacter(matchText[1])) {
|
|
28
|
+
if (!matchText.startsWith(MENTION_CHARACTER) || matchText.length > 1 && isWhitespaceCharacter(matchText[1])) {
|
|
36
29
|
return;
|
|
37
30
|
}
|
|
38
31
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mentions.js","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 const after = SlateEditor.after(editor, point, { unit: \"character\" });\n\n if (after) {\n const characterAfter = getCharacterAfter(editor, after);\n\n // Ignore \"@\" if it's followed by a whitespace character\n if (isWhitespaceCharacter(characterAfter?.text)) {\n return true;\n }\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 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","SlateEditor","SlateElement","SlateTransforms"],"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,KAAW,CAAA,WAAA,CAAY,SAAS,CAAG,EAAA;AACpD,IAAA,OAAA;AAAA,GACF;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../../../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","SlateEditor","SlateElement","SlateTransforms"],"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,KAAW,CAAA,WAAA,CAAY,SAAS,CAAG,EAAA;AACpD,IAAA,OAAA;AAAA,GACF;AAIA,EAAA,MAAM,QAAQ,aAAc,CAAA,MAAA,EAAQ,SAAW,EAAA,CAAC,GAAG,CAAG,EAAA;AAAA,IACpD,OAAS,EAAA,IAAA;AAAA,IACT,0BAA4B,EAAA,KAAA;AAAA,IAC5B,gBAAA,EAAkB,CAAC,CAAA,EAAG,KAAU,KAAA;AAC9B,MAAM,MAAA,eAAA,GAAkB,kBAAmB,CAAA,MAAA,EAAQ,KAAK,CAAA,CAAA;AAGxD,MAAA,IAAI,eAAmB,IAAA,CAAC,qBAAsB,CAAA,eAAA,CAAgB,IAAI,CAAG,EAAA;AACnE,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAEA,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACD,CAAA,CAAA;AAED,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAA;AAAA,GACF;AAEA,EAAA,MAAM,SAAY,GAAAC,MAAA,CAAY,MAAO,CAAA,MAAA,EAAQ,KAAK,CAAA,CAAA;AAGlD,EACE,IAAA,CA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;AAED,MAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAEnB,MAAA,IAAI,OAAS,EAAA;AACX,QAAgBE,UAAA,CAAA,UAAA,CAAW,QAAQ,iBAAiB,CAAA,CAAA;AAAA,OACtD;AAAA,KACK,MAAA;AACL,MAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAAA,KACrB;AAAA,GACF,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -4,6 +4,8 @@ var slate = require('slate');
|
|
|
4
4
|
var slateHyperscript = require('slate-hyperscript');
|
|
5
5
|
var dataTransfer = require('../../utils/data-transfer.cjs');
|
|
6
6
|
|
|
7
|
+
const NEWLINE_REGEX = /[\r\n]/g;
|
|
8
|
+
const WHITESPACE_REGEX = /\s+/g;
|
|
7
9
|
function areUrlsEqual(a, b) {
|
|
8
10
|
try {
|
|
9
11
|
const urlA = new URL(a);
|
|
@@ -61,7 +63,12 @@ function jsxTextChildren(children, attrs) {
|
|
|
61
63
|
}
|
|
62
64
|
function deserialize(node) {
|
|
63
65
|
if (node.nodeType === 3) {
|
|
64
|
-
|
|
66
|
+
let text = node.textContent;
|
|
67
|
+
const isMultiLine = text && NEWLINE_REGEX.test(text);
|
|
68
|
+
if (text && isMultiLine) {
|
|
69
|
+
text = text.replace(WHITESPACE_REGEX, " ").trim();
|
|
70
|
+
}
|
|
71
|
+
return text ? { text } : null;
|
|
65
72
|
} else if (node.nodeType !== 1) {
|
|
66
73
|
return null;
|
|
67
74
|
} else if (node.nodeName === "BR") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paste.cjs","sources":["../../../src/slate/plugins/paste.ts"],"sourcesContent":["import type { Descendant, Editor, Node as SlateNode } from \"slate\";\nimport { Transforms } from \"slate\";\nimport { jsx } from \"slate-hyperscript\";\n\nimport type {\n ComposerBodyAutoLink,\n ComposerBodyBlockElement,\n ComposerBodyCustomLink,\n ComposerBodyInlineElement,\n ComposerBodyParagraph,\n ComposerBodyText,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\n\n// Based on: https://github.com/ianstormtaylor/slate/blob/main/site/examples/paste-html.tsx\n\ntype OmitTextChildren<T> = Omit<T, \"text\" | \"children\">;\n\ntype ComposerBodyElementTag = OmitTextChildren<\n ComposerBodyBlockElement | ComposerBodyInlineElement\n>;\ntype ComposerBodyTextTag = OmitTextChildren<ComposerBodyText>;\n\ntype DeserializedNode =\n | null\n | string\n | Descendant\n | Descendant[]\n | DeserializedNode[];\n\nfunction areUrlsEqual(a: string, b: string) {\n try {\n const urlA = new URL(a);\n const urlB = new URL(b);\n\n return urlA.origin === urlB.origin && urlA.pathname === urlB.pathname;\n } catch {\n return false;\n }\n}\n\nconst createParagraphElement = (): OmitTextChildren<ComposerBodyParagraph> => ({\n type: \"paragraph\",\n});\n\nconst ELEMENT_TAGS = {\n A: (\n element\n ): OmitTextChildren<ComposerBodyCustomLink | ComposerBodyAutoLink> => {\n const href = element.getAttribute(\"href\");\n const innerText = element.innerText;\n\n return {\n type: href && areUrlsEqual(href, innerText) ? \"auto-link\" : \"custom-link\",\n url: href ?? \"\",\n };\n },\n P: createParagraphElement,\n // Falling back to paragraphs for unsupported elements\n BLOCKQUOTE: createParagraphElement,\n H1: createParagraphElement,\n H2: createParagraphElement,\n H3: createParagraphElement,\n H4: createParagraphElement,\n H5: createParagraphElement,\n H6: createParagraphElement,\n LI: createParagraphElement,\n} as Record<string, (node: HTMLElement) => ComposerBodyElementTag>;\n\nconst TEXT_TAGS = {\n CODE: (): ComposerBodyTextTag => ({ code: true }),\n DEL: (): ComposerBodyTextTag => ({ strikethrough: true }),\n EM: (): ComposerBodyTextTag => ({ italic: true }),\n I: (): ComposerBodyTextTag => ({ italic: true }),\n S: (): ComposerBodyTextTag => ({ strikethrough: true }),\n STRONG: (): ComposerBodyTextTag => ({ bold: true }),\n B: (): ComposerBodyTextTag => ({ bold: true }),\n} as Record<string, (node: HTMLElement) => ComposerBodyTextTag>;\n\nfunction flattenListItems(node: HTMLElement): HTMLElement[] {\n const listItems: HTMLElement[] = [];\n\n if (node.nodeName === \"LI\") {\n listItems.push(node);\n }\n\n node.childNodes.forEach((child) => {\n if (child.nodeType === 1) {\n listItems.push(...flattenListItems(child as HTMLElement));\n }\n });\n\n return listItems;\n}\n\nfunction jsxTextChildren(\n children: DeserializedNode[],\n attrs?: ComposerBodyTextTag\n) {\n return children.map((child) => jsx(\"text\", attrs, child));\n}\n\nfunction deserialize(node: Node): DeserializedNode {\n if (node.nodeType === 3) {\n return node.textContent;\n } else if (node.nodeType !== 1) {\n return null;\n } else if (node.nodeName === \"BR\") {\n // Insert a new paragraph\n return jsx(\"element\", createParagraphElement(), []);\n }\n\n const childNodes = Array.from(node.childNodes);\n let children = childNodes.map(deserialize).flat();\n\n // Lists aren't supported (yet), so we flatten them into paragraphs\n if (node.nodeName === \"UL\" || node.nodeName === \"OL\") {\n const listItems = flattenListItems(node as HTMLElement);\n\n children = listItems.map((li) => deserialize(li)).flat();\n }\n\n if (children.length === 0) {\n children = [{ text: \"\" }];\n }\n\n if (node.nodeName === \"BODY\") {\n // If the body only contains text nodes, we wrap it in a paragraph\n if (\n children.length > 0 &&\n children.every((child) => typeof child === \"string\")\n ) {\n children = [\n { type: \"paragraph\", children: [{ text: children.join(\"\") }] },\n ];\n }\n\n return jsx(\n \"fragment\",\n {},\n children.filter((child) => typeof child !== \"string\")\n );\n }\n\n if (ELEMENT_TAGS[node.nodeName]) {\n const attrs = ELEMENT_TAGS[node.nodeName]!(node as HTMLElement);\n\n return jsx(\"element\", attrs, children);\n }\n\n if (TEXT_TAGS[node.nodeName]) {\n const attrs = TEXT_TAGS[node.nodeName]!(node as HTMLElement);\n\n // If there is at least one non-text child, we skip this node\n if (\n children.some(\n (child) => child && typeof child !== \"string\" && \"type\" in child\n )\n ) {\n return jsx(\"fragment\", {}, children);\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n // Guess inline marks based on styles\n if (node.nodeName === \"SPAN\") {\n const style = (node as HTMLElement).style;\n const attrs: ComposerBodyTextTag = {};\n\n if (\n style.fontWeight === \"bold\" ||\n style.fontWeight === \"700\" ||\n style.fontWeight === \"800\" ||\n style.fontWeight === \"900\"\n ) {\n attrs.bold = true;\n }\n\n if (style.fontStyle === \"italic\") {\n attrs.italic = true;\n }\n\n if (style.textDecoration === \"line-through\") {\n attrs.strikethrough = true;\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n return children as DeserializedNode;\n}\n\nexport function withPaste(\n editor: Editor,\n {\n createAttachments,\n pasteFilesAsAttachments,\n }: {\n createAttachments: (files: File[]) => void;\n pasteFilesAsAttachments?: boolean;\n }\n) {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n // Create attachments from files when pasting\n if (data.types.includes(\"Files\") && pasteFilesAsAttachments) {\n const files = getFiles(data);\n\n if (files.length > 0) {\n createAttachments(files);\n\n return;\n }\n }\n\n // Deserialize rich text from HTML when pasting (unless there's also Slate data)\n if (\n data.types.includes(\"text/html\") &&\n !data.types.includes(\"application/x-slate-fragment\")\n ) {\n const html = data.getData(\"text/html\");\n\n try {\n const { body } = new DOMParser().parseFromString(html, \"text/html\");\n\n // WebKit browsers can add a trailing `<br>`\n body.querySelector(\"br.Apple-interchange-newline\")?.remove();\n\n // Google Docs can use `<b>` as a wrapper for the entire document,\n // it shouldn't be supported so we remove it\n if (body.children.length === 1 && body.children[0]?.nodeName === \"B\") {\n const wrapper = body.children[0] as HTMLElement;\n\n while (wrapper.firstChild) {\n body.insertBefore(wrapper.firstChild, wrapper);\n }\n\n body.removeChild(wrapper);\n }\n\n const fragment = deserialize(body);\n\n if (fragment !== null && Array.isArray(fragment)) {\n Transforms.insertFragment(editor, fragment as SlateNode[]);\n\n return;\n }\n } catch {\n // Fallback to default `insertData` behavior\n }\n }\n\n // Default `insertData` behavior\n insertData(data);\n };\n\n return editor;\n}\n"],"names":["jsx","getFiles","Transforms"],"mappings":";;;;;;AA8BA,SAAS,YAAA,CAAa,GAAW,CAAW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EAAY,OAAO,CAAA,CAAA;AAAA,WAC/C;AAEA,UAAA,IAAA,CAAK,YAAY,OAAO,CAAA,CAAA;AAAA,SAC1B;AAEA,QAAM,MAAA,QAAA,GAAW,YAAY,IAAI,CAAA,CAAA;AAEjC,QAAA,IAAI,QAAa,KAAA,IAAA,IAAQ,KAAM,CAAA,OAAA,CAAQ,QAAQ,CAAG,EAAA;AAChD,UAAWC,gBAAA,CAAA,cAAA,CAAe,QAAQ,QAAuB,CAAA,CAAA;AAEzD,UAAA,OAAA;AAAA,SACF;AAAA,OACA,CAAA,MAAA;AAAA,OAEF;AAAA,KACF;AAGA,IAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAAA,GACjB,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"paste.cjs","sources":["../../../src/slate/plugins/paste.ts"],"sourcesContent":["import type { Descendant, Editor, Node as SlateNode } from \"slate\";\nimport { Transforms } from \"slate\";\nimport { jsx } from \"slate-hyperscript\";\n\nimport type {\n ComposerBodyAutoLink,\n ComposerBodyBlockElement,\n ComposerBodyCustomLink,\n ComposerBodyInlineElement,\n ComposerBodyParagraph,\n ComposerBodyText,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\n\n// Based on: https://github.com/ianstormtaylor/slate/blob/main/site/examples/paste-html.tsx\n\nconst NEWLINE_REGEX = /[\\r\\n]/g;\nconst WHITESPACE_REGEX = /\\s+/g;\n\ntype OmitTextChildren<T> = Omit<T, \"text\" | \"children\">;\n\ntype ComposerBodyElementTag = OmitTextChildren<\n ComposerBodyBlockElement | ComposerBodyInlineElement\n>;\ntype ComposerBodyTextTag = OmitTextChildren<ComposerBodyText>;\n\ntype DeserializedNode =\n | null\n | string\n | Descendant\n | Descendant[]\n | DeserializedNode[];\n\nfunction areUrlsEqual(a: string, b: string) {\n try {\n const urlA = new URL(a);\n const urlB = new URL(b);\n\n return urlA.origin === urlB.origin && urlA.pathname === urlB.pathname;\n } catch {\n return false;\n }\n}\n\nconst createParagraphElement = (): OmitTextChildren<ComposerBodyParagraph> => ({\n type: \"paragraph\",\n});\n\nconst ELEMENT_TAGS = {\n A: (\n element\n ): OmitTextChildren<ComposerBodyCustomLink | ComposerBodyAutoLink> => {\n const href = element.getAttribute(\"href\");\n const innerText = element.innerText;\n\n return {\n type: href && areUrlsEqual(href, innerText) ? \"auto-link\" : \"custom-link\",\n url: href ?? \"\",\n };\n },\n P: createParagraphElement,\n // Falling back to paragraphs for unsupported elements\n BLOCKQUOTE: createParagraphElement,\n H1: createParagraphElement,\n H2: createParagraphElement,\n H3: createParagraphElement,\n H4: createParagraphElement,\n H5: createParagraphElement,\n H6: createParagraphElement,\n LI: createParagraphElement,\n} as Record<string, (node: HTMLElement) => ComposerBodyElementTag>;\n\nconst TEXT_TAGS = {\n CODE: (): ComposerBodyTextTag => ({ code: true }),\n DEL: (): ComposerBodyTextTag => ({ strikethrough: true }),\n EM: (): ComposerBodyTextTag => ({ italic: true }),\n I: (): ComposerBodyTextTag => ({ italic: true }),\n S: (): ComposerBodyTextTag => ({ strikethrough: true }),\n STRONG: (): ComposerBodyTextTag => ({ bold: true }),\n B: (): ComposerBodyTextTag => ({ bold: true }),\n} as Record<string, (node: HTMLElement) => ComposerBodyTextTag>;\n\nfunction flattenListItems(node: HTMLElement): HTMLElement[] {\n const listItems: HTMLElement[] = [];\n\n if (node.nodeName === \"LI\") {\n listItems.push(node);\n }\n\n node.childNodes.forEach((child) => {\n if (child.nodeType === 1) {\n listItems.push(...flattenListItems(child as HTMLElement));\n }\n });\n\n return listItems;\n}\n\nfunction jsxTextChildren(\n children: DeserializedNode[],\n attrs?: ComposerBodyTextTag\n) {\n return children.map((child) => jsx(\"text\", attrs, child));\n}\n\nfunction deserialize(node: Node): DeserializedNode {\n if (node.nodeType === 3) {\n let text = node.textContent;\n const isMultiLine = text && NEWLINE_REGEX.test(text);\n\n if (text && isMultiLine) {\n text = text.replace(WHITESPACE_REGEX, \" \").trim();\n }\n\n return text ? { text } : null;\n } else if (node.nodeType !== 1) {\n return null;\n } else if (node.nodeName === \"BR\") {\n // Insert a new paragraph\n return jsx(\"element\", createParagraphElement(), []);\n }\n\n const childNodes = Array.from(node.childNodes);\n let children = childNodes.map(deserialize).flat();\n\n // Lists aren't supported (yet), so we flatten them into paragraphs\n if (node.nodeName === \"UL\" || node.nodeName === \"OL\") {\n const listItems = flattenListItems(node as HTMLElement);\n\n children = listItems.map((li) => deserialize(li)).flat();\n }\n\n if (children.length === 0) {\n children = [{ text: \"\" }];\n }\n\n if (node.nodeName === \"BODY\") {\n // If the body only contains text nodes, we wrap it in a paragraph\n if (\n children.length > 0 &&\n children.every((child) => typeof child === \"string\")\n ) {\n children = [\n { type: \"paragraph\", children: [{ text: children.join(\"\") }] },\n ];\n }\n\n return jsx(\n \"fragment\",\n {},\n children.filter((child) => typeof child !== \"string\")\n );\n }\n\n if (ELEMENT_TAGS[node.nodeName]) {\n const attrs = ELEMENT_TAGS[node.nodeName]!(node as HTMLElement);\n\n return jsx(\"element\", attrs, children);\n }\n\n if (TEXT_TAGS[node.nodeName]) {\n const attrs = TEXT_TAGS[node.nodeName]!(node as HTMLElement);\n\n // If there is at least one non-text child, we skip this node\n if (\n children.some(\n (child) => child && typeof child !== \"string\" && \"type\" in child\n )\n ) {\n return jsx(\"fragment\", {}, children);\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n // Guess inline marks based on styles\n if (node.nodeName === \"SPAN\") {\n const style = (node as HTMLElement).style;\n const attrs: ComposerBodyTextTag = {};\n\n if (\n style.fontWeight === \"bold\" ||\n style.fontWeight === \"700\" ||\n style.fontWeight === \"800\" ||\n style.fontWeight === \"900\"\n ) {\n attrs.bold = true;\n }\n\n if (style.fontStyle === \"italic\") {\n attrs.italic = true;\n }\n\n if (style.textDecoration === \"line-through\") {\n attrs.strikethrough = true;\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n return children as DeserializedNode;\n}\n\nexport function withPaste(\n editor: Editor,\n {\n createAttachments,\n pasteFilesAsAttachments,\n }: {\n createAttachments: (files: File[]) => void;\n pasteFilesAsAttachments?: boolean;\n }\n) {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n // Create attachments from files when pasting\n if (data.types.includes(\"Files\") && pasteFilesAsAttachments) {\n const files = getFiles(data);\n\n if (files.length > 0) {\n createAttachments(files);\n\n return;\n }\n }\n\n // Deserialize rich text from HTML when pasting (unless there's also Slate data)\n if (\n data.types.includes(\"text/html\") &&\n !data.types.includes(\"application/x-slate-fragment\")\n ) {\n const html = data.getData(\"text/html\");\n\n try {\n const { body } = new DOMParser().parseFromString(html, \"text/html\");\n\n // WebKit browsers can add a trailing `<br>`\n body.querySelector(\"br.Apple-interchange-newline\")?.remove();\n\n // Google Docs can use `<b>` as a wrapper for the entire document,\n // it shouldn't be supported so we remove it\n if (body.children.length === 1 && body.children[0]?.nodeName === \"B\") {\n const wrapper = body.children[0] as HTMLElement;\n\n while (wrapper.firstChild) {\n body.insertBefore(wrapper.firstChild, wrapper);\n }\n\n body.removeChild(wrapper);\n }\n\n const fragment = deserialize(body);\n\n if (fragment !== null && Array.isArray(fragment)) {\n Transforms.insertFragment(editor, fragment as SlateNode[]);\n\n return;\n }\n } catch {\n // Fallback to default `insertData` behavior\n }\n }\n\n // Default `insertData` behavior\n insertData(data);\n };\n\n return editor;\n}\n"],"names":["jsx","getFiles","Transforms"],"mappings":";;;;;;AAgBA,MAAM,aAAgB,GAAA,SAAA,CAAA;AACtB,MAAM,gBAAmB,GAAA,MAAA,CAAA;AAgBzB,SAAS,YAAA,CAAa,GAAW,CAAW,EAAA;AAC1C,EAAI,IAAA;AACF,IAAM,MAAA,IAAA,GAAO,IAAI,GAAA,CAAI,CAAC,CAAA,CAAA;AACtB,IAAM,MAAA,IAAA,GAAO,IAAI,GAAA,CAAI,CAAC,CAAA,CAAA;AAEtB,IAAA,OAAO,KAAK,MAAW,KAAA,IAAA,CAAK,MAAU,IAAA,IAAA,CAAK,aAA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,UAAY,EAAA;AACzB,YAAK,IAAA,CAAA,YAAA,CAAa,OAAQ,CAAA,UAAA,EAAY,OAAO,CAAA,CAAA;AAAA,WAC/C;AAEA,UAAA,IAAA,CAAK,YAAY,OAAO,CAAA,CAAA;AAAA,SAC1B;AAEA,QAAM,MAAA,QAAA,GAAW,YAAY,IAAI,CAAA,CAAA;AAEjC,QAAA,IAAI,QAAa,KAAA,IAAA,IAAQ,KAAM,CAAA,OAAA,CAAQ,QAAQ,CAAG,EAAA;AAChD,UAAWC,gBAAA,CAAA,cAAA,CAAe,QAAQ,QAAuB,CAAA,CAAA;AAEzD,UAAA,OAAA;AAAA,SACF;AAAA,OACA,CAAA,MAAA;AAAA,OAEF;AAAA,KACF;AAGA,IAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAAA,GACjB,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -2,6 +2,8 @@ import { Transforms } from 'slate';
|
|
|
2
2
|
import { jsx } from 'slate-hyperscript';
|
|
3
3
|
import { getFiles } from '../../utils/data-transfer.js';
|
|
4
4
|
|
|
5
|
+
const NEWLINE_REGEX = /[\r\n]/g;
|
|
6
|
+
const WHITESPACE_REGEX = /\s+/g;
|
|
5
7
|
function areUrlsEqual(a, b) {
|
|
6
8
|
try {
|
|
7
9
|
const urlA = new URL(a);
|
|
@@ -59,7 +61,12 @@ function jsxTextChildren(children, attrs) {
|
|
|
59
61
|
}
|
|
60
62
|
function deserialize(node) {
|
|
61
63
|
if (node.nodeType === 3) {
|
|
62
|
-
|
|
64
|
+
let text = node.textContent;
|
|
65
|
+
const isMultiLine = text && NEWLINE_REGEX.test(text);
|
|
66
|
+
if (text && isMultiLine) {
|
|
67
|
+
text = text.replace(WHITESPACE_REGEX, " ").trim();
|
|
68
|
+
}
|
|
69
|
+
return text ? { text } : null;
|
|
63
70
|
} else if (node.nodeType !== 1) {
|
|
64
71
|
return null;
|
|
65
72
|
} else if (node.nodeName === "BR") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paste.js","sources":["../../../src/slate/plugins/paste.ts"],"sourcesContent":["import type { Descendant, Editor, Node as SlateNode } from \"slate\";\nimport { Transforms } from \"slate\";\nimport { jsx } from \"slate-hyperscript\";\n\nimport type {\n ComposerBodyAutoLink,\n ComposerBodyBlockElement,\n ComposerBodyCustomLink,\n ComposerBodyInlineElement,\n ComposerBodyParagraph,\n ComposerBodyText,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\n\n// Based on: https://github.com/ianstormtaylor/slate/blob/main/site/examples/paste-html.tsx\n\ntype OmitTextChildren<T> = Omit<T, \"text\" | \"children\">;\n\ntype ComposerBodyElementTag = OmitTextChildren<\n ComposerBodyBlockElement | ComposerBodyInlineElement\n>;\ntype ComposerBodyTextTag = OmitTextChildren<ComposerBodyText>;\n\ntype DeserializedNode =\n | null\n | string\n | Descendant\n | Descendant[]\n | DeserializedNode[];\n\nfunction areUrlsEqual(a: string, b: string) {\n try {\n const urlA = new URL(a);\n const urlB = new URL(b);\n\n return urlA.origin === urlB.origin && urlA.pathname === urlB.pathname;\n } catch {\n return false;\n }\n}\n\nconst createParagraphElement = (): OmitTextChildren<ComposerBodyParagraph> => ({\n type: \"paragraph\",\n});\n\nconst ELEMENT_TAGS = {\n A: (\n element\n ): OmitTextChildren<ComposerBodyCustomLink | ComposerBodyAutoLink> => {\n const href = element.getAttribute(\"href\");\n const innerText = element.innerText;\n\n return {\n type: href && areUrlsEqual(href, innerText) ? \"auto-link\" : \"custom-link\",\n url: href ?? \"\",\n };\n },\n P: createParagraphElement,\n // Falling back to paragraphs for unsupported elements\n BLOCKQUOTE: createParagraphElement,\n H1: createParagraphElement,\n H2: createParagraphElement,\n H3: createParagraphElement,\n H4: createParagraphElement,\n H5: createParagraphElement,\n H6: createParagraphElement,\n LI: createParagraphElement,\n} as Record<string, (node: HTMLElement) => ComposerBodyElementTag>;\n\nconst TEXT_TAGS = {\n CODE: (): ComposerBodyTextTag => ({ code: true }),\n DEL: (): ComposerBodyTextTag => ({ strikethrough: true }),\n EM: (): ComposerBodyTextTag => ({ italic: true }),\n I: (): ComposerBodyTextTag => ({ italic: true }),\n S: (): ComposerBodyTextTag => ({ strikethrough: true }),\n STRONG: (): ComposerBodyTextTag => ({ bold: true }),\n B: (): ComposerBodyTextTag => ({ bold: true }),\n} as Record<string, (node: HTMLElement) => ComposerBodyTextTag>;\n\nfunction flattenListItems(node: HTMLElement): HTMLElement[] {\n const listItems: HTMLElement[] = [];\n\n if (node.nodeName === \"LI\") {\n listItems.push(node);\n }\n\n node.childNodes.forEach((child) => {\n if (child.nodeType === 1) {\n listItems.push(...flattenListItems(child as HTMLElement));\n }\n });\n\n return listItems;\n}\n\nfunction jsxTextChildren(\n children: DeserializedNode[],\n attrs?: ComposerBodyTextTag\n) {\n return children.map((child) => jsx(\"text\", attrs, child));\n}\n\nfunction deserialize(node: Node): DeserializedNode {\n if (node.nodeType === 3) {\n return node.textContent;\n } else if (node.nodeType !== 1) {\n return null;\n } else if (node.nodeName === \"BR\") {\n // Insert a new paragraph\n return jsx(\"element\", createParagraphElement(), []);\n }\n\n const childNodes = Array.from(node.childNodes);\n let children = childNodes.map(deserialize).flat();\n\n // Lists aren't supported (yet), so we flatten them into paragraphs\n if (node.nodeName === \"UL\" || node.nodeName === \"OL\") {\n const listItems = flattenListItems(node as HTMLElement);\n\n children = listItems.map((li) => deserialize(li)).flat();\n }\n\n if (children.length === 0) {\n children = [{ text: \"\" }];\n }\n\n if (node.nodeName === \"BODY\") {\n // If the body only contains text nodes, we wrap it in a paragraph\n if (\n children.length > 0 &&\n children.every((child) => typeof child === \"string\")\n ) {\n children = [\n { type: \"paragraph\", children: [{ text: children.join(\"\") }] },\n ];\n }\n\n return jsx(\n \"fragment\",\n {},\n children.filter((child) => typeof child !== \"string\")\n );\n }\n\n if (ELEMENT_TAGS[node.nodeName]) {\n const attrs = ELEMENT_TAGS[node.nodeName]!(node as HTMLElement);\n\n return jsx(\"element\", attrs, children);\n }\n\n if (TEXT_TAGS[node.nodeName]) {\n const attrs = TEXT_TAGS[node.nodeName]!(node as HTMLElement);\n\n // If there is at least one non-text child, we skip this node\n if (\n children.some(\n (child) => child && typeof child !== \"string\" && \"type\" in child\n )\n ) {\n return jsx(\"fragment\", {}, children);\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n // Guess inline marks based on styles\n if (node.nodeName === \"SPAN\") {\n const style = (node as HTMLElement).style;\n const attrs: ComposerBodyTextTag = {};\n\n if (\n style.fontWeight === \"bold\" ||\n style.fontWeight === \"700\" ||\n style.fontWeight === \"800\" ||\n style.fontWeight === \"900\"\n ) {\n attrs.bold = true;\n }\n\n if (style.fontStyle === \"italic\") {\n attrs.italic = true;\n }\n\n if (style.textDecoration === \"line-through\") {\n attrs.strikethrough = true;\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n return children as DeserializedNode;\n}\n\nexport function withPaste(\n editor: Editor,\n {\n createAttachments,\n pasteFilesAsAttachments,\n }: {\n createAttachments: (files: File[]) => void;\n pasteFilesAsAttachments?: boolean;\n }\n) {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n // Create attachments from files when pasting\n if (data.types.includes(\"Files\") && pasteFilesAsAttachments) {\n const files = getFiles(data);\n\n if (files.length > 0) {\n createAttachments(files);\n\n return;\n }\n }\n\n // Deserialize rich text from HTML when pasting (unless there's also Slate data)\n if (\n data.types.includes(\"text/html\") &&\n !data.types.includes(\"application/x-slate-fragment\")\n ) {\n const html = data.getData(\"text/html\");\n\n try {\n const { body } = new DOMParser().parseFromString(html, \"text/html\");\n\n // WebKit browsers can add a trailing `<br>`\n body.querySelector(\"br.Apple-interchange-newline\")?.remove();\n\n // Google Docs can use `<b>` as a wrapper for the entire document,\n // it shouldn't be supported so we remove it\n if (body.children.length === 1 && body.children[0]?.nodeName === \"B\") {\n const wrapper = body.children[0] as HTMLElement;\n\n while (wrapper.firstChild) {\n body.insertBefore(wrapper.firstChild, wrapper);\n }\n\n body.removeChild(wrapper);\n }\n\n const fragment = deserialize(body);\n\n if (fragment !== null && Array.isArray(fragment)) {\n Transforms.insertFragment(editor, fragment as SlateNode[]);\n\n return;\n }\n } catch {\n // Fallback to default `insertData` behavior\n }\n }\n\n // Default `insertData` behavior\n insertData(data);\n };\n\n return editor;\n}\n"],"names":[],"mappings":";;;;AA8BA,SAAS,YAAA,CAAa,GAAW,CAAW,EAAA;AAC1C,EAAI,IAAA;AACF,IAAM,MAAA,IAAA,GAAO,IAAI,GAAA,CAAI,CAAC,CAAA,CAAA;AACtB,IAAM,MAAA,IAAA,GAAO,IAAI,GAAA,CAAI,CAAC,CAAA,CAAA;AAEtB,IAAA,OAAO,KAAK,MAAW,KAAA,IAAA,CAAK,MAAU,IAAA,IAAA,CAAK,aAAa,IAAK,CAAA,QAAA,CAAA;AAAA,GAC7D,CAAA,MAAA;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF,CAAA;AAEA,MAAM,yBAAyB,OAAgD;AAAA,EAC7E,IAAM,EAAA,WAAA;AACR,CAAA,CAAA,CAAA;AAEA,MAAM,YAAe,GAAA;AAAA,EACnB,CAAA,EAAG,CACD,OACoE,KAAA;AACpE,IAAM,MAAA,IAAA,GAAO,OAAQ,CAAA,YAAA,CAAa,MAAM,CAAA,CAAA;AACxC,IAAA,MAAM,YAAY,OAAQ,CAAA,SAAA,CAAA;AAE1B,IAAO,OAAA;AAAA,MACL,MAAM,IAAQ,IAAA,YAAA,CAAa,IAAM,EAAA,SAAS,IAAI,WAAc,GAAA,aAAA;AAAA,MAC5D,KAAK,IAAQ,IAAA,EAAA;AAAA,KACf,CAAA;AAAA,GACF;AAAA,EACA,CAAG,EAAA,sBAAA;AAAA,EAEH,UAAY,EAAA,sBAAA;AAAA,EACZ,EAAI,EAAA,sBAAA;AAAA,EACJ,EAAI,EAAA,sBAAA;AAAA,EACJ,EAAI,EAAA,sBAAA;AAAA,EACJ,EAAI,EAAA,sBAAA;AAAA,EACJ,EAAI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,MAAW,KAAA,CAAA,IAAK,KAAK,QAAS,CAAA,CAAA,CAAA,EAAI,aAAa,GAAK,EAAA;AACpE,UAAM,MAAA,OAAA,GAAU,KAAK,QAAS,CAAA,CAAA,CAAA,CAAA;AAE9B,UAAA,OAAO,QAAQ,UAAY,EAAA;AACzB,YAAK,IAAA,CAAA,YAAA,CAAa,OAAQ,CAAA,UAAA,EAAY,OAAO,CAAA,CAAA;AAAA,WAC/C;AAEA,UAAA,IAAA,CAAK,YAAY,OAAO,CAAA,CAAA;AAAA,SAC1B;AAEA,QAAM,MAAA,QAAA,GAAW,YAAY,IAAI,CAAA,CAAA;AAEjC,QAAA,IAAI,QAAa,KAAA,IAAA,IAAQ,KAAM,CAAA,OAAA,CAAQ,QAAQ,CAAG,EAAA;AAChD,UAAW,UAAA,CAAA,cAAA,CAAe,QAAQ,QAAuB,CAAA,CAAA;AAEzD,UAAA,OAAA;AAAA,SACF;AAAA,OACA,CAAA,MAAA;AAAA,OAEF;AAAA,KACF;AAGA,IAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAAA,GACjB,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"paste.js","sources":["../../../src/slate/plugins/paste.ts"],"sourcesContent":["import type { Descendant, Editor, Node as SlateNode } from \"slate\";\nimport { Transforms } from \"slate\";\nimport { jsx } from \"slate-hyperscript\";\n\nimport type {\n ComposerBodyAutoLink,\n ComposerBodyBlockElement,\n ComposerBodyCustomLink,\n ComposerBodyInlineElement,\n ComposerBodyParagraph,\n ComposerBodyText,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\n\n// Based on: https://github.com/ianstormtaylor/slate/blob/main/site/examples/paste-html.tsx\n\nconst NEWLINE_REGEX = /[\\r\\n]/g;\nconst WHITESPACE_REGEX = /\\s+/g;\n\ntype OmitTextChildren<T> = Omit<T, \"text\" | \"children\">;\n\ntype ComposerBodyElementTag = OmitTextChildren<\n ComposerBodyBlockElement | ComposerBodyInlineElement\n>;\ntype ComposerBodyTextTag = OmitTextChildren<ComposerBodyText>;\n\ntype DeserializedNode =\n | null\n | string\n | Descendant\n | Descendant[]\n | DeserializedNode[];\n\nfunction areUrlsEqual(a: string, b: string) {\n try {\n const urlA = new URL(a);\n const urlB = new URL(b);\n\n return urlA.origin === urlB.origin && urlA.pathname === urlB.pathname;\n } catch {\n return false;\n }\n}\n\nconst createParagraphElement = (): OmitTextChildren<ComposerBodyParagraph> => ({\n type: \"paragraph\",\n});\n\nconst ELEMENT_TAGS = {\n A: (\n element\n ): OmitTextChildren<ComposerBodyCustomLink | ComposerBodyAutoLink> => {\n const href = element.getAttribute(\"href\");\n const innerText = element.innerText;\n\n return {\n type: href && areUrlsEqual(href, innerText) ? \"auto-link\" : \"custom-link\",\n url: href ?? \"\",\n };\n },\n P: createParagraphElement,\n // Falling back to paragraphs for unsupported elements\n BLOCKQUOTE: createParagraphElement,\n H1: createParagraphElement,\n H2: createParagraphElement,\n H3: createParagraphElement,\n H4: createParagraphElement,\n H5: createParagraphElement,\n H6: createParagraphElement,\n LI: createParagraphElement,\n} as Record<string, (node: HTMLElement) => ComposerBodyElementTag>;\n\nconst TEXT_TAGS = {\n CODE: (): ComposerBodyTextTag => ({ code: true }),\n DEL: (): ComposerBodyTextTag => ({ strikethrough: true }),\n EM: (): ComposerBodyTextTag => ({ italic: true }),\n I: (): ComposerBodyTextTag => ({ italic: true }),\n S: (): ComposerBodyTextTag => ({ strikethrough: true }),\n STRONG: (): ComposerBodyTextTag => ({ bold: true }),\n B: (): ComposerBodyTextTag => ({ bold: true }),\n} as Record<string, (node: HTMLElement) => ComposerBodyTextTag>;\n\nfunction flattenListItems(node: HTMLElement): HTMLElement[] {\n const listItems: HTMLElement[] = [];\n\n if (node.nodeName === \"LI\") {\n listItems.push(node);\n }\n\n node.childNodes.forEach((child) => {\n if (child.nodeType === 1) {\n listItems.push(...flattenListItems(child as HTMLElement));\n }\n });\n\n return listItems;\n}\n\nfunction jsxTextChildren(\n children: DeserializedNode[],\n attrs?: ComposerBodyTextTag\n) {\n return children.map((child) => jsx(\"text\", attrs, child));\n}\n\nfunction deserialize(node: Node): DeserializedNode {\n if (node.nodeType === 3) {\n let text = node.textContent;\n const isMultiLine = text && NEWLINE_REGEX.test(text);\n\n if (text && isMultiLine) {\n text = text.replace(WHITESPACE_REGEX, \" \").trim();\n }\n\n return text ? { text } : null;\n } else if (node.nodeType !== 1) {\n return null;\n } else if (node.nodeName === \"BR\") {\n // Insert a new paragraph\n return jsx(\"element\", createParagraphElement(), []);\n }\n\n const childNodes = Array.from(node.childNodes);\n let children = childNodes.map(deserialize).flat();\n\n // Lists aren't supported (yet), so we flatten them into paragraphs\n if (node.nodeName === \"UL\" || node.nodeName === \"OL\") {\n const listItems = flattenListItems(node as HTMLElement);\n\n children = listItems.map((li) => deserialize(li)).flat();\n }\n\n if (children.length === 0) {\n children = [{ text: \"\" }];\n }\n\n if (node.nodeName === \"BODY\") {\n // If the body only contains text nodes, we wrap it in a paragraph\n if (\n children.length > 0 &&\n children.every((child) => typeof child === \"string\")\n ) {\n children = [\n { type: \"paragraph\", children: [{ text: children.join(\"\") }] },\n ];\n }\n\n return jsx(\n \"fragment\",\n {},\n children.filter((child) => typeof child !== \"string\")\n );\n }\n\n if (ELEMENT_TAGS[node.nodeName]) {\n const attrs = ELEMENT_TAGS[node.nodeName]!(node as HTMLElement);\n\n return jsx(\"element\", attrs, children);\n }\n\n if (TEXT_TAGS[node.nodeName]) {\n const attrs = TEXT_TAGS[node.nodeName]!(node as HTMLElement);\n\n // If there is at least one non-text child, we skip this node\n if (\n children.some(\n (child) => child && typeof child !== \"string\" && \"type\" in child\n )\n ) {\n return jsx(\"fragment\", {}, children);\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n // Guess inline marks based on styles\n if (node.nodeName === \"SPAN\") {\n const style = (node as HTMLElement).style;\n const attrs: ComposerBodyTextTag = {};\n\n if (\n style.fontWeight === \"bold\" ||\n style.fontWeight === \"700\" ||\n style.fontWeight === \"800\" ||\n style.fontWeight === \"900\"\n ) {\n attrs.bold = true;\n }\n\n if (style.fontStyle === \"italic\") {\n attrs.italic = true;\n }\n\n if (style.textDecoration === \"line-through\") {\n attrs.strikethrough = true;\n }\n\n return jsxTextChildren(children, attrs);\n }\n\n return children as DeserializedNode;\n}\n\nexport function withPaste(\n editor: Editor,\n {\n createAttachments,\n pasteFilesAsAttachments,\n }: {\n createAttachments: (files: File[]) => void;\n pasteFilesAsAttachments?: boolean;\n }\n) {\n const { insertData } = editor;\n\n editor.insertData = (data) => {\n // Create attachments from files when pasting\n if (data.types.includes(\"Files\") && pasteFilesAsAttachments) {\n const files = getFiles(data);\n\n if (files.length > 0) {\n createAttachments(files);\n\n return;\n }\n }\n\n // Deserialize rich text from HTML when pasting (unless there's also Slate data)\n if (\n data.types.includes(\"text/html\") &&\n !data.types.includes(\"application/x-slate-fragment\")\n ) {\n const html = data.getData(\"text/html\");\n\n try {\n const { body } = new DOMParser().parseFromString(html, \"text/html\");\n\n // WebKit browsers can add a trailing `<br>`\n body.querySelector(\"br.Apple-interchange-newline\")?.remove();\n\n // Google Docs can use `<b>` as a wrapper for the entire document,\n // it shouldn't be supported so we remove it\n if (body.children.length === 1 && body.children[0]?.nodeName === \"B\") {\n const wrapper = body.children[0] as HTMLElement;\n\n while (wrapper.firstChild) {\n body.insertBefore(wrapper.firstChild, wrapper);\n }\n\n body.removeChild(wrapper);\n }\n\n const fragment = deserialize(body);\n\n if (fragment !== null && Array.isArray(fragment)) {\n Transforms.insertFragment(editor, fragment as SlateNode[]);\n\n return;\n }\n } catch {\n // Fallback to default `insertData` behavior\n }\n }\n\n // Default `insertData` behavior\n insertData(data);\n };\n\n return editor;\n}\n"],"names":[],"mappings":";;;;AAgBA,MAAM,aAAgB,GAAA,SAAA,CAAA;AACtB,MAAM,gBAAmB,GAAA,MAAA,CAAA;AAgBzB,SAAS,YAAA,CAAa,GAAW,CAAW,EAAA;AAC1C,EAAI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3D,QAAI,IAAA,IAAA,CAAK,SAAS,MAAW,KAAA,CAAA,IAAK,KAAK,QAAS,CAAA,CAAA,CAAA,EAAI,aAAa,GAAK,EAAA;AACpE,UAAM,MAAA,OAAA,GAAU,KAAK,QAAS,CAAA,CAAA,CAAA,CAAA;AAE9B,UAAA,OAAO,QAAQ,UAAY,EAAA;AACzB,YAAK,IAAA,CAAA,YAAA,CAAa,OAAQ,CAAA,UAAA,EAAY,OAAO,CAAA,CAAA;AAAA,WAC/C;AAEA,UAAA,IAAA,CAAK,YAAY,OAAO,CAAA,CAAA;AAAA,SAC1B;AAEA,QAAM,MAAA,QAAA,GAAW,YAAY,IAAI,CAAA,CAAA;AAEjC,QAAA,IAAI,QAAa,KAAA,IAAA,IAAQ,KAAM,CAAA,OAAA,CAAQ,QAAQ,CAAG,EAAA;AAChD,UAAW,UAAA,CAAA,cAAA,CAAe,QAAQ,QAAuB,CAAA,CAAA;AAEzD,UAAA,OAAA;AAAA,SACF;AAAA,OACA,CAAA,MAAA;AAAA,OAEF;AAAA,KACF;AAGA,IAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAAA,GACjB,CAAA;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
@@ -53,8 +53,8 @@ function getMatchRange(editor, at, terminators = [" "], options = defaultOptions
|
|
|
53
53
|
}
|
|
54
54
|
if (include) {
|
|
55
55
|
return {
|
|
56
|
-
anchor: slate.Editor.before(editor, start, { unit: "offset" }) ?? start,
|
|
57
|
-
focus: slate.Editor.after(editor, end, { unit: "offset" }) ?? end
|
|
56
|
+
anchor: direction === "before" || direction === "both" ? slate.Editor.before(editor, start, { unit: "offset" }) ?? start : start,
|
|
57
|
+
focus: direction === "after" || direction === "both" ? slate.Editor.after(editor, end, { unit: "offset" }) ?? end : end
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
return { anchor: start, focus: end };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-match-range.cjs","sources":["../../../src/slate/utils/get-match-range.ts"],"sourcesContent":["import type { Point as SlatePoint } from \"slate\";\nimport {\n Editor as SlateEditor,\n Path as SlatePath,\n Range as SlateRange,\n} from \"slate\";\n\nimport { isWhitespaceCharacter } from \"./is-whitespace-character\";\n\ninterface Options {\n include?: boolean;\n direction?: \"before\" | \"after\" | \"both\";\n allowConsecutiveWhitespace?: boolean;\n ignoreTerminator?: (\n character: string,\n point: SlatePoint,\n direction: \"before\" | \"after\"\n ) => boolean;\n}\n\nconst defaultOptions: Options = {\n direction: \"before\",\n allowConsecutiveWhitespace: true,\n};\n\nexport function getMatchRange(\n editor: SlateEditor,\n at: SlateRange,\n terminators: string[] = [\" \"],\n options: Options = defaultOptions\n): SlateRange | undefined {\n const { include, direction, ignoreTerminator, allowConsecutiveWhitespace } = {\n ...defaultOptions,\n ...options,\n };\n\n let [start, end] = SlateRange.edges(at);\n let point: SlatePoint = start;\n let previousCharacterWasWhitespace = false;\n\n function move(direction: \"before\" | \"after\"): boolean {\n const nextPoint =\n direction === \"after\"\n ? SlateEditor.after(editor, point, { unit: \"character\" })\n : SlateEditor.before(editor, point, { unit: \"character\" });\n\n // Stop if we reached the end of a block\n if (!nextPoint || SlatePath.compare(nextPoint.path, point.path) !== 0) {\n return false;\n }\n\n const nextCharacter =\n nextPoint &&\n SlateEditor.string(\n editor,\n direction === \"after\"\n ? { anchor: point, focus: nextPoint }\n : { anchor: nextPoint, focus: point }\n );\n const lastCharacter =\n nextCharacter &&\n nextCharacter[direction === \"after\" ? 0 : nextCharacter.length - 1];\n\n if (\n !allowConsecutiveWhitespace &&\n previousCharacterWasWhitespace &&\n isWhitespaceCharacter(lastCharacter)\n ) {\n return false;\n }\n\n if (\n nextPoint &&\n lastCharacter &&\n (!terminators.includes(lastCharacter) ||\n ignoreTerminator?.(lastCharacter, nextPoint, direction))\n ) {\n previousCharacterWasWhitespace = isWhitespaceCharacter(lastCharacter);\n point = nextPoint;\n\n if (point.offset === 0) {\n return false;\n }\n } else {\n return false;\n }\n\n return true;\n }\n\n if (direction !== \"before\") {\n point = end;\n while (move(\"after\"));\n end = point;\n }\n\n if (direction !== \"after\") {\n point = start;\n while (move(\"before\"));\n start = point;\n }\n\n if (include) {\n return {\n anchor
|
|
1
|
+
{"version":3,"file":"get-match-range.cjs","sources":["../../../src/slate/utils/get-match-range.ts"],"sourcesContent":["import type { Point as SlatePoint } from \"slate\";\nimport {\n Editor as SlateEditor,\n Path as SlatePath,\n Range as SlateRange,\n} from \"slate\";\n\nimport { isWhitespaceCharacter } from \"./is-whitespace-character\";\n\ninterface Options {\n include?: boolean;\n direction?: \"before\" | \"after\" | \"both\";\n allowConsecutiveWhitespace?: boolean;\n ignoreTerminator?: (\n character: string,\n point: SlatePoint,\n direction: \"before\" | \"after\"\n ) => boolean;\n}\n\nconst defaultOptions: Options = {\n direction: \"before\",\n allowConsecutiveWhitespace: true,\n};\n\nexport function getMatchRange(\n editor: SlateEditor,\n at: SlateRange,\n terminators: string[] = [\" \"],\n options: Options = defaultOptions\n): SlateRange | undefined {\n const { include, direction, ignoreTerminator, allowConsecutiveWhitespace } = {\n ...defaultOptions,\n ...options,\n };\n\n let [start, end] = SlateRange.edges(at);\n let point: SlatePoint = start;\n let previousCharacterWasWhitespace = false;\n\n function move(direction: \"before\" | \"after\"): boolean {\n const nextPoint =\n direction === \"after\"\n ? SlateEditor.after(editor, point, { unit: \"character\" })\n : SlateEditor.before(editor, point, { unit: \"character\" });\n\n // Stop if we reached the end of a block\n if (!nextPoint || SlatePath.compare(nextPoint.path, point.path) !== 0) {\n return false;\n }\n\n const nextCharacter =\n nextPoint &&\n SlateEditor.string(\n editor,\n direction === \"after\"\n ? { anchor: point, focus: nextPoint }\n : { anchor: nextPoint, focus: point }\n );\n const lastCharacter =\n nextCharacter &&\n nextCharacter[direction === \"after\" ? 0 : nextCharacter.length - 1];\n\n if (\n !allowConsecutiveWhitespace &&\n previousCharacterWasWhitespace &&\n isWhitespaceCharacter(lastCharacter)\n ) {\n return false;\n }\n\n if (\n nextPoint &&\n lastCharacter &&\n (!terminators.includes(lastCharacter) ||\n ignoreTerminator?.(lastCharacter, nextPoint, direction))\n ) {\n previousCharacterWasWhitespace = isWhitespaceCharacter(lastCharacter);\n point = nextPoint;\n\n if (point.offset === 0) {\n return false;\n }\n } else {\n return false;\n }\n\n return true;\n }\n\n if (direction !== \"before\") {\n point = end;\n while (move(\"after\"));\n end = point;\n }\n\n if (direction !== \"after\") {\n point = start;\n while (move(\"before\"));\n start = point;\n }\n\n if (include) {\n return {\n anchor:\n direction === \"before\" || direction === \"both\"\n ? (SlateEditor.before(editor, start, { unit: \"offset\" }) ?? start)\n : start,\n focus:\n direction === \"after\" || direction === \"both\"\n ? (SlateEditor.after(editor, end, { unit: \"offset\" }) ?? end)\n : end,\n };\n }\n\n return { anchor: start, focus: end };\n}\n"],"names":["SlateRange","direction","SlateEditor","SlatePath","isWhitespaceCharacter"],"mappings":";;;;;AAoBA,MAAM,cAA0B,GAAA;AAAA,EAC9B,SAAW,EAAA,QAAA;AAAA,EACX,0BAA4B,EAAA,IAAA;AAC9B,CAAA,CAAA;AAEgB,SAAA,aAAA,CACd,QACA,EACA,EAAA,WAAA,GAAwB,CAAC,GAAG,CAAA,EAC5B,UAAmB,cACK,EAAA;AACxB,EAAA,MAAM,EAAE,OAAA,EAAS,SAAW,EAAA,gBAAA,EAAkB,4BAA+B,GAAA;AAAA,IAC3E,GAAG,cAAA;AAAA,IACH,GAAG,OAAA;AAAA,GACL,CAAA;AAEA,EAAA,IAAI,CAAC,KAAO,EAAA,GAAG,CAAI,GAAAA,WAAA,CAAW,MAAM,EAAE,CAAA,CAAA;AACtC,EAAA,IAAI,KAAoB,GAAA,KAAA,CAAA;AACxB,EAAA,IAAI,8BAAiC,GAAA,KAAA,CAAA;AAErC,EAAA,SAAS,KAAKC,UAAwC,EAAA;AACpD,IAAA,MAAM,YACJA,UAAc,KAAA,OAAA,GACVC,aAAY,KAAM,CAAA,MAAA,EAAQ,OAAO,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AA,GAAA,CAAA;AACR,IAAA,OAAO,KAAK,OAAO,CAAA;AAAE,MAAA,CAAA;AACrB,IAAM,GAAA,GAAA,KAAA,CAAA;AAAA,GACR;AAEA,EAAA,IAAI,cAAc,OAAS,EAAA;AACzB,IAAQ,KAAA,GAAA,KAAA,CAAA;AACR,IAAA,OAAO,KAAK,QAAQ,CAAA;AAAE,MAAA,CAAA;AACtB,IAAQ,KAAA,GAAA,KAAA,CAAA;AAAA,GACV;AAEA,EAAA,IAAI,OAAS,EAAA;AACX,IAAO,OAAA;AAAA,MACL,MACE,EAAA,SAAA,KAAc,QAAY,IAAA,SAAA,KAAc,SACnCF,YAAY,CAAA,MAAA,CAAO,MAAQ,EAAA,KAAA,EAAO,EAAE,IAAA,EAAM,QAAS,EAAC,KAAK,KAC1D,GAAA,KAAA;AAAA,MACN,KACE,EAAA,SAAA,KAAc,OAAW,IAAA,SAAA,KAAc,SAClCA,YAAY,CAAA,KAAA,CAAM,MAAQ,EAAA,GAAA,EAAK,EAAE,IAAA,EAAM,QAAS,EAAC,KAAK,GACvD,GAAA,GAAA;AAAA,KACR,CAAA;AAAA,GACF;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAO,EAAA,KAAA,EAAO,GAAI,EAAA,CAAA;AACrC;;;;"}
|
|
@@ -51,8 +51,8 @@ function getMatchRange(editor, at, terminators = [" "], options = defaultOptions
|
|
|
51
51
|
}
|
|
52
52
|
if (include) {
|
|
53
53
|
return {
|
|
54
|
-
anchor: Editor.before(editor, start, { unit: "offset" }) ?? start,
|
|
55
|
-
focus: Editor.after(editor, end, { unit: "offset" }) ?? end
|
|
54
|
+
anchor: direction === "before" || direction === "both" ? Editor.before(editor, start, { unit: "offset" }) ?? start : start,
|
|
55
|
+
focus: direction === "after" || direction === "both" ? Editor.after(editor, end, { unit: "offset" }) ?? end : end
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
return { anchor: start, focus: end };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-match-range.js","sources":["../../../src/slate/utils/get-match-range.ts"],"sourcesContent":["import type { Point as SlatePoint } from \"slate\";\nimport {\n Editor as SlateEditor,\n Path as SlatePath,\n Range as SlateRange,\n} from \"slate\";\n\nimport { isWhitespaceCharacter } from \"./is-whitespace-character\";\n\ninterface Options {\n include?: boolean;\n direction?: \"before\" | \"after\" | \"both\";\n allowConsecutiveWhitespace?: boolean;\n ignoreTerminator?: (\n character: string,\n point: SlatePoint,\n direction: \"before\" | \"after\"\n ) => boolean;\n}\n\nconst defaultOptions: Options = {\n direction: \"before\",\n allowConsecutiveWhitespace: true,\n};\n\nexport function getMatchRange(\n editor: SlateEditor,\n at: SlateRange,\n terminators: string[] = [\" \"],\n options: Options = defaultOptions\n): SlateRange | undefined {\n const { include, direction, ignoreTerminator, allowConsecutiveWhitespace } = {\n ...defaultOptions,\n ...options,\n };\n\n let [start, end] = SlateRange.edges(at);\n let point: SlatePoint = start;\n let previousCharacterWasWhitespace = false;\n\n function move(direction: \"before\" | \"after\"): boolean {\n const nextPoint =\n direction === \"after\"\n ? SlateEditor.after(editor, point, { unit: \"character\" })\n : SlateEditor.before(editor, point, { unit: \"character\" });\n\n // Stop if we reached the end of a block\n if (!nextPoint || SlatePath.compare(nextPoint.path, point.path) !== 0) {\n return false;\n }\n\n const nextCharacter =\n nextPoint &&\n SlateEditor.string(\n editor,\n direction === \"after\"\n ? { anchor: point, focus: nextPoint }\n : { anchor: nextPoint, focus: point }\n );\n const lastCharacter =\n nextCharacter &&\n nextCharacter[direction === \"after\" ? 0 : nextCharacter.length - 1];\n\n if (\n !allowConsecutiveWhitespace &&\n previousCharacterWasWhitespace &&\n isWhitespaceCharacter(lastCharacter)\n ) {\n return false;\n }\n\n if (\n nextPoint &&\n lastCharacter &&\n (!terminators.includes(lastCharacter) ||\n ignoreTerminator?.(lastCharacter, nextPoint, direction))\n ) {\n previousCharacterWasWhitespace = isWhitespaceCharacter(lastCharacter);\n point = nextPoint;\n\n if (point.offset === 0) {\n return false;\n }\n } else {\n return false;\n }\n\n return true;\n }\n\n if (direction !== \"before\") {\n point = end;\n while (move(\"after\"));\n end = point;\n }\n\n if (direction !== \"after\") {\n point = start;\n while (move(\"before\"));\n start = point;\n }\n\n if (include) {\n return {\n anchor
|
|
1
|
+
{"version":3,"file":"get-match-range.js","sources":["../../../src/slate/utils/get-match-range.ts"],"sourcesContent":["import type { Point as SlatePoint } from \"slate\";\nimport {\n Editor as SlateEditor,\n Path as SlatePath,\n Range as SlateRange,\n} from \"slate\";\n\nimport { isWhitespaceCharacter } from \"./is-whitespace-character\";\n\ninterface Options {\n include?: boolean;\n direction?: \"before\" | \"after\" | \"both\";\n allowConsecutiveWhitespace?: boolean;\n ignoreTerminator?: (\n character: string,\n point: SlatePoint,\n direction: \"before\" | \"after\"\n ) => boolean;\n}\n\nconst defaultOptions: Options = {\n direction: \"before\",\n allowConsecutiveWhitespace: true,\n};\n\nexport function getMatchRange(\n editor: SlateEditor,\n at: SlateRange,\n terminators: string[] = [\" \"],\n options: Options = defaultOptions\n): SlateRange | undefined {\n const { include, direction, ignoreTerminator, allowConsecutiveWhitespace } = {\n ...defaultOptions,\n ...options,\n };\n\n let [start, end] = SlateRange.edges(at);\n let point: SlatePoint = start;\n let previousCharacterWasWhitespace = false;\n\n function move(direction: \"before\" | \"after\"): boolean {\n const nextPoint =\n direction === \"after\"\n ? SlateEditor.after(editor, point, { unit: \"character\" })\n : SlateEditor.before(editor, point, { unit: \"character\" });\n\n // Stop if we reached the end of a block\n if (!nextPoint || SlatePath.compare(nextPoint.path, point.path) !== 0) {\n return false;\n }\n\n const nextCharacter =\n nextPoint &&\n SlateEditor.string(\n editor,\n direction === \"after\"\n ? { anchor: point, focus: nextPoint }\n : { anchor: nextPoint, focus: point }\n );\n const lastCharacter =\n nextCharacter &&\n nextCharacter[direction === \"after\" ? 0 : nextCharacter.length - 1];\n\n if (\n !allowConsecutiveWhitespace &&\n previousCharacterWasWhitespace &&\n isWhitespaceCharacter(lastCharacter)\n ) {\n return false;\n }\n\n if (\n nextPoint &&\n lastCharacter &&\n (!terminators.includes(lastCharacter) ||\n ignoreTerminator?.(lastCharacter, nextPoint, direction))\n ) {\n previousCharacterWasWhitespace = isWhitespaceCharacter(lastCharacter);\n point = nextPoint;\n\n if (point.offset === 0) {\n return false;\n }\n } else {\n return false;\n }\n\n return true;\n }\n\n if (direction !== \"before\") {\n point = end;\n while (move(\"after\"));\n end = point;\n }\n\n if (direction !== \"after\") {\n point = start;\n while (move(\"before\"));\n start = point;\n }\n\n if (include) {\n return {\n anchor:\n direction === \"before\" || direction === \"both\"\n ? (SlateEditor.before(editor, start, { unit: \"offset\" }) ?? start)\n : start,\n focus:\n direction === \"after\" || direction === \"both\"\n ? (SlateEditor.after(editor, end, { unit: \"offset\" }) ?? end)\n : end,\n };\n }\n\n return { anchor: start, focus: end };\n}\n"],"names":["SlateRange","direction","SlateEditor","SlatePath"],"mappings":";;;AAoBA,MAAM,cAA0B,GAAA;AAAA,EAC9B,SAAW,EAAA,QAAA;AAAA,EACX,0BAA4B,EAAA,IAAA;AAC9B,CAAA,CAAA;AAEgB,SAAA,aAAA,CACd,QACA,EACA,EAAA,WAAA,GAAwB,CAAC,GAAG,CAAA,EAC5B,UAAmB,cACK,EAAA;AACxB,EAAA,MAAM,EAAE,OAAA,EAAS,SAAW,EAAA,gBAAA,EAAkB,4BAA+B,GAAA;AAAA,IAC3E,GAAG,cAAA;AAAA,IACH,GAAG,OAAA;AAAA,GACL,CAAA;AAEA,EAAA,IAAI,CAAC,KAAO,EAAA,GAAG,CAAI,GAAAA,KAAA,CAAW,MAAM,EAAE,CAAA,CAAA;AACtC,EAAA,IAAI,KAAoB,GAAA,KAAA,CAAA;AACxB,EAAA,IAAI,8BAAiC,GAAA,KAAA,CAAA;AAErC,EAAA,SAAS,KAAKC,UAAwC,EAAA;AACpD,IAAA,MAAM,YACJA,UAAc,KAAA,OAAA,GACVC,OAAY,KAAM,CAAA,MAAA,EAAQ,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,GAAA,GAAA,CAAA;AACR,IAAA,OAAO,KAAK,OAAO,CAAA;AAAE,MAAA,CAAA;AACrB,IAAM,GAAA,GAAA,KAAA,CAAA;AAAA,GACR;AAEA,EAAA,IAAI,cAAc,OAAS,EAAA;AACzB,IAAQ,KAAA,GAAA,KAAA,CAAA;AACR,IAAA,OAAO,KAAK,QAAQ,CAAA;AAAE,MAAA,CAAA;AACtB,IAAQ,KAAA,GAAA,KAAA,CAAA;AAAA,GACV;AAEA,EAAA,IAAI,OAAS,EAAA;AACX,IAAO,OAAA;AAAA,MACL,MACE,EAAA,SAAA,KAAc,QAAY,IAAA,SAAA,KAAc,SACnCC,MAAY,CAAA,MAAA,CAAO,MAAQ,EAAA,KAAA,EAAO,EAAE,IAAA,EAAM,QAAS,EAAC,KAAK,KAC1D,GAAA,KAAA;AAAA,MACN,KACE,EAAA,SAAA,KAAc,OAAW,IAAA,SAAA,KAAc,SAClCA,MAAY,CAAA,KAAA,CAAM,MAAQ,EAAA,GAAA,EAAK,EAAE,IAAA,EAAM,QAAS,EAAC,KAAK,GACvD,GAAA,GAAA;AAAA,KACR,CAAA;AAAA,GACF;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAO,EAAA,KAAA,EAAO,GAAI,EAAA,CAAA;AACrC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Persist.cjs","sources":["../../src/utils/Persist.tsx"],"sourcesContent":["\"use client\";\n\nimport { nn } from \"@liveblocks/core\";\nimport { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport type { ReactNode, RefObject } from \"react\";\nimport {\n Children,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\n// Persist is an overly simplified version of Framer Motion's AnimatePresence,\n// mostly mimicking its usePresence API: https://github.com/framer/motion/blob/main/packages/framer-motion/src/components/AnimatePresence/use-presence.ts\n\nconst PERSIST_NAME = \"Persist\";\n\ninterface PersistProps {\n children: Exclude<ReactNode, Iterable<ReactNode>>;\n}\n\ntype PersistContext = [boolean, () => void];\n\nconst PersistContext = createContext<PersistContext | null>(null);\n\nexport function usePersist() {\n const persistContext = useContext(PersistContext);\n\n return nn(persistContext, \"Persist is missing from the React tree.\");\n}\n\nfunction getChild(children: ReactNode) {\n const child: ReactNode = Array.isArray(children)\n ? Children.only(children)\n : children;\n\n return isValidElement(child) ? child : undefined;\n}\n\nexport function useAnimationPersist(ref: RefObject<HTMLElement>) {\n const [isPresent, unmount] = usePersist();\n const previousAnimationName = useRef<string | null>(null);\n const unmountAnimationName = useRef<string | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n\n if (!element) {\n return;\n }\n\n /**\n * Stop persisting at the end of the last animation.\n *\n * We keep track of all ending animations because animations stay\n * on getComputedStyle(element).animationName even if they're over,\n * so we need to keep track of previous animations to truly know if\n * an animation should be waited on.\n */\n const handleAnimationEnd = (event: AnimationEvent) => {\n if (event.animationName === unmountAnimationName.current) {\n unmount();\n }\n\n previousAnimationName.current = event.animationName;\n };\n\n element.addEventListener(\"animationcancel\", handleAnimationEnd);\n element.addEventListener(\"animationend\", handleAnimationEnd);\n\n return () => {\n element.removeEventListener(\"animationcancel\", handleAnimationEnd);\n element.removeEventListener(\"animationend\", handleAnimationEnd);\n };\n }, [ref, unmount]);\n\n useLayoutEffect(() => {\n const element = ref.current;\n let animationFrameId: number;\n\n if (!element) {\n return;\n }\n\n if (!isPresent) {\n // If the element should be unmounting, wait for a repaint and check\n // if it is visible and has an animation. If not, unmount immediately.\n animationFrameId = requestAnimationFrame(() => {\n const styles = getComputedStyle(element);\n unmountAnimationName.current = styles.animationName;\n\n if (\n styles.animationName === \"none\" ||\n styles.animationName === previousAnimationName.current ||\n styles.display === \"none\"\n ) {\n unmount();\n }\n });\n }\n\n return () => {\n cancelAnimationFrame(animationFrameId);\n };\n }, [isPresent, ref, unmount]);\n}\n\n/**\n * Persist a component until it decides to unmount by\n * itself (instead of orchestrating the unmount from the parent).\n */\nexport function Persist({ children }: PersistProps) {\n const [isPersisting, setPersisting] = useState(true);\n const lastPresentChild = useRef<ReactNode>(null);\n const child = getChild(children);\n\n const unmount = useCallback(() => {\n flushSync(() => setPersisting(false));\n }, []);\n\n useLayoutEffect(() => {\n if (child) {\n setPersisting(true);\n lastPresentChild.current = child;\n }\n }, [child]);\n\n return (\n <PersistContext.Provider value={[Boolean(child), unmount]}>\n {child ?? (isPersisting ? lastPresentChild.current : null)}\n </PersistContext.Provider>\n );\n}\n\nif (process.env.NODE_ENV !== \"production\") {\n Persist.displayName = PERSIST_NAME;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Persist.cjs","sources":["../../src/utils/Persist.tsx"],"sourcesContent":["\"use client\";\n\nimport { nn } from \"@liveblocks/core\";\nimport { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport type { ReactNode, RefObject } from \"react\";\nimport {\n Children,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\n// Persist is an overly simplified version of Framer Motion's AnimatePresence,\n// mostly mimicking its usePresence API: https://github.com/framer/motion/blob/main/packages/framer-motion/src/components/AnimatePresence/use-presence.ts\n\nconst PERSIST_NAME = \"Persist\";\n\ninterface PersistProps {\n children: Exclude<ReactNode, Iterable<ReactNode>>;\n}\n\ntype PersistContext = [boolean, () => void];\n\nconst PersistContext = createContext<PersistContext | null>(null);\n\nexport function usePersist() {\n const persistContext = useContext(PersistContext);\n\n return nn(persistContext, \"Persist is missing from the React tree.\");\n}\n\nfunction getChild(children: ReactNode) {\n const child: ReactNode = Array.isArray(children)\n ? Children.only(children)\n : children;\n\n return isValidElement(child) ? child : undefined;\n}\n\nexport function useAnimationPersist(ref: RefObject<HTMLElement>) {\n const [isPresent, unmount] = usePersist();\n const previousAnimationName = useRef<string | null>(null);\n const unmountAnimationName = useRef<string | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n\n if (!element) {\n return;\n }\n\n /**\n * Stop persisting at the end of the last animation.\n *\n * We keep track of all ending animations because animations stay\n * on getComputedStyle(element).animationName even if they're over,\n * so we need to keep track of previous animations to truly know if\n * an animation should be waited on.\n */\n const handleAnimationEnd = (event: AnimationEvent) => {\n if (event.animationName === unmountAnimationName.current) {\n unmount();\n }\n\n previousAnimationName.current = event.animationName;\n };\n\n element.addEventListener(\"animationcancel\", handleAnimationEnd);\n element.addEventListener(\"animationend\", handleAnimationEnd);\n\n return () => {\n element.removeEventListener(\"animationcancel\", handleAnimationEnd);\n element.removeEventListener(\"animationend\", handleAnimationEnd);\n };\n }, [ref, unmount]);\n\n useLayoutEffect(() => {\n const element = ref.current;\n let animationFrameId: number;\n\n if (!element) {\n return;\n }\n\n if (!isPresent) {\n // If the element should be unmounting, wait for a repaint and check\n // if it is visible and has an animation. If not, unmount immediately.\n animationFrameId = requestAnimationFrame(() => {\n const styles = getComputedStyle(element);\n unmountAnimationName.current = styles.animationName;\n\n if (\n styles.animationName === \"none\" ||\n styles.animationName === previousAnimationName.current ||\n styles.display === \"none\"\n ) {\n unmount();\n }\n });\n }\n\n return () => {\n cancelAnimationFrame(animationFrameId);\n };\n }, [isPresent, ref, unmount]);\n}\n\n/**\n * Persist a component until it decides to unmount by\n * itself (instead of orchestrating the unmount from the parent).\n */\nexport function Persist({ children }: PersistProps) {\n const [isPersisting, setPersisting] = useState(true);\n const lastPresentChild = useRef<ReactNode>(null);\n const child = getChild(children);\n\n const unmount = useCallback(() => {\n flushSync(() => setPersisting(false));\n }, []);\n\n useLayoutEffect(() => {\n if (child) {\n setPersisting(true);\n lastPresentChild.current = child;\n }\n }, [child]);\n\n return (\n <PersistContext.Provider value={[Boolean(child), unmount]}>\n {child ?? (isPersisting ? lastPresentChild.current : null)}\n </PersistContext.Provider>\n );\n}\n\nif (process.env.NODE_ENV !== \"production\") {\n Persist.displayName = PERSIST_NAME;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAmBA;AAQA;AAEO;AACL;AAEA;AACF;AAEA;AACE;AAIA;AACF;AAEO;AACL;AACA;AACA;AAEA;AACE;AAEA;AACE;AAAA;AAWF;AACE;AACE;AAAQ;AAGV;AAAsC;AAGxC;AACA;AAEA;AACE;AACA;AAA8D;AAChE;AAGF;AACE;AACA;AAEA;AACE;AAAA;AAGF;AAGE;AACE;AACA;AAEA;AAKE;AAAQ;AACV;AACD;AAGH;AACE;AAAqC;AACvC;AAEJ;AAMgB;AACd;AACA;AACA;AAEA;AACE;AAAoC;AAGtC;AACE;AACE;AACA;AAA2B;AAC7B;AAGF;AACG;AAAuD;AACD;AAG3D;AAEA;AACE;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Persist.js","sources":["../../src/utils/Persist.tsx"],"sourcesContent":["\"use client\";\n\nimport { nn } from \"@liveblocks/core\";\nimport { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport type { ReactNode, RefObject } from \"react\";\nimport {\n Children,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\n// Persist is an overly simplified version of Framer Motion's AnimatePresence,\n// mostly mimicking its usePresence API: https://github.com/framer/motion/blob/main/packages/framer-motion/src/components/AnimatePresence/use-presence.ts\n\nconst PERSIST_NAME = \"Persist\";\n\ninterface PersistProps {\n children: Exclude<ReactNode, Iterable<ReactNode>>;\n}\n\ntype PersistContext = [boolean, () => void];\n\nconst PersistContext = createContext<PersistContext | null>(null);\n\nexport function usePersist() {\n const persistContext = useContext(PersistContext);\n\n return nn(persistContext, \"Persist is missing from the React tree.\");\n}\n\nfunction getChild(children: ReactNode) {\n const child: ReactNode = Array.isArray(children)\n ? Children.only(children)\n : children;\n\n return isValidElement(child) ? child : undefined;\n}\n\nexport function useAnimationPersist(ref: RefObject<HTMLElement>) {\n const [isPresent, unmount] = usePersist();\n const previousAnimationName = useRef<string | null>(null);\n const unmountAnimationName = useRef<string | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n\n if (!element) {\n return;\n }\n\n /**\n * Stop persisting at the end of the last animation.\n *\n * We keep track of all ending animations because animations stay\n * on getComputedStyle(element).animationName even if they're over,\n * so we need to keep track of previous animations to truly know if\n * an animation should be waited on.\n */\n const handleAnimationEnd = (event: AnimationEvent) => {\n if (event.animationName === unmountAnimationName.current) {\n unmount();\n }\n\n previousAnimationName.current = event.animationName;\n };\n\n element.addEventListener(\"animationcancel\", handleAnimationEnd);\n element.addEventListener(\"animationend\", handleAnimationEnd);\n\n return () => {\n element.removeEventListener(\"animationcancel\", handleAnimationEnd);\n element.removeEventListener(\"animationend\", handleAnimationEnd);\n };\n }, [ref, unmount]);\n\n useLayoutEffect(() => {\n const element = ref.current;\n let animationFrameId: number;\n\n if (!element) {\n return;\n }\n\n if (!isPresent) {\n // If the element should be unmounting, wait for a repaint and check\n // if it is visible and has an animation. If not, unmount immediately.\n animationFrameId = requestAnimationFrame(() => {\n const styles = getComputedStyle(element);\n unmountAnimationName.current = styles.animationName;\n\n if (\n styles.animationName === \"none\" ||\n styles.animationName === previousAnimationName.current ||\n styles.display === \"none\"\n ) {\n unmount();\n }\n });\n }\n\n return () => {\n cancelAnimationFrame(animationFrameId);\n };\n }, [isPresent, ref, unmount]);\n}\n\n/**\n * Persist a component until it decides to unmount by\n * itself (instead of orchestrating the unmount from the parent).\n */\nexport function Persist({ children }: PersistProps) {\n const [isPersisting, setPersisting] = useState(true);\n const lastPresentChild = useRef<ReactNode>(null);\n const child = getChild(children);\n\n const unmount = useCallback(() => {\n flushSync(() => setPersisting(false));\n }, []);\n\n useLayoutEffect(() => {\n if (child) {\n setPersisting(true);\n lastPresentChild.current = child;\n }\n }, [child]);\n\n return (\n <PersistContext.Provider value={[Boolean(child), unmount]}>\n {child ?? (isPersisting ? lastPresentChild.current : null)}\n </PersistContext.Provider>\n );\n}\n\nif (process.env.NODE_ENV !== \"production\") {\n Persist.displayName = PERSIST_NAME;\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Persist.js","sources":["../../src/utils/Persist.tsx"],"sourcesContent":["\"use client\";\n\nimport { nn } from \"@liveblocks/core\";\nimport { useLayoutEffect } from \"@liveblocks/react/_private\";\nimport type { ReactNode, RefObject } from \"react\";\nimport {\n Children,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useRef,\n useState,\n} from \"react\";\nimport { flushSync } from \"react-dom\";\n\n// Persist is an overly simplified version of Framer Motion's AnimatePresence,\n// mostly mimicking its usePresence API: https://github.com/framer/motion/blob/main/packages/framer-motion/src/components/AnimatePresence/use-presence.ts\n\nconst PERSIST_NAME = \"Persist\";\n\ninterface PersistProps {\n children: Exclude<ReactNode, Iterable<ReactNode>>;\n}\n\ntype PersistContext = [boolean, () => void];\n\nconst PersistContext = createContext<PersistContext | null>(null);\n\nexport function usePersist() {\n const persistContext = useContext(PersistContext);\n\n return nn(persistContext, \"Persist is missing from the React tree.\");\n}\n\nfunction getChild(children: ReactNode) {\n const child: ReactNode = Array.isArray(children)\n ? Children.only(children)\n : children;\n\n return isValidElement(child) ? child : undefined;\n}\n\nexport function useAnimationPersist(ref: RefObject<HTMLElement>) {\n const [isPresent, unmount] = usePersist();\n const previousAnimationName = useRef<string | null>(null);\n const unmountAnimationName = useRef<string | null>(null);\n\n useLayoutEffect(() => {\n const element = ref.current;\n\n if (!element) {\n return;\n }\n\n /**\n * Stop persisting at the end of the last animation.\n *\n * We keep track of all ending animations because animations stay\n * on getComputedStyle(element).animationName even if they're over,\n * so we need to keep track of previous animations to truly know if\n * an animation should be waited on.\n */\n const handleAnimationEnd = (event: AnimationEvent) => {\n if (event.animationName === unmountAnimationName.current) {\n unmount();\n }\n\n previousAnimationName.current = event.animationName;\n };\n\n element.addEventListener(\"animationcancel\", handleAnimationEnd);\n element.addEventListener(\"animationend\", handleAnimationEnd);\n\n return () => {\n element.removeEventListener(\"animationcancel\", handleAnimationEnd);\n element.removeEventListener(\"animationend\", handleAnimationEnd);\n };\n }, [ref, unmount]);\n\n useLayoutEffect(() => {\n const element = ref.current;\n let animationFrameId: number;\n\n if (!element) {\n return;\n }\n\n if (!isPresent) {\n // If the element should be unmounting, wait for a repaint and check\n // if it is visible and has an animation. If not, unmount immediately.\n animationFrameId = requestAnimationFrame(() => {\n const styles = getComputedStyle(element);\n unmountAnimationName.current = styles.animationName;\n\n if (\n styles.animationName === \"none\" ||\n styles.animationName === previousAnimationName.current ||\n styles.display === \"none\"\n ) {\n unmount();\n }\n });\n }\n\n return () => {\n cancelAnimationFrame(animationFrameId);\n };\n }, [isPresent, ref, unmount]);\n}\n\n/**\n * Persist a component until it decides to unmount by\n * itself (instead of orchestrating the unmount from the parent).\n */\nexport function Persist({ children }: PersistProps) {\n const [isPersisting, setPersisting] = useState(true);\n const lastPresentChild = useRef<ReactNode>(null);\n const child = getChild(children);\n\n const unmount = useCallback(() => {\n flushSync(() => setPersisting(false));\n }, []);\n\n useLayoutEffect(() => {\n if (child) {\n setPersisting(true);\n lastPresentChild.current = child;\n }\n }, [child]);\n\n return (\n <PersistContext.Provider value={[Boolean(child), unmount]}>\n {child ?? (isPersisting ? lastPresentChild.current : null)}\n </PersistContext.Provider>\n );\n}\n\nif (process.env.NODE_ENV !== \"production\") {\n Persist.displayName = PERSIST_NAME;\n}\n"],"names":[],"mappings":";;;;;;;;AAmBA;AAQA;AAEO;AACL;AAEA;AACF;AAEA;AACE;AAIA;AACF;AAEO;AACL;AACA;AACA;AAEA;AACE;AAEA;AACE;AAAA;AAWF;AACE;AACE;AAAQ;AAGV;AAAsC;AAGxC;AACA;AAEA;AACE;AACA;AAA8D;AAChE;AAGF;AACE;AACA;AAEA;AACE;AAAA;AAGF;AAGE;AACE;AACA;AAEA;AAKE;AAAQ;AACV;AACD;AAGH;AACE;AAAqC;AACvC;AAEJ;AAMgB;AACd;AACA;AACA;AAEA;AACE;AAAoC;AAGtC;AACE;AACE;AACA;AAA2B;AAC7B;AAGF;AACG;AAAuD;AACD;AAG3D;AAEA;AACE;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Portal.cjs","sources":["../../src/utils/Portal.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { forwardRef } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\n\nconst PORTAL_NAME = \"Portal\";\n\ninterface PortalProps extends ComponentPropsWithSlot<\"div\"> {\n /**\n * The container to render the portal into.\n */\n container?: HTMLElement | null;\n}\n\nconst Portal = forwardRef<HTMLDivElement, PortalProps>(\n ({ container = document?.body, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n\n return container\n ? createPortal(\n <Component data-liveblocks-portal=\"\" {...props} ref={forwardedRef} />,\n container\n )\n : null;\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Portal.displayName = PORTAL_NAME;\n}\n\nexport { Portal };\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Portal.cjs","sources":["../../src/utils/Portal.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { forwardRef } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\n\nconst PORTAL_NAME = \"Portal\";\n\ninterface PortalProps extends ComponentPropsWithSlot<\"div\"> {\n /**\n * The container to render the portal into.\n */\n container?: HTMLElement | null;\n}\n\nconst Portal = forwardRef<HTMLDivElement, PortalProps>(\n ({ container = document?.body, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n\n return container\n ? createPortal(\n <Component data-liveblocks-portal=\"\" {...props} ref={forwardedRef} />,\n container\n )\n : null;\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Portal.displayName = PORTAL_NAME;\n}\n\nexport { Portal };\n"],"names":[],"mappings":";;;;;;;;;AAQA;AASA;AAAe;AAEX;AAEA;AACI;AACG;AAAiC;AAAO;AAAY;AAAc;AACnE;AAEF;AAER;AAEA;AACE;AACF;;"}
|
package/dist/utils/Portal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Portal.js","sources":["../../src/utils/Portal.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { forwardRef } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\n\nconst PORTAL_NAME = \"Portal\";\n\ninterface PortalProps extends ComponentPropsWithSlot<\"div\"> {\n /**\n * The container to render the portal into.\n */\n container?: HTMLElement | null;\n}\n\nconst Portal = forwardRef<HTMLDivElement, PortalProps>(\n ({ container = document?.body, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n\n return container\n ? createPortal(\n <Component data-liveblocks-portal=\"\" {...props} ref={forwardedRef} />,\n container\n )\n : null;\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Portal.displayName = PORTAL_NAME;\n}\n\nexport { Portal };\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Portal.js","sources":["../../src/utils/Portal.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { forwardRef } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport type { ComponentPropsWithSlot } from \"../types\";\n\nconst PORTAL_NAME = \"Portal\";\n\ninterface PortalProps extends ComponentPropsWithSlot<\"div\"> {\n /**\n * The container to render the portal into.\n */\n container?: HTMLElement | null;\n}\n\nconst Portal = forwardRef<HTMLDivElement, PortalProps>(\n ({ container = document?.body, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n\n return container\n ? createPortal(\n <Component data-liveblocks-portal=\"\" {...props} ref={forwardedRef} />,\n container\n )\n : null;\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n Portal.displayName = PORTAL_NAME;\n}\n\nexport { Portal };\n"],"names":[],"mappings":";;;;;;;AAQA;AASA;AAAe;AAEX;AAEA;AACI;AACG;AAAiC;AAAO;AAAY;AAAc;AACnE;AAEF;AAER;AAEA;AACE;AACF;;"}
|
package/dist/version.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const PKG_NAME = "@liveblocks/react-ui";
|
|
4
|
-
const PKG_VERSION = typeof "2.
|
|
4
|
+
const PKG_VERSION = typeof "2.20.0-blocknote" === "string" && "2.20.0-blocknote";
|
|
5
5
|
const PKG_FORMAT = typeof "cjs" === "string" && "cjs";
|
|
6
6
|
|
|
7
7
|
exports.PKG_FORMAT = PKG_FORMAT;
|
package/dist/version.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.cjs","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const ROLLUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof ROLLUP_FORMAT === \"string\" && ROLLUP_FORMAT;\n"],"names":[],"mappings":";;AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAc,OAAO,
|
|
1
|
+
{"version":3,"file":"version.cjs","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const ROLLUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof ROLLUP_FORMAT === \"string\" && ROLLUP_FORMAT;\n"],"names":[],"mappings":";;AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAc,OAAO,kBAAA,KAAgB,QAAY,IAAA,mBAAA;AACjD,MAAA,UAAA,GAAa,OAAO,KAAA,KAAkB,QAAY,IAAA;;;;;;"}
|
package/dist/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const PKG_NAME = "@liveblocks/react-ui";
|
|
2
|
-
const PKG_VERSION = typeof "2.
|
|
2
|
+
const PKG_VERSION = typeof "2.20.0-blocknote" === "string" && "2.20.0-blocknote";
|
|
3
3
|
const PKG_FORMAT = typeof "esm" === "string" && "esm";
|
|
4
4
|
|
|
5
5
|
export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const ROLLUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof ROLLUP_FORMAT === \"string\" && ROLLUP_FORMAT;\n"],"names":[],"mappings":"AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAc,OAAO,
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const ROLLUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-ui\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof ROLLUP_FORMAT === \"string\" && ROLLUP_FORMAT;\n"],"names":[],"mappings":"AAGO,MAAM,QAAW,GAAA,uBAAA;AACX,MAAA,WAAA,GAAc,OAAO,kBAAA,KAAgB,QAAY,IAAA,mBAAA;AACjD,MAAA,UAAA,GAAa,OAAO,KAAA,KAAkB,QAAY,IAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0-blocknote",
|
|
4
4
|
"description": "A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -76,9 +76,9 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@floating-ui/react-dom": "^2.1.2",
|
|
79
|
-
"@liveblocks/client": "2.
|
|
80
|
-
"@liveblocks/core": "2.
|
|
81
|
-
"@liveblocks/react": "2.
|
|
79
|
+
"@liveblocks/client": "2.20.0-blocknote",
|
|
80
|
+
"@liveblocks/core": "2.20.0-blocknote",
|
|
81
|
+
"@liveblocks/react": "2.20.0-blocknote",
|
|
82
82
|
"@radix-ui/react-dropdown-menu": "^2.1.2",
|
|
83
83
|
"@radix-ui/react-popover": "^1.1.2",
|
|
84
84
|
"@radix-ui/react-slot": "^1.1.0",
|