@webqit/oohtml 2.1.34 → 2.1.35
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
package/package.json
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@webqit/oohtml",
|
|
3
|
-
"title": "CHTML",
|
|
4
|
-
"description": "A suite of new DOM features that brings language support for modern UI development paradigms: a component-based architecture, data binding, and reactivity.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"namespaced-HTML",
|
|
7
|
-
"html-modules",
|
|
8
|
-
"ui-bindings",
|
|
9
|
-
"html-imports",
|
|
10
|
-
"reflex",
|
|
11
|
-
"subscript",
|
|
12
|
-
"scoped-js",
|
|
13
|
-
"UI",
|
|
14
|
-
"wicg-proposal"
|
|
15
|
-
],
|
|
16
|
-
"homepage": "https://webqit.io/tooling/oohtml",
|
|
17
|
-
"version": "2.1.
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/webqit/oohtml.git"
|
|
22
|
-
},
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/webqit/oohtml/issues"
|
|
25
|
-
},
|
|
26
|
-
"type": "module",
|
|
27
|
-
"sideEffects": false,
|
|
28
|
-
"browser": {
|
|
29
|
-
"fs": false
|
|
30
|
-
},
|
|
31
|
-
"main": "./src/index.js",
|
|
32
|
-
"scripts": {
|
|
33
|
-
"test": "mocha --extension .test.js --exit",
|
|
34
|
-
"test:coverage": "c8 --reporter=text-lcov npm run test | coveralls",
|
|
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-
|
|
36
|
-
"preversion": "npm run
|
|
37
|
-
"postversion": "npm publish",
|
|
38
|
-
"postpublish": "git push && git push --tags"
|
|
39
|
-
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@webqit/observer": "^2.0.7",
|
|
42
|
-
"@webqit/realdom": "^2.1.
|
|
43
|
-
"@webqit/subscript": "^2.1.40",
|
|
44
|
-
"@webqit/util": "^0.8.11"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@webqit/oohtml-ssr": "^1.2.8",
|
|
48
|
-
"chai": "^4.3.4",
|
|
49
|
-
"coveralls": "^3.1.1",
|
|
50
|
-
"esbuild": "^0.14.43",
|
|
51
|
-
"mocha": "^10.0.0",
|
|
52
|
-
"mocha-lcov-reporter": "^1.3.0"
|
|
53
|
-
},
|
|
54
|
-
"author": "Oxford Harrison <oxharris.dev@gmail.com>",
|
|
55
|
-
"maintainers": [
|
|
56
|
-
"Oxford Harrison <oxharris.dev@gmail.com>"
|
|
57
|
-
],
|
|
58
|
-
"contributors": [],
|
|
59
|
-
"funding": {
|
|
60
|
-
"type": "patreon",
|
|
61
|
-
"url": "https://patreon.com/ox_harris"
|
|
62
|
-
},
|
|
63
|
-
"badges": {
|
|
64
|
-
"list": [
|
|
65
|
-
"npmversion",
|
|
66
|
-
"npmdownloads"
|
|
67
|
-
],
|
|
68
|
-
"config": {
|
|
69
|
-
"patreonUsername": "ox_harris",
|
|
70
|
-
"githubUsername": "webqit",
|
|
71
|
-
"githubRepository": "oohtml",
|
|
72
|
-
"githubSlug": "webqit/oohtml",
|
|
73
|
-
"npmPackageName": "@webqit/oohtml"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@webqit/oohtml",
|
|
3
|
+
"title": "CHTML",
|
|
4
|
+
"description": "A suite of new DOM features that brings language support for modern UI development paradigms: a component-based architecture, data binding, and reactivity.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"namespaced-HTML",
|
|
7
|
+
"html-modules",
|
|
8
|
+
"ui-bindings",
|
|
9
|
+
"html-imports",
|
|
10
|
+
"reflex",
|
|
11
|
+
"subscript",
|
|
12
|
+
"scoped-js",
|
|
13
|
+
"UI",
|
|
14
|
+
"wicg-proposal"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://webqit.io/tooling/oohtml",
|
|
17
|
+
"version": "2.1.35",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/webqit/oohtml.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/webqit/oohtml/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"browser": {
|
|
29
|
+
"fs": false
|
|
30
|
+
},
|
|
31
|
+
"main": "./src/index.js",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "mocha --extension .test.js --exit",
|
|
34
|
+
"test:coverage": "c8 --reporter=text-lcov npm run test | coveralls",
|
|
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-imports=src/html-imports/targets.browser.js scoped-js=src/scoped-js/targets.browser.js scoped-css=src/scoped-css/targets.browser.js --bundle --minify --sourcemap --outdir=dist",
|
|
36
|
+
"preversion": "npm run build && git add -A dist",
|
|
37
|
+
"postversion": "npm publish",
|
|
38
|
+
"postpublish": "git push && git push --tags"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@webqit/observer": "^2.0.7",
|
|
42
|
+
"@webqit/realdom": "^2.1.10",
|
|
43
|
+
"@webqit/subscript": "^2.1.40",
|
|
44
|
+
"@webqit/util": "^0.8.11"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@webqit/oohtml-ssr": "^1.2.8",
|
|
48
|
+
"chai": "^4.3.4",
|
|
49
|
+
"coveralls": "^3.1.1",
|
|
50
|
+
"esbuild": "^0.14.43",
|
|
51
|
+
"mocha": "^10.0.0",
|
|
52
|
+
"mocha-lcov-reporter": "^1.3.0"
|
|
53
|
+
},
|
|
54
|
+
"author": "Oxford Harrison <oxharris.dev@gmail.com>",
|
|
55
|
+
"maintainers": [
|
|
56
|
+
"Oxford Harrison <oxharris.dev@gmail.com>"
|
|
57
|
+
],
|
|
58
|
+
"contributors": [],
|
|
59
|
+
"funding": {
|
|
60
|
+
"type": "patreon",
|
|
61
|
+
"url": "https://patreon.com/ox_harris"
|
|
62
|
+
},
|
|
63
|
+
"badges": {
|
|
64
|
+
"list": [
|
|
65
|
+
"npmversion",
|
|
66
|
+
"npmdownloads"
|
|
67
|
+
],
|
|
68
|
+
"config": {
|
|
69
|
+
"patreonUsername": "ox_harris",
|
|
70
|
+
"githubUsername": "webqit",
|
|
71
|
+
"githubRepository": "oohtml",
|
|
72
|
+
"githubSlug": "webqit/oohtml",
|
|
73
|
+
"npmPackageName": "@webqit/oohtml"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import Observer from '@webqit/observer';
|
|
6
|
-
import { _, _init } from '../util.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @init
|
|
10
|
-
*
|
|
11
|
-
* @param Object $config
|
|
12
|
-
*/
|
|
13
|
-
export default function init( $config = {} ) {
|
|
14
|
-
const { config, window } = _init.call( this, 'bindings-api', $config, {
|
|
15
|
-
api: { bind: 'bind', bindings: 'bindings', },
|
|
16
|
-
} );
|
|
17
|
-
window.webqit.Observer = Observer;
|
|
18
|
-
exposeAPIs.call( window, config );
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { Observer }
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @Exports
|
|
25
|
-
*
|
|
26
|
-
* The internal bindings object
|
|
27
|
-
* within elements and the document object.
|
|
28
|
-
*/
|
|
29
|
-
function getBindingsObject( node ) {
|
|
30
|
-
if ( !_( node ).has( 'bindings' ) ) {
|
|
31
|
-
const bindingsObj = Object.create( null );
|
|
32
|
-
_( node ).set( 'bindings', bindingsObj );
|
|
33
|
-
}
|
|
34
|
-
return _( node ).get( 'bindings' );
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Exposes Bindings with native APIs.
|
|
39
|
-
*
|
|
40
|
-
* @param Object config
|
|
41
|
-
*
|
|
42
|
-
* @return Void
|
|
43
|
-
*/
|
|
44
|
-
function exposeAPIs( config ) {
|
|
45
|
-
const window = this;
|
|
46
|
-
// Assertions
|
|
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!` ); }
|
|
51
|
-
// Definitions
|
|
52
|
-
Object.defineProperty( window.document, config.api.bind, { value: function( bindings, config = {} ) {
|
|
53
|
-
return applyBindings( window.document, bindings, config );
|
|
54
|
-
} });
|
|
55
|
-
Object.defineProperty( window.document, config.api.bindings, { get: function() {
|
|
56
|
-
return Observer.proxy( getBindingsObject( window.document ) );
|
|
57
|
-
} });
|
|
58
|
-
Object.defineProperty( window.Element.prototype, config.api.bind, { value: function( bindings, config = {} ) {
|
|
59
|
-
return applyBindings( this, bindings, config );
|
|
60
|
-
} });
|
|
61
|
-
Object.defineProperty( window.Element.prototype, config.api.bindings, { get: function() {
|
|
62
|
-
return Observer.proxy( getBindingsObject( this ) );
|
|
63
|
-
} } );
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Exposes Bindings with native APIs.
|
|
68
|
-
*
|
|
69
|
-
* @param document|Element target
|
|
70
|
-
* @param Object bindings
|
|
71
|
-
* @param Object params
|
|
72
|
-
*
|
|
73
|
-
* @return Void
|
|
74
|
-
*/
|
|
75
|
-
function applyBindings( target, bindings, { merge, diff, namespace } = {} ) {
|
|
76
|
-
const bindingsObj = getBindingsObject( target );
|
|
77
|
-
const $params = { diff, namespace };
|
|
78
|
-
if ( merge ) return Observer.set( bindingsObj, bindings, $params );;
|
|
79
|
-
const exitingKeys = Observer.ownKeys( bindingsObj, $params ).filter( key => !( key in bindings ) );
|
|
80
|
-
return Observer.batch( bindingsObj, () => {
|
|
81
|
-
if ( exitingKeys.length ) { Observer.deleteProperty( bindingsObj, exitingKeys, $params ); }
|
|
82
|
-
return Observer.set( bindingsObj, bindings, $params );
|
|
83
|
-
}, $params );
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import Observer from '@webqit/observer';
|
|
6
|
+
import { _, _init } from '../util.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @init
|
|
10
|
+
*
|
|
11
|
+
* @param Object $config
|
|
12
|
+
*/
|
|
13
|
+
export default function init( $config = {} ) {
|
|
14
|
+
const { config, window } = _init.call( this, 'bindings-api', $config, {
|
|
15
|
+
api: { bind: 'bind', bindings: 'bindings', },
|
|
16
|
+
} );
|
|
17
|
+
window.webqit.Observer = Observer;
|
|
18
|
+
exposeAPIs.call( window, config );
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { Observer }
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @Exports
|
|
25
|
+
*
|
|
26
|
+
* The internal bindings object
|
|
27
|
+
* within elements and the document object.
|
|
28
|
+
*/
|
|
29
|
+
function getBindingsObject( node ) {
|
|
30
|
+
if ( !_( node ).has( 'bindings' ) ) {
|
|
31
|
+
const bindingsObj = Object.create( null );
|
|
32
|
+
_( node ).set( 'bindings', bindingsObj );
|
|
33
|
+
}
|
|
34
|
+
return _( node ).get( 'bindings' );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Exposes Bindings with native APIs.
|
|
39
|
+
*
|
|
40
|
+
* @param Object config
|
|
41
|
+
*
|
|
42
|
+
* @return Void
|
|
43
|
+
*/
|
|
44
|
+
function exposeAPIs( config ) {
|
|
45
|
+
const window = this;
|
|
46
|
+
// Assertions
|
|
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!` ); }
|
|
51
|
+
// Definitions
|
|
52
|
+
Object.defineProperty( window.document, config.api.bind, { value: function( bindings, config = {} ) {
|
|
53
|
+
return applyBindings( window.document, bindings, config );
|
|
54
|
+
} });
|
|
55
|
+
Object.defineProperty( window.document, config.api.bindings, { get: function() {
|
|
56
|
+
return Observer.proxy( getBindingsObject( window.document ) );
|
|
57
|
+
} });
|
|
58
|
+
Object.defineProperty( window.Element.prototype, config.api.bind, { value: function( bindings, config = {} ) {
|
|
59
|
+
return applyBindings( this, bindings, config );
|
|
60
|
+
} });
|
|
61
|
+
Object.defineProperty( window.Element.prototype, config.api.bindings, { get: function() {
|
|
62
|
+
return Observer.proxy( getBindingsObject( this ) );
|
|
63
|
+
} } );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Exposes Bindings with native APIs.
|
|
68
|
+
*
|
|
69
|
+
* @param document|Element target
|
|
70
|
+
* @param Object bindings
|
|
71
|
+
* @param Object params
|
|
72
|
+
*
|
|
73
|
+
* @return Void
|
|
74
|
+
*/
|
|
75
|
+
function applyBindings( target, bindings, { merge, diff, namespace } = {} ) {
|
|
76
|
+
const bindingsObj = getBindingsObject( target );
|
|
77
|
+
const $params = { diff, namespace };
|
|
78
|
+
if ( merge ) return Observer.set( bindingsObj, bindings, $params );;
|
|
79
|
+
const exitingKeys = Observer.ownKeys( bindingsObj, $params ).filter( key => !( key in bindings ) );
|
|
80
|
+
return Observer.batch( bindingsObj, () => {
|
|
81
|
+
if ( exitingKeys.length ) { Observer.deleteProperty( bindingsObj, exitingKeys, $params ); }
|
|
82
|
+
return Observer.set( bindingsObj, bindings, $params );
|
|
83
|
+
}, $params );
|
|
84
84
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import init from './index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @init
|
|
9
|
-
*/
|
|
10
|
-
init.call( window );
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import init from './index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @init
|
|
9
|
+
*/
|
|
10
|
+
init.call( window );
|
|
@@ -1,158 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
export default class HTMLContext {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @
|
|
12
|
-
*/
|
|
13
|
-
static
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
HTMLContextManager.instance( host ).ask( { ...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, params } = subscriptionEvent;
|
|
153
|
-
HTMLContextManager.instance( target ).ask( request, callback, params );
|
|
154
|
-
} );
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import _ContextRequestEvent from './_ContextRequestEvent.js';
|
|
6
|
+
import { _ } from '../util.js';
|
|
7
|
+
|
|
8
|
+
export default class HTMLContext {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @instance
|
|
12
|
+
*/
|
|
13
|
+
static instance( host ) {
|
|
14
|
+
return _( host ).get( 'context::instance' ) || new this( host );;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @constructor
|
|
19
|
+
*/
|
|
20
|
+
constructor( host ) {
|
|
21
|
+
_( host ).get( `context::instance` )?.dispose();
|
|
22
|
+
_( host ).set( `context::instance`, this );
|
|
23
|
+
const priv = { host, contexts: new Set };
|
|
24
|
+
Object.defineProperty( this, '#', { get: () => priv } );
|
|
25
|
+
const ContextRequestEvent = _ContextRequestEvent.call( host.ownerDocument?.defaultView || host.defaultView );
|
|
26
|
+
Object.defineProperty( this, 'ContextRequestEvent', { get: () => ContextRequestEvent } );
|
|
27
|
+
this[ Symbol.iterator ] = function*() {
|
|
28
|
+
const it = priv.contexts[ Symbol.iterator ]();
|
|
29
|
+
yield it.next().value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @length()
|
|
35
|
+
*/
|
|
36
|
+
get length() {
|
|
37
|
+
this[ '#' ].contexts.size;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @find()
|
|
42
|
+
*/
|
|
43
|
+
findProvider( callback ) {
|
|
44
|
+
return [ ...this[ '#' ].contexts ].find( callback );
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @attachProvider()
|
|
49
|
+
*/
|
|
50
|
+
attachProvider( context ) {
|
|
51
|
+
this[ '#' ].contexts.add( context );
|
|
52
|
+
context.initialize( this[ '#' ].host );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @detachProvider()
|
|
57
|
+
*/
|
|
58
|
+
detachProvider( context ) {
|
|
59
|
+
context.dispose( this[ '#' ].host );
|
|
60
|
+
this[ '#' ].contexts.delete( context );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @request()
|
|
65
|
+
*/
|
|
66
|
+
request( request, callback, options = {} ) {
|
|
67
|
+
return this[ '#' ].host.dispatchEvent(
|
|
68
|
+
new this.ContextRequestEvent( request, callback, { bubbles: true, ...options } )
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @dispose()
|
|
74
|
+
*/
|
|
75
|
+
dispose() {}
|
|
76
|
+
|
|
158
77
|
}
|