-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[lexical] Feature: Add version identifier to LexicalEditor constructor #6488
Changes from all commits
665bbed
2ecea4b
1264e60
501ced1
03725ae
1a90321
f3470da
f00946a
4071b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ handle external UI state and UI features relating to specific types of node. | |
If any existing nodes are in the DOM, and skipInitialization is not true, the listener | ||
will be called immediately with an updateTag of 'registerMutationListener' where all | ||
nodes have the 'created' NodeMutation. This can be controlled with the skipInitialization option | ||
(default is currently true for backwards compatibility in 0.16.x but will change to false in 0.17.0). | ||
(default is currently true for backwards compatibility in 0.17.x but will change to false in 0.18.0). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the deprecation policy here since 0.17.0 was the first release with the changes to |
||
|
||
```js | ||
const removeMutationListener = editor.registerMutationListener( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,24 @@ | |
* | ||
*/ | ||
|
||
import type { | ||
import type {SerializedEditorState} from './LexicalEditorState'; | ||
import type {LexicalNode, SerializedLexicalNode} from './LexicalNode'; | ||
|
||
import invariant from 'shared/invariant'; | ||
|
||
import {$isElementNode, $isTextNode, SELECTION_CHANGE_COMMAND} from '.'; | ||
import {FULL_RECONCILE, NO_DIRTY_NODES} from './LexicalConstants'; | ||
import { | ||
CommandPayloadType, | ||
EditorUpdateOptions, | ||
LexicalCommand, | ||
LexicalEditor, | ||
Listener, | ||
MutatedNodes, | ||
RegisteredNodes, | ||
resetEditor, | ||
Transform, | ||
} from './LexicalEditor'; | ||
import type {SerializedEditorState} from './LexicalEditorState'; | ||
import type {LexicalNode, SerializedLexicalNode} from './LexicalNode'; | ||
|
||
import invariant from 'shared/invariant'; | ||
|
||
import {$isElementNode, $isTextNode, SELECTION_CHANGE_COMMAND} from '.'; | ||
import {FULL_RECONCILE, NO_DIRTY_NODES} from './LexicalConstants'; | ||
import {resetEditor} from './LexicalEditor'; | ||
import { | ||
cloneEditorState, | ||
createEmptyEditorState, | ||
|
@@ -47,9 +47,11 @@ import { | |
import { | ||
$getCompositionKey, | ||
getDOMSelection, | ||
getEditorPropertyFromDOMNode, | ||
getEditorStateTextContent, | ||
getEditorsToPropagate, | ||
getRegisteredNodeOrThrow, | ||
isLexicalEditor, | ||
removeDOMBlockCursorElement, | ||
scheduleMicroTask, | ||
updateDOMBlockCursorElement, | ||
|
@@ -96,7 +98,8 @@ export function getActiveEditorState(): EditorState { | |
'Unable to find an active editor state. ' + | ||
'State helpers or node methods can only be used ' + | ||
'synchronously during the callback of ' + | ||
'editor.update(), editor.read(), or editorState.read().', | ||
'editor.update(), editor.read(), or editorState.read().%s', | ||
collectBuildInformation(), | ||
); | ||
} | ||
|
||
|
@@ -110,13 +113,46 @@ export function getActiveEditor(): LexicalEditor { | |
'Unable to find an active editor. ' + | ||
'This method can only be used ' + | ||
'synchronously during the callback of ' + | ||
'editor.update() or editor.read().', | ||
'editor.update() or editor.read().%s', | ||
collectBuildInformation(), | ||
); | ||
} | ||
|
||
return activeEditor; | ||
} | ||
|
||
function collectBuildInformation(): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @etrepum nitpicking but such detailed error is something I'd consider gating under the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the amount of bug reports for this one issue I was motivated to include it, I think a lot of people end up with the prod build for various reasons. You could put it behind a flag so it doesn't get included in www? Once dev tools gets a release with this functionality we could stub the implementation out with a string that says to install the dev tools to diagnose. We are still talking about <1kb before compression. |
||
let compatibleEditors = 0; | ||
const incompatibleEditors = new Set<string>(); | ||
const thisVersion = LexicalEditor.version; | ||
if (typeof window !== 'undefined') { | ||
for (const node of document.querySelectorAll('[contenteditable]')) { | ||
const editor = getEditorPropertyFromDOMNode(node); | ||
if (isLexicalEditor(editor)) { | ||
compatibleEditors++; | ||
} else if (editor) { | ||
let version = String( | ||
( | ||
editor.constructor as typeof editor['constructor'] & | ||
Record<string, unknown> | ||
).version || '<0.17.1', | ||
); | ||
if (version === thisVersion) { | ||
version += | ||
' (separately built, likely a bundler configuration issue)'; | ||
} | ||
incompatibleEditors.add(version); | ||
} | ||
} | ||
} | ||
let output = ` Detected on the page: ${compatibleEditors} compatible editor(s) with version ${thisVersion}`; | ||
if (incompatibleEditors.size) { | ||
output += ` and incompatible editors with versions ${Array.from( | ||
incompatibleEditors, | ||
).join(', ')}`; | ||
} | ||
return output; | ||
} | ||
|
||
export function internalGetActiveEditor(): LexicalEditor | null { | ||
return activeEditor; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
{ | ||
"name": "lexical-esm-astro-react", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"version": "0.17.0", | ||
"scripts": { | ||
"dev": "astro dev", | ||
"start": "astro dev", | ||
"build": "astro check && astro build", | ||
"preview": "astro preview", | ||
"astro": "astro", | ||
"astro": "astro", | ||
"test": "playwright test" | ||
}, | ||
"dependencies": { | ||
"@astrojs/check": "^0.5.9", | ||
"@astrojs/react": "^3.1.0", | ||
"@lexical/react": "^0.14.3", | ||
"@lexical/utils": "^0.14.3", | ||
"@lexical/react": "0.17.0", | ||
"@lexical/utils": "0.17.0", | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"astro": "^4.5.4", | ||
"lexical": "^0.14.3", | ||
"lexical": "0.17.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^5.4.2" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.43.1" | ||
} | ||
}, | ||
"sideEffects": false | ||
} |
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.
The playground is never built with an npm release of lexical since it directly includes all of the source