sanity-plugin-studio-scene 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +74 -2
- package/dist/PlacementInput.d.ts +9 -0
- package/dist/PlacementInput.js +244 -0
- package/dist/SceneInput.d.ts +6 -0
- package/dist/SceneInput.js +144 -0
- package/dist/ScenePreview.d.ts +40 -0
- package/dist/ScenePreview.js +211 -0
- package/dist/groq.d.ts +9 -0
- package/dist/groq.js +26 -0
- package/dist/importExport.d.ts +52 -0
- package/dist/importExport.js +60 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +29 -0
- package/dist/merge.d.ts +59 -0
- package/dist/merge.js +68 -0
- package/dist/options.d.ts +60 -0
- package/dist/options.js +49 -0
- package/dist/runtime/scroll-scene.js +16739 -0
- package/dist/schema/motion.d.ts +20 -0
- package/dist/schema/motion.js +63 -0
- package/dist/schema/placement.d.ts +30 -0
- package/dist/schema/placement.js +96 -0
- package/dist/schema/scene.d.ts +43 -0
- package/dist/schema/scene.js +104 -0
- package/dist/schema/style.d.ts +11 -0
- package/dist/schema/style.js +75 -0
- package/dist/styleTokens.d.ts +131 -0
- package/dist/styleTokens.js +207 -0
- package/dist/unzip.d.ts +25 -0
- package/dist/unzip.js +114 -0
- package/dist/useScene.d.ts +21 -0
- package/dist/useScene.js +37 -0
- package/package.json +27 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Create the Box, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sanity-plugin-studio-scene
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Put [Create the Box STUDIO](https://studio.createthebox.com) scroll scenes on Sanity pages.
|
|
4
|
+
|
|
5
|
+
- **A scene library.** Drop the `scroll-scene.zip` that STUDIO exports onto a `studioScene` document. The files
|
|
6
|
+
it needs become Sanity assets, and the zip is checked (size limits, only the files a page loads).
|
|
7
|
+
- **Placements.** Add a `studioScenePlacement` to any page or page builder: pick a scene, pick a shot on the
|
|
8
|
+
strip, and write the content for it. Text on a shot makes the camera pause there while the text scrolls past.
|
|
9
|
+
- **A live preview** of the scene with your content, using the same player the page uses.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install sanity-plugin-studio-scene
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// sanity.config.ts
|
|
19
|
+
import { defineConfig } from 'sanity'
|
|
20
|
+
import { studioScene } from 'sanity-plugin-studio-scene'
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
// …
|
|
24
|
+
plugins: [
|
|
25
|
+
studioScene({
|
|
26
|
+
// What editors can put on a shot: your own block types. Default: rich text.
|
|
27
|
+
stopContent: [{ type: 'block' }],
|
|
28
|
+
placementTitle: 'Scroll scene',
|
|
29
|
+
styles: {
|
|
30
|
+
colors: [{ title: 'Brand', value: 'var(--brand)', preview: '#4370f7' }],
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then add the placement wherever pages are built:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
defineField({
|
|
41
|
+
name: 'sections',
|
|
42
|
+
type: 'array',
|
|
43
|
+
of: [defineArrayMember({ type: 'studioScenePlacement' }) /* , your other blocks */],
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Options
|
|
48
|
+
|
|
49
|
+
| Option | What it does |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `stopContent` | Block types editors can put on a shot. Default: rich text. |
|
|
52
|
+
| `styles.colors` | Swatches for the colour controls (any CSS colour, including `var(--token)` with a `preview`). |
|
|
53
|
+
| `styles.paletteOnly` | Only allow the swatches. Default `false`. |
|
|
54
|
+
| `styles.controls` | Which style controls "Customise" shows. Default: all (`STYLE_CONTROLS`). |
|
|
55
|
+
| `styles.presets` | One-click looks. Default: Dark card, Light card, Outline, Text only. |
|
|
56
|
+
| `placementTitle` | What editors see the placement called. Default "Scroll scene". |
|
|
57
|
+
| `runtimeUrl` | URL of `scroll-scene.js` for the preview. Default: the copy bundled with the plugin. |
|
|
58
|
+
|
|
59
|
+
## On your site
|
|
60
|
+
|
|
61
|
+
Query a placement with the projection the plugin exports, then render it with the
|
|
62
|
+
[`@createthebox/scroll-scene`](https://www.npmjs.com/package/@createthebox/scroll-scene) element:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { studioScenePlacementProjection } from 'sanity-plugin-studio-scene/groq'
|
|
66
|
+
import { styleVars, motionVars, MOTION_CSS } from 'sanity-plugin-studio-scene/style'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`sanity-plugin-studio-scene/groq` and `/style` don't import Sanity or React, so a frontend can use them.
|
|
70
|
+
`styleVars` and `motionVars` turn a slot's style and motion into the CSS variables the content reads, and
|
|
71
|
+
`MOTION_CSS` is the stylesheet that animates shot content in step with the camera.
|
|
72
|
+
|
|
73
|
+
## Licence
|
|
74
|
+
|
|
75
|
+
MIT © Create the Box, LLC
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ObjectInputProps } from "sanity";
|
|
2
|
+
import { type ResolvedOptions } from "./options";
|
|
3
|
+
/**
|
|
4
|
+
* A scene placed on a page, on one screen: pick the scene (or upload one), see it live, pick a shot on the
|
|
5
|
+
* strip and edit its content right below: one or more groups of blocks, each with a position, a look, motion
|
|
6
|
+
* and optionally a 3D point to follow. Content on a shot makes the camera stop there while it scrolls past;
|
|
7
|
+
* shots without content are passed through.
|
|
8
|
+
*/
|
|
9
|
+
export declare function placementInput(opts: ResolvedOptions): (props: ObjectInputProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Button, Card, Flex, Select, Spinner, Stack, Switch, Text } from "@sanity/ui";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { FormInput, IntentButton, insert, set, setIfMissing, unset, useClient, useFormCallbacks, } from "sanity";
|
|
5
|
+
import { hasContent, moveSlot } from "./merge";
|
|
6
|
+
import { API_VERSION, T } from "./options";
|
|
7
|
+
import { PreviewBlocks, ScenePreview } from "./ScenePreview";
|
|
8
|
+
import { mb, readExport, titleFrom, uploadExport } from "./importExport";
|
|
9
|
+
import { MOTION_DEFAULTS, mergeMotion, mergeStyle } from "./styleTokens";
|
|
10
|
+
import { ENTER_OPTIONS, EXIT_OPTIONS } from "./schema/motion";
|
|
11
|
+
import { useScene } from "./useScene";
|
|
12
|
+
const PRESET_KEYS = ["card", "cardColor", "textColor", "cardOpacity", "blur"];
|
|
13
|
+
const LENGTHS = [
|
|
14
|
+
{ title: "Auto", value: "auto" },
|
|
15
|
+
{ title: "Short", value: "short" },
|
|
16
|
+
{ title: "Medium", value: "medium" },
|
|
17
|
+
{ title: "Long", value: "long" },
|
|
18
|
+
];
|
|
19
|
+
const TIMINGS = [
|
|
20
|
+
{ title: "Before the camera arrives", value: "early" },
|
|
21
|
+
{ title: "As it arrives", value: "with" },
|
|
22
|
+
{ title: "Once it stops", value: "late" },
|
|
23
|
+
];
|
|
24
|
+
const MODES = [
|
|
25
|
+
{ title: "Follows the scroll", value: "scrub" },
|
|
26
|
+
{ title: "By itself", value: "play" },
|
|
27
|
+
];
|
|
28
|
+
const STRENGTHS = [
|
|
29
|
+
{ title: "Subtle", value: "small" },
|
|
30
|
+
{ title: "Medium", value: "medium" },
|
|
31
|
+
{ title: "Bold", value: "large" },
|
|
32
|
+
];
|
|
33
|
+
const DRIFTS = [
|
|
34
|
+
{ title: "None", value: "none" },
|
|
35
|
+
{ title: "Subtle", value: "subtle" },
|
|
36
|
+
{ title: "Strong", value: "strong" },
|
|
37
|
+
];
|
|
38
|
+
const FLOWS = [
|
|
39
|
+
{ title: "Stays on screen", value: "hold" },
|
|
40
|
+
{ title: "Scrolls past", value: "scroll" },
|
|
41
|
+
];
|
|
42
|
+
const LINES = [
|
|
43
|
+
{ title: "Short", value: "short" },
|
|
44
|
+
{ title: "Medium", value: "medium" },
|
|
45
|
+
{ title: "Long", value: "long" },
|
|
46
|
+
];
|
|
47
|
+
const AXIS = ["start", "center", "end"];
|
|
48
|
+
const IN_WORDS = { fade: "fades in", up: "rises in from below", down: "drops in from above", left: "slides in from the left", right: "slides in from the right", scale: "zooms in", blur: "blurs in", none: "appears" };
|
|
49
|
+
const OUT_WORDS = { reverse: "leaves the way it came", fade: "fades out", up: "leaves upwards", down: "leaves downwards", left: "leaves to the left", right: "leaves to the right", scale: "zooms out", blur: "blurs out", none: "disappears" };
|
|
50
|
+
/** "Slides in from the left, leaves the way it came, with the scroll" */
|
|
51
|
+
function describeMotion(m) {
|
|
52
|
+
const parts = [IN_WORDS[m.enter ?? "fade"], OUT_WORDS[m.exit ?? "reverse"], m.mode === "play" ? "by itself" : "with the scroll"];
|
|
53
|
+
if (m.distance === "small")
|
|
54
|
+
parts.push("subtle");
|
|
55
|
+
if (m.distance === "large")
|
|
56
|
+
parts.push("bold");
|
|
57
|
+
if (m.flow === "scroll")
|
|
58
|
+
parts.push("scrolls past");
|
|
59
|
+
const s = parts.join(", ");
|
|
60
|
+
return s[0].toUpperCase() + s.slice(1);
|
|
61
|
+
}
|
|
62
|
+
const ownKeys = (o) => Object.entries(o ?? {}).some(([k, v]) => !k.startsWith("_") && v !== undefined && v !== null && v !== "");
|
|
63
|
+
/** A motion with every field filled (for showing and for copying into a level that starts its own). */
|
|
64
|
+
const fullMotion = (...layers) => mergeMotion(MOTION_DEFAULTS, ...layers);
|
|
65
|
+
/** Which preset a style matches (every key the preset sets, and nothing else among the preset keys). */
|
|
66
|
+
function presetOf(style, presets) {
|
|
67
|
+
for (const p of presets) {
|
|
68
|
+
if (PRESET_KEYS.every((k) => (p.style[k] ?? undefined) === (style?.[k] ?? undefined)))
|
|
69
|
+
return p.title;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const hasOwnPreset = (s) => PRESET_KEYS.some((k) => s?.[k] !== undefined && s?.[k] !== null);
|
|
74
|
+
/**
|
|
75
|
+
* One row of choices. The inherit button (when given) clears the field so it uses the level above; without one,
|
|
76
|
+
* `fallback` is what shows as chosen while the field is empty (the default that applies).
|
|
77
|
+
*/
|
|
78
|
+
function Choice(props) {
|
|
79
|
+
const cur = props.value || (props.inherit ? null : props.fallback);
|
|
80
|
+
return (_jsxs(Stack, { gap: 2, children: [_jsx(Text, { size: 1, weight: "medium", children: props.label }), _jsxs(Flex, { gap: 1, wrap: "wrap", children: [props.inherit ? (_jsx(Button, { text: props.inherit, fontSize: 1, padding: 2, mode: !cur ? "default" : "ghost", tone: !cur ? "primary" : "default", disabled: props.readOnly, onClick: () => props.onPick(null) })) : null, props.options.map((o) => (_jsx(Button, { text: o.title, fontSize: 1, padding: 2, mode: cur === o.value ? "default" : "ghost", tone: cur === o.value ? "primary" : "default", disabled: props.readOnly, onClick: () => props.onPick(o.value) }, o.value)))] })] }));
|
|
81
|
+
}
|
|
82
|
+
/** Where content sits over the shot: a 3 × 3 grid (left/centre/right × top/middle/bottom). */
|
|
83
|
+
function PositionGrid(props) {
|
|
84
|
+
const own = !!(props.style.align || props.style.verticalAlign);
|
|
85
|
+
return (_jsxs(Stack, { gap: 2, children: [_jsx(Text, { size: 1, weight: "medium", children: props.label ?? "Position" }), props.hint ? _jsx(Text, { size: 1, muted: true, children: props.hint }) : null, _jsxs(Flex, { gap: 3, align: "center", children: [_jsx("div", { style: { display: "grid", gridTemplateColumns: "repeat(3, 28px)", gap: 4 }, children: AXIS.map((v) => AXIS.map((h) => {
|
|
86
|
+
const on = (props.style.align ?? "") === h && (props.style.verticalAlign ?? "") === v;
|
|
87
|
+
return (_jsx("button", { type: "button", disabled: props.readOnly, title: `${v === "start" ? "Top" : v === "center" ? "Middle" : "Bottom"} ${h === "start" ? "left" : h === "center" ? "centre" : "right"}`, onClick: () => props.onPick({ align: h, verticalAlign: v }), style: { width: 28, height: 20, borderRadius: 4, border: "1px solid rgba(127,127,127,.45)", background: on ? "#2276fc" : "transparent", cursor: "pointer" } }, `${v}-${h}`));
|
|
88
|
+
})) }), _jsx(Button, { text: props.inherit, fontSize: 1, padding: 2, mode: !own ? "default" : "ghost", tone: !own ? "primary" : "default", disabled: props.readOnly, onClick: () => props.onPick({ align: null, verticalAlign: null }) })] })] }));
|
|
89
|
+
}
|
|
90
|
+
/** The animation of content over its shot: in, out, strength, how it plays; the rest under More. */
|
|
91
|
+
function MotionEditor(props) {
|
|
92
|
+
const m = props.motion;
|
|
93
|
+
const [more, setMore] = useState(false);
|
|
94
|
+
const ro = props.readOnly;
|
|
95
|
+
return (_jsxs(Stack, { gap: 4, children: [_jsx(Choice, { label: "In", options: ENTER_OPTIONS, value: m.enter, fallback: "fade", readOnly: ro, onPick: (v) => props.onSet({ enter: v }) }), _jsx(Choice, { label: "Out", options: EXIT_OPTIONS, value: m.exit, fallback: "reverse", readOnly: ro, onPick: (v) => props.onSet({ exit: v }) }), _jsxs(Flex, { gap: 5, wrap: "wrap", children: [_jsx(Choice, { label: "Strength", options: STRENGTHS, value: m.distance, fallback: "medium", readOnly: ro, onPick: (v) => props.onSet({ distance: v }) }), _jsx(Choice, { label: "Plays", options: MODES, value: m.mode, fallback: "scrub", readOnly: ro, onPick: (v) => props.onSet({ mode: v }) })] }), _jsx(Box, { children: _jsx(Button, { text: more ? "Fewer options" : "More options…", mode: "bleed", fontSize: 1, padding: 2, onClick: () => setMore(!more) }) }), more ? (_jsxs(Stack, { gap: 4, children: [_jsx(Choice, { label: "Starts", options: TIMINGS, value: m.timing, fallback: "with", readOnly: ro, onPick: (v) => props.onSet({ timing: v }) }), _jsx(Choice, { label: "Drift while the camera holds", options: DRIFTS, value: m.parallax, fallback: "none", readOnly: ro, onPick: (v) => props.onSet({ parallax: v }) }), props.pinned ? null : _jsx(Choice, { label: "Content", options: FLOWS, value: m.flow, fallback: "hold", readOnly: ro, onPick: (v) => props.onSet({ flow: v }) }), _jsxs(Flex, { gap: 2, align: "center", children: [_jsx(Switch, { checked: !!m.stagger, disabled: ro, onChange: (e) => props.onSet({ stagger: e.currentTarget.checked }) }), _jsx(Text, { size: 1, children: "One block at a time" })] })] })) : null] }));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A setting that a shot (or group) takes from the level above until it's made its own: "Same as page" shows
|
|
99
|
+
* what it inherits in words; "Custom" shows the controls, starting from those same values.
|
|
100
|
+
*/
|
|
101
|
+
function Inherit(props) {
|
|
102
|
+
return (_jsx(Card, { padding: 3, radius: 2, border: true, tone: "transparent", children: _jsxs(Stack, { gap: 4, children: [_jsxs(Flex, { gap: 3, align: "center", wrap: "wrap", children: [_jsx(Box, { flex: 1, children: _jsx(Text, { size: 1, weight: "semibold", children: props.title }) }), _jsxs(Flex, { gap: 1, children: [_jsx(Button, { text: `Same as ${props.parent}`, fontSize: 1, padding: 2, mode: !props.own ? "default" : "ghost", tone: !props.own ? "primary" : "default", disabled: props.readOnly, onClick: props.onInherit }), _jsx(Button, { text: "Custom", fontSize: 1, padding: 2, mode: props.own ? "default" : "ghost", tone: props.own ? "primary" : "default", disabled: props.readOnly, onClick: props.onOwn })] })] }), props.own ? props.children : _jsx(Text, { size: 1, muted: true, children: props.summary })] }) }));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A scene placed on a page, on one screen: pick the scene (or upload one), see it live, pick a shot on the
|
|
106
|
+
* strip and edit its content right below: one or more groups of blocks, each with a position, a look, motion
|
|
107
|
+
* and optionally a 3D point to follow. Content on a shot makes the camera stop there while it scrolls past;
|
|
108
|
+
* shots without content are passed through.
|
|
109
|
+
*/
|
|
110
|
+
export function placementInput(opts) {
|
|
111
|
+
return function PlacementInput(props) {
|
|
112
|
+
const { onChange, readOnly, path } = props;
|
|
113
|
+
const value = (props.value ?? {});
|
|
114
|
+
const { scene, loading } = useScene(value.scene?._ref);
|
|
115
|
+
const { onPathOpen } = useFormCallbacks();
|
|
116
|
+
const client = useClient({ apiVersion: API_VERSION });
|
|
117
|
+
const [selected, setSelected] = useState(null);
|
|
118
|
+
const [groupKey, setGroupKey] = useState("main");
|
|
119
|
+
const [custom, setCustom] = useState(null);
|
|
120
|
+
const [upload, setUpload] = useState(null);
|
|
121
|
+
const fileInput = useRef(null);
|
|
122
|
+
const slots = value.slots ?? [];
|
|
123
|
+
const byKey = useMemo(() => new Map(slots.map((s) => [s._key, s])), [slots]);
|
|
124
|
+
const stops = scene?.stops ?? [];
|
|
125
|
+
const points = scene?.points ?? [];
|
|
126
|
+
const stopIds = new Set(stops.map((s) => s._key));
|
|
127
|
+
const orphans = slots.filter((s) => !stopIds.has(s._key) && blockCount(s) > 0);
|
|
128
|
+
const current = stops.find((s) => s._key === selected) ?? stops[0] ?? null;
|
|
129
|
+
const index = current ? stops.indexOf(current) : -1;
|
|
130
|
+
const slot = current ? byKey.get(current._key) : undefined;
|
|
131
|
+
const slotPath = slot ? ["slots", { _key: slot._key }] : null;
|
|
132
|
+
const extra = slot?.groups ?? [];
|
|
133
|
+
const group = groupKey === "main" ? slot : extra.find((g) => g._key === groupKey);
|
|
134
|
+
const groupPath = slotPath && group ? (groupKey === "main" ? slotPath : [...slotPath, "groups", { _key: groupKey }]) : null;
|
|
135
|
+
// A shot change starts on its main group.
|
|
136
|
+
useEffect(() => { setGroupKey("main"); setCustom((c) => (c === "group" ? null : c)); }, [current?._key]);
|
|
137
|
+
// Open the selected group in the form state, so its fields render inline below (no dialog).
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (groupPath)
|
|
140
|
+
onPathOpen([...path, ...groupPath]);
|
|
141
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
142
|
+
}, [slot?._key, groupKey, !!group]);
|
|
143
|
+
const patch = (p) => onChange([setIfMissing({ _type: T.placement }), ...p]);
|
|
144
|
+
const addContent = (key) => patch([setIfMissing([], ["slots"]), insert([{ _type: T.slot, _key: key, content: [] }], "after", ["slots", -1])]);
|
|
145
|
+
const addGroup = () => {
|
|
146
|
+
if (!slotPath)
|
|
147
|
+
return;
|
|
148
|
+
const k = Math.random().toString(36).slice(2, 10);
|
|
149
|
+
patch([setIfMissing([], [...slotPath, "groups"]), insert([{ _type: T.group, _key: k, content: [] }], "after", [...slotPath, "groups", -1])]);
|
|
150
|
+
setGroupKey(k);
|
|
151
|
+
};
|
|
152
|
+
const setFields = (base, type, changes) => patch([
|
|
153
|
+
setIfMissing({ _type: type }, base),
|
|
154
|
+
...Object.entries(changes).map(([k, v]) => (v === undefined || v === null ? unset([...base, k]) : set(v, [...base, k]))),
|
|
155
|
+
]);
|
|
156
|
+
const applyPreset = (base, p) => setFields(base, T.style, Object.fromEntries(PRESET_KEYS.map((k) => [k, p?.style[k]])));
|
|
157
|
+
const uploadNew = async (file) => {
|
|
158
|
+
setUpload({ tone: "default", text: `Reading ${file.name}…`, busy: true });
|
|
159
|
+
try {
|
|
160
|
+
const r = await readExport(file);
|
|
161
|
+
const up = await uploadExport(client, r, (text) => setUpload({ tone: "default", text, busy: true }));
|
|
162
|
+
const doc = await client.create({
|
|
163
|
+
_type: T.scene,
|
|
164
|
+
title: titleFrom(file.name),
|
|
165
|
+
files: up.files,
|
|
166
|
+
stops: up.stops,
|
|
167
|
+
points: up.points,
|
|
168
|
+
export: { _type: T.sceneExport, ...up.meta },
|
|
169
|
+
source: { kind: "zip" },
|
|
170
|
+
});
|
|
171
|
+
patch([set({ _type: "reference", _ref: doc._id }, ["scene"])]);
|
|
172
|
+
setSelected(null);
|
|
173
|
+
setUpload({ tone: "positive", text: `Added "${doc.title}" to Scroll scenes (${up.stops.length} shots, ${mb(r.bytes)}).` });
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
setUpload({ tone: "critical", text: err instanceof Error ? err.message : String(err) });
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
// What the preview draws: every group of the selected shot, styled and moving as on the page.
|
|
180
|
+
const pageStyle = value.style ?? {};
|
|
181
|
+
const pageMotion = mergeMotion(value.motion);
|
|
182
|
+
const previewGroups = slot
|
|
183
|
+
? [{ key: "main", ...slot }, ...extra.map((g) => ({ ...g, key: g._key }))]
|
|
184
|
+
.filter((g) => (g.content?.length ?? 0) > 0)
|
|
185
|
+
.map((g) => ({
|
|
186
|
+
key: g.key,
|
|
187
|
+
style: previewColors(mergeStyle(mergeStyle(pageStyle, slot.style), g.key === "main" ? undefined : g.style), opts),
|
|
188
|
+
motion: mergeMotion(pageMotion, slot.motion, g.key === "main" ? undefined : g.motion),
|
|
189
|
+
pin: g.pin,
|
|
190
|
+
line: g.line,
|
|
191
|
+
ownStyle: g.key === "main" ? slot.style : g.style,
|
|
192
|
+
selected: g.key === groupKey,
|
|
193
|
+
blocks: (g.content ?? []).map((b, i) => _jsx(PreviewBlocks, { blocks: [b] }, i)),
|
|
194
|
+
}))
|
|
195
|
+
: [];
|
|
196
|
+
let body = null;
|
|
197
|
+
if (!value.scene?._ref) {
|
|
198
|
+
body = _jsx(Text, { size: 1, muted: true, children: "Pick a scene above, or upload a STUDIO export. Then pick a shot and add the blocks that appear over it." });
|
|
199
|
+
}
|
|
200
|
+
else if (loading && !scene) {
|
|
201
|
+
body = _jsx(Flex, { padding: 4, justify: "center", children: _jsx(Spinner, { muted: true }) });
|
|
202
|
+
}
|
|
203
|
+
else if (!scene) {
|
|
204
|
+
body = _jsx(Card, { padding: 3, radius: 2, tone: "critical", children: _jsx(Text, { size: 1, children: "This scene can't be found. Was it deleted?" }) });
|
|
205
|
+
}
|
|
206
|
+
else if (!stops.length) {
|
|
207
|
+
body = _jsx(Card, { padding: 3, radius: 2, tone: "caution", children: _jsx(Text, { size: 1, children: "This scene has no shots. Add camera shots in STUDIO, export again and replace the export on the scene." }) });
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const isMain = groupKey === "main";
|
|
211
|
+
const gStyle = group?.style ?? {};
|
|
212
|
+
const gMotion = group?.motion ?? {};
|
|
213
|
+
// A pinned card's side of its point: only its own position counts (see pinVars).
|
|
214
|
+
const ownPos = { align: group?.style?.align, verticalAlign: group?.style?.verticalAlign };
|
|
215
|
+
const inherit = isMain ? "Page default" : "Same as main";
|
|
216
|
+
// Animation and look: each level takes the one above until it's made Custom.
|
|
217
|
+
const pageM = fullMotion(value.motion);
|
|
218
|
+
const parentM = isMain ? pageM : mergeMotion(pageM, slot?.motion);
|
|
219
|
+
const groupM = mergeMotion(parentM, group?.motion);
|
|
220
|
+
const parentLabel = isMain ? "page" : "main group";
|
|
221
|
+
const parentStyle = isMain ? pageStyle : mergeStyle(pageStyle, slot?.style);
|
|
222
|
+
const parentLook = presetOf(parentStyle, opts.presets) ?? (hasOwnPreset(parentStyle) ? "custom colours" : "the site's default look");
|
|
223
|
+
body = (_jsxs(Stack, { gap: 4, children: [scene.hasDraft ? (_jsx(Card, { padding: 3, radius: 2, tone: "caution", border: true, children: _jsxs(Flex, { gap: 3, align: "center", wrap: "wrap", children: [_jsx(Box, { style: { flex: 1, minWidth: 200 }, children: _jsx(Text, { size: 1, children: "This scene has a newer export that isn't published. The live site uses the published one until you publish the scene." }) }), _jsx(IntentButton, { intent: "edit", params: { id: scene._id.replace(/^drafts\./, ""), type: T.scene }, text: "Open scene", mode: "ghost" })] }) })) : null, _jsx(ScenePreview, { files: scene.files, runtimeUrl: opts.runtimeUrl, focus: current?.slug, groups: previewGroups, replay: `${current?._key}:${groupKey}:${JSON.stringify(groupM)}`, onPick: (slug) => setSelected(stops.find((s) => s.slug === slug)?._key ?? null) }), _jsx(Flex, { gap: 2, style: { overflowX: "auto", paddingBottom: 4 }, children: stops.map((s, i) => {
|
|
224
|
+
const n = blockCount(byKey.get(s._key));
|
|
225
|
+
const on = s._key === current?._key;
|
|
226
|
+
return (_jsxs(Card, { as: "button", type: "button", radius: 2, border: true, tone: on ? "primary" : "default", onClick: () => setSelected(s._key), style: { flex: "none", width: 148, padding: 0, overflow: "hidden", textAlign: "left", cursor: "pointer", outline: on ? "2px solid var(--card-focus-ring-color, #2276fc)" : undefined }, children: [_jsx("div", { style: { aspectRatio: "16 / 9", background: "#111" }, children: s.thumbUrl ? _jsx("img", { src: s.thumbUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover", display: "block" } }) : null }), _jsxs(Stack, { gap: 2, padding: 2, children: [_jsxs(Text, { size: 1, weight: "semibold", textOverflow: "ellipsis", children: [i + 1, ". ", s.label] }), _jsx(Text, { size: 0, muted: true, children: n ? `${n} block${n > 1 ? "s" : ""}` : "Empty" })] })] }, s._key));
|
|
227
|
+
}) }), current ? (_jsx(Card, { padding: 4, radius: 3, border: true, children: _jsxs(Stack, { gap: 4, children: [_jsxs(Stack, { gap: 2, children: [_jsxs(Text, { size: 2, weight: "semibold", children: ["Shot ", index + 1, ": ", current.label] }), _jsx(Text, { size: 1, muted: true, children: "Content here stops the camera on this shot. It stays on screen while the shot is on (Stop length sets how long), or scrolls past if you choose that (then its length sets it). Without content, the camera moves straight through." })] }), slot && slotPath ? (_jsxs(_Fragment, { children: [_jsxs(Flex, { gap: 1, wrap: "wrap", align: "center", children: [[{ key: "main", label: "Main" }, ...extra.map((g, i) => ({ key: g._key, label: `Group ${i + 2}` }))].map((g) => (_jsx(Button, { text: g.label, fontSize: 1, padding: 2, mode: groupKey === g.key ? "default" : "ghost", tone: groupKey === g.key ? "primary" : "default", onClick: () => setGroupKey(g.key) }, g.key))), _jsx(Button, { text: "+ Add group", fontSize: 1, padding: 2, mode: "bleed", disabled: readOnly, onClick: addGroup })] }), group && groupPath ? (_jsxs(_Fragment, { children: [_jsx(FormInput, { ...props, relativePath: [...groupPath, "content"], includeField: true }), points.length ? (_jsxs(Stack, { gap: 2, children: [_jsx(Text, { size: 1, weight: "medium", children: "Pin to a 3D point" }), _jsxs(Select, { fontSize: 1, disabled: readOnly, value: group.pin ?? "", onChange: (e) => setFields(groupPath, isMain ? T.slot : T.group, { pin: e.currentTarget.value || null }), children: [_jsx("option", { value: "", children: "Not pinned: placed by position" }), points.map((p) => _jsx("option", { value: p.slug, children: p.name }, p.slug))] })] })) : null, group.pin ? (_jsxs(_Fragment, { children: [_jsx(Choice, { label: "Line to the point", inherit: "No line", options: LINES, value: group.line, readOnly: readOnly, onPick: (v) => setFields(groupPath, isMain ? T.slot : T.group, { line: v }) }), _jsx(PositionGrid, { label: "Card sits", hint: group.line ? "Which side of the point the card sits, at the end of its line." : "Which side of the point the card sits. Centre: right over it.", style: ownPos, inherit: "Above", readOnly: readOnly, onPick: (v) => setFields([...groupPath, "style"], T.style, v) })] })) : (_jsx(PositionGrid, { style: gStyle, inherit: inherit, readOnly: readOnly, onPick: (v) => setFields([...groupPath, "style"], T.style, v) })), _jsxs(Inherit, { title: "Look", parent: parentLabel, summary: `Uses the ${parentLabel}'s look: ${parentLook}.`, own: hasOwnPreset(gStyle), readOnly: readOnly, onOwn: () => applyPreset([...groupPath, "style"], opts.presets.find((p) => p.title === presetOf(parentStyle, opts.presets)) ?? opts.presets[0]), onInherit: () => applyPreset([...groupPath, "style"], null), children: [_jsx(Choice, { label: "Card", options: opts.presets.map((p) => ({ title: p.title, value: p.title })), value: presetOf(gStyle, opts.presets), readOnly: readOnly, onPick: (v) => v && applyPreset([...groupPath, "style"], opts.presets.find((p) => p.title === v)) }), _jsx(Box, { children: _jsx(Button, { text: custom === "group" ? "Hide colours and sizes" : "Colours and sizes…", mode: "bleed", fontSize: 1, padding: 2, onClick: () => setCustom(custom === "group" ? null : "group") }) }), custom === "group" ? _jsx(FormInput, { ...props, relativePath: [...groupPath, "style"], includeField: true }) : null] }), _jsx(Inherit, { title: "Animation", parent: parentLabel, summary: `${describeMotion(parentM)}.`, own: ownKeys(group.motion), readOnly: readOnly, onOwn: () => setFields([...groupPath, "motion"], T.motion, parentM), onInherit: () => patch([unset([...groupPath, "motion"])]), children: _jsx(MotionEditor, { motion: groupM, pinned: !!group.pin, readOnly: readOnly, onSet: (c) => setFields([...groupPath, "motion"], T.motion, c) }) }), isMain ? _jsx(Choice, { label: "Stop length", options: LENGTHS, value: gStyle.pause ?? "auto", readOnly: readOnly, onPick: (v) => setFields([...groupPath, "style"], T.style, { pause: v === "auto" ? null : v }) }) : null, _jsx(Flex, { gap: 2, wrap: "wrap", children: isMain ? (_jsx(Button, { text: "Remove all content on this shot", mode: "bleed", tone: "critical", fontSize: 1, disabled: readOnly, onClick: () => patch([unset(["slots", { _key: slot._key }])]) })) : (_jsx(Button, { text: "Remove this group", mode: "bleed", tone: "critical", fontSize: 1, disabled: readOnly, onClick: () => { patch([unset([...slotPath, "groups", { _key: groupKey }])]); setGroupKey("main"); } })) })] })) : null] })) : (_jsx(Box, { children: _jsx(Button, { text: "Add content to this shot", tone: "primary", disabled: readOnly, onClick: () => addContent(current._key) }) }))] }) })) : null, orphans.map((o) => (_jsx(Card, { padding: 3, radius: 2, tone: "caution", border: true, children: _jsxs(Flex, { gap: 3, align: "center", wrap: "wrap", children: [_jsx(Box, { style: { flex: 1, minWidth: 200 }, children: _jsxs(Text, { size: 1, children: ["Content for a shot that's no longer in the scene (", blockCount(o), " block(s)). It isn't shown on the page."] }) }), _jsxs(Select, { fontSize: 1, disabled: readOnly, value: "", onChange: (e) => { const to = e.currentTarget.value; if (to)
|
|
228
|
+
patch([set(moveSlot(slots, o._key, to), ["slots"])]); }, children: [_jsx("option", { value: "", children: "Move it to\u2026" }), stops.map((s, i) => _jsxs("option", { value: s._key, children: [i + 1, ". ", s.label, hasContent(byKey.get(s._key)) ? " (adds to its content)" : ""] }, s._key))] }), _jsx(Button, { text: "Delete", mode: "bleed", tone: "critical", fontSize: 1, disabled: readOnly, onClick: () => patch([unset(["slots", { _key: o._key }])]) })] }) }, o._key))), _jsx(Card, { padding: 4, radius: 3, border: true, tone: "transparent", children: _jsxs(Stack, { gap: 4, children: [_jsxs(Stack, { gap: 2, children: [_jsx(Text, { size: 2, weight: "semibold", children: "Defaults for every shot on this page" }), _jsx(Text, { size: 1, muted: true, children: "Shots and groups use these until you set them to Custom." })] }), _jsx(Choice, { label: "Look", inherit: "Site default", options: opts.presets.map((p) => ({ title: p.title, value: p.title })), value: hasOwnPreset(pageStyle) ? presetOf(pageStyle, opts.presets) ?? "custom" : null, readOnly: readOnly, onPick: (v) => applyPreset(["style"], v ? opts.presets.find((p) => p.title === v) : null) }), _jsx(PositionGrid, { style: pageStyle, inherit: "Site default", readOnly: readOnly, onPick: (v) => setFields(["style"], T.style, v) }), _jsx(Box, { children: _jsx(Button, { text: custom === "page" ? "Hide colours and sizes" : "Colours and sizes…", mode: "bleed", fontSize: 1, padding: 2, onClick: () => setCustom(custom === "page" ? null : "page") }) }), custom === "page" ? _jsx(FormInput, { ...props, relativePath: ["style"], includeField: true }) : null, _jsx(Text, { size: 1, weight: "semibold", children: "Animation" }), _jsx(MotionEditor, { motion: pageM, readOnly: readOnly, onSet: (c) => setFields(["motion"], T.motion, c) })] }) })] }));
|
|
229
|
+
}
|
|
230
|
+
return (_jsxs(Stack, { gap: 4, children: [_jsxs(Flex, { gap: 2, align: "flex-end", wrap: "wrap", children: [_jsx(Box, { style: { flex: 1, minWidth: 240 }, children: _jsx(FormInput, { ...props, relativePath: ["scene"], includeField: true }) }), _jsx(Box, { paddingBottom: 1, children: _jsx(Button, { text: "Upload new scene\u2026", mode: "ghost", disabled: readOnly || upload?.busy, onClick: () => fileInput.current?.click() }) }), _jsx("input", { ref: fileInput, type: "file", accept: ".zip,application/zip", hidden: true, onChange: (e) => { const f = e.target.files?.[0]; e.target.value = ""; if (f)
|
|
231
|
+
void uploadNew(f); } })] }), upload ? (_jsx(Card, { padding: 3, radius: 2, tone: upload.tone, children: _jsxs(Flex, { gap: 3, align: "center", children: [upload.busy ? _jsx(Spinner, { muted: true }) : null, _jsx(Text, { size: 1, children: upload.text })] }) })) : null, body] }));
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/** Blocks on a shot, in all its groups. */
|
|
235
|
+
function blockCount(s) {
|
|
236
|
+
if (!s)
|
|
237
|
+
return 0;
|
|
238
|
+
return (s.content?.length ?? 0) + (s.groups ?? []).reduce((n, g) => n + (g.content?.length ?? 0), 0);
|
|
239
|
+
}
|
|
240
|
+
/** Palette tokens (var(--…)) don't exist in the Studio: show their preview colours instead. */
|
|
241
|
+
function previewColors(s, opts) {
|
|
242
|
+
const p = (v) => (v ? opts.colors.find((c) => c.value === v)?.preview ?? v : v);
|
|
243
|
+
return { ...s, textColor: p(s.textColor), cardColor: p(s.cardColor) };
|
|
244
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ObjectInputProps } from "sanity";
|
|
2
|
+
/**
|
|
3
|
+
* The scene document's form: drop a STUDIO export zip to create or update the scene. Before anything is
|
|
4
|
+
* uploaded it shows what changes (stops kept, new, removed) and which pages have content on removed stops.
|
|
5
|
+
*/
|
|
6
|
+
export declare function SceneInput(props: ObjectInputProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Button, Card, Dialog, Flex, Grid, Spinner, Stack, Text } from "@sanity/ui";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { getPublishedId, insert, set, setIfMissing, useClient, useFormValue } from "sanity";
|
|
5
|
+
import { diffStops } from "./merge";
|
|
6
|
+
import { API_VERSION, T } from "./options";
|
|
7
|
+
import { historyKey, mb, readExport, titleFrom, uploadExport } from "./importExport";
|
|
8
|
+
/** Placements of this scene anywhere in a document (fields, page-builder arrays, nested objects), and their filled slot keys. */
|
|
9
|
+
function placementsIn(doc, sceneId, out = new Set()) {
|
|
10
|
+
if (Array.isArray(doc))
|
|
11
|
+
doc.forEach((d) => placementsIn(d, sceneId, out));
|
|
12
|
+
else if (doc && typeof doc === "object") {
|
|
13
|
+
const o = doc;
|
|
14
|
+
if (o._type === T.placement && o.scene?._ref === sceneId)
|
|
15
|
+
for (const s of o.slots ?? [])
|
|
16
|
+
if (s.content?.length)
|
|
17
|
+
out.add(s._key);
|
|
18
|
+
Object.values(o).forEach((v) => placementsIn(v, sceneId, out));
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The scene document's form: drop a STUDIO export zip to create or update the scene. Before anything is
|
|
24
|
+
* uploaded it shows what changes (stops kept, new, removed) and which pages have content on removed stops.
|
|
25
|
+
*/
|
|
26
|
+
export function SceneInput(props) {
|
|
27
|
+
const { onChange, readOnly } = props;
|
|
28
|
+
const value = (props.value ?? {});
|
|
29
|
+
const docId = useFormValue(["_id"]);
|
|
30
|
+
const sceneId = docId ? getPublishedId(docId) : undefined;
|
|
31
|
+
const client = useClient({ apiVersion: API_VERSION });
|
|
32
|
+
const [status, setStatus] = useState(null);
|
|
33
|
+
const [busy, setBusy] = useState(false);
|
|
34
|
+
const [over, setOver] = useState(false);
|
|
35
|
+
const [pending, setPending] = useState(null);
|
|
36
|
+
const [usage, setUsage] = useState(null);
|
|
37
|
+
const [unused, setUnused] = useState(null);
|
|
38
|
+
const [confirmClean, setConfirmClean] = useState(false);
|
|
39
|
+
const input = useRef(null);
|
|
40
|
+
const fetchUsage = useCallback(async () => {
|
|
41
|
+
if (!sceneId)
|
|
42
|
+
return [];
|
|
43
|
+
const docs = await client.fetch(`*[references($id)]`, { id: sceneId });
|
|
44
|
+
const byId = new Map();
|
|
45
|
+
for (const d of docs) {
|
|
46
|
+
const id = getPublishedId(String(d._id));
|
|
47
|
+
const u = byId.get(id) ?? { id, type: String(d._type), title: String(d.title ?? d.name ?? d.siteTitle ?? d._type), filled: new Set() };
|
|
48
|
+
placementsIn(d, sceneId).forEach((k) => u.filled.add(k));
|
|
49
|
+
byId.set(id, u);
|
|
50
|
+
}
|
|
51
|
+
return [...byId.values()];
|
|
52
|
+
}, [client, sceneId]);
|
|
53
|
+
const fetchUnused = useCallback(async () => {
|
|
54
|
+
const a = await client.fetch(`*[_type == "sanity.fileAsset" && source.name == "studio-scene" && count(*[references(^._id)]) == 0]{ _id, size }`);
|
|
55
|
+
// Files this scene just uploaded can look unreferenced until the draft saves: never offer those.
|
|
56
|
+
const mine = new Set((value.files ?? []).map((f) => f.asset?.asset?._ref));
|
|
57
|
+
const left = a.filter((x) => !mine.has(x._id));
|
|
58
|
+
setUnused({ ids: left.map((x) => x._id), bytes: left.reduce((n, x) => n + (x.size ?? 0), 0) });
|
|
59
|
+
}, [client, value.files]);
|
|
60
|
+
useEffect(() => { void fetchUsage().then(setUsage).catch(() => setUsage([])); }, [fetchUsage, value.export?.importedAt]);
|
|
61
|
+
useEffect(() => { void fetchUnused().catch(() => { }); }, [fetchUnused]);
|
|
62
|
+
/** Read the zip and work out what would change; nothing is uploaded until the editor confirms. */
|
|
63
|
+
const readZip = useCallback(async (file) => {
|
|
64
|
+
setBusy(true);
|
|
65
|
+
setStatus({ tone: "default", text: `Reading ${file.name}…` });
|
|
66
|
+
try {
|
|
67
|
+
const read = await readExport(file);
|
|
68
|
+
const diff = diffStops(value.stops, read.timeline.stops);
|
|
69
|
+
const u = value.stops?.length ? await fetchUsage() : [];
|
|
70
|
+
setPending({ read, diff, usage: u });
|
|
71
|
+
setStatus(null);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
setStatus({ tone: "critical", text: err instanceof Error ? err.message : String(err) });
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
setBusy(false);
|
|
78
|
+
}
|
|
79
|
+
}, [fetchUsage, value.stops]);
|
|
80
|
+
const apply = useCallback(async () => {
|
|
81
|
+
if (!pending)
|
|
82
|
+
return;
|
|
83
|
+
const { read, diff } = pending;
|
|
84
|
+
setPending(null);
|
|
85
|
+
setBusy(true);
|
|
86
|
+
try {
|
|
87
|
+
const up = await uploadExport(client, read, (text) => setStatus({ tone: "default", text }));
|
|
88
|
+
const meta = { ...up.meta, added: value.stops ? diff.added.length : up.stops.length, removed: diff.removed.length };
|
|
89
|
+
onChange([
|
|
90
|
+
setIfMissing({ _type: T.scene }),
|
|
91
|
+
...(value.title ? [] : [set(titleFrom(read.file.name), ["title"])]),
|
|
92
|
+
set(up.files, ["files"]),
|
|
93
|
+
set(up.stops, ["stops"]),
|
|
94
|
+
set(up.points, ["points"]),
|
|
95
|
+
set({ _type: T.sceneExport, ...meta }, ["export"]),
|
|
96
|
+
set({ kind: "zip" }, ["source"]),
|
|
97
|
+
...(value.export?.importedAt
|
|
98
|
+
? [setIfMissing([], ["history"]), insert([{ _type: T.sceneExport, _key: historyKey(value.export.importedAt), ...value.export }], "before", ["history", 0])]
|
|
99
|
+
: []),
|
|
100
|
+
]);
|
|
101
|
+
setStatus({ tone: "positive", text: `Imported ${up.files.length} files (${mb(read.bytes)}) and ${up.stops.length} shots. Publish the scene to update the pages that use it.` });
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
setStatus({ tone: "critical", text: err instanceof Error ? err.message : String(err) });
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
setBusy(false);
|
|
108
|
+
}
|
|
109
|
+
}, [client, onChange, pending, value.export, value.stops, value.title]);
|
|
110
|
+
const clean = useCallback(async () => {
|
|
111
|
+
if (!unused?.ids.length)
|
|
112
|
+
return;
|
|
113
|
+
setConfirmClean(false);
|
|
114
|
+
setBusy(true);
|
|
115
|
+
try {
|
|
116
|
+
const tx = client.transaction();
|
|
117
|
+
unused.ids.forEach((id) => tx.delete(id));
|
|
118
|
+
await tx.commit();
|
|
119
|
+
setStatus({ tone: "positive", text: `Deleted ${unused.ids.length} unused scene file(s), ${mb(unused.bytes)}.` });
|
|
120
|
+
await fetchUnused();
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
setStatus({ tone: "critical", text: `Couldn't delete: ${err instanceof Error ? err.message : err}` });
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
setBusy(false);
|
|
127
|
+
}
|
|
128
|
+
}, [client, fetchUnused, unused]);
|
|
129
|
+
const onDrop = (e) => {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
setOver(false);
|
|
132
|
+
const f = e.dataTransfer.files[0];
|
|
133
|
+
if (f && !readOnly && !busy)
|
|
134
|
+
void readZip(f);
|
|
135
|
+
};
|
|
136
|
+
const stops = value.stops ?? [];
|
|
137
|
+
return (_jsxs(Stack, { gap: 5, children: [props.renderDefault(props), _jsxs(Card, { padding: 4, radius: 2, border: true, tone: over ? "primary" : "transparent", style: { borderStyle: "dashed" }, onDragOver: (e) => { e.preventDefault(); setOver(true); }, onDragLeave: () => setOver(false), onDrop: onDrop, children: [_jsxs(Flex, { gap: 4, align: "center", wrap: "wrap", children: [value.export?.posterUrl ? _jsx("img", { src: value.export.posterUrl, alt: "", style: { width: 160, aspectRatio: "16 / 9", objectFit: "cover", borderRadius: 3 } }) : null, _jsxs(Stack, { gap: 3, style: { flex: 1, minWidth: 220 }, children: [_jsx(Text, { weight: "semibold", children: value.export?.fileName ? `Export: ${value.export.fileName}` : "Drop scroll-scene.zip from STUDIO here" }), _jsx(Text, { size: 1, muted: true, children: value.export?.importedAt
|
|
138
|
+
? `Imported ${new Date(value.export.importedAt).toLocaleString()} · ${mb(value.export.bytes ?? 0)}. Drop a new export to update the scene everywhere it's used; text on pages stays with its shot.`
|
|
139
|
+
: "In STUDIO: Export → Sanity. Then add a Scroll Scene section to any page, pick this scene and write text over its shots." })] }), _jsx(Button, { text: value.export ? "Replace export…" : "Choose zip…", mode: "ghost", disabled: readOnly || busy, onClick: () => input.current?.click() })] }), _jsx("input", { ref: input, type: "file", accept: ".zip,application/zip", hidden: true, onChange: (e) => { const f = e.target.files?.[0]; e.target.value = ""; if (f)
|
|
140
|
+
void readZip(f); } })] }), status ? (_jsx(Card, { padding: 3, radius: 2, tone: status.tone, children: _jsxs(Flex, { gap: 3, align: "center", children: [busy ? _jsx(Spinner, { muted: true }) : null, _jsx(Box, { style: { flex: 1 }, children: _jsx(Text, { size: 1, children: status.text }) })] }) })) : null, stops.length ? (_jsxs(Stack, { gap: 3, children: [_jsxs(Text, { size: 1, weight: "semibold", children: ["Shots (", stops.length, ")"] }), _jsx(Grid, { gridTemplateColumns: [2, 3, 4], gap: 3, children: stops.map((s, i) => (_jsxs(Card, { radius: 2, border: true, overflow: "hidden", children: [_jsx("div", { style: { aspectRatio: "16 / 9", background: "#111" }, children: s.thumbUrl ? _jsx("img", { src: s.thumbUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover", display: "block" } }) : null }), _jsx(Stack, { gap: 2, padding: 2, children: _jsxs(Text, { size: 1, weight: "semibold", textOverflow: "ellipsis", children: [i + 1, ". ", s.label] }) })] }, s._key))) })] })) : null, usage ? (_jsxs(Stack, { gap: 2, children: [_jsx(Text, { size: 1, weight: "semibold", children: "Used on" }), _jsx(Text, { size: 1, muted: true, children: usage.length ? usage.map((u) => u.title).join(", ") : "No pages yet. Add a Scroll scene section (or field) to a page and pick this scene." })] })) : null, unused?.ids.length ? (_jsx(Card, { padding: 3, radius: 2, border: true, children: _jsxs(Flex, { gap: 3, align: "center", wrap: "wrap", children: [_jsx(Box, { style: { flex: 1, minWidth: 220 }, children: _jsxs(Text, { size: 1, muted: true, children: [unused.ids.length, " scene file(s) from earlier exports aren't used by any scene (", mb(unused.bytes), ")."] }) }), _jsx(Button, { text: "Delete unused files\u2026", mode: "ghost", tone: "critical", fontSize: 1, disabled: readOnly || busy, onClick: () => setConfirmClean(true) })] }) })) : null, pending ? (_jsx(Dialog, { id: "studio-scene-review", header: "Update the scene?", width: 1, onClose: () => setPending(null), footer: _jsxs(Flex, { gap: 2, justify: "flex-end", padding: 3, children: [_jsx(Button, { text: "Cancel", mode: "bleed", onClick: () => setPending(null) }), _jsx(Button, { text: `Upload ${pending.read.keep.length} files`, tone: "primary", onClick: () => void apply() })] }), children: _jsxs(Stack, { gap: 4, padding: 4, children: [_jsxs(Text, { size: 1, children: [pending.read.file.name, " \u00B7 ", pending.read.timeline.stops.length, " shots \u00B7 ", mb(pending.read.bytes)] }), value.stops?.length ? (_jsxs(Stack, { gap: 3, children: [_jsxs(Text, { size: 1, children: [_jsx("strong", { children: pending.diff.kept.length }), " kept \u00B7 ", _jsx("strong", { children: pending.diff.added.length }), " new \u00B7 ", _jsx("strong", { children: pending.diff.removed.length }), " removed"] }), pending.diff.added.length ? _jsxs(Text, { size: 1, muted: true, children: ["New shots: ", pending.diff.added.map((s) => s.label).join(", "), ". Pages can add text to them."] }) : null, pending.diff.renamed.length ? _jsxs(Text, { size: 1, muted: true, children: ["Renamed: ", pending.diff.renamed.map((r) => `${r.from} → ${r.to}`).join(", "), ". Text stays with its shot."] }) : null, pending.diff.removed.map((r) => {
|
|
141
|
+
const pages = pending.usage.filter((u) => u.filled.has(r._key)).map((u) => u.title);
|
|
142
|
+
return (_jsx(Card, { padding: 3, radius: 2, tone: pages.length ? "caution" : "transparent", border: true, children: _jsxs(Text, { size: 1, children: ["Removed shot: ", r.label, ".", " ", pages.length ? `Its text on ${pages.join(", ")} will be hidden (not deleted); it can be moved to another shot.` : "No page has text on it."] }) }, r._key));
|
|
143
|
+
}), pending.usage.length ? _jsxs(Text, { size: 1, muted: true, children: ["Used on ", pending.usage.map((u) => u.title).join(", "), ": they update when you publish the scene."] }) : null] })) : (_jsxs(Text, { size: 1, muted: true, children: ["Shots: ", pending.read.timeline.stops.map((s) => s.label).join(", ") || "none", "."] }))] }) })) : null, confirmClean && unused ? (_jsx(Dialog, { id: "studio-scene-clean", header: "Delete unused scene files?", width: 1, onClose: () => setConfirmClean(false), footer: _jsxs(Flex, { gap: 2, justify: "flex-end", padding: 3, children: [_jsx(Button, { text: "Cancel", mode: "bleed", onClick: () => setConfirmClean(false) }), _jsx(Button, { text: `Delete ${unused.ids.length} file(s)`, tone: "critical", onClick: () => void clean() })] }), children: _jsx(Box, { padding: 4, children: _jsx(Text, { size: 1, children: "These files came from earlier exports and no scene (draft or published) uses them. Deleting them can't be undone." }) }) })) : null] }));
|
|
144
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type PinLine, type SlotMotion, type SlotStyle } from "./styleTokens";
|
|
3
|
+
/** A group of content over the shot, as the preview draws it. */
|
|
4
|
+
export interface PreviewGroup {
|
|
5
|
+
key: string;
|
|
6
|
+
style: SlotStyle;
|
|
7
|
+
motion: SlotMotion;
|
|
8
|
+
/** Web point the group follows. */
|
|
9
|
+
pin?: string;
|
|
10
|
+
/** Pinned with a line to the point (a callout). */
|
|
11
|
+
line?: PinLine;
|
|
12
|
+
/** The group's own style (not inherited): a pinned card's side of its point. */
|
|
13
|
+
ownStyle?: SlotStyle;
|
|
14
|
+
selected?: boolean;
|
|
15
|
+
/** One node per block (blocks animate one after another with a stagger). */
|
|
16
|
+
blocks: ReactNode[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The scene, live, with the shot's content groups laid over it the way the page will style and move them.
|
|
20
|
+
* The element is `driven`: the preview moves the camera (goTo a shot, or the scrubber), not page scroll.
|
|
21
|
+
* "Play" runs the content's motion (in, hold, out) with the same CSS as the page.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ScenePreview(props: {
|
|
24
|
+
files: Record<string, string>;
|
|
25
|
+
runtimeUrl?: string;
|
|
26
|
+
/** data-stop slug to show */
|
|
27
|
+
focus?: string | null;
|
|
28
|
+
groups: PreviewGroup[];
|
|
29
|
+
onPick?: (slug: string) => void;
|
|
30
|
+
/** Changes to this replay the motion (e.g. when the animation settings change). */
|
|
31
|
+
replay?: string;
|
|
32
|
+
}): import("react").JSX.Element;
|
|
33
|
+
/**
|
|
34
|
+
* Content blocks, roughly, for the preview overlay. It knows Portable Text and reads any other block by its
|
|
35
|
+
* common fields (eyebrow, heading/title, body/text, buttons, items, image), so a site's own blocks show up as
|
|
36
|
+
* a sketch without the plugin knowing them. The real page renders them with the site's components.
|
|
37
|
+
*/
|
|
38
|
+
export declare function PreviewBlocks({ blocks }: {
|
|
39
|
+
blocks: unknown[] | undefined;
|
|
40
|
+
}): import("react").JSX.Element | null;
|