@lemonadejs/cropper 5.1.0 → 6.0.0

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.
Files changed (3) hide show
  1. package/README.md +13 -12
  2. package/dist/index.js +45 -29
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -214,13 +214,13 @@ const responsiveCropper = Cropper(document.getElementById('mobile-editor'), {
214
214
 
215
215
  ### Options
216
216
 
217
- | Property | Type | Default | Description |
218
- |------------|-------------|-----------|----------------------------------------|
219
- | `width` | number | 300 | Width of the crop area in pixels |
220
- | `height` | number | 240 | Height of the crop area in pixels |
221
- | `original` | boolean | false | Whether to preserve the original image |
222
- | `name` | string | undefined | Name attribute for form integration |
223
- | `value` | ImageData[] | null | Initial image data |
217
+ | Property | Type | Default | Description |
218
+ |------------|-----------|-----------|----------------------------------------|
219
+ | `width` | number | 300 | Width of the crop area in pixels |
220
+ | `height` | number | 240 | Height of the crop area in pixels |
221
+ | `original` | boolean | false | Whether to preserve the original image |
222
+ | `name` | string | undefined | Name attribute for form integration |
223
+ | `value` | ImageData | null | Initial image data |
224
224
 
225
225
  ### Methods
226
226
 
@@ -229,10 +229,10 @@ Retrieve the current cropped image data and metadata.
229
229
 
230
230
  ```javascript
231
231
  const data = cropper.getValue();
232
- // Returns: [{ file: 'blob:...', content: 'data:image/...', extension: 'png' }]
232
+ // Returns: { file: 'blob:...', content: 'data:image/...', extension: 'png' }
233
233
  ```
234
234
 
235
- **Returns:** `ImageData[]` - Array containing image data with file URL, content, and extension
235
+ **Returns:** `ImageData` - Object containing image data with file URL, content, and extension
236
236
 
237
237
  #### setValue(data)
238
238
  Set or update the image in the cropper.
@@ -252,7 +252,7 @@ cropper.setValue(null);
252
252
  ```
253
253
 
254
254
  **Parameters:**
255
- - `data` (string | ImageData | ImageData[] | null): Image URL, data object, array of data objects, or null to clear
255
+ - `data` (string | ImageData | null): Image URL, data object, array of data objects, or null to clear
256
256
 
257
257
  #### open()
258
258
  Programmatically open the cropper modal interface.
@@ -307,15 +307,16 @@ interface ImageData {
307
307
  content?: string; // Base64 or data URL content
308
308
  extension?: string; // File extension (e.g., 'jpg', 'png')
309
309
  original?: string; // Original image URL (if preserved)
310
+ guid?: string;
310
311
  }
311
312
  ```
312
313
 
313
314
  ## Related Projects
314
315
 
315
316
  - **[LemonadeJS](https://lemonadejs.com)** - Reactive micro JavaScript library
317
+ - **[Jspreadsheet](https://jspreadsheet.com)** - JavaScript data grid and spreadsheet component
318
+ - **[CalendarJS](https://calendarjs.com)** - JavaScript calendar, schedule and timeline components
316
319
  - **[jSuites](https://jsuites.net)** - JavaScript plugins and web components collection
317
- - **[jSpreadsheet](https://jspreadsheet.com)** - JavaScript data grid and spreadsheet component
318
-
319
320
 
320
321
  ## License
321
322
 
package/dist/index.js CHANGED
@@ -123,7 +123,6 @@ if (typeof(cropper) === 'undefined') {
123
123
  const updatePhoto = () => {
124
124
  // Checks if cropper container is editable
125
125
  if (self.cropperArea.classList.contains('jcrop_edition')) {
126
- self.image.innerHTML = '';
127
126
  // Create image with metadata
128
127
  const newImage = crop.getCroppedImage();
129
128
  // Callback for the blob
@@ -140,16 +139,8 @@ if (typeof(cropper) === 'undefined') {
140
139
  if (original === true) {
141
140
  data.original = crop.getImage().src;
142
141
  }
143
- // Update file to blob
144
- newImage.src = filename;
145
- // Integration with
146
- if (self.name) {
147
- newImage.classList.remove('jfile');
148
- }
149
142
  // Value
150
- self.value = [data];
151
- // Append new image
152
- self.image.appendChild(newImage);
143
+ self.value = data;
153
144
  }
154
145
  // Create image
155
146
  crop.getCroppedAsBlob(createImage);
@@ -170,8 +161,6 @@ if (typeof(cropper) === 'undefined') {
170
161
  crop.reset();
171
162
  // Disable controls
172
163
  self.setControls(false);
173
- // Reset from container
174
- self.image.innerHTML = '';
175
164
  // Reset container
176
165
  self.value = '';
177
166
  }
@@ -211,19 +200,11 @@ if (typeof(cropper) === 'undefined') {
211
200
  }
212
201
  }
213
202
 
214
- if (data.file) {
215
- const img = document.createElement('img');
216
- img.setAttribute('src', data.file);
217
- img.setAttribute('tabindex', -1);
218
- self.image.innerHTML = '';
219
- self.image.appendChild(img);
220
- }
221
-
222
203
  if (data.original) {
223
204
  crop.addFromFile(data.original);
224
205
  }
225
206
 
226
- self.value = [data];
207
+ self.value = data;
227
208
  }
228
209
  }
229
210
 
@@ -273,12 +254,47 @@ if (typeof(cropper) === 'undefined') {
273
254
  }
274
255
  });
275
256
 
257
+ onchange((prop) => {
258
+ let image = self.value;
259
+ let filename = null;
260
+
261
+ if (Array.isArray(self.value)) {
262
+ image = self.value[0];
263
+ }
264
+ const img = document.createElement('img');
265
+ img.setAttribute('tabindex', -1);
266
+ self.image.textContent = '';
267
+ // Integration with
268
+ if (self.name) {
269
+ img.classList.remove('jfile');
270
+ }
271
+
272
+ if (image) {
273
+ if (typeof image === 'string') {
274
+ filename = image;
275
+ } else if (typeof image === 'object') {
276
+ filename = image.file;
277
+ }
278
+ }
279
+
280
+ if (filename) {
281
+ if (typeof self.onbeforeloadimage === 'function') {
282
+ let ret = self.onbeforeloadimage(self, filename, img);
283
+ if (ret) {
284
+ filename = ret;
285
+ }
286
+ }
287
+ img.setAttribute('src', filename);
288
+ self.image.appendChild(img);
289
+ }
290
+ })
291
+
276
292
  track('value');
277
293
 
278
294
  // Template
279
295
  return render => render `<div name="{{self.name}}">
280
296
  <div :ref='this.image' class="jphoto jcropper"></div>
281
- <lm-modal draggable="true" closable="true" closed="true" width="800" height="570" title="Photo Upload" icon="photo" :ref="self.modal">
297
+ <lm-modal draggable="true" closable="true" closed="true" width="800" height="580" title="Photo Upload" icon="photo" :ref="self.modal">
282
298
  <div :ready='self.createCropper' :ref='self.cropperArea'></div>
283
299
  <div class="controls">
284
300
  <div style="display: flex; justify-content: center; gap: 10px; text-align: center; border-top: 1px solid #ddd;">
@@ -287,13 +303,13 @@ if (typeof(cropper) === 'undefined') {
287
303
  <label style="padding: 20px;">Brigthness<br><input type='range' min='-1' max='1' step='.05' value='0' :bind='self.brightness' oninput='${setBrightness}' class='jrange controls' disabled='disabled'></label>
288
304
  <label style="padding: 20px;">Contrast<br><input type='range' min='-1' max='1' step='.05' value='0' :bind='self.contrast' oninput='${setContrast}' class='jrange controls' disabled='disabled'></label>
289
305
  </div>
290
- <div class='lm-row lm-p20' style='border-top: 1px solid #ddd'>
291
- <div class='lm-column lm-p6 lm-f1'>
292
- <input type='button' value='Save Photo' class='lm-button controls' style='min-width: 140px;' onclick='${updatePhoto}' disabled='disabled'>
293
- </div><div class='lm-column lm-p6'>
294
- <input type='button' value='Upload Photo' class='lm-button' style='min-width: 140px;' onclick='${uploadPhoto}'>
295
- </div><div class='lm-column lm-p6' style='text-align:right'>
296
- <input type='button' value='Delete Photo' class='lm-button controls' style='min-width: 140px;' onclick='${deletePhoto}' disabled='disabled'>
306
+ <div class='lm-row lm-p15' style='border-top: 1px solid #ddd'>
307
+ <div class='lm-column lm-f1'>
308
+ <input type='button' value='Save Photo' class='lm-button controls' style='width: 100%' onclick='${updatePhoto}' disabled='disabled'>
309
+ </div><div class='lm-column'>
310
+ <input type='button' value='Upload Photo' class='lm-button' style='width: 100%' onclick='${uploadPhoto}'>
311
+ </div><div class='lm-column' style='text-align:right'>
312
+ <input type='button' value='Delete Photo' class='lm-button controls' style='width: 100%' onclick='${deletePhoto}' disabled='disabled'>
297
313
  </div>
298
314
  </div>
299
315
  </div>
package/package.json CHANGED
@@ -14,10 +14,10 @@
14
14
  "javascript plugins"
15
15
  ],
16
16
  "dependencies": {
17
- "lemonadejs": "^5.3.2",
18
- "@lemonadejs/studio": "^5.7.0",
17
+ "lemonadejs": "^5.3.3",
18
+ "@lemonadejs/studio": "^5.7.11",
19
19
  "@jsuites/cropper": "^1.7.0"
20
20
  },
21
21
  "main": "dist/index.js",
22
- "version": "5.1.0"
22
+ "version": "6.0.0"
23
23
  }