Browse Source

Clean

pull/4134/head
Artur Arseniev 5 years ago
parent
commit
614ff3447a
  1. 3
      src/asset_manager/index.js
  2. 18
      src/block_manager/index.js
  3. 1
      src/keymaps/index.js
  4. 2
      src/style_manager/index.js
  5. 31
      src/utils/keymaster.js

3
src/asset_manager/index.js

@ -499,8 +499,9 @@ export default () => {
assetsVis.reset(); assetsVis.reset();
fu && fu.remove(); fu && fu.remove();
am && am.remove(); am && am.remove();
[assets, am, fu].forEach(i => (i = null)); [assets, assetsVis, am, fu].forEach(i => (i = null));
this._bhv = {}; this._bhv = {};
this.all = {};
c = {}; c = {};
}, },
}; };

18
src/block_manager/index.js

@ -91,7 +91,7 @@ export default () => {
drag: evDrag, drag: evDrag,
dragStart: evDragStart, dragStart: evDragStart,
dragEnd: evDragStop, dragEnd: evDragStop,
custom: evCustom custom: evCustom,
}, },
init(config = {}) { init(config = {}) {
@ -126,7 +126,7 @@ export default () => {
container: bhv.container, container: bhv.container,
dragStart: (block, ev) => this.startDrag(block, ev), dragStart: (block, ev) => this.startDrag(block, ev),
drag: ev => this.__drag(ev), drag: ev => this.__drag(ev),
dragStop: cancel => this.endDrag(cancel) dragStop: cancel => this.endDrag(cancel),
}; };
}, },
@ -185,7 +185,7 @@ export default () => {
__behaviour(opts = {}) { __behaviour(opts = {}) {
return (this._bhv = { return (this._bhv = {
...(this._bhv || {}), ...(this._bhv || {}),
...opts ...opts,
}); });
}, },
@ -343,10 +343,7 @@ export default () => {
if (opts.external) { if (opts.external) {
const collection = new Blocks(toRender); const collection = new Blocks(toRender);
return new BlocksView( return new BlocksView({ collection, categories }, { ...c, ...opts }).render().el;
{ collection, categories },
{ ...c, ...opts }
).render().el;
} }
if (blocksView) { if (blocksView) {
@ -368,6 +365,11 @@ export default () => {
colls.map(c => c.reset()); colls.map(c => c.reset());
blocksView && blocksView.remove(); blocksView && blocksView.remove();
c = {}; c = {};
} blocks = {};
blocksVisible = {};
blocksView = {};
categories = [];
this.all = {};
},
}; };
}; };

1
src/keymaps/index.js

@ -222,6 +222,7 @@ export default () => {
*/ */
removeAll() { removeAll() {
Object.keys(this.keymaps).forEach(keymap => this.remove(keymap)); Object.keys(this.keymaps).forEach(keymap => this.remove(keymap));
keymaster.handlers = {};
return this; return this;
}, },

2
src/style_manager/index.js

@ -753,6 +753,8 @@ export default () => {
[properties, sectors, SectView].forEach(i => (i = {})); [properties, sectors, SectView].forEach(i => (i = {}));
this.em = {}; this.em = {};
this.config = {}; this.config = {};
this.builtIn = {};
this.model = {};
}, },
}; };
}; };

31
src/utils/keymaster.js

@ -7,7 +7,7 @@ var k,
16: false, 16: false,
18: false, 18: false,
17: false, 17: false,
91: false 91: false,
}, },
_scope = 'all', _scope = 'all',
// modifier keys // modifier keys
@ -21,7 +21,7 @@ var k,
ctrl: 17, ctrl: 17,
control: 17, control: 17,
'⌘': 91, '⌘': 91,
command: 91 command: 91,
}, },
// special keys // special keys
_MAP = { _MAP = {
@ -53,9 +53,9 @@ var k,
"'": 222, "'": 222,
'[': 219, '[': 219,
']': 221, ']': 221,
'\\': 220 '\\': 220,
}, },
code = function(x) { code = function (x) {
return _MAP[x] || x.toUpperCase().charCodeAt(0); return _MAP[x] || x.toUpperCase().charCodeAt(0);
}, },
_downKeys = []; _downKeys = [];
@ -82,7 +82,7 @@ var modifierMap = {
16: 'shiftKey', 16: 'shiftKey',
18: 'altKey', 18: 'altKey',
17: 'ctrlKey', 17: 'ctrlKey',
91: 'metaKey' 91: 'metaKey',
}; };
function updateModifierKey(event) { function updateModifierKey(event) {
@ -126,20 +126,10 @@ function dispatch(event) {
// check if modifiers match if any // check if modifiers match if any
modifiersMatch = handler.mods.length > 0; modifiersMatch = handler.mods.length > 0;
for (k in _mods) for (k in _mods)
if ( if ((!_mods[k] && index(handler.mods, +k) > -1) || (_mods[k] && index(handler.mods, +k) == -1))
(!_mods[k] && index(handler.mods, +k) > -1) ||
(_mods[k] && index(handler.mods, +k) == -1)
)
modifiersMatch = false; modifiersMatch = false;
// call the handler and stop the event if neccessary // call the handler and stop the event if neccessary
if ( if ((handler.mods.length == 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91]) || modifiersMatch) {
(handler.mods.length == 0 &&
!_mods[16] &&
!_mods[18] &&
!_mods[17] &&
!_mods[91]) ||
modifiersMatch
) {
if (handler.method(event, handler) === false) { if (handler.method(event, handler) === false) {
if (event.preventDefault) event.preventDefault(); if (event.preventDefault) event.preventDefault();
else event.returnValue = false; else event.returnValue = false;
@ -202,7 +192,7 @@ function assignKey(key, scope, method) {
scope: scope, scope: scope,
method: method, method: method,
key: keys[i], key: keys[i],
mods: mods mods: mods,
}); });
} }
} }
@ -310,7 +300,7 @@ function getMods(key) {
function addEvent(object, event, method) { function addEvent(object, event, method) {
if (object.addEventListener) object.addEventListener(event, method, false); if (object.addEventListener) object.addEventListener(event, method, false);
else if (object.attachEvent) else if (object.attachEvent)
object.attachEvent('on' + event, function() { object.attachEvent('on' + event, function () {
method(window.event); method(window.event);
}); });
} }
@ -323,10 +313,11 @@ assignKey.filter = filter;
assignKey.isPressed = isPressed; assignKey.isPressed = isPressed;
assignKey.getPressedKeyCodes = getPressedKeyCodes; assignKey.getPressedKeyCodes = getPressedKeyCodes;
assignKey.unbind = unbindKey; assignKey.unbind = unbindKey;
assignKey.handlers = _handlers;
assignKey.init = win => { assignKey.init = win => {
// set the handlers globally on document // set the handlers globally on document
// Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48
addEvent(win.document, 'keydown', function(event) { addEvent(win.document, 'keydown', function (event) {
dispatch(event); dispatch(event);
}); });
addEvent(win.document, 'keyup', clearModifier); addEvent(win.document, 'keyup', clearModifier);

Loading…
Cancel
Save