Skip to content

Commit

Permalink
Add CucoTheme (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pitakill committed Apr 5, 2017
1 parent e1ff4a0 commit f2519b4
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 13 deletions.
18 changes: 9 additions & 9 deletions _develop/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mkdir .release/quill

npm run build
webpack --config _develop/webpack.config.js --env.minimize
cp dist/quill.core.css dist/quill.bubble.css dist/quill.snow.css dist/quill.js dist/quill.core.js dist/quill.min.js dist/quill.min.js.map .release/quill/
cp dist/quill.core.css dist/quill.bubble.css dist/quill.snow.css dist/quill.cuco.css dist/quill.js dist/quill.core.js dist/quill.min.js dist/quill.min.js.map .release/quill/

cd .release

Expand All @@ -33,14 +33,14 @@ find quill/examples -type f -exec sed -i "" 's/src="\/\//src="https:\/\//g' {} \

tar -czf quill.tar.gz quill

aws s3 cp quill/quill.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
aws s3 cp quill/quill.min.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
aws s3 cp quill/quill.core.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
aws s3 cp quill/quill.bubble.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
aws s3 cp quill/quill.core.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
aws s3 cp quill/quill.snow.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
aws s3 cp quill/quill.min.js.map s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/json; charset=utf-8" --profile quill
aws s3 sync s3://cdn.quilljs.com/$VERSION/ s3://cdn.quilljs.com/latest/ --profile quill
#aws s3 cp quill/quill.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
#aws s3 cp quill/quill.min.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
#aws s3 cp quill/quill.core.js s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/javascript; charset=utf-8" --profile quill
#aws s3 cp quill/quill.bubble.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
#aws s3 cp quill/quill.core.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
#aws s3 cp quill/quill.snow.css s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "text/css; charset=utf-8" --profile quill
#aws s3 cp quill/quill.min.js.map s3://cdn.quilljs.com/$VERSION/ --cache-control max-age=604800 --content-type "application/json; charset=utf-8" --profile quill
#aws s3 sync s3://cdn.quilljs.com/$VERSION/ s3://cdn.quilljs.com/latest/ --profile quill

cd ..
git tag v$VERSION -m "Version $VERSION"
Expand Down
1 change: 1 addition & 0 deletions _develop/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = function(env) {
'quill.core': './assets/core.styl',
'quill.bubble': './assets/bubble.styl',
'quill.snow': './assets/snow.styl',
'quill.cuco': './assets/cuco.styl',
'unit.js': './test/unit.js'
},
output: {
Expand Down
18 changes: 18 additions & 0 deletions assets/cuco.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
themeName = 'cuco'
activeColor = #0086a8
borderColor = #ccc
backgroundColor = #fff
inactiveColor = #444
shadowColor = #ddd
textColor = #444

@import './core'
@import './base'
@import './cuco/*'

.ql-cuco
a
color: activeColor

.ql-container.ql-cuco
border: 1px solid borderColor
26 changes: 26 additions & 0 deletions assets/cuco/toolbar.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.ql-toolbar.ql-cuco
border: 1px solid borderColor
box-sizing: border-box
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif
padding: 8px

.ql-formats
margin-right: 15px

.ql-picker-label
border: 1px solid transparent
.ql-picker-options
border: 1px solid transparent
box-shadow: rgba(0,0,0,0.2) 0 2px 8px
.ql-picker.ql-expanded
.ql-picker-label
border-color: borderColor
.ql-picker-options
border-color: borderColor

.ql-color-picker
.ql-picker-item.ql-selected, .ql-picker-item:hover
border-color: #000

.ql-toolbar.ql-cuco + .ql-container.ql-cuco
border-top: 0px;
55 changes: 55 additions & 0 deletions assets/cuco/tooltip.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
tooltipMargin = 8px

.ql-cuco
.ql-tooltip
background-color: #fff
border: 1px solid borderColor
box-shadow: 0px 0px 5px shadowColor
color: textColor
padding: 5px 12px
white-space: nowrap
&::before
content: "Ir a:"
line-height: 26px
margin-right: tooltipMargin
input[type=text]
display: none
border: 1px solid borderColor
font-size: 13px
height: 26px
margin: 0px
padding: 3px 5px
width: 170px
a.ql-preview
display: inline-block
max-width: 200px
overflow-x: hidden
text-overflow: ellipsis
vertical-align: top
a.ql-action::after
border-right: 1px solid borderColor
content: 'Editar'
margin-left: tooltipMargin*2
padding-right: tooltipMargin
a.ql-remove::before
content: 'Quitar'
margin-left: tooltipMargin
a
line-height: 26px
.ql-tooltip.ql-editing
a.ql-preview, a.ql-remove
display: none
input[type=text]
display: inline-block
a.ql-action::after
border-right: 0px
content: 'Guardar'
padding-right: 0px
.ql-tooltip[data-mode=link]::before
content: "Liga:"
.ql-tooltip[data-mode=formula]::before
content: "Formula:"
.ql-tooltip[data-mode=tweet]::before
content: "Liga del tweet:"
.ql-tooltip[data-mode=video]::before
content: "Liga del video:"
9 changes: 9 additions & 0 deletions assets/icons/tweet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions formats/tweet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BlockEmbed } from '../blots/block';

const {warn} = console;

class Tweet extends BlockEmbed {
static create(id) {
let node = super.create();
node.dataset.id = id;

if (typeof twttr === 'undefined') {
warn('There is no Twitter Widget Library. Add it!');
node.insertAdjacentHTML('afterbegin', '[Tuvimos problemas para desplegar el Tweet: ');
node.insertAdjacentHTML('beforeend', `<a href="https://twitter.com/a/status/${id}">${id}</a>`);
node.insertAdjacentHTML('beforeend', ' (Aquí se desplegará)]');
node.setAttribute('style', 'text-align:center;');
} else {
twttr.widgets.createTweet(id, node, {
align: 'center',
lang: 'es',
width: 350
});
}

return node;
}

static value(domNode) {
return domNode.dataset.id;
}
}
Tweet.blotName = 'tweet';
Tweet.className = 'ql-tweet';
Tweet.tagName = 'DIV';

export default Tweet;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill",
"version": "1.2.3",
"name": "quill-cuco",
"version": "1.2.3-1",
"description": "Your powerful, rich text editor",
"author": "Jason Chen <jhchen7@gmail.com>",
"homepage": "http://quilljs.com",
Expand Down
5 changes: 4 additions & 1 deletion quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Underline from './formats/underline';

import Image from './formats/image';
import Video from './formats/video';
import Tweet from './formats/tweet';

import CodeBlock, { Code as InlineCode } from './formats/code';

Expand All @@ -37,7 +38,7 @@ import Tooltip from './ui/tooltip';

import BubbleTheme from './themes/bubble';
import SnowTheme from './themes/snow';

import CucoTheme from './themes/cuco';

Quill.register({
'attributors/attribute/direction': DirectionAttribute,
Expand Down Expand Up @@ -83,6 +84,7 @@ Quill.register({

'formats/image': Image,
'formats/video': Video,
'formats/tweet': Tweet,

'formats/list/item': ListItem,

Expand All @@ -92,6 +94,7 @@ Quill.register({

'themes/bubble': BubbleTheme,
'themes/snow': SnowTheme,
'themes/cuco': CucoTheme,

'ui/icons': Icons,
'ui/picker': Picker,
Expand Down
16 changes: 16 additions & 0 deletions themes/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ BaseTheme.DEFAULTS = extend(true, {}, Theme.DEFAULTS, {
}
fileInput.click();
},
tweet: function() {
this.quill.theme.tooltip.edit('tweet');
},
video: function() {
this.quill.theme.tooltip.edit('video');
}
Expand Down Expand Up @@ -234,6 +237,19 @@ class BaseTooltip extends Tooltip {
}
break;
}
case 'tweet': {
const valueBoolean = Boolean(value);
if (!valueBoolean) break;
const match = value.match(/^(https?):\/\/(www\.)?twitter\.com\/([A-Za-z0-9_]{1,15})\/status\/([0-9]+)/);
if (match) {
value = match[4];
const range = this.quill.getSelection(true);
this.quill.insertText(range.index, '\n', Emitter.sources.USER);
this.quill.insertEmbed(range.index + 1, 'tweet', value, Emitter.sources.USER);
this.quill.setSelection(range.index + 2, Emitter.sources.SILENT);
}
break;
}
default:
}
this.textbox.value = '';
Expand Down
128 changes: 128 additions & 0 deletions themes/cuco.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import extend from 'extend';
import Emitter from '../core/emitter';
import BaseTheme, { BaseTooltip } from './base';
import LinkBlot from '../formats/link';
import { Range } from '../core/selection';
import icons from '../ui/icons';


const TOOLBAR_CONFIG = [
'bold',
'italic',
'link',
{align: []},
'image',
'video',
'code-block',
'tweet'
];

class CucoTheme extends BaseTheme {
constructor(quill, options) {
if (options.modules.toolbar != null && options.modules.toolbar.container == null) {
options.modules.toolbar.container = TOOLBAR_CONFIG;
}
super(quill, options);
this.quill.container.classList.add('ql-cuco');
}

extendToolbar(toolbar) {
toolbar.container.classList.add('ql-cuco');
this.buildButtons([].slice.call(toolbar.container.querySelectorAll('button')), icons);
this.buildPickers([].slice.call(toolbar.container.querySelectorAll('select')), icons);
this.tooltip = new CucoTooltip(this.quill, this.options.bounds);
if (toolbar.container.querySelector('.ql-link')) {
this.quill.keyboard.addBinding({ key: 'K', shortKey: true }, function(range, context) {
toolbar.handlers['link'].call(toolbar, !context.format.link);
});
}
}
}
CucoTheme.DEFAULTS = extend(true, {}, BaseTheme.DEFAULTS, {
modules: {
toolbar: {
handlers: {
link: function(value) {
if (value) {
let range = this.quill.getSelection();
if (range == null || range.length == 0) return;
let preview = this.quill.getText(range);
if (/^\S+@\S+\.\S+$/.test(preview) && preview.indexOf('mailto:') !== 0) {
preview = 'mailto:' + preview;
}
let tooltip = this.quill.theme.tooltip;
tooltip.edit('link', preview);
} else {
this.quill.format('link', false);
}
}
}
}
}
});


class CucoTooltip extends BaseTooltip {
constructor(quill, bounds) {
super(quill, bounds);
this.preview = this.root.querySelector('a.ql-preview');
}

listen() {
super.listen();
this.root.querySelector('a.ql-action').addEventListener('click', (event) => {
if (this.root.classList.contains('ql-editing')) {
this.save();
} else {
this.edit('link', this.preview.textContent);
}
event.preventDefault();
});
this.root.querySelector('a.ql-remove').addEventListener('click', (event) => {
if (this.linkRange != null) {
let range = this.linkRange;
this.restoreFocus();
this.quill.formatText(range, 'link', false, Emitter.sources.USER);
delete this.linkRange;
}
event.preventDefault();
this.hide();
});
this.quill.on(Emitter.events.SELECTION_CHANGE, (range, oldRange, source) => {
if (range == null) return;
if (range.length === 0 && source === Emitter.sources.USER) {
let [link, offset] = this.quill.scroll.descendant(LinkBlot, range.index);
if (link != null) {
this.linkRange = new Range(range.index - offset, link.length());
let preview = LinkBlot.formats(link.domNode);
this.preview.textContent = preview;
this.preview.setAttribute('href', preview);
this.show();
this.position(this.quill.getBounds(this.linkRange));
return;
}
} else {
delete this.linkRange;
}
this.hide();
});
}

show() {
super.show();
this.root.removeAttribute('data-mode');
}
}
CucoTooltip.TEMPLATE = [
'<a class="ql-preview" target="_blank" href="about:blank"></a>',
'<input type="text" ',
'data-formula="e=mc^2" ',
'data-link="http://culturacolectiva.com" ',
'data-video="Link" ',
'data-tweet="Tweet">',
'<a class="ql-action"></a>',
'<a class="ql-remove"></a>'
].join('');


export default CucoTheme;
3 changes: 2 additions & 1 deletion ui/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ module.exports = {
},
'strike' : require('../assets/icons/strike.svg'),
'underline' : require('../assets/icons/underline.svg'),
'video' : require('../assets/icons/video.svg')
'video' : require('../assets/icons/video.svg'),
'tweet' : require('../assets/icons/tweet.svg')
};

0 comments on commit f2519b4

Please sign in to comment.