@vnejs/plugins.view.coralina.history 0.0.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 SUBSCRIBE_EVENTS = {
2
+ HIDE: "vne:history_view:hide",
3
+ SHOW: "vne:history_view:show",
4
+ CLICK: "vne:history_view:click",
5
+ UPDATE: "vne:history_view:update",
6
+ ACCEPT: "vne:history_view:accept",
7
+ };
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import { SUBSCRIBE_EVENTS } from "./const/events";
4
+
5
+ import { HistoryController } from "./modules/controller";
6
+ import { HistoryView } from "./modules/view";
7
+
8
+ regPlugin("HISTORY_VIEW", { events: SUBSCRIBE_EVENTS }, [HistoryController, HistoryView]);
@@ -0,0 +1,46 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class HistoryController extends Module.Controller {
4
+ name = "history.controller";
5
+
6
+ emitHide = () => this.emit(this.EVENTS.HISTORY_VIEW.HIDE);
7
+
8
+ updateEvent = this.EVENTS.HISTORY_VIEW.UPDATE;
9
+ controls = {
10
+ [this.CONST.CONTROLS.BUTTONS.BACK]: this.emitHide,
11
+ [this.CONST.CONTROLS.BUTTONS.MENU]: this.emitHide,
12
+ [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitHide,
13
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
14
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
15
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.emit(this.EVENTS.HISTORY_VIEW.ACCEPT),
16
+ };
17
+ controlsIndex = 3000;
18
+
19
+ subscribe = () => {
20
+ this.on(this.EVENTS.HISTORY_VIEW.SHOW, this.onShow);
21
+ this.on(this.EVENTS.HISTORY_VIEW.HIDE, this.onHide);
22
+ this.on(this.EVENTS.HISTORY_VIEW.ACCEPT, this.onAccept);
23
+ this.on(this.EVENTS.HISTORY_VIEW.CLICK, this.onClick);
24
+
25
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
26
+ };
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
+ });
33
+
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 });
37
+ };
38
+
39
+ onClick = async ({ uid } = {}) => {
40
+ if (this.shared.history.storageKeys.includes(uid)) await this.emit(this.EVENTS.HISTORY.LOAD, { uid });
41
+ };
42
+
43
+ onStateSet = () => this.emit(this.EVENTS.HISTORY_VIEW.HIDE, { force: true });
44
+
45
+ getHistoryLoc = ({ text, label } = {}) => this.getLocTextByKey(label, text);
46
+ }
@@ -0,0 +1,12 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class HistoryView extends Module.View {
6
+ name = "history.view";
7
+ locLabel = "history";
8
+ animationTime = 300;
9
+ renderFunc = render;
10
+ updateEvent = this.EVENTS.HISTORY_VIEW.UPDATE;
11
+ updateHandler = this.onUpdateReactComponent;
12
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@vnejs/plugins.view.coralina.history",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major": "npm version major && npm publish --access public",
8
+ "publish:minor": "npm version minor && npm publish --access public",
9
+ "publish:patch": "npm version patch && npm publish --access public"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "description": "",
14
+ "peerDependencies": {
15
+ "@vnejs/shared": "*",
16
+ "@vnejs/module": "*"
17
+ }
18
+ }
package/view/index.jsx ADDED
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom";
3
+
4
+ import { cn } from "@bem-react/classname";
5
+
6
+ import "./index.styl";
7
+
8
+ const b = cn("History");
9
+
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;
19
+
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;
30
+
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;
50
+
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);
@@ -0,0 +1,77 @@
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