@vixoniccom/news-internal 0.4.22 → 0.4.23-dev.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/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.0",
12
12
  "scripts": {
13
13
  "prepublish": "vixonic-module-packager --mode=build",
14
14
  "watch": "vixonic-module-packager --mode=watch",
@@ -1,4 +1,4 @@
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'
@@ -42,26 +42,53 @@ export const FormattedText: React.FunctionComponent<Props> = (props) => {
42
42
  const font = format?.font
43
43
  const alignment = format?.alignment
44
44
  const fontColor = format?.fontColor
45
- const fontSize = format?.fontSize
45
+ const fontSize = format?.fontSize || defaults.fontSize
46
+ const lineHeightPx = (props.lineHeight || 1.2) * fontSize
47
+ const containerRef = useRef<HTMLDivElement>(null)
48
+ const [maxLines, setMaxLines] = useState<number | undefined>(undefined)
49
+
50
+ useLayoutEffect(() => {
51
+ const container = containerRef.current
52
+ if (!container || !props.multiline) return
53
+
54
+ const updateMaxLines = () => {
55
+ const availableHeight = container.clientHeight
56
+ setMaxLines(Math.max(1, Math.floor(availableHeight / lineHeightPx)))
57
+ }
58
+
59
+ updateMaxLines()
60
+ const observer = new ResizeObserver(updateMaxLines)
61
+ observer.observe(container)
62
+ return () => observer.disconnect()
63
+ }, [props.multiline, lineHeightPx])
64
+
46
65
  const containerStyle = {
47
66
  display: 'inline-flex',
48
67
  justifyContent: getHorizontalAlignment(alignment?.horizontal || defaults.alignment),
49
68
  ...props.style
50
69
  }
51
70
 
52
- return <div style={containerStyle}>
71
+ return <div ref={containerRef} style={containerStyle}>
53
72
  <div style={{
54
73
  color: fontColor || defaults.fontColor,
55
74
  width: '100%',
56
75
  fontFamily: font?.filename && `"${parseFontName(font.filename)}"` || undefined,
57
- fontSize: `${fontSize || defaults.fontSize}${props.unit}`,
76
+ fontSize: `${fontSize}${props.unit}`,
58
77
  textAlignLast: alignment?.horizontal || defaults.alignment,
59
78
  lineHeight: props.lineHeight,
60
79
  overflow: 'hidden',
61
- whiteSpace: props.multiline ? 'pre-wrap' : 'nowrap'
80
+ whiteSpace: props.multiline ? 'pre-wrap' : 'nowrap',
81
+ textOverflow: props.multiline ? undefined : 'ellipsis'
62
82
  }}>
63
83
  <div className='ql-editor'
64
- style={{ padding: 0, overflow: 'hidden', textAlign: alignment?.horizontal || defaults.alignment }}
84
+ style={{
85
+ padding: 0,
86
+ overflow: 'hidden',
87
+ textAlign: alignment?.horizontal || defaults.alignment,
88
+ ...(props.multiline && maxLines !== undefined
89
+ ? { display: '-webkit-box', WebkitBoxOrient: 'vertical', WebkitLineClamp: maxLines }
90
+ : undefined)
91
+ }}
65
92
  dangerouslySetInnerHTML={{ __html: sanitizeHtml(html) }}
66
93
  />
67
94
  </div>
@@ -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>