tinywidgets 1.0.12 → 1.0.14
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/bun.lockb +0 -0
- package/package.json +8 -9
- package/src/components/App/index.tsx +4 -1
- package/src/components/Code/index.tsx +39 -27
package/bun.lockb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinywidgets",
|
|
3
3
|
"description": "A collection of tiny, reusable, React components",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.14",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prePublishPackage": "eslint . && cspell --quiet . && tsc"
|
|
7
7
|
},
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"repository": "github:tinyplex/tinywidgets",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@types/react": "^18.3.
|
|
12
|
+
"@types/react": "^18.3.11",
|
|
13
13
|
"@types/react-dom": "^18.3.0",
|
|
14
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
15
|
-
"@typescript-eslint/parser": "^8.
|
|
14
|
+
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
|
15
|
+
"@typescript-eslint/parser": "^8.8.0",
|
|
16
16
|
"cspell": "^8.14.4",
|
|
17
17
|
"eslint": "^8.57.0",
|
|
18
18
|
"eslint-config-prettier": "^9.1.0",
|
|
19
|
-
"eslint-plugin-react": "^7.
|
|
19
|
+
"eslint-plugin-react": "^7.37.1",
|
|
20
20
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
21
21
|
"eslint-plugin-react-refresh": "^0.4.12",
|
|
22
22
|
"prettier": "^3.3.3",
|
|
@@ -28,11 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"lucide-react": "^0.
|
|
33
|
-
"prismjs": "^1.29.0",
|
|
31
|
+
"@vanilla-extract/css": "^1.16.0",
|
|
32
|
+
"lucide-react": "^0.447.0",
|
|
34
33
|
"react": "^18.3.1",
|
|
35
34
|
"react-dom": "^18.3.1",
|
|
36
|
-
"tinybase": "^5.3.
|
|
35
|
+
"tinybase": "^5.3.2"
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as UiReact from 'tinybase/ui-react/with-schemas';
|
|
1
2
|
import type {ComponentType, ReactNode} from 'react';
|
|
2
3
|
import {
|
|
3
4
|
LocalStore,
|
|
@@ -30,9 +31,11 @@ import {classNames, renderComponentOrNode} from '../../common/functions.tsx';
|
|
|
30
31
|
import {codeDark, codeLight} from '../../css/code.css.ts';
|
|
31
32
|
import {colorsDark, colorsLight} from '../../css/colors.css.ts';
|
|
32
33
|
import {Button} from '../Button/index.tsx';
|
|
33
|
-
import {
|
|
34
|
+
import {OptionalSchemas} from 'tinybase/with-schemas';
|
|
34
35
|
import React from 'react';
|
|
35
36
|
|
|
37
|
+
const {Provider} = UiReact as UiReact.WithSchemas<OptionalSchemas>;
|
|
38
|
+
|
|
36
39
|
const darkIcons = [Sun, Moon, SunMoon];
|
|
37
40
|
const darkChoices = ['Light always', 'Dark always', 'Auto'];
|
|
38
41
|
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
|
-
import 'prismjs';
|
|
3
|
-
import 'prismjs/components/prism-jsx';
|
|
4
|
-
import 'prismjs/components/prism-typescript';
|
|
5
|
-
import 'prismjs/components/prism-tsx';
|
|
6
|
-
import Prism from 'prismjs';
|
|
7
2
|
import React from 'react';
|
|
8
3
|
import {classNames} from '../../common/functions.tsx';
|
|
9
4
|
import {pre} from './index.css.ts';
|
|
10
5
|
|
|
11
|
-
const {highlight, languages} = Prism;
|
|
12
|
-
|
|
13
6
|
/**
|
|
14
7
|
* The `Code` component displays a block of pre-formatted code, and uses PrismJS
|
|
15
|
-
* to parse its syntax
|
|
8
|
+
* to parse its syntax if you have imported it globally. The coloring is based
|
|
9
|
+
* on the [prism-one-dark](https://github.com/PrismJS/prism-themes/blob/master/themes/prism-one-dark.css) and [prism-one-light](https://github.com/PrismJS/prism-themes/blob/master/themes/prism-one-light.css) themes.
|
|
16
10
|
*
|
|
17
|
-
*
|
|
18
|
-
* ,
|
|
19
|
-
* ,
|
|
20
|
-
* , `tsx`).
|
|
21
|
-
* Others can be added if there is demand! Please open an issue on GitHub.
|
|
11
|
+
* PrismJS is not included in the TinyWidgets bundle, so you need to include it
|
|
12
|
+
* in your project, and, if you want to highlight one of the non-default Prism
|
|
13
|
+
* languages, you will need to explicitly include that too.
|
|
22
14
|
*
|
|
23
15
|
* @param props The props for the component.
|
|
24
16
|
* @returns The Code component.
|
|
@@ -26,14 +18,37 @@ const {highlight, languages} = Prism;
|
|
|
26
18
|
* ```tsx
|
|
27
19
|
* <Code
|
|
28
20
|
* code={`
|
|
21
|
+
* const a = 1;
|
|
22
|
+
* `}
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
* This example shows a simple block of code, defaulting to the `javascript`
|
|
26
|
+
* language.
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <Code
|
|
30
|
+
* code={`
|
|
31
|
+
* const a: number = 1;
|
|
32
|
+
* `}
|
|
33
|
+
* language="typescript"
|
|
34
|
+
* />
|
|
35
|
+
* ```
|
|
36
|
+
* This example shows the use of the `typescript` language, which has been
|
|
37
|
+
* explicitly imported in addition to the Prism default languages
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <Code
|
|
41
|
+
* code={`
|
|
29
42
|
* import React from 'react';
|
|
30
43
|
* const App = () => (
|
|
31
44
|
* <div>Hello, world!</div>
|
|
32
45
|
* );
|
|
33
46
|
* `}
|
|
47
|
+
* language="tsx"
|
|
34
48
|
* />
|
|
35
49
|
* ```
|
|
36
|
-
* This example shows a simple block of code, defaulting to the `jsx` language
|
|
50
|
+
* This example shows a simple block of code, defaulting to the `jsx` language,
|
|
51
|
+
* similarly imported explicitly.
|
|
37
52
|
* @example
|
|
38
53
|
* ```tsx
|
|
39
54
|
* <Code
|
|
@@ -46,21 +61,11 @@ const {highlight, languages} = Prism;
|
|
|
46
61
|
* />
|
|
47
62
|
* ```
|
|
48
63
|
* This example shows the use of the `css` language.
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* <Code
|
|
52
|
-
* code={`
|
|
53
|
-
* const a: number = 1;
|
|
54
|
-
* `}
|
|
55
|
-
* language="typescript"
|
|
56
|
-
* />
|
|
57
|
-
* ```
|
|
58
|
-
* This example shows the use of the `tsx` language.
|
|
59
64
|
* @icon Lucide.SquareCode
|
|
60
65
|
*/
|
|
61
66
|
export const Code = ({
|
|
62
67
|
code,
|
|
63
|
-
language = '
|
|
68
|
+
language = 'javascript',
|
|
64
69
|
className,
|
|
65
70
|
}: {
|
|
66
71
|
/**
|
|
@@ -68,7 +73,7 @@ export const Code = ({
|
|
|
68
73
|
*/
|
|
69
74
|
readonly code: string;
|
|
70
75
|
/**
|
|
71
|
-
* An optional indication of the language. Defaults to `
|
|
76
|
+
* An optional indication of the language. Defaults to `javascript`.
|
|
72
77
|
*/
|
|
73
78
|
readonly language?: string;
|
|
74
79
|
/**
|
|
@@ -76,12 +81,19 @@ export const Code = ({
|
|
|
76
81
|
*/
|
|
77
82
|
readonly className?: string;
|
|
78
83
|
}) => {
|
|
84
|
+
const prism = globalThis.Prism;
|
|
79
85
|
return (
|
|
80
86
|
<pre className={classNames(pre, className)}>
|
|
81
87
|
<code
|
|
82
88
|
// eslint-disable-next-line react/no-danger
|
|
83
89
|
dangerouslySetInnerHTML={{
|
|
84
|
-
__html:
|
|
90
|
+
__html: (prism
|
|
91
|
+
? prism.highlight(code, prism.languages?.[language], language)
|
|
92
|
+
: code.replace(
|
|
93
|
+
/[\u00A0-\u9999<>&]/g,
|
|
94
|
+
(i) => `&#${i.charCodeAt(0)};`,
|
|
95
|
+
)
|
|
96
|
+
).trim(),
|
|
85
97
|
}}
|
|
86
98
|
/>
|
|
87
99
|
</pre>
|