@portel/photon-core 2.4.0 → 2.5.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.
Files changed (89) hide show
  1. package/dist/asset-discovery.d.ts.map +1 -1
  2. package/dist/asset-discovery.js +2 -1
  3. package/dist/asset-discovery.js.map +1 -1
  4. package/dist/base.d.ts +6 -0
  5. package/dist/base.d.ts.map +1 -1
  6. package/dist/base.js +11 -1
  7. package/dist/base.js.map +1 -1
  8. package/dist/collections/ReactiveArray.d.ts +97 -0
  9. package/dist/collections/ReactiveArray.d.ts.map +1 -0
  10. package/dist/collections/ReactiveArray.js +158 -0
  11. package/dist/collections/ReactiveArray.js.map +1 -0
  12. package/dist/collections/ReactiveMap.d.ts +50 -0
  13. package/dist/collections/ReactiveMap.d.ts.map +1 -0
  14. package/dist/collections/ReactiveMap.js +71 -0
  15. package/dist/collections/ReactiveMap.js.map +1 -0
  16. package/dist/collections/ReactiveSet.d.ts +50 -0
  17. package/dist/collections/ReactiveSet.d.ts.map +1 -0
  18. package/dist/collections/ReactiveSet.js +71 -0
  19. package/dist/collections/ReactiveSet.js.map +1 -0
  20. package/dist/collections/index.d.ts +44 -0
  21. package/dist/collections/index.d.ts.map +1 -0
  22. package/dist/collections/index.js +44 -0
  23. package/dist/collections/index.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +16 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/types.d.ts +2 -0
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/ui-types/Cards.d.ts +139 -0
  31. package/dist/ui-types/Cards.d.ts.map +1 -0
  32. package/dist/ui-types/Cards.js +235 -0
  33. package/dist/ui-types/Cards.js.map +1 -0
  34. package/dist/ui-types/Chart.d.ts +136 -0
  35. package/dist/ui-types/Chart.d.ts.map +1 -0
  36. package/dist/ui-types/Chart.js +188 -0
  37. package/dist/ui-types/Chart.js.map +1 -0
  38. package/dist/ui-types/Field.d.ts +342 -0
  39. package/dist/ui-types/Field.d.ts.map +1 -0
  40. package/dist/ui-types/Field.js +200 -0
  41. package/dist/ui-types/Field.js.map +1 -0
  42. package/dist/ui-types/FieldRenderer.d.ts +32 -0
  43. package/dist/ui-types/FieldRenderer.d.ts.map +1 -0
  44. package/dist/ui-types/FieldRenderer.js +277 -0
  45. package/dist/ui-types/FieldRenderer.js.map +1 -0
  46. package/dist/ui-types/Form.d.ts +212 -0
  47. package/dist/ui-types/Form.d.ts.map +1 -0
  48. package/dist/ui-types/Form.js +278 -0
  49. package/dist/ui-types/Form.js.map +1 -0
  50. package/dist/ui-types/Progress.d.ts +130 -0
  51. package/dist/ui-types/Progress.d.ts.map +1 -0
  52. package/dist/ui-types/Progress.js +191 -0
  53. package/dist/ui-types/Progress.js.map +1 -0
  54. package/dist/ui-types/Stats.d.ts +108 -0
  55. package/dist/ui-types/Stats.d.ts.map +1 -0
  56. package/dist/ui-types/Stats.js +162 -0
  57. package/dist/ui-types/Stats.js.map +1 -0
  58. package/dist/ui-types/Table.d.ts +206 -0
  59. package/dist/ui-types/Table.d.ts.map +1 -0
  60. package/dist/ui-types/Table.js +367 -0
  61. package/dist/ui-types/Table.js.map +1 -0
  62. package/dist/ui-types/base.d.ts +17 -0
  63. package/dist/ui-types/base.d.ts.map +1 -0
  64. package/dist/ui-types/base.js +18 -0
  65. package/dist/ui-types/base.js.map +1 -0
  66. package/dist/ui-types/index.d.ts +42 -0
  67. package/dist/ui-types/index.d.ts.map +1 -0
  68. package/dist/ui-types/index.js +50 -0
  69. package/dist/ui-types/index.js.map +1 -0
  70. package/package.json +2 -2
  71. package/src/asset-discovery.ts +2 -1
  72. package/src/base.ts +13 -1
  73. package/src/collections/ReactiveArray.ts +179 -0
  74. package/src/collections/ReactiveMap.ts +81 -0
  75. package/src/collections/ReactiveSet.ts +81 -0
  76. package/src/collections/index.ts +44 -0
  77. package/src/index.ts +75 -0
  78. package/src/types.ts +2 -0
  79. package/src/ui-types/Cards.ts +286 -0
  80. package/src/ui-types/Chart.ts +239 -0
  81. package/src/ui-types/Field.ts +594 -0
  82. package/src/ui-types/FieldRenderer.ts +364 -0
  83. package/src/ui-types/Form.ts +363 -0
  84. package/src/ui-types/Progress.ts +237 -0
  85. package/src/ui-types/Stats.ts +204 -0
  86. package/src/ui-types/Table.ts +438 -0
  87. package/src/ui-types/base.ts +25 -0
  88. package/src/ui-types/index.ts +96 -0
  89. package/src/ui-types/ui-types.test.ts +444 -0
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Chart - Purpose-driven type for data visualization
3
+ *
4
+ * Automatically renders as a chart with the specified type.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * async revenue() {
9
+ * return new Chart('line')
10
+ * .title('Monthly Revenue')
11
+ * .labels(['Jan', 'Feb', 'Mar', 'Apr'])
12
+ * .series('Revenue', [1000, 1500, 1200, 1800])
13
+ * .series('Costs', [800, 900, 850, 950]);
14
+ * }
15
+ *
16
+ * async distribution() {
17
+ * return new Chart('pie')
18
+ * .title('User Distribution')
19
+ * .data([
20
+ * { label: 'Free', value: 1000 },
21
+ * { label: 'Pro', value: 500 },
22
+ * { label: 'Enterprise', value: 100 },
23
+ * ]);
24
+ * }
25
+ * ```
26
+ */
27
+ import { PhotonUIType } from './base.js';
28
+ export type ChartType = 'line' | 'bar' | 'pie' | 'doughnut' | 'area' | 'scatter' | 'radar';
29
+ export interface ChartSeries {
30
+ name: string;
31
+ data: number[];
32
+ color?: string;
33
+ }
34
+ export interface ChartDataPoint {
35
+ label: string;
36
+ value: number;
37
+ color?: string;
38
+ }
39
+ export interface ChartOptions {
40
+ title?: string;
41
+ subtitle?: string;
42
+ legend?: boolean | 'top' | 'bottom' | 'left' | 'right';
43
+ stacked?: boolean;
44
+ showGrid?: boolean;
45
+ showValues?: boolean;
46
+ animate?: boolean;
47
+ height?: number;
48
+ colors?: string[];
49
+ xAxisLabel?: string;
50
+ yAxisLabel?: string;
51
+ }
52
+ export declare class Chart extends PhotonUIType {
53
+ readonly _photonType: "chart";
54
+ private _type;
55
+ private _labels;
56
+ private _series;
57
+ private _data;
58
+ private _options;
59
+ /**
60
+ * Create a new Chart
61
+ * @param type Chart type (line, bar, pie, etc.)
62
+ */
63
+ constructor(type?: ChartType);
64
+ /**
65
+ * Set chart title
66
+ */
67
+ title(title: string): this;
68
+ /**
69
+ * Set chart subtitle
70
+ */
71
+ subtitle(subtitle: string): this;
72
+ /**
73
+ * Set X-axis labels (for line, bar, area charts)
74
+ */
75
+ labels(labels: string[]): this;
76
+ /**
77
+ * Add a data series (for line, bar, area charts)
78
+ */
79
+ series(name: string, data: number[], color?: string): this;
80
+ /**
81
+ * Set pie/doughnut data points
82
+ */
83
+ data(points: ChartDataPoint[] | Array<{
84
+ label: string;
85
+ value: number;
86
+ }>): this;
87
+ /**
88
+ * Configure legend
89
+ */
90
+ legend(position?: boolean | 'top' | 'bottom' | 'left' | 'right'): this;
91
+ /**
92
+ * Enable stacked mode (for bar/area charts)
93
+ */
94
+ stacked(enabled?: boolean): this;
95
+ /**
96
+ * Show/hide grid lines
97
+ */
98
+ grid(enabled?: boolean): this;
99
+ /**
100
+ * Show values on chart
101
+ */
102
+ showValues(enabled?: boolean): this;
103
+ /**
104
+ * Enable/disable animations
105
+ */
106
+ animate(enabled?: boolean): this;
107
+ /**
108
+ * Set chart height
109
+ */
110
+ height(pixels: number): this;
111
+ /**
112
+ * Set color palette
113
+ */
114
+ colors(colors: string[]): this;
115
+ /**
116
+ * Set X-axis label
117
+ */
118
+ xAxis(label: string): this;
119
+ /**
120
+ * Set Y-axis label
121
+ */
122
+ yAxis(label: string): this;
123
+ toJSON(): {
124
+ _photonType: "chart";
125
+ chartType: ChartType;
126
+ labels: string[];
127
+ series: ChartSeries[];
128
+ data: ChartDataPoint[];
129
+ options: ChartOptions;
130
+ };
131
+ /**
132
+ * Render as plain text for MCP clients
133
+ */
134
+ toString(): string;
135
+ }
136
+ //# sourceMappingURL=Chart.d.ts.map
@@ -0,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,188 @@
1
+ /**
2
+ * Chart - Purpose-driven type for data visualization
3
+ *
4
+ * Automatically renders as a chart with the specified type.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * async revenue() {
9
+ * return new Chart('line')
10
+ * .title('Monthly Revenue')
11
+ * .labels(['Jan', 'Feb', 'Mar', 'Apr'])
12
+ * .series('Revenue', [1000, 1500, 1200, 1800])
13
+ * .series('Costs', [800, 900, 850, 950]);
14
+ * }
15
+ *
16
+ * async distribution() {
17
+ * return new Chart('pie')
18
+ * .title('User Distribution')
19
+ * .data([
20
+ * { label: 'Free', value: 1000 },
21
+ * { label: 'Pro', value: 500 },
22
+ * { label: 'Enterprise', value: 100 },
23
+ * ]);
24
+ * }
25
+ * ```
26
+ */
27
+ import { PhotonUIType } from './base.js';
28
+ export class Chart extends PhotonUIType {
29
+ _photonType = 'chart';
30
+ _type;
31
+ _labels = [];
32
+ _series = [];
33
+ _data = []; // For pie/doughnut
34
+ _options = {
35
+ legend: true,
36
+ showGrid: true,
37
+ animate: true,
38
+ };
39
+ /**
40
+ * Create a new Chart
41
+ * @param type Chart type (line, bar, pie, etc.)
42
+ */
43
+ constructor(type = 'line') {
44
+ super();
45
+ this._type = type;
46
+ }
47
+ /**
48
+ * Set chart title
49
+ */
50
+ title(title) {
51
+ this._options.title = title;
52
+ return this;
53
+ }
54
+ /**
55
+ * Set chart subtitle
56
+ */
57
+ subtitle(subtitle) {
58
+ this._options.subtitle = subtitle;
59
+ return this;
60
+ }
61
+ /**
62
+ * Set X-axis labels (for line, bar, area charts)
63
+ */
64
+ labels(labels) {
65
+ this._labels = labels;
66
+ return this;
67
+ }
68
+ /**
69
+ * Add a data series (for line, bar, area charts)
70
+ */
71
+ series(name, data, color) {
72
+ this._series.push({ name, data, color });
73
+ return this;
74
+ }
75
+ /**
76
+ * Set pie/doughnut data points
77
+ */
78
+ data(points) {
79
+ this._data = points;
80
+ return this;
81
+ }
82
+ /**
83
+ * Configure legend
84
+ */
85
+ legend(position = true) {
86
+ this._options.legend = position;
87
+ return this;
88
+ }
89
+ /**
90
+ * Enable stacked mode (for bar/area charts)
91
+ */
92
+ stacked(enabled = true) {
93
+ this._options.stacked = enabled;
94
+ return this;
95
+ }
96
+ /**
97
+ * Show/hide grid lines
98
+ */
99
+ grid(enabled = true) {
100
+ this._options.showGrid = enabled;
101
+ return this;
102
+ }
103
+ /**
104
+ * Show values on chart
105
+ */
106
+ showValues(enabled = true) {
107
+ this._options.showValues = enabled;
108
+ return this;
109
+ }
110
+ /**
111
+ * Enable/disable animations
112
+ */
113
+ animate(enabled = true) {
114
+ this._options.animate = enabled;
115
+ return this;
116
+ }
117
+ /**
118
+ * Set chart height
119
+ */
120
+ height(pixels) {
121
+ this._options.height = pixels;
122
+ return this;
123
+ }
124
+ /**
125
+ * Set color palette
126
+ */
127
+ colors(colors) {
128
+ this._options.colors = colors;
129
+ return this;
130
+ }
131
+ /**
132
+ * Set X-axis label
133
+ */
134
+ xAxis(label) {
135
+ this._options.xAxisLabel = label;
136
+ return this;
137
+ }
138
+ /**
139
+ * Set Y-axis label
140
+ */
141
+ yAxis(label) {
142
+ this._options.yAxisLabel = label;
143
+ return this;
144
+ }
145
+ toJSON() {
146
+ return {
147
+ _photonType: this._photonType,
148
+ chartType: this._type,
149
+ labels: this._labels,
150
+ series: this._series,
151
+ data: this._data,
152
+ options: this._options,
153
+ };
154
+ }
155
+ /**
156
+ * Render as plain text for MCP clients
157
+ */
158
+ toString() {
159
+ const lines = [];
160
+ if (this._options.title) {
161
+ lines.push(`## ${this._options.title}`);
162
+ if (this._options.subtitle)
163
+ lines.push(this._options.subtitle);
164
+ lines.push('');
165
+ }
166
+ // Pie/doughnut: show as list
167
+ if ((this._type === 'pie' || this._type === 'doughnut') && this._data.length > 0) {
168
+ const total = this._data.reduce((sum, d) => sum + d.value, 0);
169
+ for (const d of this._data) {
170
+ const pct = total > 0 ? ((d.value / total) * 100).toFixed(1) : '0';
171
+ lines.push(`- ${d.label}: ${d.value} (${pct}%)`);
172
+ }
173
+ return lines.join('\n');
174
+ }
175
+ // Series charts: show as table
176
+ if (this._series.length > 0 && this._labels.length > 0) {
177
+ const headers = ['', ...this._series.map(s => s.name)];
178
+ lines.push('| ' + headers.join(' | ') + ' |');
179
+ lines.push('| ' + headers.map(() => '---').join(' | ') + ' |');
180
+ for (let i = 0; i < this._labels.length; i++) {
181
+ const row = [this._labels[i], ...this._series.map(s => String(s.data[i] ?? ''))];
182
+ lines.push('| ' + row.join(' | ') + ' |');
183
+ }
184
+ }
185
+ return lines.join('\n');
186
+ }
187
+ }
188
+ //# sourceMappingURL=Chart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chart.js","sourceRoot":"","sources":["../../src/ui-types/Chart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AA8BzC,MAAM,OAAO,KAAM,SAAQ,YAAY;IAC5B,WAAW,GAAG,OAAgB,CAAC;IAEhC,KAAK,CAAY;IACjB,OAAO,GAAa,EAAE,CAAC;IACvB,OAAO,GAAkB,EAAE,CAAC;IAC5B,KAAK,GAAqB,EAAE,CAAC,CAAC,mBAAmB;IACjD,QAAQ,GAAiB;QAC/B,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,IAAI;KACd,CAAC;IAEF;;;OAGG;IACH,YAAY,OAAkB,MAAM;QAClC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,QAAgB;QACvB,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAA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CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;gBACjF,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,342 @@
1
+ /**
2
+ * Field - Unified field system for UI types
3
+ *
4
+ * Fields define how data is displayed. They work across Table, Cards, List, etc.
5
+ * Each field type handles its own rendering logic and formatting.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Field, Table, Cards } from '@portel/photon-core';
10
+ *
11
+ * // Define fields once, use anywhere
12
+ * const productFields = [
13
+ * Field.image('thumbnail', { width: 80, rounded: true }),
14
+ * Field.text('name', { link: '/products/{id}' }),
15
+ * Field.price('price', { original: 'msrp', currency: 'USD' }),
16
+ * Field.rating('rating', { count: 'reviewCount' }),
17
+ * Field.badge('status', { colors: { active: 'green' } }),
18
+ * Field.actions([{ label: 'Edit', method: 'edit' }]),
19
+ * ];
20
+ *
21
+ * // Works in Table
22
+ * new Table().fields(productFields).rows(data);
23
+ *
24
+ * // Works in Cards
25
+ * new Cards().fields(productFields).items(data);
26
+ * ```
27
+ */
28
+ export type FieldAlignment = 'left' | 'center' | 'right';
29
+ export interface BaseFieldOptions {
30
+ /** Display label (auto-inferred from source if not provided) */
31
+ label?: string;
32
+ /** Enable sorting on this field */
33
+ sortable?: boolean;
34
+ /** Sort by different field */
35
+ sortBy?: string;
36
+ /** Text alignment */
37
+ align?: FieldAlignment;
38
+ /** Column width (CSS value like '100px', '20%') */
39
+ columnWidth?: string;
40
+ /** Text to show when value is empty/null */
41
+ emptyText?: string;
42
+ /** Hide this field */
43
+ hidden?: boolean;
44
+ /** Additional CSS class */
45
+ className?: string;
46
+ /** Tooltip text */
47
+ tooltip?: string;
48
+ }
49
+ export interface TextFieldOptions extends BaseFieldOptions {
50
+ /** Make text a link. Use {field} for interpolation */
51
+ link?: string;
52
+ /** Open link in new tab */
53
+ external?: boolean;
54
+ /** Truncate text to max characters */
55
+ truncate?: number;
56
+ /** Text variant */
57
+ variant?: 'heading' | 'body' | 'caption' | 'code';
58
+ /** Make text copyable */
59
+ copyable?: boolean;
60
+ }
61
+ export interface EmailFieldOptions extends BaseFieldOptions {
62
+ /** Show as mailto link */
63
+ linked?: boolean;
64
+ }
65
+ export interface UrlFieldOptions extends BaseFieldOptions {
66
+ /** Display text (otherwise shows URL) */
67
+ text?: string;
68
+ /** Truncate URL display */
69
+ truncate?: number;
70
+ }
71
+ export interface PhoneFieldOptions extends BaseFieldOptions {
72
+ /** Show as tel: link */
73
+ linked?: boolean;
74
+ /** Format pattern */
75
+ format?: string;
76
+ }
77
+ export interface NumberFieldOptions extends BaseFieldOptions {
78
+ /** Decimal places */
79
+ decimals?: number;
80
+ /** Use compact notation (1.2K, 5M) */
81
+ compact?: boolean;
82
+ /** Prefix text */
83
+ prefix?: string;
84
+ /** Suffix text */
85
+ suffix?: string;
86
+ /** Locale for formatting */
87
+ locale?: string;
88
+ }
89
+ export interface CurrencyFieldOptions extends BaseFieldOptions {
90
+ /** Currency code (USD, EUR, etc.) */
91
+ currency?: string;
92
+ /** Locale for formatting */
93
+ locale?: string;
94
+ /** Show currency symbol */
95
+ showSymbol?: boolean;
96
+ /** Decimal places */
97
+ decimals?: number;
98
+ }
99
+ export interface PercentFieldOptions extends BaseFieldOptions {
100
+ /** Decimal places */
101
+ decimals?: number;
102
+ /** Multiply by 100 (if value is 0.5 for 50%) */
103
+ multiply?: boolean;
104
+ }
105
+ export type DateFormat = 'relative' | 'short' | 'medium' | 'long' | 'iso' | string;
106
+ export interface DateFieldOptions extends BaseFieldOptions {
107
+ /** Date format */
108
+ format?: DateFormat;
109
+ /** Show time component */
110
+ showTime?: boolean;
111
+ /** Locale for formatting */
112
+ locale?: string;
113
+ }
114
+ export interface TimeFieldOptions extends BaseFieldOptions {
115
+ /** Time format */
116
+ format?: '12h' | '24h';
117
+ /** Show seconds */
118
+ showSeconds?: boolean;
119
+ }
120
+ export interface DateRangeFieldOptions extends BaseFieldOptions {
121
+ /** End date source */
122
+ endSource: string;
123
+ /** Format for dates */
124
+ format?: DateFormat;
125
+ /** Separator between dates */
126
+ separator?: string;
127
+ }
128
+ export interface BooleanFieldOptions extends BaseFieldOptions {
129
+ /** Label for true value */
130
+ trueLabel?: string;
131
+ /** Label for false value */
132
+ falseLabel?: string;
133
+ /** Icon for true value */
134
+ trueIcon?: string;
135
+ /** Icon for false value */
136
+ falseIcon?: string;
137
+ /** Use colored badges instead of icons */
138
+ asBadge?: boolean;
139
+ }
140
+ export interface ImageFieldOptions extends BaseFieldOptions {
141
+ /** Image width */
142
+ width?: number;
143
+ /** Image height */
144
+ height?: number;
145
+ /** Make image circular */
146
+ rounded?: boolean;
147
+ /** Fallback image URL */
148
+ fallback?: string;
149
+ /** Alt text source */
150
+ altSource?: string;
151
+ /** Enable lightbox on click */
152
+ lightbox?: boolean;
153
+ }
154
+ export interface AvatarFieldOptions extends BaseFieldOptions {
155
+ /** Size in pixels */
156
+ size?: number;
157
+ /** Source for name (for initials fallback) */
158
+ nameSource?: string;
159
+ }
160
+ export interface GalleryFieldOptions extends BaseFieldOptions {
161
+ /** Max images to show inline */
162
+ maxVisible?: number;
163
+ /** Thumbnail size */
164
+ thumbnailSize?: number;
165
+ }
166
+ export interface FileFieldOptions extends BaseFieldOptions {
167
+ /** Show file size */
168
+ showSize?: boolean;
169
+ /** Show file type icon */
170
+ showIcon?: boolean;
171
+ }
172
+ export interface BadgeFieldOptions extends BaseFieldOptions {
173
+ /** Color mapping: { value: color } */
174
+ colors?: Record<string, string>;
175
+ /** Icon mapping: { value: icon } */
176
+ icons?: Record<string, string>;
177
+ /** Variant style */
178
+ variant?: 'solid' | 'outline' | 'subtle';
179
+ /** Size */
180
+ size?: 'sm' | 'md' | 'lg';
181
+ }
182
+ export interface TagsFieldOptions extends BaseFieldOptions {
183
+ /** Max tags to show */
184
+ max?: number;
185
+ /** Color for tags */
186
+ color?: string;
187
+ }
188
+ export interface RatingFieldOptions extends BaseFieldOptions {
189
+ /** Maximum rating value */
190
+ max?: number;
191
+ /** Source for review count */
192
+ countSource?: string;
193
+ /** Show numeric value */
194
+ showValue?: boolean;
195
+ /** Icon for filled star */
196
+ icon?: string;
197
+ /** Color for stars */
198
+ color?: string;
199
+ }
200
+ export interface PriceFieldOptions extends BaseFieldOptions {
201
+ /** Source for original/compare-at price */
202
+ originalSource?: string;
203
+ /** Currency code */
204
+ currency?: string;
205
+ /** Locale for formatting */
206
+ locale?: string;
207
+ /** Show discount percentage badge */
208
+ showDiscount?: boolean;
209
+ }
210
+ export interface StockFieldOptions extends BaseFieldOptions {
211
+ /** Label when in stock */
212
+ inStockLabel?: string;
213
+ /** Label when out of stock */
214
+ outOfStockLabel?: string;
215
+ /** Threshold for "low stock" warning */
216
+ lowStockThreshold?: number;
217
+ /** Label for low stock */
218
+ lowStockLabel?: string;
219
+ /** Show quantity */
220
+ showQuantity?: boolean;
221
+ }
222
+ export interface QuantityFieldOptions extends BaseFieldOptions {
223
+ /** Minimum value */
224
+ min?: number;
225
+ /** Maximum value */
226
+ max?: number;
227
+ /** Step increment */
228
+ step?: number;
229
+ /** Method to call on change */
230
+ onChange?: string;
231
+ }
232
+ export interface UserFieldOptions extends BaseFieldOptions {
233
+ /** Source for avatar image */
234
+ avatarSource?: string;
235
+ /** Source for display name */
236
+ nameSource?: string;
237
+ /** Source for secondary text (email, role) */
238
+ secondarySource?: string;
239
+ /** Link template */
240
+ link?: string;
241
+ }
242
+ export interface ReferenceFieldOptions extends BaseFieldOptions {
243
+ /** Source for display text */
244
+ displaySource?: string;
245
+ /** Link template */
246
+ link?: string;
247
+ /** Resource type (for routing) */
248
+ resource?: string;
249
+ }
250
+ export interface ActionItem {
251
+ /** Button label */
252
+ label: string;
253
+ /** Photon method to call */
254
+ method: string;
255
+ /** Icon name */
256
+ icon?: string;
257
+ /** Button variant */
258
+ variant?: 'primary' | 'secondary' | 'danger' | 'ghost';
259
+ /** Require confirmation */
260
+ confirm?: boolean | string;
261
+ /** Confirmation message */
262
+ confirmMessage?: string;
263
+ /** Disable condition (field name that must be truthy to disable) */
264
+ disabledWhen?: string;
265
+ /** Hide condition */
266
+ hiddenWhen?: string;
267
+ }
268
+ export interface ActionsFieldOptions extends BaseFieldOptions {
269
+ /** Show as dropdown menu */
270
+ dropdown?: boolean;
271
+ /** Dropdown trigger label */
272
+ dropdownLabel?: string;
273
+ }
274
+ export type RenderFunction = (value: any, record: Record<string, any>) => string;
275
+ export interface CustomFieldOptions extends BaseFieldOptions {
276
+ /** Render function */
277
+ render: RenderFunction;
278
+ }
279
+ export type FieldType = 'text' | 'email' | 'url' | 'phone' | 'number' | 'currency' | 'percent' | 'date' | 'datetime' | 'time' | 'dateRange' | 'boolean' | 'image' | 'avatar' | 'gallery' | 'file' | 'badge' | 'tags' | 'rating' | 'price' | 'stock' | 'quantity' | 'user' | 'reference' | 'actions' | 'custom';
280
+ export interface FieldDefinition {
281
+ type: FieldType;
282
+ source: string;
283
+ options: Record<string, any>;
284
+ actions?: ActionItem[];
285
+ render?: RenderFunction;
286
+ }
287
+ /**
288
+ * Field factory for creating field definitions
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const fields = [
293
+ * Field.text('name'),
294
+ * Field.email('email'),
295
+ * Field.price('price', { currency: 'USD', originalSource: 'msrp' }),
296
+ * Field.badge('status', { colors: { active: 'green', inactive: 'gray' } }),
297
+ * Field.actions([{ label: 'Edit', method: 'edit' }]),
298
+ * ];
299
+ * ```
300
+ */
301
+ export declare const Field: {
302
+ text(source: string, options?: TextFieldOptions): FieldDefinition;
303
+ email(source: string, options?: EmailFieldOptions): FieldDefinition;
304
+ url(source: string, options?: UrlFieldOptions): FieldDefinition;
305
+ phone(source: string, options?: PhoneFieldOptions): FieldDefinition;
306
+ number(source: string, options?: NumberFieldOptions): FieldDefinition;
307
+ currency(source: string, options?: CurrencyFieldOptions): FieldDefinition;
308
+ percent(source: string, options?: PercentFieldOptions): FieldDefinition;
309
+ date(source: string, options?: DateFieldOptions): FieldDefinition;
310
+ datetime(source: string, options?: DateFieldOptions): FieldDefinition;
311
+ time(source: string, options?: TimeFieldOptions): FieldDefinition;
312
+ dateRange(startSource: string, options: DateRangeFieldOptions): FieldDefinition;
313
+ boolean(source: string, options?: BooleanFieldOptions): FieldDefinition;
314
+ image(source: string, options?: ImageFieldOptions): FieldDefinition;
315
+ avatar(source: string, options?: AvatarFieldOptions): FieldDefinition;
316
+ gallery(source: string, options?: GalleryFieldOptions): FieldDefinition;
317
+ file(source: string, options?: FileFieldOptions): FieldDefinition;
318
+ badge(source: string, options?: BadgeFieldOptions): FieldDefinition;
319
+ tags(source: string, options?: TagsFieldOptions): FieldDefinition;
320
+ rating(source: string, options?: RatingFieldOptions): FieldDefinition;
321
+ price(source: string, options?: PriceFieldOptions): FieldDefinition;
322
+ stock(source: string, options?: StockFieldOptions): FieldDefinition;
323
+ quantity(source: string, options?: QuantityFieldOptions): FieldDefinition;
324
+ user(source: string, options?: UserFieldOptions): FieldDefinition;
325
+ reference(source: string, options?: ReferenceFieldOptions): FieldDefinition;
326
+ actions(items: ActionItem[], options?: ActionsFieldOptions): FieldDefinition;
327
+ custom(source: string, render: RenderFunction, options?: BaseFieldOptions): FieldDefinition;
328
+ };
329
+ /**
330
+ * Get value from record using dot notation
331
+ */
332
+ export declare function getFieldValue(record: Record<string, any>, source: string): any;
333
+ /**
334
+ * Format label from source (camelCase → Title Case)
335
+ */
336
+ export declare function formatFieldLabel(source: string): string;
337
+ /**
338
+ * Interpolate template string with record values
339
+ * e.g., "/users/{id}" with { id: 123 } → "/users/123"
340
+ */
341
+ export declare function interpolateTemplate(template: string, record: Record<string, any>): string;
342
+ //# sourceMappingURL=Field.d.ts.map