@workday/canvas-kit-react 7.1.4 → 7.2.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collection/index.ts +2 -0
- package/collection/lib/useBaseListModel.tsx +1 -1
- package/collection/lib/useCursorListModel.tsx +88 -20
- package/collection/lib/useGridModel.ts +34 -0
- package/collection/lib/useListItemRovingFocus.tsx +6 -4
- package/dist/commonjs/collection/index.d.ts +2 -0
- package/dist/commonjs/collection/index.d.ts.map +1 -1
- package/dist/commonjs/collection/index.js +5 -1
- package/dist/commonjs/collection/lib/useBaseListModel.js +1 -1
- package/dist/commonjs/collection/lib/useCursorListModel.d.ts +64 -101
- package/dist/commonjs/collection/lib/useCursorListModel.d.ts.map +1 -1
- package/dist/commonjs/collection/lib/useCursorListModel.js +64 -23
- package/dist/commonjs/collection/lib/useGridModel.d.ts +955 -0
- package/dist/commonjs/collection/lib/useGridModel.d.ts.map +1 -0
- package/dist/commonjs/collection/lib/useGridModel.js +52 -0
- package/dist/commonjs/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
- package/dist/commonjs/collection/lib/useListItemRovingFocus.js +6 -4
- package/dist/es6/collection/index.d.ts +2 -0
- package/dist/es6/collection/index.d.ts.map +1 -1
- package/dist/es6/collection/index.js +2 -0
- package/dist/es6/collection/lib/useBaseListModel.js +1 -1
- package/dist/es6/collection/lib/useCursorListModel.d.ts +64 -101
- package/dist/es6/collection/lib/useCursorListModel.d.ts.map +1 -1
- package/dist/es6/collection/lib/useCursorListModel.js +64 -23
- package/dist/es6/collection/lib/useGridModel.d.ts +955 -0
- package/dist/es6/collection/lib/useGridModel.d.ts.map +1 -0
- package/dist/es6/collection/lib/useGridModel.js +49 -0
- package/dist/es6/collection/lib/useListItemRovingFocus.d.ts.map +1 -1
- package/dist/es6/collection/lib/useListItemRovingFocus.js +6 -4
- package/package.json +5 -5
|
@@ -50,8 +50,8 @@ export var getLast = function (_, _a) {
|
|
|
50
50
|
export var getFirstOfRow = function (id, _a) {
|
|
51
51
|
var state = _a.state;
|
|
52
52
|
if (state.columnCount) {
|
|
53
|
-
var
|
|
54
|
-
var currentIndex =
|
|
53
|
+
var item = getItem(id, { state: state });
|
|
54
|
+
var currentIndex = item.index;
|
|
55
55
|
var offset = currentIndex % state.columnCount;
|
|
56
56
|
return state.items[currentIndex - offset];
|
|
57
57
|
}
|
|
@@ -63,10 +63,14 @@ export var getFirstOfRow = function (id, _a) {
|
|
|
63
63
|
export var getLastOfRow = function (id, _a) {
|
|
64
64
|
var state = _a.state;
|
|
65
65
|
if (state.columnCount) {
|
|
66
|
-
var
|
|
67
|
-
var currentIndex =
|
|
66
|
+
var item = getItem(id, { state: state });
|
|
67
|
+
var currentIndex = item.index;
|
|
68
68
|
var offset = (currentIndex % state.columnCount) - state.columnCount + 1;
|
|
69
|
-
|
|
69
|
+
var nextIndex = currentIndex - offset;
|
|
70
|
+
if (nextIndex >= state.items.length) {
|
|
71
|
+
nextIndex = state.items.length - 1;
|
|
72
|
+
}
|
|
73
|
+
return state.items[nextIndex];
|
|
70
74
|
}
|
|
71
75
|
return getLast(id, { state: state });
|
|
72
76
|
};
|
|
@@ -77,8 +81,8 @@ export var getLastOfRow = function (id, _a) {
|
|
|
77
81
|
export var getPreviousPage = function (id, _a) {
|
|
78
82
|
var state = _a.state;
|
|
79
83
|
if (state.columnCount) {
|
|
80
|
-
var
|
|
81
|
-
var currentIndex =
|
|
84
|
+
var item = getItem(id, { state: state });
|
|
85
|
+
var currentIndex = item.index;
|
|
82
86
|
return state.items[currentIndex % state.columnCount];
|
|
83
87
|
}
|
|
84
88
|
return getFirst(id, { state: state });
|
|
@@ -90,8 +94,8 @@ export var getPreviousPage = function (id, _a) {
|
|
|
90
94
|
export var getNextPage = function (id, _a) {
|
|
91
95
|
var state = _a.state;
|
|
92
96
|
if (state.columnCount) {
|
|
93
|
-
var
|
|
94
|
-
var currentIndex =
|
|
97
|
+
var item = getItem(id, { state: state });
|
|
98
|
+
var currentIndex = item.index;
|
|
95
99
|
var lastRowIndex = state.items.length - state.columnCount;
|
|
96
100
|
return state.items[lastRowIndex + (currentIndex % state.columnCount)];
|
|
97
101
|
}
|
|
@@ -108,13 +112,40 @@ export var getWrappingOffsetItem = function (offset) { return function (id, _a,
|
|
|
108
112
|
if (tries === void 0) { tries = state.items.length; }
|
|
109
113
|
var items = state.items;
|
|
110
114
|
var item = getItem(id, { state: state });
|
|
111
|
-
var currentIndex =
|
|
115
|
+
var currentIndex = item.index;
|
|
112
116
|
var nextIndex = currentIndex + offset;
|
|
117
|
+
// calculate idealLength as in if the grid was a perfect rectangle
|
|
118
|
+
var rows = Math.ceil(items.length / state.columnCount);
|
|
119
|
+
var idealLength = rows * state.columnCount;
|
|
113
120
|
if (nextIndex < 0) {
|
|
114
|
-
|
|
121
|
+
if (offset === -1) {
|
|
122
|
+
// if the offset is -1, we want to wrap to the end
|
|
123
|
+
nextIndex = items.length - 1;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// if the offset is smaller than -1, we want to wrap by column
|
|
127
|
+
if (idealLength + nextIndex >= items.length) {
|
|
128
|
+
// we'll overflow the grid because there isn't enough items. Move `nextIndex` up so we wrap in
|
|
129
|
+
// the right spot
|
|
130
|
+
nextIndex -= state.columnCount;
|
|
131
|
+
}
|
|
132
|
+
nextIndex = idealLength + nextIndex;
|
|
133
|
+
}
|
|
115
134
|
}
|
|
116
135
|
else if (nextIndex >= items.length) {
|
|
117
|
-
|
|
136
|
+
if (offset === 1) {
|
|
137
|
+
// if the offset is 1, we want to wrap to the beginning
|
|
138
|
+
nextIndex = 0;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// if the offset is larger than 1, we want to wrap by column
|
|
142
|
+
if (nextIndex - idealLength < 0) {
|
|
143
|
+
// we're going to overflow the grid because there isn't enough items. Move `nextIndex` down to
|
|
144
|
+
// the missing item in the next row. This way we'll end up wrapping in the right spot
|
|
145
|
+
nextIndex += state.columnCount;
|
|
146
|
+
}
|
|
147
|
+
nextIndex = nextIndex - idealLength;
|
|
148
|
+
}
|
|
118
149
|
}
|
|
119
150
|
if (state.nonInteractiveIds.includes(getId(items[nextIndex])) && tries > 0) {
|
|
120
151
|
// The next item is disabled, try again, but only if we haven't already tried everything.
|
|
@@ -128,7 +159,7 @@ export var getOffsetItem = function (offset) { return function (id, _a, tries) {
|
|
|
128
159
|
if (tries === void 0) { tries = state.items.length; }
|
|
129
160
|
var items = state.items, columnCount = state.columnCount;
|
|
130
161
|
var item = getItem(id, { state: state });
|
|
131
|
-
var currentIndex =
|
|
162
|
+
var currentIndex = item.index;
|
|
132
163
|
var nextIndex = currentIndex + offset;
|
|
133
164
|
if (Math.abs(offset) < columnCount) {
|
|
134
165
|
// if we're here, the columnCount is non-zero and the absolute value of offset is less than the
|
|
@@ -146,8 +177,13 @@ export var getOffsetItem = function (offset) { return function (id, _a, tries) {
|
|
|
146
177
|
if (nextRow < 0 || nextRow >= columnCount) {
|
|
147
178
|
nextIndex = currentIndex;
|
|
148
179
|
}
|
|
180
|
+
// make sure we don't go out of bounds if the grid isn't a perfect rectangle
|
|
181
|
+
if (nextIndex > items.length - 1) {
|
|
182
|
+
nextIndex = currentIndex;
|
|
183
|
+
}
|
|
149
184
|
}
|
|
150
|
-
|
|
185
|
+
// make sure we're always in bounds
|
|
186
|
+
if (nextIndex < 0) {
|
|
151
187
|
nextIndex = 0;
|
|
152
188
|
}
|
|
153
189
|
else if (nextIndex >= items.length) {
|
|
@@ -161,7 +197,9 @@ export var getOffsetItem = function (offset) { return function (id, _a, tries) {
|
|
|
161
197
|
return items[nextIndex];
|
|
162
198
|
}; };
|
|
163
199
|
/**
|
|
164
|
-
* The default navigation manager of lists
|
|
200
|
+
* The default navigation manager of lists. This navigation manager will wrap around when the edge
|
|
201
|
+
* is hit. For example, if the user is the the right-most item in a list or right-most item in a
|
|
202
|
+
* row, the cursor will wrap around to the beginning or the next row.
|
|
165
203
|
*/
|
|
166
204
|
export var wrappingNavigationManager = createNavigationManager({
|
|
167
205
|
getFirst: getFirst,
|
|
@@ -170,18 +208,22 @@ export var wrappingNavigationManager = createNavigationManager({
|
|
|
170
208
|
getNext: getWrappingOffsetItem(1),
|
|
171
209
|
getNextRow: function (id, _a) {
|
|
172
210
|
var state = _a.state;
|
|
173
|
-
return getWrappingOffsetItem(
|
|
211
|
+
return getWrappingOffsetItem(state.columnCount)(id, { state: state });
|
|
174
212
|
},
|
|
175
213
|
getPrevious: getWrappingOffsetItem(-1),
|
|
176
214
|
getPreviousRow: function (id, _a) {
|
|
177
215
|
var state = _a.state;
|
|
178
|
-
return getWrappingOffsetItem(state.columnCount)(id, { state: state });
|
|
216
|
+
return getWrappingOffsetItem(-state.columnCount)(id, { state: state });
|
|
179
217
|
},
|
|
180
218
|
getPreviousPage: getPreviousPage,
|
|
181
219
|
getNextPage: getNextPage,
|
|
182
220
|
getFirstOfRow: getFirstOfRow,
|
|
183
221
|
getLastOfRow: getLastOfRow,
|
|
184
222
|
});
|
|
223
|
+
/**
|
|
224
|
+
* The default navigation of grids. This navigation manager will not wrap, but will stop when an
|
|
225
|
+
* edge is detected. This could be the last item in a list or the last item of a row in a grid.
|
|
226
|
+
*/
|
|
185
227
|
export var navigationManager = createNavigationManager({
|
|
186
228
|
getFirst: getFirst,
|
|
187
229
|
getLast: getLast,
|
|
@@ -189,12 +231,12 @@ export var navigationManager = createNavigationManager({
|
|
|
189
231
|
getNext: getOffsetItem(1),
|
|
190
232
|
getNextRow: function (id, _a) {
|
|
191
233
|
var state = _a.state;
|
|
192
|
-
return getOffsetItem(
|
|
234
|
+
return getOffsetItem(state.columnCount)(id, { state: state });
|
|
193
235
|
},
|
|
194
236
|
getPrevious: getOffsetItem(-1),
|
|
195
237
|
getPreviousRow: function (id, _a) {
|
|
196
238
|
var state = _a.state;
|
|
197
|
-
return getOffsetItem(state.columnCount)(id, { state: state });
|
|
239
|
+
return getOffsetItem(-state.columnCount)(id, { state: state });
|
|
198
240
|
},
|
|
199
241
|
getPreviousPage: getPreviousPage,
|
|
200
242
|
getNextPage: getNextPage,
|
|
@@ -223,9 +265,7 @@ export var useCursorListModel = createModelHook({
|
|
|
223
265
|
* (left-to-right or right-to-left) and call the correct navigation method. In our example, a
|
|
224
266
|
* left-to-right language would send a `getNext`. The navigation manager may return the next item
|
|
225
267
|
* in the list. Different managers can be created for slightly different use cases. The default
|
|
226
|
-
* navigation manager will accept `orientation` and directionality to determine mapping.
|
|
227
|
-
* `columnCount` is non-zero, it will use a grid mode where `orientation` is ignored and only
|
|
228
|
-
* directionality matters.
|
|
268
|
+
* navigation manager will accept `orientation` and directionality to determine mapping.
|
|
229
269
|
*
|
|
230
270
|
* An example override might be a tab list with an overflow menu that is meant to be transparent
|
|
231
271
|
* to screen reader users. This would require the overflow menu to accept both up/down keys as
|
|
@@ -239,15 +279,16 @@ export var useCursorListModel = createModelHook({
|
|
|
239
279
|
var columnCount = config.columnCount || 0;
|
|
240
280
|
var list = useBaseListModel(config);
|
|
241
281
|
var initialCurrentRef = React.useRef(config.initialCursorId || (((_a = config.items) === null || _a === void 0 ? void 0 : _a.length) ? getId(config.items[0]) : ''));
|
|
282
|
+
var navigation = config.navigation;
|
|
242
283
|
var state = __assign(__assign({}, list.state), {
|
|
243
284
|
/** The id of the list item the cursor is pointing to */
|
|
244
285
|
cursorId: cursorId,
|
|
245
286
|
/**
|
|
246
287
|
* Any positive non-zero value treats the list like a grid with rows and columns
|
|
247
288
|
* @default 0
|
|
289
|
+
* @private Use useGridModel instead to make a grid instead of a list
|
|
248
290
|
*/
|
|
249
291
|
columnCount: columnCount });
|
|
250
|
-
var navigation = config.navigation || wrappingNavigationManager;
|
|
251
292
|
var events = __assign(__assign({}, list.events), {
|
|
252
293
|
/**
|
|
253
294
|
* Register an item to the list. Takes in an identifier, a React.Ref and an optional index. This
|