@semcore/notice-bubble 16.2.1 → 17.0.0-prerelease.18

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -4
  3. package/lib/cjs/NoticeBubble.js +222 -328
  4. package/lib/cjs/NoticeBubble.js.map +1 -1
  5. package/lib/cjs/NoticeBubble.type.js.map +1 -1
  6. package/lib/cjs/NoticeBubbleManager.js +67 -117
  7. package/lib/cjs/NoticeBubbleManager.js.map +1 -1
  8. package/lib/cjs/index.js +7 -9
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/cjs/translations/__intergalactic-dynamic-locales.js +16 -16
  11. package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
  12. package/lib/cjs/utils.js +32 -43
  13. package/lib/cjs/utils.js.map +1 -1
  14. package/lib/es6/NoticeBubble.js +207 -314
  15. package/lib/es6/NoticeBubble.js.map +1 -1
  16. package/lib/es6/NoticeBubble.type.js.map +1 -1
  17. package/lib/es6/NoticeBubbleManager.js +60 -111
  18. package/lib/es6/NoticeBubbleManager.js.map +1 -1
  19. package/lib/es6/index.js +0 -1
  20. package/lib/es6/index.js.map +1 -1
  21. package/lib/es6/translations/__intergalactic-dynamic-locales.js +15 -15
  22. package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
  23. package/lib/es6/utils.js +24 -36
  24. package/lib/es6/utils.js.map +1 -1
  25. package/lib/esm/NoticeBubble.mjs +209 -293
  26. package/lib/esm/NoticeBubbleManager.mjs +60 -111
  27. package/lib/esm/index.mjs +3 -7
  28. package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
  29. package/lib/esm/utils.mjs +24 -36
  30. package/lib/types/NoticeBubble.d.ts +2 -31
  31. package/lib/types/NoticeBubble.type.d.ts +6 -45
  32. package/lib/types/NoticeBubbleManager.d.ts +2 -4
  33. package/lib/types/index.d.ts +0 -1
  34. package/package.json +8 -10
@@ -1,127 +1,76 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
2
  import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
6
3
  import EventEmitter from "@semcore/core/lib/utils/eventEmitter";
7
- import { setFocus } from "@semcore/core/lib/utils/use/useFocusLock";
8
4
  import React from "react";
9
- var EVENT_NAME = "CHANGE";
10
- var NoticeBubbleManager = /* @__PURE__ */ (function() {
11
- function NoticeBubbleManager2() {
12
- _classCallCheck(this, NoticeBubbleManager2);
5
+ const EVENT_NAME = "CHANGE";
6
+ class NoticeBubbleManager {
7
+ constructor() {
13
8
  _defineProperty(this, "items", []);
14
9
  _defineProperty(this, "emitter", new EventEmitter());
15
10
  _defineProperty(this, "counter", 0);
16
- _defineProperty(this, "replaceTimer", null);
17
11
  }
18
- return _createClass(NoticeBubbleManager2, [{
19
- key: "addListener",
20
- value: function addListener(fn) {
21
- return this.emitter.subscribe(EVENT_NAME, fn);
22
- }
23
- }, {
24
- key: "emit",
25
- value: function emit() {
26
- this.emitter.emit(EVENT_NAME, this.items);
27
- }
28
- }, {
29
- key: "add",
30
- value: function add(props) {
31
- var _this = this;
32
- var uid = this.counter++;
33
- var ref = /* @__PURE__ */ React.createRef();
34
- var focus = function focus2() {
35
- setTimeout(function() {
36
- if (ref.current) {
37
- setFocus(ref.current);
38
- }
39
- }, 0);
40
- };
41
- var item = _objectSpread(_objectSpread({
42
- type: "info",
43
- uid,
44
- visible: props.initialAnimation ? true : void 0,
45
- forwardRef: ref
46
- }, props), {}, {
47
- onClose: callAllEventHandlers(props.onClose, function() {
48
- _this.remove(uid);
49
- })
50
- });
51
- this.items.push(item);
52
- this.emit();
53
- return {
54
- uid,
55
- update: this.update.bind(this, uid),
56
- remove: this.remove.bind(this, uid),
57
- ref,
58
- // todo Brauer Ilia: remove this property, because we added logic about autofocus in Notice
59
- focus
60
- };
61
- }
62
- }, {
63
- key: "update",
64
- value: function update(uid, props) {
65
- var index = this.items.findIndex(function(item) {
66
- return item.uid === uid;
67
- });
68
- if (index !== -1) {
69
- this.items[index] = _objectSpread(_objectSpread({}, this.items[index]), props);
70
- this.emit();
71
- return true;
72
- }
73
- return false;
74
- }
75
- }, {
76
- key: "replace",
77
- value: function replace(uid, props) {
78
- var _this2 = this;
79
- if (this.replaceTimer) {
80
- clearTimeout(this.replaceTimer);
81
- }
82
- this.remove(uid);
83
- this.replaceTimer = setTimeout(function() {
84
- _this2.add(props);
12
+ addListener(fn) {
13
+ return this.emitter.subscribe(EVENT_NAME, fn);
14
+ }
15
+ emit() {
16
+ this.emitter.emit(EVENT_NAME, this.items);
17
+ }
18
+ add(props) {
19
+ const uid = this.counter++;
20
+ const ref = /* @__PURE__ */ React.createRef();
21
+ const item = {
22
+ type: "info",
23
+ uid,
24
+ visible: props.initialAnimation ? true : void 0,
25
+ forwardRef: ref,
26
+ ...props,
27
+ onClose: callAllEventHandlers(props.onClose, () => {
28
+ this.remove(uid);
29
+ })
30
+ };
31
+ this.items.push(item);
32
+ this.emit();
33
+ return {
34
+ uid,
35
+ update: this.replace.bind(this, uid),
36
+ remove: this.remove.bind(this, uid),
37
+ ref
38
+ };
39
+ }
40
+ replace(uid, props) {
41
+ this.remove(uid);
42
+ return new Promise((resolve) => {
43
+ setTimeout(() => {
44
+ resolve(this.add(props));
85
45
  }, 300);
46
+ });
47
+ }
48
+ replaceLast(props) {
49
+ const item = this.items[this.items.length - 1];
50
+ if (item == null ? void 0 : item.visible) {
51
+ this.remove(this.counter - 1);
86
52
  }
87
- }, {
88
- key: "replaceLast",
89
- value: function replaceLast(props) {
90
- var _this3 = this;
91
- if (this.replaceTimer) {
92
- clearTimeout(this.replaceTimer);
93
- }
94
- var item = this.items[this.items.length - 1];
95
- if (item !== null && item !== void 0 && item.visible) {
96
- this.remove(this.counter - 1);
97
- }
98
- this.replaceTimer = setTimeout(function() {
99
- _this3.add(props);
53
+ return new Promise((resolve) => {
54
+ setTimeout(() => {
55
+ resolve(this.add(props));
100
56
  }, 300);
101
- }
102
- }, {
103
- key: "remove",
104
- value: function remove(uid) {
105
- var _this4 = this;
106
- var item = this.items.find(function(item2) {
107
- return item2.uid === uid;
108
- });
109
- if (item) {
110
- item.visible = false;
111
- setTimeout(function() {
112
- _this4.items = _this4.items.filter(function(item2) {
113
- return item2.uid !== uid;
114
- });
115
- _this4.emit();
116
- }, 1e3);
57
+ });
58
+ }
59
+ remove(uid) {
60
+ const item = this.items.find((item2) => item2.uid === uid);
61
+ if (item) {
62
+ item.visible = false;
63
+ setTimeout(() => {
64
+ this.items = this.items.filter((item2) => item2.uid !== uid);
117
65
  this.emit();
118
- return true;
119
- }
120
- return false;
66
+ }, 1e3);
67
+ this.emit();
68
+ return true;
121
69
  }
122
- }]);
123
- })();
124
- var noticeBubbleDefaultManager = new NoticeBubbleManager();
70
+ return false;
71
+ }
72
+ }
73
+ const noticeBubbleDefaultManager = new NoticeBubbleManager();
125
74
  export {
126
75
  NoticeBubbleManager,
127
76
  noticeBubbleDefaultManager as default
package/lib/esm/index.mjs CHANGED
@@ -1,11 +1,7 @@
1
- import { NoticeBubble, default as default2, NoticeBubbleWarning } from "./NoticeBubble.mjs";
2
- import noticeBubbleDefaultManager from "./NoticeBubbleManager.mjs";
3
- import { NoticeBubbleManager } from "./NoticeBubbleManager.mjs";
1
+ import { default as default2 } from "./NoticeBubble.mjs";
2
+ import { NoticeBubbleManager, default as default3 } from "./NoticeBubbleManager.mjs";
4
3
  export {
5
- NoticeBubble,
6
4
  default2 as NoticeBubbleContainer,
7
5
  NoticeBubbleManager,
8
- NoticeBubbleWarning,
9
- noticeBubbleDefaultManager as default,
10
- noticeBubbleDefaultManager
6
+ default3 as noticeBubbleDefaultManager
11
7
  };
@@ -12,7 +12,7 @@ import sv from "./sv.json.mjs";
12
12
  import tr from "./tr.json.mjs";
13
13
  import vi from "./vi.json.mjs";
14
14
  import zh from "./zh.json.mjs";
15
- var localizedMessages = {
15
+ const localizedMessages = {
16
16
  de,
17
17
  en,
18
18
  es,
package/lib/esm/utils.mjs CHANGED
@@ -1,9 +1,6 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- var Timer = /* @__PURE__ */ (function() {
5
- function Timer2(callback, delay) {
6
- _classCallCheck(this, Timer2);
2
+ class Timer {
3
+ constructor(callback, delay) {
7
4
  _defineProperty(this, "delay", void 0);
8
5
  _defineProperty(this, "callback", void 0);
9
6
  _defineProperty(this, "remaining", void 0);
@@ -16,40 +13,31 @@ var Timer = /* @__PURE__ */ (function() {
16
13
  this.paused = false;
17
14
  this.resume();
18
15
  }
19
- return _createClass(Timer2, [{
20
- key: "pause",
21
- value: function pause() {
22
- if (this.timerId) {
23
- clearTimeout(this.timerId);
24
- }
25
- this.remaining -= Date.now() - this.start;
26
- this.paused = true;
16
+ pause() {
17
+ if (this.timerId) {
18
+ clearTimeout(this.timerId);
27
19
  }
28
- }, {
29
- key: "resume",
30
- value: function resume() {
31
- this.start = Date.now();
32
- this.paused = false;
33
- if (this.timerId) {
34
- clearTimeout(this.timerId);
35
- }
36
- this.timerId = window.setTimeout(this.callback, this.remaining);
37
- }
38
- }, {
39
- key: "reset",
40
- value: function reset() {
41
- this.remaining = this.delay;
42
- this.resume();
20
+ this.remaining -= Date.now() - this.start;
21
+ this.paused = true;
22
+ }
23
+ resume() {
24
+ this.start = Date.now();
25
+ this.paused = false;
26
+ if (this.timerId) {
27
+ clearTimeout(this.timerId);
43
28
  }
44
- }, {
45
- key: "clear",
46
- value: function clear() {
47
- if (this.timerId) {
48
- clearTimeout(this.timerId);
49
- }
29
+ this.timerId = window.setTimeout(this.callback, this.remaining);
30
+ }
31
+ reset() {
32
+ this.remaining = this.delay;
33
+ this.resume();
34
+ }
35
+ clear() {
36
+ if (this.timerId) {
37
+ clearTimeout(this.timerId);
50
38
  }
51
- }]);
52
- })();
39
+ }
40
+ }
53
41
  export {
54
42
  Timer
55
43
  };
@@ -1,33 +1,4 @@
1
- import { Component } from '@semcore/core';
2
1
  import type { Intergalactic } from '@semcore/core';
3
- import type { AddedNoticeMeta, NoticeBubbleContainerProps, NoticeBubbleProps, NoticeBubbleWarningProps } from './NoticeBubble.type';
4
- import type { NoticeBubbleManager } from './NoticeBubbleManager';
5
- declare class NoticeBubbleView extends Component<{
6
- manager: NoticeBubbleManager;
7
- } & (NoticeBubbleProps | NoticeBubbleWarningProps)> {
8
- static defaultProps: {
9
- duration: number;
10
- type: string;
11
- manager: NoticeBubbleManager;
12
- };
13
- _notice: null | AddedNoticeMeta;
14
- componentDidMount(): void;
15
- componentWillUnmount(): void;
16
- componentDidUpdate(): void;
17
- render(): null;
18
- }
19
- declare class NoticeBubbleWarningView extends NoticeBubbleView {
20
- static defaultProps: {
21
- duration: number;
22
- type: string;
23
- manager: NoticeBubbleManager;
24
- };
25
- }
26
- declare const NoticeBubbleContainer: Intergalactic.Component<"div", NoticeBubbleContainerProps> & {
27
- Info: typeof NoticeBubbleView;
28
- Warning: typeof NoticeBubbleWarningView;
29
- };
30
- declare const NoticeBubble: typeof NoticeBubbleView;
31
- declare const NoticeBubbleWarning: typeof NoticeBubbleWarningView;
32
- export { NoticeBubble, NoticeBubbleWarning };
2
+ import type { NoticeBubbleContainerProps } from './NoticeBubble.type';
3
+ declare const NoticeBubbleContainer: Intergalactic.Component<"div", NoticeBubbleContainerProps>;
33
4
  export default NoticeBubbleContainer;
@@ -1,32 +1,25 @@
1
1
  import type { PortalProps, BoxProps } from '@semcore/base-components';
2
- import type { UnknownProperties, Intergalactic } from '@semcore/core';
2
+ import type { Intergalactic } from '@semcore/core';
3
3
  import type { useI18n } from '@semcore/core/lib/utils/enhances/WithI18n';
4
- import type { NodeByRef } from '@semcore/core/lib/utils/ref';
5
4
  import type { RefObject } from 'react';
6
- /** @deprecated */
7
- export interface INoticeBubbleContainerProps extends NoticeBubbleContainerProps, UnknownProperties {
8
- }
9
5
  /**
10
6
  * @deprecated. Pass noticeBubbleContainer property from window.sm2.getNoticeBubbleContainer()
11
7
  */
12
8
  export type NoticeBubbleContainerPortalProps = PortalProps;
13
9
  export type NoticeBubbleContainerProps = BoxProps & NoticeBubbleContainerPortalProps & {
14
- /** Ref or element to mount bubbles in. You should use element form window.sm2.getNoticeBubbleContainer() */
15
- containerNode?: NodeByRef | null;
10
+ /** Ref to mount bubbles in. You should use element form window.sm2.getNoticeBubbleContainer() */
11
+ containerNode?: HTMLElement | null;
16
12
  /** Manager copy */
17
13
  manager?: NoticeBubbleManagerClass;
18
14
  /** Specifies the locale for i18n support */
19
15
  locale?: string;
20
16
  };
21
17
  export type NoticeBubbleViewItemProps = NoticeBubbleProps & {
22
- containerNode?: NodeByRef;
18
+ containerNode?: HTMLElement;
23
19
  animationDuration: number;
24
20
  getI18nText: ReturnType<typeof useI18n>;
25
21
  styles: React.DetailedHTMLProps<React.StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement> | undefined;
26
22
  };
27
- /** @deprecated */
28
- export interface INoticeBubbleProps extends NoticeBubbleProps, UnknownProperties {
29
- }
30
23
  export type NoticeBubbleProps = BoxProps & {
31
24
  /** Notice type */
32
25
  type?: 'info' | 'warning';
@@ -65,38 +58,23 @@ export type NoticeBubbleProps = BoxProps & {
65
58
  manager?: NoticeBubbleManagerClass;
66
59
  icon?: React.ReactElement;
67
60
  };
68
- /** @deprecated */
69
- export interface INoticeBubbleInfoProps extends NoticeBubbleInfoProps, UnknownProperties {
70
- }
71
61
  export type NoticeBubbleInfoProps = NoticeBubbleProps & {
72
62
  readonly type?: 'info';
73
63
  };
74
- /** @deprecated */
75
- export interface INoticeBubbleWarningProps extends NoticeBubbleWarningProps, UnknownProperties {
76
- }
77
64
  export type NoticeBubbleWarningProps = NoticeBubbleProps & {
78
65
  readonly type?: 'warning';
79
66
  };
80
67
  export type AddedNoticeMeta = {
81
68
  uid: number;
82
- update: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => boolean;
69
+ update: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => Promise<AddedNoticeMeta>;
83
70
  remove: () => boolean;
84
71
  ref: RefObject<HTMLElement>;
85
- focus: () => void;
86
72
  };
87
- /** @deprecated */
88
- export interface INoticeBubbleManager extends NoticeBubbleManagerClass, UnknownProperties {
89
- }
90
73
  export type NoticeBubbleManagerClass = {
91
74
  /**
92
75
  * Creates and shows a notice.
93
76
  * */
94
77
  add: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => AddedNoticeMeta;
95
- /**
96
- * Updates notice by uid.
97
- * @deprecated use replace instead.
98
- */
99
- update: (uid: number, props: Partial<NoticeBubbleInfoProps> | Partial<NoticeBubbleWarningProps>) => boolean;
100
78
  /**
101
79
  * Removes notice by uid.
102
80
  * */
@@ -110,21 +88,4 @@ export type NoticeBubbleManagerClass = {
110
88
  */
111
89
  replaceLast: (props: NoticeBubbleInfoProps | NoticeBubbleWarningProps) => void;
112
90
  };
113
- /**
114
- * @deprecated use `NoticeBubbleManager` instead.
115
- * */
116
- export declare const NoticeBubble: Intergalactic.Component<'div', NoticeBubbleInfoProps>;
117
- /**
118
- * @deprecated use `NoticeBubbleManager` instead.
119
- * */
120
- export declare const NoticeBubbleWarning: Intergalactic.Component<'div', NoticeBubbleWarningProps>;
121
- export declare const NoticeBubbleContainer: Intergalactic.Component<'div', NoticeBubbleContainerProps> & {
122
- /**
123
- * @deprecated use `NoticeBubbleManager` instead.
124
- * */
125
- Info: typeof NoticeBubble;
126
- /**
127
- * @deprecated use `NoticeBubbleManager` instead.
128
- * */
129
- Warning: typeof NoticeBubbleWarning;
130
- };
91
+ export declare const NoticeBubbleContainer: Intergalactic.Component<'div', NoticeBubbleContainerProps>;
@@ -10,13 +10,11 @@ declare class NoticeBubbleManager implements NoticeBubbleManagerClass {
10
10
  private items;
11
11
  private emitter;
12
12
  private counter;
13
- private replaceTimer;
14
13
  addListener(fn: (items: NoticeItem[]) => void): () => void;
15
14
  private emit;
16
15
  add(props: NoticeBubbleInfoProps | NoticeBubbleWarningProps): AddedNoticeMeta;
17
- update(uid: number, props: NoticeBubbleInfoProps | NoticeBubbleWarningProps): boolean;
18
- replace(uid: number, props: NoticeBubbleInfoProps | NoticeBubbleWarningProps): void;
19
- replaceLast(props: NoticeBubbleInfoProps | NoticeBubbleWarningProps): void;
16
+ replace(uid: number, props: NoticeBubbleInfoProps | NoticeBubbleWarningProps): Promise<AddedNoticeMeta>;
17
+ replaceLast(props: NoticeBubbleInfoProps | NoticeBubbleWarningProps): Promise<AddedNoticeMeta>;
20
18
  remove(uid: number): boolean;
21
19
  }
22
20
  declare const noticeBubbleDefaultManager: NoticeBubbleManager;
@@ -3,6 +3,5 @@ import type { NoticeBubbleContainerProps, NoticeBubbleInfoProps, NoticeBubbleWar
3
3
  import { default as noticeBubbleDefaultManager } from './NoticeBubbleManager';
4
4
  export * from './NoticeBubble';
5
5
  export * from './NoticeBubbleManager';
6
- export default noticeBubbleDefaultManager;
7
6
  export { NoticeBubbleContainer, noticeBubbleDefaultManager };
8
7
  export type { NoticeBubbleContainerProps, NoticeBubbleInfoProps, NoticeBubbleWarningProps, AddedNoticeMeta, };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/notice-bubble",
3
3
  "description": "Semrush NoticeBubble Component",
4
- "version": "16.2.1",
4
+ "version": "17.0.0-prerelease.18",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
@@ -14,14 +14,11 @@
14
14
  "types": "./lib/types/index.d.ts"
15
15
  },
16
16
  "dependencies": {
17
- "@semcore/icon": "16.7.3",
18
- "@semcore/portal": "16.0.11",
19
- "@semcore/flex-box": "16.0.11",
20
- "@semcore/animation": "16.0.7",
21
- "@semcore/button": "16.0.12"
17
+ "@semcore/button": "^16.0.13-prerelease.18"
22
18
  },
23
19
  "peerDependencies": {
24
- "@semcore/base-components": "^16.0.0"
20
+ "@semcore/base-components": "^17.0.0-prerelease.18",
21
+ "@semcore/icon": "^16.7.2-prerelease.18"
25
22
  },
26
23
  "repository": {
27
24
  "type": "git",
@@ -29,9 +26,10 @@
29
26
  "directory": "semcore/notice-bubble"
30
27
  },
31
28
  "devDependencies": {
32
- "@semcore/base-components": "16.4.2",
33
- "@semcore/core": "16.5.1",
34
- "@semcore/testing-utils": "1.0.0"
29
+ "@semcore/base-components": "17.0.0-prerelease.18",
30
+ "@semcore/core": "17.0.0-prerelease.18",
31
+ "@semcore/testing-utils": "1.0.0",
32
+ "@semcore/icon": "16.7.2-prerelease.18"
35
33
  },
36
34
  "scripts": {
37
35
  "build": "pnpm semcore-builder && pnpm vite build"