@ordinatio/ui 1.9.0 → 1.10.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/dist/index.mjs CHANGED
@@ -3053,16 +3053,623 @@ var ACTIVITY_ICONS = {
3053
3053
  function resolveActivityIcon(name) {
3054
3054
  return ACTIVITY_ICONS[name] ?? Activity;
3055
3055
  }
3056
+
3057
+ // src/components/pipeline-board.tsx
3058
+ import { useEffect as useEffect22, useMemo as useMemo2, useRef as useRef19, useState as useState24 } from "react";
3059
+
3060
+ // src/lib/board-scroll.ts
3061
+ function nearestColumnIndex(scrollLeft, offsets) {
3062
+ if (offsets.length === 0) return 0;
3063
+ const at = Number.isFinite(scrollLeft) && scrollLeft > 0 ? scrollLeft : 0;
3064
+ let best = 0;
3065
+ let bestDistance = Math.abs((offsets[0] ?? 0) - at);
3066
+ for (let i = 1; i < offsets.length; i++) {
3067
+ const distance = Math.abs((offsets[i] ?? 0) - at);
3068
+ if (distance < bestDistance) {
3069
+ best = i;
3070
+ bestDistance = distance;
3071
+ }
3072
+ }
3073
+ return best;
3074
+ }
3075
+
3076
+ // src/components/board-column.tsx
3077
+ import { useId as useId5 } from "react";
3078
+
3079
+ // src/components/add-card-box.tsx
3080
+ import { useEffect as useEffect19, useId as useId4, useRef as useRef16, useState as useState20 } from "react";
3081
+
3082
+ // src/components/board-styles.ts
3083
+ var STRUCTURE = {
3084
+ root: { maxWidth: "100%", minWidth: 0, overflow: "hidden" },
3085
+ row: { display: "flex", alignItems: "flex-start", gap: "12px", overflowX: "auto", overflowY: "hidden", scrollSnapType: "x mandatory", overscrollBehaviorX: "contain", maxWidth: "100%", boxSizing: "border-box" },
3086
+ // About 85% of the screen on a phone (so the next column peeks in), at most 22rem on a wide screen.
3087
+ column: { flex: "0 0 min(85vw, 22rem)", scrollSnapAlign: "start", minWidth: 0, boxSizing: "border-box" },
3088
+ cardList: { listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: "8px" },
3089
+ card: { minWidth: 0, overflowWrap: "anywhere" }
3090
+ };
3091
+ var LOOK = {
3092
+ root: { fontSize: "16px", color: "#171717" },
3093
+ position: { margin: "0 0 8px", fontSize: "16px", color: "#525252" },
3094
+ column: { background: "#f4f4f5", borderRadius: "12px", padding: "12px" },
3095
+ columnDropOver: { background: "#e0e7ff" },
3096
+ columnHeader: { display: "flex", flexWrap: "wrap", alignItems: "baseline", gap: "4px 8px", marginBottom: "8px" },
3097
+ columnName: { margin: 0, fontSize: "18px", fontWeight: 700 },
3098
+ columnCount: { fontSize: "16px", color: "#525252" },
3099
+ columnTotals: { width: "100%", margin: 0, fontSize: "16px", color: "#404040" },
3100
+ empty: { margin: "8px 0", fontSize: "16px", color: "#525252" },
3101
+ card: { background: "#ffffff", borderRadius: "8px", padding: "12px", boxShadow: "0 1px 3px rgba(0,0,0,0.2)", fontSize: "16px" },
3102
+ cardPending: { opacity: 0.55 },
3103
+ cardDragging: { opacity: 0.4 },
3104
+ cardTitle: { margin: 0, fontSize: "16px", fontWeight: 600 },
3105
+ cardMeta: { margin: "4px 0 0", fontSize: "16px", color: "#404040" },
3106
+ overdue: { color: "#b91c1c", fontWeight: 700 },
3107
+ ownerMark: { display: "inline-flex", alignItems: "center", justifyContent: "center", minWidth: "28px", height: "28px", borderRadius: "14px", background: "#e5e5e5", fontSize: "14px", fontWeight: 700 },
3108
+ tagChip: { display: "inline-block", padding: "2px 8px", borderRadius: "999px", background: "#e5e7eb", fontSize: "14px" },
3109
+ badgeWon: { display: "inline-block", padding: "2px 8px", borderRadius: "6px", background: "#dcfce7", color: "#166534", fontSize: "14px", fontWeight: 700 },
3110
+ badgeLost: { display: "inline-block", padding: "2px 8px", borderRadius: "6px", background: "#fee2e2", color: "#991b1b", fontSize: "14px", fontWeight: 700 },
3111
+ cardError: { margin: "8px 0 0", fontSize: "16px", color: "#b91c1c" },
3112
+ showMore: { marginTop: "8px", minHeight: "44px", padding: "8px 12px", fontSize: "16px", border: "1px solid #d4d4d4", borderRadius: "8px", background: "#ffffff", cursor: "pointer" },
3113
+ addButton: { marginTop: "8px", minHeight: "44px", width: "100%", textAlign: "left", padding: "8px 12px", fontSize: "16px", border: "1px dashed #a3a3a3", borderRadius: "8px", background: "transparent", color: "#404040", cursor: "pointer" },
3114
+ addForm: { marginTop: "8px", display: "flex", flexDirection: "column", gap: "8px" },
3115
+ input: { minHeight: "44px", padding: "8px 12px", fontSize: "16px", border: "1px solid #a3a3a3", borderRadius: "8px", boxSizing: "border-box", width: "100%" },
3116
+ select: { minHeight: "44px", padding: "8px 12px", fontSize: "16px", border: "1px solid #a3a3a3", borderRadius: "8px", background: "#ffffff" },
3117
+ primaryButton: { minHeight: "44px", padding: "8px 16px", fontSize: "16px", border: "1px solid #1d4ed8", borderRadius: "8px", background: "#1d4ed8", color: "#ffffff", cursor: "pointer" },
3118
+ secondaryButton: { minHeight: "44px", padding: "8px 16px", fontSize: "16px", border: "1px solid #a3a3a3", borderRadius: "8px", background: "#ffffff", color: "#171717", cursor: "pointer" },
3119
+ error: { margin: 0, fontSize: "16px", color: "#b91c1c" },
3120
+ panel: { display: "flex", flexDirection: "column", gap: "8px", marginTop: "8px", padding: "12px", border: "1px solid #a3a3a3", borderRadius: "8px", background: "#ffffff" },
3121
+ panelTitle: { margin: 0, fontSize: "16px", fontWeight: 700 },
3122
+ choice: { minHeight: "44px", padding: "8px 12px", fontSize: "16px", border: "1px solid #a3a3a3", borderRadius: "8px", background: "#ffffff", cursor: "pointer" },
3123
+ choiceActive: { background: "#dbeafe", border: "1px solid #1d4ed8" },
3124
+ note: { margin: "8px 0 0", fontSize: "16px", color: "#525252" }
3125
+ };
3126
+ var DISABLED = { opacity: 0.6, cursor: "not-allowed" };
3127
+ function boardPart(classNames, key, options = {}) {
3128
+ const structure = Object.hasOwn(STRUCTURE, key) ? STRUCTURE[key] : void 0;
3129
+ const injected = classNames?.[key];
3130
+ const stateClasses = [];
3131
+ let stateLook = {};
3132
+ for (const state of options.states ?? []) {
3133
+ const name = classNames?.[state];
3134
+ if (name) stateClasses.push(name);
3135
+ else if (Object.hasOwn(LOOK, state)) stateLook = { ...stateLook, ...LOOK[state] };
3136
+ }
3137
+ const className = [injected, ...stateClasses].filter(Boolean).join(" ");
3138
+ const style = {
3139
+ ...injected ? {} : Object.hasOwn(LOOK, key) ? LOOK[key] : {},
3140
+ ...stateLook,
3141
+ ...structure ?? {},
3142
+ ...options.disabled ? DISABLED : {}
3143
+ };
3144
+ const result = {};
3145
+ if (className) result.className = className;
3146
+ if (Object.keys(style).length > 0) result.style = style;
3147
+ return result;
3148
+ }
3149
+
3150
+ // src/components/add-card-box.tsx
3151
+ import { Fragment as Fragment5, jsx as jsx16, jsxs as jsxs15 } from "react/jsx-runtime";
3152
+ function AddCardBox({ columnName, texts, classNames, currencies = [], defaultCurrency = "", onAdd }) {
3153
+ const initialCurrency = currencies.includes(defaultCurrency) ? defaultCurrency : "";
3154
+ const [open, setOpen] = useState20(false);
3155
+ const [title, setTitle] = useState20("");
3156
+ const [amount, setAmount] = useState20("");
3157
+ const [currency, setCurrency] = useState20(initialCurrency);
3158
+ const [error, setError] = useState20();
3159
+ const [pending, setPending] = useState20(false);
3160
+ const buttonRef = useRef16(null);
3161
+ const titleRef = useRef16(null);
3162
+ const inFlight = useRef16(false);
3163
+ const restore = useRef16(false);
3164
+ const ids = { title: useId4(), amount: useId4(), currency: useId4() };
3165
+ useEffect19(() => {
3166
+ if (open) titleRef.current?.focus();
3167
+ else if (restore.current) {
3168
+ restore.current = false;
3169
+ buttonRef.current?.focus();
3170
+ }
3171
+ }, [open]);
3172
+ const cancel = () => {
3173
+ restore.current = true;
3174
+ setOpen(false);
3175
+ setTitle("");
3176
+ setAmount("");
3177
+ setCurrency(initialCurrency);
3178
+ setError(void 0);
3179
+ };
3180
+ const submit = async (event) => {
3181
+ event.preventDefault();
3182
+ if (inFlight.current) return;
3183
+ if (title.trim() === "") {
3184
+ setError(texts.addTitleRequired);
3185
+ titleRef.current?.focus();
3186
+ return;
3187
+ }
3188
+ inFlight.current = true;
3189
+ setPending(true);
3190
+ setError(void 0);
3191
+ try {
3192
+ const result = await onAdd({ title: title.trim(), amount: amount.trim(), currency });
3193
+ if (result && typeof result.error === "string" && result.error !== "") {
3194
+ setError(result.error);
3195
+ } else {
3196
+ setTitle("");
3197
+ setAmount("");
3198
+ titleRef.current?.focus();
3199
+ }
3200
+ } catch {
3201
+ setError(texts.unexpectedError);
3202
+ } finally {
3203
+ inFlight.current = false;
3204
+ setPending(false);
3205
+ }
3206
+ };
3207
+ const onKeyDown = (event) => {
3208
+ if (event.key !== "Escape") return;
3209
+ event.stopPropagation();
3210
+ cancel();
3211
+ };
3212
+ if (!open) {
3213
+ return /* @__PURE__ */ jsx16("button", { type: "button", ref: buttonRef, onClick: () => setOpen(true), "aria-label": `${texts.addCard} (${columnName})`, ...boardPart(classNames, "addButton"), children: texts.addCard });
3214
+ }
3215
+ return /* @__PURE__ */ jsxs15("form", { onSubmit: submit, onKeyDown, "aria-label": `${texts.addCard} (${columnName})`, ...boardPart(classNames, "addForm"), children: [
3216
+ /* @__PURE__ */ jsx16("label", { htmlFor: ids.title, ...boardPart(classNames, "note"), children: texts.addTitleLabel }),
3217
+ /* @__PURE__ */ jsx16("input", { id: ids.title, ref: titleRef, type: "text", value: title, disabled: pending, onChange: (e) => setTitle(e.target.value), autoComplete: "off", ...boardPart(classNames, "input") }),
3218
+ /* @__PURE__ */ jsx16("label", { htmlFor: ids.amount, ...boardPart(classNames, "note"), children: texts.addAmountLabel }),
3219
+ /* @__PURE__ */ jsx16("input", { id: ids.amount, type: "text", inputMode: "decimal", value: amount, disabled: pending, onChange: (e) => setAmount(e.target.value), autoComplete: "off", ...boardPart(classNames, "input") }),
3220
+ currencies.length > 0 ? /* @__PURE__ */ jsxs15(Fragment5, { children: [
3221
+ /* @__PURE__ */ jsx16("label", { htmlFor: ids.currency, ...boardPart(classNames, "note"), children: texts.addCurrencyLabel }),
3222
+ /* @__PURE__ */ jsxs15("select", { id: ids.currency, value: currency, disabled: pending, onChange: (e) => setCurrency(e.target.value), ...boardPart(classNames, "select"), children: [
3223
+ /* @__PURE__ */ jsx16("option", { value: "", children: " " }),
3224
+ currencies.map((code) => /* @__PURE__ */ jsx16("option", { value: code, children: code }, code))
3225
+ ] })
3226
+ ] }) : null,
3227
+ error ? /* @__PURE__ */ jsx16("p", { ...boardPart(classNames, "error"), role: "alert", children: error }) : null,
3228
+ /* @__PURE__ */ jsxs15("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: [
3229
+ /* @__PURE__ */ jsx16("button", { type: "submit", disabled: pending, ...boardPart(classNames, "primaryButton", { disabled: pending }), children: pending ? texts.addPending : texts.addSubmit }),
3230
+ /* @__PURE__ */ jsx16("button", { type: "button", onClick: cancel, disabled: pending, ...boardPart(classNames, "secondaryButton", { disabled: pending }), children: texts.addCancel })
3231
+ ] })
3232
+ ] });
3233
+ }
3234
+
3235
+ // src/components/board-column.tsx
3236
+ import { jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
3237
+ function BoardColumn({ column, texts, classNames, renderCard, onAddCard, currencies, defaultCurrency, onShowMore, dnd }) {
3238
+ const headingId = useId5();
3239
+ const body = (shell, over) => /* @__PURE__ */ jsxs16("section", { "aria-labelledby": headingId, "data-column-id": column.id, "data-kind": column.kind, ...shell, ...boardPart(classNames, "column", { states: over ? ["columnDropOver"] : [] }), children: [
3240
+ /* @__PURE__ */ jsxs16("div", { ...boardPart(classNames, "columnHeader"), children: [
3241
+ /* @__PURE__ */ jsx17("h3", { id: headingId, ...boardPart(classNames, "columnName"), children: column.name }),
3242
+ /* @__PURE__ */ jsx17("span", { ...boardPart(classNames, "columnCount"), children: texts.columnCount(column.count) }),
3243
+ column.totals.length > 0 ? /* @__PURE__ */ jsx17("p", { ...boardPart(classNames, "columnTotals"), children: column.totals.join(" \xB7 ") }) : null
3244
+ ] }),
3245
+ column.cards.length === 0 ? /* @__PURE__ */ jsx17("p", { ...boardPart(classNames, "empty"), children: texts.emptyColumn }) : /* @__PURE__ */ jsx17("ul", { ...boardPart(classNames, "cardList"), children: column.cards.map((card) => renderCard(card)) }),
3246
+ column.hasMore && onShowMore ? /* @__PURE__ */ jsx17("button", { type: "button", onClick: () => onShowMore(column.id), ...boardPart(classNames, "showMore"), children: texts.showMore }) : null,
3247
+ column.kind === "open" && onAddCard ? /* @__PURE__ */ jsx17(AddCardBox, { columnName: column.name, texts, classNames, currencies, defaultCurrency, onAdd: (input) => onAddCard(column.id, input) }) : null
3248
+ ] });
3249
+ if (!dnd) return body({}, false);
3250
+ const Shell = dnd.Column;
3251
+ return /* @__PURE__ */ jsx17(Shell, { column, children: (shellProps, over) => body(shellProps, over) });
3252
+ }
3253
+
3254
+ // src/components/deal-card.tsx
3255
+ import { Fragment as Fragment6, jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
3256
+ function DealCard({ card, texts, classNames, pending = false, dragging = false, error, renderTitle, controls, shellProps }) {
3257
+ const tags = (card.tags ?? []).slice(0, 2);
3258
+ const states = [...pending ? ["cardPending"] : [], ...dragging ? ["cardDragging"] : []];
3259
+ const title = /* @__PURE__ */ jsx18("span", { children: card.title });
3260
+ const badge = card.badge === "won" ? texts.won : card.badge === "lost" ? texts.lost : null;
3261
+ return /* @__PURE__ */ jsxs17("li", { tabIndex: -1, ...shellProps, ...boardPart(classNames, "card", { states }), "aria-busy": pending || void 0, "data-card-id": card.id, "data-pending": pending || void 0, children: [
3262
+ /* @__PURE__ */ jsx18("p", { ...boardPart(classNames, "cardTitle"), children: renderTitle ? renderTitle(card, title) : title }),
3263
+ card.amountLine ? /* @__PURE__ */ jsx18("p", { ...boardPart(classNames, "cardMeta"), children: card.amountLine }) : null,
3264
+ card.closeDateLine ? /* @__PURE__ */ jsxs17("p", { ...boardPart(classNames, "cardMeta"), children: [
3265
+ card.closeDateLine,
3266
+ card.overdue ? /* @__PURE__ */ jsxs17(Fragment6, { children: [
3267
+ " ",
3268
+ /* @__PURE__ */ jsx18("strong", { ...boardPart(classNames, "overdue"), children: texts.overdue })
3269
+ ] }) : null
3270
+ ] }) : null,
3271
+ card.ownerInitials || tags.length > 0 || badge ? /* @__PURE__ */ jsxs17("p", { ...boardPart(classNames, "cardMeta"), style: { ...boardPart(classNames, "cardMeta").style, display: "flex", flexWrap: "wrap", alignItems: "center", gap: "6px" }, children: [
3272
+ card.ownerInitials ? /* @__PURE__ */ jsx18("span", { ...boardPart(classNames, "ownerMark"), "aria-label": `${texts.owner} ${card.ownerInitials}`, role: "img", children: card.ownerInitials }) : null,
3273
+ tags.map((tag) => /* @__PURE__ */ jsx18("span", { ...boardPart(classNames, "tagChip"), children: tag.label }, tag.id)),
3274
+ badge ? /* @__PURE__ */ jsx18("span", { ...boardPart(classNames, card.badge === "won" ? "badgeWon" : "badgeLost"), children: badge }) : null
3275
+ ] }) : null,
3276
+ pending ? /* @__PURE__ */ jsx18("p", { ...boardPart(classNames, "note"), role: "status", children: texts.moving }) : controls,
3277
+ error ? /* @__PURE__ */ jsx18("p", { ...boardPart(classNames, "cardError"), role: "alert", children: error }) : null
3278
+ ] });
3279
+ }
3280
+
3281
+ // src/components/lost-step.tsx
3282
+ import { useEffect as useEffect20, useId as useId6, useRef as useRef17, useState as useState21 } from "react";
3283
+ import { jsx as jsx19, jsxs as jsxs18 } from "react/jsx-runtime";
3284
+ function LostStep({ suggestions, used, validateReason, humanize, texts, classNames, error, busy = false, onConfirm, onCancel }) {
3285
+ const [picked, setPicked] = useState21(null);
3286
+ const [own, setOwn] = useState21("");
3287
+ const [missing, setMissing] = useState21(false);
3288
+ const firstRef = useRef17(null);
3289
+ const ownRef = useRef17(null);
3290
+ const sent = useRef17(false);
3291
+ const titleId = useId6();
3292
+ const ownId = useId6();
3293
+ useEffect20(() => {
3294
+ if (firstRef.current) firstRef.current.focus();
3295
+ else ownRef.current?.focus();
3296
+ }, []);
3297
+ const known = new Set(suggestions.map((s) => s.code));
3298
+ const usedOnly = used.filter((u) => !known.has(u.code));
3299
+ const code = own.trim() !== "" ? validateReason(own) : picked;
3300
+ const confirm = () => {
3301
+ if (busy || sent.current) return;
3302
+ if (code === null || code === "") {
3303
+ setMissing(true);
3304
+ return;
3305
+ }
3306
+ sent.current = true;
3307
+ onConfirm(code);
3308
+ queueMicrotask(() => {
3309
+ sent.current = false;
3310
+ });
3311
+ };
3312
+ const onKeyDown = (event) => {
3313
+ if (event.key !== "Escape") return;
3314
+ event.stopPropagation();
3315
+ onCancel();
3316
+ };
3317
+ const choice = (item, index) => {
3318
+ const active = own.trim() === "" && picked === item.code;
3319
+ return /* @__PURE__ */ jsx19(
3320
+ "button",
3321
+ {
3322
+ type: "button",
3323
+ ref: index === 0 ? firstRef : void 0,
3324
+ "aria-pressed": active,
3325
+ disabled: busy,
3326
+ onClick: () => {
3327
+ setPicked(item.code);
3328
+ setOwn("");
3329
+ setMissing(false);
3330
+ },
3331
+ ...boardPart(classNames, "choice", { states: active ? ["choiceActive"] : [], disabled: busy }),
3332
+ children: item.label ?? humanize(item.code)
3333
+ },
3334
+ item.code
3335
+ );
3336
+ };
3337
+ return (
3338
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
3339
+ /* @__PURE__ */ jsxs18("div", { role: "group", "aria-labelledby": titleId, onKeyDown, ...boardPart(classNames, "panel"), children: [
3340
+ /* @__PURE__ */ jsx19("p", { id: titleId, ...boardPart(classNames, "panelTitle"), children: texts.lostTitle }),
3341
+ suggestions.length > 0 ? /* @__PURE__ */ jsx19("div", { role: "group", "aria-label": texts.lostSuggested, style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: suggestions.map((s, i) => choice(s, i)) }) : null,
3342
+ usedOnly.length > 0 ? /* @__PURE__ */ jsx19("div", { role: "group", "aria-label": texts.lostUsed, style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: usedOnly.map((u, i) => choice(u, suggestions.length + i)) }) : null,
3343
+ /* @__PURE__ */ jsx19("label", { htmlFor: ownId, ...boardPart(classNames, "note"), children: texts.lostOwnLabel }),
3344
+ /* @__PURE__ */ jsx19(
3345
+ "input",
3346
+ {
3347
+ id: ownId,
3348
+ ref: ownRef,
3349
+ type: "text",
3350
+ value: own,
3351
+ disabled: busy,
3352
+ onChange: (e) => {
3353
+ setOwn(e.target.value);
3354
+ setMissing(false);
3355
+ },
3356
+ onKeyDown: (e) => {
3357
+ if (e.key === "Enter") {
3358
+ e.preventDefault();
3359
+ confirm();
3360
+ }
3361
+ },
3362
+ ...boardPart(classNames, "input")
3363
+ }
3364
+ ),
3365
+ missing || error ? /* @__PURE__ */ jsx19("p", { ...boardPart(classNames, "error"), role: "alert", children: error ?? texts.lostRequired }) : null,
3366
+ /* @__PURE__ */ jsxs18("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: [
3367
+ /* @__PURE__ */ jsx19("button", { type: "button", onClick: confirm, disabled: busy, ...boardPart(classNames, "primaryButton", { disabled: busy }), children: busy ? texts.movePending : texts.lostConfirm }),
3368
+ /* @__PURE__ */ jsx19("button", { type: "button", onClick: onCancel, disabled: busy, ...boardPart(classNames, "secondaryButton", { disabled: busy }), children: texts.lostCancel })
3369
+ ] })
3370
+ ] })
3371
+ );
3372
+ }
3373
+
3374
+ // src/components/move-menu.tsx
3375
+ import { useId as useId7, useState as useState22 } from "react";
3376
+ import { jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
3377
+ function MoveMenu({ cardTitle, targets, texts, classNames, busy = false, onChoose }) {
3378
+ const [value, setValue] = useState22("");
3379
+ const id = useId7();
3380
+ if (targets.length === 0) return null;
3381
+ const chosen = targets.some((t) => t.stageId === value) ? value : "";
3382
+ return /* @__PURE__ */ jsxs19("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px", marginTop: "8px" }, children: [
3383
+ /* @__PURE__ */ jsx20("label", { htmlFor: id, style: { position: "absolute", width: "1px", height: "1px", overflow: "hidden", clip: "rect(0 0 0 0)" }, children: `${texts.moveLabel} ${cardTitle}` }),
3384
+ /* @__PURE__ */ jsxs19("select", { id, value: chosen, onChange: (e) => setValue(e.target.value), disabled: busy, ...boardPart(classNames, "select", { disabled: busy }), children: [
3385
+ /* @__PURE__ */ jsx20("option", { value: "", children: texts.moveChoose }),
3386
+ targets.map((t) => /* @__PURE__ */ jsx20("option", { value: t.stageId, children: t.label }, t.stageId))
3387
+ ] }),
3388
+ /* @__PURE__ */ jsx20(
3389
+ "button",
3390
+ {
3391
+ type: "button",
3392
+ disabled: busy || chosen === "",
3393
+ onClick: () => {
3394
+ if (chosen === "") return;
3395
+ onChoose(chosen);
3396
+ setValue("");
3397
+ },
3398
+ ...boardPart(classNames, "secondaryButton", { disabled: busy || chosen === "" }),
3399
+ children: busy ? texts.movePending : texts.moveSubmit
3400
+ }
3401
+ )
3402
+ ] });
3403
+ }
3404
+
3405
+ // src/components/reopen-step.tsx
3406
+ import { useEffect as useEffect21, useId as useId8, useRef as useRef18, useState as useState23 } from "react";
3407
+ import { Fragment as Fragment7, jsx as jsx21, jsxs as jsxs20 } from "react/jsx-runtime";
3408
+ function ReopenStep({ needsStage, stages, texts, classNames, error, busy = false, onConfirm, onCancel }) {
3409
+ const [stage, setStage] = useState23("");
3410
+ const confirmRef = useRef18(null);
3411
+ const selectRef = useRef18(null);
3412
+ const titleId = useId8();
3413
+ const selectId = useId8();
3414
+ const chosen = stages.some((s) => s.stageId === stage) ? stage : "";
3415
+ useEffect21(() => {
3416
+ if (needsStage) selectRef.current?.focus();
3417
+ else confirmRef.current?.focus();
3418
+ }, [needsStage]);
3419
+ const blocked = busy || needsStage && chosen === "";
3420
+ const onKeyDown = (event) => {
3421
+ if (event.key !== "Escape") return;
3422
+ event.stopPropagation();
3423
+ onCancel();
3424
+ };
3425
+ return (
3426
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
3427
+ /* @__PURE__ */ jsxs20("div", { role: "group", "aria-labelledby": titleId, onKeyDown, ...boardPart(classNames, "panel"), children: [
3428
+ /* @__PURE__ */ jsx21("p", { id: titleId, ...boardPart(classNames, "panelTitle"), children: texts.reopenTitle }),
3429
+ needsStage ? /* @__PURE__ */ jsxs20(Fragment7, { children: [
3430
+ /* @__PURE__ */ jsx21("label", { htmlFor: selectId, ...boardPart(classNames, "note"), children: texts.reopenStageLabel }),
3431
+ /* @__PURE__ */ jsxs20("select", { id: selectId, ref: selectRef, value: chosen, disabled: busy, onChange: (e) => setStage(e.target.value), ...boardPart(classNames, "select", { disabled: busy }), children: [
3432
+ /* @__PURE__ */ jsx21("option", { value: "", children: texts.moveChoose }),
3433
+ stages.map((s) => /* @__PURE__ */ jsx21("option", { value: s.stageId, children: s.label }, s.stageId))
3434
+ ] })
3435
+ ] }) : null,
3436
+ error ? /* @__PURE__ */ jsx21("p", { ...boardPart(classNames, "error"), role: "alert", children: error }) : null,
3437
+ /* @__PURE__ */ jsxs20("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: [
3438
+ /* @__PURE__ */ jsx21(
3439
+ "button",
3440
+ {
3441
+ type: "button",
3442
+ ref: confirmRef,
3443
+ disabled: blocked,
3444
+ onClick: () => {
3445
+ if (blocked) return;
3446
+ if (needsStage) onConfirm(chosen);
3447
+ else onConfirm();
3448
+ },
3449
+ ...boardPart(classNames, "primaryButton", { disabled: blocked }),
3450
+ children: busy ? texts.movePending : texts.reopenConfirm
3451
+ }
3452
+ ),
3453
+ /* @__PURE__ */ jsx21("button", { type: "button", onClick: onCancel, disabled: busy, ...boardPart(classNames, "secondaryButton", { disabled: busy }), children: texts.reopenCancel })
3454
+ ] })
3455
+ ] })
3456
+ );
3457
+ }
3458
+
3459
+ // src/components/pipeline-board.tsx
3460
+ import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
3461
+ var errorOf2 = (result) => {
3462
+ if (result && typeof result === "object" && "error" in result) {
3463
+ const e = result.error;
3464
+ if (typeof e === "string" && e !== "") return e;
3465
+ }
3466
+ return void 0;
3467
+ };
3468
+ function PipelineBoard(props) {
3469
+ const { columns, texts, classNames, pendingDealIds = [], cardErrors, onMove, legalTargets, reopenFor, onReopen, lost, onAddCard, currencies, defaultCurrency, onShowMore, renderCardTitle, endSlot, dnd } = props;
3470
+ const [placed, setPlaced] = useState24({});
3471
+ const [errors, setErrors] = useState24({});
3472
+ const [step, setStep] = useState24(null);
3473
+ const [stepError, setStepError] = useState24();
3474
+ const [position, setPosition] = useState24(0);
3475
+ const rowRef = useRef19(null);
3476
+ const running = useRef19(/* @__PURE__ */ new Set());
3477
+ const focusAfter = useRef19(null);
3478
+ useEffect22(() => {
3479
+ const id = focusAfter.current;
3480
+ if (id === null || placed[id]?.running) return;
3481
+ for (const el of Array.from(rowRef.current?.querySelectorAll("[data-card-id]") ?? [])) {
3482
+ if (el.getAttribute("data-card-id") === id) {
3483
+ focusAfter.current = null;
3484
+ el.focus();
3485
+ return;
3486
+ }
3487
+ }
3488
+ });
3489
+ useEffect22(() => {
3490
+ setPlaced((prev) => {
3491
+ const keep = {};
3492
+ for (const [id, value] of Object.entries(prev)) if (value.running) keep[id] = value;
3493
+ return Object.keys(keep).length === Object.keys(prev).length ? prev : keep;
3494
+ });
3495
+ }, [columns]);
3496
+ const view = useMemo2(() => {
3497
+ const moved = Object.entries(placed);
3498
+ if (moved.length === 0) return columns;
3499
+ const byId = /* @__PURE__ */ new Map();
3500
+ for (const column of columns) for (const card of column.cards) byId.set(card.id, card);
3501
+ return columns.map((column) => {
3502
+ const stay = column.cards.filter((card) => !Object.hasOwn(placed, card.id) || placed[card.id]?.toStageId === column.id);
3503
+ const arriving = moved.filter(([, value]) => value.toStageId === column.id).map(([id]) => byId.get(id)).filter((card) => card !== void 0 && !column.cards.some((c) => c.id === card.id));
3504
+ return arriving.length === 0 && stay.length === column.cards.length ? column : { ...column, cards: [...arriving, ...stay] };
3505
+ });
3506
+ }, [columns, placed]);
3507
+ const cardOf = (id) => {
3508
+ for (const column of columns) for (const card of column.cards) if (card.id === id) return card;
3509
+ return void 0;
3510
+ };
3511
+ const send = async (card, toStageId, reason) => {
3512
+ if (!onMove || running.current.has(card.id)) return void 0;
3513
+ running.current.add(card.id);
3514
+ setErrors((prev) => withoutKey(prev, card.id));
3515
+ setPlaced((prev) => ({ ...prev, [card.id]: { toStageId, running: true } }));
3516
+ const request = { dealId: card.id, toStageId, expectedVersion: card.version, ...reason !== void 0 ? { reason } : {} };
3517
+ let message;
3518
+ try {
3519
+ message = errorOf2(await onMove(request));
3520
+ } catch {
3521
+ message = texts.unexpectedError;
3522
+ }
3523
+ running.current.delete(card.id);
3524
+ if (message) {
3525
+ setPlaced((prev) => withoutKey(prev, card.id));
3526
+ setErrors((prev) => ({ ...prev, [card.id]: message }));
3527
+ } else {
3528
+ focusAfter.current = card.id;
3529
+ setPlaced((prev) => ({ ...prev, [card.id]: { toStageId, running: false } }));
3530
+ }
3531
+ return message;
3532
+ };
3533
+ const requestMove = (card, toStageId) => {
3534
+ const target = columns.find((c) => c.id === toStageId);
3535
+ if (!target || card.stageId === toStageId) return;
3536
+ if (target.kind === "lost" && !lost) return;
3537
+ if (target.kind === "lost" && lost) {
3538
+ setStepError(void 0);
3539
+ setStep({ kind: "lost", card, toStageId });
3540
+ return;
3541
+ }
3542
+ void send(card, toStageId);
3543
+ };
3544
+ const pendingIds = new Set(pendingDealIds);
3545
+ const isPending = (id) => pendingIds.has(id) || placed[id]?.running === true;
3546
+ const controlsFor = (card) => {
3547
+ if (step && step.card.id === card.id) {
3548
+ if (step.kind === "lost" && lost) {
3549
+ return /* @__PURE__ */ jsx22(
3550
+ LostStep,
3551
+ {
3552
+ suggestions: lost.suggestions,
3553
+ used: lost.used,
3554
+ validateReason: lost.validateReason,
3555
+ humanize: lost.humanize,
3556
+ texts,
3557
+ classNames,
3558
+ error: stepError,
3559
+ onCancel: () => setStep(null),
3560
+ onConfirm: (reason) => {
3561
+ const target = step.toStageId;
3562
+ setStep(null);
3563
+ void send(card, target, reason);
3564
+ }
3565
+ }
3566
+ );
3567
+ }
3568
+ const options = reopenFor?.(card);
3569
+ if (step.kind === "reopen" && options) {
3570
+ return /* @__PURE__ */ jsx22(
3571
+ ReopenStep,
3572
+ {
3573
+ needsStage: options.needsStage,
3574
+ stages: options.stages,
3575
+ texts,
3576
+ classNames,
3577
+ error: stepError,
3578
+ onCancel: () => setStep(null),
3579
+ onConfirm: async (toStageId) => {
3580
+ if (!onReopen) return;
3581
+ try {
3582
+ const message = errorOf2(await onReopen({ dealId: card.id, expectedVersion: card.version, ...toStageId !== void 0 ? { toStageId } : {} }));
3583
+ if (message) setStepError(message);
3584
+ else setStep(null);
3585
+ } catch {
3586
+ setStepError(texts.unexpectedError);
3587
+ }
3588
+ }
3589
+ }
3590
+ );
3591
+ }
3592
+ }
3593
+ const reopen = card.badge && reopenFor && onReopen ? reopenFor(card) : null;
3594
+ return /* @__PURE__ */ jsxs21(Fragment8, { children: [
3595
+ onMove && legalTargets ? /* @__PURE__ */ jsx22(MoveMenu, { cardTitle: card.title, targets: legalTargets(card).filter((t) => lost || columns.find((c) => c.id === t.stageId)?.kind !== "lost"), texts, classNames, onChoose: (stageId) => requestMove(card, stageId) }) : null,
3596
+ reopen ? /* @__PURE__ */ jsx22(
3597
+ "button",
3598
+ {
3599
+ type: "button",
3600
+ onClick: () => {
3601
+ setStepError(void 0);
3602
+ setStep({ kind: "reopen", card });
3603
+ },
3604
+ ...boardPart(classNames, "secondaryButton"),
3605
+ children: texts.reopen
3606
+ }
3607
+ ) : null
3608
+ ] });
3609
+ };
3610
+ const renderCard = (card) => {
3611
+ const error = errors[card.id] ?? cardErrors?.[card.id];
3612
+ const build = (shellProps, dragging) => /* @__PURE__ */ jsx22(DealCard, { card, texts, classNames, pending: isPending(card.id), dragging, error, renderTitle: renderCardTitle, controls: controlsFor(card), shellProps }, card.id);
3613
+ if (!dnd || isPending(card.id)) return build({}, false);
3614
+ const Shell = dnd.Card;
3615
+ return /* @__PURE__ */ jsx22(Shell, { card, children: (shellProps, dragging) => build(shellProps, dragging) }, card.id);
3616
+ };
3617
+ const onScroll = () => {
3618
+ const row = rowRef.current;
3619
+ if (!row) return;
3620
+ const offsets = Array.from(row.querySelectorAll("[data-column-id]")).map((el) => el.offsetLeft - row.offsetLeft);
3621
+ setPosition(nearestColumnIndex(row.scrollLeft, offsets));
3622
+ };
3623
+ if (columns.length === 0) {
3624
+ return /* @__PURE__ */ jsx22("div", { ...boardPart(classNames, "root"), children: /* @__PURE__ */ jsx22("p", { ...boardPart(classNames, "empty"), children: texts.emptyBoard }) });
3625
+ }
3626
+ const content = /* @__PURE__ */ jsxs21("div", { ...boardPart(classNames, "root"), children: [
3627
+ columns.length > 1 ? /* @__PURE__ */ jsx22("p", { ...boardPart(classNames, "position"), role: "status", "aria-live": "polite", children: texts.stagePosition(Math.min(position, columns.length - 1) + 1, columns.length) }) : null,
3628
+ /* @__PURE__ */ jsxs21("div", { ref: rowRef, role: "region", "aria-label": texts.boardLabel, tabIndex: 0, onScroll, ...boardPart(classNames, "row"), children: [
3629
+ view.map((column) => /* @__PURE__ */ jsx22(
3630
+ BoardColumn,
3631
+ {
3632
+ column,
3633
+ texts,
3634
+ classNames,
3635
+ renderCard,
3636
+ onAddCard,
3637
+ currencies,
3638
+ defaultCurrency,
3639
+ onShowMore,
3640
+ dnd
3641
+ },
3642
+ column.id
3643
+ )),
3644
+ endSlot ? /* @__PURE__ */ jsx22("div", { style: { flex: "0 0 auto", scrollSnapAlign: "end" }, children: endSlot }) : null
3645
+ ] })
3646
+ ] });
3647
+ if (!dnd) return content;
3648
+ const Provider = dnd.Provider;
3649
+ return /* @__PURE__ */ jsx22(Provider, { columns: view, onDrop: (cardId, toStageId) => {
3650
+ const card = cardOf(cardId);
3651
+ if (card) requestMove(card, toStageId);
3652
+ }, config: dnd.config, allow: (cardId, toStageId) => lost !== void 0 || columns.find((c) => c.id === toStageId)?.kind !== "lost", children: content });
3653
+ }
3654
+ function withoutKey(record, key) {
3655
+ if (!Object.hasOwn(record, key)) return record;
3656
+ const next = { ...record };
3657
+ delete next[key];
3658
+ return next;
3659
+ }
3056
3660
  export {
3057
3661
  ACTIVITY_ICONS,
3058
3662
  ALL_SHORTCUT_CONTEXTS,
3059
3663
  ARRIVAL_FADE_MS,
3060
3664
  ActivityFeedRow,
3665
+ AddCardBox,
3061
3666
  ArchiveButton,
3667
+ BoardColumn,
3062
3668
  CLIENT_PROFILE_SHORTCUTS,
3063
3669
  COPY_NOTE_COPIED,
3064
3670
  COPY_NOTE_FAILED,
3065
3671
  ConfirmAction,
3672
+ DealCard,
3066
3673
  EmailBodyRenderer,
3067
3674
  EmailThreadView,
3068
3675
  EntityPicker,
@@ -3072,10 +3679,14 @@ export {
3072
3679
  GUARDED_ACTION_FAILURE,
3073
3680
  INBOX_SHORTCUTS,
3074
3681
  KeyboardShortcutsPanel,
3682
+ LostStep,
3683
+ MoveMenu,
3075
3684
  PICKER_SEARCH_FAILURE,
3076
3685
  Pager,
3686
+ PipelineBoard,
3077
3687
  RENDER_ERRORS,
3078
3688
  REPLY_LAYOUT_OPTIONS,
3689
+ ReopenStep,
3079
3690
  ReplyPanel,
3080
3691
  RestoreButton,
3081
3692
  RichTextEditor,
@@ -3109,6 +3720,7 @@ export {
3109
3720
  isTypingContext,
3110
3721
  isValidScheduleDate,
3111
3722
  isVideo,
3723
+ nearestColumnIndex,
3112
3724
  opensInNewTab,
3113
3725
  parseCustomSchedule,
3114
3726
  prefetch,