@parallelworks/ui 0.40.1 → 0.42.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/README.md +25 -0
- package/dist/ai/adapter/memoryStore.js +7 -0
- package/dist/ai/adapter/mock/mockAdapter.js +52 -17
- package/dist/ai/adapter/openai/createOpenAIStream.js +1 -1
- package/dist/ai/adapter/openai/index.d.ts +1 -1
- package/dist/ai/adapter/openai/sse.d.ts +8 -2
- package/dist/ai/adapter/openai/sse.js +40 -4
- package/dist/ai/adapter/openai/wire.d.ts +6 -0
- package/dist/ai/components/AllocationSelector.d.ts +3 -4
- package/dist/ai/components/AllocationSelector.js +37 -33
- package/dist/ai/components/AttachmentManager.js +7 -7
- package/dist/ai/components/AttachmentUpload.js +5 -5
- package/dist/ai/components/BranchNavigator.js +1 -1
- package/dist/ai/components/ChatEmptyState.js +2 -2
- package/dist/ai/components/ChatInput.js +10 -8
- package/dist/ai/components/ChatLayout.js +4 -5
- package/dist/ai/components/ChatMessage.js +12 -12
- package/dist/ai/components/ChatMessageList.js +9 -9
- package/dist/ai/components/ChatSidebar.js +8 -9
- package/dist/ai/components/ChatThread.js +4 -4
- package/dist/ai/components/ComposerChrome.d.ts +2 -2
- package/dist/ai/components/ComposerChrome.js +3 -6
- package/dist/ai/components/DragOverlay.js +2 -2
- package/dist/ai/components/ModelSelector.d.ts +5 -3
- package/dist/ai/components/ModelSelector.js +102 -339
- package/dist/ai/components/PastedText.js +11 -11
- package/dist/ai/components/ProviderIssueBanner.d.ts +2 -0
- package/dist/ai/components/ProviderIssueBanner.js +34 -16
- package/dist/ai/components/Reasoning.js +4 -4
- package/dist/ai/components/ShareDialog.js +43 -35
- package/dist/ai/components/SlashMenu.d.ts +12 -2
- package/dist/ai/components/SlashMenu.js +29 -13
- package/dist/ai/components/agent/ActivityLine.js +3 -3
- package/dist/ai/components/agent/AgentMessageParts.js +20 -20
- package/dist/ai/components/agent/PermissionPicker.js +13 -11
- package/dist/ai/components/conversationActions.d.ts +4 -6
- package/dist/ai/components/conversationActions.js +9 -13
- package/dist/ai/core/ChatProvider.js +4 -4
- package/dist/ai/core/config.js +1 -1
- package/dist/ai/core/parts.d.ts +5 -0
- package/dist/ai/core/parts.js +28 -1
- package/dist/ai/core/providerIssues.d.ts +7 -0
- package/dist/ai/core/providerIssues.js +9 -1
- package/dist/ai/core/useKeyboardShortcuts.d.ts +4 -0
- package/dist/ai/core/useKeyboardShortcuts.js +8 -2
- package/dist/ai/index.d.ts +0 -1
- package/dist/ai/index.js +1 -2
- package/dist/ai/strings.d.ts +19 -0
- package/dist/ai/strings.js +18 -1
- package/dist/ai/ui/Avatar.js +5 -5
- package/dist/ai/ui/ConversationSidebar.d.ts +0 -1
- package/dist/ai/ui/ConversationSidebar.js +6 -7
- package/dist/ai/ui/Markdown.js +3 -3
- package/dist/ai/ui/Notice.js +6 -6
- package/dist/ai/ui/chip.d.ts +4 -0
- package/dist/ai/ui/chip.js +8 -0
- package/dist/ai/ui/sidebar.d.ts +6 -5
- package/dist/ai/ui/sidebar.js +39 -43
- package/dist/components/ActionMenu.d.ts +13 -0
- package/dist/components/ActionMenu.js +30 -0
- package/dist/components/Avatar.js +6 -6
- package/dist/components/Breadcrumbs.js +1 -1
- package/dist/components/Button.js +10 -10
- package/dist/components/Callout.js +2 -2
- package/dist/components/Card.js +3 -3
- package/dist/components/Combobox.d.ts +66 -0
- package/dist/components/Combobox.js +393 -0
- package/dist/components/ConfirmModal.js +11 -11
- package/dist/components/ContextMenu.d.ts +23 -0
- package/dist/components/ContextMenu.js +89 -0
- package/dist/components/CopyToClipboard.js +2 -2
- package/dist/components/CreateModal.d.ts +17 -36
- package/dist/components/CreateModal.js +97 -259
- package/dist/components/DescriptionList.js +8 -8
- package/dist/components/Filter.js +2 -2
- package/dist/components/FilterPill.js +2 -2
- package/dist/components/HoverCard.d.ts +14 -0
- package/dist/components/HoverCard.js +33 -0
- package/dist/components/IconButton.d.ts +5 -5
- package/dist/components/IconButton.js +18 -22
- package/dist/components/InfoTip.d.ts +15 -0
- package/dist/components/InfoTip.js +60 -0
- package/dist/components/Input.js +5 -5
- package/dist/components/LetterBadge.js +2 -2
- package/dist/components/Loader.js +3 -3
- package/dist/components/Markdown.js +1 -1
- package/dist/components/MarkdownImpl.js +2 -2
- package/dist/components/Menu.d.ts +33 -0
- package/dist/components/Menu.js +86 -0
- package/dist/components/MenuEntries.d.ts +56 -0
- package/dist/components/MenuEntries.js +123 -0
- package/dist/components/Modal.d.ts +29 -0
- package/dist/components/Modal.js +47 -0
- package/dist/components/Overview.js +11 -10
- package/dist/components/PageHeader.d.ts +10 -16
- package/dist/components/PageHeader.js +69 -95
- package/dist/components/Pagination.js +5 -5
- package/dist/components/Provider.d.ts +5 -11
- package/dist/components/Provider.js +11 -14
- package/dist/components/Radio.d.ts +8 -0
- package/dist/components/Radio.js +16 -0
- package/dist/components/SectionHeader.js +2 -2
- package/dist/components/SegmentedControl.d.ts +6 -5
- package/dist/components/SegmentedControl.js +34 -30
- package/dist/components/Select.d.ts +27 -0
- package/dist/components/Select.js +78 -0
- package/dist/components/SettingModeOption.d.ts +5 -8
- package/dist/components/SettingModeOption.js +10 -12
- package/dist/components/SettingRow.js +4 -4
- package/dist/components/SettingsCard.js +4 -4
- package/dist/components/SettingsGroup.js +2 -2
- package/dist/components/Sort.js +1 -1
- package/dist/components/StatusBadge.js +7 -7
- package/dist/components/StatusIcons.js +4 -4
- package/dist/components/Switch.d.ts +22 -0
- package/dist/components/Switch.js +28 -0
- package/dist/components/Table.js +11 -11
- package/dist/components/Tooltip.d.ts +24 -20
- package/dist/components/Tooltip.js +58 -76
- package/dist/components/floating.d.ts +14 -0
- package/dist/components/floating.js +21 -0
- package/dist/components/search.d.ts +2 -0
- package/dist/components/search.js +14 -0
- package/dist/editor/Editor.js +1 -1
- package/dist/editor/EditorField.js +16 -21
- package/dist/editor/FormCodePanel.js +19 -19
- package/dist/editor/Monaco.js +3 -3
- package/dist/file-explorer/FileExplorer.js +77 -81
- package/dist/file-explorer/FileExplorerContext.js +2 -2
- package/dist/file-explorer/FilePreview/CodePreviewEditor.js +1 -1
- package/dist/file-explorer/FilePreview/Inline.js +1 -1
- package/dist/file-explorer/FilePreview/StreamedBadge.js +5 -6
- package/dist/file-explorer/FilePreview/Viewer.js +8 -8
- package/dist/file-explorer/FilePreview/index.d.ts +1 -1
- package/dist/file-explorer/FilePreview/index.js +49 -83
- package/dist/file-explorer/FileRow.d.ts +4 -3
- package/dist/file-explorer/FileRow.js +32 -38
- package/dist/file-explorer/FileRowsWindow.d.ts +3 -2
- package/dist/file-explorer/FileRowsWindow.js +4 -4
- package/dist/file-explorer/FileTable.d.ts +3 -2
- package/dist/file-explorer/FileTable.js +3 -3
- package/dist/file-explorer/LoadMoreRow.js +1 -1
- package/dist/file-explorer/TreeView.js +11 -16
- package/dist/file-explorer/helpers.js +11 -12
- package/dist/file-explorer/toasts.js +11 -11
- package/dist/form/FieldGroup.d.ts +11 -0
- package/dist/form/FieldGroup.js +36 -0
- package/dist/form/FieldWrapper.js +4 -4
- package/dist/form/Fields/BooleanField.js +23 -33
- package/dist/form/Fields/CheckboxGroupField.d.ts +1 -1
- package/dist/form/Fields/CheckboxGroupField.js +9 -13
- package/dist/form/Fields/ColorField.d.ts +1 -2
- package/dist/form/Fields/ColorField.js +6 -11
- package/dist/form/Fields/DropdownField.d.ts +3 -13
- package/dist/form/Fields/DropdownField.js +40 -27
- package/dist/form/Fields/DurationField.d.ts +1 -2
- package/dist/form/Fields/DurationField.js +25 -32
- package/dist/form/Fields/LabelField.js +2 -2
- package/dist/form/Fields/MultiDropdownField.d.ts +6 -12
- package/dist/form/Fields/MultiDropdownField.js +31 -22
- package/dist/form/Fields/NumberField.d.ts +1 -1
- package/dist/form/Fields/NumberField.js +65 -35
- package/dist/form/Fields/ObjectField.d.ts +1 -1
- package/dist/form/Fields/ObjectField.js +12 -43
- package/dist/form/Fields/RadioField.d.ts +1 -1
- package/dist/form/Fields/RadioField.js +30 -41
- package/dist/form/Fields/RangeField.d.ts +1 -2
- package/dist/form/Fields/RangeField.js +23 -16
- package/dist/form/Fields/StringField.d.ts +1 -2
- package/dist/form/Fields/StringField.js +58 -26
- package/dist/form/Fields/TextAreaField.js +12 -10
- package/dist/form/Form.d.ts +30 -48
- package/dist/form/Form.js +306 -412
- package/dist/form/FormLayout.js +9 -9
- package/dist/form/Wizard/WizardContainer.d.ts +1 -4
- package/dist/form/Wizard/WizardContainer.js +40 -56
- package/dist/form/Wizard/WizardNavigation.js +1 -1
- package/dist/form/Wizard/WizardStepContent.d.ts +1 -5
- package/dist/form/Wizard/WizardStepContent.js +11 -16
- package/dist/form/Wizard/WizardStepIndicator.js +6 -6
- package/dist/form/Wizard/types.d.ts +0 -14
- package/dist/form/fieldRegistry.d.ts +1 -1
- package/dist/form/fieldRegistry.js +6 -6
- package/dist/form/formEditing.js +1 -1
- package/dist/form/index.d.ts +5 -4
- package/dist/form/index.js +6 -7
- package/dist/form/types/fieldComponentTypes.d.ts +8 -10
- package/dist/form/useChoiceField.d.ts +20 -0
- package/dist/form/useChoiceField.js +49 -0
- package/dist/form/useFieldValue.d.ts +7 -0
- package/dist/form/useFieldValue.js +20 -0
- package/dist/form/useParsedOpts.d.ts +3 -1
- package/dist/form/useParsedOpts.js +12 -17
- package/dist/form/utils/dependentOptions.d.ts +8 -4
- package/dist/form/utils/dependentOptions.js +25 -17
- package/dist/form/utils/fieldItems.d.ts +10 -0
- package/dist/form/utils/fieldItems.js +11 -0
- package/dist/form/utils/fieldPath.d.ts +10 -0
- package/dist/form/utils/fieldPath.js +20 -0
- package/dist/form/utils/shareEqual.d.ts +6 -0
- package/dist/form/utils/shareEqual.js +38 -0
- package/dist/graph/AnnotationBanner.js +8 -8
- package/dist/graph/Collapse.d.ts +1 -0
- package/dist/graph/Collapse.js +6 -27
- package/dist/graph/Connectors.js +5 -5
- package/dist/graph/DependencyGraph.js +20 -19
- package/dist/graph/GraphEditor.js +30 -41
- package/dist/graph/GraphEditorDialogs.js +17 -17
- package/dist/graph/GraphNode.js +1 -1
- package/dist/graph/InputDialog.js +19 -22
- package/dist/graph/InputsEditor.js +58 -66
- package/dist/graph/JobSummary.js +42 -39
- package/dist/graph/MatrixGroup.js +1 -1
- package/dist/graph/ProblemsButton.js +18 -19
- package/dist/graph/Reveal.js +1 -1
- package/dist/graph/ShortcutsButton.js +15 -18
- package/dist/graph/SuggestionInput.d.ts +5 -10
- package/dist/graph/SuggestionInput.js +14 -18
- package/dist/graph/ToolbarPopover.d.ts +11 -6
- package/dist/graph/ToolbarPopover.js +35 -67
- package/dist/graph/TreeView.js +24 -37
- package/dist/graph/WorkflowSettingsDialog.js +4 -4
- package/dist/graph/editorChrome.js +13 -12
- package/dist/graph/editorFields.js +29 -29
- package/dist/graph/editorPrimitives.d.ts +1 -1
- package/dist/graph/editorPrimitives.js +10 -7
- package/dist/graph/editorRows.js +103 -97
- package/dist/graph/fieldProblems.js +2 -2
- package/dist/graph/graphEditorState.d.ts +4 -3
- package/dist/graph/inputRefs.js +9 -9
- package/dist/graph/settingsViews.js +6 -7
- package/dist/graph/stepWith.js +6 -6
- package/dist/index.d.ts +14 -15
- package/dist/index.js +15 -14
- package/dist/list/ActionToolbar.d.ts +6 -14
- package/dist/list/ActionToolbar.js +48 -96
- package/dist/list/ListPage.d.ts +6 -12
- package/dist/list/ListPage.js +46 -29
- package/dist/list/ListPager.js +4 -4
- package/dist/list/ListTable.js +5 -5
- package/dist/list/ListViewControls.d.ts +5 -4
- package/dist/list/ListViewControls.js +177 -267
- package/dist/list/UserHoverCard.d.ts +3 -17
- package/dist/list/UserHoverCard.js +21 -45
- package/dist/list/index.d.ts +3 -4
- package/dist/list/index.js +3 -4
- package/dist/list/listSearch.js +12 -11
- package/dist/list/rowMenu.d.ts +63 -0
- package/dist/list/rowMenu.js +134 -0
- package/dist/logviewer/LogViewer.js +26 -26
- package/dist/styles.css +1 -1
- package/package.json +7 -13
- package/dist/ai/ui/Dropdown.d.ts +0 -31
- package/dist/ai/ui/Dropdown.js +0 -110
- package/dist/components/AddMenu.d.ts +0 -18
- package/dist/components/AddMenu.js +0 -46
- package/dist/components/BareModal.d.ts +0 -17
- package/dist/components/BareModal.js +0 -77
- package/dist/components/CollapsiblePanel.d.ts +0 -27
- package/dist/components/CollapsiblePanel.js +0 -77
- package/dist/components/Dropdown.d.ts +0 -28
- package/dist/components/Dropdown.js +0 -355
- package/dist/components/Listbox.d.ts +0 -21
- package/dist/components/Listbox.js +0 -119
- package/dist/components/MultiSelect.d.ts +0 -22
- package/dist/components/MultiSelect.js +0 -168
- package/dist/components/SwitchToggle.d.ts +0 -15
- package/dist/components/SwitchToggle.js +0 -57
- package/dist/components/SwitchToggleSmall.d.ts +0 -6
- package/dist/components/SwitchToggleSmall.js +0 -14
- package/dist/components/Toggle.d.ts +0 -6
- package/dist/components/Toggle.js +0 -20
- package/dist/components/dropdownUtils.d.ts +0 -37
- package/dist/components/dropdownUtils.js +0 -99
- package/dist/form/SpecialTypes/DropdownWrapper.d.ts +0 -25
- package/dist/form/SpecialTypes/DropdownWrapper.js +0 -28
- package/dist/form/SpecialTypes/FormikCustomDropdown.d.ts +0 -51
- package/dist/form/SpecialTypes/FormikCustomDropdown.js +0 -119
- package/dist/form/SpecialTypes/FormikCustomInput.d.ts +0 -19
- package/dist/form/SpecialTypes/FormikCustomInput.js +0 -121
- package/dist/form/SpecialTypes/FormikMultiSelectDropdown.d.ts +0 -13
- package/dist/form/SpecialTypes/FormikMultiSelectDropdown.js +0 -31
- package/dist/form/SpecialTypes/FormikNumericInput.d.ts +0 -9
- package/dist/form/SpecialTypes/FormikNumericInput.js +0 -60
- package/dist/form/SpecialTypes/index.d.ts +0 -3
- package/dist/list/HoverCard.d.ts +0 -24
- package/dist/list/HoverCard.js +0 -73
- package/dist/list/RowContextMenu.d.ts +0 -127
- package/dist/list/RowContextMenu.js +0 -515
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
interface IToggleProps {
|
|
2
|
-
onChange: (value: boolean) => void;
|
|
3
|
-
/** Lets a `<label htmlFor>` point at the toggle. */
|
|
4
|
-
id?: string | undefined;
|
|
5
|
-
'aria-describedby'?: string | undefined;
|
|
6
|
-
value?: boolean;
|
|
7
|
-
/** Display label for the on/off positions; defaults to Yes/No. */
|
|
8
|
-
yesLabel?: string;
|
|
9
|
-
noLabel?: string;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
datatip?: string | undefined;
|
|
12
|
-
invalid?: boolean;
|
|
13
|
-
}
|
|
14
|
-
declare function SwitchToggle({ onChange, id, 'aria-describedby': describedBy, value, yesLabel, noLabel, disabled, datatip, invalid, }: IToggleProps): import("react").JSX.Element;
|
|
15
|
-
export default SwitchToggle;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { TOOLTIP_ID } from "./Tooltip.js";
|
|
2
|
-
import { Switch } from "@headlessui/react";
|
|
3
|
-
import cx from "classnames";
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
//#region src/components/SwitchToggle.tsx
|
|
7
|
-
function SwitchToggle({ onChange, id, "aria-describedby": describedBy, value, yesLabel = "Yes", noLabel = "No", disabled = false, datatip = "", invalid = false }) {
|
|
8
|
-
const [enabled, setEnabled] = useState(value ?? false);
|
|
9
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
10
|
-
const setIsEnabled = (e) => {
|
|
11
|
-
setEnabled(e);
|
|
12
|
-
onChange(e);
|
|
13
|
-
};
|
|
14
|
-
const checked = value ?? enabled;
|
|
15
|
-
return /* @__PURE__ */ jsx("div", {
|
|
16
|
-
...datatip ? {
|
|
17
|
-
"data-tooltip-content": datatip,
|
|
18
|
-
"data-tooltip-id": TOOLTIP_ID
|
|
19
|
-
} : {},
|
|
20
|
-
className: cx("w-[198px] h-[30px] overflow-hidden shadow-sm rounded-md cursor-pointer ring-(--theme-border) ring-1", invalid && "border-red-600 focus:border-red-600 focus:ring-red-500 ring-1 ring-red-500", !invalid && isFocused && "ring-1 ring-[rgba(82,168,236,.8)] drop-shadow-[0_1px_2px_rgba(82,168,236,0.8)]"),
|
|
21
|
-
children: /* @__PURE__ */ jsx(Switch, {
|
|
22
|
-
id,
|
|
23
|
-
"aria-describedby": describedBy,
|
|
24
|
-
checked,
|
|
25
|
-
disabled,
|
|
26
|
-
onChange: setIsEnabled,
|
|
27
|
-
className: "text-white text-sm shadow-sm rounded-md cursor-pointer",
|
|
28
|
-
onClick: (e) => e.stopPropagation(),
|
|
29
|
-
onFocus: () => setIsFocused(true),
|
|
30
|
-
onBlur: () => setIsFocused(false),
|
|
31
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
32
|
-
className: cx(checked ? "translate-x-0" : "-translate-x-[100px]", "relative transform flex flex-row ease-in-out duration-500", disabled && "cursor-not-allowed opacity-50"),
|
|
33
|
-
children: [
|
|
34
|
-
/* @__PURE__ */ jsx("div", {
|
|
35
|
-
className: "inline text-center capitalize px-2 py-1 w-[99px] border-0",
|
|
36
|
-
style: {
|
|
37
|
-
background: `linear-gradient(
|
|
38
|
-
to bottom,
|
|
39
|
-
var(--theme-element, #04c) 0%,
|
|
40
|
-
var(--theme-element, #08c) 100%
|
|
41
|
-
)`,
|
|
42
|
-
color: "var(--theme-element-text, #ffffff)"
|
|
43
|
-
},
|
|
44
|
-
children: yesLabel
|
|
45
|
-
}),
|
|
46
|
-
/* @__PURE__ */ jsx("div", { className: "inline px-2 py-1 h-8 w-[99px] bg-linear-to-b from-white to-[#e6e6e6]" }),
|
|
47
|
-
/* @__PURE__ */ jsx("div", {
|
|
48
|
-
className: "inline text-center capitalize px-2 py-1 w-[99px] bg-linear-to-b from-[#e6e6e6] to-white bg-[#04c] text-black",
|
|
49
|
-
children: noLabel
|
|
50
|
-
})
|
|
51
|
-
]
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { SwitchToggle as default };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
interface SwitchToggleSmallProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value'> {
|
|
3
|
-
value?: boolean;
|
|
4
|
-
}
|
|
5
|
-
export default function SwitchToggleSmall({ value, disabled, className, ...buttonProps }: SwitchToggleSmallProps): React.JSX.Element;
|
|
6
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import cx from "classnames";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
//#region src/components/SwitchToggleSmall.tsx
|
|
4
|
-
function SwitchToggleSmall({ value = false, disabled = false, className, ...buttonProps }) {
|
|
5
|
-
return /* @__PURE__ */ jsx("button", {
|
|
6
|
-
disabled,
|
|
7
|
-
...buttonProps,
|
|
8
|
-
role: "switch",
|
|
9
|
-
"aria-checked": value,
|
|
10
|
-
className: cx("relative w-11 h-6 rounded-full transition-colors duration-400 ease-in-out", "before:content-[\"\"] before:absolute before:w-4 before:h-4 before:top-1 before:left-1", "before:bg-white before:rounded-full before:transition-transform before:duration-400 before:ease-in-out", disabled ? "bg-(--theme-border) cursor-not-allowed" : "cursor-pointer", !disabled && value ? "bg-(--theme-element) before:translate-x-5" : "bg-(--theme-border)", className)
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { SwitchToggleSmall as default };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import cx from "classnames";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
//#region src/components/Toggle.tsx
|
|
4
|
-
function Toggle({ checked, onChange, disabled, label }) {
|
|
5
|
-
return /* @__PURE__ */ jsxs("label", {
|
|
6
|
-
role: "none",
|
|
7
|
-
onClick: (e) => e.stopPropagation(),
|
|
8
|
-
className: cx("relative inline-flex items-center", disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer"),
|
|
9
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
10
|
-
type: "checkbox",
|
|
11
|
-
className: "peer sr-only",
|
|
12
|
-
checked,
|
|
13
|
-
onChange: (e) => onChange(e.target.checked),
|
|
14
|
-
disabled,
|
|
15
|
-
"aria-label": label
|
|
16
|
-
}), /* @__PURE__ */ jsx("div", { className: "h-6 w-11 rounded-full bg-(--theme-muted-panel-bg) transition-colors peer-checked:bg-(--theme-element) peer-focus-visible:ring-2 peer-focus-visible:ring-[color-mix(in_srgb,var(--theme-element)_25%,transparent)] after:absolute after:start-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:bg-white after:shadow-sm after:transition-transform after:content-[\"\"] motion-reduce:after:transition-none peer-checked:after:translate-x-5" })]
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { Toggle };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
export interface IOptions<T = unknown> {
|
|
3
|
-
label: string;
|
|
4
|
-
value: T;
|
|
5
|
-
secondaryValue?: unknown | undefined;
|
|
6
|
-
disabled?: boolean | undefined;
|
|
7
|
-
icon?: React.ReactNode | undefined;
|
|
8
|
-
description?: string | undefined;
|
|
9
|
-
/** Hidden behind the category's toggle row until the category is expanded. */
|
|
10
|
-
collapsible?: boolean | undefined;
|
|
11
|
-
/** Always listed regardless of the typed query (e.g. a trailing "Create new…" action). */
|
|
12
|
-
pinned?: boolean | undefined;
|
|
13
|
-
}
|
|
14
|
-
export interface ICategory<T = unknown> {
|
|
15
|
-
category?: string | undefined;
|
|
16
|
-
options: IOptions<T>[];
|
|
17
|
-
}
|
|
18
|
-
export declare function isCategory<T>(option: ICategory<T> | IOptions<T> | string): option is ICategory<T>;
|
|
19
|
-
export declare function isOption<T>(option: ICategory<T> | IOptions<T> | string): option is IOptions<T>;
|
|
20
|
-
export declare function flattenOptions<T>(options: (ICategory<T> | IOptions<T> | string)[]): (IOptions<T> | ICategory<T>)[];
|
|
21
|
-
export declare function filterOption<T>(option: IOptions<T>, query: string): boolean;
|
|
22
|
-
export declare function toggleSetMember<T>(set: ReadonlySet<T>, member: T): Set<T>;
|
|
23
|
-
export type FlatDisplayOption = IOptions & {
|
|
24
|
-
category?: boolean;
|
|
25
|
-
/** Set on a category's toggle row to the category it expands/collapses. */
|
|
26
|
-
toggle?: string;
|
|
27
|
-
};
|
|
28
|
-
export declare function flattenDisplayOptions({ options, query, expandedCategories, collapsedLabel, selectedValue, allowCustomValue, customValueLabel, }: {
|
|
29
|
-
options: (ICategory | IOptions)[];
|
|
30
|
-
query: string;
|
|
31
|
-
expandedCategories?: ReadonlySet<string>;
|
|
32
|
-
collapsedLabel?: (count: number) => string;
|
|
33
|
-
selectedValue?: unknown;
|
|
34
|
-
allowCustomValue?: boolean;
|
|
35
|
-
customValueLabel?: string;
|
|
36
|
-
}): FlatDisplayOption[];
|
|
37
|
-
export declare function DropdownCaret(): React.JSX.Element;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { FaCaretDown } from "../icons/fa/FaCaretDown.js";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
//#region src/components/dropdownUtils.tsx
|
|
4
|
-
function isCategory(option) {
|
|
5
|
-
return typeof option === "object" && option !== null && "options" in option;
|
|
6
|
-
}
|
|
7
|
-
function isOption(option) {
|
|
8
|
-
return typeof option === "object" && "label" in option && "value" in option && !("category" in option);
|
|
9
|
-
}
|
|
10
|
-
function normalizeOption(option) {
|
|
11
|
-
if (typeof option === "string") return {
|
|
12
|
-
label: option,
|
|
13
|
-
value: option
|
|
14
|
-
};
|
|
15
|
-
if (typeof option === "object" && option !== null && "options" in option) return {
|
|
16
|
-
category: option.category,
|
|
17
|
-
options: Array.isArray(option.options) ? option.options : []
|
|
18
|
-
};
|
|
19
|
-
return option;
|
|
20
|
-
}
|
|
21
|
-
function flattenOptions(options) {
|
|
22
|
-
const result = [];
|
|
23
|
-
for (const opt of options) {
|
|
24
|
-
const normalized = normalizeOption(opt);
|
|
25
|
-
if (isCategory(normalized)) {
|
|
26
|
-
const children = Array.isArray(normalized.options) ? normalized.options : [];
|
|
27
|
-
result.push(normalized);
|
|
28
|
-
result.push(...children);
|
|
29
|
-
} else result.push(normalized);
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
var normalizeForMatch = (text) => String(text).toLowerCase().replace(/-/g, "");
|
|
34
|
-
function filterOption(option, query) {
|
|
35
|
-
if (query === "") return true;
|
|
36
|
-
const q = normalizeForMatch(query);
|
|
37
|
-
return normalizeForMatch(option.label ?? "").includes(q) || option.secondaryValue !== void 0 && normalizeForMatch(option.secondaryValue).includes(q);
|
|
38
|
-
}
|
|
39
|
-
function toggleSetMember(set, member) {
|
|
40
|
-
const next = new Set(set);
|
|
41
|
-
if (next.has(member)) next.delete(member);
|
|
42
|
-
else next.add(member);
|
|
43
|
-
return next;
|
|
44
|
-
}
|
|
45
|
-
function collapsedCategoryRows(category, filtered, collapsibleCount, expanded, collapsedLabel) {
|
|
46
|
-
const rows = [];
|
|
47
|
-
let togglePlaced = false;
|
|
48
|
-
for (const opt of filtered) {
|
|
49
|
-
if (!opt.collapsible) {
|
|
50
|
-
rows.push(opt);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (!togglePlaced) {
|
|
54
|
-
togglePlaced = true;
|
|
55
|
-
rows.push({
|
|
56
|
-
label: collapsedLabel(collapsibleCount),
|
|
57
|
-
value: `__toggle__:${category}`,
|
|
58
|
-
disabled: true,
|
|
59
|
-
toggle: category
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (expanded) rows.push(opt);
|
|
63
|
-
}
|
|
64
|
-
return rows;
|
|
65
|
-
}
|
|
66
|
-
function flattenDisplayOptions({ options, query, expandedCategories, collapsedLabel, selectedValue, allowCustomValue, customValueLabel }) {
|
|
67
|
-
const flatOptions = options.flatMap((option) => {
|
|
68
|
-
if (!isCategory(option)) return option.pinned || filterOption(option, query) ? [option] : [];
|
|
69
|
-
const filtered = option.options.filter((opt) => filterOption(opt, query));
|
|
70
|
-
if (filtered.length === 0) return [];
|
|
71
|
-
const category = option.category || "";
|
|
72
|
-
const header = {
|
|
73
|
-
label: category,
|
|
74
|
-
value: category,
|
|
75
|
-
disabled: true,
|
|
76
|
-
category: true
|
|
77
|
-
};
|
|
78
|
-
const collapsibleCount = filtered.filter((o) => o.collapsible).length;
|
|
79
|
-
if (query || collapsibleCount === 0 || !collapsedLabel) return [header, ...filtered];
|
|
80
|
-
return [header, ...collapsedCategoryRows(category, filtered, collapsibleCount, expandedCategories?.has(category) ?? false, collapsedLabel)];
|
|
81
|
-
});
|
|
82
|
-
if (allowCustomValue) {
|
|
83
|
-
const customValue = query || selectedValue || "";
|
|
84
|
-
flatOptions.unshift({
|
|
85
|
-
label: `${customValueLabel} "${customValue}"`,
|
|
86
|
-
value: customValue
|
|
87
|
-
});
|
|
88
|
-
} else if (flatOptions.length === 0) return [{
|
|
89
|
-
label: "No options found",
|
|
90
|
-
value: "",
|
|
91
|
-
disabled: true
|
|
92
|
-
}];
|
|
93
|
-
return flatOptions;
|
|
94
|
-
}
|
|
95
|
-
function DropdownCaret() {
|
|
96
|
-
return /* @__PURE__ */ jsx(FaCaretDown, { className: "text-neutral-400 absolute top-1/2 -translate-y-1/2 right-0 mr-3 inset-y-0 flex items-center rounded-r-md focus:outline-hidden" });
|
|
97
|
-
}
|
|
98
|
-
//#endregion
|
|
99
|
-
export { DropdownCaret, filterOption, flattenDisplayOptions, flattenOptions, isCategory, isOption, toggleSetMember };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import FormikCustomDropdown from './FormikCustomDropdown.js';
|
|
2
|
-
export default function DropdownWrapper({ options, onChange, fieldObj, setFormDirty, invalid, loading, disabled, allowCustomValue, currentValue, setFieldValue, setFieldTouched, }: {
|
|
3
|
-
options: React.ComponentProps<typeof FormikCustomDropdown>['options'];
|
|
4
|
-
onChange?: ((val: string) => void) | undefined;
|
|
5
|
-
fieldObj: {
|
|
6
|
-
name?: string | undefined;
|
|
7
|
-
label?: string | undefined;
|
|
8
|
-
disabled?: boolean | string | undefined;
|
|
9
|
-
placeholder?: string | undefined;
|
|
10
|
-
default?: unknown;
|
|
11
|
-
secondaryField?: string | string[] | undefined;
|
|
12
|
-
value?: string | undefined;
|
|
13
|
-
autoselect?: boolean | string | Record<string, unknown> | undefined;
|
|
14
|
-
allowCustomValue?: boolean | undefined;
|
|
15
|
-
customValueLabel?: string | undefined;
|
|
16
|
-
};
|
|
17
|
-
setFormDirty: React.ComponentProps<typeof FormikCustomDropdown>['setFormDirty'];
|
|
18
|
-
invalid?: boolean;
|
|
19
|
-
loading?: boolean;
|
|
20
|
-
disabled?: boolean | undefined;
|
|
21
|
-
allowCustomValue?: boolean;
|
|
22
|
-
currentValue: unknown;
|
|
23
|
-
setFieldValue: React.ComponentProps<typeof FormikCustomDropdown>['setFieldValue'];
|
|
24
|
-
setFieldTouched: React.ComponentProps<typeof FormikCustomDropdown>['setFieldTouched'];
|
|
25
|
-
}): import("react").JSX.Element;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import FormikCustomDropdown_default from "./FormikCustomDropdown.js";
|
|
2
|
-
import { getPlaceholder } from "../utils/getPlaceholder.js";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
//#region src/form/SpecialTypes/DropdownWrapper.tsx
|
|
5
|
-
function DropdownWrapper({ options, onChange, fieldObj, setFormDirty, invalid = false, loading = false, disabled, allowCustomValue, currentValue, setFieldValue, setFieldTouched }) {
|
|
6
|
-
return /* @__PURE__ */ jsx(FormikCustomDropdown_default, {
|
|
7
|
-
invalid,
|
|
8
|
-
className: "w-full",
|
|
9
|
-
onChange,
|
|
10
|
-
loading,
|
|
11
|
-
setFormDirty,
|
|
12
|
-
options,
|
|
13
|
-
disabled: disabled ?? Boolean(fieldObj.disabled),
|
|
14
|
-
placeholder: getPlaceholder(fieldObj.placeholder, typeof fieldObj.default === "string" ? fieldObj.default : void 0),
|
|
15
|
-
name: fieldObj.name ?? "",
|
|
16
|
-
ariaLabel: fieldObj.label,
|
|
17
|
-
secondaryField: fieldObj.secondaryField,
|
|
18
|
-
value: fieldObj.value,
|
|
19
|
-
autoselect: fieldObj.autoselect === void 0 ? void 0 : Boolean(fieldObj.autoselect),
|
|
20
|
-
allowCustomValue: allowCustomValue ?? fieldObj.allowCustomValue,
|
|
21
|
-
customValueLabel: fieldObj.customValueLabel,
|
|
22
|
-
currentValue,
|
|
23
|
-
setFieldValue,
|
|
24
|
-
setFieldTouched
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { DropdownWrapper as default };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Dropdown from '../../components/Dropdown.js';
|
|
2
|
-
import type { TSetFormDirty } from '../Form.js';
|
|
3
|
-
declare function toComparableOptions(options: React.ComponentProps<typeof Dropdown>['options'] | undefined): (string | {
|
|
4
|
-
category: string | undefined;
|
|
5
|
-
options: ({
|
|
6
|
-
label: string;
|
|
7
|
-
value: unknown;
|
|
8
|
-
disabled: boolean | undefined;
|
|
9
|
-
} | {
|
|
10
|
-
label: string;
|
|
11
|
-
value: unknown;
|
|
12
|
-
disabled: boolean | undefined;
|
|
13
|
-
description: string;
|
|
14
|
-
})[];
|
|
15
|
-
} | {
|
|
16
|
-
label: string;
|
|
17
|
-
value: unknown;
|
|
18
|
-
disabled: boolean | undefined;
|
|
19
|
-
} | {
|
|
20
|
-
category?: never;
|
|
21
|
-
options?: never;
|
|
22
|
-
label: string;
|
|
23
|
-
value: unknown;
|
|
24
|
-
disabled: boolean | undefined;
|
|
25
|
-
description: string;
|
|
26
|
-
})[] | undefined;
|
|
27
|
-
type FormikCustomDropdownProps = {
|
|
28
|
-
name: string;
|
|
29
|
-
ariaLabel?: string | undefined;
|
|
30
|
-
options: React.ComponentProps<typeof Dropdown>['options'];
|
|
31
|
-
setFormDirty: TSetFormDirty;
|
|
32
|
-
onChange?: ((val: string) => void) | undefined;
|
|
33
|
-
className?: string;
|
|
34
|
-
secondaryField?: string | string[] | undefined;
|
|
35
|
-
disabled?: boolean;
|
|
36
|
-
loading?: boolean;
|
|
37
|
-
invalid?: boolean;
|
|
38
|
-
autoselect?: boolean | undefined;
|
|
39
|
-
value?: string | undefined;
|
|
40
|
-
allowCustomValue?: boolean | undefined;
|
|
41
|
-
customValueLabel?: string | undefined;
|
|
42
|
-
placeholder?: string;
|
|
43
|
-
currentValue: unknown;
|
|
44
|
-
setFieldValue: (field: string, value: unknown, shouldValidate?: boolean) => void;
|
|
45
|
-
setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => void;
|
|
46
|
-
};
|
|
47
|
-
declare const _default: import("react").MemoExoticComponent<({ name, ariaLabel, options, setFormDirty, onChange, className, secondaryField, disabled, loading, invalid, autoselect, value, allowCustomValue, customValueLabel, placeholder, currentValue, setFieldValue, setFieldTouched, }: FormikCustomDropdownProps) => import("react").JSX.Element>;
|
|
48
|
-
export default _default;
|
|
49
|
-
export declare const Testables: {
|
|
50
|
-
toComparableOptions: typeof toComparableOptions;
|
|
51
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { isCategory } from "../../components/dropdownUtils.js";
|
|
2
|
-
import Dropdown from "../../components/Dropdown.js";
|
|
3
|
-
import { applySecondaryField, findSecondaryOption } from "../utils/secondaryField.js";
|
|
4
|
-
import { useFieldControlProps, useFieldRequired } from "../fieldContext.js";
|
|
5
|
-
import cx from "classnames";
|
|
6
|
-
import { memo, useEffect, useEffectEvent, useRef } from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import deepEqual from "fast-deep-equal";
|
|
9
|
-
//#region src/form/SpecialTypes/FormikCustomDropdown.tsx
|
|
10
|
-
function toComparableOptions(options) {
|
|
11
|
-
return options?.map((option) => {
|
|
12
|
-
if (typeof option === "string") return option;
|
|
13
|
-
if (isCategory(option)) return {
|
|
14
|
-
category: option.category,
|
|
15
|
-
options: option.options.map((o) => {
|
|
16
|
-
const base = {
|
|
17
|
-
label: o.label,
|
|
18
|
-
value: o.value,
|
|
19
|
-
disabled: o.disabled
|
|
20
|
-
};
|
|
21
|
-
return o.description !== void 0 ? {
|
|
22
|
-
...base,
|
|
23
|
-
description: o.description
|
|
24
|
-
} : base;
|
|
25
|
-
})
|
|
26
|
-
};
|
|
27
|
-
const base = {
|
|
28
|
-
label: option.label,
|
|
29
|
-
value: option.value,
|
|
30
|
-
disabled: option.disabled
|
|
31
|
-
};
|
|
32
|
-
return option.description !== void 0 ? {
|
|
33
|
-
...base,
|
|
34
|
-
description: option.description
|
|
35
|
-
} : base;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function arePropsEqual(prev, next) {
|
|
39
|
-
for (const key of Object.keys(next)) if (key === "options") {
|
|
40
|
-
if (!deepEqual(toComparableOptions(prev.options), toComparableOptions(next.options))) return false;
|
|
41
|
-
} else if (prev[key] !== next[key]) return false;
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
var FormikCustomDropdown_default = memo(function FormikCustomDropdown({ name, ariaLabel, options, setFormDirty, onChange, className, secondaryField, disabled = false, loading = false, invalid = false, autoselect, value, allowCustomValue = false, customValueLabel, placeholder, currentValue, setFieldValue, setFieldTouched }) {
|
|
45
|
-
const required = useFieldRequired();
|
|
46
|
-
const controlProps = useFieldControlProps();
|
|
47
|
-
const handleChange = (val) => {
|
|
48
|
-
if (secondaryField && typeof options[0] !== "string") {
|
|
49
|
-
const option = findSecondaryOption(options, val);
|
|
50
|
-
if (option) applySecondaryField(secondaryField, option.secondaryValue, setFieldValue);
|
|
51
|
-
}
|
|
52
|
-
onChange?.(val);
|
|
53
|
-
setFieldValue(name, val);
|
|
54
|
-
setFieldTouched(name, true);
|
|
55
|
-
setFormDirty(true);
|
|
56
|
-
};
|
|
57
|
-
const prevOptions = useRef(null);
|
|
58
|
-
const syncAutoselect = useEffectEvent((options, autoselect) => {
|
|
59
|
-
if (deepEqual(prevOptions.current, toComparableOptions(options))) return;
|
|
60
|
-
if (prevOptions.current === null && currentValue !== void 0 && currentValue !== null) {
|
|
61
|
-
prevOptions.current = toComparableOptions(options);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
prevOptions.current = toComparableOptions(options);
|
|
65
|
-
if (autoselect === false || !options?.length) return;
|
|
66
|
-
if (autoselect === void 0) {
|
|
67
|
-
const [first] = options;
|
|
68
|
-
if (first && isCategory(first)) {
|
|
69
|
-
let optionCount = 0;
|
|
70
|
-
for (const category of options) {
|
|
71
|
-
if (isCategory(category)) optionCount += category.options.length;
|
|
72
|
-
if (optionCount > 1) return;
|
|
73
|
-
}
|
|
74
|
-
} else if (options.length !== 1) return;
|
|
75
|
-
}
|
|
76
|
-
if (!options?.find((option) => {
|
|
77
|
-
if (typeof option === "string") return option === currentValue;
|
|
78
|
-
else if (isCategory(option)) return option.options.some((subOption) => {
|
|
79
|
-
return subOption.value === currentValue;
|
|
80
|
-
});
|
|
81
|
-
return option.value === currentValue;
|
|
82
|
-
}) || autoselect) {
|
|
83
|
-
let val;
|
|
84
|
-
for (const option of options) if (typeof option === "string") {
|
|
85
|
-
val = option;
|
|
86
|
-
break;
|
|
87
|
-
} else if (isCategory(option)) {
|
|
88
|
-
const enabled = option.options.find((o) => !o.disabled);
|
|
89
|
-
if (enabled) {
|
|
90
|
-
val = enabled.value;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
} else if (!option.disabled) {
|
|
94
|
-
val = option.value;
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
if (val !== void 0) handleChange(val);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
syncAutoselect(options, autoselect);
|
|
102
|
-
}, [options, autoselect]);
|
|
103
|
-
return /* @__PURE__ */ jsx(Dropdown, {
|
|
104
|
-
...controlProps,
|
|
105
|
-
textBoxClassName: cx(className, invalid && "invalid"),
|
|
106
|
-
ariaLabel,
|
|
107
|
-
required,
|
|
108
|
-
onChange: (val) => handleChange(val),
|
|
109
|
-
value: options?.length === 0 && !allowCustomValue ? value : currentValue,
|
|
110
|
-
options,
|
|
111
|
-
placeholder,
|
|
112
|
-
disabled,
|
|
113
|
-
loading,
|
|
114
|
-
allowCustomValue,
|
|
115
|
-
customValueLabel
|
|
116
|
-
});
|
|
117
|
-
}, arePropsEqual);
|
|
118
|
-
//#endregion
|
|
119
|
-
export { FormikCustomDropdown_default as default };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
type InputValue = string | number | undefined;
|
|
2
|
-
export default function FormikCustomInput({ name, type, step, placeholder, onChange, disabled, min, max, sanitize, invalid, lowercase, minLength, maxLength, defaultValue, value, }: {
|
|
3
|
-
name: string;
|
|
4
|
-
type: 'string' | 'number' | 'password';
|
|
5
|
-
placeholder?: string;
|
|
6
|
-
onChange?: (val: InputValue) => void;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
step?: number | undefined;
|
|
9
|
-
min?: number | undefined;
|
|
10
|
-
max?: number | undefined;
|
|
11
|
-
sanitize?: string | undefined;
|
|
12
|
-
invalid?: boolean;
|
|
13
|
-
lowercase?: boolean | undefined;
|
|
14
|
-
minLength?: number | undefined;
|
|
15
|
-
maxLength?: number | undefined;
|
|
16
|
-
defaultValue?: InputValue;
|
|
17
|
-
value?: InputValue;
|
|
18
|
-
}): import("react").JSX.Element;
|
|
19
|
-
export {};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { LuEye } from "../../icons/lu/LuEye.js";
|
|
2
|
-
import { LuEyeOff } from "../../icons/lu/LuEyeOff.js";
|
|
3
|
-
import { useFieldControlProps, useFieldRequired } from "../fieldContext.js";
|
|
4
|
-
import cx from "classnames";
|
|
5
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { useField, useFormikContext } from "formik";
|
|
8
|
-
//#region src/form/SpecialTypes/FormikCustomInput.tsx
|
|
9
|
-
var DEBOUNCE_MS = 500;
|
|
10
|
-
function FormikCustomInput({ name, type, step, placeholder, onChange, disabled, min, max, sanitize, invalid = false, lowercase = false, minLength, maxLength, defaultValue = "", value }) {
|
|
11
|
-
const [field] = useField(name);
|
|
12
|
-
const required = useFieldRequired();
|
|
13
|
-
const controlProps = useFieldControlProps();
|
|
14
|
-
const { setFieldValue, setFieldTouched } = useFormikContext();
|
|
15
|
-
const [showPassword, setShowPassword] = useState(false);
|
|
16
|
-
const isPassword = type === "password";
|
|
17
|
-
const [localValue, setLocalValue] = useState(value ?? field.value);
|
|
18
|
-
const isFocused = useRef(false);
|
|
19
|
-
const debounceRef = useRef(null);
|
|
20
|
-
const pendingRef = useRef(null);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (!isFocused.current) setLocalValue(value ?? field.value);
|
|
23
|
-
}, [field.value, value]);
|
|
24
|
-
const sanitizeRegexp = useMemo(() => {
|
|
25
|
-
if (sanitize === void 0) return;
|
|
26
|
-
try {
|
|
27
|
-
return new RegExp(sanitize, "g");
|
|
28
|
-
} catch {
|
|
29
|
-
console.error("Invalid regex for sanitization:", sanitize);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}, [sanitize]);
|
|
33
|
-
const sanitizeName = useCallback((val) => {
|
|
34
|
-
const cased = lowercase ? val.toLowerCase() : val;
|
|
35
|
-
return sanitizeRegexp ? cased.replace(sanitizeRegexp, "") : cased;
|
|
36
|
-
}, [sanitizeRegexp, lowercase]);
|
|
37
|
-
const flushToFormik = useCallback((val) => {
|
|
38
|
-
pendingRef.current = null;
|
|
39
|
-
onChange?.(val);
|
|
40
|
-
setFieldTouched(name, true);
|
|
41
|
-
setFieldValue(name, val);
|
|
42
|
-
}, [
|
|
43
|
-
name,
|
|
44
|
-
onChange,
|
|
45
|
-
setFieldTouched,
|
|
46
|
-
setFieldValue
|
|
47
|
-
]);
|
|
48
|
-
useEffect(() => () => {
|
|
49
|
-
clearTimeout(debounceRef.current ?? void 0);
|
|
50
|
-
if (pendingRef.current) flushToFormik(pendingRef.current.value);
|
|
51
|
-
}, [flushToFormik]);
|
|
52
|
-
const handleChange = (e) => {
|
|
53
|
-
const text = sanitizeName(e.target.value);
|
|
54
|
-
let val = text;
|
|
55
|
-
if (type === "number") {
|
|
56
|
-
const parsed = parseFloat(text);
|
|
57
|
-
val = Number.isNaN(parsed) ? void 0 : parsed;
|
|
58
|
-
}
|
|
59
|
-
if (type === "password" && val === "") val = defaultValue;
|
|
60
|
-
setLocalValue(val);
|
|
61
|
-
clearTimeout(debounceRef.current ?? void 0);
|
|
62
|
-
pendingRef.current = { value: val };
|
|
63
|
-
debounceRef.current = setTimeout(() => flushToFormik(val), DEBOUNCE_MS);
|
|
64
|
-
};
|
|
65
|
-
const handleFocus = () => {
|
|
66
|
-
isFocused.current = true;
|
|
67
|
-
};
|
|
68
|
-
const handleBlur = () => {
|
|
69
|
-
isFocused.current = false;
|
|
70
|
-
clearTimeout(debounceRef.current ?? void 0);
|
|
71
|
-
const current = localValue;
|
|
72
|
-
if (current === void 0 || current === null) return;
|
|
73
|
-
const text = current.toString();
|
|
74
|
-
let val = text;
|
|
75
|
-
if (type === "number") {
|
|
76
|
-
const parsed = parseFloat(text);
|
|
77
|
-
if (Number.isNaN(parsed)) val = void 0;
|
|
78
|
-
else if (min !== void 0 && parsed < min) val = min;
|
|
79
|
-
else if (max !== void 0 && parsed > max) val = max;
|
|
80
|
-
else val = parsed;
|
|
81
|
-
}
|
|
82
|
-
setLocalValue(val);
|
|
83
|
-
flushToFormik(val);
|
|
84
|
-
};
|
|
85
|
-
const displayValue = isPassword && localValue === defaultValue ? "" : localValue ?? "";
|
|
86
|
-
const resolvedType = isPassword ? showPassword ? "text" : "password" : type === "string" ? "text" : type;
|
|
87
|
-
const input = /* @__PURE__ */ jsx("input", {
|
|
88
|
-
...controlProps,
|
|
89
|
-
"data-1p-ignore": true,
|
|
90
|
-
className: cx("w-full", disabled && "disabled", invalid && "invalid", isPassword && "pr-8"),
|
|
91
|
-
name,
|
|
92
|
-
value: displayValue,
|
|
93
|
-
type: resolvedType,
|
|
94
|
-
"aria-required": required || void 0,
|
|
95
|
-
disabled,
|
|
96
|
-
placeholder,
|
|
97
|
-
minLength,
|
|
98
|
-
maxLength,
|
|
99
|
-
onChange: handleChange,
|
|
100
|
-
onFocus: handleFocus,
|
|
101
|
-
onBlur: handleBlur,
|
|
102
|
-
min,
|
|
103
|
-
max,
|
|
104
|
-
step
|
|
105
|
-
});
|
|
106
|
-
if (!isPassword) return input;
|
|
107
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
108
|
-
className: "relative w-full",
|
|
109
|
-
children: [input, /* @__PURE__ */ jsx("button", {
|
|
110
|
-
type: "button",
|
|
111
|
-
className: "absolute right-2 top-1/2 -translate-y-1/2 theme-muted-text",
|
|
112
|
-
onClick: () => setShowPassword((prev) => !prev),
|
|
113
|
-
disabled,
|
|
114
|
-
tabIndex: -1,
|
|
115
|
-
"aria-label": showPassword ? "Hide value" : "Show value",
|
|
116
|
-
children: showPassword ? /* @__PURE__ */ jsx(LuEyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(LuEye, { className: "h-4 w-4" })
|
|
117
|
-
})]
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { FormikCustomInput as default };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ICategory, IOptions } from '../../components/dropdownUtils.js';
|
|
2
|
-
import type { TSetFormDirty } from '../Form.js';
|
|
3
|
-
export default function FormikMultiSelectDropdown<T>({ name, options, setFormDirty, onChange, disabled, loading, invalid, placeholder, compareBy, }: {
|
|
4
|
-
name: string;
|
|
5
|
-
options: (ICategory<T> | IOptions<T>)[];
|
|
6
|
-
setFormDirty: TSetFormDirty;
|
|
7
|
-
onChange?: ((val: T[]) => void) | undefined;
|
|
8
|
-
disabled?: boolean;
|
|
9
|
-
loading?: boolean;
|
|
10
|
-
invalid?: boolean;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
compareBy?: (a: T, b: T) => boolean;
|
|
13
|
-
}): import("react").JSX.Element;
|