Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@ on:
types: [created]
workflow_dispatch:

permissions:
contents: read
id-token: write # Required for npm provenance (Trusted Publishing)

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 24
cache: 'yarn'
registry-url: https://registry.npmjs.org/

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build package
run: yarn install && yarn build
- name: Publish package on NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: yarn build

- name: Publish package on NPM (Trusted Publishing)
run: npm publish --provenance --access public --tag $(node -p "const v=require('./package.json').version;v.includes('-')?v.match(/-(.+?)\./)[1]:'latest'")
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressms/smartapp-sdk",
"version": "1.14.0",
"version": "1.15.0-alpha.2",
"description": "Smartapp SDK",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand All @@ -16,13 +16,17 @@
},
"repository": {
"type": "git",
"url": "git@github.com:ExpressApp/smartapp-sdk.git"
"url": "git+https://github.com/ExpressApp/smartapp-sdk.git"
},
"engines": {
"node": ">=10"
},
"author": "",
"license": "ISC",
"publishConfig": {
"access": "public",
"provenance": true
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
Expand Down
46 changes: 44 additions & 2 deletions src/lib/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
const COPY_RESTRICION_STYLE_ID = 'native-copy-restriction'

export const useQuery = () => {
const urlSearchParams = new URLSearchParams(window.location.search)
return Object.fromEntries(urlSearchParams.entries())
}

const noop = (event: Event): boolean => {
event.preventDefault()
event.stopImmediatePropagation()
return false
}

const preventSelection = (event: Event): void => {
const isInput =
event.target instanceof Element && event.target.closest('input, textarea, [contenteditable="true"]') !== null

if (!isInput) noop(event)
}

const addCopyRestrictionStyles = (): void => {
if (document.getElementById(COPY_RESTRICION_STYLE_ID)) return

const style = document.createElement('style')
style.id = COPY_RESTRICION_STYLE_ID
style.textContent = `
html,
body,
body * {
-webkit-user-select: none !important;
user-select: none !important;
-webkit-touch-callout: none !important;
}

body input,
body textarea,
body [contenteditable="true"],
body [contenteditable="true"] * {
-webkit-user-select: text !important;
user-select: text !important;
-webkit-touch-callout: default !important;
}
`

const styleRoot = document.head || document.documentElement
styleRoot.appendChild(style)
}

export const disableCopy = () => {
document.addEventListener('contextmenu', noop);
document.addEventListener('copy', noop)
document.addEventListener('contextmenu', noop, true)
document.addEventListener('copy', noop, true)
document.addEventListener('cut', noop, true)
document.addEventListener('selectstart', preventSelection, true)

addCopyRestrictionStyles()
}
Loading