@converse/skeletor 0.0.8 → 0.0.9
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/README.md +38 -25
- package/dist/skeletor.js +9232 -5096
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +74 -3
- package/dist/skeletor.min.js.map +1 -1
- package/package.json +21 -11
- package/src/collection.js +540 -395
- package/src/drivers/sessionStorage.js +222 -219
- package/src/element.js +132 -82
- package/src/eventemitter.js +187 -0
- package/src/helpers.js +143 -118
- package/src/{main.js → index.js} +21 -17
- package/src/listening.js +81 -0
- package/src/model.js +340 -238
- package/src/storage.js +222 -230
- package/src/types/collection.d.ts +366 -0
- package/src/types/collection.d.ts.map +1 -0
- package/src/types/drivers/sessionStorage.d.ts +37 -0
- package/src/types/drivers/sessionStorage.d.ts.map +1 -0
- package/src/types/element.d.ts +115 -0
- package/src/types/element.d.ts.map +1 -0
- package/src/types/eventemitter.d.ts +93 -0
- package/src/types/eventemitter.d.ts.map +1 -0
- package/src/types/helpers.d.ts +62 -0
- package/src/types/helpers.d.ts.map +1 -0
- package/src/types/index.d.ts +19 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/listening.d.ts +40 -0
- package/src/types/listening.d.ts.map +1 -0
- package/src/types/model.d.ts +230 -0
- package/src/types/model.d.ts.map +1 -0
- package/src/types/storage.d.ts +35 -0
- package/src/types/storage.d.ts.map +1 -0
- package/src/types/utils/events.d.ts +28 -0
- package/src/types/utils/events.d.ts.map +1 -0
- package/src/utils/events.js +174 -0
- package/src/drivers/sessionStorage.js~ +0 -307
- package/src/events.js +0 -328
- package/src/history.js +0 -301
- package/src/overview.js +0 -191
- package/src/router.js +0 -119
- package/src/view.js +0 -267
package/src/view.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// Backbone.js 1.4.0
|
|
2
|
-
// (c) 2010-2019 Jeremy Ashkenas and DocumentCloud
|
|
3
|
-
// Backbone may be freely distributed under the MIT license.
|
|
4
|
-
|
|
5
|
-
// View
|
|
6
|
-
// ----
|
|
7
|
-
|
|
8
|
-
// Views are almost more convention than they are actual code. A View
|
|
9
|
-
// is simply a JavaScript object that represents a logical chunk of UI in the
|
|
10
|
-
// DOM. This might be a single item, an entire list, a sidebar or panel, or
|
|
11
|
-
// even the surrounding frame which wraps your whole app. Defining a chunk of
|
|
12
|
-
// UI as a **View** allows you to define your DOM events declaratively, without
|
|
13
|
-
// having to worry about render order ... and makes it easy for the view to
|
|
14
|
-
// react to specific changes in the state of your models.
|
|
15
|
-
|
|
16
|
-
import extend from "lodash-es/extend.js";
|
|
17
|
-
import isElement from "lodash-es/isElement.js";
|
|
18
|
-
import isFunction from "lodash-es/isFunction.js";
|
|
19
|
-
import pick from "lodash-es/pick.js";
|
|
20
|
-
import result from "lodash-es/result.js";
|
|
21
|
-
import uniqueId from "lodash-es/uniqueId.js";
|
|
22
|
-
import { Events } from './events.js';
|
|
23
|
-
import { inherits, sync, urlError, wrapError } from './helpers.js';
|
|
24
|
-
import { render } from 'lit-html';
|
|
25
|
-
|
|
26
|
-
const paddedLt = /^\s*</;
|
|
27
|
-
|
|
28
|
-
// Caches a local reference to `Element.prototype` for faster access.
|
|
29
|
-
const ElementProto = (typeof Element !== 'undefined' && Element.prototype) || {};
|
|
30
|
-
|
|
31
|
-
const indexOf = function(array, item) {
|
|
32
|
-
for (let i = 0, len = array.length; i < len; i++) if (array[i] === item) return i;
|
|
33
|
-
return -1;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Creating a View creates its initial element outside of the DOM,
|
|
38
|
-
// if an existing element is not provided...
|
|
39
|
-
export const View = function(options) {
|
|
40
|
-
this.cid = uniqueId('view');
|
|
41
|
-
this._domEvents = [];
|
|
42
|
-
this.preinitialize.apply(this, arguments);
|
|
43
|
-
extend(this, pick(options, viewOptions));
|
|
44
|
-
this._ensureElement();
|
|
45
|
-
this.initialize.apply(this, arguments);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
View.extend = inherits;
|
|
49
|
-
|
|
50
|
-
// Cached regex to split keys for `delegate`.
|
|
51
|
-
const delegateEventSplitter = /^(\S+)\s*(.*)$/;
|
|
52
|
-
|
|
53
|
-
// List of view options to be set as properties.
|
|
54
|
-
const viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
|
|
55
|
-
|
|
56
|
-
// Set up all inheritable **View** properties and methods.
|
|
57
|
-
Object.assign(View.prototype, Events, {
|
|
58
|
-
|
|
59
|
-
// The default `tagName` of a View's element is `"div"`.
|
|
60
|
-
tagName: 'div',
|
|
61
|
-
|
|
62
|
-
$: function(selector) {
|
|
63
|
-
return this.el.querySelectorAll(selector);
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
// preinitialize is an empty function by default. You can override it with a function
|
|
67
|
-
// or object. preinitialize will run before any instantiation logic is run in the View
|
|
68
|
-
preinitialize: function(){},
|
|
69
|
-
|
|
70
|
-
// Initialize is an empty function by default. Override it with your own
|
|
71
|
-
// initialization logic.
|
|
72
|
-
initialize: function(){},
|
|
73
|
-
|
|
74
|
-
// **render** is the core function that your view should override, in order
|
|
75
|
-
// to populate its element (`this.el`), with the appropriate HTML. The
|
|
76
|
-
// convention is for **render** to always return `this`.
|
|
77
|
-
render: function() {
|
|
78
|
-
isFunction(this.beforeRender) && this.beforeRender();
|
|
79
|
-
isFunction(this.toHTML) && render(this.toHTML(), this.el);
|
|
80
|
-
isFunction(this.afterRender) && this.afterRender();
|
|
81
|
-
return this;
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
// Remove this view by taking the element out of the DOM, and removing any
|
|
85
|
-
// applicable Backbone.Events listeners.
|
|
86
|
-
remove: function() {
|
|
87
|
-
this._removeElement();
|
|
88
|
-
this.stopListening();
|
|
89
|
-
return this;
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
// Remove this view's element from the document and all event listeners
|
|
93
|
-
// attached to it. Exposed for subclasses using an alternative DOM
|
|
94
|
-
// manipulation API.
|
|
95
|
-
_removeElement: function() {
|
|
96
|
-
this.undelegateEvents();
|
|
97
|
-
if (this.el.parentNode) this.el.parentNode.removeChild(this.el);
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
// Change the view's element (`this.el` property) and re-delegate the
|
|
101
|
-
// view's events on the new element.
|
|
102
|
-
setElement: function(element) {
|
|
103
|
-
this.undelegateEvents();
|
|
104
|
-
this._setElement(element);
|
|
105
|
-
this.delegateEvents();
|
|
106
|
-
return this;
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
// Apply the `element` to the view. `element` can be a CSS selector,
|
|
110
|
-
// a string of HTML, or an Element node. If passed a NodeList or CSS
|
|
111
|
-
// selector, uses just the first match.
|
|
112
|
-
_setElement: function(element) {
|
|
113
|
-
if (typeof element == 'string') {
|
|
114
|
-
if (paddedLt.test(element)) {
|
|
115
|
-
const el = document.createElement('div');
|
|
116
|
-
el.innerHTML = element;
|
|
117
|
-
this.el = el.firstChild;
|
|
118
|
-
} else {
|
|
119
|
-
this.el = document.querySelector(element);
|
|
120
|
-
}
|
|
121
|
-
} else if (element && !isElement(element) && element.length) {
|
|
122
|
-
this.el = element[0];
|
|
123
|
-
} else {
|
|
124
|
-
this.el = element;
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
// Set callbacks, where `this.events` is a hash of
|
|
129
|
-
//
|
|
130
|
-
// *{"event selector": "callback"}*
|
|
131
|
-
//
|
|
132
|
-
// {
|
|
133
|
-
// 'mousedown .title': 'edit',
|
|
134
|
-
// 'click .button': 'save',
|
|
135
|
-
// 'click .open': function(e) { ... }
|
|
136
|
-
// }
|
|
137
|
-
//
|
|
138
|
-
// pairs. Callbacks will be bound to the view, with `this` set properly.
|
|
139
|
-
// Uses event delegation for efficiency.
|
|
140
|
-
// Omitting the selector binds the event to `this.el`.
|
|
141
|
-
delegateEvents: function(events) {
|
|
142
|
-
events || (events = result(this, 'events'));
|
|
143
|
-
if (!events) return this;
|
|
144
|
-
this.undelegateEvents();
|
|
145
|
-
for (const key in events) {
|
|
146
|
-
let method = events[key];
|
|
147
|
-
if (!isFunction(method)) method = this[method];
|
|
148
|
-
if (!method) continue;
|
|
149
|
-
const match = key.match(delegateEventSplitter);
|
|
150
|
-
this.delegate(match[1], match[2], method.bind(this));
|
|
151
|
-
}
|
|
152
|
-
return this;
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
// Make a event delegation handler for the given `eventName` and `selector`
|
|
156
|
-
// and attach it to `this.el`.
|
|
157
|
-
// If selector is empty, the listener will be bound to `this.el`. If not, a
|
|
158
|
-
// new handler that will recursively traverse up the event target's DOM
|
|
159
|
-
// hierarchy looking for a node that matches the selector. If one is found,
|
|
160
|
-
// the event's `delegateTarget` property is set to it and the return the
|
|
161
|
-
// result of calling bound `listener` with the parameters given to the
|
|
162
|
-
// handler.
|
|
163
|
-
delegate: function(eventName, selector, listener) {
|
|
164
|
-
const root = this.el;
|
|
165
|
-
if (!root) {
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
if (typeof selector === 'function') {
|
|
169
|
-
listener = selector;
|
|
170
|
-
selector = null;
|
|
171
|
-
}
|
|
172
|
-
// Given that `focus` and `blur` events do not bubble, do not delegate these events
|
|
173
|
-
if (['focus', 'blur'].indexOf(eventName) !== -1) {
|
|
174
|
-
const els = this.el.querySelectorAll(selector);
|
|
175
|
-
for (let i = 0, len = els.length; i < len; i++) {
|
|
176
|
-
const item = els[i];
|
|
177
|
-
item.addEventListener(eventName, listener, false);
|
|
178
|
-
this._domEvents.push({el: item, eventName: eventName, handler: listener});
|
|
179
|
-
}
|
|
180
|
-
return listener;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const handler = selector ? function (e) {
|
|
184
|
-
let node = e.target || e.srcElement;
|
|
185
|
-
for (; node && node != root; node = node.parentNode) {
|
|
186
|
-
if (node.matches(selector)) {
|
|
187
|
-
e.delegateTarget = node;
|
|
188
|
-
listener(e);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
} : listener;
|
|
192
|
-
|
|
193
|
-
this.el.addEventListener(eventName, handler, false);
|
|
194
|
-
this._domEvents.push({el: this.el, eventName: eventName, handler: handler, listener: listener, selector: selector});
|
|
195
|
-
return this;
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
// Clears all callbacks previously bound to the view by `delegateEvents`.
|
|
199
|
-
// You usually don't need to use this, but may wish to if you have multiple
|
|
200
|
-
// Backbone views attached to the same DOM element.
|
|
201
|
-
undelegateEvents: function() {
|
|
202
|
-
if (this.el) {
|
|
203
|
-
for (let i = 0, len = this._domEvents.length; i < len; i++) {
|
|
204
|
-
const item = this._domEvents[i];
|
|
205
|
-
item.el.removeEventListener(item.eventName, item.handler, false);
|
|
206
|
-
}
|
|
207
|
-
this._domEvents.length = 0;
|
|
208
|
-
}
|
|
209
|
-
return this;
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
// A finer-grained `undelegateEvents` for removing a single delegated event.
|
|
213
|
-
// `selector` and `listener` are both optional.
|
|
214
|
-
undelegate: function(eventName, selector, listener) {
|
|
215
|
-
if (typeof selector === 'function') {
|
|
216
|
-
listener = selector;
|
|
217
|
-
selector = null;
|
|
218
|
-
}
|
|
219
|
-
if (this.el) {
|
|
220
|
-
const handlers = this._domEvents.slice();
|
|
221
|
-
let i = handlers.length;
|
|
222
|
-
while (i--) {
|
|
223
|
-
const item = handlers[i];
|
|
224
|
-
const match = item.eventName === eventName &&
|
|
225
|
-
(listener ? item.listener === listener : true) &&
|
|
226
|
-
(selector ? item.selector === selector : true);
|
|
227
|
-
|
|
228
|
-
if (!match) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
item.el.removeEventListener(item.eventName, item.handler, false);
|
|
232
|
-
this._domEvents.splice(i, 1);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return this;
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
// Produces a DOM element to be assigned to your view. Exposed for
|
|
239
|
-
// subclasses using an alternative DOM manipulation API.
|
|
240
|
-
_createElement: function(tagName) {
|
|
241
|
-
return document.createElement(tagName);
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
// Ensure that the View has a DOM element to render into.
|
|
245
|
-
// If `this.el` is a string, pass it through `$()`, take the first
|
|
246
|
-
// matching element, and re-assign it to `el`. Otherwise, create
|
|
247
|
-
// an element from the `id`, `className` and `tagName` properties.
|
|
248
|
-
_ensureElement: function() {
|
|
249
|
-
if (!this.el) {
|
|
250
|
-
const attrs = extend({}, result(this, 'attributes'));
|
|
251
|
-
if (this.id) attrs.id = result(this, 'id');
|
|
252
|
-
if (this.className) attrs['class'] = result(this, 'className');
|
|
253
|
-
this.setElement(this._createElement(result(this, 'tagName')));
|
|
254
|
-
this._setAttributes(attrs);
|
|
255
|
-
} else {
|
|
256
|
-
this.setElement(result(this, 'el'));
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
|
|
260
|
-
// Set attributes from a hash on this view's element. Exposed for
|
|
261
|
-
// subclasses using an alternative DOM manipulation API.
|
|
262
|
-
_setAttributes: function(attrs) {
|
|
263
|
-
for (const attr in attrs) {
|
|
264
|
-
attr in this.el ? this.el[attr] = attrs[attr] : this.el.setAttribute(attr, attrs[attr]);
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
});
|