@procore/ai-translations 0.6.0 → 0.6.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.internal.md +257 -0
- package/README.md +158 -1
- package/dist/legacy/index.d.mts +103 -1
- package/dist/legacy/index.d.ts +103 -1
- package/dist/legacy/index.js +164 -14
- package/dist/legacy/index.mjs +153 -9
- package/dist/modern/index.d.mts +103 -1
- package/dist/modern/index.d.ts +103 -1
- package/dist/modern/index.js +164 -14
- package/dist/modern/index.mjs +153 -9
- package/package.json +1 -1
package/dist/modern/index.d.ts
CHANGED
|
@@ -2,6 +2,35 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
+
/** Shape of an analytic event passed to the MFE's `onTrackAnalyticsEvent` callback. */
|
|
6
|
+
interface AnalyticEvent {
|
|
7
|
+
key: string;
|
|
8
|
+
properties: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/** Function provided by the MFE that sends the event to the analytics destination. */
|
|
11
|
+
type AIAnalyticsTracker = (event: AnalyticEvent) => void;
|
|
12
|
+
/** Feature scope: `'project'` for project-level tools, `'company'` for company-level tools. */
|
|
13
|
+
type Scope = 'project' | 'company';
|
|
14
|
+
/**
|
|
15
|
+
* Parts needed to build an event key following the pattern:
|
|
16
|
+
* `ux.web.feature.{scope}.{tool}.{object}.{action}`
|
|
17
|
+
*/
|
|
18
|
+
interface EventKeyParts {
|
|
19
|
+
scope: Scope;
|
|
20
|
+
tool: string;
|
|
21
|
+
object: string;
|
|
22
|
+
action: string;
|
|
23
|
+
}
|
|
24
|
+
/** Standard properties included in every AI analytics event. */
|
|
25
|
+
interface AIAnalyticsEventProperties {
|
|
26
|
+
user_locale: string;
|
|
27
|
+
project_locale?: string;
|
|
28
|
+
company_locale?: string;
|
|
29
|
+
tool: string;
|
|
30
|
+
page: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
5
34
|
interface TranslationProgress {
|
|
6
35
|
/**
|
|
7
36
|
* Progress percentage (0-100)
|
|
@@ -39,12 +68,22 @@ interface ModelDownloadProgress {
|
|
|
39
68
|
interface AITranslationContextValue {
|
|
40
69
|
ait: (text: string) => Promise<string>;
|
|
41
70
|
locale: string;
|
|
71
|
+
/** Company-level locale from environment metadata (e.g. `"de-DE"`). */
|
|
72
|
+
companyLocale?: string;
|
|
73
|
+
/** Project-level locale from environment metadata (e.g. `"fr-CA"`). */
|
|
74
|
+
projectLocale?: string;
|
|
42
75
|
renderVersion?: number;
|
|
43
76
|
/** Batch-translation progress; `null` while the queue is idle. */
|
|
44
77
|
translationProgress: TranslationProgress | null;
|
|
45
78
|
/** Chrome AI model download progress; `null` until a download begins. */
|
|
46
79
|
modelDownloadProgress: ModelDownloadProgress | null;
|
|
47
80
|
tool: string;
|
|
81
|
+
/** Called by `useAIAnalytics` with a fully assembled event. The MFE is responsible for sending it. */
|
|
82
|
+
onTrackAnalyticsEvent?: AIAnalyticsTracker;
|
|
83
|
+
/** Page context used to build the event key object segment (e.g. `'view'`, `'list_column_description'`). */
|
|
84
|
+
page?: string;
|
|
85
|
+
/** Feature scope: `'project'` or `'company'`. */
|
|
86
|
+
scope?: Scope;
|
|
48
87
|
}
|
|
49
88
|
|
|
50
89
|
interface ConfigurationResponse {
|
|
@@ -117,6 +156,59 @@ declare function useConfig(toolName: string, options?: UseConfigOptions): _tanst
|
|
|
117
156
|
*/
|
|
118
157
|
declare function useAITranslation(): AITranslationContextValue;
|
|
119
158
|
|
|
159
|
+
/** Button type identifiers for the event key `object` segment. */
|
|
160
|
+
declare const BUTTON_TYPE: {
|
|
161
|
+
readonly TRANSLATE: "translate";
|
|
162
|
+
readonly HIGHLIGHT: "highlight";
|
|
163
|
+
};
|
|
164
|
+
type ButtonType = (typeof BUTTON_TYPE)[keyof typeof BUTTON_TYPE];
|
|
165
|
+
/** Action identifiers for the event key `action` segment. */
|
|
166
|
+
declare const ACTION: {
|
|
167
|
+
readonly CLICKED: "clicked";
|
|
168
|
+
};
|
|
169
|
+
type Action = (typeof ACTION)[keyof typeof ACTION];
|
|
170
|
+
/**
|
|
171
|
+
* Builds the `object` segment: `{pageContext}_{buttonType}_button`
|
|
172
|
+
* e.g. `buildObject('view', 'translate')` → `'view_translate_button'`
|
|
173
|
+
*/
|
|
174
|
+
declare function buildObject(pageContext: string, buttonType: ButtonType): string;
|
|
175
|
+
/**
|
|
176
|
+
* Builds a fully-qualified event key:
|
|
177
|
+
* `ux.web.feature.{scope}.{tool}.{object}.{action}`
|
|
178
|
+
*/
|
|
179
|
+
declare function buildEventKey(parts: EventKeyParts): string;
|
|
180
|
+
interface BuildAnalyticEventParams {
|
|
181
|
+
scope: Scope;
|
|
182
|
+
tool: string;
|
|
183
|
+
/** Prefix for the object segment, matches the Provider `page` prop (e.g. `'view'`). */
|
|
184
|
+
pageContext: string;
|
|
185
|
+
buttonType: ButtonType;
|
|
186
|
+
baseProperties: AIAnalyticsEventProperties;
|
|
187
|
+
/** Defaults to `'clicked'` if omitted. */
|
|
188
|
+
action?: Action;
|
|
189
|
+
additionalProperties?: Record<string, unknown>;
|
|
190
|
+
}
|
|
191
|
+
/** Assembles a complete `AnalyticEvent` (key + merged properties) ready for `onTrackAnalyticsEvent`. */
|
|
192
|
+
declare function buildAnalyticEvent(params: BuildAnalyticEventParams): AnalyticEvent;
|
|
193
|
+
|
|
194
|
+
interface UseAIAnalyticsReturn {
|
|
195
|
+
/** Fires `ux.web.feature.{scope}.{tool}.{page}_translate_button.clicked`. */
|
|
196
|
+
trackTranslateButtonClicked: (additionalProperties?: Record<string, unknown>) => void;
|
|
197
|
+
/** Fires `ux.web.feature.{scope}.{tool}.{page}_highlight_button.clicked`. */
|
|
198
|
+
trackHighlightButtonClicked: (additionalProperties?: Record<string, unknown>) => void;
|
|
199
|
+
/** Generic tracking for custom button types or actions. */
|
|
200
|
+
trackCustomEvent: (buttonType: ButtonType | string, action?: Action | string, additionalProperties?: Record<string, unknown>) => void;
|
|
201
|
+
/** `true` when `onTrackAnalyticsEvent` was provided to `AITranslationProvider`. */
|
|
202
|
+
isTrackingEnabled: boolean;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns analytics tracking helpers pre-wired to the Provider context.
|
|
206
|
+
* All functions no-op if `onTrackAnalyticsEvent` was not supplied.
|
|
207
|
+
*
|
|
208
|
+
* @throws if called outside of an `AITranslationProvider`.
|
|
209
|
+
*/
|
|
210
|
+
declare function useAIAnalytics(): UseAIAnalyticsReturn;
|
|
211
|
+
|
|
120
212
|
interface AITranslationProviderProps {
|
|
121
213
|
children: ReactNode;
|
|
122
214
|
locale: string;
|
|
@@ -125,6 +217,16 @@ interface AITranslationProviderProps {
|
|
|
125
217
|
userId: number;
|
|
126
218
|
projectId: number;
|
|
127
219
|
enableAIT?: boolean;
|
|
220
|
+
/** Company-level locale from environment metadata (e.g. `"de-DE"`). Passed through to context for downstream consumers such as Amplitude. */
|
|
221
|
+
companyLocale?: string;
|
|
222
|
+
/** Project-level locale from environment metadata (e.g. `"fr-CA"`). Passed through to context for downstream consumers such as Amplitude. */
|
|
223
|
+
projectLocale?: string;
|
|
224
|
+
/** Called by `useAIAnalytics` with a pre-assembled event. The MFE sends it to the analytics API. */
|
|
225
|
+
onTrackAnalyticsEvent?: AIAnalyticsTracker;
|
|
226
|
+
/** Page context for the event key object segment (e.g. `'view'`, `'list_column_description'`). */
|
|
227
|
+
page?: string;
|
|
228
|
+
/** Feature scope: `'project'` or `'company'`. */
|
|
229
|
+
scope?: Scope;
|
|
128
230
|
}
|
|
129
231
|
declare function AITranslationProvider(props: AITranslationProviderProps): react_jsx_runtime.JSX.Element;
|
|
130
232
|
|
|
@@ -177,4 +279,4 @@ declare global {
|
|
|
177
279
|
var _BACKEND_AI_TRANSLATION_IN_PROGRESS_: boolean;
|
|
178
280
|
}
|
|
179
281
|
|
|
180
|
-
export { AITranslateText, type AITranslateTextProps, AITranslationProvider, AI_TRANSLATION_FEATURE_FLAG_KEY, type TranslatedIconProps, type UseConfigOptions, getAITranslationLDId, useAITranslation, useConfig };
|
|
282
|
+
export { ACTION, type AIAnalyticsEventProperties, type AIAnalyticsTracker, AITranslateText, type AITranslateTextProps, AITranslationProvider, AI_TRANSLATION_FEATURE_FLAG_KEY, type Action, type AnalyticEvent, BUTTON_TYPE, type BuildAnalyticEventParams, type ButtonType, type EventKeyParts, type Scope, type TranslatedIconProps, type UseAIAnalyticsReturn, type UseConfigOptions, buildAnalyticEvent, buildEventKey, buildObject, getAITranslationLDId, useAIAnalytics, useAITranslation, useConfig };
|
package/dist/modern/index.js
CHANGED
|
@@ -20,10 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ACTION: () => ACTION,
|
|
23
24
|
AITranslateText: () => AITranslateText,
|
|
24
25
|
AITranslationProvider: () => AITranslationProvider,
|
|
25
26
|
AI_TRANSLATION_FEATURE_FLAG_KEY: () => AI_TRANSLATION_FEATURE_FLAG_KEY,
|
|
27
|
+
BUTTON_TYPE: () => BUTTON_TYPE,
|
|
28
|
+
buildAnalyticEvent: () => buildAnalyticEvent,
|
|
29
|
+
buildEventKey: () => buildEventKey,
|
|
30
|
+
buildObject: () => buildObject,
|
|
26
31
|
getAITranslationLDId: () => getAITranslationLDId,
|
|
32
|
+
useAIAnalytics: () => useAIAnalytics,
|
|
27
33
|
useAITranslation: () => useAITranslation,
|
|
28
34
|
useConfig: () => useConfig
|
|
29
35
|
});
|
|
@@ -1449,7 +1455,12 @@ function AITranslationInnerProvider(props) {
|
|
|
1449
1455
|
companyId,
|
|
1450
1456
|
userId,
|
|
1451
1457
|
projectId,
|
|
1452
|
-
enableAIT = true
|
|
1458
|
+
enableAIT = true,
|
|
1459
|
+
companyLocale,
|
|
1460
|
+
projectLocale,
|
|
1461
|
+
onTrackAnalyticsEvent,
|
|
1462
|
+
page,
|
|
1463
|
+
scope
|
|
1453
1464
|
} = props;
|
|
1454
1465
|
const [translationProgress, setTranslationProgress] = (0, import_react.useState)(null);
|
|
1455
1466
|
const [modelDownloadProgress, setModelDownloadProgress] = (0, import_react.useState)(null);
|
|
@@ -1526,10 +1537,15 @@ function AITranslationInnerProvider(props) {
|
|
|
1526
1537
|
const contextValue = {
|
|
1527
1538
|
ait,
|
|
1528
1539
|
locale,
|
|
1540
|
+
companyLocale,
|
|
1541
|
+
projectLocale,
|
|
1529
1542
|
renderVersion: renderVersionManager.getVersion(),
|
|
1530
1543
|
translationProgress,
|
|
1531
1544
|
modelDownloadProgress,
|
|
1532
|
-
tool
|
|
1545
|
+
tool,
|
|
1546
|
+
onTrackAnalyticsEvent,
|
|
1547
|
+
page,
|
|
1548
|
+
scope
|
|
1533
1549
|
};
|
|
1534
1550
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AITranslationContext.Provider, { value: contextValue, children });
|
|
1535
1551
|
}
|
|
@@ -1549,15 +1565,143 @@ function useAITranslation() {
|
|
|
1549
1565
|
return ctx;
|
|
1550
1566
|
}
|
|
1551
1567
|
|
|
1568
|
+
// src/hooks/useAIAnalytics.ts
|
|
1569
|
+
var import_react3 = require("react");
|
|
1570
|
+
|
|
1571
|
+
// src/analytics/events.ts
|
|
1572
|
+
var BUTTON_TYPE = {
|
|
1573
|
+
TRANSLATE: "translate",
|
|
1574
|
+
HIGHLIGHT: "highlight"
|
|
1575
|
+
};
|
|
1576
|
+
var ACTION = {
|
|
1577
|
+
CLICKED: "clicked"
|
|
1578
|
+
};
|
|
1579
|
+
function buildObject(pageContext, buttonType) {
|
|
1580
|
+
return `${pageContext}_${buttonType}_button`;
|
|
1581
|
+
}
|
|
1582
|
+
function buildEventKey(parts) {
|
|
1583
|
+
const { scope, tool, object, action } = parts;
|
|
1584
|
+
return `ux.web.feature.${scope}.${tool}.${object}.${action}`;
|
|
1585
|
+
}
|
|
1586
|
+
function buildAnalyticEvent(params) {
|
|
1587
|
+
const {
|
|
1588
|
+
scope,
|
|
1589
|
+
tool,
|
|
1590
|
+
pageContext,
|
|
1591
|
+
buttonType,
|
|
1592
|
+
baseProperties,
|
|
1593
|
+
action,
|
|
1594
|
+
additionalProperties
|
|
1595
|
+
} = params;
|
|
1596
|
+
const resolvedAction = action ?? ACTION.CLICKED;
|
|
1597
|
+
const object = buildObject(pageContext, buttonType);
|
|
1598
|
+
const key = buildEventKey({
|
|
1599
|
+
scope,
|
|
1600
|
+
tool,
|
|
1601
|
+
object,
|
|
1602
|
+
action: resolvedAction
|
|
1603
|
+
});
|
|
1604
|
+
const properties = {
|
|
1605
|
+
...baseProperties,
|
|
1606
|
+
...additionalProperties
|
|
1607
|
+
};
|
|
1608
|
+
return { key, properties };
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
// src/hooks/useAIAnalytics.ts
|
|
1612
|
+
function useAIAnalytics() {
|
|
1613
|
+
const ctx = (0, import_react3.useContext)(AITranslationContext);
|
|
1614
|
+
if (!ctx) {
|
|
1615
|
+
throw new Error(
|
|
1616
|
+
"useAIAnalytics must be used inside an AITranslationProvider"
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
const {
|
|
1620
|
+
locale,
|
|
1621
|
+
companyLocale,
|
|
1622
|
+
projectLocale,
|
|
1623
|
+
tool,
|
|
1624
|
+
page,
|
|
1625
|
+
scope,
|
|
1626
|
+
onTrackAnalyticsEvent
|
|
1627
|
+
} = ctx;
|
|
1628
|
+
const isTrackingEnabled = Boolean(onTrackAnalyticsEvent);
|
|
1629
|
+
const buildBaseProperties = (0, import_react3.useCallback)(() => {
|
|
1630
|
+
const props = {
|
|
1631
|
+
user_locale: locale,
|
|
1632
|
+
tool,
|
|
1633
|
+
page: page ?? ""
|
|
1634
|
+
};
|
|
1635
|
+
if (companyLocale) props.company_locale = companyLocale;
|
|
1636
|
+
if (projectLocale) props.project_locale = projectLocale;
|
|
1637
|
+
return props;
|
|
1638
|
+
}, [locale, tool, page, companyLocale, projectLocale]);
|
|
1639
|
+
const trackTranslateButtonClicked = (0, import_react3.useCallback)(
|
|
1640
|
+
(additionalProperties) => {
|
|
1641
|
+
if (!onTrackAnalyticsEvent || !page || !scope) return;
|
|
1642
|
+
onTrackAnalyticsEvent(
|
|
1643
|
+
buildAnalyticEvent({
|
|
1644
|
+
scope,
|
|
1645
|
+
tool,
|
|
1646
|
+
pageContext: page,
|
|
1647
|
+
buttonType: BUTTON_TYPE.TRANSLATE,
|
|
1648
|
+
baseProperties: buildBaseProperties(),
|
|
1649
|
+
additionalProperties
|
|
1650
|
+
})
|
|
1651
|
+
);
|
|
1652
|
+
},
|
|
1653
|
+
[onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
|
|
1654
|
+
);
|
|
1655
|
+
const trackHighlightButtonClicked = (0, import_react3.useCallback)(
|
|
1656
|
+
(additionalProperties) => {
|
|
1657
|
+
if (!onTrackAnalyticsEvent || !page || !scope) return;
|
|
1658
|
+
onTrackAnalyticsEvent(
|
|
1659
|
+
buildAnalyticEvent({
|
|
1660
|
+
scope,
|
|
1661
|
+
tool,
|
|
1662
|
+
pageContext: page,
|
|
1663
|
+
buttonType: BUTTON_TYPE.HIGHLIGHT,
|
|
1664
|
+
baseProperties: buildBaseProperties(),
|
|
1665
|
+
additionalProperties
|
|
1666
|
+
})
|
|
1667
|
+
);
|
|
1668
|
+
},
|
|
1669
|
+
[onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
|
|
1670
|
+
);
|
|
1671
|
+
const trackCustomEvent = (0, import_react3.useCallback)(
|
|
1672
|
+
(buttonType, action, additionalProperties) => {
|
|
1673
|
+
if (!onTrackAnalyticsEvent || !page || !scope) return;
|
|
1674
|
+
onTrackAnalyticsEvent(
|
|
1675
|
+
buildAnalyticEvent({
|
|
1676
|
+
scope,
|
|
1677
|
+
tool,
|
|
1678
|
+
pageContext: page,
|
|
1679
|
+
buttonType,
|
|
1680
|
+
baseProperties: buildBaseProperties(),
|
|
1681
|
+
action,
|
|
1682
|
+
additionalProperties
|
|
1683
|
+
})
|
|
1684
|
+
);
|
|
1685
|
+
},
|
|
1686
|
+
[onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
|
|
1687
|
+
);
|
|
1688
|
+
return {
|
|
1689
|
+
trackTranslateButtonClicked,
|
|
1690
|
+
trackHighlightButtonClicked,
|
|
1691
|
+
trackCustomEvent,
|
|
1692
|
+
isTrackingEnabled
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1552
1696
|
// src/components/AITranslateText.tsx
|
|
1553
|
-
var
|
|
1697
|
+
var import_react5 = require("react");
|
|
1554
1698
|
|
|
1555
1699
|
// src/components/TranslatedIcon.tsx
|
|
1556
|
-
var
|
|
1700
|
+
var import_react4 = require("react");
|
|
1557
1701
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1558
1702
|
var TranslatedIcon = ({
|
|
1559
|
-
width =
|
|
1560
|
-
height =
|
|
1703
|
+
width = 24,
|
|
1704
|
+
height = 24,
|
|
1561
1705
|
className,
|
|
1562
1706
|
color = "#000000"
|
|
1563
1707
|
}) => {
|
|
@@ -1575,7 +1719,7 @@ var TranslatedIcon = ({
|
|
|
1575
1719
|
"path",
|
|
1576
1720
|
{
|
|
1577
1721
|
fill: color,
|
|
1578
|
-
d: "
|
|
1722
|
+
d: "M11.99 2C6.47 2 2 6.48 2 12C2 17.52 6.47 22 11.99 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 11.99 2ZM18.92 8H15.97C15.65 6.75 15.19 5.55 14.59 4.44C16.43 5.07 17.96 6.35 18.92 8ZM12 4.04C12.83 5.24 13.48 6.57 13.91 8H10.09C10.52 6.57 11.17 5.24 12 4.04ZM4.26 14C4.1 13.36 4 12.69 4 12C4 11.31 4.1 10.64 4.26 10H7.64C7.56 10.66 7.5 11.32 7.5 12C7.5 12.68 7.56 13.34 7.64 14H4.26ZM5.08 16H8.03C8.35 17.25 8.81 18.45 9.41 19.56C7.57 18.93 6.04 17.66 5.08 16ZM8.03 8H5.08C6.04 6.34 7.57 5.07 9.41 4.44C8.81 5.55 8.35 6.75 8.03 8ZM12 19.96C11.17 18.76 10.52 17.43 10.09 16H13.91C13.48 17.43 12.83 18.76 12 19.96ZM14.34 14H9.66C9.57 13.34 9.5 12.68 9.5 12C9.5 11.32 9.57 10.65 9.66 10H14.34C14.43 10.65 14.5 11.32 14.5 12C14.5 12.68 14.43 13.34 14.34 14ZM14.59 19.56C15.19 18.45 15.65 17.25 15.97 16H18.92C17.96 17.65 16.43 18.93 14.59 19.56ZM16.36 14C16.44 13.34 16.5 12.68 16.5 12C16.5 11.32 16.44 10.66 16.36 10H19.74C19.9 10.64 20 11.31 20 12C20 12.69 19.9 13.36 19.74 14H16.36Z"
|
|
1579
1723
|
}
|
|
1580
1724
|
)
|
|
1581
1725
|
}
|
|
@@ -1590,11 +1734,11 @@ var AITranslateText = ({
|
|
|
1590
1734
|
showHighlight = false,
|
|
1591
1735
|
translatedIconProps
|
|
1592
1736
|
}) => {
|
|
1593
|
-
const context = (0,
|
|
1594
|
-
const [displayText, setDisplayText] = (0,
|
|
1595
|
-
const [showHighlightState, setShowHighlightState] = (0,
|
|
1596
|
-
const eventHandlerRef = (0,
|
|
1597
|
-
(0,
|
|
1737
|
+
const context = (0, import_react5.useContext)(AITranslationContext);
|
|
1738
|
+
const [displayText, setDisplayText] = (0, import_react5.useState)(text ?? "");
|
|
1739
|
+
const [showHighlightState, setShowHighlightState] = (0, import_react5.useState)(showHighlight);
|
|
1740
|
+
const eventHandlerRef = (0, import_react5.useRef)(null);
|
|
1741
|
+
(0, import_react5.useEffect)(() => {
|
|
1598
1742
|
if (!context) return;
|
|
1599
1743
|
if (!eventHandlerRef.current) {
|
|
1600
1744
|
eventHandlerRef.current = new EventHandler(context.tool);
|
|
@@ -1613,14 +1757,14 @@ var AITranslateText = ({
|
|
|
1613
1757
|
);
|
|
1614
1758
|
return () => unsubscribe();
|
|
1615
1759
|
}, [context, text, showHighlight]);
|
|
1616
|
-
const reset = (0,
|
|
1760
|
+
const reset = (0, import_react5.useCallback)(
|
|
1617
1761
|
(displayValue = text) => {
|
|
1618
1762
|
setDisplayText(displayValue);
|
|
1619
1763
|
setShowHighlightState(false);
|
|
1620
1764
|
},
|
|
1621
1765
|
[text]
|
|
1622
1766
|
);
|
|
1623
|
-
(0,
|
|
1767
|
+
(0, import_react5.useEffect)(() => {
|
|
1624
1768
|
if (text == null || text === "") {
|
|
1625
1769
|
reset(text ?? "");
|
|
1626
1770
|
return;
|
|
@@ -1672,10 +1816,16 @@ var getAITranslationLDId = (domain) => {
|
|
|
1672
1816
|
};
|
|
1673
1817
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1674
1818
|
0 && (module.exports = {
|
|
1819
|
+
ACTION,
|
|
1675
1820
|
AITranslateText,
|
|
1676
1821
|
AITranslationProvider,
|
|
1677
1822
|
AI_TRANSLATION_FEATURE_FLAG_KEY,
|
|
1823
|
+
BUTTON_TYPE,
|
|
1824
|
+
buildAnalyticEvent,
|
|
1825
|
+
buildEventKey,
|
|
1826
|
+
buildObject,
|
|
1678
1827
|
getAITranslationLDId,
|
|
1828
|
+
useAIAnalytics,
|
|
1679
1829
|
useAITranslation,
|
|
1680
1830
|
useConfig
|
|
1681
1831
|
});
|
package/dist/modern/index.mjs
CHANGED
|
@@ -1424,7 +1424,12 @@ function AITranslationInnerProvider(props) {
|
|
|
1424
1424
|
companyId,
|
|
1425
1425
|
userId,
|
|
1426
1426
|
projectId,
|
|
1427
|
-
enableAIT = true
|
|
1427
|
+
enableAIT = true,
|
|
1428
|
+
companyLocale,
|
|
1429
|
+
projectLocale,
|
|
1430
|
+
onTrackAnalyticsEvent,
|
|
1431
|
+
page,
|
|
1432
|
+
scope
|
|
1428
1433
|
} = props;
|
|
1429
1434
|
const [translationProgress, setTranslationProgress] = useState(null);
|
|
1430
1435
|
const [modelDownloadProgress, setModelDownloadProgress] = useState(null);
|
|
@@ -1501,10 +1506,15 @@ function AITranslationInnerProvider(props) {
|
|
|
1501
1506
|
const contextValue = {
|
|
1502
1507
|
ait,
|
|
1503
1508
|
locale,
|
|
1509
|
+
companyLocale,
|
|
1510
|
+
projectLocale,
|
|
1504
1511
|
renderVersion: renderVersionManager.getVersion(),
|
|
1505
1512
|
translationProgress,
|
|
1506
1513
|
modelDownloadProgress,
|
|
1507
|
-
tool
|
|
1514
|
+
tool,
|
|
1515
|
+
onTrackAnalyticsEvent,
|
|
1516
|
+
page,
|
|
1517
|
+
scope
|
|
1508
1518
|
};
|
|
1509
1519
|
return /* @__PURE__ */ jsx(AITranslationContext.Provider, { value: contextValue, children });
|
|
1510
1520
|
}
|
|
@@ -1524,12 +1534,140 @@ function useAITranslation() {
|
|
|
1524
1534
|
return ctx;
|
|
1525
1535
|
}
|
|
1526
1536
|
|
|
1537
|
+
// src/hooks/useAIAnalytics.ts
|
|
1538
|
+
import { useContext as useContext2, useCallback as useCallback2 } from "react";
|
|
1539
|
+
|
|
1540
|
+
// src/analytics/events.ts
|
|
1541
|
+
var BUTTON_TYPE = {
|
|
1542
|
+
TRANSLATE: "translate",
|
|
1543
|
+
HIGHLIGHT: "highlight"
|
|
1544
|
+
};
|
|
1545
|
+
var ACTION = {
|
|
1546
|
+
CLICKED: "clicked"
|
|
1547
|
+
};
|
|
1548
|
+
function buildObject(pageContext, buttonType) {
|
|
1549
|
+
return `${pageContext}_${buttonType}_button`;
|
|
1550
|
+
}
|
|
1551
|
+
function buildEventKey(parts) {
|
|
1552
|
+
const { scope, tool, object, action } = parts;
|
|
1553
|
+
return `ux.web.feature.${scope}.${tool}.${object}.${action}`;
|
|
1554
|
+
}
|
|
1555
|
+
function buildAnalyticEvent(params) {
|
|
1556
|
+
const {
|
|
1557
|
+
scope,
|
|
1558
|
+
tool,
|
|
1559
|
+
pageContext,
|
|
1560
|
+
buttonType,
|
|
1561
|
+
baseProperties,
|
|
1562
|
+
action,
|
|
1563
|
+
additionalProperties
|
|
1564
|
+
} = params;
|
|
1565
|
+
const resolvedAction = action ?? ACTION.CLICKED;
|
|
1566
|
+
const object = buildObject(pageContext, buttonType);
|
|
1567
|
+
const key = buildEventKey({
|
|
1568
|
+
scope,
|
|
1569
|
+
tool,
|
|
1570
|
+
object,
|
|
1571
|
+
action: resolvedAction
|
|
1572
|
+
});
|
|
1573
|
+
const properties = {
|
|
1574
|
+
...baseProperties,
|
|
1575
|
+
...additionalProperties
|
|
1576
|
+
};
|
|
1577
|
+
return { key, properties };
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/hooks/useAIAnalytics.ts
|
|
1581
|
+
function useAIAnalytics() {
|
|
1582
|
+
const ctx = useContext2(AITranslationContext);
|
|
1583
|
+
if (!ctx) {
|
|
1584
|
+
throw new Error(
|
|
1585
|
+
"useAIAnalytics must be used inside an AITranslationProvider"
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
const {
|
|
1589
|
+
locale,
|
|
1590
|
+
companyLocale,
|
|
1591
|
+
projectLocale,
|
|
1592
|
+
tool,
|
|
1593
|
+
page,
|
|
1594
|
+
scope,
|
|
1595
|
+
onTrackAnalyticsEvent
|
|
1596
|
+
} = ctx;
|
|
1597
|
+
const isTrackingEnabled = Boolean(onTrackAnalyticsEvent);
|
|
1598
|
+
const buildBaseProperties = useCallback2(() => {
|
|
1599
|
+
const props = {
|
|
1600
|
+
user_locale: locale,
|
|
1601
|
+
tool,
|
|
1602
|
+
page: page ?? ""
|
|
1603
|
+
};
|
|
1604
|
+
if (companyLocale) props.company_locale = companyLocale;
|
|
1605
|
+
if (projectLocale) props.project_locale = projectLocale;
|
|
1606
|
+
return props;
|
|
1607
|
+
}, [locale, tool, page, companyLocale, projectLocale]);
|
|
1608
|
+
const trackTranslateButtonClicked = useCallback2(
|
|
1609
|
+
(additionalProperties) => {
|
|
1610
|
+
if (!onTrackAnalyticsEvent || !page || !scope) return;
|
|
1611
|
+
onTrackAnalyticsEvent(
|
|
1612
|
+
buildAnalyticEvent({
|
|
1613
|
+
scope,
|
|
1614
|
+
tool,
|
|
1615
|
+
pageContext: page,
|
|
1616
|
+
buttonType: BUTTON_TYPE.TRANSLATE,
|
|
1617
|
+
baseProperties: buildBaseProperties(),
|
|
1618
|
+
additionalProperties
|
|
1619
|
+
})
|
|
1620
|
+
);
|
|
1621
|
+
},
|
|
1622
|
+
[onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
|
|
1623
|
+
);
|
|
1624
|
+
const trackHighlightButtonClicked = useCallback2(
|
|
1625
|
+
(additionalProperties) => {
|
|
1626
|
+
if (!onTrackAnalyticsEvent || !page || !scope) return;
|
|
1627
|
+
onTrackAnalyticsEvent(
|
|
1628
|
+
buildAnalyticEvent({
|
|
1629
|
+
scope,
|
|
1630
|
+
tool,
|
|
1631
|
+
pageContext: page,
|
|
1632
|
+
buttonType: BUTTON_TYPE.HIGHLIGHT,
|
|
1633
|
+
baseProperties: buildBaseProperties(),
|
|
1634
|
+
additionalProperties
|
|
1635
|
+
})
|
|
1636
|
+
);
|
|
1637
|
+
},
|
|
1638
|
+
[onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
|
|
1639
|
+
);
|
|
1640
|
+
const trackCustomEvent = useCallback2(
|
|
1641
|
+
(buttonType, action, additionalProperties) => {
|
|
1642
|
+
if (!onTrackAnalyticsEvent || !page || !scope) return;
|
|
1643
|
+
onTrackAnalyticsEvent(
|
|
1644
|
+
buildAnalyticEvent({
|
|
1645
|
+
scope,
|
|
1646
|
+
tool,
|
|
1647
|
+
pageContext: page,
|
|
1648
|
+
buttonType,
|
|
1649
|
+
baseProperties: buildBaseProperties(),
|
|
1650
|
+
action,
|
|
1651
|
+
additionalProperties
|
|
1652
|
+
})
|
|
1653
|
+
);
|
|
1654
|
+
},
|
|
1655
|
+
[onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
|
|
1656
|
+
);
|
|
1657
|
+
return {
|
|
1658
|
+
trackTranslateButtonClicked,
|
|
1659
|
+
trackHighlightButtonClicked,
|
|
1660
|
+
trackCustomEvent,
|
|
1661
|
+
isTrackingEnabled
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1527
1665
|
// src/components/AITranslateText.tsx
|
|
1528
1666
|
import {
|
|
1529
1667
|
useState as useState2,
|
|
1530
1668
|
useEffect as useEffect2,
|
|
1531
|
-
useContext as
|
|
1532
|
-
useCallback as
|
|
1669
|
+
useContext as useContext3,
|
|
1670
|
+
useCallback as useCallback3,
|
|
1533
1671
|
useRef as useRef2
|
|
1534
1672
|
} from "react";
|
|
1535
1673
|
|
|
@@ -1537,8 +1675,8 @@ import {
|
|
|
1537
1675
|
import "react";
|
|
1538
1676
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1539
1677
|
var TranslatedIcon = ({
|
|
1540
|
-
width =
|
|
1541
|
-
height =
|
|
1678
|
+
width = 24,
|
|
1679
|
+
height = 24,
|
|
1542
1680
|
className,
|
|
1543
1681
|
color = "#000000"
|
|
1544
1682
|
}) => {
|
|
@@ -1556,7 +1694,7 @@ var TranslatedIcon = ({
|
|
|
1556
1694
|
"path",
|
|
1557
1695
|
{
|
|
1558
1696
|
fill: color,
|
|
1559
|
-
d: "
|
|
1697
|
+
d: "M11.99 2C6.47 2 2 6.48 2 12C2 17.52 6.47 22 11.99 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 11.99 2ZM18.92 8H15.97C15.65 6.75 15.19 5.55 14.59 4.44C16.43 5.07 17.96 6.35 18.92 8ZM12 4.04C12.83 5.24 13.48 6.57 13.91 8H10.09C10.52 6.57 11.17 5.24 12 4.04ZM4.26 14C4.1 13.36 4 12.69 4 12C4 11.31 4.1 10.64 4.26 10H7.64C7.56 10.66 7.5 11.32 7.5 12C7.5 12.68 7.56 13.34 7.64 14H4.26ZM5.08 16H8.03C8.35 17.25 8.81 18.45 9.41 19.56C7.57 18.93 6.04 17.66 5.08 16ZM8.03 8H5.08C6.04 6.34 7.57 5.07 9.41 4.44C8.81 5.55 8.35 6.75 8.03 8ZM12 19.96C11.17 18.76 10.52 17.43 10.09 16H13.91C13.48 17.43 12.83 18.76 12 19.96ZM14.34 14H9.66C9.57 13.34 9.5 12.68 9.5 12C9.5 11.32 9.57 10.65 9.66 10H14.34C14.43 10.65 14.5 11.32 14.5 12C14.5 12.68 14.43 13.34 14.34 14ZM14.59 19.56C15.19 18.45 15.65 17.25 15.97 16H18.92C17.96 17.65 16.43 18.93 14.59 19.56ZM16.36 14C16.44 13.34 16.5 12.68 16.5 12C16.5 11.32 16.44 10.66 16.36 10H19.74C19.9 10.64 20 11.31 20 12C20 12.69 19.9 13.36 19.74 14H16.36Z"
|
|
1560
1698
|
}
|
|
1561
1699
|
)
|
|
1562
1700
|
}
|
|
@@ -1571,7 +1709,7 @@ var AITranslateText = ({
|
|
|
1571
1709
|
showHighlight = false,
|
|
1572
1710
|
translatedIconProps
|
|
1573
1711
|
}) => {
|
|
1574
|
-
const context =
|
|
1712
|
+
const context = useContext3(AITranslationContext);
|
|
1575
1713
|
const [displayText, setDisplayText] = useState2(text ?? "");
|
|
1576
1714
|
const [showHighlightState, setShowHighlightState] = useState2(showHighlight);
|
|
1577
1715
|
const eventHandlerRef = useRef2(null);
|
|
@@ -1594,7 +1732,7 @@ var AITranslateText = ({
|
|
|
1594
1732
|
);
|
|
1595
1733
|
return () => unsubscribe();
|
|
1596
1734
|
}, [context, text, showHighlight]);
|
|
1597
|
-
const reset =
|
|
1735
|
+
const reset = useCallback3(
|
|
1598
1736
|
(displayValue = text) => {
|
|
1599
1737
|
setDisplayText(displayValue);
|
|
1600
1738
|
setShowHighlightState(false);
|
|
@@ -1652,10 +1790,16 @@ var getAITranslationLDId = (domain) => {
|
|
|
1652
1790
|
}
|
|
1653
1791
|
};
|
|
1654
1792
|
export {
|
|
1793
|
+
ACTION,
|
|
1655
1794
|
AITranslateText,
|
|
1656
1795
|
AITranslationProvider,
|
|
1657
1796
|
AI_TRANSLATION_FEATURE_FLAG_KEY,
|
|
1797
|
+
BUTTON_TYPE,
|
|
1798
|
+
buildAnalyticEvent,
|
|
1799
|
+
buildEventKey,
|
|
1800
|
+
buildObject,
|
|
1658
1801
|
getAITranslationLDId,
|
|
1802
|
+
useAIAnalytics,
|
|
1659
1803
|
useAITranslation,
|
|
1660
1804
|
useConfig
|
|
1661
1805
|
};
|
package/package.json
CHANGED