Mailspring/app/internal_packages/composer-templates/lib/template-store.es6

299 lines
8.5 KiB
Plaintext
Raw Normal View History

2016-05-07 07:06:16 +08:00
/* eslint global-require: 0*/
import {
localized,
DraftStore,
Actions,
QuotedHTMLTransformer,
RegExpUtils,
} from 'mailspring-exports';
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
import { remote } from 'electron';
2017-09-27 02:46:00 +08:00
import MailspringStore from 'mailspring-store';
import path from 'path';
import fs from 'fs';
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
// Support accented characters in template names
// https://regex101.com/r/nD3eY8/1
const INVALID_TEMPLATE_NAME_REGEX = /[^a-zA-Z\u00C0-\u017F0-9_\- ]+/g;
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
class TemplateStore extends MailspringStore {
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
constructor() {
super();
this.listenTo(Actions.insertTemplateId, this._onInsertTemplateId);
this.listenTo(Actions.createTemplate, this._onCreateTemplate);
this.listenTo(Actions.showTemplates, this._onShowTemplates);
this.listenTo(Actions.deleteTemplate, this._onDeleteTemplate);
this.listenTo(Actions.renameTemplate, this._onRenameTemplate);
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
this._items = [];
this._templatesDir = path.join(AppEnv.getConfigDirPath(), 'templates');
this._welcomeName = 'Welcome to Templates.html';
this._welcomePath = path.join(__dirname, '..', 'assets', this._welcomeName);
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
this._watcher = null;
// I know this is a bit of pain but don't do anything that
// could possibly slow down app launch
2017-09-27 02:33:08 +08:00
fs.exists(this._templatesDir, exists => {
if (exists) {
this._populate();
this.watch();
} else {
fs.mkdir(this._templatesDir, () => {
fs.readFile(this._welcomePath, (err, welcome) => {
fs.writeFile(path.join(this._templatesDir, this._welcomeName), welcome, () => {
this.watch();
});
});
});
}
});
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
directory() {
return this._templatesDir;
}
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
watch() {
if (!this._watcher) {
try {
this._watcher = fs.watch(this._templatesDir, () => this._populate());
} catch (err) {
// usually an ENOSPC error
console.warn(err);
}
}
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
unwatch() {
if (this._watcher) {
this._watcher.close();
}
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
this._watcher = null;
}
items() {
return this._items;
}
_populate() {
fs.readdir(this._templatesDir, (err, filenames) => {
if (err) {
2017-09-27 02:36:58 +08:00
AppEnv.showErrorDialog({
title: localized('Cannot scan templates directory'),
message: localized(
'Mailspring was unable to read the contents of your templates directory (%@). You may want to delete this folder or ensure filesystem permissions are set correctly.',
this._templatesDir
),
});
return;
}
this._items = [];
for (let i = 0, filename; i < filenames.length; i++) {
filename = filenames[i];
2017-09-27 02:33:08 +08:00
if (filename[0] === '.') {
continue;
}
const displayname = path.basename(filename, path.extname(filename));
this._items.push({
id: filename,
name: displayname,
path: path.join(this._templatesDir, filename),
});
}
this.trigger(this);
});
}
2017-09-27 02:33:08 +08:00
_onCreateTemplate({ headerMessageId, name, contents } = {}) {
if (headerMessageId) {
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
this._onCreateTemplateFromDraft(headerMessageId);
return;
}
if (!name || name.length === 0) {
this._displayError(localized('You must provide a name for your template.'));
}
if (!contents || contents.length === 0) {
this._displayError(localized('You must provide contents for your template.'));
}
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
this.saveNewTemplate(name, contents, this._onShowTemplates);
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
_onCreateTemplateFromDraft(headerMessageId) {
DraftStore.sessionForClientId(headerMessageId).then(session => {
const draft = session.draft();
const draftName = draft.subject.replace(INVALID_TEMPLATE_NAME_REGEX, '');
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
let draftContents = QuotedHTMLTransformer.removeQuotedHTML(draft.body);
const sigIndex = draftContents.search(RegExpUtils.mailspringSignatureRegex());
draftContents = sigIndex > -1 ? draftContents.substr(0, sigIndex) : draftContents;
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
if (!draftName || draftName.length === 0) {
this._displayError(localized('Give your draft a subject to name your template.'));
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
}
if (!draftContents || draftContents.length === 0) {
this._displayError(
localized('To create a template you need to fill the body of the current draft.')
);
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
}
this.saveNewTemplate(draftName, draftContents, this._onShowTemplates);
});
}
_onShowTemplates() {
Actions.switchPreferencesTab('Templates');
Actions.openPreferences();
}
_displayError(message) {
remote.dialog.showErrorBox(localized('Template Creation Error'), message);
}
_displayDialog(title, message, buttons) {
2017-09-27 02:33:08 +08:00
return (
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
remote.dialog.showMessageBox({
2017-09-27 02:33:08 +08:00
title: title,
message: title,
detail: message,
buttons: buttons,
type: 'info',
}) === 0
);
}
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
saveNewTemplate(name, contents, callback) {
if (!name || name.length === 0) {
this._displayError(localized('You must provide a template name.'));
return;
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
if (name.match(INVALID_TEMPLATE_NAME_REGEX)) {
2017-09-27 02:33:08 +08:00
this._displayError(
localized(
'Invalid template name! Names can only contain letters, numbers, spaces, dashes, and underscores.'
)
2017-09-27 02:33:08 +08:00
);
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
return;
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
let number = 1;
let resolvedName = name;
const sameName = t => t.name === resolvedName;
while (this._items.find(sameName)) {
resolvedName = `${name} ${number}`;
number += 1;
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
this.saveTemplate(resolvedName, contents, callback);
this.trigger(this);
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
}
saveTemplate(name, contents, callback) {
const filename = `${name}.html`;
const templatePath = path.join(this._templatesDir, filename);
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
let template = this._items.find(t => t.name === name);
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
this.unwatch();
2017-09-27 02:33:08 +08:00
fs.writeFile(templatePath, contents, err => {
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
this.watch();
2017-09-27 02:33:08 +08:00
if (err) {
this._displayError(err);
}
if (!template) {
template = {
id: filename,
name: name,
path: templatePath,
};
this._items.unshift(template);
}
if (callback) {
callback(template);
}
});
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
_onDeleteTemplate(name) {
const template = this._items.find(t => t.name === name);
2017-09-27 02:33:08 +08:00
if (!template) {
return;
}
2017-09-27 02:33:08 +08:00
if (
this._displayDialog(
localized('Delete Template?'),
localized('The template and its file will be permanently deleted.'),
[localized('Delete'), localized('Cancel')]
2017-09-27 02:33:08 +08:00
)
) {
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
fs.unlink(template.path, () => {
this._populate();
});
}
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
_onRenameTemplate(name, newName) {
const template = this._items.find(t => t.name === name);
2017-09-27 02:33:08 +08:00
if (!template) {
return;
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
if (newName.match(INVALID_TEMPLATE_NAME_REGEX)) {
2017-09-27 02:33:08 +08:00
this._displayError(
localized(
'Invalid template name! Names can only contain letters, numbers, spaces, dashes, and underscores.'
)
2017-09-27 02:33:08 +08:00
);
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
return;
}
if (newName.length === 0) {
this._displayError(localized('You must provide a template name.'));
return;
}
const newFilename = `${newName}.html`;
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
const oldPath = path.join(this._templatesDir, `${name}.html`);
const newPath = path.join(this._templatesDir, newFilename);
fs.rename(oldPath, newPath, () => {
template.name = newName;
template.id = newFilename;
template.path = newPath;
this.trigger(this);
});
}
2017-09-27 02:33:08 +08:00
_onInsertTemplateId({ templateId, headerMessageId } = {}) {
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
const template = this._items.find(t => t.id === templateId);
const templateBody = fs.readFileSync(template.path).toString();
DraftStore.sessionForClientId(headerMessageId).then(session => {
let proceed = true;
if (!session.draft().pristine && !session.draft().hasEmptyBody()) {
proceed = this._displayDialog(
localized('Replace draft contents?'),
localized(
'It looks like your draft already has some content. Loading this template will overwrite all draft contents.'
),
[localized('Replace contents'), localized('Cancel')]
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
);
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
if (proceed) {
const current = session.draft().body;
let insertion = current.length;
for (const s of [
'<signature',
'<div class="gmail_quote_attribution"',
'<blockquote class="gmail_quote"',
]) {
const i = current.indexOf(s);
if (i !== -1) {
insertion = Math.min(insertion, i);
}
refactor(templates): major additions and refactoring for the Templates plugin. Summary: Adds several new features to the templates plugin, fixes some existing bugs, and refactors existing code. New Plugin Features/Fixes: - Changes the templates editor in preferences to allow variables to be entered with `{{brackets}}`. Handles many contenteditable complexities to implement. - Better interaction for renaming and deleting of templates in the editor. - Changes tabbing behavior when using templates. Tabbing between variables now wraps around, and typing tab from outside a variable region highlights the closest region. - Prevents "Enter" key in the composer when inside a variable region, and strips all formatting/tags from within the region - this prevents major contenteditable issues that can result in inline CSS in the style of our variable regions, which will not be removed when sending. - Shows a warning when choosing a template if it will replace existing text in a draft. - Prevents invalid characters in template names (due to filenames, esp. on Windows), and shows an error message. Strips these characters from draft titles when making a template. - Fixes a bug where TemplateStore's initialization code was being called multiple times. New N1 code: - Several new methods in `DOMUtils` useful for working with contenteditable. - Implement some missing methods in `Editor` Refactor: - Major refactor/rewrite of template composer extension to use new DOMUtils methods and simplify the logic (while adding new functionality). Remaining issues: - `preferences-tempaltes.cjsx` and `template-editor.coffee` should be rewritten in ES6 for consistency - Need tests for new DOMUtils functions and for new Templates plugin code. Test Plan: manual, need to update specs Reviewers: evan, bengotow Reviewed By: evan, bengotow Subscribers: juan Differential Revision: https://phab.nylas.com/D2382
2015-12-30 07:11:04 +08:00
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
session.changes.add({ body: `${templateBody}${current.substr(insertion)}` });
}
});
}
}
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
export default new TemplateStore();