Skip to content

Commit 20148fc

Browse files
committed
Added support for element internals
1 parent 8974861 commit 20148fc

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-element",
3-
"version": "0.0.230",
3+
"version": "0.0.231",
44
"description": "",
55
"license": "LGPL-3.0",
66
"main": "./index.js",
@@ -166,6 +166,7 @@
166166
"@types/chai": "^4.2.21",
167167
"@types/jest": "^27.0.1",
168168
"@types/mocha": "^9.0.0",
169+
"@types/web": "^0.0.46",
169170
"babel-loader": "^8.2.2",
170171
"bestzip": "^2.2.0",
171172
"copyfiles": "^2.4.1",

src/main/js-element-hooks.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,23 @@ export const useEffect = hook(
504504
}
505505
)
506506

507-
// === useInterval ======================================================
507+
// === useInternals ==================================================
508+
509+
const internalsByElement = new WeakMap<HTMLElement, ElementInternals>()
510+
511+
export const useInternals = hook('useInternals', () => {
512+
const host = currentCtrl!.getHost()
513+
let internals = internalsByElement.get(host)
514+
515+
if (!internals) {
516+
internals = host.attachInternals()
517+
internalsByElement.set(host, internals)
518+
}
519+
520+
return internals
521+
})
522+
523+
// === useInterval ===================================================
508524

509525
export const useInterval = hook(
510526
'useInterval',

src/main/js-element.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function elem<E extends Component, C>(params: {
8484
init: (self: E, ctrl: Ctrl) => () => C
8585
}
8686
styles?: string | string[] | (() => string | string[])
87+
formAssociated?: boolean
8788
uses?: any[]
8889
}): (clazz: new () => E) => void
8990

@@ -128,6 +129,10 @@ function elem<E extends Component>(params: any) {
128129

129130
const propConfigs = Array.from(elemConfigByClass.get(clazz)!.props.values())
130131

132+
if (params.formAssociated) {
133+
definePropValue(clazz, 'formAssociated', true)
134+
}
135+
131136
if (propConfigs.length > 0) {
132137
addAttributeHandling(clazz, propConfigs)
133138
}
@@ -227,7 +232,7 @@ class BaseElement extends HTMLElement {
227232

228233
elemConfig.styles = styles
229234
}
230-
console.log(11111, elemConfig)
235+
231236
if (elemConfig.shadow) {
232237
this.attachShadow({ mode: 'open' })
233238
}

tsconfig.dist.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"baseUrl": ".",
1717
"skipLibCheck": true,
1818
"typeRoots": ["node_modules/@types"],
19-
"types": ["node", "mocha", "chai"],
19+
"types": ["node", "mocha", "chai", "web"],
2020
"paths": {
2121
"js-element/hooks": ["src/main/js-element-hooks.ts"],
2222
"js-element/utils": ["src/main/js-element-utils.ts"],

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"js-element": ["src/main/js-element.ts"]
2525
},
2626
"typeRoots": ["node_modules/@types"],
27-
"types": ["node"]
27+
"types": ["node", "web"]
2828
},
2929
"files": [
3030
"src/main/js-element.ts",

yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,11 @@
27472747
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
27482748
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==
27492749

2750+
"@types/web@^0.0.46":
2751+
version "0.0.46"
2752+
resolved "https://registry.yarnpkg.com/@types/web/-/web-0.0.46.tgz#7f447e5eb3c511dbdc6f69e435f7ec4311d18b48"
2753+
integrity sha512-ki0OmbjSdAEfvmy5AYWFpMkRsPW+6h4ibQ4tzk8SJsS9dkrrD3B/U1eVvdNNWxAzntjq6o2sjSia6UBCoPH+Yg==
2754+
27502755
"@types/webpack-env@^1.16.0":
27512756
version "1.16.2"
27522757
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.2.tgz#8db514b059c1b2ae14ce9d7bb325296de6a9a0fa"
@@ -10712,10 +10717,10 @@ rollup-pluginutils@^2.6.0:
1071210717
dependencies:
1071310718
estree-walker "^0.6.1"
1071410719

10715-
rollup@^2.56.2:
10716-
version "2.56.3"
10717-
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.56.3.tgz#b63edadd9851b0d618a6d0e6af8201955a77aeff"
10718-
integrity sha512-Au92NuznFklgQCUcV96iXlxUbHuB1vQMaH76DHl5M11TotjOHwqk9CwcrT78+Tnv4FN9uTBxq6p4EJoYkpyekg==
10720+
rollup@^2.56.3:
10721+
version "2.59.0"
10722+
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.59.0.tgz#108c61b0fa0a37ebc8d1f164f281622056f0db59"
10723+
integrity sha512-l7s90JQhCQ6JyZjKgo7Lq1dKh2RxatOM+Jr6a9F7WbS9WgKbocyUSeLmZl8evAse7y96Ae98L2k1cBOwWD8nHw==
1071910724
optionalDependencies:
1072010725
fsevents "~2.3.2"
1072110726

0 commit comments

Comments
 (0)