c063 1.6.3 → 1.6.4
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/utils/index.d.ts +1 -0
- package/dist/utils/index.js +23 -1
- package/package.json +1 -1
- package/src/utils/index.tsx +25 -1
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CodeTokenBuilder, CodeTokenProps, CodeTokenType } from "../types";
|
|
3
|
+
export declare const isCodeTokenType: (value: any) => value is CodeTokenType;
|
|
3
4
|
/**
|
|
4
5
|
* `c063` 是一組語法高亮 token 建構器集合。
|
|
5
6
|
* 每個 key 對應一種語法分類(如 `keyword1`, `string`, `comment` 等),
|
package/dist/utils/index.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
export const isCodeTokenType = (value) => {
|
|
3
|
+
const codeTokenTypes = [
|
|
4
|
+
"keyword1",
|
|
5
|
+
"keyword2",
|
|
6
|
+
"function",
|
|
7
|
+
"string",
|
|
8
|
+
"number",
|
|
9
|
+
"comment",
|
|
10
|
+
"type",
|
|
11
|
+
"variable",
|
|
12
|
+
"constant",
|
|
13
|
+
"brackets1",
|
|
14
|
+
"brackets2",
|
|
15
|
+
"brackets3",
|
|
16
|
+
"operator",
|
|
17
|
+
"default",
|
|
18
|
+
];
|
|
19
|
+
return codeTokenTypes.includes(value);
|
|
20
|
+
};
|
|
2
21
|
/**
|
|
3
22
|
* `c063` 是一組語法高亮 token 建構器集合。
|
|
4
23
|
* 每個 key 對應一種語法分類(如 `keyword1`, `string`, `comment` 等),
|
|
@@ -13,7 +32,7 @@ import React from "react";
|
|
|
13
32
|
* @returns 以 `CodeTokenType` 為 key 的建構器函式集合。
|
|
14
33
|
*/
|
|
15
34
|
const c063 = new Proxy({}, {
|
|
16
|
-
get: (
|
|
35
|
+
get: (target, prop, receiver) => {
|
|
17
36
|
/**
|
|
18
37
|
* 建立指定語法類型的 CodeToken。
|
|
19
38
|
*
|
|
@@ -22,6 +41,9 @@ const c063 = new Proxy({}, {
|
|
|
22
41
|
* @returns 一個 CodeToken 物件
|
|
23
42
|
*/
|
|
24
43
|
const builder = (children, props) => {
|
|
44
|
+
if (!isCodeTokenType(prop)) {
|
|
45
|
+
return Reflect.get(target, prop, receiver);
|
|
46
|
+
}
|
|
25
47
|
return {
|
|
26
48
|
children,
|
|
27
49
|
type: prop,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "c063",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.4",
|
|
5
5
|
"description": "A React component for displaying code snippets with syntax highlighting.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
package/src/utils/index.tsx
CHANGED
|
@@ -6,6 +6,27 @@ import {
|
|
|
6
6
|
ParsableLanguage,
|
|
7
7
|
} from "../types";
|
|
8
8
|
|
|
9
|
+
export const isCodeTokenType = (value: any): value is CodeTokenType => {
|
|
10
|
+
const codeTokenTypes: CodeTokenType[] = [
|
|
11
|
+
"keyword1",
|
|
12
|
+
"keyword2",
|
|
13
|
+
"function",
|
|
14
|
+
"string",
|
|
15
|
+
"number",
|
|
16
|
+
"comment",
|
|
17
|
+
"type",
|
|
18
|
+
"variable",
|
|
19
|
+
"constant",
|
|
20
|
+
"brackets1",
|
|
21
|
+
"brackets2",
|
|
22
|
+
"brackets3",
|
|
23
|
+
"operator",
|
|
24
|
+
"default",
|
|
25
|
+
];
|
|
26
|
+
return codeTokenTypes.includes(value);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
9
30
|
/**
|
|
10
31
|
* `c063` 是一組語法高亮 token 建構器集合。
|
|
11
32
|
* 每個 key 對應一種語法分類(如 `keyword1`, `string`, `comment` 等),
|
|
@@ -22,7 +43,7 @@ import {
|
|
|
22
43
|
const c063 = new Proxy(
|
|
23
44
|
{},
|
|
24
45
|
{
|
|
25
|
-
get: (
|
|
46
|
+
get: (target, prop: CodeTokenType, receiver) => {
|
|
26
47
|
/**
|
|
27
48
|
* 建立指定語法類型的 CodeToken。
|
|
28
49
|
*
|
|
@@ -34,6 +55,9 @@ const c063 = new Proxy(
|
|
|
34
55
|
children: React.ReactNode,
|
|
35
56
|
props?: CodeTokenProps<T>
|
|
36
57
|
) => {
|
|
58
|
+
if (!isCodeTokenType(prop)) {
|
|
59
|
+
return Reflect.get(target, prop, receiver);
|
|
60
|
+
}
|
|
37
61
|
return {
|
|
38
62
|
children,
|
|
39
63
|
type: prop,
|