Skip to content

Commit

Permalink
refactor: ♻️ refactor plugin-interaction-breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerbenw committed Nov 12, 2024
1 parent 49b81dc commit a04fe2c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
14 changes: 13 additions & 1 deletion packages/plugin-interaction-breadcrumbs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
"name": "@bugsnag/plugin-interaction-breadcrumbs",
"version": "8.1.1",
"main": "interaction-breadcrumbs.js",
"types": "dist/types/interaction-breadcrumbs.d.ts",
"exports": {
".": {
"types": "./dist/types/interaction-breadcrumbs.d.ts",
"default": "./dist/interaction-breadcrumbs.js",
"import": "./dist/interaction-breadcrumbs.mjs"
}
},
"description": "@bugsnag/js plugin to record UI click events as breadcrumbs",
"homepage": "https://www.bugsnag.com/",
"repository": {
Expand All @@ -14,7 +22,11 @@
"files": [
"*.js"
],
"scripts": {},
"scripts": {
"build": "npm run build:npm",
"build:npm": "rollup --config rollup.config.npm.mjs",
"clean": "rm -rf dist/*"
},
"author": "Bugsnag",
"license": "MIT",
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-interaction-breadcrumbs/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import createRollupConfig from '../../.rollup/index.mjs'

export default createRollupConfig({
input: 'src/interaction-breadcrumbs.ts'
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Plugin } from '@bugsnag/core'
import type ClientWithInternals from 'packages/core/client'

/*
* Leaves breadcrumbs when the user interacts with the DOM
*/
module.exports = (win = window) => ({
export default (win = window): Plugin<ClientWithInternals> => ({
load: (client) => {
if (!('addEventListener' in win)) return
if (!client._isBreadcrumbTypeEnabled('user')) return
Expand All @@ -23,7 +26,8 @@ module.exports = (win = window) => ({

const trim = /^\s*([^\s][\s\S]{0,139}[^\s])?\s*/

function getNodeText (el) {
// TODO: Fix Type
function getNodeText (el: any) {
let text = el.textContent || el.innerText || ''

if (!text && (el.type === 'submit' || el.type === 'button')) {
Expand All @@ -40,7 +44,8 @@ function getNodeText (el) {
}

// Create a label from tagname, id and css class of the element
function getNodeSelector (el, win) {
// TODO: Fix Type
function getNodeSelector (el: any, win: Window): string {
const parts = [el.tagName]
if (el.id) parts.push('#' + el.id)
if (el.className && el.className.length) parts.push(`.${el.className.split(' ').join('.')}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from '../'
import plugin from '../src/interaction-breadcrumbs'

import Client from '@bugsnag/core/client'
import Breadcrumb from '@bugsnag/core/breadcrumb'
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-interaction-breadcrumbs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"]
}

0 comments on commit a04fe2c

Please sign in to comment.