@scm-manager/ui-components 2.30.2-20220116-102851 → 2.31.1-20220118-142503

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-manager/ui-components",
3
- "version": "2.30.2-20220116-102851",
3
+ "version": "2.31.1-20220118-142503",
4
4
  "description": "UI Components for SCM-Manager and its plugins",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "@scm-manager/jest-preset": "^2.13.0",
26
26
  "@scm-manager/prettier-config": "^2.10.1",
27
27
  "@scm-manager/tsconfig": "^2.12.0",
28
- "@scm-manager/ui-tests": "^2.30.2-20220116-102851",
28
+ "@scm-manager/ui-tests": "^2.31.1-20220118-142503",
29
29
  "@storybook/addon-actions": "^6.3.12",
30
30
  "@storybook/addon-storyshots": "^6.3.12",
31
31
  "@storybook/builder-webpack5": "^6.3.12",
@@ -66,9 +66,9 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@headlessui/react": "^1.4.3",
69
- "@scm-manager/ui-api": "^2.30.2-20220116-102851",
70
- "@scm-manager/ui-extensions": "^2.30.2-20220116-102851",
71
- "@scm-manager/ui-types": "^2.30.2-20220116-102851",
69
+ "@scm-manager/ui-api": "^2.31.1-20220118-142503",
70
+ "@scm-manager/ui-extensions": "^2.31.1-20220118-142503",
71
+ "@scm-manager/ui-types": "^2.31.1-20220118-142503",
72
72
  "classnames": "^2.2.6",
73
73
  "date-fns": "^2.4.1",
74
74
  "deepmerge": "^4.2.2",
@@ -37,6 +37,7 @@ type Props = {
37
37
  label?: string;
38
38
  testId?: string;
39
39
  searchPlaceholder?: string;
40
+ groupAriaLabelledby?: string;
40
41
  };
41
42
 
42
43
  const createAbsoluteLink = (url: string) => {
@@ -52,7 +53,8 @@ const OverviewPageActions: FC<Props> = ({
52
53
  groupSelected,
53
54
  label,
54
55
  testId,
55
- searchPlaceholder
56
+ searchPlaceholder,
57
+ groupAriaLabelledby
56
58
  }) => {
57
59
  const history = useHistory();
58
60
  const location = useLocation();
@@ -62,6 +64,7 @@ const OverviewPageActions: FC<Props> = ({
62
64
  const groupSelector = groups && (
63
65
  <div className="column is-flex">
64
66
  <Select
67
+ ariaLabelledby={groupAriaLabelledby}
65
68
  className="is-fullwidth"
66
69
  options={groups.map(g => ({ value: g, label: g }))}
67
70
  value={currentGroup}
package/src/Tag.tsx CHANGED
@@ -24,6 +24,7 @@
24
24
  import React, { FC } from "react";
25
25
  import classNames from "classnames";
26
26
  import { Color, Size } from "./styleConstants";
27
+ import { useTranslation } from "react-i18next";
27
28
 
28
29
  type Props = {
29
30
  className?: string;
@@ -51,8 +52,10 @@ const Tag: FC<Props> = ({
51
52
  title,
52
53
  onClick,
53
54
  onRemove,
54
- children,
55
+ children
55
56
  }) => {
57
+ const [t] = useTranslation("commons");
58
+
56
59
  let showIcon = null;
57
60
  if (icon) {
58
61
  showIcon = (
@@ -64,7 +67,7 @@ const Tag: FC<Props> = ({
64
67
  }
65
68
  let showDelete = null;
66
69
  if (onRemove) {
67
- showDelete = <button className="tag is-delete" onClick={onRemove} />;
70
+ showDelete = <button className="tag is-delete" onClick={onRemove} aria-label={t("tag.delete")} />;
68
71
  }
69
72
 
70
73
  return (
@@ -78,7 +81,7 @@ const Tag: FC<Props> = ({
78
81
  {
79
82
  "is-outlined": outlined,
80
83
  "is-rounded": rounded,
81
- "is-clickable": onClick,
84
+ "is-clickable": onClick
82
85
  },
83
86
  size === "small" && smallClassNames
84
87
  )}
@@ -34,6 +34,7 @@ exports[`Storyshots BranchSelector Default 1`] = `
34
34
  className="control select is-fullwidth"
35
35
  >
36
36
  <select
37
+ aria-labelledby="branch-select_0"
37
38
  disabled={false}
38
39
  onBlur={[Function]}
39
40
  onChange={[Function]}
@@ -3048,7 +3049,6 @@ exports[`Storyshots Forms/Radio Default 1`] = `
3048
3049
  className="radio mr-2"
3049
3050
  >
3050
3051
  <input
3051
- aria-describedby="radio_56"
3052
3052
  aria-labelledby="radio_55"
3053
3053
  checked={false}
3054
3054
  onBlur={[Function]}
@@ -3070,7 +3070,6 @@ exports[`Storyshots Forms/Radio Default 1`] = `
3070
3070
  className="radio mr-2"
3071
3071
  >
3072
3072
  <input
3073
- aria-describedby="radio_58"
3074
3073
  aria-labelledby="radio_57"
3075
3074
  checked={true}
3076
3075
  onBlur={[Function]}
@@ -3100,7 +3099,6 @@ exports[`Storyshots Forms/Radio Disabled 1`] = `
3100
3099
  disabled={true}
3101
3100
  >
3102
3101
  <input
3103
- aria-describedby="radio_60"
3104
3102
  aria-labelledby="radio_59"
3105
3103
  checked={true}
3106
3104
  disabled={true}
@@ -3128,7 +3126,6 @@ Array [
3128
3126
  className="radio mr-2"
3129
3127
  >
3130
3128
  <input
3131
- aria-describedby="radio_68"
3132
3129
  aria-labelledby="radio_67"
3133
3130
  checked={false}
3134
3131
  onBlur={[Function]}
@@ -3160,7 +3157,6 @@ exports[`Storyshots Forms/Radio ReactHookForm 1`] = `
3160
3157
  className="radio mr-2"
3161
3158
  >
3162
3159
  <input
3163
- aria-describedby="radio_70"
3164
3160
  aria-labelledby="radio_69"
3165
3161
  defaultChecked={true}
3166
3162
  name="rememberMe"
@@ -3184,7 +3180,6 @@ exports[`Storyshots Forms/Radio ReactHookForm 1`] = `
3184
3180
  className="radio mr-2"
3185
3181
  >
3186
3182
  <input
3187
- aria-describedby="radio_72"
3188
3183
  aria-labelledby="radio_71"
3189
3184
  name="rememberMe"
3190
3185
  onBlur={[Function]}
@@ -3208,7 +3203,6 @@ exports[`Storyshots Forms/Radio ReactHookForm 1`] = `
3208
3203
  className="radio mr-2 ml-2"
3209
3204
  >
3210
3205
  <input
3211
- aria-describedby="radio_74"
3212
3206
  aria-labelledby="radio_73"
3213
3207
  name="scramblePassword"
3214
3208
  onBlur={[Function]}
@@ -3232,7 +3226,6 @@ exports[`Storyshots Forms/Radio ReactHookForm 1`] = `
3232
3226
  disabled={true}
3233
3227
  >
3234
3228
  <input
3235
- aria-describedby="radio_76"
3236
3229
  aria-labelledby="radio_75"
3237
3230
  disabled={true}
3238
3231
  name="disabled"
@@ -3256,7 +3249,6 @@ exports[`Storyshots Forms/Radio ReactHookForm 1`] = `
3256
3249
  className="radio mr-2"
3257
3250
  >
3258
3251
  <input
3259
- aria-describedby="radio_78"
3260
3252
  aria-labelledby="radio_77"
3261
3253
  name="readonly"
3262
3254
  onBlur={[Function]}
@@ -3298,7 +3290,6 @@ Array [
3298
3290
  className="radio mr-2"
3299
3291
  >
3300
3292
  <input
3301
- aria-describedby="radio_66"
3302
3293
  aria-labelledby="radio_65"
3303
3294
  checked={false}
3304
3295
  onBlur={[Function]}
@@ -21,7 +21,7 @@
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, { ChangeEvent, FC, FocusEvent } from "react";
24
+ import React, { ChangeEvent, FC, FocusEvent, useMemo } from "react";
25
25
  import classNames from "classnames";
26
26
  import { Help } from "../index";
27
27
  import { createFormFieldWrapper, FieldProps, FieldType, isLegacy, isUsingRef } from "./FormFieldTypes";
@@ -47,8 +47,8 @@ const InnerRadio: FC<FieldProps<BaseProps, HTMLInputElement, boolean>> = ({
47
47
  ariaLabelledby,
48
48
  ...props
49
49
  }) => {
50
- const id = ariaLabelledby || createA11yId("radio");
51
- const helpId = createA11yId("radio");
50
+ const id = useMemo(() => ariaLabelledby || createA11yId("radio"), [ariaLabelledby]);
51
+ const helpId = useMemo(() => createA11yId("radio"), []);
52
52
 
53
53
  const renderHelp = () => {
54
54
  const helpText = props.helpText;
@@ -77,7 +77,7 @@ const InnerRadio: FC<FieldProps<BaseProps, HTMLInputElement, boolean>> = ({
77
77
  }
78
78
  };
79
79
 
80
- const labelElement = props.label ? (<span id={id}>{props.label}</span>) : null;
80
+ const labelElement = props.label ? <span id={id}>{props.label}</span> : null;
81
81
 
82
82
  return (
83
83
  <fieldset className="is-inline-block" disabled={readOnly}>
@@ -98,7 +98,7 @@ const InnerRadio: FC<FieldProps<BaseProps, HTMLInputElement, boolean>> = ({
98
98
  ref={props.innerRef}
99
99
  defaultChecked={defaultChecked}
100
100
  aria-labelledby={id}
101
- aria-describedby={helpId}
101
+ aria-describedby={props.helpText ? helpId : undefined}
102
102
  />{" "}
103
103
  {labelElement}
104
104
  {renderHelp()}
@@ -124,7 +124,7 @@ const InnerSelect: FC<FieldProps<BaseProps, HTMLSelectElement, string>> = ({
124
124
  onChange={handleInput}
125
125
  onBlur={handleBlur}
126
126
  disabled={disabled}
127
- aria-labelledby={label ? a11yId : undefined}
127
+ aria-labelledby={ariaLabelledby || (label ? a11yId : undefined)}
128
128
  aria-describedby={helpText ? helpId : undefined}
129
129
  {...createAttributesForTesting(testId)}
130
130
  >
@@ -0,0 +1,230 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
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";
50
+
51
+ export type MarkdownProps = {
52
+ content: string;
53
+ renderContext?: object;
54
+ renderers?: any;
55
+ skipHtml?: boolean;
56
+ enableAnchorHeadings?: boolean;
57
+ // basePath for markdown links
58
+ basePath?: string;
59
+ permalink?: string;
60
+ mdastPlugins?: AstPlugin[];
61
+ };
62
+
63
+ type Props = RouteComponentProps & WithTranslation & MarkdownProps;
64
+
65
+ type State = {
66
+ contentRef: HTMLDivElement | null | undefined;
67
+ };
68
+
69
+ const xmlMarkupSample = `\`\`\`xml
70
+ <your>
71
+ <xml>
72
+ <content/>
73
+ </xml>
74
+ </your>
75
+ \`\`\``;
76
+
77
+ const MarkdownErrorNotification: FC = () => {
78
+ const [t] = useTranslation("commons");
79
+ return (
80
+ <Notification type="danger">
81
+ <div className="content">
82
+ <p className="subtitle">{t("markdownErrorNotification.title")}</p>
83
+ <p>{t("markdownErrorNotification.description")}</p>
84
+ <pre>
85
+ <code>{xmlMarkupSample}</code>
86
+ </pre>
87
+ <p>
88
+ {t("markdownErrorNotification.spec")}:{" "}
89
+ <a href="https://github.github.com/gfm/" target="_blank" rel="noreferrer">
90
+ GitHub Flavored Markdown Spec
91
+ </a>
92
+ </p>
93
+ </div>
94
+ </Notification>
95
+ );
96
+ };
97
+
98
+ class LazyMarkdownView extends React.Component<Props, State> {
99
+ static contextType = BinderContext;
100
+
101
+ static defaultProps: Partial<Props> = {
102
+ enableAnchorHeadings: false,
103
+ skipHtml: false
104
+ };
105
+
106
+ constructor(props: Props) {
107
+ super(props);
108
+ this.state = {
109
+ contentRef: null
110
+ };
111
+ }
112
+
113
+ shouldComponentUpdate(nextProps: Readonly<Props>, nextState: Readonly<State>): boolean {
114
+ // We have check if the contentRef changed and update afterwards so the page can scroll to the anchor links.
115
+ // Otherwise it can happen that componentDidUpdate is never executed depending on how fast the markdown got rendered
116
+ // We also have to check if props have changed, because we also want to rerender if one of our props has changed
117
+ return this.state.contentRef !== nextState.contentRef || this.props !== nextProps;
118
+ }
119
+
120
+ componentDidUpdate() {
121
+ const { contentRef } = this.state;
122
+ // we have to use componentDidUpdate, because we have to wait until all
123
+ // children are rendered and componentDidMount is called before the
124
+ // markdown content was rendered.
125
+ const hash = this.props.location.hash;
126
+ if (contentRef && hash) {
127
+ // we query only child elements, to avoid strange scrolling with multiple
128
+ // markdown elements on one page.
129
+ const elementId = decodeURIComponent(hash.substring(1) /* remove # */);
130
+ const element = contentRef.querySelector(`[id="${elementId}"]`);
131
+ if (element && element.scrollIntoView) {
132
+ element.scrollIntoView();
133
+ }
134
+ }
135
+ }
136
+
137
+ render() {
138
+ const {
139
+ content,
140
+ renderers,
141
+ renderContext,
142
+ enableAnchorHeadings,
143
+ skipHtml,
144
+ basePath,
145
+ permalink,
146
+ t,
147
+ mdastPlugins = []
148
+ } = this.props;
149
+
150
+ const rendererFactory = this.context.getExtension("markdown-renderer-factory");
151
+ let remarkRendererList = renderers;
152
+
153
+ if (rendererFactory) {
154
+ remarkRendererList = rendererFactory(renderContext);
155
+ }
156
+
157
+ if (!remarkRendererList) {
158
+ remarkRendererList = {};
159
+ }
160
+
161
+ if (enableAnchorHeadings && permalink && !remarkRendererList.heading) {
162
+ remarkRendererList.heading = createMarkdownHeadingRenderer(permalink);
163
+ }
164
+
165
+ let protocolLinkRendererExtensions: ProtocolLinkRendererExtensionMap = {};
166
+ if (!remarkRendererList.link) {
167
+ const extensionPoints = this.context.getExtensions(
168
+ "markdown-renderer.link.protocol"
169
+ ) as ProtocolLinkRendererExtension[];
170
+ protocolLinkRendererExtensions = extensionPoints.reduce<ProtocolLinkRendererExtensionMap>(
171
+ (prev, { protocol, renderer }) => {
172
+ prev[protocol] = renderer;
173
+ return prev;
174
+ },
175
+ {}
176
+ );
177
+ remarkRendererList.link = createMarkdownLinkRenderer(basePath, protocolLinkRendererExtensions);
178
+ }
179
+
180
+ if (!remarkRendererList.code) {
181
+ remarkRendererList.code = MarkdownCodeRenderer;
182
+ }
183
+
184
+ const remarkPlugins = [...mdastPlugins, createChangesetShortlinkParser(t), createValuelessTextAdapter()].map(
185
+ createMdastPlugin
186
+ );
187
+
188
+ let processor = unified()
189
+ .use(parseMarkdown)
190
+ .use(gfm)
191
+ .use(remarkPlugins)
192
+ .use(remark2rehype, { allowDangerousHtml: true });
193
+
194
+ if (!skipHtml) {
195
+ processor = processor.use(raw);
196
+ }
197
+
198
+ processor = processor
199
+ .use(slug)
200
+ .use(
201
+ sanitize,
202
+ merge(gh, {
203
+ attributes: {
204
+ code: ["className"] // Allow className for code elements, this is necessary to extract the code language
205
+ },
206
+ clobberPrefix: "", // Do not prefix user-provided ids and class names,
207
+ protocols: {
208
+ href: Object.keys(protocolLinkRendererExtensions)
209
+ }
210
+ })
211
+ )
212
+ .use(rehype2react, {
213
+ createElement: React.createElement,
214
+ passNode: true,
215
+ components: createComponentList(remarkRendererList, { permalink })
216
+ });
217
+
218
+ const renderedMarkdown: any = processor.processSync(content).result;
219
+
220
+ return (
221
+ <ErrorBoundary fallback={MarkdownErrorNotification}>
222
+ <div ref={el => this.setState({ contentRef: el })} className="content is-word-break">
223
+ {renderedMarkdown}
224
+ </div>
225
+ </ErrorBoundary>
226
+ );
227
+ }
228
+ }
229
+
230
+ export default withRouter(withTranslation("repos")(LazyMarkdownView));
@@ -21,209 +21,16 @@
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 } 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";
24
+ import React, { FC, Suspense } from "react";
25
+ import { MarkdownProps } from "./LazyMarkdownView";
26
+ import Loading from "../Loading";
50
27
 
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
- };
28
+ const LazyMarkdownView = React.lazy(() => import("./LazyMarkdownView"));
63
29
 
64
- type State = {
65
- contentRef: HTMLDivElement | null | undefined;
66
- };
30
+ const MarkdownView: FC<MarkdownProps> = props => (
31
+ <Suspense fallback={<Loading />}>
32
+ <LazyMarkdownView {...props} />
33
+ </Suspense>
34
+ );
67
35
 
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));
36
+ export default MarkdownView;