@squiz/resource-browser 3.0.1-pre-alpha.1 → 3.0.1-pre-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.eslintrc +40 -0
  2. package/.storybook/main.ts +26 -0
  3. package/.storybook/preview-body.html +1 -0
  4. package/.storybook/preview-head.html +12 -0
  5. package/.storybook/preview.ts +16 -0
  6. package/CHANGELOG.md +281 -0
  7. package/README_DEVS.md +18 -0
  8. package/build.js +21 -0
  9. package/jest.config.ts +30 -0
  10. package/package.json +4 -16
  11. package/postcss.config.js +21 -0
  12. package/tailwind.config.cjs +99 -0
  13. package/tsconfig.json +22 -0
  14. package/tsconfig.storybook.json +4 -0
  15. package/tsconfig.test.json +12 -0
  16. package/vite.config.js +20 -0
  17. package/lib-esm/BrowseToSource/BrowseToSource.d.ts +0 -8
  18. package/lib-esm/BrowseToSource/BrowseToSource.js +0 -50
  19. package/lib-esm/Hooks/useAuth.d.ts +0 -7
  20. package/lib-esm/Hooks/useAuth.js +0 -54
  21. package/lib-esm/Hooks/useSelectedState.d.ts +0 -15
  22. package/lib-esm/Hooks/useSelectedState.js +0 -12
  23. package/lib-esm/Hooks/useSources.d.ts +0 -14
  24. package/lib-esm/Hooks/useSources.js +0 -44
  25. package/lib-esm/Icons/AdsClickIcon.d.ts +0 -4
  26. package/lib-esm/Icons/AdsClickIcon.js +0 -5
  27. package/lib-esm/Icons/ArrowDownIcon.d.ts +0 -4
  28. package/lib-esm/Icons/ArrowDownIcon.js +0 -5
  29. package/lib-esm/Icons/CircledLoopIcon.d.ts +0 -4
  30. package/lib-esm/Icons/CircledLoopIcon.js +0 -5
  31. package/lib-esm/MainContainer/MainContainer.d.ts +0 -19
  32. package/lib-esm/MainContainer/MainContainer.js +0 -43
  33. package/lib-esm/Plugin/Plugin.d.ts +0 -13
  34. package/lib-esm/Plugin/Plugin.js +0 -12
  35. package/lib-esm/ResourceBrowserContext/AuthProvider.d.ts +0 -16
  36. package/lib-esm/ResourceBrowserContext/AuthProvider.js +0 -18
  37. package/lib-esm/ResourceBrowserContext/ResourceBrowserContext.d.ts +0 -15
  38. package/lib-esm/ResourceBrowserContext/ResourceBrowserContext.js +0 -26
  39. package/lib-esm/ResourceBrowserInput/ResourceBrowserInput.d.ts +0 -26
  40. package/lib-esm/ResourceBrowserInput/ResourceBrowserInput.js +0 -9
  41. package/lib-esm/ResourceLauncher/ResourceLauncher.d.ts +0 -8
  42. package/lib-esm/ResourceLauncher/ResourceLauncher.js +0 -12
  43. package/lib-esm/ResourcePicker/ResourcePicker.d.ts +0 -16
  44. package/lib-esm/ResourcePicker/ResourcePicker.js +0 -25
  45. package/lib-esm/ResourcePicker/States/Error.d.ts +0 -7
  46. package/lib-esm/ResourcePicker/States/Error.js +0 -6
  47. package/lib-esm/ResourcePicker/States/Loading.d.ts +0 -2
  48. package/lib-esm/ResourcePicker/States/Loading.js +0 -4
  49. package/lib-esm/ResourcePicker/States/Selected.d.ts +0 -15
  50. package/lib-esm/ResourcePicker/States/Selected.js +0 -20
  51. package/lib-esm/SourceDropdown/SourceDropdown.d.ts +0 -7
  52. package/lib-esm/SourceDropdown/SourceDropdown.js +0 -46
  53. package/lib-esm/SourceDropdownContainer/SourceDropdownContainer.d.ts +0 -5
  54. package/lib-esm/SourceDropdownContainer/SourceDropdownContainer.js +0 -12
  55. package/lib-esm/SourceList/SourceList.d.ts +0 -8
  56. package/lib-esm/SourceList/SourceList.js +0 -16
  57. package/lib-esm/index.d.ts +0 -18
  58. package/lib-esm/index.js +0 -79
  59. package/lib-esm/types.d.ts +0 -97
  60. package/lib-esm/types.js +0 -5
  61. package/lib-esm/utils/authUtils.d.ts +0 -5
  62. package/lib-esm/utils/authUtils.js +0 -31
package/vite.config.js ADDED
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ // https://vitejs.dev/config/
5
+ // Dependencies from within the monorepo need to be configured in a special way, relates to:
6
+ // https://github.com/vitejs/vite/issues/5668
7
+ export default defineConfig({
8
+ optimizeDeps: {
9
+ include: ['@squiz/resource-browser-ui-lib'],
10
+ },
11
+ plugins: [
12
+ react({
13
+ babel: {
14
+ parserOpts: {
15
+ plugins: ['decorators-legacy'],
16
+ },
17
+ },
18
+ }),
19
+ ],
20
+ });
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import { ResourceBrowserSource, PluginLaunchMode } from '../types';
3
- export default function BrowseToSource({ sources, selectedSource, onSourceSelect, className, }: {
4
- sources: ResourceBrowserSource[];
5
- selectedSource: ResourceBrowserSource;
6
- onSourceSelect(source: ResourceBrowserSource, mode?: PluginLaunchMode): void;
7
- className?: string;
8
- }): React.JSX.Element;
@@ -1,50 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
- import { Icon, uuid } from '@squiz/generic-browser-lib';
3
- import { useFocusWithin, useKeyboard } from 'react-aria';
4
- import { AdsClickIcon } from '../Icons/AdsClickIcon';
5
- import { ArrowDownIcon } from '../Icons/ArrowDownIcon';
6
- export default function BrowseToSource({ sources, selectedSource, onSourceSelect, className = '', }) {
7
- const [uniqueId] = useState(uuid());
8
- const buttonRef = useRef(null);
9
- const [isOpen, setIsOpen] = useState(false);
10
- // Watch the focus and blur on the menu and close if focus leaves the control
11
- const { focusWithinProps } = useFocusWithin({
12
- onBlurWithin: () => {
13
- setIsOpen(false);
14
- },
15
- });
16
- // Listen for Esc key within this element
17
- const { keyboardProps } = useKeyboard({
18
- onKeyDown: (e) => {
19
- if (isOpen && e.key === 'Escape') {
20
- setIsOpen(false);
21
- buttonRef.current?.focus(); // Restore focus to the element which opened the menu
22
- }
23
- },
24
- });
25
- const handleSourceClick = (source) => {
26
- setIsOpen(false);
27
- buttonRef.current?.focus();
28
- onSourceSelect(source);
29
- };
30
- if (!sources.length) {
31
- return React.createElement(React.Fragment, null);
32
- }
33
- return (React.createElement("div", { className: `inline-block ${isOpen ? 'flex items-center border-2 border-gray-200 rounded-lg px-1 py-0.5 w-[350px]' : 'p-0'} ${className}` },
34
- isOpen && React.createElement(AdsClickIcon, { "aria-hidden": true, className: "ml-1 mr-2 shrink-0" }),
35
- sources.length > 1 && (React.createElement("div", { ...focusWithinProps, ...keyboardProps, className: `relative w-full ${isOpen && 'border-l border-gray-400 pl-1 '}` },
36
- React.createElement("button", { ref: buttonRef, type: "button", "aria-label": "Source quick select", "aria-expanded": isOpen, "aria-controls": `${uniqueId}-button-menu`, onClick: () => setIsOpen(!isOpen), className: `relative flex items-center p-2 w-full rounded-lg ${!isOpen && 'border-2 border-gray-200 hover:bg-gray-100'}` }, isOpen ? (React.createElement(React.Fragment, null,
37
- React.createElement("span", { className: "text-gray-700 text-md leading-5 mr-2" }, "Browse to ..."),
38
- React.createElement(ArrowDownIcon, { "aria-hidden": true, className: "absolute right-3" }))) : (React.createElement(React.Fragment, null,
39
- React.createElement(AdsClickIcon, { "aria-hidden": true, className: "ml-[6px] mr-2" }),
40
- React.createElement("span", { className: "text-gray-700 text-md font-semibold leading-5 mr-[6px]" }, "Browse")))),
41
- React.createElement("ul", { id: `${uniqueId}-button-menu`, "aria-hidden": !isOpen, className: `absolute z-50 top-[calc(100%+8px)] left-1 w-[calc(100%-2px)] bg-gray-100 border-1 shadow-md rounded border-gray-300 p-2 pb-0 overflow-y-auto max-h-80 ${!isOpen ? 'hidden' : ''}` }, sources.map((source) => {
42
- const { id, name, type } = source;
43
- const isSelectedSource = id === selectedSource.id;
44
- return (React.createElement("li", { key: id, className: "flex items-center text-sm font-semibold mb-2 bg-white rounded" },
45
- React.createElement("button", { type: "button", onClick: () => handleSourceClick(source), className: `relative grow flex items-center p-2 border-1 border-white rounded hover:bg-gray-50 hover:border-gray-300 focus:bg-gray-100` },
46
- React.createElement(Icon, { icon: type, "aria-label": type, className: "shrink-0 mr-2.5" }),
47
- React.createElement("span", { className: "text-left mr-7" }, name),
48
- isSelectedSource && (React.createElement(Icon, { icon: 'selected', "aria-label": "selected", className: "absolute right-4" })))));
49
- }))))));
50
- }
@@ -1,7 +0,0 @@
1
- import { AuthenticationConfiguration } from '../types';
2
- export declare const useAuth: (authConfig: AuthenticationConfiguration | undefined) => {
3
- authToken: string | null;
4
- isAuthenticated: boolean;
5
- login: () => void;
6
- refreshAccessToken: () => Promise<string>;
7
- };
@@ -1,54 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { useState, useCallback, useEffect } from 'react';
3
- import { getCookieValue, refreshAccessToken as refreshTokenUtil } from '../utils/authUtils';
4
- export const useAuth = (authConfig) => {
5
- const [authToken, setAuthToken] = useState(getCookieValue('authToken'));
6
- const [isAuthenticated, setIsAuthenticated] = useState(!!getCookieValue('authToken'));
7
- const refreshAccessToken = useCallback(async () => {
8
- const newToken = await refreshTokenUtil(authConfig);
9
- setAuthToken(newToken);
10
- setIsAuthenticated(!!newToken);
11
- return newToken;
12
- }, [authConfig]);
13
- const handleLogin = useCallback(() => {
14
- if (!authConfig?.redirectUrl && !authConfig?.authUrl && !authConfig?.scope) {
15
- console.error('Auth config is misconfigured');
16
- return;
17
- }
18
- const encodedRedirectUrl = encodeURIComponent(authConfig.redirectUrl);
19
- const loginUrl = `${authConfig?.authUrl}?client_id=${authConfig?.clientId}&scope=${authConfig?.scope}&redirect_uri=${encodedRedirectUrl}&response_type=code&state=state`;
20
- const popup = window.open(loginUrl, 'Login', 'width=600,height=600');
21
- if (!popup) {
22
- console.error('Popup failed to open');
23
- return;
24
- }
25
- const checkPopup = setInterval(() => {
26
- try {
27
- if (getCookieValue('authToken') && getCookieValue('refreshToken')) {
28
- clearInterval(checkPopup);
29
- popup.close();
30
- setAuthToken(getCookieValue('authToken'));
31
- setIsAuthenticated(true);
32
- }
33
- }
34
- catch (error) {
35
- // Ignore cross-origin access errors
36
- }
37
- if (popup.closed) {
38
- clearInterval(checkPopup);
39
- console.error('Popup closed before authentication');
40
- }
41
- }, 1000); // Check every second
42
- }, [authConfig]);
43
- useEffect(() => {
44
- refreshAccessToken().catch(() => {
45
- setIsAuthenticated(false);
46
- });
47
- }, [authConfig, refreshAccessToken]);
48
- return {
49
- authToken,
50
- isAuthenticated,
51
- login: handleLogin,
52
- refreshAccessToken,
53
- };
54
- };
@@ -1,15 +0,0 @@
1
- import { ResourceBrowserPlugin, ResourceBrowserResource } from '../types';
2
- type UseResourceProps = {
3
- plugin: ResourceBrowserPlugin | null;
4
- resource: ResourceBrowserResource | null;
5
- };
6
- /**
7
- * Loads the selected state for the provided resource
8
- */
9
- export declare const useSelectedState: ({ plugin, resource }: UseResourceProps) => {
10
- data: import("../types").ResourceBrowserSelectedState | null;
11
- error: Error | null;
12
- isLoading: boolean;
13
- reload: () => void;
14
- };
15
- export {};
@@ -1,12 +0,0 @@
1
- import { useAsync } from '@squiz/generic-browser-lib';
2
- /**
3
- * Loads the selected state for the provided resource
4
- */
5
- export const useSelectedState = ({ plugin, resource }) => {
6
- // Find the resolver for this resource
7
- const renderSelectedResource = resource && plugin?.renderSelectedResource;
8
- return useAsync({
9
- callback: () => (resource && renderSelectedResource ? renderSelectedResource(resource) : null),
10
- defaultValue: null,
11
- }, [resource]);
12
- };
@@ -1,14 +0,0 @@
1
- import { ResourceBrowserSource, ResourceBrowserPlugin, ResourceBrowserSourceWithPlugin } from '../types';
2
- export type UseSourcesProps = {
3
- onRequestSources: () => Promise<ResourceBrowserSource[]>;
4
- plugins: Array<ResourceBrowserPlugin>;
5
- };
6
- /**
7
- * Loads and caches the source list when a component using the hook is mounted.
8
- */
9
- export declare const useSources: ({ onRequestSources, plugins }: UseSourcesProps) => {
10
- data: ResourceBrowserSourceWithPlugin[];
11
- error: Error | null;
12
- isLoading: boolean;
13
- reload: () => void;
14
- };
@@ -1,44 +0,0 @@
1
- import { useAsync } from '@squiz/generic-browser-lib';
2
- /**
3
- * Loads and caches the source list when a component using the hook is mounted.
4
- */
5
- export const useSources = ({ onRequestSources, plugins }) => {
6
- const pluginsKey = plugins.reduce((acc, plugin) => acc + plugin.type, '');
7
- return useAsync({
8
- callback: () => {
9
- return new Promise((resolve, reject) => {
10
- // Get all the sources from the outer context
11
- onRequestSources()
12
- .then((sources) => {
13
- // Remove any sources which we don't have a plugin to handle
14
- const filteredSources = sources.filter((source) => {
15
- return !!plugins.find((plugin) => {
16
- if (plugin.type === source.type) {
17
- return true;
18
- }
19
- return false;
20
- });
21
- });
22
- // Attach the plugin to the source so it can be quickly used later
23
- const combinedSources = filteredSources.map((source) => {
24
- const plugin = plugins.find((plugin) => {
25
- if (plugin.type === source.type) {
26
- return true;
27
- }
28
- return false;
29
- });
30
- return {
31
- ...source,
32
- plugin,
33
- };
34
- });
35
- resolve(combinedSources);
36
- })
37
- .catch((e) => {
38
- reject(e);
39
- });
40
- });
41
- },
42
- defaultValue: [],
43
- }, [onRequestSources, pluginsKey]);
44
- };
@@ -1,4 +0,0 @@
1
- import React, { SVGAttributes } from 'react';
2
- type AdsClickIconProps = SVGAttributes<SVGElement>;
3
- export declare const AdsClickIcon: (props: AdsClickIconProps) => React.JSX.Element;
4
- export {};
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- export const AdsClickIcon = (props) => {
3
- return (React.createElement("svg", { fill: "#4f4f4f", height: "24", width: "24", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props },
4
- React.createElement("path", { d: "M11.56 17.845C8.38001 17.695 5.85001 15.075 5.85001 11.855C5.85001 8.54501 8.54001 5.85501 11.85 5.85501C15.07 5.85501 17.69 8.38501 17.84 11.565L15.74 10.935C15.33 9.16501 13.74 7.85501 11.85 7.85501C9.64001 7.85501 7.85001 9.64501 7.85001 11.855C7.85001 13.745 9.16001 15.335 10.93 15.745L11.56 17.845ZM21.85 11.855C21.85 12.155 21.84 12.455 21.81 12.755L19.84 12.165C19.85 12.065 19.85 11.955 19.85 11.855C19.85 7.43501 16.27 3.85501 11.85 3.85501C7.43001 3.85501 3.85001 7.43501 3.85001 11.855C3.85001 16.275 7.43001 19.855 11.85 19.855C11.95 19.855 12.06 19.855 12.16 19.845L12.75 21.815C12.45 21.845 12.15 21.855 11.85 21.855C6.33001 21.855 1.85001 17.375 1.85001 11.855C1.85001 6.33501 6.33001 1.85501 11.85 1.85501C17.37 1.85501 21.85 6.33501 21.85 11.855ZM18.08 16.115L20.35 15.355C20.81 15.205 20.8 14.545 20.34 14.405L12.74 12.125C12.36 12.015 12 12.365 12.12 12.745L14.4 20.345C14.54 20.815 15.2 20.825 15.35 20.355L16.11 18.085L20.02 21.995C20.22 22.195 20.53 22.195 20.73 21.995L22 20.725C22.2 20.525 22.2 20.215 22 20.015L18.08 16.115Z" })));
5
- };
@@ -1,4 +0,0 @@
1
- import React, { SVGAttributes } from 'react';
2
- type ArrowDownIconProps = SVGAttributes<SVGElement>;
3
- export declare const ArrowDownIcon: (props: ArrowDownIconProps) => React.JSX.Element;
4
- export {};
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- export const ArrowDownIcon = (props) => {
3
- return (React.createElement("svg", { fill: "#4f4f4f", height: "25", width: "24", viewBox: "0 0 24 25", xmlns: "http://www.w3.org/2000/svg", ...props },
4
- React.createElement("path", { d: "M8.12459 9.49953L12.0046 13.3795L15.8846 9.49953C16.2746 9.10953 16.9046 9.10953 17.2946 9.49953C17.6846 9.88953 17.6846 10.5195 17.2946 10.9095L12.7046 15.4995C12.3146 15.8895 11.6846 15.8895 11.2946 15.4995L6.70459 10.9095C6.51734 10.7227 6.41211 10.469 6.41211 10.2045C6.41211 9.94001 6.51734 9.68636 6.70459 9.49953C7.09459 9.11953 7.73459 9.10953 8.12459 9.49953Z" })));
5
- };
@@ -1,4 +0,0 @@
1
- import React, { SVGAttributes } from 'react';
2
- type CircledLoopIconProps = SVGAttributes<SVGElement>;
3
- export declare const CircledLoopIcon: (props: CircledLoopIconProps) => React.JSX.Element;
4
- export {};
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- export const CircledLoopIcon = (props) => {
3
- return (React.createElement("svg", { fill: "none", height: "16", viewBox: "0 0 16 16", width: "16", xmlns: "http://www.w3.org/2000/svg", ...props },
4
- React.createElement("path", { d: "M8 0.5C3.86 0.5 0.5 3.86 0.5 8C0.5 12.14 3.86 15.5 8 15.5C12.14 15.5 15.5 12.14 15.5 8C15.5 3.86 12.14 0.5 8 0.5ZM8 14C4.6925 14 2 11.3075 2 8C2 4.6925 4.6925 2 8 2C11.3075 2 14 4.6925 14 8C14 11.3075 11.3075 14 8 14ZM11.1275 10.07L10.3025 9.245C10.835 8.2475 10.7 6.9875 9.86 6.1475C9.3425 5.63 8.675 5.375 8 5.375C7.9775 5.375 7.955 5.3825 7.9325 5.3825L8.75 6.2L7.955 6.995L5.8325 4.8725L7.955 2.75L8.75 3.545L8.03 4.265C8.9825 4.2725 9.9275 4.625 10.655 5.345C11.93 6.6275 12.0875 8.615 11.1275 10.07ZM10.1675 11.1275L8.045 13.25L7.25 12.455L7.9625 11.7425C7.0175 11.735 6.0725 11.3675 5.3525 10.6475C4.07 9.365 3.9125 7.385 4.8725 5.93L5.6975 6.755C5.165 7.7525 5.3 9.0125 6.14 9.8525C6.665 10.3775 7.3625 10.6325 8.06 10.61L7.25 9.8L8.045 9.005L10.1675 11.1275Z", fill: "#949494" })));
5
- };
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { DOMAttributes, FocusableElement } from '@react-types/shared';
3
- import { ResourceBrowserPlugin, ResourceBrowserSource, ResourceBrowserResource, ResourceBrowserSourceWithPlugin, PluginLaunchMode } from '../types';
4
- interface MainContainerProps {
5
- title: string;
6
- titleAriaProps: DOMAttributes<FocusableElement>;
7
- allowedTypes: string[] | undefined;
8
- sources: ResourceBrowserSourceWithPlugin[];
9
- selectedSource: ResourceBrowserSource | null;
10
- onSourceSelect(source: ResourceBrowserSource, mode?: PluginLaunchMode): void;
11
- onChange(resource: ResourceBrowserResource | null): void;
12
- onClose: () => void;
13
- preselectedResource?: ResourceBrowserResource | null;
14
- plugin: ResourceBrowserPlugin | null;
15
- pluginMode: PluginLaunchMode | null;
16
- searchEnabled: boolean;
17
- }
18
- declare function MainContainer({ title, titleAriaProps, allowedTypes, sources, selectedSource, onSourceSelect, onChange, onClose, preselectedResource, plugin, pluginMode, searchEnabled, }: MainContainerProps): React.JSX.Element;
19
- export default MainContainer;
@@ -1,43 +0,0 @@
1
- import React, { useCallback, useState } from 'react';
2
- import SourceList from '../SourceList/SourceList';
3
- import ResourceLauncher from '../ResourceLauncher/ResourceLauncher';
4
- import SourceDropdownContainer from '../SourceDropdownContainer/SourceDropdownContainer';
5
- import SourceDropdown from '../SourceDropdown/SourceDropdown';
6
- import { PluginLaunchModeType, } from '../types';
7
- function MainContainer({ title, titleAriaProps, allowedTypes, sources, selectedSource, onSourceSelect, onChange, onClose, preselectedResource, plugin, pluginMode, searchEnabled, }) {
8
- const [headerPortal, setHeaderPortal] = useState(null);
9
- const pluginToRender = pluginMode ? pluginMode.type : PluginLaunchModeType.Browse; // Cant default a 'null' property in signature so set it here
10
- const SourceBrowser = plugin?.sourceBrowserComponent();
11
- const SourceSearch = plugin?.sourceSearchComponent();
12
- // Can't use a useRef as it wont update on change when a source is selected, so need to use a ref callback to store in state
13
- const setHeaderPortalRef = useCallback((node) => {
14
- if (node !== null) {
15
- setHeaderPortal(node);
16
- }
17
- }, [setHeaderPortal]);
18
- // MainContainer will either render the source list view if no source is set or the plugins UI if a source has been selected
19
- return (React.createElement("div", { className: "relative flex flex-col h-full text-gray-800" },
20
- React.createElement("div", { className: "flex items-center py-3 pl-6 pr-10 min-h-[68px]" },
21
- React.createElement("h2", { ...titleAriaProps, className: "text-xl leading-6 text-gray-800 font-semibold mr-6" }, title),
22
- plugin && selectedSource && (React.createElement(React.Fragment, null,
23
- plugin.createHeaderPortal && React.createElement("div", { ref: setHeaderPortalRef, className: "squiz-rb-plugin" }),
24
- !plugin.createHeaderPortal && sources.length > 1 && (React.createElement(SourceDropdownContainer, { isCollapsed: false, onExpand: () => { } },
25
- React.createElement("div", { className: `border-l border-blue-200 pl-1 w-[204px]` },
26
- React.createElement(SourceDropdown, { sources: sources, selectedSource: selectedSource, onSourceSelect: onSourceSelect })))))),
27
- React.createElement("button", { type: "button", "aria-label": `Close ${title} dialog`, onClick: onClose, className: "absolute top-2 right-2 p-2.5 rounded hover:bg-blue-100 focus:bg-blue-100" },
28
- React.createElement("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
29
- React.createElement("path", { d: "M13.3 0.710017C13.1131 0.522765 12.8595 0.417532 12.595 0.417532C12.3305 0.417532 12.0768 0.522765 11.89 0.710017L6.99997 5.59002L2.10997 0.700017C1.92314 0.512765 1.66949 0.407532 1.40497 0.407532C1.14045 0.407532 0.886802 0.512765 0.699971 0.700017C0.309971 1.09002 0.309971 1.72002 0.699971 2.11002L5.58997 7.00002L0.699971 11.89C0.309971 12.28 0.309971 12.91 0.699971 13.3C1.08997 13.69 1.71997 13.69 2.10997 13.3L6.99997 8.41002L11.89 13.3C12.28 13.69 12.91 13.69 13.3 13.3C13.69 12.91 13.69 12.28 13.3 11.89L8.40997 7.00002L13.3 2.11002C13.68 1.73002 13.68 1.09002 13.3 0.710017Z", fill: "currentColor" })))),
30
- React.createElement("div", { className: "border-t border-gray-300 overflow-y-hidden" },
31
- plugin && selectedSource && (React.createElement("div", { className: `squiz-rb-plugin squiz-rb-plugin--${pluginMode?.type}` },
32
- pluginToRender === PluginLaunchModeType.Browse && SourceBrowser && (React.createElement(SourceBrowser, { source: selectedSource, sources: sources, onSourceSelect: onSourceSelect, allowedTypes: allowedTypes, headerPortal: plugin.createHeaderPortal && headerPortal ? headerPortal : undefined, searchEnabled: searchEnabled, preselectedResource: preselectedResource || undefined, browseTo: pluginMode?.args?.browseTo, onSelected: (resource) => {
33
- onChange(resource);
34
- onClose();
35
- } })),
36
- pluginToRender === PluginLaunchModeType.Search && SourceSearch && (React.createElement(SourceSearch, { source: selectedSource, sources: sources, onSourceSelect: onSourceSelect, allowedTypes: allowedTypes, headerPortal: plugin.createHeaderPortal && headerPortal ? headerPortal : undefined, searchEnabled: searchEnabled, query: pluginMode?.args?.query, onSelected: (resource) => {
37
- onChange(resource);
38
- onClose();
39
- } })))),
40
- !selectedSource && searchEnabled && React.createElement(ResourceLauncher, { sources: sources, onSourceSelect: onSourceSelect }),
41
- !selectedSource && !searchEnabled && React.createElement(SourceList, { sources: sources, onSourceSelect: onSourceSelect }))));
42
- }
43
- export default MainContainer;
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import { ResourceBrowserInputProps } from '../ResourceBrowserInput/ResourceBrowserInput';
3
- /**
4
- * This plugin component exsits to deal with React rules of Hooks stupidity.
5
- *
6
- * For it to not freak out when we want to change from one plugin to another we have to render
7
- * something to the ReactDom for each plugin and 'activate' that component when that plugin
8
- * needs to render its UI etc.
9
- */
10
- export type PluginRenderType = ResourceBrowserInputProps & {
11
- render: boolean;
12
- };
13
- export declare const PluginRender: ({ render, ...props }: PluginRenderType) => React.JSX.Element;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { ResourceBrowserInput } from '../ResourceBrowserInput/ResourceBrowserInput';
3
- import { AuthProvider } from '../ResourceBrowserContext/AuthProvider';
4
- export const PluginRender = ({ render, ...props }) => {
5
- if (render) {
6
- return (React.createElement(AuthProvider, { authConfig: props.source },
7
- React.createElement(ResourceBrowserInput, { ...props })));
8
- }
9
- else {
10
- return React.createElement(React.Fragment, null);
11
- }
12
- };
@@ -1,16 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { ResourceBrowserSource } from '../types';
3
- interface AuthContextProps {
4
- authToken: string | null;
5
- isAuthenticated: boolean;
6
- login: () => void;
7
- refreshAccessToken: () => Promise<any>;
8
- }
9
- export declare const AuthContext: React.Context<AuthContextProps | undefined>;
10
- export declare const useAuthContext: () => AuthContextProps;
11
- interface AuthProviderProps {
12
- children: ReactNode;
13
- authConfig?: ResourceBrowserSource | null;
14
- }
15
- export declare const AuthProvider: ({ children, authConfig }: AuthProviderProps) => React.JSX.Element;
16
- export {};
@@ -1,18 +0,0 @@
1
- import React, { createContext, useContext } from 'react';
2
- import { useAuth } from '../Hooks/useAuth';
3
- export const AuthContext = createContext(undefined);
4
- export const useAuthContext = () => {
5
- const context = useContext(AuthContext);
6
- if (!context) {
7
- throw new Error('useAuthContext must be used within an AuthProvider');
8
- }
9
- return context;
10
- };
11
- export const AuthProvider = ({ children, authConfig }) => {
12
- const authConfiguration = authConfig;
13
- const auth = useAuth(authConfiguration?.configuration);
14
- if (!authConfiguration?.configuration) {
15
- return React.createElement(React.Fragment, null, children);
16
- }
17
- return React.createElement(AuthContext.Provider, { value: auth }, children);
18
- };
@@ -1,15 +0,0 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { OnRequestSources, ResourceBrowserPlugin } from '../types';
3
- export type ResourceBrowserContextProps = {
4
- onRequestSources: OnRequestSources;
5
- searchEnabled: boolean;
6
- plugins: Array<ResourceBrowserPlugin>;
7
- };
8
- /**
9
- * @internal Direct usage of this object is discouraged. It will be privated in a future major version.
10
- * Please use ResourceBrowserContextProvider instead.
11
- */
12
- export declare const ResourceBrowserContext: React.Context<ResourceBrowserContextProps>;
13
- export declare const ResourceBrowserContextProvider: (props: PropsWithChildren<{
14
- value: ResourceBrowserContextProps;
15
- }>) => React.JSX.Element;
@@ -1,26 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import pMemoize from 'p-memoize';
3
- import ExpiryMap from 'expiry-map';
4
- /**
5
- * @internal Direct usage of this object is discouraged. It will be privated in a future major version.
6
- * Please use ResourceBrowserContextProvider instead.
7
- */
8
- export const ResourceBrowserContext = React.createContext({
9
- onRequestSources: () => {
10
- throw new Error('onRequestSources has not been configured.');
11
- },
12
- searchEnabled: false,
13
- plugins: [],
14
- });
15
- export const ResourceBrowserContextProvider = (props) => {
16
- const CACHE_DURATION = 30000; // 30 seconds
17
- const { value: { onRequestSources, ...other }, children, } = props;
18
- const cache = new ExpiryMap(CACHE_DURATION);
19
- const memoized = useMemo(() => ({
20
- onRequestSources: pMemoize(onRequestSources, {
21
- cache,
22
- cacheKey: () => 'onRequestSources',
23
- }),
24
- }), [onRequestSources]);
25
- return React.createElement(ResourceBrowserContext.Provider, { value: { ...memoized, ...other } }, children);
26
- };
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import { ResourceBrowserPlugin, ResourceBrowserSource, ResourceBrowserUnresolvedResource, ResourceBrowserResource, ResourceBrowserSourceWithPlugin, PluginLaunchMode } from '../types';
3
- export type ResourceBrowserInputProps = {
4
- modalTitle: string;
5
- allowedTypes?: string[];
6
- isDisabled?: boolean;
7
- value: ResourceBrowserUnresolvedResource | null;
8
- useResource(referenceId: string | null, source: ResourceBrowserSource | null): {
9
- data: ResourceBrowserResource | null;
10
- error: Error | null;
11
- isLoading: boolean;
12
- };
13
- onChange(resource: ResourceBrowserResource | null): void;
14
- onClear?(): void;
15
- plugin: ResourceBrowserPlugin | null;
16
- pluginMode: PluginLaunchMode | null;
17
- searchEnabled: boolean;
18
- source: ResourceBrowserSource | null;
19
- sources: ResourceBrowserSourceWithPlugin[];
20
- isLoading: boolean;
21
- error: Error | null;
22
- setSource(source: ResourceBrowserSource, mode?: PluginLaunchMode): void;
23
- isModalOpen: boolean;
24
- onModalStateChange(isOpen: boolean): void;
25
- };
26
- export declare const ResourceBrowserInput: ({ modalTitle, allowedTypes, onChange, value, useResource, isDisabled, onClear, plugin, pluginMode, searchEnabled, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }: ResourceBrowserInputProps) => React.JSX.Element;
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import MainContainer from '../MainContainer/MainContainer';
3
- import { ResourcePicker } from '../ResourcePicker/ResourcePicker';
4
- export const ResourceBrowserInput = ({ modalTitle, allowedTypes, onChange, value, useResource, isDisabled, onClear, plugin, pluginMode, searchEnabled, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }) => {
5
- const { data: resource, error: resourceError, isLoading: isResourceLoading } = useResource(value?.resourceId || null, source);
6
- const defaultOnClear = () => onChange(null);
7
- const onClearFunction = onClear ?? defaultOnClear;
8
- return (React.createElement(ResourcePicker, { resource: resource, plugin: plugin, allowedTypes: allowedTypes, error: resourceError || error, isLoading: isResourceLoading || isLoading, isDisabled: isDisabled, onClear: onClearFunction, isModalOpen: isModalOpen, onModalStateChange: onModalStateChange }, (onClose, titleProps) => (React.createElement(MainContainer, { selectedSource: source, sources: sources, preselectedResource: resource, plugin: plugin, pluginMode: pluginMode, searchEnabled: searchEnabled, title: modalTitle, titleAriaProps: titleProps, allowedTypes: allowedTypes, onSourceSelect: setSource, onClose: onClose, onChange: onChange }))));
9
- };
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import { ResourceBrowserSource, ResourceBrowserSourceWithPlugin, PluginLaunchMode } from '../types';
3
- interface ResourceLauncherProps {
4
- sources: ResourceBrowserSourceWithPlugin[];
5
- onSourceSelect(source: ResourceBrowserSource, mode: PluginLaunchMode): void;
6
- }
7
- declare function ResourceLauncher({ sources, onSourceSelect }: ResourceLauncherProps): React.JSX.Element;
8
- export default ResourceLauncher;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { PluginLaunchModeType } from '../types';
3
- function ResourceLauncher({ sources, onSourceSelect }) {
4
- return (React.createElement("div", { className: "overflow-y-scroll w-screen max-w-[400px] min-h-[290px] flex-1 grow-[3] border-r border-gray-300 bg-gray-100 pl-6 pr-6 pb-6 pt-4" },
5
- React.createElement("ul", { tabIndex: -1, "aria-label": `sources list`, className: "flex flex-col bg-gray-100 min-h-full focus-visible:outline-0" }, sources.map((source, index) => {
6
- const SourceLauncher = source.plugin.renderResourceLauncher();
7
- return (React.createElement("li", { key: index, className: "flex items-stretch relative" },
8
- React.createElement("div", { className: `squiz-rb-plugin squiz-rb-plugin--${source.plugin?.type} w-full` },
9
- React.createElement(SourceLauncher, { source: source, onSearch: (query) => onSourceSelect(source, { type: PluginLaunchModeType.Search, args: { query } }), onBrowse: (browseTo) => onSourceSelect(source, { type: PluginLaunchModeType.Browse, args: { browseTo } }) }))));
10
- }))));
11
- }
12
- export default ResourceLauncher;
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { DOMAttributes } from '@react-types/shared';
3
- import { ResourceBrowserResource, ResourceBrowserPlugin } from '../types';
4
- export type ResourcePickerProps = {
5
- resource: ResourceBrowserResource | null;
6
- plugin: ResourceBrowserPlugin | null;
7
- allowedTypes: string[] | undefined;
8
- error: Error | null;
9
- isLoading: boolean;
10
- isDisabled?: boolean;
11
- children: (onClose: () => void, titleProps: DOMAttributes) => React.ReactElement;
12
- onClear: () => void;
13
- isModalOpen: boolean;
14
- onModalStateChange(isOpen: boolean): void;
15
- };
16
- export declare const ResourcePicker: ({ resource, plugin, allowedTypes, error: externalError, isLoading: isExternalLoading, isDisabled, children, onClear, isModalOpen, onModalStateChange, }: ResourcePickerProps) => React.JSX.Element;
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import AdsClickRoundedIcon from '@mui/icons-material/AdsClickRounded';
3
- import AddCircleOutlineRoundedIcon from '@mui/icons-material/AddCircleOutlineRounded';
4
- import PhotoLibraryRoundedIcon from '@mui/icons-material/PhotoLibraryRounded';
5
- import { ModalTrigger } from '@squiz/resource-browser-ui-lib';
6
- import { ErrorState } from './States/Error';
7
- import { LoadingState } from './States/Loading';
8
- import { SelectedState } from './States/Selected';
9
- import { useSelectedState } from '../Hooks/useSelectedState';
10
- import clsx from 'clsx';
11
- export const ResourcePicker = ({ resource, plugin, allowedTypes, error: externalError, isLoading: isExternalLoading, isDisabled, children, onClear, isModalOpen, onModalStateChange, }) => {
12
- const { data: selectedState, error, isLoading } = useSelectedState({ resource, plugin });
13
- const isImagePicker = allowedTypes && allowedTypes.length === 1 && allowedTypes.includes('image');
14
- const isEmpty = resource === null && !isExternalLoading && !externalError;
15
- return (React.createElement("div", { className: clsx('resource-picker', isDisabled && 'resource-picker--disabled') },
16
- isImagePicker ? (React.createElement(PhotoLibraryRoundedIcon, { "aria-hidden": true, className: "w-6 h-6" })) : (React.createElement(AdsClickRoundedIcon, { "aria-hidden": true, className: "w-6 h-6" })),
17
- isEmpty ? (React.createElement(ModalTrigger, { overlayTriggerState: {
18
- isOpen: isModalOpen,
19
- onOpenChange: onModalStateChange,
20
- }, showLabel: true, label: isImagePicker ? `Choose image` : `Choose asset`, icon: React.createElement(AddCircleOutlineRoundedIcon, { "aria-hidden": true, className: `!w-4 !h-4 text-blue-300 ${isDisabled ? 'text-gray-600' : ''}` }), isDisabled: isDisabled, scope: "squiz-rb-scope" }, children)) : (React.createElement("div", { className: "resource-picker-info" },
21
- React.createElement("div", { className: "resource-picker-info__layout" },
22
- (isExternalLoading || isLoading) && React.createElement(LoadingState, null),
23
- (externalError || error) && (React.createElement(ErrorState, { error: externalError || error, isDisabled: isDisabled, onClear: onClear })),
24
- !isExternalLoading && resource && selectedState && (React.createElement(SelectedState, { isModalOpen: isModalOpen, onModalStateChange: onModalStateChange, resource: resource, showThumbnail: selectedState?.showThumbnail || false, icon: selectedState?.icon, label: selectedState?.label, description: selectedState?.description, isDisabled: isDisabled, onClear: onClear, resourcePickerContainer: children })))))));
25
- };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- export type ErrorStateProps = {
3
- error: Error;
4
- isDisabled?: boolean;
5
- onClear: () => void;
6
- };
7
- export declare const ErrorState: ({ error, isDisabled, onClear }: ErrorStateProps) => React.JSX.Element;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- import { Icon, ResetButton } from '@squiz/generic-browser-lib';
3
- export const ErrorState = ({ error, isDisabled, onClear }) => (React.createElement(React.Fragment, null,
4
- React.createElement(Icon, { icon: 'error', "aria-hidden": true, className: "w-6 h-6 text-red-300" }),
5
- React.createElement("div", { className: "text-red-300 w-full" }, error.message),
6
- React.createElement(ResetButton, { isDisabled: isDisabled, onClick: onClear })));
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const LoadingState: () => React.JSX.Element;
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import { Spinner } from '@squiz/generic-browser-lib';
3
- export const LoadingState = () => (React.createElement("div", { className: "col-start-2 col-end-2" },
4
- React.createElement(Spinner, { label: "Loading selection", className: "m-2" })));
@@ -1,15 +0,0 @@
1
- import React, { ReactElement } from 'react';
2
- import { ResourceBrowserResource } from '../../types';
3
- export type SelectedStateProps = {
4
- resource: ResourceBrowserResource;
5
- showThumbnail: boolean;
6
- icon: ReactElement | undefined;
7
- label: string;
8
- description: Array<ReactElement>;
9
- isDisabled?: boolean;
10
- onClear: () => void;
11
- resourcePickerContainer: any;
12
- isModalOpen?: boolean;
13
- onModalStateChange?(isOpen: boolean): void;
14
- };
15
- export declare const SelectedState: ({ resource, showThumbnail, icon, label, description, isDisabled, onClear, resourcePickerContainer, isModalOpen, onModalStateChange, }: SelectedStateProps) => React.JSX.Element;