@asymmetric-effort/specifyjs 0.3.1 → 0.3.7

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.
@@ -21219,6 +21219,263 @@ function validateNameForNesting(name, targetContainer, excludeId) {
21219
21219
  return validateNameInScope(name, targetContainer, excludeId);
21220
21220
  }
21221
21221
 
21222
+ // ../components/form/buildable-list/src/BuildableList.ts
21223
+ function BuildableList(props) {
21224
+ const {
21225
+ value,
21226
+ onChange,
21227
+ orientation = "vertical",
21228
+ inputPosition = "below",
21229
+ delimiter: delimiterProp,
21230
+ placeholder = "Add item...",
21231
+ disabled = false,
21232
+ label,
21233
+ maxItems
21234
+ } = props;
21235
+ const delimiter = delimiterProp ?? (orientation === "horizontal" ? ", " : "\n");
21236
+ const items = useMemo(() => Array.from(new Set(value)), [value]);
21237
+ const [mode, setMode] = useState({ type: "closed" });
21238
+ const [inputValue, setInputValue] = useState("");
21239
+ const [duplicate, setDuplicate] = useState(false);
21240
+ const inputRef = useRef(null);
21241
+ const openAdd = useCallback(() => {
21242
+ if (disabled) return;
21243
+ if (maxItems !== void 0 && items.length >= maxItems) return;
21244
+ setMode({ type: "add" });
21245
+ setInputValue("");
21246
+ setDuplicate(false);
21247
+ }, [disabled, maxItems, items.length]);
21248
+ const openEdit = useCallback(
21249
+ (index) => {
21250
+ if (disabled) return;
21251
+ setMode({ type: "edit", index, original: items[index] });
21252
+ setInputValue(items[index]);
21253
+ setDuplicate(false);
21254
+ },
21255
+ [disabled, items]
21256
+ );
21257
+ const closeInput = useCallback(() => {
21258
+ setMode({ type: "closed" });
21259
+ setInputValue("");
21260
+ setDuplicate(false);
21261
+ }, []);
21262
+ const handleConfirm = useCallback(() => {
21263
+ const trimmed = inputValue.trim();
21264
+ if (!trimmed) return;
21265
+ if (mode.type === "add") {
21266
+ if (items.includes(trimmed)) {
21267
+ setDuplicate(true);
21268
+ setInputValue("");
21269
+ return;
21270
+ }
21271
+ onChange([...items, trimmed]);
21272
+ setInputValue("");
21273
+ setDuplicate(false);
21274
+ } else if (mode.type === "edit") {
21275
+ if (trimmed === mode.original) {
21276
+ closeInput();
21277
+ return;
21278
+ }
21279
+ if (items.includes(trimmed)) {
21280
+ setDuplicate(true);
21281
+ return;
21282
+ }
21283
+ const next = items.slice();
21284
+ next[mode.index] = trimmed;
21285
+ onChange(next);
21286
+ closeInput();
21287
+ }
21288
+ }, [inputValue, mode, items, onChange, closeInput]);
21289
+ const handleDelete = useCallback(() => {
21290
+ if (mode.type === "edit") {
21291
+ const next = items.filter((_, i) => i !== mode.index);
21292
+ onChange(next);
21293
+ closeInput();
21294
+ }
21295
+ }, [mode, items, onChange, closeInput]);
21296
+ const handleInputKeyDown = useCallback(
21297
+ (e) => {
21298
+ const key = e.key;
21299
+ if (key === "Enter") {
21300
+ e.preventDefault();
21301
+ handleConfirm();
21302
+ } else if (key === "Escape") {
21303
+ e.preventDefault();
21304
+ closeInput();
21305
+ }
21306
+ },
21307
+ [handleConfirm, closeInput]
21308
+ );
21309
+ const handleContainerKeyDown = useCallback(
21310
+ (e) => {
21311
+ if (disabled) return;
21312
+ const key = e.key;
21313
+ if (key === "+" && mode.type === "closed") {
21314
+ e.preventDefault();
21315
+ openAdd();
21316
+ }
21317
+ },
21318
+ [disabled, mode, openAdd]
21319
+ );
21320
+ const containerStyle3 = {
21321
+ display: "flex",
21322
+ flexDirection: "column",
21323
+ gap: "4px"
21324
+ };
21325
+ const listContainerStyle = {
21326
+ display: "flex",
21327
+ flexDirection: orientation === "vertical" ? "column" : "row",
21328
+ flexWrap: orientation === "horizontal" ? "wrap" : "nowrap",
21329
+ gap: orientation === "vertical" ? "2px" : "0",
21330
+ alignItems: orientation === "horizontal" ? "center" : "stretch"
21331
+ };
21332
+ const itemStyle = {
21333
+ padding: "4px 8px",
21334
+ cursor: disabled ? "default" : "pointer",
21335
+ borderRadius: "4px",
21336
+ fontSize: "14px",
21337
+ color: "#1f2937",
21338
+ backgroundColor: "transparent",
21339
+ transition: "background-color 0.1s",
21340
+ border: "1px solid transparent",
21341
+ userSelect: "none"
21342
+ };
21343
+ const buttonBase = {
21344
+ display: "inline-flex",
21345
+ alignItems: "center",
21346
+ justifyContent: "center",
21347
+ border: "1px solid #d1d5db",
21348
+ borderRadius: "6px",
21349
+ backgroundColor: "#ffffff",
21350
+ cursor: disabled ? "not-allowed" : "pointer",
21351
+ fontSize: "16px",
21352
+ fontWeight: "700",
21353
+ lineHeight: "1",
21354
+ padding: "4px 10px",
21355
+ color: "#374151",
21356
+ transition: "background-color 0.15s, border-color 0.15s"
21357
+ };
21358
+ const inputRowStyle = {
21359
+ display: "flex",
21360
+ alignItems: "center",
21361
+ gap: "4px"
21362
+ };
21363
+ const inputStyle = buildInputStyle({}, { focused: false, error: duplicate });
21364
+ const listItems = [];
21365
+ for (let i = 0; i < items.length; i++) {
21366
+ const item = items[i];
21367
+ if (orientation === "horizontal" && i > 0) {
21368
+ listItems.push(
21369
+ createElement("span", {
21370
+ key: `delim-${i}`,
21371
+ style: { color: "#9ca3af", fontSize: "14px", userSelect: "none" },
21372
+ "aria-hidden": "true"
21373
+ }, delimiter)
21374
+ );
21375
+ }
21376
+ listItems.push(
21377
+ createElement("span", {
21378
+ key: `item-${i}`,
21379
+ role: "listitem",
21380
+ tabIndex: disabled ? -1 : 0,
21381
+ style: itemStyle,
21382
+ onClick: disabled ? void 0 : () => openEdit(i),
21383
+ onKeyDown: disabled ? void 0 : (e) => {
21384
+ if (e.key === "Enter") openEdit(i);
21385
+ }
21386
+ }, item)
21387
+ );
21388
+ }
21389
+ const listEl = createElement(
21390
+ "div",
21391
+ { role: "list", style: listContainerStyle },
21392
+ ...listItems
21393
+ );
21394
+ const addBtnDisabled = disabled || maxItems !== void 0 && items.length >= maxItems;
21395
+ const addButton = createElement("button", {
21396
+ type: "button",
21397
+ "aria-label": "Add item",
21398
+ style: {
21399
+ ...buttonBase,
21400
+ opacity: addBtnDisabled ? "0.5" : "1",
21401
+ cursor: addBtnDisabled ? "not-allowed" : "pointer"
21402
+ },
21403
+ disabled: addBtnDisabled,
21404
+ onClick: addBtnDisabled ? void 0 : openAdd
21405
+ }, "+");
21406
+ let inputRow = null;
21407
+ if (mode.type !== "closed") {
21408
+ const okBtn = createElement("button", {
21409
+ type: "button",
21410
+ "aria-label": "Confirm",
21411
+ style: { ...buttonBase, fontSize: "13px", padding: "4px 8px" },
21412
+ onClick: handleConfirm
21413
+ }, "OK");
21414
+ const deleteBtn = mode.type === "edit" ? createElement("button", {
21415
+ type: "button",
21416
+ "aria-label": "Delete",
21417
+ style: { ...buttonBase, fontSize: "13px", padding: "4px 8px", color: "#ef4444" },
21418
+ onClick: handleDelete
21419
+ }, "X") : null;
21420
+ inputRow = createElement(
21421
+ "div",
21422
+ { style: inputRowStyle, className: "buildable-list__input-row" },
21423
+ createElement("input", {
21424
+ ref: inputRef,
21425
+ type: "text",
21426
+ value: inputValue,
21427
+ placeholder,
21428
+ "aria-label": mode.type === "edit" ? "Edit item" : "New item",
21429
+ style: { ...inputStyle, flex: "1", minWidth: "0" },
21430
+ autoFocus: true,
21431
+ onInput: (e) => {
21432
+ setInputValue(e.target.value);
21433
+ setDuplicate(false);
21434
+ },
21435
+ onKeyDown: handleInputKeyDown
21436
+ }),
21437
+ okBtn,
21438
+ deleteBtn
21439
+ );
21440
+ }
21441
+ const bodyParts = [];
21442
+ if (mode.type !== "closed" && inputPosition === "above") {
21443
+ bodyParts.push(inputRow);
21444
+ }
21445
+ bodyParts.push(
21446
+ createElement(
21447
+ "div",
21448
+ {
21449
+ style: {
21450
+ display: "flex",
21451
+ alignItems: "flex-start",
21452
+ gap: "8px"
21453
+ }
21454
+ },
21455
+ listEl,
21456
+ addButton
21457
+ )
21458
+ );
21459
+ if (mode.type !== "closed" && inputPosition === "below") {
21460
+ bodyParts.push(inputRow);
21461
+ }
21462
+ const body = createElement(
21463
+ "div",
21464
+ {
21465
+ style: containerStyle3,
21466
+ tabIndex: 0,
21467
+ onKeyDown: handleContainerKeyDown,
21468
+ className: "buildable-list"
21469
+ },
21470
+ ...bodyParts
21471
+ );
21472
+ return createElement(
21473
+ FormFieldWrapper,
21474
+ { label, disabled },
21475
+ body
21476
+ );
21477
+ }
21478
+
21222
21479
  // ../components/form/button/src/Button.ts
21223
21480
  var SIZE_MAP6 = {
21224
21481
  sm: { padding: "3px 10px", fontSize: "12px", borderRadius: "4px" },
@@ -30351,6 +30608,7 @@ export {
30351
30608
  BoxPlot,
30352
30609
  Breadcrumb,
30353
30610
  BubbleChart,
30611
+ BuildableList,
30354
30612
  Button,
30355
30613
  CARD_TYPE_OPTIONS,
30356
30614
  COL_COMMENT,