@doubao-dev/template 0.10.0 → 0.10.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.
@@ -2,6 +2,7 @@ import { Button, useTheme, useThemeClassName } from "@byted-doubao-apps/componen
2
2
  import { createEvent } from "@byted-doubao-apps/framework/api";
3
3
  import { clsx } from "clsx";
4
4
  import { useEffect } from "react";
5
+ import { useReportTemplateClick } from "../utils/report.js";
5
6
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
6
7
  import { reportAskHumanCardClick, reportAskHumanCardShow } from "./report.js";
7
8
  import "./styles.css";
@@ -14,7 +15,7 @@ function getAskHumanCardArrowIconContent(color) {
14
15
  function isAskHumanCardTextEmpty(content) {
15
16
  return null == content || '' === content;
16
17
  }
17
- function renderAskHumanCardItem({ item, index, optionBg, arrowColor }) {
18
+ function renderAskHumanCardItem({ item, index, optionBg, arrowColor, reportTemplateClick }) {
18
19
  const isLoading = true === item.loading;
19
20
  const arrowPosition = 'left' === item.showArrow || 'right' === item.showArrow ? item.showArrow : void 0;
20
21
  const arrowNode = arrowPosition ? <svg className="doubao-ask-human-card__option-icon" content={getAskHumanCardArrowIconContent(arrowColor)}/> : null;
@@ -24,6 +25,9 @@ function renderAskHumanCardItem({ item, index, optionBg, arrowColor }) {
24
25
  })} style={{
25
26
  backgroundColor: optionBg
26
27
  }} type="default" loading={isLoading} openType={item.openType} launchAppUrl={item.launchAppUrl} onLaunchApp={item.onLaunchApp} onLaunchAppError={item.onLaunchAppError} onClick={(event)=>{
28
+ reportTemplateClick('option', {
29
+ itemIndex: index
30
+ });
27
31
  reportAskHumanCardClick();
28
32
  item.onClick?.(event);
29
33
  }}>
@@ -38,13 +42,17 @@ function AskHumanCard(props) {
38
42
  const { items = [], variant = 'suggestion', onClick } = props;
39
43
  const cardStyle = useHostCardStyle();
40
44
  const theme = useTheme();
45
+ const reportTemplateClick = useReportTemplateClick({
46
+ templateName: 'AskHumanCard'
47
+ });
41
48
  const arrowColor = 'dark' === theme ? '#ffffff' : '#000000';
42
49
  const optionBg = 'dark' === theme ? '#000000' : '#ffffff';
43
50
  const optionNodes = items.map((item, index)=>renderAskHumanCardItem({
44
51
  item,
45
52
  index,
46
53
  optionBg,
47
- arrowColor
54
+ arrowColor,
55
+ reportTemplateClick
48
56
  })).filter((node)=>null != node);
49
57
  const isRow = 'jump' === variant && optionNodes.length > 0 && optionNodes.length <= 2;
50
58
  useEffect(()=>{
@@ -1 +1 @@
1
- import{reportEvent as o}from"@byted-doubao-apps/framework/api";import{getAppInfo as a}from"../utils/app-info";function p(p){o({eventName:p,data:{current_page:"chat",app_name:a().appName}})}function r(){p("doubao_apps_taxi_follow_up_show")}function t(){p("doubao_apps_taxi_follow_up_click")}export{t as reportAskHumanCardClick,r as reportAskHumanCardShow};
1
+ import{reportEvent as o}from"@byted-doubao-apps/framework/api";import{getAppInfo as a}from"../utils/app-info.js";function p(p){o({eventName:p,data:{current_page:"chat",app_name:a().appName}})}function r(){p("doubao_apps_taxi_follow_up_show")}function t(){p("doubao_apps_taxi_follow_up_click")}export{t as reportAskHumanCardClick,r as reportAskHumanCardShow};
@@ -3,6 +3,7 @@ import { TemplateCardFooter } from "../components/footer/index.js";
3
3
  import { TemplateCardHeader } from "../components/header/index.js";
4
4
  import { TemplateInfoSection } from "../components/info-section/index.js";
5
5
  import { TemplateProductSummary } from "../components/product-summary/index.js";
6
+ import { TemplateTelemetryProvider } from "../utils/report.js";
6
7
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
7
8
  import "./styles.css";
8
9
  function isCheckoutCardTextEmpty(content) {
@@ -18,7 +19,11 @@ function renderCheckoutCardProductItem({ item, index, showDivider }) {
18
19
  const { key, onClick, ...productSummaryProps } = item;
19
20
  return <view className="doubao-checkout-card__product" key={key ?? index}>
20
21
  {showDivider && <view className="doubao-checkout-card__divider"/>}
21
- <TemplateProductSummary {...productSummaryProps} onClick={onClick}/>
22
+ <TemplateTelemetryProvider value={{
23
+ itemIndex: index
24
+ }}>
25
+ <TemplateProductSummary {...productSummaryProps} onClick={onClick}/>
26
+ </TemplateTelemetryProvider>
22
27
  </view>;
23
28
  }
24
29
  function CheckoutCard(props) {
@@ -32,14 +37,18 @@ function CheckoutCard(props) {
32
37
  }));
33
38
  return nodes;
34
39
  }, []);
35
- return <view className={useThemeClassName('doubao-checkout-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
36
- <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
40
+ return <TemplateTelemetryProvider value={{
41
+ templateName: 'CheckoutCard'
42
+ }}>
43
+ <view className={useThemeClassName('doubao-checkout-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
44
+ <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
37
45
 
38
- {productNodes.length > 0 && <view className="doubao-checkout-card__products">{productNodes}</view>}
46
+ {productNodes.length > 0 && <view className="doubao-checkout-card__products">{productNodes}</view>}
39
47
 
40
- <TemplateInfoSection infoItems={infoItems} feeItems={feeItems} totalLabel={totalLabel} totalPrice={totalPrice} valueLayout="column"/>
48
+ <TemplateInfoSection infoItems={infoItems} feeItems={feeItems} totalLabel={totalLabel} totalPrice={totalPrice} valueLayout="column"/>
41
49
 
42
- <TemplateCardFooter secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement} primaryActionButton={footer?.primaryActionButton}/>
43
- </view>;
50
+ <TemplateCardFooter secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement} primaryActionButton={footer?.primaryActionButton}/>
51
+ </view>
52
+ </TemplateTelemetryProvider>;
44
53
  }
45
54
  export { CheckoutCard };
@@ -1,15 +1,22 @@
1
1
  import { Button } from "@byted-doubao-apps/components";
2
2
  import { Agreement } from "../../primitives/agreement/index.js";
3
+ import { useTemplateClickHandler } from "../../utils/report.js";
3
4
  import "./styles.css";
4
5
  function TemplateCardFooter(props) {
5
6
  const { primaryActionButton, secondaryActionButton, agreement } = props;
6
7
  const hasPrimaryAction = primaryActionButton?.text != null && primaryActionButton.text.length > 0;
7
8
  const hasSecondaryAction = secondaryActionButton?.text != null && secondaryActionButton.text.length > 0;
8
9
  const hasDefaultActions = hasPrimaryAction || hasSecondaryAction;
10
+ const handleSecondaryActionClick = useTemplateClickHandler('footer_secondary', secondaryActionButton?.onClick, {
11
+ clickText: secondaryActionButton?.text
12
+ });
13
+ const handlePrimaryActionClick = useTemplateClickHandler('footer_primary', primaryActionButton?.onClick, {
14
+ clickText: primaryActionButton?.text
15
+ });
9
16
  if (!hasDefaultActions) return agreement ? <Agreement {...agreement}/> : null;
10
17
  const actionBar = <view className="doubao-template-action-bar">
11
- {hasSecondaryAction && <Button className="doubao-template-action-bar__action" type="default" disabled={secondaryActionButton.disabled} loading={secondaryActionButton.loading} throttle={secondaryActionButton.throttle} text={secondaryActionButton.text} onClick={secondaryActionButton.onClick}/>}
12
- {hasPrimaryAction && <Button className="doubao-template-action-bar__action" type="primary" disabled={primaryActionButton.disabled} loading={primaryActionButton.loading} throttle={primaryActionButton.throttle} text={primaryActionButton.text} onClick={primaryActionButton.onClick}/>}
18
+ {hasSecondaryAction && <Button className="doubao-template-action-bar__action" type="default" disabled={secondaryActionButton.disabled} loading={secondaryActionButton.loading} throttle={secondaryActionButton.throttle} text={secondaryActionButton.text} onClick={handleSecondaryActionClick}/>}
19
+ {hasPrimaryAction && <Button className="doubao-template-action-bar__action" type="primary" disabled={primaryActionButton.disabled} loading={primaryActionButton.loading} throttle={primaryActionButton.throttle} text={primaryActionButton.text} onClick={handlePrimaryActionClick}/>}
13
20
  </view>;
14
21
  if (!agreement) return actionBar;
15
22
  return <>
@@ -1,5 +1,6 @@
1
1
  import { clsx } from "clsx";
2
2
  import { getAppInfo } from "../../utils/app-info.js";
3
+ import { useTemplateClickHandler } from "../../utils/report.js";
3
4
  import { TemplateChevronRightIcon } from "../chevron-right-icon/index.js";
4
5
  import "./styles.css";
5
6
  function TemplateCardHeaderIcon({ appIconSrc }) {
@@ -11,6 +12,9 @@ function TemplateCardHeader(props) {
11
12
  const appInfo = getAppInfo();
12
13
  const hasStatus = 'default' === variant && null != statusText && statusText.length > 0;
13
14
  const hasAction = !hasStatus && showAction && null != actionText && actionText.length > 0;
15
+ const handleActionClick = useTemplateClickHandler('header_action', onActionClick, {
16
+ clickText: actionText
17
+ });
14
18
  return <view className={clsx('doubao-template-title-bar', 'floating' === variant && 'doubao-template-title-bar--floating')}>
15
19
  <view className="doubao-template-title-bar__app">
16
20
  <TemplateCardHeaderIcon appIconSrc={iconSrc ?? appInfo.appIconSrc}/>
@@ -23,7 +27,7 @@ function TemplateCardHeader(props) {
23
27
  {statusText}
24
28
  </text>
25
29
  </view>}
26
- {hasAction && <view className="doubao-template-title-bar__more" catchtap={onActionClick}>
30
+ {hasAction && <view className="doubao-template-title-bar__more" catchtap={handleActionClick}>
27
31
  <text className="doubao-template-title-bar__more-text" text-maxline="1">
28
32
  {actionText}
29
33
  </text>
@@ -1,4 +1,5 @@
1
1
  import { Title } from "../../primitives/title/index.js";
2
+ import { useTemplateClickHandler } from "../../utils/report.js";
2
3
  import "./styles.css";
3
4
  function isTemplateProductSummaryTextEmpty(content) {
4
5
  return null == content || '' === content;
@@ -23,8 +24,9 @@ function TemplateProductSummary(props) {
23
24
  const hasSpec = null != spec && spec.length > 0;
24
25
  const hasQuantity = !isTemplateProductSummaryTextEmpty(quantity);
25
26
  const hasSecondaryLine = hasSpec || hasQuantity;
27
+ const handleClick = useTemplateClickHandler('product', onClick);
26
28
  if (!hasImage && !hasMainLine && !hasSecondaryLine) return null;
27
- return <view className="doubao-template-product-summary" catchtap={onClick}>
29
+ return <view className="doubao-template-product-summary" catchtap={handleClick}>
28
30
  {hasImage && <TemplateProductSummaryImage image={image1} imageSrc={imageSrc}/>}
29
31
  <view className={hasImage ? 'doubao-template-product-summary__content doubao-template-product-summary__content--with-image' : 'doubao-template-product-summary__content'}>
30
32
  {hasMainLine && <view className="doubao-template-product-summary__line-main">
@@ -1,5 +1,6 @@
1
1
  import { useTheme } from "@byted-doubao-apps/components";
2
2
  import { clsx } from "clsx";
3
+ import { useTemplateClickHandler } from "../../utils/report.js";
3
4
  import { TemplateChevronRightIcon } from "../chevron-right-icon/index.js";
4
5
  import "./styles.css";
5
6
  function getTransportSummaryArrowSvgContent(showDot, isDark) {
@@ -111,6 +112,10 @@ function renderTemplateTransportSummaryTransfer({ content, topText, showDot, bot
111
112
  function TemplateTransportSummary(props) {
112
113
  const theme = useTheme();
113
114
  const { title, departureMain, departureSub, transfer, transferTop, showTransferDot, transferBottom, arrivalMain, arrivalDayOffset, arrivalSub, price, priceActionText, priceActionTone = 'highlight', showPriceActionIcon = true, priceExtraLoading = false, tag, tagTone = 'marketing', className, onRouteClick, onPriceClick } = props;
115
+ const handleRouteClick = useTemplateClickHandler('route', onRouteClick);
116
+ const handlePriceClick = useTemplateClickHandler('price', onPriceClick, {
117
+ clickText: priceActionText
118
+ });
114
119
  const departureNode = renderTemplateTransportSummaryPoint({
115
120
  mainText: departureMain,
116
121
  subText: departureSub
@@ -132,7 +137,7 @@ function TemplateTransportSummary(props) {
132
137
  {arrivalDayOffsetNode}
133
138
  </view>;
134
139
  const titleNode = renderTemplateTransportSummaryNodeField(title, 'doubao-template-transport-summary__title', 'doubao-template-transport-summary__title-text');
135
- const priceNode = renderTemplateTransportSummaryPrice(price, tag, priceActionText, priceActionTone, showPriceActionIcon, priceExtraLoading, tagTone, 'dark' === theme, onPriceClick);
140
+ const priceNode = renderTemplateTransportSummaryPrice(price, tag, priceActionText, priceActionTone, showPriceActionIcon, priceExtraLoading, tagTone, 'dark' === theme, handlePriceClick);
136
141
  const hasRoute = Boolean(departureNode || transferNode || arrivalNode);
137
142
  const hasRouteRow = hasRoute || null != priceNode;
138
143
  const hasRouteHitArea = null != onRouteClick && (null != titleNode || hasRoute);
@@ -143,10 +148,10 @@ function TemplateTransportSummary(props) {
143
148
  {departureNode}
144
149
  {transferNode}
145
150
  {arrivalNode}
146
- {hasRouteHitArea ? <view className="doubao-template-transport-summary__route-hit-area" catchtap={onRouteClick}/> : null}
151
+ {hasRouteHitArea ? <view className="doubao-template-transport-summary__route-hit-area" catchtap={handleRouteClick}/> : null}
147
152
  {priceNode}
148
153
  </view>}
149
- {hasRouteHitArea ? <view className="doubao-template-transport-summary__route-hit-area" catchtap={onRouteClick}/> : null}
154
+ {hasRouteHitArea ? <view className="doubao-template-transport-summary__route-hit-area" catchtap={handleRouteClick}/> : null}
150
155
  </view>;
151
156
  }
152
157
  export { TemplateTransportSummary };
@@ -4,6 +4,7 @@ import { TemplateCardHeader } from "../components/header/index.js";
4
4
  import { ContentCardContent } from "../content-card/index.js";
5
5
  import { OptionGroup } from "../primitives/option-group/index.js";
6
6
  import { TransitCardContent } from "../transit-card/content.js";
7
+ import { TemplateTelemetryProvider } from "../utils/report.js";
7
8
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
8
9
  import "./styles.css";
9
10
  function isCompositeCardSectionVisible(section) {
@@ -36,23 +37,33 @@ function renderCompositeCardSectionContent(section) {
36
37
  return null;
37
38
  }
38
39
  }
39
- function renderCompositeCardSection(section, index) {
40
+ function CompositeCardSectionView({ section, index }) {
40
41
  if (!isCompositeCardSectionVisible(section)) return null;
41
- return <view className="doubao-composite-card__section" key={index}>
42
- {renderCompositeCardSectionContent(section)}
43
- </view>;
42
+ return <TemplateTelemetryProvider value={{
43
+ sectionType: section.type,
44
+ sectionIndex: index
45
+ }}>
46
+ <view className="doubao-composite-card__section">{renderCompositeCardSectionContent(section)}</view>
47
+ </TemplateTelemetryProvider>;
44
48
  }
45
49
  function CompositeCard(props) {
46
50
  const { header, sections, footer, onClick } = props;
47
51
  const cardStyle = useHostCardStyle();
48
- const visibleSections = sections.filter(isCompositeCardSectionVisible);
52
+ const visibleSections = sections.map((section, index)=>({
53
+ section,
54
+ index
55
+ })).filter(({ section })=>isCompositeCardSectionVisible(section));
49
56
  const floatingHeader = header?.placement === 'floating';
50
- return <view className={useThemeClassName('doubao-composite-card')} style={cardStyle} bindtap={onClick}>
51
- <TemplateCardHeader variant={floatingHeader ? 'floating' : 'default'} title={floatingHeader ? header?.title : void 0} iconSrc={floatingHeader ? header?.iconSrc : void 0} actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
52
- {visibleSections.length > 0 && <view className="doubao-composite-card__sections">
53
- {visibleSections.map(renderCompositeCardSection)}
54
- </view>}
55
- <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
56
- </view>;
57
+ return <TemplateTelemetryProvider value={{
58
+ templateName: 'CompositeCard'
59
+ }}>
60
+ <view className={useThemeClassName('doubao-composite-card')} style={cardStyle} bindtap={onClick}>
61
+ <TemplateCardHeader variant={floatingHeader ? 'floating' : 'default'} title={floatingHeader ? header?.title : void 0} iconSrc={floatingHeader ? header?.iconSrc : void 0} actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
62
+ {visibleSections.length > 0 && <view className="doubao-composite-card__sections">
63
+ {visibleSections.map(({ section, index })=><CompositeCardSectionView key={index} section={section} index={index}/>)}
64
+ </view>}
65
+ <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
66
+ </view>
67
+ </TemplateTelemetryProvider>;
57
68
  }
58
69
  export { CompositeCard };
@@ -3,6 +3,7 @@ import { clsx } from "clsx";
3
3
  import { renderTemplateExtraAction, stopTemplateExtraActionTap } from "../components/extra-action/index.js";
4
4
  import { TemplateCardFooter } from "../components/footer/index.js";
5
5
  import { TemplateCardHeader } from "../components/header/index.js";
6
+ import { TemplateTelemetryProvider, useTemplateClickHandler } from "../utils/report.js";
6
7
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
7
8
  import "./styles.css";
8
9
  function isContentCardNodeEmpty(content) {
@@ -34,14 +35,26 @@ function renderContentCardAction(action) {
34
35
  playbackIcon: 'doubao-content-card__item-action-playback-icon'
35
36
  });
36
37
  }
37
- function ContentCardItemView({ item, isLast }) {
38
+ function ContentCardItemView({ item, index, isLast }) {
38
39
  const { title, subtitle, description } = item;
39
40
  const hasThumbnail = !isContentCardNodeEmpty(item.thumbnail) || null != item.thumbnailSrc && item.thumbnailSrc.length > 0;
40
41
  const subtitleNode = renderContentCardText(subtitle, 'doubao-content-card__subtitle');
41
42
  const descriptionNode = renderContentCardText(description, "doubao-content-card__description");
42
- const actionNode = renderContentCardAction(item.action);
43
- return <view className={clsx('doubao-content-card__item', !hasThumbnail && 'doubao-content-card__item--without-thumbnail')} {...null != item.onClick ? {
44
- catchtap: item.onClick
43
+ const handleItemClick = useTemplateClickHandler('item', item.onClick, {
44
+ itemIndex: index
45
+ });
46
+ const actionButton = item.action?.type === 'button' ? item.action : void 0;
47
+ const handleItemActionClick = useTemplateClickHandler('item_action', actionButton?.onClick, {
48
+ clickText: actionButton?.text,
49
+ itemIndex: index
50
+ });
51
+ const action = null != actionButton ? {
52
+ ...actionButton,
53
+ onClick: handleItemActionClick
54
+ } : item.action;
55
+ const actionNode = renderContentCardAction(action);
56
+ return <view className={clsx('doubao-content-card__item', !hasThumbnail && 'doubao-content-card__item--without-thumbnail')} {...null != handleItemClick ? {
57
+ catchtap: handleItemClick
45
58
  } : {}}>
46
59
  <view className="doubao-content-card__content">
47
60
  <view className="doubao-content-card__main">
@@ -62,16 +75,20 @@ function ContentCardItemView({ item, isLast }) {
62
75
  function ContentCardContent({ items }) {
63
76
  const contentItems = items ?? [];
64
77
  return <view className="doubao-content-card__body">
65
- {contentItems.map((item, index)=><ContentCardItemView key={item.key ?? index} item={item} isLast={index === contentItems.length - 1}/>)}
78
+ {contentItems.map((item, index)=><ContentCardItemView key={item.key ?? index} item={item} index={index} isLast={index === contentItems.length - 1}/>)}
66
79
  </view>;
67
80
  }
68
81
  function ContentCard(props) {
69
82
  const { header, items, footer, onClick } = props;
70
83
  const cardStyle = useHostCardStyle();
71
- return <view className={useThemeClassName('doubao-content-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
72
- <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
73
- <ContentCardContent items={items}/>
74
- <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
75
- </view>;
84
+ return <TemplateTelemetryProvider value={{
85
+ templateName: 'ContentCard'
86
+ }}>
87
+ <view className={useThemeClassName('doubao-content-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
88
+ <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
89
+ <ContentCardContent items={items}/>
90
+ <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
91
+ </view>
92
+ </TemplateTelemetryProvider>;
76
93
  }
77
94
  export { ContentCard, ContentCardContent };
@@ -1,6 +1,7 @@
1
1
  import { Button, ScrollView, useThemeClassName } from "@byted-doubao-apps/components";
2
2
  import { clsx } from "clsx";
3
3
  import { useState } from "react";
4
+ import { TemplateTelemetryProvider, useTemplateClickHandler } from "../utils/report.js";
4
5
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
5
6
  import divider from "./assets/divider.js";
6
7
  import title_separator from "./assets/title-separator.js";
@@ -21,15 +22,22 @@ function CouponValue({ item }) {
21
22
  </text> : null}
22
23
  </view>;
23
24
  }
24
- function CouponItem({ item, layout }) {
25
+ function CouponItem({ item, index, layout }) {
25
26
  const [pressed, setPressed] = useState(false);
26
27
  const { sourceName, title, validityText, actionText = '立即用', disabled = false } = item;
27
28
  const single = 'single' === layout;
28
29
  const hasInfo = Boolean(sourceName || title || validityText);
29
30
  const handleTouchEnd = ()=>setPressed(false);
31
+ const handleItemClick = useTemplateClickHandler('item', item.onClick, {
32
+ itemIndex: index
33
+ });
34
+ const handleActionClick = useTemplateClickHandler('item_action', item.onActionClick, {
35
+ clickText: actionText,
36
+ itemIndex: index
37
+ });
30
38
  const handleTap = (event)=>{
31
39
  setPressed(false);
32
- if (!disabled) item.onClick?.(event);
40
+ if (!disabled) handleItemClick?.(event);
33
41
  };
34
42
  return <view className={clsx('doubao-coupon-card__item', {
35
43
  'doubao-coupon-card__item--disabled': disabled,
@@ -68,7 +76,7 @@ function CouponItem({ item, layout }) {
68
76
  {sourceName}
69
77
  </text> : null}
70
78
  </view>}
71
- {actionText ? <Button className="doubao-coupon-card__action" type="plain" size="mini" text={actionText} disabled={disabled} loading={item.loading} showDisabledStyle={false} onClick={item.onActionClick}/> : null}
79
+ {actionText ? <Button className="doubao-coupon-card__action" type="plain" size="mini" text={actionText} disabled={disabled} loading={item.loading} showDisabledStyle={false} onClick={handleActionClick}/> : null}
72
80
  </view>;
73
81
  }
74
82
  function CouponCard({ items = [], onClick }) {
@@ -76,15 +84,19 @@ function CouponCard({ items = [], onClick }) {
76
84
  const cardStyle = useHostCardStyle();
77
85
  const layout = 1 === items.length ? 'single' : 2 === items.length ? 'double' : 'multiple';
78
86
  if (0 === items.length) return null;
79
- const coupons = items.map((item, index)=><CouponItem key={item.key ?? index} item={item} layout={layout}/>);
80
- return <view className={clsx('doubao-coupon-card', `doubao-coupon-card--${layout}`, themeClassName)} style={cardStyle} bindtap={onClick}>
81
- {'multiple' === layout ? <ScrollView className="doubao-coupon-card__scroll" scrollOrientation="horizontal" scrollBarEnable={false}>
82
- <view className="doubao-coupon-card__items" style={{
87
+ const coupons = items.map((item, index)=><CouponItem key={item.key ?? index} item={item} index={index} layout={layout}/>);
88
+ return <TemplateTelemetryProvider value={{
89
+ templateName: 'CouponCard'
90
+ }}>
91
+ <view className={clsx('doubao-coupon-card', `doubao-coupon-card--${layout}`, themeClassName)} style={cardStyle} bindtap={onClick}>
92
+ {'multiple' === layout ? <ScrollView className="doubao-coupon-card__scroll" scrollOrientation="horizontal" scrollBarEnable={false}>
93
+ <view className="doubao-coupon-card__items" style={{
83
94
  minWidth: `${96 * items.length + (items.length - 1) * 4}px`
84
95
  }}>
85
- {coupons}
86
- </view>
87
- </ScrollView> : <view className="doubao-coupon-card__items">{coupons}</view>}
88
- </view>;
96
+ {coupons}
97
+ </view>
98
+ </ScrollView> : <view className="doubao-coupon-card__items">{coupons}</view>}
99
+ </view>
100
+ </TemplateTelemetryProvider>;
89
101
  }
90
102
  export { CouponCard };
@@ -3,6 +3,7 @@ import { clsx } from "clsx";
3
3
  import { forwardRef } from "react";
4
4
  import { TemplateCardFooter } from "../components/footer/index.js";
5
5
  import { Title } from "../primitives/title/index.js";
6
+ import { TemplateTelemetryProvider, useReportTemplateClick } from "../utils/report.js";
6
7
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
7
8
  import "./styles.css";
8
9
  function hasTemplateText(value) {
@@ -11,35 +12,51 @@ function hasTemplateText(value) {
11
12
  function MapCardImpl(props, ref) {
12
13
  const { mapProps, title, showArrow = true, metaItems = [], inlineActions = [], footer, onClick } = props;
13
14
  const cardStyle = useHostCardStyle();
15
+ const reportTemplateClick = useReportTemplateClick({
16
+ templateName: 'MapCard'
17
+ });
14
18
  const visibleMetaItems = metaItems.filter((item)=>hasTemplateText(item.text)).slice(0, 2);
15
- const visibleInlineActions = inlineActions.filter((action)=>null != action.text && action.text.length > 0).slice(0, 2);
19
+ const visibleInlineActions = inlineActions.map((action, index)=>({
20
+ action,
21
+ index
22
+ })).filter(({ action })=>null != action.text && action.text.length > 0).slice(0, 2);
16
23
  const hasTitle = hasTemplateText(title);
17
24
  const hasContent = hasTitle || visibleMetaItems.length > 0 || visibleInlineActions.length > 0;
18
- return <view className={useThemeClassName('doubao-map-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
19
- <view className="doubao-map-card__viewport">
20
- <Map {...mapProps} ref={ref} className="doubao-map-card__map"/>
21
- </view>
25
+ return <TemplateTelemetryProvider value={{
26
+ templateName: 'MapCard'
27
+ }}>
28
+ <view className={useThemeClassName('doubao-map-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
29
+ <view className="doubao-map-card__viewport">
30
+ <Map {...mapProps} ref={ref} className="doubao-map-card__map"/>
31
+ </view>
22
32
 
23
- {hasContent ? <view className="doubao-map-card__content">
24
- <view className="doubao-map-card__text-content">
25
- {hasTitle ? <Title text={title} showArrow={showArrow}/> : null}
26
- {visibleMetaItems.length > 0 ? <view className="doubao-map-card__meta">
27
- {visibleMetaItems.map((item, index)=><view className="doubao-map-card__meta-entry" key={item.key ?? index}>
28
- {index > 0 ? <text className="doubao-map-card__meta-separator">·</text> : null}
29
- <text className={clsx('doubao-map-card__meta-text', 'highlight' === item.tone && 'doubao-map-card__meta-text--highlight')} text-maxline="1">
30
- {item.text}
31
- </text>
32
- </view>)}
33
- </view> : null}
34
- </view>
33
+ {hasContent ? <view className="doubao-map-card__content">
34
+ <view className="doubao-map-card__text-content">
35
+ {hasTitle ? <Title text={title} showArrow={showArrow}/> : null}
36
+ {visibleMetaItems.length > 0 ? <view className="doubao-map-card__meta">
37
+ {visibleMetaItems.map((item, index)=><view className="doubao-map-card__meta-entry" key={item.key ?? index}>
38
+ {index > 0 ? <text className="doubao-map-card__meta-separator">·</text> : null}
39
+ <text className={clsx('doubao-map-card__meta-text', 'highlight' === item.tone && 'doubao-map-card__meta-text--highlight')} text-maxline="1">
40
+ {item.text}
41
+ </text>
42
+ </view>)}
43
+ </view> : null}
44
+ </view>
35
45
 
36
- {visibleInlineActions.length > 0 ? <view className="doubao-map-card__inline-actions">
37
- {visibleInlineActions.map((action, index)=><Button className="doubao-map-card__inline-action" key={index} size="mini" type={visibleInlineActions.length > 1 && 0 === index ? 'default' : 'primary'} text={action.text ?? ''} disabled={action.disabled} loading={action.loading} throttle={action.throttle} onClick={action.onClick}/>)}
38
- </view> : null}
39
- </view> : null}
46
+ {visibleInlineActions.length > 0 ? <view className="doubao-map-card__inline-actions">
47
+ {visibleInlineActions.map(({ action, index })=><Button className="doubao-map-card__inline-action" key={index} size="mini" type={visibleInlineActions.length > 1 && 0 === index ? 'default' : 'primary'} text={action.text ?? ''} disabled={action.disabled} loading={action.loading} throttle={action.throttle} onClick={null == action.onClick ? void 0 : (event)=>{
48
+ reportTemplateClick('inline_action', {
49
+ clickText: action.text,
50
+ actionIndex: index
51
+ });
52
+ action.onClick?.(event);
53
+ }}/>)}
54
+ </view> : null}
55
+ </view> : null}
40
56
 
41
- <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
42
- </view>;
57
+ <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
58
+ </view>
59
+ </TemplateTelemetryProvider>;
43
60
  }
44
61
  const MapCard = forwardRef(MapCardImpl);
45
62
  export { MapCard };
@@ -4,6 +4,7 @@ import { TemplateCardFooter } from "../components/footer/index.js";
4
4
  import { TemplateCardHeader } from "../components/header/index.js";
5
5
  import { Checkbox } from "../primitives/checkbox/index.js";
6
6
  import { Price } from "../primitives/price/index.js";
7
+ import { TemplateTelemetryProvider, useTemplateClickHandler } from "../utils/report.js";
7
8
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
8
9
  import "./styles.css";
9
10
  const PRICE_ACTION_CARD_INFO_ROW_LIMIT = 2;
@@ -16,13 +17,20 @@ function PriceActionCardPrice({ price }) {
16
17
  const [, currency, value] = priceText.match(PRICE_ACTION_CARD_CURRENCY_PATTERN) ?? [];
17
18
  return <Price currency={currency ?? ''} value={value ?? priceText} tone="highlight"/>;
18
19
  }
19
- function PriceActionCardItemView({ item, isLast }) {
20
+ function PriceActionCardItemView({ item, index, isLast }) {
20
21
  const hasPrice = !isPriceActionCardTextEmpty(item.price);
21
22
  const hasBadge = !isPriceActionCardTextEmpty(item.badgeText);
22
23
  const hasAction = null != item.actionText && item.actionText.length > 0;
23
24
  const infoRows = (item.infoRows ?? []).filter((infoRow)=>!isPriceActionCardTextEmpty(infoRow.text)).slice(0, PRICE_ACTION_CARD_INFO_ROW_LIMIT);
24
- return <view className={clsx('doubao-price-action-card__item', null != item.checkbox && 'doubao-price-action-card__item--checkbox')} {...null != item.onClick ? {
25
- catchtap: item.onClick
25
+ const handleItemClick = useTemplateClickHandler('item', item.onClick, {
26
+ itemIndex: index
27
+ });
28
+ const handleActionClick = useTemplateClickHandler('item_action', item.onActionClick, {
29
+ clickText: item.actionText,
30
+ itemIndex: index
31
+ });
32
+ return <view className={clsx('doubao-price-action-card__item', null != item.checkbox && 'doubao-price-action-card__item--checkbox')} {...null != handleItemClick ? {
33
+ catchtap: handleItemClick
26
34
  } : {}}>
27
35
  <view className="doubao-price-action-card__item-content">
28
36
  <view className="doubao-price-action-card__value">
@@ -36,7 +44,7 @@ function PriceActionCardItemView({ item, isLast }) {
36
44
  {infoRow.text}
37
45
  </text>)}
38
46
  </view>
39
- {null != item.checkbox ? <Checkbox {...item.checkbox}/> : hasAction ? <Button className="doubao-price-action-card__item-action" type="default" text={item.actionText} onClick={item.onActionClick}/> : null}
47
+ {null != item.checkbox ? <Checkbox {...item.checkbox}/> : hasAction ? <Button className="doubao-price-action-card__item-action" type="default" text={item.actionText} onClick={handleActionClick}/> : null}
40
48
  </view>
41
49
  {!isLast && <view className="doubao-price-action-card__divider"/>}
42
50
  </view>;
@@ -44,14 +52,18 @@ function PriceActionCardItemView({ item, isLast }) {
44
52
  function PriceActionCard(props) {
45
53
  const { header, items = [], footer, onClick } = props;
46
54
  const cardStyle = useHostCardStyle();
47
- return <view className={useThemeClassName('doubao-price-action-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
48
- <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
49
- <view className="doubao-price-action-card__body">
50
- <view className="doubao-price-action-card__default">
51
- {items.map((item, index)=><PriceActionCardItemView item={item} isLast={index === items.length - 1} key={item.key ?? index}/>)}
55
+ return <TemplateTelemetryProvider value={{
56
+ templateName: 'PriceActionCard'
57
+ }}>
58
+ <view className={useThemeClassName('doubao-price-action-card')} style={cardStyle} bindtap={onClick} clip-radius="true">
59
+ <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
60
+ <view className="doubao-price-action-card__body">
61
+ <view className="doubao-price-action-card__default">
62
+ {items.map((item, index)=><PriceActionCardItemView item={item} index={index} isLast={index === items.length - 1} key={item.key ?? index}/>)}
63
+ </view>
52
64
  </view>
65
+ <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
53
66
  </view>
54
- <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
55
- </view>;
67
+ </TemplateTelemetryProvider>;
56
68
  }
57
69
  export { PriceActionCard };
@@ -1,14 +1,27 @@
1
1
  import { useThemeClassName } from "@byted-doubao-apps/components";
2
+ import { useReportTemplateClick } from "../../utils/report.js";
2
3
  import "./styles.css";
3
4
  function Agreement({ text: text1 = '点击下单代表同意', links }) {
4
5
  const className = useThemeClassName('doubao-agreement');
5
- const visibleLinks = links.filter((link)=>'' !== link.text);
6
+ const reportClick = useReportTemplateClick({
7
+ componentName: 'Agreement'
8
+ });
9
+ const visibleLinks = links.map((link, index)=>({
10
+ ...link,
11
+ index
12
+ })).filter((link)=>'' !== link.text);
6
13
  if (0 === visibleLinks.length) return null;
7
14
  return <view className={className} catchtap={()=>{}}>
8
15
  <text className="doubao-agreement__text" text-maxline="2">
9
16
  {text1}
10
17
  {'' !== text1 && ' '}
11
- {visibleLinks.map((link, index)=><text className="doubao-agreement__link" key={link.key ?? index} bindtap={link.onClick}>
18
+ {visibleLinks.map((link, index)=><text className="doubao-agreement__link" key={link.key ?? index} bindtap={null == link.onClick ? void 0 : (event)=>{
19
+ reportClick('agreement_link', {
20
+ clickText: link.text,
21
+ itemIndex: link.index
22
+ });
23
+ link.onClick?.(event);
24
+ }}>
12
25
  {index > 0 ? '、' : ''}
13
26
  {link.text}
14
27
  </text>)}
@@ -2,6 +2,7 @@ import { clsx } from "clsx";
2
2
  import { TemplateTransportSummary } from "../components/transport-summary/index.js";
3
3
  import { Price } from "../primitives/price/index.js";
4
4
  import { Tag } from "../primitives/tag/index.js";
5
+ import { TemplateTelemetryProvider, useTemplateClickHandler } from "../utils/report.js";
5
6
  import "./styles.css";
6
7
  function isTransitCardPriceConfig(price) {
7
8
  return null != price && 'object' == typeof price && !Array.isArray(price) && 'value' in price;
@@ -23,21 +24,24 @@ function renderTransitCardTag(tag) {
23
24
  if (null == tag || '' === tag.text) return null;
24
25
  return <Tag text={tag.text} tone={tag.tone ?? 'marketing'}/>;
25
26
  }
26
- function renderTransitCardItem({ item, index, isLast }) {
27
- return <view className={clsx('doubao-transit-card__item', isLast && 'doubao-transit-card__item--last')} key={item.key ?? index} {...null != item.onClick ? {
28
- catchtap: item.onClick
27
+ function TransitCardItemView({ item, index, isLast }) {
28
+ const handleItemClick = useTemplateClickHandler('item', item.onClick, {
29
+ itemIndex: index
30
+ });
31
+ return <TemplateTelemetryProvider value={{
32
+ itemIndex: index
33
+ }}>
34
+ <view className={clsx('doubao-transit-card__item', isLast && 'doubao-transit-card__item--last')} {...null != handleItemClick ? {
35
+ catchtap: handleItemClick
29
36
  } : {}}>
30
- <TemplateTransportSummary className="doubao-template-transport-summary--list" title={item.title} departureMain={item.departureMain} departureSub={item.departureSub} transferTop={item.transferTop} transferBottom={item.transferBottom} arrivalMain={item.arrivalMain} arrivalDayOffset={item.arrivalDayOffset} arrivalSub={item.arrivalSub} price={renderTransitCardPrice(item.price)} priceActionText={item.priceAction?.text} priceActionTone={item.priceAction?.tone} showPriceActionIcon={item.priceAction?.showIcon} priceExtraLoading={item.priceExtraLoading} tag={renderTransitCardTag(item.tag)} tagTone={item.tag?.tone} onRouteClick={item.onRouteClick} onPriceClick={item.onPriceClick}/>
31
- {!isLast && <view className="doubao-transit-card__item--spread"/>}
32
- </view>;
37
+ <TemplateTransportSummary className="doubao-template-transport-summary--list" title={item.title} departureMain={item.departureMain} departureSub={item.departureSub} transferTop={item.transferTop} transferBottom={item.transferBottom} arrivalMain={item.arrivalMain} arrivalDayOffset={item.arrivalDayOffset} arrivalSub={item.arrivalSub} price={renderTransitCardPrice(item.price)} priceActionText={item.priceAction?.text} priceActionTone={item.priceAction?.tone} showPriceActionIcon={item.priceAction?.showIcon} priceExtraLoading={item.priceExtraLoading} tag={renderTransitCardTag(item.tag)} tagTone={item.tag?.tone} onRouteClick={item.onRouteClick} onPriceClick={item.onPriceClick}/>
38
+ {!isLast && <view className="doubao-transit-card__item--spread"/>}
39
+ </view>
40
+ </TemplateTelemetryProvider>;
33
41
  }
34
42
  function TransitCardContent({ items = [] }) {
35
43
  return <view className="doubao-transit-card__body">
36
- {items.map((item, index)=>renderTransitCardItem({
37
- item,
38
- index,
39
- isLast: index === items.length - 1
40
- }))}
44
+ {items.map((item, index)=><TransitCardItemView key={item.key ?? index} item={item} index={index} isLast={index === items.length - 1}/>)}
41
45
  </view>;
42
46
  }
43
47
  export { TransitCardContent };
@@ -1,15 +1,20 @@
1
1
  import { useThemeClassName } from "@byted-doubao-apps/components";
2
2
  import { TemplateCardFooter } from "../components/footer/index.js";
3
3
  import { TemplateCardHeader } from "../components/header/index.js";
4
+ import { TemplateTelemetryProvider } from "../utils/report.js";
4
5
  import { useHostCardStyle } from "../utils/use-host-card-style.js";
5
6
  import { TransitCardContent } from "./content.js";
6
7
  function TransitCard(props) {
7
8
  const { header, items = [], footer, onClick } = props;
8
9
  const cardStyle = useHostCardStyle();
9
- return <view className={useThemeClassName('doubao-transit-card')} style={cardStyle} bindtap={onClick}>
10
- <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
11
- <TransitCardContent items={items}/>
12
- <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
13
- </view>;
10
+ return <TemplateTelemetryProvider value={{
11
+ templateName: 'TransitCard'
12
+ }}>
13
+ <view className={useThemeClassName('doubao-transit-card')} style={cardStyle} bindtap={onClick}>
14
+ <TemplateCardHeader actionText={header?.actionText} statusText={header?.statusText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
15
+ <TransitCardContent items={items}/>
16
+ <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton} agreement={footer?.agreement}/>
17
+ </view>
18
+ </TemplateTelemetryProvider>;
14
19
  }
15
20
  export { TransitCard };
@@ -0,0 +1,21 @@
1
+ import type { TouchEvent } from '@lynx-js/types';
2
+ import { type ReactNode } from 'react';
3
+ interface TemplateTelemetryContextValue {
4
+ componentName?: string;
5
+ templateName?: string;
6
+ itemIndex?: number;
7
+ actionIndex?: number;
8
+ sectionType?: string;
9
+ sectionIndex?: number;
10
+ }
11
+ interface TemplateClickOptions extends TemplateTelemetryContextValue {
12
+ clickText?: string | number;
13
+ }
14
+ export declare function TemplateTelemetryProvider({ value, children }: {
15
+ value: TemplateTelemetryContextValue;
16
+ children: ReactNode;
17
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<TemplateTelemetryContextValue>>;
18
+ export declare function useReportTemplateClick(contextValue?: TemplateTelemetryContextValue): (clickArea: string, options?: TemplateClickOptions) => void;
19
+ export declare function useTemplateClickHandler<T extends (event: TouchEvent) => void>(clickArea: string, handler?: T, options?: TemplateClickOptions): ((event: TouchEvent) => void) | undefined;
20
+ export {};
21
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ import{reportEvent as e}from"@byted-doubao-apps/framework/api";import{createContext as n,createElement as t,useContext as l}from"react";let i=n({});function c({value:e,children:n}){let o={...l(i),...e};return t(i.Provider,{value:o},n)}function o(n={}){let t={...l(i),...n};return(n,l={})=>{let i={click_area:n};null!=t.componentName&&(i.component_name=t.componentName),null!=t.templateName&&(i.template_name=t.templateName),null!=t.itemIndex&&(i.item_index=t.itemIndex),null!=t.actionIndex&&(i.action_index=t.actionIndex),null!=t.sectionType&&(i.section_type=t.sectionType),null!=t.sectionIndex&&(i.section_index=t.sectionIndex),null!=l.componentName&&(i.component_name=l.componentName),null!=l.templateName&&(i.template_name=l.templateName),null!=l.itemIndex&&(i.item_index=l.itemIndex),null!=l.actionIndex&&(i.action_index=l.actionIndex),null!=l.sectionType&&(i.section_type=l.sectionType),null!=l.sectionIndex&&(i.section_index=l.sectionIndex),null!=l.clickText&&""!==l.clickText&&(i.click_text=String(l.clickText));try{e({eventName:"doubao_apps_template_click",data:i}).catch(()=>{})}catch{}}}function a(e,n,t={}){let l=o();if(null!=n)return i=>{l(e,t),n(i)}}export{c as TemplateTelemetryProvider,o as useReportTemplateClick,a as useTemplateClickHandler};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-dev/template",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {