@squiz/resource-browser 3.3.5 → 3.3.7
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/CHANGELOG.md +12 -0
- package/lib/ResourceBrowserInlineButton/ResourceBrowserInlineButton.js +37 -4
- package/lib/index.css +4 -0
- package/lib/index.js +9 -6
- package/lib/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.scss +5 -0
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.spec.tsx +10 -1
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.stories.tsx +7 -0
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.tsx +20 -4
- package/src/index.tsx +9 -6
- package/src/types.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 3.3.7
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- cbf0348: enable the resource picker for MatrixAssetURI in resource browser
|
8
|
+
|
9
|
+
## 3.3.6
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- bd748ea: Better support for AssetBank resources
|
14
|
+
|
3
15
|
## 3.3.5
|
4
16
|
|
5
17
|
### Patch Changes
|
@@ -1,26 +1,59 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
27
|
};
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
29
|
exports.ResourceBrowserInlineButton = void 0;
|
7
|
-
const react_1 =
|
30
|
+
const react_1 = __importStar(require("react"));
|
8
31
|
const MainContainer_1 = __importDefault(require("../MainContainer/MainContainer"));
|
9
32
|
const resource_browser_ui_lib_1 = require("@squiz/resource-browser-ui-lib");
|
10
33
|
const InlineLoadingErrorState_1 = require("./InlineLoadingErrorState/InlineLoadingErrorState");
|
11
34
|
const ImageInline_1 = require("../Icons/ImageInline");
|
12
35
|
const LinkInline_1 = require("../Icons/LinkInline");
|
36
|
+
const AdsClickIcon_1 = require("../Icons/AdsClickIcon");
|
13
37
|
const ResourceBrowserInlineButton = ({ inlineType, modalTitle, allowedTypes, onChange, onRetry, value, useResource, isDisabled, plugin, pluginMode, searchEnabled, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }) => {
|
14
38
|
// If an error happens loading the resource the inline browser just opens without it as if no preselectedResource is provided
|
15
39
|
const { data: resource, isLoading: isResourceLoading } = useResource(value || null, source);
|
16
|
-
const
|
40
|
+
const inlineTypePickerLabels = (0, react_1.useMemo)(() => ({
|
41
|
+
image: 'Change image',
|
42
|
+
link: 'Change link',
|
43
|
+
resource: 'Change resource',
|
44
|
+
}), [inlineType]);
|
45
|
+
const inlineTypePickerIcons = (0, react_1.useMemo)(() => ({
|
46
|
+
image: react_1.default.createElement(ImageInline_1.ImageInline, { "aria-label": "change image" }),
|
47
|
+
link: react_1.default.createElement(LinkInline_1.LinkInline, { "aria-label": "change link" }),
|
48
|
+
resource: react_1.default.createElement(AdsClickIcon_1.AdsClickIcon, { "aria-label": "change resource" }),
|
49
|
+
}), [inlineType]);
|
17
50
|
return (react_1.default.createElement("div", { className: "inline-launch-button" },
|
18
51
|
react_1.default.createElement(resource_browser_ui_lib_1.ModalTrigger, { overlayTriggerState: {
|
19
52
|
isOpen: isModalOpen,
|
20
53
|
onOpenChange: onModalStateChange,
|
21
|
-
}, showLabel: false, label: "", icon:
|
54
|
+
}, showLabel: false, label: "", icon: inlineTypePickerIcons[inlineType], isDisabled: isDisabled, scope: "squiz-rb-scope", containerClasses: "inline-launch-button__button" }, (onClose, titleProps) => (react_1.default.createElement(react_1.default.Fragment, null,
|
22
55
|
(isLoading || isResourceLoading || error) && (react_1.default.createElement(InlineLoadingErrorState_1.InlineLoadingErrorState, { title: modalTitle, titleAriaProps: titleProps, onClose: onClose, onRetry: onRetry, isLoading: isLoading || isResourceLoading, error: error })),
|
23
56
|
!(isLoading || isResourceLoading) && !error && (react_1.default.createElement(MainContainer_1.default, { selectedSource: source, sources: sources, preselectedResource: resource, plugin: plugin, pluginMode: pluginMode, searchEnabled: searchEnabled, title: modalTitle, titleAriaProps: titleProps, allowedTypes: allowedTypes, onSourceSelect: setSource, onClose: onClose, onChange: onChange }))))),
|
24
|
-
react_1.default.createElement("div", { className: "inline-launch-button__label" },
|
57
|
+
react_1.default.createElement("div", { className: "inline-launch-button__label" }, inlineTypePickerLabels[inlineType])));
|
25
58
|
};
|
26
59
|
exports.ResourceBrowserInlineButton = ResourceBrowserInlineButton;
|
package/lib/index.css
CHANGED
@@ -6402,6 +6402,10 @@
|
|
6402
6402
|
padding: 2px;
|
6403
6403
|
cursor: pointer;
|
6404
6404
|
}
|
6405
|
+
.squiz-rb-scope .inline-launch-button__button svg:not(.squiz-rb-plugin *) {
|
6406
|
+
width: 18px;
|
6407
|
+
height: 18px;
|
6408
|
+
}
|
6405
6409
|
.squiz-rb-scope .inline-launch-button__label:not(.squiz-rb-plugin *) {
|
6406
6410
|
display: none;
|
6407
6411
|
position: absolute;
|
package/lib/index.js
CHANGED
@@ -71,25 +71,28 @@ const ResourceBrowser = (props) => {
|
|
71
71
|
}, [setSource, setMode]);
|
72
72
|
// If an existing resource is passed in auto select its source
|
73
73
|
(0, react_1.useEffect)(() => {
|
74
|
-
let
|
74
|
+
let newSource = null;
|
75
75
|
setError(null);
|
76
|
+
if (source !== null) {
|
77
|
+
return;
|
78
|
+
}
|
76
79
|
// If there is a provided value try to use its source
|
77
80
|
if (value) {
|
78
81
|
// Search the sources for it matching against the value.source property
|
79
|
-
|
82
|
+
newSource = sources.find((source) => source.id === value?.sourceId) || null;
|
80
83
|
// If the source is null and we arent loading the sources
|
81
|
-
if (
|
84
|
+
if (newSource === null && !isLoading) {
|
82
85
|
// Set an error as the passed in value's source wasnt returned by onRequestSources
|
83
86
|
setError(new Error('Unable to find resource source.'));
|
84
87
|
}
|
85
88
|
}
|
86
89
|
else if (sources?.length === 1 && !searchEnabled) {
|
87
90
|
// If only one source is passed and search is not enabled select it automatically
|
88
|
-
|
91
|
+
newSource = sources[0];
|
89
92
|
}
|
90
|
-
setSource(
|
93
|
+
setSource(newSource);
|
91
94
|
setMode(null); // Passed in resource will always use the default mode
|
92
|
-
}, [value, isLoading, sources,
|
95
|
+
}, [value, isLoading, sources, source]);
|
93
96
|
// The modal has some control over it own open/closed state (for WCAG reasons) so keep this in sync with our state
|
94
97
|
const handleModalStateChange = (0, react_1.useCallback)((isOpen) => {
|
95
98
|
setIsModalOpen(isOpen);
|
package/lib/types.d.ts
CHANGED
@@ -2,7 +2,7 @@ import React, { ReactElement } from 'react';
|
|
2
2
|
import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
3
3
|
export type OnRequestSources = () => Promise<ResourceBrowserSource[]>;
|
4
4
|
export type ResourceBrowserPluginType = 'dam' | 'matrix';
|
5
|
-
export type InlineType = 'image' | 'link';
|
5
|
+
export type InlineType = 'image' | 'link' | 'resource';
|
6
6
|
export type AuthenticationConfiguration = {
|
7
7
|
authUrl: string;
|
8
8
|
redirectUrl: string;
|
package/package.json
CHANGED
@@ -27,7 +27,7 @@ describe('ResourceBrowserInlineButton', () => {
|
|
27
27
|
});
|
28
28
|
});
|
29
29
|
|
30
|
-
it('Render
|
30
|
+
it('Render link icon if inline type is "link"', async () => {
|
31
31
|
//@ts-ignore
|
32
32
|
render(<ResourceBrowserInlineButton {...defaultProps} inlineType={'link'} />);
|
33
33
|
|
@@ -36,6 +36,15 @@ describe('ResourceBrowserInlineButton', () => {
|
|
36
36
|
});
|
37
37
|
});
|
38
38
|
|
39
|
+
it('Render resource icon if inline type is "resource"', async () => {
|
40
|
+
//@ts-ignore
|
41
|
+
render(<ResourceBrowserInlineButton {...defaultProps} inlineType={'resource'} />);
|
42
|
+
|
43
|
+
await waitFor(() => {
|
44
|
+
expect(screen.getByLabelText('change resource')).toBeTruthy();
|
45
|
+
});
|
46
|
+
});
|
47
|
+
|
39
48
|
it('On trigger press render loading if still awaiting external data', async () => {
|
40
49
|
//@ts-ignore
|
41
50
|
render(<ResourceBrowserInlineButton {...defaultProps} inlineType={'image'} isLoading={true} />);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from 'react';
|
1
|
+
import React, { useMemo } from 'react';
|
2
2
|
import MainContainer from '../MainContainer/MainContainer';
|
3
3
|
import { ResourceBrowserInputProps } from '../ResourceBrowserInput/ResourceBrowserInput';
|
4
4
|
import { ModalTrigger } from '@squiz/resource-browser-ui-lib';
|
@@ -6,6 +6,7 @@ import { InlineLoadingErrorState } from './InlineLoadingErrorState/InlineLoading
|
|
6
6
|
import { ImageInline } from '../Icons/ImageInline';
|
7
7
|
import { LinkInline } from '../Icons/LinkInline';
|
8
8
|
import { InlineType } from '../types';
|
9
|
+
import { AdsClickIcon } from '../Icons/AdsClickIcon';
|
9
10
|
|
10
11
|
export type ResourceBrowserInlineButtonProps = ResourceBrowserInputProps & {
|
11
12
|
inlineType: InlineType;
|
@@ -35,7 +36,22 @@ export const ResourceBrowserInlineButton = ({
|
|
35
36
|
// If an error happens loading the resource the inline browser just opens without it as if no preselectedResource is provided
|
36
37
|
const { data: resource, isLoading: isResourceLoading } = useResource(value || null, source);
|
37
38
|
|
38
|
-
const
|
39
|
+
const inlineTypePickerLabels = useMemo(
|
40
|
+
() => ({
|
41
|
+
image: 'Change image',
|
42
|
+
link: 'Change link',
|
43
|
+
resource: 'Change resource',
|
44
|
+
}),
|
45
|
+
[inlineType],
|
46
|
+
);
|
47
|
+
const inlineTypePickerIcons = useMemo(
|
48
|
+
() => ({
|
49
|
+
image: <ImageInline aria-label="change image" />,
|
50
|
+
link: <LinkInline aria-label="change link" />,
|
51
|
+
resource: <AdsClickIcon aria-label="change resource" />,
|
52
|
+
}),
|
53
|
+
[inlineType],
|
54
|
+
);
|
39
55
|
|
40
56
|
return (
|
41
57
|
<div className="inline-launch-button">
|
@@ -46,7 +62,7 @@ export const ResourceBrowserInlineButton = ({
|
|
46
62
|
}}
|
47
63
|
showLabel={false}
|
48
64
|
label=""
|
49
|
-
icon={
|
65
|
+
icon={inlineTypePickerIcons[inlineType]}
|
50
66
|
isDisabled={isDisabled}
|
51
67
|
scope="squiz-rb-scope"
|
52
68
|
containerClasses="inline-launch-button__button"
|
@@ -82,7 +98,7 @@ export const ResourceBrowserInlineButton = ({
|
|
82
98
|
</>
|
83
99
|
)}
|
84
100
|
</ModalTrigger>
|
85
|
-
<div className="inline-launch-button__label">{
|
101
|
+
<div className="inline-launch-button__label">{inlineTypePickerLabels[inlineType]}</div>
|
86
102
|
</div>
|
87
103
|
);
|
88
104
|
};
|
package/src/index.tsx
CHANGED
@@ -70,26 +70,29 @@ export const ResourceBrowser = (props: ResourceBrowserProps) => {
|
|
70
70
|
|
71
71
|
// If an existing resource is passed in auto select its source
|
72
72
|
useEffect(() => {
|
73
|
-
let
|
73
|
+
let newSource: ResourceBrowserSourceWithPlugin | null = null;
|
74
74
|
setError(null);
|
75
|
+
if (source !== null) {
|
76
|
+
return;
|
77
|
+
}
|
75
78
|
|
76
79
|
// If there is a provided value try to use its source
|
77
80
|
if (value) {
|
78
81
|
// Search the sources for it matching against the value.source property
|
79
|
-
|
82
|
+
newSource = sources.find((source) => source.id === value?.sourceId) || null;
|
80
83
|
// If the source is null and we arent loading the sources
|
81
|
-
if (
|
84
|
+
if (newSource === null && !isLoading) {
|
82
85
|
// Set an error as the passed in value's source wasnt returned by onRequestSources
|
83
86
|
setError(new Error('Unable to find resource source.'));
|
84
87
|
}
|
85
88
|
} else if (sources?.length === 1 && !searchEnabled) {
|
86
89
|
// If only one source is passed and search is not enabled select it automatically
|
87
|
-
|
90
|
+
newSource = sources[0];
|
88
91
|
}
|
89
92
|
|
90
|
-
setSource(
|
93
|
+
setSource(newSource);
|
91
94
|
setMode(null); // Passed in resource will always use the default mode
|
92
|
-
}, [value, isLoading, sources,
|
95
|
+
}, [value, isLoading, sources, source]);
|
93
96
|
|
94
97
|
// The modal has some control over it own open/closed state (for WCAG reasons) so keep this in sync with our state
|
95
98
|
const handleModalStateChange = useCallback(
|
package/src/types.ts
CHANGED
@@ -3,7 +3,7 @@ import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
|
3
3
|
|
4
4
|
export type OnRequestSources = () => Promise<ResourceBrowserSource[]>;
|
5
5
|
export type ResourceBrowserPluginType = 'dam' | 'matrix';
|
6
|
-
export type InlineType = 'image' | 'link';
|
6
|
+
export type InlineType = 'image' | 'link' | 'resource';
|
7
7
|
|
8
8
|
export type AuthenticationConfiguration = {
|
9
9
|
authUrl: string;
|