@asymmetric-effort/specifyjs 0.3.1 → 0.3.8
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/esm/components-barrel.js +343 -2
- package/dist/specifyjs-components.cjs.js +4 -3
- package/dist/specifyjs-components.esm.js +343 -2
- package/dist/types/components/form/buildable-list/src/BuildableList.d.ts +21 -0
- package/dist/types/components/form/buildable-list/src/index.d.ts +2 -0
- package/dist/types/components/form/select/src/Select.d.ts +7 -0
- package/dist/types/core/src/components-barrel.d.ts +1 -0
- package/package.json +1 -1
|
@@ -3089,11 +3089,16 @@ function Select(props) {
|
|
|
3089
3089
|
disabled = false,
|
|
3090
3090
|
error,
|
|
3091
3091
|
label,
|
|
3092
|
-
helpText
|
|
3092
|
+
helpText,
|
|
3093
|
+
creatable = false,
|
|
3094
|
+
onCreate,
|
|
3095
|
+
createLabel = "+ Create new..."
|
|
3093
3096
|
} = props;
|
|
3094
3097
|
const [isOpen, setIsOpen] = useState(false);
|
|
3095
3098
|
const [searchQuery, setSearchQuery] = useState("");
|
|
3096
3099
|
const [focusedIndex, setFocusedIndex] = useState(-1);
|
|
3100
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
3101
|
+
const [createValue, setCreateValue] = useState("");
|
|
3097
3102
|
const containerRef = useRef(null);
|
|
3098
3103
|
const selectedValues = useMemo(
|
|
3099
3104
|
() => Array.isArray(value) ? value : value ? [value] : [],
|
|
@@ -3128,6 +3133,8 @@ function Select(props) {
|
|
|
3128
3133
|
if (containerRef.current && !containerRef.current.contains(target)) {
|
|
3129
3134
|
setIsOpen(false);
|
|
3130
3135
|
setSearchQuery("");
|
|
3136
|
+
setIsCreating(false);
|
|
3137
|
+
setCreateValue("");
|
|
3131
3138
|
}
|
|
3132
3139
|
};
|
|
3133
3140
|
document.addEventListener("mousedown", handleClick);
|
|
@@ -3263,7 +3270,7 @@ function Select(props) {
|
|
|
3263
3270
|
elements.push(renderOption(opt, flatIdx++));
|
|
3264
3271
|
}
|
|
3265
3272
|
}
|
|
3266
|
-
if (elements.length === 0) {
|
|
3273
|
+
if (elements.length === 0 && !creatable) {
|
|
3267
3274
|
elements.push(
|
|
3268
3275
|
createElement(
|
|
3269
3276
|
"div",
|
|
@@ -3272,6 +3279,82 @@ function Select(props) {
|
|
|
3272
3279
|
)
|
|
3273
3280
|
);
|
|
3274
3281
|
}
|
|
3282
|
+
if (creatable) {
|
|
3283
|
+
if (isCreating) {
|
|
3284
|
+
elements.push(
|
|
3285
|
+
createElement(
|
|
3286
|
+
"div",
|
|
3287
|
+
{
|
|
3288
|
+
key: "__create-input__",
|
|
3289
|
+
style: {
|
|
3290
|
+
padding: "4px 8px",
|
|
3291
|
+
borderTop: elements.length > 0 ? "1px solid #e5e7eb" : "none"
|
|
3292
|
+
}
|
|
3293
|
+
},
|
|
3294
|
+
createElement("input", {
|
|
3295
|
+
type: "text",
|
|
3296
|
+
value: createValue,
|
|
3297
|
+
placeholder: "Type new value...",
|
|
3298
|
+
autoFocus: true,
|
|
3299
|
+
onInput: (e) => {
|
|
3300
|
+
setCreateValue(e.target.value);
|
|
3301
|
+
},
|
|
3302
|
+
onKeyDown: (e) => {
|
|
3303
|
+
const key = e.key;
|
|
3304
|
+
if (key === "Enter") {
|
|
3305
|
+
e.preventDefault();
|
|
3306
|
+
const trimmed = createValue.trim();
|
|
3307
|
+
if (trimmed) {
|
|
3308
|
+
if (onCreate) onCreate(trimmed);
|
|
3309
|
+
if (!multiple) {
|
|
3310
|
+
onChange(trimmed);
|
|
3311
|
+
setIsOpen(false);
|
|
3312
|
+
}
|
|
3313
|
+
setCreateValue("");
|
|
3314
|
+
setIsCreating(false);
|
|
3315
|
+
}
|
|
3316
|
+
} else if (key === "Escape") {
|
|
3317
|
+
setCreateValue("");
|
|
3318
|
+
setIsCreating(false);
|
|
3319
|
+
}
|
|
3320
|
+
},
|
|
3321
|
+
style: {
|
|
3322
|
+
width: "100%",
|
|
3323
|
+
boxSizing: "border-box",
|
|
3324
|
+
padding: "6px 8px",
|
|
3325
|
+
border: "1px solid #d1d5db",
|
|
3326
|
+
borderRadius: "4px",
|
|
3327
|
+
outline: "none",
|
|
3328
|
+
fontSize: "14px"
|
|
3329
|
+
}
|
|
3330
|
+
})
|
|
3331
|
+
)
|
|
3332
|
+
);
|
|
3333
|
+
} else {
|
|
3334
|
+
elements.push(
|
|
3335
|
+
createElement(
|
|
3336
|
+
"div",
|
|
3337
|
+
{
|
|
3338
|
+
key: "__create-new__",
|
|
3339
|
+
style: {
|
|
3340
|
+
padding: "8px 12px",
|
|
3341
|
+
cursor: "pointer",
|
|
3342
|
+
color: "#3b82f6",
|
|
3343
|
+
fontSize: "14px",
|
|
3344
|
+
borderTop: elements.length > 0 ? "1px solid #e5e7eb" : "none"
|
|
3345
|
+
},
|
|
3346
|
+
onClick: () => {
|
|
3347
|
+
setIsCreating(true);
|
|
3348
|
+
setCreateValue("");
|
|
3349
|
+
},
|
|
3350
|
+
role: "option",
|
|
3351
|
+
"aria-label": "Create new option"
|
|
3352
|
+
},
|
|
3353
|
+
createLabel
|
|
3354
|
+
)
|
|
3355
|
+
);
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3275
3358
|
return elements;
|
|
3276
3359
|
};
|
|
3277
3360
|
const chevron = createElement(
|
|
@@ -21219,6 +21302,263 @@ function validateNameForNesting(name, targetContainer, excludeId) {
|
|
|
21219
21302
|
return validateNameInScope(name, targetContainer, excludeId);
|
|
21220
21303
|
}
|
|
21221
21304
|
|
|
21305
|
+
// ../components/form/buildable-list/src/BuildableList.ts
|
|
21306
|
+
function BuildableList(props) {
|
|
21307
|
+
const {
|
|
21308
|
+
value,
|
|
21309
|
+
onChange,
|
|
21310
|
+
orientation = "vertical",
|
|
21311
|
+
inputPosition = "below",
|
|
21312
|
+
delimiter: delimiterProp,
|
|
21313
|
+
placeholder = "Add item...",
|
|
21314
|
+
disabled = false,
|
|
21315
|
+
label,
|
|
21316
|
+
maxItems
|
|
21317
|
+
} = props;
|
|
21318
|
+
const delimiter = delimiterProp ?? (orientation === "horizontal" ? ", " : "\n");
|
|
21319
|
+
const items = useMemo(() => Array.from(new Set(value)), [value]);
|
|
21320
|
+
const [mode, setMode] = useState({ type: "closed" });
|
|
21321
|
+
const [inputValue, setInputValue] = useState("");
|
|
21322
|
+
const [duplicate, setDuplicate] = useState(false);
|
|
21323
|
+
const inputRef = useRef(null);
|
|
21324
|
+
const openAdd = useCallback(() => {
|
|
21325
|
+
if (disabled) return;
|
|
21326
|
+
if (maxItems !== void 0 && items.length >= maxItems) return;
|
|
21327
|
+
setMode({ type: "add" });
|
|
21328
|
+
setInputValue("");
|
|
21329
|
+
setDuplicate(false);
|
|
21330
|
+
}, [disabled, maxItems, items.length]);
|
|
21331
|
+
const openEdit = useCallback(
|
|
21332
|
+
(index) => {
|
|
21333
|
+
if (disabled) return;
|
|
21334
|
+
setMode({ type: "edit", index, original: items[index] });
|
|
21335
|
+
setInputValue(items[index]);
|
|
21336
|
+
setDuplicate(false);
|
|
21337
|
+
},
|
|
21338
|
+
[disabled, items]
|
|
21339
|
+
);
|
|
21340
|
+
const closeInput = useCallback(() => {
|
|
21341
|
+
setMode({ type: "closed" });
|
|
21342
|
+
setInputValue("");
|
|
21343
|
+
setDuplicate(false);
|
|
21344
|
+
}, []);
|
|
21345
|
+
const handleConfirm = useCallback(() => {
|
|
21346
|
+
const trimmed = inputValue.trim();
|
|
21347
|
+
if (!trimmed) return;
|
|
21348
|
+
if (mode.type === "add") {
|
|
21349
|
+
if (items.includes(trimmed)) {
|
|
21350
|
+
setDuplicate(true);
|
|
21351
|
+
setInputValue("");
|
|
21352
|
+
return;
|
|
21353
|
+
}
|
|
21354
|
+
onChange([...items, trimmed]);
|
|
21355
|
+
setInputValue("");
|
|
21356
|
+
setDuplicate(false);
|
|
21357
|
+
} else if (mode.type === "edit") {
|
|
21358
|
+
if (trimmed === mode.original) {
|
|
21359
|
+
closeInput();
|
|
21360
|
+
return;
|
|
21361
|
+
}
|
|
21362
|
+
if (items.includes(trimmed)) {
|
|
21363
|
+
setDuplicate(true);
|
|
21364
|
+
return;
|
|
21365
|
+
}
|
|
21366
|
+
const next = items.slice();
|
|
21367
|
+
next[mode.index] = trimmed;
|
|
21368
|
+
onChange(next);
|
|
21369
|
+
closeInput();
|
|
21370
|
+
}
|
|
21371
|
+
}, [inputValue, mode, items, onChange, closeInput]);
|
|
21372
|
+
const handleDelete = useCallback(() => {
|
|
21373
|
+
if (mode.type === "edit") {
|
|
21374
|
+
const next = items.filter((_, i) => i !== mode.index);
|
|
21375
|
+
onChange(next);
|
|
21376
|
+
closeInput();
|
|
21377
|
+
}
|
|
21378
|
+
}, [mode, items, onChange, closeInput]);
|
|
21379
|
+
const handleInputKeyDown = useCallback(
|
|
21380
|
+
(e) => {
|
|
21381
|
+
const key = e.key;
|
|
21382
|
+
if (key === "Enter") {
|
|
21383
|
+
e.preventDefault();
|
|
21384
|
+
handleConfirm();
|
|
21385
|
+
} else if (key === "Escape") {
|
|
21386
|
+
e.preventDefault();
|
|
21387
|
+
closeInput();
|
|
21388
|
+
}
|
|
21389
|
+
},
|
|
21390
|
+
[handleConfirm, closeInput]
|
|
21391
|
+
);
|
|
21392
|
+
const handleContainerKeyDown = useCallback(
|
|
21393
|
+
(e) => {
|
|
21394
|
+
if (disabled) return;
|
|
21395
|
+
const key = e.key;
|
|
21396
|
+
if (key === "+" && mode.type === "closed") {
|
|
21397
|
+
e.preventDefault();
|
|
21398
|
+
openAdd();
|
|
21399
|
+
}
|
|
21400
|
+
},
|
|
21401
|
+
[disabled, mode, openAdd]
|
|
21402
|
+
);
|
|
21403
|
+
const containerStyle3 = {
|
|
21404
|
+
display: "flex",
|
|
21405
|
+
flexDirection: "column",
|
|
21406
|
+
gap: "4px"
|
|
21407
|
+
};
|
|
21408
|
+
const listContainerStyle = {
|
|
21409
|
+
display: "flex",
|
|
21410
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
|
21411
|
+
flexWrap: orientation === "horizontal" ? "wrap" : "nowrap",
|
|
21412
|
+
gap: orientation === "vertical" ? "2px" : "0",
|
|
21413
|
+
alignItems: orientation === "horizontal" ? "center" : "stretch"
|
|
21414
|
+
};
|
|
21415
|
+
const itemStyle = {
|
|
21416
|
+
padding: "4px 8px",
|
|
21417
|
+
cursor: disabled ? "default" : "pointer",
|
|
21418
|
+
borderRadius: "4px",
|
|
21419
|
+
fontSize: "14px",
|
|
21420
|
+
color: "#1f2937",
|
|
21421
|
+
backgroundColor: "transparent",
|
|
21422
|
+
transition: "background-color 0.1s",
|
|
21423
|
+
border: "1px solid transparent",
|
|
21424
|
+
userSelect: "none"
|
|
21425
|
+
};
|
|
21426
|
+
const buttonBase = {
|
|
21427
|
+
display: "inline-flex",
|
|
21428
|
+
alignItems: "center",
|
|
21429
|
+
justifyContent: "center",
|
|
21430
|
+
border: "1px solid #d1d5db",
|
|
21431
|
+
borderRadius: "6px",
|
|
21432
|
+
backgroundColor: "#ffffff",
|
|
21433
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
21434
|
+
fontSize: "16px",
|
|
21435
|
+
fontWeight: "700",
|
|
21436
|
+
lineHeight: "1",
|
|
21437
|
+
padding: "4px 10px",
|
|
21438
|
+
color: "#374151",
|
|
21439
|
+
transition: "background-color 0.15s, border-color 0.15s"
|
|
21440
|
+
};
|
|
21441
|
+
const inputRowStyle = {
|
|
21442
|
+
display: "flex",
|
|
21443
|
+
alignItems: "center",
|
|
21444
|
+
gap: "4px"
|
|
21445
|
+
};
|
|
21446
|
+
const inputStyle = buildInputStyle({}, { focused: false, error: duplicate });
|
|
21447
|
+
const listItems = [];
|
|
21448
|
+
for (let i = 0; i < items.length; i++) {
|
|
21449
|
+
const item = items[i];
|
|
21450
|
+
if (orientation === "horizontal" && i > 0) {
|
|
21451
|
+
listItems.push(
|
|
21452
|
+
createElement("span", {
|
|
21453
|
+
key: `delim-${i}`,
|
|
21454
|
+
style: { color: "#9ca3af", fontSize: "14px", userSelect: "none" },
|
|
21455
|
+
"aria-hidden": "true"
|
|
21456
|
+
}, delimiter)
|
|
21457
|
+
);
|
|
21458
|
+
}
|
|
21459
|
+
listItems.push(
|
|
21460
|
+
createElement("span", {
|
|
21461
|
+
key: `item-${i}`,
|
|
21462
|
+
role: "listitem",
|
|
21463
|
+
tabIndex: disabled ? -1 : 0,
|
|
21464
|
+
style: itemStyle,
|
|
21465
|
+
onClick: disabled ? void 0 : () => openEdit(i),
|
|
21466
|
+
onKeyDown: disabled ? void 0 : (e) => {
|
|
21467
|
+
if (e.key === "Enter") openEdit(i);
|
|
21468
|
+
}
|
|
21469
|
+
}, item)
|
|
21470
|
+
);
|
|
21471
|
+
}
|
|
21472
|
+
const listEl = createElement(
|
|
21473
|
+
"div",
|
|
21474
|
+
{ role: "list", style: listContainerStyle },
|
|
21475
|
+
...listItems
|
|
21476
|
+
);
|
|
21477
|
+
const addBtnDisabled = disabled || maxItems !== void 0 && items.length >= maxItems;
|
|
21478
|
+
const addButton = createElement("button", {
|
|
21479
|
+
type: "button",
|
|
21480
|
+
"aria-label": "Add item",
|
|
21481
|
+
style: {
|
|
21482
|
+
...buttonBase,
|
|
21483
|
+
opacity: addBtnDisabled ? "0.5" : "1",
|
|
21484
|
+
cursor: addBtnDisabled ? "not-allowed" : "pointer"
|
|
21485
|
+
},
|
|
21486
|
+
disabled: addBtnDisabled,
|
|
21487
|
+
onClick: addBtnDisabled ? void 0 : openAdd
|
|
21488
|
+
}, "+");
|
|
21489
|
+
let inputRow = null;
|
|
21490
|
+
if (mode.type !== "closed") {
|
|
21491
|
+
const okBtn = createElement("button", {
|
|
21492
|
+
type: "button",
|
|
21493
|
+
"aria-label": "Confirm",
|
|
21494
|
+
style: { ...buttonBase, fontSize: "13px", padding: "4px 8px" },
|
|
21495
|
+
onClick: handleConfirm
|
|
21496
|
+
}, "OK");
|
|
21497
|
+
const deleteBtn = mode.type === "edit" ? createElement("button", {
|
|
21498
|
+
type: "button",
|
|
21499
|
+
"aria-label": "Delete",
|
|
21500
|
+
style: { ...buttonBase, fontSize: "13px", padding: "4px 8px", color: "#ef4444" },
|
|
21501
|
+
onClick: handleDelete
|
|
21502
|
+
}, "X") : null;
|
|
21503
|
+
inputRow = createElement(
|
|
21504
|
+
"div",
|
|
21505
|
+
{ style: inputRowStyle, className: "buildable-list__input-row" },
|
|
21506
|
+
createElement("input", {
|
|
21507
|
+
ref: inputRef,
|
|
21508
|
+
type: "text",
|
|
21509
|
+
value: inputValue,
|
|
21510
|
+
placeholder,
|
|
21511
|
+
"aria-label": mode.type === "edit" ? "Edit item" : "New item",
|
|
21512
|
+
style: { ...inputStyle, flex: "1", minWidth: "0" },
|
|
21513
|
+
autoFocus: true,
|
|
21514
|
+
onInput: (e) => {
|
|
21515
|
+
setInputValue(e.target.value);
|
|
21516
|
+
setDuplicate(false);
|
|
21517
|
+
},
|
|
21518
|
+
onKeyDown: handleInputKeyDown
|
|
21519
|
+
}),
|
|
21520
|
+
okBtn,
|
|
21521
|
+
deleteBtn
|
|
21522
|
+
);
|
|
21523
|
+
}
|
|
21524
|
+
const bodyParts = [];
|
|
21525
|
+
if (mode.type !== "closed" && inputPosition === "above") {
|
|
21526
|
+
bodyParts.push(inputRow);
|
|
21527
|
+
}
|
|
21528
|
+
bodyParts.push(
|
|
21529
|
+
createElement(
|
|
21530
|
+
"div",
|
|
21531
|
+
{
|
|
21532
|
+
style: {
|
|
21533
|
+
display: "flex",
|
|
21534
|
+
alignItems: "flex-start",
|
|
21535
|
+
gap: "8px"
|
|
21536
|
+
}
|
|
21537
|
+
},
|
|
21538
|
+
listEl,
|
|
21539
|
+
addButton
|
|
21540
|
+
)
|
|
21541
|
+
);
|
|
21542
|
+
if (mode.type !== "closed" && inputPosition === "below") {
|
|
21543
|
+
bodyParts.push(inputRow);
|
|
21544
|
+
}
|
|
21545
|
+
const body = createElement(
|
|
21546
|
+
"div",
|
|
21547
|
+
{
|
|
21548
|
+
style: containerStyle3,
|
|
21549
|
+
tabIndex: 0,
|
|
21550
|
+
onKeyDown: handleContainerKeyDown,
|
|
21551
|
+
className: "buildable-list"
|
|
21552
|
+
},
|
|
21553
|
+
...bodyParts
|
|
21554
|
+
);
|
|
21555
|
+
return createElement(
|
|
21556
|
+
FormFieldWrapper,
|
|
21557
|
+
{ label, disabled },
|
|
21558
|
+
body
|
|
21559
|
+
);
|
|
21560
|
+
}
|
|
21561
|
+
|
|
21222
21562
|
// ../components/form/button/src/Button.ts
|
|
21223
21563
|
var SIZE_MAP6 = {
|
|
21224
21564
|
sm: { padding: "3px 10px", fontSize: "12px", borderRadius: "4px" },
|
|
@@ -30351,6 +30691,7 @@ export {
|
|
|
30351
30691
|
BoxPlot,
|
|
30352
30692
|
Breadcrumb,
|
|
30353
30693
|
BubbleChart,
|
|
30694
|
+
BuildableList,
|
|
30354
30695
|
Button,
|
|
30355
30696
|
CARD_TYPE_OPTIONS,
|
|
30356
30697
|
COL_COMMENT,
|