@a2ui/angular 0.0.1
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 +9 -0
- package/angular.json +35 -0
- package/ng-package.json +8 -0
- package/package.json +59 -0
- package/src/lib/catalog/audio.ts +50 -0
- package/src/lib/catalog/button.ts +56 -0
- package/src/lib/catalog/card.ts +57 -0
- package/src/lib/catalog/checkbox.ts +73 -0
- package/src/lib/catalog/column.ts +96 -0
- package/src/lib/catalog/datetime-input.ts +127 -0
- package/src/lib/catalog/default.ts +185 -0
- package/src/lib/catalog/divider.ts +37 -0
- package/src/lib/catalog/icon.ts +44 -0
- package/src/lib/catalog/image.ts +62 -0
- package/src/lib/catalog/list.ts +63 -0
- package/src/lib/catalog/modal.ts +113 -0
- package/src/lib/catalog/multiple-choice.ts +77 -0
- package/src/lib/catalog/row.ts +100 -0
- package/src/lib/catalog/slider.ts +73 -0
- package/src/lib/catalog/surface.ts +82 -0
- package/src/lib/catalog/tabs.ts +72 -0
- package/src/lib/catalog/text-field.ts +86 -0
- package/src/lib/catalog/text.ts +137 -0
- package/src/lib/catalog/video.ts +50 -0
- package/src/lib/config.ts +25 -0
- package/src/lib/data/index.ts +18 -0
- package/src/lib/data/markdown.ts +114 -0
- package/src/lib/data/processor.ts +47 -0
- package/src/lib/data/types.ts +29 -0
- package/src/lib/rendering/catalog.ts +36 -0
- package/src/lib/rendering/dynamic-component.ts +100 -0
- package/src/lib/rendering/index.ts +20 -0
- package/src/lib/rendering/renderer.ts +109 -0
- package/src/lib/rendering/theming.ts +22 -0
- package/src/public-api.ts +21 -0
- package/tsconfig.json +23 -0
- package/tsconfig.lib.json +16 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +12 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { inputBinding } from '@angular/core';
|
|
18
|
+
import { Types } from '@a2ui/lit/0.8';
|
|
19
|
+
import { Catalog } from '../rendering/catalog';
|
|
20
|
+
import { Row } from './row';
|
|
21
|
+
import { Column } from './column';
|
|
22
|
+
import { Text } from './text';
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_CATALOG: Catalog = {
|
|
25
|
+
Row: {
|
|
26
|
+
type: () => Row,
|
|
27
|
+
bindings: (node) => {
|
|
28
|
+
const properties = (node as Types.RowNode).properties;
|
|
29
|
+
return [
|
|
30
|
+
inputBinding('alignment', () => properties.alignment ?? 'stretch'),
|
|
31
|
+
inputBinding('distribution', () => properties.distribution ?? 'start'),
|
|
32
|
+
];
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
Column: {
|
|
37
|
+
type: () => Column,
|
|
38
|
+
bindings: (node) => {
|
|
39
|
+
const properties = (node as Types.ColumnNode).properties;
|
|
40
|
+
return [
|
|
41
|
+
inputBinding('alignment', () => properties.alignment ?? 'stretch'),
|
|
42
|
+
inputBinding('distribution', () => properties.distribution ?? 'start'),
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
List: {
|
|
48
|
+
type: () => import('./list').then((r) => r.List),
|
|
49
|
+
bindings: (node) => {
|
|
50
|
+
const properties = (node as Types.ListNode).properties;
|
|
51
|
+
return [inputBinding('direction', () => properties.direction ?? 'vertical')];
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
Card: () => import('./card').then((r) => r.Card),
|
|
56
|
+
|
|
57
|
+
Image: {
|
|
58
|
+
type: () => import('./image').then((r) => r.Image),
|
|
59
|
+
bindings: (node) => {
|
|
60
|
+
const properties = (node as Types.ImageNode).properties;
|
|
61
|
+
return [
|
|
62
|
+
inputBinding('url', () => properties.url),
|
|
63
|
+
inputBinding('usageHint', () => properties.usageHint),
|
|
64
|
+
];
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
Icon: {
|
|
69
|
+
type: () => import('./icon').then((r) => r.Icon),
|
|
70
|
+
bindings: (node) => {
|
|
71
|
+
const properties = (node as Types.IconNode).properties;
|
|
72
|
+
return [inputBinding('name', () => properties.name)];
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
Video: {
|
|
77
|
+
type: () => import('./video').then((r) => r.Video),
|
|
78
|
+
bindings: (node) => {
|
|
79
|
+
const properties = (node as Types.VideoNode).properties;
|
|
80
|
+
return [inputBinding('url', () => properties.url)];
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
AudioPlayer: {
|
|
85
|
+
type: () => import('./audio').then((r) => r.Audio),
|
|
86
|
+
bindings: (node) => {
|
|
87
|
+
const properties = (node as Types.AudioPlayerNode).properties;
|
|
88
|
+
return [inputBinding('url', () => properties.url)];
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
Text: {
|
|
93
|
+
type: () => Text,
|
|
94
|
+
bindings: (node) => {
|
|
95
|
+
const properties = (node as Types.TextNode).properties;
|
|
96
|
+
return [
|
|
97
|
+
inputBinding('text', () => properties.text),
|
|
98
|
+
inputBinding('usageHint', () => properties.usageHint || null),
|
|
99
|
+
];
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
Button: {
|
|
104
|
+
type: () => import('./button').then((r) => r.Button),
|
|
105
|
+
bindings: (node) => {
|
|
106
|
+
const properties = (node as Types.ButtonNode).properties;
|
|
107
|
+
return [inputBinding('action', () => properties.action)];
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
Divider: () => import('./divider').then((r) => r.Divider),
|
|
112
|
+
|
|
113
|
+
MultipleChoice: {
|
|
114
|
+
type: () => import('./multiple-choice').then((r) => r.MultipleChoice),
|
|
115
|
+
bindings: (node) => {
|
|
116
|
+
const properties = (node as Types.MultipleChoiceNode).properties;
|
|
117
|
+
return [
|
|
118
|
+
inputBinding('options', () => properties.options || []),
|
|
119
|
+
inputBinding('value', () => properties.selections),
|
|
120
|
+
inputBinding('description', () => 'Select an item'), // TODO: this should be defined in the properties
|
|
121
|
+
];
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
TextField: {
|
|
126
|
+
type: () => import('./text-field').then((r) => r.TextField),
|
|
127
|
+
bindings: (node) => {
|
|
128
|
+
const properties = (node as Types.TextFieldNode).properties;
|
|
129
|
+
return [
|
|
130
|
+
inputBinding('text', () => properties.text ?? null),
|
|
131
|
+
inputBinding('label', () => properties.label),
|
|
132
|
+
inputBinding('inputType', () => properties.type),
|
|
133
|
+
];
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
DateTimeInput: {
|
|
138
|
+
type: () => import('./datetime-input').then((r) => r.DatetimeInput),
|
|
139
|
+
bindings: (node) => {
|
|
140
|
+
const properties = (node as Types.DateTimeInputNode).properties;
|
|
141
|
+
return [
|
|
142
|
+
inputBinding('enableDate', () => properties.enableDate),
|
|
143
|
+
inputBinding('enableTime', () => properties.enableTime),
|
|
144
|
+
inputBinding('value', () => properties.value),
|
|
145
|
+
];
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
CheckBox: {
|
|
150
|
+
type: () => import('./checkbox').then((r) => r.Checkbox),
|
|
151
|
+
bindings: (node) => {
|
|
152
|
+
const properties = (node as Types.CheckboxNode).properties;
|
|
153
|
+
return [
|
|
154
|
+
inputBinding('label', () => properties.label),
|
|
155
|
+
inputBinding('value', () => properties.value),
|
|
156
|
+
];
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
Slider: {
|
|
161
|
+
type: () => import('./slider').then((r) => r.Slider),
|
|
162
|
+
bindings: (node) => {
|
|
163
|
+
const properties = (node as Types.SliderNode).properties;
|
|
164
|
+
return [
|
|
165
|
+
inputBinding('value', () => properties.value),
|
|
166
|
+
inputBinding('minValue', () => properties.minValue),
|
|
167
|
+
inputBinding('maxValue', () => properties.maxValue),
|
|
168
|
+
inputBinding('label', () => ''), // TODO: this should be defined in the properties
|
|
169
|
+
];
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
Tabs: {
|
|
174
|
+
type: () => import('./tabs').then((r) => r.Tabs),
|
|
175
|
+
bindings: (node) => {
|
|
176
|
+
const properties = (node as Types.TabsNode).properties;
|
|
177
|
+
return [inputBinding('tabs', () => properties.tabItems)];
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
Modal: {
|
|
182
|
+
type: () => import('./modal').then((r) => r.Modal),
|
|
183
|
+
bindings: () => [],
|
|
184
|
+
},
|
|
185
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component } from '@angular/core';
|
|
18
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
19
|
+
|
|
20
|
+
@Component({
|
|
21
|
+
selector: 'a2ui-divider',
|
|
22
|
+
template: '<hr [class]="theme.components.Divider" [style]="theme.additionalStyles?.Divider"/>',
|
|
23
|
+
styles: `
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
min-height: 0;
|
|
27
|
+
overflow: auto;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
hr {
|
|
31
|
+
height: 1px;
|
|
32
|
+
background: #ccc;
|
|
33
|
+
border: none;
|
|
34
|
+
}
|
|
35
|
+
`,
|
|
36
|
+
})
|
|
37
|
+
export class Divider extends DynamicComponent {}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component, computed, input } from '@angular/core';
|
|
18
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
19
|
+
import { Primitives } from '@a2ui/lit/0.8';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'a2ui-icon',
|
|
23
|
+
styles: `
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
flex: var(--weight);
|
|
27
|
+
min-height: 0;
|
|
28
|
+
overflow: auto;
|
|
29
|
+
}
|
|
30
|
+
`,
|
|
31
|
+
template: `
|
|
32
|
+
@let resolvedName = this.resolvedName();
|
|
33
|
+
|
|
34
|
+
@if (resolvedName) {
|
|
35
|
+
<section [class]="theme.components.Icon" [style]="theme.additionalStyles?.Icon">
|
|
36
|
+
<span class="g-icon">{{ resolvedName }}</span>
|
|
37
|
+
</section>
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
})
|
|
41
|
+
export class Icon extends DynamicComponent {
|
|
42
|
+
readonly name = input.required<Primitives.StringValue | null>();
|
|
43
|
+
protected readonly resolvedName = computed(() => this.resolvePrimitive(this.name()));
|
|
44
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component, computed, input } from '@angular/core';
|
|
18
|
+
import { Primitives, Styles, Types } from '@a2ui/lit/0.8';
|
|
19
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'a2ui-image',
|
|
23
|
+
styles: `
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
flex: var(--weight);
|
|
27
|
+
min-height: 0;
|
|
28
|
+
overflow: auto;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
img {
|
|
32
|
+
display: block;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
}
|
|
37
|
+
`,
|
|
38
|
+
template: `
|
|
39
|
+
@let resolvedUrl = this.resolvedUrl();
|
|
40
|
+
|
|
41
|
+
@if (resolvedUrl) {
|
|
42
|
+
<section [class]="classes()" [style]="theme.additionalStyles?.Image">
|
|
43
|
+
<img [src]="resolvedUrl" />
|
|
44
|
+
</section>
|
|
45
|
+
}
|
|
46
|
+
`,
|
|
47
|
+
})
|
|
48
|
+
export class Image extends DynamicComponent {
|
|
49
|
+
readonly url = input.required<Primitives.StringValue | null>();
|
|
50
|
+
readonly usageHint = input.required<Types.ResolvedImage['usageHint'] | null>();
|
|
51
|
+
|
|
52
|
+
protected readonly resolvedUrl = computed(() => this.resolvePrimitive(this.url()));
|
|
53
|
+
|
|
54
|
+
protected classes = computed(() => {
|
|
55
|
+
const usageHint = this.usageHint();
|
|
56
|
+
|
|
57
|
+
return Styles.merge(
|
|
58
|
+
this.theme.components.Image.all,
|
|
59
|
+
usageHint ? this.theme.components.Image[usageHint] : {},
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component, input } from '@angular/core';
|
|
18
|
+
import { Types } from '@a2ui/lit/0.8';
|
|
19
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
20
|
+
import { Renderer } from '../rendering/renderer';
|
|
21
|
+
|
|
22
|
+
@Component({
|
|
23
|
+
selector: 'a2ui-list',
|
|
24
|
+
imports: [Renderer],
|
|
25
|
+
host: {
|
|
26
|
+
'[attr.direction]': 'direction()',
|
|
27
|
+
},
|
|
28
|
+
styles: `
|
|
29
|
+
:host {
|
|
30
|
+
display: block;
|
|
31
|
+
flex: var(--weight);
|
|
32
|
+
min-height: 0;
|
|
33
|
+
overflow: auto;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:host([direction='vertical']) section {
|
|
37
|
+
display: grid;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:host([direction='horizontal']) section {
|
|
41
|
+
display: flex;
|
|
42
|
+
max-width: 100%;
|
|
43
|
+
overflow-x: scroll;
|
|
44
|
+
overflow-y: hidden;
|
|
45
|
+
scrollbar-width: none;
|
|
46
|
+
|
|
47
|
+
> ::slotted(*) {
|
|
48
|
+
flex: 1 0 fit-content;
|
|
49
|
+
max-width: min(80%, 400px);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`,
|
|
53
|
+
template: `
|
|
54
|
+
<section [class]="theme.components.List" [style]="theme.additionalStyles?.List">
|
|
55
|
+
@for (child of component().properties.children; track child) {
|
|
56
|
+
<ng-container a2ui-renderer [surfaceId]="surfaceId()!" [component]="child" />
|
|
57
|
+
}
|
|
58
|
+
</section>
|
|
59
|
+
`,
|
|
60
|
+
})
|
|
61
|
+
export class List extends DynamicComponent<Types.ListNode> {
|
|
62
|
+
readonly direction = input<'vertical' | 'horizontal'>('vertical');
|
|
63
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component, signal, viewChild, ElementRef, effect } from '@angular/core';
|
|
18
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
19
|
+
import { Types } from '@a2ui/lit/0.8';
|
|
20
|
+
import { Renderer } from '../rendering';
|
|
21
|
+
|
|
22
|
+
@Component({
|
|
23
|
+
selector: 'a2ui-modal',
|
|
24
|
+
imports: [Renderer],
|
|
25
|
+
template: `
|
|
26
|
+
@if (showDialog()) {
|
|
27
|
+
<dialog #dialog [class]="theme.components.Modal.backdrop" (click)="handleDialogClick($event)">
|
|
28
|
+
<section [class]="theme.components.Modal.element" [style]="theme.additionalStyles?.Modal">
|
|
29
|
+
<div class="controls">
|
|
30
|
+
<button (click)="closeDialog()">
|
|
31
|
+
<span class="g-icon">close</span>
|
|
32
|
+
</button>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<ng-container
|
|
36
|
+
a2ui-renderer
|
|
37
|
+
[surfaceId]="surfaceId()!"
|
|
38
|
+
[component]="component().properties.contentChild"
|
|
39
|
+
/>
|
|
40
|
+
</section>
|
|
41
|
+
</dialog>
|
|
42
|
+
} @else {
|
|
43
|
+
<section (click)="showDialog.set(true)">
|
|
44
|
+
<ng-container
|
|
45
|
+
a2ui-renderer
|
|
46
|
+
[surfaceId]="surfaceId()!"
|
|
47
|
+
[component]="component().properties.entryPointChild"
|
|
48
|
+
/>
|
|
49
|
+
</section>
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
styles: `
|
|
53
|
+
dialog {
|
|
54
|
+
padding: 0;
|
|
55
|
+
border: none;
|
|
56
|
+
background: none;
|
|
57
|
+
|
|
58
|
+
& section {
|
|
59
|
+
& .controls {
|
|
60
|
+
display: flex;
|
|
61
|
+
justify-content: end;
|
|
62
|
+
margin-bottom: 4px;
|
|
63
|
+
|
|
64
|
+
& button {
|
|
65
|
+
padding: 0;
|
|
66
|
+
background: none;
|
|
67
|
+
width: 20px;
|
|
68
|
+
height: 20px;
|
|
69
|
+
pointer: cursor;
|
|
70
|
+
border: none;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
`,
|
|
77
|
+
})
|
|
78
|
+
export class Modal extends DynamicComponent<Types.ModalNode> {
|
|
79
|
+
protected readonly showDialog = signal(false);
|
|
80
|
+
protected readonly dialog = viewChild<ElementRef<HTMLDialogElement>>('dialog');
|
|
81
|
+
|
|
82
|
+
constructor() {
|
|
83
|
+
super();
|
|
84
|
+
|
|
85
|
+
effect(() => {
|
|
86
|
+
const dialog = this.dialog();
|
|
87
|
+
|
|
88
|
+
if (dialog && !dialog.nativeElement.open) {
|
|
89
|
+
dialog.nativeElement.showModal();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected handleDialogClick(event: MouseEvent) {
|
|
95
|
+
if (event.target instanceof HTMLDialogElement) {
|
|
96
|
+
this.closeDialog();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected closeDialog() {
|
|
101
|
+
const dialog = this.dialog();
|
|
102
|
+
|
|
103
|
+
if (!dialog) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!dialog.nativeElement.open) {
|
|
108
|
+
dialog.nativeElement.close();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.showDialog.set(false);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component, computed, input } from '@angular/core';
|
|
18
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
19
|
+
import { Primitives } from '@a2ui/lit/0.8';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'a2ui-multiple-choice',
|
|
23
|
+
template: `
|
|
24
|
+
<section [class]="theme.components.MultipleChoice.container">
|
|
25
|
+
<label [class]="theme.components.MultipleChoice.label" [for]="selectId">{{
|
|
26
|
+
description()
|
|
27
|
+
}}</label>
|
|
28
|
+
|
|
29
|
+
<select
|
|
30
|
+
(change)="handleChange($event)"
|
|
31
|
+
[id]="selectId"
|
|
32
|
+
[value]="selectValue()"
|
|
33
|
+
[class]="theme.components.MultipleChoice.element"
|
|
34
|
+
[style]="theme.additionalStyles?.MultipleChoice"
|
|
35
|
+
>
|
|
36
|
+
@for (option of options(); track option.value) {
|
|
37
|
+
<option [value]="option.value">{{ resolvePrimitive(option.label) }}</option>
|
|
38
|
+
}
|
|
39
|
+
</select>
|
|
40
|
+
</section>
|
|
41
|
+
`,
|
|
42
|
+
styles: `
|
|
43
|
+
:host {
|
|
44
|
+
display: block;
|
|
45
|
+
flex: var(--weight);
|
|
46
|
+
min-height: 0;
|
|
47
|
+
overflow: auto;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
select {
|
|
51
|
+
width: 100%;
|
|
52
|
+
box-sizing: border-box;
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
})
|
|
56
|
+
export class MultipleChoice extends DynamicComponent {
|
|
57
|
+
readonly options = input.required<{ label: Primitives.StringValue; value: string }[]>();
|
|
58
|
+
readonly value = input.required<Primitives.StringValue | null>();
|
|
59
|
+
readonly description = input.required<string>();
|
|
60
|
+
|
|
61
|
+
protected readonly selectId = super.getUniqueId('a2ui-multiple-choice');
|
|
62
|
+
protected selectValue = computed(() => super.resolvePrimitive(this.value()));
|
|
63
|
+
|
|
64
|
+
protected handleChange(event: Event) {
|
|
65
|
+
const path = this.value()?.path;
|
|
66
|
+
|
|
67
|
+
if (!(event.target instanceof HTMLSelectElement) || !event.target.value || !path) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.processor.setData(
|
|
72
|
+
this.component(),
|
|
73
|
+
this.processor.resolvePath(path, this.component().dataContextPath),
|
|
74
|
+
event.target.value,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Component, computed, input } from '@angular/core';
|
|
18
|
+
import { DynamicComponent } from '../rendering/dynamic-component';
|
|
19
|
+
import { Renderer } from '../rendering/renderer';
|
|
20
|
+
import { Types } from '@a2ui/lit/0.8';
|
|
21
|
+
|
|
22
|
+
@Component({
|
|
23
|
+
selector: 'a2ui-row',
|
|
24
|
+
imports: [Renderer],
|
|
25
|
+
host: {
|
|
26
|
+
'[attr.alignment]': 'alignment()',
|
|
27
|
+
'[attr.distribution]': 'distribution()',
|
|
28
|
+
},
|
|
29
|
+
styles: `
|
|
30
|
+
:host {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex: var(--weight);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
section {
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: row;
|
|
38
|
+
width: 100%;
|
|
39
|
+
min-height: 100%;
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.align-start {
|
|
44
|
+
align-items: start;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.align-center {
|
|
48
|
+
align-items: center;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.align-end {
|
|
52
|
+
align-items: end;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.align-stretch {
|
|
56
|
+
align-items: stretch;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.distribute-start {
|
|
60
|
+
justify-content: start;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.distribute-center {
|
|
64
|
+
justify-content: center;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.distribute-end {
|
|
68
|
+
justify-content: end;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.distribute-spaceBetween {
|
|
72
|
+
justify-content: space-between;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.distribute-spaceAround {
|
|
76
|
+
justify-content: space-around;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.distribute-spaceEvenly {
|
|
80
|
+
justify-content: space-evenly;
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
template: `
|
|
84
|
+
<section [class]="classes()" [style]="theme.additionalStyles?.Row">
|
|
85
|
+
@for (child of component().properties.children; track child) {
|
|
86
|
+
<ng-container a2ui-renderer [surfaceId]="surfaceId()!" [component]="child" />
|
|
87
|
+
}
|
|
88
|
+
</section>
|
|
89
|
+
`,
|
|
90
|
+
})
|
|
91
|
+
export class Row extends DynamicComponent<Types.RowNode> {
|
|
92
|
+
readonly alignment = input<Types.ResolvedRow['alignment']>('stretch');
|
|
93
|
+
readonly distribution = input<Types.ResolvedRow['distribution']>('start');
|
|
94
|
+
|
|
95
|
+
protected readonly classes = computed(() => ({
|
|
96
|
+
...this.theme.components.Row,
|
|
97
|
+
[`align-${this.alignment()}`]: true,
|
|
98
|
+
[`distribute-${this.distribution()}`]: true,
|
|
99
|
+
}));
|
|
100
|
+
}
|