@dloizides/ui-feedback 1.15.2 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/index.d.mts +85 -1
- package/dist/index.d.ts +85 -1
- package/dist/index.js +240 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,238 @@ 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_BASIS = 150;
|
|
1338
|
+
var DURATION_WIDTH = 64;
|
|
1339
|
+
var PERCENT = 100;
|
|
1340
|
+
var styles14 = StyleSheet.create({
|
|
1341
|
+
list: { gap: 6 },
|
|
1342
|
+
row: { flexDirection: "row", alignItems: "center", gap: 8, flexWrap: "wrap" },
|
|
1343
|
+
label: { fontSize: 13, flexBasis: LABEL_BASIS, flexGrow: 0, flexShrink: 1, minWidth: 0 },
|
|
1344
|
+
track: { flexGrow: 1, flexShrink: 1, flexBasis: 80, height: BAR_HEIGHT2, borderRadius: 2, overflow: "hidden" },
|
|
1345
|
+
fill: { height: "100%", borderRadius: 2 },
|
|
1346
|
+
duration: { fontSize: 13, width: DURATION_WIDTH, textAlign: "right", fontVariant: ["tabular-nums"] },
|
|
1347
|
+
strong: { fontWeight: "700" }
|
|
1348
|
+
});
|
|
1349
|
+
function RunStepBars({ steps, maxBars, labels, testID }) {
|
|
1350
|
+
const { theme } = useFeedbackUi();
|
|
1351
|
+
const [all, setAll] = useState(false);
|
|
1352
|
+
const split = splitShorterSteps(steps, all ? steps.length : maxBars);
|
|
1353
|
+
const maxSec = steps.reduce((m, s) => Math.max(m, s.durationSec), 0);
|
|
1354
|
+
const folded = split.hiddenCount > 0;
|
|
1355
|
+
const canFold = all && steps.length > maxBars;
|
|
1356
|
+
return /* @__PURE__ */ jsxs(View, { style: styles14.list, testID, children: [
|
|
1357
|
+
split.visible.map((step, i) => {
|
|
1358
|
+
const color = runToneColor(theme, step.state);
|
|
1359
|
+
const duration = labels.formatDuration(step.durationSec);
|
|
1360
|
+
const strong = step.state === "running" ? styles14.strong : null;
|
|
1361
|
+
return /* @__PURE__ */ jsxs(View, { style: styles14.row, accessible: true, accessibilityLabel: labels.stepA11y(step.label, duration), testID: `${testID}-row-${String(i)}`, children: [
|
|
1362
|
+
/* @__PURE__ */ jsx(Text, { style: [styles14.label, { color: theme.colors.text }, strong], numberOfLines: 1, children: step.label }),
|
|
1363
|
+
/* @__PURE__ */ jsx(View, { style: [styles14.track, { backgroundColor: theme.colors.border }], children: /* @__PURE__ */ jsx(View, { style: [styles14.fill, { backgroundColor: color, width: `${barFraction(step.durationSec, maxSec) * PERCENT}%` }] }) }),
|
|
1364
|
+
/* @__PURE__ */ jsx(Text, { style: [styles14.duration, { color: theme.colors.textSecondary }, strong], children: duration })
|
|
1365
|
+
] }, `${step.label}-${String(i)}`);
|
|
1366
|
+
}),
|
|
1367
|
+
folded || canFold ? /* @__PURE__ */ jsx(
|
|
1368
|
+
RunCardButton,
|
|
1369
|
+
{
|
|
1370
|
+
label: folded ? labels.moreSteps(split.hiddenCount) : labels.fewerSteps,
|
|
1371
|
+
hint: labels.moreStepsHint,
|
|
1372
|
+
color: theme.colors.textSecondary,
|
|
1373
|
+
onPress: () => setAll(!all),
|
|
1374
|
+
expanded: all,
|
|
1375
|
+
testID: `${testID}-more`
|
|
1376
|
+
}
|
|
1377
|
+
) : null
|
|
1378
|
+
] });
|
|
1379
|
+
}
|
|
1380
|
+
var LIVE_RUN_CARD_COMPACT_MAX_PX = 640;
|
|
1381
|
+
var DEFAULT_MAX_BARS = 4;
|
|
1382
|
+
var styles15 = StyleSheet.create({
|
|
1383
|
+
card: { borderWidth: 1, borderRadius: 8, padding: 14, gap: 10 },
|
|
1384
|
+
head: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 10 },
|
|
1385
|
+
titleBox: { flexGrow: 1, flexShrink: 1, flexBasis: 200, minWidth: 0, gap: 2 },
|
|
1386
|
+
pill: { borderWidth: 1, borderRadius: 999, paddingHorizontal: 10, paddingVertical: 2, alignSelf: "flex-start" },
|
|
1387
|
+
pillText: { fontSize: 12, fontWeight: "700" },
|
|
1388
|
+
title: { fontSize: 16, fontWeight: "700" },
|
|
1389
|
+
meta: { fontSize: 13 },
|
|
1390
|
+
step: { fontSize: 14, fontWeight: "600" }
|
|
1391
|
+
});
|
|
1392
|
+
function LiveRunCard(props) {
|
|
1393
|
+
const { title, status = "running", currentStep = null, progress = null, groups, labels, onCancel, cancelDisabled = false } = props;
|
|
1394
|
+
const { maxBars = DEFAULT_MAX_BARS, testID = "live-run-card" } = props;
|
|
1395
|
+
const { theme } = useFeedbackUi();
|
|
1396
|
+
const { width } = useWindowDimensions();
|
|
1397
|
+
const compact = props.compact ?? width < LIVE_RUN_CARD_COMPACT_MAX_PX;
|
|
1398
|
+
const [picked, setPicked] = useState(null);
|
|
1399
|
+
const [open, setOpen] = useState(false);
|
|
1400
|
+
const selectedId = groups.some((g) => g.id === picked) ? picked : defaultGroupId(groups);
|
|
1401
|
+
const selected = groups.find((g) => g.id === selectedId);
|
|
1402
|
+
const tone = runToneColor(theme, status);
|
|
1403
|
+
const percent = progressPercent(progress);
|
|
1404
|
+
const showTimings = !compact || open;
|
|
1405
|
+
const muted = { color: theme.colors.textSecondary };
|
|
1406
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles15.card, { borderColor: tone, backgroundColor: theme.colors.surface }], testID, children: [
|
|
1407
|
+
/* @__PURE__ */ jsxs(View, { style: styles15.head, children: [
|
|
1408
|
+
/* @__PURE__ */ jsx(View, { style: [styles15.pill, { borderColor: tone }], children: /* @__PURE__ */ jsx(Text, { style: [styles15.pillText, { color: tone }], testID: `${testID}-status`, children: labels.status }) }),
|
|
1409
|
+
/* @__PURE__ */ jsxs(View, { style: styles15.titleBox, children: [
|
|
1410
|
+
/* @__PURE__ */ jsx(Text, { style: [styles15.title, { color: theme.colors.text }], testID: `${testID}-title`, children: title }),
|
|
1411
|
+
/* @__PURE__ */ jsx(Text, { style: [styles15.meta, muted], testID: `${testID}-meta`, children: labels.meta })
|
|
1412
|
+
] }),
|
|
1413
|
+
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
|
|
1414
|
+
] }),
|
|
1415
|
+
currentStep !== null && currentStep !== "" ? /* @__PURE__ */ jsx(Text, { style: [styles15.step, { color: theme.colors.text }], testID: `${testID}-step`, children: currentStep }) : null,
|
|
1416
|
+
percent !== null ? /* @__PURE__ */ jsx(ProgressBar, { percent, label: labels.progress, accessibilityLabel: labels.progressA11y, color: tone, testID: `${testID}-progress` }) : null,
|
|
1417
|
+
percent === null && labels.progress !== void 0 ? /* @__PURE__ */ jsx(Text, { style: [styles15.meta, muted], testID: `${testID}-progress-text`, children: labels.progress }) : null,
|
|
1418
|
+
compact ? /* @__PURE__ */ jsx(RunGroupSummary, { groups, labels, testID: `${testID}-summary` }) : null,
|
|
1419
|
+
compact ? /* @__PURE__ */ jsx(RunCardButton, { label: labels.stepTimings, hint: labels.stepTimingsHint, color: theme.colors.textSecondary, onPress: () => setOpen(!open), expanded: open, testID: `${testID}-timings-toggle` }) : null,
|
|
1420
|
+
showTimings ? /* @__PURE__ */ jsx(RunGroupChips, { groups, labels, selectedId, onSelect: setPicked, testID: `${testID}-groups` }) : null,
|
|
1421
|
+
showTimings && selected !== void 0 && selected.steps.length > 0 ? /* @__PURE__ */ jsx(RunStepBars, { steps: selected.steps, maxBars, labels, testID: `${testID}-steps` }, selected.id) : null
|
|
1422
|
+
] });
|
|
1423
|
+
}
|
|
1193
1424
|
|
|
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 };
|
|
1425
|
+
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
1426
|
//# sourceMappingURL=index.mjs.map
|
|
1196
1427
|
//# sourceMappingURL=index.mjs.map
|