@mxenabled/web-connect-widget-sdk 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/package.json +8 -5
- package/.prettierignore +0 -3
- package/.prettierrc +0 -6
- package/eslint.config.js +0 -24
- package/src/ConnectWidget.test.ts +0 -116
- package/src/ConnectWidget.ts +0 -50
- package/src/index.ts +0 -1
- package/testSetup.ts +0 -1
- package/tsconfig.json +0 -26
- package/vite.config.ts +0 -18
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxenabled/web-connect-widget-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "MX Connect Web Widget SDK",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
5
8
|
"main": "dist/index.js",
|
|
6
9
|
"type": "module",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
7
11
|
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": false
|
|
9
14
|
},
|
|
10
15
|
"repository": {
|
|
11
16
|
"type": "git",
|
|
@@ -39,9 +44,7 @@
|
|
|
39
44
|
"typescript": "~5.9.3",
|
|
40
45
|
"typescript-eslint": "^8.48.0",
|
|
41
46
|
"vite": "^7.0.0",
|
|
42
|
-
"vitest": "^4.0.18"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
47
|
+
"vitest": "^4.0.18",
|
|
45
48
|
"vite-plugin-dts": "^4.5.4"
|
|
46
49
|
}
|
|
47
50
|
}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/eslint.config.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import prettier from 'eslint-plugin-prettier/recommended';
|
|
4
|
-
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
5
|
-
|
|
6
|
-
export default defineConfig([
|
|
7
|
-
globalIgnores(['dist', 'node_modules']),
|
|
8
|
-
{
|
|
9
|
-
files: ['**/*.{ts,js}'],
|
|
10
|
-
extends: [
|
|
11
|
-
js.configs.recommended,
|
|
12
|
-
...tseslint.configs.recommended,
|
|
13
|
-
prettier,
|
|
14
|
-
],
|
|
15
|
-
languageOptions: {
|
|
16
|
-
ecmaVersion: 2024,
|
|
17
|
-
sourceType: 'module',
|
|
18
|
-
parser: tseslint.parser,
|
|
19
|
-
parserOptions: {
|
|
20
|
-
tsconfigRootDir: import.meta.dirname,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
]);
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import { getByTestId, queryByTestId } from '@testing-library/dom';
|
|
3
|
-
import { ConnectWidget } from './ConnectWidget';
|
|
4
|
-
|
|
5
|
-
const widgetContainerId = 'widget-container';
|
|
6
|
-
const testId = 'connect-widget-iframe';
|
|
7
|
-
|
|
8
|
-
const createDOM = () => {
|
|
9
|
-
const div = document.createElement('div');
|
|
10
|
-
div.id = widgetContainerId;
|
|
11
|
-
document.body.appendChild(div);
|
|
12
|
-
|
|
13
|
-
return div;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe('ConnectWidget', () => {
|
|
17
|
-
let container: HTMLElement;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
container = createDOM();
|
|
21
|
-
});
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
document.body.replaceChildren();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('mounts and unmounts without error', () => {
|
|
27
|
-
const widget = ConnectWidget({
|
|
28
|
-
containerSelector: `#${widgetContainerId}`,
|
|
29
|
-
iframeProps: {
|
|
30
|
-
'data-testid': 'connect-widget-iframe',
|
|
31
|
-
},
|
|
32
|
-
url: 'https://example.com',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
widget.mount();
|
|
36
|
-
|
|
37
|
-
const iframe = getByTestId(container, testId);
|
|
38
|
-
|
|
39
|
-
expect(iframe).toBeTruthy();
|
|
40
|
-
|
|
41
|
-
widget.unmount();
|
|
42
|
-
|
|
43
|
-
expect(queryByTestId(container, testId)).toBeFalsy();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('sets data attributes, styles, and other iframe props correctly', () => {
|
|
47
|
-
const widget = ConnectWidget({
|
|
48
|
-
containerSelector: `#${widgetContainerId}`,
|
|
49
|
-
iframeProps: {
|
|
50
|
-
'data-testid': testId,
|
|
51
|
-
'data-custom-attr': 'customValue',
|
|
52
|
-
title: 'Connect Widget Iframe',
|
|
53
|
-
style: {
|
|
54
|
-
border: 'solid 1px black',
|
|
55
|
-
height: '50px',
|
|
56
|
-
width: '50px',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
url: 'https://example.com',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
widget.mount();
|
|
63
|
-
|
|
64
|
-
const iframe = getByTestId(container, testId);
|
|
65
|
-
|
|
66
|
-
expect(iframe).toBeTruthy();
|
|
67
|
-
expect(iframe).toHaveAttribute('data-custom-attr', 'customValue');
|
|
68
|
-
expect(iframe).toHaveAttribute('title', 'Connect Widget Iframe');
|
|
69
|
-
expect(iframe).toHaveStyle({
|
|
70
|
-
width: '50px',
|
|
71
|
-
height: '50px',
|
|
72
|
-
});
|
|
73
|
-
expect(iframe.style.border).toBe('1px solid black');
|
|
74
|
-
|
|
75
|
-
widget.unmount();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('defaults height and width to 100% if not provided in styles, but still uses the rest of the provided styles', () => {
|
|
79
|
-
const widget = ConnectWidget({
|
|
80
|
-
containerSelector: `#${widgetContainerId}`,
|
|
81
|
-
iframeProps: {
|
|
82
|
-
'data-testid': testId,
|
|
83
|
-
style: {
|
|
84
|
-
border: 'solid 1px black',
|
|
85
|
-
},
|
|
86
|
-
title: 'Connect Widget Iframe',
|
|
87
|
-
},
|
|
88
|
-
url: 'https://example.com',
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
widget.mount();
|
|
92
|
-
|
|
93
|
-
const iframe = getByTestId(container, testId);
|
|
94
|
-
|
|
95
|
-
expect(iframe).toBeTruthy();
|
|
96
|
-
expect(iframe).toHaveStyle({
|
|
97
|
-
width: '100%',
|
|
98
|
-
height: '100%',
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(iframe.style.border).toBe('1px solid black');
|
|
102
|
-
|
|
103
|
-
widget.unmount();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('throws an error if the container element is not found when mounting', () => {
|
|
107
|
-
const widget = ConnectWidget({
|
|
108
|
-
containerSelector: '#non-existent-container',
|
|
109
|
-
url: 'https://example.com',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(() => widget.mount()).toThrowError(
|
|
113
|
-
'Container with selector "#non-existent-container" not found.'
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
});
|
package/src/ConnectWidget.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
interface ConnectWidgetProps {
|
|
2
|
-
containerSelector: string;
|
|
3
|
-
iframeProps?: Record<string, unknown>;
|
|
4
|
-
url: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const ConnectWidget = ({
|
|
8
|
-
containerSelector,
|
|
9
|
-
iframeProps,
|
|
10
|
-
url,
|
|
11
|
-
}: ConnectWidgetProps) => {
|
|
12
|
-
const iframe = document.createElement('iframe');
|
|
13
|
-
|
|
14
|
-
const { style: iframeStyle, ...restIframeProps } = iframeProps || {};
|
|
15
|
-
|
|
16
|
-
const style = {
|
|
17
|
-
height: '100%',
|
|
18
|
-
width: '100%',
|
|
19
|
-
...(iframeStyle ?? {}),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
Object.assign(iframe.style, style);
|
|
23
|
-
|
|
24
|
-
for (const [key, value] of Object.entries(restIframeProps)) {
|
|
25
|
-
if (key.startsWith('data-')) {
|
|
26
|
-
iframe.setAttribute(key, String(value));
|
|
27
|
-
} else {
|
|
28
|
-
Object.assign(iframe, { [key]: value });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
iframe.src = url;
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
mount: () => {
|
|
36
|
-
const container = document.querySelector(containerSelector);
|
|
37
|
-
|
|
38
|
-
if (!container) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Container with selector "${containerSelector}" not found.`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
container.appendChild(iframe);
|
|
45
|
-
},
|
|
46
|
-
unmount: () => {
|
|
47
|
-
iframe.remove();
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ConnectWidget } from './ConnectWidget';
|
package/testSetup.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom/vitest';
|
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
-
"types": ["vite/client", "vitest/globals", "@testing-library/jest-dom"],
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
|
|
10
|
-
/* Bundler mode */
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"allowImportingTsExtensions": true,
|
|
13
|
-
"verbatimModuleSyntax": true,
|
|
14
|
-
"moduleDetection": "force",
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
|
|
17
|
-
/* Linting */
|
|
18
|
-
"strict": true,
|
|
19
|
-
"noUnusedLocals": true,
|
|
20
|
-
"noUnusedParameters": true,
|
|
21
|
-
"erasableSyntaxOnly": true,
|
|
22
|
-
"noFallthroughCasesInSwitch": true,
|
|
23
|
-
"noUncheckedSideEffectImports": true
|
|
24
|
-
},
|
|
25
|
-
"include": ["src"]
|
|
26
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="vitest/config" />
|
|
2
|
-
import { defineConfig } from 'vite';
|
|
3
|
-
import dts from 'vite-plugin-dts';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
entry: 'src/index.ts',
|
|
9
|
-
name: 'index',
|
|
10
|
-
fileName: 'index',
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
plugins: [dts()],
|
|
14
|
-
test: {
|
|
15
|
-
environment: 'jsdom',
|
|
16
|
-
setupFiles: ['./testSetup.ts'],
|
|
17
|
-
},
|
|
18
|
-
});
|