@activecollab/components 2.0.408 → 2.0.410
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/BreakPoints.js +12 -1
- package/dist/cjs/components/BreakPoints.js.map +1 -1
- package/dist/cjs/components/Columns/Columns.js +42 -0
- package/dist/cjs/components/Columns/Columns.js.map +1 -0
- package/dist/cjs/components/Columns/Styles.js +25 -0
- package/dist/cjs/components/Columns/Styles.js.map +1 -0
- package/dist/cjs/components/Columns/index.js +17 -0
- package/dist/cjs/components/Columns/index.js.map +1 -0
- package/dist/cjs/components/Icons/collection/Project.js +98 -0
- package/dist/cjs/components/Icons/collection/Project.js.map +1 -0
- package/dist/cjs/components/Icons/collection/Task.js +61 -0
- package/dist/cjs/components/Icons/collection/Task.js.map +1 -0
- package/dist/cjs/components/Icons/collection/index.js +14 -0
- package/dist/cjs/components/Icons/collection/index.js.map +1 -1
- package/dist/cjs/components/LayoutTokens.js +21 -0
- package/dist/cjs/components/LayoutTokens.js.map +1 -0
- package/dist/cjs/components/Media/Media.js +39 -0
- package/dist/cjs/components/Media/Media.js.map +1 -0
- package/dist/cjs/components/Media/Styles.js +18 -0
- package/dist/cjs/components/Media/Styles.js.map +1 -0
- package/dist/cjs/components/Media/index.js +17 -0
- package/dist/cjs/components/Media/index.js.map +1 -0
- package/dist/cjs/components/PortableText/PortableText.js +125 -0
- package/dist/cjs/components/PortableText/PortableText.js.map +1 -0
- package/dist/cjs/components/PortableText/Styles.js +33 -0
- package/dist/cjs/components/PortableText/Styles.js.map +1 -0
- package/dist/cjs/components/PortableText/index.js +39 -0
- package/dist/cjs/components/PortableText/index.js.map +1 -0
- package/dist/cjs/components/PortableText/renderers.js +116 -0
- package/dist/cjs/components/PortableText/renderers.js.map +1 -0
- package/dist/cjs/components/PortableText/types.js +122 -0
- package/dist/cjs/components/PortableText/types.js.map +1 -0
- package/dist/cjs/components/PortableText/types.test.js +183 -0
- package/dist/cjs/components/PortableText/types.test.js.map +1 -0
- package/dist/cjs/components/Row/Row.js +30 -0
- package/dist/cjs/components/Row/Row.js.map +1 -0
- package/dist/cjs/components/Row/Styles.js +25 -0
- package/dist/cjs/components/Row/Styles.js.map +1 -0
- package/dist/cjs/components/Row/index.js +17 -0
- package/dist/cjs/components/Row/index.js.map +1 -0
- package/dist/cjs/components/Stack/Stack.js +27 -0
- package/dist/cjs/components/Stack/Stack.js.map +1 -0
- package/dist/cjs/components/Stack/Styles.js +21 -0
- package/dist/cjs/components/Stack/Styles.js.map +1 -0
- package/dist/cjs/components/Stack/index.js +17 -0
- package/dist/cjs/components/Stack/index.js.map +1 -0
- package/dist/cjs/components/Tiles/Styles.js +25 -0
- package/dist/cjs/components/Tiles/Styles.js.map +1 -0
- package/dist/cjs/components/Tiles/Tiles.js +29 -0
- package/dist/cjs/components/Tiles/Tiles.js.map +1 -0
- package/dist/cjs/components/Tiles/index.js +17 -0
- package/dist/cjs/components/Tiles/index.js.map +1 -0
- package/dist/cjs/components/TitledText/Styles.js +15 -0
- package/dist/cjs/components/TitledText/Styles.js.map +1 -0
- package/dist/cjs/components/TitledText/TitledText.js +50 -0
- package/dist/cjs/components/TitledText/TitledText.js.map +1 -0
- package/dist/cjs/components/TitledText/index.js +17 -0
- package/dist/cjs/components/TitledText/index.js.map +1 -0
- package/dist/cjs/components/index.js +88 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/presentation/shared/MessageDialog.js +351 -0
- package/dist/cjs/presentation/shared/MessageDialog.js.map +1 -0
- package/dist/cjs/presentation/shared/index.js +22 -0
- package/dist/cjs/presentation/shared/index.js.map +1 -1
- package/dist/cjs/presentation/stackedCard/content/NoteCard.js +7 -3
- package/dist/cjs/presentation/stackedCard/content/NoteCard.js.map +1 -1
- package/dist/cjs/presentation/stackedCard/content/ProjectCard.js +136 -0
- package/dist/cjs/presentation/stackedCard/content/ProjectCard.js.map +1 -0
- package/dist/cjs/presentation/stackedCard/content/TaskCard.js +183 -56
- package/dist/cjs/presentation/stackedCard/content/TaskCard.js.map +1 -1
- package/dist/cjs/presentation/stackedCard/content/index.js +11 -0
- package/dist/cjs/presentation/stackedCard/content/index.js.map +1 -1
- package/dist/cjs/presentation/stackedCard/content/shared.js +66 -19
- package/dist/cjs/presentation/stackedCard/content/shared.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/bottomDock.js +95 -32
- package/dist/cjs/presentation/whiteboard/bottomDock.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/canvasElements.js +196 -8
- package/dist/cjs/presentation/whiteboard/canvasElements.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/inspector.js +149 -47
- package/dist/cjs/presentation/whiteboard/inspector.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/outline.js +91 -18
- package/dist/cjs/presentation/whiteboard/outline.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/projectElements.js +883 -0
- package/dist/cjs/presentation/whiteboard/projectElements.js.map +1 -0
- package/dist/esm/components/BreakPoints.d.ts +2 -0
- package/dist/esm/components/BreakPoints.d.ts.map +1 -1
- package/dist/esm/components/BreakPoints.js +9 -0
- package/dist/esm/components/BreakPoints.js.map +1 -1
- package/dist/esm/components/Columns/Columns.d.ts +11 -0
- package/dist/esm/components/Columns/Columns.d.ts.map +1 -0
- package/dist/esm/components/Columns/Columns.js +34 -0
- package/dist/esm/components/Columns/Columns.js.map +1 -0
- package/dist/esm/components/Columns/Styles.d.ts +8 -0
- package/dist/esm/components/Columns/Styles.d.ts.map +1 -0
- package/dist/esm/components/Columns/Styles.js +18 -0
- package/dist/esm/components/Columns/Styles.js.map +1 -0
- package/dist/esm/components/Columns/index.d.ts +2 -0
- package/dist/esm/components/Columns/index.d.ts.map +1 -0
- package/dist/esm/components/Columns/index.js +2 -0
- package/dist/esm/components/Columns/index.js.map +1 -0
- package/dist/esm/components/Icons/collection/Project.d.ts +36 -0
- package/dist/esm/components/Icons/collection/Project.d.ts.map +1 -0
- package/dist/esm/components/Icons/collection/Project.js +91 -0
- package/dist/esm/components/Icons/collection/Project.js.map +1 -0
- package/dist/esm/components/Icons/collection/Task.d.ts +32 -0
- package/dist/esm/components/Icons/collection/Task.d.ts.map +1 -0
- package/dist/esm/components/Icons/collection/Task.js +54 -0
- package/dist/esm/components/Icons/collection/Task.js.map +1 -0
- package/dist/esm/components/Icons/collection/index.d.ts +2 -0
- package/dist/esm/components/Icons/collection/index.d.ts.map +1 -1
- package/dist/esm/components/Icons/collection/index.js +2 -0
- package/dist/esm/components/Icons/collection/index.js.map +1 -1
- package/dist/esm/components/LayoutTokens.d.ts +6 -0
- package/dist/esm/components/LayoutTokens.d.ts.map +1 -0
- package/dist/esm/components/LayoutTokens.js +15 -0
- package/dist/esm/components/LayoutTokens.js.map +1 -0
- package/dist/esm/components/Media/Media.d.ts +10 -0
- package/dist/esm/components/Media/Media.d.ts.map +1 -0
- package/dist/esm/components/Media/Media.js +31 -0
- package/dist/esm/components/Media/Media.js.map +1 -0
- package/dist/esm/components/Media/Styles.d.ts +4 -0
- package/dist/esm/components/Media/Styles.d.ts.map +1 -0
- package/dist/esm/components/Media/Styles.js +11 -0
- package/dist/esm/components/Media/Styles.js.map +1 -0
- package/dist/esm/components/Media/index.d.ts +2 -0
- package/dist/esm/components/Media/index.d.ts.map +1 -0
- package/dist/esm/components/Media/index.js +2 -0
- package/dist/esm/components/Media/index.js.map +1 -0
- package/dist/esm/components/PortableText/PortableText.d.ts +24 -0
- package/dist/esm/components/PortableText/PortableText.d.ts.map +1 -0
- package/dist/esm/components/PortableText/PortableText.js +111 -0
- package/dist/esm/components/PortableText/PortableText.js.map +1 -0
- package/dist/esm/components/PortableText/Styles.d.ts +9 -0
- package/dist/esm/components/PortableText/Styles.d.ts.map +1 -0
- package/dist/esm/components/PortableText/Styles.js +27 -0
- package/dist/esm/components/PortableText/Styles.js.map +1 -0
- package/dist/esm/components/PortableText/index.d.ts +4 -0
- package/dist/esm/components/PortableText/index.d.ts.map +1 -0
- package/dist/esm/components/PortableText/index.js +4 -0
- package/dist/esm/components/PortableText/index.js.map +1 -0
- package/dist/esm/components/PortableText/renderers.d.ts +9 -0
- package/dist/esm/components/PortableText/renderers.d.ts.map +1 -0
- package/dist/esm/components/PortableText/renderers.js +110 -0
- package/dist/esm/components/PortableText/renderers.js.map +1 -0
- package/dist/esm/components/PortableText/types.d.ts +141 -0
- package/dist/esm/components/PortableText/types.d.ts.map +1 -0
- package/dist/esm/components/PortableText/types.js +106 -0
- package/dist/esm/components/PortableText/types.js.map +1 -0
- package/dist/esm/components/PortableText/types.test.d.ts +2 -0
- package/dist/esm/components/PortableText/types.test.d.ts.map +1 -0
- package/dist/esm/components/PortableText/types.test.js +181 -0
- package/dist/esm/components/PortableText/types.test.js.map +1 -0
- package/dist/esm/components/Row/Row.d.ts +10 -0
- package/dist/esm/components/Row/Row.d.ts.map +1 -0
- package/dist/esm/components/Row/Row.js +22 -0
- package/dist/esm/components/Row/Row.js.map +1 -0
- package/dist/esm/components/Row/Styles.d.ts +8 -0
- package/dist/esm/components/Row/Styles.d.ts.map +1 -0
- package/dist/esm/components/Row/Styles.js +18 -0
- package/dist/esm/components/Row/Styles.js.map +1 -0
- package/dist/esm/components/Row/index.d.ts +2 -0
- package/dist/esm/components/Row/index.d.ts.map +1 -0
- package/dist/esm/components/Row/index.js +2 -0
- package/dist/esm/components/Row/index.js.map +1 -0
- package/dist/esm/components/Stack/Stack.d.ts +8 -0
- package/dist/esm/components/Stack/Stack.d.ts.map +1 -0
- package/dist/esm/components/Stack/Stack.js +19 -0
- package/dist/esm/components/Stack/Stack.js.map +1 -0
- package/dist/esm/components/Stack/Styles.d.ts +6 -0
- package/dist/esm/components/Stack/Styles.d.ts.map +1 -0
- package/dist/esm/components/Stack/Styles.js +14 -0
- package/dist/esm/components/Stack/Styles.js.map +1 -0
- package/dist/esm/components/Stack/index.d.ts +2 -0
- package/dist/esm/components/Stack/index.d.ts.map +1 -0
- package/dist/esm/components/Stack/index.js +2 -0
- package/dist/esm/components/Stack/index.js.map +1 -0
- package/dist/esm/components/Tiles/Styles.d.ts +8 -0
- package/dist/esm/components/Tiles/Styles.d.ts.map +1 -0
- package/dist/esm/components/Tiles/Styles.js +18 -0
- package/dist/esm/components/Tiles/Styles.js.map +1 -0
- package/dist/esm/components/Tiles/Tiles.d.ts +10 -0
- package/dist/esm/components/Tiles/Tiles.d.ts.map +1 -0
- package/dist/esm/components/Tiles/Tiles.js +21 -0
- package/dist/esm/components/Tiles/Tiles.js.map +1 -0
- package/dist/esm/components/Tiles/index.d.ts +2 -0
- package/dist/esm/components/Tiles/index.d.ts.map +1 -0
- package/dist/esm/components/Tiles/index.js +2 -0
- package/dist/esm/components/Tiles/index.js.map +1 -0
- package/dist/esm/components/TitledText/Styles.d.ts +2 -0
- package/dist/esm/components/TitledText/Styles.d.ts.map +1 -0
- package/dist/esm/components/TitledText/Styles.js +8 -0
- package/dist/esm/components/TitledText/Styles.js.map +1 -0
- package/dist/esm/components/TitledText/TitledText.d.ts +18 -0
- package/dist/esm/components/TitledText/TitledText.d.ts.map +1 -0
- package/dist/esm/components/TitledText/TitledText.js +43 -0
- package/dist/esm/components/TitledText/TitledText.js.map +1 -0
- package/dist/esm/components/TitledText/index.d.ts +2 -0
- package/dist/esm/components/TitledText/index.d.ts.map +1 -0
- package/dist/esm/components/TitledText/index.js +2 -0
- package/dist/esm/components/TitledText/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +8 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +8 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/presentation/shared/MessageDialog.d.ts +35 -0
- package/dist/esm/presentation/shared/MessageDialog.d.ts.map +1 -0
- package/dist/esm/presentation/shared/MessageDialog.js +331 -0
- package/dist/esm/presentation/shared/MessageDialog.js.map +1 -0
- package/dist/esm/presentation/shared/index.d.ts +2 -0
- package/dist/esm/presentation/shared/index.d.ts.map +1 -1
- package/dist/esm/presentation/shared/index.js +1 -0
- package/dist/esm/presentation/shared/index.js.map +1 -1
- package/dist/esm/presentation/stackedCard/content/NoteCard.d.ts +8 -1
- package/dist/esm/presentation/stackedCard/content/NoteCard.d.ts.map +1 -1
- package/dist/esm/presentation/stackedCard/content/NoteCard.js +8 -4
- package/dist/esm/presentation/stackedCard/content/NoteCard.js.map +1 -1
- package/dist/esm/presentation/stackedCard/content/ProjectCard.d.ts +64 -0
- package/dist/esm/presentation/stackedCard/content/ProjectCard.d.ts.map +1 -0
- package/dist/esm/presentation/stackedCard/content/ProjectCard.js +128 -0
- package/dist/esm/presentation/stackedCard/content/ProjectCard.js.map +1 -0
- package/dist/esm/presentation/stackedCard/content/TaskCard.d.ts +64 -2
- package/dist/esm/presentation/stackedCard/content/TaskCard.d.ts.map +1 -1
- package/dist/esm/presentation/stackedCard/content/TaskCard.js +181 -58
- package/dist/esm/presentation/stackedCard/content/TaskCard.js.map +1 -1
- package/dist/esm/presentation/stackedCard/content/index.d.ts +1 -0
- package/dist/esm/presentation/stackedCard/content/index.d.ts.map +1 -1
- package/dist/esm/presentation/stackedCard/content/index.js +1 -0
- package/dist/esm/presentation/stackedCard/content/index.js.map +1 -1
- package/dist/esm/presentation/stackedCard/content/shared.d.ts +30 -0
- package/dist/esm/presentation/stackedCard/content/shared.d.ts.map +1 -1
- package/dist/esm/presentation/stackedCard/content/shared.js +66 -19
- package/dist/esm/presentation/stackedCard/content/shared.js.map +1 -1
- package/dist/esm/presentation/whiteboard/bottomDock.d.ts +30 -7
- package/dist/esm/presentation/whiteboard/bottomDock.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/bottomDock.js +79 -32
- package/dist/esm/presentation/whiteboard/bottomDock.js.map +1 -1
- package/dist/esm/presentation/whiteboard/canvasElements.d.ts +4 -1
- package/dist/esm/presentation/whiteboard/canvasElements.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/canvasElements.js +158 -7
- package/dist/esm/presentation/whiteboard/canvasElements.js.map +1 -1
- package/dist/esm/presentation/whiteboard/inspector.d.ts +35 -1
- package/dist/esm/presentation/whiteboard/inspector.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/inspector.js +170 -68
- package/dist/esm/presentation/whiteboard/inspector.js.map +1 -1
- package/dist/esm/presentation/whiteboard/outline.d.ts +23 -3
- package/dist/esm/presentation/whiteboard/outline.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/outline.js +89 -18
- package/dist/esm/presentation/whiteboard/outline.js.map +1 -1
- package/dist/esm/presentation/whiteboard/projectElements.d.ts +267 -0
- package/dist/esm/presentation/whiteboard/projectElements.d.ts.map +1 -0
- package/dist/esm/presentation/whiteboard/projectElements.js +824 -0
- package/dist/esm/presentation/whiteboard/projectElements.js.map +1 -0
- package/dist/index.js +1490 -738
- 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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { SPACE } from "../LayoutTokens";
|
|
3
|
+
|
|
4
|
+
/** The default `code` mark: a quiet inline chip that keeps the line intact. */
|
|
5
|
+
export const StyledCode = styled.code.withConfig({
|
|
6
|
+
displayName: "Styles__StyledCode",
|
|
7
|
+
componentId: "sc-1fss4z4-0"
|
|
8
|
+
})(["padding:0 ", ";border-radius:", ";background-color:var(--color-theme-300);font-family:\"SFMono-Regular\",Menlo,Consolas,\"Liberation Mono\",monospace;font-size:0.85em;"], "0.25rem", "0.25rem");
|
|
9
|
+
StyledCode.displayName = "StyledCode";
|
|
10
|
+
|
|
11
|
+
/** The default `link` mark: an inline text link inside flowing content. */
|
|
12
|
+
export const StyledLink = styled.a.withConfig({
|
|
13
|
+
displayName: "Styles__StyledLink",
|
|
14
|
+
componentId: "sc-1fss4z4-1"
|
|
15
|
+
})(["color:var(--color-primary);text-decoration:underline var(--color-primary);text-underline-offset:3px;&:hover{text-decoration:none;}"]);
|
|
16
|
+
StyledLink.displayName = "StyledLink";
|
|
17
|
+
|
|
18
|
+
/** The default `list` block; rendered as ul or ol through the `as` prop. */
|
|
19
|
+
export const StyledList = styled.ul.withConfig({
|
|
20
|
+
displayName: "Styles__StyledList",
|
|
21
|
+
componentId: "sc-1fss4z4-2"
|
|
22
|
+
})(["margin:0;padding-left:", ";list-style:", " outside;li + li{margin-top:", ";}"], "1.25rem", _ref => {
|
|
23
|
+
let $ordered = _ref.$ordered;
|
|
24
|
+
return $ordered ? "decimal" : "disc";
|
|
25
|
+
}, SPACE.xs);
|
|
26
|
+
StyledList.displayName = "StyledList";
|
|
27
|
+
//# sourceMappingURL=Styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Styles.js","names":["styled","SPACE","StyledCode","code","withConfig","displayName","componentId","StyledLink","a","StyledList","ul","_ref","$ordered","xs"],"sources":["../../../../src/components/PortableText/Styles.ts"],"sourcesContent":["import styled from \"styled-components\";\nimport { theme } from \"twin.macro\";\n\nimport { SPACE } from \"../LayoutTokens\";\n\n/** The default `code` mark: a quiet inline chip that keeps the line intact. */\nexport const StyledCode = styled.code`\n padding: 0 ${theme(\"spacing.1\")};\n border-radius: ${theme(\"borderRadius.DEFAULT\")};\n background-color: var(--color-theme-300);\n font-family: \"SFMono-Regular\", Menlo, Consolas, \"Liberation Mono\", monospace;\n font-size: 0.85em;\n`;\n\nStyledCode.displayName = \"StyledCode\";\n\n/** The default `link` mark: an inline text link inside flowing content. */\nexport const StyledLink = styled.a`\n color: var(--color-primary);\n text-decoration: underline var(--color-primary);\n text-underline-offset: 3px;\n\n &:hover {\n text-decoration: none;\n }\n`;\n\nStyledLink.displayName = \"StyledLink\";\n\n/** The default `list` block; rendered as ul or ol through the `as` prop. */\nexport const StyledList = styled.ul<{ $ordered: boolean }>`\n margin: 0;\n padding-left: ${theme(\"spacing.5\")};\n list-style: ${({ $ordered }) => ($ordered ? \"decimal\" : \"disc\")} outside;\n\n li + li {\n margin-top: ${SPACE.xs};\n }\n`;\n\nStyledList.displayName = \"StyledList\";\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAGtC,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA,OAAO,MAAMC,UAAU,GAAGF,MAAM,CAACG,IAAI,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,gLACtB,SAAkB,EACd,SAA6B,CAI/C;AAEDJ,UAAU,CAACG,WAAW,GAAG,YAAY;;AAErC;AACA,OAAO,MAAME,UAAU,GAAGP,MAAM,CAACQ,CAAC,CAAAJ,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,0IAQjC;AAEDC,UAAU,CAACF,WAAW,GAAG,YAAY;;AAErC;AACA,OAAO,MAAMI,UAAU,GAAGT,MAAM,CAACU,EAAE,CAAAN,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,qFAEjB,SAAkB,EACpBK,IAAA;EAAA,IAAGC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;EAAA,OAAQA,QAAQ,GAAG,SAAS,GAAG,MAAM;AAAA,CAAC,EAG/CX,KAAK,CAACY,EAAE,CAEzB;AAEDJ,UAAU,CAACJ,WAAW,GAAG,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/PortableText/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/PortableText/index.ts"],"sourcesContent":["export * from \"./PortableText\";\nexport * from \"./renderers\";\nexport * from \"./types\";\n"],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,aAAa;AAC3B,cAAc,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PortableTextBlockRenderer, PortableTextDefaultBlockType, PortableTextDefaultMark, PortableTextMarkRenderer } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* The default renderers for the universal set — everything a client renders
|
|
4
|
+
* without injection, and nothing more: no product element ever lands here.
|
|
5
|
+
* Injected {@link PortableTextComponents} maps take precedence entry by entry.
|
|
6
|
+
*/
|
|
7
|
+
export declare const portableTextDefaultMarkRenderers: Record<PortableTextDefaultMark, PortableTextMarkRenderer>;
|
|
8
|
+
export declare const portableTextDefaultBlockRenderers: Record<PortableTextDefaultBlockType, PortableTextBlockRenderer>;
|
|
9
|
+
//# sourceMappingURL=renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../src/components/PortableText/renderers.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EAKvB,wBAAwB,EAGzB,MAAM,SAAS,CAAC;AAUjB;;;;GAIG;AAEH,eAAO,MAAM,gCAAgC,EAAE,MAAM,CACnD,uBAAuB,EACvB,wBAAwB,CAoBzB,CAAC;AAoBF,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACpD,4BAA4B,EAC5B,yBAAyB,CA6B1B,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyledCode, StyledLink, StyledList } from "./Styles";
|
|
3
|
+
import { Media } from "../Media";
|
|
4
|
+
import { TitledText, titledTextHeadings } from "../TitledText";
|
|
5
|
+
import { Body1 } from "../Typography";
|
|
6
|
+
import { Typography } from "../Typography/Typography";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The default renderers for the universal set — everything a client renders
|
|
10
|
+
* without injection, and nothing more: no product element ever lands here.
|
|
11
|
+
* Injected {@link PortableTextComponents} maps take precedence entry by entry.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const portableTextDefaultMarkRenderers = {
|
|
15
|
+
strong: _ref => {
|
|
16
|
+
let children = _ref.children;
|
|
17
|
+
return /*#__PURE__*/React.createElement("strong", null, children);
|
|
18
|
+
},
|
|
19
|
+
em: _ref2 => {
|
|
20
|
+
let children = _ref2.children;
|
|
21
|
+
return /*#__PURE__*/React.createElement("em", null, children);
|
|
22
|
+
},
|
|
23
|
+
code: _ref3 => {
|
|
24
|
+
let children = _ref3.children;
|
|
25
|
+
return /*#__PURE__*/React.createElement(StyledCode, null, children);
|
|
26
|
+
},
|
|
27
|
+
link: _ref4 => {
|
|
28
|
+
let mark = _ref4.mark,
|
|
29
|
+
children = _ref4.children;
|
|
30
|
+
const href = mark == null ? void 0 : mark.href;
|
|
31
|
+
|
|
32
|
+
// A link mark without an href (authored as a plain string) has nowhere
|
|
33
|
+
// to go — keep the text, skip the anchor.
|
|
34
|
+
if (!href) {
|
|
35
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
36
|
+
}
|
|
37
|
+
return /*#__PURE__*/React.createElement(StyledLink, {
|
|
38
|
+
href: href,
|
|
39
|
+
target: "_blank",
|
|
40
|
+
rel: "noopener noreferrer"
|
|
41
|
+
}, children);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** The semantic wire levels resolve to typography only here, in the renderer. */
|
|
46
|
+
const HEADING_LEVEL_VARIANTS = {
|
|
47
|
+
1: "title1",
|
|
48
|
+
2: "title2",
|
|
49
|
+
3: "header2"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** Heading levels map to the same typography TitledText uses. */
|
|
53
|
+
const HeadingBlock = _ref5 => {
|
|
54
|
+
var _HEADING_LEVEL_VARIAN;
|
|
55
|
+
let block = _ref5.block,
|
|
56
|
+
children = _ref5.children;
|
|
57
|
+
const _ref6 = block,
|
|
58
|
+
level = _ref6.level;
|
|
59
|
+
const Heading = titledTextHeadings[(_HEADING_LEVEL_VARIAN = HEADING_LEVEL_VARIANTS[level]) != null ? _HEADING_LEVEL_VARIAN : "header2"];
|
|
60
|
+
return /*#__PURE__*/React.createElement(Heading, null, children);
|
|
61
|
+
};
|
|
62
|
+
export const portableTextDefaultBlockRenderers = {
|
|
63
|
+
paragraph: _ref7 => {
|
|
64
|
+
let children = _ref7.children;
|
|
65
|
+
return /*#__PURE__*/React.createElement(Body1, null, children);
|
|
66
|
+
},
|
|
67
|
+
heading: HeadingBlock,
|
|
68
|
+
list: _ref8 => {
|
|
69
|
+
let block = _ref8.block,
|
|
70
|
+
children = _ref8.children;
|
|
71
|
+
const ordered = block.style === "number";
|
|
72
|
+
return /*#__PURE__*/React.createElement(StyledList, {
|
|
73
|
+
as: ordered ? "ol" : "ul",
|
|
74
|
+
$ordered: ordered
|
|
75
|
+
}, children);
|
|
76
|
+
},
|
|
77
|
+
"list-item": _ref9 => {
|
|
78
|
+
let children = _ref9.children;
|
|
79
|
+
return /*#__PURE__*/React.createElement(Typography, {
|
|
80
|
+
variant: "Body 1",
|
|
81
|
+
as: "li"
|
|
82
|
+
}, children);
|
|
83
|
+
},
|
|
84
|
+
media: _ref0 => {
|
|
85
|
+
let block = _ref0.block;
|
|
86
|
+
const _ref1 = block,
|
|
87
|
+
src = _ref1.src,
|
|
88
|
+
alt = _ref1.alt,
|
|
89
|
+
variant = _ref1.variant,
|
|
90
|
+
caption = _ref1.caption;
|
|
91
|
+
return /*#__PURE__*/React.createElement(Media, {
|
|
92
|
+
src: src,
|
|
93
|
+
alt: alt,
|
|
94
|
+
variant: variant,
|
|
95
|
+
caption: caption
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
"titled-text": _ref10 => {
|
|
99
|
+
let block = _ref10.block,
|
|
100
|
+
children = _ref10.children;
|
|
101
|
+
const _ref11 = block,
|
|
102
|
+
title = _ref11.title,
|
|
103
|
+
level = _ref11.level;
|
|
104
|
+
return /*#__PURE__*/React.createElement(TitledText, {
|
|
105
|
+
title: title,
|
|
106
|
+
variant: HEADING_LEVEL_VARIANTS[level != null ? level : 3]
|
|
107
|
+
}, children);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.js","names":["React","StyledCode","StyledLink","StyledList","Media","TitledText","titledTextHeadings","Body1","Typography","portableTextDefaultMarkRenderers","strong","_ref","children","createElement","em","_ref2","code","_ref3","link","_ref4","mark","href","Fragment","target","rel","HEADING_LEVEL_VARIANTS","HeadingBlock","_ref5","_HEADING_LEVEL_VARIAN","block","_ref6","level","Heading","portableTextDefaultBlockRenderers","paragraph","_ref7","heading","list","_ref8","ordered","style","as","$ordered","_ref9","variant","media","_ref0","_ref1","src","alt","caption","_ref10","_ref11","title"],"sources":["../../../../src/components/PortableText/renderers.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { StyledCode, StyledLink, StyledList } from \"./Styles\";\nimport {\n PortableTextBlockRenderer,\n PortableTextDefaultBlockType,\n PortableTextDefaultMark,\n PortableTextHeadingBlock,\n PortableTextHeadingLevel,\n PortableTextLinkMark,\n PortableTextListBlock,\n PortableTextMarkRenderer,\n PortableTextMediaBlock,\n PortableTextTitledTextBlock,\n} from \"./types\";\nimport { Media } from \"../Media\";\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/** Heading levels map to the same typography TitledText uses. */\nconst HeadingBlock: PortableTextBlockRenderer = ({ block, children }) => {\n const { level } = block as PortableTextHeadingBlock;\n const Heading =\n titledTextHeadings[HEADING_LEVEL_VARIANTS[level] ?? \"header2\"];\n return <Heading>{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 <StyledList as={ordered ? \"ol\" : \"ul\"} $ordered={ordered}>\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 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={HEADING_LEVEL_VARIANTS[level ?? 3]}>\n {children}\n </TitledText>\n );\n },\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,UAAU,EAAEC,UAAU,EAAEC,UAAU,QAAQ,UAAU;AAa7D,SAASC,KAAK,QAAQ,UAAU;AAChC,SACEC,UAAU,EAEVC,kBAAkB,QACb,eAAe;AACtB,SAASC,KAAK,QAAQ,eAAe;AACrC,SAASC,UAAU,QAAQ,0BAA0B;;AAErD;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,gCAGZ,GAAG;EACFC,MAAM,E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AAA,CAACT,KAAK;MAAC4C,GAAG,EAAEA,GAAI;MAACC,GAAG,EAAEA,GAAI;MAACL,OAAO,EAAEA,OAAQ;MAACM,OAAO,EAAEA;IAAQ,CAAE,CAAC;EAC1E,CAAC;EACD,aAAa,EAAEC,MAAA,IAAyB;IAAA,IAAtBtB,KAAK,GAAAsB,MAAA,CAALtB,KAAK;MAAEjB,QAAQ,GAAAuC,MAAA,CAARvC,QAAQ;IAC/B,MAAAwC,MAAA,GAAyBvB,KAAK;MAAtBwB,KAAK,GAAAD,MAAA,CAALC,KAAK;MAAEtB,KAAK,GAAAqB,MAAA,CAALrB,KAAK;IACpB,oBACE/B,KAAA,CAAAa,aAAA,CAACR,UAAU;MAACgD,KAAK,EAAEA,KAAM;MAACT,OAAO,EAAEnB,sBAAsB,CAACM,KAAK,WAALA,KAAK,GAAI,CAAC;IAAE,GACnEnB,QACS,CAAC;EAEjB;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Portable Text envelope — the general content contract for structured,
|
|
4
|
+
* renderer-independent content (in-app messages, help, changelogs).
|
|
5
|
+
*
|
|
6
|
+
* The design system owns this envelope and the universal default set below.
|
|
7
|
+
* It never hardcodes a product element: concrete elements (callout,
|
|
8
|
+
* button-reference, doc-link, …) are defined in the application catalog and
|
|
9
|
+
* injected into the Portable Text engine through {@link PortableTextComponents}.
|
|
10
|
+
* See README.md next to this file for the full contract.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A mark with data. Parameterless marks travel as plain strings ("strong");
|
|
14
|
+
* marks that need data travel as objects discriminated by `type`.
|
|
15
|
+
*/
|
|
16
|
+
export interface PortableTextMarkObject {
|
|
17
|
+
type: string;
|
|
18
|
+
[data: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** The one default mark that carries data. */
|
|
21
|
+
export interface PortableTextLinkMark extends PortableTextMarkObject {
|
|
22
|
+
type: "link";
|
|
23
|
+
href: string;
|
|
24
|
+
}
|
|
25
|
+
export type PortableTextMark = string | PortableTextMarkObject;
|
|
26
|
+
/** The leaf of every text run: a piece of text plus the marks wrapping it. */
|
|
27
|
+
export interface PortableTextSpan {
|
|
28
|
+
text: string;
|
|
29
|
+
marks?: PortableTextMark[];
|
|
30
|
+
}
|
|
31
|
+
/** Marks every client understands without injection. */
|
|
32
|
+
export declare const PORTABLE_TEXT_DEFAULT_MARKS: readonly ["strong", "em", "code", "link"];
|
|
33
|
+
export type PortableTextDefaultMark = (typeof PORTABLE_TEXT_DEFAULT_MARKS)[number];
|
|
34
|
+
export interface PortableTextParagraphBlock {
|
|
35
|
+
type: "paragraph";
|
|
36
|
+
children: PortableTextSpan[];
|
|
37
|
+
}
|
|
38
|
+
/** 1 maps to Title1, 2 to Title2, 3 to Header2 typography. */
|
|
39
|
+
export type PortableTextHeadingLevel = 1 | 2 | 3;
|
|
40
|
+
export interface PortableTextHeadingBlock {
|
|
41
|
+
type: "heading";
|
|
42
|
+
level: PortableTextHeadingLevel;
|
|
43
|
+
children: PortableTextSpan[];
|
|
44
|
+
}
|
|
45
|
+
export type PortableTextListStyle = "bullet" | "number";
|
|
46
|
+
export interface PortableTextListItemBlock {
|
|
47
|
+
type: "list-item";
|
|
48
|
+
children: PortableTextSpan[];
|
|
49
|
+
}
|
|
50
|
+
export interface PortableTextListBlock {
|
|
51
|
+
type: "list";
|
|
52
|
+
style?: PortableTextListStyle;
|
|
53
|
+
children: PortableTextListItemBlock[];
|
|
54
|
+
}
|
|
55
|
+
/** Screenshots render framed (border, no shadow); illustrations render flat. */
|
|
56
|
+
export type PortableTextMediaVariant = "screenshot" | "illustration";
|
|
57
|
+
export interface PortableTextMediaBlock {
|
|
58
|
+
type: "media";
|
|
59
|
+
src: string;
|
|
60
|
+
alt?: string;
|
|
61
|
+
variant?: PortableTextMediaVariant;
|
|
62
|
+
caption?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface PortableTextTitledTextBlock {
|
|
65
|
+
type: "titled-text";
|
|
66
|
+
/**
|
|
67
|
+
* Same semantic scale as `heading` — 1, 2 or 3 (the default) — so the wire
|
|
68
|
+
* format never encodes a typography name. How a level looks is the
|
|
69
|
+
* renderer's business.
|
|
70
|
+
*/
|
|
71
|
+
level?: PortableTextHeadingLevel;
|
|
72
|
+
title: string;
|
|
73
|
+
content?: PortableTextNode[];
|
|
74
|
+
}
|
|
75
|
+
export type PortableTextBlock = PortableTextParagraphBlock | PortableTextHeadingBlock | PortableTextListBlock | PortableTextMediaBlock | PortableTextTitledTextBlock;
|
|
76
|
+
/**
|
|
77
|
+
* Derived from the union's discriminators, so adding a block to the union
|
|
78
|
+
* without a renderer entry is a compile error, never silent drift.
|
|
79
|
+
*/
|
|
80
|
+
export type PortableTextDefaultBlockType = (PortableTextBlock | PortableTextListItemBlock)["type"];
|
|
81
|
+
/** Blocks every client understands without injection. */
|
|
82
|
+
export declare const PORTABLE_TEXT_DEFAULT_BLOCKS: readonly PortableTextDefaultBlockType[];
|
|
83
|
+
/**
|
|
84
|
+
* An embedded component the envelope does not interpret: `_type` names an
|
|
85
|
+
* application-catalog element, everything else is that element's data. An
|
|
86
|
+
* object whose `_type` has no injected renderer renders nothing and is logged.
|
|
87
|
+
*/
|
|
88
|
+
export interface PortableTextObjectNode {
|
|
89
|
+
type: "object";
|
|
90
|
+
_type: string;
|
|
91
|
+
[data: string]: unknown;
|
|
92
|
+
}
|
|
93
|
+
export type PortableTextNode = PortableTextBlock | PortableTextObjectNode;
|
|
94
|
+
/** The root of a message body: what an API returns under `content`. */
|
|
95
|
+
export type PortableTextContent = PortableTextNode[];
|
|
96
|
+
export interface PortableTextMarkRendererProps<TMark extends PortableTextMarkObject = PortableTextMarkObject> {
|
|
97
|
+
/** Present for object marks; absent when the mark is a plain string. */
|
|
98
|
+
mark?: TMark;
|
|
99
|
+
children: ReactNode;
|
|
100
|
+
}
|
|
101
|
+
export type PortableTextMarkRenderer<TMark extends PortableTextMarkObject = PortableTextMarkObject> = ComponentType<PortableTextMarkRendererProps<TMark>>;
|
|
102
|
+
export interface PortableTextObjectRendererProps<TNode extends PortableTextObjectNode = PortableTextObjectNode> {
|
|
103
|
+
node: TNode;
|
|
104
|
+
/** The object's nested `content`, already rendered by the engine. */
|
|
105
|
+
children?: ReactNode;
|
|
106
|
+
}
|
|
107
|
+
export type PortableTextObjectRenderer<TNode extends PortableTextObjectNode = PortableTextObjectNode> = ComponentType<PortableTextObjectRendererProps<TNode>>;
|
|
108
|
+
export interface PortableTextBlockRendererProps<TBlock extends PortableTextBlock = PortableTextBlock> {
|
|
109
|
+
block: TBlock;
|
|
110
|
+
/** The block's rendered children/content, when it has any. */
|
|
111
|
+
children?: ReactNode;
|
|
112
|
+
}
|
|
113
|
+
export type PortableTextBlockRenderer<TBlock extends PortableTextBlock = PortableTextBlock> = ComponentType<PortableTextBlockRendererProps<TBlock>>;
|
|
114
|
+
export type PortableTextUnknownKind = "block" | "mark" | "object";
|
|
115
|
+
/**
|
|
116
|
+
* Called once per unknown type instead of rendering it, so content written
|
|
117
|
+
* for newer clients degrades silently on older ones.
|
|
118
|
+
*/
|
|
119
|
+
export type PortableTextUnknownTypeHandler = (kind: PortableTextUnknownKind, type: string) => void;
|
|
120
|
+
/**
|
|
121
|
+
* What an application injects into the Portable Text engine: renderers for
|
|
122
|
+
* its catalog marks and objects, optional overrides for the default blocks,
|
|
123
|
+
* and the unknown-type hook.
|
|
124
|
+
*/
|
|
125
|
+
export interface PortableTextComponents {
|
|
126
|
+
marks?: Record<string, PortableTextMarkRenderer>;
|
|
127
|
+
objects?: Record<string, PortableTextObjectRenderer>;
|
|
128
|
+
blocks?: Partial<Record<PortableTextDefaultBlockType, PortableTextBlockRenderer>>;
|
|
129
|
+
onUnknownType?: PortableTextUnknownTypeHandler;
|
|
130
|
+
}
|
|
131
|
+
export declare const isPortableTextSpan: (value: unknown) => value is PortableTextSpan;
|
|
132
|
+
export declare const isPortableTextObjectNode: (value: unknown) => value is PortableTextObjectNode;
|
|
133
|
+
/**
|
|
134
|
+
* A block is any non-object node with a string `type`. Unknown block types
|
|
135
|
+
* stay valid on purpose — they render nothing on clients that predate them.
|
|
136
|
+
* Known types are held to their shape, so a serializer bug (a paragraph
|
|
137
|
+
* without `children`, a list of non-nodes) fails here instead of at render.
|
|
138
|
+
*/
|
|
139
|
+
export declare const isPortableTextBlock: (value: unknown) => value is PortableTextBlock;
|
|
140
|
+
export declare const isPortableTextContent: (value: unknown) => value is PortableTextContent;
|
|
141
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/PortableText/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjD;;;;;;;;;GASG;AAIH;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED,8CAA8C;AAC9C,MAAM,WAAW,oBAAqB,SAAQ,sBAAsB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,sBAAsB,CAAC;AAE/D,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED,wDAAwD;AACxD,eAAO,MAAM,2BAA2B,2CAK9B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC;AAI/C,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED,8DAA8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;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,CAC3C,IAAI,EAAE,uBAAuB,EAC7B,IAAI,EAAE,MAAM,KACT,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IACrD,MAAM,CAAC,EAAE,OAAO,CACd,MAAM,CAAC,4BAA4B,EAAE,yBAAyB,CAAC,CAChE,CAAC;IACF,aAAa,CAAC,EAAE,8BAA8B,CAAC;CAChD;AAOD,eAAO,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,gBACV,CAAC;AAEpD,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,KAAK,IAAI,sBACmE,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,OAAO,KACb,KAAK,IAAI,iBAgCX,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,OAAO,OAAO,KACb,KAAK,IAAI,mBAIT,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable Text envelope — the general content contract for structured,
|
|
3
|
+
* renderer-independent content (in-app messages, help, changelogs).
|
|
4
|
+
*
|
|
5
|
+
* The design system owns this envelope and the universal default set below.
|
|
6
|
+
* It never hardcodes a product element: concrete elements (callout,
|
|
7
|
+
* button-reference, doc-link, …) are defined in the application catalog and
|
|
8
|
+
* injected into the Portable Text engine through {@link PortableTextComponents}.
|
|
9
|
+
* See README.md next to this file for the full contract.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/* ---- Spans and marks ------------------------------------------------- */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A mark with data. Parameterless marks travel as plain strings ("strong");
|
|
16
|
+
* marks that need data travel as objects discriminated by `type`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** The one default mark that carries data. */
|
|
20
|
+
|
|
21
|
+
/** The leaf of every text run: a piece of text plus the marks wrapping it. */
|
|
22
|
+
|
|
23
|
+
/** Marks every client understands without injection. */
|
|
24
|
+
export const PORTABLE_TEXT_DEFAULT_MARKS = ["strong", "em", "code", "link"];
|
|
25
|
+
|
|
26
|
+
/* ---- Blocks ----------------------------------------------------------- */
|
|
27
|
+
|
|
28
|
+
/** 1 maps to Title1, 2 to Title2, 3 to Header2 typography. */
|
|
29
|
+
|
|
30
|
+
/** Screenshots render framed (border, no shadow); illustrations render flat. */
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Derived from the union's discriminators, so adding a block to the union
|
|
34
|
+
* without a renderer entry is a compile error, never silent drift.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
// A Record so the compiler checks the list against the union in both
|
|
38
|
+
// directions: a missing and a stray key each fail to build.
|
|
39
|
+
const DEFAULT_BLOCK_TYPES = {
|
|
40
|
+
paragraph: true,
|
|
41
|
+
heading: true,
|
|
42
|
+
list: true,
|
|
43
|
+
"list-item": true,
|
|
44
|
+
media: true,
|
|
45
|
+
"titled-text": true
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Blocks every client understands without injection. */
|
|
49
|
+
export const PORTABLE_TEXT_DEFAULT_BLOCKS = Object.keys(DEFAULT_BLOCK_TYPES);
|
|
50
|
+
|
|
51
|
+
/* ---- Objects ----------------------------------------------------------- */
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* An embedded component the envelope does not interpret: `_type` names an
|
|
55
|
+
* application-catalog element, everything else is that element's data. An
|
|
56
|
+
* object whose `_type` has no injected renderer renders nothing and is logged.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/** The root of a message body: what an API returns under `content`. */
|
|
60
|
+
|
|
61
|
+
/* ---- Injection contract ------------------------------------------------ */
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Called once per unknown type instead of rendering it, so content written
|
|
65
|
+
* for newer clients degrades silently on older ones.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* What an application injects into the Portable Text engine: renderers for
|
|
70
|
+
* its catalog marks and objects, optional overrides for the default blocks,
|
|
71
|
+
* and the unknown-type hook.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/* ---- Runtime guards ----------------------------------------------------- */
|
|
75
|
+
|
|
76
|
+
const isRecord = value => typeof value === "object" && value !== null;
|
|
77
|
+
export const isPortableTextSpan = value => isRecord(value) && typeof value.text === "string";
|
|
78
|
+
export const isPortableTextObjectNode = value => isRecord(value) && value.type === "object" && typeof value._type === "string";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A block is any non-object node with a string `type`. Unknown block types
|
|
82
|
+
* stay valid on purpose — they render nothing on clients that predate them.
|
|
83
|
+
* Known types are held to their shape, so a serializer bug (a paragraph
|
|
84
|
+
* without `children`, a list of non-nodes) fails here instead of at render.
|
|
85
|
+
*/
|
|
86
|
+
export const isPortableTextBlock = value => {
|
|
87
|
+
if (!isRecord(value) || typeof value.type !== "string" || value.type === "object") {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
switch (value.type) {
|
|
91
|
+
case "paragraph":
|
|
92
|
+
case "heading":
|
|
93
|
+
case "list-item":
|
|
94
|
+
return Array.isArray(value.children) && value.children.every(isPortableTextSpan);
|
|
95
|
+
case "list":
|
|
96
|
+
return Array.isArray(value.children) && value.children.every(isPortableTextBlock);
|
|
97
|
+
case "media":
|
|
98
|
+
return typeof value.src === "string";
|
|
99
|
+
case "titled-text":
|
|
100
|
+
return typeof value.title === "string" && (value.content === undefined || isPortableTextContent(value.content));
|
|
101
|
+
default:
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
export const isPortableTextContent = value => Array.isArray(value) && value.every(node => isPortableTextBlock(node) || isPortableTextObjectNode(node));
|
|
106
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":["PORTABLE_TEXT_DEFAULT_MARKS","DEFAULT_BLOCK_TYPES","paragraph","heading","list","media","PORTABLE_TEXT_DEFAULT_BLOCKS","Object","keys","isRecord","value","isPortableTextSpan","text","isPortableTextObjectNode","type","_type","isPortableTextBlock","Array","isArray","children","every","src","title","content","undefined","isPortableTextContent","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 children: PortableTextSpan[];\n}\n\nexport type PortableTextListStyle = \"bullet\" | \"number\";\n\nexport interface PortableTextListItemBlock {\n type: \"list-item\";\n children: PortableTextSpan[];\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 PortableTextMediaVariant = \"screenshot\" | \"illustration\";\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 type PortableTextBlock =\n | PortableTextParagraphBlock\n | PortableTextHeadingBlock\n | PortableTextListBlock\n | PortableTextMediaBlock\n | PortableTextTitledTextBlock;\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};\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\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 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 case \"heading\":\n case \"list-item\":\n return (\n Array.isArray(value.children) &&\n value.children.every(isPortableTextSpan)\n );\n case \"list\":\n return (\n Array.isArray(value.children) &&\n value.children.every(isPortableTextBlock)\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 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;;AAMA;AACA,OAAO,MAAMA,2BAA2B,GAAG,CACzC,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,MAAM,CACE;;AAKV;;AAOA;;AAsBA;;AA8BA;AACA;AACA;AACA;;AAMA;AACA;AACA,MAAMC,mBAA+D,GAAG;EACtEC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAE,IAAI;EACbC,IAA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E7C,KAAK,OAAO;MACV,OAAO,OAAON,KAAK,CAACW,GAAG,KAAK,QAAQ;IACtC,KAAK,aAAa;MAChB,OACE,OAAOX,KAAK,CAACY,KAAK,KAAK,QAAQ,KAC9BZ,KAAK,CAACa,OAAO,KAAKC,SAAS,IAAIC,qBAAqB,CAACf,KAAK,CAACa,OAAO,CAAC,CAAC;IAEzE;MACE,OAAO,IAAI;EACf;AACF,CAAC;AAED,OAAO,MAAME,qBAAqB,GAChCf,KAAc,IAEdO,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,IACpBA,KAAK,CAACU,KAAK,CACRM,IAAI,IAAKV,mBAAmB,CAACU,IAAI,CAAC,IAAIb,wBAAwB,CAACa,IAAI,CACtE,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test.d.ts","sourceRoot":"","sources":["../../../../src/components/PortableText/types.test.ts"],"names":[],"mappings":""}
|