@24i/bigscreen-sdk 1.0.4-alpha.2116 → 1.0.4-alpha.2118
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,12 +1,14 @@
|
|
|
1
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
|
+
import { isRtl } from '@24i/bigscreen-sdk/i18n';
|
|
4
5
|
import { ime } from '@24i/bigscreen-sdk/ime';
|
|
5
6
|
import { noop } from '@24i/bigscreen-sdk/utils/noop';
|
|
6
7
|
import { device, isClickOrEnter } from '@24i/bigscreen-sdk/device';
|
|
7
8
|
import { stopEvent } from '@24i/bigscreen-sdk/utils/stopEvent';
|
|
8
9
|
import { addClass } from '@24i/bigscreen-sdk/utils/addClass';
|
|
9
10
|
import { removeClass } from '@24i/bigscreen-sdk/utils/removeClass';
|
|
11
|
+
import { offsetPosition } from '@24i/bigscreen-sdk/utils/offsetPosition';
|
|
10
12
|
import { handleOverflow } from './handleOverflow';
|
|
11
13
|
import './Input.scss';
|
|
12
14
|
|
|
@@ -38,9 +40,7 @@ export class Input extends Component<Props> implements IFocusable {
|
|
|
38
40
|
|
|
39
41
|
placeholder = createRef<HTMLDivElement>();
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
textPostCaret = createRef<HTMLDivElement>();
|
|
43
|
+
text = createRef<HTMLDivElement>();
|
|
44
44
|
|
|
45
45
|
caret = createRef<HTMLDivElement>();
|
|
46
46
|
|
|
@@ -89,12 +89,10 @@ export class Input extends Component<Props> implements IFocusable {
|
|
|
89
89
|
if (position === null) return;
|
|
90
90
|
const { shouldHandleOverflow } = this.props;
|
|
91
91
|
const value = this.getValue();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
setText(this.textPreCaret, this.filterText(preCaret));
|
|
95
|
-
setText(this.textPostCaret, this.filterText(postCaret));
|
|
92
|
+
setText(this.text, this.filterText(value));
|
|
93
|
+
this.setCaretPosition(position);
|
|
96
94
|
if (shouldHandleOverflow) {
|
|
97
|
-
handleOverflow(this.wrap.current, this.caret.current, this.
|
|
95
|
+
handleOverflow(this.wrap.current, this.caret.current, this.text.current);
|
|
98
96
|
}
|
|
99
97
|
if (this.lastValue !== value) {
|
|
100
98
|
const { onChange } = this.props;
|
|
@@ -116,7 +114,25 @@ export class Input extends Component<Props> implements IFocusable {
|
|
|
116
114
|
if (this.getType() === type) return;
|
|
117
115
|
const value = this.getValue();
|
|
118
116
|
this.nativeInput.current!.type = type;
|
|
119
|
-
setText(this.
|
|
117
|
+
setText(this.text, this.filterText(value));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setCaretPosition(position: number) {
|
|
121
|
+
const textNode = this.text.current!.firstChild;
|
|
122
|
+
if (!textNode) {
|
|
123
|
+
offsetPosition(this.caret, { x: 0 });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const range = new Range();
|
|
127
|
+
range.selectNode(textNode);
|
|
128
|
+
const wholeText = range.getBoundingClientRect();
|
|
129
|
+
range.setStart(textNode, position);
|
|
130
|
+
range.setEnd(textNode, position);
|
|
131
|
+
const caretText = range.getBoundingClientRect();
|
|
132
|
+
const offset = isRtl()
|
|
133
|
+
? wholeText.left - caretText.left
|
|
134
|
+
: wholeText.left + wholeText.width - caretText.left;
|
|
135
|
+
offsetPosition(this.caret, { x: -offset }, false);
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
/**
|
|
@@ -204,11 +220,10 @@ export class Input extends Component<Props> implements IFocusable {
|
|
|
204
220
|
>
|
|
205
221
|
{placeholder}
|
|
206
222
|
</div>
|
|
207
|
-
<div ref={this.
|
|
223
|
+
<div ref={this.text} className="text" dir="auto">
|
|
208
224
|
{this.filterText(value)}
|
|
209
225
|
</div>
|
|
210
226
|
<div ref={this.caret} className="caret" />
|
|
211
|
-
<div ref={this.textPostCaret} className="text" />
|
|
212
227
|
</div>
|
|
213
228
|
</Interactable>
|
|
214
229
|
);
|
|
@@ -2,18 +2,28 @@ import { isRtl } from '@24i/bigscreen-sdk/i18n';
|
|
|
2
2
|
|
|
3
3
|
export const handleOverflow = (
|
|
4
4
|
wrap: HTMLDivElement | null,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
caret: HTMLDivElement | null,
|
|
6
|
+
text: HTMLDivElement | null,
|
|
7
7
|
) => {
|
|
8
|
-
if (!wrap || !
|
|
9
|
-
const wrapWidth = wrap.getBoundingClientRect()
|
|
10
|
-
const caretWidth =
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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';
|
|
18
28
|
}
|
|
19
29
|
};
|
|
@@ -63,9 +63,12 @@ export const formatTime = (duration: number, pattern: string) => {
|
|
|
63
63
|
const unitValues = calculateUnitValues(duration, units);
|
|
64
64
|
let result: string = pattern;
|
|
65
65
|
forEach(matches, (match) => {
|
|
66
|
+
const formatedValue = Number.isNaN(unitValues[match.unit]) ?
|
|
67
|
+
'--' :
|
|
68
|
+
unitValues[match.unit]!.toString().padStart(match.count, '0');
|
|
66
69
|
result = result.replace(
|
|
67
70
|
match.completeMatch,
|
|
68
|
-
|
|
71
|
+
formatedValue,
|
|
69
72
|
);
|
|
70
73
|
});
|
|
71
74
|
return result;
|