Add @lexical/overflow @lexical/link (#1556)

* Add @lexical/overflow @lexical/link

* Fix tests
This commit is contained in:
Dominic Gannaway
2022-03-25 15:56:06 +00:00
committed by acywatson
parent 89ae5046f6
commit 146c95a540
72 changed files with 392 additions and 639 deletions

View File

@ -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/LexicalOverflow.js');

View File

@ -0,0 +1,3 @@
# `@lexical/overflow`
This package contains selection overflow helpers and nodes for Lexical.

View File

@ -0,0 +1,25 @@
{
"name": "@lexical/overflow",
"author": {
"name": "Dominic Gannaway",
"email": "dg@domgan.com"
},
"description": "This package contains selection overflow helpers and nodes for Lexical.",
"keywords": [
"lexical",
"editor",
"rich-text",
"overflow"
],
"license": "MIT",
"version": "0.1.16",
"main": "LexicalOverflow.js",
"peerDependencies": {
"lexical": "0.1.16"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-overflow"
}
}

View File

@ -0,0 +1,57 @@
/**
* 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 {EditorConfig, LexicalNode, NodeKey, RangeSelection} from 'lexical';
import {ElementNode} from 'lexical';
export class OverflowNode extends ElementNode {
static getType(): string {
return 'overflow';
}
static clone(node: OverflowNode): OverflowNode {
return new OverflowNode(node.__key);
}
constructor(key?: NodeKey): void {
super(key);
this.__type = 'overflow';
}
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement {
const div = document.createElement('span');
const className = config.theme.characterLimit;
if (typeof className === 'string') {
div.className = className;
}
return div;
}
updateDOM(prevNode: OverflowNode, dom: HTMLElement): boolean {
return false;
}
insertNewAfter(selection: RangeSelection): null | LexicalNode {
const parent = this.getParentOrThrow();
return parent.insertNewAfter(selection);
}
excludeFromCopy(): boolean {
return true;
}
}
export function $createOverflowNode(): OverflowNode {
return new OverflowNode();
}
export function $isOverflowNode(node: ?LexicalNode): boolean %checks {
return node instanceof OverflowNode;
}