@ray-js/t-agent-ui-ray 0.0.9-beta-1 → 0.0.9-beta-2

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.
@@ -1,7 +1,7 @@
1
1
  import './index.less';
2
2
  import { View } from '@ray-js/components';
3
- import React from 'react';
4
- import { useRenderOptions } from '../hooks';
3
+ import React, { useCallback, useEffect, useRef } from 'react';
4
+ import { useRenderOptions, useTileProps } from '../hooks';
5
5
  export default function CustomCardRender(_ref) {
6
6
  let {
7
7
  card
@@ -9,6 +9,23 @@ export default function CustomCardRender(_ref) {
9
9
  const {
10
10
  customCardMap
11
11
  } = useRenderOptions();
12
+ const {
13
+ emitEvent
14
+ } = useTileProps();
15
+ const ref = useRef(card);
16
+ useEffect(() => {
17
+ ref.current = card;
18
+ });
19
+ const setCardState = useCallback((state, options) => {
20
+ if (typeof state === 'function') {
21
+ state = state(ref.current.cardState);
22
+ }
23
+ emitEvent({
24
+ type: '@buildIn/setCardState',
25
+ state,
26
+ options: options || {}
27
+ });
28
+ }, [emitEvent]);
12
29
  const Card = customCardMap[card.cardCode];
13
30
  if (!Card) {
14
31
  return null;
@@ -16,6 +33,7 @@ export default function CustomCardRender(_ref) {
16
33
  return /*#__PURE__*/React.createElement(View, {
17
34
  className: "t-agent-custom-card-render"
18
35
  }, /*#__PURE__*/React.createElement(Card, {
19
- card: card
36
+ card: card,
37
+ setCardState: setCardState
20
38
  }));
21
39
  }
@@ -10,7 +10,7 @@ const TileRender = _ref => {
10
10
  side
11
11
  } = _ref;
12
12
  const agent = useChatAgent();
13
- const emitEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [tile.id]);
13
+ const emitEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [agent, tile.id]);
14
14
  const {
15
15
  renderTileAs
16
16
  } = useRenderOptions();
package/dist/contexts.js CHANGED
@@ -9,7 +9,8 @@ export const RenderContext = /*#__PURE__*/createContext({
9
9
  renderCardAs: () => null,
10
10
  customBlockTypes: [],
11
11
  customCardMap: {},
12
- getStaticResourceBizType: () => ''
12
+ getStaticResourceBizType: () => '',
13
+ i18nTranslate: key => key
13
14
  });
14
15
  export const ChatAgentContext = /*#__PURE__*/createContext({});
15
16
  export const TilePropsContext = /*#__PURE__*/createContext({});
@@ -85,6 +85,7 @@ const BubbleTile = props => {
85
85
  }
86
86
  return /*#__PURE__*/React.createElement(View, {
87
87
  className: "t-agent-bubble-tile t-agent-bubble-tile-".concat(side),
88
+ "data-testid": "t-agent-bubble-tile",
88
89
  onLongPress: () => {}
89
90
  }, side === 'end' && errorNode, /*#__PURE__*/React.createElement(View, {
90
91
  className: "t-agent-bubble-tile-bubble ".concat(loading ? 't-agent-bubble-tile-bubble-loading' : '')
@@ -14,7 +14,8 @@ const CardTile = props => {
14
14
  return null;
15
15
  }
16
16
  return /*#__PURE__*/React.createElement(View, {
17
- className: "t-agent-card-tile"
17
+ className: "t-agent-card-tile",
18
+ "data-testid": "t-agent-bubble-tile"
18
19
  }, node);
19
20
  };
20
21
  export default /*#__PURE__*/React.memo(CardTile);
package/dist/types.d.ts CHANGED
@@ -14,14 +14,20 @@ export interface MarkdownBlock {
14
14
  children: string;
15
15
  map: [number, number];
16
16
  }
17
+ export type ChatCardComponent<T = any, S = any> = React.ComponentType<{
18
+ card: ChatCardObject<T, S>;
19
+ setCardState: ChatCardComponentSetCardState<S>;
20
+ }>;
21
+ export interface ChatCardComponentSetCardStateOptions {
22
+ persist?: boolean;
23
+ }
24
+ export type ChatCardComponentSetCardState<S = any> = (state: S | ((prev: S | undefined) => S), options?: ChatCardComponentSetCardStateOptions) => void;
17
25
  export interface RenderOptions {
18
26
  renderTileAs: (props: TileProps) => React.ReactNode;
19
27
  renderCustomBlockAs: (block: MarkdownBlock) => React.ReactNode;
20
28
  renderCardAs: (card: ChatCardObject) => React.ReactNode;
21
29
  customBlockTypes: string[];
22
- customCardMap: Record<string, React.ComponentType<{
23
- card: ChatCardObject;
24
- }>>;
30
+ customCardMap: Record<string, ChatCardComponent>;
25
31
  getStaticResourceBizType: (src: string, scene?: string, data?: any) => string;
26
32
  i18nTranslate: (key: string) => string;
27
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent-ui-ray",
3
- "version": "0.0.9-beta-1",
3
+ "version": "0.0.9-beta-2",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -41,5 +41,5 @@
41
41
  "@types/echarts": "^4.9.22",
42
42
  "@types/markdown-it": "^14.1.1"
43
43
  },
44
- "gitHead": "df6f4f35caa6e62408450f14d9dcdd26f068283c"
44
+ "gitHead": "45f4f153fe2ce1e218a74f9bd3df726cf4e06d63"
45
45
  }