-
-
Notifications
You must be signed in to change notification settings - Fork 726
feat: simplify links by inlining it to BlockNote #2623
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c416d9c
refactor: remove dep on @tiptap/extension-link and linkify
nperez0111 3393322
refactor: simplify inlined Link extension by removing unused tiptap o…
nperez0111 50210b7
refactor: simplify link API — move operations to StyleManager, rewrit…
nperez0111 421cff5
fix: resolve lint errors in Link extension files
nperez0111 42dfa87
fix: address CodeRabbit review feedback in linkDetector
nperez0111 35add49
chore: relax dependency version ranges and add workspaces config
nperez0111 606c872
fix(ci): resolve duplicate React install and npm overrides conflict
nperez0111 0ca9a3e
Fixed lock file
matthewlipski da46433
fix: Non-editable link clicks opening duplicate tabs (#2667)
matthewlipski f18f037
feat: Link customization options (BLO-913) (#2666)
matthewlipski c9c3f5d
revert: restore nodeToBlock/blockToNode to main
nperez0111 bcb526b
fix: preserve cursor position in editLink when text is unchanged
nperez0111 77cb1ef
chore: clear request headers in xl-ai MSW snapshots
nperez0111 b6756ab
Implemented PR feedback
matthewlipski 295a0de
feat: add isValidLink option and auto-generate TLD list from IANA
nperez0111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Regenerate src/extensions/tiptap-extensions/Link/helpers/tlds.ts from IANA's | ||
| * authoritative TLD list. | ||
| * | ||
| * Run with: pnpm --filter @blocknote/core update-tlds | ||
| * | ||
| * Encoding format ported from linkifyjs (MIT, https://github.com/nfrasser/linkifyjs): | ||
| * a sorted TLD list is built into a trie, then serialized as an ASCII string | ||
| * where letters descend the trie and digit runs mean "emit a word and pop N | ||
| * levels back up." Shared TLD prefixes (e.g. construction/consulting/ | ||
| * contractors) collapse, producing a payload smaller than a flat list. | ||
| * | ||
| * IDN punycode entries (XN--...) are skipped: the schemeless URL regex in | ||
| * linkDetector.ts requires ASCII-only TLDs, so unicode TLDs would never reach | ||
| * the validation step. | ||
| */ | ||
|
|
||
| import { writeFileSync } from "node:fs"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { dirname, resolve } from "node:path"; | ||
|
|
||
| const TLDS_URL = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const OUT_PATH = resolve( | ||
| __dirname, | ||
| "../src/extensions/tiptap-extensions/Link/helpers/tlds.ts", | ||
| ); | ||
|
|
||
| function createTrie(words) { | ||
| const root = {}; | ||
| for (const word of words) { | ||
| let current = root; | ||
| for (const letter of word) { | ||
| if (!(letter in current)) { | ||
| current[letter] = {}; | ||
| } | ||
| current = current[letter]; | ||
| } | ||
| current.isWord = true; | ||
| } | ||
| return root; | ||
| } | ||
|
|
||
| function encodeTrieHelper(trie) { | ||
| const output = []; | ||
| for (const k in trie) { | ||
| if (k === "isWord") { | ||
| output.push(0); | ||
| continue; | ||
| } | ||
| output.push(k); | ||
| output.push(...encodeTrieHelper(trie[k])); | ||
| if (typeof output[output.length - 1] === "number") { | ||
| output[output.length - 1] += 1; | ||
| } else { | ||
| output.push(1); | ||
| } | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| function encodeTlds(tlds) { | ||
| return encodeTrieHelper(createTrie(tlds)).join(""); | ||
| } | ||
|
|
||
| function decodeTlds(encoded) { | ||
| const words = []; | ||
| const stack = []; | ||
| let i = 0; | ||
| const digits = "0123456789"; | ||
| while (i < encoded.length) { | ||
| let popDigitCount = 0; | ||
| while (digits.indexOf(encoded[i + popDigitCount]) >= 0) { | ||
| popDigitCount++; | ||
| } | ||
| if (popDigitCount > 0) { | ||
| words.push(stack.join("")); | ||
| let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); | ||
| while (popCount-- > 0) { | ||
| stack.pop(); | ||
| } | ||
| i += popDigitCount; | ||
| } else { | ||
| stack.push(encoded[i]); | ||
| i++; | ||
| } | ||
| } | ||
| return words; | ||
| } | ||
|
|
||
| async function main() { | ||
| console.log(`Fetching ${TLDS_URL}...`); | ||
| const response = await fetch(TLDS_URL); | ||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch IANA TLDs: ${response.status}`); | ||
| } | ||
| const body = await response.text(); | ||
|
|
||
| const tlds = body | ||
| .split("\n") | ||
| .map((line) => line.trim()) | ||
| .filter((line) => line && !line.startsWith("#") && !/^XN--/i.test(line)) | ||
| .map((line) => line.toLowerCase()) | ||
| .sort(); | ||
|
|
||
| console.log(`Encoding ${tlds.length} TLDs...`); | ||
| const encoded = encodeTlds(tlds); | ||
|
|
||
| console.log("Round-trip asserting..."); | ||
| const decoded = decodeTlds(encoded); | ||
| if (JSON.stringify(decoded) !== JSON.stringify(tlds)) { | ||
| throw new Error("Encode/decode round-trip mismatch"); | ||
| } | ||
|
|
||
| const fileContents = `// THIS FILE IS AUTO-GENERATED. DO NOT EDIT DIRECTLY. | ||
| // Source: ${TLDS_URL} | ||
| // Regenerate with: pnpm --filter @blocknote/core update-tlds | ||
| // Encoding format ported from linkifyjs (MIT) — trie collapsed into ASCII. | ||
|
|
||
| export const ENCODED_TLDS = | ||
| "${encoded}"; | ||
| `; | ||
|
|
||
| writeFileSync(OUT_PATH, fileContents); | ||
| console.log( | ||
| `Wrote ${OUT_PATH} (${encoded.length} chars, ${tlds.length} TLDs)`, | ||
| ); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also make sure this is reflected correctly in blocknote initialization options?
Looking at it, that part is actually currently broken in docs: https://www.blocknotejs.org/docs/reference/editor/overview#options
(maybe check for other AutoTypeTables that are broken as well)