@ably/ui 8.7.0-dev.6ce15a7 → 8.7.0-dev.9659fc3
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/core/.DS_Store +0 -0
- package/core/Code/component.css +3 -3
- package/core/Code/component.js +1 -1
- package/core/Code.jsx +328 -7145
- package/core/Notice/component.js.LICENSE.txt +0 -15
- package/package.json +3 -1
- package/src/core/Code/component.css +1 -67
- package/src/core/Code/component.js +11 -46
- package/src/core/Code/component.jsx +7 -3
- package/src/core/utils/syntax-highlighter-registry.js +61 -0
- package/src/core/utils/syntax-highlighter.css +69 -0
- package/src/core/utils/syntax-highlighter.js +98 -0
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
object-assign
|
|
3
|
-
(c) Sindre Sorhus
|
|
4
|
-
@license MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
1
|
/*!
|
|
8
2
|
* JavaScript Cookie v2.2.1
|
|
9
3
|
* https://github.com/js-cookie/js-cookie
|
|
@@ -13,12 +7,3 @@ object-assign
|
|
|
13
7
|
*/
|
|
14
8
|
|
|
15
9
|
/*! @license DOMPurify | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.2.2/LICENSE */
|
|
16
|
-
|
|
17
|
-
/** @license React v17.0.2
|
|
18
|
-
* react.production.min.js
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the MIT license found in the
|
|
23
|
-
* LICENSE file in the root directory of this source tree.
|
|
24
|
-
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ably/ui",
|
|
3
|
-
"version": "8.7.0-dev.
|
|
3
|
+
"version": "8.7.0-dev.9659fc3",
|
|
4
4
|
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"eslint-plugin-cypress": "^2.11.2",
|
|
35
35
|
"eslint-plugin-react": "^7.21.5",
|
|
36
36
|
"extra-watch-webpack-plugin": "^1.0.3",
|
|
37
|
+
"find-imports": "^1.1.0",
|
|
37
38
|
"mini-css-extract-plugin": "^1.2.1",
|
|
38
39
|
"null-loader": "^4.0.1",
|
|
39
40
|
"postcss": "^8.1.10",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"array-flat-polyfill": "^1.0.1",
|
|
69
70
|
"dompurify": "^2.2.9",
|
|
70
71
|
"highlight.js": "^10.7.2",
|
|
72
|
+
"highlightjs-curl": "^1.3.0",
|
|
71
73
|
"js-cookie": "^2.2.1",
|
|
72
74
|
"lodash.throttle": "^4.1.1",
|
|
73
75
|
"nanoid": "^4.0.0",
|
|
@@ -1,67 +1 @@
|
|
|
1
|
-
@import "../
|
|
2
|
-
|
|
3
|
-
@layer components {
|
|
4
|
-
.hljs {
|
|
5
|
-
background: var(--syntax-black);
|
|
6
|
-
color: var(--syntax-light-grey);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.hljs-emphasis {
|
|
10
|
-
font-style: italic;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.hljs-strong {
|
|
14
|
-
font-weight: bold;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.hljs-comment,
|
|
18
|
-
.hljs-quote {
|
|
19
|
-
color: var(--syntax-dark-grey);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.hljs-variable,
|
|
23
|
-
.hljs-template-variable,
|
|
24
|
-
.hljs-tag,
|
|
25
|
-
.hljs-name,
|
|
26
|
-
.hljs-selector-id,
|
|
27
|
-
.hljs-selector-class,
|
|
28
|
-
.hljs-regexp,
|
|
29
|
-
.hljs-deletion {
|
|
30
|
-
color: var(--syntax-red);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.hljs-number,
|
|
34
|
-
.hljs-built_in,
|
|
35
|
-
.hljs-literal,
|
|
36
|
-
.hljs-type,
|
|
37
|
-
.hljs-params,
|
|
38
|
-
.hljs-meta,
|
|
39
|
-
.hljs-link {
|
|
40
|
-
color: var(--syntax-orange);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.hljs-attribute {
|
|
44
|
-
color: var(--syntax-yellow);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.hljs-string,
|
|
48
|
-
.hljs-symbol,
|
|
49
|
-
.hljs-bullet,
|
|
50
|
-
.hljs-addition {
|
|
51
|
-
color: var(--syntax-green);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.hljs-title,
|
|
55
|
-
.hljs-section {
|
|
56
|
-
color: var(--syntax-blue);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.hljs-keyword,
|
|
60
|
-
.hljs-selector-tag {
|
|
61
|
-
color: var(--syntax-lilac);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.hljs-subst {
|
|
65
|
-
color: var(--syntax-mid-grey);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
1
|
+
@import "../utils/syntax-highlighter.css";
|
|
@@ -1,47 +1,17 @@
|
|
|
1
1
|
import "./component.css";
|
|
2
|
-
import hljs from "highlight.js/lib/core";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import java from "highlight.js/lib/languages/java";
|
|
11
|
-
import javascript from "highlight.js/lib/languages/javascript";
|
|
12
|
-
import json from "highlight.js/lib/languages/json";
|
|
13
|
-
import objectivec from "highlight.js/lib/languages/objectivec";
|
|
14
|
-
import php from "highlight.js/lib/languages/php";
|
|
15
|
-
import python from "highlight.js/lib/languages/python";
|
|
16
|
-
import ruby from "highlight.js/lib/languages/ruby";
|
|
17
|
-
import swift from "highlight.js/lib/languages/swift";
|
|
18
|
-
import xml from "highlight.js/lib/languages/xml";
|
|
3
|
+
// Note: importing syntax-highlighter here means the component.js file will include
|
|
4
|
+
// all the language dependecies, creating a large a bundle. Prefer using the highlighter serverside.
|
|
5
|
+
import {
|
|
6
|
+
highlightSnippet,
|
|
7
|
+
registerDefaultLanguages,
|
|
8
|
+
} from "../utils/syntax-highlighter";
|
|
19
9
|
|
|
20
|
-
|
|
21
|
-
// https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md
|
|
22
|
-
const register = [
|
|
23
|
-
{ label: "", key: "plaintext", module: plaintext },
|
|
24
|
-
{ label: "JS", key: "javascript", module: javascript },
|
|
25
|
-
{ label: "Java", key: "java", module: java },
|
|
26
|
-
{ label: "Ruby", key: "ruby", module: ruby },
|
|
27
|
-
{ label: "Python", key: "python", module: python },
|
|
28
|
-
{ label: "PHP", key: "php", module: php },
|
|
29
|
-
{ label: "Shell", key: "bash", module: bash },
|
|
30
|
-
{ label: "C#", key: "cs", module: csharp },
|
|
31
|
-
{ label: "Go", key: "go", module: go },
|
|
32
|
-
{ label: "HTML", key: "xml", module: xml },
|
|
33
|
-
{ label: "C++", key: "cpp", module: cpp },
|
|
34
|
-
{ label: "Dart", key: "dart", module: dart },
|
|
35
|
-
{ label: "Swift", key: "swift", module: swift },
|
|
36
|
-
{ label: "Objective C", key: "objectivec", module: objectivec },
|
|
37
|
-
{ label: "Node.js", key: "javascript", module: javascript },
|
|
38
|
-
{ label: "JSON", key: "json", module: json },
|
|
39
|
-
];
|
|
10
|
+
import languagesRegistry from "../utils/syntax-highlighter-registry";
|
|
40
11
|
|
|
41
|
-
|
|
42
|
-
register.forEach(({ key, module }) => hljs.registerLanguage(key, module));
|
|
12
|
+
registerDefaultLanguages(languagesRegistry);
|
|
43
13
|
|
|
44
|
-
function
|
|
14
|
+
function highlightEl(el) {
|
|
45
15
|
if (!el) throw "Missing code element";
|
|
46
16
|
|
|
47
17
|
const pre = el.querySelector("pre");
|
|
@@ -51,14 +21,9 @@ function convertCodeToHTML(el) {
|
|
|
51
21
|
if (!code || !pre || !language) throw "Malformed code element";
|
|
52
22
|
|
|
53
23
|
const { innerHTML } = code;
|
|
54
|
-
const html =
|
|
24
|
+
const html = highlightSnippet(language, innerHTML);
|
|
55
25
|
|
|
56
26
|
code.innerHTML = html;
|
|
57
27
|
}
|
|
58
28
|
|
|
59
|
-
|
|
60
|
-
return hljs.highlight(snippet, { language }).value;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { highlight };
|
|
64
|
-
export default convertCodeToHTML;
|
|
29
|
+
export default highlightEl;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import T from "prop-types";
|
|
3
3
|
|
|
4
|
-
import "
|
|
5
|
-
import {
|
|
4
|
+
import "../utils/syntax-highlighter.css";
|
|
5
|
+
import { highlightSnippet, registerDefaultLanguages } from "../utils/syntax-highlighter";
|
|
6
|
+
import languagesRegistry from "../utils/syntax-highlighter-registry";
|
|
7
|
+
|
|
8
|
+
registerDefaultLanguages(languagesRegistry);
|
|
6
9
|
|
|
7
10
|
const Code = ({ language, snippet, textSize = "ui-text-code", padding = "p-32", additionalCSS = "" }) => {
|
|
8
|
-
const HTMLraw =
|
|
11
|
+
const HTMLraw = highlightSnippet(language, `${snippet}`.trim());
|
|
9
12
|
const className = `language-${language} ${textSize}`;
|
|
13
|
+
|
|
10
14
|
return (
|
|
11
15
|
<div className={`hljs overflow-auto ${padding} ${additionalCSS}`} data-id="code">
|
|
12
16
|
<pre lang={language}>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// This file can be used in the browser, but because of the weight of all the language
|
|
2
|
+
// definitions, preferably it should be used on the server.
|
|
3
|
+
|
|
4
|
+
import bash from "highlight.js/lib/languages/bash";
|
|
5
|
+
import cpp from "highlight.js/lib/languages/cpp";
|
|
6
|
+
import csharp from "highlight.js/lib/languages/csharp";
|
|
7
|
+
import css from "highlight.js/lib/languages/css";
|
|
8
|
+
import dart from "highlight.js/lib/languages/dart";
|
|
9
|
+
import dos from "highlight.js/lib/languages/dos";
|
|
10
|
+
import diff from "highlight.js/lib/languages/diff";
|
|
11
|
+
import erlang from "highlight.js/lib/languages/erlang";
|
|
12
|
+
import elixir from "highlight.js/lib/languages/elixir";
|
|
13
|
+
import plaintext from "highlight.js/lib/languages/plaintext";
|
|
14
|
+
import go from "highlight.js/lib/languages/go";
|
|
15
|
+
import http from "highlight.js/lib/languages/http";
|
|
16
|
+
import java from "highlight.js/lib/languages/java";
|
|
17
|
+
import javascript from "highlight.js/lib/languages/javascript";
|
|
18
|
+
import typescript from "highlight.js/lib/languages/typescript";
|
|
19
|
+
import json from "highlight.js/lib/languages/json";
|
|
20
|
+
import objectivec from "highlight.js/lib/languages/objectivec";
|
|
21
|
+
import php from "highlight.js/lib/languages/php";
|
|
22
|
+
import python from "highlight.js/lib/languages/python";
|
|
23
|
+
import ruby from "highlight.js/lib/languages/ruby";
|
|
24
|
+
import swift from "highlight.js/lib/languages/swift";
|
|
25
|
+
import sql from "highlight.js/lib/languages/sql";
|
|
26
|
+
import xml from "highlight.js/lib/languages/xml";
|
|
27
|
+
import yaml from "highlight.js/lib/languages/yaml";
|
|
28
|
+
import curl from "highlightjs-curl/src/languages/curl";
|
|
29
|
+
|
|
30
|
+
const registry = [
|
|
31
|
+
{ label: "Text", key: "text", module: plaintext },
|
|
32
|
+
{ label: "JS", key: "javascript", module: javascript },
|
|
33
|
+
{ label: "TS", key: "typescript", module: typescript },
|
|
34
|
+
{ label: "Java", key: "java", module: java },
|
|
35
|
+
{ label: "Ruby", key: "ruby", module: ruby },
|
|
36
|
+
{ label: "Python", key: "python", module: python },
|
|
37
|
+
{ label: "PHP", key: "php", module: php },
|
|
38
|
+
{ label: "Shell", key: "bash", module: bash },
|
|
39
|
+
{ label: "C#", key: "cs", module: csharp },
|
|
40
|
+
{ label: "CSS", key: "css", module: css },
|
|
41
|
+
{ label: "Go", key: "go", module: go },
|
|
42
|
+
{ label: "HTML", key: "xml", module: xml },
|
|
43
|
+
{ label: "HTTP", key: "http", module: http },
|
|
44
|
+
{ label: "C++", key: "cpp", module: cpp },
|
|
45
|
+
{ label: "Dart", key: "dart", module: dart },
|
|
46
|
+
{ label: "Swift", key: "swift", module: swift },
|
|
47
|
+
{ label: "Objective C", key: "objectivec", module: objectivec },
|
|
48
|
+
{ label: "Node.js", key: "javascript", module: javascript },
|
|
49
|
+
{ label: "JSON", key: "json", module: json },
|
|
50
|
+
{ label: "DOS", key: "dos", module: dos },
|
|
51
|
+
{ label: "YAML", key: "yaml", module: yaml },
|
|
52
|
+
{ label: "Erlang", key: "erlang", module: erlang },
|
|
53
|
+
{ label: "Elixir", key: "elixir", module: elixir },
|
|
54
|
+
{ label: "Diff", key: "diff", module: diff },
|
|
55
|
+
{ label: "SQL", key: "sql", module: sql },
|
|
56
|
+
{ label: "cURL", key: "curl", module: curl },
|
|
57
|
+
{ label: "HTML", key: "html", module: xml },
|
|
58
|
+
{ label: "XML", key: "xml", module: xml },
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
export default registry;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
@layer base {
|
|
2
|
+
@import url("https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,600;0,700;1,600;1,700&display=swap");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
@layer components {
|
|
6
|
+
.hljs {
|
|
7
|
+
background: var(--syntax-black);
|
|
8
|
+
color: var(--syntax-light-grey);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.hljs-emphasis {
|
|
12
|
+
@apply italic;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.hljs-strong {
|
|
16
|
+
@apply font-bold;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.hljs-comment,
|
|
20
|
+
.hljs-quote {
|
|
21
|
+
color: var(--syntax-dark-grey);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.hljs-variable,
|
|
25
|
+
.hljs-template-variable,
|
|
26
|
+
.hljs-tag,
|
|
27
|
+
.hljs-name,
|
|
28
|
+
.hljs-selector-id,
|
|
29
|
+
.hljs-selector-class,
|
|
30
|
+
.hljs-regexp,
|
|
31
|
+
.hljs-deletion {
|
|
32
|
+
color: var(--syntax-red);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.hljs-number,
|
|
36
|
+
.hljs-built_in,
|
|
37
|
+
.hljs-literal,
|
|
38
|
+
.hljs-type,
|
|
39
|
+
.hljs-params,
|
|
40
|
+
.hljs-meta,
|
|
41
|
+
.hljs-link {
|
|
42
|
+
color: var(--syntax-orange);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.hljs-attribute {
|
|
46
|
+
color: var(--syntax-yellow);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.hljs-string,
|
|
50
|
+
.hljs-symbol,
|
|
51
|
+
.hljs-bullet,
|
|
52
|
+
.hljs-addition {
|
|
53
|
+
color: var(--syntax-green);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.hljs-title,
|
|
57
|
+
.hljs-section {
|
|
58
|
+
color: var(--syntax-blue);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.hljs-keyword,
|
|
62
|
+
.hljs-selector-tag {
|
|
63
|
+
color: var(--syntax-lilac);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.hljs-subst {
|
|
67
|
+
color: var(--syntax-mid-grey);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import hljs from "highlight.js/lib/core";
|
|
2
|
+
|
|
3
|
+
// Map certain frameworks, protocols etc to available langauage packs
|
|
4
|
+
const languageToHighlightKey = (lang) => {
|
|
5
|
+
let id;
|
|
6
|
+
|
|
7
|
+
if (!lang) {
|
|
8
|
+
lang = "text";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
switch (lang.toLowerCase()) {
|
|
12
|
+
case "android":
|
|
13
|
+
id = "java";
|
|
14
|
+
break;
|
|
15
|
+
|
|
16
|
+
case ".net":
|
|
17
|
+
case "net":
|
|
18
|
+
case "dotnet":
|
|
19
|
+
case "csharp":
|
|
20
|
+
case "c#":
|
|
21
|
+
id = "cs";
|
|
22
|
+
break;
|
|
23
|
+
|
|
24
|
+
case "objc":
|
|
25
|
+
case "objective c":
|
|
26
|
+
id = "objectivec";
|
|
27
|
+
break;
|
|
28
|
+
|
|
29
|
+
case "laravel":
|
|
30
|
+
id = "php";
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case "flutter":
|
|
34
|
+
id = "dart";
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
case "node.js":
|
|
38
|
+
case "js":
|
|
39
|
+
id = "javascript";
|
|
40
|
+
break;
|
|
41
|
+
|
|
42
|
+
case "ts":
|
|
43
|
+
id = "typescript";
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case "shell":
|
|
47
|
+
case "fh":
|
|
48
|
+
case "sh":
|
|
49
|
+
id = "bash";
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
case "https":
|
|
53
|
+
case "http":
|
|
54
|
+
case "txt":
|
|
55
|
+
case "plaintext":
|
|
56
|
+
id = "text";
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
case "cmd":
|
|
60
|
+
case "bat":
|
|
61
|
+
id = "dos";
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case "yml":
|
|
65
|
+
id = "yaml";
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case "erl":
|
|
69
|
+
id = "erlang";
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case "patch":
|
|
73
|
+
id = "diff";
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case "svg":
|
|
77
|
+
id = "xml";
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
default:
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return id || lang;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const registerDefaultLanguages = (register) => {
|
|
88
|
+
register.forEach(({ key, module }) => hljs.registerLanguage(key, module));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const highlightSnippet = (languageKeyword, snippet) => {
|
|
92
|
+
const language = languageToHighlightKey(languageKeyword);
|
|
93
|
+
if (typeof snippet !== "string" || !snippet || !language) return;
|
|
94
|
+
|
|
95
|
+
return hljs.highlight(snippet, { language }).value;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export { highlightSnippet, languageToHighlightKey, registerDefaultLanguages };
|