dinocollab-core 2.2.55 → 2.2.56
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 +1 -23
- package/dist/data-surface/index.js +1 -1
- package/dist/filter-bar/index.js +1 -1
- package/dist/src/data-surface/button-switch.js +1 -1
- package/dist/src/data-surface/button-switch.js.map +1 -1
- package/dist/src/data-surface/index.create.js +1 -1
- package/dist/src/data-surface/index.create.js.map +1 -1
- package/dist/src/data-surface/index.dino.js +1 -1
- package/dist/src/data-surface/index.dino.js.map +1 -1
- package/dist/src/data-surface/ui.units.js +1 -1
- package/dist/src/data-surface/ui.units.js.map +1 -1
- package/dist/src/data-surface/view-grid/index.js +1 -1
- package/dist/src/data-surface/view-grid/index.js.map +1 -1
- package/dist/src/data-surface/view-list/column-selector.js +2 -0
- package/dist/src/data-surface/view-list/column-selector.js.map +1 -0
- package/dist/src/data-surface/view-list/helpers.js +1 -1
- package/dist/src/data-surface/view-list/helpers.js.map +1 -1
- package/dist/src/data-surface/view-list/hooks.js +1 -1
- package/dist/src/data-surface/view-list/hooks.js.map +1 -1
- package/dist/src/data-surface/view-list/index.js +1 -1
- package/dist/src/data-surface/view-list/index.js.map +1 -1
- package/dist/src/data-surface/view-list/types.js.map +1 -1
- package/dist/src/filter-bar/components/ui.units.js +1 -1
- package/dist/src/filter-bar/components/ui.units.js.map +1 -1
- package/dist/src/filter-bar/convert-to-graphql.js +1 -1
- package/dist/src/filter-bar/convert-to-graphql.js.map +1 -1
- package/dist/src/filter-bar/filter-input.js +2 -0
- package/dist/src/filter-bar/filter-input.js.map +1 -0
- package/dist/src/filter-bar/filter-input.types.js +2 -0
- package/dist/src/filter-bar/filter-input.types.js.map +1 -0
- package/dist/src/filter-bar/filter-input.units.js +2 -0
- package/dist/src/filter-bar/filter-input.units.js.map +1 -0
- package/dist/src/filter-bar/filter-menu.helpers.js +2 -0
- package/dist/src/filter-bar/filter-menu.helpers.js.map +1 -0
- package/dist/src/filter-bar/filter-menu.js +2 -0
- package/dist/src/filter-bar/filter-menu.js.map +1 -0
- package/dist/src/filter-bar/filter-menu.styled.js +2 -0
- package/dist/src/filter-bar/filter-menu.styled.js.map +1 -0
- package/dist/src/filter-bar/filter-menu.units.js +2 -0
- package/dist/src/filter-bar/filter-menu.units.js.map +1 -0
- package/dist/src/filter-bar/filter-sort.js +2 -0
- package/dist/src/filter-bar/filter-sort.js.map +1 -0
- package/dist/src/filter-bar/filter-sort.types.js +2 -0
- package/dist/src/filter-bar/filter-sort.types.js.map +1 -0
- package/dist/src/filter-bar/filter-summary.js +2 -0
- package/dist/src/filter-bar/filter-summary.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-boolean.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-boolean.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-datetime.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-datetime.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-number.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-number.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-select-with-api.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-select-with-api.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-select.fallback.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-select.fallback.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-select.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-select.js.map +1 -0
- package/dist/src/filter-bar/form-field/create-form-field-string.js +2 -0
- package/dist/src/filter-bar/form-field/create-form-field-string.js.map +1 -0
- package/dist/src/filter-bar/helpers.js +1 -1
- package/dist/src/filter-bar/helpers.js.map +1 -1
- package/dist/src/filter-bar/index.create.js +1 -1
- package/dist/src/filter-bar/index.create.js.map +1 -1
- package/dist/src/filter-bar/index.dino.js +1 -1
- package/dist/src/filter-bar/index.dino.js.map +1 -1
- package/dist/src/filter-bar/local-filter-builder.js +1 -1
- package/dist/src/filter-bar/local-filter-builder.js.map +1 -1
- package/dist/src/filter-bar/popper-custom.js +2 -0
- package/dist/src/filter-bar/popper-custom.js.map +1 -0
- package/dist/src/filter-bar/types.js.map +1 -1
- package/dist/src/form/create.checkbox.js +1 -1
- package/dist/src/form/create.checkbox.js.map +1 -1
- package/dist/src/form/helpers.js +1 -1
- package/dist/src/form/helpers.js.map +1 -1
- package/dist/types/data-surface/button-switch.d.ts +4 -0
- package/dist/types/data-surface/index.create.d.ts +13 -5
- package/dist/types/data-surface/index.dino.d.ts +6 -7
- package/dist/types/data-surface/ui.units.d.ts +1 -0
- package/dist/types/data-surface/view-grid/index.d.ts +0 -1
- package/dist/types/data-surface/view-list/column-selector.d.ts +6 -0
- package/dist/types/data-surface/view-list/helpers.d.ts +3 -2
- package/dist/types/data-surface/view-list/index.d.ts +1 -1
- package/dist/types/data-surface/view-list/types.d.ts +30 -2
- package/dist/types/filter-bar/components/filter-input.mobile.d.ts +1 -7
- package/dist/types/filter-bar/components/ui.units.d.ts +7 -0
- package/dist/types/filter-bar/convert-to-graphql.d.ts +56 -28
- package/dist/types/filter-bar/{components/filter-input.d.ts → filter-input.d.ts} +5 -1
- package/dist/types/filter-bar/{components/filter-input.types.d.ts → filter-input.types.d.ts} +1 -16
- package/dist/types/filter-bar/{components/filter-input.units.d.ts → filter-input.units.d.ts} +7 -2
- package/dist/types/filter-bar/{menu/create.d.ts → filter-menu.d.ts} +4 -13
- package/dist/types/filter-bar/filter-menu.helpers.d.ts +31 -0
- package/dist/types/filter-bar/filter-menu.styled.d.ts +20 -0
- package/dist/types/filter-bar/filter-menu.types.d.ts +63 -0
- package/dist/types/filter-bar/filter-menu.units.d.ts +20 -0
- package/dist/types/filter-bar/{components/filter-sort.d.ts → filter-sort.d.ts} +21 -2
- package/dist/types/filter-bar/filter-sort.types.d.ts +30 -0
- package/dist/types/filter-bar/filter-summary.types.d.ts +14 -0
- package/dist/types/filter-bar/{menu → form-field}/create-form-field-boolean.d.ts +2 -2
- package/dist/types/filter-bar/{menu → form-field}/create-form-field-datetime.d.ts +2 -2
- package/dist/types/filter-bar/{menu → form-field}/create-form-field-number.d.ts +2 -2
- package/dist/types/filter-bar/{menu → form-field}/create-form-field-select-with-api.d.ts +2 -2
- package/dist/types/filter-bar/{menu → form-field}/create-form-field-select.d.ts +2 -2
- package/dist/types/filter-bar/form-field/create-form-field-select.fallback.d.ts +24 -0
- package/dist/types/filter-bar/{menu → form-field}/create-form-field-string.d.ts +2 -2
- package/dist/types/filter-bar/helpers.d.ts +11 -0
- package/dist/types/filter-bar/index.create.d.ts +10 -28
- package/dist/types/filter-bar/index.d.ts +9 -8
- package/dist/types/filter-bar/index.dino.d.ts +7 -7
- package/dist/types/filter-bar/local-filter-builder.d.ts +12 -3
- package/dist/types/filter-bar/types.d.ts +123 -49
- package/dist/types/form/create.checkbox.d.ts +40 -3
- package/package.json +1 -1
- package/dist/src/filter-bar/components/filter-input.js +0 -2
- package/dist/src/filter-bar/components/filter-input.js.map +0 -1
- package/dist/src/filter-bar/components/filter-input.units.js +0 -2
- package/dist/src/filter-bar/components/filter-input.units.js.map +0 -1
- package/dist/src/filter-bar/components/filter-sort.js +0 -2
- package/dist/src/filter-bar/components/filter-sort.js.map +0 -1
- package/dist/src/filter-bar/components/filter-summary.js +0 -2
- package/dist/src/filter-bar/components/filter-summary.js.map +0 -1
- package/dist/src/filter-bar/components/popper-custom.js +0 -2
- package/dist/src/filter-bar/components/popper-custom.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-boolean.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-boolean.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-datetime.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-datetime.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-number.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-number.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-select-with-api.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-select-with-api.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-select.fallback.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-select.fallback.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-select.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-select.js.map +0 -1
- package/dist/src/filter-bar/menu/create-form-field-string.js +0 -2
- package/dist/src/filter-bar/menu/create-form-field-string.js.map +0 -1
- package/dist/src/filter-bar/menu/create.js +0 -2
- package/dist/src/filter-bar/menu/create.js.map +0 -1
- package/dist/src/filter-bar/menu/ui.units.js +0 -2
- package/dist/src/filter-bar/menu/ui.units.js.map +0 -1
- package/dist/types/filter-bar/components/filter-sort.types.d.ts +0 -49
- package/dist/types/filter-bar/components/filter-summary.types.d.ts +0 -21
- package/dist/types/filter-bar/menu/create-form-field-select.fallback.d.ts +0 -11
- package/dist/types/filter-bar/menu/types.d.ts +0 -70
- package/dist/types/filter-bar/menu/ui.units.d.ts +0 -6
- /package/dist/types/filter-bar/{components/filter-summary.d.ts → filter-summary.d.ts} +0 -0
- /package/dist/types/filter-bar/{components/popper-custom.d.ts → popper-custom.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../../../src/form/helpers.ts"],"sourcesContent":["import FormValidator, { IModelError, IValidateRule, IPartialError, IFormValidatorConfig, IFieldValidateConfig } from './validator'\r\n\r\ntype IAnyObject = { [key: string]: any }\r\n\r\n/**\r\n * deepMerge: merge objects deeply, later sources always override earlier values for the same key.\r\n *\r\n * @example\r\n * // Primitive override — source wins\r\n * deepMerge({ a: 1, b: true }, { b: false })\r\n * // → { a: 1, b: false }\r\n *\r\n * // null override — null wins over nested object\r\n * deepMerge({ a: { x: 1, y: 2 } }, { a: null })\r\n * // → { a: null }\r\n *\r\n * // undefined override — undefined wins\r\n * deepMerge({ a: 'hello' }, { a: undefined })\r\n * // → { a: undefined }\r\n *\r\n * // Nested deep merge — both sides are plain objects → recurse\r\n * deepMerge({ a: { x: 1, y: 2 } }, { a: { x: 10, z: 3 } })\r\n * // → { a: { x: 10, y: 2, z: 3 } }\r\n *\r\n * // Multiple sources — last source wins on conflict\r\n * deepMerge({ a: 1 }, { a: 2 }, { a: 3 })\r\n * // → { a: 3 }\r\n */\r\nconst deepMerge = <T extends IAnyObject>(model: T, ...sources: (Partial<T> | undefined)[]): T => {\r\n const validSources = sources.filter((x): x is Partial<T> => !!x)\r\n if (validSources.length < 1) {\r\n return model\r\n }\r\n\r\n const target = Object.assign({}, model) as T\r\n\r\n for (const source of validSources) {\r\n for (const key of Object.keys(source)) {\r\n const srcVal = (source as any)[key]\r\n const tgtVal = (target as any)[key]\r\n if (\r\n srcVal !== null &&\r\n typeof srcVal === 'object' &&\r\n !Array.isArray(srcVal) &&\r\n tgtVal !== null &&\r\n typeof tgtVal === 'object' &&\r\n !Array.isArray(tgtVal)\r\n ) {\r\n // Both are plain objects → deep merge recursively\r\n ;(target as any)[key] = deepMerge(tgtVal, srcVal)\r\n } else {\r\n // Source value always wins (null, false, undefined, array, primitive)\r\n ;(target as any)[key] = srcVal\r\n }\r\n }\r\n }\r\n\r\n return target\r\n}\r\n\r\nexport const getErrorMessage = function <T>(MessageErrors: IPartialError<T> | undefined, key?: keyof T): IModelError {\r\n return MessageErrors && (MessageErrors as any)[key] ? { ...(MessageErrors as any)[key][0], error: true } : { error: false, message: '' }\r\n}\r\n\r\ntype IModelBase = {\r\n [key: string]: any\r\n}\r\n\r\nexport const convertFormDataToJson = function <T>(form: FormData, formElement?: HTMLFormElement): Partial<T> {\r\n const data = Array.from(form as any).reduce<Partial<T>>((a: unknown | any, b: any) => {\r\n if (!a[b[0]]) {\r\n a[b[0]] = b[1]\r\n } else if (Array.isArray(a[b[0]])) {\r\n a[b[0]].push(b[1])\r\n } else {\r\n a[b[0]] = [a[b[0]], b[1]]\r\n }\r\n return a\r\n }, {} as any) as any\r\n\r\n if (formElement) {\r\n const checkboxes = formElement.querySelectorAll<HTMLInputElement>('input[type=\"checkbox\"][name]')\r\n checkboxes.forEach((cb) => {\r\n if (!cb.checked && !(cb.name in data)) {\r\n data[cb.name] = false\r\n }\r\n })\r\n\r\n const numberInputs = formElement.querySelectorAll<HTMLInputElement>('input[type=\"number\"][name]')\r\n numberInputs.forEach((numInput) => {\r\n const name = numInput.name\r\n if (name && name in data) {\r\n const val = data[name]\r\n if (typeof val === 'string') {\r\n const trimmed = val.trim()\r\n if (trimmed === '') {\r\n data[name] = undefined\r\n } else {\r\n const parsed = Number(trimmed)\r\n if (!Number.isNaN(parsed)) {\r\n data[name] = parsed\r\n }\r\n }\r\n } else if (Array.isArray(val)) {\r\n data[name] = val.map((v) => {\r\n if (typeof v === 'string') {\r\n const trimmed = v.trim()\r\n if (trimmed === '') return undefined\r\n const parsed = Number(trimmed)\r\n return !Number.isNaN(parsed) ? parsed : v\r\n }\r\n return v\r\n })\r\n }\r\n }\r\n })\r\n }\r\n\r\n Object.keys(data).forEach((key) => {\r\n const value = data[key]\r\n if (typeof value === 'string' && (value.toString().toLocaleLowerCase() === 'true' || value.toString().toLocaleLowerCase() === 'false')) {\r\n data[key] = value.toString().toLocaleLowerCase() === 'true'\r\n }\r\n })\r\n return data\r\n}\r\n\r\nexport const trimAllStrings = <T>(obj: T): Partial<T> => {\r\n if (typeof obj === 'string') {\r\n // Don't trim color values (hex colors start with #)\r\n if (obj.startsWith('#') && /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(obj)) {\r\n return obj as any\r\n }\r\n return obj.trim() as any\r\n }\r\n\r\n if (Array.isArray(obj)) {\r\n return obj.map((item) => trimAllStrings(item)) as any\r\n }\r\n\r\n // Skip File objects to preserve file data\r\n if (obj instanceof File) {\r\n return obj as any\r\n }\r\n\r\n // Skip FileList objects (multiple file inputs)\r\n if (obj instanceof FileList) {\r\n return obj as any\r\n }\r\n\r\n // Skip Date objects to preserve date data\r\n if (obj instanceof Date) {\r\n return obj as any\r\n }\r\n\r\n // Skip numeric values, booleans, null, undefined\r\n if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null || obj === undefined) {\r\n return obj as any\r\n }\r\n\r\n // Skip DOM elements\r\n if (obj instanceof HTMLElement) {\r\n return obj as any\r\n }\r\n\r\n // Skip functions\r\n if (typeof obj === 'function') {\r\n return obj as any\r\n }\r\n\r\n if (obj && typeof obj === 'object') {\r\n const result: any = {}\r\n Object.keys(obj).forEach((key) => {\r\n result[key] = trimAllStrings((obj as any)[key])\r\n })\r\n return result\r\n }\r\n return obj\r\n}\r\n\r\nexport const singleValidate = function <T, TPartial = T>(\r\n key: keyof T,\r\n modelState: TPartial,\r\n MessageErrors: IPartialError<T>,\r\n Validator: FormValidator<TPartial>\r\n) {\r\n const messageErrors = Validator.run(modelState) as { [key: string]: any }\r\n if (messageErrors) {\r\n let errors = (MessageErrors || {}) as { [key: string]: any }\r\n // Collect File-type fields that also need error updating\r\n const fileKeys = Object.keys(modelState as any)\r\n .filter((k) => !!(modelState as any)[k])\r\n .filter((k) => ((modelState as any)[k] instanceof File ? !!((modelState as any)[k] as File).size : false))\r\n // Always include the primary validated key (regardless of its value type)\r\n const keys = Array.from(new Set([...fileKeys, key as string]))\r\n keys.forEach((k) => {\r\n if (messageErrors[k]) {\r\n errors[k] = messageErrors[k]\r\n } else {\r\n delete errors[k]\r\n }\r\n })\r\n return errors\r\n }\r\n return null\r\n}\r\n\r\n// export const getErrorFromResponse = <T>(error: AxiosError, modelRender?: T): IPartialError<T> | undefined => {\r\n// const data = error.response?.data as any\r\n// console.log('getErrorFromResponse', error, modelRender)\r\n// const finalData = data?.errors || data\r\n// if (finalData) {\r\n// const keys = Object.keys(modelRender as any)\r\n// const MessageErrors: IPartialError<T> | undefined = {}\r\n// keys.forEach((key) => {\r\n// const messages = finalData[key]\r\n// if (Array.isArray(messages) && messages.length > 0) {\r\n// ;(MessageErrors as any)[key] = [{ message: messages[0] }]\r\n// }\r\n// })\r\n// return MessageErrors\r\n// }\r\n// }\r\n\r\n// export const getErrorCommonFromResponse = function <T>(error: AxiosError): string[] {\r\n// const data = error.response?.data as any\r\n// console.log('getErrorCommonFromResponse', error)\r\n// const finalData = data?.errors || data\r\n// if (finalData && finalData['']) {\r\n// const messages = finalData['']\r\n// if (Array.isArray(messages)) {\r\n// return messages.filter((msg) => msg && typeof msg === 'string' && msg.trim() !== '')\r\n// }\r\n// }\r\n// return []\r\n// }\r\n\r\nexport const clearFieldEmpty = <T>(model: Extract<T, IModelBase>) => {\r\n Object.keys(model).forEach((key: keyof Extract<T, IModelBase>) => {\r\n if (!model[key]) delete model[key]\r\n })\r\n}\r\n\r\nexport const validateMerge = <T>(...validators: (FormValidator<T> | undefined)[]): FormValidator<T> => {\r\n const configs = validators.map((validator) => validator?.configs).filter((config): config is IFormValidatorConfig<T> => !!config)\r\n\r\n const mergedConfig: IFormValidatorConfig<T> = {}\r\n\r\n // Collect all unique field keys across all configs\r\n const allKeys = new Set<string>()\r\n configs.forEach((config) => {\r\n Object.keys(config).forEach((key) => allKeys.add(key))\r\n })\r\n\r\n // Merge field configs and rules for each key\r\n allKeys.forEach((key) => {\r\n const fieldConfigs = configs.map((config) => (config as any)[key]).filter((fc): fc is IFieldValidateConfig<T> => !!fc)\r\n\r\n if (fieldConfigs.length > 0) {\r\n // Find the first defined label across field configs\r\n const label = fieldConfigs.find((fc) => fc?.label)?.label\r\n\r\n // Combine all rules from each validator for this field\r\n const rules = fieldConfigs.reduce<IValidateRule<T>[]>((acc, fc) => {\r\n if (fc?.rules) {\r\n acc.push(...fc.rules)\r\n }\r\n return acc\r\n }, [])\r\n\r\n ;(mergedConfig as any)[key] = {\r\n ...deepMerge<IFieldValidateConfig<T>>({ rules: [] }, ...fieldConfigs),\r\n ...(label !== undefined ? { label } : {}),\r\n rules\r\n }\r\n }\r\n })\r\n\r\n return new FormValidator(mergedConfig)\r\n}\r\n\r\n/** Interface representing the result of a CSV validation. */\r\nexport interface IValidateCsv {\r\n /** Indicates whether the CSV data is valid */\r\n valid: boolean\r\n /** Optional message providing error details if validation fails */\r\n message?: string\r\n}\r\n\r\ninterface IValidateCsvOptions {\r\n maxRows?: number\r\n}\r\n\r\n/**\r\n * Validates a parsed CSV data array against a list of required column keys.\r\n *\r\n * @param data - An array of objects representing rows parsed from a CSV file.\r\n * @param requiredKeys - An array of keys that must exist in the CSV headers and each row.\r\n * @returns An object indicating whether the data is valid and an optional error message.\r\n */\r\nexport const validateCsvModel = <T extends Record<string, any>>(\r\n data: T[],\r\n requiredKeys: (keyof T)[],\r\n options?: IValidateCsvOptions\r\n): IValidateCsv => {\r\n // If the data is empty, consider the file invalid\r\n if (data.length === 0) {\r\n return { valid: false, message: 'File is empty or cannot be parsed' }\r\n }\r\n\r\n // Extract headers from the first row\r\n const headers = Object.keys(data[0])\r\n\r\n // Check for missing required columns\r\n const missing = requiredKeys.filter((key) => !headers.includes(key as string))\r\n if (missing.length > 0) {\r\n return { valid: false, message: `Missing required columns: ${missing.join(', ')}` }\r\n }\r\n\r\n if (options?.maxRows && data.length > options.maxRows) {\r\n return { valid: false, message: `File exceeds maximum row limit of ${options.maxRows}` }\r\n }\r\n\r\n // Validate that each required column in each row has a non-empty string value\r\n for (let i = 0; i < data.length; i++) {\r\n const row = data[i]\r\n for (const key of requiredKeys) {\r\n const value = row[key as string]\r\n if (typeof value !== 'string' || value.trim() === '') {\r\n return {\r\n valid: false,\r\n message: `Invalid or missing value for \"${key.toString()}\" at row ${i + 2}` // +2 accounts for header and 0-based index\r\n }\r\n }\r\n }\r\n }\r\n\r\n // All validations passed\r\n return { valid: true }\r\n}\r\n\r\nexport const isValueEqual = (val1: any, val2: any): boolean => {\r\n if (val1 === val2) return true\r\n\r\n // Treat empty string, null, undefined, empty array as equivalent for form inputs\r\n const empty1 = val1 === null || val1 === undefined || val1 === '' || val1 === '[]' || (Array.isArray(val1) && val1.length === 0)\r\n const empty2 = val2 === null || val2 === undefined || val2 === '' || val2 === '[]' || (Array.isArray(val2) && val2.length === 0)\r\n if (empty1 && empty2) return true\r\n if (empty1 !== empty2) return false\r\n\r\n // File comparison\r\n if (val1 instanceof File || val2 instanceof File) {\r\n if (val1 instanceof File && val2 instanceof File) {\r\n return val1.name === val2.name && val1.size === val2.size && val1.lastModified === val2.lastModified\r\n }\r\n return false\r\n }\r\n\r\n // Date comparison (handles Date objects and date formatted strings like \"11/23/1997\" vs \"1997-11-23T00:00:00.000Z\")\r\n if (\r\n val1 instanceof Date ||\r\n val2 instanceof Date ||\r\n (typeof val1 === 'string' && typeof val2 === 'string' && (val1.includes('/') || val1.includes('-')) && (val2.includes('/') || val2.includes('-')))\r\n ) {\r\n const t1 = val1 instanceof Date ? val1.getTime() : Date.parse(val1)\r\n const t2 = val2 instanceof Date ? val2.getTime() : Date.parse(val2)\r\n if (!isNaN(t1) && !isNaN(t2)) {\r\n return t1 === t2\r\n }\r\n }\r\n\r\n // Number comparison (handles string \"123\" vs number 123)\r\n if (typeof val1 === 'number' || typeof val2 === 'number') {\r\n const num1 = Number(val1)\r\n const num2 = Number(val2)\r\n if (!isNaN(num1) && !isNaN(num2)) {\r\n return num1 === num2\r\n }\r\n }\r\n\r\n // Boolean comparison (handles string \"true\"/\"false\" vs boolean)\r\n if (typeof val1 === 'boolean' || typeof val2 === 'boolean') {\r\n return String(val1).toLowerCase() === String(val2).toLowerCase()\r\n }\r\n\r\n // Object / Array comparison\r\n if (typeof val1 === 'object' || typeof val2 === 'object') {\r\n try {\r\n return JSON.stringify(val1) === JSON.stringify(val2)\r\n } catch {\r\n return false\r\n }\r\n }\r\n\r\n // String comparison after trim\r\n if (typeof val1 === 'string' && typeof val2 === 'string') {\r\n return val1.trim() === val2.trim()\r\n }\r\n\r\n return false\r\n}\r\n\r\nexport function isChanged<T extends Record<string, any>>(value: T, oldValue?: T): boolean {\r\n if (!value) return false\r\n\r\n const hasOldData =\r\n !!oldValue &&\r\n Object.keys(oldValue).some((k) => {\r\n const val = (oldValue as any)[k]\r\n return val !== null && val !== undefined && val !== '' && !(Array.isArray(val) && val.length === 0)\r\n })\r\n\r\n if (!hasOldData) {\r\n // If no valid non-empty oldValue is provided (e.g. create mode), check if at least one field in value has a non-empty value\r\n const keys = Object.keys(value) as (keyof T)[]\r\n for (const key of keys) {\r\n const val = value[key]\r\n const isEmpty = val === null || val === undefined || val === '' || (Array.isArray(val) && val.length === 0)\r\n if (!isEmpty) {\r\n return true\r\n }\r\n }\r\n return false\r\n }\r\n\r\n const keys = Object.keys(value) as (keyof T)[]\r\n for (const key of keys) {\r\n if (!isValueEqual(value[key], oldValue[key])) {\r\n return true\r\n }\r\n }\r\n return false\r\n}\r\n"],"names":["deepMerge","model","_len","arguments","length","sources","Array","_key","validSources","filter","x","_step","target","Object","assign","_iterator","_createForOfIteratorHelper","s","n","done","source","value","_i","_Object$keys","keys","key","srcVal","tgtVal","_typeof","isArray","err","e","f","getErrorMessage","MessageErrors","_objectSpread","error","message","convertFormDataToJson","form","formElement","data","from","reduce","a","b","push","querySelectorAll","forEach","cb","checked","name","numInput","val","trimmed","trim","undefined","parsed","Number","isNaN","map","v","toString","toLocaleLowerCase","trimAllStrings","obj","startsWith","test","item","File","FileList","Date","HTMLElement","result","singleValidate","modelState","Validator","messageErrors","run","errors","fileKeys","k","size","Set","concat","_toConsumableArray","validateMerge","_len2","validators","_key2","configs","validator","config","mergedConfig","allKeys","add","fieldConfigs","fc","_fieldConfigs$find","label","find","rules","acc","apply","FormValidator","validateCsvModel","requiredKeys","options","valid","headers","missing","includes","join","maxRows","i","_step2","row","_iterator2","isValueEqual","val1","val2","empty1","empty2","lastModified","t1","getTime","parse","t2","num1","num2","String","toLowerCase","JSON","stringify","_unused","isChanged","oldValue","hasOldData","some","_i2","_keys2","_i3","_keys3"],"mappings":"6LA4BA,IAAMA,EAAY,SAAuBC,GAAuD,IAAAC,IAAAA,EAAAC,UAAAC,OAA1CC,MAAmCC,MAAAJ,EAAAA,EAAAA,OAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAnCF,EAAmCE,EAAAJ,GAAAA,UA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version":3,"file":"helpers.js","sources":["../../../src/form/helpers.ts"],"sourcesContent":["import FormValidator, { IModelError, IValidateRule, IPartialError, IFormValidatorConfig, IFieldValidateConfig } from './validator'\r\n\r\ntype IAnyObject = { [key: string]: any }\r\n\r\n/**\r\n * deepMerge: merge objects deeply, later sources always override earlier values for the same key.\r\n *\r\n * @example\r\n * // Primitive override — source wins\r\n * deepMerge({ a: 1, b: true }, { b: false })\r\n * // → { a: 1, b: false }\r\n *\r\n * // null override — null wins over nested object\r\n * deepMerge({ a: { x: 1, y: 2 } }, { a: null })\r\n * // → { a: null }\r\n *\r\n * // undefined override — undefined wins\r\n * deepMerge({ a: 'hello' }, { a: undefined })\r\n * // → { a: undefined }\r\n *\r\n * // Nested deep merge — both sides are plain objects → recurse\r\n * deepMerge({ a: { x: 1, y: 2 } }, { a: { x: 10, z: 3 } })\r\n * // → { a: { x: 10, y: 2, z: 3 } }\r\n *\r\n * // Multiple sources — last source wins on conflict\r\n * deepMerge({ a: 1 }, { a: 2 }, { a: 3 })\r\n * // → { a: 3 }\r\n */\r\nconst deepMerge = <T extends IAnyObject>(model: T, ...sources: (Partial<T> | undefined)[]): T => {\r\n const validSources = sources.filter((x): x is Partial<T> => !!x)\r\n if (validSources.length < 1) {\r\n return model\r\n }\r\n\r\n const target = Object.assign({}, model) as T\r\n\r\n for (const source of validSources) {\r\n for (const key of Object.keys(source)) {\r\n const srcVal = (source as any)[key]\r\n const tgtVal = (target as any)[key]\r\n if (\r\n srcVal !== null &&\r\n typeof srcVal === 'object' &&\r\n !Array.isArray(srcVal) &&\r\n tgtVal !== null &&\r\n typeof tgtVal === 'object' &&\r\n !Array.isArray(tgtVal)\r\n ) {\r\n // Both are plain objects → deep merge recursively\r\n ;(target as any)[key] = deepMerge(tgtVal, srcVal)\r\n } else {\r\n // Source value always wins (null, false, undefined, array, primitive)\r\n ;(target as any)[key] = srcVal\r\n }\r\n }\r\n }\r\n\r\n return target\r\n}\r\n\r\nexport const getErrorMessage = function <T>(MessageErrors: IPartialError<T> | undefined, key?: keyof T): IModelError {\r\n return MessageErrors && (MessageErrors as any)[key] ? { ...(MessageErrors as any)[key][0], error: true } : { error: false, message: '' }\r\n}\r\n\r\ntype IModelBase = {\r\n [key: string]: any\r\n}\r\n\r\nexport const convertFormDataToJson = function <T>(form: FormData, formElement?: HTMLFormElement): Partial<T> {\r\n const data = Array.from(form as any).reduce<Partial<T>>((a: unknown | any, b: any) => {\r\n if (!a[b[0]]) {\r\n a[b[0]] = b[1]\r\n } else if (Array.isArray(a[b[0]])) {\r\n a[b[0]].push(b[1])\r\n } else {\r\n a[b[0]] = [a[b[0]], b[1]]\r\n }\r\n return a\r\n }, {} as any) as any\r\n\r\n if (formElement) {\r\n const checkboxes = formElement.querySelectorAll<HTMLInputElement>('input[type=\"checkbox\"][name]')\r\n checkboxes.forEach((cb) => {\r\n if (!cb.checked && !(cb.name in data)) {\r\n data[cb.name] = false\r\n }\r\n })\r\n\r\n const numberInputs = formElement.querySelectorAll<HTMLInputElement>('input[type=\"number\"][name]')\r\n numberInputs.forEach((numInput) => {\r\n const name = numInput.name\r\n if (name && name in data) {\r\n const val = data[name]\r\n if (typeof val === 'string') {\r\n const trimmed = val.trim()\r\n if (trimmed === '') {\r\n data[name] = undefined\r\n } else {\r\n const parsed = Number(trimmed)\r\n if (!Number.isNaN(parsed)) {\r\n data[name] = parsed\r\n }\r\n }\r\n } else if (Array.isArray(val)) {\r\n data[name] = val.map((v) => {\r\n if (typeof v === 'string') {\r\n const trimmed = v.trim()\r\n if (trimmed === '') return undefined\r\n const parsed = Number(trimmed)\r\n return !Number.isNaN(parsed) ? parsed : v\r\n }\r\n return v\r\n })\r\n }\r\n }\r\n })\r\n }\r\n\r\n Object.keys(data).forEach((key) => {\r\n const value = data[key]\r\n if (typeof value === 'string') {\r\n const lower = value.toString().toLowerCase()\r\n if (lower === 'true' || lower === 'on') {\r\n data[key] = true\r\n } else if (lower === 'false' || lower === 'off') {\r\n data[key] = false\r\n }\r\n }\r\n })\r\n return data\r\n}\r\n\r\nexport const trimAllStrings = <T>(obj: T): Partial<T> => {\r\n if (typeof obj === 'string') {\r\n // Don't trim color values (hex colors start with #)\r\n if (obj.startsWith('#') && /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(obj)) {\r\n return obj as any\r\n }\r\n return obj.trim() as any\r\n }\r\n\r\n if (Array.isArray(obj)) {\r\n return obj.map((item) => trimAllStrings(item)) as any\r\n }\r\n\r\n // Skip File objects to preserve file data\r\n if (obj instanceof File) {\r\n return obj as any\r\n }\r\n\r\n // Skip FileList objects (multiple file inputs)\r\n if (obj instanceof FileList) {\r\n return obj as any\r\n }\r\n\r\n // Skip Date objects to preserve date data\r\n if (obj instanceof Date) {\r\n return obj as any\r\n }\r\n\r\n // Skip numeric values, booleans, null, undefined\r\n if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null || obj === undefined) {\r\n return obj as any\r\n }\r\n\r\n // Skip DOM elements\r\n if (obj instanceof HTMLElement) {\r\n return obj as any\r\n }\r\n\r\n // Skip functions\r\n if (typeof obj === 'function') {\r\n return obj as any\r\n }\r\n\r\n if (obj && typeof obj === 'object') {\r\n const result: any = {}\r\n Object.keys(obj).forEach((key) => {\r\n result[key] = trimAllStrings((obj as any)[key])\r\n })\r\n return result\r\n }\r\n return obj\r\n}\r\n\r\nexport const singleValidate = function <T, TPartial = T>(\r\n key: keyof T,\r\n modelState: TPartial,\r\n MessageErrors: IPartialError<T>,\r\n Validator: FormValidator<TPartial>\r\n) {\r\n const messageErrors = Validator.run(modelState) as { [key: string]: any }\r\n if (messageErrors) {\r\n let errors = (MessageErrors || {}) as { [key: string]: any }\r\n // Collect File-type fields that also need error updating\r\n const fileKeys = Object.keys(modelState as any)\r\n .filter((k) => !!(modelState as any)[k])\r\n .filter((k) => ((modelState as any)[k] instanceof File ? !!((modelState as any)[k] as File).size : false))\r\n // Always include the primary validated key (regardless of its value type)\r\n const keys = Array.from(new Set([...fileKeys, key as string]))\r\n keys.forEach((k) => {\r\n if (messageErrors[k]) {\r\n errors[k] = messageErrors[k]\r\n } else {\r\n delete errors[k]\r\n }\r\n })\r\n return errors\r\n }\r\n return null\r\n}\r\n\r\n// export const getErrorFromResponse = <T>(error: AxiosError, modelRender?: T): IPartialError<T> | undefined => {\r\n// const data = error.response?.data as any\r\n// console.log('getErrorFromResponse', error, modelRender)\r\n// const finalData = data?.errors || data\r\n// if (finalData) {\r\n// const keys = Object.keys(modelRender as any)\r\n// const MessageErrors: IPartialError<T> | undefined = {}\r\n// keys.forEach((key) => {\r\n// const messages = finalData[key]\r\n// if (Array.isArray(messages) && messages.length > 0) {\r\n// ;(MessageErrors as any)[key] = [{ message: messages[0] }]\r\n// }\r\n// })\r\n// return MessageErrors\r\n// }\r\n// }\r\n\r\n// export const getErrorCommonFromResponse = function <T>(error: AxiosError): string[] {\r\n// const data = error.response?.data as any\r\n// console.log('getErrorCommonFromResponse', error)\r\n// const finalData = data?.errors || data\r\n// if (finalData && finalData['']) {\r\n// const messages = finalData['']\r\n// if (Array.isArray(messages)) {\r\n// return messages.filter((msg) => msg && typeof msg === 'string' && msg.trim() !== '')\r\n// }\r\n// }\r\n// return []\r\n// }\r\n\r\nexport const clearFieldEmpty = <T>(model: Extract<T, IModelBase>) => {\r\n Object.keys(model).forEach((key: keyof Extract<T, IModelBase>) => {\r\n if (!model[key]) delete model[key]\r\n })\r\n}\r\n\r\nexport const validateMerge = <T>(...validators: (FormValidator<T> | undefined)[]): FormValidator<T> => {\r\n const configs = validators.map((validator) => validator?.configs).filter((config): config is IFormValidatorConfig<T> => !!config)\r\n\r\n const mergedConfig: IFormValidatorConfig<T> = {}\r\n\r\n // Collect all unique field keys across all configs\r\n const allKeys = new Set<string>()\r\n configs.forEach((config) => {\r\n Object.keys(config).forEach((key) => allKeys.add(key))\r\n })\r\n\r\n // Merge field configs and rules for each key\r\n allKeys.forEach((key) => {\r\n const fieldConfigs = configs.map((config) => (config as any)[key]).filter((fc): fc is IFieldValidateConfig<T> => !!fc)\r\n\r\n if (fieldConfigs.length > 0) {\r\n // Find the first defined label across field configs\r\n const label = fieldConfigs.find((fc) => fc?.label)?.label\r\n\r\n // Combine all rules from each validator for this field\r\n const rules = fieldConfigs.reduce<IValidateRule<T>[]>((acc, fc) => {\r\n if (fc?.rules) {\r\n acc.push(...fc.rules)\r\n }\r\n return acc\r\n }, [])\r\n\r\n ;(mergedConfig as any)[key] = {\r\n ...deepMerge<IFieldValidateConfig<T>>({ rules: [] }, ...fieldConfigs),\r\n ...(label !== undefined ? { label } : {}),\r\n rules\r\n }\r\n }\r\n })\r\n\r\n return new FormValidator(mergedConfig)\r\n}\r\n\r\n/** Interface representing the result of a CSV validation. */\r\nexport interface IValidateCsv {\r\n /** Indicates whether the CSV data is valid */\r\n valid: boolean\r\n /** Optional message providing error details if validation fails */\r\n message?: string\r\n}\r\n\r\ninterface IValidateCsvOptions {\r\n maxRows?: number\r\n}\r\n\r\n/**\r\n * Validates a parsed CSV data array against a list of required column keys.\r\n *\r\n * @param data - An array of objects representing rows parsed from a CSV file.\r\n * @param requiredKeys - An array of keys that must exist in the CSV headers and each row.\r\n * @returns An object indicating whether the data is valid and an optional error message.\r\n */\r\nexport const validateCsvModel = <T extends Record<string, any>>(\r\n data: T[],\r\n requiredKeys: (keyof T)[],\r\n options?: IValidateCsvOptions\r\n): IValidateCsv => {\r\n // If the data is empty, consider the file invalid\r\n if (data.length === 0) {\r\n return { valid: false, message: 'File is empty or cannot be parsed' }\r\n }\r\n\r\n // Extract headers from the first row\r\n const headers = Object.keys(data[0])\r\n\r\n // Check for missing required columns\r\n const missing = requiredKeys.filter((key) => !headers.includes(key as string))\r\n if (missing.length > 0) {\r\n return { valid: false, message: `Missing required columns: ${missing.join(', ')}` }\r\n }\r\n\r\n if (options?.maxRows && data.length > options.maxRows) {\r\n return { valid: false, message: `File exceeds maximum row limit of ${options.maxRows}` }\r\n }\r\n\r\n // Validate that each required column in each row has a non-empty string value\r\n for (let i = 0; i < data.length; i++) {\r\n const row = data[i]\r\n for (const key of requiredKeys) {\r\n const value = row[key as string]\r\n if (typeof value !== 'string' || value.trim() === '') {\r\n return {\r\n valid: false,\r\n message: `Invalid or missing value for \"${key.toString()}\" at row ${i + 2}` // +2 accounts for header and 0-based index\r\n }\r\n }\r\n }\r\n }\r\n\r\n // All validations passed\r\n return { valid: true }\r\n}\r\n\r\nexport const isValueEqual = (val1: any, val2: any): boolean => {\r\n if (val1 === val2) return true\r\n\r\n // Treat empty string, null, undefined, empty array as equivalent for form inputs\r\n const empty1 = val1 === null || val1 === undefined || val1 === '' || val1 === '[]' || (Array.isArray(val1) && val1.length === 0)\r\n const empty2 = val2 === null || val2 === undefined || val2 === '' || val2 === '[]' || (Array.isArray(val2) && val2.length === 0)\r\n if (empty1 && empty2) return true\r\n if (empty1 !== empty2) return false\r\n\r\n // File comparison\r\n if (val1 instanceof File || val2 instanceof File) {\r\n if (val1 instanceof File && val2 instanceof File) {\r\n return val1.name === val2.name && val1.size === val2.size && val1.lastModified === val2.lastModified\r\n }\r\n return false\r\n }\r\n\r\n // Date comparison (handles Date objects and date formatted strings like \"11/23/1997\" vs \"1997-11-23T00:00:00.000Z\")\r\n if (\r\n val1 instanceof Date ||\r\n val2 instanceof Date ||\r\n (typeof val1 === 'string' && typeof val2 === 'string' && (val1.includes('/') || val1.includes('-')) && (val2.includes('/') || val2.includes('-')))\r\n ) {\r\n const t1 = val1 instanceof Date ? val1.getTime() : Date.parse(val1)\r\n const t2 = val2 instanceof Date ? val2.getTime() : Date.parse(val2)\r\n if (!isNaN(t1) && !isNaN(t2)) {\r\n return t1 === t2\r\n }\r\n }\r\n\r\n // Number comparison (handles string \"123\" vs number 123)\r\n if (typeof val1 === 'number' || typeof val2 === 'number') {\r\n const num1 = Number(val1)\r\n const num2 = Number(val2)\r\n if (!isNaN(num1) && !isNaN(num2)) {\r\n return num1 === num2\r\n }\r\n }\r\n\r\n // Boolean comparison (handles string \"true\"/\"false\" vs boolean)\r\n if (typeof val1 === 'boolean' || typeof val2 === 'boolean') {\r\n return String(val1).toLowerCase() === String(val2).toLowerCase()\r\n }\r\n\r\n // Object / Array comparison\r\n if (typeof val1 === 'object' || typeof val2 === 'object') {\r\n try {\r\n return JSON.stringify(val1) === JSON.stringify(val2)\r\n } catch {\r\n return false\r\n }\r\n }\r\n\r\n // String comparison after trim\r\n if (typeof val1 === 'string' && typeof val2 === 'string') {\r\n return val1.trim() === val2.trim()\r\n }\r\n\r\n return false\r\n}\r\n\r\nexport function isChanged<T extends Record<string, any>>(value: T, oldValue?: T): boolean {\r\n if (!value) return false\r\n\r\n const hasOldData =\r\n !!oldValue &&\r\n Object.keys(oldValue).some((k) => {\r\n const val = (oldValue as any)[k]\r\n return val !== null && val !== undefined && val !== '' && !(Array.isArray(val) && val.length === 0)\r\n })\r\n\r\n if (!hasOldData) {\r\n // If no valid non-empty oldValue is provided (e.g. create mode), check if at least one field in value has a non-empty value\r\n const keys = Object.keys(value) as (keyof T)[]\r\n for (const key of keys) {\r\n const val = value[key]\r\n const isEmpty = val === null || val === undefined || val === '' || (Array.isArray(val) && val.length === 0)\r\n if (!isEmpty) {\r\n return true\r\n }\r\n }\r\n return false\r\n }\r\n\r\n const keys = Object.keys(value) as (keyof T)[]\r\n for (const key of keys) {\r\n if (!isValueEqual(value[key], oldValue[key])) {\r\n return true\r\n }\r\n }\r\n return false\r\n}\r\n"],"names":["deepMerge","model","_len","arguments","length","sources","Array","_key","validSources","filter","x","_step","target","Object","assign","_iterator","_createForOfIteratorHelper","s","n","done","source","value","_i","_Object$keys","keys","key","srcVal","tgtVal","_typeof","isArray","err","e","f","getErrorMessage","MessageErrors","_objectSpread","error","message","convertFormDataToJson","form","formElement","data","from","reduce","a","b","push","querySelectorAll","forEach","cb","checked","name","numInput","val","trimmed","trim","undefined","parsed","Number","isNaN","map","v","lower","toString","toLowerCase","trimAllStrings","obj","startsWith","test","item","File","FileList","Date","HTMLElement","result","singleValidate","modelState","Validator","messageErrors","run","errors","fileKeys","k","size","Set","concat","_toConsumableArray","validateMerge","_len2","validators","_key2","configs","validator","config","mergedConfig","allKeys","add","fieldConfigs","fc","_fieldConfigs$find","label","find","rules","acc","apply","FormValidator","validateCsvModel","requiredKeys","options","valid","headers","missing","includes","join","maxRows","i","_step2","row","_iterator2","isValueEqual","val1","val2","empty1","empty2","lastModified","t1","getTime","parse","t2","num1","num2","String","JSON","stringify","_unused","isChanged","oldValue","hasOldData","some","_i2","_keys2","_i3","_keys3"],"mappings":"6LA4BA,IAAMA,EAAY,SAAuBC,GAAuD,IAAAC,IAAAA,EAAAC,UAAAC,OAA1CC,MAAmCC,MAAAJ,EAAAA,EAAAA,OAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAnCF,EAAmCE,EAAAJ,GAAAA,UAAAI,GACvF,IAAMC,EAAeH,EAAQI,OAAO,SAACC,GAAC,QAAwBA,IAC9D,GAAIF,EAAaJ,OAAS,EACxB,OAAOH,EAGT,IAEiCU,EAF3BC,EAASC,OAAOC,OAAO,CAAA,EAAIb,GAAWc,EAAAC,EAEvBR,GAAY,IAAjC,IAAAO,EAAAE,MAAAN,EAAAI,EAAAG,KAAAC,MACE,IADiC,IAAxBC,EAAMT,EAAAU,MACfC,EAAAC,EAAAA,EAAkBV,OAAOW,KAAKJ,GAAOE,EAAAC,EAAAnB,OAAAkB,IAAE,CAAlC,IAAMG,EAAGF,EAAAD,GACNI,EAAUN,EAAeK,GACzBE,EAAUf,EAAea,GAElB,OAAXC,GACkB,WAAlBE,EAAOF,IACNpB,MAAMuB,QAAQH,IACJ,OAAXC,GACkB,WAAlBC,EAAOD,IACNrB,MAAMuB,QAAQF,GAMbf,EAAea,GAAOC,EAHtBd,EAAea,GAAOzB,EAAU2B,EAAQD,EAK7C,CACF,CAAA,MAAAI,GAAAf,EAAAgB,EAAAD,EAAA,CAAA,QAAAf,EAAAiB,GAAA,CAED,OAAOpB,CACT,EAEaqB,EAAkB,SAAaC,EAA6CT,GACvF,OAAOS,GAAkBA,EAAsBT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/C,MAAMuB,QAAQwB,IAAuB,IAAfA,EAAIjD,OACxF,GAEF,IAAKqI,EAAY,CAGf,IADA,IACAE,EAAA,EAAAC,EADa/H,OAAOW,KAAKH,GACHsH,EAAAC,EAAAxI,OAAAuI,IAAE,CAAnB,IACGtF,EAAMhC,EADAuH,EAAAD,IAGZ,KADgBtF,SAA6C,KAARA,GAAe/C,MAAMuB,QAAQwB,IAAuB,IAAfA,EAAIjD,QAE5F,OAAO,CAEV,CACD,OAAO,CACR,CAGD,IADA,IACAyI,EAAA,EAAAC,EADajI,OAAOW,KAAKH,GACHwH,EAAAC,EAAA1I,OAAAyI,IAAE,CAAnB,IAAMpH,EAAGqH,EAAAD,GACZ,IAAKtB,EAAalG,EAAMI,GAAM+G,EAAS/G,IACrC,OAAO,CAEV,CACD,OAAO,CACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
+
import { ToggleButtonGroupProps } from '@mui/material';
|
|
2
3
|
import { DataSurfaceViewMode } from './types';
|
|
3
4
|
export interface IButtonSwitchProps {
|
|
4
5
|
value?: DataSurfaceViewMode;
|
|
@@ -7,7 +8,10 @@ export interface IButtonSwitchProps {
|
|
|
7
8
|
className?: string;
|
|
8
9
|
onlyIcon?: boolean;
|
|
9
10
|
reverse?: boolean;
|
|
11
|
+
hide?: boolean;
|
|
12
|
+
sx?: ToggleButtonGroupProps['sx'];
|
|
10
13
|
}
|
|
11
14
|
export declare const mapIcons: Record<DataSurfaceViewMode, JSX.Element>;
|
|
12
15
|
export declare const ButtonSwitch: FC<IButtonSwitchProps>;
|
|
13
16
|
export default ButtonSwitch;
|
|
17
|
+
export declare const createButtonSwitch: (params?: Partial<IButtonSwitchProps>) => FC<IButtonSwitchProps>;
|
|
@@ -3,11 +3,11 @@ import type { BoxProps } from '@mui/material';
|
|
|
3
3
|
import type { ComponentType, FC } from 'react';
|
|
4
4
|
import type { IViewGridConfig, IViewGridProps } from './view-grid/types';
|
|
5
5
|
import type { TPagination, TDataSurfaceState, TRenderableNode } from './types';
|
|
6
|
-
import type { IViewListConfig, IViewListProps } from './view-list';
|
|
6
|
+
import type { IViewListConfig, IViewListProps, TColumnVisibility } from './view-list';
|
|
7
7
|
import type { TFieldSort } from '../filter-bar/types';
|
|
8
8
|
export interface IDataSurfaceSlots<T> {
|
|
9
|
-
listViewProps?: IViewListProps<T
|
|
10
|
-
gridViewProps?: IViewGridProps<T
|
|
9
|
+
listViewProps?: Partial<Omit<IViewListProps<T>, 'columnVisibility'>>;
|
|
10
|
+
gridViewProps?: Partial<IViewGridProps<T>>;
|
|
11
11
|
/** Custom loading component. If not provided, a default loading component will be used. */
|
|
12
12
|
PanelLoading?: ComponentType<{
|
|
13
13
|
viewMode: DataSurfaceViewMode;
|
|
@@ -71,6 +71,11 @@ export interface IDataSurfaceProps<T> {
|
|
|
71
71
|
* NOTE: This sorting callback is currently supported ONLY in ViewList (List view).
|
|
72
72
|
*/
|
|
73
73
|
onSortChange?: (sort?: TFieldSort<T>) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Column visibility configuration.
|
|
76
|
+
* NOTE: This column visibility configuration is currently supported ONLY in ViewList (List view).
|
|
77
|
+
*/
|
|
78
|
+
columnVisibility?: TColumnVisibility<T>;
|
|
74
79
|
}
|
|
75
80
|
export interface IDataSurfaceConfig<T> {
|
|
76
81
|
/** Feature mode determines the internal optimizations and rendering strategies. @default 'client' */
|
|
@@ -100,5 +105,8 @@ export interface IDataSurfaceConfig<T> {
|
|
|
100
105
|
/** Custom load more component for infinite scroll mode. If not provided, a default loading indicator will be shown when fetching the next page. */
|
|
101
106
|
PanelLoadMore?: ComponentType;
|
|
102
107
|
}
|
|
103
|
-
export declare function createDataSurface<T>(config: IDataSurfaceConfig<T>): FC<IDataSurfaceProps<T
|
|
104
|
-
|
|
108
|
+
export declare function createDataSurface<T>(config: IDataSurfaceConfig<T>): FC<IDataSurfaceProps<T>> & {
|
|
109
|
+
listConfig?: IViewListConfig<T> | undefined;
|
|
110
|
+
gridConfig?: IViewGridConfig<T> | undefined;
|
|
111
|
+
config: IDataSurfaceConfig<T>;
|
|
112
|
+
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { setViewModeToURL, getViewModeFromURL, setPaginationToURL, getPaginationFromURL } from './helpers';
|
|
3
|
-
import createViewGrid from './view-grid';
|
|
4
|
-
import createDataSurface from './index.create';
|
|
5
|
-
import createViewList from './view-list';
|
|
3
|
+
import { createViewGrid } from './view-grid';
|
|
4
|
+
import { createDataSurface } from './index.create';
|
|
5
|
+
import { createViewList, createColumnSelector } from './view-list';
|
|
6
6
|
export declare class DinoDataSurFace {
|
|
7
7
|
createDataSurface: typeof createDataSurface;
|
|
8
8
|
createViewGrid: typeof createViewGrid;
|
|
9
9
|
createViewList: typeof createViewList;
|
|
10
|
-
|
|
11
|
-
createButtonSwitch: () => import("react").FC<import("./button-switch").IButtonSwitchProps>;
|
|
12
|
-
|
|
13
|
-
createPanelPaginationFooter: () => import("react").FC<import("./ui.units").IPanelPaginationFooterProps>;
|
|
10
|
+
createColumnSelector: typeof createColumnSelector;
|
|
11
|
+
createButtonSwitch: (params?: Partial<import("./button-switch").IButtonSwitchProps> | undefined) => import("react").FC<import("./button-switch").IButtonSwitchProps>;
|
|
12
|
+
createPanelPaginationFooter: (params?: Partial<import("./ui.units").IPanelPaginationFooterProps> | undefined) => import("react").FC<import("./ui.units").IPanelPaginationFooterProps>;
|
|
14
13
|
setViewModeToURL: typeof setViewModeToURL;
|
|
15
14
|
getViewModeFromURL: typeof getViewModeFromURL;
|
|
16
15
|
setPaginationToURL: typeof setPaginationToURL;
|
|
@@ -36,3 +36,4 @@ export interface IPanelPaginationFooterProps {
|
|
|
36
36
|
resetKey?: string | number;
|
|
37
37
|
}
|
|
38
38
|
export declare const PanelPaginationFooter: FC<IPanelPaginationFooterProps>;
|
|
39
|
+
export declare const createPanelPaginationFooter: (params?: Partial<IPanelPaginationFooterProps>) => FC<IPanelPaginationFooterProps>;
|
|
@@ -16,4 +16,3 @@ export interface IViewGridLoadingProps<T> extends IViewGridProps<T> {
|
|
|
16
16
|
onPageChange?: (page: number, pageSize: number) => void | Promise<void>;
|
|
17
17
|
}
|
|
18
18
|
export declare function createViewGridLoading<T>(GridComponent: ComponentType<IViewGridProps<T>>): FC<IViewGridLoadingProps<T>>;
|
|
19
|
-
export default createViewGrid;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { IColumnSelectorConfig, IColumnSelectorProps, TColumnVisibility } from './types';
|
|
3
|
+
export declare function createColumnSelector<T>(config: IColumnSelectorConfig<T>): FC<IColumnSelectorProps<T>> & {
|
|
4
|
+
defaultValue: TColumnVisibility<T>;
|
|
5
|
+
};
|
|
6
|
+
export default createColumnSelector;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableCellProps } from '@mui/material';
|
|
2
|
-
import { ListDensity, TListColumn, TListColumns } from './types';
|
|
2
|
+
import { ListDensity, TColumnVisibility, TListColumn, TListColumns } from './types';
|
|
3
3
|
export declare const LIST_HEADER_HEIGHT = 48;
|
|
4
4
|
export declare const LIST_DEFAULT_ROW_SPACING = 4;
|
|
5
5
|
export declare const CHECKBOX_COL_WIDTH = 48;
|
|
@@ -7,8 +7,9 @@ export declare const LIST_ROW_HEIGHT_BY_DENSITY: Record<ListDensity, number>;
|
|
|
7
7
|
export declare const LIST_CELL_PADDING_BY_DENSITY: Record<ListDensity, string>;
|
|
8
8
|
/**
|
|
9
9
|
* Converts TListColumns<T> Record type to TListColumn<T>[] array for internal use.
|
|
10
|
+
* Applies columnVisibilityModel if provided for managed columns.
|
|
10
11
|
*/
|
|
11
|
-
export declare const columnsRecordToArray: <T>(value: T[], columnsRecord?: Partial<Record<keyof T, Omit<TListColumn<T>, "field">>> | undefined) => TListColumn<T>[];
|
|
12
|
+
export declare const columnsRecordToArray: <T>(value: T[], columnsRecord?: Partial<Record<keyof T, Omit<TListColumn<T>, "field">>> | undefined, visibilityModel?: Partial<Record<keyof T, boolean>> | undefined) => TListColumn<T>[];
|
|
12
13
|
export declare function resolveListRowHeight(density?: number | ListDensity): number;
|
|
13
14
|
export declare function resolveListCellPadding(density?: number | ListDensity): string;
|
|
14
15
|
export declare function resolveListRowSpacing(spacing?: number): number;
|
|
@@ -2,6 +2,7 @@ import type { ComponentType, FC } from 'react';
|
|
|
2
2
|
import type { LoadingModeRule, TPagination } from '../types';
|
|
3
3
|
import type { IViewListConfig, IViewListProps } from './types';
|
|
4
4
|
export * from './types';
|
|
5
|
+
export * from './column-selector';
|
|
5
6
|
export declare function createViewList<T>(config: IViewListConfig<T>): FC<IViewListProps<T>>;
|
|
6
7
|
export interface IViewListLoadingProps<T> extends IViewListProps<T> {
|
|
7
8
|
loadMode: LoadingModeRule;
|
|
@@ -10,4 +11,3 @@ export interface IViewListLoadingProps<T> extends IViewListProps<T> {
|
|
|
10
11
|
onPageChange?: (page: number, pageSize: number) => void | Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
export declare function createViewListLoading<T>(ListComponent: ComponentType<IViewListProps<T>>): FC<IViewListLoadingProps<T>>;
|
|
13
|
-
export default createViewList;
|
|
@@ -38,8 +38,6 @@ export interface TListColumn<T> {
|
|
|
38
38
|
field: keyof T;
|
|
39
39
|
/** Column header label shown in the header. */
|
|
40
40
|
label?: string;
|
|
41
|
-
/** If true, the column is visible in the list @default true */
|
|
42
|
-
visible?: boolean;
|
|
43
41
|
/** Explicit column width. Accepts px number or CSS string (e.g. '120px', '20%'). */
|
|
44
42
|
width?: number | string;
|
|
45
43
|
/** Minimum column width in pixels. */
|
|
@@ -56,6 +54,10 @@ export interface TListColumn<T> {
|
|
|
56
54
|
valueGetter?: (value: string, row: T, index: number) => any;
|
|
57
55
|
/** Allow sorting on this column */
|
|
58
56
|
sortable?: boolean;
|
|
57
|
+
/** If true, the column is visible in the list @default true */
|
|
58
|
+
visible?: boolean;
|
|
59
|
+
/** Allow toggling visibility of this column via ColumnSelector */
|
|
60
|
+
colVisibleable?: boolean;
|
|
59
61
|
}
|
|
60
62
|
/** Columns configuration for List view. */
|
|
61
63
|
export type TListColumns<T> = Partial<Record<keyof T, Omit<TListColumn<T>, 'field'>>>;
|
|
@@ -104,6 +106,32 @@ export interface IViewListBase<T> {
|
|
|
104
106
|
sort?: TFieldSort<T>;
|
|
105
107
|
/** Callback triggered when sorting changes */
|
|
106
108
|
onSortChange?: (sort?: TFieldSort<T>) => void;
|
|
109
|
+
/** Map specifying which managed columns are visible (true) or hidden (false) */
|
|
110
|
+
columnVisibility?: TColumnVisibility<T>;
|
|
111
|
+
}
|
|
112
|
+
/** Visibility model for columns where key is field name and value is boolean. */
|
|
113
|
+
export type TColumnVisibility<T> = Partial<Record<keyof T, boolean>>;
|
|
114
|
+
/** Factory configuration for ColumnSelector */
|
|
115
|
+
export interface IColumnSelectorConfig<T> {
|
|
116
|
+
/** Unique table key for namespacing localStorage data (required) */
|
|
117
|
+
persistenceKey: string;
|
|
118
|
+
/** Global storage key in localStorage @default 'dino-view-list-column-visibility' */
|
|
119
|
+
storageKey?: string;
|
|
120
|
+
/** Target listConfig (e.g. DataSurfaceIns.listConfig) */
|
|
121
|
+
config?: IViewListConfig<T>;
|
|
122
|
+
/** Whether the column selector should be hidden */
|
|
123
|
+
hide?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/** Props for ColumnSelector component */
|
|
126
|
+
export interface IColumnSelectorProps<T> {
|
|
127
|
+
/** Controlled column visibility model */
|
|
128
|
+
visibility?: TColumnVisibility<T>;
|
|
129
|
+
/** Callback when column visibility model changes */
|
|
130
|
+
onChange?: (model: TColumnVisibility<T>) => void;
|
|
131
|
+
/** Size of IconButton @default 'small' */
|
|
132
|
+
size?: 'small' | 'medium';
|
|
133
|
+
/** Whether the column selector should be hidden */
|
|
134
|
+
hide?: boolean;
|
|
107
135
|
}
|
|
108
136
|
/** Configuration for List view. */
|
|
109
137
|
export interface IViewListConfig<T> extends IViewListBase<T> {
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export interface IMobileSearchButtonProps {
|
|
3
|
-
placeholder?: string;
|
|
4
|
-
onSearching?: (keyword: string) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const MobileSearchButton: FC<IMobileSearchButtonProps>;
|
|
7
|
-
export default MobileSearchButton;
|
|
1
|
+
export {};
|
|
@@ -13,6 +13,13 @@ export declare const ButtonBack: import("@emotion/styled").StyledComponent<impor
|
|
|
13
13
|
export declare const ChipDark: import("@emotion/styled").StyledComponent<import("@mui/material").ChipOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
14
14
|
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
15
15
|
}, "classes" | "className" | "style" | "children" | "sx" | "variant" | "label" | "tabIndex" | "color" | "icon" | "disabled" | "size" | "clickable" | "avatar" | "deleteIcon" | "onDelete" | "skipFocusWhenDisabled"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
16
|
+
export declare const GroupSubheaderStyled: import("@emotion/styled").StyledComponent<import("@mui/material").ListSubheaderOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>, "ref"> & {
|
|
17
|
+
ref?: ((instance: HTMLLIElement | null) => void) | import("react").RefObject<HTMLLIElement> | null | undefined;
|
|
18
|
+
}, "classes" | "className" | "style" | "children" | "sx" | "color" | "inset" | "disableGutters" | "disableSticky"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
19
|
+
interface IErrorPannelProps {
|
|
20
|
+
onRetry?: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const ErrorPannel: FC<IErrorPannelProps>;
|
|
16
23
|
export interface FilterLogicToggleProps {
|
|
17
24
|
value?: TLogic;
|
|
18
25
|
onChange?: (event: React.MouseEvent<HTMLElement>, value: TLogic) => void;
|
|
@@ -2,12 +2,8 @@ import { RequestParam } from '../http-service/graphql/request-param';
|
|
|
2
2
|
import type { TFilterState, TFieldStore, TLogic, TDirection, TFieldType, TFieldValid } from './types';
|
|
3
3
|
type TFilterScopeFn<TSource, TTarget extends object, U extends object = {}> = (currentBuilder: RequestParam<TTarget, U>, store?: TFieldStore<TSource>) => void;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - Supports mapping filter fields to different GraphQL fields, custom filter logic, and sorting.
|
|
8
|
-
* @vi
|
|
9
|
-
* - Lớp tiện ích để chuyển đổi trạng thái filter từ filter bar thành builder truy vấn GraphQL.
|
|
10
|
-
* - Hỗ trợ ánh xạ các trường filter sang các trường GraphQL khác, logic filter tùy chỉnh và sắp xếp.
|
|
5
|
+
* Utility class to convert filter state from a filter bar into a GraphQL query builder.
|
|
6
|
+
* Supports mapping filter fields to different GraphQL fields, custom filter logic, and sorting.
|
|
11
7
|
*/
|
|
12
8
|
type TAutoMapFieldCustomFn<TSource, TTarget extends object, U extends object = {}> = (currentBuilder: RequestParam<TTarget, U>, value?: NonNullable<TFieldStore<TSource>>[keyof TFieldStore<TSource>], store?: TFieldStore<TSource>) => void;
|
|
13
9
|
type TAutoMapFieldCustomSingleFn<TSource, TTarget extends object, U extends object = {}> = (currentBuilder: RequestParam<TTarget, U>, value: TFieldValid, options?: {
|
|
@@ -15,43 +11,30 @@ type TAutoMapFieldCustomSingleFn<TSource, TTarget extends object, U extends obje
|
|
|
15
11
|
}, store?: TFieldStore<TSource>) => void;
|
|
16
12
|
type TAutoMapConfig<TSource, TTarget extends object, U extends object = {}> = {
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @vi Trường đích trong schema GraphQL mà trường filter này ánh xạ tới. Nếu không cung cấp, tên trường nguồn sẽ được sử dụng làm trường đích.
|
|
14
|
+
* The target field in the GraphQL schema that this filter field maps to. If not provided, the source field name will be used as the target field.
|
|
20
15
|
*/
|
|
21
16
|
targetfield?: keyof TTarget;
|
|
22
17
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @vi Thao tác áp dụng cho trường filter. @default 'contains'
|
|
18
|
+
* The operation to apply for the filter field. @default 'contains'
|
|
25
19
|
*/
|
|
26
20
|
operation?: 'equal' | 'equalAndAny' | 'contains' | 'datetime' | 'number' | 'boolean' | 'enum';
|
|
27
21
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @vi Giá trị của enum schema nếu thao tác là 'enum'.
|
|
22
|
+
* Value of the enum schema if the operation is 'enum'.
|
|
30
23
|
*/
|
|
31
24
|
enumValue?: string;
|
|
32
25
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @vi Định dạng giá trị bộ lọc trước khi gửi vào query builder. Nếu giá trị trả về trống, bộ lọc sẽ bị bỏ qua.
|
|
26
|
+
* Format the filter value before passing it to query builder. If the returned value is empty, the filter is ignored.
|
|
35
27
|
*/
|
|
36
28
|
valueFormater?: (value: TFieldValid) => TFieldValid | undefined | null;
|
|
37
29
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* - Receives the current GraphQL builder, the value of the filter field, and the entire filter store for context.
|
|
41
|
-
* @vi
|
|
42
|
-
* - Hàm tùy chỉnh để áp dụng logic filter phức tạp không phù hợp với các thao tác 'equal' hoặc 'contains' tiêu chuẩn.
|
|
43
|
-
* - Nhận builder GraphQL hiện tại, giá trị của trường filter và toàn bộ store filter để có ngữ cảnh.
|
|
30
|
+
* Custom function to apply complex filter logic that doesn't fit standard 'equal' or 'contains' operations.
|
|
31
|
+
* Receives the current GraphQL builder, the value of the filter field, and the entire filter store for context.
|
|
44
32
|
*/
|
|
45
33
|
custom?: TAutoMapFieldCustomFn<TSource, TTarget, U>;
|
|
46
34
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* - Note: 'custom' takes precedence over 'customField'.
|
|
51
|
-
* @vi
|
|
52
|
-
* - Hàm tùy chỉnh để áp dụng logic filter cho từng giá trị đơn lẻ của trường filter.
|
|
53
|
-
* - Nhận builder GraphQL hiện tại, một giá trị đơn lẻ và toàn bộ store filter để có ngữ cảnh.
|
|
54
|
-
* - Lưu ý: 'custom' sẽ ghi đè 'customField'.
|
|
35
|
+
* Custom function to apply filter logic for each individual value of the filter field.
|
|
36
|
+
* Receives the current GraphQL builder, a single value, and the entire filter store for context.
|
|
37
|
+
* Note: 'custom' takes precedence over 'customField'.
|
|
55
38
|
*/
|
|
56
39
|
customField?: TAutoMapFieldCustomSingleFn<TSource, TTarget, U>;
|
|
57
40
|
};
|
|
@@ -63,32 +46,77 @@ type TFilterOption = {
|
|
|
63
46
|
export declare const mapLogic: (logic?: TLogic) => 'And' | 'Or';
|
|
64
47
|
/** Map sort direction for GraphQL queries @default 'asc' */
|
|
65
48
|
export declare const mapSortDirection: (direction?: TDirection) => 'ASC' | 'DESC';
|
|
49
|
+
/**
|
|
50
|
+
* Converter class that transforms `TFilterState` into a GraphQL `RequestParam` payload.
|
|
51
|
+
*/
|
|
66
52
|
export declare class TableFileterConverter<TSource extends Record<string, any>, TTarget extends object, U extends object = {}> {
|
|
67
53
|
private state;
|
|
68
54
|
private graphqlBuilder;
|
|
69
55
|
constructor(state: TFilterState<TSource>);
|
|
56
|
+
/**
|
|
57
|
+
* Wraps filter builder execution inside a logical scope (AND / OR).
|
|
58
|
+
*/
|
|
70
59
|
filterScope(fn: TFilterScopeFn<TSource, TTarget, U>, options?: TFilterOption): this;
|
|
60
|
+
/**
|
|
61
|
+
* Helper method to retrieve, format, and validate filter values for a specific field.
|
|
62
|
+
*/
|
|
71
63
|
private getFormattedValues;
|
|
64
|
+
/**
|
|
65
|
+
* Applies exact equality (`equal`) or `isAny` array comparison filter for a field.
|
|
66
|
+
*/
|
|
72
67
|
filterEqual(field: TFieldType<TSource>, targetField?: keyof TTarget, options?: TFilterOption & {
|
|
73
68
|
isAny?: boolean;
|
|
74
69
|
}): this;
|
|
70
|
+
/**
|
|
71
|
+
* Applies string containment (`contains`) filter for a field.
|
|
72
|
+
*/
|
|
75
73
|
filterContains(field: TFieldType<TSource>, targetField?: keyof TTarget, options?: TFilterOption): this;
|
|
74
|
+
/**
|
|
75
|
+
* Applies date/time comparisons (`before`, `after`, or `range` bounds) for a field.
|
|
76
|
+
*/
|
|
76
77
|
filterDatetime(field: TFieldType<TSource>, targetField?: keyof TTarget, options?: TFilterOption): this;
|
|
78
|
+
/**
|
|
79
|
+
* Applies boolean filter evaluation (`==true` or `==false`) for a field.
|
|
80
|
+
*/
|
|
77
81
|
filterBoolean(field: TFieldType<TSource>, targetField?: keyof TTarget, options?: TFilterOption): this;
|
|
82
|
+
/**
|
|
83
|
+
* Decodes encoded numeric operators (`=`, `<`, `≤`, `>`, `≥`) and applies number filters for a field.
|
|
84
|
+
*/
|
|
78
85
|
filterNumber(field: TFieldType<TSource>, targetField?: keyof TTarget, options?: TFilterOption): this;
|
|
86
|
+
/**
|
|
87
|
+
* Applies enum comparison filter (`enumValue.VALUE`) for a field.
|
|
88
|
+
*/
|
|
79
89
|
filterEnum(field: TFieldType<TSource>, targetField?: keyof TTarget, enumValue?: string, options?: TFilterOption): this;
|
|
90
|
+
/**
|
|
91
|
+
* Configures sorting and random seed ordering state into the GraphQL query builder.
|
|
92
|
+
*/
|
|
80
93
|
sort(param?: {
|
|
81
94
|
seed: {
|
|
82
95
|
targetField?: TFieldType<TSource>;
|
|
83
96
|
autoSave?: boolean;
|
|
84
97
|
};
|
|
85
98
|
}, options?: TFilterOption): this;
|
|
99
|
+
/**
|
|
100
|
+
* Applies multi-field quick search matching across target fields.
|
|
101
|
+
*/
|
|
86
102
|
quickSearch(fields: TFieldType<TSource> | TFieldType<TSource>[], options?: TFilterOption): this;
|
|
87
103
|
private currentObjectMap?;
|
|
104
|
+
/**
|
|
105
|
+
* Maps active fields in `TFilterState` to GraphQL builder rules according to a field mapping schema.
|
|
106
|
+
*/
|
|
88
107
|
autoMap: (objMap: TAutoMapConfigs<TSource, TTarget, U>, options?: TFilterOption) => this;
|
|
89
108
|
private prebuildFunc?;
|
|
109
|
+
/**
|
|
110
|
+
* Registers a callback executed prior to final AST construction.
|
|
111
|
+
*/
|
|
90
112
|
prebuild: (func: (requestParam: RequestParam<TTarget, U>) => RequestParam<TTarget, U>) => this;
|
|
113
|
+
/**
|
|
114
|
+
* Assembles and returns the final GraphQL query parameter payload.
|
|
115
|
+
*/
|
|
91
116
|
build(): import("../http-service/graphql/request-param").IRequestParamResult<TTarget, U>;
|
|
92
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Factory function to create a `TableFileterConverter` instance for converting filter state to GraphQL queries.
|
|
120
|
+
*/
|
|
93
121
|
export declare const createConvertToGraphQL: <TSource extends Record<string, any>, TTarget extends object, U extends object = {}>(state: TFilterState<TSource>) => TableFileterConverter<TSource, TTarget, U>;
|
|
94
122
|
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
|
+
import type { TFilterFieldConfigs } from './types';
|
|
2
3
|
import type { IFilterInputConfig, IFilterInputProps } from './filter-input.types';
|
|
3
|
-
export
|
|
4
|
+
export interface IFilterInputParam<T> extends IFilterInputConfig<T> {
|
|
5
|
+
fields?: TFilterFieldConfigs<T>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createFilterInput<T>(config: IFilterInputParam<T>): FC<IFilterInputProps<T>>;
|
|
4
8
|
export declare const filterInputClasses: {
|
|
5
9
|
root: string;
|
|
6
10
|
rootInner: string;
|
package/dist/types/filter-bar/{components/filter-input.types.d.ts → filter-input.types.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { BoxProps, PopperProps } from '@mui/material';
|
|
3
|
-
import type { TFieldType } from '
|
|
3
|
+
import type { TFieldType } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* RuleMatch defines the matching rules for displaying fields
|
|
6
6
|
* - 'always': This field will always be displayed regardless of keywords
|
|
@@ -21,19 +21,6 @@ export type TFieldMatch = {
|
|
|
21
21
|
/** Only applies when the rule is 'custom' */
|
|
22
22
|
validate?: (value: any) => boolean;
|
|
23
23
|
};
|
|
24
|
-
export type TFieldMatchConfig<T> = {
|
|
25
|
-
field: TFieldType<T>;
|
|
26
|
-
rules?: TFieldMatch | TFieldMatch[];
|
|
27
|
-
};
|
|
28
|
-
export type TFieldMatchConfigs<T> = Partial<Record<TFieldType<T>, Omit<TFieldMatchConfig<T>, 'field'>>>;
|
|
29
|
-
export interface IFieldInputConfig<T> {
|
|
30
|
-
field: TFieldType<T>;
|
|
31
|
-
label?: string;
|
|
32
|
-
/** If true, the field is visible in the input menu @default true */
|
|
33
|
-
visible?: boolean;
|
|
34
|
-
singleValue?: boolean;
|
|
35
|
-
}
|
|
36
|
-
export type TFieldInputConfigs<T> = Partial<Record<TFieldType<T>, Omit<IFieldInputConfig<T>, 'field'>>>;
|
|
37
24
|
export interface IFilterInputLayoutSlots {
|
|
38
25
|
beforeInput?: ReactNode;
|
|
39
26
|
afterInput?: ReactNode;
|
|
@@ -44,8 +31,6 @@ export interface IFilterInputBase {
|
|
|
44
31
|
fullWidth?: boolean;
|
|
45
32
|
}
|
|
46
33
|
export interface IFilterInputConfig<T> extends IFilterInputBase, IFilterInputLayoutSlots {
|
|
47
|
-
fields: TFieldInputConfigs<T>;
|
|
48
|
-
matches?: TFieldMatchConfigs<T>;
|
|
49
34
|
/** Enable or disable quick search, @default false */
|
|
50
35
|
enableQuickSearch?: boolean;
|
|
51
36
|
/** Placeholder text for input field */
|
package/dist/types/filter-bar/{components/filter-input.units.d.ts → filter-input.units.d.ts}
RENAMED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
2
|
import type { IconButtonProps } from '@mui/material';
|
|
3
|
-
import type {
|
|
4
|
-
export
|
|
3
|
+
import type { TFieldType, TFilterFieldConfig, TFilterFieldConfigs } from './types';
|
|
4
|
+
export type TInputMatchedField<T> = TFilterFieldConfig<T> & {
|
|
5
|
+
field: TFieldType<T>;
|
|
6
|
+
};
|
|
7
|
+
export declare function getFieldsByMatches<T>(config: {
|
|
8
|
+
fields?: TFilterFieldConfigs<T>;
|
|
9
|
+
}, keywords: string): TInputMatchedField<T>[];
|
|
5
10
|
interface InputAdornmentLeftProps {
|
|
6
11
|
onSearch?: IconButtonProps['onClick'];
|
|
7
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export { filterMenuClasses } from './filter-menu.styled';
|
|
1
2
|
import type { FC } from 'react';
|
|
2
|
-
import type { IFilterMenuProps } from './types';
|
|
3
|
-
import type { IFilterMenuConfig } from './types';
|
|
3
|
+
import type { IFilterMenuParam, IFilterMenuProps } from './filter-menu.types';
|
|
4
4
|
/**
|
|
5
5
|
* Factory function that creates a `FilterMenu` component from a static field configuration.
|
|
6
6
|
*
|
|
@@ -14,16 +14,7 @@ import type { IFilterMenuConfig } from './types';
|
|
|
14
14
|
* All state (open/close, selected field) is local; filter values are read/written through
|
|
15
15
|
* `FilterBarContext` via `useFilterActions`.
|
|
16
16
|
*
|
|
17
|
-
* @param
|
|
17
|
+
* @param param - Static filter-menu configuration (fields, validation, slots, etc.)
|
|
18
18
|
* @returns A React FC ready to be dropped anywhere inside a `FilterBarProvider`
|
|
19
19
|
*/
|
|
20
|
-
export declare function createFilterMenu<T>(
|
|
21
|
-
/** CSS class names used by the `FilterMenu` component for external style overrides. */
|
|
22
|
-
export declare const filterMenuClasses: {
|
|
23
|
-
root: string;
|
|
24
|
-
input: string;
|
|
25
|
-
beforeInput: string;
|
|
26
|
-
menu: string;
|
|
27
|
-
menuItem: string;
|
|
28
|
-
menuItemInner: string;
|
|
29
|
-
};
|
|
20
|
+
export declare function createFilterMenu<T>(param: IFilterMenuParam<T>): FC<IFilterMenuProps<T>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FormValidator } from '../form/validator';
|
|
3
|
+
import type { TFieldModelValid, TFieldType } from './types';
|
|
4
|
+
import type { IFilterMenuParam, IFilterMenuFormProps } from './filter-menu.types';
|
|
5
|
+
/**
|
|
6
|
+
* Builds a map of `FormValidator` instances keyed by field name.
|
|
7
|
+
* Each validator is constructed from the validation rules defined in `config.validation`.
|
|
8
|
+
* Fields with no validation config are skipped.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateValidatorMap<T>(param: IFilterMenuParam<T>): Record<TFieldType<T>, FormValidator<Partial<TFieldModelValid<T>>>>;
|
|
13
|
+
/**
|
|
14
|
+
* Builds a map of form input components keyed by field name.
|
|
15
|
+
* If a field defines a custom `MenuForm`, that is used; otherwise falls back to
|
|
16
|
+
* default `createFormFieldString()` free-text component.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateFormInputMap<T>(param: IFilterMenuParam<T>): Record<TFieldType<T>, import("react").ComponentType<IFilterMenuFormProps<T>>>;
|
|
21
|
+
export declare const getQuickSearchTooltip: (currentHint?: string | ((currentHint: string) => string) | undefined) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Normalises raw `IFilterMenuParam`:
|
|
24
|
+
* - Injects the quick-search pseudo-field when `enableQuickSearch` is `true`
|
|
25
|
+
* - Merges validation rules
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateConfigs<T>(param: IFilterMenuParam<T>): IFilterMenuParam<T>;
|
|
30
|
+
export { groupFields } from './helpers';
|
|
31
|
+
export type { IFieldGroup } from './helpers';
|