basklee-react 0.9.2 → 0.9.3
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": "basklee-react",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Next.js 16 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,10 +32,16 @@ link, a button or a product placement keep their own action. The helper is
|
|
|
32
32
|
During server rendering, editor HTML is converted to escaped text paragraphs.
|
|
33
33
|
After hydration, DOMPurify replaces those paragraphs with sanitized formatting.
|
|
34
34
|
The allowlist retains headings, text formatting, links, lists, quotes, code,
|
|
35
|
-
tables, images and galleries, audio and video controls,
|
|
35
|
+
tables, images and galleries, audio and video controls, YouTube players,
|
|
36
|
+
collapsible sections,
|
|
36
37
|
alignment and supported text styles. External links open in a new tab with
|
|
37
|
-
`noopener noreferrer`; editor article links use `/journal/<id>`.
|
|
38
|
-
|
|
38
|
+
`noopener noreferrer`; editor article links use `/journal/<id>`. A YouTube
|
|
39
|
+
player from the editor (an `<iframe>` with a `youtube.com` or
|
|
40
|
+
`youtube-nocookie.com` `/embed/<id>` address) is kept and played from
|
|
41
|
+
`youtube-nocookie.com` at the article's width in 16:9, with fixed `allow`,
|
|
42
|
+
`loading="lazy"` and referrer attributes and an optional start second.
|
|
43
|
+
Scripts, other frames, forms, event attributes, unsafe URLs and unsupported
|
|
44
|
+
styles are removed.
|
|
39
45
|
A leading heading that repeats the page title is removed.
|
|
40
46
|
|
|
41
47
|
For an authenticated, accessible non-public article with a positive reading
|
|
@@ -182,6 +182,17 @@
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
.prose :where(img, video, audio):where(:not([data-product-id] *, [data-product-ids] *)) { max-width: 100%; }
|
|
185
|
+
/* A YouTube player from the editor: the article's width, 16:9 (an attribute selector: CSS modules rename classes). */
|
|
186
|
+
.prose iframe[class~='blog-post-editor-youtube']:where(:not([data-product-id] *, [data-product-ids] *)) {
|
|
187
|
+
display: block;
|
|
188
|
+
width: 100%;
|
|
189
|
+
height: auto;
|
|
190
|
+
margin: 1.5rem 0;
|
|
191
|
+
clear: both;
|
|
192
|
+
aspect-ratio: 16 / 9;
|
|
193
|
+
border: 0;
|
|
194
|
+
background: #000;
|
|
195
|
+
}
|
|
185
196
|
.prose img:where(:not([data-product-id] *, [data-product-ids] *)) { height: auto; }
|
|
186
197
|
.prose figure:where(:not([data-product-id] *, [data-product-ids] *)) { max-width: 100%; }
|
|
187
198
|
.prose figure > img:where(:not([data-product-id] *, [data-product-ids] *)) { display: block; margin-inline: auto; }
|
|
@@ -9,6 +9,12 @@ import { APP_ORIGIN, appMediaUrl } from './nativeApp';
|
|
|
9
9
|
|
|
10
10
|
type StylePatterns = Record<string, RegExp>;
|
|
11
11
|
|
|
12
|
+
/*
|
|
13
|
+
* Article HTML comes from the marketplace blog editor and is stored as-is by
|
|
14
|
+
* the backend, so the storefront sanitizes it before display. A frame is kept
|
|
15
|
+
* only when its address is a YouTube embed (see blogYoutubeEmbedSource);
|
|
16
|
+
* every other frame is removed.
|
|
17
|
+
*/
|
|
12
18
|
export const blogArticleTags = [
|
|
13
19
|
'h1',
|
|
14
20
|
'h2',
|
|
@@ -69,6 +75,7 @@ export const blogArticleTags = [
|
|
|
69
75
|
'track',
|
|
70
76
|
'details',
|
|
71
77
|
'summary',
|
|
78
|
+
'iframe',
|
|
72
79
|
];
|
|
73
80
|
|
|
74
81
|
const attributes = [
|
|
@@ -126,6 +133,9 @@ const attributes = [
|
|
|
126
133
|
'data-product-id',
|
|
127
134
|
'data-product-ids',
|
|
128
135
|
'data-product-hidden-badges',
|
|
136
|
+
'allow',
|
|
137
|
+
'allowfullscreen',
|
|
138
|
+
'referrerpolicy',
|
|
129
139
|
];
|
|
130
140
|
|
|
131
141
|
const marginLength = '(-?\\d+(\\.\\d+)?(px|em|rem|%)?|auto)';
|
|
@@ -135,6 +145,7 @@ const editorClasses = new Set([
|
|
|
135
145
|
'blog-code-block',
|
|
136
146
|
'blog-post-editor-image',
|
|
137
147
|
'blog-post-editor-video',
|
|
148
|
+
'blog-post-editor-youtube',
|
|
138
149
|
]);
|
|
139
150
|
|
|
140
151
|
export const blogArticleColorTokens = new Set([
|
|
@@ -174,6 +185,53 @@ const editorArticlePath =
|
|
|
174
185
|
/^\/(?:[a-z]{2}(?:-[a-z]{2})?\/)?blog\/[^/?#]+\/([1-9]\d*)\/?$/i;
|
|
175
186
|
const authorRelTokens = new Set(['nofollow', 'sponsored', 'ugc']);
|
|
176
187
|
|
|
188
|
+
// A YouTube player the editor inserts: youtube.com or youtube-nocookie.com,
|
|
189
|
+
// /embed/ and an 11-character video ID, optionally a start second.
|
|
190
|
+
const youtubeEmbed =
|
|
191
|
+
/^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/([\w-]{11})(?:\?([^#]*))?$/i;
|
|
192
|
+
|
|
193
|
+
export const blogYoutubeAllow =
|
|
194
|
+
'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The privacy-enhanced player address for a YouTube embed address, or an
|
|
198
|
+
* empty string for anything else (other sites, other YouTube pages).
|
|
199
|
+
*/
|
|
200
|
+
export function blogYoutubeEmbedSource(value: string) {
|
|
201
|
+
const match = youtubeEmbed.exec(value.trim());
|
|
202
|
+
|
|
203
|
+
if (!match) {
|
|
204
|
+
return '';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const start = /(?:^|&)start=(\d{1,6})(?:&|$)/.exec(match[2] ?? '')?.[1];
|
|
208
|
+
|
|
209
|
+
return `https://www.youtube-nocookie.com/embed/${match[1]}${start && Number(start) > 0 ? `?start=${Number(start)}` : ''}`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function prepareYoutubeFrame(node: Element) {
|
|
213
|
+
const source = blogYoutubeEmbedSource(node.getAttribute('src') ?? '');
|
|
214
|
+
|
|
215
|
+
if (!source) {
|
|
216
|
+
node.remove();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const title = node.getAttribute('title')?.trim() || 'YouTube video';
|
|
221
|
+
|
|
222
|
+
for (const attribute of [...node.getAttributeNames()]) {
|
|
223
|
+
node.removeAttribute(attribute);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
node.setAttribute('class', 'blog-post-editor-youtube');
|
|
227
|
+
node.setAttribute('src', source);
|
|
228
|
+
node.setAttribute('title', title);
|
|
229
|
+
node.setAttribute('allow', blogYoutubeAllow);
|
|
230
|
+
node.setAttribute('allowfullscreen', '');
|
|
231
|
+
node.setAttribute('loading', 'lazy');
|
|
232
|
+
node.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
233
|
+
}
|
|
234
|
+
|
|
177
235
|
function normalizedHeadingText(value: string) {
|
|
178
236
|
return htmlTextParagraphs(value)
|
|
179
237
|
.join(' ')
|
|
@@ -292,6 +350,11 @@ function prepareLink(link: Element) {
|
|
|
292
350
|
function prepareElement(node: Element) {
|
|
293
351
|
const name = node.nodeName;
|
|
294
352
|
|
|
353
|
+
if (name === 'IFRAME') {
|
|
354
|
+
prepareYoutubeFrame(node);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
295
358
|
if (name === 'A') {
|
|
296
359
|
prepareLink(node);
|
|
297
360
|
}
|