@ndla/ui 13.2.1 → 15.0.0
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/es/Article/Article.js +22 -3
- package/es/Article/ArticleFavoritesButton.js +38 -0
- package/es/Article/index.js +2 -1
- package/es/Breadcrumb/ActionBreadcrumb.js +57 -0
- package/es/Breadcrumb/index.js +1 -0
- package/es/Footer/FooterAuth.js +15 -22
- package/es/InfoBlock/InfoBlock.js +55 -0
- package/es/InfoBlock/index.js +1 -0
- package/es/LearningPaths/LearningPathMenu.js +3 -4
- package/es/Masthead/MastheadAuthModal.js +2 -2
- package/es/MyNdla/Navigation/VerticalNavigation.js +51 -0
- package/es/MyNdla/Navigation/index.js +2 -0
- package/es/MyNdla/Resource/Folder.js +86 -0
- package/{lib/MyNdla/ResourceDash/ResourcesView.d.ts → es/MyNdla/Resource/index.js} +2 -3
- package/es/MyNdla/index.js +3 -4
- package/es/Notion/ConceptNotion.js +2 -1
- package/es/Notion/FigureNotion.js +13 -9
- package/es/Notion/NotionVisualElement.js +3 -2
- package/es/Resource/BlockResource.js +73 -0
- package/es/Resource/ListResource.js +66 -0
- package/es/Resource/index.js +10 -0
- package/es/Resource/resourceComponents.js +97 -0
- package/es/ResourceGroup/ResourceGroup.js +7 -5
- package/es/ResourceGroup/ResourceItem.js +28 -30
- package/es/ResourceGroup/ResourceList.js +18 -6
- package/es/Search/ActiveFilters.js +6 -7
- package/es/Search/ContentTypeResult.js +6 -8
- package/es/SearchTypeResult/ActiveFilters.js +6 -10
- package/es/SearchTypeResult/SearchViewType.js +5 -5
- package/es/SnackBar/SnackBar.js +117 -0
- package/es/SnackBar/index.js +9 -0
- package/es/TagSelector/SuggestionInput.js +240 -0
- package/es/TagSelector/Suggestions.js +93 -0
- package/es/TagSelector/TagSelector.js +137 -0
- package/es/TagSelector/index.js +9 -0
- package/es/TopicIntroductionList/TopicIntroduction.js +2 -4
- package/es/TopicIntroductionList/TopicShortcutItem.js +1 -3
- package/es/TreeStructure/FolderItem.js +130 -0
- package/es/TreeStructure/FolderItems.js +123 -0
- package/es/TreeStructure/FolderNameInput.js +112 -0
- package/es/TreeStructure/TreeStructure.js +254 -0
- package/es/TreeStructure/TreeStructure.types.js +0 -0
- package/es/TreeStructure/TreeStructureWrapper.js +13 -0
- package/es/TreeStructure/helperFunctions.js +92 -0
- package/es/TreeStructure/index.js +9 -0
- package/es/TreeStructure/keyboardNavigation/keyboardNavigation.js +182 -0
- package/es/TreeStructure/keyboardNavigation/keyboardNavigation.types.js +0 -0
- package/es/User/AuthModal.js +15 -24
- package/es/User/UserInfo.js +70 -0
- package/es/User/apiTypes.js +0 -0
- package/es/User/index.js +2 -0
- package/es/User/parseUserObject.js +102 -0
- package/es/all.css +90 -0
- package/es/index.js +9 -3
- package/es/locale/messages-en.js +75 -8
- package/es/locale/messages-nb.js +74 -7
- package/es/locale/messages-nn.js +74 -7
- package/es/locale/messages-se.js +74 -7
- package/es/locale/messages-sma.js +74 -7
- package/lib/Article/Article.d.ts +3 -1
- package/lib/Article/Article.js +43 -23
- package/lib/Article/ArticleFavoritesButton.d.ts +15 -0
- package/lib/Article/ArticleFavoritesButton.js +56 -0
- package/lib/Article/index.d.ts +2 -1
- package/lib/Article/index.js +8 -0
- package/lib/Breadcrumb/ActionBreadcrumb.d.ts +16 -0
- package/lib/Breadcrumb/ActionBreadcrumb.js +72 -0
- package/lib/Breadcrumb/index.d.ts +1 -0
- package/lib/Breadcrumb/index.js +8 -0
- package/lib/Footer/FooterAuth.d.ts +1 -1
- package/lib/Footer/FooterAuth.js +17 -17
- package/lib/InfoBlock/InfoBlock.d.ts +8 -0
- package/lib/InfoBlock/InfoBlock.js +58 -0
- package/lib/InfoBlock/index.d.ts +1 -0
- package/lib/InfoBlock/index.js +13 -0
- package/lib/LearningPaths/LearningPathMenu.js +3 -4
- package/lib/Masthead/MastheadAuthModal.d.ts +3 -3
- package/lib/Masthead/MastheadAuthModal.js +3 -3
- package/lib/MyNdla/Navigation/VerticalNavigation.d.ts +10 -0
- package/lib/MyNdla/Navigation/VerticalNavigation.js +61 -0
- package/lib/MyNdla/Navigation/index.d.ts +2 -0
- package/lib/MyNdla/Navigation/index.js +15 -0
- package/lib/MyNdla/Resource/Folder.d.ts +20 -0
- package/lib/MyNdla/Resource/Folder.js +100 -0
- package/lib/MyNdla/Resource/index.d.ts +9 -0
- package/lib/MyNdla/Resource/index.js +15 -0
- package/lib/MyNdla/index.d.ts +3 -4
- package/lib/MyNdla/index.js +9 -11
- package/lib/Notion/ConceptNotion.js +2 -1
- package/lib/Notion/FigureNotion.d.ts +1 -1
- package/lib/Notion/FigureNotion.js +12 -8
- package/lib/Notion/NotionVisualElement.js +3 -2
- package/lib/Resource/BlockResource.d.ts +20 -0
- package/lib/Resource/BlockResource.js +84 -0
- package/lib/Resource/ListResource.d.ts +20 -0
- package/lib/Resource/ListResource.js +78 -0
- package/lib/Resource/index.d.ts +11 -0
- package/lib/Resource/index.js +29 -0
- package/lib/Resource/resourceComponents.d.ts +24 -0
- package/lib/Resource/resourceComponents.js +106 -0
- package/lib/ResourceGroup/ResourceGroup.d.ts +2 -1
- package/lib/ResourceGroup/ResourceGroup.js +7 -5
- package/lib/ResourceGroup/ResourceItem.d.ts +5 -1
- package/lib/ResourceGroup/ResourceItem.js +29 -30
- package/lib/ResourceGroup/ResourceList.d.ts +3 -1
- package/lib/ResourceGroup/ResourceList.js +18 -6
- package/lib/Search/ActiveFilters.js +6 -7
- package/lib/Search/ContentTypeResult.js +6 -8
- package/lib/SearchTypeResult/ActiveFilters.js +6 -10
- package/lib/SearchTypeResult/SearchViewType.js +5 -5
- package/lib/SnackBar/SnackBar.d.ts +23 -0
- package/lib/SnackBar/SnackBar.js +127 -0
- package/lib/SnackBar/index.d.ts +10 -0
- package/lib/SnackBar/index.js +15 -0
- package/lib/TagSelector/SuggestionInput.d.ts +19 -0
- package/lib/TagSelector/SuggestionInput.js +255 -0
- package/lib/TagSelector/Suggestions.d.ts +12 -0
- package/lib/TagSelector/Suggestions.js +96 -0
- package/lib/TagSelector/TagSelector.d.ts +16 -0
- package/lib/TagSelector/TagSelector.js +150 -0
- package/lib/TagSelector/index.d.ts +10 -0
- package/lib/TagSelector/index.js +19 -0
- package/lib/TopicIntroductionList/TopicIntroduction.js +2 -4
- package/lib/TopicIntroductionList/TopicShortcutItem.js +1 -3
- package/lib/TreeStructure/FolderItem.d.ts +27 -0
- package/lib/TreeStructure/FolderItem.js +140 -0
- package/lib/TreeStructure/FolderItems.d.ts +11 -0
- package/lib/TreeStructure/FolderItems.js +130 -0
- package/lib/TreeStructure/FolderNameInput.d.ts +15 -0
- package/lib/TreeStructure/FolderNameInput.js +125 -0
- package/lib/TreeStructure/TreeStructure.d.ts +12 -0
- package/lib/TreeStructure/TreeStructure.js +273 -0
- package/lib/TreeStructure/TreeStructure.types.d.ts +63 -0
- package/lib/TreeStructure/TreeStructure.types.js +1 -0
- package/lib/TreeStructure/TreeStructureWrapper.d.ts +12 -0
- package/lib/TreeStructure/TreeStructureWrapper.js +24 -0
- package/lib/TreeStructure/helperFunctions.d.ts +5 -0
- package/lib/TreeStructure/helperFunctions.js +103 -0
- package/lib/TreeStructure/index.d.ts +10 -0
- package/lib/TreeStructure/index.js +15 -0
- package/lib/TreeStructure/keyboardNavigation/keyboardNavigation.d.ts +11 -0
- package/lib/TreeStructure/keyboardNavigation/keyboardNavigation.js +186 -0
- package/lib/TreeStructure/keyboardNavigation/keyboardNavigation.types.d.ts +26 -0
- package/lib/TreeStructure/keyboardNavigation/keyboardNavigation.types.js +1 -0
- package/lib/User/AuthModal.d.ts +3 -3
- package/lib/User/AuthModal.js +16 -23
- package/lib/User/UserInfo.d.ts +13 -0
- package/lib/User/UserInfo.js +84 -0
- package/lib/User/apiTypes.d.ts +61 -0
- package/lib/User/apiTypes.js +1 -0
- package/lib/User/index.d.ts +4 -0
- package/lib/User/index.js +8 -0
- package/lib/User/parseUserObject.d.ts +32 -0
- package/lib/User/parseUserObject.js +105 -0
- package/lib/all.css +90 -0
- package/lib/index.d.ts +14 -3
- package/lib/index.js +76 -10
- package/lib/locale/messages-en.d.ts +67 -0
- package/lib/locale/messages-en.js +75 -8
- package/lib/locale/messages-nb.d.ts +67 -0
- package/lib/locale/messages-nb.js +74 -7
- package/lib/locale/messages-nn.d.ts +67 -0
- package/lib/locale/messages-nn.js +74 -7
- package/lib/locale/messages-se.d.ts +67 -0
- package/lib/locale/messages-se.js +74 -7
- package/lib/locale/messages-sma.d.ts +67 -0
- package/lib/locale/messages-sma.js +74 -7
- package/lib/types.d.ts +1 -1
- package/package.json +11 -11
- package/src/Article/Article.tsx +31 -0
- package/src/Article/ArticleFavoritesButton.tsx +40 -0
- package/src/Article/index.ts +2 -0
- package/src/Breadcrumb/ActionBreadcrumb.tsx +68 -0
- package/src/Breadcrumb/index.ts +2 -0
- package/src/Footer/FooterAuth.tsx +7 -9
- package/src/InfoBlock/InfoBlock.tsx +61 -0
- package/src/InfoBlock/index.ts +1 -0
- package/src/LearningPaths/LearningPathMenu.tsx +1 -1
- package/src/Masthead/MastheadAuthModal.tsx +4 -5
- package/src/MyNdla/Navigation/VerticalNavigation.tsx +93 -0
- package/src/MyNdla/Navigation/index.ts +2 -0
- package/src/MyNdla/Resource/Folder.tsx +143 -0
- package/src/MyNdla/Resource/index.ts +10 -0
- package/src/MyNdla/index.ts +3 -5
- package/src/Notion/ConceptNotion.tsx +1 -0
- package/src/Notion/FigureNotion.tsx +12 -5
- package/src/Notion/NotionVisualElement.tsx +1 -1
- package/src/Resource/BlockResource.tsx +101 -0
- package/src/Resource/ListResource.tsx +111 -0
- package/src/Resource/index.ts +12 -0
- package/src/Resource/resourceComponents.tsx +143 -0
- package/src/ResourceGroup/ResourceGroup.tsx +3 -0
- package/src/ResourceGroup/ResourceItem.tsx +20 -3
- package/src/ResourceGroup/ResourceList.tsx +16 -3
- package/src/Search/ActiveFilters.jsx +0 -1
- package/src/Search/ContentTypeResult.tsx +8 -9
- package/src/SearchTypeResult/ActiveFilters.tsx +1 -3
- package/src/SearchTypeResult/SearchViewType.tsx +1 -1
- package/src/SnackBar/SnackBar.tsx +183 -0
- package/src/SnackBar/index.ts +13 -0
- package/src/TagSelector/SuggestionInput.tsx +230 -0
- package/src/TagSelector/Suggestions.tsx +125 -0
- package/src/TagSelector/TagSelector.tsx +111 -0
- package/src/TagSelector/index.ts +13 -0
- package/src/TopicIntroductionList/TopicIntroduction.tsx +2 -2
- package/src/TopicIntroductionList/TopicShortcutItem.tsx +1 -5
- package/src/TreeStructure/FolderItem.tsx +160 -0
- package/src/TreeStructure/FolderItems.tsx +109 -0
- package/src/TreeStructure/FolderNameInput.tsx +109 -0
- package/src/TreeStructure/TreeStructure.tsx +184 -0
- package/src/TreeStructure/TreeStructure.types.ts +69 -0
- package/src/TreeStructure/TreeStructureWrapper.tsx +34 -0
- package/src/TreeStructure/helperFunctions.ts +52 -0
- package/src/TreeStructure/index.ts +11 -0
- package/src/TreeStructure/keyboardNavigation/keyboardNavigation.ts +161 -0
- package/src/TreeStructure/keyboardNavigation/keyboardNavigation.types.ts +28 -0
- package/src/User/AuthModal.tsx +5 -26
- package/src/User/UserInfo.tsx +80 -0
- package/src/User/__tests__/parseUserObject-test.ts +315 -0
- package/src/User/apiTypes.ts +74 -0
- package/src/User/index.ts +4 -0
- package/src/User/parseUserObject.ts +83 -0
- package/src/all.scss +2 -0
- package/src/index.ts +15 -4
- package/src/locale/messages-en.ts +69 -7
- package/src/locale/messages-nb.ts +68 -6
- package/src/locale/messages-nn.ts +68 -6
- package/src/locale/messages-se.ts +68 -6
- package/src/locale/messages-sma.ts +68 -6
- package/src/types.ts +1 -1
- package/es/MyNdla/ResourceDash/Breadcrumbs.js +0 -22
- package/es/MyNdla/ResourceDash/ResourceElement.js +0 -27
- package/es/MyNdla/ResourceDash/ResourcesView.js +0 -43
- package/es/MyNdla/ResourceDash/index.js +0 -4
- package/lib/MyNdla/ResourceDash/Breadcrumbs.d.ts +0 -15
- package/lib/MyNdla/ResourceDash/Breadcrumbs.js +0 -35
- package/lib/MyNdla/ResourceDash/ResourceElement.d.ts +0 -18
- package/lib/MyNdla/ResourceDash/ResourceElement.js +0 -38
- package/lib/MyNdla/ResourceDash/ResourcesView.js +0 -57
- package/lib/MyNdla/ResourceDash/index.d.ts +0 -4
- package/lib/MyNdla/ResourceDash/index.js +0 -31
- package/src/MyNdla/ResourceDash/Breadcrumbs.tsx +0 -31
- package/src/MyNdla/ResourceDash/ResourceElement.tsx +0 -50
- package/src/MyNdla/ResourceDash/ResourcesView.tsx +0 -42
- package/src/MyNdla/ResourceDash/index.ts +0 -5
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFolderName = exports.getIdPathsOfFolder = exports.getPathOfFolder = void 0;
|
|
7
|
+
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
13
|
+
|
|
14
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
+
|
|
16
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
17
|
+
|
|
18
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
19
|
+
|
|
20
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
|
+
|
|
22
|
+
var getPathOfFolder = function getPathOfFolder(data, findId) {
|
|
23
|
+
var paths = function paths(dataChildren, path) {
|
|
24
|
+
var _iterator = _createForOfIteratorHelper(dataChildren),
|
|
25
|
+
_step;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
29
|
+
var _step$value = _step.value,
|
|
30
|
+
id = _step$value.id,
|
|
31
|
+
dataChildrenSub = _step$value.data;
|
|
32
|
+
|
|
33
|
+
if (id === findId) {
|
|
34
|
+
return [].concat(_toConsumableArray(path), [id]);
|
|
35
|
+
} else if (dataChildrenSub === null || dataChildrenSub === void 0 ? void 0 : dataChildrenSub.length) {
|
|
36
|
+
return paths(dataChildrenSub, [].concat(_toConsumableArray(path), [id]));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
_iterator.e(err);
|
|
41
|
+
} finally {
|
|
42
|
+
_iterator.f();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return [];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return paths(data, []);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.getPathOfFolder = getPathOfFolder;
|
|
52
|
+
|
|
53
|
+
var getIdPathsOfFolder = function getIdPathsOfFolder(data, findId) {
|
|
54
|
+
var currentPath = [];
|
|
55
|
+
|
|
56
|
+
var paths = function paths(dataChildren, path) {
|
|
57
|
+
dataChildren.forEach(function (_ref, _index) {
|
|
58
|
+
var id = _ref.id,
|
|
59
|
+
dataChildrenSub = _ref.data;
|
|
60
|
+
|
|
61
|
+
if (id === findId) {
|
|
62
|
+
currentPath = [].concat(_toConsumableArray(path), [_index]);
|
|
63
|
+
} else if (dataChildrenSub === null || dataChildrenSub === void 0 ? void 0 : dataChildrenSub.length) {
|
|
64
|
+
paths(dataChildrenSub, [].concat(_toConsumableArray(path), [_index]));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
paths(data, []);
|
|
70
|
+
return currentPath;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
exports.getIdPathsOfFolder = getIdPathsOfFolder;
|
|
74
|
+
|
|
75
|
+
var getFolderName = function getFolderName(data, findId) {
|
|
76
|
+
if (!findId) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var folderName;
|
|
81
|
+
|
|
82
|
+
var paths = function paths(dataChildren) {
|
|
83
|
+
dataChildren.some(function (_ref2, _index) {
|
|
84
|
+
var id = _ref2.id,
|
|
85
|
+
name = _ref2.name,
|
|
86
|
+
dataChildrenSub = _ref2.data;
|
|
87
|
+
|
|
88
|
+
if (id === findId) {
|
|
89
|
+
folderName = name;
|
|
90
|
+
return true;
|
|
91
|
+
} else if (dataChildrenSub === null || dataChildrenSub === void 0 ? void 0 : dataChildrenSub.length) {
|
|
92
|
+
return paths(dataChildrenSub);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
paths(data);
|
|
100
|
+
return folderName;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.getFolderName = getFolderName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import TreeStructure from './TreeStructure';
|
|
9
|
+
export type { FolderStructureProps, TreeStructureProps } from './TreeStructure.types';
|
|
10
|
+
export { TreeStructure };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "TreeStructure", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _TreeStructure["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _TreeStructure = _interopRequireDefault(require("./TreeStructure"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { KeyboardNavigationProps } from './keyboardNavigation.types';
|
|
9
|
+
export declare const KEYBOARD_KEYS_OF_INTEREST: string[];
|
|
10
|
+
declare const keyboardNavigation: ({ e, data, onToggleOpen, setFocusedFolderId, focusedFolderId: id, openFolders, }: KeyboardNavigationProps) => string | undefined;
|
|
11
|
+
export default keyboardNavigation;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.KEYBOARD_KEYS_OF_INTEREST = void 0;
|
|
7
|
+
|
|
8
|
+
var _TreeStructure = require("../TreeStructure");
|
|
9
|
+
|
|
10
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
+
|
|
12
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
|
|
16
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
17
|
+
|
|
18
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
|
+
|
|
20
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
|
+
|
|
22
|
+
var KEYBOARD_KEYS_OF_INTEREST = ['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft', ' ']; // Traverse upwards, incase parent is last element of its parent..
|
|
23
|
+
|
|
24
|
+
exports.KEYBOARD_KEYS_OF_INTEREST = KEYBOARD_KEYS_OF_INTEREST;
|
|
25
|
+
|
|
26
|
+
var traverseUpwards = function traverseUpwards(inital, setFocusedFolderId, paths, index) {
|
|
27
|
+
var findParent = inital;
|
|
28
|
+
var parentNextIds = [];
|
|
29
|
+
paths.forEach(function (pathIndex) {
|
|
30
|
+
var nextParent = findParent ? findParent[pathIndex + 1] : undefined;
|
|
31
|
+
parentNextIds.push((nextParent === null || nextParent === void 0 ? void 0 : nextParent.id) || false);
|
|
32
|
+
findParent = findParent[pathIndex].data || [];
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!parentNextIds.length) {
|
|
36
|
+
var _findParent;
|
|
37
|
+
|
|
38
|
+
parentNextIds.push(((_findParent = findParent[index + 1]) === null || _findParent === void 0 ? void 0 : _findParent.id) || false);
|
|
39
|
+
} // We use a reversed version of parentNextIds, filtered out falses, to find the next element
|
|
40
|
+
// No newId? We are at the end of the tree so we wont update.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
var newId = parentNextIds.reverse().filter(function (id) {
|
|
44
|
+
return id;
|
|
45
|
+
})[0];
|
|
46
|
+
|
|
47
|
+
if (newId) {
|
|
48
|
+
setFocusedFolderId(newId);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var keyboardNavigation = function keyboardNavigation(_ref) {
|
|
53
|
+
var _document$activeEleme, _elementWithKeyFocus$3;
|
|
54
|
+
|
|
55
|
+
var e = _ref.e,
|
|
56
|
+
data = _ref.data,
|
|
57
|
+
onToggleOpen = _ref.onToggleOpen,
|
|
58
|
+
setFocusedFolderId = _ref.setFocusedFolderId,
|
|
59
|
+
id = _ref.focusedFolderId,
|
|
60
|
+
openFolders = _ref.openFolders;
|
|
61
|
+
|
|
62
|
+
if (e.key === ' ' && ((_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.nodeName) === 'INPUT') {
|
|
63
|
+
return;
|
|
64
|
+
} // We are navigating in the tree.
|
|
65
|
+
// We need to find the next folder in the tree
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
var elementWithKeyFocus = {
|
|
69
|
+
paths: [],
|
|
70
|
+
index: 0
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var updatePathToElementWithKeyFocus = function updatePathToElementWithKeyFocus(data, paths, parent, parentId) {
|
|
74
|
+
return data.some(function (_ref2, _index) {
|
|
75
|
+
var childData = _ref2.data,
|
|
76
|
+
dataId = _ref2.id,
|
|
77
|
+
url = _ref2.url;
|
|
78
|
+
|
|
79
|
+
if (dataId === id) {
|
|
80
|
+
elementWithKeyFocus.paths = paths;
|
|
81
|
+
elementWithKeyFocus.index = _index;
|
|
82
|
+
elementWithKeyFocus.isOpen = openFolders.has(dataId) && childData && childData.length > 0;
|
|
83
|
+
elementWithKeyFocus.data = childData;
|
|
84
|
+
elementWithKeyFocus.parent = parent;
|
|
85
|
+
elementWithKeyFocus.parentId = parentId;
|
|
86
|
+
elementWithKeyFocus.url = url;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return childData ? updatePathToElementWithKeyFocus(childData, [].concat(_toConsumableArray(paths), [_index]), _toConsumableArray(childData), dataId) : false;
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (!updatePathToElementWithKeyFocus(data, [], data)) {
|
|
95
|
+
// Couldn't find its location in the tree.
|
|
96
|
+
// This should not happen, reset its value to root.
|
|
97
|
+
setFocusedFolderId(e.key === 'ArrowDown' ? data[0].id : undefined);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
|
|
104
|
+
if (e.key === ' ') {
|
|
105
|
+
var simulatedEvent = new MouseEvent('click', {
|
|
106
|
+
bubbles: true,
|
|
107
|
+
cancelable: true,
|
|
108
|
+
view: window
|
|
109
|
+
});
|
|
110
|
+
document.activeElement && document.activeElement.dispatchEvent(simulatedEvent);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (e.key === 'ArrowRight') {
|
|
115
|
+
var _elementWithKeyFocus$;
|
|
116
|
+
|
|
117
|
+
if (!elementWithKeyFocus.isOpen && ((_elementWithKeyFocus$ = elementWithKeyFocus.data) === null || _elementWithKeyFocus$ === void 0 ? void 0 : _elementWithKeyFocus$.length) && id && elementWithKeyFocus.paths.length < _TreeStructure.MAX_LEVEL_FOR_FOLDERS - 1) {
|
|
118
|
+
onToggleOpen(id);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (e.key === 'ArrowLeft') {
|
|
125
|
+
if (id && elementWithKeyFocus.isOpen) {
|
|
126
|
+
onToggleOpen(id);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!id && e.key === 'ArrowDown') {
|
|
133
|
+
setFocusedFolderId(data[0].id);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!id) {
|
|
138
|
+
return;
|
|
139
|
+
} // Move up
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if (e.key === 'ArrowUp') {
|
|
143
|
+
if (elementWithKeyFocus.index > 0) {
|
|
144
|
+
// Move upwards to the parent folder
|
|
145
|
+
setFocusedFolderId(elementWithKeyFocus.parent ? elementWithKeyFocus.parent[elementWithKeyFocus.index - 1].id : undefined);
|
|
146
|
+
} else if (elementWithKeyFocus.paths.length > 0) {
|
|
147
|
+
elementWithKeyFocus.paths.pop();
|
|
148
|
+
var findParent = data;
|
|
149
|
+
elementWithKeyFocus.paths.forEach(function (index) {
|
|
150
|
+
findParent = findParent[index].data;
|
|
151
|
+
});
|
|
152
|
+
var parentsCurrentIndex = findParent.findIndex(function (_ref3) {
|
|
153
|
+
var id = _ref3.id;
|
|
154
|
+
return id === elementWithKeyFocus.parentId;
|
|
155
|
+
});
|
|
156
|
+
setFocusedFolderId(findParent[parentsCurrentIndex].id);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (elementWithKeyFocus.isOpen) {
|
|
163
|
+
var _elementWithKeyFocus$2;
|
|
164
|
+
|
|
165
|
+
if ((_elementWithKeyFocus$2 = elementWithKeyFocus.data) === null || _elementWithKeyFocus$2 === void 0 ? void 0 : _elementWithKeyFocus$2.length) {
|
|
166
|
+
setFocusedFolderId(elementWithKeyFocus.data[0].id);
|
|
167
|
+
} else {
|
|
168
|
+
// move to next child of parent if any... need new traverse :-/
|
|
169
|
+
traverseUpwards(data, setFocusedFolderId, elementWithKeyFocus.paths, elementWithKeyFocus.index);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (elementWithKeyFocus.parent && elementWithKeyFocus.index < ((_elementWithKeyFocus$3 = elementWithKeyFocus.parent) === null || _elementWithKeyFocus$3 === void 0 ? void 0 : _elementWithKeyFocus$3.length) - 1) {
|
|
176
|
+
// Move downwards to the next child
|
|
177
|
+
setFocusedFolderId(elementWithKeyFocus.parent[elementWithKeyFocus.index + 1].id);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
traverseUpwards(data, setFocusedFolderId, elementWithKeyFocus.paths, elementWithKeyFocus.index);
|
|
182
|
+
return;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
var _default = keyboardNavigation;
|
|
186
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/// <reference types="react" />
|
|
9
|
+
import { FolderStructureProps, SetFocusedFolderId } from '../TreeStructure.types';
|
|
10
|
+
export interface KeyboardNavigationProps {
|
|
11
|
+
e: React.KeyboardEvent<HTMLElement>;
|
|
12
|
+
data: FolderStructureProps[];
|
|
13
|
+
setFocusedFolderId: SetFocusedFolderId;
|
|
14
|
+
openFolders: Set<string>;
|
|
15
|
+
onToggleOpen: (id: string) => void;
|
|
16
|
+
focusedFolderId: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface ElementWithKeyFocusProps {
|
|
19
|
+
paths: number[];
|
|
20
|
+
index: number;
|
|
21
|
+
data?: FolderStructureProps[];
|
|
22
|
+
parent?: FolderStructureProps[];
|
|
23
|
+
parentId?: string;
|
|
24
|
+
isOpen?: boolean;
|
|
25
|
+
url?: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/lib/User/AuthModal.d.ts
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import { ReactElement, ReactNode } from 'react';
|
|
9
|
+
import { FeideUserApiType } from './apiTypes';
|
|
9
10
|
export declare type AuthModalProps = {
|
|
10
11
|
isAuthenticated?: boolean;
|
|
12
|
+
user?: FeideUserApiType;
|
|
11
13
|
showGeneralMessage?: boolean;
|
|
12
|
-
authorizedRole?: string;
|
|
13
|
-
authorizedCollectedInfo?: string[];
|
|
14
14
|
onAuthenticateClick: () => void;
|
|
15
15
|
position?: 'top' | 'bottom';
|
|
16
16
|
activateButton?: ReactElement;
|
|
@@ -18,5 +18,5 @@ export declare type AuthModalProps = {
|
|
|
18
18
|
isOpen?: boolean;
|
|
19
19
|
onClose?: () => void;
|
|
20
20
|
};
|
|
21
|
-
declare const AuthModal: ({ isAuthenticated,
|
|
21
|
+
declare const AuthModal: ({ isAuthenticated, user, showGeneralMessage, onAuthenticateClick, position, activateButton, children, isOpen, onClose, }: AuthModalProps) => JSX.Element;
|
|
22
22
|
export default AuthModal;
|