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 CHANGED
@@ -1,5 +1,7 @@
1
- this.simply = (function(simply, global) {
2
- simply.app = function(options) {
1
+ (function(global) {
2
+ 'use strict';
3
+
4
+ var app = function(options) {
3
5
  if (!options) {
4
6
  options = {};
5
7
  }
@@ -13,12 +15,22 @@ this.simply = (function(simply, global) {
13
15
  }
14
16
  if ( options.routes ) {
15
17
  simply.route.load(options.routes);
18
+ if (options.routeEvents) {
19
+ Object.keys(options.routeEvents).forEach(function(action) {
20
+ Object.keys(options.routeEvents[action]).forEach(function(route) {
21
+ options.routeEvents[action][route].forEach(function(callback) {
22
+ simply.route.addListener(action, route, callback);
23
+ });
24
+ });
25
+ });
26
+ }
16
27
  simply.route.handleEvents();
17
28
  global.setTimeout(function() {
18
- simply.route.match(global.location.pathname);
29
+ simply.route.match(global.location.pathname+global.location.hash);
19
30
  });
20
31
  }
21
- this.container = options.container || document.body;
32
+ this.container = options.container || document.body;
33
+ this.keyboard = simply.keyboard ? simply.keyboard(this, options.keyboard || {}) : false;
22
34
  this.actions = simply.action ? simply.action(this, options.actions) : false;
23
35
  this.commands = simply.command ? simply.command(this, options.commands) : false;
24
36
  this.resize = simply.resize ? simply.resize(this, options.resize) : false;
@@ -36,10 +48,16 @@ this.simply = (function(simply, global) {
36
48
  return this.container.querySelector('[data-simply-id='+id+']') || document.getElementById(id);
37
49
  };
38
50
 
39
- var app = new simplyApp(options);
40
-
41
- return app;
51
+ return new simplyApp(options);
42
52
  };
43
53
 
44
- return simply;
45
- })(this.simply || {}, this);
54
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
55
+ module.exports = app;
56
+ } else {
57
+ if (!global.simply) {
58
+ global.simply = {};
59
+ }
60
+ global.simply.app = app;
61
+ }
62
+
63
+ })(this);
@@ -1,8 +1,9 @@
1
- this.simply = (function(simply, global) {
1
+ (function(global) {
2
+ 'use strict';
2
3
 
3
4
  var knownCollections = {};
4
5
 
5
- simply.collect = {
6
+ var collect = {
6
7
  addListener: function(name, callback) {
7
8
  if (!knownCollections[name]) {
8
9
  knownCollections[name] = [];
@@ -35,7 +36,7 @@ this.simply = (function(simply, global) {
35
36
  return el;
36
37
  }
37
38
 
38
- document.addEventListener('change', function(evt) {
39
+ global.addEventListener('change', function(evt) {
39
40
  var root = null;
40
41
  var name = '';
41
42
  if (evt.target.dataset.simplyElement) {
@@ -59,6 +60,13 @@ this.simply = (function(simply, global) {
59
60
  }
60
61
  }, true);
61
62
 
62
- return simply;
63
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
64
+ module.exports = collect;
65
+ } else {
66
+ if (!global.simply) {
67
+ global.simply = {};
68
+ }
69
+ global.simply.collect = collect;
70
+ }
63
71
 
64
- })(this.simply || {}, this);
72
+ })(this);
@@ -1,4 +1,5 @@
1
- this.simply = (function(simply, global) {
1
+ (function(global) {
2
+ 'use strict';
2
3
 
3
4
  var defaultCommands = {
4
5
  'simply-hide': function(el, value) {
@@ -44,6 +45,16 @@ this.simply = (function(simply, global) {
44
45
  {
45
46
  match: 'input,select,textarea',
46
47
  get: function(el) {
48
+ if (el.tagName==='SELECT' && el.multiple) {
49
+ var values = [], opt;
50
+ for (var i=0,l=el.options.length;i<l;i++) {
51
+ var opt = el.options[i];
52
+ if (opt.selected) {
53
+ values.push(opt.value);
54
+ }
55
+ }
56
+ return values;
57
+ }
47
58
  return el.dataset.simplyValue || el.value;
48
59
  },
49
60
  check: function(el, evt) {
@@ -64,7 +75,19 @@ this.simply = (function(simply, global) {
64
75
  get: function(el) {
65
76
  var data = {};
66
77
  [].forEach.call(el.elements, function(el) {
67
- data[el.name] = el.value;
78
+ if (el.tagName=='INPUT' && (el.type=='checkbox' || el.type=='radio')) {
79
+ if (!el.checked) {
80
+ return;
81
+ }
82
+ }
83
+ if (data[el.name] && !Array.isArray(data[el.name])) {
84
+ data[el.name] = [data[el.name]];
85
+ }
86
+ if (Array.isArray(data[el.name])) {
87
+ data[el.name].push(el.value);
88
+ } else {
89
+ data[el.name] = el.value;
90
+ }
68
91
  });
69
92
  return data;//new FormData(el);
70
93
  },
@@ -110,7 +133,7 @@ this.simply = (function(simply, global) {
110
133
  return null;
111
134
  }
112
135
 
113
- simply.command = function(app, inCommands) {
136
+ var command = function(app, inCommands) {
114
137
 
115
138
  var commands = Object.create(defaultCommands);
116
139
  for (var i in inCommands) {
@@ -161,6 +184,13 @@ this.simply = (function(simply, global) {
161
184
  return commands;
162
185
  };
163
186
 
164
- return simply;
165
-
166
- })(this.simply || {}, this);
187
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
188
+ module.exports = command;
189
+ } else {
190
+ if (!global.simply) {
191
+ global.simply = {};
192
+ }
193
+ global.simply.command = command;
194
+ }
195
+
196
+ })(this);
@@ -1,4 +1,5 @@
1
- this.simply = (function (simply, global) {
1
+ (function (global) {
2
+ 'use strict';
2
3
 
3
4
  var throttle = function( callbackFunction, intervalTime ) {
4
5
  var eventId = 0;
@@ -45,8 +46,19 @@ this.simply = (function (simply, global) {
45
46
  };
46
47
 
47
48
  var observer, loaded = {};
48
- var head = document.documentElement.querySelector('head');
49
- var currentScript = document.currentScript;
49
+ var head = global.document.querySelector('head');
50
+ var currentScript = global.document.currentScript;
51
+ if (!currentScript) {
52
+ var getScriptURL = (function() {
53
+ var scripts = document.getElementsByTagName('script');
54
+ var index = scripts.length - 1;
55
+ var myScript = scripts[index];
56
+ return function() { return myScript.src; };
57
+ })();
58
+ var currentScriptURL = getScriptURL();
59
+ } else {
60
+ var currentScriptURL = currentScript.src;
61
+ }
50
62
 
51
63
  var waitForPreviousScripts = function() {
52
64
  // because of the async=false attribute, this script will run after
@@ -54,10 +66,10 @@ this.simply = (function (simply, global) {
54
66
  // simply.include.next.js only fires the simply-next-script event
55
67
  // that triggers the Promise.resolve method
56
68
  return new Promise(function(resolve) {
57
- var next = document.createElement('script');
58
- next.src = rebaseHref('simply.include.next.js', currentScript.src);
69
+ var next = global.document.createElement('script');
70
+ next.src = rebaseHref('simply.include.next.js', currentScriptURL);
59
71
  next.async = false;
60
- document.addEventListener('simply-include-next', function() {
72
+ global.document.addEventListener('simply-include-next', function() {
61
73
  head.removeChild(next);
62
74
  resolve();
63
75
  }, { once: true, passive: true});
@@ -67,7 +79,7 @@ this.simply = (function (simply, global) {
67
79
 
68
80
  var scriptLocations = [];
69
81
 
70
- simply.include = {
82
+ var include = {
71
83
  scripts: function(scripts, base) {
72
84
  var arr = [];
73
85
  for(var i = scripts.length; i--; arr.unshift(scripts[i]));
@@ -79,9 +91,9 @@ this.simply = (function (simply, global) {
79
91
  var attrs = [].map.call(script.attributes, function(attr) {
80
92
  return attr.name;
81
93
  });
82
- var clone = document.createElement('script');
94
+ var clone = global.document.createElement('script');
83
95
  attrs.forEach(function(attr) {
84
- clone.setAttribute(attr, script[attr]);
96
+ clone.setAttribute(attr, script.getAttribute(attr));
85
97
  });
86
98
  clone.removeAttribute('data-simply-location');
87
99
  if (!clone.src) {
@@ -111,7 +123,7 @@ this.simply = (function (simply, global) {
111
123
  }
112
124
  },
113
125
  html: function(html, link) {
114
- var fragment = document.createRange().createContextualFragment(html);
126
+ var fragment = global.document.createRange().createContextualFragment(html);
115
127
  var stylesheets = fragment.querySelectorAll('link[rel="stylesheet"],style');
116
128
  // add all stylesheets to head
117
129
  [].forEach.call(stylesheets, function(stylesheet) {
@@ -122,12 +134,12 @@ this.simply = (function (simply, global) {
122
134
  });
123
135
  // remove the scripts from the fragment, as they will not run in the
124
136
  // order in which they are defined
125
- var scriptsFragment = document.createDocumentFragment();
137
+ var scriptsFragment = global.document.createDocumentFragment();
126
138
  // FIXME: this loses the original position of the script
127
139
  // should add a placeholder so we can reinsert the clone
128
140
  var scripts = fragment.querySelectorAll('script');
129
141
  [].forEach.call(scripts, function(script) {
130
- var placeholder = document.createComment(script.src || 'inline script');
142
+ var placeholder = global.document.createComment(script.src || 'inline script');
131
143
  script.parentNode.insertBefore(placeholder, script);
132
144
  script.dataset.simplyLocation = scriptLocations.length;
133
145
  scriptLocations.push(placeholder);
@@ -138,7 +150,7 @@ this.simply = (function (simply, global) {
138
150
  global.setTimeout(function() {
139
151
  if (global.editor && global.editor.data && fragment.querySelector('[data-simply-field],[data-simply-list]')) {
140
152
  //TODO: remove this dependency and let simply.bind listen for dom node insertions (and simply-edit.js use simply.bind)
141
- global.editor.data.apply(editor.currentData, document);
153
+ global.editor.data.apply(global.editor.currentData, global.document);
142
154
  }
143
155
  simply.include.scripts(scriptsFragment.childNodes, link ? link.href : global.location.href );
144
156
  }, 10);
@@ -183,7 +195,7 @@ this.simply = (function (simply, global) {
183
195
 
184
196
  var handleChanges = throttle(function() {
185
197
  runWhenIdle(function() {
186
- var links = document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');
198
+ var links = global.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');
187
199
  if (links.length) {
188
200
  includeLinks(links);
189
201
  }
@@ -192,14 +204,23 @@ this.simply = (function (simply, global) {
192
204
 
193
205
  var observe = function() {
194
206
  observer = new MutationObserver(handleChanges);
195
- observer.observe(document, {
207
+ observer.observe(global.document, {
196
208
  subtree: true,
197
209
  childList: true,
198
210
  });
199
211
  };
200
212
 
201
213
  observe();
214
+ handleChanges(); // check if there are include links in the dom already
215
+
216
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
217
+ module.exports = include;
218
+ } else {
219
+ if (!global.simply) {
220
+ global.simply = {};
221
+ }
222
+ global.simply.include = include;
223
+ }
202
224
 
203
- return simply;
204
225
 
205
- })(this.simply || {}, this);
226
+ })(this);
@@ -0,0 +1,45 @@
1
+ (function(global) {
2
+ 'use strict';
3
+
4
+ function keyboard(app, config) {
5
+ var keys = config;
6
+
7
+ if (!app) {
8
+ app = {};
9
+ }
10
+ if (!app.container) {
11
+ app.container = document.body;
12
+ }
13
+ app.container.addEventListener('keydown', (e) => {
14
+ if (e.isComposing || e.keyCode === 229) {
15
+ return;
16
+ }
17
+ if (e.defaultPrevented) {
18
+ return;
19
+ }
20
+ if (!e.target) {
21
+ return;
22
+ }
23
+
24
+ let selectedKeyboard = 'default';
25
+ if (e.target.closest('[data-simply-keyboard]')) {
26
+ selectedKeyboard = e.target.closest('[data-simply-keyboard]').dataset.simplyKeyboard;
27
+ }
28
+ if (keys[selectedKeyboard] && keys[selectedKeyboard][e.code]) {
29
+ keys[selectedKeyboard][e.code].call(app,e);
30
+ }
31
+ });
32
+
33
+ return keys;
34
+ }
35
+
36
+
37
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
38
+ module.exports = keyboard;
39
+ } else {
40
+ if (!global.simply) {
41
+ global.simply = {};
42
+ }
43
+ global.simply.keyboard = keyboard;
44
+ }
45
+ })(this);
@@ -0,0 +1,22 @@
1
+ (function() {
2
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
3
+ var simply = {
4
+ command: require('simply.command.js'),
5
+ action: require('simply.action.js'),
6
+ route: require('simply.route.js'),
7
+ view: require('simply.view.js'),
8
+ viewmodel: require('simply.viewmodel.js'),
9
+ resize: require('simply.resize.js'),
10
+ activate:require('simply.active.js'),
11
+ include: require('simply.include.js'),
12
+ render: require('simply.render.js'),
13
+ observe: require('simply.observe.js'),
14
+ bind: require('simply.bind.js'),
15
+ app: require('simply.app.js'),
16
+ collect: require('simply.collect.js'),
17
+ path: require('simply.path.js')
18
+ }
19
+
20
+ module.exports = simply;
21
+ }
22
+ })();
@@ -39,7 +39,9 @@
39
39
  properties for a given parent, keep seperate index for this?
40
40
  */
41
41
 
42
- this.simply = (function (simply, global) {
42
+ (function (global) {
43
+ 'use strict';
44
+
43
45
  var changeListeners = new WeakMap();
44
46
  var parentListeners = new WeakMap();
45
47
  var childListeners = new WeakMap();
@@ -315,7 +317,7 @@ this.simply = (function (simply, global) {
315
317
  // model.foo = { }
316
318
  // model.foo.bar = 'zab'; // this should trigger the observer but doesn't
317
319
 
318
- simply.observe = function(model, path, callback, options) {
320
+ var observe = function(model, path, callback, options) {
319
321
  if (!path) {
320
322
  var keys = Object.keys(model);
321
323
  keys.forEach(function(key) {
@@ -336,5 +338,12 @@ this.simply = (function (simply, global) {
336
338
  }
337
339
  };
338
340
 
339
- return simply;
340
- })(this.simply || {}, this);
341
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
342
+ module.exports = observe;
343
+ } else {
344
+ if (!global.simply) {
345
+ global.simply = {};
346
+ }
347
+ global.simply.observe = observe;
348
+ }
349
+ })(this);
package/js/simply.path.js CHANGED
@@ -1,6 +1,7 @@
1
- this.simply = (function(simply) {
1
+ (function(global) {
2
+ 'us strict';
2
3
 
3
- simply.path = {
4
+ var path = {
4
5
  get: function(model, path) {
5
6
  if (!path) {
6
7
  return model;
@@ -36,5 +37,12 @@ this.simply = (function(simply) {
36
37
  }
37
38
  };
38
39
 
39
- return simply;
40
- })(this.simply || {});
40
+ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
41
+ module.exports = path;
42
+ } else {
43
+ if (!global.simply) {
44
+ global.simply = {};
45
+ }
46
+ global.simply.path = path;
47
+ }
48
+ })(this);
@@ -1,8 +1,7 @@
1
- this.simply = (function(simply, global) {
1
+ (function(global) {
2
+ 'use strict';
2
3
 
3
- // var templates = new WeakMap();
4
-
5
- simply.render = function(options) {
4
+ var render = function(options) {
6
5
  if (!options) {
7
6
  options = {};
8
7
  }
@@ -115,5 +114,12 @@ this.simply = (function(simply, global) {
115
114
  return options;
116
115
  };
117
116
 
118
- return simply;
119
- })(this.simply || {}, this);
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,18 +1,19 @@
1
- this.simply = (function(simply, global) {
1
+ (function(global) {
2
+ 'use strict';
2
3
 
3
- simply.resize = function(app, config) {
4
- if (!config) {
5
- config = {};
6
- }
7
- if (!config.sizes) {
8
- config.sizes = {
9
- 'simply-tiny' : 0,
10
- 'simply-xsmall' : 480,
11
- 'simply-small' : 768,
12
- 'simply-medium' : 992,
13
- 'simply-large' : 1200
14
- };
15
- }
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
+ }
16
17
 
17
18
  var lastSize = 0;
18
19
  function resizeSniffer() {
@@ -31,6 +32,7 @@ this.simply = (function(simply, global) {
31
32
  } else {
32
33
  if ( !app.container.classList.contains(match) ) {
33
34
  app.container.classList.add(match);
35
+ match = sizes.pop(); // skip to next match to remove these
34
36
  }
35
37
  break;
36
38
  }
@@ -40,7 +42,7 @@ this.simply = (function(simply, global) {
40
42
  if ( app.container.classList.contains(match)) {
41
43
  app.container.classList.remove(match);
42
44
  }
43
- match=sizes.pop();
45
+ match = sizes.pop();
44
46
  }
45
47
  var toolbars = app.container.querySelectorAll('.simply-toolbar');
46
48
  [].forEach.call(toolbars, function(toolbar) {
@@ -64,9 +66,15 @@ this.simply = (function(simply, global) {
64
66
  });
65
67
  }
66
68
 
67
- return resizeSniffer;
68
- };
69
+ return resizeSniffer;
70
+ };
69
71
 
70
- return simply;
71
-
72
- })(this.simply || {}, this);
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);