@liveblocks/react-lexical 2.18.3 → 2.18.4-uns2

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.
Files changed (135) hide show
  1. package/dist/{classnames.mjs → classnames.cjs} +4 -2
  2. package/dist/{classnames.mjs.map → classnames.cjs.map} +1 -1
  3. package/dist/classnames.js +1 -3
  4. package/dist/classnames.js.map +1 -1
  5. package/dist/comments/{anchored-threads.mjs → anchored-threads.cjs} +44 -41
  6. package/dist/comments/{anchored-threads.mjs.map → anchored-threads.cjs.map} +1 -1
  7. package/dist/comments/anchored-threads.js +40 -43
  8. package/dist/comments/anchored-threads.js.map +1 -1
  9. package/dist/comments/{comment-plugin-provider.mjs → comment-plugin-provider.cjs} +62 -55
  10. package/dist/comments/{comment-plugin-provider.mjs.map → comment-plugin-provider.cjs.map} +1 -1
  11. package/dist/comments/comment-plugin-provider.js +54 -61
  12. package/dist/comments/comment-plugin-provider.js.map +1 -1
  13. package/dist/comments/{floating-composer.mjs → floating-composer.cjs} +68 -64
  14. package/dist/comments/{floating-composer.mjs.map → floating-composer.cjs.map} +1 -1
  15. package/dist/comments/floating-composer.js +63 -67
  16. package/dist/comments/floating-composer.js.map +1 -1
  17. package/dist/comments/{floating-threads.mjs → floating-threads.cjs} +51 -48
  18. package/dist/comments/{floating-threads.mjs.map → floating-threads.cjs.map} +1 -1
  19. package/dist/comments/floating-threads.js +47 -50
  20. package/dist/comments/floating-threads.js.map +1 -1
  21. package/dist/comments/get-thread-mark-ids.cjs +23 -0
  22. package/dist/comments/{get-thread-mark-ids.mjs.map → get-thread-mark-ids.cjs.map} +1 -1
  23. package/dist/comments/get-thread-mark-ids.js +6 -8
  24. package/dist/comments/get-thread-mark-ids.js.map +1 -1
  25. package/dist/comments/{thread-mark-node.mjs → thread-mark-node.cjs} +10 -6
  26. package/dist/comments/{thread-mark-node.mjs.map → thread-mark-node.cjs.map} +1 -1
  27. package/dist/comments/thread-mark-node.js +5 -9
  28. package/dist/comments/thread-mark-node.js.map +1 -1
  29. package/dist/comments/{unwrap-thread-mark-node.mjs → unwrap-thread-mark-node.cjs} +4 -2
  30. package/dist/comments/unwrap-thread-mark-node.cjs.map +1 -0
  31. package/dist/comments/unwrap-thread-mark-node.js +1 -3
  32. package/dist/comments/unwrap-thread-mark-node.js.map +1 -1
  33. package/dist/comments/{wrap-selection-in-thread-mark-node.mjs → wrap-selection-in-thread-mark-node.cjs} +12 -10
  34. package/dist/comments/{wrap-selection-in-thread-mark-node.mjs.map → wrap-selection-in-thread-mark-node.cjs.map} +1 -1
  35. package/dist/comments/wrap-selection-in-thread-mark-node.js +9 -11
  36. package/dist/comments/wrap-selection-in-thread-mark-node.js.map +1 -1
  37. package/dist/{create-dom-range.mjs → create-dom-range.cjs} +7 -5
  38. package/dist/{create-dom-range.mjs.map → create-dom-range.cjs.map} +1 -1
  39. package/dist/create-dom-range.js +4 -6
  40. package/dist/create-dom-range.js.map +1 -1
  41. package/dist/{create-rects-from-dom-range.mjs → create-rects-from-dom-range.cjs} +4 -2
  42. package/dist/{create-rects-from-dom-range.mjs.map → create-rects-from-dom-range.cjs.map} +1 -1
  43. package/dist/create-rects-from-dom-range.js +1 -3
  44. package/dist/create-rects-from-dom-range.js.map +1 -1
  45. package/dist/index.cjs +33 -0
  46. package/dist/{index.mjs.map → index.cjs.map} +1 -1
  47. package/dist/index.js +14 -31
  48. package/dist/index.js.map +1 -1
  49. package/dist/{is-block-node-active.mjs → is-block-node-active.cjs} +12 -10
  50. package/dist/{is-block-node-active.mjs.map → is-block-node-active.cjs.map} +1 -1
  51. package/dist/is-block-node-active.js +9 -11
  52. package/dist/is-block-node-active.js.map +1 -1
  53. package/dist/is-command-registered.cjs +11 -0
  54. package/dist/{is-command-registered.mjs.map → is-command-registered.cjs.map} +1 -1
  55. package/dist/is-command-registered.js +3 -5
  56. package/dist/is-command-registered.js.map +1 -1
  57. package/dist/is-text-format-active.cjs +16 -0
  58. package/dist/{is-text-format-active.mjs.map → is-text-format-active.cjs.map} +1 -1
  59. package/dist/is-text-format-active.js +4 -6
  60. package/dist/is-text-format-active.js.map +1 -1
  61. package/dist/liveblocks-config.cjs +17 -0
  62. package/dist/{liveblocks-config.mjs.map → liveblocks-config.cjs.map} +1 -1
  63. package/dist/liveblocks-config.js +4 -6
  64. package/dist/liveblocks-config.js.map +1 -1
  65. package/dist/liveblocks-plugin-provider.cjs +151 -0
  66. package/dist/liveblocks-plugin-provider.cjs.map +1 -0
  67. package/dist/liveblocks-plugin-provider.js +43 -47
  68. package/dist/liveblocks-plugin-provider.js.map +1 -1
  69. package/dist/mentions/{avatar.mjs → avatar.cjs} +16 -14
  70. package/dist/mentions/avatar.cjs.map +1 -0
  71. package/dist/mentions/avatar.js +13 -15
  72. package/dist/mentions/avatar.js.map +1 -1
  73. package/dist/mentions/mention-component.cjs +51 -0
  74. package/dist/mentions/{mention-component.mjs.map → mention-component.cjs.map} +1 -1
  75. package/dist/mentions/mention-component.js +14 -16
  76. package/dist/mentions/mention-component.js.map +1 -1
  77. package/dist/mentions/{mention-node.mjs → mention-node.cjs} +16 -12
  78. package/dist/mentions/{mention-node.mjs.map → mention-node.cjs.map} +1 -1
  79. package/dist/mentions/mention-node.js +11 -15
  80. package/dist/mentions/mention-node.js.map +1 -1
  81. package/dist/mentions/{mention-plugin.mjs → mention-plugin.cjs} +81 -78
  82. package/dist/mentions/{mention-plugin.mjs.map → mention-plugin.cjs.map} +1 -1
  83. package/dist/mentions/mention-plugin.js +77 -80
  84. package/dist/mentions/mention-plugin.js.map +1 -1
  85. package/dist/mentions/{suggestions.mjs → suggestions.cjs} +43 -37
  86. package/dist/mentions/{suggestions.mjs.map → suggestions.cjs.map} +1 -1
  87. package/dist/mentions/suggestions.js +36 -42
  88. package/dist/mentions/suggestions.js.map +1 -1
  89. package/dist/mentions/user.cjs +26 -0
  90. package/dist/mentions/{user.mjs.map → user.cjs.map} +1 -1
  91. package/dist/mentions/user.js +11 -13
  92. package/dist/mentions/user.js.map +1 -1
  93. package/dist/toolbar/{floating-toolbar.mjs → floating-toolbar.cjs} +73 -70
  94. package/dist/toolbar/{floating-toolbar.mjs.map → floating-toolbar.cjs.map} +1 -1
  95. package/dist/toolbar/floating-toolbar.js +69 -72
  96. package/dist/toolbar/floating-toolbar.js.map +1 -1
  97. package/dist/toolbar/shared.cjs +36 -0
  98. package/dist/toolbar/{shared.mjs.map → shared.cjs.map} +1 -1
  99. package/dist/toolbar/shared.js +12 -15
  100. package/dist/toolbar/shared.js.map +1 -1
  101. package/dist/toolbar/toolbar.cjs +433 -0
  102. package/dist/toolbar/{toolbar.mjs.map → toolbar.cjs.map} +1 -1
  103. package/dist/toolbar/toolbar.js +131 -156
  104. package/dist/toolbar/toolbar.js.map +1 -1
  105. package/dist/use-root-element.cjs +21 -0
  106. package/dist/use-root-element.cjs.map +1 -0
  107. package/dist/use-root-element.js +7 -9
  108. package/dist/use-root-element.js.map +1 -1
  109. package/dist/version-history/{history-version-preview.mjs → history-version-preview.cjs} +52 -50
  110. package/dist/version-history/{history-version-preview.mjs.map → history-version-preview.cjs.map} +1 -1
  111. package/dist/version-history/history-version-preview.js +49 -51
  112. package/dist/version-history/history-version-preview.js.map +1 -1
  113. package/dist/version.cjs +10 -0
  114. package/dist/{version.mjs.map → version.cjs.map} +1 -1
  115. package/dist/version.js +3 -7
  116. package/dist/version.js.map +1 -1
  117. package/package.json +18 -17
  118. package/styles.css.d.cts +1 -0
  119. package/dist/comments/get-thread-mark-ids.mjs +0 -21
  120. package/dist/comments/unwrap-thread-mark-node.mjs.map +0 -1
  121. package/dist/index.mjs +0 -16
  122. package/dist/is-command-registered.mjs +0 -9
  123. package/dist/is-text-format-active.mjs +0 -14
  124. package/dist/liveblocks-config.mjs +0 -15
  125. package/dist/liveblocks-plugin-provider.mjs +0 -147
  126. package/dist/liveblocks-plugin-provider.mjs.map +0 -1
  127. package/dist/mentions/avatar.mjs.map +0 -1
  128. package/dist/mentions/mention-component.mjs +0 -49
  129. package/dist/mentions/user.mjs +0 -24
  130. package/dist/toolbar/shared.mjs +0 -33
  131. package/dist/toolbar/toolbar.mjs +0 -408
  132. package/dist/use-root-element.mjs +0 -19
  133. package/dist/use-root-element.mjs.map +0 -1
  134. package/dist/version.mjs +0 -6
  135. /package/dist/{index.d.mts → index.d.cts} +0 -0
@@ -1,20 +1,18 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var LexicalComposer = require('@lexical/react/LexicalComposer');
5
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
6
- var LexicalContentEditable = require('@lexical/react/LexicalContentEditable');
7
- var LexicalEditorRefPlugin = require('@lexical/react/LexicalEditorRefPlugin');
8
- var LexicalErrorBoundary = require('@lexical/react/LexicalErrorBoundary');
9
- var LexicalRichTextPlugin = require('@lexical/react/LexicalRichTextPlugin');
10
- var yjs = require('@lexical/yjs');
11
- var react$1 = require('@liveblocks/react');
12
- var reactUi = require('@liveblocks/react-ui');
13
- var _private = require('@liveblocks/react-ui/_private');
14
- var react = require('react');
15
- var yjs$1 = require('yjs');
16
- var classnames = require('../classnames.js');
17
- var liveblocksConfig = require('../liveblocks-config.js');
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { LexicalComposer } from '@lexical/react/LexicalComposer';
3
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
+ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
5
+ import { EditorRefPlugin } from '@lexical/react/LexicalEditorRefPlugin';
6
+ import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
7
+ import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
8
+ import { syncLexicalUpdateToYjs, syncYjsChangesToLexical, createBinding } from '@lexical/yjs';
9
+ import { useHistoryVersionData } from '@liveblocks/react';
10
+ import { useOverrides } from '@liveblocks/react-ui';
11
+ import { SpinnerIcon, List, User, Button, RestoreIcon } from '@liveblocks/react-ui/_private';
12
+ import { forwardRef, useRef, useMemo, useEffect, useCallback } from 'react';
13
+ import { Doc, applyUpdate } from 'yjs';
14
+ import { classNames } from '../classnames.js';
15
+ import { liveblocksConfig } from '../liveblocks-config.js';
18
16
 
19
17
  const AUTHORS_TRUNCATE = 3;
20
18
  function createNoOpProvider() {
@@ -46,7 +44,7 @@ function registerCollaborationListeners(editor, provider, binding) {
46
44
  tags
47
45
  }) => {
48
46
  if (tags.has("skip-collab") === false) {
49
- yjs.syncLexicalUpdateToYjs(
47
+ syncLexicalUpdateToYjs(
50
48
  binding,
51
49
  provider,
52
50
  prevEditorState,
@@ -61,7 +59,7 @@ function registerCollaborationListeners(editor, provider, binding) {
61
59
  );
62
60
  const observer = (events, transaction) => {
63
61
  if (transaction.origin !== binding) {
64
- yjs.syncYjsChangesToLexical(binding, provider, events, false);
62
+ syncYjsChangesToLexical(binding, provider, events, false);
65
63
  }
66
64
  };
67
65
  binding.root.getSharedType().observeDeep(observer);
@@ -70,14 +68,14 @@ function registerCollaborationListeners(editor, provider, binding) {
70
68
  binding.root.getSharedType().unobserveDeep(observer);
71
69
  };
72
70
  }
73
- const HistoryVersionPreview = react.forwardRef(({ version, onVersionRestore, className, ...props }, forwardedRef) => {
74
- const [parentEditor, parentContext] = LexicalComposerContext.useLexicalComposerContext();
75
- const editor = react.useRef();
76
- const $ = reactUi.useOverrides();
77
- const { isLoading, data, error } = react$1.useHistoryVersionData(version.id);
78
- const initialConfig = react.useMemo(() => {
71
+ const HistoryVersionPreview = forwardRef(({ version, onVersionRestore, className, ...props }, forwardedRef) => {
72
+ const [parentEditor, parentContext] = useLexicalComposerContext();
73
+ const editor = useRef();
74
+ const $ = useOverrides();
75
+ const { isLoading, data, error } = useHistoryVersionData(version.id);
76
+ const initialConfig = useMemo(() => {
79
77
  const nodes = Array.from(parentEditor._nodes.values()).map((n) => n.klass);
80
- return liveblocksConfig.liveblocksConfig({
78
+ return liveblocksConfig({
81
79
  namespace: "VersionPreview",
82
80
  theme: parentContext.getTheme() || {},
83
81
  nodes,
@@ -85,14 +83,14 @@ const HistoryVersionPreview = react.forwardRef(({ version, onVersionRestore, cla
85
83
  onError: (err) => console.error(err)
86
84
  });
87
85
  }, [parentEditor, parentContext]);
88
- react.useEffect(() => {
86
+ useEffect(() => {
89
87
  if (error || !data || !editor.current || !data.length) {
90
88
  return;
91
89
  }
92
- const doc = new yjs$1.Doc();
90
+ const doc = new Doc();
93
91
  const docMap = /* @__PURE__ */ new Map([[version.id, doc]]);
94
92
  const provider = createNoOpProvider();
95
- const binding = yjs.createBinding(
93
+ const binding = createBinding(
96
94
  editor.current,
97
95
  provider,
98
96
  version.id,
@@ -105,60 +103,60 @@ const HistoryVersionPreview = react.forwardRef(({ version, onVersionRestore, cla
105
103
  binding
106
104
  );
107
105
  try {
108
- yjs$1.applyUpdate(doc, data);
106
+ applyUpdate(doc, data);
109
107
  } catch (err) {
110
108
  console.warn(err);
111
109
  }
112
110
  return unsubscribe;
113
111
  }, [data, version.id, isLoading, error]);
114
- const restore = react.useCallback(() => {
112
+ const restore = useCallback(() => {
115
113
  if (!editor.current || !parentEditor) {
116
114
  return;
117
115
  }
118
116
  parentEditor.setEditorState(editor.current.getEditorState());
119
117
  onVersionRestore?.(version);
120
118
  }, [parentEditor, onVersionRestore, version]);
121
- return /* @__PURE__ */ jsxRuntime.jsxs("div", {
119
+ return /* @__PURE__ */ jsxs("div", {
122
120
  ...props,
123
- className: classnames.classNames(
121
+ className: classNames(
124
122
  "lb-root lb-history-version-preview lb-lexical-version-preview",
125
123
  className
126
124
  ),
127
125
  ref: forwardedRef,
128
126
  children: [
129
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", {
127
+ isLoading ? /* @__PURE__ */ jsx("div", {
130
128
  className: "lb-loading lb-history-version-preview-loading",
131
- children: /* @__PURE__ */ jsxRuntime.jsx(_private.SpinnerIcon, {})
132
- }) : error ? /* @__PURE__ */ jsxRuntime.jsx("div", {
129
+ children: /* @__PURE__ */ jsx(SpinnerIcon, {})
130
+ }) : error ? /* @__PURE__ */ jsx("div", {
133
131
  className: "lb-error lb-history-version-preview-error",
134
132
  children: $.HISTORY_VERSION_PREVIEW_ERROR(error)
135
- }) : /* @__PURE__ */ jsxRuntime.jsx("div", {
133
+ }) : /* @__PURE__ */ jsx("div", {
136
134
  className: "lb-history-version-preview-content lb-lexical-editor-container lb-lexical-version-preview-editor-container",
137
- children: /* @__PURE__ */ jsxRuntime.jsxs(LexicalComposer.LexicalComposer, {
135
+ children: /* @__PURE__ */ jsxs(LexicalComposer, {
138
136
  initialConfig,
139
137
  children: [
140
- /* @__PURE__ */ jsxRuntime.jsx(LexicalEditorRefPlugin.EditorRefPlugin, {
138
+ /* @__PURE__ */ jsx(EditorRefPlugin, {
141
139
  editorRef: editor
142
140
  }),
143
- /* @__PURE__ */ jsxRuntime.jsx(LexicalRichTextPlugin.RichTextPlugin, {
144
- contentEditable: /* @__PURE__ */ jsxRuntime.jsx(LexicalContentEditable.ContentEditable, {}),
145
- placeholder: /* @__PURE__ */ jsxRuntime.jsx("div", {
141
+ /* @__PURE__ */ jsx(RichTextPlugin, {
142
+ contentEditable: /* @__PURE__ */ jsx(ContentEditable, {}),
143
+ placeholder: /* @__PURE__ */ jsx("div", {
146
144
  className: "lb-empty lb-history-version-preview-empty",
147
145
  children: $.HISTORY_VERSION_PREVIEW_EMPTY
148
146
  }),
149
- ErrorBoundary: LexicalErrorBoundary.LexicalErrorBoundary
147
+ ErrorBoundary: LexicalErrorBoundary
150
148
  })
151
149
  ]
152
150
  })
153
151
  }),
154
- /* @__PURE__ */ jsxRuntime.jsxs("div", {
152
+ /* @__PURE__ */ jsxs("div", {
155
153
  className: "lb-history-version-preview-footer",
156
154
  children: [
157
- /* @__PURE__ */ jsxRuntime.jsx("span", {
155
+ /* @__PURE__ */ jsx("span", {
158
156
  className: "lb-history-version-preview-authors",
159
157
  children: $.HISTORY_VERSION_PREVIEW_AUTHORS_LIST(
160
- /* @__PURE__ */ jsxRuntime.jsx(_private.List, {
161
- values: version.authors.map((author) => /* @__PURE__ */ jsxRuntime.jsx(_private.User, {
158
+ /* @__PURE__ */ jsx(List, {
159
+ values: version.authors.map((author) => /* @__PURE__ */ jsx(User, {
162
160
  userId: author.id,
163
161
  replaceSelf: true
164
162
  }, author.id)),
@@ -168,15 +166,15 @@ const HistoryVersionPreview = react.forwardRef(({ version, onVersionRestore, cla
168
166
  })
169
167
  )
170
168
  }),
171
- /* @__PURE__ */ jsxRuntime.jsx("div", {
169
+ /* @__PURE__ */ jsx("div", {
172
170
  className: "lb-history-version-preview-actions",
173
- children: /* @__PURE__ */ jsxRuntime.jsx(_private.Button, {
171
+ children: /* @__PURE__ */ jsx(Button, {
174
172
  onClick: restore,
175
173
  disabled: !data || !parentEditor,
176
174
  variant: "primary",
177
175
  size: "large",
178
176
  className: "lb-history-version-preview-action",
179
- icon: /* @__PURE__ */ jsxRuntime.jsx(_private.RestoreIcon, {}),
177
+ icon: /* @__PURE__ */ jsx(RestoreIcon, {}),
180
178
  children: $.HISTORY_VERSION_PREVIEW_RESTORE
181
179
  })
182
180
  })
@@ -186,5 +184,5 @@ const HistoryVersionPreview = react.forwardRef(({ version, onVersionRestore, cla
186
184
  });
187
185
  });
188
186
 
189
- exports.HistoryVersionPreview = HistoryVersionPreview;
187
+ export { HistoryVersionPreview };
190
188
  //# sourceMappingURL=history-version-preview.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"history-version-preview.js","sources":["../../src/version-history/history-version-preview.tsx"],"sourcesContent":["import { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { EditorRefPlugin } from \"@lexical/react/LexicalEditorRefPlugin\";\nimport { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport type { Binding, Provider } from \"@lexical/yjs\";\nimport {\n createBinding,\n syncLexicalUpdateToYjs,\n syncYjsChangesToLexical,\n} from \"@lexical/yjs\";\nimport type { HistoryVersion } from \"@liveblocks/core\";\nimport { useHistoryVersionData } from \"@liveblocks/react\";\nimport { useOverrides } from \"@liveblocks/react-ui\";\nimport {\n Button,\n List,\n RestoreIcon,\n SpinnerIcon,\n User,\n} from \"@liveblocks/react-ui/_private\";\nimport type { LexicalEditor } from \"lexical\";\nimport type { ComponentPropsWithoutRef } from \"react\";\nimport { forwardRef, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport type { Transaction, YEvent } from \"yjs\";\nimport { applyUpdate, Doc } from \"yjs\";\n\nimport { classNames } from \"../classnames\";\nimport { liveblocksConfig } from \"../liveblocks-config\";\n\nconst AUTHORS_TRUNCATE = 3;\n\nexport interface HistoryVersionPreviewProps\n extends ComponentPropsWithoutRef<\"div\"> {\n version: HistoryVersion;\n onVersionRestore?: (version: HistoryVersion) => void;\n}\n\nfunction createNoOpProvider(): Provider {\n const emptyFunction = () => {};\n\n return {\n awareness: {\n getLocalState: () => null,\n setLocalStateField: emptyFunction,\n getStates: () => new Map(),\n off: emptyFunction,\n on: emptyFunction,\n setLocalState: emptyFunction,\n },\n connect: emptyFunction,\n disconnect: emptyFunction,\n off: emptyFunction,\n on: emptyFunction,\n };\n}\n\nfunction registerCollaborationListeners(\n editor: LexicalEditor,\n provider: Provider,\n binding: Binding\n): () => void {\n const unsubscribeUpdateListener = editor.registerUpdateListener(\n ({\n dirtyElements,\n dirtyLeaves,\n editorState,\n normalizedNodes,\n prevEditorState,\n tags,\n }) => {\n if (tags.has(\"skip-collab\") === false) {\n syncLexicalUpdateToYjs(\n binding,\n provider,\n prevEditorState,\n editorState,\n dirtyElements,\n dirtyLeaves,\n normalizedNodes,\n tags\n );\n }\n }\n );\n\n const observer = (events: Array<YEvent<any>>, transaction: Transaction) => {\n if (transaction.origin !== binding) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n syncYjsChangesToLexical(binding, provider, events, false);\n }\n };\n\n binding.root.getSharedType().observeDeep(observer);\n\n return () => {\n unsubscribeUpdateListener();\n binding.root.getSharedType().unobserveDeep(observer);\n };\n}\n\n/**\n * Displays a specific version of the current Lexical document.\n *\n * @example\n * <HistoryVersionPreview version={version} />\n */\nexport const HistoryVersionPreview = forwardRef<\n HTMLDivElement,\n HistoryVersionPreviewProps\n>(({ version, onVersionRestore, className, ...props }, forwardedRef) => {\n const [parentEditor, parentContext] = useLexicalComposerContext();\n const editor = useRef<LexicalEditor>();\n const $ = useOverrides();\n const { isLoading, data, error } = useHistoryVersionData(version.id);\n\n const initialConfig = useMemo(() => {\n const nodes = Array.from(parentEditor._nodes.values()).map((n) => n.klass);\n\n return liveblocksConfig({\n namespace: \"VersionPreview\",\n theme: parentContext.getTheme() || {},\n nodes,\n editable: false,\n onError: (err) => console.error(err),\n });\n }, [parentEditor, parentContext]);\n\n useEffect(() => {\n if (error || !data || !editor.current || !data.length) {\n return;\n }\n const doc = new Doc();\n const docMap = new Map([[version.id, doc]]);\n const provider = createNoOpProvider();\n const binding = createBinding(\n editor.current,\n provider,\n version.id,\n doc,\n docMap\n );\n const unsubscribe = registerCollaborationListeners(\n editor.current,\n provider,\n binding\n );\n\n try {\n applyUpdate(doc, data);\n } catch (err) {\n console.warn(err);\n }\n\n return unsubscribe;\n }, [data, version.id, isLoading, error]);\n\n const restore = useCallback(() => {\n if (!editor.current || !parentEditor) {\n return;\n }\n\n parentEditor.setEditorState(editor.current.getEditorState());\n onVersionRestore?.(version);\n }, [parentEditor, onVersionRestore, version]);\n\n return (\n <div\n {...props}\n className={classNames(\n \"lb-root lb-history-version-preview lb-lexical-version-preview\",\n className\n )}\n ref={forwardedRef}\n >\n {isLoading ? (\n <div className=\"lb-loading lb-history-version-preview-loading\">\n <SpinnerIcon />\n </div>\n ) : error ? (\n <div className=\"lb-error lb-history-version-preview-error\">\n {$.HISTORY_VERSION_PREVIEW_ERROR(error)}\n </div>\n ) : (\n <div className=\"lb-history-version-preview-content lb-lexical-editor-container lb-lexical-version-preview-editor-container\">\n <LexicalComposer initialConfig={initialConfig}>\n <EditorRefPlugin editorRef={editor} />\n <RichTextPlugin\n contentEditable={<ContentEditable />}\n placeholder={\n <div className=\"lb-empty lb-history-version-preview-empty\">\n {$.HISTORY_VERSION_PREVIEW_EMPTY}\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n />\n </LexicalComposer>\n </div>\n )}\n <div className=\"lb-history-version-preview-footer\">\n <span className=\"lb-history-version-preview-authors\">\n {$.HISTORY_VERSION_PREVIEW_AUTHORS_LIST(\n <List\n values={version.authors.map((author) => (\n <User key={author.id} userId={author.id} replaceSelf />\n ))}\n formatRemaining={$.LIST_REMAINING_USERS}\n truncate={AUTHORS_TRUNCATE}\n locale={$.locale}\n />\n )}\n </span>\n <div className=\"lb-history-version-preview-actions\">\n <Button\n onClick={restore}\n disabled={!data || !parentEditor}\n variant=\"primary\"\n size=\"large\"\n className=\"lb-history-version-preview-action\"\n icon={<RestoreIcon />}\n >\n {$.HISTORY_VERSION_PREVIEW_RESTORE}\n </Button>\n </div>\n </div>\n </div>\n );\n});\n"],"names":["syncLexicalUpdateToYjs","syncYjsChangesToLexical","forwardRef","useLexicalComposerContext","useRef","useOverrides","useHistoryVersionData","useMemo","liveblocksConfig","useEffect","Doc","createBinding","applyUpdate","useCallback","jsxs","classNames","jsx","SpinnerIcon","LexicalComposer","EditorRefPlugin","RichTextPlugin","ContentEditable","LexicalErrorBoundary","List","User","Button","RestoreIcon"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAM,gBAAmB,GAAA,CAAA,CAAA;AAQzB,SAAS,kBAA+B,GAAA;AACtC,EAAA,MAAM,gBAAgB,MAAM;AAAA,GAAC,CAAA;AAE7B,EAAO,OAAA;AAAA,IACL,SAAW,EAAA;AAAA,MACT,eAAe,MAAM,IAAA;AAAA,MACrB,kBAAoB,EAAA,aAAA;AAAA,MACpB,SAAA,EAAW,sBAAM,IAAI,GAAI,EAAA;AAAA,MACzB,GAAK,E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CAAA;AAAA,gBACD,iBAAiB,CAAE,CAAA,oBAAA;AAAA,gBACnB,QAAU,EAAA,gBAAA;AAAA,gBACV,QAAQ,CAAE,CAAA,MAAA;AAAA,eACZ,CAAA;AAAA,aACF;AAAA,WACF,CAAA;AAAA,0BACCR,cAAA,CAAA,KAAA,EAAA;AAAA,YAAI,SAAU,EAAA,oCAAA;AAAA,YACb,QAAC,kBAAAA,cAAA,CAAAS,eAAA,EAAA;AAAA,cACC,OAAS,EAAA,OAAA;AAAA,cACT,QAAA,EAAU,CAAC,IAAA,IAAQ,CAAC,YAAA;AAAA,cACpB,OAAQ,EAAA,SAAA;AAAA,cACR,IAAK,EAAA,OAAA;AAAA,cACL,SAAU,EAAA,mCAAA;AAAA,cACV,IAAA,iCAAOC,oBAAY,EAAA,EAAA,CAAA;AAAA,cAElB,QAAE,EAAA,CAAA,CAAA,+BAAA;AAAA,aACL,CAAA;AAAA,WACF,CAAA;AAAA,SAAA;AAAA,OACF,CAAA;AAAA,KAAA;AAAA,GACF,CAAA,CAAA;AAEJ,CAAC;;;;"}
1
+ {"version":3,"file":"history-version-preview.js","sources":["../../src/version-history/history-version-preview.tsx"],"sourcesContent":["import { LexicalComposer } from \"@lexical/react/LexicalComposer\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\nimport { EditorRefPlugin } from \"@lexical/react/LexicalEditorRefPlugin\";\nimport { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\nimport { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\nimport type { Binding, Provider } from \"@lexical/yjs\";\nimport {\n createBinding,\n syncLexicalUpdateToYjs,\n syncYjsChangesToLexical,\n} from \"@lexical/yjs\";\nimport type { HistoryVersion } from \"@liveblocks/core\";\nimport { useHistoryVersionData } from \"@liveblocks/react\";\nimport { useOverrides } from \"@liveblocks/react-ui\";\nimport {\n Button,\n List,\n RestoreIcon,\n SpinnerIcon,\n User,\n} from \"@liveblocks/react-ui/_private\";\nimport type { LexicalEditor } from \"lexical\";\nimport type { ComponentPropsWithoutRef } from \"react\";\nimport { forwardRef, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport type { Transaction, YEvent } from \"yjs\";\nimport { applyUpdate, Doc } from \"yjs\";\n\nimport { classNames } from \"../classnames\";\nimport { liveblocksConfig } from \"../liveblocks-config\";\n\nconst AUTHORS_TRUNCATE = 3;\n\nexport interface HistoryVersionPreviewProps\n extends ComponentPropsWithoutRef<\"div\"> {\n version: HistoryVersion;\n onVersionRestore?: (version: HistoryVersion) => void;\n}\n\nfunction createNoOpProvider(): Provider {\n const emptyFunction = () => {};\n\n return {\n awareness: {\n getLocalState: () => null,\n setLocalStateField: emptyFunction,\n getStates: () => new Map(),\n off: emptyFunction,\n on: emptyFunction,\n setLocalState: emptyFunction,\n },\n connect: emptyFunction,\n disconnect: emptyFunction,\n off: emptyFunction,\n on: emptyFunction,\n };\n}\n\nfunction registerCollaborationListeners(\n editor: LexicalEditor,\n provider: Provider,\n binding: Binding\n): () => void {\n const unsubscribeUpdateListener = editor.registerUpdateListener(\n ({\n dirtyElements,\n dirtyLeaves,\n editorState,\n normalizedNodes,\n prevEditorState,\n tags,\n }) => {\n if (tags.has(\"skip-collab\") === false) {\n syncLexicalUpdateToYjs(\n binding,\n provider,\n prevEditorState,\n editorState,\n dirtyElements,\n dirtyLeaves,\n normalizedNodes,\n tags\n );\n }\n }\n );\n\n const observer = (events: Array<YEvent<any>>, transaction: Transaction) => {\n if (transaction.origin !== binding) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n syncYjsChangesToLexical(binding, provider, events, false);\n }\n };\n\n binding.root.getSharedType().observeDeep(observer);\n\n return () => {\n unsubscribeUpdateListener();\n binding.root.getSharedType().unobserveDeep(observer);\n };\n}\n\n/**\n * Displays a specific version of the current Lexical document.\n *\n * @example\n * <HistoryVersionPreview version={version} />\n */\nexport const HistoryVersionPreview = forwardRef<\n HTMLDivElement,\n HistoryVersionPreviewProps\n>(({ version, onVersionRestore, className, ...props }, forwardedRef) => {\n const [parentEditor, parentContext] = useLexicalComposerContext();\n const editor = useRef<LexicalEditor>();\n const $ = useOverrides();\n const { isLoading, data, error } = useHistoryVersionData(version.id);\n\n const initialConfig = useMemo(() => {\n const nodes = Array.from(parentEditor._nodes.values()).map((n) => n.klass);\n\n return liveblocksConfig({\n namespace: \"VersionPreview\",\n theme: parentContext.getTheme() || {},\n nodes,\n editable: false,\n onError: (err) => console.error(err),\n });\n }, [parentEditor, parentContext]);\n\n useEffect(() => {\n if (error || !data || !editor.current || !data.length) {\n return;\n }\n const doc = new Doc();\n const docMap = new Map([[version.id, doc]]);\n const provider = createNoOpProvider();\n const binding = createBinding(\n editor.current,\n provider,\n version.id,\n doc,\n docMap\n );\n const unsubscribe = registerCollaborationListeners(\n editor.current,\n provider,\n binding\n );\n\n try {\n applyUpdate(doc, data);\n } catch (err) {\n console.warn(err);\n }\n\n return unsubscribe;\n }, [data, version.id, isLoading, error]);\n\n const restore = useCallback(() => {\n if (!editor.current || !parentEditor) {\n return;\n }\n\n parentEditor.setEditorState(editor.current.getEditorState());\n onVersionRestore?.(version);\n }, [parentEditor, onVersionRestore, version]);\n\n return (\n <div\n {...props}\n className={classNames(\n \"lb-root lb-history-version-preview lb-lexical-version-preview\",\n className\n )}\n ref={forwardedRef}\n >\n {isLoading ? (\n <div className=\"lb-loading lb-history-version-preview-loading\">\n <SpinnerIcon />\n </div>\n ) : error ? (\n <div className=\"lb-error lb-history-version-preview-error\">\n {$.HISTORY_VERSION_PREVIEW_ERROR(error)}\n </div>\n ) : (\n <div className=\"lb-history-version-preview-content lb-lexical-editor-container lb-lexical-version-preview-editor-container\">\n <LexicalComposer initialConfig={initialConfig}>\n <EditorRefPlugin editorRef={editor} />\n <RichTextPlugin\n contentEditable={<ContentEditable />}\n placeholder={\n <div className=\"lb-empty lb-history-version-preview-empty\">\n {$.HISTORY_VERSION_PREVIEW_EMPTY}\n </div>\n }\n ErrorBoundary={LexicalErrorBoundary}\n />\n </LexicalComposer>\n </div>\n )}\n <div className=\"lb-history-version-preview-footer\">\n <span className=\"lb-history-version-preview-authors\">\n {$.HISTORY_VERSION_PREVIEW_AUTHORS_LIST(\n <List\n values={version.authors.map((author) => (\n <User key={author.id} userId={author.id} replaceSelf />\n ))}\n formatRemaining={$.LIST_REMAINING_USERS}\n truncate={AUTHORS_TRUNCATE}\n locale={$.locale}\n />\n )}\n </span>\n <div className=\"lb-history-version-preview-actions\">\n <Button\n onClick={restore}\n disabled={!data || !parentEditor}\n variant=\"primary\"\n size=\"large\"\n className=\"lb-history-version-preview-action\"\n icon={<RestoreIcon />}\n >\n {$.HISTORY_VERSION_PREVIEW_RESTORE}\n </Button>\n </div>\n </div>\n </div>\n );\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAM,gBAAmB,GAAA,CAAA,CAAA;AAQzB,SAAS,kBAA+B,GAAA;AACtC,EAAA,MAAM,gBAAgB,MAAM;AAAA,GAAC,CAAA;AAE7B,EAAO,OAAA;AAAA,IACL,SAAW,EAAA;AAAA,MACT,eAAe,MAAM,IAAA;AAAA,MACrB,kBAAoB,EAAA,aAAA;AAAA,MACpB,SAAA,EAAW,sBAAM,IAAI,GAAI,EAAA;AAAA,MACzB,GAAK,EAAA,aAAA;AAAA,MACL,EAAI,EAAA,aAAA;AAAA,MACJ,aAAe,EAAA,aAAA;AAAA,KACjB;AAAA,IACA,OAAS,EAAA,aAAA;AAAA,IACT,UAAY,EAAA,aAAA;AAAA,IACZ,GAAK,EAAA,aAAA;AAAA,IACL,EAAI,EAAA,aAAA;AAAA,GACN,CAAA;AACF,CAAA;AAEA,SAAS,8BAAA,CACP,MACA,EAAA,QAAA,EACA,OACY,EAAA;AACZ,EAAA,MAAM,4BAA4B,MAAO,CAAA,sBAAA;AAAA,IACvC,CAAC;AAAA,MACC,aAAA;AAAA,MACA,WAAA;AAAA,MACA,WAAA;AAAA,M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cACV,IAAA,sBAAO,WAAY,EAAA,EAAA,CAAA;AAAA,cAElB,QAAE,EAAA,CAAA,CAAA,+BAAA;AAAA,aACL,CAAA;AAAA,WACF,CAAA;AAAA,SAAA;AAAA,OACF,CAAA;AAAA,KAAA;AAAA,GACF,CAAA,CAAA;AAEJ,CAAC;;;;"}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const PKG_NAME = "@liveblocks/react-lexical";
4
+ const PKG_VERSION = typeof "2.18.4-uns2" === "string" && "2.18.4-uns2";
5
+ const PKG_FORMAT = typeof "cjs" === "string" && "cjs";
6
+
7
+ exports.PKG_FORMAT = PKG_FORMAT;
8
+ exports.PKG_NAME = PKG_NAME;
9
+ exports.PKG_VERSION = PKG_VERSION;
10
+ //# sourceMappingURL=version.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.mjs","sources":["../src/version.ts"],"sourcesContent":["declare const __VERSION__: string;\ndeclare const ROLLUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react-lexical\";\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,4BAAA;AACX,MAAA,WAAA,GAAc,OAAO,QAAA,KAAgB,QAAY,IAAA,SAAA;AACjD,MAAA,UAAA,GAAa,OAAO,KAAA,KAAkB,QAAY,IAAA;;;;"}
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-lexical\";\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,4BAAA;AACX,MAAA,WAAA,GAAc,OAAO,aAAA,KAAgB,QAAY,IAAA,cAAA;AACjD,MAAA,UAAA,GAAa,OAAO,KAAA,KAAkB,QAAY,IAAA;;;;;;"}
package/dist/version.js CHANGED
@@ -1,10 +1,6 @@
1
- 'use strict';
2
-
3
1
  const PKG_NAME = "@liveblocks/react-lexical";
4
- const PKG_VERSION = typeof "2.18.3" === "string" && "2.18.3";
5
- const PKG_FORMAT = typeof "cjs" === "string" && "cjs";
2
+ const PKG_VERSION = typeof "2.18.4-uns2" === "string" && "2.18.4-uns2";
3
+ const PKG_FORMAT = typeof "esm" === "string" && "esm";
6
4
 
7
- exports.PKG_FORMAT = PKG_FORMAT;
8
- exports.PKG_NAME = PKG_NAME;
9
- exports.PKG_VERSION = PKG_VERSION;
5
+ export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
10
6
  //# sourceMappingURL=version.js.map
@@ -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-lexical\";\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,4BAAA;AACX,MAAA,WAAA,GAAc,OAAO,QAAA,KAAgB,QAAY,IAAA,SAAA;AACjD,MAAA,UAAA,GAAa,OAAO,KAAA,KAAkB,QAAY,IAAA;;;;;;"}
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-lexical\";\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,4BAAA;AACX,MAAA,WAAA,GAAc,OAAO,aAAA,KAAgB,QAAY,IAAA,cAAA;AACjD,MAAA,UAAA,GAAa,OAAO,KAAA,KAAkB,QAAY,IAAA;;;;"}
package/package.json CHANGED
@@ -1,38 +1,39 @@
1
1
  {
2
2
  "name": "@liveblocks/react-lexical",
3
- "version": "2.18.3",
3
+ "version": "2.18.4-uns2",
4
4
  "description": "A lexical react plugin to enable collaboration, comments, live cursors, and more.",
5
5
  "license": "Apache-2.0",
6
- "type": "commonjs",
7
- "main": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "types": "./dist/index.d.cts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": {
12
- "types": "./dist/index.d.mts",
13
- "default": "./dist/index.mjs"
14
- },
15
- "require": {
16
12
  "types": "./dist/index.d.ts",
17
- "module": "./dist/index.mjs",
18
13
  "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "module": "./dist/index.js",
18
+ "default": "./dist/index.cjs"
19
19
  }
20
20
  },
21
21
  "./styles.css": {
22
- "types": "./styles.css.d.ts",
22
+ "types": "./styles.css.d.cts",
23
23
  "default": "./styles.css"
24
24
  }
25
25
  },
26
26
  "files": [
27
27
  "dist/**",
28
28
  "**/*.css",
29
+ "**/*.css.d.cts",
29
30
  "**/*.css.d.ts",
30
31
  "**/*.css.map",
31
32
  "README.md"
32
33
  ],
33
34
  "scripts": {
34
- "dev": "rollup --config rollup.config.mjs --watch",
35
- "build": "rollup --config rollup.config.mjs",
35
+ "dev": "rollup --config rollup.config.js --watch",
36
+ "build": "rollup --config rollup.config.js",
36
37
  "format": "eslint --fix src/; stylelint --fix src/styles/; prettier --write src/",
37
38
  "lint": "eslint src/; stylelint src/styles/",
38
39
  "lint:package": "publint --strict && attw --pack",
@@ -42,11 +43,11 @@
42
43
  },
43
44
  "dependencies": {
44
45
  "@floating-ui/react-dom": "^2.1.1",
45
- "@liveblocks/client": "2.18.3",
46
- "@liveblocks/core": "2.18.3",
47
- "@liveblocks/react": "2.18.3",
48
- "@liveblocks/react-ui": "2.18.3",
49
- "@liveblocks/yjs": "2.18.3",
46
+ "@liveblocks/client": "2.18.4-uns2",
47
+ "@liveblocks/core": "2.18.4-uns2",
48
+ "@liveblocks/react": "2.18.4-uns2",
49
+ "@liveblocks/react-ui": "2.18.4-uns2",
50
+ "@liveblocks/yjs": "2.18.4-uns2",
50
51
  "@radix-ui/react-select": "^2.1.2",
51
52
  "@radix-ui/react-toggle": "^1.1.0",
52
53
  "yjs": "^13.6.18"
@@ -0,0 +1 @@
1
+ declare module "@liveblocks/react-lexical/styles.css";
@@ -1,21 +0,0 @@
1
- import { $isTextNode } from 'lexical';
2
- import { $isThreadMarkNode } from './thread-mark-node.mjs';
3
-
4
- function $getThreadMarkIds(node, offset) {
5
- let currentNode = node;
6
- while (currentNode !== null) {
7
- if ($isThreadMarkNode(currentNode)) {
8
- return currentNode.getIDs();
9
- } else if ($isTextNode(currentNode) && offset === currentNode.getTextContentSize()) {
10
- const nextSibling = currentNode.getNextSibling();
11
- if ($isThreadMarkNode(nextSibling)) {
12
- return nextSibling.getIDs();
13
- }
14
- }
15
- currentNode = currentNode.getParent();
16
- }
17
- return null;
18
- }
19
-
20
- export { $getThreadMarkIds as default };
21
- //# sourceMappingURL=get-thread-mark-ids.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unwrap-thread-mark-node.mjs","sources":["../../src/comments/unwrap-thread-mark-node.ts"],"sourcesContent":["import type { ThreadMarkNode } from \"./thread-mark-node\";\n\nexport default function $unwrapThreadMarkNode(node: ThreadMarkNode): void {\n const children = node.getChildren();\n let target = null;\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (target === null) {\n node.insertBefore(child);\n } else {\n target.insertAfter(child);\n }\n target = child;\n }\n node.remove();\n}\n"],"names":[],"mappings":"AAEA,SAAwB,sBAAsB,IAA4B,EAAA;AACxE,EAAM,MAAA,QAAA,GAAW,KAAK,WAAY,EAAA,CAAA;AAClC,EAAA,IAAI,MAAS,GAAA,IAAA,CAAA;AACb,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,QAAA,CAAS,QAAQ,CAAK,EAAA,EAAA;AACxC,IAAA,MAAM,QAAQ,QAAS,CAAA,CAAA,CAAA,CAAA;AACvB,IAAA,IAAI,WAAW,IAAM,EAAA;AACnB,MAAA,IAAA,CAAK,aAAa,KAAK,CAAA,CAAA;AAAA,KAClB,MAAA;AACL,MAAA,MAAA,CAAO,YAAY,KAAK,CAAA,CAAA;AAAA,KAC1B;AACA,IAAS,MAAA,GAAA,KAAA,CAAA;AAAA,GACX;AACA,EAAA,IAAA,CAAK,MAAO,EAAA,CAAA;AACd;;;;"}
package/dist/index.mjs DELETED
@@ -1,16 +0,0 @@
1
- import { detectDupes } from '@liveblocks/core';
2
- import { PKG_NAME, PKG_VERSION, PKG_FORMAT } from './version.mjs';
3
- export { AnchoredThreads } from './comments/anchored-threads.mjs';
4
- export { useIsThreadActive } from './comments/comment-plugin-provider.mjs';
5
- export { FloatingComposer, OPEN_FLOATING_COMPOSER_COMMAND } from './comments/floating-composer.mjs';
6
- export { FloatingThreads } from './comments/floating-threads.mjs';
7
- export { isBlockNodeActive } from './is-block-node-active.mjs';
8
- export { isTextFormatActive } from './is-text-format-active.mjs';
9
- export { liveblocksConfig } from './liveblocks-config.mjs';
10
- export { LiveblocksPlugin, useEditorStatus, useIsEditorReady } from './liveblocks-plugin-provider.mjs';
11
- export { FloatingToolbar } from './toolbar/floating-toolbar.mjs';
12
- export { Toolbar } from './toolbar/toolbar.mjs';
13
- export { HistoryVersionPreview } from './version-history/history-version-preview.mjs';
14
-
15
- detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
16
- //# sourceMappingURL=index.mjs.map
@@ -1,9 +0,0 @@
1
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
2
-
3
- function useIsCommandRegistered(command) {
4
- const [editor] = useLexicalComposerContext();
5
- return editor._commands.has(command);
6
- }
7
-
8
- export { useIsCommandRegistered };
9
- //# sourceMappingURL=is-command-registered.mjs.map
@@ -1,14 +0,0 @@
1
- import { $getSelection, $isRangeSelection } from 'lexical';
2
-
3
- function isTextFormatActive(editor, format) {
4
- return editor.getEditorState().read(() => {
5
- const selection = $getSelection();
6
- if (!$isRangeSelection(selection) || selection.isCollapsed()) {
7
- return false;
8
- }
9
- return selection.hasFormat(format);
10
- });
11
- }
12
-
13
- export { isTextFormatActive };
14
- //# sourceMappingURL=is-text-format-active.mjs.map
@@ -1,15 +0,0 @@
1
- import { ThreadMarkNode } from './comments/thread-mark-node.mjs';
2
- import { MentionNode } from './mentions/mention-node.mjs';
3
-
4
- function liveblocksConfig(editorConfig) {
5
- const nodes = [...editorConfig.nodes ?? []];
6
- nodes.push(ThreadMarkNode, MentionNode);
7
- return {
8
- ...editorConfig,
9
- nodes,
10
- editorState: null
11
- };
12
- }
13
-
14
- export { liveblocksConfig };
15
- //# sourceMappingURL=liveblocks-config.mjs.map
@@ -1,147 +0,0 @@
1
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
- import { useFloating, autoUpdate } from '@floating-ui/react-dom';
3
- import { CollaborationPlugin } from '@lexical/react/LexicalCollaborationPlugin';
4
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
5
- import { TextEditorType } from '@liveblocks/core';
6
- import { useRoom, useSelf } from '@liveblocks/react';
7
- import { useYjsProvider, useResolveMentionSuggestions, useReportTextEditor, useLayoutEffect } from '@liveblocks/react/_private';
8
- import { getYjsProviderForRoom } from '@liveblocks/yjs';
9
- import { useCallback, useSyncExternalStore, useState, useEffect } from 'react';
10
- import { CommentPluginProvider } from './comments/comment-plugin-provider.mjs';
11
- import { ThreadMarkNode } from './comments/thread-mark-node.mjs';
12
- import { MentionNode } from './mentions/mention-node.mjs';
13
- import { MentionPlugin } from './mentions/mention-plugin.mjs';
14
- import { useRootElement } from './use-root-element.mjs';
15
-
16
- function useEditorStatus() {
17
- const provider = useYjsProvider();
18
- const subscribe = useCallback(
19
- (onStoreChange) => {
20
- if (provider === void 0)
21
- return () => {
22
- };
23
- provider.on("status", onStoreChange);
24
- return () => {
25
- provider.off("status", onStoreChange);
26
- };
27
- },
28
- [provider]
29
- );
30
- const getSnapshot = useCallback(() => {
31
- if (provider === void 0) {
32
- return "not-loaded";
33
- }
34
- return provider.getStatus();
35
- }, [provider]);
36
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
37
- }
38
- function useIsEditorReady() {
39
- const yjsProvider = useYjsProvider();
40
- const getSnapshot = useCallback(() => {
41
- const status = yjsProvider?.getStatus();
42
- return status === "synchronizing" || status === "synchronized";
43
- }, [yjsProvider]);
44
- const subscribe = useCallback(
45
- (callback) => {
46
- if (yjsProvider === void 0)
47
- return () => {
48
- };
49
- yjsProvider.on("status", callback);
50
- return () => {
51
- yjsProvider.off("status", callback);
52
- };
53
- },
54
- [yjsProvider]
55
- );
56
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
57
- }
58
- const LiveblocksPlugin = ({
59
- children
60
- }) => {
61
- const isResolveMentionSuggestionsDefined = useResolveMentionSuggestions() !== void 0;
62
- const [editor] = useLexicalComposerContext();
63
- const room = useRoom();
64
- if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {
65
- throw new Error(
66
- "LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig"
67
- );
68
- }
69
- const [containerRef, setContainerRef] = useState(void 0);
70
- const {
71
- refs: { setReference, setFloating },
72
- strategy,
73
- x,
74
- y
75
- } = useFloating({
76
- strategy: "fixed",
77
- placement: "bottom",
78
- whileElementsMounted: (...args) => {
79
- return autoUpdate(...args, {
80
- animationFrame: true
81
- });
82
- }
83
- });
84
- useEffect(() => {
85
- if (process.env.NODE_ENV !== "production") {
86
- if (!editor.getEditorState().isEmpty()) {
87
- console.warn(
88
- "Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null."
89
- );
90
- }
91
- }
92
- }, []);
93
- useReportTextEditor(TextEditorType.Lexical, "root");
94
- const self = useSelf();
95
- const providerFactory = useCallback(
96
- (id, yjsDocMap) => {
97
- const provider = getYjsProviderForRoom(room);
98
- yjsDocMap.set(id, provider.getYDoc());
99
- return provider;
100
- },
101
- [room]
102
- );
103
- const root = useRootElement();
104
- useLayoutEffect(() => {
105
- if (root === null)
106
- return;
107
- setReference({
108
- getBoundingClientRect: () => root.getBoundingClientRect()
109
- });
110
- }, [setReference, root]);
111
- const handleFloatingRef = useCallback(
112
- (node) => {
113
- setFloating(node);
114
- setContainerRef({ current: node });
115
- },
116
- [setFloating, setContainerRef]
117
- );
118
- return /* @__PURE__ */ jsxs(Fragment, {
119
- children: [
120
- /* @__PURE__ */ jsx("div", {
121
- ref: handleFloatingRef,
122
- style: {
123
- position: strategy,
124
- top: 0,
125
- left: 0,
126
- transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,
127
- minWidth: "max-content"
128
- }
129
- }),
130
- self && /* @__PURE__ */ jsx(CollaborationPlugin, {
131
- id: room.id,
132
- providerFactory,
133
- username: self.info?.name ?? "",
134
- cursorColor: self.info?.color,
135
- cursorsContainerRef: containerRef,
136
- shouldBootstrap: true
137
- }, room.id),
138
- isResolveMentionSuggestionsDefined && /* @__PURE__ */ jsx(MentionPlugin, {}),
139
- /* @__PURE__ */ jsx(CommentPluginProvider, {
140
- children
141
- })
142
- ]
143
- });
144
- };
145
-
146
- export { LiveblocksPlugin, useEditorStatus, useIsEditorReady };
147
- //# sourceMappingURL=liveblocks-plugin-provider.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"liveblocks-plugin-provider.mjs","sources":["../src/liveblocks-plugin-provider.tsx"],"sourcesContent":["import { autoUpdate, useFloating } from \"@floating-ui/react-dom\";\nimport { CollaborationPlugin } from \"@lexical/react/LexicalCollaborationPlugin\";\nimport { useLexicalComposerContext } from \"@lexical/react/LexicalComposerContext\";\nimport type { Provider } from \"@lexical/yjs\";\nimport { TextEditorType } from \"@liveblocks/core\";\nimport { useRoom, useSelf } from \"@liveblocks/react\";\nimport {\n useLayoutEffect,\n useReportTextEditor,\n useResolveMentionSuggestions,\n useYjsProvider,\n} from \"@liveblocks/react/_private\";\nimport { getYjsProviderForRoom } from \"@liveblocks/yjs\";\nimport type { MutableRefObject, ReactNode } from \"react\";\nimport {\n useCallback,\n useEffect,\n useState,\n useSyncExternalStore,\n} from \"react\";\nimport type { Doc } from \"yjs\";\n\nimport { CommentPluginProvider } from \"./comments/comment-plugin-provider\";\nimport { ThreadMarkNode } from \"./comments/thread-mark-node\";\nimport { MentionNode } from \"./mentions/mention-node\";\nimport { MentionPlugin } from \"./mentions/mention-plugin\";\nimport { useRootElement } from \"./use-root-element\";\n\nexport type EditorStatus =\n /* The editor state is not loaded and has not been requested. */\n | \"not-loaded\"\n /* The editor state is loading from Liveblocks servers */\n | \"loading\"\n /**\n * Not working yet! Will be available in a future release.\n * Some editor state modifications has not been acknowledged yet by the server\n */\n | \"synchronizing\"\n /* The editor state is sync with Liveblocks servers */\n | \"synchronized\";\n\n/**\n * Get the storage status.\n *\n * - `not-loaded`: Initial state when entering the room.\n * - `loading`: Once the editor state has been requested by LiveblocksPlugin.\n * - `synchronizing`: Not working yet! Will be available in a future release.\n * - `synchronized`: The editor state is sync with Liveblocks servers.\n *\n * @deprecated Prefer `useIsEditorReady` or `useSyncStatus` (from @liveblocks/react)\n */\nexport function useEditorStatus(): EditorStatus {\n const provider = useYjsProvider();\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n if (provider === undefined) return () => { };\n provider.on(\"status\", onStoreChange);\n return () => {\n provider.off(\"status\", onStoreChange);\n };\n },\n [provider]\n );\n\n const getSnapshot = useCallback(() => {\n if (provider === undefined) {\n return \"not-loaded\";\n }\n return provider.getStatus();\n }, [provider]);\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * Returns whether the editor has loaded the initial text contents from the\n * server and is ready to be used.\n */\nexport function useIsEditorReady(): boolean {\n const yjsProvider = useYjsProvider();\n\n const getSnapshot = useCallback(() => {\n const status = yjsProvider?.getStatus();\n return status === \"synchronizing\" || status === \"synchronized\";\n }, [yjsProvider]);\n\n const subscribe = useCallback(\n (callback: () => void) => {\n if (yjsProvider === undefined) return () => { };\n yjsProvider.on(\"status\", callback);\n return () => {\n yjsProvider.off(\"status\", callback);\n };\n },\n [yjsProvider]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\nexport type LiveblocksPluginProps = {\n children?: ReactNode;\n};\n\n/**\n * Liveblocks plugin for Lexical that adds collaboration to your editor.\n *\n * `LiveblocksPlugin` should always be nested inside `LexicalComposer`.\n *\n * @example\n *\n * import { LexicalComposer } from \"@lexical/react/LexicalComposer\";\n * import { RichTextPlugin } from \"@lexical/react/LexicalRichTextPlugin\";\n * import { ContentEditable } from \"@lexical/react/LexicalContentEditable\";\n * import { LexicalErrorBoundary } from \"@lexical/react/LexicalErrorBoundary\";\n * import { liveblocksConfig, LiveblocksPlugin } from \"@liveblocks/react-lexical\";\n *\n * const initialConfig = liveblocksConfig({\n * namespace: \"MyEditor\",\n * theme: {},\n * nodes: [],\n * onError: (err) => console.error(err),\n * });\n *\n * function Editor() {\n * return (\n * <LexicalComposer initialConfig={initialConfig}>\n * <LiveblocksPlugin />\n * <RichTextPlugin\n * contentEditable={<ContentEditable />}\n * placeholder={<div>Enter some text...</div>}\n * ErrorBoundary={LexicalErrorBoundary}\n * />\n * </LexicalComposer>\n * );\n * }\n */\nexport const LiveblocksPlugin = ({\n children,\n}: LiveblocksPluginProps): JSX.Element => {\n const isResolveMentionSuggestionsDefined =\n useResolveMentionSuggestions() !== undefined;\n const [editor] = useLexicalComposerContext();\n const room = useRoom();\n\n if (!editor.hasNodes([ThreadMarkNode, MentionNode])) {\n throw new Error(\n \"LiveblocksPlugin requires Lexical configuration to be wrapped in the `liveblocksConfig(options)` function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-react-lexical#liveblocksConfig\"\n );\n }\n\n const [containerRef, setContainerRef] = useState<\n MutableRefObject<HTMLDivElement | null> | undefined\n >(undefined);\n\n const {\n refs: { setReference, setFloating },\n strategy,\n x,\n y,\n } = useFloating({\n strategy: \"fixed\",\n placement: \"bottom\",\n whileElementsMounted: (...args) => {\n return autoUpdate(...args, {\n animationFrame: true,\n });\n },\n });\n\n // Warn users if initialConfig.editorState, set on the composer, is not null\n useEffect(() => {\n // only in dev mode\n if (process.env.NODE_ENV !== \"production\") {\n // A user should not even be set an emptyState, but when passing null, getEditorState still has initial empty state\n if (!editor.getEditorState().isEmpty()) {\n console.warn(\n \"Warning: LiveblocksPlugin: editorState in initialConfig detected, but must be null.\"\n );\n }\n }\n\n // we know editor is already defined as we're inside LexicalComposer, and we only want this running the first time\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useReportTextEditor(TextEditorType.Lexical, \"root\");\n\n // Get user info or allow override from props\n const self = useSelf();\n\n const providerFactory = useCallback(\n (id: string, yjsDocMap: Map<string, Doc>): Provider => {\n const provider = getYjsProviderForRoom(room);\n yjsDocMap.set(id, provider.getYDoc());\n\n return provider as Provider;\n },\n [room]\n );\n\n const root = useRootElement();\n\n useLayoutEffect(() => {\n if (root === null) return;\n setReference({\n getBoundingClientRect: () => root.getBoundingClientRect(),\n });\n }, [setReference, root]);\n\n const handleFloatingRef = useCallback(\n (node: HTMLDivElement) => {\n setFloating(node);\n setContainerRef({ current: node });\n },\n [setFloating, setContainerRef]\n );\n\n return (\n <>\n <div\n ref={handleFloatingRef}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,\n minWidth: \"max-content\",\n }}\n />\n\n {self && (\n <CollaborationPlugin\n // Setting the key allows us to reset the internal Y.doc used by useYjsCollaboration\n // without implementing `reload` event\n key={room.id}\n id={room.id}\n providerFactory={providerFactory}\n username={self.info?.name ?? \"\"} // use empty string to prevent random name\n cursorColor={self.info?.color as string | undefined}\n cursorsContainerRef={containerRef}\n shouldBootstrap={true}\n />\n )}\n\n {isResolveMentionSuggestionsDefined && <MentionPlugin />}\n <CommentPluginProvider>{children}</CommentPluginProvider>\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmDO,SAAS,eAAgC,GAAA;AAC9C,EAAA,MAAM,WAAW,cAAe,EAAA,CAAA;AAEhC,EAAA,MAAM,SAAY,GAAA,WAAA;AAAA,IAChB,CAAC,aAA8B,KAAA;AAC7B,MAAA,IAAI,QAAa,KAAA,KAAA,CAAA;AAAW,QAAA,OAAO,MAAM;AAAA,SAAE,CAAA;AAC3C,MAAS,QAAA,CAAA,EAAA,CAAG,UAAU,aAAa,CAAA,CAAA;AACnC,MAAA,OAAO,MAAM;AACX,QAAS,QAAA,CAAA,GAAA,CAAI,UAAU,aAAa,CAAA,CAAA;AAAA,OACtC,CAAA;AAAA,KACF;AAAA,IACA,CAAC,QAAQ,CAAA;AAAA,GACX,CAAA;AAEA,EAAM,MAAA,WAAA,GAAc,YAAY,MAAM;AACpC,IAAA,IAAI,aAAa,KAAW,CAAA,EAAA;AAC1B,MAAO,OAAA,YAAA,CAAA;AAAA,KACT;AACA,IAAA,OAAO,SAAS,SAAU,EAAA,CAAA;AAAA,GAC5B,EAAG,CAAC,QAAQ,CAAC,CAAA,CAAA;AAEb,EAAO,OAAA,oBAAA,CAAqB,SAAW,EAAA,WAAA,EAAa,WAAW,CAAA,CAAA;AACjE,CAAA;AAMO,SAAS,gBAA4B,GAAA;AAC1C,EAAA,MAAM,cAAc,cAAe,EAAA,CAAA;AAEnC,EAAM,MAAA,WAAA,GAAc,YAAY,MAAM;AACpC,IAAM,MAAA,MAAA,GAAS,aAAa,SAAU,EAAA,CAAA;AACtC,IAAO,OAAA,MAAA,KAAW,mBAAmB,MAAW,KAAA,cAAA,CAAA;AAAA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