ag-common 0.0.117 → 0.0.121

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,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Chevron: ({ down, width, className, colour, onToggle, }: {
3
2
  colour?: string | undefined;
4
3
  className?: string | undefined;
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
- export declare function DropdownList<T>({ options, value, onChange, placeholder, className, renderF, children, }: {
1
+ export declare function DropdownList<T>({ options, value, onChange, placeholder, className, renderF, children, shadow, }: {
3
2
  options: T[];
4
3
  value?: T;
5
4
  onChange: (v: T, index: number) => void;
@@ -7,4 +6,8 @@ export declare function DropdownList<T>({ options, value, onChange, placeholder,
7
6
  className?: string;
8
7
  renderF: (v: T) => string;
9
8
  children?: JSX.Element;
9
+ /**
10
+ * colour of dropdown shadow. default #555
11
+ */
12
+ shadow?: string;
10
13
  }): JSX.Element;
@@ -25,6 +25,7 @@ const react_1 = __importStar(require("react"));
25
25
  const styled_components_1 = __importStar(require("styled-components"));
26
26
  const Icon_1 = require("../Icon");
27
27
  const dom_1 = require("../../helpers/dom");
28
+ const common_1 = require("../../styles/common");
28
29
  const SBase = styled_components_1.default.div `
29
30
  display: flex;
30
31
  flex-flow: row;
@@ -48,6 +49,7 @@ const SItems = styled_components_1.default.div `
48
49
  (0, styled_components_1.css) `
49
50
  display: flex;
50
51
  `}
52
+ ${({ shadow }) => shadow && (0, common_1.Shadow)(shadow)}
51
53
  `;
52
54
  const Dots = (react_1.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", fillRule: "evenodd", clipRule: "evenodd" },
53
55
  react_1.default.createElement("path", { d: "M16 12a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 0117 12zm-8 0a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 0110 12zm-8 0a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 013 12z" })));
@@ -80,7 +82,7 @@ const SItem = styled_components_1.default.div `
80
82
  background-color: rgba(0, 0, 0, 0.2);
81
83
  }
82
84
  `;
83
- function DropdownList({ options, value, onChange, placeholder, className, renderF, children, }) {
85
+ function DropdownList({ options, value, onChange, placeholder, className, renderF, children, shadow = '#555', }) {
84
86
  var _a, _b;
85
87
  const ref = (0, react_1.useRef)(null);
86
88
  const [state, setState] = (0, react_1.useState)(value);
@@ -122,7 +124,7 @@ function DropdownList({ options, value, onChange, placeholder, className, render
122
124
  e.preventDefault();
123
125
  setOpen(!open);
124
126
  } },
125
- react_1.default.createElement(SItems, { open: open, style: style }, open &&
127
+ react_1.default.createElement(SItems, { open: open, style: style, shadow: shadow }, open &&
126
128
  options.map((s, i) => (react_1.default.createElement(SItem, { key: renderF(s), selected: s === state, onClick: (e) => {
127
129
  if (s !== state) {
128
130
  onChange(s, i);
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const HeadersRaw: ({ title, image, SiteShort, FullSiteUrl, siteDesc, }: {
3
2
  title?: string | undefined;
4
3
  image?: string | undefined;
@@ -65,7 +65,7 @@ exports.IconF = styled_components_1.default.span `
65
65
  stop-color: ${fill} !important;
66
66
  }
67
67
  `};
68
- ${({ outline }) => outline && (0, common_1.DropShadow)(outline)};
68
+ ${({ outline }) => outline && (0, common_1.HardOutline)(outline)};
69
69
 
70
70
  width: ${({ width }) => width || '100%'};
71
71
  height: ${({ height }) => height || '100%'};
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Loader: ({ name }: {
3
2
  name: string;
4
3
  }) => JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const LoginButton: ({ className, text, invert, savePath, loginPath, }: {
3
2
  invert?: boolean | undefined;
4
3
  text: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const LogoutButton: ({ className, invert, logout, }: {
3
2
  invert?: boolean | undefined;
4
3
  className?: string | undefined;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export interface TableItem {
3
2
  content: JSX.Element;
4
3
  groupTitle: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const CheckboxEdit: ({ defaultValue, onSubmit, noGrow, }: {
3
2
  defaultValue: boolean;
4
3
  onSubmit: (val: boolean) => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const ColourEdit: ({ defaultValue, onSubmit, }: {
3
2
  defaultValue: string;
4
3
  onSubmit: (val: string) => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const ListboxEdit: ({ defaultValue, onSubmit, values, }: {
3
2
  defaultValue: string;
4
3
  onSubmit: (val: string[]) => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { StyledComponent } from 'styled-components';
3
2
  export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
4
3
  export declare const TextEdit: ({ defaultValue, defaultEditing, onSubmit, disableEdit, placeholder, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, className, singleLine, }: {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const UndoIcon: () => JSX.Element;
3
2
  export declare const PencilIcon: () => JSX.Element;
4
3
  export declare const SaveIcon: () => JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ToastPosition } from 'react-hot-toast';
3
2
  interface Options {
4
3
  appearance: 'error' | 'success';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { AxiosWrapper, User } from '../../helpers/jwt';
3
2
  export declare const UserImageIcon: JSX.Element;
4
3
  export declare const UserImage: ({ image, className, }: {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { TLang, TResource } from '../../common/helpers/i18n';
3
2
  export declare const useTranslation: <T extends {
4
3
  [a: string]: TResource;
@@ -11,5 +11,9 @@ export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaul
11
11
  * will shortcut and return the appropriate axioswrapper data if cachekey is found
12
12
  */
13
13
  ssrCacheItems?: CacheItems | undefined;
14
+ /**
15
+ * default ttl in seconds for cache - default 120s
16
+ */
17
+ cacheTtl?: number | undefined;
14
18
  }) => AxiosWrapperWrap<T>;
15
19
  export {};
@@ -8,13 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.useCallOpenApi = void 0;
13
16
  const react_1 = require("react");
14
17
  const callOpenApi_1 = require("./callOpenApi");
18
+ const node_cache_1 = __importDefault(require("node-cache"));
19
+ let useCallOpenApiCache;
15
20
  const useCallOpenApi = (p) => {
16
- var _a, _b;
21
+ var _a;
22
+ if (!useCallOpenApiCache) {
23
+ useCallOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
24
+ }
17
25
  const ssrCached = (_a = p.ssrCacheItems) === null || _a === void 0 ? void 0 : _a.find((s) => s.cacheKey === p.cacheKey);
26
+ if (!useCallOpenApiCache.get(p.cacheKey) && ssrCached) {
27
+ useCallOpenApiCache.set(p.cacheKey, ssrCached);
28
+ }
18
29
  const defv = {
19
30
  data: undefined,
20
31
  url: '',
@@ -24,12 +35,16 @@ const useCallOpenApi = (p) => {
24
35
  loaded: false,
25
36
  reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
26
37
  };
27
- const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, defv), { data: ssrCached ? (_b = ssrCached.prefillData) === null || _b === void 0 ? void 0 : _b.data : undefined, loaded: !!ssrCached }));
38
+ const cached = useCallOpenApiCache.get(p.cacheKey);
39
+ const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, defv), { data: cached, loaded: !!cached }));
28
40
  (0, react_1.useEffect)(() => {
29
41
  function run() {
30
42
  return __awaiter(this, void 0, void 0, function* () {
31
- const res = yield (0, callOpenApi_1.callOpenApi)(p);
32
- setData((d) => (Object.assign(Object.assign({}, res), { loaded: true, loading: false, loadcount: d.loadcount + 1 })));
43
+ const resp = yield (0, callOpenApi_1.callOpenApi)(p);
44
+ if (useCallOpenApiCache) {
45
+ useCallOpenApiCache.set(p.cacheKey, resp.data);
46
+ }
47
+ setData((d) => (Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d.loadcount + 1 })));
33
48
  });
34
49
  }
35
50
  const { error, loaded, loading, loadcount } = data;
@@ -39,7 +54,7 @@ const useCallOpenApi = (p) => {
39
54
  }
40
55
  setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
41
56
  void run();
42
- }, [data, p, setData]);
57
+ }, [cached, data, p, setData]);
43
58
  return Object.assign(Object.assign({}, data), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
44
59
  setData(defv);
45
60
  }) });
@@ -33,6 +33,14 @@ const useQueryStringRaw = ({ name, searchOverride, defaultValue, stringify, pars
33
33
  window.history.replaceState({}, '', loc);
34
34
  setStateRaw(v);
35
35
  };
36
+ (0, react_1.useEffect)(() => {
37
+ const parsed = new URLSearchParams(raw);
38
+ const g = parsed.get(name);
39
+ const newv = g ? parse(g) : defaultValue;
40
+ if (state !== newv) {
41
+ setStateRaw(newv);
42
+ }
43
+ }, [defaultValue, name, parse, raw, state]);
36
44
  return [state, setState];
37
45
  };
38
46
  exports.useQueryStringRaw = useQueryStringRaw;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
- export declare const DropShadow: (outline: string) => import("styled-components").FlattenSimpleInterpolation;
2
+ export declare const HardOutline: (colour: string) => import("styled-components").FlattenSimpleInterpolation;
3
+ export declare const Shadow: (colour: string) => import("styled-components").FlattenSimpleInterpolation;
3
4
  export declare const NoTextSelect: import("styled-components").FlattenSimpleInterpolation;
4
5
  export declare const CssTransparentBlock: import("styled-components").FlattenSimpleInterpolation;
5
6
  export declare const FadeBottom: ({ height }: {
@@ -19,15 +19,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.FullScreenPage = exports.noDrag = exports.Card = exports.FadeBottom = exports.CssTransparentBlock = exports.NoTextSelect = exports.DropShadow = void 0;
22
+ exports.FullScreenPage = exports.noDrag = exports.Card = exports.FadeBottom = exports.CssTransparentBlock = exports.NoTextSelect = exports.Shadow = exports.HardOutline = void 0;
23
23
  const styled_components_1 = __importStar(require("styled-components"));
24
24
  const colours_1 = require("./colours");
25
- const DropShadow = (outline) => (0, styled_components_1.css) `
26
- filter: drop-shadow(1px 1px 0px ${outline})
27
- drop-shadow(-1px 1px 0px ${outline}) drop-shadow(1px -1px 0px ${outline})
28
- drop-shadow(-1px -1px 0px ${outline});
25
+ const HardOutline = (colour) => (0, styled_components_1.css) `
26
+ filter: drop-shadow(1px 1px 0px ${colour}) drop-shadow(-1px 1px 0px ${colour})
27
+ drop-shadow(1px -1px 0px ${colour}) drop-shadow(-1px -1px 0px ${colour});
29
28
  `;
30
- exports.DropShadow = DropShadow;
29
+ exports.HardOutline = HardOutline;
30
+ const Shadow = (colour) => (0, styled_components_1.css) `
31
+ filter: drop-shadow(1px 1px 0.5rem ${colour});
32
+ `;
33
+ exports.Shadow = Shadow;
31
34
  exports.NoTextSelect = (0, styled_components_1.css) `
32
35
  user-select: none; /* supported by Chrome and Opera */
33
36
  -webkit-user-select: none; /* Safari */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.117",
3
+ "version": "0.0.121",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -13,28 +13,29 @@
13
13
  "start": "tsc --watch"
14
14
  },
15
15
  "dependencies": {
16
- "aws-sdk": "2.1066.0",
16
+ "aws-cdk-lib": "2.x",
17
+ "aws-sdk": "2.1069.0",
17
18
  "axios": "0.25.0",
19
+ "constructs": "10.x",
18
20
  "jsonwebtoken": "8.5.1",
19
21
  "jwks-rsa": "2.0.5",
22
+ "node-cache": "5.1.2",
20
23
  "openapi-request-validator": "10.0.0",
21
24
  "react": "17.0.2",
22
25
  "react-dom": "17.0.2",
23
26
  "react-hot-toast": "2.2.0",
24
27
  "styled-components": "5.3.3",
25
- "typescript": "4.5.5",
26
- "aws-cdk-lib": "2.x",
27
- "constructs": "10.x"
28
+ "typescript": "4.5.5"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/jsonwebtoken": "8.5.8",
31
- "@types/node": "17.0.13",
32
- "@types/react": "17.0.38",
32
+ "@types/node": "17.0.15",
33
+ "@types/react": "17.0.39",
33
34
  "@types/react-dom": "17.0.11",
34
- "@types/styled-components": "5.1.21",
35
- "@typescript-eslint/eslint-plugin": "5.10.1",
36
- "@typescript-eslint/parser": "5.10.1",
37
- "eslint": "8.7.0",
35
+ "@types/styled-components": "5.1.22",
36
+ "@typescript-eslint/eslint-plugin": "5.10.2",
37
+ "@typescript-eslint/parser": "5.10.2",
38
+ "eslint": "8.8.0",
38
39
  "eslint-config-airbnb-typescript": "16.1.0",
39
40
  "eslint-config-prettier": "8.3.0",
40
41
  "eslint-config-react-app": "7.0.0",