@webqit/oohtml 1.9.24 → 1.10.1

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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "wicg-proposal"
15
15
  ],
16
16
  "homepage": "https://webqit.io/tooling/oohtml",
17
- "version": "1.9.24",
17
+ "version": "1.10.1",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -109,7 +109,7 @@ export default function init( _config = {} ) {
109
109
  });
110
110
  };
111
111
 
112
- const discoverContents = (contents, node, path, mutationType = null, fireEvents = true) => {
112
+ const discoverContents = (node, contentNode, path, mutationType = null, fireEvents = true) => {
113
113
 
114
114
  // -----------------------
115
115
  // Templates and exports
@@ -123,8 +123,8 @@ export default function init( _config = {} ) {
123
123
  var _path = (path ? path + '/' : '') + templateName;
124
124
  if (mutationType === 'removed') {
125
125
  _internals(node, 'oohtml', 'templates').delete(templateName)
126
- if (_internals(node, 'oohtml').get('parentTemplate') === node) {
127
- _internals(node, 'oohtml').delete('parentTemplate');
126
+ if (_internals(el, 'oohtml').get('parentTemplate') === node) {
127
+ _internals(el, 'oohtml').delete('parentTemplate');
128
128
  }
129
129
  if (eventsObject) {
130
130
  eventsObject.removedTemplates[templateName] = el;
@@ -137,7 +137,7 @@ export default function init( _config = {} ) {
137
137
  }
138
138
  }
139
139
  // Recurse
140
- discoverContents(el.content, el, _path, mutationType, fireEvents);
140
+ discoverContents(el, el.content, _path, mutationType, fireEvents);
141
141
  } else {
142
142
  const manageExportItem = exportItem => {
143
143
  var exportId = exportItem.getAttribute(_meta.get('attr.exportgroup')) || 'default';
@@ -183,7 +183,7 @@ export default function init( _config = {} ) {
183
183
  // Run...
184
184
  node.modulemutationsType = mutationType;
185
185
  const eventsObject = { addedTemplates: Object.create(null), removedTemplates: Object.create(null), addedExports: Object.create(null), removedExports: Object.create(null), };
186
- _arrFrom(contents.children).forEach(el => manageComponent(el, eventsObject, mutationType, fireEvents));
186
+ _arrFrom(contentNode.children).forEach(el => manageComponent(el, eventsObject, mutationType, fireEvents));
187
187
  if (fireEvents) {
188
188
  fireDocumentTemplateEvent('templatemutation', eventsObject, path);
189
189
  }
@@ -192,14 +192,28 @@ export default function init( _config = {} ) {
192
192
  // Handle content loading
193
193
  if (mutationType === 'added' && !_internals(node, 'oohtml').get('onLiveMode')) {
194
194
  _internals(node, 'oohtml').set('onLiveMode', true);
195
- if (node.getAttribute('src') && !node.content.children.length) {
196
- loadingTemplates.push(loadTemplateContent(node, path));
195
+ const honourSrc = () => {
196
+ if (node.content.children.length) return;
197
+ _internals(node, 'oohtml').delete('queryCallback');
198
+ return loadTemplateContent(node, path);
199
+ };
200
+ if (node.getAttribute('src')) {
201
+ if (node.getAttribute('loading') === 'lazy') {
202
+ _internals(node, 'oohtml').set('queryCallback', honourSrc);
203
+ } else {
204
+ loadingTemplates.push(honourSrc());
205
+ }
197
206
  }
198
207
  mutations.onAttrChange(node, mr => {
199
- if (mr[0].target.getAttribute(mr[0].attributeName) !== mr[0].oldValue) {
200
- loadTemplateContent(node, path);
208
+ if (mr[0].target.getAttribute(mr[0].attributeName) === mr[0].oldValue) return;
209
+ if (node.getAttribute('loading') === 'lazy') {
210
+ _internals(node, 'oohtml').set('queryCallback', honourSrc);
211
+ } else if (mr[0].attributeName === 'loading') {
212
+ _internals(node, 'oohtml').delete('queryCallback');
213
+ } else {
214
+ honourSrc();
201
215
  }
202
- }, ['src']);
216
+ }, ['src', 'loading']);
203
217
 
204
218
  // -----------------------
205
219
  // Watch mutations
@@ -211,7 +225,7 @@ export default function init( _config = {} ) {
211
225
  });
212
226
  fireDocumentTemplateEvent('templatemutation', eventsObject, path);
213
227
  });
214
- mo.observe(contents, {childList: true});
228
+ mo.observe(contentNode, {childList: true});
215
229
  }
216
230
 
217
231
  };
@@ -239,6 +253,9 @@ export default function init( _config = {} ) {
239
253
  }
240
254
  Object.defineProperty(TemplateElementClass.prototype, _meta.get('api.templates'), {
241
255
  get: function() {
256
+ if (_internals(this, 'oohtml').has('queryCallback')) {
257
+ _internals(this, 'oohtml').get('queryCallback')();
258
+ }
242
259
  return mapToObject(_internals(this, 'oohtml', 'templates'));
243
260
  }
244
261
  });
@@ -247,6 +264,9 @@ export default function init( _config = {} ) {
247
264
  }
248
265
  Object.defineProperty(TemplateElementClass.prototype, _meta.get('api.exports'), {
249
266
  get: function() {
267
+ if (_internals(this, 'oohtml').has('queryCallback')) {
268
+ _internals(this, 'oohtml').get('queryCallback')();
269
+ }
250
270
  return mapToObject(_internals(this, 'oohtml', 'exports'));
251
271
  }
252
272
  });
@@ -293,25 +313,24 @@ export default function init( _config = {} ) {
293
313
  var name = el.getAttribute(_meta.get('attr.moduleid'));
294
314
  if (!el.closest(_meta.get('element.import')) && validateModuleName(name)) {
295
315
  _internals(document, 'oohtml', 'templates').set(name, el);
296
- discoverContents(el.content, el, name, 'added', false);
316
+ discoverContents(el, el.content, name, 'added', false);
297
317
  }
298
318
  });
299
319
  mutations.onPresenceChange(templateSelector, async (els, presence) => {
300
320
  const eventsObject = { addedTemplates: Object.create(null), removedTemplates: Object.create(null), addedExports: Object.create(null), removedExports: Object.create(null), };
301
321
  els.forEach(el => {
302
322
  var name = el.getAttribute(_meta.get('attr.moduleid'));
303
- if (!el.closest(_meta.get('element.import')) && validateModuleName(name)) {
304
- if (presence) {
305
- _internals(document, 'oohtml', 'templates').set(name, el);
306
- discoverContents(el.content, el, name, 'added');
307
- eventsObject.addedTemplates[name] = el;
308
- } else {
309
- if (_internals(document, 'oohtml', 'templates').get(name) === el) {
310
- _internals(document, 'oohtml', 'templates').delete(name);
311
- }
312
- discoverContents(el.content, el, name, 'removed');
313
- eventsObject.removedTemplates[name] = el;
323
+ if (el.closest(_meta.get('element.import')) || !validateModuleName(name)) return;
324
+ if (presence) {
325
+ _internals(document, 'oohtml', 'templates').set(name, el);
326
+ discoverContents(el, el.content, name, 'added');
327
+ eventsObject.addedTemplates[name] = el;
328
+ } else {
329
+ if (_internals(document, 'oohtml', 'templates').get(name) === el) {
330
+ _internals(document, 'oohtml', 'templates').delete(name);
314
331
  }
332
+ discoverContents(el, el.content, name, 'removed');
333
+ eventsObject.removedTemplates[name] = el;
315
334
  }
316
335
  });
317
336
  fireDocumentTemplateEvent('templatemutation', eventsObject, '');
package/src/util.js CHANGED
@@ -116,7 +116,7 @@ const evalModuleExpr = (contexts, segment, collectionCallback) => {
116
116
  return contexts.reduce((list, context) => {
117
117
  var collection = collectionCallback(context);
118
118
  if (_reference === '*') {
119
- _reference = '(' + collection.keys().join('+') + ')';
119
+ _reference = '(' + collection.keys().join('+') + ')';
120
120
  }
121
121
  var itemArray = _wrapped(_reference, '(', ')') ? evalModuleExpr([context], _unwrap(_reference, '(', ')'), collectionCallback) : _arrFrom(collection.get(_reference), false);
122
122
  // ------------
@@ -151,20 +151,25 @@ const execScopeQuery = function(contexts, path, collectionCallback, advancementC
151
151
  return [];
152
152
  }
153
153
 
154
- var segment = path.shift(), isStopSegmentIfCount;
154
+ let segment = path.shift(), isStopSegmentIfCount;
155
155
  if (segment.endsWith('.')) {
156
156
  isStopSegmentIfCount = true;
157
157
  segment = segment.substr(0, segment.length - 1).trim();
158
158
  }
159
159
  // -----------
160
- var modules = evalModuleExpr(contexts, segment, collectionCallback);
160
+ let modules = evalModuleExpr(contexts, segment, collectionCallback);
161
+ modules.forEach(context => {
162
+ if (_internals(context, 'oohtml').has('queryCallback')) {
163
+ _internals(context, 'oohtml').get('queryCallback')();
164
+ }
165
+ });
161
166
  // -----------
162
167
  if (modules.length && isStopSegmentIfCount) {
163
168
  return modules;
164
169
  }
165
170
  // -----------
166
171
  if (path.length) {
167
- var submodules = execScopeQuery(modules, path.slice(), collectionCallback, advancementCallback, level + 1);
172
+ let submodules = execScopeQuery(modules, path.slice(), collectionCallback, advancementCallback, level + 1);
168
173
  if (submodules === -1) {
169
174
  return advancementCallback(modules, level, true);
170
175
  }