mirror of
https://github.com/facebook/lexical.git
synced 2025-08-06 16:39:33 +08:00
Add @lexical/overflow @lexical/link (#1556)
* Add @lexical/overflow @lexical/link * Fix tests
This commit is contained in:

committed by
acywatson

parent
89ae5046f6
commit
146c95a540
12
packages/lexical-overflow/LexicalOverflow.js
Normal file
12
packages/lexical-overflow/LexicalOverflow.js
Normal 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');
|
3
packages/lexical-overflow/README.md
Normal file
3
packages/lexical-overflow/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# `@lexical/overflow`
|
||||
|
||||
This package contains selection overflow helpers and nodes for Lexical.
|
25
packages/lexical-overflow/package.json
Normal file
25
packages/lexical-overflow/package.json
Normal 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"
|
||||
}
|
||||
}
|
57
packages/lexical-overflow/src/index.js
Normal file
57
packages/lexical-overflow/src/index.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user