@vnejs/plugins.view.coralina.history 0.0.1 → 0.1.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.
@@ -0,0 +1,7 @@
1
+ export const ZINDEX = 2000;
2
+ export const TRANSITION = 300;
3
+ export const LOC_LABEL = "history";
4
+
5
+ export const VIEW_PROPS = {
6
+ screen: { isDisableAutoread: true, isIgnoreOnScreenshot: true, withBackgroundBlur: true, withBackgroundDark: true, zIndex: ZINDEX, transition: TRANSITION },
7
+ };
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
2
 
3
3
  import { SUBSCRIBE_EVENTS } from "./const/events";
4
+ import * as params from "./const/params";
4
5
 
5
6
  import { HistoryController } from "./modules/controller";
6
7
  import { HistoryView } from "./modules/view";
7
8
 
8
- regPlugin("HISTORY_VIEW", { events: SUBSCRIBE_EVENTS }, [HistoryController, HistoryView]);
9
+ regPlugin("HISTORY_VIEW", { events: SUBSCRIBE_EVENTS, params }, [HistoryController, HistoryView]);
@@ -1,6 +1,6 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class HistoryController extends Module.Controller {
3
+ export class HistoryController extends ModuleController {
4
4
  name = "history.controller";
5
5
 
6
6
  emitHide = () => this.emit(this.EVENTS.HISTORY_VIEW.HIDE);
@@ -14,7 +14,7 @@ export class HistoryController extends Module.Controller {
14
14
  [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
15
15
  [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.emit(this.EVENTS.HISTORY_VIEW.ACCEPT),
16
16
  };
17
- controlsIndex = 3000;
17
+ controlsIndex = this.PARAMS.HISTORY_VIEW.ZINDEX;
18
18
 
19
19
  subscribe = () => {
20
20
  this.on(this.EVENTS.HISTORY_VIEW.SHOW, this.onShow);
@@ -25,22 +25,16 @@ export class HistoryController extends Module.Controller {
25
25
  this.on(this.EVENTS.STATE.SET, this.onStateSet);
26
26
  };
27
27
 
28
- beforeShow = async () =>
29
- this.updateState({
30
- historyLocs: await Promise.all(this.globalState.history.history.map(this.getHistoryLoc)),
31
- history: this.globalState.history.history,
32
- });
28
+ beforeShow = async () => {
29
+ this.maxCurrentItem = this.globalState.history.history.length - 1;
33
30
 
34
- onAccept = async () => {
35
- if (this.currentItem !== null)
36
- await this.emit(this.EVENTS.HISTORY_VIEW.CLICK, { uid: this.globalState.history.history[this.currentItem].uid });
31
+ this.updateState({ historyLocs: await Promise.all(this.globalState.history.history.map(this.getHistoryLoc)), history: this.globalState.history.history });
37
32
  };
38
33
 
39
- onClick = async ({ uid } = {}) => {
40
- if (this.shared.history.storageKeys.includes(uid)) await this.emit(this.EVENTS.HISTORY.LOAD, { uid });
41
- };
34
+ onAccept = () => this.currentItem !== null && this.emit(this.EVENTS.HISTORY_VIEW.CLICK, { uid: this.globalState.history.history[this.currentItem].uid });
35
+ onClick = ({ uid } = {}) => this.shared.history.storageKeys.includes(uid) && this.emit(this.EVENTS.HISTORY.LOAD, { uid });
42
36
 
43
- onStateSet = () => this.emit(this.EVENTS.HISTORY_VIEW.HIDE, { force: true });
37
+ onStateSet = () => this.emit(this.EVENTS.HISTORY_VIEW.HIDE, { isForce: true });
44
38
 
45
- getHistoryLoc = ({ text, label } = {}) => this.getLocTextByKey(label, text);
39
+ getHistoryLoc = ({ label, text } = {}) => this.emitOne(this.EVENTS.LOCS.GET_TEXT, { label, key: text });
46
40
  }
package/modules/view.js CHANGED
@@ -1,12 +1,14 @@
1
- import { Module } from "@vnejs/module";
1
+ import { ModuleView } from "@vnejs/module.components";
2
2
 
3
3
  import { render } from "../view";
4
4
 
5
- export class HistoryView extends Module.View {
5
+ export class HistoryView extends ModuleView {
6
6
  name = "history.view";
7
- locLabel = "history";
8
- animationTime = 300;
9
- renderFunc = render;
7
+
8
+ locLabel = this.PARAMS.HISTORY_VIEW.LOC_LABEL;
9
+ animationTime = this.PARAMS.HISTORY_VIEW.TRANSITION;
10
10
  updateEvent = this.EVENTS.HISTORY_VIEW.UPDATE;
11
- updateHandler = this.onUpdateReactComponent;
11
+
12
+ renderFunc = render;
13
+ updateHandler = this.onUpdateStoreComponent;
12
14
  }
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.history",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major:plugin": "npm run publish:major",
8
+ "publish:minor:plugin": "npm run publish:minor",
9
+ "publish:patch:plugin": "npm run publish:patch",
7
10
  "publish:major": "npm version major && npm publish --access public",
8
11
  "publish:minor": "npm version minor && npm publish --access public",
9
12
  "publish:patch": "npm version patch && npm publish --access public"
10
13
  },
11
14
  "author": "",
12
15
  "license": "ISC",
13
- "description": "",
14
- "peerDependencies": {
15
- "@vnejs/shared": "*",
16
- "@vnejs/module": "*"
17
- }
16
+ "description": ""
18
17
  }
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+
3
+ import { PositionBox, Text } from "@vnejs/uis.base";
4
+
5
+ export class HistoryClose extends React.Component {
6
+ onCloseClick = () => this.props.emit(this.props.EVENTS.HISTORY_VIEW.HIDE);
7
+
8
+ render() {
9
+ const { locs = {} } = this.props;
10
+
11
+ return (
12
+ <PositionBox
13
+ bottom={120}
14
+ left={120}
15
+ >
16
+ <Text
17
+ size={60}
18
+ text={locs.back}
19
+ onClick={this.onCloseClick}
20
+ />
21
+ </PositionBox>
22
+ );
23
+ }
24
+ }
@@ -0,0 +1,64 @@
1
+ import React from "react";
2
+
3
+ import { PositionBox, Text, TextControls } from "@vnejs/uis.base";
4
+
5
+ export class HistoryLines extends React.Component {
6
+ scrollbarWrapRef = React.createRef(null);
7
+
8
+ componentDidUpdate(props, state) {
9
+ if (this.props.isShow && !props.isShow) setImmediate(this.scrollToBottom);
10
+ }
11
+
12
+ scrollToBottom = () => {
13
+ this.scrollbarWrapRef.current.scrollTop = 9999999;
14
+ };
15
+
16
+ onLineClick = (uid) => {
17
+ const { history: { storageKeys } = {} } = this.props.shared;
18
+
19
+ if (Boolean(storageKeys.find((key) => key === uid))) return this.props.emit(this.props.EVENTS.HISTORY_VIEW.CLICK, { uid });
20
+ };
21
+
22
+ mapTexts = ({ text, uid, speaker, meet }, i) => {
23
+ const { historyLocs = [], shared: { history: { storageKeys } = {}, lang = "ru" } = {} } = this.props;
24
+
25
+ const speakers = this.props.PARAMS.TEXT.SPEAKERS_INFO;
26
+
27
+ const { names = {}, speakerColor = "white" } = speakers[speaker] || speakers.default;
28
+ const langNames = names[lang] || names.default;
29
+ const speakerName = langNames[meet] || langNames[langNames.length - 1];
30
+
31
+ return {
32
+ text: (historyLocs && historyLocs[i]) || text,
33
+ value: uid,
34
+ textPrefix: speakerName ? `${speakerName}: ` : undefined,
35
+ colorPrefix: speakerColor,
36
+ weightPrefix: Text.WEIGHT.BOLD,
37
+ isHoverable: Boolean(storageKeys.find((key) => key === uid)),
38
+ };
39
+ };
40
+
41
+ render() {
42
+ const { history = [], currentItem = null } = this.props;
43
+
44
+ return (
45
+ <PositionBox
46
+ top={120}
47
+ left={120}
48
+ right={120}
49
+ >
50
+ <TextControls
51
+ selectedIndex={currentItem}
52
+ scrollbarWrapRef={this.scrollbarWrapRef}
53
+ wrapHeight={1800}
54
+ withScrollbar={true}
55
+ flexGap={36}
56
+ textSize={60}
57
+ textMarginTop={36}
58
+ texts={history.map(this.mapTexts)}
59
+ onClick={this.onLineClick}
60
+ />
61
+ </PositionBox>
62
+ );
63
+ }
64
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./HistoryClose";
2
+ export * from "./HistoryLines";
package/view/index.jsx CHANGED
@@ -1,66 +1,26 @@
1
- import React from "react";
1
+ import React, { useEffect, useMemo, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
- import { cn } from "@bem-react/classname";
4
+ import { Screen } from "@vnejs/uis.base";
5
5
 
6
- import "./index.styl";
6
+ import { HistoryClose, HistoryLines } from "./components";
7
7
 
8
- const b = cn("History");
8
+ const History = ({ store, onMount, ...props } = {}) => {
9
+ const [{ isShow = false, isForce = false, locs = {}, history = [], historyLocs = [], currentItem = null }, setState] = useState({});
9
10
 
10
- class History extends React.Component {
11
- state = { isShow: false, history: [], storageKeys: [] };
12
- linesRef = React.createRef(null);
13
- componentDidUpdate(props, state) {
14
- if (this.state.isShow && !state.isShow) setImmediate(this.scrollLinesToBottom);
15
- }
16
- onCloseClick = () => this.props.emit(this.props.EVENTS.HISTORY_VIEW.HIDE);
17
- onLineClick = (e) => {
18
- const { uid } = e.currentTarget.dataset;
11
+ useEffect(() => store.subscribe(setState), []);
12
+ useEffect(() => void onMount(), []);
19
13
 
20
- this.props.emit(this.props.EVENTS.HISTORY_VIEW.CLICK, { uid });
21
- };
22
- renderHistoryLine = ({ uid, text, speaker, meet } = {}, i) => {
23
- const { historyLocs = [], currentItem } = this.state;
24
- const { history: { storageKeys } = {}, speakers = {}, lang = "ru" } = this.props.shared;
25
- const isActive = Boolean(storageKeys.find((key) => key === uid));
26
- const { names = {}, speakerColor = "white" } = speakers[speaker] || speakers.default;
27
- const langNames = names[lang] || names.default;
28
- const speakerName = langNames[meet] || langNames[langNames.length - 1];
29
- const realText = (historyLocs && historyLocs[i]) || text;
14
+ const propsScreen = useMemo(() => ({ ...props.PARAMS.HISTORY_VIEW.VIEW_PROPS.screen, isShow, isForce }), [isShow, isForce]);
15
+ const propsLines = useMemo(() => ({ ...props, isShow, history, historyLocs, currentItem }), [isShow, history, historyLocs, currentItem]);
16
+ const propsClose = useMemo(() => ({ ...props, locs }), [locs]);
30
17
 
31
- return (
32
- <div
33
- className={b("line", { active: isActive, disabled: !isActive, isCurrent: currentItem === i }, ["textWrap_60"])}
34
- key={uid}
35
- data-uid={uid}
36
- onClick={isActive ? this.onLineClick : undefined}
37
- >
38
- <span className={b("lineSpeaker", ["text"])} style={{ color: speakerColor }}>
39
- {speakerName && <>{speakerName}: </>}
40
- </span>
41
- <span className={b("lineText", ["text"])}>{realText}</span>
42
- </div>
43
- );
44
- };
45
- scrollLinesToBottom = () => {
46
- this.linesRef.current.scrollTop = 9999999;
47
- };
48
- render() {
49
- const { isShow = false, isForce = false, history = [], locs = {} } = this.state;
18
+ return (
19
+ <Screen {...propsScreen}>
20
+ <HistoryLines {...propsLines} />
21
+ <HistoryClose {...propsClose} />
22
+ </Screen>
23
+ );
24
+ };
50
25
 
51
- return (
52
- <div className={b({ isShow, isForce })} id="History" data-html2canvas-ignore="1">
53
- <div className={b("wrap")}>
54
- <div className={b("lines")} ref={this.linesRef}>
55
- {history.map(this.renderHistoryLine)}
56
- </div>
57
- <div className={b("back", ["textWrap_60"])} onClick={this.onCloseClick}>
58
- <span className="text">{locs.back}</span>
59
- </div>
60
- </div>
61
- </div>
62
- );
63
- }
64
- }
65
-
66
- export const render = (props, root, resolve) => ReactDOM.render(<History {...props} />, root, resolve);
26
+ export const render = (props, root) => ReactDOM.render(<History {...props} />, root);
package/view/index.styl DELETED
@@ -1,77 +0,0 @@
1
- .History
2
- position: absolute
3
- top: 0
4
- right: 0
5
- bottom: 0
6
- left: 0
7
- z-index: 4000
8
- backdrop-filter: blur(5px) brightness(0.5)
9
- background: rgba(0,0,0,0.4)
10
- opacity: 0
11
- pointer-events: none
12
- display: flex
13
- justify-content: center
14
- align-items: center
15
- font-family: Montserrat
16
-
17
- &-wrap
18
- position: absolute
19
- top: 1.25%
20
- right: 2.25%
21
- bottom: 1.25%
22
- left: 2.25%
23
- z-index: 4001
24
- box-sizing: border-box
25
- display: flex
26
- align-items: initial
27
- justify-content: space-between
28
- align-items: flex-start
29
- flex-direction: column
30
-
31
- &-linesWrap
32
- position relative
33
-
34
- &-lines
35
- overflow: auto
36
- display: flex
37
- flex-direction: column
38
- align-items: flex-start
39
- height: calc(1900 / 2100 * 100%)
40
-
41
- &-line
42
- color: rgb(255, 255, 255, 1)
43
- opacity: 0.6
44
- border-radius: 8px
45
- transition: opacity 300ms, outline 300ms
46
-
47
- &_active
48
- cursor: pointer
49
-
50
- &:hover
51
- opacity: 1
52
-
53
- &_isCurrent
54
- outline: 2px solid white
55
-
56
- & ~ &
57
- margin-top: 1%
58
-
59
- &-lineSpeaker
60
- font-weight: 700
61
-
62
- &-back
63
- color: white
64
- cursor: pointer
65
- transition: opacity 300ms
66
- flex-shrink: 0
67
- opacity 0.6
68
-
69
- &:hover
70
- opacity: 1
71
-
72
- &_isShow
73
- opacity: 1
74
- pointer-events: all
75
-
76
- &:not(&_isForce)
77
- transition: opacity 300ms