@questwork/vue-q-list-vue3 3.1.0 → 3.1.1

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.
@@ -75,7 +75,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75
75
  ---
76
76
 
77
77
  Name: @questwork/utilities
78
- Version: 0.1.65
78
+ Version: 0.1.67
79
79
  License: MIT
80
80
  Private: false
81
81
  Description: Questwork utilities
@@ -0,0 +1,57 @@
1
+ const { getValidation } = require("./getValidation")
2
+ const { getValue } = require("./getValue")
3
+
4
+ function getTitle(titleTemplate, data) {
5
+ return titleTemplate.reduce((acc, item) => {
6
+ const { type, value = '', restriction, template, format, showMinutes } = item
7
+ switch (type) {
8
+ case('label'): {
9
+ if (getValidation({ rule: restriction, data })) {
10
+ acc += (value.toString())
11
+ }
12
+ break
13
+ }
14
+ case('value'): {
15
+ if (getValidation({ rule: restriction, data })) {
16
+ const _value = getValue(value, data) || ''
17
+ acc += (_value.toString())
18
+ }
19
+ break
20
+ }
21
+ case('array'): {
22
+ if (getValidation({ rule: restriction, data })) {
23
+ const _value = getValue(value, data) || []
24
+ acc += _value.reduce((_acc, item) => {
25
+ return _acc += getTitle(template, item)
26
+ }, '')
27
+ }
28
+
29
+ break
30
+ }
31
+ case('ellipsis'): {
32
+ if (getValidation({ rule: restriction, data })) {
33
+ const { maxLength } = item
34
+ const _value = getValue(value, data) || ''
35
+ if (_value.length <= maxLength) {
36
+ acc += (_value.toString())
37
+ } else {
38
+ acc += `${_value.substr(0, maxLength)}...`
39
+ }
40
+ }
41
+ break
42
+ }
43
+ case ('date'): {
44
+ if (getValidation({ rule: restriction, data })) {
45
+ const _value = getValue(value, data) || ''
46
+ acc += (formatDate({ date: _value, showMinutes, format }).toString())
47
+ }
48
+ break
49
+ }
50
+ }
51
+ return acc
52
+ }, '')
53
+ }
54
+
55
+ module.exports = {
56
+ getTitle
57
+ }
@@ -0,0 +1,26 @@
1
+ function getTooltipPosition({ tooltipContainer, cellText, window }) {
2
+ const containerRect = tooltipContainer.getBoundingClientRect()
3
+ const textRect = cellText.getBoundingClientRect()
4
+
5
+ let left = textRect.left + window.scrollX
6
+ let top = textRect.bottom + window.scrollY
7
+
8
+ if (left + containerRect.width > window.innerWidth) {
9
+ left = window.innerWidth - containerRect.width
10
+ }
11
+
12
+ if (top + containerRect.height > window.innerHeight) {
13
+ top = textRect.top + window.scrollY - containerRect.height
14
+ }
15
+
16
+ if (top < 0) {
17
+ top = textRect.bottom + window.scrollY
18
+ }
19
+
20
+ tooltipContainer.style.left = `${left}px`
21
+ tooltipContainer.style.top = `${top}px`
22
+ }
23
+
24
+ module.exports = {
25
+ getTooltipPosition
26
+ }
@@ -0,0 +1,90 @@
1
+ const { getValue } = require('./getValue')
2
+
3
+ function getValidation({ rule, data }) {
4
+ if (!rule) {
5
+ return true
6
+ }
7
+ const { key = '', value } = rule
8
+ const [valueAttribute] = Object.keys(value || {})
9
+
10
+ if (!key) {
11
+ switch (valueAttribute) {
12
+ case '$and': {
13
+ const arr = value['$and']
14
+ return arr.reduce((acc, item) => (acc && getValidation({ rule: item, data })), true)
15
+ }
16
+ case '$or': {
17
+ const arr = value['$or']
18
+ return arr.reduce((acc, item) => (acc || getValidation({ rule: item, data })), false)
19
+ }
20
+ default:
21
+ return false
22
+ }
23
+ }
24
+
25
+ const rowValue = getValue(key, data)
26
+ switch (valueAttribute) {
27
+ case '$empty': {
28
+ return !rowValue === !!value['$empty']
29
+ }
30
+ case '$eq': {
31
+ return rowValue === value['$eq']
32
+ }
33
+ case '$gt': {
34
+ return rowValue > value['$gt']
35
+ }
36
+ case '$gte': {
37
+ return rowValue >= value['$gte']
38
+ }
39
+ case '$in': {
40
+ if (Array.isArray(rowValue)) {
41
+ return !!rowValue.find((e) => (value['$in'].includes(e)))
42
+ }
43
+ if (typeof rowValue !== 'object') {
44
+ return !!value['$in'].includes(rowValue)
45
+ }
46
+ return false
47
+ }
48
+ case '$lt': {
49
+ return rowValue < value['$lt']
50
+ }
51
+ case '$lte': {
52
+ return rowValue <= value['$lte']
53
+ }
54
+ case '$ne': {
55
+ return rowValue !== value['$ne']
56
+ }
57
+ case '$notIn': {
58
+ if (Array.isArray(rowValue)) {
59
+ return !rowValue.find((e) => (value['$notIn'].includes(e)))
60
+ }
61
+ if (typeof rowValue !== 'object') {
62
+ return !value['$notIn'].includes(rowValue)
63
+ }
64
+ return false
65
+ }
66
+ case '$intervalTimeGt': {
67
+ const now = new Date().getTime()
68
+ const timestamp = new Date(rowValue).getTime()
69
+ return (now - timestamp) > value['$intervalTimeGt']
70
+ }
71
+ case '$intervalTimeLt': {
72
+ const now = new Date().getTime()
73
+ const timestamp = new Date(rowValue).getTime()
74
+ return (now - timestamp) < value['$intervalTimeLt']
75
+ }
76
+ case '$range': {
77
+ const [min, max] = value['$range']
78
+ if (typeof min === 'number' && typeof max === 'number' && rowValue >= min && rowValue <= max) {
79
+ return true
80
+ }
81
+ return false
82
+ }
83
+ default:
84
+ return false
85
+ }
86
+ }
87
+
88
+ module.exports = {
89
+ getValidation
90
+ }
@@ -0,0 +1,18 @@
1
+ function getValue(key, value) {
2
+ return getValueInObj({ keys: key.split('.'), obj: value })
3
+ }
4
+
5
+ function getValueInObj({ keys, obj }) {
6
+ if (keys.length === 0) {
7
+ return obj
8
+ }
9
+ const firstKey = keys.shift()
10
+ if (obj && obj.hasOwnProperty(firstKey)) {
11
+ return getValueInObj({ keys, obj: obj[firstKey] })
12
+ }
13
+ return obj
14
+ }
15
+
16
+ module.exports = {
17
+ getValue
18
+ }
@@ -1,6 +1,13 @@
1
1
  const { getPopupPosition } = require('./getPopupPosition')
2
+ const { getTitle } = require('./getTitle')
3
+ const { getTooltipPosition } = require('./getTooltipPosition')
4
+ const { getValidation } = require('./getValidation')
5
+ const { getValue } = require('./getValue')
2
6
 
3
7
  module.exports = {
4
- getPopupPosition
8
+ getPopupPosition,
9
+ getTitle,
10
+ getTooltipPosition,
11
+ getValidation,
12
+ getValue
5
13
  }
6
- exports.getPopupPosition = getPopupPosition
package/lib/index.js CHANGED
@@ -1,11 +1,7 @@
1
- // const factories = require('./factories')
2
1
  const models = require('./models')
2
+ const helpers = require('./helpers')
3
3
 
4
4
  module.exports = {
5
- // ...factories,
6
5
  ...models,
6
+ ...helpers
7
7
  }
8
-
9
- exports.QListBulkButton = models.QListBulkButton
10
- exports.QRow = models.QRow
11
- exports.QListButton = models.QListButton
@@ -2,6 +2,7 @@ const { KeyValueObject } = require('../keyValueObject')
2
2
  class QListButton {
3
3
  constructor(options = {}) {
4
4
  options = options || {}
5
+ this.id = options.actionId
5
6
  this.active = (typeof options.active !== 'undefined') ? !!options.active : true
6
7
  this.creator = options.creator
7
8
  this.css = options.css || {}
@@ -1,5 +1,5 @@
1
1
  const { QRow } = require('./qRow')
2
2
 
3
3
  module.exports = {
4
- QRow
4
+ QRow,
5
5
  }
@@ -9,6 +9,7 @@ class QRow {
9
9
  this.cssNames = options.cssNames || []
10
10
  this.deleted = options.deleted || false
11
11
  this.duration = options.duration
12
+ this.editable = (typeof options.editable === 'boolean') ? options.editable : true
12
13
  this.getActions = options.getActions
13
14
  this.new = options.new || false
14
15
  this.owner = options.owner
@@ -150,6 +151,10 @@ class QRow {
150
151
  return this
151
152
  }
152
153
 
154
+ setEditable(val) {
155
+ this.editable = val
156
+ }
157
+
153
158
  toggleActive() {
154
159
  this.active = !this.active
155
160
  this.new = false
@@ -208,5 +213,5 @@ function setShouldBeVisible(shouldBeVisible) {
208
213
  }
209
214
 
210
215
  module.exports = {
211
- QRow
216
+ QRow,
212
217
  }
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "@questwork/vue-q-list-vue3",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Questwork vue component for displaying a list",
5
- "main": "dist/q-list.min.js",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./dist/q-list.min.js",
8
+ "require": "./dist/q-list.min.js"
9
+ },
10
+ "./style.css": "./dist/q-list.min.css"
11
+ },
6
12
  "author": {
7
13
  "name": "Questwork Consulting Limited",
8
14
  "email": "info@questwork.com",
@@ -13,58 +19,44 @@
13
19
  "@babel/core": "^7.17.8",
14
20
  "@babel/eslint-parser": "^7.17.0",
15
21
  "@babel/preset-env": "^7.22.10",
16
- "@questwork/utilities": "^0.1.51",
22
+ "@questwork/utilities": "^0.1.67",
17
23
  "@questwork/vue-q-buttons-vue3": "^3.1.0",
18
24
  "@questwork/vue-q-paginator-vue3": "^3.1.0",
19
- "@storybook/addon-links": "^7.3.2",
20
- "@storybook/addon-viewport": "^7.3.2",
21
- "@storybook/source-loader": "^7.3.2",
22
- "@storybook/vue": "^7.3.2",
23
- "@storybook/vue-webpack5": "^7.3.2",
24
- "@storybook/vue3": "^7.3.2",
25
- "@storybook/vue3-vite": "^7.3.2",
26
- "@vitejs/plugin-vue": "^5.1.4",
25
+ "@storybook/addon-essentials": "8.5.3",
26
+ "@storybook/addon-links": "^8.4.7",
27
+ "@storybook/addon-viewport": "^8.4.7",
28
+ "@storybook/vue3": "^8.4.7",
29
+ "@storybook/vue3-vite": "^8.4.7",
30
+ "@vitejs/plugin-vue": "^5.2.1",
27
31
  "babel-loader": "^8.2.4",
28
32
  "chai": "^4.3.6",
29
33
  "chromedriver": "^116.0.0",
30
- "clean-webpack-plugin": "^3.0.0",
34
+ "color-name": "^2.0.0",
31
35
  "cross-env": "^7.0.3",
32
- "css-loader": "^3.6.0",
33
36
  "eslint": "^8.47.0",
34
- "eslint-plugin-storybook": "^0.9.0",
35
- "eslint-plugin-vue": "^9.29.0",
36
- "file-loader": "^6.2.0",
37
- "gulp": "^4.0.2",
37
+ "eslint-plugin-storybook": "^0.11.1",
38
+ "eslint-plugin-vue": "^9.32.0",
38
39
  "mocha": "^9.2.2",
39
40
  "rollup-plugin-license": "^3.5.3",
40
- "rollup-webpack-umd": "^0.1.2",
41
- "sass": "^1.49.11",
42
- "sass-loader": "^8.0.2",
41
+ "sass": "^1.83.4",
43
42
  "selenium-webdriver": "^4.11.1",
44
43
  "sinon": "^9.2.4",
45
44
  "sinon-chai": "^3.7.0",
46
- "storybook": "^7.3.2",
47
- "style-loader": "^1.3.0",
48
- "url-loader": "^4.1.1",
45
+ "storybook": "^8.4.7",
49
46
  "vite": "^5.4.9",
50
47
  "vite-plugin-commonjs": "^0.10.3",
51
- "vite-plugin-lib-inject-css": "^2.1.1",
52
- "vue": "^3.5.12",
53
- "vue-loader": "^15.9.8",
54
- "vue-template-compiler": "^2.6.14",
55
- "webpack": "^5.71.0",
56
- "webpack-cli": "^4.9.2",
57
- "webpack-merge": "^4.2.2",
58
- "webpack-node-externals": "^1.7.2"
48
+ "vue": "^3.5.12"
59
49
  },
60
50
  "engines": {
61
51
  "node": ">=10.0.0"
62
52
  },
63
53
  "scripts": {
64
54
  "build": "vite build",
55
+ "build:copy": "vite build && cp -r dist/*.js '../congress.system/public/libs/vue.v3/' && cp -r dist/*.js '../wordpress.plugins/wp-q-components/assets/js/vue.v3/' && cp -r dist/*.css '../congress.system/public/userfile/shared/css/vue.v3/' && cp -r dist/*.css '../wordpress.plugins/wp-q-components/assets/css/vue.v3/'",
56
+ "build:wordpress": "vite build && cp -r dist/* '../wordpress.plugins/wp-q-components/assets/js/'",
65
57
  "build:storybook": "storybook build -c .storybook -o storybook",
66
58
  "storybook": "storybook dev -p 6017",
67
- "test:playground": "NODE_ENV=test mocha --no-timeouts 'lib/test.setup.js' 'lib/**/*.spec.js'",
68
- "test:selenium": "NODE_ENV=test mocha --no-timeouts 'test/selenium/test.setup.js' 'test/selenium/**/*.spec.js'"
59
+ "test:playground": "cross-env NODE_ENV=test mocha --no-timeouts 'lib/test.setup.js' 'lib/**/*.spec.js'",
60
+ "test:selenium": "cross-env NODE_ENV=test mocha --no-timeouts 'test/selenium/test.setup.js' 'test/selenium/**/*.spec.js'"
69
61
  }
70
62
  }
package/vite.config.js CHANGED
@@ -1,19 +1,13 @@
1
- import { fileURLToPath, URL } from 'node:url'
2
1
  import { defineConfig } from 'vite'
3
- import { libInjectCss } from 'vite-plugin-lib-inject-css'
4
2
  import vue from '@vitejs/plugin-vue'
5
3
  import license from 'rollup-plugin-license'
6
4
  import commonjs from 'vite-plugin-commonjs'
7
- import rewriteUmdPlugin from 'rollup-webpack-umd'
8
5
 
9
- // 与 ./webpack/prod.config.js 的 output.library 名一致
10
6
  const libName = 'QList'
11
- // libName 的 kebab-case 格式
12
7
  const fileName = 'q-list'
13
8
 
14
9
  export default defineConfig({
15
10
  build: {
16
- target: ['chrome100', 'safari15', 'firefox91'],
17
11
  lib: {
18
12
  entry: './src/index.js',
19
13
  name: libName,
@@ -23,6 +17,7 @@ export default defineConfig({
23
17
  rollupOptions: {
24
18
  external: ['vue'],
25
19
  output: {
20
+ assetFileNames: `${fileName}.min.[ext]`,
26
21
  globals: {
27
22
  vue: 'Vue',
28
23
  },
@@ -39,20 +34,19 @@ export default defineConfig({
39
34
  }),
40
35
  ],
41
36
  },
37
+ target: ['chrome100', 'safari15', 'firefox91'],
38
+ terserOptions: {
39
+ compress: false,
40
+ mangle: false,
41
+ },
42
42
  },
43
43
  esbuild: {
44
44
  legalComments: 'none',
45
45
  },
46
46
  plugins: [
47
47
  vue(),
48
- libInjectCss(),
49
48
  commonjs(),
50
49
  ],
51
- resolve: {
52
- alias: {
53
- '@': fileURLToPath(new URL('./src', import.meta.url)),
54
- },
55
- },
56
50
  css: {
57
51
  preprocessorOptions: {
58
52
  scss: {
@@ -61,3 +55,48 @@ export default defineConfig({
61
55
  },
62
56
  },
63
57
  })
58
+
59
+ function rewriteUmdPlugin(options) {
60
+ const {
61
+ banner
62
+ } = options || {}
63
+ return {
64
+ name: "rewrite-umd",
65
+ generateBundle(_ctx, options2) {
66
+ if (_ctx.format !== "umd") {
67
+ return
68
+ }
69
+ const data = Object.values(options2)[0]
70
+ const { code, exports, imports } = data
71
+ const defineReg = /^\(function\((?<root>\w+),(?<factory>\w+)\)\{(?<rest>.*?)\|\|self,(?<scriptTag>.*?)\)\}\)\(this,function/s
72
+ const rewritten = code
73
+ .replace(defineReg, (...args) => {
74
+ const { root, factory, scriptTag } = args.at(-1)
75
+ return `${banner || ""}
76
+ ;(function(${root},${factory}){
77
+ if (typeof exports == "object" && typeof module < "u") { // for commonjs
78
+ const returns = {}
79
+ ${factory}(returns, ${imports.map((i) => `require("${i}")`).join(", ")});
80
+ module.exports = returns;
81
+ ${exports.map((exp) => `exports.${exp} = returns.${exp};`).join("\n")}
82
+ }
83
+ else if (typeof define == "function" && define.amd) { // for amd
84
+ define(["exports", ${imports.map((i) => `"${i}"`).join(", ")}], ${factory});
85
+ }
86
+ else { // for browser script tag
87
+ ${root} = (typeof globalThis < "u") ? globalThis : ${root} || self;
88
+ ${scriptTag};
89
+ }
90
+ })(this,function`
91
+ })
92
+
93
+ // return the exports object at the end
94
+ .replace(new RegExp(/Object.defineProperty\((?<name>\w+),Symbol.toStringTag,{value:"Module"}\)}\);/), (...args) => {
95
+ const { name } = args.at(-1)
96
+ return `Object.defineProperty(${name},Symbol.toStringTag,{value:"Module"}); return ${name}; });`
97
+ })
98
+
99
+ data.code = rewritten
100
+ }
101
+ }
102
+ }
@@ -1,6 +0,0 @@
1
- const qListButtonFactory = require('./qListButtonFactory')
2
-
3
- module.exports = {
4
- ...qListButtonFactory,
5
- }
6
- exports.QListButtonFactory = qListButtonFactory.QListButtonFactory
@@ -1,5 +0,0 @@
1
- const { QListButtonFactory } = require('./qListButtonFactory')
2
-
3
- module.exports = {
4
- QListButtonFactory
5
- }
@@ -1,16 +0,0 @@
1
- // const { QListButton } = require('../../models')
2
-
3
- // class QListButtonFactory {
4
- // static init(options) {
5
- // const { action, qRow, row } = options
6
- // if (action.qListButtonType) {
7
- // return new QListButton(action)
8
- // }
9
- // return action
10
- // }
11
- // }
12
-
13
- // module.exports = {
14
- // QListButtonFactory
15
- // }
16
-