@jetbrains/ring-ui 7.0.0-beta.4 → 7.0.0-beta.5
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/components/auth/auth__core.js +4 -1
- package/components/auth/storage.js +1 -2
- package/components/global/variables.css +2 -0
- package/components/global/variables_dark.css +2 -0
- package/components/query-assist/query-assist.js +2 -2
- package/components/select/select.js +3 -3
- package/components/storage/storage.d.ts +2 -3
- package/components/storage/storage.js +1 -21
- package/components/user-agreement/service.d.ts +2 -1
- package/package.json +19 -20
- package/components/storage/storage__fallback.d.ts +0 -79
- package/components/storage/storage__fallback.js +0 -181
|
@@ -137,7 +137,10 @@ export default class Auth {
|
|
|
137
137
|
this.addListener(LOGOUT_EVENT, this.config.onLogout);
|
|
138
138
|
}
|
|
139
139
|
if (this.config.reloadOnUserChange) {
|
|
140
|
-
this.addListener(USER_CHANGED_EVENT, () =>
|
|
140
|
+
this.addListener(USER_CHANGED_EVENT, () => {
|
|
141
|
+
// Timeout is needed to ensure all other listeners triggered before stopping current page
|
|
142
|
+
setTimeout(() => this._reloadCurrentPage());
|
|
143
|
+
});
|
|
141
144
|
}
|
|
142
145
|
this.addListener(LOGOUT_POSTPONED_EVENT, () => this._setPostponed(true));
|
|
143
146
|
this.addListener(USER_CHANGE_POSTPONED_EVENT, () => this._setPostponed(true));
|
|
@@ -39,8 +39,7 @@ export default class AuthStorage {
|
|
|
39
39
|
this.stateTTL = config.stateTTL || DEFAULT_STATE_TTL;
|
|
40
40
|
this._lastMessage = null;
|
|
41
41
|
const StorageConstructor = config.storage || Storage;
|
|
42
|
-
this.stateQuota =
|
|
43
|
-
DEFAULT_STATE_QUOTA, StorageConstructor.QUOTA || Infinity);
|
|
42
|
+
this.stateQuota = config.stateQuota || DEFAULT_STATE_QUOTA;
|
|
44
43
|
this._stateStorage = new StorageConstructor({
|
|
45
44
|
cookieName: 'ring-state'
|
|
46
45
|
});
|
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
--ring-popup-background-color: rgb(var(--ring-popup-background-components)); /* #FFFFFF */
|
|
91
91
|
--ring-sidebar-background-components: 247, 248, 250;
|
|
92
92
|
--ring-sidebar-background-color: rgb(var(--ring-sidebar-background-components)); /* #F7F8FA */
|
|
93
|
+
--ring-secondary-background-components: 247, 248, 250;
|
|
94
|
+
--ring-secondary-background-color: rgb(var(--ring-secondary-background-components)); /* #F7F8FA */
|
|
93
95
|
--ring-selected-background-components: 212, 226, 255;
|
|
94
96
|
--ring-selected-background-color: rgb(var(--ring-selected-background-components)); /* #D4E2FF */
|
|
95
97
|
--ring-hover-background-components: 237, 243, 255;
|
|
@@ -76,6 +76,8 @@
|
|
|
76
76
|
--ring-popup-background-color: rgb(var(--ring-popup-background-components)); /* #393B40 */
|
|
77
77
|
--ring-sidebar-background-components: 43, 45, 48;
|
|
78
78
|
--ring-sidebar-background-color: rgb(var(--ring-sidebar-background-components)); /* #2B2D30 */
|
|
79
|
+
--ring-secondary-background-components: 43, 45, 48;
|
|
80
|
+
--ring-secondary-background-color: rgb(var(--ring-secondary-background-components)); /* #2B2D30 */
|
|
79
81
|
--ring-selected-background-components: 46, 67, 110;
|
|
80
82
|
--ring-selected-background-color: rgb(var(--ring-selected-background-components)); /* #2E436E */
|
|
81
83
|
--ring-hover-background-components: 37, 50, 77;
|
|
@@ -2,7 +2,7 @@ import { Component } from 'react';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import debounce from 'just-debounce-it';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
|
-
import
|
|
5
|
+
import { dequal } from 'dequal';
|
|
6
6
|
import searchIcon from '@jetbrains/icons/search';
|
|
7
7
|
import closeIcon from '@jetbrains/icons/close-12px';
|
|
8
8
|
import getUID from '../global/get-uid';
|
|
@@ -386,7 +386,7 @@ export default class QueryAssist extends Component {
|
|
|
386
386
|
};
|
|
387
387
|
this.immediateState.suggestionsQuery = query;
|
|
388
388
|
// Do not update deep equal styleRanges to simplify shouldComponentUpdate check
|
|
389
|
-
if (!
|
|
389
|
+
if (!dequal(this.state.styleRanges, styleRanges)) {
|
|
390
390
|
state.styleRanges = styleRanges;
|
|
391
391
|
}
|
|
392
392
|
this.immediateState.selection = this.caret?.getPosition({ avoidFocus: true });
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import chevronDownIcon from '@jetbrains/icons/chevron-down';
|
|
5
5
|
import closeIcon from '@jetbrains/icons/close-12px';
|
|
6
|
-
import
|
|
6
|
+
import { dequal } from 'dequal';
|
|
7
7
|
import { Anchor } from '../dropdown/dropdown';
|
|
8
8
|
import Avatar, { Size as AvatarSize } from '../avatar/avatar';
|
|
9
9
|
import Popup from '../popup/popup';
|
|
@@ -257,7 +257,7 @@ export default class Select extends Component {
|
|
|
257
257
|
Object.assign(nextState, { selectedIndex });
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
if (prevMultiple !== multiple && !
|
|
260
|
+
if (prevMultiple !== multiple && !dequal(prevMultiple, multiple)) {
|
|
261
261
|
nextState.selected = multiple ? [] : null;
|
|
262
262
|
}
|
|
263
263
|
if (multiple && !nextState.selected) {
|
|
@@ -296,7 +296,7 @@ export default class Select extends Component {
|
|
|
296
296
|
else if (!prevState.showPopup && showPopup) {
|
|
297
297
|
onOpen();
|
|
298
298
|
}
|
|
299
|
-
if (multiple !== prevProps.multiple && !
|
|
299
|
+
if (multiple !== prevProps.multiple && !dequal(multiple, prevProps.multiple)) {
|
|
300
300
|
onChange(selected);
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import LocalStorage from './storage__local';
|
|
1
2
|
export interface StorageConfig {
|
|
2
3
|
type?: 'local' | 'session' | null | undefined;
|
|
3
4
|
cookieName?: string | null | undefined;
|
|
@@ -12,7 +13,5 @@ export interface StorageInterface {
|
|
|
12
13
|
}
|
|
13
14
|
export interface StorageClass {
|
|
14
15
|
new (config?: StorageConfig | undefined): StorageInterface;
|
|
15
|
-
QUOTA?: number;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
export default ActualStorage;
|
|
17
|
+
export default LocalStorage;
|
|
@@ -1,22 +1,2 @@
|
|
|
1
1
|
import LocalStorage from './storage__local';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @name Storage
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* @constructor
|
|
8
|
-
* @extends {LocalStorage}
|
|
9
|
-
*/
|
|
10
|
-
let Storage = LocalStorage;
|
|
11
|
-
// Using try/catch here because of IE10+ protected mode and other browsers' quirks
|
|
12
|
-
// See https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
|
|
13
|
-
try {
|
|
14
|
-
const temp = 'testStorage';
|
|
15
|
-
localStorage.setItem(temp, temp);
|
|
16
|
-
localStorage.removeItem(temp);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
Storage = FallbackStorage;
|
|
20
|
-
}
|
|
21
|
-
const ActualStorage = Storage;
|
|
22
|
-
export default ActualStorage;
|
|
2
|
+
export default LocalStorage;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import Storage from '../storage/storage';
|
|
2
3
|
import { UserAgreementAttrs, UserAgreementTranslations } from './user-agreement';
|
|
3
4
|
export declare const showMessage = "userAgreementShow";
|
|
4
5
|
export declare const hideMessage = "userAgreementHide";
|
|
@@ -42,7 +43,7 @@ export default class UserAgreementService {
|
|
|
42
43
|
interval: number;
|
|
43
44
|
container: HTMLDivElement;
|
|
44
45
|
reactRoot: import("react-dom/client").Root;
|
|
45
|
-
storage:
|
|
46
|
+
storage: Storage;
|
|
46
47
|
checkingPromise: Promise<[Agreement, Consent]> | null;
|
|
47
48
|
guest: boolean | null | undefined;
|
|
48
49
|
userAgreement: Agreement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetbrains/ring-ui",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.5",
|
|
4
4
|
"description": "JetBrains UI library",
|
|
5
5
|
"author": "JetBrains",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"readmeFilename": "README.md",
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@babel/cli": "^7.
|
|
79
|
+
"@babel/cli": "^7.25.6",
|
|
80
80
|
"@babel/eslint-parser": "^7.25.1",
|
|
81
81
|
"@csstools/css-parser-algorithms": "^3.0.0",
|
|
82
82
|
"@csstools/stylelint-no-at-nest-rule": "^4.0.0",
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"@storybook/test-runner": "^0.19.1",
|
|
100
100
|
"@storybook/theming": "8.2.9",
|
|
101
101
|
"@testing-library/dom": "^10.4.0",
|
|
102
|
-
"@testing-library/react": "^16.0.
|
|
102
|
+
"@testing-library/react": "^16.0.1",
|
|
103
103
|
"@testing-library/user-event": "^14.5.2",
|
|
104
|
-
"@types/chai": "^4.3.
|
|
105
|
-
"@types/chai-as-promised": "^
|
|
104
|
+
"@types/chai": "^4.3.19",
|
|
105
|
+
"@types/chai-as-promised": "^8.0.0",
|
|
106
106
|
"@types/chai-dom": "0.0.10",
|
|
107
107
|
"@types/chai-enzyme": "^0.6.13",
|
|
108
108
|
"@types/enzyme": "^3.10.18",
|
|
@@ -112,14 +112,14 @@
|
|
|
112
112
|
"@types/sinon": "^17.0.3",
|
|
113
113
|
"@types/sinon-chai": "^3.2.12",
|
|
114
114
|
"@types/webpack-env": "^1.18.5",
|
|
115
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
116
|
-
"@typescript-eslint/parser": "^8.
|
|
115
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
116
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
117
117
|
"@vitejs/plugin-react": "^4.3.1",
|
|
118
118
|
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
|
|
119
119
|
"acorn": "^8.12.1",
|
|
120
|
-
"axe-playwright": "^2.0.
|
|
120
|
+
"axe-playwright": "^2.0.2",
|
|
121
121
|
"babel-plugin-require-context-hook": "^1.0.0",
|
|
122
|
-
"caniuse-lite": "^1.0.
|
|
122
|
+
"caniuse-lite": "^1.0.30001655",
|
|
123
123
|
"chai": "^5.1.1",
|
|
124
124
|
"chai-as-promised": "^8.0.0",
|
|
125
125
|
"chai-dom": "^1.10.0",
|
|
@@ -129,11 +129,11 @@
|
|
|
129
129
|
"cpy-cli": "^5.0.0",
|
|
130
130
|
"enzyme": "^3.11.0",
|
|
131
131
|
"eslint": "^8.57.0",
|
|
132
|
-
"eslint-import-resolver-webpack": "^0.13.
|
|
132
|
+
"eslint-import-resolver-webpack": "^0.13.9",
|
|
133
133
|
"eslint-plugin-bdd": "^2.1.1",
|
|
134
|
-
"eslint-plugin-import": "^2.
|
|
135
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
136
|
-
"eslint-plugin-react": "^7.35.
|
|
134
|
+
"eslint-plugin-import": "^2.30.0",
|
|
135
|
+
"eslint-plugin-jsx-a11y": "^6.10.0",
|
|
136
|
+
"eslint-plugin-react": "^7.35.2",
|
|
137
137
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
138
138
|
"eslint-plugin-storybook": "^0.8.0",
|
|
139
139
|
"events": "^3.3.0",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"jest": "~29.7.0",
|
|
146
146
|
"jest-environment-jsdom": "^29.7.0",
|
|
147
147
|
"jest-teamcity": "^1.12.0",
|
|
148
|
-
"lint-staged": "^15.2.
|
|
148
|
+
"lint-staged": "^15.2.10",
|
|
149
149
|
"markdown-it": "^14.1.0",
|
|
150
150
|
"merge-options": "^3.0.4",
|
|
151
151
|
"pinst": "^3.0.0",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"react-test-renderer": "^18.3.1",
|
|
157
157
|
"regenerator-runtime": "^0.14.1",
|
|
158
158
|
"rimraf": "^6.0.1",
|
|
159
|
-
"rollup": "^4.21.
|
|
159
|
+
"rollup": "^4.21.2",
|
|
160
160
|
"rollup-plugin-clear": "^2.0.7",
|
|
161
161
|
"rollup-plugin-styles": "^4.0.0",
|
|
162
162
|
"sinon": "^18.0.0",
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"storage-mock": "^2.1.0",
|
|
165
165
|
"storybook": "8.2.9",
|
|
166
166
|
"storybook-addon-themes": "^6.1.0",
|
|
167
|
-
"stylelint": "^16.
|
|
167
|
+
"stylelint": "^16.9.0",
|
|
168
168
|
"svg-inline-loader": "^0.8.2",
|
|
169
169
|
"teamcity-service-messages": "^0.1.14",
|
|
170
170
|
"terser-webpack-plugin": "^5.3.10",
|
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
"vitest": "^2.0.5",
|
|
173
173
|
"vitest-teamcity-reporter": "^0.3.1",
|
|
174
174
|
"wallaby-webpack": "^3.9.16",
|
|
175
|
-
"webpack": "^5.
|
|
175
|
+
"webpack": "^5.94.0",
|
|
176
176
|
"webpack-cli": "^5.1.4",
|
|
177
177
|
"xmlappend": "^1.0.4"
|
|
178
178
|
},
|
|
@@ -202,7 +202,6 @@
|
|
|
202
202
|
"@jetbrains/icons": "^4.4.0",
|
|
203
203
|
"@jetbrains/postcss-require-hover": "^0.1.2",
|
|
204
204
|
"@types/combokeys": "^2.4.9",
|
|
205
|
-
"@types/deep-equal": "^1.0.4",
|
|
206
205
|
"@types/element-resize-detector": "^1.1.6",
|
|
207
206
|
"@types/react-virtualized": "9.21.30",
|
|
208
207
|
"@types/util-deprecate": "^1.0.3",
|
|
@@ -216,7 +215,7 @@
|
|
|
216
215
|
"css-loader": "^7.1.2",
|
|
217
216
|
"csstype": "^3.1.3",
|
|
218
217
|
"date-fns": "^3.6.0",
|
|
219
|
-
"
|
|
218
|
+
"dequal": "^2.0.3",
|
|
220
219
|
"element-resize-detector": "^1.2.4",
|
|
221
220
|
"es6-error": "^4.1.1",
|
|
222
221
|
"fastdom": "^1.0.12",
|
|
@@ -225,7 +224,7 @@
|
|
|
225
224
|
"highlight.js": "^10.7.2",
|
|
226
225
|
"just-debounce-it": "^3.2.0",
|
|
227
226
|
"memoize-one": "^6.0.0",
|
|
228
|
-
"postcss": "^8.4.
|
|
227
|
+
"postcss": "^8.4.45",
|
|
229
228
|
"postcss-calc": "^10.0.2",
|
|
230
229
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
231
230
|
"postcss-font-family-system-ui": "^5.0.0",
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { StorageInterface, StorageConfig } from './storage';
|
|
2
|
-
/**
|
|
3
|
-
* @prop {string} cookieName
|
|
4
|
-
*
|
|
5
|
-
* @param {{cookieName: string}} config
|
|
6
|
-
* @param {{checkDelay: number}} config
|
|
7
|
-
* @param {{type: string}} config
|
|
8
|
-
* @return {FallbackStorage}
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
export default class FallbackStorage implements StorageInterface {
|
|
12
|
-
static DEFAULT_COOKIE_NAME: string;
|
|
13
|
-
static DEFAULT_SESSION_COOKIE_NAME: string;
|
|
14
|
-
static DEFAULT_CHECK_DELAY: number;
|
|
15
|
-
static COOKIE_EXPIRES: number;
|
|
16
|
-
/**
|
|
17
|
-
* Maximum storage size
|
|
18
|
-
* @see http://browsercookielimits.squawky.net/
|
|
19
|
-
* @type {number}
|
|
20
|
-
*/
|
|
21
|
-
static QUOTA: number;
|
|
22
|
-
/**
|
|
23
|
-
* @param {string} name
|
|
24
|
-
* @param {string} value
|
|
25
|
-
* @param {number} days
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
28
|
-
private static _createCookie;
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {string} name
|
|
32
|
-
* @return {string}
|
|
33
|
-
* @private
|
|
34
|
-
*/
|
|
35
|
-
private static _readCookie;
|
|
36
|
-
cookieName: string;
|
|
37
|
-
checkDelay: number;
|
|
38
|
-
expires: number | null;
|
|
39
|
-
constructor(config?: StorageConfig);
|
|
40
|
-
/**
|
|
41
|
-
* @return {Promise}
|
|
42
|
-
* @private
|
|
43
|
-
*/
|
|
44
|
-
private _read;
|
|
45
|
-
/**
|
|
46
|
-
* @param data
|
|
47
|
-
* @return {Promise}
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
private _write;
|
|
51
|
-
/**
|
|
52
|
-
* @param {string} key
|
|
53
|
-
* @return {Promise}
|
|
54
|
-
*/
|
|
55
|
-
get(key: string): Promise<any>;
|
|
56
|
-
/**
|
|
57
|
-
* @param {string} key
|
|
58
|
-
* @param {object} value
|
|
59
|
-
* @return {Promise}
|
|
60
|
-
*/
|
|
61
|
-
set<T>(key: string, value: T | null): Promise<T | null>;
|
|
62
|
-
/**
|
|
63
|
-
* @param {string} key
|
|
64
|
-
* @return {Promise}
|
|
65
|
-
*/
|
|
66
|
-
remove(key: string): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {function(string, value)} callback
|
|
70
|
-
* @return {Promise}
|
|
71
|
-
*/
|
|
72
|
-
each<R>(callback: (item: string, value: unknown) => R | Promise<R>): Promise<Awaited<R>[]>;
|
|
73
|
-
/**
|
|
74
|
-
* @param {string} key
|
|
75
|
-
* @param {Function} callback
|
|
76
|
-
* @return {Function}
|
|
77
|
-
*/
|
|
78
|
-
on<T>(key: string, callback: (value: T | null) => void): () => void;
|
|
79
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import deepEqual from 'deep-equal';
|
|
2
|
-
const DEFAULT_CHECK_DELAY = 3000;
|
|
3
|
-
const COOKIE_EXPIRES = 365;
|
|
4
|
-
const QUOTA = 4093;
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
6
|
-
const SECONDS_IN_DAY = 24 * 60 * 60 * 1000;
|
|
7
|
-
/**
|
|
8
|
-
* @prop {string} cookieName
|
|
9
|
-
*
|
|
10
|
-
* @param {{cookieName: string}} config
|
|
11
|
-
* @param {{checkDelay: number}} config
|
|
12
|
-
* @param {{type: string}} config
|
|
13
|
-
* @return {FallbackStorage}
|
|
14
|
-
* @constructor
|
|
15
|
-
*/
|
|
16
|
-
export default class FallbackStorage {
|
|
17
|
-
static DEFAULT_COOKIE_NAME = 'localStorage';
|
|
18
|
-
static DEFAULT_SESSION_COOKIE_NAME = 'sessionStorage';
|
|
19
|
-
static DEFAULT_CHECK_DELAY = DEFAULT_CHECK_DELAY;
|
|
20
|
-
static COOKIE_EXPIRES = COOKIE_EXPIRES;
|
|
21
|
-
/**
|
|
22
|
-
* Maximum storage size
|
|
23
|
-
* @see http://browsercookielimits.squawky.net/
|
|
24
|
-
* @type {number}
|
|
25
|
-
*/
|
|
26
|
-
static QUOTA = QUOTA;
|
|
27
|
-
/**
|
|
28
|
-
* @param {string} name
|
|
29
|
-
* @param {string} value
|
|
30
|
-
* @param {number} days
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
static _createCookie(name, value, days) {
|
|
34
|
-
let date;
|
|
35
|
-
let expires;
|
|
36
|
-
if (days) {
|
|
37
|
-
date = new Date();
|
|
38
|
-
date.setTime(date.getTime() + (days * SECONDS_IN_DAY));
|
|
39
|
-
expires = `; expires=${date.toUTCString()}`;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
expires = ';';
|
|
43
|
-
}
|
|
44
|
-
document.cookie = `${name}=${value}${expires}; path=/`;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @param {string} name
|
|
49
|
-
* @return {string}
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
static _readCookie(name) {
|
|
53
|
-
const nameEQ = `${name}=`;
|
|
54
|
-
const cookies = document.cookie.split(';');
|
|
55
|
-
let cookie;
|
|
56
|
-
for (let i = 0; i < cookies.length; i++) {
|
|
57
|
-
cookie = cookies[i];
|
|
58
|
-
while (cookie.charAt(0) === ' ') {
|
|
59
|
-
cookie = cookie.substring(1, cookie.length);
|
|
60
|
-
}
|
|
61
|
-
if (cookie.indexOf(nameEQ) === 0) {
|
|
62
|
-
return cookie.substring(nameEQ.length, cookie.length);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
cookieName;
|
|
68
|
-
checkDelay;
|
|
69
|
-
expires;
|
|
70
|
-
constructor(config = {}) {
|
|
71
|
-
const session = config.type === 'session';
|
|
72
|
-
this.cookieName = config.cookieName ||
|
|
73
|
-
(session
|
|
74
|
-
? FallbackStorage.DEFAULT_SESSION_COOKIE_NAME
|
|
75
|
-
: FallbackStorage.DEFAULT_COOKIE_NAME);
|
|
76
|
-
this.checkDelay = config.checkDelay || FallbackStorage.DEFAULT_CHECK_DELAY;
|
|
77
|
-
this.expires = session ? FallbackStorage.COOKIE_EXPIRES : null;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @return {Promise}
|
|
81
|
-
* @private
|
|
82
|
-
*/
|
|
83
|
-
_read() {
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
const rawData = FallbackStorage._readCookie(this.cookieName);
|
|
86
|
-
if (rawData != null) {
|
|
87
|
-
resolve(JSON.parse(decodeURIComponent(rawData)));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
reject();
|
|
91
|
-
}
|
|
92
|
-
}).catch(() => ({}));
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @param data
|
|
96
|
-
* @return {Promise}
|
|
97
|
-
* @private
|
|
98
|
-
*/
|
|
99
|
-
_write(data) {
|
|
100
|
-
return new Promise(resolve => {
|
|
101
|
-
const stringData = encodeURIComponent(JSON.stringify(data));
|
|
102
|
-
FallbackStorage.
|
|
103
|
-
_createCookie(this.cookieName, stringData === '{}' ? '' : stringData, this.expires);
|
|
104
|
-
return resolve(data);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @param {string} key
|
|
109
|
-
* @return {Promise}
|
|
110
|
-
*/
|
|
111
|
-
get(key) {
|
|
112
|
-
return this._read().then(data => data[key] || null);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @param {string} key
|
|
116
|
-
* @param {object} value
|
|
117
|
-
* @return {Promise}
|
|
118
|
-
*/
|
|
119
|
-
async set(key, value) {
|
|
120
|
-
const data = await this._read();
|
|
121
|
-
if (key) {
|
|
122
|
-
if (value != null) {
|
|
123
|
-
data[key] = value;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
Reflect.deleteProperty(data, key);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
await this._write(data);
|
|
130
|
-
return value;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* @param {string} key
|
|
134
|
-
* @return {Promise}
|
|
135
|
-
*/
|
|
136
|
-
async remove(key) {
|
|
137
|
-
await this.set(key, null);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
*
|
|
141
|
-
* @param {function(string, value)} callback
|
|
142
|
-
* @return {Promise}
|
|
143
|
-
*/
|
|
144
|
-
each(callback) {
|
|
145
|
-
if (typeof callback !== 'function') {
|
|
146
|
-
return Promise.reject(new Error('Callback is not a function'));
|
|
147
|
-
}
|
|
148
|
-
return this._read().then(data => {
|
|
149
|
-
const promises = [];
|
|
150
|
-
for (const key in data) {
|
|
151
|
-
if (data.hasOwnProperty(key)) {
|
|
152
|
-
promises.push(callback(key, data[key]));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return Promise.all(promises);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* @param {string} key
|
|
160
|
-
* @param {Function} callback
|
|
161
|
-
* @return {Function}
|
|
162
|
-
*/
|
|
163
|
-
on(key, callback) {
|
|
164
|
-
let stop = false;
|
|
165
|
-
const checkForChange = (oldValue) => {
|
|
166
|
-
this.get(key).then(newValue => {
|
|
167
|
-
if (stop) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (!deepEqual(oldValue, newValue)) {
|
|
171
|
-
callback(newValue);
|
|
172
|
-
}
|
|
173
|
-
window.setTimeout(() => checkForChange(oldValue), this.checkDelay);
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
this.get(key).then(checkForChange);
|
|
177
|
-
return () => {
|
|
178
|
-
stop = true;
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|