mango-cms 0.2.12 → 0.2.14

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.
@@ -7,6 +7,9 @@
7
7
  "preview": "vite preview",
8
8
  "mango": "mango"
9
9
  },
10
+ "resolutions": {
11
+ "strip-ansi": "^6.0.1"
12
+ },
10
13
  "dependencies": {
11
14
  "@headlessui/vue": "^1.6.7",
12
15
  "@mapbox/mapbox-gl-geocoder": "^5.0.0",
@@ -333,6 +333,72 @@ Mango.endpoints = Object.keys(endpoints).reduce((a, c) => {
333
333
 
334
334
  }, {})
335
335
 
336
+ Mango.upload = async (file) => {
337
+
338
+ return new Promise((resolve, reject) => {
339
+ const formData = new FormData()
340
+
341
+ let uploading = true
342
+ let filename = file.name
343
+ let progress = 0
344
+ let url
345
+ let error
346
+
347
+ // // Compress the image
348
+ // if (file.type.includes('image')) {
349
+ // let results = await compress.compress([file], {
350
+ // quality: .75, // the quality of the image, max is 1,
351
+ // maxWidth: 1920, // the max width of the output image, defaults to 1920px
352
+ // maxHeight: 1920, // the max height of the output image, defaults to 1920px
353
+ // resize: true, // defaults to true, set false if you do not want to resize the image width and height
354
+ // rotate: false, // See the rotation section below
355
+ // })
356
+ // const img1 = results[0]
357
+ // const base64str = img1.data
358
+ // const imgExt = img1.ext
359
+ // const filename = file.name
360
+ // file = Compress.convertBase64ToFile(base64str, imgExt)
361
+ // file = new File([file], filename, { type: file.type });
362
+ // console.log('file', file)
363
+ // }
364
+
365
+ formData.append('file', file)
366
+
367
+ const xhr = new XMLHttpRequest()
368
+
369
+ xhr.open('POST', `${api}/upload`, true)
370
+
371
+ xhr.upload.onprogress = (event) => {
372
+ if (event.lengthComputable) {
373
+ progress = (event.loaded / event.total) * 100
374
+ }
375
+ }
376
+
377
+ xhr.onload = () => {
378
+ if (xhr.status === 200) {
379
+ const json = JSON.parse(xhr.response)
380
+ const path = json.paths[0]
381
+ const url = api + path
382
+ uploading = false
383
+ progress = 0
384
+ resolve(url)
385
+ } else {
386
+ error = 'Error while uploading file'
387
+ uploading = false
388
+ reject(error)
389
+ }
390
+ }
391
+
392
+ xhr.onerror = () => {
393
+ error = 'Error while uploading file'
394
+ uploading = false
395
+ reject(error)
396
+ }
397
+
398
+ xhr.send(formData)
399
+ })
400
+ }
401
+
336
402
  Mango.collections = collections
337
403
  Mango.ws = ws
338
404
 
@@ -9,32 +9,49 @@ let configPath = path.resolve(projectRoot, 'mango')
9
9
 
10
10
  // If config doesn't exist in current directory, check parent
11
11
  if (!fs.existsSync(configPath)) {
12
- projectRoot = path.resolve(projectRoot, '..')
13
- configPath = path.resolve(projectRoot, 'mango')
12
+ projectRoot = path.resolve(projectRoot, '..')
13
+ configPath = path.resolve(projectRoot, 'mango')
14
14
 
15
- // If config still doesn't exist, throw error
16
- if (!fs.existsSync(configPath)) {
17
- throw new Error('Mango folder not found. Please ensure your mango folder exists either in the current directory or parent directory.')
18
- }
15
+ // If config still doesn't exist, throw error
16
+ if (!fs.existsSync(configPath)) {
17
+ throw new Error('Mango folder not found. Please ensure your mango folder exists either in the current directory or parent directory.')
18
+ }
19
19
  }
20
20
 
21
+ const collectionsPath = path.resolve(configPath, 'config/.collections.json')
22
+
21
23
  // https://vitejs.dev/config/
22
24
  export default defineConfig({
23
- plugins: [vue()],
24
- server: {
25
- host: '0.0.0.0',
26
- },
27
- resolve: {
28
- alias: {
29
- '@config': configPath,
30
- '@mango': configPath,
31
- '@settings': path.resolve(configPath, 'config/settings.json'),
32
- '@collections': path.resolve(configPath, 'config/.collections.json'),
33
- '@plugins': path.resolve(configPath, 'plugins'),
34
- 'vue': path.resolve(__dirname, 'node_modules/vue'),
35
- }
36
- },
37
- optimizeDeps: {
38
- exclude: ['vue'], // Prevent Vite from optimizing Vue separately
39
- },
25
+ plugins: [
26
+ vue(),
27
+ {
28
+ name: 'watch-collections',
29
+ configureServer(server) {
30
+ server.watcher.add(collectionsPath)
31
+ server.watcher.on('change', (file) => {
32
+ if (file === collectionsPath) {
33
+ server.ws.send({
34
+ type: 'full-reload',
35
+ })
36
+ }
37
+ })
38
+ },
39
+ },
40
+ ],
41
+ server: {
42
+ host: '0.0.0.0',
43
+ },
44
+ resolve: {
45
+ alias: {
46
+ '@config': configPath,
47
+ '@mango': configPath,
48
+ '@settings': path.resolve(configPath, 'config/settings.json'),
49
+ '@collections': path.resolve(configPath, 'config/.collections.json'),
50
+ '@plugins': path.resolve(configPath, 'plugins'),
51
+ vue: path.resolve(__dirname, 'node_modules/vue'),
52
+ },
53
+ },
54
+ optimizeDeps: {
55
+ exclude: ['vue', '@collections'], // Prevent Vite from optimizing Vue separately
56
+ },
40
57
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mango-cms",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "main": "./index.js",
5
5
  "exports": {
6
6
  ".": "./index.js",