-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathbasic-catalog.ts
More file actions
163 lines (150 loc) · 5.55 KB
/
basic-catalog.ts
File metadata and controls
163 lines (150 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Injectable} from '@angular/core';
import {AngularCatalog, AngularComponentImplementation} from '../types';
import {TextComponent} from './text.component';
import {RowComponent} from './row.component';
import {ColumnComponent} from './column.component';
import {ButtonComponent} from './button.component';
import {TextFieldComponent} from './text-field.component';
import {ImageComponent} from './image.component';
import {IconComponent} from './icon.component';
import {VideoComponent} from './video.component';
import {AudioPlayerComponent} from './audio-player.component';
import {ListComponent} from './list.component';
import {CardComponent} from './card.component';
import {TabsComponent} from './tabs.component';
import {ModalComponent} from './modal.component';
import {DividerComponent} from './divider.component';
import {CheckBoxComponent} from './check-box.component';
import {ChoicePickerComponent} from './choice-picker.component';
import {SliderComponent} from './slider.component';
import {DateTimeInputComponent} from './date-time-input.component';
import {
BASIC_FUNCTIONS,
TextApi,
RowApi,
ColumnApi,
ButtonApi,
TextFieldApi,
ImageApi,
IconApi,
VideoApi,
AudioPlayerApi,
ListApi,
CardApi,
TabsApi,
ModalApi,
DividerApi,
CheckBoxApi,
ChoicePickerApi,
SliderApi,
DateTimeInputApi,
} from '@a2ui/web_core/v0_9/basic_catalog';
import {FunctionImplementation} from '@a2ui/web_core/v0_9';
/**
* The set of default Angular implementations for each component in the basic catalog.
* Using string literals as keys, to survive property renaming, as these names need to match the JSON payload.
*/
// Ignore Prettier to preserve quoted keys, needed to survive property renaming.
// prettier-ignore
const DEFAULT_COMPONENT_IMPLEMENTATIONS: Record<string, AngularComponentImplementation> = {
'text': {...TextApi, component: TextComponent},
'row': {...RowApi, component: RowComponent},
'column': {...ColumnApi, component: ColumnComponent},
'button': {...ButtonApi, component: ButtonComponent},
'textField': {...TextFieldApi, component: TextFieldComponent},
'image': {...ImageApi, component: ImageComponent},
'icon': {...IconApi, component: IconComponent},
'video': {...VideoApi, component: VideoComponent},
'audioPlayer': {...AudioPlayerApi, component: AudioPlayerComponent},
'list': {...ListApi, component: ListComponent},
'card': {...CardApi, component: CardComponent},
'tabs': {...TabsApi, component: TabsComponent},
'modal': {...ModalApi, component: ModalComponent},
'divider': {...DividerApi, component: DividerComponent},
'checkBox': {...CheckBoxApi, component: CheckBoxComponent},
'choicePicker': {...ChoicePickerApi, component: ChoicePickerComponent},
'slider': {...SliderApi, component: SliderComponent},
'dateTimeInput': {...DateTimeInputApi, component: DateTimeInputComponent},
} as const;
/**
* Interface for specifying overrides and configuration for the basic catalog.
*/
export interface BasicCatalogOptions {
/**
* An optional override for the catalog's unique identifier.
*/
id?: string;
/**
* Optional overrides for individual components in the catalog.
*/
components?: Partial<{
[K in keyof typeof DEFAULT_COMPONENT_IMPLEMENTATIONS]: AngularComponentImplementation;
}>;
/**
* Optional additional components to include in the catalog beyond
* the standard basic catalog components.
*/
extraComponents?: AngularComponentImplementation[];
/**
* An optional set of function implementations to use instead of the defaults.
*/
functions?: FunctionImplementation[];
}
/**
* The set of Angular UI components provided by the basic catalog.
*/
export const BASIC_COMPONENTS: AngularComponentImplementation[] = Object.values(
DEFAULT_COMPONENT_IMPLEMENTATIONS,
);
/**
* The set of client-side functions provided by the basic catalog.
*/
export {BASIC_FUNCTIONS};
/**
* A base class for basic catalogs, providing extensibility for non-DI use cases.
*/
export class BasicCatalogBase extends AngularCatalog {
constructor(options: BasicCatalogOptions = {}) {
const id = options.id ?? 'https://a2ui.org/specification/v0_9/basic_catalog.json';
const functions = options.functions ?? BASIC_FUNCTIONS;
const overrides = options.components ?? {};
const components: AngularComponentImplementation[] = [
...Object.entries(DEFAULT_COMPONENT_IMPLEMENTATIONS).map(([key, defaultValue]) => {
const impl = (overrides as any)[key] ?? defaultValue;
return {...impl, name: impl.name || key};
}),
...(options.extraComponents ?? []),
];
super(id, components, functions);
}
}
/**
* A basic catalog of components and functions for v0.9 verification.
*
* This catalog includes a wide range of UI components (Text, Button, Row, etc.)
* and utility functions (capitalize, formatString) defined in the A2UI v0.9
* basic catalog specification.
*/
@Injectable({
providedIn: 'root',
})
export class BasicCatalog extends BasicCatalogBase {
constructor() {
super();
}
}