@dosgato/dialog 0.0.33 → 0.0.35

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 (77) hide show
  1. package/Button.svelte.d.ts +7 -7
  2. package/ButtonGroup.svelte.d.ts +5 -5
  3. package/Checkbox.svelte.d.ts +4 -4
  4. package/Container.svelte.d.ts +2 -2
  5. package/Dialog.svelte +3 -2
  6. package/Dialog.svelte.d.ts +14 -14
  7. package/FieldAutocomplete.svelte +7 -2
  8. package/FieldAutocomplete.svelte.d.ts +9 -9
  9. package/FieldCheckbox.svelte.d.ts +4 -4
  10. package/FieldChoices.svelte.d.ts +6 -6
  11. package/FieldChooserLink.svelte +7 -2
  12. package/FieldChooserLink.svelte.d.ts +8 -8
  13. package/FieldCodeEditor.svelte +2 -2
  14. package/FieldCodeEditor.svelte.d.ts +7 -7
  15. package/FieldDate.svelte.d.ts +4 -4
  16. package/FieldDateTime.svelte.d.ts +3 -3
  17. package/FieldDualListbox.svelte.d.ts +6 -6
  18. package/FieldHidden.svelte +1 -1
  19. package/FieldHidden.svelte.d.ts +2 -2
  20. package/FieldMultiple.svelte.d.ts +7 -7
  21. package/FieldMultiselect.svelte +5 -1
  22. package/FieldMultiselect.svelte.d.ts +5 -5
  23. package/FieldNumber.svelte.d.ts +5 -5
  24. package/FieldRadio.svelte.d.ts +13 -13
  25. package/FieldSelect.svelte.d.ts +15 -15
  26. package/FieldStandard.svelte +2 -1
  27. package/FieldStandard.svelte.d.ts +11 -10
  28. package/FieldText.svelte +1 -1
  29. package/FieldText.svelte.d.ts +8 -8
  30. package/FieldTextArea.svelte +1 -1
  31. package/FieldTextArea.svelte.d.ts +6 -6
  32. package/FileIcon.svelte.d.ts +5 -5
  33. package/Form.svelte +3 -3
  34. package/Form.svelte.d.ts +5 -5
  35. package/FormDialog.svelte +2 -2
  36. package/FormDialog.svelte.d.ts +24 -21
  37. package/Icon.svelte.d.ts +5 -5
  38. package/Input.svelte.d.ts +8 -8
  39. package/Listbox.svelte +2 -2
  40. package/Listbox.svelte.d.ts +6 -6
  41. package/Radio.svelte.d.ts +4 -4
  42. package/Switcher.svelte.d.ts +11 -11
  43. package/TabStore.d.ts +3 -3
  44. package/TabStore.js +7 -6
  45. package/Tabs.svelte +6 -6
  46. package/Tabs.svelte.d.ts +2 -2
  47. package/chooser/Chooser.svelte +4 -3
  48. package/chooser/Chooser.svelte.d.ts +12 -12
  49. package/chooser/ChooserStore.d.ts +4 -4
  50. package/chooser/ChooserStore.js +3 -3
  51. package/colorpicker/FieldColorPicker.svelte.d.ts +5 -5
  52. package/cropper/FieldCropper.svelte +219 -0
  53. package/cropper/FieldCropper.svelte.d.ts +24 -0
  54. package/cropper/cropper.d.ts +78 -0
  55. package/cropper/cropper.js +220 -0
  56. package/cropper/index.d.ts +2 -0
  57. package/cropper/index.js +2 -0
  58. package/helpers.d.ts +1 -1
  59. package/iconpicker/FieldIconPicker.svelte +5 -5
  60. package/iconpicker/FieldIconPicker.svelte.d.ts +3 -3
  61. package/index.d.ts +1 -1
  62. package/index.js +1 -1
  63. package/package.json +13 -14
  64. package/tree/LoadIcon.svelte.d.ts +2 -2
  65. package/tree/Tree.svelte.d.ts +11 -11
  66. package/tree/TreeNode.svelte +4 -1
  67. package/tree/TreeNode.svelte.d.ts +4 -4
  68. package/tree/treestore.d.ts +16 -16
  69. package/tree/treestore.js +3 -3
  70. package/imagecropper/FieldImageCropper.svelte +0 -380
  71. package/imagecropper/FieldImageCropper.svelte.d.ts +0 -25
  72. package/imagecropper/ImageCropperStore.d.ts +0 -16
  73. package/imagecropper/ImageCropperStore.js +0 -104
  74. package/imagecropper/imagecropper.d.ts +0 -21
  75. package/imagecropper/imagecropper.js +0 -1
  76. package/imagecropper/index.d.ts +0 -1
  77. package/imagecropper/index.js +0 -1
package/package.json CHANGED
@@ -1,10 +1,10 @@
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.33",
4
+ "version": "0.0.35",
5
5
  "dependencies": {
6
- "@txstate-mws/svelte-components": "^1.3.5",
7
- "@txstate-mws/svelte-forms": "^1.2.1",
6
+ "@txstate-mws/svelte-components": "^1.3.7",
7
+ "@txstate-mws/svelte-forms": "^1.3.4",
8
8
  "@iconify/svelte": "^3.0.0",
9
9
  "@iconify-icons/mdi": "^1.2.22",
10
10
  "@iconify-icons/ph": "^1.2.2",
@@ -12,15 +12,15 @@
12
12
  "txstate-utils": "^1.8.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@sveltejs/adapter-auto": "next",
16
- "@sveltejs/kit": "next",
17
- "@sveltejs/package": "^1.0.0-next.5",
15
+ "@sveltejs/adapter-auto": "^1.0.0",
16
+ "@sveltejs/kit": "^1.0.1",
17
+ "@sveltejs/package": "^1.0.1",
18
18
  "@types/codeflask": "^1.4.3",
19
- "eslint-config-standard-with-typescript": "^23.0.0",
19
+ "eslint-config-standard-with-typescript": "^24.0.0",
20
20
  "eslint-plugin-svelte3": "^4.0.0",
21
- "svelte-check": "^2.2.6",
22
- "svelte-preprocess": "^4.9.4",
23
- "svelte2tsx": "^0.5.20",
21
+ "svelte-check": "^3.0.1",
22
+ "svelte-preprocess": "^5.0.0",
23
+ "svelte2tsx": "^0.6.0",
24
24
  "tslib": "^2.3.1",
25
25
  "typescript": "^4.4.3"
26
26
  },
@@ -75,15 +75,14 @@
75
75
  "./colorpicker/FieldColorPicker.svelte": "./colorpicker/FieldColorPicker.svelte",
76
76
  "./colorpicker/colorpicker": "./colorpicker/colorpicker.js",
77
77
  "./colorpicker": "./colorpicker/index.js",
78
+ "./cropper/FieldCropper.svelte": "./cropper/FieldCropper.svelte",
79
+ "./cropper/cropper": "./cropper/cropper.js",
80
+ "./cropper": "./cropper/index.js",
78
81
  "./fileIcons": "./fileIcons.js",
79
82
  "./helpers": "./helpers.js",
80
83
  "./iconpicker/FieldIconPicker.svelte": "./iconpicker/FieldIconPicker.svelte",
81
84
  "./iconpicker/iconpicker": "./iconpicker/iconpicker.js",
82
85
  "./iconpicker": "./iconpicker/index.js",
83
- "./imagecropper/FieldImageCropper.svelte": "./imagecropper/FieldImageCropper.svelte",
84
- "./imagecropper/ImageCropperStore": "./imagecropper/ImageCropperStore.js",
85
- "./imagecropper/imagecropper": "./imagecropper/imagecropper.js",
86
- "./imagecropper": "./imagecropper/index.js",
87
86
  ".": "./index.js",
88
87
  "./tree/LoadIcon.svelte": "./tree/LoadIcon.svelte",
89
88
  "./tree/Tree.svelte": "./tree/Tree.svelte",
@@ -2,7 +2,7 @@
2
2
  /** @typedef {typeof __propDef.events} LoadIconEvents */
3
3
  /** @typedef {typeof __propDef.slots} LoadIconSlots */
4
4
  export default class LoadIcon extends SvelteComponentTyped<{
5
- size?: string;
5
+ size?: string | undefined;
6
6
  }, {
7
7
  [evt: string]: CustomEvent<any>;
8
8
  }, {}> {
@@ -13,7 +13,7 @@ export type LoadIconSlots = typeof __propDef.slots;
13
13
  import { SvelteComponentTyped } from "svelte";
14
14
  declare const __propDef: {
15
15
  props: {
16
- size?: string;
16
+ size?: string | undefined;
17
17
  };
18
18
  events: {
19
19
  [evt: string]: CustomEvent<any>;
@@ -4,22 +4,22 @@ import type { DragEligibleFn, CopyHandlerFn, DropEffectFn, FetchChildrenFn, Move
4
4
  declare class __sveltets_Render<T extends TreeItemFromDB> {
5
5
  props(): {
6
6
  headers: TreeHeader<T>[];
7
- nodeClass?: (itm: T) => string;
8
- singleSelect?: boolean;
9
- enableResize?: boolean;
7
+ nodeClass?: ((itm: T) => string) | undefined;
8
+ singleSelect?: boolean | undefined;
9
+ enableResize?: boolean | undefined;
10
10
  /**
11
11
  * this `itemType` prop is here for typescript only
12
12
  *
13
13
  * it will allow users to specify T
14
14
  *
15
15
  * we are able to determine T from the store prop, but not everyone will use the store prop
16
- */ itemType?: T;
17
- fetchChildren?: FetchChildrenFn<T>;
18
- dragEligible?: DragEligibleFn<T>;
19
- moveHandler?: MoveHandlerFn<T>;
20
- copyHandler?: CopyHandlerFn<T>;
21
- dropEffect?: DropEffectFn<T>;
22
- store?: TreeStore<T>;
16
+ */ itemType?: T | undefined;
17
+ fetchChildren?: FetchChildrenFn<T> | undefined;
18
+ dragEligible?: DragEligibleFn<T> | undefined;
19
+ moveHandler?: MoveHandlerFn<T> | undefined;
20
+ copyHandler?: CopyHandlerFn<T> | undefined;
21
+ dropEffect?: DropEffectFn<T> | undefined;
22
+ store?: TreeStore<T> | undefined;
23
23
  };
24
24
  events(): {
25
25
  choose: CustomEvent<T>;
@@ -31,6 +31,6 @@ export type TreeProps<T extends TreeItemFromDB> = ReturnType<__sveltets_Render<T
31
31
  export type TreeEvents<T extends TreeItemFromDB> = ReturnType<__sveltets_Render<T>['events']>;
32
32
  export type TreeSlots<T extends TreeItemFromDB> = ReturnType<__sveltets_Render<T>['slots']>;
33
33
  export default class Tree<T extends TreeItemFromDB> extends SvelteComponentTyped<TreeProps<T>, TreeEvents<T>, TreeSlots<T>> {
34
- get itemType(): T;
34
+ get itemType(): T & {};
35
35
  }
36
36
  export {};
@@ -310,7 +310,10 @@ $: if ($dragging) {
310
310
  </div>
311
311
  {/each}
312
312
  <ScreenReaderOnly>
313
- command enter select multiple, shift enter select all from last selection
313
+ up down to navigate
314
+ {#if item.hasChildren && showChildren}, left arrow to hide children{/if}
315
+ {#if item.hasChildren && !showChildren}, right arrow to show children{/if}
316
+ {#if $selected.size > 0}, command-enter to select multiple, shift-enter to select all from last selection{/if}
314
317
  </ScreenReaderOnly>
315
318
  </div>
316
319
  {#if showChildren && item.children}
@@ -5,14 +5,14 @@ declare class __sveltets_Render<T extends TreeItemFromDB> {
5
5
  props(): {
6
6
  headers: TreeHeader<T>[];
7
7
  headerSizes: Store<string[]>;
8
- nodeClass?: (itm: T) => string;
8
+ nodeClass?: ((itm: T) => string) | undefined;
9
9
  item: TypedTreeItem<T>;
10
10
  posinset: number;
11
11
  setsize: number;
12
12
  level: number;
13
- next: TypedTreeItem<T>;
14
- prev: TypedTreeItem<T>;
15
- parent?: TypedTreeItem<T>;
13
+ next: TypedTreeItem<T> | undefined;
14
+ prev: TypedTreeItem<T> | undefined;
15
+ parent?: TypedTreeItem<T> | undefined;
16
16
  };
17
17
  events(): {
18
18
  choose: CustomEvent<any>;
@@ -48,12 +48,12 @@ export declare class TreeStore<T extends TreeItemFromDB> extends ActiveStore<ITr
48
48
  #private;
49
49
  fetchChildren: FetchChildrenFn<T>;
50
50
  treeElement?: HTMLElement;
51
- rootItems: import("@txstate-mws/svelte-store").DerivedStore<TypedTreeItem<T>[], ITreeStore<T>>;
51
+ rootItems: import("@txstate-mws/svelte-store").DerivedStore<TypedTreeItem<T>[] | undefined, ITreeStore<T>>;
52
52
  draggable: import("@txstate-mws/svelte-store").DerivedStore<boolean, ITreeStore<T>>;
53
53
  dragging: import("@txstate-mws/svelte-store").DerivedStore<boolean, ITreeStore<T>>;
54
- selectedUndraggable: import("@txstate-mws/svelte-store").DerivedStore<boolean, ITreeStore<T>>;
54
+ selectedUndraggable: import("@txstate-mws/svelte-store").DerivedStore<boolean | undefined, ITreeStore<T>>;
55
55
  selected: import("@txstate-mws/svelte-store").DerivedStore<Map<string, TypedTreeItem<T>>, ITreeStore<T>>;
56
- focused: import("@txstate-mws/svelte-store").DerivedStore<TypedTreeItem<T>, ITreeStore<T>>;
56
+ focused: import("@txstate-mws/svelte-store").DerivedStore<TypedTreeItem<T> | undefined, ITreeStore<T>>;
57
57
  copied: import("@txstate-mws/svelte-store").DerivedStore<Map<string, TypedTreeItem<T>>, ITreeStore<T>>;
58
58
  headerOverride: import("@txstate-mws/svelte-store").DerivedStore<Record<string, string>, ITreeStore<T>>;
59
59
  moveHandler?: MoveHandlerFn<T>;
@@ -79,14 +79,14 @@ export declare class TreeStore<T extends TreeItemFromDB> extends ActiveStore<ITr
79
79
  refresh(item?: TypedTreeItem<T>, skipNotify?: boolean): Promise<void>;
80
80
  focus(item: TypedTreeItem<T> | undefined, notify?: boolean): void;
81
81
  select(item: TypedTreeItem<T>, { clear, notify, toggle }: {
82
- clear?: boolean;
83
- notify?: boolean;
84
- toggle?: boolean;
82
+ clear?: boolean | undefined;
83
+ notify?: boolean | undefined;
84
+ toggle?: boolean | undefined;
85
85
  }): void;
86
86
  selectById(id: string, { clear, notify, toggle }: {
87
- clear?: boolean;
88
- notify?: boolean;
89
- toggle?: boolean;
87
+ clear?: boolean | undefined;
88
+ notify?: boolean | undefined;
89
+ toggle?: boolean | undefined;
90
90
  }): void;
91
91
  deselect(notify?: boolean): void;
92
92
  isSelected(item: TypedTreeItem<T>): boolean;
@@ -96,22 +96,22 @@ export declare class TreeStore<T extends TreeItemFromDB> extends ActiveStore<ITr
96
96
  toggle(item: TypedTreeItem<T>): Promise<void>;
97
97
  viewUnder(item?: TypedTreeItem<T>): Promise<void>;
98
98
  dragStart(item: TypedTreeItem<T>): void;
99
- protected _drop(item: TypedTreeItem<T>, droppedItems: Map<string, TypedTreeItem<T>>, above: boolean, userWantsCopy: boolean, userWantsRecursive: boolean | undefined): Promise<boolean>;
100
- drop(item: TypedTreeItem<T>, above: boolean, userWantsCopy: any): Promise<boolean>;
99
+ protected _drop(item: TypedTreeItem<T>, droppedItems: Map<string, TypedTreeItem<T>>, above: boolean, userWantsCopy: boolean, userWantsRecursive: boolean | undefined): Promise<boolean | undefined>;
100
+ drop(item: TypedTreeItem<T>, above: boolean, userWantsCopy: any): Promise<boolean | undefined>;
101
101
  collectAncestors(item: TypedTreeItem<T>): TypedTreeItem<T>[];
102
102
  root(item: TypedTreeItem<T>): TypedTreeItem<T>;
103
- findCommonParent(items: TypedTreeItem<T>[]): TypedTreeItem<T>;
103
+ findCommonParent(items: TypedTreeItem<T>[]): TypedTreeItem<T> | undefined;
104
104
  dragEligible(selectedItems: TypedTreeItem<T>[], userWantsCopy: boolean): boolean;
105
105
  protected _dropEffect(item: TypedTreeItem<T>, droppedItems: Map<string, TypedTreeItem<T>>, above: boolean, userWantsCopy: boolean): "none" | "copy" | "move";
106
106
  dropEffect(item: TypedTreeItem<T>, above: boolean, userWantsCopy: boolean): "none" | "copy" | "move";
107
107
  cut(): void;
108
108
  copy(): void;
109
- cutEligible(): boolean;
110
- copyEligible(): boolean;
109
+ cutEligible(): boolean | undefined;
110
+ copyEligible(): boolean | undefined;
111
111
  cancelCopy(): void;
112
- pasteEligible(above?: boolean): boolean;
112
+ pasteEligible(above?: boolean): boolean | 0;
113
113
  pasteEffect(above?: boolean): "none" | "copy" | "move";
114
- paste(above?: boolean, userWantsRecursive?: boolean): Promise<boolean>;
114
+ paste(above?: boolean, userWantsRecursive?: boolean): Promise<boolean | undefined>;
115
115
  setHeaderOverride(id: string, width: string): void;
116
116
  resetHeaderOverride(): void;
117
117
  }
package/tree/treestore.js CHANGED
@@ -103,7 +103,7 @@ export class TreeStore extends ActiveStore {
103
103
  this.addLookup(children);
104
104
  // if the focused item disappeared in the refresh, we need to replace it,
105
105
  // as without a focus the tree becomes invisible to keyboard nav
106
- if (!this.value.itemsById[this.value.focused?.id])
106
+ if (!this.value.itemsById[this.value.focused?.id ?? ''])
107
107
  this.focus(this.value.selectedItems.slice(-1)[0] ?? this.value.rootItems?.[0], true);
108
108
  }
109
109
  finally {
@@ -205,8 +205,8 @@ export class TreeStore extends ActiveStore {
205
205
  const commonparent = this.findCommonParent([...selectedItems, item]);
206
206
  try {
207
207
  const result = dropEffect === 'move'
208
- ? await this.moveHandler(selectedItems, item, above)
209
- : await this.copyHandler(selectedItems, item, above, userWantsRecursive);
208
+ ? await this.moveHandler?.(selectedItems, item, above)
209
+ : await this.copyHandler?.(selectedItems, item, above, userWantsRecursive);
210
210
  await this.openAndRefresh(item);
211
211
  await this.refresh(commonparent);
212
212
  return result;
@@ -1,380 +0,0 @@
1
- <script>import { isNotBlank, isNotNull } from 'txstate-utils';
2
- import FieldStandard from '../FieldStandard.svelte';
3
- import { ImageCropperStore } from './ImageCropperStore';
4
- export let id = undefined;
5
- export let path;
6
- export let imageSrc;
7
- export let selectionAspectRatio = 1;
8
- export let minSelection = 0; // percentage of image, a value 0-1
9
- export let snapDistance = 0;
10
- export let label = '';
11
- export let required = false;
12
- export let conditional = undefined;
13
- export let helptext = undefined;
14
- let minSelectionWidth = 0;
15
- let minSelectionHeight = 0;
16
- let localCoord = null;
17
- const oldGlobalCoord = { x: 0, y: 0 };
18
- let initialGlobalCoord = null;
19
- let globalOffsetX = 0;
20
- let globalOffsetY = 0;
21
- let initialGlobalDragCoord = null;
22
- let initialDragLeft = 0;
23
- let initialDragTop = 0;
24
- let altKey = false;
25
- let ctrlKey = false;
26
- const pseudoEvent = { clientX: 0, clientY: 0 };
27
- let shieldDiv;
28
- let image;
29
- function widthPercent(val) {
30
- return val / imageWidth * 100;
31
- }
32
- function heightPercent(val) {
33
- return val / imageHeight * 100;
34
- }
35
- const defaultSelection = {
36
- src: '',
37
- selection: {
38
- left: undefined,
39
- top: undefined,
40
- width: undefined,
41
- height: undefined,
42
- visible: false,
43
- shieldVisible: false,
44
- track: false,
45
- drag: false
46
- },
47
- crop: {
48
- imagecropbottom: 0,
49
- imagecropleft: 0,
50
- imagecropright: 0,
51
- imagecroptop: 0
52
- }
53
- };
54
- let imageWidth;
55
- let imageHeight;
56
- $: imageAspectRatio = imageWidth / imageHeight;
57
- $: maxContainerWidth = ((image && imageWidth > 0 && imageHeight > 0) ? Math.min(image.width, 700) : '700');
58
- $: store.setSrc(imageSrc, imageWidth, imageHeight, selectionAspectRatio);
59
- const store = new ImageCropperStore(defaultSelection);
60
- const { selection, crop } = store;
61
- function startSelection(e) {
62
- e.preventDefault();
63
- e.stopPropagation();
64
- if (e.altKey)
65
- altKey = e.altKey;
66
- if (e.ctrlKey)
67
- ctrlKey = e.ctrlKey;
68
- if (!$selection.visible) {
69
- localCoord = { x: e.offsetX + 1, y: e.offsetY + 1 };
70
- initialGlobalCoord = { x: e.clientX, y: e.clientY };
71
- oldGlobalCoord.x = e.clientX;
72
- oldGlobalCoord.y = e.clientY;
73
- let selectionWidth = 0;
74
- let selectionHeight = 0;
75
- if (minSelection > 0) {
76
- if (imageAspectRatio > selectionAspectRatio) {
77
- // use height for min selection calculation
78
- selectionHeight = imageHeight * minSelection;
79
- selectionWidth = (16.0 * selectionHeight) / 9.0; // TODO: Why is this assuming a 16:9 ratio? That's how it's working Gato, but probably isn't right.
80
- }
81
- else {
82
- // use width for min selection calculation
83
- selectionWidth = imageWidth * minSelection;
84
- selectionHeight = (9.0 * selectionWidth) / 16.0;
85
- }
86
- minSelectionWidth = selectionWidth;
87
- minSelectionHeight = selectionHeight;
88
- }
89
- store.draw(e.offsetX, e.offsetY, selectionWidth, selectionHeight, imageWidth, imageHeight);
90
- store.setTrack(true);
91
- }
92
- }
93
- function adjustInitialSelection(e, setVal) {
94
- // Getting position and size.
95
- if (altKey) {
96
- // Pressing alt allows the user to move the selection while creating it.
97
- globalOffsetX += e.clientX - oldGlobalCoord.x;
98
- globalOffsetY += e.clientY - oldGlobalCoord.y;
99
- }
100
- // If the user moved the mouse from right to left instead of left to right
101
- const invertedHor = e.clientX - (initialGlobalCoord.x + globalOffsetX) < 0;
102
- // If the user moved the mouse from bottom to top instead of top to bottom
103
- const invertedVer = e.clientY - (initialGlobalCoord.y + globalOffsetY) < 0;
104
- let width = Math.abs(e.clientX - (initialGlobalCoord.x + globalOffsetX));
105
- let height = Math.abs(e.clientY - (initialGlobalCoord.y + globalOffsetY));
106
- let left = localCoord.x + globalOffsetX;
107
- let top = localCoord.y + globalOffsetY;
108
- if (invertedHor)
109
- left -= width;
110
- if (invertedVer)
111
- top -= height;
112
- const leftEdge = left;
113
- if (leftEdge < 0 || (leftEdge <= snapDistance && !ctrlKey)) {
114
- width += leftEdge;
115
- left = 0;
116
- }
117
- const topEdge = top;
118
- if (topEdge < 0 || (topEdge <= snapDistance && !ctrlKey)) {
119
- height += topEdge;
120
- top = 0;
121
- }
122
- const rightEdge = imageWidth - width - left;
123
- if (rightEdge < 0 || (rightEdge <= snapDistance && !ctrlKey))
124
- width += rightEdge;
125
- const bottomEdge = imageHeight - height - top;
126
- if (bottomEdge < 0 || (bottomEdge <= snapDistance && !ctrlKey))
127
- height += bottomEdge;
128
- if (width > selectionAspectRatio * height) {
129
- if (invertedHor)
130
- left += width - selectionAspectRatio * height;
131
- width = selectionAspectRatio * height;
132
- }
133
- else {
134
- if (invertedVer)
135
- top += height - width / selectionAspectRatio;
136
- height = width / selectionAspectRatio;
137
- }
138
- if (width < minSelectionWidth || height < minSelectionHeight) {
139
- width = minSelectionWidth;
140
- height = minSelectionHeight;
141
- }
142
- store.draw(left, top, width, height, imageWidth, imageHeight);
143
- setVal($crop);
144
- }
145
- function onMouseUp(setVal) {
146
- return (e) => {
147
- e.preventDefault();
148
- e.stopPropagation();
149
- if (e.altKey)
150
- altKey = e.altKey;
151
- if (e.ctrlKey)
152
- ctrlKey = e.ctrlKey;
153
- if ($selection.track) {
154
- if (initialGlobalCoord.x === e.clientX && initialGlobalCoord.y === e.clientY) {
155
- reset(setVal);
156
- }
157
- else {
158
- adjustInitialSelection(e, setVal);
159
- store.setShieldVisibility(true);
160
- oldGlobalCoord.x = e.clientX;
161
- oldGlobalCoord.y = e.clientY;
162
- }
163
- }
164
- else if (e.target === shieldDiv || e.target === image) {
165
- reset(setVal);
166
- }
167
- store.setTrack(false);
168
- store.setDrag(false);
169
- };
170
- }
171
- function onMouseMove(setVal) {
172
- return (e) => {
173
- if (e.altKey)
174
- altKey = e.altKey;
175
- if (e.ctrlKey)
176
- ctrlKey = e.ctrlKey;
177
- if ($selection.track || $selection.drag) {
178
- e.preventDefault();
179
- pseudoEvent.clientX = e.clientX;
180
- pseudoEvent.clientY = e.clientY;
181
- if ($selection.track)
182
- adjustInitialSelection(pseudoEvent, setVal);
183
- else if ($selection.drag)
184
- adjustSelectionDrag(pseudoEvent, setVal);
185
- oldGlobalCoord.x = e.clientX;
186
- oldGlobalCoord.y = e.clientY;
187
- }
188
- };
189
- }
190
- function startDragSelection(e) {
191
- e.preventDefault();
192
- e.stopPropagation();
193
- if (e.altKey)
194
- altKey = e.altKey;
195
- if (e.ctrlKey)
196
- ctrlKey = e.ctrlKey;
197
- initialGlobalDragCoord = { x: e.clientX, y: e.clientY };
198
- initialDragLeft = $selection.left;
199
- initialDragTop = $selection.top;
200
- store.setDrag(true);
201
- }
202
- function onKey(e, setVal) {
203
- altKey = e.altKey;
204
- ctrlKey = e.ctrlKey;
205
- if ($selection.track || $selection.drag) {
206
- e.preventDefault();
207
- pseudoEvent.preventDefault = function () { };
208
- pseudoEvent.clientX = oldGlobalCoord.x;
209
- pseudoEvent.clientY = oldGlobalCoord.y;
210
- pseudoEvent.altKey = e.altKey;
211
- pseudoEvent.ctrlKey = e.ctrlKey;
212
- }
213
- if ($selection.track)
214
- adjustInitialSelection(pseudoEvent, setVal);
215
- else if ($selection.drag)
216
- onMouseMove.call(pseudoEvent, setVal);
217
- }
218
- function onKeyDown(setVal) {
219
- return (e) => {
220
- if ((!altKey && e.altKey) || (!ctrlKey && e.ctrlKey))
221
- onKey(e, setVal);
222
- };
223
- }
224
- function onKeyUp(setVal) {
225
- return (e) => {
226
- if ((!altKey && e.altKey) || (!ctrlKey && e.ctrlKey))
227
- onKey(e, setVal);
228
- };
229
- }
230
- function adjustSelectionDrag(e, setVal) {
231
- let left = initialDragLeft + e.clientX - initialGlobalDragCoord.x;
232
- let top = initialDragTop + e.clientY - initialGlobalDragCoord.y;
233
- // Adjusting position to account for edge snapping
234
- const leftEdge = left;
235
- if (leftEdge < 0 || (leftEdge <= snapDistance && !ctrlKey))
236
- left = 0;
237
- const topEdge = top;
238
- if (topEdge < 0 || (topEdge <= snapDistance && !ctrlKey))
239
- top = 0;
240
- const rightEdge = imageWidth - $selection.width - left;
241
- if (rightEdge < 0 || (rightEdge <= snapDistance && !ctrlKey))
242
- left += rightEdge;
243
- const bottomEdge = imageHeight - $selection.height - top;
244
- if (bottomEdge < 0 || (bottomEdge <= snapDistance && !ctrlKey))
245
- top += bottomEdge;
246
- store.moveSelectionTo(left, top, imageWidth, imageHeight);
247
- setVal($crop);
248
- }
249
- function maximize(setVal) {
250
- store.maximize(imageWidth, imageHeight, selectionAspectRatio);
251
- setVal($crop);
252
- }
253
- function reset(setVal) {
254
- localCoord = null;
255
- initialGlobalCoord = null;
256
- store.reset();
257
- setVal($crop);
258
- altKey = false;
259
- ctrlKey = false;
260
- }
261
- let storeInitialized = false;
262
- function init(value, setVal) {
263
- if (!storeInitialized && imageWidth > 0 && imageHeight > 0) {
264
- if (value) {
265
- store.setCrop(value.imagecropleft, value.imagecroptop, value.imagecropright, value.imagecropbottom, imageWidth, imageHeight);
266
- }
267
- else {
268
- store.maximize(imageWidth, imageHeight, selectionAspectRatio);
269
- setVal($crop);
270
- }
271
- storeInitialized = true;
272
- }
273
- }
274
- </script>
275
-
276
- <FieldStandard bind:id {label} {path} {required} {conditional} {helptext} let:value let:setVal>
277
- {#if isNotBlank(imageSrc)}
278
- {@const _ = init(value, setVal)}
279
- <div class="cropper-wrapper">
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">
281
- <img bind:this={image} class="crop-image" src={imageSrc} alt=""/>
282
- <div class='selectionLine divSelectionHor divSelectionTop' class:visible={$selection.visible} style={isNotNull($selection.left) ? `left: ${$selection.left}px; top: ${$selection.top}px; width: ${$selection.width}px` : ''}></div>
283
- <div class='selectionLine divSelectionVer divSelectionRight' class:visible={$selection.visible} style={isNotNull($selection.left) ? `left: ${$selection.left + $selection.width - 1}px; top: ${$selection.top}px; height: ${$selection.height}px` : ''}></div>
284
- <div class='selectionLine divSelectionHor divSelectionBottom' class:visible={$selection.visible} style={isNotNull($selection.left) ? `left: ${$selection.left}px; top: ${$selection.top + $selection.height - 1}px; width: ${$selection.width}px` : ''}></div>
285
- <div class='selectionLine divSelectionVer divSelectionLeft' class:visible={$selection.visible} style={isNotNull($selection.left) ? `left: ${$selection.left}px; top: ${$selection.top}px; height: ${$selection.height}px` : ''}></div>
286
- <img src="{imageSrc}" class='imageCropSelection' alt="" class:visible={$selection.visible} style={isNotNull($selection.left) ? `clip-path: polygon(${widthPercent($selection.left)}% ${heightPercent($selection.top)}%, ${widthPercent($selection.left + $selection.width)}% ${heightPercent($selection.top)}%, ${widthPercent($selection.left + $selection.width)}% ${heightPercent($selection.top + $selection.height)}%, ${widthPercent($selection.left)}% ${heightPercent($selection.top + $selection.height)}%)` : ''} on:mousedown={startDragSelection}/>
287
- <div bind:this={shieldDiv} class="divShield" class:visible={$selection.shieldVisible} ></div>
288
- </div>
289
- <div class="action-buttons">
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>
292
- </div>
293
- <div class="cropper-instructions">
294
- Click and drag to select a section of your image to use.
295
- </div>
296
- </div>
297
- {:else}
298
- Image not selected
299
- {/if}
300
- </FieldStandard>
301
-
302
- <style>
303
- .crop-image-container {
304
- position: relative;
305
- }
306
- .crop-image-container .crop-image {
307
- max-width: 100%;
308
- max-height: 100%;
309
- z-index: 3;
310
- cursor: crosshair;
311
- display: block;
312
- position: relative;
313
- }
314
-
315
- .selectionLine {
316
- visibility: hidden;
317
- }
318
- .selectionLine.visible {
319
- visibility: visible;
320
- }
321
- .imageCropSelection {
322
- visibility: hidden;
323
- }
324
- .imageCropSelection.visible {
325
- visibility: visible;
326
- }
327
- .imageCropSelection {
328
- position: absolute;
329
- top: 0;
330
- left: 0;
331
- display: block;
332
- z-index: 9;
333
- visibility: hidden;
334
- overflow: hidden;
335
- max-width:100%;
336
- max-height: 100%;
337
- }
338
- .divShield {
339
- position: absolute;
340
- left: 0;
341
- top: 0;
342
- background: #000;
343
- z-index: 4;
344
- cursor: default;
345
- visibility: hidden;
346
- filter: opacity(80%);
347
- opacity: 0.8;
348
- width: 100%;
349
- height: 100%;
350
- }
351
- .divShield.visible {
352
- visibility: visible;
353
- }
354
-
355
- .divSelectionHor {
356
- position: absolute;
357
- left: 0;
358
- top: 0;
359
- width: 1px;
360
- height: 1px;
361
- font: 1px/1px verdana, sans-serif;
362
- background: repeating-linear-gradient(to right, #000, #000 5px, white 5px, transparent 10px);
363
- z-index: 10;
364
- cursor: crosshair;
365
- visibility: hidden;
366
- }
367
- .divSelectionVer {
368
- position: absolute;
369
- left: 0;
370
- top: 0;
371
- width: 1px;
372
- height: 1px;
373
- font: 1px/1px verdana, sans-serif;
374
- background: repeating-linear-gradient(to bottom, #000, #000 5px, white 5px, transparent 10px);
375
- z-index: 10;
376
- cursor: crosshair;
377
- visibility: hidden;
378
- }
379
-
380
- </style>
@@ -1,25 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- id?: string | undefined;
5
- path: string;
6
- imageSrc: string;
7
- selectionAspectRatio?: number;
8
- minSelection?: number;
9
- snapDistance?: number;
10
- label?: string;
11
- required?: boolean;
12
- conditional?: boolean | undefined;
13
- helptext?: string | undefined;
14
- };
15
- events: {
16
- [evt: string]: CustomEvent<any>;
17
- };
18
- slots: {};
19
- };
20
- export type FieldImageCropperProps = typeof __propDef.props;
21
- export type FieldImageCropperEvents = typeof __propDef.events;
22
- export type FieldImageCropperSlots = typeof __propDef.slots;
23
- export default class FieldImageCropper extends SvelteComponentTyped<FieldImageCropperProps, FieldImageCropperEvents, FieldImageCropperSlots> {
24
- }
25
- export {};
@@ -1,16 +0,0 @@
1
- import { Store } from '@txstate-mws/svelte-store';
2
- import type { ICropperStore } from './imagecropper';
3
- export declare class ImageCropperStore extends Store<ICropperStore> {
4
- selection: import("@txstate-mws/svelte-store").DerivedStore<import("./imagecropper").ICropSelection, ICropperStore>;
5
- crop: import("@txstate-mws/svelte-store").DerivedStore<import("./imagecropper").ImageCropperOutput, ICropperStore>;
6
- setSrc(src: string, imageWidth: number, imageHeight: number, selectionAspectRatio: number): void;
7
- draw(left: number, top: number, width: number, height: number, imageWidth: number, imageHeight: number): void;
8
- setCrop(cropLeft: number, cropTop: number, cropRight: number, cropBottom: number, imageWidth: number, imageHeight: number): void;
9
- setTrack(track: boolean): void;
10
- setShieldVisibility(vis: boolean): void;
11
- setDrag(drag: boolean): void;
12
- setSelectionVisibility(visible: boolean): void;
13
- moveSelectionTo(left: number, top: number, imageWidth: number, imageHeight: number): void;
14
- maximize(imageWidth: number, imageHeight: number, selectionAspectRatio: number): void;
15
- reset(): void;
16
- }