simplyview 2.1.1 → 3.0.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.
@@ -1,125 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
-
4
- var render = function(options) {
5
- if (!options) {
6
- options = {};
7
- }
8
- options = Object.assign({
9
- attribute: 'data-simply-field',
10
- selector: '[data-simply-field]',
11
- twoway: true,
12
- model: {}
13
- }, options);
14
-
15
- options.fieldTypes = Object.assign({
16
- '*': {
17
- set: function(value) {
18
- this.innerHTML = value;
19
- },
20
- get: function() {
21
- return this.innerHTML;
22
- }
23
- },
24
- 'input,textarea,select': {
25
- init: function(binding) {
26
- this.addEventListener('input', function() {
27
- if (binding.observing) {
28
- this.dispatchEvent(new Event('simply.bind.update', {
29
- bubbles: true,
30
- cancelable: true
31
- }));
32
- }
33
- });
34
- },
35
- set: function(value) {
36
- this.value = value;
37
- },
38
- get: function() {
39
- return this.value;
40
- }
41
- },
42
- 'input[type=radio]': {
43
- init: function(binding) {
44
- this.addEventListener('change', function() {
45
- if (binding.observing) {
46
- this.dispatchEvent(new Event('simply.bind.update', {
47
- bubbles: true,
48
- cancelable: true
49
- }));
50
- }
51
- });
52
- },
53
- set: function(value) {
54
- this.checked = (value==this.value);
55
- },
56
- get: function() {
57
- var checked;
58
- if (this.form) {
59
- return this.form[this.name].value;
60
- } else if (checked=document.body.querySelector('input[name="'+this.name+'"][checked]')) {
61
- return checked.value;
62
- } else {
63
- return null;
64
- }
65
- }
66
- },
67
- 'input[type=checkbox]': {
68
- init: function(binding) {
69
- this.addEventListener('change', function() {
70
- if (binding.observing) {
71
- this.dispatchEvent(new Event('simply.bind.update', {
72
- bubbles: true,
73
- cancelable: true
74
- }));
75
- }
76
- });
77
- },
78
- set: function(value) {
79
- this.checked = (value.checked);
80
- this.value = value.value;
81
- },
82
- get: function() {
83
- return {
84
- checked: this.checked,
85
- value: this.value
86
- };
87
- }
88
- },
89
- 'select[multiple]': {
90
- init: function(binding) {
91
- this.addEventListener('change', function() {
92
- if (binding.observing) {
93
- this.dispatchEvent(new Event('simply.bind.update', {
94
- bubbles: true,
95
- cancelable: true
96
- }));
97
- }
98
- });
99
- },
100
- set: function(value) {
101
- for (var i=0,l=this.options.length;i<l;i++) {
102
- this.options[i].selected = (value.indexOf(this.options[i].value)>=0);
103
- }
104
- },
105
- get: function() {
106
- return this.value;
107
- }
108
- },
109
- // '[data-simply-content="template"]': {
110
- // allowNesting: true
111
- // },
112
- }, options.fieldTypes);
113
-
114
- return options;
115
- };
116
-
117
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
118
- module.exports = render;
119
- } else {
120
- if (!global.simply) {
121
- global.simply = {};
122
- }
123
- global.simply.render = render;
124
- }
125
- })(this);
@@ -1,80 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
-
4
- var resize = function(app, config) {
5
- if (!config) {
6
- config = {};
7
- }
8
- if (!config.sizes) {
9
- config.sizes = {
10
- 'simply-tiny' : 0,
11
- 'simply-xsmall' : 480,
12
- 'simply-small' : 768,
13
- 'simply-medium' : 992,
14
- 'simply-large' : 1200
15
- };
16
- }
17
-
18
- var lastSize = 0;
19
- function resizeSniffer() {
20
- var size = app.container.getBoundingClientRect().width;
21
- if ( lastSize==size ) {
22
- return;
23
- }
24
- lastSize = size;
25
- var sizes = Object.keys(config.sizes);
26
- var match = sizes.pop();
27
- while (match) {
28
- if ( size<config.sizes[match] ) {
29
- if ( app.container.classList.contains(match)) {
30
- app.container.classList.remove(match);
31
- }
32
- } else {
33
- if ( !app.container.classList.contains(match) ) {
34
- app.container.classList.add(match);
35
- match = sizes.pop(); // skip to next match to remove these
36
- }
37
- break;
38
- }
39
- match = sizes.pop();
40
- }
41
- while (match) {
42
- if ( app.container.classList.contains(match)) {
43
- app.container.classList.remove(match);
44
- }
45
- match = sizes.pop();
46
- }
47
- var toolbars = app.container.querySelectorAll('.simply-toolbar');
48
- [].forEach.call(toolbars, function(toolbar) {
49
- toolbar.style.transform = '';
50
- });
51
- }
52
-
53
- if ( global.attachEvent ) {
54
- app.container.attachEvent('onresize', resizeSniffer);
55
- } else {
56
- global.setInterval(resizeSniffer, 200);
57
- }
58
-
59
- if ( simply.toolbar ) {
60
- var toolbars = app.container.querySelectorAll('.simply-toolbar');
61
- [].forEach.call(toolbars, function(toolbar) {
62
- simply.toolbar.init(toolbar);
63
- if (simply.toolbar.scroll) {
64
- simply.toolbar.scroll(toolbar);
65
- }
66
- });
67
- }
68
-
69
- return resizeSniffer;
70
- };
71
-
72
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
73
- module.exports = resize;
74
- } else {
75
- if (!global.simply) {
76
- global.simply = {};
77
- }
78
- global.simply.resize = resize;
79
- }
80
- })(this);
@@ -1,234 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
-
4
- var routeInfo = [];
5
- var listeners = {
6
- goto: {},
7
- match: {},
8
- call: {},
9
- finish: {}
10
- };
11
-
12
- function getRegexpFromRoute(route) {
13
- return new RegExp('^'+route.replace(/:\w+/g, '([^/]+)').replace(/:\*/, '(.*)'));
14
- }
15
-
16
- function parseRoutes(routes) {
17
- var paths = Object.keys(routes);
18
- var matchParams = /:(\w+|\*)/g;
19
- var matches, params, path;
20
- for (var i=0; i<paths.length; i++) {
21
- path = paths[i];
22
- matches = [];
23
- params = [];
24
- do {
25
- matches = matchParams.exec(path);
26
- if (matches) {
27
- params.push(matches[1]);
28
- }
29
- } while(matches);
30
- routeInfo.push({
31
- match: getRegexpFromRoute(path),
32
- params: params,
33
- action: routes[path]
34
- });
35
- }
36
- }
37
-
38
- var linkHandler = function(evt) {
39
- if (evt.ctrlKey) {
40
- return;
41
- }
42
- if (evt.which != 1) {
43
- return; // not a 'left' mouse click
44
- }
45
- var link = evt.target;
46
- while (link && link.tagName!='A') {
47
- link = link.parentElement;
48
- }
49
- if (link
50
- && link.pathname
51
- && link.hostname==global.location.hostname
52
- && !link.link
53
- && !link.dataset.simplyCommand
54
- ) {
55
- let path = getPath(link.pathname+link.hash);
56
- if ( !route.has(path) ) {
57
- path = getPath(link.pathname);
58
- }
59
- if ( route.has(path) ) {
60
- let params = runListeners('goto', { path: path});
61
- if (params.path) {
62
- route.goto(params.path);
63
- }
64
- evt.preventDefault();
65
- return false;
66
- }
67
- }
68
- };
69
-
70
- var options = {
71
- root: '/'
72
- };
73
-
74
- var getPath = function(path) {
75
- if (path.substring(0,options.root.length)==options.root
76
- ||
77
- ( options.root[options.root.length-1]=='/'
78
- && path.length==(options.root.length-1)
79
- && path == options.root.substring(0,path.length)
80
- )
81
- ) {
82
- path = path.substring(options.root.length);
83
- }
84
- if (path[0]!='/' && path[0]!='#') {
85
- path = '/'+path;
86
- }
87
- return path;
88
- };
89
-
90
- var getUrl = function(path) {
91
- path = getPath(path);
92
- if (options.root[options.root.length-1]==='/' && path[0]==='/') {
93
- path = path.substring(1);
94
- }
95
- return options.root + path;
96
- };
97
-
98
- function runListeners(action, params) {
99
- if (!Object.keys(listeners[action])) {
100
- return;
101
- }
102
- Object.keys(listeners[action]).forEach(function(route) {
103
- var routeRe = getRegexpFromRoute(route);
104
- if (routeRe.exec(params.path)) {
105
- var result;
106
- listeners[action][route].forEach(function(callback) {
107
- result = callback.call(global, params);
108
- if (result) {
109
- params = result;
110
- }
111
- });
112
- }
113
- });
114
- return params;
115
- }
116
-
117
- var route = {
118
- handleEvents: function() {
119
- global.addEventListener('popstate', function() {
120
- if (route.match(getPath(document.location.pathname + document.location.hash)) === false) {
121
- route.match(getPath(document.location.pathname));
122
- }
123
- });
124
- global.document.addEventListener('click', linkHandler);
125
- },
126
- load: function(routes) {
127
- parseRoutes(routes);
128
- },
129
- clear: function() {
130
- routeInfo = [];
131
- listeners = {
132
- match: {},
133
- call: {},
134
- finish: {}
135
- };
136
- },
137
- match: function(path, options) {
138
- var args = {
139
- path: path,
140
- options: options
141
- };
142
- args = runListeners('match',args);
143
- path = args.path ? args.path : path;
144
-
145
- var matches;
146
- if (!path) {
147
- if (route.match(document.location.pathname+document.location.hash)) {
148
- return true;
149
- } else {
150
- return route.match(document.location.pathname);
151
- }
152
- }
153
- path = getPath(path);
154
- for ( var i=0; i<routeInfo.length; i++) {
155
- matches = routeInfo[i].match.exec(path);
156
- if (!matches || !matches.length) {
157
- if (path && path[path.length-1]!='/') {
158
- matches = routeInfo[i].match.exec(path+'/');
159
- if (matches) {
160
- path+='/';
161
- history.replaceState({}, '', getUrl(path));
162
- }
163
- }
164
- }
165
- if (matches && matches.length) {
166
- var params = {};
167
- routeInfo[i].params.forEach(function(key, i) {
168
- if (key=='*') {
169
- key = 'remainder';
170
- }
171
- params[key] = matches[i+1];
172
- });
173
- Object.assign(params, options);
174
- args.route = route;
175
- args.params = params;
176
- args = runListeners('call', args);
177
- params = args.params ? args.params : params;
178
- args.result = routeInfo[i].action.call(route, params);
179
- runListeners('finish', args);
180
- return args.result;
181
- }
182
- }
183
- return false;
184
- },
185
- goto: function(path) {
186
- history.pushState({},'',getUrl(path));
187
- return route.match(path);
188
- },
189
- has: function(path) {
190
- path = getPath(path);
191
- for ( var i=0; i<routeInfo.length; i++) {
192
- var matches = routeInfo[i].match.exec(path);
193
- if (matches && matches.length) {
194
- return true;
195
- }
196
- }
197
- return false;
198
- },
199
- addListener: function(action, route, callback) {
200
- if (['goto','match','call','finish'].indexOf(action)==-1) {
201
- throw new Error('Unknown action '+action);
202
- }
203
- if (!listeners[action][route]) {
204
- listeners[action][route] = [];
205
- }
206
- listeners[action][route].push(callback);
207
- },
208
- removeListener: function(action, route, callback) {
209
- if (['match','call','finish'].indexOf(action)==-1) {
210
- throw new Error('Unknown action '+action);
211
- }
212
- if (!listeners[action][route]) {
213
- return;
214
- }
215
- listeners[action][route] = listeners[action][route].filter(function(listener) {
216
- return listener != callback;
217
- });
218
- },
219
- init: function(params) {
220
- if (params.root) {
221
- options.root = params.root;
222
- }
223
- }
224
- };
225
-
226
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
227
- module.exports = route;
228
- } else {
229
- if (!global.simply) {
230
- global.simply = {};
231
- }
232
- global.simply.route = route;
233
- }
234
- })(this);
package/js/simply.view.js DELETED
@@ -1,35 +0,0 @@
1
- (function(global) {
2
- 'use strict';
3
- var view = function(app, view) {
4
-
5
- app.view = view || {};
6
-
7
- var load = function() {
8
- var data = app.view;
9
- var path = global.editor.data.getDataPath(app.container);
10
- app.view = global.editor.currentData[path];
11
- Object.keys(data).forEach(function(key) {
12
- app.view[key] = data[key];
13
- });
14
- };
15
-
16
- if (global.editor && global.editor.currentData) {
17
- load();
18
- } else {
19
- global.document.addEventListener('simply-content-loaded', function() {
20
- load();
21
- });
22
- }
23
-
24
- return app.view;
25
- };
26
-
27
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
28
- module.exports = view;
29
- } else {
30
- if (!global.simply) {
31
- global.simply = {};
32
- }
33
- global.simply.view = view;
34
- }
35
- })(this);
@@ -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);