simplyview 2.1.0 → 3.0.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/dist/simply.app.js +1120 -0
- package/dist/simply.app.js.map +7 -0
- package/dist/simply.app.min.js +2 -0
- package/dist/simply.app.min.js.map +7 -0
- package/dist/simply.everything.js +1583 -2025
- package/dist/simply.everything.js.map +7 -0
- package/dist/simply.everything.min.js +2 -0
- package/dist/simply.everything.min.js.map +7 -0
- package/package.json +8 -3
- package/src/action.mjs +12 -0
- package/src/activate.mjs +63 -0
- package/src/app.mjs +40 -0
- package/src/bind.mjs +572 -0
- package/src/command.mjs +125 -0
- package/src/everything.mjs +27 -0
- package/src/include.mjs +191 -0
- package/src/key.mjs +55 -0
- package/src/model.mjs +151 -0
- package/src/route.mjs +222 -0
- package/src/state.mjs +536 -0
- package/js/.eslintrc.json +0 -29
- package/js/simply.action.js +0 -115
- package/js/simply.activate.js +0 -79
- package/js/simply.api.js +0 -228
- package/js/simply.app.js +0 -63
- package/js/simply.collect.js +0 -72
- package/js/simply.command.js +0 -196
- package/js/simply.include.js +0 -226
- package/js/simply.keyboard.js +0 -62
- package/js/simply.modules.js +0 -22
- package/js/simply.observe.js +0 -349
- package/js/simply.path.js +0 -48
- package/js/simply.render.js +0 -125
- package/js/simply.resize.js +0 -80
- package/js/simply.route.js +0 -234
- package/js/simply.view.js +0 -35
- package/js/simply.viewmodel.js +0 -189
- /package/{js/simply.include.next.js → src/include.next.js} +0 -0
package/js/simply.viewmodel.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
function etag() {
|
|
5
|
-
let d = '';
|
|
6
|
-
while (d.length < 32) d += Math.random().toString(16).substr(2);
|
|
7
|
-
const vr = ((parseInt(d.substr(16, 1), 16) & 0x3) | 0x8).toString(16);
|
|
8
|
-
return `${d.substr(0, 8)}-${d.substr(8, 4)}-4${d.substr(13, 3)}-${vr}${d.substr(17, 3)}-${d.substr(20, 12)}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function ViewModel(name, data, options) {
|
|
12
|
-
this.name = name;
|
|
13
|
-
this.data = data || [];
|
|
14
|
-
this.data.etag = etag();
|
|
15
|
-
this.view = {
|
|
16
|
-
options: {},
|
|
17
|
-
data: [] //Array.from(this.data).slice()
|
|
18
|
-
};
|
|
19
|
-
this.options = options || {};
|
|
20
|
-
this.plugins = {
|
|
21
|
-
start: [],
|
|
22
|
-
select: [],
|
|
23
|
-
order: [],
|
|
24
|
-
render: [],
|
|
25
|
-
finish: []
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
ViewModel.prototype.update = function(params) {
|
|
30
|
-
if (!params) {
|
|
31
|
-
params = {};
|
|
32
|
-
}
|
|
33
|
-
if (params.data) {
|
|
34
|
-
// this.data is a reference to the data passed, so that any changes in it will get applied
|
|
35
|
-
// to the original
|
|
36
|
-
this.data = params.data;
|
|
37
|
-
this.data.etag = etag()
|
|
38
|
-
}
|
|
39
|
-
// the view is a shallow copy of the array, so that changes in sort order and filtering
|
|
40
|
-
// won't get applied to the original, but databindings on its children will still work
|
|
41
|
-
this.view.data = Array.from(this.data).slice();
|
|
42
|
-
this.view.data.etag = this.data.etag;
|
|
43
|
-
let data = this.view.data;
|
|
44
|
-
let plugins = this.plugins.start.concat(this.plugins.select, this.plugins.order, this.plugins.render, this.plugins.finish);
|
|
45
|
-
plugins.forEach(plugin => {
|
|
46
|
-
data = plugin.call(this, params, data);
|
|
47
|
-
if (!data) {
|
|
48
|
-
data = this.view.data;
|
|
49
|
-
}
|
|
50
|
-
this.view.data = data
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (global.editor) {
|
|
54
|
-
global.editor.addDataSource(this.name,{
|
|
55
|
-
load: function(el, callback) {
|
|
56
|
-
callback(self.view.data);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
updateDataSource(this.name);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
ViewModel.prototype.addPlugin = function(pipe, plugin) {
|
|
64
|
-
if (typeof this.plugins[pipe] == 'undefined') {
|
|
65
|
-
throw new Error('Unknown pipeline '+pipe);
|
|
66
|
-
}
|
|
67
|
-
this.plugins[pipe].push(plugin);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
ViewModel.prototype.removePlugin = function(pipe, plugin) {
|
|
71
|
-
if (typeof this.plugins[pipe] == 'undefined') {
|
|
72
|
-
throw new Error('Unknown pipeline '+pipe);
|
|
73
|
-
}
|
|
74
|
-
this.plugins[pipe] = this.plugins[pipe].filter(function(p) {
|
|
75
|
-
return p != plugin;
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
var updateDataSource = function(name) {
|
|
80
|
-
global.document.querySelectorAll('[data-simply-data="'+name+'"]').forEach(function(list) {
|
|
81
|
-
global.editor.list.applyDataSource(list, name);
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var createSort = function(options) {
|
|
86
|
-
var defaultOptions = {
|
|
87
|
-
name: 'sort',
|
|
88
|
-
getSort: function(params) {
|
|
89
|
-
return Array.prototype.sort;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
options = Object.assign(defaultOptions, options || {});
|
|
93
|
-
|
|
94
|
-
return function(params) {
|
|
95
|
-
this.options[options.name] = options;
|
|
96
|
-
if (params[options.name]) {
|
|
97
|
-
options = Object.assign(options, params[options.name]);
|
|
98
|
-
}
|
|
99
|
-
this.view.data.sort(options.getSort.call(this, options));
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
var createPaging = function(options) {
|
|
104
|
-
var defaultOptions = {
|
|
105
|
-
name: 'paging',
|
|
106
|
-
page: 1,
|
|
107
|
-
pageSize: 100,
|
|
108
|
-
max: 1,
|
|
109
|
-
prev: 0,
|
|
110
|
-
next: 0
|
|
111
|
-
};
|
|
112
|
-
options = Object.assign(defaultOptions, options || {});
|
|
113
|
-
|
|
114
|
-
return function(params) {
|
|
115
|
-
this.options[options.name] = options;
|
|
116
|
-
if (this.view.data) {
|
|
117
|
-
options.max = Math.max(1, Math.ceil(Array.from(this.view.data).length / options.pageSize));
|
|
118
|
-
} else {
|
|
119
|
-
options.max = 1;
|
|
120
|
-
}
|
|
121
|
-
if (this.view.changed) {
|
|
122
|
-
options.page = 1; // reset to page 1 when something in the view data has changed
|
|
123
|
-
}
|
|
124
|
-
if (params[options.name]) {
|
|
125
|
-
options = Object.assign(options, params[options.name]);
|
|
126
|
-
}
|
|
127
|
-
options.page = Math.max(1, Math.min(options.max, options.page)); // clamp page nr
|
|
128
|
-
options.prev = options.page - 1; // calculate previous page, 0 is allowed
|
|
129
|
-
if (options.page<options.max) {
|
|
130
|
-
options.next = options.page + 1;
|
|
131
|
-
} else {
|
|
132
|
-
options.next = 0; // no next page
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
var start = (options.page - 1) * options.pageSize;
|
|
136
|
-
var end = start + options.pageSize;
|
|
137
|
-
|
|
138
|
-
this.view.data = this.view.data.slice(start, end);
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
var createFilter = function(options) {
|
|
143
|
-
var defaultOptions = {
|
|
144
|
-
name: 'filter',
|
|
145
|
-
label: 'A filter',
|
|
146
|
-
getMatch: function(entry) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
options = Object.assign(defaultOptions, options || {});
|
|
151
|
-
if (options.init) {
|
|
152
|
-
options.init.call(this, options);
|
|
153
|
-
}
|
|
154
|
-
return function(params) {
|
|
155
|
-
this.options[options.name] = options;
|
|
156
|
-
if (params[options.name]) {
|
|
157
|
-
options = Object.assign(options, params[options.name]);
|
|
158
|
-
}
|
|
159
|
-
var match = options.getMatch.call(this, options);
|
|
160
|
-
if (match) {
|
|
161
|
-
options.enabled = true;
|
|
162
|
-
this.view.data = this.view.data.filter(match);
|
|
163
|
-
} else if (options.enabled) {
|
|
164
|
-
options.enabled = false;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var viewmodel = {
|
|
170
|
-
create: function(name, data, options) {
|
|
171
|
-
return new ViewModel(name, data, options);
|
|
172
|
-
},
|
|
173
|
-
createFilter: createFilter,
|
|
174
|
-
createSort: createSort,
|
|
175
|
-
createPaging: createPaging,
|
|
176
|
-
updateDataSource: updateDataSource,
|
|
177
|
-
etag
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
181
|
-
module.exports = viewmodel;
|
|
182
|
-
} else {
|
|
183
|
-
if (!global.simply) {
|
|
184
|
-
global.simply = {};
|
|
185
|
-
}
|
|
186
|
-
global.simply.viewmodel = viewmodel;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
})(this);
|
|
File without changes
|