@slash-editor/react 0.0.2 → 0.0.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/dist/index.d.mts +24 -1
- package/dist/index.mjs +37 -2
- package/package.json +7 -2
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,29 @@ interface UseSlashEditorOptions extends Omit<UseEditorOptions, "extensions"> {
|
|
|
23
23
|
*/
|
|
24
24
|
declare function useSlashEditor(options?: UseSlashEditorOptions): Editor | null;
|
|
25
25
|
//#endregion
|
|
26
|
+
//#region src/use-active-item-scroll.d.ts
|
|
27
|
+
interface ActiveItemScrollOptions {
|
|
28
|
+
/** Attribute carrying an item's id on the list rows. @default "data-value" */
|
|
29
|
+
attribute?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Keeps the highlighted row of a suggestion list visible.
|
|
33
|
+
*
|
|
34
|
+
* Command palettes scroll themselves only while they own the keyboard. Here
|
|
35
|
+
* the editor never loses focus — the suggestion plugin moves the highlight and
|
|
36
|
+
* the list only receives a controlled value — so nothing scrolls unless the
|
|
37
|
+
* consumer does it. `block: "nearest"` makes this inert for an already visible
|
|
38
|
+
* row, so pointer hover never fights the scroll position.
|
|
39
|
+
*
|
|
40
|
+
* Returns a ref callback for the scroll container:
|
|
41
|
+
*
|
|
42
|
+
* ```tsx
|
|
43
|
+
* const listRef = useActiveItemScroll(menu.activeItem?.id);
|
|
44
|
+
* <CommandList ref={listRef}>…</CommandList>
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function useActiveItemScroll(activeId: string | null | undefined, options?: ActiveItemScrollOptions): (node: HTMLElement | null) => void;
|
|
48
|
+
//#endregion
|
|
26
49
|
//#region src/use-block-drag.d.ts
|
|
27
50
|
/** Minimal anchor accepted by floating-ui based popovers and absolutely positioned elements. */
|
|
28
51
|
interface BlockDragAnchor {
|
|
@@ -205,4 +228,4 @@ interface SlashMenu extends SlashMenuState {
|
|
|
205
228
|
*/
|
|
206
229
|
declare function useSlashMenu(editor: Editor | null): SlashMenu;
|
|
207
230
|
//#endregion
|
|
208
|
-
export { type BlockDrag, type BlockDragAnchor, type BubbleToolbar, type BubbleToolbarAnchor, type BubbleToolbarItem, type Comments, EditorContent, EditorContext, EditorProvider, type LinkEditor, type LinkEditorAnchor, type MentionMenu, type MentionMenuAnchor, type PresencePeer, type PresenceProvider, type SlashMenu, type SlashMenuAnchor, type UseCommentsOptions, type UseSlashEditorOptions, useBlockDrag, useBubbleToolbar, useComments, useCurrentEditor, useEditorState, useLinkEditor, useMention, usePresence, useSlashEditor, useSlashMenu };
|
|
231
|
+
export { type ActiveItemScrollOptions, type BlockDrag, type BlockDragAnchor, type BubbleToolbar, type BubbleToolbarAnchor, type BubbleToolbarItem, type Comments, EditorContent, EditorContext, EditorProvider, type LinkEditor, type LinkEditorAnchor, type MentionMenu, type MentionMenuAnchor, type PresencePeer, type PresenceProvider, type SlashMenu, type SlashMenuAnchor, type UseCommentsOptions, type UseSlashEditorOptions, useActiveItemScroll, useBlockDrag, useBubbleToolbar, useComments, useCurrentEditor, useEditorState, useLinkEditor, useMention, usePresence, useSlashEditor, useSlashMenu };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EditorContent, EditorContext, EditorProvider, useCurrentEditor, useEditor, useEditorState } from "@tiptap/react";
|
|
2
2
|
import { createBlockKit } from "@slash-editor/core";
|
|
3
|
-
import { useCallback, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { useCallback, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
//#region src/use-slash-editor.ts
|
|
5
5
|
/**
|
|
6
6
|
* Creates an editor with the slash-editor baseline schema.
|
|
@@ -23,6 +23,41 @@ function useSlashEditor(options = {}) {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
|
+
//#region src/use-active-item-scroll.ts
|
|
27
|
+
/**
|
|
28
|
+
* Keeps the highlighted row of a suggestion list visible.
|
|
29
|
+
*
|
|
30
|
+
* Command palettes scroll themselves only while they own the keyboard. Here
|
|
31
|
+
* the editor never loses focus — the suggestion plugin moves the highlight and
|
|
32
|
+
* the list only receives a controlled value — so nothing scrolls unless the
|
|
33
|
+
* consumer does it. `block: "nearest"` makes this inert for an already visible
|
|
34
|
+
* row, so pointer hover never fights the scroll position.
|
|
35
|
+
*
|
|
36
|
+
* Returns a ref callback for the scroll container:
|
|
37
|
+
*
|
|
38
|
+
* ```tsx
|
|
39
|
+
* const listRef = useActiveItemScroll(menu.activeItem?.id);
|
|
40
|
+
* <CommandList ref={listRef}>…</CommandList>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function useActiveItemScroll(activeId, options = {}) {
|
|
44
|
+
const { attribute = "data-value" } = options;
|
|
45
|
+
const container = useRef(null);
|
|
46
|
+
const listRef = useCallback((node) => {
|
|
47
|
+
container.current = node;
|
|
48
|
+
}, []);
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
const node = container.current;
|
|
51
|
+
if (!node || !activeId || !node.isConnected) return;
|
|
52
|
+
const item = node.querySelector(`[${attribute}="${CSS.escape(activeId)}"]`);
|
|
53
|
+
if (!item) return;
|
|
54
|
+
const group = item.parentElement;
|
|
55
|
+
if (group?.firstElementChild === item) group.parentElement?.firstElementChild?.scrollIntoView({ block: "nearest" });
|
|
56
|
+
item.scrollIntoView({ block: "nearest" });
|
|
57
|
+
}, [activeId, attribute]);
|
|
58
|
+
return listRef;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
26
61
|
//#region src/use-block-drag.ts
|
|
27
62
|
const CLOSED$4 = {
|
|
28
63
|
hovered: null,
|
|
@@ -367,4 +402,4 @@ function useSlashMenu(editor) {
|
|
|
367
402
|
};
|
|
368
403
|
}
|
|
369
404
|
//#endregion
|
|
370
|
-
export { EditorContent, EditorContext, EditorProvider, useBlockDrag, useBubbleToolbar, useComments, useCurrentEditor, useEditorState, useLinkEditor, useMention, usePresence, useSlashEditor, useSlashMenu };
|
|
405
|
+
export { EditorContent, EditorContext, EditorProvider, useActiveItemScroll, useBlockDrag, useBubbleToolbar, useComments, useCurrentEditor, useEditorState, useLinkEditor, useMention, usePresence, useSlashEditor, useSlashMenu };
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slash-editor/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Headless React bindings for slash-editor: provider, hooks, unstyled primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/buiducnhat/slash-editor.git",
|
|
9
|
+
"directory": "packages/react"
|
|
10
|
+
},
|
|
6
11
|
"files": [
|
|
7
12
|
"dist"
|
|
8
13
|
],
|
|
@@ -19,7 +24,7 @@
|
|
|
19
24
|
"dev": "vp pack --watch"
|
|
20
25
|
},
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@slash-editor/core": "0.0.
|
|
27
|
+
"@slash-editor/core": "0.0.7"
|
|
23
28
|
},
|
|
24
29
|
"devDependencies": {
|
|
25
30
|
"@tiptap/core": "^3.31.3",
|