@cntrl-site/sdk-nextjs 1.11.16 → 1.11.17
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/cntrl-site-sdk-nextjs-1.9.125.tgz +0 -0
- package/lib/components/StructuredBlockItem/StructuredTable/StructuredTable.js +19 -6
- package/package.json +2 -2
- package/src/components/StructuredBlockItem/StructuredTable/StructuredTable.tsx +31 -16
- package/src/components/StructuredContent/StructuredContent.test.tsx +20 -1
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/modules.xml +0 -8
- package/.idea/sdk-nextjs.iml +0 -12
- package/.idea/vcs.xml +0 -6
|
Binary file
|
|
@@ -37,10 +37,12 @@ function convertCells(block, layouts) {
|
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* A table of one of three kinds, as served: its cells rich text set, spaced above and below and
|
|
40
|
-
* lined in the styles it comes with, their ranges styled over them, each column
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* lined in the styles it comes with, their ranges styled over them, each column padded on either
|
|
41
|
+
* side as its own values say. Cells draw a heading row over a grid; rows draw every row plain, the
|
|
42
|
+
* two fills alternating from the first; lines draw the heading and a line between each pair of rows
|
|
43
|
+
* only. The table is drawn in a box, which grows out past its columns. On each layout it fills the
|
|
44
|
+
* box, each column its share of it; or it is as wide as its columns, each as wide as it is set, and
|
|
45
|
+
* scrolls sideways inside the box where it is wider than that.
|
|
44
46
|
*/
|
|
45
47
|
const StructuredTable = ({ block }) => {
|
|
46
48
|
const reactId = (0, react_1.useId)();
|
|
@@ -53,11 +55,14 @@ const StructuredTable = ({ block }) => {
|
|
|
53
55
|
const Heading = headingAsRow ? 'td' : 'th';
|
|
54
56
|
const table = `.structured-table-${block.id}`;
|
|
55
57
|
const box = `.structured-table-box-${block.id}`;
|
|
58
|
+
const scroller = `.structured-table-scroller-${block.id}`;
|
|
56
59
|
const cells = `${table} th, ${table} td`;
|
|
57
60
|
const cellContent = (cell) => content.get(cell.id);
|
|
58
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `structured-table-box-${block.id}`, children: (0, jsx_runtime_1.jsxs)("table", { ref: setRef, className: `structured-table-${block.id}`, children: [(0, jsx_runtime_1.jsx)("colgroup", { children: header.map((_, col) => (0, jsx_runtime_1.jsx)("col", {}, col)) }), (0, jsx_runtime_1.jsx)("thead", { className: `structured-table-heading-${block.id}`, children: (0, jsx_runtime_1.jsx)("tr", { children: header.map(cell => (0, jsx_runtime_1.jsx)(Heading, { children: cellContent(cell) }, cell.id)) }) }), (0, jsx_runtime_1.jsx)("tbody", { className: `structured-table-body-${block.id}`, children: rows.map((row, index) => { var _a, _b; return (0, jsx_runtime_1.jsx)("tr", { children: row.map(cell => (0, jsx_runtime_1.jsx)("td", { children: cellContent(cell) }, cell.id)) }, (_b = (_a = row[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : index); }) })] }) }), listStyles && (0, jsx_runtime_1.jsx)(style_1.default, { id: RichTextConverter_1.LIST_STYLES_ID, children: listStyles }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: `${reactId}-table-${block.id}`, children: [rangeStyles, `
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `structured-table-box-${block.id}`, children: (0, jsx_runtime_1.jsx)("div", { className: `structured-table-scroller-${block.id}`, children: (0, jsx_runtime_1.jsxs)("table", { ref: setRef, className: `structured-table-${block.id}`, children: [(0, jsx_runtime_1.jsx)("colgroup", { children: header.map((_, col) => (0, jsx_runtime_1.jsx)("col", {}, col)) }), (0, jsx_runtime_1.jsx)("thead", { className: `structured-table-heading-${block.id}`, children: (0, jsx_runtime_1.jsx)("tr", { children: header.map(cell => (0, jsx_runtime_1.jsx)(Heading, { children: cellContent(cell) }, cell.id)) }) }), (0, jsx_runtime_1.jsx)("tbody", { className: `structured-table-body-${block.id}`, children: rows.map((row, index) => { var _a, _b; return (0, jsx_runtime_1.jsx)("tr", { children: row.map(cell => (0, jsx_runtime_1.jsx)("td", { children: cellContent(cell) }, cell.id)) }, (_b = (_a = row[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : index); }) })] }) }) }), listStyles && (0, jsx_runtime_1.jsx)(style_1.default, { id: RichTextConverter_1.LIST_STYLES_ID, children: listStyles }), (0, jsx_runtime_1.jsxs)(style_1.default, { id: `${reactId}-table-${block.id}`, children: [rangeStyles, `
|
|
62
|
+
${scroller} {
|
|
63
|
+
overflow-y: hidden;
|
|
64
|
+
}
|
|
59
65
|
${table} {
|
|
60
|
-
width: 100%;
|
|
61
66
|
table-layout: fixed;
|
|
62
67
|
border-collapse: collapse;
|
|
63
68
|
}
|
|
@@ -73,8 +78,16 @@ const StructuredTable = ({ block }) => {
|
|
|
73
78
|
${(0, sdk_1.getLayoutStyles)(layouts, [block.layoutParams], ([layoutParams], exemplary) => {
|
|
74
79
|
const border = (0, vw_1.vw)(BORDER_PX / exemplary);
|
|
75
80
|
const fill = (selector, color) => (color ? (0, textStylesRule_1.colorRule)(selector, 'background-color', color) : '');
|
|
81
|
+
// as wide as its columns where it scrolls, served with that width; its box's width where it fills it
|
|
82
|
+
const isScrolling = layoutParams.sizing === 'scroll' && layoutParams.tableWidth !== undefined;
|
|
76
83
|
return (`
|
|
77
84
|
${(0, textStylesRule_1.boxRule)(box, layoutParams)}
|
|
85
|
+
${scroller} {
|
|
86
|
+
overflow-x: ${isScrolling ? 'auto' : 'visible'};
|
|
87
|
+
}
|
|
88
|
+
${table} {
|
|
89
|
+
width: ${isScrolling ? (0, vw_1.vw)(layoutParams.tableWidth) : '100%'};
|
|
90
|
+
}
|
|
78
91
|
${(0, textStylesRule_1.textStylesRule)(table, layoutParams)}
|
|
79
92
|
${cells} {
|
|
80
93
|
padding-top: ${(0, vw_1.vw)(layoutParams.cellPaddingTop)};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.17",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"author": "arsen@momdesign.nyc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@cntrl-site/color": "^1.0.0",
|
|
33
33
|
"@cntrl-site/components": "^1.0.117",
|
|
34
34
|
"@cntrl-site/effects": "^1.4.2",
|
|
35
|
-
"@cntrl-site/sdk": "^1.29.
|
|
35
|
+
"@cntrl-site/sdk": "^1.29.13",
|
|
36
36
|
"@types/vimeo__player": "^2.18.0",
|
|
37
37
|
"@vimeo/player": "^2.25.0",
|
|
38
38
|
"franc-min": "^5.0.0",
|
|
@@ -35,10 +35,12 @@ function convertCells(block: TableStructuredBlock, layouts: Layout[]): { cells:
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* A table of one of three kinds, as served: its cells rich text set, spaced above and below and
|
|
38
|
-
* lined in the styles it comes with, their ranges styled over them, each column
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* lined in the styles it comes with, their ranges styled over them, each column padded on either
|
|
39
|
+
* side as its own values say. Cells draw a heading row over a grid; rows draw every row plain, the
|
|
40
|
+
* two fills alternating from the first; lines draw the heading and a line between each pair of rows
|
|
41
|
+
* only. The table is drawn in a box, which grows out past its columns. On each layout it fills the
|
|
42
|
+
* box, each column its share of it; or it is as wide as its columns, each as wide as it is set, and
|
|
43
|
+
* scrolls sideways inside the box where it is wider than that.
|
|
42
44
|
*/
|
|
43
45
|
export const StructuredTable: FC<StructuredBlockItemProps<TableStructuredBlock>> = ({ block }) => {
|
|
44
46
|
const reactId = useId();
|
|
@@ -51,29 +53,34 @@ export const StructuredTable: FC<StructuredBlockItemProps<TableStructuredBlock>>
|
|
|
51
53
|
const Heading = headingAsRow ? 'td' : 'th';
|
|
52
54
|
const table = `.structured-table-${block.id}`;
|
|
53
55
|
const box = `.structured-table-box-${block.id}`;
|
|
56
|
+
const scroller = `.structured-table-scroller-${block.id}`;
|
|
54
57
|
const cells = `${table} th, ${table} td`;
|
|
55
58
|
const cellContent = (cell: StructuredBlockTableCell) => content.get(cell.id);
|
|
56
59
|
return (
|
|
57
60
|
<>
|
|
58
61
|
<div className={`structured-table-box-${block.id}`}>
|
|
59
|
-
<
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
<div className={`structured-table-scroller-${block.id}`}>
|
|
63
|
+
<table ref={setRef} className={`structured-table-${block.id}`}>
|
|
64
|
+
<colgroup>
|
|
65
|
+
{header.map((_, col) => <col key={col} />)}
|
|
66
|
+
</colgroup>
|
|
67
|
+
<thead className={`structured-table-heading-${block.id}`}>
|
|
68
|
+
<tr>{header.map(cell => <Heading key={cell.id}>{cellContent(cell)}</Heading>)}</tr>
|
|
69
|
+
</thead>
|
|
70
|
+
<tbody className={`structured-table-body-${block.id}`}>
|
|
71
|
+
{rows.map((row, index) => <tr key={row[0]?.id ?? index}>{row.map(cell => <td key={cell.id}>{cellContent(cell)}</td>)}</tr>)}
|
|
72
|
+
</tbody>
|
|
73
|
+
</table>
|
|
74
|
+
</div>
|
|
70
75
|
</div>
|
|
71
76
|
{listStyles && <JSXStyle id={LIST_STYLES_ID}>{listStyles}</JSXStyle>}
|
|
72
77
|
<JSXStyle id={`${reactId}-table-${block.id}`}>
|
|
73
78
|
{rangeStyles}
|
|
74
79
|
{`
|
|
80
|
+
${scroller} {
|
|
81
|
+
overflow-y: hidden;
|
|
82
|
+
}
|
|
75
83
|
${table} {
|
|
76
|
-
width: 100%;
|
|
77
84
|
table-layout: fixed;
|
|
78
85
|
border-collapse: collapse;
|
|
79
86
|
}
|
|
@@ -89,8 +96,16 @@ export const StructuredTable: FC<StructuredBlockItemProps<TableStructuredBlock>>
|
|
|
89
96
|
${getLayoutStyles(layouts, [block.layoutParams], ([layoutParams], exemplary) => {
|
|
90
97
|
const border = vw(BORDER_PX / exemplary);
|
|
91
98
|
const fill = (selector: string, color: string | undefined) => (color ? colorRule(selector, 'background-color', color) : '');
|
|
99
|
+
// as wide as its columns where it scrolls, served with that width; its box's width where it fills it
|
|
100
|
+
const isScrolling = layoutParams.sizing === 'scroll' && layoutParams.tableWidth !== undefined;
|
|
92
101
|
return (`
|
|
93
102
|
${boxRule(box, layoutParams)}
|
|
103
|
+
${scroller} {
|
|
104
|
+
overflow-x: ${isScrolling ? 'auto' : 'visible'};
|
|
105
|
+
}
|
|
106
|
+
${table} {
|
|
107
|
+
width: ${isScrolling ? vw(layoutParams.tableWidth) : '100%'};
|
|
108
|
+
}
|
|
94
109
|
${textStylesRule(table, layoutParams)}
|
|
95
110
|
${cells} {
|
|
96
111
|
padding-top: ${vw(layoutParams.cellPaddingTop)};
|
|
@@ -273,6 +273,25 @@ describe('StructuredContent', () => {
|
|
|
273
273
|
expect(css()).toMatch(/\.structured-table-body-table \{\s*background-color: oklch/);
|
|
274
274
|
});
|
|
275
275
|
|
|
276
|
+
it('draws a table filling its box on one layout and, on another, as wide as its columns and scrolling sideways inside its box, each column its share of that', () => {
|
|
277
|
+
const scrolled = {
|
|
278
|
+
...block(StructuredBlockType.Table, 'scrolled', { kind: 'cells', ...tableContent('scrolled') }, tableCells),
|
|
279
|
+
layoutParams: {
|
|
280
|
+
desktop: tableCells,
|
|
281
|
+
mobile: { ...tableCells, sizing: 'scroll', tableWidth: 1.5 }
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
draw({ ...section(false), structuredContent: [scrolled] } as Section);
|
|
285
|
+
expect(css()).toMatch(/\.structured-table-scroller-scrolled \{\s*overflow-x: visible;\s*\}\s*\.structured-table-scrolled \{\s*width: 100%;/);
|
|
286
|
+
expect(css()).toMatch(/\.structured-table-scroller-scrolled \{\s*overflow-x: auto;\s*\}\s*\.structured-table-scrolled \{\s*width: 150vw;/);
|
|
287
|
+
expect(css()).toMatch(/\.structured-table-scrolled col:nth-child\(1\) \{\s*width: 60%;/);
|
|
288
|
+
expect(css()).toMatch(/\.structured-table-scrolled col:nth-child\(2\) \{\s*width: 40%;/);
|
|
289
|
+
// set to scroll with no width of its own, it fills its box
|
|
290
|
+
const unsized = { ...scrolled, id: 'unsized', layoutParams: { desktop: { ...tableCells, sizing: 'scroll' }, mobile: tableCells } };
|
|
291
|
+
draw({ ...section(false), structuredContent: [unsized] } as Section);
|
|
292
|
+
expect(css()).not.toMatch(/\.structured-table-scroller-unsized \{\s*overflow-x: auto;/);
|
|
293
|
+
});
|
|
294
|
+
|
|
276
295
|
it('draws a table in its box, its sides grown out past the columns the table stays on, filled and rounded', () => {
|
|
277
296
|
const boxed = block(StructuredBlockType.Table, 'boxed', { kind: 'rows', ...tableContent('boxed') }, {
|
|
278
297
|
...tableCells,
|
|
@@ -284,7 +303,7 @@ describe('StructuredContent', () => {
|
|
|
284
303
|
boxRadius: 0.005
|
|
285
304
|
});
|
|
286
305
|
const { container } = draw({ ...section(false), structuredContent: [boxed] } as Section);
|
|
287
|
-
expect(container.querySelector('.structured-table-box-boxed > .structured-table-boxed')).not.toBeNull();
|
|
306
|
+
expect(container.querySelector('.structured-table-box-boxed > .structured-table-scroller-boxed > .structured-table-boxed')).not.toBeNull();
|
|
288
307
|
expect(css()).toMatch(/\.structured-table-box-boxed \{[^}]*padding: 1vw 2vw 1vw 2vw;[^}]*margin: 0 -2vw 0 -2vw;[^}]*border-radius: 0\.5vw;/);
|
|
289
308
|
// a box with no turn of its own is drawn upright on every layout, whatever another layout turns it by
|
|
290
309
|
expect(css()).toMatch(/\.structured-table-box-boxed \{[^}]*rotate: none;/);
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/sdk-nextjs.iml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|