@textcortex/slidewise 1.6.0 → 1.8.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.
@@ -0,0 +1,82 @@
1
+ import type { CSSProperties, PropsWithChildren } from "react";
2
+ import { useEditor } from "@/lib/StoreProvider";
3
+ import type { Slide } from "@/lib/types";
4
+ import { SlideRailItemProvider } from "./ItemContext";
5
+
6
+ /**
7
+ * Wraps a single slide in the rail. Provides the slide to descendants via
8
+ * context (read with `useSlideRailItem`) and wires click → `selectSlide`.
9
+ *
10
+ * The default subparts (`Thumbnail`, `Number`) read the slide off the
11
+ * context, so hosts can rearrange them freely. Host content (e.g. a
12
+ * three-dots menu, a duplicate button) drops in as additional children.
13
+ *
14
+ * ```tsx
15
+ * <Slidewise.SlideRail.Item slide={slide}>
16
+ * <Slidewise.SlideRail.Thumbnail />
17
+ * <Slidewise.SlideRail.Number />
18
+ * <MyContextMenu slide={slide} />
19
+ * </Slidewise.SlideRail.Item>
20
+ * ```
21
+ */
22
+ export interface SlideRailItemProps {
23
+ slide: Slide;
24
+ className?: string;
25
+ style?: CSSProperties;
26
+ /**
27
+ * Override the click handler. The default selects the slide via the
28
+ * editor store; pass a function here to add host behavior (e.g. open
29
+ * a context drawer instead of selecting).
30
+ */
31
+ onClick?: (slide: Slide) => void;
32
+ }
33
+
34
+ export function Item({
35
+ slide,
36
+ className,
37
+ style,
38
+ onClick,
39
+ children,
40
+ }: PropsWithChildren<SlideRailItemProps>) {
41
+ const slides = useEditor((s) => s.deck.slides);
42
+ const currentId = useEditor((s) => s.currentSlideId);
43
+ const selectSlide = useEditor((s) => s.selectSlide);
44
+ const index = slides.findIndex((s) => s.id === slide.id);
45
+ const isCurrent = slide.id === currentId;
46
+
47
+ return (
48
+ <SlideRailItemProvider value={{ slide, index, isCurrent }}>
49
+ <div
50
+ className={className}
51
+ onClick={() => (onClick ? onClick(slide) : selectSlide(slide.id))}
52
+ role="button"
53
+ tabIndex={0}
54
+ aria-current={isCurrent ? "true" : undefined}
55
+ aria-label={`Open slide ${index + 1}`}
56
+ onKeyDown={(e) => {
57
+ if (e.key === "Enter" || e.key === " ") {
58
+ e.preventDefault();
59
+ onClick ? onClick(slide) : selectSlide(slide.id);
60
+ }
61
+ }}
62
+ style={{
63
+ position: "relative",
64
+ padding: "0 12px",
65
+ marginBottom: 14,
66
+ cursor: "pointer",
67
+ background:
68
+ "var(--slidewise-bg-rail-item, transparent)",
69
+ ...(isCurrent
70
+ ? {
71
+ background:
72
+ "var(--slidewise-bg-rail-item-active, var(--accent-soft))",
73
+ }
74
+ : null),
75
+ ...style,
76
+ }}
77
+ >
78
+ {children}
79
+ </div>
80
+ </SlideRailItemProvider>
81
+ );
82
+ }
@@ -0,0 +1,42 @@
1
+ import { createContext, useContext } from "react";
2
+ import type { Slide } from "@/lib/types";
3
+
4
+ /**
5
+ * Context handed to descendants of `<SlideRail.Item>` so leaf subparts
6
+ * (`Thumbnail`, `Number`) and host content can read which slide they're
7
+ * rendering against without prop drilling.
8
+ */
9
+ export interface SlideRailItemContextValue {
10
+ slide: Slide;
11
+ /** Zero-based position in `deck.slides`. */
12
+ index: number;
13
+ /** True when this is the editor's currently-focused slide. */
14
+ isCurrent: boolean;
15
+ }
16
+
17
+ const ItemContext = createContext<SlideRailItemContextValue | null>(null);
18
+
19
+ export function SlideRailItemProvider({
20
+ value,
21
+ children,
22
+ }: {
23
+ value: SlideRailItemContextValue;
24
+ children: React.ReactNode;
25
+ }) {
26
+ return <ItemContext.Provider value={value}>{children}</ItemContext.Provider>;
27
+ }
28
+
29
+ /**
30
+ * Read the current item context. Throws when used outside a
31
+ * `<SlideRail.Item>` — the leaf subparts are meaningless without a
32
+ * concrete slide to render.
33
+ */
34
+ export function useSlideRailItem(): SlideRailItemContextValue {
35
+ const ctx = useContext(ItemContext);
36
+ if (!ctx) {
37
+ throw new Error(
38
+ "useSlideRailItem must be used inside <Slidewise.SlideRail.Item>"
39
+ );
40
+ }
41
+ return ctx;
42
+ }
@@ -0,0 +1,67 @@
1
+ import type { CSSProperties, ReactNode } from "react";
2
+ import { useEditor } from "@/lib/StoreProvider";
3
+ import type { Slide } from "@/lib/types";
4
+ import { Item } from "./Item";
5
+ import { Thumbnail } from "./Thumbnail";
6
+ import { Number as SlideNumber } from "./Number";
7
+
8
+ /**
9
+ * Iterates `deck.slides` and renders each one. Pass a render-prop child
10
+ * for full control over what each row contains; omit the child to get
11
+ * the default `<Item><Thumbnail /><Number /></Item>` layout.
12
+ *
13
+ * ```tsx
14
+ * // Default
15
+ * <Slidewise.SlideRail.List />
16
+ *
17
+ * // Custom — add a per-row context menu
18
+ * <Slidewise.SlideRail.List>
19
+ * {(slide) => (
20
+ * <Slidewise.SlideRail.Item slide={slide}>
21
+ * <Slidewise.SlideRail.Thumbnail />
22
+ * <Slidewise.SlideRail.Number />
23
+ * <MyContextMenu slide={slide} />
24
+ * </Slidewise.SlideRail.Item>
25
+ * )}
26
+ * </Slidewise.SlideRail.List>
27
+ * ```
28
+ */
29
+ export interface SlideRailListProps {
30
+ className?: string;
31
+ style?: CSSProperties;
32
+ /**
33
+ * Optional render-prop. Receives each slide + its zero-based index;
34
+ * return the row content. When omitted, the default row layout
35
+ * is used.
36
+ */
37
+ children?: (slide: Slide, index: number) => ReactNode;
38
+ }
39
+
40
+ export function List({ className, style, children }: SlideRailListProps) {
41
+ const slides = useEditor((s) => s.deck.slides);
42
+
43
+ return (
44
+ <div
45
+ className={className}
46
+ style={{
47
+ flex: 1,
48
+ overflowY: "auto",
49
+ padding: "12px 0",
50
+ ...style,
51
+ }}
52
+ >
53
+ {slides.map((slide, index) =>
54
+ children ? (
55
+ // Render-prop branch: host returns whatever they want, typically
56
+ // wrapping their JSX in a SlideRail.Item to wire selection.
57
+ <div key={slide.id}>{children(slide, index)}</div>
58
+ ) : (
59
+ <Item key={slide.id} slide={slide}>
60
+ <Thumbnail />
61
+ <SlideNumber />
62
+ </Item>
63
+ )
64
+ )}
65
+ </div>
66
+ );
67
+ }
@@ -0,0 +1,57 @@
1
+ import type { CSSProperties } from "react";
2
+ import { useSlideRailItem } from "./ItemContext";
3
+
4
+ /**
5
+ * Renders the slide's "01" / "02" badge in the top-left corner of the rail
6
+ * item. Reads the current slide's index from `<SlideRail.Item>`'s context.
7
+ *
8
+ * Render after `<SlideRail.Thumbnail>` so it stacks on top (or position
9
+ * it manually via `style`).
10
+ */
11
+ export interface SlideRailNumberProps {
12
+ className?: string;
13
+ style?: CSSProperties;
14
+ /**
15
+ * Format the displayed number. Default is zero-padded to width 2
16
+ * (`01`, `02`, …, `10`).
17
+ */
18
+ format?: (index: number) => string;
19
+ }
20
+
21
+ const defaultFormat = (i: number) => String(i + 1).padStart(2, "0");
22
+
23
+ export function Number({
24
+ className,
25
+ style,
26
+ format = defaultFormat,
27
+ }: SlideRailNumberProps = {}) {
28
+ const { index, isCurrent } = useSlideRailItem();
29
+
30
+ return (
31
+ <span
32
+ className={className}
33
+ aria-hidden="true"
34
+ style={{
35
+ position: "absolute",
36
+ left: 20,
37
+ top: 6,
38
+ zIndex: 2,
39
+ width: 22,
40
+ height: 22,
41
+ borderRadius: 5,
42
+ background: isCurrent ? "var(--ink)" : "#6B7280",
43
+ color: isCurrent ? "var(--app-bg)" : "#fff",
44
+ display: "flex",
45
+ alignItems: "center",
46
+ justifyContent: "center",
47
+ fontSize: 11,
48
+ fontWeight: 700,
49
+ fontFamily: "Inter, system-ui, sans-serif",
50
+ pointerEvents: "none",
51
+ ...style,
52
+ }}
53
+ >
54
+ {format(index)}
55
+ </span>
56
+ );
57
+ }
@@ -0,0 +1,54 @@
1
+ import type { CSSProperties, PropsWithChildren } from "react";
2
+
3
+ export const SLIDERAIL_DEFAULT_WIDTH = 168;
4
+
5
+ /**
6
+ * Container for the slide rail subparts. Owns the rail's width, surface
7
+ * color, and divider. Hosts replace this when they want a different rail
8
+ * geometry (wider, narrower, full-bleed, etc.) — otherwise just render
9
+ * subparts inside it.
10
+ *
11
+ * ```tsx
12
+ * <Slidewise.SlideRail.Root>
13
+ * <Slidewise.SlideRail.Header />
14
+ * <Slidewise.SlideRail.List />
15
+ * <Slidewise.SlideRail.AddButton />
16
+ * </Slidewise.SlideRail.Root>
17
+ * ```
18
+ */
19
+ export interface SlideRailRootProps {
20
+ className?: string;
21
+ style?: CSSProperties;
22
+ /** Rail width in pixels. Defaults to 168. */
23
+ width?: number | string;
24
+ }
25
+
26
+ export function Root({
27
+ className,
28
+ style,
29
+ width = SLIDERAIL_DEFAULT_WIDTH,
30
+ children,
31
+ }: PropsWithChildren<SlideRailRootProps>) {
32
+ return (
33
+ <div
34
+ className={
35
+ className ? `slidewise-rail ${className}` : "slidewise-rail"
36
+ }
37
+ style={{
38
+ width,
39
+ flexShrink: 0,
40
+ background: "var(--slidewise-bg-rail, var(--rail-bg))",
41
+ borderRight: "1px solid var(--border)",
42
+ boxShadow: "var(--rail-shadow)",
43
+ display: "flex",
44
+ flexDirection: "column",
45
+ fontFamily: "Inter, system-ui, sans-serif",
46
+ overflow: "hidden",
47
+ zIndex: 5,
48
+ ...style,
49
+ }}
50
+ >
51
+ {children}
52
+ </div>
53
+ );
54
+ }
@@ -0,0 +1,58 @@
1
+ import type { CSSProperties } from "react";
2
+ import { SlideView } from "@/components/editor/SlideView";
3
+ import { SLIDE_W } from "@/lib/types";
4
+ import { useSlideRailItem } from "./ItemContext";
5
+
6
+ const DEFAULT_THUMB_W = 132;
7
+
8
+ /**
9
+ * Renders the slide preview inside the rail item. Reads the current slide
10
+ * from `<SlideRail.Item>`'s context. Honors the focused/non-focused state
11
+ * via an accent border.
12
+ *
13
+ * ```tsx
14
+ * <Slidewise.SlideRail.Item slide={slide}>
15
+ * <Slidewise.SlideRail.Thumbnail />
16
+ * </Slidewise.SlideRail.Item>
17
+ * ```
18
+ */
19
+ export interface SlideRailThumbnailProps {
20
+ className?: string;
21
+ style?: CSSProperties;
22
+ /** Pixel width for the rendered thumbnail. Defaults to 132. */
23
+ width?: number;
24
+ }
25
+
26
+ export function Thumbnail({
27
+ className,
28
+ style,
29
+ width = DEFAULT_THUMB_W,
30
+ }: SlideRailThumbnailProps = {}) {
31
+ const { slide, isCurrent } = useSlideRailItem();
32
+ const scale = width / SLIDE_W;
33
+
34
+ return (
35
+ <div style={{ position: "relative" }}>
36
+ <div
37
+ className={className}
38
+ style={{
39
+ display: "block",
40
+ width,
41
+ border: isCurrent
42
+ ? "2px solid var(--slidewise-accent, var(--accent))"
43
+ : "2px solid transparent",
44
+ borderRadius: 8,
45
+ padding: 0,
46
+ background: "transparent",
47
+ overflow: "hidden",
48
+ transition: "border-color 120ms",
49
+ ...style,
50
+ }}
51
+ >
52
+ <div style={{ pointerEvents: "none" }}>
53
+ <SlideView slide={slide} scale={scale} />
54
+ </div>
55
+ </div>
56
+ </div>
57
+ );
58
+ }
@@ -0,0 +1,74 @@
1
+ import type { CSSProperties } from "react";
2
+ import { Root, type SlideRailRootProps } from "./Root";
3
+ import { Header, type SlideRailHeaderProps } from "./Header";
4
+ import { List, type SlideRailListProps } from "./List";
5
+ import { Item, type SlideRailItemProps } from "./Item";
6
+ import { Thumbnail, type SlideRailThumbnailProps } from "./Thumbnail";
7
+ import { Number, type SlideRailNumberProps } from "./Number";
8
+ import { AddButton, type SlideRailAddButtonProps } from "./AddButton";
9
+
10
+ export interface SlideRailProps {
11
+ className?: string;
12
+ style?: CSSProperties;
13
+ /** Rail width; forwarded to `<SlideRail.Root>`. */
14
+ width?: number | string;
15
+ /** Omit the header. */
16
+ hideHeader?: boolean;
17
+ /** Omit the "New Slide" button. */
18
+ hideAddButton?: boolean;
19
+ }
20
+
21
+ /**
22
+ * Default SlideRail arrangement. Equivalent to:
23
+ *
24
+ * ```tsx
25
+ * <Slidewise.SlideRail.Root>
26
+ * <Slidewise.SlideRail.Header />
27
+ * <Slidewise.SlideRail.List />
28
+ * <Slidewise.SlideRail.AddButton />
29
+ * </Slidewise.SlideRail.Root>
30
+ * ```
31
+ *
32
+ * For full control (per-row context menus, custom thumbnail layout,
33
+ * etc.), drop down to the subparts directly.
34
+ */
35
+ function DefaultSlideRail({
36
+ className,
37
+ style,
38
+ width,
39
+ hideHeader,
40
+ hideAddButton,
41
+ }: SlideRailProps = {}) {
42
+ return (
43
+ <Root className={className} style={style} width={width}>
44
+ {!hideHeader && <Header />}
45
+ <List />
46
+ {!hideAddButton && <AddButton />}
47
+ </Root>
48
+ );
49
+ }
50
+
51
+ /**
52
+ * `<Slidewise.SlideRail />` is both the default arrangement and a
53
+ * namespace of subparts. Mirrors `<Slidewise.TopBar>`.
54
+ */
55
+ export const SlideRail = Object.assign(DefaultSlideRail, {
56
+ Root,
57
+ Header,
58
+ List,
59
+ Item,
60
+ Thumbnail,
61
+ Number,
62
+ AddButton,
63
+ });
64
+
65
+ export { useSlideRailItem, type SlideRailItemContextValue } from "./ItemContext";
66
+ export type {
67
+ SlideRailRootProps,
68
+ SlideRailHeaderProps,
69
+ SlideRailListProps,
70
+ SlideRailItemProps,
71
+ SlideRailThumbnailProps,
72
+ SlideRailNumberProps,
73
+ SlideRailAddButtonProps,
74
+ };
package/src/index.ts CHANGED
@@ -48,6 +48,9 @@ export {
48
48
  useDirty,
49
49
  useLabels,
50
50
  useSurfaces,
51
+ useCanvasConfig,
52
+ resolveSlideBackground,
53
+ DEFAULT_CANVAS_CONFIG,
51
54
  useEditor,
52
55
  useEditorStore,
53
56
  useSlides,
@@ -67,10 +70,22 @@ export {
67
70
  type SlidewiseIcons,
68
71
  type SlidewiseLabels,
69
72
  type SlidewiseSurfaces,
73
+ type SlidewiseCanvasConfig,
70
74
  type ResolvedLabels,
75
+ type ResolvedCanvasConfig,
76
+ useSlideRailItem,
71
77
  type RegionProps,
72
78
  type TopBarProps,
73
79
  type TopBarSlotId,
80
+ type SlideRailProps,
81
+ type SlideRailRootProps,
82
+ type SlideRailHeaderProps,
83
+ type SlideRailListProps,
84
+ type SlideRailItemProps,
85
+ type SlideRailThumbnailProps,
86
+ type SlideRailNumberProps,
87
+ type SlideRailAddButtonProps,
88
+ type SlideRailItemContextValue,
74
89
  } from "./compound";
75
90
 
76
91
  export { parsePptx, serializeDeck } from "./lib/pptx";