diff --git a/.github/workflows/check-tree-shakeability.yml b/.github/workflows/check-tree-shakeability.yml deleted file mode 100644 index 68cf86333..000000000 --- a/.github/workflows/check-tree-shakeability.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Check tree-shakeability -on: [pull_request] -jobs: - build: - runs-on: ubuntu-latest - permissions: - pull-requests: write - concurrency: ci-treeshake-${{ github.ref }} - steps: - - uses: actions/checkout@v4 - - name: Setup Node.js with Yarn cache - uses: actions/setup-node@v4 - with: - node-version: '20' - cache: 'yarn' - - - name: Install dependencies - run: yarn --frozen-lockfile - - - name: Build artifacts - run: yarn build - - - name: Run agadoo - id: agadoo - run: | - # Run Agadoo and store the output for further usage - # We store the process stdout and stderr to tmp files - STDOUT_F=$(mktemp) - STDERR_F=$(mktemp) - # Run agadoo and capture errors without breaking the workflow - $(npx agadoo 2> $STDERR_F > $STDOUT_F) && true - - # Infer the result from the first word of the last line - RET="$(cat $STDERR_F | tail -1 | cut -d' ' -f 1)" - - # In order to be used in GH actions `echo "::set-output` the - # multi-line output must be escaped. - STDOUT="$(cat $STDOUT_F)" - STDOUT="${STDOUT//'%'/%25}" - STDOUT="${STDOUT//$'\n'/%0A}" - STDOUT="${STDOUT//$'\r'/%0D}" - STDERR="$(cat $STDERR_F)" - STDERR="${STDERR//'%'/%25}" - STDERR="${STDERR//$'\n'/%0A}" - STDERR="${STDERR//$'\r'/%0D}" - echo "::set-output name=stdout::$STDOUT" - echo "::set-output name=stderr::$STDERR" - if [[ $RET == 'Success!' ]]; then - echo "::set-output name=status::tree-shakeable" - else - echo "::set-output name=status::not tree-shakeable" - fi - echo "$STDOUT" - echo "" - echo "$STDERR" - # Clean-up - rm $STDOUT_F - rm $STDERR_F - exit 0 - - name: Fail if cannot tree-shake - if: ${{ steps.agadoo.outputs.status == 'not tree-shakeable' }} - run: exit 1 diff --git a/package.json b/package.json index c57f6dfb8..1b33395ed 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,13 @@ "main": "./dist/index.cjs" } }, - "sideEffects": false, + "sideEffects": [ + "dist/track-focus.js", + "src/track-focus.js", + "dist/index.ts", + "dist/index.js", + "src/index.ts" + ], "files": [ "dist", "src" diff --git a/src/index.ts b/src/index.ts index 01e55a7d8..6f429ee77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -299,52 +299,4 @@ export type { UncontrolledTooltipProps } from 'reactstrap'; -// Focus Management - -/** - * -------------------------------------------------------------------------- - * Bootstrap Italia (https://italia.github.io/bootstrap-italia/) - * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS - * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE) - * -------------------------------------------------------------------------- - */ - -// const DATA_MOUSE_FOCUS = 'data-focus-mouse' -// const CLASS_NAME_MOUSE_FOCUS = 'focus--mouse' - -// class TrackFocus { -// private _usingMouse: boolean; -// constructor() { -// this._usingMouse = false - -// this._bindEvents() -// } - -// _bindEvents() { -// if (typeof document === 'undefined') { -// return -// } -// const events = ['keydown', 'mousedown'] -// events.forEach((evtName) => { -// document.addEventListener(evtName, (evt) => { -// this._usingMouse = evt.type === 'mousedown' -// }) -// }) -// document.addEventListener('focusin', (evt: Event) => { -// if (this._usingMouse) { -// if (evt.target) { -// (evt.target as HTMLElement).classList.add(CLASS_NAME_MOUSE_FOCUS); -// (evt.target as HTMLElement).setAttribute(DATA_MOUSE_FOCUS, 'true') -// } -// } -// }) -// document.addEventListener('focusout', (evt: Event) => { -// if (evt.target) { -// (evt.target as HTMLElement).classList.remove(CLASS_NAME_MOUSE_FOCUS); -// (evt.target as HTMLElement).setAttribute(DATA_MOUSE_FOCUS, 'false') -// } -// }) -// } -// } - -// new TrackFocus() +import "./track-focus.js" \ No newline at end of file diff --git a/src/track-focus.js b/src/track-focus.js new file mode 100644 index 000000000..7883aefb6 --- /dev/null +++ b/src/track-focus.js @@ -0,0 +1,49 @@ + +// Focus Management + +/** + * -------------------------------------------------------------------------- + * Bootstrap Italia (https://italia.github.io/bootstrap-italia/) + * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS + * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + +const DATA_MOUSE_FOCUS = 'data-focus-mouse' +const CLASS_NAME_MOUSE_FOCUS = 'focus--mouse' + +class TrackFocus { + constructor() { + this._usingMouse = false + + this._bindEvents() + } + + _bindEvents() { + if (typeof document === 'undefined') { + return + } + const events = ['keydown', 'mousedown'] + events.forEach((evtName) => { + document.addEventListener(evtName, (evt) => { + this._usingMouse = evt.type === 'mousedown' + }) + }) + document.addEventListener('focusin', (evt) => { + if (this._usingMouse) { + if (evt.target) { + evt.target.classList.add(CLASS_NAME_MOUSE_FOCUS); + evt.target.setAttribute(DATA_MOUSE_FOCUS, 'true') + } + } + }) + document.addEventListener('focusout', (evt) => { + if (evt.target) { + evt.target.classList.remove(CLASS_NAME_MOUSE_FOCUS); + evt.target.setAttribute(DATA_MOUSE_FOCUS, 'false') + } + }) + } +} + +new TrackFocus() \ No newline at end of file diff --git a/tsup.config.ts b/tsup.config.ts index 6c50f6cea..b40d7de49 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from 'tsup'; export default defineConfig({ - entry: ['src/**/*.@(ts|tsx)'], + entry: ['src/**/*.@(js|ts|tsx)'], format: ['cjs', 'esm'], target: 'esnext', dts: false,