@@ -24,7 +24,7 @@ import type { LinkPayload } from '../types.js'
24
24
import { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'
25
25
import { getSelectedNode } from '../../../../../lexical/utils/getSelectedNode.js'
26
26
import { setFloatingElemPositionForLinkEditor } from '../../../../../lexical/utils/setFloatingElemPositionForLinkEditor.js'
27
- import { LinkDrawer } from '../../../drawer/index .js'
27
+ import { FieldsDrawer } from '../../../../../utilities/fieldsDrawer/Drawer .js'
28
28
import { $isAutoLinkNode } from '../../../nodes/AutoLinkNode.js'
29
29
import { $createLinkNode , $isLinkNode , TOGGLE_LINK_COMMAND } from '../../../nodes/LinkNode.js'
30
30
import { TOGGLE_LINK_WITH_MODAL_COMMAND } from './commands.js'
@@ -44,7 +44,7 @@ export function LinkEditor({ anchorElem }: { anchorElem: HTMLElement }): React.R
44
44
45
45
const [ stateData , setStateData ] = useState < { } | ( LinkFields & { id ?: string ; text : string } ) > ( { } )
46
46
47
- const { closeModal, isModalOpen , toggleModal } = useModal ( )
47
+ const { closeModal, toggleModal } = useModal ( )
48
48
const editDepth = useEditDepth ( )
49
49
const [ isLink , setIsLink ] = useState ( false )
50
50
const [ selectedNodes , setSelectedNodes ] = useState < LexicalNode [ ] > ( [ ] )
@@ -312,50 +312,52 @@ export function LinkEditor({ anchorElem }: { anchorElem: HTMLElement }): React.R
312
312
) }
313
313
</ div >
314
314
</ div >
315
- { isModalOpen ( drawerSlug ) && (
316
- < LinkDrawer
317
- drawerSlug = { drawerSlug }
318
- handleModalSubmit = { ( fields : FormState , data : Data ) => {
319
- closeModal ( drawerSlug )
320
-
321
- const newLinkPayload = data as LinkFields & { text : string }
322
-
323
- const bareLinkFields : LinkFields = {
324
- ...newLinkPayload ,
325
- }
326
- delete bareLinkFields . text
327
-
328
- // See: https://github.com/facebook/lexical/pull/5536. This updates autolink nodes to link nodes whenever a change was made (which is good!).
329
- editor . update ( ( ) => {
330
- const selection = $getSelection ( )
331
- let linkParent = null
332
- if ( $isRangeSelection ( selection ) ) {
333
- linkParent = getSelectedNode ( selection ) . getParent ( )
334
- } else {
335
- if ( selectedNodes . length ) {
336
- linkParent = selectedNodes [ 0 ] . getParent ( )
337
- }
315
+ < FieldsDrawer
316
+ className = "lexical-link-edit-drawer"
317
+ data = { stateData }
318
+ drawerSlug = { drawerSlug }
319
+ drawerTitle = { t ( 'fields:editLink' ) }
320
+ featureKey = "link"
321
+ handleDrawerSubmit = { ( fields : FormState , data : Data ) => {
322
+ closeModal ( drawerSlug )
323
+
324
+ const newLinkPayload = data as LinkFields & { text : string }
325
+
326
+ const bareLinkFields : LinkFields = {
327
+ ...newLinkPayload ,
328
+ }
329
+ delete bareLinkFields . text
330
+
331
+ // See: https://github.com/facebook/lexical/pull/5536. This updates autolink nodes to link nodes whenever a change was made (which is good!).
332
+ editor . update ( ( ) => {
333
+ const selection = $getSelection ( )
334
+ let linkParent = null
335
+ if ( $isRangeSelection ( selection ) ) {
336
+ linkParent = getSelectedNode ( selection ) . getParent ( )
337
+ } else {
338
+ if ( selectedNodes . length ) {
339
+ linkParent = selectedNodes [ 0 ] . getParent ( )
338
340
}
341
+ }
339
342
340
- if ( linkParent && $isAutoLinkNode ( linkParent ) ) {
341
- const linkNode = $createLinkNode ( {
342
- fields : bareLinkFields ,
343
- } )
344
- linkParent . replace ( linkNode , true )
345
- }
346
- } )
347
-
348
- // Needs to happen AFTER a potential auto link => link node conversion, as otherwise, the updated text to display may be lost due to
349
- // it being applied to the auto link node instead of the link node.
350
- editor . dispatchCommand ( TOGGLE_LINK_COMMAND , {
351
- fields : bareLinkFields ,
352
- selectedNodes,
353
- text : newLinkPayload . text ,
354
- } )
355
- } }
356
- stateData = { stateData }
357
- />
358
- ) }
343
+ if ( linkParent && $isAutoLinkNode ( linkParent ) ) {
344
+ const linkNode = $createLinkNode ( {
345
+ fields : bareLinkFields ,
346
+ } )
347
+ linkParent . replace ( linkNode , true )
348
+ }
349
+ } )
350
+
351
+ // Needs to happen AFTER a potential auto link => link node conversion, as otherwise, the updated text to display may be lost due to
352
+ // it being applied to the auto link node instead of the link node.
353
+ editor . dispatchCommand ( TOGGLE_LINK_COMMAND , {
354
+ fields : bareLinkFields ,
355
+ selectedNodes,
356
+ text : newLinkPayload . text ,
357
+ } )
358
+ } }
359
+ schemaPathSuffix = "fields"
360
+ />
359
361
</ React . Fragment >
360
362
)
361
363
}
0 commit comments