2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
13 } from './nodes/LexicalTextNode';
20 } from 'lexical/shared/environment';
23 export const DOM_ELEMENT_TYPE = 1;
24 export const DOM_TEXT_TYPE = 3;
27 export const NO_DIRTY_NODES = 0;
28 export const HAS_DIRTY_NODES = 1;
29 export const FULL_RECONCILE = 2;
32 export const IS_NORMAL = 0;
33 export const IS_TOKEN = 1;
34 export const IS_SEGMENTED = 2;
37 // Text node formatting
38 export const IS_BOLD = 1;
39 export const IS_ITALIC = 1 << 1;
40 export const IS_STRIKETHROUGH = 1 << 2;
41 export const IS_UNDERLINE = 1 << 3;
42 export const IS_CODE = 1 << 4;
43 export const IS_SUBSCRIPT = 1 << 5;
44 export const IS_SUPERSCRIPT = 1 << 6;
45 export const IS_HIGHLIGHT = 1 << 7;
47 export const IS_ALL_FORMATTING =
58 export const IS_DIRECTIONLESS = 1;
59 export const IS_UNMERGEABLE = 1 << 1;
61 // Element node formatting
62 export const IS_ALIGN_LEFT = 1;
63 export const IS_ALIGN_CENTER = 2;
64 export const IS_ALIGN_RIGHT = 3;
65 export const IS_ALIGN_JUSTIFY = 4;
66 export const IS_ALIGN_START = 5;
67 export const IS_ALIGN_END = 6;
70 export const NON_BREAKING_SPACE = '\u00A0';
71 const ZERO_WIDTH_SPACE = '\u200b';
73 // For iOS/Safari we use a non breaking space, otherwise the cursor appears
74 // overlapping the composed text.
75 export const COMPOSITION_SUFFIX: string =
76 IS_SAFARI || IS_IOS || IS_APPLE_WEBKIT
79 export const DOUBLE_LINE_BREAK = '\n\n';
81 // For FF, we need to use a non-breaking space, or it gets composition
83 export const COMPOSITION_START_CHAR: string = IS_FIREFOX
86 const RTL = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
88 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
89 '\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
90 '\uFE00-\uFE6F\uFEFD-\uFFFF';
92 // eslint-disable-next-line no-misleading-character-class
93 export const RTL_REGEX = new RegExp('^[^' + LTR + ']*[' + RTL + ']');
94 // eslint-disable-next-line no-misleading-character-class
95 export const LTR_REGEX = new RegExp('^[^' + RTL + ']*[' + LTR + ']');
97 export const TEXT_TYPE_TO_FORMAT: Record<TextFormatType | string, number> = {
100 highlight: IS_HIGHLIGHT,
102 strikethrough: IS_STRIKETHROUGH,
103 subscript: IS_SUBSCRIPT,
104 superscript: IS_SUPERSCRIPT,
105 underline: IS_UNDERLINE,
108 export const DETAIL_TYPE_TO_DETAIL: Record<TextDetailType | string, number> = {
109 directionless: IS_DIRECTIONLESS,
110 unmergeable: IS_UNMERGEABLE,
113 export const TEXT_MODE_TO_TYPE: Record<TextModeType, 0 | 1 | 2> = {
115 segmented: IS_SEGMENTED,
119 export const TEXT_TYPE_TO_MODE: Record<number, TextModeType> = {
120 [IS_NORMAL]: 'normal',
121 [IS_SEGMENTED]: 'segmented',