@42.nl/react-flash-messages 2.0.1 → 2.0.3-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/actions.js CHANGED
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetNextFlashMessageId = exports.addApocalypse = exports.addInfo = exports.addSuccess = exports.addWarning = exports.addError = exports.removeFlashMessage = exports.addFlashMessage = void 0;
3
+ exports.addFlashMessage = addFlashMessage;
4
+ exports.removeFlashMessage = removeFlashMessage;
5
+ exports.addError = addError;
6
+ exports.addWarning = addWarning;
7
+ exports.addSuccess = addSuccess;
8
+ exports.addInfo = addInfo;
9
+ exports.addApocalypse = addApocalypse;
10
+ exports.resetNextFlashMessageId = resetNextFlashMessageId;
4
11
  const service_1 = require("./service");
5
12
  /**
6
13
  * Each flash message gets an unique id so we can identify the
@@ -24,7 +31,6 @@ function addFlashMessage(flashMessageConfig) {
24
31
  }
25
32
  return flashMessage;
26
33
  }
27
- exports.addFlashMessage = addFlashMessage;
28
34
  /**
29
35
  * Manually removes the flash message from the flash message store.
30
36
  *
@@ -33,7 +39,6 @@ exports.addFlashMessage = addFlashMessage;
33
39
  function removeFlashMessage(flashMessage) {
34
40
  service_1.flashMessageService.removeFlashMessage(flashMessage, 'manually-removed');
35
41
  }
36
- exports.removeFlashMessage = removeFlashMessage;
37
42
  /**
38
43
  * Adds a flash message of the type 'ERROR' on the flash message queue.
39
44
  *
@@ -42,7 +47,6 @@ exports.removeFlashMessage = removeFlashMessage;
42
47
  function addError(config) {
43
48
  return addFlashMessage(Object.assign({ type: 'ERROR', duration: 10000 }, config));
44
49
  }
45
- exports.addError = addError;
46
50
  /**
47
51
  * Adds a flash message of the type 'WARNING' on the flash message queue.
48
52
  * After 7000 milliseconds it will automatically be removed
@@ -53,7 +57,6 @@ exports.addError = addError;
53
57
  function addWarning(config) {
54
58
  return addFlashMessage(Object.assign({ type: 'WARNING', duration: 7000 }, config));
55
59
  }
56
- exports.addWarning = addWarning;
57
60
  /**
58
61
  * Adds a flash message of the type 'SUCCESS' on the flash message queue.
59
62
  * After 2000 milliseconds it will automatically be removed
@@ -64,7 +67,6 @@ exports.addWarning = addWarning;
64
67
  function addSuccess(config) {
65
68
  return addFlashMessage(Object.assign({ type: 'SUCCESS', duration: 2000 }, config));
66
69
  }
67
- exports.addSuccess = addSuccess;
68
70
  /**
69
71
  * Adds a flash message of the type 'INFO' on the flash message queue.
70
72
  * After 5000 milliseconds it will automatically be removed
@@ -75,7 +77,6 @@ exports.addSuccess = addSuccess;
75
77
  function addInfo(config) {
76
78
  return addFlashMessage(Object.assign({ type: 'INFO', duration: 5000 }, config));
77
79
  }
78
- exports.addInfo = addInfo;
79
80
  /**
80
81
  * Adds a flash message of the type 'APOCALYPSE' on the flash message queue.
81
82
  * This message is never removed from the queue automatically.
@@ -85,7 +86,6 @@ exports.addInfo = addInfo;
85
86
  function addApocalypse(config) {
86
87
  return addFlashMessage(Object.assign({ type: 'APOCALYPSE', duration: false }, config));
87
88
  }
88
- exports.addApocalypse = addApocalypse;
89
89
  function addIdAndOnClick(flashMessage) {
90
90
  const onClick = flashMessage.onClick !== undefined ? flashMessage.onClick : noop;
91
91
  const onRemove = flashMessage.onRemove !== undefined ? flashMessage.onRemove : noop;
@@ -117,7 +117,6 @@ function addIdAndOnClick(flashMessage) {
117
117
  function resetNextFlashMessageId() {
118
118
  nextFlashMessageId = 1;
119
119
  }
120
- exports.resetNextFlashMessageId = resetNextFlashMessageId;
121
120
  // This function does not do anything, and is used as the default
122
121
  // for the onClick and onRemove
123
122
  function noop() {
package/lib/hooks.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFlashMessages = void 0;
3
+ exports.useFlashMessages = useFlashMessages;
4
4
  const react_1 = require("react");
5
5
  const service_1 = require("./service");
6
6
  /**
@@ -20,4 +20,3 @@ function useFlashMessages() {
20
20
  }, []);
21
21
  return state;
22
22
  }
23
- exports.useFlashMessages = useFlashMessages;
package/lib/models.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type OnFlashMessageClicked<Data> = (flashMessage: FlashMessage<Data>) => void;
1
+ export type OnFlashMessageClicked<Data> = (flashMessage: FlashMessage<Data>) => void;
2
2
  /**
3
3
  * The reason a flash message was removed.
4
4
  *
@@ -7,13 +7,13 @@ export declare type OnFlashMessageClicked<Data> = (flashMessage: FlashMessage<Da
7
7
  * it is 'manually-removed' it was because the `removeFlashMessage`
8
8
  * action was called.
9
9
  */
10
- export declare type FlashMessageRemovedReason = 'duration-elapsed' | 'manually-removed';
11
- export declare type OnFlashMessageRemoved<Data> = (flashMessage: FlashMessage<Data>, reason: FlashMessageRemovedReason) => void;
10
+ export type FlashMessageRemovedReason = 'duration-elapsed' | 'manually-removed';
11
+ export type OnFlashMessageRemoved<Data> = (flashMessage: FlashMessage<Data>, reason: FlashMessageRemovedReason) => void;
12
12
  /**
13
13
  * Represents a FlashMessage as it will be represented in the
14
14
  * flashMessageService.
15
15
  */
16
- export declare type FlashMessage<Data> = {
16
+ export type FlashMessage<Data> = {
17
17
  /**
18
18
  * The id of the flashMessage must be unique for each flash message.
19
19
  */
@@ -77,7 +77,7 @@ export declare type FlashMessage<Data> = {
77
77
  * creating a the FlashMessage from the FlashMessageConfig and they
78
78
  * will be re-written.
79
79
  */
80
- export declare type FlashMessageConfig<Data> = {
80
+ export type FlashMessageConfig<Data> = {
81
81
  /**
82
82
  * The type of flash message, can be useful to distinguish
83
83
  * between types of messages. For example you might have a type
@@ -119,7 +119,7 @@ export declare type FlashMessageConfig<Data> = {
119
119
  * etc etc, so the developer can quickly spawn flash messages without
120
120
  * resorting to the more low level `addFlashMessage` action.
121
121
  */
122
- export declare type FlashMessageCreatorConfig<Data> = {
122
+ export type FlashMessageCreatorConfig<Data> = {
123
123
  /**
124
124
  * The text message you want to show to the user.
125
125
  */
package/lib/provider.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { FlashMessage } from './models';
3
3
  export declare const FlashMessagesContext: React.Context<FlashMessage<unknown>[]>;
4
- export declare type Props = {
4
+ export type Props = {
5
5
  children: React.ReactNode;
6
6
  };
7
7
  /**
@@ -11,4 +11,4 @@ export declare type Props = {
11
11
  *
12
12
  * @param children The children to render
13
13
  */
14
- export declare function FlashMessagesProvider({ children }: Props): JSX.Element;
14
+ export declare function FlashMessagesProvider({ children }: Props): React.ReactElement;
package/lib/provider.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FlashMessagesProvider = exports.FlashMessagesContext = void 0;
6
+ exports.FlashMessagesContext = void 0;
7
+ exports.FlashMessagesProvider = FlashMessagesProvider;
7
8
  const react_1 = __importDefault(require("react"));
8
9
  const hooks_1 = require("./hooks");
9
10
  const service_1 = require("./service");
@@ -19,4 +20,3 @@ function FlashMessagesProvider({ children }) {
19
20
  const flashMessages = (0, hooks_1.useFlashMessages)();
20
21
  return (react_1.default.createElement(exports.FlashMessagesContext.Provider, { value: flashMessages }, children));
21
22
  }
22
- exports.FlashMessagesProvider = FlashMessagesProvider;
package/lib/service.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FlashMessage, FlashMessageRemovedReason } from './models';
2
- export declare type Subscriber = (flashMessages: FlashMessage<unknown>[]) => void;
3
- export declare type FlashMessageService = {
2
+ export type Subscriber = (flashMessages: FlashMessage<unknown>[]) => void;
3
+ export type FlashMessageService = {
4
4
  addFlashMessage(flashMessage: FlashMessage<unknown>): void;
5
5
  removeFlashMessage(flashMessage: FlashMessage<unknown>, reason: FlashMessageRemovedReason): void;
6
6
  clearFlashMessages(): void;
package/lib/service.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flashMessageService = exports.makeFlashMessageService = void 0;
3
+ exports.flashMessageService = void 0;
4
+ exports.makeFlashMessageService = makeFlashMessageService;
4
5
  function makeFlashMessageService() {
5
6
  let flashMessages = [];
6
7
  let subscribers = [];
@@ -47,5 +48,4 @@ function makeFlashMessageService() {
47
48
  subscribers.forEach((subscriber) => subscriber([...flashMessages]));
48
49
  }
49
50
  }
50
- exports.makeFlashMessageService = makeFlashMessageService;
51
51
  exports.flashMessageService = makeFlashMessageService();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42.nl/react-flash-messages",
3
- "version": "2.0.1",
3
+ "version": "2.0.3-rc.0",
4
4
  "description": "Storing flash messages via a nice api for use with React.",
5
5
  "files": [
6
6
  "lib"
@@ -20,69 +20,45 @@
20
20
  "url": "https://github.com/42BV/flash-messages/issues"
21
21
  },
22
22
  "homepage": "https://github.com/42BV/flash-messages#readme",
23
+ "peerDependencies": {
24
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
25
+ },
23
26
  "devDependencies": {
24
- "@testing-library/jest-dom": "5.16.2",
25
- "@testing-library/react": "12.1.4",
26
- "@types/jest": "27.4.1",
27
- "@types/react": "17.0.40",
28
- "@types/react-dom": "17.0.13",
29
- "@typescript-eslint/eslint-plugin": "5.14.0",
30
- "@typescript-eslint/parser": "5.14.0",
31
- "eslint": "8.10.0",
32
- "eslint-config-react-app": "7.0.0",
33
- "eslint-plugin-jest": "26.1.1",
34
- "eslint-plugin-react": "7.29.3",
35
- "eslint-plugin-react-hooks": "4.3.0",
36
- "husky": "7.0.4",
37
- "jest": "27.5.1",
38
- "jest-watch-typeahead": "1.0.0",
39
- "lint-staged": "12.3.5",
40
- "np": "^7.6.0",
41
- "prettier": "2.5.1",
42
- "react": "17.0.2",
43
- "react-dom": "17.0.2",
44
- "ts-jest": "27.1.3",
45
- "typescript": "4.6.2"
27
+ "@testing-library/jest-dom": "6.9.1",
28
+ "@testing-library/react": "16.3.2",
29
+ "@types/react": "19.2.13",
30
+ "@types/react-dom": "19.2.3",
31
+ "@vitest/coverage-v8": "4.0.18",
32
+ "eslint": "9.39.2",
33
+ "eslint-plugin-react": "7.37.5",
34
+ "eslint-plugin-react-hooks": "7.0.1",
35
+ "eslint-plugin-vitest": "0.5.4",
36
+ "jsdom": "28.0.0",
37
+ "husky": "9.1.7",
38
+ "lint-staged": "16.2.7",
39
+ "np": "11.0.2",
40
+ "prettier": "3.8.1",
41
+ "react": "19.2.4",
42
+ "react-dom": "19.2.4",
43
+ "typescript": "5.9.3",
44
+ "typescript-eslint": "8.54.0",
45
+ "vitest": "4.0.18"
46
46
  },
47
47
  "scripts": {
48
- "start": "jest --watch --coverage",
48
+ "start": "vitest --coverage",
49
49
  "clean": "rm -rf lib",
50
50
  "test": "npm run lint && npm run test:ts && npm run test:coverage",
51
51
  "test:ts": "tsc --version && tsc --noEmit",
52
- "test:coverage": "jest test --no-cache --coverage",
52
+ "test:coverage": "vitest run --coverage",
53
53
  "docs": "jekyll serve --source docs",
54
54
  "tsc": "npm run clean && tsc --version && tsc",
55
55
  "lint": "npm run lint:test && npm run lint:src",
56
56
  "lint:test": "eslint \"tests/**\" --max-warnings=0",
57
57
  "lint:src": "eslint \"src/**\" --max-warnings=0",
58
- "release": "npm run tsc && np --otp",
58
+ "release": "npm run tsc && np",
59
59
  "dev:publish": "./scripts/dev-publish.sh",
60
60
  "version": "npm run tsc && jekyll build",
61
- "prepare": "husky install"
62
- },
63
- "jest": {
64
- "preset": "ts-jest",
65
- "roots": [
66
- "src",
67
- "tests"
68
- ],
69
- "collectCoverageFrom": [
70
- "./src/**/*.{ts,tsx}"
71
- ],
72
- "coverageThreshold": {
73
- "global": {
74
- "branches": 100,
75
- "functions": 100,
76
- "lines": 100,
77
- "statements": 100
78
- }
79
- },
80
- "restoreMocks": true,
81
- "watchPlugins": [
82
- "jest-watch-typeahead/filename",
83
- "jest-watch-typeahead/testname"
84
- ],
85
- "testEnvironment": "jsdom"
61
+ "prepare": "husky"
86
62
  },
87
63
  "lint-staged": {
88
64
  "{src,test}/**/*.{js,jsx,json,scss,tsx,ts}": [