@ram_28/kf-ai-sdk 1.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/LICENSE +21 -0
- package/README.md +840 -0
- package/dist/api/client.d.ts +78 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/datetime.d.ts +21 -0
- package/dist/api/datetime.d.ts.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/metadata.d.ts +75 -0
- package/dist/api/metadata.d.ts.map +1 -0
- package/dist/components/hooks/index.d.ts +8 -0
- package/dist/components/hooks/index.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/index.d.ts +5 -0
- package/dist/components/hooks/useFilter/index.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts +33 -0
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/types.d.ts +137 -0
- package/dist/components/hooks/useFilter/types.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/useFilter.d.ts +3 -0
- package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/validation.utils.d.ts +38 -0
- package/dist/components/hooks/useFilter/validation.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/apiClient.d.ts +71 -0
- package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -0
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +28 -0
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/index.d.ts +6 -0
- package/dist/components/hooks/useForm/index.d.ts.map +1 -0
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +88 -0
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +28 -0
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts +29 -0
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/types.d.ts +412 -0
- package/dist/components/hooks/useForm/types.d.ts.map +1 -0
- package/dist/components/hooks/useForm/useForm.d.ts +3 -0
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/apiClient.d.ts +99 -0
- package/dist/components/hooks/useKanban/apiClient.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/context.d.ts +4 -0
- package/dist/components/hooks/useKanban/context.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/dragDropManager.d.ts +27 -0
- package/dist/components/hooks/useKanban/dragDropManager.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/index.d.ts +6 -0
- package/dist/components/hooks/useKanban/index.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/types.d.ts +438 -0
- package/dist/components/hooks/useKanban/types.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/useKanban.d.ts +3 -0
- package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/useKanbanSimple.d.ts +62 -0
- package/dist/components/hooks/useKanban/useKanbanSimple.d.ts.map +1 -0
- package/dist/components/hooks/useTable/index.d.ts +3 -0
- package/dist/components/hooks/useTable/index.d.ts.map +1 -0
- package/dist/components/hooks/useTable/types.d.ts +107 -0
- package/dist/components/hooks/useTable/types.d.ts.map +1 -0
- package/dist/components/hooks/useTable/useTable.d.ts +8 -0
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/kanban/Kanban.d.ts +12 -0
- package/dist/components/ui/kanban/Kanban.d.ts.map +1 -0
- package/dist/components/ui/kanban/index.d.ts +2 -0
- package/dist/components/ui/kanban/index.d.ts.map +1 -0
- package/dist/index.cjs +45 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +6522 -0
- package/dist/types/base-fields.d.ts +182 -0
- package/dist/types/base-fields.d.ts.map +1 -0
- package/dist/types/common.d.ts +238 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/cn.d.ts +7 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +52 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +98 -0
- package/sdk/api/client.ts +447 -0
- package/sdk/api/datetime.ts +33 -0
- package/sdk/api/index.ts +61 -0
- package/sdk/api/metadata.ts +148 -0
- package/sdk/components/hooks/index.ts +34 -0
- package/sdk/components/hooks/useFilter/index.ts +37 -0
- package/sdk/components/hooks/useFilter/payloadBuilder.utils.ts +298 -0
- package/sdk/components/hooks/useFilter/types.ts +158 -0
- package/sdk/components/hooks/useFilter/useFilter.llm.txt +497 -0
- package/sdk/components/hooks/useFilter/useFilter.ts +494 -0
- package/sdk/components/hooks/useFilter/validation.utils.ts +401 -0
- package/sdk/components/hooks/useForm/apiClient.ts +441 -0
- package/sdk/components/hooks/useForm/expressionValidator.utils.ts +444 -0
- package/sdk/components/hooks/useForm/index.ts +64 -0
- package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +482 -0
- package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +424 -0
- package/sdk/components/hooks/useForm/schemaParser.utils.ts +519 -0
- package/sdk/components/hooks/useForm/types.ts +630 -0
- package/sdk/components/hooks/useForm/useForm.llm.txt +340 -0
- package/sdk/components/hooks/useForm/useForm.ts +821 -0
- package/sdk/components/hooks/useKanban/apiClient.ts +494 -0
- package/sdk/components/hooks/useKanban/context.ts +14 -0
- package/sdk/components/hooks/useKanban/dragDropManager.ts +529 -0
- package/sdk/components/hooks/useKanban/index.ts +63 -0
- package/sdk/components/hooks/useKanban/types.ts +606 -0
- package/sdk/components/hooks/useKanban/useKanban.llm.txt +482 -0
- package/sdk/components/hooks/useKanban/useKanban.ts +725 -0
- package/sdk/components/hooks/useKanban/useKanbanSimple.ts +389 -0
- package/sdk/components/hooks/useTable/index.ts +5 -0
- package/sdk/components/hooks/useTable/types.ts +154 -0
- package/sdk/components/hooks/useTable/useTable.llm.txt +344 -0
- package/sdk/components/hooks/useTable/useTable.ts +413 -0
- package/sdk/components/index.ts +15 -0
- package/sdk/components/ui/index.ts +2 -0
- package/sdk/components/ui/kanban/Kanban.tsx +134 -0
- package/sdk/components/ui/kanban/index.ts +11 -0
- package/sdk/index.ts +13 -0
- package/sdk/types/base-fields.ts +221 -0
- package/sdk/types/common.ts +306 -0
- package/sdk/types/index.ts +5 -0
- package/sdk/utils/cn.ts +10 -0
- package/sdk/utils/formatting.ts +212 -0
- package/sdk/utils/index.ts +5 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { CurrencyValue, JSONValue } from '../types/base-fields';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Data formatting utilities for display and conversion
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Format currency value for display
|
|
9
|
+
*/
|
|
10
|
+
export function formatCurrency(value: CurrencyValue): string {
|
|
11
|
+
if (typeof value === 'string') {
|
|
12
|
+
return value; // Already formatted
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (typeof value === 'object' && value !== null) {
|
|
16
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
17
|
+
style: 'currency',
|
|
18
|
+
currency: value.currency,
|
|
19
|
+
});
|
|
20
|
+
return formatter.format(value.value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return 'Invalid Currency';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parse currency string to currency object
|
|
28
|
+
*/
|
|
29
|
+
export function parseCurrency(value: string): CurrencyValue | null {
|
|
30
|
+
// Try to parse "USD 100.50" or "100.50 USD" format
|
|
31
|
+
const match = value.match(/^(?:([A-Z]{3})\s+(\d+\.?\d*))|(?:(\d+\.?\d*)\s+([A-Z]{3}))$/);
|
|
32
|
+
|
|
33
|
+
if (match) {
|
|
34
|
+
const currency = match[1] || match[4];
|
|
35
|
+
const amount = parseFloat(match[2] || match[3]);
|
|
36
|
+
|
|
37
|
+
if (!isNaN(amount)) {
|
|
38
|
+
return { value: amount, currency };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Format date for display
|
|
47
|
+
*/
|
|
48
|
+
export function formatDate(date: Date, format: 'short' | 'medium' | 'long' = 'medium'): string {
|
|
49
|
+
if (!(date instanceof Date) || isNaN(date.getTime())) {
|
|
50
|
+
return 'Invalid Date';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const options: Intl.DateTimeFormatOptions = {
|
|
54
|
+
short: { dateStyle: 'short' as const },
|
|
55
|
+
medium: { dateStyle: 'medium' as const },
|
|
56
|
+
long: { dateStyle: 'long' as const },
|
|
57
|
+
}[format];
|
|
58
|
+
|
|
59
|
+
return new Intl.DateTimeFormat('en-US', options).format(date);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Format datetime for display
|
|
64
|
+
*/
|
|
65
|
+
export function formatDateTime(date: Date, format: 'short' | 'medium' | 'long' = 'medium'): string {
|
|
66
|
+
if (!(date instanceof Date) || isNaN(date.getTime())) {
|
|
67
|
+
return 'Invalid Date';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const options: Intl.DateTimeFormatOptions = {
|
|
71
|
+
short: { dateStyle: 'short' as const, timeStyle: 'short' as const },
|
|
72
|
+
medium: { dateStyle: 'medium' as const, timeStyle: 'medium' as const },
|
|
73
|
+
long: { dateStyle: 'long' as const, timeStyle: 'long' as const },
|
|
74
|
+
}[format];
|
|
75
|
+
|
|
76
|
+
return new Intl.DateTimeFormat('en-US', options).format(date);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Format number with precision
|
|
81
|
+
*/
|
|
82
|
+
export function formatNumber(value: number, precision: number = 2): string {
|
|
83
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
84
|
+
return 'Invalid Number';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return value.toFixed(precision);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Format JSON value for display
|
|
92
|
+
*/
|
|
93
|
+
export function formatJSON(value: JSONValue, indent: number = 2): string {
|
|
94
|
+
try {
|
|
95
|
+
return JSON.stringify(value, null, indent);
|
|
96
|
+
} catch {
|
|
97
|
+
return 'Invalid JSON';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Format array values for display
|
|
103
|
+
*/
|
|
104
|
+
export function formatArray<T>(
|
|
105
|
+
array: T[],
|
|
106
|
+
formatter?: (item: T) => string,
|
|
107
|
+
separator: string = ', '
|
|
108
|
+
): string {
|
|
109
|
+
if (!Array.isArray(array)) {
|
|
110
|
+
return 'Invalid Array';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (formatter) {
|
|
114
|
+
return array.map(formatter).join(separator);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return array.map(item => String(item)).join(separator);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Format boolean for display
|
|
122
|
+
*/
|
|
123
|
+
export function formatBoolean(value: boolean, options?: {
|
|
124
|
+
trueLabel?: string;
|
|
125
|
+
falseLabel?: string;
|
|
126
|
+
}): string {
|
|
127
|
+
if (typeof value !== 'boolean') {
|
|
128
|
+
return 'Invalid Boolean';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return value
|
|
132
|
+
? (options?.trueLabel || 'Yes')
|
|
133
|
+
: (options?.falseLabel || 'No');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Truncate string with ellipsis
|
|
138
|
+
*/
|
|
139
|
+
export function truncateString(value: string, maxLength: number = 50): string {
|
|
140
|
+
if (typeof value !== 'string') {
|
|
141
|
+
return 'Invalid String';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (value.length <= maxLength) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return value.slice(0, maxLength - 3) + '...';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Format text area content for display (handle line breaks)
|
|
153
|
+
*/
|
|
154
|
+
export function formatTextArea(value: string, maxLines?: number): string {
|
|
155
|
+
if (typeof value !== 'string') {
|
|
156
|
+
return 'Invalid Text';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const lines = value.split('\n');
|
|
160
|
+
|
|
161
|
+
if (maxLines && lines.length > maxLines) {
|
|
162
|
+
return lines.slice(0, maxLines).join('\n') + '\n...';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Generic formatter that automatically detects field type and formats accordingly
|
|
170
|
+
*/
|
|
171
|
+
export function formatFieldValue(
|
|
172
|
+
value: any,
|
|
173
|
+
fieldType?: 'id' | 'string' | 'textarea' | 'number' | 'boolean' | 'date' | 'datetime' | 'currency' | 'json' | 'array'
|
|
174
|
+
): string {
|
|
175
|
+
if (value === null || value === undefined) {
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Auto-detect type if not provided
|
|
180
|
+
if (!fieldType) {
|
|
181
|
+
if (typeof value === 'boolean') fieldType = 'boolean';
|
|
182
|
+
else if (typeof value === 'number') fieldType = 'number';
|
|
183
|
+
else if (value instanceof Date) fieldType = 'datetime';
|
|
184
|
+
else if (Array.isArray(value)) fieldType = 'array';
|
|
185
|
+
else if (typeof value === 'object') fieldType = 'json';
|
|
186
|
+
else fieldType = 'string';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
switch (fieldType) {
|
|
190
|
+
case 'id':
|
|
191
|
+
case 'string':
|
|
192
|
+
return String(value);
|
|
193
|
+
case 'textarea':
|
|
194
|
+
return formatTextArea(String(value));
|
|
195
|
+
case 'number':
|
|
196
|
+
return formatNumber(value);
|
|
197
|
+
case 'boolean':
|
|
198
|
+
return formatBoolean(value);
|
|
199
|
+
case 'date':
|
|
200
|
+
return formatDate(value);
|
|
201
|
+
case 'datetime':
|
|
202
|
+
return formatDateTime(value);
|
|
203
|
+
case 'currency':
|
|
204
|
+
return formatCurrency(value);
|
|
205
|
+
case 'json':
|
|
206
|
+
return formatJSON(value);
|
|
207
|
+
case 'array':
|
|
208
|
+
return formatArray(value);
|
|
209
|
+
default:
|
|
210
|
+
return String(value);
|
|
211
|
+
}
|
|
212
|
+
}
|