@dloizides/ui-feedback 1.15.2 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createContext, useMemo, useContext, useCallback, useState, useEffect, useSyncExternalStore, Component, useRef } from 'react';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { StyleSheet, Platform, TouchableOpacity, Text, View, ActivityIndicator, Modal, Animated } from 'react-native';
3
+ import { StyleSheet, Platform, TouchableOpacity, Text, View, ActivityIndicator, Modal, useWindowDimensions, Animated, Pressable } from 'react-native';
4
4
  import { MIN_TOUCH_TARGET_PX } from '@dloizides/a11y';
5
5
  import { Skeleton } from '@dloizides/ui-motion';
6
6
  import { createPortal } from 'react-dom';
@@ -1190,7 +1190,253 @@ function ProgressBar(props) {
1190
1190
  }
1191
1191
  );
1192
1192
  }
1193
+ var styles12 = StyleSheet.create({
1194
+ button: {
1195
+ minHeight: MIN_TOUCH_TARGET_PX,
1196
+ minWidth: MIN_TOUCH_TARGET_PX,
1197
+ paddingHorizontal: 14,
1198
+ borderRadius: 6,
1199
+ borderWidth: 1,
1200
+ justifyContent: "center",
1201
+ alignItems: "center",
1202
+ alignSelf: "flex-start"
1203
+ },
1204
+ text: { fontSize: 14, fontWeight: "600" }
1205
+ });
1206
+ function RunCardButton({ label, hint, color, onPress, testID, disabled = false, expanded }) {
1207
+ return /* @__PURE__ */ jsx(
1208
+ Pressable,
1209
+ {
1210
+ accessibilityRole: "button",
1211
+ accessibilityLabel: label,
1212
+ accessibilityHint: hint,
1213
+ accessibilityState: { disabled, expanded },
1214
+ disabled,
1215
+ onPress,
1216
+ style: [styles12.button, { borderColor: color }, disabled ? { opacity: DISABLED_OPACITY } : null],
1217
+ testID,
1218
+ children: /* @__PURE__ */ jsx(Text, { style: [styles12.text, { color }], children: label })
1219
+ }
1220
+ );
1221
+ }
1222
+
1223
+ // src/LiveRunCard/runGroups.ts
1224
+ var STATE_RANK = { done: 0, pending: 1, running: 2, failed: 3 };
1225
+ var MIN_BAR_FRACTION = 0.02;
1226
+ var NONE = 0;
1227
+ function isEmptyDoneMarker(step) {
1228
+ return step.state === "done" && step.durationSec <= NONE;
1229
+ }
1230
+ function mergeRunSteps(flat) {
1231
+ const groups = [];
1232
+ const byId = /* @__PURE__ */ new Map();
1233
+ for (const s of flat) {
1234
+ let group = byId.get(s.groupId);
1235
+ if (group === void 0) {
1236
+ group = { id: s.groupId, label: s.groupLabel, state: "done", durationSec: NONE, steps: [] };
1237
+ byId.set(s.groupId, group);
1238
+ groups.push(group);
1239
+ }
1240
+ const durationSec = Math.max(NONE, s.durationSec);
1241
+ group.durationSec += durationSec;
1242
+ if (STATE_RANK[s.state] > STATE_RANK[group.state]) group.state = s.state;
1243
+ if (!isEmptyDoneMarker(s)) group.steps.push({ label: s.label, durationSec, state: s.state });
1244
+ }
1245
+ return groups;
1246
+ }
1247
+ function splitShorterSteps(steps, keep) {
1248
+ if (steps.length <= keep) return { visible: [...steps], hiddenCount: NONE };
1249
+ const ranked = steps.map((step, index) => ({ step, index })).sort((a, b) => b.step.durationSec - a.step.durationSec || a.index - b.index);
1250
+ const kept = new Set(ranked.slice(0, keep).map((r) => r.index));
1251
+ steps.forEach((step, index) => {
1252
+ if (step.state === "running") kept.add(index);
1253
+ });
1254
+ const visible = steps.filter((_, index) => kept.has(index));
1255
+ return { visible, hiddenCount: steps.length - visible.length };
1256
+ }
1257
+ function defaultGroupId(groups) {
1258
+ const active = groups.find((g) => g.state === "running") ?? groups.find((g) => g.state === "failed");
1259
+ if (active !== void 0) return active.id;
1260
+ return groups.at(-1)?.id ?? null;
1261
+ }
1262
+ function summariseDoneGroups(groups) {
1263
+ const done = groups.filter((g) => g.state === "done");
1264
+ return { count: done.length, durationSec: done.reduce((sum, g) => sum + g.durationSec, NONE) };
1265
+ }
1266
+ function barFraction(durationSec, maxSec) {
1267
+ if (maxSec <= NONE || durationSec <= NONE) return NONE;
1268
+ return Math.min(1, Math.max(MIN_BAR_FRACTION, durationSec / maxSec));
1269
+ }
1270
+ function progressPercent(progress) {
1271
+ if (!progress || progress.total <= NONE) return null;
1272
+ return Math.max(NONE, progress.done) / progress.total * 100;
1273
+ }
1274
+
1275
+ // src/LiveRunCard/runTone.ts
1276
+ function scale(theme, name) {
1277
+ const found = theme.semantic[name];
1278
+ return found?.["500"];
1279
+ }
1280
+ function runToneColor(theme, state) {
1281
+ if (state === "failed") return theme.semantic.error["500"];
1282
+ if (state === "running") return scale(theme, "warning") ?? theme.palette.primary["500"];
1283
+ if (state === "done") return scale(theme, "success") ?? theme.colors.text;
1284
+ return theme.colors.textSecondary;
1285
+ }
1286
+ var MARK = { done: "\u2713", running: "\u25CF", pending: "\u25CB", failed: "\u2715" };
1287
+ var styles13 = StyleSheet.create({
1288
+ row: { flexDirection: "row", flexWrap: "wrap", gap: 6 },
1289
+ chip: { borderWidth: 1, borderRadius: 6, paddingHorizontal: 10, justifyContent: "center" },
1290
+ tap: { minHeight: MIN_TOUCH_TARGET_PX },
1291
+ still: { paddingVertical: 4 },
1292
+ text: { fontSize: 13, fontVariant: ["tabular-nums"] },
1293
+ strong: { fontWeight: "700" }
1294
+ });
1295
+ function chipText(group, labels) {
1296
+ return `${MARK[group.state]} ${group.label} ${labels.formatDuration(group.durationSec)}`;
1297
+ }
1298
+ function RunGroupChips({ groups, labels, testID, selectedId = null, onSelect }) {
1299
+ const { theme } = useFeedbackUi();
1300
+ return /* @__PURE__ */ jsx(View, { style: styles13.row, testID, children: groups.map((group) => {
1301
+ const color = runToneColor(theme, group.state);
1302
+ const selected = group.id === selectedId;
1303
+ const a11y = labels.groupA11y(group.label, group.state, labels.formatDuration(group.durationSec));
1304
+ const body = /* @__PURE__ */ jsx(Text, { style: [styles13.text, { color }, selected || group.state === "running" ? styles13.strong : null], children: chipText(group, labels) });
1305
+ const look = [styles13.chip, { borderColor: color, backgroundColor: selected ? theme.colors.surfaceElevated : theme.colors.surface }];
1306
+ if (onSelect === void 0) {
1307
+ return /* @__PURE__ */ jsx(View, { style: [look, styles13.still], accessible: true, accessibilityLabel: a11y, testID: `${testID}-${group.id}`, children: body }, group.id);
1308
+ }
1309
+ return /* @__PURE__ */ jsx(
1310
+ Pressable,
1311
+ {
1312
+ accessibilityRole: "button",
1313
+ accessibilityLabel: a11y,
1314
+ accessibilityHint: labels.groupHint,
1315
+ accessibilityState: { selected },
1316
+ onPress: () => onSelect(group.id),
1317
+ style: [look, styles13.tap],
1318
+ testID: `${testID}-${group.id}`,
1319
+ children: body
1320
+ },
1321
+ group.id
1322
+ );
1323
+ }) });
1324
+ }
1325
+ function RunGroupSummary({ groups, labels, testID }) {
1326
+ const { theme } = useFeedbackUi();
1327
+ const done = summariseDoneGroups(groups);
1328
+ const open = groups.filter((g) => g.state !== "done");
1329
+ const doneColor = runToneColor(theme, "done");
1330
+ const doneText = labels.doneSummary(done.count, labels.formatDuration(done.durationSec));
1331
+ return /* @__PURE__ */ jsxs(View, { style: styles13.row, testID, children: [
1332
+ done.count > 0 ? /* @__PURE__ */ jsx(View, { style: [styles13.chip, styles13.still, { borderColor: doneColor }], accessible: true, accessibilityLabel: doneText, testID: `${testID}-done`, children: /* @__PURE__ */ jsx(Text, { style: [styles13.text, { color: doneColor }], children: `${MARK.done} ${doneText}` }) }) : null,
1333
+ /* @__PURE__ */ jsx(RunGroupChips, { groups: open, labels, testID: `${testID}-open` })
1334
+ ] });
1335
+ }
1336
+ var BAR_HEIGHT2 = 8;
1337
+ var LABEL_MIN_WIDTH = 220;
1338
+ var LABEL_SHARE = "35%";
1339
+ var LABEL_LINES = 2;
1340
+ var DURATION_WIDTH = 64;
1341
+ var PERCENT = 100;
1342
+ var styles14 = StyleSheet.create({
1343
+ list: { gap: 6 },
1344
+ row: { flexDirection: "row", alignItems: "center", gap: 8 },
1345
+ stack: { gap: 4 },
1346
+ label: { fontSize: 13, flexBasis: LABEL_SHARE, flexGrow: 0, flexShrink: 0, minWidth: LABEL_MIN_WIDTH },
1347
+ compactLabel: { fontSize: 13, flexGrow: 1, flexShrink: 1, minWidth: 0 },
1348
+ track: { flexGrow: 1, flexShrink: 1, flexBasis: 80, height: BAR_HEIGHT2, borderRadius: 2, overflow: "hidden" },
1349
+ fullTrack: { height: BAR_HEIGHT2, borderRadius: 2, overflow: "hidden" },
1350
+ fill: { height: "100%", borderRadius: 2 },
1351
+ duration: { fontSize: 13, width: DURATION_WIDTH, textAlign: "right", fontVariant: ["tabular-nums"] },
1352
+ strong: { fontWeight: "700" }
1353
+ });
1354
+ function RunStepBars({ steps, maxBars, labels, compact, testID }) {
1355
+ const { theme } = useFeedbackUi();
1356
+ const [all, setAll] = useState(false);
1357
+ const split = splitShorterSteps(steps, all ? steps.length : maxBars);
1358
+ const maxSec = steps.reduce((m, s) => Math.max(m, s.durationSec), 0);
1359
+ const folded = split.hiddenCount > 0;
1360
+ const canFold = all && steps.length > maxBars;
1361
+ return /* @__PURE__ */ jsxs(View, { style: styles14.list, testID, children: [
1362
+ split.visible.map((step, i) => {
1363
+ const color = runToneColor(theme, step.state);
1364
+ const duration = labels.formatDuration(step.durationSec);
1365
+ const strong = step.state === "running" ? styles14.strong : null;
1366
+ const name = /* @__PURE__ */ jsx(Text, { style: [compact ? styles14.compactLabel : styles14.label, { color: theme.colors.text }, strong], numberOfLines: LABEL_LINES, testID: `${testID}-name-${String(i)}`, children: step.label });
1367
+ const time = /* @__PURE__ */ jsx(Text, { style: [styles14.duration, { color: theme.colors.textSecondary }, strong], children: duration });
1368
+ const bar = /* @__PURE__ */ jsx(View, { style: [compact ? styles14.fullTrack : styles14.track, { backgroundColor: theme.colors.border }], children: /* @__PURE__ */ jsx(View, { style: [styles14.fill, { backgroundColor: color, width: `${barFraction(step.durationSec, maxSec) * PERCENT}%` }] }) });
1369
+ const a11y = { accessible: true, accessibilityLabel: labels.stepA11y(step.label, duration), testID: `${testID}-row-${String(i)}` };
1370
+ return compact ? /* @__PURE__ */ jsxs(View, { style: styles14.stack, ...a11y, children: [
1371
+ /* @__PURE__ */ jsxs(View, { style: styles14.row, children: [
1372
+ name,
1373
+ time
1374
+ ] }),
1375
+ bar
1376
+ ] }, `${step.label}-${String(i)}`) : /* @__PURE__ */ jsxs(View, { style: styles14.row, ...a11y, children: [
1377
+ name,
1378
+ bar,
1379
+ time
1380
+ ] }, `${step.label}-${String(i)}`);
1381
+ }),
1382
+ folded || canFold ? /* @__PURE__ */ jsx(
1383
+ RunCardButton,
1384
+ {
1385
+ label: folded ? labels.moreSteps(split.hiddenCount) : labels.fewerSteps,
1386
+ hint: labels.moreStepsHint,
1387
+ color: theme.colors.textSecondary,
1388
+ onPress: () => setAll(!all),
1389
+ expanded: all,
1390
+ testID: `${testID}-more`
1391
+ }
1392
+ ) : null
1393
+ ] });
1394
+ }
1395
+ var LIVE_RUN_CARD_COMPACT_MAX_PX = 640;
1396
+ var DEFAULT_MAX_BARS = 4;
1397
+ var styles15 = StyleSheet.create({
1398
+ card: { borderWidth: 1, borderRadius: 8, padding: 14, gap: 10 },
1399
+ head: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 10 },
1400
+ titleBox: { flexGrow: 1, flexShrink: 1, flexBasis: 200, minWidth: 0, gap: 2 },
1401
+ pill: { borderWidth: 1, borderRadius: 999, paddingHorizontal: 10, paddingVertical: 2, alignSelf: "flex-start" },
1402
+ pillText: { fontSize: 12, fontWeight: "700" },
1403
+ title: { fontSize: 16, fontWeight: "700" },
1404
+ meta: { fontSize: 13 },
1405
+ step: { fontSize: 14, fontWeight: "600" }
1406
+ });
1407
+ function LiveRunCard(props) {
1408
+ const { title, status = "running", currentStep = null, progress = null, groups, labels, onCancel, cancelDisabled = false } = props;
1409
+ const { maxBars = DEFAULT_MAX_BARS, testID = "live-run-card" } = props;
1410
+ const { theme } = useFeedbackUi();
1411
+ const { width } = useWindowDimensions();
1412
+ const compact = props.compact ?? width < LIVE_RUN_CARD_COMPACT_MAX_PX;
1413
+ const [picked, setPicked] = useState(null);
1414
+ const [open, setOpen] = useState(false);
1415
+ const selectedId = groups.some((g) => g.id === picked) ? picked : defaultGroupId(groups);
1416
+ const selected = groups.find((g) => g.id === selectedId);
1417
+ const tone = runToneColor(theme, status);
1418
+ const percent = progressPercent(progress);
1419
+ const showTimings = !compact || open;
1420
+ const muted = { color: theme.colors.textSecondary };
1421
+ return /* @__PURE__ */ jsxs(View, { style: [styles15.card, { borderColor: tone, backgroundColor: theme.colors.surface }], testID, children: [
1422
+ /* @__PURE__ */ jsxs(View, { style: styles15.head, children: [
1423
+ /* @__PURE__ */ jsx(View, { style: [styles15.pill, { borderColor: tone }], children: /* @__PURE__ */ jsx(Text, { style: [styles15.pillText, { color: tone }], testID: `${testID}-status`, children: labels.status }) }),
1424
+ /* @__PURE__ */ jsxs(View, { style: styles15.titleBox, children: [
1425
+ /* @__PURE__ */ jsx(Text, { style: [styles15.title, { color: theme.colors.text }], testID: `${testID}-title`, children: title }),
1426
+ /* @__PURE__ */ jsx(Text, { style: [styles15.meta, muted], testID: `${testID}-meta`, children: labels.meta })
1427
+ ] }),
1428
+ onCancel !== void 0 ? /* @__PURE__ */ jsx(RunCardButton, { label: labels.cancel, hint: labels.cancelHint, color: theme.semantic.error["500"], onPress: onCancel, disabled: cancelDisabled, testID: `${testID}-cancel` }) : null
1429
+ ] }),
1430
+ currentStep !== null && currentStep !== "" ? /* @__PURE__ */ jsx(Text, { style: [styles15.step, { color: theme.colors.text }], testID: `${testID}-step`, children: currentStep }) : null,
1431
+ percent !== null ? /* @__PURE__ */ jsx(ProgressBar, { percent, label: labels.progress, accessibilityLabel: labels.progressA11y, color: tone, testID: `${testID}-progress` }) : null,
1432
+ percent === null && labels.progress !== void 0 ? /* @__PURE__ */ jsx(Text, { style: [styles15.meta, muted], testID: `${testID}-progress-text`, children: labels.progress }) : null,
1433
+ compact && !open ? /* @__PURE__ */ jsx(RunGroupSummary, { groups, labels, testID: `${testID}-summary` }) : null,
1434
+ compact ? /* @__PURE__ */ jsx(RunCardButton, { label: labels.stepTimings, hint: labels.stepTimingsHint, color: theme.colors.textSecondary, onPress: () => setOpen(!open), expanded: open, testID: `${testID}-timings-toggle` }) : null,
1435
+ showTimings ? /* @__PURE__ */ jsx(RunGroupChips, { groups, labels, selectedId, onSelect: setPicked, testID: `${testID}-groups` }) : null,
1436
+ showTimings && selected !== void 0 && selected.steps.length > 0 ? /* @__PURE__ */ jsx(RunStepBars, { steps: selected.steps, maxBars, labels, compact, testID: `${testID}-steps` }, selected.id) : null
1437
+ ] });
1438
+ }
1193
1439
 
1194
- export { AppErrorBoundary, AsyncSurface, ConfirmDialog, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, ErrorState, FEEDBACK_TEST_IDS, FeedbackUiProvider, LoadingFallback, MODAL_OVERLAY_COLOR, PageSkeleton, ProgressBar, ToastHost, FeedbackUiProvider as UiProvider, WARMING_QUIET_PERIOD_MS, WarmingOverlay, clampPercent, createToastBus, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
1440
+ export { AppErrorBoundary, AsyncSurface, ConfirmDialog, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, ErrorState, FEEDBACK_TEST_IDS, FeedbackUiProvider, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, LoadingFallback, MODAL_OVERLAY_COLOR, PageSkeleton, ProgressBar, ToastHost, FeedbackUiProvider as UiProvider, WARMING_QUIET_PERIOD_MS, WarmingOverlay, barFraction, clampPercent, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useFeedbackUi, useFeedbackUi as useUi };
1195
1441
  //# sourceMappingURL=index.mjs.map
1196
1442
  //# sourceMappingURL=index.mjs.map