@squiz/resource-browser 1.69.1 → 2.1.8-rc.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/CHANGELOG.md +88 -35
- package/LICENSE.md +15 -0
- package/README.md +9 -0
- package/jest.config.ts +22 -21
- package/lib/Hooks/useSelectedState.d.ts +15 -0
- package/lib/Hooks/useSelectedState.js +16 -0
- package/lib/Hooks/useSources.d.ts +5 -4
- package/lib/Hooks/useSources.js +25 -1
- package/lib/MainContainer/MainContainer.d.ts +17 -0
- package/lib/MainContainer/MainContainer.js +61 -0
- package/lib/Plugin/Plugin.d.ts +13 -0
- package/lib/Plugin/Plugin.js +17 -0
- package/lib/ResourceBrowserContext/ResourceBrowserContext.d.ts +2 -3
- package/lib/ResourceBrowserContext/ResourceBrowserContext.js +4 -17
- package/lib/ResourceBrowserInput/ResourceBrowserInput.d.ts +24 -0
- package/lib/ResourceBrowserInput/ResourceBrowserInput.js +16 -0
- package/lib/ResourcePicker/ResourcePicker.d.ts +6 -4
- package/lib/ResourcePicker/ResourcePicker.js +14 -8
- package/lib/ResourcePicker/States/Selected.d.ts +10 -4
- package/lib/ResourcePicker/States/Selected.js +11 -32
- package/lib/SourceDropdown/SourceDropdown.d.ts +5 -11
- package/lib/SourceDropdown/SourceDropdown.js +20 -99
- package/lib/SourceList/SourceList.d.ts +5 -16
- package/lib/SourceList/SourceList.js +14 -75
- package/lib/index.css +42 -202
- package/lib/index.d.ts +7 -7
- package/lib/index.js +69 -13
- package/lib/types.d.ts +41 -59
- package/package.json +82 -80
- package/src/Hooks/useSelectedState.spec.ts +46 -0
- package/src/Hooks/useSelectedState.ts +22 -0
- package/src/Hooks/useSources.spec.ts +30 -12
- package/src/Hooks/useSources.ts +33 -4
- package/src/Icons/CircledLoopIcon.tsx +8 -8
- package/src/MainContainer/MainContainer.spec.tsx +203 -0
- package/src/MainContainer/MainContainer.stories.tsx +62 -0
- package/src/MainContainer/MainContainer.tsx +101 -0
- package/src/Plugin/Plugin.spec.tsx +46 -0
- package/src/Plugin/Plugin.tsx +20 -0
- package/src/ResourceBrowserContext/ResourceBrowserContext.spec.tsx +65 -106
- package/src/ResourceBrowserContext/ResourceBrowserContext.tsx +24 -39
- package/src/ResourceBrowserInput/ResourceBrowserInput.spec.tsx +192 -0
- package/src/ResourceBrowserInput/ResourceBrowserInput.tsx +81 -0
- package/src/ResourcePicker/ResourcePicker.spec.tsx +159 -116
- package/src/ResourcePicker/ResourcePicker.stories.tsx +28 -24
- package/src/ResourcePicker/ResourcePicker.tsx +79 -59
- package/src/ResourcePicker/States/Error.tsx +8 -8
- package/src/ResourcePicker/States/Loading.tsx +3 -3
- package/src/ResourcePicker/States/Selected.tsx +66 -73
- package/src/ResourcePicker/mock-image-resource.json +25 -47
- package/src/ResourcePicker/mock-resource.json +11 -13
- package/src/ResourcePicker/resource-picker.scss +13 -13
- package/src/SourceDropdown/SourceDropdown.spec.tsx +65 -391
- package/src/SourceDropdown/SourceDropdown.stories.tsx +21 -24
- package/src/SourceDropdown/SourceDropdown.tsx +80 -258
- package/src/SourceList/SourceList.spec.tsx +37 -430
- package/src/SourceList/SourceList.stories.tsx +17 -37
- package/src/SourceList/SourceList.tsx +28 -155
- package/src/__mocks__/MockModels.ts +56 -25
- package/src/__mocks__/PluginExample.tsx +98 -0
- package/src/__mocks__/StorybookHelpers.tsx +141 -0
- package/src/__mocks__/renderWithContext.tsx +14 -18
- package/src/__mocks__/sample-sources.json +32 -0
- package/src/index.scss +18 -8
- package/src/index.spec.tsx +277 -99
- package/src/index.stories.tsx +65 -39
- package/src/index.tsx +119 -57
- package/src/types.ts +54 -63
- package/tailwind.config.cjs +92 -92
- package/vite.config.js +12 -12
- package/lib/Hooks/useCategorisedSources.d.ts +0 -14
- package/lib/Hooks/useCategorisedSources.js +0 -38
- package/lib/Hooks/useChildResources.d.ts +0 -16
- package/lib/Hooks/useChildResources.js +0 -13
- package/lib/Hooks/usePreselectedResourcePath.d.ts +0 -20
- package/lib/Hooks/usePreselectedResourcePath.js +0 -31
- package/lib/Hooks/useRecentLocations.d.ts +0 -5
- package/lib/Hooks/useRecentLocations.js +0 -38
- package/lib/Hooks/useRecentResourcesPaths.d.ts +0 -20
- package/lib/Hooks/useRecentResourcesPaths.js +0 -30
- package/lib/Hooks/useResource.d.ts +0 -28
- package/lib/Hooks/useResource.js +0 -23
- package/lib/Hooks/useResourcePath.d.ts +0 -16
- package/lib/Hooks/useResourcePath.js +0 -64
- package/lib/Icons/HistoryIcon.d.ts +0 -4
- package/lib/Icons/HistoryIcon.js +0 -13
- package/lib/PreviewPanel/PreviewPanel.d.ts +0 -5
- package/lib/PreviewPanel/PreviewPanel.js +0 -8
- package/lib/PreviewPanel/details/MatrixResource.d.ts +0 -7
- package/lib/PreviewPanel/details/MatrixResource.js +0 -35
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +0 -9
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +0 -54
- package/lib/ResourceList/ResourceList.d.ts +0 -18
- package/lib/ResourceList/ResourceList.js +0 -49
- package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +0 -17
- package/lib/ResourcePickerContainer/ResourcePickerContainer.js +0 -166
- package/lib/StatusIndicator/StatusIndicator.d.ts +0 -8
- package/lib/StatusIndicator/StatusIndicator.js +0 -27
- package/lib/utils/findBestMatchLineage.d.ts +0 -2
- package/lib/utils/findBestMatchLineage.js +0 -28
- package/lib/utils/uuid.d.ts +0 -1
- package/lib/utils/uuid.js +0 -6
- package/src/Hooks/useCategorisedSources.spec.ts +0 -39
- package/src/Hooks/useCategorisedSources.ts +0 -46
- package/src/Hooks/useChildResources.spec.ts +0 -29
- package/src/Hooks/useChildResources.ts +0 -21
- package/src/Hooks/usePreselectedResourcePath.ts +0 -54
- package/src/Hooks/useRecentLocations.spec.ts +0 -81
- package/src/Hooks/useRecentLocations.ts +0 -44
- package/src/Hooks/useRecentResourcesPaths.ts +0 -54
- package/src/Hooks/useResource.spec.ts +0 -61
- package/src/Hooks/useResource.ts +0 -38
- package/src/Hooks/useResourcePath.spec.ts +0 -120
- package/src/Hooks/useResourcePath.ts +0 -76
- package/src/Icons/HistoryIcon.tsx +0 -17
- package/src/PreviewPanel/PreviewPanel.spec.tsx +0 -198
- package/src/PreviewPanel/PreviewPanel.stories.tsx +0 -76
- package/src/PreviewPanel/PreviewPanel.tsx +0 -6
- package/src/PreviewPanel/details/MatrixResource.tsx +0 -54
- package/src/PreviewPanel/details/matrix-resource.scss +0 -16
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +0 -133
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +0 -24
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +0 -79
- package/src/ResourceBreadcrumb/resource-breadcrumb.scss +0 -28
- package/src/ResourceBreadcrumb/sample-hierarchy.json +0 -27
- package/src/ResourceList/ResourceList.spec.tsx +0 -202
- package/src/ResourceList/ResourceList.stories.tsx +0 -40
- package/src/ResourceList/ResourceList.tsx +0 -83
- package/src/ResourceList/sample-resources.json +0 -851
- package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +0 -780
- package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +0 -45
- package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +0 -290
- package/src/SourceList/sample-sources.json +0 -251
- package/src/StatusIndicator/StatusIndicator.stories.tsx +0 -83
- package/src/StatusIndicator/StatusIndicator.tsx +0 -38
- package/src/__mocks__/JestHelpers.ts +0 -65
- package/src/__mocks__/StorybookHelpers.ts +0 -128
- package/src/__mocks__/jestHelpers.spec.ts +0 -38
- package/src/utils/findBestMatchLineage.spec.ts +0 -81
- package/src/utils/findBestMatchLineage.ts +0 -30
- package/src/utils/uuid.ts +0 -5
package/src/index.tsx
CHANGED
@@ -1,64 +1,126 @@
|
|
1
|
-
import React, { useContext } from 'react';
|
2
|
-
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
ResourceBrowserContextProps,
|
8
|
-
} from './ResourceBrowserContext/ResourceBrowserContext';
|
9
|
-
import ResourcePicker from './ResourcePicker/ResourcePicker';
|
10
|
-
import { useResource } from './Hooks/useResource';
|
1
|
+
import React, { useState, useContext, useEffect, useCallback } from 'react';
|
2
|
+
|
3
|
+
import { ResourceBrowserContext, ResourceBrowserContextProvider } from './ResourceBrowserContext/ResourceBrowserContext';
|
4
|
+
import { ResourceBrowserSource, ResourceBrowserUnresolvedResource, ResourceBrowserResource, ResourceBrowserPlugin } from './types';
|
5
|
+
import { useSources } from './Hooks/useSources';
|
6
|
+
import { PluginRender } from './Plugin/Plugin';
|
11
7
|
|
12
|
-
export type { HydratedResourceReference, Resource, ResourceReference, Source, ResourceBrowserContextProps };
|
13
8
|
export { ResourceBrowserContext, ResourceBrowserContextProvider };
|
9
|
+
export * from './types';
|
14
10
|
|
15
|
-
export type
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
export type ResourceBrowserProps = {
|
12
|
+
modalTitle: string;
|
13
|
+
allowedTypes?: string[];
|
14
|
+
isDisabled?: boolean;
|
15
|
+
value: ResourceBrowserUnresolvedResource | null;
|
16
|
+
onChange(resource: ResourceBrowserResource | null): void;
|
17
|
+
onClear?(): void;
|
22
18
|
};
|
23
19
|
|
24
|
-
export const
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
20
|
+
export const ResourceBrowser = (props: ResourceBrowserProps) => {
|
21
|
+
const { value } = props;
|
22
|
+
const [error, setError] = useState<Error | null>(null);
|
23
|
+
const { onRequestSources, plugins } = useContext(ResourceBrowserContext);
|
24
|
+
|
25
|
+
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
26
|
+
const [source, setSource] = useState<ResourceBrowserSource | null>(null);
|
27
|
+
const { data: sources, isLoading, error: sourcesError } = useSources({ onRequestSources, plugins });
|
28
|
+
const [plugin, setPlugin] = useState<ResourceBrowserPlugin | null>(null);
|
29
|
+
|
30
|
+
// MainContainer will render a list of sources of one is not provided to it, callback to allow it to set the source once a user selects
|
31
|
+
const handleSourceSelect = useCallback(
|
32
|
+
(source: ResourceBrowserSource | null) => {
|
33
|
+
setSource(source);
|
34
|
+
},
|
35
|
+
[setSource],
|
36
|
+
);
|
37
|
+
|
38
|
+
// Try to auto set the source
|
39
|
+
useEffect(() => {
|
40
|
+
let source: ResourceBrowserSource | null = null;
|
41
|
+
setError(null);
|
42
|
+
|
43
|
+
// If there is a provided value try to use its source
|
44
|
+
if (value) {
|
45
|
+
// Search the sources for it matching against the value.source property
|
46
|
+
source = sources.find((source) => source.id === value?.sourceId) || null;
|
47
|
+
// If the source is null and we arent loading the sources
|
48
|
+
if (source === null && !isLoading) {
|
49
|
+
// Set an error as the passed in value's source wasnt returned by onRequestSources
|
50
|
+
setError(new Error('Unable to find resource source.'));
|
51
|
+
}
|
52
|
+
} else if (sources?.length === 1) {
|
53
|
+
// If only one source is passed in select it automatically
|
54
|
+
source = sources[0];
|
55
|
+
}
|
56
|
+
|
57
|
+
setSource(source);
|
58
|
+
}, [value, isLoading, sources, setSource, setError]);
|
59
|
+
|
60
|
+
useEffect(() => {
|
61
|
+
if (source) {
|
62
|
+
const plugin = plugins.find((plugin) => {
|
63
|
+
return plugin.type === source.type;
|
64
|
+
});
|
65
|
+
setPlugin(plugin || null);
|
66
|
+
} else {
|
67
|
+
setPlugin(null);
|
68
|
+
}
|
69
|
+
}, [plugins, source]);
|
70
|
+
|
71
|
+
const handleModalStateChange = useCallback(
|
72
|
+
(isOpen: boolean) => {
|
73
|
+
setIsModalOpen(isOpen);
|
74
|
+
},
|
75
|
+
[setIsModalOpen],
|
76
|
+
);
|
77
|
+
useEffect(() => {
|
78
|
+
if (!isModalOpen && !value && sources?.length > 1) {
|
79
|
+
setSource(null);
|
80
|
+
}
|
81
|
+
}, [sources, isModalOpen]);
|
36
82
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
83
|
+
// Render a default "plugin" and one for each item in the plugins array. They are conditionally rendered based on what is selected
|
84
|
+
return (
|
85
|
+
<div className="squiz-rb-scope">
|
86
|
+
<PluginRender
|
87
|
+
key="default"
|
88
|
+
render={plugin === null}
|
89
|
+
{...props}
|
90
|
+
source={source}
|
91
|
+
sources={sources}
|
92
|
+
setSource={handleSourceSelect}
|
93
|
+
isLoading={isLoading}
|
94
|
+
error={sourcesError || error}
|
95
|
+
plugin={plugin}
|
96
|
+
useResource={() => {
|
97
|
+
return {
|
98
|
+
data: null,
|
99
|
+
error: null,
|
100
|
+
isLoading: false,
|
101
|
+
};
|
102
|
+
}}
|
103
|
+
isModalOpen={isModalOpen}
|
104
|
+
onModalStateChange={handleModalStateChange}
|
105
|
+
/>
|
106
|
+
{plugins.map((thisPlugin) => {
|
107
|
+
return (
|
108
|
+
<PluginRender
|
109
|
+
key={thisPlugin.type}
|
110
|
+
render={thisPlugin === plugin}
|
111
|
+
{...props}
|
112
|
+
source={source}
|
113
|
+
sources={sources}
|
114
|
+
setSource={handleSourceSelect}
|
115
|
+
isLoading={isLoading}
|
116
|
+
error={error}
|
117
|
+
plugin={plugin}
|
118
|
+
useResource={thisPlugin.useResolveResource}
|
119
|
+
isModalOpen={isModalOpen}
|
120
|
+
onModalStateChange={handleModalStateChange}
|
121
|
+
/>
|
122
|
+
);
|
123
|
+
})}
|
124
|
+
</div>
|
125
|
+
);
|
64
126
|
};
|
package/src/types.ts
CHANGED
@@ -1,81 +1,72 @@
|
|
1
|
+
import React, { ReactElement } from 'react';
|
1
2
|
import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
2
3
|
|
3
|
-
export type
|
4
|
-
|
5
|
-
|
4
|
+
export type OnRequestSources = () => Promise<ResourceBrowserSource[]>;
|
5
|
+
export type ResourceBrowserPluginType = 'dam' | 'matrix';
|
6
|
+
|
7
|
+
export type ResourceBrowserSource = {
|
8
|
+
// Source name; shown on the UI
|
9
|
+
name?: string;
|
10
|
+
// Source identifier for additional information lookups
|
11
|
+
id: string;
|
12
|
+
// Source type e.g. Matrix, DAM etc determines what plugin will be used for resource selection
|
13
|
+
type: ResourceBrowserPluginType;
|
6
14
|
};
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
|
16
|
+
export type ResourceBrowserUnresolvedResource = {
|
17
|
+
sourceId: string;
|
18
|
+
resourceId: string;
|
19
|
+
};
|
20
|
+
|
21
|
+
export type ResourceBrowserResource = {
|
22
|
+
id: string;
|
15
23
|
name: string;
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
url: string;
|
25
|
+
source: ResourceBrowserSource;
|
26
|
+
type: {
|
27
|
+
code: string;
|
28
|
+
name: string;
|
29
|
+
};
|
30
|
+
squizImage?: SquizImageType['__shape__'];
|
23
31
|
};
|
24
32
|
|
25
|
-
export type
|
26
|
-
|
33
|
+
export type ResourceBrowserSelectedState = {
|
34
|
+
showThumbnail?: boolean;
|
35
|
+
icon?: ReactElement;
|
36
|
+
label: string;
|
37
|
+
description: Array<ReactElement>;
|
27
38
|
};
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
name: string;
|
36
|
-
nodes: Resource[];
|
40
|
+
export type ResourceBrowserUIProps = {
|
41
|
+
source: ResourceBrowserSource;
|
42
|
+
allowedTypes?: string[];
|
43
|
+
headerPortal?: Element;
|
44
|
+
preselectedResource?: ResourceBrowserResource;
|
45
|
+
onSelected: (resource: ResourceBrowserResource) => void;
|
37
46
|
};
|
38
47
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
source: Source;
|
44
|
-
resource: Resource | null;
|
48
|
+
export type useResolveResourceResponse = {
|
49
|
+
data: ResourceBrowserResource | null;
|
50
|
+
error: Error | null;
|
51
|
+
isLoading: boolean;
|
45
52
|
};
|
46
53
|
|
47
54
|
/**
|
48
|
-
*
|
55
|
+
* If you change this interface please update the example here: src/__mocks__/PluginExample.tsx
|
49
56
|
*/
|
50
|
-
export
|
57
|
+
export interface ResourceBrowserPlugin {
|
58
|
+
/** Datasource type this plugin should be used for */
|
59
|
+
type: ResourceBrowserPluginType;
|
51
60
|
|
52
|
-
|
53
|
-
|
54
|
-
*/
|
55
|
-
export type HydratedResourceReference = { source: Source; resource: Resource };
|
61
|
+
// Setting to create a header portal
|
62
|
+
createHeaderPortal?: boolean;
|
56
63
|
|
57
|
-
/**
|
58
|
-
|
59
|
-
* Within the picker T will be ScopedSource|Resource.
|
60
|
-
* ScopedSource will be the first item in the array, Resource will be every other item.
|
61
|
-
*/
|
62
|
-
export type Hierarchy<T> = Array<{
|
63
|
-
key: string;
|
64
|
-
label: string;
|
65
|
-
node: T;
|
66
|
-
}>;
|
64
|
+
/** React Functional Component to provde the UI to render to allow a user to select a resource to use */
|
65
|
+
sourceBrowserComponent: () => React.FunctionComponent<ResourceBrowserUIProps>;
|
67
66
|
|
68
|
-
/**
|
69
|
-
|
70
|
-
*/
|
71
|
-
export type DeepPartial<T> = {
|
72
|
-
[P in keyof T]?: T[P] extends Array<infer U>
|
73
|
-
? Array<DeepPartial<U>>
|
74
|
-
: T[P] extends ReadonlyArray<infer U>
|
75
|
-
? ReadonlyArray<DeepPartial<U>>
|
76
|
-
: DeepPartial<T[P]>;
|
77
|
-
};
|
67
|
+
/** Function to provde the the summary information to show what resource is currently selected */
|
68
|
+
renderSelectedResource: (resource: ResourceBrowserResource) => Promise<ResourceBrowserSelectedState>;
|
78
69
|
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
/** Function to resolve a resource and source id into a fully resolved output reference */
|
71
|
+
useResolveResource: (resourceId: string | null, source: ResourceBrowserSource | null) => useResolveResourceResponse;
|
72
|
+
}
|
package/tailwind.config.cjs
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
/** @type {import('tailwindcss').Config} */
|
2
2
|
module.exports = {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
3
|
+
content: {
|
4
|
+
relative: true,
|
5
|
+
files: [
|
6
|
+
'../../node_modules/@squiz/generic-browser-lib/src/**/*.{js,ts,jsx,tsx,scss}',
|
7
|
+
'./index.html',
|
8
|
+
'./src/**/*.{js,ts,jsx,tsx}',
|
9
|
+
'./node_modules/flowbite/**/*.js',
|
10
|
+
],
|
11
|
+
},
|
12
|
+
theme: {
|
13
|
+
extend: {
|
14
|
+
borderWidth: {
|
15
|
+
// We shouldn't use ".border" class and instead use ".border-1".
|
16
|
+
// ".border" has !important styling defined in Matrix so overrides anything various border styling if used.
|
17
|
+
1: '1px',
|
18
|
+
},
|
19
|
+
borderRadius: {
|
20
|
+
DEFAULT: '4px',
|
21
|
+
md: '6px',
|
22
|
+
},
|
23
|
+
fontFamily: {
|
24
|
+
base: 'Open Sans, Arial, sans-serif',
|
25
|
+
},
|
26
|
+
fontWeight: {
|
27
|
+
normal: '400',
|
28
|
+
medium: '500',
|
29
|
+
semibold: '600',
|
30
|
+
bold: '700',
|
31
|
+
},
|
32
|
+
fontSize: {
|
33
|
+
xlg: '1.125rem',
|
34
|
+
lg: '1rem',
|
35
|
+
md: '0.875rem',
|
36
|
+
sm: '0.8125rem',
|
37
|
+
base: '1rem',
|
38
|
+
'heading-1': ['1.625rem', '2rem'],
|
39
|
+
'heading-2': ['1.25rem', '1.5rem'],
|
40
|
+
'heading-3': ['1.125rem', '1.375rem'],
|
41
|
+
'heading-4': ['1rem', '1.25rem'],
|
42
|
+
},
|
43
|
+
fontFamily: {
|
44
|
+
base: 'Open Sans, Arial, sans-serif',
|
45
|
+
},
|
46
|
+
boxShadow: {
|
47
|
+
outline: '0 0 0 1px rgba(0,0,0,0.10)',
|
48
|
+
sm: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 4px 2px rgba(0,0,0,0.08)',
|
49
|
+
DEFAULT: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
|
50
|
+
md: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
|
51
|
+
lg: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 24px 12px rgba(0,0,0,0.12)',
|
52
|
+
inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
|
53
|
+
none: 'none',
|
54
|
+
},
|
55
|
+
width: {
|
56
|
+
'modal-sm': '25rem',
|
57
|
+
'modal-md': '37.5rem',
|
58
|
+
'modal-lg': '50rem',
|
59
|
+
'modal-xl': '62.5rem',
|
60
|
+
},
|
61
|
+
spacing: {
|
62
|
+
1: '0.25rem', // 4px
|
63
|
+
2: '0.5rem', // 8px
|
64
|
+
3: '0.75rem', // 12px
|
65
|
+
4: '1rem', // 16px
|
66
|
+
5: '1.25rem', // 20px
|
67
|
+
6: '1.5rem', // 24px
|
68
|
+
7: '1.75rem', // 28px
|
69
|
+
8: '2rem', // 32px
|
70
|
+
169: '169px', // 169px
|
71
|
+
},
|
72
|
+
colors: {
|
73
|
+
gray: {
|
74
|
+
50: '#F7F7F7',
|
75
|
+
100: '#F5F5F5',
|
76
|
+
200: '#ededed',
|
77
|
+
300: '#e0e0e0',
|
78
|
+
400: '#BABABA',
|
79
|
+
500: '#949494',
|
80
|
+
600: '#707070',
|
81
|
+
700: '#4F4F4F',
|
82
|
+
800: '#3D3D3D',
|
83
|
+
900: '#2B2B2B',
|
84
|
+
},
|
85
|
+
blue: {
|
86
|
+
100: '#e6f1fa',
|
87
|
+
200: '#8FC0EB',
|
88
|
+
300: '#0774d2',
|
89
|
+
400: '#044985',
|
90
|
+
},
|
91
|
+
red: {
|
92
|
+
300: '#d72321',
|
93
|
+
},
|
94
|
+
},
|
93
95
|
},
|
94
|
-
},
|
95
96
|
},
|
96
|
-
},
|
97
97
|
};
|
package/vite.config.js
CHANGED
@@ -5,16 +5,16 @@ import react from '@vitejs/plugin-react';
|
|
5
5
|
// Dependencies from within the monorepo need to be configured in a special way, relates to:
|
6
6
|
// https://github.com/vitejs/vite/issues/5668
|
7
7
|
export default defineConfig({
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
20
|
});
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { ScopedSource, Source } from '../types';
|
2
|
-
export type CategorisedSource = {
|
3
|
-
key: string;
|
4
|
-
label: string;
|
5
|
-
sources: ScopedSource[];
|
6
|
-
};
|
7
|
-
/**
|
8
|
-
* Groups a list of source into scoped/un-scoped for rendering in the source list.
|
9
|
-
*
|
10
|
-
* @param {Source[]} sources
|
11
|
-
*
|
12
|
-
* @return {SourceList}
|
13
|
-
*/
|
14
|
-
export declare const useCategorisedSources: (sources: Source[]) => CategorisedSource[];
|
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.useCategorisedSources = void 0;
|
4
|
-
const react_1 = require("react");
|
5
|
-
/**
|
6
|
-
* Groups a list of source into scoped/un-scoped for rendering in the source list.
|
7
|
-
*
|
8
|
-
* @param {Source[]} sources
|
9
|
-
*
|
10
|
-
* @return {SourceList}
|
11
|
-
*/
|
12
|
-
const useCategorisedSources = (sources) => {
|
13
|
-
return (0, react_1.useMemo)(() => {
|
14
|
-
const categorised = [];
|
15
|
-
const uncategorised = [];
|
16
|
-
sources.forEach((source) => {
|
17
|
-
if (source.nodes.length > 0) {
|
18
|
-
const category = { key: source.id, label: source.name, sources: [] };
|
19
|
-
source.nodes.forEach((resource) => {
|
20
|
-
category.sources.push({ source, resource });
|
21
|
-
});
|
22
|
-
categorised.push(category);
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
uncategorised.push({ source, resource: null });
|
26
|
-
}
|
27
|
-
});
|
28
|
-
if (uncategorised.length > 0) {
|
29
|
-
categorised.push({
|
30
|
-
key: 'other',
|
31
|
-
label: 'Other systems',
|
32
|
-
sources: uncategorised,
|
33
|
-
});
|
34
|
-
}
|
35
|
-
return categorised;
|
36
|
-
}, [sources]);
|
37
|
-
};
|
38
|
-
exports.useCategorisedSources = useCategorisedSources;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { Resource, ScopedSource, Source } from '../types';
|
2
|
-
type UseChildResourcesProps = {
|
3
|
-
source: ScopedSource | null;
|
4
|
-
currentResource: Resource | null;
|
5
|
-
onRequestChildren: (source: Source, resource: Resource | null) => Promise<Resource[]>;
|
6
|
-
};
|
7
|
-
/**
|
8
|
-
* Triggers a reload of the child resources when the source or current resource change.
|
9
|
-
*/
|
10
|
-
export declare const useChildResources: ({ source, currentResource, onRequestChildren }: UseChildResourcesProps) => {
|
11
|
-
data: Resource[] | never[];
|
12
|
-
error: Error | null;
|
13
|
-
isLoading: boolean;
|
14
|
-
reload: () => void;
|
15
|
-
};
|
16
|
-
export {};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.useChildResources = void 0;
|
4
|
-
const generic_browser_lib_1 = require("@squiz/generic-browser-lib");
|
5
|
-
/**
|
6
|
-
* Triggers a reload of the child resources when the source or current resource change.
|
7
|
-
*/
|
8
|
-
const useChildResources = ({ source, currentResource, onRequestChildren }) => (0, generic_browser_lib_1.useAsync)({
|
9
|
-
callback: () => (source ? onRequestChildren(source.source, currentResource || source.resource) : []),
|
10
|
-
defaultValue: [],
|
11
|
-
ignorePrevious: true,
|
12
|
-
}, [source, currentResource]);
|
13
|
-
exports.useChildResources = useChildResources;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { Source, Resource, OnRequestResource, OnRequestSources } from '../types';
|
2
|
-
export type PreselectedResourceProps = {
|
3
|
-
sourceId?: string;
|
4
|
-
resource?: Resource | null;
|
5
|
-
onRequestResource: OnRequestResource;
|
6
|
-
onRequestSources: OnRequestSources;
|
7
|
-
};
|
8
|
-
export type PreselectedResourcePath = {
|
9
|
-
source?: Source;
|
10
|
-
path?: Resource[];
|
11
|
-
};
|
12
|
-
export declare const usePreselectedResourcePath: ({ sourceId, resource, onRequestResource, onRequestSources, }: PreselectedResourceProps) => {
|
13
|
-
data: PreselectedResourcePath | {
|
14
|
-
source: Source | undefined;
|
15
|
-
path: Resource[] | undefined;
|
16
|
-
};
|
17
|
-
error: Error | null;
|
18
|
-
isLoading: boolean;
|
19
|
-
reload: () => void;
|
20
|
-
};
|