@litejs/ui 22.8.0 → 23.3.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.
@@ -1,312 +0,0 @@
1
-
2
- /* litejs.com/MIT-LICENSE.txt */
3
-
4
- !function() {
5
- var dummy = El("div")
6
- , isArray = Array.isArray
7
-
8
- El.bindings.schemaToForm = schemaToForm
9
- schemaToForm.once = 1
10
-
11
- function allOf(schema) {
12
- return isArray(schema.allOf) ?
13
- schema.allOf.reduce(function(memo, item) {
14
- return JSON.mergePatch(memo, item)
15
- }, {}):
16
- schema
17
- }
18
-
19
- function schemaToForm(form, schema, link, template, event) {
20
- var scope = this
21
- , model = scope.model || null
22
-
23
- link = link || "self"
24
-
25
- form.fill = function(model) {
26
- View.blur()
27
- form.fillForm(model)
28
- }
29
-
30
- xhr.getSchema(schema, function(err, schema) {
31
- var i, selfHref, fieldset
32
- , _link = schema
33
-
34
- if (schema.links) for (i = 0; _link = schema.links[i++]; ) {
35
- if (_link.rel == "self") {
36
- selfHref = _link.href
37
- }
38
- if (_link.rel == link) {
39
- schema = _link.schema || schema
40
- break
41
- }
42
- }
43
-
44
- form.fillForm = fillForm
45
- function fillForm(model) {
46
- if (fieldset) El.kill(fieldset)
47
- fieldset = El(template + "-fieldset")
48
- drawSchema(schema, null, fieldset, model && model.data || null, null, scope, model)
49
- El.append(form, fieldset)
50
- }
51
-
52
- fillForm(model)
53
-
54
- El.on(form, "submit", function() {
55
- var data = El.val(this)
56
- , _scope = Object.assign({}, scope.params, model && model.data)
57
- , href = (_link.href || selfHref).format(_scope)
58
- JSON.schemaApply(schema, data)
59
-
60
- if (model) {
61
- var changed = []
62
- , clone = JSON.clone(model.data)
63
- JSON.mergePatch(clone, data, changed)
64
-
65
- if (changed.length) {
66
- data = JSON.tr(changed)(data)
67
- } else {
68
- data = null
69
- }
70
- }
71
-
72
- try { document.activeElement.blur() } catch(e) {}
73
-
74
- if (data) View.emit(event || "makeReq", _link, href, data)
75
- })
76
-
77
- })
78
-
79
- function drawSchema(schema, key, fieldset, data, namePrefix, scope, model, def) {
80
- var alternatives, keys, i, root, tmp
81
- , alSelected
82
- , count = 0
83
-
84
- schema = allOf(schema)
85
-
86
- if (schema.properties || schema.anyOf) {
87
- if (key !== null) {
88
- namePrefix = namePrefix ? namePrefix + "[" + key + "]" : key
89
- if (schema.title) {
90
- El.append(fieldset, El.append(El(template + "-subheader"), schema.title))
91
- }
92
- }
93
- }
94
-
95
- if (schema.properties) {
96
- Object.each(schema.properties, function(sub, _key) {
97
- drawSchema(
98
- sub,
99
- _key,
100
- fieldset,
101
- data === null ? null : (sub.type == "object" || sub.properties || sub.anyOf ? data[_key] : data) || {},
102
- namePrefix,
103
- scope,
104
- model,
105
- def
106
- )
107
- })
108
- if (!schema.anyOf) return
109
- }
110
-
111
- if (isArray(schema.anyOf)) {
112
- var title
113
- schema = schema.anyOf.map(allOf)
114
- key = []
115
-
116
- alternatives = {}
117
- keys = Object.keys(schema[0].properties)
118
-
119
- for (i = 0; tmp = schema[i++]; ) {
120
- keys = keys.filter(function(val) {
121
- var t = tmp.properties[val]
122
- return t && (
123
- t["enum"] ||
124
- t.type == "boolean" && typeof t["default"] == t.type
125
- )
126
- })
127
- }
128
-
129
- scope.selected = {}
130
- for (i = 0; tmp = schema[i++]; ) {
131
- root = El(".grid.b2.w12")
132
- tmp = JSON.clone(tmp)
133
- keys.each(function(val) {
134
- var prop = tmp.properties[val]
135
- title = title || prop.title
136
- if (prop.type == "boolean") {
137
- setAlt(prop["default"])
138
- } else {
139
- prop["enum"].each(setAlt)
140
- }
141
- delete tmp.properties[val]
142
- })
143
- function setAlt(val) {
144
- key.push(val)
145
- alternatives[val] = root
146
- }
147
- root._draw = [tmp, null, root, data, namePrefix, scope, model]
148
- }
149
-
150
- schema = typeof key[0] == "boolean" ? JSON.clone(schema[0].properties[keys[0]]) : {
151
- title: title,
152
- "enum": key
153
- }
154
- key = keys[0]
155
- }
156
-
157
- var ro = model && model.acl && !model.acl("write", key || namePrefix) ? "-ro" : ""
158
-
159
-
160
- var row = El(template + (
161
- schema["ui:el"] && El.cache[template + "-" + schema["ui:el"]] ? "-" + schema["ui:el"] :
162
- schema["enum"] ? "-enum" + ro :
163
- schema.type == "boolean" ? "-boolean" + ro :
164
- schema.type == "array" ? "-" + schema.type :
165
- schema.patternProperties ? "-array" :
166
- schema.resourceCollection ? "-list" + ro :
167
- ro ))
168
- , sc = El.scope(row, scope)
169
- , val = data === null ? (def && def[key] || schema["default"]) : (key == null ? data : data[key])
170
-
171
- sc.name = key || ""
172
- sc.value = val
173
- sc.add = function(e) {
174
- if (schema.patternProperties) {
175
- var key = Object.keys(schema.patternProperties)[0]
176
- app.emit("confirm", " ", {
177
- body: "Enter key", code:1
178
- }, function(action, code) {
179
- add(null, schema.patternProperties[key], code)
180
- })
181
- } else {
182
- add()
183
- }
184
- }
185
- sc.del = del
186
- if (ro !== "") sc.noAdd = true
187
-
188
- Object.assign(sc, schema)
189
-
190
- if (schema.type == "array" || schema.patternProperties) {
191
- var content = El.find(row, ".js-items")
192
- , hidden = El("input[type=hidden]")
193
-
194
- El.append(content, hidden)
195
-
196
- key = namePrefix ? namePrefix + "[" + key + "]" : key
197
-
198
- El.attr(hidden, "name", key)
199
-
200
- if (isArray(schema.items)) {
201
- sc.noAdd = true
202
- schema.items.each(function(item, i) {
203
- add(val && val[i], item)
204
- })
205
- } else if (schema.patternProperties) {
206
- hidden.valObject = null
207
- if (val) Object.each(schema.patternProperties, function(sub, _re) {
208
- var re = RegExp(_re)
209
- Object.each(val, function(val, key) {
210
- if (re.test(key)) {
211
- add(val, sub, key)
212
- }
213
- })
214
- })
215
- } else if (schema.resourceCollection) {
216
- api(schema.resourceCollection.format(scope.params, scope)).each(add2)
217
- } else if (isArray(val) && val.length) {
218
- val.each(function(v) { add(v) })
219
- } else if (schema.minItems) {
220
- for (i = schema.minItems; i--; ) {
221
- add()
222
- }
223
- }
224
- El.render(row, sc)
225
- El.append(fieldset, row)
226
- return
227
- }
228
-
229
- El.render(row, sc)
230
- El.append(fieldset, row)
231
-
232
- function add2(val, i) {
233
- var map = {}
234
- map[i] = sc.value && sc.value.indexOf(val.data.id) != -1 || null
235
-
236
- drawSchema(
237
- { type: "boolean", title: val.data.name },
238
- "" + i,
239
- content,
240
- data && map || null,
241
- key,
242
- scope,
243
- model
244
- )
245
- }
246
-
247
- function add(val, itemSchema, param) {
248
- var root = El(template + "-array-item")
249
- , rootScope = El.scope(root, sc)
250
- rootScope.key = param
251
- if (itemSchema && param) {
252
- rootScope.title = _(itemSchema.title, rootScope)
253
- }
254
- El.append(content, root)
255
- El.render(root, rootScope)
256
-
257
- root = El.find(root, ".js-item") || root
258
-
259
-
260
- drawSchema(
261
- itemSchema || schema.items,
262
- null,
263
- root,
264
- data && val || null,
265
- key + "[" + (param || count++) + "]",
266
- scope,
267
- model,
268
- val
269
- )
270
- }
271
-
272
- var field = El.find(row, ".field")
273
- if (field) El.attr(field, "name", namePrefix && key ? namePrefix + "[" + key + "]" : namePrefix || key)
274
-
275
- if (val !== void 0 && field) {
276
- El.val(field, val)
277
- }
278
-
279
- if (schema.readonly) {
280
- field.disabled = true
281
- }
282
-
283
- if (alternatives) {
284
- El.on(field, "change click", alUp)
285
- alUp()
286
- }
287
-
288
- function alUp() {
289
- var val = El.val(field)
290
- if (typeof val !== "string") val = !!val
291
- scope["selected"][key] = val
292
- if (alSelected != alternatives[val]) {
293
- if (alSelected) {
294
- El.append(dummy, alSelected)
295
- }
296
- alSelected = alternatives[val]
297
- if (alSelected._draw) {
298
- drawSchema.apply(null, alSelected._draw)
299
- alSelected._draw = null
300
- }
301
- El.append(fieldset, (alSelected = alternatives[val]), row.nextSibling)
302
- } else {
303
- El.render(alSelected, scope)
304
- }
305
- }
306
- }
307
- }
308
-
309
- function del() {
310
- El.kill(El.closest(this, ".js-del"))
311
- }
312
- }()
@@ -1,28 +0,0 @@
1
-
2
- /* litejs.com/MIT-LICENSE.txt */
3
-
4
-
5
-
6
- !function(process) {
7
- var seq = 0
8
- , tickQueue = []
9
- , tickImage = new Image()
10
-
11
- tickImage.onerror = function() {
12
- var fn
13
- , i = 0
14
- , queue = tickQueue
15
- for (tickQueue = []; fn = queue[i++]; ) {
16
- fn()
17
- }
18
- }
19
-
20
- // IE11 throws when setImmediate called without window context
21
- // IE5-8 Image.onerror is sync when bad mime.
22
- // with "data:image/gif," it is async but logs errors
23
- nextTick: window.setImmediate ? setImmediate.bind(window) : function(fn) {
24
- ~-tickQueue.push(fn)||(tickImage.src = "data:," + seq++)
25
- }
26
-
27
- }(process)
28
-
package/schema-apply.js DELETED
@@ -1,110 +0,0 @@
1
-
2
- /* litejs.com/MIT-LICENSE.txt */
3
-
4
- !function(exports) {
5
- exports.schemaApply = schemaApply
6
-
7
- function allOf(schema) {
8
- return Array.isArray(schema.allOf) ?
9
- schema.allOf.reduce(function(memo, item) {
10
- return JSON.mergePatch(memo, item)
11
- }, {}):
12
- schema
13
- }
14
-
15
- function schemaApply(schema, data, _required) {
16
- var tmp
17
- , type = schema.type
18
- , actualType = typeof data
19
- , required = _required || schema.required
20
-
21
- schema = allOf(schema)
22
-
23
- if (schema.anyOf) {
24
- schema.anyOf.map(allOf).each(function(schema) {
25
- var i, tmp, tmp2
26
- , keys = Object.keys(schema.properties)
27
-
28
- for (i = 0; tmp = keys[i++]; ) {
29
- tmp2 = schema.properties[tmp]["enum"]
30
- if (tmp2 && tmp2.indexOf(data[tmp]) < 0) {
31
- return
32
- }
33
- }
34
- schemaApply(schema, data)
35
- })
36
- }
37
- if (Array.isArray(tmp = schema["enum"])) {
38
- if (tmp.indexOf(data) < 0) {
39
- for (var i = tmp.length; i--; ) {
40
- if (tmp[i] == data) {
41
- data = tmp[i]
42
- break
43
- }
44
- }
45
- }
46
- } else if (type == "string") {
47
- if (type !== actualType) data = "" + data
48
- } else if (type === "number" || type == "integer") {
49
- if (schema["ui:el"] == "date-time") {
50
- data = Date.parse(data)
51
- }
52
- data = (data + "").replace(",", ".")
53
- data = type === "number" ? parseFloat(data) : parseInt(data, 10)
54
-
55
- if (typeof(tmp = schema.multipleOf) == "number") {
56
- data -= data % tmp
57
- }
58
- if (typeof(tmp = schema.minimum) == "number" && data < tmp) {
59
- data = tmp
60
- }
61
- if (typeof(tmp = schema.maximum) == "number" && data > tmp) {
62
- data = tmp
63
- }
64
- } else if (type == "boolean" ) {
65
- data = data ? true : required ? false : null
66
- } else if (type == "date-time") {
67
- data = data.date()
68
- } else if (schema.type == "array" ) {
69
- var itemSchema = Array.isArray(schema.items) && schema.items
70
-
71
- data = Array.isArray(data) ?
72
- data.reduce(function(memo, item, idx) {
73
- var sc = itemSchema ? itemSchema[idx] : schema.items
74
- if (item !== void null && sc) {
75
- item = schemaApply(sc, item)
76
- memo.push(item)
77
- }
78
- return memo
79
- }, []) :
80
- null
81
- } else if (data) {
82
- var reqArr = Array.isArray(schema.required) && schema.required
83
- Object.each(schema.properties, function(propSchema, prop) {
84
- if (data[prop] !== void 0) {
85
- data[prop] = schemaApply(
86
- propSchema,
87
- data[prop],
88
- reqArr && reqArr.indexOf(prop) > -1
89
- )
90
- }
91
- })
92
- if (schema.patternProperties) {
93
- tmp = schema.properties || {}
94
- Object.each(schema.patternProperties, function(propSchema, _re) {
95
- var re = RegExp(_re)
96
- Object.each(data, function(val, prop) {
97
- if (!tmp[prop] && re.test(prop)) data[prop] = schemaApply(
98
- propSchema,
99
- data[prop],
100
- reqArr && reqArr.indexOf(prop) > -1
101
- )
102
- })
103
- })
104
- }
105
- }
106
-
107
- return data
108
- }
109
- }(this.JSON || this)
110
-
package/worker-push.js DELETED
@@ -1,29 +0,0 @@
1
-
2
- /* litejs.com/MIT-LICENSE.txt */
3
-
4
-
5
- console.log('Push service started', self);
6
-
7
- self.addEventListener('install', function(event) {
8
- self.skipWaiting();
9
- console.log('Installed', event);
10
- });
11
-
12
- self.addEventListener('activate', function(event) {
13
- console.log('Activated', event);
14
- });
15
-
16
- self.addEventListener('push', function(event) {
17
- console.log('Push message', event);
18
-
19
- var title = 'Push message';
20
-
21
- event.waitUntil(
22
- self.registration.showNotification(title, {
23
- 'body': 'The Message',
24
- 'icon': 'images/icon.png'
25
- })
26
- );
27
- });
28
-
29
-
package/xhr-getschema.js DELETED
@@ -1,92 +0,0 @@
1
-
2
-
3
-
4
-
5
- !function(xhr) {
6
- var pending = []
7
- , loaded = getSchema.loaded = {}
8
-
9
- xhr.getSchema = getSchema
10
- /**
11
- * JSON Reference
12
- * @see http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03
13
- * A JSON Reference is a JSON object, which contains a member named "$ref":
14
- * { "$ref": "http://example.com/example.json#/foo/bar" }
15
- *
16
- *
17
- * JSON Activity Streams
18
- * http://activitystrea.ms/specs/json/schema/activity-schema.html
19
- * https://tools.ietf.org/html/draft-snell-activitystreams-09
20
- *
21
- * official mime type is "application/schema+json"
22
- */
23
-
24
- function getSchema(ref, next) {
25
- var parts = ref.split("#")
26
- , file = parts[0]
27
- , schema = loaded[file]
28
- , path = decodeURIComponent((parts[1] || "").replace(/\+/g, " "))
29
-
30
- if (schema && schema !== 1) {
31
- return next && next(null, path ? JSON.get(schema, path) : schema)
32
- }
33
-
34
- pending.push(arguments)
35
- loaded[file] = 1
36
-
37
- if (schema !== 1) xhr("GET", file, function(err, _schema) {
38
- if (err) return next(err)
39
-
40
- var i, ref
41
- , refs = []
42
- , schema = JSON.parse(_schema)
43
- , cb = Fn.wait(function() {
44
- loaded[file] = schema
45
- if (pending.length) {
46
- var arr = pending
47
- pending = []
48
- for (i = 0; ref = arr[i++]; ) {
49
- getSchema.apply(null, ref)
50
- }
51
- }
52
- })
53
- resolveRefs(schema, refs, file, schema)
54
- if (refs[0]) {
55
- // TODO:2014-12-23:lauri:resolve multiple refs
56
- // TODO:2014-12-23:lauri:resolve refs from other files
57
- // TODO:2016-07-26:lauri:Fix resolving circular refs
58
- for (i = 0; ref = refs[i]; i += 3) !function(ref, i, next) {
59
- getSchema(ref, function(err, schema) {
60
- refs[i+1][refs[i+2]] = schema
61
- next()
62
- })
63
- }(ref, i, cb.wait())
64
- }
65
- cb()
66
-
67
- }).send()
68
- }
69
-
70
- function resolveRefs(obj, refs, $id, schema, key, val) {
71
- for (key in obj) if (val = obj[key]) {
72
- if (typeof val.$id == "string") {
73
- resolveRefs(loaded[val.$id] = val, refs, val.$id, val)
74
- } else if (typeof val == "object") {
75
- resolveRefs(val, refs, $id, schema)
76
- }
77
- if (val = val.$ref) {
78
- if (val.charAt(0) == "#") {
79
- val = val.slice(1)
80
- obj[key] = val ? JSON.get(schema, val) : schema
81
- } else if (val.charAt(0) != "/") {
82
- val = $id.replace(/[^\/]*$/, val)
83
- refs.push(val, obj, key)
84
- }
85
- }
86
- }
87
- }
88
-
89
- }(xhr)
90
-
91
-
92
-