@24i/bigscreen-sdk 1.0.43 → 1.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24i/bigscreen-sdk",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "SmartApps BIGscreen SDK monorepo",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,7 +18,6 @@ import type {
18
18
  TealiumAnalyticsConfiguration,
19
19
  TeaResult,
20
20
  TealiumDataMapper,
21
- TealiumCustomConfiguration,
22
21
  CustomMappers,
23
22
  TeaDynamicCoreResult,
24
23
  } from './types';
@@ -75,7 +74,7 @@ export class TealiumAnalytics implements AnalyticsClient {
75
74
  datasource,
76
75
  customMappers,
77
76
  dataMapper = {} as TealiumDataMapper,
78
- } = this.config || {} as TealiumCustomConfiguration;
77
+ } = this.config;
79
78
  const { entity, platformShort, platformType, appType } = dataMapper;
80
79
  this.customMappers = customMappers;
81
80
  this.constantPayload = {
@@ -19,7 +19,7 @@ export interface LanguageMapper {
19
19
  export type CustomMappers = Partial<Record<EVENTS, EventMappingFunction>>;
20
20
 
21
21
  export type TealiumDataMapper = {
22
- appType: TeaAppType,
22
+ appType?: TeaAppType,
23
23
  entity: string, // e.g: 'rfe'
24
24
  platformShort?: string,
25
25
  platformType?: string,
@@ -305,8 +305,8 @@ export class UnifiedGridController<T> implements IUnifiedGridController<T> {
305
305
  for (let i = 1; i <= scrollToIndex; i++) {
306
306
  this.scroll(backwards ? lastScrollIndex - i : lastScrollIndex + i, animate);
307
307
  }
308
- base.index = dataIndex;
309
308
  }
309
+ base.index = dataIndex;
310
310
  this.focusCurrentItem();
311
311
  base.mrcuRef.current?.handleArrowState();
312
312
  }
@@ -60,6 +60,3 @@ The reason for no styling is to limit unnecessary CSS code that would be overrid
60
60
  `.native-input-wrap` is set to `display: none`. This is the native input used on the background.
61
61
 
62
62
  `.input-field` is a custom component that should look like input field with possibility of custom styling.
63
-
64
- `.caret` position is counted from the left side of the input in LTR layout and from the right side of the
65
- input in RTL layout.
@@ -1,4 +1,4 @@
1
- import { createRef, Component, DeclareProps } from '@24i/bigscreen-sdk/jsx';
1
+ import { createRef, Component, setText, DeclareProps } from '@24i/bigscreen-sdk/jsx';
2
2
  import { Interactable } from '@24i/bigscreen-sdk/interactable';
3
3
  import { IFocusable } from '@24i/bigscreen-sdk/focus';
4
4
  import { isRtl } from '@24i/bigscreen-sdk/i18n';
@@ -9,7 +9,7 @@ import { stopEvent } from '@24i/bigscreen-sdk/utils/stopEvent';
9
9
  import { addClass } from '@24i/bigscreen-sdk/utils/addClass';
10
10
  import { removeClass } from '@24i/bigscreen-sdk/utils/removeClass';
11
11
  import { offsetPosition } from '@24i/bigscreen-sdk/utils/offsetPosition';
12
- import { checkCharOrderMishmash, handleOverflow } from './utils';
12
+ import { handleOverflow } from './handleOverflow';
13
13
  import './Input.scss';
14
14
 
15
15
  type Props = {
@@ -42,8 +42,6 @@ export class Input extends Component<Props> implements IFocusable {
42
42
 
43
43
  caret = createRef<HTMLDivElement>();
44
44
 
45
- caretPosition = 0;
46
-
47
45
  isInputting = false;
48
46
 
49
47
  lastValue: string;
@@ -70,11 +68,6 @@ export class Input extends Component<Props> implements IFocusable {
70
68
  this.isPlaceholderVisible = value.length === 0;
71
69
  }
72
70
 
73
- componentDidMount() {
74
- const { value } = this.props;
75
- if (value) this.setText(value);
76
- }
77
-
78
71
  getType() {
79
72
  return this.nativeInput.current?.type;
80
73
  }
@@ -92,10 +85,13 @@ export class Input extends Component<Props> implements IFocusable {
92
85
 
93
86
  onCaretPositionChange = (position: number | null) => {
94
87
  if (position === null) return;
88
+ const { shouldHandleOverflow } = this.props;
95
89
  const value = this.getValue();
96
- this.setText(value);
97
- this.updateCaretPosition(position);
98
- this.updateTextOverflow();
90
+ setText(this.text, this.filterText(value));
91
+ this.setCaretPosition(position);
92
+ if (shouldHandleOverflow) {
93
+ handleOverflow(this.wrap.current, this.caret.current, this.text.current);
94
+ }
99
95
  if (this.lastValue !== value) {
100
96
  const { onChange } = this.props;
101
97
  this.lastValue = value;
@@ -110,59 +106,33 @@ export class Input extends Component<Props> implements IFocusable {
110
106
 
111
107
  setValue(value: string) {
112
108
  this.nativeInput.current!.value = value;
113
- this.setText(value);
114
109
  }
115
110
 
116
111
  setType(type: Props['type']) {
117
112
  if (this.getType() === type) return;
118
113
  const value = this.getValue();
119
114
  this.nativeInput.current!.type = type;
120
- this.setText(value);
115
+ setText(this.text, this.filterText(value));
121
116
  }
122
117
 
123
- setText(text: string): void {
124
- const filtered = this.filterText(text);
125
- this.renderText(filtered);
126
- }
127
-
128
- updateCaretPosition(position: number) {
118
+ setCaretPosition(position: number) {
129
119
  const textNode = this.text.current!.firstChild;
130
- if (!textNode || position <= 0) {
131
- this.caretPosition = 0;
120
+ if (!textNode) {
132
121
  offsetPosition(this.caret, { x: 0 });
133
122
  return;
134
123
  }
135
- const wholeTextDimensions = this.text.current!.getBoundingClientRect();
136
- if (position >= this.text.current!.children.length) {
137
- const offset = wholeTextDimensions.right - wholeTextDimensions.left;
138
- this.caretPosition = isRtl() ? -offset : offset;
139
- offsetPosition(this.caret, { x: this.caretPosition }, false);
140
- return;
141
- }
142
- const charNode = this.text.current!.children[position - 1];
143
- const charDimensions = charNode!.getBoundingClientRect();
144
- const isCharMishmash = checkCharOrderMishmash(this.text.current!, position - 1);
145
- if (isRtl()) {
146
- if (isCharMishmash) {
147
- this.caretPosition = charDimensions.right - wholeTextDimensions.right;
148
- } else {
149
- this.caretPosition = charDimensions.left - wholeTextDimensions.right;
150
- }
151
- } else if (isCharMishmash) {
152
- this.caretPosition = charDimensions.left - wholeTextDimensions.left;
153
- } else {
154
- this.caretPosition = charDimensions.right - wholeTextDimensions.left;
155
- }
156
- offsetPosition(this.caret, { x: this.caretPosition }, false);
157
- }
158
-
159
- updateTextOverflow() {
160
- const { shouldHandleOverflow } = this.props;
161
- if (!shouldHandleOverflow) return;
162
- const textMargin = handleOverflow(
163
- this.wrap.current, this.caret.current, this.text.current,
164
- );
165
- offsetPosition(this.caret, { x: this.caretPosition - textMargin }, false);
124
+ const range = new Range();
125
+ range.selectNode(textNode);
126
+ const wholeText = range.getBoundingClientRect();
127
+ range.setStart(textNode, 0);
128
+ range.setEnd(textNode, position);
129
+ const caretText = range.getBoundingClientRect();
130
+ const [initialCaretPosition, currentCarretPosition, offsetBase] = isRtl()
131
+ ? [wholeText.right, caretText.left, wholeText.left]
132
+ : [wholeText.left, caretText.right, wholeText.right];
133
+ const caretPos = position === 0 ? initialCaretPosition : currentCarretPosition;
134
+ const offset = offsetBase - caretPos;
135
+ offsetPosition(this.caret, { x: -offset }, false);
166
136
  }
167
137
 
168
138
  /**
@@ -226,14 +196,6 @@ export class Input extends Component<Props> implements IFocusable {
226
196
  return text.replace(/ /g, NBSP);
227
197
  }
228
198
 
229
- renderText(text: string): void {
230
- const chars: JSX.Element[] = [];
231
- for (let i = 0; i < text.length; i++) {
232
- chars.push(<span className="char">{text[i]}</span>);
233
- }
234
- this.clearMount(chars, this.text);
235
- }
236
-
237
199
  render() {
238
200
  const { value, type, placeholder, onFocus, onBlur } = this.props;
239
201
  return (
@@ -258,7 +220,9 @@ export class Input extends Component<Props> implements IFocusable {
258
220
  >
259
221
  {placeholder}
260
222
  </div>
261
- <div ref={this.text} className="text" />
223
+ <div ref={this.text} className="text">
224
+ {this.filterText(value)}
225
+ </div>
262
226
  <div ref={this.caret} className="caret" />
263
227
  </div>
264
228
  </Interactable>
@@ -0,0 +1,29 @@
1
+ import { isRtl } from '@24i/bigscreen-sdk/i18n';
2
+
3
+ export const handleOverflow = (
4
+ wrap: HTMLDivElement | null,
5
+ caret: HTMLDivElement | null,
6
+ text: HTMLDivElement | null,
7
+ ) => {
8
+ if (!wrap || !caret || !text) return;
9
+ const { width: wrapWidth, left: wrapLeft } = wrap.getBoundingClientRect();
10
+ const { width: caretWidth, left: caretLeft } = caret.getBoundingClientRect();
11
+ const textMargin = parseInt(text.dataset.margin!, 10) || 0;
12
+ const caretOffset = isRtl()
13
+ ? caretLeft + textMargin - caretWidth
14
+ : caretLeft - textMargin + caretWidth;
15
+ if (!isRtl() && wrapWidth + wrapLeft < caretOffset) {
16
+ const margin = -(caretOffset - wrapWidth - wrapLeft);
17
+ text.style.marginLeft = `${margin}px`;
18
+ text.style.marginRight = '0px';
19
+ text.dataset.margin = margin.toString();
20
+ } else if (isRtl() && caretOffset < wrapLeft) {
21
+ const margin = -(wrapLeft - caretOffset);
22
+ text.style.marginLeft = '0px';
23
+ text.style.marginRight = `${margin}px`;
24
+ text.dataset.margin = margin.toString();
25
+ } else {
26
+ text.style.marginLeft = '0px';
27
+ text.style.marginRight = '0px';
28
+ }
29
+ };
@@ -1,71 +0,0 @@
1
- import { isRtl } from '@24i/bigscreen-sdk/i18n';
2
-
3
- /**
4
- * Handles overflowing text in the input by moving with the inner
5
- * text element.
6
- * @param wrap input wrapper
7
- * @param caret caret element
8
- * @param text input inner text element
9
- * @returns value how much is text element moved
10
- */
11
- export const handleOverflow = (
12
- wrap: HTMLDivElement | null,
13
- caret: HTMLDivElement | null,
14
- text: HTMLDivElement | null,
15
- ) => {
16
- if (!wrap || !caret || !text) return 0;
17
- const { width: wrapWidth, left: wrapLeft } = wrap.getBoundingClientRect();
18
- const { width: caretWidth, left: caretLeft } = caret.getBoundingClientRect();
19
- const caretOffset = isRtl() ? caretLeft - caretWidth : caretLeft + caretWidth;
20
- if (!isRtl() && wrapWidth + wrapLeft < caretOffset) {
21
- const margin = -(caretOffset - wrapWidth - wrapLeft);
22
- text.style.marginLeft = `${margin}px`;
23
- text.style.marginRight = '0px';
24
- return margin;
25
- }
26
- if (isRtl() && caretOffset < wrapLeft) {
27
- const margin = -(wrapLeft - caretOffset);
28
- text.style.marginLeft = '0px';
29
- text.style.marginRight = `${margin}px`;
30
- return margin;
31
- }
32
- text.style.marginLeft = '0px';
33
- text.style.marginRight = '0px';
34
- return 0;
35
- };
36
-
37
- /**
38
- * Check for char element position mishmash in the input's text element. This is
39
- * necessary to recognize if the char is in the wrong direction than it's position
40
- * in children collection, this means that the char is LTR char in RTL scheme or RTL
41
- * char in LTR scheme.
42
- * @param text input inner text element
43
- * @param position position of the char in children collection
44
- * @returns true if char has position mishmash
45
- */
46
- export const checkCharOrderMishmash = (text: HTMLDivElement, position: number) => {
47
- const { children } = text!;
48
- if (!children.length) return false;
49
- const charOffsets: {
50
- index: number,
51
- offset: number,
52
- }[] = [];
53
- for (let i = 0; i < children.length; i++) {
54
- charOffsets.push({
55
- index: i,
56
- offset: (children[i] as HTMLElement).getBoundingClientRect().left,
57
- });
58
- }
59
- charOffsets.sort((a, b) => {
60
- if (a.offset < b.offset) return isRtl() ? 1 : -1;
61
- if (a.offset > b.offset) return isRtl() ? -1 : 1;
62
- return 0;
63
- });
64
- const lastPos = children.length - 1;
65
- const posBefore = position - 1;
66
- const mishmashBefore = posBefore < 0
67
- ? false : charOffsets[posBefore].index !== posBefore;
68
- const mishmashCurrent = charOffsets[position].index !== position;
69
- if (mishmashCurrent) return true;
70
- return !mishmashCurrent && mishmashBefore && position !== lastPos;
71
- };