@hkdigital/lib-sveltekit 0.1.77 → 0.1.79

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 (33) hide show
  1. package/dist/components/drag-drop/DragDropContext.svelte +26 -0
  2. package/dist/components/drag-drop/DragDropContext.svelte.d.ts +18 -0
  3. package/dist/components/drag-drop/Draggable.svelte +49 -27
  4. package/dist/components/drag-drop/Draggable.svelte.d.ts +2 -0
  5. package/dist/components/drag-drop/{Dropzone.svelte → DropZone.svelte} +147 -90
  6. package/dist/components/drag-drop/{Dropzone.svelte.d.ts → DropZone.svelte.d.ts} +5 -3
  7. package/dist/components/drag-drop/drag-state.svelte.d.ts +29 -5
  8. package/dist/components/drag-drop/drag-state.svelte.js +48 -17
  9. package/dist/components/drag-drop/index.d.ts +2 -0
  10. package/dist/components/drag-drop/index.js +3 -0
  11. package/dist/components/drag-drop/util.d.ts +32 -0
  12. package/dist/components/drag-drop/util.js +85 -0
  13. package/dist/components/tab-bar/HkTabBar.state.svelte.d.ts +4 -4
  14. package/dist/components/tab-bar/HkTabBar.svelte +3 -3
  15. package/dist/components/tab-bar/HkTabBar.svelte.d.ts +2 -2
  16. package/dist/components/tab-bar/HkTabBarSelector.state.svelte.d.ts +3 -3
  17. package/dist/components/tab-bar/HkTabBarSelector.svelte +3 -3
  18. package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +2 -2
  19. package/dist/components/tab-bar/index.d.ts +1 -0
  20. package/dist/components/tab-bar/typedef.d.ts +3 -1
  21. package/dist/components/tab-bar/typedef.js +3 -0
  22. package/dist/themes/hkdev/components/drag-drop/draggable.css +10 -1
  23. package/dist/typedef/context.d.ts +3 -0
  24. package/dist/typedef/context.js +6 -0
  25. package/dist/typedef/index.d.ts +1 -0
  26. package/dist/typedef/index.js +1 -0
  27. package/dist/util/svelte/state-context/index.d.ts +2 -1
  28. package/dist/util/svelte/state-context/index.js +46 -12
  29. package/dist/widgets/game-box/GameBox.svelte +1 -0
  30. package/dist/widgets/hk-app-layout/HkAppLayout.state.svelte.d.ts +3 -3
  31. package/dist/widgets/image-box/ImageBox.svelte +2 -4
  32. package/package.json +3 -1
  33. package/dist/components/drag-drop/Dropzone.svelte__ +0 -282
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Find the source draggable element from an event
3
+ *
4
+ * @param {DragEvent} event
5
+ * @returns {HTMLElement|null}
6
+ */
7
+ export function findDraggableSource(event: DragEvent): HTMLElement | null;
8
+ /**
9
+ * Get draggable ID from an event, if available
10
+ * @param {DragEvent} event
11
+ * @returns {string|null}
12
+ */
13
+ export function getDraggableIdFromEvent(event: DragEvent): string | null;
14
+ /**
15
+ * Process a drop event with the provided data and handlers
16
+ * @param {DragEvent} event
17
+ * @param {any} data The drag data
18
+ * @param {Object} options
19
+ * @param {Function} options.onDropStart Optional drop start handler
20
+ * @param {Function} options.onDrop Main drop handler
21
+ * @param {Function} options.onDropEnd Optional drop end handler
22
+ * @param {string} options.zone The drop zone identifier
23
+ * @param {Function} options.setState Function to update component state
24
+ * @returns {Promise<boolean>} Success status
25
+ */
26
+ export function processDropWithData(event: DragEvent, data: any, { onDropStart, onDrop, onDropEnd, zone, setState }: {
27
+ onDropStart: Function;
28
+ onDrop: Function;
29
+ onDropEnd: Function;
30
+ zone: string;
31
+ setState: Function;
32
+ }): Promise<boolean>;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Find the source draggable element from an event
3
+ *
4
+ * @param {DragEvent} event
5
+ * @returns {HTMLElement|null}
6
+ */
7
+ export function findDraggableSource(event) {
8
+ const target = /** @type {Element|EventTarget|null} */ (event.target);
9
+
10
+ if (!(target instanceof Element)) {
11
+ return null;
12
+ }
13
+
14
+ let element = /** @type {Element|null} */ (target);
15
+
16
+ // Walk up the DOM tree
17
+ while (element !== null && element !== document.body) {
18
+ if (element.hasAttribute('data-id')) {
19
+ // Return as HTMLElement if needed
20
+ return /** @type {HTMLElement} */ (element);
21
+ }
22
+
23
+ element = element.parentElement;
24
+ }
25
+
26
+ return null;
27
+ }
28
+
29
+ /**
30
+ * Get draggable ID from an event, if available
31
+ * @param {DragEvent} event
32
+ * @returns {string|null}
33
+ */
34
+ export function getDraggableIdFromEvent(event) {
35
+ const element = findDraggableSource(event);
36
+ return element ? element.getAttribute('data-id') : null;
37
+ }
38
+
39
+ /**
40
+ * Process a drop event with the provided data and handlers
41
+ * @param {DragEvent} event
42
+ * @param {any} data The drag data
43
+ * @param {Object} options
44
+ * @param {Function} options.onDropStart Optional drop start handler
45
+ * @param {Function} options.onDrop Main drop handler
46
+ * @param {Function} options.onDropEnd Optional drop end handler
47
+ * @param {string} options.zone The drop zone identifier
48
+ * @param {Function} options.setState Function to update component state
49
+ * @returns {Promise<boolean>} Success status
50
+ */
51
+ export async function processDropWithData(event, data, {
52
+ onDropStart,
53
+ onDrop,
54
+ onDropEnd,
55
+ zone,
56
+ setState
57
+ }) {
58
+ try {
59
+ // Update state and notify listeners
60
+ setState('ACTIVE_DROP');
61
+ onDropStart?.({ event, zone, data });
62
+
63
+ // Call the onDrop handler
64
+ const dropResult = onDrop?.({
65
+ event,
66
+ zone,
67
+ item: data.item,
68
+ source: data.source,
69
+ metadata: data.metadata
70
+ });
71
+
72
+ // Handle async or sync results
73
+ await Promise.resolve(dropResult);
74
+
75
+ // Success path
76
+ setState('READY');
77
+ onDropEnd?.({ event, zone, data, success: true });
78
+ return true;
79
+ } catch (error) {
80
+ // Error path
81
+ setState('READY');
82
+ onDropEnd?.({ event, zone, data, success: false, error });
83
+ return false;
84
+ }
85
+ }
@@ -48,7 +48,7 @@ export class HkTabBarState {
48
48
  */
49
49
  linkTab(index: number, tabElement: HTMLElement): void;
50
50
  }
51
- export const createOrGetState: (instanceKey?: string | Symbol) => HkTabBarState;
52
- export const createState: (instanceKey?: string | Symbol) => HkTabBarState;
53
- export const getState: (instanceKey?: string | Symbol) => HkTabBarState;
54
- export type Tab = any;
51
+ export const createOrGetState: (contextKey: import("../../typedef/context.js").ContextKey) => HkTabBarState;
52
+ export const createState: (contextKey: import("../../typedef/context.js").ContextKey) => HkTabBarState;
53
+ export const getState: (contextKey: import("../../typedef/context.js").ContextKey) => HkTabBarState;
54
+ export type Tab = import("./typedef.js").Tab;
@@ -19,7 +19,7 @@
19
19
  * margin?: string,
20
20
  * classes?: string,
21
21
  * style?: string,
22
- * instanceKey?: Symbol | string,
22
+ * contextKey?: Symbol | string,
23
23
  * children: import('svelte').Snippet,
24
24
  * onmount?: function,
25
25
  * domElem?: HTMLElement
@@ -39,7 +39,7 @@
39
39
  style,
40
40
 
41
41
  // State
42
- instanceKey,
42
+ contextKey,
43
43
 
44
44
  // Snippets
45
45
  children,
@@ -54,7 +54,7 @@
54
54
  ...attrs
55
55
  } = $props();
56
56
 
57
- createOrGetState(instanceKey);
57
+ createOrGetState(contextKey);
58
58
 
59
59
  //grid-cols-[repeat({cols},minmax(0,auto))]
60
60
  </script>
@@ -9,7 +9,7 @@ type HkTabBar = {
9
9
  margin?: string;
10
10
  classes?: string;
11
11
  style?: string;
12
- instanceKey?: string | Symbol;
12
+ contextKey?: string | Symbol;
13
13
  children: Snippet<[]>;
14
14
  onmount?: Function;
15
15
  domElem?: HTMLElement;
@@ -25,7 +25,7 @@ declare const HkTabBar: import("svelte").Component<{
25
25
  margin?: string;
26
26
  classes?: string;
27
27
  style?: string;
28
- instanceKey?: Symbol | string;
28
+ contextKey?: Symbol | string;
29
29
  children: import("svelte").Snippet;
30
30
  onmount?: Function;
31
31
  domElem?: HTMLElement;
@@ -14,6 +14,6 @@ export class HkTabBarSelectorState {
14
14
  tabBarState: any;
15
15
  #private;
16
16
  }
17
- export const createOrGetState: (instanceKey?: string | Symbol) => HkTabBarSelectorState;
18
- export const createState: (instanceKey?: string | Symbol) => HkTabBarSelectorState;
19
- export const getState: (instanceKey?: string | Symbol) => HkTabBarSelectorState;
17
+ export const createOrGetState: (contextKey: import("../../typedef/context.js").ContextKey) => HkTabBarSelectorState;
18
+ export const createState: (contextKey: import("../../typedef/context.js").ContextKey) => HkTabBarSelectorState;
19
+ export const getState: (contextKey: import("../../typedef/context.js").ContextKey) => HkTabBarSelectorState;
@@ -17,7 +17,7 @@
17
17
  * boxMargin?: string,
18
18
  * boxClasses?: string,
19
19
  * boxAttrs?: { [attr: string]: * },
20
- * instanceKey?: Symbol | string
20
+ * contextKey?: Symbol | string
21
21
  * } & { [attr: string]: any }}
22
22
  */
23
23
  let {
@@ -30,10 +30,10 @@
30
30
  boxClasses,
31
31
 
32
32
  // State
33
- instanceKey
33
+ contextKey
34
34
  } = $props();
35
35
 
36
- const selectorState = createOrGetState(instanceKey);
36
+ const selectorState = createOrGetState(contextKey);
37
37
  </script>
38
38
 
39
39
  <div
@@ -13,7 +13,7 @@ type HkTabBarSelector = {
13
13
  boxAttrs?: {
14
14
  [attr: string]: any;
15
15
  };
16
- instanceKey?: string | Symbol;
16
+ contextKey?: string | Symbol;
17
17
  } & {
18
18
  [attr: string]: any;
19
19
  }>): void;
@@ -30,7 +30,7 @@ declare const HkTabBarSelector: import("svelte").Component<{
30
30
  boxAttrs?: {
31
31
  [attr: string]: any;
32
32
  };
33
- instanceKey?: Symbol | string;
33
+ contextKey?: Symbol | string;
34
34
  } & {
35
35
  [attr: string]: any;
36
36
  }, {}, "">;
@@ -1,4 +1,5 @@
1
1
  export { default as HkTabBar } from "./HkTabBar.svelte";
2
2
  export { default as HkTabBarSelector } from "./HkTabBarSelector.svelte";
3
+ export * from "./typedef.js";
3
4
  export { createOrGetState as createOrGetTabBarState, createState as createTabBarState, getState as getTabBarState } from "./HkTabBar.state.svelte.js";
4
5
  export { createOrGetState as createOrGetTabBarSelectorState, createState as createTabBarSelectorState, getState as getTabBarSelectorState } from "./HkTabBarSelector.state.svelte.js";
@@ -1,4 +1,6 @@
1
- type Tab = {
1
+ declare const _default: {};
2
+ export default _default;
3
+ export type Tab = {
2
4
  icon: any;
3
5
  label?: string;
4
6
  route?: string;
@@ -6,3 +6,6 @@
6
6
  * @property {string} [route]
7
7
  * @property {string} [routePrefix]
8
8
  */
9
+
10
+
11
+ export default {};
@@ -1,12 +1,20 @@
1
1
  @define-mixin component-draggable {
2
2
  [data-component='draggable'] {
3
- cursor: move;
4
3
  user-select: none;
5
4
  transition:
6
5
  opacity 0.2s ease,
7
6
  transform 0.2s ease;
8
7
  }
9
8
 
9
+ [data-component='draggable']:not(.state-dragging):not(.state-drag-disabled) {
10
+ cursor: grab; /* Open hand when hovering draggable items */
11
+ }
12
+
13
+
14
+ /*[data-component='draggable']:active {
15
+ cursor: grabbing;
16
+ }*/
17
+
10
18
  /* State-based styling using state classes */
11
19
  [data-component='draggable'].state-idle {
12
20
  opacity: 1;
@@ -16,6 +24,7 @@
16
24
  [data-component='draggable'].state-dragging {
17
25
  opacity: 0.5;
18
26
  transform: scale(0.95);
27
+ cursor: grabbing;
19
28
  }
20
29
 
21
30
  [data-component='draggable'].state-drag-preview {
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+ export default _default;
3
+ export type ContextKey = Symbol | "default";
@@ -0,0 +1,6 @@
1
+
2
+ /**
3
+ * @typedef {Symbol|'default'} ContextKey
4
+ */
5
+
6
+ export default {};
@@ -1,3 +1,4 @@
1
+ export * from "./context.js";
1
2
  export * from "./drag.js";
2
3
  export * from "./drop.js";
3
4
  export * from "./image.js";
@@ -1,3 +1,4 @@
1
+ export * from './context.js';
1
2
  export * from './drag.js';
2
3
  export * from './drop.js';
3
4
  export * from './image.js';
@@ -14,4 +14,5 @@
14
14
  * getState
15
15
  * ]}
16
16
  */
17
- export function defineStateContext<T>(State: new () => T): [(instanceKey?: string | Symbol) => T, (instanceKey?: string | Symbol) => T, (instanceKey?: string | Symbol) => T];
17
+ export function defineStateContext<T>(State: new () => T): [(contextKey: import("../../../typedef").ContextKey) => T, (contextKey: import("../../../typedef").ContextKey) => T, (contextKey: import("../../../typedef").ContextKey) => T];
18
+ export const DEFAULT_CONTEXT_KEY: "default";
@@ -1,5 +1,7 @@
1
1
  import { setContext, getContext, hasContext } from 'svelte';
2
2
 
3
+ export const DEFAULT_CONTEXT_KEY = 'default';
4
+
3
5
  /* ----------------------------------------------------------- Create and Get */
4
6
 
5
7
  /**
@@ -19,26 +21,58 @@ import { setContext, getContext, hasContext } from 'svelte';
19
21
  * ]}
20
22
  */
21
23
  export function defineStateContext(State) {
22
- const description = State.name;
24
+ const stateName = State.name;
25
+
26
+ const sharedKey = Symbol(stateName);
27
+
28
+ // console.debug(`Creating state context for ${stateName}`, { sharedKey });
29
+
30
+ /**
31
+ * Internal function to get the supplied key or the shared key
32
+ *
33
+ * @param {import('../../../typedef').ContextKey} contextKey
34
+ *
35
+ * @returns {Symbol} key
36
+ */
37
+ function getKey(contextKey) {
38
+ if (typeof contextKey === 'symbol') {
39
+ return contextKey;
40
+ }
23
41
 
24
- const sharedKey = Symbol(description);
42
+ if (
43
+ contextKey === undefined ||
44
+ contextKey === null ||
45
+ contextKey === DEFAULT_CONTEXT_KEY
46
+ ) {
47
+ return sharedKey;
48
+ }
49
+
50
+ throw new Error(
51
+ `Invalid contextKey (use a Symbol or DEFAULT_CONTEXT_KEY)`
52
+ );
53
+ }
25
54
 
26
55
  /**
27
56
  * Create component state
28
57
  *
29
- * @param {string|Symbol} [instanceKey]
58
+ * @param {import('../../../typedef').ContextKey} contextKey
30
59
  *
31
60
  * @returns {T} state
32
61
  */
33
- function createState(instanceKey) {
34
- const key = instanceKey ?? sharedKey;
62
+ function createState(contextKey) {
63
+ const key = getKey(contextKey);
35
64
 
36
65
  // console.log('Create state', key);
66
+ // console.debug(`Creating new state for ${stateName}`, {
67
+ // key,
68
+ // contextKey,
69
+ // isDefaultKey: key === sharedKey
70
+ // });
37
71
 
38
72
  const state = new State();
39
73
 
40
74
  // @ts-ignore
41
- state._instanceKey = instanceKey;
75
+ state._contextKey = contextKey;
42
76
 
43
77
  return setContext(key, state);
44
78
  }
@@ -46,12 +80,12 @@ export function defineStateContext(State) {
46
80
  /**
47
81
  * Get component state or create a new state if it does not yet exist
48
82
  *
49
- * @param {string|Symbol} [instanceKey]
83
+ * @param {import('../../../typedef').ContextKey} contextKey
50
84
  *
51
85
  * @returns {T} state
52
86
  */
53
- function createOrGetState(instanceKey) {
54
- let key = instanceKey ?? sharedKey;
87
+ function createOrGetState(contextKey) {
88
+ let key = getKey(contextKey);
55
89
 
56
90
  if (!hasContext(key)) {
57
91
  return createState(key);
@@ -65,12 +99,12 @@ export function defineStateContext(State) {
65
99
  *
66
100
  * @throws Will throw an error if the state-context does not exist
67
101
  *
68
- * @param {string|Symbol} [instanceKey]
102
+ * @param {import('../../../typedef').ContextKey} contextKey
69
103
  *
70
104
  * @returns {T} state
71
105
  */
72
- function getState(instanceKey) {
73
- let key = instanceKey ?? sharedKey;
106
+ function getState(contextKey) {
107
+ let key = getKey(contextKey);
74
108
 
75
109
  if (!hasContext(key)) {
76
110
  throw new Error(`No state context found. Create one first`);
@@ -558,6 +558,7 @@
558
558
 
559
559
  <style>
560
560
  .center {
561
+ display: grid;
561
562
  height: 100lvh;
562
563
  display: grid;
563
564
  justify-items: center;
@@ -1,6 +1,6 @@
1
1
  export class AppLayoutState {
2
2
  landscapeOnSmallScreen: boolean;
3
3
  }
4
- export const createOrGetState: (instanceKey?: string | Symbol) => AppLayoutState;
5
- export const createState: (instanceKey?: string | Symbol) => AppLayoutState;
6
- export const getState: (instanceKey?: string | Symbol) => AppLayoutState;
4
+ export const createOrGetState: (contextKey: import("../../typedef").ContextKey) => AppLayoutState;
5
+ export const createState: (contextKey: import("../../typedef").ContextKey) => AppLayoutState;
6
+ export const getState: (contextKey: import("../../typedef").ContextKey) => AppLayoutState;
@@ -204,9 +204,7 @@
204
204
  height: 100%;
205
205
  max-width: 100%;
206
206
  max-height: 100%;
207
- -o-object-fit: var(--fit);
208
- object-fit: var(--fit);
209
- -o-object-position: var(--pos);
210
- object-position: var(--pos);
207
+ object-fit: var(--fit);
208
+ object-position: var(--pos);
211
209
  }
212
210
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.1.77",
3
+ "version": "0.1.79",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"
@@ -62,6 +62,7 @@
62
62
  "pino-pretty": "^13.0.0",
63
63
  "runed": "^0.23.0",
64
64
  "svelte": "^5.0.0",
65
+ "svelte-preprocess": "^6.0.3",
65
66
  "valibot": "^0.42.1",
66
67
  "zod": "^3.24.2"
67
68
  },
@@ -95,6 +96,7 @@
95
96
  "standardized-audio-context-mock": "^9.7.16",
96
97
  "svelte": "^5.20.5",
97
98
  "svelte-check": "^4.1.4",
99
+ "svelte-preprocess": "^6.0.3",
98
100
  "tailwindcss": "^3.4.17",
99
101
  "typescript": "^5.8.2",
100
102
  "vite": "^6.2.0",