Skip to content

Commit 3e289de

Browse files
author
Katochimoto
committed
tokenizer
1 parent b67e26b commit 3e289de

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
bower_components
55
coverage
66
npm-debug.log
7+
.DS_Store

dist/x-bubbles-compact.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ var XBubbles =
5959

6060
var OPTIONS = {
6161
begining: ['noop', null, 'begining'],
62-
bubbleCopy: ['funk', bubbleCopyOption, 'bubble-copy'],
63-
bubbleDeformation: ['funk', function () {}, 'bubble-deformation'],
64-
bubbleFormation: ['funk', function () {}, 'bubble-formation'],
65-
checkBubblePaste: ['funk', checkBubblePasteOption, 'check-bubble-paste'],
62+
bubbleCopy: ['func', bubbleCopyOption, 'bubble-copy'],
63+
bubbleDeformation: ['func', function () {}, 'bubble-deformation'],
64+
bubbleFormation: ['func', function () {}, 'bubble-formation'],
65+
checkBubblePaste: ['func', checkBubblePasteOption, 'check-bubble-paste'],
6666
classBubble: ['noop', 'bubble', 'class-bubble'],
6767
disableControls: ['bool', false, 'disable-controls'],
6868
draggable: ['bool', true, 'draggable'],
6969
ending: ['noop', null, 'ending'], // /\@ya\.ru/g;
70-
separator: ['noop', /[,;]/, 'separator']
70+
separator: ['noop', /[,;]/, 'separator'],
71+
tokenizer: ['func', null, 'tokenizer']
7172
};
7273

7374
var XBubbles = Object.create(HTMLDivElement.prototype, {
@@ -167,7 +168,7 @@ var XBubbles =
167168
});
168169

169170
var OPTIONS_PREPARE = {
170-
funk: function funk(value) {
171+
func: function func(value) {
171172
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
172173
switch (type) {
173174
case 'string':
@@ -706,9 +707,10 @@ var XBubbles =
706707
}
707708

708709
function bubbling(nodeSet) {
709-
var separator = nodeSet.options('separator');
710-
var ending = nodeSet.options('ending');
711710
var begining = nodeSet.options('begining');
711+
var ending = nodeSet.options('ending');
712+
var separator = nodeSet.options('separator');
713+
var tokenizer = nodeSet.options('tokenizer');
712714
var ranges = getBubbleRanges(nodeSet);
713715
var nodes = [];
714716

@@ -722,7 +724,9 @@ var XBubbles =
722724

723725
var textParts = [dataText];
724726

725-
if (separator) {
727+
if (tokenizer) {
728+
textParts = tokenizer(dataText);
729+
} else if (separator) {
726730
textParts = dataText.split(separator).map(trimIterator).filter(nonEmptyIterator);
727731
}
728732

@@ -736,8 +740,9 @@ var XBubbles =
736740
}, []).map(trimIterator).filter(nonEmptyIterator);
737741
}
738742

739-
if (!textParts.length) {
740-
range.deleteContents();
743+
if (!Array.isArray(textParts) || !textParts.length) {
744+
// range.deleteContents();
745+
return;
741746
}
742747

743748
var fragment = context.document.createDocumentFragment();
@@ -2362,7 +2367,7 @@ var XBubbles =
23622367

23632368
case KEY.Comma:
23642369
case KEY.Semicolon:
2365-
event.preventDefault();
2370+
// event.preventDefault();
23662371
bubble.bubbling(nodeEditor);
23672372
cursor.restore(nodeEditor);
23682373
break;

dist/x-bubbles.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ var XBubbles =
5959

6060
var OPTIONS = {
6161
begining: ['noop', null, 'begining'],
62-
bubbleCopy: ['funk', bubbleCopyOption, 'bubble-copy'],
63-
bubbleDeformation: ['funk', function () {}, 'bubble-deformation'],
64-
bubbleFormation: ['funk', function () {}, 'bubble-formation'],
65-
checkBubblePaste: ['funk', checkBubblePasteOption, 'check-bubble-paste'],
62+
bubbleCopy: ['func', bubbleCopyOption, 'bubble-copy'],
63+
bubbleDeformation: ['func', function () {}, 'bubble-deformation'],
64+
bubbleFormation: ['func', function () {}, 'bubble-formation'],
65+
checkBubblePaste: ['func', checkBubblePasteOption, 'check-bubble-paste'],
6666
classBubble: ['noop', 'bubble', 'class-bubble'],
6767
disableControls: ['bool', false, 'disable-controls'],
6868
draggable: ['bool', true, 'draggable'],
6969
ending: ['noop', null, 'ending'], // /\@ya\.ru/g;
70-
separator: ['noop', /[,;]/, 'separator']
70+
separator: ['noop', /[,;]/, 'separator'],
71+
tokenizer: ['func', null, 'tokenizer']
7172
};
7273

7374
var XBubbles = Object.create(HTMLDivElement.prototype, {
@@ -167,7 +168,7 @@ var XBubbles =
167168
});
168169

169170
var OPTIONS_PREPARE = {
170-
funk: function funk(value) {
171+
func: function func(value) {
171172
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
172173
switch (type) {
173174
case 'string':
@@ -706,9 +707,10 @@ var XBubbles =
706707
}
707708

708709
function bubbling(nodeSet) {
709-
var separator = nodeSet.options('separator');
710-
var ending = nodeSet.options('ending');
711710
var begining = nodeSet.options('begining');
711+
var ending = nodeSet.options('ending');
712+
var separator = nodeSet.options('separator');
713+
var tokenizer = nodeSet.options('tokenizer');
712714
var ranges = getBubbleRanges(nodeSet);
713715
var nodes = [];
714716

@@ -722,7 +724,9 @@ var XBubbles =
722724

723725
var textParts = [dataText];
724726

725-
if (separator) {
727+
if (tokenizer) {
728+
textParts = tokenizer(dataText);
729+
} else if (separator) {
726730
textParts = dataText.split(separator).map(trimIterator).filter(nonEmptyIterator);
727731
}
728732

@@ -736,8 +740,9 @@ var XBubbles =
736740
}, []).map(trimIterator).filter(nonEmptyIterator);
737741
}
738742

739-
if (!textParts.length) {
740-
range.deleteContents();
743+
if (!Array.isArray(textParts) || !textParts.length) {
744+
// range.deleteContents();
745+
return;
741746
}
742747

743748
var fragment = context.document.createDocumentFragment();
@@ -3244,7 +3249,7 @@ var XBubbles =
32443249

32453250
case KEY.Comma:
32463251
case KEY.Semicolon:
3247-
event.preventDefault();
3252+
// event.preventDefault();
32483253
bubble.bubbling(nodeEditor);
32493254
cursor.restore(nodeEditor);
32503255
break;

samples/index.html

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,20 @@
6565
<script src="../dist/x-bubbles.js?1234"></script>
6666
</head>
6767
<body>
68+
<script>
69+
function tokenizer(dataText) {
70+
var i = 0;
71+
var len = dataText.length;
72+
73+
for (; i < len; i++) {
74+
75+
}
76+
77+
return [];
78+
}
79+
</script>
6880
<div style="margin-top: 0;">
69-
<div class="bubbles" id="test" is="x-bubbles" tabindex="0">
81+
<div class="bubbles" id="test" is="x-bubbles" tabindex="0" data-tokenizer="tokenizer">
7082
123,456,789
7183
</div>
7284
<br/>

src/core/bubble.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ function create(nodeSet, dataText, dataAttributes = {}) {
101101
}
102102

103103
function bubbling(nodeSet) {
104-
const separator = nodeSet.options('separator');
105-
const ending = nodeSet.options('ending');
106104
const begining = nodeSet.options('begining');
105+
const ending = nodeSet.options('ending');
106+
const separator = nodeSet.options('separator');
107+
const tokenizer = nodeSet.options('tokenizer');
107108
const ranges = getBubbleRanges(nodeSet);
108109
const nodes = [];
109110

@@ -117,7 +118,10 @@ function bubbling(nodeSet) {
117118

118119
let textParts = [ dataText ];
119120

120-
if (separator) {
121+
if (tokenizer) {
122+
textParts = tokenizer(dataText);
123+
124+
} else if (separator) {
121125
textParts = dataText
122126
.split(separator)
123127
.map(trimIterator)
@@ -137,8 +141,9 @@ function bubbling(nodeSet) {
137141
.filter(nonEmptyIterator);
138142
}
139143

140-
if (!textParts.length) {
141-
range.deleteContents();
144+
if (!Array.isArray(textParts) || !textParts.length) {
145+
// range.deleteContents();
146+
return;
142147
}
143148

144149
const fragment = context.document.createDocumentFragment();

src/core/editor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function onKeypress(event) {
120120

121121
case KEY.Comma:
122122
case KEY.Semicolon:
123-
event.preventDefault();
123+
// event.preventDefault();
124124
bubble.bubbling(nodeEditor);
125125
cursor.restore(nodeEditor);
126126
break;

src/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ const bubbleset = require('./core/bubbleset');
66

77
const OPTIONS = {
88
begining: [ 'noop', null, 'begining' ],
9-
bubbleCopy: [ 'funk', bubbleCopyOption, 'bubble-copy' ],
10-
bubbleDeformation: [ 'funk', function () {}, 'bubble-deformation' ],
11-
bubbleFormation: [ 'funk', function () {}, 'bubble-formation' ],
12-
checkBubblePaste: [ 'funk', checkBubblePasteOption, 'check-bubble-paste' ],
9+
bubbleCopy: [ 'func', bubbleCopyOption, 'bubble-copy' ],
10+
bubbleDeformation: [ 'func', function () {}, 'bubble-deformation' ],
11+
bubbleFormation: [ 'func', function () {}, 'bubble-formation' ],
12+
checkBubblePaste: [ 'func', checkBubblePasteOption, 'check-bubble-paste' ],
1313
classBubble: [ 'noop', 'bubble', 'class-bubble' ],
1414
disableControls: [ 'bool', false, 'disable-controls' ],
1515
draggable: [ 'bool', true, 'draggable' ],
1616
ending: [ 'noop', null, 'ending' ], // /\@ya\.ru/g;
1717
separator: [ 'noop', /[,;]/, 'separator' ],
18+
tokenizer: [ 'func', null, 'tokenizer' ],
1819
};
1920

2021
const XBubbles = Object.create(HTMLDivElement.prototype, {
@@ -115,7 +116,7 @@ module.exports = context.document.registerElement('x-bubbles', {
115116
});
116117

117118
const OPTIONS_PREPARE = {
118-
funk: function (value) {
119+
func: function (value) {
119120
const type = typeof value;
120121
switch (type) {
121122
case 'string':

0 commit comments

Comments
 (0)