scribe-editor
Advanced tools
Comparing version 1.3.2 to 1.3.3
{ | ||
"name": "scribe", | ||
"dependencies": { | ||
"lodash-amd": "2.4.1", | ||
"lodash-compat": "3.5.0-amd", | ||
"immutable" : "3.6.2" | ||
@@ -6,0 +6,0 @@ }, |
@@ -0,1 +1,9 @@ | ||
# 1.3.3 | ||
All plugins, formatters and commands can now be overridden via options. | ||
Thanks [David Tobin](https://github.com/DavidTobin) | ||
Lodash has been bumped to 3.5.0 | ||
# 1.3.2 | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "scribe-editor", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"main": "src/scribe.js", | ||
"dependencies": { | ||
"lodash-amd": "~2.4.1", | ||
"lodash-amd": "~3.5.0", | ||
"immutable": "~3.6.2" | ||
@@ -27,3 +27,3 @@ }, | ||
"request": "~2.33.0", | ||
"scribe-test-harness": "~0.0.17", | ||
"scribe-test-harness": "~0.0.19", | ||
"selenium-webdriver": "~2.41.0", | ||
@@ -30,0 +30,0 @@ "sinon": "^1.12.2" |
@@ -1,4 +0,14 @@ | ||
define(['lodash-amd/modern/objects/defaults',], function (defaults) { | ||
define([ | ||
'lodash-amd/modern/objects/defaults' | ||
], function (defaults) { | ||
var defaultOptions = { | ||
var blockModePlugins = [ | ||
'setRootPElement', | ||
'enforcePElements', | ||
'ensureSelectableContainers', | ||
], | ||
inlineModePlugins = [ | ||
'inlineElementsMode' | ||
], | ||
defaultOptions = { | ||
allowBlockElements: true, | ||
@@ -19,16 +29,85 @@ debug: false, | ||
'createLink' | ||
], | ||
defaultPlugins: blockModePlugins.concat(inlineModePlugins), | ||
defaultFormatters: [ | ||
'escapeHtmlCharactersFormatter', | ||
'replaceNbspCharsFormatter' | ||
] | ||
}; | ||
/** | ||
* Overrides defaults with user's options | ||
* | ||
* @param {Object} userSuppliedOptions The user's options | ||
* @return {Object} The overridden options | ||
*/ | ||
function checkOptions(userSuppliedOptions) { | ||
var options = userSuppliedOptions || {}; | ||
// Remove invalid plugins | ||
if (options.defaultPlugins) { | ||
options.defaultPlugins = options.defaultPlugins.filter(filterByPluginExists(defaultOptions.defaultPlugins)); | ||
} | ||
if (options.defaultFormatters) { | ||
options.defaultFormatters = options.defaultFormatters.filter(filterByPluginExists(defaultOptions.defaultFormatters)); | ||
} | ||
return Object.freeze(defaults(options, defaultOptions)); | ||
} | ||
/** | ||
* Sorts a plugin list by a specified plugin name | ||
* | ||
* @param {String} priorityPlugin The plugin name to be given priority | ||
* @return {Function} Sorting function for the given plugin name | ||
*/ | ||
function sortByPlugin(priorityPlugin) { | ||
return function (pluginCurrent, pluginNext) { | ||
if (pluginCurrent === priorityPlugin) { | ||
// pluginCurrent comes before plugin next | ||
return -1; | ||
} else if (pluginNext === priorityPlugin) { | ||
// pluginNext comes before pluginCurrent | ||
return 1; | ||
} | ||
// Do no swap | ||
return 0; | ||
} | ||
} | ||
/** | ||
* Filters a list of plugins by block level / inline level mode. | ||
* | ||
* @param {Boolean} isBlockLevelMode Whether block level mode is enabled | ||
* @return {Function} Filtering function based upon the given mode | ||
*/ | ||
function filterByBlockLevelMode(isBlockLevelMode) { | ||
return function (plugin) { | ||
return (isBlockLevelMode ? blockModePlugins : inlineModePlugins).indexOf(plugin) !== -1; | ||
} | ||
} | ||
/** | ||
* Filters a list of plugins by their validity | ||
* | ||
* @param {Array<String>} pluginList List of plugins to check against | ||
* @return {Function} Filtering function based upon the given list | ||
*/ | ||
function filterByPluginExists(pluginList) { | ||
return function (plugin) { | ||
return pluginList.indexOf(plugin) !== -1; | ||
} | ||
} | ||
return { | ||
defaultOptions: defaultOptions, | ||
checkOptions: checkOptions | ||
checkOptions: checkOptions, | ||
sortByPlugin: sortByPlugin, | ||
filterByBlockLevelMode: filterByBlockLevelMode, | ||
filterByPluginExists: filterByPluginExists | ||
} | ||
}); |
define([ | ||
'./plugins/core/plugins', | ||
'./plugins/core/commands', | ||
'./plugins/core/formatters', | ||
'./plugins/core/events', | ||
'./plugins/core/formatters/html/replace-nbsp-chars', | ||
'./plugins/core/formatters/html/enforce-p-elements', | ||
'./plugins/core/formatters/html/ensure-selectable-containers', | ||
'./plugins/core/formatters/plain-text/escape-html-characters', | ||
'./plugins/core/inline-elements-mode', | ||
'./plugins/core/patches', | ||
'./plugins/core/set-root-p-element', | ||
'./api', | ||
@@ -20,11 +16,7 @@ './transaction-manager', | ||
], function ( | ||
plugins, | ||
commands, | ||
formatters, | ||
events, | ||
replaceNbspCharsFormatter, | ||
enforcePElements, | ||
ensureSelectableContainers, | ||
escapeHtmlCharactersFormatter, | ||
inlineElementsMode, | ||
patches, | ||
setRootPElement, | ||
Api, | ||
@@ -96,24 +88,12 @@ buildTransactionManager, | ||
*/ | ||
var corePlugins = Immutable.OrderedSet(this.options.defaultPlugins) | ||
.sort(config.sortByPlugin('setRootPElement')) // Ensure `setRootPElement` is always loaded first | ||
.filter(config.filterByBlockLevelMode(this.allowsBlockElements())) | ||
.map(function (plugin) { return plugins[plugin]; }); | ||
if (this.allowsBlockElements()) { | ||
// Commands assume block elements are allowed, so all we have to do is | ||
// set the content. | ||
// TODO: replace this by initial formatter application? | ||
this.use(setRootPElement()); | ||
// Warning: enforcePElements must come before ensureSelectableContainers | ||
this.use(enforcePElements()); | ||
this.use(ensureSelectableContainers()); | ||
} else { | ||
// Commands assume block elements are allowed, so we have to set the | ||
// content and override some UX. | ||
this.use(inlineElementsMode()); | ||
} | ||
// Formatters | ||
var defaultFormatters = Immutable.List.of( | ||
escapeHtmlCharactersFormatter, | ||
replaceNbspCharsFormatter | ||
); | ||
var defaultFormatters = Immutable.List(this.options.defaultFormatters) | ||
.filter(function (formatter) { return !!formatters[formatter]; }) | ||
.map(function (formatter) { return formatters[formatter]; }) | ||
// Patches | ||
@@ -138,2 +118,3 @@ | ||
var allPlugins = Immutable.List().concat( | ||
corePlugins, | ||
defaultFormatters, | ||
@@ -140,0 +121,0 @@ defaultPatches, |
@@ -0,1 +1,3 @@ | ||
require('node-amd-require')({ | ||
@@ -14,3 +16,3 @@ baseUrl: __dirname, | ||
describe('config', function(){ | ||
describe('config', function() { | ||
it('should normalise unspecified options', function() { | ||
@@ -20,2 +22,14 @@ expect(config.checkOptions(undefined)).to.exist; | ||
it('should remove invalid plugins', function() { | ||
var options = config.checkOptions({ | ||
defaultPlugins: ['bad_plugin'], | ||
defaultFormatters: ['bad_plugin'] | ||
}), | ||
dummyPluginList = ['a', 'b']; | ||
expect(options.defaultPlugins.length).to.be.equal(0); | ||
expect(options.defaultFormatters.length).to.be.equal(0); | ||
expect(['a', 'b', 'c'].filter(config.filterByPluginExists(dummyPluginList))).to.not.include('c'); | ||
}); | ||
it('should respect overridden options', function() { | ||
@@ -22,0 +36,0 @@ var checkedOptions = config.checkOptions({allowBlockElements: false}); |
197721
75
4117
+ Addedlodash-amd@3.5.0(transitive)
- Removedlodash-amd@2.4.1(transitive)
Updatedlodash-amd@~3.5.0