@lexical/react 0.49.1-nightly.20260901.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LexicalAutoEmbedPlugin.d.ts +4 -47
- package/dist/LexicalAutoEmbedPlugin.dev.js +5 -31
- package/dist/LexicalAutoEmbedPlugin.dev.mjs +5 -30
- package/dist/LexicalAutoEmbedPlugin.prod.js +1 -1
- package/dist/LexicalAutoEmbedPlugin.prod.mjs +1 -1
- package/dist/LexicalAutoEmbedPluginUtils.d.ts +53 -0
- package/dist/LexicalAutoEmbedPluginUtils.dev.js +66 -0
- package/dist/LexicalAutoEmbedPluginUtils.dev.mjs +62 -0
- package/dist/LexicalAutoEmbedPluginUtils.js +11 -0
- package/dist/LexicalAutoEmbedPluginUtils.js.flow +40 -0
- package/dist/LexicalAutoEmbedPluginUtils.mjs +14 -0
- package/dist/LexicalAutoEmbedPluginUtils.node.mjs +12 -0
- package/dist/LexicalAutoEmbedPluginUtils.prod.js +9 -0
- package/dist/LexicalAutoEmbedPluginUtils.prod.mjs +9 -0
- package/dist/LexicalCollaborationContext.d.ts +1 -26
- package/dist/LexicalCollaborationContext.dev.js +5 -55
- package/dist/LexicalCollaborationContext.dev.mjs +4 -53
- package/dist/LexicalCollaborationContext.prod.js +2 -2
- package/dist/LexicalCollaborationContext.prod.mjs +2 -2
- package/dist/LexicalCollaborationContextUtils.d.ts +35 -0
- package/dist/LexicalCollaborationContextUtils.dev.js +83 -0
- package/dist/LexicalCollaborationContextUtils.dev.mjs +79 -0
- package/dist/LexicalCollaborationContextUtils.js +11 -0
- package/dist/LexicalCollaborationContextUtils.js.flow +25 -0
- package/dist/LexicalCollaborationContextUtils.mjs +14 -0
- package/dist/LexicalCollaborationContextUtils.node.mjs +12 -0
- package/dist/LexicalCollaborationContextUtils.prod.js +9 -0
- package/dist/LexicalCollaborationContextUtils.prod.mjs +9 -0
- package/dist/LexicalMenuOption.d.ts +29 -0
- package/dist/LexicalMenuOption.dev.js +51 -0
- package/dist/LexicalMenuOption.dev.mjs +49 -0
- package/dist/LexicalMenuOption.js +11 -0
- package/dist/LexicalMenuOption.js.flow +20 -0
- package/dist/LexicalMenuOption.mjs +12 -0
- package/dist/LexicalMenuOption.node.mjs +10 -0
- package/dist/LexicalMenuOption.prod.js +9 -0
- package/dist/LexicalMenuOption.prod.mjs +9 -0
- package/dist/LexicalNodeMenuPlugin.dev.js +5 -28
- package/dist/LexicalNodeMenuPlugin.dev.mjs +4 -27
- package/dist/LexicalNodeMenuPlugin.prod.js +1 -1
- package/dist/LexicalNodeMenuPlugin.prod.mjs +1 -1
- package/dist/LexicalTypeaheadMenuPlugin.d.ts +2 -34
- package/dist/LexicalTypeaheadMenuPlugin.dev.js +10 -78
- package/dist/LexicalTypeaheadMenuPlugin.dev.mjs +9 -76
- package/dist/LexicalTypeaheadMenuPlugin.prod.js +1 -1
- package/dist/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
- package/dist/LexicalTypeaheadMenuPluginUtils.d.ts +44 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.dev.js +81 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.dev.mjs +76 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.js +11 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.js.flow +34 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.mjs +15 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.node.mjs +13 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.prod.js +9 -0
- package/dist/LexicalTypeaheadMenuPluginUtils.prod.mjs +9 -0
- package/dist/shared/LexicalMenu.d.ts +5 -19
- package/package.json +164 -20
- package/src/LexicalAutoEmbedPlugin.tsx +12 -70
- package/src/LexicalAutoEmbedPluginUtils.ts +80 -0
- package/src/LexicalCollaborationContext.tsx +11 -90
- package/src/LexicalCollaborationContextUtils.ts +99 -0
- package/src/LexicalMenuOption.ts +39 -0
- package/src/LexicalTypeaheadMenuPlugin.tsx +6 -80
- package/src/LexicalTypeaheadMenuPluginUtils.ts +93 -0
- package/src/shared/LexicalMenu.tsx +12 -28
|
@@ -5,53 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import { type
|
|
8
|
+
import { type AutoEmbedOption, type EmbedConfig } from '@lexical/react/LexicalAutoEmbedPluginUtils';
|
|
9
|
+
import { type MenuRenderFn } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
10
|
+
import { type CommandListenerPriority } from 'lexical';
|
|
10
11
|
import { type JSX } from 'react';
|
|
11
|
-
|
|
12
|
-
* The result of matching a URL for an embed: the matched `url`, an `id`
|
|
13
|
-
* identifying the embedded resource, and optional provider-specific `data`.
|
|
14
|
-
*/
|
|
15
|
-
export type EmbedMatchResult<TEmbedMatchResult = unknown> = {
|
|
16
|
-
url: string;
|
|
17
|
-
id: string;
|
|
18
|
-
data?: TEmbedMatchResult;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Describes a kind of embed (for example YouTube, a tweet, or Google Maps) that
|
|
22
|
-
* {@link LexicalAutoEmbedPlugin} can detect and insert. Each config has a `type`
|
|
23
|
-
* identifier, a `parseUrl` function that decides whether a URL matches and
|
|
24
|
-
* extracts its data, and an `insertNode` function that inserts the corresponding
|
|
25
|
-
* Lexical node.
|
|
26
|
-
*/
|
|
27
|
-
export interface EmbedConfig<TEmbedMatchResultData = unknown, TEmbedMatchResult = EmbedMatchResult<TEmbedMatchResultData>> {
|
|
28
|
-
type: string;
|
|
29
|
-
parseUrl: (text: string) => Promise<TEmbedMatchResult | null> | TEmbedMatchResult | null;
|
|
30
|
-
insertNode: (editor: LexicalEditor, result: TEmbedMatchResult) => void;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* A general-purpose regular expression for detecting URLs, provided as a
|
|
34
|
-
* convenience for implementing an {@link EmbedConfig}'s `parseUrl`.
|
|
35
|
-
*/
|
|
36
|
-
export declare const URL_MATCHER: RegExp;
|
|
37
|
-
/**
|
|
38
|
-
* Command dispatched to start inserting an embed. Its payload is the `type` of
|
|
39
|
-
* the {@link EmbedConfig} to use; {@link LexicalAutoEmbedPlugin} listens for it
|
|
40
|
-
* and runs that config's URL detection flow.
|
|
41
|
-
*/
|
|
42
|
-
export declare const INSERT_EMBED_COMMAND: LexicalCommand<EmbedConfig['type']>;
|
|
43
|
-
/**
|
|
44
|
-
* A {@link MenuOption} for the auto-embed menu, pairing a display `title` with
|
|
45
|
-
* an `onSelect` callback invoked when the user chooses to embed the detected
|
|
46
|
-
* URL.
|
|
47
|
-
*/
|
|
48
|
-
export declare class AutoEmbedOption extends MenuOption {
|
|
49
|
-
title: string;
|
|
50
|
-
onSelect: (targetNode: LexicalNode | null) => void;
|
|
51
|
-
constructor(title: string, options: {
|
|
52
|
-
onSelect: (targetNode: LexicalNode | null) => void;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
12
|
+
export { AutoEmbedOption, type EmbedConfig, type EmbedMatchResult, INSERT_EMBED_COMMAND, URL_MATCHER, } from '@lexical/react/LexicalAutoEmbedPluginUtils';
|
|
55
13
|
type LexicalAutoEmbedPluginProps<TEmbedConfig extends EmbedConfig> = {
|
|
56
14
|
/**
|
|
57
15
|
* An array of configurations used to insert Embed elements
|
|
@@ -117,4 +75,3 @@ type LexicalAutoEmbedPluginProps<TEmbedConfig extends EmbedConfig> = {
|
|
|
117
75
|
* ```
|
|
118
76
|
*/
|
|
119
77
|
export declare function LexicalAutoEmbedPlugin<TEmbedConfig extends EmbedConfig>({ embedConfigs, onOpenEmbedModalForConfig, getMenuOptions, menuRenderFn, menuCommandPriority, }: LexicalAutoEmbedPluginProps<TEmbedConfig>): JSX.Element | null;
|
|
120
|
-
export {};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
11
|
var link = require('@lexical/link');
|
|
12
|
+
var LexicalAutoEmbedPluginUtils = require('@lexical/react/LexicalAutoEmbedPluginUtils');
|
|
12
13
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
13
14
|
var LexicalNodeMenuPlugin = require('@lexical/react/LexicalNodeMenuPlugin');
|
|
14
15
|
var utils = require('@lexical/utils');
|
|
@@ -24,33 +25,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
24
25
|
*
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
-
* A general-purpose regular expression for detecting URLs, provided as a
|
|
29
|
-
* convenience for implementing an {@link EmbedConfig}'s `parseUrl`.
|
|
30
|
-
*/
|
|
31
|
-
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Command dispatched to start inserting an embed. Its payload is the `type` of
|
|
35
|
-
* the {@link EmbedConfig} to use; {@link LexicalAutoEmbedPlugin} listens for it
|
|
36
|
-
* and runs that config's URL detection flow.
|
|
37
|
-
*/
|
|
38
|
-
const INSERT_EMBED_COMMAND = /* @__PURE__ */lexical.createCommand('INSERT_EMBED_COMMAND');
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A {@link MenuOption} for the auto-embed menu, pairing a display `title` with
|
|
42
|
-
* an `onSelect` callback invoked when the user chooses to embed the detected
|
|
43
|
-
* URL.
|
|
44
|
-
*/
|
|
45
|
-
class AutoEmbedOption extends LexicalNodeMenuPlugin.MenuOption {
|
|
46
|
-
title;
|
|
47
|
-
onSelect;
|
|
48
|
-
constructor(title, options) {
|
|
49
|
-
super(title);
|
|
50
|
-
this.title = title;
|
|
51
|
-
this.onSelect = options.onSelect.bind(this);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
28
|
/**
|
|
55
29
|
* Watches for pasted AutoLink nodes that match any of the provided embed configurations (e.g., YouTube, Twitter URLs).
|
|
56
30
|
* When a match is found, it shows a menu offering to replace the link with an embedded node.
|
|
@@ -138,7 +112,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
138
112
|
}, [checkIfLinkNodeIsEmbeddable, editor, nodeKey, reset]);
|
|
139
113
|
react.useEffect(() => {
|
|
140
114
|
if (!onOpenEmbedModalForConfig) return;
|
|
141
|
-
return editor.registerCommand(INSERT_EMBED_COMMAND, embedConfigType => {
|
|
115
|
+
return editor.registerCommand(LexicalAutoEmbedPluginUtils.INSERT_EMBED_COMMAND, embedConfigType => {
|
|
142
116
|
const embedConfig = embedConfigs.find(({
|
|
143
117
|
type
|
|
144
118
|
}) => type === embedConfigType);
|
|
@@ -193,7 +167,7 @@ function LexicalAutoEmbedPlugin({
|
|
|
193
167
|
}) : null;
|
|
194
168
|
}
|
|
195
169
|
|
|
196
|
-
exports.AutoEmbedOption = AutoEmbedOption;
|
|
197
|
-
exports.INSERT_EMBED_COMMAND = INSERT_EMBED_COMMAND;
|
|
170
|
+
exports.AutoEmbedOption = LexicalAutoEmbedPluginUtils.AutoEmbedOption;
|
|
171
|
+
exports.INSERT_EMBED_COMMAND = LexicalAutoEmbedPluginUtils.INSERT_EMBED_COMMAND;
|
|
172
|
+
exports.URL_MATCHER = LexicalAutoEmbedPluginUtils.URL_MATCHER;
|
|
198
173
|
exports.LexicalAutoEmbedPlugin = LexicalAutoEmbedPlugin;
|
|
199
|
-
exports.URL_MATCHER = URL_MATCHER;
|
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { $isLinkNode, LinkNode, AutoLinkNode } from '@lexical/link';
|
|
10
|
+
import { INSERT_EMBED_COMMAND } from '@lexical/react/LexicalAutoEmbedPluginUtils';
|
|
11
|
+
export { AutoEmbedOption, INSERT_EMBED_COMMAND, URL_MATCHER } from '@lexical/react/LexicalAutoEmbedPluginUtils';
|
|
10
12
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
11
|
-
import {
|
|
13
|
+
import { LexicalNodeMenuPlugin } from '@lexical/react/LexicalNodeMenuPlugin';
|
|
12
14
|
import { objectKlassEquals } from '@lexical/utils';
|
|
13
|
-
import {
|
|
15
|
+
import { $getNodeByKey, mergeRegister, PASTE_COMMAND, $onUpdate, COMMAND_PRIORITY_BEFORE_EDITOR, COMMAND_PRIORITY_EDITOR, $getSelection, COMMAND_PRIORITY_LOW, PASTE_TAG } from 'lexical';
|
|
14
16
|
import { useState, useCallback, useEffect, useMemo } from 'react';
|
|
15
17
|
import { jsx } from 'react/jsx-runtime';
|
|
16
18
|
|
|
@@ -22,33 +24,6 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
22
24
|
*
|
|
23
25
|
*/
|
|
24
26
|
|
|
25
|
-
/**
|
|
26
|
-
* A general-purpose regular expression for detecting URLs, provided as a
|
|
27
|
-
* convenience for implementing an {@link EmbedConfig}'s `parseUrl`.
|
|
28
|
-
*/
|
|
29
|
-
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Command dispatched to start inserting an embed. Its payload is the `type` of
|
|
33
|
-
* the {@link EmbedConfig} to use; {@link LexicalAutoEmbedPlugin} listens for it
|
|
34
|
-
* and runs that config's URL detection flow.
|
|
35
|
-
*/
|
|
36
|
-
const INSERT_EMBED_COMMAND = /* @__PURE__ */createCommand('INSERT_EMBED_COMMAND');
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* A {@link MenuOption} for the auto-embed menu, pairing a display `title` with
|
|
40
|
-
* an `onSelect` callback invoked when the user chooses to embed the detected
|
|
41
|
-
* URL.
|
|
42
|
-
*/
|
|
43
|
-
class AutoEmbedOption extends MenuOption {
|
|
44
|
-
title;
|
|
45
|
-
onSelect;
|
|
46
|
-
constructor(title, options) {
|
|
47
|
-
super(title);
|
|
48
|
-
this.title = title;
|
|
49
|
-
this.onSelect = options.onSelect.bind(this);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
27
|
/**
|
|
53
28
|
* Watches for pasted AutoLink nodes that match any of the provided embed configurations (e.g., YouTube, Twitter URLs).
|
|
54
29
|
* When a match is found, it shows a menu offering to replace the link with an embedded node.
|
|
@@ -191,4 +166,4 @@ function LexicalAutoEmbedPlugin({
|
|
|
191
166
|
}) : null;
|
|
192
167
|
}
|
|
193
168
|
|
|
194
|
-
export {
|
|
169
|
+
export { LexicalAutoEmbedPlugin };
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/link"),t=require("@lexical/react/
|
|
9
|
+
"use strict";var e=require("@lexical/link"),t=require("@lexical/react/LexicalAutoEmbedPluginUtils"),n=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/react/LexicalNodeMenuPlugin"),i=require("@lexical/utils"),o=require("lexical"),r=require("react"),a=require("react/jsx-runtime");exports.AutoEmbedOption=t.AutoEmbedOption,exports.INSERT_EMBED_COMMAND=t.INSERT_EMBED_COMMAND,exports.URL_MATCHER=t.URL_MATCHER,exports.LexicalAutoEmbedPlugin=function({embedConfigs:s,onOpenEmbedModalForConfig:u,getMenuOptions:c,menuRenderFn:d,menuCommandPriority:E=o.COMMAND_PRIORITY_LOW}){const[m]=n.useLexicalComposerContext(),[p,M]=r.useState(null),[C,x]=r.useState(null),N=r.useCallback(()=>{M(null),x(null)},[]),R=r.useCallback(async t=>{const n=m.read("latest",function(){const n=o.$getNodeByKey(t);if(e.$isLinkNode(n))return n.getURL()});if(void 0!==n)for(const e of s){null!=await Promise.resolve(e.parseUrl(n))&&(x(e),M(t))}},[m,s]);r.useEffect(()=>{let t=!1;const n=(e,{updateTags:n})=>{for(const[l,i]of e)"created"===i&&n.has(o.PASTE_TAG)&&t?R(l):l===p&&N()};return o.mergeRegister(m.registerCommand(o.PASTE_COMMAND,e=>(t=i.objectKlassEquals(e,ClipboardEvent)&&null!==e.clipboardData&&/^\S+$/.test(e.clipboardData.getData("text/plain")),t&&o.$onUpdate(()=>{t=!1}),!1),o.COMMAND_PRIORITY_BEFORE_EDITOR),...[e.LinkNode,e.AutoLinkNode].map(e=>m.registerMutationListener(e,n,{skipInitialization:!0})))},[R,m,p,N]),r.useEffect(()=>{if(u)return m.registerCommand(t.INSERT_EMBED_COMMAND,e=>{const t=s.find(({type:t})=>t===e);return!!t&&(u(t),!0)},o.COMMAND_PRIORITY_EDITOR)},[m,s,u]);const f=r.useCallback(async function(){if(null!=C&&null!=p){const t=m.read("latest",()=>{const t=o.$getNodeByKey(p);return e.$isLinkNode(t)?t:null});if(e.$isLinkNode(t)){const e=await Promise.resolve(C.parseUrl(t.__url));null!=e&&m.update(()=>{o.$getSelection()||t.selectEnd(),C.insertNode(m,e),t.isAttached()&&t.remove()})}}},[C,m,p]),O=r.useMemo(()=>null!=C&&null!=p?c(C,f,N):[],[C,f,c,p,N]),_=r.useCallback((e,t,n)=>{m.update(()=>{e.onSelect(t),n()})},[m]);return null!=p?/*#__PURE__*/a.jsx(l.LexicalNodeMenuPlugin,{nodeKey:p,onClose:N,onSelectOption:_,options:O,menuRenderFn:d,commandPriority:E}):null};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isLinkNode as
|
|
9
|
+
import{$isLinkNode as e,LinkNode as t,AutoLinkNode as n}from"@lexical/link";import{INSERT_EMBED_COMMAND as o}from"@lexical/react/LexicalAutoEmbedPluginUtils";export{AutoEmbedOption,INSERT_EMBED_COMMAND,URL_MATCHER}from"@lexical/react/LexicalAutoEmbedPluginUtils";import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{LexicalNodeMenuPlugin as l}from"@lexical/react/LexicalNodeMenuPlugin";import{objectKlassEquals as i}from"@lexical/utils";import{$getNodeByKey as a,mergeRegister as c,PASTE_COMMAND as s,$onUpdate as u,COMMAND_PRIORITY_BEFORE_EDITOR as m,COMMAND_PRIORITY_EDITOR as d,$getSelection as p,COMMAND_PRIORITY_LOW as f,PASTE_TAG as x}from"lexical";import{useState as g,useCallback as C,useEffect as E,useMemo as b}from"react";import{jsx as M}from"react/jsx-runtime";function L({embedConfigs:L,onOpenEmbedModalForConfig:P,getMenuOptions:y,menuRenderFn:A,menuCommandPriority:R=f}){const[U]=r(),[v,D]=g(null),[O,_]=g(null),N=C(()=>{D(null),_(null)},[]),S=C(async t=>{const n=U.read("latest",function(){const n=a(t);if(e(n))return n.getURL()});if(void 0!==n)for(const e of L){null!=await Promise.resolve(e.parseUrl(n))&&(_(e),D(t))}},[U,L]);E(()=>{let e=!1;const o=(t,{updateTags:n})=>{for(const[o,r]of t)"created"===r&&n.has(x)&&e?S(o):o===v&&N()};return c(U.registerCommand(s,t=>(e=i(t,ClipboardEvent)&&null!==t.clipboardData&&/^\S+$/.test(t.clipboardData.getData("text/plain")),e&&u(()=>{e=!1}),!1),m),...[t,n].map(e=>U.registerMutationListener(e,o,{skipInitialization:!0})))},[S,U,v,N]),E(()=>{if(P)return U.registerCommand(o,e=>{const t=L.find(({type:t})=>t===e);return!!t&&(P(t),!0)},d)},[U,L,P]);const F=C(async function(){if(null!=O&&null!=v){const t=U.read("latest",()=>{const t=a(v);return e(t)?t:null});if(e(t)){const e=await Promise.resolve(O.parseUrl(t.__url));null!=e&&U.update(()=>{p()||t.selectEnd(),O.insertNode(U,e),t.isAttached()&&t.remove()})}}},[O,U,v]),T=b(()=>null!=O&&null!=v?y(O,F,N):[],[O,F,y,v,N]),h=C((e,t,n)=>{U.update(()=>{e.onSelect(t),n()})},[U]);return null!=v?/*#__PURE__*/M(l,{nodeKey:v,onClose:N,onSelectOption:h,options:T,menuRenderFn:A,commandPriority:R}):null}export{L as LexicalAutoEmbedPlugin};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { MenuOption } from '@lexical/react/LexicalMenuOption';
|
|
9
|
+
import { type LexicalCommand, type LexicalEditor, type LexicalNode } from 'lexical';
|
|
10
|
+
/**
|
|
11
|
+
* The result of matching a URL for an embed: the matched `url`, an `id`
|
|
12
|
+
* identifying the embedded resource, and optional provider-specific `data`.
|
|
13
|
+
*/
|
|
14
|
+
export type EmbedMatchResult<TEmbedMatchResult = unknown> = {
|
|
15
|
+
url: string;
|
|
16
|
+
id: string;
|
|
17
|
+
data?: TEmbedMatchResult;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Describes a kind of embed (for example YouTube, a tweet, or Google Maps) that
|
|
21
|
+
* {@link LexicalAutoEmbedPlugin} can detect and insert. Each config has a `type`
|
|
22
|
+
* identifier, a `parseUrl` function that decides whether a URL matches and
|
|
23
|
+
* extracts its data, and an `insertNode` function that inserts the corresponding
|
|
24
|
+
* Lexical node.
|
|
25
|
+
*/
|
|
26
|
+
export interface EmbedConfig<TEmbedMatchResultData = unknown, TEmbedMatchResult = EmbedMatchResult<TEmbedMatchResultData>> {
|
|
27
|
+
type: string;
|
|
28
|
+
parseUrl: (text: string) => Promise<TEmbedMatchResult | null> | TEmbedMatchResult | null;
|
|
29
|
+
insertNode: (editor: LexicalEditor, result: TEmbedMatchResult) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A general-purpose regular expression for detecting URLs, provided as a
|
|
33
|
+
* convenience for implementing an {@link EmbedConfig}'s `parseUrl`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const URL_MATCHER: RegExp;
|
|
36
|
+
/**
|
|
37
|
+
* Command dispatched to start inserting an embed. Its payload is the `type` of
|
|
38
|
+
* the {@link EmbedConfig} to use; {@link LexicalAutoEmbedPlugin} listens for it
|
|
39
|
+
* and runs that config's URL detection flow.
|
|
40
|
+
*/
|
|
41
|
+
export declare const INSERT_EMBED_COMMAND: LexicalCommand<EmbedConfig['type']>;
|
|
42
|
+
/**
|
|
43
|
+
* A {@link MenuOption} for the auto-embed menu, pairing a display `title` with
|
|
44
|
+
* an `onSelect` callback invoked when the user chooses to embed the detected
|
|
45
|
+
* URL.
|
|
46
|
+
*/
|
|
47
|
+
export declare class AutoEmbedOption extends MenuOption {
|
|
48
|
+
title: string;
|
|
49
|
+
onSelect: (targetNode: LexicalNode | null) => void;
|
|
50
|
+
constructor(title: string, options: {
|
|
51
|
+
onSelect: (targetNode: LexicalNode | null) => void;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var LexicalMenuOption = require('@lexical/react/LexicalMenuOption');
|
|
12
|
+
var lexical = require('lexical');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The result of matching a URL for an embed: the matched `url`, an `id`
|
|
25
|
+
* identifying the embedded resource, and optional provider-specific `data`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Describes a kind of embed (for example YouTube, a tweet, or Google Maps) that
|
|
30
|
+
* {@link LexicalAutoEmbedPlugin} can detect and insert. Each config has a `type`
|
|
31
|
+
* identifier, a `parseUrl` function that decides whether a URL matches and
|
|
32
|
+
* extracts its data, and an `insertNode` function that inserts the corresponding
|
|
33
|
+
* Lexical node.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A general-purpose regular expression for detecting URLs, provided as a
|
|
38
|
+
* convenience for implementing an {@link EmbedConfig}'s `parseUrl`.
|
|
39
|
+
*/
|
|
40
|
+
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Command dispatched to start inserting an embed. Its payload is the `type` of
|
|
44
|
+
* the {@link EmbedConfig} to use; {@link LexicalAutoEmbedPlugin} listens for it
|
|
45
|
+
* and runs that config's URL detection flow.
|
|
46
|
+
*/
|
|
47
|
+
const INSERT_EMBED_COMMAND = /* @__PURE__ */lexical.createCommand('INSERT_EMBED_COMMAND');
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A {@link MenuOption} for the auto-embed menu, pairing a display `title` with
|
|
51
|
+
* an `onSelect` callback invoked when the user chooses to embed the detected
|
|
52
|
+
* URL.
|
|
53
|
+
*/
|
|
54
|
+
class AutoEmbedOption extends LexicalMenuOption.MenuOption {
|
|
55
|
+
title;
|
|
56
|
+
onSelect;
|
|
57
|
+
constructor(title, options) {
|
|
58
|
+
super(title);
|
|
59
|
+
this.title = title;
|
|
60
|
+
this.onSelect = options.onSelect.bind(this);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.AutoEmbedOption = AutoEmbedOption;
|
|
65
|
+
exports.INSERT_EMBED_COMMAND = INSERT_EMBED_COMMAND;
|
|
66
|
+
exports.URL_MATCHER = URL_MATCHER;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { MenuOption } from '@lexical/react/LexicalMenuOption';
|
|
10
|
+
import { createCommand } from 'lexical';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The result of matching a URL for an embed: the matched `url`, an `id`
|
|
23
|
+
* identifying the embedded resource, and optional provider-specific `data`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Describes a kind of embed (for example YouTube, a tweet, or Google Maps) that
|
|
28
|
+
* {@link LexicalAutoEmbedPlugin} can detect and insert. Each config has a `type`
|
|
29
|
+
* identifier, a `parseUrl` function that decides whether a URL matches and
|
|
30
|
+
* extracts its data, and an `insertNode` function that inserts the corresponding
|
|
31
|
+
* Lexical node.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A general-purpose regular expression for detecting URLs, provided as a
|
|
36
|
+
* convenience for implementing an {@link EmbedConfig}'s `parseUrl`.
|
|
37
|
+
*/
|
|
38
|
+
const URL_MATCHER = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Command dispatched to start inserting an embed. Its payload is the `type` of
|
|
42
|
+
* the {@link EmbedConfig} to use; {@link LexicalAutoEmbedPlugin} listens for it
|
|
43
|
+
* and runs that config's URL detection flow.
|
|
44
|
+
*/
|
|
45
|
+
const INSERT_EMBED_COMMAND = /* @__PURE__ */createCommand('INSERT_EMBED_COMMAND');
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A {@link MenuOption} for the auto-embed menu, pairing a display `title` with
|
|
49
|
+
* an `onSelect` callback invoked when the user chooses to embed the detected
|
|
50
|
+
* URL.
|
|
51
|
+
*/
|
|
52
|
+
class AutoEmbedOption extends MenuOption {
|
|
53
|
+
title;
|
|
54
|
+
onSelect;
|
|
55
|
+
constructor(title, options) {
|
|
56
|
+
super(title);
|
|
57
|
+
this.title = title;
|
|
58
|
+
this.onSelect = options.onSelect.bind(this);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { AutoEmbedOption, INSERT_EMBED_COMMAND, URL_MATCHER };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict'
|
|
10
|
+
const LexicalAutoEmbedPluginUtils = process.env.NODE_ENV !== 'production' ? require('./LexicalAutoEmbedPluginUtils.dev.js') : require('./LexicalAutoEmbedPluginUtils.prod.js');
|
|
11
|
+
module.exports = LexicalAutoEmbedPluginUtils;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {LexicalCommand, LexicalEditor, LexicalNode} from 'lexical';
|
|
11
|
+
|
|
12
|
+
import {MenuOption} from '@lexical/react/LexicalMenuOption';
|
|
13
|
+
|
|
14
|
+
export type EmbedMatchResult<TEmbedMatchResult = unknown> = {
|
|
15
|
+
url: string,
|
|
16
|
+
id: string,
|
|
17
|
+
data?: TEmbedMatchResult,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export interface EmbedConfig<
|
|
21
|
+
TEmbedMatchResultData = unknown,
|
|
22
|
+
TEmbedMatchResult = EmbedMatchResult<TEmbedMatchResultData>,
|
|
23
|
+
> {
|
|
24
|
+
type: string;
|
|
25
|
+
parseUrl: (
|
|
26
|
+
text: string,
|
|
27
|
+
) => Promise<TEmbedMatchResult | null> | TEmbedMatchResult | null;
|
|
28
|
+
insertNode: (editor: LexicalEditor, result: TEmbedMatchResult) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare export var URL_MATCHER: RegExp;
|
|
32
|
+
declare export var INSERT_EMBED_COMMAND: LexicalCommand<EmbedConfig<>['type']>;
|
|
33
|
+
|
|
34
|
+
declare export class AutoEmbedOption extends MenuOption {
|
|
35
|
+
onSelect: (targetNode: LexicalNode | null) => void;
|
|
36
|
+
constructor(
|
|
37
|
+
title: string,
|
|
38
|
+
options: {onSelect: (targetNode: LexicalNode | null) => void},
|
|
39
|
+
): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as modDev from './LexicalAutoEmbedPluginUtils.dev.mjs';
|
|
10
|
+
import * as modProd from './LexicalAutoEmbedPluginUtils.prod.mjs';
|
|
11
|
+
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
|
|
12
|
+
export const AutoEmbedOption = mod.AutoEmbedOption;
|
|
13
|
+
export const INSERT_EMBED_COMMAND = mod.INSERT_EMBED_COMMAND;
|
|
14
|
+
export const URL_MATCHER = mod.URL_MATCHER;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalAutoEmbedPluginUtils.dev.mjs') : import('./LexicalAutoEmbedPluginUtils.prod.mjs'));
|
|
10
|
+
export const AutoEmbedOption = mod.AutoEmbedOption;
|
|
11
|
+
export const INSERT_EMBED_COMMAND = mod.INSERT_EMBED_COMMAND;
|
|
12
|
+
export const URL_MATCHER = mod.URL_MATCHER;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";var e=require("@lexical/react/LexicalMenuOption");const t=/* @__PURE__ */require("lexical").createCommand("INSERT_EMBED_COMMAND");class i extends e.MenuOption{title;onSelect;constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}}exports.AutoEmbedOption=i,exports.INSERT_EMBED_COMMAND=t,exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import{MenuOption as t}from"@lexical/react/LexicalMenuOption";import{createCommand as e}from"lexical";const i=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,o=/* @__PURE__ */e("INSERT_EMBED_COMMAND");class c extends t{title;onSelect;constructor(t,e){super(t),this.title=t,this.onSelect=e.onSelect.bind(this)}}export{c as AutoEmbedOption,o as INSERT_EMBED_COMMAND,i as URL_MATCHER};
|
|
@@ -5,24 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The value stored in the {@link CollaborationContext}: the local user's
|
|
11
|
-
* display `name` and cursor `color`, whether collaboration is currently active,
|
|
12
|
-
* and the map of Yjs documents shared by the editors under this provider.
|
|
13
|
-
*/
|
|
14
|
-
export type CollaborationContextType = {
|
|
15
|
-
color: string;
|
|
16
|
-
isCollabActive: boolean;
|
|
17
|
-
name: string;
|
|
18
|
-
yjsDocMap: Map<string, Doc>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* The React context that holds the shared {@link CollaborationContextType} for
|
|
22
|
-
* collaborative editors. Provide it with {@link LexicalCollaboration} and read
|
|
23
|
-
* it with {@link useCollaborationContext}.
|
|
24
|
-
*/
|
|
25
|
-
export declare const CollaborationContext: import("react").Context<CollaborationContextType | null>;
|
|
8
|
+
export { CollaborationContext, type CollaborationContextType, useCollaborationContext, } from '@lexical/react/LexicalCollaborationContextUtils';
|
|
26
9
|
/**
|
|
27
10
|
* A provider component that creates a fresh {@link CollaborationContextType}
|
|
28
11
|
* and makes it available to descendant editors via {@link CollaborationContext}.
|
|
@@ -34,11 +17,3 @@ export declare const CollaborationContext: import("react").Context<Collaboration
|
|
|
34
17
|
export declare function LexicalCollaboration({ children }: {
|
|
35
18
|
children: React.ReactNode;
|
|
36
19
|
}): import("react/jsx-runtime").JSX.Element;
|
|
37
|
-
/**
|
|
38
|
-
* Reads the current {@link CollaborationContextType} from the nearest
|
|
39
|
-
* {@link LexicalCollaboration} provider. Optionally pass `username` and `color`
|
|
40
|
-
* to set the local user's display name and cursor color.
|
|
41
|
-
*
|
|
42
|
-
* @returns The active collaboration context.
|
|
43
|
-
*/
|
|
44
|
-
export declare function useCollaborationContext(username?: string, color?: string): CollaborationContextType;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
+
var LexicalCollaborationContextUtils = require('@lexical/react/LexicalCollaborationContextUtils');
|
|
11
12
|
var react = require('react');
|
|
12
13
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
14
|
|
|
@@ -19,33 +20,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
19
20
|
*
|
|
20
21
|
*/
|
|
21
22
|
|
|
22
|
-
// Do not require this module directly! Use normal `invariant` calls.
|
|
23
|
-
|
|
24
|
-
function formatDevErrorMessage(message) {
|
|
25
|
-
throw new Error(message);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const entries = [['Cat', 'rgb(125, 50, 0)'], ['Dog', 'rgb(100, 0, 0)'], ['Rabbit', 'rgb(150, 0, 0)'], ['Frog', 'rgb(200, 0, 0)'], ['Fox', 'rgb(200, 75, 0)'], ['Hedgehog', 'rgb(0, 75, 0)'], ['Pigeon', 'rgb(0, 125, 0)'], ['Squirrel', 'rgb(75, 100, 0)'], ['Bear', 'rgb(125, 100, 0)'], ['Tiger', 'rgb(0, 0, 150)'], ['Leopard', 'rgb(0, 0, 200)'], ['Zebra', 'rgb(0, 0, 250)'], ['Wolf', 'rgb(0, 100, 150)'], ['Owl', 'rgb(0, 100, 100)'], ['Gull', 'rgb(100, 0, 100)'], ['Squid', 'rgb(150, 0, 150)']];
|
|
29
|
-
const randomEntry = entries[Math.floor(Math.random() * entries.length)];
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The React context that holds the shared {@link CollaborationContextType} for
|
|
33
|
-
* collaborative editors. Provide it with {@link LexicalCollaboration} and read
|
|
34
|
-
* it with {@link useCollaborationContext}.
|
|
35
|
-
*/
|
|
36
|
-
const CollaborationContext = /*#__PURE__*/react.createContext(null);
|
|
37
|
-
function newContext() {
|
|
38
|
-
return {
|
|
39
|
-
color: randomEntry[1],
|
|
40
|
-
isCollabActive: false,
|
|
41
|
-
name: randomEntry[0],
|
|
42
|
-
yjsDocMap: new Map()
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// This is here to help the transition post-#7818, however should be removed in a future release as
|
|
47
|
-
// a shared context across editors is likely to lead to bugs.
|
|
48
|
-
const UNSAFE_GLOBAL_CONTEXT = newContext();
|
|
49
23
|
|
|
50
24
|
/**
|
|
51
25
|
* A provider component that creates a fresh {@link CollaborationContextType}
|
|
@@ -58,37 +32,13 @@ const UNSAFE_GLOBAL_CONTEXT = newContext();
|
|
|
58
32
|
function LexicalCollaboration({
|
|
59
33
|
children
|
|
60
34
|
}) {
|
|
61
|
-
const collabContext = react.useMemo(() => newContext(), []);
|
|
62
|
-
return /*#__PURE__*/jsxRuntime.jsx(CollaborationContext.Provider, {
|
|
35
|
+
const collabContext = react.useMemo(() => LexicalCollaborationContextUtils.newContext(), []);
|
|
36
|
+
return /*#__PURE__*/jsxRuntime.jsx(LexicalCollaborationContextUtils.CollaborationContext.Provider, {
|
|
63
37
|
value: collabContext,
|
|
64
38
|
children: children
|
|
65
39
|
});
|
|
66
40
|
}
|
|
67
41
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* {@link LexicalCollaboration} provider. Optionally pass `username` and `color`
|
|
71
|
-
* to set the local user's display name and cursor color.
|
|
72
|
-
*
|
|
73
|
-
* @returns The active collaboration context.
|
|
74
|
-
*/
|
|
75
|
-
function useCollaborationContext(username, color) {
|
|
76
|
-
let collabContext = react.useContext(CollaborationContext);
|
|
77
|
-
if (!(collabContext != null)) {
|
|
78
|
-
formatDevErrorMessage(`useCollaborationContext: no context provider found`);
|
|
79
|
-
}
|
|
80
|
-
collabContext = collabContext ?? UNSAFE_GLOBAL_CONTEXT;
|
|
81
|
-
if (username != null) {
|
|
82
|
-
// eslint-disable-next-line react-hooks/immutability
|
|
83
|
-
collabContext.name = username;
|
|
84
|
-
}
|
|
85
|
-
if (color != null) {
|
|
86
|
-
// eslint-disable-next-line react-hooks/immutability
|
|
87
|
-
collabContext.color = color;
|
|
88
|
-
}
|
|
89
|
-
return collabContext;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
exports.CollaborationContext = CollaborationContext;
|
|
42
|
+
exports.CollaborationContext = LexicalCollaborationContextUtils.CollaborationContext;
|
|
43
|
+
exports.useCollaborationContext = LexicalCollaborationContextUtils.useCollaborationContext;
|
|
93
44
|
exports.LexicalCollaboration = LexicalCollaboration;
|
|
94
|
-
exports.useCollaborationContext = useCollaborationContext;
|