flash-notifications 0.0.15 → 0.0.16
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/.eslintrc.js +7 -1
- package/build/configuration.d.ts +3 -0
- package/build/configuration.d.ts.map +1 -0
- package/build/configuration.js +6 -0
- package/build/configuration.js.map +1 -0
- package/build/container/index.d.ts.map +1 -1
- package/build/container/index.js +7 -10
- package/build/container/index.js.map +1 -1
- package/build/container/notification.d.ts.map +1 -1
- package/build/container/notification.js +3 -3
- package/build/container/notification.js.map +1 -1
- package/build/events.d.ts +2 -0
- package/build/events.d.ts.map +1 -0
- package/build/events.js +6 -0
- package/build/events.js.map +1 -0
- package/build/flash-notifications.d.ts +1 -1
- package/build/flash-notifications.d.ts.map +1 -1
- package/build/flash-notifications.js +18 -17
- package/build/flash-notifications.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -1
- package/build/index.js.map +1 -1
- package/package.json +4 -3
- package/peak_flow.yml +4 -0
- package/src/configuration.js +7 -0
- package/src/container/index.jsx +8 -11
- package/src/container/notification.jsx +3 -3
- package/src/events.js +7 -0
- package/src/flash-notifications.js +20 -18
- package/src/index.js +6 -0
package/.eslintrc.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.js"],"names":[],"mappings":";AAIA,iCAAgE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.js"],"names":[],"mappings":"AAAA,IAAI,CAAC,UAAU,CAAC,+BAA+B,EAAE,CAAC;IAChD,UAAU,CAAC,+BAA+B,GAAG,EAAE,CAAA;AACjD,CAAC;AAED,MAAM,aAAa,GAAG,UAAU,CAAC,+BAA+B,CAAA;AAEhE,eAAe,aAAa,CAAA","sourcesContent":["if (!globalThis.flashNotificationsConfiguration) {\n globalThis.flashNotificationsConfiguration = {}\n}\n\nconst configuration = globalThis.flashNotificationsConfiguration\n\nexport default configuration\n"]}
|
|
@@ -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":";;kBAE0B,OAAO"}
|
package/build/container/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
+
import useEventEmitter from "@kaspernj/api-maker/src/use-event-emitter";
|
|
2
|
+
import { digg } from "diggerize";
|
|
1
3
|
import React, { memo } from "react";
|
|
2
|
-
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
3
4
|
import { StyleSheet, View } from "react-native";
|
|
4
|
-
import {
|
|
5
|
+
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
|
|
6
|
+
import events from "../events";
|
|
5
7
|
import Notification from "./notification";
|
|
6
|
-
import useEventListener from "@kaspernj/api-maker/src/use-event-listener";
|
|
7
|
-
const dataSets = {
|
|
8
|
-
view: { class: "flash-notifications-container" }
|
|
9
|
-
};
|
|
10
8
|
const styles = StyleSheet.create({
|
|
11
9
|
view: {
|
|
12
10
|
position: "fixed",
|
|
@@ -21,13 +19,12 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
21
19
|
count: 0,
|
|
22
20
|
notifications: []
|
|
23
21
|
});
|
|
24
|
-
|
|
22
|
+
useEventEmitter(events, "pushNotification", this.tt.onPushNotification);
|
|
25
23
|
}
|
|
26
24
|
render() {
|
|
27
|
-
return (React.createElement(View, { dataSet:
|
|
25
|
+
return (React.createElement(View, { dataSet: this.rootViewDataSet ||= { class: "flash-notifications-container" }, style: styles.view }, this.s.notifications.map((notification) => React.createElement(Notification, { key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.tt.onRemovedClicked, title: notification.title, type: notification.type }))));
|
|
28
26
|
}
|
|
29
|
-
onPushNotification = (
|
|
30
|
-
const detail = digg(event, "detail");
|
|
27
|
+
onPushNotification = (detail) => {
|
|
31
28
|
const count = this.s.count + 1;
|
|
32
29
|
setTimeout(() => this.removeNotification(count), 4000);
|
|
33
30
|
const notification = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,2CAA2C,CAAA;AACvE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,EAAE,EAAC,IAAI,EAAC,MAAM,OAAO,CAAA;AACjC,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AAEpF,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,QAAQ,EAAE,OAAO;QACjB,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE;QACP,KAAK,EAAE,EAAE;KACV;CACF,CAAC,CAAA;AAEF,eAAe,IAAI,CAAC,cAAc,CAAC,MAAM,2BAA4B,SAAQ,cAAc;IACzF,KAAK;QACH,IAAI,CAAC,SAAS,CAAC;YACb,KAAK,EAAE,CAAC;YACR,aAAa,EAAE,EAAE;SAClB,CAAC,CAAA;QAEF,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAA;IACzE,CAAC;IAED,MAAM;QACJ,OAAO,CACL,oBAAC,IAAI,IACH,OAAO,EAAE,IAAI,CA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B,IAAI,CAAC,QAAQ,CAAC;YACZ,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":["import useEventEmitter from \"@kaspernj/api-maker/src/use-event-emitter\"\nimport {digg} from \"diggerize\"\nimport React, {memo} from \"react\"\nimport {StyleSheet, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\n\nimport events from \"../events\"\nimport Notification from \"./notification\"\n\nconst styles = StyleSheet.create({\n view: {\n position: \"fixed\",\n zIndex: 99999,\n top: 20,\n right: 20\n }\n})\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n setup() {\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventEmitter(events, \"pushNotification\", this.tt.onPushNotification)\n }\n\n render() {\n return (\n <View\n dataSet={this.rootViewDataSet ||= {class: \"flash-notifications-container\"}}\n style={styles.view}\n >\n {this.s.notifications.map((notification) =>\n <Notification\n key={`notification-${notification.count}`}\n message={notification.message}\n notification={notification}\n onRemovedClicked={this.tt.onRemovedClicked}\n title={notification.title}\n type={notification.type}\n />\n )}\n </View>\n )\n }\n\n onPushNotification = (detail) => {\n const count = this.s.count + 1\n\n setTimeout(() => this.removeNotification(count), 4000)\n\n const notification = {\n count,\n message: digg(detail, \"message\"),\n title: digg(detail, \"title\"),\n type: digg(detail, \"type\")\n }\n\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 this.setState({\n notifications: this.s.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":";;kBAGmC,OAAO"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
2
|
-
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
|
|
3
|
-
import React, { memo, useMemo } from "react";
|
|
4
1
|
import classNames from "classnames";
|
|
5
2
|
import PropTypes from "prop-types";
|
|
6
3
|
import PropTypesExact from "prop-types-exact";
|
|
4
|
+
import React, { memo, useMemo } from "react";
|
|
5
|
+
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
6
|
+
import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
|
|
7
7
|
const styles = StyleSheet.create({
|
|
8
8
|
view: {
|
|
9
9
|
width: 300,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AAEpF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,MAAM;QAChB,YAAY,EAAE,EAAE;QAChB,OAAO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AAI,IAAI,IAAI,OAAO;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YACtD,IAAI,IAAI,IAAI,SAAS;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC1D,IAAI,IAAI,IAAI,OAAO;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAEtD,OAAO,UAAU,CAAA;QACnB,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAA;QAED,MAAM,gBAAgB,GAAG,OAAO,CAC9B,GAAG,EAAE,CAAC,CAAC;YACL,KAAK,EAAE,UAAU,CAAC,kCAAkC,EAAE,SAAS,CAAC;YAChE,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,IAC1B,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,IAAC,OAAO,EAAE,kBAAkB;oBAC/B,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,WAAW,IAC5B,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\"\n\nconst styles = StyleSheet.create({\n view: {\n width: 300,\n maxWidth: \"100%\",\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\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 NotificationsNotification extends ShapeComponent {\n static propTypes = PropTypesExact({\n className: PropTypes.string,\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 {className, message, title, type} = this.props\n\n const viewStyles = useMemo(\n () => {\n const viewStyles = [styles.view]\n\n if (type == \"error\") viewStyles.push(styles.viewError)\n if (type == \"success\") viewStyles.push(styles.viewSuccess)\n if (type == \"alert\") viewStyles.push(styles.viewAlert)\n\n return viewStyles\n },\n [type]\n )\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\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}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.js"],"names":[],"mappings":""}
|
package/build/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.js"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AAEjC,IAAI,CAAC,UAAU,CAAC,wBAAwB,EAAE,CAAC;IACzC,UAAU,CAAC,wBAAwB,GAAG,IAAI,YAAY,EAAE,CAAA;AAC1D,CAAC;AAED,eAAe,UAAU,CAAC,wBAAwB,CAAA","sourcesContent":["import EventEmitter from \"events\"\n\nif (!globalThis.flashNotificationsEvents) {\n globalThis.flashNotificationsEvents = new EventEmitter()\n}\n\nexport default globalThis.flashNotificationsEvents\n"]}
|
|
@@ -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":"AAOA;IACE,iCAEC;IAED,+BA4BC;IAED,uCAEC;IAED,mCAEC;IAED,6BAkBC;CACF"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import BaseError from "@kaspernj/api-maker/src/base-error";
|
|
2
2
|
import ValidationError from "@kaspernj/api-maker/src/validation-error";
|
|
3
|
-
|
|
3
|
+
import { digg } from "diggerize";
|
|
4
|
+
import configuration from "./configuration";
|
|
5
|
+
import events from "./events";
|
|
6
|
+
export default class FlashNotifications {
|
|
4
7
|
static alert(message) {
|
|
5
|
-
|
|
8
|
+
FlashNotifications.show({ type: "alert", text: message });
|
|
6
9
|
}
|
|
7
10
|
static error(error) {
|
|
8
11
|
if (error instanceof BaseError) {
|
|
@@ -14,7 +17,7 @@ export default class FlashMessage {
|
|
|
14
17
|
}
|
|
15
18
|
return digg(error, "message");
|
|
16
19
|
});
|
|
17
|
-
|
|
20
|
+
FlashNotifications.alert(errorMessages.join(". "));
|
|
18
21
|
}
|
|
19
22
|
else {
|
|
20
23
|
throw error;
|
|
@@ -22,10 +25,11 @@ export default class FlashMessage {
|
|
|
22
25
|
}
|
|
23
26
|
else if (error instanceof ValidationError) {
|
|
24
27
|
if (error.hasUnhandledErrors()) {
|
|
25
|
-
|
|
28
|
+
FlashNotifications.alert(error.message);
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
28
|
-
|
|
31
|
+
const defaultValue = "Couldn't submit because of validation errors.";
|
|
32
|
+
FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", { defaultValue }));
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
else {
|
|
@@ -37,30 +41,27 @@ export default class FlashMessage {
|
|
|
37
41
|
this.error(error);
|
|
38
42
|
}
|
|
39
43
|
static success(message) {
|
|
40
|
-
|
|
44
|
+
FlashNotifications.show({ type: "success", text: message });
|
|
41
45
|
}
|
|
42
46
|
static show(args) {
|
|
43
47
|
let title;
|
|
44
48
|
if (args.type == "alert") {
|
|
45
|
-
title =
|
|
49
|
+
title = configuration.translate("js.shared.alert", { defaultValue: "Alert" });
|
|
46
50
|
}
|
|
47
51
|
else if (args.type == "error") {
|
|
48
|
-
title =
|
|
52
|
+
title = configuration.translate("js.shared.error", { defaultValue: "Error" });
|
|
49
53
|
}
|
|
50
54
|
else if (args.type == "success") {
|
|
51
|
-
title =
|
|
55
|
+
title = configuration.translate("js.shared.success", { defaultValue: "Success" });
|
|
52
56
|
}
|
|
53
57
|
else {
|
|
54
|
-
title =
|
|
58
|
+
title = configuration.translate("js.shared.notification", { defaultValue: "Notification" });
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
type: args.type
|
|
61
|
-
}
|
|
60
|
+
events.emit("pushNotification", {
|
|
61
|
+
message: args.text,
|
|
62
|
+
title,
|
|
63
|
+
type: args.type
|
|
62
64
|
});
|
|
63
|
-
globalThis.dispatchEvent(event);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
//# sourceMappingURL=flash-notifications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oCAAoC,CAAA;AAC1D,OAAO,eAAe,MAAM,0CAA0C,CAAA;
|
|
1
|
+
{"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oCAAoC,CAAA;AAC1D,OAAO,eAAe,MAAM,0CAA0C,CAAA;AACtE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,MAAM,MAAM,UAAU,CAAA;AAE7B,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;gBACtD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;gBACxD,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAA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,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YAChC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YAClC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAC,YAAY,EAAE,SAAS,EAAC,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,wBAAwB,EAAE,EAAC,YAAY,EAAE,cAAc,EAAC,CAAC,CAAA;QAC3F,CAAC;QAED,MAAM,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":["import BaseError from \"@kaspernj/api-maker/src/base-error\"\nimport ValidationError from \"@kaspernj/api-maker/src/validation-error\"\nimport {digg} from \"diggerize\"\n\nimport configuration from \"./configuration\"\nimport events from \"./events\"\n\nexport default class FlashNotifications {\n static alert(message) {\n FlashNotifications.show({type: \"alert\", text: message})\n }\n\n static error(error) {\n if (error instanceof BaseError) {\n if (error.args.response && error.args.response.errors) {\n const errors = 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.alert(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else if (error instanceof ValidationError) {\n if (error.hasUnhandledErrors()) {\n FlashNotifications.alert(error.message)\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 {\n console.error(\"Didnt know what to do with that error\", error)\n throw error\n }\n }\n\n static errorResponse(error) {\n this.error(error)\n }\n\n static success(message) {\n FlashNotifications.show({type: \"success\", text: message})\n }\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,4 +1,5 @@
|
|
|
1
|
+
import configuration from "./configuration";
|
|
1
2
|
import Container from "./container";
|
|
2
3
|
import FlashNotifications from "./flash-notifications";
|
|
3
|
-
export { Container, FlashNotifications };
|
|
4
|
+
export { configuration, Container, FlashNotifications };
|
|
4
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":"0BAA0B,iBAAiB;sBACrB,aAAa;+BACJ,uBAAuB"}
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import configuration from "./configuration";
|
|
1
2
|
import Container from "./container";
|
|
2
3
|
import FlashNotifications from "./flash-notifications";
|
|
3
|
-
|
|
4
|
+
if (!configuration) {
|
|
5
|
+
throw new Error("No configuration object given?");
|
|
6
|
+
}
|
|
7
|
+
export { configuration, Container, FlashNotifications };
|
|
4
8
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,kBAAkB,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EACL,SAAS,EACT,kBAAkB,EACnB,CAAA","sourcesContent":["import Container from \"./container\"\nimport FlashNotifications from \"./flash-notifications\"\n\nexport {\n Container,\n FlashNotifications\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,kBAAkB,MAAM,uBAAuB,CAAA;AAEtD,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":["import configuration from \"./configuration\"\nimport Container from \"./container\"\nimport FlashNotifications from \"./flash-notifications\"\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.16",
|
|
4
4
|
"description": "My new module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,15 +29,16 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"homepage": "https://github.com/kaspernj/flash-notifications#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"classnames": "^2.5.1",
|
|
32
33
|
"diggerize": "*",
|
|
33
34
|
"prop-types-exact": "*",
|
|
34
35
|
"set-state-compare": "*"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/react": "~18.3.12",
|
|
39
|
+
"expo": "~53.0.9",
|
|
38
40
|
"expo-module-scripts": "^4.0.2",
|
|
39
|
-
"
|
|
40
|
-
"react-native": "0.76.0"
|
|
41
|
+
"react-native": "~0.76.9"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"expo": "*",
|
package/peak_flow.yml
ADDED
package/src/container/index.jsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import useEventEmitter from "@kaspernj/api-maker/src/use-event-emitter"
|
|
2
|
+
import {digg} from "diggerize"
|
|
1
3
|
import React, {memo} from "react"
|
|
2
|
-
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
3
4
|
import {StyleSheet, View} from "react-native"
|
|
4
|
-
import {
|
|
5
|
-
import Notification from "./notification"
|
|
6
|
-
import useEventListener from "@kaspernj/api-maker/src/use-event-listener"
|
|
5
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
7
|
+
import events from "../events"
|
|
8
|
+
import Notification from "./notification"
|
|
11
9
|
|
|
12
10
|
const styles = StyleSheet.create({
|
|
13
11
|
view: {
|
|
@@ -25,13 +23,13 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
25
23
|
notifications: []
|
|
26
24
|
})
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
useEventEmitter(events, "pushNotification", this.tt.onPushNotification)
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
render() {
|
|
32
30
|
return (
|
|
33
31
|
<View
|
|
34
|
-
dataSet={
|
|
32
|
+
dataSet={this.rootViewDataSet ||= {class: "flash-notifications-container"}}
|
|
35
33
|
style={styles.view}
|
|
36
34
|
>
|
|
37
35
|
{this.s.notifications.map((notification) =>
|
|
@@ -48,8 +46,7 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
|
|
|
48
46
|
)
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
onPushNotification = (
|
|
52
|
-
const detail = digg(event, "detail")
|
|
49
|
+
onPushNotification = (detail) => {
|
|
53
50
|
const count = this.s.count + 1
|
|
54
51
|
|
|
55
52
|
setTimeout(() => this.removeNotification(count), 4000)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {Pressable, StyleSheet, Text, View} from "react-native"
|
|
2
|
-
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
3
|
-
import React, {memo, useMemo} from "react"
|
|
4
1
|
import classNames from "classnames"
|
|
5
2
|
import PropTypes from "prop-types"
|
|
6
3
|
import PropTypesExact from "prop-types-exact"
|
|
4
|
+
import React, {memo, useMemo} from "react"
|
|
5
|
+
import {Pressable, StyleSheet, Text, View} from "react-native"
|
|
6
|
+
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
7
7
|
|
|
8
8
|
const styles = StyleSheet.create({
|
|
9
9
|
view: {
|
package/src/events.js
ADDED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import BaseError from "@kaspernj/api-maker/src/base-error"
|
|
2
2
|
import ValidationError from "@kaspernj/api-maker/src/validation-error"
|
|
3
|
+
import {digg} from "diggerize"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
import configuration from "./configuration"
|
|
6
|
+
import events from "./events"
|
|
7
|
+
|
|
8
|
+
export default class FlashNotifications {
|
|
5
9
|
static alert(message) {
|
|
6
|
-
|
|
10
|
+
FlashNotifications.show({type: "alert", text: message})
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
static error(error) {
|
|
@@ -18,15 +22,17 @@ export default class FlashMessage {
|
|
|
18
22
|
return digg(error, "message")
|
|
19
23
|
})
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
FlashNotifications.alert(errorMessages.join(". "))
|
|
22
26
|
} else {
|
|
23
27
|
throw error
|
|
24
28
|
}
|
|
25
29
|
} else if (error instanceof ValidationError) {
|
|
26
30
|
if (error.hasUnhandledErrors()) {
|
|
27
|
-
|
|
31
|
+
FlashNotifications.alert(error.message)
|
|
28
32
|
} else {
|
|
29
|
-
|
|
33
|
+
const defaultValue = "Couldn't submit because of validation errors."
|
|
34
|
+
|
|
35
|
+
FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", {defaultValue}))
|
|
30
36
|
}
|
|
31
37
|
} else {
|
|
32
38
|
console.error("Didnt know what to do with that error", error)
|
|
@@ -39,30 +45,26 @@ export default class FlashMessage {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
static success(message) {
|
|
42
|
-
|
|
48
|
+
FlashNotifications.show({type: "success", text: message})
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
static show(args) {
|
|
46
52
|
let title
|
|
47
53
|
|
|
48
54
|
if (args.type == "alert") {
|
|
49
|
-
title =
|
|
55
|
+
title = configuration.translate("js.shared.alert", {defaultValue: "Alert"})
|
|
50
56
|
} else if (args.type == "error") {
|
|
51
|
-
title =
|
|
57
|
+
title = configuration.translate("js.shared.error", {defaultValue: "Error"})
|
|
52
58
|
} else if (args.type == "success") {
|
|
53
|
-
title =
|
|
59
|
+
title = configuration.translate("js.shared.success", {defaultValue: "Success"})
|
|
54
60
|
} else {
|
|
55
|
-
title =
|
|
61
|
+
title = configuration.translate("js.shared.notification", {defaultValue: "Notification"})
|
|
56
62
|
}
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
type: args.type
|
|
63
|
-
}
|
|
64
|
+
events.emit("pushNotification", {
|
|
65
|
+
message: args.text,
|
|
66
|
+
title,
|
|
67
|
+
type: args.type
|
|
64
68
|
})
|
|
65
|
-
|
|
66
|
-
globalThis.dispatchEvent(event)
|
|
67
69
|
}
|
|
68
70
|
}
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import configuration from "./configuration"
|
|
1
2
|
import Container from "./container"
|
|
2
3
|
import FlashNotifications from "./flash-notifications"
|
|
3
4
|
|
|
5
|
+
if (!configuration) {
|
|
6
|
+
throw new Error("No configuration object given?")
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export {
|
|
10
|
+
configuration,
|
|
5
11
|
Container,
|
|
6
12
|
FlashNotifications
|
|
7
13
|
}
|