@scm-manager/ui-components 2.31.1-20220118-144252 → 2.31.1

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.
@@ -33,7 +33,18 @@ class ButtonGroup extends React.Component<Props> {
33
33
  render() {
34
34
  const { className, children } = this.props;
35
35
 
36
- return <div className={classNames("buttons", className)}>{children}</div>;
36
+ const childWrapper: ReactNode[] = [];
37
+ React.Children.forEach(children, (child) => {
38
+ if (child) {
39
+ childWrapper.push(
40
+ <div className="control" key={childWrapper.length}>
41
+ {child}
42
+ </div>
43
+ );
44
+ }
45
+ });
46
+
47
+ return <div className={classNames("field", "is-grouped", className)}>{childWrapper}</div>;
37
48
  }
38
49
  }
39
50
 
@@ -25,7 +25,6 @@ import React, { FC, useState } from "react";
25
25
  import styled from "styled-components";
26
26
  import InputField from "./InputField";
27
27
  import { AddButton } from "../buttons";
28
- import { devices } from "../devices";
29
28
 
30
29
  type Props = {
31
30
  addEntry: (key: string, value: string) => void;
@@ -43,15 +42,8 @@ const FullWidthInputField = styled(InputField)`
43
42
  width: 100%;
44
43
  `;
45
44
 
46
- const MobileWrappedDiv = styled.div`
47
- @media screen and (min-width: ${devices.tablet.width}px) {
48
- & > ${FullWidthInputField} {
49
- margin-right: 1.5rem;
50
- }
51
- }
52
- @media screen and (max-width: ${devices.mobile.width}px) {
53
- flex-wrap: wrap;
54
- }
45
+ const MarginTopButton = styled(AddButton)`
46
+ margin-top: 2rem;
55
47
  `;
56
48
 
57
49
  const AddKeyValueEntryToTableField: FC<Props> = ({
@@ -63,7 +55,7 @@ const AddKeyValueEntryToTableField: FC<Props> = ({
63
55
  valueHelpText,
64
56
  validateEntry,
65
57
  errorMessage,
66
- addEntry
58
+ addEntry,
67
59
  }) => {
68
60
  const [key, setKey] = useState("");
69
61
  const [value, setValue] = useState("");
@@ -83,8 +75,9 @@ const AddKeyValueEntryToTableField: FC<Props> = ({
83
75
  };
84
76
 
85
77
  return (
86
- <MobileWrappedDiv className="is-flex is-align-items-flex-end">
78
+ <div className="is-flex is-justify-content-space-between">
87
79
  <FullWidthInputField
80
+ className="mr-5"
88
81
  label={keyFieldLabel}
89
82
  errorMessage={errorMessage}
90
83
  onChange={setKey}
@@ -95,6 +88,7 @@ const AddKeyValueEntryToTableField: FC<Props> = ({
95
88
  helpText={keyHelpText}
96
89
  />
97
90
  <FullWidthInputField
91
+ className="mr-5"
98
92
  label={valueFieldLabel}
99
93
  errorMessage={errorMessage}
100
94
  onChange={setValue}
@@ -104,13 +98,12 @@ const AddKeyValueEntryToTableField: FC<Props> = ({
104
98
  disabled={disabled}
105
99
  helpText={valueHelpText}
106
100
  />
107
- <AddButton
108
- className="ml-auto mb-3"
101
+ <MarginTopButton
109
102
  label={buttonLabel}
110
103
  action={add}
111
104
  disabled={disabled || !key || !value || !isValid(key) || !isValid(value)}
112
105
  />
113
- </MobileWrappedDiv>
106
+ </div>
114
107
  );
115
108
  };
116
109
 
@@ -51,6 +51,11 @@ const PageActionContainer = styled.div`
51
51
  }
52
52
  `;
53
53
 
54
+ const MaxTitleHeight = styled.div`
55
+ // remove blank space in repo create form
56
+ height: 2.25rem;
57
+ `;
58
+
54
59
  export default class Page extends React.Component<Props> {
55
60
  componentDidUpdate() {
56
61
  const textualTitle = this.getTextualTitle();
@@ -85,7 +90,7 @@ export default class Page extends React.Component<Props> {
85
90
 
86
91
  let pageActions = null;
87
92
  let pageActionsExists = false;
88
- React.Children.forEach(children, child => {
93
+ React.Children.forEach(children, (child) => {
89
94
  if (child && !error) {
90
95
  if (this.isPageAction(child)) {
91
96
  pageActions = (
@@ -113,12 +118,10 @@ export default class Page extends React.Component<Props> {
113
118
  <>
114
119
  <div className="columns">
115
120
  <div className="column">
116
- <div className="is-flex is-flex-wrap-wrap is-align-items-center">
117
- <Title className="mb-0 mr-2" title={this.getTextualTitle()}>
118
- {this.getTitleComponent()}
119
- </Title>
120
- {afterTitle}
121
- </div>
121
+ <MaxTitleHeight className="is-flex">
122
+ <Title title={this.getTextualTitle()}>{this.getTitleComponent()}</Title>
123
+ {afterTitle && <div className="ml-2">{afterTitle}</div>}
124
+ </MaxTitleHeight>
122
125
  {subtitle ? <Subtitle>{subtitle}</Subtitle> : null}
123
126
  </div>
124
127
  {pageActions}
@@ -141,7 +144,7 @@ export default class Page extends React.Component<Props> {
141
144
  }
142
145
 
143
146
  const content: ReactNode[] = [];
144
- React.Children.forEach(children, child => {
147
+ React.Children.forEach(children, (child) => {
145
148
  if (child) {
146
149
  if (!this.isPageAction(child)) {
147
150
  content.push(child);
@@ -21,16 +21,209 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import React, { FC, Suspense } from "react";
25
- import { MarkdownProps } from "./LazyMarkdownView";
26
- import Loading from "../Loading";
24
+ import React, { FC } from "react";
25
+ import { RouteComponentProps, withRouter } from "react-router-dom";
26
+ import unified from "unified";
27
+ import parseMarkdown from "remark-parse";
28
+ import sanitize from "rehype-sanitize";
29
+ import remark2rehype from "remark-rehype";
30
+ import rehype2react from "rehype-react";
31
+ import gfm from "remark-gfm";
32
+ import { BinderContext } from "@scm-manager/ui-extensions";
33
+ import ErrorBoundary from "../ErrorBoundary";
34
+ import { create as createMarkdownHeadingRenderer } from "./MarkdownHeadingRenderer";
35
+ import { create as createMarkdownLinkRenderer } from "./MarkdownLinkRenderer";
36
+ import { useTranslation, WithTranslation, withTranslation } from "react-i18next";
37
+ import Notification from "../Notification";
38
+ import { createTransformer as createChangesetShortlinkParser } from "./remarkChangesetShortLinkParser";
39
+ import { createTransformer as createValuelessTextAdapter } from "./remarkValuelessTextAdapter";
40
+ import MarkdownCodeRenderer from "./MarkdownCodeRenderer";
41
+ import { AstPlugin } from "./PluginApi";
42
+ import createMdastPlugin from "./createMdastPlugin";
43
+ // @ts-ignore
44
+ import gh from "hast-util-sanitize/lib/github";
45
+ import raw from "rehype-raw";
46
+ import slug from "rehype-slug";
47
+ import merge from "deepmerge";
48
+ import { createComponentList } from "./createComponentList";
49
+ import { ProtocolLinkRendererExtension, ProtocolLinkRendererExtensionMap } from "./markdownExtensions";
27
50
 
28
- const LazyMarkdownView = React.lazy(() => import("./LazyMarkdownView"));
51
+ type Props = RouteComponentProps &
52
+ WithTranslation & {
53
+ content: string;
54
+ renderContext?: object;
55
+ renderers?: any;
56
+ skipHtml?: boolean;
57
+ enableAnchorHeadings?: boolean;
58
+ // basePath for markdown links
59
+ basePath?: string;
60
+ permalink?: string;
61
+ mdastPlugins?: AstPlugin[];
62
+ };
29
63
 
30
- const MarkdownView: FC<MarkdownProps> = props => (
31
- <Suspense fallback={<Loading />}>
32
- <LazyMarkdownView {...props} />
33
- </Suspense>
34
- );
64
+ type State = {
65
+ contentRef: HTMLDivElement | null | undefined;
66
+ };
35
67
 
36
- export default MarkdownView;
68
+ const xmlMarkupSample = `\`\`\`xml
69
+ <your>
70
+ <xml>
71
+ <content/>
72
+ </xml>
73
+ </your>
74
+ \`\`\``;
75
+
76
+ const MarkdownErrorNotification: FC = () => {
77
+ const [t] = useTranslation("commons");
78
+ return (
79
+ <Notification type="danger">
80
+ <div className="content">
81
+ <p className="subtitle">{t("markdownErrorNotification.title")}</p>
82
+ <p>{t("markdownErrorNotification.description")}</p>
83
+ <pre>
84
+ <code>{xmlMarkupSample}</code>
85
+ </pre>
86
+ <p>
87
+ {t("markdownErrorNotification.spec")}:{" "}
88
+ <a href="https://github.github.com/gfm/" target="_blank" rel="noreferrer">
89
+ GitHub Flavored Markdown Spec
90
+ </a>
91
+ </p>
92
+ </div>
93
+ </Notification>
94
+ );
95
+ };
96
+
97
+ class MarkdownView extends React.Component<Props, State> {
98
+ static contextType = BinderContext;
99
+
100
+ static defaultProps: Partial<Props> = {
101
+ enableAnchorHeadings: false,
102
+ skipHtml: false,
103
+ };
104
+
105
+ constructor(props: Props) {
106
+ super(props);
107
+ this.state = {
108
+ contentRef: null,
109
+ };
110
+ }
111
+
112
+ shouldComponentUpdate(nextProps: Readonly<Props>, nextState: Readonly<State>): boolean {
113
+ // We have check if the contentRef changed and update afterwards so the page can scroll to the anchor links.
114
+ // Otherwise it can happen that componentDidUpdate is never executed depending on how fast the markdown got rendered
115
+ // We also have to check if props have changed, because we also want to rerender if one of our props has changed
116
+ return this.state.contentRef !== nextState.contentRef || this.props !== nextProps;
117
+ }
118
+
119
+ componentDidUpdate() {
120
+ const { contentRef } = this.state;
121
+ // we have to use componentDidUpdate, because we have to wait until all
122
+ // children are rendered and componentDidMount is called before the
123
+ // markdown content was rendered.
124
+ const hash = this.props.location.hash;
125
+ if (contentRef && hash) {
126
+ // we query only child elements, to avoid strange scrolling with multiple
127
+ // markdown elements on one page.
128
+ const elementId = decodeURIComponent(hash.substring(1) /* remove # */);
129
+ const element = contentRef.querySelector(`[id="${elementId}"]`);
130
+ if (element && element.scrollIntoView) {
131
+ element.scrollIntoView();
132
+ }
133
+ }
134
+ }
135
+
136
+ render() {
137
+ const {
138
+ content,
139
+ renderers,
140
+ renderContext,
141
+ enableAnchorHeadings,
142
+ skipHtml,
143
+ basePath,
144
+ permalink,
145
+ t,
146
+ mdastPlugins = [],
147
+ } = this.props;
148
+
149
+ const rendererFactory = this.context.getExtension("markdown-renderer-factory");
150
+ let remarkRendererList = renderers;
151
+
152
+ if (rendererFactory) {
153
+ remarkRendererList = rendererFactory(renderContext);
154
+ }
155
+
156
+ if (!remarkRendererList) {
157
+ remarkRendererList = {};
158
+ }
159
+
160
+ if (enableAnchorHeadings && permalink && !remarkRendererList.heading) {
161
+ remarkRendererList.heading = createMarkdownHeadingRenderer(permalink);
162
+ }
163
+
164
+ let protocolLinkRendererExtensions: ProtocolLinkRendererExtensionMap = {};
165
+ if (!remarkRendererList.link) {
166
+ const extensionPoints = this.context.getExtensions(
167
+ "markdown-renderer.link.protocol"
168
+ ) as ProtocolLinkRendererExtension[];
169
+ protocolLinkRendererExtensions = extensionPoints.reduce<ProtocolLinkRendererExtensionMap>(
170
+ (prev, { protocol, renderer }) => {
171
+ prev[protocol] = renderer;
172
+ return prev;
173
+ },
174
+ {}
175
+ );
176
+ remarkRendererList.link = createMarkdownLinkRenderer(basePath, protocolLinkRendererExtensions);
177
+ }
178
+
179
+ if (!remarkRendererList.code) {
180
+ remarkRendererList.code = MarkdownCodeRenderer;
181
+ }
182
+
183
+ const remarkPlugins = [...mdastPlugins, createChangesetShortlinkParser(t), createValuelessTextAdapter()].map(
184
+ createMdastPlugin
185
+ );
186
+
187
+ let processor = unified()
188
+ .use(parseMarkdown)
189
+ .use(gfm)
190
+ .use(remarkPlugins)
191
+ .use(remark2rehype, { allowDangerousHtml: true });
192
+
193
+ if (!skipHtml) {
194
+ processor = processor.use(raw);
195
+ }
196
+
197
+ processor = processor
198
+ .use(slug)
199
+ .use(
200
+ sanitize,
201
+ merge(gh, {
202
+ attributes: {
203
+ code: ["className"], // Allow className for code elements, this is necessary to extract the code language
204
+ },
205
+ clobberPrefix: "", // Do not prefix user-provided ids and class names,
206
+ protocols: {
207
+ href: Object.keys(protocolLinkRendererExtensions),
208
+ },
209
+ })
210
+ )
211
+ .use(rehype2react, {
212
+ createElement: React.createElement,
213
+ passNode: true,
214
+ components: createComponentList(remarkRendererList, { permalink }),
215
+ });
216
+
217
+ const renderedMarkdown: any = processor.processSync(content).result;
218
+
219
+ return (
220
+ <ErrorBoundary fallback={MarkdownErrorNotification}>
221
+ <div ref={(el) => this.setState({ contentRef: el })} className="content is-word-break">
222
+ {renderedMarkdown}
223
+ </div>
224
+ </ErrorBoundary>
225
+ );
226
+ }
227
+ }
228
+
229
+ export default withRouter(withTranslation("repos")(MarkdownView));
@@ -25,7 +25,6 @@ import React, { FC, MutableRefObject, useRef } from "react";
25
25
  import classNames from "classnames";
26
26
  import styled from "styled-components";
27
27
  import { Dialog } from "@headlessui/react";
28
- import { devices } from "../devices";
29
28
 
30
29
  type ModalSize = "S" | "M" | "L";
31
30
 
@@ -48,9 +47,6 @@ type Props = {
48
47
  const SizedModal = styled.div<{ size?: ModalSize; overflow: string }>`
49
48
  width: ${props => (props.size ? `${modalSizes[props.size]}%` : "640px")};
50
49
  overflow: ${props => props.overflow};
51
- @media screen and (max-width: ${devices.mobile.width}px) {
52
- width: ${props => (props.size ? `${modalSizes[props.size]}%` : "320px")};
53
- }
54
50
  `;
55
51
 
56
52
  export const Modal: FC<Props> = ({
@@ -64,14 +64,14 @@ const Diff: FC<Props> = ({ diff, ...fileProps }) => {
64
64
  {diff.length === 0 ? (
65
65
  <Notification type="info">{t("diff.noDiffFound")}</Notification>
66
66
  ) : (
67
- diff.map(file => <DiffFile key={createKey(file)} file={file} {...fileProps} />)
67
+ diff.map((file) => <DiffFile key={createKey(file)} file={file} {...fileProps} />)
68
68
  )}
69
69
  </div>
70
70
  );
71
71
  };
72
72
 
73
73
  Diff.defaultProps = {
74
- sideBySide: false
74
+ sideBySide: false,
75
75
  };
76
76
 
77
77
  export default Diff;