simplyview 2.0.2 → 2.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.
Files changed (41) hide show
  1. package/dist/simply.everything.js +105 -70
  2. package/js/simply.api.js +46 -47
  3. package/js/simply.keyboard.js +19 -2
  4. package/js/simply.route.js +18 -16
  5. package/js/simply.viewmodel.js +20 -5
  6. package/package.json +7 -2
  7. package/docs/examples.md +0 -82
  8. package/docs/readme.md +0 -33
  9. package/docs/simply.action.md +0 -42
  10. package/docs/simply.activate.md +0 -27
  11. package/docs/simply.api.md +0 -188
  12. package/docs/simply.app.md +0 -27
  13. package/docs/simply.collect.md +0 -64
  14. package/docs/simply.command.md +0 -110
  15. package/docs/simply.include.md +0 -61
  16. package/docs/simply.keyboard.md +0 -60
  17. package/docs/simply.path.md +0 -3
  18. package/docs/simply.route.md +0 -133
  19. package/docs/simply.view.md +0 -53
  20. package/docs/simply.viewmodel.md +0 -3
  21. package/examples/commands.html +0 -70
  22. package/examples/counter.html +0 -52
  23. package/examples/examples.css +0 -3
  24. package/examples/github.html +0 -39
  25. package/examples/githubv4.html +0 -107
  26. package/examples/graphql.html +0 -51
  27. package/examples/graphql.html~ +0 -35
  28. package/examples/include/fifth.js +0 -1
  29. package/examples/include/first.js +0 -1
  30. package/examples/include/include.html +0 -4
  31. package/examples/include/include2.html +0 -1
  32. package/examples/include/index.html +0 -18
  33. package/examples/include/scripts.html +0 -16
  34. package/examples/include/third.js +0 -3
  35. package/examples/keyboard.html +0 -41
  36. package/examples/todo.html +0 -48
  37. package/examples/viewmodel.html +0 -359
  38. package/make +0 -18
  39. package/make~ +0 -17
  40. package/package.json~ +0 -31
  41. package/test/simply.route.test.js +0 -102
@@ -1,133 +0,0 @@
1
- # simply.route
2
-
3
- simply.route is a simple url routing component. It will listen to URL changes
4
- and match them against the routes you provide. If a match is found, it will
5
- call the matching function and update the address bar without reloading.
6
-
7
- simply.route will run the first matching route handler it finds, in the order
8
- in which they were registered.
9
-
10
- Each route is a function with a single argument: `params`. Each variable you
11
- define in the route, like `:section`, is translated into a property of the
12
- params object, e.g. `params.section`. If you add a `:*` at the end of the route
13
- it will be translated to `params.remainder`.
14
-
15
- simply.route also supports events that trigger either before route matching,
16
- before route calling or after a route is called.
17
-
18
- If you need more complex behaviour, you should replace simply.route with a
19
- different library. simply.route is explicitly meant to be a simple library
20
- that is sufficient for 90% of javascript applications.
21
-
22
- ## simply.route.load
23
-
24
- ```javascript
25
- simply.route.load({
26
-
27
- '/:section/:*': function(params) {
28
- loadSection(params.section, params.remainder);
29
- },
30
-
31
- '/': function() {
32
- loadHome();
33
- }
34
- });
35
- ```
36
-
37
- ## simply.route.match
38
-
39
- ```javascript
40
- simply.route.match(path);
41
- ```
42
-
43
- This allows you to trigger a route. You can also provide extra parameters
44
- for the route handler:
45
-
46
- ```javascript
47
- simply.route.match(path, { foo: 'bar' });
48
- ```
49
-
50
- ## simply.route.goto
51
-
52
- Updates the browsers address bar and matches the path.
53
-
54
- ```javascript
55
- simply.route.goto(path);
56
- ```
57
-
58
- ## simply.route.has
59
-
60
- Returns true if the route is registered.
61
-
62
- ```javascript
63
- if (simply.route.has(path)) { ... }
64
- ```
65
-
66
- ## simply.route.init
67
-
68
- Allows you to set the root pathname for routing. The root pathname is prepended
69
- on every route you define. So if your application lives in the '/hnpwa/'
70
- directory in the document root of you website, init simply.route like this:
71
-
72
- ```javascript
73
- simply.route.init({
74
- root: '/hnpwa/'
75
- });
76
- ````
77
-
78
- ## simply.route.addListener
79
-
80
- In the normal route handling, once a matching route is found, simply.route calls
81
- it and stops. But sometimes you may want to trigger some code for multiple routes.
82
- With route listeners you can do just that. You can setup a function that will be
83
- called either before a route is found (`match`), before it is called (`call`) or after
84
- it is called (`finish`).
85
-
86
- In each of these steps you may change the default behaviour of simply.route by altering
87
- parameters passed to your listener function and returning them.
88
-
89
- ### match
90
-
91
- This allows you to add complex behaviour to the route matching step, so you can for
92
- example match multiple different URL's to a single route. The single parameter is the
93
- path to match on:
94
-
95
- ```
96
- simply.route.addListener('match', '/protected/', function(params) {
97
- // assume user is a variable in scope
98
- if (!user || !user.isLoggedIn ) {
99
- return {
100
- path: '/login/'
101
- };
102
- }
103
- });
104
- ```
105
-
106
- ### call
107
-
108
- This allows you to change parameters before the actual route function is called.
109
-
110
- ```
111
- simply.route.addListener('call', '/foo/', function(params) {
112
- params.foo = 'bar';
113
- return params;
114
- });
115
- ```
116
-
117
- ### finish
118
-
119
- This allows you to do stuff after a route is called. You can also change the result
120
- of the route, though that is usually not a good idea.
121
-
122
- ## simply.route.removeListener
123
-
124
- This allows you to remove a route listener. You need to exactly match the fase of the
125
- listener (`match`, `call` or `finish`), the route and the function:
126
-
127
- ```javascript
128
- simply.route.removeListener('call', '/foo/', fooListener);
129
- ```
130
-
131
- ## simply.route.clear
132
-
133
- Removes all routes and listeners globally.
@@ -1,53 +0,0 @@
1
- # simply.view
2
-
3
- simply.view provides a simple interface to use the databinding from
4
- [SimplyEdit](https://simplyedit.io/) in a web application:
5
-
6
- ```javascript
7
- var myView = {
8
- foo: 'bar'
9
- };
10
-
11
- simply.view(myApp, myView);
12
- ```
13
-
14
- But generally you won't use this directly, but through simply.app:
15
-
16
- ```javascript
17
- var counterApp = simply.app({
18
- view: {
19
- counter: 1
20
- }
21
- });
22
- ```
23
-
24
- Any data-simply-field you define in your apps HTML is automatically bound to the corresponding entry in the view.
25
-
26
- ## Example
27
-
28
- A simple example - an app that can count up and down:
29
-
30
- ```html
31
- <div id="counter">
32
- <input type="text" data-simply-field="counter">
33
- <button data-simply-command="add1">+</button>
34
- <button data-simply-command="sub1">-</button>
35
- </div>
36
- ```
37
-
38
- ```javascript
39
- var counterApp = simply.app({
40
-
41
- container: document.getElementById('counter'),
42
-
43
- commands: {
44
- add1: function() { this.app.view.counter++; },
45
- sub1: function() { this.app.view.counter--; }
46
- },
47
-
48
- view: {
49
- counter: 0
50
- }
51
-
52
- };
53
- ```
@@ -1,3 +0,0 @@
1
- # simply.viewmodel.md
2
-
3
- TODO
@@ -1,70 +0,0 @@
1
-
2
- <!doctype html>
3
- <body>
4
-
5
- <label>testSubmit:</label>
6
- <form data-simply-command="testSubmit">
7
- <div>
8
- <label>
9
- testChange:
10
- <input type="text" name="a" data-simply-command="testChange">
11
- </label>
12
- </div>
13
- <div>
14
- <label>
15
- testChange:
16
- <select name="b" data-simply-command="testChange">
17
- <option>foo</option>
18
- <option>bar</option>
19
- </select>
20
- </label>
21
- </div>
22
- <div>
23
- <label>
24
- testChange:
25
- <textarea name="c" data-simply-command="testChange"></textarea>
26
- </label>
27
- </div>
28
- <div>
29
- <label>
30
- testInput:
31
- <input type="text" name="d" data-simply-command="testInput" data-simply-immediate="true">
32
- </label>
33
- </div>
34
- <button type="submit">Submit</button>
35
- </form>
36
- <div><a href="foo" data-simply-command="testClick">testClick A</a></div>
37
- <div><button data-simply-command="testClick" data-simply-value="bar">testClick Button</button></div>
38
-
39
- <pre data-simply-field="out"></pre>
40
-
41
- <script src="../dist/simply.everything.js"></script>
42
-
43
- <script>
44
- var test = simply.app({
45
- view: {
46
- out: 'start'
47
- }
48
- });
49
-
50
- test.commands.testChange = function(el, value) {
51
- test.view.out = el.name+': '+value;
52
- };
53
-
54
- test.commands.testSubmit = function(form, values) {
55
- var out = [];
56
- for (var key of Object.keys(values)) {
57
- out.push(key+': '+values[key]);
58
- }
59
- test.view.out = out.join('\n');
60
- }
61
-
62
- test.commands.testInput = function(el, value) {
63
- test.view.out = el.name + ': '+value;
64
- }
65
-
66
- test.commands.testClick = function(el, value) {
67
- test.view.out = el.tagName + ': '+value;
68
- }
69
- </script>
70
- </body>
@@ -1,52 +0,0 @@
1
- <h1>Examples</h1>
2
- <h2>Counter</h2>
3
- <link rel="stylesheet" href="examples.css">
4
-
5
- <div id="counterApp">
6
- <input type="text" data-simply-field="counter">
7
- <button data-simply-command="add1">+</button>
8
- <button data-simply-command="sub1">-</button>
9
- <div>Counter is now: <span data-simply-field="counter"></span></div>
10
- </div>
11
-
12
- <div id="counterApp2">
13
- <input type="text" data-simply-field="counter">
14
- <button data-simply-command="add1">+</button>
15
- <button data-simply-command="sub1">-</button>
16
- <div>Counter is now: <span data-simply-field="counter"></span></div>
17
- </div>
18
-
19
- <script src="//cdn.simplyedit.io/1/simply-edit.js"></script>
20
- <script src="../dist/simply.everything.js"></script>
21
- <script>
22
- var counterApp = simply.app({
23
- container: document.getElementById('counterApp'),
24
- commands: {
25
- add1: function() {
26
- counterApp.view.counter++;
27
- },
28
- sub1: function() {
29
- counterApp.view.counter--;
30
- }
31
- },
32
- view: {
33
- counter: 1
34
- }
35
- });
36
-
37
- var counterApp2 = simply.app({
38
- container: document.getElementById('counterApp2'),
39
- commands: {
40
- add1: function() {
41
- counterApp2.view.counter++;
42
- },
43
- sub1: function() {
44
- counterApp2.view.counter--;
45
- }
46
- },
47
- view: {
48
- counter: 2
49
- }
50
- });
51
-
52
- </script>
@@ -1,3 +0,0 @@
1
- html, body {
2
- font-family: arial, helvetica, sans-serif;
3
- }
@@ -1,39 +0,0 @@
1
- <!doctype html>
2
- <meta charset="utf-8">
3
- <pre id="output"></pre>
4
- <script src="../dist/simply.everything.js"></script>
5
- <script src="../js/simply.api.js"></script>
6
- <script>
7
- var githubApi = simply.api.proxy({
8
- baseURL: 'https://api.github.com',
9
- headers: {
10
- 'Accept': 'application/vnd.github.v3+json',
11
- 'User-Agent': 'poef'
12
- },
13
- handlers: {
14
- fetch: function(verb, params, options) {
15
- console.log(verb, params, options);
16
- return simply.api.fetch(verb, params, options)
17
- .then(function(response) {
18
- console.log(response,[...response.headers.entries()].map((h) => h[0]+': '+h[1]));
19
- return response;
20
- });
21
- },
22
- result: function(result, options) {
23
- return simply.api.getResult(result, options)
24
- .then(function(result) {
25
- console.log(result);
26
- return result;
27
- });
28
- }
29
- }
30
- });
31
-
32
- githubApi.users.poef().then(function(user) {
33
- document.getElementById('output').innerText = JSON.stringify(user,
34
- null, 4);
35
- });
36
-
37
- githubApi.test = 'test';
38
- console.log(githubApi.test);
39
- </script>
@@ -1,107 +0,0 @@
1
- <!doctype html>
2
- <meta charset="utf-8">
3
- <pre id="output"></pre>
4
- <script src="../dist/simply.everything.js"></script>
5
- <script src="../js/simply.api.js"></script>
6
- <h1>Github repo browser</h1>
7
- <form data-simply-command="showRepo">
8
- <label>Owner
9
- <input type="text" name="owner">
10
- </label>
11
- <label>Repository
12
- <input type="text" name="repo">
13
- </label>
14
- <label>Application token
15
- <input type="text" name="token">
16
- </label>
17
- <button type="submit">OK</button>
18
- </form>
19
- <main>
20
- <h2 data-simply-field="repo.name"></h2>
21
- <div data-simply-field="repo.description"></div>
22
- <ul data-simply-list="repo.files.entries">
23
- <template>
24
- <li><span data-simply-field="name"></span></li>
25
- </template>
26
- </ul>
27
- </main>
28
- <script>
29
- simply.bind = false;
30
- document.addEventListener('simply-content-loaded', function() {
31
- editor.pageData.repo = {
32
- name: "foo",
33
- files: {
34
- entries: [
35
- {
36
- name: 'barf'
37
- }
38
- ]
39
- }
40
- };
41
- return;
42
- });
43
-
44
-
45
- var githubURL = 'https://api.github.com/graphql';
46
- var githubToken = 'af948d67c63a2f9f940e0b0be7a2d5ff3446327f';
47
- var github = {
48
- repository: simply.api.graphqlQuery(
49
- githubURL,
50
- `query($owner:String!, $repo:String!) {
51
- repository(name:$repo, owner:$owner) {
52
- id
53
- name
54
- description
55
- files: object(expression: "master:") {
56
- ... on Tree {
57
- entries {
58
- oid
59
- name
60
- type
61
- }
62
- }
63
-
64
- }
65
- }
66
- }`,
67
- {
68
- headers: { Authorization: 'bearer '+githubToken },
69
- responseResult: 'data.repository',
70
- responseErrors: 'errors'
71
- }
72
- )
73
- };
74
- /*
75
- github.repository({
76
- login: 'poef',
77
- repo: 'arc-web'
78
- }).then(function(data) {
79
- document.getElementById('output').innerText = JSON.stringify(data,
80
- null, 4);
81
- });
82
-
83
- async function foo() {
84
- var foo = await github.repository({ login: 'poef', repo: 'arc-web'});
85
- console.log(foo);
86
- };
87
- foo();
88
- */
89
- var githubBrowser = simply.app({
90
- commands: {
91
- 'showRepo': function(form, values) {
92
- if (values.token) {
93
- githubToken = values.token;
94
- }
95
- github.repository({
96
- owner: values.owner,
97
- repo: values.repo
98
- })
99
- .then(function(data) {
100
- githubBrowser.view.repo = data.data.repository;
101
- });
102
- }
103
- }
104
- })
105
-
106
- </script>
107
- <script src="//cdn.simplyedit.io/1/simply-edit.js"></script>
@@ -1,51 +0,0 @@
1
- <!doctype html>
2
- <ul data-simply-list="vakleergebieden">
3
- <template>
4
- <li><span data-simply-field="title"></span></li>
5
- </template>
6
- </ul>
7
- <script src="//cdn.simplyedit.io/1/simply-edit.js" data-storage="none"></script>
8
- <script src="../dist/simply.everything.js"></script>
9
- <script>
10
- var baseURL = '//localhost:3000/';
11
-
12
- var app = simply.app({
13
- routes: {
14
- '/:*': function() {
15
- api.Vakleergebied().then(result => {
16
- app.view.vakleergebieden = result.data.allVakleergebied;
17
- });
18
- }
19
- },
20
- view: {
21
- vakleergebieden: []
22
- }
23
- });
24
-
25
- var api = simply.api.proxy({
26
- baseURL: baseURL
27
- });
28
-
29
- api.Vakleergebied = simply.api.graphqlQuery(baseURL,
30
- 'Vakleergebied',
31
- `fragment NiveauShort on Niveau {
32
- id
33
- title
34
- prefix
35
- }
36
- query Vakleergebied($page:Int,$perPage:Int) {
37
- allVakleergebied(page:$page,perPage:$perPage,sortField:"title") {
38
- id
39
- prefix
40
- title
41
- prefix
42
- Niveau {
43
- ...NiveauShort
44
- }
45
- }
46
- _allVakleergebiedMeta {
47
- count
48
- }
49
- }`);
50
-
51
- </script>
@@ -1,35 +0,0 @@
1
- <!doctype html>
2
- <script src="//cdn.simplyedit.io/1/simply-edit.js" data-storage="none"></script>
3
- <script src="../dist/simply.everything.js"></script>
4
- <script>
5
- var baseURL = '//localhost:3000/';
6
-
7
- var api = simply.api.proxy({
8
- baseURL: baseURL
9
- });
10
-
11
- api.Vakleergebied = simply.api.graphqlQuery(baseURL,
12
- 'Vakleergebied',
13
- `fragment NiveauShort on Niveau {
14
- id
15
- title
16
- prefix
17
- }
18
- query Vakleergebied($page:Int,$perPage:Int) {
19
- allVakleergebied(page:$page,perPage:$perPage,sortField:"title") {
20
- id
21
- prefix
22
- title
23
- prefix
24
- Niveau {
25
- ...NiveauShort
26
- }
27
- }
28
- _allVakleergebiedMeta {
29
- count
30
- }
31
- }`);
32
-
33
- api.Vakleergebied()
34
- .then(result => console.log(result));
35
- </script>
@@ -1 +0,0 @@
1
- console.log('fifth');
@@ -1 +0,0 @@
1
- console.log('first');
@@ -1,4 +0,0 @@
1
- <h1>Basic includes work</h1>
2
- <textarea class="autosize" data-simply-activate="autosize">include</textarea>
3
- <link rel="simply-include-once" href="include2.html">
4
- <link rel="simply-include-once" href="include2.html">
@@ -1 +0,0 @@
1
- <h2>Sub includes work as well</h2>
@@ -1,18 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <script src="../../dist/simply.everything.js"></script>
5
- </head>
6
- <body>
7
- <link rel="simply-include" href="include.html">
8
- <textarea class="autosize" data-simply-activate="autosize">index</textarea>
9
- <link rel="simply-include" href="scripts.html">
10
- <p>Done.</p>
11
- <script>
12
- simply.activate.addListener('autosize', function() {
13
- this.value="activated";
14
- console.log('activate', this)
15
- });
16
- </script>
17
- </body>
18
- </html>
@@ -1,16 +0,0 @@
1
- <script src="first.js"></script>
2
- <script>
3
- console.log('second');
4
- </script>
5
- <script src="third.js"></script>
6
- <script>
7
- console.log('after third');
8
- </script>
9
- <script>
10
- console.log('fourth');
11
- </script>
12
- <script src="fifth.js"></script>
13
- <script src="//cdn.simplyedit.io/1/simply-edit.js"></script>
14
- <script>
15
- console.log(editor);
16
- </script>
@@ -1,3 +0,0 @@
1
- for (var i=0; i<100000000; i++) {
2
- }
3
- console.log('third');
@@ -1,41 +0,0 @@
1
- <h1>Examples</h1>
2
- <h2>Keyboard</h2>
3
- <link rel="stylesheet" href="examples.css">
4
-
5
- <div id="myApp">
6
- <input type="text" data-simply-field="counter">
7
- <button data-simply-command="add1">+</button>
8
- <button data-simply-command="sub1">-</button>
9
- <div>Counter is now: <span data-simply-field="counter"></span></div>
10
- </div>
11
-
12
- <script src="../dist/simply.everything.js"></script>
13
- <script src="//cdn.simplyedit.io/1/simply-edit.js"></script>
14
- <script>
15
- var myApp = simply.app({
16
- container: document.getElementById('myApp'),
17
- keyboard: {
18
- default: {
19
- ArrowDown: function(e) {
20
- this.view.counter--;
21
- e.preventDefault();
22
- },
23
- ArrowUp: function(e) {
24
- this.view.counter++;
25
- e.preventDefault();
26
- }
27
- }
28
- },
29
- commands: {
30
- add1: function(el, value) {
31
- this.app.view.counter++;
32
- },
33
- sub1: function(el, value) {
34
- this.app.view.counter--;
35
- }
36
- },
37
- view: {
38
- counter: 1
39
- }
40
- });
41
- </script>