@theaccessibleteam/a11y-feedback-svelte 2.0.0
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/dist/index.cjs +211 -0
- package/dist/index.d.cts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +201 -0
- package/package.json +50 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createA11yFeedbackStore: () => createA11yFeedbackStore,
|
|
24
|
+
useA11yAnnounce: () => useA11yAnnounce,
|
|
25
|
+
useA11yFeedback: () => useA11yFeedback,
|
|
26
|
+
useFeedbackConfig: () => useFeedbackConfig
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/useA11yFeedback.ts
|
|
31
|
+
var import_store = require("svelte/store");
|
|
32
|
+
var import_a11y_feedback = require("@theaccessibleteam/a11y-feedback");
|
|
33
|
+
function useA11yFeedback() {
|
|
34
|
+
const state = (0, import_store.writable)({
|
|
35
|
+
notifications: (0, import_a11y_feedback.getNotificationHistory)(),
|
|
36
|
+
unreadCount: (0, import_a11y_feedback.getUnreadCount)()
|
|
37
|
+
});
|
|
38
|
+
const updateState = () => {
|
|
39
|
+
state.set({
|
|
40
|
+
notifications: (0, import_a11y_feedback.getNotificationHistory)(),
|
|
41
|
+
unreadCount: (0, import_a11y_feedback.getUnreadCount)()
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
(0, import_a11y_feedback.onFeedback)("announced", updateState);
|
|
45
|
+
(0, import_a11y_feedback.onFeedback)("dismissed", updateState);
|
|
46
|
+
(0, import_a11y_feedback.onFeedback)("replaced", updateState);
|
|
47
|
+
return {
|
|
48
|
+
subscribe: state.subscribe,
|
|
49
|
+
notify: async (message, type, options) => {
|
|
50
|
+
const result = await (0, import_a11y_feedback.notify)({ message, type, options });
|
|
51
|
+
updateState();
|
|
52
|
+
return result;
|
|
53
|
+
},
|
|
54
|
+
success: async (message, options) => {
|
|
55
|
+
const result = await import_a11y_feedback.notify.success(message, options);
|
|
56
|
+
updateState();
|
|
57
|
+
return result;
|
|
58
|
+
},
|
|
59
|
+
error: async (message, options) => {
|
|
60
|
+
const result = await import_a11y_feedback.notify.error(message, options);
|
|
61
|
+
updateState();
|
|
62
|
+
return result;
|
|
63
|
+
},
|
|
64
|
+
warning: async (message, options) => {
|
|
65
|
+
const result = await import_a11y_feedback.notify.warning(message, options);
|
|
66
|
+
updateState();
|
|
67
|
+
return result;
|
|
68
|
+
},
|
|
69
|
+
info: async (message, options) => {
|
|
70
|
+
const result = await import_a11y_feedback.notify.info(message, options);
|
|
71
|
+
updateState();
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
loading: async (message, options) => {
|
|
75
|
+
const result = await import_a11y_feedback.notify.loading(message, options);
|
|
76
|
+
updateState();
|
|
77
|
+
return result;
|
|
78
|
+
},
|
|
79
|
+
dismiss: (id) => {
|
|
80
|
+
(0, import_a11y_feedback.dismissVisualFeedback)(id);
|
|
81
|
+
updateState();
|
|
82
|
+
},
|
|
83
|
+
dismissAll: () => {
|
|
84
|
+
(0, import_a11y_feedback.dismissAllVisualFeedback)();
|
|
85
|
+
updateState();
|
|
86
|
+
},
|
|
87
|
+
destroy: () => {
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/useA11yAnnounce.ts
|
|
93
|
+
var import_a11y_feedback2 = require("@theaccessibleteam/a11y-feedback");
|
|
94
|
+
function useA11yAnnounce() {
|
|
95
|
+
return {
|
|
96
|
+
success: async (message, options) => {
|
|
97
|
+
await import_a11y_feedback2.notify.success(message, options);
|
|
98
|
+
},
|
|
99
|
+
error: async (message, options) => {
|
|
100
|
+
await import_a11y_feedback2.notify.error(message, options);
|
|
101
|
+
},
|
|
102
|
+
warning: async (message, options) => {
|
|
103
|
+
await import_a11y_feedback2.notify.warning(message, options);
|
|
104
|
+
},
|
|
105
|
+
info: async (message, options) => {
|
|
106
|
+
await import_a11y_feedback2.notify.info(message, options);
|
|
107
|
+
},
|
|
108
|
+
loading: async (message, options) => {
|
|
109
|
+
await import_a11y_feedback2.notify.loading(message, options);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/useFeedbackConfig.ts
|
|
115
|
+
var import_store2 = require("svelte/store");
|
|
116
|
+
var import_a11y_feedback3 = require("@theaccessibleteam/a11y-feedback");
|
|
117
|
+
function useFeedbackConfig() {
|
|
118
|
+
const store = (0, import_store2.writable)((0, import_a11y_feedback3.getConfig)());
|
|
119
|
+
return {
|
|
120
|
+
subscribe: store.subscribe,
|
|
121
|
+
update: (config) => {
|
|
122
|
+
(0, import_a11y_feedback3.configureFeedback)(config);
|
|
123
|
+
store.set((0, import_a11y_feedback3.getConfig)());
|
|
124
|
+
},
|
|
125
|
+
reset: () => {
|
|
126
|
+
(0, import_a11y_feedback3.resetConfig)();
|
|
127
|
+
store.set((0, import_a11y_feedback3.getConfig)());
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/store.ts
|
|
133
|
+
var import_store3 = require("svelte/store");
|
|
134
|
+
var import_a11y_feedback4 = require("@theaccessibleteam/a11y-feedback");
|
|
135
|
+
function createA11yFeedbackStore() {
|
|
136
|
+
const { subscribe, set, update } = (0, import_store3.writable)({
|
|
137
|
+
notifications: (0, import_a11y_feedback4.getNotificationHistory)(),
|
|
138
|
+
unreadCount: (0, import_a11y_feedback4.getUnreadCount)(),
|
|
139
|
+
config: (0, import_a11y_feedback4.getConfig)()
|
|
140
|
+
});
|
|
141
|
+
const handleFeedback = () => {
|
|
142
|
+
update((state) => ({
|
|
143
|
+
...state,
|
|
144
|
+
notifications: (0, import_a11y_feedback4.getNotificationHistory)(),
|
|
145
|
+
unreadCount: (0, import_a11y_feedback4.getUnreadCount)()
|
|
146
|
+
}));
|
|
147
|
+
};
|
|
148
|
+
(0, import_a11y_feedback4.onFeedback)("announced", handleFeedback);
|
|
149
|
+
(0, import_a11y_feedback4.onFeedback)("dismissed", handleFeedback);
|
|
150
|
+
return {
|
|
151
|
+
subscribe,
|
|
152
|
+
/**
|
|
153
|
+
* Send a notification
|
|
154
|
+
*/
|
|
155
|
+
notify: async (message, type, options) => {
|
|
156
|
+
return (0, import_a11y_feedback4.notify)({ message, type, options });
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* Send a success notification
|
|
160
|
+
*/
|
|
161
|
+
success: async (message, options) => {
|
|
162
|
+
return import_a11y_feedback4.notify.success(message, options);
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Send an error notification
|
|
166
|
+
*/
|
|
167
|
+
error: async (message, options) => {
|
|
168
|
+
return import_a11y_feedback4.notify.error(message, options);
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* Send a warning notification
|
|
172
|
+
*/
|
|
173
|
+
warning: async (message, options) => {
|
|
174
|
+
return import_a11y_feedback4.notify.warning(message, options);
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* Send an info notification
|
|
178
|
+
*/
|
|
179
|
+
info: async (message, options) => {
|
|
180
|
+
return import_a11y_feedback4.notify.info(message, options);
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* Send a loading notification
|
|
184
|
+
*/
|
|
185
|
+
loading: async (message, options) => {
|
|
186
|
+
return import_a11y_feedback4.notify.loading(message, options);
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* Update configuration
|
|
190
|
+
*/
|
|
191
|
+
configure: (config) => {
|
|
192
|
+
(0, import_a11y_feedback4.configureFeedback)(config);
|
|
193
|
+
update((state) => ({
|
|
194
|
+
...state,
|
|
195
|
+
config: (0, import_a11y_feedback4.getConfig)()
|
|
196
|
+
}));
|
|
197
|
+
},
|
|
198
|
+
/**
|
|
199
|
+
* Cleanup subscriptions
|
|
200
|
+
*/
|
|
201
|
+
destroy: () => {
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
206
|
+
0 && (module.exports = {
|
|
207
|
+
createA11yFeedbackStore,
|
|
208
|
+
useA11yAnnounce,
|
|
209
|
+
useA11yFeedback,
|
|
210
|
+
useFeedbackConfig
|
|
211
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as svelte_store from 'svelte/store';
|
|
2
|
+
import { Readable } from 'svelte/store';
|
|
3
|
+
import { FeedbackEvent, FeedbackType, FeedbackOptions, FeedbackConfig } from '@theaccessibleteam/a11y-feedback';
|
|
4
|
+
export { ConfirmOptions, FeedbackConfig, FeedbackEvent, FeedbackOptions, FeedbackType, NotificationAction, ProgressController, ProgressOptions, PromptOptions, RichContent } from '@theaccessibleteam/a11y-feedback';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Main hook for a11y-feedback in Svelte
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A11y Feedback store interface
|
|
12
|
+
*/
|
|
13
|
+
interface A11yFeedbackStore extends Readable<{
|
|
14
|
+
notifications: readonly FeedbackEvent[];
|
|
15
|
+
unreadCount: number;
|
|
16
|
+
}> {
|
|
17
|
+
notify: (message: string, type: FeedbackType, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
18
|
+
success: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
19
|
+
error: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
20
|
+
warning: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
21
|
+
info: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
22
|
+
loading: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
23
|
+
dismiss: (id: string) => void;
|
|
24
|
+
dismissAll: () => void;
|
|
25
|
+
destroy: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create the a11y-feedback store for Svelte
|
|
29
|
+
*/
|
|
30
|
+
declare function useA11yFeedback(): A11yFeedbackStore;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Simple announce hook for Svelte
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Announce functions interface
|
|
38
|
+
*/
|
|
39
|
+
interface A11yAnnounce {
|
|
40
|
+
success: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
41
|
+
error: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
42
|
+
warning: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
43
|
+
info: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
44
|
+
loading: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create simple announce functions for screen readers
|
|
48
|
+
*/
|
|
49
|
+
declare function useA11yAnnounce(): A11yAnnounce;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Configuration hook for Svelte
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Config store interface
|
|
57
|
+
*/
|
|
58
|
+
interface FeedbackConfigStore extends Readable<FeedbackConfig> {
|
|
59
|
+
update: (config: Partial<FeedbackConfig>) => void;
|
|
60
|
+
reset: () => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a config store for a11y-feedback
|
|
64
|
+
*/
|
|
65
|
+
declare function useFeedbackConfig(): FeedbackConfigStore;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A11y Feedback store state
|
|
69
|
+
*/
|
|
70
|
+
interface A11yFeedbackState {
|
|
71
|
+
notifications: readonly FeedbackEvent[];
|
|
72
|
+
unreadCount: number;
|
|
73
|
+
config: FeedbackConfig;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a Svelte store for a11y-feedback
|
|
77
|
+
*/
|
|
78
|
+
declare function createA11yFeedbackStore(): {
|
|
79
|
+
subscribe: (this: void, run: svelte_store.Subscriber<A11yFeedbackState>, invalidate?: svelte_store.Invalidator<A11yFeedbackState> | undefined) => svelte_store.Unsubscriber;
|
|
80
|
+
/**
|
|
81
|
+
* Send a notification
|
|
82
|
+
*/
|
|
83
|
+
notify: (message: string, type: FeedbackType, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
84
|
+
/**
|
|
85
|
+
* Send a success notification
|
|
86
|
+
*/
|
|
87
|
+
success: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
88
|
+
/**
|
|
89
|
+
* Send an error notification
|
|
90
|
+
*/
|
|
91
|
+
error: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
92
|
+
/**
|
|
93
|
+
* Send a warning notification
|
|
94
|
+
*/
|
|
95
|
+
warning: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
96
|
+
/**
|
|
97
|
+
* Send an info notification
|
|
98
|
+
*/
|
|
99
|
+
info: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
100
|
+
/**
|
|
101
|
+
* Send a loading notification
|
|
102
|
+
*/
|
|
103
|
+
loading: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
104
|
+
/**
|
|
105
|
+
* Update configuration
|
|
106
|
+
*/
|
|
107
|
+
configure: (config: Partial<FeedbackConfig>) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Cleanup subscriptions
|
|
110
|
+
*/
|
|
111
|
+
destroy: () => void;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { type A11yFeedbackStore, createA11yFeedbackStore, useA11yAnnounce, useA11yFeedback, useFeedbackConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as svelte_store from 'svelte/store';
|
|
2
|
+
import { Readable } from 'svelte/store';
|
|
3
|
+
import { FeedbackEvent, FeedbackType, FeedbackOptions, FeedbackConfig } from '@theaccessibleteam/a11y-feedback';
|
|
4
|
+
export { ConfirmOptions, FeedbackConfig, FeedbackEvent, FeedbackOptions, FeedbackType, NotificationAction, ProgressController, ProgressOptions, PromptOptions, RichContent } from '@theaccessibleteam/a11y-feedback';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Main hook for a11y-feedback in Svelte
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A11y Feedback store interface
|
|
12
|
+
*/
|
|
13
|
+
interface A11yFeedbackStore extends Readable<{
|
|
14
|
+
notifications: readonly FeedbackEvent[];
|
|
15
|
+
unreadCount: number;
|
|
16
|
+
}> {
|
|
17
|
+
notify: (message: string, type: FeedbackType, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
18
|
+
success: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
19
|
+
error: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
20
|
+
warning: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
21
|
+
info: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
22
|
+
loading: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
23
|
+
dismiss: (id: string) => void;
|
|
24
|
+
dismissAll: () => void;
|
|
25
|
+
destroy: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create the a11y-feedback store for Svelte
|
|
29
|
+
*/
|
|
30
|
+
declare function useA11yFeedback(): A11yFeedbackStore;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Simple announce hook for Svelte
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Announce functions interface
|
|
38
|
+
*/
|
|
39
|
+
interface A11yAnnounce {
|
|
40
|
+
success: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
41
|
+
error: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
42
|
+
warning: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
43
|
+
info: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
44
|
+
loading: (message: string, options?: FeedbackOptions) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create simple announce functions for screen readers
|
|
48
|
+
*/
|
|
49
|
+
declare function useA11yAnnounce(): A11yAnnounce;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Configuration hook for Svelte
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Config store interface
|
|
57
|
+
*/
|
|
58
|
+
interface FeedbackConfigStore extends Readable<FeedbackConfig> {
|
|
59
|
+
update: (config: Partial<FeedbackConfig>) => void;
|
|
60
|
+
reset: () => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a config store for a11y-feedback
|
|
64
|
+
*/
|
|
65
|
+
declare function useFeedbackConfig(): FeedbackConfigStore;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A11y Feedback store state
|
|
69
|
+
*/
|
|
70
|
+
interface A11yFeedbackState {
|
|
71
|
+
notifications: readonly FeedbackEvent[];
|
|
72
|
+
unreadCount: number;
|
|
73
|
+
config: FeedbackConfig;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a Svelte store for a11y-feedback
|
|
77
|
+
*/
|
|
78
|
+
declare function createA11yFeedbackStore(): {
|
|
79
|
+
subscribe: (this: void, run: svelte_store.Subscriber<A11yFeedbackState>, invalidate?: svelte_store.Invalidator<A11yFeedbackState> | undefined) => svelte_store.Unsubscriber;
|
|
80
|
+
/**
|
|
81
|
+
* Send a notification
|
|
82
|
+
*/
|
|
83
|
+
notify: (message: string, type: FeedbackType, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
84
|
+
/**
|
|
85
|
+
* Send a success notification
|
|
86
|
+
*/
|
|
87
|
+
success: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
88
|
+
/**
|
|
89
|
+
* Send an error notification
|
|
90
|
+
*/
|
|
91
|
+
error: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
92
|
+
/**
|
|
93
|
+
* Send a warning notification
|
|
94
|
+
*/
|
|
95
|
+
warning: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
96
|
+
/**
|
|
97
|
+
* Send an info notification
|
|
98
|
+
*/
|
|
99
|
+
info: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
100
|
+
/**
|
|
101
|
+
* Send a loading notification
|
|
102
|
+
*/
|
|
103
|
+
loading: (message: string, options?: FeedbackOptions) => Promise<FeedbackEvent>;
|
|
104
|
+
/**
|
|
105
|
+
* Update configuration
|
|
106
|
+
*/
|
|
107
|
+
configure: (config: Partial<FeedbackConfig>) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Cleanup subscriptions
|
|
110
|
+
*/
|
|
111
|
+
destroy: () => void;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { type A11yFeedbackStore, createA11yFeedbackStore, useA11yAnnounce, useA11yFeedback, useFeedbackConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/useA11yFeedback.ts
|
|
2
|
+
import { writable } from "svelte/store";
|
|
3
|
+
import {
|
|
4
|
+
notify,
|
|
5
|
+
dismissVisualFeedback,
|
|
6
|
+
dismissAllVisualFeedback,
|
|
7
|
+
getNotificationHistory,
|
|
8
|
+
getUnreadCount,
|
|
9
|
+
onFeedback
|
|
10
|
+
} from "@theaccessibleteam/a11y-feedback";
|
|
11
|
+
function useA11yFeedback() {
|
|
12
|
+
const state = writable({
|
|
13
|
+
notifications: getNotificationHistory(),
|
|
14
|
+
unreadCount: getUnreadCount()
|
|
15
|
+
});
|
|
16
|
+
const updateState = () => {
|
|
17
|
+
state.set({
|
|
18
|
+
notifications: getNotificationHistory(),
|
|
19
|
+
unreadCount: getUnreadCount()
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
onFeedback("announced", updateState);
|
|
23
|
+
onFeedback("dismissed", updateState);
|
|
24
|
+
onFeedback("replaced", updateState);
|
|
25
|
+
return {
|
|
26
|
+
subscribe: state.subscribe,
|
|
27
|
+
notify: async (message, type, options) => {
|
|
28
|
+
const result = await notify({ message, type, options });
|
|
29
|
+
updateState();
|
|
30
|
+
return result;
|
|
31
|
+
},
|
|
32
|
+
success: async (message, options) => {
|
|
33
|
+
const result = await notify.success(message, options);
|
|
34
|
+
updateState();
|
|
35
|
+
return result;
|
|
36
|
+
},
|
|
37
|
+
error: async (message, options) => {
|
|
38
|
+
const result = await notify.error(message, options);
|
|
39
|
+
updateState();
|
|
40
|
+
return result;
|
|
41
|
+
},
|
|
42
|
+
warning: async (message, options) => {
|
|
43
|
+
const result = await notify.warning(message, options);
|
|
44
|
+
updateState();
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
info: async (message, options) => {
|
|
48
|
+
const result = await notify.info(message, options);
|
|
49
|
+
updateState();
|
|
50
|
+
return result;
|
|
51
|
+
},
|
|
52
|
+
loading: async (message, options) => {
|
|
53
|
+
const result = await notify.loading(message, options);
|
|
54
|
+
updateState();
|
|
55
|
+
return result;
|
|
56
|
+
},
|
|
57
|
+
dismiss: (id) => {
|
|
58
|
+
dismissVisualFeedback(id);
|
|
59
|
+
updateState();
|
|
60
|
+
},
|
|
61
|
+
dismissAll: () => {
|
|
62
|
+
dismissAllVisualFeedback();
|
|
63
|
+
updateState();
|
|
64
|
+
},
|
|
65
|
+
destroy: () => {
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/useA11yAnnounce.ts
|
|
71
|
+
import {
|
|
72
|
+
notify as notify2
|
|
73
|
+
} from "@theaccessibleteam/a11y-feedback";
|
|
74
|
+
function useA11yAnnounce() {
|
|
75
|
+
return {
|
|
76
|
+
success: async (message, options) => {
|
|
77
|
+
await notify2.success(message, options);
|
|
78
|
+
},
|
|
79
|
+
error: async (message, options) => {
|
|
80
|
+
await notify2.error(message, options);
|
|
81
|
+
},
|
|
82
|
+
warning: async (message, options) => {
|
|
83
|
+
await notify2.warning(message, options);
|
|
84
|
+
},
|
|
85
|
+
info: async (message, options) => {
|
|
86
|
+
await notify2.info(message, options);
|
|
87
|
+
},
|
|
88
|
+
loading: async (message, options) => {
|
|
89
|
+
await notify2.loading(message, options);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/useFeedbackConfig.ts
|
|
95
|
+
import { writable as writable2 } from "svelte/store";
|
|
96
|
+
import {
|
|
97
|
+
configureFeedback,
|
|
98
|
+
getConfig,
|
|
99
|
+
resetConfig
|
|
100
|
+
} from "@theaccessibleteam/a11y-feedback";
|
|
101
|
+
function useFeedbackConfig() {
|
|
102
|
+
const store = writable2(getConfig());
|
|
103
|
+
return {
|
|
104
|
+
subscribe: store.subscribe,
|
|
105
|
+
update: (config) => {
|
|
106
|
+
configureFeedback(config);
|
|
107
|
+
store.set(getConfig());
|
|
108
|
+
},
|
|
109
|
+
reset: () => {
|
|
110
|
+
resetConfig();
|
|
111
|
+
store.set(getConfig());
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/store.ts
|
|
117
|
+
import { writable as writable3 } from "svelte/store";
|
|
118
|
+
import {
|
|
119
|
+
notify as notify3,
|
|
120
|
+
configureFeedback as configureFeedback2,
|
|
121
|
+
getConfig as getConfig2,
|
|
122
|
+
getNotificationHistory as getNotificationHistory2,
|
|
123
|
+
getUnreadCount as getUnreadCount2,
|
|
124
|
+
onFeedback as onFeedback2
|
|
125
|
+
} from "@theaccessibleteam/a11y-feedback";
|
|
126
|
+
function createA11yFeedbackStore() {
|
|
127
|
+
const { subscribe, set, update } = writable3({
|
|
128
|
+
notifications: getNotificationHistory2(),
|
|
129
|
+
unreadCount: getUnreadCount2(),
|
|
130
|
+
config: getConfig2()
|
|
131
|
+
});
|
|
132
|
+
const handleFeedback = () => {
|
|
133
|
+
update((state) => ({
|
|
134
|
+
...state,
|
|
135
|
+
notifications: getNotificationHistory2(),
|
|
136
|
+
unreadCount: getUnreadCount2()
|
|
137
|
+
}));
|
|
138
|
+
};
|
|
139
|
+
onFeedback2("announced", handleFeedback);
|
|
140
|
+
onFeedback2("dismissed", handleFeedback);
|
|
141
|
+
return {
|
|
142
|
+
subscribe,
|
|
143
|
+
/**
|
|
144
|
+
* Send a notification
|
|
145
|
+
*/
|
|
146
|
+
notify: async (message, type, options) => {
|
|
147
|
+
return notify3({ message, type, options });
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Send a success notification
|
|
151
|
+
*/
|
|
152
|
+
success: async (message, options) => {
|
|
153
|
+
return notify3.success(message, options);
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Send an error notification
|
|
157
|
+
*/
|
|
158
|
+
error: async (message, options) => {
|
|
159
|
+
return notify3.error(message, options);
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* Send a warning notification
|
|
163
|
+
*/
|
|
164
|
+
warning: async (message, options) => {
|
|
165
|
+
return notify3.warning(message, options);
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* Send an info notification
|
|
169
|
+
*/
|
|
170
|
+
info: async (message, options) => {
|
|
171
|
+
return notify3.info(message, options);
|
|
172
|
+
},
|
|
173
|
+
/**
|
|
174
|
+
* Send a loading notification
|
|
175
|
+
*/
|
|
176
|
+
loading: async (message, options) => {
|
|
177
|
+
return notify3.loading(message, options);
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Update configuration
|
|
181
|
+
*/
|
|
182
|
+
configure: (config) => {
|
|
183
|
+
configureFeedback2(config);
|
|
184
|
+
update((state) => ({
|
|
185
|
+
...state,
|
|
186
|
+
config: getConfig2()
|
|
187
|
+
}));
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* Cleanup subscriptions
|
|
191
|
+
*/
|
|
192
|
+
destroy: () => {
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
createA11yFeedbackStore,
|
|
198
|
+
useA11yAnnounce,
|
|
199
|
+
useA11yFeedback,
|
|
200
|
+
useFeedbackConfig
|
|
201
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theaccessibleteam/a11y-feedback-svelte",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Svelte bindings for a11y-feedback accessibility notification library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
21
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@theaccessibleteam/a11y-feedback": "^2.0.0",
|
|
25
|
+
"svelte": ">=3.0.0 || >=4.0.0 || >=5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"svelte": "^4.2.0",
|
|
29
|
+
"tsup": "^8.0.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"svelte",
|
|
34
|
+
"a11y",
|
|
35
|
+
"accessibility",
|
|
36
|
+
"notifications",
|
|
37
|
+
"screen-reader",
|
|
38
|
+
"aria"
|
|
39
|
+
],
|
|
40
|
+
"author": "The Accessible Team",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/WOLFIEEEE/a11y-feedback.git",
|
|
45
|
+
"directory": "packages/svelte"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|