@webqit/oohtml 2.1.34 → 2.1.36
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/.gitignore +3 -3
- package/LICENSE +20 -20
- package/README.md +733 -67
- 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/main.js +12 -12
- package/dist/main.js.map +3 -3
- package/dist/namespace-api.js +1 -1
- package/dist/namespace-api.js.map +3 -3
- package/dist/scoped-css.js +2 -2
- package/dist/scoped-css.js.map +3 -3
- package/dist/scoped-js.js +7 -7
- package/dist/scoped-js.js.map +3 -3
- package/package.json +76 -76
- package/src/bindings-api/index.js +83 -83
- package/src/bindings-api/targets.browser.js +10 -10
- package/src/context-api/HTMLContext.js +76 -157
- package/src/context-api/HTMLContextProvider.js +158 -0
- package/src/context-api/_ContextRequestEvent.js +25 -25
- package/src/context-api/index.js +51 -51
- package/src/context-api/targets.browser.js +9 -9
- package/src/{html-modules/HTMLExportsManager.js → html-imports/_HTMLExportsManager.js} +185 -199
- package/src/html-imports/_HTMLImportElement.js +211 -213
- package/src/{html-modules/_HTMLImportsContext.js → html-imports/_HTMLImportsProvider.js} +122 -114
- package/src/html-imports/index.js +197 -88
- package/src/html-imports/targets.browser.js +9 -9
- package/src/index.js +30 -32
- package/src/namespace-api/index.js +144 -144
- package/src/namespace-api/targets.browser.js +10 -10
- package/src/scoped-css/index.js +45 -45
- package/src/scoped-css/targets.browser.js +10 -10
- package/src/scoped-js/Compiler.js +297 -297
- package/src/scoped-js/index.js +112 -112
- package/src/scoped-js/targets.browser.js +10 -10
- package/src/targets.browser.js +9 -9
- package/src/util.js +34 -34
- package/test/bindings-api.test.js +42 -42
- package/test/imports.test.js +221 -221
- package/test/index.js +50 -50
- package/test/modules.test.js +200 -200
- package/test/namespace-api.test.js +51 -51
- package/test/scoped-css.test.js +31 -31
- package/test/scoped-js.test.js +29 -29
- package/dist/html-modules.js +0 -2
- package/dist/html-modules.js.map +0 -7
- package/src/context-api/HTMLContextManager.js +0 -77
- package/src/html-modules/index.js +0 -131
- package/src/html-modules/targets.browser.js +0 -10
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _compare } from '../util.js';
|
|
6
|
+
import HTMLContext from './HTMLContext.js';
|
|
7
|
+
|
|
8
|
+
export default class HTMLContextProvider {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @config
|
|
12
|
+
*/
|
|
13
|
+
static get config() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @attachTo
|
|
19
|
+
*/
|
|
20
|
+
static attachTo( host, Id, multiple = false ) {
|
|
21
|
+
let provider, contextMgr = HTMLContext.instance( host );
|
|
22
|
+
if ( !multiple && ( provider = contextMgr.findProvider( cx => this.matchRequest( cx.id, Id, true ) ) ) ) return provider;
|
|
23
|
+
return contextMgr.attachProvider( new this( Id ) );
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @detachFrom
|
|
28
|
+
*/
|
|
29
|
+
static detachFrom( host, Id, multiple = false ) {
|
|
30
|
+
let provider, contextMgr = HTMLContext.instance( host );
|
|
31
|
+
for ( provider of contextMgr[ '#' ].contexts ) {
|
|
32
|
+
if ( !this.matchRequest( provider.id, Id, true ) || ( typeof multiple === 'function' && !multiple( provider ) ) ) continue;
|
|
33
|
+
contextMgr.detachProvider( provider );
|
|
34
|
+
if ( typeof multiple !== 'function' && !multiple ) return provider;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @createId
|
|
40
|
+
*/
|
|
41
|
+
static createId( host, fields = {} ) {
|
|
42
|
+
const id = { ...fields };
|
|
43
|
+
if ( id.contextName ) return id;
|
|
44
|
+
if ( host.getAttribute && !( id.contextName = ( host.getAttribute( this.config.context.attr.contextname ) || '' ).trim() ) ) {
|
|
45
|
+
delete id.contextName;
|
|
46
|
+
} else if ( !host.ownerDocument ) {
|
|
47
|
+
id.contextName = 'root';
|
|
48
|
+
}
|
|
49
|
+
return id;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @createRequest
|
|
54
|
+
*/
|
|
55
|
+
static createRequest( fields = {} ) {
|
|
56
|
+
return { ...fields };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @matchesRequest
|
|
61
|
+
*/
|
|
62
|
+
static matchRequest( id, request, strict = false ) {
|
|
63
|
+
if ( strict ) return _compare( id, request, 1, true );
|
|
64
|
+
return request.type === id.type && !request.contextName || request.contextName === id.contextName;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @constructor
|
|
69
|
+
*/
|
|
70
|
+
constructor( id ) {
|
|
71
|
+
Object.defineProperty( this, 'id', { get: () => id } );
|
|
72
|
+
Object.defineProperty( this, 'subscriptions', { value: new Set } );
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @length()
|
|
77
|
+
*/
|
|
78
|
+
get length() {
|
|
79
|
+
this.subscriptions.size;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @handle()
|
|
84
|
+
*/
|
|
85
|
+
handle( event ) {}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @subscribe()
|
|
89
|
+
*/
|
|
90
|
+
subscribe( event ) {
|
|
91
|
+
this.subscriptions.add( event );
|
|
92
|
+
if ( !event.request.signal ) return;
|
|
93
|
+
event.request.signal.addEventListener( 'abort', () => {
|
|
94
|
+
this.unsubscribe( event );
|
|
95
|
+
} );
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @unsubscribe()
|
|
100
|
+
*/
|
|
101
|
+
unsubscribe( event ) {
|
|
102
|
+
this.subscriptions.delete( event );
|
|
103
|
+
event.request.controller?.abort();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @handleEvent()
|
|
108
|
+
*/
|
|
109
|
+
handleEvent( event ) {
|
|
110
|
+
if ( this.disposed || ( event.target === this.host && event.request?.superContextOnly )
|
|
111
|
+
|| !event.request || typeof event.callback !== 'function' || !this.constructor.matchRequest( this.id, event.request ) ) return;
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
if ( event.type === 'contextclaim' ) {
|
|
114
|
+
const claims = new Set;
|
|
115
|
+
this.subscriptions.forEach( subscriptionEvent => {
|
|
116
|
+
if ( !event.target.contains( subscriptionEvent.request.superContextOnly ? subscriptionEvent.target.parentNode : subscriptionEvent.target )
|
|
117
|
+
|| !this.constructor.matchRequest( event.request/*provider ID*/, subscriptionEvent.request/*request ID*/ ) ) return;
|
|
118
|
+
this.subscriptions.delete( subscriptionEvent );
|
|
119
|
+
claims.add( subscriptionEvent );
|
|
120
|
+
} );
|
|
121
|
+
event.respondWith( claims );
|
|
122
|
+
} else if ( event.type === 'contextrequest' ) {
|
|
123
|
+
if ( event.request.live ) { this.subscribe( event ); }
|
|
124
|
+
this.handle( event );
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @initialize()
|
|
130
|
+
*/
|
|
131
|
+
initialize( host ) {
|
|
132
|
+
this.host = host;
|
|
133
|
+
this.disposed = false;
|
|
134
|
+
host.addEventListener( 'contextrequest', this );
|
|
135
|
+
host.addEventListener( 'contextclaim', this );
|
|
136
|
+
HTMLContext.instance( host ).request( { ...this.id, superContextOnly: true }, claims => claims.forEach( subscriptionEvent => {
|
|
137
|
+
this.subscribe( subscriptionEvent );
|
|
138
|
+
this.handle( subscriptionEvent );
|
|
139
|
+
} ), { type: 'contextclaim' } );
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @dispose()
|
|
145
|
+
*/
|
|
146
|
+
dispose( host ) {
|
|
147
|
+
this.disposed = true;
|
|
148
|
+
host.removeEventListener( 'contextrequest', this );
|
|
149
|
+
host.removeEventListener( 'contextclaim', this );
|
|
150
|
+
this.subscriptions.forEach( subscriptionEvent => {
|
|
151
|
+
this.unsubscribe( subscriptionEvent );
|
|
152
|
+
const { target, request, callback, options } = subscriptionEvent;
|
|
153
|
+
HTMLContext.instance( target ).request( request, callback, options );
|
|
154
|
+
} );
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
export default function() {
|
|
3
|
-
const window = this;
|
|
4
|
-
return class ContextRequestEvent extends window.Event {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @constructor
|
|
8
|
-
*/
|
|
9
|
-
constructor( request, callback, { type = 'contextrequest', ...
|
|
10
|
-
super( type,
|
|
11
|
-
Object.defineProperty( this, 'request', { get: () => request } );
|
|
12
|
-
Object.defineProperty( this, 'callback', { get: () => callback } );
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @respondWith
|
|
17
|
-
*/
|
|
18
|
-
respondWith( response, ...rest ) {
|
|
19
|
-
if ( this.request.diff ) {
|
|
20
|
-
if ( 'previousValue' in this && this.previousValue === response ) return;
|
|
21
|
-
this.previousValue = response;
|
|
22
|
-
}
|
|
23
|
-
return this.callback( response, ...rest );
|
|
24
|
-
}
|
|
25
|
-
};
|
|
1
|
+
|
|
2
|
+
export default function() {
|
|
3
|
+
const window = this;
|
|
4
|
+
return class ContextRequestEvent extends window.Event {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @constructor
|
|
8
|
+
*/
|
|
9
|
+
constructor( request, callback, { type = 'contextrequest', ...options } = {} ) {
|
|
10
|
+
super( type, options );
|
|
11
|
+
Object.defineProperty( this, 'request', { get: () => request } );
|
|
12
|
+
Object.defineProperty( this, 'callback', { get: () => callback } );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @respondWith
|
|
17
|
+
*/
|
|
18
|
+
respondWith( response, ...rest ) {
|
|
19
|
+
if ( this.request.diff ) {
|
|
20
|
+
if ( 'previousValue' in this && this.previousValue === response ) return;
|
|
21
|
+
this.previousValue = response;
|
|
22
|
+
}
|
|
23
|
+
return this.callback( response, ...rest );
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
26
|
}
|
package/src/context-api/index.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _init } from '../util.js';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Initializes HTML Modules.
|
|
11
|
-
*
|
|
12
|
-
* @param $config Object
|
|
13
|
-
*
|
|
14
|
-
* @return Void
|
|
15
|
-
*/
|
|
16
|
-
export default function init( $config = {} ) {
|
|
17
|
-
const { config, window } = _init.call( this, 'context-api', $config, {
|
|
18
|
-
api: { context: 'context', },
|
|
19
|
-
} );
|
|
20
|
-
window.webqit.
|
|
21
|
-
window.webqit.HTMLContext = HTMLContext;
|
|
22
|
-
exposeModulesObjects.call( window, config );
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Exposes HTML Modules with native APIs.
|
|
27
|
-
*
|
|
28
|
-
* @param Object config
|
|
29
|
-
*
|
|
30
|
-
* @return Void
|
|
31
|
-
*/
|
|
32
|
-
function exposeModulesObjects( config ) {
|
|
33
|
-
const window = this;
|
|
34
|
-
// Assertions
|
|
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!` ); }
|
|
37
|
-
// Definitions
|
|
38
|
-
Object.defineProperty( window.document, config.api.context, { get: function() {
|
|
39
|
-
return
|
|
40
|
-
} } );
|
|
41
|
-
Object.defineProperty( window.HTMLElement.prototype, config.api.context, { get: function() {
|
|
42
|
-
return
|
|
43
|
-
} } );
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @exports
|
|
48
|
-
*/
|
|
49
|
-
export {
|
|
50
|
-
|
|
51
|
-
HTMLContext,
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _init } from '../util.js';
|
|
6
|
+
import HTMLContext from './HTMLContext.js';
|
|
7
|
+
import HTMLContextProvider from './HTMLContextProvider.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initializes HTML Modules.
|
|
11
|
+
*
|
|
12
|
+
* @param $config Object
|
|
13
|
+
*
|
|
14
|
+
* @return Void
|
|
15
|
+
*/
|
|
16
|
+
export default function init( $config = {} ) {
|
|
17
|
+
const { config, window } = _init.call( this, 'context-api', $config, {
|
|
18
|
+
api: { context: 'context', },
|
|
19
|
+
} );
|
|
20
|
+
window.webqit.HTMLContextProvider = HTMLContextProvider;
|
|
21
|
+
window.webqit.HTMLContext = HTMLContext;
|
|
22
|
+
exposeModulesObjects.call( window, config );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Exposes HTML Modules with native APIs.
|
|
27
|
+
*
|
|
28
|
+
* @param Object config
|
|
29
|
+
*
|
|
30
|
+
* @return Void
|
|
31
|
+
*/
|
|
32
|
+
function exposeModulesObjects( config ) {
|
|
33
|
+
const window = this;
|
|
34
|
+
// Assertions
|
|
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!` ); }
|
|
37
|
+
// Definitions
|
|
38
|
+
Object.defineProperty( window.document, config.api.context, { get: function() {
|
|
39
|
+
return HTMLContext.instance( window.document );
|
|
40
|
+
} } );
|
|
41
|
+
Object.defineProperty( window.HTMLElement.prototype, config.api.context, { get: function() {
|
|
42
|
+
return HTMLContext.instance( this );
|
|
43
|
+
} } );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @exports
|
|
48
|
+
*/
|
|
49
|
+
export {
|
|
50
|
+
HTMLContextProvider,
|
|
51
|
+
HTMLContext,
|
|
52
52
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import init from './index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @init
|
|
9
|
-
*/
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import init from './index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @init
|
|
9
|
+
*/
|
|
10
10
|
init.call( window );
|