@eccenca/gui-elements 25.0.0-rc.2 → 25.1.0-featurev2510colorfield.0
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/CHANGELOG.md +94 -18
- package/dist/cjs/cmem/ActivityControl/ActivityControlWidget.js +17 -13
- package/dist/cjs/cmem/ActivityControl/ActivityControlWidget.js.map +1 -1
- package/dist/cjs/cmem/ActivityControl/SilkActivityControl.js +1 -3
- package/dist/cjs/cmem/ActivityControl/SilkActivityControl.js.map +1 -1
- package/dist/cjs/cmem/ContentBlobToggler/ContentBlobToggler.js +1 -0
- package/dist/cjs/cmem/ContentBlobToggler/ContentBlobToggler.js.map +1 -1
- package/dist/cjs/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.js +34 -11
- package/dist/cjs/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.js.map +1 -1
- package/dist/cjs/cmem/react-flow/ReactFlow/ReactFlowV12.js.map +1 -1
- package/dist/cjs/common/Intent/index.js +1 -1
- package/dist/cjs/common/Intent/index.js.map +1 -1
- package/dist/cjs/common/index.js +4 -1
- package/dist/cjs/common/index.js.map +1 -1
- package/dist/cjs/common/utils/colorHash.js +25 -11
- package/dist/cjs/common/utils/colorHash.js.map +1 -1
- package/dist/cjs/common/utils/reduceToText.js +26 -1
- package/dist/cjs/common/utils/reduceToText.js.map +1 -1
- package/dist/cjs/components/Application/ApplicationViewability.js +33 -0
- package/dist/cjs/components/Application/ApplicationViewability.js.map +1 -0
- package/dist/cjs/components/Application/index.js +1 -0
- package/dist/cjs/components/Application/index.js.map +1 -1
- package/dist/cjs/components/ColorField/ColorField.js +115 -0
- package/dist/cjs/components/ColorField/ColorField.js.map +1 -0
- package/dist/cjs/components/ContextOverlay/ContextMenu.js +2 -2
- package/dist/cjs/components/ContextOverlay/ContextMenu.js.map +1 -1
- package/dist/cjs/components/ContextOverlay/ContextOverlay.js +67 -29
- package/dist/cjs/components/ContextOverlay/ContextOverlay.js.map +1 -1
- package/dist/cjs/components/DecoupledOverlay/DecoupledOverlay.js +47 -0
- package/dist/cjs/components/DecoupledOverlay/DecoupledOverlay.js.map +1 -0
- package/dist/cjs/components/Icon/IconButton.js.map +1 -1
- package/dist/cjs/components/Icon/canonicalIconNames.js +3 -0
- package/dist/cjs/components/Icon/canonicalIconNames.js.map +1 -1
- package/dist/cjs/components/Icon/transformIcon.js +14 -0
- package/dist/cjs/components/Icon/transformIcon.js.map +1 -0
- package/dist/cjs/components/MultiSelect/MultiSelect.js +2 -1
- package/dist/cjs/components/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/cjs/components/RadioButton/RadioButton.js +5 -2
- package/dist/cjs/components/RadioButton/RadioButton.js.map +1 -1
- package/dist/cjs/components/TextReducer/TextReducer.js +15 -3
- package/dist/cjs/components/TextReducer/TextReducer.js.map +1 -1
- package/dist/cjs/components/Typography/InlineText.js +29 -0
- package/dist/cjs/components/Typography/InlineText.js.map +1 -0
- package/dist/cjs/components/Typography/index.js +1 -0
- package/dist/cjs/components/Typography/index.js.map +1 -1
- package/dist/cjs/components/VisualTour/VisualTour.js +24 -32
- package/dist/cjs/components/VisualTour/VisualTour.js.map +1 -1
- package/dist/cjs/components/index.js +2 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/extensions/codemirror/CodeMirror.js +18 -6
- package/dist/cjs/extensions/codemirror/CodeMirror.js.map +1 -1
- package/dist/cjs/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.js +1 -1
- package/dist/cjs/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.js.map +1 -1
- package/dist/cjs/extensions/codemirror/tests/codemirrorTestHelper.js +2 -2
- package/dist/cjs/extensions/codemirror/tests/codemirrorTestHelper.js.map +1 -1
- package/dist/cjs/extensions/react-flow/edges/EdgeLabel.js +1 -1
- package/dist/cjs/extensions/react-flow/edges/EdgeLabel.js.map +1 -1
- package/dist/cjs/extensions/react-flow/edges/EdgeNew.js +1 -1
- package/dist/cjs/extensions/react-flow/edges/EdgeNew.js.map +1 -1
- package/dist/cjs/extensions/react-flow/handles/HandleDefault.js +1 -1
- package/dist/cjs/extensions/react-flow/handles/HandleDefault.js.map +1 -1
- package/dist/cjs/extensions/react-flow/minimap/MiniMap.js +1 -1
- package/dist/cjs/extensions/react-flow/minimap/MiniMap.js.map +1 -1
- package/dist/cjs/extensions/react-flow/minimap/MiniMapV12.js.map +1 -1
- package/dist/cjs/extensions/react-flow/nodes/nodeUtils.js.map +1 -1
- package/dist/esm/cmem/ActivityControl/ActivityControlWidget.js +19 -14
- package/dist/esm/cmem/ActivityControl/ActivityControlWidget.js.map +1 -1
- package/dist/esm/cmem/ActivityControl/SilkActivityControl.js +1 -3
- package/dist/esm/cmem/ActivityControl/SilkActivityControl.js.map +1 -1
- package/dist/esm/cmem/ContentBlobToggler/ContentBlobToggler.js +1 -0
- package/dist/esm/cmem/ContentBlobToggler/ContentBlobToggler.js.map +1 -1
- package/dist/esm/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.js +32 -9
- package/dist/esm/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.js.map +1 -1
- package/dist/esm/cmem/react-flow/ReactFlow/ReactFlowV12.js.map +1 -1
- package/dist/esm/common/Intent/index.js +1 -1
- package/dist/esm/common/Intent/index.js.map +1 -1
- package/dist/esm/common/index.js +5 -2
- package/dist/esm/common/index.js.map +1 -1
- package/dist/esm/common/utils/colorHash.js +25 -12
- package/dist/esm/common/utils/colorHash.js.map +1 -1
- package/dist/esm/common/utils/reduceToText.js +37 -1
- package/dist/esm/common/utils/reduceToText.js.map +1 -1
- package/dist/esm/components/Application/ApplicationViewability.js +28 -0
- package/dist/esm/components/Application/ApplicationViewability.js.map +1 -0
- package/dist/esm/components/Application/index.js +1 -0
- package/dist/esm/components/Application/index.js.map +1 -1
- package/dist/esm/components/ColorField/ColorField.js +141 -0
- package/dist/esm/components/ColorField/ColorField.js.map +1 -0
- package/dist/esm/components/ContextOverlay/ContextMenu.js +2 -2
- package/dist/esm/components/ContextOverlay/ContextMenu.js.map +1 -1
- package/dist/esm/components/ContextOverlay/ContextOverlay.js +67 -29
- package/dist/esm/components/ContextOverlay/ContextOverlay.js.map +1 -1
- package/dist/esm/components/DecoupledOverlay/DecoupledOverlay.js +41 -0
- package/dist/esm/components/DecoupledOverlay/DecoupledOverlay.js.map +1 -0
- package/dist/esm/components/Icon/IconButton.js.map +1 -1
- package/dist/esm/components/Icon/canonicalIconNames.js +3 -0
- package/dist/esm/components/Icon/canonicalIconNames.js.map +1 -1
- package/dist/esm/components/Icon/transformIcon.js +21 -0
- package/dist/esm/components/Icon/transformIcon.js.map +1 -0
- package/dist/esm/components/MultiSelect/MultiSelect.js +3 -2
- package/dist/esm/components/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/esm/components/RadioButton/RadioButton.js +6 -2
- package/dist/esm/components/RadioButton/RadioButton.js.map +1 -1
- package/dist/esm/components/TextReducer/TextReducer.js +14 -3
- package/dist/esm/components/TextReducer/TextReducer.js.map +1 -1
- package/dist/esm/components/Typography/InlineText.js +33 -0
- package/dist/esm/components/Typography/InlineText.js.map +1 -0
- package/dist/esm/components/Typography/index.js +1 -0
- package/dist/esm/components/Typography/index.js.map +1 -1
- package/dist/esm/components/VisualTour/VisualTour.js +25 -33
- package/dist/esm/components/VisualTour/VisualTour.js.map +1 -1
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/extensions/codemirror/CodeMirror.js +19 -7
- package/dist/esm/extensions/codemirror/CodeMirror.js.map +1 -1
- package/dist/esm/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.js +1 -1
- package/dist/esm/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.js.map +1 -1
- package/dist/esm/extensions/codemirror/tests/codemirrorTestHelper.js +3 -3
- package/dist/esm/extensions/codemirror/tests/codemirrorTestHelper.js.map +1 -1
- package/dist/esm/extensions/react-flow/edges/EdgeLabel.js +1 -1
- package/dist/esm/extensions/react-flow/edges/EdgeLabel.js.map +1 -1
- package/dist/esm/extensions/react-flow/edges/EdgeNew.js +1 -1
- package/dist/esm/extensions/react-flow/edges/EdgeNew.js.map +1 -1
- package/dist/esm/extensions/react-flow/handles/HandleDefault.js +1 -1
- package/dist/esm/extensions/react-flow/handles/HandleDefault.js.map +1 -1
- package/dist/esm/extensions/react-flow/minimap/MiniMap.js +1 -1
- package/dist/esm/extensions/react-flow/minimap/MiniMap.js.map +1 -1
- package/dist/esm/extensions/react-flow/minimap/MiniMapV12.js.map +1 -1
- package/dist/esm/extensions/react-flow/nodes/nodeUtils.js.map +1 -1
- package/dist/types/cmem/ActivityControl/ActivityControlWidget.d.ts +9 -0
- package/dist/types/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.d.ts +26 -10
- package/dist/types/common/index.d.ts +4 -1
- package/dist/types/common/utils/colorHash.d.ts +4 -3
- package/dist/types/common/utils/reduceToText.d.ts +1 -1
- package/dist/types/components/Application/ApplicationViewability.d.ts +36 -0
- package/dist/types/components/Application/index.d.ts +1 -0
- package/dist/types/components/ColorField/ColorField.d.ts +31 -0
- package/dist/types/components/ContextOverlay/ContextMenu.d.ts +1 -1
- package/dist/types/components/ContextOverlay/ContextOverlay.d.ts +7 -1
- package/dist/types/components/DecoupledOverlay/DecoupledOverlay.d.ts +20 -0
- package/dist/types/components/Icon/IconButton.d.ts +1 -1
- package/dist/types/components/Icon/canonicalIconNames.d.ts +2 -0
- package/dist/types/components/Icon/transformIcon.d.ts +2 -0
- package/dist/types/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/dist/types/components/RadioButton/RadioButton.d.ts +8 -2
- package/dist/types/components/Structure/TitleSubsection.d.ts +1 -1
- package/dist/types/components/Tabs/Tab.d.ts +2 -2
- package/dist/types/components/TextReducer/TextReducer.d.ts +13 -1
- package/dist/types/components/Typography/InlineText.d.ts +13 -0
- package/dist/types/components/Typography/index.d.ts +1 -0
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.d.ts +1 -1
- package/dist/types/extensions/codemirror/tests/codemirrorTestHelper.d.ts +1 -1
- package/package.json +54 -53
- package/src/cmem/ActivityControl/ActivityControlWidget.tsx +68 -35
- package/src/cmem/ActivityControl/SilkActivityControl.tsx +1 -1
- package/src/cmem/ContentBlobToggler/ContentBlobToggler.tsx +1 -1
- package/src/cmem/ContentBlobToggler/StringPreviewContentBlobToggler.tsx +66 -18
- package/src/cmem/ContentBlobToggler/stories/StringPreviewContentBlobToggler.stories.tsx +27 -0
- package/src/cmem/ContentBlobToggler/tests/StringPreviewContentBlobToggler.test.tsx +98 -0
- package/src/cmem/react-flow/ReactFlow/ReactFlowV12.tsx +1 -0
- package/src/common/Intent/index.ts +2 -1
- package/src/common/index.ts +8 -3
- package/src/common/utils/colorHash.ts +36 -18
- package/src/common/utils/reduceToText.tsx +30 -2
- package/src/components/Application/ApplicationViewability.tsx +61 -0
- package/src/components/Application/_colors.scss +15 -0
- package/src/components/Application/_content.scss +7 -0
- package/src/components/Application/_header.scss +12 -3
- package/src/components/Application/_viewability.scss +13 -0
- package/src/components/Application/application.scss +1 -0
- package/src/components/Application/index.ts +1 -0
- package/src/components/Application/stories/ApplicationViewability.stories.tsx +37 -0
- package/src/components/Application/tests/ApplicationViewability.test.tsx +43 -0
- package/src/components/AutoSuggestion/tests/ExtendedCodeEditor.test.tsx +1 -1
- package/src/components/Card/card.scss +6 -0
- package/src/components/Checkbox/checkbox.scss +14 -2
- package/src/components/ColorField/ColorField.stories.tsx +69 -0
- package/src/components/ColorField/ColorField.test.tsx +125 -0
- package/src/components/ColorField/ColorField.tsx +200 -0
- package/src/components/ColorField/_colorfield.scss +56 -0
- package/src/components/ContentGroup/_contentgroup.scss +9 -0
- package/src/components/ContextOverlay/ContextMenu.tsx +4 -1
- package/src/components/ContextOverlay/ContextOverlay.tsx +94 -25
- package/src/components/ContextOverlay/tests/ContextMenu.test.tsx +43 -0
- package/src/components/ContextOverlay/tests/ContextOverlay.test.tsx +71 -0
- package/src/components/DecoupledOverlay/DecoupledOverlay.stories.tsx +30 -0
- package/src/components/DecoupledOverlay/DecoupledOverlay.tsx +97 -0
- package/src/components/DecoupledOverlay/_decoupledoverlay.scss +46 -0
- package/src/components/Depiction/depiction.scss +6 -0
- package/src/components/Dialog/stories/Modal.stories.tsx +12 -150
- package/src/components/Dialog/stories/ModalContext.stories.tsx +153 -0
- package/src/components/FlexibleLayout/flexiblelayout.scss +16 -0
- package/src/components/Grid/grid.scss +17 -0
- package/src/components/Grid/stories/Grid.stories.tsx +10 -7
- package/src/components/Grid/stories/GridRow.stories.tsx +13 -7
- package/src/components/Icon/IconButton.tsx +1 -1
- package/src/components/Icon/canonicalIconNames.tsx +3 -0
- package/src/components/Icon/transformIcon.tsx +17 -0
- package/src/components/Link/Link.stories.tsx +30 -0
- package/src/components/Link/link.scss +28 -2
- package/src/components/MultiSelect/MultiSelect.tsx +12 -3
- package/src/components/Notification/notification.scss +6 -0
- package/src/components/OverviewItem/overviewitem.scss +9 -0
- package/src/components/OverviewItem/stories/OverviewItem.stories.tsx +28 -0
- package/src/components/OverviewItem/stories/OverviewItemActions.stories.tsx +2 -2
- package/src/components/OverviewItem/stories/OverviewItemDescription.stories.tsx +1 -1
- package/src/components/OverviewItem/stories/OverviewItemLine.stories.tsx +1 -1
- package/src/components/PropertyValuePair/propertyvalue.scss +23 -1
- package/src/components/RadioButton/RadioButton.tsx +15 -3
- package/src/components/RadioButton/radiobutton.scss +13 -0
- package/src/components/Separation/separation.scss +6 -0
- package/src/components/Table/table.scss +22 -0
- package/src/components/Tabs/stories/TabTitle.stories.tsx +7 -2
- package/src/components/Tag/stories/TagList.stories.tsx +2 -2
- package/src/components/Tag/tag.scss +19 -9
- package/src/components/TextReducer/TextReducer.stories.tsx +2 -1
- package/src/components/TextReducer/TextReducer.test.tsx +44 -0
- package/src/components/TextReducer/TextReducer.tsx +14 -4
- package/src/components/Typography/InlineText.tsx +24 -0
- package/src/components/Typography/_reset.scss +1 -0
- package/src/components/Typography/index.ts +1 -0
- package/src/components/Typography/stories/InlineText.stories.tsx +27 -0
- package/src/components/Typography/typography.scss +28 -2
- package/src/components/VisualTour/VisualTour.tsx +30 -50
- package/src/components/VisualTour/visualTour.scss +0 -34
- package/src/components/index.scss +2 -0
- package/src/components/index.ts +2 -0
- package/src/configuration/_customproperties.scss +32 -0
- package/src/configuration/stories/customproperties.stories.tsx +118 -0
- package/src/extensions/codemirror/CodeMirror.tsx +20 -9
- package/src/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.ts +1 -2
- package/src/extensions/codemirror/tests/codemirrorTestHelper.ts +3 -3
- package/src/extensions/react-flow/_config.scss +3 -3
- package/src/extensions/react-flow/edges/EdgeLabel.tsx +5 -3
- package/src/extensions/react-flow/edges/EdgeNew.tsx +2 -1
- package/src/extensions/react-flow/edges/_edges.scss +3 -2
- package/src/extensions/react-flow/handles/HandleDefault.tsx +2 -2
- package/src/extensions/react-flow/minimap/MiniMap.tsx +2 -1
- package/src/extensions/react-flow/minimap/MiniMapV12.tsx +1 -1
- package/src/extensions/react-flow/nodes/_nodes.scss +4 -3
- package/src/extensions/react-flow/nodes/nodeUtils.tsx +1 -0
- package/src/extensions/react-flow/nodes/stories/NodeContent.stories.tsx +2 -2
- package/src/index.scss +1 -0
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
3
|
+
import {ValidIconName} from "../../components/Icon/canonicalIconNames";
|
|
4
|
+
import {IconProps} from "../../components/Icon/Icon";
|
|
5
|
+
import {TestIconProps} from "../../components/Icon/TestIcon";
|
|
6
|
+
import {TestableComponent} from "../../components/interfaces";
|
|
7
|
+
import {ProgressBarProps} from "../../components/ProgressBar/ProgressBar";
|
|
8
|
+
import {SpinnerProps} from "../../components/Spinner/Spinner";
|
|
9
|
+
import {CLASSPREFIX as eccgui} from "../../configuration/constants";
|
|
10
10
|
import {
|
|
11
11
|
Card,
|
|
12
12
|
ContextMenu,
|
|
13
|
+
DecoupledOverlay,
|
|
13
14
|
IconButton,
|
|
14
15
|
MenuItem,
|
|
16
|
+
Notification,
|
|
17
|
+
NotificationProps,
|
|
15
18
|
OverflowText,
|
|
16
19
|
OverviewItem,
|
|
17
20
|
OverviewItemActions,
|
|
@@ -97,7 +100,7 @@ interface IActivityContextMenu extends TestableComponent {
|
|
|
97
100
|
export interface ActivityControlWidgetAction extends TestableComponent {
|
|
98
101
|
// The action that should be triggered
|
|
99
102
|
action: () => void;
|
|
100
|
-
// The tooltip that should be shown over the action icon
|
|
103
|
+
// The tooltip that should be shown over the action icon on hover
|
|
101
104
|
tooltip?: string;
|
|
102
105
|
// The icon of the action button
|
|
103
106
|
icon: ValidIconName | React.ReactElement<TestIconProps>;
|
|
@@ -105,6 +108,16 @@ export interface ActivityControlWidgetAction extends TestableComponent {
|
|
|
105
108
|
disabled?: boolean;
|
|
106
109
|
// Warning state
|
|
107
110
|
hasStateWarning?: boolean;
|
|
111
|
+
// Active state
|
|
112
|
+
active?: boolean
|
|
113
|
+
/** A notification that is shown in an overlay pointing at the activity action button. */
|
|
114
|
+
notification?: {
|
|
115
|
+
message: string
|
|
116
|
+
onClose: () => void
|
|
117
|
+
intent?: NotificationProps["intent"]
|
|
118
|
+
// Timeout in ms before notification is closed. Default: none
|
|
119
|
+
timeout?: number
|
|
120
|
+
}
|
|
108
121
|
}
|
|
109
122
|
|
|
110
123
|
interface IActivityMenuAction extends ActivityControlWidgetAction {
|
|
@@ -209,28 +222,11 @@ export function ActivityControlWidget(props: ActivityControlWidgetProps) {
|
|
|
209
222
|
data-test-id={dataTestIdLegacy ? `${dataTestIdLegacy}-actions` : undefined}
|
|
210
223
|
>
|
|
211
224
|
{activityActions &&
|
|
212
|
-
activityActions.map((action, idx) =>
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
? action.icon
|
|
218
|
-
: action["data-test-id"] ?? action["data-testid"] ?? idx
|
|
219
|
-
}
|
|
220
|
-
data-test-id={action["data-test-id"]}
|
|
221
|
-
data-testid={action["data-testid"]}
|
|
222
|
-
name={action.icon}
|
|
223
|
-
text={action.tooltip}
|
|
224
|
-
onClick={action.action}
|
|
225
|
-
disabled={action.disabled}
|
|
226
|
-
intent={action.hasStateWarning ? "warning" : undefined}
|
|
227
|
-
tooltipProps={{
|
|
228
|
-
hoverOpenDelay: 200,
|
|
229
|
-
placement: "bottom",
|
|
230
|
-
}}
|
|
231
|
-
/>
|
|
232
|
-
);
|
|
233
|
-
})}
|
|
225
|
+
activityActions.map((action, idx) => <ActivityActionButton
|
|
226
|
+
key={idx}
|
|
227
|
+
action={action}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
234
230
|
{additionalActions}
|
|
235
231
|
{activityContextMenu && activityContextMenu.menuItems.length > 0 && (
|
|
236
232
|
<ContextMenu
|
|
@@ -241,11 +237,7 @@ export function ActivityControlWidget(props: ActivityControlWidgetProps) {
|
|
|
241
237
|
return (
|
|
242
238
|
<MenuItem
|
|
243
239
|
icon={menuAction.icon}
|
|
244
|
-
key={
|
|
245
|
-
typeof menuAction.icon === "string"
|
|
246
|
-
? menuAction.icon
|
|
247
|
-
: menuAction["data-test-id"] ?? idx
|
|
248
|
-
}
|
|
240
|
+
key={idx}
|
|
249
241
|
onClick={menuAction.action}
|
|
250
242
|
text={menuAction.tooltip}
|
|
251
243
|
/>
|
|
@@ -267,3 +259,44 @@ export function ActivityControlWidget(props: ActivityControlWidgetProps) {
|
|
|
267
259
|
<div className={classname}>{widget}</div>
|
|
268
260
|
);
|
|
269
261
|
}
|
|
262
|
+
|
|
263
|
+
interface ActivityActionButtonProps {
|
|
264
|
+
action: ActivityControlWidgetAction
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const ActivityActionButton = ({action}: ActivityActionButtonProps) => {
|
|
268
|
+
const actionButtonRef = React.useRef(null);
|
|
269
|
+
const ActionButton = () => (
|
|
270
|
+
<IconButton
|
|
271
|
+
data-test-id={action["data-test-id"]}
|
|
272
|
+
data-testid={action["data-testid"]}
|
|
273
|
+
name={action.icon}
|
|
274
|
+
text={action.tooltip}
|
|
275
|
+
onClick={action.action}
|
|
276
|
+
disabled={action.disabled}
|
|
277
|
+
intent={action.hasStateWarning ? "warning" : undefined}
|
|
278
|
+
tooltipProps={{
|
|
279
|
+
hoverOpenDelay: 200,
|
|
280
|
+
placement: "bottom"
|
|
281
|
+
}}
|
|
282
|
+
active={action.active}
|
|
283
|
+
/>
|
|
284
|
+
)
|
|
285
|
+
return action.notification ?
|
|
286
|
+
<>
|
|
287
|
+
<span ref={actionButtonRef}>
|
|
288
|
+
<ActionButton/>
|
|
289
|
+
</span>
|
|
290
|
+
{actionButtonRef.current && (
|
|
291
|
+
<DecoupledOverlay targetSelectorOrElement={actionButtonRef.current} paddingSize={"small"}>
|
|
292
|
+
<Notification
|
|
293
|
+
message={action.notification.message}
|
|
294
|
+
intent={action.notification.intent ?? "neutral"}
|
|
295
|
+
onDismiss={action.notification.onClose}
|
|
296
|
+
timeout={action.notification.timeout}
|
|
297
|
+
/>
|
|
298
|
+
</DecoupledOverlay>
|
|
299
|
+
)}
|
|
300
|
+
</> :
|
|
301
|
+
<ActionButton/>
|
|
302
|
+
}
|
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import { ContentBlobToggler, ContentBlobTogglerProps, Markdown } from "
|
|
3
|
+
import { ContentBlobToggler, ContentBlobTogglerProps, InlineText, Markdown, utils } from "./../../index";
|
|
4
4
|
|
|
5
5
|
export interface StringPreviewContentBlobTogglerProps
|
|
6
6
|
extends Omit<ContentBlobTogglerProps, "previewContent" | "enableToggler"> {
|
|
7
7
|
/**
|
|
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.
|
|
9
9
|
*/
|
|
10
10
|
previewMaxLength?: number;
|
|
11
11
|
/**
|
|
12
|
-
The content string.
|
|
12
|
+
* The content string.
|
|
13
|
+
* If it is smaller than `previewMaxLength` this will be displayed in full, else `fullviewContent` will be displayed.
|
|
13
14
|
*/
|
|
14
15
|
content: string;
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
*/
|
|
18
25
|
renderPreviewAsMarkdown?: boolean;
|
|
19
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* White-listing of HTML elements that will be rendered when renderPreviewAsMarkdown is enabled.
|
|
28
|
+
*/
|
|
20
29
|
allowedHtmlElementsInPreview?: string[];
|
|
21
|
-
/**
|
|
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.
|
|
22
32
|
* This allows to add non-string elements to both the full-view content and the pure string content.
|
|
23
33
|
*/
|
|
24
34
|
noTogglerContentSuffix?: 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;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
/** Version of the content toggler for text
|
|
43
|
+
/** Version of the content toggler for text centric content. */
|
|
28
44
|
export function StringPreviewContentBlobToggler({
|
|
29
45
|
className = "",
|
|
30
46
|
previewMaxLength,
|
|
@@ -33,14 +49,28 @@ export function StringPreviewContentBlobToggler({
|
|
|
33
49
|
content,
|
|
34
50
|
fullviewContent,
|
|
35
51
|
startExtended,
|
|
36
|
-
|
|
52
|
+
useOnly,
|
|
37
53
|
renderPreviewAsMarkdown = false,
|
|
38
54
|
allowedHtmlElementsInPreview,
|
|
39
55
|
noTogglerContentSuffix,
|
|
56
|
+
firstNonEmptyLineOnly,
|
|
40
57
|
}: StringPreviewContentBlobTogglerProps) {
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
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
|
+
|
|
44
74
|
let previewContent = renderPreviewAsMarkdown ? (
|
|
45
75
|
<Markdown key="markdown-content" allowedElements={allowedHtmlElementsInPreview}>
|
|
46
76
|
{previewString}
|
|
@@ -48,6 +78,15 @@ export function StringPreviewContentBlobToggler({
|
|
|
48
78
|
) : (
|
|
49
79
|
previewString
|
|
50
80
|
);
|
|
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
|
+
|
|
51
90
|
if (!enableToggler && noTogglerContentSuffix) {
|
|
52
91
|
previewContent = (
|
|
53
92
|
<>
|
|
@@ -60,7 +99,7 @@ export function StringPreviewContentBlobToggler({
|
|
|
60
99
|
return (
|
|
61
100
|
<ContentBlobToggler
|
|
62
101
|
className={className}
|
|
63
|
-
previewContent={previewContent}
|
|
102
|
+
previewContent={<InlineText>{previewContent}</InlineText>}
|
|
64
103
|
toggleExtendText={toggleExtendText}
|
|
65
104
|
toggleReduceText={toggleReduceText}
|
|
66
105
|
fullviewContent={fullviewContent}
|
|
@@ -70,17 +109,26 @@ export function StringPreviewContentBlobToggler({
|
|
|
70
109
|
);
|
|
71
110
|
}
|
|
72
111
|
|
|
73
|
-
const
|
|
112
|
+
const regexFirstNonEmptyLine = new RegExp("\r|\n"); // eslint-disable-line
|
|
113
|
+
const regexFirstMarkdownSection = new RegExp("\r\n\r\n|\n\n"); // eslint-disable-line
|
|
74
114
|
|
|
75
115
|
/**
|
|
76
116
|
* Takes the first non-empty line from a preview string.
|
|
77
117
|
*/
|
|
78
118
|
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 {
|
|
79
127
|
const previewString = preview.trim();
|
|
80
|
-
const result =
|
|
81
|
-
return result !== null ?
|
|
128
|
+
const result = regexTest.exec(previewString);
|
|
129
|
+
return result !== null ? result.input.slice(0, result.index) : previewString;
|
|
82
130
|
}
|
|
83
131
|
|
|
84
132
|
export const stringPreviewContentBlobTogglerUtils = {
|
|
85
133
|
firstNonEmptyLine,
|
|
86
|
-
};
|
|
134
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Meta, StoryFn } from "@storybook/react";
|
|
3
|
+
|
|
4
|
+
import { Markdown, StringPreviewContentBlobToggler } from "../../../index";
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
title: "CMEM/ContentBlobToggler/StringPreview",
|
|
8
|
+
component: StringPreviewContentBlobToggler,
|
|
9
|
+
} as Meta<typeof StringPreviewContentBlobToggler>;
|
|
10
|
+
export default config;
|
|
11
|
+
|
|
12
|
+
const Template: StoryFn<typeof StringPreviewContentBlobToggler> = (args) => (
|
|
13
|
+
<StringPreviewContentBlobToggler {...args} />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const initialTeststring =
|
|
17
|
+
"A library for GUI elements.\nIn order to create graphical user interfaces, please have look at the documentation at [Github](https://github.com/eccenca/gui-elements).";
|
|
18
|
+
|
|
19
|
+
export const Default = Template.bind({});
|
|
20
|
+
Default.args = {
|
|
21
|
+
content: initialTeststring,
|
|
22
|
+
fullviewContent: <Markdown htmlContentBlockProps={{ large: true }}>{initialTeststring}</Markdown>,
|
|
23
|
+
previewMaxLength: 64,
|
|
24
|
+
renderPreviewAsMarkdown: true,
|
|
25
|
+
toggleExtendText: "show more",
|
|
26
|
+
toggleReduceText: "show less",
|
|
27
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, RenderResult } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
import "@testing-library/jest-dom";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
StringPreviewContentBlobToggler,
|
|
8
|
+
StringPreviewContentBlobTogglerProps,
|
|
9
|
+
} from "../StringPreviewContentBlobToggler";
|
|
10
|
+
|
|
11
|
+
import { Default as StringPreviewContentBlobTogglerStory } from "./../stories/StringPreviewContentBlobToggler.stories";
|
|
12
|
+
|
|
13
|
+
describe("StringPreviewContentBlobToggler", () => {
|
|
14
|
+
const textMustExist = (queryByText: RenderResult["queryByText"], text: string) => {
|
|
15
|
+
expect(queryByText(text, { exact: false })).not.toBeNull();
|
|
16
|
+
};
|
|
17
|
+
const textMustNotExist = (queryByText: RenderResult["queryByText"], text: string) => {
|
|
18
|
+
expect(queryByText(text, { exact: false })).toBeNull();
|
|
19
|
+
};
|
|
20
|
+
it("should cut preview and show toggler to extend", () => {
|
|
21
|
+
const { queryByText } = render(
|
|
22
|
+
<StringPreviewContentBlobToggler
|
|
23
|
+
{...(StringPreviewContentBlobTogglerStory.args as StringPreviewContentBlobTogglerProps)}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
textMustExist(queryByText, "A library for GUI elements.");
|
|
27
|
+
textMustNotExist(
|
|
28
|
+
queryByText,
|
|
29
|
+
"In order to create graphical user interfaces, please have look at the documentation at"
|
|
30
|
+
);
|
|
31
|
+
textMustExist(queryByText, "show more");
|
|
32
|
+
});
|
|
33
|
+
it("should display full view if `startExtended` is enabled, and show toggler to reduce", () => {
|
|
34
|
+
const { queryByText } = render(
|
|
35
|
+
<StringPreviewContentBlobToggler
|
|
36
|
+
{...(StringPreviewContentBlobTogglerStory.args as StringPreviewContentBlobTogglerProps)}
|
|
37
|
+
startExtended
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
textMustExist(
|
|
41
|
+
queryByText,
|
|
42
|
+
"In order to create graphical user interfaces, please have look at the documentation at"
|
|
43
|
+
);
|
|
44
|
+
textMustExist(queryByText, "show less");
|
|
45
|
+
});
|
|
46
|
+
it('should display only first content line on `useOnly={"firstNonEmptyLine"}`', () => {
|
|
47
|
+
const { queryByText } = render(
|
|
48
|
+
<StringPreviewContentBlobToggler
|
|
49
|
+
{...(StringPreviewContentBlobTogglerStory.args as StringPreviewContentBlobTogglerProps)}
|
|
50
|
+
useOnly={"firstNonEmptyLine"}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
textMustExist(queryByText, "A library for GUI elements.");
|
|
54
|
+
textMustNotExist(queryByText, "In order to create");
|
|
55
|
+
});
|
|
56
|
+
it('should use first Markdown paragraph as preview content on `useOnly={"firstMarkdownSection"}` but shorten it', () => {
|
|
57
|
+
const { queryByText } = render(
|
|
58
|
+
<StringPreviewContentBlobToggler
|
|
59
|
+
{...(StringPreviewContentBlobTogglerStory.args as StringPreviewContentBlobTogglerProps)}
|
|
60
|
+
useOnly={"firstMarkdownSection"}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
textMustExist(queryByText, "A library for GUI elements.");
|
|
64
|
+
textMustExist(queryByText, "In order to create");
|
|
65
|
+
textMustNotExist(queryByText, "please have look at the documentation at");
|
|
66
|
+
});
|
|
67
|
+
it("should display full preview and no toggler if content is short enough", () => {
|
|
68
|
+
const { queryByText } = render(
|
|
69
|
+
<StringPreviewContentBlobToggler
|
|
70
|
+
{...(StringPreviewContentBlobTogglerStory.args as StringPreviewContentBlobTogglerProps)}
|
|
71
|
+
previewMaxLength={144}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
textMustExist(queryByText, "A library for GUI elements.");
|
|
75
|
+
textMustExist(
|
|
76
|
+
queryByText,
|
|
77
|
+
"In order to create graphical user interfaces, please have look at the documentation at"
|
|
78
|
+
);
|
|
79
|
+
textMustNotExist(queryByText, "https://github.com/"); // test if Markdown was rendered
|
|
80
|
+
textMustNotExist(queryByText, "show more");
|
|
81
|
+
});
|
|
82
|
+
it("should not use Markdown rendering on `renderPreviewAsMarkdown={false}`", () => {
|
|
83
|
+
const { queryByText } = render(
|
|
84
|
+
<StringPreviewContentBlobToggler
|
|
85
|
+
{...(StringPreviewContentBlobTogglerStory.args as StringPreviewContentBlobTogglerProps)}
|
|
86
|
+
previewMaxLength={144}
|
|
87
|
+
renderPreviewAsMarkdown={false}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
textMustExist(queryByText, "A library for GUI elements.");
|
|
91
|
+
textMustExist(
|
|
92
|
+
queryByText,
|
|
93
|
+
"In order to create graphical user interfaces, please have look at the documentation at"
|
|
94
|
+
);
|
|
95
|
+
textMustExist(queryByText, "https://github.com/"); // test if Markdown was rendered
|
|
96
|
+
textMustExist(queryByText, "show more");
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
|
|
2
1
|
import { Intent as BlueprintIntent } from "@blueprintjs/core";
|
|
3
2
|
|
|
3
|
+
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
|
|
4
|
+
|
|
4
5
|
export type IntentBlueprint = BlueprintIntent;
|
|
5
6
|
export const DefinitionsBlueprint = BlueprintIntent;
|
|
6
7
|
|
package/src/common/index.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { decode } from "he";
|
|
2
|
+
|
|
1
3
|
import { invisibleZeroWidthCharacters } from "./utils/characters";
|
|
2
4
|
import { colorCalculateDistance } from "./utils/colorCalculateDistance";
|
|
3
5
|
import decideContrastColorValue from "./utils/colorDecideContrastvalue";
|
|
4
|
-
import { getEnabledColorsFromPalette, textToColorHash } from "./utils/colorHash";
|
|
6
|
+
import { getEnabledColorPropertiesFromPalette, getEnabledColorsFromPalette, textToColorHash } from "./utils/colorHash";
|
|
5
7
|
import getColorConfiguration from "./utils/getColorConfiguration";
|
|
6
8
|
import { getScrollParent } from "./utils/getScrollParent";
|
|
7
9
|
import { getGlobalVar, setGlobalVar } from "./utils/globalVars";
|
|
8
10
|
import { openInNewTab } from "./utils/openInNewTab";
|
|
9
|
-
import { reduceToText } from "./utils/reduceToText"
|
|
11
|
+
import { reduceToText } from "./utils/reduceToText";
|
|
12
|
+
export type { DecodeOptions as DecodeHtmlEntitiesOptions } from "he";
|
|
10
13
|
export type { IntentTypes as IntentBaseTypes } from "./Intent";
|
|
11
14
|
|
|
12
15
|
export const utils = {
|
|
@@ -19,6 +22,8 @@ export const utils = {
|
|
|
19
22
|
setGlobalVar,
|
|
20
23
|
getScrollParent,
|
|
21
24
|
getEnabledColorsFromPalette,
|
|
25
|
+
getEnabledColorPropertiesFromPalette,
|
|
22
26
|
textToColorHash,
|
|
23
|
-
reduceToText
|
|
27
|
+
reduceToText,
|
|
28
|
+
decodeHtmlEntities: decode,
|
|
24
29
|
};
|
|
@@ -6,8 +6,8 @@ import { colorCalculateDistance } from "./colorCalculateDistance";
|
|
|
6
6
|
import CssCustomProperties from "./CssCustomProperties";
|
|
7
7
|
|
|
8
8
|
type ColorOrFalse = Color | false;
|
|
9
|
-
type ColorWeight = 100 | 300 | 500 | 700 | 900;
|
|
10
|
-
type PaletteGroup = "identity" | "semantic" | "layout" | "extra";
|
|
9
|
+
export type ColorWeight = 100 | 300 | 500 | 700 | 900;
|
|
10
|
+
export type PaletteGroup = "identity" | "semantic" | "layout" | "extra";
|
|
11
11
|
|
|
12
12
|
interface getEnabledColorsProps {
|
|
13
13
|
/** Specify the palette groups used to define the set of colors. */
|
|
@@ -21,20 +21,43 @@ interface getEnabledColorsProps {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const getEnabledColorsFromPaletteCache = new Map<string, Color[]>();
|
|
24
|
+
const getEnabledColorPropertiesFromPaletteCache = new Map<string, string[][]>();
|
|
24
25
|
|
|
25
|
-
export function getEnabledColorsFromPalette({
|
|
26
|
+
export function getEnabledColorsFromPalette(props: getEnabledColorsProps): Color[] {
|
|
27
|
+
const configId = JSON.stringify({
|
|
28
|
+
includePaletteGroup: props.includePaletteGroup,
|
|
29
|
+
includeColorWeight: props.includeColorWeight,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (getEnabledColorsFromPaletteCache.has(configId)) {
|
|
33
|
+
return getEnabledColorsFromPaletteCache.get(configId)!;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const colorPropertiesFromPalette = Object.values(getEnabledColorPropertiesFromPalette(props));
|
|
37
|
+
|
|
38
|
+
getEnabledColorsFromPaletteCache.set(
|
|
39
|
+
configId,
|
|
40
|
+
colorPropertiesFromPalette.map((color) => {
|
|
41
|
+
return Color(color[1]);
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return getEnabledColorsFromPaletteCache.get(configId)!;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getEnabledColorPropertiesFromPalette({
|
|
26
49
|
includePaletteGroup = ["layout"],
|
|
27
50
|
includeColorWeight = [100, 300, 500, 700, 900],
|
|
28
|
-
//
|
|
51
|
+
// (planned for later): includeMixedColors = false,
|
|
29
52
|
minimalColorDistance = COLORMINDISTANCE,
|
|
30
|
-
}: getEnabledColorsProps):
|
|
53
|
+
}: getEnabledColorsProps): string[][] {
|
|
31
54
|
const configId = JSON.stringify({
|
|
32
55
|
includePaletteGroup,
|
|
33
56
|
includeColorWeight,
|
|
34
57
|
});
|
|
35
58
|
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
59
|
+
if (getEnabledColorPropertiesFromPaletteCache.has(configId)) {
|
|
60
|
+
return getEnabledColorPropertiesFromPaletteCache.get(configId)!;
|
|
38
61
|
}
|
|
39
62
|
|
|
40
63
|
const colorsFromPalette = new CssCustomProperties({
|
|
@@ -50,18 +73,18 @@ export function getEnabledColorsFromPalette({
|
|
|
50
73
|
const weight = parseInt(tint[2], 10) as ColorWeight;
|
|
51
74
|
return includePaletteGroup.includes(group) && includeColorWeight.includes(weight);
|
|
52
75
|
},
|
|
53
|
-
removeDashPrefix:
|
|
76
|
+
removeDashPrefix: true,
|
|
54
77
|
returnObject: true,
|
|
55
78
|
}).customProperties();
|
|
56
79
|
|
|
57
|
-
const colorsFromPaletteValues = Object.
|
|
80
|
+
const colorsFromPaletteValues = Object.entries(colorsFromPalette) as [string, string][];
|
|
58
81
|
|
|
59
82
|
const colorsFromPaletteWithEnoughDistance =
|
|
60
83
|
minimalColorDistance > 0
|
|
61
|
-
? colorsFromPaletteValues.reduce((enoughDistance: string[], color: string) => {
|
|
84
|
+
? colorsFromPaletteValues.reduce((enoughDistance: [string, string][], color: [string, string]) => {
|
|
62
85
|
if (enoughDistance.includes(color)) {
|
|
63
86
|
return enoughDistance.filter((checkColor) => {
|
|
64
|
-
const distance = colorCalculateDistance({ color1: color, color2: checkColor });
|
|
87
|
+
const distance = colorCalculateDistance({ color1: color[1], color2: checkColor[1] });
|
|
65
88
|
return checkColor === color || (distance && minimalColorDistance <= distance);
|
|
66
89
|
});
|
|
67
90
|
} else {
|
|
@@ -70,14 +93,9 @@ export function getEnabledColorsFromPalette({
|
|
|
70
93
|
}, colorsFromPaletteValues)
|
|
71
94
|
: colorsFromPaletteValues;
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
configId,
|
|
75
|
-
colorsFromPaletteWithEnoughDistance.map((color: string) => {
|
|
76
|
-
return Color(color);
|
|
77
|
-
})
|
|
78
|
-
);
|
|
96
|
+
getEnabledColorPropertiesFromPaletteCache.set(configId, colorsFromPaletteWithEnoughDistance);
|
|
79
97
|
|
|
80
|
-
return
|
|
98
|
+
return getEnabledColorPropertiesFromPaletteCache.get(configId)!;
|
|
81
99
|
}
|
|
82
100
|
|
|
83
101
|
function getColorcode(text: string): ColorOrFalse {
|
|
@@ -3,6 +3,7 @@ import { renderToString } from "react-dom/server";
|
|
|
3
3
|
import * as ReactIs from "react-is";
|
|
4
4
|
|
|
5
5
|
import { TextReducerProps } from "./../../components/TextReducer/TextReducer";
|
|
6
|
+
import { DecodeHtmlEntitiesOptions, utils } from "./../";
|
|
6
7
|
|
|
7
8
|
export interface ReduceToTextFuncType {
|
|
8
9
|
(
|
|
@@ -10,12 +11,12 @@ export interface ReduceToTextFuncType {
|
|
|
10
11
|
* Component or text to reduce HTML markup content to plain text.
|
|
11
12
|
*/
|
|
12
13
|
input: React.ReactNode | React.ReactNode[] | string,
|
|
13
|
-
options?: Pick<TextReducerProps, "maxNodes" | "maxLength">
|
|
14
|
+
options?: Pick<TextReducerProps, "maxNodes" | "maxLength" | "decodeHtmlEntities" | "decodeHtmlEntitiesOptions">
|
|
14
15
|
): string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export const reduceToText: ReduceToTextFuncType = (input, options) => {
|
|
18
|
-
const { maxNodes, maxLength } = options || {};
|
|
19
|
+
const { maxNodes, maxLength, decodeHtmlEntities } = options || {};
|
|
19
20
|
const content: React.ReactNode | React.ReactNode[] = input;
|
|
20
21
|
let nodeCount = 0;
|
|
21
22
|
|
|
@@ -46,6 +47,33 @@ export const reduceToText: ReduceToTextFuncType = (input, options) => {
|
|
|
46
47
|
// Basic HTML cleanup
|
|
47
48
|
text = text.replace(/<[^\s][^>]*>/g, "").replace(/\n/g, " ");
|
|
48
49
|
|
|
50
|
+
if (decodeHtmlEntities) {
|
|
51
|
+
const decodeDefaultOptions = {
|
|
52
|
+
isAttributeValue: true,
|
|
53
|
+
strict: true,
|
|
54
|
+
} as DecodeHtmlEntitiesOptions;
|
|
55
|
+
let decodeErrors = 0;
|
|
56
|
+
// we decode in pieces to apply some error tolerance even in strict mode
|
|
57
|
+
text = text
|
|
58
|
+
.split(" ")
|
|
59
|
+
.map((value) => {
|
|
60
|
+
try {
|
|
61
|
+
return utils.decodeHtmlEntities(value, {
|
|
62
|
+
...decodeDefaultOptions,
|
|
63
|
+
...options?.decodeHtmlEntitiesOptions,
|
|
64
|
+
});
|
|
65
|
+
} catch {
|
|
66
|
+
decodeErrors++;
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.join(" ");
|
|
71
|
+
if (decodeErrors > 0) {
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
console.warn(`${decodeErrors} parse error(s) for decodeHtmlEntities, return un-decoded text`, text);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
49
77
|
if (typeof maxLength === "number") {
|
|
50
78
|
text = text.slice(0, maxLength);
|
|
51
79
|
}
|