flash-notifications 0.0.24 → 0.0.26
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/build/container/index.d.ts +6 -0
- package/build/container/index.d.ts.map +1 -1
- package/build/container/index.js +55 -19
- package/build/container/index.js.map +1 -1
- package/build/container/notification.js +1 -1
- package/build/container/notification.js.map +1 -1
- package/build/flash-notifications.d.ts +30 -5
- package/build/flash-notifications.d.ts.map +1 -1
- package/build/flash-notifications.js +32 -6
- package/build/flash-notifications.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -2
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/container/index.jsx +57 -20
- package/src/container/notification.jsx +1 -1
- package/src/flash-notifications.js +33 -6
- package/src/index.js +4 -2
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
declare const _default: React.MemoExoticComponent<any>;
|
|
2
2
|
export default _default;
|
|
3
|
+
export type NotificationObjectType = {
|
|
4
|
+
count: number;
|
|
5
|
+
message: string;
|
|
6
|
+
title: string;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
3
9
|
import React from "react";
|
|
4
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;;WAiBc,MAAM;aACN,MAAM;WACN,MAAM;UACN,MAAM;;kBAf0B,OAAO"}
|
package/build/container/index.js
CHANGED
|
@@ -1,71 +1,107 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
import { digg } from "diggerize";
|
|
2
3
|
import PropTypes from "prop-types";
|
|
3
4
|
import propTypesExact from "prop-types-exact";
|
|
4
5
|
import React, { memo, useEffect, useMemo } from "react";
|
|
5
|
-
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
|
|
6
|
-
import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint";
|
|
7
|
-
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter";
|
|
6
|
+
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
7
|
+
import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint.js";
|
|
8
|
+
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter.js";
|
|
8
9
|
import useEnvSense from "env-sense/src/use-env-sense.js";
|
|
9
10
|
import { View } from "react-native";
|
|
10
|
-
import events from "../events";
|
|
11
|
+
import events from "../events.js";
|
|
11
12
|
import Notification from "./notification";
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} NotificationObjectType
|
|
15
|
+
* @property {number} count
|
|
16
|
+
* @property {string} message
|
|
17
|
+
* @property {string} title
|
|
18
|
+
* @property {string} type
|
|
19
|
+
*/
|
|
12
20
|
export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
|
|
13
21
|
static propTypes = propTypesExact({
|
|
14
22
|
insets: PropTypes.object
|
|
15
23
|
});
|
|
24
|
+
/** @type {number[]} */
|
|
16
25
|
timeouts = [];
|
|
17
26
|
setup() {
|
|
27
|
+
// @ts-expect-error
|
|
18
28
|
this.useStates({
|
|
19
29
|
count: 0,
|
|
20
30
|
notifications: []
|
|
21
31
|
});
|
|
22
|
-
useEventEmitter(events, "pushNotification", this.
|
|
32
|
+
useEventEmitter(events, "pushNotification", this.onPushNotification);
|
|
23
33
|
useEffect(() => {
|
|
24
34
|
return () => {
|
|
25
|
-
for (const timeout of this.
|
|
35
|
+
for (const timeout of this.timeouts) {
|
|
26
36
|
clearTimeout(timeout);
|
|
27
37
|
}
|
|
28
38
|
};
|
|
29
39
|
}, []);
|
|
30
40
|
}
|
|
31
41
|
render() {
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
const { notifications } = this.s;
|
|
44
|
+
// @ts-expect-error
|
|
32
45
|
const insets = this.props.insets || {};
|
|
33
46
|
const { smDown, mdUp } = useBreakpoint();
|
|
34
47
|
const { isNative } = useEnvSense();
|
|
35
48
|
const viewStyle = useMemo(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
let top = 20;
|
|
50
|
+
let right = 0;
|
|
51
|
+
let left = undefined;
|
|
52
|
+
if (insets.top)
|
|
53
|
+
top += insets.top;
|
|
54
|
+
if (insets.right)
|
|
55
|
+
right += insets.right;
|
|
43
56
|
if (smDown) {
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
left = 20;
|
|
58
|
+
if (insets.left)
|
|
59
|
+
left += insets.left;
|
|
60
|
+
right += 20;
|
|
46
61
|
}
|
|
47
62
|
else if (mdUp) {
|
|
48
|
-
|
|
63
|
+
right += 20;
|
|
49
64
|
}
|
|
65
|
+
const style = {
|
|
66
|
+
position: isNative ? "absolute" : "fixed",
|
|
67
|
+
top,
|
|
68
|
+
right,
|
|
69
|
+
left,
|
|
70
|
+
zIndex: 99999
|
|
71
|
+
};
|
|
50
72
|
return style;
|
|
51
|
-
}, [isNative, smDown, mdUp, insets.top, insets.right, insets.
|
|
52
|
-
return (React.createElement(View
|
|
73
|
+
}, [isNative, smDown, mdUp, insets.top, insets.right, insets.left]);
|
|
74
|
+
return (React.createElement(View
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
, {
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
dataSet: this.rootViewDataSet ||= { component: "flash-notifications-container" },
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
style: viewStyle, testID: "flash-notificaitons/container" }, notifications.map((notification) => React.createElement(Notification, { count: notification.count, key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.onRemovedClicked, title: notification.title, type: notification.type }))));
|
|
53
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* @param {NotificationObjectType} detail
|
|
84
|
+
* @returns {void}
|
|
85
|
+
*/
|
|
54
86
|
onPushNotification = (detail) => {
|
|
87
|
+
// @ts-expect-error
|
|
55
88
|
const count = this.s.count + 1;
|
|
56
89
|
const timeout = setTimeout(() => this.removeNotification(count), 4000);
|
|
57
|
-
this.
|
|
90
|
+
this.timeouts.push(timeout);
|
|
58
91
|
const notification = {
|
|
59
92
|
count,
|
|
60
93
|
message: digg(detail, "message"),
|
|
61
94
|
title: digg(detail, "title"),
|
|
62
95
|
type: digg(detail, "type")
|
|
63
96
|
};
|
|
97
|
+
// @ts-expect-error
|
|
64
98
|
this.setState({ count, notifications: this.s.notifications.concat([notification]) });
|
|
65
99
|
};
|
|
66
100
|
onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"));
|
|
67
101
|
removeNotification = (count) => {
|
|
102
|
+
// @ts-expect-error
|
|
68
103
|
this.setState({
|
|
104
|
+
// @ts-expect-error
|
|
69
105
|
notifications: this.s.notifications.filter((notification) => notification.count != count)
|
|
70
106
|
});
|
|
71
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,E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AAC,QAAQ,CAAC;YACZ,mBAAmB;YACnB,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC1F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["// @ts-check\n\nimport {digg} from \"diggerize\"\nimport PropTypes from \"prop-types\"\nimport propTypesExact from \"prop-types-exact\"\nimport React, {memo, useEffect, useMemo} from \"react\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport useBreakpoint from \"@kaspernj/api-maker/build/use-breakpoint.js\"\nimport useEventEmitter from \"@kaspernj/api-maker/build/use-event-emitter.js\"\nimport useEnvSense from \"env-sense/src/use-env-sense.js\"\nimport {View} from \"react-native\"\n\nimport events from \"../events.js\"\nimport Notification from \"./notification\"\n\n/**\n * @typedef {object} NotificationObjectType\n * @property {number} count\n * @property {string} message\n * @property {string} title\n * @property {string} type\n */\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n static propTypes = propTypesExact({\n insets: PropTypes.object\n })\n\n /** @type {number[]} */\n timeouts = []\n\n setup() {\n // @ts-expect-error\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventEmitter(events, \"pushNotification\", this.onPushNotification)\n useEffect(() => {\n return () => {\n for (const timeout of this.timeouts) {\n clearTimeout(timeout)\n }\n }\n }, [])\n }\n\n render() {\n // @ts-expect-error\n const {notifications} = this.s\n\n // @ts-expect-error\n const insets = this.props.insets || {}\n\n const {smDown, mdUp} = useBreakpoint()\n const {isNative} = useEnvSense()\n\n const viewStyle = useMemo(() => {\n let top = 20\n let right = 0\n let left = undefined\n\n if (insets.top) top += insets.top\n if (insets.right) right += insets.right\n\n if (smDown) {\n left = 20\n\n if (insets.left) left += insets.left\n\n right += 20\n } else if (mdUp) {\n right += 20\n }\n\n const style = {\n position: isNative ? \"absolute\" : \"fixed\",\n top,\n right,\n left,\n zIndex: 99999\n }\n\n return style\n }, [isNative, smDown, mdUp, insets.top, insets.right, insets.left])\n\n return (\n <View\n // @ts-expect-error\n dataSet={this.rootViewDataSet ||= {component: \"flash-notifications-container\"}}\n // @ts-expect-error\n style={viewStyle}\n testID=\"flash-notificaitons/container\"\n >\n {notifications.map((notification) =>\n <Notification\n count={notification.count}\n key={`notification-${notification.count}`}\n message={notification.message}\n notification={notification}\n onRemovedClicked={this.onRemovedClicked}\n title={notification.title}\n type={notification.type}\n />\n )}\n </View>\n )\n }\n\n /**\n * @param {NotificationObjectType} detail\n * @returns {void}\n */\n onPushNotification = (detail) => {\n // @ts-expect-error\n const count = this.s.count + 1\n const timeout = setTimeout(() => this.removeNotification(count), 4000)\n\n this.timeouts.push(timeout)\n\n const notification = {\n count,\n message: digg(detail, \"message\"),\n title: digg(detail, \"title\"),\n type: digg(detail, \"type\")\n }\n\n // @ts-expect-error\n this.setState({count, notifications: this.s.notifications.concat([notification])})\n }\n\n onRemovedClicked = (notification) => this.removeNotification(digg(notification, \"count\"))\n\n removeNotification = (count) => {\n // @ts-expect-error\n this.setState({\n // @ts-expect-error\n notifications: this.s.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
|
|
@@ -3,7 +3,7 @@ import PropTypes from "prop-types";
|
|
|
3
3
|
import PropTypesExact from "prop-types-exact";
|
|
4
4
|
import React, { memo, useMemo } from "react";
|
|
5
5
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
6
|
-
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
|
|
6
|
+
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
7
7
|
import useStyles from "@kaspernj/api-maker/build/use-styles.js";
|
|
8
8
|
const styles = StyleSheet.create({
|
|
9
9
|
view: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mapp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GAAG,EAAE,CAAC,CAAC;YACL,KAAK,EAAE,UAAU,CAAC,kCAAkC,EAAE,SAAS,CAAC;YAChE,IAAI,EAAE,QAAQ;YACd,IAAI;SACL,CAAC,EACF,CAAC,SAAS,EAAE,IAAI,CAAC,CAClB,CAAA;QAED,OAAO,CACL,oBAAC,SAAS,IAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,gBAAgB;YACrE,oBAAC,IAAI,IAAC,KAAK,EAAE,UAAU;gBACrB,oBAAC,IAAI,IAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS;oBACtD,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,oCAAoC,KAAK,QAAQ,IACrF,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,IAAC,OAAO,EAAE,kBAAkB;oBAC/B,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,oCAAoC,KAAK,UAAU,IACzF,OAAO,CACH,CACF,CACF,CACG,CACb,CAAA;IACH,CAAC;IAED,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;CACtE,CAAC,CAAC,CAAA","sourcesContent":["import classNames from \"classnames\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\nimport React, {memo, useMemo} from \"react\"\nimport {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport useStyles from \"@kaspernj/api-maker/build/use-styles.js\"\n\nconst styles = StyleSheet.create({\n view: {\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\n },\n viewSmDown: {\n width: \"100%\"\n },\n viewMdUp: {\n width: 300,\n maxWidth: \"100%\"\n },\n viewError: {\n border: \"1px solid rgba(161, 34, 32, 0.95)\",\n backgroundColor: \"rgba(161, 34, 32, 0.87)\"\n },\n viewSuccess: {\n border: \"1px solid rgba(0, 0, 0, 0.95)\",\n backgroundColor: \"rgba(0, 0, 0, 0.87)\"\n },\n viewAlert: {\n border: \"1px solid rgba(204, 51, 0, 0.95)\",\n backgroundColor: \"rgba(204, 51, 0, 0.87)\"\n },\n titleview: {\n marginBottom: 5\n },\n titleText: {\n color: \"#fff\",\n fontWeight: \"bold\"\n },\n messageText: {\n color: \"#fff\"\n }\n})\n\nconst titleViewDataSet = {class: \"notification-title\"}\nconst messageViewDataSet = {class: \"notification-message\"}\n\nexport default memo(shapeComponent(class FlashNotificationsNotification extends ShapeComponent {\n static propTypes = PropTypesExact({\n className: PropTypes.string,\n count: PropTypes.number.isRequired,\n message: PropTypes.string.isRequired,\n notification: PropTypes.object.isRequired,\n onRemovedClicked: PropTypes.func.isRequired,\n title: PropTypes.string.isRequired,\n type: PropTypes.string.isRequired\n })\n\n render() {\n const {count, message, title, type} = this.p\n const {className} = this.props\n\n const viewStyles = useStyles(styles, [\"view\", {\n viewError: type == \"error\",\n viewSuccess: type == \"success\",\n viewAlert: type == \"alert\"\n }])\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\n role: \"dialog\",\n type\n }),\n [className, type]\n )\n\n return (\n <Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>\n <View style={viewStyles}>\n <View dataSet={titleViewDataSet} style={styles.titleview}>\n <Text style={styles.titleText} testID={`flash-notifications/notification-${count}/title`}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText} testID={`flash-notifications/notification-${count}/message`}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
export default class FlashNotifications {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} message
|
|
4
|
+
* @returns {void}
|
|
5
|
+
*/
|
|
6
|
+
static alert(message: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} message
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
11
|
+
static error(message: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* @param {Error} error
|
|
14
|
+
* @returns {void}
|
|
15
|
+
*/
|
|
16
|
+
static errorResponse(error: Error): void;
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} message
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
21
|
+
static success(message: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* @param {object} args
|
|
24
|
+
* @param {string} args.text
|
|
25
|
+
* @param {string} args.type
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
static show(args: {
|
|
29
|
+
text: string;
|
|
30
|
+
type: string;
|
|
31
|
+
}): void;
|
|
7
32
|
}
|
|
8
33
|
//# sourceMappingURL=flash-notifications.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flash-notifications.d.ts","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flash-notifications.d.ts","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AASA;IACE;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,IAAI,CAmChB;IAED;;;OAGG;IACH,wBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;;;OAKG;IACH,kBAJG;QAAqB,IAAI,EAAjB,MAAM;QACO,IAAI,EAAjB,MAAM;KACd,GAAU,IAAI,CAoBhB;CACF"}
|
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
// @ts-check
|
|
2
|
+
import BaseError from "@kaspernj/api-maker/build/base-error.js";
|
|
3
|
+
import ValidationError from "@kaspernj/api-maker/build/validation-error.js";
|
|
3
4
|
import { digg } from "diggerize";
|
|
4
|
-
import configuration from "./configuration";
|
|
5
|
-
import events from "./events";
|
|
5
|
+
import configuration from "./configuration.js";
|
|
6
|
+
import events from "./events.js";
|
|
6
7
|
export default class FlashNotifications {
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} message
|
|
10
|
+
* @returns {void}
|
|
11
|
+
*/
|
|
7
12
|
static alert(message) {
|
|
8
13
|
FlashNotifications.show({ type: "alert", text: message });
|
|
9
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} message
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*/
|
|
10
19
|
static error(message) {
|
|
11
20
|
FlashNotifications.show({ type: "error", text: message });
|
|
12
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {Error} error
|
|
24
|
+
* @returns {void}
|
|
25
|
+
*/
|
|
13
26
|
static errorResponse(error) {
|
|
14
27
|
if (error instanceof ValidationError) {
|
|
28
|
+
// @ts-expect-error
|
|
15
29
|
if (error.hasUnhandledErrors()) {
|
|
30
|
+
// @ts-expect-error
|
|
16
31
|
const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat();
|
|
17
32
|
FlashNotifications.error(unhandledErrorMessages.join(". "));
|
|
18
33
|
}
|
|
@@ -22,8 +37,9 @@ export default class FlashNotifications {
|
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
39
|
else if (error instanceof BaseError) {
|
|
40
|
+
// @ts-expect-error
|
|
25
41
|
if (error.args.response && error.args.response.errors) {
|
|
26
|
-
const errors = digg(error, "args", "response", "errors");
|
|
42
|
+
const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, "args", "response", "errors"));
|
|
27
43
|
const errorMessages = errors.map((error) => {
|
|
28
44
|
if (typeof error == "string") {
|
|
29
45
|
return error;
|
|
@@ -37,13 +53,23 @@ export default class FlashNotifications {
|
|
|
37
53
|
}
|
|
38
54
|
}
|
|
39
55
|
else {
|
|
40
|
-
console.error(
|
|
56
|
+
console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`);
|
|
41
57
|
throw error;
|
|
42
58
|
}
|
|
43
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} message
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
44
64
|
static success(message) {
|
|
45
65
|
FlashNotifications.show({ type: "success", text: message });
|
|
46
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* @param {object} args
|
|
69
|
+
* @param {string} args.text
|
|
70
|
+
* @param {string} args.type
|
|
71
|
+
* @returns {void}
|
|
72
|
+
*/
|
|
47
73
|
static show(args) {
|
|
48
74
|
let title;
|
|
49
75
|
if (args.type == "alert") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,SAAS,MAAM,yCAAyC,CAAA;AAC/D,OAAO,eAAe,MAAM,+CAA+C,CAAA;AAC3E,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,MAAM,MAAM,aAAa,CAAA;AAEhC,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IAC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AM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,KAAK;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["// @ts-check\n\nimport BaseError from \"@kaspernj/api-maker/build/base-error.js\"\nimport ValidationError from \"@kaspernj/api-maker/build/validation-error.js\"\nimport {digg} from \"diggerize\"\n\nimport configuration from \"./configuration.js\"\nimport events from \"./events.js\"\n\nexport default class FlashNotifications {\n /**\n * @param {string} message\n * @returns {void}\n */\n static alert(message) {\n FlashNotifications.show({type: \"alert\", text: message})\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static error(message) {\n FlashNotifications.show({type: \"error\", text: message})\n }\n\n /**\n * @param {Error} error\n * @returns {void}\n */\n static errorResponse(error) {\n if (error instanceof ValidationError) {\n // @ts-expect-error\n if (error.hasUnhandledErrors()) {\n // @ts-expect-error\n const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()\n\n FlashNotifications.error(unhandledErrorMessages.join(\". \"))\n } else {\n const defaultValue = \"Couldn't submit because of validation errors.\"\n\n FlashNotifications.alert(configuration.translate(\"js.notification.couldnt_submit_because_of_validation_errors\", {defaultValue}))\n }\n } else if (error instanceof BaseError) {\n // @ts-expect-error\n if (error.args.response && error.args.response.errors) {\n const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, \"args\", \"response\", \"errors\"))\n const errorMessages = errors.map((error) => {\n if (typeof error == \"string\") {\n return error\n }\n\n return digg(error, \"message\")\n })\n\n FlashNotifications.error(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else {\n console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`)\n throw error\n }\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static success(message) {\n FlashNotifications.show({type: \"success\", text: message})\n }\n\n /**\n * @param {object} args\n * @param {string} args.text\n * @param {string} args.type\n * @returns {void}\n */\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = configuration.translate(\"js.shared.alert\", {defaultValue: \"Alert\"})\n } else if (args.type == \"error\") {\n title = configuration.translate(\"js.shared.error\", {defaultValue: \"Error\"})\n } else if (args.type == \"success\") {\n title = configuration.translate(\"js.shared.success\", {defaultValue: \"Success\"})\n } else {\n title = configuration.translate(\"js.shared.notification\", {defaultValue: \"Notification\"})\n }\n\n events.emit(\"pushNotification\", {\n message: args.text,\n title,\n type: args.type\n })\n }\n}\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import configuration from "./configuration";
|
|
1
|
+
import configuration from "./configuration.js";
|
|
2
2
|
import Container from "./container";
|
|
3
|
-
import FlashNotifications from "./flash-notifications";
|
|
3
|
+
import FlashNotifications from "./flash-notifications.js";
|
|
4
4
|
export { configuration, Container, FlashNotifications };
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"0BAE0B,oBAAoB;sBACxB,aAAa;+BACJ,0BAA0B"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import configuration from "./configuration.js";
|
|
2
3
|
import Container from "./container";
|
|
3
|
-
import FlashNotifications from "./flash-notifications";
|
|
4
|
+
import FlashNotifications from "./flash-notifications.js";
|
|
4
5
|
if (!configuration) {
|
|
5
6
|
throw new Error("No configuration object given?");
|
|
6
7
|
}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,kBAAkB,MAAM,0BAA0B,CAAA;AAEzD,IAAI,CAAC,aAAa,EAAE,CAAC;IACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;AACnD,CAAC;AAED,OAAO,EACL,aAAa,EACb,SAAS,EACT,kBAAkB,EACnB,CAAA","sourcesContent":["// @ts-check\n\nimport configuration from \"./configuration.js\"\nimport Container from \"./container\"\nimport FlashNotifications from \"./flash-notifications.js\"\n\nif (!configuration) {\n throw new Error(\"No configuration object given?\")\n}\n\nexport {\n configuration,\n Container,\n FlashNotifications\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flash-notifications",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "My new module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"react-native": "~0.76.9"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@kaspernj/api-maker": ">= 1.0.
|
|
54
|
+
"@kaspernj/api-maker": ">= 1.0.2053",
|
|
55
55
|
"expo": "*",
|
|
56
56
|
"react": "*",
|
|
57
57
|
"react-native": "*"
|
package/src/container/index.jsx
CHANGED
|
@@ -1,33 +1,45 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import {digg} from "diggerize"
|
|
2
4
|
import PropTypes from "prop-types"
|
|
3
5
|
import propTypesExact from "prop-types-exact"
|
|
4
6
|
import React, {memo, useEffect, useMemo} from "react"
|
|
5
|
-
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
6
|
-
import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint"
|
|
7
|
-
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter"
|
|
7
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
8
|
+
import useBreakpoint from "@kaspernj/api-maker/build/use-breakpoint.js"
|
|
9
|
+
import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter.js"
|
|
8
10
|
import useEnvSense from "env-sense/src/use-env-sense.js"
|
|
9
11
|
import {View} from "react-native"
|
|
10
12
|
|
|
11
|
-
import events from "../events"
|
|
13
|
+
import events from "../events.js"
|
|
12
14
|
import Notification from "./notification"
|
|
13
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} NotificationObjectType
|
|
18
|
+
* @property {number} count
|
|
19
|
+
* @property {string} message
|
|
20
|
+
* @property {string} title
|
|
21
|
+
* @property {string} type
|
|
22
|
+
*/
|
|
23
|
+
|
|
14
24
|
export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
|
|
15
25
|
static propTypes = propTypesExact({
|
|
16
26
|
insets: PropTypes.object
|
|
17
27
|
})
|
|
18
28
|
|
|
29
|
+
/** @type {number[]} */
|
|
19
30
|
timeouts = []
|
|
20
31
|
|
|
21
32
|
setup() {
|
|
33
|
+
// @ts-expect-error
|
|
22
34
|
this.useStates({
|
|
23
35
|
count: 0,
|
|
24
36
|
notifications: []
|
|
25
37
|
})
|
|
26
38
|
|
|
27
|
-
useEventEmitter(events, "pushNotification", this.
|
|
39
|
+
useEventEmitter(events, "pushNotification", this.onPushNotification)
|
|
28
40
|
useEffect(() => {
|
|
29
41
|
return () => {
|
|
30
|
-
for (const timeout of this.
|
|
42
|
+
for (const timeout of this.timeouts) {
|
|
31
43
|
clearTimeout(timeout)
|
|
32
44
|
}
|
|
33
45
|
}
|
|
@@ -35,42 +47,59 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
render() {
|
|
50
|
+
// @ts-expect-error
|
|
51
|
+
const {notifications} = this.s
|
|
52
|
+
|
|
53
|
+
// @ts-expect-error
|
|
38
54
|
const insets = this.props.insets || {}
|
|
55
|
+
|
|
39
56
|
const {smDown, mdUp} = useBreakpoint()
|
|
40
57
|
const {isNative} = useEnvSense()
|
|
41
58
|
|
|
42
59
|
const viewStyle = useMemo(() => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
60
|
+
let top = 20
|
|
61
|
+
let right = 0
|
|
62
|
+
let left = undefined
|
|
63
|
+
|
|
64
|
+
if (insets.top) top += insets.top
|
|
65
|
+
if (insets.right) right += insets.right
|
|
50
66
|
|
|
51
67
|
if (smDown) {
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
left = 20
|
|
69
|
+
|
|
70
|
+
if (insets.left) left += insets.left
|
|
71
|
+
|
|
72
|
+
right += 20
|
|
54
73
|
} else if (mdUp) {
|
|
55
|
-
|
|
74
|
+
right += 20
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const style = {
|
|
78
|
+
position: isNative ? "absolute" : "fixed",
|
|
79
|
+
top,
|
|
80
|
+
right,
|
|
81
|
+
left,
|
|
82
|
+
zIndex: 99999
|
|
56
83
|
}
|
|
57
84
|
|
|
58
85
|
return style
|
|
59
|
-
}, [isNative, smDown, mdUp, insets.top, insets.right, insets.
|
|
86
|
+
}, [isNative, smDown, mdUp, insets.top, insets.right, insets.left])
|
|
60
87
|
|
|
61
88
|
return (
|
|
62
89
|
<View
|
|
90
|
+
// @ts-expect-error
|
|
63
91
|
dataSet={this.rootViewDataSet ||= {component: "flash-notifications-container"}}
|
|
92
|
+
// @ts-expect-error
|
|
64
93
|
style={viewStyle}
|
|
65
94
|
testID="flash-notificaitons/container"
|
|
66
95
|
>
|
|
67
|
-
{
|
|
96
|
+
{notifications.map((notification) =>
|
|
68
97
|
<Notification
|
|
69
98
|
count={notification.count}
|
|
70
99
|
key={`notification-${notification.count}`}
|
|
71
100
|
message={notification.message}
|
|
72
101
|
notification={notification}
|
|
73
|
-
onRemovedClicked={this.
|
|
102
|
+
onRemovedClicked={this.onRemovedClicked}
|
|
74
103
|
title={notification.title}
|
|
75
104
|
type={notification.type}
|
|
76
105
|
/>
|
|
@@ -79,11 +108,16 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
79
108
|
)
|
|
80
109
|
}
|
|
81
110
|
|
|
111
|
+
/**
|
|
112
|
+
* @param {NotificationObjectType} detail
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
82
115
|
onPushNotification = (detail) => {
|
|
116
|
+
// @ts-expect-error
|
|
83
117
|
const count = this.s.count + 1
|
|
84
118
|
const timeout = setTimeout(() => this.removeNotification(count), 4000)
|
|
85
119
|
|
|
86
|
-
this.
|
|
120
|
+
this.timeouts.push(timeout)
|
|
87
121
|
|
|
88
122
|
const notification = {
|
|
89
123
|
count,
|
|
@@ -92,13 +126,16 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
92
126
|
type: digg(detail, "type")
|
|
93
127
|
}
|
|
94
128
|
|
|
129
|
+
// @ts-expect-error
|
|
95
130
|
this.setState({count, notifications: this.s.notifications.concat([notification])})
|
|
96
131
|
}
|
|
97
132
|
|
|
98
133
|
onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"))
|
|
99
134
|
|
|
100
135
|
removeNotification = (count) => {
|
|
136
|
+
// @ts-expect-error
|
|
101
137
|
this.setState({
|
|
138
|
+
// @ts-expect-error
|
|
102
139
|
notifications: this.s.notifications.filter((notification) => notification.count != count)
|
|
103
140
|
})
|
|
104
141
|
}
|
|
@@ -3,7 +3,7 @@ import PropTypes from "prop-types"
|
|
|
3
3
|
import PropTypesExact from "prop-types-exact"
|
|
4
4
|
import React, {memo, useMemo} from "react"
|
|
5
5
|
import {Pressable, StyleSheet, Text, View} from "react-native"
|
|
6
|
-
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
6
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
7
7
|
import useStyles from "@kaspernj/api-maker/build/use-styles.js"
|
|
8
8
|
|
|
9
9
|
const styles = StyleSheet.create({
|
|
@@ -1,22 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import BaseError from "@kaspernj/api-maker/build/base-error.js"
|
|
4
|
+
import ValidationError from "@kaspernj/api-maker/build/validation-error.js"
|
|
3
5
|
import {digg} from "diggerize"
|
|
4
6
|
|
|
5
|
-
import configuration from "./configuration"
|
|
6
|
-
import events from "./events"
|
|
7
|
+
import configuration from "./configuration.js"
|
|
8
|
+
import events from "./events.js"
|
|
7
9
|
|
|
8
10
|
export default class FlashNotifications {
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} message
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
9
15
|
static alert(message) {
|
|
10
16
|
FlashNotifications.show({type: "alert", text: message})
|
|
11
17
|
}
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} message
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
13
23
|
static error(message) {
|
|
14
24
|
FlashNotifications.show({type: "error", text: message})
|
|
15
25
|
}
|
|
16
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @param {Error} error
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/
|
|
17
31
|
static errorResponse(error) {
|
|
18
32
|
if (error instanceof ValidationError) {
|
|
33
|
+
// @ts-expect-error
|
|
19
34
|
if (error.hasUnhandledErrors()) {
|
|
35
|
+
// @ts-expect-error
|
|
20
36
|
const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()
|
|
21
37
|
|
|
22
38
|
FlashNotifications.error(unhandledErrorMessages.join(". "))
|
|
@@ -26,8 +42,9 @@ export default class FlashNotifications {
|
|
|
26
42
|
FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", {defaultValue}))
|
|
27
43
|
}
|
|
28
44
|
} else if (error instanceof BaseError) {
|
|
45
|
+
// @ts-expect-error
|
|
29
46
|
if (error.args.response && error.args.response.errors) {
|
|
30
|
-
const errors = digg(error, "args", "response", "errors")
|
|
47
|
+
const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, "args", "response", "errors"))
|
|
31
48
|
const errorMessages = errors.map((error) => {
|
|
32
49
|
if (typeof error == "string") {
|
|
33
50
|
return error
|
|
@@ -41,15 +58,25 @@ export default class FlashNotifications {
|
|
|
41
58
|
throw error
|
|
42
59
|
}
|
|
43
60
|
} else {
|
|
44
|
-
console.error(
|
|
61
|
+
console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`)
|
|
45
62
|
throw error
|
|
46
63
|
}
|
|
47
64
|
}
|
|
48
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @param {string} message
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
49
70
|
static success(message) {
|
|
50
71
|
FlashNotifications.show({type: "success", text: message})
|
|
51
72
|
}
|
|
52
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @param {object} args
|
|
76
|
+
* @param {string} args.text
|
|
77
|
+
* @param {string} args.type
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
53
80
|
static show(args) {
|
|
54
81
|
let title
|
|
55
82
|
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import configuration from "./configuration.js"
|
|
2
4
|
import Container from "./container"
|
|
3
|
-
import FlashNotifications from "./flash-notifications"
|
|
5
|
+
import FlashNotifications from "./flash-notifications.js"
|
|
4
6
|
|
|
5
7
|
if (!configuration) {
|
|
6
8
|
throw new Error("No configuration object given?")
|