mirror of https://github.com/artf/grapesjs.git
committed by
GitHub
108 changed files with 48872 additions and 1276 deletions
@ -1,3 +0,0 @@ |
|||||
test |
|
||||
index.html |
|
||||
webpack.config.js |
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because one or more lines are too long
@ -1,24 +0,0 @@ |
|||||
var Backbone = require('backbone'); |
|
||||
|
|
||||
module.exports = Backbone.Collection.extend({ |
|
||||
|
|
||||
initialize(models, opt) { |
|
||||
|
|
||||
this.model = function(attrs, opts) { |
|
||||
var model; |
|
||||
|
|
||||
switch(1){ |
|
||||
|
|
||||
default: |
|
||||
if(!this.ClassTag) |
|
||||
this.ClassTag = require("selector_manager/model/Selector"); |
|
||||
model = new this.ClassTag(attrs, opts); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
return model; |
|
||||
}; |
|
||||
|
|
||||
}, |
|
||||
|
|
||||
}); |
|
||||
@ -0,0 +1,135 @@ |
|||||
|
/** |
||||
|
* This module allows to create shortcuts for functions and commands (via command id) |
||||
|
* |
||||
|
* You can access the module in this way |
||||
|
* ```js
|
||||
|
* const keymaps = editor.Keymaps; |
||||
|
* ``` |
||||
|
* |
||||
|
*/ |
||||
|
import { isString } from 'underscore'; |
||||
|
|
||||
|
const keymaster = require('keymaster'); |
||||
|
|
||||
|
module.exports = () => { |
||||
|
let config; |
||||
|
const configDef = {}; |
||||
|
const keymaps = {}; |
||||
|
|
||||
|
return { |
||||
|
|
||||
|
keymaster, |
||||
|
|
||||
|
|
||||
|
name: 'Keymaps', |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get module configurations |
||||
|
* @return {Object} Configuration object |
||||
|
*/ |
||||
|
getConfig() { |
||||
|
return config; |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Initialize module |
||||
|
* @param {Object} config Configurations |
||||
|
* @private |
||||
|
*/ |
||||
|
init(opts = {}) { |
||||
|
config = { ...opts, ...configDef }; |
||||
|
this.em = config.em; |
||||
|
return this; |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* Add new keymap |
||||
|
* @param {string} id Keymap id |
||||
|
* @param {string} keys Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z` |
||||
|
* @param {Function|string} handler Keymap handler, might be a function |
||||
|
* @return {Object} Added keymap |
||||
|
* or just a command id as a string |
||||
|
* @example |
||||
|
* // 'ns' is just a custom namespace
|
||||
|
* keymaps.add('ns:my-keymap', '⌘+j, ⌘+u, ctrl+j, alt+u', editor => { |
||||
|
* console.log('do stuff'); |
||||
|
* }); |
||||
|
* // or
|
||||
|
* keymaps.add('ns:my-keymap', '⌘+s, ctrl+s', 'some-gjs-command'); |
||||
|
* |
||||
|
* // listen to events
|
||||
|
* editor.on('keymap:emit', (id, shortcut, e) => { |
||||
|
* // ...
|
||||
|
* }) |
||||
|
*/ |
||||
|
add(id, keys, handler) { |
||||
|
const em = this.em; |
||||
|
const cmd = em.get('Commands'); |
||||
|
const editor = em.getEditor(); |
||||
|
const keymap = { id, keys, handler }; |
||||
|
const pk = keymaps[id]; |
||||
|
pk && this.remove(id); |
||||
|
keymaps[id] = keymap; |
||||
|
keymaster(keys, (e, h) => { |
||||
|
// It's safer putting handlers resolution inside the callback
|
||||
|
handler = isString(handler) ? cmd.get(handler) : handler; |
||||
|
typeof handler == 'object' ? handler.run(editor) : handler(editor); |
||||
|
const args = [id, h.shortcut, e]; |
||||
|
em.trigger('keymap:emit', ...args); |
||||
|
em.trigger(`keymap:emit:${id}`, ...args); |
||||
|
}); |
||||
|
em.trigger('keymap:add', keymap); |
||||
|
return keymap; |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get the keymap by id |
||||
|
* @param {string} id Keymap id |
||||
|
* @return {Object} Keymap object |
||||
|
* @example |
||||
|
* keymaps.get('ns:my-keymap'); |
||||
|
* // -> {keys, handler};
|
||||
|
*/ |
||||
|
get(id) { |
||||
|
return keymaps[id]; |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Get all keymaps |
||||
|
* @return {Object} |
||||
|
* @example |
||||
|
* keymaps.getAll(); |
||||
|
* // -> {id1: {}, id2: {}};
|
||||
|
*/ |
||||
|
getAll() { |
||||
|
return keymaps; |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Remove the keymap by id |
||||
|
* @param {string} id Keymap id |
||||
|
* @return {Object} Removed keymap |
||||
|
* @example |
||||
|
* keymaps.remove('ns:my-keymap'); |
||||
|
* // -> {keys, handler};
|
||||
|
*/ |
||||
|
remove(id) { |
||||
|
const em = this.em; |
||||
|
const keymap = this.get(id); |
||||
|
|
||||
|
if (keymap) { |
||||
|
delete keymaps[id]; |
||||
|
keymaster.unbind(keymap.keys); |
||||
|
em && em.trigger('keymap:remove', keymap); |
||||
|
return keymap; |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
}; |
||||
|
}; |
||||
@ -1,5 +1,5 @@ |
|||||
module.exports = { |
module.exports = { |
||||
|
|
||||
textTags: ['br', 'b', 'i', 'u'], |
textTags: ['br', 'b', 'i', 'u', 'a', 'ul', 'ol'], |
||||
|
|
||||
}; |
}; |
||||
|
|||||
@ -0,0 +1,20 @@ |
|||||
|
.#{$app-prefix}devices-c { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
padding: 3px; |
||||
|
|
||||
|
.#{$app-prefix}device-label { |
||||
|
flex-grow: 2; |
||||
|
text-align: left; |
||||
|
margin-right: 10px; |
||||
|
} |
||||
|
|
||||
|
.#{$app-prefix}select { |
||||
|
flex-grow: 20; |
||||
|
} |
||||
|
|
||||
|
.#{$app-prefix}add-trasp { |
||||
|
flex-grow: 1; |
||||
|
margin-left: 5px; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
.#{$mdl-prefix} { |
||||
|
&backlayer { |
||||
|
@include opacity(0.5); |
||||
|
|
||||
|
background-color: #000; |
||||
|
position: absolute; |
||||
|
top: 0; |
||||
|
left: 0; |
||||
|
z-index: 1; |
||||
|
width: 100%; |
||||
|
height: 100%; |
||||
|
} |
||||
|
|
||||
|
&container { |
||||
|
font-family: $mainFont; |
||||
|
position: absolute; |
||||
|
top: 0; |
||||
|
left: 0; |
||||
|
z-index: 10; |
||||
|
width: 100%; |
||||
|
height: 100%; |
||||
|
} |
||||
|
|
||||
|
&dialog { |
||||
|
text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.05); |
||||
|
animation: #{$app-prefix}slide-down 0.215s; |
||||
|
margin: 30px auto 0; |
||||
|
max-width: 850px; |
||||
|
width: 90%; |
||||
|
border-radius: 3px; |
||||
|
font-weight: lighter; |
||||
|
position: relative; |
||||
|
z-index: 2; |
||||
|
} |
||||
|
|
||||
|
&title { |
||||
|
font-size: 1rem; |
||||
|
} |
||||
|
|
||||
|
&btn-close { |
||||
|
@extend .btn-cl; |
||||
|
|
||||
|
position: absolute; |
||||
|
right: 15px; |
||||
|
top: 5px; |
||||
|
} |
||||
|
|
||||
|
&active .#{$mdl-prefix}dialog { |
||||
|
animation: #{$mdl-prefix}slide-down 0.216s; |
||||
|
} |
||||
|
|
||||
|
&header, |
||||
|
&content { |
||||
|
padding: 10px 15px; |
||||
|
clear: both; |
||||
|
} |
||||
|
|
||||
|
&header { |
||||
|
position: relative; |
||||
|
border-bottom: 1px solid $mainDkColor; |
||||
|
padding: 15px 15px 7px; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.#{$app-prefix}export-dl::after { |
||||
|
content: ""; |
||||
|
clear: both; |
||||
|
display: block; |
||||
|
margin-bottom: 10px; |
||||
|
} |
||||
@ -0,0 +1,60 @@ |
|||||
|
const Editor = require('editor/model/Editor'); |
||||
|
const Keymaps = require('keymaps'); |
||||
|
|
||||
|
describe('Keymaps', () => { |
||||
|
|
||||
|
describe('Main', () => { |
||||
|
|
||||
|
let em; |
||||
|
let obj; |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
em = new Editor(); |
||||
|
obj = new Keymaps().init({em}); |
||||
|
}); |
||||
|
|
||||
|
it('Object exists', () => { |
||||
|
expect(obj).toExist(); |
||||
|
}); |
||||
|
|
||||
|
it('No keymaps inside', () => { |
||||
|
var coll = obj.getAll(); |
||||
|
expect(coll).toEqual({}); |
||||
|
}); |
||||
|
|
||||
|
it('Add new keymap', () => { |
||||
|
const id = 'test'; |
||||
|
const keys = 'ctrl+a'; |
||||
|
const handler = () => {}; |
||||
|
const model = obj.add(id, 'ctrl+a', handler); |
||||
|
expect(obj.get(id)).toEqual({id, keys, handler}); |
||||
|
}); |
||||
|
|
||||
|
it('Add keymap event triggers', () => { |
||||
|
let called = 0; |
||||
|
em.on('keymap:add', () => called = 1); |
||||
|
const model = obj.add('tes', 'ctrl+a'); |
||||
|
expect(called).toEqual(1); |
||||
|
}); |
||||
|
|
||||
|
it('Remove keymap', () => { |
||||
|
const id = 'test'; |
||||
|
const keys = 'ctrl+a'; |
||||
|
const handler = () => {}; |
||||
|
const model = obj.add(id, 'ctrl+a', handler); |
||||
|
const removed = obj.remove(id); |
||||
|
expect(obj.get(id)).toEqual(undefined); |
||||
|
expect(obj.getAll()).toEqual({}); |
||||
|
expect(removed).toEqual({id, keys, handler}); |
||||
|
}); |
||||
|
|
||||
|
it('Remove keymap event triggers', () => { |
||||
|
let called = 0; |
||||
|
em.on('keymap:remove', () => called = 1); |
||||
|
const model = obj.add('tes', 'ctrl+a'); |
||||
|
const removed = obj.remove('tes'); |
||||
|
expect(called).toEqual(1); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue