@selfcommunity/react-ui 0.7.0-alpha.320 → 0.7.0-alpha.322

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.
@@ -3,14 +3,6 @@ import { $getNodeByKey, $getSelection, $isNodeSelection, $setSelection, CLICK_CO
3
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
4
  import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
5
5
  import { mergeRegister } from '@lexical/utils';
6
- /**
7
- * Calc aspect-ratio of image
8
- * @param width
9
- * @param height
10
- */
11
- function getAspectRatio(width, height) {
12
- return width / height;
13
- }
14
6
  const imageCache = new Set();
15
7
  function useSuspenseImage(src) {
16
8
  if (!imageCache.has(src)) {
@@ -24,13 +16,15 @@ function useSuspenseImage(src) {
24
16
  });
25
17
  }
26
18
  }
27
- function LazyImage({ altText, className, imageRef, src, width, height }) {
19
+ function LazyImage({ altText, className, imageRef, src, width, height, maxWidth }) {
28
20
  useSuspenseImage(src);
29
- const aspectRatio = getAspectRatio(width, height);
30
- return (React.createElement("div", { draggable: false, className: className, style: { position: 'relative', paddingBottom: `${100 / aspectRatio}%` } },
31
- React.createElement("img", { src: src, alt: altText, ref: imageRef, style: { position: 'absolute', width: '100%' } })));
21
+ return (React.createElement("img", { className: className, src: src, alt: altText, ref: imageRef, style: {
22
+ height: `${height}${height === 'inherit' ? '' : 'px'}`,
23
+ maxWidth,
24
+ width: `${width}${width === 'inherit' ? '' : 'px'}`
25
+ } }));
32
26
  }
33
- function ImageComponent({ src, altText, nodeKey, width, height }) {
27
+ function ImageComponent({ src, altText, nodeKey, width, height, maxWidth }) {
34
28
  const imageRef = useRef(null);
35
29
  const buttonRef = useRef(null);
36
30
  const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
@@ -98,29 +92,30 @@ function ImageComponent({ src, altText, nodeKey, width, height }) {
98
92
  }, [clearSelection, editor, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
99
93
  const isFocused = isSelected;
100
94
  return (React.createElement(Suspense, { fallback: null },
101
- React.createElement(LazyImage, { className: isFocused ? `focused` : null, src: src, altText: altText, imageRef: imageRef, width: width, height: height })));
95
+ React.createElement(LazyImage, { className: isFocused ? `focused` : null, src: src, altText: altText, imageRef: imageRef, width: width, height: height, maxWidth: maxWidth })));
102
96
  }
103
97
  function convertImageElement(domNode) {
104
98
  if (domNode instanceof HTMLImageElement) {
105
99
  const { alt: altText, src, dataset: { width, height } } = domNode;
106
- const node = $createImageNode({ altText, height: Number(height), src, width: Number(width) });
100
+ const node = $createImageNode({ altText, height: Number(height), src, width: Number(width), maxWidth: '100%' });
107
101
  return { node };
108
102
  }
109
103
  return null;
110
104
  }
111
105
  export class ImageNode extends DecoratorNode {
112
- constructor(src, altText, width, height, key) {
106
+ constructor(src, altText, maxWidth, width, height, key) {
113
107
  super(key);
114
108
  this.__src = src;
115
109
  this.__altText = altText;
116
- this.__width = width;
117
- this.__height = height;
110
+ this.__width = width || 'inherit';
111
+ this.__maxWidth = maxWidth;
112
+ this.__height = height || 'inherit';
118
113
  }
119
114
  static getType() {
120
115
  return 'image';
121
116
  }
122
117
  static clone(node) {
123
- return new ImageNode(node.__src, node.__altText, node.__width, node.__height, node.__key);
118
+ return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__key);
124
119
  }
125
120
  setWidthAndHeight(width, height) {
126
121
  const writable = this.getWritable();
@@ -154,44 +149,42 @@ export class ImageNode extends DecoratorNode {
154
149
  }) }, dom);
155
150
  }
156
151
  exportDOM() {
157
- const aspectRatio = getAspectRatio(this.__width, this.__height);
158
- const element = document.createElement('div');
159
- element.setAttribute('style', `position: relative;padding-bottom:${100 / aspectRatio}%`);
160
- const image = document.createElement('img');
161
- image.setAttribute('src', this.__src);
162
- image.setAttribute('alt', this.__altText);
163
- image.setAttribute('style', `position: absolute;width:100%;height:100%;`);
164
- image.setAttribute('data-width', `${this.__width}`);
165
- image.setAttribute('data-height', `${this.__height}`);
166
- element.appendChild(image);
152
+ const element = document.createElement('img');
153
+ element.setAttribute('src', this.__src);
154
+ element.setAttribute('alt', this.__altText);
155
+ element.setAttribute('width', `${this.__width}`);
156
+ element.setAttribute('height', `${this.__height}`);
157
+ element.setAttribute('style', `max-width: ${this.__maxWidth}px;`);
167
158
  return { element };
168
159
  }
169
160
  decorate() {
170
- return React.createElement(ImageComponent, { src: this.__src, altText: this.__altText, width: this.__width, height: this.__height, nodeKey: this.getKey() });
161
+ return (React.createElement(ImageComponent, { src: this.__src, altText: this.__altText, width: this.__width, height: this.__height, maxWidth: this.__maxWidth, nodeKey: this.getKey() }));
171
162
  }
172
163
  static importJSON(serializedNode) {
173
- const { altText, height, width, src } = serializedNode;
164
+ const { altText, height, width, maxWidth, src } = serializedNode;
174
165
  const node = $createImageNode({
175
166
  altText,
176
167
  height,
177
168
  src,
178
- width
169
+ width,
170
+ maxWidth
179
171
  });
180
172
  return node;
181
173
  }
182
174
  exportJSON() {
183
175
  return {
184
176
  altText: this.getAltText(),
185
- height: this.__height,
177
+ height: this.__height === 'inherit' ? 0 : this.__height,
178
+ maxWidth: this.__maxWidth,
186
179
  src: this.getSrc(),
187
180
  type: 'image',
188
181
  version: 1,
189
- width: this.__width
182
+ width: this.__width === 'inherit' ? 0 : this.__width
190
183
  };
191
184
  }
192
185
  }
193
- export function $createImageNode({ src, altText, width, height }) {
194
- return new ImageNode(src, altText, width, height);
186
+ export function $createImageNode({ src, altText, maxWidth, width = null, height = null }) {
187
+ return new ImageNode(src, altText, maxWidth, width, height);
195
188
  }
196
189
  export function $isImageNode(node) {
197
190
  return node.getType() === 'image';
@@ -29,18 +29,11 @@ function Image({ editor, className = '' }) {
29
29
  return file.type.startsWith('image/');
30
30
  };
31
31
  const handleUploadSuccess = (media) => {
32
- const image = media.image_thumbnail
33
- ? media.image_thumbnail
34
- : {
35
- url: media.image,
36
- width: media.image_width,
37
- height: media.image_height
38
- };
39
32
  const data = {
40
33
  altText: media.title,
41
- src: image.url,
42
- width: image.width,
43
- height: image.height
34
+ src: media.image,
35
+ width: media.image_width,
36
+ height: media.image_height
44
37
  };
45
38
  editor.focus();
46
39
  editor.dispatchCommand(INSERT_IMAGE_COMMAND, data);
@@ -93,7 +86,13 @@ export default function ImagePlugin() {
93
86
  if ($isRootNode(selection.anchor.getNode())) {
94
87
  selection.insertParagraph();
95
88
  }
96
- const imageNode = $createImageNode({ src: payload.src, altText: payload.altText, width: payload.width, height: payload.height });
89
+ const imageNode = $createImageNode({
90
+ src: payload.src,
91
+ altText: payload.altText,
92
+ maxWidth: '100%',
93
+ width: payload.width,
94
+ height: payload.height
95
+ });
97
96
  selection.insertNodes([imageNode]);
98
97
  }
99
98
  return true;
@@ -88,7 +88,7 @@ export default function Activities(inProps) {
88
88
  * Render comments of feedObject
89
89
  */
90
90
  function renderComments() {
91
- return (React.createElement(React.Fragment, null, (commentsObject.feedObject.comment_count > 0 || comments.length > 0) && (React.createElement(CommentsObject, Object.assign({ feedObject: commentsObject.feedObject, comments: commentsObject.comments, startComments: comments, next: commentsObject.next, isLoadingNext: commentsObject.isLoadingNext, handleNext: handleNext, totalLoadedComments: commentsObject.comments.length + comments.length, totalComments: commentsObject.feedObject.comment_count, hideAdvertising: true }, CommentsObjectProps, { cacheStrategy: cacheStrategy, CommentsObjectSkeletonProps: { count: skeletonsCount }, CommentComponentProps: Object.assign(Object.assign(Object.assign({}, CommentComponentProps), { cacheStrategy }), (CommentsObjectProps.CommentComponentProps ? CommentsObjectProps.CommentComponentProps : {})) })))));
91
+ return (React.createElement(React.Fragment, null, (commentsObject.feedObject.comment_count > 0 || comments.length > 0) && (React.createElement(CommentsObject, Object.assign({ feedObject: commentsObject.feedObject, comments: commentsObject.comments, startComments: comments, next: commentsObject.next, isLoadingNext: commentsObject.isLoadingNext, handleNext: handleNext, totalLoadedComments: commentsObject.comments.length + comments.length, totalComments: commentsObject.feedObject.comment_count, hideAdvertising: true }, CommentsObjectProps, { cacheStrategy: cacheStrategy, CommentsObjectSkeletonProps: { count: skeletonsCount }, CommentComponentProps: Object.assign(Object.assign(Object.assign({}, CommentComponentProps), { cacheStrategy }), (CommentsObjectProps.CommentComponentProps ? CommentsObjectProps.CommentComponentProps : {})), inPlaceLoadMoreContents: false })))));
92
92
  }
93
93
  /**
94
94
  * Renders root object
@@ -456,7 +456,7 @@ export default function FeedObject(inProps) {
456
456
  template === SCFeedObjectTemplateType.PREVIEW && (obj.comment_count > 0 || (feedObjectActivities && feedObjectActivities.length > 0)) && (React.createElement(Collapse, { in: expandedActivities, timeout: "auto", classes: { root: classes.activitiesSection } },
457
457
  React.createElement(CardContent, { className: classes.activitiesContent },
458
458
  React.createElement(Activities, Object.assign({ feedObject: obj, key: selectedActivities, feedObjectActivities: feedObjectActivities, activitiesType: selectedActivities, onSetSelectedActivities: handleSelectedActivities, comments: comments, CommentsObjectProps: {
459
- CommentComponentProps: Object.assign({ onDelete: handleDeleteComment, truncateContent: false }, CommentComponentProps),
459
+ CommentComponentProps: Object.assign({ onDelete: handleDeleteComment, truncateContent: true }, CommentComponentProps),
460
460
  CommentObjectSkeletonProps: CommentObjectSkeletonProps
461
461
  }, cacheStrategy: cacheStrategy }, ActivitiesProps))))),
462
462
  composerOpen && (React.createElement(Composer, { open: composerOpen, feedObject: obj, onClose: handleToggleEdit, onSuccess: handleEditSuccess, maxWidth: "sm", fullWidth: true, scroll: "body" })))) : (React.createElement(FeedObjectSkeleton, Object.assign({ template: template }, FeedObjectSkeletonProps)))));