poulet 0.0.6 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +268 -4
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.global.js +2 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +16 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.global.js +25 -0
- package/dist/react.global.js.map +1 -0
- package/dist/react.js +2 -0
- package/dist/react.js.map +1 -0
- package/package.json +70 -52
- package/LICENSE +0 -22
- package/dist/.gitkeep +0 -0
- package/dist/poulet.common.js +0 -959
- package/dist/poulet.js +0 -962
- package/dist/poulet.min.js +0 -7
- package/dist/poulet.mjs +0 -957
- package/lib/Core/Component/_copyAccessor.js +0 -3
- package/lib/Core/Component/_defineReactive.js +0 -46
- package/lib/Core/Component/_mergeMixins.js +0 -53
- package/lib/Core/Component/index.js +0 -139
- package/lib/Core/Directive/_stringParser.js +0 -61
- package/lib/Core/Directive/index.js +0 -93
- package/lib/Core/Observer.js +0 -32
- package/lib/Core/index.js +0 -140
- package/lib/Directives/Class.js +0 -26
- package/lib/Directives/Html.js +0 -7
- package/lib/Directives/Model.js +0 -57
- package/lib/Directives/On.js +0 -13
- package/lib/Directives/Show.js +0 -9
- package/lib/Directives/Style.js +0 -7
- package/lib/Directives/Text.js +0 -7
- package/lib/Directives/index.js +0 -6
- package/lib/Mixins/index.js +0 -0
- package/lib/get.js +0 -10
- package/lib/index.js +0 -6
- package/lib/set.js +0 -10
package/dist/poulet.common.js
DELETED
|
@@ -1,959 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Poulet.js v0.0.6
|
|
3
|
-
* (c) 2017 Alex Toudic
|
|
4
|
-
* Released under MIT License.
|
|
5
|
-
**/
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
var lodash = require('lodash');
|
|
10
|
-
var chirashi = require('chirashi');
|
|
11
|
-
|
|
12
|
-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
13
|
-
return typeof obj;
|
|
14
|
-
} : function (obj) {
|
|
15
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var classCallCheck = function (instance, Constructor) {
|
|
29
|
-
if (!(instance instanceof Constructor)) {
|
|
30
|
-
throw new TypeError("Cannot call a class as a function");
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
var createClass = function () {
|
|
35
|
-
function defineProperties(target, props) {
|
|
36
|
-
for (var i = 0; i < props.length; i++) {
|
|
37
|
-
var descriptor = props[i];
|
|
38
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
-
descriptor.configurable = true;
|
|
40
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return function (Constructor, protoProps, staticProps) {
|
|
46
|
-
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
47
|
-
if (staticProps) defineProperties(Constructor, staticProps);
|
|
48
|
-
return Constructor;
|
|
49
|
-
};
|
|
50
|
-
}();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var defineProperty = function (obj, key, value) {
|
|
57
|
-
if (key in obj) {
|
|
58
|
-
Object.defineProperty(obj, key, {
|
|
59
|
-
value: value,
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true
|
|
63
|
-
});
|
|
64
|
-
} else {
|
|
65
|
-
obj[key] = value;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return obj;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
var _extends = Object.assign || function (target) {
|
|
72
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
73
|
-
var source = arguments[i];
|
|
74
|
-
|
|
75
|
-
for (var key in source) {
|
|
76
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
77
|
-
target[key] = source[key];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return target;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var get = function get(object, property, receiver) {
|
|
86
|
-
if (object === null) object = Function.prototype;
|
|
87
|
-
var desc = Object.getOwnPropertyDescriptor(object, property);
|
|
88
|
-
|
|
89
|
-
if (desc === undefined) {
|
|
90
|
-
var parent = Object.getPrototypeOf(object);
|
|
91
|
-
|
|
92
|
-
if (parent === null) {
|
|
93
|
-
return undefined;
|
|
94
|
-
} else {
|
|
95
|
-
return get(parent, property, receiver);
|
|
96
|
-
}
|
|
97
|
-
} else if ("value" in desc) {
|
|
98
|
-
return desc.value;
|
|
99
|
-
} else {
|
|
100
|
-
var getter = desc.get;
|
|
101
|
-
|
|
102
|
-
if (getter === undefined) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return getter.call(receiver);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
var inherits = function (subClass, superClass) {
|
|
111
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
112
|
-
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
116
|
-
constructor: {
|
|
117
|
-
value: subClass,
|
|
118
|
-
enumerable: false,
|
|
119
|
-
writable: true,
|
|
120
|
-
configurable: true
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var possibleConstructorReturn = function (self, call) {
|
|
137
|
-
if (!self) {
|
|
138
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
var toConsumableArray = function (arr) {
|
|
163
|
-
if (Array.isArray(arr)) {
|
|
164
|
-
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
165
|
-
|
|
166
|
-
return arr2;
|
|
167
|
-
} else {
|
|
168
|
-
return Array.from(arr);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
var Observer = function () {
|
|
173
|
-
function Observer(domElement) {
|
|
174
|
-
classCallCheck(this, Observer);
|
|
175
|
-
|
|
176
|
-
this._observer = new MutationObserver(this._update.bind(this));
|
|
177
|
-
|
|
178
|
-
this._observer.observe(domElement, {
|
|
179
|
-
childList: true,
|
|
180
|
-
subtree: true
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
this._listeners = [];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
createClass(Observer, [{
|
|
187
|
-
key: 'on',
|
|
188
|
-
value: function on$$1(callback) {
|
|
189
|
-
this._listeners.push(callback);
|
|
190
|
-
}
|
|
191
|
-
}, {
|
|
192
|
-
key: 'off',
|
|
193
|
-
value: function off(callback) {
|
|
194
|
-
this._listeners.splice(this._listeners.indexOf(callback), 1);
|
|
195
|
-
}
|
|
196
|
-
}, {
|
|
197
|
-
key: '_update',
|
|
198
|
-
value: function _update() {
|
|
199
|
-
chirashi.forEach(this._listeners, function (listener) {
|
|
200
|
-
try {
|
|
201
|
-
listener();
|
|
202
|
-
} catch (e) {
|
|
203
|
-
console.error(e);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}]);
|
|
208
|
-
return Observer;
|
|
209
|
-
}();
|
|
210
|
-
|
|
211
|
-
var get$1 = function (obj, key) {
|
|
212
|
-
var keys = key.split('.');
|
|
213
|
-
key = keys.pop();
|
|
214
|
-
var n = keys.length;
|
|
215
|
-
for (var i = 0; i < n; ++i) {
|
|
216
|
-
obj = obj[keys[i]];
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return obj[key];
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
function _copyAccessor(key, to, from) {
|
|
223
|
-
Object.defineProperty(to, key, Object.getOwnPropertyDescriptor(from, key));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
var _arrayChangingMethods = ['push', 'splice', 'unshift'];
|
|
227
|
-
|
|
228
|
-
function _defineReactive(watchers, watchKey, output, key, value) {
|
|
229
|
-
watchKey += key;
|
|
230
|
-
|
|
231
|
-
watchers[watchKey] = {};
|
|
232
|
-
|
|
233
|
-
Object.defineProperty(output, key, {
|
|
234
|
-
get: function get$$1() {
|
|
235
|
-
return value;
|
|
236
|
-
},
|
|
237
|
-
set: function set$$1(newValue) {
|
|
238
|
-
chirashi.forIn(watchers[watchKey], function (key, options) {
|
|
239
|
-
return options.beforeChange();
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
value = newValue;
|
|
243
|
-
|
|
244
|
-
if ((typeof newValue === 'undefined' ? 'undefined' : _typeof(newValue)) === 'object') {
|
|
245
|
-
chirashi.forIn(newValue, _defineReactive.bind(null, watchers, watchKey + '.', output[key]));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
chirashi.forIn(watchers[watchKey], function (key, options) {
|
|
249
|
-
return options.afterChange();
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
if (value instanceof Array) {
|
|
253
|
-
chirashi.forEach(_arrayChangingMethods, function (method) {
|
|
254
|
-
value[method] = function () {
|
|
255
|
-
chirashi.forIn(watchers[watchKey], function (key, options) {
|
|
256
|
-
if (options.deep) options.beforeChange();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
var ret = Array.prototype[method].apply(this, arguments);
|
|
260
|
-
|
|
261
|
-
chirashi.forIn(watchers[watchKey], function (key, options) {
|
|
262
|
-
if (options.deep) options.afterChange();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
return ret;
|
|
266
|
-
};
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
output[key] = value;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var Mixins = Object.freeze({
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
function lifeCycleMerger(base, mixin) {
|
|
282
|
-
if (!base) return mixin;
|
|
283
|
-
|
|
284
|
-
if (!(base instanceof Array)) base = [base];
|
|
285
|
-
if (!(mixin instanceof Array)) mixin = [mixin];
|
|
286
|
-
|
|
287
|
-
return [].concat(toConsumableArray(base), toConsumableArray(mixin));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
var merger = {
|
|
291
|
-
mounted: lifeCycleMerger,
|
|
292
|
-
beforeDestroy: lifeCycleMerger,
|
|
293
|
-
default: function _default(base, mixin) {
|
|
294
|
-
if ((typeof base === 'undefined' ? 'undefined' : _typeof(base)) === 'object' && (typeof mixin === 'undefined' ? 'undefined' : _typeof(mixin)) === 'object') {
|
|
295
|
-
return _extends({}, mixin, base);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return base || mixin;
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
mixins: function mixins(base) {
|
|
302
|
-
return base;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
function _mergeOptions(base, mixin) {
|
|
307
|
-
chirashi.forIn(mixin, function (key, value) {
|
|
308
|
-
if (key in merger) {
|
|
309
|
-
base[key] = merger[key](base[key], value);
|
|
310
|
-
} else {
|
|
311
|
-
base[key] = merger.default(base[key], value);
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function _mergeMixins(options) {
|
|
317
|
-
var result = _extends({}, options);
|
|
318
|
-
|
|
319
|
-
chirashi.forEach(result.mixins, function (mixin, index) {
|
|
320
|
-
if (typeof mixin === 'string') {
|
|
321
|
-
mixin = Mixins[mixin];
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if ('mixins' in options) {
|
|
325
|
-
mixin = _mergeMixins(mixin);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
_mergeOptions(result, mixin);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
return result;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
var lifeCycle = ['mounted', 'beforeDestroy'];
|
|
335
|
-
|
|
336
|
-
var Component = function () {
|
|
337
|
-
function Component() {
|
|
338
|
-
var globals = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
339
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
340
|
-
classCallCheck(this, Component);
|
|
341
|
-
|
|
342
|
-
Object.assign(this, globals);
|
|
343
|
-
this.$options = options;
|
|
344
|
-
|
|
345
|
-
this.$id = this._generateId();
|
|
346
|
-
|
|
347
|
-
this.$options = _mergeMixins(this.$options);
|
|
348
|
-
|
|
349
|
-
this.$scope = {};
|
|
350
|
-
|
|
351
|
-
this._bindLifeCycle();
|
|
352
|
-
this._bindData();
|
|
353
|
-
this._bindMethods();
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
createClass(Component, [{
|
|
357
|
-
key: '_bindData',
|
|
358
|
-
value: function _bindData() {
|
|
359
|
-
var _this = this;
|
|
360
|
-
|
|
361
|
-
this.$data = {};
|
|
362
|
-
|
|
363
|
-
this._watchers = {};
|
|
364
|
-
chirashi.forIn(this.$options.data, function (key, value) {
|
|
365
|
-
_defineReactive(_this._watchers, '', _this.$data, key, value);
|
|
366
|
-
_copyAccessor(key, _this, _this.$data);
|
|
367
|
-
_copyAccessor(key, _this.$scope, _this.$data);
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}, {
|
|
371
|
-
key: '_bindMethods',
|
|
372
|
-
value: function _bindMethods() {
|
|
373
|
-
var _this2 = this;
|
|
374
|
-
|
|
375
|
-
this.$methods = {};
|
|
376
|
-
chirashi.forIn(this.$options.methods, function (name, callback) {
|
|
377
|
-
_this2.$methods[name] = callback.bind(_this2);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
Object.assign(this, this.$methods);
|
|
381
|
-
Object.assign(this.$scope, this.$methods);
|
|
382
|
-
}
|
|
383
|
-
}, {
|
|
384
|
-
key: '_generateId',
|
|
385
|
-
value: function _generateId() {
|
|
386
|
-
return lodash.uniqueId('' + this.$prefix + this.$options.name + '-');
|
|
387
|
-
}
|
|
388
|
-
}, {
|
|
389
|
-
key: '_bindLifeCycle',
|
|
390
|
-
value: function _bindLifeCycle() {
|
|
391
|
-
var _this3 = this;
|
|
392
|
-
|
|
393
|
-
chirashi.forEach(lifeCycle, function (method) {
|
|
394
|
-
_this3[method] = function () {
|
|
395
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
396
|
-
args[_key] = arguments[_key];
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
chirashi.forEach(_this3.$options[method], function (callback) {
|
|
400
|
-
return callback.apply(_this3, args);
|
|
401
|
-
});
|
|
402
|
-
};
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
}, {
|
|
406
|
-
key: '$watch',
|
|
407
|
-
value: function $watch(key, callback) {
|
|
408
|
-
var _this4 = this;
|
|
409
|
-
|
|
410
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { deep: false, immediate: false };
|
|
411
|
-
|
|
412
|
-
var watcherId = lodash.uniqueId(this.$id + '-' + key + '-');
|
|
413
|
-
|
|
414
|
-
if (typeof callback === 'string') callback = this.$scope[callback];
|
|
415
|
-
|
|
416
|
-
var oldValue = {
|
|
417
|
-
value: null
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
options.beforeChange = function () {
|
|
421
|
-
var old = get$1(_this4.$scope, key);
|
|
422
|
-
|
|
423
|
-
if (old instanceof Array) {
|
|
424
|
-
oldValue.value = [].concat(toConsumableArray(old));
|
|
425
|
-
} else if ((typeof old === 'undefined' ? 'undefined' : _typeof(old)) === 'object') {
|
|
426
|
-
oldValue.value = _extends({}, old);
|
|
427
|
-
} else {
|
|
428
|
-
oldValue.value = old;
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
options.afterChange = function () {
|
|
433
|
-
callback(get$1(_this4.$scope, key), oldValue.value);
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
if (key in this._watchers) {
|
|
437
|
-
this._watchers[key][watcherId] = options;
|
|
438
|
-
|
|
439
|
-
if (options.deep) {
|
|
440
|
-
var keyRoot = key + '.';
|
|
441
|
-
if (_typeof(get$1(this.$scope, key)) === 'object') {
|
|
442
|
-
chirashi.forIn(this._watchers, function (watchKey, watchers) {
|
|
443
|
-
if (watchKey.indexOf(keyRoot) === 0) {
|
|
444
|
-
_this4._watchers[watchKey][watcherId] = options;
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
if (options.immediate) {
|
|
452
|
-
options.afterChange();
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return function () {
|
|
456
|
-
if (options.deep) {
|
|
457
|
-
if (_typeof(get$1(_this4.$scope, key)) === 'object') {
|
|
458
|
-
chirashi.forIn(_this4._watchers, function (watchKey, watchers) {
|
|
459
|
-
delete _this4._watchers[watchKey][watcherId];
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
} else {
|
|
463
|
-
if (key in _this4._watchers) {
|
|
464
|
-
delete _this4._watchers[key][watcherId];
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
}, {
|
|
470
|
-
key: '$mount',
|
|
471
|
-
value: function $mount(el) {
|
|
472
|
-
this.$el = chirashi.getElement(el);
|
|
473
|
-
|
|
474
|
-
this.$el[this.$marker] = this.$id;
|
|
475
|
-
|
|
476
|
-
try {
|
|
477
|
-
this.mounted(el);
|
|
478
|
-
} catch (e) {
|
|
479
|
-
console.error(e);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}, {
|
|
483
|
-
key: '$destroy',
|
|
484
|
-
value: function $destroy() {
|
|
485
|
-
try {
|
|
486
|
-
this.beforeDestroy();
|
|
487
|
-
} catch (e) {
|
|
488
|
-
console.error(e);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}]);
|
|
492
|
-
return Component;
|
|
493
|
-
}();
|
|
494
|
-
|
|
495
|
-
var stringRegex = /([\w-_.\s]+)/g;
|
|
496
|
-
var quote = /["']/g;
|
|
497
|
-
|
|
498
|
-
function stringParser(input) {
|
|
499
|
-
var props = [];
|
|
500
|
-
var inquote = false;
|
|
501
|
-
var inobject = false;
|
|
502
|
-
var leftobject = false;
|
|
503
|
-
var nbQuotes = 0;
|
|
504
|
-
|
|
505
|
-
var segments = input.split(/\s/g);
|
|
506
|
-
chirashi.forEach(segments, function (segment, index) {
|
|
507
|
-
var quotes = segment.match(quote);
|
|
508
|
-
if (!inquote && quotes) {
|
|
509
|
-
inquote = true;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (!inobject && segment.indexOf('{') !== -1) {
|
|
513
|
-
inobject = true;
|
|
514
|
-
leftobject = true;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (inobject && segment.indexOf(',') === 0) {
|
|
518
|
-
leftobject = true;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
if (!inquote && !leftobject) {
|
|
522
|
-
var variable = segment.match(stringRegex);
|
|
523
|
-
|
|
524
|
-
if (variable) {
|
|
525
|
-
variable = variable[0];
|
|
526
|
-
|
|
527
|
-
if (isNaN(+variable)) {
|
|
528
|
-
props.push(variable);
|
|
529
|
-
segments[index] = segment.replace(variable, '$scope.' + variable);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
if (quotes) nbQuotes += quotes.length;
|
|
535
|
-
if (quotes && nbQuotes % 2 === 0) {
|
|
536
|
-
inquote = false;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
if (inobject && segment.indexOf(':') !== -1) {
|
|
540
|
-
leftobject = false;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
if (inobject && segment.indexOf(',') !== -1) {
|
|
544
|
-
leftobject = true;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (inobject && segment.indexOf('}') !== -1) {
|
|
548
|
-
inobject = false;
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
return { template: segments.join(' '), props: props };
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
var lifeCycle$1 = ['bind', 'update', 'unbind'];
|
|
556
|
-
|
|
557
|
-
var Directive = function () {
|
|
558
|
-
function Directive() {
|
|
559
|
-
var globals = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
560
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
561
|
-
classCallCheck(this, Directive);
|
|
562
|
-
|
|
563
|
-
Object.assign(this, globals);
|
|
564
|
-
this.$options = options;
|
|
565
|
-
|
|
566
|
-
this.$update = this.$update.bind(this);
|
|
567
|
-
|
|
568
|
-
this.$id = this._generateId();
|
|
569
|
-
|
|
570
|
-
this._bindLifeCycle();
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
createClass(Directive, [{
|
|
574
|
-
key: '_generateId',
|
|
575
|
-
value: function _generateId() {
|
|
576
|
-
return lodash.uniqueId('' + this.$prefix + this.$options.name + '-');
|
|
577
|
-
}
|
|
578
|
-
}, {
|
|
579
|
-
key: '_bindLifeCycle',
|
|
580
|
-
value: function _bindLifeCycle() {
|
|
581
|
-
var _this = this;
|
|
582
|
-
|
|
583
|
-
chirashi.forEach(lifeCycle$1, function (method) {
|
|
584
|
-
_this[method] = function () {
|
|
585
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
586
|
-
args[_key] = arguments[_key];
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
chirashi.forEach(_this.$options[method], function (callback) {
|
|
590
|
-
return callback.apply(_this, args);
|
|
591
|
-
});
|
|
592
|
-
};
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
}, {
|
|
596
|
-
key: '_eval',
|
|
597
|
-
value: function _eval(string) {
|
|
598
|
-
return (0, eval)('(function ($scope) { return ' + string + '; })')(this.$scope);
|
|
599
|
-
}
|
|
600
|
-
}, {
|
|
601
|
-
key: '$bind',
|
|
602
|
-
value: function $bind(el, option) {
|
|
603
|
-
var _this2 = this;
|
|
604
|
-
|
|
605
|
-
this.$el = chirashi.getElement(el);
|
|
606
|
-
|
|
607
|
-
this.$option = stringParser(option);
|
|
608
|
-
|
|
609
|
-
var closests = [this.$el].concat(toConsumableArray(chirashi.parents(this.$el)));
|
|
610
|
-
var parent = void 0;
|
|
611
|
-
var i = 0;
|
|
612
|
-
while ((parent = closests[i++]) && !(this.$marker in parent)) {}
|
|
613
|
-
|
|
614
|
-
this.$component = this.$components[parent[this.$marker]];
|
|
615
|
-
|
|
616
|
-
if (this.bind) {
|
|
617
|
-
try {
|
|
618
|
-
this.bind(el);
|
|
619
|
-
} catch (e) {
|
|
620
|
-
console.error(e);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
this.unwatchers = [];
|
|
625
|
-
if (this.$option.props.length) {
|
|
626
|
-
chirashi.forEach(this.$option.props, function (prop) {
|
|
627
|
-
_this2.unwatchers.push(_this2.$component.$watch(prop, _this2.$update, { immediate: true }));
|
|
628
|
-
});
|
|
629
|
-
} else {
|
|
630
|
-
this.$update();
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}, {
|
|
634
|
-
key: '$update',
|
|
635
|
-
value: function $update() {
|
|
636
|
-
if (this.update) {
|
|
637
|
-
try {
|
|
638
|
-
this.update(this._eval(this.$option.template));
|
|
639
|
-
} catch (e) {
|
|
640
|
-
console.error(e);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}, {
|
|
645
|
-
key: '$unbind',
|
|
646
|
-
value: function $unbind() {
|
|
647
|
-
chirashi.forEach(this.unwatchers, function (unwatch) {
|
|
648
|
-
unwatch();
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
if (this.unbind) {
|
|
652
|
-
try {
|
|
653
|
-
this.unbind();
|
|
654
|
-
} catch (e) {
|
|
655
|
-
console.error(e);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}, {
|
|
660
|
-
key: '$scope',
|
|
661
|
-
get: function get$$1() {
|
|
662
|
-
return this.$component.$scope;
|
|
663
|
-
}
|
|
664
|
-
}]);
|
|
665
|
-
return Directive;
|
|
666
|
-
}();
|
|
667
|
-
|
|
668
|
-
var Class = {
|
|
669
|
-
bind: function bind() {
|
|
670
|
-
this.currentClasses = [];
|
|
671
|
-
},
|
|
672
|
-
update: function update(value) {
|
|
673
|
-
var newClasses = void 0;
|
|
674
|
-
|
|
675
|
-
if (typeof value === 'string') {
|
|
676
|
-
newClasses = [value];
|
|
677
|
-
} else if ('length' in value) {
|
|
678
|
-
newClasses = value;
|
|
679
|
-
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
|
|
680
|
-
newClasses = Object.keys(value).filter(function (className) {
|
|
681
|
-
return value[className];
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
var removeClasses = this.currentClasses.filter(function (className) {
|
|
686
|
-
return newClasses.indexOf(className) === -1;
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
if (newClasses.length) chirashi.addClass.apply(undefined, [this.$el].concat(toConsumableArray(newClasses)));
|
|
690
|
-
if (removeClasses.length) chirashi.removeClass.apply(undefined, [this.$el].concat(toConsumableArray(removeClasses)));
|
|
691
|
-
|
|
692
|
-
this.currentClasses = newClasses;
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
var Html = {
|
|
697
|
-
update: function update(innerHTML) {
|
|
698
|
-
chirashi.setProp(this.$el, { innerHTML: innerHTML });
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
var set$1 = function (obj, key, value) {
|
|
703
|
-
var keys = key.split('.');
|
|
704
|
-
key = keys.pop();
|
|
705
|
-
var n = keys.length;
|
|
706
|
-
for (var i = 0; i < n; ++i) {
|
|
707
|
-
obj = obj[keys[i]];
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
return obj[key] = value;
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
var Model = {
|
|
714
|
-
bind: function bind(el) {
|
|
715
|
-
var _this = this;
|
|
716
|
-
|
|
717
|
-
this.type = chirashi.getProp(el, 'type');
|
|
718
|
-
|
|
719
|
-
this.inputChanged = function () {
|
|
720
|
-
var newValue = void 0;
|
|
721
|
-
switch (_this.type) {
|
|
722
|
-
case 'checkbox':
|
|
723
|
-
newValue = chirashi.getProp(_this.$el, 'checked');
|
|
724
|
-
break;
|
|
725
|
-
|
|
726
|
-
default:
|
|
727
|
-
newValue = chirashi.getProp(_this.$el, 'value');
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
if (newValue === _this.currentValue) return;
|
|
731
|
-
|
|
732
|
-
_this.currentValue = newValue;
|
|
733
|
-
|
|
734
|
-
set$1(_this.$scope, _this.model, _this.currentValue);
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
this.offObj = chirashi.on(el, {
|
|
738
|
-
'keyup blur change': this.inputChanged
|
|
739
|
-
});
|
|
740
|
-
},
|
|
741
|
-
update: function update(newValue) {
|
|
742
|
-
if (newValue === this.currentValue) return;
|
|
743
|
-
|
|
744
|
-
this.model = this.$option.props[0];
|
|
745
|
-
|
|
746
|
-
this.currentValue = newValue;
|
|
747
|
-
|
|
748
|
-
switch (this.type) {
|
|
749
|
-
case 'checkbox':
|
|
750
|
-
chirashi.setProp(this.$el, { checked: newValue });
|
|
751
|
-
break;
|
|
752
|
-
|
|
753
|
-
case 'radio':
|
|
754
|
-
var selector = this.$options.selector.slice(0, -1) + '="' + this.model + '"]';
|
|
755
|
-
chirashi.setProp(selector, { checked: false });
|
|
756
|
-
chirashi.setProp(selector + '[value="' + newValue + '"]', { checked: true });
|
|
757
|
-
break;
|
|
758
|
-
|
|
759
|
-
default:
|
|
760
|
-
chirashi.setProp(this.$el, { value: newValue });
|
|
761
|
-
}
|
|
762
|
-
},
|
|
763
|
-
unbind: function unbind() {
|
|
764
|
-
this.offObj.off();
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
|
|
768
|
-
var On = {
|
|
769
|
-
unbind: function unbind() {
|
|
770
|
-
if (this.off) this.off();
|
|
771
|
-
},
|
|
772
|
-
update: function update(options) {
|
|
773
|
-
if (this.off) this.off();
|
|
774
|
-
|
|
775
|
-
chirashi.on(this.$el, options);
|
|
776
|
-
}
|
|
777
|
-
};
|
|
778
|
-
|
|
779
|
-
var Show = {
|
|
780
|
-
update: function update(value) {
|
|
781
|
-
chirashi.setStyleProp(this.$el, {
|
|
782
|
-
display: value ? 'block' : 'none'
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
|
|
787
|
-
var Text = {
|
|
788
|
-
update: function update(textContent) {
|
|
789
|
-
chirashi.setProp(this.$el, { textContent: textContent });
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
var Directives = Object.freeze({
|
|
796
|
-
Class: Class,
|
|
797
|
-
Html: Html,
|
|
798
|
-
Model: Model,
|
|
799
|
-
On: On,
|
|
800
|
-
Show: Show,
|
|
801
|
-
Text: Text
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
var defaultsGlobals = {
|
|
805
|
-
$prefix: 'p-'
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
var defaults$$1 = {
|
|
809
|
-
name: 'root'
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
var Core = function (_Component) {
|
|
813
|
-
inherits(Core, _Component);
|
|
814
|
-
|
|
815
|
-
function Core() {
|
|
816
|
-
var globals = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
817
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
818
|
-
classCallCheck(this, Core);
|
|
819
|
-
|
|
820
|
-
globals = _extends({}, defaultsGlobals, globals);
|
|
821
|
-
options = _extends({}, defaults$$1, options);
|
|
822
|
-
|
|
823
|
-
var _this = possibleConstructorReturn(this, (Core.__proto__ || Object.getPrototypeOf(Core)).call(this, globals, options));
|
|
824
|
-
|
|
825
|
-
_this.$components = defineProperty({}, _this.$id, _this);
|
|
826
|
-
|
|
827
|
-
_this.$directives = {};
|
|
828
|
-
|
|
829
|
-
_this.$gobals = _extends({}, globals, options, {
|
|
830
|
-
$root: _this,
|
|
831
|
-
$components: _this.$components,
|
|
832
|
-
$directives: _this.$directives
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
_this.$gobals.$marker = _this.$marker = '_' + _this.$prefix + 'id';
|
|
836
|
-
_this.$directivesMarker = '_' + _this.$prefix + 'directives';
|
|
837
|
-
|
|
838
|
-
_this._components = [];
|
|
839
|
-
_this._directives = [];
|
|
840
|
-
|
|
841
|
-
chirashi.forIn(Directives, _this.directive.bind(_this));
|
|
842
|
-
return _this;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
createClass(Core, [{
|
|
846
|
-
key: 'component',
|
|
847
|
-
value: function component(name, options) {
|
|
848
|
-
name = lodash.kebabCase(name);
|
|
849
|
-
|
|
850
|
-
var selector = 'selector' in options ? options.selector : '[' + this.$prefix + name + ']';
|
|
851
|
-
|
|
852
|
-
this._components.push({
|
|
853
|
-
selector: selector,
|
|
854
|
-
options: _extends({
|
|
855
|
-
name: name,
|
|
856
|
-
selector: selector
|
|
857
|
-
}, options)
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
}, {
|
|
861
|
-
key: 'directive',
|
|
862
|
-
value: function directive(name, options) {
|
|
863
|
-
name = lodash.kebabCase(name);
|
|
864
|
-
|
|
865
|
-
var selector = 'selector' in options ? options.selector : '[' + this.$prefix + name + ']';
|
|
866
|
-
|
|
867
|
-
this._directives.push({
|
|
868
|
-
selector: selector,
|
|
869
|
-
options: _extends({
|
|
870
|
-
name: name,
|
|
871
|
-
selector: selector
|
|
872
|
-
}, options)
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
}, {
|
|
876
|
-
key: '$mount',
|
|
877
|
-
value: function $mount(selector) {
|
|
878
|
-
get(Core.prototype.__proto__ || Object.getPrototypeOf(Core.prototype), '$mount', this).call(this, selector);
|
|
879
|
-
|
|
880
|
-
this._observer = new Observer(this.$el);
|
|
881
|
-
this._observer.on(this._domChanged.bind(this));
|
|
882
|
-
|
|
883
|
-
this._domChanged();
|
|
884
|
-
}
|
|
885
|
-
}, {
|
|
886
|
-
key: '_domChanged',
|
|
887
|
-
value: function _domChanged() {
|
|
888
|
-
this._unbindComponents();
|
|
889
|
-
this._unbindDirectives();
|
|
890
|
-
this._bindComponents();
|
|
891
|
-
this._bindDirectives();
|
|
892
|
-
}
|
|
893
|
-
}, {
|
|
894
|
-
key: '_unbindComponents',
|
|
895
|
-
value: function _unbindComponents() {
|
|
896
|
-
var _this2 = this;
|
|
897
|
-
|
|
898
|
-
chirashi.forIn(this.$components, function (id, component) {
|
|
899
|
-
if (!chirashi.closest(component.$el, document.body)) {
|
|
900
|
-
component.$destroy();
|
|
901
|
-
delete _this2.$components[id];
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
}, {
|
|
906
|
-
key: '_bindComponents',
|
|
907
|
-
value: function _bindComponents() {
|
|
908
|
-
var _this3 = this;
|
|
909
|
-
|
|
910
|
-
chirashi.forEach(this._components, function (component) {
|
|
911
|
-
chirashi.forEach(chirashi.find(_this3.$el, component.selector), function (el) {
|
|
912
|
-
if (_this3.$marker in el) return;
|
|
913
|
-
|
|
914
|
-
var createdComponent = new Component(_this3.$gobals, component.options);
|
|
915
|
-
createdComponent.$mount(el);
|
|
916
|
-
_this3.$components[createdComponent.$id] = createdComponent;
|
|
917
|
-
});
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
}, {
|
|
921
|
-
key: '_unbindDirectives',
|
|
922
|
-
value: function _unbindDirectives() {
|
|
923
|
-
var _this4 = this;
|
|
924
|
-
|
|
925
|
-
chirashi.forIn(this.$directives, function (id, directive) {
|
|
926
|
-
if (!chirashi.closest(directive.$el, document.body)) {
|
|
927
|
-
directive.$unbind();
|
|
928
|
-
delete _this4.$directives[id];
|
|
929
|
-
}
|
|
930
|
-
});
|
|
931
|
-
}
|
|
932
|
-
}, {
|
|
933
|
-
key: '_bindDirectives',
|
|
934
|
-
value: function _bindDirectives() {
|
|
935
|
-
var _this5 = this;
|
|
936
|
-
|
|
937
|
-
chirashi.forEach(this._directives, function (directive) {
|
|
938
|
-
chirashi.forEach(chirashi.find(_this5.$el, directive.selector), function (el) {
|
|
939
|
-
if (!(_this5.$directivesMarker in el)) {
|
|
940
|
-
el[_this5.$directivesMarker] = [];
|
|
941
|
-
} else if (el[_this5.$directivesMarker].indexOf(directive.options.name) !== -1) {
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
el[_this5.$directivesMarker].push(directive.options.name);
|
|
946
|
-
|
|
947
|
-
var createdDirective = new Directive(_this5.$gobals, directive.options);
|
|
948
|
-
createdDirective.$bind(el, chirashi.getAttr(el, '' + _this5.$gobals.$prefix + directive.options.name));
|
|
949
|
-
_this5.$directives[createdDirective.$id] = createdDirective;
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
}]);
|
|
954
|
-
return Core;
|
|
955
|
-
}(Component);
|
|
956
|
-
|
|
957
|
-
var Poulet = Object.assign(Core, { get: get$1, set: set$1 });
|
|
958
|
-
|
|
959
|
-
module.exports = Poulet;
|