riot_js-rails 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -9
- data/lib/riot_js/rails/processors/processor.rb +11 -91
- data/lib/riot_js/rails/processors/sprockets_processor_v2.rb +26 -0
- data/lib/riot_js/rails/processors/sprockets_processor_v3.rb +39 -0
- data/lib/riot_js/rails/railtie.rb +6 -8
- data/lib/riot_js/rails/version.rb +1 -1
- data/vendor/assets/javascripts/riot.js +244 -147
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28f4dddc008edcc616cea43019ee720f630c33ae
|
4
|
+
data.tar.gz: 0bd1a5fcb5a7b5d148b57fa0e3bf71ef82115c2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 214ba2fb02851170d4ee823a7396e17973f2d5a113a6acb400d5dfa79e3925109a6eeb856840a7373e4cca7baa649c2476ccf065a475dd89cd5588798af91b0b
|
7
|
+
data.tar.gz: c112dfc72896c9f3a0d6c2eb8d02caeaa350a84fd998a102f14ff6ae139f3a826a30a3f825673bf45f629cee1d385c6d54979649981330e2858480360d62f5e4
|
data/Rakefile
CHANGED
@@ -7,12 +7,4 @@ Rake::TestTask.new do |t|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
desc "Run tests"
|
10
|
-
task :default => :test
|
11
|
-
|
12
|
-
namespace :test do
|
13
|
-
desc "Test with various versions of sprockets"
|
14
|
-
task :sprockets_versions do
|
15
|
-
sh "bash test/test_sprockets_versions.sh"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
10
|
+
task :default => :test
|
@@ -1,103 +1,23 @@
|
|
1
1
|
require 'riot_js/rails/processors/compiler'
|
2
2
|
|
3
|
+
if Gem::Version.new(Sprockets::VERSION) < Gem::Version.new('3.0.0')
|
4
|
+
require 'riot_js/rails/processors/sprockets_processor_v2'
|
5
|
+
else
|
6
|
+
require 'riot_js/rails/processors/sprockets_processor_v3'
|
7
|
+
end
|
8
|
+
|
3
9
|
module RiotJs
|
4
10
|
module Rails
|
11
|
+
class Processor < SprocketsProcessor
|
5
12
|
|
6
|
-
|
7
|
-
|
8
|
-
attr_reader :default_mime_type
|
9
|
-
|
10
|
-
def initialize(filename, &block)
|
11
|
-
@filename = filename
|
12
|
-
@source = block.call
|
13
|
-
end
|
14
|
-
|
15
|
-
def render(context, empty_hash_wtf)
|
16
|
-
self.class.run(@filename, @source, context)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.run(filename, source, context)
|
20
|
-
raise 'Not implemented'
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.call(input)
|
24
|
-
if input.is_a?(String)
|
25
|
-
run("", input, nil)
|
26
|
-
else
|
27
|
-
filename = input[:filename]
|
28
|
-
source = input[:data]
|
29
|
-
context = input[:environment].context_class.new(input)
|
30
|
-
|
31
|
-
result = run(filename, source, context)
|
32
|
-
context.metadata.merge(data: result)
|
33
|
-
end
|
13
|
+
def process
|
14
|
+
compile_tag
|
34
15
|
end
|
35
16
|
|
36
17
|
private
|
37
18
|
|
38
|
-
def
|
39
|
-
|
40
|
-
if config.respond_to?(:assets)
|
41
|
-
config.assets.configure do |env|
|
42
|
-
if env.respond_to?(:register_transformer)
|
43
|
-
# Sprockets 3 and 4
|
44
|
-
env.register_mime_type mime_type_from, extensions: [file_ext], charset: charset
|
45
|
-
env.register_transformer mime_type_from, mime_type_to, self
|
46
|
-
elsif env.respond_to?(:register_engine)
|
47
|
-
if Sprockets::VERSION.start_with?("3")
|
48
|
-
# Sprockets 3 ... is this needed?
|
49
|
-
env.register_engine file_ext, self, { mime_type: mime_type_to, silence_deprecation: true }
|
50
|
-
else
|
51
|
-
# Sprockets 2.12.4
|
52
|
-
@default_mime_type = mime_type_to
|
53
|
-
env.register_engine file_ext, self
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
else
|
58
|
-
# Sprockets 2.2.3
|
59
|
-
@default_mime_type = mime_type_to
|
60
|
-
app.assets.register_engine file_ext, self
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
class Processor < SprocketsExtensionBase
|
67
|
-
|
68
|
-
def self.run(filename, source, context)
|
69
|
-
::RiotJs::Rails::Compiler.compile(source)
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.register_self(app, config)
|
73
|
-
# app is a YourApp::Application
|
74
|
-
# config is Rails::Railtie::Configuration that belongs to RiotJs::Rails::Railtie
|
75
|
-
register_self_helper(app, config, '.tag', 'text/riot-tag', 'application/javascript', :html)
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.register_nested(app, config, type, charset, tilt_template)
|
79
|
-
extention = '.' + type
|
80
|
-
if config.respond_to?(:assets)
|
81
|
-
config.assets.configure do |env|
|
82
|
-
if env.respond_to?(:register_transformer)
|
83
|
-
# Sprockets 3 and 4
|
84
|
-
env.register_mime_type 'text/riot-tag+'+type, extensions: ['.tag'+extention], charset: charset
|
85
|
-
env.register_transformer 'text/riot-tag+'+type, 'application/javascript',
|
86
|
-
Proc.new{ |input| Processor.call(tilt_template.new{input[:data]}.render) }
|
87
|
-
elsif env.respond_to?(:register_engine)
|
88
|
-
if Sprockets::VERSION.start_with?("3")
|
89
|
-
# Sprockets 3 ... is this needed?
|
90
|
-
env.register_engine extention, tilt_template, { silence_deprecation: true }
|
91
|
-
else
|
92
|
-
# Sprockets 2.12.4
|
93
|
-
env.register_engine extention, tilt_template
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
else
|
98
|
-
# Sprockets 2
|
99
|
-
app.assets.register_engine extention, tilt_template
|
100
|
-
end
|
19
|
+
def compile_tag
|
20
|
+
::RiotJs::Rails::Compiler.compile(@data)
|
101
21
|
end
|
102
22
|
end
|
103
23
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RiotJs
|
2
|
+
module Rails
|
3
|
+
class SprocketsProcessor < Tilt::Template
|
4
|
+
|
5
|
+
self.default_mime_type = 'application/javascript'
|
6
|
+
|
7
|
+
def self.register_self(app)
|
8
|
+
app.assets.register_engine '.tag', self
|
9
|
+
end
|
10
|
+
|
11
|
+
def evaluate(context, locals, &block)
|
12
|
+
@context = context
|
13
|
+
process
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare
|
17
|
+
@data = data
|
18
|
+
end
|
19
|
+
|
20
|
+
def process
|
21
|
+
raise 'Not implemented'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RiotJs
|
2
|
+
module Rails
|
3
|
+
class SprocketsProcessor
|
4
|
+
def self.instance
|
5
|
+
@instance ||= new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.call(input)
|
9
|
+
instance.call(input)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(input)
|
13
|
+
prepare(input)
|
14
|
+
data = process
|
15
|
+
|
16
|
+
@context.metadata.merge(data: data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.register_self(config)
|
20
|
+
config.assets.configure do |env|
|
21
|
+
opts = { mime_type: 'application/javascript', silence_deprecation: true }
|
22
|
+
env.register_engine '.tag', self, opts
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def process
|
29
|
+
raise 'Not implemented'
|
30
|
+
end
|
31
|
+
|
32
|
+
def prepare(input)
|
33
|
+
@context = input[:environment].context_class.new(input)
|
34
|
+
@data = input[:data]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -9,18 +9,15 @@ module RiotJs
|
|
9
9
|
config.riot.node_paths = []
|
10
10
|
|
11
11
|
initializer :setup_sprockets do |app|
|
12
|
-
|
13
|
-
# config is Rails::Railtie::Configuration that belongs to RiotJs::Rails::Railtie
|
14
|
-
Processor.register_self app, config
|
12
|
+
Processor.register_self config
|
15
13
|
|
16
|
-
if defined?
|
14
|
+
if defined? ::Haml
|
17
15
|
require 'tilt/haml'
|
18
|
-
|
19
|
-
Processor.register_nested(app, config, 'haml', :html, ::Tilt::HamlTemplate)
|
16
|
+
config.assets.register_engine '.haml', ::Tilt::HamlTemplate
|
20
17
|
end
|
21
18
|
|
22
|
-
if defined?
|
23
|
-
|
19
|
+
if defined? ::Slim
|
20
|
+
config.assets.register_engine '.slim', ::Slim::Template
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
@@ -39,6 +36,7 @@ module RiotJs
|
|
39
36
|
ENV['NODE_PATH'] = node_paths.join(':')
|
40
37
|
end
|
41
38
|
|
39
|
+
|
42
40
|
def detect_node_global_path
|
43
41
|
prefix = `npm config get prefix`.to_s.chomp("\n")
|
44
42
|
possible_paths = [ "#{prefix}/lib/node", "#{prefix}/lib/node_modules" ]
|
@@ -1,15 +1,15 @@
|
|
1
|
-
/* Riot v3.
|
1
|
+
/* Riot v3.3.1, @license MIT */
|
2
2
|
(function (global, factory) {
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
4
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
5
|
+
(factory((global.riot = global.riot || {})));
|
6
6
|
}(this, (function (exports) { 'use strict';
|
7
7
|
|
8
8
|
var __TAGS_CACHE = [];
|
9
9
|
var __TAG_IMPL = {};
|
10
10
|
var GLOBAL_MIXIN = '__global_mixin';
|
11
11
|
var ATTRS_PREFIX = 'riot-';
|
12
|
-
var REF_DIRECTIVES = ['
|
12
|
+
var REF_DIRECTIVES = ['ref', 'data-ref'];
|
13
13
|
var IS_DIRECTIVE = 'data-is';
|
14
14
|
var CONDITIONAL_DIRECTIVE = 'if';
|
15
15
|
var LOOP_DIRECTIVE = 'each';
|
@@ -371,7 +371,7 @@ var styleManager = {
|
|
371
371
|
|
372
372
|
/**
|
373
373
|
* The riot template engine
|
374
|
-
* @version v3.0.
|
374
|
+
* @version v3.0.2
|
375
375
|
*/
|
376
376
|
/**
|
377
377
|
* riot.util.brackets
|
@@ -610,7 +610,7 @@ var tmpl = (function () {
|
|
610
610
|
function _logErr (err, ctx) {
|
611
611
|
|
612
612
|
err.riotData = {
|
613
|
-
tagName: ctx && ctx.
|
613
|
+
tagName: ctx && ctx.__ && ctx.__.tagName,
|
614
614
|
_riot_id: ctx && ctx._riot_id //eslint-disable-line camelcase
|
615
615
|
};
|
616
616
|
|
@@ -620,7 +620,7 @@ var tmpl = (function () {
|
|
620
620
|
typeof console.error === 'function'
|
621
621
|
) {
|
622
622
|
if (err.riotData.tagName) {
|
623
|
-
console.error('Riot template error thrown in the <%s> tag', err.riotData.tagName
|
623
|
+
console.error('Riot template error thrown in the <%s> tag', err.riotData.tagName);
|
624
624
|
}
|
625
625
|
console.error(err);
|
626
626
|
}
|
@@ -791,7 +791,7 @@ var tmpl = (function () {
|
|
791
791
|
return expr
|
792
792
|
}
|
793
793
|
|
794
|
-
_tmpl.version = brackets.version = 'v3.0.
|
794
|
+
_tmpl.version = brackets.version = 'v3.0.2';
|
795
795
|
|
796
796
|
return _tmpl
|
797
797
|
|
@@ -948,7 +948,7 @@ function each(list, fn) {
|
|
948
948
|
* @returns { Boolean } -
|
949
949
|
*/
|
950
950
|
function contains(array, item) {
|
951
|
-
return
|
951
|
+
return array.indexOf(item) !== -1
|
952
952
|
}
|
953
953
|
|
954
954
|
/**
|
@@ -1021,6 +1021,10 @@ var misc = Object.freeze({
|
|
1021
1021
|
extend: extend
|
1022
1022
|
});
|
1023
1023
|
|
1024
|
+
var settings$1 = extend(Object.create(brackets.settings), {
|
1025
|
+
skipAnonymousTags: true
|
1026
|
+
});
|
1027
|
+
|
1024
1028
|
var EVENTS_PREFIX_REGEX = /^on/;
|
1025
1029
|
|
1026
1030
|
/**
|
@@ -1030,13 +1034,13 @@ var EVENTS_PREFIX_REGEX = /^on/;
|
|
1030
1034
|
* @param { Object } e - event object
|
1031
1035
|
*/
|
1032
1036
|
function handleEvent(dom, handler, e) {
|
1033
|
-
var ptag = this.
|
1034
|
-
item = this.
|
1037
|
+
var ptag = this.__.parent,
|
1038
|
+
item = this.__.item;
|
1035
1039
|
|
1036
1040
|
if (!item)
|
1037
1041
|
{ while (ptag && !item) {
|
1038
|
-
item = ptag.
|
1039
|
-
ptag = ptag.
|
1042
|
+
item = ptag.__.item;
|
1043
|
+
ptag = ptag.__.parent;
|
1040
1044
|
} }
|
1041
1045
|
|
1042
1046
|
// override the event properties
|
@@ -1094,34 +1098,45 @@ function setEventHandler(name, handler, dom, tag) {
|
|
1094
1098
|
*/
|
1095
1099
|
function updateDataIs(expr, parent) {
|
1096
1100
|
var tagName = tmpl(expr.value, parent),
|
1097
|
-
conf;
|
1101
|
+
conf, isVirtual, head, ref;
|
1098
1102
|
|
1099
1103
|
if (expr.tag && expr.tagName === tagName) {
|
1100
1104
|
expr.tag.update();
|
1101
1105
|
return
|
1102
1106
|
}
|
1103
1107
|
|
1108
|
+
isVirtual = expr.dom.tagName === 'VIRTUAL';
|
1104
1109
|
// sync _parent to accommodate changing tagnames
|
1105
1110
|
if (expr.tag) {
|
1106
|
-
|
1111
|
+
|
1112
|
+
// need placeholder before unmount
|
1113
|
+
if(isVirtual) {
|
1114
|
+
head = expr.tag.__.head;
|
1115
|
+
ref = createDOMPlaceholder();
|
1116
|
+
head.parentNode.insertBefore(ref, head);
|
1117
|
+
}
|
1118
|
+
|
1107
1119
|
expr.tag.unmount(true);
|
1108
1120
|
}
|
1109
1121
|
|
1110
1122
|
expr.impl = __TAG_IMPL[tagName];
|
1111
1123
|
conf = {root: expr.dom, parent: parent, hasImpl: true, tagName: tagName};
|
1112
1124
|
expr.tag = initChildTag(expr.impl, conf, expr.dom.innerHTML, parent);
|
1125
|
+
each(expr.attrs, function (a) { return setAttr(expr.tag.root, a.name, a.value); });
|
1113
1126
|
expr.tagName = tagName;
|
1114
1127
|
expr.tag.mount();
|
1128
|
+
if (isVirtual)
|
1129
|
+
{ makeReplaceVirtual(expr.tag, ref || expr.tag.root); } // root exist first time, after use placeholder
|
1115
1130
|
|
1116
1131
|
// parent is the placeholder tag, not the dynamic tag so clean up
|
1117
|
-
parent.
|
1132
|
+
parent.__.onUnmount = function() {
|
1118
1133
|
var delName = expr.tag.opts.dataIs,
|
1119
1134
|
tags = expr.tag.parent.tags,
|
1120
|
-
_tags = expr.tag.
|
1135
|
+
_tags = expr.tag.__.parent.tags;
|
1121
1136
|
arrayishRemove(tags, delName, expr.tag);
|
1122
1137
|
arrayishRemove(_tags, delName, expr.tag);
|
1123
1138
|
expr.tag.unmount();
|
1124
|
-
}
|
1139
|
+
};
|
1125
1140
|
}
|
1126
1141
|
|
1127
1142
|
/**
|
@@ -1131,6 +1146,8 @@ function updateDataIs(expr, parent) {
|
|
1131
1146
|
* @returns { undefined }
|
1132
1147
|
*/
|
1133
1148
|
function updateExpression(expr) {
|
1149
|
+
if (this.root && getAttr(this.root,'virtualized')) { return }
|
1150
|
+
|
1134
1151
|
var dom = expr.dom,
|
1135
1152
|
attrName = expr.attr,
|
1136
1153
|
isToggle = contains([SHOW_DIRECTIVE, HIDE_DIRECTIVE], attrName),
|
@@ -1153,11 +1170,9 @@ function updateExpression(expr) {
|
|
1153
1170
|
} else {
|
1154
1171
|
expr.mount();
|
1155
1172
|
|
1156
|
-
if (isVirtual)
|
1157
|
-
|
1158
|
-
|
1159
|
-
expr.root.parentElement.replaceChild(frag, expr.root);
|
1160
|
-
}
|
1173
|
+
if (isVirtual)
|
1174
|
+
{ makeReplaceVirtual(expr, expr.root); }
|
1175
|
+
|
1161
1176
|
}
|
1162
1177
|
return
|
1163
1178
|
}
|
@@ -1218,13 +1233,12 @@ function updateExpression(expr) {
|
|
1218
1233
|
if (value != null)
|
1219
1234
|
{ setAttr(dom, attrName, value); }
|
1220
1235
|
} else {
|
1221
|
-
|
1222
|
-
if (attrName === 'selected' && parent && /^(SELECT|OPTGROUP)$/.test(parent.tagName) && value) {
|
1223
|
-
parent.value = dom.value;
|
1224
|
-
} if (expr.bool) {
|
1236
|
+
if (expr.bool) {
|
1225
1237
|
dom[attrName] = value;
|
1226
1238
|
if (!value) { return }
|
1227
|
-
}
|
1239
|
+
}
|
1240
|
+
|
1241
|
+
if (value === 0 || value && typeof value !== T_OBJECT) {
|
1228
1242
|
setAttr(dom, attrName, value);
|
1229
1243
|
}
|
1230
1244
|
}
|
@@ -1315,10 +1329,18 @@ var RefExpr = {
|
|
1315
1329
|
remAttr(this.dom, this.attr);
|
1316
1330
|
} else {
|
1317
1331
|
// add it to the refs of parent tag (this behavior was changed >=3.0)
|
1318
|
-
if (customParent) { arrayishAdd(
|
1332
|
+
if (customParent) { arrayishAdd(
|
1333
|
+
customParent.refs,
|
1334
|
+
value,
|
1335
|
+
tagOrDom,
|
1336
|
+
// use an array if it's a looped node and the ref is not an expression
|
1337
|
+
null,
|
1338
|
+
this.parent.__.index
|
1339
|
+
); }
|
1319
1340
|
// set the actual DOM attr
|
1320
1341
|
setAttr(this.dom, this.attr, value);
|
1321
1342
|
}
|
1343
|
+
|
1322
1344
|
this.value = value;
|
1323
1345
|
this.firstRun = false;
|
1324
1346
|
},
|
@@ -1356,21 +1378,30 @@ function mkitem(expr, key, val, base) {
|
|
1356
1378
|
* Unmount the redundant tags
|
1357
1379
|
* @param { Array } items - array containing the current items to loop
|
1358
1380
|
* @param { Array } tags - array containing all the children tags
|
1359
|
-
* @param { String } tagName - key used to identify the type of tag
|
1360
1381
|
*/
|
1361
|
-
function unmountRedundant(items, tags
|
1382
|
+
function unmountRedundant(items, tags) {
|
1362
1383
|
var i = tags.length,
|
1363
|
-
j = items.length
|
1364
|
-
t;
|
1384
|
+
j = items.length;
|
1365
1385
|
|
1366
1386
|
while (i > j) {
|
1367
|
-
|
1368
|
-
|
1369
|
-
t.unmount();
|
1370
|
-
arrayishRemove(t.parent, tagName, t, true);
|
1387
|
+
i--;
|
1388
|
+
remove.apply(tags[i], [tags, i]);
|
1371
1389
|
}
|
1372
1390
|
}
|
1373
1391
|
|
1392
|
+
|
1393
|
+
/**
|
1394
|
+
* Remove a child tag
|
1395
|
+
* @this Tag
|
1396
|
+
* @param { Array } tags - tags collection
|
1397
|
+
* @param { Number } i - index of the tag to remove
|
1398
|
+
*/
|
1399
|
+
function remove(tags, i) {
|
1400
|
+
tags.splice(i, 1);
|
1401
|
+
this.unmount();
|
1402
|
+
arrayishRemove(this.parent, this, this.__.tagName, true);
|
1403
|
+
}
|
1404
|
+
|
1374
1405
|
/**
|
1375
1406
|
* Move the nested custom tags in non custom loop tags
|
1376
1407
|
* @this Tag
|
@@ -1445,10 +1476,9 @@ function _each(dom, parent, expr) {
|
|
1445
1476
|
|
1446
1477
|
var mustReorder = typeof getAttr(dom, LOOP_NO_REORDER_DIRECTIVE) !== T_STRING || remAttr(dom, LOOP_NO_REORDER_DIRECTIVE),
|
1447
1478
|
tagName = getTagName(dom),
|
1448
|
-
impl = __TAG_IMPL[tagName]
|
1449
|
-
useRoot = RE_SPECIAL_TAGS.test(tagName),
|
1479
|
+
impl = __TAG_IMPL[tagName],
|
1450
1480
|
parentNode = dom.parentNode,
|
1451
|
-
|
1481
|
+
placeholder = createDOMPlaceholder(),
|
1452
1482
|
child = getTag(dom),
|
1453
1483
|
ifExpr = getAttr(dom, CONDITIONAL_DIRECTIVE),
|
1454
1484
|
tags = [],
|
@@ -1465,16 +1495,15 @@ function _each(dom, parent, expr) {
|
|
1465
1495
|
if (ifExpr) { remAttr(dom, CONDITIONAL_DIRECTIVE); }
|
1466
1496
|
|
1467
1497
|
// insert a marked where the loop tags will be injected
|
1468
|
-
parentNode.insertBefore(
|
1498
|
+
parentNode.insertBefore(placeholder, dom);
|
1469
1499
|
parentNode.removeChild(dom);
|
1470
1500
|
|
1471
1501
|
expr.update = function updateEach() {
|
1472
|
-
|
1473
1502
|
// get the new items collection
|
1474
1503
|
var items = tmpl(expr.val, parent),
|
1475
1504
|
frag = createFrag(),
|
1476
|
-
isObject$$1 = !isArray(items),
|
1477
|
-
root =
|
1505
|
+
isObject$$1 = !isArray(items) && !isString(items),
|
1506
|
+
root = placeholder.parentNode;
|
1478
1507
|
|
1479
1508
|
// object loop. any changes cause full redraw
|
1480
1509
|
if (isObject$$1) {
|
@@ -1502,26 +1531,25 @@ function _each(dom, parent, expr) {
|
|
1502
1531
|
var
|
1503
1532
|
doReorder = mustReorder && typeof item === T_OBJECT && !hasKeys,
|
1504
1533
|
oldPos = oldItems.indexOf(item),
|
1505
|
-
isNew =
|
1506
|
-
mustAppend = i <= tags.length,
|
1534
|
+
isNew = oldPos === -1,
|
1507
1535
|
pos = !isNew && doReorder ? oldPos : i,
|
1508
1536
|
// does a tag exist in this position?
|
1509
|
-
tag = tags[pos]
|
1537
|
+
tag = tags[pos],
|
1538
|
+
mustAppend = i >= oldItems.length,
|
1539
|
+
mustCreate = doReorder && isNew || !doReorder && !tag;
|
1510
1540
|
|
1511
1541
|
item = !hasKeys && expr.key ? mkitem(expr, item, i) : item;
|
1512
1542
|
|
1513
1543
|
// new tag
|
1514
|
-
if (
|
1515
|
-
doReorder && isNew // by default we always try to reorder the DOM elements
|
1516
|
-
||
|
1517
|
-
!doReorder && !tag // with no-reorder we just update the old tags
|
1518
|
-
) {
|
1544
|
+
if (mustCreate) {
|
1519
1545
|
tag = new Tag$1(impl, {
|
1520
1546
|
parent: parent,
|
1521
1547
|
isLoop: isLoop,
|
1522
1548
|
isAnonymous: isAnonymous,
|
1523
|
-
|
1524
|
-
|
1549
|
+
tagName: tagName,
|
1550
|
+
root: dom.cloneNode(isAnonymous),
|
1551
|
+
item: item,
|
1552
|
+
index: i,
|
1525
1553
|
}, dom.innerHTML);
|
1526
1554
|
|
1527
1555
|
// mount the tag
|
@@ -1535,21 +1563,22 @@ function _each(dom, parent, expr) {
|
|
1535
1563
|
if (!mustAppend) { oldItems.splice(i, 0, item); }
|
1536
1564
|
tags.splice(i, 0, tag);
|
1537
1565
|
if (child) { arrayishAdd(parent.tags, tagName, tag, true); }
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
// reorder the tag if it's not located in its previous position
|
1542
|
-
if (pos !== i && doReorder) {
|
1543
|
-
// #closes 2040
|
1544
|
-
if (contains(items, oldItems[i])) {
|
1566
|
+
} else if (pos !== i && doReorder) {
|
1567
|
+
// move
|
1568
|
+
if (contains(items, oldItems[pos])) {
|
1545
1569
|
move.apply(tag, [root, tags[i], isVirtual]);
|
1570
|
+
// move the old tag instance
|
1571
|
+
tags.splice(i, 0, tags.splice(pos, 1)[0]);
|
1572
|
+
// move the old item
|
1573
|
+
oldItems.splice(i, 0, oldItems.splice(pos, 1)[0]);
|
1574
|
+
} else { // remove
|
1575
|
+
remove.apply(tags[i], [tags, i]);
|
1576
|
+
oldItems.splice(i, 1);
|
1546
1577
|
}
|
1578
|
+
|
1547
1579
|
// update the position attribute if it exists
|
1548
1580
|
if (expr.pos) { tag[expr.pos] = i; }
|
1549
|
-
|
1550
|
-
tags.splice(i, 0, tags.splice(pos, 1)[0]);
|
1551
|
-
// move the old item
|
1552
|
-
oldItems.splice(i, 0, oldItems.splice(pos, 1)[0]);
|
1581
|
+
|
1553
1582
|
// if the loop tags are not custom
|
1554
1583
|
// we need to move all their custom tags into the right position
|
1555
1584
|
if (!child && tag.tags) { moveNestedTags.call(tag, i); }
|
@@ -1557,18 +1586,20 @@ function _each(dom, parent, expr) {
|
|
1557
1586
|
|
1558
1587
|
// cache the original item to use it in the events bound to this node
|
1559
1588
|
// and its children
|
1560
|
-
tag.
|
1561
|
-
|
1562
|
-
|
1589
|
+
tag.__.item = item;
|
1590
|
+
tag.__.index = i;
|
1591
|
+
tag.__.parent = parent;
|
1592
|
+
|
1593
|
+
if (!mustCreate) { tag.update(item); }
|
1563
1594
|
});
|
1564
1595
|
|
1565
1596
|
// remove the redundant tags
|
1566
|
-
unmountRedundant(items, tags
|
1597
|
+
unmountRedundant(items, tags);
|
1567
1598
|
|
1568
1599
|
// clone the items array
|
1569
1600
|
oldItems = items.slice();
|
1570
1601
|
|
1571
|
-
root.insertBefore(frag,
|
1602
|
+
root.insertBefore(frag, placeholder);
|
1572
1603
|
};
|
1573
1604
|
|
1574
1605
|
expr.unmount = function() {
|
@@ -1601,8 +1632,11 @@ function parseExpressions(root, expressions, mustIncludeRoot) {
|
|
1601
1632
|
|
1602
1633
|
if (type !== 1) { return ctx } // not an element
|
1603
1634
|
|
1635
|
+
var isVirtual = dom.tagName === 'VIRTUAL';
|
1636
|
+
|
1604
1637
|
// loop. each does it's own thing (for now)
|
1605
1638
|
if (attr = getAttr(dom, LOOP_DIRECTIVE)) {
|
1639
|
+
if(isVirtual) { setAttr(dom, 'loopVirtual', true); } // ignore here, handled in _each
|
1606
1640
|
parent.children.push(_each(dom, this$1, attr));
|
1607
1641
|
return false
|
1608
1642
|
}
|
@@ -1624,10 +1658,27 @@ function parseExpressions(root, expressions, mustIncludeRoot) {
|
|
1624
1658
|
// if this is a tag, stop traversing here.
|
1625
1659
|
// we ignore the root, since parseExpressions is called while we're mounting that root
|
1626
1660
|
tagImpl = getTag(dom);
|
1661
|
+
if(isVirtual) {
|
1662
|
+
if(getAttr(dom, 'virtualized')) {dom.parentElement.removeChild(dom); } // tag created, remove from dom
|
1663
|
+
if(!tagImpl && !getAttr(dom, 'virtualized') && !getAttr(dom, 'loopVirtual')) // ok to create virtual tag
|
1664
|
+
{ tagImpl = { tmpl: dom.outerHTML }; }
|
1665
|
+
}
|
1666
|
+
|
1627
1667
|
if (tagImpl && (dom !== root || mustIncludeRoot)) {
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1668
|
+
if(isVirtual && !getAttr(dom, IS_DIRECTIVE)) { // handled in update
|
1669
|
+
// can not remove attribute like directives
|
1670
|
+
// so flag for removal after creation to prevent maximum stack error
|
1671
|
+
setAttr(dom, 'virtualized', true);
|
1672
|
+
|
1673
|
+
var tag = new Tag$1({ tmpl: dom.outerHTML },
|
1674
|
+
{root: dom, parent: this$1},
|
1675
|
+
dom.innerHTML);
|
1676
|
+
parent.children.push(tag); // no return, anonymous tag, keep parsing
|
1677
|
+
} else {
|
1678
|
+
var conf = {root: dom, parent: this$1, hasImpl: true};
|
1679
|
+
parent.children.push(initChildTag(tagImpl, conf, dom.innerHTML, this$1));
|
1680
|
+
return false
|
1681
|
+
}
|
1631
1682
|
}
|
1632
1683
|
|
1633
1684
|
// attribute expressions
|
@@ -1759,8 +1810,6 @@ function mkdom(tmpl, html, checkSvg) {
|
|
1759
1810
|
else
|
1760
1811
|
{ setInnerHTML(el, tmpl); }
|
1761
1812
|
|
1762
|
-
el.stub = true;
|
1763
|
-
|
1764
1813
|
return el
|
1765
1814
|
}
|
1766
1815
|
|
@@ -1975,6 +2024,17 @@ function unregister$1(name) {
|
|
1975
2024
|
delete __TAG_IMPL[name];
|
1976
2025
|
}
|
1977
2026
|
|
2027
|
+
|
2028
|
+
var core = Object.freeze({
|
2029
|
+
Tag: Tag$2,
|
2030
|
+
tag: tag$1,
|
2031
|
+
tag2: tag2$1,
|
2032
|
+
mount: mount$1,
|
2033
|
+
mixin: mixin$1,
|
2034
|
+
update: update$1,
|
2035
|
+
unregister: unregister$1
|
2036
|
+
});
|
2037
|
+
|
1978
2038
|
// counter to give a unique id to all the Tag instances
|
1979
2039
|
var __uid = 0;
|
1980
2040
|
|
@@ -2010,12 +2070,17 @@ function updateOpts(isLoop, parent, isAnonymous, opts, instAttrs) {
|
|
2010
2070
|
* @param { String } innerHTML - html that eventually we need to inject in the tag
|
2011
2071
|
*/
|
2012
2072
|
function Tag$1(impl, conf, innerHTML) {
|
2073
|
+
if ( impl === void 0 ) impl = {};
|
2074
|
+
if ( conf === void 0 ) conf = {};
|
2075
|
+
|
2013
2076
|
|
2014
2077
|
var opts = extend({}, conf.opts),
|
2015
2078
|
parent = conf.parent,
|
2016
2079
|
isLoop = conf.isLoop,
|
2017
|
-
isAnonymous = conf.isAnonymous,
|
2080
|
+
isAnonymous = !!conf.isAnonymous,
|
2081
|
+
skipAnonymous = settings$1.skipAnonymousTags && isAnonymous,
|
2018
2082
|
item = cleanUpData(conf.item),
|
2083
|
+
index = conf.index, // available only for the looped nodes
|
2019
2084
|
instAttrs = [], // All attributes on the Tag when it's first parsed
|
2020
2085
|
implAttrs = [], // expressions on this type of Tag
|
2021
2086
|
expressions = [],
|
@@ -2026,35 +2091,39 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2026
2091
|
dom;
|
2027
2092
|
|
2028
2093
|
// make this tag observable
|
2029
|
-
observable$1(this);
|
2094
|
+
if (!skipAnonymous) { observable$1(this); }
|
2030
2095
|
// only call unmount if we have a valid __TAG_IMPL (has name property)
|
2031
2096
|
if (impl.name && root._tag) { root._tag.unmount(true); }
|
2032
2097
|
|
2033
2098
|
// not yet mounted
|
2034
2099
|
this.isMounted = false;
|
2035
|
-
root.isLoop = isLoop;
|
2036
2100
|
|
2037
|
-
defineProperty(this, '
|
2101
|
+
defineProperty(this, '__', {
|
2038
2102
|
isAnonymous: isAnonymous,
|
2039
2103
|
instAttrs: instAttrs,
|
2040
2104
|
innerHTML: innerHTML,
|
2105
|
+
tagName: tagName,
|
2106
|
+
index: index,
|
2107
|
+
isLoop: isLoop,
|
2041
2108
|
// these vars will be needed only for the virtual tags
|
2042
2109
|
virts: [],
|
2043
2110
|
tail: null,
|
2044
|
-
head: null
|
2111
|
+
head: null,
|
2112
|
+
parent: null,
|
2113
|
+
item: null
|
2045
2114
|
});
|
2046
2115
|
|
2047
2116
|
// create a unique id to this tag
|
2048
2117
|
// it could be handy to use it also to improve the virtual dom rendering speed
|
2049
2118
|
defineProperty(this, '_riot_id', ++__uid); // base 1 allows test !t._riot_id
|
2050
|
-
|
2051
|
-
extend(this, {
|
2119
|
+
defineProperty(this, 'root', root);
|
2120
|
+
extend(this, { opts: opts }, item);
|
2052
2121
|
// protect the "tags" and "refs" property from being overridden
|
2053
2122
|
defineProperty(this, 'parent', parent || null);
|
2054
2123
|
defineProperty(this, 'tags', {});
|
2055
2124
|
defineProperty(this, 'refs', {});
|
2056
2125
|
|
2057
|
-
dom = mkdom(impl.tmpl, innerHTML, isLoop);
|
2126
|
+
dom = isLoop && isAnonymous ? root : mkdom(impl.tmpl, innerHTML, isLoop);
|
2058
2127
|
|
2059
2128
|
/**
|
2060
2129
|
* Update the tag expressions and options
|
@@ -2062,7 +2131,11 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2062
2131
|
* @returns { Tag } the current tag instance
|
2063
2132
|
*/
|
2064
2133
|
defineProperty(this, 'update', function tagUpdate(data) {
|
2065
|
-
|
2134
|
+
var nextOpts = {},
|
2135
|
+
canTrigger = this.isMounted && !skipAnonymous;
|
2136
|
+
|
2137
|
+
updateOpts.apply(this, [isLoop, parent, isAnonymous, nextOpts, instAttrs]);
|
2138
|
+
if (this.isMounted && isFunction(this.shouldUpdate) && !this.shouldUpdate(data, nextOpts)) { return this }
|
2066
2139
|
|
2067
2140
|
// make sure the data passed will not override
|
2068
2141
|
// the component core methods
|
@@ -2071,10 +2144,10 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2071
2144
|
// inherit properties from the parent, but only for isAnonymous tags
|
2072
2145
|
if (isLoop && isAnonymous) { inheritFrom.apply(this, [this.parent, propsInSyncWithParent]); }
|
2073
2146
|
extend(this, data);
|
2074
|
-
|
2075
|
-
if (
|
2147
|
+
extend(opts, nextOpts);
|
2148
|
+
if (canTrigger) { this.trigger('update', data); }
|
2076
2149
|
updateAllExpressions.call(this, expressions);
|
2077
|
-
if (
|
2150
|
+
if (canTrigger) { this.trigger('updated'); }
|
2078
2151
|
|
2079
2152
|
return this
|
2080
2153
|
|
@@ -2140,6 +2213,7 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2140
2213
|
defineProperty(this, 'mount', function tagMount() {
|
2141
2214
|
var this$1 = this;
|
2142
2215
|
|
2216
|
+
var _parent = this.__.parent;
|
2143
2217
|
root._tag = this; // keep a reference to the tag just created
|
2144
2218
|
|
2145
2219
|
// Read all the attrs on this instance. This give us the info we need for updateOpts
|
@@ -2158,7 +2232,7 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2158
2232
|
}]);
|
2159
2233
|
|
2160
2234
|
// children in loop should inherit from true parent
|
2161
|
-
if (
|
2235
|
+
if (_parent && isAnonymous) { inheritFrom.apply(this, [_parent, propsInSyncWithParent]); }
|
2162
2236
|
|
2163
2237
|
// initialiation
|
2164
2238
|
updateOpts.apply(this, [isLoop, parent, isAnonymous, opts, instAttrs]);
|
@@ -2166,7 +2240,7 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2166
2240
|
// add global mixins
|
2167
2241
|
var globalMixin = mixin$1(GLOBAL_MIXIN);
|
2168
2242
|
|
2169
|
-
if (globalMixin) {
|
2243
|
+
if (globalMixin && !skipAnonymous) {
|
2170
2244
|
for (var i in globalMixin) {
|
2171
2245
|
if (globalMixin.hasOwnProperty(i)) {
|
2172
2246
|
this$1.mixin(globalMixin[i]);
|
@@ -2176,32 +2250,33 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2176
2250
|
|
2177
2251
|
if (impl.fn) { impl.fn.call(this, opts); }
|
2178
2252
|
|
2179
|
-
this.trigger('before-mount');
|
2253
|
+
if (!skipAnonymous) { this.trigger('before-mount'); }
|
2180
2254
|
|
2181
2255
|
// parse layout after init. fn may calculate args for nested custom tags
|
2182
|
-
parseExpressions.apply(this, [dom, expressions,
|
2256
|
+
parseExpressions.apply(this, [dom, expressions, isAnonymous]);
|
2183
2257
|
|
2184
2258
|
this.update(item);
|
2185
2259
|
|
2186
|
-
if (
|
2187
|
-
// update the root attribute for the looped elements
|
2188
|
-
this.root = root = dom.firstChild;
|
2189
|
-
} else {
|
2260
|
+
if (!isAnonymous) {
|
2190
2261
|
while (dom.firstChild) { root.appendChild(dom.firstChild); }
|
2191
|
-
if (root.stub) { root = parent.root; }
|
2192
2262
|
}
|
2193
2263
|
|
2194
2264
|
defineProperty(this, 'root', root);
|
2195
|
-
this
|
2265
|
+
defineProperty(this, 'isMounted', true);
|
2266
|
+
|
2267
|
+
if (skipAnonymous) { return }
|
2196
2268
|
|
2197
2269
|
// if it's not a child tag we can trigger its mount event
|
2198
|
-
if (!this.parent
|
2270
|
+
if (!this.parent) {
|
2199
2271
|
this.trigger('mount');
|
2200
2272
|
}
|
2201
|
-
// otherwise we need to wait that the parent event gets triggered
|
2202
|
-
else {
|
2203
|
-
this
|
2204
|
-
|
2273
|
+
// otherwise we need to wait that the parent "mount" or "updated" event gets triggered
|
2274
|
+
else {
|
2275
|
+
var p = getImmediateCustomParentTag(this.parent);
|
2276
|
+
p.one(!p.isMounted ? 'mount' : 'updated', function () {
|
2277
|
+
this$1.trigger('mount');
|
2278
|
+
});
|
2279
|
+
}
|
2205
2280
|
|
2206
2281
|
return this
|
2207
2282
|
|
@@ -2220,7 +2295,7 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2220
2295
|
ptag,
|
2221
2296
|
tagIndex = __TAGS_CACHE.indexOf(this);
|
2222
2297
|
|
2223
|
-
this.trigger('before-unmount');
|
2298
|
+
if (!skipAnonymous) { this.trigger('before-unmount'); }
|
2224
2299
|
|
2225
2300
|
// clear all attributes coming from the mounted tag
|
2226
2301
|
walkAttrs(impl.attrs, function (name) {
|
@@ -2230,10 +2305,10 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2230
2305
|
});
|
2231
2306
|
|
2232
2307
|
// remove this tag instance from the global virtualDom variable
|
2233
|
-
if (
|
2308
|
+
if (tagIndex !== -1)
|
2234
2309
|
{ __TAGS_CACHE.splice(tagIndex, 1); }
|
2235
2310
|
|
2236
|
-
if (p) {
|
2311
|
+
if (p || isVirtual) {
|
2237
2312
|
if (parent) {
|
2238
2313
|
ptag = getImmediateCustomParentTag(parent);
|
2239
2314
|
|
@@ -2250,16 +2325,17 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2250
2325
|
while (el.firstChild) { el.removeChild(el.firstChild); }
|
2251
2326
|
}
|
2252
2327
|
|
2253
|
-
if (
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2328
|
+
if (p)
|
2329
|
+
{ if (!mustKeepRoot) {
|
2330
|
+
p.removeChild(el);
|
2331
|
+
} else {
|
2332
|
+
// the riot-tag and the data-is attributes aren't needed anymore, remove them
|
2333
|
+
remAttr(p, IS_DIRECTIVE);
|
2334
|
+
} }
|
2259
2335
|
}
|
2260
2336
|
|
2261
|
-
if (this.
|
2262
|
-
each(this.
|
2337
|
+
if (this.__.virts) {
|
2338
|
+
each(this.__.virts, function (v) {
|
2263
2339
|
if (v.parentNode) { v.parentNode.removeChild(v); }
|
2264
2340
|
});
|
2265
2341
|
}
|
@@ -2268,9 +2344,15 @@ function Tag$1(impl, conf, innerHTML) {
|
|
2268
2344
|
unmountAll(expressions);
|
2269
2345
|
each(instAttrs, function (a) { return a.expr && a.expr.unmount && a.expr.unmount(); });
|
2270
2346
|
|
2271
|
-
|
2272
|
-
this.
|
2273
|
-
|
2347
|
+
// custom internal unmount function to avoid relying on the observable
|
2348
|
+
if (this.__.onUnmount) { this.__.onUnmount(); }
|
2349
|
+
|
2350
|
+
if (!skipAnonymous) {
|
2351
|
+
this.trigger('unmount');
|
2352
|
+
this.off('*');
|
2353
|
+
}
|
2354
|
+
|
2355
|
+
defineProperty(this, 'isMounted', false);
|
2274
2356
|
|
2275
2357
|
delete this.root._tag;
|
2276
2358
|
|
@@ -2347,7 +2429,7 @@ function initChildTag(child, opts, innerHTML, parent) {
|
|
2347
2429
|
// store the real parent tag
|
2348
2430
|
// in some cases this could be different from the custom parent tag
|
2349
2431
|
// for example in nested loops
|
2350
|
-
tag.
|
2432
|
+
tag.__.parent = parent;
|
2351
2433
|
|
2352
2434
|
// add this tag to the custom parent tag
|
2353
2435
|
arrayishAdd(ptag.tags, tagName, tag);
|
@@ -2370,7 +2452,7 @@ function initChildTag(child, opts, innerHTML, parent) {
|
|
2370
2452
|
*/
|
2371
2453
|
function getImmediateCustomParentTag(tag) {
|
2372
2454
|
var ptag = tag;
|
2373
|
-
while (ptag.
|
2455
|
+
while (ptag.__.isAnonymous) {
|
2374
2456
|
if (!ptag.parent) { break }
|
2375
2457
|
ptag = ptag.parent;
|
2376
2458
|
}
|
@@ -2425,10 +2507,12 @@ function cleanUpData(data) {
|
|
2425
2507
|
* @param { String } key - property name
|
2426
2508
|
* @param { Object } value - the value of the property to be set
|
2427
2509
|
* @param { Boolean } ensureArray - ensure that the property remains an array
|
2510
|
+
* @param { Number } index - add the new item in a certain array position
|
2428
2511
|
*/
|
2429
|
-
function arrayishAdd(obj, key, value, ensureArray) {
|
2512
|
+
function arrayishAdd(obj, key, value, ensureArray, index) {
|
2430
2513
|
var dest = obj[key];
|
2431
2514
|
var isArr = isArray(dest);
|
2515
|
+
var hasIndex = !isUndefined(index);
|
2432
2516
|
|
2433
2517
|
if (dest && dest === value) { return }
|
2434
2518
|
|
@@ -2436,9 +2520,20 @@ function arrayishAdd(obj, key, value, ensureArray) {
|
|
2436
2520
|
if (!dest && ensureArray) { obj[key] = [value]; }
|
2437
2521
|
else if (!dest) { obj[key] = value; }
|
2438
2522
|
// if it was an array and not yet set
|
2439
|
-
else
|
2440
|
-
if (isArr) {
|
2441
|
-
|
2523
|
+
else {
|
2524
|
+
if (isArr) {
|
2525
|
+
var oldIndex = dest.indexOf(value);
|
2526
|
+
// this item never changed its position
|
2527
|
+
if (oldIndex === index) { return }
|
2528
|
+
// remove the item from its old position
|
2529
|
+
if (oldIndex !== -1) { dest.splice(oldIndex, 1); }
|
2530
|
+
// move or add the item
|
2531
|
+
if (hasIndex) {
|
2532
|
+
dest.splice(index, 0, value);
|
2533
|
+
} else {
|
2534
|
+
dest.push(value);
|
2535
|
+
}
|
2536
|
+
} else { obj[key] = [dest, value]; }
|
2442
2537
|
}
|
2443
2538
|
}
|
2444
2539
|
|
@@ -2452,9 +2547,8 @@ function arrayishAdd(obj, key, value, ensureArray) {
|
|
2452
2547
|
*/
|
2453
2548
|
function arrayishRemove(obj, key, value, ensureArray) {
|
2454
2549
|
if (isArray(obj[key])) {
|
2455
|
-
|
2456
|
-
|
2457
|
-
});
|
2550
|
+
var index = obj[key].indexOf(value);
|
2551
|
+
if (index !== -1) { obj[key].splice(index, 1); }
|
2458
2552
|
if (!obj[key].length) { delete obj[key]; }
|
2459
2553
|
else if (obj[key].length === 1 && !ensureArray) { obj[key] = obj[key][0]; }
|
2460
2554
|
} else
|
@@ -2507,6 +2601,17 @@ function mountTo(root, tagName, opts, ctx) {
|
|
2507
2601
|
return tag
|
2508
2602
|
}
|
2509
2603
|
|
2604
|
+
/**
|
2605
|
+
* makes a tag virtual and replaces a reference in the dom
|
2606
|
+
* @this Tag
|
2607
|
+
* @param { tag } the tag to make virtual
|
2608
|
+
* @param { ref } the dom reference location
|
2609
|
+
*/
|
2610
|
+
function makeReplaceVirtual(tag, ref) {
|
2611
|
+
var frag = createFrag();
|
2612
|
+
makeVirtual.call(tag, frag);
|
2613
|
+
ref.parentNode.replaceChild(frag, ref);
|
2614
|
+
}
|
2510
2615
|
|
2511
2616
|
/**
|
2512
2617
|
* Adds the elements for a virtual tag
|
@@ -2522,20 +2627,20 @@ function makeVirtual(src, target) {
|
|
2522
2627
|
frag = createFrag(),
|
2523
2628
|
sib, el;
|
2524
2629
|
|
2525
|
-
this.
|
2526
|
-
this.
|
2630
|
+
this.__.head = this.root.insertBefore(head, this.root.firstChild);
|
2631
|
+
this.__.tail = this.root.appendChild(tail);
|
2527
2632
|
|
2528
|
-
el = this.
|
2633
|
+
el = this.__.head;
|
2529
2634
|
|
2530
2635
|
while (el) {
|
2531
2636
|
sib = el.nextSibling;
|
2532
2637
|
frag.appendChild(el);
|
2533
|
-
this$1.
|
2638
|
+
this$1.__.virts.push(el); // hold for unmounting
|
2534
2639
|
el = sib;
|
2535
2640
|
}
|
2536
2641
|
|
2537
2642
|
if (target)
|
2538
|
-
{ src.insertBefore(frag, target.
|
2643
|
+
{ src.insertBefore(frag, target.__.head); }
|
2539
2644
|
else
|
2540
2645
|
{ src.appendChild(frag); }
|
2541
2646
|
}
|
@@ -2549,7 +2654,7 @@ function makeVirtual(src, target) {
|
|
2549
2654
|
function moveVirtual(src, target) {
|
2550
2655
|
var this$1 = this;
|
2551
2656
|
|
2552
|
-
var el = this.
|
2657
|
+
var el = this.__.head,
|
2553
2658
|
frag = createFrag(),
|
2554
2659
|
sib;
|
2555
2660
|
|
@@ -2557,9 +2662,9 @@ function moveVirtual(src, target) {
|
|
2557
2662
|
sib = el.nextSibling;
|
2558
2663
|
frag.appendChild(el);
|
2559
2664
|
el = sib;
|
2560
|
-
if (el === this$1.
|
2665
|
+
if (el === this$1.__.tail) {
|
2561
2666
|
frag.appendChild(el);
|
2562
|
-
src.insertBefore(frag, target.
|
2667
|
+
src.insertBefore(frag, target.__.head);
|
2563
2668
|
break
|
2564
2669
|
}
|
2565
2670
|
}
|
@@ -2599,6 +2704,7 @@ var tags = Object.freeze({
|
|
2599
2704
|
arrayishRemove: arrayishRemove,
|
2600
2705
|
isInStub: isInStub,
|
2601
2706
|
mountTo: mountTo,
|
2707
|
+
makeReplaceVirtual: makeReplaceVirtual,
|
2602
2708
|
makeVirtual: makeVirtual,
|
2603
2709
|
moveVirtual: moveVirtual,
|
2604
2710
|
selectTags: selectTags
|
@@ -2607,8 +2713,7 @@ var tags = Object.freeze({
|
|
2607
2713
|
/**
|
2608
2714
|
* Riot public api
|
2609
2715
|
*/
|
2610
|
-
var settings =
|
2611
|
-
|
2716
|
+
var settings = settings$1;
|
2612
2717
|
var util = {
|
2613
2718
|
tmpl: tmpl,
|
2614
2719
|
brackets: brackets,
|
@@ -2632,19 +2737,11 @@ var update$$1 = update$1;
|
|
2632
2737
|
var unregister$$1 = unregister$1;
|
2633
2738
|
var observable = observable$1;
|
2634
2739
|
|
2635
|
-
var riot$1 = {
|
2740
|
+
var riot$1 = extend({}, core, {
|
2741
|
+
observable: observable$1,
|
2636
2742
|
settings: settings,
|
2637
2743
|
util: util,
|
2638
|
-
|
2639
|
-
Tag: Tag$$1,
|
2640
|
-
tag: tag$$1,
|
2641
|
-
tag2: tag2$$1,
|
2642
|
-
mount: mount$$1,
|
2643
|
-
mixin: mixin$$1,
|
2644
|
-
update: update$$1,
|
2645
|
-
unregister: unregister$$1,
|
2646
|
-
observable: observable
|
2647
|
-
};
|
2744
|
+
});
|
2648
2745
|
|
2649
2746
|
exports.settings = settings;
|
2650
2747
|
exports.util = util;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot_js-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Jaroszewski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,6 +131,8 @@ files:
|
|
131
131
|
- lib/riot_js/rails/processors/compiler.rb
|
132
132
|
- lib/riot_js/rails/processors/processor.rb
|
133
133
|
- lib/riot_js/rails/processors/renderer.rb
|
134
|
+
- lib/riot_js/rails/processors/sprockets_processor_v2.rb
|
135
|
+
- lib/riot_js/rails/processors/sprockets_processor_v3.rb
|
134
136
|
- lib/riot_js/rails/railtie.rb
|
135
137
|
- lib/riot_js/rails/version.rb
|
136
138
|
- riot_js-rails.gemspec
|
@@ -173,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
175
|
version: '0'
|
174
176
|
requirements: []
|
175
177
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.4.5.1
|
177
179
|
signing_key:
|
178
180
|
specification_version: 4
|
179
181
|
summary: Muut Riot integration with Rails.
|