Skip to content

Commit 75a6bef

Browse files
committed
removed references to JSUtils and fixed preview editor events
1 parent 2a83acf commit 75a6bef

File tree

9 files changed

+63
-450
lines changed

9 files changed

+63
-450
lines changed

projects/core/src/lib/components/base-ui-component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { OnDestroy, HostBinding, SimpleChanges, OnChanges, Directive, Input, Output, EventEmitter } from '@angular/core';
22
import { AttributesMap, UIModel, ComponentEvent } from '../models';
3-
import { JSONUtils } from '../utils/json.utils';
43
import { kebabStrToCamel, queryValue, setValue } from '../utils';
54
import { StyleProperties, DataModelProperties, StylePropertiesList, BaseProperties } from '../properties';
65
import { InputProperties } from '../ui-components/input/input.component';

projects/core/src/lib/services/core.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ export class CoreService {
8787
if (res) {
8888
const type = Object.keys(res)[0];
8989
const xmlObj = res[type];
90+
if(typeof xmlObj === 'string')
91+
{
92+
throw Error(`Invalid XML, please make sure file can't start with comment <!-- -->`);
93+
}
9094
xmlObj['#name'] = type;
9195
return CoreService.getUIModel(toXMLResult(xmlObj));
9296
}
9397
} catch (e) {
94-
console.log(e);
98+
console.error(e);
9599
throw e;
96100
}
97101
}
@@ -126,7 +130,9 @@ export class CoreService {
126130
}
127131

128132
if (xmlRes.childNodes && !uiModel.children) {
129-
uiModel.children = xmlRes.childNodes.map((r: any) => CoreService.getUIModel(toXMLResult(r)));
133+
uiModel.children = xmlRes.childNodes
134+
.filter(n => n['#name'] !== '#comment')
135+
.map((r: any) => CoreService.getUIModel(toXMLResult(r)));
130136
}
131137
return uiModel;
132138
} else {

projects/core/src/lib/ui-components/select/select.component.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const example: ComponentExample<UIModel<SelectProperties>> = {
119119
<section class="flex-column">
120120
<section class="form-group">
121121
<label class="col-form-label" width="60px">Country</label>
122-
<select class="form-control" onSelect="countryChanged()" width="300px" binding="$.country">
122+
<select class="form-control" onSelect="countryChanged(selectedItem)" width="300px" binding="$.country">
123123
<option>Select country</option>
124124
<option value="uk">United Kingdom</option>
125125
<option value="ua">Ukraine</option>
@@ -137,14 +137,20 @@ export const example: ComponentExample<UIModel<SelectProperties>> = {
137137
138138
def countryChanged():
139139
dataModel.city = null
140-
if dataModel.country == null:
141-
dataModel.cities = []
142-
if dataModel.country == "uk":
143-
dataModel.cities = [{label: "Select city", value: null}, {label: "London", value: "lon"}, {label: "Liverpool", value: "liv"}]
144-
if dataModel.country == "ua":
145-
dataModel.cities = [{label: "Select city", value: null}, {label: "Kyiv", value: "kyiv"}, {label: "Lviv", value: "lviv"}]
146-
147-
print(dataModel)
140+
141+
if selectedItem?.value == "uk":
142+
dataModel.cities = [
143+
{label: "Select city", value: null},
144+
{label: "London", value: "lon"},
145+
{label: "Liverpool", value: "liv"}
146+
]
147+
148+
if selectedItem?.value == "ua":
149+
dataModel.cities = [
150+
{label: "Select city", value: null},
151+
{label: "Kyiv", value: "kyiv"},
152+
{label: "Lviv", value: "lviv"}
153+
]
148154
149155
`,
150156
title: 'Basic select example'

projects/core/src/lib/utils/index.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { BaseUIComponent } from '../components/base-ui-component';
22
import { BaseHTMLElement } from '../components/base-html-element';
33
import { BaseDynamicComponent } from '../components/base-dynamic-component';
44
import { UIModel } from '../models';
5-
import { JSONUtils } from './json.utils';
65

76
export * from './helpers';
87
export type BaseUIComponentConstructor = new () => BaseUIComponent;
@@ -36,10 +35,41 @@ export function getComponentById(uiModel: UIModel, id: string): BaseDynamicCompo
3635
return componentUIModel?.getComponent();
3736
}
3837

38+
/**
39+
* A helper method that sets value based on path.
40+
* e.g. setValue({}, 'obj.prop1.value', 22) will create a corresponding object and assign value = 22
41+
*/
3942
export function setValue(objectValue: object, path: string, value: any): void {
40-
JSONUtils.setValue(objectValue, path, value);
43+
if (!objectValue) {
44+
objectValue = {};
45+
}
46+
47+
if (path === '$' || path === '') {
48+
Object.assign(objectValue, value);
49+
return;
50+
}
51+
52+
if (path.startsWith('$.')) {
53+
path = path.substring(2);
54+
}
55+
56+
const props = path.indexOf('/') > 0 ? path.split('/') : path.split('.');
57+
let res: any = objectValue;
58+
59+
for (let i = 0; i < props.length - 1; i++) {
60+
res = objectValue[props[i]];
61+
if (typeof res !== 'object') {
62+
objectValue[props[i]] = {};
63+
res = objectValue[props[i]];
64+
}
65+
}
66+
67+
res[props[props.length - 1]] = value;
4168
}
4269

70+
/**
71+
* a helper methods that query JS Object for a value based on path. obj.subObject.value
72+
*/
4373
export function queryValue(obj: any, path: string, defaultValue: any = null): any {
4474
if (path === '$' || path === '') {
4575
return defaultValue;
@@ -49,7 +79,7 @@ export function queryValue(obj: any, path: string, defaultValue: any = null): an
4979
path = path.substring(2);
5080
}
5181

52-
const props = path.indexOf('/') > 0 ? path.split('/') : path.split('.')
82+
const props = path.indexOf('/') > 0 ? path.split('/') : path.split('.');
5383

5484
let res = obj;
5585
for (const p of props) {

projects/core/src/lib/utils/json.utils.spec.ts

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)