@tensor_1/react 2.27.0 → 2.29.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/README.md +46 -0
- package/THIRD_PARTY_NOTICES.md +54 -0
- package/dist/components/Toast.d.ts +15 -3
- package/dist/components/Toast.js +153 -9
- package/dist/icons/Icon.d.ts +489 -0
- package/dist/icons/Icon.js +37 -0
- package/dist/icons/NamedIcon.d.ts +15 -0
- package/dist/icons/NamedIcon.js +9 -0
- package/dist/icons/components.d.ts +257 -0
- package/dist/icons/components.js +508 -0
- package/dist/icons/glyphs.d.ts +476 -0
- package/dist/icons/glyphs.js +704 -0
- package/dist/icons/types.d.ts +26 -0
- package/dist/icons/types.js +0 -0
- package/dist/icons.cjs +1310 -0
- package/dist/icons.d.cts +532 -0
- package/dist/icons.d.ts +6 -0
- package/dist/icons.js +9 -0
- package/dist/index.cjs +266 -7
- package/dist/index.d.cts +110 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/toast-store.d.ts +98 -0
- package/dist/toast-store.js +110 -0
- package/package.json +8 -2
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const DEFAULT_DURATION = {
|
|
2
|
+
success: 5e3,
|
|
3
|
+
info: 5e3,
|
|
4
|
+
default: 5e3,
|
|
5
|
+
warning: 8e3,
|
|
6
|
+
error: null,
|
|
7
|
+
loading: null
|
|
8
|
+
};
|
|
9
|
+
const TOAST_LEAVE_MS = 200;
|
|
10
|
+
let counter = 0;
|
|
11
|
+
function createToastStore() {
|
|
12
|
+
let records = [];
|
|
13
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
const emit = () => {
|
|
15
|
+
for (const listener of listeners) listener();
|
|
16
|
+
};
|
|
17
|
+
const set = (next) => {
|
|
18
|
+
records = next;
|
|
19
|
+
emit();
|
|
20
|
+
};
|
|
21
|
+
const show = (kind, message, options = {}) => {
|
|
22
|
+
const id = options.id ?? `uix-toast-${++counter}`;
|
|
23
|
+
const record = {
|
|
24
|
+
id,
|
|
25
|
+
kind,
|
|
26
|
+
message,
|
|
27
|
+
description: options.description,
|
|
28
|
+
duration: options.duration === void 0 ? DEFAULT_DURATION[kind] : options.duration,
|
|
29
|
+
action: options.action,
|
|
30
|
+
icon: options.icon,
|
|
31
|
+
onDismiss: options.onDismiss,
|
|
32
|
+
version: 0
|
|
33
|
+
};
|
|
34
|
+
const existing = records.find((r) => r.id === id);
|
|
35
|
+
set(existing ? records.map((r) => r.id === id ? { ...record, version: r.version + 1 } : r) : [...records, record]);
|
|
36
|
+
return id;
|
|
37
|
+
};
|
|
38
|
+
const update = (id, patch) => {
|
|
39
|
+
if (!records.some((r) => r.id === id)) return;
|
|
40
|
+
set(records.map((r) => {
|
|
41
|
+
if (r.id !== id) return r;
|
|
42
|
+
const kind = patch.kind ?? r.kind;
|
|
43
|
+
const duration = "duration" in patch ? patch.duration ?? null : patch.kind ? DEFAULT_DURATION[kind] : r.duration;
|
|
44
|
+
return { ...r, ...patch, kind, duration, leaving: false, version: r.version + 1 };
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
const dismiss = (id, reason = "programmatic") => {
|
|
48
|
+
const closing = records.filter((r) => (id === void 0 || r.id === id) && !r.leaving);
|
|
49
|
+
if (closing.length === 0) return;
|
|
50
|
+
const ids = new Set(closing.map((r) => r.id));
|
|
51
|
+
set(records.map((r) => ids.has(r.id) ? { ...r, leaving: true } : r));
|
|
52
|
+
for (const r of closing) r.onDismiss?.(reason);
|
|
53
|
+
const remove = () => set(records.filter((r) => !(ids.has(r.id) && r.leaving)));
|
|
54
|
+
if (typeof setTimeout === "function") setTimeout(remove, TOAST_LEAVE_MS);
|
|
55
|
+
else remove();
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
show,
|
|
59
|
+
update,
|
|
60
|
+
dismiss,
|
|
61
|
+
subscribe: (listener) => {
|
|
62
|
+
listeners.add(listener);
|
|
63
|
+
return () => {
|
|
64
|
+
listeners.delete(listener);
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
getSnapshot: () => records
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function createToastApi(store) {
|
|
71
|
+
const api = ((message, options) => store.show("default", message, options));
|
|
72
|
+
api.success = (message, options) => store.show("success", message, options);
|
|
73
|
+
api.error = (message, options) => store.show("error", message, options);
|
|
74
|
+
api.warning = (message, options) => store.show("warning", message, options);
|
|
75
|
+
api.info = (message, options) => store.show("info", message, options);
|
|
76
|
+
api.loading = (message, options) => store.show("loading", message, options);
|
|
77
|
+
api.dismiss = (id) => store.dismiss(id, "programmatic");
|
|
78
|
+
api.update = (id, patch) => store.update(id, patch);
|
|
79
|
+
api.promise = (promise, messages, options) => {
|
|
80
|
+
const id = store.show("loading", messages.loading, options);
|
|
81
|
+
promise.then(
|
|
82
|
+
(value) => store.update(id, { kind: "success", message: typeof messages.success === "function" ? messages.success(value) : messages.success }),
|
|
83
|
+
(error) => store.update(id, { kind: "error", message: typeof messages.error === "function" ? messages.error(error) : messages.error })
|
|
84
|
+
);
|
|
85
|
+
return promise;
|
|
86
|
+
};
|
|
87
|
+
api.undoable = (message, { onUndo, onCommit, undoLabel = "Undo", duration = 6e3, ...options }) => {
|
|
88
|
+
let undone = false;
|
|
89
|
+
return store.show("default", message, {
|
|
90
|
+
...options,
|
|
91
|
+
duration,
|
|
92
|
+
action: { label: undoLabel, onClick: () => {
|
|
93
|
+
undone = true;
|
|
94
|
+
onUndo();
|
|
95
|
+
} },
|
|
96
|
+
onDismiss: () => {
|
|
97
|
+
if (!undone) onCommit();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
api.store = store;
|
|
102
|
+
return api;
|
|
103
|
+
}
|
|
104
|
+
const toast = createToastApi(createToastStore());
|
|
105
|
+
export {
|
|
106
|
+
TOAST_LEAVE_MS,
|
|
107
|
+
createToastApi,
|
|
108
|
+
createToastStore,
|
|
109
|
+
toast
|
|
110
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tensor_1/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.29.0",
|
|
4
4
|
"description": "Thin React wrappers over the UIx v2 CSS component library.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"directory": "packages/react"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"dist"
|
|
14
|
+
"dist",
|
|
15
|
+
"THIRD_PARTY_NOTICES.md"
|
|
15
16
|
],
|
|
16
17
|
"publishConfig": {
|
|
17
18
|
"access": "public"
|
|
@@ -46,6 +47,11 @@
|
|
|
46
47
|
"types": "./dist/emoji.d.ts",
|
|
47
48
|
"import": "./dist/emoji.js",
|
|
48
49
|
"require": "./dist/emoji.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./icons": {
|
|
52
|
+
"types": "./dist/icons.d.ts",
|
|
53
|
+
"import": "./dist/icons.js",
|
|
54
|
+
"require": "./dist/icons.cjs"
|
|
49
55
|
}
|
|
50
56
|
},
|
|
51
57
|
"scripts": {
|