New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sumor/ux

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/ux - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

index.js

46

package.json
{
"name": "@sumor/ux",
"description": "Sumor Cloud UI Library",
"version": "1.1.3",
"version": "1.1.4",
"license": "MIT",

@@ -10,4 +10,10 @@ "repository": "sumor-cloud/ux",

"type": "module",
"main": "./src/index.js",
"exports": "./src/index.js",
"main": "./dist/index.umd.cjs",
"module": "./dist/index.es.js",
"exports": {
".": {
"import": "./dist/index.es.js",
"require": "./dist/index.umd.cjs"
}
},
"keywords": [

@@ -18,20 +24,37 @@ "vue"

"axios": "^1.6.8",
"dayjs": "^1.11.10",
"vconsole": "^3.15.1",
"vue": "^3.3.4"
"dayjs": "^1.11.11",
"pinia": "^2.1.6",
"vue": "^3.3.4",
"vue-lazyload": "^3.0.0",
"vue-router": "^4.2.4"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@vitejs/plugin-vue": "^5.0.4",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0"
"eslint-config-standard": "^17.1.0",
"fs-extra": "^11.2.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-html-reporter": "^3.10.2",
"jsdom": "^24.0.0",
"puppeteer": "^22.8.0",
"vite": "^5.2.0"
},
"files": [
"src",
"dist",
"LICENSE",
"index.js",
".gitignore"
],
"engines": {
"node": ">=16.0.0"
},
"scripts": {
"lint": "eslint --ext .js src",
"audit": "npm audit",
"test": "echo \"Error: no test specified\"",
"coverage": "echo \"Error: no test specified\"",
"lint": "eslint .",
"build": "vite build",
"setup-browser": "npx puppeteer browsers install chrome",
"test": "npm run setup-browser && node --experimental-vm-modules node_modules/jest/bin/jest.js --testMatch='**/test/**/*.test.js'",
"coverage": "npm run setup-browser && node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --testMatch='**/test/**/*.test.js'",
"push-tag": "git push --tags && git push",

@@ -42,4 +65,5 @@ "publish-beta": "npm version prerelease --preid beta && npm run push-tag",

"publish-release-major": "npm version major && npm run push-tag",
"prepare": "husky",
"check": "eslint --fix . && npm audit fix --force && npm run coverage"
}
}
import { useSSRContext } from 'vue'
import init from './init.js'
import setPageInfo from './setPageInfo.js'
import call from './call.js'
import time from './tools/time'
import table from './tools/table'
import qrcode from './tools/qrcode'
import copy from './tools/copy'
import upload from './upload'
import load from './tools/load'
import guessTimezone from './tools/time/timezone.js'
export default (options) => {
options = options || {}
const SSR = options.SSR || false
import checkLandscape from './attributes/checkLandscape.js'
import checkIphoneX from './attributes/checkIphoneX.js'
import checkSize from './attributes/checkSize.js'
import setPageInfo from './attributes/setPageInfo.js'
export default ({ SSR }) => {
return {
state: () => {
const { width, height } = checkSize()
let language; let isWechat = false
if (typeof navigator !== 'undefined') {
language = navigator.language || navigator.browserLanguage
isWechat = /micromessenger/i.test(navigator.userAgent)
}
language = language || 'zh-CN'
const timezone = guessTimezone() || 'Asia/Shanghai'
return {
table,
qrcode,
copy,
upload,
load,
dark: false,
isWechat,
iphoneX: checkIphoneX(),
landscape: checkLandscape(),
width,
height,
language,
timezone,
screen: {
height: 0,
width: 0,
dark: false,
landscape: false,
isIPhone: false,
isIPhoneX: false,
isWechat: false
},
personalization: {
dark: null,
language: null,
timezone: null
},
pageInfo: {

@@ -50,2 +32,3 @@ title: '',

},
instance: {},
meta: {

@@ -63,8 +46,31 @@ name: null,

data: {}
}
},
_listened: false
}
},
getters: {
time (state) {
return time(state)
dark (state) {
if (state.personalization.dark !== null) {
return state.personalization.dark
} else {
return state.screen.dark
}
},
language (state) {
if (state.personalization.language !== null) {
return state.personalization.language
} else if (typeof window !== 'undefined' && window) {
return window.navigator.language
} else {
return 'en'
}
},
timezone (state) {
if (state.personalization.timezone !== null) {
return state.personalization.timezone
} else if (typeof window !== 'undefined' && window) {
return window.Intl.DateTimeFormat().resolvedOptions().timeZone
} else {
return 'Asia/Shanghai'
}
}

@@ -98,47 +104,61 @@ },

},
setDark (dark) {
if (!SSR) {
const name = 'dark'
let classes = document.documentElement.className.split(' ')
classes = classes.filter(item => item !== name)
if (dark) {
classes.push(name)
updateScreen () {
if (typeof window !== 'undefined' && window) {
const dark = window.matchMedia('(prefers-color-scheme: dark)').matches
const screen = {
height: window.innerHeight,
width: window.innerWidth,
dark,
landscape: window.innerHeight <= window.innerWidth
}
document.documentElement.className = classes.join(' ')
const longest = !screen.landscape ? screen.height : screen.width
screen.isIPhone = /iphone/gi.test(window.navigator.userAgent)
screen.isIPhoneX = screen.isIPhone && longest >= 812
screen.isWechat = /micromessenger/gi.test(window.navigator.userAgent)
this.screen = Object.assign({}, this.screen, screen)
}
this.dark = dark
},
resize () {
this.iphoneX = checkIphoneX()
this.landscape = checkLandscape()
const { width, height } = checkSize()
this.width = width
this.height = height
},
async updateMeta (force) {
if (!this.meta.name || force) {
const res = await call('/sumor/meta')
Object.assign(this.meta, res.data.data)
updatePersonalization (key, value) {
if (typeof window !== 'undefined' && window) {
// load from localStorage
const personalization = window.localStorage.getItem('personalization')
if (personalization !== JSON.stringify(this.personalization)) {
this.personalization = JSON.parse(personalization) || {}
const personalizationOptions = ['dark', 'language', 'timezone']
personalizationOptions.forEach(key => {
if (this.personalization[key] === undefined) {
this.personalization[key] = null
}
})
window.sumorPersonalization = JSON.parse(personalization)
}
}
// update key value
if (key) {
if (value === undefined) {
value = null
}
this.personalization = Object.assign({}, this.personalization)
this.personalization[key] = value
}
if (typeof window !== 'undefined' && window) {
const latest = JSON.stringify(this.personalization)
const last = window.localStorage.getItem('personalization')
if (latest !== last) {
// sync to global personalization
window.sumorPersonalization = JSON.parse(JSON.stringify(this.personalization))
// save to localStorage
window.localStorage.setItem('personalization', JSON.stringify(this.personalization))
}
}
},
async updateToken () {
const res = await this.call('/sumor/token')
Object.assign(this.token, res.data)
// this.token.id = res.data.id || null;
// this.token.user = res.data.user || null;
// this.token.time = res.data.time || null;
// this.token.permission = res.data.permission || {};
// this.token.data = res.data.data || {};
},
async logout () {
await this.call('/sumor/logout')
await this.updateToken()
},
async call (api, params) {
if (SSR) {
throw new Error('禁止在SSR模式下调用API,这将会引起性能等问题,请使用SSRContext模式载入数据')
throw new Error('Forbidden to call API in SSR mode, which will cause performance and other issues. Please use SSRContext mode to load data')
}
const options = {}
options.language = this.language
options.timezone = this.timezone
const response = await call(api, params, options)

@@ -159,2 +179,21 @@ if (!response.error) {

},
async updateMeta (force) {
if (!this.meta.name || force) {
const res = await call('/sumor/meta')
Object.assign(this.meta, res.data.data)
}
},
async updateToken () {
const res = await this.call('/sumor/token')
Object.assign(this.token, res.data)
// this.token.id = res.data.id || null;
// this.token.user = res.data.user || null;
// this.token.time = res.data.time || null;
// this.token.permission = res.data.permission || {};
// this.token.data = res.data.data || {};
},
async logout () {
await this.call('/sumor/logout')
await this.updateToken()
},
form (path) {

@@ -183,2 +222,15 @@ const call = this.call

return new Form()
},
listen () {
if (!this._listened) {
this._listened = true
init(this)
this._listenTimer = setInterval(() => {
this.updatePersonalization()
}, 100)
}
},
stop () {
this._listened = false
clearInterval(this._listenTimer)
}

@@ -185,0 +237,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc