@ndla/image-search 11.0.100-alpha.0 → 11.0.102-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/image-search",
3
- "version": "11.0.100-alpha.0",
3
+ "version": "11.0.102-alpha.0",
4
4
  "description": "A simple library for searching images from NDLA",
5
5
  "license": "GPL-3.0",
6
6
  "main": "lib/index.js",
@@ -26,14 +26,14 @@
26
26
  "es"
27
27
  ],
28
28
  "dependencies": {
29
- "@ndla/icons": "^8.0.57-alpha.0",
29
+ "@ndla/icons": "^8.0.58-alpha.0",
30
30
  "@ndla/licenses": "^9.0.1",
31
- "@ndla/primitives": "^1.0.86-alpha.0",
31
+ "@ndla/primitives": "^1.0.88-alpha.0",
32
32
  "@ndla/styled-system": "^0.0.34",
33
- "@ndla/util": "^5.0.7-alpha.0"
33
+ "@ndla/util": "^5.0.8-alpha.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@ndla/preset-panda": "^0.0.53",
36
+ "@ndla/preset-panda": "^0.0.54",
37
37
  "@ndla/types-backend": "^1.0.40",
38
38
  "@pandacss/dev": "^0.53.6"
39
39
  },
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "0f292ecf99e2b24151c55d6da3f360854fc9d4ea"
47
+ "gitHead": "52adafa4348c1c02ebc4da28317aa5270cbe2a80"
48
48
  }
package/es/ImageMeta.js DELETED
@@ -1,28 +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
- import { useMemo } from "react";
10
- import { Text } from "@ndla/primitives";
11
- import { humanFileSize } from "@ndla/util";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- const ImageMeta = _ref => {
14
- let {
15
- contentType,
16
- fileSize,
17
- imageDimensions,
18
- locale
19
- } = _ref;
20
- const prettySize = useMemo(() => {
21
- return humanFileSize(fileSize, locale);
22
- }, [fileSize, locale]);
23
- const dimensions = imageDimensions ? ` - ${imageDimensions.width}x${imageDimensions.height} px` : "";
24
- return /*#__PURE__*/_jsx(Text, {
25
- children: `${contentType} - ${prettySize}${dimensions}`
26
- });
27
- };
28
- export default ImageMeta;
package/es/ImageSearch.js DELETED
@@ -1,213 +0,0 @@
1
- /**
2
- * Copyright (c) 2017-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 { useEffect, useState } from "react";
10
- import { ArrowLeftShortLine, ArrowRightShortLine, SearchLine } from "@ndla/icons";
11
- import { Button, IconButton, Input, PaginationContext, PaginationEllipsis, PaginationItem, PaginationNextTrigger, PaginationPrevTrigger, PaginationRoot, Text } from "@ndla/primitives";
12
- import { styled } from "@ndla/styled-system/jsx";
13
- import ImageSearchResult from "./ImageSearchResult";
14
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
- const ImageSearchWrapper = styled("div", {
16
- base: {
17
- display: "flex",
18
- flexDirection: "column",
19
- gap: "small"
20
- }
21
- });
22
- const StyledSearchResults = styled("div", {
23
- base: {
24
- display: "grid",
25
- gridTemplateColumns: "repeat(auto-fit, minmax(200px, 1fr))",
26
- gridGap: "xsmall",
27
- gridAutoFlow: "dense"
28
- }
29
- });
30
- const InputWrapper = styled("div", {
31
- base: {
32
- display: "flex",
33
- gap: "xsmall"
34
- }
35
- });
36
- const StyledPaginationRoot = styled(PaginationRoot, {
37
- base: {
38
- flexWrap: "wrap"
39
- }
40
- });
41
- const StyledButton = styled(Button, {
42
- base: {
43
- tabletWideDown: {
44
- paddingInline: "xsmall",
45
- "& span": {
46
- display: "none"
47
- }
48
- }
49
- }
50
- });
51
- const StyledPaginationItem = styled(PaginationItem, {
52
- base: {
53
- tabletWideDown: {
54
- "&:nth-child(2)": {
55
- display: "none"
56
- },
57
- "&:nth-last-child(2)": {
58
- display: "none"
59
- }
60
- }
61
- }
62
- });
63
- const ImageSearch = _ref => {
64
- let {
65
- onImageSelect,
66
- searchImages: search,
67
- onError,
68
- locale,
69
- noResults,
70
- checkboxAction,
71
- showCheckbox,
72
- translations
73
- } = _ref;
74
- const [queryObject, setQueryObject] = useState({
75
- query: undefined,
76
- page: 1,
77
- pageSize: 16
78
- });
79
- const [selectedImage, setSelectedImage] = useState();
80
- const [searching, setSearching] = useState(false);
81
- const [searchResult, setSearchResult] = useState();
82
- const {
83
- page
84
- } = queryObject;
85
- const noResultsFound = !searching && searchResult?.results.length === 0;
86
- const onSelectImage = (image, saveAsMetaImage) => {
87
- setSelectedImage(undefined);
88
- if (!image) return;
89
- onImageSelect(image);
90
- if (saveAsMetaImage) {
91
- checkboxAction?.(image);
92
- }
93
- };
94
- const searchImages = queryObject => {
95
- setSearching(true);
96
- search(queryObject.query, queryObject.page).then(result => {
97
- setQueryObject({
98
- query: queryObject.query,
99
- pageSize: result.pageSize,
100
- page: queryObject.page
101
- });
102
- setSearchResult(result);
103
- setSearching(false);
104
- }).catch(err => {
105
- onError?.(err);
106
- setSearching(false);
107
- });
108
- };
109
- const handleQueryChange = _ref2 => {
110
- let {
111
- target: {
112
- value
113
- }
114
- } = _ref2;
115
- setQueryObject(prevState => ({
116
- ...prevState,
117
- query: value
118
- }));
119
- };
120
- const onEnter = e => {
121
- if (e.key === "Enter") {
122
- searchImages(queryObject);
123
- }
124
- };
125
- useEffect(() => {
126
- searchImages(queryObject);
127
- // eslint-disable-next-line react-hooks/exhaustive-deps
128
- }, []);
129
- return /*#__PURE__*/_jsxs(ImageSearchWrapper, {
130
- children: [/*#__PURE__*/_jsxs(InputWrapper, {
131
- role: "search",
132
- children: [/*#__PURE__*/_jsx(Input, {
133
- type: "search",
134
- placeholder: translations.searchPlaceholder,
135
- value: queryObject?.query ?? "",
136
- onChange: handleQueryChange,
137
- onKeyDown: onEnter
138
- }), /*#__PURE__*/_jsx(IconButton, {
139
- variant: "primary",
140
- "aria-label": translations.searchButtonTitle,
141
- title: translations.searchButtonTitle,
142
- onKeyDown: onEnter,
143
- onClick: () => searchImages(queryObject),
144
- children: /*#__PURE__*/_jsx(SearchLine, {})
145
- })]
146
- }), !!noResultsFound && noResults, /*#__PURE__*/_jsx(StyledSearchResults, {
147
- children: searchResult?.results.map(image => /*#__PURE__*/_jsx(ImageSearchResult, {
148
- image: image,
149
- onImageClick: image => setSelectedImage(image),
150
- selectedImage: selectedImage,
151
- onSelectImage: onSelectImage,
152
- showCheckbox: !!showCheckbox,
153
- translations: translations.imagePreview,
154
- locale: locale
155
- }, image.id))
156
- }), /*#__PURE__*/_jsxs(StyledPaginationRoot, {
157
- page: page ?? 1,
158
- onPageChange: details => searchImages({
159
- ...queryObject,
160
- page: details.page
161
- }),
162
- translations: translations.paginationTranslations,
163
- count: searchResult?.totalCount ?? 0,
164
- pageSize: searchResult?.pageSize,
165
- hidden: noResultsFound,
166
- children: [/*#__PURE__*/_jsx(PaginationPrevTrigger, {
167
- asChild: true,
168
- children: /*#__PURE__*/_jsxs(StyledButton, {
169
- variant: "tertiary",
170
- "aria-label": translations.paginationTranslations?.prevTriggerLabel,
171
- title: translations.paginationTranslations?.prevTriggerLabel,
172
- children: [/*#__PURE__*/_jsx(ArrowLeftShortLine, {}), /*#__PURE__*/_jsx("span", {
173
- children: translations.paginationTranslations?.prevTriggerLabel
174
- })]
175
- })
176
- }), /*#__PURE__*/_jsx(PaginationContext, {
177
- children: pagination => pagination.pages.map((page, index, full) => {
178
- // Hide last page to not trigger RESULT_WINDOW_TOO_LARGE error
179
- if (index === full.length - 1) return null;
180
- return page.type === "page" ? /*#__PURE__*/_jsx(StyledPaginationItem, {
181
- ...page,
182
- asChild: true,
183
- children: /*#__PURE__*/_jsx(Button, {
184
- variant: page.value === pagination.page ? "primary" : "tertiary",
185
- children: page.value
186
- })
187
- }, index) : /*#__PURE__*/_jsx(PaginationEllipsis, {
188
- index: index,
189
- asChild: true,
190
- children: /*#__PURE__*/_jsx(Text, {
191
- asChild: true,
192
- consumeCss: true,
193
- children: /*#__PURE__*/_jsx("div", {
194
- children: "\u2026"
195
- })
196
- })
197
- }, index);
198
- })
199
- }), /*#__PURE__*/_jsx(PaginationNextTrigger, {
200
- asChild: true,
201
- children: /*#__PURE__*/_jsxs(StyledButton, {
202
- variant: "tertiary",
203
- "aria-label": translations.paginationTranslations?.nextTriggerLabel,
204
- title: translations.paginationTranslations?.nextTriggerLabel,
205
- children: [/*#__PURE__*/_jsx("span", {
206
- children: translations.paginationTranslations?.nextTriggerLabel
207
- }), /*#__PURE__*/_jsx(ArrowRightShortLine, {})]
208
- })
209
- })]
210
- })]
211
- });
212
- };
213
- export default ImageSearch;
@@ -1,73 +0,0 @@
1
- /**
2
- * Copyright (c) 2017-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 { Text, Image, Button } from "@ndla/primitives";
10
- import { styled } from "@ndla/styled-system/jsx";
11
- import PreviewImage from "./PreviewImage";
12
- import { getPreviewSrcSets } from "./util/imageUtil";
13
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- const StyledButton = styled(Button, {
15
- base: {
16
- display: "flex",
17
- flexDirection: "column",
18
- borderColor: "stroke.subtle"
19
- }
20
- });
21
- const StyledImage = styled(Image, {
22
- base: {
23
- maxHeight: "135px",
24
- width: "100%",
25
- height: "100%"
26
- }
27
- });
28
- const StyledText = styled(Text, {
29
- base: {
30
- lineClamp: "3"
31
- }
32
- });
33
- export default function ImageSearchResult(_ref) {
34
- let {
35
- image,
36
- onImageClick,
37
- selectedImage,
38
- onSelectImage,
39
- showCheckbox,
40
- translations,
41
- locale
42
- } = _ref;
43
- const isSelectedImage = selectedImage?.id === image.id;
44
- return /*#__PURE__*/_jsxs(_Fragment, {
45
- children: [/*#__PURE__*/_jsxs(StyledButton, {
46
- variant: isSelectedImage ? "secondary" : "tertiary",
47
- "data-testid": "select-image-from-list",
48
- onClick: () => onImageClick(image),
49
- "aria-expanded": isSelectedImage,
50
- "aria-controls": `image-preview-${image.id}`,
51
- children: [/*#__PURE__*/_jsx(StyledImage, {
52
- alt: "",
53
- srcSet: getPreviewSrcSets(image.image.imageUrl),
54
- src: image.image.imageUrl,
55
- variant: "rounded"
56
- }), /*#__PURE__*/_jsx(StyledText, {
57
- textStyle: "label.medium",
58
- asChild: true,
59
- consumeCss: true,
60
- children: /*#__PURE__*/_jsx("span", {
61
- children: image.title.title.trim() ? image.title.title : translations.missingTitleFallback ?? `ID: ${image.id}`
62
- })
63
- })]
64
- }), isSelectedImage ? /*#__PURE__*/_jsx(PreviewImage, {
65
- id: `image-preview-${image.id}`,
66
- image: selectedImage,
67
- onSelectImage: onSelectImage,
68
- translations: translations,
69
- showCheckbox: showCheckbox,
70
- locale: locale
71
- }) : null]
72
- });
73
- }
@@ -1,190 +0,0 @@
1
- /**
2
- * Copyright (c) 2017-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 { useState } from "react";
10
- import { CloseLine, HashTag, CheckLine } from "@ndla/icons";
11
- import { getModelReleaseValue } from "@ndla/licenses";
12
- import { Button, CheckboxControl, CheckboxHiddenInput, CheckboxIndicator, CheckboxLabel, CheckboxRoot, Text, Image, IconButton, FieldRoot } from "@ndla/primitives";
13
- import { styled } from "@ndla/styled-system/jsx";
14
- import ImageMeta from "./ImageMeta";
15
- import { getSrcSets } from "./util/imageUtil";
16
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
- const ImageContainer = styled("div", {
18
- base: {
19
- flexShrink: "0"
20
- }
21
- });
22
- const StyledImage = styled(Image, {
23
- base: {
24
- maxHeight: "surface.xsmall"
25
- }
26
- });
27
- const StyledImageMetadata = styled("div", {
28
- base: {
29
- display: "flex",
30
- flexDirection: "column",
31
- gap: "xxsmall"
32
- }
33
- });
34
- const HashTagWrapper = styled("ul", {
35
- base: {
36
- display: "flex",
37
- gap: "xxsmall",
38
- flexWrap: "wrap"
39
- }
40
- });
41
- const HashTagGroup = styled("div", {
42
- base: {
43
- display: "flex",
44
- gap: "xxsmall",
45
- flexWrap: "wrap"
46
- }
47
- });
48
- const StyledTagItem = styled("li", {
49
- base: {
50
- display: "flex",
51
- alignItems: "center"
52
- }
53
- });
54
- const StyledPreview = styled("div", {
55
- base: {
56
- display: "flex",
57
- gridColumn: "1 / -1",
58
- borderColor: "stroke.default",
59
- border: "1px solid",
60
- borderRadius: "xsmall",
61
- gap: "small",
62
- padding: "small",
63
- flexWrap: "wrap",
64
- overflow: "hidden"
65
- }
66
- });
67
- const StyledTopRow = styled("div", {
68
- base: {
69
- display: "flex",
70
- justifyContent: "space-between"
71
- }
72
- });
73
- const ContentWrapper = styled("div", {
74
- base: {
75
- display: "flex",
76
- flexDirection: "column",
77
- gap: "medium",
78
- flex: "2"
79
- }
80
- });
81
- const ActionsWrapper = styled("div", {
82
- base: {
83
- display: "flex",
84
- gap: "small",
85
- marginBlockEnd: "medium"
86
- }
87
- });
88
- const StyledFieldRoot = styled(FieldRoot, {
89
- base: {
90
- alignSelf: "center"
91
- }
92
- });
93
- const PreviewImage = _ref => {
94
- let {
95
- id,
96
- image,
97
- onSelectImage,
98
- showCheckbox,
99
- translations,
100
- locale
101
- } = _ref;
102
- const [saveAsMetaImage, setSaveAsMetaImage] = useState(false);
103
- return /*#__PURE__*/_jsxs(StyledPreview, {
104
- id: id,
105
- children: [/*#__PURE__*/_jsx(ImageContainer, {
106
- children: /*#__PURE__*/_jsx(StyledImage, {
107
- alt: "",
108
- srcSet: getSrcSets(image.image.imageUrl),
109
- sizes: "(min-width: 800px) 360px, (min-width: 400px) 300px, 100vw",
110
- src: image.image.imageUrl,
111
- "aria-label": image.title.title,
112
- variant: "rounded"
113
- })
114
- }), /*#__PURE__*/_jsxs(ContentWrapper, {
115
- children: [/*#__PURE__*/_jsxs(StyledImageMetadata, {
116
- children: [/*#__PURE__*/_jsxs(StyledTopRow, {
117
- children: [/*#__PURE__*/_jsx(Text, {
118
- textStyle: "title.medium",
119
- children: image.title.title.trim() ? image.title.title : translations.missingTitleFallback ?? `ID: ${image.id}`
120
- }), /*#__PURE__*/_jsx(IconButton, {
121
- variant: "tertiary",
122
- onClick: () => onSelectImage(undefined),
123
- "aria-label": translations.close,
124
- title: translations.close,
125
- children: /*#__PURE__*/_jsx(CloseLine, {})
126
- })]
127
- }), !!image.copyright.creators.length && /*#__PURE__*/_jsxs(Text, {
128
- children: [/*#__PURE__*/_jsx("b", {
129
- children: `${translations.creatorsLabel}: `
130
- }), image.copyright.creators.map(creator => creator.name).join(", ")]
131
- }), !!image.copyright.license.description?.trim() && /*#__PURE__*/_jsxs(Text, {
132
- children: [/*#__PURE__*/_jsx("b", {
133
- children: `${translations.license}: `
134
- }), image.copyright.license.description]
135
- }), !!image.caption.caption.trim() && /*#__PURE__*/_jsxs(Text, {
136
- children: [/*#__PURE__*/_jsx("b", {
137
- children: `${translations.caption}: `
138
- }), image.caption.caption]
139
- }), !!image.alttext.alttext.trim() && /*#__PURE__*/_jsxs(Text, {
140
- children: [/*#__PURE__*/_jsx("b", {
141
- children: `${translations.altText}:`
142
- }), " ", image.alttext.alttext]
143
- }), !!image.modelRelease.trim() && /*#__PURE__*/_jsxs(Text, {
144
- children: [/*#__PURE__*/_jsx("b", {
145
- children: `${translations.modelRelease}: `
146
- }), getModelReleaseValue(image.modelRelease, locale)]
147
- }), /*#__PURE__*/_jsx(ImageMeta, {
148
- contentType: image.image.contentType,
149
- fileSize: image.image.size,
150
- imageDimensions: image.image.dimensions,
151
- locale: locale
152
- }), !!image.tags.tags.length && /*#__PURE__*/_jsxs(HashTagGroup, {
153
- children: [/*#__PURE__*/_jsx(Text, {
154
- id: "tags-title",
155
- children: /*#__PURE__*/_jsx("b", {
156
- children: `${translations.tags}: `
157
- })
158
- }), /*#__PURE__*/_jsx(HashTagWrapper, {
159
- "aria-describedby": "tags-title",
160
- children: image.tags.tags.map(tag => /*#__PURE__*/_jsxs(StyledTagItem, {
161
- children: [/*#__PURE__*/_jsx(HashTag, {
162
- size: "small"
163
- }), tag]
164
- }, tag))
165
- })]
166
- })]
167
- }), /*#__PURE__*/_jsxs(ActionsWrapper, {
168
- children: [/*#__PURE__*/_jsx(Button, {
169
- "data-testid": "use-image",
170
- onClick: () => onSelectImage(image, saveAsMetaImage),
171
- children: translations.useImageTitle
172
- }), !!showCheckbox && /*#__PURE__*/_jsx(StyledFieldRoot, {
173
- children: /*#__PURE__*/_jsxs(CheckboxRoot, {
174
- checked: saveAsMetaImage,
175
- onCheckedChange: () => setSaveAsMetaImage(prev => !prev),
176
- children: [/*#__PURE__*/_jsx(CheckboxControl, {
177
- children: /*#__PURE__*/_jsx(CheckboxIndicator, {
178
- asChild: true,
179
- children: /*#__PURE__*/_jsx(CheckLine, {})
180
- })
181
- }), /*#__PURE__*/_jsx(CheckboxLabel, {
182
- children: translations.checkboxLabel
183
- }), /*#__PURE__*/_jsx(CheckboxHiddenInput, {})]
184
- })
185
- })]
186
- })]
187
- })]
188
- });
189
- };
190
- export default PreviewImage;
package/es/index.js DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) 2017-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 { default as ImageMeta } from "./ImageMeta";
10
- export { default as ImageSearch } from "./ImageSearch";
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) 2017-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
- /* - Source sets for gallery search is retina-display optimized
10
- - Based on: https://www.smashingmagazine.com/2014/05/responsive-images-done-right-guide-picture-srcset/ */
11
-
12
- export const getSrcSets = imageUrl => [`${imageUrl}?width=1440 1440w`, `${imageUrl}?width=1120 1120w`, `${imageUrl}?width=1000 1000w`, `${imageUrl}?width=960 960w`, `${imageUrl}?width=800 800w`, `${imageUrl}?width=640 640w`, `${imageUrl}?width=480 480w`, `${imageUrl}?width=320 320w`].join(", ");
13
- export const getPreviewSrcSets = imageUrl => [`${imageUrl}?width=480 3x`, `${imageUrl}?width=320 2x`, `${imageUrl}?width=160 1x`].join(", ");
package/lib/ImageMeta.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = require("react");
8
- var _primitives = require("@ndla/primitives");
9
- var _util = require("@ndla/util");
10
- var _jsxRuntime = require("react/jsx-runtime");
11
- /**
12
- * Copyright (c) 2022-present, NDLA.
13
- *
14
- * This source code is licensed under the GPLv3 license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- *
17
- */
18
-
19
- const ImageMeta = _ref => {
20
- let {
21
- contentType,
22
- fileSize,
23
- imageDimensions,
24
- locale
25
- } = _ref;
26
- const prettySize = (0, _react.useMemo)(() => {
27
- return (0, _util.humanFileSize)(fileSize, locale);
28
- }, [fileSize, locale]);
29
- const dimensions = imageDimensions ? ` - ${imageDimensions.width}x${imageDimensions.height} px` : "";
30
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Text, {
31
- children: `${contentType} - ${prettySize}${dimensions}`
32
- });
33
- };
34
- var _default = exports.default = ImageMeta;
@@ -1,220 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = require("react");
8
- var _icons = require("@ndla/icons");
9
- var _primitives = require("@ndla/primitives");
10
- var _jsx2 = require("@ndla/styled-system/jsx");
11
- var _ImageSearchResult = _interopRequireDefault(require("./ImageSearchResult"));
12
- var _jsxRuntime = require("react/jsx-runtime");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- /**
15
- * Copyright (c) 2017-present, NDLA.
16
- *
17
- * This source code is licensed under the GPLv3 license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- *
20
- */
21
-
22
- const ImageSearchWrapper = (0, _jsx2.styled)("div", {
23
- base: {
24
- display: "flex",
25
- flexDirection: "column",
26
- gap: "small"
27
- }
28
- });
29
- const StyledSearchResults = (0, _jsx2.styled)("div", {
30
- base: {
31
- display: "grid",
32
- gridTemplateColumns: "repeat(auto-fit, minmax(200px, 1fr))",
33
- gridGap: "xsmall",
34
- gridAutoFlow: "dense"
35
- }
36
- });
37
- const InputWrapper = (0, _jsx2.styled)("div", {
38
- base: {
39
- display: "flex",
40
- gap: "xsmall"
41
- }
42
- });
43
- const StyledPaginationRoot = (0, _jsx2.styled)(_primitives.PaginationRoot, {
44
- base: {
45
- flexWrap: "wrap"
46
- }
47
- });
48
- const StyledButton = (0, _jsx2.styled)(_primitives.Button, {
49
- base: {
50
- tabletWideDown: {
51
- paddingInline: "xsmall",
52
- "& span": {
53
- display: "none"
54
- }
55
- }
56
- }
57
- });
58
- const StyledPaginationItem = (0, _jsx2.styled)(_primitives.PaginationItem, {
59
- base: {
60
- tabletWideDown: {
61
- "&:nth-child(2)": {
62
- display: "none"
63
- },
64
- "&:nth-last-child(2)": {
65
- display: "none"
66
- }
67
- }
68
- }
69
- });
70
- const ImageSearch = _ref => {
71
- let {
72
- onImageSelect,
73
- searchImages: search,
74
- onError,
75
- locale,
76
- noResults,
77
- checkboxAction,
78
- showCheckbox,
79
- translations
80
- } = _ref;
81
- const [queryObject, setQueryObject] = (0, _react.useState)({
82
- query: undefined,
83
- page: 1,
84
- pageSize: 16
85
- });
86
- const [selectedImage, setSelectedImage] = (0, _react.useState)();
87
- const [searching, setSearching] = (0, _react.useState)(false);
88
- const [searchResult, setSearchResult] = (0, _react.useState)();
89
- const {
90
- page
91
- } = queryObject;
92
- const noResultsFound = !searching && searchResult?.results.length === 0;
93
- const onSelectImage = (image, saveAsMetaImage) => {
94
- setSelectedImage(undefined);
95
- if (!image) return;
96
- onImageSelect(image);
97
- if (saveAsMetaImage) {
98
- checkboxAction?.(image);
99
- }
100
- };
101
- const searchImages = queryObject => {
102
- setSearching(true);
103
- search(queryObject.query, queryObject.page).then(result => {
104
- setQueryObject({
105
- query: queryObject.query,
106
- pageSize: result.pageSize,
107
- page: queryObject.page
108
- });
109
- setSearchResult(result);
110
- setSearching(false);
111
- }).catch(err => {
112
- onError?.(err);
113
- setSearching(false);
114
- });
115
- };
116
- const handleQueryChange = _ref2 => {
117
- let {
118
- target: {
119
- value
120
- }
121
- } = _ref2;
122
- setQueryObject(prevState => ({
123
- ...prevState,
124
- query: value
125
- }));
126
- };
127
- const onEnter = e => {
128
- if (e.key === "Enter") {
129
- searchImages(queryObject);
130
- }
131
- };
132
- (0, _react.useEffect)(() => {
133
- searchImages(queryObject);
134
- // eslint-disable-next-line react-hooks/exhaustive-deps
135
- }, []);
136
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ImageSearchWrapper, {
137
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(InputWrapper, {
138
- role: "search",
139
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Input, {
140
- type: "search",
141
- placeholder: translations.searchPlaceholder,
142
- value: queryObject?.query ?? "",
143
- onChange: handleQueryChange,
144
- onKeyDown: onEnter
145
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.IconButton, {
146
- variant: "primary",
147
- "aria-label": translations.searchButtonTitle,
148
- title: translations.searchButtonTitle,
149
- onKeyDown: onEnter,
150
- onClick: () => searchImages(queryObject),
151
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.SearchLine, {})
152
- })]
153
- }), !!noResultsFound && noResults, /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledSearchResults, {
154
- children: searchResult?.results.map(image => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ImageSearchResult.default, {
155
- image: image,
156
- onImageClick: image => setSelectedImage(image),
157
- selectedImage: selectedImage,
158
- onSelectImage: onSelectImage,
159
- showCheckbox: !!showCheckbox,
160
- translations: translations.imagePreview,
161
- locale: locale
162
- }, image.id))
163
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledPaginationRoot, {
164
- page: page ?? 1,
165
- onPageChange: details => searchImages({
166
- ...queryObject,
167
- page: details.page
168
- }),
169
- translations: translations.paginationTranslations,
170
- count: searchResult?.totalCount ?? 0,
171
- pageSize: searchResult?.pageSize,
172
- hidden: noResultsFound,
173
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.PaginationPrevTrigger, {
174
- asChild: true,
175
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledButton, {
176
- variant: "tertiary",
177
- "aria-label": translations.paginationTranslations?.prevTriggerLabel,
178
- title: translations.paginationTranslations?.prevTriggerLabel,
179
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.ArrowLeftShortLine, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
180
- children: translations.paginationTranslations?.prevTriggerLabel
181
- })]
182
- })
183
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.PaginationContext, {
184
- children: pagination => pagination.pages.map((page, index, full) => {
185
- // Hide last page to not trigger RESULT_WINDOW_TOO_LARGE error
186
- if (index === full.length - 1) return null;
187
- return page.type === "page" ? /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledPaginationItem, {
188
- ...page,
189
- asChild: true,
190
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Button, {
191
- variant: page.value === pagination.page ? "primary" : "tertiary",
192
- children: page.value
193
- })
194
- }, index) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.PaginationEllipsis, {
195
- index: index,
196
- asChild: true,
197
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Text, {
198
- asChild: true,
199
- consumeCss: true,
200
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
201
- children: "\u2026"
202
- })
203
- })
204
- }, index);
205
- })
206
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.PaginationNextTrigger, {
207
- asChild: true,
208
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledButton, {
209
- variant: "tertiary",
210
- "aria-label": translations.paginationTranslations?.nextTriggerLabel,
211
- title: translations.paginationTranslations?.nextTriggerLabel,
212
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
213
- children: translations.paginationTranslations?.nextTriggerLabel
214
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.ArrowRightShortLine, {})]
215
- })
216
- })]
217
- })]
218
- });
219
- };
220
- var _default = exports.default = ImageSearch;
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = ImageSearchResult;
7
- var _primitives = require("@ndla/primitives");
8
- var _jsx2 = require("@ndla/styled-system/jsx");
9
- var _PreviewImage = _interopRequireDefault(require("./PreviewImage"));
10
- var _imageUtil = require("./util/imageUtil");
11
- var _jsxRuntime = require("react/jsx-runtime");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- /**
14
- * Copyright (c) 2017-present, NDLA.
15
- *
16
- * This source code is licensed under the GPLv3 license found in the
17
- * LICENSE file in the root directory of this source tree.
18
- *
19
- */
20
-
21
- const StyledButton = (0, _jsx2.styled)(_primitives.Button, {
22
- base: {
23
- display: "flex",
24
- flexDirection: "column",
25
- borderColor: "stroke.subtle"
26
- }
27
- });
28
- const StyledImage = (0, _jsx2.styled)(_primitives.Image, {
29
- base: {
30
- maxHeight: "135px",
31
- width: "100%",
32
- height: "100%"
33
- }
34
- });
35
- const StyledText = (0, _jsx2.styled)(_primitives.Text, {
36
- base: {
37
- lineClamp: "3"
38
- }
39
- });
40
- function ImageSearchResult(_ref) {
41
- let {
42
- image,
43
- onImageClick,
44
- selectedImage,
45
- onSelectImage,
46
- showCheckbox,
47
- translations,
48
- locale
49
- } = _ref;
50
- const isSelectedImage = selectedImage?.id === image.id;
51
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
52
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledButton, {
53
- variant: isSelectedImage ? "secondary" : "tertiary",
54
- "data-testid": "select-image-from-list",
55
- onClick: () => onImageClick(image),
56
- "aria-expanded": isSelectedImage,
57
- "aria-controls": `image-preview-${image.id}`,
58
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(StyledImage, {
59
- alt: "",
60
- srcSet: (0, _imageUtil.getPreviewSrcSets)(image.image.imageUrl),
61
- src: image.image.imageUrl,
62
- variant: "rounded"
63
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledText, {
64
- textStyle: "label.medium",
65
- asChild: true,
66
- consumeCss: true,
67
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
68
- children: image.title.title.trim() ? image.title.title : translations.missingTitleFallback ?? `ID: ${image.id}`
69
- })
70
- })]
71
- }), isSelectedImage ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_PreviewImage.default, {
72
- id: `image-preview-${image.id}`,
73
- image: selectedImage,
74
- onSelectImage: onSelectImage,
75
- translations: translations,
76
- showCheckbox: showCheckbox,
77
- locale: locale
78
- }) : null]
79
- });
80
- }
@@ -1,197 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = require("react");
8
- var _icons = require("@ndla/icons");
9
- var _licenses = require("@ndla/licenses");
10
- var _primitives = require("@ndla/primitives");
11
- var _jsx2 = require("@ndla/styled-system/jsx");
12
- var _ImageMeta = _interopRequireDefault(require("./ImageMeta"));
13
- var _imageUtil = require("./util/imageUtil");
14
- var _jsxRuntime = require("react/jsx-runtime");
15
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
- /**
17
- * Copyright (c) 2017-present, NDLA.
18
- *
19
- * This source code is licensed under the GPLv3 license found in the
20
- * LICENSE file in the root directory of this source tree.
21
- *
22
- */
23
-
24
- const ImageContainer = (0, _jsx2.styled)("div", {
25
- base: {
26
- flexShrink: "0"
27
- }
28
- });
29
- const StyledImage = (0, _jsx2.styled)(_primitives.Image, {
30
- base: {
31
- maxHeight: "surface.xsmall"
32
- }
33
- });
34
- const StyledImageMetadata = (0, _jsx2.styled)("div", {
35
- base: {
36
- display: "flex",
37
- flexDirection: "column",
38
- gap: "xxsmall"
39
- }
40
- });
41
- const HashTagWrapper = (0, _jsx2.styled)("ul", {
42
- base: {
43
- display: "flex",
44
- gap: "xxsmall",
45
- flexWrap: "wrap"
46
- }
47
- });
48
- const HashTagGroup = (0, _jsx2.styled)("div", {
49
- base: {
50
- display: "flex",
51
- gap: "xxsmall",
52
- flexWrap: "wrap"
53
- }
54
- });
55
- const StyledTagItem = (0, _jsx2.styled)("li", {
56
- base: {
57
- display: "flex",
58
- alignItems: "center"
59
- }
60
- });
61
- const StyledPreview = (0, _jsx2.styled)("div", {
62
- base: {
63
- display: "flex",
64
- gridColumn: "1 / -1",
65
- borderColor: "stroke.default",
66
- border: "1px solid",
67
- borderRadius: "xsmall",
68
- gap: "small",
69
- padding: "small",
70
- flexWrap: "wrap",
71
- overflow: "hidden"
72
- }
73
- });
74
- const StyledTopRow = (0, _jsx2.styled)("div", {
75
- base: {
76
- display: "flex",
77
- justifyContent: "space-between"
78
- }
79
- });
80
- const ContentWrapper = (0, _jsx2.styled)("div", {
81
- base: {
82
- display: "flex",
83
- flexDirection: "column",
84
- gap: "medium",
85
- flex: "2"
86
- }
87
- });
88
- const ActionsWrapper = (0, _jsx2.styled)("div", {
89
- base: {
90
- display: "flex",
91
- gap: "small",
92
- marginBlockEnd: "medium"
93
- }
94
- });
95
- const StyledFieldRoot = (0, _jsx2.styled)(_primitives.FieldRoot, {
96
- base: {
97
- alignSelf: "center"
98
- }
99
- });
100
- const PreviewImage = _ref => {
101
- let {
102
- id,
103
- image,
104
- onSelectImage,
105
- showCheckbox,
106
- translations,
107
- locale
108
- } = _ref;
109
- const [saveAsMetaImage, setSaveAsMetaImage] = (0, _react.useState)(false);
110
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledPreview, {
111
- id: id,
112
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ImageContainer, {
113
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledImage, {
114
- alt: "",
115
- srcSet: (0, _imageUtil.getSrcSets)(image.image.imageUrl),
116
- sizes: "(min-width: 800px) 360px, (min-width: 400px) 300px, 100vw",
117
- src: image.image.imageUrl,
118
- "aria-label": image.title.title,
119
- variant: "rounded"
120
- })
121
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(ContentWrapper, {
122
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledImageMetadata, {
123
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledTopRow, {
124
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Text, {
125
- textStyle: "title.medium",
126
- children: image.title.title.trim() ? image.title.title : translations.missingTitleFallback ?? `ID: ${image.id}`
127
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.IconButton, {
128
- variant: "tertiary",
129
- onClick: () => onSelectImage(undefined),
130
- "aria-label": translations.close,
131
- title: translations.close,
132
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.CloseLine, {})
133
- })]
134
- }), !!image.copyright.creators.length && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.Text, {
135
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("b", {
136
- children: `${translations.creatorsLabel}: `
137
- }), image.copyright.creators.map(creator => creator.name).join(", ")]
138
- }), !!image.copyright.license.description?.trim() && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.Text, {
139
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("b", {
140
- children: `${translations.license}: `
141
- }), image.copyright.license.description]
142
- }), !!image.caption.caption.trim() && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.Text, {
143
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("b", {
144
- children: `${translations.caption}: `
145
- }), image.caption.caption]
146
- }), !!image.alttext.alttext.trim() && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.Text, {
147
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("b", {
148
- children: `${translations.altText}:`
149
- }), " ", image.alttext.alttext]
150
- }), !!image.modelRelease.trim() && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.Text, {
151
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("b", {
152
- children: `${translations.modelRelease}: `
153
- }), (0, _licenses.getModelReleaseValue)(image.modelRelease, locale)]
154
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ImageMeta.default, {
155
- contentType: image.image.contentType,
156
- fileSize: image.image.size,
157
- imageDimensions: image.image.dimensions,
158
- locale: locale
159
- }), !!image.tags.tags.length && /*#__PURE__*/(0, _jsxRuntime.jsxs)(HashTagGroup, {
160
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Text, {
161
- id: "tags-title",
162
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("b", {
163
- children: `${translations.tags}: `
164
- })
165
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(HashTagWrapper, {
166
- "aria-describedby": "tags-title",
167
- children: image.tags.tags.map(tag => /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledTagItem, {
168
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.HashTag, {
169
- size: "small"
170
- }), tag]
171
- }, tag))
172
- })]
173
- })]
174
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(ActionsWrapper, {
175
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.Button, {
176
- "data-testid": "use-image",
177
- onClick: () => onSelectImage(image, saveAsMetaImage),
178
- children: translations.useImageTitle
179
- }), !!showCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledFieldRoot, {
180
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_primitives.CheckboxRoot, {
181
- checked: saveAsMetaImage,
182
- onCheckedChange: () => setSaveAsMetaImage(prev => !prev),
183
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.CheckboxControl, {
184
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.CheckboxIndicator, {
185
- asChild: true,
186
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.CheckLine, {})
187
- })
188
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.CheckboxLabel, {
189
- children: translations.checkboxLabel
190
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_primitives.CheckboxHiddenInput, {})]
191
- })
192
- })]
193
- })]
194
- })]
195
- });
196
- };
197
- var _default = exports.default = PreviewImage;
package/lib/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ImageMeta", {
7
- enumerable: true,
8
- get: function () {
9
- return _ImageMeta.default;
10
- }
11
- });
12
- Object.defineProperty(exports, "ImageSearch", {
13
- enumerable: true,
14
- get: function () {
15
- return _ImageSearch.default;
16
- }
17
- });
18
- var _ImageMeta = _interopRequireDefault(require("./ImageMeta"));
19
- var _ImageSearch = _interopRequireDefault(require("./ImageSearch"));
20
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSrcSets = exports.getPreviewSrcSets = void 0;
7
- /**
8
- * Copyright (c) 2017-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
- /* - Source sets for gallery search is retina-display optimized
16
- - Based on: https://www.smashingmagazine.com/2014/05/responsive-images-done-right-guide-picture-srcset/ */
17
-
18
- const getSrcSets = imageUrl => [`${imageUrl}?width=1440 1440w`, `${imageUrl}?width=1120 1120w`, `${imageUrl}?width=1000 1000w`, `${imageUrl}?width=960 960w`, `${imageUrl}?width=800 800w`, `${imageUrl}?width=640 640w`, `${imageUrl}?width=480 480w`, `${imageUrl}?width=320 320w`].join(", ");
19
- exports.getSrcSets = getSrcSets;
20
- const getPreviewSrcSets = imageUrl => [`${imageUrl}?width=480 3x`, `${imageUrl}?width=320 2x`, `${imageUrl}?width=160 1x`].join(", ");
21
- exports.getPreviewSrcSets = getPreviewSrcSets;