@activecollab/components 2.0.424 → 2.0.425
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/cjs/components/Media/Media.js +45 -4
- package/dist/cjs/components/Media/Media.js.map +1 -1
- package/dist/cjs/components/Media/Styles.js +4 -1
- package/dist/cjs/components/Media/Styles.js.map +1 -1
- package/dist/cjs/components/PortableText/renderers.js +8 -2
- package/dist/cjs/components/PortableText/renderers.js.map +1 -1
- package/dist/cjs/components/PortableText/types.js.map +1 -1
- package/dist/esm/components/Media/Media.d.ts +9 -0
- package/dist/esm/components/Media/Media.d.ts.map +1 -1
- package/dist/esm/components/Media/Media.js +44 -3
- package/dist/esm/components/Media/Media.js.map +1 -1
- package/dist/esm/components/Media/Styles.d.ts +1 -0
- package/dist/esm/components/Media/Styles.d.ts.map +1 -1
- package/dist/esm/components/Media/Styles.js +4 -1
- package/dist/esm/components/Media/Styles.js.map +1 -1
- package/dist/esm/components/PortableText/renderers.d.ts.map +1 -1
- package/dist/esm/components/PortableText/renderers.js +8 -2
- package/dist/esm/components/PortableText/renderers.js.map +1 -1
- package/dist/esm/components/PortableText/types.d.ts +16 -0
- package/dist/esm/components/PortableText/types.d.ts.map +1 -1
- package/dist/esm/components/PortableText/types.js.map +1 -1
- package/dist/index.js +57 -6
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,18 +3,51 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Media = void 0;
|
|
6
|
+
exports.Media = exports.MEDIA_PORTRAIT_MAX_HEIGHT = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _Styles = require("./Styles");
|
|
9
9
|
var _Typography = require("../Typography");
|
|
10
|
-
var _excluded = ["src", "alt", "variant", "caption"];
|
|
10
|
+
var _excluded = ["src", "alt", "variant", "caption", "width", "height", "density"];
|
|
11
11
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
12
12
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
13
13
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
14
14
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
15
|
+
/** A tall image (height greater than width) is capped at this display height. */
|
|
16
|
+
var MEDIA_PORTRAIT_MAX_HEIGHT = exports.MEDIA_PORTRAIT_MAX_HEIGHT = 680;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The box the `<img>` is laid out in, in CSS pixels. A portrait image taller
|
|
20
|
+
* than the cap is scaled down to the cap, keeping its aspect ratio. Resolving
|
|
21
|
+
* the cap here — rather than with `width: auto; max-height` in CSS — keeps the
|
|
22
|
+
* size independent of the file's natural pixel size, so a 2x capture without a
|
|
23
|
+
* `density` (and therefore no `srcset` descriptor) never renders upscaled.
|
|
24
|
+
*/
|
|
25
|
+
var displaySize = function displaySize(width, height) {
|
|
26
|
+
if (width == null || height == null) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (height > width && height > MEDIA_PORTRAIT_MAX_HEIGHT) {
|
|
30
|
+
return {
|
|
31
|
+
width: Math.round(width * MEDIA_PORTRAIT_MAX_HEIGHT / height),
|
|
32
|
+
height: MEDIA_PORTRAIT_MAX_HEIGHT
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
width,
|
|
37
|
+
height
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
15
41
|
/**
|
|
16
42
|
* An image block: a screenshot renders framed (border, no shadow), a flat
|
|
17
43
|
* illustration renders without a frame. The caption sits below the frame.
|
|
44
|
+
*
|
|
45
|
+
* `width`/`height` are the image's real display size in CSS pixels, measured
|
|
46
|
+
* at compile time. When present, the image renders at that size — centered,
|
|
47
|
+
* capped at the column width, never upscaled — and the `<img>` reserves the
|
|
48
|
+
* space so the layout does not jump as it loads. A tall image (height greater
|
|
49
|
+
* than width) is capped by height instead. When absent (e.g. a remote source
|
|
50
|
+
* the build could not measure), the image falls back to the column-width cap.
|
|
18
51
|
*/
|
|
19
52
|
var Media = exports.Media = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
20
53
|
var src = _ref.src,
|
|
@@ -22,15 +55,23 @@ var Media = exports.Media = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
|
|
|
22
55
|
_ref$variant = _ref.variant,
|
|
23
56
|
variant = _ref$variant === void 0 ? "illustration" : _ref$variant,
|
|
24
57
|
caption = _ref.caption,
|
|
58
|
+
width = _ref.width,
|
|
59
|
+
height = _ref.height,
|
|
60
|
+
density = _ref.density,
|
|
25
61
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
62
|
+
var size = displaySize(width, height);
|
|
26
63
|
return /*#__PURE__*/_react.default.createElement(_Styles.StyledMedia, _extends({
|
|
27
64
|
ref: ref,
|
|
28
|
-
$bordered: variant === "screenshot"
|
|
65
|
+
$bordered: variant === "screenshot",
|
|
66
|
+
$sized: size !== undefined
|
|
29
67
|
}, rest), /*#__PURE__*/_react.default.createElement("div", {
|
|
30
68
|
className: "c-media-frame"
|
|
31
69
|
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
32
70
|
src: src,
|
|
33
|
-
alt: alt !== null && alt !== void 0 ? alt : ""
|
|
71
|
+
alt: alt !== null && alt !== void 0 ? alt : "",
|
|
72
|
+
width: size === null || size === void 0 ? void 0 : size.width,
|
|
73
|
+
height: size === null || size === void 0 ? void 0 : size.height,
|
|
74
|
+
srcSet: density ? "".concat(src, " ").concat(density, "x") : undefined
|
|
34
75
|
})), caption ? /*#__PURE__*/_react.default.createElement(_Typography.Caption1, {
|
|
35
76
|
color: "secondary"
|
|
36
77
|
}, caption) : null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Media.js","names":["_react","_interopRequireWildcard","require","_Styles","_Typography","_excluded","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","_objectWithoutProperties","_objectWithoutPropertiesLoose","getOwnPropertySymbols","indexOf","propertyIsEnumerable","
|
|
1
|
+
{"version":3,"file":"Media.js","names":["_react","_interopRequireWildcard","require","_Styles","_Typography","_excluded","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","_objectWithoutProperties","_objectWithoutPropertiesLoose","getOwnPropertySymbols","indexOf","propertyIsEnumerable","MEDIA_PORTRAIT_MAX_HEIGHT","exports","displaySize","width","height","undefined","Math","round","Media","forwardRef","_ref","ref","src","alt","_ref$variant","variant","caption","density","rest","size","createElement","StyledMedia","$bordered","$sized","className","srcSet","concat","Caption1","color","displayName"],"sources":["../../../../src/components/Media/Media.tsx"],"sourcesContent":["import React, { forwardRef } from \"react\";\n\nimport { StyledMedia } from \"./Styles\";\nimport {\n PortableTextMediaBlock,\n PortableTextMediaImageVariant,\n} from \"../PortableText/types\";\nimport { Caption1 } from \"../Typography\";\n\nexport interface IMediaProps\n extends Omit<PortableTextMediaBlock, \"type\" | \"variant\">,\n React.ComponentPropsWithoutRef<\"div\"> {\n variant?: PortableTextMediaImageVariant;\n}\n\n/** A tall image (height greater than width) is capped at this display height. */\nexport const MEDIA_PORTRAIT_MAX_HEIGHT = 680;\n\n/**\n * The box the `<img>` is laid out in, in CSS pixels. A portrait image taller\n * than the cap is scaled down to the cap, keeping its aspect ratio. Resolving\n * the cap here — rather than with `width: auto; max-height` in CSS — keeps the\n * size independent of the file's natural pixel size, so a 2x capture without a\n * `density` (and therefore no `srcset` descriptor) never renders upscaled.\n */\nconst displaySize = (width?: number, height?: number) => {\n if (width == null || height == null) {\n return undefined;\n }\n\n if (height > width && height > MEDIA_PORTRAIT_MAX_HEIGHT) {\n return {\n width: Math.round((width * MEDIA_PORTRAIT_MAX_HEIGHT) / height),\n height: MEDIA_PORTRAIT_MAX_HEIGHT,\n };\n }\n\n return { width, height };\n};\n\n/**\n * An image block: a screenshot renders framed (border, no shadow), a flat\n * illustration renders without a frame. The caption sits below the frame.\n *\n * `width`/`height` are the image's real display size in CSS pixels, measured\n * at compile time. When present, the image renders at that size — centered,\n * capped at the column width, never upscaled — and the `<img>` reserves the\n * space so the layout does not jump as it loads. A tall image (height greater\n * than width) is capped by height instead. When absent (e.g. a remote source\n * the build could not measure), the image falls back to the column-width cap.\n */\nexport const Media = forwardRef<HTMLDivElement, IMediaProps>(\n (\n {\n src,\n alt,\n variant = \"illustration\",\n caption,\n width,\n height,\n density,\n ...rest\n },\n ref\n ) => {\n const size = displaySize(width, height);\n\n return (\n <StyledMedia\n ref={ref}\n $bordered={variant === \"screenshot\"}\n $sized={size !== undefined}\n {...rest}\n >\n <div className=\"c-media-frame\">\n <img\n src={src}\n alt={alt ?? \"\"}\n width={size?.width}\n height={size?.height}\n srcSet={density ? `${src} ${density}x` : undefined}\n />\n </div>\n {caption ? <Caption1 color=\"secondary\">{caption}</Caption1> : null}\n </StyledMedia>\n );\n }\n);\n\nMedia.displayName = \"Media\";\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAF,OAAA;AAAyC,IAAAG,SAAA;AAAA,SAAAJ,wBAAAK,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAP,uBAAA,YAAAA,wBAAAK,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,EAAA,OAAAP,CAAA,IAAAD,CAAA,GAAAW,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAnB,CAAA,EAAAc,EAAA,OAAAP,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAA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B,OAAA,CAAAyC,aAAA,CAACtD,OAAA,CAAAuD,WAAW,EAAAhC,QAAA;IACVsB,GAAG,EAAEA,GAAI;IACTW,SAAS,EAAEP,OAAO,KAAK,YAAa;IACpCQ,MAAM,EAAEJ,IAAI,KAAKd;EAAU,GACvBa,IAAI,gBAERvD,MAAA,CAAAgB,OAAA,CAAAyC,aAAA;IAAKI,SAAS,EAAC;EAAe,gBAC5B7D,MAAA,CAAAgB,OAAA,CAAAyC,aAAA;IACER,GAAG,EAAEA,GAAI;IACTC,GAAG,EAAEA,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,EAAG;IACfV,KAAK,EAAEgB,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEhB,KAAM;IACnBC,MAAM,EAAEe,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEf,MAAO;IACrBqB,MAAM,EAAER,OAAO,MAAAS,MAAA,CAAMd,GAAG,OAAAc,MAAA,CAAIT,OAAO,SAAMZ;EAAU,CACpD,CACE,CAAC,EACLW,OAAO,gBAAGrD,MAAA,CAAAgB,OAAA,CAAAyC,aAAA,CAACrD,WAAA,CAAA4D,QAAQ;IAACC,KAAK,EAAC;EAAW,GAAEZ,OAAkB,CAAC,GAAG,IACnD,CAAC;AAElB,CACF,CAAC;AAEDR,KAAK,CAACqB,WAAW,GAAG,OAAO","ignoreList":[]}
|
|
@@ -10,9 +10,12 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
10
10
|
var StyledMedia = exports.StyledMedia = _styledComponents.default.div.withConfig({
|
|
11
11
|
displayName: "Styles__StyledMedia",
|
|
12
12
|
componentId: "sc-zjz7mh-0"
|
|
13
|
-
})(["display:flex;flex-direction:column;gap:", ";width:100%;.c-media-frame{", "}.c-media-frame img{display:block;
|
|
13
|
+
})(["display:flex;flex-direction:column;gap:", ";width:100%;.c-media-frame{width:fit-content;max-width:100%;margin-inline:auto;", "}.c-media-frame img{display:block;height:auto;", "}"], _LayoutTokens.SPACE.sm, function (_ref) {
|
|
14
14
|
var $bordered = _ref.$bordered;
|
|
15
15
|
return $bordered && (0, _styledComponents.css)(["overflow:hidden;border:1px solid var(--border-primary);border-radius:", ";"], "0.5rem");
|
|
16
|
+
}, function (_ref2) {
|
|
17
|
+
var $sized = _ref2.$sized;
|
|
18
|
+
return $sized ? (0, _styledComponents.css)(["max-width:100%;"]) : (0, _styledComponents.css)(["width:100%;"]);
|
|
16
19
|
});
|
|
17
20
|
StyledMedia.displayName = "StyledMedia";
|
|
18
21
|
//# sourceMappingURL=Styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Styles.js","names":["_styledComponents","_interopRequireWildcard","require","_LayoutTokens","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledMedia","exports","styled","div","withConfig","displayName","componentId","SPACE","sm","_ref","$bordered","css"],"sources":["../../../../src/components/Media/Styles.ts"],"sourcesContent":["import styled, { css } from \"styled-components\";\nimport { theme } from \"twin.macro\";\n\nimport { SPACE } from \"../LayoutTokens\";\n\nexport const StyledMedia = styled.div<{ $bordered: boolean }>`\n display: flex;\n flex-direction: column;\n gap: ${SPACE.sm};\n width: 100%;\n\n .c-media-frame {\n ${({ $bordered }) =>\n $bordered &&\n css`\n overflow: hidden;\n border: 1px solid var(--border-primary);\n border-radius: ${theme(\"borderRadius.lg\")};\n `}\n }\n\n .c-media-frame img {\n display: block;\n
|
|
1
|
+
{"version":3,"file":"Styles.js","names":["_styledComponents","_interopRequireWildcard","require","_LayoutTokens","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledMedia","exports","styled","div","withConfig","displayName","componentId","SPACE","sm","_ref","$bordered","css","_ref2","$sized"],"sources":["../../../../src/components/Media/Styles.ts"],"sourcesContent":["import styled, { css } from \"styled-components\";\nimport { theme } from \"twin.macro\";\n\nimport { SPACE } from \"../LayoutTokens\";\n\nexport const StyledMedia = styled.div<{ $bordered: boolean; $sized: boolean }>`\n display: flex;\n flex-direction: column;\n gap: ${SPACE.sm};\n width: 100%;\n\n .c-media-frame {\n /* Hug the image and center it, so a small screenshot stays small instead\n of stretching to the column. Never wider than the column. */\n width: fit-content;\n max-width: 100%;\n margin-inline: auto;\n\n ${({ $bordered }) =>\n $bordered &&\n css`\n overflow: hidden;\n border: 1px solid var(--border-primary);\n border-radius: ${theme(\"borderRadius.lg\")};\n `}\n }\n\n .c-media-frame img {\n display: block;\n height: auto;\n\n ${({ $sized }) =>\n $sized\n ? css`\n /* The img's width/height attributes hold the display size (the\n portrait height cap already applied), so the image renders at\n its real on-screen size and never upscales. max-width keeps it\n inside the column; height: auto above preserves the aspect\n ratio when it shrinks. */\n max-width: 100%;\n `\n : css`\n /* No measured size (e.g. a remote source): fall back to the\n column-width cap. */\n width: 100%;\n `}\n }\n`;\n\nStyledMedia.displayName = \"StyledMedia\";\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,aAAA,GAAAD,OAAA;AAAwC,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,wBAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,EAAA,OAAAP,CAAA,IAAAD,CAAA,GAAAW,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAnB,CAAA,EAAAc,EAAA,OAAAP,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAM,EAAA,EAAAP,CAAA,IAAAC,CAAA,CAAAM,EAAA,IAAAd,CAAA,CAAAc,EAAA,WAAAN,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAEjC,IAAMmB,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAGE,yBAAM,CAACC,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,0LAG5BC,mBAAK,CAACC,EAAE,EAUX,UAAAC,IAAA;EAAA,IAAGC,SAAS,GAAAD,IAAA,CAATC,SAAS;EAAA,OACZA,SAAS,QACTC,qBAAG,kFAGgB,QAAwB,CAC1C;AAAA,GAOD,UAAAC,KAAA;EAAA,IAAGC,MAAM,GAAAD,KAAA,CAANC,MAAM;EAAA,OACTA,MAAM,OACFF,qBAAG,6BAQHA,qBAAG,kBAIF;AAAA,EAEV;AAEDX,WAAW,CAACK,WAAW,GAAG,aAAa","ignoreList":[]}
|
|
@@ -124,7 +124,10 @@ var portableTextDefaultBlockRenderers = exports.portableTextDefaultBlockRenderer
|
|
|
124
124
|
src = _ref1.src,
|
|
125
125
|
alt = _ref1.alt,
|
|
126
126
|
variant = _ref1.variant,
|
|
127
|
-
caption = _ref1.caption
|
|
127
|
+
caption = _ref1.caption,
|
|
128
|
+
width = _ref1.width,
|
|
129
|
+
height = _ref1.height,
|
|
130
|
+
density = _ref1.density;
|
|
128
131
|
|
|
129
132
|
// Video (and future) variants carry service semantics, so their renderer
|
|
130
133
|
// is application-catalog territory — an injected `media` override. The
|
|
@@ -138,7 +141,10 @@ var portableTextDefaultBlockRenderers = exports.portableTextDefaultBlockRenderer
|
|
|
138
141
|
src: src,
|
|
139
142
|
alt: alt,
|
|
140
143
|
variant: variant,
|
|
141
|
-
caption: caption
|
|
144
|
+
caption: caption,
|
|
145
|
+
width: width,
|
|
146
|
+
height: height,
|
|
147
|
+
density: density
|
|
142
148
|
});
|
|
143
149
|
},
|
|
144
150
|
"titled-text": function titledText(_ref10) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.js","names":["_react","_interopRequireWildcard","require","_Styles","_types","_Media","_Tables","_TitledText","_Typography","_Typography2","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","portableTextDefaultMarkRenderers","exports","strong","_ref","children","createElement","em","_ref2","code","_ref3","StyledCode","link","_ref4","mark","href","Fragment","StyledLink","target","rel","HEADING_LEVEL_VARIANTS","DEFAULT_HEADING_LEVEL","headingVariantForLevel","level","undefined","variant","console","warn","concat","HeadingBlock","_ref5","block","_ref6","id","Heading","titledTextHeadings","portableTextDefaultBlockRenderers","paragraph","_ref7","Body1","heading","list","_ref8","ordered","style","StyledList","as","$ordered","listItem","_ref9","Typography","media","_ref0","_ref1","src","alt","caption","isPortableTextMediaImageVariant","Media","titledText","_ref10","_ref11","title","TitledText","codeBlock","_ref12","_ref13","language","StyledCodeBlock","table","_ref14","renderSpans","_ref15","header","rows","cell","spans","map","span","index","key","text","StyledTableBlock","Table","Thead","Tbody","row","rowIndex","cellIndex","divider","StyledDivider"],"sources":["../../../../src/components/PortableText/renderers.tsx"],"sourcesContent":["import React, { Fragment, ReactNode } from \"react\";\n\nimport {\n StyledCode,\n StyledCodeBlock,\n StyledDivider,\n StyledLink,\n StyledList,\n StyledTableBlock,\n} from \"./Styles\";\nimport {\n isPortableTextMediaImageVariant,\n PortableTextBlockRenderer,\n PortableTextCodeBlock,\n PortableTextDefaultBlockType,\n PortableTextDefaultMark,\n PortableTextHeadingBlock,\n PortableTextHeadingLevel,\n PortableTextLinkMark,\n PortableTextListBlock,\n PortableTextMarkRenderer,\n PortableTextMediaBlock,\n PortableTextSpan,\n PortableTextTableBlock,\n PortableTextTitledTextBlock,\n} from \"./types\";\nimport { Media } from \"../Media\";\nimport { Table, Tbody, Thead } from \"../Tables\";\nimport {\n TitledText,\n TitledTextVariant,\n titledTextHeadings,\n} from \"../TitledText\";\nimport { Body1 } from \"../Typography\";\nimport { Typography } from \"../Typography/Typography\";\n\n/**\n * The default renderers for the universal set — everything a client renders\n * without injection, and nothing more: no product element ever lands here.\n * Injected {@link PortableTextComponents} maps take precedence entry by entry.\n */\n\nexport const portableTextDefaultMarkRenderers: Record<\n PortableTextDefaultMark,\n PortableTextMarkRenderer\n> = {\n strong: ({ children }) => <strong>{children}</strong>,\n em: ({ children }) => <em>{children}</em>,\n code: ({ children }) => <StyledCode>{children}</StyledCode>,\n link: ({ mark, children }) => {\n const href = (mark as PortableTextLinkMark | undefined)?.href;\n\n // A link mark without an href (authored as a plain string) has nowhere\n // to go — keep the text, skip the anchor.\n if (!href) {\n return <>{children}</>;\n }\n\n return (\n <StyledLink href={href} target=\"_blank\" rel=\"noopener noreferrer\">\n {children}\n </StyledLink>\n );\n },\n};\n\n/** The semantic wire levels resolve to typography only here, in the renderer. */\nconst HEADING_LEVEL_VARIANTS: Record<\n PortableTextHeadingLevel,\n TitledTextVariant\n> = {\n 1: \"title1\",\n 2: \"title2\",\n 3: \"header2\",\n};\n\n/** The level `heading` and `titled-text` fall back to. */\nconst DEFAULT_HEADING_LEVEL: PortableTextHeadingLevel = 3;\n\n/**\n * Resolve a semantic wire level to its typography variant. An absent level is\n * the documented default; any other unrecognised level is a serializer bug on\n * a fixed 1–3 scale, so it falls back to the default and is logged, per the\n * contract's degradation rule.\n */\nconst headingVariantForLevel = (\n level: PortableTextHeadingLevel | undefined\n): TitledTextVariant => {\n if (level === undefined) {\n return HEADING_LEVEL_VARIANTS[DEFAULT_HEADING_LEVEL];\n }\n\n const variant = HEADING_LEVEL_VARIANTS[level];\n if (!variant) {\n console.warn(\n `PortableText: unknown heading level ${level}, falling back to ${DEFAULT_HEADING_LEVEL}.`\n );\n return HEADING_LEVEL_VARIANTS[DEFAULT_HEADING_LEVEL];\n }\n\n return variant;\n};\n\n/** Heading levels map to the same typography TitledText uses. */\nconst HeadingBlock: PortableTextBlockRenderer = ({ block, children }) => {\n const { level, id } = block as PortableTextHeadingBlock;\n const Heading = titledTextHeadings[headingVariantForLevel(level)];\n return <Heading id={id}>{children}</Heading>;\n};\n\nexport const portableTextDefaultBlockRenderers: Record<\n PortableTextDefaultBlockType,\n PortableTextBlockRenderer\n> = {\n paragraph: ({ children }) => <Body1>{children}</Body1>,\n heading: HeadingBlock,\n list: ({ block, children }) => {\n const ordered = (block as PortableTextListBlock).style === \"number\";\n return (\n // `data-portable-list` scopes the depth-marker rules in Styles.ts to\n // design-system lists, and marks the ancestors those rules count.\n <StyledList\n as={ordered ? \"ol\" : \"ul\"}\n $ordered={ordered}\n data-portable-list=\"\"\n >\n {children}\n </StyledList>\n );\n },\n \"list-item\": ({ children }) => (\n <Typography variant=\"Body 1\" as=\"li\">\n {children}\n </Typography>\n ),\n media: ({ block }) => {\n const { src, alt, variant, caption } = block as PortableTextMediaBlock;\n\n // Video (and future) variants carry service semantics, so their renderer\n // is application-catalog territory — an injected `media` override. The\n // universal set covers images only; anything else degrades and warns, per\n // the contract's degradation rule.\n if (variant !== undefined && !isPortableTextMediaImageVariant(variant)) {\n console.warn(\n `PortableText: no default renderer for media variant \"${variant}\".`\n );\n return null;\n }\n\n return <Media src={src} alt={alt} variant={variant} caption={caption} />;\n },\n \"titled-text\": ({ block, children }) => {\n const { title, level } = block as PortableTextTitledTextBlock;\n return (\n <TitledText title={title} variant={headingVariantForLevel(level)}>\n {children}\n </TitledText>\n );\n },\n // No highlighter ships with the default set, so every language — known,\n // unknown or absent — is plain preformatted text; the hint travels on\n // data-language for surfaces that highlight.\n \"code-block\": ({ block }) => {\n const { code, language } = block as PortableTextCodeBlock;\n return (\n <StyledCodeBlock data-language={language || undefined}>\n <code>{code}</code>\n </StyledCodeBlock>\n );\n },\n table: ({ block, renderSpans }) => {\n const { header, rows } = block as PortableTextTableBlock;\n // Standalone (engine-less) use has no span renderer — keep the raw text.\n const cell = (spans: PortableTextSpan[]): ReactNode =>\n renderSpans\n ? renderSpans(spans)\n : spans.map((span, index) => (\n <Fragment key={index}>{span.text}</Fragment>\n ));\n\n return (\n <StyledTableBlock>\n <Table>\n <Thead>\n <tr>\n {header.map((spans, index) => (\n <th key={index}>{cell(spans)}</th>\n ))}\n </tr>\n </Thead>\n <Tbody>\n {rows.map((row, rowIndex) => (\n <tr key={rowIndex}>\n {row.map((spans, cellIndex) => (\n <td key={cellIndex}>{cell(spans)}</td>\n ))}\n </tr>\n ))}\n </Tbody>\n </Table>\n </StyledTableBlock>\n );\n },\n divider: () => <StyledDivider />,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAQA,IAAAE,MAAA,GAAAF,OAAA;AAgBA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAKA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAAsD,SAAAD,wBAAAS,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAX,uBAAA,YAAAA,wBAAAS,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,C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A,CAAC7B,OAAA,CAAA0G,KAAK,qBACJhH,MAAA,CAAAoB,OAAA,CAAAe,aAAA,CAAC7B,OAAA,CAAA2G,KAAK,qBACJjH,MAAA,CAAAoB,OAAA,CAAAe,aAAA,aACGmE,MAAM,CAACI,GAAG,CAAC,UAACD,KAAK,EAAEG,KAAK;MAAA,oBACvB5G,MAAA,CAAAoB,OAAA,CAAAe,aAAA;QAAI0E,GAAG,EAAED;MAAM,GAAEJ,IAAI,CAACC,KAAK,CAAM,CAAC;IAAA,CACnC,CACC,CACC,CAAC,eACRzG,MAAA,CAAAoB,OAAA,CAAAe,aAAA,CAAC7B,OAAA,CAAA4G,KAAK,QACHX,IAAI,CAACG,GAAG,CAAC,UAACS,GAAG,EAAEC,QAAQ;MAAA,oBACtBpH,MAAA,CAAAoB,OAAA,CAAAe,aAAA;QAAI0E,GAAG,EAAEO;MAAS,GACfD,GAAG,CAACT,GAAG,CAAC,UAACD,KAAK,EAAEY,SAAS;QAAA,oBACxBrH,MAAA,CAAAoB,OAAA,CAAAe,aAAA;UAAI0E,GAAG,EAAEQ;QAAU,GAAEb,IAAI,CAACC,KAAK,CAAM,CAAC;MAAA,CACvC,CACC,CAAC;IAAA,CACN,CACI,CACF,CACS,CAAC;EAEvB,CAAC;EACDa,OAAO,EAAE,SAATA,OAAOA,CAAA;IAAA,oBAAQtH,MAAA,CAAAoB,OAAA,CAAAe,aAAA,CAAChC,OAAA,CAAAoH,aAAa,MAAE,CAAC;EAAA;AAClC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"renderers.js","names":["_react","_interopRequireWildcard","require","_Styles","_types","_Media","_Tables","_TitledText","_Typography","_Typography2","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","portableTextDefaultMarkRenderers","exports","strong","_ref","children","createElement","em","_ref2","code","_ref3","StyledCode","link","_ref4","mark","href","Fragment","StyledLink","target","rel","HEADING_LEVEL_VARIANTS","DEFAULT_HEADING_LEVEL","headingVariantForLevel","level","undefined","variant","console","warn","concat","HeadingBlock","_ref5","block","_ref6","id","Heading","titledTextHeadings","portableTextDefaultBlockRenderers","paragraph","_ref7","Body1","heading","list","_ref8","ordered","style","StyledList","as","$ordered","listItem","_ref9","Typography","media","_ref0","_ref1","src","alt","caption","width","height","density","isPortableTextMediaImageVariant","Media","titledText","_ref10","_ref11","title","TitledText","codeBlock","_ref12","_ref13","language","StyledCodeBlock","table","_ref14","renderSpans","_ref15","header","rows","cell","spans","map","span","index","key","text","StyledTableBlock","Table","Thead","Tbody","row","rowIndex","cellIndex","divider","StyledDivider"],"sources":["../../../../src/components/PortableText/renderers.tsx"],"sourcesContent":["import React, { Fragment, ReactNode } from \"react\";\n\nimport {\n StyledCode,\n StyledCodeBlock,\n StyledDivider,\n StyledLink,\n StyledList,\n StyledTableBlock,\n} from \"./Styles\";\nimport {\n isPortableTextMediaImageVariant,\n PortableTextBlockRenderer,\n PortableTextCodeBlock,\n PortableTextDefaultBlockType,\n PortableTextDefaultMark,\n PortableTextHeadingBlock,\n PortableTextHeadingLevel,\n PortableTextLinkMark,\n PortableTextListBlock,\n PortableTextMarkRenderer,\n PortableTextMediaBlock,\n PortableTextSpan,\n PortableTextTableBlock,\n PortableTextTitledTextBlock,\n} from \"./types\";\nimport { Media } from \"../Media\";\nimport { Table, Tbody, Thead } from \"../Tables\";\nimport {\n TitledText,\n TitledTextVariant,\n titledTextHeadings,\n} from \"../TitledText\";\nimport { Body1 } from \"../Typography\";\nimport { Typography } from \"../Typography/Typography\";\n\n/**\n * The default renderers for the universal set — everything a client renders\n * without injection, and nothing more: no product element ever lands here.\n * Injected {@link PortableTextComponents} maps take precedence entry by entry.\n */\n\nexport const portableTextDefaultMarkRenderers: Record<\n PortableTextDefaultMark,\n PortableTextMarkRenderer\n> = {\n strong: ({ children }) => <strong>{children}</strong>,\n em: ({ children }) => <em>{children}</em>,\n code: ({ children }) => <StyledCode>{children}</StyledCode>,\n link: ({ mark, children }) => {\n const href = (mark as PortableTextLinkMark | undefined)?.href;\n\n // A link mark without an href (authored as a plain string) has nowhere\n // to go — keep the text, skip the anchor.\n if (!href) {\n return <>{children}</>;\n }\n\n return (\n <StyledLink href={href} target=\"_blank\" rel=\"noopener noreferrer\">\n {children}\n </StyledLink>\n );\n },\n};\n\n/** The semantic wire levels resolve to typography only here, in the renderer. */\nconst HEADING_LEVEL_VARIANTS: Record<\n PortableTextHeadingLevel,\n TitledTextVariant\n> = {\n 1: \"title1\",\n 2: \"title2\",\n 3: \"header2\",\n};\n\n/** The level `heading` and `titled-text` fall back to. */\nconst DEFAULT_HEADING_LEVEL: PortableTextHeadingLevel = 3;\n\n/**\n * Resolve a semantic wire level to its typography variant. An absent level is\n * the documented default; any other unrecognised level is a serializer bug on\n * a fixed 1–3 scale, so it falls back to the default and is logged, per the\n * contract's degradation rule.\n */\nconst headingVariantForLevel = (\n level: PortableTextHeadingLevel | undefined\n): TitledTextVariant => {\n if (level === undefined) {\n return HEADING_LEVEL_VARIANTS[DEFAULT_HEADING_LEVEL];\n }\n\n const variant = HEADING_LEVEL_VARIANTS[level];\n if (!variant) {\n console.warn(\n `PortableText: unknown heading level ${level}, falling back to ${DEFAULT_HEADING_LEVEL}.`\n );\n return HEADING_LEVEL_VARIANTS[DEFAULT_HEADING_LEVEL];\n }\n\n return variant;\n};\n\n/** Heading levels map to the same typography TitledText uses. */\nconst HeadingBlock: PortableTextBlockRenderer = ({ block, children }) => {\n const { level, id } = block as PortableTextHeadingBlock;\n const Heading = titledTextHeadings[headingVariantForLevel(level)];\n return <Heading id={id}>{children}</Heading>;\n};\n\nexport const portableTextDefaultBlockRenderers: Record<\n PortableTextDefaultBlockType,\n PortableTextBlockRenderer\n> = {\n paragraph: ({ children }) => <Body1>{children}</Body1>,\n heading: HeadingBlock,\n list: ({ block, children }) => {\n const ordered = (block as PortableTextListBlock).style === \"number\";\n return (\n // `data-portable-list` scopes the depth-marker rules in Styles.ts to\n // design-system lists, and marks the ancestors those rules count.\n <StyledList\n as={ordered ? \"ol\" : \"ul\"}\n $ordered={ordered}\n data-portable-list=\"\"\n >\n {children}\n </StyledList>\n );\n },\n \"list-item\": ({ children }) => (\n <Typography variant=\"Body 1\" as=\"li\">\n {children}\n </Typography>\n ),\n media: ({ block }) => {\n const { src, alt, variant, caption, width, height, density } =\n block as PortableTextMediaBlock;\n\n // Video (and future) variants carry service semantics, so their renderer\n // is application-catalog territory — an injected `media` override. The\n // universal set covers images only; anything else degrades and warns, per\n // the contract's degradation rule.\n if (variant !== undefined && !isPortableTextMediaImageVariant(variant)) {\n console.warn(\n `PortableText: no default renderer for media variant \"${variant}\".`\n );\n return null;\n }\n\n return (\n <Media\n src={src}\n alt={alt}\n variant={variant}\n caption={caption}\n width={width}\n height={height}\n density={density}\n />\n );\n },\n \"titled-text\": ({ block, children }) => {\n const { title, level } = block as PortableTextTitledTextBlock;\n return (\n <TitledText title={title} variant={headingVariantForLevel(level)}>\n {children}\n </TitledText>\n );\n },\n // No highlighter ships with the default set, so every language — known,\n // unknown or absent — is plain preformatted text; the hint travels on\n // data-language for surfaces that highlight.\n \"code-block\": ({ block }) => {\n const { code, language } = block as PortableTextCodeBlock;\n return (\n <StyledCodeBlock data-language={language || undefined}>\n <code>{code}</code>\n </StyledCodeBlock>\n );\n },\n table: ({ block, renderSpans }) => {\n const { header, rows } = block as PortableTextTableBlock;\n // Standalone (engine-less) use has no span renderer — keep the raw text.\n const cell = (spans: PortableTextSpan[]): ReactNode =>\n renderSpans\n ? renderSpans(spans)\n : spans.map((span, index) => (\n <Fragment key={index}>{span.text}</Fragment>\n ));\n\n return (\n <StyledTableBlock>\n <Table>\n <Thead>\n <tr>\n {header.map((spans, index) => (\n <th key={index}>{cell(spans)}</th>\n ))}\n </tr>\n </Thead>\n <Tbody>\n {rows.map((row, rowIndex) => (\n <tr key={rowIndex}>\n {row.map((spans, cellIndex) => (\n <td key={cellIndex}>{cell(spans)}</td>\n ))}\n </t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A,CAAC7B,OAAA,CAAA+G,KAAK,QACHX,IAAI,CAACG,GAAG,CAAC,UAACS,GAAG,EAAEC,QAAQ;MAAA,oBACtBvH,MAAA,CAAAoB,OAAA,CAAAe,aAAA;QAAI6E,GAAG,EAAEO;MAAS,GACfD,GAAG,CAACT,GAAG,CAAC,UAACD,KAAK,EAAEY,SAAS;QAAA,oBACxBxH,MAAA,CAAAoB,OAAA,CAAAe,aAAA;UAAI6E,GAAG,EAAEQ;QAAU,GAAEb,IAAI,CAACC,KAAK,CAAM,CAAC;MAAA,CACvC,CACC,CAAC;IAAA,CACN,CACI,CACF,CACS,CAAC;EAEvB,CAAC;EACDa,OAAO,EAAE,SAATA,OAAOA,CAAA;IAAA,oBAAQzH,MAAA,CAAAoB,OAAA,CAAAe,aAAA,CAAChC,OAAA,CAAAuH,aAAa,MAAE,CAAC;EAAA;AAClC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["PORTABLE_TEXT_DEFAULT_MARKS","exports","MEDIA_IMAGE_VARIANTS","screenshot","illustration","isPortableTextMediaImageVariant","value","DEFAULT_BLOCK_TYPES","paragraph","heading","list","media","table","divider","PORTABLE_TEXT_DEFAULT_BLOCKS","Object","keys","isRecord","isPortableTextSpan","text","isPortableTextTableRow","Array","isArray","every","cell","isPortableTextObjectNode","type","_type","isPortableTextBlock","children","id","undefined","child","src","title","content","isPortableTextContent","code","language","header","rows","node"],"sources":["../../../../src/components/PortableText/types.ts"],"sourcesContent":["import { ComponentType, ReactNode } from \"react\";\n\n/**\n * Portable Text envelope — the general content contract for structured,\n * renderer-independent content (in-app messages, help, changelogs).\n *\n * The design system owns this envelope and the universal default set below.\n * It never hardcodes a product element: concrete elements (callout,\n * button-reference, doc-link, …) are defined in the application catalog and\n * injected into the Portable Text engine through {@link PortableTextComponents}.\n * See README.md next to this file for the full contract.\n */\n\n/* ---- Spans and marks ------------------------------------------------- */\n\n/**\n * A mark with data. Parameterless marks travel as plain strings (\"strong\");\n * marks that need data travel as objects discriminated by `type`.\n */\nexport interface PortableTextMarkObject {\n type: string;\n [data: string]: unknown;\n}\n\n/** The one default mark that carries data. */\nexport interface PortableTextLinkMark extends PortableTextMarkObject {\n type: \"link\";\n href: string;\n}\n\nexport type PortableTextMark = string | PortableTextMarkObject;\n\n/** The leaf of every text run: a piece of text plus the marks wrapping it. */\nexport interface PortableTextSpan {\n text: string;\n marks?: PortableTextMark[];\n}\n\n/** Marks every client understands without injection. */\nexport const PORTABLE_TEXT_DEFAULT_MARKS = [\n \"strong\",\n \"em\",\n \"code\",\n \"link\",\n] as const;\n\nexport type PortableTextDefaultMark =\n (typeof PORTABLE_TEXT_DEFAULT_MARKS)[number];\n\n/* ---- Blocks ----------------------------------------------------------- */\n\nexport interface PortableTextParagraphBlock {\n type: \"paragraph\";\n children: PortableTextSpan[];\n}\n\n/** 1 maps to Title1, 2 to Title2, 3 to Header2 typography. */\nexport type PortableTextHeadingLevel = 1 | 2 | 3;\n\nexport interface PortableTextHeadingBlock {\n type: \"heading\";\n level: PortableTextHeadingLevel;\n /**\n * Optional anchor id, rendered verbatim as the heading element's `id` so the\n * heading is a scroll target (e.g. subarticle deep-links). Opaque to the\n * renderer — any slug convention lives with whoever produced the block.\n */\n id?: string;\n children: PortableTextSpan[];\n}\n\nexport type PortableTextListStyle = \"bullet\" | \"number\";\n\n/**\n * A list item's children are its own spans first, then any nested `list`\n * block(s) — the shape that carries multi-level lists. A spans-only item (no\n * nested list) is the common, flat case and stays valid unchanged.\n */\nexport interface PortableTextListItemBlock {\n type: \"list-item\";\n children: (PortableTextSpan | PortableTextListBlock)[];\n}\n\nexport interface PortableTextListBlock {\n type: \"list\";\n style?: PortableTextListStyle;\n children: PortableTextListItemBlock[];\n}\n\n/** Screenshots render framed (border, no shadow); illustrations render flat. */\nexport type PortableTextMediaImageVariant = \"screenshot\" | \"illustration\";\n\n/**\n * Video variants name the hosting service; `src` is the canonical video URL.\n * Their rendering carries service semantics (URL parsing, embed derivation),\n * so it belongs to the application catalog — injected as a `media` block\n * override — never to the default set. The default renderer degrades them.\n */\nexport type PortableTextMediaVideoVariant = \"vimeo\" | \"youtube\";\n\nexport type PortableTextMediaVariant =\n | PortableTextMediaImageVariant\n | PortableTextMediaVideoVariant;\n\n// A Record so the compiler checks the list against the union in both\n// directions: a missing and a stray key each fail to build.\nconst MEDIA_IMAGE_VARIANTS: Record<PortableTextMediaImageVariant, true> = {\n screenshot: true,\n illustration: true,\n};\n\nexport const isPortableTextMediaImageVariant = (\n value: unknown\n): value is PortableTextMediaImageVariant =>\n typeof value === \"string\" && value in MEDIA_IMAGE_VARIANTS;\n\nexport interface PortableTextMediaBlock {\n type: \"media\";\n src: string;\n alt?: string;\n variant?: PortableTextMediaVariant;\n caption?: string;\n}\n\nexport interface PortableTextTitledTextBlock {\n type: \"titled-text\";\n /**\n * Same semantic scale as `heading` — 1, 2 or 3 (the default) — so the wire\n * format never encodes a typography name. How a level looks is the\n * renderer's business.\n */\n level?: PortableTextHeadingLevel;\n title: string;\n content?: PortableTextNode[];\n}\n\nexport interface PortableTextCodeBlock {\n type: \"code-block\";\n /**\n * A language hint (e.g. \"php\", \"json\"). The default renderer does no\n * highlighting, so any value — known, unknown or absent — renders as plain\n * preformatted text; it travels as data for surfaces that highlight.\n */\n language?: string;\n code: string;\n}\n\n/** A table cell is a span array, so inline marks work inside cells. */\nexport type PortableTextTableCell = PortableTextSpan[];\nexport type PortableTextTableRow = PortableTextTableCell[];\n\nexport interface PortableTextTableBlock {\n type: \"table\";\n header: PortableTextTableRow;\n rows: PortableTextTableRow[];\n}\n\n/** A themed horizontal rule between sections. Carries no data. */\nexport interface PortableTextDividerBlock {\n type: \"divider\";\n}\n\nexport type PortableTextBlock =\n | PortableTextParagraphBlock\n | PortableTextHeadingBlock\n | PortableTextListBlock\n | PortableTextMediaBlock\n | PortableTextTitledTextBlock\n | PortableTextCodeBlock\n | PortableTextTableBlock\n | PortableTextDividerBlock;\n\n/**\n * Derived from the union's discriminators, so adding a block to the union\n * without a renderer entry is a compile error, never silent drift.\n */\nexport type PortableTextDefaultBlockType = (\n | PortableTextBlock\n | PortableTextListItemBlock\n)[\"type\"];\n\n// A Record so the compiler checks the list against the union in both\n// directions: a missing and a stray key each fail to build.\nconst DEFAULT_BLOCK_TYPES: Record<PortableTextDefaultBlockType, true> = {\n paragraph: true,\n heading: true,\n list: true,\n \"list-item\": true,\n media: true,\n \"titled-text\": true,\n \"code-block\": true,\n table: true,\n divider: true,\n};\n\n/** Blocks every client understands without injection. */\nexport const PORTABLE_TEXT_DEFAULT_BLOCKS = Object.keys(\n DEFAULT_BLOCK_TYPES\n) as readonly PortableTextDefaultBlockType[];\n\n/* ---- Objects ----------------------------------------------------------- */\n\n/**\n * An embedded component the envelope does not interpret: `_type` names an\n * application-catalog element, everything else is that element's data. An\n * object whose `_type` has no injected renderer renders nothing and is logged.\n */\nexport interface PortableTextObjectNode {\n type: \"object\";\n _type: string;\n [data: string]: unknown;\n}\n\nexport type PortableTextNode = PortableTextBlock | PortableTextObjectNode;\n\n/** The root of a message body: what an API returns under `content`. */\nexport type PortableTextContent = PortableTextNode[];\n\n/* ---- Injection contract ------------------------------------------------ */\n\nexport interface PortableTextMarkRendererProps<\n TMark extends PortableTextMarkObject = PortableTextMarkObject\n> {\n /** Present for object marks; absent when the mark is a plain string. */\n mark?: TMark;\n children: ReactNode;\n}\n\nexport type PortableTextMarkRenderer<\n TMark extends PortableTextMarkObject = PortableTextMarkObject\n> = ComponentType<PortableTextMarkRendererProps<TMark>>;\n\nexport interface PortableTextObjectRendererProps<\n TNode extends PortableTextObjectNode = PortableTextObjectNode\n> {\n node: TNode;\n /** The object's nested `content`, already rendered by the engine. */\n children?: ReactNode;\n}\n\nexport type PortableTextObjectRenderer<\n TNode extends PortableTextObjectNode = PortableTextObjectNode\n> = ComponentType<PortableTextObjectRendererProps<TNode>>;\n\nexport interface PortableTextBlockRendererProps<\n TBlock extends PortableTextBlock = PortableTextBlock\n> {\n block: TBlock;\n /** The block's rendered children/content, when it has any. */\n children?: ReactNode;\n /**\n * Engine-bound span renderer for blocks that carry spans outside `children`\n * (table cells). Resolves marks with the same precedence — injected first,\n * then defaults — as flowing text. Absent when a renderer is used without\n * the engine.\n */\n renderSpans?: (spans: PortableTextSpan[]) => ReactNode;\n}\n\nexport type PortableTextBlockRenderer<\n TBlock extends PortableTextBlock = PortableTextBlock\n> = ComponentType<PortableTextBlockRendererProps<TBlock>>;\n\nexport type PortableTextUnknownKind = \"block\" | \"mark\" | \"object\";\n\n/**\n * Called once per unknown type instead of rendering it, so content written\n * for newer clients degrades silently on older ones.\n */\nexport type PortableTextUnknownTypeHandler = (\n kind: PortableTextUnknownKind,\n type: string\n) => void;\n\n/**\n * What an application injects into the Portable Text engine: renderers for\n * its catalog marks and objects, optional overrides for the default blocks,\n * and the unknown-type hook.\n */\nexport interface PortableTextComponents {\n marks?: Record<string, PortableTextMarkRenderer>;\n objects?: Record<string, PortableTextObjectRenderer>;\n blocks?: Partial<\n Record<PortableTextDefaultBlockType, PortableTextBlockRenderer>\n >;\n onUnknownType?: PortableTextUnknownTypeHandler;\n}\n\n/* ---- Runtime guards ----------------------------------------------------- */\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nexport const isPortableTextSpan = (value: unknown): value is PortableTextSpan =>\n isRecord(value) && typeof value.text === \"string\";\n\nexport const isPortableTextTableRow = (\n value: unknown\n): value is PortableTextTableRow =>\n Array.isArray(value) &&\n value.every((cell) => Array.isArray(cell) && cell.every(isPortableTextSpan));\n\nexport const isPortableTextObjectNode = (\n value: unknown\n): value is PortableTextObjectNode =>\n isRecord(value) && value.type === \"object\" && typeof value._type === \"string\";\n\n/**\n * A block is any non-object node with a string `type`. Unknown block types\n * stay valid on purpose — they render nothing on clients that predate them.\n * Known types are held to their shape, so a serializer bug (a paragraph\n * without `children`, a list of non-nodes) fails here instead of at render.\n */\nexport const isPortableTextBlock = (\n value: unknown\n): value is PortableTextBlock => {\n if (\n !isRecord(value) ||\n typeof value.type !== \"string\" ||\n value.type === \"object\"\n ) {\n return false;\n }\n\n switch (value.type) {\n case \"paragraph\":\n return (\n Array.isArray(value.children) &&\n value.children.every(isPortableTextSpan)\n );\n case \"heading\":\n return (\n (value.id === undefined || typeof value.id === \"string\") &&\n Array.isArray(value.children) &&\n value.children.every(isPortableTextSpan)\n );\n case \"list-item\":\n // The item's spans, plus optional nested `list` block(s). Widened only\n // for nested lists: any other block child (a stray paragraph, an object)\n // still fails, so a serializer bug is caught here, not at render.\n return (\n Array.isArray(value.children) &&\n value.children.every(\n (child) =>\n isPortableTextSpan(child) ||\n (isPortableTextBlock(child) && child.type === \"list\")\n )\n );\n case \"list\":\n // A list holds `list-item`s only. A sublist emitted as a sibling of the\n // items (the classic half-implemented-nesting bug) renders invalid HTML\n // — <ul> with a direct <ul> child — so it fails here, not at render.\n // `list-item` is validated but sits outside the PortableTextBlock union,\n // so the discriminator is checked before isPortableTextBlock narrows it.\n return (\n Array.isArray(value.children) &&\n value.children.every(\n (child) =>\n isRecord(child) &&\n child.type === \"list-item\" &&\n isPortableTextBlock(child)\n )\n );\n case \"media\":\n return typeof value.src === \"string\";\n case \"titled-text\":\n return (\n typeof value.title === \"string\" &&\n (value.content === undefined || isPortableTextContent(value.content))\n );\n case \"code-block\":\n return (\n typeof value.code === \"string\" &&\n (value.language === undefined || typeof value.language === \"string\")\n );\n case \"table\":\n return (\n isPortableTextTableRow(value.header) &&\n Array.isArray(value.rows) &&\n value.rows.every(isPortableTextTableRow)\n );\n case \"divider\":\n return true;\n default:\n return true;\n }\n};\n\nexport const isPortableTextContent = (\n value: unknown\n): value is PortableTextContent =>\n Array.isArray(value) &&\n value.every(\n (node) => isPortableTextBlock(node) || isPortableTextObjectNode(node)\n );\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAMA;;AAQA;;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;IACb;MACE,OAAO,IAAI;EACf;AACF,CAAC;AAEM,IAAMgB,qBAAqB,GAAAnC,OAAA,CAAAmC,qBAAA,GAAG,SAAxBA,qBAAqBA,CAChC9B,KAAc;EAAA,OAEde,KAAK,CAACC,OAAO,CAAChB,KAAK,CAAC,IACpBA,KAAK,CAACiB,KAAK,CACT,UAACkB,IAAI;IAAA,OAAKb,oBAAmB,CAACa,IAAI,CAAC,IAAIhB,wBAAwB,CAACgB,IAAI,CAAC;EAAA,CACvE,CAAC;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":["PORTABLE_TEXT_DEFAULT_MARKS","exports","MEDIA_IMAGE_VARIANTS","screenshot","illustration","isPortableTextMediaImageVariant","value","DEFAULT_BLOCK_TYPES","paragraph","heading","list","media","table","divider","PORTABLE_TEXT_DEFAULT_BLOCKS","Object","keys","isRecord","isPortableTextSpan","text","isPortableTextTableRow","Array","isArray","every","cell","isPortableTextObjectNode","type","_type","isPortableTextBlock","children","id","undefined","child","src","title","content","isPortableTextContent","code","language","header","rows","node"],"sources":["../../../../src/components/PortableText/types.ts"],"sourcesContent":["import { ComponentType, ReactNode } from \"react\";\n\n/**\n * Portable Text envelope — the general content contract for structured,\n * renderer-independent content (in-app messages, help, changelogs).\n *\n * The design system owns this envelope and the universal default set below.\n * It never hardcodes a product element: concrete elements (callout,\n * button-reference, doc-link, …) are defined in the application catalog and\n * injected into the Portable Text engine through {@link PortableTextComponents}.\n * See README.md next to this file for the full contract.\n */\n\n/* ---- Spans and marks ------------------------------------------------- */\n\n/**\n * A mark with data. Parameterless marks travel as plain strings (\"strong\");\n * marks that need data travel as objects discriminated by `type`.\n */\nexport interface PortableTextMarkObject {\n type: string;\n [data: string]: unknown;\n}\n\n/** The one default mark that carries data. */\nexport interface PortableTextLinkMark extends PortableTextMarkObject {\n type: \"link\";\n href: string;\n}\n\nexport type PortableTextMark = string | PortableTextMarkObject;\n\n/** The leaf of every text run: a piece of text plus the marks wrapping it. */\nexport interface PortableTextSpan {\n text: string;\n marks?: PortableTextMark[];\n}\n\n/** Marks every client understands without injection. */\nexport const PORTABLE_TEXT_DEFAULT_MARKS = [\n \"strong\",\n \"em\",\n \"code\",\n \"link\",\n] as const;\n\nexport type PortableTextDefaultMark =\n (typeof PORTABLE_TEXT_DEFAULT_MARKS)[number];\n\n/* ---- Blocks ----------------------------------------------------------- */\n\nexport interface PortableTextParagraphBlock {\n type: \"paragraph\";\n children: PortableTextSpan[];\n}\n\n/** 1 maps to Title1, 2 to Title2, 3 to Header2 typography. */\nexport type PortableTextHeadingLevel = 1 | 2 | 3;\n\nexport interface PortableTextHeadingBlock {\n type: \"heading\";\n level: PortableTextHeadingLevel;\n /**\n * Optional anchor id, rendered verbatim as the heading element's `id` so the\n * heading is a scroll target (e.g. subarticle deep-links). Opaque to the\n * renderer — any slug convention lives with whoever produced the block.\n */\n id?: string;\n children: PortableTextSpan[];\n}\n\nexport type PortableTextListStyle = \"bullet\" | \"number\";\n\n/**\n * A list item's children are its own spans first, then any nested `list`\n * block(s) — the shape that carries multi-level lists. A spans-only item (no\n * nested list) is the common, flat case and stays valid unchanged.\n */\nexport interface PortableTextListItemBlock {\n type: \"list-item\";\n children: (PortableTextSpan | PortableTextListBlock)[];\n}\n\nexport interface PortableTextListBlock {\n type: \"list\";\n style?: PortableTextListStyle;\n children: PortableTextListItemBlock[];\n}\n\n/** Screenshots render framed (border, no shadow); illustrations render flat. */\nexport type PortableTextMediaImageVariant = \"screenshot\" | \"illustration\";\n\n/**\n * Video variants name the hosting service; `src` is the canonical video URL.\n * Their rendering carries service semantics (URL parsing, embed derivation),\n * so it belongs to the application catalog — injected as a `media` block\n * override — never to the default set. The default renderer degrades them.\n */\nexport type PortableTextMediaVideoVariant = \"vimeo\" | \"youtube\";\n\nexport type PortableTextMediaVariant =\n | PortableTextMediaImageVariant\n | PortableTextMediaVideoVariant;\n\n// A Record so the compiler checks the list against the union in both\n// directions: a missing and a stray key each fail to build.\nconst MEDIA_IMAGE_VARIANTS: Record<PortableTextMediaImageVariant, true> = {\n screenshot: true,\n illustration: true,\n};\n\nexport const isPortableTextMediaImageVariant = (\n value: unknown\n): value is PortableTextMediaImageVariant =>\n typeof value === \"string\" && value in MEDIA_IMAGE_VARIANTS;\n\nexport interface PortableTextMediaBlock {\n type: \"media\";\n src: string;\n alt?: string;\n variant?: PortableTextMediaVariant;\n caption?: string;\n /**\n * Display size in CSS pixels — the image's real on-screen size after the\n * compile-time density divide (a 2x screenshot is measured, then halved).\n * The renderer draws the image at this size, capping the width at the\n * column and never upscaling past it. Absent when the build could not\n * measure the source (e.g. a remote `http(s)` src); the renderer then falls\n * back to the column-width cap.\n */\n width?: number;\n height?: number;\n /**\n * The density factor the width and height were derived from (2 for a Retina\n * capture). Drives the `srcset` so Retina viewers get full sharpness at the\n * same display size. Opaque to layout.\n */\n density?: number;\n}\n\nexport interface PortableTextTitledTextBlock {\n type: \"titled-text\";\n /**\n * Same semantic scale as `heading` — 1, 2 or 3 (the default) — so the wire\n * format never encodes a typography name. How a level looks is the\n * renderer's business.\n */\n level?: PortableTextHeadingLevel;\n title: string;\n content?: PortableTextNode[];\n}\n\nexport interface PortableTextCodeBlock {\n type: \"code-block\";\n /**\n * A language hint (e.g. \"php\", \"json\"). The default renderer does no\n * highlighting, so any value — known, unknown or absent — renders as plain\n * preformatted text; it travels as data for surfaces that highlight.\n */\n language?: string;\n code: string;\n}\n\n/** A table cell is a span array, so inline marks work inside cells. */\nexport type PortableTextTableCell = PortableTextSpan[];\nexport type PortableTextTableRow = PortableTextTableCell[];\n\nexport interface PortableTextTableBlock {\n type: \"table\";\n header: PortableTextTableRow;\n rows: PortableTextTableRow[];\n}\n\n/** A themed horizontal rule between sections. Carries no data. */\nexport interface PortableTextDividerBlock {\n type: \"divider\";\n}\n\nexport type PortableTextBlock =\n | PortableTextParagraphBlock\n | PortableTextHeadingBlock\n | PortableTextListBlock\n | PortableTextMediaBlock\n | PortableTextTitledTextBlock\n | PortableTextCodeBlock\n | PortableTextTableBlock\n | PortableTextDividerBlock;\n\n/**\n * Derived from the union's discriminators, so adding a block to the union\n * without a renderer entry is a compile error, never silent drift.\n */\nexport type PortableTextDefaultBlockType = (\n | PortableTextBlock\n | PortableTextListItemBlock\n)[\"type\"];\n\n// A Record so the compiler checks the list against the union in both\n// directions: a missing and a stray key each fail to build.\nconst DEFAULT_BLOCK_TYPES: Record<PortableTextDefaultBlockType, true> = {\n paragraph: true,\n heading: true,\n list: true,\n \"list-item\": true,\n media: true,\n \"titled-text\": true,\n \"code-block\": true,\n table: true,\n divider: true,\n};\n\n/** Blocks every client understands without injection. */\nexport const PORTABLE_TEXT_DEFAULT_BLOCKS = Object.keys(\n DEFAULT_BLOCK_TYPES\n) as readonly PortableTextDefaultBlockType[];\n\n/* ---- Objects ----------------------------------------------------------- */\n\n/**\n * An embedded component the envelope does not interpret: `_type` names an\n * application-catalog element, everything else is that element's data. An\n * object whose `_type` has no injected renderer renders nothing and is logged.\n */\nexport interface PortableTextObjectNode {\n type: \"object\";\n _type: string;\n [data: string]: unknown;\n}\n\nexport type PortableTextNode = PortableTextBlock | PortableTextObjectNode;\n\n/** The root of a message body: what an API returns under `content`. */\nexport type PortableTextContent = PortableTextNode[];\n\n/* ---- Injection contract ------------------------------------------------ */\n\nexport interface PortableTextMarkRendererProps<\n TMark extends PortableTextMarkObject = PortableTextMarkObject\n> {\n /** Present for object marks; absent when the mark is a plain string. */\n mark?: TMark;\n children: ReactNode;\n}\n\nexport type PortableTextMarkRenderer<\n TMark extends PortableTextMarkObject = PortableTextMarkObject\n> = ComponentType<PortableTextMarkRendererProps<TMark>>;\n\nexport interface PortableTextObjectRendererProps<\n TNode extends PortableTextObjectNode = PortableTextObjectNode\n> {\n node: TNode;\n /** The object's nested `content`, already rendered by the engine. */\n children?: ReactNode;\n}\n\nexport type PortableTextObjectRenderer<\n TNode extends PortableTextObjectNode = PortableTextObjectNode\n> = ComponentType<PortableTextObjectRendererProps<TNode>>;\n\nexport interface PortableTextBlockRendererProps<\n TBlock extends PortableTextBlock = PortableTextBlock\n> {\n block: TBlock;\n /** The block's rendered children/content, when it has any. */\n children?: ReactNode;\n /**\n * Engine-bound span renderer for blocks that carry spans outside `children`\n * (table cells). Resolves marks with the same precedence — injected first,\n * then defaults — as flowing text. Absent when a renderer is used without\n * the engine.\n */\n renderSpans?: (spans: PortableTextSpan[]) => ReactNode;\n}\n\nexport type PortableTextBlockRenderer<\n TBlock extends PortableTextBlock = PortableTextBlock\n> = ComponentType<PortableTextBlockRendererProps<TBlock>>;\n\nexport type PortableTextUnknownKind = \"block\" | \"mark\" | \"object\";\n\n/**\n * Called once per unknown type instead of rendering it, so content written\n * for newer clients degrades silently on older ones.\n */\nexport type PortableTextUnknownTypeHandler = (\n kind: PortableTextUnknownKind,\n type: string\n) => void;\n\n/**\n * What an application injects into the Portable Text engine: renderers for\n * its catalog marks and objects, optional overrides for the default blocks,\n * and the unknown-type hook.\n */\nexport interface PortableTextComponents {\n marks?: Record<string, PortableTextMarkRenderer>;\n objects?: Record<string, PortableTextObjectRenderer>;\n blocks?: Partial<\n Record<PortableTextDefaultBlockType, PortableTextBlockRenderer>\n >;\n onUnknownType?: PortableTextUnknownTypeHandler;\n}\n\n/* ---- Runtime guards ----------------------------------------------------- */\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nexport const isPortableTextSpan = (value: unknown): value is PortableTextSpan =>\n isRecord(value) && typeof value.text === \"string\";\n\nexport const isPortableTextTableRow = (\n value: unknown\n): value is PortableTextTableRow =>\n Array.isArray(value) &&\n value.every((cell) => Array.isArray(cell) && cell.every(isPortableTextSpan));\n\nexport const isPortableTextObjectNode = (\n value: unknown\n): value is PortableTextObjectNode =>\n isRecord(value) && value.type === \"object\" && typeof value._type === \"string\";\n\n/**\n * A block is any non-object node with a string `type`. Unknown block types\n * stay valid on purpose — they render nothing on clients that predate them.\n * Known types are held to their shape, so a serializer bug (a paragraph\n * without `children`, a list of non-nodes) fails here instead of at render.\n */\nexport const isPortableTextBlock = (\n value: unknown\n): value is PortableTextBlock => {\n if (\n !isRecord(value) ||\n typeof value.type !== \"string\" ||\n value.type === \"object\"\n ) {\n return false;\n }\n\n switch (value.type) {\n case \"paragraph\":\n return (\n Array.isArray(value.children) &&\n value.children.every(isPortableTextSpan)\n );\n case \"heading\":\n return (\n (value.id === undefined || typeof value.id === \"string\") &&\n Array.isArray(value.children) &&\n value.children.every(isPortableTextSpan)\n );\n case \"list-item\":\n // The item's spans, plus optional nested `list` block(s). Widened only\n // for nested lists: any other block child (a stray paragraph, an object)\n // still fails, so a serializer bug is caught here, not at render.\n return (\n Array.isArray(value.children) &&\n value.children.every(\n (child) =>\n isPortableTextSpan(child) ||\n (isPortableTextBlock(child) && child.type === \"list\")\n )\n );\n case \"list\":\n // A list holds `list-item`s only. A sublist emitted as a sibling of the\n // items (the classic half-implemented-nesting bug) renders invalid HTML\n // — <ul> with a direct <ul> child — so it fails here, not at render.\n // `list-item` is validated but sits outside the PortableTextBlock union,\n // so the discriminator is checked before isPortableTextBlock narrows it.\n return (\n Array.isArray(value.children) &&\n value.children.every(\n (child) =>\n isRecord(child) &&\n child.type === \"list-item\" &&\n isPortableTextBlock(child)\n )\n );\n case \"media\":\n return typeof value.src === \"string\";\n case \"titled-text\":\n return (\n typeof value.title === \"string\" &&\n (value.content === undefined || isPortableTextContent(value.content))\n );\n case \"code-block\":\n return (\n typeof value.code === \"string\" &&\n (value.language === undefined || typeof value.language === \"string\")\n );\n case \"table\":\n return (\n isPortableTextTableRow(value.header) &&\n Array.isArray(value.rows) &&\n value.rows.every(isPortableTextTableRow)\n );\n case \"divider\":\n return true;\n default:\n return true;\n }\n};\n\nexport const isPortableTextContent = (\n value: unknown\n): value is PortableTextContent =>\n Array.isArray(value) &&\n value.every(\n (node) => isPortableTextBlock(node) || isPortableTextObjectNode(node)\n );\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;A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CAAC;IAE5C,KAAK,SAAS;MACZ,OAAO,IAAI;IACb;MACE,OAAO,IAAI;EACf;AACF,CAAC;AAEM,IAAMgB,qBAAqB,GAAAnC,OAAA,CAAAmC,qBAAA,GAAG,SAAxBA,qBAAqBA,CAChC9B,KAAc;EAAA,OAEde,KAAK,CAACC,OAAO,CAAChB,KAAK,CAAC,IACpBA,KAAK,CAACiB,KAAK,CACT,UAACkB,IAAI;IAAA,OAAKb,oBAAmB,CAACa,IAAI,CAAC,IAAIhB,wBAAwB,CAACgB,IAAI,CAAC;EAAA,CACvE,CAAC;AAAA","ignoreList":[]}
|
|
@@ -3,9 +3,18 @@ import { PortableTextMediaBlock, PortableTextMediaImageVariant } from "../Portab
|
|
|
3
3
|
export interface IMediaProps extends Omit<PortableTextMediaBlock, "type" | "variant">, React.ComponentPropsWithoutRef<"div"> {
|
|
4
4
|
variant?: PortableTextMediaImageVariant;
|
|
5
5
|
}
|
|
6
|
+
/** A tall image (height greater than width) is capped at this display height. */
|
|
7
|
+
export declare const MEDIA_PORTRAIT_MAX_HEIGHT = 680;
|
|
6
8
|
/**
|
|
7
9
|
* An image block: a screenshot renders framed (border, no shadow), a flat
|
|
8
10
|
* illustration renders without a frame. The caption sits below the frame.
|
|
11
|
+
*
|
|
12
|
+
* `width`/`height` are the image's real display size in CSS pixels, measured
|
|
13
|
+
* at compile time. When present, the image renders at that size — centered,
|
|
14
|
+
* capped at the column width, never upscaled — and the `<img>` reserves the
|
|
15
|
+
* space so the layout does not jump as it loads. A tall image (height greater
|
|
16
|
+
* than width) is capped by height instead. When absent (e.g. a remote source
|
|
17
|
+
* the build could not measure), the image falls back to the column-width cap.
|
|
9
18
|
*/
|
|
10
19
|
export declare const Media: React.ForwardRefExoticComponent<IMediaProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
20
|
//# sourceMappingURL=Media.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Media.d.ts","sourceRoot":"","sources":["../../../../src/components/Media/Media.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,uBAAuB,CAAC;AAG/B,MAAM,WAAW,WACf,SAAQ,IAAI,CAAC,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC,EACtD,KAAK,CAAC,wBAAwB,CAAC,KAAK,CAAC;IACvC,OAAO,CAAC,EAAE,6BAA6B,CAAC;CACzC;AAED
|
|
1
|
+
{"version":3,"file":"Media.d.ts","sourceRoot":"","sources":["../../../../src/components/Media/Media.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,uBAAuB,CAAC;AAG/B,MAAM,WAAW,WACf,SAAQ,IAAI,CAAC,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC,EACtD,KAAK,CAAC,wBAAwB,CAAC,KAAK,CAAC;IACvC,OAAO,CAAC,EAAE,6BAA6B,CAAC;CACzC;AAED,iFAAiF;AACjF,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAwB7C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,oFAoCjB,CAAC"}
|
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["src", "alt", "variant", "caption"];
|
|
3
|
+
const _excluded = ["src", "alt", "variant", "caption", "width", "height", "density"];
|
|
4
4
|
import React, { forwardRef } from "react";
|
|
5
5
|
import { StyledMedia } from "./Styles";
|
|
6
6
|
import { Caption1 } from "../Typography";
|
|
7
|
+
/** A tall image (height greater than width) is capped at this display height. */
|
|
8
|
+
export const MEDIA_PORTRAIT_MAX_HEIGHT = 680;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The box the `<img>` is laid out in, in CSS pixels. A portrait image taller
|
|
12
|
+
* than the cap is scaled down to the cap, keeping its aspect ratio. Resolving
|
|
13
|
+
* the cap here — rather than with `width: auto; max-height` in CSS — keeps the
|
|
14
|
+
* size independent of the file's natural pixel size, so a 2x capture without a
|
|
15
|
+
* `density` (and therefore no `srcset` descriptor) never renders upscaled.
|
|
16
|
+
*/
|
|
17
|
+
const displaySize = (width, height) => {
|
|
18
|
+
if (width == null || height == null) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (height > width && height > MEDIA_PORTRAIT_MAX_HEIGHT) {
|
|
22
|
+
return {
|
|
23
|
+
width: Math.round(width * MEDIA_PORTRAIT_MAX_HEIGHT / height),
|
|
24
|
+
height: MEDIA_PORTRAIT_MAX_HEIGHT
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
width,
|
|
29
|
+
height
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
7
33
|
/**
|
|
8
34
|
* An image block: a screenshot renders framed (border, no shadow), a flat
|
|
9
35
|
* illustration renders without a frame. The caption sits below the frame.
|
|
36
|
+
*
|
|
37
|
+
* `width`/`height` are the image's real display size in CSS pixels, measured
|
|
38
|
+
* at compile time. When present, the image renders at that size — centered,
|
|
39
|
+
* capped at the column width, never upscaled — and the `<img>` reserves the
|
|
40
|
+
* space so the layout does not jump as it loads. A tall image (height greater
|
|
41
|
+
* than width) is capped by height instead. When absent (e.g. a remote source
|
|
42
|
+
* the build could not measure), the image falls back to the column-width cap.
|
|
10
43
|
*/
|
|
11
44
|
export const Media = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
12
45
|
let src = _ref.src,
|
|
@@ -14,15 +47,23 @@ export const Media = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
14
47
|
_ref$variant = _ref.variant,
|
|
15
48
|
variant = _ref$variant === void 0 ? "illustration" : _ref$variant,
|
|
16
49
|
caption = _ref.caption,
|
|
50
|
+
width = _ref.width,
|
|
51
|
+
height = _ref.height,
|
|
52
|
+
density = _ref.density,
|
|
17
53
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
54
|
+
const size = displaySize(width, height);
|
|
18
55
|
return /*#__PURE__*/React.createElement(StyledMedia, _extends({
|
|
19
56
|
ref: ref,
|
|
20
|
-
$bordered: variant === "screenshot"
|
|
57
|
+
$bordered: variant === "screenshot",
|
|
58
|
+
$sized: size !== undefined
|
|
21
59
|
}, rest), /*#__PURE__*/React.createElement("div", {
|
|
22
60
|
className: "c-media-frame"
|
|
23
61
|
}, /*#__PURE__*/React.createElement("img", {
|
|
24
62
|
src: src,
|
|
25
|
-
alt: alt != null ? alt : ""
|
|
63
|
+
alt: alt != null ? alt : "",
|
|
64
|
+
width: size == null ? void 0 : size.width,
|
|
65
|
+
height: size == null ? void 0 : size.height,
|
|
66
|
+
srcSet: density ? src + " " + density + "x" : undefined
|
|
26
67
|
})), caption ? /*#__PURE__*/React.createElement(Caption1, {
|
|
27
68
|
color: "secondary"
|
|
28
69
|
}, caption) : null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Media.js","names":["React","forwardRef","StyledMedia","Caption1","Media","_ref","ref","src","alt","_ref$variant","variant","caption","rest","_objectWithoutPropertiesLoose","_excluded","createElement","_extends","$bordered","className","color","displayName"],"sources":["../../../../src/components/Media/Media.tsx"],"sourcesContent":["import React, { forwardRef } from \"react\";\n\nimport { StyledMedia } from \"./Styles\";\nimport {\n PortableTextMediaBlock,\n PortableTextMediaImageVariant,\n} from \"../PortableText/types\";\nimport { Caption1 } from \"../Typography\";\n\nexport interface IMediaProps\n extends Omit<PortableTextMediaBlock, \"type\" | \"variant\">,\n React.ComponentPropsWithoutRef<\"div\"> {\n variant?: PortableTextMediaImageVariant;\n}\n\n/**\n * An image block: a screenshot renders framed (border, no shadow), a flat\n * illustration renders without a frame. The caption sits below the frame.\n */\nexport const Media = forwardRef<HTMLDivElement, IMediaProps>(\n ({
|
|
1
|
+
{"version":3,"file":"Media.js","names":["React","forwardRef","StyledMedia","Caption1","MEDIA_PORTRAIT_MAX_HEIGHT","displaySize","width","height","undefined","Math","round","Media","_ref","ref","src","alt","_ref$variant","variant","caption","density","rest","_objectWithoutPropertiesLoose","_excluded","size","createElement","_extends","$bordered","$sized","className","srcSet","color","displayName"],"sources":["../../../../src/components/Media/Media.tsx"],"sourcesContent":["import React, { forwardRef } from \"react\";\n\nimport { StyledMedia } from \"./Styles\";\nimport {\n PortableTextMediaBlock,\n PortableTextMediaImageVariant,\n} from \"../PortableText/types\";\nimport { Caption1 } from \"../Typography\";\n\nexport interface IMediaProps\n extends Omit<PortableTextMediaBlock, \"type\" | \"variant\">,\n React.ComponentPropsWithoutRef<\"div\"> {\n variant?: PortableTextMediaImageVariant;\n}\n\n/** A tall image (height greater than width) is capped at this display height. */\nexport const MEDIA_PORTRAIT_MAX_HEIGHT = 680;\n\n/**\n * The box the `<img>` is laid out in, in CSS pixels. A portrait image taller\n * than the cap is scaled down to the cap, keeping its aspect ratio. Resolving\n * the cap here — rather than with `width: auto; max-height` in CSS — keeps the\n * size independent of the file's natural pixel size, so a 2x capture without a\n * `density` (and therefore no `srcset` descriptor) never renders upscaled.\n */\nconst displaySize = (width?: number, height?: number) => {\n if (width == null || height == null) {\n return undefined;\n }\n\n if (height > width && height > MEDIA_PORTRAIT_MAX_HEIGHT) {\n return {\n width: Math.round((width * MEDIA_PORTRAIT_MAX_HEIGHT) / height),\n height: MEDIA_PORTRAIT_MAX_HEIGHT,\n };\n }\n\n return { width, height };\n};\n\n/**\n * An image block: a screenshot renders framed (border, no shadow), a flat\n * illustration renders without a frame. The caption sits below the frame.\n *\n * `width`/`height` are the image's real display size in CSS pixels, measured\n * at compile time. When present, the image renders at that size — centered,\n * capped at the column width, never upscaled — and the `<img>` reserves the\n * space so the layout does not jump as it loads. A tall image (height greater\n * than width) is capped by height instead. When absent (e.g. a remote source\n * the build could not measure), the image falls back to the column-width cap.\n */\nexport const Media = forwardRef<HTMLDivElement, IMediaProps>(\n (\n {\n src,\n alt,\n variant = \"illustration\",\n caption,\n width,\n height,\n density,\n ...rest\n },\n ref\n ) => {\n const size = displaySize(width, height);\n\n return (\n <StyledMedia\n ref={ref}\n $bordered={variant === \"screenshot\"}\n $sized={size !== undefined}\n {...rest}\n >\n <div className=\"c-media-frame\">\n <img\n src={src}\n alt={alt ?? \"\"}\n width={size?.width}\n height={size?.height}\n srcSet={density ? `${src} ${density}x` : undefined}\n />\n </div>\n {caption ? <Caption1 color=\"secondary\">{caption}</Caption1> : null}\n </StyledMedia>\n );\n }\n);\n\nMedia.displayName = \"Media\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AAEzC,SAASC,WAAW,QAAQ,UAAU;AAKtC,SAASC,QAAQ,QAAQ,eAAe;AAQxC;AACA,OAAO,MAAMC,yBAAyB,GAAG,GAAG;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAGA,CAACC,KAAc,EAAEC,MAAe,KAAK;EACvD,IAAID,KAAK,IAAI,IAAI,IAAIC,MAAM,IAAI,IAAI,EAAE;IACnC,OAAOC,SAAS;EAClB;EAEA,IAAID,MAAM,GAAGD,KAAK,IAAIC,MAAM,GAAGH,yBAAyB,EAAE;IACxD,OAAO;MACLE,KAAK,EAAEG,IAAI,CAACC,KAAK,CAAEJ,KAAK,GAAGF,yBAAyB,GAAIG,MAAM,CAAC;MAC/DA,MAAM,EAAEH;IACV,CAAC;EACH;EAEA,OAAO;IAAEE,KAAK;IAAEC;EAAO,CAAC;AAC1B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,KAAK,gBAAGV,UAAU,CAC7B,CAAAW,IAAA,EAWEC,GAAG,KACA;EAAA,IAVDC,GAAG,GAAAF,IAAA,CAAHE,GAAG;IACHC,GAAG,GAAAH,IAA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AAW;eAA2B,OAAO;
|
|
1
|
+
{"version":3,"file":"Styles.d.ts","sourceRoot":"","sources":["../../../../src/components/Media/Styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW;eAA2B,OAAO;YAAU,OAAO;SA0C1E,CAAC"}
|
|
@@ -3,9 +3,12 @@ import { SPACE } from "../LayoutTokens";
|
|
|
3
3
|
export const StyledMedia = styled.div.withConfig({
|
|
4
4
|
displayName: "Styles__StyledMedia",
|
|
5
5
|
componentId: "sc-zjz7mh-0"
|
|
6
|
-
})(["display:flex;flex-direction:column;gap:", ";width:100%;.c-media-frame{", "}.c-media-frame img{display:block;
|
|
6
|
+
})(["display:flex;flex-direction:column;gap:", ";width:100%;.c-media-frame{width:fit-content;max-width:100%;margin-inline:auto;", "}.c-media-frame img{display:block;height:auto;", "}"], SPACE.sm, _ref => {
|
|
7
7
|
let $bordered = _ref.$bordered;
|
|
8
8
|
return $bordered && css(["overflow:hidden;border:1px solid var(--border-primary);border-radius:", ";"], "0.5rem");
|
|
9
|
+
}, _ref2 => {
|
|
10
|
+
let $sized = _ref2.$sized;
|
|
11
|
+
return $sized ? css(["max-width:100%;"]) : css(["width:100%;"]);
|
|
9
12
|
});
|
|
10
13
|
StyledMedia.displayName = "StyledMedia";
|
|
11
14
|
//# sourceMappingURL=Styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Styles.js","names":["styled","css","SPACE","StyledMedia","div","withConfig","displayName","componentId","sm","_ref","$bordered"],"sources":["../../../../src/components/Media/Styles.ts"],"sourcesContent":["import styled, { css } from \"styled-components\";\nimport { theme } from \"twin.macro\";\n\nimport { SPACE } from \"../LayoutTokens\";\n\nexport const StyledMedia = styled.div<{ $bordered: boolean }>`\n display: flex;\n flex-direction: column;\n gap: ${SPACE.sm};\n width: 100%;\n\n .c-media-frame {\n ${({ $bordered }) =>\n $bordered &&\n css`\n overflow: hidden;\n border: 1px solid var(--border-primary);\n border-radius: ${theme(\"borderRadius.lg\")};\n `}\n }\n\n .c-media-frame img {\n display: block;\n
|
|
1
|
+
{"version":3,"file":"Styles.js","names":["styled","css","SPACE","StyledMedia","div","withConfig","displayName","componentId","sm","_ref","$bordered","_ref2","$sized"],"sources":["../../../../src/components/Media/Styles.ts"],"sourcesContent":["import styled, { css } from \"styled-components\";\nimport { theme } from \"twin.macro\";\n\nimport { SPACE } from \"../LayoutTokens\";\n\nexport const StyledMedia = styled.div<{ $bordered: boolean; $sized: boolean }>`\n display: flex;\n flex-direction: column;\n gap: ${SPACE.sm};\n width: 100%;\n\n .c-media-frame {\n /* Hug the image and center it, so a small screenshot stays small instead\n of stretching to the column. Never wider than the column. */\n width: fit-content;\n max-width: 100%;\n margin-inline: auto;\n\n ${({ $bordered }) =>\n $bordered &&\n css`\n overflow: hidden;\n border: 1px solid var(--border-primary);\n border-radius: ${theme(\"borderRadius.lg\")};\n `}\n }\n\n .c-media-frame img {\n display: block;\n height: auto;\n\n ${({ $sized }) =>\n $sized\n ? css`\n /* The img's width/height attributes hold the display size (the\n portrait height cap already applied), so the image renders at\n its real on-screen size and never upscales. max-width keeps it\n inside the column; height: auto above preserves the aspect\n ratio when it shrinks. */\n max-width: 100%;\n `\n : css`\n /* No measured size (e.g. a remote source): fall back to the\n column-width cap. */\n width: 100%;\n `}\n }\n`;\n\nStyledMedia.displayName = \"StyledMedia\";\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAG/C,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,OAAO,MAAMC,WAAW,GAAGH,MAAM,CAACI,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,0LAG5BL,KAAK,CAACM,EAAE,EAUXC,IAAA;EAAA,IAAGC,SAAS,GAAAD,IAAA,CAATC,SAAS;EAAA,OACZA,SAAS,IACTT,GAAG,iFAGgB,QAAwB,CAC1C;AAAA,GAODU,KAAA;EAAA,IAAGC,MAAM,GAAAD,KAAA,CAANC,MAAM;EAAA,OACTA,MAAM,GACFX,GAAG,wBAQHA,GAAG,iBAIF;AAAA,EAEV;AAEDE,WAAW,CAACG,WAAW,GAAG,aAAa","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../src/components/PortableText/renderers.tsx"],"names":[],"mappings":"AAUA,OAAO,EAEL,yBAAyB,EAEzB,4BAA4B,EAC5B,uBAAuB,EAKvB,wBAAwB,EAKzB,MAAM,SAAS,CAAC;AAWjB;;;;GAIG;AAEH,eAAO,MAAM,gCAAgC,EAAE,MAAM,CACnD,uBAAuB,EACvB,wBAAwB,CAoBzB,CAAC;AA8CF,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACpD,4BAA4B,EAC5B,yBAAyB,
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../src/components/PortableText/renderers.tsx"],"names":[],"mappings":"AAUA,OAAO,EAEL,yBAAyB,EAEzB,4BAA4B,EAC5B,uBAAuB,EAKvB,wBAAwB,EAKzB,MAAM,SAAS,CAAC;AAWjB;;;;GAIG;AAEH,eAAO,MAAM,gCAAgC,EAAE,MAAM,CACnD,uBAAuB,EACvB,wBAAwB,CAoBzB,CAAC;AA8CF,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACpD,4BAA4B,EAC5B,yBAAyB,CAuG1B,CAAC"}
|
|
@@ -118,7 +118,10 @@ export const portableTextDefaultBlockRenderers = {
|
|
|
118
118
|
src = _ref1.src,
|
|
119
119
|
alt = _ref1.alt,
|
|
120
120
|
variant = _ref1.variant,
|
|
121
|
-
caption = _ref1.caption
|
|
121
|
+
caption = _ref1.caption,
|
|
122
|
+
width = _ref1.width,
|
|
123
|
+
height = _ref1.height,
|
|
124
|
+
density = _ref1.density;
|
|
122
125
|
|
|
123
126
|
// Video (and future) variants carry service semantics, so their renderer
|
|
124
127
|
// is application-catalog territory — an injected `media` override. The
|
|
@@ -132,7 +135,10 @@ export const portableTextDefaultBlockRenderers = {
|
|
|
132
135
|
src: src,
|
|
133
136
|
alt: alt,
|
|
134
137
|
variant: variant,
|
|
135
|
-
caption: caption
|
|
138
|
+
caption: caption,
|
|
139
|
+
width: width,
|
|
140
|
+
height: height,
|
|
141
|
+
density: density
|
|
136
142
|
});
|
|
137
143
|
},
|
|
138
144
|
"titled-text": _ref10 => {
|