@webqit/oohtml 2.1.9 → 2.1.12
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/bindings-api.js +1 -1
- package/dist/bindings-api.js.map +3 -3
- package/dist/context-api.js +1 -1
- package/dist/context-api.js.map +3 -3
- package/dist/html-imports.js +1 -1
- package/dist/html-imports.js.map +3 -3
- package/dist/html-modules.js +1 -1
- package/dist/html-modules.js.map +3 -3
- package/dist/main.js +7 -7
- package/dist/main.js.map +3 -3
- package/dist/namespace-api.js +2 -0
- package/dist/namespace-api.js.map +7 -0
- package/dist/scoped-js.js +7 -7
- package/dist/scoped-js.js.map +3 -3
- package/package.json +6 -6
- package/src/bindings-api/index.js +25 -26
- package/src/context-api/HTMLContext.js +3 -3
- package/src/context-api/index.js +13 -17
- package/src/html-imports/_HTMLImportElement.js +13 -15
- package/src/html-imports/index.js +20 -26
- package/src/html-modules/HTMLExportsManager.js +17 -17
- package/src/html-modules/_HTMLImportsContext.js +6 -6
- package/src/html-modules/index.js +31 -37
- package/src/index.js +8 -10
- package/src/{namespaced-html → namespace-api}/index.js +35 -40
- package/src/scoped-js/Compiler.js +7 -7
- package/src/scoped-js/index.js +19 -24
- package/src/targets.browser.js +2 -2
- package/src/util.js +14 -2
- package/test/index.js +12 -10
- package/dist/namespaced-html.js +0 -2
- package/dist/namespaced-html.js.map +0 -7
- package/dist/state-api.js +0 -2
- package/dist/state-api.js.map +0 -7
- /package/src/{namespaced-html → namespace-api}/targets.browser.js +0 -0
- /package/test/{namespaced-html.test.js → namespace-api.test.js} +0 -0
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"wicg-proposal"
|
|
15
15
|
],
|
|
16
16
|
"homepage": "https://webqit.io/tooling/oohtml",
|
|
17
|
-
"version": "2.1.
|
|
17
|
+
"version": "2.1.12",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "mocha --extension .test.js --exit",
|
|
34
34
|
"test:coverage": "c8 --reporter=text-lcov npm run test | coveralls",
|
|
35
|
-
"build": "esbuild main=src/targets.browser.js
|
|
35
|
+
"build": "esbuild main=src/targets.browser.js bindings-api=src/bindings-api/targets.browser.js context-api=src/context-api/targets.browser.js namespace-api=src/namespace-api/targets.browser.js html-modules=src/html-modules/targets.browser.js html-imports=src/html-imports/targets.browser.js scoped-js=src/scoped-js/targets.browser.js --bundle --minify --sourcemap --outdir=dist",
|
|
36
36
|
"preversion": "npm run test && npm run build && git add -A dist",
|
|
37
37
|
"postversion": "npm publish",
|
|
38
38
|
"postpublish": "git push && git push --tags"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@webqit/dom": "^2.0.
|
|
42
|
-
"@webqit/observer": "^2.0.
|
|
43
|
-
"@webqit/subscript": "^2.1.
|
|
44
|
-
"@webqit/util": "^0.8.
|
|
41
|
+
"@webqit/dom": "^2.0.5",
|
|
42
|
+
"@webqit/observer": "^2.0.5",
|
|
43
|
+
"@webqit/subscript": "^2.1.39",
|
|
44
|
+
"@webqit/util": "^0.8.10"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"chai": "^4.3.4",
|
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import wqDom from '@webqit/dom';
|
|
6
5
|
import Observer from '@webqit/observer';
|
|
7
|
-
import { _ } from '../util.js';
|
|
6
|
+
import { _, _init } from '../util.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @init
|
|
11
10
|
*
|
|
12
|
-
* @param Object $
|
|
11
|
+
* @param Object $config
|
|
13
12
|
*/
|
|
14
|
-
export default function init( $
|
|
15
|
-
|
|
16
|
-
if ( !window.wq ) { window.wq = {}; }
|
|
17
|
-
window.wq.Observer = Observer;
|
|
18
|
-
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
13
|
+
export default function init( $config = {} ) {
|
|
14
|
+
const { config, window } = _init.call( this, 'bindings-api', $config, {
|
|
19
15
|
api: { bind: 'bind', bindings: 'bindings', },
|
|
20
16
|
} );
|
|
21
|
-
|
|
17
|
+
window.webqit.Observer = Observer;
|
|
18
|
+
exposeAPIs.call( window, config );
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
export { Observer }
|
|
@@ -40,28 +37,28 @@ function getBindingsObject( node ) {
|
|
|
40
37
|
/**
|
|
41
38
|
* Exposes Bindings with native APIs.
|
|
42
39
|
*
|
|
43
|
-
* @param Object
|
|
40
|
+
* @param Object config
|
|
44
41
|
*
|
|
45
42
|
* @return Void
|
|
46
43
|
*/
|
|
47
|
-
function exposeAPIs(
|
|
44
|
+
function exposeAPIs( config ) {
|
|
48
45
|
const window = this;
|
|
49
46
|
// Assertions
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
if (
|
|
53
|
-
if (
|
|
47
|
+
if ( config.api.bind in window.document ) { throw new Error( `document already has a "${ config.api.bind }" property!` ); }
|
|
48
|
+
if ( config.api.bindings in window.document ) { throw new Error( `document already has a "${ config.api.bindings }" property!` ); }
|
|
49
|
+
if ( config.api.bind in window.Element.prototype ) { throw new Error( `The "Element" class already has a "${ config.api.bind }" property!` ); }
|
|
50
|
+
if ( config.api.bindings in window.Element.prototype ) { throw new Error( `The "Element" class already has a "${ config.api.bindings }" property!` ); }
|
|
54
51
|
// Definitions
|
|
55
|
-
Object.defineProperty( window.document,
|
|
56
|
-
return applyBindings( window.document, bindings,
|
|
52
|
+
Object.defineProperty( window.document, config.api.bind, { value: function( bindings, config = {} ) {
|
|
53
|
+
return applyBindings( window.document, bindings, config );
|
|
57
54
|
} });
|
|
58
|
-
Object.defineProperty( window.document,
|
|
55
|
+
Object.defineProperty( window.document, config.api.bindings, { get: function() {
|
|
59
56
|
return Observer.proxy( getBindingsObject( window.document ) );
|
|
60
57
|
} });
|
|
61
|
-
Object.defineProperty( window.Element.prototype,
|
|
62
|
-
return applyBindings( this, bindings,
|
|
58
|
+
Object.defineProperty( window.Element.prototype, config.api.bind, { value: function( bindings, config = {} ) {
|
|
59
|
+
return applyBindings( this, bindings, config );
|
|
63
60
|
} });
|
|
64
|
-
Object.defineProperty( window.Element.prototype,
|
|
61
|
+
Object.defineProperty( window.Element.prototype, config.api.bindings, { get: function() {
|
|
65
62
|
return Observer.proxy( getBindingsObject( this ) );
|
|
66
63
|
} } );
|
|
67
64
|
}
|
|
@@ -75,11 +72,13 @@ function exposeAPIs( params ) {
|
|
|
75
72
|
*
|
|
76
73
|
* @return Void
|
|
77
74
|
*/
|
|
78
|
-
function applyBindings( target, bindings,
|
|
75
|
+
function applyBindings( target, bindings, { merge, namespace } = {} ) {
|
|
79
76
|
const bindingsObj = getBindingsObject( target );
|
|
80
|
-
const
|
|
77
|
+
const $params = { namespace };
|
|
78
|
+
if ( merge ) return Observer.set( bindingsObj, bindings, $params );;
|
|
79
|
+
const exitingKeys = Observer.ownKeys( bindingsObj, $params ).filter( key => !( key in bindings ) );
|
|
81
80
|
return Observer.batch( bindingsObj, () => {
|
|
82
|
-
if ( exitingKeys.length ) { Observer.deleteProperty( bindingsObj, exitingKeys, params ); }
|
|
83
|
-
Observer.set( bindingsObj, bindings, params );
|
|
84
|
-
} );
|
|
81
|
+
if ( exitingKeys.length ) { Observer.deleteProperty( bindingsObj, exitingKeys, $params ); }
|
|
82
|
+
return Observer.set( bindingsObj, bindings, $params );
|
|
83
|
+
}, $params );
|
|
85
84
|
}
|
|
@@ -8,9 +8,9 @@ import HTMLContextManager from './HTMLContextManager.js';
|
|
|
8
8
|
export default class HTMLContext {
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @
|
|
11
|
+
* @config
|
|
12
12
|
*/
|
|
13
|
-
static get
|
|
13
|
+
static get config() {
|
|
14
14
|
return {};
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -41,7 +41,7 @@ export default class HTMLContext {
|
|
|
41
41
|
static createId( host, fields = {} ) {
|
|
42
42
|
const id = { type: 'HTMLModules', ...fields };
|
|
43
43
|
if ( id.name ) return id;
|
|
44
|
-
if ( host.getAttribute && !( id.name = ( host.getAttribute( this.
|
|
44
|
+
if ( host.getAttribute && !( id.name = ( host.getAttribute( this.config.context.attr.contextname ) || '' ).trim() ) ) {
|
|
45
45
|
delete id.name;
|
|
46
46
|
} else if ( !host.ownerDocument ) {
|
|
47
47
|
id.name = 'root';
|
package/src/context-api/index.js
CHANGED
|
@@ -2,47 +2,43 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { _init } from '../util.js';
|
|
6
6
|
import HTMLContextManager from './HTMLContextManager.js';
|
|
7
7
|
import HTMLContext from './HTMLContext.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Initializes HTML Modules.
|
|
11
11
|
*
|
|
12
|
-
* @param $
|
|
12
|
+
* @param $config Object
|
|
13
13
|
*
|
|
14
14
|
* @return Void
|
|
15
15
|
*/
|
|
16
|
-
export default function init( $
|
|
17
|
-
const
|
|
18
|
-
if ( !window.wq ) { window.wq = {}; }
|
|
19
|
-
window.wq.HTMLContextManager = HTMLContextManager;
|
|
20
|
-
window.wq.HTMLContext = HTMLContext;
|
|
21
|
-
// -------
|
|
22
|
-
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
16
|
+
export default function init( $config = {} ) {
|
|
17
|
+
const { config, window } = _init.call( this, 'context-api', $config, {
|
|
23
18
|
api: { context: 'context', },
|
|
24
19
|
} );
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
window.webqit.HTMLContextManager = HTMLContextManager;
|
|
21
|
+
window.webqit.HTMLContext = HTMLContext;
|
|
22
|
+
exposeModulesObjects.call( window, config );
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
26
|
* Exposes HTML Modules with native APIs.
|
|
31
27
|
*
|
|
32
|
-
* @param Object
|
|
28
|
+
* @param Object config
|
|
33
29
|
*
|
|
34
30
|
* @return Void
|
|
35
31
|
*/
|
|
36
|
-
function exposeModulesObjects(
|
|
32
|
+
function exposeModulesObjects( config ) {
|
|
37
33
|
const window = this;
|
|
38
34
|
// Assertions
|
|
39
|
-
if (
|
|
40
|
-
if (
|
|
35
|
+
if ( config.api.context in window.document ) { throw new Error( `document already has a "${ config.api.context }" property!` ); }
|
|
36
|
+
if ( config.api.context in window.HTMLElement.prototype ) { throw new Error( `The "HTMLElement" class already has a "${ config.api.context }" property!` ); }
|
|
41
37
|
// Definitions
|
|
42
|
-
Object.defineProperty( window.document,
|
|
38
|
+
Object.defineProperty( window.document, config.api.context, { get: function() {
|
|
43
39
|
return HTMLContextManager.instance( window.document );
|
|
44
40
|
} } );
|
|
45
|
-
Object.defineProperty( window.HTMLElement.prototype,
|
|
41
|
+
Object.defineProperty( window.HTMLElement.prototype, config.api.context, { get: function() {
|
|
46
42
|
return HTMLContextManager.instance( this );
|
|
47
43
|
} } );
|
|
48
44
|
}
|
|
@@ -9,16 +9,14 @@ import { _ } from '../util.js';
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates the HTMLImportElement class.
|
|
11
11
|
*
|
|
12
|
-
* @param Object
|
|
12
|
+
* @param Object config
|
|
13
13
|
*
|
|
14
14
|
* @return HTMLImportElement
|
|
15
15
|
*/
|
|
16
|
-
export default function(
|
|
17
|
-
const window = this, { dom } = window.
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
: class {};
|
|
21
|
-
return class HTMLImportElement extends BaseExportElement {
|
|
16
|
+
export default function( config ) {
|
|
17
|
+
const window = this, { dom } = window.webqit;
|
|
18
|
+
const BaseElement = config.import.tagName.includes( '-' ) ? window.HTMLElement : class {};
|
|
19
|
+
return class HTMLImportElement extends BaseElement {
|
|
22
20
|
|
|
23
21
|
/**
|
|
24
22
|
* @instance
|
|
@@ -28,7 +26,7 @@ export default function( params ) {
|
|
|
28
26
|
* @returns
|
|
29
27
|
*/
|
|
30
28
|
static instance( node ) {
|
|
31
|
-
if (
|
|
29
|
+
if ( config.import.tagName.includes( '-' ) && ( node instanceof this ) ) return node;
|
|
32
30
|
return _( node ).get( 'import::instance' ) || new this( node );;
|
|
33
31
|
}
|
|
34
32
|
|
|
@@ -61,7 +59,7 @@ export default function( params ) {
|
|
|
61
59
|
|
|
62
60
|
priv.hydrate = ( anchorNode, slottedElements ) => {
|
|
63
61
|
// ----------------
|
|
64
|
-
priv.moduleRef = ( this.el.getAttribute(
|
|
62
|
+
priv.moduleRef = ( this.el.getAttribute( config.import.attr.moduleref ) || '' ).trim();
|
|
65
63
|
priv.setAnchorNode( anchorNode );
|
|
66
64
|
priv.autoRestore( () => {
|
|
67
65
|
slottedElements.forEach( slottedElement => {
|
|
@@ -73,9 +71,9 @@ export default function( params ) {
|
|
|
73
71
|
priv.hydrationImportRequest = new AbortController;
|
|
74
72
|
priv.importRequest( modules => {
|
|
75
73
|
if ( priv.originalsRemapped ) { return this.fill( modules ); }
|
|
76
|
-
const identifiersMap = [ ...modules ].map( module => ( { el: module, exportId: module.getAttribute(
|
|
74
|
+
const identifiersMap = [ ...modules ].map( module => ( { el: module, exportId: module.getAttribute( config.export.attr.exportid ) || '#default', tagName: module.tagName, } ) );
|
|
77
75
|
slottedElements.forEach( slottedElement => {
|
|
78
|
-
const tagName = slottedElement.tagName, exportId = slottedElement.getAttribute(
|
|
76
|
+
const tagName = slottedElement.tagName, exportId = slottedElement.getAttribute( config.export.attr.exportid ) || '#default';
|
|
79
77
|
const originalsMatch = identifiersMap.filter( moduleIdentifiers => tagName === moduleIdentifiers.tagName && exportId === moduleIdentifiers.exportId );
|
|
80
78
|
if ( originalsMatch.length !== 1 ) return;
|
|
81
79
|
_( slottedElement ).set( 'original@imports', originalsMatch[ 0 ].el );
|
|
@@ -112,7 +110,7 @@ export default function( params ) {
|
|
|
112
110
|
// Totally initialize this instance?
|
|
113
111
|
if ( !priv.anchorNode ) { priv.setAnchorNode( this.createAnchorNode() ); }
|
|
114
112
|
if ( priv.moduleRefRealtime ) return;
|
|
115
|
-
priv.moduleRefRealtime = dom.realtime( this.el ).attr(
|
|
113
|
+
priv.moduleRefRealtime = dom.realtime( this.el ).attr( config.import.attr.moduleref, ( record, { signal } ) => {
|
|
116
114
|
priv.moduleRef = record.value;
|
|
117
115
|
;
|
|
118
116
|
// Below, we ignore first restore from hydration
|
|
@@ -138,7 +136,7 @@ export default function( params ) {
|
|
|
138
136
|
* @return Element
|
|
139
137
|
*/
|
|
140
138
|
createAnchorNode() {
|
|
141
|
-
if ( !
|
|
139
|
+
if ( !config.isomorphic ) { return window.document.createTextNode( '' ) }
|
|
142
140
|
return window.document.createComment( this.el.outerHTML );
|
|
143
141
|
}
|
|
144
142
|
|
|
@@ -174,8 +172,8 @@ export default function( params ) {
|
|
|
174
172
|
// Clone each slottable element and give it a reference to its original
|
|
175
173
|
const slottableElementClone = slottableElement.cloneNode( true );
|
|
176
174
|
// The folllowing references must be set before adding to DODM
|
|
177
|
-
if ( !slottableElementClone.hasAttribute(
|
|
178
|
-
slottableElementClone.toggleAttribute(
|
|
175
|
+
if ( !slottableElementClone.hasAttribute( config.export.attr.exportid ) ) {
|
|
176
|
+
slottableElementClone.toggleAttribute( config.export.attr.exportid, true );
|
|
179
177
|
}
|
|
180
178
|
_( slottableElementClone ).set( 'original@imports', slottableElement );
|
|
181
179
|
_( slottableElementClone ).set( 'slot@imports', this.el );
|
|
@@ -2,45 +2,39 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import wqDom from '@webqit/dom';
|
|
6
5
|
import _HTMLImportElement from './_HTMLImportElement.js';
|
|
7
|
-
import { _ } from '../util.js';
|
|
6
|
+
import { _, _init } from '../util.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Initializes HTML Modules.
|
|
11
10
|
*
|
|
12
|
-
* @param $
|
|
11
|
+
* @param $config Object
|
|
13
12
|
*
|
|
14
13
|
* @return Void
|
|
15
14
|
*/
|
|
16
|
-
export default function init( $
|
|
17
|
-
const
|
|
18
|
-
if ( !window.wq ) { window.wq = {}; }
|
|
19
|
-
// -------
|
|
20
|
-
const params = dom.meta( 'oohtml' ).copyWithDefaults( $params, {
|
|
15
|
+
export default function init( $config = {} ) {
|
|
16
|
+
const { config, dom, window } = _init.call( this, 'html-imports', $config, {
|
|
21
17
|
import: { tagName: 'import', attr: { moduleref: 'module' }, },
|
|
22
18
|
export: { attr: { exportid: 'exportid' }, },
|
|
23
19
|
isomorphic: true,
|
|
24
20
|
} );
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
dom.ready( () => hydration.call( this, params ) );
|
|
30
|
-
realtime.call( this, params );
|
|
21
|
+
config.slottedElementsSelector = `[${ window.CSS.escape( config.export.attr.exportid ) }]`;
|
|
22
|
+
window.webqit.HTMLImportElement = _HTMLImportElement.call( window, config );
|
|
23
|
+
dom.ready( () => hydration.call( window, config ) );
|
|
24
|
+
realtime.call( window, config );
|
|
31
25
|
}
|
|
32
26
|
|
|
33
27
|
/**
|
|
34
28
|
* Performs realtime capture of elements and their attributes
|
|
35
29
|
* and their module query results; then resolves the respective import elements.
|
|
36
30
|
*
|
|
37
|
-
* @param Object
|
|
31
|
+
* @param Object config
|
|
38
32
|
*
|
|
39
33
|
* @return Void
|
|
40
34
|
*/
|
|
41
|
-
function realtime(
|
|
42
|
-
const window = this, { dom, HTMLImportElement } = window.
|
|
43
|
-
dom.realtime( window.document ).observe(
|
|
35
|
+
function realtime( config ) {
|
|
36
|
+
const window = this, { dom, HTMLImportElement } = window.webqit;
|
|
37
|
+
dom.realtime( window.document ).observe( config.import.tagName, record => {
|
|
44
38
|
record.entrants.forEach( node => handleRealtime( node, true, record ) );
|
|
45
39
|
record.exits.forEach( node => handleRealtime( node, false, record ) );
|
|
46
40
|
}, { subtree: true, timing: 'sync' } );
|
|
@@ -54,27 +48,27 @@ function realtime( params ) {
|
|
|
54
48
|
/**
|
|
55
49
|
* Performs hydration for server-slotted elements.
|
|
56
50
|
*
|
|
57
|
-
* @param Object
|
|
51
|
+
* @param Object config
|
|
58
52
|
*
|
|
59
53
|
* @return Void
|
|
60
54
|
*/
|
|
61
|
-
function hydration(
|
|
62
|
-
const window = this, { HTMLImportElement } = window.
|
|
55
|
+
function hydration( config ) {
|
|
56
|
+
const window = this, { HTMLImportElement } = window.webqit;
|
|
63
57
|
function scan( context ) {
|
|
64
58
|
const slottedElements = new Set;
|
|
65
59
|
context.childNodes.forEach( node => {
|
|
66
60
|
if ( node.nodeType === 1/** ELEMENT_NODE */ ) {
|
|
67
|
-
if ( !node.matches(
|
|
61
|
+
if ( !node.matches( config.slottedElementsSelector ) ) return;
|
|
68
62
|
if ( _( node ).get( 'slot@imports' ) ) return;
|
|
69
63
|
slottedElements.add( node );
|
|
70
64
|
} else if ( node.nodeType === 8/** COMMENT_NODE */ ) {
|
|
71
65
|
const nodeValue = node.nodeValue.trim();
|
|
72
|
-
if ( !nodeValue.startsWith( '<' +
|
|
73
|
-
if ( !nodeValue.endsWith( '</' +
|
|
66
|
+
if ( !nodeValue.startsWith( '<' + config.import.tagName ) ) return;
|
|
67
|
+
if ( !nodeValue.endsWith( '</' + config.import.tagName + '>' ) ) return;
|
|
74
68
|
const reviver = window.document.createElement( 'div' );
|
|
75
69
|
reviver.innerHTML = nodeValue;
|
|
76
70
|
const importEl = reviver.firstChild;
|
|
77
|
-
if ( !importEl.matches(
|
|
71
|
+
if ( !importEl.matches( config.import.tagName ) ) return;
|
|
78
72
|
HTMLImportElement.instance( importEl )[ '#' ].hydrate(
|
|
79
73
|
node/* the comment node */, slottedElements
|
|
80
74
|
);
|
|
@@ -82,7 +76,7 @@ function hydration( params ) {
|
|
|
82
76
|
}
|
|
83
77
|
} );
|
|
84
78
|
}
|
|
85
|
-
Array.from( window.document.querySelectorAll(
|
|
79
|
+
Array.from( window.document.querySelectorAll( config.slottedElementsSelector ) ).forEach( slottedElement => {
|
|
86
80
|
// hydration() might be running AFTER certain <slots> have resolved
|
|
87
81
|
// and slottedElement might be a just-resolved node
|
|
88
82
|
if ( _( slottedElement ).get( 'slot@imports' ) ) return;
|
|
@@ -11,24 +11,25 @@ export default class HTMLExportsManager {
|
|
|
11
11
|
/**
|
|
12
12
|
* @instance
|
|
13
13
|
*/
|
|
14
|
-
static instance( host,
|
|
15
|
-
return _( host ).get( 'exportsmanager::instance' ) || new this( host,
|
|
14
|
+
static instance( window, host, config ) {
|
|
15
|
+
return _( host ).get( 'exportsmanager::instance' ) || new this( window, host, config );
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @constructor
|
|
20
20
|
*/
|
|
21
|
-
constructor( host,
|
|
21
|
+
constructor( window, host, config = {}, parent = null, level = 0 ) {
|
|
22
22
|
_( host ).get( `exportsmanager::instance` )?.dispose();
|
|
23
23
|
_( host ).set( `exportsmanager::instance`, this );
|
|
24
24
|
this.host = host;
|
|
25
|
-
this.
|
|
25
|
+
this.window = window;
|
|
26
|
+
this.config = config;
|
|
26
27
|
this.parent = parent;
|
|
27
28
|
this.level = level;
|
|
28
29
|
this.modules = getModulesObject( this.host );
|
|
29
|
-
this.exportId = ( this.host.getAttribute( this.
|
|
30
|
+
this.exportId = ( this.host.getAttribute( this.config.template?.attr.exportid ) || '' ).trim();
|
|
30
31
|
this.validateExportId( this.exportId );
|
|
31
|
-
const dom =
|
|
32
|
+
const dom = this.window.webqit.dom;
|
|
32
33
|
// ----------
|
|
33
34
|
this.realtimeA = dom.realtime( this.host.content ).children( record => {
|
|
34
35
|
this.export( record.entrants, true );
|
|
@@ -71,18 +72,18 @@ export default class HTMLExportsManager {
|
|
|
71
72
|
const fragmentsExports = new Map;
|
|
72
73
|
entries.forEach( entry => {
|
|
73
74
|
if ( entry.nodeType !== 1 ) return;
|
|
74
|
-
const exportId = ( entry.getAttribute( this.
|
|
75
|
-
const isPackage = entry.matches( this.
|
|
75
|
+
const exportId = ( entry.getAttribute( this.config.export.attr.exportid ) || '' ).trim() || '#default';
|
|
76
|
+
const isPackage = entry.matches( this.config.templateSelector );
|
|
76
77
|
if ( exportId.startsWith( '#' ) ) {
|
|
77
78
|
this.validateExportId( exportId.substring( 1 ) );
|
|
78
79
|
if ( !fragmentsExports.has( exportId ) ) { fragmentsExports.set( exportId, [] ); }
|
|
79
80
|
fragmentsExports.get( exportId ).push( entry );
|
|
80
81
|
} else {
|
|
81
82
|
if ( isConnected ) {
|
|
82
|
-
if ( isPackage ) { new HTMLExportsManager( entry, this.
|
|
83
|
+
if ( isPackage ) { new HTMLExportsManager( this.window, entry, this.config, this.host, this.level + 1 ); }
|
|
83
84
|
Observer.set( this.modules, exportId, entry );
|
|
84
85
|
} else {
|
|
85
|
-
if ( isPackage ) {
|
|
86
|
+
if ( isPackage ) { HTMLExportsManager.instance( this.window, entry ).dispose(); }
|
|
86
87
|
Observer.deleteProperty( this.modules, exportId );
|
|
87
88
|
}
|
|
88
89
|
}
|
|
@@ -128,15 +129,14 @@ export default class HTMLExportsManager {
|
|
|
128
129
|
* @return Promise
|
|
129
130
|
*/
|
|
130
131
|
load( src ) {
|
|
131
|
-
const window = this.params.window;
|
|
132
132
|
if ( this.host.content.children.length ) return;
|
|
133
133
|
// Ongoing request?
|
|
134
134
|
if ( this.fetchInFlight?.src === src ) return this.fetchInFlight.request;
|
|
135
135
|
this.fetchInFlight?.controller.abort();
|
|
136
136
|
// The promise
|
|
137
137
|
const controller = new AbortController();
|
|
138
|
-
const fire = ( type, detail ) => this.host.dispatchEvent( new window.CustomEvent( type, { detail } ) );
|
|
139
|
-
const request = window.fetch( src, { signal: controller.signal } ).then( response => {
|
|
138
|
+
const fire = ( type, detail ) => this.host.dispatchEvent( new this.window.CustomEvent( type, { detail } ) );
|
|
139
|
+
const request = this.window.fetch( src, { signal: controller.signal } ).then( response => {
|
|
140
140
|
return response.ok ? response.text() : Promise.reject( response.statusText );
|
|
141
141
|
}).then( content => {
|
|
142
142
|
this.host.innerHTML = content.trim(); // IMPORTANT: .trim()
|
|
@@ -159,8 +159,8 @@ export default class HTMLExportsManager {
|
|
|
159
159
|
*/
|
|
160
160
|
evalInheritance( ) {
|
|
161
161
|
if ( !this.parent ) return [];
|
|
162
|
-
let extendedId = ( this.host.getAttribute( this.
|
|
163
|
-
let inheritedIds = ( this.host.getAttribute( this.
|
|
162
|
+
let extendedId = ( this.host.getAttribute( this.config.template.attr.extends ) || '' ).trim();
|
|
163
|
+
let inheritedIds = ( this.host.getAttribute( this.config.template.attr.inherits ) || '' ).trim();
|
|
164
164
|
const handleInherited = records => {
|
|
165
165
|
records.forEach( record => {
|
|
166
166
|
if ( Observer.get( this.modules, record.key ) !== record.oldValue ) return;
|
|
@@ -174,7 +174,7 @@ export default class HTMLExportsManager {
|
|
|
174
174
|
const realtimes = [];
|
|
175
175
|
const parentExportsObj = getModulesObject( this.parent );
|
|
176
176
|
if ( extendedId ) {
|
|
177
|
-
realtimes.push( Observer.deep( parentExportsObj, [ extendedId, this.
|
|
177
|
+
realtimes.push( Observer.deep( parentExportsObj, [ extendedId, this.config.template.api.modules, Infinity ], Observer.get, handleInherited, { live: true } ) );
|
|
178
178
|
}
|
|
179
179
|
if ( ( inheritedIds = inheritedIds.split( ' ' ).map( id => id.trim() ).filter( x => x ) ).length ) {
|
|
180
180
|
realtimes.push( Observer.get( parentExportsObj, inheritedIds, handleInherited, { live: true } ) );
|
|
@@ -193,7 +193,7 @@ export default class HTMLExportsManager {
|
|
|
193
193
|
this.realtimeC.forEach( r => r.abort() );
|
|
194
194
|
Object.entries( this.modules ).forEach( ( [ key, entry ] ) => {
|
|
195
195
|
if ( key.startsWith( '#' ) ) return;
|
|
196
|
-
HTMLExportsManager.instance( entry ).dispose();
|
|
196
|
+
HTMLExportsManager.instance( this.window, entry ).dispose();
|
|
197
197
|
} );
|
|
198
198
|
}
|
|
199
199
|
}
|
|
@@ -39,9 +39,9 @@ export default class _HTMLImportsContext extends HTMLContext {
|
|
|
39
39
|
|
|
40
40
|
// Parse and translate detail
|
|
41
41
|
if ( ( event.request.detail || '' ).trim() === '/' ) return event.respondWith( this.modules );
|
|
42
|
-
const $
|
|
42
|
+
const $config = this.constructor.config;
|
|
43
43
|
let path = ( event.request.detail || '' ).split( /\/|(?<=\w)(?=\W)/g ).map( x => x.trim() ).filter( x => x );
|
|
44
|
-
if ( path.length ) { path = path.join( `/${ $
|
|
44
|
+
if ( path.length ) { path = path.join( `/${ $config.template.api.modules }/` )?.split( '/' ) || []; }
|
|
45
45
|
// No detail?
|
|
46
46
|
if ( !path.length ) return event.respondWith();
|
|
47
47
|
|
|
@@ -70,12 +70,12 @@ export default class _HTMLImportsContext extends HTMLContext {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
// ----------------
|
|
73
|
-
const $
|
|
74
|
-
if ( !this.host.matches || !$
|
|
73
|
+
const $config = this.constructor.config;
|
|
74
|
+
if ( !this.host.matches || !$config.context.attr.importscontext ) return;
|
|
75
75
|
// Any existing this.refdSourceController? Abort!
|
|
76
76
|
this.refdSourceController?.disconnect();
|
|
77
|
-
const dom = this.host.ownerDocument.defaultView.
|
|
78
|
-
this.refdSourceController = dom.realtime( this.host ).attr( $
|
|
77
|
+
const dom = this.host.ownerDocument.defaultView.webqit.dom;
|
|
78
|
+
this.refdSourceController = dom.realtime( this.host ).attr( $config.context.attr.importscontext, ( record, { signal } ) => {
|
|
79
79
|
// No importscontext attr set. But we're still watching
|
|
80
80
|
if ( !record.value ) {
|
|
81
81
|
this.altModules = undefined;
|