@dosgato/dialog 0.0.32 → 0.0.33
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.
package/FieldChooserLink.svelte
CHANGED
|
@@ -46,12 +46,19 @@ function onChange(setVal) {
|
|
|
46
46
|
hide();
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
let timer;
|
|
50
|
+
function userUrlEntry() {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
timer = setTimeout(userUrlEntryDebounced.bind(this), 300);
|
|
53
|
+
}
|
|
54
|
+
async function userUrlEntryDebounced() {
|
|
50
55
|
const url = this.value;
|
|
51
56
|
store.clearPreview();
|
|
52
57
|
let found = false;
|
|
53
58
|
if (chooserClient.findByUrl) {
|
|
54
59
|
const item = await chooserClient.findByUrl(url);
|
|
60
|
+
if (url !== this.value)
|
|
61
|
+
return;
|
|
55
62
|
if (item) {
|
|
56
63
|
found = true;
|
|
57
64
|
if ((item.type === 'page' && !pages) || // they typed the URL for a page but we don't allow pages right now
|
|
@@ -93,7 +100,11 @@ async function userUrlEntry() {
|
|
|
93
100
|
}
|
|
94
101
|
async function updateSelected(..._) {
|
|
95
102
|
if ($value && selectedAsset?.id !== $value) {
|
|
96
|
-
|
|
103
|
+
const valueBeforeFind = $value;
|
|
104
|
+
const asset = await chooserClient.findById($value);
|
|
105
|
+
if ($value !== valueBeforeFind)
|
|
106
|
+
return;
|
|
107
|
+
selectedAsset = asset;
|
|
97
108
|
try {
|
|
98
109
|
if (!selectedAsset)
|
|
99
110
|
selectedAsset = { type: 'raw', id: $value, url: chooserClient.valueToUrl?.($value) ?? $value };
|
|
@@ -33,6 +33,7 @@ function heightPercent(val) {
|
|
|
33
33
|
return val / imageHeight * 100;
|
|
34
34
|
}
|
|
35
35
|
const defaultSelection = {
|
|
36
|
+
src: '',
|
|
36
37
|
selection: {
|
|
37
38
|
left: undefined,
|
|
38
39
|
top: undefined,
|
|
@@ -53,7 +54,8 @@ const defaultSelection = {
|
|
|
53
54
|
let imageWidth;
|
|
54
55
|
let imageHeight;
|
|
55
56
|
$: imageAspectRatio = imageWidth / imageHeight;
|
|
56
|
-
$: maxContainerWidth = (image ? Math.min(image.width, 700) : '700');
|
|
57
|
+
$: maxContainerWidth = ((image && imageWidth > 0 && imageHeight > 0) ? Math.min(image.width, 700) : '700');
|
|
58
|
+
$: store.setSrc(imageSrc, imageWidth, imageHeight, selectionAspectRatio);
|
|
57
59
|
const store = new ImageCropperStore(defaultSelection);
|
|
58
60
|
const { selection, crop } = store;
|
|
59
61
|
function startSelection(e) {
|
|
@@ -257,13 +259,14 @@ function reset(setVal) {
|
|
|
257
259
|
ctrlKey = false;
|
|
258
260
|
}
|
|
259
261
|
let storeInitialized = false;
|
|
260
|
-
function init(value) {
|
|
261
|
-
if (!storeInitialized && imageWidth > 0) {
|
|
262
|
+
function init(value, setVal) {
|
|
263
|
+
if (!storeInitialized && imageWidth > 0 && imageHeight > 0) {
|
|
262
264
|
if (value) {
|
|
263
265
|
store.setCrop(value.imagecropleft, value.imagecroptop, value.imagecropright, value.imagecropbottom, imageWidth, imageHeight);
|
|
264
266
|
}
|
|
265
267
|
else {
|
|
266
268
|
store.maximize(imageWidth, imageHeight, selectionAspectRatio);
|
|
269
|
+
setVal($crop);
|
|
267
270
|
}
|
|
268
271
|
storeInitialized = true;
|
|
269
272
|
}
|
|
@@ -272,7 +275,7 @@ function init(value) {
|
|
|
272
275
|
|
|
273
276
|
<FieldStandard bind:id {label} {path} {required} {conditional} {helptext} let:value let:setVal>
|
|
274
277
|
{#if isNotBlank(imageSrc)}
|
|
275
|
-
{@const _ = init(value)}
|
|
278
|
+
{@const _ = init(value, setVal)}
|
|
276
279
|
<div class="cropper-wrapper">
|
|
277
280
|
<div class="crop-image-container" on:mousedown={startSelection} on:mouseup={onMouseUp(setVal)} on:mousemove={onMouseMove(setVal)} on:keydown={onKeyDown(setVal)} on:keyup={onKeyUp(setVal)} bind:clientWidth={imageWidth} bind:clientHeight={imageHeight} style="max-width: {maxContainerWidth}px">
|
|
278
281
|
<img bind:this={image} class="crop-image" src={imageSrc} alt=""/>
|
|
@@ -284,8 +287,8 @@ function init(value) {
|
|
|
284
287
|
<div bind:this={shieldDiv} class="divShield" class:visible={$selection.shieldVisible} ></div>
|
|
285
288
|
</div>
|
|
286
289
|
<div class="action-buttons">
|
|
287
|
-
<button class='btn-center-max' on:click={() => maximize(setVal)}>Center and Maximize</button>
|
|
288
|
-
<button class='btn-clear' on:click={() => reset(setVal)}>Clear</button>
|
|
290
|
+
<button type="button" class='btn-center-max' on:click={() => maximize(setVal)}>Center and Maximize</button>
|
|
291
|
+
<button type="button" class='btn-clear' on:click={() => reset(setVal)}>Clear</button>
|
|
289
292
|
</div>
|
|
290
293
|
<div class="cropper-instructions">
|
|
291
294
|
Click and drag to select a section of your image to use.
|
|
@@ -3,6 +3,7 @@ import type { ICropperStore } from './imagecropper';
|
|
|
3
3
|
export declare class ImageCropperStore extends Store<ICropperStore> {
|
|
4
4
|
selection: import("@txstate-mws/svelte-store").DerivedStore<import("./imagecropper").ICropSelection, ICropperStore>;
|
|
5
5
|
crop: import("@txstate-mws/svelte-store").DerivedStore<import("./imagecropper").ImageCropperOutput, ICropperStore>;
|
|
6
|
+
setSrc(src: string, imageWidth: number, imageHeight: number, selectionAspectRatio: number): void;
|
|
6
7
|
draw(left: number, top: number, width: number, height: number, imageWidth: number, imageHeight: number): void;
|
|
7
8
|
setCrop(cropLeft: number, cropTop: number, cropRight: number, cropBottom: number, imageWidth: number, imageHeight: number): void;
|
|
8
9
|
setTrack(track: boolean): void;
|
|
@@ -2,6 +2,13 @@ import { Store, derivedStore } from '@txstate-mws/svelte-store';
|
|
|
2
2
|
export class ImageCropperStore extends Store {
|
|
3
3
|
selection = derivedStore(this, 'selection');
|
|
4
4
|
crop = derivedStore(this, 'crop');
|
|
5
|
+
setSrc(src, imageWidth, imageHeight, selectionAspectRatio) {
|
|
6
|
+
this.maximize(imageWidth, imageHeight, selectionAspectRatio);
|
|
7
|
+
this.update(v => ({
|
|
8
|
+
...v,
|
|
9
|
+
src
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
5
12
|
draw(left, top, width, height, imageWidth, imageHeight) {
|
|
6
13
|
// calculate new values for crop
|
|
7
14
|
const cropLeft = left / imageWidth;
|
|
@@ -75,6 +82,7 @@ export class ImageCropperStore extends Store {
|
|
|
75
82
|
}
|
|
76
83
|
reset() {
|
|
77
84
|
this.update(v => ({
|
|
85
|
+
...v,
|
|
78
86
|
selection: {
|
|
79
87
|
left: undefined,
|
|
80
88
|
top: undefined,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dosgato/dialog",
|
|
3
3
|
"description": "A component library for building forms that edit a JSON document.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.33",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@txstate-mws/svelte-components": "^1.3.5",
|
|
7
7
|
"@txstate-mws/svelte-forms": "^1.2.1",
|