@telia-ace/widget-components-tab-stop 1.1.8 → 1.2.3

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/.eslintrc.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {
12
+ "@typescript-eslint/ban-types": "off",
13
+ "@typescript-eslint/no-explicit-any": "off",
14
+ "@typescript-eslint/no-unused-vars": "off",
15
+ "@typescript-eslint/no-empty-function": "off"
16
+ }
17
+ },
18
+ {
19
+ "files": ["*.js", "*.jsx"],
20
+ "rules": {}
21
+ },
22
+ {
23
+ "files": ["*.json"],
24
+ "parser": "jsonc-eslint-parser",
25
+ "rules": {
26
+ "@nx/dependency-checks": [
27
+ "error",
28
+ {
29
+ "ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
30
+ }
31
+ ]
32
+ }
33
+ }
34
+ ]
35
+ }
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @telia-ace/widget-components-tab-stop
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test @telia-ace/widget-components-tab-stop` to execute the unit tests via [Vitest](https://vitest.dev/).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-components-tab-stop",
3
- "version": "1.1.8",
3
+ "version": "1.2.3",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -10,9 +10,9 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "@telia-ace/widget-core": "^1.1.8",
14
- "@telia-ace/widget-ui": "^1.1.8",
15
- "@telia-ace/widget-utilities": "^1.1.8",
13
+ "@telia-ace/widget-core": "*",
14
+ "@telia-ace/widget-ui": "*",
15
+ "@telia-ace/widget-utilities": "*",
16
16
  "@webprovisions/platform": "^1.1.4"
17
17
  },
18
18
  "peerDependencies": {
package/project.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@telia-ace/widget-components-tab-stop",
3
+ "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/components/tab-stop/src",
5
+ "projectType": "library",
6
+ "tags": [],
7
+ "targets": {
8
+ "lint": {
9
+ "executor": "@nx/linter:eslint",
10
+ "outputs": ["{options.outputFile}"],
11
+ "options": {
12
+ "lintFilePatterns": [
13
+ "libs/components/tab-stop/**/*.{ts,tsx,js,jsx}",
14
+ "libs/components/tab-stop/package.json"
15
+ ]
16
+ }
17
+ },
18
+ "build": {
19
+ "executor": "@nx/vite:build",
20
+ "outputs": ["{options.outputPath}"],
21
+ "defaultConfiguration": "production",
22
+ "options": {
23
+ "outputPath": "dist/libs/components/tab-stop"
24
+ },
25
+ "configurations": {
26
+ "development": {
27
+ "mode": "development"
28
+ },
29
+ "production": {
30
+ "mode": "production"
31
+ }
32
+ }
33
+ },
34
+ "publish": {
35
+ "executor": "nx:run-commands",
36
+ "options": {
37
+ "command": "npm publish",
38
+ "cwd": "dist/libs/components/tab-stop"
39
+ }
40
+ },
41
+ "prerelease": {
42
+ "executor": "nx:run-commands",
43
+ "options": {
44
+ "command": "npm publish --tag=rc",
45
+ "cwd": "dist/libs/components/tab-stop"
46
+ }
47
+ },
48
+ "test": {
49
+ "executor": "@nx/vite:test",
50
+ "outputs": ["{options.reportsDirectory}"],
51
+ "options": {
52
+ "passWithNoTests": true,
53
+ "reportsDirectory": "../../../coverage/libs/components/tab-stop"
54
+ }
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,2 @@
1
+ declare type Optional<T> = T | undefined;
2
+ declare type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
@@ -0,0 +1,7 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2
+ import '@emotion/react';
3
+ import { Theme as ITheme } from '@telia-ace/widget-core';
4
+
5
+ declare module '@emotion/react' {
6
+ export interface Theme extends Partial<ITheme> {}
7
+ }
@@ -1,2 +1,3 @@
1
1
  import TabStopComponent from './tab-stop-component';
2
+
2
3
  export default TabStopComponent;
@@ -0,0 +1,12 @@
1
+ import { createReactComponent } from '@telia-ace/widget-ui';
2
+ import { Container } from '@webprovisions/platform';
3
+
4
+ export type TabStopComponentProps = {
5
+ position: 'start' | 'end';
6
+ };
7
+
8
+ const TabStopComponent = (container: Container) => {
9
+ return createReactComponent(container, 'tab-stop', import('./tab-stop'));
10
+ };
11
+
12
+ export default TabStopComponent;
@@ -0,0 +1,88 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
2
+ import styled from '@emotion/styled';
3
+ import { useContainer, useProperties } from '@telia-ace/widget-ui';
4
+ import { appendClassNames } from '@telia-ace/widget-utilities';
5
+ import React, { useEffect, useRef } from 'react';
6
+ import { TabStopComponentProps } from './tab-stop-component';
7
+
8
+ type Props = {
9
+ className: string;
10
+ };
11
+
12
+ const TabStop: React.FC<Props> = ({ className, ...other }) => {
13
+ const node = useRef() as React.MutableRefObject<HTMLDivElement>;
14
+ const container = useContainer();
15
+ const { position = 'end' } = useProperties<TabStopComponentProps>();
16
+ const positionRef = useRef(position) as React.MutableRefObject<
17
+ 'start' | 'end'
18
+ >;
19
+
20
+ useEffect(() => {
21
+ positionRef.current = position;
22
+ }, [position]);
23
+
24
+ const focusHandler = () => {
25
+ const [widgetDOMElement] = container.get(
26
+ 'widgetDOMElements'
27
+ ) as HTMLElement[];
28
+
29
+ const focusable = widgetDOMElement.querySelectorAll(
30
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]):not(.humany-tab-stop):not([tabindex=""])'
31
+ );
32
+
33
+ // ensure that elements is visible
34
+ const filtered = [].filter.call(focusable, (el: HTMLElement) => {
35
+ if (typeof window === 'undefined') {
36
+ return true;
37
+ }
38
+
39
+ const style = window.getComputedStyle(el);
40
+ if (
41
+ style.display === 'none' ||
42
+ (el.offsetWidth <= 0 && el.offsetHeight <= 0)
43
+ ) {
44
+ return false;
45
+ }
46
+ return true;
47
+ }) as HTMLElement[];
48
+
49
+ const target =
50
+ positionRef.current === 'end'
51
+ ? filtered[0]
52
+ : filtered[filtered.length - 1];
53
+
54
+ if (target) {
55
+ target.focus();
56
+ }
57
+ };
58
+
59
+ useEffect(() => {
60
+ const [widgetDOMElement] = container.get('widgetDOMElements');
61
+
62
+ if (node.current && widgetDOMElement) {
63
+ node.current.addEventListener('focus', focusHandler);
64
+ }
65
+
66
+ return () => {
67
+ if (node.current) {
68
+ node.current.removeEventListener('focus', focusHandler);
69
+ }
70
+ };
71
+ }, []);
72
+
73
+ return (
74
+ <Wrapper
75
+ {...other}
76
+ tabIndex={0}
77
+ ref={node}
78
+ className={appendClassNames(className, 'humany-tab-stop')}
79
+ />
80
+ );
81
+ };
82
+
83
+ export default TabStop;
84
+
85
+ const Wrapper = styled.div`
86
+ opacity: 0;
87
+ position: absolute;
88
+ `;
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "jsx": "react-jsx",
4
+ "allowJs": false,
5
+ "esModuleInterop": false,
6
+ "allowSyntheticDefaultImports": true,
7
+ "strict": true,
8
+ "jsxImportSource": "@emotion/react",
9
+ "types": ["vite/client", "vitest"]
10
+ },
11
+ "files": [],
12
+ "include": [],
13
+ "references": [
14
+ {
15
+ "path": "./tsconfig.lib.json"
16
+ },
17
+ {
18
+ "path": "./tsconfig.spec.json"
19
+ }
20
+ ],
21
+ "extends": "../../../tsconfig.base.json"
22
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "types": [
6
+ "node",
7
+ "@nx/react/typings/cssmodule.d.ts",
8
+ "@nx/react/typings/image.d.ts",
9
+ "vite/client"
10
+ ]
11
+ },
12
+ "exclude": [
13
+ "**/*.spec.ts",
14
+ "**/*.test.ts",
15
+ "**/*.spec.tsx",
16
+ "**/*.test.tsx",
17
+ "**/*.spec.js",
18
+ "**/*.test.js",
19
+ "**/*.spec.jsx",
20
+ "**/*.test.jsx"
21
+ ],
22
+ "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
23
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
6
+ },
7
+ "include": [
8
+ "vite.config.ts",
9
+ "src/**/*.test.ts",
10
+ "src/**/*.spec.ts",
11
+ "src/**/*.test.tsx",
12
+ "src/**/*.spec.tsx",
13
+ "src/**/*.test.js",
14
+ "src/**/*.spec.js",
15
+ "src/**/*.test.jsx",
16
+ "src/**/*.spec.jsx",
17
+ "src/**/*.d.ts"
18
+ ]
19
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,65 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vite';
3
+ import react from '@vitejs/plugin-react-swc';
4
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
5
+ import dts from 'vite-plugin-dts';
6
+ import * as path from 'path';
7
+ import packageJson from './package.json';
8
+
9
+ export default defineConfig({
10
+ cacheDir: '../../../node_modules/.vite/@telia-ace/widget-components-tab-stop',
11
+
12
+ plugins: [
13
+ dts({
14
+ entryRoot: 'src',
15
+ tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'),
16
+ skipDiagnostics: true,
17
+ }),
18
+ react(),
19
+ nxViteTsPaths(),
20
+ ],
21
+
22
+ // Uncomment this if you are using workers.
23
+ // worker: {
24
+ // plugins: [ nxViteTsPaths() ],
25
+ // },
26
+
27
+ // Configuration for building your library.
28
+ // See: https://vitejs.dev/guide/build.html#library-mode
29
+ build: {
30
+ lib: {
31
+ // Could also be a dictionary or array of multiple entry points.
32
+ entry: 'src/index.ts',
33
+ name: '@telia-ace/widget-components-tab-stop',
34
+ fileName: 'index',
35
+ // Change this to the formats you want to support.
36
+ // Don't forget to update your package.json as well.
37
+ formats: ['es', 'cjs'],
38
+ },
39
+ rollupOptions: {
40
+ // External packages that should not be bundled into your library.
41
+ external: [
42
+ 'react',
43
+ 'react-dom',
44
+ 'react/jsx-runtime',
45
+ '@emotion/styled',
46
+ '@emotion/cache',
47
+ '@emotion/react',
48
+ 'react-router',
49
+ 'react-router-dom',
50
+ 'react-transition-group',
51
+ ...Object.keys(packageJson.dependencies || {}),
52
+ ...Object.keys(packageJson.peerDependencies || {}),
53
+ ],
54
+ },
55
+ },
56
+
57
+ test: {
58
+ globals: true,
59
+ cache: {
60
+ dir: '../../../node_modules/.vitest',
61
+ },
62
+ environment: 'jsdom',
63
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
64
+ },
65
+ });
package/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";const t=require("@telia-ace/widget-ui"),o=e=>t.createReactComponent(e,"tab-stop",Promise.resolve().then(()=>require("./tab-stop-bd0fb6e0.js")));module.exports=o;
package/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- import { createReactComponent as o } from "@telia-ace/widget-ui";
2
- const p = (t) => o(t, "tab-stop", import("./tab-stop-a53e4966.mjs"));
3
- export {
4
- p as default
5
- };
@@ -1,39 +0,0 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import b from "@emotion/styled";
3
- import { useContainer as g, useProperties as y } from "@telia-ace/widget-ui";
4
- import { appendClassNames as w } from "@telia-ace/widget-utilities";
5
- import { useRef as u, useEffect as a } from "react";
6
- const C = ({ className: d, ...l }) => {
7
- const t = u(), s = g(), { position: e = "end" } = y(), i = u(e);
8
- a(() => {
9
- i.current = e;
10
- }, [e]);
11
- const c = () => {
12
- const [n] = s.get(
13
- "widgetDOMElements"
14
- ), p = n.querySelectorAll(
15
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]):not(.humany-tab-stop):not([tabindex=""])'
16
- ), o = [].filter.call(p, (r) => typeof window > "u" ? !0 : !(window.getComputedStyle(r).display === "none" || r.offsetWidth <= 0 && r.offsetHeight <= 0)), f = i.current === "end" ? o[0] : o[o.length - 1];
17
- f && f.focus();
18
- };
19
- return a(() => {
20
- const [n] = s.get("widgetDOMElements");
21
- return t.current && n && t.current.addEventListener("focus", c), () => {
22
- t.current && t.current.removeEventListener("focus", c);
23
- };
24
- }, []), /* @__PURE__ */ m(
25
- x,
26
- {
27
- ...l,
28
- tabIndex: 0,
29
- ref: t,
30
- className: w(d, "humany-tab-stop")
31
- }
32
- );
33
- }, x = b.div`
34
- opacity: 0;
35
- position: absolute;
36
- `;
37
- export {
38
- C as default
39
- };
@@ -1,4 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),b=require("@emotion/styled"),d=require("@telia-ace/widget-ui"),m=require("@telia-ace/widget-utilities"),t=require("react"),y=({className:f,...l})=>{const e=t.useRef(),i=d.useContainer(),{position:n="end"}=d.useProperties(),u=t.useRef(n);t.useEffect(()=>{u.current=n},[n]);const c=()=>{const[s]=i.get("widgetDOMElements"),p=s.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]):not(.humany-tab-stop):not([tabindex=""])'),r=[].filter.call(p,o=>typeof window>"u"?!0:!(window.getComputedStyle(o).display==="none"||o.offsetWidth<=0&&o.offsetHeight<=0)),a=u.current==="end"?r[0]:r[r.length-1];a&&a.focus()};return t.useEffect(()=>{const[s]=i.get("widgetDOMElements");return e.current&&s&&e.current.addEventListener("focus",c),()=>{e.current&&e.current.removeEventListener("focus",c)}},[]),g.jsx(w,{...l,tabIndex:0,ref:e,className:m.appendClassNames(f,"humany-tab-stop")})},w=b.div`
2
- opacity: 0;
3
- position: absolute;
4
- `;exports.default=y;
@@ -1,6 +0,0 @@
1
- import { Container } from '@webprovisions/platform';
2
- export type TabStopComponentProps = {
3
- position: 'start' | 'end';
4
- };
5
- declare const TabStopComponent: (container: Container) => Promise<void>;
6
- export default TabStopComponent;
package/tab-stop.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- type Props = {
3
- className: string;
4
- };
5
- declare const TabStop: React.FC<Props>;
6
- export default TabStop;