strata-react 1.0.45 → 1.0.47
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/README.md +3 -3
- package/UPGRADING.md +4 -0
- package/dist/components/conversation.d.ts +14 -0
- package/dist/components/markable-text.d.ts +7 -3
- package/dist/components/selectable-grid.d.ts +17 -5
- package/dist/components/tile-grid.d.ts +9 -1
- package/dist/components/transcript-view.d.ts +16 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1785 -1371
- package/dist/index.js.map +1 -1
- package/dist/lib/grouped-grid-layout.d.ts +30 -0
- package/dist/lib/transcript.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4011,6 +4011,10 @@ function MediaPlayer({ label, kind = "audio", src, sources, index: controlledInd
|
|
|
4011
4011
|
});
|
|
4012
4012
|
}
|
|
4013
4013
|
// src/lib/transcript.ts
|
|
4014
|
+
/** The id of a word for marking (`TranscriptView`'s `marking`, `Mark`): its phrase and its place in it. */
|
|
4015
|
+
var wordId = (phraseId, index) => `${phraseId}:${index}`;
|
|
4016
|
+
/** The phrase an id made by `wordId` belongs to. */
|
|
4017
|
+
var phraseOfWordId = (id) => id.slice(0, id.lastIndexOf(":"));
|
|
4014
4018
|
/** Whether a word is doubtful: the recogniser said so, or its confidence is under `below`. */
|
|
4015
4019
|
function isDoubtful(word, below = .6) {
|
|
4016
4020
|
return word.doubtful ?? (word.confidence !== void 0 && word.confidence < below);
|
|
@@ -4042,100 +4046,384 @@ function wordAt(phrase, time) {
|
|
|
4042
4046
|
else break;
|
|
4043
4047
|
return found;
|
|
4044
4048
|
}
|
|
4045
|
-
// src/
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
const
|
|
4050
|
-
const
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
const
|
|
4057
|
-
const
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4049
|
+
// src/lib/marks.ts
|
|
4050
|
+
/** The ids from `a` to `b` inclusive, in document order whichever way round they are given. Empty when either is not in `ids`. */
|
|
4051
|
+
function rangeBetween(ids, a, b) {
|
|
4052
|
+
if (a === null || b === null) return [];
|
|
4053
|
+
const i = ids.indexOf(a);
|
|
4054
|
+
const j = ids.indexOf(b);
|
|
4055
|
+
if (i < 0 || j < 0) return [];
|
|
4056
|
+
return ids.slice(Math.min(i, j), Math.max(i, j) + 1);
|
|
4057
|
+
}
|
|
4058
|
+
/** How many ids carry each mark key. Ids with no mark are not counted. */
|
|
4059
|
+
function countMarks(marks, ids) {
|
|
4060
|
+
const out = {};
|
|
4061
|
+
for (const id of ids ?? Object.keys(marks)) {
|
|
4062
|
+
const m = marks[id];
|
|
4063
|
+
if (m) out[m] = (out[m] ?? 0) + 1;
|
|
4064
|
+
}
|
|
4065
|
+
return out;
|
|
4066
|
+
}
|
|
4067
|
+
/** The id `by` places from `from` in `ids`, held to the ends; the first (or last) when `from` is not set. */
|
|
4068
|
+
function stepId(ids, from, by) {
|
|
4069
|
+
if (ids.length === 0) return null;
|
|
4070
|
+
const i = from === null ? -1 : ids.indexOf(from);
|
|
4071
|
+
if (i < 0) return by >= 0 ? ids[0] : ids[ids.length - 1];
|
|
4072
|
+
return ids[Math.min(Math.max(i + by, 0), ids.length - 1)];
|
|
4073
|
+
}
|
|
4074
|
+
// src/components/markable-text.tsx
|
|
4075
|
+
var TONE$2 = {
|
|
4076
|
+
neutral: {
|
|
4077
|
+
fill: "var(--muted)",
|
|
4078
|
+
edge: "var(--muted-foreground)"
|
|
4079
|
+
},
|
|
4080
|
+
info: {
|
|
4081
|
+
fill: "var(--info-subtle)",
|
|
4082
|
+
edge: "var(--info)"
|
|
4083
|
+
},
|
|
4084
|
+
success: {
|
|
4085
|
+
fill: "var(--success-subtle)",
|
|
4086
|
+
edge: "var(--success)"
|
|
4087
|
+
},
|
|
4088
|
+
warning: {
|
|
4089
|
+
fill: "var(--warning-subtle)",
|
|
4090
|
+
edge: "var(--warning)"
|
|
4091
|
+
},
|
|
4092
|
+
danger: {
|
|
4093
|
+
fill: "var(--danger-subtle)",
|
|
4094
|
+
edge: "var(--danger)"
|
|
4095
|
+
}
|
|
4096
|
+
};
|
|
4097
|
+
var MarksContext = React.createContext(null);
|
|
4098
|
+
/** One word (or phrase, or clip) that can be marked. Draws its mark, its selection and the caret; inside a `MarkableText`. */
|
|
4099
|
+
function Mark({ id, children, className, onClick, onHover }) {
|
|
4100
|
+
const c = React.useContext(MarksContext);
|
|
4101
|
+
if (!c) return /* @__PURE__ */ jsx("span", {
|
|
4102
|
+
className,
|
|
4103
|
+
children
|
|
4104
|
+
});
|
|
4105
|
+
const kind = c.kinds.find((k) => k.key === c.marks[id]);
|
|
4106
|
+
const tone = kind && TONE$2[kind.tone];
|
|
4107
|
+
const on = c.selected.has(id);
|
|
4108
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
4109
|
+
"data-mark-id": id,
|
|
4110
|
+
"data-mark": kind?.key,
|
|
4111
|
+
"data-selected": on || void 0,
|
|
4112
|
+
"data-caret": c.caret === id || void 0,
|
|
4113
|
+
onPointerDown: (e) => c.press(e, id),
|
|
4114
|
+
onPointerEnter: (e) => {
|
|
4115
|
+
c.over(id);
|
|
4116
|
+
onHover?.(e.currentTarget);
|
|
4117
|
+
},
|
|
4118
|
+
onPointerLeave: onHover ? () => onHover(null) : void 0,
|
|
4119
|
+
onClick,
|
|
4120
|
+
className: cn("cursor-text rounded-control px-px", on && "bg-primary/20", c.caret === id && "outline-2 outline-primary", className),
|
|
4121
|
+
style: kind && tone ? {
|
|
4122
|
+
backgroundColor: on ? void 0 : tone.fill,
|
|
4123
|
+
textDecorationLine: "underline",
|
|
4124
|
+
textDecorationStyle: kind.pattern,
|
|
4125
|
+
textDecorationColor: tone.edge,
|
|
4126
|
+
textDecorationThickness: "2px",
|
|
4127
|
+
textUnderlineOffset: "3px"
|
|
4128
|
+
} : void 0,
|
|
4129
|
+
children: [children, kind && /* @__PURE__ */ jsxs("span", {
|
|
4130
|
+
className: "sr-only",
|
|
4131
|
+
children: [
|
|
4132
|
+
" (",
|
|
4133
|
+
kind.label.toLowerCase(),
|
|
4134
|
+
")"
|
|
4135
|
+
]
|
|
4078
4136
|
})]
|
|
4079
4137
|
});
|
|
4080
|
-
return virtualise ? /* @__PURE__ */ jsx(Virtualizer, {
|
|
4081
|
-
layout: ListLayout,
|
|
4082
|
-
layoutOptions,
|
|
4083
|
-
children: list
|
|
4084
|
-
}) : list;
|
|
4085
4138
|
}
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4139
|
+
/** "12 words must use, 3 never": a count for each kind in use, with its icon. */
|
|
4140
|
+
function MarkSummary({ marks, kinds, unit = ["word", "words"], className }) {
|
|
4141
|
+
const counts = countMarks(marks);
|
|
4142
|
+
const used = kinds.filter((k) => counts[k.key]);
|
|
4143
|
+
if (!used.length) return /* @__PURE__ */ jsx("p", {
|
|
4144
|
+
className: cn("type-caption text-muted-foreground", className),
|
|
4145
|
+
children: "Nothing marked yet."
|
|
4146
|
+
});
|
|
4147
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
4148
|
+
"aria-label": "Marked",
|
|
4149
|
+
className: cn("flex flex-wrap gap-x-4 gap-y-1 type-body-sm", className),
|
|
4150
|
+
children: used.map((k) => {
|
|
4151
|
+
const Icon = k.icon;
|
|
4152
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
4153
|
+
className: "inline-flex items-center gap-1.5",
|
|
4154
|
+
children: [
|
|
4155
|
+
Icon && /* @__PURE__ */ jsx(Icon, {
|
|
4156
|
+
"aria-hidden": true,
|
|
4157
|
+
className: "size-4"
|
|
4158
|
+
}),
|
|
4159
|
+
/* @__PURE__ */ jsx("span", {
|
|
4160
|
+
className: "tabular-nums",
|
|
4161
|
+
children: format.count(counts[k.key], unit[0], unit[1])
|
|
4162
|
+
}),
|
|
4163
|
+
" ",
|
|
4164
|
+
k.label.toLowerCase()
|
|
4165
|
+
]
|
|
4166
|
+
}, k.key);
|
|
4167
|
+
})
|
|
4168
|
+
});
|
|
4169
|
+
}
|
|
4170
|
+
/** Selects ids over `<Mark>` words by drag, Shift+click and Shift+arrows (a run in the app's order, so it holds across virtualised rows), offers the app's marks as chorded commands in a bar, says each change in words, and lists what is marked. */
|
|
4171
|
+
function MarkableText({ label, ids, marks, kinds, onMark, clearKeys = [], onActivate, onCaretChange, unit = ["word", "words"], summary = true, children, className }) {
|
|
4172
|
+
const [anchor, setAnchor] = React.useState(null);
|
|
4173
|
+
const [caret, setCaret] = React.useState(null);
|
|
4174
|
+
const [said, setSaid] = React.useState("");
|
|
4175
|
+
const dragging = React.useRef(false);
|
|
4176
|
+
const hintId = React.useId();
|
|
4177
|
+
const run = React.useMemo(() => rangeBetween(ids, anchor, caret), [
|
|
4178
|
+
ids,
|
|
4179
|
+
anchor,
|
|
4180
|
+
caret
|
|
4112
4181
|
]);
|
|
4113
|
-
const
|
|
4114
|
-
const
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4182
|
+
const selected = React.useMemo(() => new Set(run), [run]);
|
|
4183
|
+
const n = run.length;
|
|
4184
|
+
const counted = (k) => format.count(k, unit[0], unit[1]);
|
|
4185
|
+
const moveCaret = (id, extend) => {
|
|
4186
|
+
if (id === null) return;
|
|
4187
|
+
setCaret(id);
|
|
4188
|
+
if (!extend || anchor === null) setAnchor(id);
|
|
4189
|
+
onCaretChange?.(id);
|
|
4190
|
+
};
|
|
4191
|
+
const apply = (kind) => {
|
|
4192
|
+
if (!n) return;
|
|
4193
|
+
onMark(run, kind);
|
|
4194
|
+
const k = kinds.find((x) => x.key === kind);
|
|
4195
|
+
setSaid(kind === null ? `${counted(n)} cleared` : `${counted(n)} marked ${k?.label.toLowerCase() ?? kind}`);
|
|
4196
|
+
};
|
|
4197
|
+
const commands = [...kinds.map((k) => ({
|
|
4198
|
+
id: `mark-${k.key}`,
|
|
4199
|
+
label: k.label,
|
|
4200
|
+
keys: k.keys,
|
|
4201
|
+
icon: k.icon,
|
|
4202
|
+
disabled: n ? false : "Select words first",
|
|
4203
|
+
run: () => apply(k.key)
|
|
4204
|
+
})), {
|
|
4205
|
+
id: "mark-clear",
|
|
4206
|
+
label: "Clear mark",
|
|
4207
|
+
keys: clearKeys,
|
|
4208
|
+
disabled: n ? false : "Select words first",
|
|
4209
|
+
run: () => apply(null)
|
|
4210
|
+
}];
|
|
4211
|
+
useCommands(commands);
|
|
4212
|
+
React.useEffect(() => {
|
|
4213
|
+
const stop = () => dragging.current = false;
|
|
4214
|
+
window.addEventListener("pointerup", stop);
|
|
4215
|
+
return () => window.removeEventListener("pointerup", stop);
|
|
4216
|
+
}, []);
|
|
4217
|
+
const ctx = {
|
|
4218
|
+
kinds,
|
|
4219
|
+
marks,
|
|
4220
|
+
selected,
|
|
4221
|
+
caret,
|
|
4222
|
+
press: (e, id) => {
|
|
4223
|
+
if (e.button !== 0) return;
|
|
4224
|
+
dragging.current = true;
|
|
4225
|
+
if (e.shiftKey && anchor !== null) setCaret(id);
|
|
4226
|
+
else {
|
|
4227
|
+
setAnchor(id);
|
|
4228
|
+
setCaret(id);
|
|
4137
4229
|
}
|
|
4138
|
-
|
|
4230
|
+
onCaretChange?.(id);
|
|
4231
|
+
setSaid("");
|
|
4232
|
+
},
|
|
4233
|
+
over: (id) => {
|
|
4234
|
+
if (dragging.current && id !== caret) setCaret(id);
|
|
4235
|
+
}
|
|
4236
|
+
};
|
|
4237
|
+
React.useEffect(() => {
|
|
4238
|
+
if (n > 1) setSaid(`${counted(n)} selected`);
|
|
4239
|
+
else if (n === 1 && caret) setSaid(`${document.querySelector(`[data-mark-id="${CSS.escape(caret)}"]`)?.textContent ?? caret}`);
|
|
4240
|
+
}, [n, caret]);
|
|
4241
|
+
const keys = (e) => {
|
|
4242
|
+
if (e.target !== e.currentTarget) return;
|
|
4243
|
+
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
|
4244
|
+
const to = e.key === "ArrowRight" ? stepId(ids, caret, 1) : e.key === "ArrowLeft" ? stepId(ids, caret, -1) : e.key === "Home" ? ids[0] ?? null : e.key === "End" ? ids[ids.length - 1] ?? null : void 0;
|
|
4245
|
+
if (to !== void 0) {
|
|
4246
|
+
e.preventDefault();
|
|
4247
|
+
moveCaret(to, e.shiftKey);
|
|
4248
|
+
} else if (e.key === "Enter" && caret !== null && onActivate) {
|
|
4249
|
+
e.preventDefault();
|
|
4250
|
+
onActivate(caret);
|
|
4251
|
+
} else if (e.key === "Escape" && (anchor !== null || caret !== null)) {
|
|
4252
|
+
e.preventDefault();
|
|
4253
|
+
setAnchor(null);
|
|
4254
|
+
setCaret(null);
|
|
4255
|
+
setSaid("Selection cleared");
|
|
4256
|
+
}
|
|
4257
|
+
};
|
|
4258
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4259
|
+
className: cn("space-y-2", className),
|
|
4260
|
+
children: [
|
|
4261
|
+
n > 0 && /* @__PURE__ */ jsxs(Toolbar, {
|
|
4262
|
+
label: "Marks",
|
|
4263
|
+
className: "sticky top-0 z-10 flex flex-wrap items-center gap-2 rounded-surface border border-border bg-background p-1.5",
|
|
4264
|
+
children: [
|
|
4265
|
+
/* @__PURE__ */ jsxs("span", {
|
|
4266
|
+
className: "px-1 type-label tabular-nums",
|
|
4267
|
+
children: [counted(n), " selected"]
|
|
4268
|
+
}),
|
|
4269
|
+
kinds.map((k) => {
|
|
4270
|
+
const Icon = k.icon;
|
|
4271
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
4272
|
+
size: "sm",
|
|
4273
|
+
onPress: () => apply(k.key),
|
|
4274
|
+
children: [
|
|
4275
|
+
Icon && /* @__PURE__ */ jsx(Icon, {}),
|
|
4276
|
+
" ",
|
|
4277
|
+
k.label
|
|
4278
|
+
]
|
|
4279
|
+
}, k.key);
|
|
4280
|
+
}),
|
|
4281
|
+
/* @__PURE__ */ jsx(Button, {
|
|
4282
|
+
size: "sm",
|
|
4283
|
+
variant: "ghost",
|
|
4284
|
+
onPress: () => apply(null),
|
|
4285
|
+
children: "Clear mark"
|
|
4286
|
+
}),
|
|
4287
|
+
/* @__PURE__ */ jsx(Button, {
|
|
4288
|
+
size: "sm",
|
|
4289
|
+
variant: "ghost",
|
|
4290
|
+
onPress: () => {
|
|
4291
|
+
setAnchor(null);
|
|
4292
|
+
setCaret(null);
|
|
4293
|
+
},
|
|
4294
|
+
children: "Deselect"
|
|
4295
|
+
})
|
|
4296
|
+
]
|
|
4297
|
+
}),
|
|
4298
|
+
/* @__PURE__ */ jsx(MarksContext.Provider, {
|
|
4299
|
+
value: ctx,
|
|
4300
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
4301
|
+
role: "group",
|
|
4302
|
+
"aria-label": label,
|
|
4303
|
+
"aria-describedby": hintId,
|
|
4304
|
+
tabIndex: 0,
|
|
4305
|
+
onKeyDown: keys,
|
|
4306
|
+
className: "select-none rounded-surface outline-offset-2",
|
|
4307
|
+
children
|
|
4308
|
+
})
|
|
4309
|
+
}),
|
|
4310
|
+
/* @__PURE__ */ jsx("p", {
|
|
4311
|
+
id: hintId,
|
|
4312
|
+
className: "type-caption text-muted-foreground",
|
|
4313
|
+
children: "Drag across words, or Shift+click, to select. Left and Right move; Shift and arrows select; Escape clears."
|
|
4314
|
+
}),
|
|
4315
|
+
/* @__PURE__ */ jsx(CommandLegend, {
|
|
4316
|
+
commands,
|
|
4317
|
+
label: "Mark keys"
|
|
4318
|
+
}),
|
|
4319
|
+
summary && /* @__PURE__ */ jsx(MarkSummary, {
|
|
4320
|
+
marks,
|
|
4321
|
+
kinds,
|
|
4322
|
+
unit
|
|
4323
|
+
}),
|
|
4324
|
+
/* @__PURE__ */ jsx("div", {
|
|
4325
|
+
role: "status",
|
|
4326
|
+
"aria-live": "polite",
|
|
4327
|
+
className: "sr-only",
|
|
4328
|
+
children: said
|
|
4329
|
+
})
|
|
4330
|
+
]
|
|
4331
|
+
});
|
|
4332
|
+
}
|
|
4333
|
+
// src/components/virtual-list.tsx
|
|
4334
|
+
var FOOTER = "\0footer";
|
|
4335
|
+
/** A list that renders only its visible rows (React Aria's GridList and Virtualizer) from `virtualizeFrom` items, with arrow-key navigation between rows. */
|
|
4336
|
+
function VirtualList({ label, items, itemKey, children, estimateSize = 48, rowHeight, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
|
|
4337
|
+
const virtual = items.length >= virtualizeFrom;
|
|
4338
|
+
const rows = React.useMemo(() => items.map((item, index) => ({
|
|
4339
|
+
id: itemKey(item),
|
|
4340
|
+
item,
|
|
4341
|
+
index
|
|
4342
|
+
})), [items, itemKey]);
|
|
4343
|
+
const layoutOptions = React.useMemo(() => rowHeight ? { rowHeight } : { estimatedRowHeight: estimateSize }, [rowHeight, estimateSize]);
|
|
4344
|
+
const virtualise = virtual || bounded;
|
|
4345
|
+
const scrolls = virtualise;
|
|
4346
|
+
const list = /* @__PURE__ */ jsxs(GridList, {
|
|
4347
|
+
"aria-label": label,
|
|
4348
|
+
selectionMode: "none",
|
|
4349
|
+
"data-strata-scroll": "",
|
|
4350
|
+
className: cn("min-w-0 outline-none", scrolls && "overflow-y-auto", className),
|
|
4351
|
+
style: scrolls ? virtual ? { height } : { maxHeight: height } : void 0,
|
|
4352
|
+
children: [/* @__PURE__ */ jsx(Collection, {
|
|
4353
|
+
items: rows,
|
|
4354
|
+
children: (row) => /* @__PURE__ */ jsx(GridListItem, {
|
|
4355
|
+
id: row.id,
|
|
4356
|
+
textValue: row.id,
|
|
4357
|
+
"data-index": row.index,
|
|
4358
|
+
className: cn("min-w-0 outline-offset-[-2px]", row.index > 0 && "border-t border-border"),
|
|
4359
|
+
children: children(row.item, row.index)
|
|
4360
|
+
})
|
|
4361
|
+
}), footer && /* @__PURE__ */ jsx(GridListItem, {
|
|
4362
|
+
id: FOOTER,
|
|
4363
|
+
textValue: "More",
|
|
4364
|
+
className: "min-w-0",
|
|
4365
|
+
children: footer
|
|
4366
|
+
})]
|
|
4367
|
+
});
|
|
4368
|
+
return virtualise ? /* @__PURE__ */ jsx(Virtualizer, {
|
|
4369
|
+
layout: ListLayout,
|
|
4370
|
+
layoutOptions,
|
|
4371
|
+
children: list
|
|
4372
|
+
}) : list;
|
|
4373
|
+
}
|
|
4374
|
+
// src/components/transcript-view.tsx
|
|
4375
|
+
var ALL = "all";
|
|
4376
|
+
var capital = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
4377
|
+
var range = (a, b) => `${format.runningTime(a)}–${format.runningTime(b)}`;
|
|
4378
|
+
/** Timed text that follows playback: the heard word marked, any word or phrase pressed to play from, modes, speakers, follow and Jump to now. */
|
|
4379
|
+
function TranscriptView({ label, groups, time, onSeek, marking, onCorrectionPress, mode: controlledMode, onModeChange, modeLabels = {}, speaker: controlledSpeaker, onSpeakerChange, follow = true, announce = false, renderPlay, doubtfulBelow = .6, states = [], onPhraseState, renderActions, onEdit, renderCard, cardDelay = 500, height = 480, className }) {
|
|
4380
|
+
const [ownMode, setOwnMode] = React.useState("original");
|
|
4381
|
+
const [ownSpeaker, setOwnSpeaker] = React.useState(ALL);
|
|
4382
|
+
const mode = controlledMode ?? ownMode;
|
|
4383
|
+
const speaker = controlledSpeaker ?? ownSpeaker;
|
|
4384
|
+
const modes = React.useMemo(() => ["original", ...new Set(groups.flatMap((g) => g.phrases.flatMap((p) => Object.keys(p.alt ?? {}))))], [groups]);
|
|
4385
|
+
const speakers = React.useMemo(() => [...new Set(groups.flatMap((g) => g.phrases.map((p) => p.speaker).filter((s) => Boolean(s))))], [groups]);
|
|
4386
|
+
const [onlyDoubtful, setOnlyDoubtful] = React.useState(false);
|
|
4387
|
+
const summary = React.useMemo(() => {
|
|
4388
|
+
const mine = groups.flatMap((g) => g.phrases).filter((p) => speaker === ALL || p.speaker === speaker);
|
|
4389
|
+
const doubtful = mine.filter((p) => phraseDoubtful(p, doubtfulBelow)).length;
|
|
4390
|
+
const marked = /* @__PURE__ */ new Map();
|
|
4391
|
+
for (const p of mine) if (p.state) marked.set(p.state.label, (marked.get(p.state.label) ?? 0) + 1);
|
|
4392
|
+
return {
|
|
4393
|
+
doubtful,
|
|
4394
|
+
marked: [...marked]
|
|
4395
|
+
};
|
|
4396
|
+
}, [
|
|
4397
|
+
groups,
|
|
4398
|
+
speaker,
|
|
4399
|
+
doubtfulBelow
|
|
4400
|
+
]);
|
|
4401
|
+
const filtering = onlyDoubtful && summary.doubtful > 0;
|
|
4402
|
+
const { rows, phrases } = React.useMemo(() => {
|
|
4403
|
+
const rows = [];
|
|
4404
|
+
const phrases = [];
|
|
4405
|
+
for (const g of groups) {
|
|
4406
|
+
const mine = g.phrases.filter((p) => (speaker === ALL || p.speaker === speaker) && (!filtering || phraseDoubtful(p, doubtfulBelow)));
|
|
4407
|
+
if (mine.length === 0) continue;
|
|
4408
|
+
rows.push({
|
|
4409
|
+
kind: "heading",
|
|
4410
|
+
key: `group:${g.id}`,
|
|
4411
|
+
group: {
|
|
4412
|
+
...g,
|
|
4413
|
+
start: g.start ?? mine[0].start,
|
|
4414
|
+
end: g.end ?? mine[mine.length - 1].end
|
|
4415
|
+
}
|
|
4416
|
+
});
|
|
4417
|
+
for (const p of mine) {
|
|
4418
|
+
rows.push({
|
|
4419
|
+
kind: "phrase",
|
|
4420
|
+
key: p.id,
|
|
4421
|
+
phrase: p,
|
|
4422
|
+
index: phrases.length
|
|
4423
|
+
});
|
|
4424
|
+
phrases.push(p);
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4139
4427
|
return {
|
|
4140
4428
|
rows,
|
|
4141
4429
|
phrases
|
|
@@ -4146,9 +4434,9 @@ function TranscriptView({ label, groups, time, onSeek, mode: controlledMode, onM
|
|
|
4146
4434
|
filtering,
|
|
4147
4435
|
doubtfulBelow
|
|
4148
4436
|
]);
|
|
4149
|
-
const heard = phraseAt(phrases, time);
|
|
4437
|
+
const heard = time === void 0 ? -1 : phraseAt(phrases, time);
|
|
4150
4438
|
const heardPhrase = heard >= 0 ? phrases[heard] : null;
|
|
4151
|
-
const heardWord = heardPhrase ? wordAt(heardPhrase, time) : -1;
|
|
4439
|
+
const heardWord = heardPhrase && time !== void 0 ? wordAt(heardPhrase, time) : -1;
|
|
4152
4440
|
const heardText = heardPhrase ? mode === "original" ? heardPhrase.words.map((w) => w.text).join(" ") : heardPhrase.alt?.[mode] ?? heardPhrase.words.map((w) => w.text).join(" ") : "";
|
|
4153
4441
|
const root = React.useRef(null);
|
|
4154
4442
|
const [following, setFollowing] = React.useState(follow);
|
|
@@ -4281,10 +4569,13 @@ function TranscriptView({ label, groups, time, onSeek, mode: controlledMode, onM
|
|
|
4281
4569
|
if (controlledSpeaker === void 0) setOwnSpeaker(s);
|
|
4282
4570
|
onSpeakerChange?.(s);
|
|
4283
4571
|
};
|
|
4284
|
-
const seek = (t, from) => {
|
|
4572
|
+
const seek = onSeek ? (t, from) => {
|
|
4285
4573
|
setFollowing(follow);
|
|
4286
4574
|
onSeek(t, from);
|
|
4287
|
-
};
|
|
4575
|
+
} : void 0;
|
|
4576
|
+
const marks = marking && mode === "original" ? marking : null;
|
|
4577
|
+
const wordIds = React.useMemo(() => marks ? phrases.flatMap((p) => p.words.map((_, i) => wordId(p.id, i))) : [], [marks, phrases]);
|
|
4578
|
+
const [hint, setHint] = React.useState(null);
|
|
4288
4579
|
const modeOptions = modes.map((m) => ({
|
|
4289
4580
|
value: m,
|
|
4290
4581
|
label: m === "original" ? modeLabels.original ?? "Original" : modeLabels[m] ?? capital(m)
|
|
@@ -4296,6 +4587,72 @@ function TranscriptView({ label, groups, time, onSeek, mode: controlledMode, onM
|
|
|
4296
4587
|
value: s,
|
|
4297
4588
|
label: s
|
|
4298
4589
|
}))];
|
|
4590
|
+
const list = /* @__PURE__ */ jsxs("div", {
|
|
4591
|
+
className: "relative",
|
|
4592
|
+
onKeyDown: onKeys,
|
|
4593
|
+
onFocus: (e) => showCard(phraseOfEvent(e.target)),
|
|
4594
|
+
onBlur: (e) => {
|
|
4595
|
+
if (!root.current?.contains(e.relatedTarget)) showCard(null);
|
|
4596
|
+
},
|
|
4597
|
+
onPointerLeave: () => {
|
|
4598
|
+
dismissed.current = null;
|
|
4599
|
+
showCard(null);
|
|
4600
|
+
},
|
|
4601
|
+
children: [/* @__PURE__ */ jsx(VirtualList, {
|
|
4602
|
+
label,
|
|
4603
|
+
items: rows,
|
|
4604
|
+
itemKey: (r) => r.key,
|
|
4605
|
+
estimateSize: 72,
|
|
4606
|
+
height,
|
|
4607
|
+
virtualizeFrom: 100,
|
|
4608
|
+
children: (row) => row.kind === "heading" ? /* @__PURE__ */ jsxs("div", {
|
|
4609
|
+
className: "flex items-baseline gap-3 bg-surface-sunken px-3 py-2",
|
|
4610
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
4611
|
+
className: "type-label text-foreground",
|
|
4612
|
+
children: row.group.title
|
|
4613
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4614
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
4615
|
+
children: range(row.group.start, row.group.end)
|
|
4616
|
+
})]
|
|
4617
|
+
}) : /* @__PURE__ */ jsx(PhraseRow, {
|
|
4618
|
+
phrase: row.phrase,
|
|
4619
|
+
marking: Boolean(marks),
|
|
4620
|
+
onCorrectionPress,
|
|
4621
|
+
onHint: setHint,
|
|
4622
|
+
mode,
|
|
4623
|
+
active: row.index === heard,
|
|
4624
|
+
word: row.index === heard ? heardWord : -1,
|
|
4625
|
+
onSeek: seek,
|
|
4626
|
+
play: renderPlay?.(row.phrase),
|
|
4627
|
+
doubtfulBelow,
|
|
4628
|
+
states,
|
|
4629
|
+
onPhraseState,
|
|
4630
|
+
actions: renderActions?.(row.phrase),
|
|
4631
|
+
edit: editing?.id === row.phrase.id ? {
|
|
4632
|
+
text: editing.text,
|
|
4633
|
+
change: (text) => setEditing({
|
|
4634
|
+
...editing,
|
|
4635
|
+
text
|
|
4636
|
+
}),
|
|
4637
|
+
done: stopEdit
|
|
4638
|
+
} : void 0,
|
|
4639
|
+
onHover: (on) => {
|
|
4640
|
+
if (!on) dismissed.current = null;
|
|
4641
|
+
showCard(on ? row.phrase.id : null);
|
|
4642
|
+
}
|
|
4643
|
+
})
|
|
4644
|
+
}), follow && !following && heardPhrase && /* @__PURE__ */ jsx("div", {
|
|
4645
|
+
className: "pointer-events-none absolute inset-x-0 bottom-2 flex justify-center",
|
|
4646
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
4647
|
+
className: "pointer-events-auto max-w-full shadow-overlay",
|
|
4648
|
+
onPress: () => setFollowing(true),
|
|
4649
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
4650
|
+
className: "truncate",
|
|
4651
|
+
children: ["Jump to now: ", heardText]
|
|
4652
|
+
})
|
|
4653
|
+
})
|
|
4654
|
+
})]
|
|
4655
|
+
});
|
|
4299
4656
|
return /* @__PURE__ */ jsxs("div", {
|
|
4300
4657
|
ref: root,
|
|
4301
4658
|
className: cn("grid min-w-0 gap-3", className),
|
|
@@ -4338,73 +4695,35 @@ function TranscriptView({ label, groups, time, onSeek, mode: controlledMode, onM
|
|
|
4338
4695
|
})
|
|
4339
4696
|
]
|
|
4340
4697
|
}),
|
|
4341
|
-
/* @__PURE__ */
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
height,
|
|
4358
|
-
virtualizeFrom: 100,
|
|
4359
|
-
children: (row) => row.kind === "heading" ? /* @__PURE__ */ jsxs("div", {
|
|
4360
|
-
className: "flex items-baseline gap-3 bg-surface-sunken px-3 py-2",
|
|
4361
|
-
children: [/* @__PURE__ */ jsx("h3", {
|
|
4362
|
-
className: "type-label text-foreground",
|
|
4363
|
-
children: row.group.title
|
|
4364
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
4365
|
-
className: "type-caption tabular-nums text-muted-foreground",
|
|
4366
|
-
children: range(row.group.start, row.group.end)
|
|
4367
|
-
})]
|
|
4368
|
-
}) : /* @__PURE__ */ jsx(PhraseRow, {
|
|
4369
|
-
phrase: row.phrase,
|
|
4370
|
-
mode,
|
|
4371
|
-
active: row.index === heard,
|
|
4372
|
-
word: row.index === heard ? heardWord : -1,
|
|
4373
|
-
onSeek: seek,
|
|
4374
|
-
play: renderPlay?.(row.phrase),
|
|
4375
|
-
doubtfulBelow,
|
|
4376
|
-
states,
|
|
4377
|
-
onPhraseState,
|
|
4378
|
-
actions: renderActions?.(row.phrase),
|
|
4379
|
-
edit: editing?.id === row.phrase.id ? {
|
|
4380
|
-
text: editing.text,
|
|
4381
|
-
change: (text) => setEditing({
|
|
4382
|
-
...editing,
|
|
4383
|
-
text
|
|
4384
|
-
}),
|
|
4385
|
-
done: stopEdit
|
|
4386
|
-
} : void 0,
|
|
4387
|
-
onHover: (on) => {
|
|
4388
|
-
if (!on) dismissed.current = null;
|
|
4389
|
-
showCard(on ? row.phrase.id : null);
|
|
4390
|
-
}
|
|
4391
|
-
})
|
|
4392
|
-
}), follow && !following && heardPhrase && /* @__PURE__ */ jsx("div", {
|
|
4393
|
-
className: "pointer-events-none absolute inset-x-0 bottom-2 flex justify-center",
|
|
4394
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
4395
|
-
className: "pointer-events-auto max-w-full shadow-overlay",
|
|
4396
|
-
onPress: () => setFollowing(true),
|
|
4397
|
-
children: /* @__PURE__ */ jsxs("span", {
|
|
4398
|
-
className: "truncate",
|
|
4399
|
-
children: ["Jump to now: ", heardText]
|
|
4400
|
-
})
|
|
4401
|
-
})
|
|
4402
|
-
})]
|
|
4403
|
-
}),
|
|
4698
|
+
marks ? /* @__PURE__ */ jsx(MarkableText, {
|
|
4699
|
+
label: `${label}, for marking`,
|
|
4700
|
+
ids: wordIds,
|
|
4701
|
+
marks: marks.marks,
|
|
4702
|
+
kinds: marks.kinds,
|
|
4703
|
+
onMark: marks.onMark,
|
|
4704
|
+
clearKeys: marks.clearKeys,
|
|
4705
|
+
summary: marks.summary,
|
|
4706
|
+
onActivate: onCorrectionPress ? (id) => {
|
|
4707
|
+
const pid = phraseOfWordId(id);
|
|
4708
|
+
const i = Number(id.slice(pid.length + 1));
|
|
4709
|
+
if (phrases.find((x) => x.id === pid)?.words[i]?.correction) onCorrectionPress(pid, i);
|
|
4710
|
+
} : void 0,
|
|
4711
|
+
onCaretChange: (id) => scrollToHeard(phraseOfWordId(id)),
|
|
4712
|
+
children: list
|
|
4713
|
+
}) : list,
|
|
4404
4714
|
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("span", {
|
|
4405
4715
|
role: "status",
|
|
4406
4716
|
children: said
|
|
4407
4717
|
}) }),
|
|
4718
|
+
hint && /* @__PURE__ */ jsx(Popover$1, {
|
|
4719
|
+
triggerRef: { current: hint.el },
|
|
4720
|
+
isOpen: true,
|
|
4721
|
+
isNonModal: true,
|
|
4722
|
+
placement: "top",
|
|
4723
|
+
offset: 4,
|
|
4724
|
+
className: cn("layer-overlay max-w-xs px-2 py-1 type-caption", "rounded-overlay border border-border bg-popover text-popover-foreground shadow-overlay enter-overlay"),
|
|
4725
|
+
children: hint.text
|
|
4726
|
+
}),
|
|
4408
4727
|
card && renderCard && (() => {
|
|
4409
4728
|
const p = phrases.find((x) => x.id === card);
|
|
4410
4729
|
const anchor = rowEl(card);
|
|
@@ -4424,7 +4743,7 @@ function TranscriptView({ label, groups, time, onSeek, mode: controlledMode, onM
|
|
|
4424
4743
|
]
|
|
4425
4744
|
});
|
|
4426
4745
|
}
|
|
4427
|
-
function PhraseRow({ phrase, mode, active, word, onSeek, play, doubtfulBelow, states, onPhraseState, actions, edit, onHover }) {
|
|
4746
|
+
function PhraseRow({ phrase, mode, active, word, onSeek, marking, onCorrectionPress, onHint, play, doubtfulBelow, states, onPhraseState, actions, edit, onHover }) {
|
|
4428
4747
|
const alt = mode === "original" ? null : phrase.alt?.[mode] ?? null;
|
|
4429
4748
|
const doubtful = phraseDoubtful(phrase, doubtfulBelow);
|
|
4430
4749
|
const marks = states.filter((s) => s.id !== phrase.state?.id).map((s) => ({
|
|
@@ -4457,11 +4776,14 @@ function PhraseRow({ phrase, mode, active, word, onSeek, play, doubtfulBelow, st
|
|
|
4457
4776
|
className: "type-label text-muted-foreground",
|
|
4458
4777
|
children: phrase.speaker
|
|
4459
4778
|
}),
|
|
4460
|
-
/* @__PURE__ */ jsx(Button$1, {
|
|
4779
|
+
onSeek ? /* @__PURE__ */ jsx(Button$1, {
|
|
4461
4780
|
onPress: () => onSeek(phrase.start, { phraseId: phrase.id }),
|
|
4462
4781
|
className: "rounded-control type-caption tabular-nums text-muted-foreground hover:text-foreground",
|
|
4463
4782
|
"aria-label": `Play from ${format.runningTime(phrase.start)}`,
|
|
4464
4783
|
children: format.runningTime(phrase.start)
|
|
4784
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
4785
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
4786
|
+
children: format.runningTime(phrase.start)
|
|
4465
4787
|
}),
|
|
4466
4788
|
doubtful && /* @__PURE__ */ jsx(Status, {
|
|
4467
4789
|
tone: "warning",
|
|
@@ -4499,22 +4821,58 @@ function PhraseRow({ phrase, mode, active, word, onSeek, play, doubtfulBelow, st
|
|
|
4499
4821
|
children: "Cancel"
|
|
4500
4822
|
})]
|
|
4501
4823
|
})]
|
|
4502
|
-
}) : alt !== null ? /* @__PURE__ */ jsx(Button$1, {
|
|
4824
|
+
}) : alt !== null ? onSeek ? /* @__PURE__ */ jsx(Button$1, {
|
|
4503
4825
|
onPress: () => onSeek(phrase.start, { phraseId: phrase.id }),
|
|
4504
4826
|
className: cn("rounded-control text-left type-body", active && "font-medium underline decoration-2 underline-offset-4"),
|
|
4505
4827
|
children: alt
|
|
4828
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
4829
|
+
className: cn("type-body", active && "font-medium underline decoration-2 underline-offset-4"),
|
|
4830
|
+
children: alt
|
|
4506
4831
|
}) : /* @__PURE__ */ jsx("p", {
|
|
4507
4832
|
className: "type-body",
|
|
4508
|
-
children: phrase.words.map((w, i) =>
|
|
4509
|
-
|
|
4510
|
-
"
|
|
4511
|
-
|
|
4833
|
+
children: phrase.words.map((w, i) => {
|
|
4834
|
+
const doubt = isDoubtful(w, doubtfulBelow);
|
|
4835
|
+
const looks = cn(doubt && "underline decoration-dotted decoration-2 underline-offset-4", w.correction && "underline decoration-dotted decoration-primary decoration-2 underline-offset-4");
|
|
4836
|
+
const said = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4837
|
+
w.text,
|
|
4838
|
+
doubt && /* @__PURE__ */ jsx(VisuallyHidden, { children: " (doubtful)" }),
|
|
4839
|
+
w.correction && /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
|
|
4840
|
+
" (corrected, was ",
|
|
4841
|
+
w.correction.original,
|
|
4842
|
+
")"
|
|
4843
|
+
] })
|
|
4844
|
+
] });
|
|
4845
|
+
const hint = w.correction ? (el) => onHint(el ? {
|
|
4846
|
+
el,
|
|
4847
|
+
text: `Was “${w.correction.original}”${w.correction.by ? `, corrected by ${w.correction.by}` : ""}`
|
|
4848
|
+
} : null) : void 0;
|
|
4849
|
+
const press = w.correction && onCorrectionPress ? () => onCorrectionPress(phrase.id, i) : onSeek ? () => onSeek(w.start, {
|
|
4512
4850
|
phraseId: phrase.id,
|
|
4513
4851
|
wordIndex: i
|
|
4514
|
-
})
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4852
|
+
}) : void 0;
|
|
4853
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && " ", marking ? /* @__PURE__ */ jsx(Mark, {
|
|
4854
|
+
id: wordId(phrase.id, i),
|
|
4855
|
+
className: cn(looks, i === word && "font-medium"),
|
|
4856
|
+
onClick: w.correction && onCorrectionPress ? press : void 0,
|
|
4857
|
+
onHover: hint,
|
|
4858
|
+
children: said
|
|
4859
|
+
}) : press ? /* @__PURE__ */ jsx(Button$1, {
|
|
4860
|
+
"aria-current": i === word ? "true" : void 0,
|
|
4861
|
+
"data-doubtful": doubt ? "" : void 0,
|
|
4862
|
+
onPress: press,
|
|
4863
|
+
onHoverStart: hint ? (e) => hint(e.target) : void 0,
|
|
4864
|
+
onHoverEnd: hint ? () => hint(null) : void 0,
|
|
4865
|
+
className: cn("rounded-control hover:bg-muted", looks, i === word && "font-medium underline decoration-2 underline-offset-4"),
|
|
4866
|
+
children: said
|
|
4867
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
4868
|
+
"aria-current": i === word ? "true" : void 0,
|
|
4869
|
+
"data-doubtful": doubt ? "" : void 0,
|
|
4870
|
+
onPointerEnter: hint ? (e) => hint(e.currentTarget) : void 0,
|
|
4871
|
+
onPointerLeave: hint ? () => hint(null) : void 0,
|
|
4872
|
+
className: cn("rounded-control", looks, i === word && "font-medium underline decoration-2 underline-offset-4"),
|
|
4873
|
+
children: said
|
|
4874
|
+
})] }, i);
|
|
4875
|
+
})
|
|
4518
4876
|
})]
|
|
4519
4877
|
}),
|
|
4520
4878
|
(commands.length > 0 || actions) && !edit && /* @__PURE__ */ jsxs("div", {
|
|
@@ -4632,7 +4990,7 @@ function clampView(from, span, duration) {
|
|
|
4632
4990
|
return [a, a + s];
|
|
4633
4991
|
}
|
|
4634
4992
|
// src/components/waveform.tsx
|
|
4635
|
-
var TONE$
|
|
4993
|
+
var TONE$1 = {
|
|
4636
4994
|
neutral: {
|
|
4637
4995
|
fill: "var(--muted)",
|
|
4638
4996
|
edge: "var(--muted-foreground)"
|
|
@@ -4966,7 +5324,7 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
|
|
|
4966
5324
|
spans.map((s) => {
|
|
4967
5325
|
const a = clamp$2(px(s.from), 0, width);
|
|
4968
5326
|
const b = clamp$2(px(s.to), 0, width);
|
|
4969
|
-
const tone = TONE$
|
|
5327
|
+
const tone = TONE$1[s.tone ?? "neutral"];
|
|
4970
5328
|
return b > a ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
|
|
4971
5329
|
x: a,
|
|
4972
5330
|
y: 0,
|
|
@@ -5107,8 +5465,8 @@ function Waveform({ label, peaks, source, duration: given, time, onSeek, marks =
|
|
|
5107
5465
|
children: [/* @__PURE__ */ jsx("span", {
|
|
5108
5466
|
className: "h-2 w-3.5 rounded-sm border border-border",
|
|
5109
5467
|
style: {
|
|
5110
|
-
background: TONE$
|
|
5111
|
-
borderTopColor: TONE$
|
|
5468
|
+
background: TONE$1[s.tone ?? "neutral"].fill,
|
|
5469
|
+
borderTopColor: TONE$1[s.tone ?? "neutral"].edge,
|
|
5112
5470
|
borderTopWidth: 3
|
|
5113
5471
|
}
|
|
5114
5472
|
}), s.label]
|
|
@@ -6476,12 +6834,70 @@ function PropertyList({ items, label, className }) {
|
|
|
6476
6834
|
var GROUP_PREFIX = "group";
|
|
6477
6835
|
var groupKey = (group) => `${GROUP_PREFIX}${group}`;
|
|
6478
6836
|
var isGroupKey = (key) => typeof key === "string" && key.startsWith("group");
|
|
6837
|
+
/**
|
|
6838
|
+
* Rows of equal height, each picture at its own shape (Google Photos, Lightroom): fill a row with
|
|
6839
|
+
* pictures at the target height `rowHeight` until it is full, then scale the row's height so it spans
|
|
6840
|
+
* `width` exactly. The last row of a run keeps the target height rather than stretching, so a short
|
|
6841
|
+
* run does not become giant pictures. `padding` is each tile's own padding and border, added to
|
|
6842
|
+
* every tile's width on top of the picture (the picture is `aspect` times the row's height). Returns
|
|
6843
|
+
* the placements and each row's picture height.
|
|
6844
|
+
*/
|
|
6845
|
+
function justifyRows(items, width, rowHeight, gap, padding) {
|
|
6846
|
+
const placed = [];
|
|
6847
|
+
const heights = [];
|
|
6848
|
+
let run = [];
|
|
6849
|
+
const flush = (last) => {
|
|
6850
|
+
if (!run.length) return;
|
|
6851
|
+
const sum = run.reduce((t, i) => t + i.aspect, 0);
|
|
6852
|
+
const room = width - gap * (run.length - 1) - padding * run.length;
|
|
6853
|
+
const h = last ? Math.min(rowHeight, room / sum) : room / sum;
|
|
6854
|
+
let x = 0;
|
|
6855
|
+
for (const i of run) {
|
|
6856
|
+
const w = i.aspect * h + padding;
|
|
6857
|
+
placed.push({
|
|
6858
|
+
key: i.key,
|
|
6859
|
+
x,
|
|
6860
|
+
width: w,
|
|
6861
|
+
row: heights.length
|
|
6862
|
+
});
|
|
6863
|
+
x += w + gap;
|
|
6864
|
+
}
|
|
6865
|
+
heights.push(h);
|
|
6866
|
+
run = [];
|
|
6867
|
+
};
|
|
6868
|
+
for (const item of items) {
|
|
6869
|
+
run.push(item);
|
|
6870
|
+
if (run.reduce((t, i) => t + i.aspect * rowHeight + padding, 0) + gap * (run.length - 1) >= width) flush(false);
|
|
6871
|
+
}
|
|
6872
|
+
flush(true);
|
|
6873
|
+
return {
|
|
6874
|
+
placed,
|
|
6875
|
+
heights
|
|
6876
|
+
};
|
|
6877
|
+
}
|
|
6878
|
+
/**
|
|
6879
|
+
* The copy of the heading to draw at the top of the visible area, or null when the real one is already
|
|
6880
|
+
* there. It is the last heading at or above `top`, moved to `top`, but never lower than the next
|
|
6881
|
+
* heading's top less its own height, so the next heading pushes it up as it arrives.
|
|
6882
|
+
*/
|
|
6883
|
+
function stuckHeader(headers, top) {
|
|
6884
|
+
let current = null;
|
|
6885
|
+
for (const h of headers) if (h.rect.y <= top) current = h;
|
|
6886
|
+
if (!current || current.rect.y === top) return null;
|
|
6887
|
+
const after = headers[headers.indexOf(current) + 1];
|
|
6888
|
+
const y = after ? Math.min(top, after.rect.y - current.rect.height) : top;
|
|
6889
|
+
const copy = current.copy();
|
|
6890
|
+
copy.rect = new Rect(0, y, current.rect.width, current.rect.height);
|
|
6891
|
+
copy.zIndex = 10;
|
|
6892
|
+
return copy;
|
|
6893
|
+
}
|
|
6479
6894
|
/** `GridLayout` with full-width group headings (items keyed by `groupKey`) that stay at the top of the scroll box while their group is in view. */
|
|
6480
6895
|
var GroupedGridLayout = class extends GridLayout {
|
|
6481
6896
|
headers = [];
|
|
6482
6897
|
update(context) {
|
|
6483
6898
|
super.update(context);
|
|
6484
|
-
const
|
|
6899
|
+
const options = context.layoutOptions ?? {};
|
|
6900
|
+
const space = options.minSpace?.height ?? 18;
|
|
6485
6901
|
const width = this.virtualizer.size.width;
|
|
6486
6902
|
const collection = this.virtualizer.collection;
|
|
6487
6903
|
const tiles = [...collection].filter((n) => !isGroupKey(n.key)).map((n) => super.getLayoutInfo(n.key)).filter((l) => l !== null);
|
|
@@ -6489,12 +6905,35 @@ var GroupedGridLayout = class extends GridLayout {
|
|
|
6489
6905
|
const columns = Math.max(1, this.numColumns);
|
|
6490
6906
|
const xs = [...collection].slice(0, columns).map((n) => super.getLayoutInfo(n.key)?.rect.x ?? 0);
|
|
6491
6907
|
const tileHeight = tiles.reduce((h, t) => Math.max(h, t.rect.height), 0) || first?.rect.height || 0;
|
|
6908
|
+
const justify = options.justify;
|
|
6492
6909
|
const next = /* @__PURE__ */ new Map();
|
|
6493
6910
|
this.headers = [];
|
|
6494
6911
|
let y = space;
|
|
6495
6912
|
let col = 0;
|
|
6496
6913
|
let rowInfos = [];
|
|
6914
|
+
let run = [];
|
|
6915
|
+
const endRun = () => {
|
|
6916
|
+
if (!justify || !run.length) return;
|
|
6917
|
+
const { placed, heights } = justifyRows(run.map((r) => ({
|
|
6918
|
+
key: String(r.node.key),
|
|
6919
|
+
aspect: r.aspect
|
|
6920
|
+
})), width, justify.rowHeight, space, justify.padding);
|
|
6921
|
+
const byKey = new Map(run.map((r) => [String(r.node.key), r]));
|
|
6922
|
+
const tops = [];
|
|
6923
|
+
for (const h of heights) {
|
|
6924
|
+
tops.push(y);
|
|
6925
|
+
y += h + justify.chrome + space;
|
|
6926
|
+
}
|
|
6927
|
+
for (const p of placed) {
|
|
6928
|
+
const info = byKey.get(p.key).base.copy();
|
|
6929
|
+
info.rect = new Rect(p.x, tops[p.row], p.width, heights[p.row] + justify.chrome);
|
|
6930
|
+
info.estimatedSize = false;
|
|
6931
|
+
next.set(p.key, info);
|
|
6932
|
+
}
|
|
6933
|
+
run = [];
|
|
6934
|
+
};
|
|
6497
6935
|
const endRow = () => {
|
|
6936
|
+
endRun();
|
|
6498
6937
|
if (!rowInfos.length) return;
|
|
6499
6938
|
const h = rowInfos.reduce((m, l) => Math.max(m, l.rect.height), 0);
|
|
6500
6939
|
for (const l of rowInfos) l.rect.height = h;
|
|
@@ -6517,8 +6956,16 @@ var GroupedGridLayout = class extends GridLayout {
|
|
|
6517
6956
|
}
|
|
6518
6957
|
const base = super.getLayoutInfo(node.key);
|
|
6519
6958
|
if (!base) continue;
|
|
6520
|
-
|
|
6521
|
-
|
|
6959
|
+
if (justify) {
|
|
6960
|
+
run.push({
|
|
6961
|
+
node,
|
|
6962
|
+
base,
|
|
6963
|
+
aspect: justify.aspects.get(key) ?? 1
|
|
6964
|
+
});
|
|
6965
|
+
continue;
|
|
6966
|
+
}
|
|
6967
|
+
const info = base.copy();
|
|
6968
|
+
info.rect = new Rect(xs[col] ?? base.rect.x, y, base.rect.width, Math.max(tileHeight, base.rect.height));
|
|
6522
6969
|
info.estimatedSize = base.estimatedSize;
|
|
6523
6970
|
next.set(key, info);
|
|
6524
6971
|
rowInfos.push(info);
|
|
@@ -6533,12 +6980,9 @@ var GroupedGridLayout = class extends GridLayout {
|
|
|
6533
6980
|
}
|
|
6534
6981
|
getVisibleLayoutInfos(rect) {
|
|
6535
6982
|
const visible = super.getVisibleLayoutInfos(rect);
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
const stuck = current.copy();
|
|
6540
|
-
stuck.rect = new Rect(0, rect.y, current.rect.width, current.rect.height);
|
|
6541
|
-
stuck.zIndex = 10;
|
|
6983
|
+
const stuck = stuckHeader(this.headers, rect.y);
|
|
6984
|
+
if (!stuck) return visible;
|
|
6985
|
+
const current = stuck;
|
|
6542
6986
|
return [...visible.filter((l) => l.key !== current.key), stuck];
|
|
6543
6987
|
}
|
|
6544
6988
|
};
|
|
@@ -6570,6 +7014,10 @@ var tileWidth = (size) => typeof size === "number" ? size : minWidth[size];
|
|
|
6570
7014
|
/** `GridLayout` options for tiles of this size and aspect: they grow from the minimum width to fill the row, and each row is as tall as its tallest tile as measured. */
|
|
6571
7015
|
function tileLayoutOptions(tileSize, aspect) {
|
|
6572
7016
|
const w = tileWidth(tileSize);
|
|
7017
|
+
if (typeof aspect === "number") return {
|
|
7018
|
+
minItemSize: new Size(w, Math.round(w / aspect) + TILE_CHROME),
|
|
7019
|
+
minSpace: new Size(GAP, GAP)
|
|
7020
|
+
};
|
|
6573
7021
|
return {
|
|
6574
7022
|
minItemSize: new Size(w, Math.round(w * aspectRatio[aspect]) + TILE_CHROME),
|
|
6575
7023
|
minSpace: new Size(GAP, GAP)
|
|
@@ -6644,9 +7092,32 @@ function TileGridSkeleton({ count = 12, aspect = "square", tileSize = "md", clas
|
|
|
6644
7092
|
}, i))
|
|
6645
7093
|
});
|
|
6646
7094
|
}
|
|
7095
|
+
/** The loading shape of a `SelectableGrid`: `count` picture boxes at the grid's tile size and shape, for a `DataView` skeleton. With `shapes` (widths over heights, cycled) the boxes are in rows at their own shapes, as `aspect="natural"` draws them. */
|
|
7096
|
+
function SelectableGridSkeleton({ count = 24, aspect = "square", tileSize = "md", shapes, className }) {
|
|
7097
|
+
const px = tileWidth(tileSize);
|
|
7098
|
+
if (shapes?.length) return /* @__PURE__ */ jsx("div", {
|
|
7099
|
+
"aria-hidden": true,
|
|
7100
|
+
className: cn("flex min-w-0 flex-wrap gap-3", className),
|
|
7101
|
+
children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx("div", {
|
|
7102
|
+
className: "p-1.5",
|
|
7103
|
+
style: { width: Math.round(shapes[i % shapes.length] * px) + 14 },
|
|
7104
|
+
children: /* @__PURE__ */ jsx(ThumbnailSkeleton, { aspect: shapes[i % shapes.length] })
|
|
7105
|
+
}, i))
|
|
7106
|
+
});
|
|
7107
|
+
const ratio = typeof aspect === "number" ? aspect : thumbnailAspect[aspect];
|
|
7108
|
+
return /* @__PURE__ */ jsx("div", {
|
|
7109
|
+
"aria-hidden": true,
|
|
7110
|
+
className: cn("grid min-w-0 gap-3", className),
|
|
7111
|
+
style: { gridTemplateColumns: `repeat(auto-fill, minmax(min(${px}px, 100%), 1fr))` },
|
|
7112
|
+
children: Array.from({ length: count }, (_, i) => /* @__PURE__ */ jsx("div", {
|
|
7113
|
+
className: "p-1.5",
|
|
7114
|
+
children: /* @__PURE__ */ jsx(ThumbnailSkeleton, { aspect: ratio })
|
|
7115
|
+
}, i))
|
|
7116
|
+
});
|
|
7117
|
+
}
|
|
6647
7118
|
// src/components/selectable-grid.tsx
|
|
6648
7119
|
/** A grid of pictures to choose from: each tile one labelled target, "Select all shown", Shift-click ranges, virtualised from `virtualizeFrom` tiles. Pair with `useSelection` and a `BulkBar`. */
|
|
6649
|
-
function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, aspect = "square", tileSize = "md", onTileSizeChange, zoomRange = [64, 320], selectionMode = "multiple", selectionBehavior = "toggle", onAction, badge, groupBy, groupHeading, unselectableReason, virtualizeFrom = 100, maxHeight = 480, className }) {
|
|
7120
|
+
function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, aspect = "square", naturalAspect, tileSize = "md", onTileSizeChange, zoomRange = [64, 320], selectionMode = "multiple", selectionBehavior = "toggle", onAction, badge, mark, fit = "cover", groupBy, groupHeading, unselectableReason, virtualizeFrom = 100, maxHeight = 480, className }) {
|
|
6650
7121
|
const select = useSelectRows(rows, rowKey, selection);
|
|
6651
7122
|
const shownKeys = React.useMemo(() => new Set(rows.map(rowKey)), [rows, rowKey]);
|
|
6652
7123
|
const groups = React.useMemo(() => {
|
|
@@ -6664,26 +7135,51 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
|
|
|
6664
7135
|
}));
|
|
6665
7136
|
}, [rows, groupBy]);
|
|
6666
7137
|
const [folded, setFolded] = React.useState(/* @__PURE__ */ new Set());
|
|
6667
|
-
const
|
|
7138
|
+
const natural = aspect === "natural";
|
|
7139
|
+
const ratio = typeof aspect === "number" ? aspect : null;
|
|
7140
|
+
const virtual = natural || Boolean(groups) || rows.length >= virtualizeFrom;
|
|
6668
7141
|
const px = tileWidth(tileSize);
|
|
6669
7142
|
const outer = React.useRef(null);
|
|
6670
7143
|
const hidden = [...selection.selected].filter((k) => !shownKeys.has(k)).length;
|
|
6671
|
-
const keep = React.useRef(
|
|
7144
|
+
const keep = React.useRef({
|
|
7145
|
+
share: null,
|
|
7146
|
+
key: null,
|
|
7147
|
+
offset: 0
|
|
7148
|
+
});
|
|
7149
|
+
const pointerAt = React.useRef(null);
|
|
6672
7150
|
const scrollBox = () => outer.current?.querySelector("[data-strata-scroll]") ?? null;
|
|
6673
7151
|
const zoom = (next) => {
|
|
6674
7152
|
if (!onTileSizeChange) return;
|
|
6675
7153
|
const clamped = Math.round(Math.min(zoomRange[1], Math.max(zoomRange[0], next)));
|
|
6676
7154
|
if (clamped === px) return;
|
|
6677
7155
|
const box = scrollBox();
|
|
6678
|
-
|
|
7156
|
+
const p = pointerAt.current;
|
|
7157
|
+
const under = p ? document.elementFromPoint?.(p.x, p.y)?.closest("[data-key]") : null;
|
|
7158
|
+
const anchor = under && outer.current?.contains(under) ? under : document.activeElement?.closest("[data-key]") ?? null;
|
|
7159
|
+
keep.current = {
|
|
7160
|
+
share: box && box.scrollHeight > 0 ? box.scrollTop / box.scrollHeight : null,
|
|
7161
|
+
key: anchor && !isGroupKey(anchor.getAttribute("data-key")) ? anchor.getAttribute("data-key") : null,
|
|
7162
|
+
offset: box && anchor ? anchor.getBoundingClientRect().top - box.getBoundingClientRect().top : 0
|
|
7163
|
+
};
|
|
6679
7164
|
onTileSizeChange(clamped);
|
|
6680
7165
|
};
|
|
6681
7166
|
const zoomRef = React.useRef(zoom);
|
|
6682
7167
|
zoomRef.current = zoom;
|
|
6683
7168
|
React.useLayoutEffect(() => {
|
|
6684
7169
|
const box = scrollBox();
|
|
6685
|
-
|
|
6686
|
-
|
|
7170
|
+
const { share, key, offset } = keep.current;
|
|
7171
|
+
if (box && share !== null) box.scrollTop = share * box.scrollHeight;
|
|
7172
|
+
keep.current = {
|
|
7173
|
+
share: null,
|
|
7174
|
+
key: null,
|
|
7175
|
+
offset: 0
|
|
7176
|
+
};
|
|
7177
|
+
if (!box || !key) return;
|
|
7178
|
+
const frame = requestAnimationFrame(() => {
|
|
7179
|
+
const el = [...box.querySelectorAll("[data-key]")].find((n) => n.getAttribute("data-key") === key);
|
|
7180
|
+
if (el) box.scrollTop += el.getBoundingClientRect().top - box.getBoundingClientRect().top - offset;
|
|
7181
|
+
});
|
|
7182
|
+
return () => cancelAnimationFrame(frame);
|
|
6687
7183
|
}, [px]);
|
|
6688
7184
|
React.useEffect(() => {
|
|
6689
7185
|
const el = outer.current;
|
|
@@ -6691,12 +7187,132 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
|
|
|
6691
7187
|
const onWheel = (e) => {
|
|
6692
7188
|
if (!e.ctrlKey && !e.metaKey) return;
|
|
6693
7189
|
e.preventDefault();
|
|
7190
|
+
pointerAt.current = {
|
|
7191
|
+
x: e.clientX,
|
|
7192
|
+
y: e.clientY
|
|
7193
|
+
};
|
|
6694
7194
|
zoomRef.current(px * (e.deltaY < 0 ? 1.1 : 1 / 1.1));
|
|
6695
7195
|
};
|
|
6696
7196
|
el.addEventListener("wheel", onWheel, { passive: false });
|
|
6697
7197
|
return () => el.removeEventListener("wheel", onWheel);
|
|
6698
7198
|
}, [px, Boolean(onTileSizeChange)]);
|
|
7199
|
+
const pinch = React.useRef(null);
|
|
7200
|
+
React.useEffect(() => {
|
|
7201
|
+
const el = outer.current;
|
|
7202
|
+
if (!el || !onTileSizeChange) return;
|
|
7203
|
+
const distance = (t) => Math.hypot(t[0].clientX - t[1].clientX, t[0].clientY - t[1].clientY);
|
|
7204
|
+
const onStart = (e) => void (pinch.current = e.touches.length === 2 ? {
|
|
7205
|
+
distance: distance(e.touches),
|
|
7206
|
+
px
|
|
7207
|
+
} : null);
|
|
7208
|
+
const onMove = (e) => {
|
|
7209
|
+
const start = pinch.current;
|
|
7210
|
+
if (!start || e.touches.length !== 2 || start.distance === 0) return;
|
|
7211
|
+
e.preventDefault();
|
|
7212
|
+
zoomRef.current(start.px * (distance(e.touches) / start.distance));
|
|
7213
|
+
};
|
|
7214
|
+
const onEnd = (e) => void (e.touches.length < 2 && (pinch.current = null));
|
|
7215
|
+
el.addEventListener("touchstart", onStart, { passive: true });
|
|
7216
|
+
el.addEventListener("touchmove", onMove, { passive: false });
|
|
7217
|
+
el.addEventListener("touchend", onEnd);
|
|
7218
|
+
el.addEventListener("touchcancel", onEnd);
|
|
7219
|
+
return () => {
|
|
7220
|
+
el.removeEventListener("touchstart", onStart);
|
|
7221
|
+
el.removeEventListener("touchmove", onMove);
|
|
7222
|
+
el.removeEventListener("touchend", onEnd);
|
|
7223
|
+
el.removeEventListener("touchcancel", onEnd);
|
|
7224
|
+
};
|
|
7225
|
+
}, [Boolean(onTileSizeChange)]);
|
|
7226
|
+
const [marquee, setMarquee] = React.useState(null);
|
|
7227
|
+
const startMarquee = (e) => {
|
|
7228
|
+
if (selectionMode !== "multiple" || e.button !== 0 || e.pointerType === "touch") return;
|
|
7229
|
+
const target = e.target;
|
|
7230
|
+
if (!target.closest("[data-strata-scroll]") || target.closest("[data-key], button, input, a")) return;
|
|
7231
|
+
const root = outer.current;
|
|
7232
|
+
const scroller = scrollBox();
|
|
7233
|
+
if (!root || !scroller) return;
|
|
7234
|
+
const additive = e.ctrlKey || e.metaKey || e.shiftKey;
|
|
7235
|
+
const base = new Set([...selection.selected].filter((k) => additive || !shownKeys.has(k)));
|
|
7236
|
+
const origin = () => {
|
|
7237
|
+
const r = scroller.getBoundingClientRect();
|
|
7238
|
+
return {
|
|
7239
|
+
x: r.left - scroller.scrollLeft,
|
|
7240
|
+
y: r.top - scroller.scrollTop
|
|
7241
|
+
};
|
|
7242
|
+
};
|
|
7243
|
+
const o0 = origin();
|
|
7244
|
+
const start = {
|
|
7245
|
+
x: e.clientX - o0.x,
|
|
7246
|
+
y: e.clientY - o0.y
|
|
7247
|
+
};
|
|
7248
|
+
const seen = /* @__PURE__ */ new Map();
|
|
7249
|
+
let pointer = {
|
|
7250
|
+
x: e.clientX,
|
|
7251
|
+
y: e.clientY
|
|
7252
|
+
};
|
|
7253
|
+
let moved = false;
|
|
7254
|
+
let frame = 0;
|
|
7255
|
+
const update = () => {
|
|
7256
|
+
const o = origin();
|
|
7257
|
+
for (const el of root.querySelectorAll("[data-key]")) {
|
|
7258
|
+
const key = el.getAttribute("data-key");
|
|
7259
|
+
if (isGroupKey(key) || !byKey.has(key) || disabledSet.has(key)) continue;
|
|
7260
|
+
const box = el.getBoundingClientRect();
|
|
7261
|
+
seen.set(key, {
|
|
7262
|
+
l: box.left - o.x,
|
|
7263
|
+
r: box.right - o.x,
|
|
7264
|
+
t: box.top - o.y,
|
|
7265
|
+
b: box.bottom - o.y
|
|
7266
|
+
});
|
|
7267
|
+
}
|
|
7268
|
+
const cur = {
|
|
7269
|
+
x: pointer.x - o.x,
|
|
7270
|
+
y: pointer.y - o.y
|
|
7271
|
+
};
|
|
7272
|
+
const l = Math.min(start.x, cur.x), r = Math.max(start.x, cur.x), t = Math.min(start.y, cur.y), b = Math.max(start.y, cur.y);
|
|
7273
|
+
const chosen = new Set(base);
|
|
7274
|
+
for (const [key, box] of seen) if (box.l < r && box.r > l && box.t < b && box.b > t) chosen.add(key);
|
|
7275
|
+
selection.onChange(chosen);
|
|
7276
|
+
setMarquee({
|
|
7277
|
+
x0: start.x + o.x,
|
|
7278
|
+
y0: start.y + o.y,
|
|
7279
|
+
x1: pointer.x,
|
|
7280
|
+
y1: pointer.y
|
|
7281
|
+
});
|
|
7282
|
+
};
|
|
7283
|
+
const tick = () => {
|
|
7284
|
+
const r = scroller.getBoundingClientRect();
|
|
7285
|
+
const edge = 40;
|
|
7286
|
+
const delta = pointer.y < r.top + edge ? -(r.top + edge - pointer.y) : pointer.y > r.bottom - edge ? pointer.y - (r.bottom - edge) : 0;
|
|
7287
|
+
if (delta) scroller.scrollTop += Math.max(-24, Math.min(24, delta / 2));
|
|
7288
|
+
update();
|
|
7289
|
+
frame = requestAnimationFrame(tick);
|
|
7290
|
+
};
|
|
7291
|
+
const move = (m) => {
|
|
7292
|
+
pointer = {
|
|
7293
|
+
x: m.clientX,
|
|
7294
|
+
y: m.clientY
|
|
7295
|
+
};
|
|
7296
|
+
if (!moved && Math.hypot(m.clientX - e.clientX, m.clientY - e.clientY) < 4) return;
|
|
7297
|
+
if (!moved) {
|
|
7298
|
+
moved = true;
|
|
7299
|
+
frame = requestAnimationFrame(tick);
|
|
7300
|
+
}
|
|
7301
|
+
update();
|
|
7302
|
+
};
|
|
7303
|
+
const up = () => {
|
|
7304
|
+
cancelAnimationFrame(frame);
|
|
7305
|
+
window.removeEventListener("pointermove", move);
|
|
7306
|
+
window.removeEventListener("pointerup", up);
|
|
7307
|
+
window.removeEventListener("pointercancel", up);
|
|
7308
|
+
setMarquee(null);
|
|
7309
|
+
};
|
|
7310
|
+
window.addEventListener("pointermove", move);
|
|
7311
|
+
window.addEventListener("pointerup", up);
|
|
7312
|
+
window.addEventListener("pointercancel", up);
|
|
7313
|
+
};
|
|
6699
7314
|
const disabledKeys = rows.filter((r) => !(selection.isSelectable?.(r) ?? true)).map(rowKey);
|
|
7315
|
+
const disabledSet = new Set(disabledKeys);
|
|
6700
7316
|
const shift = useShiftNote();
|
|
6701
7317
|
const pressed = React.useRef(null);
|
|
6702
7318
|
const notePress = (e) => void (pressed.current = e.target.closest("[data-key]")?.getAttribute("data-key") ?? null);
|
|
@@ -6715,7 +7331,25 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
|
|
|
6715
7331
|
const picked = next === "all" ? rows.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey) : [...next].map(String).filter((k) => shownKeys.has(k));
|
|
6716
7332
|
selection.onChange(/* @__PURE__ */ new Set([...outside, ...picked]));
|
|
6717
7333
|
};
|
|
6718
|
-
const
|
|
7334
|
+
const hasDetail = Boolean(detail);
|
|
7335
|
+
const layoutOptions = React.useMemo(() => {
|
|
7336
|
+
if (aspect !== "natural") return tileLayoutOptions(px, aspect);
|
|
7337
|
+
const aspects = new Map(rows.map((r) => [rowKey(r), Math.max(.1, naturalAspect?.(r) ?? 1)]));
|
|
7338
|
+
return {
|
|
7339
|
+
...tileLayoutOptions(px, "square"),
|
|
7340
|
+
justify: {
|
|
7341
|
+
aspects,
|
|
7342
|
+
rowHeight: px,
|
|
7343
|
+
padding: 14,
|
|
7344
|
+
chrome: hasDetail ? 40 : 14
|
|
7345
|
+
}
|
|
7346
|
+
};
|
|
7347
|
+
}, [
|
|
7348
|
+
px,
|
|
7349
|
+
aspect,
|
|
7350
|
+
rows,
|
|
7351
|
+
hasDetail
|
|
7352
|
+
]);
|
|
6719
7353
|
const byKey = React.useMemo(() => new Map(rows.map((r) => [rowKey(r), r])), [rows, rowKey]);
|
|
6720
7354
|
const indexOf = React.useMemo(() => new Map(rows.map((r, i) => [rowKey(r), i])), [rows, rowKey]);
|
|
6721
7355
|
const changeOne = (next) => {
|
|
@@ -6749,15 +7383,24 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
|
|
|
6749
7383
|
const unselectable = !(selection.isSelectable?.(row) ?? true);
|
|
6750
7384
|
const why = unselectableReason && unselectable ? unselectableReason(row) : void 0;
|
|
6751
7385
|
const corner = badge?.(row);
|
|
7386
|
+
const second = mark?.(row);
|
|
6752
7387
|
return /* @__PURE__ */ jsxs(GridListItem, {
|
|
6753
7388
|
id: key,
|
|
6754
7389
|
textValue: name,
|
|
7390
|
+
"aria-label": why ? `${name}, ${why}` : void 0,
|
|
6755
7391
|
"data-index": index,
|
|
6756
7392
|
className: cn("group relative grid min-w-0 gap-1.5 rounded-surface border border-transparent p-1.5 select-none outline-offset-2 transition-state", "selected:border-primary selected:bg-surface-sunken", unselectable ? "cursor-not-allowed opacity-50" : "cursor-pointer hover:bg-surface-sunken"),
|
|
6757
7393
|
children: [
|
|
6758
|
-
/* @__PURE__ */
|
|
6759
|
-
className:
|
|
6760
|
-
children:
|
|
7394
|
+
/* @__PURE__ */ jsxs("span", {
|
|
7395
|
+
className: "relative block",
|
|
7396
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
7397
|
+
className: cn("block overflow-hidden rounded-control bg-muted *:size-full", fit === "contain" ? "*:object-contain" : "*:object-cover", !natural && ratio === null && aspectClass[aspect]),
|
|
7398
|
+
style: natural ? { aspectRatio: Math.max(.1, naturalAspect?.(row) ?? 1) } : ratio !== null ? { aspectRatio: ratio } : void 0,
|
|
7399
|
+
children: renderImage(row)
|
|
7400
|
+
}), second != null && /* @__PURE__ */ jsx("span", {
|
|
7401
|
+
className: "absolute right-1.5 bottom-1.5 rounded-control bg-background/90 px-1.5 type-caption text-foreground tabular-nums",
|
|
7402
|
+
children: second
|
|
7403
|
+
})]
|
|
6761
7404
|
}),
|
|
6762
7405
|
selectionMode === "multiple" && /* @__PURE__ */ jsx(TileBox, { label: `Select ${name}` }),
|
|
6763
7406
|
corner != null && /* @__PURE__ */ jsx("span", {
|
|
@@ -6831,6 +7474,11 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
|
|
|
6831
7474
|
return /* @__PURE__ */ jsxs("div", {
|
|
6832
7475
|
ref: outer,
|
|
6833
7476
|
className: cn("grid min-w-0 gap-3", className),
|
|
7477
|
+
onPointerDown: startMarquee,
|
|
7478
|
+
onPointerMove: (e) => void (pointerAt.current = {
|
|
7479
|
+
x: e.clientX,
|
|
7480
|
+
y: e.clientY
|
|
7481
|
+
}),
|
|
6834
7482
|
onMouseDownCapture: (e) => {
|
|
6835
7483
|
shift.handlers.onMouseDown(e);
|
|
6836
7484
|
notePress(e);
|
|
@@ -6853,28 +7501,41 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
|
|
|
6853
7501
|
else return;
|
|
6854
7502
|
e.preventDefault();
|
|
6855
7503
|
},
|
|
6856
|
-
children: [
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
7504
|
+
children: [
|
|
7505
|
+
selectionMode === "multiple" && /* @__PURE__ */ jsxs("div", {
|
|
7506
|
+
className: "flex flex-wrap items-center gap-3",
|
|
7507
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
7508
|
+
label: "Select all shown",
|
|
7509
|
+
checked: select.all.checked,
|
|
7510
|
+
disabled: select.all.disabled,
|
|
7511
|
+
onCheckedChange: select.all.toggle
|
|
7512
|
+
}), hidden > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
7513
|
+
role: "status",
|
|
7514
|
+
className: "type-body-sm text-muted-foreground",
|
|
7515
|
+
children: hidden === 1 ? "1 chosen is hidden by the filter" : `${hidden} chosen are hidden by the filter`
|
|
7516
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
7517
|
+
size: "sm",
|
|
7518
|
+
variant: "ghost",
|
|
7519
|
+
onPress: () => selection.onChange(new Set([...selection.selected].filter((k) => shownKeys.has(k)))),
|
|
7520
|
+
children: "Clear hidden"
|
|
7521
|
+
})] })]
|
|
7522
|
+
}),
|
|
7523
|
+
marquee && /* @__PURE__ */ jsx("div", {
|
|
7524
|
+
"aria-hidden": true,
|
|
7525
|
+
className: "pointer-events-none fixed z-50 border border-primary bg-primary/10",
|
|
7526
|
+
style: {
|
|
7527
|
+
left: Math.min(marquee.x0, marquee.x1),
|
|
7528
|
+
top: Math.min(marquee.y0, marquee.y1),
|
|
7529
|
+
width: Math.abs(marquee.x1 - marquee.x0),
|
|
7530
|
+
height: Math.abs(marquee.y1 - marquee.y0)
|
|
7531
|
+
}
|
|
7532
|
+
}),
|
|
7533
|
+
virtual ? /* @__PURE__ */ jsx(Virtualizer, {
|
|
7534
|
+
layout: groups || natural ? GroupedGridLayout : GridLayout,
|
|
7535
|
+
layoutOptions,
|
|
7536
|
+
children: grid
|
|
7537
|
+
}) : grid
|
|
7538
|
+
]
|
|
6878
7539
|
});
|
|
6879
7540
|
}
|
|
6880
7541
|
function TileBox({ label }) {
|
|
@@ -13089,6 +13750,7 @@ function Conversation({ label, turns, answerName, personName = "You", entities,
|
|
|
13089
13750
|
last?.text,
|
|
13090
13751
|
last?.state,
|
|
13091
13752
|
last?.role,
|
|
13753
|
+
last?.images?.length,
|
|
13092
13754
|
toBottom
|
|
13093
13755
|
]);
|
|
13094
13756
|
const states = React.useRef(/* @__PURE__ */ new Map());
|
|
@@ -13135,6 +13797,33 @@ function Conversation({ label, turns, answerName, personName = "You", entities,
|
|
|
13135
13797
|
onOpen,
|
|
13136
13798
|
children: t.text
|
|
13137
13799
|
}),
|
|
13800
|
+
t.images && t.images.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
13801
|
+
className: "mt-2 flex flex-wrap gap-2",
|
|
13802
|
+
children: t.images.map((im, i) => {
|
|
13803
|
+
const pic = /* @__PURE__ */ jsx(Thumbnail, {
|
|
13804
|
+
src: im.src,
|
|
13805
|
+
alt: im.label,
|
|
13806
|
+
missing: "Picture not available",
|
|
13807
|
+
aspect: im.aspect ?? "16/9",
|
|
13808
|
+
fit: "contain",
|
|
13809
|
+
className: "w-56 max-w-full rounded-control bg-muted"
|
|
13810
|
+
});
|
|
13811
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
13812
|
+
className: "flex max-w-full flex-col gap-1",
|
|
13813
|
+
children: [im.href ? /* @__PURE__ */ jsx("a", {
|
|
13814
|
+
href: im.href,
|
|
13815
|
+
target: "_blank",
|
|
13816
|
+
rel: "noreferrer",
|
|
13817
|
+
"aria-label": `${im.label} (full size, opens in a new tab)`,
|
|
13818
|
+
className: "rounded-control",
|
|
13819
|
+
children: pic
|
|
13820
|
+
}) : pic, /* @__PURE__ */ jsx("span", {
|
|
13821
|
+
className: "type-caption text-muted-foreground",
|
|
13822
|
+
children: im.label
|
|
13823
|
+
})]
|
|
13824
|
+
}, `${i}-${im.src}`);
|
|
13825
|
+
})
|
|
13826
|
+
}),
|
|
13138
13827
|
t.state === "streaming" && t.text && /* @__PURE__ */ jsx("p", {
|
|
13139
13828
|
className: "mt-1 type-caption text-muted-foreground",
|
|
13140
13829
|
children: "Still writing…"
|
|
@@ -13466,7 +14155,7 @@ function moveGutter(left, right, dx, { bounds, min }) {
|
|
|
13466
14155
|
}];
|
|
13467
14156
|
}
|
|
13468
14157
|
// src/components/region-editor.tsx
|
|
13469
|
-
var TONE
|
|
14158
|
+
var TONE = {
|
|
13470
14159
|
neutral: {
|
|
13471
14160
|
edge: "var(--foreground)",
|
|
13472
14161
|
fill: "var(--muted)"
|
|
@@ -13885,7 +14574,7 @@ function RegionEditor({ label, children, size, regions, onChange, selectedId, on
|
|
|
13885
14574
|
})]
|
|
13886
14575
|
}),
|
|
13887
14576
|
shown.map((r) => {
|
|
13888
|
-
const tone = TONE
|
|
14577
|
+
const tone = TONE[r.tone ?? "neutral"];
|
|
13889
14578
|
const active = r.id === selected;
|
|
13890
14579
|
return /* @__PURE__ */ jsxs("div", {
|
|
13891
14580
|
role: "group",
|
|
@@ -14547,1212 +15236,937 @@ function BoxList({ label, boxes, state, renderBox, className }) {
|
|
|
14547
15236
|
return /* @__PURE__ */ jsx(ListBox, {
|
|
14548
15237
|
ref,
|
|
14549
15238
|
"aria-label": label,
|
|
14550
|
-
selectionMode: "single",
|
|
14551
|
-
disallowEmptySelection: true,
|
|
14552
|
-
selectedKeys: state.active ? [state.active] : [],
|
|
14553
|
-
onSelectionChange: (keys) => {
|
|
14554
|
-
const id = [...keys][0];
|
|
14555
|
-
if (id !== void 0) state.choose(String(id), "list");
|
|
14556
|
-
},
|
|
14557
|
-
className: cn("min-w-0 overflow-y-auto rounded-surface border border-border", className),
|
|
14558
|
-
children: order.map((id) => {
|
|
14559
|
-
const b = byId.get(id);
|
|
14560
|
-
return /* @__PURE__ */ jsx(ListBoxItem, {
|
|
14561
|
-
id,
|
|
14562
|
-
textValue: b.label,
|
|
14563
|
-
onHoverStart: () => state.point(id),
|
|
14564
|
-
onHoverEnd: () => state.point(null),
|
|
14565
|
-
className: cn("flex cursor-pointer items-baseline gap-2 border-l-2 px-3 py-1.5 type-body-sm outline-offset-[-2px] transition-state", "selected:bg-surface-sunken selected:font-medium hover:bg-surface-sunken", state.pointed === id && "bg-surface-sunken"),
|
|
14566
|
-
style: { borderLeftColor: (b.tone ?? "neutral") === "neutral" ? "transparent" : STROKE[b.tone ?? "neutral"] },
|
|
14567
|
-
children: renderBox ? renderBox(b) : b.label
|
|
14568
|
-
}, id);
|
|
14569
|
-
})
|
|
14570
|
-
});
|
|
14571
|
-
}
|
|
14572
|
-
// src/lib/sequence.ts
|
|
14573
|
-
var EPS = 1e-9;
|
|
14574
|
-
/** The grid point nearest to `time`, or `time` itself when there is no grid. */
|
|
14575
|
-
function snapToGrid(time, grid) {
|
|
14576
|
-
if (grid === void 0) return time;
|
|
14577
|
-
if (typeof grid === "number") return grid > 0 ? tidy(Math.round(time / grid) * grid) : time;
|
|
14578
|
-
let best = time;
|
|
14579
|
-
let gap = Infinity;
|
|
14580
|
-
for (const p of grid) if (Math.abs(p - time) < gap) [best, gap] = [p, Math.abs(p - time)];
|
|
14581
|
-
return best;
|
|
14582
|
-
}
|
|
14583
|
-
/** The next grid point after `time` in a direction (`1` later, `-1` earlier); `fallback` is the step when there is no grid. A point `time` is already on is stepped past. */
|
|
14584
|
-
function stepOnGrid(time, dir, grid, fallback) {
|
|
14585
|
-
if (grid === void 0) return tidy(time + dir * fallback);
|
|
14586
|
-
if (typeof grid === "number") {
|
|
14587
|
-
if (grid <= 0) return tidy(time + dir * fallback);
|
|
14588
|
-
return tidy((dir > 0 ? Math.floor(time / grid + EPS) + 1 : Math.ceil(time / grid - EPS) - 1) * grid);
|
|
14589
|
-
}
|
|
14590
|
-
const points = [...grid].sort((a, b) => a - b);
|
|
14591
|
-
return (dir > 0 ? points.find((p) => p > time + EPS) : [...points].reverse().find((p) => p < time - EPS)) ?? tidy(time + dir * fallback);
|
|
14592
|
-
}
|
|
14593
|
-
/** Grid points inside `[from, to]`, for drawing on a ruler. At most `limit`, so a fine grid on a long axis stays cheap. */
|
|
14594
|
-
function gridPoints(grid, from, to, limit = 2e3) {
|
|
14595
|
-
if (grid === void 0) return [];
|
|
14596
|
-
if (typeof grid !== "number") return grid.filter((p) => p >= from - EPS && p <= to + EPS).slice(0, limit);
|
|
14597
|
-
if (grid <= 0) return [];
|
|
14598
|
-
const out = [];
|
|
14599
|
-
for (let i = Math.ceil(from / grid - EPS); i * grid <= to + EPS && out.length < limit; i++) out.push(tidy(i * grid) || 0);
|
|
14600
|
-
return out;
|
|
14601
|
-
}
|
|
14602
|
-
/** Puts `time` inside the room, and says which end held it (with the app's reason) when one did. */
|
|
14603
|
-
function clampToRoom(time, room) {
|
|
14604
|
-
const t = clamp$1(time, room.min, room.max);
|
|
14605
|
-
if (t > time + EPS) return {
|
|
14606
|
-
time: t,
|
|
14607
|
-
limit: {
|
|
14608
|
-
side: "min",
|
|
14609
|
-
at: room.min,
|
|
14610
|
-
reason: room.minReason
|
|
14611
|
-
}
|
|
14612
|
-
};
|
|
14613
|
-
if (t < time - EPS) return {
|
|
14614
|
-
time: t,
|
|
14615
|
-
limit: {
|
|
14616
|
-
side: "max",
|
|
14617
|
-
at: room.max,
|
|
14618
|
-
reason: room.maxReason
|
|
14619
|
-
}
|
|
14620
|
-
};
|
|
14621
|
-
return {
|
|
14622
|
-
time: t,
|
|
14623
|
-
limit: null
|
|
14624
|
-
};
|
|
14625
|
-
}
|
|
14626
|
-
/** Where a dragged cut lands: held by the room (saying which end, if the pointer is beyond it), otherwise snapped to the grid, and never to a grid point outside the room. */
|
|
14627
|
-
function settleCut(wanted, grid, room) {
|
|
14628
|
-
const held = clampToRoom(wanted, room);
|
|
14629
|
-
const snapped = snapToGrid(held.time, grid);
|
|
14630
|
-
return {
|
|
14631
|
-
time: snapped >= room.min - EPS && snapped <= room.max + EPS ? snapped : held.time,
|
|
14632
|
-
limit: held.limit
|
|
14633
|
-
};
|
|
14634
|
-
}
|
|
14635
|
-
// src/components/sequence-timeline.tsx
|
|
14636
|
-
var seconds = (n) => `${tidy(Math.round(n * 10) / 10)} s`;
|
|
14637
|
-
var at = (t) => tickLabel(t, .1);
|
|
14638
|
-
/** A gapless strip of windows whose cuts are dragged or stepped, snapping to a beat grid inside the room the app gives; each cut is a slider that announces both windows' new lengths; Shift+click chooses a run. */
|
|
14639
|
-
function SequenceTimeline({ label, items, zoom, onCutChange, room, minLength = .1, grid, step = .1, selected = [], onSelectRange, renderItem, height = "5rem", className }) {
|
|
14640
|
-
const start = items[0]?.start ?? 0;
|
|
14641
|
-
const end = items[items.length - 1]?.end ?? 0;
|
|
14642
|
-
const span = Math.max(end - start, 1e-6);
|
|
14643
|
-
const track = React.useRef(null);
|
|
14644
|
-
const [fit, setFit] = React.useState(800);
|
|
14645
|
-
React.useLayoutEffect(() => {
|
|
14646
|
-
const el = track.current?.parentElement;
|
|
14647
|
-
if (!el || typeof ResizeObserver === "undefined") return;
|
|
14648
|
-
const read = () => setFit(el.clientWidth || 800);
|
|
14649
|
-
read();
|
|
14650
|
-
const ro = new ResizeObserver(read);
|
|
14651
|
-
ro.observe(el);
|
|
14652
|
-
return () => ro.disconnect();
|
|
14653
|
-
}, []);
|
|
14654
|
-
const pxPerUnit = zoom ?? fit / span;
|
|
14655
|
-
const [drag, setDrag] = React.useState(null);
|
|
14656
|
-
const [said, setSaid] = React.useState("");
|
|
14657
|
-
const anchor = React.useRef(null);
|
|
14658
|
-
const roomFor = React.useCallback((i) => room?.(i) ?? {
|
|
14659
|
-
min: items[i].start + minLength,
|
|
14660
|
-
max: items[i + 1].end - minLength
|
|
14661
|
-
}, [
|
|
14662
|
-
room,
|
|
14663
|
-
items,
|
|
14664
|
-
minLength
|
|
14665
|
-
]);
|
|
14666
|
-
const view = items.map((it, i) => ({
|
|
14667
|
-
...it,
|
|
14668
|
-
start: drag && drag.index === i - 1 ? drag.time : it.start,
|
|
14669
|
-
end: drag && drag.index === i ? drag.time : it.end
|
|
14670
|
-
}));
|
|
14671
|
-
const change = (i, time) => ({
|
|
14672
|
-
before: {
|
|
14673
|
-
...items[i],
|
|
14674
|
-
end: time
|
|
14675
|
-
},
|
|
14676
|
-
after: {
|
|
14677
|
-
...items[i + 1],
|
|
14678
|
-
start: time
|
|
14679
|
-
}
|
|
14680
|
-
});
|
|
14681
|
-
const words = (i, time) => `Cut ${i + 1} moved to ${at(time)}. Window ${i + 1} is ${seconds(time - items[i].start)}, window ${i + 2} is ${seconds(items[i + 1].end - time)}.`;
|
|
14682
|
-
const timeAt = (clientX) => {
|
|
14683
|
-
const box = track.current?.getBoundingClientRect();
|
|
14684
|
-
if (!box || !box.width) return start;
|
|
14685
|
-
return start + (clientX - box.left) / box.width * span;
|
|
14686
|
-
};
|
|
14687
|
-
const keys = (e, i) => {
|
|
14688
|
-
const r = roomFor(i);
|
|
14689
|
-
const now = items[i].end;
|
|
14690
|
-
let target = null;
|
|
14691
|
-
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
14692
|
-
const dir = e.key === "ArrowRight" ? 1 : -1;
|
|
14693
|
-
target = e.shiftKey ? now + dir : stepOnGrid(now, dir, grid, step);
|
|
14694
|
-
} else if (e.key === "Home") target = r.min;
|
|
14695
|
-
else if (e.key === "End") target = r.max;
|
|
14696
|
-
if (target === null) return;
|
|
14697
|
-
e.preventDefault();
|
|
14698
|
-
const { time, limit } = clampToRoom(tidy(target), r);
|
|
14699
|
-
if (Math.abs(time - now) < 1e-9) {
|
|
14700
|
-
const why = limit?.reason ?? (e.key === "End" || e.key === "ArrowRight" ? r.maxReason : r.minReason);
|
|
14701
|
-
setSaid(`Cut ${i + 1} stays at ${at(now)}.${why ? ` ${why}` : ""}`);
|
|
14702
|
-
return;
|
|
14703
|
-
}
|
|
14704
|
-
onCutChange(i, time, change(i, time));
|
|
14705
|
-
setSaid(words(i, time) + (limit?.reason ? ` ${limit.reason}` : ""));
|
|
14706
|
-
};
|
|
14707
|
-
const begin = (e, i) => {
|
|
14708
|
-
if (e.button !== 0) return;
|
|
14709
|
-
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
14710
|
-
setDrag({
|
|
14711
|
-
index: i,
|
|
14712
|
-
time: items[i].end,
|
|
14713
|
-
refused: null
|
|
14714
|
-
});
|
|
14715
|
-
};
|
|
14716
|
-
const drive = (e) => {
|
|
14717
|
-
if (!drag) return;
|
|
14718
|
-
const { time, limit } = settleCut(timeAt(e.clientX), grid, roomFor(drag.index));
|
|
14719
|
-
setDrag({
|
|
14720
|
-
index: drag.index,
|
|
14721
|
-
time,
|
|
14722
|
-
refused: limit ? `Cut ${drag.index + 1} stops at ${at(limit.at)}.${limit.reason ? ` ${limit.reason}` : ""}` : null
|
|
14723
|
-
});
|
|
14724
|
-
};
|
|
14725
|
-
const release = () => {
|
|
14726
|
-
if (!drag) return;
|
|
14727
|
-
const d = drag;
|
|
14728
|
-
setDrag(null);
|
|
14729
|
-
if (Math.abs(d.time - items[d.index].end) > 1e-9) {
|
|
14730
|
-
onCutChange(d.index, d.time, change(d.index, d.time));
|
|
14731
|
-
setSaid(words(d.index, d.time) + (d.refused ? ` ${d.refused}` : ""));
|
|
14732
|
-
} else if (d.refused) setSaid(d.refused);
|
|
14733
|
-
};
|
|
14734
|
-
const step0 = tickStep(pxPerUnit);
|
|
14735
|
-
const ticks = ticksBetween(start, end, step0);
|
|
14736
|
-
const all = gridPoints(grid, start, end);
|
|
14737
|
-
const beats = (end - start) / Math.max(all.length, 1) * pxPerUnit >= 4 ? all : [];
|
|
14738
|
-
const pct = (t) => `${(t - start) / span * 100}%`;
|
|
14739
|
-
const choose = (e, id) => {
|
|
14740
|
-
if (!onSelectRange) return;
|
|
14741
|
-
const here = items.findIndex((x) => x.id === id);
|
|
14742
|
-
const from = anchor.current ? items.findIndex((x) => x.id === anchor.current) : -1;
|
|
14743
|
-
if (e.shiftKey && from >= 0) {
|
|
14744
|
-
const [a, b] = from <= here ? [from, here] : [here, from];
|
|
14745
|
-
onSelectRange(items.slice(a, b + 1).map((x) => x.id));
|
|
14746
|
-
} else {
|
|
14747
|
-
anchor.current = id;
|
|
14748
|
-
onSelectRange([id]);
|
|
14749
|
-
}
|
|
14750
|
-
};
|
|
14751
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
14752
|
-
className: cn("min-w-0", className),
|
|
14753
|
-
children: [
|
|
14754
|
-
/* @__PURE__ */ jsx("div", {
|
|
14755
|
-
role: "group",
|
|
14756
|
-
"aria-label": label,
|
|
14757
|
-
className: "overflow-x-auto pb-2",
|
|
14758
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
14759
|
-
ref: track,
|
|
14760
|
-
className: "relative",
|
|
14761
|
-
style: { width: zoom ? `${span * zoom}px` : "100%" },
|
|
14762
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
14763
|
-
"aria-hidden": true,
|
|
14764
|
-
className: "relative h-6 border-b border-border",
|
|
14765
|
-
children: [ticks.map((t) => /* @__PURE__ */ jsx("span", {
|
|
14766
|
-
className: "absolute top-0 -translate-x-1/2 type-caption tabular-nums text-muted-foreground",
|
|
14767
|
-
style: { left: pct(t) },
|
|
14768
|
-
children: tickLabel(t, step0)
|
|
14769
|
-
}, t)), beats.map((p) => /* @__PURE__ */ jsx("span", {
|
|
14770
|
-
"data-beat": true,
|
|
14771
|
-
className: "absolute bottom-0 h-1.5 w-px bg-border",
|
|
14772
|
-
style: { left: pct(p) }
|
|
14773
|
-
}, `b${p}`))]
|
|
14774
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
14775
|
-
className: "relative mt-1",
|
|
14776
|
-
style: { height },
|
|
14777
|
-
children: [view.map((it) => {
|
|
14778
|
-
const on = selected.includes(it.id);
|
|
14779
|
-
return /* @__PURE__ */ jsx("button", {
|
|
14780
|
-
type: "button",
|
|
14781
|
-
"aria-pressed": on,
|
|
14782
|
-
"aria-label": `${it.label}, ${at(it.start)} to ${at(it.end)}`,
|
|
14783
|
-
onClick: (e) => choose(e, it.id),
|
|
14784
|
-
className: cn("absolute inset-y-0 min-w-0 cursor-pointer overflow-hidden rounded-control border px-1.5 text-left transition-state", on ? "border-primary bg-primary/10" : "border-border bg-muted hover:bg-muted/70"),
|
|
14785
|
-
style: {
|
|
14786
|
-
left: pct(it.start),
|
|
14787
|
-
width: `calc(${(it.end - it.start) / span * 100}% - 2px)`
|
|
14788
|
-
},
|
|
14789
|
-
children: renderItem ? renderItem(it, on) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
14790
|
-
className: "block truncate type-label",
|
|
14791
|
-
children: it.label
|
|
14792
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
14793
|
-
className: "block truncate type-caption tabular-nums text-muted-foreground",
|
|
14794
|
-
children: seconds(it.end - it.start)
|
|
14795
|
-
})] })
|
|
14796
|
-
}, it.id);
|
|
14797
|
-
}), items.slice(0, -1).map((it, i) => {
|
|
14798
|
-
const r = roomFor(i);
|
|
14799
|
-
const now = drag?.index === i ? drag.time : it.end;
|
|
14800
|
-
return /* @__PURE__ */ jsx("div", {
|
|
14801
|
-
role: "slider",
|
|
14802
|
-
tabIndex: 0,
|
|
14803
|
-
"aria-label": `Cut ${i + 1}, between window ${i + 1} and window ${i + 2}`,
|
|
14804
|
-
"aria-orientation": "horizontal",
|
|
14805
|
-
"aria-valuemin": r.min,
|
|
14806
|
-
"aria-valuemax": r.max,
|
|
14807
|
-
"aria-valuenow": now,
|
|
14808
|
-
"aria-valuetext": at(now),
|
|
14809
|
-
"data-cut": i,
|
|
14810
|
-
onKeyDown: (e) => keys(e, i),
|
|
14811
|
-
onPointerDown: (e) => begin(e, i),
|
|
14812
|
-
onPointerMove: drive,
|
|
14813
|
-
onPointerUp: release,
|
|
14814
|
-
onPointerCancel: () => setDrag(null),
|
|
14815
|
-
className: "group absolute inset-y-0 z-10 w-3 -translate-x-1/2 cursor-ew-resize touch-none outline-offset-1",
|
|
14816
|
-
style: { left: pct(now) },
|
|
14817
|
-
children: /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 left-1/2 w-0.5 -translate-x-1/2 rounded-pill bg-foreground group-hover:w-1 group-focus-visible:w-1" })
|
|
14818
|
-
}, `cut${it.id}`);
|
|
14819
|
-
})]
|
|
14820
|
-
})]
|
|
14821
|
-
})
|
|
14822
|
-
}),
|
|
14823
|
-
drag?.refused && /* @__PURE__ */ jsxs("p", {
|
|
14824
|
-
className: "mt-1 flex items-center gap-1.5 type-body-sm text-danger",
|
|
14825
|
-
children: [
|
|
14826
|
-
/* @__PURE__ */ jsx(Ban, {
|
|
14827
|
-
className: "size-4 shrink-0",
|
|
14828
|
-
"aria-hidden": true
|
|
14829
|
-
}),
|
|
14830
|
-
" ",
|
|
14831
|
-
drag.refused
|
|
14832
|
-
]
|
|
14833
|
-
}),
|
|
14834
|
-
/* @__PURE__ */ jsx("div", {
|
|
14835
|
-
role: "status",
|
|
14836
|
-
"aria-live": "polite",
|
|
14837
|
-
className: "sr-only",
|
|
14838
|
-
children: said
|
|
14839
|
-
})
|
|
14840
|
-
]
|
|
14841
|
-
});
|
|
14842
|
-
}
|
|
14843
|
-
// src/components/tree.tsx
|
|
14844
|
-
var Context = React.createContext(null);
|
|
14845
|
-
var useCtx = () => React.useContext(Context);
|
|
14846
|
-
var NOTE = "\0";
|
|
14847
|
-
var isNote = (key) => key.includes(NOTE);
|
|
14848
|
-
var ROW = "flex min-h-(--control-h-sm) min-w-0 items-center gap-1 rounded-control pr-2 type-body-sm";
|
|
14849
|
-
function Row$1({ level, children }) {
|
|
14850
|
-
return /* @__PURE__ */ jsx("div", {
|
|
14851
|
-
className: ROW,
|
|
14852
|
-
style: { paddingInlineStart: `${level * 1.25 + .25}rem` },
|
|
14853
|
-
children
|
|
14854
|
-
});
|
|
14855
|
-
}
|
|
14856
|
-
function Node$1({ node }) {
|
|
14857
|
-
const c = useCtx();
|
|
14858
|
-
const key = c.nodeKey(node);
|
|
14859
|
-
c.nodes.set(key, node);
|
|
14860
|
-
const branch = c.isBranch ? c.isBranch(node) : true;
|
|
14861
|
-
const open = branch && c.expanded.isOpen(key);
|
|
14862
|
-
const name = c.nodeLabel(node);
|
|
14863
|
-
const nodeCount = c.count?.(node);
|
|
14864
|
-
const badge = c.badge?.(node);
|
|
14865
|
-
const because = c.choices?.implied.has(key) ? c.choices.because(key).map((k) => c.nodes.has(k) ? c.nodeLabel(c.nodes.get(k)) : k) : [];
|
|
14866
|
-
return /* @__PURE__ */ jsxs(TreeItem, {
|
|
14867
|
-
id: key,
|
|
14868
|
-
textValue: name,
|
|
14869
|
-
hasChildItems: branch,
|
|
14870
|
-
className: "outline-none",
|
|
14871
|
-
children: [/* @__PURE__ */ jsx(TreeItemContent, { children: ({ level, isSelected, isExpanded }) => /* @__PURE__ */ jsxs("div", {
|
|
14872
|
-
title: name,
|
|
14873
|
-
className: cn(ROW, "cursor-pointer outline-offset-[-2px] hover:bg-muted", (isSelected || c.current === key) && "bg-surface-sunken font-medium"),
|
|
14874
|
-
style: { paddingInlineStart: `${(level - 1) * 1.25 + .25}rem` },
|
|
14875
|
-
"data-selected": isSelected || void 0,
|
|
14876
|
-
"aria-current": c.current === key ? "true" : void 0,
|
|
14877
|
-
"data-current": c.current === key || void 0,
|
|
14878
|
-
children: [
|
|
14879
|
-
c.choices && /* @__PURE__ */ jsx(TableSelectionCheckbox, {
|
|
14880
|
-
label: `Choose ${name}`,
|
|
14881
|
-
mixed: c.stateOf(key) === "mixed"
|
|
14882
|
-
}),
|
|
14883
|
-
branch ? /* @__PURE__ */ jsx(Button$1, {
|
|
14884
|
-
slot: "chevron",
|
|
14885
|
-
className: "grid size-6 shrink-0 place-items-center rounded-control text-muted-foreground",
|
|
14886
|
-
children: /* @__PURE__ */ jsx(ChevronRight, {
|
|
14887
|
-
"aria-hidden": true,
|
|
14888
|
-
className: cn("size-4", isExpanded && "rotate-90")
|
|
14889
|
-
})
|
|
14890
|
-
}) : /* @__PURE__ */ jsx("span", {
|
|
14891
|
-
"aria-hidden": true,
|
|
14892
|
-
className: "size-6 shrink-0"
|
|
14893
|
-
}),
|
|
14894
|
-
branch ? isExpanded ? /* @__PURE__ */ jsx(FolderOpen, {
|
|
14895
|
-
"aria-hidden": true,
|
|
14896
|
-
className: "size-4 shrink-0 text-muted-foreground"
|
|
14897
|
-
}) : /* @__PURE__ */ jsx(Folder, {
|
|
14898
|
-
"aria-hidden": true,
|
|
14899
|
-
className: "size-4 shrink-0 text-muted-foreground"
|
|
14900
|
-
}) : null,
|
|
14901
|
-
/* @__PURE__ */ jsx("span", {
|
|
14902
|
-
className: "min-w-0 flex-1 truncate",
|
|
14903
|
-
children: c.renderNode ? c.renderNode(node, {
|
|
14904
|
-
expanded: isExpanded,
|
|
14905
|
-
selected: isSelected,
|
|
14906
|
-
level,
|
|
14907
|
-
branch
|
|
14908
|
-
}) : name
|
|
14909
|
-
}),
|
|
14910
|
-
badge && /* @__PURE__ */ jsx(Status, {
|
|
14911
|
-
tone: badge.tone ?? "info",
|
|
14912
|
-
children: badge.label
|
|
14913
|
-
}),
|
|
14914
|
-
nodeCount != null && /* @__PURE__ */ jsx("span", {
|
|
14915
|
-
className: "shrink-0 type-caption text-muted-foreground tabular-nums",
|
|
14916
|
-
children: typeof nodeCount === "number" ? format.integer(nodeCount) : nodeCount
|
|
14917
|
-
}),
|
|
14918
|
-
because.length > 0 && /* @__PURE__ */ jsxs("span", {
|
|
14919
|
-
className: "flex max-w-[50%] shrink-0 items-center gap-1 truncate type-caption text-muted-foreground",
|
|
14920
|
-
title: `Included because of ${because.join(", ")}`,
|
|
14921
|
-
children: [/* @__PURE__ */ jsx(Lock, {
|
|
14922
|
-
"aria-hidden": true,
|
|
14923
|
-
className: "size-3 shrink-0"
|
|
14924
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
14925
|
-
className: "truncate",
|
|
14926
|
-
children: [
|
|
14927
|
-
"Included because of ",
|
|
14928
|
-
because.slice(0, 2).join(", "),
|
|
14929
|
-
because.length > 2 ? ` and ${because.length - 2} more` : ""
|
|
14930
|
-
]
|
|
14931
|
-
})]
|
|
14932
|
-
})
|
|
14933
|
-
]
|
|
14934
|
-
}) }), open ? /* @__PURE__ */ jsx(Children, { node }) : branch && /* @__PURE__ */ jsx(ClosedChild, { id: `${key}${NOTE}closed` })]
|
|
14935
|
-
});
|
|
14936
|
-
}
|
|
14937
|
-
function ClosedChild({ id }) {
|
|
14938
|
-
return /* @__PURE__ */ jsx(TreeItem, {
|
|
14939
|
-
id,
|
|
14940
|
-
textValue: "",
|
|
14941
|
-
isDisabled: true,
|
|
14942
|
-
children: /* @__PURE__ */ jsx(TreeItemContent, { children: () => null })
|
|
14943
|
-
}, "closed");
|
|
14944
|
-
}
|
|
14945
|
-
function Nodes({ nodes }) {
|
|
14946
|
-
const c = useCtx();
|
|
14947
|
-
return /* @__PURE__ */ jsx(Fragment, { children: c.sorted(nodes).map((n) => /* @__PURE__ */ jsx(Node$1, { node: n }, c.nodeKey(n))) });
|
|
14948
|
-
}
|
|
14949
|
-
function Children({ node }) {
|
|
14950
|
-
const c = useCtx();
|
|
14951
|
-
const key = c.nodeKey(node);
|
|
14952
|
-
const load = c.useChildren(node);
|
|
14953
|
-
const ready = load.status === "ready" ? load.data : void 0;
|
|
14954
|
-
React.useEffect(() => {
|
|
14955
|
-
if (ready) c.settle(key, ready);
|
|
14956
|
-
}, [ready]);
|
|
14957
|
-
if (load.status === "loading") return /* @__PURE__ */ jsx(TreeItem, {
|
|
14958
|
-
id: `${key}${NOTE}loading`,
|
|
14959
|
-
textValue: "Loading",
|
|
14960
|
-
isDisabled: true,
|
|
14961
|
-
className: "outline-none",
|
|
14962
|
-
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
14963
|
-
level: level - 1,
|
|
14964
|
-
children: [
|
|
14965
|
-
/* @__PURE__ */ jsx("span", {
|
|
14966
|
-
"aria-hidden": true,
|
|
14967
|
-
className: "size-6 shrink-0"
|
|
14968
|
-
}),
|
|
14969
|
-
/* @__PURE__ */ jsx("span", {
|
|
14970
|
-
role: "status",
|
|
14971
|
-
className: "sr-only",
|
|
14972
|
-
children: "Loading"
|
|
14973
|
-
}),
|
|
14974
|
-
c.loadingRow ?? /* @__PURE__ */ jsx("span", {
|
|
14975
|
-
"aria-hidden": true,
|
|
14976
|
-
className: "h-3 w-32 animate-pulse rounded-pill bg-muted"
|
|
14977
|
-
})
|
|
14978
|
-
]
|
|
14979
|
-
}) })
|
|
14980
|
-
}, "loading");
|
|
14981
|
-
if (load.status === "error") return /* @__PURE__ */ jsx(TreeItem, {
|
|
14982
|
-
id: `${key}${NOTE}error`,
|
|
14983
|
-
textValue: load.message,
|
|
14984
|
-
className: "outline-none",
|
|
14985
|
-
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
14986
|
-
level: level - 1,
|
|
14987
|
-
children: [
|
|
14988
|
-
/* @__PURE__ */ jsx(CircleAlert, {
|
|
14989
|
-
"aria-hidden": true,
|
|
14990
|
-
className: "size-4 shrink-0 text-danger"
|
|
14991
|
-
}),
|
|
14992
|
-
/* @__PURE__ */ jsx("span", {
|
|
14993
|
-
className: "min-w-0 flex-1 truncate text-danger",
|
|
14994
|
-
title: load.message,
|
|
14995
|
-
children: load.message
|
|
14996
|
-
}),
|
|
14997
|
-
/* @__PURE__ */ jsx(Button, {
|
|
14998
|
-
size: "sm",
|
|
14999
|
-
onPress: load.retry,
|
|
15000
|
-
children: "Try again"
|
|
15001
|
-
})
|
|
15002
|
-
]
|
|
15003
|
-
}) })
|
|
15004
|
-
}, "error");
|
|
15005
|
-
if (load.data.length === 0) return /* @__PURE__ */ jsx(TreeItem, {
|
|
15006
|
-
id: `${key}${NOTE}empty`,
|
|
15007
|
-
textValue: c.emptyRow,
|
|
15008
|
-
isDisabled: true,
|
|
15009
|
-
className: "outline-none",
|
|
15010
|
-
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
15011
|
-
level: level - 1,
|
|
15012
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
15013
|
-
"aria-hidden": true,
|
|
15014
|
-
className: "size-6 shrink-0"
|
|
15015
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
15016
|
-
className: "text-muted-foreground",
|
|
15017
|
-
children: c.emptyRow
|
|
15018
|
-
})]
|
|
15019
|
-
}) })
|
|
15020
|
-
}, "empty");
|
|
15021
|
-
c.childKeys.set(key, c.sorted(load.data).map(c.nodeKey));
|
|
15022
|
-
return /* @__PURE__ */ jsx(Nodes, { nodes: load.data });
|
|
15023
|
-
}
|
|
15024
|
-
/** A hierarchy whose children load as each node opens (a `useChildren` hook per open node): a skeleton row, a Try again row and an "empty" row per node, type-ahead and arrow keys, single selection, open state optionally in the URL, always virtualised. */
|
|
15025
|
-
function Tree({ label, roots, useChildren, nodeKey, nodeLabel, isBranch, renderNode, selected, onSelect, choices, current, onCurrentChange, count, badge, sortChildren, reveal, resolveBranch, coverNoun = ["item", "items"], expanded, beforeOpen, loadingRow, emptyRow, height = "24rem", className }) {
|
|
15026
|
-
const nodes = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15027
|
-
const [covered, setCovered] = React.useState("");
|
|
15028
|
-
const scroller = React.useRef(null);
|
|
15029
|
-
const scrollToReveal = React.useRef(() => {});
|
|
15030
|
-
const sorted = React.useCallback((list) => sortChildren ? [...list].sort(sortChildren) : list, [sortChildren]);
|
|
15031
|
-
const childKeys = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15032
|
-
const resolved = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15033
|
-
const below = (key) => [.../* @__PURE__ */ new Set([...(childKeys.get(key) ?? []).flatMap((k) => [k, ...below(k)]), ...resolved.get(key) ?? []])];
|
|
15034
|
-
const stateOf = (key) => {
|
|
15035
|
-
const all = choices?.selected;
|
|
15036
|
-
const own = all?.has(key) ?? false;
|
|
15037
|
-
const ds = below(key);
|
|
15038
|
-
if (ds.length === 0) return own ? "on" : "off";
|
|
15039
|
-
const chosen = ds.filter((k) => all?.has(k)).length;
|
|
15040
|
-
if (chosen === ds.length) return "on";
|
|
15041
|
-
return chosen === 0 && !own ? "off" : "mixed";
|
|
15042
|
-
};
|
|
15043
|
-
const awaiting = React.useRef(/* @__PURE__ */ new Set()).current;
|
|
15044
|
-
const latest = React.useRef({
|
|
15045
|
-
expanded,
|
|
15046
|
-
choices
|
|
15239
|
+
selectionMode: "single",
|
|
15240
|
+
disallowEmptySelection: true,
|
|
15241
|
+
selectedKeys: state.active ? [state.active] : [],
|
|
15242
|
+
onSelectionChange: (keys) => {
|
|
15243
|
+
const id = [...keys][0];
|
|
15244
|
+
if (id !== void 0) state.choose(String(id), "list");
|
|
15245
|
+
},
|
|
15246
|
+
className: cn("min-w-0 overflow-y-auto rounded-surface border border-border", className),
|
|
15247
|
+
children: order.map((id) => {
|
|
15248
|
+
const b = byId.get(id);
|
|
15249
|
+
return /* @__PURE__ */ jsx(ListBoxItem, {
|
|
15250
|
+
id,
|
|
15251
|
+
textValue: b.label,
|
|
15252
|
+
onHoverStart: () => state.point(id),
|
|
15253
|
+
onHoverEnd: () => state.point(null),
|
|
15254
|
+
className: cn("flex cursor-pointer items-baseline gap-2 border-l-2 px-3 py-1.5 type-body-sm outline-offset-[-2px] transition-state", "selected:bg-surface-sunken selected:font-medium hover:bg-surface-sunken", state.pointed === id && "bg-surface-sunken"),
|
|
15255
|
+
style: { borderLeftColor: (b.tone ?? "neutral") === "neutral" ? "transparent" : STROKE[b.tone ?? "neutral"] },
|
|
15256
|
+
children: renderBox ? renderBox(b) : b.label
|
|
15257
|
+
}, id);
|
|
15258
|
+
})
|
|
15047
15259
|
});
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
const
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
|
|
15069
|
-
|
|
15260
|
+
}
|
|
15261
|
+
// src/lib/sequence.ts
|
|
15262
|
+
var EPS = 1e-9;
|
|
15263
|
+
/** The grid point nearest to `time`, or `time` itself when there is no grid. */
|
|
15264
|
+
function snapToGrid(time, grid) {
|
|
15265
|
+
if (grid === void 0) return time;
|
|
15266
|
+
if (typeof grid === "number") return grid > 0 ? tidy(Math.round(time / grid) * grid) : time;
|
|
15267
|
+
let best = time;
|
|
15268
|
+
let gap = Infinity;
|
|
15269
|
+
for (const p of grid) if (Math.abs(p - time) < gap) [best, gap] = [p, Math.abs(p - time)];
|
|
15270
|
+
return best;
|
|
15271
|
+
}
|
|
15272
|
+
/** The next grid point after `time` in a direction (`1` later, `-1` earlier); `fallback` is the step when there is no grid. A point `time` is already on is stepped past. */
|
|
15273
|
+
function stepOnGrid(time, dir, grid, fallback) {
|
|
15274
|
+
if (grid === void 0) return tidy(time + dir * fallback);
|
|
15275
|
+
if (typeof grid === "number") {
|
|
15276
|
+
if (grid <= 0) return tidy(time + dir * fallback);
|
|
15277
|
+
return tidy((dir > 0 ? Math.floor(time / grid + EPS) + 1 : Math.ceil(time / grid - EPS) - 1) * grid);
|
|
15278
|
+
}
|
|
15279
|
+
const points = [...grid].sort((a, b) => a - b);
|
|
15280
|
+
return (dir > 0 ? points.find((p) => p > time + EPS) : [...points].reverse().find((p) => p < time - EPS)) ?? tidy(time + dir * fallback);
|
|
15281
|
+
}
|
|
15282
|
+
/** Grid points inside `[from, to]`, for drawing on a ruler. At most `limit`, so a fine grid on a long axis stays cheap. */
|
|
15283
|
+
function gridPoints(grid, from, to, limit = 2e3) {
|
|
15284
|
+
if (grid === void 0) return [];
|
|
15285
|
+
if (typeof grid !== "number") return grid.filter((p) => p >= from - EPS && p <= to + EPS).slice(0, limit);
|
|
15286
|
+
if (grid <= 0) return [];
|
|
15287
|
+
const out = [];
|
|
15288
|
+
for (let i = Math.ceil(from / grid - EPS); i * grid <= to + EPS && out.length < limit; i++) out.push(tidy(i * grid) || 0);
|
|
15289
|
+
return out;
|
|
15290
|
+
}
|
|
15291
|
+
/** Puts `time` inside the room, and says which end held it (with the app's reason) when one did. */
|
|
15292
|
+
function clampToRoom(time, room) {
|
|
15293
|
+
const t = clamp$1(time, room.min, room.max);
|
|
15294
|
+
if (t > time + EPS) return {
|
|
15295
|
+
time: t,
|
|
15296
|
+
limit: {
|
|
15297
|
+
side: "min",
|
|
15298
|
+
at: room.min,
|
|
15299
|
+
reason: room.minReason
|
|
15070
15300
|
}
|
|
15071
|
-
const toOpen = keys.filter((k) => unread(k) && !toResolve.includes(k));
|
|
15072
|
-
for (const k of toOpen) awaiting.add(k);
|
|
15073
|
-
if (toOpen.length) open(toOpen);
|
|
15074
15301
|
};
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
tick(keys);
|
|
15302
|
+
if (t < time - EPS) return {
|
|
15303
|
+
time: t,
|
|
15304
|
+
limit: {
|
|
15305
|
+
side: "max",
|
|
15306
|
+
at: room.max,
|
|
15307
|
+
reason: room.maxReason
|
|
15308
|
+
}
|
|
15083
15309
|
};
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
nodeLabel,
|
|
15088
|
-
isBranch,
|
|
15089
|
-
renderNode,
|
|
15090
|
-
expanded,
|
|
15091
|
-
loadingRow,
|
|
15092
|
-
emptyRow,
|
|
15093
|
-
nodes,
|
|
15094
|
-
childKeys,
|
|
15095
|
-
choices,
|
|
15096
|
-
stateOf,
|
|
15097
|
-
settle,
|
|
15098
|
-
current,
|
|
15099
|
-
sorted,
|
|
15100
|
-
count,
|
|
15101
|
-
badge
|
|
15310
|
+
return {
|
|
15311
|
+
time: t,
|
|
15312
|
+
limit: null
|
|
15102
15313
|
};
|
|
15103
|
-
|
|
15104
|
-
|
|
15105
|
-
|
|
15106
|
-
|
|
15107
|
-
|
|
15108
|
-
|
|
15109
|
-
|
|
15110
|
-
|
|
15111
|
-
const walk = (keys) => sorted(keys.map((k) => nodes.get(k)).filter((n) => n !== void 0)).map(nodeKey).flatMap((k) => latest.current.expanded.isOpen(k) && childKeys.has(k) ? [k, ...walk(childKeys.get(k))] : [k]);
|
|
15112
|
-
const i = walk(sorted(roots.data).map(nodeKey)).indexOf(reveal[reveal.length - 1]);
|
|
15113
|
-
if (i >= 0) scroller.current.scrollTop = Math.max(0, i * 32 - 32);
|
|
15314
|
+
}
|
|
15315
|
+
/** Where a dragged cut lands: held by the room (saying which end, if the pointer is beyond it), otherwise snapped to the grid, and never to a grid point outside the room. */
|
|
15316
|
+
function settleCut(wanted, grid, room) {
|
|
15317
|
+
const held = clampToRoom(wanted, room);
|
|
15318
|
+
const snapped = snapToGrid(held.time, grid);
|
|
15319
|
+
return {
|
|
15320
|
+
time: snapped >= room.min - EPS && snapped <= room.max + EPS ? snapped : held.time,
|
|
15321
|
+
limit: held.limit
|
|
15114
15322
|
};
|
|
15115
|
-
|
|
15116
|
-
|
|
15117
|
-
|
|
15118
|
-
|
|
15119
|
-
|
|
15120
|
-
|
|
15121
|
-
|
|
15122
|
-
|
|
15123
|
-
|
|
15124
|
-
|
|
15125
|
-
|
|
15126
|
-
|
|
15127
|
-
|
|
15128
|
-
|
|
15129
|
-
|
|
15130
|
-
|
|
15131
|
-
|
|
15132
|
-
|
|
15133
|
-
|
|
15134
|
-
|
|
15135
|
-
|
|
15136
|
-
|
|
15137
|
-
|
|
15138
|
-
|
|
15139
|
-
|
|
15140
|
-
|
|
15141
|
-
|
|
15142
|
-
|
|
15143
|
-
|
|
15144
|
-
|
|
15145
|
-
|
|
15146
|
-
|
|
15147
|
-
|
|
15148
|
-
|
|
15323
|
+
}
|
|
15324
|
+
// src/components/sequence-timeline.tsx
|
|
15325
|
+
var seconds = (n) => `${tidy(Math.round(n * 10) / 10)} s`;
|
|
15326
|
+
var at = (t) => tickLabel(t, .1);
|
|
15327
|
+
/** A gapless strip of windows whose cuts are dragged or stepped, snapping to a beat grid inside the room the app gives; each cut is a slider that announces both windows' new lengths; Shift+click chooses a run. */
|
|
15328
|
+
function SequenceTimeline({ label, items, zoom, onCutChange, room, minLength = .1, grid, step = .1, selected = [], onSelectRange, renderItem, height = "5rem", className }) {
|
|
15329
|
+
const start = items[0]?.start ?? 0;
|
|
15330
|
+
const end = items[items.length - 1]?.end ?? 0;
|
|
15331
|
+
const span = Math.max(end - start, 1e-6);
|
|
15332
|
+
const track = React.useRef(null);
|
|
15333
|
+
const [fit, setFit] = React.useState(800);
|
|
15334
|
+
React.useLayoutEffect(() => {
|
|
15335
|
+
const el = track.current?.parentElement;
|
|
15336
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
15337
|
+
const read = () => setFit(el.clientWidth || 800);
|
|
15338
|
+
read();
|
|
15339
|
+
const ro = new ResizeObserver(read);
|
|
15340
|
+
ro.observe(el);
|
|
15341
|
+
return () => ro.disconnect();
|
|
15342
|
+
}, []);
|
|
15343
|
+
const pxPerUnit = zoom ?? fit / span;
|
|
15344
|
+
const [drag, setDrag] = React.useState(null);
|
|
15345
|
+
const [said, setSaid] = React.useState("");
|
|
15346
|
+
const anchor = React.useRef(null);
|
|
15347
|
+
const roomFor = React.useCallback((i) => room?.(i) ?? {
|
|
15348
|
+
min: items[i].start + minLength,
|
|
15349
|
+
max: items[i + 1].end - minLength
|
|
15350
|
+
}, [
|
|
15351
|
+
room,
|
|
15352
|
+
items,
|
|
15353
|
+
minLength
|
|
15354
|
+
]);
|
|
15355
|
+
const view = items.map((it, i) => ({
|
|
15356
|
+
...it,
|
|
15357
|
+
start: drag && drag.index === i - 1 ? drag.time : it.start,
|
|
15358
|
+
end: drag && drag.index === i ? drag.time : it.end
|
|
15359
|
+
}));
|
|
15360
|
+
const change = (i, time) => ({
|
|
15361
|
+
before: {
|
|
15362
|
+
...items[i],
|
|
15363
|
+
end: time
|
|
15364
|
+
},
|
|
15365
|
+
after: {
|
|
15366
|
+
...items[i + 1],
|
|
15367
|
+
start: time
|
|
15368
|
+
}
|
|
15149
15369
|
});
|
|
15150
|
-
const
|
|
15151
|
-
|
|
15152
|
-
|
|
15153
|
-
|
|
15154
|
-
|
|
15155
|
-
if (node !== void 0) onSelect?.(key, node);
|
|
15156
|
-
};
|
|
15157
|
-
const displayKeys = choices ? [.../* @__PURE__ */ new Set([...choices.selected, ...nodes.keys()])].filter((k) => stateOf(k) === "on" || choices.selected.has(k) && !nodes.has(k)) : [];
|
|
15158
|
-
const shown = () => {
|
|
15159
|
-
const walk = (keys) => keys.flatMap((k) => expanded.isOpen(k) && childKeys.has(k) ? [k, ...walk(childKeys.get(k))] : [k]);
|
|
15160
|
-
return walk(roots.data.map(nodeKey));
|
|
15370
|
+
const words = (i, time) => `Cut ${i + 1} moved to ${at(time)}. Window ${i + 1} is ${seconds(time - items[i].start)}, window ${i + 2} is ${seconds(items[i + 1].end - time)}.`;
|
|
15371
|
+
const timeAt = (clientX) => {
|
|
15372
|
+
const box = track.current?.getBoundingClientRect();
|
|
15373
|
+
if (!box || !box.width) return start;
|
|
15374
|
+
return start + (clientX - box.left) / box.width * span;
|
|
15161
15375
|
};
|
|
15162
|
-
const
|
|
15163
|
-
|
|
15164
|
-
const
|
|
15165
|
-
|
|
15166
|
-
|
|
15167
|
-
|
|
15168
|
-
|
|
15169
|
-
|
|
15376
|
+
const keys = (e, i) => {
|
|
15377
|
+
const r = roomFor(i);
|
|
15378
|
+
const now = items[i].end;
|
|
15379
|
+
let target = null;
|
|
15380
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
15381
|
+
const dir = e.key === "ArrowRight" ? 1 : -1;
|
|
15382
|
+
target = e.shiftKey ? now + dir : stepOnGrid(now, dir, grid, step);
|
|
15383
|
+
} else if (e.key === "Home") target = r.min;
|
|
15384
|
+
else if (e.key === "End") target = r.max;
|
|
15385
|
+
if (target === null) return;
|
|
15386
|
+
e.preventDefault();
|
|
15387
|
+
const { time, limit } = clampToRoom(tidy(target), r);
|
|
15388
|
+
if (Math.abs(time - now) < 1e-9) {
|
|
15389
|
+
const why = limit?.reason ?? (e.key === "End" || e.key === "ArrowRight" ? r.maxReason : r.minReason);
|
|
15390
|
+
setSaid(`Cut ${i + 1} stays at ${at(now)}.${why ? ` ${why}` : ""}`);
|
|
15170
15391
|
return;
|
|
15171
15392
|
}
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
|
|
15179
|
-
|
|
15180
|
-
|
|
15181
|
-
|
|
15182
|
-
|
|
15393
|
+
onCutChange(i, time, change(i, time));
|
|
15394
|
+
setSaid(words(i, time) + (limit?.reason ? ` ${limit.reason}` : ""));
|
|
15395
|
+
};
|
|
15396
|
+
const begin = (e, i) => {
|
|
15397
|
+
if (e.button !== 0) return;
|
|
15398
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
15399
|
+
setDrag({
|
|
15400
|
+
index: i,
|
|
15401
|
+
time: items[i].end,
|
|
15402
|
+
refused: null
|
|
15403
|
+
});
|
|
15404
|
+
};
|
|
15405
|
+
const drive = (e) => {
|
|
15406
|
+
if (!drag) return;
|
|
15407
|
+
const { time, limit } = settleCut(timeAt(e.clientX), grid, roomFor(drag.index));
|
|
15408
|
+
setDrag({
|
|
15409
|
+
index: drag.index,
|
|
15410
|
+
time,
|
|
15411
|
+
refused: limit ? `Cut ${drag.index + 1} stops at ${at(limit.at)}.${limit.reason ? ` ${limit.reason}` : ""}` : null
|
|
15412
|
+
});
|
|
15413
|
+
};
|
|
15414
|
+
const release = () => {
|
|
15415
|
+
if (!drag) return;
|
|
15416
|
+
const d = drag;
|
|
15417
|
+
setDrag(null);
|
|
15418
|
+
if (Math.abs(d.time - items[d.index].end) > 1e-9) {
|
|
15419
|
+
onCutChange(d.index, d.time, change(d.index, d.time));
|
|
15420
|
+
setSaid(words(d.index, d.time) + (d.refused ? ` ${d.refused}` : ""));
|
|
15421
|
+
} else if (d.refused) setSaid(d.refused);
|
|
15422
|
+
};
|
|
15423
|
+
const step0 = tickStep(pxPerUnit);
|
|
15424
|
+
const ticks = ticksBetween(start, end, step0);
|
|
15425
|
+
const all = gridPoints(grid, start, end);
|
|
15426
|
+
const beats = (end - start) / Math.max(all.length, 1) * pxPerUnit >= 4 ? all : [];
|
|
15427
|
+
const pct = (t) => `${(t - start) / span * 100}%`;
|
|
15428
|
+
const choose = (e, id) => {
|
|
15429
|
+
if (!onSelectRange) return;
|
|
15430
|
+
const here = items.findIndex((x) => x.id === id);
|
|
15431
|
+
const from = anchor.current ? items.findIndex((x) => x.id === anchor.current) : -1;
|
|
15432
|
+
if (e.shiftKey && from >= 0) {
|
|
15433
|
+
const [a, b] = from <= here ? [from, here] : [here, from];
|
|
15434
|
+
onSelectRange(items.slice(a, b + 1).map((x) => x.id));
|
|
15435
|
+
} else {
|
|
15436
|
+
anchor.current = id;
|
|
15437
|
+
onSelectRange([id]);
|
|
15183
15438
|
}
|
|
15184
|
-
choices.onChange(wanted);
|
|
15185
15439
|
};
|
|
15186
|
-
const tree = /* @__PURE__ */ jsx(Tree$1, {
|
|
15187
|
-
ref: scroller,
|
|
15188
|
-
"aria-label": label,
|
|
15189
|
-
onAction: onCurrentChange ? (key) => {
|
|
15190
|
-
const k = String(key);
|
|
15191
|
-
const node = nodes.get(k);
|
|
15192
|
-
if (!isNote(k) && node !== void 0) onCurrentChange(k, node);
|
|
15193
|
-
} : void 0,
|
|
15194
|
-
selectionMode: choices ? "multiple" : "single",
|
|
15195
|
-
disallowEmptySelection: !choices,
|
|
15196
|
-
selectedKeys: choices ? displayKeys : selected === null ? [] : [selected],
|
|
15197
|
-
onSelectionChange: choices ? chooseMany : choose,
|
|
15198
|
-
expandedKeys: expanded.expanded,
|
|
15199
|
-
onExpandedChange: (keys) => {
|
|
15200
|
-
const next = new Set([...keys].map(String).filter((k) => !isNote(k)));
|
|
15201
|
-
if (beforeOpen) for (const k of [...next]) {
|
|
15202
|
-
const node = nodes.get(k);
|
|
15203
|
-
if (!expanded.isOpen(k) && node !== void 0 && beforeOpen(node) === false) next.delete(k);
|
|
15204
|
-
}
|
|
15205
|
-
expanded.onChange(next);
|
|
15206
|
-
},
|
|
15207
|
-
renderEmptyState: () => /* @__PURE__ */ jsx("p", {
|
|
15208
|
-
className: "p-3 type-body-sm text-muted-foreground",
|
|
15209
|
-
children: emptyRow
|
|
15210
|
-
}),
|
|
15211
|
-
className: cn("min-w-0 overflow-y-auto outline-none", !choices && className),
|
|
15212
|
-
style: { maxHeight: height },
|
|
15213
|
-
"data-strata-scroll": "",
|
|
15214
|
-
children: /* @__PURE__ */ jsx(Nodes, { nodes: roots.data })
|
|
15215
|
-
});
|
|
15216
|
-
const body = /* @__PURE__ */ jsx(Context.Provider, {
|
|
15217
|
-
value: ctx,
|
|
15218
|
-
children: /* @__PURE__ */ jsx(Virtualizer, {
|
|
15219
|
-
layout: ListLayout,
|
|
15220
|
-
layoutOptions: { rowHeight: 32 },
|
|
15221
|
-
children: tree
|
|
15222
|
-
})
|
|
15223
|
-
});
|
|
15224
|
-
if (!choices) return body;
|
|
15225
15440
|
return /* @__PURE__ */ jsxs("div", {
|
|
15226
|
-
className: cn("
|
|
15227
|
-
children: [
|
|
15228
|
-
/* @__PURE__ */ jsxs("div", {
|
|
15229
|
-
className: "flex items-center gap-2",
|
|
15230
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
15231
|
-
size: "sm",
|
|
15232
|
-
variant: "ghost",
|
|
15233
|
-
onPress: () => chooseMany("all"),
|
|
15234
|
-
children: "Select all shown"
|
|
15235
|
-
}), choices.count > 0 && /* @__PURE__ */ jsx(Button, {
|
|
15236
|
-
size: "sm",
|
|
15237
|
-
variant: "ghost",
|
|
15238
|
-
onPress: choices.clear,
|
|
15239
|
-
children: "Clear"
|
|
15240
|
-
})]
|
|
15241
|
-
}),
|
|
15242
|
-
body,
|
|
15243
|
-
/* @__PURE__ */ jsx("p", {
|
|
15244
|
-
role: "status",
|
|
15245
|
-
className: "sr-only",
|
|
15246
|
-
children: covered || choices.note
|
|
15247
|
-
})
|
|
15248
|
-
]
|
|
15249
|
-
});
|
|
15250
|
-
}
|
|
15251
|
-
// src/components/folder-picker.tsx
|
|
15252
|
-
var SEP = "/";
|
|
15253
|
-
var parts = (path) => path.split(SEP).filter(Boolean);
|
|
15254
|
-
var join = (parent, name) => `${parent === SEP ? "" : parent}${SEP}${name}`;
|
|
15255
|
-
/** The parent of a path, or `null` at the top. */
|
|
15256
|
-
var parentOf = (path) => {
|
|
15257
|
-
const p = parts(path);
|
|
15258
|
-
return p.length <= 1 ? null : `${SEP}${p.slice(0, -1).join(SEP)}`;
|
|
15259
|
-
};
|
|
15260
|
-
/** Every folder from the top down to `path`, which the tree must have open to show it. */
|
|
15261
|
-
var ancestorsOf = (path) => parts(path).slice(0, -1).map((_, i, a) => `${SEP}${a.slice(0, i + 1).join(SEP)}`);
|
|
15262
|
-
/** A server folder chooser: a lazy tree, a breadcrumb that is also editable text, Up, recents, a New folder field that shows the server's refusal, and Choose this folder as the one filled button. */
|
|
15263
|
-
function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose, expanded, recent, canChoose, chooseLabel = "Choose this folder", onOpen, onCreate, topLabel = "Top", emptyRow = "No folders", height = "18rem", className }) {
|
|
15264
|
-
const useFolders = (path) => {
|
|
15265
|
-
const l = useListing(path);
|
|
15266
|
-
return l.status === "ready" && !Array.isArray(l.data) ? {
|
|
15267
|
-
...l,
|
|
15268
|
-
data: l.data.folders
|
|
15269
|
-
} : l;
|
|
15270
|
-
};
|
|
15271
|
-
const roots = useFolders(null);
|
|
15272
|
-
const siblings = useFolders(value ? parentOf(value) : null);
|
|
15273
|
-
const own = useListing(value);
|
|
15274
|
-
const folder = value && siblings.status === "ready" ? siblings.data.find((f) => f.path === value) : void 0;
|
|
15275
|
-
const footer = value && own.status === "ready" && !Array.isArray(own.data) ? own.data.footer : void 0;
|
|
15276
|
-
const verdict = value && canChoose ? canChoose(value, folder) : true;
|
|
15277
|
-
const reason = typeof verdict === "string" ? verdict : void 0;
|
|
15278
|
-
const reasonId = React.useId();
|
|
15279
|
-
const [editing, setEditing] = React.useState(false);
|
|
15280
|
-
const [text, setText] = React.useState("");
|
|
15281
|
-
const go = (path) => onChange(path);
|
|
15282
|
-
React.useEffect(() => {
|
|
15283
|
-
if (!value) return;
|
|
15284
|
-
const open = ancestorsOf(value).filter((a) => !expanded.isOpen(a));
|
|
15285
|
-
if (open.length) expanded.onChange(/* @__PURE__ */ new Set([...expanded.expanded, ...open]));
|
|
15286
|
-
}, [value, expanded]);
|
|
15287
|
-
const [name, setName] = React.useState("");
|
|
15288
|
-
const created = useAsyncAction(async (name) => {
|
|
15289
|
-
if (!value) return;
|
|
15290
|
-
await onCreate?.(value, name);
|
|
15291
|
-
setName("");
|
|
15292
|
-
go(join(value, name));
|
|
15293
|
-
expanded.setOpen(value, true);
|
|
15294
|
-
}, { validate: (name) => name.trim() ? void 0 : { name: "Name the new folder." } });
|
|
15295
|
-
const crumbs = value ? parts(value) : [];
|
|
15296
|
-
return /* @__PURE__ */ jsxs("section", {
|
|
15297
|
-
"aria-label": label,
|
|
15298
|
-
className: cn("space-y-3", className),
|
|
15441
|
+
className: cn("min-w-0", className),
|
|
15299
15442
|
children: [
|
|
15300
|
-
/* @__PURE__ */
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
|
|
15305
|
-
|
|
15306
|
-
|
|
15307
|
-
|
|
15308
|
-
|
|
15309
|
-
|
|
15310
|
-
|
|
15311
|
-
|
|
15312
|
-
|
|
15313
|
-
|
|
15314
|
-
|
|
15315
|
-
|
|
15316
|
-
|
|
15317
|
-
|
|
15318
|
-
|
|
15319
|
-
|
|
15320
|
-
|
|
15321
|
-
className: "
|
|
15322
|
-
|
|
15323
|
-
|
|
15324
|
-
|
|
15325
|
-
|
|
15326
|
-
|
|
15327
|
-
|
|
15328
|
-
|
|
15329
|
-
|
|
15330
|
-
|
|
15331
|
-
|
|
15332
|
-
|
|
15333
|
-
|
|
15334
|
-
|
|
15335
|
-
|
|
15336
|
-
|
|
15337
|
-
|
|
15338
|
-
|
|
15339
|
-
|
|
15340
|
-
|
|
15341
|
-
|
|
15342
|
-
|
|
15343
|
-
|
|
15344
|
-
|
|
15345
|
-
|
|
15346
|
-
|
|
15347
|
-
|
|
15348
|
-
|
|
15349
|
-
|
|
15350
|
-
|
|
15351
|
-
|
|
15352
|
-
|
|
15353
|
-
|
|
15354
|
-
|
|
15355
|
-
|
|
15356
|
-
|
|
15357
|
-
|
|
15358
|
-
|
|
15359
|
-
|
|
15360
|
-
|
|
15443
|
+
/* @__PURE__ */ jsx("div", {
|
|
15444
|
+
role: "group",
|
|
15445
|
+
"aria-label": label,
|
|
15446
|
+
className: "overflow-x-auto pb-2",
|
|
15447
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
15448
|
+
ref: track,
|
|
15449
|
+
className: "relative",
|
|
15450
|
+
style: { width: zoom ? `${span * zoom}px` : "100%" },
|
|
15451
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
15452
|
+
"aria-hidden": true,
|
|
15453
|
+
className: "relative h-6 border-b border-border",
|
|
15454
|
+
children: [ticks.map((t) => /* @__PURE__ */ jsx("span", {
|
|
15455
|
+
className: "absolute top-0 -translate-x-1/2 type-caption tabular-nums text-muted-foreground",
|
|
15456
|
+
style: { left: pct(t) },
|
|
15457
|
+
children: tickLabel(t, step0)
|
|
15458
|
+
}, t)), beats.map((p) => /* @__PURE__ */ jsx("span", {
|
|
15459
|
+
"data-beat": true,
|
|
15460
|
+
className: "absolute bottom-0 h-1.5 w-px bg-border",
|
|
15461
|
+
style: { left: pct(p) }
|
|
15462
|
+
}, `b${p}`))]
|
|
15463
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
15464
|
+
className: "relative mt-1",
|
|
15465
|
+
style: { height },
|
|
15466
|
+
children: [view.map((it) => {
|
|
15467
|
+
const on = selected.includes(it.id);
|
|
15468
|
+
return /* @__PURE__ */ jsx("button", {
|
|
15469
|
+
type: "button",
|
|
15470
|
+
"aria-pressed": on,
|
|
15471
|
+
"aria-label": `${it.label}, ${at(it.start)} to ${at(it.end)}`,
|
|
15472
|
+
onClick: (e) => choose(e, it.id),
|
|
15473
|
+
className: cn("absolute inset-y-0 min-w-0 cursor-pointer overflow-hidden rounded-control border px-1.5 text-left transition-state", on ? "border-primary bg-primary/10" : "border-border bg-muted hover:bg-muted/70"),
|
|
15474
|
+
style: {
|
|
15475
|
+
left: pct(it.start),
|
|
15476
|
+
width: `calc(${(it.end - it.start) / span * 100}% - 2px)`
|
|
15477
|
+
},
|
|
15478
|
+
children: renderItem ? renderItem(it, on) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
15479
|
+
className: "block truncate type-label",
|
|
15480
|
+
children: it.label
|
|
15481
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
15482
|
+
className: "block truncate type-caption tabular-nums text-muted-foreground",
|
|
15483
|
+
children: seconds(it.end - it.start)
|
|
15484
|
+
})] })
|
|
15485
|
+
}, it.id);
|
|
15486
|
+
}), items.slice(0, -1).map((it, i) => {
|
|
15487
|
+
const r = roomFor(i);
|
|
15488
|
+
const now = drag?.index === i ? drag.time : it.end;
|
|
15489
|
+
return /* @__PURE__ */ jsx("div", {
|
|
15490
|
+
role: "slider",
|
|
15491
|
+
tabIndex: 0,
|
|
15492
|
+
"aria-label": `Cut ${i + 1}, between window ${i + 1} and window ${i + 2}`,
|
|
15493
|
+
"aria-orientation": "horizontal",
|
|
15494
|
+
"aria-valuemin": r.min,
|
|
15495
|
+
"aria-valuemax": r.max,
|
|
15496
|
+
"aria-valuenow": now,
|
|
15497
|
+
"aria-valuetext": at(now),
|
|
15498
|
+
"data-cut": i,
|
|
15499
|
+
onKeyDown: (e) => keys(e, i),
|
|
15500
|
+
onPointerDown: (e) => begin(e, i),
|
|
15501
|
+
onPointerMove: drive,
|
|
15502
|
+
onPointerUp: release,
|
|
15503
|
+
onPointerCancel: () => setDrag(null),
|
|
15504
|
+
className: "group absolute inset-y-0 z-10 w-3 -translate-x-1/2 cursor-ew-resize touch-none outline-offset-1",
|
|
15505
|
+
style: { left: pct(now) },
|
|
15506
|
+
children: /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 left-1/2 w-0.5 -translate-x-1/2 rounded-pill bg-foreground group-hover:w-1 group-focus-visible:w-1" })
|
|
15507
|
+
}, `cut${it.id}`);
|
|
15361
15508
|
})]
|
|
15362
|
-
})
|
|
15363
|
-
}), /* @__PURE__ */ jsx(IconButton, {
|
|
15364
|
-
icon: Pencil,
|
|
15365
|
-
label: "Edit path",
|
|
15366
|
-
onPress: () => {
|
|
15367
|
-
setText(value ?? "");
|
|
15368
|
-
setEditing(true);
|
|
15369
|
-
}
|
|
15370
|
-
})] })]
|
|
15371
|
-
}),
|
|
15372
|
-
/* @__PURE__ */ jsx("div", {
|
|
15373
|
-
className: "rounded-surface border border-border",
|
|
15374
|
-
children: /* @__PURE__ */ jsx(Tree, {
|
|
15375
|
-
label: `${label}: folders`,
|
|
15376
|
-
roots,
|
|
15377
|
-
useChildren: (f) => useFolders(f.path),
|
|
15378
|
-
nodeKey: (f) => f.path,
|
|
15379
|
-
nodeLabel: (f) => f.badge ? `${f.name}, ${f.badge}` : f.name,
|
|
15380
|
-
beforeOpen: onOpen ? (f) => {
|
|
15381
|
-
if (onOpen(f) !== "choose") return true;
|
|
15382
|
-
go(f.path);
|
|
15383
|
-
onChoose(f.path);
|
|
15384
|
-
return false;
|
|
15385
|
-
} : void 0,
|
|
15386
|
-
renderNode: (f) => /* @__PURE__ */ jsxs("span", {
|
|
15387
|
-
className: "flex min-w-0 items-baseline gap-2",
|
|
15388
|
-
children: [
|
|
15389
|
-
/* @__PURE__ */ jsx("span", {
|
|
15390
|
-
className: "truncate",
|
|
15391
|
-
children: f.name
|
|
15392
|
-
}),
|
|
15393
|
-
f.badge && /* @__PURE__ */ jsx(Status, {
|
|
15394
|
-
tone: f.tone ?? "neutral",
|
|
15395
|
-
className: "self-center",
|
|
15396
|
-
children: f.badge
|
|
15397
|
-
}),
|
|
15398
|
-
f.count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
15399
|
-
className: "type-caption tabular-nums text-muted-foreground",
|
|
15400
|
-
children: format.integer(f.count)
|
|
15401
|
-
})
|
|
15402
|
-
]
|
|
15403
|
-
}),
|
|
15404
|
-
selected: value,
|
|
15405
|
-
onSelect: (key) => onChange(key),
|
|
15406
|
-
expanded,
|
|
15407
|
-
emptyRow,
|
|
15408
|
-
height
|
|
15509
|
+
})]
|
|
15409
15510
|
})
|
|
15410
15511
|
}),
|
|
15411
|
-
|
|
15412
|
-
|
|
15413
|
-
|
|
15414
|
-
|
|
15415
|
-
|
|
15416
|
-
|
|
15417
|
-
children: "Recent"
|
|
15418
|
-
}), recent.map((r) => /* @__PURE__ */ jsx(Tooltip, {
|
|
15419
|
-
label: r,
|
|
15420
|
-
side: "bottom",
|
|
15421
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
15422
|
-
size: "sm",
|
|
15423
|
-
variant: "outline",
|
|
15424
|
-
onPress: () => go(r),
|
|
15425
|
-
className: "max-w-64 truncate font-mono",
|
|
15426
|
-
children: r
|
|
15427
|
-
})
|
|
15428
|
-
}, r))]
|
|
15429
|
-
}),
|
|
15430
|
-
onCreate && /* @__PURE__ */ jsx("form", {
|
|
15431
|
-
onSubmit: (e) => {
|
|
15432
|
-
e.preventDefault();
|
|
15433
|
-
created.run(name.trim());
|
|
15434
|
-
},
|
|
15435
|
-
children: /* @__PURE__ */ jsx(Field, {
|
|
15436
|
-
label: "New folder",
|
|
15437
|
-
hint: value ? `It will be made in ${value}.` : "Open a folder first.",
|
|
15438
|
-
error: created.fieldErrors.name ?? (created.phase === "error" ? created.error : void 0),
|
|
15439
|
-
action: /* @__PURE__ */ jsx(AsyncButton, {
|
|
15440
|
-
type: "submit",
|
|
15441
|
-
phase: created.phase,
|
|
15442
|
-
error: created.error,
|
|
15443
|
-
disabled: !value,
|
|
15444
|
-
labels: {
|
|
15445
|
-
idle: "Make folder",
|
|
15446
|
-
pending: "Making…",
|
|
15447
|
-
done: "Made"
|
|
15448
|
-
}
|
|
15512
|
+
drag?.refused && /* @__PURE__ */ jsxs("p", {
|
|
15513
|
+
className: "mt-1 flex items-center gap-1.5 type-body-sm text-danger",
|
|
15514
|
+
children: [
|
|
15515
|
+
/* @__PURE__ */ jsx(Ban, {
|
|
15516
|
+
className: "size-4 shrink-0",
|
|
15517
|
+
"aria-hidden": true
|
|
15449
15518
|
}),
|
|
15450
|
-
|
|
15451
|
-
|
|
15452
|
-
|
|
15453
|
-
onChange: (e) => {
|
|
15454
|
-
setName(e.target.value);
|
|
15455
|
-
created.clearFieldError("name");
|
|
15456
|
-
}
|
|
15457
|
-
})
|
|
15458
|
-
})
|
|
15459
|
-
}),
|
|
15460
|
-
footer && /* @__PURE__ */ jsx("p", {
|
|
15461
|
-
className: "type-body-sm text-muted-foreground",
|
|
15462
|
-
children: footer
|
|
15519
|
+
" ",
|
|
15520
|
+
drag.refused
|
|
15521
|
+
]
|
|
15463
15522
|
}),
|
|
15464
|
-
/* @__PURE__ */
|
|
15465
|
-
|
|
15466
|
-
|
|
15467
|
-
|
|
15468
|
-
|
|
15469
|
-
children: reason
|
|
15470
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
15471
|
-
variant: "default",
|
|
15472
|
-
disabled: !value || reason !== void 0,
|
|
15473
|
-
"aria-describedby": reason ? reasonId : void 0,
|
|
15474
|
-
onPress: () => value && onChoose(value),
|
|
15475
|
-
children: chooseLabel
|
|
15476
|
-
})]
|
|
15523
|
+
/* @__PURE__ */ jsx("div", {
|
|
15524
|
+
role: "status",
|
|
15525
|
+
"aria-live": "polite",
|
|
15526
|
+
className: "sr-only",
|
|
15527
|
+
children: said
|
|
15477
15528
|
})
|
|
15478
15529
|
]
|
|
15479
15530
|
});
|
|
15480
15531
|
}
|
|
15481
|
-
// src/
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
return
|
|
15489
|
-
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
|
|
15493
|
-
|
|
15494
|
-
|
|
15495
|
-
|
|
15496
|
-
|
|
15497
|
-
|
|
15532
|
+
// src/components/tree.tsx
|
|
15533
|
+
var Context = React.createContext(null);
|
|
15534
|
+
var useCtx = () => React.useContext(Context);
|
|
15535
|
+
var NOTE = "\0";
|
|
15536
|
+
var isNote = (key) => key.includes(NOTE);
|
|
15537
|
+
var ROW = "flex min-h-(--control-h-sm) min-w-0 items-center gap-1 rounded-control pr-2 type-body-sm";
|
|
15538
|
+
function Row$1({ level, children }) {
|
|
15539
|
+
return /* @__PURE__ */ jsx("div", {
|
|
15540
|
+
className: ROW,
|
|
15541
|
+
style: { paddingInlineStart: `${level * 1.25 + .25}rem` },
|
|
15542
|
+
children
|
|
15543
|
+
});
|
|
15544
|
+
}
|
|
15545
|
+
function Node$1({ node }) {
|
|
15546
|
+
const c = useCtx();
|
|
15547
|
+
const key = c.nodeKey(node);
|
|
15548
|
+
c.nodes.set(key, node);
|
|
15549
|
+
const branch = c.isBranch ? c.isBranch(node) : true;
|
|
15550
|
+
const open = branch && c.expanded.isOpen(key);
|
|
15551
|
+
const name = c.nodeLabel(node);
|
|
15552
|
+
const nodeCount = c.count?.(node);
|
|
15553
|
+
const badge = c.badge?.(node);
|
|
15554
|
+
const because = c.choices?.implied.has(key) ? c.choices.because(key).map((k) => c.nodes.has(k) ? c.nodeLabel(c.nodes.get(k)) : k) : [];
|
|
15555
|
+
return /* @__PURE__ */ jsxs(TreeItem, {
|
|
15556
|
+
id: key,
|
|
15557
|
+
textValue: name,
|
|
15558
|
+
hasChildItems: branch,
|
|
15559
|
+
className: "outline-none",
|
|
15560
|
+
children: [/* @__PURE__ */ jsx(TreeItemContent, { children: ({ level, isSelected, isExpanded }) => /* @__PURE__ */ jsxs("div", {
|
|
15561
|
+
title: name,
|
|
15562
|
+
className: cn(ROW, "cursor-pointer outline-offset-[-2px] hover:bg-muted", (isSelected || c.current === key) && "bg-surface-sunken font-medium"),
|
|
15563
|
+
style: { paddingInlineStart: `${(level - 1) * 1.25 + .25}rem` },
|
|
15564
|
+
"data-selected": isSelected || void 0,
|
|
15565
|
+
"aria-current": c.current === key ? "true" : void 0,
|
|
15566
|
+
"data-current": c.current === key || void 0,
|
|
15567
|
+
children: [
|
|
15568
|
+
c.choices && /* @__PURE__ */ jsx(TableSelectionCheckbox, {
|
|
15569
|
+
label: `Choose ${name}`,
|
|
15570
|
+
mixed: c.stateOf(key) === "mixed"
|
|
15571
|
+
}),
|
|
15572
|
+
branch ? /* @__PURE__ */ jsx(Button$1, {
|
|
15573
|
+
slot: "chevron",
|
|
15574
|
+
className: "grid size-6 shrink-0 place-items-center rounded-control text-muted-foreground",
|
|
15575
|
+
children: /* @__PURE__ */ jsx(ChevronRight, {
|
|
15576
|
+
"aria-hidden": true,
|
|
15577
|
+
className: cn("size-4", isExpanded && "rotate-90")
|
|
15578
|
+
})
|
|
15579
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
15580
|
+
"aria-hidden": true,
|
|
15581
|
+
className: "size-6 shrink-0"
|
|
15582
|
+
}),
|
|
15583
|
+
branch ? isExpanded ? /* @__PURE__ */ jsx(FolderOpen, {
|
|
15584
|
+
"aria-hidden": true,
|
|
15585
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
15586
|
+
}) : /* @__PURE__ */ jsx(Folder, {
|
|
15587
|
+
"aria-hidden": true,
|
|
15588
|
+
className: "size-4 shrink-0 text-muted-foreground"
|
|
15589
|
+
}) : null,
|
|
15590
|
+
/* @__PURE__ */ jsx("span", {
|
|
15591
|
+
className: "min-w-0 flex-1 truncate",
|
|
15592
|
+
children: c.renderNode ? c.renderNode(node, {
|
|
15593
|
+
expanded: isExpanded,
|
|
15594
|
+
selected: isSelected,
|
|
15595
|
+
level,
|
|
15596
|
+
branch
|
|
15597
|
+
}) : name
|
|
15598
|
+
}),
|
|
15599
|
+
badge && /* @__PURE__ */ jsx(Status, {
|
|
15600
|
+
tone: badge.tone ?? "info",
|
|
15601
|
+
children: badge.label
|
|
15602
|
+
}),
|
|
15603
|
+
nodeCount != null && /* @__PURE__ */ jsx("span", {
|
|
15604
|
+
className: "shrink-0 type-caption text-muted-foreground tabular-nums",
|
|
15605
|
+
children: typeof nodeCount === "number" ? format.integer(nodeCount) : nodeCount
|
|
15606
|
+
}),
|
|
15607
|
+
because.length > 0 && /* @__PURE__ */ jsxs("span", {
|
|
15608
|
+
className: "flex max-w-[50%] shrink-0 items-center gap-1 truncate type-caption text-muted-foreground",
|
|
15609
|
+
title: `Included because of ${because.join(", ")}`,
|
|
15610
|
+
children: [/* @__PURE__ */ jsx(Lock, {
|
|
15611
|
+
"aria-hidden": true,
|
|
15612
|
+
className: "size-3 shrink-0"
|
|
15613
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
15614
|
+
className: "truncate",
|
|
15615
|
+
children: [
|
|
15616
|
+
"Included because of ",
|
|
15617
|
+
because.slice(0, 2).join(", "),
|
|
15618
|
+
because.length > 2 ? ` and ${because.length - 2} more` : ""
|
|
15619
|
+
]
|
|
15620
|
+
})]
|
|
15621
|
+
})
|
|
15622
|
+
]
|
|
15623
|
+
}) }), open ? /* @__PURE__ */ jsx(Children, { node }) : branch && /* @__PURE__ */ jsx(ClosedChild, { id: `${key}${NOTE}closed` })]
|
|
15624
|
+
});
|
|
15625
|
+
}
|
|
15626
|
+
function ClosedChild({ id }) {
|
|
15627
|
+
return /* @__PURE__ */ jsx(TreeItem, {
|
|
15628
|
+
id,
|
|
15629
|
+
textValue: "",
|
|
15630
|
+
isDisabled: true,
|
|
15631
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: () => null })
|
|
15632
|
+
}, "closed");
|
|
15498
15633
|
}
|
|
15499
|
-
|
|
15500
|
-
|
|
15501
|
-
|
|
15502
|
-
const i = from === null ? -1 : ids.indexOf(from);
|
|
15503
|
-
if (i < 0) return by >= 0 ? ids[0] : ids[ids.length - 1];
|
|
15504
|
-
return ids[Math.min(Math.max(i + by, 0), ids.length - 1)];
|
|
15634
|
+
function Nodes({ nodes }) {
|
|
15635
|
+
const c = useCtx();
|
|
15636
|
+
return /* @__PURE__ */ jsx(Fragment, { children: c.sorted(nodes).map((n) => /* @__PURE__ */ jsx(Node$1, { node: n }, c.nodeKey(n))) });
|
|
15505
15637
|
}
|
|
15506
|
-
|
|
15507
|
-
|
|
15508
|
-
|
|
15509
|
-
|
|
15510
|
-
|
|
15511
|
-
|
|
15512
|
-
|
|
15513
|
-
|
|
15514
|
-
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
15518
|
-
|
|
15519
|
-
|
|
15520
|
-
|
|
15521
|
-
fill: "var(--warning-subtle)",
|
|
15522
|
-
edge: "var(--warning)"
|
|
15523
|
-
},
|
|
15524
|
-
danger: {
|
|
15525
|
-
fill: "var(--danger-subtle)",
|
|
15526
|
-
edge: "var(--danger)"
|
|
15527
|
-
}
|
|
15528
|
-
};
|
|
15529
|
-
var MarksContext = React.createContext(null);
|
|
15530
|
-
/** One word (or phrase, or clip) that can be marked. Draws its mark, its selection and the caret; inside a `MarkableText`. */
|
|
15531
|
-
function Mark({ id, children, className }) {
|
|
15532
|
-
const c = React.useContext(MarksContext);
|
|
15533
|
-
if (!c) return /* @__PURE__ */ jsx("span", {
|
|
15534
|
-
className,
|
|
15535
|
-
children
|
|
15536
|
-
});
|
|
15537
|
-
const kind = c.kinds.find((k) => k.key === c.marks[id]);
|
|
15538
|
-
const tone = kind && TONE[kind.tone];
|
|
15539
|
-
const on = c.selected.has(id);
|
|
15540
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
15541
|
-
"data-mark-id": id,
|
|
15542
|
-
"data-mark": kind?.key,
|
|
15543
|
-
"data-selected": on || void 0,
|
|
15544
|
-
"data-caret": c.caret === id || void 0,
|
|
15545
|
-
onPointerDown: (e) => c.press(e, id),
|
|
15546
|
-
onPointerEnter: () => c.over(id),
|
|
15547
|
-
className: cn("cursor-text rounded-control px-px", on && "bg-primary/20", c.caret === id && "outline-2 outline-primary", className),
|
|
15548
|
-
style: kind && tone ? {
|
|
15549
|
-
backgroundColor: on ? void 0 : tone.fill,
|
|
15550
|
-
textDecorationLine: "underline",
|
|
15551
|
-
textDecorationStyle: kind.pattern,
|
|
15552
|
-
textDecorationColor: tone.edge,
|
|
15553
|
-
textDecorationThickness: "2px",
|
|
15554
|
-
textUnderlineOffset: "3px"
|
|
15555
|
-
} : void 0,
|
|
15556
|
-
children: [children, kind && /* @__PURE__ */ jsxs("span", {
|
|
15557
|
-
className: "sr-only",
|
|
15638
|
+
function Children({ node }) {
|
|
15639
|
+
const c = useCtx();
|
|
15640
|
+
const key = c.nodeKey(node);
|
|
15641
|
+
const load = c.useChildren(node);
|
|
15642
|
+
const ready = load.status === "ready" ? load.data : void 0;
|
|
15643
|
+
React.useEffect(() => {
|
|
15644
|
+
if (ready) c.settle(key, ready);
|
|
15645
|
+
}, [ready]);
|
|
15646
|
+
if (load.status === "loading") return /* @__PURE__ */ jsx(TreeItem, {
|
|
15647
|
+
id: `${key}${NOTE}loading`,
|
|
15648
|
+
textValue: "Loading",
|
|
15649
|
+
isDisabled: true,
|
|
15650
|
+
className: "outline-none",
|
|
15651
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
15652
|
+
level: level - 1,
|
|
15558
15653
|
children: [
|
|
15559
|
-
|
|
15560
|
-
|
|
15561
|
-
|
|
15654
|
+
/* @__PURE__ */ jsx("span", {
|
|
15655
|
+
"aria-hidden": true,
|
|
15656
|
+
className: "size-6 shrink-0"
|
|
15657
|
+
}),
|
|
15658
|
+
/* @__PURE__ */ jsx("span", {
|
|
15659
|
+
role: "status",
|
|
15660
|
+
className: "sr-only",
|
|
15661
|
+
children: "Loading"
|
|
15662
|
+
}),
|
|
15663
|
+
c.loadingRow ?? /* @__PURE__ */ jsx("span", {
|
|
15664
|
+
"aria-hidden": true,
|
|
15665
|
+
className: "h-3 w-32 animate-pulse rounded-pill bg-muted"
|
|
15666
|
+
})
|
|
15562
15667
|
]
|
|
15563
|
-
})
|
|
15564
|
-
});
|
|
15668
|
+
}) })
|
|
15669
|
+
}, "loading");
|
|
15670
|
+
if (load.status === "error") return /* @__PURE__ */ jsx(TreeItem, {
|
|
15671
|
+
id: `${key}${NOTE}error`,
|
|
15672
|
+
textValue: load.message,
|
|
15673
|
+
className: "outline-none",
|
|
15674
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
15675
|
+
level: level - 1,
|
|
15676
|
+
children: [
|
|
15677
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
15678
|
+
"aria-hidden": true,
|
|
15679
|
+
className: "size-4 shrink-0 text-danger"
|
|
15680
|
+
}),
|
|
15681
|
+
/* @__PURE__ */ jsx("span", {
|
|
15682
|
+
className: "min-w-0 flex-1 truncate text-danger",
|
|
15683
|
+
title: load.message,
|
|
15684
|
+
children: load.message
|
|
15685
|
+
}),
|
|
15686
|
+
/* @__PURE__ */ jsx(Button, {
|
|
15687
|
+
size: "sm",
|
|
15688
|
+
onPress: load.retry,
|
|
15689
|
+
children: "Try again"
|
|
15690
|
+
})
|
|
15691
|
+
]
|
|
15692
|
+
}) })
|
|
15693
|
+
}, "error");
|
|
15694
|
+
if (load.data.length === 0) return /* @__PURE__ */ jsx(TreeItem, {
|
|
15695
|
+
id: `${key}${NOTE}empty`,
|
|
15696
|
+
textValue: c.emptyRow,
|
|
15697
|
+
isDisabled: true,
|
|
15698
|
+
className: "outline-none",
|
|
15699
|
+
children: /* @__PURE__ */ jsx(TreeItemContent, { children: ({ level }) => /* @__PURE__ */ jsxs(Row$1, {
|
|
15700
|
+
level: level - 1,
|
|
15701
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
15702
|
+
"aria-hidden": true,
|
|
15703
|
+
className: "size-6 shrink-0"
|
|
15704
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
15705
|
+
className: "text-muted-foreground",
|
|
15706
|
+
children: c.emptyRow
|
|
15707
|
+
})]
|
|
15708
|
+
}) })
|
|
15709
|
+
}, "empty");
|
|
15710
|
+
c.childKeys.set(key, c.sorted(load.data).map(c.nodeKey));
|
|
15711
|
+
return /* @__PURE__ */ jsx(Nodes, { nodes: load.data });
|
|
15565
15712
|
}
|
|
15566
|
-
/**
|
|
15567
|
-
function
|
|
15568
|
-
const
|
|
15569
|
-
const
|
|
15570
|
-
|
|
15571
|
-
|
|
15572
|
-
|
|
15713
|
+
/** A hierarchy whose children load as each node opens (a `useChildren` hook per open node): a skeleton row, a Try again row and an "empty" row per node, type-ahead and arrow keys, single selection, open state optionally in the URL, always virtualised. */
|
|
15714
|
+
function Tree({ label, roots, useChildren, nodeKey, nodeLabel, isBranch, renderNode, selected, onSelect, choices, current, onCurrentChange, count, badge, sortChildren, reveal, resolveBranch, coverNoun = ["item", "items"], expanded, beforeOpen, loadingRow, emptyRow, height = "24rem", className }) {
|
|
15715
|
+
const nodes = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15716
|
+
const [covered, setCovered] = React.useState("");
|
|
15717
|
+
const scroller = React.useRef(null);
|
|
15718
|
+
const scrollToReveal = React.useRef(() => {});
|
|
15719
|
+
const sorted = React.useCallback((list) => sortChildren ? [...list].sort(sortChildren) : list, [sortChildren]);
|
|
15720
|
+
const childKeys = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15721
|
+
const resolved = React.useRef(/* @__PURE__ */ new Map()).current;
|
|
15722
|
+
const below = (key) => [.../* @__PURE__ */ new Set([...(childKeys.get(key) ?? []).flatMap((k) => [k, ...below(k)]), ...resolved.get(key) ?? []])];
|
|
15723
|
+
const stateOf = (key) => {
|
|
15724
|
+
const all = choices?.selected;
|
|
15725
|
+
const own = all?.has(key) ?? false;
|
|
15726
|
+
const ds = below(key);
|
|
15727
|
+
if (ds.length === 0) return own ? "on" : "off";
|
|
15728
|
+
const chosen = ds.filter((k) => all?.has(k)).length;
|
|
15729
|
+
if (chosen === ds.length) return "on";
|
|
15730
|
+
return chosen === 0 && !own ? "off" : "mixed";
|
|
15731
|
+
};
|
|
15732
|
+
const awaiting = React.useRef(/* @__PURE__ */ new Set()).current;
|
|
15733
|
+
const latest = React.useRef({
|
|
15734
|
+
expanded,
|
|
15735
|
+
choices
|
|
15736
|
+
});
|
|
15737
|
+
latest.current = {
|
|
15738
|
+
expanded,
|
|
15739
|
+
choices
|
|
15740
|
+
};
|
|
15741
|
+
const opening = React.useRef(/* @__PURE__ */ new Set()).current;
|
|
15742
|
+
const open = (keys) => {
|
|
15743
|
+
for (const k of keys) opening.add(k);
|
|
15744
|
+
latest.current.expanded.onChange(/* @__PURE__ */ new Set([...latest.current.expanded.expanded, ...opening]));
|
|
15745
|
+
};
|
|
15746
|
+
const unread = (key) => {
|
|
15747
|
+
const node = nodes.get(key);
|
|
15748
|
+
return node !== void 0 && (isBranch ? isBranch(node) : true) && !childKeys.has(key);
|
|
15749
|
+
};
|
|
15750
|
+
const tick = (keys) => {
|
|
15751
|
+
const toResolve = resolveBranch ? keys.filter(unread) : [];
|
|
15752
|
+
for (const k of toResolve) {
|
|
15753
|
+
const node = nodes.get(k);
|
|
15754
|
+
resolveBranch(node).then((under) => {
|
|
15755
|
+
resolved.set(k, under);
|
|
15756
|
+
latest.current.choices?.add([k, ...under]);
|
|
15757
|
+
setCovered(`${nodeLabel(node)} and its ${under.length === 1 ? `1 ${coverNoun[0]}` : `${format.integer(under.length)} ${coverNoun[1]}`}`);
|
|
15758
|
+
});
|
|
15759
|
+
}
|
|
15760
|
+
const toOpen = keys.filter((k) => unread(k) && !toResolve.includes(k));
|
|
15761
|
+
for (const k of toOpen) awaiting.add(k);
|
|
15762
|
+
if (toOpen.length) open(toOpen);
|
|
15763
|
+
};
|
|
15764
|
+
const settle = (key, kids) => {
|
|
15765
|
+
opening.delete(key);
|
|
15766
|
+
scrollToReveal.current();
|
|
15767
|
+
if (!awaiting.delete(key) || !latest.current.choices) return;
|
|
15768
|
+
const keys = kids.map(nodeKey);
|
|
15769
|
+
for (const kid of kids) nodes.set(nodeKey(kid), kid);
|
|
15770
|
+
latest.current.choices.add(keys);
|
|
15771
|
+
tick(keys);
|
|
15772
|
+
};
|
|
15773
|
+
const ctx = {
|
|
15774
|
+
useChildren,
|
|
15775
|
+
nodeKey,
|
|
15776
|
+
nodeLabel,
|
|
15777
|
+
isBranch,
|
|
15778
|
+
renderNode,
|
|
15779
|
+
expanded,
|
|
15780
|
+
loadingRow,
|
|
15781
|
+
emptyRow,
|
|
15782
|
+
nodes,
|
|
15783
|
+
childKeys,
|
|
15784
|
+
choices,
|
|
15785
|
+
stateOf,
|
|
15786
|
+
settle,
|
|
15787
|
+
current,
|
|
15788
|
+
sorted,
|
|
15789
|
+
count,
|
|
15790
|
+
badge
|
|
15791
|
+
};
|
|
15792
|
+
const revealed = reveal?.join("");
|
|
15793
|
+
React.useEffect(() => {
|
|
15794
|
+
if (!reveal || reveal.length === 0) return;
|
|
15795
|
+
const ancestors = reveal.slice(0, -1).filter((k) => !latest.current.expanded.isOpen(k));
|
|
15796
|
+
if (ancestors.length) latest.current.expanded.onChange(/* @__PURE__ */ new Set([...latest.current.expanded.expanded, ...ancestors]));
|
|
15797
|
+
}, [revealed]);
|
|
15798
|
+
scrollToReveal.current = () => {
|
|
15799
|
+
if (!reveal || reveal.length === 0 || roots.status !== "ready" || !scroller.current) return;
|
|
15800
|
+
const walk = (keys) => sorted(keys.map((k) => nodes.get(k)).filter((n) => n !== void 0)).map(nodeKey).flatMap((k) => latest.current.expanded.isOpen(k) && childKeys.has(k) ? [k, ...walk(childKeys.get(k))] : [k]);
|
|
15801
|
+
const i = walk(sorted(roots.data).map(nodeKey)).indexOf(reveal[reveal.length - 1]);
|
|
15802
|
+
if (i >= 0) scroller.current.scrollTop = Math.max(0, i * 32 - 32);
|
|
15803
|
+
};
|
|
15804
|
+
React.useEffect(() => scrollToReveal.current());
|
|
15805
|
+
if (roots.status === "loading") return /* @__PURE__ */ jsx("div", {
|
|
15806
|
+
role: "status",
|
|
15807
|
+
"aria-label": `${label}: loading`,
|
|
15808
|
+
className: cn("space-y-2 p-2", className),
|
|
15809
|
+
children: [
|
|
15810
|
+
0,
|
|
15811
|
+
1,
|
|
15812
|
+
2,
|
|
15813
|
+
3
|
|
15814
|
+
].map((i) => /* @__PURE__ */ jsx("div", {
|
|
15815
|
+
"aria-hidden": true,
|
|
15816
|
+
className: "h-4 animate-pulse rounded-pill bg-muted",
|
|
15817
|
+
style: { width: `${70 - i * 10}%` }
|
|
15818
|
+
}, i))
|
|
15573
15819
|
});
|
|
15574
|
-
return /* @__PURE__ */
|
|
15575
|
-
|
|
15576
|
-
className: cn("flex
|
|
15577
|
-
children:
|
|
15578
|
-
|
|
15579
|
-
|
|
15580
|
-
className: "
|
|
15581
|
-
|
|
15582
|
-
|
|
15583
|
-
|
|
15584
|
-
|
|
15585
|
-
|
|
15586
|
-
|
|
15587
|
-
|
|
15588
|
-
|
|
15589
|
-
|
|
15590
|
-
|
|
15591
|
-
|
|
15592
|
-
]
|
|
15593
|
-
}, k.key);
|
|
15594
|
-
})
|
|
15820
|
+
if (roots.status === "error") return /* @__PURE__ */ jsxs("div", {
|
|
15821
|
+
role: "alert",
|
|
15822
|
+
className: cn("flex items-center gap-3 rounded-surface bg-danger-subtle p-3 text-danger", className),
|
|
15823
|
+
children: [
|
|
15824
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
15825
|
+
"aria-hidden": true,
|
|
15826
|
+
className: "size-5 shrink-0"
|
|
15827
|
+
}),
|
|
15828
|
+
/* @__PURE__ */ jsx("p", {
|
|
15829
|
+
className: "min-w-0 flex-1 type-body-sm",
|
|
15830
|
+
children: roots.message
|
|
15831
|
+
}),
|
|
15832
|
+
/* @__PURE__ */ jsx(Button, {
|
|
15833
|
+
size: "sm",
|
|
15834
|
+
onPress: roots.retry,
|
|
15835
|
+
children: "Try again"
|
|
15836
|
+
})
|
|
15837
|
+
]
|
|
15595
15838
|
});
|
|
15596
|
-
|
|
15597
|
-
|
|
15598
|
-
|
|
15599
|
-
|
|
15600
|
-
|
|
15601
|
-
|
|
15602
|
-
const dragging = React.useRef(false);
|
|
15603
|
-
const hintId = React.useId();
|
|
15604
|
-
const run = React.useMemo(() => rangeBetween(ids, anchor, caret), [
|
|
15605
|
-
ids,
|
|
15606
|
-
anchor,
|
|
15607
|
-
caret
|
|
15608
|
-
]);
|
|
15609
|
-
const selected = React.useMemo(() => new Set(run), [run]);
|
|
15610
|
-
const n = run.length;
|
|
15611
|
-
const counted = (k) => format.count(k, unit[0], unit[1]);
|
|
15612
|
-
const moveCaret = (id, extend) => {
|
|
15613
|
-
if (id === null) return;
|
|
15614
|
-
setCaret(id);
|
|
15615
|
-
if (!extend || anchor === null) setAnchor(id);
|
|
15616
|
-
onCaretChange?.(id);
|
|
15839
|
+
const choose = (keys) => {
|
|
15840
|
+
const first = keys === "all" ? void 0 : [...keys][0];
|
|
15841
|
+
if (first === void 0 || isNote(String(first))) return;
|
|
15842
|
+
const key = String(first);
|
|
15843
|
+
const node = nodes.get(key);
|
|
15844
|
+
if (node !== void 0) onSelect?.(key, node);
|
|
15617
15845
|
};
|
|
15618
|
-
const
|
|
15619
|
-
|
|
15620
|
-
|
|
15621
|
-
|
|
15622
|
-
setSaid(kind === null ? `${counted(n)} cleared` : `${counted(n)} marked ${k?.label.toLowerCase() ?? kind}`);
|
|
15846
|
+
const displayKeys = choices ? [.../* @__PURE__ */ new Set([...choices.selected, ...nodes.keys()])].filter((k) => stateOf(k) === "on" || choices.selected.has(k) && !nodes.has(k)) : [];
|
|
15847
|
+
const shown = () => {
|
|
15848
|
+
const walk = (keys) => keys.flatMap((k) => expanded.isOpen(k) && childKeys.has(k) ? [k, ...walk(childKeys.get(k))] : [k]);
|
|
15849
|
+
return walk(roots.data.map(nodeKey));
|
|
15623
15850
|
};
|
|
15624
|
-
const
|
|
15625
|
-
|
|
15626
|
-
|
|
15627
|
-
keys
|
|
15628
|
-
|
|
15629
|
-
|
|
15630
|
-
|
|
15631
|
-
|
|
15632
|
-
|
|
15633
|
-
|
|
15634
|
-
|
|
15635
|
-
|
|
15636
|
-
|
|
15637
|
-
|
|
15638
|
-
|
|
15639
|
-
|
|
15640
|
-
const stop = () => dragging.current = false;
|
|
15641
|
-
window.addEventListener("pointerup", stop);
|
|
15642
|
-
return () => window.removeEventListener("pointerup", stop);
|
|
15643
|
-
}, []);
|
|
15644
|
-
const ctx = {
|
|
15645
|
-
kinds,
|
|
15646
|
-
marks,
|
|
15647
|
-
selected,
|
|
15648
|
-
caret,
|
|
15649
|
-
press: (e, id) => {
|
|
15650
|
-
if (e.button !== 0) return;
|
|
15651
|
-
dragging.current = true;
|
|
15652
|
-
if (e.shiftKey && anchor !== null) setCaret(id);
|
|
15851
|
+
const chooseMany = (keys) => {
|
|
15852
|
+
if (!choices) return;
|
|
15853
|
+
const wanted = new Set(choices.selected);
|
|
15854
|
+
if (keys === "all") {
|
|
15855
|
+
const rows = shown().flatMap((k) => [k, ...below(k)]);
|
|
15856
|
+
for (const x of rows) wanted.add(x);
|
|
15857
|
+
choices.onChange(wanted);
|
|
15858
|
+
tick(rows);
|
|
15859
|
+
return;
|
|
15860
|
+
}
|
|
15861
|
+
const display = new Set(displayKeys);
|
|
15862
|
+
const next = new Set([...keys].map(String).filter((k) => !isNote(k)));
|
|
15863
|
+
for (const k of /* @__PURE__ */ new Set([...next, ...display])) {
|
|
15864
|
+
if (next.has(k) === display.has(k)) continue;
|
|
15865
|
+
const under = [k, ...below(k)];
|
|
15866
|
+
for (const x of under) if (next.has(k)) wanted.add(x);
|
|
15653
15867
|
else {
|
|
15654
|
-
|
|
15655
|
-
|
|
15868
|
+
wanted.delete(x);
|
|
15869
|
+
awaiting.delete(x);
|
|
15656
15870
|
}
|
|
15657
|
-
|
|
15658
|
-
setSaid("");
|
|
15659
|
-
},
|
|
15660
|
-
over: (id) => {
|
|
15661
|
-
if (dragging.current && id !== caret) setCaret(id);
|
|
15662
|
-
}
|
|
15663
|
-
};
|
|
15664
|
-
React.useEffect(() => {
|
|
15665
|
-
if (n > 1) setSaid(`${counted(n)} selected`);
|
|
15666
|
-
else if (n === 1 && caret) setSaid(`${document.querySelector(`[data-mark-id="${CSS.escape(caret)}"]`)?.textContent ?? caret}`);
|
|
15667
|
-
}, [n, caret]);
|
|
15668
|
-
const keys = (e) => {
|
|
15669
|
-
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
|
15670
|
-
const to = e.key === "ArrowRight" ? stepId(ids, caret, 1) : e.key === "ArrowLeft" ? stepId(ids, caret, -1) : e.key === "Home" ? ids[0] ?? null : e.key === "End" ? ids[ids.length - 1] ?? null : void 0;
|
|
15671
|
-
if (to !== void 0) {
|
|
15672
|
-
e.preventDefault();
|
|
15673
|
-
moveCaret(to, e.shiftKey);
|
|
15674
|
-
} else if (e.key === "Escape" && (anchor !== null || caret !== null)) {
|
|
15675
|
-
e.preventDefault();
|
|
15676
|
-
setAnchor(null);
|
|
15677
|
-
setCaret(null);
|
|
15678
|
-
setSaid("Selection cleared");
|
|
15871
|
+
if (next.has(k)) tick(under);
|
|
15679
15872
|
}
|
|
15873
|
+
choices.onChange(wanted);
|
|
15680
15874
|
};
|
|
15875
|
+
const tree = /* @__PURE__ */ jsx(Tree$1, {
|
|
15876
|
+
ref: scroller,
|
|
15877
|
+
"aria-label": label,
|
|
15878
|
+
onAction: onCurrentChange ? (key) => {
|
|
15879
|
+
const k = String(key);
|
|
15880
|
+
const node = nodes.get(k);
|
|
15881
|
+
if (!isNote(k) && node !== void 0) onCurrentChange(k, node);
|
|
15882
|
+
} : void 0,
|
|
15883
|
+
selectionMode: choices ? "multiple" : "single",
|
|
15884
|
+
disallowEmptySelection: !choices,
|
|
15885
|
+
selectedKeys: choices ? displayKeys : selected === null ? [] : [selected],
|
|
15886
|
+
onSelectionChange: choices ? chooseMany : choose,
|
|
15887
|
+
expandedKeys: expanded.expanded,
|
|
15888
|
+
onExpandedChange: (keys) => {
|
|
15889
|
+
const next = new Set([...keys].map(String).filter((k) => !isNote(k)));
|
|
15890
|
+
if (beforeOpen) for (const k of [...next]) {
|
|
15891
|
+
const node = nodes.get(k);
|
|
15892
|
+
if (!expanded.isOpen(k) && node !== void 0 && beforeOpen(node) === false) next.delete(k);
|
|
15893
|
+
}
|
|
15894
|
+
expanded.onChange(next);
|
|
15895
|
+
},
|
|
15896
|
+
renderEmptyState: () => /* @__PURE__ */ jsx("p", {
|
|
15897
|
+
className: "p-3 type-body-sm text-muted-foreground",
|
|
15898
|
+
children: emptyRow
|
|
15899
|
+
}),
|
|
15900
|
+
className: cn("min-w-0 overflow-y-auto outline-none", !choices && className),
|
|
15901
|
+
style: { maxHeight: height },
|
|
15902
|
+
"data-strata-scroll": "",
|
|
15903
|
+
children: /* @__PURE__ */ jsx(Nodes, { nodes: roots.data })
|
|
15904
|
+
});
|
|
15905
|
+
const body = /* @__PURE__ */ jsx(Context.Provider, {
|
|
15906
|
+
value: ctx,
|
|
15907
|
+
children: /* @__PURE__ */ jsx(Virtualizer, {
|
|
15908
|
+
layout: ListLayout,
|
|
15909
|
+
layoutOptions: { rowHeight: 32 },
|
|
15910
|
+
children: tree
|
|
15911
|
+
})
|
|
15912
|
+
});
|
|
15913
|
+
if (!choices) return body;
|
|
15681
15914
|
return /* @__PURE__ */ jsxs("div", {
|
|
15682
|
-
className: cn("
|
|
15915
|
+
className: cn("grid min-w-0 gap-2", className),
|
|
15916
|
+
children: [
|
|
15917
|
+
/* @__PURE__ */ jsxs("div", {
|
|
15918
|
+
className: "flex items-center gap-2",
|
|
15919
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
15920
|
+
size: "sm",
|
|
15921
|
+
variant: "ghost",
|
|
15922
|
+
onPress: () => chooseMany("all"),
|
|
15923
|
+
children: "Select all shown"
|
|
15924
|
+
}), choices.count > 0 && /* @__PURE__ */ jsx(Button, {
|
|
15925
|
+
size: "sm",
|
|
15926
|
+
variant: "ghost",
|
|
15927
|
+
onPress: choices.clear,
|
|
15928
|
+
children: "Clear"
|
|
15929
|
+
})]
|
|
15930
|
+
}),
|
|
15931
|
+
body,
|
|
15932
|
+
/* @__PURE__ */ jsx("p", {
|
|
15933
|
+
role: "status",
|
|
15934
|
+
className: "sr-only",
|
|
15935
|
+
children: covered || choices.note
|
|
15936
|
+
})
|
|
15937
|
+
]
|
|
15938
|
+
});
|
|
15939
|
+
}
|
|
15940
|
+
// src/components/folder-picker.tsx
|
|
15941
|
+
var SEP = "/";
|
|
15942
|
+
var parts = (path) => path.split(SEP).filter(Boolean);
|
|
15943
|
+
var join = (parent, name) => `${parent === SEP ? "" : parent}${SEP}${name}`;
|
|
15944
|
+
/** The parent of a path, or `null` at the top. */
|
|
15945
|
+
var parentOf = (path) => {
|
|
15946
|
+
const p = parts(path);
|
|
15947
|
+
return p.length <= 1 ? null : `${SEP}${p.slice(0, -1).join(SEP)}`;
|
|
15948
|
+
};
|
|
15949
|
+
/** Every folder from the top down to `path`, which the tree must have open to show it. */
|
|
15950
|
+
var ancestorsOf = (path) => parts(path).slice(0, -1).map((_, i, a) => `${SEP}${a.slice(0, i + 1).join(SEP)}`);
|
|
15951
|
+
/** A server folder chooser: a lazy tree, a breadcrumb that is also editable text, Up, recents, a New folder field that shows the server's refusal, and Choose this folder as the one filled button. */
|
|
15952
|
+
function FolderPicker({ label, useFolders: useListing, value, onChange, onChoose, expanded, recent, canChoose, chooseLabel = "Choose this folder", onOpen, onCreate, topLabel = "Top", emptyRow = "No folders", height = "18rem", className }) {
|
|
15953
|
+
const useFolders = (path) => {
|
|
15954
|
+
const l = useListing(path);
|
|
15955
|
+
return l.status === "ready" && !Array.isArray(l.data) ? {
|
|
15956
|
+
...l,
|
|
15957
|
+
data: l.data.folders
|
|
15958
|
+
} : l;
|
|
15959
|
+
};
|
|
15960
|
+
const roots = useFolders(null);
|
|
15961
|
+
const siblings = useFolders(value ? parentOf(value) : null);
|
|
15962
|
+
const own = useListing(value);
|
|
15963
|
+
const folder = value && siblings.status === "ready" ? siblings.data.find((f) => f.path === value) : void 0;
|
|
15964
|
+
const footer = value && own.status === "ready" && !Array.isArray(own.data) ? own.data.footer : void 0;
|
|
15965
|
+
const verdict = value && canChoose ? canChoose(value, folder) : true;
|
|
15966
|
+
const reason = typeof verdict === "string" ? verdict : void 0;
|
|
15967
|
+
const reasonId = React.useId();
|
|
15968
|
+
const [editing, setEditing] = React.useState(false);
|
|
15969
|
+
const [text, setText] = React.useState("");
|
|
15970
|
+
const go = (path) => onChange(path);
|
|
15971
|
+
React.useEffect(() => {
|
|
15972
|
+
if (!value) return;
|
|
15973
|
+
const open = ancestorsOf(value).filter((a) => !expanded.isOpen(a));
|
|
15974
|
+
if (open.length) expanded.onChange(/* @__PURE__ */ new Set([...expanded.expanded, ...open]));
|
|
15975
|
+
}, [value, expanded]);
|
|
15976
|
+
const [name, setName] = React.useState("");
|
|
15977
|
+
const created = useAsyncAction(async (name) => {
|
|
15978
|
+
if (!value) return;
|
|
15979
|
+
await onCreate?.(value, name);
|
|
15980
|
+
setName("");
|
|
15981
|
+
go(join(value, name));
|
|
15982
|
+
expanded.setOpen(value, true);
|
|
15983
|
+
}, { validate: (name) => name.trim() ? void 0 : { name: "Name the new folder." } });
|
|
15984
|
+
const crumbs = value ? parts(value) : [];
|
|
15985
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
15986
|
+
"aria-label": label,
|
|
15987
|
+
className: cn("space-y-3", className),
|
|
15683
15988
|
children: [
|
|
15684
|
-
|
|
15685
|
-
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
15689
|
-
|
|
15690
|
-
|
|
15691
|
-
|
|
15692
|
-
|
|
15693
|
-
|
|
15694
|
-
|
|
15695
|
-
|
|
15696
|
-
|
|
15697
|
-
|
|
15698
|
-
|
|
15699
|
-
|
|
15700
|
-
|
|
15701
|
-
|
|
15702
|
-
|
|
15703
|
-
|
|
15704
|
-
|
|
15705
|
-
|
|
15706
|
-
|
|
15707
|
-
|
|
15708
|
-
children: "Clear mark"
|
|
15709
|
-
}),
|
|
15710
|
-
/* @__PURE__ */ jsx(Button, {
|
|
15989
|
+
/* @__PURE__ */ jsxs("div", {
|
|
15990
|
+
className: "flex flex-wrap items-center gap-2",
|
|
15991
|
+
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
15992
|
+
icon: ArrowUp,
|
|
15993
|
+
label: "Up one folder",
|
|
15994
|
+
onPress: () => go(value ? parentOf(value) : null),
|
|
15995
|
+
disabled: !value
|
|
15996
|
+
}), editing ? /* @__PURE__ */ jsxs("form", {
|
|
15997
|
+
className: "flex min-w-0 flex-1 items-center gap-2",
|
|
15998
|
+
onSubmit: (e) => {
|
|
15999
|
+
e.preventDefault();
|
|
16000
|
+
const typed = text.trim();
|
|
16001
|
+
go(typed ? (typed.startsWith(SEP) ? typed : `${SEP}${typed}`).replace(/\/+$/, "") || SEP : null);
|
|
16002
|
+
setEditing(false);
|
|
16003
|
+
},
|
|
16004
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
16005
|
+
"aria-label": "Folder path",
|
|
16006
|
+
value: text,
|
|
16007
|
+
autoFocus: true,
|
|
16008
|
+
onChange: (e) => setText(e.target.value),
|
|
16009
|
+
onKeyDown: (e) => e.key === "Escape" && (e.stopPropagation(), setEditing(false)),
|
|
16010
|
+
className: "min-w-0 flex-1 font-mono",
|
|
16011
|
+
size: "sm"
|
|
16012
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
15711
16013
|
size: "sm",
|
|
15712
|
-
|
|
15713
|
-
|
|
15714
|
-
|
|
15715
|
-
|
|
15716
|
-
|
|
15717
|
-
|
|
16014
|
+
type: "submit",
|
|
16015
|
+
children: "Go"
|
|
16016
|
+
})]
|
|
16017
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("nav", {
|
|
16018
|
+
"aria-label": "Folder path",
|
|
16019
|
+
className: "min-w-0 flex-1",
|
|
16020
|
+
children: /* @__PURE__ */ jsxs("ol", {
|
|
16021
|
+
className: "flex flex-wrap items-center gap-x-1 type-body-sm",
|
|
16022
|
+
children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Button, {
|
|
16023
|
+
size: "sm",
|
|
16024
|
+
variant: "ghost",
|
|
16025
|
+
onPress: () => go(null),
|
|
16026
|
+
"aria-current": value ? void 0 : "location",
|
|
16027
|
+
children: topLabel
|
|
16028
|
+
}) }), crumbs.map((c, i) => {
|
|
16029
|
+
const path = `${SEP}${crumbs.slice(0, i + 1).join(SEP)}`;
|
|
16030
|
+
const last = i === crumbs.length - 1;
|
|
16031
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
16032
|
+
className: "flex min-w-0 items-center gap-1",
|
|
16033
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
16034
|
+
"aria-hidden": true,
|
|
16035
|
+
className: "text-muted-foreground",
|
|
16036
|
+
children: "/"
|
|
16037
|
+
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
16038
|
+
label: path,
|
|
16039
|
+
side: "bottom",
|
|
16040
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
16041
|
+
size: "sm",
|
|
16042
|
+
variant: "ghost",
|
|
16043
|
+
onPress: () => go(path),
|
|
16044
|
+
"aria-current": last ? "location" : void 0,
|
|
16045
|
+
className: cn("max-w-48 truncate", last && "font-medium"),
|
|
16046
|
+
children: c
|
|
16047
|
+
})
|
|
16048
|
+
})]
|
|
16049
|
+
}, path);
|
|
16050
|
+
})]
|
|
15718
16051
|
})
|
|
15719
|
-
|
|
16052
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
16053
|
+
icon: Pencil,
|
|
16054
|
+
label: "Edit path",
|
|
16055
|
+
onPress: () => {
|
|
16056
|
+
setText(value ?? "");
|
|
16057
|
+
setEditing(true);
|
|
16058
|
+
}
|
|
16059
|
+
})] })]
|
|
15720
16060
|
}),
|
|
15721
|
-
/* @__PURE__ */ jsx(
|
|
15722
|
-
|
|
15723
|
-
children: /* @__PURE__ */ jsx(
|
|
15724
|
-
|
|
15725
|
-
|
|
15726
|
-
|
|
15727
|
-
|
|
15728
|
-
|
|
15729
|
-
|
|
15730
|
-
|
|
16061
|
+
/* @__PURE__ */ jsx("div", {
|
|
16062
|
+
className: "rounded-surface border border-border",
|
|
16063
|
+
children: /* @__PURE__ */ jsx(Tree, {
|
|
16064
|
+
label: `${label}: folders`,
|
|
16065
|
+
roots,
|
|
16066
|
+
useChildren: (f) => useFolders(f.path),
|
|
16067
|
+
nodeKey: (f) => f.path,
|
|
16068
|
+
nodeLabel: (f) => f.badge ? `${f.name}, ${f.badge}` : f.name,
|
|
16069
|
+
beforeOpen: onOpen ? (f) => {
|
|
16070
|
+
if (onOpen(f) !== "choose") return true;
|
|
16071
|
+
go(f.path);
|
|
16072
|
+
onChoose(f.path);
|
|
16073
|
+
return false;
|
|
16074
|
+
} : void 0,
|
|
16075
|
+
renderNode: (f) => /* @__PURE__ */ jsxs("span", {
|
|
16076
|
+
className: "flex min-w-0 items-baseline gap-2",
|
|
16077
|
+
children: [
|
|
16078
|
+
/* @__PURE__ */ jsx("span", {
|
|
16079
|
+
className: "truncate",
|
|
16080
|
+
children: f.name
|
|
16081
|
+
}),
|
|
16082
|
+
f.badge && /* @__PURE__ */ jsx(Status, {
|
|
16083
|
+
tone: f.tone ?? "neutral",
|
|
16084
|
+
className: "self-center",
|
|
16085
|
+
children: f.badge
|
|
16086
|
+
}),
|
|
16087
|
+
f.count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
16088
|
+
className: "type-caption tabular-nums text-muted-foreground",
|
|
16089
|
+
children: format.integer(f.count)
|
|
16090
|
+
})
|
|
16091
|
+
]
|
|
16092
|
+
}),
|
|
16093
|
+
selected: value,
|
|
16094
|
+
onSelect: (key) => onChange(key),
|
|
16095
|
+
expanded,
|
|
16096
|
+
emptyRow,
|
|
16097
|
+
height
|
|
15731
16098
|
})
|
|
15732
16099
|
}),
|
|
15733
|
-
/* @__PURE__ */
|
|
15734
|
-
|
|
15735
|
-
|
|
15736
|
-
|
|
16100
|
+
recent && recent.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
16101
|
+
role: "group",
|
|
16102
|
+
"aria-label": "Recent folders",
|
|
16103
|
+
className: "flex flex-wrap items-center gap-2",
|
|
16104
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
16105
|
+
className: "type-caption text-muted-foreground",
|
|
16106
|
+
children: "Recent"
|
|
16107
|
+
}), recent.map((r) => /* @__PURE__ */ jsx(Tooltip, {
|
|
16108
|
+
label: r,
|
|
16109
|
+
side: "bottom",
|
|
16110
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
16111
|
+
size: "sm",
|
|
16112
|
+
variant: "outline",
|
|
16113
|
+
onPress: () => go(r),
|
|
16114
|
+
className: "max-w-64 truncate font-mono",
|
|
16115
|
+
children: r
|
|
16116
|
+
})
|
|
16117
|
+
}, r))]
|
|
15737
16118
|
}),
|
|
15738
|
-
/* @__PURE__ */ jsx(
|
|
15739
|
-
|
|
15740
|
-
|
|
16119
|
+
onCreate && /* @__PURE__ */ jsx("form", {
|
|
16120
|
+
onSubmit: (e) => {
|
|
16121
|
+
e.preventDefault();
|
|
16122
|
+
created.run(name.trim());
|
|
16123
|
+
},
|
|
16124
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
16125
|
+
label: "New folder",
|
|
16126
|
+
hint: value ? `It will be made in ${value}.` : "Open a folder first.",
|
|
16127
|
+
error: created.fieldErrors.name ?? (created.phase === "error" ? created.error : void 0),
|
|
16128
|
+
action: /* @__PURE__ */ jsx(AsyncButton, {
|
|
16129
|
+
type: "submit",
|
|
16130
|
+
phase: created.phase,
|
|
16131
|
+
error: created.error,
|
|
16132
|
+
disabled: !value,
|
|
16133
|
+
labels: {
|
|
16134
|
+
idle: "Make folder",
|
|
16135
|
+
pending: "Making…",
|
|
16136
|
+
done: "Made"
|
|
16137
|
+
}
|
|
16138
|
+
}),
|
|
16139
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
16140
|
+
value: name,
|
|
16141
|
+
disabled: !value,
|
|
16142
|
+
onChange: (e) => {
|
|
16143
|
+
setName(e.target.value);
|
|
16144
|
+
created.clearFieldError("name");
|
|
16145
|
+
}
|
|
16146
|
+
})
|
|
16147
|
+
})
|
|
15741
16148
|
}),
|
|
15742
|
-
|
|
15743
|
-
|
|
15744
|
-
|
|
15745
|
-
unit
|
|
16149
|
+
footer && /* @__PURE__ */ jsx("p", {
|
|
16150
|
+
className: "type-body-sm text-muted-foreground",
|
|
16151
|
+
children: footer
|
|
15746
16152
|
}),
|
|
15747
|
-
/* @__PURE__ */
|
|
15748
|
-
|
|
15749
|
-
|
|
15750
|
-
|
|
15751
|
-
|
|
16153
|
+
/* @__PURE__ */ jsxs("div", {
|
|
16154
|
+
className: "flex flex-wrap items-center justify-end gap-3",
|
|
16155
|
+
children: [reason && /* @__PURE__ */ jsx("p", {
|
|
16156
|
+
id: reasonId,
|
|
16157
|
+
className: "min-w-0 flex-1 type-body-sm text-muted-foreground",
|
|
16158
|
+
children: reason
|
|
16159
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
16160
|
+
variant: "default",
|
|
16161
|
+
disabled: !value || reason !== void 0,
|
|
16162
|
+
"aria-describedby": reason ? reasonId : void 0,
|
|
16163
|
+
onPress: () => value && onChoose(value),
|
|
16164
|
+
children: chooseLabel
|
|
16165
|
+
})]
|
|
15752
16166
|
})
|
|
15753
16167
|
]
|
|
15754
16168
|
});
|
|
15755
16169
|
}
|
|
15756
|
-
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, ContextMenu, Conversation, CursorScope, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, PlayWindowButton, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, SaveStatus, SecretField, SeekBar, SelectableGrid, SequenceTimeline, SideNav, Skeleton, Slider, SortableList, SpanActions, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, Workspace, actualPixelsScale, ancestorsOf, boxViewport, buttonVariants, canFullscreen, clampToRoom, clampViewport, cn, colorSchemeScript, commandShortcut, countMarks, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, describeRegion, detectPlatform, diffWords, differences, drawRect, ease, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, gainToVolume, geo, gridPoints, gutterOf, isDoubtful, isReservedChord, isTypingTarget, jobProgressText, joinMediaGroup, joinRects, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, parentOf, parseChord, parseInline, parseRichText, parseSort, peaksFromAudio, phraseAt, phraseDoubtful, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, resample, resamplePeaks, resizeRect, safeHref, sayPosition, serialiseSort, settleCut, snapToGrid, sortRows, splitRect, staleOf, stepId, stepOnGrid, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useSelection, useSharedCursor, useSystemColorScheme, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkspaceState, valueAt, viewOf, viewsOf, wordAt, zoomAt, zoomToBox };
|
|
16170
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, BookViewer, BoxList, BoxOverlay, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareAudio, CompareGrid, CompareText, CompareVideo, CompareVideoGrid, Composer, CompositionBar, ContextMenu, Conversation, CursorScope, DEFAULT_TOLERANCE, DataTable, DataView, Density, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FolderPicker, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, Lightbox, LineChart, LineChartGroup, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Mark, MarkSummary, MarkableText, MediaGroup, MediaPlayer, MediaStage, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, PairJudge, PairVote, Pane, PlayWindowButton, Popover, PropertyList, PropertyRow, RateChoice, RegionEditor, RichText, RowAction, SPEECH_RATES, SaveStatus, SecretField, SeekBar, SelectableGrid, SelectableGridSkeleton, SequenceTimeline, SideNav, Skeleton, Slider, SortableList, SpanActions, Split, StageGuides, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, TileGrid, TileGridSkeleton, TimeReadout, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, TranscriptView, Transport, Tree, UndoBar, ViewOptions, ViewportFrame, VirtualList, VolumeControl, Waveform, Workspace, actualPixelsScale, ancestorsOf, boxViewport, buttonVariants, canFullscreen, clampToRoom, clampViewport, cn, colorSchemeScript, commandShortcut, countMarks, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, describeRegion, detectPlatform, diffWords, differences, drawRect, ease, fetchJson, fieldErrorsOf, findPage, fitRect, format, formatChord, gainToVolume, geo, gridPoints, gutterOf, isDoubtful, isReservedChord, isTypingTarget, jobProgressText, joinMediaGroup, joinRects, labelOf, lerpRect, logScale, loudnessOf, matchEntities, matchGains, matchesAccept, matchesChord, measureLoudness, moveGutter, moveRect, noOverlap, normaliseAngle, pageName, parentOf, parseChord, parseInline, parseRichText, parseSort, peaksFromAudio, phraseAt, phraseDoubtful, phraseOfWordId, plainText, rangeBetween, readErrorBody, readPixels, readingOrder, regionShares, resample, resamplePeaks, resizeRect, safeHref, sayPosition, serialiseSort, settleCut, snapToGrid, sortRows, splitRect, staleOf, stepId, stepOnGrid, tickLabel, tickStep, ticksBetween, toDate, toLoad, toPeakPair, toast, toastTimeout, transportShortcuts, turnRect, turnedSize, typeSteps, useActiveItem, useAsyncAction, useAttachedSource, useAutoSave, useBookUrl, useBoxes, useChoices, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHistory, useHistoryState, useHotkeys, useInView, useInfiniteLoad, useJob, useJobAction, useLeaveGuard, useLightboxUrl, useLoad, useMediaElement, useMediaSpans, useSelection, useSharedCursor, useSystemColorScheme, useTimelineZoom, useUndoable, useViewOptions, useViewport, useWorkspaceState, valueAt, viewOf, viewsOf, wordAt, wordId, zoomAt, zoomToBox };
|
|
15757
16171
|
|
|
15758
16172
|
//# sourceMappingURL=index.js.map
|