@webiny/ui 5.22.0-beta.3 → 5.23.0-beta.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.
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { ControllerStateAndHelpers } from "downshift";
2
3
  import { AutoCompleteBaseProps } from "./types";
3
4
  export declare enum Placement {
4
5
  top = "top",
@@ -13,12 +14,19 @@ export declare type Props = AutoCompleteBaseProps & {
13
14
  declare type State = {
14
15
  inputValue: string;
15
16
  };
17
+ interface RenderOptionsParams extends Omit<ControllerStateAndHelpers<any>, "getInputProps" | "openMenu"> {
18
+ options: Props["options"];
19
+ placement: Props["placement"];
20
+ }
16
21
  declare class AutoComplete extends React.Component<Props, State> {
17
22
  static defaultProps: {
18
23
  valueProp: string;
19
24
  textProp: string;
20
25
  options: any[];
21
26
  placement: Placement;
27
+ /**
28
+ * We cast this as AutoComplete because renderItem() is executed via .call() where AutoComplete instance is assigned as this.
29
+ */
22
30
  renderItem(item: any): JSX.Element;
23
31
  };
24
32
  state: {
@@ -32,7 +40,7 @@ declare class AutoComplete extends React.Component<Props, State> {
32
40
  /**
33
41
  * Renders options - based on user's input. It will try to match input text with available options.
34
42
  */
35
- renderOptions({ options, isOpen, highlightedIndex, selectedItem, getMenuProps, getItemProps, placement }: any): JSX.Element;
43
+ renderOptions({ options, isOpen, highlightedIndex, selectedItem, getMenuProps, getItemProps, placement }: RenderOptionsParams): JSX.Element;
36
44
  render(): JSX.Element;
37
45
  }
38
46
  export { AutoComplete };
@@ -49,6 +49,18 @@ function Spinner() {
49
49
  });
50
50
  }
51
51
 
52
+ var OptionsList = function OptionsList(_ref) {
53
+ var placement = _ref.placement,
54
+ getMenuProps = _ref.getMenuProps,
55
+ children = _ref.children;
56
+ return /*#__PURE__*/React.createElement(Elevation, {
57
+ z: 1,
58
+ className: classNames(_defineProperty({}, menuStyles, placement === Placement.top))
59
+ }, /*#__PURE__*/React.createElement("ul", Object.assign({
60
+ className: classNames("autocomplete__options-list", listStyles)
61
+ }, getMenuProps()), children));
62
+ };
63
+
52
64
  var AutoComplete = /*#__PURE__*/function (_React$Component) {
53
65
  _inherits(AutoComplete, _React$Component);
54
66
 
@@ -107,20 +119,33 @@ var AutoComplete = /*#__PURE__*/function (_React$Component) {
107
119
 
108
120
  }, {
109
121
  key: "renderOptions",
110
- value: function renderOptions(_ref) {
122
+ value: function renderOptions(_ref2) {
111
123
  var _this3 = this;
112
124
 
113
- var options = _ref.options,
114
- isOpen = _ref.isOpen,
115
- highlightedIndex = _ref.highlightedIndex,
116
- selectedItem = _ref.selectedItem,
117
- getMenuProps = _ref.getMenuProps,
118
- getItemProps = _ref.getItemProps,
119
- placement = _ref.placement;
125
+ var options = _ref2.options,
126
+ isOpen = _ref2.isOpen,
127
+ highlightedIndex = _ref2.highlightedIndex,
128
+ selectedItem = _ref2.selectedItem,
129
+ getMenuProps = _ref2.getMenuProps,
130
+ getItemProps = _ref2.getItemProps,
131
+ placement = _ref2.placement;
120
132
 
121
133
  if (!isOpen) {
122
134
  return null;
123
135
  }
136
+ /**
137
+ * Suggest user to start typing when there are no options available to choose from.
138
+ */
139
+
140
+
141
+ if (!this.state.inputValue && !options.length) {
142
+ return /*#__PURE__*/React.createElement(OptionsList, {
143
+ placement: placement,
144
+ getMenuProps: getMenuProps
145
+ }, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Typography, {
146
+ use: "body2"
147
+ }, "Start typing to find entry")));
148
+ }
124
149
 
125
150
  var renderItem = this.props.renderItem;
126
151
  var filtered = options.filter(function (item) {
@@ -137,22 +162,18 @@ var AutoComplete = /*#__PURE__*/function (_React$Component) {
137
162
  });
138
163
 
139
164
  if (!filtered.length) {
140
- return /*#__PURE__*/React.createElement(Elevation, {
141
- z: 1,
142
- className: classNames(_defineProperty({}, menuStyles, placement === Placement.top))
143
- }, /*#__PURE__*/React.createElement("ul", Object.assign({
144
- className: classNames("autocomplete__options-list", listStyles)
145
- }, getMenuProps()), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Typography, {
165
+ return /*#__PURE__*/React.createElement(OptionsList, {
166
+ placement: placement,
167
+ getMenuProps: getMenuProps
168
+ }, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Typography, {
146
169
  use: "body2"
147
- }, "No results."), this.props.noResultFound)));
170
+ }, "No results."), this.props.noResultFound));
148
171
  }
149
172
 
150
- return /*#__PURE__*/React.createElement(Elevation, {
151
- z: 1,
152
- className: classNames(_defineProperty({}, menuStyles, placement === Placement.top))
153
- }, /*#__PURE__*/React.createElement("ul", Object.assign({
154
- className: classNames("autocomplete__options-list", listStyles)
155
- }, getMenuProps()), filtered.map(function (item, index) {
173
+ return /*#__PURE__*/React.createElement(OptionsList, {
174
+ placement: placement,
175
+ getMenuProps: getMenuProps
176
+ }, filtered.map(function (item, index) {
156
177
  var _itemClassNames;
157
178
 
158
179
  var itemValue = getOptionValue(item, _this3.props); // Base classes.
@@ -171,7 +192,7 @@ var AutoComplete = /*#__PURE__*/function (_React$Component) {
171
192
  item: item,
172
193
  className: classNames(itemClassNames)
173
194
  })), renderItem.call(_this3, item, index));
174
- })));
195
+ }));
175
196
  }
176
197
  }, {
177
198
  key: "render",
@@ -218,10 +239,10 @@ var AutoComplete = /*#__PURE__*/function (_React$Component) {
218
239
  className: classNames(autoCompleteStyle, className)
219
240
  }, /*#__PURE__*/React.createElement(Downshift, Object.assign({}, downshiftProps, {
220
241
  ref: this.downshift
221
- }), function (_ref2) {
222
- var getInputProps = _ref2.getInputProps,
223
- openMenu = _ref2.openMenu,
224
- rest = _objectWithoutProperties(_ref2, _excluded2);
242
+ }), function (_ref3) {
243
+ var getInputProps = _ref3.getInputProps,
244
+ openMenu = _ref3.openMenu,
245
+ rest = _objectWithoutProperties(_ref3, _excluded2);
225
246
 
226
247
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Input, getInputProps(_objectSpread(_objectSpread({
227
248
  // This prop is above `otherInputProps` since it can be overridden by the user.
@@ -289,6 +310,10 @@ _defineProperty(AutoComplete, "defaultProps", {
289
310
  textProp: "name",
290
311
  options: [],
291
312
  placement: Placement.bottom,
313
+
314
+ /**
315
+ * We cast this as AutoComplete because renderItem() is executed via .call() where AutoComplete instance is assigned as this.
316
+ */
292
317
  renderItem: function renderItem(item) {
293
318
  return /*#__PURE__*/React.createElement(Typography, {
294
319
  use: "body2"
@@ -1,5 +1,7 @@
1
1
  import * as React from "react";
2
+ import { ControllerStateAndHelpers } from "downshift";
2
3
  import { AutoCompleteBaseProps } from "./types";
4
+ import { Props } from "./AutoComplete";
3
5
  export declare type MultiAutoCompleteProps = AutoCompleteBaseProps & {
4
6
  /**
5
7
  * Prevents adding the same item to the list twice.
@@ -30,6 +32,10 @@ declare type State = {
30
32
  reorderFormVisible: string;
31
33
  reorderFormValue: string;
32
34
  };
35
+ interface RenderOptionsParams extends Omit<ControllerStateAndHelpers<any>, "getInputProps" | "openMenu"> {
36
+ options: Props["options"];
37
+ unique: boolean;
38
+ }
33
39
  export declare class MultiAutoComplete extends React.Component<MultiAutoCompleteProps, State> {
34
40
  static defaultProps: {
35
41
  valueProp: string;
@@ -38,7 +44,13 @@ export declare class MultiAutoComplete extends React.Component<MultiAutoComplete
38
44
  options: any[];
39
45
  useSimpleValues: boolean;
40
46
  useMultipleSelectionList: boolean;
47
+ /**
48
+ * We cast this as MultiAutoComplete because renderItem() is executed via .call() where this is MultiAutoComplete instance.
49
+ */
41
50
  renderItem(item: any): JSX.Element;
51
+ /**
52
+ * We cast this as MultiAutoComplete because renderListItemLabel() is executed via .call() where this is MultiAutoComplete instance.
53
+ */
42
54
  renderListItemLabel(item: any): any;
43
55
  };
44
56
  state: {
@@ -51,7 +63,7 @@ export declare class MultiAutoComplete extends React.Component<MultiAutoComplete
51
63
  /**
52
64
  * Helps us trigger some of the downshift's methods (eg. clearSelection) and helps us to avoid adding state.
53
65
  */
54
- downshift: any;
66
+ downshift: React.RefObject<any>;
55
67
  assignedValueAfterClearing: {
56
68
  set: boolean;
57
69
  selection: any;
@@ -61,15 +73,8 @@ export declare class MultiAutoComplete extends React.Component<MultiAutoComplete
61
73
  getOptions(): any[];
62
74
  /**
63
75
  * Renders options - based on user's input. It will try to match input text with available options.
64
- * @param options
65
- * @param isOpen
66
- * @param highlightedIndex
67
- * @param selectedItem
68
- * @param getMenuProps
69
- * @param getItemProps
70
- * @returns {*}
71
76
  */
72
- renderOptions({ options, isOpen, highlightedIndex, getMenuProps, getItemProps }: any): JSX.Element;
77
+ renderOptions(params: RenderOptionsParams): JSX.Element;
73
78
  /**
74
79
  * Once added, items can also be removed by clicking on the ✕ icon. This is the method that is responsible for
75
80
  * rendering selected items (we are using already existing "Chips" component).
@@ -123,6 +123,16 @@ function paginateMultipleSelection(multipleSelection, limit, page, search) {
123
123
  };
124
124
  }
125
125
 
126
+ var OptionsList = function OptionsList(_ref) {
127
+ var getMenuProps = _ref.getMenuProps,
128
+ children = _ref.children;
129
+ return /*#__PURE__*/React.createElement(Elevation, {
130
+ z: 1
131
+ }, /*#__PURE__*/React.createElement("ul", Object.assign({
132
+ className: classNames("multi-autocomplete__options-list", listStyles)
133
+ }, getMenuProps()), children));
134
+ };
135
+
126
136
  export var MultiAutoComplete = /*#__PURE__*/function (_React$Component) {
127
137
  _inherits(MultiAutoComplete, _React$Component);
128
138
 
@@ -229,29 +239,34 @@ export var MultiAutoComplete = /*#__PURE__*/function (_React$Component) {
229
239
  }
230
240
  /**
231
241
  * Renders options - based on user's input. It will try to match input text with available options.
232
- * @param options
233
- * @param isOpen
234
- * @param highlightedIndex
235
- * @param selectedItem
236
- * @param getMenuProps
237
- * @param getItemProps
238
- * @returns {*}
239
242
  */
240
243
 
241
244
  }, {
242
245
  key: "renderOptions",
243
- value: function renderOptions(_ref) {
246
+ value: function renderOptions(params) {
244
247
  var _this3 = this;
245
248
 
246
- var options = _ref.options,
247
- isOpen = _ref.isOpen,
248
- highlightedIndex = _ref.highlightedIndex,
249
- getMenuProps = _ref.getMenuProps,
250
- getItemProps = _ref.getItemProps;
249
+ var options = params.options,
250
+ isOpen = params.isOpen,
251
+ highlightedIndex = params.highlightedIndex,
252
+ getMenuProps = params.getMenuProps,
253
+ getItemProps = params.getItemProps;
251
254
 
252
255
  if (!isOpen) {
253
256
  return null;
254
257
  }
258
+ /**
259
+ * Suggest user to start typing when there are no options available to choose from.
260
+ */
261
+
262
+
263
+ if (!this.state.inputValue && !options.length) {
264
+ return /*#__PURE__*/React.createElement(OptionsList, {
265
+ getMenuProps: getMenuProps
266
+ }, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Typography, {
267
+ use: "body2"
268
+ }, "Start typing to find entry")));
269
+ }
255
270
 
256
271
  if (!options.length) {
257
272
  return /*#__PURE__*/React.createElement(Elevation, {
@@ -558,11 +573,19 @@ _defineProperty(MultiAutoComplete, "defaultProps", {
558
573
  options: [],
559
574
  useSimpleValues: false,
560
575
  useMultipleSelectionList: false,
576
+
577
+ /**
578
+ * We cast this as MultiAutoComplete because renderItem() is executed via .call() where this is MultiAutoComplete instance.
579
+ */
561
580
  renderItem: function renderItem(item) {
562
581
  return /*#__PURE__*/React.createElement(Typography, {
563
582
  use: "body2"
564
583
  }, getOptionText(item, this.props));
565
584
  },
585
+
586
+ /**
587
+ * We cast this as MultiAutoComplete because renderListItemLabel() is executed via .call() where this is MultiAutoComplete instance.
588
+ */
566
589
  renderListItemLabel: function renderListItemLabel(item) {
567
590
  return getOptionText(item, this.props);
568
591
  }
@@ -6,6 +6,11 @@ import _inherits from "@babel/runtime/helpers/inherits";
6
6
  import _createSuper from "@babel/runtime/helpers/createSuper";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
8
  import _debounce from "lodash/debounce";
9
+
10
+ /**
11
+ * When using Caman, we added @ts-ignore because it does not exist in packages, but it is loaded in packages/ui/src/ImageEditor/ImageEditor.tsx:38.
12
+ * TODO: use some other library to edit images
13
+ */
9
14
  import React from "react";
10
15
  import { ReactComponent as FilterIcon } from "./icons/filter.svg";
11
16
  import { Slider } from "../../Slider";
@@ -103,10 +108,13 @@ var RenderForm = /*#__PURE__*/function (_React$Component) {
103
108
  Caman(canvas.current, function () {
104
109
  var _this2 = this;
105
110
 
111
+ // @ts-ignore
106
112
  this.revert(false);
107
- Object.keys(values).forEach(function (key) {
113
+ Object.keys(values).forEach( // @ts-ignore
114
+ function (key) {
108
115
  return values[key] !== 0 && _this2[key] && _this2[key](values[key]);
109
- });
116
+ }); // @ts-ignore
117
+
110
118
  this.render();
111
119
  component.setState({
112
120
  processing: false
@@ -201,7 +209,9 @@ var tool = {
201
209
  var canvas = _ref2.canvas;
202
210
  // @ts-ignore
203
211
  Caman(canvas.current, function () {
204
- this.revert(false);
212
+ // @ts-ignore
213
+ this.revert(false); // @ts-ignore
214
+
205
215
  this.render();
206
216
  });
207
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/ui",
3
- "version": "5.22.0-beta.3",
3
+ "version": "5.23.0-beta.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,7 +47,7 @@
47
47
  "@rmwc/top-app-bar": "5.7.2",
48
48
  "@rmwc/types": "5.6.0",
49
49
  "@rmwc/typography": "5.7.2",
50
- "@svgr/webpack": "6.2.0",
50
+ "@svgr/webpack": "6.2.1",
51
51
  "brace": "0.11.1",
52
52
  "classnames": "2.3.1",
53
53
  "cropperjs": "1.5.12",
@@ -81,11 +81,11 @@
81
81
  "@storybook/addon-knobs": "^5.0.5",
82
82
  "@storybook/addon-links": "^5.0.5",
83
83
  "@storybook/react": "^5.2.8",
84
- "@webiny/cli": "^5.22.0-beta.3",
85
- "@webiny/form": "^5.22.0-beta.3",
86
- "@webiny/project-utils": "^5.22.0-beta.3",
87
- "@webiny/storybook-utils": "^5.22.0-beta.3",
88
- "@webiny/validation": "^5.22.0-beta.3",
84
+ "@webiny/cli": "^5.23.0-beta.0",
85
+ "@webiny/form": "^5.23.0-beta.0",
86
+ "@webiny/project-utils": "^5.23.0-beta.0",
87
+ "@webiny/storybook-utils": "^5.23.0-beta.0",
88
+ "@webiny/validation": "^5.23.0-beta.0",
89
89
  "babel-loader": "^8.0.0-beta.6",
90
90
  "babel-plugin-emotion": "^9.2.8",
91
91
  "execa": "^5.0.0",
@@ -99,6 +99,7 @@
99
99
  "rimraf": "^3.0.2",
100
100
  "sass": "^1.38.0",
101
101
  "sass-loader": "^12.1.0",
102
+ "ttypescript": "^1.5.13",
102
103
  "typescript": "^4.1.3",
103
104
  "webpack": "^4.46.0"
104
105
  },
@@ -132,5 +133,5 @@
132
133
  ]
133
134
  }
134
135
  },
135
- "gitHead": "7a6b4ce3b9f31fe0702fffd28b7959c637e9a20b"
136
+ "gitHead": "deb16c58954f7396c848f04806a2028aa53cc97b"
136
137
  }