@phis/ui 0.4.21 → 0.4.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/components/cms/phi-cms-layout-renderer.js +1 -1
- package/components/controls/phi-brand-control.d.ts +10 -2
- package/components/controls/phi-brand-control.js +12 -8
- package/components/controls/phi-cascader-control.js +6 -1
- package/components/controls/phi-geometry-control.d.ts +33 -1
- package/components/controls/phi-geometry-control.js +87 -29
- package/components/controls/phi-series-chart-control.js +4 -2
- package/components/forms/form-provider-contract.d.ts +1 -0
- package/components/forms/form-provider-contract.js +1 -0
- package/components/forms/upload-form-control.js +1 -0
- package/components/layouts/clients/phi-flex-layout-client.js +23 -5
- package/components/layouts/clients/phi-grid-layout-client.js +20 -10
- package/components/layouts/clients/phi-layout-anchored-overlay.d.ts +2 -0
- package/components/layouts/clients/phi-layout-anchored-overlay.js +9 -2
- package/components/layouts/clients/phi-three-column-layout-client.js +7 -4
- package/components/layouts/layout-definitions.d.ts +16 -16
- package/components/layouts/layout-definitions.js +8 -8
- package/components/layouts/phi-base-layout.js +13 -9
- package/components/layouts/phi-layout-contract.d.ts +12 -2
- package/components/layouts/phi-layout-contract.js +30 -7
- package/components/layouts/phi-masonry-layout.d.ts +6 -0
- package/components/layouts/phi-masonry-layout.js +13 -3
- package/components/layouts/plugins/masonry-layout-plugin.js +2 -1
- package/components/media/asset-collection-runtime.d.ts +1 -6
- package/components/media/asset-collection-runtime.js +2 -93
- package/components/media/label-sets/media.js +12 -0
- package/components/media/media-folder-lock.d.ts +19 -0
- package/components/media/media-folder-lock.js +40 -0
- package/components/media/media-folder-options.d.ts +14 -2
- package/components/media/media-folder-options.js +17 -5
- package/components/media/media-widget-labels.d.ts +9 -0
- package/components/media/media-widget-labels.js +6 -0
- package/components/media/phi-area-upload-widget.js +1 -0
- package/components/media/phi-asset-folder-control.d.ts +14 -1
- package/components/media/phi-asset-folder-control.js +11 -4
- package/components/media/phi-image-preview-store.d.ts +0 -4
- package/components/media/phi-image-preview-store.js +0 -10
- package/components/media/phi-media-picker-binding.d.ts +7 -2
- package/components/media/phi-media-upload.d.ts +2 -0
- package/components/media/phi-media-upload.js +3 -0
- package/components/regions/clients/cms-region-container-client.d.ts +3 -1
- package/components/regions/clients/cms-region-container-client.js +4 -3
- package/components/regions/phi-cms-region-container.d.ts +3 -1
- package/components/regions/phi-cms-region-container.js +3 -2
- package/components/regions/phi-cms-region-shell.d.ts +9 -1
- package/components/regions/phi-cms-region-shell.js +3 -1
- package/components/regions/phi-cms-region-static.d.ts +3 -1
- package/components/regions/phi-cms-region-static.js +3 -2
- package/components/regions/presets/navigation-redirect.d.ts +2 -2
- package/components/regions/presets/navigation-redirect.js +5 -3
- package/components/shell/phi-antd-icon.d.ts +2 -0
- package/components/shell/phi-antd-icon.js +6 -0
- package/components/widgets/label-sets/geometry.js +10 -0
- package/components/widgets/label-types/geometry.d.ts +7 -0
- package/components/widgets/label-types/geometry.js +6 -0
- package/components/widgets/shared/markdown-render.js +30 -135
- package/components/widgets/shared/markdown-translation-unit.d.ts +62 -0
- package/components/widgets/shared/markdown-translation-unit.js +211 -0
- package/helpers/block-geometry-profiles.d.ts +67 -0
- package/helpers/block-geometry-profiles.js +105 -0
- package/helpers/cms-navigation-catalog.js +4 -2
- package/helpers/renderable-block-effects.js +16 -0
- package/package.json +1 -1
- package/plugins/runtime/phi-slot-child-frame-view.js +14 -4
- package/plugins/runtime/phi-slot-child-viewport-effects-observer.js +42 -2
- package/plugins/runtime/slot-size-policy.d.ts +15 -0
- package/plugins/runtime/slot-size-policy.js +29 -0
- package/plugins/runtime-modules/asset/data-providers.js +3 -0
- package/plugins/runtime-modules/asset/services/collection.js +34 -0
- package/plugins/runtime-modules/asset/services/options.js +19 -2
- package/plugins/runtime-modules/asset/trees/phi-default-builder-media-page-tree.js +9 -0
- package/plugins/runtime-modules/auth/trees/phi-auth-runtime-page-tree.js +21 -17
- package/plugins/runtime-modules/avatar/widgets/account-avatar-picker/client.js +2 -0
- package/plugins/runtime-modules/builder/clients/region-inspector.js +1 -1
- package/plugins/runtime-modules/builder/render-root-node-preview.server.js +2 -1
- package/plugins/runtime-modules/builder/services/navigation-table.js +3 -2
- package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +7 -1
- package/plugins/runtime-modules/builder/widgets/structure-region/built-in.js +8 -2
- package/plugins/runtime-modules/core/messaging/data-providers.js +23 -0
- package/plugins/runtime-modules/core/messaging/labels.d.ts +2 -0
- package/plugins/runtime-modules/core/messaging/labels.js +8 -0
- package/plugins/runtime-modules/core/messaging/thread-inbox-table.d.ts +32 -0
- package/plugins/runtime-modules/core/messaging/thread-inbox-table.js +31 -16
- package/plugins/runtime-modules/core/widgets/brand/client.d.ts +3 -1
- package/plugins/runtime-modules/core/widgets/brand/client.js +2 -1
- package/plugins/runtime-modules/core/widgets/brand/plugin.js +23 -2
- package/plugins/runtime-modules/core/widgets/brand/server.d.ts +2 -2
- package/plugins/runtime-modules/core/widgets/brand/server.js +2 -1
- package/plugins/runtime-modules/core/widgets/card/server.js +7 -4
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +52 -6
- package/plugins/runtime-modules/core/widgets/gallery/plugin.js +3 -1
- package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +3 -1
- package/plugins/runtime-modules/core/widgets/gallery/server.js +12 -2
- package/plugins/runtime-modules/core/widgets/image/server.js +28 -5
- package/plugins/runtime-modules/core/widgets/thread-conversation/client.d.ts +3 -0
- package/plugins/runtime-modules/core/widgets/thread-conversation/client.js +8 -2
- package/plugins/runtime-modules/descriptor-compiler.js +45 -2
- package/plugins/runtime-modules/public/trees/phi-default-pub-welcome-page-tree.js +8 -14
- package/plugins/runtime-modules/search/widgets/search-box/client.d.ts +2 -1
- package/plugins/runtime-modules/search/widgets/search-box/client.js +28 -6
- package/plugins/runtime-modules/theme/widgets/brand-controls/client.js +19 -2
- package/plugins/runtime-modules/threads/labels.d.ts +6 -0
- package/plugins/runtime-modules/threads/labels.js +16 -0
- package/plugins/runtime-modules/threads/trees/phi-default-threads-page-tree.js +24 -1
- package/styles/layout.css +101 -0
- package/styles/root.css +2 -1
- package/types/cms-config.d.ts +5 -1
- package/types/cms-config.js +1 -0
- package/types/cms-module-descriptors.d.ts +17 -0
- package/types/renderable-block.d.ts +5 -0
- package/types/site-theme.d.ts +9 -1
- package/types.d.ts +1 -1
|
@@ -20,6 +20,10 @@ const PHI_GEOMETRY_WIDGET_LABEL_SET = definePhiLabelSet({
|
|
|
20
20
|
field_max_size: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.fields.maxSize,
|
|
21
21
|
field_z_index: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.fields.zIndex,
|
|
22
22
|
field_viewport: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.fields.viewport,
|
|
23
|
+
field_profile: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.fields.profile,
|
|
24
|
+
profile_compact: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.profiles.compact,
|
|
25
|
+
profile_medium: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.profiles.medium,
|
|
26
|
+
profile_wide: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.profiles.wide,
|
|
23
27
|
viewport_compact: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.viewport.compact,
|
|
24
28
|
viewport_medium: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.viewport.medium,
|
|
25
29
|
viewport_wide: PHI_GEOMETRY_WIDGET_DEFAULT_LABELS.viewport.wide,
|
|
@@ -46,6 +50,12 @@ export async function getPhiGeometryWidgetLabels(options) {
|
|
|
46
50
|
maxSize: labels.field_max_size,
|
|
47
51
|
zIndex: labels.field_z_index,
|
|
48
52
|
viewport: labels.field_viewport,
|
|
53
|
+
profile: labels.field_profile,
|
|
54
|
+
},
|
|
55
|
+
profiles: {
|
|
56
|
+
compact: labels.profile_compact,
|
|
57
|
+
medium: labels.profile_medium,
|
|
58
|
+
wide: labels.profile_wide,
|
|
49
59
|
},
|
|
50
60
|
viewport: {
|
|
51
61
|
compact: labels.viewport_compact,
|
|
@@ -16,6 +16,13 @@ export type PhiGeometryWidgetLabels = {
|
|
|
16
16
|
maxSize: string;
|
|
17
17
|
zIndex: string;
|
|
18
18
|
viewport: string;
|
|
19
|
+
profile: string;
|
|
20
|
+
};
|
|
21
|
+
/** The rooms a size may name a value for, narrow first (design/RESPONSIVE_BLOCK_GEOMETRY.md). */
|
|
22
|
+
profiles: {
|
|
23
|
+
compact: string;
|
|
24
|
+
medium: string;
|
|
25
|
+
wide: string;
|
|
19
26
|
};
|
|
20
27
|
viewport: {
|
|
21
28
|
compact: string;
|
|
@@ -16,6 +16,12 @@ export const PHI_GEOMETRY_WIDGET_DEFAULT_LABELS = {
|
|
|
16
16
|
maxSize: "Max size",
|
|
17
17
|
zIndex: "z-index",
|
|
18
18
|
viewport: "Viewport",
|
|
19
|
+
profile: "Room",
|
|
20
|
+
},
|
|
21
|
+
profiles: {
|
|
22
|
+
compact: "< 377",
|
|
23
|
+
medium: "≥ 377",
|
|
24
|
+
wide: "≥ 610",
|
|
19
25
|
},
|
|
20
26
|
viewport: {
|
|
21
27
|
compact: "Compact",
|
|
@@ -11,6 +11,7 @@ import { readPhiInternalReference } from "../../../types/references";
|
|
|
11
11
|
import { resolvePhiWidgetInternalReferences } from "../helpers/internal-reference-resolver.server";
|
|
12
12
|
import { protectPhiMailHref, splitPhiMailAddresses } from "../../../helpers/protected-mail";
|
|
13
13
|
import { resolvePhiWidgetSourceUrl } from "../helpers/widget-source-url";
|
|
14
|
+
import { buildMarkdownTranslationUnit, readMarkdownTranslationUnit, } from "./markdown-translation-unit";
|
|
14
15
|
const MARKDOWN_DEFAULT_REVALIDATE_SECONDS = 14400;
|
|
15
16
|
function normalizeMarkdownSourceUrl(sourceUrl, publicUrl) {
|
|
16
17
|
const trimmed = resolvePhiWidgetSourceUrl(sourceUrl, publicUrl);
|
|
@@ -251,65 +252,11 @@ function mapInlineNodes(nodes) {
|
|
|
251
252
|
}
|
|
252
253
|
});
|
|
253
254
|
}
|
|
254
|
-
function escapeTranslationHtml(value) {
|
|
255
|
-
return value
|
|
256
|
-
.replaceAll("&", "&")
|
|
257
|
-
.replaceAll("<", "<")
|
|
258
|
-
.replaceAll(">", ">")
|
|
259
|
-
.replaceAll('"', """);
|
|
260
|
-
}
|
|
261
|
-
function decodeTranslationHtml(value) {
|
|
262
|
-
return value
|
|
263
|
-
.replaceAll(""", '"')
|
|
264
|
-
.replaceAll("'", "'")
|
|
265
|
-
.replaceAll(">", ">")
|
|
266
|
-
.replaceAll("<", "<")
|
|
267
|
-
.replaceAll("&", "&");
|
|
268
|
-
}
|
|
269
|
-
function serializeMarkdownInlines(nodes, metadata) {
|
|
270
|
-
return (nodes ?? []).map((node) => {
|
|
271
|
-
switch (node.type) {
|
|
272
|
-
case "text":
|
|
273
|
-
return escapeTranslationHtml(node.value ?? "");
|
|
274
|
-
case "strong":
|
|
275
|
-
return `<x-strong>${serializeMarkdownInlines(node.children, metadata)}</x-strong>`;
|
|
276
|
-
case "emphasis":
|
|
277
|
-
return `<x-emphasis>${serializeMarkdownInlines(node.children, metadata)}</x-emphasis>`;
|
|
278
|
-
case "delete":
|
|
279
|
-
return `<x-delete>${serializeMarkdownInlines(node.children, metadata)}</x-delete>`;
|
|
280
|
-
case "link": {
|
|
281
|
-
const index = metadata.links.push(node.url?.trim() ?? "") - 1;
|
|
282
|
-
return `<x-link data-index="${index}">${serializeMarkdownInlines(node.children, metadata)}</x-link>`;
|
|
283
|
-
}
|
|
284
|
-
case "image": {
|
|
285
|
-
/*
|
|
286
|
-
* The title is prose and gets translated, but as a unit of its own rather than as more content
|
|
287
|
-
* inside the image token. Two separate sentences in one token read as one run of text: asked to
|
|
288
|
-
* translate `alt` and title together, a translator returned them merged and re-split at a
|
|
289
|
-
* different point. Keeping the token's shape also leaves every already-translated image
|
|
290
|
-
* unchanged, since the string the catalogue is keyed by does not move.
|
|
291
|
-
*/
|
|
292
|
-
const index = metadata.images.push(node.url?.trim() ?? "") - 1;
|
|
293
|
-
metadata.titles[index] = node.title?.trim() ?? "";
|
|
294
|
-
return `<x-image data-index="${index}">${escapeTranslationHtml(node.alt ?? "")}</x-image>`;
|
|
295
|
-
}
|
|
296
|
-
case "inlineCode": {
|
|
297
|
-
const index = metadata.code.push(node.value ?? "") - 1;
|
|
298
|
-
return `<x-code data-index="${index}" translate="no">${escapeTranslationHtml(node.value ?? "")}</x-code>`;
|
|
299
|
-
}
|
|
300
|
-
case "break":
|
|
301
|
-
return "<br/>";
|
|
302
|
-
default:
|
|
303
|
-
return serializeMarkdownInlines(node.children, metadata);
|
|
304
|
-
}
|
|
305
|
-
}).join("");
|
|
306
|
-
}
|
|
307
255
|
function collectMarkdownTranslationUnits(node, units) {
|
|
308
256
|
if (node.type === "heading" || node.type === "paragraph" || node.type === "tableCell") {
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
units.push({ node, html, metadata });
|
|
257
|
+
const unit = buildMarkdownTranslationUnit(node.children);
|
|
258
|
+
if (unit.translatable || unit.slots.some((slot) => slot.kind === "image")) {
|
|
259
|
+
units.push({ node, unit });
|
|
313
260
|
}
|
|
314
261
|
return;
|
|
315
262
|
}
|
|
@@ -320,69 +267,6 @@ function collectMarkdownTranslationUnits(node, units) {
|
|
|
320
267
|
collectMarkdownTranslationUnits(child, units);
|
|
321
268
|
}
|
|
322
269
|
}
|
|
323
|
-
function parseTranslatedMarkdownInlines(translatedHtml, metadata) {
|
|
324
|
-
const stack = [{ kind: "root", children: [] }];
|
|
325
|
-
const tokenPattern = /<\/?x-(?:strong|emphasis|delete|link|image|code)\b[^>]*>|<br\s*\/?>/gi;
|
|
326
|
-
let cursor = 0;
|
|
327
|
-
const appendText = (value) => {
|
|
328
|
-
if (value)
|
|
329
|
-
stack.at(-1)?.children.push({ kind: "text", text: decodeTranslationHtml(value) });
|
|
330
|
-
};
|
|
331
|
-
for (const match of translatedHtml.matchAll(tokenPattern)) {
|
|
332
|
-
appendText(translatedHtml.slice(cursor, match.index));
|
|
333
|
-
const token = match[0];
|
|
334
|
-
cursor = (match.index ?? 0) + token.length;
|
|
335
|
-
if (/^<br/i.test(token)) {
|
|
336
|
-
stack.at(-1)?.children.push({ kind: "break" });
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
const closing = /^<\//.test(token);
|
|
340
|
-
const kindMatch = token.match(/^<\/?x-(strong|emphasis|delete|link|image|code)/i);
|
|
341
|
-
const kind = kindMatch?.[1]?.toLowerCase();
|
|
342
|
-
if (!kind)
|
|
343
|
-
return null;
|
|
344
|
-
if (!closing) {
|
|
345
|
-
const indexMatch = token.match(/data-index=["']?(\d+)/i);
|
|
346
|
-
stack.push({ kind, index: indexMatch ? Number(indexMatch[1]) : undefined, children: [] });
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
const frame = stack.pop();
|
|
350
|
-
if (!frame || frame.kind !== kind || stack.length === 0)
|
|
351
|
-
return null;
|
|
352
|
-
const parent = stack.at(-1);
|
|
353
|
-
if (!parent)
|
|
354
|
-
return null;
|
|
355
|
-
if (kind === "strong" || kind === "emphasis" || kind === "delete") {
|
|
356
|
-
parent.children.push({ kind, children: frame.children });
|
|
357
|
-
}
|
|
358
|
-
else if (kind === "link") {
|
|
359
|
-
const href = metadata.links[frame.index ?? -1];
|
|
360
|
-
if (href == null)
|
|
361
|
-
return null;
|
|
362
|
-
parent.children.push({ kind: "link", href, external: /^https?:\/\//.test(href), children: frame.children });
|
|
363
|
-
}
|
|
364
|
-
else if (kind === "image") {
|
|
365
|
-
const src = metadata.images[frame.index ?? -1];
|
|
366
|
-
if (src == null)
|
|
367
|
-
return null;
|
|
368
|
-
const title = metadata.titles[frame.index ?? -1]?.trim() ?? "";
|
|
369
|
-
parent.children.push({
|
|
370
|
-
kind: "image",
|
|
371
|
-
src,
|
|
372
|
-
alt: getInlineText(frame.children),
|
|
373
|
-
...(title ? { title } : {}),
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
else if (kind === "code") {
|
|
377
|
-
const text = metadata.code[frame.index ?? -1];
|
|
378
|
-
if (text == null)
|
|
379
|
-
return null;
|
|
380
|
-
parent.children.push({ kind: "inline_code", text });
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
appendText(translatedHtml.slice(cursor));
|
|
384
|
-
return stack.length === 1 ? stack[0]?.children ?? [] : null;
|
|
385
|
-
}
|
|
386
270
|
/*
|
|
387
271
|
* The render's own locale where there is one. A static render has no request to ask: `trBulk` reads the
|
|
388
272
|
* locale from the request headers, finds none, and answers in the Site's default -- which left every
|
|
@@ -396,25 +280,36 @@ function translateUnits(locale, msgs, format, sourceLocale) {
|
|
|
396
280
|
async function buildMarkdownInlineMap(tree, translate, sourceLocale, locale) {
|
|
397
281
|
const units = [];
|
|
398
282
|
collectMarkdownTranslationUnits(tree, units);
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
283
|
+
const sent = units.filter((entry) => entry.unit.translatable);
|
|
284
|
+
const translated = new Map();
|
|
285
|
+
if (translate && sent.length > 0) {
|
|
286
|
+
const answers = await translateUnits(locale, sent.map((entry) => entry.unit.html), "html", sourceLocale);
|
|
287
|
+
sent.forEach((entry, index) => translated.set(entry, answers[index] || entry.unit.html));
|
|
288
|
+
}
|
|
402
289
|
/*
|
|
403
|
-
*
|
|
404
|
-
* from the
|
|
405
|
-
* them. They are collected across every unit so this stays one
|
|
290
|
+
* A picture's alt text and title are prose and translate as plain text, each on its own: they are
|
|
291
|
+
* separate sentences from the one the picture stands in, and asked for together a translator merged
|
|
292
|
+
* them and re-split them at another point. They are collected across every unit so this stays one
|
|
293
|
+
* request.
|
|
406
294
|
*/
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
295
|
+
const imageTexts = units.flatMap(({ unit }) => unit.slots.flatMap((slot) => slot.kind !== "image"
|
|
296
|
+
? []
|
|
297
|
+
: ["alt", "title"].flatMap((field) => slot[field].trim() ? [{ slot, field, text: slot[field] }] : [])));
|
|
298
|
+
if (translate && imageTexts.length > 0) {
|
|
299
|
+
const answers = await translateUnits(locale, imageTexts.map((entry) => entry.text), "text", sourceLocale);
|
|
300
|
+
imageTexts.forEach((entry, index) => {
|
|
301
|
+
entry.slot[entry.field] = answers[index] || entry.text;
|
|
412
302
|
});
|
|
413
303
|
}
|
|
414
|
-
return new Map(units.map((
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
304
|
+
return new Map(units.map((entry) => {
|
|
305
|
+
const answer = translated.get(entry);
|
|
306
|
+
return [
|
|
307
|
+
entry.node,
|
|
308
|
+
(answer !== undefined ? readMarkdownTranslationUnit(answer, entry.unit.slots) : null)
|
|
309
|
+
?? readMarkdownTranslationUnit(entry.unit.html, entry.unit.slots)
|
|
310
|
+
?? mapInlineNodes(entry.node.children),
|
|
311
|
+
];
|
|
312
|
+
}));
|
|
418
313
|
}
|
|
419
314
|
function getInlineText(inlines) {
|
|
420
315
|
return inlines
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PhiMarkdownInline } from "./markdown-body-client";
|
|
2
|
+
/**
|
|
3
|
+
* One Markdown translation unit as it travels: plain HTML any provider's HTML mode handles, with what
|
|
4
|
+
* must not be translated taken out of the text as a numbered `%n`. The vocabulary is the table in
|
|
5
|
+
* TRANSLATIONS.md, "The Markdown unit format".
|
|
6
|
+
*/
|
|
7
|
+
/** The smallest tree the unit is built from: an mdast inline node, as far as a unit reads it. */
|
|
8
|
+
export type MarkdownUnitNode = {
|
|
9
|
+
type: string;
|
|
10
|
+
value?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
alt?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
children?: MarkdownUnitNode[];
|
|
15
|
+
};
|
|
16
|
+
/** What one `%n` stands for, at index `n - 1`. */
|
|
17
|
+
export type MarkdownUnitSlot = {
|
|
18
|
+
kind: "code";
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "link";
|
|
22
|
+
href: string;
|
|
23
|
+
}
|
|
24
|
+
/** `alt` and `title` are filled with their translations before the unit is read back. */
|
|
25
|
+
| {
|
|
26
|
+
kind: "image";
|
|
27
|
+
src: string;
|
|
28
|
+
alt: string;
|
|
29
|
+
title: string;
|
|
30
|
+
}
|
|
31
|
+
/** `%` and digits the author wrote; masked so a provider cannot confuse it with a token. */
|
|
32
|
+
| {
|
|
33
|
+
kind: "literal";
|
|
34
|
+
text: string;
|
|
35
|
+
}
|
|
36
|
+
/** A Site copy placeholder (`helpers/text-placeholders.ts`), masked in the same sequence. */
|
|
37
|
+
| {
|
|
38
|
+
kind: "placeholder";
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
export type MarkdownTranslationUnit = {
|
|
42
|
+
/** What is sent: `format: "html"`. */
|
|
43
|
+
html: string;
|
|
44
|
+
slots: MarkdownUnitSlot[];
|
|
45
|
+
/** Whether any text is left once the tokens are out; a unit without any is not sent, only read back. */
|
|
46
|
+
translatable: boolean;
|
|
47
|
+
};
|
|
48
|
+
export type MarkdownTranslationUnitOptions = {
|
|
49
|
+
/** Mask Site copy placeholders (`{site.name}` …) in the same sequence; the Markdown body masks none. */
|
|
50
|
+
sitePlaceholders?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/** Builds the unit for one heading, paragraph or table cell from its inline children. */
|
|
53
|
+
export declare function buildMarkdownTranslationUnit(nodes: readonly MarkdownUnitNode[] | undefined, options?: MarkdownTranslationUnitOptions): MarkdownTranslationUnit;
|
|
54
|
+
/**
|
|
55
|
+
* Reads a unit back into inlines, by number and never by order: a provider moves tokens to wherever its
|
|
56
|
+
* language needs them. `null` for anything outside the vocabulary -- an unknown tag or attribute, a tag
|
|
57
|
+
* left open or closed out of turn, a slot missing, doubled or used as the wrong kind; the caller then
|
|
58
|
+
* shows the source.
|
|
59
|
+
*/
|
|
60
|
+
export declare function readMarkdownTranslationUnit(html: string, slots: readonly MarkdownUnitSlot[], options?: {
|
|
61
|
+
resolvePlaceholder?: (name: string) => string;
|
|
62
|
+
}): PhiMarkdownInline[] | null;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
const TEXT_TOKEN_PATTERN = /%\d+|\{([A-Za-z][\w.]*)\}/g;
|
|
2
|
+
function escapeUnitText(value) {
|
|
3
|
+
return value
|
|
4
|
+
.replaceAll("&", "&")
|
|
5
|
+
.replaceAll("<", "<")
|
|
6
|
+
.replaceAll(">", ">")
|
|
7
|
+
.replaceAll('"', """);
|
|
8
|
+
}
|
|
9
|
+
const NAMED_ENTITIES = {
|
|
10
|
+
amp: "&",
|
|
11
|
+
lt: "<",
|
|
12
|
+
gt: ">",
|
|
13
|
+
quot: '"',
|
|
14
|
+
apos: "'",
|
|
15
|
+
nbsp: " ",
|
|
16
|
+
};
|
|
17
|
+
function decodeUnitText(value) {
|
|
18
|
+
return value.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/giu, (entity, body) => {
|
|
19
|
+
if (body[0] === "#") {
|
|
20
|
+
const code = body[1] === "x" || body[1] === "X" ? Number.parseInt(body.slice(2), 16) : Number(body.slice(1));
|
|
21
|
+
return Number.isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : entity;
|
|
22
|
+
}
|
|
23
|
+
return NAMED_ENTITIES[body.toLowerCase()] ?? entity;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Builds the unit for one heading, paragraph or table cell from its inline children. */
|
|
27
|
+
export function buildMarkdownTranslationUnit(nodes, options = {}) {
|
|
28
|
+
const slots = [];
|
|
29
|
+
let html = "";
|
|
30
|
+
const token = (slot) => {
|
|
31
|
+
html += `%${slots.push(slot)}`;
|
|
32
|
+
};
|
|
33
|
+
const serializeText = (value) => {
|
|
34
|
+
let cursor = 0;
|
|
35
|
+
/*
|
|
36
|
+
* Digits right after a token would read as part of its number -- `%1` and `2 times` are `%12` --
|
|
37
|
+
* so they leave the text as a literal of their own: `%1%2 times`.
|
|
38
|
+
*/
|
|
39
|
+
const leading = /%\d+$/.test(html) ? value.match(/^\d+/)?.[0] : undefined;
|
|
40
|
+
if (leading) {
|
|
41
|
+
token({ kind: "literal", text: leading });
|
|
42
|
+
cursor = leading.length;
|
|
43
|
+
}
|
|
44
|
+
for (const match of value.slice(cursor).matchAll(TEXT_TOKEN_PATTERN)) {
|
|
45
|
+
const name = match[1];
|
|
46
|
+
if (name !== undefined && !options.sitePlaceholders)
|
|
47
|
+
continue;
|
|
48
|
+
const start = cursor + (match.index ?? 0);
|
|
49
|
+
html += escapeUnitText(value.slice(cursor, start));
|
|
50
|
+
token(name !== undefined ? { kind: "placeholder", name } : { kind: "literal", text: match[0] });
|
|
51
|
+
cursor = start + match[0].length;
|
|
52
|
+
}
|
|
53
|
+
html += escapeUnitText(value.slice(cursor));
|
|
54
|
+
};
|
|
55
|
+
const serialize = (children) => {
|
|
56
|
+
for (const node of children ?? []) {
|
|
57
|
+
switch (node.type) {
|
|
58
|
+
case "text":
|
|
59
|
+
serializeText(node.value ?? "");
|
|
60
|
+
break;
|
|
61
|
+
case "strong":
|
|
62
|
+
html += "<b>";
|
|
63
|
+
serialize(node.children);
|
|
64
|
+
html += "</b>";
|
|
65
|
+
break;
|
|
66
|
+
case "emphasis":
|
|
67
|
+
html += "<i>";
|
|
68
|
+
serialize(node.children);
|
|
69
|
+
html += "</i>";
|
|
70
|
+
break;
|
|
71
|
+
case "delete":
|
|
72
|
+
html += "<s>";
|
|
73
|
+
serialize(node.children);
|
|
74
|
+
html += "</s>";
|
|
75
|
+
break;
|
|
76
|
+
case "link":
|
|
77
|
+
// The address is numbered before the text it carries, so the numbers read in source order.
|
|
78
|
+
html += `<a href="%${slots.push({ kind: "link", href: node.url?.trim() ?? "" })}">`;
|
|
79
|
+
serialize(node.children);
|
|
80
|
+
html += "</a>";
|
|
81
|
+
break;
|
|
82
|
+
case "image": {
|
|
83
|
+
const src = node.url?.trim() ?? "";
|
|
84
|
+
if (src)
|
|
85
|
+
token({ kind: "image", src, alt: node.alt ?? "", title: node.title?.trim() ?? "" });
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "inlineCode":
|
|
89
|
+
token({ kind: "code", text: node.value ?? "" });
|
|
90
|
+
break;
|
|
91
|
+
case "break":
|
|
92
|
+
html += "<br>";
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
serialize(node.children);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
serialize(nodes);
|
|
100
|
+
return { html, slots, translatable: hasMarkdownUnitText(html) };
|
|
101
|
+
}
|
|
102
|
+
/** Whether a unit holds any text once its tags and tokens are out. */
|
|
103
|
+
function hasMarkdownUnitText(html) {
|
|
104
|
+
return decodeUnitText(html.replace(/<[^>]*>/g, "").replace(/%\d+/g, "")).trim().length > 0;
|
|
105
|
+
}
|
|
106
|
+
const UNIT_TOKEN_PATTERN = /<(\/?)([a-z][a-z0-9]*)\b([^>]*)>|%(\d+)/gi;
|
|
107
|
+
const HREF_PATTERN = /^\s+href\s*=\s*(?:"%(\d+)"|'%(\d+)'|%(\d+)(?=\s|$))\s*$/i;
|
|
108
|
+
/**
|
|
109
|
+
* Reads a unit back into inlines, by number and never by order: a provider moves tokens to wherever its
|
|
110
|
+
* language needs them. `null` for anything outside the vocabulary -- an unknown tag or attribute, a tag
|
|
111
|
+
* left open or closed out of turn, a slot missing, doubled or used as the wrong kind; the caller then
|
|
112
|
+
* shows the source.
|
|
113
|
+
*/
|
|
114
|
+
export function readMarkdownTranslationUnit(html, slots, options = {}) {
|
|
115
|
+
const stack = [{ tag: "root", children: [] }];
|
|
116
|
+
const used = new Set();
|
|
117
|
+
const take = (digits) => {
|
|
118
|
+
const number = Number(digits);
|
|
119
|
+
const slot = slots[number - 1];
|
|
120
|
+
if (!slot || used.has(number))
|
|
121
|
+
return null;
|
|
122
|
+
used.add(number);
|
|
123
|
+
return slot;
|
|
124
|
+
};
|
|
125
|
+
const appendText = (text) => {
|
|
126
|
+
if (!text)
|
|
127
|
+
return;
|
|
128
|
+
const children = stack.at(-1).children;
|
|
129
|
+
const last = children.at(-1);
|
|
130
|
+
if (last?.kind === "text")
|
|
131
|
+
last.text += text;
|
|
132
|
+
else
|
|
133
|
+
children.push({ kind: "text", text });
|
|
134
|
+
};
|
|
135
|
+
const appendRaw = (raw) => {
|
|
136
|
+
// A `<` that opened no tag the pattern knows is markup this vocabulary does not have.
|
|
137
|
+
if (/<[a-z/!?]/i.test(raw))
|
|
138
|
+
return false;
|
|
139
|
+
appendText(decodeUnitText(raw));
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
let cursor = 0;
|
|
143
|
+
for (const match of html.matchAll(UNIT_TOKEN_PATTERN)) {
|
|
144
|
+
if (!appendRaw(html.slice(cursor, match.index)))
|
|
145
|
+
return null;
|
|
146
|
+
cursor = (match.index ?? 0) + match[0].length;
|
|
147
|
+
const [, closing, rawTag, attributes, digits] = match;
|
|
148
|
+
if (digits !== undefined) {
|
|
149
|
+
const slot = take(digits);
|
|
150
|
+
if (!slot || slot.kind === "link")
|
|
151
|
+
return null;
|
|
152
|
+
const children = stack.at(-1).children;
|
|
153
|
+
if (slot.kind === "code")
|
|
154
|
+
children.push({ kind: "inline_code", text: slot.text });
|
|
155
|
+
else if (slot.kind === "image") {
|
|
156
|
+
children.push({ kind: "image", src: slot.src, alt: slot.alt, ...(slot.title ? { title: slot.title } : {}) });
|
|
157
|
+
}
|
|
158
|
+
else if (slot.kind === "literal")
|
|
159
|
+
appendText(slot.text);
|
|
160
|
+
else
|
|
161
|
+
appendText(options.resolvePlaceholder?.(slot.name) ?? `{${slot.name}}`);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const tag = rawTag.toLowerCase();
|
|
165
|
+
if (tag === "br") {
|
|
166
|
+
if (closing || !/^\s*\/?\s*$/.test(attributes ?? ""))
|
|
167
|
+
return null;
|
|
168
|
+
stack.at(-1).children.push({ kind: "break" });
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (tag !== "b" && tag !== "i" && tag !== "s" && tag !== "a")
|
|
172
|
+
return null;
|
|
173
|
+
if (closing) {
|
|
174
|
+
const frame = stack.pop();
|
|
175
|
+
const parent = stack.at(-1);
|
|
176
|
+
if (!frame || !parent || frame.tag !== tag || (attributes ?? "").trim())
|
|
177
|
+
return null;
|
|
178
|
+
if (frame.tag === "a") {
|
|
179
|
+
parent.children.push({
|
|
180
|
+
kind: "link",
|
|
181
|
+
href: frame.href,
|
|
182
|
+
external: /^https?:\/\//.test(frame.href),
|
|
183
|
+
children: frame.children,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
parent.children.push({
|
|
188
|
+
kind: frame.tag === "b" ? "strong" : frame.tag === "i" ? "emphasis" : "delete",
|
|
189
|
+
children: frame.children,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (tag === "a") {
|
|
195
|
+
const href = (attributes ?? "").match(HREF_PATTERN);
|
|
196
|
+
const slot = href ? take(href[1] ?? href[2] ?? href[3]) : null;
|
|
197
|
+
if (slot?.kind !== "link")
|
|
198
|
+
return null;
|
|
199
|
+
stack.push({ tag, href: slot.href, children: [] });
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if ((attributes ?? "").trim())
|
|
203
|
+
return null;
|
|
204
|
+
stack.push({ tag, children: [] });
|
|
205
|
+
}
|
|
206
|
+
if (!appendRaw(html.slice(cursor)))
|
|
207
|
+
return null;
|
|
208
|
+
if (stack.length !== 1 || used.size !== slots.length)
|
|
209
|
+
return null;
|
|
210
|
+
return stack[0].children;
|
|
211
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import type { PhiResolvedBlockGeometry, PhiResolvedBlockLength } from "../types/renderable-block-geometry";
|
|
3
|
+
/**
|
|
4
|
+
* Where a block's geometry switches profile: one pair for every block (design/RESPONSIVE_BLOCK_GEOMETRY.md).
|
|
5
|
+
*
|
|
6
|
+
* A container query cannot read a custom property in its condition, so the widths stand literally in
|
|
7
|
+
* `styles/layout.css` and one rule serves every block -- the Grid's pair, so `compact | medium | wide`
|
|
8
|
+
* means one thing across the tree. `validate-container-breakpoint-contracts.ts` holds the literals to
|
|
9
|
+
* these numbers.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PHI_BLOCK_GEOMETRY_RESPONSIVE_MIN_WIDTH: {
|
|
12
|
+
readonly medium: 144 | 233 | 377 | 610 | 987;
|
|
13
|
+
readonly wide: 144 | 233 | 377 | 610 | 987;
|
|
14
|
+
};
|
|
15
|
+
/** The six declarations a block may hand to its container's queries, as CSS spells them. */
|
|
16
|
+
export type PhiBlockProfileDeclaration = "width" | "height" | "min-width" | "min-height" | "max-width" | "max-height";
|
|
17
|
+
/** The attribute a box carries for the declarations it hands to CSS, space-separated. */
|
|
18
|
+
export declare const PHI_BLOCK_PROFILED_ATTRIBUTE = "data-phi-block-profiled";
|
|
19
|
+
/**
|
|
20
|
+
* What the box a block is drawn on says where a profile says nothing, and how it writes a maximum.
|
|
21
|
+
*
|
|
22
|
+
* The frame and a Layout's own inner box answer silence differently -- the frame never grows past its
|
|
23
|
+
* slot, the inner box states no maximum of its own -- so each passes its own answers, the ones it
|
|
24
|
+
* writes inline for a block that names no profile.
|
|
25
|
+
*/
|
|
26
|
+
export type PhiBlockProfileBox = {
|
|
27
|
+
unstated: Record<PhiBlockProfileDeclaration, string>;
|
|
28
|
+
/** A stated inline maximum as the box writes it; the frame caps one at the slot. */
|
|
29
|
+
inlineMaximum?: (maximum: PhiResolvedBlockLength) => string;
|
|
30
|
+
};
|
|
31
|
+
export type PhiBlockProfileStyle = {
|
|
32
|
+
/** The declarations the box hands to the stylesheet; it writes none of them inline. */
|
|
33
|
+
declarations: readonly PhiBlockProfileDeclaration[];
|
|
34
|
+
attributes: {
|
|
35
|
+
[PHI_BLOCK_PROFILED_ATTRIBUTE]?: string;
|
|
36
|
+
};
|
|
37
|
+
/** `--phi-block-<declaration>`, `-medium` and `-wide`, all three for every declaration handed over. */
|
|
38
|
+
properties: Record<string, string>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The profile answers as the stylesheet reads them (LAYOUTING.md, "Block geometry per profile").
|
|
42
|
+
*
|
|
43
|
+
* **An axis is written inline or in CSS, never both**: an inline style beats every `@container` rule.
|
|
44
|
+
* So a declaration whose three answers differ is left out of the inline style and written as three
|
|
45
|
+
* custom properties, and the rules in `styles/layout.css` choose by the room the block is offered. A
|
|
46
|
+
* declaration that answers the same at every profile stays inline, and a block that names no profile
|
|
47
|
+
* hands nothing over and pays nothing.
|
|
48
|
+
*
|
|
49
|
+
* All three properties are written for a declaration handed over, the silent ones with the box's own
|
|
50
|
+
* answer: custom properties inherit, so a property left unwritten would read whatever an enclosing
|
|
51
|
+
* block wrote for its own geometry.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolvePhiBlockProfileStyle(geometry: PhiResolvedBlockGeometry, box: PhiBlockProfileBox): PhiBlockProfileStyle;
|
|
54
|
+
/** The inline style without the declarations handed to the stylesheet. */
|
|
55
|
+
export declare function omitPhiBlockProfiledDeclarations(style: CSSProperties, declarations: readonly PhiBlockProfileDeclaration[]): CSSProperties;
|
|
56
|
+
/**
|
|
57
|
+
* Whether a block asks the room it is offered a question, which is what makes that room a container.
|
|
58
|
+
*
|
|
59
|
+
* The box offering the room is a `phi-slot` size container only where the block standing in it names a
|
|
60
|
+
* profile; containment is not free (design/RESPONSIVE_BLOCK_GEOMETRY.md, "What it costs elsewhere"),
|
|
61
|
+
* and a page that names no profile stays byte for byte what it was.
|
|
62
|
+
*/
|
|
63
|
+
export declare function phiBlockGeometryQueriesRoom(geometry: PhiResolvedBlockGeometry): boolean;
|
|
64
|
+
/** The attribute that declares the `phi-slot` container, on the box that offers a profiled block its room. */
|
|
65
|
+
export declare function phiSlotContainerAttributes(queriesRoom: boolean): {
|
|
66
|
+
"data-phi-slot-container": string | undefined;
|
|
67
|
+
};
|