@raketa-builder/markdown-input 0.2.0
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/.turbo/turbo-build.log +8 -0
- package/.turbo/turbo-lint.log +13 -0
- package/CHANGELOG.md +7 -0
- package/dist/index.js +1181 -0
- package/package.json +32 -0
- package/src/MarkdownInput.js +126 -0
- package/src/index.js +4 -0
- package/src/toHTML.js +19 -0
- package/tsconfig.json +5 -0
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raketa-builder/markdown-input",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "TIMING=1 eslint \"**/*.js\"",
|
|
9
|
+
"build": "tsup src/index.js --format cjs --loader \".js=jsx\"",
|
|
10
|
+
"dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"styled-components": "^5.1.0",
|
|
14
|
+
"react": "18.2.0",
|
|
15
|
+
"react-dom": "18.2.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"markdown-it": "13.0.1",
|
|
19
|
+
"markdown-it-attrs": "4.1.4",
|
|
20
|
+
"ui": "*"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/react": "17.0.37",
|
|
24
|
+
"@types/react-dom": "17.0.11",
|
|
25
|
+
"eslint": "7.32.0",
|
|
26
|
+
"eslint-config-custom": "*",
|
|
27
|
+
"react": "18.2.0",
|
|
28
|
+
"tsconfig": "*",
|
|
29
|
+
"tsup": "^6.5.0",
|
|
30
|
+
"typescript": "4.5.2"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
FormGroup,
|
|
4
|
+
Label,
|
|
5
|
+
Textarea,
|
|
6
|
+
buttonReset,
|
|
7
|
+
Hint,
|
|
8
|
+
} from "@raketa-builder/ui";
|
|
9
|
+
import styled from "styled-components";
|
|
10
|
+
import toHTML from "./toHTML";
|
|
11
|
+
|
|
12
|
+
const ICONS = {
|
|
13
|
+
eye: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCAxOCAxOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTAuNzUgOUMwLjc1IDkgMy43NSAzIDkgM0MxNC4yNSAzIDE3LjI1IDkgMTcuMjUgOUMxNy4yNSA5IDE0LjI1IDE1IDkgMTVDMy43NSAxNSAwLjc1IDkgMC43NSA5WiIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPgo8cGF0aCBkPSJNOSAxMS4yNUMxMC4yNDI2IDExLjI1IDExLjI1IDEwLjI0MjYgMTEuMjUgOUMxMS4yNSA3Ljc1NzM2IDEwLjI0MjYgNi43NSA5IDYuNzVDNy43NTczNiA2Ljc1IDYuNzUgNy43NTczNiA2Ljc1IDlDNi43NSAxMC4yNDI2IDcuNzU3MzYgMTEuMjUgOSAxMS4yNVoiIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==",
|
|
14
|
+
questionmark:
|
|
15
|
+
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOCIgaGVpZ2h0PSIxMiIgdmlld0JveD0iMCAwIDggMTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xIDMuMDA0NDhDMS4yMzUxIDIuMzM2MTQgMS42OTkxNSAxLjc3MjU4IDIuMzA5OTUgMS40MTM2MUMyLjkyMDc2IDEuMDU0NjMgMy42Mzg5IDAuOTIzNDE0IDQuMzM3MTggMS4wNDMxOUM1LjAzNTQ2IDEuMTYyOTYgNS42Njg4MiAxLjUyNiA2LjEyNTA4IDIuMDY4QzYuNTgxMzQgMi42MTAwMSA2LjgzMTA2IDMuMjk2IDYuODMgNC4wMDQ0OEM2LjgzIDYuMDA0NDggMy44MyA3LjAwNDQ4IDMuODMgNy4wMDQ0OCIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPgo8cGF0aCBkPSJNMy45MTAwMyAxMS4wMDQ1SDMuOTIwMDMiIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const IconButton = styled.button`
|
|
19
|
+
${buttonReset};
|
|
20
|
+
width: 2em;
|
|
21
|
+
height: 2em;
|
|
22
|
+
border-radius: 50%;
|
|
23
|
+
background-color: ${(props) => props.theme.colors.black};
|
|
24
|
+
background-repeat: no-repeat;
|
|
25
|
+
background-position: center;
|
|
26
|
+
background-size: 50%;
|
|
27
|
+
color: ${(props) => props.theme.colors.white};
|
|
28
|
+
font-weight: 700;
|
|
29
|
+
text-align: center;
|
|
30
|
+
text-decoration: none;
|
|
31
|
+
line-height: 1.5;
|
|
32
|
+
text-indent: -9999px;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
transition: all 0.3s ease-in-out;
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
background-color: ${(props) => props.theme.colors.primary};
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
const TextareaWrapper = styled.div`
|
|
42
|
+
position: relative;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const ButtonToolbar = styled.div`
|
|
46
|
+
position: absolute;
|
|
47
|
+
right: 0.5em;
|
|
48
|
+
bottom: 1em;
|
|
49
|
+
display: flex;
|
|
50
|
+
gap: 0.5em;
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const PreviewPane = styled.div`
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
padding: 1em;
|
|
56
|
+
overflow-y: auto;
|
|
57
|
+
border: 1px dashed ${(props) => props.theme.colors.primary};
|
|
58
|
+
background-color: ${(props) => props.theme.colors.trueWhite};
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const MarkdownInput = ({
|
|
62
|
+
label = "Text",
|
|
63
|
+
height = "200px",
|
|
64
|
+
hint = "",
|
|
65
|
+
documentationLink = "https://guides.github.com/features/mastering-markdown/",
|
|
66
|
+
value,
|
|
67
|
+
onChange,
|
|
68
|
+
...props
|
|
69
|
+
}) => {
|
|
70
|
+
const [open, setOpen] = React.useState(false);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<FormGroup>
|
|
74
|
+
{label && <Label>{label}</Label>}
|
|
75
|
+
|
|
76
|
+
<TextareaWrapper>
|
|
77
|
+
{!open && (
|
|
78
|
+
<Textarea
|
|
79
|
+
value={value}
|
|
80
|
+
style={{
|
|
81
|
+
height,
|
|
82
|
+
resize: "vertical",
|
|
83
|
+
}}
|
|
84
|
+
onChange={(e) => onChange(e.target.value, e)}
|
|
85
|
+
{...props}
|
|
86
|
+
/>
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
{open && (
|
|
90
|
+
<PreviewPane
|
|
91
|
+
style={{
|
|
92
|
+
height,
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<div dangerouslySetInnerHTML={{ __html: toHTML(value) }} />
|
|
96
|
+
</PreviewPane>
|
|
97
|
+
)}
|
|
98
|
+
|
|
99
|
+
<ButtonToolbar>
|
|
100
|
+
<IconButton
|
|
101
|
+
type="button"
|
|
102
|
+
style={{ backgroundImage: `url(${ICONS.eye})` }}
|
|
103
|
+
onClick={() => setOpen(!open)}
|
|
104
|
+
>
|
|
105
|
+
Preview
|
|
106
|
+
</IconButton>
|
|
107
|
+
<IconButton
|
|
108
|
+
as="a"
|
|
109
|
+
style={{
|
|
110
|
+
backgroundImage: `url(${ICONS.questionmark})`,
|
|
111
|
+
backgroundSize: "30%",
|
|
112
|
+
}}
|
|
113
|
+
href={documentationLink}
|
|
114
|
+
target="_blank"
|
|
115
|
+
>
|
|
116
|
+
Help
|
|
117
|
+
</IconButton>
|
|
118
|
+
</ButtonToolbar>
|
|
119
|
+
</TextareaWrapper>
|
|
120
|
+
|
|
121
|
+
<Hint>{hint}</Hint>
|
|
122
|
+
</FormGroup>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export default MarkdownInput;
|
package/src/index.js
ADDED
package/src/toHTML.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import MarkdownIt from "markdown-it";
|
|
2
|
+
import markdownItAttrs from "markdown-it-attrs";
|
|
3
|
+
|
|
4
|
+
const parser = new MarkdownIt({
|
|
5
|
+
html: true,
|
|
6
|
+
breaks: true,
|
|
7
|
+
}).use(markdownItAttrs, {
|
|
8
|
+
// optional, these are default options
|
|
9
|
+
leftDelimiter: "{",
|
|
10
|
+
rightDelimiter: "}",
|
|
11
|
+
allowedAttributes: [], // empty array = all attributes are allowed
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const toHTML = (string, inline = false) => {
|
|
15
|
+
if (!string) return;
|
|
16
|
+
return inline ? parser.renderInline(string) : parser.render(string);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default toHTML;
|