@antglobal/copilot-cards-mini-program 0.0.0 → 1.0.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.
- package/README.md +1 -3
- package/dist/action-context/index.d.ts +44 -0
- package/dist/action-context/index.js +71 -0
- package/dist/action-context/index.js.map +1 -0
- package/dist/adapter/alipay.d.ts +22 -0
- package/dist/adapter/alipay.js +66 -0
- package/dist/adapter/alipay.js.map +1 -0
- package/dist/adapter/index.d.ts +53 -0
- package/dist/adapter/index.js +3 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/adapter/wechat.d.ts +22 -0
- package/dist/adapter/wechat.js +66 -0
- package/dist/adapter/wechat.js.map +1 -0
- package/dist/components/card-button/index.acss +61 -0
- package/dist/components/card-button/index.axml +9 -0
- package/dist/components/card-button/index.d.ts +23 -0
- package/dist/components/card-button/index.js +27 -0
- package/dist/components/card-button/index.js.map +1 -0
- package/dist/components/card-button/index.wxml +9 -0
- package/dist/components/card-divider/index.acss +8 -0
- package/dist/components/card-divider/index.axml +5 -0
- package/dist/components/card-divider/index.d.ts +11 -0
- package/dist/components/card-divider/index.js +14 -0
- package/dist/components/card-divider/index.js.map +1 -0
- package/dist/components/card-divider/index.wxml +5 -0
- package/dist/components/card-image/index.acss +7 -0
- package/dist/components/card-image/index.axml +9 -0
- package/dist/components/card-image/index.d.ts +22 -0
- package/dist/components/card-image/index.js +23 -0
- package/dist/components/card-image/index.js.map +1 -0
- package/dist/components/card-image/index.wxml +9 -0
- package/dist/components/card-input/index.acss +24 -0
- package/dist/components/card-input/index.axml +16 -0
- package/dist/components/card-input/index.d.ts +25 -0
- package/dist/components/card-input/index.js +46 -0
- package/dist/components/card-input/index.js.map +1 -0
- package/dist/components/card-input/index.wxml +16 -0
- package/dist/components/card-node/index.acss +5 -0
- package/dist/components/card-node/index.axml +27 -0
- package/dist/components/card-node/index.d.ts +31 -0
- package/dist/components/card-node/index.js +29 -0
- package/dist/components/card-node/index.js.map +1 -0
- package/dist/components/card-node/index.wxml +27 -0
- package/dist/components/card-root/index.acss +4 -0
- package/dist/components/card-root/index.axml +4 -0
- package/dist/components/card-root/index.d.ts +78 -0
- package/dist/components/card-root/index.js +94 -0
- package/dist/components/card-root/index.js.map +1 -0
- package/dist/components/card-root/index.wxml +4 -0
- package/dist/components/card-text/index.acss +11 -0
- package/dist/components/card-text/index.axml +8 -0
- package/dist/components/card-text/index.d.ts +23 -0
- package/dist/components/card-text/index.js +24 -0
- package/dist/components/card-text/index.js.map +1 -0
- package/dist/components/card-text/index.wxml +8 -0
- package/dist/events/index.d.ts +37 -0
- package/dist/events/index.js +51 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/renderer/index.d.ts +67 -0
- package/dist/renderer/index.js +159 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/transform.d.ts +24 -0
- package/dist/renderer/transform.js +88 -0
- package/dist/renderer/transform.js.map +1 -0
- package/dist/streaming/index.d.ts +80 -0
- package/dist/streaming/index.js +231 -0
- package/dist/streaming/index.js.map +1 -0
- package/package.json +30 -7
- package/LEGAL.md +0 -7
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
.card-input {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.card-input__label {
|
|
7
|
+
font-size: 28rpx;
|
|
8
|
+
color: #333333;
|
|
9
|
+
margin-bottom: 8rpx;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.card-input__field {
|
|
13
|
+
border: 1rpx solid #D9D9D9;
|
|
14
|
+
border-radius: 8rpx;
|
|
15
|
+
padding: 16rpx 24rpx;
|
|
16
|
+
font-size: 28rpx;
|
|
17
|
+
color: #333333;
|
|
18
|
+
background-color: #FFFFFF;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.card-input__field--disabled {
|
|
22
|
+
background-color: #F5F5F5;
|
|
23
|
+
color: #C0C0C0;
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!-- card-input: Alipay template -->
|
|
2
|
+
<view class="card-input" style="{{node.props._styleString || ''}}">
|
|
3
|
+
<text a:if="{{node.props.label}}" class="card-input__label">{{node.props.label}}</text>
|
|
4
|
+
<input
|
|
5
|
+
class="card-input__field {{node.disabled ? 'card-input__field--disabled' : ''}}"
|
|
6
|
+
type="{{node.props.type || 'text'}}"
|
|
7
|
+
password="{{node.props.type === 'password'}}"
|
|
8
|
+
placeholder="{{node.props.placeholder || ''}}"
|
|
9
|
+
value="{{node.props.value || ''}}"
|
|
10
|
+
disabled="{{node.disabled}}"
|
|
11
|
+
maxlength="{{node.props.maxLength || -1}}"
|
|
12
|
+
onInput="onInput"
|
|
13
|
+
onBlur="onChange"
|
|
14
|
+
onConfirm="onConfirm"
|
|
15
|
+
/>
|
|
16
|
+
</view>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MiniProgramRenderNode } from '../../renderer/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* card-input — Input component for mini-program.
|
|
5
|
+
* Supports text/password/number types with placeholder and label.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface CardInputInstance {
|
|
9
|
+
props: {
|
|
10
|
+
node: MiniProgramRenderNode | null;
|
|
11
|
+
};
|
|
12
|
+
triggerEvent(name: string, detail?: any): void;
|
|
13
|
+
}
|
|
14
|
+
declare function createCardInputComponent(): {
|
|
15
|
+
props: {
|
|
16
|
+
node: null;
|
|
17
|
+
};
|
|
18
|
+
methods: {
|
|
19
|
+
onInput(this: CardInputInstance, e: any): void;
|
|
20
|
+
onChange(this: CardInputInstance, e: any): void;
|
|
21
|
+
onConfirm(this: CardInputInstance, e: any): void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { createCardInputComponent };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* card-input — Input component for mini-program.
|
|
3
|
+
* Supports text/password/number types with placeholder and label.
|
|
4
|
+
*/
|
|
5
|
+
function createCardInputComponent() {
|
|
6
|
+
return {
|
|
7
|
+
props: {
|
|
8
|
+
node: null,
|
|
9
|
+
},
|
|
10
|
+
methods: {
|
|
11
|
+
onInput(e) {
|
|
12
|
+
const value = e.detail?.value ?? '';
|
|
13
|
+
if (!this.props.node)
|
|
14
|
+
return;
|
|
15
|
+
this.triggerEvent('event', {
|
|
16
|
+
nodeId: this.props.node.id,
|
|
17
|
+
eventName: 'onInput',
|
|
18
|
+
value,
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
onChange(e) {
|
|
22
|
+
const value = e.detail?.value ?? '';
|
|
23
|
+
if (!this.props.node)
|
|
24
|
+
return;
|
|
25
|
+
this.triggerEvent('event', {
|
|
26
|
+
nodeId: this.props.node.id,
|
|
27
|
+
eventName: 'onChange',
|
|
28
|
+
value,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
onConfirm(e) {
|
|
32
|
+
const value = e.detail?.value ?? '';
|
|
33
|
+
if (!this.props.node)
|
|
34
|
+
return;
|
|
35
|
+
this.triggerEvent('event', {
|
|
36
|
+
nodeId: this.props.node.id,
|
|
37
|
+
eventName: 'onSubmit',
|
|
38
|
+
value,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { createCardInputComponent };
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!-- card-input: WeChat template -->
|
|
2
|
+
<view class="card-input" style="{{node.props._styleString || ''}}">
|
|
3
|
+
<text wx:if="{{node.props.label}}" class="card-input__label">{{node.props.label}}</text>
|
|
4
|
+
<input
|
|
5
|
+
class="card-input__field {{node.disabled ? 'card-input__field--disabled' : ''}}"
|
|
6
|
+
type="{{node.props.type || 'text'}}"
|
|
7
|
+
password="{{node.props.type === 'password'}}"
|
|
8
|
+
placeholder="{{node.props.placeholder || ''}}"
|
|
9
|
+
value="{{node.props.value || ''}}"
|
|
10
|
+
disabled="{{node.disabled}}"
|
|
11
|
+
maxlength="{{node.props.maxLength || -1}}"
|
|
12
|
+
bindinput="onInput"
|
|
13
|
+
bindblur="onChange"
|
|
14
|
+
bindconfirm="onConfirm"
|
|
15
|
+
/>
|
|
16
|
+
</view>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!-- card-node: Alipay recursive dispatcher template -->
|
|
2
|
+
<block a:if="{{node && node.visible}}">
|
|
3
|
+
<!-- Text -->
|
|
4
|
+
<card-text a:if="{{node.type === 'Text'}}" node="{{node}}" onEvent="onEvent" />
|
|
5
|
+
|
|
6
|
+
<!-- Button -->
|
|
7
|
+
<card-button a:elif="{{node.type === 'Button'}}" node="{{node}}" onEvent="onEvent" />
|
|
8
|
+
|
|
9
|
+
<!-- Image -->
|
|
10
|
+
<card-image a:elif="{{node.type === 'Image'}}" node="{{node}}" onEvent="onEvent" />
|
|
11
|
+
|
|
12
|
+
<!-- Input -->
|
|
13
|
+
<card-input a:elif="{{node.type === 'Input'}}" node="{{node}}" onEvent="onEvent" />
|
|
14
|
+
|
|
15
|
+
<!-- Divider -->
|
|
16
|
+
<card-divider a:elif="{{node.type === 'Divider'}}" node="{{node}}" />
|
|
17
|
+
|
|
18
|
+
<!-- Default container (unknown type or layout container) -->
|
|
19
|
+
<view a:else class="card-container card-{{node.type}}" style="{{node.props._styleString || ''}}">
|
|
20
|
+
<card-node
|
|
21
|
+
a:for="{{node.children}}"
|
|
22
|
+
a:key="id"
|
|
23
|
+
node="{{item}}"
|
|
24
|
+
onEvent="onEvent"
|
|
25
|
+
/>
|
|
26
|
+
</view>
|
|
27
|
+
</block>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MiniProgramRenderNode } from '../../renderer/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* card-node — Recursive dispatcher component.
|
|
5
|
+
*
|
|
6
|
+
* Receives a MiniProgramRenderNode and dispatches rendering
|
|
7
|
+
* to the appropriate typed component based on node.type.
|
|
8
|
+
* For unknown types, renders as a generic container with children.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface CardNodeInstance {
|
|
12
|
+
props: {
|
|
13
|
+
node: MiniProgramRenderNode | null;
|
|
14
|
+
};
|
|
15
|
+
triggerEvent(name: string, detail?: any): void;
|
|
16
|
+
}
|
|
17
|
+
declare function createCardNodeComponent(): {
|
|
18
|
+
props: {
|
|
19
|
+
node: null;
|
|
20
|
+
};
|
|
21
|
+
methods: {
|
|
22
|
+
/**
|
|
23
|
+
* Bubble events up to card-root.
|
|
24
|
+
* Each leaf component calls triggerEvent('event', { nodeId, eventName, ... })
|
|
25
|
+
* which flows through card-node → card-root.
|
|
26
|
+
*/
|
|
27
|
+
onEvent(this: CardNodeInstance, e: any): void;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { createCardNodeComponent };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* card-node — Recursive dispatcher component.
|
|
3
|
+
*
|
|
4
|
+
* Receives a MiniProgramRenderNode and dispatches rendering
|
|
5
|
+
* to the appropriate typed component based on node.type.
|
|
6
|
+
* For unknown types, renders as a generic container with children.
|
|
7
|
+
*/
|
|
8
|
+
// ─── Component Definition ────────────────────────────────────────
|
|
9
|
+
function createCardNodeComponent() {
|
|
10
|
+
return {
|
|
11
|
+
props: {
|
|
12
|
+
node: null,
|
|
13
|
+
},
|
|
14
|
+
methods: {
|
|
15
|
+
/**
|
|
16
|
+
* Bubble events up to card-root.
|
|
17
|
+
* Each leaf component calls triggerEvent('event', { nodeId, eventName, ... })
|
|
18
|
+
* which flows through card-node → card-root.
|
|
19
|
+
*/
|
|
20
|
+
onEvent(e) {
|
|
21
|
+
// Pass through to parent
|
|
22
|
+
this.triggerEvent('event', e.detail ?? e);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { createCardNodeComponent };
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!-- card-node: WeChat recursive dispatcher template -->
|
|
2
|
+
<block wx:if="{{node && node.visible}}">
|
|
3
|
+
<!-- Text -->
|
|
4
|
+
<card-text wx:if="{{node.type === 'Text'}}" node="{{node}}" bind:event="onEvent" />
|
|
5
|
+
|
|
6
|
+
<!-- Button -->
|
|
7
|
+
<card-button wx:elif="{{node.type === 'Button'}}" node="{{node}}" bind:event="onEvent" />
|
|
8
|
+
|
|
9
|
+
<!-- Image -->
|
|
10
|
+
<card-image wx:elif="{{node.type === 'Image'}}" node="{{node}}" bind:event="onEvent" />
|
|
11
|
+
|
|
12
|
+
<!-- Input -->
|
|
13
|
+
<card-input wx:elif="{{node.type === 'Input'}}" node="{{node}}" bind:event="onEvent" />
|
|
14
|
+
|
|
15
|
+
<!-- Divider -->
|
|
16
|
+
<card-divider wx:elif="{{node.type === 'Divider'}}" node="{{node}}" />
|
|
17
|
+
|
|
18
|
+
<!-- Default container (unknown type or layout container) -->
|
|
19
|
+
<view wx:else class="card-container card-{{node.type}}" style="{{node.props._styleString || ''}}">
|
|
20
|
+
<card-node
|
|
21
|
+
wx:for="{{node.children}}"
|
|
22
|
+
wx:key="id"
|
|
23
|
+
node="{{item}}"
|
|
24
|
+
bind:event="onEvent"
|
|
25
|
+
/>
|
|
26
|
+
</view>
|
|
27
|
+
</block>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MiniProgramRenderNode, MiniProgramCardInstance } from '../../renderer/index.js';
|
|
2
|
+
import { MiniProgramAdapter } from '../../adapter/index.js';
|
|
3
|
+
import { CardSchemaInput } from '@antglobal/copilot-cards-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* card-root — Root container component for mini-program card rendering.
|
|
7
|
+
*
|
|
8
|
+
* This is the entry point component that accepts a CardSchema,
|
|
9
|
+
* initializes the renderer, and drives the recursive rendering pipeline.
|
|
10
|
+
*
|
|
11
|
+
* Usage in page AXML/WXML:
|
|
12
|
+
* ```xml
|
|
13
|
+
* <card-root schema="{{cardSchema}}" variables="{{variables}}" />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
interface CardRootProps {
|
|
18
|
+
/** The card schema JSON */
|
|
19
|
+
schema: CardSchemaInput | null;
|
|
20
|
+
/** External variables to merge */
|
|
21
|
+
variables: Record<string, any> | null;
|
|
22
|
+
/** Platform adapter instance (injected from page) */
|
|
23
|
+
adapter: MiniProgramAdapter | null;
|
|
24
|
+
/** Bot ID for bot-scoped action handlers */
|
|
25
|
+
botId: string;
|
|
26
|
+
}
|
|
27
|
+
interface CardRootData {
|
|
28
|
+
tree: MiniProgramRenderNode | null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Mini-program component instance interface.
|
|
32
|
+
* This is the `this` context inside Component() methods.
|
|
33
|
+
*/
|
|
34
|
+
interface CardRootInstance {
|
|
35
|
+
props: CardRootProps;
|
|
36
|
+
data: CardRootData;
|
|
37
|
+
_instance: MiniProgramCardInstance | null;
|
|
38
|
+
setData(data: Partial<CardRootData>): void;
|
|
39
|
+
triggerEvent(name: string, detail?: any): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create the card-root component definition object.
|
|
43
|
+
*
|
|
44
|
+
* This returns a plain object that can be passed to the platform's
|
|
45
|
+
* `Component()` constructor (Alipay or WeChat).
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Alipay
|
|
50
|
+
* Component(createCardRootComponent());
|
|
51
|
+
*
|
|
52
|
+
* // WeChat
|
|
53
|
+
* Component(createCardRootComponent());
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function createCardRootComponent(): {
|
|
57
|
+
props: {
|
|
58
|
+
schema: null;
|
|
59
|
+
variables: null;
|
|
60
|
+
adapter: null;
|
|
61
|
+
botId: string;
|
|
62
|
+
};
|
|
63
|
+
data: {
|
|
64
|
+
tree: null;
|
|
65
|
+
};
|
|
66
|
+
didMount(this: CardRootInstance): void;
|
|
67
|
+
attached(this: CardRootInstance): void;
|
|
68
|
+
didUpdate(this: CardRootInstance, prevProps: CardRootProps): void;
|
|
69
|
+
didUnmount(this: CardRootInstance): void;
|
|
70
|
+
detached(this: CardRootInstance): void;
|
|
71
|
+
methods: {
|
|
72
|
+
handleEvent(this: CardRootInstance, e: any): Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
_instance: MiniProgramCardInstance | null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { createCardRootComponent };
|
|
78
|
+
export type { CardRootData, CardRootProps };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { renderForMiniProgram } from '../../renderer/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* card-root — Root container component for mini-program card rendering.
|
|
5
|
+
*
|
|
6
|
+
* This is the entry point component that accepts a CardSchema,
|
|
7
|
+
* initializes the renderer, and drives the recursive rendering pipeline.
|
|
8
|
+
*
|
|
9
|
+
* Usage in page AXML/WXML:
|
|
10
|
+
* ```xml
|
|
11
|
+
* <card-root schema="{{cardSchema}}" variables="{{variables}}" />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
// ─── Component Definition ────────────────────────────────────────
|
|
15
|
+
/**
|
|
16
|
+
* Create the card-root component definition object.
|
|
17
|
+
*
|
|
18
|
+
* This returns a plain object that can be passed to the platform's
|
|
19
|
+
* `Component()` constructor (Alipay or WeChat).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Alipay
|
|
24
|
+
* Component(createCardRootComponent());
|
|
25
|
+
*
|
|
26
|
+
* // WeChat
|
|
27
|
+
* Component(createCardRootComponent());
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function createCardRootComponent() {
|
|
31
|
+
function init(ctx) {
|
|
32
|
+
if (!ctx.props.schema || !ctx.props.adapter) {
|
|
33
|
+
console.warn('[card-root] Missing schema or adapter prop');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
ctx._instance = renderForMiniProgram(ctx.props.schema, {
|
|
37
|
+
adapter: ctx.props.adapter,
|
|
38
|
+
data: ctx.props.variables ?? undefined,
|
|
39
|
+
botId: ctx.props.botId || undefined,
|
|
40
|
+
onEmit: (eventName, payload) => {
|
|
41
|
+
ctx.triggerEvent('emit', { eventName, payload });
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
ctx.setData({ tree: ctx._instance.getData().tree });
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
props: {
|
|
48
|
+
schema: null,
|
|
49
|
+
variables: null,
|
|
50
|
+
adapter: null,
|
|
51
|
+
botId: '',
|
|
52
|
+
},
|
|
53
|
+
data: {
|
|
54
|
+
tree: null,
|
|
55
|
+
},
|
|
56
|
+
// Alipay lifecycle
|
|
57
|
+
didMount() {
|
|
58
|
+
init(this);
|
|
59
|
+
},
|
|
60
|
+
// WeChat lifecycle
|
|
61
|
+
attached() {
|
|
62
|
+
init(this);
|
|
63
|
+
},
|
|
64
|
+
didUpdate(prevProps) {
|
|
65
|
+
if (prevProps.variables !== this.props.variables && this._instance) {
|
|
66
|
+
const result = this._instance.updateVariables(this.props.variables ?? {});
|
|
67
|
+
this.setData({ tree: result.tree });
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
didUnmount() {
|
|
71
|
+
this._instance?.dispose();
|
|
72
|
+
this._instance = null;
|
|
73
|
+
},
|
|
74
|
+
detached() {
|
|
75
|
+
this._instance?.dispose();
|
|
76
|
+
this._instance = null;
|
|
77
|
+
},
|
|
78
|
+
methods: {
|
|
79
|
+
async handleEvent(e) {
|
|
80
|
+
const detail = e.detail ?? e.target?.dataset ?? {};
|
|
81
|
+
const { nodeId, eventName } = detail;
|
|
82
|
+
if (!nodeId || !eventName || !this._instance)
|
|
83
|
+
return;
|
|
84
|
+
await this._instance.handleEvent(nodeId, eventName, detail.value ?? detail);
|
|
85
|
+
// Re-sync data after event handling (variables may have changed)
|
|
86
|
+
this.setData({ tree: this._instance.getData().tree });
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
_instance: null,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { createCardRootComponent };
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<!-- card-text: Alipay template -->
|
|
2
|
+
<view
|
|
3
|
+
class="card-text {{node.props.bold ? 'card-text--bold' : ''}} {{node.props.italic ? 'card-text--italic' : ''}}"
|
|
4
|
+
style="font-size: {{node.props.fontSize || '14px'}}; color: {{node.props.color || '#333333'}}; line-height: {{node.props.lineHeight || '1.5'}}; text-align: {{node.props.textAlign || 'left'}}; {{node.props.style ? node.props._styleString : ''}}"
|
|
5
|
+
onTap="onTap"
|
|
6
|
+
>
|
|
7
|
+
<text>{{node.props.content}}</text>
|
|
8
|
+
</view>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MiniProgramRenderNode } from '../../renderer/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* card-text — Text component for mini-program.
|
|
5
|
+
* Renders text content with styling support.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface CardTextInstance {
|
|
9
|
+
props: {
|
|
10
|
+
node: MiniProgramRenderNode | null;
|
|
11
|
+
};
|
|
12
|
+
triggerEvent(name: string, detail?: any): void;
|
|
13
|
+
}
|
|
14
|
+
declare function createCardTextComponent(): {
|
|
15
|
+
props: {
|
|
16
|
+
node: null;
|
|
17
|
+
};
|
|
18
|
+
methods: {
|
|
19
|
+
onTap(this: CardTextInstance): void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { createCardTextComponent };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* card-text — Text component for mini-program.
|
|
3
|
+
* Renders text content with styling support.
|
|
4
|
+
*/
|
|
5
|
+
function createCardTextComponent() {
|
|
6
|
+
return {
|
|
7
|
+
props: {
|
|
8
|
+
node: null,
|
|
9
|
+
},
|
|
10
|
+
methods: {
|
|
11
|
+
onTap() {
|
|
12
|
+
if (!this.props.node?.events.includes('onClick'))
|
|
13
|
+
return;
|
|
14
|
+
this.triggerEvent('event', {
|
|
15
|
+
nodeId: this.props.node.id,
|
|
16
|
+
eventName: 'onClick',
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { createCardTextComponent };
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<!-- card-text: WeChat template -->
|
|
2
|
+
<view
|
|
3
|
+
class="card-text {{node.props.bold ? 'card-text--bold' : ''}} {{node.props.italic ? 'card-text--italic' : ''}}"
|
|
4
|
+
style="font-size: {{node.props.fontSize || '14px'}}; color: {{node.props.color || '#333333'}}; line-height: {{node.props.lineHeight || '1.5'}}; text-align: {{node.props.textAlign || 'left'}}; {{node.props.style ? node.props._styleString : ''}}"
|
|
5
|
+
bindtap="onTap"
|
|
6
|
+
>
|
|
7
|
+
<text>{{node.props.content}}</text>
|
|
8
|
+
</view>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system utilities for mini-program card components.
|
|
3
|
+
*
|
|
4
|
+
* Maps between schema event names and mini-program native events,
|
|
5
|
+
* and provides helpers for event bubbling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Map from mini-program native event names to schema event names.
|
|
9
|
+
* Mini-program templates use `bindtap`, `bindinput`, etc.
|
|
10
|
+
* Schema uses `onClick`, `onInput`, etc.
|
|
11
|
+
*/
|
|
12
|
+
declare const nativeToSchemaEventMap: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Map from schema event names to Alipay mini-program event bindings.
|
|
15
|
+
*/
|
|
16
|
+
declare const schemaToAlipayEventMap: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Map from schema event names to WeChat mini-program event bindings.
|
|
19
|
+
*/
|
|
20
|
+
declare const schemaToWeChatEventMap: Record<string, string>;
|
|
21
|
+
interface CardEventDetail {
|
|
22
|
+
/** The node ID that triggered the event */
|
|
23
|
+
nodeId: string;
|
|
24
|
+
/** The schema event name (e.g. 'onClick', 'onInput') */
|
|
25
|
+
eventName: string;
|
|
26
|
+
/** Optional event value (e.g. input value) */
|
|
27
|
+
value?: unknown;
|
|
28
|
+
/** Additional event data */
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a standardized event detail object for triggerEvent.
|
|
33
|
+
*/
|
|
34
|
+
declare function createEventDetail(nodeId: string, eventName: string, extra?: Record<string, unknown>): CardEventDetail;
|
|
35
|
+
|
|
36
|
+
export { createEventDetail, nativeToSchemaEventMap, schemaToAlipayEventMap, schemaToWeChatEventMap };
|
|
37
|
+
export type { CardEventDetail };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system utilities for mini-program card components.
|
|
3
|
+
*
|
|
4
|
+
* Maps between schema event names and mini-program native events,
|
|
5
|
+
* and provides helpers for event bubbling.
|
|
6
|
+
*/
|
|
7
|
+
// ─── Event Name Mapping ──────────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Map from mini-program native event names to schema event names.
|
|
10
|
+
* Mini-program templates use `bindtap`, `bindinput`, etc.
|
|
11
|
+
* Schema uses `onClick`, `onInput`, etc.
|
|
12
|
+
*/
|
|
13
|
+
const nativeToSchemaEventMap = {
|
|
14
|
+
tap: 'onClick',
|
|
15
|
+
input: 'onInput',
|
|
16
|
+
change: 'onChange',
|
|
17
|
+
confirm: 'onSubmit',
|
|
18
|
+
blur: 'onChange',
|
|
19
|
+
longpress: 'onLongPress',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Map from schema event names to Alipay mini-program event bindings.
|
|
23
|
+
*/
|
|
24
|
+
const schemaToAlipayEventMap = {
|
|
25
|
+
onClick: 'onTap',
|
|
26
|
+
onInput: 'onInput',
|
|
27
|
+
onChange: 'onBlur',
|
|
28
|
+
onSubmit: 'onConfirm',
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Map from schema event names to WeChat mini-program event bindings.
|
|
32
|
+
*/
|
|
33
|
+
const schemaToWeChatEventMap = {
|
|
34
|
+
onClick: 'bindtap',
|
|
35
|
+
onInput: 'bindinput',
|
|
36
|
+
onChange: 'bindblur',
|
|
37
|
+
onSubmit: 'bindconfirm',
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Create a standardized event detail object for triggerEvent.
|
|
41
|
+
*/
|
|
42
|
+
function createEventDetail(nodeId, eventName, extra) {
|
|
43
|
+
return {
|
|
44
|
+
nodeId,
|
|
45
|
+
eventName,
|
|
46
|
+
...extra,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createEventDetail, nativeToSchemaEventMap, schemaToAlipayEventMap, schemaToWeChatEventMap };
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { MiniProgramAdapter, MiniProgramNavigateOptions, MiniProgramRequestOptions, MiniProgramResponse, MiniProgramSystemInfo, MiniProgramToastOptions } from './adapter/index.js';
|
|
2
|
+
export { AlipayAdapter } from './adapter/alipay.js';
|
|
3
|
+
export { WeChatAdapter } from './adapter/wechat.js';
|
|
4
|
+
export { MiniProgramActionContextOptions, createMiniProgramActionContext } from './action-context/index.js';
|
|
5
|
+
export { MiniProgramCardInstance, MiniProgramRenderNode, MiniProgramRendererOptions, renderForMiniProgram } from './renderer/index.js';
|
|
6
|
+
export { createCardRootComponent } from './components/card-root/index.js';
|
|
7
|
+
export { createCardNodeComponent } from './components/card-node/index.js';
|
|
8
|
+
export { createCardTextComponent } from './components/card-text/index.js';
|
|
9
|
+
export { createCardButtonComponent } from './components/card-button/index.js';
|
|
10
|
+
export { createCardImageComponent } from './components/card-image/index.js';
|
|
11
|
+
export { createCardInputComponent } from './components/card-input/index.js';
|
|
12
|
+
export { createCardDividerComponent } from './components/card-divider/index.js';
|
|
13
|
+
export { CardEventDetail, createEventDetail, nativeToSchemaEventMap, schemaToAlipayEventMap, schemaToWeChatEventMap } from './events/index.js';
|
|
14
|
+
export { DataPatch, MiniProgramStreamingCardInstance, MiniProgramStreamingOptions, createStreamingCardInstance } from './streaming/index.js';
|
|
15
|
+
export { ActionRunnerContext, ActionStep, CardSchema, CardSchemaInput, ElementNode, ExpressionContext, ExpressionValue, RenderTreeNode, convertLegacySchema, createLifecycleManager, hasExpression, isLegacySchema, normalizeSchema, parseSchema, registerActionHandler, resolveDeep, resolveExpression, runActionStep, runActionSteps, validateSchema } from '@antglobal/copilot-cards-core';
|
|
16
|
+
export { transformNode, transformTree } from './renderer/transform.js';
|