@octanejs/lexical 0.1.57 → 0.2.0

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 (32) hide show
  1. package/README.md +16 -10
  2. package/package.json +31 -22
  3. package/src/LexicalAutoEmbedPlugin.tsrx +30 -17
  4. package/src/{autoEmbedShared.ts → LexicalAutoEmbedPluginUtils.ts} +4 -4
  5. package/src/LexicalCollaborationContext.ts +7 -66
  6. package/src/LexicalCollaborationContextUtils.ts +76 -0
  7. package/src/LexicalDecoratorBlockNode.ts +41 -23
  8. package/src/LexicalDraggableBlockPlugin.tsrx +37 -39
  9. package/src/LexicalHorizontalRuleNode.tsrx +13 -21
  10. package/src/LexicalMarkdownShortcutPlugin.tsrx +12 -1
  11. package/src/LexicalMenuOption.ts +26 -0
  12. package/src/LexicalNodeContextMenuPlugin.tsrx +20 -14
  13. package/src/LexicalNodeEventPlugin.tsrx +2 -3
  14. package/src/LexicalNodeMenuPlugin.tsrx +2 -1
  15. package/src/LexicalTypeaheadMenuPlugin.tsrx +10 -9
  16. package/src/LexicalTypeaheadMenuPluginUtils.ts +78 -0
  17. package/src/index.ts +19 -4
  18. package/src/shared/LexicalContentEditableElement.tsrx +1 -1
  19. package/src/shared/LexicalDecorators.tsrx +23 -35
  20. package/src/shared/LexicalMenu.tsrx +63 -45
  21. package/src/shared/LexicalReactGeneratedJSON.ts +78 -0
  22. package/src/shared/menuShared.ts +75 -24
  23. package/src/shared/useCharacterLimit.ts +48 -23
  24. package/src/shared/useDynamicPositioning.ts +25 -18
  25. package/src/shared/useMenuAnchorRef.ts +28 -12
  26. package/src/typeaheadShared.ts +2 -55
  27. package/src/useLexicalAriaLiveRegion.ts +25 -0
  28. package/src/useLexicalFocusManagerRef.ts +40 -0
  29. package/src/useLexicalFocusTrapRef.ts +65 -0
  30. package/src/useLexicalIsTextContentEmpty.ts +5 -1
  31. package/src/useLexicalNodeSelection.ts +11 -0
  32. package/src/useLexicalRovingTabIndexRef.ts +41 -0
@@ -15,12 +15,16 @@ export function useLexicalIsTextContentEmpty(...args: any[]): boolean {
15
15
  const trim = user[1] as boolean | undefined;
16
16
 
17
17
  const [isEmpty, setIsEmpty] = useState(
18
- editor.read('latest', $isRootTextContentEmptyCurry(editor.isComposing(), trim)),
18
+ () => editor.read('latest', $isRootTextContentEmptyCurry(editor.isComposing(), trim)),
19
19
  subSlot(slot, 'ultce:state'),
20
20
  );
21
21
 
22
22
  useLayoutEffect(
23
23
  () => {
24
+ // The state was seeded on the first render only, so re-derive it whenever
25
+ // the inputs the effect depends on change -- otherwise a new editor or a
26
+ // new trim keeps reporting the previous answer until the next update.
27
+ setIsEmpty(editor.read('latest', $isRootTextContentEmptyCurry(editor.isComposing(), trim)));
24
28
  return editor.registerUpdateListener(({ editorState }) => {
25
29
  const isComposing = editor.isComposing();
26
30
  const currentIsEmpty = editorState.read($isRootTextContentEmptyCurry(isComposing, trim));
@@ -58,6 +58,17 @@ export function useLexicalNodeSelection(
58
58
  editor.update(() => {
59
59
  let selection = $getSelection();
60
60
  if (!$isNodeSelection(selection)) {
61
+ const node = selected ? null : $getNodeByKey(key);
62
+ if (node !== null && !node.isSelected()) {
63
+ // Nothing to remove: this node is not part of the current
64
+ // selection, and replacing it with an empty NodeSelection would
65
+ // discard the user's caret for no benefit.
66
+ return;
67
+ }
68
+ // Deselecting a node the selection *does* cover still has to take
69
+ // effect, or the `clearSelection(); setSelected(!isSelected)` toggle
70
+ // that decorator nodes use becomes a dead click under a
71
+ // RangeSelection.
61
72
  selection = $createNodeSelection();
62
73
  $setSelection(selection);
63
74
  }
@@ -0,0 +1,41 @@
1
+ import { RovingTabIndexExtension, type RovingTabIndexOptions } from '@lexical/a11y';
2
+ import { getExtensionDependencyFromEditor } from '@lexical/extension';
3
+ import { useCallback, useRef } from 'octane';
4
+
5
+ import { useLexicalComposerContext } from './LexicalComposerContext';
6
+ import { splitSlot, subSlot } from './shared/internal';
7
+
8
+ export type { RovingOrientation, RovingTabIndexOptions } from '@lexical/a11y';
9
+
10
+ // Ported from @lexical/react/src/useLexicalRovingTabIndexRef.ts. `options` is
11
+ // optional, so the trailing slot is found with splitSlot. Public
12
+ // signature is `(options?: RovingTabIndexOptions)`.
13
+
14
+ /**
15
+ * Returns a callback ref that registers the attached element as a
16
+ * roving-tabindex container with {@link RovingTabIndexExtension}, and releases
17
+ * it when the element detaches. Requires `RovingTabIndexExtension` in the
18
+ * editor's extension tree.
19
+ */
20
+ export function useLexicalRovingTabIndexRef(...args: any[]): (node: HTMLElement | null) => void {
21
+ const [user, slot] = splitSlot(args);
22
+ const options = (user[0] as RovingTabIndexOptions | undefined) ?? {};
23
+ const [editor] = useLexicalComposerContext();
24
+ const { orientation, itemSelector } = options;
25
+ const disposeRef = useRef<(() => void) | null>(null, subSlot(slot, 'ulrt:dispose'));
26
+
27
+ return useCallback(
28
+ (node: HTMLElement | null) => {
29
+ if (disposeRef.current !== null) {
30
+ disposeRef.current();
31
+ disposeRef.current = null;
32
+ }
33
+ if (node !== null) {
34
+ const dep = getExtensionDependencyFromEditor(editor, RovingTabIndexExtension);
35
+ disposeRef.current = dep.output.register(node, { itemSelector, orientation });
36
+ }
37
+ },
38
+ [editor, orientation, itemSelector],
39
+ subSlot(slot, 'ulrt:ref'),
40
+ );
41
+ }