@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
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Angular implementation of A2UI.
|
|
2
|
+
|
|
3
|
+
Important: The sample code provided is for demonstration purposes and illustrates the mechanics of A2UI and the Agent-to-Agent (A2A) protocol. When building production applications, it is critical to treat any agent operating outside of your direct control as a potentially untrusted entity.
|
|
4
|
+
|
|
5
|
+
All operational data received from an external agent—including its AgentCard, messages, artifacts, and task statuses—should be handled as untrusted input. For example, a malicious agent could provide crafted data in its fields (e.g., name, skills.description) that, if used without sanitization to construct prompts for a Large Language Model (LLM), could expose your application to prompt injection attacks.
|
|
6
|
+
|
|
7
|
+
Similarly, any UI definition or data stream received must be treated as untrusted. Malicious agents could attempt to spoof legitimate interfaces to deceive users (phishing), inject malicious scripts via property values (XSS), or generate excessive layout complexity to degrade client performance (DoS). If your application supports optional embedded content (such as iframes or web views), additional care must be taken to prevent exposure to malicious external sites.
|
|
8
|
+
|
|
9
|
+
Developer Responsibility: Failure to properly validate data and strictly sandbox rendered content can introduce severe vulnerabilities. Developers are responsible for implementing appropriate security measures—such as input sanitization, Content Security Policies (CSP), strict isolation for optional embedded content, and secure credential handling—to protect their systems and users.
|
package/angular.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"projects": {
|
|
5
|
+
"lib": {
|
|
6
|
+
"projectType": "library",
|
|
7
|
+
"root": ".",
|
|
8
|
+
"sourceRoot": "./src",
|
|
9
|
+
"prefix": "lib",
|
|
10
|
+
"architect": {
|
|
11
|
+
"build": {
|
|
12
|
+
"builder": "@angular/build:ng-packagr",
|
|
13
|
+
"configurations": {
|
|
14
|
+
"production": {
|
|
15
|
+
"tsConfig": "./tsconfig.lib.prod.json"
|
|
16
|
+
},
|
|
17
|
+
"development": {
|
|
18
|
+
"tsConfig": "./tsconfig.lib.json"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"defaultConfiguration": "production"
|
|
22
|
+
},
|
|
23
|
+
"test": {
|
|
24
|
+
"builder": "@angular/build:karma",
|
|
25
|
+
"options": {
|
|
26
|
+
"tsConfig": "./tsconfig.spec.json"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"cli": {
|
|
33
|
+
"analytics": false
|
|
34
|
+
}
|
|
35
|
+
}
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a2ui/angular",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "ng build"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@a2ui/lit": "file:../lit",
|
|
9
|
+
"markdown-it": "^14.1.0",
|
|
10
|
+
"tslib": "^2.3.0"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@angular/common": "^21.0.0",
|
|
14
|
+
"@angular/core": "^21.0.0",
|
|
15
|
+
"@angular/platform-browser": "^21.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@angular/build": "^21.0.2",
|
|
19
|
+
"@angular/cli": "^21.0.2",
|
|
20
|
+
"@angular/compiler": "^21.0.0",
|
|
21
|
+
"@angular/compiler-cli": "^21.0.3",
|
|
22
|
+
"@angular/core": "^21.0.0",
|
|
23
|
+
"@types/express": "^5.0.1",
|
|
24
|
+
"@types/jasmine": "~5.1.0",
|
|
25
|
+
"@types/markdown-it": "^14.1.2",
|
|
26
|
+
"@types/node": "^20.17.19",
|
|
27
|
+
"@types/uuid": "^10.0.0",
|
|
28
|
+
"@vitest/browser": "^4.0.15",
|
|
29
|
+
"cypress": "^15.6.0",
|
|
30
|
+
"google-artifactregistry-auth": "^3.5.0",
|
|
31
|
+
"jasmine-core": "~5.9.0",
|
|
32
|
+
"jsdom": "^27.2.0",
|
|
33
|
+
"karma": "^6.4.4",
|
|
34
|
+
"karma-chrome-launcher": "^3.2.0",
|
|
35
|
+
"karma-coverage": "^2.2.1",
|
|
36
|
+
"karma-jasmine": "^5.1.0",
|
|
37
|
+
"karma-jasmine-html-reporter": "^2.1.0",
|
|
38
|
+
"ng-packagr": "^21.0.0",
|
|
39
|
+
"playwright": "^1.56.1",
|
|
40
|
+
"prettier": "^3.6.2",
|
|
41
|
+
"sass": "^1.93.2",
|
|
42
|
+
"tslib": "^2.8.1",
|
|
43
|
+
"typescript": "~5.9.2",
|
|
44
|
+
"vitest": "^4.0.15"
|
|
45
|
+
},
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"prettier": {
|
|
48
|
+
"printWidth": 100,
|
|
49
|
+
"singleQuote": true,
|
|
50
|
+
"overrides": [
|
|
51
|
+
{
|
|
52
|
+
"files": "*.html",
|
|
53
|
+
"options": {
|
|
54
|
+
"parser": "angular"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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-audio',
|
|
23
|
+
template: `
|
|
24
|
+
@let resolvedUrl = this.resolvedUrl();
|
|
25
|
+
|
|
26
|
+
@if (resolvedUrl) {
|
|
27
|
+
<section [class]="theme.components.AudioPlayer" [style]="theme.additionalStyles?.AudioPlayer">
|
|
28
|
+
<audio controls [src]="resolvedUrl"></audio>
|
|
29
|
+
</section>
|
|
30
|
+
}
|
|
31
|
+
`,
|
|
32
|
+
styles: `
|
|
33
|
+
:host {
|
|
34
|
+
display: block;
|
|
35
|
+
flex: var(--weight);
|
|
36
|
+
min-height: 0;
|
|
37
|
+
overflow: auto;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
audio {
|
|
41
|
+
display: block;
|
|
42
|
+
width: 100%;
|
|
43
|
+
box-sizing: border-box;
|
|
44
|
+
}
|
|
45
|
+
`
|
|
46
|
+
})
|
|
47
|
+
export class Audio extends DynamicComponent {
|
|
48
|
+
readonly url = input.required<Primitives.StringValue | null>();
|
|
49
|
+
protected readonly resolvedUrl = computed(() => this.resolvePrimitive(this.url()));
|
|
50
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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-button',
|
|
24
|
+
imports: [Renderer],
|
|
25
|
+
template: `
|
|
26
|
+
<button
|
|
27
|
+
[class]="theme.components.Button"
|
|
28
|
+
[style]="theme.additionalStyles?.Button"
|
|
29
|
+
(click)="handleClick()"
|
|
30
|
+
>
|
|
31
|
+
<ng-container
|
|
32
|
+
a2ui-renderer
|
|
33
|
+
[surfaceId]="surfaceId()!"
|
|
34
|
+
[component]="component().properties.child"
|
|
35
|
+
/>
|
|
36
|
+
</button>
|
|
37
|
+
`,
|
|
38
|
+
styles: `
|
|
39
|
+
:host {
|
|
40
|
+
display: block;
|
|
41
|
+
flex: var(--weight);
|
|
42
|
+
min-height: 0;
|
|
43
|
+
}
|
|
44
|
+
`,
|
|
45
|
+
})
|
|
46
|
+
export class Button extends DynamicComponent<Types.ButtonNode> {
|
|
47
|
+
readonly action = input.required<Types.Action | null>();
|
|
48
|
+
|
|
49
|
+
protected handleClick() {
|
|
50
|
+
const action = this.action();
|
|
51
|
+
|
|
52
|
+
if (action) {
|
|
53
|
+
super.sendAction(action);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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, ViewEncapsulation } 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-card',
|
|
24
|
+
imports: [Renderer],
|
|
25
|
+
encapsulation: ViewEncapsulation.None,
|
|
26
|
+
styles: `
|
|
27
|
+
a2ui-card {
|
|
28
|
+
display: block;
|
|
29
|
+
flex: var(--weight);
|
|
30
|
+
min-height: 0;
|
|
31
|
+
overflow: auto;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
a2ui-card > section {
|
|
35
|
+
height: 100%;
|
|
36
|
+
width: 100%;
|
|
37
|
+
min-height: 0;
|
|
38
|
+
overflow: auto;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
a2ui-card > section > * {
|
|
42
|
+
height: 100%;
|
|
43
|
+
width: 100%;
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
template: `
|
|
47
|
+
@let properties = component().properties;
|
|
48
|
+
@let children = properties.children || [properties.child];
|
|
49
|
+
|
|
50
|
+
<section [class]="theme.components.Card" [style]="theme.additionalStyles?.Card">
|
|
51
|
+
@for (child of children; track child) {
|
|
52
|
+
<ng-container a2ui-renderer [surfaceId]="surfaceId()!" [component]="child" />
|
|
53
|
+
}
|
|
54
|
+
</section>
|
|
55
|
+
`,
|
|
56
|
+
})
|
|
57
|
+
export class Card extends DynamicComponent<Types.CardNode> { }
|
|
@@ -0,0 +1,73 @@
|
|
|
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-checkbox',
|
|
23
|
+
template: `
|
|
24
|
+
<section
|
|
25
|
+
[class]="theme.components.CheckBox.container"
|
|
26
|
+
[style]="theme.additionalStyles?.CheckBox"
|
|
27
|
+
>
|
|
28
|
+
<input
|
|
29
|
+
autocomplete="off"
|
|
30
|
+
type="checkbox"
|
|
31
|
+
[id]="inputId"
|
|
32
|
+
[checked]="inputChecked()"
|
|
33
|
+
[class]="theme.components.CheckBox.element"
|
|
34
|
+
(change)="handleChange($event)"
|
|
35
|
+
/>
|
|
36
|
+
|
|
37
|
+
<label [htmlFor]="inputId" [class]="theme.components.CheckBox.label">{{
|
|
38
|
+
resolvedLabel()
|
|
39
|
+
}}</label>
|
|
40
|
+
</section>
|
|
41
|
+
`,
|
|
42
|
+
styles: `
|
|
43
|
+
:host {
|
|
44
|
+
display: block;
|
|
45
|
+
flex: var(--weight);
|
|
46
|
+
min-height: 0;
|
|
47
|
+
overflow: auto;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
input {
|
|
51
|
+
display: block;
|
|
52
|
+
width: 100%;
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
})
|
|
56
|
+
export class Checkbox extends DynamicComponent {
|
|
57
|
+
readonly value = input.required<Primitives.BooleanValue | null>();
|
|
58
|
+
readonly label = input.required<Primitives.StringValue | null>();
|
|
59
|
+
|
|
60
|
+
protected inputChecked = computed(() => super.resolvePrimitive(this.value()) ?? false);
|
|
61
|
+
protected resolvedLabel = computed(() => super.resolvePrimitive(this.label()));
|
|
62
|
+
protected inputId = super.getUniqueId('a2ui-checkbox');
|
|
63
|
+
|
|
64
|
+
protected handleChange(event: Event) {
|
|
65
|
+
const path = this.value()?.path;
|
|
66
|
+
|
|
67
|
+
if (!(event.target instanceof HTMLInputElement) || !path) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.processor.setData(this.component(), path, event.target.checked, this.surfaceId());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 { 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-column',
|
|
24
|
+
imports: [Renderer],
|
|
25
|
+
styles: `
|
|
26
|
+
:host {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex: var(--weight);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
section {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
min-width: 100%;
|
|
35
|
+
height: 100%;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.align-start {
|
|
40
|
+
align-items: start;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.align-center {
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.align-end {
|
|
48
|
+
align-items: end;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.align-stretch {
|
|
52
|
+
align-items: stretch;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.distribute-start {
|
|
56
|
+
justify-content: start;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.distribute-center {
|
|
60
|
+
justify-content: center;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.distribute-end {
|
|
64
|
+
justify-content: end;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.distribute-spaceBetween {
|
|
68
|
+
justify-content: space-between;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.distribute-spaceAround {
|
|
72
|
+
justify-content: space-around;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.distribute-spaceEvenly {
|
|
76
|
+
justify-content: space-evenly;
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
79
|
+
template: `
|
|
80
|
+
<section [class]="classes()" [style]="theme.additionalStyles?.Column">
|
|
81
|
+
@for (child of component().properties.children; track child) {
|
|
82
|
+
<ng-container a2ui-renderer [surfaceId]="surfaceId()!" [component]="child" />
|
|
83
|
+
}
|
|
84
|
+
</section>
|
|
85
|
+
`,
|
|
86
|
+
})
|
|
87
|
+
export class Column extends DynamicComponent<Types.ColumnNode> {
|
|
88
|
+
readonly alignment = input<Types.ResolvedColumn['alignment']>('stretch');
|
|
89
|
+
readonly distribution = input<Types.ResolvedColumn['distribution']>('start');
|
|
90
|
+
|
|
91
|
+
protected readonly classes = computed(() => ({
|
|
92
|
+
...this.theme.components.Column,
|
|
93
|
+
[`align-${this.alignment()}`]: true,
|
|
94
|
+
[`distribute-${this.distribution()}`]: true,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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 { computed, Component, 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-datetime-input',
|
|
23
|
+
template: `
|
|
24
|
+
<section [class]="theme.components.DateTimeInput.container">
|
|
25
|
+
<label [for]="inputId" [class]="theme.components.DateTimeInput.label">{{ label() }}</label>
|
|
26
|
+
|
|
27
|
+
<input
|
|
28
|
+
autocomplete="off"
|
|
29
|
+
[attr.type]="inputType()"
|
|
30
|
+
[id]="inputId"
|
|
31
|
+
[class]="theme.components.DateTimeInput.element"
|
|
32
|
+
[style]="theme.additionalStyles?.DateTimeInput"
|
|
33
|
+
[value]="inputValue()"
|
|
34
|
+
(input)="handleInput($event)"
|
|
35
|
+
/>
|
|
36
|
+
</section>
|
|
37
|
+
`,
|
|
38
|
+
styles: `
|
|
39
|
+
:host {
|
|
40
|
+
display: block;
|
|
41
|
+
flex: var(--weight);
|
|
42
|
+
min-height: 0;
|
|
43
|
+
overflow: auto;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
input {
|
|
47
|
+
display: block;
|
|
48
|
+
width: 100%;
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
})
|
|
53
|
+
export class DatetimeInput extends DynamicComponent {
|
|
54
|
+
readonly value = input.required<Primitives.StringValue | null>();
|
|
55
|
+
readonly enableDate = input.required<boolean>();
|
|
56
|
+
readonly enableTime = input.required<boolean>();
|
|
57
|
+
protected readonly inputId = super.getUniqueId('a2ui-datetime-input');
|
|
58
|
+
|
|
59
|
+
protected inputType = computed(() => {
|
|
60
|
+
const enableDate = this.enableDate();
|
|
61
|
+
const enableTime = this.enableTime();
|
|
62
|
+
|
|
63
|
+
if (enableDate && enableTime) {
|
|
64
|
+
return 'datetime-local';
|
|
65
|
+
} else if (enableDate) {
|
|
66
|
+
return 'date';
|
|
67
|
+
} else if (enableTime) {
|
|
68
|
+
return 'time';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return 'datetime-local';
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
protected label = computed(() => {
|
|
75
|
+
// TODO: this should likely be passed from the model.
|
|
76
|
+
const inputType = this.inputType();
|
|
77
|
+
|
|
78
|
+
if (inputType === 'date') {
|
|
79
|
+
return 'Date';
|
|
80
|
+
} else if (inputType === 'time') {
|
|
81
|
+
return 'Time';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return 'Date & Time';
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
protected inputValue = computed(() => {
|
|
88
|
+
const inputType = this.inputType();
|
|
89
|
+
const parsed = super.resolvePrimitive(this.value()) || '';
|
|
90
|
+
const date = parsed ? new Date(parsed) : null;
|
|
91
|
+
|
|
92
|
+
if (!date || isNaN(date.getTime())) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const year = this.padNumber(date.getFullYear());
|
|
97
|
+
const month = this.padNumber(date.getMonth());
|
|
98
|
+
const day = this.padNumber(date.getDate());
|
|
99
|
+
const hours = this.padNumber(date.getHours());
|
|
100
|
+
const minutes = this.padNumber(date.getMinutes());
|
|
101
|
+
|
|
102
|
+
// Browsers are picky with what format they allow for the `value` attribute of date/time inputs.
|
|
103
|
+
// We need to parse it out of the provided value. Note that we don't use `toISOString`,
|
|
104
|
+
// because the resulting value is relative to UTC.
|
|
105
|
+
if (inputType === 'date') {
|
|
106
|
+
return `${year}-${month}-${day}`;
|
|
107
|
+
} else if (inputType === 'time') {
|
|
108
|
+
return `${hours}:${minutes}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
protected handleInput(event: Event) {
|
|
115
|
+
const path = this.value()?.path;
|
|
116
|
+
|
|
117
|
+
if (!(event.target instanceof HTMLInputElement) || !path) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.processor.setData(this.component(), path, event.target.value, this.surfaceId());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private padNumber(value: number) {
|
|
125
|
+
return value.toString().padStart(2, '0');
|
|
126
|
+
}
|
|
127
|
+
}
|