poulet 0.0.5 → 0.1.0
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 +270 -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 +66 -0
- package/dist/react.d.ts +66 -0
- package/dist/react.js +2 -0
- package/dist/react.js.map +1 -0
- package/package.json +51 -52
- package/LICENSE +0 -22
- package/dist/.gitkeep +0 -0
- package/dist/poulet.common.js +0 -929
- package/dist/poulet.js +0 -932
- package/dist/poulet.min.js +0 -7
- package/dist/poulet.mjs +0 -927
- 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 -131
- package/lib/Core/Directive/_stringParser.js +0 -61
- package/lib/Core/Directive/index.js +0 -75
- package/lib/Core/Observer.js +0 -26
- 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
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { forEach, forIn } from 'chirashi'
|
|
2
|
-
|
|
3
|
-
const _arrayChangingMethods = ['push', 'splice', 'unshift']
|
|
4
|
-
|
|
5
|
-
export default function _defineReactive (watchers, watchKey, output, key, value) {
|
|
6
|
-
watchKey += key
|
|
7
|
-
|
|
8
|
-
watchers[watchKey] = {}
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(output, key, {
|
|
11
|
-
get: () => {
|
|
12
|
-
return value
|
|
13
|
-
},
|
|
14
|
-
set: newValue => {
|
|
15
|
-
forIn(watchers[watchKey], (key, options) => options.beforeChange())
|
|
16
|
-
|
|
17
|
-
value = newValue
|
|
18
|
-
|
|
19
|
-
if (typeof newValue === 'object') {
|
|
20
|
-
forIn(newValue, _defineReactive.bind(null, watchers, `${watchKey}.`, output[key]))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
forIn(watchers[watchKey], (key, options) => options.afterChange())
|
|
24
|
-
|
|
25
|
-
if (value instanceof Array) {
|
|
26
|
-
forEach(_arrayChangingMethods, method => {
|
|
27
|
-
value[method] = function () {
|
|
28
|
-
forIn(watchers[watchKey], (key, options) => {
|
|
29
|
-
if (options.deep) options.beforeChange()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const ret = Array.prototype[method].apply(this, arguments)
|
|
33
|
-
|
|
34
|
-
forIn(watchers[watchKey], (key, options) => {
|
|
35
|
-
if (options.deep) options.afterChange()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return ret
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
output[key] = value
|
|
46
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { forEach, forIn } from 'chirashi'
|
|
2
|
-
|
|
3
|
-
import * as Mixins from '../../mixins'
|
|
4
|
-
|
|
5
|
-
function lifeCycleMerger (base, mixin) {
|
|
6
|
-
if (!base) return mixin
|
|
7
|
-
|
|
8
|
-
if (!(base instanceof Array)) base = [base]
|
|
9
|
-
if (!(mixin instanceof Array)) mixin = [mixin]
|
|
10
|
-
|
|
11
|
-
return [...base, ...mixin]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const merger = {
|
|
15
|
-
mounted: lifeCycleMerger,
|
|
16
|
-
beforeDestroy: lifeCycleMerger,
|
|
17
|
-
default (base, mixin) {
|
|
18
|
-
if (typeof base === 'object' && typeof mixin === 'object') {
|
|
19
|
-
return {...mixin, ...base}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return base || mixin
|
|
23
|
-
},
|
|
24
|
-
mixins: base => base
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function _mergeOptions (base, mixin) {
|
|
28
|
-
forIn(mixin, (key, value) => {
|
|
29
|
-
if (key in merger) {
|
|
30
|
-
base[key] = merger[key](base[key], value)
|
|
31
|
-
} else {
|
|
32
|
-
base[key] = merger.default(base[key], value)
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default function _mergeMixins (options) {
|
|
38
|
-
const result = {...options}
|
|
39
|
-
|
|
40
|
-
forEach(result.mixins, (mixin, index) => {
|
|
41
|
-
if (typeof mixin === 'string') {
|
|
42
|
-
mixin = Mixins[mixin]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if ('mixins' in options) {
|
|
46
|
-
mixin = _mergeMixins(mixin)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_mergeOptions(result, mixin)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return result
|
|
53
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { forIn, forEach, getElement } from 'chirashi'
|
|
2
|
-
import { uniqueId } from 'lodash'
|
|
3
|
-
|
|
4
|
-
import get from '../../get'
|
|
5
|
-
|
|
6
|
-
import _copyAccessor from './_copyAccessor'
|
|
7
|
-
import _defineReactive from './_defineReactive'
|
|
8
|
-
import _mergeMixins from './_mergeMixins'
|
|
9
|
-
|
|
10
|
-
const lifeCycle = ['mounted', 'beforeDestroy']
|
|
11
|
-
|
|
12
|
-
export default class Component {
|
|
13
|
-
constructor (globals = {}, options = {}) {
|
|
14
|
-
Object.assign(this, globals)
|
|
15
|
-
this.$options = options
|
|
16
|
-
|
|
17
|
-
this.$id = this._generateId()
|
|
18
|
-
|
|
19
|
-
this.$options = _mergeMixins(this.$options)
|
|
20
|
-
|
|
21
|
-
this.$scope = {}
|
|
22
|
-
|
|
23
|
-
this._bindLifeCycle()
|
|
24
|
-
this._bindData()
|
|
25
|
-
this._bindMethods()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_bindData () {
|
|
29
|
-
this.$data = {}
|
|
30
|
-
|
|
31
|
-
this._watchers = {}
|
|
32
|
-
forIn(this.$options.data, (key, value) => {
|
|
33
|
-
_defineReactive(this._watchers, '', this.$data, key, value)
|
|
34
|
-
_copyAccessor(key, this, this.$data)
|
|
35
|
-
_copyAccessor(key, this.$scope, this.$data)
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_bindMethods () {
|
|
40
|
-
this.$methods = {}
|
|
41
|
-
forIn(this.$options.methods, (name, callback) => {
|
|
42
|
-
this.$methods[name] = callback.bind(this)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
Object.assign(this, this.$methods)
|
|
46
|
-
Object.assign(this.$scope, this.$methods)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_generateId () {
|
|
50
|
-
return uniqueId(`${this.$prefix}${this.$options.name}-`)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_bindLifeCycle () {
|
|
54
|
-
forEach(lifeCycle, method => {
|
|
55
|
-
this[method] = (...args) => {
|
|
56
|
-
forEach(this.$options[method], callback => callback.apply(this, args))
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
$watch (key, callback, options = { deep: false, immediate: false }) {
|
|
62
|
-
const watcherId = uniqueId(this.$id + '-' + key + '-')
|
|
63
|
-
|
|
64
|
-
if (typeof callback === 'string') callback = this.$scope[callback]
|
|
65
|
-
|
|
66
|
-
const oldValue = {
|
|
67
|
-
value: null
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
options.beforeChange = () => {
|
|
71
|
-
const old = get(this.$scope, key)
|
|
72
|
-
|
|
73
|
-
if (old instanceof Array) {
|
|
74
|
-
oldValue.value = [...old]
|
|
75
|
-
} else if (typeof old === 'object') {
|
|
76
|
-
oldValue.value = {...old}
|
|
77
|
-
} else {
|
|
78
|
-
oldValue.value = old
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
options.afterChange = () => {
|
|
83
|
-
callback(get(this.$scope, key), oldValue.value)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (key in this._watchers) {
|
|
87
|
-
this._watchers[key][watcherId] = options
|
|
88
|
-
|
|
89
|
-
if (options.deep) {
|
|
90
|
-
const keyRoot = key + '.'
|
|
91
|
-
if (typeof get(this.$scope, key) === 'object') {
|
|
92
|
-
forIn(this._watchers, (watchKey, watchers) => {
|
|
93
|
-
if (watchKey.indexOf(keyRoot) === 0) {
|
|
94
|
-
this._watchers[watchKey][watcherId] = options
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (options.immediate) {
|
|
102
|
-
options.afterChange()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return () => {
|
|
106
|
-
if (options.deep) {
|
|
107
|
-
if (typeof get(this.$scope, key) === 'object') {
|
|
108
|
-
forIn(this._watchers, (watchKey, watchers) => {
|
|
109
|
-
delete this._watchers[watchKey][watcherId]
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
if (key in this._watchers) {
|
|
114
|
-
delete this._watchers[key][watcherId]
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
$mount (el) {
|
|
121
|
-
this.$el = getElement(el)
|
|
122
|
-
|
|
123
|
-
this.$el[this.$marker] = this.$id
|
|
124
|
-
|
|
125
|
-
this.mounted(el)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
$destroy () {
|
|
129
|
-
this.beforeDestroy()
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { forEach } from 'chirashi'
|
|
2
|
-
|
|
3
|
-
const stringRegex = /([\w-_.\s]+)/g
|
|
4
|
-
const quote = /["']/g
|
|
5
|
-
|
|
6
|
-
export default function stringParser (input) {
|
|
7
|
-
const props = []
|
|
8
|
-
let inquote = false
|
|
9
|
-
let inobject = false
|
|
10
|
-
let leftobject = false
|
|
11
|
-
let nbQuotes = 0
|
|
12
|
-
|
|
13
|
-
const segments = input.split(/\s/g)
|
|
14
|
-
forEach(segments, (segment, index) => {
|
|
15
|
-
const quotes = segment.match(quote)
|
|
16
|
-
if (!inquote && quotes) {
|
|
17
|
-
inquote = true
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!inobject && segment.indexOf('{') !== -1) {
|
|
21
|
-
inobject = true
|
|
22
|
-
leftobject = true
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (inobject && segment.indexOf(',') === 0) {
|
|
26
|
-
leftobject = true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!inquote && !leftobject) {
|
|
30
|
-
let variable = segment.match(stringRegex)
|
|
31
|
-
|
|
32
|
-
if (variable) {
|
|
33
|
-
variable = variable[0]
|
|
34
|
-
|
|
35
|
-
if (isNaN(+variable)) {
|
|
36
|
-
props.push(variable)
|
|
37
|
-
segments[index] = segment.replace(variable, `$scope.${variable}`)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (quotes) nbQuotes += quotes.length
|
|
43
|
-
if (quotes && nbQuotes % 2 === 0) {
|
|
44
|
-
inquote = false
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (inobject && segment.indexOf(':') !== -1) {
|
|
48
|
-
leftobject = false
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (inobject && segment.indexOf(',') !== -1) {
|
|
52
|
-
leftobject = true
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (inobject && segment.indexOf('}') !== -1) {
|
|
56
|
-
inobject = false
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
return { template: segments.join(' '), props }
|
|
61
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { forEach, getElement, parents } from 'chirashi'
|
|
2
|
-
import { uniqueId } from 'lodash'
|
|
3
|
-
|
|
4
|
-
import _stringParser from './_stringParser'
|
|
5
|
-
|
|
6
|
-
const lifeCycle = ['bind', 'update', 'unbind']
|
|
7
|
-
|
|
8
|
-
export default class Directive {
|
|
9
|
-
constructor (globals = {}, options = {}) {
|
|
10
|
-
Object.assign(this, globals)
|
|
11
|
-
this.$options = options
|
|
12
|
-
|
|
13
|
-
this.$update = this.$update.bind(this)
|
|
14
|
-
|
|
15
|
-
this.$id = this._generateId()
|
|
16
|
-
|
|
17
|
-
this._bindLifeCycle()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_generateId () {
|
|
21
|
-
return uniqueId(`${this.$prefix}${this.$options.name}-`)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
_bindLifeCycle () {
|
|
25
|
-
forEach(lifeCycle, method => {
|
|
26
|
-
this[method] = (...args) => {
|
|
27
|
-
forEach(this.$options[method], callback => callback.apply(this, args))
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_eval (string) {
|
|
33
|
-
return (0, eval)(`(function ($scope) { return ${string}; })`)(this.$scope)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
$bind (el, option) {
|
|
37
|
-
this.$el = getElement(el)
|
|
38
|
-
|
|
39
|
-
this.$option = _stringParser(option)
|
|
40
|
-
|
|
41
|
-
const closests = [this.$el, ...parents(this.$el)]
|
|
42
|
-
let parent
|
|
43
|
-
let i = 0
|
|
44
|
-
while ((parent = closests[i++]) && !(this.$marker in parent)) {}
|
|
45
|
-
|
|
46
|
-
this.$component = this.$components[parent[this.$marker]]
|
|
47
|
-
|
|
48
|
-
if (this.bind) this.bind(el)
|
|
49
|
-
|
|
50
|
-
this.unwatchers = []
|
|
51
|
-
if (this.$option.props.length) {
|
|
52
|
-
forEach(this.$option.props, prop => {
|
|
53
|
-
this.unwatchers.push(this.$component.$watch(prop, this.$update, { immediate: true }))
|
|
54
|
-
})
|
|
55
|
-
} else {
|
|
56
|
-
this.$update()
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
$update () {
|
|
61
|
-
if (this.update) this.update(this._eval(this.$option.template))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
$unbind () {
|
|
65
|
-
forEach(this.unwatchers, unwatch => {
|
|
66
|
-
unwatch()
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if (this.unbind) this.unbind()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get $scope () {
|
|
73
|
-
return this.$component.$scope
|
|
74
|
-
}
|
|
75
|
-
}
|
package/lib/Core/Observer.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { forEach } from 'chirashi'
|
|
2
|
-
|
|
3
|
-
export default class Observer {
|
|
4
|
-
constructor (domElement) {
|
|
5
|
-
this._observer = new MutationObserver(this._update.bind(this))
|
|
6
|
-
|
|
7
|
-
this._observer.observe(domElement, {
|
|
8
|
-
childList: true,
|
|
9
|
-
subtree: true
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
this._listeners = []
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
on (callback) {
|
|
16
|
-
this._listeners.push(callback)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
off (callback) {
|
|
20
|
-
this._listeners.splice(this._listeners.indexOf(callback), 1)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
_update () {
|
|
24
|
-
forEach(this._listeners, listener => listener())
|
|
25
|
-
}
|
|
26
|
-
}
|
package/lib/Core/index.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { kebabCase } from 'lodash'
|
|
2
|
-
import { forEach, forIn, getAttr, closest, find } from 'chirashi'
|
|
3
|
-
|
|
4
|
-
import Observer from './Observer'
|
|
5
|
-
import Component from './Component'
|
|
6
|
-
import Directive from './Directive'
|
|
7
|
-
import * as Directives from '../Directives'
|
|
8
|
-
|
|
9
|
-
const defaultsGlobals = {
|
|
10
|
-
$prefix: 'p-'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const defaults = {
|
|
14
|
-
name: 'root'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default class Core extends Component {
|
|
18
|
-
constructor (globals = {}, options = {}) {
|
|
19
|
-
globals = {...defaultsGlobals, ...globals}
|
|
20
|
-
options = {...defaults, ...options}
|
|
21
|
-
|
|
22
|
-
super(globals, options)
|
|
23
|
-
|
|
24
|
-
this.$components = {
|
|
25
|
-
[this.$id]: this
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
this.$directives = {}
|
|
29
|
-
|
|
30
|
-
this.$gobals = {
|
|
31
|
-
...globals,
|
|
32
|
-
...options,
|
|
33
|
-
$root: this,
|
|
34
|
-
$components: this.$components,
|
|
35
|
-
$directives: this.$directives
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.$gobals.$marker = this.$marker = `_${this.$prefix}id`
|
|
39
|
-
this.$directivesMarker = `_${this.$prefix}directives`
|
|
40
|
-
|
|
41
|
-
this._components = []
|
|
42
|
-
this._directives = []
|
|
43
|
-
|
|
44
|
-
forIn(Directives, this.directive.bind(this))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
component (name, options) {
|
|
48
|
-
name = kebabCase(name)
|
|
49
|
-
|
|
50
|
-
const selector = 'selector' in options ? options.selector : `[${this.$prefix}${name}]`
|
|
51
|
-
|
|
52
|
-
this._components.push({
|
|
53
|
-
selector,
|
|
54
|
-
options: {
|
|
55
|
-
name,
|
|
56
|
-
selector,
|
|
57
|
-
...options
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
directive (name, options) {
|
|
63
|
-
name = kebabCase(name)
|
|
64
|
-
|
|
65
|
-
const selector = 'selector' in options ? options.selector : `[${this.$prefix}${name}]`
|
|
66
|
-
|
|
67
|
-
this._directives.push({
|
|
68
|
-
selector,
|
|
69
|
-
options: {
|
|
70
|
-
name,
|
|
71
|
-
selector,
|
|
72
|
-
...options
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
$mount (selector) {
|
|
78
|
-
super.$mount(selector)
|
|
79
|
-
|
|
80
|
-
this._observer = new Observer(this.$el)
|
|
81
|
-
this._observer.on(this._domChanged.bind(this))
|
|
82
|
-
|
|
83
|
-
this._domChanged()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_domChanged () {
|
|
87
|
-
this._unbindComponents()
|
|
88
|
-
this._unbindDirectives()
|
|
89
|
-
this._bindComponents()
|
|
90
|
-
this._bindDirectives()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_unbindComponents () {
|
|
94
|
-
forIn(this.$components, (id, component) => {
|
|
95
|
-
if (!closest(component.$el, document.body)) {
|
|
96
|
-
component.$destroy()
|
|
97
|
-
delete this.$components[id]
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
_bindComponents () {
|
|
103
|
-
forEach(this._components, component => {
|
|
104
|
-
forEach(find(this.$el, component.selector), el => {
|
|
105
|
-
if (this.$marker in el) return
|
|
106
|
-
|
|
107
|
-
const createdComponent = new Component(this.$gobals, component.options)
|
|
108
|
-
createdComponent.$mount(el)
|
|
109
|
-
this.$components[createdComponent.$id] = createdComponent
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
_unbindDirectives () {
|
|
115
|
-
forIn(this.$directives, (id, directive) => {
|
|
116
|
-
if (!closest(directive.$el, document.body)) {
|
|
117
|
-
directive.$unbind()
|
|
118
|
-
delete this.$directives[id]
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
_bindDirectives () {
|
|
124
|
-
forEach(this._directives, directive => {
|
|
125
|
-
forEach(find(this.$el, directive.selector), el => {
|
|
126
|
-
if (!(this.$directivesMarker in el)) {
|
|
127
|
-
el[this.$directivesMarker] = []
|
|
128
|
-
} else if (el[this.$directivesMarker].indexOf(directive.options.name) !== -1) {
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
el[this.$directivesMarker].push(directive.options.name)
|
|
133
|
-
|
|
134
|
-
const createdDirective = new Directive(this.$gobals, directive.options)
|
|
135
|
-
createdDirective.$bind(el, getAttr(el, `${this.$gobals.$prefix}${directive.options.name}`))
|
|
136
|
-
this.$directives[createdDirective.$id] = createdDirective
|
|
137
|
-
})
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
}
|
package/lib/Directives/Class.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { addClass, removeClass } from 'chirashi'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
bind () {
|
|
5
|
-
this.currentClasses = []
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
update (value) {
|
|
9
|
-
let newClasses
|
|
10
|
-
|
|
11
|
-
if (typeof value === 'string') {
|
|
12
|
-
newClasses = [value]
|
|
13
|
-
} else if ('length' in value) {
|
|
14
|
-
newClasses = value
|
|
15
|
-
} else if (typeof value === 'object') {
|
|
16
|
-
newClasses = Object.keys(value).filter(className => value[className])
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const removeClasses = this.currentClasses.filter(className => newClasses.indexOf(className) === -1)
|
|
20
|
-
|
|
21
|
-
if (newClasses.length) addClass(this.$el, ...newClasses)
|
|
22
|
-
if (removeClasses.length) removeClass(this.$el, ...removeClasses)
|
|
23
|
-
|
|
24
|
-
this.currentClasses = newClasses
|
|
25
|
-
}
|
|
26
|
-
}
|
package/lib/Directives/Html.js
DELETED
package/lib/Directives/Model.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { on, getProp, setProp } from 'chirashi'
|
|
2
|
-
import set from '../set'
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
bind (el) {
|
|
6
|
-
this.type = getProp(el, 'type')
|
|
7
|
-
|
|
8
|
-
this.inputChanged = () => {
|
|
9
|
-
let newValue
|
|
10
|
-
switch (this.type) {
|
|
11
|
-
case 'checkbox':
|
|
12
|
-
newValue = getProp(this.$el, 'checked')
|
|
13
|
-
break
|
|
14
|
-
|
|
15
|
-
default:
|
|
16
|
-
newValue = getProp(this.$el, 'value')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (newValue === this.currentValue) return
|
|
20
|
-
|
|
21
|
-
this.currentValue = newValue
|
|
22
|
-
|
|
23
|
-
set(this.$scope, this.model, this.currentValue)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this.offObj = on(el, {
|
|
27
|
-
'keyup blur change': this.inputChanged
|
|
28
|
-
})
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
update (newValue) {
|
|
32
|
-
if (newValue === this.currentValue) return
|
|
33
|
-
|
|
34
|
-
this.model = this.$option.props[0]
|
|
35
|
-
|
|
36
|
-
this.currentValue = newValue
|
|
37
|
-
|
|
38
|
-
switch (this.type) {
|
|
39
|
-
case 'checkbox':
|
|
40
|
-
setProp(this.$el, { checked: newValue })
|
|
41
|
-
break
|
|
42
|
-
|
|
43
|
-
case 'radio':
|
|
44
|
-
const selector = `${this.$options.selector.slice(0, -1)}="${this.model}"]`
|
|
45
|
-
setProp(selector, { checked: false })
|
|
46
|
-
setProp(`${selector}[value="${newValue}"]`, { checked: true })
|
|
47
|
-
break
|
|
48
|
-
|
|
49
|
-
default:
|
|
50
|
-
setProp(this.$el, { value: newValue })
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
unbind () {
|
|
55
|
-
this.offObj.off()
|
|
56
|
-
}
|
|
57
|
-
}
|
package/lib/Directives/On.js
DELETED
package/lib/Directives/Show.js
DELETED
package/lib/Directives/Style.js
DELETED
package/lib/Directives/Text.js
DELETED
package/lib/Directives/index.js
DELETED
package/lib/Mixins/index.js
DELETED
|
File without changes
|
package/lib/get.js
DELETED