simplyview 1.0.0 → 2.0.2

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.
Files changed (49) hide show
  1. package/README.md +9 -6
  2. package/dist/simply.everything.js +1596 -1139
  3. package/docs/examples.md +82 -0
  4. package/docs/readme.md +33 -0
  5. package/docs/simply.action.md +42 -0
  6. package/docs/simply.activate.md +27 -0
  7. package/docs/simply.api.md +188 -0
  8. package/docs/simply.app.md +27 -0
  9. package/docs/simply.collect.md +64 -0
  10. package/docs/simply.command.md +110 -0
  11. package/docs/simply.include.md +61 -0
  12. package/docs/simply.keyboard.md +60 -0
  13. package/docs/simply.path.md +3 -0
  14. package/docs/simply.route.md +133 -0
  15. package/docs/simply.view.md +53 -0
  16. package/docs/simply.viewmodel.md +3 -0
  17. package/examples/counter.html +1 -0
  18. package/examples/github.html +39 -0
  19. package/examples/githubv4.html +107 -0
  20. package/examples/graphql.html +51 -0
  21. package/examples/graphql.html~ +35 -0
  22. package/examples/keyboard.html +41 -0
  23. package/examples/viewmodel.html +359 -0
  24. package/js/simply.action.js +14 -5
  25. package/js/simply.activate.js +12 -4
  26. package/js/simply.api.js +229 -0
  27. package/js/simply.app.js +27 -9
  28. package/js/simply.collect.js +13 -5
  29. package/js/simply.command.js +36 -6
  30. package/js/simply.include.js +38 -17
  31. package/js/simply.keyboard.js +45 -0
  32. package/js/simply.modules.js +22 -0
  33. package/js/simply.observe.js +13 -4
  34. package/js/simply.path.js +12 -4
  35. package/js/simply.render.js +12 -6
  36. package/js/simply.resize.js +28 -20
  37. package/js/simply.route.js +149 -19
  38. package/js/simply.view.js +16 -9
  39. package/js/simply.viewmodel.js +174 -0
  40. package/make +16 -2
  41. package/make~ +17 -0
  42. package/package.json +6 -3
  43. package/package.json~ +8 -5
  44. package/test/simply.route.test.js +102 -0
  45. package/examples/todo.html~ +0 -50
  46. package/js/simply.app.js~ +0 -44
  47. package/js/simply.bind.js +0 -253
  48. package/js/simply.command.js~ +0 -166
  49. package/js/simply.resize.js~ +0 -69
package/js/simply.app.js~ DELETED
@@ -1,44 +0,0 @@
1
- this.simply = (function(simply, global) {
2
- simply.app = function(options) {
3
- if (!options) {
4
- options = {};
5
- }
6
- if (!options.container) {
7
- console.warn('No simply.app application container element specified, using document.body.');
8
- }
9
-
10
- function simplyApp(options) {
11
- if (!options) {
12
- options = {};
13
- }
14
- if ( options.routes ) {
15
- simply.route.load(options.routes);
16
- global.setTimeout(function() {
17
- simply.route.match(global.location.pathname);
18
- });
19
- }
20
- this.container = options.container || document.body;
21
- this.actions = simply.action ? simply.action(this, options.actions) : false;
22
- this.commands = simply.command ? simply.command(this, options.commands) : false;
23
- this.resize = simply.resize ? simply.resize(this, options.resize) : false;
24
- this.view = simply.view ? simply.view(this, options.view) : false;
25
- if (!(editor && editor.field) && simply.bind) {
26
- // skip simplyview databinding if SimplyEdit is loaded
27
- options.bind = simply.render(options.bind || {});
28
- options.bind.model = this.view;
29
- options.bind.container = this.container;
30
- this.bind = options.bindings = simply.bind(options.bind);
31
- }
32
- }
33
-
34
- simplyApp.prototype.get = function(id) {
35
- return this.container.querySelector('[data-simply-id='+id+']') || document.getElementById(id);
36
- };
37
-
38
- var app = new simplyApp(options);
39
-
40
- return app;
41
- };
42
-
43
- return simply;
44
- })(this.simply || {}, this);
package/js/simply.bind.js DELETED
@@ -1,253 +0,0 @@
1
- this.simply = (function(simply, global) {
2
- if (!simply.observe) {
3
- console.error('Error: simply.bind requires simply.observe');
4
- return simply;
5
- }
6
-
7
- function getByPath(model, path) {
8
- var parts = path.split('.');
9
- var curr = model;
10
- do {
11
- curr = curr[parts.shift()];
12
- } while (parts.length && curr);
13
- return curr;
14
- }
15
-
16
- function setByPath(model, path, value) {
17
- var parts = path.split('.');
18
- var curr = model;
19
- while (parts.length>1 && curr) {
20
- var key = parts.shift();
21
- if (typeof curr[key] == 'undefined' || curr[key]==null) {
22
- curr[key] = {};
23
- }
24
- curr = curr[key];
25
- }
26
- curr[parts.shift()] = value;
27
- }
28
-
29
- function setValue(el, value, binding) {
30
- if (el!=focusedElement) {
31
- var fieldType = getFieldType(binding.fieldTypes, el);
32
- if (fieldType) {
33
- fieldType.set.call(el, (typeof value != 'undefined' ? value : ''), binding);
34
- el.dispatchEvent(new Event('simply.bind.resolved', {
35
- bubbles: true,
36
- cancelable: false
37
- }));
38
- }
39
- }
40
- }
41
-
42
- function getValue(el, binding) {
43
- var setters = Object.keys(binding.fieldTypes);
44
- for(var i=setters.length-1;i>=0;i--) {
45
- if (el.matches(setters[i])) {
46
- return binding.fieldTypes[setters[i]].get.call(el);
47
- }
48
- }
49
- }
50
-
51
- function getFieldType(fieldTypes, el) {
52
- var setters = Object.keys(fieldTypes);
53
- for(var i=setters.length-1;i>=0;i--) {
54
- if (el.matches(setters[i])) {
55
- return fieldTypes[setters[i]];
56
- }
57
- }
58
- return null;
59
- }
60
-
61
- function getPath(el, attribute) {
62
- var attributes = attribute.split(',');
63
- for (var attr of attributes) {
64
- if (el.hasAttribute(attr)) {
65
- return el.getAttribute(attr);
66
- }
67
- }
68
- return null;
69
- }
70
-
71
- function throttle( callbackFunction, intervalTime ) {
72
- var eventId = 0;
73
- return function() {
74
- var myArguments = arguments;
75
- var me = this;
76
- if ( eventId ) {
77
- return;
78
- } else {
79
- eventId = global.setTimeout( function() {
80
- callbackFunction.apply(me, myArguments);
81
- eventId = 0;
82
- }, intervalTime );
83
- }
84
- };
85
- }
86
-
87
- var runWhenIdle = (function() {
88
- if (global.requestIdleCallback) {
89
- return function(callback) {
90
- global.requestIdleCallback(callback, {timeout: 500});
91
- };
92
- }
93
- return global.requestAnimationFrame;
94
- })();
95
-
96
- function Binding(config, force) {
97
- this.config = config;
98
- if (!this.config) {
99
- this.config = {};
100
- }
101
- if (!this.config.model) {
102
- this.config.model = {};
103
- }
104
- if (!this.config.attribute) {
105
- this.config.attribute = 'data-simply-bind';
106
- }
107
- if (!this.config.selector) {
108
- this.config.selector = '[data-simply-bind]';
109
- }
110
- if (!this.config.container) {
111
- this.config.container = document;
112
- }
113
- if (typeof this.config.twoway == 'undefined') {
114
- this.config.twoway = true;
115
- }
116
- this.fieldTypes = {
117
- '*': {
118
- set: function(value) {
119
- this.innerHTML = value;
120
- },
121
- get: function() {
122
- return this.innerHTML;
123
- }
124
- }
125
- };
126
- if (this.config.fieldTypes) {
127
- Object.assign(this.fieldTypes, this.config.fieldTypes);
128
- }
129
- this.attach(this.config.container.querySelectorAll(this.config.selector), this.config.model, force);
130
- if (this.config.twoway) {
131
- var self = this;
132
- var observer = new MutationObserver(
133
- throttle(function() {
134
- runWhenIdle(function() {
135
- self.attach(self.config.container.querySelectorAll(self.config.selector), self.config.model);
136
- });
137
- })
138
- );
139
- observer.observe(this.config.container, {
140
- subtree: true,
141
- childList: true
142
- });
143
- }
144
- }
145
-
146
- var focusedElement = null;
147
- var initialized = new WeakMap();
148
- var observers = new WeakMap();
149
- var observersPaused = 0;
150
-
151
- Binding.prototype.attach = function(el, model, force) {
152
- var illegalNesting = function() {
153
- return (!force && el.parentElement && el.parentElement.closest(self.config.selector));
154
- };
155
-
156
- var attachElement = function(jsonPath) {
157
- el.dataset.simplyBound = true;
158
- initElement(el);
159
- setValue(el, getByPath(model, jsonPath), self);
160
- simply.observe(model, jsonPath, function(value) {
161
- if (el != focusedElement) {
162
- setValue(el, value, self);
163
- }
164
- });
165
- };
166
-
167
- var addMutationObserver = function(jsonPath) {
168
- if (el.dataset.simplyList) {
169
- return;
170
- }
171
- var update = throttle(function() {
172
- runWhenIdle(function() {
173
- var v = getValue(el, self);
174
- var s = getByPath(model, jsonPath);
175
- if (v != s) {
176
- focusedElement = el;
177
- setByPath(model, jsonPath, v);
178
- focusedElement = null;
179
- }
180
- });
181
- }, 250);
182
- var observer = new MutationObserver(function() {
183
- if (observersPaused) {
184
- return;
185
- }
186
- update();
187
- });
188
- observer.observe(el, {
189
- characterData: true,
190
- subtree: true,
191
- childList: true,
192
- attributes: true
193
- });
194
- if (!observers.has(el)) {
195
- observers.set(el, []);
196
- }
197
- observers.get(el).push(observer);
198
- return observer;
199
- };
200
-
201
- /**
202
- * Runs the init() method of the fieldType, if it is defined.
203
- **/
204
- var initElement = function(el) {
205
- if (initialized.has(el)) {
206
- return;
207
- }
208
- initialized.set(el, true);
209
- var selectors = Object.keys(self.fieldTypes);
210
- for (var i=selectors.length-1; i>=0; i--) {
211
- if (self.fieldTypes[selectors[i]].init && el.matches(selectors[i])) {
212
- self.fieldTypes[selectors[i]].init.call(el, self);
213
- return;
214
- }
215
- }
216
- };
217
-
218
- var self = this;
219
- if (el instanceof HTMLElement) {
220
- if (!force && el.dataset.simplyBound) {
221
- return;
222
- }
223
- var jsonPath = getPath(el, this.config.attribute);
224
- if (illegalNesting(el)) {
225
- el.dataset.simplyBound = 'Error: nested binding';
226
- console.error('Error: found nested data-binding element:',el);
227
- return;
228
- }
229
- attachElement(jsonPath);
230
- if (this.config.twoway) {
231
- addMutationObserver(jsonPath);
232
- }
233
- } else {
234
- [].forEach.call(el, function(element) {
235
- self.attach(element, model, force);
236
- });
237
- }
238
- };
239
-
240
- Binding.prototype.pauseObservers = function() {
241
- observersPaused++;
242
- };
243
-
244
- Binding.prototype.resumeObservers = function() {
245
- observersPaused--;
246
- };
247
-
248
- simply.bind = function(config, force) {
249
- return new Binding(config, force);
250
- };
251
-
252
- return simply;
253
- })(this.simply || {}, this);
@@ -1,166 +0,0 @@
1
- this.simply = (function(simply, global) {
2
-
3
- var defaultCommands = {
4
- 'simply-hide': function(el, value) {
5
- var target = this.app.get(value);
6
- if (target) {
7
- this.action('simply-hide',target);
8
- }
9
- },
10
- 'simply-show': function(el, value) {
11
- var target = this.app.get(value);
12
- if (target) {
13
- this.action('simply-show',target);
14
- }
15
- },
16
- 'simply-select': function(value,el) {
17
- var group = el.dataset.simplyGroup;
18
- var target = this.app.get(value);
19
- var targetGroup = (target ? target.dataset.simplyGroup : null);
20
- this.action('simply-select', el, group, target, targetGroup);
21
- },
22
- 'simply-toggle-select': function(el, value) {
23
- var group = el.dataset.simplyGroup;
24
- var target = this.app.get(value);
25
- var targetGroup = (target ? target.dataset.simplyTarget : null);
26
- this.action('simply-toggle-select',el,group,target,targetGroup);
27
- },
28
- 'simply-toggle-class': function(el, value) {
29
- var target = this.app.get(el.dataset.simplyTarget);
30
- this.action('simply-toggle-class',el,value,target);
31
- },
32
- 'simply-deselect': function(el, value) {
33
- var target = this.app.get(value);
34
- this.action('simply-deselect',el,target);
35
- },
36
- 'simply-fullscreen': function(el, value) {
37
- var target = this.app.get(value);
38
- this.action('simply-fullscreen',target);
39
- }
40
- };
41
-
42
-
43
- var handlers = [
44
- {
45
- match: 'input,select,textarea',
46
- get: function(el) {
47
- return el.dataset.simplyValue || el.value;
48
- },
49
- check: function(el, evt) {
50
- return evt.type=='change' || (el.dataset.simplyImmediate && evt.type=='input');
51
- }
52
- },
53
- {
54
- match: 'a,button',
55
- get: function(el) {
56
- return el.dataset.simplyValue || el.href || el.value;
57
- },
58
- check: function(el,evt) {
59
- return evt.type=='click' && evt.ctrlKey==false && evt.button==0;
60
- }
61
- },
62
- {
63
- match: 'form',
64
- get: function(el) {
65
- var data = {};
66
- [].forEach.call(el.elements, function(el) {
67
- data[el.name] = el.value;
68
- });
69
- return data;//new FormData(el);
70
- },
71
- check: function(el,evt) {
72
- return evt.type=='submit';
73
- }
74
- }
75
- ];
76
-
77
- var fallbackHandler = {
78
- get: function(el) {
79
- return el.dataset.simplyValue;
80
- },
81
- check: function(el, evt) {
82
- return evt.type=='click' && evt.ctrlKey==false && evt.button==0;
83
- }
84
- };
85
-
86
- function getCommand(evt) {
87
- var el = evt.target.closest('[data-simply-command]');
88
- if (el) {
89
- var matched = false;
90
- for (var i=handlers.length-1; i>=0; i--) {
91
- if (el.matches(handlers[i].match)) {
92
- matched = true;
93
- if (handlers[i].check(el, evt)) {
94
- return {
95
- name: el.dataset.simplyCommand,
96
- source: el,
97
- value: handlers[i].get(el)
98
- };
99
- }
100
- }
101
- }
102
- if (!matched && fallbackHandler.check(el,evt)) {
103
- return {
104
- name: el.dataset.simplyCommand,
105
- source: el,
106
- value: fallbackHandler.get(el)
107
- };
108
- }
109
- }
110
- return null;
111
- }
112
-
113
- simply.command = function(app, inCommands) {
114
-
115
- var commands = Object.create(defaultCommands);
116
- for (var i in inCommands) {
117
- commands[i] = inCommands[i];
118
- }
119
-
120
- commands.app = app;
121
-
122
- commands.action = function(name) {
123
- var params = Array.prototype.slice.call(arguments);
124
- params.shift();
125
- return app.actions[name].apply(app.actions,params);
126
- };
127
-
128
- commands.call = function(name) {
129
- var params = Array.prototype.slice.call(arguments);
130
- params.shift();
131
- return this[name].apply(this,params);
132
- };
133
-
134
- commands.appendHandler = function(handler) {
135
- handlers.push(handler);
136
- };
137
-
138
- commands.prependHandler = function(handler) {
139
- handlers.unshift(handler);
140
- };
141
-
142
- var commandHandler = function(evt) {
143
- var command = getCommand(evt);
144
- if ( command ) {
145
- if (!commands[command.name]) {
146
- console.error('simply.command: undefined command '+command.name, command.source);
147
- } else {
148
- commands.call(command.name, command.source, command.value);
149
- evt.preventDefault();
150
- evt.stopPropagation();
151
- return false;
152
- }
153
- }
154
- };
155
-
156
- app.container.addEventListener('click', commandHandler);
157
- app.container.addEventListener('submit', commandHandler);
158
- app.container.addEventListener('change', commandHandler);
159
- app.container.addEventListener('input', commandHandler);
160
-
161
- return commands;
162
- };
163
-
164
- return simply;
165
-
166
- })(this.simply || {}, this);
@@ -1,69 +0,0 @@
1
- this.simply = (function(simply, global) {
2
-
3
- simply.resize = function(app, config) {
4
- if(!config.sizes) {
5
- config.sizes = {
6
- 'simply-tiny' : 0,
7
- 'simply-xsmall' : 480,
8
- 'simply-small' : 768,
9
- 'simply-medium' : 992,
10
- 'simply-large' : 1200
11
- };
12
- }
13
-
14
- var lastSize = 0;
15
- function resizeSniffer() {
16
- var size = app.container.getBoundingClientRect().width;
17
- if ( lastSize==size ) {
18
- return;
19
- }
20
- lastSize = size;
21
- var sizes = Object.keys(config.sizes);
22
- var match = sizes.pop();
23
- while (match) {
24
- if ( size<config.sizes[match] ) {
25
- if ( app.container.classList.contains(match)) {
26
- app.container.classList.remove(match);
27
- }
28
- } else {
29
- if ( !app.container.classList.contains(match) ) {
30
- app.container.classList.add(match);
31
- }
32
- break;
33
- }
34
- match = sizes.pop();
35
- }
36
- while (match) {
37
- if ( app.container.classList.contains(match)) {
38
- app.container.classList.remove(match);
39
- }
40
- match=sizes.pop();
41
- }
42
- var toolbars = app.container.querySelectorAll('.simply-toolbar');
43
- [].forEach.call(toolbars, function(toolbar) {
44
- toolbar.style.transform = '';
45
- });
46
- }
47
-
48
- if ( global.attachEvent ) {
49
- app.container.attachEvent('onresize', resizeSniffer);
50
- } else {
51
- global.setInterval(resizeSniffer, 200);
52
- }
53
-
54
- if ( simply.toolbar ) {
55
- var toolbars = app.container.querySelectorAll('.simply-toolbar');
56
- [].forEach.call(toolbars, function(toolbar) {
57
- simply.toolbar.init(toolbar);
58
- if (simply.toolbar.scroll) {
59
- simply.toolbar.scroll(toolbar);
60
- }
61
- });
62
- }
63
-
64
- return resizeSniffer;
65
- };
66
-
67
- return simply;
68
-
69
- })(this.simply || {}, this);