superdesk-ui-framework 3.0.7 → 3.0.8

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.
@@ -50,12 +50,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.TableListItem = exports.TableList = void 0;
52
52
  var React = __importStar(require("react"));
53
+ var react_dom_1 = __importDefault(require("react-dom"));
53
54
  var classnames_1 = __importDefault(require("classnames"));
54
55
  var react_beautiful_dnd_1 = require("react-beautiful-dnd");
55
56
  var Tooltip_1 = require("../Tooltip");
56
57
  var Button_1 = require("../Button");
57
58
  var Dropdown_1 = require("../Dropdown");
58
- var react_dom_1 = __importDefault(require("react-dom"));
59
+ var SingleAndDoubleClickFunction_1 = require("./../SingleAndDoubleClickFunction");
59
60
  var reorder = function (list, startIndex, endIndex) {
60
61
  var result = Array.from(list);
61
62
  var removed = result.splice(startIndex, 1)[0];
@@ -121,30 +122,37 @@ var TableList = /** @class */ (function (_super) {
121
122
  ? _this.props.itemsDropdown(index)
122
123
  : []; } })
123
124
  : React.createElement("div", __assign({ ref: provided2.innerRef }, provided2.draggableProps, provided2.dragHandleProps),
124
- React.createElement(TableListItem, { dragAndDrop: _this.props.dragAndDrop, start: item.start, center: item.center, end: item.end, action: item.action, onClick: item.onClick ? item.onClick : undefined, onDoubleClick: item.onDoubleClick
125
+ React.createElement(TableListItem, { dragAndDrop: _this.props.dragAndDrop, start: item.start, center: item.center, end: item.end, action: item.action, onClick: item.onClick
126
+ ? item.onClick
127
+ : undefined, onDoubleClick: item.onDoubleClick
125
128
  ? item.onDoubleClick
126
129
  : undefined, addItem: _this.props.addItem, itemsDropdown: function () { return _this.props.itemsDropdown
127
130
  ? _this.props.itemsDropdown(index)
128
131
  : []; }, hexColor: item.hexColor, locked: item.locked, positionLocked: item.positionLocked, onAddItem: function () { return _this.props.onAddItem
129
132
  && _this.props.onAddItem(index, item); }, showDragHandle: _this.props.showDragHandle }))); })); }),
130
133
  provided.placeholder,
131
- (_this.props.addItem && !_this.props.readOnly) &&
132
- React.createElement("div", { className: "table-list__add-item table-list__item--margin" },
134
+ (_this.props.addItem && !_this.props.readOnly)
135
+ && React.createElement("div", { className: "table-list__add-item table-list__item--margin" },
133
136
  React.createElement(Tooltip_1.Tooltip, { text: 'Add item', flow: 'top', appendToBody: true },
134
137
  React.createElement("div", { className: 'table-list__add-item--container sd-margin-x--auto' }, _this.dropDown()))))); }))
135
138
  : React.createElement("div", { role: 'list', className: classes },
136
- this.state.items.map(function (item, index) { return (React.createElement(TableListItem, { key: index, start: item.start, center: item.center, end: item.end, action: item.action, onClick: item.onClick ? item.onClick : undefined, onDoubleClick: item.onDoubleClick
139
+ this.state.items.map(function (item, index) { return (React.createElement(TableListItem, { key: index, start: item.start, center: item.center, end: item.end, action: item.action, onClick: item.onClick
140
+ ? item.onClick
141
+ : undefined, onDoubleClick: item.onDoubleClick
137
142
  ? item.onDoubleClick
138
- : undefined, addItem: _this.props.addItem, itemsDropdown: function () { return _this.props.itemsDropdown ? _this.props.itemsDropdown(index) : []; }, hexColor: item.hexColor, locked: item.locked, positionLocked: item.positionLocked, onAddItem: function () { return _this.props.onAddItem
143
+ : undefined, addItem: _this.props.addItem, itemsDropdown: function () { return _this.props.itemsDropdown
144
+ ? _this.props.itemsDropdown(index)
145
+ : []; }, hexColor: item.hexColor, locked: item.locked, positionLocked: item.positionLocked, onAddItem: function () { return _this.props.onAddItem
139
146
  && _this.props.onAddItem(index, item); } })); }),
140
- (this.props.addItem && !this.props.readOnly) &&
141
- React.createElement("div", { className: "table-list__add-item table-list__item--margin" },
147
+ (this.props.addItem && !this.props.readOnly)
148
+ && React.createElement("div", { className: "table-list__add-item table-list__item--margin" },
142
149
  React.createElement(Tooltip_1.Tooltip, { text: 'Add item', flow: 'top', appendToBody: true },
143
150
  React.createElement("div", { className: 'table-list__add-item--container sd-margin-x--auto' }, this.dropDown()))))
144
- : (this.props.addItem && !this.props.readOnly) ? React.createElement("div", { role: 'list', className: classes },
145
- React.createElement("div", { className: "table-list__add-item table-list__item--margin" },
146
- React.createElement(Tooltip_1.Tooltip, { text: 'Add item', flow: 'top', appendToBody: true },
147
- React.createElement("div", { className: 'table-list__add-item--container sd-margin-x--auto' }, this.dropDown()))))
151
+ : (this.props.addItem && !this.props.readOnly)
152
+ ? React.createElement("div", { role: 'list', className: classes },
153
+ React.createElement("div", { className: "table-list__add-item table-list__item--margin" },
154
+ React.createElement(Tooltip_1.Tooltip, { text: 'Add item', flow: 'top', appendToBody: true },
155
+ React.createElement("div", { className: 'table-list__add-item--container sd-margin-x--auto' }, this.dropDown()))))
148
156
  : null);
149
157
  };
150
158
  return TableList;
@@ -152,39 +160,13 @@ var TableList = /** @class */ (function (_super) {
152
160
  exports.TableList = TableList;
153
161
  var TableListItem = /** @class */ (function (_super) {
154
162
  __extends(TableListItem, _super);
155
- function TableListItem() {
156
- var _this = _super !== null && _super.apply(this, arguments) || this;
157
- _this.delay = 200;
158
- _this.prevent = false;
159
- _this.onSingleClick = function () {
160
- var selection = window.getSelection();
161
- _this.timer = setTimeout(function () {
162
- if (!_this.prevent && _this.props.onClick && selection) {
163
- if (_this.props.dragAndDrop) {
164
- _this.props.onClick();
165
- }
166
- else {
167
- if (selection.toString().length < 1) {
168
- _this.props.onClick();
169
- }
170
- }
171
- }
172
- }, _this.delay);
173
- };
174
- _this.onDoubleClick = function () {
175
- clearTimeout(_this.timer);
176
- _this.prevent = true;
177
- if (_this.props.onDoubleClick) {
178
- _this.props.onDoubleClick();
179
- }
180
- setTimeout(function () {
181
- _this.prevent = false;
182
- }, _this.delay);
183
- };
163
+ function TableListItem(props) {
164
+ var _this = _super.call(this, props) || this;
184
165
  _this.onActionMenuClick = function (event) {
185
166
  event.preventDefault();
186
167
  event.stopPropagation();
187
168
  };
169
+ _this.multiClickHandler = (0, SingleAndDoubleClickFunction_1.setupSingleAndDoubleClick)();
188
170
  return _this;
189
171
  }
190
172
  TableListItem.prototype.render = function () {
@@ -196,30 +178,52 @@ var TableListItem = /** @class */ (function (_super) {
196
178
  'table-list__item--position-locked': this.props.positionLocked,
197
179
  'table-list__item--drag-handles-always': !this.props.showDragHandle,
198
180
  'table-list__item--drag-handles-none': this.props.showDragHandle === 'none',
181
+ 'table-list__item--margin': !this.props.addItem,
199
182
  });
200
- return (this.props.addItem ?
201
- React.createElement("div", { className: 'table-list__item-container' },
202
- React.createElement("div", { role: 'listitem', onClick: function () { return _this.onSingleClick(); }, onDoubleClick: function () { return _this.onDoubleClick(); }, className: classes },
183
+ var Wrapper = this.props.addItem
184
+ ? function (_a) {
185
+ var children = _a.children;
186
+ return (React.createElement("div", { className: 'table-list__item-container' }, children));
187
+ }
188
+ : function (_a) {
189
+ var children = _a.children;
190
+ return children;
191
+ };
192
+ return (React.createElement(Wrapper, null,
193
+ React.createElement(React.Fragment, null,
194
+ React.createElement("div", { role: 'listitem', className: classes, onClick: function (e) { return _this.multiClickHandler(e, {
195
+ onSingleClick: function () {
196
+ var selection = window.getSelection();
197
+ if (_this.props.onClick && selection) {
198
+ if (_this.props.dragAndDrop) {
199
+ _this.props.onClick();
200
+ }
201
+ else {
202
+ if (selection.toString().length < 1) {
203
+ _this.props.onClick();
204
+ }
205
+ }
206
+ }
207
+ },
208
+ onDoubleClick: function () {
209
+ if (_this.props.onDoubleClick) {
210
+ _this.props.onDoubleClick();
211
+ }
212
+ },
213
+ }); } },
203
214
  React.createElement("div", { className: 'table-list__item-border', style: { backgroundColor: this.props.hexColor } }),
204
215
  React.createElement("div", { className: 'table-list__item-content' },
205
216
  React.createElement("div", { className: 'table-list__item-content-block' }, this.props.start && this.props.start),
206
217
  React.createElement("div", { className: 'table-list__item-content-block table-list__item-content-block--center' }, this.props.center && this.props.center),
207
218
  React.createElement("div", { className: 'table-list__item-content-block' }, this.props.end && this.props.end)),
208
- this.props.action &&
209
- React.createElement("div", { className: 'table-list__slide-in-actions', onClick: this.onActionMenuClick }, this.props.action)),
210
- React.createElement("div", { className: 'table-list__add-bar-container' },
211
- React.createElement(Tooltip_1.Tooltip, { text: 'Add item', flow: 'top', appendToBody: true },
212
- React.createElement("div", { className: 'table-list__add-bar' },
213
- React.createElement(Dropdown_1.Dropdown, { onChange: this.props.onAddItem, items: this.props.itemsDropdown ? this.props.itemsDropdown() : [] },
214
- React.createElement(Button_1.Button, { type: "primary", icon: "plus-large", text: "Add item", size: "small", shape: "round", iconOnly: true, onClick: function () { return false; } }))))))
215
- : React.createElement("div", { role: 'listitem', className: "".concat(classes, " table-list__item--margin"), onClick: function () { return _this.onSingleClick(); }, onDoubleClick: function () { return _this.onDoubleClick(); } },
216
- React.createElement("div", { className: 'table-list__item-border', style: { backgroundColor: this.props.hexColor } }),
217
- React.createElement("div", { className: 'table-list__item-content' },
218
- React.createElement("div", { className: 'table-list__item-content-block' }, this.props.start && this.props.start),
219
- React.createElement("div", { className: 'table-list__item-content-block table-list__item-content-block--center' }, this.props.center && this.props.center),
220
- React.createElement("div", { className: 'table-list__item-content-block' }, this.props.end && this.props.end)),
221
- this.props.action &&
222
- React.createElement("div", { className: 'table-list__slide-in-actions', onClick: this.onActionMenuClick }, this.props.action)));
219
+ this.props.action
220
+ && React.createElement("div", { className: 'table-list__slide-in-actions', onClick: this.onActionMenuClick }, this.props.action)),
221
+ this.props.addItem
222
+ && React.createElement("div", { className: 'table-list__add-bar-container' },
223
+ React.createElement(Tooltip_1.Tooltip, { text: 'Add item', flow: 'top', appendToBody: true },
224
+ React.createElement("div", { className: 'table-list__add-bar' },
225
+ React.createElement(Dropdown_1.Dropdown, { onChange: this.props.onAddItem, items: this.props.itemsDropdown ? this.props.itemsDropdown() : [] },
226
+ React.createElement(Button_1.Button, { type: "primary", icon: "plus-large", text: "Add item", size: "small", shape: "round", iconOnly: true, onClick: function () { return false; } }))))))));
223
227
  };
224
228
  return TableListItem;
225
229
  }(React.PureComponent));
@@ -235,7 +239,9 @@ var PortalItem = /** @class */ (function (_super) {
235
239
  var snapshot = this.props.snapshot;
236
240
  var usePortal = snapshot.isDragging;
237
241
  var child = (React.createElement("div", __assign({ ref: provided.innerRef }, provided.draggableProps, provided.dragHandleProps),
238
- React.createElement(TableListItem, { dragAndDrop: this.props.dragAndDrop, start: this.props.item.start, center: this.props.item.center, end: this.props.item.end, action: this.props.item.action, onClick: this.props.item.onClick ? this.props.item.onClick : undefined, onDoubleClick: this.props.item.onDoubleClick
242
+ React.createElement(TableListItem, { dragAndDrop: this.props.dragAndDrop, start: this.props.item.start, center: this.props.item.center, end: this.props.item.end, action: this.props.item.action, onClick: this.props.item.onClick
243
+ ? this.props.item.onClick
244
+ : undefined, onDoubleClick: this.props.item.onDoubleClick
239
245
  ? this.props.item.onDoubleClick
240
246
  : undefined, addItem: this.props.addItem, itemsDropdown: this.props.itemsDropdown, hexColor: this.props.item.hexColor, locked: this.props.item.locked, positionLocked: this.props.item.positionLocked, onAddItem: function () { return _this.props.onAddItem; }, showDragHandle: this.props.showDragHandle })));
241
247
  if (!usePortal) {
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export interface ICallbacks {
3
+ onSingleClick: (event: React.MouseEvent) => void;
4
+ onDoubleClick: (event: React.MouseEvent) => void;
5
+ }
6
+ export declare function setupSingleAndDoubleClick(): (event: React.MouseEvent, cb: ICallbacks) => void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupSingleAndDoubleClick = void 0;
4
+ function setupSingleAndDoubleClick() {
5
+ var timer;
6
+ var delay;
7
+ return function (event, cb) {
8
+ clearTimeout(timer);
9
+ if (event.nativeEvent.detail === 1) {
10
+ timer = window.setTimeout(function () {
11
+ cb.onSingleClick(event);
12
+ }, delay);
13
+ }
14
+ else if (event.nativeEvent.detail === 2) {
15
+ cb.onDoubleClick(event);
16
+ }
17
+ };
18
+ }
19
+ exports.setupSingleAndDoubleClick = setupSingleAndDoubleClick;