@ayasofyazilim/ui 0.0.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/__mocks__/canvas.ts +8 -0
- package/components.json +21 -0
- package/eslint.config.js +4 -0
- package/jest-environment.js +37 -0
- package/jest.config.ts +47 -0
- package/jest.setup.ts +69 -0
- package/package.json +124 -0
- package/postcss.config.mjs +6 -0
- package/src/aria/index.tsx +1 -0
- package/src/aria/number-field.tsx +41 -0
- package/src/components/.gitkeep +0 -0
- package/src/components/accordion.tsx +66 -0
- package/src/components/alert-dialog.tsx +157 -0
- package/src/components/alert.tsx +70 -0
- package/src/components/aspect-ratio.tsx +11 -0
- package/src/components/avatar.tsx +53 -0
- package/src/components/badge.tsx +67 -0
- package/src/components/breadcrumb.tsx +109 -0
- package/src/components/button-group.tsx +83 -0
- package/src/components/button.tsx +68 -0
- package/src/components/calendar.tsx +219 -0
- package/src/components/card.tsx +92 -0
- package/src/components/carousel.tsx +241 -0
- package/src/components/chart.tsx +363 -0
- package/src/components/checkbox.tsx +32 -0
- package/src/components/collapsible.tsx +33 -0
- package/src/components/command.tsx +184 -0
- package/src/components/context-menu.tsx +252 -0
- package/src/components/dialog.tsx +144 -0
- package/src/components/drawer.tsx +135 -0
- package/src/components/dropdown-menu.tsx +258 -0
- package/src/components/empty.tsx +100 -0
- package/src/components/field.tsx +248 -0
- package/src/components/form.tsx +169 -0
- package/src/components/hover-card.tsx +44 -0
- package/src/components/input-group.tsx +170 -0
- package/src/components/input-otp.tsx +77 -0
- package/src/components/input.tsx +21 -0
- package/src/components/item.tsx +193 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +24 -0
- package/src/components/menubar.tsx +276 -0
- package/src/components/navigation-menu.tsx +168 -0
- package/src/components/pagination.tsx +130 -0
- package/src/components/popover.tsx +88 -0
- package/src/components/progress.tsx +31 -0
- package/src/components/radio-group.tsx +45 -0
- package/src/components/resizable.tsx +56 -0
- package/src/components/scroll-area.tsx +58 -0
- package/src/components/select.tsx +189 -0
- package/src/components/separator.tsx +28 -0
- package/src/components/sheet.tsx +140 -0
- package/src/components/sidebar.tsx +862 -0
- package/src/components/skeleton.tsx +13 -0
- package/src/components/slider.tsx +63 -0
- package/src/components/sonner.tsx +40 -0
- package/src/components/spinner.tsx +16 -0
- package/src/components/stepper.tsx +291 -0
- package/src/components/switch.tsx +31 -0
- package/src/components/table.tsx +133 -0
- package/src/components/tabs.tsx +66 -0
- package/src/components/textarea.tsx +18 -0
- package/src/components/toggle-group.tsx +83 -0
- package/src/components/toggle.tsx +47 -0
- package/src/components/tooltip.tsx +66 -0
- package/src/custom/action-button.tsx +48 -0
- package/src/custom/async-select.tsx +287 -0
- package/src/custom/awesome-not-found.tsx +116 -0
- package/src/custom/charts/area-chart.tsx +147 -0
- package/src/custom/charts/bar-chart.tsx +233 -0
- package/src/custom/charts/chart-card.tsx +103 -0
- package/src/custom/charts/index.tsx +16 -0
- package/src/custom/charts/pie-chart.tsx +168 -0
- package/src/custom/charts/radar-chart.tsx +126 -0
- package/src/custom/checkbox-tree.tsx +100 -0
- package/src/custom/combobox.tsx +296 -0
- package/src/custom/confirm-dialog.tsx +102 -0
- package/src/custom/country-selector.tsx +204 -0
- package/src/custom/date-picker/calendar-rac.tsx +109 -0
- package/src/custom/date-picker/datefield-rac.tsx +84 -0
- package/src/custom/date-picker/index.tsx +273 -0
- package/src/custom/date-picker/types/index.ts +4 -0
- package/src/custom/date-picker/utils/index.ts +42 -0
- package/src/custom/date-picker-old.tsx +50 -0
- package/src/custom/date-tooltip.tsx +98 -0
- package/src/custom/document-scanner/consts.ts +5 -0
- package/src/custom/document-scanner/corner-adjustment/action-buttons.tsx +33 -0
- package/src/custom/document-scanner/corner-adjustment/corner-handle.tsx +43 -0
- package/src/custom/document-scanner/corner-adjustment/hooks/use-corner-drag.ts +85 -0
- package/src/custom/document-scanner/corner-adjustment/index.tsx +125 -0
- package/src/custom/document-scanner/corner-adjustment/types.ts +53 -0
- package/src/custom/document-scanner/corner-adjustment/utils/clip-path.ts +22 -0
- package/src/custom/document-scanner/corner-adjustment/zoom-magnifier.tsx +115 -0
- package/src/custom/document-scanner/hooks/use-document-capture.ts +81 -0
- package/src/custom/document-scanner/hooks/use-document-scanner.ts +80 -0
- package/src/custom/document-scanner/hooks/use-perspective-crop.ts +38 -0
- package/src/custom/document-scanner/index.tsx +255 -0
- package/src/custom/document-scanner/lib.ts +407 -0
- package/src/custom/document-scanner/types.ts +205 -0
- package/src/custom/document-scanner/utils/perspective-correction.ts +139 -0
- package/src/custom/document-viewer/controllers.tsx +98 -0
- package/src/custom/document-viewer/index.tsx +43 -0
- package/src/custom/document-viewer/renderers/image.tsx +37 -0
- package/src/custom/document-viewer/renderers/index.tsx +2 -0
- package/src/custom/document-viewer/renderers/pdf.tsx +105 -0
- package/src/custom/email-input/domains.json +159 -0
- package/src/custom/email-input/email.tsx +229 -0
- package/src/custom/email-input/index.tsx +4 -0
- package/src/custom/email-input/types.ts +104 -0
- package/src/custom/file-uploader.tsx +541 -0
- package/src/custom/filter-component/fields/async-select.tsx +33 -0
- package/src/custom/filter-component/fields/date.tsx +60 -0
- package/src/custom/filter-component/fields/multi-select.tsx +30 -0
- package/src/custom/filter-component/index.tsx +217 -0
- package/src/custom/image-canvas.tsx +260 -0
- package/src/custom/json-editor.tsx +22 -0
- package/src/custom/master-data-grid/components/dialogs/column-settings-dialog.tsx +100 -0
- package/src/custom/master-data-grid/components/dialogs/index.ts +1 -0
- package/src/custom/master-data-grid/components/filters/client-filter.tsx +368 -0
- package/src/custom/master-data-grid/components/filters/filter-input.tsx +256 -0
- package/src/custom/master-data-grid/components/filters/index.ts +3 -0
- package/src/custom/master-data-grid/components/filters/inline-column-filter.tsx +233 -0
- package/src/custom/master-data-grid/components/filters/multi-filter-dialog.tsx +90 -0
- package/src/custom/master-data-grid/components/filters/server-filter.tsx +255 -0
- package/src/custom/master-data-grid/components/master-data-grid.tsx +472 -0
- package/src/custom/master-data-grid/components/pagination/index.ts +1 -0
- package/src/custom/master-data-grid/components/pagination/pagination.tsx +178 -0
- package/src/custom/master-data-grid/components/table/cell-renderer.tsx +634 -0
- package/src/custom/master-data-grid/components/table/header-cell.tsx +162 -0
- package/src/custom/master-data-grid/components/table/index.ts +4 -0
- package/src/custom/master-data-grid/components/table/table-body-renderer.tsx +113 -0
- package/src/custom/master-data-grid/components/table/virtual-body.tsx +138 -0
- package/src/custom/master-data-grid/components/toolbar/index.ts +1 -0
- package/src/custom/master-data-grid/components/toolbar/toolbar.tsx +314 -0
- package/src/custom/master-data-grid/hooks/index.ts +3 -0
- package/src/custom/master-data-grid/hooks/use-columns.tsx +332 -0
- package/src/custom/master-data-grid/hooks/use-editing.ts +106 -0
- package/src/custom/master-data-grid/hooks/use-table-state-reducer.ts +157 -0
- package/src/custom/master-data-grid/hooks/use-table-state.ts +31 -0
- package/src/custom/master-data-grid/index.ts +16 -0
- package/src/custom/master-data-grid/types.ts +466 -0
- package/src/custom/master-data-grid/utils/column-generator.tsx +306 -0
- package/src/custom/master-data-grid/utils/export-utils.ts +67 -0
- package/src/custom/master-data-grid/utils/filter-fns.ts +290 -0
- package/src/custom/master-data-grid/utils/index.ts +8 -0
- package/src/custom/master-data-grid/utils/pinning-utils.ts +88 -0
- package/src/custom/master-data-grid/utils/translation-utils.ts +42 -0
- package/src/custom/multi-select.tsx +432 -0
- package/src/custom/password-input.tsx +194 -0
- package/src/custom/phone-input.tsx +172 -0
- package/src/custom/schema-form/custom/index.tsx +1 -0
- package/src/custom/schema-form/custom/label.tsx +53 -0
- package/src/custom/schema-form/fields/base-input-field.tsx +82 -0
- package/src/custom/schema-form/fields/field.tsx +67 -0
- package/src/custom/schema-form/fields/index.tsx +5 -0
- package/src/custom/schema-form/fields/object.tsx +12 -0
- package/src/custom/schema-form/fields/table-array/array-field-item.tsx +90 -0
- package/src/custom/schema-form/fields/table-array/array-field-template.tsx +115 -0
- package/src/custom/schema-form/index.tsx +259 -0
- package/src/custom/schema-form/templates/description.tsx +20 -0
- package/src/custom/schema-form/templates/index.tsx +2 -0
- package/src/custom/schema-form/templates/submit.tsx +32 -0
- package/src/custom/schema-form/types.ts +64 -0
- package/src/custom/schema-form/utils/index.ts +4 -0
- package/src/custom/schema-form/utils/schema-dependency.ts +655 -0
- package/src/custom/schema-form/utils/schemas.ts +289 -0
- package/src/custom/schema-form/utils/validation.ts +23 -0
- package/src/custom/schema-form/widgets/boolean.tsx +77 -0
- package/src/custom/schema-form/widgets/combobox.tsx +274 -0
- package/src/custom/schema-form/widgets/date.tsx +59 -0
- package/src/custom/schema-form/widgets/email.tsx +34 -0
- package/src/custom/schema-form/widgets/index.tsx +10 -0
- package/src/custom/schema-form/widgets/password.tsx +40 -0
- package/src/custom/schema-form/widgets/phone.tsx +40 -0
- package/src/custom/schema-form/widgets/select.tsx +105 -0
- package/src/custom/schema-form/widgets/selectable.tsx +25 -0
- package/src/custom/schema-form/widgets/string-array.tsx +296 -0
- package/src/custom/schema-form/widgets/url.tsx +56 -0
- package/src/custom/section-layout-v2.tsx +212 -0
- package/src/custom/select-tabs.tsx +109 -0
- package/src/custom/selectable.tsx +316 -0
- package/src/custom/stepper.tsx +236 -0
- package/src/custom/tab-layout.tsx +213 -0
- package/src/custom/tanstack-table/fields/index.tsx +12 -0
- package/src/custom/tanstack-table/fields/tanstack-table-action-dialogs.tsx +89 -0
- package/src/custom/tanstack-table/fields/tanstack-table-column-header.tsx +66 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-date.tsx +180 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-faceted.tsx +158 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-text.tsx +76 -0
- package/src/custom/tanstack-table/fields/tanstack-table-pagination.tsx +136 -0
- package/src/custom/tanstack-table/fields/tanstack-table-plain-table.tsx +142 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions-confirmation.tsx +77 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions-custom-dialog.tsx +87 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions.tsx +151 -0
- package/src/custom/tanstack-table/fields/tanstack-table-table-actions-custom-dialog.tsx +88 -0
- package/src/custom/tanstack-table/fields/tanstack-table-table-actions-schemaform-dialog.tsx +47 -0
- package/src/custom/tanstack-table/fields/tanstack-table-toolbar.tsx +143 -0
- package/src/custom/tanstack-table/fields/tanstack-table-view-options.tsx +171 -0
- package/src/custom/tanstack-table/index.tsx +244 -0
- package/src/custom/tanstack-table/types/index.ts +328 -0
- package/src/custom/tanstack-table/utils/cell-with-actions.tsx +21 -0
- package/src/custom/tanstack-table/utils/column-names.ts +26 -0
- package/src/custom/tanstack-table/utils/columns-by-row-data.tsx +312 -0
- package/src/custom/tanstack-table/utils/editable-columns-by-row-data.tsx +219 -0
- package/src/custom/tanstack-table/utils/faceted-boolean-options.tsx +22 -0
- package/src/custom/tanstack-table/utils/index.tsx +10 -0
- package/src/custom/tanstack-table/utils/pinning-styles.ts +57 -0
- package/src/custom/tanstack-table/utils/table.tsx +83 -0
- package/src/custom/tanstack-table/utils/test-conditions.ts +17 -0
- package/src/custom/timeline.tsx +208 -0
- package/src/custom/tree.tsx +200 -0
- package/src/custom/tscanify/browser.ts +66 -0
- package/src/custom/tscanify/index.ts +51 -0
- package/src/custom/tscanify/tscanify-browser.ts +522 -0
- package/src/custom/tscanify/tscanify.ts +262 -0
- package/src/custom/tscanify/types.ts +22 -0
- package/src/custom/webcam.tsx +737 -0
- package/src/hooks/.gitkeep +0 -0
- package/src/hooks/use-callback-ref.ts +27 -0
- package/src/hooks/use-controllable-state.ts +67 -0
- package/src/hooks/use-debounce.ts +19 -0
- package/src/hooks/use-is-visible.ts +23 -0
- package/src/hooks/use-media-query.ts +21 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/hooks/use-on-window-resize.ts +15 -0
- package/src/hooks/use-scroll.tsx +22 -0
- package/src/lib/utils.ts +61 -0
- package/src/lib/zod.ts +2 -0
- package/src/styles/core.css +57 -0
- package/src/styles/globals.css +130 -0
- package/src/test/email-input.test.tsx +217 -0
- package/src/test/password-input.test.tsx +92 -0
- package/src/test/select-tabs.test.tsx +302 -0
- package/src/test/selectable.test.tsx +1093 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lint.json +8 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Button } from "@repo/ayasofyazilim-ui/components/button";
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
TableBody,
|
|
5
|
+
TableCaption,
|
|
6
|
+
TableHead,
|
|
7
|
+
TableHeader,
|
|
8
|
+
TableRow,
|
|
9
|
+
} from "@repo/ayasofyazilim-ui/components/table";
|
|
10
|
+
import { cn } from "@repo/ayasofyazilim-ui/lib/utils";
|
|
11
|
+
import {
|
|
12
|
+
ArrayFieldTemplateProps,
|
|
13
|
+
buttonId,
|
|
14
|
+
getTemplate,
|
|
15
|
+
getUiOptions,
|
|
16
|
+
} from "@rjsf/utils";
|
|
17
|
+
import { PlusCircle } from "lucide-react";
|
|
18
|
+
|
|
19
|
+
export function ArrayFieldTemplate(props: ArrayFieldTemplateProps) {
|
|
20
|
+
const {
|
|
21
|
+
canAdd,
|
|
22
|
+
disabled,
|
|
23
|
+
fieldPathId,
|
|
24
|
+
uiSchema,
|
|
25
|
+
items,
|
|
26
|
+
optionalDataControl,
|
|
27
|
+
onAddClick,
|
|
28
|
+
readonly,
|
|
29
|
+
registry,
|
|
30
|
+
required,
|
|
31
|
+
schema,
|
|
32
|
+
title,
|
|
33
|
+
} = props;
|
|
34
|
+
const uiOptions = getUiOptions(uiSchema);
|
|
35
|
+
const ArrayFieldDescriptionTemplate = getTemplate(
|
|
36
|
+
"ArrayFieldDescriptionTemplate",
|
|
37
|
+
registry,
|
|
38
|
+
uiOptions
|
|
39
|
+
);
|
|
40
|
+
const ArrayFieldTitleTemplate = getTemplate(
|
|
41
|
+
"ArrayFieldTitleTemplate",
|
|
42
|
+
registry,
|
|
43
|
+
uiOptions
|
|
44
|
+
);
|
|
45
|
+
const showOptionalDataControlInTitle = !readonly && !disabled;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className="border rounded-md overflow-hidden">
|
|
49
|
+
<Table key={`array-item-list-${fieldPathId.$id}`} className="caption-top">
|
|
50
|
+
{!showOptionalDataControlInTitle ? optionalDataControl : undefined}
|
|
51
|
+
<TableCaption className="border-b mt-0 [&_h5]:font-medium [&_h5]:text-black **:data-[slot=separator]:hidden">
|
|
52
|
+
<ArrayFieldTitleTemplate
|
|
53
|
+
fieldPathId={fieldPathId}
|
|
54
|
+
title={uiOptions.title || title}
|
|
55
|
+
schema={schema}
|
|
56
|
+
uiSchema={uiSchema}
|
|
57
|
+
required={required}
|
|
58
|
+
registry={registry}
|
|
59
|
+
optionalDataControl={
|
|
60
|
+
showOptionalDataControlInTitle ? optionalDataControl : undefined
|
|
61
|
+
}
|
|
62
|
+
/>
|
|
63
|
+
<ArrayFieldDescriptionTemplate
|
|
64
|
+
fieldPathId={fieldPathId}
|
|
65
|
+
description={uiOptions.description || schema.description}
|
|
66
|
+
schema={schema}
|
|
67
|
+
uiSchema={uiSchema}
|
|
68
|
+
registry={registry}
|
|
69
|
+
/>
|
|
70
|
+
</TableCaption>
|
|
71
|
+
<TableHeader>
|
|
72
|
+
<TableRow className="divide-x">
|
|
73
|
+
{Object.keys(
|
|
74
|
+
(schema?.items as { properties: Record<string, string> })
|
|
75
|
+
?.properties || {}
|
|
76
|
+
).map((item) => {
|
|
77
|
+
const itemsUiSchema =
|
|
78
|
+
typeof uiSchema?.items === "function"
|
|
79
|
+
? undefined
|
|
80
|
+
: (uiSchema?.items as
|
|
81
|
+
| Record<string, { "ui:title": string }>
|
|
82
|
+
| undefined);
|
|
83
|
+
const title =
|
|
84
|
+
itemsUiSchema?.[item as string]?.["ui:title"] || item;
|
|
85
|
+
return (
|
|
86
|
+
<TableHead
|
|
87
|
+
key={item}
|
|
88
|
+
className={cn("h-9", !canAdd && "nth-last-2:border-0!")}
|
|
89
|
+
>
|
|
90
|
+
{title}
|
|
91
|
+
</TableHead>
|
|
92
|
+
);
|
|
93
|
+
})}
|
|
94
|
+
<TableHead className={cn("p-0 size-9")}>
|
|
95
|
+
{canAdd && (
|
|
96
|
+
<Button
|
|
97
|
+
id={buttonId(fieldPathId, "add")}
|
|
98
|
+
onClick={onAddClick}
|
|
99
|
+
disabled={disabled || readonly}
|
|
100
|
+
className="rounded-none h-full"
|
|
101
|
+
variant="ghost"
|
|
102
|
+
>
|
|
103
|
+
<PlusCircle className="size-4" />
|
|
104
|
+
</Button>
|
|
105
|
+
)}
|
|
106
|
+
</TableHead>
|
|
107
|
+
</TableRow>
|
|
108
|
+
</TableHeader>
|
|
109
|
+
<TableBody className="[&_tr:last-child>td]:rounded-md">
|
|
110
|
+
{items}
|
|
111
|
+
</TableBody>
|
|
112
|
+
</Table>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { lodash } from "@repo/ayasofyazilim-ui/lib/utils";
|
|
4
|
+
import { Form } from "@rjsf/shadcn";
|
|
5
|
+
import { customizeValidator } from "@rjsf/validator-ajv8";
|
|
6
|
+
import type { RJSFValidationError, FormValidation } from "@rjsf/utils";
|
|
7
|
+
import { useCallback, useMemo } from "react";
|
|
8
|
+
import {
|
|
9
|
+
ArrayFieldItemTemplate,
|
|
10
|
+
ArrayFieldTemplate,
|
|
11
|
+
BaseInputTemplate,
|
|
12
|
+
FieldTemplate,
|
|
13
|
+
ObjectFieldTemplate,
|
|
14
|
+
} from "./fields";
|
|
15
|
+
import { DescriptionFieldTemplate, SubmitButton } from "./templates";
|
|
16
|
+
import { SchemaFormProps } from "./types";
|
|
17
|
+
import {
|
|
18
|
+
createSchemaWithFilters,
|
|
19
|
+
removeFieldsfromGenericSchema,
|
|
20
|
+
isValueEmpty,
|
|
21
|
+
cleanFormDataForSubmit,
|
|
22
|
+
cleanHiddenFieldsFromFormData,
|
|
23
|
+
createRuntimeValidator,
|
|
24
|
+
createDynamicSchema,
|
|
25
|
+
applyFieldDependencies,
|
|
26
|
+
} from "./utils";
|
|
27
|
+
import {
|
|
28
|
+
CheckboxWidget,
|
|
29
|
+
DateTimeWidget,
|
|
30
|
+
DateWidget,
|
|
31
|
+
EmailInputWidget,
|
|
32
|
+
PasswordInputWidget,
|
|
33
|
+
PhoneWithParseWidget,
|
|
34
|
+
PhoneWithValueWidget,
|
|
35
|
+
SelectWidget,
|
|
36
|
+
SwitchWidget,
|
|
37
|
+
URLInputWidget,
|
|
38
|
+
} from "./widgets";
|
|
39
|
+
|
|
40
|
+
export * from "./custom";
|
|
41
|
+
export * from "./types";
|
|
42
|
+
export * from "./utils";
|
|
43
|
+
export * from "./widgets";
|
|
44
|
+
|
|
45
|
+
const INTERNAL_WIDGETS = {
|
|
46
|
+
switch: SwitchWidget,
|
|
47
|
+
checkbox: CheckboxWidget,
|
|
48
|
+
date: DateWidget,
|
|
49
|
+
"date-time": DateTimeWidget,
|
|
50
|
+
email: EmailInputWidget,
|
|
51
|
+
password: PasswordInputWidget,
|
|
52
|
+
phone: PhoneWithValueWidget,
|
|
53
|
+
"phone-with-parse": PhoneWithParseWidget,
|
|
54
|
+
select: SelectWidget,
|
|
55
|
+
url: URLInputWidget,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const INTERNAL_TEMPLATES = {
|
|
59
|
+
ObjectFieldTemplate,
|
|
60
|
+
BaseInputTemplate,
|
|
61
|
+
FieldTemplate,
|
|
62
|
+
DescriptionFieldTemplate,
|
|
63
|
+
ButtonTemplates: { SubmitButton },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const FIELDS_TO_REMOVE = ["extraProperties", "additionalProperties"];
|
|
67
|
+
|
|
68
|
+
export function SchemaForm<T = any>(props: SchemaFormProps<T>) {
|
|
69
|
+
const {
|
|
70
|
+
validator: customValidator,
|
|
71
|
+
schema: originalSchema,
|
|
72
|
+
widgets,
|
|
73
|
+
fields,
|
|
74
|
+
templates,
|
|
75
|
+
filter,
|
|
76
|
+
useTableForArrayFields = false,
|
|
77
|
+
formData,
|
|
78
|
+
transformErrors: userTransformErrors,
|
|
79
|
+
runtimeDependencyConfig,
|
|
80
|
+
fieldDependencies,
|
|
81
|
+
onSubmit: userOnSubmit,
|
|
82
|
+
customValidate: userCustomValidate,
|
|
83
|
+
...restProps
|
|
84
|
+
} = props;
|
|
85
|
+
|
|
86
|
+
const validatorToUse = useMemo(() => {
|
|
87
|
+
if (customValidator) return customValidator;
|
|
88
|
+
|
|
89
|
+
return customizeValidator({
|
|
90
|
+
ajvOptionsOverrides: {
|
|
91
|
+
removeAdditional: true,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}, [customValidator]);
|
|
95
|
+
|
|
96
|
+
const processedSchema = useMemo(() => {
|
|
97
|
+
let schema = originalSchema;
|
|
98
|
+
|
|
99
|
+
if (fieldDependencies) {
|
|
100
|
+
schema = applyFieldDependencies(schema, fieldDependencies);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (runtimeDependencyConfig && formData) {
|
|
104
|
+
schema = createDynamicSchema(
|
|
105
|
+
schema,
|
|
106
|
+
runtimeDependencyConfig,
|
|
107
|
+
formData as Record<string, unknown>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (filter) {
|
|
112
|
+
schema = createSchemaWithFilters({
|
|
113
|
+
filter,
|
|
114
|
+
schema,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return removeFieldsfromGenericSchema(schema, FIELDS_TO_REMOVE);
|
|
118
|
+
}, [
|
|
119
|
+
originalSchema,
|
|
120
|
+
filter,
|
|
121
|
+
runtimeDependencyConfig,
|
|
122
|
+
formData,
|
|
123
|
+
fieldDependencies,
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
const transformErrors = useCallback(
|
|
127
|
+
(errors: RJSFValidationError[]): RJSFValidationError[] => {
|
|
128
|
+
const errorsToFilterWhenEmpty = ["format", "minLength", "pattern"];
|
|
129
|
+
|
|
130
|
+
let filteredErrors = errors.filter((error) => {
|
|
131
|
+
if (!error.name || !errorsToFilterWhenEmpty.includes(error.name))
|
|
132
|
+
return true;
|
|
133
|
+
|
|
134
|
+
const path = (error.property || "")
|
|
135
|
+
.replace(/^\./, "")
|
|
136
|
+
.split(".")
|
|
137
|
+
.filter(Boolean);
|
|
138
|
+
|
|
139
|
+
if (path.length === 0 || !formData) return true;
|
|
140
|
+
|
|
141
|
+
let value: unknown = formData;
|
|
142
|
+
for (const key of path) {
|
|
143
|
+
if (value && typeof value === "object" && key in value) {
|
|
144
|
+
value = (value as Record<string, unknown>)[key];
|
|
145
|
+
} else {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return !isValueEmpty(value);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (userTransformErrors) {
|
|
154
|
+
filteredErrors = userTransformErrors(filteredErrors, {} as any);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return filteredErrors;
|
|
158
|
+
},
|
|
159
|
+
[formData, userTransformErrors]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const combinedCustomValidate = useCallback(
|
|
163
|
+
(formDataToValidate: T, errors: FormValidation<T>): FormValidation<T> => {
|
|
164
|
+
let validationErrors = errors;
|
|
165
|
+
|
|
166
|
+
if (runtimeDependencyConfig) {
|
|
167
|
+
const runtimeValidator = createRuntimeValidator(
|
|
168
|
+
runtimeDependencyConfig
|
|
169
|
+
);
|
|
170
|
+
validationErrors = runtimeValidator(
|
|
171
|
+
formDataToValidate as Record<string, unknown>,
|
|
172
|
+
validationErrors as FormValidation<Record<string, unknown>>
|
|
173
|
+
) as FormValidation<T>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (userCustomValidate) {
|
|
177
|
+
validationErrors = userCustomValidate(
|
|
178
|
+
formDataToValidate,
|
|
179
|
+
validationErrors
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return validationErrors;
|
|
184
|
+
},
|
|
185
|
+
[runtimeDependencyConfig, userCustomValidate]
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const memoizedWidgets = useMemo(
|
|
189
|
+
() => lodash.merge(INTERNAL_WIDGETS, widgets),
|
|
190
|
+
[widgets]
|
|
191
|
+
);
|
|
192
|
+
const memoizedFields = useMemo(() => fields, [fields]);
|
|
193
|
+
const memoizedTemplates = useMemo(() => {
|
|
194
|
+
return lodash.merge(
|
|
195
|
+
INTERNAL_TEMPLATES,
|
|
196
|
+
templates,
|
|
197
|
+
useTableForArrayFields
|
|
198
|
+
? { ArrayFieldItemTemplate, ArrayFieldTemplate }
|
|
199
|
+
: {}
|
|
200
|
+
);
|
|
201
|
+
}, [templates]);
|
|
202
|
+
|
|
203
|
+
const handleSubmit = useCallback(
|
|
204
|
+
(
|
|
205
|
+
data: Parameters<NonNullable<typeof userOnSubmit>>[0],
|
|
206
|
+
event: React.FormEvent<HTMLFormElement>
|
|
207
|
+
) => {
|
|
208
|
+
if (!userOnSubmit) return;
|
|
209
|
+
|
|
210
|
+
let submitData = data;
|
|
211
|
+
let cleanedFormData = data.formData as T;
|
|
212
|
+
|
|
213
|
+
if (fieldDependencies && cleanedFormData) {
|
|
214
|
+
cleanedFormData = cleanHiddenFieldsFromFormData(
|
|
215
|
+
cleanedFormData as Record<string, unknown>,
|
|
216
|
+
fieldDependencies
|
|
217
|
+
) as T;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (runtimeDependencyConfig && cleanedFormData) {
|
|
221
|
+
cleanedFormData = cleanFormDataForSubmit(
|
|
222
|
+
cleanedFormData as Record<string, unknown>,
|
|
223
|
+
runtimeDependencyConfig
|
|
224
|
+
) as T;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (fieldDependencies || runtimeDependencyConfig) {
|
|
228
|
+
submitData = { ...data, formData: cleanedFormData };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
userOnSubmit(submitData, event);
|
|
232
|
+
},
|
|
233
|
+
[userOnSubmit, runtimeDependencyConfig, fieldDependencies]
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<Form
|
|
238
|
+
{...restProps}
|
|
239
|
+
customValidate={
|
|
240
|
+
runtimeDependencyConfig || userCustomValidate
|
|
241
|
+
? combinedCustomValidate
|
|
242
|
+
: undefined
|
|
243
|
+
}
|
|
244
|
+
formContext={{
|
|
245
|
+
useTableForArrayFields,
|
|
246
|
+
}}
|
|
247
|
+
formData={formData}
|
|
248
|
+
onSubmit={handleSubmit}
|
|
249
|
+
schema={processedSchema}
|
|
250
|
+
transformErrors={transformErrors}
|
|
251
|
+
validator={validatorToUse}
|
|
252
|
+
widgets={memoizedWidgets}
|
|
253
|
+
fields={memoizedFields}
|
|
254
|
+
templates={memoizedTemplates}
|
|
255
|
+
noHtml5Validate={restProps.noHtml5Validate ?? true}
|
|
256
|
+
showErrorList={restProps.showErrorList ?? false}
|
|
257
|
+
/>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Tooltip,
|
|
3
|
+
TooltipTrigger,
|
|
4
|
+
TooltipContent,
|
|
5
|
+
} from "@repo/ayasofyazilim-ui/components/tooltip";
|
|
6
|
+
import { DescriptionFieldProps } from "@rjsf/utils";
|
|
7
|
+
import { InfoIcon, MessageCircleQuestion } from "lucide-react";
|
|
8
|
+
|
|
9
|
+
export function DescriptionFieldTemplate(props: DescriptionFieldProps) {
|
|
10
|
+
const { description, id } = props;
|
|
11
|
+
if (!description) return null;
|
|
12
|
+
return (
|
|
13
|
+
<Tooltip>
|
|
14
|
+
<TooltipTrigger id={id} type="button">
|
|
15
|
+
<InfoIcon className="size-3.5 ml-1 text-muted-foreground cursor-help" />
|
|
16
|
+
</TooltipTrigger>
|
|
17
|
+
<TooltipContent>{description}</TooltipContent>
|
|
18
|
+
</Tooltip>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
getSubmitButtonOptions,
|
|
4
|
+
SubmitButtonProps,
|
|
5
|
+
UISchemaSubmitButtonOptions,
|
|
6
|
+
} from "@rjsf/utils";
|
|
7
|
+
import { Button } from "@repo/ayasofyazilim-ui/components/button";
|
|
8
|
+
import { cn } from "@repo/ayasofyazilim-ui/lib/utils";
|
|
9
|
+
|
|
10
|
+
export function SubmitButton(props: SubmitButtonProps) {
|
|
11
|
+
const { uiSchema } = props;
|
|
12
|
+
const {
|
|
13
|
+
norender,
|
|
14
|
+
props: options,
|
|
15
|
+
disabled,
|
|
16
|
+
submitText,
|
|
17
|
+
}: UISchemaSubmitButtonOptions & {
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
} = getSubmitButtonOptions(uiSchema);
|
|
20
|
+
if (norender) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return (
|
|
24
|
+
<Button
|
|
25
|
+
type="submit"
|
|
26
|
+
className={cn("w-full mt-3", options?.className)}
|
|
27
|
+
disabled={options?.disabled || disabled}
|
|
28
|
+
>
|
|
29
|
+
{submitText || "Submit"}
|
|
30
|
+
</Button>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { FormProps, IChangeEvent } from "@rjsf/core";
|
|
2
|
+
import { GenericObjectType as _GenericObjectType } from "@rjsf/utils";
|
|
3
|
+
import { UiSchema as BaseUiSchema } from "@rjsf/utils";
|
|
4
|
+
import type {
|
|
5
|
+
RuntimeDependencyConfig,
|
|
6
|
+
DependencyConfig,
|
|
7
|
+
} from "./utils/schema-dependency";
|
|
8
|
+
export type GenericObjectType = _GenericObjectType;
|
|
9
|
+
export type {
|
|
10
|
+
FieldProps,
|
|
11
|
+
ArrayFieldItemTemplateProps,
|
|
12
|
+
ArrayFieldTemplateProps,
|
|
13
|
+
FieldTemplateProps,
|
|
14
|
+
ObjectFieldTemplateProps,
|
|
15
|
+
TemplatesType,
|
|
16
|
+
WidgetProps,
|
|
17
|
+
RJSFSchema,
|
|
18
|
+
StrictRJSFSchema,
|
|
19
|
+
} from "@rjsf/utils";
|
|
20
|
+
|
|
21
|
+
export type SchemaFormProps<T = any> = Omit<
|
|
22
|
+
FormProps<T>,
|
|
23
|
+
"validator" | "schema" | "uiSchema"
|
|
24
|
+
> & {
|
|
25
|
+
schema: _GenericObjectType;
|
|
26
|
+
validator?: FormProps<T>["validator"];
|
|
27
|
+
uiSchema?: UiSchema | UiSchema<T>;
|
|
28
|
+
filter?: FilterType<T>;
|
|
29
|
+
useTableForArrayFields?: boolean;
|
|
30
|
+
runtimeDependencyConfig?: RuntimeDependencyConfig;
|
|
31
|
+
fieldDependencies?: DependencyConfig;
|
|
32
|
+
};
|
|
33
|
+
export type RJSFChangeEvent<T = any> = IChangeEvent<T>;
|
|
34
|
+
|
|
35
|
+
export type CreateFieldConfigWithResourceProps = {
|
|
36
|
+
extend?: _GenericObjectType;
|
|
37
|
+
name?: string;
|
|
38
|
+
resources: _GenericObjectType;
|
|
39
|
+
schema: _GenericObjectType;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type UiSchema<T = unknown> = BaseUiSchema<T>;
|
|
43
|
+
|
|
44
|
+
export type CommonFilterType<T> = {
|
|
45
|
+
keys: Array<keyof Partial<T> | string>;
|
|
46
|
+
};
|
|
47
|
+
export type FilterType<T> = CommonFilterType<T> & {
|
|
48
|
+
type: "include" | "exclude" | "fullExclude";
|
|
49
|
+
};
|
|
50
|
+
export type CreateSchemaWithFilters<T> = {
|
|
51
|
+
filter: FilterType<T>;
|
|
52
|
+
name?: string;
|
|
53
|
+
schema: _GenericObjectType;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type FilteredObject<T> = {
|
|
57
|
+
[K in keyof T]: T[K] extends object
|
|
58
|
+
? T[K] extends Array<any>
|
|
59
|
+
? T[K] // Keep arrays as they are
|
|
60
|
+
: FilteredObject<T[K]>
|
|
61
|
+
: T[K] extends undefined
|
|
62
|
+
? never
|
|
63
|
+
: T[K];
|
|
64
|
+
};
|