@mirrormedia/lilith-draft-editor 1.1.0-alpha.21 → 1.1.0-alpha.23

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.
@@ -6,12 +6,18 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.SlideshowEditBlock = SlideshowEditBlock;
7
7
  exports.SlideshowEditBlockV2 = SlideshowEditBlockV2;
8
8
 
9
- var _react = _interopRequireDefault(require("react"));
9
+ var _react = _interopRequireWildcard(require("react"));
10
10
 
11
11
  var _styledComponents = _interopRequireDefault(require("styled-components"));
12
12
 
13
+ var _imageSelector = require("../selector/image-selector");
14
+
13
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
16
 
17
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
+
19
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+
15
21
  const Image = _styledComponents.default.img`
16
22
  width: 100%;
17
23
  `;
@@ -36,11 +42,24 @@ const Figure = _styledComponents.default.figure`
36
42
  margin-block: unset;
37
43
  margin-inline: unset;
38
44
  margin: 0 10px;
39
- `; // support old version of slideshow without delay propertiy
45
+ `;
46
+ const SlideshowEditButton = _styledComponents.default.span`
47
+ cursor: pointer;
48
+ background-color: white;
49
+ padding: 6px;
50
+ border-radius: 6px;
51
+ `;
40
52
 
41
- function SlideshowEditBlock(entity) {
53
+ // support old version of slideshow without delay propertiy
54
+ function SlideshowEditBlock(props) {
42
55
  var _images$, _images$$resized;
43
56
 
57
+ const {
58
+ block,
59
+ contentState
60
+ } = props;
61
+ const entityKey = block.getEntityAt(0);
62
+ const entity = contentState.getEntity(entityKey);
44
63
  const images = entity.getData();
45
64
  return /*#__PURE__*/_react.default.createElement(Figure, null, /*#__PURE__*/_react.default.createElement(Image, {
46
65
  src: images === null || images === void 0 ? void 0 : (_images$ = images[0]) === null || _images$ === void 0 ? void 0 : (_images$$resized = _images$.resized) === null || _images$$resized === void 0 ? void 0 : _images$$resized.original,
@@ -53,19 +72,79 @@ function SlideshowEditBlock(entity) {
53
72
  } // 202206 latest version of slideshow, support delay property
54
73
 
55
74
 
56
- function SlideshowEditBlockV2(entity) {
75
+ function SlideshowEditBlockV2(props) {
57
76
  var _images$3, _images$3$resized;
58
77
 
78
+ const {
79
+ block,
80
+ blockProps,
81
+ contentState
82
+ } = props;
83
+ const {
84
+ onEditStart,
85
+ onEditFinish
86
+ } = blockProps;
87
+ const entityKey = block.getEntityAt(0);
88
+ const entity = contentState.getEntity(entityKey);
59
89
  const {
60
90
  images,
61
91
  delay
62
92
  } = entity.getData();
63
- return /*#__PURE__*/_react.default.createElement(Figure, null, /*#__PURE__*/_react.default.createElement(Image, {
93
+ const initialSelected = images.map(image => ({
94
+ desc: image.desc,
95
+ image: {
96
+ id: image.id,
97
+ name: image.name,
98
+ imageFile: image.imageFile,
99
+ resized: image.resized,
100
+ resizedWebp: image.resizedWebp
101
+ }
102
+ }));
103
+ const [toShowImageSelector, setToShowImageSelector] = (0, _react.useState)(false);
104
+
105
+ const onImageSelectorChange = (selected, align, delay) => {
106
+ if (selected.length === 0) {
107
+ onEditFinish({});
108
+ } else {
109
+ onEditFinish({
110
+ entityKey,
111
+ entityData: {
112
+ alignment: align,
113
+ delay,
114
+ images: selected.map(ele => {
115
+ return { ...(ele === null || ele === void 0 ? void 0 : ele.image),
116
+ desc: ele === null || ele === void 0 ? void 0 : ele.desc
117
+ };
118
+ })
119
+ }
120
+ });
121
+ }
122
+
123
+ setToShowImageSelector(false);
124
+ };
125
+
126
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowImageSelector && /*#__PURE__*/_react.default.createElement(_imageSelector.ImageSelector, {
127
+ onChange: onImageSelectorChange,
128
+ enableCaption: true,
129
+ enableDelay: true,
130
+ enableMultiSelect: true,
131
+ initialSelected: initialSelected,
132
+ initialDelay: delay
133
+ }), /*#__PURE__*/_react.default.createElement(Figure, null, /*#__PURE__*/_react.default.createElement(Image, {
64
134
  src: images === null || images === void 0 ? void 0 : (_images$3 = images[0]) === null || _images$3 === void 0 ? void 0 : (_images$3$resized = _images$3.resized) === null || _images$3$resized === void 0 ? void 0 : _images$3$resized.original,
65
135
  onError: e => {
66
136
  var _images$4, _images$4$imageFile;
67
137
 
68
138
  return e.currentTarget.src = images === null || images === void 0 ? void 0 : (_images$4 = images[0]) === null || _images$4 === void 0 ? void 0 : (_images$4$imageFile = _images$4.imageFile) === null || _images$4$imageFile === void 0 ? void 0 : _images$4$imageFile.url;
69
139
  }
70
- }), /*#__PURE__*/_react.default.createElement(SlideshowCount, null, /*#__PURE__*/_react.default.createElement("div", null, "+", images.length), delay && /*#__PURE__*/_react.default.createElement("div", null, `${delay}s`)));
140
+ }), /*#__PURE__*/_react.default.createElement(SlideshowCount, null, /*#__PURE__*/_react.default.createElement("div", null, "+", images.length), delay && /*#__PURE__*/_react.default.createElement("div", null, `${delay}s`))), /*#__PURE__*/_react.default.createElement(SlideshowEditButton, {
141
+ onClick: () => {
142
+ // call `onEditStart` prop as we are trying to update the BGImage entity
143
+ onEditStart(); // open `BGImageInput`
144
+
145
+ setToShowImageSelector(true);
146
+ }
147
+ }, /*#__PURE__*/_react.default.createElement("i", {
148
+ className: "fa-solid fa-pen"
149
+ }), /*#__PURE__*/_react.default.createElement("span", null, "Modify")));
71
150
  }
@@ -55,12 +55,12 @@ const AtomicBlock = props => {
55
55
 
56
56
  case 'slideshow':
57
57
  {
58
- return (0, _slideshowBlock.SlideshowEditBlock)(entity);
58
+ return (0, _slideshowBlock.SlideshowEditBlock)(props);
59
59
  }
60
60
 
61
61
  case 'slideshow-v2':
62
62
  {
63
- return (0, _slideshowBlock.SlideshowEditBlockV2)(entity);
63
+ return (0, _slideshowBlock.SlideshowEditBlockV2)(props);
64
64
  }
65
65
 
66
66
  case 'EMBEDDEDCODE':
@@ -145,6 +145,7 @@ const AudiosQuery = (0, _apollo.gql)`
145
145
  audioFilesCount(where: { name: { contains: $searchText } })
146
146
  audioFiles(
147
147
  where: { name: { contains: $searchText } }
148
+ orderBy: { createdAt: desc }
148
149
  take: $take
149
150
  skip: $skip
150
151
  ) {
@@ -34,6 +34,7 @@ const imagesQuery = (0, _apollo.gql)`
34
34
  photosCount(where: { name: { contains: $searchText } })
35
35
  photos(
36
36
  where: { name: { contains: $searchText } }
37
+ orderBy: { createdAt: desc }
37
38
  take: $take
38
39
  skip: $skip
39
40
  ) {
@@ -130,7 +131,7 @@ function ImageGrids(props) {
130
131
  return /*#__PURE__*/_react.default.createElement(ImageGridsWrapper, null, images.map(image => {
131
132
  return /*#__PURE__*/_react.default.createElement(ImageGrid, {
132
133
  key: image.id,
133
- isSelected: selected === null || selected === void 0 ? void 0 : selected.includes(image),
134
+ isSelected: !!(selected !== null && selected !== void 0 && selected.find(selectedImage => selectedImage.id === image.id)),
134
135
  onSelect: () => onSelect(image),
135
136
  image: image
136
137
  });
@@ -258,8 +259,10 @@ function ImageSelector(props) {
258
259
  enableDelay = false,
259
260
  onChange,
260
261
  initialSelected = [],
261
- initialAlign
262
+ initialAlign,
263
+ initialDelay
262
264
  } = props;
265
+ console.log(imagesQuery);
263
266
  const [queryImages, {
264
267
  loading,
265
268
  error,
@@ -274,7 +277,7 @@ function ImageSelector(props) {
274
277
 
275
278
  const [searchText, setSearchText] = (0, _react.useState)('');
276
279
  const [selected, setSelected] = (0, _react.useState)(initialSelected);
277
- const [delay, setDelay] = (0, _react.useState)('5');
280
+ const [delay, setDelay] = (0, _react.useState)(initialDelay ?? '5');
278
281
  const [align, setAlign] = (0, _react.useState)(initialAlign);
279
282
  const contentWrapperRef = (0, _react.useRef)();
280
283
  const pageSize = 6;
@@ -28,6 +28,7 @@ const postsQuery = (0, _apollo.gql)`
28
28
  postsCount(where: { title: { contains: $searchText } })
29
29
  posts(
30
30
  where: { title: { contains: $searchText } }
31
+ orderBy: { createdAt: desc }
31
32
  take: $take
32
33
  skip: $skip
33
34
  ) {
@@ -28,6 +28,7 @@ const videosQuery = (0, _apollo.gql)`
28
28
  videosCount(where: { name: { contains: $searchText } })
29
29
  videos(
30
30
  where: { name: { contains: $searchText } }
31
+ orderBy: { createdAt: desc }
31
32
  take: $take
32
33
  skip: $skip
33
34
  ) {
@@ -145,6 +145,7 @@ const AudiosQuery = (0, _apollo.gql)`
145
145
  audioFilesCount(where: { name: { contains: $searchText } })
146
146
  audioFiles(
147
147
  where: { name: { contains: $searchText } }
148
+ orderBy: { createdAt: desc }
148
149
  take: $take
149
150
  skip: $skip
150
151
  ) {
@@ -34,6 +34,7 @@ const imagesQuery = (0, _apollo.gql)`
34
34
  photosCount(where: { name: { contains: $searchText } })
35
35
  photos(
36
36
  where: { name: { contains: $searchText } }
37
+ orderBy: { createdAt: desc }
37
38
  take: $take
38
39
  skip: $skip
39
40
  ) {
@@ -28,6 +28,7 @@ const postsQuery = (0, _apollo.gql)`
28
28
  postsCount(where: { name: { contains: $searchText } })
29
29
  posts(
30
30
  where: { name: { contains: $searchText } }
31
+ orderBy: { createdAt: desc }
31
32
  take: $take
32
33
  skip: $skip
33
34
  ) {
@@ -28,6 +28,7 @@ const videosQuery = (0, _apollo.gql)`
28
28
  videosCount(where: { name: { contains: $searchText } })
29
29
  videos(
30
30
  where: { name: { contains: $searchText } }
31
+ orderBy: { createdAt: desc }
31
32
  take: $take
32
33
  skip: $skip
33
34
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirrormedia/lilith-draft-editor",
3
- "version": "1.1.0-alpha.21",
3
+ "version": "1.1.0-alpha.23",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -23,7 +23,7 @@
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
25
  "draft-js": "^0.11.7",
26
- "@mirrormedia/lilith-draft-renderer": "1.3.0-alpha.3"
26
+ "@mirrormedia/lilith-draft-renderer": "1.3.0-alpha.5"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": "18.2.0",