@vixoniccom/news-internal 0.4.22 → 0.4.23-dev.1

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/build.zip CHANGED
Binary file
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "author": {
9
9
  "name": ""
10
10
  },
11
- "version": "0.4.22",
11
+ "version": "0.4.23-dev.1",
12
12
  "scripts": {
13
13
  "prepublish": "vixonic-module-packager --mode=build",
14
14
  "watch": "vixonic-module-packager --mode=watch",
@@ -1,7 +1,8 @@
1
- import React from 'react'
1
+ import React, { useLayoutEffect, useRef, useState } from 'react'
2
2
  import { TextFormat } from '@vixoniccom/modules'
3
3
  import { parseFontName } from '../FontLoader'
4
4
  import DOMPurify from 'dompurify'
5
+ import './styles.css'
5
6
 
6
7
  const sanitizeHtml = (html?: string): string => {
7
8
  return html ? DOMPurify.sanitize(html, {
@@ -42,26 +43,53 @@ export const FormattedText: React.FunctionComponent<Props> = (props) => {
42
43
  const font = format?.font
43
44
  const alignment = format?.alignment
44
45
  const fontColor = format?.fontColor
45
- const fontSize = format?.fontSize
46
+ const fontSize = format?.fontSize || defaults.fontSize
47
+ const lineHeightPx = (props.lineHeight || 1.2) * fontSize
48
+ const containerRef = useRef<HTMLDivElement>(null)
49
+ const [maxLines, setMaxLines] = useState<number | undefined>(undefined)
50
+
51
+ useLayoutEffect(() => {
52
+ const container = containerRef.current
53
+ if (!container || !props.multiline) return
54
+
55
+ const updateMaxLines = () => {
56
+ const availableHeight = container.clientHeight
57
+ setMaxLines(Math.max(1, Math.floor(availableHeight / lineHeightPx)))
58
+ }
59
+
60
+ updateMaxLines()
61
+ const observer = new ResizeObserver(updateMaxLines)
62
+ observer.observe(container)
63
+ return () => observer.disconnect()
64
+ }, [props.multiline, lineHeightPx])
65
+
46
66
  const containerStyle = {
47
67
  display: 'inline-flex',
48
68
  justifyContent: getHorizontalAlignment(alignment?.horizontal || defaults.alignment),
49
69
  ...props.style
50
70
  }
51
71
 
52
- return <div style={containerStyle}>
72
+ return <div ref={containerRef} style={containerStyle}>
53
73
  <div style={{
54
74
  color: fontColor || defaults.fontColor,
55
75
  width: '100%',
56
76
  fontFamily: font?.filename && `"${parseFontName(font.filename)}"` || undefined,
57
- fontSize: `${fontSize || defaults.fontSize}${props.unit}`,
77
+ fontSize: `${fontSize}${props.unit}`,
58
78
  textAlignLast: alignment?.horizontal || defaults.alignment,
59
79
  lineHeight: props.lineHeight,
60
80
  overflow: 'hidden',
61
- whiteSpace: props.multiline ? 'pre-wrap' : 'nowrap'
81
+ whiteSpace: props.multiline ? 'pre-wrap' : 'nowrap',
82
+ textOverflow: props.multiline ? undefined : 'ellipsis'
62
83
  }}>
63
84
  <div className='ql-editor'
64
- style={{ padding: 0, overflow: 'hidden', textAlign: alignment?.horizontal || defaults.alignment }}
85
+ style={{
86
+ padding: 0,
87
+ overflow: 'hidden',
88
+ textAlign: alignment?.horizontal || defaults.alignment,
89
+ ...(props.multiline && maxLines !== undefined
90
+ ? { display: '-webkit-box', WebkitBoxOrient: 'vertical', WebkitLineClamp: maxLines }
91
+ : undefined)
92
+ }}
65
93
  dangerouslySetInnerHTML={{ __html: sanitizeHtml(html) }}
66
94
  />
67
95
  </div>
@@ -0,0 +1,14 @@
1
+ .ql-editor p,
2
+ .ql-editor ol,
3
+ .ql-editor ul,
4
+ .ql-editor pre,
5
+ .ql-editor blockquote,
6
+ .ql-editor h1,
7
+ .ql-editor h2,
8
+ .ql-editor h3,
9
+ .ql-editor h4,
10
+ .ql-editor h5,
11
+ .ql-editor h6 {
12
+ margin: 0;
13
+ padding: 0;
14
+ }
@@ -16,19 +16,22 @@ export const TextContainer: React.FunctionComponent<Props> = (props) => {
16
16
  flexDirection: 'column',
17
17
  justifyContent: parameters.textAlignment || 'center',
18
18
  height: '100%',
19
- flex: 1
19
+ flex: 1,
20
+ overflow: 'hidden'
20
21
  }}>
21
22
  {parameters.titleEnabled && <FormattedText text={item.title || ''} unit={'px'}
22
23
  format={parameters.titleFormat} lineHeight={parameters.titleLineHeight}
23
- style={
24
- (parameters.textSeparation && parameters.titleEnabled && parameters.descriptionEnabled)
24
+ style={{
25
+ flexShrink: 0,
26
+ ...(parameters.textSeparation && parameters.titleEnabled && parameters.descriptionEnabled
25
27
  ? { marginBottom: Number(parameters.textSeparation) }
26
- : undefined
27
- } multiline />
28
+ : undefined)
29
+ }} multiline />
28
30
  }
29
31
  {parameters.descriptionEnabled && <FormattedHtmlText html={item.description || ''} unit={'px'}
30
32
  format={parameters.descriptionFormat} lineHeight={parameters.descriptionLineHeight}
31
33
  defaults={{ fontSize: 10, fontColor: 'black', alignment: 'left' }}
34
+ style={{ flex: 1, minHeight: 0, overflow: 'hidden' }}
32
35
  multiline />
33
36
  }
34
37
  </div>