@manuscripts/style-guide 1.1.11 → 1.1.13

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.
@@ -35,7 +35,7 @@ const react_tooltip_1 = __importDefault(require("react-tooltip"));
35
35
  const styled_components_1 = __importDefault(require("styled-components"));
36
36
  const Button_1 = require("../Button");
37
37
  const Form_1 = require("../Form");
38
- exports.CommentBody = react_1.default.memo(({ createKeyword, comment, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, setIsEditing, scrollIntoHighlight, isEditing, isProdNote, }) => {
38
+ exports.CommentBody = react_1.default.memo(({ createKeyword, comment, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, setIsEditing, scrollIntoHighlight, onFocusOut, isEditing, isProdNote, }) => {
39
39
  (0, react_1.useEffect)(() => {
40
40
  if (isNew) {
41
41
  setIsEditing(true);
@@ -54,11 +54,14 @@ exports.CommentBody = react_1.default.memo(({ createKeyword, comment, getCollabo
54
54
  } }, ({ errors, values, setFieldValue }) => (react_1.default.createElement(formik_1.Form, null,
55
55
  errors.contents && react_1.default.createElement(Form_1.FormError, null, errors.contents),
56
56
  react_1.default.createElement(formik_1.Field, { name: 'contents' }, (props) => (react_1.default.createElement(CommentContent, null,
57
- react_1.default.createElement(StyledCommentField, { autoFocus: isEditing, value: values.contents, handleChange: (data) => setFieldValue(props.field.name, data), createKeyword: createKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, notePlaceholder: !isReply ? 'Comment or @mention...' : 'Reply...' })))),
57
+ react_1.default.createElement(StyledCommentField, { id: comment._id, autoFocus: isEditing, value: values.contents, handleChange: (data) => setFieldValue(props.field.name, data), handleBlur: onFocusOut, createKeyword: createKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, notePlaceholder: !isReply ? 'Comment or @mention...' : 'Reply...' })))),
58
58
  react_1.default.createElement(EditingCommentFooter, null,
59
59
  react_1.default.createElement(Actions, null,
60
60
  react_1.default.createElement(Button_1.SecondaryButton, { onClick: cancelEditing }, "Cancel"),
61
- react_1.default.createElement(Button_1.PrimaryButton, { type: "submit" }, "Save"))))))) : (react_1.default.createElement("div", null,
61
+ react_1.default.createElement(Button_1.PrimaryButton, { disabled: !values.contents.replace(/<[^>]+>/g, '').length ||
62
+ (!isNew &&
63
+ (comment.contents === values.contents ||
64
+ !values.contents.replace(/<[^>]+>/g, '').length)), type: "submit" }, "Save"))))))) : (react_1.default.createElement("div", null,
62
65
  react_1.default.createElement(CommentContent, { onClick: () => scrollIntoHighlight && scrollIntoHighlight(comment) },
63
66
  react_1.default.createElement(StyledCommentViewer, { value: comment.contents, getCollaborator: getCollaborator, getKeyword: getKeyword })),
64
67
  !isReply && (react_1.default.createElement(CommentFooter, null,
@@ -54,7 +54,7 @@ const isOwn = (comment, userId) => {
54
54
  ? (_a = comment.contributions) === null || _a === void 0 ? void 0 : _a.some((c) => c.profileID === userId)
55
55
  : false;
56
56
  };
57
- const CommentWrapper = ({ createKeyword, comment, can, currentUserId, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, handleSetResolved, isProdNote, isSelected, handleRequestSelect, scrollIntoHighlight, children, }) => {
57
+ const CommentWrapper = ({ createKeyword, comment, can, currentUserId, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, handleSetResolved, isProdNote, isSelected, handleRequestSelect, scrollIntoHighlight, onFocusOut, children, }) => {
58
58
  const [isEditing, setIsEditing] = (0, react_1.useState)();
59
59
  const threadRef = (0, react_1.useRef)(null);
60
60
  (0, react_1.useEffect)(() => {
@@ -89,7 +89,7 @@ const CommentWrapper = ({ createKeyword, comment, can, currentUserId, getCollabo
89
89
  react_1.default.createElement(NoteTitle, { type: "button", onMouseDown: onTitleMouseDown, onKeyDown: onTitleKeyDown }, comment.contributions && (react_1.default.createElement(CommentUser_1.CommentUser, { contributions: comment.contributions, getCollaboratorById: getCollaborator, displayName: comment.displayName, createdAt: (0, comments_1.isSavedComment)(comment) ? comment.createdAt * 1000 : undefined }))),
90
90
  react_1.default.createElement(CommentActions_1.CommentActions, { id: comment._id, isOwnComment: isOwnComment, can: can, target: comment.target, isResolved: comment.resolved, handleSetResolved: handleSetResolved, deleteComment: deleteComment, setIsEditing: setIsEditing, isProdNote: isProdNote })),
91
91
  children,
92
- react_1.default.createElement(CommentBody_1.CommentBody, { createKeyword: createKeyword, comment: comment, deleteComment: deleteComment, getCollaborator: getCollaborator, getKeyword: getKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, isReply: isReply, saveComment: saveComment, handleCreateReply: handleCreateReply, scrollIntoHighlight: scrollIntoHighlight, isNew: isNew, setIsEditing: setIsEditing, isEditing: isEditing, isProdNote: isProdNote })));
92
+ react_1.default.createElement(CommentBody_1.CommentBody, { createKeyword: createKeyword, onFocusOut: onFocusOut, comment: comment, deleteComment: deleteComment, getCollaborator: getCollaborator, getKeyword: getKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, isReply: isReply, saveComment: saveComment, handleCreateReply: handleCreateReply, scrollIntoHighlight: scrollIntoHighlight, isNew: isNew, setIsEditing: setIsEditing, isEditing: isEditing, isProdNote: isProdNote })));
93
93
  };
94
94
  exports.CommentWrapper = CommentWrapper;
95
95
  const Note = styled_components_1.default.div `
@@ -8,21 +8,27 @@ const json_schema_1 = require("@manuscripts/json-schema");
8
8
  const transform_1 = require("@manuscripts/transform");
9
9
  const inlineFiles_1 = __importDefault(require("../lib/inlineFiles"));
10
10
  const use_deep_compare_1 = require("./use-deep-compare");
11
- const getSupplementFiles = (modelMap, attachments, filePredicate) => {
11
+ const getInlineFilesIds = (inlineFiles) => {
12
+ return inlineFiles
13
+ .map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
14
+ .flat();
15
+ };
16
+ const getSupplementFiles = (modelMap, inlineFiles, attachments, filePredicate) => {
12
17
  const supplements = new Map((0, transform_1.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
18
+ const excludedAttachmentsIds = new Set(getInlineFilesIds(inlineFiles).map(({ id }) => id));
13
19
  return attachments.filter((attachment) => {
14
20
  if (supplements.has(attachment.id) && filePredicate) {
15
- return filePredicate(attachment.name);
21
+ return (!excludedAttachmentsIds.has(attachment.id) &&
22
+ filePredicate(attachment.name));
16
23
  }
17
24
  else {
18
- return supplements.has(attachment.id);
25
+ return (!excludedAttachmentsIds.has(attachment.id) &&
26
+ supplements.has(attachment.id));
19
27
  }
20
28
  });
21
29
  };
22
30
  const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate) => {
23
- const inlineFilesAttachmentIds = inlineFiles
24
- .map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
25
- .flat();
31
+ const inlineFilesAttachmentIds = getInlineFilesIds(inlineFiles);
26
32
  const excludedAttachmentsIds = new Set([...inlineFilesAttachmentIds, ...supplementFiles].map(({ id }) => id));
27
33
  return attachments.filter(({ id, name }) => {
28
34
  if (!excludedAttachmentsIds.has(id) && filePredicate) {
@@ -35,7 +41,7 @@ const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate)
35
41
  };
36
42
  const useFiles = (modelMap, attachments, filePredicate) => (0, use_deep_compare_1.useDeepCompareMemo)(() => {
37
43
  const inlineFiles = (0, inlineFiles_1.default)(modelMap, attachments);
38
- const supplementFiles = getSupplementFiles(modelMap, attachments, filePredicate);
44
+ const supplementFiles = getSupplementFiles(modelMap, inlineFiles, attachments, filePredicate);
39
45
  const otherFiles = getOtherFiles(inlineFiles, supplementFiles, attachments, filePredicate);
40
46
  return {
41
47
  otherFiles,
@@ -6,7 +6,7 @@ import ReactTooltip from 'react-tooltip';
6
6
  import styled from 'styled-components';
7
7
  import { ButtonGroup, PrimaryButton, SecondaryButton } from '../Button';
8
8
  import { FormError } from '../Form';
9
- export const CommentBody = React.memo(({ createKeyword, comment, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, setIsEditing, scrollIntoHighlight, isEditing, isProdNote, }) => {
9
+ export const CommentBody = React.memo(({ createKeyword, comment, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, setIsEditing, scrollIntoHighlight, onFocusOut, isEditing, isProdNote, }) => {
10
10
  useEffect(() => {
11
11
  if (isNew) {
12
12
  setIsEditing(true);
@@ -25,11 +25,14 @@ export const CommentBody = React.memo(({ createKeyword, comment, getCollaborator
25
25
  } }, ({ errors, values, setFieldValue }) => (React.createElement(Form, null,
26
26
  errors.contents && React.createElement(FormError, null, errors.contents),
27
27
  React.createElement(Field, { name: 'contents' }, (props) => (React.createElement(CommentContent, null,
28
- React.createElement(StyledCommentField, { autoFocus: isEditing, value: values.contents, handleChange: (data) => setFieldValue(props.field.name, data), createKeyword: createKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, notePlaceholder: !isReply ? 'Comment or @mention...' : 'Reply...' })))),
28
+ React.createElement(StyledCommentField, { id: comment._id, autoFocus: isEditing, value: values.contents, handleChange: (data) => setFieldValue(props.field.name, data), handleBlur: onFocusOut, createKeyword: createKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, notePlaceholder: !isReply ? 'Comment or @mention...' : 'Reply...' })))),
29
29
  React.createElement(EditingCommentFooter, null,
30
30
  React.createElement(Actions, null,
31
31
  React.createElement(SecondaryButton, { onClick: cancelEditing }, "Cancel"),
32
- React.createElement(PrimaryButton, { type: "submit" }, "Save"))))))) : (React.createElement("div", null,
32
+ React.createElement(PrimaryButton, { disabled: !values.contents.replace(/<[^>]+>/g, '').length ||
33
+ (!isNew &&
34
+ (comment.contents === values.contents ||
35
+ !values.contents.replace(/<[^>]+>/g, '').length)), type: "submit" }, "Save"))))))) : (React.createElement("div", null,
33
36
  React.createElement(CommentContent, { onClick: () => scrollIntoHighlight && scrollIntoHighlight(comment) },
34
37
  React.createElement(StyledCommentViewer, { value: comment.contents, getCollaborator: getCollaborator, getKeyword: getKeyword })),
35
38
  !isReply && (React.createElement(CommentFooter, null,
@@ -25,7 +25,7 @@ const isOwn = (comment, userId) => {
25
25
  ? (_a = comment.contributions) === null || _a === void 0 ? void 0 : _a.some((c) => c.profileID === userId)
26
26
  : false;
27
27
  };
28
- export const CommentWrapper = ({ createKeyword, comment, can, currentUserId, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, handleSetResolved, isProdNote, isSelected, handleRequestSelect, scrollIntoHighlight, children, }) => {
28
+ export const CommentWrapper = ({ createKeyword, comment, can, currentUserId, getCollaborator, getKeyword, listCollaborators, listKeywords, saveComment, deleteComment, isReply, isNew, handleCreateReply, handleSetResolved, isProdNote, isSelected, handleRequestSelect, scrollIntoHighlight, onFocusOut, children, }) => {
29
29
  const [isEditing, setIsEditing] = useState();
30
30
  const threadRef = useRef(null);
31
31
  useEffect(() => {
@@ -60,7 +60,7 @@ export const CommentWrapper = ({ createKeyword, comment, can, currentUserId, get
60
60
  React.createElement(NoteTitle, { type: "button", onMouseDown: onTitleMouseDown, onKeyDown: onTitleKeyDown }, comment.contributions && (React.createElement(CommentUser, { contributions: comment.contributions, getCollaboratorById: getCollaborator, displayName: comment.displayName, createdAt: isSavedComment(comment) ? comment.createdAt * 1000 : undefined }))),
61
61
  React.createElement(CommentActions, { id: comment._id, isOwnComment: isOwnComment, can: can, target: comment.target, isResolved: comment.resolved, handleSetResolved: handleSetResolved, deleteComment: deleteComment, setIsEditing: setIsEditing, isProdNote: isProdNote })),
62
62
  children,
63
- React.createElement(CommentBody, { createKeyword: createKeyword, comment: comment, deleteComment: deleteComment, getCollaborator: getCollaborator, getKeyword: getKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, isReply: isReply, saveComment: saveComment, handleCreateReply: handleCreateReply, scrollIntoHighlight: scrollIntoHighlight, isNew: isNew, setIsEditing: setIsEditing, isEditing: isEditing, isProdNote: isProdNote })));
63
+ React.createElement(CommentBody, { createKeyword: createKeyword, onFocusOut: onFocusOut, comment: comment, deleteComment: deleteComment, getCollaborator: getCollaborator, getKeyword: getKeyword, listCollaborators: listCollaborators, listKeywords: listKeywords, isReply: isReply, saveComment: saveComment, handleCreateReply: handleCreateReply, scrollIntoHighlight: scrollIntoHighlight, isNew: isNew, setIsEditing: setIsEditing, isEditing: isEditing, isProdNote: isProdNote })));
64
64
  };
65
65
  const Note = styled.div `
66
66
  & .note-actions {
@@ -2,21 +2,27 @@ import { ObjectTypes } from '@manuscripts/json-schema';
2
2
  import { getModelsByType } from '@manuscripts/transform';
3
3
  import getInlineFiles from '../lib/inlineFiles';
4
4
  import { useDeepCompareMemo } from './use-deep-compare';
5
- const getSupplementFiles = (modelMap, attachments, filePredicate) => {
5
+ const getInlineFilesIds = (inlineFiles) => {
6
+ return inlineFiles
7
+ .map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
8
+ .flat();
9
+ };
10
+ const getSupplementFiles = (modelMap, inlineFiles, attachments, filePredicate) => {
6
11
  const supplements = new Map(getModelsByType(modelMap, ObjectTypes.Supplement).map((supplement) => { var _a; return [(_a = supplement.href) === null || _a === void 0 ? void 0 : _a.replace('attachment:', ''), supplement]; }));
12
+ const excludedAttachmentsIds = new Set(getInlineFilesIds(inlineFiles).map(({ id }) => id));
7
13
  return attachments.filter((attachment) => {
8
14
  if (supplements.has(attachment.id) && filePredicate) {
9
- return filePredicate(attachment.name);
15
+ return (!excludedAttachmentsIds.has(attachment.id) &&
16
+ filePredicate(attachment.name));
10
17
  }
11
18
  else {
12
- return supplements.has(attachment.id);
19
+ return (!excludedAttachmentsIds.has(attachment.id) &&
20
+ supplements.has(attachment.id));
13
21
  }
14
22
  });
15
23
  };
16
24
  const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate) => {
17
- const inlineFilesAttachmentIds = inlineFiles
18
- .map(({ attachments }) => (attachments === null || attachments === void 0 ? void 0 : attachments.map(({ id }) => ({ id }))) || [])
19
- .flat();
25
+ const inlineFilesAttachmentIds = getInlineFilesIds(inlineFiles);
20
26
  const excludedAttachmentsIds = new Set([...inlineFilesAttachmentIds, ...supplementFiles].map(({ id }) => id));
21
27
  return attachments.filter(({ id, name }) => {
22
28
  if (!excludedAttachmentsIds.has(id) && filePredicate) {
@@ -29,7 +35,7 @@ const getOtherFiles = (inlineFiles, supplementFiles, attachments, filePredicate)
29
35
  };
30
36
  export const useFiles = (modelMap, attachments, filePredicate) => useDeepCompareMemo(() => {
31
37
  const inlineFiles = getInlineFiles(modelMap, attachments);
32
- const supplementFiles = getSupplementFiles(modelMap, attachments, filePredicate);
38
+ const supplementFiles = getSupplementFiles(modelMap, inlineFiles, attachments, filePredicate);
33
39
  const otherFiles = getOtherFiles(inlineFiles, supplementFiles, attachments, filePredicate);
34
40
  return {
35
41
  otherFiles,
@@ -1,4 +1,5 @@
1
1
  import { Keyword, UserProfile } from '@manuscripts/json-schema';
2
+ import { EditorView } from 'prosemirror-view';
2
3
  import React, { Dispatch, SetStateAction } from 'react';
3
4
  import { CommentType, UnsavedComment } from '../../lib/comments';
4
5
  export interface CommentBodyProps {
@@ -14,6 +15,7 @@ export interface CommentBodyProps {
14
15
  saveComment: (comment: CommentType | UnsavedComment) => Promise<CommentType>;
15
16
  handleCreateReply: (id: string) => void;
16
17
  scrollIntoHighlight?: (comment: CommentType | UnsavedComment) => void;
18
+ onFocusOut?: (view: EditorView, event: Event) => boolean;
17
19
  }
18
20
  export declare const CommentBody: React.FC<CommentBodyProps & {
19
21
  setIsEditing: Dispatch<SetStateAction<boolean | undefined>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/style-guide",
3
3
  "description": "Shared components for Manuscripts applications",
4
- "version": "1.1.11",
4
+ "version": "1.1.13",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -36,10 +36,10 @@
36
36
  "@formatjs/intl-relativetimeformat": "^4.5.9",
37
37
  "@formatjs/intl-utils": "^2.2.0",
38
38
  "@manuscripts/assets": "^0.6.2",
39
- "@manuscripts/transform": "^1.3.0",
39
+ "@manuscripts/transform": "^1.3.1",
40
40
  "@manuscripts/json-schema": "^2.0.2",
41
41
  "@manuscripts/title-editor": "^1.1.0",
42
- "@manuscripts/comment-editor": "^1.0.1",
42
+ "@manuscripts/comment-editor": "^1.0.2",
43
43
  "@reach/tabs": "^0.11.2",
44
44
  "formik": "^2.2.9",
45
45
  "date-fns": "^2.29.3",