Skip to content

Commit

Permalink
Move rich/plain/dragon logic to separate packages (facebook#1555)
Browse files Browse the repository at this point in the history
* Move rich/plain/dragon logic to seperate pacakges

* Clean up entity logic
  • Loading branch information
trueadm authored and acywatson committed Apr 9, 2022
1 parent dbae9f8 commit 89ae504
Show file tree
Hide file tree
Showing 36 changed files with 1,296 additions and 969 deletions.
5 changes: 3 additions & 2 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ exact_by_default=true

module.name_mapper='^lexical$' -> '<PROJECT_ROOT>/packages/lexical/flow/Lexical.js.flow'

module.name_mapper='^lexical/HeadingNode' -> '<PROJECT_ROOT>/packages/lexical/flow/LexicalHeadingNode.js.flow'
module.name_mapper='^lexical/QuoteNode' -> '<PROJECT_ROOT>/packages/lexical/flow/LexicalQuoteNode.js.flow'
module.name_mapper='^lexical/LinkNode' -> '<PROJECT_ROOT>/packages/lexical/flow/LexicalLinkNode.js.flow'
module.name_mapper='^lexical/AutoLinkNode' -> '<PROJECT_ROOT>/packages/lexical/flow/LexicalAutoLinkNode.js.flow'
module.name_mapper='^lexical/OverflowNode' -> '<PROJECT_ROOT>/packages/lexical/flow/LexicalOverflowNode.js.flow'
Expand All @@ -34,6 +32,9 @@ module.name_mapper='^@lexical/text' -> '<PROJECT_ROOT>/packages/lexical-text/src
module.name_mapper='^@lexical/offset' -> '<PROJECT_ROOT>/packages/lexical-offset/src/index.js'
module.name_mapper='^@lexical/utils' -> '<PROJECT_ROOT>/packages/lexical-utils/src/index.js'
module.name_mapper='^@lexical/code' -> '<PROJECT_ROOT>/packages/lexical-code/src/index.js'
module.name_mapper='^@lexical/plain-text' -> '<PROJECT_ROOT>/packages/lexical-plain-text/src/index.js'
module.name_mapper='^@lexical/rich-text' -> '<PROJECT_ROOT>/packages/lexical-rich-text/src/index.js'
module.name_mapper='^@lexical/dragon' -> '<PROJECT_ROOT>/packages/lexical-dragon/src/index.js'

module.name_mapper='^@lexical/react/DEPRECATED_useLexicalEditor' -> '<PROJECT_ROOT>/packages/lexical-react/src/DEPRECATED_useLexicalEditor.js'
module.name_mapper='^@lexical/react/DEPRECATED_useLexicalRichText' -> '<PROJECT_ROOT>/packages/lexical-react/src/DEPRECATED_useLexicalRichText.js'
Expand Down
11 changes: 5 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ module.exports = {
'^@lexical/clipboard$':
'<rootDir>/packages/lexical-clipboard/src/index.js',
'^@lexical/code$': '<rootDir>/packages/lexical-code/src/index.js',
'^@lexical/dragon$': '<rootDir>/packages/lexical-dragon/src/index.js',
'^@lexical/file$': '<rootDir>/packages/lexical-file/src/index.js',
'^@lexical/hashtag$': '<rootDir>/packages/lexical-hashtag/src/index.js',
'^@lexical/list$': '<rootDir>/packages/lexical-list/src/index.js',
'^@lexical/offset$': '<rootDir>/packages/lexical-offset/src/index.js',
'^@lexical/plain-text$':
'<rootDir>/packages/lexical-plain-text/src/index.js',
'^@lexical/react/DEPRECATED_useLexicalRichText$':
'<rootDir>/packages/lexical-react/src/DEPRECATED_useLexicalRichText.js',
'^@lexical/react/LexicalAutoLinkPlugin$':
Expand Down Expand Up @@ -56,6 +59,8 @@ module.exports = {
'<rootDir>/packages/lexical-react/src/useLexicalEditor.js',
'^@lexical/react/withSubscriptions$':
'<rootDir>/packages/lexical-react/src/withSubscriptions.js',
'^@lexical/rich-text$':
'<rootDir>/packages/lexical-rich-text/src/index.js',
'^@lexical/selection$':
'<rootDir>/packages/lexical-selection/src/index.js',
'^@lexical/table$': '<rootDir>/packages/lexical-table/src/index.js',
Expand All @@ -65,18 +70,12 @@ module.exports = {
'^lexical$': '<rootDir>/packages/lexical/src/index.js',
'^lexical/AutoLinkNode$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalAutoLinkNode.js',
'^lexical/CodeHighlightNode$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalCodeHighlightNode.js',
'^lexical/ExtendedNodes$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalExtendedNodes.js',
'^lexical/HeadingNode$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalHeadingNode.js',
'^lexical/LinkNode$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalLinkNode.js',
'^lexical/OverflowNode$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalOverflowNode.js',
'^lexical/QuoteNode$':
'<rootDir>/packages/lexical/src/nodes/extended/LexicalQuoteNode.js',
'^shared/canUseDOM$': '<rootDir>/packages/shared/src/canUseDOM.js',
'^shared/environment$': '<rootDir>/packages/shared/src/environment.js',
'^shared/getDOMSelection$':
Expand Down
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
5 changes: 5 additions & 0 deletions packages/lexical-dragon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `@lexical/dragon`

This package contains compatability with Dragon NaturallySpeaking accessibility tools.

More documentation coming soon.
26 changes: 26 additions & 0 deletions packages/lexical-dragon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@lexical/dragon",
"author": {
"name": "Dominic Gannaway",
"email": "dg@domgan.com"
},
"description": "This package contains compatability with Dragon NaturallySpeaking accessibility tools.",
"keywords": [
"lexical",
"editor",
"rich-text",
"dragon",
"accessibility"
],
"license": "MIT",
"version": "0.1.16",
"main": "LexicalDragon.js",
"peerDependencies": {
"lexical": "0.1.16"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-dragon"
}
}
108 changes: 108 additions & 0 deletions packages/lexical-dragon/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
*/

import type {LexicalEditor} from 'lexical';

import {$getSelection, $isRangeSelection, $isTextNode} from 'lexical';

export function registerDragonSupport(editor: LexicalEditor): () => void {
const handler = (event) => {
const rootElement = editor.getRootElement();
if (document.activeElement !== rootElement) {
return;
}
const data = event.data;
if (typeof data === 'string') {
let parsedData;
try {
parsedData = JSON.parse(data);
} catch (e) {
return;
}
if (
parsedData &&
parsedData.protocol === 'nuanria_messaging' &&
parsedData.type === 'request'
) {
const payload = parsedData.payload;
if (payload && payload.functionId === 'makeChanges') {
const args = payload.args;
if (args) {
const [
elementStart,
elementLength,
text,
selStart,
selLength,
formatCommand,
] = args;
// TODO: we should probably handle formatCommand somehow?
// eslint-disable-next-line no-unused-expressions
formatCommand;
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
const anchor = selection.anchor;
let anchorNode = anchor.getNode();
let setSelStart = 0;
let setSelEnd = 0;
if ($isTextNode(anchorNode)) {
// set initial selection
if (elementStart >= 0 && elementLength >= 0) {
setSelStart = elementStart;
setSelEnd = elementStart + elementLength;
// If the offset is more than the end, make it the end
selection.setTextNodeRange(
anchorNode,
setSelStart,
anchorNode,
setSelEnd,
);
}
}
if (setSelStart !== setSelEnd || text !== '') {
selection.insertRawText(text);
anchorNode = anchor.getNode();
}
if ($isTextNode(anchorNode)) {
// set final selection
setSelStart = selStart;
setSelEnd = selStart + selLength;
const anchorNodeTextLength = anchorNode.getTextContentSize();
// If the offset is more than the end, make it the end
setSelStart =
setSelStart > anchorNodeTextLength
? anchorNodeTextLength
: setSelStart;
setSelEnd =
setSelEnd > anchorNodeTextLength
? anchorNodeTextLength
: setSelEnd;
selection.setTextNodeRange(
anchorNode,
setSelStart,
anchorNode,
setSelEnd,
);
}
// block the chrome extension from handling this event
event.stopImmediatePropagation();
}
});
}
}
}
}
};
window.addEventListener('message', handler, true);

return () => {
window.removeEventListener('message', handler, true);
};
}
12 changes: 12 additions & 0 deletions packages/lexical-plain-text/LexicalPlainText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

'use strict';

module.exports = require('./dist/LexicalPlainText.js');
3 changes: 3 additions & 0 deletions packages/lexical-plain-text/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@lexical/plain-text`

This package contains plain text helpers for Lexical.
26 changes: 26 additions & 0 deletions packages/lexical-plain-text/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@lexical/plain-text",
"author": {
"name": "Dominic Gannaway",
"email": "dg@domgan.com"
},
"description": "This package contains plain text helpers for Lexical.",
"keywords": [
"lexical",
"editor",
"plain-text"
],
"license": "MIT",
"version": "0.1.16",
"main": "LexicalPlainText.js",
"peerDependencies": {
"lexical": "0.1.16",
"@lexical/selection": "0.1.16",
"@lexical/clipboard": "0.1.16"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-plain-text"
}
}
Loading

0 comments on commit 89ae504

Please sign in to comment.