@evergis/common
Advanced tools
Comparing version 0.0.57 to 0.0.60
@@ -0,3 +1,3 @@ | ||
import { FC } from 'react'; | ||
import { Api } from '@evergis/api'; | ||
import { FC } from 'react'; | ||
export declare type ApiContextProps = { | ||
@@ -4,0 +4,0 @@ api?: Api; |
@@ -7,6 +7,6 @@ 'use strict'; | ||
var React = require('react'); | ||
var React__default = _interopDefault(React); | ||
var api = require('@evergis/api'); | ||
var react = require('@evergis/react'); | ||
var React = require('react'); | ||
var React__default = _interopDefault(React); | ||
var reactI18next = require('react-i18next'); | ||
@@ -13,0 +13,0 @@ var reactFetching = require('@evergis/react-fetching'); |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@evergis/api"),n=require("@evergis/react"),r=require("react"),a=e(r),i=require("react-i18next"),o=require("@evergis/react-fetching"),l=require("@evergis/ui"),c=e(require("styled-components"));const s=r.createContext({}),m=()=>r.useContext(s);let u;const p=e=>(u||(u=o.createResource(e=>async t=>({data:await t.resourceCatalog.checkLimits(e)}),{injected:e})),u),x=function(e,t){return void 0===t&&(t=10),null==e?"":parseFloat(("string"==typeof e?parseFloat(e):e).toString()).toLocaleString("ru-RU",{maximumFractionDigits:t})};function d(e,t){return t||(t=e.slice(0)),e.raw=t,e}var y,b,g,f,E,C,T,h,P,v,F;const w=c(l.Flex)(y||(y=d(["\n margin-top: 3rem;\n flex-direction: column;\n"]))),L=c(l.H2)(b||(b=d(["\n margin: 0;\n"]))),j=c(l.Flex)(g||(g=d(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"]))),S=c(l.Flex)(f||(f=d(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n height: 10.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"]))),z=c(l.Flex)(E||(E=d(["\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n"]))),M=c(l.Icon)(C||(C=d(["\n opacity: 0.28;\n"]))),k=c.span(T||(T=d(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"]))),I=c.span(h||(h=d(["\n font-size: 12px;\n color: ",";\n text-align: center;\n"])),e=>{let{theme:{palette:t}}=e;return t.textSecondary}),O=c.div(P||(P=d(["\n margin: auto 0 0;\n height: 0.5rem;\n width: 100%;\n"]))),U=c(l.RatioLine)(v||(v=d(["\n width: 100%;\n margin: 0;\n"]))),q=c(l.Flex)(F||(F=d(["\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n"]))),N=e=>{let{item:n,updatePolicyItem:o,canUpdate:c}=e;const{t:s}=i.useTranslation("politics"),{name:m,used:u,max:p,type:d,disabled:y,icon:b}=n,g=r.useCallback(e=>{o(e||0,d)},[o]),f=d===t.PolicyType.MaxUploadContentSize?(p/1048576).toFixed(6):p,E=x(f,6);return a.createElement(S,{key:m},a.createElement(z,null,a.createElement(M,{kind:b}),a.createElement(k,null,void 0!==u?u+" "+s("from")+" "+(-1===p?"∞":E):(-1===p?"∞":E)+" "+(d===t.PolicyType.MaxUploadContentSize?"mb":"")),a.createElement(I,null,m),c&&a.createElement(q,null,a.createElement(l.NumberInput,{required:!0,disabled:y,counter:!1,width:"100%",value:+f,onChange:g}))),a.createElement(O,null,void 0!==u&&a.createElement(U,Object.assign({ratio:u/p*100},function(e,t){const n=e/t*100;return n>=90?{error:!0}:n>=75?{secondary:!0}:{primary:!0}}(u,p)))))};exports.ApiProvider=e=>{let{api:t,children:n}=e;return a.createElement(s.Provider,{value:{api:t}},n)},exports.Politics=e=>{let{username:o,canUpdate:l,title:c,className:s,initialLimits:u,onError:x}=e;const[d,y]=(e=>{let{username:n,onError:a,initialLimits:o}=e;const{t:l}=i.useTranslation("politics"),{api:c}=m(),{data:s,refetch:u,error:x}=p(c).use({input:{userName:n},waitInput:!0});return r.useEffect(()=>{x&&a&&a(x)},[x,a]),[r.useMemo(()=>{const e=s||o;return e?[{name:l("maps"),used:e.currentProjectCount,max:e.maxProjectsCount,type:t.PolicyType.CreateProject,icon:"map"},{name:l("layers"),used:e.currentServiceCount,max:e.maxServicesCount,type:t.PolicyType.CreateLayer,icon:"layers"},{name:l("tables"),used:e.currentTableCount,max:e.maxTablesCount,type:t.PolicyType.CreateTable,icon:"table"},{name:l("maxFeaturesInLayerLimit"),max:e.maxFeaturesInOneTable,type:t.PolicyType.MaxFeaturesInOneTable,icon:"points"},{name:l("maxFileSize"),max:e.maxUploadContentSize,type:t.PolicyType.MaxUploadContentSize,icon:"textfile"},{name:l("maxObjectsToExport"),max:e.maxObjectsToExport,type:t.PolicyType.MaxObjectsToExport,icon:"points"}]:[]},[l,s,o]),r.useCallback(async(e,t)=>{await c.security.setPolicy({value:e,type:t,role:"__"+n}),await u()},[c])]})({username:o,onError:x,initialLimits:u}),b=n.useDebouncedCallback(500),g=r.useCallback((e,n)=>{b(async()=>{const r=n===t.PolicyType.MaxUploadContentSize?1024*e*1024:e;await y(r,n)})},[o]);return a.createElement(w,{className:s},c&&a.createElement(L,null,c),a.createElement(j,null,d.map(e=>a.createElement(N,{key:e.name,canUpdate:l,item:e,updatePolicyItem:g}))))},exports.checkLimits=p,exports.numberWithSpaces=x,exports.resources={en:{politics:{maps:"Maps",layers:"Layers",maxFeaturesInLayerLimit:"Max objects count in layer",maxFileSize:"Max file size",maxObjectsToExport:"Max objects to export",tables:"Tables",in:"in",from:"from"}},ru:{politics:{maps:"Карты",layers:"Слои",maxFeaturesInLayerLimit:"Макс. количество объектов в слое",maxFileSize:"Макс. размер файла",maxObjectsToExport:"Макс. количество объектов для экспорта",tables:"Таблицы",in:"в",from:"из"}}},exports.useApi=m; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),n=e(t),r=require("@evergis/api"),a=require("@evergis/react"),i=require("react-i18next"),o=require("@evergis/react-fetching"),l=require("@evergis/ui"),c=e(require("styled-components"));const s=t.createContext({}),m=()=>t.useContext(s);let u;const p=e=>(u||(u=o.createResource(e=>async t=>({data:await t.resourceCatalog.checkLimits(e)}),{injected:e})),u),x=function(e,t){return void 0===t&&(t=10),null==e?"":parseFloat(("string"==typeof e?parseFloat(e):e).toString()).toLocaleString("ru-RU",{maximumFractionDigits:t})};function d(e,t){return t||(t=e.slice(0)),e.raw=t,e}var y,b,g,f,E,C,T,h,P,v,F;const w=c(l.Flex)(y||(y=d(["\n margin-top: 3rem;\n flex-direction: column;\n"]))),L=c(l.H2)(b||(b=d(["\n margin: 0;\n"]))),j=c(l.Flex)(g||(g=d(["\n flex-wrap: wrap;\n margin-top: 0.5rem;\n margin-bottom: 0.75rem;\n"]))),S=c(l.Flex)(f||(f=d(["\n margin-top: 1rem;\n margin-right: 1rem;\n width: 14.5rem;\n height: 10.5rem;\n border-radius: 2px;\n background-color: #f6f6f6;\n flex-direction: column;\n"]))),z=c(l.Flex)(E||(E=d(["\n flex-direction: column;\n align-items: center;\n padding: 1rem 1rem 0;\n width: 100%;\n box-sizing: border-box;\n"]))),M=c(l.Icon)(C||(C=d(["\n opacity: 0.28;\n"]))),k=c.span(T||(T=d(["\n font-size: 18px;\n font-weight: bold;\n margin-top: 0.75rem;\n"]))),I=c.span(h||(h=d(["\n font-size: 12px;\n color: ",";\n text-align: center;\n"])),e=>{let{theme:{palette:t}}=e;return t.textSecondary}),O=c.div(P||(P=d(["\n margin: auto 0 0;\n height: 0.5rem;\n width: 100%;\n"]))),U=c(l.RatioLine)(v||(v=d(["\n width: 100%;\n margin: 0;\n"]))),q=c(l.Flex)(F||(F=d(["\n flex-direction: column;\n width: 100%;\n margin-top: 0.75rem;\n background: white;\n"]))),N=e=>{let{item:a,updatePolicyItem:o,canUpdate:c}=e;const{t:s}=i.useTranslation("politics"),{name:m,used:u,max:p,type:d,disabled:y,icon:b}=a,g=t.useCallback(e=>{o(e||0,d)},[o]),f=d===r.PolicyType.MaxUploadContentSize?(p/1048576).toFixed(6):p,E=x(f,6);return n.createElement(S,{key:m},n.createElement(z,null,n.createElement(M,{kind:b}),n.createElement(k,null,void 0!==u?u+" "+s("from")+" "+(-1===p?"∞":E):(-1===p?"∞":E)+" "+(d===r.PolicyType.MaxUploadContentSize?"mb":"")),n.createElement(I,null,m),c&&n.createElement(q,null,n.createElement(l.NumberInput,{required:!0,disabled:y,counter:!1,width:"100%",value:+f,onChange:g}))),n.createElement(O,null,void 0!==u&&n.createElement(U,Object.assign({ratio:u/p*100},function(e,t){const n=e/t*100;return n>=90?{error:!0}:n>=75?{secondary:!0}:{primary:!0}}(u,p)))))};exports.ApiProvider=e=>{let{api:t,children:r}=e;return n.createElement(s.Provider,{value:{api:t}},r)},exports.Politics=e=>{let{username:o,canUpdate:l,title:c,className:s,initialLimits:u,onError:x}=e;const[d,y]=(e=>{let{username:n,onError:a,initialLimits:o}=e;const{t:l}=i.useTranslation("politics"),{api:c}=m(),{data:s,refetch:u,error:x}=p(c).use({input:{userName:n},waitInput:!0});return t.useEffect(()=>{x&&a&&a(x)},[x,a]),[t.useMemo(()=>{const e=s||o;return e?[{name:l("maps"),used:e.currentProjectCount,max:e.maxProjectsCount,type:r.PolicyType.CreateProject,icon:"map"},{name:l("layers"),used:e.currentServiceCount,max:e.maxServicesCount,type:r.PolicyType.CreateLayer,icon:"layers"},{name:l("tables"),used:e.currentTableCount,max:e.maxTablesCount,type:r.PolicyType.CreateTable,icon:"table"},{name:l("maxFeaturesInLayerLimit"),max:e.maxFeaturesInOneTable,type:r.PolicyType.MaxFeaturesInOneTable,icon:"points"},{name:l("maxFileSize"),max:e.maxUploadContentSize,type:r.PolicyType.MaxUploadContentSize,icon:"textfile"},{name:l("maxObjectsToExport"),max:e.maxObjectsToExport,type:r.PolicyType.MaxObjectsToExport,icon:"points"}]:[]},[l,s,o]),t.useCallback(async(e,t)=>{await c.security.setPolicy({value:e,type:t,role:"__"+n}),await u()},[c])]})({username:o,onError:x,initialLimits:u}),b=a.useDebouncedCallback(500),g=t.useCallback((e,t)=>{b(async()=>{const n=t===r.PolicyType.MaxUploadContentSize?1024*e*1024:e;await y(n,t)})},[o]);return n.createElement(w,{className:s},c&&n.createElement(L,null,c),n.createElement(j,null,d.map(e=>n.createElement(N,{key:e.name,canUpdate:l,item:e,updatePolicyItem:g}))))},exports.checkLimits=p,exports.numberWithSpaces=x,exports.resources={en:{politics:{maps:"Maps",layers:"Layers",maxFeaturesInLayerLimit:"Max objects count in layer",maxFileSize:"Max file size",maxObjectsToExport:"Max objects to export",tables:"Tables",in:"in",from:"from"}},ru:{politics:{maps:"Карты",layers:"Слои",maxFeaturesInLayerLimit:"Макс. количество объектов в слое",maxFileSize:"Макс. размер файла",maxObjectsToExport:"Макс. количество объектов для экспорта",tables:"Таблицы",in:"в",from:"из"}}},exports.useApi=m; | ||
//# sourceMappingURL=common.cjs.production.min.js.map |
@@ -0,4 +1,4 @@ | ||
import React, { useContext, createContext, useEffect, useMemo, useCallback } from 'react'; | ||
import { PolicyType } from '@evergis/api'; | ||
import { useDebouncedCallback } from '@evergis/react'; | ||
import React, { useContext, createContext, useEffect, useMemo, useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
@@ -5,0 +5,0 @@ import { createResource } from '@evergis/react-fetching'; |
{ | ||
"version": "0.0.57", | ||
"version": "0.0.60", | ||
"license": "MIT", | ||
@@ -50,3 +50,3 @@ "main": "dist/index.js", | ||
"@babel/preset-env": "^7.16.11", | ||
"@evergis/api": "^3.0.159", | ||
"@evergis/api": "^3.0.162", | ||
"@evergis/react-fetching": "0.1.8", | ||
@@ -68,3 +68,3 @@ "@evergis/sgis": "0.5.0-alpha.60", | ||
}, | ||
"gitHead": "d8affb7611cc95b07d0441f3dfa4d7b52a2cd526" | ||
"gitHead": "cafb25bfd0c9a16802191b195b70f03f6ba6ebb5" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88165