1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.KeytipManager = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var Utilities_1 = require("../../Utilities");
|
6 | var KeytipConstants_1 = require("../../utilities/keytips/KeytipConstants");
|
7 |
|
8 |
|
9 |
|
10 | var KeytipManager = (function () {
|
11 | function KeytipManager() {
|
12 | this.keytips = {};
|
13 | this.persistedKeytips = {};
|
14 | this.sequenceMapping = {};
|
15 |
|
16 |
|
17 | this.inKeytipMode = false;
|
18 |
|
19 |
|
20 | this.shouldEnterKeytipMode = true;
|
21 |
|
22 |
|
23 | this.delayUpdatingKeytipChange = false;
|
24 | }
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | KeytipManager.getInstance = function () {
|
31 | return this._instance;
|
32 | };
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | KeytipManager.prototype.init = function (delayUpdatingKeytipChange) {
|
41 | this.delayUpdatingKeytipChange = delayUpdatingKeytipChange;
|
42 | };
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | KeytipManager.prototype.register = function (keytipProps, persisted) {
|
51 | if (persisted === void 0) { persisted = false; }
|
52 | var props = keytipProps;
|
53 | if (!persisted) {
|
54 |
|
55 | props = this.addParentOverflow(keytipProps);
|
56 | this.sequenceMapping[props.keySequences.toString()] = props;
|
57 | }
|
58 |
|
59 | var uniqueKeytip = this._getUniqueKtp(props);
|
60 |
|
61 | persisted
|
62 | ? (this.persistedKeytips[uniqueKeytip.uniqueID] = uniqueKeytip)
|
63 | : (this.keytips[uniqueKeytip.uniqueID] = uniqueKeytip);
|
64 |
|
65 | if (this.inKeytipMode || !this.delayUpdatingKeytipChange) {
|
66 | var event_1 = persisted ? KeytipConstants_1.KeytipEvents.PERSISTED_KEYTIP_ADDED : KeytipConstants_1.KeytipEvents.KEYTIP_ADDED;
|
67 | Utilities_1.EventGroup.raise(this, event_1, {
|
68 | keytip: props,
|
69 | uniqueID: uniqueKeytip.uniqueID,
|
70 | });
|
71 | }
|
72 | return uniqueKeytip.uniqueID;
|
73 | };
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | KeytipManager.prototype.update = function (keytipProps, uniqueID) {
|
81 | var newKeytipProps = this.addParentOverflow(keytipProps);
|
82 | var uniqueKeytip = this._getUniqueKtp(newKeytipProps, uniqueID);
|
83 | var oldKeyTip = this.keytips[uniqueID];
|
84 | if (oldKeyTip) {
|
85 |
|
86 | uniqueKeytip.keytip.visible = oldKeyTip.keytip.visible;
|
87 |
|
88 | this.keytips[uniqueID] = uniqueKeytip;
|
89 |
|
90 | delete this.sequenceMapping[oldKeyTip.keytip.keySequences.toString()];
|
91 | this.sequenceMapping[uniqueKeytip.keytip.keySequences.toString()] = uniqueKeytip.keytip;
|
92 |
|
93 | if (this.inKeytipMode || !this.delayUpdatingKeytipChange) {
|
94 | Utilities_1.EventGroup.raise(this, KeytipConstants_1.KeytipEvents.KEYTIP_UPDATED, {
|
95 | keytip: uniqueKeytip.keytip,
|
96 | uniqueID: uniqueKeytip.uniqueID,
|
97 | });
|
98 | }
|
99 | }
|
100 | };
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | KeytipManager.prototype.unregister = function (keytipToRemove, uniqueID, persisted) {
|
109 | if (persisted === void 0) { persisted = false; }
|
110 | persisted ? delete this.persistedKeytips[uniqueID] : delete this.keytips[uniqueID];
|
111 | !persisted && delete this.sequenceMapping[keytipToRemove.keySequences.toString()];
|
112 | var event = persisted ? KeytipConstants_1.KeytipEvents.PERSISTED_KEYTIP_REMOVED : KeytipConstants_1.KeytipEvents.KEYTIP_REMOVED;
|
113 |
|
114 | if (this.inKeytipMode || !this.delayUpdatingKeytipChange) {
|
115 | Utilities_1.EventGroup.raise(this, event, {
|
116 | keytip: keytipToRemove,
|
117 | uniqueID: uniqueID,
|
118 | });
|
119 | }
|
120 | };
|
121 | |
122 |
|
123 |
|
124 | KeytipManager.prototype.enterKeytipMode = function () {
|
125 | Utilities_1.EventGroup.raise(this, KeytipConstants_1.KeytipEvents.ENTER_KEYTIP_MODE);
|
126 | };
|
127 | |
128 |
|
129 |
|
130 | KeytipManager.prototype.exitKeytipMode = function () {
|
131 | Utilities_1.EventGroup.raise(this, KeytipConstants_1.KeytipEvents.EXIT_KEYTIP_MODE);
|
132 | };
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 | KeytipManager.prototype.getKeytips = function () {
|
139 | var _this = this;
|
140 | return Object.keys(this.keytips).map(function (key) { return _this.keytips[key].keytip; });
|
141 | };
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | KeytipManager.prototype.addParentOverflow = function (keytipProps) {
|
149 | var fullSequence = tslib_1.__spreadArray([], keytipProps.keySequences);
|
150 | fullSequence.pop();
|
151 | if (fullSequence.length !== 0) {
|
152 | var parentKeytip = this.sequenceMapping[fullSequence.toString()];
|
153 | if (parentKeytip && parentKeytip.overflowSetSequence) {
|
154 | return tslib_1.__assign(tslib_1.__assign({}, keytipProps), { overflowSetSequence: parentKeytip.overflowSetSequence });
|
155 | }
|
156 | }
|
157 | return keytipProps;
|
158 | };
|
159 | |
160 |
|
161 |
|
162 | KeytipManager.prototype.menuExecute = function (overflowButtonSequences, keytipSequences) {
|
163 | Utilities_1.EventGroup.raise(this, KeytipConstants_1.KeytipEvents.PERSISTED_KEYTIP_EXECUTE, {
|
164 | overflowButtonSequences: overflowButtonSequences,
|
165 | keytipSequences: keytipSequences,
|
166 | });
|
167 | };
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | KeytipManager.prototype._getUniqueKtp = function (keytipProps, uniqueID) {
|
176 | if (uniqueID === void 0) { uniqueID = Utilities_1.getId(); }
|
177 | return { keytip: tslib_1.__assign({}, keytipProps), uniqueID: uniqueID };
|
178 | };
|
179 | KeytipManager._instance = new KeytipManager();
|
180 | return KeytipManager;
|
181 | }());
|
182 | exports.KeytipManager = KeytipManager;
|
183 |
|
\ | No newline at end of file |