pome-ui 2.0.0-preview2 → 2.0.0-preview21

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.
@@ -40,7 +40,6 @@
40
40
  batchInterval: null,
41
41
  batchTimeout: 10
42
42
  };
43
- _combineObject(window.CQOptions || {}, _options);
44
43
 
45
44
  var _batchRequests = [];
46
45
 
@@ -81,8 +80,6 @@
81
80
  var __cache = {};
82
81
  var __cacheDictionary = {};
83
82
  var __cacheExpire = {};
84
- var __cacheFilters = {};
85
- var __cacheSubscribe = {};
86
83
 
87
84
  function randomString(length, chars = null) {
88
85
  chars = chars || '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
@@ -93,7 +90,7 @@
93
90
  return result;
94
91
  }
95
92
 
96
- function SetOptions(options) {
93
+ function UseConfig(options) {
97
94
  _combineObject(options, _options);
98
95
  }
99
96
 
@@ -226,6 +223,34 @@
226
223
  }
227
224
  }
228
225
 
226
+ function getSync(endpoint, params, dataType = 'json') {
227
+ var names = Object.getOwnPropertyNames(params || {});
228
+ if (names.length) {
229
+ if (endpoint.indexOf('?') >= 0) {
230
+ endpoint += '&';
231
+ } else {
232
+ endpoint += '?';
233
+ }
234
+ }
235
+
236
+ for (var i = 0; i < names.length; ++i) {
237
+ var name = names[i];
238
+ endpoint += encodeURIComponent(name) + '=' + encodeURIComponent(params[name] || '') + '&';
239
+ }
240
+
241
+ if (names.length) {
242
+ endpoint = endpoint.substr(0, endpoint.length - 1);
243
+ }
244
+
245
+ var xhr = new XMLHttpRequest();
246
+ xhr.open('get', endpoint, false);
247
+ if (_options.beforeSend) {
248
+ _options.beforeSend(xhr);
249
+ }
250
+ xhr.send();
251
+ return dataType == 'json' ? JSON.parse(xhr.responseText) : xhr.responseText;
252
+ };
253
+
229
254
  function get(endpoint, params, dataType, contentType) {
230
255
  var names = Object.getOwnPropertyNames(params || {});
231
256
  if (names.length) {
@@ -315,11 +340,12 @@
315
340
  exports.xhrRequest = _xhrRequest;
316
341
  exports.request = request;
317
342
  exports.get = get;
343
+ exports.getSync = getSync;
318
344
  exports.post = post;
319
345
  exports.put = put;
320
346
  exports.patch = patch;
321
347
  exports.delete = _delete;
322
- exports.setOptions = SetOptions;
348
+ exports.useConfig = UseConfig;
323
349
 
324
350
  return exports;
325
351
 
@@ -1 +1 @@
1
- (function(e){if(typeof e!="undefined"&&e.get){return e}function n(e,n){if(!e){return}var t=Object.getOwnPropertyNames(e);for(var r=0;r<t.length;++r){n[t[r]]=e[t[r]]}}var f={isPagedResult(e){if(e.totalRecords==undefined||e.totalPages===undefined||e.currentPage===undefined||e.pageSize===undefined)return false;else return true},beforeSend:function(e){},onError:function(e,n){return Promise.resolve(e)},onSucceeded:function(e,n){return Promise.resolve(e)},baseUrl:null,batch:null,batchInterval:null,batchTimeout:10};n(window.CQOptions||{},f);var t=[];var r=function(e){var n=[];for(var t=0;t<e.length;++t){n.push(e[t])}return n};if(f.batch){setInterval(function(){if(!t.length){return}f.batch(t,y,f);t=[]},f.batchInterval||50)}function o(e){var n=JSON.stringify(e);return JSON.parse(n)}function a(e){var n=[];if(!e||typeof e!=="object")return n;for(var t in e){if(e[t])n.push(t)}return n}var i={};var u={};var s={};var c={};var l={};function d(e,n=null){n=n||"1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";var t="";for(var r=e;r>0;--r){t+=n[Math.floor(Math.random()*n.length)]}return t}function p(e){n(e,f)}function v(e,n=true,t=null){var r=Object.keys(e).sort();if(!r.length)return"";var o=n?"?":"";for(var a=0;a<r.length;a++){if(t){if(t.some(e=>e==r[a])){continue}}o+=r[a]+"="+encodeURI(e[r[a]])+"&"}return o.substr(0,o.length-1)}function g(e){e=e.substr(e.indexOf("?")+1);var n=e.split("&");var t={};for(var r=0;r<n.length;r++){var o=n[r].split("=");t[o[0]]=decodeURI(o[1])}return t}function h(e,n,t){var r=o(n);if(t&&r.page)delete r.page;return e+v(r)}function b(e){return f.isPagedResult(e)}function y(n){var t=new XMLHttpRequest;t.open(n.type,n.url);t.setRequestHeader("Content-Type",n.contentType);if(n.beforeSend){n.beforeSend(t)}if(typeof n.data!=="string"){if(n.contentType.toLocaleLowerCase()=="application/json"){n.data=JSON.stringify(n.data)}else if(n.contentType.toLocaleLowerCase()=="application/octet-stream"){}else{n.data=v(n.data,false)}}t.send(n.data);t.onreadystatechange=function(){if(t.readyState==4){var e=n.dataType=="json"?JSON.parse(t.responseText):t.responseText;if(t.status>=200&&t.status<300){n.success(e,t)}else{n.error(e,t)}}};return t}function m(e){if(e.indexOf("//")>=0){return e}else if(f.baseUrl){return f.baseUrl+e}else{return e}}function O(o,a,i,e,u){e=e||"json";u=u||"application/json";i=a=="GET"?null:i;o=m(o);if(!f.batch||e!="json"||u!="application/json"){var n=this;return new Promise(function(n,t){var r=y({url:o,type:a,dataType:e,contentType:u||"application/json",data:a=="GET"?null:i,success:function(e){f.onSucceeded(e,r).then(function(e){n(e)})},error:function(e){return f.onError(e,r).then(function(e){t(e)})},beforeSend:function(e){f.beforeSend(e)}})})}else{return new Promise(function(e,n){t.push({resolve:e,reject:n,request:{requestId:d(32),url:o,method:a,body:i?JSON.stringify(i):null,contentType:"application/json",timeout:f.batchTimeout}})})}}function T(e,n,t,r){var o=Object.getOwnPropertyNames(n||{});if(o.length){if(e.indexOf("?")>=0){e+="&"}else{e+="?"}}for(var a=0;a<o.length;++a){var i=o[a];e+=encodeURIComponent(i)+"="+encodeURIComponent(n[i]||"")+"&"}if(o.length){e=e.substr(0,e.length-1)}return O(e,"GET",n,t,r)}function j(e,n,t,r){return O(e,"POST",n,t,r)}function S(e,n,t,r){return O(e,"PATCH",n,t,r)}function w(e,n,t,r){return O(e,"PUT",n,t,r)}function P(e,n,t){var r=Object.getOwnPropertyNames(n||{});if(r.length){if(e.indexOf("?")>=0){e+="&"}else{e+="?"}}for(var o=0;o<r.length;++o){var a=r[o];e+=encodeURIComponent(a)+"="+encodeURIComponent(n[a]||"")+"&"}if(r.length){e=e.substr(0,e.length-1)}return O(e,"DELETE",n,t)}function R(e,n){var t=a(n);var r=h(e,n,t.some(e=>e==="page"));if(i[r]){delete i[r]}}function I(e,n,t,r){var o;if(!u[e])u[e]=[];var a=b(t);if(!a){o=h(e,n);i[o]=t}else{o=h(e,n,true);if(!i[o])i[o]={isPaged:true};i[o][t.data.current]=t}if(!u[e].some(e=>e==o))u[e].push(o);if(r)s[o]=(new Date).getTime()+r}e.generateQueryStringFromObject=v;e.generateObjectFromQueryString=g;e.xhrRequest=y;e.request=O;e.get=T;e.post=j;e.put=w;e.patch=S;e.delete=P;e.setOptions=p;return e})(typeof exports==="object"&&typeof module!=="undefined"?exports:function(){window.cq={};return window.cq}());
1
+ (function(e){if(typeof e!="undefined"&&e.get){return e}function n(e,n){if(!e){return}var t=Object.getOwnPropertyNames(e);for(var r=0;r<t.length;++r){n[t[r]]=e[t[r]]}}var f={isPagedResult(e){if(e.totalRecords==undefined||e.totalPages===undefined||e.currentPage===undefined||e.pageSize===undefined)return false;else return true},beforeSend:function(e){},onError:function(e,n){return Promise.resolve(e)},onSucceeded:function(e,n){return Promise.resolve(e)},baseUrl:null,batch:null,batchInterval:null,batchTimeout:10};var t=[];var r=function(e){var n=[];for(var t=0;t<e.length;++t){n.push(e[t])}return n};if(f.batch){setInterval(function(){if(!t.length){return}f.batch(t,h,f);t=[]},f.batchInterval||50)}function o(e){var n=JSON.stringify(e);return JSON.parse(n)}function a(e){var n=[];if(!e||typeof e!=="object")return n;for(var t in e){if(e[t])n.push(t)}return n}var i={};var u={};var s={};function c(e,n=null){n=n||"1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";var t="";for(var r=e;r>0;--r){t+=n[Math.floor(Math.random()*n.length)]}return t}function l(e){n(e,f)}function d(e,n=true,t=null){var r=Object.keys(e).sort();if(!r.length)return"";var o=n?"?":"";for(var a=0;a<r.length;a++){if(t){if(t.some(e=>e==r[a])){continue}}o+=r[a]+"="+encodeURI(e[r[a]])+"&"}return o.substr(0,o.length-1)}function p(e){e=e.substr(e.indexOf("?")+1);var n=e.split("&");var t={};for(var r=0;r<n.length;r++){var o=n[r].split("=");t[o[0]]=decodeURI(o[1])}return t}function g(e,n,t){var r=o(n);if(t&&r.page)delete r.page;return e+d(r)}function v(e){return f.isPagedResult(e)}function h(n){var t=new XMLHttpRequest;t.open(n.type,n.url);t.setRequestHeader("Content-Type",n.contentType);if(n.beforeSend){n.beforeSend(t)}if(typeof n.data!=="string"){if(n.contentType.toLocaleLowerCase()=="application/json"){n.data=JSON.stringify(n.data)}else if(n.contentType.toLocaleLowerCase()=="application/octet-stream"){}else{n.data=d(n.data,false)}}t.send(n.data);t.onreadystatechange=function(){if(t.readyState==4){var e=n.dataType=="json"?JSON.parse(t.responseText):t.responseText;if(t.status>=200&&t.status<300){n.success(e,t)}else{n.error(e,t)}}};return t}function b(e){if(e.indexOf("//")>=0){return e}else if(f.baseUrl){return f.baseUrl+e}else{return e}}function y(o,a,i,e,u){e=e||"json";u=u||"application/json";i=a=="GET"?null:i;o=b(o);if(!f.batch||e!="json"||u!="application/json"){var n=this;return new Promise(function(n,t){var r=h({url:o,type:a,dataType:e,contentType:u||"application/json",data:a=="GET"?null:i,success:function(e){f.onSucceeded(e,r).then(function(e){n(e)})},error:function(e){return f.onError(e,r).then(function(e){t(e)})},beforeSend:function(e){f.beforeSend(e)}})})}else{return new Promise(function(e,n){t.push({resolve:e,reject:n,request:{requestId:c(32),url:o,method:a,body:i?JSON.stringify(i):null,contentType:"application/json",timeout:f.batchTimeout}})})}}function m(e,n,t="json"){var r=Object.getOwnPropertyNames(n||{});if(r.length){if(e.indexOf("?")>=0){e+="&"}else{e+="?"}}for(var o=0;o<r.length;++o){var a=r[o];e+=encodeURIComponent(a)+"="+encodeURIComponent(n[a]||"")+"&"}if(r.length){e=e.substr(0,e.length-1)}var i=new XMLHttpRequest;i.open("get",e,false);if(f.beforeSend){f.beforeSend(i)}i.send();return t=="json"?JSON.parse(i.responseText):i.responseText}function O(e,n,t,r){var o=Object.getOwnPropertyNames(n||{});if(o.length){if(e.indexOf("?")>=0){e+="&"}else{e+="?"}}for(var a=0;a<o.length;++a){var i=o[a];e+=encodeURIComponent(i)+"="+encodeURIComponent(n[i]||"")+"&"}if(o.length){e=e.substr(0,e.length-1)}return y(e,"GET",n,t,r)}function T(e,n,t,r){return y(e,"POST",n,t,r)}function S(e,n,t,r){return y(e,"PATCH",n,t,r)}function j(e,n,t,r){return y(e,"PUT",n,t,r)}function P(e,n,t){var r=Object.getOwnPropertyNames(n||{});if(r.length){if(e.indexOf("?")>=0){e+="&"}else{e+="?"}}for(var o=0;o<r.length;++o){var a=r[o];e+=encodeURIComponent(a)+"="+encodeURIComponent(n[a]||"")+"&"}if(r.length){e=e.substr(0,e.length-1)}return y(e,"DELETE",n,t)}function w(e,n){var t=a(n);var r=g(e,n,t.some(e=>e==="page"));if(i[r]){delete i[r]}}function R(e,n,t,r){var o;if(!u[e])u[e]=[];var a=v(t);if(!a){o=g(e,n);i[o]=t}else{o=g(e,n,true);if(!i[o])i[o]={isPaged:true};i[o][t.data.current]=t}if(!u[e].some(e=>e==o))u[e].push(o);if(r)s[o]=(new Date).getTime()+r}e.generateQueryStringFromObject=d;e.generateObjectFromQueryString=p;e.xhrRequest=h;e.request=y;e.get=O;e.getSync=m;e.post=T;e.put=j;e.patch=S;e.delete=P;e.useConfig=l;return e})(typeof exports==="object"&&typeof module!=="undefined"?exports:function(){window.cq={};return window.cq}());
@@ -4,11 +4,16 @@
4
4
  function create() {
5
5
  var currentLocale = null;
6
6
  return {
7
+ localesGroups: [],
7
8
  locales: {},
8
9
  texts: {},
10
+ overrides: {},
9
11
  getCurrentLocale() {
10
12
  return currentLocale;
11
13
  },
14
+ getLocalesGroups() {
15
+ return this.localesGroups;
16
+ },
12
17
  addLocale(path, locales, isFallback) {
13
18
  if (!locales) {
14
19
  var index = path.lastIndexOf('/');
@@ -20,6 +25,8 @@ function create() {
20
25
  locales = locales.split('.')[0];
21
26
  }
22
27
 
28
+ this.localesGroups.push(locales);
29
+
23
30
  if (typeof locales == 'string') {
24
31
  this.locales[locales] = path;
25
32
  } else if (locales instanceof Array) {
@@ -67,15 +74,34 @@ function create() {
67
74
  if (arguments.length == 0) {
68
75
  return null;
69
76
  }
77
+
70
78
  var key = arguments[0];
71
79
  var val = key;
72
- if (this.texts[key]) {
80
+ var foundInOverrides = false;
81
+ if (this.overrides[this.getCurrentLocale()] && this.overrides[this.getCurrentLocale()][key]) {
82
+ val = this.overrides[this.getCurrentLocale()][key];
83
+ foundInOverrides = true;
84
+ }
85
+
86
+ if (!foundInOverrides && this.texts[key]) {
73
87
  val = this.texts[key];
74
88
  }
89
+
75
90
  for (var i = 1; i < arguments.length; ++i) {
76
91
  val = val.replaceAll(`{${i - 1}}`, arguments[i]);
77
92
  }
93
+
78
94
  return val;
95
+ },
96
+ setLocalizedString(locales, key, val) {
97
+ var self = this;
98
+ locales.forEach(function (locale) {
99
+ if (!self.overrides[locale]) {
100
+ self.overrides[locale] = {};
101
+ }
102
+
103
+ self.overrides[locale][key] = val;
104
+ });
79
105
  }
80
106
  };
81
107
  }
@@ -1 +1 @@
1
- function create(){var s=null;return{locales:{},texts:{},getCurrentLocale(){return s},addLocale(e,l,t){if(!l){var a=e.lastIndexOf("/");if(a<0){l=e}else{l=e.substr(e,a+1)}l=l.split(".")[0]}if(typeof l=="string"){this.locales[l]=e}else if(l instanceof Array){for(var s=0;s<l.length;++s){this.locales[l[s]]=e}}if(t){this.locales["fallback"]=e}},setLocale(e){if(!e){e=!window.localStorage.locale?window.navigator.language:window.localStorage.locale}if(!this.locales[e]){e="fallback"}if(!this.locales[e]){throw"No available translations for the locale"}s=e;this.texts=require(this.locales[e]).texts;if(this.locales["fallback"]){if(this.locales[e]!=this.locales["fallback"]){var l=require(this.locales["fallback"]).texts;var t=Object.getOwnPropertyNames(l);var a=this;t.forEach(function(e){if(!a.texts[e]){a.texts[e]=l[e]}})}}},sr(){if(arguments.length==0){return null}var e=arguments[0];var l=e;if(this.texts[e]){l=this.texts[e]}for(var t=1;t<arguments.length;++t){l=l.replaceAll(`{${t-1}}`,arguments[t])}return l}}}exports.create=create;
1
+ function create(){var s=null;return{localesGroups:[],locales:{},texts:{},overrides:{},getCurrentLocale(){return s},getLocalesGroups(){return this.localesGroups},addLocale(e,t,l){if(!t){var r=e.lastIndexOf("/");if(r<0){t=e}else{t=e.substr(e,r+1)}t=t.split(".")[0]}this.localesGroups.push(t);if(typeof t=="string"){this.locales[t]=e}else if(t instanceof Array){for(var s=0;s<t.length;++s){this.locales[t[s]]=e}}if(l){this.locales["fallback"]=e}},setLocale(e){if(!e){e=!window.localStorage.locale?window.navigator.language:window.localStorage.locale}if(!this.locales[e]){e="fallback"}if(!this.locales[e]){throw"No available translations for the locale"}s=e;this.texts=require(this.locales[e]).texts;if(this.locales["fallback"]){if(this.locales[e]!=this.locales["fallback"]){var t=require(this.locales["fallback"]).texts;var l=Object.getOwnPropertyNames(t);var r=this;l.forEach(function(e){if(!r.texts[e]){r.texts[e]=t[e]}})}}},sr(){if(arguments.length==0){return null}var e=arguments[0];var t=e;var l=false;if(this.overrides[this.getCurrentLocale()]&&this.overrides[this.getCurrentLocale()][e]){t=this.overrides[this.getCurrentLocale()][e];l=true}if(!l&&this.texts[e]){t=this.texts[e]}for(var r=1;r<arguments.length;++r){t=t.replaceAll(`{${r-1}}`,arguments[r])}return t},setLocalizedString(e,t,l){var r=this;e.forEach(function(e){if(!r.overrides[e]){r.overrides[e]={}}r.overrides[e][t]=l})}}}exports.create=create;