@cntwg/xml-lib-js 0.0.16 → 0.0.17
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.
- package/CHANGELOG.md +7 -0
- package/lib/xmldoc-lib.js +58 -63
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
#### *v0.0.17*
|
|
2
|
+
|
|
3
|
+
Pre-release version.
|
|
4
|
+
|
|
5
|
+
> fixed error in `TXmlContentRootElement` class constructor that caused failure on `TXmlContentContainer` class initiation with `options => autoBindRoot = "false"`;
|
|
6
|
+
> - some fixes in `xmldoc-lib.js` module.
|
|
7
|
+
|
|
1
8
|
#### *v0.0.16*
|
|
2
9
|
|
|
3
10
|
Pre-release version.
|
package/lib/xmldoc-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.047-20220907]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -146,7 +146,7 @@ class TXmlAttributesMapper {
|
|
|
146
146
|
class TXmlElementController {
|
|
147
147
|
#_host = null;
|
|
148
148
|
#_options = null;
|
|
149
|
-
#
|
|
149
|
+
#_parseOptions = null;
|
|
150
150
|
#_attributes = null;
|
|
151
151
|
#_name = null;
|
|
152
152
|
|
|
@@ -162,24 +162,24 @@ class TXmlElementController {
|
|
|
162
162
|
this.#_host = obj;
|
|
163
163
|
} else {
|
|
164
164
|
if (proxyModeEnable) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
throw new TypeError(msg);
|
|
165
|
+
throw new TypeError(
|
|
166
|
+
`TXmlElementController in "proxyMode": ${XML_TE_NOBJ_EMSG}`
|
|
167
|
+
);
|
|
169
168
|
};
|
|
170
169
|
this.#_host = {};
|
|
171
170
|
};
|
|
172
171
|
// set parser options
|
|
173
172
|
let { parseOptions: _parseOptions } = _options;
|
|
174
|
-
if (!isPlainObject(_parseOptions))
|
|
173
|
+
if (!isPlainObject(_parseOptions)) {
|
|
174
|
+
_options.parseOptions = _parseOptions = {};
|
|
175
|
+
};
|
|
175
176
|
let { settings: _settings } = _parseOptions;
|
|
176
177
|
if (!isPlainObject(_settings)) {
|
|
177
178
|
_parseOptions.settings = _settings = {};
|
|
178
179
|
// // TODO: set defaults
|
|
179
180
|
};
|
|
180
181
|
// save parser options
|
|
181
|
-
|
|
182
|
-
this.#_p_opts = _parseOptions;
|
|
182
|
+
this.#_parseOptions = _parseOptions;
|
|
183
183
|
// save options
|
|
184
184
|
_options.proxyModeEnable = proxyModeEnable;
|
|
185
185
|
this.#_options = _options;
|
|
@@ -193,8 +193,11 @@ class TXmlElementController {
|
|
|
193
193
|
|
|
194
194
|
get name(){
|
|
195
195
|
let result = '';
|
|
196
|
-
if (this.#
|
|
197
|
-
result = xObj.readXObjParam(
|
|
196
|
+
if (this.#_parseOptions.settings.compact) {
|
|
197
|
+
result = xObj.readXObjParam(
|
|
198
|
+
this.#_host,
|
|
199
|
+
this.#_parseOptions.settings.nameKey
|
|
200
|
+
);
|
|
198
201
|
} else {
|
|
199
202
|
// TODO: read name of element in non-compact mode
|
|
200
203
|
};
|
|
@@ -202,11 +205,11 @@ class TXmlElementController {
|
|
|
202
205
|
}
|
|
203
206
|
|
|
204
207
|
get textValue(){
|
|
205
|
-
return xObj.readXObjParam(this.#_host, this.#
|
|
208
|
+
return xObj.readXObjParam(this.#_host, this.#_parseOptions.settings.textKey);
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
set textValue(value){
|
|
209
|
-
xObj.writeXObjParam(this.#_host, value, this.#
|
|
212
|
+
xObj.writeXObjParam(this.#_host, value, this.#_parseOptions.settings.textKey);
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
hasAttribute(name){
|
|
@@ -239,13 +242,13 @@ class TXmlElementController {
|
|
|
239
242
|
return xObj.writeXObjParam(
|
|
240
243
|
this.#_host,
|
|
241
244
|
value[0],
|
|
242
|
-
this.#
|
|
245
|
+
this.#_parseOptions.settings.textKey,
|
|
243
246
|
);
|
|
244
247
|
} else if (val_size > 1) {
|
|
245
248
|
if (xObj.writeXObjParam(
|
|
246
249
|
this.#_host,
|
|
247
250
|
value[1],
|
|
248
|
-
this.#
|
|
251
|
+
this.#_parseOptions.settings.textKey,
|
|
249
252
|
)) {
|
|
250
253
|
return this.#_attributes.setAttribute(XML_LANG_ATTR_TNAME, value[0]);
|
|
251
254
|
};
|
|
@@ -321,9 +324,12 @@ class TXmlElementController {
|
|
|
321
324
|
) {
|
|
322
325
|
return null;
|
|
323
326
|
};
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
const result = xObj.addXObjElement(this.#_host, name);
|
|
328
|
+
return (
|
|
329
|
+
result.isSucceed
|
|
330
|
+
? new TXmlElementController(result.item, this.#_options)
|
|
331
|
+
: null
|
|
332
|
+
);
|
|
327
333
|
}
|
|
328
334
|
|
|
329
335
|
delChild(value){
|
|
@@ -389,10 +395,9 @@ class TXmlElementsListController {
|
|
|
389
395
|
this.#_host = obj;
|
|
390
396
|
} else {
|
|
391
397
|
if (proxyModeEnable) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
throw new TypeError(msg);
|
|
398
|
+
throw new TypeError(
|
|
399
|
+
`TXmlElementsListController in "proxyMode": ${XML_TE_NARR_EMSG}`
|
|
400
|
+
);
|
|
396
401
|
} else {
|
|
397
402
|
// // TODO: split a plain object and class instances
|
|
398
403
|
this.#_host = [];
|
|
@@ -441,7 +446,8 @@ class TXmlElementsListController {
|
|
|
441
446
|
|
|
442
447
|
isValidItem(obj){
|
|
443
448
|
return (
|
|
444
|
-
(this.#_options.isNullItemsAllowed && obj === null)
|
|
449
|
+
(this.#_options.isNullItemsAllowed && obj === null)
|
|
450
|
+
|| isPlainObject(obj)
|
|
445
451
|
);
|
|
446
452
|
}
|
|
447
453
|
|
|
@@ -559,9 +565,6 @@ class TXmlContentDeclaration {
|
|
|
559
565
|
constructor(obj, opt){
|
|
560
566
|
// check <obj>-param
|
|
561
567
|
if (!isPlainObject(obj)) {
|
|
562
|
-
/*let msg = [
|
|
563
|
-
'TXmlContentDeclaration :', XML_TE_NOBJ_EMSG,
|
|
564
|
-
].join(' ');*/
|
|
565
568
|
throw new TypeError(`TXmlContentDeclaration : ${XML_TE_NOBJ_EMSG}`);
|
|
566
569
|
};
|
|
567
570
|
// load options
|
|
@@ -651,7 +654,7 @@ class TXmlContentRootElement extends TXmlElementController {
|
|
|
651
654
|
const len = entries.length;
|
|
652
655
|
if (len === 0) {
|
|
653
656
|
rootItem = xObj.insertXObjElement(obj, rootETagName, false);
|
|
654
|
-
} else
|
|
657
|
+
} else {
|
|
655
658
|
const {
|
|
656
659
|
declarationKey,
|
|
657
660
|
attributesKey,
|
|
@@ -684,14 +687,16 @@ class TXmlContentRootElement extends TXmlElementController {
|
|
|
684
687
|
if (targetKey === '') {
|
|
685
688
|
rootItem = xObj.insertXObjElement(obj, rootETagName, false);
|
|
686
689
|
} else {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
690
|
+
if (autoBindRoot) {
|
|
691
|
+
rootItem = obj[targetKey];
|
|
692
|
+
rootETagName = targetKey;
|
|
693
|
+
if (!isPlainObject(rootItem)) {
|
|
694
|
+
rootItem = xObj.insertXObjElement(obj, rootETagName, false);
|
|
695
|
+
};
|
|
696
|
+
} else {
|
|
697
|
+
throw new TypeError(`TXmlContentRootElement : ${XML_TE_NROOT_EMSG}`);
|
|
691
698
|
};
|
|
692
699
|
};
|
|
693
|
-
} else {
|
|
694
|
-
throw new TypeError(`TXmlContentRootElement : ${XML_TE_NROOT_EMSG}`);
|
|
695
700
|
};
|
|
696
701
|
} else if (!isPlainObject(rootItem)) {
|
|
697
702
|
rootItem = xObj.insertXObjElement(obj, rootETagName, false);
|
|
@@ -782,40 +787,30 @@ class TXmlContentContainer {
|
|
|
782
787
|
}
|
|
783
788
|
|
|
784
789
|
_bindContent(obj, opt){
|
|
785
|
-
//console.log('CHECK: TXmlContentContainer._bindContent() => was called...');
|
|
786
790
|
const _options = isPlainObject(opt) ? opt : this.#_options;
|
|
787
791
|
let isSUCCEED = false;
|
|
788
792
|
if (isPlainObject(obj)) {
|
|
789
|
-
let {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
//
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
this.#_content = obj;
|
|
810
|
-
// bind refs to controllers
|
|
811
|
-
this.#_docDecl = _docDecl;
|
|
812
|
-
this.#_docRoot = _docRoot;
|
|
813
|
-
};
|
|
814
|
-
//};
|
|
793
|
+
let { parseOptions } = _options;
|
|
794
|
+
if (!(parseOptions instanceof TXmlContentParseOptions)) {
|
|
795
|
+
parseOptions = new TXmlContentParseOptions(parseOptions);
|
|
796
|
+
_options.parseOptions = parseOptions;
|
|
797
|
+
};
|
|
798
|
+
const _docDecl = new TXmlContentDeclaration(obj, _options);
|
|
799
|
+
const _docRoot = new TXmlContentRootElement(obj, _options);
|
|
800
|
+
// // TODO: check elements
|
|
801
|
+
isSUCCEED = true;
|
|
802
|
+
if (isSUCCEED) {
|
|
803
|
+
// save options
|
|
804
|
+
this.#_options = _options;
|
|
805
|
+
// save parser options
|
|
806
|
+
this.#_parseOptions = parseOptions;
|
|
807
|
+
// save content
|
|
808
|
+
this.#_content = obj;
|
|
809
|
+
// bind refs to controllers
|
|
810
|
+
this.#_docDecl = _docDecl;
|
|
811
|
+
this.#_docRoot = _docRoot;
|
|
812
|
+
};
|
|
815
813
|
};
|
|
816
|
-
//console.log('CHECK: TXmlContentContainer.constructor() => _content => '+JSON.stringify(this.#_content, null, 2));
|
|
817
|
-
//console.log('CHECK: TXmlContentContainer._bindContent() => result:['+isSUCCEED+']');
|
|
818
|
-
//console.log('CHECK: TXmlContentContainer._bindContent() => was left...');
|
|
819
814
|
return isSUCCEED;
|
|
820
815
|
}
|
|
821
816
|
|