@c-rex/components 0.1.21 → 0.1.23
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 +78 -62
- package/src/article/article-action-bar.tsx +89 -0
- package/src/article/article-content.tsx +55 -0
- package/src/autocomplete.tsx +55 -50
- package/src/breadcrumb.tsx +3 -1
- package/src/directoryNodes/tree-of-content.tsx +49 -0
- package/src/{bookmark-button.tsx → favorites/bookmark-button.tsx} +12 -3
- package/src/{favorite-button.tsx → favorites/favorite-button.tsx} +1 -1
- package/src/generated/client-components.tsx +1350 -0
- package/src/generated/create-client-request.tsx +105 -0
- package/src/generated/create-server-request.tsx +61 -0
- package/src/generated/create-suggestions-request.tsx +56 -0
- package/src/generated/server-components.tsx +1056 -0
- package/src/generated/suggestions.tsx +299 -0
- package/src/info/bookmark.tsx +51 -0
- package/src/info/info-table.tsx +127 -60
- package/src/info/shared.tsx +1 -1
- package/src/navbar/language-switcher/shared.tsx +1 -1
- package/src/navbar/navbar.tsx +1 -1
- package/src/{stories → navbar/stories}/navbar.stories.tsx +1 -1
- package/src/page-wrapper.tsx +1 -1
- package/src/renditions/file-download.tsx +84 -0
- package/src/renditions/html.tsx +55 -0
- package/src/renditions/image/container.tsx +52 -0
- package/src/renditions/image/rendition.tsx +61 -0
- package/src/{dialog-filter.tsx → results/dialog-filter.tsx} +22 -23
- package/src/results/filter-navbar.tsx +241 -0
- package/src/results/filter-sidebar/index.tsx +125 -0
- package/src/results/filter-sidebar/utils.ts +164 -0
- package/src/{pagination.tsx → results/pagination.tsx} +12 -10
- package/src/results/result-container.tsx +70 -0
- package/src/{stories/blog-view.stories.tsx → results/stories/cards.stories.tsx} +1 -1
- package/src/{stories/table-view.stories.tsx → results/stories/table.stories.tsx} +1 -1
- package/src/results/table-with-images.tsx +140 -0
- package/src/{result-view → results}/table.tsx +1 -2
- package/src/results/utils.ts +67 -0
- package/src/{navbar/search-input.tsx → search-input.tsx} +9 -6
- package/src/share-button.tsx +49 -0
- package/src/stores/search-settings-store.ts +1 -1
- package/src/blur-image.tsx +0 -23
- package/src/left-sidebar.tsx +0 -90
- package/src/result-list.tsx +0 -43
- package/src/result-view/table-with-images.tsx +0 -199
- package/src/right-sidebar.tsx +0 -70
- package/src/search-modal.tsx +0 -140
- package/src/stories/blur-image.stories.tsx +0 -51
- package/src/stories/sidebar.stories.tsx +0 -94
- /package/src/{file-icon.tsx → icons/file-icon.tsx} +0 -0
- /package/src/{flag.tsx → icons/flag-icon.tsx} +0 -0
- /package/src/{loading.tsx → icons/loading.tsx} +0 -0
- /package/src/{result-view/blog.tsx → results/cards.tsx} +0 -0
- /package/src/{empty.tsx → results/empty.tsx} +0 -0
- /package/src/{stories → results/stories}/empty.stories.tsx +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-generated from OpenAPI spec (Client-Side)
|
|
3
|
+
* Source: https://staging.c-rex.net/ids/api/swagger/v1/swagger.json
|
|
4
|
+
* Generated: 2025-12-11T16:23:03.635Z
|
|
5
|
+
* Do not edit manually
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
"use client";
|
|
9
|
+
|
|
10
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
11
|
+
import { replacePathParams, call } from "@c-rex/utils"
|
|
12
|
+
|
|
13
|
+
type SerializedError = {
|
|
14
|
+
message: string;
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type DataRequestRenderProps<T> = {
|
|
19
|
+
data: T | null;
|
|
20
|
+
error: SerializedError | null;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type FetchState<T> = {
|
|
25
|
+
data: T | null;
|
|
26
|
+
error: Error | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function createClientDataRequest<T, PathParams, QueryParams>(
|
|
30
|
+
endpointTemplate: string
|
|
31
|
+
) {
|
|
32
|
+
return function DataRequest(
|
|
33
|
+
pathParams?: PathParams,
|
|
34
|
+
queryParams?: QueryParams,
|
|
35
|
+
) {
|
|
36
|
+
|
|
37
|
+
const [state, setState] = useState<DataRequestRenderProps<T>>({
|
|
38
|
+
data: null,
|
|
39
|
+
error: null,
|
|
40
|
+
isLoading: false,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const fetchData = useCallback(async () => {
|
|
44
|
+
setState({
|
|
45
|
+
...state,
|
|
46
|
+
isLoading: !state.data,
|
|
47
|
+
error: null,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const url = replacePathParams(endpointTemplate, pathParams as Record<string, string>);
|
|
52
|
+
const data = await call<T>("CrexApi.execute", {
|
|
53
|
+
url,
|
|
54
|
+
method: "get",
|
|
55
|
+
params: queryParams as Record<string, string | number | boolean | (string | number | boolean)[] | undefined>,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
setState({
|
|
59
|
+
data,
|
|
60
|
+
error: null,
|
|
61
|
+
isLoading: false,
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
setState({
|
|
65
|
+
data: null,
|
|
66
|
+
error: error instanceof Error ? error : new Error('Unknown error'),
|
|
67
|
+
isLoading: false,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
+
}, [endpointTemplate, pathParams]);
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// Initial fetch
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
fetchData();
|
|
77
|
+
}, [fetchData]);
|
|
78
|
+
|
|
79
|
+
return state;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type ClientDataRequestProps<T, PathParams, QueryParams> = {
|
|
84
|
+
pathParams?: PathParams;
|
|
85
|
+
queryParams?: QueryParams;
|
|
86
|
+
children: (result: DataRequestRenderProps<T>) => React.ReactNode;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Create a render-prop component for client-side data fetching
|
|
91
|
+
*/
|
|
92
|
+
export function createClientDataRequestComponent<T, PathParams, QueryParams>(
|
|
93
|
+
endpointTemplate: string
|
|
94
|
+
) {
|
|
95
|
+
const useDataRequest = createClientDataRequest<T, PathParams, QueryParams>(endpointTemplate);
|
|
96
|
+
|
|
97
|
+
return function ClientDataRequest({
|
|
98
|
+
pathParams,
|
|
99
|
+
queryParams,
|
|
100
|
+
children,
|
|
101
|
+
}: ClientDataRequestProps<T, PathParams, QueryParams>) {
|
|
102
|
+
const result = useDataRequest(pathParams, queryParams);
|
|
103
|
+
return <>{children(result)}</>;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CrexApi } from '@c-rex/core/requests';
|
|
2
|
+
import { OPERATOR_OPTIONS, WILD_CARD_OPTIONS } from '@c-rex/constants';
|
|
3
|
+
|
|
4
|
+
type SerializedError = {
|
|
5
|
+
message: string;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type DataRequestRenderProps<T> = {
|
|
10
|
+
data: T;
|
|
11
|
+
error?: SerializedError;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type DataRequestProps<T, PathParams, QueryParams> = {
|
|
15
|
+
pathParams?: PathParams;
|
|
16
|
+
queryParams?: QueryParams;
|
|
17
|
+
render: (data: T, error?: SerializedError) => React.ReactNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export function createDataRequestWithParams<T, PathParams, QueryParams>(
|
|
22
|
+
endpointTemplate: string
|
|
23
|
+
) {
|
|
24
|
+
return async function DataRequest({
|
|
25
|
+
pathParams,
|
|
26
|
+
queryParams = {} as QueryParams,
|
|
27
|
+
render,
|
|
28
|
+
}: DataRequestProps<T, PathParams, QueryParams>) {
|
|
29
|
+
let endpoint = endpointTemplate;
|
|
30
|
+
if (pathParams) {
|
|
31
|
+
endpoint = Object.entries(pathParams as Record<string, string>).reduce(
|
|
32
|
+
(url, [key, value]) => url.replace(`{${key}}`, encodeURIComponent(value)),
|
|
33
|
+
endpointTemplate
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const params = {
|
|
38
|
+
PageNumber: 1,
|
|
39
|
+
PageSize: 12,
|
|
40
|
+
Wildcard: WILD_CARD_OPTIONS.BOTH,
|
|
41
|
+
QueryOperator: OPERATOR_OPTIONS.OR,
|
|
42
|
+
...queryParams,
|
|
43
|
+
} as Record<string, string | number | boolean | (string | number | boolean)[] | undefined>;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const api = new CrexApi();
|
|
47
|
+
const data = await api.execute<T>({
|
|
48
|
+
url: endpoint,
|
|
49
|
+
method: 'GET',
|
|
50
|
+
params,
|
|
51
|
+
});
|
|
52
|
+
return render(data);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const serializedError: SerializedError = {
|
|
55
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
56
|
+
name: error instanceof Error ? error.name : 'Error',
|
|
57
|
+
};
|
|
58
|
+
return render({} as T, serializedError);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { AutocompleteSuggestion, SuggestionQueryParams } from '@c-rex/interfaces';
|
|
4
|
+
import { call } from '@c-rex/utils';
|
|
5
|
+
|
|
6
|
+
type SerializedError = {
|
|
7
|
+
message: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type SuggestionRequestProps = {
|
|
12
|
+
prefix: string;
|
|
13
|
+
queryParams?: SuggestionQueryParams;
|
|
14
|
+
endpoint: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const suggestionRequest = async ({
|
|
18
|
+
endpoint,
|
|
19
|
+
prefix,
|
|
20
|
+
queryParams = {}
|
|
21
|
+
}: SuggestionRequestProps): Promise<{ data: string[], error?: SerializedError }> => {
|
|
22
|
+
try {
|
|
23
|
+
const data = await call<AutocompleteSuggestion>("CrexApi.execute", {
|
|
24
|
+
url: endpoint,
|
|
25
|
+
method: "get",
|
|
26
|
+
params: {
|
|
27
|
+
Prefix: prefix,
|
|
28
|
+
...queryParams
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const suggestions: string[] = [];
|
|
33
|
+
const comparableList: string[] = [];
|
|
34
|
+
|
|
35
|
+
if (data.suggestions) {
|
|
36
|
+
data.suggestions.forEach((item) => {
|
|
37
|
+
suggestions.push(item.value);
|
|
38
|
+
comparableList.push(item.value.toLowerCase());
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Add query to beginning if not already in suggestions
|
|
43
|
+
if (!comparableList.includes(prefix.toLowerCase())) {
|
|
44
|
+
return { data: [prefix, ...suggestions] };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { data: suggestions };
|
|
48
|
+
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const serializedError: SerializedError = {
|
|
51
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
52
|
+
name: error instanceof Error ? error.name : 'Error',
|
|
53
|
+
};
|
|
54
|
+
return { data: [], error: serializedError };
|
|
55
|
+
}
|
|
56
|
+
};
|