react-component-instance 0.0.1 → 0.0.2
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/README.md +1 -1
- package/package.json +10 -3
- package/babel.config.cjs +0 -42
- package/eslint.config.mjs +0 -168
- package/jest.config.mjs +0 -15
- package/src/__tests__/index.spec.jsx +0 -58
- package/src/container/__tests__/index.spec.jsx +0 -29
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-component-instance",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Get a React class component instance from its DOM Element",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"class",
|
|
8
|
+
"component",
|
|
9
|
+
"instance"
|
|
10
|
+
],
|
|
4
11
|
"main": "./src/index.mjs",
|
|
5
12
|
"type": "module",
|
|
6
13
|
"types": "./index.d.mts",
|
|
@@ -20,8 +27,8 @@
|
|
|
20
27
|
"scripts": {
|
|
21
28
|
"lint": "eslint",
|
|
22
29
|
"lint:fix": "npm run lint -- --fix",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
30
|
+
"prepare": "husky",
|
|
31
|
+
"test": "NODE_ENV=test jest"
|
|
25
32
|
},
|
|
26
33
|
"devDependencies": {
|
|
27
34
|
"@babel/core": "^7.26.10",
|
package/babel.config.cjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const debug = require('debug')
|
|
2
|
-
|
|
3
|
-
const log = debug('react-component-instance')
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
env: {
|
|
7
|
-
NODE_ENV = 'development'
|
|
8
|
-
}
|
|
9
|
-
} = process
|
|
10
|
-
|
|
11
|
-
log('`react-component-instance` is awake')
|
|
12
|
-
|
|
13
|
-
function env () {
|
|
14
|
-
log({ NODE_ENV })
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
NODE_ENV === 'production'
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const presets = [
|
|
22
|
-
[
|
|
23
|
-
'@babel/env',
|
|
24
|
-
{
|
|
25
|
-
targets: {
|
|
26
|
-
node: 'current'
|
|
27
|
-
},
|
|
28
|
-
useBuiltIns: 'usage',
|
|
29
|
-
corejs: 3
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
'@babel/react'
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
module.exports = (api) => {
|
|
37
|
-
if (api) api.cache.using(env)
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
presets
|
|
41
|
-
}
|
|
42
|
-
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import globals from 'globals'
|
|
2
|
-
import standard from '@sequencemedia/eslint-config-standard/configs/recommended/merge'
|
|
3
|
-
import typescript from '@sequencemedia/eslint-config-typescript/configs/recommended/merge'
|
|
4
|
-
import babelParser from '@babel/eslint-parser'
|
|
5
|
-
import typescriptParser from '@typescript-eslint/parser'
|
|
6
|
-
import reactPlugin from 'eslint-plugin-react'
|
|
7
|
-
|
|
8
|
-
const reactParserOptions = {
|
|
9
|
-
ecmaFeatures: {
|
|
10
|
-
jsx: true
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const reactPlugins = {
|
|
15
|
-
react: reactPlugin
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const reactRules = {
|
|
19
|
-
'no-unused-vars': [
|
|
20
|
-
'error',
|
|
21
|
-
{
|
|
22
|
-
varsIgnorePattern: 'React'
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
quotes: [
|
|
26
|
-
'error',
|
|
27
|
-
'single'
|
|
28
|
-
],
|
|
29
|
-
'jsx-quotes': [
|
|
30
|
-
'error',
|
|
31
|
-
'prefer-single'
|
|
32
|
-
],
|
|
33
|
-
'react/jsx-indent': [
|
|
34
|
-
'error',
|
|
35
|
-
2,
|
|
36
|
-
{
|
|
37
|
-
checkAttributes: true,
|
|
38
|
-
indentLogicalExpressions: true
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const reactSettings = {
|
|
44
|
-
react: {
|
|
45
|
-
version: 'detect'
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default [
|
|
50
|
-
/**
|
|
51
|
-
* React config for all `jsx` files
|
|
52
|
-
*/
|
|
53
|
-
{
|
|
54
|
-
...reactPlugin.configs.flat.recommended,
|
|
55
|
-
settings: {
|
|
56
|
-
...reactSettings
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Standard config
|
|
61
|
-
*/
|
|
62
|
-
standard({
|
|
63
|
-
files: [
|
|
64
|
-
'**/*.{mjs,cjs,mts,cts}'
|
|
65
|
-
],
|
|
66
|
-
ignores: [
|
|
67
|
-
'src'
|
|
68
|
-
],
|
|
69
|
-
languageOptions: {
|
|
70
|
-
globals: {
|
|
71
|
-
...globals.node
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
rules: {
|
|
75
|
-
'no-use-before-define': 'off'
|
|
76
|
-
}
|
|
77
|
-
}),
|
|
78
|
-
/**
|
|
79
|
-
* Standard config for `mjs` and `mts` files
|
|
80
|
-
*/
|
|
81
|
-
standard({
|
|
82
|
-
files: [
|
|
83
|
-
'src/**/*.{mjs,cjs,mts,cts}'
|
|
84
|
-
],
|
|
85
|
-
languageOptions: {
|
|
86
|
-
globals: {
|
|
87
|
-
...globals.browser
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
/**
|
|
92
|
-
* Standard config for `jsx` files
|
|
93
|
-
*/
|
|
94
|
-
standard({
|
|
95
|
-
files: [
|
|
96
|
-
'src/**/*.jsx'
|
|
97
|
-
],
|
|
98
|
-
ignores: [
|
|
99
|
-
'src/**/__tests__/**/*.jsx'
|
|
100
|
-
],
|
|
101
|
-
languageOptions: {
|
|
102
|
-
parser: babelParser,
|
|
103
|
-
parserOptions: {
|
|
104
|
-
...reactParserOptions,
|
|
105
|
-
project: null
|
|
106
|
-
},
|
|
107
|
-
globals: {
|
|
108
|
-
...globals.browser
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
plugins: {
|
|
112
|
-
...reactPlugins
|
|
113
|
-
}, // @ts-expect-error Storybook
|
|
114
|
-
rules: {
|
|
115
|
-
...reactRules
|
|
116
|
-
},
|
|
117
|
-
settings: {
|
|
118
|
-
...reactSettings
|
|
119
|
-
}
|
|
120
|
-
}),
|
|
121
|
-
/**
|
|
122
|
-
* Standard config for `jsx` files
|
|
123
|
-
*/
|
|
124
|
-
standard({
|
|
125
|
-
files: [
|
|
126
|
-
'src/**/__tests__/**/*.jsx'
|
|
127
|
-
],
|
|
128
|
-
languageOptions: {
|
|
129
|
-
parser: babelParser,
|
|
130
|
-
parserOptions: {
|
|
131
|
-
...reactParserOptions,
|
|
132
|
-
project: null
|
|
133
|
-
},
|
|
134
|
-
globals: {
|
|
135
|
-
...globals.browser,
|
|
136
|
-
...globals.jest
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
plugins: {
|
|
140
|
-
...reactPlugins
|
|
141
|
-
}, // @ts-expect-error Storybook
|
|
142
|
-
rules: {
|
|
143
|
-
...reactRules
|
|
144
|
-
},
|
|
145
|
-
settings: {
|
|
146
|
-
...reactSettings
|
|
147
|
-
}
|
|
148
|
-
}),
|
|
149
|
-
/**
|
|
150
|
-
* TypeScript config
|
|
151
|
-
*/
|
|
152
|
-
typescript({
|
|
153
|
-
files: [
|
|
154
|
-
'**/*.{mts,cts}'
|
|
155
|
-
],
|
|
156
|
-
languageOptions: {
|
|
157
|
-
parser: typescriptParser,
|
|
158
|
-
parserOptions: {
|
|
159
|
-
projectService: true,
|
|
160
|
-
project: 'tsconfig.json'
|
|
161
|
-
},
|
|
162
|
-
globals: {
|
|
163
|
-
...globals.browser,
|
|
164
|
-
ReactComponentInstanceTypes: 'readonly'
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
]
|
package/jest.config.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
bail: 1,
|
|
3
|
-
verbose: true,
|
|
4
|
-
rootDir: '.',
|
|
5
|
-
roots: [
|
|
6
|
-
'./src'
|
|
7
|
-
],
|
|
8
|
-
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(mjs?|jsx?)$',
|
|
9
|
-
testEnvironment: 'jsdom',
|
|
10
|
-
transform: {
|
|
11
|
-
'^.+\\.jsx$': 'babel-jest',
|
|
12
|
-
'^.+\\.mjs$': 'babel-jest'
|
|
13
|
-
},
|
|
14
|
-
moduleFileExtensions: ['js', 'mjs', 'cjs', 'jsx']
|
|
15
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {ReactComponentInstanceTypes.FiberNode} FiberNode
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import React from 'react'
|
|
6
|
-
|
|
7
|
-
import '@testing-library/jest-dom'
|
|
8
|
-
import {
|
|
9
|
-
render
|
|
10
|
-
} from '@testing-library/react'
|
|
11
|
-
|
|
12
|
-
import getReactComponentInstanceFrom, {
|
|
13
|
-
findReactComponentInstanceFor
|
|
14
|
-
} from '#react-component-instance'
|
|
15
|
-
|
|
16
|
-
describe('#react-component-instance', () => {
|
|
17
|
-
class Component extends React.Component {
|
|
18
|
-
render () {
|
|
19
|
-
return (
|
|
20
|
-
<div>
|
|
21
|
-
<div>
|
|
22
|
-
<div className='target' />
|
|
23
|
-
</div>
|
|
24
|
-
</div>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe('`getReactComponentInstanceFrom`', () => {
|
|
30
|
-
it('gets the instance', () => {
|
|
31
|
-
const {
|
|
32
|
-
container: {
|
|
33
|
-
firstElementChild: element
|
|
34
|
-
}
|
|
35
|
-
} = render(
|
|
36
|
-
<Component />
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
expect(getReactComponentInstanceFrom(element))
|
|
40
|
-
.toBeInstanceOf(Component)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('`findReactComponentInstanceFor`', () => {
|
|
45
|
-
it('gets the instance', () => {
|
|
46
|
-
const {
|
|
47
|
-
container: {
|
|
48
|
-
firstElementChild: element
|
|
49
|
-
}
|
|
50
|
-
} = render(
|
|
51
|
-
<Component />
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
expect(findReactComponentInstanceFor(element?.querySelector('.target'), Component))
|
|
55
|
-
.toBeInstanceOf(Component)
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import '@testing-library/jest-dom'
|
|
4
|
-
import {
|
|
5
|
-
render
|
|
6
|
-
} from '@testing-library/react'
|
|
7
|
-
|
|
8
|
-
import getReactComponentInstanceFrom from '#react-component-instance/container'
|
|
9
|
-
|
|
10
|
-
describe('#react-component-instance/container', () => {
|
|
11
|
-
describe('`getReactComponentInstanceFrom`', () => {
|
|
12
|
-
class Component extends React.Component {
|
|
13
|
-
render () {
|
|
14
|
-
return <div />
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
it('gets the instance', () => {
|
|
19
|
-
const {
|
|
20
|
-
container
|
|
21
|
-
} = render(
|
|
22
|
-
<Component />
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
expect(getReactComponentInstanceFrom(container))
|
|
26
|
-
.toBeInstanceOf(Component)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
})
|