Skip to content

Commit

Permalink
feat(editor-toolbar): create DictyLinkNode to extend LinkNode and add…
Browse files Browse the repository at this point in the history
… filename as download attribute

This change introduces a new node type, `DictyLinkNode`, which extends the existing `LinkNode` from `@lexical/link`. This new node allows specifying a `download` attribute, effectively setting a suggested filename when the linked resource is downloaded. The filename is extracted from the attributes during node construction, leveraging `fp-ts` for safe handling of nullable or undefined values. This enhancement provides more control over how links are handled, particularly for downloadable resources.
  • Loading branch information
ktun95 committed Mar 4, 2025
1 parent b686490 commit 887945a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/editor-toolbar/DictyLinkNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NodeKey } from "lexical"
import { LinkNode, LinkAttributes } from "@lexical/link"
import { pipe } from "fp-ts/function"
import {
fromNullable as OfromNullable,
flatMap as OflatMap,
match as Omatch,
} from "fp-ts/Option"

type DictyLinkAttributes = LinkAttributes & {
download?: null | string
}

class DictyLinkNode extends LinkNode {
__download: string

constructor(url: string, attributes?: DictyLinkAttributes, key?: NodeKey) {
super(url, attributes, key)
const filename = pipe(
attributes,
OfromNullable,
OflatMap(({ download }) => OfromNullable(download)),
Omatch(() => "", (f) => f)
)
this.__download = filename
}
}

export { DictyLinkNode }

0 comments on commit 887945a

Please sign in to comment.