@squiz/resource-browser 1.69.2 → 2.1.9-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 +89 -38
  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 +6 -6
  8. package/lib/Hooks/useSources.js +26 -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 +60 -13
  33. package/src/Hooks/useSources.ts +35 -5
  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 -25
  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 -40
  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/CHANGELOG.md CHANGED
@@ -1,107 +1,158 @@
1
- # @squiz/resource-browser
1
+ # Change Log
2
2
 
3
- ## 1.69.2
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
5
 
5
- ### Patch Changes
6
+ ## [2.1.9-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser@2.1.8-rc.0...@squiz/resource-browser@2.1.9-rc.0) (2024-06-03)
6
7
 
7
- - d167ab9: Fixed bug with resource browser inputs
8
+ **Note:** Version bump only for package @squiz/resource-browser
8
9
 
9
- ## 1.69.1
10
+ ## 2.1.8-rc.0 (2024-05-30)
10
11
 
11
- ### Patch Changes
12
+ **Note:** Version bump only for package @squiz/resource-browser
12
13
 
13
- - 5cd6ef6: Updated logic & handling of recent locations in resource browser
14
+ ## [2.1.7-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.6-rc.0...@squiz/resource-browser-v2@2.1.7-rc.0) (2024-05-27)
14
15
 
15
- ## 1.69.0
16
+ **Note:** Version bump only for package @squiz/resource-browser-v2
16
17
 
17
- ### Minor Changes
18
+ ## [2.1.6-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.5-rc.0...@squiz/resource-browser-v2@2.1.6-rc.0) (2024-05-27)
18
19
 
19
- - b642152: updates to source list node selection
20
+ **Note:** Version bump only for package @squiz/resource-browser-v2
20
21
 
21
- ## 1.68.1
22
+ ## [2.1.5-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.4-rc.0...@squiz/resource-browser-v2@2.1.5-rc.0) (2024-05-23)
22
23
 
23
- ### Patch Changes
24
+ **Note:** Version bump only for package @squiz/resource-browser-v2
24
25
 
25
- - 7c324d7: Fixed useChildResources to ignore previous data (race condition bug)
26
- - Updated dependencies [7c324d7]
27
- - @squiz/generic-browser-lib@1.67.0
26
+ ## [2.1.4-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.3-rc.0...@squiz/resource-browser-v2@2.1.4-rc.0) (2024-05-20)
28
27
 
29
- ## 1.68.0
28
+ **Note:** Version bump only for package @squiz/resource-browser-v2
30
29
 
31
- ### Minor Changes
30
+ ## [2.1.3-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.2-rc.0...@squiz/resource-browser-v2@2.1.3-rc.0) (2024-05-20)
31
+
32
+ **Note:** Version bump only for package @squiz/resource-browser-v2
33
+
34
+ ## [2.1.2-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.1-rc.0...@squiz/resource-browser-v2@2.1.2-rc.0) (2024-05-15)
35
+
36
+ **Note:** Version bump only for package @squiz/resource-browser-v2
37
+
38
+ ## [2.1.1-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.1.0-rc.0...@squiz/resource-browser-v2@2.1.1-rc.0) (2024-05-13)
39
+
40
+ **Note:** Version bump only for package @squiz/resource-browser-v2
41
+
42
+ # [2.1.0-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.9-rc.0...@squiz/resource-browser-v2@2.1.0-rc.0) (2024-05-13)
43
+
44
+ ### Features
45
+
46
+ - **prodam-133:** add source dropdown to rb wrapper ([a258b0f](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/commit/a258b0febebca94aad1885f602d6a10a323ab95f))
47
+
48
+ ## [2.0.9-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.8-rc.0...@squiz/resource-browser-v2@2.0.9-rc.0) (2024-05-13)
49
+
50
+ **Note:** Version bump only for package @squiz/resource-browser-v2
51
+
52
+ ## [2.0.8-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.7-rc.0...@squiz/resource-browser-v2@2.0.8-rc.0) (2024-05-10)
32
53
 
33
- - 8c2491b: Added recent locations section to resource browser
54
+ **Note:** Version bump only for package @squiz/resource-browser-v2
55
+
56
+ ## [2.0.7-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.6-rc.0...@squiz/resource-browser-v2@2.0.7-rc.0) (2024-05-09)
57
+
58
+ **Note:** Version bump only for package @squiz/resource-browser-v2
59
+
60
+ ## [2.0.6-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.5-rc.0...@squiz/resource-browser-v2@2.0.6-rc.0) (2024-05-07)
61
+
62
+ **Note:** Version bump only for package @squiz/resource-browser-v2
63
+
64
+ ## [2.0.5-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.4-rc.0...@squiz/resource-browser-v2@2.0.5-rc.0) (2024-05-07)
65
+
66
+ **Note:** Version bump only for package @squiz/resource-browser-v2
67
+
68
+ ## [2.0.4-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.3-rc.0...@squiz/resource-browser-v2@2.0.4-rc.0) (2024-05-03)
69
+
70
+ **Note:** Version bump only for package @squiz/resource-browser-v2
71
+
72
+ ## [2.0.3-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.2-rc.0...@squiz/resource-browser-v2@2.0.3-rc.0) (2024-05-02)
73
+
74
+ **Note:** Version bump only for package @squiz/resource-browser-v2
75
+
76
+ ## [2.0.2-rc.0](https://gitlab.squiz.net/dxp/dxp-shared-ui/resource-browser/compare/@squiz/resource-browser-v2@2.0.1-rc.0...@squiz/resource-browser-v2@2.0.2-rc.0) (2024-04-29)
77
+
78
+ **Note:** Version bump only for package @squiz/resource-browser-v2
79
+
80
+ ## 2.0.1-rc.0 (2024-04-26)
81
+
82
+ **Note:** Version bump only for package @squiz/resource-browser-v2
83
+
84
+ # @squiz/resource-browser
34
85
 
35
86
  ## 1.67.1
36
87
 
37
88
  ### Patch Changes
38
89
 
39
- - 9e4cad8: Fixed minor issue with finding best matched lineage in resource browser
90
+ - 9e4cad8: Fixed minor issue with finding best matched lineage in resource browser
40
91
 
41
92
  ## 1.67.0
42
93
 
43
94
  ### Minor Changes
44
95
 
45
- - 5fa9b39: Updated resource browser to allow replacing the previously selected resource. Replacing will open the resource browser to the location where the resource resides.
96
+ - 5fa9b39: Updated resource browser to allow replacing the previously selected resource. Replacing will open the resource browser to the location where the resource resides.
46
97
 
47
98
  ### Patch Changes
48
99
 
49
- - Updated dependencies [5fa9b39]
50
- - Updated dependencies [5fa9b39]
51
- - @squiz/dx-json-schema-lib@1.67.0
52
- - @squiz/generic-browser-lib@1.66.0
100
+ - Updated dependencies [5fa9b39]
101
+ - Updated dependencies [5fa9b39]
102
+ - @squiz/dx-json-schema-lib@1.67.0
103
+ - @squiz/generic-browser-lib@1.66.0
53
104
 
54
105
  ## 1.66.3
55
106
 
56
107
  ### Patch Changes
57
108
 
58
- - 8421756: Selected image assets in the resource browser will now display the actual image instead of just the image asset icon if they have a URL specified
109
+ - 8421756: Selected image assets in the resource browser will now display the actual image instead of just the image asset icon if they have a URL specified
59
110
 
60
111
  ## 1.66.2
61
112
 
62
113
  ### Patch Changes
63
114
 
64
- - 6d41052: Added white background to resource picker input to avoid it inheriting the background colour of its parent element.
115
+ - 6d41052: Added white background to resource picker input to avoid it inheriting the background colour of its parent element.
65
116
 
66
117
  ## 1.66.1
67
118
 
68
119
  ### Patch Changes
69
120
 
70
- - 81c7cba: Image asset previews will now display the image if there is a URL in the returned resource data
71
- Also fixes a bug around the selected resource name not having break-word applied so the filename was not wrapping as expected
121
+ - 81c7cba: Image asset previews will now display the image if there is a URL in the returned resource data
122
+ Also fixes a bug around the selected resource name not having break-word applied so the filename was not wrapping as expected
72
123
 
73
124
  ## 1.66.0
74
125
 
75
126
  ### Minor Changes
76
127
 
77
- - 5032c38: Added content page asset icon.
128
+ - 5032c38: Added content page asset icon.
78
129
 
79
130
  ### Patch Changes
80
131
 
81
- - Updated dependencies [5032c38]
82
- - @squiz/generic-browser-lib@1.65.0
132
+ - Updated dependencies [5032c38]
133
+ - @squiz/generic-browser-lib@1.65.0
83
134
 
84
135
  ## 1.65.0
85
136
 
86
137
  ### Minor Changes
87
138
 
88
- - ac68ec6: Unpinned Squiz dependencies, they should now be following semver.
139
+ - ac68ec6: Unpinned Squiz dependencies, they should now be following semver.
89
140
 
90
141
  ### Patch Changes
91
142
 
92
- - Updated dependencies [ac68ec6]
93
- - @squiz/dx-json-schema-lib@1.65.0
143
+ - Updated dependencies [ac68ec6]
144
+ - @squiz/dx-json-schema-lib@1.65.0
94
145
 
95
146
  ## 1.64.1
96
147
 
97
148
  ### Patch Changes
98
149
 
99
- - Updated dependencies [e717e6e]
100
- - @squiz/generic-browser-lib@1.64.0
101
- - @squiz/dx-json-schema-lib@1.64.0
150
+ - Updated dependencies [e717e6e]
151
+ - @squiz/generic-browser-lib@1.64.0
152
+ - @squiz/dx-json-schema-lib@1.64.0
102
153
 
103
154
  ## 1.64.0
104
155
 
105
156
  ### Minor Changes
106
157
 
107
- - e7d4c0f: Updated disabled styling for component-editing-ui & resource browser
158
+ - e7d4c0f: Updated disabled styling for component-editing-ui & resource browser
package/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ This software is copyright Squiz and may only be used with the explicit
2
+ permission of the copyright holder.
3
+
4
+ 1. Squiz shall make the Services available to You pursuant to your Agreement and these terms.
5
+ 2. Squiz shall provide the Services only in accordance with applicable laws and government regulations and where applicable your Agreement.
6
+ 3. You shall:
7
+ (a) be responsible for Your compliance with these terms and the Agreement;
8
+ (b) prevent unauthorised access to or use of the Services, and notify Squiz promptly of any such unauthorised access or use, and
9
+ (c) use the Services only in accordance with the Documentation and applicable laws and government regulations.
10
+ 4. You shall not:
11
+ (a) sell, resell, rent or lease the Services;
12
+ (b) use the Services to store or transmit Malicious Code;
13
+ (c) interfere with or disrupt the integrity or performance of the Services or third-party data contained therein, or
14
+ (d) attempt to gain unauthorised access to the Services or their related systems or networks.
15
+ 5. You acknowledge that Squiz retains ownership of the Software, the Documentation and the source code and all proprietary rights relating thereto and You agree all Intellectual Property Rights in the Software and Documentation are and shall remain the exclusive property of Squiz and its third party suppliers, as applicable. Unless expressly permitted in this Subscription Agreement, You must not use any of Squiz's or its third party suppliers' intellectual property without Squiz or its third party suppliers' prior written consent. Nothing in these terms should be construed as transferring any aspects of such rights mentioned in this clause to You or any Third Party. Squiz reserves any and all rights not expressly granted herein.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Resource Browser
2
+
3
+ The Resource Browser is a generic frontend intended for use across the Squiz DXP when a end user needs to browse for and select a resource via a React frontend UI. It is intended to allow rendering of various compatible sources and to move from one source to another seamlessly. It is not intended to provide an actual UI for any specific datasource; these must be provided via the plugin framework.
4
+
5
+ ## Plugins
6
+
7
+ The Resource Browser does not know how to interface with any source systems; this support needs to be plugged into it. A plugin interface has been defined to allow any source system to be added into the Resource Browser as needed with as complex a UI as that source needs. These plugin can be defined inline when simple (e.g testing) or published to NPM as a packages and consumed by a specific application.
8
+
9
+ An example plugin with comments as documentation can be found [here](./src/__mocks__/PluginExample.tsx).
package/jest.config.ts CHANGED
@@ -2,28 +2,29 @@ import type { Config } from 'jest';
2
2
 
3
3
  // Sync object
4
4
  const config: Config = {
5
- preset: 'ts-jest',
6
- clearMocks: true,
7
- collectCoverage: true,
8
- collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.stories.{ts,tsx}'],
9
- coverageThreshold: {
10
- global: {
11
- branches: 90,
12
- functions: 90,
13
- lines: 90,
14
- statements: 90,
5
+ preset: 'ts-jest',
6
+ clearMocks: true,
7
+ collectCoverage: true,
8
+ collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.stories.{ts,tsx}'],
9
+ coverageThreshold: {
10
+ global: {
11
+ branches: 90,
12
+ functions: 90,
13
+ lines: 90,
14
+ statements: 90,
15
+ },
15
16
  },
16
- },
17
- errorOnDeprecated: true,
18
- moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
19
- testTimeout: 60_000,
20
- testEnvironment: 'jsdom',
21
- testPathIgnorePatterns: ['/lib/', `/node_modules/`],
22
- maxWorkers: 1,
23
- moduleNameMapper: {
24
- '^.+\\.(css|scss)$': '<rootDir>/src/__mocks__/styleMock.ts',
25
- },
26
- setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
17
+ errorOnDeprecated: true,
18
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
19
+ testTimeout: 60_000,
20
+ testEnvironment: 'jsdom',
21
+ testPathIgnorePatterns: ['/lib/', `/node_modules/`],
22
+ maxWorkers: 1,
23
+ moduleNameMapper: {
24
+ '^.+\\.(css|scss)$': '<rootDir>/src/__mocks__/styleMock.ts',
25
+ '^@squiz/resource-browser-ui-lib$': '<rootDir>/../resource-browser-ui-lib/src/index',
26
+ },
27
+ setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
27
28
  };
28
29
 
29
30
  export default config;
@@ -0,0 +1,15 @@
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 {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSelectedState = void 0;
4
+ const generic_browser_lib_1 = require("@squiz/generic-browser-lib");
5
+ /**
6
+ * Loads the selected state for the provided resource
7
+ */
8
+ const useSelectedState = ({ plugin, resource }) => {
9
+ // Find the resolver for this resource
10
+ const renderSelectedResource = resource && plugin?.renderSelectedResource;
11
+ return (0, generic_browser_lib_1.useAsync)({
12
+ callback: () => (resource && renderSelectedResource ? renderSelectedResource(resource) : null),
13
+ defaultValue: null,
14
+ }, [resource]);
15
+ };
16
+ exports.useSelectedState = useSelectedState;
@@ -1,14 +1,14 @@
1
- import { Source } from '../types';
2
- type UseSourcesProps = {
3
- onRequestSources: () => Promise<Source[]>;
1
+ import { ResourceBrowserSource, ResourceBrowserPlugin } from '../types';
2
+ export type UseSourcesProps = {
3
+ onRequestSources: () => Promise<ResourceBrowserSource[]>;
4
+ plugins: Array<ResourceBrowserPlugin>;
4
5
  };
5
6
  /**
6
7
  * Loads and caches the source list when a component using the hook is mounted.
7
8
  */
8
- export declare const useSources: ({ onRequestSources }: UseSourcesProps) => {
9
- data: Source[];
9
+ export declare const useSources: ({ onRequestSources, plugins }: UseSourcesProps) => {
10
+ data: ResourceBrowserSource[];
10
11
  error: Error | null;
11
12
  isLoading: boolean;
12
13
  reload: () => void;
13
14
  };
14
- export {};
@@ -5,5 +5,30 @@ const generic_browser_lib_1 = require("@squiz/generic-browser-lib");
5
5
  /**
6
6
  * Loads and caches the source list when a component using the hook is mounted.
7
7
  */
8
- const useSources = ({ onRequestSources }) => (0, generic_browser_lib_1.useAsync)({ callback: onRequestSources, defaultValue: [] }, []);
8
+ const useSources = ({ onRequestSources, plugins }) => {
9
+ const pluginsKey = plugins.reduce((acc, plugin) => acc + plugin.type, '');
10
+ return (0, generic_browser_lib_1.useAsync)({
11
+ callback: () => {
12
+ return new Promise((resolve, reject) => {
13
+ // Get all the sources from the outer context
14
+ onRequestSources()
15
+ .then((sources) => {
16
+ // Remove any sources which we don't have a plugin to handle
17
+ resolve(sources.filter((source) => {
18
+ return !!plugins.find((plugin) => {
19
+ if (plugin.type === source.type) {
20
+ return true;
21
+ }
22
+ return false;
23
+ });
24
+ }));
25
+ })
26
+ .catch((e) => {
27
+ reject(e);
28
+ });
29
+ });
30
+ },
31
+ defaultValue: [],
32
+ }, [onRequestSources, pluginsKey]);
33
+ };
9
34
  exports.useSources = useSources;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { DOMAttributes, FocusableElement } from '@react-types/shared';
3
+ import { ResourceBrowserPlugin, ResourceBrowserSource, ResourceBrowserResource } from '../types';
4
+ interface MainContainerProps {
5
+ title: string;
6
+ titleAriaProps: DOMAttributes<FocusableElement>;
7
+ allowedTypes: string[] | undefined;
8
+ sources: ResourceBrowserSource[];
9
+ selectedSource: ResourceBrowserSource | null;
10
+ onSourceSelect(source: ResourceBrowserSource | null): void;
11
+ onChange(resource: ResourceBrowserResource | null): void;
12
+ onClose: () => void;
13
+ preselectedResource?: ResourceBrowserResource | null;
14
+ plugin: ResourceBrowserPlugin | null;
15
+ }
16
+ declare function MainContainer({ title, titleAriaProps, allowedTypes, sources, selectedSource, onSourceSelect, onChange, onClose, preselectedResource, plugin, }: MainContainerProps): React.JSX.Element;
17
+ export default MainContainer;
@@ -0,0 +1,61 @@
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
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const SourceDropdown_1 = __importDefault(require("../SourceDropdown/SourceDropdown"));
31
+ const SourceList_1 = __importDefault(require("../SourceList/SourceList"));
32
+ function MainContainer({ title, titleAriaProps, allowedTypes, sources, selectedSource, onSourceSelect, onChange, onClose, preselectedResource, plugin, }) {
33
+ const [headerPortal, setHeaderPortal] = (0, react_1.useState)(null);
34
+ const SourceBrowser = plugin?.sourceBrowserComponent();
35
+ // 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
36
+ const setHeaderPortalRef = (0, react_1.useCallback)((node) => {
37
+ if (node !== null) {
38
+ setHeaderPortal(node);
39
+ }
40
+ }, [setHeaderPortal]);
41
+ // MainContainer will either render the source list view if no source is set or the plugins UI if a source has been selected
42
+ return (react_1.default.createElement("div", { className: "relative flex flex-col h-full text-gray-800" },
43
+ react_1.default.createElement("div", { className: "flex items-center p-4.5" },
44
+ react_1.default.createElement("h2", { ...titleAriaProps, className: "text-xl leading-6 text-gray-800 font-semibold mr-6" },
45
+ !plugin && 'Environment Selector',
46
+ plugin && title),
47
+ plugin && selectedSource && (react_1.default.createElement(react_1.default.Fragment, null,
48
+ sources.length > 1 && (react_1.default.createElement("div", { className: "px-3 border-l border-gray-300 w-300px" },
49
+ react_1.default.createElement(SourceDropdown_1.default, { sources: sources, selectedSource: selectedSource, onSourceSelect: onSourceSelect }))),
50
+ plugin.createHeaderPortal && (react_1.default.createElement("div", { ref: setHeaderPortalRef, className: "px-3 border-l border-gray-300 w-300px" })))),
51
+ react_1.default.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" },
52
+ react_1.default.createElement("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
53
+ react_1.default.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" })))),
54
+ react_1.default.createElement("div", { className: "border-t border-gray-300 h-[calc(100%-72px)]" },
55
+ plugin && selectedSource && SourceBrowser && (react_1.default.createElement(SourceBrowser, { source: selectedSource, allowedTypes: allowedTypes, headerPortal: plugin.createHeaderPortal && headerPortal ? headerPortal : undefined, preselectedResource: preselectedResource || undefined, onSelected: (resource) => {
56
+ onChange(resource);
57
+ onClose();
58
+ } })),
59
+ !selectedSource && react_1.default.createElement(SourceList_1.default, { sources: sources, onSourceSelect: onSourceSelect }))));
60
+ }
61
+ exports.default = MainContainer;
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PluginRender = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const ResourceBrowserInput_1 = require("../ResourceBrowserInput/ResourceBrowserInput");
9
+ const PluginRender = ({ render, ...props }) => {
10
+ if (render) {
11
+ return react_1.default.createElement(ResourceBrowserInput_1.ResourceBrowserInput, { ...props });
12
+ }
13
+ else {
14
+ return react_1.default.createElement(react_1.default.Fragment, null);
15
+ }
16
+ };
17
+ exports.PluginRender = PluginRender;
@@ -1,9 +1,8 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- import { OnRequestResource, OnRequestSources, OnRequestChildren } from '../types';
2
+ import { OnRequestSources, ResourceBrowserPlugin } from '../types';
3
3
  export type ResourceBrowserContextProps = {
4
4
  onRequestSources: OnRequestSources;
5
- onRequestChildren: OnRequestChildren;
6
- onRequestResource: OnRequestResource;
5
+ plugins: Array<ResourceBrowserPlugin>;
7
6
  };
8
7
  /**
9
8
  * @internal Direct usage of this object is discouraged. It will be privated in a future major version.
@@ -38,31 +38,18 @@ exports.ResourceBrowserContext = react_1.default.createContext({
38
38
  onRequestSources: () => {
39
39
  throw new Error('onRequestSources has not been configured.');
40
40
  },
41
- onRequestChildren: () => {
42
- throw new Error('onRequestChildren has not been configured.');
43
- },
44
- onRequestResource: () => {
45
- throw new Error('onRequestResource has not been configured.');
46
- },
41
+ plugins: [],
47
42
  });
48
43
  const ResourceBrowserContextProvider = (props) => {
49
44
  const CACHE_DURATION = 30000; // 30 seconds
50
- const { value: { onRequestSources, onRequestChildren, onRequestResource, ...other }, children, } = props;
45
+ const { value: { onRequestSources, ...other }, children, } = props;
51
46
  const cache = new expiry_map_1.default(CACHE_DURATION);
52
47
  const memoized = (0, react_1.useMemo)(() => ({
53
48
  onRequestSources: (0, p_memoize_1.default)(onRequestSources, {
54
49
  cache,
55
50
  cacheKey: () => 'onRequestSources',
56
51
  }),
57
- onRequestChildren: (0, p_memoize_1.default)(onRequestChildren, {
58
- cache,
59
- cacheKey: ([source, resource]) => `onRequestChildren.${source.id}.${resource?.id}`,
60
- }),
61
- onRequestResource: (0, p_memoize_1.default)(onRequestResource, {
62
- cache,
63
- cacheKey: ([reference]) => `onRequestResource.${reference.source}.${reference.resource}`,
64
- }),
65
- }), [onRequestSources, onRequestChildren, onRequestResource]);
66
- return (react_1.default.createElement(exports.ResourceBrowserContext.Provider, { value: { ...memoized, ...other } }, children));
52
+ }), [onRequestSources]);
53
+ return react_1.default.createElement(exports.ResourceBrowserContext.Provider, { value: { ...memoized, ...other } }, children);
67
54
  };
68
55
  exports.ResourceBrowserContextProvider = ResourceBrowserContextProvider;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { ResourceBrowserPlugin, ResourceBrowserSource, ResourceBrowserUnresolvedResource, ResourceBrowserResource } 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
+ source: ResourceBrowserSource | null;
17
+ sources: ResourceBrowserSource[];
18
+ isLoading: boolean;
19
+ error: Error | null;
20
+ setSource(source: ResourceBrowserSource | null): void;
21
+ isModalOpen: boolean;
22
+ onModalStateChange(isOpen: boolean): void;
23
+ };
24
+ export declare const ResourceBrowserInput: ({ modalTitle, allowedTypes, onChange, value, useResource, isDisabled, onClear, plugin, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }: ResourceBrowserInputProps) => React.JSX.Element;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ResourceBrowserInput = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const MainContainer_1 = __importDefault(require("../MainContainer/MainContainer"));
9
+ const ResourcePicker_1 = require("../ResourcePicker/ResourcePicker");
10
+ const ResourceBrowserInput = ({ modalTitle, allowedTypes, onChange, value, useResource, isDisabled, onClear, plugin, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }) => {
11
+ const { data: resource, error: resourceError, isLoading: isResourceLoading } = useResource(value?.resourceId || null, source);
12
+ const defaultOnClear = () => onChange(null);
13
+ const onClearFunction = onClear ?? defaultOnClear;
14
+ return (react_1.default.createElement(ResourcePicker_1.ResourcePicker, { resource: resource, plugin: plugin, allowedTypes: allowedTypes, error: resourceError || error, isLoading: isResourceLoading || isLoading, isDisabled: isDisabled, onClear: onClearFunction, isModalOpen: isModalOpen, onModalStateChange: onModalStateChange }, (onClose, titleProps) => (react_1.default.createElement(MainContainer_1.default, { selectedSource: source, sources: sources, preselectedResource: resource, plugin: plugin, title: modalTitle, titleAriaProps: titleProps, allowedTypes: allowedTypes, onSourceSelect: setSource, onClose: onClose, onChange: onChange }))));
15
+ };
16
+ exports.ResourceBrowserInput = ResourceBrowserInput;
@@ -1,14 +1,16 @@
1
1
  import React from 'react';
2
2
  import { DOMAttributes } from '@react-types/shared';
3
- import { Resource } from '../types';
3
+ import { ResourceBrowserResource, ResourceBrowserPlugin } from '../types';
4
4
  export type ResourcePickerProps = {
5
- resource: Resource | null;
5
+ resource: ResourceBrowserResource | null;
6
+ plugin: ResourceBrowserPlugin | null;
6
7
  allowedTypes: string[] | undefined;
7
8
  error: Error | null;
8
9
  isLoading: boolean;
9
10
  isDisabled?: boolean;
10
11
  children: (onClose: () => void, titleProps: DOMAttributes) => React.ReactElement;
11
12
  onClear: () => void;
13
+ isModalOpen: boolean;
14
+ onModalStateChange(isOpen: boolean): void;
12
15
  };
13
- declare const ResourcePicker: ({ resource, allowedTypes, error, isLoading, isDisabled, children, onClear, }: ResourcePickerProps) => React.JSX.Element;
14
- export default ResourcePicker;
16
+ export declare const ResourcePicker: ({ resource, plugin, allowedTypes, error: externalError, isLoading: isExternalLoading, isDisabled, children, onClear, isModalOpen, onModalStateChange, }: ResourcePickerProps) => React.JSX.Element;