@rxdrag/website-lib-core 0.0.86 → 0.0.88
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.88",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@types/react-dom": "^19.1.0",
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
|
-
"@rxdrag/
|
|
27
|
+
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
28
28
|
"@rxdrag/tsconfig": "0.2.0",
|
|
29
|
-
"@rxdrag/
|
|
29
|
+
"@rxdrag/slate-preview": "1.2.61"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@iconify/utils": "^3.0.2",
|
package/src/entify/Entify.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { queryPageBySlug } from "./lib/queryPageBySlug";
|
|
|
42
42
|
import { queryPageByType } from "./lib/queryPageByType";
|
|
43
43
|
import { queryOneMedia } from "./lib/queryOneMedia";
|
|
44
44
|
import { DEFAULT_LARGE, DEFAULT_MEDIUM, DEFAULT_SAMLL, DEFUALT_HEIGHT, DEFUALT_WIDTH, FileFieldType, ImageResize } from "../astro/media";
|
|
45
|
+
import { queryOneIcon } from "./lib/queryOneIcon";
|
|
45
46
|
|
|
46
47
|
export class Entify implements IEntify {
|
|
47
48
|
private static instance: Entify | null = null;
|
|
@@ -132,6 +133,10 @@ export class Entify implements IEntify {
|
|
|
132
133
|
return await queryOneMedia(ref, fields, this.envVariables);
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
public async getIcon(name: string | undefined | null) {
|
|
137
|
+
return await queryOneIcon(name, this.envVariables);
|
|
138
|
+
}
|
|
139
|
+
|
|
135
140
|
public async getFeaturedProducts(
|
|
136
141
|
count?: number,
|
|
137
142
|
imageSize?: ImageSize,
|
package/src/entify/IEntify.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
PageType,
|
|
17
17
|
Product,
|
|
18
18
|
SearchIndex,
|
|
19
|
+
SvgIcon,
|
|
19
20
|
ThemeBranch,
|
|
20
21
|
Website,
|
|
21
22
|
WebsitePart,
|
|
@@ -61,6 +62,8 @@ export interface IEntify {
|
|
|
61
62
|
|
|
62
63
|
getMedia(ref: string | undefined | null, fileField?: FileFieldType, resize?: ImageResize): Promise<Media | undefined>;
|
|
63
64
|
|
|
65
|
+
getIcon(name: string | undefined | null): Promise<SvgIcon | undefined>;
|
|
66
|
+
|
|
64
67
|
getFeaturedProducts(
|
|
65
68
|
count?: number,
|
|
66
69
|
imageSize?: ImageSize,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SvgIcon, SvgIconBoolExp, SvgIconDistinctExp, SvgIconOrderBy, SvgIconQueryOptions, SvgIconFields } from "@rxdrag/rxcms-models";
|
|
2
|
+
import { EnvVariables } from "../types";
|
|
3
|
+
import { queryOneEntity } from "./queryOneEntity";
|
|
4
|
+
|
|
5
|
+
export const queryOneIcon = async (
|
|
6
|
+
name: string | undefined | null,
|
|
7
|
+
envVariables: EnvVariables) => {
|
|
8
|
+
|
|
9
|
+
const icon = await queryOneEntity<SvgIcon, SvgIconBoolExp, SvgIconOrderBy, SvgIconDistinctExp>(
|
|
10
|
+
new SvgIconQueryOptions([
|
|
11
|
+
SvgIconFields.id,
|
|
12
|
+
SvgIconFields.name,
|
|
13
|
+
SvgIconFields.title,
|
|
14
|
+
SvgIconFields.code,
|
|
15
|
+
], {
|
|
16
|
+
where: {
|
|
17
|
+
name: {
|
|
18
|
+
"_eq": name || ""
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
.setNoQuery(!name)
|
|
23
|
+
,
|
|
24
|
+
envVariables
|
|
25
|
+
);
|
|
26
|
+
return icon;
|
|
27
|
+
};
|
|
@@ -63,15 +63,8 @@ export async function queryProducts(
|
|
|
63
63
|
[
|
|
64
64
|
ProductCategoryFields.id,
|
|
65
65
|
ProductCategoryFields.slug,
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
where: {
|
|
69
|
-
slug: {
|
|
70
|
-
_eq: categorySlug,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
}
|
|
74
|
-
).children([])),
|
|
66
|
+
]
|
|
67
|
+
).children([ProductCategoryFields.id])),
|
|
75
68
|
envVariables
|
|
76
69
|
);
|
|
77
70
|
if (category) {
|
|
@@ -16,7 +16,6 @@ export function svgToIconify(svgString: string): IconifyIcon | null {
|
|
|
16
16
|
const viewBox = svg.getAttribute("viewBox");
|
|
17
17
|
let width = svg.getAttribute("width");
|
|
18
18
|
let height = svg.getAttribute("height");
|
|
19
|
-
const body = svg.innerHTML;
|
|
20
19
|
|
|
21
20
|
// 如果没有显式宽高,尝试从 viewBox 解析
|
|
22
21
|
if (viewBox && (!width || !height)) {
|
|
@@ -27,6 +26,27 @@ export function svgToIconify(svgString: string): IconifyIcon | null {
|
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
|
|
29
|
+
// 提取关键属性并包裹在 <g> 中,以保留 SVG 根节点的样式
|
|
30
|
+
const attributesToPreserve = [
|
|
31
|
+
"fill",
|
|
32
|
+
"stroke",
|
|
33
|
+
"stroke-width",
|
|
34
|
+
"stroke-linecap",
|
|
35
|
+
"stroke-linejoin"
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const gAttributes = attributesToPreserve
|
|
39
|
+
.map(attr => {
|
|
40
|
+
const value = svg.getAttribute(attr);
|
|
41
|
+
return value ? `${attr}="${value}"` : "";
|
|
42
|
+
})
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.join(" ");
|
|
45
|
+
|
|
46
|
+
const body = gAttributes
|
|
47
|
+
? `<g ${gAttributes}>${svg.innerHTML}</g>`
|
|
48
|
+
: svg.innerHTML;
|
|
49
|
+
|
|
30
50
|
return {
|
|
31
51
|
body,
|
|
32
52
|
width: width ? parseFloat(width) : undefined,
|