flash-notifications 0.0.12 → 0.0.14

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.
@@ -1,3 +1,4 @@
1
- declare const _default: import("react").MemoExoticComponent<any>;
1
+ declare const _default: React.MemoExoticComponent<any>;
2
2
  export default _default;
3
+ import React from "react";
3
4
  //# 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":";;kBAA0B,OAAO"}
@@ -1,41 +1,47 @@
1
- import { memo } from "react";
1
+ import React, { memo } from "react";
2
+ import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
3
+ import { StyleSheet, View } from "react-native";
2
4
  import { digg } from "diggerize";
3
5
  import Notification from "./notification";
4
- import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
5
6
  import useEventListener from "@kaspernj/api-maker/src/use-event-listener";
6
- import { View } from "react-native";
7
+ const dataSets = {
8
+ view: { class: "flash-notifications-container" }
9
+ };
10
+ const styles = StyleSheet.create({
11
+ view: {
12
+ position: "fixed",
13
+ zIndex: 99999,
14
+ top: 20,
15
+ right: 20
16
+ }
17
+ });
7
18
  export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
8
19
  setup() {
9
20
  this.useStates({
10
21
  count: 0,
11
22
  notifications: []
12
23
  });
13
- useEventListener(window, "pushNotification", this.onPushNotification);
24
+ useEventListener(globalThis, "pushNotification", this.tt.onPushNotification);
14
25
  }
15
26
  render() {
16
- return (React.createElement(View, { dataSet: { class: "flash-notifications-container" }, style: {
17
- position: "fixed",
18
- zIndex: 99999,
19
- top: 20,
20
- right: 20
21
- } }, this.state.notifications.map((notification) => React.createElement(Notification, { key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.onRemovedClicked, title: notification.title, type: notification.type }))));
27
+ return (React.createElement(View, { dataSet: dataSets.view, 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 }))));
22
28
  }
23
29
  onPushNotification = (event) => {
24
30
  const detail = digg(event, "detail");
25
- const count = this.state.count + 1;
26
- setTimeout(() => this.removeNotification(count), 4000);
31
+ const count = this.s.count + 1;
32
+ // setTimeout(() => this.removeNotification(count), 4000)
27
33
  const notification = {
28
34
  count,
29
35
  message: digg(detail, "message"),
30
36
  title: digg(detail, "title"),
31
37
  type: digg(detail, "type")
32
38
  };
33
- this.setState({ count, notifications: this.state.notifications.concat([notification]) });
39
+ this.setState({ count, notifications: this.s.notifications.concat([notification]) });
34
40
  };
35
41
  onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"));
36
42
  removeNotification = (count) => {
37
43
  this.setState({
38
- notifications: this.state.notifications.filter((notification) => notification.count != count)
44
+ notifications: this.s.notifications.filter((notification) => notification.count != count)
39
45
  });
40
46
  };
41
47
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,OAAO,CAAA;AAC1B,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0CAA0C,CAAA;AACvF,OAAO,gBAAgB,MAAM,4CAA4C,CAAA;AACzE,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AAEjC,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,CAA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C,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,EAAC,CAAC,CAAA;IACxF,CAAC,CAAA;IAED,gBAAgB,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;IAEzF,kBAAkB,GAAG,CAAC,KAAK,EAAE,EAAE;QAC7B,IAAI,CAAC,QAAQ,CAAC;YACZ,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC9F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import {memo} from \"react\"\nimport {digg} from \"diggerize\"\nimport Notification from \"./notification\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport useEventListener from \"@kaspernj/api-maker/src/use-event-listener\"\nimport {View} from \"react-native\"\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n setup() {\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventListener(window, \"pushNotification\", this.onPushNotification)\n }\n\n render() {\n return (\n <View\n dataSet={{class: \"flash-notifications-container\"}}\n style={{\n position: \"fixed\",\n zIndex: 99999,\n top: 20,\n right: 20\n }}\n >\n {this.state.notifications.map((notification) =>\n <Notification\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 onPushNotification = (event) => {\n const detail = digg(event, \"detail\")\n const count = this.state.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.state.notifications.concat([notification])})\n }\n\n onRemovedClicked = (notification) => this.removeNotification(digg(notification, \"count\"))\n\n removeNotification = (count) => {\n this.setState({\n notifications: this.state.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,IAAI,EAAC,MAAM,OAAO,CAAA;AACjC,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0CAA0C,CAAA;AACvF,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,gBAAgB,MAAM,4CAA4C,CAAA;AAEzE,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,EAAC,KAAK,EAAE,+BAA+B,EAAC;CAC/C,CAAA;AAED,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,gBAAgB,CAAC,UAAU,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAA;IAC9E,CAAC;IAED,MAAM;QACJ,OAAO,CACL,oBAAC,IAAI,IACH,OAAO,EAAE,QAAQ,CAAC,IAAI,EACtB,KAAK,EAAE,MAAM,CAAC,IAAI,IAEjB,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE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AAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import React, {memo} from \"react\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport {StyleSheet, View} from \"react-native\"\nimport {digg} from \"diggerize\"\nimport Notification from \"./notification\"\nimport useEventListener from \"@kaspernj/api-maker/src/use-event-listener\"\n\nconst dataSets = {\n view: {class: \"flash-notifications-container\"}\n}\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 useEventListener(globalThis, \"pushNotification\", this.tt.onPushNotification)\n }\n\n render() {\n return (\n <View\n dataSet={dataSets.view}\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 = (event) => {\n const detail = digg(event, \"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,3 +1,4 @@
1
- declare const _default: import("react").MemoExoticComponent<any>;
1
+ declare const _default: React.MemoExoticComponent<any>;
2
2
  export default _default;
3
+ import React from "react";
3
4
  //# sourceMappingURL=notification.d.ts.map
@@ -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":";;kBAEmC,OAAO"}
@@ -1,8 +1,43 @@
1
- import { Pressable, Text, View } from "react-native";
2
- import { memo } from "react";
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
+ import classNames from "classnames";
3
5
  import PropTypes from "prop-types";
4
6
  import PropTypesExact from "prop-types-exact";
5
- import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component.js";
7
+ const styles = StyleSheet.create({
8
+ view: {
9
+ width: 300,
10
+ maxWidth: "100%",
11
+ marginBottom: 15,
12
+ padding: 15,
13
+ borderRadius: 11,
14
+ cursor: "pointer"
15
+ },
16
+ viewError: {
17
+ border: "1px solid rgba(161, 34, 32, 0.95)",
18
+ backgroundColor: "rgba(161, 34, 32, 0.87)"
19
+ },
20
+ viewSuccess: {
21
+ border: "1px solid rgba(0, 0, 0, 0.95)",
22
+ backgroundColor: "rgba(0, 0, 0, 0.87)"
23
+ },
24
+ viewAlert: {
25
+ border: "1px solid rgba(204, 51, 0, 0.95)",
26
+ backgroundColor: "rgba(204, 51, 0, 0.87)"
27
+ },
28
+ titleview: {
29
+ marginBottom: 5
30
+ },
31
+ titleText: {
32
+ color: "#fff",
33
+ fontWeight: "bold"
34
+ },
35
+ messageText: {
36
+ color: "#fff"
37
+ }
38
+ });
39
+ const titleViewDataSet = { class: "notification-title" };
40
+ const messageViewDataSet = { class: "notification-message" };
6
41
  export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
7
42
  static propTypes = PropTypesExact({
8
43
  className: PropTypes.string,
@@ -14,35 +49,27 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
14
49
  });
15
50
  render() {
16
51
  const { className, message, title, type } = this.props;
17
- const style = {
18
- width: 300,
19
- maxWidth: "100%",
20
- marginBottom: 15,
21
- padding: 15,
22
- borderRadius: 11,
23
- cursor: "pointer"
24
- };
25
- if (type == "error") {
26
- style.border = "1px solid rgba(161 34 32 / 95%)";
27
- style.background = "rgba(161 34 32 / 87%)";
28
- }
29
- if (type == "success") {
30
- style.border = "1px solid rgba(0 0 0 / 95%)";
31
- style.background = "rgba(0 0 0 / 87%)";
32
- }
33
- if (type == "alert") {
34
- style.border = "1px solid rgba(204 51 0 / 95%)";
35
- style.background = "rgba(204 51 0 / 87%)";
36
- }
37
- return (React.createElement(Pressable, { dataSet: { class: classNames("flash-notifications-notification", className), type }, onPress: this.onRemovedClicked },
38
- React.createElement(View, { style: style },
39
- React.createElement(View, { dataSet: { class: "notification-title" }, style: { marginBottom: 5 } },
40
- React.createElement(Text, { style: { color: "#fff", fontWeight: "bold" } }, title)),
41
- React.createElement(View, { dataSet: { class: "notification-message" } },
42
- React.createElement(Text, { style: { color: "#fff" } }, message)))));
52
+ const viewStyles = useMemo(() => {
53
+ const viewStyles = [styles.view];
54
+ if (type == "error")
55
+ viewStyles.push(styles.viewError);
56
+ if (type == "success")
57
+ viewStyles.push(styles.viewSuccess);
58
+ if (type == "alert")
59
+ viewStyles.push(styles.viewAlert);
60
+ return viewStyles;
61
+ }, [type]);
62
+ const pressableDataSet = useMemo(() => ({
63
+ class: classNames("flash-notifications-notification", className),
64
+ type
65
+ }), [className, type]);
66
+ return (React.createElement(Pressable, { dataSet: pressableDataSet, onPress: this.tt.onRemovedClicked },
67
+ React.createElement(View, { style: viewStyles },
68
+ React.createElement(View, { dataSet: titleViewDataSet, style: styles.titleview },
69
+ React.createElement(Text, { style: styles.titleText }, title)),
70
+ React.createElement(View, { dataSet: messageViewDataSet },
71
+ React.createElement(Text, { style: styles.messageText }, message)))));
43
72
  }
44
- onRemovedClicked = () => {
45
- this.props.onRemovedClicked(this.props.notification);
46
- };
73
+ onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification);
47
74
  }));
48
75
  //# sourceMappingURL=notification.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"not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A;YAC5C,KAAK,CAAC,UAAU,GAAG,mBAAmB,CAAA;QACxC,CAAC;QAGD,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;YACpB,KAAK,CAAC,MAAM,GAAG,gCAAgC,CAAA;YAC/C,KAAK,CAAC,UAAU,GAAG,sBAAsB,CAAA;QAC3C,CAAC;QAED,OAAO,CACL,oBAAC,SAAS,IAAC,OAAO,EAAE,EAAC,KAAK,EAAE,UAAU,CAAC,kCAAkC,EAAE,SAAS,CAAC,EAAE,IAAI,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB;YAC1H,oBAAC,IAAI,IAAC,KAAK,EAAE,KAAK;gBAChB,oBAAC,IAAI,IAAC,OAAO,EAAE,EAAC,KAAK,EAAE,oBAAoB,EAAC,EAAE,KAAK,EAAE,EAAC,YAAY,EAAE,CAAC,EAAC;oBACpE,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAC,IAC7C,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,IAAC,OAAO,EAAE,EAAC,KAAK,EAAE,sBAAsB,EAAC;oBAC5C,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAC,KAAK,EAAE,MAAM,EAAC,IACzB,OAAO,CACH,CACF,CACF,CACG,CACb,CAAA;IACH,CAAC;IAED,gBAAgB,GAAG,GAAG,EAAE;QACtB,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IACtD,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import {Pressable, Text, View} from \"react-native\"\nimport {memo} from \"react\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\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 style = {\n width: 300,\n maxWidth: \"100%\",\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\n }\n\n if (type == \"error\") {\n style.border = \"1px solid rgba(161 34 32 / 95%)\"\n style.background = \"rgba(161 34 32 / 87%)\"\n }\n\n if (type == \"success\") {\n style.border = \"1px solid rgba(0 0 0 / 95%)\"\n style.background = \"rgba(0 0 0 / 87%)\"\n }\n\n\n if (type == \"alert\") {\n style.border = \"1px solid rgba(204 51 0 / 95%)\"\n style.background = \"rgba(204 51 0 / 87%)\"\n }\n\n return (\n <Pressable dataSet={{class: classNames(\"flash-notifications-notification\", className), type}} onPress={this.onRemovedClicked}>\n <View style={style}>\n <View dataSet={{class: \"notification-title\"}} style={{marginBottom: 5}}>\n <Text style={{color: \"#fff\", fontWeight: \"bold\"}}>\n {title}\n </Text>\n </View>\n <View dataSet={{class: \"notification-message\"}}>\n <Text style={{color: \"#fff\"}}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => {\n this.props.onRemovedClicked(this.props.notification)\n }\n}))\n"]}
1
+ {"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,0CAA0C,CAAA;AACvF,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C,MAAM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AC,YAAY,CAAC,CAAA;CACtE,CAAC,CAAC,CAAA","sourcesContent":["import {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component.js\"\nimport React, {memo, useMemo} from \"react\"\nimport classNames from \"classnames\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\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"]}
@@ -60,7 +60,7 @@ export default class FlashMessage {
60
60
  type: args.type
61
61
  }
62
62
  });
63
- window.dispatchEvent(event);
63
+ globalThis.dispatchEvent(event);
64
64
  }
65
65
  }
66
66
  //# 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;AAEtE,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,YAAY,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACnD,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,KAAK,EAAE,EAAE;oBACzC,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;wBAC7B,OAAO,KAAK,CAAA;oBACd,CAAC;oBAED,OAAO,IAAI,CAAC,KAAK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G,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAA;QACrC,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAA;QAC1C,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,kBAAkB,EAAE;YAChD,MAAM,EAAE;gBACN,OAAO,EAAE,IAAI,CAAC,IAAI;gBAClB,KAAK;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;CACF","sourcesContent":["import BaseError from \"@kaspernj/api-maker/src/base-error\"\nimport ValidationError from \"@kaspernj/api-maker/src/validation-error\"\n\nexport default class FlashMessage {\n static alert(message) {\n FlashMessage.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 FlashMessage.alert(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else if (error instanceof ValidationError) {\n if (error.hasUnhandledErrors()) {\n FlashMessage.alert(error.message)\n } else {\n FlashMessage.alert(I18n.t(\"js.notification.couldnt_submit_because_of_validation_errors\"))\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 FlashMessage.show({type: \"success\", text: message})\n }\n\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = I18n.t(\"js.shared.alert\")\n } else if (args.type == \"error\") {\n title = I18n.t(\"js.shared.error\")\n } else if (args.type == \"success\") {\n title = I18n.t(\"js.shared.success\")\n } else {\n title = I18n.t(\"js.shared.notification\")\n }\n\n const event = new CustomEvent(\"pushNotification\", {\n detail: {\n message: args.text,\n title,\n type: args.type\n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ourcesContent":["import BaseError from \"@kaspernj/api-maker/src/base-error\"\nimport ValidationError from \"@kaspernj/api-maker/src/validation-error\"\n\nexport default class FlashMessage {\n static alert(message) {\n FlashMessage.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 FlashMessage.alert(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else if (error instanceof ValidationError) {\n if (error.hasUnhandledErrors()) {\n FlashMessage.alert(error.message)\n } else {\n FlashMessage.alert(I18n.t(\"js.notification.couldnt_submit_because_of_validation_errors\"))\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 FlashMessage.show({type: \"success\", text: message})\n }\n\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = I18n.t(\"js.shared.alert\")\n } else if (args.type == \"error\") {\n title = I18n.t(\"js.shared.error\")\n } else if (args.type == \"success\") {\n title = I18n.t(\"js.shared.success\")\n } else {\n title = I18n.t(\"js.shared.notification\")\n }\n\n const event = new CustomEvent(\"pushNotification\", {\n detail: {\n message: args.text,\n title,\n type: args.type\n }\n })\n\n globalThis.dispatchEvent(event)\n }\n}\n"]}
package/link.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ cd node_modules
4
+ rm -rf react
5
+ ln -s ../../gratisbyggetilbud_rails/node_modules/react
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flash-notifications",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "My new module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,9 +1,22 @@
1
- import {memo} from "react"
1
+ import React, {memo} from "react"
2
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
3
+ import {StyleSheet, View} from "react-native"
2
4
  import {digg} from "diggerize"
3
5
  import Notification from "./notification"
4
- import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
5
6
  import useEventListener from "@kaspernj/api-maker/src/use-event-listener"
6
- import {View} from "react-native"
7
+
8
+ const dataSets = {
9
+ view: {class: "flash-notifications-container"}
10
+ }
11
+
12
+ const styles = StyleSheet.create({
13
+ view: {
14
+ position: "fixed",
15
+ zIndex: 99999,
16
+ top: 20,
17
+ right: 20
18
+ }
19
+ })
7
20
 
8
21
  export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
9
22
  setup() {
@@ -12,26 +25,21 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
12
25
  notifications: []
13
26
  })
14
27
 
15
- useEventListener(window, "pushNotification", this.onPushNotification)
28
+ useEventListener(globalThis, "pushNotification", this.tt.onPushNotification)
16
29
  }
17
30
 
18
31
  render() {
19
32
  return (
20
33
  <View
21
- dataSet={{class: "flash-notifications-container"}}
22
- style={{
23
- position: "fixed",
24
- zIndex: 99999,
25
- top: 20,
26
- right: 20
27
- }}
34
+ dataSet={dataSets.view}
35
+ style={styles.view}
28
36
  >
29
- {this.state.notifications.map((notification) =>
37
+ {this.s.notifications.map((notification) =>
30
38
  <Notification
31
39
  key={`notification-${notification.count}`}
32
40
  message={notification.message}
33
41
  notification={notification}
34
- onRemovedClicked={this.onRemovedClicked}
42
+ onRemovedClicked={this.tt.onRemovedClicked}
35
43
  title={notification.title}
36
44
  type={notification.type}
37
45
  />
@@ -42,9 +50,9 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
42
50
 
43
51
  onPushNotification = (event) => {
44
52
  const detail = digg(event, "detail")
45
- const count = this.state.count + 1
53
+ const count = this.s.count + 1
46
54
 
47
- setTimeout(() => this.removeNotification(count), 4000)
55
+ // setTimeout(() => this.removeNotification(count), 4000)
48
56
 
49
57
  const notification = {
50
58
  count,
@@ -53,14 +61,14 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
53
61
  type: digg(detail, "type")
54
62
  }
55
63
 
56
- this.setState({count, notifications: this.state.notifications.concat([notification])})
64
+ this.setState({count, notifications: this.s.notifications.concat([notification])})
57
65
  }
58
66
 
59
67
  onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"))
60
68
 
61
69
  removeNotification = (count) => {
62
70
  this.setState({
63
- notifications: this.state.notifications.filter((notification) => notification.count != count)
71
+ notifications: this.s.notifications.filter((notification) => notification.count != count)
64
72
  })
65
73
  }
66
74
  }))
@@ -1,8 +1,45 @@
1
- import {Pressable, Text, View} from "react-native"
2
- import {memo} from "react"
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
+ import classNames from "classnames"
3
5
  import PropTypes from "prop-types"
4
6
  import PropTypesExact from "prop-types-exact"
5
- import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
7
+
8
+ const styles = StyleSheet.create({
9
+ view: {
10
+ width: 300,
11
+ maxWidth: "100%",
12
+ marginBottom: 15,
13
+ padding: 15,
14
+ borderRadius: 11,
15
+ cursor: "pointer"
16
+ },
17
+ viewError: {
18
+ border: "1px solid rgba(161, 34, 32, 0.95)",
19
+ backgroundColor: "rgba(161, 34, 32, 0.87)"
20
+ },
21
+ viewSuccess: {
22
+ border: "1px solid rgba(0, 0, 0, 0.95)",
23
+ backgroundColor: "rgba(0, 0, 0, 0.87)"
24
+ },
25
+ viewAlert: {
26
+ border: "1px solid rgba(204, 51, 0, 0.95)",
27
+ backgroundColor: "rgba(204, 51, 0, 0.87)"
28
+ },
29
+ titleview: {
30
+ marginBottom: 5
31
+ },
32
+ titleText: {
33
+ color: "#fff",
34
+ fontWeight: "bold"
35
+ },
36
+ messageText: {
37
+ color: "#fff"
38
+ }
39
+ })
40
+
41
+ const titleViewDataSet = {class: "notification-title"}
42
+ const messageViewDataSet = {class: "notification-message"}
6
43
 
7
44
  export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
8
45
  static propTypes = PropTypesExact({
@@ -17,41 +54,37 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
17
54
  render() {
18
55
  const {className, message, title, type} = this.props
19
56
 
20
- const style = {
21
- width: 300,
22
- maxWidth: "100%",
23
- marginBottom: 15,
24
- padding: 15,
25
- borderRadius: 11,
26
- cursor: "pointer"
27
- }
57
+ const viewStyles = useMemo(
58
+ () => {
59
+ const viewStyles = [styles.view]
28
60
 
29
- if (type == "error") {
30
- style.border = "1px solid rgba(161 34 32 / 95%)"
31
- style.background = "rgba(161 34 32 / 87%)"
32
- }
33
-
34
- if (type == "success") {
35
- style.border = "1px solid rgba(0 0 0 / 95%)"
36
- style.background = "rgba(0 0 0 / 87%)"
37
- }
61
+ if (type == "error") viewStyles.push(styles.viewError)
62
+ if (type == "success") viewStyles.push(styles.viewSuccess)
63
+ if (type == "alert") viewStyles.push(styles.viewAlert)
38
64
 
65
+ return viewStyles
66
+ },
67
+ [type]
68
+ )
39
69
 
40
- if (type == "alert") {
41
- style.border = "1px solid rgba(204 51 0 / 95%)"
42
- style.background = "rgba(204 51 0 / 87%)"
43
- }
70
+ const pressableDataSet = useMemo(
71
+ () => ({
72
+ class: classNames("flash-notifications-notification", className),
73
+ type
74
+ }),
75
+ [className, type]
76
+ )
44
77
 
45
78
  return (
46
- <Pressable dataSet={{class: classNames("flash-notifications-notification", className), type}} onPress={this.onRemovedClicked}>
47
- <View style={style}>
48
- <View dataSet={{class: "notification-title"}} style={{marginBottom: 5}}>
49
- <Text style={{color: "#fff", fontWeight: "bold"}}>
79
+ <Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>
80
+ <View style={viewStyles}>
81
+ <View dataSet={titleViewDataSet} style={styles.titleview}>
82
+ <Text style={styles.titleText}>
50
83
  {title}
51
84
  </Text>
52
85
  </View>
53
- <View dataSet={{class: "notification-message"}}>
54
- <Text style={{color: "#fff"}}>
86
+ <View dataSet={messageViewDataSet}>
87
+ <Text style={styles.messageText}>
55
88
  {message}
56
89
  </Text>
57
90
  </View>
@@ -60,7 +93,5 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
60
93
  )
61
94
  }
62
95
 
63
- onRemovedClicked = () => {
64
- this.props.onRemovedClicked(this.props.notification)
65
- }
96
+ onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)
66
97
  }))
@@ -63,6 +63,6 @@ export default class FlashMessage {
63
63
  }
64
64
  })
65
65
 
66
- window.dispatchEvent(event)
66
+ globalThis.dispatchEvent(event)
67
67
  }
68
68
  }