@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.
- package/lib/cjs/components/CommentObject/CommentObject.js +1 -1
- package/lib/cjs/components/CommentsObject/CommentsObject.d.ts +5 -0
- package/lib/cjs/components/CommentsObject/CommentsObject.js +21 -7
- package/lib/cjs/components/Composer/Composer.js +1 -1
- package/lib/cjs/components/Editor/nodes/ImageNode.d.ts +11 -8
- package/lib/cjs/components/Editor/nodes/ImageNode.js +29 -36
- package/lib/cjs/components/Editor/plugins/ImagePlugin.js +10 -11
- package/lib/cjs/components/FeedObject/Activities/Activities.js +1 -1
- package/lib/cjs/components/FeedObject/FeedObject.js +1 -1
- package/lib/esm/components/CommentObject/CommentObject.js +1 -1
- package/lib/esm/components/CommentsObject/CommentsObject.d.ts +5 -0
- package/lib/esm/components/CommentsObject/CommentsObject.js +21 -7
- package/lib/esm/components/Composer/Composer.js +1 -1
- package/lib/esm/components/Editor/nodes/ImageNode.d.ts +11 -8
- package/lib/esm/components/Editor/nodes/ImageNode.js +29 -36
- package/lib/esm/components/Editor/plugins/ImagePlugin.js +10 -11
- package/lib/esm/components/FeedObject/Activities/Activities.js +1 -1
- package/lib/esm/components/FeedObject/FeedObject.js +1 -1
- package/lib/umd/react-ui.js +1 -1
- package/package.json +2 -2
|
@@ -362,7 +362,7 @@ function CommentObject(inProps) {
|
|
|
362
362
|
* @param comment
|
|
363
363
|
*/
|
|
364
364
|
function renderLatestComment(comment) {
|
|
365
|
-
return (react_1.default.createElement(CommentsObject_1.default, { feedObject: commentsObject.feedObject, feedObjectType: commentsObject.feedObject ? commentsObject.feedObject.type : feedObjectType, hideAdvertising: true, comments: [].concat(commentsObject.comments).reverse(), endComments: comment.latest_comments, previous: comment.comment_count > comment.latest_comments.length ? commentsObject.next : null, isLoadingPrevious: commentsObject.isLoadingNext, handlePrevious: commentsObject.getNextPage, CommentComponentProps: Object.assign(Object.assign({ onOpenReply: reply, CommentObjectSkeletonProps, elevation: elevation, linkableCommentDateTime: linkableCommentDateTime }, rest), { cacheStrategy }), CommentsObjectSkeletonProps: { count: 1, CommentObjectSkeletonProps: CommentObjectSkeletonProps }, cacheStrategy: cacheStrategy }));
|
|
365
|
+
return (react_1.default.createElement(CommentsObject_1.default, { feedObject: commentsObject.feedObject, feedObjectType: commentsObject.feedObject ? commentsObject.feedObject.type : feedObjectType, hideAdvertising: true, comments: [].concat(commentsObject.comments).reverse(), endComments: comment.latest_comments, previous: comment.comment_count > comment.latest_comments.length ? commentsObject.next : null, isLoadingPrevious: commentsObject.isLoadingNext, handlePrevious: commentsObject.getNextPage, CommentComponentProps: Object.assign(Object.assign({ onOpenReply: reply, CommentObjectSkeletonProps, elevation: elevation, linkableCommentDateTime: linkableCommentDateTime }, rest), { cacheStrategy }), CommentsObjectSkeletonProps: { count: 1, CommentObjectSkeletonProps: CommentObjectSkeletonProps }, cacheStrategy: cacheStrategy, inPlaceLoadMoreContents: true }));
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
368
|
* Render comments
|
|
@@ -110,6 +110,11 @@ export interface CommentsObjectProps {
|
|
|
110
110
|
* @default true
|
|
111
111
|
*/
|
|
112
112
|
hidePaginationLinks?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Load more contents in place
|
|
115
|
+
* rather than opening a new page
|
|
116
|
+
*/
|
|
117
|
+
inPlaceLoadMoreContents?: boolean;
|
|
113
118
|
/**
|
|
114
119
|
* Page query parameter name
|
|
115
120
|
* @default 'page'
|
|
@@ -88,7 +88,7 @@ function CommentsObject(inProps) {
|
|
|
88
88
|
name: PREFIX
|
|
89
89
|
});
|
|
90
90
|
// PROPS
|
|
91
|
-
const { id = `comments_object_${props.feedObjectId ? props.feedObjectId : props.feedObject ? props.feedObject.id : ''}`, className, feedObjectId, feedObject, feedObjectType = types_1.SCContributionType.POST, CommentComponent = CommentObject_1.default, CommentComponentProps = { variant: 'outlined' }, CommentObjectSkeletonProps = { elevation: 0, WidgetProps: { variant: 'outlined' } }, CommentsObjectSkeletonProps = {}, next, isLoadingNext, handleNext, previous, isLoadingPrevious, handlePrevious, totalLoadedComments, totalComments, page, previousPage, nextPage, comments = [], startComments = [], endComments = [], infiniteScrolling = false, hideAdvertising = false, disablePaginationLinks = false, hidePaginationLinks = true, paginationLinksPageQueryParam = Pagination_1.DEFAULT_PAGINATION_QUERY_PARAM_NAME, PaginationLinkProps = {}, cacheStrategy = utils_1.CacheStrategies.NETWORK_ONLY } = props, rest = tslib_1.__rest(props, ["id", "className", "feedObjectId", "feedObject", "feedObjectType", "CommentComponent", "CommentComponentProps", "CommentObjectSkeletonProps", "CommentsObjectSkeletonProps", "next", "isLoadingNext", "handleNext", "previous", "isLoadingPrevious", "handlePrevious", "totalLoadedComments", "totalComments", "page", "previousPage", "nextPage", "comments", "startComments", "endComments", "infiniteScrolling", "hideAdvertising", "disablePaginationLinks", "hidePaginationLinks", "paginationLinksPageQueryParam", "PaginationLinkProps", "cacheStrategy"]);
|
|
91
|
+
const { id = `comments_object_${props.feedObjectId ? props.feedObjectId : props.feedObject ? props.feedObject.id : ''}`, className, feedObjectId, feedObject, feedObjectType = types_1.SCContributionType.POST, CommentComponent = CommentObject_1.default, CommentComponentProps = { variant: 'outlined' }, CommentObjectSkeletonProps = { elevation: 0, WidgetProps: { variant: 'outlined' } }, CommentsObjectSkeletonProps = {}, next, isLoadingNext, handleNext, previous, isLoadingPrevious, handlePrevious, totalLoadedComments, totalComments, page, previousPage, nextPage, comments = [], startComments = [], endComments = [], infiniteScrolling = false, hideAdvertising = false, disablePaginationLinks = false, hidePaginationLinks = true, inPlaceLoadMoreContents = true, paginationLinksPageQueryParam = Pagination_1.DEFAULT_PAGINATION_QUERY_PARAM_NAME, PaginationLinkProps = {}, cacheStrategy = utils_1.CacheStrategies.NETWORK_ONLY } = props, rest = tslib_1.__rest(props, ["id", "className", "feedObjectId", "feedObject", "feedObjectType", "CommentComponent", "CommentComponentProps", "CommentObjectSkeletonProps", "CommentsObjectSkeletonProps", "next", "isLoadingNext", "handleNext", "previous", "isLoadingPrevious", "handlePrevious", "totalLoadedComments", "totalComments", "page", "previousPage", "nextPage", "comments", "startComments", "endComments", "infiniteScrolling", "hideAdvertising", "disablePaginationLinks", "hidePaginationLinks", "inPlaceLoadMoreContents", "paginationLinksPageQueryParam", "PaginationLinkProps", "cacheStrategy"]);
|
|
92
92
|
// CONTEXT
|
|
93
93
|
const scUserContext = (0, react_core_1.useSCUser)();
|
|
94
94
|
const scPreferences = (0, react_core_1.useSCPreferences)();
|
|
@@ -152,7 +152,12 @@ function CommentsObject(inProps) {
|
|
|
152
152
|
return (react_1.default.createElement(material_1.Box, { className: classes.pagination },
|
|
153
153
|
isLoadingPrevious && react_1.default.createElement(CommentObject_1.CommentObjectSkeleton, Object.assign({}, CommentObjectSkeletonProps, { count: 1 })),
|
|
154
154
|
!isLoadingPrevious && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
155
|
-
react_1.default.createElement(material_1.Button, { variant: "text"
|
|
155
|
+
react_1.default.createElement(material_1.Button, Object.assign({ variant: "text" }, (inPlaceLoadMoreContents
|
|
156
|
+
? { onClick: handlePrevious }
|
|
157
|
+
: {
|
|
158
|
+
component: react_core_1.Link,
|
|
159
|
+
to: `${scRoutingContext.url((0, contribution_1.getContributionRouteName)(feedObject), (0, contribution_1.getRouteData)(feedObject))}`
|
|
160
|
+
}), { disabled: isLoadingPrevious, color: "inherit", classes: { root: classes.loadPreviousCommentsButton } }),
|
|
156
161
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.commentsObject.loadPreviousComments", defaultMessage: "ui.commentsObject.loadPreviousComments" })),
|
|
157
162
|
!disablePaginationLinks && previousPage && previous && (react_1.default.createElement(react_core_1.Link, Object.assign({ to: `${(0, utils_1.appendURLSearchParams)(scRoutingContext.url((0, contribution_1.getContributionRouteName)(feedObject), (0, contribution_1.getRouteData)(feedObject)), [
|
|
158
163
|
{ [paginationLinksPageQueryParam]: previousPage }
|
|
@@ -166,7 +171,16 @@ function CommentsObject(inProps) {
|
|
|
166
171
|
return (react_1.default.createElement(material_1.Box, { className: classes.pagination }, isLoadingNext ? (react_1.default.createElement(CommentObject_1.CommentObjectSkeleton, Object.assign({}, CommentObjectSkeletonProps, { count: 1 }))) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
167
172
|
react_1.default.createElement(react_intersection_observer_1.InView, { as: "div", onChange: handleScrollEnd, threshold: 0.5 },
|
|
168
173
|
react_1.default.createElement(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
|
|
169
|
-
react_1.default.createElement(material_1.Button, { variant: "text"
|
|
174
|
+
react_1.default.createElement(material_1.Button, Object.assign({ variant: "text" }, (inPlaceLoadMoreContents
|
|
175
|
+
? { onClick: handleNext }
|
|
176
|
+
: {
|
|
177
|
+
component: react_core_1.Link,
|
|
178
|
+
to: nextPage && next
|
|
179
|
+
? `${(0, utils_1.appendURLSearchParams)(scRoutingContext.url((0, contribution_1.getContributionRouteName)(feedObject), (0, contribution_1.getRouteData)(feedObject)), [
|
|
180
|
+
{ [paginationLinksPageQueryParam]: nextPage }
|
|
181
|
+
])}`
|
|
182
|
+
: `${scRoutingContext.url((0, contribution_1.getContributionRouteName)(feedObject), (0, contribution_1.getRouteData)(feedObject))}`
|
|
183
|
+
}), { onClick: handleNext, disabled: isLoadingNext, color: "inherit", classes: { root: classes.loadNextCommentsButton } }),
|
|
170
184
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.commentsObject.loadMoreComments", defaultMessage: "ui.commentsObject.loadMoreComments" })),
|
|
171
185
|
showCommentsCounter() && (react_1.default.createElement(Typography_1.default, { variant: "body1", classes: { root: classes.commentsCounter } },
|
|
172
186
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.commentsObject.numberOfComments", defaultMessage: "ui.commentsObject.numberOfComments", values: { loaded: totalLoadedComments, total: totalComments } }))))),
|
|
@@ -185,9 +199,9 @@ function CommentsObject(inProps) {
|
|
|
185
199
|
/**
|
|
186
200
|
* Render comments and load others with load more button
|
|
187
201
|
*/
|
|
188
|
-
function renderComments(comments) {
|
|
202
|
+
function renderComments(comments, truncateContent = null) {
|
|
189
203
|
return (react_1.default.createElement(react_1.default.Fragment, null, comments.map((comment, index) => (react_1.default.createElement(react_1.default.Fragment, { key: index },
|
|
190
|
-
react_1.default.createElement(CommentComponent, Object.assign({ key: comment.id, commentObject: comment, onOpenReply: openReplyBox, feedObject: obj }, CommentComponentProps, { CommentObjectSkeletonProps: CommentObjectSkeletonProps })),
|
|
204
|
+
react_1.default.createElement(CommentComponent, Object.assign({ key: comment.id, commentObject: comment, onOpenReply: openReplyBox, feedObject: obj }, CommentComponentProps, { CommentObjectSkeletonProps: CommentObjectSkeletonProps }, (truncateContent !== null ? { truncateContent } : {}))),
|
|
191
205
|
advPosition === index && renderAdvertising())))));
|
|
192
206
|
}
|
|
193
207
|
/**
|
|
@@ -219,8 +233,8 @@ function CommentsObject(inProps) {
|
|
|
219
233
|
* Renders root object
|
|
220
234
|
*/
|
|
221
235
|
return (react_1.default.createElement(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className) }, rest),
|
|
222
|
-
renderComments(getFilteredComments(startComments)),
|
|
236
|
+
renderComments(getFilteredComments(startComments), false),
|
|
223
237
|
commentsRendered,
|
|
224
|
-
renderComments(getFilteredComments(endComments))));
|
|
238
|
+
renderComments(getFilteredComments(endComments), false)));
|
|
225
239
|
}
|
|
226
240
|
exports.default = CommentsObject;
|
|
@@ -480,7 +480,7 @@ function Composer(inProps) {
|
|
|
480
480
|
.then(() => setIsSubmitting(false));
|
|
481
481
|
};
|
|
482
482
|
// MEMO
|
|
483
|
-
const _EditorProps = (0, react_1.useMemo)(() => (EditorProps ? EditorProps : { toolbar: true, uploadImage:
|
|
483
|
+
const _EditorProps = (0, react_1.useMemo)(() => (EditorProps ? EditorProps : { toolbar: true, uploadImage: true }), [EditorProps, type]);
|
|
484
484
|
const isIOS = (0, react_1.useMemo)(() => (0, utils_1.iOS)(), []);
|
|
485
485
|
// RENDER
|
|
486
486
|
const hasMediaShare = (0, react_1.useMemo)(() => medias.findIndex((m) => m.type === Media_1.MEDIA_TYPE_SHARE) !== -1, [medias]);
|
|
@@ -3,30 +3,33 @@ import { DecoratorNode, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, Ser
|
|
|
3
3
|
export interface ImagePayload {
|
|
4
4
|
altText: string;
|
|
5
5
|
className?: string;
|
|
6
|
-
height
|
|
6
|
+
height?: 'inherit' | number;
|
|
7
7
|
imageRef?: LegacyRef<HTMLImageElement>;
|
|
8
|
+
maxWidth: number | string;
|
|
8
9
|
src: string;
|
|
9
|
-
width
|
|
10
|
+
width?: 'inherit' | number;
|
|
10
11
|
}
|
|
11
12
|
declare function convertImageElement(domNode: any): {
|
|
12
13
|
node: ImageNode;
|
|
13
14
|
};
|
|
14
15
|
export declare type SerializedImageNode = Spread<{
|
|
15
16
|
altText: string;
|
|
16
|
-
height
|
|
17
|
+
height?: number;
|
|
18
|
+
maxWidth: number | string;
|
|
17
19
|
src: string;
|
|
18
|
-
width
|
|
20
|
+
width?: number;
|
|
19
21
|
type: 'image';
|
|
20
22
|
version: 1;
|
|
21
23
|
}, SerializedLexicalNode>;
|
|
22
24
|
export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
23
25
|
__src: string;
|
|
24
26
|
__altText: string;
|
|
25
|
-
__width: number;
|
|
26
|
-
__height: number;
|
|
27
|
+
__width: 'inherit' | number;
|
|
28
|
+
__height: 'inherit' | number;
|
|
29
|
+
__maxWidth: number | string;
|
|
27
30
|
static getType(): string;
|
|
28
31
|
static clone(node: ImageNode): ImageNode;
|
|
29
|
-
constructor(src: string, altText: string,
|
|
32
|
+
constructor(src: string, altText: string, maxWidth: number | string, width?: 'inherit' | number, height?: 'inherit' | number, key?: NodeKey);
|
|
30
33
|
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
31
34
|
createDOM(config: EditorConfig): HTMLElement;
|
|
32
35
|
updateDOM(): false;
|
|
@@ -41,6 +44,6 @@ export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
41
44
|
static importJSON(serializedNode: SerializedImageNode): ImageNode;
|
|
42
45
|
exportJSON(): SerializedImageNode;
|
|
43
46
|
}
|
|
44
|
-
export declare function $createImageNode({ src, altText, width, height }: ImagePayload): ImageNode;
|
|
47
|
+
export declare function $createImageNode({ src, altText, maxWidth, width, height }: ImagePayload): ImageNode;
|
|
45
48
|
export declare function $isImageNode(node?: LexicalNode): boolean;
|
|
46
49
|
export {};
|
|
@@ -7,14 +7,6 @@ const lexical_1 = require("lexical");
|
|
|
7
7
|
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
|
|
8
8
|
const useLexicalNodeSelection_1 = require("@lexical/react/useLexicalNodeSelection");
|
|
9
9
|
const utils_1 = require("@lexical/utils");
|
|
10
|
-
/**
|
|
11
|
-
* Calc aspect-ratio of image
|
|
12
|
-
* @param width
|
|
13
|
-
* @param height
|
|
14
|
-
*/
|
|
15
|
-
function getAspectRatio(width, height) {
|
|
16
|
-
return width / height;
|
|
17
|
-
}
|
|
18
10
|
const imageCache = new Set();
|
|
19
11
|
function useSuspenseImage(src) {
|
|
20
12
|
if (!imageCache.has(src)) {
|
|
@@ -28,13 +20,15 @@ function useSuspenseImage(src) {
|
|
|
28
20
|
});
|
|
29
21
|
}
|
|
30
22
|
}
|
|
31
|
-
function LazyImage({ altText, className, imageRef, src, width, height }) {
|
|
23
|
+
function LazyImage({ altText, className, imageRef, src, width, height, maxWidth }) {
|
|
32
24
|
useSuspenseImage(src);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
return (react_1.default.createElement("img", { className: className, src: src, alt: altText, ref: imageRef, style: {
|
|
26
|
+
height: `${height}${height === 'inherit' ? '' : 'px'}`,
|
|
27
|
+
maxWidth,
|
|
28
|
+
width: `${width}${width === 'inherit' ? '' : 'px'}`
|
|
29
|
+
} }));
|
|
36
30
|
}
|
|
37
|
-
function ImageComponent({ src, altText, nodeKey, width, height }) {
|
|
31
|
+
function ImageComponent({ src, altText, nodeKey, width, height, maxWidth }) {
|
|
38
32
|
const imageRef = (0, react_1.useRef)(null);
|
|
39
33
|
const buttonRef = (0, react_1.useRef)(null);
|
|
40
34
|
const [isSelected, setSelected, clearSelection] = (0, useLexicalNodeSelection_1.useLexicalNodeSelection)(nodeKey);
|
|
@@ -102,29 +96,30 @@ function ImageComponent({ src, altText, nodeKey, width, height }) {
|
|
|
102
96
|
}, [clearSelection, editor, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
|
|
103
97
|
const isFocused = isSelected;
|
|
104
98
|
return (react_1.default.createElement(react_1.Suspense, { fallback: null },
|
|
105
|
-
react_1.default.createElement(LazyImage, { className: isFocused ? `focused` : null, src: src, altText: altText, imageRef: imageRef, width: width, height: height })));
|
|
99
|
+
react_1.default.createElement(LazyImage, { className: isFocused ? `focused` : null, src: src, altText: altText, imageRef: imageRef, width: width, height: height, maxWidth: maxWidth })));
|
|
106
100
|
}
|
|
107
101
|
function convertImageElement(domNode) {
|
|
108
102
|
if (domNode instanceof HTMLImageElement) {
|
|
109
103
|
const { alt: altText, src, dataset: { width, height } } = domNode;
|
|
110
|
-
const node = $createImageNode({ altText, height: Number(height), src, width: Number(width) });
|
|
104
|
+
const node = $createImageNode({ altText, height: Number(height), src, width: Number(width), maxWidth: '100%' });
|
|
111
105
|
return { node };
|
|
112
106
|
}
|
|
113
107
|
return null;
|
|
114
108
|
}
|
|
115
109
|
class ImageNode extends lexical_1.DecoratorNode {
|
|
116
|
-
constructor(src, altText, width, height, key) {
|
|
110
|
+
constructor(src, altText, maxWidth, width, height, key) {
|
|
117
111
|
super(key);
|
|
118
112
|
this.__src = src;
|
|
119
113
|
this.__altText = altText;
|
|
120
|
-
this.__width = width;
|
|
121
|
-
this.
|
|
114
|
+
this.__width = width || 'inherit';
|
|
115
|
+
this.__maxWidth = maxWidth;
|
|
116
|
+
this.__height = height || 'inherit';
|
|
122
117
|
}
|
|
123
118
|
static getType() {
|
|
124
119
|
return 'image';
|
|
125
120
|
}
|
|
126
121
|
static clone(node) {
|
|
127
|
-
return new ImageNode(node.__src, node.__altText, node.__width, node.__height, node.__key);
|
|
122
|
+
return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__key);
|
|
128
123
|
}
|
|
129
124
|
setWidthAndHeight(width, height) {
|
|
130
125
|
const writable = this.getWritable();
|
|
@@ -158,45 +153,43 @@ class ImageNode extends lexical_1.DecoratorNode {
|
|
|
158
153
|
}) }, dom);
|
|
159
154
|
}
|
|
160
155
|
exportDOM() {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
element.setAttribute('
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
image.setAttribute('style', `position: absolute;width:100%;height:100%;`);
|
|
168
|
-
image.setAttribute('data-width', `${this.__width}`);
|
|
169
|
-
image.setAttribute('data-height', `${this.__height}`);
|
|
170
|
-
element.appendChild(image);
|
|
156
|
+
const element = document.createElement('img');
|
|
157
|
+
element.setAttribute('src', this.__src);
|
|
158
|
+
element.setAttribute('alt', this.__altText);
|
|
159
|
+
element.setAttribute('width', `${this.__width}`);
|
|
160
|
+
element.setAttribute('height', `${this.__height}`);
|
|
161
|
+
element.setAttribute('style', `max-width: ${this.__maxWidth}px;`);
|
|
171
162
|
return { element };
|
|
172
163
|
}
|
|
173
164
|
decorate() {
|
|
174
|
-
return react_1.default.createElement(ImageComponent, { src: this.__src, altText: this.__altText, width: this.__width, height: this.__height, nodeKey: this.getKey() });
|
|
165
|
+
return (react_1.default.createElement(ImageComponent, { src: this.__src, altText: this.__altText, width: this.__width, height: this.__height, maxWidth: this.__maxWidth, nodeKey: this.getKey() }));
|
|
175
166
|
}
|
|
176
167
|
static importJSON(serializedNode) {
|
|
177
|
-
const { altText, height, width, src } = serializedNode;
|
|
168
|
+
const { altText, height, width, maxWidth, src } = serializedNode;
|
|
178
169
|
const node = $createImageNode({
|
|
179
170
|
altText,
|
|
180
171
|
height,
|
|
181
172
|
src,
|
|
182
|
-
width
|
|
173
|
+
width,
|
|
174
|
+
maxWidth
|
|
183
175
|
});
|
|
184
176
|
return node;
|
|
185
177
|
}
|
|
186
178
|
exportJSON() {
|
|
187
179
|
return {
|
|
188
180
|
altText: this.getAltText(),
|
|
189
|
-
height: this.__height,
|
|
181
|
+
height: this.__height === 'inherit' ? 0 : this.__height,
|
|
182
|
+
maxWidth: this.__maxWidth,
|
|
190
183
|
src: this.getSrc(),
|
|
191
184
|
type: 'image',
|
|
192
185
|
version: 1,
|
|
193
|
-
width: this.__width
|
|
186
|
+
width: this.__width === 'inherit' ? 0 : this.__width
|
|
194
187
|
};
|
|
195
188
|
}
|
|
196
189
|
}
|
|
197
190
|
exports.ImageNode = ImageNode;
|
|
198
|
-
function $createImageNode({ src, altText, width, height }) {
|
|
199
|
-
return new ImageNode(src, altText, width, height);
|
|
191
|
+
function $createImageNode({ src, altText, maxWidth, width = null, height = null }) {
|
|
192
|
+
return new ImageNode(src, altText, maxWidth, width, height);
|
|
200
193
|
}
|
|
201
194
|
exports.$createImageNode = $createImageNode;
|
|
202
195
|
function $isImageNode(node) {
|
|
@@ -32,18 +32,11 @@ function Image({ editor, className = '' }) {
|
|
|
32
32
|
return file.type.startsWith('image/');
|
|
33
33
|
};
|
|
34
34
|
const handleUploadSuccess = (media) => {
|
|
35
|
-
const image = media.image_thumbnail
|
|
36
|
-
? media.image_thumbnail
|
|
37
|
-
: {
|
|
38
|
-
url: media.image,
|
|
39
|
-
width: media.image_width,
|
|
40
|
-
height: media.image_height
|
|
41
|
-
};
|
|
42
35
|
const data = {
|
|
43
36
|
altText: media.title,
|
|
44
|
-
src: image
|
|
45
|
-
width:
|
|
46
|
-
height:
|
|
37
|
+
src: media.image,
|
|
38
|
+
width: media.image_width,
|
|
39
|
+
height: media.image_height
|
|
47
40
|
};
|
|
48
41
|
editor.focus();
|
|
49
42
|
editor.dispatchCommand(exports.INSERT_IMAGE_COMMAND, data);
|
|
@@ -96,7 +89,13 @@ function ImagePlugin() {
|
|
|
96
89
|
if ((0, lexical_1.$isRootNode)(selection.anchor.getNode())) {
|
|
97
90
|
selection.insertParagraph();
|
|
98
91
|
}
|
|
99
|
-
const imageNode = (0, ImageNode_1.$createImageNode)({
|
|
92
|
+
const imageNode = (0, ImageNode_1.$createImageNode)({
|
|
93
|
+
src: payload.src,
|
|
94
|
+
altText: payload.altText,
|
|
95
|
+
maxWidth: '100%',
|
|
96
|
+
width: payload.width,
|
|
97
|
+
height: payload.height
|
|
98
|
+
});
|
|
100
99
|
selection.insertNodes([imageNode]);
|
|
101
100
|
}
|
|
102
101
|
return true;
|
|
@@ -90,7 +90,7 @@ function Activities(inProps) {
|
|
|
90
90
|
* Render comments of feedObject
|
|
91
91
|
*/
|
|
92
92
|
function renderComments() {
|
|
93
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, (commentsObject.feedObject.comment_count > 0 || comments.length > 0) && (react_1.default.createElement(CommentsObject_1.default, 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 : {})) })))));
|
|
93
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, (commentsObject.feedObject.comment_count > 0 || comments.length > 0) && (react_1.default.createElement(CommentsObject_1.default, 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 })))));
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Renders root object
|
|
@@ -458,7 +458,7 @@ function FeedObject(inProps) {
|
|
|
458
458
|
template === feedObject_1.SCFeedObjectTemplateType.PREVIEW && (obj.comment_count > 0 || (feedObjectActivities && feedObjectActivities.length > 0)) && (react_1.default.createElement(material_1.Collapse, { in: expandedActivities, timeout: "auto", classes: { root: classes.activitiesSection } },
|
|
459
459
|
react_1.default.createElement(CardContent_1.default, { className: classes.activitiesContent },
|
|
460
460
|
react_1.default.createElement(Activities_1.default, Object.assign({ feedObject: obj, key: selectedActivities, feedObjectActivities: feedObjectActivities, activitiesType: selectedActivities, onSetSelectedActivities: handleSelectedActivities, comments: comments, CommentsObjectProps: {
|
|
461
|
-
CommentComponentProps: Object.assign({ onDelete: handleDeleteComment, truncateContent:
|
|
461
|
+
CommentComponentProps: Object.assign({ onDelete: handleDeleteComment, truncateContent: true }, CommentComponentProps),
|
|
462
462
|
CommentObjectSkeletonProps: CommentObjectSkeletonProps
|
|
463
463
|
}, cacheStrategy: cacheStrategy }, ActivitiesProps))))),
|
|
464
464
|
composerOpen && (react_1.default.createElement(Composer_1.default, { open: composerOpen, feedObject: obj, onClose: handleToggleEdit, onSuccess: handleEditSuccess, maxWidth: "sm", fullWidth: true, scroll: "body" })))) : (react_1.default.createElement(Skeleton_1.default, Object.assign({ template: template }, FeedObjectSkeletonProps)))));
|
|
@@ -360,7 +360,7 @@ export default function CommentObject(inProps) {
|
|
|
360
360
|
* @param comment
|
|
361
361
|
*/
|
|
362
362
|
function renderLatestComment(comment) {
|
|
363
|
-
return (React.createElement(CommentsObject, { feedObject: commentsObject.feedObject, feedObjectType: commentsObject.feedObject ? commentsObject.feedObject.type : feedObjectType, hideAdvertising: true, comments: [].concat(commentsObject.comments).reverse(), endComments: comment.latest_comments, previous: comment.comment_count > comment.latest_comments.length ? commentsObject.next : null, isLoadingPrevious: commentsObject.isLoadingNext, handlePrevious: commentsObject.getNextPage, CommentComponentProps: Object.assign(Object.assign({ onOpenReply: reply, CommentObjectSkeletonProps, elevation: elevation, linkableCommentDateTime: linkableCommentDateTime }, rest), { cacheStrategy }), CommentsObjectSkeletonProps: { count: 1, CommentObjectSkeletonProps: CommentObjectSkeletonProps }, cacheStrategy: cacheStrategy }));
|
|
363
|
+
return (React.createElement(CommentsObject, { feedObject: commentsObject.feedObject, feedObjectType: commentsObject.feedObject ? commentsObject.feedObject.type : feedObjectType, hideAdvertising: true, comments: [].concat(commentsObject.comments).reverse(), endComments: comment.latest_comments, previous: comment.comment_count > comment.latest_comments.length ? commentsObject.next : null, isLoadingPrevious: commentsObject.isLoadingNext, handlePrevious: commentsObject.getNextPage, CommentComponentProps: Object.assign(Object.assign({ onOpenReply: reply, CommentObjectSkeletonProps, elevation: elevation, linkableCommentDateTime: linkableCommentDateTime }, rest), { cacheStrategy }), CommentsObjectSkeletonProps: { count: 1, CommentObjectSkeletonProps: CommentObjectSkeletonProps }, cacheStrategy: cacheStrategy, inPlaceLoadMoreContents: true }));
|
|
364
364
|
}
|
|
365
365
|
/**
|
|
366
366
|
* Render comments
|
|
@@ -110,6 +110,11 @@ export interface CommentsObjectProps {
|
|
|
110
110
|
* @default true
|
|
111
111
|
*/
|
|
112
112
|
hidePaginationLinks?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Load more contents in place
|
|
115
|
+
* rather than opening a new page
|
|
116
|
+
*/
|
|
117
|
+
inPlaceLoadMoreContents?: boolean;
|
|
113
118
|
/**
|
|
114
119
|
* Page query parameter name
|
|
115
120
|
* @default 'page'
|
|
@@ -86,7 +86,7 @@ export default function CommentsObject(inProps) {
|
|
|
86
86
|
name: PREFIX
|
|
87
87
|
});
|
|
88
88
|
// PROPS
|
|
89
|
-
const { id = `comments_object_${props.feedObjectId ? props.feedObjectId : props.feedObject ? props.feedObject.id : ''}`, className, feedObjectId, feedObject, feedObjectType = SCContributionType.POST, CommentComponent = CommentObject, CommentComponentProps = { variant: 'outlined' }, CommentObjectSkeletonProps = { elevation: 0, WidgetProps: { variant: 'outlined' } }, CommentsObjectSkeletonProps = {}, next, isLoadingNext, handleNext, previous, isLoadingPrevious, handlePrevious, totalLoadedComments, totalComments, page, previousPage, nextPage, comments = [], startComments = [], endComments = [], infiniteScrolling = false, hideAdvertising = false, disablePaginationLinks = false, hidePaginationLinks = true, paginationLinksPageQueryParam = DEFAULT_PAGINATION_QUERY_PARAM_NAME, PaginationLinkProps = {}, cacheStrategy = CacheStrategies.NETWORK_ONLY } = props, rest = __rest(props, ["id", "className", "feedObjectId", "feedObject", "feedObjectType", "CommentComponent", "CommentComponentProps", "CommentObjectSkeletonProps", "CommentsObjectSkeletonProps", "next", "isLoadingNext", "handleNext", "previous", "isLoadingPrevious", "handlePrevious", "totalLoadedComments", "totalComments", "page", "previousPage", "nextPage", "comments", "startComments", "endComments", "infiniteScrolling", "hideAdvertising", "disablePaginationLinks", "hidePaginationLinks", "paginationLinksPageQueryParam", "PaginationLinkProps", "cacheStrategy"]);
|
|
89
|
+
const { id = `comments_object_${props.feedObjectId ? props.feedObjectId : props.feedObject ? props.feedObject.id : ''}`, className, feedObjectId, feedObject, feedObjectType = SCContributionType.POST, CommentComponent = CommentObject, CommentComponentProps = { variant: 'outlined' }, CommentObjectSkeletonProps = { elevation: 0, WidgetProps: { variant: 'outlined' } }, CommentsObjectSkeletonProps = {}, next, isLoadingNext, handleNext, previous, isLoadingPrevious, handlePrevious, totalLoadedComments, totalComments, page, previousPage, nextPage, comments = [], startComments = [], endComments = [], infiniteScrolling = false, hideAdvertising = false, disablePaginationLinks = false, hidePaginationLinks = true, inPlaceLoadMoreContents = true, paginationLinksPageQueryParam = DEFAULT_PAGINATION_QUERY_PARAM_NAME, PaginationLinkProps = {}, cacheStrategy = CacheStrategies.NETWORK_ONLY } = props, rest = __rest(props, ["id", "className", "feedObjectId", "feedObject", "feedObjectType", "CommentComponent", "CommentComponentProps", "CommentObjectSkeletonProps", "CommentsObjectSkeletonProps", "next", "isLoadingNext", "handleNext", "previous", "isLoadingPrevious", "handlePrevious", "totalLoadedComments", "totalComments", "page", "previousPage", "nextPage", "comments", "startComments", "endComments", "infiniteScrolling", "hideAdvertising", "disablePaginationLinks", "hidePaginationLinks", "inPlaceLoadMoreContents", "paginationLinksPageQueryParam", "PaginationLinkProps", "cacheStrategy"]);
|
|
90
90
|
// CONTEXT
|
|
91
91
|
const scUserContext = useSCUser();
|
|
92
92
|
const scPreferences = useSCPreferences();
|
|
@@ -150,7 +150,12 @@ export default function CommentsObject(inProps) {
|
|
|
150
150
|
return (React.createElement(Box, { className: classes.pagination },
|
|
151
151
|
isLoadingPrevious && React.createElement(CommentObjectSkeleton, Object.assign({}, CommentObjectSkeletonProps, { count: 1 })),
|
|
152
152
|
!isLoadingPrevious && (React.createElement(React.Fragment, null,
|
|
153
|
-
React.createElement(Button, { variant: "text"
|
|
153
|
+
React.createElement(Button, Object.assign({ variant: "text" }, (inPlaceLoadMoreContents
|
|
154
|
+
? { onClick: handlePrevious }
|
|
155
|
+
: {
|
|
156
|
+
component: Link,
|
|
157
|
+
to: `${scRoutingContext.url(getContributionRouteName(feedObject), getRouteData(feedObject))}`
|
|
158
|
+
}), { disabled: isLoadingPrevious, color: "inherit", classes: { root: classes.loadPreviousCommentsButton } }),
|
|
154
159
|
React.createElement(FormattedMessage, { id: "ui.commentsObject.loadPreviousComments", defaultMessage: "ui.commentsObject.loadPreviousComments" })),
|
|
155
160
|
!disablePaginationLinks && previousPage && previous && (React.createElement(Link, Object.assign({ to: `${appendURLSearchParams(scRoutingContext.url(getContributionRouteName(feedObject), getRouteData(feedObject)), [
|
|
156
161
|
{ [paginationLinksPageQueryParam]: previousPage }
|
|
@@ -164,7 +169,16 @@ export default function CommentsObject(inProps) {
|
|
|
164
169
|
return (React.createElement(Box, { className: classes.pagination }, isLoadingNext ? (React.createElement(CommentObjectSkeleton, Object.assign({}, CommentObjectSkeletonProps, { count: 1 }))) : (React.createElement(React.Fragment, null,
|
|
165
170
|
React.createElement(InView, { as: "div", onChange: handleScrollEnd, threshold: 0.5 },
|
|
166
171
|
React.createElement(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
|
|
167
|
-
React.createElement(Button, { variant: "text"
|
|
172
|
+
React.createElement(Button, Object.assign({ variant: "text" }, (inPlaceLoadMoreContents
|
|
173
|
+
? { onClick: handleNext }
|
|
174
|
+
: {
|
|
175
|
+
component: Link,
|
|
176
|
+
to: nextPage && next
|
|
177
|
+
? `${appendURLSearchParams(scRoutingContext.url(getContributionRouteName(feedObject), getRouteData(feedObject)), [
|
|
178
|
+
{ [paginationLinksPageQueryParam]: nextPage }
|
|
179
|
+
])}`
|
|
180
|
+
: `${scRoutingContext.url(getContributionRouteName(feedObject), getRouteData(feedObject))}`
|
|
181
|
+
}), { onClick: handleNext, disabled: isLoadingNext, color: "inherit", classes: { root: classes.loadNextCommentsButton } }),
|
|
168
182
|
React.createElement(FormattedMessage, { id: "ui.commentsObject.loadMoreComments", defaultMessage: "ui.commentsObject.loadMoreComments" })),
|
|
169
183
|
showCommentsCounter() && (React.createElement(Typography, { variant: "body1", classes: { root: classes.commentsCounter } },
|
|
170
184
|
React.createElement(FormattedMessage, { id: "ui.commentsObject.numberOfComments", defaultMessage: "ui.commentsObject.numberOfComments", values: { loaded: totalLoadedComments, total: totalComments } }))))),
|
|
@@ -183,9 +197,9 @@ export default function CommentsObject(inProps) {
|
|
|
183
197
|
/**
|
|
184
198
|
* Render comments and load others with load more button
|
|
185
199
|
*/
|
|
186
|
-
function renderComments(comments) {
|
|
200
|
+
function renderComments(comments, truncateContent = null) {
|
|
187
201
|
return (React.createElement(React.Fragment, null, comments.map((comment, index) => (React.createElement(React.Fragment, { key: index },
|
|
188
|
-
React.createElement(CommentComponent, Object.assign({ key: comment.id, commentObject: comment, onOpenReply: openReplyBox, feedObject: obj }, CommentComponentProps, { CommentObjectSkeletonProps: CommentObjectSkeletonProps })),
|
|
202
|
+
React.createElement(CommentComponent, Object.assign({ key: comment.id, commentObject: comment, onOpenReply: openReplyBox, feedObject: obj }, CommentComponentProps, { CommentObjectSkeletonProps: CommentObjectSkeletonProps }, (truncateContent !== null ? { truncateContent } : {}))),
|
|
189
203
|
advPosition === index && renderAdvertising())))));
|
|
190
204
|
}
|
|
191
205
|
/**
|
|
@@ -217,7 +231,7 @@ export default function CommentsObject(inProps) {
|
|
|
217
231
|
* Renders root object
|
|
218
232
|
*/
|
|
219
233
|
return (React.createElement(Root, Object.assign({ id: id, className: classNames(classes.root, className) }, rest),
|
|
220
|
-
renderComments(getFilteredComments(startComments)),
|
|
234
|
+
renderComments(getFilteredComments(startComments), false),
|
|
221
235
|
commentsRendered,
|
|
222
|
-
renderComments(getFilteredComments(endComments))));
|
|
236
|
+
renderComments(getFilteredComments(endComments), false)));
|
|
223
237
|
}
|
|
@@ -477,7 +477,7 @@ export default function Composer(inProps) {
|
|
|
477
477
|
.then(() => setIsSubmitting(false));
|
|
478
478
|
};
|
|
479
479
|
// MEMO
|
|
480
|
-
const _EditorProps = useMemo(() => (EditorProps ? EditorProps : { toolbar: true, uploadImage:
|
|
480
|
+
const _EditorProps = useMemo(() => (EditorProps ? EditorProps : { toolbar: true, uploadImage: true }), [EditorProps, type]);
|
|
481
481
|
const isIOS = useMemo(() => iOS(), []);
|
|
482
482
|
// RENDER
|
|
483
483
|
const hasMediaShare = useMemo(() => medias.findIndex((m) => m.type === MEDIA_TYPE_SHARE) !== -1, [medias]);
|
|
@@ -3,30 +3,33 @@ import { DecoratorNode, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, Ser
|
|
|
3
3
|
export interface ImagePayload {
|
|
4
4
|
altText: string;
|
|
5
5
|
className?: string;
|
|
6
|
-
height
|
|
6
|
+
height?: 'inherit' | number;
|
|
7
7
|
imageRef?: LegacyRef<HTMLImageElement>;
|
|
8
|
+
maxWidth: number | string;
|
|
8
9
|
src: string;
|
|
9
|
-
width
|
|
10
|
+
width?: 'inherit' | number;
|
|
10
11
|
}
|
|
11
12
|
declare function convertImageElement(domNode: any): {
|
|
12
13
|
node: ImageNode;
|
|
13
14
|
};
|
|
14
15
|
export declare type SerializedImageNode = Spread<{
|
|
15
16
|
altText: string;
|
|
16
|
-
height
|
|
17
|
+
height?: number;
|
|
18
|
+
maxWidth: number | string;
|
|
17
19
|
src: string;
|
|
18
|
-
width
|
|
20
|
+
width?: number;
|
|
19
21
|
type: 'image';
|
|
20
22
|
version: 1;
|
|
21
23
|
}, SerializedLexicalNode>;
|
|
22
24
|
export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
23
25
|
__src: string;
|
|
24
26
|
__altText: string;
|
|
25
|
-
__width: number;
|
|
26
|
-
__height: number;
|
|
27
|
+
__width: 'inherit' | number;
|
|
28
|
+
__height: 'inherit' | number;
|
|
29
|
+
__maxWidth: number | string;
|
|
27
30
|
static getType(): string;
|
|
28
31
|
static clone(node: ImageNode): ImageNode;
|
|
29
|
-
constructor(src: string, altText: string,
|
|
32
|
+
constructor(src: string, altText: string, maxWidth: number | string, width?: 'inherit' | number, height?: 'inherit' | number, key?: NodeKey);
|
|
30
33
|
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
31
34
|
createDOM(config: EditorConfig): HTMLElement;
|
|
32
35
|
updateDOM(): false;
|
|
@@ -41,6 +44,6 @@ export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
41
44
|
static importJSON(serializedNode: SerializedImageNode): ImageNode;
|
|
42
45
|
exportJSON(): SerializedImageNode;
|
|
43
46
|
}
|
|
44
|
-
export declare function $createImageNode({ src, altText, width, height }: ImagePayload): ImageNode;
|
|
47
|
+
export declare function $createImageNode({ src, altText, maxWidth, width, height }: ImagePayload): ImageNode;
|
|
45
48
|
export declare function $isImageNode(node?: LexicalNode): boolean;
|
|
46
49
|
export {};
|