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.
- package/dist/simply.everything.js +105 -70
- package/js/simply.api.js +46 -47
- package/js/simply.keyboard.js +19 -2
- package/js/simply.route.js +18 -16
- package/js/simply.viewmodel.js +20 -5
- package/package.json +7 -2
- package/docs/examples.md +0 -82
- package/docs/readme.md +0 -33
- package/docs/simply.action.md +0 -42
- package/docs/simply.activate.md +0 -27
- package/docs/simply.api.md +0 -188
- package/docs/simply.app.md +0 -27
- package/docs/simply.collect.md +0 -64
- package/docs/simply.command.md +0 -110
- package/docs/simply.include.md +0 -61
- package/docs/simply.keyboard.md +0 -60
- package/docs/simply.path.md +0 -3
- package/docs/simply.route.md +0 -133
- package/docs/simply.view.md +0 -53
- package/docs/simply.viewmodel.md +0 -3
- package/examples/commands.html +0 -70
- package/examples/counter.html +0 -52
- package/examples/examples.css +0 -3
- package/examples/github.html +0 -39
- package/examples/githubv4.html +0 -107
- package/examples/graphql.html +0 -51
- package/examples/graphql.html~ +0 -35
- package/examples/include/fifth.js +0 -1
- package/examples/include/first.js +0 -1
- package/examples/include/include.html +0 -4
- package/examples/include/include2.html +0 -1
- package/examples/include/index.html +0 -18
- package/examples/include/scripts.html +0 -16
- package/examples/include/third.js +0 -3
- package/examples/keyboard.html +0 -41
- package/examples/todo.html +0 -48
- package/examples/viewmodel.html +0 -359
- package/make +0 -18
- package/make~ +0 -17
- package/package.json~ +0 -31
- package/test/simply.route.test.js +0 -102
package/docs/readme.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Introduction
|
|
2
|
-
|
|
3
|
-
SimplyView is a set of seperate components that allow you to rapidly build web
|
|
4
|
-
application user interfaces. They are designed to work with modern reactive
|
|
5
|
-
libraries, like that included in [SimplyEdit](https://simplyedit.io/).
|
|
6
|
-
|
|
7
|
-
SimplyView seperates structure - HTML - from behaviour - javascript. There is
|
|
8
|
-
never a need to write HTML inside your javascript code. There is also never a
|
|
9
|
-
need to write javascript - or any other kind of code - inside your HTML.
|
|
10
|
-
This strict seperation allows for a much easier workflow between designers and developers.
|
|
11
|
-
|
|
12
|
-
This seperation also makes it possible, even easy, to re-use and upgrade
|
|
13
|
-
existing web applications. There is no need to rewrite everthing from scratch.
|
|
14
|
-
SimplyView works well with jQuery. In rare cases you can use the simply.activate
|
|
15
|
-
component to make sure your legacy javascript can react to changes in the HTML
|
|
16
|
-
structure.
|
|
17
|
-
|
|
18
|
-
SimplyView is not a framework, but a selection of components. There is a
|
|
19
|
-
simply.app component which ties them all together, but you don't need it to
|
|
20
|
-
use any of them.
|
|
21
|
-
|
|
22
|
-
- [simply.app](simply.app.md)
|
|
23
|
-
- [simply.route](simply.route.md)
|
|
24
|
-
- [simply.command](simply.command.md)
|
|
25
|
-
- [simply.action](simply.action.md)
|
|
26
|
-
- [simply.collect](simply.collect.md)
|
|
27
|
-
- [simply.activate](simply.activate.md)
|
|
28
|
-
- [simply.include](simply.include.md)
|
|
29
|
-
- [simply.api](simply.api.md)
|
|
30
|
-
- [simply.viewmodel](simply.viewmodel.md)
|
|
31
|
-
- [simply.path](simply.path.md)
|
|
32
|
-
|
|
33
|
-
Here are [some examples](examples.md) that use parts of SimplyView.
|
package/docs/simply.action.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# simply.action
|
|
2
|
-
|
|
3
|
-
Actions are a standardized way to define a kind of API for your user
|
|
4
|
-
interface. They are meant to be used together with routes and commands.
|
|
5
|
-
|
|
6
|
-
In this case the routes and commands are tightly bound to your URL
|
|
7
|
-
structure and your HTML structure respectively.
|
|
8
|
-
|
|
9
|
-
Actions should be decoupled from those. An action should just be a method
|
|
10
|
-
that updates the application state. The parameters for an action should
|
|
11
|
-
be the logical parameters for that update.
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
var myApp = simply.app({
|
|
15
|
-
commands: {
|
|
16
|
-
addTodo: function(form, values) {
|
|
17
|
-
form.elements.todo.value = '';
|
|
18
|
-
this.app.actions.addTodo(values.todo);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
actions: {
|
|
23
|
-
addTodo: function(todo) {
|
|
24
|
-
this.app.view.todos.push(todo);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
By structuring your application in this way, it is easy to add different
|
|
31
|
-
user interface modes which accomplish the same action. So you can create a
|
|
32
|
-
route as well as a command, that both trigger the same action. Or later you
|
|
33
|
-
can add keyboard shortcuts or gestures, without having to copy the logic of
|
|
34
|
-
your action.
|
|
35
|
-
|
|
36
|
-
You can add actions later by just defining them in the actions object:
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
myApp.actions.anotherAction = function(...arguments) {
|
|
40
|
-
...
|
|
41
|
-
};
|
|
42
|
-
```
|
package/docs/simply.activate.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# simply.activate
|
|
2
|
-
|
|
3
|
-
simply.activate is a component to automatically initialize HTML elements with
|
|
4
|
-
javascript as they appear in the DOM.
|
|
5
|
-
|
|
6
|
-
```javascript
|
|
7
|
-
simply.activate.addListener('autosize',function() {
|
|
8
|
-
$.autosize(this);
|
|
9
|
-
});
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```html
|
|
13
|
-
<textarea data-simply-activate="autosize"></textarea>
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The `addListener` method takes two arguments, a name and a callback method.
|
|
17
|
-
The name is what you use in the html `data-simply-activate` attribute. The
|
|
18
|
-
callback method is then called whenever the DOM element with that attribute
|
|
19
|
-
is added to the dom. It is also called on load.
|
|
20
|
-
|
|
21
|
-
The callback method has no arguments, instead it is called on the DOM element
|
|
22
|
-
itself. `this` references the DOM element.
|
|
23
|
-
|
|
24
|
-
Now you can use any 'legacy' component, in this case a jQuery textarea
|
|
25
|
-
resizer, that needs to initialize HTML elements. Simply.activate will
|
|
26
|
-
trigger the initialization routine whenever the element is inserted into the
|
|
27
|
-
dom, no matter how or when this happens.
|
package/docs/simply.api.md
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# simply.api
|
|
2
|
-
|
|
3
|
-
Simply.api is a library that makes it easier to connect to online API's,
|
|
4
|
-
like REST or JSON-RPC api's. It contains a simplified fetch() method as well
|
|
5
|
-
as a proxy that allows you to call remote API's as if they were a local
|
|
6
|
-
library. E.g.:
|
|
7
|
-
|
|
8
|
-
```javascript
|
|
9
|
-
const githubApi = simply.api.proxy({
|
|
10
|
-
baseURL: 'https://api.github.com',
|
|
11
|
-
headers: {
|
|
12
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
13
|
-
'User-Agent': 'SimplyApi'
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
githubApi.users.poef()
|
|
18
|
-
.then(user => {
|
|
19
|
-
console.log(user);
|
|
20
|
-
});
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
The proxy() method returns an object that will create new proxy objects on
|
|
24
|
-
the fly for any property you access on it, like the 'users' property above.
|
|
25
|
-
When you call such a property as a function, the proxy object will convert
|
|
26
|
-
the property path to a URL and fetch it.
|
|
27
|
-
|
|
28
|
-
In this case the githubApi.users.poef() call is converted to a GET request
|
|
29
|
-
with the url: 'https://api.github.com/users/poef'.
|
|
30
|
-
|
|
31
|
-
You can also pass arguments to the method, by passing an object with key
|
|
32
|
-
value pairs:
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
githubApi.users.octocat.hovercard({
|
|
36
|
-
subject_type: 'repository',
|
|
37
|
-
subject_id: 1300192
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Which is converted in a fetch() request like this:
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
44
|
-
GET https://api.github.com/users/octocat/hovercard?subject_type=repository&subject_id=1300192
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
If you want to use a different HTTP Verb, like 'POST', add that as the last entry like
|
|
48
|
-
this:
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
githubApi.user.keys.post({
|
|
52
|
-
key: "mykey"
|
|
53
|
-
})
|
|
54
|
-
.then(result => {
|
|
55
|
-
console.log(result);
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
The default verb methods that simply.api understands are GET and POST. If
|
|
60
|
-
you need more, declare them in the options object under the 'verbs' key.
|
|
61
|
-
|
|
62
|
-
You can add any option recognized by the default fetch() api in the proxy
|
|
63
|
-
options object, see [the init property
|
|
64
|
-
here](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#parameters).
|
|
65
|
-
In addition the proxy recognizes these options:
|
|
66
|
-
|
|
67
|
-
- responseFormat
|
|
68
|
-
- paramsFormat
|
|
69
|
-
- verbs
|
|
70
|
-
- user and password
|
|
71
|
-
- handlers
|
|
72
|
-
|
|
73
|
-
## responseFormat
|
|
74
|
-
|
|
75
|
-
This declares the expected result format of the remote API. The valid
|
|
76
|
-
options are:
|
|
77
|
-
|
|
78
|
-
- text
|
|
79
|
-
- formData
|
|
80
|
-
- blob
|
|
81
|
-
- arrayBuffer
|
|
82
|
-
- unbuffered
|
|
83
|
-
- json
|
|
84
|
-
|
|
85
|
-
The default is 'json'. Unlike the standard fetch() api, simply.api.fetch
|
|
86
|
-
(used by the proxy object) automatically parses and returns the result, as a
|
|
87
|
-
Promise. If an error is returned - the response.ok flag is false - then it
|
|
88
|
-
will throw an error object with the status, message and full response
|
|
89
|
-
object.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
## paramsFormat
|
|
93
|
-
|
|
94
|
-
Available formats are:
|
|
95
|
-
- search
|
|
96
|
-
- formData
|
|
97
|
-
- json
|
|
98
|
-
|
|
99
|
-
When the fetch method is GET, the format is forced to 'search'.
|
|
100
|
-
|
|
101
|
-
### search
|
|
102
|
-
This option sets the parameter format for the remote API. When set to search,
|
|
103
|
-
the parameters are send as a url encoded parameters in the URL of the
|
|
104
|
-
request.
|
|
105
|
-
|
|
106
|
-
### formData
|
|
107
|
-
Sets the parameter format to the default formdata encoding, add the
|
|
108
|
-
parameters to the body of the request.
|
|
109
|
-
|
|
110
|
-
### json
|
|
111
|
-
Encodes the parameters as a json string and adds it to the body of the
|
|
112
|
-
request.
|
|
113
|
-
|
|
114
|
-
## verbs
|
|
115
|
-
|
|
116
|
-
By default simply.api.proxy understands the GET and POST verbs. You can add
|
|
117
|
-
more by setting this option, e.g:
|
|
118
|
-
|
|
119
|
-
```javascript
|
|
120
|
-
const githubApi = simply.api.proxy({
|
|
121
|
-
baseURL: 'https://api.github.com',
|
|
122
|
-
headers: {
|
|
123
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
124
|
-
'User-Agent': 'SimplyApi'
|
|
125
|
-
},
|
|
126
|
-
verbs: [ 'get', 'post', 'put', 'delete' ]
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Now you can call the put() and delete() methods on the proxy as well:
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
githubApi.user.following.octocat.delete();
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Note: the verb names are automatically uppercased when sent.
|
|
137
|
-
|
|
138
|
-
## user and password
|
|
139
|
-
|
|
140
|
-
If you set a user and password property in the options to simply.api.proxy,
|
|
141
|
-
these will be converted to a basic authentication header and added to each
|
|
142
|
-
request.
|
|
143
|
-
|
|
144
|
-
## handlers
|
|
145
|
-
|
|
146
|
-
Some API's require extra handling for requests or parsing of responses. You
|
|
147
|
-
can override or extend the default handlers here. The available handlers are:
|
|
148
|
-
|
|
149
|
-
- fetch
|
|
150
|
-
- result
|
|
151
|
-
- error
|
|
152
|
-
|
|
153
|
-
A minimal definition for these handlers that maintains the default behaviour
|
|
154
|
-
is:
|
|
155
|
-
|
|
156
|
-
```javascript
|
|
157
|
-
const githubApi = simply.api.proxy({
|
|
158
|
-
baseURL: 'https://api.github.com',
|
|
159
|
-
headers: {
|
|
160
|
-
'Accept': 'application/vnd.github.v3+json',
|
|
161
|
-
'User-Agent': 'SimplyApi'
|
|
162
|
-
},
|
|
163
|
-
verbs: [ 'get', 'post', 'put', 'delete' ],
|
|
164
|
-
handlers: {
|
|
165
|
-
fetch: function(verb, params, options) {
|
|
166
|
-
// prepare stuff here
|
|
167
|
-
return simply.api.fetch(verb, params, options)
|
|
168
|
-
.then(response => {
|
|
169
|
-
// do some more stuff here
|
|
170
|
-
return response;
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
result: function(result, options) {
|
|
174
|
-
// ditto
|
|
175
|
-
return simply.api.getResult(result, options)
|
|
176
|
-
.then(result => {
|
|
177
|
-
// more doing
|
|
178
|
-
return result;
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
error: function(error, options) {
|
|
182
|
-
// ...
|
|
183
|
-
simply.api.logError(error, options); // no return value here
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
```
|
|
188
|
-
|
package/docs/simply.app.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# simply.app
|
|
2
|
-
|
|
3
|
-
simply.app provides a simple starting point to build web applications:
|
|
4
|
-
|
|
5
|
-
```javascript
|
|
6
|
-
var myApp = simply.app({
|
|
7
|
-
routes: {
|
|
8
|
-
'/:section/': function(params) { ... }
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
commands: { ... },
|
|
12
|
-
|
|
13
|
-
actions: { ... },
|
|
14
|
-
|
|
15
|
-
container: document.getElementById('myApp'),
|
|
16
|
-
|
|
17
|
-
view: {
|
|
18
|
-
myVariable: 'foo'
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
It combines [simply.route](simply.route.md),
|
|
26
|
-
[simply.command](simply.command.md), [simply.action](simply.action.md) and
|
|
27
|
-
[simply.view](simply.view.md) into a single application wrapper.
|
package/docs/simply.collect.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# simply.collect
|
|
2
|
-
|
|
3
|
-
simply.collect allows you to create auto updating forms, just by adding a few
|
|
4
|
-
attributes to the form and its elements:
|
|
5
|
-
|
|
6
|
-
```javascript
|
|
7
|
-
function getAddress(elements) {
|
|
8
|
-
if (elements.zipcode.value && elements.housenr.value) {
|
|
9
|
-
zipcodeAPI
|
|
10
|
-
.getAddress(elements.zipcode.value,elements.country.value)
|
|
11
|
-
.then(function(address) {
|
|
12
|
-
elements.street.value = address.street;
|
|
13
|
-
elements.city.value = address.city;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
simply.collect.addListener('address', getAddress);
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
```html
|
|
22
|
-
<form>
|
|
23
|
-
<div data-simply-collect="address">
|
|
24
|
-
<label>
|
|
25
|
-
Zipcode: <input name="zipcode" data-simply-element="zipcode">
|
|
26
|
-
</label>
|
|
27
|
-
<label>
|
|
28
|
-
House NR: <input name="housenumber" data-simply-element="housenr">
|
|
29
|
-
</label>
|
|
30
|
-
<label>
|
|
31
|
-
Street: <input name="street" data-simply-element="street">
|
|
32
|
-
</label>
|
|
33
|
-
<label>
|
|
34
|
-
City: <input name="city" data-simply-element="city">
|
|
35
|
-
</label>
|
|
36
|
-
</div>
|
|
37
|
-
</form>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
The listener will get called whenever any of the elements changes. You can add
|
|
41
|
-
as many forms and as many container elements with data-simply-collect as you want.
|
|
42
|
-
|
|
43
|
-
## simply.collect.addListener
|
|
44
|
-
|
|
45
|
-
Add a collect listener. See the code above in the overview.
|
|
46
|
-
|
|
47
|
-
## simply.collect.removeListener
|
|
48
|
-
|
|
49
|
-
Removes a previously added listener. You must call removeListener with the
|
|
50
|
-
exact same name and function as used in addListener:
|
|
51
|
-
|
|
52
|
-
```javascript
|
|
53
|
-
simply.collect.removeListener('address', getAddress);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## simply.collect.update
|
|
57
|
-
|
|
58
|
-
simply.collect only listens for the change event. So if you update an input
|
|
59
|
-
elements value through javascript, the collect listeners won't trigger, unless
|
|
60
|
-
you also trigger the change event. simply.collect.update does this for you:
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
simply.collect.update(form.elements.zipcode, newZipcode);
|
|
64
|
-
```
|
package/docs/simply.command.md
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# simply.command
|
|
2
|
-
|
|
3
|
-
simply.command provides a way to tie behaviour (javascript code) to HTML
|
|
4
|
-
elements:
|
|
5
|
-
```html
|
|
6
|
-
<button data-simply-command="doSomething">does something</button>
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
Commands can be set on any HTML element, but the behaviour differs based on
|
|
10
|
-
the element type:
|
|
11
|
-
|
|
12
|
-
- BUTTON, A:
|
|
13
|
-
Command triggers on click. Value is copied from the data-simply-value attribute.
|
|
14
|
-
- INPUT, TEXTAREA, SELECT:
|
|
15
|
-
Command triggers on change. Value is copied from the input value.
|
|
16
|
-
- FORM:
|
|
17
|
-
Command triggers on submit. Value is the set of form values.
|
|
18
|
-
- All others:
|
|
19
|
-
Command triggers on click. Value is copied from the data-simply-value
|
|
20
|
-
attribute. Only runs if no other command handlers match.
|
|
21
|
-
|
|
22
|
-
If a command is triggered, the default event handler is cancelled. So links
|
|
23
|
-
aren't followed, forms aren't submitted, etc.
|
|
24
|
-
|
|
25
|
-
Initialize the commands like this:
|
|
26
|
-
|
|
27
|
-
```javascript
|
|
28
|
-
var commands = simply.command(myApp, {
|
|
29
|
-
myCommand: function(el, value) {
|
|
30
|
-
doSomething(value);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
For basic applications, commands are sufficient. But once your application
|
|
36
|
-
gets more complex it pays to limit the code in commands to just the parts that
|
|
37
|
-
tie into the HTML structure of your application. So searching the DOM,
|
|
38
|
-
getting attribute values, etc.
|
|
39
|
-
|
|
40
|
-
Once that is done, you should call an internal function that doesn't know
|
|
41
|
-
anything about the exact HTML structure. [simply.action](simply.action.md)
|
|
42
|
-
is purpose build to be used in that way. The Todo example shows how you can use this.
|
|
43
|
-
|
|
44
|
-
## commands.action
|
|
45
|
-
|
|
46
|
-
Each command function runs with the commands object returned from
|
|
47
|
-
simply.command as its scope. The action method is a useful shortcut to app.actions:
|
|
48
|
-
|
|
49
|
-
```javascript
|
|
50
|
-
var myApp = simply.app({
|
|
51
|
-
commands: {
|
|
52
|
-
addTodo: function(form, values) {
|
|
53
|
-
form.elements.todo.value = '';
|
|
54
|
-
this.action.call('addTodo', values.todo);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
actions: {
|
|
59
|
-
addTodo: function(todo) {
|
|
60
|
-
this.app.view.todos.push(todo);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
The same thing can also be accomplished like this:
|
|
67
|
-
```javascript
|
|
68
|
-
this.app.actions.addTodo(values.todo);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## commands.call
|
|
72
|
-
|
|
73
|
-
Allows you to call a command directly:
|
|
74
|
-
```javascript
|
|
75
|
-
myApp.commands.call('addTodo', el, value);
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## commands.appendHandler
|
|
79
|
-
|
|
80
|
-
Adds a command handler on top of the existing ones, so it gets matched first.
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
myApp.commands.appendHandler({
|
|
84
|
-
match: 'input[type="radio"]',
|
|
85
|
-
|
|
86
|
-
check: function(el, evt) {
|
|
87
|
-
return (evt.type=='change');
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
get: function(el) {
|
|
91
|
-
return el.dataset.simplyValue || el.value;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Handler properties:
|
|
97
|
-
|
|
98
|
-
- match:
|
|
99
|
-
A CSS selector that checks if an element is handled by this command handler.
|
|
100
|
-
- check:
|
|
101
|
-
A function that checks if the command should be run in this event.
|
|
102
|
-
- get:
|
|
103
|
-
A function that returns the value for this command.
|
|
104
|
-
|
|
105
|
-
## commands.prependHandler
|
|
106
|
-
|
|
107
|
-
Adds a command handler, just like appendHandler. But it adds it first in the
|
|
108
|
-
list, so it will be matched last. This way you can add handlers with a more
|
|
109
|
-
generic CSS selector and append more specific handlers.
|
|
110
|
-
|
package/docs/simply.include.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# simply.include
|
|
2
|
-
|
|
3
|
-
simply.include is a component that allows you to include external HTML - with
|
|
4
|
-
CSS and javascript - in the current HTML document. You will need to make sure
|
|
5
|
-
you don't overwrite global variables, the javascript and css get applied to
|
|
6
|
-
the whole document.
|
|
7
|
-
|
|
8
|
-
This component makes it easy to create microfrontends for microservices,
|
|
9
|
-
without forcing you to use a specific framework or technology.
|
|
10
|
-
|
|
11
|
-
Start by including the simply.include script, or simply.everything.js:
|
|
12
|
-
|
|
13
|
-
```html
|
|
14
|
-
<script src="js/simply.everything.js"></script>
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Then add a simply-include link at the exact spot where you want to include a
|
|
18
|
-
widget or application or just a piece of HTML:
|
|
19
|
-
|
|
20
|
-
```html
|
|
21
|
-
<link rel="simply-include" href="/simplyview/widgets/my-widget/index.html"></link>
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Your widget may contain any HTML, CSS and javascript you like, except it
|
|
25
|
-
shouldn't contain a HEAD. So a widget might look like this:
|
|
26
|
-
|
|
27
|
-
```html
|
|
28
|
-
<script src="/simplyview/js/simply.everything.js"></script>
|
|
29
|
-
<link rel="simply-include-once" href="/simplyview/common/head.html">
|
|
30
|
-
<link rel="simply-include-once" href="/simplyview/common/menu.html">
|
|
31
|
-
<link rel="stylesheet" href="/simplyview/widgets/my-widget/style.css">
|
|
32
|
-
<div class="my-widget">
|
|
33
|
-
....
|
|
34
|
-
</div>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
The widget includes some common HTML, but only if it wasn't included before.
|
|
38
|
-
Assuming your pages all include the common head and menu, the widget will skip
|
|
39
|
-
this if the widget is included in a page. However you can also call the widget
|
|
40
|
-
as a normal page. In that case the common head and menu will be included and
|
|
41
|
-
the widget will decorate itself with the default styling and menu.
|
|
42
|
-
|
|
43
|
-
simply.include will automatically detect `<link rel="simply-include(-once)">`
|
|
44
|
-
links in the DOM, no matter when and how they appear, and replace them with
|
|
45
|
-
the HTML fetched from the linked href.
|
|
46
|
-
|
|
47
|
-
## Security
|
|
48
|
-
|
|
49
|
-
simply.include is meant to include HTML with CSS and javascript into an
|
|
50
|
-
existing document. So you must take care that whatever you include is what you
|
|
51
|
-
meant to include. If you allow user input, you must make sure that it doesn't
|
|
52
|
-
have `<link rel="simply-include(-once)">` tags. Or that if they do, they won't
|
|
53
|
-
get executed.
|
|
54
|
-
|
|
55
|
-
As a baseline, always clean user input of any offending tags, or even better:
|
|
56
|
-
clean it of all HTML. If that can't be done, make sure you use a whitelist of
|
|
57
|
-
acceptable tags.
|
|
58
|
-
|
|
59
|
-
Finally as a catchall, use Content-Security-Policy headers to only allow script
|
|
60
|
-
execution of whitelisted URL's. Don't allow inline scripts or you will still
|
|
61
|
-
be open to Cross Site Scripting attacks (XSS).
|
package/docs/simply.keyboard.md
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# simply.keyboard
|
|
2
|
-
|
|
3
|
-
simply.keyboard is a simple library to add keyboard support to your application:
|
|
4
|
-
|
|
5
|
-
```javascript
|
|
6
|
-
let myKeys = {
|
|
7
|
-
default: {
|
|
8
|
-
ArrowDown: (e) => {
|
|
9
|
-
// handle arrow down
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
simply.keyboard(myApp, myKeys);
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
But generally you won't use this directly, but through simply.app:
|
|
17
|
-
|
|
18
|
-
```javascript
|
|
19
|
-
var myApp = simply.app({
|
|
20
|
-
keyboard: {
|
|
21
|
-
default: {
|
|
22
|
-
ArrowDown: (e) => {
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
You can add multiple keyboard definitions:
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
var counterApp = simply.app({
|
|
34
|
-
keyboard: {
|
|
35
|
-
default: {
|
|
36
|
-
ArrowDown: (e) => {
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
alternate: {
|
|
41
|
-
ArrowDown: (e) => {
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
The default keyboard is 'default', but you can switch the keyboard by setting this attribute:
|
|
50
|
-
|
|
51
|
-
```html
|
|
52
|
-
<div data-simply-keyboard="alternate">
|
|
53
|
-
<input type="text" name="example">
|
|
54
|
-
</div>
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Whenever a keyboard `keydown` is fired, simply.keyboard will look for the closest parent with a `data-simply-keyboard` attribute. If found, it will use that keyboard definition. If not found, it will use `default`.
|
|
58
|
-
|
|
59
|
-
The `keydown` event is only handled if the activeElement (the element that has focus) is inside the application container. See `simply.app` for more on that.
|
|
60
|
-
|
package/docs/simply.path.md
DELETED