@pronto-tools-and-more/components 6.26.2 → 6.27.0
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/main.js +108 -15
- package/dist/parts/CreateFakeSection/CreateFakeSection.d.ts +4 -0
- package/dist/parts/FakeNode/FakeNode.d.ts +5 -0
- package/dist/parts/HasComplexChildren/HasComplexChildren.d.ts +1 -0
- package/dist/parts/ISearchResult/ISearchResult.d.ts +7 -0
- package/dist/parts/ISearchResultComponent/ISearchResultComponent.d.ts +7 -0
- package/dist/parts/SearchResults/SearchResults.d.ts +4 -1
- package/dist/parts/UnwrapComponent/UnwrapComponent.d.ts +7 -0
- package/package.json +1 -1
- package/src/parts/CreateFakeSection/CreateFakeSection.ts +8 -0
- package/src/parts/FakeNode/FakeNode.ts +6 -0
- package/src/parts/HasComplexChildren/HasComplexChildren.ts +7 -0
- package/src/parts/ISearchResult/ISearchResult.tsx +7 -0
- package/src/parts/ISearchResultComponent/ISearchResultComponent.tsx +6 -0
- package/src/parts/SearchResults/SearchResults.tsx +19 -15
- package/src/parts/UnwrapComponent/UnwrapComponent.tsx +98 -0
package/dist/main.js
CHANGED
@@ -119,23 +119,116 @@ var SearchLink = ({ message } = {}) => {
|
|
119
119
|
return /* @__PURE__ */ React.createElement("div", { className: "SearchLink" }, /* @__PURE__ */ React.createElement(JsonComponent, { json }));
|
120
120
|
};
|
121
121
|
|
122
|
+
// src/parts/HasComplexChildren/HasComplexChildren.ts
|
123
|
+
var isComplex = (child) => {
|
124
|
+
return typeof child !== "string";
|
125
|
+
};
|
126
|
+
var hasComplexChildren = (children) => {
|
127
|
+
return children.some(isComplex);
|
128
|
+
};
|
129
|
+
|
130
|
+
// src/parts/FakeNode/FakeNode.ts
|
131
|
+
var fakeNode = {
|
132
|
+
type: "html",
|
133
|
+
tag: "div",
|
134
|
+
content: '<img src="x" onerror="globalThis.fixRender(this)" />'
|
135
|
+
};
|
136
|
+
|
137
|
+
// src/parts/CreateFakeSection/CreateFakeSection.ts
|
138
|
+
var createFakeSection = (children) => {
|
139
|
+
return {
|
140
|
+
type: "section",
|
141
|
+
content: [fakeNode, ...children]
|
142
|
+
};
|
143
|
+
};
|
144
|
+
|
145
|
+
// src/parts/UnwrapComponent/UnwrapComponent.tsx
|
146
|
+
var getComponentChildren = (element, componentProps) => {
|
147
|
+
if (componentProps && componentProps.children) {
|
148
|
+
if (typeof componentProps.children === "string") {
|
149
|
+
return [componentProps.children];
|
150
|
+
}
|
151
|
+
return componentProps.children;
|
152
|
+
}
|
153
|
+
if (element && element.children) {
|
154
|
+
if (typeof element.children === "string") {
|
155
|
+
return [element.children];
|
156
|
+
}
|
157
|
+
return element.children;
|
158
|
+
}
|
159
|
+
return [];
|
160
|
+
};
|
161
|
+
var getComponentProperties = (element) => {
|
162
|
+
const componentType = element.type;
|
163
|
+
const componentProps = element.props;
|
164
|
+
const componentChildren = getComponentChildren(element, componentProps);
|
165
|
+
return {
|
166
|
+
componentType,
|
167
|
+
componentProps,
|
168
|
+
componentChildren
|
169
|
+
};
|
170
|
+
};
|
171
|
+
var unwrapComponent = (element) => {
|
172
|
+
if (!element) {
|
173
|
+
return {
|
174
|
+
type: "html",
|
175
|
+
tag: "div",
|
176
|
+
content: `Unknown component`
|
177
|
+
};
|
178
|
+
}
|
179
|
+
if (typeof element === "string" || typeof element === "number" || typeof element === "boolean") {
|
180
|
+
return {
|
181
|
+
type: "html",
|
182
|
+
tag: "div",
|
183
|
+
content: `${element}`
|
184
|
+
};
|
185
|
+
}
|
186
|
+
const { componentChildren, componentProps, componentType } = getComponentProperties(element);
|
187
|
+
if (typeof componentType === "function") {
|
188
|
+
const vnode = componentType({
|
189
|
+
...componentProps
|
190
|
+
});
|
191
|
+
const rendered = unwrapComponent(vnode);
|
192
|
+
return rendered;
|
193
|
+
}
|
194
|
+
if (typeof componentType === "string") {
|
195
|
+
const hasComplexChildren2 = hasComplexChildren(componentChildren);
|
196
|
+
const renderedChildren = hasComplexChildren2 ? componentChildren.map(unwrapComponent) : [];
|
197
|
+
const content = hasComplexChildren2 ? "" : componentChildren[0] || "";
|
198
|
+
const props = componentProps ? componentProps : {};
|
199
|
+
return createFakeSection([
|
200
|
+
{
|
201
|
+
type: "html",
|
202
|
+
tag: componentType,
|
203
|
+
content
|
204
|
+
},
|
205
|
+
...renderedChildren
|
206
|
+
]);
|
207
|
+
}
|
208
|
+
if (componentType) {
|
209
|
+
return {
|
210
|
+
type: "TODO"
|
211
|
+
};
|
212
|
+
}
|
213
|
+
return {};
|
214
|
+
};
|
215
|
+
|
122
216
|
// src/parts/SearchResults/SearchResults.tsx
|
123
|
-
var SearchResults = (
|
217
|
+
var SearchResults = ({
|
218
|
+
SearchResult
|
219
|
+
}) => {
|
220
|
+
const searchResult = {
|
221
|
+
description: "abc",
|
222
|
+
label: "abc",
|
223
|
+
readtime: "",
|
224
|
+
title: "$context.title",
|
225
|
+
imageSrc: ""
|
226
|
+
};
|
227
|
+
const unwrapped = unwrapComponent(
|
228
|
+
/* @__PURE__ */ React.createElement(SearchResult, { item: searchResult })
|
229
|
+
);
|
124
230
|
const json = {
|
125
|
-
content:
|
126
|
-
type: "search-result",
|
127
|
-
pageHitExcerptMessage: "test",
|
128
|
-
coverHeight: "FIXED",
|
129
|
-
tapPageHit: {
|
130
|
-
type: "openContent"
|
131
|
-
},
|
132
|
-
tapCover: {
|
133
|
-
type: "openContent"
|
134
|
-
},
|
135
|
-
class: "issue-card issue-card--overline-in-page-hit-excerpt-message",
|
136
|
-
template: "feed",
|
137
|
-
renderProperties: ["authors"]
|
138
|
-
},
|
231
|
+
content: unwrapped,
|
139
232
|
dataSource: {
|
140
233
|
phrase: "$context.phrase",
|
141
234
|
type: "search-result",
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const hasComplexChildren: (children: any) => any;
|
@@ -1 +1,4 @@
|
|
1
|
-
|
1
|
+
import type { ISearchResultComponent } from "../ISearchResultComponent/ISearchResultComponent.tsx";
|
2
|
+
export declare const SearchResults: ({ SearchResult, }: {
|
3
|
+
SearchResult: ISearchResultComponent;
|
4
|
+
}) => import("react").JSX.Element;
|
package/package.json
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
+
import { ISearchResult } from "../ISearchResult/ISearchResult.tsx";
|
2
|
+
import type { ISearchResultComponent } from "../ISearchResultComponent/ISearchResultComponent.tsx";
|
1
3
|
import { JsonComponent } from "../JsonComponent/JsonComponent.tsx";
|
4
|
+
import * as UnwrapComponent from "../UnwrapComponent/UnwrapComponent.tsx";
|
2
5
|
|
3
|
-
export const SearchResults = (
|
6
|
+
export const SearchResults = ({
|
7
|
+
SearchResult,
|
8
|
+
}: {
|
9
|
+
SearchResult: ISearchResultComponent;
|
10
|
+
}) => {
|
11
|
+
const searchResult: ISearchResult = {
|
12
|
+
description: "abc",
|
13
|
+
label: "abc",
|
14
|
+
readtime: "",
|
15
|
+
title: "$context.title",
|
16
|
+
imageSrc: "",
|
17
|
+
};
|
18
|
+
const unwrapped = UnwrapComponent.unwrapComponent(
|
19
|
+
<SearchResult item={searchResult} />
|
20
|
+
);
|
4
21
|
const json = {
|
5
|
-
content:
|
6
|
-
type: "search-result",
|
7
|
-
pageHitExcerptMessage: "test",
|
8
|
-
coverHeight: "FIXED",
|
9
|
-
tapPageHit: {
|
10
|
-
type: "openContent",
|
11
|
-
},
|
12
|
-
tapCover: {
|
13
|
-
type: "openContent",
|
14
|
-
},
|
15
|
-
class: "issue-card issue-card--overline-in-page-hit-excerpt-message",
|
16
|
-
template: "feed",
|
17
|
-
renderProperties: ["authors"],
|
18
|
-
},
|
22
|
+
content: unwrapped,
|
19
23
|
dataSource: {
|
20
24
|
phrase: "$context.phrase",
|
21
25
|
type: "search-result",
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import type React from "react";
|
2
|
+
import * as HasComplexChildren from "../HasComplexChildren/HasComplexChildren.ts";
|
3
|
+
import * as CreateFakeSection from "../CreateFakeSection/CreateFakeSection.ts";
|
4
|
+
|
5
|
+
export const createElement = (tag, props, ...children) => {
|
6
|
+
return {
|
7
|
+
tag,
|
8
|
+
props,
|
9
|
+
children,
|
10
|
+
};
|
11
|
+
};
|
12
|
+
|
13
|
+
const getComponentChildren = (element: any, componentProps: any) => {
|
14
|
+
if (componentProps && componentProps.children) {
|
15
|
+
if (typeof componentProps.children === "string") {
|
16
|
+
return [componentProps.children];
|
17
|
+
}
|
18
|
+
return componentProps.children;
|
19
|
+
}
|
20
|
+
if (element && element.children) {
|
21
|
+
if (typeof element.children === "string") {
|
22
|
+
return [element.children];
|
23
|
+
}
|
24
|
+
return element.children;
|
25
|
+
}
|
26
|
+
return [];
|
27
|
+
};
|
28
|
+
|
29
|
+
const getComponentProperties = (element: any) => {
|
30
|
+
// @ts-ignore
|
31
|
+
const componentType = element.type;
|
32
|
+
// @ts-ignore
|
33
|
+
const componentProps = element.props;
|
34
|
+
//@ts-ignore
|
35
|
+
const componentChildren = getComponentChildren(element, componentProps);
|
36
|
+
return {
|
37
|
+
componentType,
|
38
|
+
componentProps,
|
39
|
+
componentChildren,
|
40
|
+
};
|
41
|
+
};
|
42
|
+
|
43
|
+
export const unwrapComponent = (element: React.ReactNode) => {
|
44
|
+
if (!element) {
|
45
|
+
return {
|
46
|
+
type: "html",
|
47
|
+
tag: "div",
|
48
|
+
content: `Unknown component`,
|
49
|
+
};
|
50
|
+
}
|
51
|
+
if (
|
52
|
+
typeof element === "string" ||
|
53
|
+
typeof element === "number" ||
|
54
|
+
typeof element === "boolean"
|
55
|
+
) {
|
56
|
+
return {
|
57
|
+
type: "html",
|
58
|
+
tag: "div",
|
59
|
+
content: `${element}`,
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
const { componentChildren, componentProps, componentType } =
|
64
|
+
getComponentProperties(element);
|
65
|
+
|
66
|
+
if (typeof componentType === "function") {
|
67
|
+
const vnode = componentType({
|
68
|
+
...componentProps,
|
69
|
+
});
|
70
|
+
const rendered = unwrapComponent(vnode);
|
71
|
+
return rendered;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (typeof componentType === "string") {
|
75
|
+
const hasComplexChildren =
|
76
|
+
HasComplexChildren.hasComplexChildren(componentChildren);
|
77
|
+
const renderedChildren = hasComplexChildren
|
78
|
+
? componentChildren.map(unwrapComponent)
|
79
|
+
: [];
|
80
|
+
const content = hasComplexChildren ? "" : componentChildren[0] || "";
|
81
|
+
const props = componentProps ? componentProps : {};
|
82
|
+
|
83
|
+
return CreateFakeSection.createFakeSection([
|
84
|
+
{
|
85
|
+
type: "html",
|
86
|
+
tag: componentType,
|
87
|
+
content,
|
88
|
+
},
|
89
|
+
...renderedChildren,
|
90
|
+
]);
|
91
|
+
}
|
92
|
+
if (componentType) {
|
93
|
+
return {
|
94
|
+
type: "TODO",
|
95
|
+
};
|
96
|
+
}
|
97
|
+
return {};
|
98
|
+
};
|