@mantine/code-highlight 7.0.0-alpha.2 → 7.0.0-alpha.21
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/cjs/CodeHighlight.js +1 -20
- package/cjs/CodeHighlight.js.map +1 -1
- package/cjs/CodeHighlight.module.css.js +1 -1
- package/cjs/CodeHighlight.theme.module.css.js +1 -1
- package/cjs/CodeHighlightTabs.js +41 -50
- package/cjs/CodeHighlightTabs.js.map +1 -1
- package/cjs/CopyIcon.js +14 -24
- package/cjs/CopyIcon.js.map +1 -1
- package/cjs/ExpandIcon.js +14 -38
- package/cjs/ExpandIcon.js.map +1 -1
- package/cjs/FileIcon.js +3 -3
- package/cjs/FileIcon.js.map +1 -1
- package/cjs/InlineCodeHighlight.js +9 -6
- package/cjs/InlineCodeHighlight.js.map +1 -1
- package/cjs/index.css +91 -127
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/cjs/use-highlight.js +3 -1
- package/cjs/use-highlight.js.map +1 -1
- package/esm/CodeHighlight.js +1 -20
- package/esm/CodeHighlight.js.map +1 -1
- package/esm/CodeHighlight.module.css.js +1 -1
- package/esm/CodeHighlight.theme.module.css.js +1 -1
- package/esm/CodeHighlightTabs.js +42 -51
- package/esm/CodeHighlightTabs.js.map +1 -1
- package/esm/CopyIcon.js +14 -24
- package/esm/CopyIcon.js.map +1 -1
- package/esm/ExpandIcon.js +14 -38
- package/esm/ExpandIcon.js.map +1 -1
- package/esm/FileIcon.js +3 -3
- package/esm/FileIcon.js.map +1 -1
- package/esm/InlineCodeHighlight.js +9 -6
- package/esm/InlineCodeHighlight.js.map +1 -1
- package/esm/index.css +91 -127
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/use-highlight.js +3 -1
- package/esm/use-highlight.js.map +1 -1
- package/lib/CodeHighlight.d.ts +0 -3
- package/lib/CodeHighlightTabs.d.ts +2 -3
- package/lib/CopyIcon.d.ts +1 -1
- package/lib/ExpandIcon.d.ts +1 -1
- package/lib/FileIcon.d.ts +3 -1
- package/lib/InlineCodeHighlight.d.ts +0 -1
- package/lib/index.d.ts +3 -3
- package/package.json +18 -10
- package/src/CodeHighlight.module.css +14 -0
- package/src/CodeHighlight.story.tsx +6 -0
- package/src/CodeHighlight.tsx +1 -3
- package/src/CodeHighlightTabs.tsx +10 -5
- package/src/FileIcon.tsx +13 -3
- package/src/InlineCodeHighlight.tsx +0 -1
- package/src/index.ts +0 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/styles.css +0 -326
package/esm/index.css
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
.
|
|
1
|
+
.m-5caae6d3 {
|
|
2
2
|
display: inline-block;
|
|
3
|
-
padding: 0.0625rem 0.1875rem;
|
|
4
|
-
font-size: 0.8125rem;
|
|
3
|
+
padding: calc(0.0625rem * var(--mantine-scale)) calc(0.1875rem * var(--mantine-scale));
|
|
4
|
+
font-size: calc(0.8125rem * var(--mantine-scale));
|
|
5
5
|
border-radius: var(--mantine-radius-xs);
|
|
6
6
|
line-height: var(--_code-line-height, var(--mantine-line-height));
|
|
7
7
|
font-family: var(--mantine-font-family-monospace);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.
|
|
10
|
+
.m-2c47c4fd {
|
|
11
11
|
display: block;
|
|
12
12
|
padding: var(--mantine-spacing-xs) var(--mantine-spacing-md);
|
|
13
13
|
margin: 0;
|
|
14
14
|
--_code-line-height: 1.7;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
.
|
|
17
|
+
.m-e58679f3 {
|
|
18
18
|
display: flex;
|
|
19
19
|
align-items: flex-start;
|
|
20
20
|
justify-content: space-between;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
.
|
|
23
|
+
.m-be7e9c9c {
|
|
24
24
|
display: flex;
|
|
25
|
-
margin-top: 0.4375rem;
|
|
26
|
-
margin-right: 0.4375rem;
|
|
25
|
+
margin-top: calc(0.4375rem * var(--mantine-scale));
|
|
26
|
+
margin-right: calc(0.4375rem * var(--mantine-scale));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
.
|
|
30
|
-
.
|
|
29
|
+
.m-5caae85b,
|
|
30
|
+
.m-d498bab7 {
|
|
31
31
|
background-color: transparent;
|
|
32
32
|
opacity: 0.8;
|
|
33
33
|
margin: 0;
|
|
@@ -35,149 +35,131 @@
|
|
|
35
35
|
|
|
36
36
|
@media (hover: hover) {
|
|
37
37
|
|
|
38
|
-
.
|
|
38
|
+
.m-5caae85b:hover, .m-d498bab7:hover {
|
|
39
39
|
opacity: 1;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
@media (hover: none) {
|
|
44
44
|
|
|
45
|
-
.
|
|
45
|
+
.m-5caae85b:active, .m-d498bab7:active {
|
|
46
46
|
opacity: 1;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
@media (max-width: 40em) {
|
|
51
51
|
|
|
52
|
-
.
|
|
53
|
-
.
|
|
52
|
+
.m-5caae85b,
|
|
53
|
+
.m-d498bab7 {
|
|
54
54
|
display: none
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
.
|
|
58
|
+
.m-5caae85b {
|
|
59
59
|
position: absolute;
|
|
60
|
-
top: 0.3125rem;
|
|
61
|
-
right: 0.3125rem;
|
|
60
|
+
top: calc(0.3125rem * var(--mantine-scale));
|
|
61
|
+
right: calc(0.3125rem * var(--mantine-scale));
|
|
62
62
|
z-index: 1;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
.
|
|
65
|
+
.m-5cac2e62 {
|
|
66
66
|
display: flex;
|
|
67
67
|
align-items: center;
|
|
68
68
|
justify-content: center;
|
|
69
69
|
font-size: var(--mantine-font-size-xs);
|
|
70
|
-
gap: 0.4375rem;
|
|
71
|
-
padding: 0.4375rem 0.75rem;
|
|
70
|
+
gap: calc(0.4375rem * var(--mantine-scale));
|
|
71
|
+
padding: calc(0.4375rem * var(--mantine-scale)) calc(0.75rem * var(--mantine-scale));
|
|
72
72
|
font-family: var(--mantine-font-family-monospace);
|
|
73
73
|
font-weight: 700;
|
|
74
74
|
line-height: 1;
|
|
75
75
|
user-select: none;
|
|
76
76
|
cursor: var(--_file-cursor);
|
|
77
|
-
border: 0.0625rem solid var(--_file-bd);
|
|
77
|
+
border: calc(0.0625rem * var(--mantine-scale)) solid var(--_file-bd);
|
|
78
78
|
border-top: 0;
|
|
79
79
|
border-left: 0;
|
|
80
80
|
color: var(--_file-color);
|
|
81
81
|
opacity: var(--_file-opacity);
|
|
82
82
|
background-color: var(--_file-bg);
|
|
83
|
+
white-space: nowrap;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
@media (hover: hover) {
|
|
86
87
|
|
|
87
|
-
.
|
|
88
|
+
.m-5cac2e62:hover {
|
|
88
89
|
--_file-opacity: 1;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
@media (hover: none) {
|
|
93
94
|
|
|
94
|
-
.
|
|
95
|
+
.m-5cac2e62:active {
|
|
95
96
|
--_file-opacity: 1;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
.
|
|
100
|
+
.m-5cac2e62:last-of-type {
|
|
100
101
|
border-bottom-right-radius: var(--mantine-radius-sm);
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
.
|
|
104
|
+
.m-5cac2e62:only-child {
|
|
104
105
|
--_file-cursor: default;
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
.
|
|
108
|
+
.m-5cac2e62[data-active] {
|
|
108
109
|
--_file-opacity: 1;
|
|
109
110
|
--_file-color: var(--_file-active-color) !important;
|
|
110
111
|
--_file-bg: var(--_file-active-bg);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
.
|
|
114
|
+
.m-5cac2e62 {
|
|
114
115
|
|
|
115
116
|
--_file-opacity: 0.8;
|
|
116
117
|
--_file-cursor: pointer;
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
[data-mantine-color-scheme='light'] .
|
|
120
|
+
[data-mantine-color-scheme='light'] .m-5cac2e62 {
|
|
120
121
|
--_file-color: var(--mantine-color-gray-8);
|
|
121
122
|
--_file-bd: var(--mantine-color-gray-2);
|
|
122
123
|
--_file-active-bg: var(--mantine-color-white);
|
|
123
124
|
--_file-active-color: var(--mantine-color-black);
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.mantine-PBrPXnu {
|
|
129
|
-
--_file-color: var(--mantine-color-gray-8);
|
|
130
|
-
--_file-bd: var(--mantine-color-gray-2);
|
|
131
|
-
--_file-active-bg: var(--mantine-color-white);
|
|
132
|
-
--_file-active-color: var(--mantine-color-black);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
[data-mantine-color-scheme='dark'] .mantine-PBrPXnu {
|
|
127
|
+
[data-mantine-color-scheme='dark'] .m-5cac2e62 {
|
|
137
128
|
--_file-color: var(--mantine-color-dark-0);
|
|
138
129
|
--_file-bd: var(--mantine-color-dark-4);
|
|
139
130
|
--_file-active-bg: var(--mantine-color-dark-6);
|
|
140
131
|
--_file-active-color: var(--mantine-color-white);
|
|
141
132
|
}
|
|
142
133
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.mantine-PBrPXnu {
|
|
146
|
-
--_file-color: var(--mantine-color-dark-0);
|
|
147
|
-
--_file-bd: var(--mantine-color-dark-4);
|
|
148
|
-
--_file-active-bg: var(--mantine-color-dark-6);
|
|
149
|
-
--_file-active-color: var(--mantine-color-white);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.mantine-IvOddiX {
|
|
134
|
+
.m-38d99e51 {
|
|
154
135
|
display: flex;
|
|
155
136
|
}
|
|
156
137
|
|
|
157
|
-
.
|
|
138
|
+
.m-9f507240 {
|
|
158
139
|
max-height: var(--ch-max-collapsed-height);
|
|
159
140
|
overflow: hidden;
|
|
160
141
|
position: relative;
|
|
161
142
|
}
|
|
162
143
|
|
|
163
|
-
.
|
|
144
|
+
.m-9f507240::before {
|
|
164
145
|
content: '';
|
|
146
|
+
z-index: 100;
|
|
165
147
|
position: absolute;
|
|
166
148
|
inset: 0;
|
|
167
149
|
pointer-events: none;
|
|
168
150
|
background-image: linear-gradient(0deg, var(--_background) 16%, rgba(0, 0, 0, 0) 100%);
|
|
169
|
-
border-radius: calc(var(--mantine-radius-md) - 0.0625rem);
|
|
151
|
+
border-radius: calc(var(--mantine-radius-md) - calc(0.0625rem * var(--mantine-scale)));
|
|
170
152
|
}
|
|
171
153
|
|
|
172
|
-
.
|
|
154
|
+
.m-9f507240[data-expanded] {
|
|
173
155
|
max-height: none;
|
|
174
156
|
}
|
|
175
157
|
|
|
176
|
-
.
|
|
158
|
+
.m-9f507240[data-expanded]::before {
|
|
177
159
|
display: none;
|
|
178
160
|
}
|
|
179
161
|
|
|
180
|
-
.
|
|
162
|
+
.m-c9378bc2 {
|
|
181
163
|
position: absolute;
|
|
182
164
|
bottom: 0;
|
|
183
165
|
left: 50%;
|
|
@@ -186,39 +168,37 @@
|
|
|
186
168
|
color: var(--mantine-color-anchor);
|
|
187
169
|
width: 100%;
|
|
188
170
|
text-align: center;
|
|
171
|
+
z-index: 101;
|
|
189
172
|
padding-top: var(--mantine-spacing-xs);
|
|
190
173
|
padding-bottom: var(--mantine-spacing-xs);
|
|
191
174
|
}
|
|
192
175
|
|
|
193
|
-
.
|
|
176
|
+
.m-c9378bc2[data-hidden] {
|
|
194
177
|
display: none;
|
|
195
178
|
}
|
|
196
179
|
|
|
197
|
-
.
|
|
180
|
+
.m-5cb1b9c8 {
|
|
198
181
|
margin-top: 0;
|
|
199
182
|
position: relative;
|
|
200
183
|
}
|
|
201
184
|
|
|
202
|
-
.
|
|
203
|
-
|
|
204
|
-
|
|
185
|
+
.m-b46cddfb {
|
|
186
|
+
display: flex;
|
|
187
|
+
align-items: center;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
flex: 0 1;
|
|
205
190
|
}
|
|
206
191
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
--code-comment-color: var(--mantine-color-gray-6);
|
|
211
|
-
--code-keyword-color: var(--mantine-color-violet-8);
|
|
212
|
-
--code-tag-color: var(--mantine-color-red-9);
|
|
213
|
-
--code-literal-color: var(--mantine-color-blue-6);
|
|
214
|
-
--code-string-color: var(--mantine-color-blue-9);
|
|
215
|
-
--code-variable-color: var(--mantine-color-lime-9);
|
|
216
|
-
--code-class-color: var(--mantine-color-orange-9);
|
|
217
|
-
}
|
|
192
|
+
.m-b46cddfb > svg {
|
|
193
|
+
display: block;
|
|
194
|
+
}
|
|
218
195
|
|
|
219
|
-
|
|
196
|
+
.m-1f5e827e {
|
|
197
|
+
color: var(--_color);
|
|
198
|
+
background: var(--_background);
|
|
199
|
+
}
|
|
220
200
|
|
|
221
|
-
|
|
201
|
+
[data-mantine-color-scheme='light'] .m-1f5e827e {
|
|
222
202
|
--_color: var(--mantine-color-gray-7);
|
|
223
203
|
--_background: var(--mantine-color-gray-0);
|
|
224
204
|
--code-comment-color: var(--mantine-color-gray-6);
|
|
@@ -228,24 +208,9 @@
|
|
|
228
208
|
--code-string-color: var(--mantine-color-blue-9);
|
|
229
209
|
--code-variable-color: var(--mantine-color-lime-9);
|
|
230
210
|
--code-class-color: var(--mantine-color-orange-9);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
[data-mantine-color-scheme='dark'] .mantine-h-DP-Yw {
|
|
235
|
-
--_color: var(--mantine-color-dark-1);
|
|
236
|
-
--_background: var(--mantine-color-dark-8);
|
|
237
|
-
--code-comment-color: var(--mantine-color-dark-3);
|
|
238
|
-
--code-keyword-color: var(--mantine-color-violet-3);
|
|
239
|
-
--code-tag-color: var(--mantine-color-yellow-4);
|
|
240
|
-
--code-literal-color: var(--mantine-color-blue-4);
|
|
241
|
-
--code-string-color: var(--mantine-color-green-6);
|
|
242
|
-
--code-variable-color: var(--mantine-color-blue-2);
|
|
243
|
-
--code-class-color: var(--mantine-color-orange-5);
|
|
244
211
|
}
|
|
245
212
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
.mantine-h-DP-Yw {
|
|
213
|
+
[data-mantine-color-scheme='dark'] .m-1f5e827e {
|
|
249
214
|
--_color: var(--mantine-color-dark-1);
|
|
250
215
|
--_background: var(--mantine-color-dark-8);
|
|
251
216
|
--code-comment-color: var(--mantine-color-dark-3);
|
|
@@ -255,72 +220,71 @@
|
|
|
255
220
|
--code-string-color: var(--mantine-color-green-6);
|
|
256
221
|
--code-variable-color: var(--mantine-color-blue-2);
|
|
257
222
|
--code-class-color: var(--mantine-color-orange-5);
|
|
258
|
-
}
|
|
259
223
|
}
|
|
260
224
|
|
|
261
|
-
.
|
|
262
|
-
.
|
|
225
|
+
.m-1f5e827e .hljs-comment,
|
|
226
|
+
.m-1f5e827e .hljs-quote {
|
|
263
227
|
font-style: italic;
|
|
264
228
|
color: var(--code-comment-color);
|
|
265
229
|
}
|
|
266
230
|
|
|
267
|
-
.
|
|
268
|
-
.
|
|
269
|
-
.
|
|
231
|
+
.m-1f5e827e .hljs-doctag,
|
|
232
|
+
.m-1f5e827e .hljs-formula,
|
|
233
|
+
.m-1f5e827e .hljs-keyword {
|
|
270
234
|
color: var(--code-keyword-color);
|
|
271
235
|
}
|
|
272
236
|
|
|
273
|
-
.
|
|
274
|
-
.
|
|
275
|
-
.
|
|
276
|
-
.
|
|
277
|
-
.
|
|
237
|
+
.m-1f5e827e .hljs-deletion,
|
|
238
|
+
.m-1f5e827e .hljs-name,
|
|
239
|
+
.m-1f5e827e .hljs-section,
|
|
240
|
+
.m-1f5e827e .hljs-selector-tag,
|
|
241
|
+
.m-1f5e827e .hljs-subst {
|
|
278
242
|
color: var(--code-tag-color);
|
|
279
243
|
}
|
|
280
244
|
|
|
281
|
-
.
|
|
245
|
+
.m-1f5e827e .hljs-literal {
|
|
282
246
|
color: var(--code-literal-color);
|
|
283
247
|
}
|
|
284
248
|
|
|
285
|
-
.
|
|
286
|
-
.
|
|
287
|
-
.
|
|
288
|
-
.
|
|
289
|
-
.
|
|
249
|
+
.m-1f5e827e .hljs-addition,
|
|
250
|
+
.m-1f5e827e .hljs-attribute,
|
|
251
|
+
.m-1f5e827e .hljs-meta .hljs-string,
|
|
252
|
+
.m-1f5e827e .hljs-regexp,
|
|
253
|
+
.m-1f5e827e .hljs-string {
|
|
290
254
|
color: var(--code-string-color);
|
|
291
255
|
}
|
|
292
256
|
|
|
293
|
-
.
|
|
294
|
-
.
|
|
295
|
-
.
|
|
296
|
-
.
|
|
297
|
-
.
|
|
298
|
-
.
|
|
299
|
-
.
|
|
300
|
-
.
|
|
257
|
+
.m-1f5e827e .hljs-attr,
|
|
258
|
+
.m-1f5e827e .hljs-number,
|
|
259
|
+
.m-1f5e827e .hljs-selector-attr,
|
|
260
|
+
.m-1f5e827e .hljs-selector-class,
|
|
261
|
+
.m-1f5e827e .hljs-selector-pseudo,
|
|
262
|
+
.m-1f5e827e .hljs-template-variable,
|
|
263
|
+
.m-1f5e827e .hljs-type,
|
|
264
|
+
.m-1f5e827e .hljs-variable {
|
|
301
265
|
color: var(--code-variable-color);
|
|
302
266
|
}
|
|
303
267
|
|
|
304
|
-
.
|
|
305
|
-
.
|
|
306
|
-
.
|
|
307
|
-
.
|
|
308
|
-
.
|
|
309
|
-
.
|
|
310
|
-
.
|
|
311
|
-
.
|
|
312
|
-
.
|
|
268
|
+
.m-1f5e827e .hljs-bullet,
|
|
269
|
+
.m-1f5e827e .hljs-link,
|
|
270
|
+
.m-1f5e827e .hljs-meta,
|
|
271
|
+
.m-1f5e827e .hljs-selector-id,
|
|
272
|
+
.m-1f5e827e .hljs-symbol,
|
|
273
|
+
.m-1f5e827e .hljs-title,
|
|
274
|
+
.m-1f5e827e .hljs-built_in,
|
|
275
|
+
.m-1f5e827e .hljs-class .hljs-title,
|
|
276
|
+
.m-1f5e827e .hljs-title.class_ {
|
|
313
277
|
color: var(--code-class-color);
|
|
314
278
|
}
|
|
315
279
|
|
|
316
|
-
.
|
|
280
|
+
.m-1f5e827e .hljs-emphasis {
|
|
317
281
|
font-style: italic;
|
|
318
282
|
}
|
|
319
283
|
|
|
320
|
-
.
|
|
284
|
+
.m-1f5e827e .hljs-strong {
|
|
321
285
|
font-weight: 700;
|
|
322
286
|
}
|
|
323
287
|
|
|
324
|
-
.
|
|
288
|
+
.m-1f5e827e .hljs-link {
|
|
325
289
|
text-decoration: underline;
|
|
326
290
|
}
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
package/esm/use-highlight.js
CHANGED
|
@@ -4,7 +4,9 @@ import hljs from 'highlight.js';
|
|
|
4
4
|
function useHighlight({ code, language, highlightOnClient }) {
|
|
5
5
|
const getHighlightedCode = () => hljs.highlight(code.trim(), { language }).value;
|
|
6
6
|
const [highlighted, setHighlighted] = useState(!highlightOnClient);
|
|
7
|
-
const [highlightedCode, setHighlightedCode] = useState(
|
|
7
|
+
const [highlightedCode, setHighlightedCode] = useState(
|
|
8
|
+
highlightOnClient ? code : getHighlightedCode()
|
|
9
|
+
);
|
|
8
10
|
const getCodeProps = () => highlighted ? { dangerouslySetInnerHTML: { __html: highlightedCode } } : { children: code.trim() };
|
|
9
11
|
useEffect(() => {
|
|
10
12
|
if (highlightOnClient) {
|
package/esm/use-highlight.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-highlight.js","sources":["../src/use-highlight.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport hljs from 'highlight.js';\n\ninterface UseHighlightInput {\n code: string;\n language: string;\n highlightOnClient: boolean | undefined;\n}\n\nexport function useHighlight({ code, language, highlightOnClient }: UseHighlightInput) {\n const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language! }).value;\n const [highlighted, setHighlighted] = useState(!highlightOnClient);\n const [highlightedCode, setHighlightedCode] = useState(\n highlightOnClient ? code : getHighlightedCode()\n );\n\n const getCodeProps = () =>\n highlighted\n ? { dangerouslySetInnerHTML: { __html: highlightedCode } }\n : { children: code.trim() };\n\n useEffect(() => {\n if (highlightOnClient) {\n setHighlightedCode(getHighlightedCode());\n setHighlighted(true);\n }\n }, []);\n\n return getCodeProps;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,EAAE;AACpE,EAAE,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC;AACnF,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC;AACrE,EAAE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"use-highlight.js","sources":["../src/use-highlight.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport hljs from 'highlight.js';\n\ninterface UseHighlightInput {\n code: string;\n language: string;\n highlightOnClient: boolean | undefined;\n}\n\nexport function useHighlight({ code, language, highlightOnClient }: UseHighlightInput) {\n const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language! }).value;\n const [highlighted, setHighlighted] = useState(!highlightOnClient);\n const [highlightedCode, setHighlightedCode] = useState(\n highlightOnClient ? code : getHighlightedCode()\n );\n\n const getCodeProps = () =>\n highlighted\n ? { dangerouslySetInnerHTML: { __html: highlightedCode } }\n : { children: code.trim() };\n\n useEffect(() => {\n if (highlightOnClient) {\n setHighlightedCode(getHighlightedCode());\n setHighlighted(true);\n }\n }, []);\n\n return getCodeProps;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,EAAE;AACpE,EAAE,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC;AACnF,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC;AACrE,EAAE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ;AACxD,IAAI,iBAAiB,GAAG,IAAI,GAAG,kBAAkB,EAAE;AACnD,GAAG,CAAC;AACJ,EAAE,MAAM,YAAY,GAAG,MAAM,WAAW,GAAG,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AAChI,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,iBAAiB,EAAE;AAC3B,MAAM,kBAAkB,CAAC,kBAAkB,EAAE,CAAC,CAAC;AAC/C,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC;AAC3B,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,YAAY,CAAC;AACtB;;;;"}
|
package/lib/CodeHighlight.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BoxProps, StylesApiProps, ElementProps, Factory } from '@mantine/core';
|
|
2
2
|
export type CodeHighlightStylesNames = 'root' | 'code' | 'pre' | 'copy';
|
|
3
|
-
export type CodeHighlightVariant = string;
|
|
4
3
|
export interface CodeHighlightProps extends BoxProps, StylesApiProps<CodeHighlightFactory>, ElementProps<'div'> {
|
|
5
4
|
/** Code to highlight */
|
|
6
5
|
code: string;
|
|
@@ -19,11 +18,9 @@ export type CodeHighlightFactory = Factory<{
|
|
|
19
18
|
props: CodeHighlightProps;
|
|
20
19
|
ref: HTMLDivElement;
|
|
21
20
|
stylesNames: CodeHighlightStylesNames;
|
|
22
|
-
variant: CodeHighlightVariant;
|
|
23
21
|
}>;
|
|
24
22
|
export declare const CodeHighlight: import("@mantine/core").MantineComponent<{
|
|
25
23
|
props: CodeHighlightProps;
|
|
26
24
|
ref: HTMLDivElement;
|
|
27
25
|
stylesNames: CodeHighlightStylesNames;
|
|
28
|
-
variant: CodeHighlightVariant;
|
|
29
26
|
}>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BoxProps, StylesApiProps, ElementProps, Factory } from '@mantine/core';
|
|
3
|
-
export type CodeHighlightTabsStylesNames = 'root' | 'code' | 'codeWrapper' | 'showCodeButton' | 'pre' | 'controls' | 'control' | 'header' | 'file' | 'files';
|
|
4
|
-
export type CodeHighlightTabsVariant = string;
|
|
3
|
+
export type CodeHighlightTabsStylesNames = 'root' | 'code' | 'codeWrapper' | 'showCodeButton' | 'pre' | 'controls' | 'control' | 'header' | 'file' | 'files' | 'fileIcon';
|
|
5
4
|
export type CodeHighlightTabsCssVariables = {
|
|
6
5
|
root: '--ch-max-collapsed-height';
|
|
7
6
|
};
|
|
@@ -28,7 +27,7 @@ export interface CodeHighlightTabsProps extends BoxProps, StylesApiProps<CodeHig
|
|
|
28
27
|
copiedLabel?: string;
|
|
29
28
|
/** Function that returns icon based on file name */
|
|
30
29
|
getFileIcon?(fileName: string): React.ReactNode;
|
|
31
|
-
/** `max-height` of code in collapsed state
|
|
30
|
+
/** `max-height` of code in collapsed state */
|
|
32
31
|
maxCollapsedHeight?: React.CSSProperties['maxHeight'];
|
|
33
32
|
/** Controlled expanded state */
|
|
34
33
|
expanded?: boolean;
|
package/lib/CopyIcon.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
interface CopyIconProps extends React.ComponentPropsWithoutRef<'svg'> {
|
|
3
3
|
copied: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare function CopyIcon({ copied, style, ...others }: CopyIconProps): JSX.Element;
|
|
5
|
+
export declare function CopyIcon({ copied, style, ...others }: CopyIconProps): React.JSX.Element;
|
|
6
6
|
export declare namespace CopyIcon {
|
|
7
7
|
var displayName: string;
|
|
8
8
|
}
|
package/lib/ExpandIcon.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import React from 'react';
|
|
|
2
2
|
interface ExpandIconProps extends React.ComponentPropsWithoutRef<'svg'> {
|
|
3
3
|
expanded: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare function ExpandIcon({ expanded, style, ...others }: ExpandIconProps): JSX.Element;
|
|
5
|
+
export declare function ExpandIcon({ expanded, style, ...others }: ExpandIconProps): React.JSX.Element;
|
|
6
6
|
export {};
|
package/lib/FileIcon.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ interface FileIconProps {
|
|
|
3
3
|
fileName: string | undefined;
|
|
4
4
|
getFileIcon?: ((fileName: string) => React.ReactNode) | undefined;
|
|
5
5
|
fileIcon: React.ReactNode | undefined;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
6
8
|
}
|
|
7
|
-
export declare function FileIcon({ fileIcon, fileName, getFileIcon }: FileIconProps): JSX.Element | null;
|
|
9
|
+
export declare function FileIcon({ fileIcon, fileName, getFileIcon, className, style }: FileIconProps): React.JSX.Element | null;
|
|
8
10
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BoxProps, StylesApiProps, ElementProps, Factory } from '@mantine/core';
|
|
2
2
|
export type InlineCodeHighlightStylesNames = 'code';
|
|
3
|
-
export type InlineCodeHighlightVariant = string;
|
|
4
3
|
export interface InlineCodeHighlightProps extends BoxProps, StylesApiProps<InlineCodeHighlightFactory>, ElementProps<'div'> {
|
|
5
4
|
/** Code to highlight */
|
|
6
5
|
code: string;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { CodeHighlightTabs } from './CodeHighlightTabs';
|
|
2
2
|
export { CodeHighlight } from './CodeHighlight';
|
|
3
3
|
export { InlineCodeHighlight } from './InlineCodeHighlight';
|
|
4
|
-
export type { CodeHighlightTabsFactory, CodeHighlightTabsStylesNames, CodeHighlightTabsProps, CodeHighlightTabsCode,
|
|
5
|
-
export type { CodeHighlightFactory, CodeHighlightProps, CodeHighlightStylesNames,
|
|
6
|
-
export type { InlineCodeHighlightFactory, InlineCodeHighlightProps, InlineCodeHighlightStylesNames,
|
|
4
|
+
export type { CodeHighlightTabsFactory, CodeHighlightTabsStylesNames, CodeHighlightTabsProps, CodeHighlightTabsCode, CodeHighlightTabsCssVariables, } from './CodeHighlightTabs';
|
|
5
|
+
export type { CodeHighlightFactory, CodeHighlightProps, CodeHighlightStylesNames, } from './CodeHighlight';
|
|
6
|
+
export type { InlineCodeHighlightFactory, InlineCodeHighlightProps, InlineCodeHighlightStylesNames, } from './InlineCodeHighlight';
|
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantine/code-highlight",
|
|
3
3
|
"description": "Code highlight with Mantine theme",
|
|
4
|
-
"version": "7.0.0-alpha.
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
4
|
+
"version": "7.0.0-alpha.21",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./esm/index.js",
|
|
9
|
+
"require": "./cjs/index.js",
|
|
10
|
+
"types": "./lib/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./styles.css": "./esm/index.css"
|
|
13
|
+
},
|
|
8
14
|
"license": "MIT",
|
|
9
15
|
"author": "Vitaly Rtishchev <rtivital@gmail.com>",
|
|
10
|
-
"sideEffects":
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"*.css"
|
|
18
|
+
],
|
|
11
19
|
"homepage": "https://mantine.dev/others/prism/",
|
|
12
20
|
"repository": {
|
|
13
21
|
"url": "https://github.com/mantinedev/mantine.git",
|
|
@@ -29,14 +37,14 @@
|
|
|
29
37
|
"syntax-highlight"
|
|
30
38
|
],
|
|
31
39
|
"peerDependencies": {
|
|
32
|
-
"@mantine/core": "7.0.0-alpha.
|
|
33
|
-
"@mantine/hooks": "7.0.0-alpha.
|
|
34
|
-
"react": "
|
|
35
|
-
"react-dom": "
|
|
40
|
+
"@mantine/core": "7.0.0-alpha.21",
|
|
41
|
+
"@mantine/hooks": "7.0.0-alpha.21",
|
|
42
|
+
"react": "^18.2.0",
|
|
43
|
+
"react-dom": "^18.2.0"
|
|
36
44
|
},
|
|
37
45
|
"dependencies": {
|
|
38
46
|
"highlight.js": "^11.7.0",
|
|
39
|
-
"clsx": "
|
|
47
|
+
"clsx": "2.0.0"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {}
|
|
42
50
|
}
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
color: var(--_file-color);
|
|
67
67
|
opacity: var(--_file-opacity);
|
|
68
68
|
background-color: var(--_file-bg);
|
|
69
|
+
white-space: nowrap;
|
|
69
70
|
|
|
70
71
|
@mixin hover {
|
|
71
72
|
--_file-opacity: 1;
|
|
@@ -114,6 +115,7 @@
|
|
|
114
115
|
|
|
115
116
|
&::before {
|
|
116
117
|
content: '';
|
|
118
|
+
z-index: 100;
|
|
117
119
|
position: absolute;
|
|
118
120
|
inset: 0;
|
|
119
121
|
pointer-events: none;
|
|
@@ -139,6 +141,7 @@
|
|
|
139
141
|
color: var(--mantine-color-anchor);
|
|
140
142
|
width: 100%;
|
|
141
143
|
text-align: center;
|
|
144
|
+
z-index: 101;
|
|
142
145
|
padding-top: var(--mantine-spacing-xs);
|
|
143
146
|
padding-bottom: var(--mantine-spacing-xs);
|
|
144
147
|
|
|
@@ -151,3 +154,14 @@
|
|
|
151
154
|
margin-top: 0;
|
|
152
155
|
position: relative;
|
|
153
156
|
}
|
|
157
|
+
|
|
158
|
+
.fileIcon {
|
|
159
|
+
display: flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
justify-content: center;
|
|
162
|
+
flex: 0;
|
|
163
|
+
|
|
164
|
+
& > svg {
|
|
165
|
+
display: block;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -194,6 +194,12 @@ export function Tabs() {
|
|
|
194
194
|
code={[
|
|
195
195
|
{ code: tsxCode, language: 'tsx', icon: <TsIcon />, fileName: 'Component.tsx' },
|
|
196
196
|
{ code: cssCode, language: 'css', icon: <CSSIcon />, fileName: 'Component.module.css' },
|
|
197
|
+
{
|
|
198
|
+
code: cssCode,
|
|
199
|
+
language: 'css',
|
|
200
|
+
icon: <CSSIcon />,
|
|
201
|
+
fileName: 'Long-file-name-that-will-break-to-another-line.css',
|
|
202
|
+
},
|
|
197
203
|
]}
|
|
198
204
|
defaultExpanded={false}
|
|
199
205
|
>
|
package/src/CodeHighlight.tsx
CHANGED
|
@@ -22,7 +22,6 @@ import themeClasses from './CodeHighlight.theme.module.css';
|
|
|
22
22
|
const classes = { ..._classes, root: cx(_classes.root, themeClasses.theme) };
|
|
23
23
|
|
|
24
24
|
export type CodeHighlightStylesNames = 'root' | 'code' | 'pre' | 'copy';
|
|
25
|
-
export type CodeHighlightVariant = string;
|
|
26
25
|
|
|
27
26
|
export interface CodeHighlightProps
|
|
28
27
|
extends BoxProps,
|
|
@@ -51,7 +50,6 @@ export type CodeHighlightFactory = Factory<{
|
|
|
51
50
|
props: CodeHighlightProps;
|
|
52
51
|
ref: HTMLDivElement;
|
|
53
52
|
stylesNames: CodeHighlightStylesNames;
|
|
54
|
-
variant: CodeHighlightVariant;
|
|
55
53
|
}>;
|
|
56
54
|
|
|
57
55
|
const defaultProps: Partial<CodeHighlightProps> = {
|
|
@@ -111,7 +109,7 @@ export const CodeHighlight = factory<CodeHighlightFactory>((_props, ref) => {
|
|
|
111
109
|
</CopyButton>
|
|
112
110
|
)}
|
|
113
111
|
|
|
114
|
-
<ScrollArea type="
|
|
112
|
+
<ScrollArea type="hover" dir="ltr" offsetScrollbars={false}>
|
|
115
113
|
<pre {...getStyles('pre')}>
|
|
116
114
|
<code {...getStyles('code')} {...getCodeProps()} />
|
|
117
115
|
</pre>
|