simplesvelte 2.4.12 → 2.5.1

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
@@ -1,214 +1,214 @@
1
- # SimpleSvelte
2
-
3
- A lightweight collection of essential Svelte components and utilities for building modern web applications quickly and efficiently.
4
-
5
- ## Features
6
-
7
- - **Form Components**: Ready-to-use Input, Label, Select, and TextArea components with built-in validation support
8
- - **UI Components**: Modal and Grid components for common layout needs
9
- - **Popup System**: Easy-to-use Pop class for alerts, confirmations, and notifications (powered by SweetAlert2)
10
- - **Utility Functions**: FormHelper for form data processing, clickOutside action, and role helpers
11
- - **TypeScript Support**: Fully typed components and utilities
12
- - **Lightweight**: Minimal dependencies, maximum functionality
13
-
14
- ## Installation
15
-
16
- ```bash
17
- bun install simplesvelte
18
- ```
19
-
20
- ## CSS Setup
21
-
22
- SimpleSvelte requires CSS to be imported for proper styling. See [CSS_USAGE.md](./CSS_USAGE.md) for detailed instructions.
23
-
24
- **Quick setup:**
25
-
26
- ```css
27
- /* In your main CSS file */
28
- @import 'simplesvelte/styles.css';
29
- ```
30
-
31
- Or in JavaScript/TypeScript:
32
-
33
- ```typescript
34
- import 'simplesvelte/styles.css'
35
- ```
36
-
37
- ## Quick Start
38
-
39
- ```svelte
40
- <script>
41
- import { Input, Label, Modal, Pop } from 'simplesvelte'
42
-
43
- let showModal = false
44
- let inputValue = ''
45
-
46
- const handleConfirm = async () => {
47
- const result = await Pop.confirm('Delete item?', 'This action cannot be undone')
48
- if (result.isConfirmed) {
49
- // Handle deletion
50
- Pop.success('Deleted!', 'Your item has been deleted.')
51
- }
52
- }
53
- </script>
54
-
55
- <Label for="email">Email Address</Label>
56
- <Input name="email" type="email" bind:value={inputValue} placeholder="Enter your email" required />
57
-
58
- <button on:click={() => (showModal = true)}>Open Modal</button>
59
- <button on:click={handleConfirm}>Delete Item</button>
60
-
61
- <Modal bind:show={showModal}>
62
- <h2>Modal Content</h2>
63
- <p>Your modal content goes here!</p>
64
- </Modal>
65
- ```
66
-
67
- ## Components
68
-
69
- aa
70
-
71
- ### Form Components
72
-
73
- - **Input**: Versatile input component supporting text, email, password, number, date, and more
74
- - **Label**: Accessible label component with built-in styling
75
- - **Select**: Dropdown select component with custom styling and multi-select support
76
- - **TextArea**: Multi-line text input with auto-resize options
77
-
78
- ### UI Components
79
-
80
- - **Modal**: Flexible modal component with backdrop and keyboard controls
81
- - **Grid**: Responsive grid layout component
82
-
83
- ### Utilities
84
-
85
- - **Pop**: SweetAlert2-powered popup system for alerts, confirmations, and toasts
86
- - **FormHelper**: Utility class for processing FormData with type-safe getters
87
- - **clickOutside**: Svelte action for detecting clicks outside an element
88
- - **roleHelper**: Accessibility helper for ARIA roles
89
-
90
- ## Examples
91
-
92
- ### Select Component
93
-
94
- ```svelte
95
- <script>
96
- import { Select } from 'simplesvelte'
97
-
98
- let singleValue = ''
99
- let multipleValues = []
100
-
101
- const options = [
102
- { value: 'apple', label: 'Apple' },
103
- { value: 'banana', label: 'Banana' },
104
- { value: 'cherry', label: 'Cherry' },
105
- ]
106
- </script>
107
-
108
- <!-- Single Select -->
109
- <Select bind:value={singleValue} {options} label="Choose a fruit" name="fruit" required />
110
-
111
- <!-- Multi Select -->
112
- <Select bind:value={multipleValues} {options} label="Choose multiple fruits" name="fruits" multiple />
113
-
114
- <!-- Disabled Select -->
115
- <Select value={['apple', 'cherry']} {options} label="Pre-selected fruits" name="preset-fruits" multiple disabled />
116
- ```
117
-
118
- ### Using Pop for Notifications
119
-
120
- ```javascript
121
- import { Pop } from 'simplesvelte'
122
-
123
- // Success notification
124
- await Pop.success('Your changes have been saved.')
125
-
126
- // Error notification
127
- await Pop.error('Something went wrong.')
128
-
129
- // Confirmation dialog
130
- const result = await Pop.confirm('Delete this item?', 'This action cannot be undone')
131
- if (!res) {
132
- // User confirmed
133
- }
134
-
135
- // Custom toast
136
- Pop.toast('Updated!', 'success', 'top-end')
137
- ```
138
-
139
- ### Using FormHelper
140
-
141
- ```svelte
142
- <script>
143
- import { FormHelper } from 'simplesvelte'
144
-
145
- function parseFormData(FormData: FormData) {
146
- const fh = new FormHelper(formData)
147
- const data = {
148
- name: fh.string("name")
149
- optionalPhone: fh.nString("phone")
150
- }
151
-
152
-
153
- }
154
- </script>
155
-
156
- <form use:enhance>
157
- <!-- Your form inputs here -->
158
- </form>
159
- ```
160
-
161
- ### Using clickOutside Action
162
-
163
- ```svelte
164
- <script>
165
- import { clickOutside } from 'simplesvelte'
166
-
167
- let showDropdown = false
168
-
169
- function handleClickOutside() {
170
- showDropdown = false
171
- }
172
- </script>
173
-
174
- <div use:clickOutside={handleClickOutside}>
175
- <!-- Dropdown content -->
176
- </div>
177
- ```
178
-
179
- ## Development
180
-
181
- This library is built with SvelteKit and powered by Vite. To contribute or modify the library:
182
-
183
- ```bash
184
- # Clone and install dependencies
185
- git clone <your-repo>
186
- cd SimpleSvelte
187
- bun install
188
-
189
- # Start development server with showcase app
190
- bun run dev
191
-
192
- # or open in browser automatically
193
- bun run dev -- --open
194
- ```
195
-
196
- The `src/lib` directory contains all library components, while `src/routes` provides a showcase/preview app for testing components.
197
-
198
- ## Building
199
-
200
- To build your library:
201
-
202
- ```bash
203
- bun run package
204
- ```
205
-
206
- This will generate the distribution files in the `dist` directory.
207
-
208
- ## License
209
-
210
- MIT - see LICENSE file for details.
211
-
212
- ## Contributing
213
-
214
- Contributions are welcome! Please feel free to submit a Pull Request.
1
+ # SimpleSvelte
2
+
3
+ A lightweight collection of essential Svelte components and utilities for building modern web applications quickly and efficiently.
4
+
5
+ ## Features
6
+
7
+ - **Form Components**: Ready-to-use Input, Label, Select, and TextArea components with built-in validation support
8
+ - **UI Components**: Modal and Grid components for common layout needs
9
+ - **Popup System**: Easy-to-use Pop class for alerts, confirmations, and notifications (powered by SweetAlert2)
10
+ - **Utility Functions**: FormHelper for form data processing, clickOutside action, and role helpers
11
+ - **TypeScript Support**: Fully typed components and utilities
12
+ - **Lightweight**: Minimal dependencies, maximum functionality
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ bun install simplesvelte
18
+ ```
19
+
20
+ ## CSS Setup
21
+
22
+ SimpleSvelte requires CSS to be imported for proper styling. See [CSS_USAGE.md](./CSS_USAGE.md) for detailed instructions.
23
+
24
+ **Quick setup:**
25
+
26
+ ```css
27
+ /* In your main CSS file */
28
+ @import 'simplesvelte/styles.css';
29
+ ```
30
+
31
+ Or in JavaScript/TypeScript:
32
+
33
+ ```typescript
34
+ import 'simplesvelte/styles.css'
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ```svelte
40
+ <script>
41
+ import { Input, Label, Modal, Pop } from 'simplesvelte'
42
+
43
+ let showModal = false
44
+ let inputValue = ''
45
+
46
+ const handleConfirm = async () => {
47
+ const result = await Pop.confirm('Delete item?', 'This action cannot be undone')
48
+ if (result.isConfirmed) {
49
+ // Handle deletion
50
+ Pop.success('Deleted!', 'Your item has been deleted.')
51
+ }
52
+ }
53
+ </script>
54
+
55
+ <Label for="email">Email Address</Label>
56
+ <Input name="email" type="email" bind:value={inputValue} placeholder="Enter your email" required />
57
+
58
+ <button on:click={() => (showModal = true)}>Open Modal</button>
59
+ <button on:click={handleConfirm}>Delete Item</button>
60
+
61
+ <Modal bind:show={showModal}>
62
+ <h2>Modal Content</h2>
63
+ <p>Your modal content goes here!</p>
64
+ </Modal>
65
+ ```
66
+
67
+ ## Components
68
+
69
+ aa
70
+
71
+ ### Form Components
72
+
73
+ - **Input**: Versatile input component supporting text, email, password, number, date, and more
74
+ - **Label**: Accessible label component with built-in styling
75
+ - **Select**: Dropdown select component with custom styling and multi-select support
76
+ - **TextArea**: Multi-line text input with auto-resize options
77
+
78
+ ### UI Components
79
+
80
+ - **Modal**: Flexible modal component with backdrop and keyboard controls
81
+ - **Grid**: Responsive grid layout component
82
+
83
+ ### Utilities
84
+
85
+ - **Pop**: SweetAlert2-powered popup system for alerts, confirmations, and toasts
86
+ - **FormHelper**: Utility class for processing FormData with type-safe getters
87
+ - **clickOutside**: Svelte action for detecting clicks outside an element
88
+ - **roleHelper**: Accessibility helper for ARIA roles
89
+
90
+ ## Examples
91
+
92
+ ### Select Component
93
+
94
+ ```svelte
95
+ <script>
96
+ import { Select } from 'simplesvelte'
97
+
98
+ let singleValue = ''
99
+ let multipleValues = []
100
+
101
+ const options = [
102
+ { value: 'apple', label: 'Apple' },
103
+ { value: 'banana', label: 'Banana' },
104
+ { value: 'cherry', label: 'Cherry' },
105
+ ]
106
+ </script>
107
+
108
+ <!-- Single Select -->
109
+ <Select bind:value={singleValue} {options} label="Choose a fruit" name="fruit" required />
110
+
111
+ <!-- Multi Select -->
112
+ <Select bind:value={multipleValues} {options} label="Choose multiple fruits" name="fruits" multiple />
113
+
114
+ <!-- Disabled Select -->
115
+ <Select value={['apple', 'cherry']} {options} label="Pre-selected fruits" name="preset-fruits" multiple disabled />
116
+ ```
117
+
118
+ ### Using Pop for Notifications
119
+
120
+ ```javascript
121
+ import { Pop } from 'simplesvelte'
122
+
123
+ // Success notification
124
+ await Pop.success('Your changes have been saved.')
125
+
126
+ // Error notification
127
+ await Pop.error('Something went wrong.')
128
+
129
+ // Confirmation dialog
130
+ const result = await Pop.confirm('Delete this item?', 'This action cannot be undone')
131
+ if (!res) {
132
+ // User confirmed
133
+ }
134
+
135
+ // Custom toast
136
+ Pop.toast('Updated!', 'success', 'top-end')
137
+ ```
138
+
139
+ ### Using FormHelper
140
+
141
+ ```svelte
142
+ <script>
143
+ import { FormHelper } from 'simplesvelte'
144
+
145
+ function parseFormData(FormData: FormData) {
146
+ const fh = new FormHelper(formData)
147
+ const data = {
148
+ name: fh.string("name")
149
+ optionalPhone: fh.nString("phone")
150
+ }
151
+
152
+
153
+ }
154
+ </script>
155
+
156
+ <form use:enhance>
157
+ <!-- Your form inputs here -->
158
+ </form>
159
+ ```
160
+
161
+ ### Using clickOutside Action
162
+
163
+ ```svelte
164
+ <script>
165
+ import { clickOutside } from 'simplesvelte'
166
+
167
+ let showDropdown = false
168
+
169
+ function handleClickOutside() {
170
+ showDropdown = false
171
+ }
172
+ </script>
173
+
174
+ <div use:clickOutside={handleClickOutside}>
175
+ <!-- Dropdown content -->
176
+ </div>
177
+ ```
178
+
179
+ ## Development
180
+
181
+ This library is built with SvelteKit and powered by Vite. To contribute or modify the library:
182
+
183
+ ```bash
184
+ # Clone and install dependencies
185
+ git clone <your-repo>
186
+ cd SimpleSvelte
187
+ bun install
188
+
189
+ # Start development server with showcase app
190
+ bun run dev
191
+
192
+ # or open in browser automatically
193
+ bun run dev -- --open
194
+ ```
195
+
196
+ The `src/lib` directory contains all library components, while `src/routes` provides a showcase/preview app for testing components.
197
+
198
+ ## Building
199
+
200
+ To build your library:
201
+
202
+ ```bash
203
+ bun run package
204
+ ```
205
+
206
+ This will generate the distribution files in the `dist` directory.
207
+
208
+ ## License
209
+
210
+ MIT - see LICENSE file for details.
211
+
212
+ ## Contributing
213
+
214
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/dist/Grid.svelte CHANGED
@@ -14,15 +14,25 @@
14
14
 
15
15
  type Props = {
16
16
  gridEl?: HTMLDivElement
17
+ /** Bindable reference to the AG Grid API. Use `bind:gridApi` on the parent. */
18
+ gridApi?: GridApi
17
19
  gridData?: any[] // Replace with your actual data type
18
20
  gridOptions: GridOptions
21
+ /**
22
+ * localStorage key for automatic grid state persistence (filters, sorts, column widths).
23
+ * When set, state is saved on every change and restored on mount.
24
+ */
25
+ stateKey?: string
19
26
  class?: string
20
27
  }
21
- let { gridEl = $bindable(), gridData, gridOptions, class: gridClass = 'grow' }: Props = $props()
22
-
23
- // Register modules once
24
-
25
- let gridApi: GridApi | undefined
28
+ let {
29
+ gridEl = $bindable(),
30
+ gridApi = $bindable(),
31
+ gridData,
32
+ gridOptions,
33
+ stateKey,
34
+ class: gridClass = 'grow',
35
+ }: Props = $props()
26
36
  let initCheckInterval: ReturnType<typeof setInterval> | undefined
27
37
  let attemptCount = 0
28
38
 
@@ -49,10 +59,39 @@
49
59
  console.warn('⚠️ Grid: No license key found. Running in trial mode.')
50
60
  }
51
61
 
62
+ // Wrap onGridReady to expose the gridApi bindable and handle stateKey persistence,
63
+ // while still calling the user's own onGridReady callback if provided.
64
+ const userOnGridReady = gridOptions.onGridReady
65
+
66
+ // Load saved state upfront — must be in gridConfig.initialState, not applied post-init.
67
+ let savedState: object | undefined
68
+ if (stateKey) {
69
+ try {
70
+ const raw = localStorage.getItem(stateKey)
71
+ if (raw) savedState = JSON.parse(raw)
72
+ } catch {
73
+ /* ignore parse errors */
74
+ }
75
+ }
76
+
52
77
  const gridConfig = {
53
78
  ...gridOptions,
54
79
  theme: themeQuartz,
55
80
  ...(gridData !== undefined && { rowData: gridData }),
81
+ ...(savedState !== undefined && { initialState: savedState }),
82
+ onGridReady: (params: Parameters<NonNullable<GridOptions['onGridReady']>>[0]) => {
83
+ userOnGridReady?.(params)
84
+ gridApi = params.api
85
+ if (stateKey) {
86
+ params.api.addEventListener('stateUpdated', (e: any) => {
87
+ try {
88
+ localStorage.setItem(stateKey, JSON.stringify(e.state))
89
+ } catch {
90
+ /* ignore storage errors */
91
+ }
92
+ })
93
+ }
94
+ },
56
95
  }
57
96
 
58
97
  console.log('🎨 Grid: Creating grid instance...')
@@ -1,10 +1,17 @@
1
- import { type GridOptions } from 'ag-grid-enterprise';
1
+ import { type GridApi, type GridOptions } from 'ag-grid-enterprise';
2
2
  type Props = {
3
3
  gridEl?: HTMLDivElement;
4
+ /** Bindable reference to the AG Grid API. Use `bind:gridApi` on the parent. */
5
+ gridApi?: GridApi;
4
6
  gridData?: any[];
5
7
  gridOptions: GridOptions;
8
+ /**
9
+ * localStorage key for automatic grid state persistence (filters, sorts, column widths).
10
+ * When set, state is saved on every change and restored on mount.
11
+ */
12
+ stateKey?: string;
6
13
  class?: string;
7
14
  };
8
- declare const Grid: import("svelte").Component<Props, {}, "gridEl">;
15
+ declare const Grid: import("svelte").Component<Props, {}, "gridEl" | "gridApi">;
9
16
  type Grid = ReturnType<typeof Grid>;
10
17
  export default Grid;