@antglobal/copilot-cards-web 1.0.7 → 1.0.9
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 +79 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +867 -145
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ The package includes the core schema and action APIs, responsive rendering, Shad
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @antglobal/copilot-cards-web
|
|
10
|
+
npm install @antglobal/copilot-cards-web@1.0.8
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
`@antglobal/copilot-cards-core` is installed automatically.
|
|
@@ -50,6 +50,50 @@ card.updateVariables({ userName: "Alice" });
|
|
|
50
50
|
card.dispose();
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
## Stable host updates
|
|
54
|
+
|
|
55
|
+
Create the card once and keep its `CardInstance`. Input events should update
|
|
56
|
+
only the variables that changed. Do not call `renderCard()` again for input updates,
|
|
57
|
+
because remounting the card recreates image elements and can cause visible flicker.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import {
|
|
61
|
+
renderCard,
|
|
62
|
+
type CardInstance,
|
|
63
|
+
type CardSchema,
|
|
64
|
+
} from "@antglobal/copilot-cards-web";
|
|
65
|
+
|
|
66
|
+
let card: CardInstance | null = null;
|
|
67
|
+
|
|
68
|
+
export function mountDataRechargeCard(
|
|
69
|
+
container: HTMLElement,
|
|
70
|
+
schema: CardSchema,
|
|
71
|
+
): void {
|
|
72
|
+
card?.dispose();
|
|
73
|
+
card = renderCard(container, schema, {
|
|
74
|
+
emit: (eventName, payload) => {
|
|
75
|
+
if (eventName !== "dataRecharge.phone.input") return;
|
|
76
|
+
|
|
77
|
+
const value = String(
|
|
78
|
+
(payload as { value?: unknown } | undefined)?.value ?? "",
|
|
79
|
+
);
|
|
80
|
+
if (!card) return;
|
|
81
|
+
card.updateVariables({ phoneNumber: value });
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function unmountDataRechargeCard(): void {
|
|
87
|
+
card?.dispose();
|
|
88
|
+
card = null;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Keep `skuOptions` and `isSkuLoading` out of each keystroke patch unless their
|
|
93
|
+
values actually changed. Fetching or filtering SKU data can run from the
|
|
94
|
+
`dataRecharge.phone.commit` event instead of remounting the card on every
|
|
95
|
+
`dataRecharge.phone.input` event.
|
|
96
|
+
|
|
53
97
|
## Framework usage
|
|
54
98
|
|
|
55
99
|
The renderer accesses browser APIs and should be loaded on the client in frameworks that perform server-side rendering.
|
|
@@ -69,10 +113,44 @@ Renders a complete schema and returns a `CardInstance`:
|
|
|
69
113
|
```ts
|
|
70
114
|
interface CardInstance {
|
|
71
115
|
updateVariables(variables: Record<string, unknown>): void;
|
|
116
|
+
onScroll(nodeId: string, listener: CardScrollListener): () => void;
|
|
72
117
|
dispose(): void;
|
|
73
118
|
}
|
|
74
119
|
```
|
|
75
120
|
|
|
121
|
+
`CardScrollEvent` and `CardScrollListener` are top-level package exports. The
|
|
122
|
+
event contains readonly `node`, `scrollTop`, `scrollLeft`, `scrollHeight`,
|
|
123
|
+
`scrollWidth`, `clientHeight`, and `clientWidth` values:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import type {
|
|
127
|
+
CardScrollEvent,
|
|
128
|
+
CardScrollListener,
|
|
129
|
+
} from "@antglobal/copilot-cards-web";
|
|
130
|
+
|
|
131
|
+
const unsubscribe = card.onScroll("friendsList", event => {
|
|
132
|
+
const remaining =
|
|
133
|
+
event.scrollHeight - event.clientHeight - event.scrollTop;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
unsubscribe(); // Idempotent; card.dispose() also removes the subscription.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The subscription follows the logical node ID across physical replacement and
|
|
140
|
+
reports native-frequency values. It does not emit an initial, render, resize,
|
|
141
|
+
or `updateVariables` callback. Generated internal scroll tracks and scroll
|
|
142
|
+
ports inside Shadow DOM are not observed. Thresholds, throttling, requests,
|
|
143
|
+
locks, cursors, retries, and deduplication remain host responsibilities.
|
|
144
|
+
|
|
145
|
+
For pagination, continue passing the complete next array to `updateVariables`.
|
|
146
|
+
The SDK retains the Repeat owner and old prefix only when it can strictly prove
|
|
147
|
+
a structurally equal tail extension whose retained rendering is unchanged, on
|
|
148
|
+
a default-rendered `Container` with an unambiguous direct-child `default` or
|
|
149
|
+
`flex` layout. Every unproven case uses the existing replacement behavior; this
|
|
150
|
+
is not a general keyed diff or public append API. A trailing control object is
|
|
151
|
+
eligible only when it does not change retained rows. Put temporary loading UI
|
|
152
|
+
outside the Repeat owner when scroll identity matters.
|
|
153
|
+
|
|
76
154
|
Common render options include:
|
|
77
155
|
|
|
78
156
|
| Option | Purpose |
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,23 @@ interface CardFocusChangeEvent {
|
|
|
55
55
|
previousNode: CardNodeHandle | null;
|
|
56
56
|
}
|
|
57
57
|
type CardFocusChangeListener = (event: CardFocusChangeEvent) => void;
|
|
58
|
+
interface CardScrollEvent {
|
|
59
|
+
/** Stable logical handle for the scrolling card node. */
|
|
60
|
+
readonly node: CardNodeHandle;
|
|
61
|
+
/** Raw native vertical scroll offset. */
|
|
62
|
+
readonly scrollTop: number;
|
|
63
|
+
/** Raw native horizontal scroll offset, including negative RTL values. */
|
|
64
|
+
readonly scrollLeft: number;
|
|
65
|
+
/** Raw native scrollable content height. */
|
|
66
|
+
readonly scrollHeight: number;
|
|
67
|
+
/** Raw native scrollable content width. */
|
|
68
|
+
readonly scrollWidth: number;
|
|
69
|
+
/** Raw native viewport height. */
|
|
70
|
+
readonly clientHeight: number;
|
|
71
|
+
/** Raw native viewport width. */
|
|
72
|
+
readonly clientWidth: number;
|
|
73
|
+
}
|
|
74
|
+
type CardScrollListener = (event: CardScrollEvent) => void;
|
|
58
75
|
|
|
59
76
|
interface ResponsiveMobileOptions {
|
|
60
77
|
readonly unit: 'rem';
|
|
@@ -108,6 +125,8 @@ interface CardInstance {
|
|
|
108
125
|
getNode: (id: string) => CardNodeHandle;
|
|
109
126
|
/** Observe logical focus changes within this card. */
|
|
110
127
|
onFocusChange: (listener: CardFocusChangeListener) => () => void;
|
|
128
|
+
/** Observe native scroll metrics for one logical card node. */
|
|
129
|
+
onScroll: (nodeId: string, listener: CardScrollListener) => () => void;
|
|
111
130
|
}
|
|
112
131
|
/**
|
|
113
132
|
* Render a card schema into a container element.
|
|
@@ -707,6 +726,10 @@ declare class CardInput extends BaseElement {
|
|
|
707
726
|
declare class CardImage extends BaseElement {
|
|
708
727
|
static readonly is = "ai-card-image";
|
|
709
728
|
private _lightbox;
|
|
729
|
+
private readonly _wiredImages;
|
|
730
|
+
private readonly _wiredLightboxes;
|
|
731
|
+
private readonly _wiredCloseButtons;
|
|
732
|
+
private readonly _handleEscape;
|
|
710
733
|
protected render(): void;
|
|
711
734
|
private applyHostDimension;
|
|
712
735
|
private resolveDeclaredDimension;
|
|
@@ -1837,4 +1860,4 @@ declare const componentRenderers: Record<string, ComponentRenderer>;
|
|
|
1837
1860
|
declare function registerComponent(type: string, renderer: ComponentRenderer): void;
|
|
1838
1861
|
|
|
1839
1862
|
export { BaseElement, BotSDK, CardButton, CardChoiceItem, CardChoiceList, CardCollapse, CardCounter, CardDivider, CardForm, CardHtml, CardIcon, CardImage, CardInput, CardLoading, CardPasscodeInput, CardProgress, CardRate, CardSelect, CardSteps, CardSwitch, CardTag, CardText, DEFAULT_MOBILE_RESPONSIVE, LocalActionConfigProvider, RemoteActionConfigProvider, buildStyleString, componentRenderers, connectSSE, connectStreaming, convertPixelTokens, createResponsiveContext, createWebActionContext, isMobileViewport, onViewportChange, pxToRem, pxToVw, registerComponent, renderCard, renderStreamingCard, resolveSize, sanitizeHtml, trimIncompleteTag };
|
|
1840
|
-
export type { A2UIActionPayload, BotSDKOptions, ButtonProps, CardFocusChangeEvent, CardFocusChangeListener, CardInstance, CardNodeHandle, ChoiceIndicatorIcon, ChoiceItemProps, ChoiceListProps, ChoiceListValue, CollapseProps, ComponentRenderer, ConnectorConfig, CounterIcon, CounterProps, DividerProps, FormField, FormProps, FormRule, HtmlProps, IconProps, ImageProps, InputAffix, InputAffixConfig, InputProps, LoadingProps, PartialFinalizeResult, PasscodeInputProps, ProgressProps, ProgressSegment, RateProps, RenderCardOptions, ResponsiveContext, ResponsiveMobileOptions, ResponsiveOptions, SSEConnectOptions, SelectOption, SelectProps, SelectSize, SelectStyles, SelectVariant, StepIcon, StepItem, StepsProps, StreamingCardInstance, StreamingCardOptions, StreamingConnectOptions, StreamingConnection, SwitchProps, TagProps, TextProps, WebActionContextOptions };
|
|
1863
|
+
export type { A2UIActionPayload, BotSDKOptions, ButtonProps, CardFocusChangeEvent, CardFocusChangeListener, CardInstance, CardNodeHandle, CardScrollEvent, CardScrollListener, ChoiceIndicatorIcon, ChoiceItemProps, ChoiceListProps, ChoiceListValue, CollapseProps, ComponentRenderer, ConnectorConfig, CounterIcon, CounterProps, DividerProps, FormField, FormProps, FormRule, HtmlProps, IconProps, ImageProps, InputAffix, InputAffixConfig, InputProps, LoadingProps, PartialFinalizeResult, PasscodeInputProps, ProgressProps, ProgressSegment, RateProps, RenderCardOptions, ResponsiveContext, ResponsiveMobileOptions, ResponsiveOptions, SSEConnectOptions, SelectOption, SelectProps, SelectSize, SelectStyles, SelectVariant, StepIcon, StepItem, StepsProps, StreamingCardInstance, StreamingCardOptions, StreamingConnectOptions, StreamingConnection, SwitchProps, TagProps, TextProps, WebActionContextOptions };
|