@ndla/ui 56.0.33-alpha.0 → 56.0.35-alpha.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.
@@ -1,29 +0,0 @@
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
-
9
- export const flattenFolders = (folders, openFolders) => {
10
- return folders.reduce((acc, _ref) => {
11
- let {
12
- subfolders,
13
- id,
14
- ...rest
15
- } = _ref;
16
- if (!subfolders || openFolders && !openFolders.includes(id)) {
17
- return acc.concat({
18
- subfolders,
19
- id,
20
- ...rest
21
- });
22
- }
23
- return acc.concat({
24
- subfolders,
25
- id,
26
- ...rest
27
- }, flattenFolders(subfolders, openFolders));
28
- }, []);
29
- };
@@ -1,9 +0,0 @@
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
-
9
- export { TreeStructure } from "./TreeStructure";
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-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
- export declare const LayoutItem: import("@ndla/styled-system/types").StyledComponent<"section", {
9
- layout?: "center" | "extend" | undefined;
10
- }>;
11
- export default LayoutItem;
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.LayoutItem = void 0;
7
- var _jsx = require("@ndla/styled-system/jsx");
8
- /**
9
- * Copyright (c) 2016-present, NDLA.
10
- *
11
- * This source code is licensed under the GPLv3 license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- *
14
- */
15
-
16
- // TODO: Refactor this. This is a copy of our old layout.
17
- const LayoutItem = exports.LayoutItem = (0, _jsx.styled)("section", {
18
- defaultVariants: {
19
- layout: "center"
20
- },
21
- variants: {
22
- layout: {
23
- center: {
24
- position: "relative!",
25
- width: "83.333%",
26
- right: "auto !important",
27
- left: "8.333%"
28
- },
29
- extend: {
30
- tablet: {
31
- position: "relative!",
32
- width: "83.333%",
33
- right: "auto!",
34
- left: "8.333%"
35
- }
36
- }
37
- }
38
- }
39
- });
40
- var _default = exports.default = LayoutItem;
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-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 { IFolder, IResource } from "@ndla/types-backend/myndla-api";
9
- import { NewFolderInputFunc } from "./types";
10
- export declare const MAX_LEVEL_FOR_FOLDERS = 5;
11
- export interface TreeStructureProps {
12
- loading?: boolean;
13
- targetResource?: IResource;
14
- defaultOpenFolders?: string[];
15
- folders: IFolder[];
16
- label?: string;
17
- maxLevel?: number;
18
- newFolderInput?: NewFolderInputFunc;
19
- onSelectFolder?: (id: string) => void;
20
- ariaDescribedby?: string;
21
- }
22
- export declare const TreeStructure: ({ folders, defaultOpenFolders, newFolderInput, label, targetResource, loading, maxLevel, onSelectFolder, ariaDescribedby, }: TreeStructureProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,325 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TreeStructure = exports.MAX_LEVEL_FOR_FOLDERS = void 0;
7
- var _react = require("react");
8
- var _reactDom = require("react-dom");
9
- var _reactI18next = require("react-i18next");
10
- var _react2 = require("@ark-ui/react");
11
- var _action = require("@ndla/icons/action");
12
- var _common = require("@ndla/icons/common");
13
- var _contentType = require("@ndla/icons/contentType");
14
- var _editor = require("@ndla/icons/editor");
15
- var _primitives = require("@ndla/primitives");
16
- var _jsx2 = require("@ndla/styled-system/jsx");
17
- var _helperFunctions = require("./helperFunctions");
18
- var _jsxRuntime = require("react/jsx-runtime");
19
- /**
20
- * Copyright (c) 2024-present, NDLA.
21
- *
22
- * This source code is licensed under the GPLv3 license found in the
23
- * LICENSE file in the root directory of this source tree.
24
- *
25
- */
26
-
27
- const MAX_LEVEL_FOR_FOLDERS = exports.MAX_LEVEL_FOR_FOLDERS = 5;
28
- const StyledButton = (0, _jsx2.styled)(_primitives.Button, {
29
- base: {
30
- width: "100%",
31
- justifyContent: "space-between",
32
- "& span": {
33
- overflow: "hidden",
34
- textOverflow: "ellipsis"
35
- }
36
- }
37
- });
38
- const StyledHStack = (0, _jsx2.styled)(_jsx2.HStack, {
39
- base: {
40
- overflow: "hidden"
41
- }
42
- });
43
- const StyledHeartFill = (0, _jsx2.styled)(_action.HeartFill, {
44
- base: {
45
- color: "icon.strong"
46
- }
47
- });
48
- const StyledFolderLine = (0, _jsx2.styled)(_editor.FolderLine, {
49
- base: {
50
- color: "icon.strong"
51
- }
52
- });
53
- const StyledFolderUserLine = (0, _jsx2.styled)(_contentType.FolderUserLine, {
54
- base: {
55
- color: "icon.strong"
56
- }
57
- });
58
- const StyledTreeRootProvider = (0, _jsx2.styled)(_primitives.TreeRootProvider, {
59
- base: {
60
- width: "100%",
61
- maxHeight: "inherit"
62
- }
63
- });
64
- const StyledPopoverContent = (0, _jsx2.styled)(_primitives.PopoverContent, {
65
- base: {
66
- display: "flex",
67
- flexDirection: "column",
68
- gap: "xsmall",
69
- overflow: "auto",
70
- maxHeight: "inherit",
71
- paddingInline: "xsmall",
72
- paddingBlock: "xsmall"
73
- }
74
- });
75
- const LabelHStack = (0, _jsx2.styled)(_jsx2.HStack, {
76
- base: {
77
- width: "100%"
78
- }
79
- });
80
- const TreeStructure = _ref => {
81
- let {
82
- folders,
83
- defaultOpenFolders,
84
- newFolderInput,
85
- label,
86
- targetResource,
87
- loading,
88
- maxLevel = MAX_LEVEL_FOR_FOLDERS,
89
- onSelectFolder,
90
- ariaDescribedby
91
- } = _ref;
92
- const [open, setOpen] = (0, _react.useState)(false);
93
- const [selectedValue, setSelectedValue] = (0, _react.useState)(defaultOpenFolders?.[defaultOpenFolders?.length - 1] ?? "");
94
- const [expandedValue, setExpandedValue] = (0, _react.useState)(defaultOpenFolders ?? []);
95
- const [focusedValue, setFocusedValue] = (0, _react.useState)(selectedValue);
96
- const [newFolderParentId, setNewFolderParentId] = (0, _react.useState)(null);
97
- const newFolderButtonRef = (0, _react.useRef)(null);
98
- const {
99
- t
100
- } = (0, _reactI18next.useTranslation)();
101
- const rootFolderIds = (0, _react.useMemo)(() => folders.map(folder => folder.id), [folders]);
102
- const contentRef = (0, _react.useRef)(null);
103
- const selectedFolder = (0, _react.useMemo)(() => {
104
- return (0, _helperFunctions.flattenFolders)(folders).find(folder => folder.id === selectedValue);
105
- }, [folders, selectedValue]);
106
- const disableCreateFolder = (0, _react.useMemo)(() => {
107
- return (selectedFolder?.breadcrumbs.length ?? 0) > maxLevel - 1;
108
- }, [maxLevel, selectedFolder?.breadcrumbs.length]);
109
- const onOpenChange = (0, _react.useCallback)(details => {
110
- setOpen(details.open);
111
- if (!details.open) {
112
- setNewFolderParentId(null);
113
- }
114
- }, []);
115
- const onKeyDown = (0, _react.useCallback)(e => {
116
- if (e.key === "ArrowUp" || e.key === "ArrowDown") {
117
- e.stopPropagation();
118
- setOpen(true);
119
- }
120
- }, []);
121
- const onShowInput = (0, _react.useCallback)(() => {
122
- if (disableCreateFolder) return;
123
- const flattenedFolders = (0, _helperFunctions.flattenFolders)(folders);
124
- const folder = flattenedFolders.find(folder => folder.id === selectedValue);
125
- const newExpandedIds = rootFolderIds.concat(folder?.breadcrumbs.map(bc => bc.id) ?? []);
126
- setOpen(true);
127
- setExpandedValue(prev => Array.from(new Set([...prev, ...newExpandedIds])));
128
- setNewFolderParentId(selectedValue);
129
- }, [disableCreateFolder, folders, rootFolderIds, selectedValue]);
130
- const treeView = (0, _react2.useTreeView)({
131
- focusedValue,
132
- onFocusChange: details => !!details.focusedValue && setFocusedValue(details.focusedValue),
133
- expandedValue,
134
- onExpandedChange: details => setExpandedValue(details.expandedValue),
135
- selectedValue: [selectedValue],
136
- onSelectionChange: details => {
137
- // TODO: This is currently a bug in zag. The TreeView component simply expects the already selected value to remain selected. As such, always choose the "last" selected value.
138
- const val = details.selectedValue[details.selectedValue.length - 1];
139
- if (!val) return;
140
- if (val === selectedValue && details.focusedValue === selectedValue) {
141
- setOpen(false);
142
- return;
143
- }
144
- setSelectedValue(val);
145
- onSelectFolder?.(val);
146
- },
147
- expandOnClick: false
148
- });
149
- const onCreateFolder = (0, _react.useCallback)(folder => {
150
- if (!folder) return;
151
- const focus = treeView.focusItem;
152
- const expand = treeView.expand;
153
- const select = treeView.select;
154
- (0, _reactDom.flushSync)(() => {
155
- setOpen(true);
156
- });
157
- (0, _reactDom.flushSync)(() => {
158
- expand(folder.breadcrumbs.map(bc => bc.id));
159
- });
160
- (0, _reactDom.flushSync)(() => {
161
- select([folder.id]);
162
- });
163
- (0, _reactDom.flushSync)(() => {
164
- focus(folder.id);
165
- });
166
- setNewFolderParentId(null);
167
- }, [treeView.expand, treeView.focusItem, treeView.select]);
168
- const onAnimationEnd = (0, _react.useCallback)(() => {
169
- if (open && focusedValue) {
170
- document.getElementById(focusedValue)?.scrollIntoView({
171
- behavior: "smooth",
172
- block: "nearest"
173
- });
174
- }
175
- }, [focusedValue, open]);
176
- const onCancelFolder = (0, _react.useCallback)(() => {
177
- if (!selectedFolder) return;
178
- const focusFunc = selectedFolder.subfolders.length ? treeView.focusBranch : treeView.focusItem;
179
- focusFunc(selectedFolder.id);
180
- setNewFolderParentId(null);
181
- }, [selectedFolder, treeView.focusBranch, treeView.focusItem]);
182
- const addTooltip = loading ? t("loading") : disableCreateFolder ? t("treeStructure.maxFoldersAlreadyAdded") : t("myNdla.newFolderUnder", {
183
- folderName: selectedFolder?.name
184
- });
185
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledTreeRootProvider, {
186
- value: treeView,
187
- asChild: true,
188
- ...treeView.getRootProps(),
189
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsx2.Stack, {
190
- align: "flex-end",
191
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(LabelHStack, {
192
- gap: "xsmall",
193
- justify: "space-between",
194
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeLabel, {
195
- children: label
196
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.Button, {
197
- size: "small",
198
- variant: "tertiary",
199
- ref: newFolderButtonRef,
200
- "aria-disabled": disableCreateFolder,
201
- title: addTooltip,
202
- "aria-label": addTooltip,
203
- loading: loading,
204
- onClick: onShowInput,
205
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_action.AddLine, {}), t("myNdla.newFolder")]
206
- })]
207
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.PopoverRoot, {
208
- open: open,
209
- positioning: {
210
- sameWidth: true
211
- },
212
- onOpenChange: onOpenChange,
213
- persistentElements: [() => newFolderButtonRef.current],
214
- initialFocusEl: () => contentRef.current?.querySelector("input") ?? null,
215
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.PopoverTrigger, {
216
- asChild: true,
217
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledButton, {
218
- variant: "secondary",
219
- onKeyDown: onKeyDown,
220
- "aria-haspopup": "tree",
221
- role: "combobox",
222
- "aria-describedby": ariaDescribedby,
223
- "aria-activedescendant": focusedValue ?? undefined,
224
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
225
- children: selectedFolder?.name
226
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_common.ArrowDownShortLine, {})]
227
- })
228
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledPopoverContent, {
229
- onAnimationEnd: onAnimationEnd,
230
- ref: contentRef,
231
- children: [!!newFolderParentId && newFolderInput?.({
232
- parentId: newFolderParentId,
233
- onCreate: onCreateFolder,
234
- onCancel: onCancelFolder
235
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Tree, {
236
- children: folders.map(folder => /*#__PURE__*/(0, _jsxRuntime.jsx)(TreeStructureItem, {
237
- folder: folder,
238
- targetResource: targetResource
239
- }, folder.id))
240
- })]
241
- })]
242
- })]
243
- })
244
- });
245
- };
246
- exports.TreeStructure = TreeStructure;
247
- const TreeStructureItem = _ref2 => {
248
- let {
249
- folder,
250
- targetResource
251
- } = _ref2;
252
- const {
253
- t
254
- } = (0, _reactI18next.useTranslation)();
255
- const {
256
- setOpen
257
- } = (0, _react2.usePopoverContext)();
258
- const containsResource = targetResource && folder.resources.some(resource => resource.resourceId === targetResource.resourceId);
259
- const FolderIcon = folder.status === "shared" ? StyledFolderUserLine : StyledFolderLine;
260
- const onKeyDown = (0, _react.useCallback)(e => {
261
- if (e.key === "Enter") {
262
- setOpen(false);
263
- }
264
- }, [setOpen]);
265
- if (!folder.subfolders.length) {
266
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeItem, {
267
- value: folder.id,
268
- onKeyDown: onKeyDown,
269
- id: folder.id,
270
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledHStack, {
271
- gap: "xsmall",
272
- justify: "space-between",
273
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledHStack, {
274
- gap: "xxsmall",
275
- justify: "center",
276
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(FolderIcon, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeItemText, {
277
- children: folder.name
278
- })]
279
- }), containsResource && /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledHeartFill, {
280
- title: t("myNdla.alreadyInFolder")
281
- })]
282
- })
283
- }, folder.id);
284
- }
285
- const ariaLabel = folder.status === "shared" ? `${folder.name}. ${t("myNdla.folder.sharing.shared")}` : folder.name;
286
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.TreeBranch, {
287
- value: folder.id,
288
- id: folder.id,
289
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeBranchControl, {
290
- onKeyDown: onKeyDown,
291
- asChild: true,
292
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledHStack, {
293
- gap: "xsmall",
294
- justify: "space-between",
295
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledHStack, {
296
- gap: "xxsmall",
297
- justify: "center",
298
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.IconButton, {
299
- variant: "clear",
300
- asChild: true,
301
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeBranchTrigger, {
302
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeBranchIndicator, {
303
- asChild: true,
304
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_common.ArrowRightShortLine, {})
305
- })
306
- })
307
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(FolderIcon, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeBranchText, {
308
- "aria-label": ariaLabel,
309
- title: ariaLabel,
310
- children: folder.name
311
- })]
312
- }), containsResource && /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledHeartFill, {
313
- title: t("myNdla.alreadyInFolder"),
314
- "aria-label": t("myNdla.alreadyInFolder"),
315
- "aria-hidden": false
316
- })]
317
- })
318
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.TreeBranchContent, {
319
- children: folder.subfolders.map(subfolder => /*#__PURE__*/(0, _jsxRuntime.jsx)(TreeStructureItem, {
320
- folder: subfolder,
321
- targetResource: targetResource
322
- }, subfolder.id))
323
- })]
324
- }, folder.id);
325
- };
@@ -1,9 +0,0 @@
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 { IFolder } from "@ndla/types-backend/myndla-api";
9
- export declare const flattenFolders: (folders: IFolder[], openFolders?: string[]) => IFolder[];
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.flattenFolders = void 0;
7
- /**
8
- * Copyright (c) 2022-present, NDLA.
9
- *
10
- * This source code is licensed under the GPLv3 license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- */
14
-
15
- const flattenFolders = (folders, openFolders) => {
16
- return folders.reduce((acc, _ref) => {
17
- let {
18
- subfolders,
19
- id,
20
- ...rest
21
- } = _ref;
22
- if (!subfolders || openFolders && !openFolders.includes(id)) {
23
- return acc.concat({
24
- subfolders,
25
- id,
26
- ...rest
27
- });
28
- }
29
- return acc.concat({
30
- subfolders,
31
- id,
32
- ...rest
33
- }, flattenFolders(subfolders, openFolders));
34
- }, []);
35
- };
36
- exports.flattenFolders = flattenFolders;
@@ -1,9 +0,0 @@
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
- export type { TreeStructureProps } from "./TreeStructure";
9
- export { TreeStructure } from "./TreeStructure";
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "TreeStructure", {
7
- enumerable: true,
8
- get: function () {
9
- return _TreeStructure.TreeStructure;
10
- }
11
- });
12
- var _TreeStructure = require("./TreeStructure");
@@ -1,15 +0,0 @@
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 { ReactNode } from "react";
9
- import { IFolder } from "@ndla/types-backend/myndla-api";
10
- export type OnCreatedFunc = (folder: IFolder | undefined) => void;
11
- export type NewFolderInputFunc = ({ onCancel, parentId, onCreate, }: {
12
- onCancel: () => void;
13
- parentId: string;
14
- onCreate: OnCreatedFunc;
15
- }) => ReactNode;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,36 +0,0 @@
1
- /**
2
- * Copyright (c) 2016-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
-
9
- import { styled } from "@ndla/styled-system/jsx";
10
-
11
- // TODO: Refactor this. This is a copy of our old layout.
12
- export const LayoutItem = styled("section", {
13
- defaultVariants: {
14
- layout: "center",
15
- },
16
- variants: {
17
- layout: {
18
- center: {
19
- position: "relative!",
20
- width: "83.333%",
21
- right: "auto !important",
22
- left: "8.333%",
23
- },
24
- extend: {
25
- tablet: {
26
- position: "relative!",
27
- width: "83.333%",
28
- right: "auto!",
29
- left: "8.333%",
30
- },
31
- },
32
- },
33
- },
34
- });
35
-
36
- export default LayoutItem;