@rxdrag/website-lib-core 0.0.69 → 0.0.70

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.69",
3
+ "version": "0.0.70",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -25,8 +25,8 @@
25
25
  "eslint": "^7.32.0",
26
26
  "typescript": "^5",
27
27
  "@rxdrag/eslint-config-custom": "0.2.12",
28
- "@rxdrag/slate-preview": "1.2.58",
29
- "@rxdrag/tsconfig": "0.2.0"
28
+ "@rxdrag/tsconfig": "0.2.0",
29
+ "@rxdrag/slate-preview": "1.2.58"
30
30
  },
31
31
  "dependencies": {
32
32
  "clsx": "^2.1.0",
@@ -35,8 +35,8 @@
35
35
  "lodash-es": "^4.17.21",
36
36
  "react": "^19.1.0",
37
37
  "react-dom": "^19.1.0",
38
- "@rxdrag/entify-lib": "0.0.20",
39
- "@rxdrag/rxcms-models": "0.3.91"
38
+ "@rxdrag/entify-lib": "0.0.21",
39
+ "@rxdrag/rxcms-models": "0.3.92"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "astro": "^4.0.0 || ^5.0.0"
@@ -1,5 +1,4 @@
1
1
  import { ImageSizes, Media } from "@rxdrag/rxcms-models";
2
- import { ImgHTMLAttributes } from "react";
3
2
 
4
3
  export type FileFieldType =
5
4
  | "thumbnail"
@@ -53,15 +52,13 @@ export const DEFAULT_POST_THUMBNAIL_IMAGE_SIZE: ImageResize = {
53
52
  };
54
53
 
55
54
  //TODO:以后还要加transform参数
56
- export type ImageProps = ImgHTMLAttributes<HTMLImageElement> & {
55
+ export type ImageProps = {
57
56
  className?: string;
58
- mediaId?: string;
57
+ mediaRef?: string;
59
58
  //默认original
60
59
  fileField?: FileFieldType;
61
60
  resize?: ImageResize;
62
61
  children?: React.ReactNode;
63
- //为导出代码方便,如果设置了src,显示的时候可以忽略mediaId等
64
- src?: string;
65
62
  };
66
63
 
67
64
  export const transformMeidaFields = (
@@ -41,6 +41,7 @@ import {
41
41
  import { queryPageBySlug } from "./lib/queryPageBySlug";
42
42
  import { queryPageByType } from "./lib/queryPageByType";
43
43
  import { queryOneMedia } from "./lib/queryOneMedia";
44
+ import { DEFAULT_LARGE, DEFAULT_MEDIUM, DEFAULT_SAMLL, DEFUALT_HEIGHT, DEFUALT_WIDTH, FileFieldType, ImageResize } from "../astro/media";
44
45
 
45
46
  export class Entify implements IEntify {
46
47
  private static instance: Entify | null = null;
@@ -99,8 +100,23 @@ export class Entify implements IEntify {
99
100
  return (await queryLangs(this.envVariables))?.items;
100
101
  }
101
102
 
102
- public async getMedia(ref: string | undefined | null): Promise<Media | undefined> {
103
- return await queryOneMedia(ref, this.envVariables);
103
+ public async getMedia(ref: string | undefined | null, fileField?: FileFieldType, resize?: ImageResize): Promise<Media | undefined> {
104
+ const fields: string[] = []
105
+ switch (fileField) {
106
+ case "resize":
107
+ fields.push(`resize(width: ${resize?.width || DEFUALT_WIDTH}, height: ${resize?.height || DEFUALT_HEIGHT})`)
108
+ break;
109
+ case "small":
110
+ fields.push(`small(width: ${this.imageSizes.small?.width || DEFAULT_SAMLL.width}, height: ${this.imageSizes.small?.height || DEFAULT_SAMLL.height})`)
111
+ break;
112
+ case "medium":
113
+ fields.push(`medium(width: ${this.imageSizes.medium?.width || DEFAULT_MEDIUM.width}, height: ${this.imageSizes.medium?.height || DEFAULT_MEDIUM.height})`)
114
+ break;
115
+ case "large":
116
+ fields.push(`large(width: ${this.imageSizes.large?.width || DEFAULT_LARGE.width}, height: ${this.imageSizes.large?.height || DEFAULT_LARGE.height})`)
117
+ break;
118
+ }
119
+ return await queryOneMedia(ref, fields, this.envVariables);
104
120
  }
105
121
 
106
122
  public async getFeaturedProducts(
@@ -21,6 +21,7 @@ import {
21
21
  WebsitePart,
22
22
  } from "@rxdrag/rxcms-models";
23
23
  import { WebsitePartBoolExp } from "@rxdrag/rxcms-models/";
24
+ import { FileFieldType, ImageResize } from "../astro";
24
25
 
25
26
  export type PostsOptions = {
26
27
  category?: string;
@@ -58,7 +59,7 @@ export interface IEntify {
58
59
 
59
60
  getLangs(): Promise<Lang[] | undefined>;
60
61
 
61
- getMedia(ref: string | undefined | null): Promise<Media | undefined>;
62
+ getMedia(ref: string | undefined | null, fileField?: FileFieldType, resize?: ImageResize): Promise<Media | undefined>;
62
63
 
63
64
  getFeaturedProducts(
64
65
  count?: number,
@@ -1,8 +1,11 @@
1
1
  import { Media, MediaBoolExp, MediaDistinctExp, MediaFields, MediaOrderBy, MediaQueryOptions } from "@rxdrag/rxcms-models";
2
2
  import { EnvVariables } from "../types";
3
3
  import { queryOneEntity } from "./queryOneEntity";
4
+ export const queryOneMedia = async (
5
+ ref: string | undefined | null,
6
+ fields: string[] | undefined,
7
+ envVariables: EnvVariables) => {
4
8
 
5
- export const queryOneMedia = async (ref: string | undefined | null, envVariables: EnvVariables) => {
6
9
  const media = await queryOneEntity<Media, MediaBoolExp, MediaOrderBy, MediaDistinctExp>(
7
10
  new MediaQueryOptions([
8
11
  MediaFields.id,
@@ -16,7 +19,7 @@ export const queryOneMedia = async (ref: string | undefined | null, envVariables
16
19
  }
17
20
  }
18
21
  })
19
- .file(["original", "thumbnail"])
22
+ .file(["original", "thumbnail", ...(fields || [])])
20
23
  .setNoQuery(!ref)
21
24
  ,
22
25
  envVariables