Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Link node with target and rel #2687

Merged

Conversation

andrewchmr
Copy link
Contributor

@andrewchmr andrewchmr commented Jul 22, 2022

Issue: #2671

Support target and rel for LinkNode

Ideas for the future:

  • Add an option in the playground if link should be opened in the new tab

@facebook-github-bot
Copy link
Contributor

Hi @andrewchmr!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@vercel
Copy link

vercel bot commented Jul 22, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lexical ✅ Ready (Inspect) Visit Preview Jul 25, 2022 at 4:49PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview Jul 25, 2022 at 4:49PM (UTC)

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 22, 2022
@andrewchmr andrewchmr changed the title WIP feat: Link node with target and rel feat: Link node with target and rel Jul 22, 2022
@andrewchmr andrewchmr marked this pull request as ready for review July 22, 2022 15:59
return this.getLatest().__rel;
}

setRel(rel: string | undefined): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this to be something more explicit, like setRelationship?

@thegreatercurve
Copy link
Contributor

LGTM @andrewchmr! It just seems to be breaking a few tests to do with the Autolink node.

@thegreatercurve
Copy link
Contributor

@andrewchmr This is weird, I can't actually seeing any tests failing in the CI, especially the unit tests. Can you try rebasing onto main and then force pushing an update to trigger another CI run? It might be some weird caching issue with Github Actions

@thegreatercurve
Copy link
Contributor

The failing unit tests are due to a the coverage reports returning errors. Given that we don't use the coverage reports, we can probably just delete them: #2699

Copy link
Contributor

@thegreatercurve thegreatercurve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @andrewchmr! Thanks for making these backwards compatible and adding in the tests.

@thegreatercurve
Copy link
Contributor

Closes #2671

@andrewchmr
Copy link
Contributor Author

Last commit handles updateDOM when target or relationship is undefined

If target or relationship is undefined then we remove this attribute otherwise, we set it

@thegreatercurve thegreatercurve merged commit f4b7819 into facebook:main Jul 25, 2022
karam-qaoud pushed a commit to karam-qaoud/lexical that referenced this pull request Jul 26, 2022
karam-qaoud added a commit that referenced this pull request Jul 26, 2022
* Fixed getStyleObjectFromRawCSS function to work for unformatted css strings

* Testing that  handles unformatted css text

* Testing that $getStyleObjectFromRawCss handles unformatted css

* Added TableOfContents

* Renamed TableOfContetnsPlugin file name and added flow file

* Added TableOfContentsPlugin to config files and added styling

* Fixed types

* Added TableOfContentsList as a seperate module

* Fixed type of tag from string to HeadingTagType

* Table of contents updates as user scrolls

* Wrapped plugin in a feature

* Deleted package-lock.json

* Fixed conditioanl rendering syntax

* Removed extra parameter

* package-lock

* fix imports

* Update packages/lexical-playground/src/plugins/TableOfContentsPlugin.tsx

Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>

* Added sticky styling and handled text overflow

* Table of contents updates automtaically on scroll without observing all heading nodes

* Update table correctly  when headings are not visible but exist either up or down

* Fix failing E2E

* Changed isTableOfContentes to showTableOfContents in settings

* Added useEffect to fix memory leak

* Hoisted functions that don't use props

* Renamed isTableOfContets to showTableOfContents

* Changing selectedHeading by observing page top

* resolved lint error

* Refactored scroll up logic

* Added comments

* Added better css

* Changed place of toc div to fix failing test

* Fixed adjacent headings scrolling

* Fixed adjacent headings bug

* Renamed helper methods

* Fixed test

* Added dependency array to useEffect

* Added TableOfContents to dependency array

* Updated dependeny array in useEffect

* Created e2e test file for table of contents plugin

* Added scroll test

* E2E test: Adding heading to editor adds them to table-of-contents

* clean up

* Refactored getEditorElement

* Scrolling callback has better conditions

* Table of contents is now covering all edge cases and doesn't freeze webpage

* Solved page freezing

* Added one more assert statment to second test

* chore(lexical-playground): make directory clear (#2674)

* Conditionally utilize `startTransition` if it's present (#2676)

* Only utilize startTransition if it's available

* Add type annotation

* Run prettier

* fix(lexical-list): remove list breaks if selection in empty (#2672)

* fix(lexical-list): remove list breaks if selection in empty

* chore: add a comment

* chore: add test

* Separate `@lexical/code` into more atomic modules (#2673)

* separate code package into more atomic modules

* remove utils

* named exports

* Fixed typo (#2678)

* fix: path to icons (#2683)

* Fix VALID_TWITTER_URL to allow underscores. (#2690)

* fix(lexical-playground): LexicalTypeaheadMenuPlugin import (#2689)

Use the correct import path that available in NPM package

* Collapse and Expand DevTools Tree Nodes (#2679)

* fix(playground): fix rendering Exclidraw (#2694)

* Make includeHeaders a boolean (#2697)

Changed type for includeHeaders parameter from string to boolean to match the type of the parameter from the $createTableNodeWithDimensions function.

* Remove coverage reports (#2699)

* fix: check if options are empty (#2701)

* feat: Link node with target and rel (#2687)

* OnChangePlugin ignoreInitialChange -> ignoreHistoryMergeTagChange (#2706)

* OnChangePlugin ignoreInitialChange -> ignoreHistoryMergeTag

* .

* default to false because 0.4

Co-authored-by: Karam Qaoud <kqaoud@fb.com>
Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>
Co-authored-by: 子瞻 Luci <haru.lucinyan@gmail.com>
Co-authored-by: Jack Hanford <jackhanford@gmail.com>
Co-authored-by: John Flockton <thegreatercurve@users.noreply.github.com>
Co-authored-by: SalvadorLekan <66782276+SalvadorLekan@users.noreply.github.com>
Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com>
Co-authored-by: hiraoka <62982380+y-hiraoka@users.noreply.github.com>
Co-authored-by: Elvin Dzhavadov <elvin.d@outlook.com>
Co-authored-by: Will <will.gutierrez@gmail.com>
Co-authored-by: Bryan <ImSingee@users.noreply.github.com>
Co-authored-by: alinamusuroi <44519061+alinamusuroi@users.noreply.github.com>
Co-authored-by: Andriy Chemerynskiy <andrzej.chem@gmail.com>
@fameoflight
Copy link

Any ideas on how can I enable target="_blank" as default for any link

thegreatercurve added a commit that referenced this pull request Nov 25, 2022
* Fixed getStyleObjectFromRawCSS function to work for unformatted css strings

* Testing that  handles unformatted css text

* Testing that $getStyleObjectFromRawCss handles unformatted css

* Added TableOfContents

* Renamed TableOfContetnsPlugin file name and added flow file

* Added TableOfContentsPlugin to config files and added styling

* Fixed types

* Added TableOfContentsList as a seperate module

* Fixed type of tag from string to HeadingTagType

* Table of contents updates as user scrolls

* Wrapped plugin in a feature

* Deleted package-lock.json

* Fixed conditioanl rendering syntax

* Removed extra parameter

* package-lock

* fix imports

* Update packages/lexical-playground/src/plugins/TableOfContentsPlugin.tsx

Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>

* Added sticky styling and handled text overflow

* Table of contents updates automtaically on scroll without observing all heading nodes

* Update table correctly  when headings are not visible but exist either up or down

* Fix failing E2E

* Changed isTableOfContentes to showTableOfContents in settings

* Added useEffect to fix memory leak

* Hoisted functions that don't use props

* Renamed isTableOfContets to showTableOfContents

* Changing selectedHeading by observing page top

* resolved lint error

* Refactored scroll up logic

* Added comments

* Added better css

* Changed place of toc div to fix failing test

* Fixed adjacent headings scrolling

* Fixed adjacent headings bug

* Renamed helper methods

* Fixed test

* Added dependency array to useEffect

* Added TableOfContents to dependency array

* Updated dependeny array in useEffect

* Created e2e test file for table of contents plugin

* Added scroll test

* E2E test: Adding heading to editor adds them to table-of-contents

* clean up

* Refactored getEditorElement

* Scrolling callback has better conditions

* Table of contents is now covering all edge cases and doesn't freeze webpage

* Solved page freezing

* Added one more assert statment to second test

* chore(lexical-playground): make directory clear (#2674)

* Conditionally utilize `startTransition` if it's present (#2676)

* Only utilize startTransition if it's available

* Add type annotation

* Run prettier

* fix(lexical-list): remove list breaks if selection in empty (#2672)

* fix(lexical-list): remove list breaks if selection in empty

* chore: add a comment

* chore: add test

* Separate `@lexical/code` into more atomic modules (#2673)

* separate code package into more atomic modules

* remove utils

* named exports

* Fixed typo (#2678)

* fix: path to icons (#2683)

* Fix VALID_TWITTER_URL to allow underscores. (#2690)

* fix(lexical-playground): LexicalTypeaheadMenuPlugin import (#2689)

Use the correct import path that available in NPM package

* Collapse and Expand DevTools Tree Nodes (#2679)

* fix(playground): fix rendering Exclidraw (#2694)

* Make includeHeaders a boolean (#2697)

Changed type for includeHeaders parameter from string to boolean to match the type of the parameter from the $createTableNodeWithDimensions function.

* Remove coverage reports (#2699)

* fix: check if options are empty (#2701)

* feat: Link node with target and rel (#2687)

* OnChangePlugin ignoreInitialChange -> ignoreHistoryMergeTagChange (#2706)

* OnChangePlugin ignoreInitialChange -> ignoreHistoryMergeTag

* .

* default to false because 0.4

Co-authored-by: Karam Qaoud <kqaoud@fb.com>
Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>
Co-authored-by: 子瞻 Luci <haru.lucinyan@gmail.com>
Co-authored-by: Jack Hanford <jackhanford@gmail.com>
Co-authored-by: John Flockton <thegreatercurve@users.noreply.github.com>
Co-authored-by: SalvadorLekan <66782276+SalvadorLekan@users.noreply.github.com>
Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com>
Co-authored-by: hiraoka <62982380+y-hiraoka@users.noreply.github.com>
Co-authored-by: Elvin Dzhavadov <elvin.d@outlook.com>
Co-authored-by: Will <will.gutierrez@gmail.com>
Co-authored-by: Bryan <ImSingee@users.noreply.github.com>
Co-authored-by: alinamusuroi <44519061+alinamusuroi@users.noreply.github.com>
Co-authored-by: Andriy Chemerynskiy <andrzej.chem@gmail.com>
@giokallis
Copy link

Is there anything new with @fameoflight's proposal ? I also don't understand how to use the target in LinkNode!

@tylerklose
Copy link

tylerklose commented Jul 24, 2023

Is there anything new with @fameoflight's proposal ? I also don't understand how to use the target in LinkNode!

I tried achieving this by using the following, but have had no luck:

  const URL_MATCHER =
    /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/

  const MATCHERS = [
    (text: string) => {
      const match = URL_MATCHER.exec(text)
      return (
        match && {
          index: match.index,
          length: match[0].length,
          text: match[0],
          url: match[0],
          attributes: { rel: "noopener", target: "_blank" }
        }
      )
    },
  ]
  
  ...
  
<AutoLinkPlugin matchers={MATCHERS} />

@djeriko
Copy link

djeriko commented Jan 26, 2024

Any ideas on how can I enable target="_blank" as default for any link

Try this when you pass nodes to config in LexicalComposer:

const LINK_NODES = [
  {
    replace: LinkNode,
    with: (node: LinkNode) => {
      return new LinkNode(node.__url, { target: '_blank' })
    }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants