Skip to content

Commit d466588

Browse files
committed
add codemirror
1 parent f3861c2 commit d466588

File tree

99 files changed

+14953
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+14953
-452
lines changed

coverage-ts/assets/source-file.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.uncovered {
2+
background: rgba(235, 26, 26, 0.3);
3+
}
4+
.CodeMirror {
5+
border: 1px solid #ccc;
6+
border-radius: 3px;
7+
height: auto;
8+
}
9+
.TS-lineuncovered {
10+
background: rgba(255, 255, 255, 0.3);
11+
width: 24px;
12+
}
13+
/* NOTE: I have to increase the specificity because of semantic-ui */
14+
p.footer-text {
15+
text-align: center;
16+
margin: 3em 0;
17+
}
18+
.gutter-marker {
19+
text-align: center;
20+
font-size: 0.6em;
21+
}

coverage-ts/assets/source-file.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const CodeMirror = require('codemirror');
2+
3+
document.addEventListener('DOMContentLoaded', () => {
4+
const myTextArea = document.getElementById('editor');
5+
const codeMirrorInstance = CodeMirror.fromTextArea(myTextArea, {
6+
readOnly: true,
7+
lineNumbers: true,
8+
lineWrapping: false,
9+
mode: 'text/typescript',
10+
gutters: ['TS-lineuncovered', 'CodeMirror-linenumbers']
11+
});
12+
const annotations = JSON.parse(document.getElementById('annotations').textContent);
13+
const gutters = {};
14+
15+
annotations.forEach((annotation) => {
16+
gutters[annotation.line] = (gutters[annotation.line] || 0) + 1;
17+
codeMirrorInstance.markText(
18+
{ line: annotation.line, ch: annotation.character },
19+
{
20+
line: annotation.line,
21+
ch: annotation.character + annotation.text.length
22+
},
23+
{
24+
className: 'uncovered'
25+
}
26+
);
27+
});
28+
29+
Object.entries(gutters).forEach(([line, count]) => {
30+
const gutterMarker = document.createElement('div');
31+
32+
gutterMarker.textContent = count + 'x';
33+
gutterMarker.classList.add('gutter-marker');
34+
gutterMarker.style.background = 'rgba(255,0,0,' + count * 0.2 + ')';
35+
36+
codeMirrorInstance.setGutterMarker(+line, 'TS-lineuncovered', gutterMarker);
37+
});
38+
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>Button.tsx</title>
6+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css" type="text/css" rel="stylesheet">
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
9+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
10+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
11+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
12+
</head>
13+
<body>
14+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">components/button/Button.tsx</td><td class="">100.00%</td><td class="">80%</td><td class="">66</td><td class="">66</td><td class="">0</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">import React from &#x27;react&#x27;;
15+
import { Box, BoxProps, styles } from &#x27;@sparkpost/matchbox&#x27;;
16+
import styled from &#x27;styled-components&#x27;;
17+
import css from &#x27;@styled-system/css&#x27;;
18+
19+
const StyledButton = styled(Box)&lt;BoxProps&gt;`
20+
${styles.buttonReset}
21+
${css({
22+
border: &#x27;thick&#x27;,
23+
px: &#x27;400&#x27;,
24+
py: &#x27;200&#x27;
25+
})}
26+
27+
cursor: pointer;
28+
&amp;:hover {
29+
${css({
30+
bg: &#x27;scheme.lightAccent&#x27;,
31+
color: &#x27;scheme.fg&#x27;
32+
})}
33+
}
34+
35+
${({ isActive }) =&gt; {
36+
if (isActive) {
37+
return css({
38+
bg: &#x27;scheme.lightAccent&#x27;,
39+
color: &#x27;scheme.heavyAccent&#x27;,
40+
pointerEvents: &#x27;none&#x27;
41+
});
42+
}
43+
}}
44+
`;
45+
46+
interface ButtonProps extends React.ButtonHTMLAttributes&lt;HTMLButtonElement&gt; {
47+
/**
48+
* Disables pointer events and highlights the button
49+
*/
50+
active?: boolean;
51+
children: React.ReactNode;
52+
}
53+
54+
function Button(props: ButtonProps): JSX.Element {
55+
const { children, active, ...rest } = props;
56+
return (
57+
&lt;StyledButton as=&quot;button&quot; type=&quot;button&quot; {...rest} isActive={active}&gt;
58+
{children}
59+
&lt;/StyledButton&gt;
60+
);
61+
}
62+
63+
const StyledGroup = styled.div`
64+
button:not(:first-child) {
65+
margin-left: -2px !important;
66+
}
67+
`;
68+
69+
type GroupProps = {
70+
children: React.ReactNode;
71+
};
72+
73+
/**
74+
* Collapses borders between child Buttons
75+
*/
76+
function Group(props: GroupProps): JSX.Element {
77+
const { children } = props;
78+
return &lt;StyledGroup&gt;{children}&lt;/StyledGroup&gt;;
79+
}
80+
81+
Button.Group = Group;
82+
export default Button;
83+
</textarea><pre id="annotations" style="display:none">[]</pre></div>
84+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Thu, 11 Aug 2022 15:27:29 GMT</p>
85+
</body>
86+
</html>
87+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>index.tsx</title>
6+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css" type="text/css" rel="stylesheet">
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
9+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
10+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
11+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
12+
</head>
13+
<body>
14+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">components/button/index.tsx</td><td class="">100.00%</td><td class="">80%</td><td class="">2</td><td class="">2</td><td class="">0</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">export { default as Button } from &#x27;./Button&#x27;;
15+
</textarea><pre id="annotations" style="display:none">[]</pre></div>
16+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Thu, 11 Aug 2022 15:27:29 GMT</p>
17+
</body>
18+
</html>
19+
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>card.tsx</title>
6+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css" type="text/css" rel="stylesheet">
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.js" type="text/javascript" charset="utf-8"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/mode/javascript/javascript.min.js" type="text/javascript" charset="utf-8"></script>
9+
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.2/codemirror.min.css" type="text/css" rel="stylesheet">
10+
<script src="../../../assets/source-file.js" type="text/javascript" charset="utf-8"></script>
11+
<link href="../../../assets/source-file.css" type="text/css" rel="stylesheet">
12+
</head>
13+
<body>
14+
<div style="margin-top:3em" class="ui container"><h1 class="ui header"><a href="../../../index.html">TypeScript coverage report</a></h1><table style="margin-top:2em" class="ui celled table"><thead class=""><tr class=""><th class="">Filename</th><th class="">Percent</th><th class="">Threshold</th><th class="">Total</th><th class="">Covered</th><th class="">Uncovered</th></tr></thead><tbody class=""><tr class="positive"><td class="">components/card/card.tsx</td><td class="">91.19%</td><td class="">80%</td><td class="">193</td><td class="">176</td><td class="">17</td></tr></tbody></table><textarea id="editor" readonly="" style="margin-top:3em">import React from &#x27;react&#x27;;
15+
import Link from &#x27;next/link&#x27;;
16+
import { Box, BoxProps } from &#x27;@sparkpost/matchbox&#x27;;
17+
import { SimplePortableText } from &#x27;@lib/sanity&#x27;;
18+
import { ArrowForward } from &#x27;@sparkpost/matchbox-icons&#x27;;
19+
import styled from &#x27;styled-components&#x27;;
20+
import css from &#x27;@styled-system/css&#x27;;
21+
import { formatDate } from &#x27;@utils/date&#x27;;
22+
import { Category, categoryColors } from &#x27;@components/category&#x27;;
23+
24+
// Turns block content into plain text
25+
function toPlainText(blocks = []) {
26+
return (
27+
blocks
28+
// loop through each block
29+
.map((block) =&gt; {
30+
// if it&#x27;s not a text block with children or if it is a header,
31+
// return nothing
32+
if (block._type !== &#x27;block&#x27; || !block.children || /^h\d/.test(block.style)) {
33+
return &#x27;&#x27;;
34+
}
35+
// loop through the children spans, and join the
36+
// text strings
37+
return block.children.map((child) =&gt; child.text).join(&#x27;&#x27;);
38+
})
39+
// join the paragraphs leaving split by two linebreaks
40+
.join(&#x27;\n\n&#x27;)
41+
);
42+
}
43+
44+
// TODO: this is temporary, need to find a better way to scale cards
45+
function getRatio(span) {
46+
if (span &gt; 5) {
47+
return &#x27;25%&#x27;;
48+
}
49+
50+
return [&#x27;40%&#x27;, null, &#x27;82%&#x27;, &#x27;60%&#x27;, &#x27;44%&#x27;];
51+
}
52+
53+
const HoverBox = styled.div&lt;BoxProps &amp; { $index: number; $span: number; $url: string }&gt;`
54+
position: absolute;
55+
width: 100%;
56+
height: 100%;
57+
top: 0;
58+
left: 0;
59+
transform: translate3d(0, 0, 0);
60+
transition: transform 200ms ease-in-out, z-index 200ms linear;
61+
z-index: 0;
62+
63+
${({ $url, $index }) =&gt; {
64+
return `
65+
cursor: ${$url ? &#x27;pointer&#x27; : &#x27;&#x27;};
66+
&amp;:hover {
67+
transition: transform 200ms ease-in-out, z-index 200ms linear;
68+
z-index: ${$url ? ($index === 0 ? 2 : 1) : 0};
69+
}
70+
`;
71+
}};
72+
73+
${({ $index, $span, $url }) =&gt;
74+
css({
75+
bg: &#x27;scheme.bg&#x27;,
76+
p: [&#x27;300&#x27;, null, null, &#x27;400&#x27;, &#x27;600&#x27;],
77+
border: &#x27;thick&#x27;,
78+
&#x27;user-select&#x27;: [&#x27;none&#x27;, null, &#x27;inherit&#x27;],
79+
&#x27;&amp;:hover, &amp;:active&#x27;: {
80+
transform: [
81+
`translate3d(0, 0, 0)`,
82+
null,
83+
$url
84+
? `translate3d(${($index * $span) % 12 === 0 ? &#x27;12px&#x27; : &#x27;-12px&#x27;}, -12px, 0)`
85+
: &#x27;translate3d(0, 0, 0)&#x27;
86+
]
87+
}
88+
})}
89+
`;
90+
91+
const BorderBox = styled(Box)&lt;BoxProps&gt;`
92+
margin-top: -1px;
93+
margin-left: -1px;
94+
margin-bottom: -1px;
95+
margin-right: -1px;
96+
text-decoration: none;
97+
display: block;
98+
99+
&amp;,
100+
&amp;:visited,
101+
&amp;:hover {
102+
${css({ color: &#x27;scheme.fg&#x27; })}
103+
}
104+
&amp;:focus {
105+
outline: none;
106+
}
107+
`;
108+
109+
const NegateMargins = styled.div`
110+
* {
111+
margin-bottom: 0;
112+
padding-top: 0;
113+
}
114+
`;
115+
116+
type CardProps = {
117+
content?: Array&lt;any&gt;;
118+
date?: string;
119+
enableCategory?: boolean;
120+
excerpt?: object[];
121+
index?: number; // Used to animate to the right instead of left
122+
span: number;
123+
mobileSpan?: number;
124+
subtitle?: string;
125+
title?: string;
126+
url: string;
127+
};
128+
129+
const Card: React.FC&lt;CardProps&gt; = (props: CardProps) =&gt; {
130+
const { url, span, mobileSpan, index, content, title, subtitle, enableCategory, date, excerpt } =
131+
props;
132+
133+
const category = React.useMemo(() =&gt; {
134+
if (!url) {
135+
return &#x27;&#x27;;
136+
}
137+
return url.split(&#x27;/&#x27;)?.[1];
138+
}, [url]);
139+
140+
const accentColor = React.useMemo(() =&gt; {
141+
if (!url) {
142+
return &#x27;scheme.heavyAccent&#x27;;
143+
}
144+
145+
return categoryColors[category]?.bg || &#x27;scheme.heavyAccent&#x27;;
146+
}, [category, url]);
147+
148+
const smallSpan = mobileSpan || &#x27;6&#x27;;
149+
150+
const card = (
151+
&lt;BorderBox
152+
gridColumn={[`span ${smallSpan}`, null, `span ${span}`]}
153+
pb={getRatio(span)}
154+
minHeight=&quot;12rem&quot;
155+
position=&quot;relative&quot;
156+
as={url ? &#x27;a&#x27; : &#x27;div&#x27;}
157+
&gt;
158+
&lt;Box
159+
position=&quot;absolute&quot;
160+
width=&quot;100%&quot;
161+
height=&quot;100%&quot;
162+
top=&quot;0&quot;
163+
left=&quot;0&quot;
164+
bg={accentColor}
165+
border=&quot;thick&quot;
166+
/&gt;
167+
&lt;HoverBox $url={url} p={[&#x27;200&#x27;, null, &#x27;600&#x27;]} $index={index} $span={span}&gt;
168+
{enableCategory &amp;&amp; url &amp;&amp; &lt;Category category={category} /&gt;}
169+
{date &amp;&amp; (
170+
&lt;Box fontSize=&quot;100&quot; mb=&quot;0&quot; lineHeight=&quot;100&quot;&gt;
171+
{formatDate(date)}
172+
&lt;/Box&gt;
173+
)}
174+
{title &amp;&amp; (
175+
&lt;Box fontSize=&quot;300&quot; fontWeight=&quot;500&quot; mb=&quot;200&quot;&gt;
176+
{title}
177+
&lt;/Box&gt;
178+
)}
179+
{subtitle &amp;&amp; (
180+
&lt;Box fontSize=&quot;200&quot; lineHeight=&quot;200&quot; mb=&quot;200&quot;&gt;
181+
{subtitle}
182+
&lt;/Box&gt;
183+
)}
184+
{excerpt &amp;&amp; (
185+
&lt;Box fontSize=&quot;200&quot; lineHeight=&quot;200&quot; mb=&quot;200&quot;&gt;
186+
{toPlainText(excerpt).substring(0, 180)}
187+
{toPlainText(excerpt).substring(0, 180).length &gt; 179 ? &#x27;...&#x27; : &#x27;&#x27;}
188+
&lt;/Box&gt;
189+
)}
190+
{content &amp;&amp; (
191+
&lt;NegateMargins&gt;
192+
&lt;SimplePortableText blocks={content} /&gt;
193+
&lt;/NegateMargins&gt;
194+
)}
195+
{url &amp;&amp; (
196+
&lt;Box mt=&quot;100&quot;&gt;
197+
&lt;ArrowForward /&gt;
198+
&lt;/Box&gt;
199+
)}
200+
&lt;/HoverBox&gt;
201+
&lt;/BorderBox&gt;
202+
);
203+
204+
return url ? (
205+
&lt;Link href={url} passHref&gt;
206+
{card}
207+
&lt;/Link&gt;
208+
) : (
209+
&lt;&gt;{card}&lt;/&gt;
210+
);
211+
};
212+
213+
export default Card;
214+
</textarea><pre id="annotations" style="display:none">[{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:15,&quot;character&quot;:12,&quot;text&quot;:&quot;block&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:18,&quot;character&quot;:12,&quot;text&quot;:&quot;block&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:18,&quot;character&quot;:18,&quot;text&quot;:&quot;_type&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:18,&quot;character&quot;:40,&quot;text&quot;:&quot;block&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:18,&quot;character&quot;:46,&quot;text&quot;:&quot;children&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:18,&quot;character&quot;:70,&quot;text&quot;:&quot;block&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:18,&quot;character&quot;:76,&quot;text&quot;:&quot;style&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:15,&quot;text&quot;:&quot;block&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:21,&quot;text&quot;:&quot;children&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:30,&quot;text&quot;:&quot;map&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:35,&quot;text&quot;:&quot;child&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:45,&quot;text&quot;:&quot;child&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:51,&quot;text&quot;:&quot;text&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:23,&quot;character&quot;:57,&quot;text&quot;:&quot;join&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:31,&quot;character&quot;:18,&quot;text&quot;:&quot;span&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:32,&quot;character&quot;:6,&quot;text&quot;:&quot;span&quot;,&quot;kind&quot;:1},{&quot;file&quot;:&quot;components/card/card.tsx&quot;,&quot;line&quot;:126,&quot;character&quot;:8,&quot;text&quot;:&quot;accentColor&quot;,&quot;kind&quot;:1}]</pre></div>
215+
<p class="footer-text">TypeScript Coverage Report generated by <a href="https://github.com/plantain-00/type-coverage">type-coverage</a> and <a href="https://github.com/alexcanessa/typescript-coverage-report">typescript-coverage-report</a> at Thu, 11 Aug 2022 15:27:29 GMT</p>
216+
</body>
217+
</html>
218+

0 commit comments

Comments
 (0)