@fabrika/annotations 0.9.0-dev.1 → 0.9.0-dev.2

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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Replace the document body with `html` inside a fresh container and return it.
3
+ * Call it at the start of each test — the document is shared across every test
4
+ * in the process, so whatever the previous one left behind is still there.
5
+ */
6
+ export declare function mountContainer(html: string): HTMLElement;
7
+ /**
8
+ * A Range over the first occurrence of `text` within a single text node of
9
+ * `root`, which is how a reader's selection arrives in the annotation code.
10
+ * Throws rather than returning null so a typo in the fixture fails the test at
11
+ * its cause instead of somewhere downstream.
12
+ */
13
+ export declare function selectText(root: HTMLElement, text: string): Range;
14
+ /** Ids of the marks currently wrapping annotated text, in document order. */
15
+ export declare function markIds(root: HTMLElement): string[];
@@ -0,0 +1,12 @@
1
+ import type { AnnotationTarget } from './annotationTarget';
2
+ /** A run of text, identified by the text itself. */
3
+ export interface TextLocator {
4
+ text: string;
5
+ }
6
+ /**
7
+ * Selected text, wrapped in inline `<mark>` elements.
8
+ *
9
+ * The fallback target: any snippet at all is text, so this one claims
10
+ * everything the others turned down and must stay last in the registry.
11
+ */
12
+ export declare const textTarget: AnnotationTarget<TextLocator>;
@@ -0,0 +1,13 @@
1
+ import type { Dispatch, SetStateAction } from 'react';
2
+ import type { Annotation, AnnotationContextValue } from './runtime';
3
+ interface AnnotationStateOptions {
4
+ annotations: Annotation[];
5
+ setAnnotations: Dispatch<SetStateAction<Annotation[]>>;
6
+ generalNote: string;
7
+ setGeneralNote: (note: string) => void;
8
+ remoteAnnotations?: Annotation[];
9
+ isReadOnly: boolean;
10
+ onClear?: () => void;
11
+ }
12
+ export declare function useAnnotationState({ annotations: localAnnotations, setAnnotations, generalNote, setGeneralNote, remoteAnnotations, isReadOnly, onClear, }: AnnotationStateOptions): AnnotationContextValue;
13
+ export {};
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { type RegionShape } from './regionTarget';
3
+ interface UseRegionAnnotationOptions {
4
+ /** Container holding the image blocks a region can be drawn on. */
5
+ containerRef: React.RefObject<HTMLElement | null>;
6
+ /** Re-registers the drawing listener when the canvas remounts. */
7
+ restoreKey: unknown;
8
+ /** Shape a new region takes. */
9
+ shape?: RegionShape;
10
+ /** Canvas file the created annotation belongs to. */
11
+ canvasFile?: string;
12
+ /** Scroll container for popover positioning. */
13
+ scrollContainer?: HTMLElement | null;
14
+ }
15
+ /**
16
+ * Drag on an image block to annotate one part of it.
17
+ *
18
+ * An image carries no text, so a plain drag over one is unambiguous and takes
19
+ * no modifier: the selection this would compete with cannot start there. It
20
+ * still has to stay off the two things that already live on an image block —
21
+ * the whole-image comment button and any region already drawn.
22
+ */
23
+ export declare function useRegionAnnotation(options: UseRegionAnnotationOptions): {
24
+ popovers: React.JSX.Element | null;
25
+ isDrawing: boolean;
26
+ isPopoverOpen: boolean;
27
+ };
28
+ export {};
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import type { Annotation, AnnotationContext } from './AnnotationProvider';
3
+ interface UseTextAnnotationOptions {
4
+ /** Ref to the container element where text can be selected and marks are placed */
5
+ containerRef: React.RefObject<HTMLElement | null>;
6
+ /** Trigger for mark restoration — when this value changes, marks are restored */
7
+ restoreKey: unknown;
8
+ /** Subset of annotations to restore in this container */
9
+ restoreAnnotations: Annotation[];
10
+ /** Build AnnotationContext from a selection Range */
11
+ extractContext: (range: Range) => AnnotationContext | undefined;
12
+ /** Optional filePath to associate with created annotations */
13
+ filePath?: string;
14
+ /** Optional canvasFile to associate with created annotations */
15
+ canvasFile?: string;
16
+ /** Scroll container for popover positioning */
17
+ scrollContainer?: HTMLElement | null;
18
+ }
19
+ export declare function useTextAnnotation(options: UseTextAnnotationOptions): {
20
+ popovers: React.JSX.Element;
21
+ openCreatePopover: (anchorEl: HTMLElement, tempId: string, snippet: string, ctx?: AnnotationContext) => void;
22
+ isPopoverOpen: boolean;
23
+ };
24
+ export {};
@@ -0,0 +1,24 @@
1
+ /** Sentinel filePath for annotations on the agent response banner */
2
+ export declare const RESPONSE_ANNOTATION_PATH = "__agent-response__";
3
+ /**
4
+ * The file this annotation lives in, or undefined if it lives in no file.
5
+ * Response annotations ride in the same field under a sentinel, so a bare
6
+ * `if (ann.filePath)` opens a file tab for a path that is not one.
7
+ */
8
+ export declare function fileAnnotationPath(ann: {
9
+ filePath?: string;
10
+ }): string | undefined;
11
+ /**
12
+ * Whether the attach-image affordances are drawn at all.
13
+ *
14
+ * The button, the paste handler and the drop zone all end in one POST to the
15
+ * host's upload endpoint, so a host without one gets none of the three instead
16
+ * of controls that fail silently.
17
+ */
18
+ export declare function hostAcceptsUploads(host: {
19
+ uploadUrl: (() => string) | null;
20
+ }): boolean;
21
+ /** Generate a unique annotation ID */
22
+ export declare function generateAnnotationId(): string;
23
+ /** Auto-resize a textarea to fit its content */
24
+ export declare function autoResizeTextarea(el: HTMLTextAreaElement, minHeight?: number): void;