@squiz/resource-browser 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 911e0c4: Update file icon size and display for dam
8
+
9
+ ## 3.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - c8240b6: Minor styling updates
14
+ - Updated dependencies [c8240b6]
15
+ - @squiz/resource-browser-ui-lib@1.2.1
16
+
3
17
  ## 3.3.0
4
18
 
5
19
  ### Minor Changes
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
+ const sds_1 = require("@squiz/sds");
7
8
  const types_1 = require("../types");
8
9
  function ResourceLauncher({ sources, onSourceSelect }) {
9
10
  return (react_1.default.createElement("div", { className: "overflow-y-auto w-screen max-w-[400px] min-h-[290px] flex-1 grow-[3] border-r border-gray-300 bg-gray-100 pl-6 pr-6 pb-6 pt-4" },
@@ -11,7 +12,9 @@ function ResourceLauncher({ sources, onSourceSelect }) {
11
12
  const SourceLauncher = source.plugin.renderResourceLauncher();
12
13
  return (react_1.default.createElement("li", { key: index, className: "flex items-stretch relative" },
13
14
  react_1.default.createElement("div", { className: `squiz-rb-plugin squiz-rb-plugin--${source.plugin?.type} w-full` },
14
- react_1.default.createElement(SourceLauncher, { source: source, onSearch: (query) => onSourceSelect(source, { type: types_1.PluginLaunchModeType.Search, args: { query } }), onBrowse: (browseTo) => onSourceSelect(source, { type: types_1.PluginLaunchModeType.Browse, args: { browseTo } }) }))));
15
+ react_1.default.createElement(SourceLauncher, { source: source, onSearch: (query) => onSourceSelect(source, { type: types_1.PluginLaunchModeType.Search, args: { query } }), onBrowse: (browseTo) => onSourceSelect(source, { type: types_1.PluginLaunchModeType.Browse, args: { browseTo } }) }),
16
+ sources.length > 1 && index < sources.length - 1 && (react_1.default.createElement("div", { className: "pt-3 pb-3" },
17
+ react_1.default.createElement(sds_1.Divider, null))))));
15
18
  }))));
16
19
  }
17
20
  exports.default = ResourceLauncher;
@@ -16,7 +16,7 @@ const SelectedState = ({ resource, showThumbnail, icon, label, description, isDi
16
16
  const replaceAsset = (react_1.default.createElement(resource_browser_ui_lib_1.ModalTrigger, { overlayTriggerState: modalController, showLabel: false, label: "Replace selection", containerClasses: "text-gray-500 hover:text-gray-800 focus:text-gray-800 disabled:text-gray-500 disabled:cursor-not-allowed", icon: react_1.default.createElement(CircledLoopIcon_1.CircledLoopIcon, { "aria-hidden": true, className: "m-1" }), isDisabled: isDisabled, scope: "squiz-rb-scope" }, resourcePickerContainer));
17
17
  return (react_1.default.createElement(react_1.default.Fragment, null,
18
18
  showThumbnail && resource.squizImage ? (react_1.default.createElement("div", { className: "checkered-bg w-[56px] h-[56px] overflow-hidden flex justify-center items-center rounded" },
19
- react_1.default.createElement("img", { src: resource.squizImage.imageVariations.original.url || resource.url, className: "w-full h-full object-cover object-center", alt: resource.squizImage.name || resource.name }))) : (react_1.default.createElement("div", { className: "w-4 h-4 mt-1 flex self-start overflow-hidden" }, icon)),
19
+ react_1.default.createElement("img", { src: resource.squizImage.imageVariations.original.url || resource.url, className: "w-full h-full object-cover object-center", alt: resource.squizImage.name || resource.name }))) : (react_1.default.createElement("div", { className: "w-4 h-5 mt-1 flex self-start overflow-hidden" }, icon)),
20
20
  react_1.default.createElement("div", { className: "justify-self-start self-center w-full overflow-hidden break-words" },
21
21
  label,
22
22
  description),
package/lib/index.css CHANGED
@@ -5005,6 +5005,9 @@
5005
5005
  .squiz-rb-scope .h-4:not(.squiz-rb-plugin *) {
5006
5006
  height: 1rem;
5007
5007
  }
5008
+ .squiz-rb-scope .h-5:not(.squiz-rb-plugin *) {
5009
+ height: 1.25rem;
5010
+ }
5008
5011
  .squiz-rb-scope .h-6:not(.squiz-rb-plugin *) {
5009
5012
  height: 1.5rem;
5010
5013
  }
@@ -5201,6 +5204,9 @@
5201
5204
  .squiz-rb-scope .rounded-lg:not(.squiz-rb-plugin *) {
5202
5205
  border-radius: 0.5rem;
5203
5206
  }
5207
+ .squiz-rb-scope .border:not(.squiz-rb-plugin *) {
5208
+ border-width: 1px;
5209
+ }
5204
5210
  .squiz-rb-scope .border-0:not(.squiz-rb-plugin *) {
5205
5211
  border-width: 0px;
5206
5212
  }
@@ -5364,6 +5370,9 @@
5364
5370
  .squiz-rb-scope .pb-0:not(.squiz-rb-plugin *) {
5365
5371
  padding-bottom: 0px;
5366
5372
  }
5373
+ .squiz-rb-scope .pb-3:not(.squiz-rb-plugin *) {
5374
+ padding-bottom: 0.75rem;
5375
+ }
5367
5376
  .squiz-rb-scope .pb-4:not(.squiz-rb-plugin *) {
5368
5377
  padding-bottom: 1rem;
5369
5378
  }
@@ -5893,7 +5902,12 @@
5893
5902
  width: 48px;
5894
5903
  }
5895
5904
  .squiz-rb-scope .sourceLauncher:not(.squiz-rb-plugin *) {
5896
- position: relative;
5905
+ margin-bottom: 0.5rem;
5906
+ }
5907
+ .squiz-rb-scope .sourceLauncher__top-row:not(.squiz-rb-plugin *) {
5908
+ display: flex;
5909
+ align-items: flex-end;
5910
+ justify-content: space-between;
5897
5911
  margin-bottom: 0.5rem;
5898
5912
  }
5899
5913
  .squiz-rb-scope .sourceLauncher__title:not(.squiz-rb-plugin *) {
@@ -5904,10 +5918,8 @@
5904
5918
  color: #4f4f4f;
5905
5919
  }
5906
5920
  .squiz-rb-scope .sourceLauncher__browse-group:not(.squiz-rb-plugin *) {
5907
- position: absolute;
5908
- right: 0;
5909
- top: 0;
5910
5921
  display: flex;
5922
+ align-items: center;
5911
5923
  }
5912
5924
  .squiz-rb-scope .sourceLauncher__or:not(.squiz-rb-plugin *) {
5913
5925
  display: flex;
@@ -6041,11 +6053,21 @@
6041
6053
  padding: 0.25rem 0;
6042
6054
  border-bottom: 1px solid #ededed;
6043
6055
  }
6044
- .squiz-rb-scope .searchItem--selected .searchItem__button:not(.squiz-rb-plugin *) {
6056
+ .squiz-rb-scope .searchItem.searchItem--selected .searchItem__button:not(.squiz-rb-plugin *) {
6045
6057
  background-color: #e6f1fa;
6046
6058
  border-radius: 0.5rem;
6047
6059
  }
6048
- .squiz-rb-scope .searchItem--selected .searchItem__label:not(.squiz-rb-plugin *) {
6060
+ .squiz-rb-scope .searchItem.searchItem--selected .searchItem__label:not(.squiz-rb-plugin *) {
6061
+ color: #044985;
6062
+ }
6063
+ .squiz-rb-scope .searchItem.searchItem--selected:hover .searchItem__button:not(.squiz-rb-plugin *),
6064
+ .squiz-rb-scope .searchItem.searchItem--selected:focus .searchItem__button:not(.squiz-rb-plugin *),
6065
+ .squiz-rb-scope .searchItem.searchItem--selected:focus-within .searchItem__button:not(.squiz-rb-plugin *) {
6066
+ background-color: #e6f1fa;
6067
+ }
6068
+ .squiz-rb-scope .searchItem.searchItem--selected:hover .searchItem__label:not(.squiz-rb-plugin *),
6069
+ .squiz-rb-scope .searchItem.searchItem--selected:focus .searchItem__label:not(.squiz-rb-plugin *),
6070
+ .squiz-rb-scope .searchItem.searchItem--selected:focus-within .searchItem__label:not(.squiz-rb-plugin *) {
6049
6071
  color: #044985;
6050
6072
  }
6051
6073
  .squiz-rb-scope .searchItem:hover .searchItem__button:not(.squiz-rb-plugin *),
@@ -6096,7 +6118,7 @@
6096
6118
  line-height: 24px;
6097
6119
  text-align: center;
6098
6120
  letter-spacing: -0.4px;
6099
- color: #707070;
6121
+ color: #949494;
6100
6122
  }
6101
6123
  .squiz-rb-scope .no-search-result-container .no-result-message:not(.squiz-rb-plugin *) {
6102
6124
  margin-top: 1rem;
@@ -6263,6 +6285,74 @@
6263
6285
  .squiz-rb-scope .image-info__loading:not(.squiz-rb-plugin *) {
6264
6286
  margin-top: 80px;
6265
6287
  }
6288
+ .squiz-rb-scope .divider:not(.squiz-rb-plugin *) {
6289
+ width: 100%;
6290
+ padding: 0 1.25rem;
6291
+ }
6292
+ .squiz-rb-scope .empty-wrapper:not(.squiz-rb-plugin *) {
6293
+ align-items: center;
6294
+ color: #707070;
6295
+ display: flex;
6296
+ flex-direction: column;
6297
+ }
6298
+ .squiz-rb-scope .empty-text:not(.squiz-rb-plugin *) {
6299
+ padding-left: 1.25rem;
6300
+ padding-right: 1.25rem;
6301
+ }
6302
+ .squiz-rb-scope .empty-text__select:not(.squiz-rb-plugin *) {
6303
+ padding-top: 1.5rem;
6304
+ padding-bottom: 1rem;
6305
+ }
6306
+ .squiz-rb-scope .empty-text__select svg:not(.squiz-rb-plugin *) {
6307
+ height: 72px;
6308
+ width: 72px;
6309
+ }
6310
+ .squiz-rb-scope .empty-text__select svg path:not(.squiz-rb-plugin *) {
6311
+ fill: #bababa;
6312
+ }
6313
+ .squiz-rb-scope .image-info__details-list:not(.squiz-rb-plugin *) {
6314
+ width: 270px;
6315
+ display: flex;
6316
+ flex-direction: column;
6317
+ margin: 1rem 0;
6318
+ width: 100%;
6319
+ padding: 0 1.25rem;
6320
+ }
6321
+ .squiz-rb-scope .info__details-list:not(.squiz-rb-plugin *) {
6322
+ width: 270px;
6323
+ display: flex;
6324
+ flex-direction: column;
6325
+ margin: 1rem 0;
6326
+ width: 100%;
6327
+ padding: 0 1.25rem;
6328
+ }
6329
+ .squiz-rb-scope .info__details-item:not(.squiz-rb-plugin *) {
6330
+ display: flex;
6331
+ margin-bottom: 0.5rem;
6332
+ padding-left: 0.25rem;
6333
+ }
6334
+ .squiz-rb-scope .info__details-label:not(.squiz-rb-plugin *) {
6335
+ color: #707070;
6336
+ width: 60px;
6337
+ display: flex;
6338
+ }
6339
+ .squiz-rb-scope .info__details-value:not(.squiz-rb-plugin *) {
6340
+ margin-left: 20px;
6341
+ color: #3d3d3d;
6342
+ }
6343
+ .squiz-rb-scope .info__title:not(.squiz-rb-plugin *) {
6344
+ padding: 0 2.2rem;
6345
+ margin: 1rem 0;
6346
+ color: #3d3d3d;
6347
+ }
6348
+ .squiz-rb-scope .loader__container:not(.squiz-rb-plugin *) {
6349
+ display: flex;
6350
+ justify-content: center;
6351
+ align-items: center;
6352
+ height: 100%;
6353
+ width: 100%;
6354
+ color: #949494;
6355
+ }
6266
6356
  .squiz-rb-scope .resource-picker:not(.squiz-rb-plugin *) {
6267
6357
  display: grid;
6268
6358
  grid-template-columns: 24px 1fr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/resource-browser",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -28,7 +28,7 @@
28
28
  "@react-types/shared": "^3.23.1",
29
29
  "@squiz/dx-json-schema-lib": "^1.67.0",
30
30
  "@squiz/generic-browser-lib": "1.67.2",
31
- "@squiz/resource-browser-ui-lib": "^1.0.0",
31
+ "@squiz/resource-browser-ui-lib": "^1.2.1",
32
32
  "clsx": "^2.1.0",
33
33
  "expiry-map": "^2.0.0",
34
34
  "p-memoize": "^4.0.4",
@@ -23,6 +23,20 @@ describe('ResourceLauncher', () => {
23
23
  expect(screen.queryAllByText('Resource Launcher UI').length).toEqual(2);
24
24
  });
25
25
 
26
+ it('should render the divider only for source items except the last one', () => {
27
+ const sources = [
28
+ mockSourceWithPlugin({ plugin: defaultPlugin }),
29
+ mockSourceWithPlugin({ id: '2', plugin: defaultPlugin }),
30
+ mockSourceWithPlugin({ id: '3', plugin: defaultPlugin }),
31
+ ];
32
+ const onSourceSelect = jest.fn();
33
+ const { container } = render(<ResourceLauncher sources={sources} onSourceSelect={onSourceSelect} />);
34
+
35
+ const dividerContainers = container.querySelectorAll('div.pt-3.pb-3');
36
+ // With 3 sources, there should be 2 dividers (in the first two <li>s)
37
+ expect(dividerContainers.length).toEqual(sources.length - 1);
38
+ });
39
+
26
40
  it('onSourceSelect query', async () => {
27
41
  const sources = [mockSourceWithPlugin({ plugin: defaultPlugin })];
28
42
  const onSourceSelect = jest.fn();
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { StoryFn, Meta } from '@storybook/react';
3
+ import ResourceLauncher from './ResourceLauncher';
4
+ import sampleSources from '../__mocks__/sample-sources.json';
5
+ import { ResourceBrowserSourceWithPlugin, PluginLaunchMode, PluginLaunchModeType } from '../types';
6
+
7
+ const DummyLauncher = ({
8
+ source,
9
+ onSearch,
10
+ onBrowse,
11
+ }: {
12
+ source: any;
13
+ onSearch: (query: string) => void;
14
+ onBrowse: (browseTo: string) => void;
15
+ }) => (
16
+ <div className="p-2 border rounded">
17
+ <div>{source.name}</div>
18
+ <button onClick={() => onSearch('sample query')} className="mr-2">
19
+ Search
20
+ </button>
21
+ <button onClick={() => onBrowse('sample browse')}>Browse</button>
22
+ </div>
23
+ );
24
+
25
+ const sourcesWithDummyPlugin = (sampleSources as any[]).map((source) => ({
26
+ ...source,
27
+ plugin: {
28
+ ...source.plugin,
29
+ type: source.plugin?.type || 'dummy',
30
+ // renderResourceLauncher should return a component. Here we return a function that renders DummyLauncher.
31
+ renderResourceLauncher: () => DummyLauncher,
32
+ },
33
+ })) as ResourceBrowserSourceWithPlugin[];
34
+
35
+ export default {
36
+ title: 'Resource Launcher',
37
+ component: ResourceLauncher,
38
+ } as Meta<typeof ResourceLauncher>;
39
+
40
+ const Template: StoryFn<typeof ResourceLauncher> = (args) => {
41
+ return (
42
+ <div className="flex justify-center m-3">
43
+ <ResourceLauncher
44
+ {...args}
45
+ sources={sourcesWithDummyPlugin}
46
+ onSourceSelect={(source, mode: PluginLaunchMode) => {
47
+ console.log(`Source ${source?.name} / ${source.id} was selected with mode:`, mode);
48
+ }}
49
+ />
50
+ </div>
51
+ );
52
+ };
53
+
54
+ export const Primary = Template.bind({});
55
+ Primary.args = {};
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { Divider } from '@squiz/sds';
2
3
  import { ResourceBrowserSource, ResourceBrowserSourceWithPlugin, PluginLaunchMode, PluginLaunchModeType } from '../types';
3
4
 
4
5
  interface ResourceLauncherProps {
@@ -23,6 +24,11 @@ function ResourceLauncher({ sources, onSourceSelect }: ResourceLauncherProps) {
23
24
  onSourceSelect(source, { type: PluginLaunchModeType.Browse, args: { browseTo } })
24
25
  }
25
26
  />
27
+ {sources.length > 1 && index < sources.length - 1 && (
28
+ <div className="pt-3 pb-3">
29
+ <Divider />
30
+ </div>
31
+ )}
26
32
  </div>
27
33
  </li>
28
34
  );
@@ -60,7 +60,7 @@ export const SelectedState = ({
60
60
  />
61
61
  </div>
62
62
  ) : (
63
- <div className="w-4 h-4 mt-1 flex self-start overflow-hidden">{icon}</div>
63
+ <div className="w-4 h-5 mt-1 flex self-start overflow-hidden">{icon}</div>
64
64
  )}
65
65
  {/* Center columns */}
66
66
  <div className="justify-self-start self-center w-full overflow-hidden break-words">
@@ -85,26 +85,28 @@ export const createPlugins = (callbackWait: number, headerPortal = false, resour
85
85
  setTimeout(() => {
86
86
  resolve({
87
87
  showThumbnail: resource.squizImage ? true : false,
88
- icon: <Icon icon={resource.type.code} resourceSource="matrix" className="w-4 h-4" />,
88
+ icon: <Icon icon={resource.type.code} resourceSource="matrix" className="" />,
89
89
  label: resource.name || resource.squizImage?.name || resource.id,
90
- description: [
91
- <dl
92
- key="1"
93
- className="col-start-2 col-end-2 flex flex-row gap-1 justify-self-start items-center font-normal text-sm"
94
- >
95
- <div>
96
- <span>{type} plugin</span>
97
- <dt className="hidden">Asset size</dt>
98
- <dd className="text-gray-600">
99
- {resource.squizImage && (
100
- <>
101
- {fileSize} kB , {fileWidth} x {fileHeight}px
102
- </>
103
- )}
104
- </dd>
105
- </div>
106
- </dl>,
107
- ],
90
+ description: resource.squizImage
91
+ ? [
92
+ <dl
93
+ key="1"
94
+ className="col-start-2 col-end-2 flex flex-row gap-1 justify-self-start items-center font-normal text-sm"
95
+ >
96
+ <div>
97
+ <span>{type} plugin</span>
98
+ <dt className="hidden">Asset size</dt>
99
+ <dd className="text-gray-600">
100
+ {resource.squizImage && (
101
+ <>
102
+ {fileSize} kB , {fileWidth} x {fileHeight}px
103
+ </>
104
+ )}
105
+ </dd>
106
+ </div>
107
+ </dl>,
108
+ ]
109
+ : undefined,
108
110
  });
109
111
  }, callbackWait);
110
112
  });
@@ -121,6 +123,7 @@ export const createPlugins = (callbackWait: number, headerPortal = false, resour
121
123
  }
122
124
  useEffect(() => {
123
125
  if (unresolvedResource !== null) {
126
+ const forceType: string = unresolvedResource.forceResourceType;
124
127
  setTimeout(() => {
125
128
  setIsLoading(false);
126
129
  setResource({
@@ -129,23 +132,25 @@ export const createPlugins = (callbackWait: number, headerPortal = false, resour
129
132
  url: 'https://cdn.mediavalet.com/aunsw/squiz/KfIjcjUJz0O6kWoInBys5A/XpBxg3Hj-0qOXFWnAAWvXQ/Large/RX-7.jpeg',
130
133
  source: unresolvedResource.source,
131
134
  type: {
132
- code: 'jpeg',
135
+ code: forceType ? forceType : 'jpeg',
133
136
  name: 'JPEG image',
134
137
  },
135
- squizImage: {
136
- name: 'An image from Bynder',
137
- imageVariations: {
138
- original: {
139
- width: 1024,
140
- height: 900,
141
- url: 'https://cdn.mediavalet.com/aunsw/squiz/KfIjcjUJz0O6kWoInBys5A/XpBxg3Hj-0qOXFWnAAWvXQ/Large/RX-7.jpeg',
142
- mimeType: 'image/jpeg',
143
- byteSize: 1068,
144
- sha1Hash: '',
145
- aspectRatio: '',
146
- },
147
- },
148
- },
138
+ squizImage: forceType
139
+ ? undefined
140
+ : {
141
+ name: 'An image from Bynder',
142
+ imageVariations: {
143
+ original: {
144
+ width: 1024,
145
+ height: 900,
146
+ url: 'https://cdn.mediavalet.com/aunsw/squiz/KfIjcjUJz0O6kWoInBys5A/XpBxg3Hj-0qOXFWnAAWvXQ/Large/RX-7.jpeg',
147
+ mimeType: 'image/jpeg',
148
+ byteSize: 1068,
149
+ sha1Hash: '',
150
+ aspectRatio: '',
151
+ },
152
+ },
153
+ },
149
154
  });
150
155
  }, callbackWait);
151
156
  } else {
@@ -74,6 +74,16 @@ Selected.args = {
74
74
  },
75
75
  };
76
76
 
77
+ export const SelectedFile = Template.bind({});
78
+ SelectedFile.args = {
79
+ ...Primary.args,
80
+ value: {
81
+ resourceId: '1f7a25b4-380f-4540-9555-8be2dcab4019',
82
+ sourceId: 'c90feac1-55f3-4e1f-9b56-c22829e3f510',
83
+ forceResourceType: 'pdf',
84
+ },
85
+ };
86
+
77
87
  export const ImagesOnly = Template.bind({});
78
88
  ImagesOnly.args = {
79
89
  ...Primary.args,