simplyview 2.0.1 → 2.0.3
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 +128 -64
- package/docs/simply.keyboard.md +60 -0
- package/examples/counter.html +1 -0
- package/js/simply.api.js +46 -47
- package/js/simply.app.js +2 -1
- package/js/simply.keyboard.js +62 -0
- package/js/simply.route.js +18 -16
- package/make +1 -0
- package/package.json +1 -1
- package/examples/githubv4.html +0 -107
- package/examples/graphql.html +0 -51
- package/examples/graphql.html~ +0 -35
- package/js/simply.api.js~ +0 -225
- package/package.json~ +0 -31
|
@@ -639,8 +639,8 @@ properties for a given parent, keep seperate index for this?
|
|
|
639
639
|
handleEvents: function() {
|
|
640
640
|
global.addEventListener('popstate', function() {
|
|
641
641
|
if (route.match(getPath(document.location.pathname + document.location.hash)) === false) {
|
|
642
|
-
|
|
643
|
-
|
|
642
|
+
route.match(getPath(document.location.pathname));
|
|
643
|
+
}
|
|
644
644
|
});
|
|
645
645
|
global.document.addEventListener('click', linkHandler);
|
|
646
646
|
},
|
|
@@ -665,22 +665,24 @@ properties for a given parent, keep seperate index for this?
|
|
|
665
665
|
|
|
666
666
|
var matches;
|
|
667
667
|
if (!path) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
668
|
+
if (route.match(document.location.pathname+document.location.hash)) {
|
|
669
|
+
return true;
|
|
670
|
+
} else {
|
|
671
|
+
return route.match(document.location.pathname);
|
|
672
|
+
}
|
|
673
673
|
}
|
|
674
674
|
path = getPath(path);
|
|
675
675
|
for ( var i=0; i<routeInfo.length; i++) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if (
|
|
679
|
-
path
|
|
680
|
-
|
|
676
|
+
matches = routeInfo[i].match.exec(path);
|
|
677
|
+
if (!matches || !matches.length) {
|
|
678
|
+
if (path && path[path.length-1]!='/') {
|
|
679
|
+
matches = routeInfo[i].match.exec(path+'/');
|
|
680
|
+
if (matches) {
|
|
681
|
+
path+='/';
|
|
682
|
+
history.replaceState({}, '', getUrl(path));
|
|
683
|
+
}
|
|
681
684
|
}
|
|
682
685
|
}
|
|
683
|
-
matches = routeInfo[i].match.exec(path);
|
|
684
686
|
if (matches && matches.length) {
|
|
685
687
|
var params = {};
|
|
686
688
|
routeInfo[i].params.forEach(function(key, i) {
|
|
@@ -697,9 +699,9 @@ properties for a given parent, keep seperate index for this?
|
|
|
697
699
|
args.result = routeInfo[i].action.call(route, params);
|
|
698
700
|
runListeners('finish', args);
|
|
699
701
|
return args.result;
|
|
700
|
-
|
|
702
|
+
}
|
|
701
703
|
}
|
|
702
|
-
|
|
704
|
+
return false;
|
|
703
705
|
},
|
|
704
706
|
goto: function(path) {
|
|
705
707
|
history.pushState({},'',getUrl(path));
|
|
@@ -734,7 +736,7 @@ properties for a given parent, keep seperate index for this?
|
|
|
734
736
|
listeners[action][route] = listeners[action][route].filter(function(listener) {
|
|
735
737
|
return listener != callback;
|
|
736
738
|
});
|
|
737
|
-
|
|
739
|
+
},
|
|
738
740
|
init: function(params) {
|
|
739
741
|
if (params.root) {
|
|
740
742
|
options.root = params.root;
|
|
@@ -1098,6 +1100,68 @@ properties for a given parent, keep seperate index for this?
|
|
|
1098
1100
|
}
|
|
1099
1101
|
|
|
1100
1102
|
})(this);
|
|
1103
|
+
(function(global) {
|
|
1104
|
+
'use strict';
|
|
1105
|
+
|
|
1106
|
+
function keyboard(app, config) {
|
|
1107
|
+
var keys = config;
|
|
1108
|
+
|
|
1109
|
+
if (!app) {
|
|
1110
|
+
app = {};
|
|
1111
|
+
}
|
|
1112
|
+
if (!app.container) {
|
|
1113
|
+
app.container = document.body;
|
|
1114
|
+
}
|
|
1115
|
+
app.container.addEventListener('keydown', (e) => {
|
|
1116
|
+
if (e.isComposing || e.keyCode === 229) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (e.defaultPrevented) {
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
if (!e.target) {
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
let selectedKeyboard = 'default';
|
|
1127
|
+
if (e.target.closest('[data-simply-keyboard]')) {
|
|
1128
|
+
selectedKeyboard = e.target.closest('[data-simply-keyboard]').dataset.simplyKeyboard;
|
|
1129
|
+
}
|
|
1130
|
+
let key = '';
|
|
1131
|
+
if (e.ctrlKey && e.keyCode!=17) {
|
|
1132
|
+
key+='Control+';
|
|
1133
|
+
}
|
|
1134
|
+
if (e.metaKey && e.keyCode!=224) {
|
|
1135
|
+
key+='Meta+';
|
|
1136
|
+
}
|
|
1137
|
+
if (e.altKey && e.keyCode!=18) {
|
|
1138
|
+
key+='Alt+';
|
|
1139
|
+
}
|
|
1140
|
+
if (e.shiftKey && e.keyCode!=16) {
|
|
1141
|
+
key+='Shift+';
|
|
1142
|
+
}
|
|
1143
|
+
key+=e.key;
|
|
1144
|
+
|
|
1145
|
+
if (keys[selectedKeyboard] && keys[selectedKeyboard][key]) {
|
|
1146
|
+
let keyboard = keys[selectedKeyboard]
|
|
1147
|
+
keyboard.app = app;
|
|
1148
|
+
keyboard[key].call(keyboard,e);
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
return keys;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
1157
|
+
module.exports = keyboard;
|
|
1158
|
+
} else {
|
|
1159
|
+
if (!global.simply) {
|
|
1160
|
+
global.simply = {};
|
|
1161
|
+
}
|
|
1162
|
+
global.simply.keyboard = keyboard;
|
|
1163
|
+
}
|
|
1164
|
+
})(this);
|
|
1101
1165
|
(function(global) {
|
|
1102
1166
|
'use strict';
|
|
1103
1167
|
|
|
@@ -1730,7 +1794,7 @@ properties for a given parent, keep seperate index for this?
|
|
|
1730
1794
|
'use strict';
|
|
1731
1795
|
|
|
1732
1796
|
var api = {
|
|
1733
|
-
|
|
1797
|
+
/**
|
|
1734
1798
|
* Returns a Proxy object that translates property access to a URL in the api
|
|
1735
1799
|
* and method calls to a fetch on that URL.
|
|
1736
1800
|
* @param options: a list of options for fetch(),
|
|
@@ -1852,27 +1916,27 @@ properties for a given parent, keep seperate index for this?
|
|
|
1852
1916
|
*/
|
|
1853
1917
|
getResult: function(response, options) {
|
|
1854
1918
|
if (response.ok) {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1919
|
+
switch(options.responseFormat) {
|
|
1920
|
+
case 'text':
|
|
1921
|
+
return response.text();
|
|
1922
|
+
break;
|
|
1923
|
+
case 'formData':
|
|
1924
|
+
return response.formData();
|
|
1925
|
+
break;
|
|
1926
|
+
case 'blob':
|
|
1927
|
+
return response.blob();
|
|
1928
|
+
break;
|
|
1929
|
+
case 'arrayBuffer':
|
|
1930
|
+
return response.arrayBuffer();
|
|
1931
|
+
break;
|
|
1932
|
+
case 'unbuffered':
|
|
1933
|
+
return response.body;
|
|
1934
|
+
break;
|
|
1935
|
+
case 'json':
|
|
1936
|
+
default:
|
|
1937
|
+
return response.json();
|
|
1938
|
+
break;
|
|
1939
|
+
}
|
|
1876
1940
|
} else {
|
|
1877
1941
|
throw {
|
|
1878
1942
|
status: response.status,
|
|
@@ -1880,23 +1944,22 @@ properties for a given parent, keep seperate index for this?
|
|
|
1880
1944
|
response: response
|
|
1881
1945
|
}
|
|
1882
1946
|
}
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
logError: function(error, options) {
|
|
1947
|
+
},
|
|
1948
|
+
logError: function(error, options) {
|
|
1886
1949
|
console.error(error.status, error.message);
|
|
1887
|
-
|
|
1950
|
+
}
|
|
1888
1951
|
}
|
|
1889
1952
|
|
|
1890
1953
|
var defaultOptions = {
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1954
|
+
path: '',
|
|
1955
|
+
responseFormat: 'json',
|
|
1956
|
+
paramsFormat: 'search',
|
|
1957
|
+
verbs: ['get','post'],
|
|
1958
|
+
handlers: {
|
|
1959
|
+
fetch: api.fetch,
|
|
1960
|
+
result: api.getResult,
|
|
1961
|
+
error: api.logError
|
|
1962
|
+
}
|
|
1900
1963
|
};
|
|
1901
1964
|
|
|
1902
1965
|
function cd(path, name) {
|
|
@@ -1907,20 +1970,20 @@ properties for a given parent, keep seperate index for this?
|
|
|
1907
1970
|
return path+encodeURIComponent(name);
|
|
1908
1971
|
}
|
|
1909
1972
|
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1973
|
+
function fetchChain(prop, params) {
|
|
1974
|
+
var options = this;
|
|
1975
|
+
return this.handlers.fetch
|
|
1976
|
+
.call(this, prop, params, options)
|
|
1977
|
+
.then(function(res) {
|
|
1978
|
+
return options.handlers.result.call(options, res, options);
|
|
1979
|
+
})
|
|
1980
|
+
.catch(function(error) {
|
|
1981
|
+
return options.handlers.error.call(options, error, options);
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1921
1984
|
|
|
1922
1985
|
function getApiHandler(options) {
|
|
1923
|
-
|
|
1986
|
+
options.handlers = Object.assign({}, defaultOptions.handlers, options.handlers);
|
|
1924
1987
|
options = Object.assign({}, defaultOptions, options);
|
|
1925
1988
|
|
|
1926
1989
|
return {
|
|
@@ -1986,7 +2049,8 @@ properties for a given parent, keep seperate index for this?
|
|
|
1986
2049
|
simply.route.match(global.location.pathname+global.location.hash);
|
|
1987
2050
|
});
|
|
1988
2051
|
}
|
|
1989
|
-
this.container = options.container
|
|
2052
|
+
this.container = options.container || document.body;
|
|
2053
|
+
this.keyboard = simply.keyboard ? simply.keyboard(this, options.keyboard || {}) : false;
|
|
1990
2054
|
this.actions = simply.action ? simply.action(this, options.actions) : false;
|
|
1991
2055
|
this.commands = simply.command ? simply.command(this, options.commands) : false;
|
|
1992
2056
|
this.resize = simply.resize ? simply.resize(this, options.resize) : false;
|
|
@@ -0,0 +1,60 @@
|
|
|
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/examples/counter.html
CHANGED
package/js/simply.api.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var api = {
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
6
|
* Returns a Proxy object that translates property access to a URL in the api
|
|
7
7
|
* and method calls to a fetch on that URL.
|
|
8
8
|
* @param options: a list of options for fetch(),
|
|
@@ -124,27 +124,27 @@
|
|
|
124
124
|
*/
|
|
125
125
|
getResult: function(response, options) {
|
|
126
126
|
if (response.ok) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
127
|
+
switch(options.responseFormat) {
|
|
128
|
+
case 'text':
|
|
129
|
+
return response.text();
|
|
130
|
+
break;
|
|
131
|
+
case 'formData':
|
|
132
|
+
return response.formData();
|
|
133
|
+
break;
|
|
134
|
+
case 'blob':
|
|
135
|
+
return response.blob();
|
|
136
|
+
break;
|
|
137
|
+
case 'arrayBuffer':
|
|
138
|
+
return response.arrayBuffer();
|
|
139
|
+
break;
|
|
140
|
+
case 'unbuffered':
|
|
141
|
+
return response.body;
|
|
142
|
+
break;
|
|
143
|
+
case 'json':
|
|
144
|
+
default:
|
|
145
|
+
return response.json();
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
148
|
} else {
|
|
149
149
|
throw {
|
|
150
150
|
status: response.status,
|
|
@@ -152,23 +152,22 @@
|
|
|
152
152
|
response: response
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
logError: function(error, options) {
|
|
155
|
+
},
|
|
156
|
+
logError: function(error, options) {
|
|
158
157
|
console.error(error.status, error.message);
|
|
159
|
-
|
|
158
|
+
}
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
var defaultOptions = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
162
|
+
path: '',
|
|
163
|
+
responseFormat: 'json',
|
|
164
|
+
paramsFormat: 'search',
|
|
165
|
+
verbs: ['get','post'],
|
|
166
|
+
handlers: {
|
|
167
|
+
fetch: api.fetch,
|
|
168
|
+
result: api.getResult,
|
|
169
|
+
error: api.logError
|
|
170
|
+
}
|
|
172
171
|
};
|
|
173
172
|
|
|
174
173
|
function cd(path, name) {
|
|
@@ -179,20 +178,20 @@
|
|
|
179
178
|
return path+encodeURIComponent(name);
|
|
180
179
|
}
|
|
181
180
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
181
|
+
function fetchChain(prop, params) {
|
|
182
|
+
var options = this;
|
|
183
|
+
return this.handlers.fetch
|
|
184
|
+
.call(this, prop, params, options)
|
|
185
|
+
.then(function(res) {
|
|
186
|
+
return options.handlers.result.call(options, res, options);
|
|
187
|
+
})
|
|
188
|
+
.catch(function(error) {
|
|
189
|
+
return options.handlers.error.call(options, error, options);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
193
192
|
|
|
194
193
|
function getApiHandler(options) {
|
|
195
|
-
|
|
194
|
+
options.handlers = Object.assign({}, defaultOptions.handlers, options.handlers);
|
|
196
195
|
options = Object.assign({}, defaultOptions, options);
|
|
197
196
|
|
|
198
197
|
return {
|
package/js/simply.app.js
CHANGED
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
simply.route.match(global.location.pathname+global.location.hash);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
this.container = options.container
|
|
32
|
+
this.container = options.container || document.body;
|
|
33
|
+
this.keyboard = simply.keyboard ? simply.keyboard(this, options.keyboard || {}) : false;
|
|
33
34
|
this.actions = simply.action ? simply.action(this, options.actions) : false;
|
|
34
35
|
this.commands = simply.command ? simply.command(this, options.commands) : false;
|
|
35
36
|
this.resize = simply.resize ? simply.resize(this, options.resize) : false;
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
let key = '';
|
|
29
|
+
if (e.ctrlKey && e.keyCode!=17) {
|
|
30
|
+
key+='Control+';
|
|
31
|
+
}
|
|
32
|
+
if (e.metaKey && e.keyCode!=224) {
|
|
33
|
+
key+='Meta+';
|
|
34
|
+
}
|
|
35
|
+
if (e.altKey && e.keyCode!=18) {
|
|
36
|
+
key+='Alt+';
|
|
37
|
+
}
|
|
38
|
+
if (e.shiftKey && e.keyCode!=16) {
|
|
39
|
+
key+='Shift+';
|
|
40
|
+
}
|
|
41
|
+
key+=e.key;
|
|
42
|
+
|
|
43
|
+
if (keys[selectedKeyboard] && keys[selectedKeyboard][key]) {
|
|
44
|
+
let keyboard = keys[selectedKeyboard]
|
|
45
|
+
keyboard.app = app;
|
|
46
|
+
keyboard[key].call(keyboard,e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return keys;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
55
|
+
module.exports = keyboard;
|
|
56
|
+
} else {
|
|
57
|
+
if (!global.simply) {
|
|
58
|
+
global.simply = {};
|
|
59
|
+
}
|
|
60
|
+
global.simply.keyboard = keyboard;
|
|
61
|
+
}
|
|
62
|
+
})(this);
|
package/js/simply.route.js
CHANGED
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
handleEvents: function() {
|
|
119
119
|
global.addEventListener('popstate', function() {
|
|
120
120
|
if (route.match(getPath(document.location.pathname + document.location.hash)) === false) {
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
route.match(getPath(document.location.pathname));
|
|
122
|
+
}
|
|
123
123
|
});
|
|
124
124
|
global.document.addEventListener('click', linkHandler);
|
|
125
125
|
},
|
|
@@ -144,22 +144,24 @@
|
|
|
144
144
|
|
|
145
145
|
var matches;
|
|
146
146
|
if (!path) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
147
|
+
if (route.match(document.location.pathname+document.location.hash)) {
|
|
148
|
+
return true;
|
|
149
|
+
} else {
|
|
150
|
+
return route.match(document.location.pathname);
|
|
151
|
+
}
|
|
152
152
|
}
|
|
153
153
|
path = getPath(path);
|
|
154
154
|
for ( var i=0; i<routeInfo.length; i++) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
path
|
|
159
|
-
|
|
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
|
+
}
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
|
-
matches = routeInfo[i].match.exec(path);
|
|
163
165
|
if (matches && matches.length) {
|
|
164
166
|
var params = {};
|
|
165
167
|
routeInfo[i].params.forEach(function(key, i) {
|
|
@@ -176,9 +178,9 @@
|
|
|
176
178
|
args.result = routeInfo[i].action.call(route, params);
|
|
177
179
|
runListeners('finish', args);
|
|
178
180
|
return args.result;
|
|
179
|
-
|
|
181
|
+
}
|
|
180
182
|
}
|
|
181
|
-
|
|
183
|
+
return false;
|
|
182
184
|
},
|
|
183
185
|
goto: function(path) {
|
|
184
186
|
history.pushState({},'',getUrl(path));
|
|
@@ -213,7 +215,7 @@
|
|
|
213
215
|
listeners[action][route] = listeners[action][route].filter(function(listener) {
|
|
214
216
|
return listener != callback;
|
|
215
217
|
});
|
|
216
|
-
|
|
218
|
+
},
|
|
217
219
|
init: function(params) {
|
|
218
220
|
if (params.root) {
|
|
219
221
|
options.root = params.root;
|
package/make
CHANGED
package/package.json
CHANGED
package/examples/githubv4.html
DELETED
|
@@ -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>
|
package/examples/graphql.html
DELETED
|
@@ -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>
|
package/examples/graphql.html~
DELETED
|
@@ -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>
|
package/js/simply.api.js~
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
(function(global) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var api = {
|
|
5
|
-
/**
|
|
6
|
-
* Returns a Proxy object that translates property access to a URL in the api
|
|
7
|
-
* and method calls to a fetch on that URL.
|
|
8
|
-
* @param options: a list of options for fetch(),
|
|
9
|
-
* see the 'init' parameter at https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#parameters
|
|
10
|
-
* additionally:
|
|
11
|
-
* - baseURL: (required) the endpoint of the API
|
|
12
|
-
* - path: the current path in the API, is appended to the baseURL
|
|
13
|
-
* - verbs: list of http verbs to allow as methods, default ['get','post']
|
|
14
|
-
* - handlers.fetch: alternative fetch method
|
|
15
|
-
* - handlers.result: alternative getResult method
|
|
16
|
-
* - handlers.error: alternative error method
|
|
17
|
-
* - user (and password): if set, a basic authentication header will be added
|
|
18
|
-
* - paramsFormat: either 'formData', 'json' or 'search'. Default is search.
|
|
19
|
-
* - responseFormat: test, formData, blob, json, arrayBuffer or unbuffered. Default is json.
|
|
20
|
-
* @return Proxy
|
|
21
|
-
*/
|
|
22
|
-
proxy: function(options) {
|
|
23
|
-
var cache = () => {};
|
|
24
|
-
cache.$options = Object.assign({}, options);
|
|
25
|
-
return new Proxy( cache, getApiHandler(cache.$options) );
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Fetches the options.baseURL using the fetch api and returns a promise
|
|
30
|
-
* Extra options in addition to those of global.fetch():
|
|
31
|
-
* - user (and password): if set, a basic authentication header will be added
|
|
32
|
-
* - paramsFormat: either 'formData', 'json' or 'search'
|
|
33
|
-
* By default params, if set, will be added to the baseURL as searchParams
|
|
34
|
-
* @param method one of the http verbs, e.g. get, post, etc.
|
|
35
|
-
* @param options the options for fetch(), with some additions
|
|
36
|
-
* @param params the parameters to send with the request, as javascript/json data
|
|
37
|
-
* @return Promise
|
|
38
|
-
*/
|
|
39
|
-
fetch: function(method, params, options) {
|
|
40
|
-
if (!options.url) {
|
|
41
|
-
if (!options.baseURL) {
|
|
42
|
-
throw new Error('No url or baseURL in options object');
|
|
43
|
-
}
|
|
44
|
-
while (options.baseURL[options.baseURL.length-1]=='/') {
|
|
45
|
-
options.baseURL = options.baseURL.substr(0, options.baseURL.length-1);
|
|
46
|
-
}
|
|
47
|
-
var url = new URL(options.baseURL+options.path);
|
|
48
|
-
} else {
|
|
49
|
-
var url = options.url;
|
|
50
|
-
}
|
|
51
|
-
var fetchOptions = Object.assign({}, options);
|
|
52
|
-
if (!fetchOptions.headers) {
|
|
53
|
-
fetchOptions.headers = {};
|
|
54
|
-
}
|
|
55
|
-
if (params) {
|
|
56
|
-
if (method=='GET') {
|
|
57
|
-
var paramsFormat = 'search';
|
|
58
|
-
} else {
|
|
59
|
-
var paramsFormat = options.paramsFormat;
|
|
60
|
-
}
|
|
61
|
-
switch(paramsFormat) {
|
|
62
|
-
case 'formData':
|
|
63
|
-
var formData = new FormData();
|
|
64
|
-
for (const name in params) {
|
|
65
|
-
formData.append(name, params[name]);
|
|
66
|
-
}
|
|
67
|
-
if (!fetchOptions.headers['Content-Type']) {
|
|
68
|
-
fetchOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
case 'json':
|
|
72
|
-
var formData = JSON.stringify(params);
|
|
73
|
-
if (!fetchOptions.headers['Content-Type']) {
|
|
74
|
-
fetchOptions.headers['Content-Type'] = 'application/json';
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
case 'search':
|
|
78
|
-
var searchParams = url.searchParams; //new URLSearchParams(url.search.slice(1));
|
|
79
|
-
for (const name in params) {
|
|
80
|
-
searchParams.set(name, params[name]);
|
|
81
|
-
}
|
|
82
|
-
url.search = searchParams.toString();
|
|
83
|
-
break;
|
|
84
|
-
default:
|
|
85
|
-
throw Error('Unknown options.paramsFormat '+options.paramsFormat+'. Select one of formData, json or search.');
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (formData) {
|
|
90
|
-
fetchOptions.body = formData
|
|
91
|
-
}
|
|
92
|
-
if (options.user) {
|
|
93
|
-
fetchOptions.headers['Authorization'] = 'Basic '+btoa(options.user+':'+options.password);
|
|
94
|
-
}
|
|
95
|
-
fetchOptions.method = method.toUpperCase();
|
|
96
|
-
var fetchURL = url.toString()
|
|
97
|
-
return fetch(fetchURL, fetchOptions);
|
|
98
|
-
},
|
|
99
|
-
graphqlQuery: function(url, operationName, query, options) {
|
|
100
|
-
options = Object.assign({ paramsFormat: 'json', url: url, responseFormat: 'json' }, options)
|
|
101
|
-
return function(params) {
|
|
102
|
-
return simply.api.fetch(
|
|
103
|
-
'POST',
|
|
104
|
-
{
|
|
105
|
-
operationName: operationName,
|
|
106
|
-
query: query,
|
|
107
|
-
variables: params || {}
|
|
108
|
-
},
|
|
109
|
-
options
|
|
110
|
-
).then(function(response) {
|
|
111
|
-
return simply.api.getResult(response, options);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
/**
|
|
116
|
-
* Handles the response and returns a Promise with the response data as specified
|
|
117
|
-
* @param response Response
|
|
118
|
-
* @param options
|
|
119
|
-
* - responseFormat: one of 'text', 'formData', 'blob', 'arrayBuffer', 'unbuffered' or 'json'.
|
|
120
|
-
* The default is json.
|
|
121
|
-
*/
|
|
122
|
-
getResult: function(response, options) {
|
|
123
|
-
if (response.ok) {
|
|
124
|
-
switch(options.responseFormat) {
|
|
125
|
-
case 'text':
|
|
126
|
-
return response.text();
|
|
127
|
-
break;
|
|
128
|
-
case 'formData':
|
|
129
|
-
return response.formData();
|
|
130
|
-
break;
|
|
131
|
-
case 'blob':
|
|
132
|
-
return response.blob();
|
|
133
|
-
break;
|
|
134
|
-
case 'arrayBuffer':
|
|
135
|
-
return response.arrayBuffer();
|
|
136
|
-
break;
|
|
137
|
-
case 'unbuffered':
|
|
138
|
-
return response.body;
|
|
139
|
-
break;
|
|
140
|
-
case 'json':
|
|
141
|
-
default:
|
|
142
|
-
return response.json();
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
throw {
|
|
147
|
-
status: response.status,
|
|
148
|
-
message: response.statusText,
|
|
149
|
-
response: response
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
logError: function(error, options) {
|
|
154
|
-
console.error(error.status, error.message);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
var defaultOptions = {
|
|
159
|
-
path: '',
|
|
160
|
-
responseFormat: 'json',
|
|
161
|
-
paramsFormat: 'search',
|
|
162
|
-
verbs: ['get','post'],
|
|
163
|
-
handlers: {
|
|
164
|
-
fetch: api.fetch,
|
|
165
|
-
result: api.getResult,
|
|
166
|
-
error: api.logError
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
function cd(path, name) {
|
|
171
|
-
name = name.replace(/\//g,'');
|
|
172
|
-
if (!path.length || path[path.length-1]!=='/') {
|
|
173
|
-
path+='/';
|
|
174
|
-
}
|
|
175
|
-
return path+encodeURIComponent(name);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function fetchChain(prop, params) {
|
|
179
|
-
var options = this;
|
|
180
|
-
return this.handlers.fetch
|
|
181
|
-
.call(this, prop, params, options)
|
|
182
|
-
.then(function(res) {
|
|
183
|
-
return options.handlers.result.call(options, res, options);
|
|
184
|
-
})
|
|
185
|
-
.catch(function(error) {
|
|
186
|
-
return options.handlers.error.call(options, error, options);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function getApiHandler(options) {
|
|
191
|
-
options.handlers = Object.assign({}, defaultOptions.handlers, options.handlers);
|
|
192
|
-
options = Object.assign({}, defaultOptions, options);
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
get: function(cache, prop) {
|
|
196
|
-
if (!cache[prop]) {
|
|
197
|
-
if (options.verbs.indexOf(prop)!=-1) {
|
|
198
|
-
cache[prop] = function(params) {
|
|
199
|
-
return fetchChain.call(options, prop, params);
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
cache[prop] = api.proxy(Object.assign({}, options, {
|
|
203
|
-
path: cd(options.path, prop)
|
|
204
|
-
}));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return cache[prop];
|
|
208
|
-
},
|
|
209
|
-
apply: function(cache, thisArg, params) {
|
|
210
|
-
return fetchChain.call(options, 'get', params[0] ? params[0] : null)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
217
|
-
module.exports = api;
|
|
218
|
-
} else {
|
|
219
|
-
if (!global.simply) {
|
|
220
|
-
global.simply = {};
|
|
221
|
-
}
|
|
222
|
-
global.simply.api = api;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
})(this);
|
package/package.json~
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "simplyview",
|
|
3
|
-
"version": "2.0.0",
|
|
4
|
-
"description": "Library to rapidly build UI components, using declarative tools",
|
|
5
|
-
"main": "dist/simply.everything.js",
|
|
6
|
-
"directories": {
|
|
7
|
-
"example": "examples"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "jest"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/simplyedit/simplyview.git"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"UI",
|
|
18
|
-
"components",
|
|
19
|
-
"declarative",
|
|
20
|
-
"reactive"
|
|
21
|
-
],
|
|
22
|
-
"author": "auke@muze.nl",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://github.com/simplyedit/simplyview/issues"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://github.com/simplyedit/simplyview#readme",
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"jest": "^24.9.0"
|
|
30
|
-
}
|
|
31
|
-
}
|