@hybridcore/ui 1.4.7 → 1.4.9

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,32 +1,7 @@
1
- import f from "lodash";
2
- const i = (s, e) => !!f.get(e, s, !1), a = (s, e) => {
3
- if (!e || !i("UI", e)) return !1;
4
- if (f.get(e, "UI.access") === "ALL") return !0;
5
- if (s.includes(".")) {
6
- let r = "UI";
7
- const t = s.split(".");
8
- for (const n of t)
9
- if (r += `.permissions.${n}`, i(`${r}.access`, e)) return !0;
10
- return !1;
11
- }
12
- return i(`UI.permissions.${s}`, e);
13
- }, u = (s, e, r) => {
14
- const t = f.get(r, s, null);
15
- return t === e || e === "READ" && (t === "ALL" || t === "SUPER_ADMIN") || e === "ALL" && t === "SUPER_ADMIN";
16
- }, A = (s, e, r) => {
17
- const [t, n, o] = s.split(".");
18
- return !!(u("DATA.access", e, r) || u(`DATA.permissions.${t}.access`, e, r) || u(
19
- `DATA.permissions.${t}.permissions.${n}.access`,
20
- e,
21
- r
22
- ) || u(
23
- `DATA.permissions.${t}.permissions.${n}.permissions.${o}.access`,
24
- e,
25
- r
26
- ));
27
- };
1
+ import "lodash";
2
+ import { c as e, b as h, a as o } from "../../helpers-B4UL9NMD.js";
28
3
  export {
29
- u as hasAccess,
30
- A as hasDataAccess,
31
- a as hasUIAccess
4
+ e as hasAccess,
5
+ h as hasDataAccess,
6
+ o as hasUIAccess
32
7
  };
@@ -1,5 +1,5 @@
1
1
  import { jsx as m } from "react/jsx-runtime";
2
- import { hasUIAccess as f } from "./helpers.js";
2
+ import { a as f } from "../../helpers-B4UL9NMD.js";
3
3
  import n from "lodash";
4
4
  import { Loading as d } from "../loading/index.js";
5
5
  const A = ({
@@ -1,30 +1,30 @@
1
1
  import { jsxs as a, Fragment as A, jsx as l } from "react/jsx-runtime";
2
2
  import { useMemo as C } from "react";
3
3
  import { FormControl as D, InputLabel as F, Select as $, MenuItem as j, FormHelperText as I } from "@mui/material";
4
- import { hasDataAccess as g } from "../../access/helpers.js";
4
+ import { b as s } from "../../../helpers-B4UL9NMD.js";
5
5
  const q = ({
6
6
  ontologyId: h,
7
7
  appRoles: o,
8
8
  templateKeys: e,
9
9
  templateType: c,
10
10
  securityLevels: i,
11
- value: s,
11
+ value: b,
12
12
  minLevel: t = 99,
13
13
  minLevelId: u,
14
14
  minLevelRoles: n,
15
15
  showError: d,
16
16
  variant: m = "outlined",
17
- onChange: S
17
+ onChange: g
18
18
  }) => {
19
- const b = C(() => {
19
+ const S = C(() => {
20
20
  if (n && n.length > 0) {
21
21
  for (const r of n)
22
- if (g(r, "SUPER_ADMIN", o))
22
+ if (s(r, "SUPER_ADMIN", o))
23
23
  return t;
24
24
  }
25
25
  if (e && e.length > 0 && c) {
26
26
  for (const r of e)
27
- if (g(
27
+ if (s(
28
28
  `${h}.${c}.${r}`,
29
29
  "SUPER_ADMIN",
30
30
  o
@@ -48,7 +48,7 @@ const q = ({
48
48
  o,
49
49
  h
50
50
  ]), x = (r) => {
51
- S(r.target.value);
51
+ g(r.target.value);
52
52
  };
53
53
  return /* @__PURE__ */ a(A, { children: [
54
54
  /* @__PURE__ */ a(
@@ -66,9 +66,9 @@ const q = ({
66
66
  label: "Security Level *",
67
67
  labelId: "security-level-label",
68
68
  id: "demo-simple-select",
69
- value: s,
69
+ value: b,
70
70
  onChange: x,
71
- children: i.filter((r) => r.level <= b).map((r, f) => /* @__PURE__ */ l(j, { value: r.id, children: r.name }, f))
71
+ children: i.filter((r) => r.level <= S).map((r, f) => /* @__PURE__ */ l(j, { value: r.id, children: r.name }, f))
72
72
  }
73
73
  )
74
74
  ]
@@ -33,7 +33,7 @@ function B(e, x) {
33
33
  value: o.templateKey,
34
34
  checked: h("parent") === o.templateKey
35
35
  });
36
- return L(a);
36
+ return L(a, !1);
37
37
  }, S = () => {
38
38
  const t = I(e.mappedTemplates);
39
39
  F(t);
@@ -0,0 +1,38 @@
1
+ import o from "lodash";
2
+ const i = (s, e) => !!o.get(e, s, !1), f = (s, e) => {
3
+ if (!e || !i("UI", e)) return !1;
4
+ if (o.get(e, "UI.access") === "ALL") return !0;
5
+ if (s.includes(".")) {
6
+ let r = "UI";
7
+ const t = s.split(".");
8
+ for (const u of t)
9
+ if (r += `.permissions.${u}`, i(`${r}.access`, e)) return !0;
10
+ return !1;
11
+ }
12
+ return i(`UI.permissions.${s}`, e);
13
+ }, n = (s, e, r) => {
14
+ const t = o.get(r, s, null);
15
+ return t === e || e === "READ" && (t === "ALL" || t === "SUPER_ADMIN") || e === "ALL" && t === "SUPER_ADMIN";
16
+ }, c = (s, e, r) => {
17
+ const [t, u, a] = s.split(".");
18
+ return !!(n("DATA.access", e, r) || n(`DATA.permissions.${t}.access`, e, r) || n(
19
+ `DATA.permissions.${t}.permissions.${u}.access`,
20
+ e,
21
+ r
22
+ ) || n(
23
+ `DATA.permissions.${t}.permissions.${u}.permissions.${a}.access`,
24
+ e,
25
+ r
26
+ ));
27
+ }, A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
28
+ __proto__: null,
29
+ hasAccess: n,
30
+ hasDataAccess: c,
31
+ hasUIAccess: f
32
+ }, Symbol.toStringTag, { value: "Module" }));
33
+ export {
34
+ f as a,
35
+ c as b,
36
+ n as c,
37
+ A as h
38
+ };
package/dist/main.d.ts CHANGED
@@ -25,6 +25,16 @@ import { View } from 'ol';
25
25
 
26
26
  export declare const Access: React.FC<Props>;
27
27
 
28
+ declare type AccessType = "READ" | "ALL" | "SUPER_ADMIN";
29
+
30
+ export declare namespace AccessUtils {
31
+ export {
32
+ hasUIAccess,
33
+ hasAccess,
34
+ hasDataAccess
35
+ }
36
+ }
37
+
28
38
  export { AdapterDayjs }
29
39
 
30
40
  declare function alert_2(title: string, message: string): Promise<unknown>;
@@ -188,6 +198,8 @@ declare function encrypt(encryptionKey: any, data: any): Promise<{
188
198
 
189
199
  declare function exportKey(key: any): Promise<JsonWebKey>;
190
200
 
201
+ declare type FeatureType = AUTH.ModuleType;
202
+
191
203
  declare function generateKey(): Promise<CryptoKey>;
192
204
 
193
205
  export declare const GeometryPicker: React.FC<Props_5>;
@@ -196,6 +208,19 @@ declare interface Handle {
196
208
  reset: () => void;
197
209
  }
198
210
 
211
+ declare const hasAccess: (path: string, access: AccessType, permissions: AUTH.PermissionType) => boolean;
212
+
213
+ /**
214
+ * Checks if the given role and access type in permissions
215
+ * @param {string} role The role string which's format should be ONTOLOGY_ID?.TEMPLATE_TYPE?.TEMPLATE_KEY?
216
+ * @param {AccessType} access The access type (READ, ALL, SUPER_ADMIN) to check
217
+ * @param {AUTH.PermissionType} permissions The permission list
218
+ * @return {boolean} True if the role and access in the permissions
219
+ */
220
+ declare const hasDataAccess: (role: string, access: AccessType, permissions: AUTH.PermissionType) => boolean;
221
+
222
+ declare const hasUIAccess: (feature: FeatureType, permissions?: AUTH.PermissionType) => boolean;
223
+
199
224
  export declare const IconButton: default_2.FC<Props_6>;
200
225
 
201
226
  declare function importKey(jwk: any): Promise<CryptoKey>;
package/dist/main.js CHANGED
@@ -3,7 +3,7 @@ import { alert as Ft, confirm as Ct } from "./components/confirm/index.js";
3
3
  import { Card as jt } from "./components/card/index.js";
4
4
  import { CollapsibleCard as Pt } from "./components/collapsible-card/index.js";
5
5
  import { ConditionalWrapper as Et } from "./components/conditional-wrapper/index.js";
6
- import { Container as Ut } from "./components/container/index.js";
6
+ import { Container as zt } from "./components/container/index.js";
7
7
  import { ContextMenu as Nt } from "./components/context-menu/index.js";
8
8
  import { DateTimePicker as _t } from "./components/date-time-picker/index.js";
9
9
  import { DisseminationList as qt } from "./components/data-security-selectors/dissemination-list/index.js";
@@ -19,20 +19,21 @@ import { PhoneInput as fe } from "./components/phone-input/index.js";
19
19
  import { SearchInput as le } from "./components/search-input/index.js";
20
20
  import { SecurityLevel as ye } from "./components/data-security-selectors/security-level/index.js";
21
21
  import { TemplateForm as De } from "./components/template-form/index.js";
22
- import { TemplatePropertyFilters as Ye } from "./components/template-property-filters/index.js";
22
+ import { TemplatePropertyFilters as xe } from "./components/template-property-filters/index.js";
23
23
  import { TreeSelect as Le } from "./components/tree-select/index.js";
24
24
  import { TreeViewFilter as Te } from "./components/treeview-filter/index.js";
25
25
  import { S as ve } from "./utils-Bq0ye5vf.js";
26
26
  import { i as Se } from "./index-DlnzUkwe.js";
27
+ import { h as be } from "./helpers-B4UL9NMD.js";
27
28
  import { _ as dt } from "./objectWithoutPropertiesLoose-BK36oJDi.js";
28
29
  import C from "dayjs";
29
- import { c as z, g as U } from "./createStyled-BzvgQjjR.js";
30
+ import { c as U, g as z } from "./createStyled-BzvgQjjR.js";
30
31
  import { b as ut } from "./index-C1fczHEW.js";
31
32
  var tt = { exports: {} };
32
33
  (function(l, D) {
33
34
  (function(f, c) {
34
35
  l.exports = c();
35
- })(z, function() {
36
+ })(U, function() {
36
37
  var f = "week", c = "year";
37
38
  return function(t, e, s) {
38
39
  var o = e.prototype;
@@ -52,12 +53,12 @@ var tt = { exports: {} };
52
53
  });
53
54
  })(tt);
54
55
  var ct = tt.exports;
55
- const ft = /* @__PURE__ */ U(ct);
56
+ const ft = /* @__PURE__ */ z(ct);
56
57
  var et = { exports: {} };
57
58
  (function(l, D) {
58
59
  (function(f, c) {
59
60
  l.exports = c();
60
- })(z, function() {
61
+ })(U, function() {
61
62
  var f = { LTS: "h:mm:ss A", LT: "h:mm A", L: "MM/DD/YYYY", LL: "MMMM D, YYYY", LLL: "MMMM D, YYYY h:mm A", LLLL: "dddd, MMMM D, YYYY h:mm A" }, c = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g, t = /\d/, e = /\d\d/, s = /\d\d?/, o = /\d*[^-_:/,()\s\d]+/, n = {}, i = function(r) {
62
63
  return (r = +r) + (r > 68 ? 1900 : 2e3);
63
64
  }, a = function(r) {
@@ -76,8 +77,8 @@ var et = { exports: {} };
76
77
  }, H = function(r, h) {
77
78
  var d, u = n.meridiem;
78
79
  if (u) {
79
- for (var Y = 1; Y <= 24; Y += 1) if (r.indexOf(u(Y, 0, h)) > -1) {
80
- d = Y > 12;
80
+ for (var x = 1; x <= 24; x += 1) if (r.indexOf(u(x, 0, h)) > -1) {
81
+ d = x > 12;
81
82
  break;
82
83
  }
83
84
  } else d = r === (h ? "pm" : "PM");
@@ -115,72 +116,72 @@ var et = { exports: {} };
115
116
  h = r, d = n && n.formats;
116
117
  for (var u = (r = h.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function(S, T, M) {
117
118
  var y = M && M.toUpperCase();
118
- return T || d[M] || f[M] || d[y].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function(k, v, b) {
119
- return v || b.slice(1);
119
+ return T || d[M] || f[M] || d[y].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function(k, v, A) {
120
+ return v || A.slice(1);
120
121
  });
121
- })).match(c), Y = u.length, x = 0; x < Y; x += 1) {
122
- var I = u[x], O = Z[I], L = O && O[0], w = O && O[1];
123
- u[x] = w ? { regex: L, parser: w } : I.replace(/^\[|\]$/g, "");
122
+ })).match(c), x = u.length, Y = 0; Y < x; Y += 1) {
123
+ var I = u[Y], O = Z[I], L = O && O[0], w = O && O[1];
124
+ u[Y] = w ? { regex: L, parser: w } : I.replace(/^\[|\]$/g, "");
124
125
  }
125
126
  return function(S) {
126
- for (var T = {}, M = 0, y = 0; M < Y; M += 1) {
127
+ for (var T = {}, M = 0, y = 0; M < x; M += 1) {
127
128
  var k = u[M];
128
129
  if (typeof k == "string") y += k.length;
129
130
  else {
130
- var v = k.regex, b = k.parser, j = S.slice(y), F = v.exec(j)[0];
131
- b.call(T, F), S = S.replace(F, "");
131
+ var v = k.regex, A = k.parser, j = S.slice(y), F = v.exec(j)[0];
132
+ A.call(T, F), S = S.replace(F, "");
132
133
  }
133
134
  }
134
- return function(A) {
135
- var $ = A.afternoon;
135
+ return function(b) {
136
+ var $ = b.afternoon;
136
137
  if ($ !== void 0) {
137
- var m = A.hours;
138
- $ ? m < 12 && (A.hours += 12) : m === 12 && (A.hours = 0), delete A.afternoon;
138
+ var m = b.hours;
139
+ $ ? m < 12 && (b.hours += 12) : m === 12 && (b.hours = 0), delete b.afternoon;
139
140
  }
140
141
  }(T), T;
141
142
  };
142
143
  }
143
144
  return function(r, h, d) {
144
145
  d.p.customParseFormat = !0, r && r.parseTwoDigitYear && (i = r.parseTwoDigitYear);
145
- var u = h.prototype, Y = u.parse;
146
- u.parse = function(x) {
147
- var I = x.date, O = x.utc, L = x.args;
146
+ var u = h.prototype, x = u.parse;
147
+ u.parse = function(Y) {
148
+ var I = Y.date, O = Y.utc, L = Y.args;
148
149
  this.$u = O;
149
150
  var w = L[1];
150
151
  if (typeof w == "string") {
151
152
  var S = L[2] === !0, T = L[3] === !0, M = S || T, y = L[2];
152
- T && (y = L[2]), n = this.$locale(), !S && y && (n = d.Ls[y]), this.$d = function(j, F, A, $) {
153
+ T && (y = L[2]), n = this.$locale(), !S && y && (n = d.Ls[y]), this.$d = function(j, F, b, $) {
153
154
  try {
154
155
  if (["x", "X"].indexOf(F) > -1) return new Date((F === "X" ? 1e3 : 1) * j);
155
156
  var m = B(F)(j), N = m.year, P = m.month, nt = m.day, ot = m.hours, at = m.minutes, it = m.seconds, ht = m.milliseconds, R = m.zone, X = m.week, J = /* @__PURE__ */ new Date(), _ = nt || (N || P ? 1 : J.getDate()), V = N || J.getFullYear(), W = 0;
156
157
  N && !P || (W = P > 0 ? P - 1 : J.getMonth());
157
158
  var E, q = ot || 0, G = at || 0, K = it || 0, Q = ht || 0;
158
- return R ? new Date(Date.UTC(V, W, _, q, G, K, Q + 60 * R.offset * 1e3)) : A ? new Date(Date.UTC(V, W, _, q, G, K, Q)) : (E = new Date(V, W, _, q, G, K, Q), X && (E = $(E).week(X).toDate()), E);
159
+ return R ? new Date(Date.UTC(V, W, _, q, G, K, Q + 60 * R.offset * 1e3)) : b ? new Date(Date.UTC(V, W, _, q, G, K, Q)) : (E = new Date(V, W, _, q, G, K, Q), X && (E = $(E).week(X).toDate()), E);
159
160
  } catch {
160
161
  return /* @__PURE__ */ new Date("");
161
162
  }
162
163
  }(I, w, O, d), this.init(), y && y !== !0 && (this.$L = this.locale(y).$L), M && I != this.format(w) && (this.$d = /* @__PURE__ */ new Date("")), n = {};
163
164
  } else if (w instanceof Array) for (var k = w.length, v = 1; v <= k; v += 1) {
164
165
  L[1] = w[v - 1];
165
- var b = d.apply(this, L);
166
- if (b.isValid()) {
167
- this.$d = b.$d, this.$L = b.$L, this.init();
166
+ var A = d.apply(this, L);
167
+ if (A.isValid()) {
168
+ this.$d = A.$d, this.$L = A.$L, this.init();
168
169
  break;
169
170
  }
170
171
  v === k && (this.$d = /* @__PURE__ */ new Date(""));
171
172
  }
172
- else Y.call(this, x);
173
+ else x.call(this, Y);
173
174
  };
174
175
  };
175
176
  });
176
177
  })(et);
177
178
  var mt = et.exports;
178
- const lt = /* @__PURE__ */ U(mt);
179
+ const lt = /* @__PURE__ */ z(mt);
179
180
  var rt = { exports: {} };
180
181
  (function(l, D) {
181
182
  (function(f, c) {
182
183
  l.exports = c();
183
- })(z, function() {
184
+ })(U, function() {
184
185
  var f = { LTS: "h:mm:ss A", LT: "h:mm A", L: "MM/DD/YYYY", LL: "MMMM D, YYYY", LLL: "MMMM D, YYYY h:mm A", LLLL: "dddd, MMMM D, YYYY h:mm A" };
185
186
  return function(c, t, e) {
186
187
  var s = t.prototype, o = s.format;
@@ -200,12 +201,12 @@ var rt = { exports: {} };
200
201
  });
201
202
  })(rt);
202
203
  var pt = rt.exports;
203
- const yt = /* @__PURE__ */ U(pt);
204
+ const yt = /* @__PURE__ */ z(pt);
204
205
  var st = { exports: {} };
205
206
  (function(l, D) {
206
207
  (function(f, c) {
207
208
  l.exports = c();
208
- })(z, function() {
209
+ })(U, function() {
209
210
  return function(f, c, t) {
210
211
  c.prototype.isBetween = function(e, s, o, n) {
211
212
  var i = t(e), a = t(s), g = (n = n || "()")[0] === "(", p = n[1] === ")";
@@ -215,11 +216,11 @@ var st = { exports: {} };
215
216
  });
216
217
  })(st);
217
218
  var Mt = st.exports;
218
- const Dt = /* @__PURE__ */ U(Mt);
219
+ const Dt = /* @__PURE__ */ z(Mt);
219
220
  C.extend(lt);
220
221
  C.extend(yt);
221
222
  C.extend(Dt);
222
- const gt = ut(["Your locale has not been found.", "Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale", "Or you forget to import the locale with `require('dayjs/locale/{localeUsed}')`", "fallback on English locale"]), Yt = {
223
+ const gt = ut(["Your locale has not been found.", "Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale", "Or you forget to import the locale with `require('dayjs/locale/{localeUsed}')`", "fallback on English locale"]), xt = {
223
224
  // Year
224
225
  YY: "year",
225
226
  YYYY: {
@@ -301,7 +302,7 @@ const gt = ut(["Your locale has not been found.", "Either the locale key is not
301
302
  maxLength: 2
302
303
  },
303
304
  ss: "seconds"
304
- }, xt = {
305
+ }, Yt = {
305
306
  normalDateWithWeekday: "ddd, MMM D",
306
307
  normalDate: "D MMMM",
307
308
  shortDate: "MMM D",
@@ -339,7 +340,7 @@ class St {
339
340
  this.isMUIAdapter = !0, this.lib = "dayjs", this.rawDayJsInstance = void 0, this.dayjs = void 0, this.locale = void 0, this.formats = void 0, this.escapedCharacters = {
340
341
  start: "[",
341
342
  end: "]"
342
- }, this.formatTokenMap = Yt, this.getLocaleFormats = () => {
343
+ }, this.formatTokenMap = xt, this.getLocaleFormats = () => {
343
344
  var t;
344
345
  const e = (t = this.rawDayJsInstance.Ls) != null ? t : C.Ls, s = this.locale || "en";
345
346
  let o = e[s];
@@ -375,16 +376,17 @@ class St {
375
376
  for (; i.isBefore(o); )
376
377
  n.push(i), i = i.add(1, "year");
377
378
  return n;
378
- }, this.getMeridiemText = (t) => t === "am" ? "AM" : "PM", this.rawDayJsInstance = c || C, this.dayjs = Lt(this.rawDayJsInstance, D), this.locale = D, this.formats = dt({}, xt, f), C.extend(ft);
379
+ }, this.getMeridiemText = (t) => t === "am" ? "AM" : "PM", this.rawDayJsInstance = c || C, this.dayjs = Lt(this.rawDayJsInstance, D), this.locale = D, this.formats = dt({}, Yt, f), C.extend(ft);
379
380
  }
380
381
  }
381
382
  export {
382
383
  Ht as Access,
384
+ be as AccessUtils,
383
385
  St as AdapterDayjs,
384
386
  jt as Card,
385
387
  Pt as CollapsibleCard,
386
388
  Et as ConditionalWrapper,
387
- Ut as Container,
389
+ zt as Container,
388
390
  Nt as ContextMenu,
389
391
  _t as DateTimePicker,
390
392
  qt as DisseminationList,
@@ -402,7 +404,7 @@ export {
402
404
  le as SearchInput,
403
405
  ye as SecurityLevel,
404
406
  De as TemplateForm,
405
- Ye as TemplatePropertyFilters,
407
+ xe as TemplatePropertyFilters,
406
408
  Le as TreeSelect,
407
409
  Te as TreeViewFilter,
408
410
  Ft as alert,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hybridcore/ui",
3
3
  "description": "Hybrid Core UI Library",
4
- "version": "1.4.7",
4
+ "version": "1.4.9",
5
5
  "author": "Hybrid Core",
6
6
  "license": "ISC",
7
7
  "type": "module",