@wavemaker/angular-codegen 11.0.1-next.138730 → 11.0.1-next.138733

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.
@@ -38622,9 +38622,12 @@ class ASTCompiler {
38622
38622
  cleanup() {
38623
38623
  this.ast = this.cAst = this.stmts = this.cStmts = this.declarations = this.pipes = this.pipeNameVsIsPureMap = undefined;
38624
38624
  }
38625
- compile() {
38625
+ compile(defOnly) {
38626
38626
  this.extendCtxWithLocals();
38627
38627
  this.addReturnStmt(this.build(this.ast));
38628
+ if (defOnly) {
38629
+ return { fnBody: this.fnBody(), fnArgs: this.fnArgs(), pipes: this.pipes };
38630
+ }
38628
38631
  const fn = new Function(this.fnArgs(), this.fnBody());
38629
38632
  let boundFn;
38630
38633
  if (this.exprType === ExpressionType$1.Binding) {
@@ -38643,13 +38646,27 @@ const nullPipe = () => {
38643
38646
  transform: noop$1$1
38644
38647
  };
38645
38648
  };
38649
+ let _cspEnabled;
38650
+ const isCSPEnabled = () => {
38651
+ if (typeof _cspEnabled !== 'undefined') {
38652
+ return _cspEnabled;
38653
+ }
38654
+ try {
38655
+ new Function();
38656
+ _cspEnabled = false;
38657
+ }
38658
+ catch (e) {
38659
+ _cspEnabled = true;
38660
+ }
38661
+ return _cspEnabled;
38662
+ };
38646
38663
  let pipeProvider;
38647
38664
  var ExpressionType$1;
38648
38665
  (function (ExpressionType$$1) {
38649
38666
  ExpressionType$$1[ExpressionType$$1["Binding"] = 0] = "Binding";
38650
38667
  ExpressionType$$1[ExpressionType$$1["Action"] = 1] = "Action";
38651
38668
  })(ExpressionType$1 || (ExpressionType$1 = {}));
38652
- function $parseExpr(expr) {
38669
+ function $parseExpr(expr, defOnly) {
38653
38670
  if (!pipeProvider) {
38654
38671
  console.log('set pipe provider');
38655
38672
  return noop$1$1;
@@ -38668,51 +38685,89 @@ function $parseExpr(expr) {
38668
38685
  if (fn) {
38669
38686
  return fn;
38670
38687
  }
38671
- const parser = new Parser$1(new Lexer);
38672
- const ast = parser.parseBinding(expr, '', 0);
38673
38688
  let boundFn;
38674
- if (ast.errors.length) {
38675
- fn = noop$1$1;
38676
- boundFn = fn;
38677
- }
38678
- else {
38679
- const pipeNameVsIsPureMap = pipeProvider.getPipeNameVsIsPureMap();
38680
- const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Binding, pipeNameVsIsPureMap);
38681
- fn = astCompiler.compile();
38682
- if (fn.usedPipes.length) {
38683
- const pipeArgs = [];
38684
- let hasPurePipe = false;
38685
- for (const [pipeName] of fn.usedPipes) {
38686
- const pipeInfo = pipeProvider.meta(pipeName);
38687
- let pipeInstance;
38688
- if (!pipeInfo) {
38689
- pipeInstance = nullPipe;
38689
+ if (!defOnly) {
38690
+ boundFn = getFnForBindExpr(expr);
38691
+ }
38692
+ // fallback to generate function in runtime. This will break if CSP is enabled
38693
+ if (!boundFn) {
38694
+ // If CSP enabled, function def not found from the generated fn expressions for the page.
38695
+ // Handle bind expressions used internally inside WM components. e.g. wmAnchor used inside nav.comp.html
38696
+ if (isCSPEnabled()) {
38697
+ boundFn = function (ctx, locals) {
38698
+ // handle internal bindings for wm widgets used inside a component
38699
+ let _ctx = Object.assign({}, locals);
38700
+ Object.setPrototypeOf(_ctx, ctx);
38701
+ return _.get(_ctx, expr);
38702
+ };
38703
+ }
38704
+ else {
38705
+ const parser = new Parser$1(new Lexer);
38706
+ const ast = parser.parseBinding(expr, '', 0);
38707
+ if (ast.errors.length) {
38708
+ fn = noop$1$1;
38709
+ boundFn = fn;
38710
+ }
38711
+ else {
38712
+ const pipeNameVsIsPureMap = pipeProvider.getPipeNameVsIsPureMap();
38713
+ const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Binding, pipeNameVsIsPureMap);
38714
+ fn = astCompiler.compile(defOnly);
38715
+ if (defOnly) {
38716
+ return fn;
38717
+ }
38718
+ if (fn.usedPipes.length) {
38719
+ const pipeArgs = [];
38720
+ let hasPurePipe = false;
38721
+ for (const [pipeName] of fn.usedPipes) {
38722
+ const pipeInfo = pipeProvider.meta(pipeName);
38723
+ let pipeInstance;
38724
+ if (!pipeInfo) {
38725
+ pipeInstance = nullPipe;
38726
+ }
38727
+ else {
38728
+ if (pipeInfo.pure) {
38729
+ hasPurePipe = true;
38730
+ pipeInstance = purePipes.get(pipeName);
38731
+ }
38732
+ if (!pipeInstance) {
38733
+ pipeInstance = pipeProvider.getInstance(pipeName);
38734
+ }
38735
+ if (pipeInfo.pure) {
38736
+ purePipes.set(pipeName, pipeInstance);
38737
+ }
38738
+ }
38739
+ pipeArgs.push(pipeInstance);
38740
+ }
38741
+ pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
38742
+ boundFn = fn.bind(undefined, ...pipeArgs);
38690
38743
  }
38691
38744
  else {
38692
- if (pipeInfo.pure) {
38693
- hasPurePipe = true;
38694
- pipeInstance = purePipes.get(pipeName);
38695
- }
38696
- if (!pipeInstance) {
38697
- pipeInstance = pipeProvider.getInstance(pipeName);
38698
- }
38699
- if (pipeInfo.pure) {
38700
- purePipes.set(pipeName, pipeInstance);
38701
- }
38745
+ boundFn = fn.bind(undefined, undefined);
38702
38746
  }
38703
- pipeArgs.push(pipeInstance);
38704
38747
  }
38705
- pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
38706
- boundFn = fn.bind(undefined, ...pipeArgs);
38707
- }
38708
- else {
38709
- boundFn = fn.bind(undefined, undefined);
38710
38748
  }
38711
38749
  }
38712
38750
  exprFnCache.set(expr, boundFn);
38713
38751
  return boundFn;
38714
38752
  }
38715
- function $parseEvent(expr) {
38753
+ function simpleFunctionEvaluator(expr, ctx, locals) {
38754
+ let _ctx = Object.assign({}, locals);
38755
+ Object.setPrototypeOf(_ctx, ctx);
38756
+ let parts = expr.split('(');
38757
+ let fnName = parts[0];
38758
+ let computedFn = _.get(ctx, fnName);
38759
+ if (computedFn) {
38760
+ let args = parts[1].replace(')', '');
38761
+ args = args.split(',');
38762
+ let computedArgs = [];
38763
+ args.forEach((arg) => {
38764
+ arg = arg && arg.trim();
38765
+ computedArgs.push(_.get(_ctx, arg));
38766
+ });
38767
+ return computedFn.bind(_ctx)(...computedArgs);
38768
+ }
38769
+ }
38770
+ function $parseEvent(expr, defOnly) {
38716
38771
  if (!isString$1(expr)) {
38717
38772
  return noop$1$1;
38718
38773
  }
@@ -38724,16 +38779,80 @@ function $parseEvent(expr) {
38724
38779
  if (fn) {
38725
38780
  return fn;
38726
38781
  }
38727
- const parser = new Parser$1(new Lexer);
38728
- const ast = parser.parseAction(expr, '', 0);
38729
- if (ast.errors.length) {
38730
- return noop$1$1;
38782
+ if (!defOnly) {
38783
+ fn = getFnForEventExpr(expr);
38784
+ }
38785
+ // fallback to generate function in runtime. This will break if CSP is enabled
38786
+ if (!fn) {
38787
+ if (isCSPEnabled()) {
38788
+ fn = simpleFunctionEvaluator.bind(undefined, expr);
38789
+ }
38790
+ else {
38791
+ const parser = new Parser$1(new Lexer);
38792
+ const ast = parser.parseAction(expr, '', 0);
38793
+ if (ast.errors.length) {
38794
+ return noop$1$1;
38795
+ }
38796
+ const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Action);
38797
+ fn = astCompiler.compile(defOnly);
38798
+ }
38731
38799
  }
38732
- const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Action);
38733
- fn = astCompiler.compile();
38734
38800
  eventFnCache.set(expr, fn);
38735
38801
  return fn;
38736
38802
  }
38803
+ const fnNameMap = new Map();
38804
+ const getFnByExpr = (expr) => fnNameMap.get(expr);
38805
+ const fnExecutor = (expr, exprType) => {
38806
+ let fn = getFnByExpr(expr);
38807
+ if (!fn) {
38808
+ return;
38809
+ }
38810
+ const usedPipes = fn.usedPipes || [];
38811
+ if (exprType === ExpressionType$1.Binding) {
38812
+ fn = fn.bind(undefined, plus, minus, isDef, getPurePipeVal);
38813
+ }
38814
+ else {
38815
+ fn = fn.bind(undefined, plus, minus, isDef);
38816
+ }
38817
+ if (usedPipes.length) {
38818
+ const pipeArgs = [];
38819
+ let hasPurePipe = false;
38820
+ for (const [pipeName] of usedPipes) {
38821
+ const pipeInfo = pipeProvider.meta(pipeName);
38822
+ let pipeInstance;
38823
+ if (!pipeInfo) {
38824
+ pipeInstance = nullPipe;
38825
+ }
38826
+ else {
38827
+ if (pipeInfo.pure) {
38828
+ hasPurePipe = true;
38829
+ pipeInstance = purePipes.get(pipeName);
38830
+ }
38831
+ if (!pipeInstance) {
38832
+ pipeInstance = pipeProvider.getInstance(pipeName);
38833
+ }
38834
+ if (pipeInfo.pure) {
38835
+ purePipes.set(pipeName, pipeInstance);
38836
+ }
38837
+ }
38838
+ pipeArgs.push(pipeInstance);
38839
+ }
38840
+ pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
38841
+ fn = fn.bind(undefined, ...pipeArgs);
38842
+ }
38843
+ else {
38844
+ if (exprType === ExpressionType$1.Binding) {
38845
+ fn = fn.bind(undefined, undefined);
38846
+ }
38847
+ }
38848
+ return fn;
38849
+ };
38850
+ const getFnForBindExpr = (expr) => {
38851
+ return fnExecutor(expr, ExpressionType$1.Binding);
38852
+ };
38853
+ const getFnForEventExpr = (expr) => {
38854
+ return fnExecutor(expr, ExpressionType$1.Action);
38855
+ };
38737
38856
 
38738
38857
  const registry = new Map();
38739
38858
  const watchIdGenerator = new IDGenerator('watch-id-');
@@ -38840,6 +38959,7 @@ var Operation;
38840
38959
  Operation["SUPPORTS_CRUD"] = "supportsCRUD";
38841
38960
  Operation["SUPPORTS_DISTINCT_API"] = "supportsDistinctAPI";
38842
38961
  Operation["IS_PAGEABLE"] = "isPageable";
38962
+ Operation["IS_SORTABLE"] = "isSortable";
38843
38963
  Operation["GET_OPERATION_TYPE"] = "getOperationType";
38844
38964
  Operation["GET_RELATED_PRIMARY_KEYS"] = "getRelatedTablePrimaryKeys";
38845
38965
  Operation["GET_ENTITY_NAME"] = "getEntityName";
@@ -39573,10 +39693,26 @@ const loadScript = (url, loadViaScriptTag, cacheable = false) => __awaiter$1(voi
39573
39693
  return Promise.resolve();
39574
39694
  }
39575
39695
  if (loadViaScriptTag) {
39576
- return fetchContent('text', _url, false, text => {
39577
- const script = document.createElement('script');
39578
- script.textContent = text;
39579
- document.head.appendChild(script);
39696
+ return new Promise((resolve, reject) => {
39697
+ let script = document.createElement('script');
39698
+ script.type = 'text/javascript';
39699
+ script.src = _url;
39700
+ script.async = false;
39701
+ if (script.readyState) { //IE
39702
+ script.onreadystatechange = () => {
39703
+ if (script.readyState === "loaded" || script.readyState === "complete") {
39704
+ script.onreadystatechange = null;
39705
+ resolve(true);
39706
+ }
39707
+ };
39708
+ }
39709
+ else { //Other browsers
39710
+ script.onload = () => {
39711
+ resolve(true);
39712
+ };
39713
+ }
39714
+ script.onerror = (error) => reject(error);
39715
+ document.getElementsByTagName('head')[0].appendChild(script);
39580
39716
  });
39581
39717
  }
39582
39718
  else if (cacheable) {
@@ -39592,13 +39728,6 @@ const loadScript = (url, loadViaScriptTag, cacheable = false) => __awaiter$1(voi
39592
39728
  .done(response => response)
39593
39729
  .fail(reason => reason);
39594
39730
  }
39595
- // return fetch(_url)
39596
- // .then(response => response.text())
39597
- // .then(text => {
39598
- // const script = document.createElement('script');
39599
- // script.textContent = text;
39600
- // document.head.appendChild(script);
39601
- // });
39602
39731
  });
39603
39732
  const loadScripts = (urls = [], loadViaScriptTag = true) => __awaiter$1(void 0, void 0, void 0, function* () {
39604
39733
  for (const url of urls) {
@@ -39628,7 +39757,8 @@ const setSessionStorageItem = (key, value) => {
39628
39757
  * @param key string
39629
39758
  */
39630
39759
  const getSessionStorageItem = key => {
39631
- let item = window.sessionStorage.getItem(_WM_APP_PROJECT.id);
39760
+ // sanity check for this to work with ng-codegen
39761
+ let item = window && window.sessionStorage && window.sessionStorage.getItem(_WM_APP_PROJECT.id);
39632
39762
  if (item) {
39633
39763
  item = JSON.parse(item);
39634
39764
  return item[key];
@@ -39852,6 +39982,7 @@ const processFilterExpBindNode = (context, filterExpressions) => {
39852
39982
  const filter$ = new Subject();
39853
39983
  const bindFilExpObj = (obj, targetNodeKey) => {
39854
39984
  if (stringStartsWith(obj[targetNodeKey], 'bind:')) {
39985
+ // [Todo-CSP]: needs a check, where is this used
39855
39986
  destroyFn($watch(obj[targetNodeKey].replace('bind:', ''), context, {}, (newVal, oldVal) => {
39856
39987
  if ((newVal === oldVal && _.isUndefined(newVal)) || (_.isUndefined(newVal) && !_.isUndefined(oldVal))) {
39857
39988
  return;
@@ -40095,6 +40226,7 @@ const triggerItemAction = (scope, item) => {
40095
40226
  const linkTarget = item.target;
40096
40227
  if (itemAction) {
40097
40228
  if (!scope.itemActionFn) {
40229
+ //[Todo-CSP]: This will not work as function will be dynamic
40098
40230
  scope.itemActionFn = $parseEvent(itemAction);
40099
40231
  }
40100
40232
  scope.itemActionFn(scope.userDefinedExecutionContext, Object.create(item));
@@ -41212,7 +41344,7 @@ class PaginationService {
41212
41344
  parent.gridOptions.setDeletedRowIndex(-1);
41213
41345
  }
41214
41346
  // reset fieldDefs if last action performed is search or sort
41215
- if (parent.widgetType === 'wm-table' && (parent.gridOptions.isNavTypeScrollOrOndemand()) && (parent.gridOptions.lastActionPerformed === parent.gridOptions.ACTIONS.SEARCH_OR_SORT || parent.gridOptions.lastActionPerformed === parent.gridOptions.ACTIONS.FILTER_CRITERIA)) {
41347
+ if (parent.widgetType === 'wm-table' && (parent.gridOptions.isNavTypeScrollOrOndemand()) && (parent.gridOptions.lastActionPerformed === parent.gridOptions.ACTIONS.SEARCH_OR_SORT || parent.gridOptions.lastActionPerformed === parent.gridOptions.ACTIONS.FILTER_CRITERIA || parent.gridOptions.lastActionPerformed === parent.gridOptions.ACTIONS.DATASET_UPDATE)) {
41216
41348
  fieldDefs = [];
41217
41349
  parent.gridOptions.setCurrentPage(1);
41218
41350
  }
@@ -41811,7 +41943,7 @@ const getRequiredProviders = (nodeDef, providers, nodeAttrs) => {
41811
41943
  }
41812
41944
  });
41813
41945
  };
41814
- const ɵ11 = getRequiredProviders;
41946
+ const ɵ11$1 = getRequiredProviders;
41815
41947
  const DIMENSION_PROPS = ['padding', 'borderwidth', 'margin'];
41816
41948
  const SEPARATOR = ' ', UNSET = 'unset';
41817
41949
  const setDimensionProp = (cssObj, key, nv) => {
@@ -41846,7 +41978,7 @@ const setDimensionProp = (cssObj, key, nv) => {
41846
41978
  cssObj[cssKey] = nv;
41847
41979
  }
41848
41980
  };
41849
- const ɵ12 = setDimensionProp;
41981
+ const ɵ12$1 = setDimensionProp;
41850
41982
  const processDimensionAttributes = attrMap => {
41851
41983
  const attrKeys = Array.from(attrMap.keys());
41852
41984
  attrKeys.forEach((attrKey) => {
@@ -44097,8 +44229,8 @@ var layout_build$1 = /*#__PURE__*/Object.freeze({
44097
44229
  const tagName$n = 'router-outlet';
44098
44230
  register('wm-router-outlet', () => {
44099
44231
  return {
44100
- pre: attrs => `<${tagName$n} ${getAttrMarkup(attrs)}>`,
44101
- post: () => `</${tagName$n}>`
44232
+ pre: attrs => `<div wmRouterOutlet ${getAttrMarkup(attrs)}><${tagName$n}>`,
44233
+ post: () => `</${tagName$n}></div>`
44102
44234
  };
44103
44235
  });
44104
44236
  var routerOutlet_build = () => { };
@@ -44237,7 +44369,7 @@ register('wm-page-content', () => {
44237
44369
  return {
44238
44370
  template: (node) => {
44239
44371
  for (let attr of node.attrs) {
44240
- if (attr.name === 'spa' && attr.value) {
44372
+ if (attr.name === 'spa' && attr.value === 'true') {
44241
44373
  const conditionalNode = createElement$2('ng-container');
44242
44374
  addAtrribute$2(conditionalNode, '*ngIf', 'compilePageContent');
44243
44375
  conditionalNode.children = conditionalNode.children.concat(node.children);
@@ -45057,8 +45189,8 @@ exports.transpile = transpile;
45057
45189
  exports.ɵ0 = ɵ0$h;
45058
45190
  exports.ɵ1 = ɵ1$5;
45059
45191
  exports.ɵ10 = ɵ10$1;
45060
- exports.ɵ11 = ɵ11;
45061
- exports.ɵ12 = ɵ12;
45192
+ exports.ɵ11 = ɵ11$1;
45193
+ exports.ɵ12 = ɵ12$1;
45062
45194
  exports.ɵ13 = ɵ13;
45063
45195
  exports.ɵ14 = ɵ14;
45064
45196
  exports.ɵ2 = ɵ2$4;