Skip to content

Commit e7ab6a0

Browse files
Merge branch 'develop' into change/upgradedToReact18-CMEM-6639
# Conflicts: # src/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.tsx
2 parents f8edf61 + f2e85ba commit e7ab6a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+705
-66
lines changed

.github/workflows/create-release-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@main
2323
- uses: actions/setup-node@main
2424
with:
25-
node-version: "18"
25+
node-version: "lts/krypton"
2626
- name: Check and save dispatched branch
2727
id: dispatched-branch
2828
run: |

.github/workflows/deployment-storybook.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ on:
55
paths:
66
- "src/**"
77
- ".storybook/**"
8+
- ".github/workflows/deployment-storybook.yml"
89
- "index.ts"
10+
- package.json
911
- yarn.lock
1012
push:
1113
branches:
1214
- "develop"
1315
paths:
1416
- "src/**"
1517
- ".storybook/**"
18+
- ".github/workflows/deployment-storybook.yml"
1619
- "index.ts"
20+
- package.json
1721
- yarn.lock
1822

1923
jobs:
@@ -33,7 +37,7 @@ jobs:
3337
git log --oneline -1
3438
- uses: actions/setup-node@main
3539
with:
36-
node-version: "18"
40+
node-version: "lts/krypton"
3741
- name: Install dependencies
3842
run: yarn install
3943
- name: Create jest results

.github/workflows/publish-featurefix-prerelease.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
git config user.email "${{ github.actor }}@users.noreply.github.com"
4343
- uses: actions/setup-node@main
4444
with:
45-
node-version: "18"
45+
node-version: "lts/krypton"
4646
- name: Create pre-release version number
4747
run: |
4848
preid=$(echo ${{ steps.branch-name.outputs.current_branch }} | tr '[:upper:]' '[:lower:]' | sed 's=[^[:alnum:][:space:]"]==g')

.github/workflows/publish-final-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
git config user.email "${{ github.actor }}@users.noreply.github.com"
4444
- uses: actions/setup-node@main
4545
with:
46-
node-version: "18"
46+
node-version: "lts/krypton"
4747
- name: Get version
4848
id: package-version
4949
run: echo "version=$(node -p -e "require('./package.json').version.split('-').shift()")" >> $GITHUB_OUTPUT

.github/workflows/publish-release-candidate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
git config user.email "${{ github.actor }}@users.noreply.github.com"
4040
- uses: actions/setup-node@main
4141
with:
42-
node-version: "18"
42+
node-version: "lts/krypton"
4343
- name: Create release candidate version number
4444
run: |
4545
preid="rc"

.github/workflows/push-tagged-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
ref: ${{ inputs.ref }}
3737
- uses: actions/setup-node@main
3838
with:
39-
node-version: "18"
39+
node-version: "lts/krypton"
4040
registry-url: "https://registry.npmjs.org"
4141
- name: Set name vars
4242
id: info-vars

.github/workflows/test-code.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: "🧪 Test: code"
33
on:
44
pull_request:
55
paths:
6+
- ".github/workflows/test-code.yml"
67
- "src/**.js"
78
- "src/**.ts"
89
- "src/**.tsx"
@@ -19,7 +20,7 @@ jobs:
1920
- name: Test using Node.js
2021
uses: actions/setup-node@main
2122
with:
22-
node-version: "18"
23+
node-version: "lts/krypton"
2324
- run: yarn install
2425
- run: yarn compile
2526
- run: yarn compile-scss

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,43 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `<ApplicationViewability />`
12+
- component for hiding elements in specific media
13+
- `<InlineText />`
14+
- force children to get displayed as inline content
15+
- `<StringPreviewContentBlobToggler />`
16+
- `useOnly` property: specify if only parts of the content should be used for the shortened preview, this property replaces `firstNonEmptyLineOnly`
17+
18+
### Fixed
19+
20+
- `<Tag />`
21+
- create more whitespace inside `small` tag
22+
- reduce visual impact of border
23+
- `<StringPreviewContentBlobToggler />`
24+
- take Markdown rendering into account before testing the maximum preview length
25+
- `<NodeContent />`
26+
- header-menu items are vertically centered now
27+
28+
### Changed
29+
30+
- automatically hide user interaction elements in print view
31+
- all application header components except `<WorkspaceHeader />`
32+
- `<CardActions />` and `<CardOptions />`
33+
- `actionOptions` of `<ContentGroup />`
34+
- `actions` of `<Notification />`
35+
- `<OverviewItemActions />`
36+
- automatically serialize display of layout elements in print view
37+
- `<FlexibleLayoutItem />`
38+
- `<GridColumn />`
39+
- `<PropertyName />` and `<PropertyValue />`
40+
41+
### Deprecated
42+
43+
- `<StringPreviewContentBlobToggler />`
44+
- `firstNonEmptyLineOnly` will be removed, is replaced by `useOnly="firstNonEmptyLine"`
45+
946
## [25.0.0] - 2025-12-01
1047

1148
This is a major release, and it might be not compatible with your current usage of our library. Please read about the necessary changes in the section about how to migrate.

src/cmem/ContentBlobToggler/ContentBlobToggler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function ContentBlobToggler({
5858
{previewContent}
5959
{enableToggler && (
6060
<>
61-
&hellip;{" "}
61+
{" "}&hellip;{" "}
6262
<Link
6363
href="#more"
6464
data-test-id={"content-blob-toggler-more-link"}
Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
import React from "react";
22

3-
import { ContentBlobToggler, ContentBlobTogglerProps, Markdown } from "./..";
3+
import { ContentBlobToggler, ContentBlobTogglerProps, InlineText, Markdown, utils } from "./../../index";
44

55
export interface StringPreviewContentBlobTogglerProps
66
extends Omit<ContentBlobTogglerProps, "previewContent" | "enableToggler"> {
77
/**
8-
The preview content will be cut to this length if it is too long.
8+
* The preview content will be cut to this length if it is too long.
99
*/
1010
previewMaxLength?: number;
1111
/**
12-
The content string. If it is smaller than previewMaxLength this will be displayed in full, else fullviewContent will be displayed.
12+
* The content string.
13+
* If it is smaller than `previewMaxLength` this will be displayed in full, else `fullviewContent` will be displayed.
1314
*/
1415
content: string;
15-
/** If only the first non-empty line should be shown in the preview. This will in addition also be shortened according to previewMaxLength. */
16-
firstNonEmptyLineOnly?: boolean;
17-
/** If enabled the preview is rendered as markdown. */
16+
/**
17+
* Use only parts of `content` in the preview.
18+
* `firstMarkdownSection` uses the content until the first double line return.
19+
* Currently overwritten by `firstNonEmptyLineOnly`.
20+
*/
21+
useOnly?: "firstNonEmptyLine" | "firstMarkdownSection";
22+
/**
23+
* If enabled the preview is rendered as Markdown.
24+
*/
1825
renderPreviewAsMarkdown?: boolean;
19-
/** White-listing of HTML elements that will be rendered when renderPreviewAsMarkdown is enabled. */
26+
/**
27+
* White-listing of HTML elements that will be rendered when renderPreviewAsMarkdown is enabled.
28+
*/
2029
allowedHtmlElementsInPreview?: string[];
21-
/** Allows to add non-string elements at the end of the content if the full description is shown, i.e. no toggler is necessary.
30+
/**
31+
* Allows to add non-string elements at the end of the content if the full description is shown, i.e. no toggler is necessary.
2232
* This allows to add non-string elements to both the full-view content and the pure string content.
2333
*/
2434
noTogglerContentSuffix?: React.JSX.Element;
35+
/**
36+
* If only the first non-empty line should be shown in the preview.
37+
* This will in addition also be shortened according to `previewMaxLength`.
38+
* @deprecated (v26) use `useOnly="firstNonEmptyLine"` instead
39+
*/
40+
firstNonEmptyLineOnly?: boolean;
2541
}
2642

27-
/** Version of the content toggler for text only content. */
43+
/** Version of the content toggler for text centric content. */
2844
export function StringPreviewContentBlobToggler({
2945
className = "",
3046
previewMaxLength,
@@ -33,21 +49,44 @@ export function StringPreviewContentBlobToggler({
3349
content,
3450
fullviewContent,
3551
startExtended,
36-
firstNonEmptyLineOnly,
52+
useOnly,
3753
renderPreviewAsMarkdown = false,
3854
allowedHtmlElementsInPreview,
3955
noTogglerContentSuffix,
56+
firstNonEmptyLineOnly,
4057
}: StringPreviewContentBlobTogglerProps) {
41-
const previewMaybeFirstLine = firstNonEmptyLineOnly ? firstNonEmptyLine(content) : content;
42-
const previewString = previewMaxLength ? previewMaybeFirstLine.substr(0, previewMaxLength) : previewMaybeFirstLine;
43-
const enableToggler = previewString !== content;
58+
// need to test `firstNonEmptyLineOnly` until property is removed
59+
const useOnlyTest: StringPreviewContentBlobTogglerProps["useOnly"] = firstNonEmptyLineOnly
60+
? "firstNonEmptyLine"
61+
: useOnly;
62+
63+
let previewString = content;
64+
switch (useOnlyTest) {
65+
case "firstNonEmptyLine":
66+
previewString = useOnlyPart(content, regexFirstNonEmptyLine);
67+
break;
68+
case "firstMarkdownSection":
69+
previewString = useOnlyPart(content, regexFirstMarkdownSection);
70+
}
71+
72+
let enableToggler = previewString !== content;
73+
4474
let previewContent = renderPreviewAsMarkdown ? (
4575
<Markdown key="markdown-content" allowedElements={allowedHtmlElementsInPreview}>
4676
{previewString}
4777
</Markdown>
4878
) : (
4979
previewString
5080
);
81+
82+
if (
83+
previewMaxLength &&
84+
utils.reduceToText(previewContent, { decodeHtmlEntities: true }).length > previewMaxLength
85+
) {
86+
previewContent = utils.reduceToText(previewContent, { decodeHtmlEntities: true }).slice(0, previewMaxLength);
87+
enableToggler = true;
88+
}
89+
5190
if (!enableToggler && noTogglerContentSuffix) {
5291
previewContent = (
5392
<>
@@ -60,7 +99,7 @@ export function StringPreviewContentBlobToggler({
6099
return (
61100
<ContentBlobToggler
62101
className={className}
63-
previewContent={previewContent}
102+
previewContent={<InlineText>{previewContent}</InlineText>}
64103
toggleExtendText={toggleExtendText}
65104
toggleReduceText={toggleReduceText}
66105
fullviewContent={fullviewContent}
@@ -70,17 +109,26 @@ export function StringPreviewContentBlobToggler({
70109
);
71110
}
72111

73-
const newLineRegex = new RegExp("\r|\n"); // eslint-disable-line
112+
const regexFirstNonEmptyLine = new RegExp("\r|\n"); // eslint-disable-line
113+
const regexFirstMarkdownSection = new RegExp("\r\n\r\n|\n\n"); // eslint-disable-line
74114

75115
/**
76116
* Takes the first non-empty line from a preview string.
77117
*/
78118
function firstNonEmptyLine(preview: string) {
119+
return useOnlyPart(preview, regexFirstNonEmptyLine);
120+
}
121+
122+
/**
123+
* Returns only the first part from a preview string.
124+
* Or the full string as fallback.
125+
*/
126+
function useOnlyPart(preview: string, regexTest: RegExp): string {
79127
const previewString = preview.trim();
80-
const result = newLineRegex.exec(previewString);
81-
return result !== null ? previewString.substr(0, result.index) : previewString;
128+
const result = regexTest.exec(previewString);
129+
return result !== null ? result.input.slice(0, result.index) : previewString;
82130
}
83131

84132
export const stringPreviewContentBlobTogglerUtils = {
85133
firstNonEmptyLine,
86-
};
134+
};

0 commit comments

Comments
 (0)