@genesislcap/expression-builder 14.260.3 → 14.261.0

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.
@@ -427,7 +427,7 @@
427
427
  {
428
428
  "kind": "variable",
429
429
  "name": "template",
430
- "default": "html<ExpressionBuilder>`\n <div class=\"query-builder\">\n <expression-group\n :model=${(x) => x.model}\n :config=${(x) => x.config}\n :styles=${(x) => x.styles}\n ></expression-group>\n </div>\n`"
430
+ "default": "html<ExpressionBuilder>`\n <div class=\"query-builder\">\n ${when(\n (x) => x.model !== null,\n html<ExpressionBuilder>`\n <expression-group\n :model=${(x) => x.model}\n :config=${(x) => x.config}\n :styles=${(x) => x.styles}\n ></expression-group>\n `,\n )}\n </div>\n`"
431
431
  }
432
432
  ],
433
433
  "exports": [
@@ -506,6 +506,29 @@
506
506
  }
507
507
  ]
508
508
  },
509
+ {
510
+ "kind": "method",
511
+ "name": "isValidConfig",
512
+ "privacy": "private",
513
+ "return": {
514
+ "type": {
515
+ "text": "boolean"
516
+ }
517
+ },
518
+ "parameters": [
519
+ {
520
+ "name": "config",
521
+ "type": {
522
+ "text": "Config"
523
+ }
524
+ }
525
+ ]
526
+ },
527
+ {
528
+ "kind": "method",
529
+ "name": "initBaseModel",
530
+ "privacy": "private"
531
+ },
509
532
  {
510
533
  "kind": "field",
511
534
  "name": "handleAddGroup",
@@ -681,6 +704,41 @@
681
704
  }
682
705
  ]
683
706
  },
707
+ {
708
+ "kind": "javascript-module",
709
+ "path": "src/types/index.ts",
710
+ "declarations": [],
711
+ "exports": [
712
+ {
713
+ "kind": "js",
714
+ "name": "*",
715
+ "declaration": {
716
+ "name": "*",
717
+ "package": "./public.types"
718
+ }
719
+ },
720
+ {
721
+ "kind": "js",
722
+ "name": "*",
723
+ "declaration": {
724
+ "name": "*",
725
+ "package": "./private.types"
726
+ }
727
+ }
728
+ ]
729
+ },
730
+ {
731
+ "kind": "javascript-module",
732
+ "path": "src/types/private.types.ts",
733
+ "declarations": [],
734
+ "exports": []
735
+ },
736
+ {
737
+ "kind": "javascript-module",
738
+ "path": "src/types/public.types.ts",
739
+ "declarations": [],
740
+ "exports": []
741
+ },
684
742
  {
685
743
  "kind": "javascript-module",
686
744
  "path": "src/utils/data-model.ts",
@@ -930,41 +988,6 @@
930
988
  }
931
989
  ]
932
990
  },
933
- {
934
- "kind": "javascript-module",
935
- "path": "src/types/index.ts",
936
- "declarations": [],
937
- "exports": [
938
- {
939
- "kind": "js",
940
- "name": "*",
941
- "declaration": {
942
- "name": "*",
943
- "package": "./public.types"
944
- }
945
- },
946
- {
947
- "kind": "js",
948
- "name": "*",
949
- "declaration": {
950
- "name": "*",
951
- "package": "./private.types"
952
- }
953
- }
954
- ]
955
- },
956
- {
957
- "kind": "javascript-module",
958
- "path": "src/types/private.types.ts",
959
- "declarations": [],
960
- "exports": []
961
- },
962
- {
963
- "kind": "javascript-module",
964
- "path": "src/types/public.types.ts",
965
- "declarations": [],
966
- "exports": []
967
- },
968
991
  {
969
992
  "kind": "javascript-module",
970
993
  "path": "src/main/expression-group/expression-group.styles.ts",
@@ -144,6 +144,8 @@ export declare class ExpressionBuilder extends GenesisElement implements Metadat
144
144
  connectedCallback(): void;
145
145
  /** @internal */
146
146
  disconnectedCallback(): void;
147
+ private isValidConfig;
148
+ private initBaseModel;
147
149
  private handleAddGroup;
148
150
  private _handleAddGroup;
149
151
  private handleAddRule;
@@ -1 +1 @@
1
- {"version":3,"file":"expression-builder.d.ts","sourceRoot":"","sources":["../../../src/main/expression-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAc,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAa,MAAM,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAqB,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AAkB7F;;;;;;;;;;;;;GAaG;AACH,qBAKa,iBAAkB,SAAQ,cAAe,YAAW,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AO,CAAC,gBAAgB,CAAqC;IAC7D,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,qBAAqB,CAA0C;IACvE,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,oBAAoB,CAAyC;IACrE,OAAO,CAAC,qBAAqB;CAI9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"expression-builder.template.d.ts","sourceRoot":"","sources":["../../../src/main/expression-builder.template.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAK9D,cAAc;AACd,eAAO,MAAM,QAAQ,wEAQpB,CAAC"}
1
+ {"version":3,"file":"expression-builder.template.d.ts","sourceRoot":"","sources":["../../../src/main/expression-builder.template.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAK9D,cAAc;AACd,eAAO,MAAM,QAAQ,wEAapB,CAAC"}
@@ -68,6 +68,9 @@ let ExpressionBuilder = class ExpressionBuilder extends GenesisElement {
68
68
  }
69
69
  /** @internal */
70
70
  configChanged(_, newConfig) {
71
+ if (!this.isValidConfig(newConfig)) {
72
+ throw new Error("Invalid config passed to ExpressionBuilder. Verify you've defined operators, fields, and combinators.");
73
+ }
71
74
  if (newConfig.model) {
72
75
  this.ruleCount = 0;
73
76
  this.groupCount = 0;
@@ -75,6 +78,9 @@ let ExpressionBuilder = class ExpressionBuilder extends GenesisElement {
75
78
  this.model = groupToModelGroup(newConfig.model, this);
76
79
  this.userUpdatingModel = false;
77
80
  }
81
+ else if (this.model === null) {
82
+ this.initBaseModel();
83
+ }
78
84
  }
79
85
  /** @internal */
80
86
  modelChanged(_, newModel) {
@@ -117,24 +123,26 @@ let ExpressionBuilder = class ExpressionBuilder extends GenesisElement {
117
123
  /** @internal */
118
124
  connectedCallback() {
119
125
  super.connectedCallback();
120
- if (!this.config || !this.config.combinators || !this.config.operators || !this.config.fields) {
121
- throw new Error("Invalid config passed to ExpressionBuilder. Verify you've defined operators, fields, and combinators.");
122
- }
123
126
  this.addEventListener(Events.AddGroup, this.handleAddGroup);
124
127
  this.addEventListener(Events.DelGroup, this.handleDeleteGroup);
125
128
  this.addEventListener(Events.AddRule, this.handleAddRule);
126
129
  this.addEventListener(Events.DelRule, this.handleDeleteRule);
127
130
  this.addEventListener(Events.UpdateGroup, this.handleUpdateGroupData);
128
131
  this.addEventListener(Events.UpdateRule, this.handleUpdateRuleData);
132
+ // When using other frameworks such as React we cannot guarantee that it sets the property on the component
133
+ // by the time connectedCallback is called, so we need to allow for lazy setting of the config
134
+ if (!this.isValidConfig(this.config)) {
135
+ if (this.config) {
136
+ console.warn("Config detected during connectedCallback but it isn't valid");
137
+ }
138
+ this.config = null;
139
+ return;
140
+ }
141
+ // If the property contains a model then let that be used, via configChanged
129
142
  if (this.config.model)
130
143
  return;
131
- this.model = {
132
- children: [],
133
- level: 1,
134
- groupId: ROOT_GROUP,
135
- config: this.config,
136
- combinator: this.config.combinators[0],
137
- };
144
+ // Else, set a blank model
145
+ this.initBaseModel();
138
146
  }
139
147
  /** @internal */
140
148
  disconnectedCallback() {
@@ -146,6 +154,22 @@ let ExpressionBuilder = class ExpressionBuilder extends GenesisElement {
146
154
  this.removeEventListener(Events.UpdateGroup, this.handleUpdateGroupData);
147
155
  this.removeEventListener(Events.UpdateRule, this.handleUpdateRuleData);
148
156
  }
157
+ isValidConfig(config) {
158
+ var _a, _b, _c;
159
+ return Boolean(config && ((_a = config.combinators) === null || _a === void 0 ? void 0 : _a.length) && ((_b = config.operators) === null || _b === void 0 ? void 0 : _b.length) && ((_c = config.fields) === null || _c === void 0 ? void 0 : _c.length));
160
+ }
161
+ initBaseModel() {
162
+ if (!this.isValidConfig(this.config)) {
163
+ throw new Error("Invalid config set on ExpressionBuilder. Verify you've defined operators, fields, and combinators.");
164
+ }
165
+ this.model = {
166
+ children: [],
167
+ level: 1,
168
+ groupId: ROOT_GROUP,
169
+ config: this.config,
170
+ combinator: this.config.combinators[0],
171
+ };
172
+ }
149
173
  _handleAddGroup(event) {
150
174
  const { parentGroupId, newGroup: _newGroup } = event.detail;
151
175
  const newGroup = {
@@ -1,13 +1,15 @@
1
- import { html } from '@genesislcap/web-core';
1
+ import { html, when } from '@genesislcap/web-core';
2
2
  import { ExpressionGroup } from './expression-group/expression-group';
3
3
  ExpressionGroup;
4
4
  /** @alpha **/
5
5
  export const template = html `
6
6
  <div class="query-builder">
7
- <expression-group
8
- :model=${(x) => x.model}
9
- :config=${(x) => x.config}
10
- :styles=${(x) => x.styles}
11
- ></expression-group>
7
+ ${when((x) => x.model !== null, html `
8
+ <expression-group
9
+ :model=${(x) => x.model}
10
+ :config=${(x) => x.config}
11
+ :styles=${(x) => x.styles}
12
+ ></expression-group>
13
+ `)}
12
14
  </div>
13
15
  `;
@@ -333,6 +333,8 @@ export declare class ExpressionBuilder extends GenesisElement implements Metadat
333
333
  connectedCallback(): void;
334
334
  /** @internal */
335
335
  disconnectedCallback(): void;
336
+ private isValidConfig;
337
+ private initBaseModel;
336
338
  private handleAddGroup;
337
339
  private _handleAddGroup;
338
340
  private handleAddRule;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/expression-builder",
3
3
  "description": "Genesis Foundation Expression Builder",
4
- "version": "14.260.3",
4
+ "version": "14.261.0",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/expression-builder.d.ts",
@@ -59,5 +59,5 @@
59
59
  "access": "public"
60
60
  },
61
61
  "customElements": "dist/custom-elements.json",
62
- "gitHead": "8c2edfa09d71c8b6c5487873d1751da090c62480"
62
+ "gitHead": "0f53a72fa79fcfc3ffb9a4b741815aaaad1a8980"
63
63
  }