Skip to content

Commit 48f7f8a

Browse files
authoredJun 17, 2021
Add bundled version (#384)
1 parent 1e46b5c commit 48f7f8a

12 files changed

+495
-1459
lines changed
 

‎.release-it.json

-19
This file was deleted.

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ issues](https://img.shields.io/github/issues/grid-js/gridjs-vue?color=41B883&sty
1818
npm install gridjs-vue
1919
```
2020

21-
Also available on [unpkg](https://unpkg.com/browse/gridjs-vue@5.0.1/dist/) and [Skypack](https://www.skypack.dev/view/gridjs-vue)!
21+
Also available on [unpkg](https://unpkg.com/browse/gridjs-vue/dist/) and [Skypack](https://www.skypack.dev/view/gridjs-vue)!
2222

2323
```html
2424
<script>
25-
import Grid from 'gridjs-vue'
25+
import { Grid } from 'gridjs-vue'
2626
2727
export default {
2828
components: {

‎bili.config.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
22
jsCompiler: 'babel',
3-
input: 'src/index.js',
3+
input: ['src/index.browser.mjs', 'src/index.mjs'],
4+
bundleNodeModules: true,
45
output: {
56
format: ['cjs', 'esm', 'umd'],
6-
bundleNodeModules: true,
77
minify: true,
88
moduleName: 'Grid',
99
extractCSS: false
@@ -13,15 +13,12 @@ module.exports = {
1313
include: 'node_modules/**/*.css'
1414
},
1515
vue: {
16-
target: 'browser',
17-
babelHelopers: 'runtime',
18-
css: true
16+
target: 'browser'
1917
},
2018
babel: {
2119
presets: ['vue', ['@babel/preset-env', { useBuiltIns: 'usage', corejs: 3 }]],
2220
plugins: ['@babel/plugin-transform-runtime'],
2321
babelHelpers: 'runtime',
24-
exclude: 'node_modules/**',
2522
configFile: false
2623
},
2724
'node-resolve': true

‎examples/basic/hello-world.mjs

+19-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ export default {
77
},
88
data() {
99
return {
10-
columns: ['Name', 'Email', 'Phone Number'],
10+
sort: true,
11+
columns: [
12+
'Name',
13+
'Email',
14+
{
15+
name: 'Phone Number',
16+
sort: {
17+
compare: (a, b) => {
18+
a = parseInt(a.replace(/\(|\)|\s/g, ''))
19+
b = parseInt(b.replace(/\(|\)|\s/g, ''))
20+
let out = 0
21+
if (a > b) out = 1
22+
if (a < b) out = -1
23+
return out
24+
}
25+
}
26+
}
27+
],
1128
rows: [
1229
['John', 'john@example.com', '(353) 01 222 3333'],
1330
['Mark', 'mark@gmail.com', '(01) 22 888 4444']
@@ -20,6 +37,6 @@ export default {
2037
}
2138
},
2239
template: `
23-
<div><grid :columns="columns" :rows="rows" @ready="log('Hi to you too!')"></grid></div>
40+
<div><grid :columns="columns" :rows="rows" ref="helloWorld" @ready="log('Hi to you too!')"></grid></div>
2441
`
2542
}

‎examples/basic/loading-state.mjs

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ export default {
1010
columns: ['Name', 'Email', 'Phone Number'],
1111
sort: true,
1212
search: true,
13-
rows:() => {
13+
rows: () => {
1414
return new Promise(resolve => {
15-
setTimeout(() =>
16-
resolve([
17-
['John', 'john@example.com', '(353) 01 222 3333'],
18-
['Mark', 'mark@gmail.com', '(01) 22 888 4444']
19-
]), 2000);
15+
setTimeout(
16+
() =>
17+
resolve([
18+
['John', 'john@example.com', '(353) 01 222 3333'],
19+
['Mark', 'mark@gmail.com', '(01) 22 888 4444']
20+
]),
21+
2000
22+
)
2023
})
2124
}
2225
}

‎examples/customizing/vue-component-in-cells.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default {
1313
{
1414
name: 'Name',
1515
formatter: cell =>
16-
return this.$gridjs.helper({
16+
this.$gridjs.helper({
1717
components: { TestComponent },
1818
template: `<test-component :content="content"></test-component>`,
1919
data() {

‎package.json

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gridjs-vue",
33
"description": "A Vue.js wrapper component for Grid.js",
4-
"version": "5.0.2-0",
4+
"version": "5.0.2-3",
55
"license": "MIT",
66
"private": false,
77
"authors": [
@@ -14,13 +14,25 @@
1414
"type": "git",
1515
"url": "https://github.com/grid-js/gridjs-vue.git"
1616
},
17-
"main": "./dist/index.js",
17+
"keywords": [
18+
"table",
19+
"grid",
20+
"spreadsheet",
21+
"vue",
22+
"vue-component"
23+
],
24+
"main": "./dist/index.esm.js",
1825
"umd": "./dist/index.umd.js",
19-
"module": "./dist/index.esm.js",
26+
"module": "./dist/index.browser.esm.js",
27+
"exports": {
28+
"require": "./dist/index.js",
29+
"import": "./dist/index.esm.js",
30+
"default": "./dist/index.esm.js",
31+
"browser": "./dist/index.browser.esm.js"
32+
},
2033
"scripts": {
2134
"dev": "baechli -c 'yarn build'",
22-
"build": "rm -rf dist/*; bili src/index.mjs;",
23-
"release": "doppler run -- release-it"
35+
"build": "rm -rf dist/*; bili;"
2436
},
2537
"files": [
2638
"dist/*",
@@ -36,6 +48,8 @@
3648
"@babel/core": "^7.14.3",
3749
"@babel/plugin-transform-runtime": "^7.14.3",
3850
"@babel/preset-env": "^7.14.4",
51+
"@juggle/resize-observer": "^3.3.1",
52+
"@lesniewski.pro/necktie": "^1.1.3",
3953
"@release-it/keep-a-changelog": "^2.3.0",
4054
"@vue/compiler-sfc": "^3.1.1",
4155
"@vue/eslint-config-prettier": "^6.0.0",
@@ -51,18 +65,20 @@
5165
"eslint-plugin-import": "^2.23.4",
5266
"eslint-plugin-prettier": "^3.4.0",
5367
"eslint-plugin-vue": "^7.10.0",
68+
"gridjs": "5.0.1",
69+
"parse-css-stylesheet": "^0.0.1",
5470
"prettier": "^2.3.1",
55-
"release-it": "^14.8.0",
5671
"rollup": "^2.51.1",
5772
"rollup-plugin-babel": "^4.4.0",
5873
"rollup-plugin-commonjs": "^10.1.0",
5974
"rollup-plugin-node-resolve": "^5.2.0",
6075
"rollup-plugin-string": "^3.0.0",
6176
"rollup-plugin-vue": "^6.0.0",
77+
"styl-injector": "^1.4.0",
6278
"typescript": "^4.3.2",
79+
"uid": "^2.0.0",
6380
"vue": "^2.6.11",
6481
"vue-runtime-helpers": "1.1.2",
6582
"vue-template-compiler": "^2.6.14"
66-
},
67-
"dependencies": {}
83+
}
6884
}

‎src/gridjs-vue.browser.mjs

+270
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
import { ResizeObserver as Polyfill } from 'https://cdn.skypack.dev/@juggle/resize-observer'
2+
import parseStylesheet from 'https://cdn.skypack.dev/parse-css-stylesheet'
3+
import { injectStyle } from 'https://cdn.skypack.dev/styl-injector'
4+
import { uid } from 'https://cdn.skypack.dev/uid'
5+
import { Grid } from 'https://unpkg.com/gridjs@5.0.1/dist/gridjs.module.js'
6+
7+
const waitForSelector = selector => {
8+
const element = document.querySelector(selector)
9+
if (element) return element
10+
11+
const mutObserver = new MutationObserver(mutations => {
12+
for (const mutation of mutations) {
13+
const nodes = Array.from(mutation.addedNodes)
14+
for (const node of nodes) {
15+
if (node.matches && node.matches(selector)) {
16+
mutObserver.disconnect()
17+
return node
18+
}
19+
}
20+
}
21+
})
22+
23+
mutObserver.observe(document.documentElement, { childList: true, subtree: true })
24+
}
25+
26+
export default {
27+
name: 'Grid',
28+
props: {
29+
autoWidth: {
30+
type: Boolean,
31+
default: true
32+
},
33+
className: {
34+
type: Object,
35+
default: undefined
36+
},
37+
columns: {
38+
type: [Array, Function],
39+
default: undefined
40+
},
41+
fixedHeader: {
42+
type: Boolean,
43+
default: false
44+
},
45+
from: {
46+
type: [String, Function],
47+
default: undefined
48+
},
49+
height: {
50+
type: String,
51+
default: undefined
52+
},
53+
language: {
54+
type: Object,
55+
default: undefined
56+
},
57+
pagination: {
58+
type: [Object, Boolean],
59+
default: false
60+
},
61+
resizable: {
62+
type: Boolean,
63+
default: false
64+
},
65+
rows: {
66+
type: [Array, Function],
67+
default: undefined
68+
},
69+
search: {
70+
type: [Object, Boolean],
71+
default: false
72+
},
73+
server: {
74+
type: [Object, Function],
75+
default: undefined
76+
},
77+
sort: {
78+
type: [Object, Boolean],
79+
default: false
80+
},
81+
styles: {
82+
type: Object,
83+
default: undefined
84+
},
85+
theme: {
86+
type: String,
87+
default: undefined
88+
},
89+
width: {
90+
type: String,
91+
default: '100%'
92+
}
93+
},
94+
data() {
95+
return {
96+
grid: null,
97+
resize: null,
98+
uuid: null,
99+
wrapper: null
100+
}
101+
},
102+
computed: {
103+
options() {
104+
let options = {
105+
autoWidth: this.autoWidth,
106+
fixedHeader: this.fixedHeader,
107+
pagination: this.pagination,
108+
resizable: this.resizable,
109+
sort: this.sort,
110+
width: this.width
111+
}
112+
113+
if (this.columns) options.columns = this.columns
114+
if (this.rows) options.data = this.rows
115+
if (this.className) options.className = this.className
116+
if (this.from)
117+
options.from =
118+
typeof this.from === 'string'
119+
? document.querySelector(this.from)
120+
: document.createRange().createContextualFragment(this.from())
121+
if (this.height) options.height = this.height
122+
if (this.language) options.language = this.language
123+
if (this.search) options.search = this.search
124+
if (this.server) options.server = this.server
125+
if (this.styles) options.style = this.styles
126+
127+
return options
128+
},
129+
activeTheme() {
130+
if (this.theme) return this.theme
131+
if (this.$gridjs.options.theme) return this.$gridjs.options.theme
132+
return 'mermaid'
133+
},
134+
divId() {
135+
return `gridjs__${this.uuid}`
136+
}
137+
},
138+
watch: {
139+
autoWidth() {
140+
this.update()
141+
},
142+
className() {
143+
this.update()
144+
},
145+
columns() {
146+
this.update()
147+
},
148+
fixedHeader() {
149+
this.update()
150+
},
151+
from() {
152+
this.update()
153+
},
154+
height() {
155+
this.update()
156+
},
157+
language() {
158+
this.update()
159+
},
160+
pagination() {
161+
this.update()
162+
},
163+
resizable() {
164+
this.update()
165+
},
166+
rows() {
167+
this.update()
168+
},
169+
search() {
170+
this.update()
171+
},
172+
server() {
173+
this.update()
174+
},
175+
sort() {
176+
this.update()
177+
},
178+
style() {
179+
this.update()
180+
},
181+
theme() {
182+
this.update()
183+
},
184+
width() {
185+
this.update()
186+
}
187+
},
188+
async created() {
189+
try {
190+
// give table a unique id
191+
this.uuid = uid(16)
192+
193+
// get the wrapper
194+
await waitForSelector(this.divId)
195+
this.wrapper = document.getElementById(this.divId)
196+
197+
// instantiate grid.js
198+
if (Object.keys(this.$gridjs.options).length) this.setOptions()
199+
if (this.wrapper && (this.options.data || this.options.from || this.options.server)) {
200+
this.grid = new Grid(this.options).render(this.wrapper)
201+
}
202+
} catch (error) {
203+
console.error(error)
204+
}
205+
},
206+
mounted() {
207+
this.assignTheme()
208+
const ResizeObserver = window.ResizeObserver || Polyfill
209+
this.resize = new ResizeObserver(() => {
210+
this.rerender()
211+
})
212+
this.resize.observe(this.$refs[this.uuid])
213+
this.$nextTick(() => this.$emit('ready'))
214+
},
215+
destroyed() {
216+
// unload from memory
217+
this.resize.disconnect()
218+
this.grid = undefined
219+
this.wrapper = undefined
220+
},
221+
methods: {
222+
async assignTheme() {
223+
try {
224+
if (this.activeTheme !== 'none') {
225+
let theme,
226+
stylesheet = ''
227+
228+
theme = await (await fetch(`https://unpkg.com/gridjs/dist/theme/${this.activeTheme}.css`)).text()
229+
theme = parseStylesheet(theme)
230+
231+
for (const index in theme.cssRules) {
232+
let css = theme.cssRules[index].cssText
233+
if (css && !/^@/g.test(css)) {
234+
stylesheet = `${stylesheet}\n\n#${this.divId} ${css}`
235+
}
236+
}
237+
238+
injectStyle(stylesheet, `${this.divId}__theme`)
239+
}
240+
} catch (error) {
241+
console.error(error)
242+
}
243+
},
244+
setOptions() {
245+
try {
246+
const plugins = this.$gridjs.options.plugins
247+
if (plugins) {
248+
plugins.forEach(plugin => {
249+
this.grid.plugin.add(plugin)
250+
})
251+
}
252+
} catch (error) {
253+
console.error(error)
254+
}
255+
},
256+
rerender() {
257+
if (this.grid) this.grid.forceRender()
258+
},
259+
update() {
260+
try {
261+
if (this.grid) this.grid.updateConfig(this.options).forceRender()
262+
} catch (error) {
263+
console.error(error)
264+
}
265+
}
266+
},
267+
template: `
268+
<article :id="divId" :data-uuid="uuid" :ref="uuid"></article>
269+
`
270+
}

‎src/gridjs-vue.mjs

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import parseStylesheet from 'https://cdn.skypack.dev/parse-css-stylesheet'
2-
import { injectStyle } from 'https://cdn.skypack.dev/styl-injector'
3-
import { uid } from 'https://cdn.skypack.dev/uid'
4-
import { Grid } from 'https://unpkg.com/gridjs@5.0.1/dist/gridjs.module.js'
1+
import { ResizeObserver as Polyfill } from '@juggle/resize-observer'
2+
import { Grid } from 'gridjs/dist/gridjs.module.js'
3+
import mermaid from 'gridjs/dist/theme/mermaid.css'
4+
import parseStylesheet from 'parse-css-stylesheet'
5+
import { injectStyle } from 'styl-injector'
6+
import { uid } from 'uid'
57

68
const waitForSelector = selector => {
79
const element = document.querySelector(selector)
@@ -204,36 +206,31 @@ export default {
204206
},
205207
mounted() {
206208
this.assignTheme()
207-
this.resize = window.addEventListener('resize', () => this.update(), true)
209+
const ResizeObserver = window.ResizeObserver || Polyfill
210+
this.resize = new ResizeObserver(() => {
211+
this.rerender()
212+
})
213+
this.resize.observe(this.$refs[this.uuid])
208214
this.$nextTick(() => this.$emit('ready'))
209215
},
210216
destroyed() {
211217
// unload from memory
218+
this.resize.disconnect()
212219
this.grid = undefined
213220
this.wrapper = undefined
214-
window.removeEventListener(this.resize)
215221
},
216222
methods: {
217223
async assignTheme() {
218224
try {
219225
if (this.activeTheme !== 'none') {
220-
const head = document.getElementsByTagName('head')[0]
226+
let theme,
227+
stylesheet = ''
221228

222-
let styles = document.createElement('style')
223-
styles.title = `${this.divId}__theme`
224-
styles.type = 'text/css'
225-
head.appendChild(styles)
226-
227-
let theme = await fetch(`https://unpkg.com/gridjs/dist/theme/${this.activeTheme}.css`)
228-
theme = parseStylesheet(await theme.text())
229-
230-
for (let index in document.styleSheets) {
231-
if (document.styleSheets[index].title === styles.title) {
232-
styles = document.styleSheets[index]
233-
}
234-
}
235-
236-
let stylesheet = ''
229+
theme = parseStylesheet(
230+
this.activeTheme === 'mermaid'
231+
? mermaid.match(/= "(.*?)";/)[1].replace(/\\n/g, '')
232+
: await (await fetch(`https://unpkg.com/gridjs/dist/theme/${this.activeTheme}.css`)).text()
233+
)
237234

238235
for (const index in theme.cssRules) {
239236
let css = theme.cssRules[index].cssText
@@ -242,7 +239,7 @@ export default {
242239
}
243240
}
244241

245-
injectStyle(stylesheet, `${this.divId}_styles`)
242+
injectStyle(stylesheet, `${this.divId}__theme`)
246243
}
247244
} catch (error) {
248245
console.error(error)
@@ -260,6 +257,9 @@ export default {
260257
console.error(error)
261258
}
262259
},
260+
rerender() {
261+
if (this.grid) this.grid.forceRender()
262+
},
263263
update() {
264264
try {
265265
if (this.grid) this.grid.updateConfig(this.options).forceRender()
@@ -269,6 +269,6 @@ export default {
269269
}
270270
},
271271
template: `
272-
<article :id="divId" :data-uuid="uuid"></article>
272+
<article :id="divId" :data-uuid="uuid" :ref="uuid"></article>
273273
`
274274
}

‎src/index.browser.mjs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Necktie } from 'https://cdn.skypack.dev/@lesniewski.pro/necktie'
2+
import { uid } from 'https://cdn.skypack.dev/uid'
3+
import { h, html, PluginPosition } from 'https://unpkg.com/gridjs@5.0.1/dist/gridjs.module.js'
4+
import Grid from './gridjs-vue.browser.mjs'
5+
6+
export function install(Vue, options = {}) {
7+
if (install.installed) return
8+
install.installed = true
9+
10+
const helper = vueConfig => {
11+
const uuid = uid(16)
12+
const tie = new Necktie()
13+
tie.startListening()
14+
15+
tie.bind(
16+
`[data-obj-id='${uuid}']`,
17+
el =>
18+
new Vue({
19+
el,
20+
...vueConfig
21+
})
22+
)
23+
24+
return html(`<span data-obj-id=${uuid}></span>`)
25+
}
26+
27+
if (!Vue.prototype.$gridjs) {
28+
Vue.prototype.$gridjs = {
29+
h,
30+
helper,
31+
html,
32+
options,
33+
PluginPosition
34+
}
35+
}
36+
37+
Vue.component('Grid', Grid)
38+
}
39+
40+
const plugin = {
41+
install
42+
}
43+
44+
let GlobalVue = null
45+
46+
if (typeof window !== 'undefined') {
47+
GlobalVue = window.Vue
48+
} else if (typeof global !== 'undefined') {
49+
GlobalVue = global.Vue
50+
}
51+
52+
if (GlobalVue) {
53+
GlobalVue.use(plugin)
54+
}
55+
56+
export { Grid, plugin as GridGlobal }
57+
export default Grid

‎src/index.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Necktie } from 'https://cdn.skypack.dev/@lesniewski.pro/necktie'
2-
import { uid } from 'https://cdn.skypack.dev/uid'
3-
import { h, html, PluginPosition } from 'https://unpkg.com/gridjs@5.0.1/dist/gridjs.module.js'
1+
import { Necktie } from '@lesniewski.pro/necktie'
2+
import { h, html, PluginPosition } from 'gridjs/dist/gridjs.module.js'
3+
import { uid } from 'uid'
44
import Grid from './gridjs-vue.mjs'
55

66
export function install(Vue, options = {}) {

‎yarn.lock

+83-1,388
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.