svelte-multistyle-ui 0.0.1-alpha → 0.0.3-alpha

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/README.md CHANGED
@@ -84,7 +84,7 @@ A Svelte action for portaling content to `document.body`:
84
84
  The library exports the following components from `svelte-multistyle-ui`:
85
85
 
86
86
  - Actions: `Button`, `IconButton`, `FAB`, `ButtonGroup`, `DropdownMenu`, `Popover`
87
- - Form: `Input`, `Textarea`, `Select`, `MultiSelect`, `Checkbox`, `Radio`, `Toggle`, `Slider`, `FileUpload`, `DatePicker`
87
+ - Form: `Input`, `Textarea`, `Select`, `MultiSelect`, `Checkbox`, `Radio`, `Toggle`, `Slider`, `FileUpload`, `DatePicker`, `SortableList`
88
88
  - Layout: `Card`, `Divider`, `Tabs`, `Accordion`, `Modal`, `Drawer`, `CommandPalette`, `Row`, `Column`, `Grid`
89
89
  - Navigation: `Breadcrumb`, `Pagination`, `Stepper`
90
90
  - Data display: `Avatar`, `Chip`, `Tooltip`, `ProgressBar`, `Table`, `Spinner`, `Skeleton`, `Rating`
@@ -0,0 +1,128 @@
1
+ <script>
2
+ import { draggable, droppable } from '@thisux/sveltednd';
3
+ import "./sortablelist-styles.css";
4
+ import { defaults } from "../config.js";
5
+
6
+ let {
7
+ style: styleProp,
8
+ theme: themeProp,
9
+ items = $bindable([]),
10
+ onUpdate,
11
+ type = 'item',
12
+ direction = 'vertical',
13
+ children
14
+ } = $props();
15
+
16
+ const style = $derived(styleProp ?? defaults.style);
17
+ const theme = $derived(themeProp ?? defaults.theme);
18
+
19
+ const styleClass = $derived(`s-sortablelist-${style}`);
20
+ const themeClass = $derived(`theme-${theme}`);
21
+ const directionClass = $derived(direction === 'horizontal' ? 's-sortablelist-horizontal' : 's-sortablelist-vertical');
22
+
23
+ const handleSelector = '.dnd-handle';
24
+ const containerPrefix = $derived(`${type}:`);
25
+
26
+ function idKey(id) {
27
+ return String(id ?? '');
28
+ }
29
+
30
+ function containerFor(item) {
31
+ return `${type}:${idKey(item.id)}`;
32
+ }
33
+
34
+ function findIndexByContainer(container) {
35
+ if (!container || !container.startsWith(containerPrefix)) return -1;
36
+ const id = container.slice(containerPrefix.length);
37
+ return items.findIndex((i) => idKey(i.id) === id);
38
+ }
39
+
40
+ let consumedThisDrop = false;
41
+
42
+ function isolateEvents(node) {
43
+ function stopStart(e) {
44
+ e.stopPropagation();
45
+ }
46
+ function stopConsumedDrop(e) {
47
+ if (consumedThisDrop) {
48
+ e.stopPropagation();
49
+ consumedThisDrop = false;
50
+ }
51
+ }
52
+ node.addEventListener('pointerdown', stopStart);
53
+ node.addEventListener('dragstart', stopStart);
54
+ node.addEventListener('drop', stopConsumedDrop);
55
+ node.addEventListener('pointerdrop-on-container', stopConsumedDrop);
56
+ return {
57
+ destroy() {
58
+ node.removeEventListener('pointerdown', stopStart);
59
+ node.removeEventListener('dragstart', stopStart);
60
+ node.removeEventListener('drop', stopConsumedDrop);
61
+ node.removeEventListener('pointerdrop-on-container', stopConsumedDrop);
62
+ }
63
+ };
64
+ }
65
+
66
+ function handleDrop(state) {
67
+ const { sourceContainer, targetContainer, dropPosition } = state;
68
+
69
+ if (
70
+ !sourceContainer?.startsWith(containerPrefix) ||
71
+ !targetContainer?.startsWith(containerPrefix)
72
+ ) {
73
+ return;
74
+ }
75
+
76
+ const dragIndex = findIndexByContainer(sourceContainer);
77
+ let dropIndex = findIndexByContainer(targetContainer);
78
+ if (dragIndex === -1 || dropIndex === -1) return;
79
+
80
+ if (dropPosition === 'after') {
81
+ dropIndex++;
82
+ }
83
+
84
+ if (dragIndex < dropIndex) {
85
+ dropIndex--;
86
+ }
87
+
88
+ const next = [...items];
89
+ const [moved] = next.splice(dragIndex, 1);
90
+ next.splice(dropIndex, 0, moved);
91
+
92
+ consumedThisDrop = true;
93
+ items = next;
94
+ onUpdate?.(next);
95
+ }
96
+ </script>
97
+
98
+ <div class="s-sortablelist {directionClass} {styleClass} {themeClass}" use:isolateEvents>
99
+ {#each items as item, index (item.id)}
100
+ <div
101
+ use:droppable={{
102
+ container: containerFor(item),
103
+ direction,
104
+ callbacks: { onDrop: handleDrop }
105
+ }}
106
+ >
107
+ <div
108
+ class="s-sortablelist-item"
109
+ data-item-id={item.id}
110
+ data-container-type={type}
111
+ use:draggable={{ dragData: item, container: containerFor(item), handle: handleSelector }}
112
+ >
113
+ {#if children}
114
+ <button
115
+ type="button"
116
+ class="dnd-handle s-sortablelist-handle"
117
+ aria-label="Drag to reorder"
118
+ >
119
+ ⋮⋮
120
+ </button>
121
+ <div class="s-sortablelist-content">
122
+ {@render children(item, index)}
123
+ </div>
124
+ {/if}
125
+ </div>
126
+ </div>
127
+ {/each}
128
+ </div>
@@ -0,0 +1,23 @@
1
+ export default SortableList;
2
+ type SortableList = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const SortableList: import("svelte").Component<{
7
+ style: any;
8
+ theme: any;
9
+ items?: any[];
10
+ onUpdate: any;
11
+ type?: string;
12
+ direction?: string;
13
+ children: any;
14
+ }, {}, "items">;
15
+ type $$ComponentProps = {
16
+ style: any;
17
+ theme: any;
18
+ items?: any[];
19
+ onUpdate: any;
20
+ type?: string;
21
+ direction?: string;
22
+ children: any;
23
+ };
@@ -47,13 +47,17 @@ Chart.register(
47
47
  // Safety patch: ensure setLineDash always receives a valid array.
48
48
  // Chart.js v4 can pass undefined/null internal values that throw "cannot be
49
49
  // converted to a sequence" in some browser environments.
50
- const origSetLineDash = CanvasRenderingContext2D.prototype.setLineDash;
51
- CanvasRenderingContext2D.prototype.setLineDash = function (segments) {
52
- if (!segments || typeof segments !== "object" || typeof segments[Symbol.iterator] !== "function") {
53
- return origSetLineDash.call(this, []);
54
- }
55
- return origSetLineDash.call(this, segments);
56
- };
50
+ // Guarded so the module stays safe during SSR (CanvasRenderingContext2D is
51
+ // only available in the browser).
52
+ if (typeof CanvasRenderingContext2D !== "undefined") {
53
+ const origSetLineDash = CanvasRenderingContext2D.prototype.setLineDash;
54
+ CanvasRenderingContext2D.prototype.setLineDash = function (segments) {
55
+ if (!segments || typeof segments !== "object" || typeof segments[Symbol.iterator] !== "function") {
56
+ return origSetLineDash.call(this, []);
57
+ }
58
+ return origSetLineDash.call(this, segments);
59
+ };
60
+ }
57
61
 
58
62
  /**
59
63
  * Read theme tokens from a DOM element's computed style.
@@ -0,0 +1,149 @@
1
+ /* ===== BASE ===== */
2
+ .s-sortablelist {
3
+ display: flex;
4
+ gap: 8px;
5
+ }
6
+ .s-sortablelist-vertical {
7
+ flex-direction: column;
8
+ }
9
+ .s-sortablelist-horizontal {
10
+ flex-direction: row;
11
+ flex-wrap: wrap;
12
+ }
13
+ .s-sortablelist-item {
14
+ display: flex;
15
+ align-items: center;
16
+ gap: 12px;
17
+ padding: 10px 14px;
18
+ border-radius: var(--t-card-radius);
19
+ border: var(--t-border-width) solid var(--t-card-border-color);
20
+ background: var(--t-card-bg);
21
+ box-shadow: var(--t-shadow-sm);
22
+ transition: all 0.2s ease;
23
+ cursor: default;
24
+ }
25
+ .s-sortablelist-content {
26
+ flex: 1;
27
+ min-width: 0;
28
+ }
29
+ .s-sortablelist-handle {
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ padding: 0 4px;
34
+ margin: -4px 0;
35
+ align-self: stretch;
36
+ border: none;
37
+ background: transparent;
38
+ cursor: grab;
39
+ color: var(--t-text-hint);
40
+ font-size: 18px;
41
+ line-height: 1;
42
+ user-select: none;
43
+ touch-action: none;
44
+ }
45
+ .s-sortablelist-handle:active {
46
+ cursor: grabbing;
47
+ }
48
+ .s-sortablelist-handle:hover {
49
+ color: var(--t-text);
50
+ }
51
+
52
+ /* ===== STYLE OVERRIDES ===== */
53
+
54
+ /* Brutalist */
55
+ .s-sortablelist-brutalist .s-sortablelist-item {
56
+ border-radius: 0;
57
+ border-width: 3px;
58
+ border-color: var(--t-text);
59
+ box-shadow: 5px 5px 0 var(--t-text);
60
+ }
61
+
62
+ /* Pixel */
63
+ .s-sortablelist-pixel .s-sortablelist-item {
64
+ border-radius: 0;
65
+ border-width: 3px;
66
+ border-color: var(--t-primary);
67
+ box-shadow: 3px 3px 0 var(--t-primary);
68
+ image-rendering: pixelated;
69
+ }
70
+
71
+ /* Neon */
72
+ .s-sortablelist-neon .s-sortablelist-item {
73
+ box-shadow: 0 0 6px var(--t-primary), 0 0 12px color-mix(in srgb, var(--t-primary) 40%, transparent);
74
+ border-color: var(--t-primary);
75
+ }
76
+
77
+ /* Metro */
78
+ .s-sortablelist-metro .s-sortablelist-item {
79
+ border-radius: 0;
80
+ border-width: 0 0 2px 0;
81
+ box-shadow: none;
82
+ }
83
+
84
+ /* Bootstrap */
85
+ .s-sortablelist-bootstrap .s-sortablelist-item {
86
+ border-radius: 6px;
87
+ background: var(--t-card-bg);
88
+ border-color: var(--t-card-border-color);
89
+ box-shadow: var(--t-shadow-xs);
90
+ }
91
+
92
+ /* Cartoon */
93
+ .s-sortablelist-cartoon .s-sortablelist-item {
94
+ border-radius: 12px;
95
+ border-width: 2px;
96
+ border-color: var(--t-text);
97
+ box-shadow: 4px 4px 0 var(--t-primary);
98
+ }
99
+
100
+ /* Illustration */
101
+ .s-sortablelist-illustration .s-sortablelist-item {
102
+ border-radius: 16px;
103
+ border-width: 2px;
104
+ box-shadow: 3px 3px 0 var(--t-border);
105
+ }
106
+
107
+ /* Carbon */
108
+ .s-sortablelist-carbon .s-sortablelist-item {
109
+ border-radius: 0;
110
+ border-width: 1px;
111
+ box-shadow: none;
112
+ }
113
+
114
+ /* Liquid Glass */
115
+ .s-sortablelist-liquid-glass .s-sortablelist-item {
116
+ background: rgba(255, 255, 255, 0.08);
117
+ backdrop-filter: blur(12px);
118
+ border: 1px solid rgba(255, 255, 255, 0.15);
119
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
120
+ }
121
+
122
+ /* Legacy iOS */
123
+ .s-sortablelist-legacy-ios .s-sortablelist-item {
124
+ border-radius: 10px;
125
+ background: linear-gradient(180deg, #fff, #f5f5f5);
126
+ border: 1px solid #d1d1d1;
127
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
128
+ }
129
+ html.dark .s-sortablelist-legacy-ios .s-sortablelist-item {
130
+ background: linear-gradient(180deg, #2c2c2c, #1c1c1c);
131
+ border-color: #3a3a3a;
132
+ }
133
+
134
+ /* Material 3 */
135
+ .s-sortablelist-material3 .s-sortablelist-item {
136
+ border-radius: 28px;
137
+ box-shadow: var(--t-shadow-xs);
138
+ }
139
+
140
+ /* Fluent */
141
+ .s-sortablelist-fluent .s-sortablelist-item {
142
+ border-radius: 4px;
143
+ box-shadow: var(--t-shadow-xs);
144
+ }
145
+
146
+ /* Carbon */
147
+ .s-sortablelist-carbon .s-sortablelist-item {
148
+ border-radius: 0;
149
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { initMultistyleUI } from "./config.js";
2
2
  export { portal } from "./actions/portal.js";
3
+ export { default as SortableList } from "./components/SortableList.svelte";
3
4
  export { default as Input } from "./components/Input.svelte";
4
5
  export { default as Button } from "./components/Button.svelte";
5
6
  export { default as IconButton } from "./components/IconButton.svelte";
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { initMultistyleUI } from "./config.js";
5
5
  export { portal } from "./actions/portal.js";
6
6
 
7
7
  // Form Components
8
+ export { default as SortableList } from "./components/SortableList.svelte";
8
9
  export { default as Input } from "./components/Input.svelte";
9
10
  export { default as Button } from "./components/Button.svelte";
10
11
  export { default as IconButton } from "./components/IconButton.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-multistyle-ui",
3
- "version": "0.0.1-alpha",
3
+ "version": "0.0.3-alpha",
4
4
  "description": "A multi-style, multi-theme Svelte 5 component library with multiple design styles and multiple color schemes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -59,6 +59,7 @@
59
59
  "multi-style"
60
60
  ],
61
61
  "dependencies": {
62
+ "@thisux/sveltednd": "^0.4.1",
62
63
  "dayjs": "^1.11.21",
63
64
  "prismjs": "^1.30.0"
64
65
  }