@elliemae/ds-imagelibrarymodal 2.3.0-alpha.8 → 2.3.0-next.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/cjs/DSImageLibraryModal.js +64 -0
- package/cjs/components/ImageLibraryModalImpl.js +254 -0
- package/cjs/index.js +7 -0
- package/esm/DSImageLibraryModal.js +57 -0
- package/esm/components/ImageLibraryModalImpl.js +242 -0
- package/esm/index.js +1 -0
- package/package.json +25 -27
- package/types/DSImageLibraryModal.d.ts +35 -0
- package/types/components/ImageLibraryModalImpl.d.ts +16 -0
- package/types/index.d.ts +1 -0
- package/dist/cjs/DSImageLibraryModal.js +0 -83
- package/dist/cjs/DSImageLibraryModal.js.map +0 -7
- package/dist/cjs/components/ImageLibraryModalImpl.js +0 -188
- package/dist/cjs/components/ImageLibraryModalImpl.js.map +0 -7
- package/dist/cjs/index.js +0 -35
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/DSImageLibraryModal.js +0 -54
- package/dist/esm/DSImageLibraryModal.js.map +0 -7
- package/dist/esm/components/ImageLibraryModalImpl.js +0 -159
- package/dist/esm/components/ImageLibraryModalImpl.js.map +0 -7
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -7
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
4
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
5
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
9
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
10
|
+
require('react');
|
|
11
|
+
var DSModal = require('@elliemae/ds-modal');
|
|
12
|
+
var constants = require('@elliemae/ds-shared/constants');
|
|
13
|
+
var ImageLibraryModalImpl = require('./components/ImageLibraryModalImpl.js');
|
|
14
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
|
+
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
+
|
|
18
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
19
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
20
|
+
|
|
21
|
+
const _excluded = ["containerProps", "confirmLabel", "disableDoubleClick", "isOpen", "modalTitle", "modalType", "rejectLabel", "shouldCloseOnOverlayClick", "size", "imagesData", "onSelect"];
|
|
22
|
+
|
|
23
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
24
|
+
|
|
25
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
26
|
+
const modalTypes = Object.values(DSModal.MODAL_TYPE);
|
|
27
|
+
|
|
28
|
+
const DSImageLibraryModal = _ref => {
|
|
29
|
+
let {
|
|
30
|
+
containerProps = {},
|
|
31
|
+
confirmLabel = 'Add',
|
|
32
|
+
disableDoubleClick = false,
|
|
33
|
+
isOpen = true,
|
|
34
|
+
modalTitle = 'Add Image',
|
|
35
|
+
modalType = modalTypes[2],
|
|
36
|
+
rejectLabel = 'Cancel',
|
|
37
|
+
shouldCloseOnOverlayClick = true,
|
|
38
|
+
size = constants.sizeOptions[3],
|
|
39
|
+
imagesData = [{
|
|
40
|
+
url: 'https://www.freeiconspng.com/minicovers/no-image-icon-6.png',
|
|
41
|
+
name: 'no image',
|
|
42
|
+
createdBy: 'user:John Doe',
|
|
43
|
+
createdDate: '0000-01-01 00:00 AM UTC'
|
|
44
|
+
}],
|
|
45
|
+
onSelect = () => null
|
|
46
|
+
} = _ref,
|
|
47
|
+
rest = _objectWithoutProperties__default["default"](_ref, _excluded);
|
|
48
|
+
|
|
49
|
+
return /*#__PURE__*/jsxRuntime.jsx(ImageLibraryModalImpl, _objectSpread({
|
|
50
|
+
confirmLabel: confirmLabel,
|
|
51
|
+
containerProps: containerProps,
|
|
52
|
+
disableDoubleClick: disableDoubleClick,
|
|
53
|
+
imagesData: imagesData,
|
|
54
|
+
isOpen: isOpen,
|
|
55
|
+
modalTitle: modalTitle,
|
|
56
|
+
modalType: modalType,
|
|
57
|
+
onSelect: onSelect,
|
|
58
|
+
rejectLabel: rejectLabel,
|
|
59
|
+
shouldCloseOnOverlayClick: shouldCloseOnOverlayClick,
|
|
60
|
+
size: size
|
|
61
|
+
}, rest));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports = DSImageLibraryModal;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
5
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
11
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
12
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var DSModal = require('@elliemae/ds-modal');
|
|
15
|
+
var DSSpinner = require('@elliemae/ds-spinner');
|
|
16
|
+
var dsIcon = require('@elliemae/ds-icon');
|
|
17
|
+
var lodash = require('lodash');
|
|
18
|
+
var ImageLoader = require('react-loading-image');
|
|
19
|
+
var dsIcons = require('@elliemae/ds-icons');
|
|
20
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
21
|
+
|
|
22
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
|
+
|
|
24
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
25
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
26
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
27
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
28
|
+
var DSModal__default = /*#__PURE__*/_interopDefaultLegacy(DSModal);
|
|
29
|
+
var DSSpinner__default = /*#__PURE__*/_interopDefaultLegacy(DSSpinner);
|
|
30
|
+
var ImageLoader__default = /*#__PURE__*/_interopDefaultLegacy(ImageLoader);
|
|
31
|
+
|
|
32
|
+
const _excluded = ["containerProps", "imagesData", "onSelect", "disableDoubleClick"];
|
|
33
|
+
|
|
34
|
+
var _DSSpinner;
|
|
35
|
+
|
|
36
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
|
|
38
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
+
const elementClassName = 'imglibmodal-element';
|
|
40
|
+
class ImageLibraryModalImpl extends React__default["default"].PureComponent {
|
|
41
|
+
constructor(props) {
|
|
42
|
+
super(props);
|
|
43
|
+
|
|
44
|
+
this.onReject = () => {
|
|
45
|
+
const {
|
|
46
|
+
onReject,
|
|
47
|
+
onClose
|
|
48
|
+
} = this.props;
|
|
49
|
+
|
|
50
|
+
if (onReject) {
|
|
51
|
+
onReject();
|
|
52
|
+
} else {
|
|
53
|
+
onClose();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this.handleElementClick = (e, image) => {
|
|
58
|
+
if (e.key && e.key !== ' ') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const {
|
|
63
|
+
selected
|
|
64
|
+
} = this.state;
|
|
65
|
+
const {
|
|
66
|
+
disableDoubleClick,
|
|
67
|
+
onConfirm,
|
|
68
|
+
onSelect
|
|
69
|
+
} = this.props;
|
|
70
|
+
|
|
71
|
+
if (image === selected && onConfirm && !disableDoubleClick) {
|
|
72
|
+
onConfirm();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.setState({
|
|
77
|
+
selected: image,
|
|
78
|
+
user: this.getUser(image)
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (onSelect) {
|
|
82
|
+
onSelect(image);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
this.renderElements = () => {
|
|
87
|
+
const {
|
|
88
|
+
imagesData
|
|
89
|
+
} = this.props;
|
|
90
|
+
|
|
91
|
+
if (!imagesData) {
|
|
92
|
+
return 'Empty';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const {
|
|
96
|
+
selected
|
|
97
|
+
} = this.state;
|
|
98
|
+
return imagesData.map((image, idx) => {
|
|
99
|
+
const extras = {};
|
|
100
|
+
const {
|
|
101
|
+
name,
|
|
102
|
+
id
|
|
103
|
+
} = image;
|
|
104
|
+
|
|
105
|
+
if (this.focusFirst && idx === 0) {
|
|
106
|
+
extras.ref = element => element && element.focus();
|
|
107
|
+
|
|
108
|
+
this.focusFirst = undefined;
|
|
109
|
+
} else if (selected && name === selected.name) {
|
|
110
|
+
extras.ref = element => element && element.focus();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
|
|
114
|
+
className: elementClassName,
|
|
115
|
+
onClick: e => this.handleElementClick(e, image),
|
|
116
|
+
onKeyUp: e => this.handleElementClick(e, image),
|
|
117
|
+
role: "button",
|
|
118
|
+
tabIndex: 0
|
|
119
|
+
}, extras), {}, {
|
|
120
|
+
children: /*#__PURE__*/_jsx__default["default"]("div", {
|
|
121
|
+
className: "content"
|
|
122
|
+
}, void 0, name)
|
|
123
|
+
}), id || "".concat(name, "_").concat(idx));
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
this.renderSpinner = () => _DSSpinner || (_DSSpinner = /*#__PURE__*/_jsx__default["default"](DSSpinner__default["default"], {
|
|
128
|
+
message: "Loading...",
|
|
129
|
+
size: "m"
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
this.renderError = () => /*#__PURE__*/_jsx__default["default"](dsIcons.ImageMissing, {
|
|
133
|
+
color: dsIcon.DSIconColors.NEUTRAL,
|
|
134
|
+
size: dsIcon.DSIconSizes.M
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
this.state = {
|
|
138
|
+
selected: undefined,
|
|
139
|
+
user: undefined
|
|
140
|
+
};
|
|
141
|
+
this.preventSpacebarScroll();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
componentDidMount() {
|
|
145
|
+
const {
|
|
146
|
+
imagesData
|
|
147
|
+
} = this.props;
|
|
148
|
+
|
|
149
|
+
if (imagesData) {
|
|
150
|
+
this.handleElementClick({}, imagesData[0]);
|
|
151
|
+
this.focusFirst = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getDerivedStateFromProps(nextProps) {
|
|
156
|
+
const {
|
|
157
|
+
imagesData
|
|
158
|
+
} = this.props;
|
|
159
|
+
|
|
160
|
+
if (!imagesData && nextProps.imagesData) {
|
|
161
|
+
this.setState({
|
|
162
|
+
selected: imagesData[0]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
getUser(selected) {
|
|
168
|
+
if (!selected) {
|
|
169
|
+
return '';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const index = selected.createdBy.lastIndexOf('user:');
|
|
173
|
+
|
|
174
|
+
if (index === -1) {
|
|
175
|
+
return selected.createdBy;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return selected.createdBy.substring(index + 5);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
preventSpacebarScroll() {
|
|
182
|
+
document.onkeypress = function (e) {
|
|
183
|
+
if (!lodash.includes(e.target.className, elementClassName)) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
e = e || window.event;
|
|
188
|
+
const charCode = e.keyCode || e.which;
|
|
189
|
+
|
|
190
|
+
if (charCode === 32) {
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return true;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
drawDiv(className, content) {
|
|
200
|
+
return /*#__PURE__*/_jsx__default["default"]("div", {
|
|
201
|
+
className: className
|
|
202
|
+
}, void 0, content);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
drawLabel(className, label, value) {
|
|
206
|
+
return /*#__PURE__*/_jsx__default["default"]("div", {
|
|
207
|
+
className: className
|
|
208
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"]("span", {
|
|
209
|
+
className: "label"
|
|
210
|
+
}, void 0, label), /*#__PURE__*/_jsx__default["default"]("span", {
|
|
211
|
+
className: "value"
|
|
212
|
+
}, void 0, value));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
render() {
|
|
216
|
+
const {
|
|
217
|
+
selected,
|
|
218
|
+
user
|
|
219
|
+
} = this.state;
|
|
220
|
+
|
|
221
|
+
const _this$props = this.props,
|
|
222
|
+
{
|
|
223
|
+
containerProps,
|
|
224
|
+
imagesData,
|
|
225
|
+
onSelect,
|
|
226
|
+
disableDoubleClick
|
|
227
|
+
} = _this$props,
|
|
228
|
+
modalProps = _objectWithoutProperties__default["default"](_this$props, _excluded);
|
|
229
|
+
|
|
230
|
+
return /*#__PURE__*/jsxRuntime.jsx(DSModal__default["default"], _objectSpread(_objectSpread({
|
|
231
|
+
containerProps: containerProps
|
|
232
|
+
}, modalProps), {}, {
|
|
233
|
+
className: "em-ds-modal-image-library",
|
|
234
|
+
onReject: this.onReject,
|
|
235
|
+
children: /*#__PURE__*/_jsx__default["default"]("div", {
|
|
236
|
+
className: "wrapper"
|
|
237
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"]("div", {
|
|
238
|
+
className: "col-1"
|
|
239
|
+
}, void 0, this.drawDiv('title', 'Company Images'), this.renderElements()), /*#__PURE__*/_jsx__default["default"]("div", {
|
|
240
|
+
className: "col-2"
|
|
241
|
+
}, void 0, this.drawDiv('title', selected ? selected.name : ''), /*#__PURE__*/_jsx__default["default"](ImageLoader__default["default"], {
|
|
242
|
+
className: "image-loader",
|
|
243
|
+
error: this.renderError,
|
|
244
|
+
loading: this.renderSpinner,
|
|
245
|
+
src: selected ? selected.url : ''
|
|
246
|
+
}), selected && /*#__PURE__*/_jsx__default["default"]("div", {
|
|
247
|
+
className: "info"
|
|
248
|
+
}, void 0, this.drawLabel('info-element', 'Created Date:', selected.createdDate), this.drawLabel('info-element', 'Created By:', user))))
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
module.exports = ImageLibraryModalImpl;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
8
|
+
import 'react';
|
|
9
|
+
import { MODAL_TYPE } from '@elliemae/ds-modal';
|
|
10
|
+
import { sizeOptions } from '@elliemae/ds-shared/constants';
|
|
11
|
+
import ImageLibraryModalImpl from './components/ImageLibraryModalImpl.js';
|
|
12
|
+
import { jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
const _excluded = ["containerProps", "confirmLabel", "disableDoubleClick", "isOpen", "modalTitle", "modalType", "rejectLabel", "shouldCloseOnOverlayClick", "size", "imagesData", "onSelect"];
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
+
const modalTypes = Object.values(MODAL_TYPE);
|
|
20
|
+
|
|
21
|
+
const DSImageLibraryModal = _ref => {
|
|
22
|
+
let {
|
|
23
|
+
containerProps = {},
|
|
24
|
+
confirmLabel = 'Add',
|
|
25
|
+
disableDoubleClick = false,
|
|
26
|
+
isOpen = true,
|
|
27
|
+
modalTitle = 'Add Image',
|
|
28
|
+
modalType = modalTypes[2],
|
|
29
|
+
rejectLabel = 'Cancel',
|
|
30
|
+
shouldCloseOnOverlayClick = true,
|
|
31
|
+
size = sizeOptions[3],
|
|
32
|
+
imagesData = [{
|
|
33
|
+
url: 'https://www.freeiconspng.com/minicovers/no-image-icon-6.png',
|
|
34
|
+
name: 'no image',
|
|
35
|
+
createdBy: 'user:John Doe',
|
|
36
|
+
createdDate: '0000-01-01 00:00 AM UTC'
|
|
37
|
+
}],
|
|
38
|
+
onSelect = () => null
|
|
39
|
+
} = _ref,
|
|
40
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
41
|
+
|
|
42
|
+
return /*#__PURE__*/jsx(ImageLibraryModalImpl, _objectSpread({
|
|
43
|
+
confirmLabel: confirmLabel,
|
|
44
|
+
containerProps: containerProps,
|
|
45
|
+
disableDoubleClick: disableDoubleClick,
|
|
46
|
+
imagesData: imagesData,
|
|
47
|
+
isOpen: isOpen,
|
|
48
|
+
modalTitle: modalTitle,
|
|
49
|
+
modalType: modalType,
|
|
50
|
+
onSelect: onSelect,
|
|
51
|
+
rejectLabel: rejectLabel,
|
|
52
|
+
shouldCloseOnOverlayClick: shouldCloseOnOverlayClick,
|
|
53
|
+
size: size
|
|
54
|
+
}, rest));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { DSImageLibraryModal as default };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
3
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
6
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
8
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
9
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
10
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import DSModal from '@elliemae/ds-modal';
|
|
13
|
+
import DSSpinner from '@elliemae/ds-spinner';
|
|
14
|
+
import { DSIconColors, DSIconSizes } from '@elliemae/ds-icon';
|
|
15
|
+
import { includes } from 'lodash';
|
|
16
|
+
import ImageLoader from 'react-loading-image';
|
|
17
|
+
import { ImageMissing } from '@elliemae/ds-icons';
|
|
18
|
+
import { jsx } from 'react/jsx-runtime';
|
|
19
|
+
|
|
20
|
+
const _excluded = ["containerProps", "imagesData", "onSelect", "disableDoubleClick"];
|
|
21
|
+
|
|
22
|
+
var _DSSpinner;
|
|
23
|
+
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
+
const elementClassName = 'imglibmodal-element';
|
|
28
|
+
class ImageLibraryModalImpl extends React.PureComponent {
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
|
|
32
|
+
this.onReject = () => {
|
|
33
|
+
const {
|
|
34
|
+
onReject,
|
|
35
|
+
onClose
|
|
36
|
+
} = this.props;
|
|
37
|
+
|
|
38
|
+
if (onReject) {
|
|
39
|
+
onReject();
|
|
40
|
+
} else {
|
|
41
|
+
onClose();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
this.handleElementClick = (e, image) => {
|
|
46
|
+
if (e.key && e.key !== ' ') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const {
|
|
51
|
+
selected
|
|
52
|
+
} = this.state;
|
|
53
|
+
const {
|
|
54
|
+
disableDoubleClick,
|
|
55
|
+
onConfirm,
|
|
56
|
+
onSelect
|
|
57
|
+
} = this.props;
|
|
58
|
+
|
|
59
|
+
if (image === selected && onConfirm && !disableDoubleClick) {
|
|
60
|
+
onConfirm();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.setState({
|
|
65
|
+
selected: image,
|
|
66
|
+
user: this.getUser(image)
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (onSelect) {
|
|
70
|
+
onSelect(image);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
this.renderElements = () => {
|
|
75
|
+
const {
|
|
76
|
+
imagesData
|
|
77
|
+
} = this.props;
|
|
78
|
+
|
|
79
|
+
if (!imagesData) {
|
|
80
|
+
return 'Empty';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
selected
|
|
85
|
+
} = this.state;
|
|
86
|
+
return imagesData.map((image, idx) => {
|
|
87
|
+
const extras = {};
|
|
88
|
+
const {
|
|
89
|
+
name,
|
|
90
|
+
id
|
|
91
|
+
} = image;
|
|
92
|
+
|
|
93
|
+
if (this.focusFirst && idx === 0) {
|
|
94
|
+
extras.ref = element => element && element.focus();
|
|
95
|
+
|
|
96
|
+
this.focusFirst = undefined;
|
|
97
|
+
} else if (selected && name === selected.name) {
|
|
98
|
+
extras.ref = element => element && element.focus();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
|
|
102
|
+
className: elementClassName,
|
|
103
|
+
onClick: e => this.handleElementClick(e, image),
|
|
104
|
+
onKeyUp: e => this.handleElementClick(e, image),
|
|
105
|
+
role: "button",
|
|
106
|
+
tabIndex: 0
|
|
107
|
+
}, extras), {}, {
|
|
108
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
109
|
+
className: "content"
|
|
110
|
+
}, void 0, name)
|
|
111
|
+
}), id || "".concat(name, "_").concat(idx));
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.renderSpinner = () => _DSSpinner || (_DSSpinner = /*#__PURE__*/_jsx(DSSpinner, {
|
|
116
|
+
message: "Loading...",
|
|
117
|
+
size: "m"
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
this.renderError = () => /*#__PURE__*/_jsx(ImageMissing, {
|
|
121
|
+
color: DSIconColors.NEUTRAL,
|
|
122
|
+
size: DSIconSizes.M
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
this.state = {
|
|
126
|
+
selected: undefined,
|
|
127
|
+
user: undefined
|
|
128
|
+
};
|
|
129
|
+
this.preventSpacebarScroll();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
componentDidMount() {
|
|
133
|
+
const {
|
|
134
|
+
imagesData
|
|
135
|
+
} = this.props;
|
|
136
|
+
|
|
137
|
+
if (imagesData) {
|
|
138
|
+
this.handleElementClick({}, imagesData[0]);
|
|
139
|
+
this.focusFirst = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getDerivedStateFromProps(nextProps) {
|
|
144
|
+
const {
|
|
145
|
+
imagesData
|
|
146
|
+
} = this.props;
|
|
147
|
+
|
|
148
|
+
if (!imagesData && nextProps.imagesData) {
|
|
149
|
+
this.setState({
|
|
150
|
+
selected: imagesData[0]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getUser(selected) {
|
|
156
|
+
if (!selected) {
|
|
157
|
+
return '';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const index = selected.createdBy.lastIndexOf('user:');
|
|
161
|
+
|
|
162
|
+
if (index === -1) {
|
|
163
|
+
return selected.createdBy;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return selected.createdBy.substring(index + 5);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
preventSpacebarScroll() {
|
|
170
|
+
document.onkeypress = function (e) {
|
|
171
|
+
if (!includes(e.target.className, elementClassName)) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
e = e || window.event;
|
|
176
|
+
const charCode = e.keyCode || e.which;
|
|
177
|
+
|
|
178
|
+
if (charCode === 32) {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return true;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
drawDiv(className, content) {
|
|
188
|
+
return /*#__PURE__*/_jsx("div", {
|
|
189
|
+
className: className
|
|
190
|
+
}, void 0, content);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
drawLabel(className, label, value) {
|
|
194
|
+
return /*#__PURE__*/_jsx("div", {
|
|
195
|
+
className: className
|
|
196
|
+
}, void 0, /*#__PURE__*/_jsx("span", {
|
|
197
|
+
className: "label"
|
|
198
|
+
}, void 0, label), /*#__PURE__*/_jsx("span", {
|
|
199
|
+
className: "value"
|
|
200
|
+
}, void 0, value));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
render() {
|
|
204
|
+
const {
|
|
205
|
+
selected,
|
|
206
|
+
user
|
|
207
|
+
} = this.state;
|
|
208
|
+
|
|
209
|
+
const _this$props = this.props,
|
|
210
|
+
{
|
|
211
|
+
containerProps,
|
|
212
|
+
imagesData,
|
|
213
|
+
onSelect,
|
|
214
|
+
disableDoubleClick
|
|
215
|
+
} = _this$props,
|
|
216
|
+
modalProps = _objectWithoutProperties(_this$props, _excluded);
|
|
217
|
+
|
|
218
|
+
return /*#__PURE__*/jsx(DSModal, _objectSpread(_objectSpread({
|
|
219
|
+
containerProps: containerProps
|
|
220
|
+
}, modalProps), {}, {
|
|
221
|
+
className: "em-ds-modal-image-library",
|
|
222
|
+
onReject: this.onReject,
|
|
223
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
224
|
+
className: "wrapper"
|
|
225
|
+
}, void 0, /*#__PURE__*/_jsx("div", {
|
|
226
|
+
className: "col-1"
|
|
227
|
+
}, void 0, this.drawDiv('title', 'Company Images'), this.renderElements()), /*#__PURE__*/_jsx("div", {
|
|
228
|
+
className: "col-2"
|
|
229
|
+
}, void 0, this.drawDiv('title', selected ? selected.name : ''), /*#__PURE__*/_jsx(ImageLoader, {
|
|
230
|
+
className: "image-loader",
|
|
231
|
+
error: this.renderError,
|
|
232
|
+
loading: this.renderSpinner,
|
|
233
|
+
src: selected ? selected.url : ''
|
|
234
|
+
}), selected && /*#__PURE__*/_jsx("div", {
|
|
235
|
+
className: "info"
|
|
236
|
+
}, void 0, this.drawLabel('info-element', 'Created Date:', selected.createdDate), this.drawLabel('info-element', 'Created By:', user))))
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { ImageLibraryModalImpl as default };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './DSImageLibraryModal.js';
|