@octanejs/lexical 0.2.6 → 0.2.8

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.
Files changed (33) hide show
  1. package/package.json +5 -5
  2. package/src/LexicalAutoEmbedPlugin.tsrx +73 -61
  3. package/src/LexicalAutoFocusPlugin.tsrx +14 -11
  4. package/src/LexicalAutoLinkPlugin.tsrx +6 -5
  5. package/src/LexicalBlockWithAlignableContents.tsrx +13 -14
  6. package/src/LexicalCharacterLimitPlugin.tsrx +3 -1
  7. package/src/LexicalCheckListPlugin.tsrx +4 -4
  8. package/src/LexicalClearEditorPlugin.tsrx +3 -4
  9. package/src/LexicalClickableLinkPlugin.tsrx +4 -5
  10. package/src/LexicalComposer.tsrx +1 -1
  11. package/src/LexicalContentEditable.tsrx +11 -9
  12. package/src/LexicalDraggableBlockPlugin.tsrx +17 -15
  13. package/src/LexicalEditorRefPlugin.tsrx +2 -2
  14. package/src/LexicalErrorBoundary.tsrx +10 -6
  15. package/src/LexicalHistoryPlugin.tsrx +5 -5
  16. package/src/LexicalLinkPlugin.tsrx +4 -5
  17. package/src/LexicalListPlugin.tsrx +7 -8
  18. package/src/LexicalMarkdownShortcutPlugin.tsrx +4 -6
  19. package/src/LexicalNestedComposer.tsrx +9 -6
  20. package/src/LexicalNodeContextMenuPlugin.tsrx +15 -13
  21. package/src/LexicalNodeEventPlugin.tsrx +5 -6
  22. package/src/LexicalNodeMenuPlugin.tsrx +29 -20
  23. package/src/LexicalOnChangePlugin.tsrx +11 -15
  24. package/src/LexicalPlainTextPlugin.tsrx +4 -5
  25. package/src/LexicalRichTextPlugin.tsrx +4 -5
  26. package/src/LexicalSelectionAlwaysOnDisplay.tsrx +3 -4
  27. package/src/LexicalTabIndentationPlugin.tsrx +8 -9
  28. package/src/LexicalTableOfContentsPlugin.tsrx +83 -82
  29. package/src/LexicalTablePlugin.tsrx +24 -27
  30. package/src/LexicalTypeaheadMenuPlugin.tsrx +48 -31
  31. package/src/shared/LexicalContentEditableElement.tsrx +52 -47
  32. package/src/shared/LexicalDecorators.tsrx +24 -22
  33. 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
- editor: LexicalEditor;
26
- ariaActiveDescendant?: DivAttributes['aria-activedescendant'];
27
- ariaAutoComplete?: DivAttributes['aria-autocomplete'];
28
- ariaControls?: DivAttributes['aria-controls'];
29
- ariaDescribedBy?: DivAttributes['aria-describedby'];
30
- ariaErrorMessage?: DivAttributes['aria-errormessage'];
31
- ariaExpanded?: DivAttributes['aria-expanded'];
32
- ariaInvalid?: DivAttributes['aria-invalid'];
33
- ariaLabel?: DivAttributes['aria-label'];
34
- ariaLabelledBy?: DivAttributes['aria-labelledby'];
35
- ariaMultiline?: DivAttributes['aria-multiline'];
36
- ariaOwns?: DivAttributes['aria-owns'];
37
- ariaRequired?: DivAttributes['aria-required'];
38
- autoCapitalize?: HTMLDivElement['autocapitalize'];
39
- 'data-testid'?: string | null | undefined;
40
- // Octane ref shapes (no forwardRef): callback or ref object.
41
- ref?: ((el: HTMLDivElement | null) => void) | { current: HTMLDivElement | null };
42
- // Consumed (excluded from the `rest` passthrough) but never rendered —
43
- // upstream omits `placeholder` from the accepted div attributes; the octane
44
- // port receives it via `<ContentEditable {...props}>`'s spread instead.
45
- placeholder?: unknown;
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((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
- }, [editor]);
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={props.ref != null
118
- ? // Octane's runtime accepts an array of refs natively; the checker's
119
- // merged-ref signature only models the single-ref forms, so the
120
- // dynamic array branch needs a type-level cast.
121
- [props.ref, handleRef] as unknown as typeof handleRef
122
- : handleRef}
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={isEditable && role === 'combobox'
129
- ? String(!!props.ariaExpanded) as 'true' | 'false'
130
- : undefined}
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={props.ariaRequired != null
138
- ? String(props.ariaRequired) as 'true' | 'false'
139
- : undefined}
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
- (props: {
14
- children: OctaneNode;
15
- onError: (error: Error) => void;
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
- (cb: () => void) => editor.registerDecoratorListener(cb),
52
- () => editor.getDecorators<OctaneNode>(),
53
- ] as const,
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
- {entries.map(
89
- (entry) => <DecoratorPortal
90
- key={entry.nodeKey}
91
- element={entry.element}
92
- bodyProps={{
93
- ErrorBoundary,
94
- onError: (e: Error) => editor._onError(e),
95
- decorator: entry.decorator,
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>{props.options.map(
57
- (option, i) => <MenuItem
58
- key={option.key}
59
- index={i}
60
- isSelected={props.selectedIndex === i}
61
- onClick={() => {
62
- props.setHighlightedIndex(i);
63
- props.selectOptionAndCleanUp(option);
64
- }}
65
- onMouseEnter={() => props.setHighlightedIndex(i)}
66
- option={option}
67
- />,
68
- )}</ul>
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: (option: TOption, textNodeContainingQuery: | TextNode
81
- | null, closeMenu: () => void, matchingString: string) => void;
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((selectedEntry: TOption) => {
112
- editor.update(() => {
113
- const textNodeContainingQuery =
114
- resolution.match != null && shouldSplitNodeWithQuery
115
- ? $splitNodeContainingQuery(resolution.match)
116
- : null;
117
- onSelectOption(
118
- selectedEntry,
119
- textNodeContainingQuery,
120
- close,
121
- resolution.match ? resolution.match.matchingString : '',
122
- );
123
- });
124
- }, [editor, shouldSplitNodeWithQuery, resolution.match, onSelectOption, close]);
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((index: number) => {
127
- const rootElem = editor.getRootElement();
128
- if (rootElem !== null) {
129
- rootElem.setAttribute('aria-activedescendant', 'typeahead-item-' + index);
130
- setHighlightedIndex(index);
131
- }
132
- }, [editor]);
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 || selectedIndex === null || options[selectedIndex] == null ||
275
- event && event.shiftKey
286
+ options === null ||
287
+ selectedIndex === null ||
288
+ options[selectedIndex] == null ||
289
+ (event && event.shiftKey)
276
290
  ) {
277
291
  return false;
278
292
  }