@live-change/image-frontend 0.2.7 → 0.2.8

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.
@@ -22,7 +22,7 @@
22
22
  </div>
23
23
  </div>
24
24
  </div>
25
- <div v-else>
25
+ <div v-else-if="state == 'upload'">
26
26
  <DropZone class="w-full relative p-6 md:p-8 lg:p-8" :accept="acceptList" @input="handleFile">
27
27
  <div class="w-auto border-dashed border-primary-500 flex align-items-center justify-content-center"
28
28
  :style="`aspect-ratio: ${aspectRatio}`">
@@ -37,6 +37,9 @@
37
37
  </div>
38
38
  </div>
39
39
  </div>
40
+ <div v-else>
41
+ <ProgressSpinner />
42
+ </div>
40
43
  </template>
41
44
 
42
45
  <script setup>
@@ -49,6 +52,7 @@
49
52
  import { FileInput, DropZone } from '@live-change/upload-frontend'
50
53
  import { uploadImage } from "./imageUploads.js"
51
54
  import Button from "primevue/button"
55
+ import ProgressSpinner from "primevue/progressspinner"
52
56
 
53
57
  import ImageCrop from "./ImageCrop.vue"
54
58
 
@@ -146,6 +150,7 @@
146
150
  const { crop, canvas } = await imageCrop.value.crop()
147
151
  console.log("CROP RESULT", crop, canvas)
148
152
 
153
+ state.value = 'uploading'
149
154
  upload.value = uploadImage(props.purpose, { canvas },
150
155
  { preparedPreview: true, appContext, generateId : true, crop, })
151
156
  console.log("START PREPARE!")
@@ -163,6 +168,7 @@
163
168
  sourceUpload.value = uploadImage(props.purpose, { file },
164
169
  { preparedPreview: true, appContext, generateId : true, saveCanvas: true })
165
170
  console.log("START PREPARE!")
171
+ state.value = 'uploading'
166
172
  await sourceUpload.value.prepare()
167
173
  cropReady.value = false
168
174
  sourceImage.value = sourceUpload.value.id
@@ -0,0 +1,123 @@
1
+ <template>
2
+ <div>
3
+ <div v-if="modelValue">
4
+ <Image :image="modelValue" :key="modelValue"
5
+ :width="definition?.width ?? 400" :height="definition?.height ?? 400"
6
+ style="max-width: 100%" />
7
+ <div class="p-buttonset">
8
+ <Button @click="cropImage" type="button" label="Crop Image"
9
+ icon="pi pi-pencil" class="p-button-secondary" />
10
+ <Button @click="deleteImage" type="button" label="Remove Image"
11
+ icon="pi pi-trash" class="p-button-danger" />
12
+ </div>
13
+ </div>
14
+ <div v-else>
15
+ <DropZone class="w-full md:w-4 lg:w-1 relative p-2" :accept="acceptList" @input="handleFile">
16
+ <div class="w-auto border-dashed border-primary-500 flex align-items-center justify-content-center p-2"
17
+ :style="dropZoneStyle">
18
+ <p class="text-primary text-xl">Drop image here!</p>
19
+ </div>
20
+ </DropZone>
21
+ <FileInput :accept="acceptList" @input="handleFile" class="block">
22
+ <Button type="button" label="Upload Image" icon="pi pi-upload" class="p-button-primary" />
23
+ </FileInput>
24
+ </div>
25
+
26
+ <Dialog v-model:visible="editorVisible" header="Crop Image">
27
+ <ImageEditor :modelValue="modelValue" @update:modelValue="updateImage"
28
+ :width="definition?.width ?? 400" :height="definition?.height ?? 400"
29
+ :uploadedFile="uploadedFile" :purpose="definition?.purpose"
30
+ @close="closeEditor" />
31
+ </Dialog>
32
+ </div>
33
+ </template>
34
+
35
+ <script setup>
36
+ import { FileInput, DropZone } from '@live-change/upload-frontend'
37
+ import Button from "primevue/button"
38
+ import Dialog from "primevue/dialog"
39
+ import Image from "./Image.vue"
40
+ import ImageEditor from "./ImageEditor.vue"
41
+
42
+ const props = defineProps({
43
+ modelValue: { // image
44
+ type: String,
45
+ default: null
46
+ },
47
+ definition: {
48
+ type: Object,
49
+ default: () => {}
50
+ }
51
+ })
52
+ const emit = defineEmits(['update:modelValue'])
53
+
54
+ import { computed, ref } from 'vue'
55
+ import { toRefs } from '@vueuse/core'
56
+
57
+ const { modelValue, definition } = toRefs(props)
58
+
59
+ const acceptList = 'image/jpeg, image/png, image/webp, .jpg, .png, .jpeg, .webp'
60
+ const aspectRatio = computed(() => {
61
+ if(definition.value?.aspectRatio) {
62
+ return definition.value.aspectRatio
63
+ } else if(definition.value?.width && definition?.value.height) {
64
+ return definition.value.width / definition.value.height
65
+ } else {
66
+ return 1
67
+ }
68
+ })
69
+
70
+ const dropZoneStyle = computed(() => ({
71
+ 'aspect-ratio': `${aspectRatio.value}`,
72
+ 'max-width': `${definition.value?.width ?? 250}px`,
73
+ 'max-height': `${definition.value?.height ?? 250}px`
74
+ }))
75
+
76
+ import { useToast } from 'primevue/usetoast'
77
+ const toast = useToast()
78
+ import { useConfirm } from 'primevue/useconfirm'
79
+ const confirm = useConfirm()
80
+
81
+ const editorVisible = ref(false)
82
+ const uploadedFile = ref(null)
83
+
84
+ function handleFile(file) {
85
+ console.log("HANDLE FILE", file)
86
+ if(file) {
87
+ uploadedFile.value = file
88
+ editorVisible.value = true
89
+ }
90
+ }
91
+ function updateImage(value) {
92
+ emit('update:modelValue', value)
93
+ }
94
+ function closeEditor() {
95
+ editorVisible.value = false
96
+ uploadedFile.value = null
97
+ }
98
+ function cropImage() {
99
+ uploadedFile.value = null
100
+ editorVisible.value = true
101
+ }
102
+ function deleteImage() {
103
+ console.log("CONFIRM", confirm)
104
+ confirm.require({
105
+ target: event.currentTarget,
106
+ message: `Are you sure you want to delete this image?`,
107
+ icon: 'pi pi-info-circle',
108
+ acceptClass: 'p-button-danger',
109
+ accept: async () => {
110
+ emit('update:modelValue', null)
111
+ toast.add({ severity: 'info', summary: 'Image removed', life: 1500 })
112
+ },
113
+ reject: () => {
114
+ toast.add({ severity:'error', summary: 'Rejected', detail: 'You have rejected', life: 3000 })
115
+ }
116
+ })
117
+ }
118
+
119
+ </script>
120
+
121
+ <style scoped>
122
+
123
+ </style>
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <div class="w-full card">
3
+ <ImageInput v-model="image" />
4
+ </div>
5
+ <p>{{ image ?? 'none'}}</p>
6
+ </template>
7
+
8
+ <script setup>
9
+
10
+ import ImageInput from "./ImageInput.vue";
11
+
12
+ import { ref } from 'vue'
13
+
14
+ const image = ref()
15
+
16
+ </script>
17
+
18
+ <style scoped>
19
+
20
+ </style>
@@ -21,6 +21,12 @@ export function wysiwygRoutes(config = {}) {
21
21
  props: {
22
22
  }
23
23
  }),
24
+ route({
25
+ name: 'input:test', path: prefix + 'input', meta: { },
26
+ component: () => import("./InputTest.vue"),
27
+ props: {
28
+ }
29
+ }),
24
30
 
25
31
  ...dbAdminRoutes({ prefix: '/_db', route: r => ({ ...r, meta: { ...r.meta, raw: true }}) })
26
32
  ]
package/index.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import ImageUpload from "./front/src/ImageUpload.js"
2
2
  import ImageEditor from "./front/src/ImageEditor.vue"
3
+ import ImageInput from "./front/src/ImageInput.vue"
3
4
  import Image from "./front/src/Image.vue"
4
5
  import {uploadImage, imageUploads} from "./front/src/imageUploads.js";
5
6
  import preProcessImageFile from "./front/src/preprocessImageFile.js";
6
7
 
7
- export { ImageUpload, Image, uploadImage, preProcessImageFile, imageUploads, ImageEditor }
8
+ export { ImageUpload, Image, uploadImage, preProcessImageFile, imageUploads, ImageEditor, ImageInput }
9
+
10
+ import { inputConfig } from "@live-change/frontend-auto-form"
11
+ inputConfig.types.Image = inputConfig.inputs.image = inputConfig.input(
12
+ () => import('./front/src/ImageInput.vue'))
13
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/image-frontend",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "scripts": {
5
5
  "memDev": "lcli memDev --enableSessions --initScript ./init.js --dbAccess",
6
6
  "localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
@@ -28,8 +28,8 @@
28
28
  "@live-change/framework": "0.7.4",
29
29
  "@live-change/image-service": "0.3.2",
30
30
  "@live-change/session-service": "0.3.2",
31
- "@live-change/vue3-components": "0.2.15",
32
- "@live-change/vue3-ssr": "0.2.15",
31
+ "@live-change/vue3-components": "0.2.16",
32
+ "@live-change/vue3-ssr": "0.2.16",
33
33
  "@tiptap/extension-highlight": "^2.0.0-beta.33",
34
34
  "@tiptap/extension-underline": "2.0.0-beta.23",
35
35
  "@tiptap/starter-kit": "^2.0.0-beta.185",
@@ -66,5 +66,5 @@
66
66
  "author": "",
67
67
  "license": "BSD-3-Clause",
68
68
  "description": "",
69
- "gitHead": "ef577fb31dd857acb491bd7114e611638283fe6f"
69
+ "gitHead": "72bd46680370e7804b168fec5dde28de205487e0"
70
70
  }