@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.
Files changed (141) hide show
  1. package/CHANGELOG.md +88 -35
  2. package/LICENSE.md +15 -0
  3. package/README.md +9 -0
  4. package/jest.config.ts +22 -21
  5. package/lib/Hooks/useSelectedState.d.ts +15 -0
  6. package/lib/Hooks/useSelectedState.js +16 -0
  7. package/lib/Hooks/useSources.d.ts +5 -4
  8. package/lib/Hooks/useSources.js +25 -1
  9. package/lib/MainContainer/MainContainer.d.ts +17 -0
  10. package/lib/MainContainer/MainContainer.js +61 -0
  11. package/lib/Plugin/Plugin.d.ts +13 -0
  12. package/lib/Plugin/Plugin.js +17 -0
  13. package/lib/ResourceBrowserContext/ResourceBrowserContext.d.ts +2 -3
  14. package/lib/ResourceBrowserContext/ResourceBrowserContext.js +4 -17
  15. package/lib/ResourceBrowserInput/ResourceBrowserInput.d.ts +24 -0
  16. package/lib/ResourceBrowserInput/ResourceBrowserInput.js +16 -0
  17. package/lib/ResourcePicker/ResourcePicker.d.ts +6 -4
  18. package/lib/ResourcePicker/ResourcePicker.js +14 -8
  19. package/lib/ResourcePicker/States/Selected.d.ts +10 -4
  20. package/lib/ResourcePicker/States/Selected.js +11 -32
  21. package/lib/SourceDropdown/SourceDropdown.d.ts +5 -11
  22. package/lib/SourceDropdown/SourceDropdown.js +20 -99
  23. package/lib/SourceList/SourceList.d.ts +5 -16
  24. package/lib/SourceList/SourceList.js +14 -75
  25. package/lib/index.css +42 -202
  26. package/lib/index.d.ts +7 -7
  27. package/lib/index.js +69 -13
  28. package/lib/types.d.ts +41 -59
  29. package/package.json +82 -80
  30. package/src/Hooks/useSelectedState.spec.ts +46 -0
  31. package/src/Hooks/useSelectedState.ts +22 -0
  32. package/src/Hooks/useSources.spec.ts +30 -12
  33. package/src/Hooks/useSources.ts +33 -4
  34. package/src/Icons/CircledLoopIcon.tsx +8 -8
  35. package/src/MainContainer/MainContainer.spec.tsx +203 -0
  36. package/src/MainContainer/MainContainer.stories.tsx +62 -0
  37. package/src/MainContainer/MainContainer.tsx +101 -0
  38. package/src/Plugin/Plugin.spec.tsx +46 -0
  39. package/src/Plugin/Plugin.tsx +20 -0
  40. package/src/ResourceBrowserContext/ResourceBrowserContext.spec.tsx +65 -106
  41. package/src/ResourceBrowserContext/ResourceBrowserContext.tsx +24 -39
  42. package/src/ResourceBrowserInput/ResourceBrowserInput.spec.tsx +192 -0
  43. package/src/ResourceBrowserInput/ResourceBrowserInput.tsx +81 -0
  44. package/src/ResourcePicker/ResourcePicker.spec.tsx +159 -116
  45. package/src/ResourcePicker/ResourcePicker.stories.tsx +28 -24
  46. package/src/ResourcePicker/ResourcePicker.tsx +79 -59
  47. package/src/ResourcePicker/States/Error.tsx +8 -8
  48. package/src/ResourcePicker/States/Loading.tsx +3 -3
  49. package/src/ResourcePicker/States/Selected.tsx +66 -73
  50. package/src/ResourcePicker/mock-image-resource.json +25 -47
  51. package/src/ResourcePicker/mock-resource.json +11 -13
  52. package/src/ResourcePicker/resource-picker.scss +13 -13
  53. package/src/SourceDropdown/SourceDropdown.spec.tsx +65 -391
  54. package/src/SourceDropdown/SourceDropdown.stories.tsx +21 -24
  55. package/src/SourceDropdown/SourceDropdown.tsx +80 -258
  56. package/src/SourceList/SourceList.spec.tsx +37 -430
  57. package/src/SourceList/SourceList.stories.tsx +17 -37
  58. package/src/SourceList/SourceList.tsx +28 -155
  59. package/src/__mocks__/MockModels.ts +56 -25
  60. package/src/__mocks__/PluginExample.tsx +98 -0
  61. package/src/__mocks__/StorybookHelpers.tsx +141 -0
  62. package/src/__mocks__/renderWithContext.tsx +14 -18
  63. package/src/__mocks__/sample-sources.json +32 -0
  64. package/src/index.scss +18 -8
  65. package/src/index.spec.tsx +277 -99
  66. package/src/index.stories.tsx +65 -39
  67. package/src/index.tsx +119 -57
  68. package/src/types.ts +54 -63
  69. package/tailwind.config.cjs +92 -92
  70. package/vite.config.js +12 -12
  71. package/lib/Hooks/useCategorisedSources.d.ts +0 -14
  72. package/lib/Hooks/useCategorisedSources.js +0 -38
  73. package/lib/Hooks/useChildResources.d.ts +0 -16
  74. package/lib/Hooks/useChildResources.js +0 -13
  75. package/lib/Hooks/usePreselectedResourcePath.d.ts +0 -20
  76. package/lib/Hooks/usePreselectedResourcePath.js +0 -31
  77. package/lib/Hooks/useRecentLocations.d.ts +0 -5
  78. package/lib/Hooks/useRecentLocations.js +0 -38
  79. package/lib/Hooks/useRecentResourcesPaths.d.ts +0 -20
  80. package/lib/Hooks/useRecentResourcesPaths.js +0 -30
  81. package/lib/Hooks/useResource.d.ts +0 -28
  82. package/lib/Hooks/useResource.js +0 -23
  83. package/lib/Hooks/useResourcePath.d.ts +0 -16
  84. package/lib/Hooks/useResourcePath.js +0 -64
  85. package/lib/Icons/HistoryIcon.d.ts +0 -4
  86. package/lib/Icons/HistoryIcon.js +0 -13
  87. package/lib/PreviewPanel/PreviewPanel.d.ts +0 -5
  88. package/lib/PreviewPanel/PreviewPanel.js +0 -8
  89. package/lib/PreviewPanel/details/MatrixResource.d.ts +0 -7
  90. package/lib/PreviewPanel/details/MatrixResource.js +0 -35
  91. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +0 -9
  92. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +0 -54
  93. package/lib/ResourceList/ResourceList.d.ts +0 -18
  94. package/lib/ResourceList/ResourceList.js +0 -49
  95. package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +0 -17
  96. package/lib/ResourcePickerContainer/ResourcePickerContainer.js +0 -166
  97. package/lib/StatusIndicator/StatusIndicator.d.ts +0 -8
  98. package/lib/StatusIndicator/StatusIndicator.js +0 -27
  99. package/lib/utils/findBestMatchLineage.d.ts +0 -2
  100. package/lib/utils/findBestMatchLineage.js +0 -28
  101. package/lib/utils/uuid.d.ts +0 -1
  102. package/lib/utils/uuid.js +0 -6
  103. package/src/Hooks/useCategorisedSources.spec.ts +0 -39
  104. package/src/Hooks/useCategorisedSources.ts +0 -46
  105. package/src/Hooks/useChildResources.spec.ts +0 -29
  106. package/src/Hooks/useChildResources.ts +0 -21
  107. package/src/Hooks/usePreselectedResourcePath.ts +0 -54
  108. package/src/Hooks/useRecentLocations.spec.ts +0 -81
  109. package/src/Hooks/useRecentLocations.ts +0 -44
  110. package/src/Hooks/useRecentResourcesPaths.ts +0 -54
  111. package/src/Hooks/useResource.spec.ts +0 -61
  112. package/src/Hooks/useResource.ts +0 -38
  113. package/src/Hooks/useResourcePath.spec.ts +0 -120
  114. package/src/Hooks/useResourcePath.ts +0 -76
  115. package/src/Icons/HistoryIcon.tsx +0 -17
  116. package/src/PreviewPanel/PreviewPanel.spec.tsx +0 -198
  117. package/src/PreviewPanel/PreviewPanel.stories.tsx +0 -76
  118. package/src/PreviewPanel/PreviewPanel.tsx +0 -6
  119. package/src/PreviewPanel/details/MatrixResource.tsx +0 -54
  120. package/src/PreviewPanel/details/matrix-resource.scss +0 -16
  121. package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +0 -133
  122. package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +0 -24
  123. package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +0 -79
  124. package/src/ResourceBreadcrumb/resource-breadcrumb.scss +0 -28
  125. package/src/ResourceBreadcrumb/sample-hierarchy.json +0 -27
  126. package/src/ResourceList/ResourceList.spec.tsx +0 -202
  127. package/src/ResourceList/ResourceList.stories.tsx +0 -40
  128. package/src/ResourceList/ResourceList.tsx +0 -83
  129. package/src/ResourceList/sample-resources.json +0 -851
  130. package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +0 -780
  131. package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +0 -45
  132. package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +0 -290
  133. package/src/SourceList/sample-sources.json +0 -251
  134. package/src/StatusIndicator/StatusIndicator.stories.tsx +0 -83
  135. package/src/StatusIndicator/StatusIndicator.tsx +0 -38
  136. package/src/__mocks__/JestHelpers.ts +0 -65
  137. package/src/__mocks__/StorybookHelpers.ts +0 -128
  138. package/src/__mocks__/jestHelpers.spec.ts +0 -38
  139. package/src/utils/findBestMatchLineage.spec.ts +0 -81
  140. package/src/utils/findBestMatchLineage.ts +0 -30
  141. package/src/utils/uuid.ts +0 -5
package/src/index.tsx CHANGED
@@ -1,64 +1,126 @@
1
- import React, { useContext } from 'react';
2
- import ResourcePickerContainer from './ResourcePickerContainer/ResourcePickerContainer';
3
- import { HydratedResourceReference, Resource, ResourceReference, Source } from './types';
4
- import {
5
- ResourceBrowserContext,
6
- ResourceBrowserContextProvider,
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 ResourceBrowserInputProps = {
16
- modalTitle: string;
17
- allowedTypes?: string[];
18
- isDisabled?: boolean;
19
- value: ResourceReference | null;
20
- onChange(resource: HydratedResourceReference | null): void;
21
- onClear?(): void;
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 ResourceBrowserInput = ({
25
- modalTitle,
26
- allowedTypes,
27
- onChange,
28
- value,
29
- isDisabled,
30
- onClear,
31
- }: ResourceBrowserInputProps) => {
32
- const { onRequestSources, onRequestChildren, onRequestResource } = useContext(ResourceBrowserContext);
33
- const { data: resource, error, isLoading } = useResource({ onRequestResource, reference: value });
34
- const defaultOnClear = () => onChange(null);
35
- const onClearFunction = onClear ?? defaultOnClear;
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
- return (
38
- <div className="squiz-rb-scope">
39
- <ResourcePicker
40
- resource={resource}
41
- allowedTypes={allowedTypes}
42
- error={error}
43
- isLoading={isLoading}
44
- isDisabled={isDisabled}
45
- onClear={() => onClearFunction()}
46
- >
47
- {(onClose, titleProps) => (
48
- <ResourcePickerContainer
49
- preselectedSourceId={value?.source}
50
- preselectedResource={resource}
51
- title={modalTitle}
52
- titleAriaProps={titleProps}
53
- allowedTypes={allowedTypes}
54
- onClose={onClose}
55
- onRequestSources={onRequestSources}
56
- onRequestResource={onRequestResource}
57
- onRequestChildren={onRequestChildren}
58
- onChange={onChange}
59
- />
60
- )}
61
- </ResourcePicker>
62
- </div>
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 Status = {
4
- code: string;
5
- name: string;
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
- * Represents a resource that has been picked from a source.
9
- */
10
- export type Resource = {
11
- id: string;
12
- name: string;
13
- type: {
14
- code: string;
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
- status: Status;
18
- url: string;
19
- urls: string[];
20
- childCount: number;
21
- squizImage?: SquizImageType['__shape__'];
22
- lineages?: ResourceLineage[];
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 ResourceLineage = {
26
- resourceIds: string[];
33
+ export type ResourceBrowserSelectedState = {
34
+ showThumbnail?: boolean;
35
+ icon?: ReactElement;
36
+ label: string;
37
+ description: Array<ReactElement>;
27
38
  };
28
39
 
29
- /**
30
- * Represents a system that resources can be picked from.
31
- * Optionally, may indicate a list of "nodes" that can be used to scope the source to a subset of its resources.
32
- */
33
- export type Source = {
34
- id: string;
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
- * Represents a source that has been optionally scoped to one of its "nodes".
41
- */
42
- export type ScopedSource = {
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
- * A non-hydrated resource reference.
55
+ * If you change this interface please update the example here: src/__mocks__/PluginExample.tsx
49
56
  */
50
- export type ResourceReference = { source: string; resource: string };
57
+ export interface ResourceBrowserPlugin {
58
+ /** Datasource type this plugin should be used for */
59
+ type: ResourceBrowserPluginType;
51
60
 
52
- /**
53
- * A hydrated resource reference.
54
- */
55
- export type HydratedResourceReference = { source: Source; resource: Resource };
61
+ // Setting to create a header portal
62
+ createHeaderPortal?: boolean;
56
63
 
57
- /**
58
- * Represents the hierarchy within the asset picker.
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
- * Augments a type so that all properties are optional.
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
- export type OnRequestSources = () => Promise<Source[]>;
80
- export type OnRequestResource = (reference: ResourceReference) => Promise<Resource>;
81
- export type OnRequestChildren = (source: Source, resource: Resource | null) => Promise<Resource[]>;
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
+ }
@@ -1,97 +1,97 @@
1
1
  /** @type {import('tailwindcss').Config} */
2
2
  module.exports = {
3
- content: {
4
- relative: true,
5
- files: [
6
- '../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',
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
- optimizeDeps: {
9
- include: ['@squiz/generic-browser-lib'],
10
- },
11
- plugins: [
12
- react({
13
- babel: {
14
- parserOpts: {
15
- plugins: ['decorators-legacy'],
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
- };