@microsoft/omnichannel-chat-widget 1.8.4-main.e0c2625 → 1.8.4-main.f6a1732

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.
Files changed (22) hide show
  1. package/README.md +1 -0
  2. package/lib/cjs/common/utils.js +36 -1
  3. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +30 -12
  4. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +96 -5
  5. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +51 -0
  6. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -0
  7. package/lib/cjs/components/webchatcontainerstateful/common/utils/citationA11y.js +195 -0
  8. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachments/AdaptiveCardAccessibilityWrapper.js +15 -0
  9. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.js +55 -1
  10. package/lib/esm/common/utils.js +34 -0
  11. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +31 -13
  12. package/lib/esm/components/livechatwidget/common/createMarkdown.js +96 -5
  13. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +51 -0
  14. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -0
  15. package/lib/esm/components/webchatcontainerstateful/common/utils/citationA11y.js +188 -0
  16. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachments/AdaptiveCardAccessibilityWrapper.js +15 -0
  17. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.js +55 -1
  18. package/lib/types/common/utils.d.ts +1 -0
  19. package/lib/types/components/webchatcontainerstateful/common/utils/citationA11y.d.ts +1 -0
  20. package/lib/types/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.d.ts +7 -0
  21. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +12 -0
  22. package/package.json +20 -2
package/README.md CHANGED
@@ -311,6 +311,7 @@ BroadcastService.getMessageByEventName("CloseChat").subscribe(async (msg) => {
311
311
  [Create LiveChatWidget with Webpack5 and TypeScript](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/BuildingUsingWebpack5.md)\
312
312
  [Omnichannel Features](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/Features.md)\
313
313
  [How to Add Visual Regression Tests](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/VisualRegressionTestingGuide.md)\
314
+ [Accessibility Tooling](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/accessibility/README.md)\
314
315
  [Security](https://github.com/microsoft/omnichannel-chat-widget/blob/main/SECURITY.md)\
315
316
  [Third Party Cookie Support](https://github.com/microsoft/omnichannel-chat-widget/blob/main/docs/Tpc.md)\
316
317
  [Storybook](https://microsoft.github.io/omnichannel-chat-widget/docs/storybook/)
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getCustomEventValue = exports.getConversationDetailsCall = exports.getBroadcastChannelName = exports.formatTemplateString = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.debounceLeading = exports.createTimer = exports.createFileAndDownload = exports.checkContactIdError = exports.changeLanguageCodeFormatForWebChat = exports.addDelayInMs = void 0;
6
+ exports.getCustomEventValue = exports.getConversationDetailsCall = exports.getBroadcastChannelName = exports.formatTemplateString = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.debounceLeading = exports.createTimer = exports.createFileAndDownload = exports.checkContactIdError = exports.changeLanguageCodeFormatForWebChat = exports.announceMessageImmediately = exports.addDelayInMs = void 0;
7
7
  exports.getDeviceType = getDeviceType;
8
8
  exports.getWidgetEndChatEventName = exports.getWidgetCacheIdfromProps = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getStateFromCache = exports.getLocaleDirection = exports.getIconText = exports.getDomain = void 0;
9
9
  exports.isEndConversationDueToOverflowActivity = isEndConversationDueToOverflowActivity;
@@ -158,6 +158,41 @@ const setFocusOnElement = selector => {
158
158
  element === null || element === void 0 ? void 0 : element.focus();
159
159
  };
160
160
  exports.setFocusOnElement = setFocusOnElement;
161
+ const IMMEDIATE_ANNOUNCEMENT_REGION_ID = "oc-lcw-immediate-announcement";
162
+
163
+ // Announces a message to screen readers via an aria-live="assertive" region
164
+ // attached to document.body — outside the chat widget's DOM subtree — so the
165
+ // screen reader does not have to traverse chat content to reach it.
166
+ const announceMessageImmediately = message => {
167
+ if (!message || typeof document === "undefined") {
168
+ return;
169
+ }
170
+ let region = document.getElementById(IMMEDIATE_ANNOUNCEMENT_REGION_ID);
171
+ if (!region) {
172
+ region = document.createElement("div");
173
+ region.id = IMMEDIATE_ANNOUNCEMENT_REGION_ID;
174
+ region.setAttribute("aria-live", "assertive");
175
+ region.setAttribute("role", "alert");
176
+ region.setAttribute("aria-atomic", "true");
177
+ region.style.position = "absolute";
178
+ region.style.width = "1px";
179
+ region.style.height = "1px";
180
+ region.style.overflow = "hidden";
181
+ region.style.clip = "rect(0 0 0 0)";
182
+ region.style.clipPath = "inset(50%)";
183
+ region.style.whiteSpace = "nowrap";
184
+ document.body.appendChild(region);
185
+ }
186
+ region.textContent = "";
187
+ // Re-set on the next tick so screen readers detect the change even when
188
+ // the same message is announced twice in a row.
189
+ setTimeout(() => {
190
+ if (region) {
191
+ region.textContent = message;
192
+ }
193
+ }, 50);
194
+ };
195
+ exports.announceMessageImmediately = announceMessageImmediately;
161
196
  const escapeHtml = inputString => {
162
197
  const entityMap = {
163
198
  "<": "&lt;",
@@ -35,16 +35,23 @@ const EmailTranscriptPaneStateful = props => {
35
35
  const [state, dispatch] = (0, _useChatContextStore.default)();
36
36
  const [facadeChatSDK] = (0, _useFacadeChatSDKStore.default)();
37
37
  const [initialEmail, setInitialEmail] = (0, _react.useState)("");
38
- const closeEmailTranscriptPane = () => {
38
+ // restoreFocus=false is used on the submit path: the notification banner
39
+ // (success or error) takes focus via NotificationHandler.setFocusOnNotificationCloseButton,
40
+ // so an intermediate restore to the chat-widget shell would otherwise cause SRs to
41
+ // announce "Enter <widget>" in between the dialog and the banner.
42
+ const closeEmailTranscriptPane = function () {
43
+ let restoreFocus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
39
44
  dispatch({
40
45
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOW_EMAIL_TRANSCRIPT_PANE,
41
46
  payload: false
42
47
  });
43
- const previousFocusedElementId = state.appStates.previousElementIdOnFocusBeforeModalOpen;
44
- if (previousFocusedElementId) {
45
- (0, _utils.setFocusOnElement)("#" + previousFocusedElementId);
46
- } else {
47
- (0, _utils.setFocusOnSendBox)();
48
+ if (restoreFocus) {
49
+ const previousFocusedElementId = state.appStates.previousElementIdOnFocusBeforeModalOpen;
50
+ if (previousFocusedElementId) {
51
+ (0, _utils.setFocusOnElement)("#" + previousFocusedElementId);
52
+ } else {
53
+ (0, _utils.setFocusOnSendBox)();
54
+ }
48
55
  }
49
56
  dispatch({
50
57
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PREVIOUS_FOCUSED_ELEMENT_ID,
@@ -55,23 +62,31 @@ const EmailTranscriptPaneStateful = props => {
55
62
  const onSend = (0, _react.useCallback)(async email => {
56
63
  var _state$domainStates;
57
64
  const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext;
58
- closeEmailTranscriptPane();
65
+ closeEmailTranscriptPane(false);
59
66
  const chatTranscriptBody = {
60
67
  emailAddress: email,
61
68
  attachmentMessage: (props === null || props === void 0 ? void 0 : props.attachmentMessage) ?? "The following attachment was uploaded during the conversation:"
62
69
  };
63
70
  try {
64
- var _state$domainStates2, _state$domainStates2$;
71
+ var _state$domainStates2, _state$domainStates2$, _state$domainStates3, _state$domainStates3$;
65
72
  await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.emailLiveChatTranscript(chatTranscriptBody, {
66
73
  liveChatContext
67
74
  }));
68
- _NotificationHandler.NotificationHandler.notifySuccess(_NotificationScenarios.NotificationScenarios.EmailAddressSaved, (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.middlewareLocalizedTexts) === null || _state$domainStates2$ === void 0 ? void 0 : _state$domainStates2$.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS) ?? (_defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === null || _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === void 0 ? void 0 : _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS));
75
+ const successMessage = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.middlewareLocalizedTexts) === null || _state$domainStates2$ === void 0 ? void 0 : _state$domainStates2$.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS) ?? (_defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === null || _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === void 0 ? void 0 : _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS);
76
+ // Announce from a live region at document.body level so the
77
+ // screen reader speaks the confirmation immediately, without
78
+ // traversing the chat transcript on the way to the banner.
79
+ // Prefix with the explicit state word so SR users hear the outcome
80
+ // (visual users already see a success icon on the banner).
81
+ const successSrPrefix = (state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.middlewareLocalizedTexts) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.MIDDLEWARE_SR_PREFIX_SUCCESS) ?? _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_SR_PREFIX_SUCCESS;
82
+ (0, _utils.announceMessageImmediately)(`${successSrPrefix}${successMessage}`);
83
+ _NotificationHandler.NotificationHandler.notifySuccess(_NotificationScenarios.NotificationScenarios.EmailAddressSaved, successMessage);
69
84
  _TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
70
85
  Event: _TelemetryConstants.TelemetryEvent.EmailTranscriptSent,
71
86
  Description: "Transcript sent to email successfully."
72
87
  });
73
88
  } catch (ex) {
74
- var _state$domainStates3, _state$domainStates3$;
89
+ var _state$domainStates4, _state$domainStates4$, _state$domainStates5, _state$domainStates5$;
75
90
  _TelemetryHelper.TelemetryHelper.logActionEventToAllTelemetry(_TelemetryConstants.LogLevel.ERROR, {
76
91
  Event: _TelemetryConstants.TelemetryEvent.EmailTranscriptFailed,
77
92
  Description: "Email transcript failed.",
@@ -79,8 +94,11 @@ const EmailTranscriptPaneStateful = props => {
79
94
  exception: ex
80
95
  }
81
96
  });
82
- const message = (0, _utils.formatTemplateString)((state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.middlewareLocalizedTexts) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR) ?? _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR, [email]);
83
- _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.EmailTranscriptError, (props === null || props === void 0 ? void 0 : props.bannerMessageOnError) ?? message);
97
+ const message = (0, _utils.formatTemplateString)((state === null || state === void 0 ? void 0 : (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : (_state$domainStates4$ = _state$domainStates4.middlewareLocalizedTexts) === null || _state$domainStates4$ === void 0 ? void 0 : _state$domainStates4$.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR) ?? _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR, [email]);
98
+ const bannerMessage = (props === null || props === void 0 ? void 0 : props.bannerMessageOnError) ?? message;
99
+ const errorSrPrefix = (state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.middlewareLocalizedTexts) === null || _state$domainStates5$ === void 0 ? void 0 : _state$domainStates5$.MIDDLEWARE_SR_PREFIX_ERROR) ?? _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_SR_PREFIX_ERROR;
100
+ (0, _utils.announceMessageImmediately)(`${errorSrPrefix}${bannerMessage}`);
101
+ _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.EmailTranscriptError, bannerMessage);
84
102
  }
85
103
  }, [props.attachmentMessage, props.bannerMessageOnError, facadeChatSDK, state.domainStates.liveChatContext]);
86
104
  const controlProps = {
@@ -42,10 +42,8 @@ const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdown
42
42
 
43
43
  markdown.disable(["strikethrough"]);
44
44
 
45
- // Custom plugin to fix numbered list continuity
45
+ // Custom plugin to fix numbered list continuity and merge adjacent markdown links with the same href.
46
46
  markdown.use(function (md) {
47
- const originalRender = md.render.bind(md);
48
- const originalRenderInline = md.renderInline.bind(md);
49
47
  function preprocessText(text) {
50
48
  // Handle numbered lists that come with double line breaks (knowledge article format)
51
49
  // This ensures proper continuous numbering instead of separate lists
@@ -80,16 +78,109 @@ const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdown
80
78
  return result;
81
79
  }
82
80
 
81
+ // Accessibility fix: when a bot emits content like "[1.](url) [View details](url)",
82
+ // markdown-it renders two sibling links that screen readers announce as two separate
83
+ // focusable links. Merge consecutive markdown link tokens with identical attributes so
84
+ // the number and label form one combined focusable link without discarding metadata.
85
+ md.core.ruler.after("inline", "merge_adjacent_same_href_links", function (state) {
86
+ const sortedAttrs = token => (token.attrs || []).map(attr => `${attr[0]}=${attr[1]}`).sort();
87
+ const hasSameAttributes = (first, second) => {
88
+ const firstAttrs = sortedAttrs(first);
89
+ const secondAttrs = sortedAttrs(second);
90
+ return firstAttrs.length === secondAttrs.length && firstAttrs.every((attr, index) => attr === secondAttrs[index]);
91
+ };
92
+ const collectLink = (children, index) => {
93
+ var _open$attrGet;
94
+ const open = children[index];
95
+ if (!open || open.type !== "link_open") {
96
+ return undefined;
97
+ }
98
+ const href = (_open$attrGet = open.attrGet) === null || _open$attrGet === void 0 ? void 0 : _open$attrGet.call(open, "href");
99
+ if (!href) {
100
+ return undefined;
101
+ }
102
+ let depth = 0;
103
+ for (let currentIndex = index; currentIndex < children.length; currentIndex++) {
104
+ const token = children[currentIndex];
105
+ if (token.type === "link_open") {
106
+ depth++;
107
+ } else if (token.type === "link_close") {
108
+ depth--;
109
+ if (depth === 0) {
110
+ return {
111
+ closeIndex: currentIndex,
112
+ href,
113
+ open
114
+ };
115
+ }
116
+ }
117
+ }
118
+ return undefined;
119
+ };
120
+ const getNextAdjacentLink = (children, startIndex) => {
121
+ const separatorTokens = [];
122
+ let index = startIndex;
123
+ while (index < children.length && children[index].type === "text" && /^\s*$/.test(children[index].content || "")) {
124
+ separatorTokens.push(children[index]);
125
+ index++;
126
+ }
127
+ const link = collectLink(children, index);
128
+ if (!link) {
129
+ return undefined;
130
+ }
131
+ return {
132
+ ...link,
133
+ openIndex: index,
134
+ separatorTokens
135
+ };
136
+ };
137
+ state.tokens.forEach(blockToken => {
138
+ if (blockToken.type !== "inline" || !blockToken.children) {
139
+ return;
140
+ }
141
+ const mergedChildren = [];
142
+ const children = blockToken.children;
143
+ let index = 0;
144
+ while (index < children.length) {
145
+ const firstLink = collectLink(children, index);
146
+ if (!firstLink) {
147
+ mergedChildren.push(children[index]);
148
+ index++;
149
+ continue;
150
+ }
151
+ const linkTokens = [firstLink.open, ...children.slice(index + 1, firstLink.closeIndex)];
152
+ let nextIndex = firstLink.closeIndex + 1;
153
+ let mergedAnyLink = false;
154
+ let nextLink = getNextAdjacentLink(children, nextIndex);
155
+ while (nextLink && nextLink.href === firstLink.href && hasSameAttributes(firstLink.open, nextLink.open)) {
156
+ linkTokens.push(...nextLink.separatorTokens);
157
+ linkTokens.push(...children.slice(nextLink.openIndex + 1, nextLink.closeIndex));
158
+ nextIndex = nextLink.closeIndex + 1;
159
+ mergedAnyLink = true;
160
+ nextLink = getNextAdjacentLink(children, nextIndex);
161
+ }
162
+ if (mergedAnyLink) {
163
+ mergedChildren.push(...linkTokens, children[firstLink.closeIndex]);
164
+ index = nextIndex;
165
+ } else {
166
+ mergedChildren.push(children[index]);
167
+ index++;
168
+ }
169
+ }
170
+ blockToken.children = mergedChildren;
171
+ });
172
+ });
173
+
83
174
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
175
  md.render = function (text, env) {
85
176
  const processedText = preprocessText(text);
86
- return originalRender(processedText, env);
177
+ return md.renderer.render(md.parse(processedText, env), md.options, env);
87
178
  };
88
179
 
89
180
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
181
  md.renderInline = function (text, env) {
91
182
  const processedText = preprocessText(text);
92
- return originalRenderInline(processedText, env);
183
+ return md.renderer.render(md.parseInline(processedText, env), md.options, env);
93
184
  };
94
185
  });
95
186
 
@@ -31,6 +31,7 @@ var _liveChatConfigUtils = require("../livechatwidget/common/liveChatConfigUtils
31
31
  var _ = require("../..");
32
32
  var _useFacadeChatSDKStore = _interopRequireDefault(require("../../hooks/useFacadeChatSDKStore"));
33
33
  var _usePersistentChatHistory = _interopRequireDefault(require("./hooks/usePersistentChatHistory"));
34
+ var _citationA11y = require("./common/utils/citationA11y");
34
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
36
37
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -155,6 +156,56 @@ const WebChatContainerStateful = props => {
155
156
  document.addEventListener("click", clickHandler);
156
157
  return () => document.removeEventListener("click", clickHandler);
157
158
  }, [state]);
159
+
160
+ // Accessibility: Merge citation card's number badge and link text into a single
161
+ // focusable element. WebChat's LinkDefinitionItem renders an <a> containing a
162
+ // badge <div> (the number, e.g. "1") and a text <div> (the title). On iOS
163
+ // VoiceOver and Android TalkBack, those block-level descendants are otherwise
164
+ // announced as two separate focusable links. The patch sets a combined
165
+ // aria-label on the anchor and hides every descendant from the a11y tree so
166
+ // the whole card is announced as one link.
167
+ (0, _react2.useEffect)(() => {
168
+ const webChatRoot = document.getElementById("ms_lcw_webchat_root");
169
+ if (!webChatRoot) {
170
+ return;
171
+ }
172
+ (0, _citationA11y.patchCitationAnchorsForA11y)(webChatRoot);
173
+ const observer = new MutationObserver(mutations => {
174
+ for (const m of mutations) {
175
+ if (m.type === "childList") {
176
+ m.addedNodes.forEach(node => {
177
+ if (node.nodeType === Node.ELEMENT_NODE) {
178
+ var _parentElement, _parentElement$closes;
179
+ (0, _citationA11y.patchCitationAnchorsForA11y)(node);
180
+ // A child added inside an existing anchor (e.g. React
181
+ // mounting OpenInNewWindowIcon after the anchor) means
182
+ // the parent anchor needs to re-walk its descendants.
183
+ const ancestor = (_parentElement = node.parentElement) === null || _parentElement === void 0 ? void 0 : (_parentElement$closes = _parentElement.closest) === null || _parentElement$closes === void 0 ? void 0 : _parentElement$closes.call(_parentElement, "a.webchat__link-definitions__list-item-box");
184
+ if (ancestor) {
185
+ (0, _citationA11y.patchCitationAnchorsForA11y)(ancestor);
186
+ }
187
+ }
188
+ });
189
+ } else if (m.type === "attributes" && m.target.nodeType === Node.ELEMENT_NODE) {
190
+ var _target$closest;
191
+ // React may strip our aria-hidden during a re-render; reapply
192
+ // by re-patching the closest matching anchor ancestor.
193
+ const target = m.target;
194
+ const ancestor = (_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, "a.webchat__link-definitions__list-item-box");
195
+ if (ancestor) {
196
+ (0, _citationA11y.patchCitationAnchorsForA11y)(ancestor);
197
+ }
198
+ }
199
+ }
200
+ });
201
+ observer.observe(webChatRoot, {
202
+ childList: true,
203
+ subtree: true,
204
+ attributes: true,
205
+ attributeFilter: ["aria-hidden", "role", "tabindex", "inert"]
206
+ });
207
+ return () => observer.disconnect();
208
+ }, []);
158
209
  const minimizedStyles = state.appStates.isMinimized ? shouldLoadPersistentHistoryMessages ? {
159
210
  visibility: "hidden",
160
211
  position: "absolute",
@@ -36,6 +36,8 @@ const defaultMiddlewareLocalizedTexts = {
36
36
  MIDDLEWARE_BANNER_FILE_SENT: "File sent successfully.",
37
37
  MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS: "Email will be sent after chat ends!",
38
38
  MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR: "Email {0} could not be saved, try again later.",
39
+ MIDDLEWARE_SR_PREFIX_SUCCESS: "Success. ",
40
+ MIDDLEWARE_SR_PREFIX_ERROR: "Error. ",
39
41
  PREVIOUS_MESSAGES_LOADING: "Loading previous messages...",
40
42
  CONVERSATION_DIVIDER_ARIA_LABEL: "Conversation history divider"
41
43
  };
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.patchCitationAnchorsForA11y = void 0;
7
+ // Accessibility helper: Merges WebChat's citation card number badge and link
8
+ // text into a single focusable element.
9
+ //
10
+ // WebChat's LinkDefinitionItem renders an <a> containing a badge <div> (number)
11
+ // and a text <div> (title). On iOS VoiceOver, these block-level descendants are
12
+ // announced as two separate focusable links (e.g. "1, link" and
13
+ // "Assessment of eligibility..., link"). Setting a combined aria-label on the
14
+ // anchor and hiding inner descendants from the accessibility tree ensures the
15
+ // whole card is announced as one link.
16
+
17
+ const CITATION_ANCHOR_SELECTOR = "a.webchat__link-definitions__list-item-box";
18
+ const PATCHED_MARKER = "ocwCitationA11yPatched";
19
+ const STYLE_TAG_ID = "ocw-citation-a11y-styles";
20
+
21
+ // Global CSS injected once per document. Neutralizes iOS Safari's per-inner-
22
+ // element tap highlight / selection / focus rectangles that otherwise make
23
+ // the "1" badge and the link text appear as separate selectable areas even
24
+ // though they are inside a single <a>.
25
+ // Strategy:
26
+ // - Make the anchor a block-level positioning parent.
27
+ // - Add a transparent ::after pseudo-element that covers the entire anchor.
28
+ // iOS Safari hit-tests that overlay as a SINGLE region, so the tap
29
+ // highlight / selection rectangle always covers the whole card instead
30
+ // of just the "1" badge or just the link text.
31
+ // - Make every descendant transparent to pointer / focus, so they can never
32
+ // become a standalone tap target.
33
+ const STYLE_RULES = `
34
+ a.webchat__link-definitions__list-item-box {
35
+ position: relative;
36
+ display: block;
37
+ isolation: isolate;
38
+ -webkit-tap-highlight-color: rgba(0, 120, 212, 0.15);
39
+ -webkit-touch-callout: none;
40
+ cursor: pointer;
41
+ }
42
+ a.webchat__link-definitions__list-item-box::after {
43
+ content: "";
44
+ position: absolute;
45
+ inset: 0;
46
+ z-index: 2;
47
+ background: transparent;
48
+ pointer-events: auto;
49
+ -webkit-tap-highlight-color: rgba(0, 120, 212, 0.15);
50
+ }
51
+ a.webchat__link-definitions__list-item-box * {
52
+ pointer-events: none;
53
+ -webkit-tap-highlight-color: transparent;
54
+ -webkit-touch-callout: none;
55
+ outline: none;
56
+ text-decoration: inherit;
57
+ cursor: inherit;
58
+ }
59
+ `;
60
+ const ensureStyleInjected = doc => {
61
+ if (!doc || typeof doc.getElementById !== "function" || doc.getElementById(STYLE_TAG_ID)) {
62
+ return;
63
+ }
64
+ const style = doc.createElement("style");
65
+ style.id = STYLE_TAG_ID;
66
+ style.textContent = STYLE_RULES;
67
+ (doc.head || doc.documentElement).appendChild(style);
68
+ };
69
+ const patchCitationAnchorsForA11y = root => {
70
+ var _defaultView;
71
+ if (!root || typeof root.querySelectorAll !== "function") {
72
+ return;
73
+ }
74
+
75
+ // Inject global CSS once per document. This covers every citation anchor
76
+ // regardless of whether our per-node patch has run on it yet.
77
+ const rootNode = root;
78
+ const doc = rootNode.ownerDocument ?? ((_defaultView = root.defaultView) === null || _defaultView === void 0 ? void 0 : _defaultView.document) ?? root ?? (typeof document !== "undefined" ? document : null);
79
+ if (doc && typeof doc.createElement === "function") {
80
+ ensureStyleInjected(doc);
81
+ }
82
+
83
+ // Also include the root itself when it matches — calls from MutationObserver
84
+ // pass the anchor element directly, which querySelectorAll wouldn't return.
85
+ const matched = new Set();
86
+ if (typeof root.matches === "function" && root.matches(CITATION_ANCHOR_SELECTOR)) {
87
+ matched.add(root);
88
+ }
89
+ root.querySelectorAll(CITATION_ANCHOR_SELECTOR).forEach(n => {
90
+ matched.add(n);
91
+ });
92
+ matched.forEach(anchor => {
93
+ var _badge$textContent, _textEl$textContent;
94
+ const badge = anchor.querySelector(".webchat__link-definitions__badge");
95
+ const textEl = anchor.querySelector(".webchat__link-definitions__list-item-text");
96
+ const identifier = (badge === null || badge === void 0 ? void 0 : (_badge$textContent = badge.textContent) === null || _badge$textContent === void 0 ? void 0 : _badge$textContent.trim()) ?? "";
97
+ // Prefer the explicit text element. For plain (non-card) citation anchors
98
+ // (no badge), fall back to the title or the anchor's own text. When a
99
+ // badge is present but no text element, avoid using anchor.textContent
100
+ // since it would duplicate the identifier.
101
+ let text = (textEl === null || textEl === void 0 ? void 0 : (_textEl$textContent = textEl.textContent) === null || _textEl$textContent === void 0 ? void 0 : _textEl$textContent.trim()) ?? "";
102
+ if (!text && !badge) {
103
+ var _anchor$getAttribute, _anchor$textContent;
104
+ text = ((_anchor$getAttribute = anchor.getAttribute("title")) === null || _anchor$getAttribute === void 0 ? void 0 : _anchor$getAttribute.trim()) || ((_anchor$textContent = anchor.textContent) === null || _anchor$textContent === void 0 ? void 0 : _anchor$textContent.trim()) || "";
105
+ }
106
+ if (!identifier && !text) {
107
+ return;
108
+ }
109
+ const combinedLabel = identifier && text ? `${identifier}, ${text}` : identifier || text;
110
+
111
+ // Always (re-)apply aria-label if absent. Setting it again with the same
112
+ // value when it already matches is a no-op for the DOM; this keeps the
113
+ // patch idempotent so React re-renders that strip the attribute heal.
114
+ const existingLabel = anchor.getAttribute("aria-label");
115
+ if (!existingLabel) {
116
+ anchor.setAttribute("aria-label", combinedLabel);
117
+ }
118
+
119
+ // Explicitly mark the anchor as a single link so iOS VoiceOver treats
120
+ // the whole card as one element.
121
+ if (!anchor.getAttribute("role")) {
122
+ anchor.setAttribute("role", "link");
123
+ }
124
+
125
+ // Nuclear a11y lockdown of EVERY descendant of the anchor (not just
126
+ // known class names, because WebChat can render additional nodes).
127
+ // iOS VoiceOver is known to split focus on block-level descendants
128
+ // inside an <a>. Applying all of the following guarantees only the
129
+ // outer <a> is a selectable a11y / focus target:
130
+ // - aria-hidden="true" removes element from the a11y tree
131
+ // - role="presentation" strips any implicit semantic role
132
+ // - inert removes element from focus + interaction
133
+ // - tabindex="-1" defensive (covers browsers without inert)
134
+ // - title removed iOS VoiceOver in WKWebView still surfaces
135
+ // elements with a `title` attribute as a
136
+ // separately swipeable item even when
137
+ // aria-hidden=true. WebChat's ItemBody sets
138
+ // title={text} on the inner link-text div,
139
+ // which is the root cause of the "two
140
+ // separate links" announcement on iOS.
141
+ // We move the title to a data-* attribute
142
+ // so any tooltip-like tooling can still
143
+ // read it, but iOS VO ignores it.
144
+ anchor.querySelectorAll("*").forEach(el => {
145
+ const inner = el;
146
+ if (inner.getAttribute("aria-hidden") !== "true") {
147
+ inner.setAttribute("aria-hidden", "true");
148
+ }
149
+ if (inner.getAttribute("role") !== "presentation") {
150
+ inner.setAttribute("role", "presentation");
151
+ }
152
+ if (inner.getAttribute("tabindex") !== "-1") {
153
+ inner.setAttribute("tabindex", "-1");
154
+ }
155
+ if (!inner.hasAttribute("inert")) {
156
+ inner.setAttribute("inert", "");
157
+ }
158
+ const innerTitle = inner.getAttribute("title");
159
+ if (innerTitle !== null) {
160
+ inner.removeAttribute("title");
161
+ if (!inner.dataset.ocwOriginalTitle) {
162
+ inner.dataset.ocwOriginalTitle = innerTitle;
163
+ }
164
+ }
165
+ if (inner.style.pointerEvents !== "none") {
166
+ inner.style.pointerEvents = "none";
167
+ }
168
+ });
169
+
170
+ // DOM-level full-bleed overlay. Inline styles are used so this works
171
+ // even when the widget renders inside a shadow DOM (where an
172
+ // injected <style> tag in document.head cannot reach). The overlay
173
+ // becomes the ONLY visible hit-test target for iOS Safari, so tapping
174
+ // anywhere on the card highlights the entire card instead of just the
175
+ // "1" badge or just the link text.
176
+ const anchorStyle = anchor.style;
177
+ if (!anchorStyle.position) {
178
+ anchorStyle.position = "relative";
179
+ }
180
+ if (!anchorStyle.display || anchorStyle.display === "inline") {
181
+ anchorStyle.display = "block";
182
+ }
183
+ const ownerDoc = anchor.ownerDocument;
184
+ const existingOverlay = anchor.querySelector(":scope > [data-ocw-citation-overlay='true']");
185
+ if (!existingOverlay && ownerDoc && typeof ownerDoc.createElement === "function") {
186
+ const overlay = ownerDoc.createElement("span");
187
+ overlay.setAttribute("aria-hidden", "true");
188
+ overlay.setAttribute("data-ocw-citation-overlay", "true");
189
+ overlay.style.cssText = ["position:absolute", "top:0", "left:0", "right:0", "bottom:0", "z-index:2", "background:transparent", "pointer-events:auto", "-webkit-tap-highlight-color:rgba(0,120,212,0.15)", "-webkit-touch-callout:none", "-webkit-user-select:none", "user-select:none", "cursor:pointer"].join(";");
190
+ anchor.appendChild(overlay);
191
+ }
192
+ anchor.dataset[PATCHED_MARKER] = "true";
193
+ });
194
+ };
195
+ exports.patchCitationAnchorsForA11y = patchCitationAnchorsForA11y;
@@ -32,6 +32,21 @@ const AdaptiveCardAccessibilityWrapper = _ref => {
32
32
  const container = containerRef.current;
33
33
  if (!container) return;
34
34
 
35
+ // action-button-toggle / login-button-toggle: submit/login action buttons can be
36
+ // rendered with toggle-only ARIA that causes screen readers to announce them as
37
+ // switches instead of plain push buttons. Preserve Action.ToggleVisibility buttons,
38
+ // which own aria-controls and legitimately expose a pressed state.
39
+ const actionButtons = container.querySelectorAll(".ac-actionSet button.ac-pushButton:not([aria-controls])");
40
+ actionButtons.forEach(btn => {
41
+ if (btn.hasAttribute("aria-pressed")) {
42
+ btn.removeAttribute("aria-pressed");
43
+ }
44
+ const role = btn.getAttribute("role");
45
+ if (role === "switch") {
46
+ btn.removeAttribute("role");
47
+ }
48
+ });
49
+
35
50
  // Find all radio inputs inside the adaptive card
36
51
  const radios = container.querySelectorAll("input[type='radio']");
37
52
  if (radios.length === 0) return;
@@ -14,8 +14,11 @@ var _TelemetryConstants = require("../../../../common/telemetry/TelemetryConstan
14
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
15
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
16
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
18
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
19
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
+ const LIVE_REGION_ID = "oc-lcw-notification-live-region";
21
+ const LIVE_REGION_CLEAR_DELAY_MS = 1000;
19
22
  let NotificationHandler = /*#__PURE__*/function () {
20
23
  function NotificationHandler() {
21
24
  _classCallCheck(this, NotificationHandler);
@@ -32,9 +35,59 @@ let NotificationHandler = /*#__PURE__*/function () {
32
35
  message
33
36
  }
34
37
  });
38
+ NotificationHandler.announceToScreenReader(message);
35
39
  NotificationHandler.setFocusOnNotificationCloseButton();
36
40
  }
37
41
  }
42
+
43
+ /**
44
+ * Announces a message immediately to screen readers via an aria-live="assertive" region.
45
+ * This ensures notifications interrupt the current screen reader output
46
+ * instead of waiting for it to finish reading other content.
47
+ */
48
+ }, {
49
+ key: "announceToScreenReader",
50
+ value: function announceToScreenReader(message) {
51
+ let liveRegion = document.getElementById(LIVE_REGION_ID);
52
+ if (!liveRegion) {
53
+ liveRegion = document.createElement("div");
54
+ liveRegion.id = LIVE_REGION_ID;
55
+ liveRegion.setAttribute("aria-live", "assertive");
56
+ liveRegion.setAttribute("role", "alert");
57
+ liveRegion.setAttribute("aria-atomic", "true");
58
+ // Visually hidden but accessible to screen readers
59
+ liveRegion.style.position = "absolute";
60
+ liveRegion.style.width = "1px";
61
+ liveRegion.style.height = "1px";
62
+ liveRegion.style.overflow = "hidden";
63
+ liveRegion.style.clip = "rect(0 0 0 0)";
64
+ liveRegion.style.clipPath = "inset(50%)";
65
+ liveRegion.style.whiteSpace = "nowrap";
66
+ const widgetContainer = document.getElementById(_Constants.HtmlIdNames.MSLiveChatWidget);
67
+ (widgetContainer || document.body).appendChild(liveRegion);
68
+ }
69
+
70
+ // Clear first, then set after a microtask so the browser detects the change
71
+ // even when the same message is announced consecutively.
72
+ liveRegion.textContent = "";
73
+ requestAnimationFrame(() => {
74
+ if (liveRegion) {
75
+ liveRegion.textContent = message;
76
+ }
77
+ });
78
+
79
+ // Cancel any previous clear timer to avoid prematurely clearing a newer message
80
+ if (NotificationHandler.clearTimeoutId) {
81
+ clearTimeout(NotificationHandler.clearTimeoutId);
82
+ }
83
+
84
+ // Clear the live region after a delay so repeated identical messages still trigger
85
+ NotificationHandler.clearTimeoutId = setTimeout(() => {
86
+ if (liveRegion) {
87
+ liveRegion.textContent = "";
88
+ }
89
+ }, LIVE_REGION_CLEAR_DELAY_MS);
90
+ }
38
91
  }, {
39
92
  key: "dismissNotification",
40
93
  value: function dismissNotification(id) {
@@ -109,4 +162,5 @@ let NotificationHandler = /*#__PURE__*/function () {
109
162
  }]);
110
163
  return NotificationHandler;
111
164
  }();
112
- exports.NotificationHandler = NotificationHandler;
165
+ exports.NotificationHandler = NotificationHandler;
166
+ _defineProperty(NotificationHandler, "clearTimeoutId", void 0);