@octanejs/lexical 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/LexicalAutoEmbedPlugin.tsrx +73 -61
- package/src/LexicalAutoFocusPlugin.tsrx +14 -11
- package/src/LexicalAutoLinkPlugin.tsrx +6 -5
- package/src/LexicalBlockWithAlignableContents.tsrx +13 -14
- package/src/LexicalCharacterLimitPlugin.tsrx +3 -1
- package/src/LexicalCheckListPlugin.tsrx +4 -4
- package/src/LexicalClearEditorPlugin.tsrx +3 -4
- package/src/LexicalClickableLinkPlugin.tsrx +4 -5
- package/src/LexicalComposer.tsrx +1 -1
- package/src/LexicalContentEditable.tsrx +11 -9
- package/src/LexicalDraggableBlockPlugin.tsrx +17 -15
- package/src/LexicalEditorRefPlugin.tsrx +2 -2
- package/src/LexicalErrorBoundary.tsrx +10 -6
- package/src/LexicalHistoryPlugin.tsrx +5 -5
- package/src/LexicalLinkPlugin.tsrx +4 -5
- package/src/LexicalListPlugin.tsrx +7 -8
- package/src/LexicalMarkdownShortcutPlugin.tsrx +4 -6
- package/src/LexicalNestedComposer.tsrx +9 -6
- package/src/LexicalNodeContextMenuPlugin.tsrx +15 -13
- package/src/LexicalNodeEventPlugin.tsrx +5 -6
- package/src/LexicalNodeMenuPlugin.tsrx +29 -20
- package/src/LexicalOnChangePlugin.tsrx +11 -15
- package/src/LexicalPlainTextPlugin.tsrx +4 -5
- package/src/LexicalRichTextPlugin.tsrx +4 -5
- package/src/LexicalSelectionAlwaysOnDisplay.tsrx +3 -4
- package/src/LexicalTabIndentationPlugin.tsrx +8 -9
- package/src/LexicalTableOfContentsPlugin.tsrx +83 -82
- package/src/LexicalTablePlugin.tsrx +24 -27
- package/src/LexicalTypeaheadMenuPlugin.tsrx +48 -31
- package/src/shared/LexicalContentEditableElement.tsrx +52 -47
- package/src/shared/LexicalDecorators.tsrx +24 -22
- package/src/shared/LexicalMenu.tsrx +52 -38
|
@@ -20,30 +20,29 @@ type DivAttributes = Octane.HTMLAttributes<HTMLDivElement>;
|
|
|
20
20
|
* set ARIA properties. The camelCase `aria*` props (such as `ariaLabel`) are
|
|
21
21
|
* also accepted but are retained only for backwards compatibility.
|
|
22
22
|
*/
|
|
23
|
-
export type ContentEditableElementProps =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} & Omit<Octane.JSX.IntrinsicElements['div'], 'ref' | 'placeholder'>;
|
|
23
|
+
export type ContentEditableElementProps = {
|
|
24
|
+
editor: LexicalEditor;
|
|
25
|
+
ariaActiveDescendant?: DivAttributes['aria-activedescendant'];
|
|
26
|
+
ariaAutoComplete?: DivAttributes['aria-autocomplete'];
|
|
27
|
+
ariaControls?: DivAttributes['aria-controls'];
|
|
28
|
+
ariaDescribedBy?: DivAttributes['aria-describedby'];
|
|
29
|
+
ariaErrorMessage?: DivAttributes['aria-errormessage'];
|
|
30
|
+
ariaExpanded?: DivAttributes['aria-expanded'];
|
|
31
|
+
ariaInvalid?: DivAttributes['aria-invalid'];
|
|
32
|
+
ariaLabel?: DivAttributes['aria-label'];
|
|
33
|
+
ariaLabelledBy?: DivAttributes['aria-labelledby'];
|
|
34
|
+
ariaMultiline?: DivAttributes['aria-multiline'];
|
|
35
|
+
ariaOwns?: DivAttributes['aria-owns'];
|
|
36
|
+
ariaRequired?: DivAttributes['aria-required'];
|
|
37
|
+
autoCapitalize?: HTMLDivElement['autocapitalize'];
|
|
38
|
+
'data-testid'?: string | null | undefined;
|
|
39
|
+
// Octane ref shapes (no forwardRef): callback or ref object.
|
|
40
|
+
ref?: ((el: HTMLDivElement | null) => void) | { current: HTMLDivElement | null };
|
|
41
|
+
// Consumed (excluded from the `rest` passthrough) but never rendered —
|
|
42
|
+
// upstream omits `placeholder` from the accepted div attributes; the octane
|
|
43
|
+
// port receives it via `<ContentEditable {...props}>`'s spread instead.
|
|
44
|
+
placeholder?: unknown;
|
|
45
|
+
} & Omit<Octane.JSX.IntrinsicElements['div'], 'ref' | 'placeholder'>;
|
|
47
46
|
|
|
48
47
|
// Props consumed by name — everything else flows through to the <div> via `rest`.
|
|
49
48
|
const NAMED_PROPS = new Set([
|
|
@@ -77,15 +76,18 @@ export function ContentEditableElement(props: ContentEditableElementProps) @{
|
|
|
77
76
|
const editor = props.editor;
|
|
78
77
|
const [isEditable, setEditable] = useState(editor.isEditable());
|
|
79
78
|
|
|
80
|
-
const handleRef = useCallback(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
const handleRef = useCallback(
|
|
80
|
+
(rootElement: HTMLDivElement | null) => {
|
|
81
|
+
// defaultView is required for a root element. In multi-window setups it may
|
|
82
|
+
// not exist at certain points.
|
|
83
|
+
if (rootElement && rootElement.ownerDocument && rootElement.ownerDocument.defaultView) {
|
|
84
|
+
editor.setRootElement(rootElement);
|
|
85
|
+
} else {
|
|
86
|
+
editor.setRootElement(null);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[editor],
|
|
90
|
+
);
|
|
89
91
|
|
|
90
92
|
useLayoutEffect(() => {
|
|
91
93
|
setEditable(editor.isEditable());
|
|
@@ -94,8 +96,7 @@ export function ContentEditableElement(props: ContentEditableElementProps) @{
|
|
|
94
96
|
});
|
|
95
97
|
}, [editor]);
|
|
96
98
|
|
|
97
|
-
const role =
|
|
98
|
-
props.role != null ? props.role : 'textbox';
|
|
99
|
+
const role = props.role != null ? props.role : 'textbox';
|
|
99
100
|
const rest: Record<string, any> = {};
|
|
100
101
|
for (const k in props) {
|
|
101
102
|
if (!NAMED_PROPS.has(k)) {
|
|
@@ -114,29 +115,33 @@ export function ContentEditableElement(props: ContentEditableElementProps) @{
|
|
|
114
115
|
// (`tabIndex` via ATTRIBUTE_ALIASES, the rest via HTML's case-insensitive
|
|
115
116
|
// setAttribute).
|
|
116
117
|
<div
|
|
117
|
-
ref={
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
ref={
|
|
119
|
+
props.ref != null
|
|
120
|
+
? // Octane's runtime accepts an array of refs natively; the checker's
|
|
121
|
+
// merged-ref signature only models the single-ref forms, so the
|
|
122
|
+
// dynamic array branch needs a type-level cast.
|
|
123
|
+
([props.ref, handleRef] as unknown as typeof handleRef)
|
|
124
|
+
: handleRef
|
|
125
|
+
}
|
|
123
126
|
aria-activedescendant={isEditable ? props.ariaActiveDescendant : undefined}
|
|
124
127
|
aria-autocomplete={isEditable ? props.ariaAutoComplete : 'none'}
|
|
125
128
|
aria-controls={isEditable ? props.ariaControls : undefined}
|
|
126
129
|
aria-describedby={props.ariaDescribedBy}
|
|
127
130
|
aria-errormessage={props.ariaErrorMessage != null ? props.ariaErrorMessage : undefined}
|
|
128
|
-
aria-expanded={
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
aria-expanded={
|
|
132
|
+
isEditable && role === 'combobox'
|
|
133
|
+
? (String(!!props.ariaExpanded) as 'true' | 'false')
|
|
134
|
+
: undefined
|
|
135
|
+
}
|
|
131
136
|
aria-invalid={props.ariaInvalid != null ? props.ariaInvalid : undefined}
|
|
132
137
|
aria-label={props.ariaLabel}
|
|
133
138
|
aria-labelledby={props.ariaLabelledBy}
|
|
134
139
|
aria-multiline={props.ariaMultiline}
|
|
135
140
|
aria-owns={isEditable ? props.ariaOwns : undefined}
|
|
136
141
|
aria-readonly={isEditable ? undefined : 'true'}
|
|
137
|
-
aria-required={
|
|
138
|
-
? String(props.ariaRequired) as 'true' | 'false'
|
|
139
|
-
|
|
142
|
+
aria-required={
|
|
143
|
+
props.ariaRequired != null ? (String(props.ariaRequired) as 'true' | 'false') : undefined
|
|
144
|
+
}
|
|
140
145
|
autoCapitalize={props.autoCapitalize}
|
|
141
146
|
contentEditable={isEditable ? 'true' : 'false'}
|
|
142
147
|
data-testid={props['data-testid']}
|
|
@@ -9,11 +9,10 @@ import type { LexicalEditor } from 'lexical';
|
|
|
9
9
|
import type { OctaneNode } from 'octane';
|
|
10
10
|
import { createElement, createPortal, Suspense, useMemo, useSyncExternalStore } from 'octane';
|
|
11
11
|
|
|
12
|
-
type ErrorBoundaryType =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}) => OctaneNode;
|
|
12
|
+
type ErrorBoundaryType = (props: {
|
|
13
|
+
children: OctaneNode;
|
|
14
|
+
onError: (error: Error) => void;
|
|
15
|
+
}) => OctaneNode;
|
|
17
16
|
|
|
18
17
|
type DecoratorPortalBodyProps = {
|
|
19
18
|
ErrorBoundary: ErrorBoundaryType;
|
|
@@ -47,10 +46,11 @@ export function Decorators(props: DecoratorsProps) {
|
|
|
47
46
|
const ErrorBoundary = props.ErrorBoundary;
|
|
48
47
|
|
|
49
48
|
const [subscribe, getSnapshot] = useMemo(
|
|
50
|
-
() =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
() =>
|
|
50
|
+
[
|
|
51
|
+
(cb: () => void) => editor.registerDecoratorListener(cb),
|
|
52
|
+
() => editor.getDecorators<OctaneNode>(),
|
|
53
|
+
] as const,
|
|
54
54
|
[editor],
|
|
55
55
|
);
|
|
56
56
|
const decorators = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
@@ -84,17 +84,19 @@ export function Decorators(props: DecoratorsProps) {
|
|
|
84
84
|
if (entries.length === 0) {
|
|
85
85
|
return null;
|
|
86
86
|
}
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
(entry) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
return (
|
|
88
|
+
<>
|
|
89
|
+
{entries.map((entry) => (
|
|
90
|
+
<DecoratorPortal
|
|
91
|
+
key={entry.nodeKey}
|
|
92
|
+
element={entry.element}
|
|
93
|
+
bodyProps={{
|
|
94
|
+
ErrorBoundary,
|
|
95
|
+
onError: (e: Error) => editor._onError(e),
|
|
96
|
+
decorator: entry.decorator,
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
))}
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
100
102
|
}
|
|
@@ -53,19 +53,21 @@ type DefaultMenuProps<TOption extends MenuOption> = {
|
|
|
53
53
|
|
|
54
54
|
function DefaultMenu<TOption extends MenuOption>(props: DefaultMenuProps<TOption>) @{
|
|
55
55
|
<div class="typeahead-popover mentions-menu">
|
|
56
|
-
<ul>
|
|
57
|
-
(option, i) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
<ul>
|
|
57
|
+
{props.options.map((option, i) => (
|
|
58
|
+
<MenuItem
|
|
59
|
+
key={option.key}
|
|
60
|
+
index={i}
|
|
61
|
+
isSelected={props.selectedIndex === i}
|
|
62
|
+
onClick={() => {
|
|
63
|
+
props.setHighlightedIndex(i);
|
|
64
|
+
props.selectOptionAndCleanUp(option);
|
|
65
|
+
}}
|
|
66
|
+
onMouseEnter={() => props.setHighlightedIndex(i)}
|
|
67
|
+
option={option}
|
|
68
|
+
/>
|
|
69
|
+
))}
|
|
70
|
+
</ul>
|
|
69
71
|
</div>
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -77,8 +79,12 @@ type LexicalMenuProps<TOption extends MenuOption> = {
|
|
|
77
79
|
options: TOption[];
|
|
78
80
|
shouldSplitNodeWithQuery?: boolean;
|
|
79
81
|
menuRenderFn?: MenuRenderFn<TOption>;
|
|
80
|
-
onSelectOption: (
|
|
81
|
-
|
|
82
|
+
onSelectOption: (
|
|
83
|
+
option: TOption,
|
|
84
|
+
textNodeContainingQuery: TextNode | null,
|
|
85
|
+
closeMenu: () => void,
|
|
86
|
+
matchingString: string,
|
|
87
|
+
) => void;
|
|
82
88
|
commandPriority?: CommandListenerPriority;
|
|
83
89
|
preselectFirstItem?: boolean;
|
|
84
90
|
};
|
|
@@ -108,28 +114,34 @@ export function LexicalMenu<TOption extends MenuOption>(props: LexicalMenuProps<
|
|
|
108
114
|
}
|
|
109
115
|
}, [matchingString, preselectFirstItem]);
|
|
110
116
|
|
|
111
|
-
const selectOptionAndCleanUp = useCallback(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
const selectOptionAndCleanUp = useCallback(
|
|
118
|
+
(selectedEntry: TOption) => {
|
|
119
|
+
editor.update(() => {
|
|
120
|
+
const textNodeContainingQuery =
|
|
121
|
+
resolution.match != null && shouldSplitNodeWithQuery
|
|
122
|
+
? $splitNodeContainingQuery(resolution.match)
|
|
123
|
+
: null;
|
|
124
|
+
onSelectOption(
|
|
125
|
+
selectedEntry,
|
|
126
|
+
textNodeContainingQuery,
|
|
127
|
+
close,
|
|
128
|
+
resolution.match ? resolution.match.matchingString : '',
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
[editor, shouldSplitNodeWithQuery, resolution.match, onSelectOption, close],
|
|
133
|
+
);
|
|
125
134
|
|
|
126
|
-
const updateSelectedIndex = useCallback(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
rootElem
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
const updateSelectedIndex = useCallback(
|
|
136
|
+
(index: number) => {
|
|
137
|
+
const rootElem = editor.getRootElement();
|
|
138
|
+
if (rootElem !== null) {
|
|
139
|
+
rootElem.setAttribute('aria-activedescendant', 'typeahead-item-' + index);
|
|
140
|
+
setHighlightedIndex(index);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
[editor],
|
|
144
|
+
);
|
|
133
145
|
|
|
134
146
|
useEffect(() => {
|
|
135
147
|
return () => {
|
|
@@ -271,8 +283,10 @@ export function LexicalMenu<TOption extends MenuOption>(props: LexicalMenuProps<
|
|
|
271
283
|
KEY_ENTER_COMMAND,
|
|
272
284
|
(event) => {
|
|
273
285
|
if (
|
|
274
|
-
options === null ||
|
|
275
|
-
|
|
286
|
+
options === null ||
|
|
287
|
+
selectedIndex === null ||
|
|
288
|
+
options[selectedIndex] == null ||
|
|
289
|
+
(event && event.shiftKey)
|
|
276
290
|
) {
|
|
277
291
|
return false;
|
|
278
292
|
}
|