@retor/react-native 0.1.0 → 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.
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ interface RetorTag {
16
16
  color?: string;
17
17
  tagType?: string;
18
18
  iconName?: string;
19
+ objectId?: string;
19
20
  }
20
21
  interface RetorLine {
21
22
  _id: string;
@@ -50,12 +51,106 @@ interface ViewerHandle {
50
51
  toggleAutoplay: () => void;
51
52
  setAutoplay: (playing: boolean) => void;
52
53
  }
54
+
55
+ interface NoteSubmitPayload {
56
+ text: string;
57
+ isPrivate: boolean;
58
+ tagId: string | null;
59
+ lineId: string | null;
60
+ position: {
61
+ x: number;
62
+ y: number;
63
+ z: number;
64
+ } | null;
65
+ }
66
+ interface RetorBridgeContextValue {
67
+ project: RetorProject | null;
68
+ lines: RetorLine[];
69
+ activeLineId: string | null;
70
+ activeLine: RetorLine | null;
71
+ closestTagId: string | null;
72
+ progress: number;
73
+ isPlaying: boolean;
74
+ isAddNoteOpen: boolean;
75
+ addNoteTagId: string | null;
76
+ controls: ViewerHandle;
77
+ openAddNote: (tagId?: string) => void;
78
+ closeAddNote: () => void;
79
+ submitNote: (text: string, isPrivate?: boolean) => void;
80
+ onNoteSubmit?: (payload: NoteSubmitPayload) => void;
81
+ }
82
+ declare function useRetorBridge(): RetorBridgeContextValue;
83
+ /** Returns the array of all lines in the current project. */
84
+ declare function useLines(): RetorLine[];
85
+ /** Returns the project metadata once `init` has fired. */
86
+ declare function useProject(): RetorProject | null;
87
+ /**
88
+ * Returns the line that's currently open (after the user enters a scroll path),
89
+ * or null when in browse mode.
90
+ */
91
+ declare function useActiveLine(): RetorLine | null;
92
+ /**
93
+ * Returns scroll progress (0..1) and the id of the closest tag along the
94
+ * currently active line. Both are null when no line is open.
95
+ */
96
+ declare function useLineProgress(): {
97
+ progress: number;
98
+ closestTagId: string | null;
99
+ };
100
+ /**
101
+ * Returns the autoplay state and controls.
102
+ */
103
+ declare function useAutoplay(): {
104
+ isPlaying: boolean;
105
+ toggle: () => void;
106
+ play: () => void;
107
+ pause: () => void;
108
+ };
109
+ /**
110
+ * Returns the current add-note flow state and actions.
111
+ */
112
+ declare function useAddNote(): {
113
+ isOpen: boolean;
114
+ tagId: string | null;
115
+ open: (tagId?: string) => void;
116
+ close: () => void;
117
+ submit: (text: string, isPrivate?: boolean) => void;
118
+ };
119
+
120
+ /**
121
+ * Hook for controlling a Viewer from anywhere in your tree.
122
+ *
123
+ * Default usage (single viewer):
124
+ * ```tsx
125
+ * const { openLine, exitLine } = useViewer();
126
+ * ```
127
+ *
128
+ * Multiple viewers:
129
+ * ```tsx
130
+ * <Viewer id="left" projectId="..." />
131
+ * const left = useViewer("left");
132
+ * ```
133
+ *
134
+ * With a ref:
135
+ * ```tsx
136
+ * const ref = useRef<ViewerHandle>(null);
137
+ * const { openLine } = useViewer(ref);
138
+ * ```
139
+ */
140
+ declare function useViewer(target?: string | React.RefObject<ViewerHandle | null>): ViewerHandle;
141
+ interface NotesProps {
142
+ /** Array of notes (same shape as RetorTag) to push into the 3D scene. */
143
+ notes: RetorTag[];
144
+ }
145
+ declare function Notes(_props: NotesProps): React.ReactElement | null;
53
146
  interface ViewerProps {
54
147
  projectId: string;
55
148
  /** Identifier for this viewer instance. Used by `useViewer(id)`. Defaults to "default". */
56
149
  id?: string;
57
150
  /** Base URL where Retor is hosted. Defaults to https://retor.app */
58
151
  baseUrl?: string;
152
+ /** Called when a note is submitted via `<AddNoteSheet>`. Receives the text + position. */
153
+ onNoteSubmit?: (note: NoteSubmitPayload) => void;
59
154
  onInit?: (data: InitPayload) => void;
60
155
  onLineOpen?: (data: {
61
156
  lineId: string;
@@ -66,48 +161,132 @@ interface ViewerProps {
66
161
  style?: StyleProp<ViewStyle>;
67
162
  children?: React.ReactNode;
68
163
  }
164
+ declare const Viewer: React.ForwardRefExoticComponent<ViewerProps & React.RefAttributes<ViewerHandle>>;
165
+
166
+ interface HudProps {
167
+ children: React.ReactNode;
168
+ }
69
169
  /**
70
- * Hook that returns a destructured set of viewer controls.
170
+ * Sets up the bottom-sheet provider tree for the SDK's UI components
171
+ * (`<ProjectSheet>`, `<LineDetailSheet>`, `<AddNoteSheet>`).
71
172
  *
72
- * Usage with an ID (default "default"):
73
- * ```tsx
74
- * <Viewer projectId="..." /> // id defaults to "default"
75
- * const { openLine, exitLine } = useViewer();
76
- * ```
173
+ * Place inside `<Viewer>` so the sheets can read scene state from the bridge:
77
174
  *
78
- * With an explicit ID (multiple viewers on one screen):
79
175
  * ```tsx
80
- * <Viewer id="left" projectId="..." />
81
- * <Viewer id="right" projectId="..." />
82
- * const left = useViewer("left");
83
- * left.openLine("...");
176
+ * <Viewer projectId="...">
177
+ * <Hud>
178
+ * <ProjectSheet />
179
+ * <LineDetailSheet />
180
+ * <AddNoteSheet />
181
+ * </Hud>
182
+ * </Viewer>
84
183
  * ```
184
+ */
185
+ declare function Hud({ children }: HudProps): React.JSX.Element;
186
+
187
+ interface ProjectSheetProps {
188
+ /**
189
+ * Snap points for the sheet. Defaults to ["20%", "60%"].
190
+ */
191
+ snapPoints?: (string | number)[];
192
+ /**
193
+ * Override the default header (project name + description).
194
+ * Receives the project metadata.
195
+ */
196
+ renderHeader?: (project: {
197
+ name?: string;
198
+ description?: string;
199
+ }) => React.ReactNode;
200
+ /**
201
+ * Children to render below the header. Typically a `<LinesCarousel>`.
202
+ * If omitted, a default LinesCarousel is rendered.
203
+ */
204
+ children?: React.ReactNode;
205
+ }
206
+ /**
207
+ * The browse-mode bottom sheet. Auto-presents whenever no line is open.
85
208
  *
86
- * With a ref (if you prefer imperative style):
87
209
  * ```tsx
88
- * const ref = useRef<ViewerHandle>(null);
89
- * <Viewer ref={ref} projectId="..." />
90
- * const { openLine } = useViewer(ref);
210
+ * <ProjectSheet>
211
+ * <LinesCarousel>
212
+ * {(line) => <MyLineCard line={line} />}
213
+ * </LinesCarousel>
214
+ * </ProjectSheet>
91
215
  * ```
92
216
  */
93
- declare function useViewer(target?: string | React.RefObject<ViewerHandle | null>): ViewerHandle;
217
+ declare function ProjectSheet({ snapPoints, renderHeader, children }: ProjectSheetProps): React.JSX.Element;
218
+ interface LinesCarouselProps {
219
+ children: (line: RetorLine, index: number) => React.ReactNode;
220
+ /** Optional gap between items. Defaults to 12. */
221
+ gap?: number;
222
+ /** Optional horizontal padding. Defaults to 16. */
223
+ paddingHorizontal?: number;
224
+ }
94
225
  /**
95
- * Include as a child of `<Viewer>` to show Retor's built-in UI
96
- * (info card, tag list, autoplay controls). Without it, the viewer runs in
97
- * vanilla mode — you build your own UI around the 3D scene using the props.
226
+ * Renders a horizontally scrolling list of lines using a render prop.
227
+ * Place inside `<ProjectSheet>`.
228
+ *
229
+ * Pressing an item is up to your render — use `useViewer().openLine(line._id)`.
98
230
  */
99
- declare function Hud(): React.ReactElement | null;
100
- interface NotesProps {
101
- /** Array of notes (same shape as RetorTag) to pass into the 3D scene. */
102
- notes: RetorTag[];
231
+ declare function LinesCarousel({ children, gap, paddingHorizontal }: LinesCarouselProps): React.JSX.Element | null;
232
+
233
+ interface LineDetailSheetProps {
234
+ /** Snap points. Defaults to ["25%", "75%"]. */
235
+ snapPoints?: (string | number)[];
236
+ /** Override the header. Receives the active line. */
237
+ renderHeader?: (line: RetorLine) => React.ReactNode;
238
+ /** Custom content (typically a `<LineTagList>`). Defaults to a built-in tag list. */
239
+ children?: React.ReactNode;
103
240
  }
104
241
  /**
105
- * Pass user-generated notes into the Retor scene as a child of `<Viewer>`.
106
- * The notes use the same shape as a RetorTag Retor will render them in
107
- * the scene and tag lists. Persistence is handled entirely by your app:
108
- * re-render with an updated `notes` array to sync changes.
242
+ * Sheet that auto-presents when the user enters a line. Shows the line's
243
+ * tags and a Done button. Pass `<LineTagList>` as a child to customise items.
109
244
  */
110
- declare function Notes(_props: NotesProps): React.ReactElement | null;
111
- declare const Viewer: React.ForwardRefExoticComponent<ViewerProps & React.RefAttributes<ViewerHandle>>;
245
+ declare function LineDetailSheet({ snapPoints, renderHeader, children }: LineDetailSheetProps): React.JSX.Element;
246
+ interface LineTagListProps {
247
+ children: (tag: RetorTag, isActive: boolean) => React.ReactNode;
248
+ }
249
+ /**
250
+ * Renders the tags of the active line as a vertical list. Re-renders the
251
+ * active item when the camera scrolls to it. Empty when no line is open.
252
+ */
253
+ declare function LineTagList({ children }: LineTagListProps): React.JSX.Element | null;
254
+
255
+ interface AddNoteSheetProps {
256
+ /** Snap points. Defaults to ["50%"]. */
257
+ snapPoints?: (string | number)[];
258
+ /** Max characters allowed. Defaults to 280. */
259
+ maxLength?: number;
260
+ /** Placeholder text. */
261
+ placeholder?: string;
262
+ /** Override the entire form. Receives helpers + state. */
263
+ renderForm?: (api: AddNoteFormApi) => React.ReactNode;
264
+ }
265
+ interface AddNoteFormApi {
266
+ text: string;
267
+ setText: (v: string) => void;
268
+ isPrivate: boolean;
269
+ setPrivate: (v: boolean) => void;
270
+ submit: () => void;
271
+ close: () => void;
272
+ maxLength: number;
273
+ }
274
+ /**
275
+ * Sheet for adding a note. Auto-presents when `useAddNote().open()` is called.
276
+ * On submit, fires `onNoteSubmit` on the parent `<Viewer>` with the text + position.
277
+ */
278
+ declare function AddNoteSheet({ snapPoints, maxLength, placeholder, renderForm, }: AddNoteSheetProps): React.JSX.Element;
279
+
280
+ interface CoverPhotoProps {
281
+ projectId: string;
282
+ /** Base URL where Retor is hosted. Defaults to https://retor.app */
283
+ baseUrl?: string;
284
+ style?: StyleProp<ViewStyle>;
285
+ }
286
+ /**
287
+ * Renders a Retor project's start view as a static cover image.
288
+ * No 3D rendering, no bridge — use as a thumbnail or hero.
289
+ */
290
+ declare function CoverPhoto({ projectId, baseUrl, style }: CoverPhotoProps): React.JSX.Element;
112
291
 
113
- export { Hud, type InitPayload, type LineProgressPayload, Notes, type NotesProps, type RetorLine, type RetorProject, type RetorTag, Viewer, type ViewerHandle, type ViewerProps, useViewer };
292
+ export { type AddNoteFormApi, AddNoteSheet, type AddNoteSheetProps, CoverPhoto, type CoverPhotoProps, Hud, type HudProps, type InitPayload, LineDetailSheet, type LineDetailSheetProps, type LineProgressPayload, LineTagList, type LineTagListProps, LinesCarousel, type LinesCarouselProps, type NoteSubmitPayload, Notes, type NotesProps, ProjectSheet, type ProjectSheetProps, type RetorBridgeContextValue, type RetorLine, type RetorProject, type RetorTag, Viewer, type ViewerHandle, type ViewerProps, useActiveLine, useAddNote, useAutoplay, useLineProgress, useLines, useProject, useRetorBridge, useViewer };