Skip to content

Commit

Permalink
refactor: remove clutter from BaseExtensionOptions
Browse files Browse the repository at this point in the history
Now exclude options are all sub-properties of the exclude property.
  • Loading branch information
ifiokjr committed Jul 20, 2019
1 parent ad330a9 commit ba19c41
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
18 changes: 9 additions & 9 deletions @remirror/core/src/extension-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
let combinedAttributes: AttrsWithClass = {};
this.extensions
.filter(hasExtensionProperty('attributes'))
.filter(extension => !extension.options.excludeAttributes)
.filter(extension => !extension.options.exclude.attributes)
.map(extension => extension.attributes(this.params))
.reverse()
.forEach(attrs => {
Expand All @@ -227,7 +227,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
this.extensions
.filter(extension => extension.options.SSRComponent)
// User can opt out of SSR rendering
.filter(extension => !extension.options.disableSSR)
.filter(extension => !extension.options.exclude.ssr)
.forEach(({ name, options: { SSRComponent } }) => {
components[name] = SSRComponent;
});
Expand Down Expand Up @@ -403,7 +403,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
public ssrTransformer(element: JSX.Element): JSX.Element {
return this.extensions
.filter(hasExtensionProperty('ssrTransformer'))
.filter(extension => !extension.options.disableSSR)
.filter(extension => !extension.options.exclude.ssr)
.reduce((prevElement, extension) => {
return extension.ssrTransformer(prevElement, this.params);
}, element);
Expand Down Expand Up @@ -503,7 +503,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
const plugins: ProsemirrorPlugin[] = [];
const extensionPlugins = this.extensions
.filter(hasExtensionProperty('plugin'))
.filter(extension => !extension.options.excludePlugin)
.filter(extension => !extension.options.exclude.plugin)
.map(extensionPropertyMapper('plugin', this.params)) as ProsemirrorPlugin[];

extensionPlugins.forEach(plugin => {
Expand All @@ -521,7 +521,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
const nodeViews: Record<string, NodeViewMethod> = {};
return this.extensions
.filter(hasExtensionProperty('nodeView'))
.filter(extension => !extension.options.excludeNodeView)
.filter(extension => !extension.options.exclude.nodeView)
.reduce(
(prevNodeViews, extension) => ({
...prevNodeViews,
Expand All @@ -538,7 +538,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
this.checkInitialized();
const extensionKeymaps = this.extensions
.filter(hasExtensionProperty('keys'))
.filter(extension => !extension.options.excludeKeymaps)
.filter(extension => !extension.options.exclude.keymaps)
.map(extensionPropertyMapper('keys', this.params));

const mappedKeys: Record<string, CommandFunction> = {};
Expand Down Expand Up @@ -569,7 +569,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
const rules: InputRule[] = [];
const extensionInputRules = this.extensions
.filter(hasExtensionProperty('inputRules'))
.filter(extension => !extension.options.excludeInputRules)
.filter(extension => !extension.options.exclude.inputRules)
.map(extensionPropertyMapper('inputRules', this.params)) as InputRule[][];

extensionInputRules.forEach(rule => {
Expand Down Expand Up @@ -599,7 +599,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
const pasteRules: ProsemirrorPlugin[] = [];
const extensionPasteRules = this.extensions
.filter(hasExtensionProperty('pasteRules'))
.filter(extension => !extension.options.excludePasteRules)
.filter(extension => !extension.options.exclude.pasteRules)
.map(extensionPropertyMapper('pasteRules', this.params)) as ProsemirrorPlugin[][];

extensionPasteRules.forEach(rules => {
Expand All @@ -616,7 +616,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
this.checkInitialized();
const extensionStyles = this.extensions
.filter(hasExtensionProperty('styles'))
.filter(extension => !extension.options.excludeStyles)
.filter(extension => !extension.options.exclude.styles)
.map(extensionPropertyMapper('styles', this.params));

return extensionStyles;
Expand Down
18 changes: 10 additions & 8 deletions @remirror/core/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ import {
*/
const defaultOptions: Required<BaseExtensionOptions> = {
extraStyles: '',
excludeInputRules: false,
excludeKeymaps: false,
excludePasteRules: false,
excludePlugin: false,
excludeStyles: false,
excludeAttributes: false,
excludeNodeView: false,
disableSSR: false,
extraAttrs: [],
exclude: {
inputRules: false,
keymaps: false,
pasteRules: false,
plugin: false,
styles: false,
attributes: false,
nodeView: false,
ssr: false,
},
};

/**
Expand Down
23 changes: 15 additions & 8 deletions @remirror/core/src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,61 +199,68 @@ export interface BaseExtensionOptions {
*/
extraAttrs?: ExtraAttrs;

/**
* a configuration object which allows for excluding certain functionality from an extension.
*/
exclude?: ExcludeOptions;
}

export interface ExcludeOptions {
/**
* Whether to exclude the extension's styles.
*
* @default false
*/
excludeStyles?: boolean;
styles?: boolean;

/**
* Whether to exclude the extension's pasteRules
*
* @default false
*/
excludePasteRules?: boolean;
pasteRules?: boolean;

/**
* Whether to exclude the extension's inputRules
*
* @default false
*/
excludeInputRules?: boolean;
inputRules?: boolean;

/**
* Whether to exclude the extension's keymaps
*
* @default false
*/
excludeKeymaps?: boolean;
keymaps?: boolean;

/**
* Whether to exclude the extension's plugin
*
* @default false
*/
excludePlugin?: boolean;
plugin?: boolean;

/**
* Whether to exclude the extension's nodeView
*
* @default false
*/
excludeNodeView?: boolean;
nodeView?: boolean;

/**
* Whether to use the attributes provided by this extension
*
* @default false
*/
excludeAttributes?: boolean;
attributes?: boolean;

/**
* Whether to use the SSR component when not in a DOM environment
*
* @default false
*/
disableSSR?: boolean;
ssr?: boolean;
}

export interface SSRComponentParams {
Expand Down

0 comments on commit ba19c41

Please sign in to comment.