@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.
Files changed (55) hide show
  1. package/cjs/CodeHighlight.js +1 -20
  2. package/cjs/CodeHighlight.js.map +1 -1
  3. package/cjs/CodeHighlight.module.css.js +1 -1
  4. package/cjs/CodeHighlight.theme.module.css.js +1 -1
  5. package/cjs/CodeHighlightTabs.js +41 -50
  6. package/cjs/CodeHighlightTabs.js.map +1 -1
  7. package/cjs/CopyIcon.js +14 -24
  8. package/cjs/CopyIcon.js.map +1 -1
  9. package/cjs/ExpandIcon.js +14 -38
  10. package/cjs/ExpandIcon.js.map +1 -1
  11. package/cjs/FileIcon.js +3 -3
  12. package/cjs/FileIcon.js.map +1 -1
  13. package/cjs/InlineCodeHighlight.js +9 -6
  14. package/cjs/InlineCodeHighlight.js.map +1 -1
  15. package/cjs/index.css +91 -127
  16. package/cjs/index.js +1 -0
  17. package/cjs/index.js.map +1 -1
  18. package/cjs/use-highlight.js +3 -1
  19. package/cjs/use-highlight.js.map +1 -1
  20. package/esm/CodeHighlight.js +1 -20
  21. package/esm/CodeHighlight.js.map +1 -1
  22. package/esm/CodeHighlight.module.css.js +1 -1
  23. package/esm/CodeHighlight.theme.module.css.js +1 -1
  24. package/esm/CodeHighlightTabs.js +42 -51
  25. package/esm/CodeHighlightTabs.js.map +1 -1
  26. package/esm/CopyIcon.js +14 -24
  27. package/esm/CopyIcon.js.map +1 -1
  28. package/esm/ExpandIcon.js +14 -38
  29. package/esm/ExpandIcon.js.map +1 -1
  30. package/esm/FileIcon.js +3 -3
  31. package/esm/FileIcon.js.map +1 -1
  32. package/esm/InlineCodeHighlight.js +9 -6
  33. package/esm/InlineCodeHighlight.js.map +1 -1
  34. package/esm/index.css +91 -127
  35. package/esm/index.js +1 -0
  36. package/esm/index.js.map +1 -1
  37. package/esm/use-highlight.js +3 -1
  38. package/esm/use-highlight.js.map +1 -1
  39. package/lib/CodeHighlight.d.ts +0 -3
  40. package/lib/CodeHighlightTabs.d.ts +2 -3
  41. package/lib/CopyIcon.d.ts +1 -1
  42. package/lib/ExpandIcon.d.ts +1 -1
  43. package/lib/FileIcon.d.ts +3 -1
  44. package/lib/InlineCodeHighlight.d.ts +0 -1
  45. package/lib/index.d.ts +3 -3
  46. package/package.json +18 -10
  47. package/src/CodeHighlight.module.css +14 -0
  48. package/src/CodeHighlight.story.tsx +6 -0
  49. package/src/CodeHighlight.tsx +1 -3
  50. package/src/CodeHighlightTabs.tsx +10 -5
  51. package/src/FileIcon.tsx +13 -3
  52. package/src/InlineCodeHighlight.tsx +0 -1
  53. package/src/index.ts +0 -3
  54. package/tsconfig.build.tsbuildinfo +1 -1
  55. package/styles.css +0 -326
package/esm/index.css CHANGED
@@ -1,33 +1,33 @@
1
- .mantine-XIBJZDt {
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
- .mantine-RDvBcjB {
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
- .mantine-cmEtjrV {
17
+ .m-e58679f3 {
18
18
  display: flex;
19
19
  align-items: flex-start;
20
20
  justify-content: space-between;
21
21
  }
22
22
 
23
- .mantine-059sM-t {
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
- .mantine-tB-P5PD,
30
- .mantine-NTm-nGn {
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
- .mantine-tB-P5PD:hover, .mantine-NTm-nGn:hover {
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
- .mantine-tB-P5PD:active, .mantine-NTm-nGn:active {
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
- .mantine-tB-P5PD,
53
- .mantine-NTm-nGn {
52
+ .m-5caae85b,
53
+ .m-d498bab7 {
54
54
  display: none
55
55
  }
56
56
  }
57
57
 
58
- .mantine-tB-P5PD {
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
- .mantine-PBrPXnu {
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
- .mantine-PBrPXnu:hover {
88
+ .m-5cac2e62:hover {
88
89
  --_file-opacity: 1;
89
90
  }
90
91
  }
91
92
 
92
93
  @media (hover: none) {
93
94
 
94
- .mantine-PBrPXnu:active {
95
+ .m-5cac2e62:active {
95
96
  --_file-opacity: 1;
96
97
  }
97
98
  }
98
99
 
99
- .mantine-PBrPXnu:last-of-type {
100
+ .m-5cac2e62:last-of-type {
100
101
  border-bottom-right-radius: var(--mantine-radius-sm);
101
102
  }
102
103
 
103
- .mantine-PBrPXnu:only-child {
104
+ .m-5cac2e62:only-child {
104
105
  --_file-cursor: default;
105
106
  }
106
107
 
107
- .mantine-PBrPXnu[data-active] {
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
- .mantine-PBrPXnu {
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'] .mantine-PBrPXnu {
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
- @media (prefers-color-scheme: light) {
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
- @media (prefers-color-scheme: dark) {
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
- .mantine-YfYyOiA {
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
- .mantine-YfYyOiA::before {
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
- .mantine-YfYyOiA[data-expanded] {
154
+ .m-9f507240[data-expanded] {
173
155
  max-height: none;
174
156
  }
175
157
 
176
- .mantine-YfYyOiA[data-expanded]::before {
158
+ .m-9f507240[data-expanded]::before {
177
159
  display: none;
178
160
  }
179
161
 
180
- .mantine-haNyFRC {
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
- .mantine-haNyFRC[data-hidden] {
176
+ .m-c9378bc2[data-hidden] {
194
177
  display: none;
195
178
  }
196
179
 
197
- .mantine-k6OJW8l {
180
+ .m-5cb1b9c8 {
198
181
  margin-top: 0;
199
182
  position: relative;
200
183
  }
201
184
 
202
- .mantine-h-DP-Yw {
203
- color: var(--_color);
204
- background: var(--_background);
185
+ .m-b46cddfb {
186
+ display: flex;
187
+ align-items: center;
188
+ justify-content: center;
189
+ flex: 0 1;
205
190
  }
206
191
 
207
- [data-mantine-color-scheme='light'] .mantine-h-DP-Yw {
208
- --_color: var(--mantine-color-gray-7);
209
- --_background: var(--mantine-color-gray-0);
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
- @media (prefers-color-scheme: light) {
196
+ .m-1f5e827e {
197
+ color: var(--_color);
198
+ background: var(--_background);
199
+ }
220
200
 
221
- .mantine-h-DP-Yw {
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
- @media (prefers-color-scheme: dark) {
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
- .mantine-h-DP-Yw .hljs-comment,
262
- .mantine-h-DP-Yw .hljs-quote {
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
- .mantine-h-DP-Yw .hljs-doctag,
268
- .mantine-h-DP-Yw .hljs-formula,
269
- .mantine-h-DP-Yw .hljs-keyword {
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
- .mantine-h-DP-Yw .hljs-deletion,
274
- .mantine-h-DP-Yw .hljs-name,
275
- .mantine-h-DP-Yw .hljs-section,
276
- .mantine-h-DP-Yw .hljs-selector-tag,
277
- .mantine-h-DP-Yw .hljs-subst {
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
- .mantine-h-DP-Yw .hljs-literal {
245
+ .m-1f5e827e .hljs-literal {
282
246
  color: var(--code-literal-color);
283
247
  }
284
248
 
285
- .mantine-h-DP-Yw .hljs-addition,
286
- .mantine-h-DP-Yw .hljs-attribute,
287
- .mantine-h-DP-Yw .hljs-meta .hljs-string,
288
- .mantine-h-DP-Yw .hljs-regexp,
289
- .mantine-h-DP-Yw .hljs-string {
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
- .mantine-h-DP-Yw .hljs-attr,
294
- .mantine-h-DP-Yw .hljs-number,
295
- .mantine-h-DP-Yw .hljs-selector-attr,
296
- .mantine-h-DP-Yw .hljs-selector-class,
297
- .mantine-h-DP-Yw .hljs-selector-pseudo,
298
- .mantine-h-DP-Yw .hljs-template-variable,
299
- .mantine-h-DP-Yw .hljs-type,
300
- .mantine-h-DP-Yw .hljs-variable {
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
- .mantine-h-DP-Yw .hljs-bullet,
305
- .mantine-h-DP-Yw .hljs-link,
306
- .mantine-h-DP-Yw .hljs-meta,
307
- .mantine-h-DP-Yw .hljs-selector-id,
308
- .mantine-h-DP-Yw .hljs-symbol,
309
- .mantine-h-DP-Yw .hljs-title,
310
- .mantine-h-DP-Yw .hljs-built_in,
311
- .mantine-h-DP-Yw .hljs-class .hljs-title,
312
- .mantine-h-DP-Yw .hljs-title.class_ {
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
- .mantine-h-DP-Yw .hljs-emphasis {
280
+ .m-1f5e827e .hljs-emphasis {
317
281
  font-style: italic;
318
282
  }
319
283
 
320
- .mantine-h-DP-Yw .hljs-strong {
284
+ .m-1f5e827e .hljs-strong {
321
285
  font-weight: 700;
322
286
  }
323
287
 
324
- .mantine-h-DP-Yw .hljs-link {
288
+ .m-1f5e827e .hljs-link {
325
289
  text-decoration: underline;
326
290
  }
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  export { CodeHighlightTabs } from './CodeHighlightTabs.js';
2
3
  export { CodeHighlight } from './CodeHighlight.js';
3
4
  export { InlineCodeHighlight } from './InlineCodeHighlight.js';
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":";;;"}
@@ -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(highlightOnClient ? code : getHighlightedCode());
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) {
@@ -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,CAAC,iBAAiB,GAAG,IAAI,GAAG,kBAAkB,EAAE,CAAC,CAAC;AAC1G,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;;;;"}
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;;;;"}
@@ -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, `'6rem'` by default */
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
  }
@@ -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, CodeHighlightTabsVariant, CodeHighlightTabsCssVariables, } from './CodeHighlightTabs';
5
- export type { CodeHighlightFactory, CodeHighlightProps, CodeHighlightStylesNames, CodeHighlightVariant, } from './CodeHighlight';
6
- export type { InlineCodeHighlightFactory, InlineCodeHighlightProps, InlineCodeHighlightStylesNames, InlineCodeHighlightVariant, } from './InlineCodeHighlight';
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.2",
5
- "main": "cjs/index.js",
6
- "module": "esm/index.js",
7
- "types": "lib/index.d.ts",
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": false,
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.2",
33
- "@mantine/hooks": "7.0.0-alpha.2",
34
- "react": ">=16.8.0",
35
- "react-dom": ">=16.8.0"
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": "1.1.1"
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
  >
@@ -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="auto" dir="ltr" offsetScrollbars={false}>
112
+ <ScrollArea type="hover" dir="ltr" offsetScrollbars={false}>
115
113
  <pre {...getStyles('pre')}>
116
114
  <code {...getStyles('code')} {...getCodeProps()} />
117
115
  </pre>