ag-common 0.0.97 → 0.0.103

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.
@@ -25,7 +25,7 @@ const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, must
25
25
  throw new Error('exceeded dynamo provision cap');
26
26
  }
27
27
  if (mustEqual && (reads !== readsMax || writes !== writesMax)) {
28
- throw new Error(`dynamo provision cap not met reads`);
28
+ throw new Error(`dynamo provision cap not met`);
29
29
  }
30
30
  };
31
31
  exports.enforceDynamoProvisionCap = enforceDynamoProvisionCap;
@@ -102,17 +102,20 @@ function DropdownList({ options, value, onChange, placeholder, className, render
102
102
  if (JSON.stringify(newv) !== JSON.stringify(value))
103
103
  setState(newv);
104
104
  }, [options, value]);
105
- const maxLen = Math.max(...options.map((s) => renderF(s).length));
106
- const style = {
107
- width: `calc(${maxLen}ch + 2rem)`,
108
- };
109
- const minLeft = (0, dom_1.convertRemToPixels)(2 + maxLen / 2);
110
- const offsetList = (_b = (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.offsetLeft) !== null && _b !== void 0 ? _b : 0;
111
- if (offsetList < minLeft) {
112
- style.left = 0;
113
- }
114
- else {
115
- style.right = 0;
105
+ let style = {};
106
+ if (open) {
107
+ const maxLen = Math.max(...options.map((s) => renderF(s).length));
108
+ style = {
109
+ width: `calc(${maxLen}ch + 2rem)`,
110
+ };
111
+ const minLeft = (0, dom_1.convertRemToPixels)(2 + maxLen / 2);
112
+ const offsetList = (_b = (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.offsetLeft) !== null && _b !== void 0 ? _b : 0;
113
+ if (offsetList < minLeft) {
114
+ style.left = 0;
115
+ }
116
+ else {
117
+ style.right = 0;
118
+ }
116
119
  }
117
120
  return (react_1.default.createElement(SBase, { className: className, ref: ref, title: placeholder, onClick: (e) => {
118
121
  e.stopPropagation();
@@ -1,14 +1,13 @@
1
1
  export declare const toBase64: (str: string) => string;
2
2
  export declare const fromBase64: (str: string) => string;
3
+ export declare const setNodeCookieDocument: (s: string) => void;
3
4
  export declare function setCookieWrapper<T>(cname: string, raw: T, exdays?: number): void;
4
5
  export declare function wipeCookies(cname: string): void;
5
- export declare function getCookieWrapper<T>({ cname, cookieDocument, defaultValue, }: {
6
+ export declare function getCookieWrapper<T>({ cname, defaultValue, }: {
6
7
  cname: string;
7
- cookieDocument?: string;
8
8
  defaultValue?: string;
9
9
  }): T;
10
- export declare function useCookie<T>({ key, defaultValue, cookieDocument, }: {
10
+ export declare function useCookie<T>({ key, defaultValue, }: {
11
11
  key: string;
12
12
  defaultValue?: string;
13
- cookieDocument?: string;
14
13
  }): [T, (v: T) => any];
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCookie = exports.getCookieWrapper = exports.wipeCookies = exports.setCookieWrapper = exports.fromBase64 = exports.toBase64 = void 0;
3
+ exports.useCookie = exports.getCookieWrapper = exports.wipeCookies = exports.setCookieWrapper = exports.setNodeCookieDocument = exports.fromBase64 = exports.toBase64 = void 0;
4
4
  /* eslint-disable guard-for-in */
5
5
  /* eslint-disable no-restricted-syntax */
6
6
  const react_1 = require("react");
7
+ const log_1 = require("../../common/helpers/log");
7
8
  const expireDate = 'Thu, 01 Jan 1970 00:00:00 UTC';
8
9
  const maxCookieLen = 4000;
9
10
  const chunkString = (str, length) => str.match(new RegExp(`.{1,${length}}`, 'g'));
@@ -11,15 +12,32 @@ const toBase64 = (str) => Buffer.from(str).toString('base64');
11
12
  exports.toBase64 = toBase64;
12
13
  const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
13
14
  exports.fromBase64 = fromBase64;
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ if (!process.nodeLocalCookie === undefined) {
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ process.nodeLocalCookie = '';
19
+ }
20
+ const setNodeCookieDocument = (s) => {
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ process.nodeLocalCookie = s;
23
+ };
24
+ exports.setNodeCookieDocument = setNodeCookieDocument;
14
25
  function setCookie(cname, raw, exdays = 1) {
15
26
  const d = new Date();
16
27
  d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
17
28
  const expires = `expires=${!raw || exdays < 0 ? expireDate : d.toUTCString()}`;
29
+ if (typeof window === undefined) {
30
+ (0, log_1.warn)('cant set cookie with no window object');
31
+ return;
32
+ }
18
33
  document.cookie = `${cname}=${!raw ? '' : raw};${expires};path=/`;
19
34
  }
20
- function getCookie({ cname, cookieDocument, }) {
35
+ function getCookie({ cname }) {
21
36
  const name = `${cname}=`;
22
- const ca1 = cookieDocument || (typeof window !== 'undefined' && document.cookie);
37
+ const ca1 =
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ process.nodeLocalCookie ||
40
+ (typeof window !== 'undefined' && document.cookie);
23
41
  if (!ca1 || !(ca1 === null || ca1 === void 0 ? void 0 : ca1.trim())) {
24
42
  return undefined;
25
43
  }
@@ -65,14 +83,13 @@ function wipeCookies(cname) {
65
83
  }
66
84
  }
67
85
  exports.wipeCookies = wipeCookies;
68
- function getCookieWrapper({ cname, cookieDocument, defaultValue, }) {
86
+ function getCookieWrapper({ cname, defaultValue, }) {
69
87
  let raw = '';
70
88
  let currentCount = 0;
71
89
  // eslint-disable-next-line no-constant-condition
72
90
  while (true) {
73
91
  const newv = getCookie({
74
92
  cname: cname + currentCount,
75
- cookieDocument,
76
93
  });
77
94
  if (!newv) {
78
95
  if (currentCount === 0) {
@@ -97,8 +114,8 @@ function getCookieWrapper({ cname, cookieDocument, defaultValue, }) {
97
114
  }
98
115
  exports.getCookieWrapper = getCookieWrapper;
99
116
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
- function useCookie({ key, defaultValue, cookieDocument, }) {
101
- const [cookie, setC] = (0, react_1.useState)(getCookieWrapper({ cname: key, defaultValue, cookieDocument }));
117
+ function useCookie({ key, defaultValue, }) {
118
+ const [cookie, setC] = (0, react_1.useState)(getCookieWrapper({ cname: key, defaultValue }));
102
119
  return [
103
120
  cookie,
104
121
  (v) => {
@@ -8,5 +8,11 @@ const domContains = (e, x, y) => {
8
8
  return e.x <= x && x <= e.x + e.width && e.y <= y && y <= e.y + e.height;
9
9
  };
10
10
  exports.domContains = domContains;
11
- const convertRemToPixels = (rem) => rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
11
+ const convertRemToPixels = (rem) => {
12
+ let fontSize = '16px';
13
+ if (typeof window !== 'undefined') {
14
+ fontSize = getComputedStyle(document.documentElement).fontSize;
15
+ }
16
+ return rem * parseFloat(fontSize);
17
+ };
12
18
  exports.convertRemToPixels = convertRemToPixels;
@@ -4,7 +4,5 @@ declare type AxiosWrapperWrap<T> = AxiosWrapper<T | undefined> & {
4
4
  loaded: boolean;
5
5
  loadcount: number;
6
6
  };
7
- export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi> & {
8
- cacheKey: string;
9
- }) => AxiosWrapperWrap<T>;
7
+ export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi>) => AxiosWrapperWrap<T>;
10
8
  export {};
@@ -5,8 +5,16 @@ const react_1 = require("react");
5
5
  const log_1 = require("../../common/helpers/log");
6
6
  const object_1 = require("../../common/helpers/object");
7
7
  const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ if (!process.nodeLocalStorage) {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ process.nodeLocalStorage = {};
13
+ }
8
14
  const clearLocalStorageItem = (key) => {
9
15
  if (typeof window === 'undefined') {
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ delete process.nodeLocalStorage[key];
10
18
  return;
11
19
  }
12
20
  try {
@@ -20,6 +28,8 @@ exports.clearLocalStorageItem = clearLocalStorageItem;
20
28
  const clearAllLocalStorage = (except) => {
21
29
  try {
22
30
  if (typeof window === 'undefined') {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ process.nodeLocalStorage = {};
23
33
  return;
24
34
  }
25
35
  for (let i = 0; i < localStorage.length; i += 1) {
@@ -38,6 +48,8 @@ exports.clearAllLocalStorage = clearAllLocalStorage;
38
48
  const setLocalStorageItem = (key, value, ttl) => {
39
49
  try {
40
50
  if (typeof window === 'undefined') {
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ process.nodeLocalStorage[key] = value;
41
53
  return;
42
54
  }
43
55
  const set = {
@@ -54,7 +66,9 @@ const setLocalStorageItem = (key, value, ttl) => {
54
66
  exports.setLocalStorageItem = setLocalStorageItem;
55
67
  const getLocalStorageItem = (key, initialValue, ttl) => {
56
68
  if (typeof window === 'undefined') {
57
- return initialValue;
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ const value = process.nodeLocalStorage[key] || initialValue;
71
+ return value;
58
72
  }
59
73
  const itemraw = window.localStorage.getItem(key);
60
74
  const item = (0, object_1.tryJsonParse)(itemraw, undefined);
@@ -70,7 +84,6 @@ const getLocalStorageItem = (key, initialValue, ttl) => {
70
84
  return itemv;
71
85
  };
72
86
  exports.getLocalStorageItem = getLocalStorageItem;
73
- // Hook
74
87
  function UseLocalStorage(key, initialValue, ttl) {
75
88
  const storedValue = (0, exports.getLocalStorageItem)(key, initialValue, ttl);
76
89
  //bump use of stored value
@@ -78,9 +91,6 @@ function UseLocalStorage(key, initialValue, ttl) {
78
91
  // Return a wrapped version of useState's setter function that ...
79
92
  // ... persists the new value to localStorage.
80
93
  const setValue = (value) => {
81
- if (typeof window === 'undefined') {
82
- return;
83
- }
84
94
  const valueToStore = (value instanceof Function ? value(storedValue) : value);
85
95
  (0, exports.setLocalStorageItem)(key, valueToStore, ttl);
86
96
  setT(new Date().getTime());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.97",
3
+ "version": "0.0.103",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",