@skitter/assistant_md 1.0.0 → 1.0.2-alpha.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/dist/assistant_md.d.ts +60 -0
- package/dist/assistant_md.d.ts.map +1 -0
- package/dist/assistant_md.js +193 -0
- package/dist/assistant_md.js.map +1 -0
- package/package.json +13 -3
- package/src/assistant_md.tsx +293 -0
- package/tsconfig.json +104 -0
- package/assistant_md.js +0 -119
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export function parseUrlAndString(str: string): {
|
|
2
|
+
type: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}[];
|
|
5
|
+
type NormalText = {
|
|
6
|
+
normal_text: string;
|
|
7
|
+
markdown_text: "normal_text";
|
|
8
|
+
};
|
|
9
|
+
type MdValueContainer = {
|
|
10
|
+
value: MdText;
|
|
11
|
+
};
|
|
12
|
+
type BoldText = {
|
|
13
|
+
bold: MdValueContainer;
|
|
14
|
+
markdown_text: "bold";
|
|
15
|
+
};
|
|
16
|
+
type ItalicText = {
|
|
17
|
+
italic: MdValueContainer;
|
|
18
|
+
markdown_text: "italic";
|
|
19
|
+
};
|
|
20
|
+
type UnderlineText = {
|
|
21
|
+
underline: MdValueContainer;
|
|
22
|
+
markdown_text: "underline";
|
|
23
|
+
};
|
|
24
|
+
type HyperLinkContainer = {
|
|
25
|
+
link: string;
|
|
26
|
+
value: MdText;
|
|
27
|
+
};
|
|
28
|
+
type HyperLinkText = {
|
|
29
|
+
hyperlink: HyperLinkContainer;
|
|
30
|
+
markdown_text: "hyperlink";
|
|
31
|
+
};
|
|
32
|
+
type MdList = {
|
|
33
|
+
list: MdText[];
|
|
34
|
+
};
|
|
35
|
+
type OrdredListText = {
|
|
36
|
+
ordered_list: MdList;
|
|
37
|
+
markdown_text: "ordered_list";
|
|
38
|
+
};
|
|
39
|
+
type UnOrdredListText = {
|
|
40
|
+
unordered_list: MdList;
|
|
41
|
+
markdown_text: "unordered_list";
|
|
42
|
+
};
|
|
43
|
+
type NewlineText = {
|
|
44
|
+
markdown_text: "newline";
|
|
45
|
+
};
|
|
46
|
+
type JoinMdContainer = {
|
|
47
|
+
lhs: MdText;
|
|
48
|
+
rhs: MdText;
|
|
49
|
+
};
|
|
50
|
+
type JoinMdText = {
|
|
51
|
+
join: JoinMdContainer;
|
|
52
|
+
markdown_text: "join";
|
|
53
|
+
};
|
|
54
|
+
type MdText = NormalText | BoldText | ItalicText | UnderlineText | HyperLinkText | OrdredListText | UnOrdredListText | JoinMdText | NewlineText;
|
|
55
|
+
type MdTextProp = {
|
|
56
|
+
mdText: MdText;
|
|
57
|
+
};
|
|
58
|
+
export default function AssistantMd({ mdText }: MdTextProp): JSX.Element;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=assistant_md.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAeA,kCAAkC,GAAG,EAAE,MAAM;;;IA2B5C;AAqDD,kBAAkB;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,wBAAwB;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,gBAAgB;IACd,IAAI,EAAE,gBAAgB,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,kBAAkB;IAChB,MAAM,EAAE,gBAAgB,CAAC;IACzB,aAAa,EAAE,QAAQ,CAAC;CACzB,CAAC;AAEF,qBAAqB;IACnB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,aAAa,EAAE,WAAW,CAAC;CAC5B,CAAC;AAEF,0BAA0B;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAqB;IACnB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,aAAa,EAAE,WAAW,CAAC;CAC5B,CAAC;AAEF,cAAc;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,sBAAsB;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEF,wBAAwB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF,mBAAmB;IACjB,aAAa,EAAE,SAAS,CAAC;CAC1B,CAAC;AAEF,uBAAuB;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,kBAAkB;IAChB,IAAI,EAAE,eAAe,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,cACI,UAAU,GACV,QAAQ,GACR,UAAU,GACV,aAAa,GACb,aAAa,GACb,cAAc,GACd,gBAAgB,GAChB,UAAU,GACV,WAAW,CAAC;AAEhB,kBAAkB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA8ErC,oCAAoC,EAAE,MAAM,EAAE,EAAE,UAAU,eAgDzD","sources":["src/src/assistant_md.tsx","src/assistant_md.tsx"],"sourcesContent":[null,"import React from \"react\";\n\nconst URL_REGEX =\n /[(http(s)?):\\/\\/(www\\.)?a-zA-Z0-9@:%._\\+~#=-]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)/;\n\nconst normalStr = (str: string) => ({\n type: \"normal_str\",\n value: str,\n});\n\nconst urlStr = (str: string) => ({\n type: \"url\",\n value: str,\n});\n\nexport function parseUrlAndString(str: string) {\n const results = [];\n let remaining = str;\n while (remaining) {\n let match = remaining.match(URL_REGEX);\n if (!match) {\n results.push(normalStr(remaining));\n break;\n }\n\n if (match.index !== 0) {\n results.push(normalStr(remaining.slice(0, match.index)));\n results.push(\n urlStr(\n remaining.slice(\n match.index,\n match.index && match.index + match[0].length\n )\n )\n );\n remaining = remaining.slice(match.index && match.index + match[0].length);\n continue;\n }\n results.push(urlStr(remaining.slice(0, match[0].length)));\n remaining = remaining.slice(match[0].length);\n }\n return results;\n}\n\nconst DisplayWithSpace = ({ text }: { text: string }) => {\n return <span style={{ whiteSpace: \"pre-wrap\" }}>{text}</span>;\n};\n\nconst DisplayLineBreaks = ({ text }: { text: string }) => {\n let texts = text.split(\"\\n\");\n let lastOne = texts[texts.length - 1];\n let exceptLastOne = texts.slice(0, texts.length - 1);\n return (\n <>\n {exceptLastOne.reduce(\n (arr: (string | JSX.Element)[], text) => [\n ...arr,\n <DisplayWithSpace text={text} />,\n <br key={arr.length} />,\n ],\n []\n )}\n {<DisplayWithSpace text={lastOne} />}\n </>\n );\n};\n\nconst DisplayURL = ({ text }: { text: string }) => {\n const parsed = parseUrlAndString(text);\n return (\n <>\n {parsed.map(({ type, value }, i) =>\n type === \"url\" ? (\n <a href={value} target=\"_blank\" key={i} rel=\"noreferrer\">\n {value}\n </a>\n ) : (\n <DisplayLineBreaks text={value} key={i}></DisplayLineBreaks>\n )\n )}\n </>\n );\n};\n\ntype MdTypes =\n | \"normal_text\"\n | \"bold\"\n | \"italic\"\n | \"underline\"\n | \"hyperlink\"\n | \"ordered_list\"\n | \"unordered_list\"\n | \"newline\"\n | \"join\";\n\ntype NormalText = {\n normal_text: string;\n markdown_text: \"normal_text\";\n};\n\ntype MdValueContainer = { value: MdText };\n\ntype BoldText = {\n bold: MdValueContainer;\n markdown_text: \"bold\";\n};\n\ntype ItalicText = {\n italic: MdValueContainer;\n markdown_text: \"italic\";\n};\n\ntype UnderlineText = {\n underline: MdValueContainer;\n markdown_text: \"underline\";\n};\n\ntype HyperLinkContainer = {\n link: string;\n value: MdText;\n};\n\ntype HyperLinkText = {\n hyperlink: HyperLinkContainer;\n markdown_text: \"hyperlink\";\n};\n\ntype MdList = {\n list: MdText[];\n};\n\ntype OrdredListText = {\n ordered_list: MdList;\n markdown_text: \"ordered_list\";\n};\n\ntype UnOrdredListText = {\n unordered_list: MdList;\n markdown_text: \"unordered_list\";\n};\n\ntype NewlineText = {\n markdown_text: \"newline\";\n};\n\ntype JoinMdContainer = {\n lhs: MdText;\n rhs: MdText;\n};\n\ntype JoinMdText = {\n join: JoinMdContainer;\n markdown_text: \"join\";\n};\n\ntype MdText =\n | NormalText\n | BoldText\n | ItalicText\n | UnderlineText\n | HyperLinkText\n | OrdredListText\n | UnOrdredListText\n | JoinMdText\n | NewlineText;\n\ntype MdTextProp = { mdText: MdText };\n\ntype NormalRenderes = React.FunctionComponent<{ mdText: MdValueContainer }>;\n\ntype ListRenderers = React.FunctionComponent<{ mdText: MdList }>;\n\ntype TextRenderer = React.FunctionComponent<{ mdText: string }>;\n\ntype JoinMdRenderer = React.FunctionComponent<{ mdText: JoinMdContainer }>;\n\ntype HyperLinkRenderer = React.FunctionComponent<{\n mdText: HyperLinkContainer;\n}>;\n\nconst normalWrapper: (TagName: React.ElementType) => NormalRenderes =\n (TagName: React.ElementType) =>\n ({ mdText }) =>\n (\n <TagName>\n <AssistantMd mdText={mdText.value} />\n </TagName>\n );\n\nconst listWrapper: (TagName: React.ElementType) => ListRenderers =\n (TagName) =>\n ({ mdText: { list } }) =>\n (\n <TagName>\n {list.map((mdText) => (\n <li>\n <AssistantMd mdText={mdText} />\n </li>\n ))}\n </TagName>\n );\n\ntype RenderTypes = MdTypes;\n\ntype MdRenderers =\n | NormalRenderes\n | ListRenderers\n | TextRenderer\n | HyperLinkRenderer\n | JoinMdRenderer;\n\n// type RenderMap = Record<RenderTypes, MdRenderers>;\n\nconst NormalTextMd: TextRenderer = ({ mdText }) => {\n return <DisplayURL text={mdText} />;\n};\n\nconst HyperLinkMd: HyperLinkRenderer = ({ mdText }) => (\n <a href={mdText.link} target=\"_blank\">\n <AssistantMd mdText={mdText.value} />\n </a>\n);\n\nconst JoinMd: JoinMdRenderer = ({ mdText: { lhs, rhs } }) => (\n <>\n <AssistantMd mdText={lhs} />\n <AssistantMd mdText={rhs} />\n </>\n);\n\nconst mdTypeRenderers = {\n normal_text: NormalTextMd,\n bold: normalWrapper(\"strong\"),\n italic: normalWrapper(\"em\"),\n underline: normalWrapper(\"u\"),\n hyperlink: HyperLinkMd,\n ordered_list: listWrapper(\"ol\"),\n unordered_list: listWrapper(\"ul\"),\n newline: () => <br />,\n join: JoinMd,\n};\n\nfunction exhaustiveCheck(param: never) {}\n\nexport default function AssistantMd({ mdText }: MdTextProp) {\n switch (mdText.markdown_text) {\n case \"bold\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"italic\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"normal_text\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"underline\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"hyperlink\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"ordered_list\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"unordered_list\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"join\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"newline\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n return <RendenMDElement />;\n }\n }\n exhaustiveCheck(mdText);\n}\n"],"names":[],"version":3,"file":"assistant_md.d.ts.map"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
var $kmRvl$react = require("react");
|
|
2
|
+
|
|
3
|
+
function $parcel$interopDefault(a) {
|
|
4
|
+
return a && a.__esModule ? a.default : a;
|
|
5
|
+
}
|
|
6
|
+
function $parcel$defineInteropFlag(a) {
|
|
7
|
+
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
8
|
+
}
|
|
9
|
+
function $parcel$export(e, n, v, s) {
|
|
10
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
$parcel$defineInteropFlag(module.exports);
|
|
14
|
+
|
|
15
|
+
$parcel$export(module.exports, "parseUrlAndString", () => $69304f3cd9aa4f81$export$41849f4004f0a2a6);
|
|
16
|
+
$parcel$export(module.exports, "default", () => $69304f3cd9aa4f81$export$2e2bcd8739ae039);
|
|
17
|
+
|
|
18
|
+
const $69304f3cd9aa4f81$var$URL_REGEX = /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
|
|
19
|
+
const $69304f3cd9aa4f81$var$normalStr = (str)=>({
|
|
20
|
+
type: "normal_str",
|
|
21
|
+
value: str
|
|
22
|
+
});
|
|
23
|
+
const $69304f3cd9aa4f81$var$urlStr = (str)=>({
|
|
24
|
+
type: "url",
|
|
25
|
+
value: str
|
|
26
|
+
});
|
|
27
|
+
function $69304f3cd9aa4f81$export$41849f4004f0a2a6(str) {
|
|
28
|
+
const results = [];
|
|
29
|
+
let remaining = str;
|
|
30
|
+
while(remaining){
|
|
31
|
+
let match = remaining.match($69304f3cd9aa4f81$var$URL_REGEX);
|
|
32
|
+
if (!match) {
|
|
33
|
+
results.push($69304f3cd9aa4f81$var$normalStr(remaining));
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (match.index !== 0) {
|
|
37
|
+
results.push($69304f3cd9aa4f81$var$normalStr(remaining.slice(0, match.index)));
|
|
38
|
+
results.push($69304f3cd9aa4f81$var$urlStr(remaining.slice(match.index, match.index && match.index + match[0].length)));
|
|
39
|
+
remaining = remaining.slice(match.index && match.index + match[0].length);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
results.push($69304f3cd9aa4f81$var$urlStr(remaining.slice(0, match[0].length)));
|
|
43
|
+
remaining = remaining.slice(match[0].length);
|
|
44
|
+
}
|
|
45
|
+
return results;
|
|
46
|
+
}
|
|
47
|
+
const $69304f3cd9aa4f81$var$DisplayWithSpace = ({ text: text })=>{
|
|
48
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement("span", {
|
|
49
|
+
style: {
|
|
50
|
+
whiteSpace: "pre-wrap"
|
|
51
|
+
}
|
|
52
|
+
}, text);
|
|
53
|
+
};
|
|
54
|
+
const $69304f3cd9aa4f81$var$DisplayLineBreaks = ({ text: text1 })=>{
|
|
55
|
+
let texts = text1.split("\n");
|
|
56
|
+
let lastOne = texts[texts.length - 1];
|
|
57
|
+
let exceptLastOne = texts.slice(0, texts.length - 1);
|
|
58
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement((0, ($parcel$interopDefault($kmRvl$react))).Fragment, null, exceptLastOne.reduce((arr, text)=>[
|
|
59
|
+
...arr,
|
|
60
|
+
/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$var$DisplayWithSpace, {
|
|
61
|
+
text: text
|
|
62
|
+
}),
|
|
63
|
+
/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement("br", {
|
|
64
|
+
key: arr.length
|
|
65
|
+
}),
|
|
66
|
+
], []), /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$var$DisplayWithSpace, {
|
|
67
|
+
text: lastOne
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
const $69304f3cd9aa4f81$var$DisplayURL = ({ text: text })=>{
|
|
71
|
+
const parsed = $69304f3cd9aa4f81$export$41849f4004f0a2a6(text);
|
|
72
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement((0, ($parcel$interopDefault($kmRvl$react))).Fragment, null, parsed.map(({ type: type , value: value }, i)=>type === "url" ? /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement("a", {
|
|
73
|
+
href: value,
|
|
74
|
+
target: "_blank",
|
|
75
|
+
key: i,
|
|
76
|
+
rel: "noreferrer"
|
|
77
|
+
}, value) : /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$var$DisplayLineBreaks, {
|
|
78
|
+
text: value,
|
|
79
|
+
key: i
|
|
80
|
+
})));
|
|
81
|
+
};
|
|
82
|
+
const $69304f3cd9aa4f81$var$normalWrapper = (TagName)=>({ mdText: mdText })=>/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(TagName, null, /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$export$2e2bcd8739ae039, {
|
|
83
|
+
mdText: mdText.value
|
|
84
|
+
}));
|
|
85
|
+
const $69304f3cd9aa4f81$var$listWrapper = (TagName)=>({ mdText: { list: list } })=>/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(TagName, null, list.map((mdText)=>/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement("li", null, /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$export$2e2bcd8739ae039, {
|
|
86
|
+
mdText: mdText
|
|
87
|
+
}))));
|
|
88
|
+
// type RenderMap = Record<RenderTypes, MdRenderers>;
|
|
89
|
+
const $69304f3cd9aa4f81$var$NormalTextMd = ({ mdText: mdText })=>{
|
|
90
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$var$DisplayURL, {
|
|
91
|
+
text: mdText
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const $69304f3cd9aa4f81$var$HyperLinkMd = ({ mdText: mdText })=>/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement("a", {
|
|
95
|
+
href: mdText.link,
|
|
96
|
+
target: "_blank"
|
|
97
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$export$2e2bcd8739ae039, {
|
|
98
|
+
mdText: mdText.value
|
|
99
|
+
}));
|
|
100
|
+
const $69304f3cd9aa4f81$var$JoinMd = ({ mdText: { lhs: lhs , rhs: rhs } })=>/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement((0, ($parcel$interopDefault($kmRvl$react))).Fragment, null, /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$export$2e2bcd8739ae039, {
|
|
101
|
+
mdText: lhs
|
|
102
|
+
}), /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement($69304f3cd9aa4f81$export$2e2bcd8739ae039, {
|
|
103
|
+
mdText: rhs
|
|
104
|
+
}));
|
|
105
|
+
const $69304f3cd9aa4f81$var$mdTypeRenderers = {
|
|
106
|
+
normal_text: $69304f3cd9aa4f81$var$NormalTextMd,
|
|
107
|
+
bold: $69304f3cd9aa4f81$var$normalWrapper("strong"),
|
|
108
|
+
italic: $69304f3cd9aa4f81$var$normalWrapper("em"),
|
|
109
|
+
underline: $69304f3cd9aa4f81$var$normalWrapper("u"),
|
|
110
|
+
hyperlink: $69304f3cd9aa4f81$var$HyperLinkMd,
|
|
111
|
+
ordered_list: $69304f3cd9aa4f81$var$listWrapper("ol"),
|
|
112
|
+
unordered_list: $69304f3cd9aa4f81$var$listWrapper("ul"),
|
|
113
|
+
newline: ()=>/*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement("br", null),
|
|
114
|
+
join: $69304f3cd9aa4f81$var$JoinMd
|
|
115
|
+
};
|
|
116
|
+
function $69304f3cd9aa4f81$var$exhaustiveCheck(param) {}
|
|
117
|
+
function $69304f3cd9aa4f81$export$2e2bcd8739ae039({ mdText: mdText }) {
|
|
118
|
+
switch(mdText.markdown_text){
|
|
119
|
+
case "bold":
|
|
120
|
+
{
|
|
121
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
122
|
+
let container = mdText[mdText.markdown_text];
|
|
123
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
124
|
+
mdText: container
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
case "italic":
|
|
128
|
+
{
|
|
129
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
130
|
+
let container = mdText[mdText.markdown_text];
|
|
131
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
132
|
+
mdText: container
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
case "normal_text":
|
|
136
|
+
{
|
|
137
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
138
|
+
let container = mdText[mdText.markdown_text];
|
|
139
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
140
|
+
mdText: container
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
case "underline":
|
|
144
|
+
{
|
|
145
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
146
|
+
let container = mdText[mdText.markdown_text];
|
|
147
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
148
|
+
mdText: container
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
case "hyperlink":
|
|
152
|
+
{
|
|
153
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
154
|
+
let container = mdText[mdText.markdown_text];
|
|
155
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
156
|
+
mdText: container
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
case "ordered_list":
|
|
160
|
+
{
|
|
161
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
162
|
+
let container = mdText[mdText.markdown_text];
|
|
163
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
164
|
+
mdText: container
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
case "unordered_list":
|
|
168
|
+
{
|
|
169
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
170
|
+
let container = mdText[mdText.markdown_text];
|
|
171
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
172
|
+
mdText: container
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
case "join":
|
|
176
|
+
{
|
|
177
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
178
|
+
let container = mdText[mdText.markdown_text];
|
|
179
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, {
|
|
180
|
+
mdText: container
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
case "newline":
|
|
184
|
+
{
|
|
185
|
+
let RendenMDElement = $69304f3cd9aa4f81$var$mdTypeRenderers[mdText.markdown_text];
|
|
186
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($kmRvl$react))).createElement(RendenMDElement, null);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
$69304f3cd9aa4f81$var$exhaustiveCheck(mdText);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|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AAM,EAAE,SAAS;kBAAI,CAAC;aAC/C;QACD,KAAK,SAAS;YAAE;gBACd,IAAI,eAAe,GAAG,qCAAe,CAAC,MAAM,CAAC,aAAa,CAAC,AAAC;gBAC5D,qBAAO,0DAAC,eAAe,OAAG,CAAC;aAC5B;KACF;IACD,qCAAe,CAAC,MAAM,CAAC,CAAC;CACzB","sources":["src/assistant_md.tsx"],"sourcesContent":["import React from \"react\";\n\nconst URL_REGEX =\n /[(http(s)?):\\/\\/(www\\.)?a-zA-Z0-9@:%._\\+~#=-]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)/;\n\nconst normalStr = (str: string) => ({\n type: \"normal_str\",\n value: str,\n});\n\nconst urlStr = (str: string) => ({\n type: \"url\",\n value: str,\n});\n\nexport function parseUrlAndString(str: string) {\n const results = [];\n let remaining = str;\n while (remaining) {\n let match = remaining.match(URL_REGEX);\n if (!match) {\n results.push(normalStr(remaining));\n break;\n }\n\n if (match.index !== 0) {\n results.push(normalStr(remaining.slice(0, match.index)));\n results.push(\n urlStr(\n remaining.slice(\n match.index,\n match.index && match.index + match[0].length\n )\n )\n );\n remaining = remaining.slice(match.index && match.index + match[0].length);\n continue;\n }\n results.push(urlStr(remaining.slice(0, match[0].length)));\n remaining = remaining.slice(match[0].length);\n }\n return results;\n}\n\nconst DisplayWithSpace = ({ text }: { text: string }) => {\n return <span style={{ whiteSpace: \"pre-wrap\" }}>{text}</span>;\n};\n\nconst DisplayLineBreaks = ({ text }: { text: string }) => {\n let texts = text.split(\"\\n\");\n let lastOne = texts[texts.length - 1];\n let exceptLastOne = texts.slice(0, texts.length - 1);\n return (\n <>\n {exceptLastOne.reduce(\n (arr: (string | JSX.Element)[], text) => [\n ...arr,\n <DisplayWithSpace text={text} />,\n <br key={arr.length} />,\n ],\n []\n )}\n {<DisplayWithSpace text={lastOne} />}\n </>\n );\n};\n\nconst DisplayURL = ({ text }: { text: string }) => {\n const parsed = parseUrlAndString(text);\n return (\n <>\n {parsed.map(({ type, value }, i) =>\n type === \"url\" ? (\n <a href={value} target=\"_blank\" key={i} rel=\"noreferrer\">\n {value}\n </a>\n ) : (\n <DisplayLineBreaks text={value} key={i}></DisplayLineBreaks>\n )\n )}\n </>\n );\n};\n\ntype MdTypes =\n | \"normal_text\"\n | \"bold\"\n | \"italic\"\n | \"underline\"\n | \"hyperlink\"\n | \"ordered_list\"\n | \"unordered_list\"\n | \"newline\"\n | \"join\";\n\ntype NormalText = {\n normal_text: string;\n markdown_text: \"normal_text\";\n};\n\ntype MdValueContainer = { value: MdText };\n\ntype BoldText = {\n bold: MdValueContainer;\n markdown_text: \"bold\";\n};\n\ntype ItalicText = {\n italic: MdValueContainer;\n markdown_text: \"italic\";\n};\n\ntype UnderlineText = {\n underline: MdValueContainer;\n markdown_text: \"underline\";\n};\n\ntype HyperLinkContainer = {\n link: string;\n value: MdText;\n};\n\ntype HyperLinkText = {\n hyperlink: HyperLinkContainer;\n markdown_text: \"hyperlink\";\n};\n\ntype MdList = {\n list: MdText[];\n};\n\ntype OrdredListText = {\n ordered_list: MdList;\n markdown_text: \"ordered_list\";\n};\n\ntype UnOrdredListText = {\n unordered_list: MdList;\n markdown_text: \"unordered_list\";\n};\n\ntype NewlineText = {\n markdown_text: \"newline\";\n};\n\ntype JoinMdContainer = {\n lhs: MdText;\n rhs: MdText;\n};\n\ntype JoinMdText = {\n join: JoinMdContainer;\n markdown_text: \"join\";\n};\n\ntype MdText =\n | NormalText\n | BoldText\n | ItalicText\n | UnderlineText\n | HyperLinkText\n | OrdredListText\n | UnOrdredListText\n | JoinMdText\n | NewlineText;\n\ntype MdTextProp = { mdText: MdText };\n\ntype NormalRenderes = React.FunctionComponent<{ mdText: MdValueContainer }>;\n\ntype ListRenderers = React.FunctionComponent<{ mdText: MdList }>;\n\ntype TextRenderer = React.FunctionComponent<{ mdText: string }>;\n\ntype JoinMdRenderer = React.FunctionComponent<{ mdText: JoinMdContainer }>;\n\ntype HyperLinkRenderer = React.FunctionComponent<{\n mdText: HyperLinkContainer;\n}>;\n\nconst normalWrapper: (TagName: React.ElementType) => NormalRenderes =\n (TagName: React.ElementType) =>\n ({ mdText }) =>\n (\n <TagName>\n <AssistantMd mdText={mdText.value} />\n </TagName>\n );\n\nconst listWrapper: (TagName: React.ElementType) => ListRenderers =\n (TagName) =>\n ({ mdText: { list } }) =>\n (\n <TagName>\n {list.map((mdText) => (\n <li>\n <AssistantMd mdText={mdText} />\n </li>\n ))}\n </TagName>\n );\n\ntype RenderTypes = MdTypes;\n\ntype MdRenderers =\n | NormalRenderes\n | ListRenderers\n | TextRenderer\n | HyperLinkRenderer\n | JoinMdRenderer;\n\n// type RenderMap = Record<RenderTypes, MdRenderers>;\n\nconst NormalTextMd: TextRenderer = ({ mdText }) => {\n return <DisplayURL text={mdText} />;\n};\n\nconst HyperLinkMd: HyperLinkRenderer = ({ mdText }) => (\n <a href={mdText.link} target=\"_blank\">\n <AssistantMd mdText={mdText.value} />\n </a>\n);\n\nconst JoinMd: JoinMdRenderer = ({ mdText: { lhs, rhs } }) => (\n <>\n <AssistantMd mdText={lhs} />\n <AssistantMd mdText={rhs} />\n </>\n);\n\nconst mdTypeRenderers = {\n normal_text: NormalTextMd,\n bold: normalWrapper(\"strong\"),\n italic: normalWrapper(\"em\"),\n underline: normalWrapper(\"u\"),\n hyperlink: HyperLinkMd,\n ordered_list: listWrapper(\"ol\"),\n unordered_list: listWrapper(\"ul\"),\n newline: () => <br />,\n join: JoinMd,\n};\n\nfunction exhaustiveCheck(param: never) {}\n\nexport default function AssistantMd({ mdText }: MdTextProp) {\n switch (mdText.markdown_text) {\n case \"bold\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"italic\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"normal_text\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"underline\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"hyperlink\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"ordered_list\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"unordered_list\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"join\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n let container = mdText[mdText.markdown_text];\n return <RendenMDElement mdText={container} />;\n }\n case \"newline\": {\n let RendenMDElement = mdTypeRenderers[mdText.markdown_text];\n return <RendenMDElement />;\n }\n }\n exhaustiveCheck(mdText);\n}\n"],"names":[],"version":3,"file":"assistant_md.js.map"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skitter/assistant_md",
|
|
3
|
-
"version": "1.0.0",
|
|
3
|
+
"version": "1.0.2-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
5
|
+
"source": "src/assistant_md.tsx",
|
|
6
|
+
"main": "dist/assistant_md.js",
|
|
7
|
+
"types": "dist/assistant_md.d.ts",
|
|
6
8
|
"scripts": {
|
|
7
|
-
"
|
|
9
|
+
"watch": "parcel watch",
|
|
10
|
+
"build": "parcel build"
|
|
8
11
|
},
|
|
9
12
|
"keywords": [],
|
|
10
13
|
"author": "",
|
|
@@ -14,5 +17,12 @@
|
|
|
14
17
|
},
|
|
15
18
|
"volta": {
|
|
16
19
|
"node": "14.19.3"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@parcel/packager-ts": "^2.6.0",
|
|
23
|
+
"@parcel/transformer-typescript-types": "^2.6.0",
|
|
24
|
+
"@types/react": "^18.0.12",
|
|
25
|
+
"parcel": "^2.6.0",
|
|
26
|
+
"typescript": "^4.7.3"
|
|
17
27
|
}
|
|
18
28
|
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
const URL_REGEX =
|
|
4
|
+
/[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
|
|
5
|
+
|
|
6
|
+
const normalStr = (str: string) => ({
|
|
7
|
+
type: "normal_str",
|
|
8
|
+
value: str,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const urlStr = (str: string) => ({
|
|
12
|
+
type: "url",
|
|
13
|
+
value: str,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function parseUrlAndString(str: string) {
|
|
17
|
+
const results = [];
|
|
18
|
+
let remaining = str;
|
|
19
|
+
while (remaining) {
|
|
20
|
+
let match = remaining.match(URL_REGEX);
|
|
21
|
+
if (!match) {
|
|
22
|
+
results.push(normalStr(remaining));
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (match.index !== 0) {
|
|
27
|
+
results.push(normalStr(remaining.slice(0, match.index)));
|
|
28
|
+
results.push(
|
|
29
|
+
urlStr(
|
|
30
|
+
remaining.slice(
|
|
31
|
+
match.index,
|
|
32
|
+
match.index && match.index + match[0].length
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
remaining = remaining.slice(match.index && match.index + match[0].length);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
results.push(urlStr(remaining.slice(0, match[0].length)));
|
|
40
|
+
remaining = remaining.slice(match[0].length);
|
|
41
|
+
}
|
|
42
|
+
return results;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const DisplayWithSpace = ({ text }: { text: string }) => {
|
|
46
|
+
return <span style={{ whiteSpace: "pre-wrap" }}>{text}</span>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const DisplayLineBreaks = ({ text }: { text: string }) => {
|
|
50
|
+
let texts = text.split("\n");
|
|
51
|
+
let lastOne = texts[texts.length - 1];
|
|
52
|
+
let exceptLastOne = texts.slice(0, texts.length - 1);
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
{exceptLastOne.reduce(
|
|
56
|
+
(arr: (string | JSX.Element)[], text) => [
|
|
57
|
+
...arr,
|
|
58
|
+
<DisplayWithSpace text={text} />,
|
|
59
|
+
<br key={arr.length} />,
|
|
60
|
+
],
|
|
61
|
+
[]
|
|
62
|
+
)}
|
|
63
|
+
{<DisplayWithSpace text={lastOne} />}
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const DisplayURL = ({ text }: { text: string }) => {
|
|
69
|
+
const parsed = parseUrlAndString(text);
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
{parsed.map(({ type, value }, i) =>
|
|
73
|
+
type === "url" ? (
|
|
74
|
+
<a href={value} target="_blank" key={i} rel="noreferrer">
|
|
75
|
+
{value}
|
|
76
|
+
</a>
|
|
77
|
+
) : (
|
|
78
|
+
<DisplayLineBreaks text={value} key={i}></DisplayLineBreaks>
|
|
79
|
+
)
|
|
80
|
+
)}
|
|
81
|
+
</>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type MdTypes =
|
|
86
|
+
| "normal_text"
|
|
87
|
+
| "bold"
|
|
88
|
+
| "italic"
|
|
89
|
+
| "underline"
|
|
90
|
+
| "hyperlink"
|
|
91
|
+
| "ordered_list"
|
|
92
|
+
| "unordered_list"
|
|
93
|
+
| "newline"
|
|
94
|
+
| "join";
|
|
95
|
+
|
|
96
|
+
type NormalText = {
|
|
97
|
+
normal_text: string;
|
|
98
|
+
markdown_text: "normal_text";
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type MdValueContainer = { value: MdText };
|
|
102
|
+
|
|
103
|
+
type BoldText = {
|
|
104
|
+
bold: MdValueContainer;
|
|
105
|
+
markdown_text: "bold";
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
type ItalicText = {
|
|
109
|
+
italic: MdValueContainer;
|
|
110
|
+
markdown_text: "italic";
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
type UnderlineText = {
|
|
114
|
+
underline: MdValueContainer;
|
|
115
|
+
markdown_text: "underline";
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
type HyperLinkContainer = {
|
|
119
|
+
link: string;
|
|
120
|
+
value: MdText;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type HyperLinkText = {
|
|
124
|
+
hyperlink: HyperLinkContainer;
|
|
125
|
+
markdown_text: "hyperlink";
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
type MdList = {
|
|
129
|
+
list: MdText[];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
type OrdredListText = {
|
|
133
|
+
ordered_list: MdList;
|
|
134
|
+
markdown_text: "ordered_list";
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
type UnOrdredListText = {
|
|
138
|
+
unordered_list: MdList;
|
|
139
|
+
markdown_text: "unordered_list";
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
type NewlineText = {
|
|
143
|
+
markdown_text: "newline";
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
type JoinMdContainer = {
|
|
147
|
+
lhs: MdText;
|
|
148
|
+
rhs: MdText;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
type JoinMdText = {
|
|
152
|
+
join: JoinMdContainer;
|
|
153
|
+
markdown_text: "join";
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
type MdText =
|
|
157
|
+
| NormalText
|
|
158
|
+
| BoldText
|
|
159
|
+
| ItalicText
|
|
160
|
+
| UnderlineText
|
|
161
|
+
| HyperLinkText
|
|
162
|
+
| OrdredListText
|
|
163
|
+
| UnOrdredListText
|
|
164
|
+
| JoinMdText
|
|
165
|
+
| NewlineText;
|
|
166
|
+
|
|
167
|
+
type MdTextProp = { mdText: MdText };
|
|
168
|
+
|
|
169
|
+
type NormalRenderes = React.FunctionComponent<{ mdText: MdValueContainer }>;
|
|
170
|
+
|
|
171
|
+
type ListRenderers = React.FunctionComponent<{ mdText: MdList }>;
|
|
172
|
+
|
|
173
|
+
type TextRenderer = React.FunctionComponent<{ mdText: string }>;
|
|
174
|
+
|
|
175
|
+
type JoinMdRenderer = React.FunctionComponent<{ mdText: JoinMdContainer }>;
|
|
176
|
+
|
|
177
|
+
type HyperLinkRenderer = React.FunctionComponent<{
|
|
178
|
+
mdText: HyperLinkContainer;
|
|
179
|
+
}>;
|
|
180
|
+
|
|
181
|
+
const normalWrapper: (TagName: React.ElementType) => NormalRenderes =
|
|
182
|
+
(TagName: React.ElementType) =>
|
|
183
|
+
({ mdText }) =>
|
|
184
|
+
(
|
|
185
|
+
<TagName>
|
|
186
|
+
<AssistantMd mdText={mdText.value} />
|
|
187
|
+
</TagName>
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const listWrapper: (TagName: React.ElementType) => ListRenderers =
|
|
191
|
+
(TagName) =>
|
|
192
|
+
({ mdText: { list } }) =>
|
|
193
|
+
(
|
|
194
|
+
<TagName>
|
|
195
|
+
{list.map((mdText) => (
|
|
196
|
+
<li>
|
|
197
|
+
<AssistantMd mdText={mdText} />
|
|
198
|
+
</li>
|
|
199
|
+
))}
|
|
200
|
+
</TagName>
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
type RenderTypes = MdTypes;
|
|
204
|
+
|
|
205
|
+
type MdRenderers =
|
|
206
|
+
| NormalRenderes
|
|
207
|
+
| ListRenderers
|
|
208
|
+
| TextRenderer
|
|
209
|
+
| HyperLinkRenderer
|
|
210
|
+
| JoinMdRenderer;
|
|
211
|
+
|
|
212
|
+
// type RenderMap = Record<RenderTypes, MdRenderers>;
|
|
213
|
+
|
|
214
|
+
const NormalTextMd: TextRenderer = ({ mdText }) => {
|
|
215
|
+
return <DisplayURL text={mdText} />;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const HyperLinkMd: HyperLinkRenderer = ({ mdText }) => (
|
|
219
|
+
<a href={mdText.link} target="_blank">
|
|
220
|
+
<AssistantMd mdText={mdText.value} />
|
|
221
|
+
</a>
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const JoinMd: JoinMdRenderer = ({ mdText: { lhs, rhs } }) => (
|
|
225
|
+
<>
|
|
226
|
+
<AssistantMd mdText={lhs} />
|
|
227
|
+
<AssistantMd mdText={rhs} />
|
|
228
|
+
</>
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const mdTypeRenderers = {
|
|
232
|
+
normal_text: NormalTextMd,
|
|
233
|
+
bold: normalWrapper("strong"),
|
|
234
|
+
italic: normalWrapper("em"),
|
|
235
|
+
underline: normalWrapper("u"),
|
|
236
|
+
hyperlink: HyperLinkMd,
|
|
237
|
+
ordered_list: listWrapper("ol"),
|
|
238
|
+
unordered_list: listWrapper("ul"),
|
|
239
|
+
newline: () => <br />,
|
|
240
|
+
join: JoinMd,
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
function exhaustiveCheck(param: never) {}
|
|
244
|
+
|
|
245
|
+
export default function AssistantMd({ mdText }: MdTextProp) {
|
|
246
|
+
switch (mdText.markdown_text) {
|
|
247
|
+
case "bold": {
|
|
248
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
249
|
+
let container = mdText[mdText.markdown_text];
|
|
250
|
+
return <RendenMDElement mdText={container} />;
|
|
251
|
+
}
|
|
252
|
+
case "italic": {
|
|
253
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
254
|
+
let container = mdText[mdText.markdown_text];
|
|
255
|
+
return <RendenMDElement mdText={container} />;
|
|
256
|
+
}
|
|
257
|
+
case "normal_text": {
|
|
258
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
259
|
+
let container = mdText[mdText.markdown_text];
|
|
260
|
+
return <RendenMDElement mdText={container} />;
|
|
261
|
+
}
|
|
262
|
+
case "underline": {
|
|
263
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
264
|
+
let container = mdText[mdText.markdown_text];
|
|
265
|
+
return <RendenMDElement mdText={container} />;
|
|
266
|
+
}
|
|
267
|
+
case "hyperlink": {
|
|
268
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
269
|
+
let container = mdText[mdText.markdown_text];
|
|
270
|
+
return <RendenMDElement mdText={container} />;
|
|
271
|
+
}
|
|
272
|
+
case "ordered_list": {
|
|
273
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
274
|
+
let container = mdText[mdText.markdown_text];
|
|
275
|
+
return <RendenMDElement mdText={container} />;
|
|
276
|
+
}
|
|
277
|
+
case "unordered_list": {
|
|
278
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
279
|
+
let container = mdText[mdText.markdown_text];
|
|
280
|
+
return <RendenMDElement mdText={container} />;
|
|
281
|
+
}
|
|
282
|
+
case "join": {
|
|
283
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
284
|
+
let container = mdText[mdText.markdown_text];
|
|
285
|
+
return <RendenMDElement mdText={container} />;
|
|
286
|
+
}
|
|
287
|
+
case "newline": {
|
|
288
|
+
let RendenMDElement = mdTypeRenderers[mdText.markdown_text];
|
|
289
|
+
return <RendenMDElement />;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exhaustiveCheck(mdText);
|
|
293
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
"jsx": "react",
|
|
17
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
|
|
28
|
+
/* Modules */
|
|
29
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
30
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
31
|
+
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
32
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
33
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
34
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
35
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
36
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
37
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
38
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
39
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
40
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
41
|
+
|
|
42
|
+
/* JavaScript Support */
|
|
43
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
44
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
45
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
46
|
+
|
|
47
|
+
/* Emit */
|
|
48
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
49
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
50
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
51
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
52
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
53
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
54
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
55
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
56
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
57
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
58
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
59
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
60
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
61
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
62
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
63
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
64
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
65
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
66
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
67
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
68
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
69
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
70
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
71
|
+
|
|
72
|
+
/* Interop Constraints */
|
|
73
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
74
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
75
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
76
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
77
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
78
|
+
|
|
79
|
+
/* Type Checking */
|
|
80
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
81
|
+
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
82
|
+
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
83
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
84
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
85
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
86
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
87
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
88
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
89
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
90
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
91
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
92
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
93
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
94
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
95
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
96
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
97
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
98
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
99
|
+
|
|
100
|
+
/* Completeness */
|
|
101
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
102
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
103
|
+
}
|
|
104
|
+
}
|
package/assistant_md.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
const URL_REGEX = /[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=-]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
|
|
4
|
-
|
|
5
|
-
const normalStr = (str) => ({
|
|
6
|
-
type: "normal_str",
|
|
7
|
-
value: str
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const urlStr = (str) => ({
|
|
11
|
-
type: "url",
|
|
12
|
-
value: str
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const normalWrapper = (TagName) => ({ mdText }) => (
|
|
16
|
-
<TagName>
|
|
17
|
-
<AssistantMd mdText={mdText.value} />
|
|
18
|
-
</TagName>
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const listWrapper = (TagName) => ({ mdText: { list } }) => (
|
|
22
|
-
<TagName>
|
|
23
|
-
{list.map((mdText) => (
|
|
24
|
-
<li>
|
|
25
|
-
<AssistantMd mdText={mdText} />
|
|
26
|
-
</li>
|
|
27
|
-
))}
|
|
28
|
-
</TagName>
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
export function parseUrlAndString(str) {
|
|
32
|
-
const results = [];
|
|
33
|
-
let remaining = str;
|
|
34
|
-
while (remaining) {
|
|
35
|
-
let match = remaining.match(URL_REGEX);
|
|
36
|
-
if (!match) {
|
|
37
|
-
results.push(normalStr(remaining));
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (match.index !== 0) {
|
|
42
|
-
results.push(normalStr(remaining.slice(0, match.index)));
|
|
43
|
-
results.push(
|
|
44
|
-
urlStr(remaining.slice(match.index, match.index + match[0].length))
|
|
45
|
-
);
|
|
46
|
-
remaining = remaining.slice(match.index + match[0].length);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
results.push(urlStr(remaining.slice(0, match[0].length)));
|
|
50
|
-
remaining = remaining.slice(match[0].length);
|
|
51
|
-
}
|
|
52
|
-
return results;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const mdTypeRenderers = {
|
|
56
|
-
normal_text: NormalTextMd,
|
|
57
|
-
bold: normalWrapper("strong"),
|
|
58
|
-
italic: normalWrapper("em"),
|
|
59
|
-
underline: normalWrapper("u"),
|
|
60
|
-
hyperlink: HyperLinkMd,
|
|
61
|
-
ordered_list: listWrapper("ol"),
|
|
62
|
-
unordered_list: listWrapper("ul"),
|
|
63
|
-
newline: () => <br />,
|
|
64
|
-
join: JoinMd
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const DisplayLineBreaks = ({ text }) => {
|
|
68
|
-
let texts = text.split("\n");
|
|
69
|
-
let lastOne = texts[texts.length - 1];
|
|
70
|
-
let exceptLastOne = texts.slice(0, texts.length - 1);
|
|
71
|
-
return (
|
|
72
|
-
<>
|
|
73
|
-
{exceptLastOne.reduce(
|
|
74
|
-
(arr, text) => [...arr, text, <br key={arr.length} />],
|
|
75
|
-
[]
|
|
76
|
-
)}
|
|
77
|
-
{lastOne}
|
|
78
|
-
</>
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const DisplayURL = ({ text }) => {
|
|
83
|
-
const parsed = parseUrlAndString(text);
|
|
84
|
-
return parsed.map(({ type, value }, i) =>
|
|
85
|
-
type === "url" ? (
|
|
86
|
-
<a href={value} target="_blank" key={i} rel="noreferrer">
|
|
87
|
-
{value}
|
|
88
|
-
</a>
|
|
89
|
-
) : (
|
|
90
|
-
<DisplayLineBreaks text={value} key={i}></DisplayLineBreaks>
|
|
91
|
-
)
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
function NormalTextMd({ mdText }) {
|
|
96
|
-
return <DisplayURL text={mdText} />;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function HyperLinkMd({ mdText }) {
|
|
100
|
-
return (
|
|
101
|
-
<a href={mdText.link}>
|
|
102
|
-
<AssistantMd mdText={mdText.value} />
|
|
103
|
-
</a>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function JoinMd({ mdText: { lhs, rhs } }) {
|
|
108
|
-
return (
|
|
109
|
-
<>
|
|
110
|
-
<AssistantMd mdText={lhs} />
|
|
111
|
-
<AssistantMd mdText={rhs} />
|
|
112
|
-
</>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default function AssistantMd({ mdText }) {
|
|
117
|
-
let RenderMd = mdTypeRenderers[mdText.markdown_text];
|
|
118
|
-
return <RenderMd mdText={mdText[mdText.markdown_text]} />;
|
|
119
|
-
}
|