@pega/lists-react 10.0.0-build.16.3 → 10.0.0-build.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"RenderView.d.ts","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAoBlE,iBAAS,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,WAAW,CAAC,IAAI,CAAA;CAAE,kDAW3F;;AAED,wBAAgC"}
1
+ {"version":3,"file":"RenderView.d.ts","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AA4BlE,iBAAS,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,WAAW,CAAC,IAAI,CAAA;CAAE,kDAW3F;;AAED,wBAAgC"}
@@ -13,6 +13,14 @@ const StyledDiv = styled.div(({ theme }) => {
13
13
  &:has(> span > *) {
14
14
  margin-block: ${theme.base.spacing};
15
15
  }
16
+
17
+ // Many filters scroll within a capped area instead of crowding out the results (e.g. on browser zoom).
18
+ // position: relative contains absolutely positioned helper text (e.g. screen-reader hints) so it is clipped here instead of stretching the scroll height of the table container.
19
+ // flex-shrink: 0 stops the flex parent from squeezing the slot below its cap on short cards, as overflow makes its min-height 0.
20
+ position: relative;
21
+ flex-shrink: 0;
22
+ max-block-size: 10rem;
23
+ overflow-y: auto;
16
24
  `;
17
25
  });
18
26
  StyledDiv.defaultProps = defaultThemeProp;
@@ -1 +1 @@
1
- {"version":3,"file":"RenderView.js","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qEAAqE;AACrE,aAAa;AAEb,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACzC,OAAO;;;;;sBAKa,KAAK,CAAC,IAAI,CAAC,OAAO;;GAErC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAC1C,SAAS,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAA4D;IAC1F,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU,EAAE;QACf,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,IAAI;KACL,CAAC;IAEF,MAAM,YAAY,GAAG,oBAAoB,CAAC,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAE9E,OAAO,YAAY,CAAC,CAAC,CAAC,KAAC,SAAS,oBAAe,IAAI,YAAG,YAAY,GAAa,CAAC,CAAC,CAAC,IAAI,CAAC;AACzF,CAAC;AAED,eAAe,IAAI,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { memo } from 'react';\nimport styled from 'styled-components';\n\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\n// TODO remove ts-ignore once ComponentResolverFactory migrated to TS\n// @ts-ignore\n\nimport { resolveViewComponent } from './ComponentResolverFactory';\n\nconst StyledDiv = styled.div(({ theme }) => {\n return `\n // FIXME: Ideally, the meta passed to the table should reflect whether the PromotedFilters are configured or not. But, currently RS doesn't support change in meta after load.\n // Handling it via CSS for now. Once meta update is possible in RS, the consumer of RS should make sure that correct externalFilters are set in meta.\n // Add margin only if some content is rendered in render view. Adding span as RS by default injects a span for external renderers.\n &:has(> span > *) {\n margin-block: ${theme.base.spacing};\n }\n `;\n});\n\nStyledDiv.defaultProps = defaultThemeProp;\nfunction RenderView({ view, type }: { view: RsCoreTypes.View; type: keyof RsCoreTypes.Meta }) {\n const { state, meta, getContext, renderFactory, rsID } = view;\n const engineContext = {\n ...getContext(),\n [String(meta[type])]: state?.externalState?.[String(meta[type])],\n rsID\n };\n\n const resolvedView = resolveViewComponent(type, renderFactory, engineContext);\n\n return resolvedView ? <StyledDiv data-test-id={type}>{resolvedView}</StyledDiv> : null;\n}\n\nexport default memo(RenderView);\n"]}
1
+ {"version":3,"file":"RenderView.js","sourceRoot":"","sources":["../../../../Core/Components/RenderingEngine/RenderView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qEAAqE;AACrE,aAAa;AAEb,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACzC,OAAO;;;;;sBAKa,KAAK,CAAC,IAAI,CAAC,OAAO;;;;;;;;;;GAUrC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAC1C,SAAS,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAA4D;IAC1F,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAC9D,MAAM,aAAa,GAAG;QACpB,GAAG,UAAU,EAAE;QACf,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,IAAI;KACL,CAAC;IAEF,MAAM,YAAY,GAAG,oBAAoB,CAAC,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IAE9E,OAAO,YAAY,CAAC,CAAC,CAAC,KAAC,SAAS,oBAAe,IAAI,YAAG,YAAY,GAAa,CAAC,CAAC,CAAC,IAAI,CAAC;AACzF,CAAC;AAED,eAAe,IAAI,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { memo } from 'react';\nimport styled from 'styled-components';\n\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\n// TODO remove ts-ignore once ComponentResolverFactory migrated to TS\n// @ts-ignore\n\nimport { resolveViewComponent } from './ComponentResolverFactory';\n\nconst StyledDiv = styled.div(({ theme }) => {\n return `\n // FIXME: Ideally, the meta passed to the table should reflect whether the PromotedFilters are configured or not. But, currently RS doesn't support change in meta after load.\n // Handling it via CSS for now. Once meta update is possible in RS, the consumer of RS should make sure that correct externalFilters are set in meta.\n // Add margin only if some content is rendered in render view. Adding span as RS by default injects a span for external renderers.\n &:has(> span > *) {\n margin-block: ${theme.base.spacing};\n }\n\n // Many filters scroll within a capped area instead of crowding out the results (e.g. on browser zoom).\n // position: relative contains absolutely positioned helper text (e.g. screen-reader hints) so it is clipped here instead of stretching the scroll height of the table container.\n // flex-shrink: 0 stops the flex parent from squeezing the slot below its cap on short cards, as overflow makes its min-height 0.\n position: relative;\n flex-shrink: 0;\n max-block-size: 10rem;\n overflow-y: auto;\n `;\n});\n\nStyledDiv.defaultProps = defaultThemeProp;\nfunction RenderView({ view, type }: { view: RsCoreTypes.View; type: keyof RsCoreTypes.Meta }) {\n const { state, meta, getContext, renderFactory, rsID } = view;\n const engineContext = {\n ...getContext(),\n [String(meta[type])]: state?.externalState?.[String(meta[type])],\n rsID\n };\n\n const resolvedView = resolveViewComponent(type, renderFactory, engineContext);\n\n return resolvedView ? <StyledDiv data-test-id={type}>{resolvedView}</StyledDiv> : null;\n}\n\nexport default memo(RenderView);\n"]}
@@ -5,10 +5,35 @@ export type Selectors = {
5
5
  belowLoader: string;
6
6
  };
7
7
  type AnnounceMethod = ReturnType<typeof useLiveLog>['announceAssertive'];
8
+ /**
9
+ * Gallery cards are a single tab stop: Tab moves focus to the last focused card (or to the first/last
10
+ * card when the gallery has not had focus yet) and the arrow keys move focus between cards.
11
+ */
8
12
  declare class GalleryA11y extends BaseA11y {
9
13
  #private;
10
14
  constructor(selectors: Selectors, focusableSelectors: string[], container: HTMLElement, announceAssertive: AnnounceMethod, announcePolite: AnnounceMethod, translate: (key: string) => string);
15
+ dispose(): void;
16
+ /**
17
+ * Makes the active card the only card in the tab order. The active card is the last focused card,
18
+ * or the first card when the gallery has not had focus yet or that card is no longer rendered.
19
+ */
20
+ syncTabStops(): void;
21
+ /**
22
+ * Moves focus between cards with the arrow keys. Keys pressed on elements inside a card are ignored
23
+ * so that they keep working for the card content. Loading more records is left to the virtualizer,
24
+ * which loads them when the focused card scrolls into view near the edge of the loaded records.
25
+ */
26
+ keyDownHandler(event: KeyboardEvent): void;
11
27
  onFocusHandler(event?: Event): void;
28
+ onBlurHandler(event: FocusEvent): void;
29
+ /**
30
+ * Runs after every Gallery render, like the table's. Announces that loading completed, keeps a
31
+ * single card in the tab order and restores focus if the focused card was removed.
32
+ *
33
+ * Cosmos cards update their own tabindex in effects and a second render pass, which can happen
34
+ * after the Gallery's effect and make cards tabbable again. So the tab order and the focus are
35
+ * checked once more after the next frame.
36
+ */
12
37
  itemsLoadedCallback(): void;
13
38
  }
14
39
  export default GalleryA11y;
@@ -1 +1 @@
1
- {"version":3,"file":"GalleryA11y.d.ts","sourceRoot":"","sources":["../../../../Core/Views/Gallery/GalleryA11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D,MAAM,MAAM,SAAS,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,mBAAmB,CAAC,CAAC;AAEzE,cAAM,WAAY,SAAQ,QAAQ;;gBAI9B,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,MAAM,EAAE,EAC5B,SAAS,EAAE,WAAW,EACtB,iBAAiB,EAAE,cAAc,EACjC,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM;IAY3B,cAAc,CAAC,KAAK,CAAC,EAAE,KAAK;IAIrC,mBAAmB;CAGpB;AAED,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"GalleryA11y.d.ts","sourceRoot":"","sources":["../../../../Core/Views/Gallery/GalleryA11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D,MAAM,MAAM,SAAS,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,mBAAmB,CAAC,CAAC;AA6EzE;;;GAGG;AACH,cAAM,WAAY,SAAQ,QAAQ;;gBAU9B,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,MAAM,EAAE,EAC5B,SAAS,EAAE,WAAW,EACtB,iBAAiB,EAAE,cAAc,EACjC,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM;IAYpC,OAAO;IAOP;;;OAGG;IACH,YAAY;IAkBZ;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,aAAa;IA6B1B,cAAc,CAAC,KAAK,CAAC,EAAE,KAAK;IAqB5B,aAAa,CAAC,KAAK,EAAE,UAAU;IAgBxC;;;;;;;OAOG;IACH,mBAAmB;CAgEpB;AAED,eAAe,WAAW,CAAC"}
@@ -1,16 +1,228 @@
1
1
  import { BaseA11y } from 'pega-repeating-structures-core';
2
+ import { getActiveElement, isInstance } from '@pega/cosmos-react-core';
2
3
  import createLoadingAnnouncementBehavior from '../../a11y/loadingAnnouncementBehavior';
4
+ const TAB_INDEX = 'tabindex';
5
+ const CARD_KEY_ATTRIBUTE = 'data-key';
6
+ // Set by the virtualizer on every card, it is the position of the card in all the records
7
+ const CARD_INDEX_ATTRIBUTE = 'data-index';
8
+ const MAIN_FOCUS_SELECTOR = '[data-main-focus]';
9
+ // Cards in the same grid row can differ by a sub-pixel amount.
10
+ const ROW_TOP_TOLERANCE = 1;
11
+ const HORIZONTAL_KEYS = ['ArrowLeft', 'ArrowRight'];
12
+ const VERTICAL_KEYS = ['ArrowUp', 'ArrowDown'];
13
+ function isForwardNavigationKey(key) {
14
+ return key === 'ArrowDown' || key === 'ArrowRight';
15
+ }
16
+ /**
17
+ * Returns the element that receives keyboard focus in a card. It is the card itself, except when its
18
+ * only focusable content is an input such as a checkbox: cosmos then makes the input the focus
19
+ * element and marks it with `data-main-focus`. Using the card there would make Tab stop on every
20
+ * checkbox, and the arrow keys would not move between those cards.
21
+ */
22
+ function getTabTarget(card) {
23
+ return card.matches(MAIN_FOCUS_SELECTOR)
24
+ ? card
25
+ : card.querySelector(MAIN_FOCUS_SELECTOR) ?? card;
26
+ }
27
+ /**
28
+ * Finds the card in the row below (ArrowDown) or above (ArrowUp) the current card, the one whose left
29
+ * edge is closest to the current card's. Cards are in DOM order, which is the order they are displayed
30
+ * in. The search starts at the current card and ends with the adjacent row, so only the cards of these
31
+ * two rows are measured.
32
+ *
33
+ * @param cards - All cards, in DOM order.
34
+ * @param currentIndex - Index of the card that currently has focus.
35
+ * @param key - ArrowDown to look at the row below the current card, ArrowUp to look at the row above it.
36
+ * @returns The index of that card, or null when there is no row in that direction.
37
+ */
38
+ function findCardIndexToFocusInAdjacentRow(cards, currentIndex, key) {
39
+ const step = key === 'ArrowDown' ? 1 : -1;
40
+ const { top: currentFocusedCardTop, left: currentFocusedCardLeft } = cards[currentIndex].getBoundingClientRect();
41
+ const areCardsInSameRow = (top, rowTop) => Math.abs(top - rowTop) <= ROW_TOP_TOLERANCE;
42
+ let adjacentRowTop = null;
43
+ let closestIndex = null;
44
+ let closestDistance = Infinity;
45
+ for (let index = currentIndex + step; index >= 0 && index < cards.length; index += step) {
46
+ const { top, left } = cards[index].getBoundingClientRect();
47
+ // The first card outside the current row starts the adjacent row
48
+ if (adjacentRowTop === null && !areCardsInSameRow(top, currentFocusedCardTop))
49
+ adjacentRowTop = top;
50
+ if (adjacentRowTop !== null) {
51
+ if (!areCardsInSameRow(top, adjacentRowTop))
52
+ break;
53
+ const distance = Math.abs(left - currentFocusedCardLeft);
54
+ if (distance < closestDistance) {
55
+ closestIndex = index;
56
+ closestDistance = distance;
57
+ }
58
+ }
59
+ }
60
+ return closestIndex;
61
+ }
62
+ /**
63
+ * Gallery cards are a single tab stop: Tab moves focus to the last focused card (or to the first/last
64
+ * card when the gallery has not had focus yet) and the arrow keys move focus between cards.
65
+ */
3
66
  class GalleryA11y extends BaseA11y {
4
67
  #loadingAnnouncement;
68
+ #activeCardKey = null;
69
+ #activeCardIndex = null;
70
+ #settleFrame = null;
5
71
  constructor(selectors, focusableSelectors, container, announceAssertive, announcePolite, translate) {
6
72
  super(selectors, focusableSelectors, {}, container);
7
73
  this.#loadingAnnouncement = createLoadingAnnouncementBehavior(selectors, container, announceAssertive, announcePolite, translate);
8
74
  }
75
+ dispose() {
76
+ if (this.#settleFrame !== null) {
77
+ cancelAnimationFrame(this.#settleFrame);
78
+ this.#settleFrame = null;
79
+ }
80
+ }
81
+ /**
82
+ * Makes the active card the only card in the tab order. The active card is the last focused card,
83
+ * or the first card when the gallery has not had focus yet or that card is no longer rendered.
84
+ */
85
+ syncTabStops() {
86
+ const cards = this.#getCards();
87
+ const rememberedCard = cards.find(card => card.getAttribute(CARD_KEY_ATTRIBUTE) === this.#activeCardKey);
88
+ const activeCard = rememberedCard ?? cards[0];
89
+ // The position of a card changes when records before it are added or removed
90
+ if (rememberedCard)
91
+ this.#activeCardIndex = rememberedCard.getAttribute(CARD_INDEX_ATTRIBUTE);
92
+ cards.forEach(card => {
93
+ const tabIndex = card === activeCard ? '0' : '-1';
94
+ const tabTarget = getTabTarget(card);
95
+ if (tabTarget.getAttribute(TAB_INDEX) !== tabIndex) {
96
+ tabTarget.setAttribute(TAB_INDEX, tabIndex);
97
+ }
98
+ });
99
+ }
100
+ /**
101
+ * Moves focus between cards with the arrow keys. Keys pressed on elements inside a card are ignored
102
+ * so that they keep working for the card content. Loading more records is left to the virtualizer,
103
+ * which loads them when the focused card scrolls into view near the edge of the loaded records.
104
+ */
105
+ keyDownHandler(event) {
106
+ const { key } = event;
107
+ const isArrowKey = HORIZONTAL_KEYS.includes(key) || VERTICAL_KEYS.includes(key);
108
+ const hasModifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
109
+ if (event.defaultPrevented || hasModifierKey || !isArrowKey)
110
+ return;
111
+ const cards = this.#getCards();
112
+ const currentIndex = cards.findIndex(card => getTabTarget(card) === event.target);
113
+ if (currentIndex === -1)
114
+ return;
115
+ // Arrow keys would otherwise scroll the gallery.
116
+ event.preventDefault();
117
+ const isForwardNavigation = isForwardNavigationKey(key);
118
+ const step = isForwardNavigation ? 1 : -1;
119
+ let targetIndex = currentIndex + step;
120
+ if (VERTICAL_KEYS.includes(key)) {
121
+ // With no row above or below, focus stays on the current card
122
+ targetIndex = findCardIndexToFocusInAdjacentRow(cards, currentIndex, key) ?? currentIndex;
123
+ }
124
+ if (targetIndex >= 0 && targetIndex < cards.length && targetIndex !== currentIndex) {
125
+ this.#focusCard(cards[targetIndex]);
126
+ }
127
+ }
9
128
  onFocusHandler(event) {
129
+ // Records that the gallery has focus, to restore it if the focused card is removed
130
+ super.onFocusHandler();
10
131
  this.#loadingAnnouncement.onFocus(event);
132
+ const target = event?.target;
133
+ if (!isInstance(target, Element))
134
+ return;
135
+ const card = target.closest(this.selectors.focusElementSelector);
136
+ if (!card || !this.container.contains(card))
137
+ return;
138
+ if (this.#activeCardKey === null && this.#isReverseTabEntry(event, target)) {
139
+ const cards = this.#getCards();
140
+ const lastCard = cards[cards.length - 1];
141
+ if (lastCard !== card) {
142
+ this.#focusCard(lastCard);
143
+ return;
144
+ }
145
+ }
146
+ this.#setActiveCard(card);
11
147
  }
148
+ onBlurHandler(event) {
149
+ const { target, relatedTarget } = event;
150
+ if (relatedTarget === null && isInstance(target, Node)) {
151
+ // Chromium dispatches blur when the focused card is removed, other browsers do not. Only a card
152
+ // that is still rendered once the removal has completed was really blurred.
153
+ queueMicrotask(() => {
154
+ if (target.isConnected)
155
+ this.focusState.hadFocus = false;
156
+ });
157
+ return;
158
+ }
159
+ // event.currentTarget is not the gallery when the event comes from React (it is the React root)
160
+ if (!isInstance(relatedTarget, Node) || !this.container.contains(relatedTarget)) {
161
+ this.focusState.hadFocus = false;
162
+ }
163
+ }
164
+ /**
165
+ * Runs after every Gallery render, like the table's. Announces that loading completed, keeps a
166
+ * single card in the tab order and restores focus if the focused card was removed.
167
+ *
168
+ * Cosmos cards update their own tabindex in effects and a second render pass, which can happen
169
+ * after the Gallery's effect and make cards tabbable again. So the tab order and the focus are
170
+ * checked once more after the next frame.
171
+ */
12
172
  itemsLoadedCallback() {
13
173
  this.#loadingAnnouncement.onItemsLoaded();
174
+ this.syncTabStops();
175
+ if (this.#settleFrame !== null)
176
+ cancelAnimationFrame(this.#settleFrame);
177
+ this.#settleFrame = requestAnimationFrame(() => {
178
+ this.#settleFrame = null;
179
+ this.syncTabStops();
180
+ this.#restoreFocusIfLost();
181
+ });
182
+ }
183
+ /**
184
+ * When the focused card is removed (for example after deleting it), focus falls back to the body.
185
+ * Unless it had already left the gallery, focus is restored to the first of these that exists, like
186
+ * in the table: the same card (it can have moved), the card that is now at the same position, the
187
+ * last card. Focus on any other element was moved there on purpose and is left alone.
188
+ */
189
+ #restoreFocusIfLost() {
190
+ if (!this.focusState.hadFocus || getActiveElement() !== document.body)
191
+ return;
192
+ const cards = this.#getCards();
193
+ const card = cards.find(candidate => candidate.getAttribute(CARD_KEY_ATTRIBUTE) === this.#activeCardKey) ??
194
+ cards.find(candidate => this.#activeCardIndex !== null &&
195
+ candidate.getAttribute(CARD_INDEX_ATTRIBUTE) === this.#activeCardIndex) ??
196
+ cards[cards.length - 1];
197
+ if (card)
198
+ this.#focusCard(card);
199
+ }
200
+ #getCards() {
201
+ return Array.from(this.container.querySelectorAll(this.selectors.focusElementSelector));
202
+ }
203
+ #setActiveCard(card) {
204
+ this.#activeCardKey = card.getAttribute(CARD_KEY_ATTRIBUTE);
205
+ this.#activeCardIndex = card.getAttribute(CARD_INDEX_ATTRIBUTE);
206
+ this.syncTabStops();
207
+ }
208
+ #focusCard(card) {
209
+ this.#setActiveCard(card);
210
+ getTabTarget(card).focus();
211
+ }
212
+ /**
213
+ * True when focus moved into the gallery with Shift+Tab from an element after it.
214
+ * Pointer focus is excluded through `:focus-visible`.
215
+ */
216
+ #isReverseTabEntry(event, target) {
217
+ if (!isInstance(event, FocusEvent))
218
+ return false;
219
+ const { relatedTarget } = event;
220
+ if (!isInstance(relatedTarget, Node) || this.container.contains(relatedTarget))
221
+ return false;
222
+ const position = this.container.compareDocumentPosition(relatedTarget);
223
+ // eslint-disable-next-line no-bitwise
224
+ const isAfterGallery = (position & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
225
+ return isAfterGallery && target.matches(':focus-visible');
14
226
  }
15
227
  }
16
228
  export default GalleryA11y;
@@ -1 +1 @@
1
- {"version":3,"file":"GalleryA11y.js","sourceRoot":"","sources":["../../../../Core/Views/Gallery/GalleryA11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAG1D,OAAO,iCAAiC,MAAM,wCAAwC,CAAC;AASvF,MAAM,WAAY,SAAQ,QAAQ;IAChC,oBAAoB,CAAuD;IAE3E,YACE,SAAoB,EACpB,kBAA4B,EAC5B,SAAsB,EACtB,iBAAiC,EACjC,cAA8B,EAC9B,SAAkC;QAElC,KAAK,CAAC,SAAS,EAAE,kBAAkB,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QACpD,IAAI,CAAC,oBAAoB,GAAG,iCAAiC,CAC3D,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,SAAS,CACV,CAAC;IACJ,CAAC;IAEQ,cAAc,CAAC,KAAa;QACnC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,mBAAmB;QACjB,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,CAAC;IAC5C,CAAC;CACF;AAED,eAAe,WAAW,CAAC","sourcesContent":["import { BaseA11y } from 'pega-repeating-structures-core';\nimport type { useLiveLog } from '@pega/cosmos-react-core';\n\nimport createLoadingAnnouncementBehavior from '../../a11y/loadingAnnouncementBehavior';\n\nexport type Selectors = {\n focusElementSelector: string;\n belowLoader: string;\n};\n\ntype AnnounceMethod = ReturnType<typeof useLiveLog>['announceAssertive'];\n\nclass GalleryA11y extends BaseA11y {\n #loadingAnnouncement: ReturnType<typeof createLoadingAnnouncementBehavior>;\n\n constructor(\n selectors: Selectors,\n focusableSelectors: string[],\n container: HTMLElement,\n announceAssertive: AnnounceMethod,\n announcePolite: AnnounceMethod,\n translate: (key: string) => string\n ) {\n super(selectors, focusableSelectors, {}, container);\n this.#loadingAnnouncement = createLoadingAnnouncementBehavior(\n selectors,\n container,\n announceAssertive,\n announcePolite,\n translate\n );\n }\n\n override onFocusHandler(event?: Event) {\n this.#loadingAnnouncement.onFocus(event);\n }\n\n itemsLoadedCallback() {\n this.#loadingAnnouncement.onItemsLoaded();\n }\n}\n\nexport default GalleryA11y;\n"]}
1
+ {"version":3,"file":"GalleryA11y.js","sourceRoot":"","sources":["../../../../Core/Views/Gallery/GalleryA11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,iCAAiC,MAAM,wCAAwC,CAAC;AASvF,MAAM,SAAS,GAAG,UAAU,CAAC;AAC7B,MAAM,kBAAkB,GAAG,UAAU,CAAC;AACtC,0FAA0F;AAC1F,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAC1C,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAChD,+DAA+D;AAC/D,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AACpD,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAE/C,SAAS,sBAAsB,CAAC,GAAW;IACzC,OAAO,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,YAAY,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAiB;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;QACtC,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,CAAC,aAAa,CAAc,mBAAmB,CAAC,IAAI,IAAI,CAAC;AACnE,CAAC;AA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AuB,CAAC,aAAa,CAAC,CAAC;QACvE,sCAAsC;QACtC,MAAM,cAAc,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO,cAAc,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,CAAC;CACF;AAED,eAAe,WAAW,CAAC","sourcesContent":["import { BaseA11y } from 'pega-repeating-structures-core';\nimport { getActiveElement, isInstance } from '@pega/cosmos-react-core';\nimport type { useLiveLog } from '@pega/cosmos-react-core';\n\nimport createLoadingAnnouncementBehavior from '../../a11y/loadingAnnouncementBehavior';\n\nexport type Selectors = {\n focusElementSelector: string;\n belowLoader: string;\n};\n\ntype AnnounceMethod = ReturnType<typeof useLiveLog>['announceAssertive'];\n\nconst TAB_INDEX = 'tabindex';\nconst CARD_KEY_ATTRIBUTE = 'data-key';\n// Set by the virtualizer on every card, it is the position of the card in all the records\nconst CARD_INDEX_ATTRIBUTE = 'data-index';\nconst MAIN_FOCUS_SELECTOR = '[data-main-focus]';\n// Cards in the same grid row can differ by a sub-pixel amount.\nconst ROW_TOP_TOLERANCE = 1;\n\nconst HORIZONTAL_KEYS = ['ArrowLeft', 'ArrowRight'];\nconst VERTICAL_KEYS = ['ArrowUp', 'ArrowDown'];\n\nfunction isForwardNavigationKey(key: string) {\n return key === 'ArrowDown' || key === 'ArrowRight';\n}\n\n/**\n * Returns the element that receives keyboard focus in a card. It is the card itself, except when its\n * only focusable content is an input such as a checkbox: cosmos then makes the input the focus\n * element and marks it with `data-main-focus`. Using the card there would make Tab stop on every\n * checkbox, and the arrow keys would not move between those cards.\n */\nfunction getTabTarget(card: HTMLElement) {\n return card.matches(MAIN_FOCUS_SELECTOR)\n ? card\n : card.querySelector<HTMLElement>(MAIN_FOCUS_SELECTOR) ?? card;\n}\n\n/**\n * Finds the card in the row below (ArrowDown) or above (ArrowUp) the current card, the one whose left\n * edge is closest to the current card's. Cards are in DOM order, which is the order they are displayed\n * in. The search starts at the current card and ends with the adjacent row, so only the cards of these\n * two rows are measured.\n *\n * @param cards - All cards, in DOM order.\n * @param currentIndex - Index of the card that currently has focus.\n * @param key - ArrowDown to look at the row below the current card, ArrowUp to look at the row above it.\n * @returns The index of that card, or null when there is no row in that direction.\n */\nfunction findCardIndexToFocusInAdjacentRow(\n cards: HTMLElement[],\n currentIndex: number,\n key: string\n): number | null {\n const step = key === 'ArrowDown' ? 1 : -1;\n const { top: currentFocusedCardTop, left: currentFocusedCardLeft } =\n cards[currentIndex].getBoundingClientRect();\n\n const areCardsInSameRow = (top: number, rowTop: number) =>\n Math.abs(top - rowTop) <= ROW_TOP_TOLERANCE;\n\n let adjacentRowTop: number | null = null;\n let closestIndex: number | null = null;\n let closestDistance = Infinity;\n\n for (let index = currentIndex + step; index >= 0 && index < cards.length; index += step) {\n const { top, left } = cards[index].getBoundingClientRect();\n\n // The first card outside the current row starts the adjacent row\n if (adjacentRowTop === null && !areCardsInSameRow(top, currentFocusedCardTop))\n adjacentRowTop = top;\n\n if (adjacentRowTop !== null) {\n if (!areCardsInSameRow(top, adjacentRowTop)) break;\n\n const distance = Math.abs(left - currentFocusedCardLeft);\n if (distance < closestDistance) {\n closestIndex = index;\n closestDistance = distance;\n }\n }\n }\n\n return closestIndex;\n}\n\n/**\n * Gallery cards are a single tab stop: Tab moves focus to the last focused card (or to the first/last\n * card when the gallery has not had focus yet) and the arrow keys move focus between cards.\n */\nclass GalleryA11y extends BaseA11y {\n #loadingAnnouncement: ReturnType<typeof createLoadingAnnouncementBehavior>;\n\n #activeCardKey: string | null = null;\n\n #activeCardIndex: string | null = null;\n\n #settleFrame: number | null = null;\n\n constructor(\n selectors: Selectors,\n focusableSelectors: string[],\n container: HTMLElement,\n announceAssertive: AnnounceMethod,\n announcePolite: AnnounceMethod,\n translate: (key: string) => string\n ) {\n super(selectors, focusableSelectors, {}, container);\n this.#loadingAnnouncement = createLoadingAnnouncementBehavior(\n selectors,\n container,\n announceAssertive,\n announcePolite,\n translate\n );\n }\n\n dispose() {\n if (this.#settleFrame !== null) {\n cancelAnimationFrame(this.#settleFrame);\n this.#settleFrame = null;\n }\n }\n\n /**\n * Makes the active card the only card in the tab order. The active card is the last focused card,\n * or the first card when the gallery has not had focus yet or that card is no longer rendered.\n */\n syncTabStops() {\n const cards = this.#getCards();\n const rememberedCard = cards.find(\n card => card.getAttribute(CARD_KEY_ATTRIBUTE) === this.#activeCardKey\n );\n const activeCard = rememberedCard ?? cards[0];\n // The position of a card changes when records before it are added or removed\n if (rememberedCard) this.#activeCardIndex = rememberedCard.getAttribute(CARD_INDEX_ATTRIBUTE);\n\n cards.forEach(card => {\n const tabIndex = card === activeCard ? '0' : '-1';\n const tabTarget = getTabTarget(card);\n if (tabTarget.getAttribute(TAB_INDEX) !== tabIndex) {\n tabTarget.setAttribute(TAB_INDEX, tabIndex);\n }\n });\n }\n\n /**\n * Moves focus between cards with the arrow keys. Keys pressed on elements inside a card are ignored\n * so that they keep working for the card content. Loading more records is left to the virtualizer,\n * which loads them when the focused card scrolls into view near the edge of the loaded records.\n */\n keyDownHandler(event: KeyboardEvent) {\n const { key } = event;\n\n const isArrowKey = HORIZONTAL_KEYS.includes(key) || VERTICAL_KEYS.includes(key);\n const hasModifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;\n\n if (event.defaultPrevented || hasModifierKey || !isArrowKey) return;\n\n const cards = this.#getCards();\n const currentIndex = cards.findIndex(card => getTabTarget(card) === event.target);\n if (currentIndex === -1) return;\n\n // Arrow keys would otherwise scroll the gallery.\n event.preventDefault();\n\n const isForwardNavigation = isForwardNavigationKey(key);\n const step = isForwardNavigation ? 1 : -1;\n\n let targetIndex = currentIndex + step;\n if (VERTICAL_KEYS.includes(key)) {\n // With no row above or below, focus stays on the current card\n targetIndex = findCardIndexToFocusInAdjacentRow(cards, currentIndex, key) ?? currentIndex;\n }\n\n if (targetIndex >= 0 && targetIndex < cards.length && targetIndex !== currentIndex) {\n this.#focusCard(cards[targetIndex]);\n }\n }\n\n override onFocusHandler(event?: Event) {\n // Records that the gallery has focus, to restore it if the focused card is removed\n super.onFocusHandler();\n this.#loadingAnnouncement.onFocus(event);\n\n const target = event?.target;\n if (!isInstance(target, Element)) return;\n const card = target.closest<HTMLElement>(this.selectors.focusElementSelector);\n if (!card || !this.container.contains(card)) return;\n\n if (this.#activeCardKey === null && this.#isReverseTabEntry(event, target)) {\n const cards = this.#getCards();\n const lastCard = cards[cards.length - 1];\n if (lastCard !== card) {\n this.#focusCard(lastCard);\n return;\n }\n }\n this.#setActiveCard(card);\n }\n\n override onBlurHandler(event: FocusEvent) {\n const { target, relatedTarget } = event;\n if (relatedTarget === null && isInstance(target, Node)) {\n // Chromium dispatches blur when the focused card is removed, other browsers do not. Only a card\n // that is still rendered once the removal has completed was really blurred.\n queueMicrotask(() => {\n if (target.isConnected) this.focusState.hadFocus = false;\n });\n return;\n }\n // event.currentTarget is not the gallery when the event comes from React (it is the React root)\n if (!isInstance(relatedTarget, Node) || !this.container.contains(relatedTarget)) {\n this.focusState.hadFocus = false;\n }\n }\n\n /**\n * Runs after every Gallery render, like the table's. Announces that loading completed, keeps a\n * single card in the tab order and restores focus if the focused card was removed.\n *\n * Cosmos cards update their own tabindex in effects and a second render pass, which can happen\n * after the Gallery's effect and make cards tabbable again. So the tab order and the focus are\n * checked once more after the next frame.\n */\n itemsLoadedCallback() {\n this.#loadingAnnouncement.onItemsLoaded();\n this.syncTabStops();\n\n if (this.#settleFrame !== null) cancelAnimationFrame(this.#settleFrame);\n this.#settleFrame = requestAnimationFrame(() => {\n this.#settleFrame = null;\n this.syncTabStops();\n this.#restoreFocusIfLost();\n });\n }\n\n /**\n * When the focused card is removed (for example after deleting it), focus falls back to the body.\n * Unless it had already left the gallery, focus is restored to the first of these that exists, like\n * in the table: the same card (it can have moved), the card that is now at the same position, the\n * last card. Focus on any other element was moved there on purpose and is left alone.\n */\n #restoreFocusIfLost() {\n if (!this.focusState.hadFocus || getActiveElement() !== document.body) return;\n\n const cards = this.#getCards();\n const card =\n cards.find(candidate => candidate.getAttribute(CARD_KEY_ATTRIBUTE) === this.#activeCardKey) ??\n cards.find(\n candidate =>\n this.#activeCardIndex !== null &&\n candidate.getAttribute(CARD_INDEX_ATTRIBUTE) === this.#activeCardIndex\n ) ??\n cards[cards.length - 1];\n if (card) this.#focusCard(card);\n }\n\n #getCards() {\n return Array.from(\n this.container.querySelectorAll<HTMLElement>(this.selectors.focusElementSelector)\n );\n }\n\n #setActiveCard(card: HTMLElement) {\n this.#activeCardKey = card.getAttribute(CARD_KEY_ATTRIBUTE);\n this.#activeCardIndex = card.getAttribute(CARD_INDEX_ATTRIBUTE);\n this.syncTabStops();\n }\n\n #focusCard(card: HTMLElement) {\n this.#setActiveCard(card);\n getTabTarget(card).focus();\n }\n\n /**\n * True when focus moved into the gallery with Shift+Tab from an element after it.\n * Pointer focus is excluded through `:focus-visible`.\n */\n #isReverseTabEntry(event: Event | undefined, target: Element) {\n if (!isInstance(event, FocusEvent)) return false;\n const { relatedTarget } = event;\n if (!isInstance(relatedTarget, Node) || this.container.contains(relatedTarget)) return false;\n\n const position = this.container.compareDocumentPosition(relatedTarget);\n // eslint-disable-next-line no-bitwise\n const isAfterGallery = (position & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;\n return isAfterGallery && target.matches(':focus-visible');\n }\n}\n\nexport default GalleryA11y;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../Core/Views/Gallery/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAqBlE,iBAAS,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAA;CAAE,2CAiIpD;kBAjIQ,OAAO;;;AAqIhB,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../Core/Views/Gallery/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAqBlE,iBAAS,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAA;CAAE,2CAoIpD;kBApIQ,OAAO;;;AAwIhB,eAAe,OAAO,CAAC"}
@@ -33,6 +33,7 @@ function Gallery({ view }) {
33
33
  }, [], containerRef.current, announceAssertive, announcePolite, translate);
34
34
  }
35
35
  return () => {
36
+ a11yRef.current?.dispose();
36
37
  a11yRef.current = null;
37
38
  };
38
39
  }, [announceAssertive, announcePolite, translate]);
@@ -53,7 +54,7 @@ function Gallery({ view }) {
53
54
  });
54
55
  const isMasterDetailDocked = masterDetail.masterDetailProps.open &&
55
56
  masterDetail.masterDetailProps.presentation !== 'overlay';
56
- const galleryContent = (_jsxs(StyledVirtualizeContainer, { ref: containerRef, className: 'container', onFocusCapture: e => a11yRef.current?.onFocusHandler(e.nativeEvent), children: [_jsx(Virtualiser, { id: 'rootVirtualiser', rowContainerClass: 'grid-container', view: view, bufferMultiplier: 0.8, children: rows?.length
57
+ const galleryContent = (_jsxs(StyledVirtualizeContainer, { ref: containerRef, className: 'container', onFocusCapture: e => a11yRef.current?.onFocusHandler(e.nativeEvent), onBlurCapture: e => a11yRef.current?.onBlurHandler(e.nativeEvent), onKeyDown: e => a11yRef.current?.keyDownHandler(e.nativeEvent), children: [_jsx(Virtualiser, { id: 'rootVirtualiser', rowContainerClass: 'grid-container', view: view, bufferMultiplier: 0.8, children: rows?.length
57
58
  ? rows.map(row => selectionMode === SELECTION_MODES.multi && selectionColumn ? (_jsx(GalleryCheckboxCard, { meta: meta, row: row, visibleColumns: visibleColumns, masterDetailActive: row.masterDetailActive, headerColumn: headerColumn, selectionColumn: selectionColumn, restoreFocusRef: restoreFocusRef }, row.reactKey)) : (_jsx(GalleryCard, { meta: meta, row: row, visibleColumns: visibleColumns, masterDetailActive: row.masterDetailActive, headerColumn: headerColumn, subHeadingsColumns: subHeadingsColumns, restoreFocusRef: restoreFocusRef }, row.reactKey)))
58
59
  : [] }), _jsx(LoadingIndicator, { view: view, show: !rows || !!view.isLoading })] }));
59
60
  return (_jsx(RsCardWrapper, { children: _jsxs(GalleryContainer, { "data-test-id": 'gallery', "data-testid": 'gallery', view: view, isFullscreen: isFullscreen, image: heroImage, isStackLayout: isCardList || isMasterDetailDocked, tile: tileConfig, children: [_jsx(WarningBanner, { warningMessages: view.warningMessages }), _jsx(Toolbar, { view: view }), _jsx(RenderView, { view: view, type: EXTERNAL_FILTERS }), isMasterDetail ? (_jsx(StyledCardFlushMasterDetail, { master: galleryContent, detail: masterDetail.detail, ...masterDetail.masterDetailProps, restoreFocusRef: restoreFocusRef, "$flush": isMasterDetailDocked })) : (galleryContent)] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../Core/Views/Gallery/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,UAAU,MAAM,6CAA6C,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,gBAAgB,MAAM,mCAAmC,CAAC;AACjE,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;AACtE,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,oBAAoB,EACjD,IAAI,EAAE,UAAU,aAEhB,KAAC,aAAa,IAAC,eAAe,EAAE,IAAI,CAAC,eAAe,GAAI,EACxD,KAAC,OAAO,IAAC,IAAI,EAAE,IAAI,GAAI,EACvB,KAAC,UAAU,IAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,GAAI,EACjD,cAAc,CAAC,CAAC,CAAC,CAChB,KAAC,2BAA2B,IAC1B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,YAAY,CAAC,MAAM,KACvB,YAAY,CAAC,iBAAiB,EAClC,eAAe,EAAE,eAAe,YACxB,oBAAoB,GAC5B,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,IACgB,GACL,CACjB,CAAC;AACJ,CAAC;AAED,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;AAEhC,eAAe,OAAO,CAAC","sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\n\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport { useLiveLog, useFullscreenContext } from '@pega/cosmos-react-core';\nimport { rowSelectColumnMeta } from 'pega-repeating-structures-core';\n\nimport useTranslate from '../../Hooks/useTranslate';\nimport Virtualiser from '../Table/VirtualizeWrapper';\nimport Toolbar from '../../Components/Toolbar';\nimport RenderView from '../../Components/RenderingEngine/RenderView';\nimport { EXTERNAL_FILTERS, SELECTION_MODES } from '../../constants';\nimport RsCardWrapper from '../RsCardWrapper';\nimport LoadingIndicator from '../../Components/LoadingIndicator';\nimport WarningBanner from '../../Components/WarningBanner';\nimport { getCardColumns } from '../../Components/Card';\nimport useMasterDetailHost from '../MasterDetail/useMasterDetailHost';\nimport StyledCardFlushMasterDetail from '../MasterDetail/MasterDetail.styles';\n\nimport GalleryCard from './Components/GalleryCard';\nimport GalleryCheckboxCard from './Components/GalleryCheckboxCard';\nimport GalleryContainer, { StyledVirtualizeContainer } from './GalleryContainer';\nimport GalleryA11y from './GalleryA11y';\n\nfunction Gallery({ view }: { view: RsCoreTypes.View }) {\n const layoutType = view.galleryLayout;\n const isFullscreen = !!useFullscreenContext()?.[0];\n const containerRef = useRef<HTMLDivElement>(null);\n const { announceAssertive, announcePolite } = useLiveLog();\n const [translate] = useTranslate();\n const a11yRef = useRef<GalleryA11y | null>(null);\n const restoreFocusRef = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n if (containerRef.current) {\n a11yRef.current = new GalleryA11y(\n {\n focusElementSelector: '[data-gallery-card]',\n belowLoader: '.below-loader'\n },\n [],\n containerRef.current,\n announceAssertive,\n announcePolite,\n translate\n );\n }\n return () => {\n a11yRef.current = null;\n };\n }, [announceAssertive, announcePolite, translate]);\n\n useEffect(() => {\n a11yRef.current?.itemsLoadedCallback();\n });\n const isCardList = layoutType === 'cardlist';\n\n const { columns = [], meta, rows } = view;\n const cardConfig = { ...meta.galleryConfig, ...meta.cardConfig };\n const { heroImage, tile: tileConfig, header, subHeadings } = cardConfig;\n const { selectionMode } = meta;\n\n const { visibleColumns, headerColumn, subHeadingsColumns } = useMemo(\n () => getCardColumns(columns, { header, subHeadings }),\n [columns, header, subHeadings]\n );\n\n const selectionColumn = useMemo(\n () => columns.find(col => col.field.id === rowSelectColumnMeta.field.id),\n [columns]\n );\n const isMasterDetail = Boolean(meta.masterDetail);\n const masterDetail = useMasterDetailHost({\n view,\n ...(headerColumn !== undefined ? { headerColumn } : {})\n });\n const isMasterDetailDocked =\n masterDetail.masterDetailProps.open &&\n masterDetail.masterDetailProps.presentation !== 'overlay';\n\n const galleryContent = (\n <StyledVirtualizeContainer\n ref={containerRef}\n className='container'\n onFocusCapture={e => a11yRef.current?.onFocusHandler(e.nativeEvent)}\n >\n <Virtualiser\n id='rootVirtualiser'\n rowContainerClass='grid-container'\n view={view}\n bufferMultiplier={0.8}\n >\n {rows?.length\n ? rows.map(row =>\n selectionMode === SELECTION_MODES.multi && selectionColumn ? (\n // TODO: Checkbox card doesn't support subHeadingsColumns yet\n <GalleryCheckboxCard\n key={row.reactKey}\n meta={meta}\n row={row}\n visibleColumns={visibleColumns}\n masterDetailActive={row.masterDetailActive}\n headerColumn={headerColumn}\n selectionColumn={selectionColumn}\n restoreFocusRef={restoreFocusRef}\n />\n ) : (\n <GalleryCard\n key={row.reactKey}\n meta={meta}\n row={row}\n visibleColumns={visibleColumns}\n masterDetailActive={row.masterDetailActive}\n headerColumn={headerColumn}\n subHeadingsColumns={subHeadingsColumns}\n restoreFocusRef={restoreFocusRef}\n />\n )\n )\n : []}\n </Virtualiser>\n <LoadingIndicator view={view} show={!rows || !!view.isLoading} />\n </StyledVirtualizeContainer>\n );\n\n return (\n <RsCardWrapper>\n <GalleryContainer\n data-test-id='gallery'\n data-testid='gallery'\n view={view}\n isFullscreen={isFullscreen}\n image={heroImage}\n isStackLayout={isCardList || isMasterDetailDocked}\n tile={tileConfig}\n >\n <WarningBanner warningMessages={view.warningMessages} />\n <Toolbar view={view} />\n <RenderView view={view} type={EXTERNAL_FILTERS} />\n {isMasterDetail ? (\n <StyledCardFlushMasterDetail\n master={galleryContent}\n detail={masterDetail.detail}\n {...masterDetail.masterDetailProps}\n restoreFocusRef={restoreFocusRef}\n $flush={isMasterDetailDocked}\n />\n ) : (\n galleryContent\n )}\n </GalleryContainer>\n </RsCardWrapper>\n );\n}\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../Core/Views/Gallery/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAC/C,OAAO,UAAU,MAAM,6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,EACV,GAAG,EAAE,GAAG,EACR,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,EAC1C,YAAY,EAAE,YAAY,EAC1B,kBAAkB,EAAE,kBAAkB,EACtC,eAAe,EAAE,eAAe,IAP3B,GAAG,CAAC,QAAQ,CAQjB,CACH,CACF;oBACH,CAAC,CAAC,EAAE,GACM,EACd,KAAC,gBAAgB,IAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,GAAI,IACvC,CAC7B,CAAC;IAEF,OAAO,CACL,KAAC,aAAa,cACZ,MAAC,gBAAgB,oBACF,SAAS,iBACV,SAAS,EACrB,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,SAAS,EAChB,aAAa,EAAE,UAAU,IAAI,oBAAoB,EACjD,IAAI,EAAE,UAAU,aAEhB,KAAC,aAAa,IAAC,eAAe,EAAE,IAAI,CAAC,eAAe,GAAI,EACxD,KAAC,OAAO,IAAC,IAAI,EAAE,IAAI,GAAI,EACvB,KAAC,UAAU,IAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,GAAI,EACjD,cAAc,CAAC,CAAC,CAAC,CAChB,KAAC,2BAA2B,IAC1B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,YAAY,CAAC,MAAM,KACvB,YAAY,CAAC,iBAAiB,EAClC,eAAe,EAAE,eAAe,YACxB,oBAAoB,GAC5B,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,IACgB,GACL,CACjB,CAAC;AACJ,CAAC;AAED,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;AAEhC,eAAe,OAAO,CAAC","sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\n\nimport type { RsCoreTypes } from 'pega-repeating-structures-core';\nimport { useLiveLog, useFullscreenContext } from '@pega/cosmos-react-core';\nimport { rowSelectColumnMeta } from 'pega-repeating-structures-core';\n\nimport useTranslate from '../../Hooks/useTranslate';\nimport Virtualiser from '../Table/VirtualizeWrapper';\nimport Toolbar from '../../Components/Toolbar';\nimport RenderView from '../../Components/RenderingEngine/RenderView';\nimport { EXTERNAL_FILTERS, SELECTION_MODES } from '../../constants';\nimport RsCardWrapper from '../RsCardWrapper';\nimport LoadingIndicator from '../../Components/LoadingIndicator';\nimport WarningBanner from '../../Components/WarningBanner';\nimport { getCardColumns } from '../../Components/Card';\nimport useMasterDetailHost from '../MasterDetail/useMasterDetailHost';\nimport StyledCardFlushMasterDetail from '../MasterDetail/MasterDetail.styles';\n\nimport GalleryCard from './Components/GalleryCard';\nimport GalleryCheckboxCard from './Components/GalleryCheckboxCard';\nimport GalleryContainer, { StyledVirtualizeContainer } from './GalleryContainer';\nimport GalleryA11y from './GalleryA11y';\n\nfunction Gallery({ view }: { view: RsCoreTypes.View }) {\n const layoutType = view.galleryLayout;\n const isFullscreen = !!useFullscreenContext()?.[0];\n const containerRef = useRef<HTMLDivElement>(null);\n const { announceAssertive, announcePolite } = useLiveLog();\n const [translate] = useTranslate();\n const a11yRef = useRef<GalleryA11y | null>(null);\n const restoreFocusRef = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n if (containerRef.current) {\n a11yRef.current = new GalleryA11y(\n {\n focusElementSelector: '[data-gallery-card]',\n belowLoader: '.below-loader'\n },\n [],\n containerRef.current,\n announceAssertive,\n announcePolite,\n translate\n );\n }\n return () => {\n a11yRef.current?.dispose();\n a11yRef.current = null;\n };\n }, [announceAssertive, announcePolite, translate]);\n\n useEffect(() => {\n a11yRef.current?.itemsLoadedCallback();\n });\n const isCardList = layoutType === 'cardlist';\n\n const { columns = [], meta, rows } = view;\n const cardConfig = { ...meta.galleryConfig, ...meta.cardConfig };\n const { heroImage, tile: tileConfig, header, subHeadings } = cardConfig;\n const { selectionMode } = meta;\n\n const { visibleColumns, headerColumn, subHeadingsColumns } = useMemo(\n () => getCardColumns(columns, { header, subHeadings }),\n [columns, header, subHeadings]\n );\n\n const selectionColumn = useMemo(\n () => columns.find(col => col.field.id === rowSelectColumnMeta.field.id),\n [columns]\n );\n const isMasterDetail = Boolean(meta.masterDetail);\n const masterDetail = useMasterDetailHost({\n view,\n ...(headerColumn !== undefined ? { headerColumn } : {})\n });\n const isMasterDetailDocked =\n masterDetail.masterDetailProps.open &&\n masterDetail.masterDetailProps.presentation !== 'overlay';\n\n const galleryContent = (\n <StyledVirtualizeContainer\n ref={containerRef}\n className='container'\n onFocusCapture={e => a11yRef.current?.onFocusHandler(e.nativeEvent)}\n onBlurCapture={e => a11yRef.current?.onBlurHandler(e.nativeEvent)}\n onKeyDown={e => a11yRef.current?.keyDownHandler(e.nativeEvent)}\n >\n <Virtualiser\n id='rootVirtualiser'\n rowContainerClass='grid-container'\n view={view}\n bufferMultiplier={0.8}\n >\n {rows?.length\n ? rows.map(row =>\n selectionMode === SELECTION_MODES.multi && selectionColumn ? (\n // TODO: Checkbox card doesn't support subHeadingsColumns yet\n <GalleryCheckboxCard\n key={row.reactKey}\n meta={meta}\n row={row}\n visibleColumns={visibleColumns}\n masterDetailActive={row.masterDetailActive}\n headerColumn={headerColumn}\n selectionColumn={selectionColumn}\n restoreFocusRef={restoreFocusRef}\n />\n ) : (\n <GalleryCard\n key={row.reactKey}\n meta={meta}\n row={row}\n visibleColumns={visibleColumns}\n masterDetailActive={row.masterDetailActive}\n headerColumn={headerColumn}\n subHeadingsColumns={subHeadingsColumns}\n restoreFocusRef={restoreFocusRef}\n />\n )\n )\n : []}\n </Virtualiser>\n <LoadingIndicator view={view} show={!rows || !!view.isLoading} />\n </StyledVirtualizeContainer>\n );\n\n return (\n <RsCardWrapper>\n <GalleryContainer\n data-test-id='gallery'\n data-testid='gallery'\n view={view}\n isFullscreen={isFullscreen}\n image={heroImage}\n isStackLayout={isCardList || isMasterDetailDocked}\n tile={tileConfig}\n >\n <WarningBanner warningMessages={view.warningMessages} />\n <Toolbar view={view} />\n <RenderView view={view} type={EXTERNAL_FILTERS} />\n {isMasterDetail ? (\n <StyledCardFlushMasterDetail\n master={galleryContent}\n detail={masterDetail.detail}\n {...masterDetail.masterDetailProps}\n restoreFocusRef={restoreFocusRef}\n $flush={isMasterDetailDocked}\n />\n ) : (\n galleryContent\n )}\n </GalleryContainer>\n </RsCardWrapper>\n );\n}\n\nGallery.displayName = 'Gallery';\n\nexport default Gallery;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/lists-react",
3
- "version": "10.0.0-build.16.3",
3
+ "version": "10.0.0-build.16.4",
4
4
  "description": "Repeating view structures such as Table, Gallery(Repeating layouts), Kanban etc.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Pegasystems",
@@ -14,19 +14,19 @@
14
14
  "build": "tsc -b tsconfig.build.json"
15
15
  },
16
16
  "dependencies": {
17
- "@pega/cosmos-react-condition-builder": "10.0.0-build.16.3",
18
- "@pega/cosmos-react-core": "10.0.0-build.16.3",
19
- "@pega/cosmos-react-dnd": "10.0.0-build.16.3",
20
- "@pega/cosmos-react-rte": "10.0.0-build.16.3",
21
- "@pega/cosmos-react-work": "10.0.0-build.16.3",
17
+ "@pega/cosmos-react-condition-builder": "10.0.0-build.16.4",
18
+ "@pega/cosmos-react-core": "10.0.0-build.16.4",
19
+ "@pega/cosmos-react-dnd": "10.0.0-build.16.4",
20
+ "@pega/cosmos-react-rte": "10.0.0-build.16.4",
21
+ "@pega/cosmos-react-work": "10.0.0-build.16.4",
22
22
  "@types/lodash-es": "^4.17.12",
23
23
  "@types/react": "^17.0.62 || ^18.3.3",
24
24
  "@types/react-dom": "^17.0.20 || ^18.3.0",
25
25
  "dayjs": "^1.11.13",
26
26
  "fast-deep-equal": "^3.1.3",
27
27
  "lodash-es": "^4.18.1",
28
- "pega-repeating-structures-core": "npm:@pega/lists-core@10.0.0-build.16.3",
29
- "pega-ui-list-data-apis": "npm:@pega/lists-core-utils@10.0.0-build.16.3",
28
+ "pega-repeating-structures-core": "npm:@pega/lists-core@10.0.0-build.16.4",
29
+ "pega-ui-list-data-apis": "npm:@pega/lists-core-utils@10.0.0-build.16.4",
30
30
  "polished": "^4.1.0",
31
31
  "prop-types": "^15.8.1",
32
32
  "react": "^17.0.0 || ^18.0.0",
@@ -40,7 +40,7 @@
40
40
  "@testing-library/react": "^16.0.0",
41
41
  "@testing-library/user-event": "^14.6.1",
42
42
  "jest-axe": "^8.0.0",
43
- "srs-utils": "10.0.0-build.16.3",
43
+ "srs-utils": "10.0.0-build.16.4",
44
44
  "storybook": "~10.6.6",
45
45
  "typescript": "~6.0.3"
46
46
  }