@logicflow/extension 2.2.0-alpha.7 → 2.2.1

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.
Files changed (125) hide show
  1. package/README.md +16 -0
  2. package/package.json +10 -7
  3. package/.turbo/turbo-build.log +0 -38
  4. package/CHANGELOG.md +0 -1829
  5. package/__test__/bpmn-adapter.test.js +0 -227
  6. package/es/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
  7. package/es/materials/curved-edge/__test__/curved-edge.test.js +0 -18
  8. package/jest.config.js +0 -198
  9. package/lib/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
  10. package/lib/materials/curved-edge/__test__/curved-edge.test.js +0 -20
  11. package/rollup.config.js +0 -52
  12. package/src/NodeResize/BasicShape/Ellipse.tsx +0 -22
  13. package/src/NodeResize/BasicShape/Polygon.tsx +0 -24
  14. package/src/NodeResize/BasicShape/Rect.tsx +0 -44
  15. package/src/NodeResize/control/Control.tsx +0 -537
  16. package/src/NodeResize/control/ControlGroup.tsx +0 -76
  17. package/src/NodeResize/control/Util.ts +0 -206
  18. package/src/NodeResize/index.ts +0 -26
  19. package/src/NodeResize/node/DiamondResize.tsx +0 -149
  20. package/src/NodeResize/node/EllipseResize.tsx +0 -140
  21. package/src/NodeResize/node/HtmlResize.tsx +0 -125
  22. package/src/NodeResize/node/RectResize.tsx +0 -126
  23. package/src/NodeResize/node/index.ts +0 -4
  24. package/src/bpmn/constant.ts +0 -56
  25. package/src/bpmn/events/EndEvent.ts +0 -73
  26. package/src/bpmn/events/StartEvent.ts +0 -52
  27. package/src/bpmn/events/index.ts +0 -2
  28. package/src/bpmn/flow/SequenceFlow.ts +0 -25
  29. package/src/bpmn/flow/index.ts +0 -1
  30. package/src/bpmn/gateways/ExclusiveGateway.ts +0 -71
  31. package/src/bpmn/gateways/index.ts +0 -1
  32. package/src/bpmn/getBpmnId.ts +0 -31
  33. package/src/bpmn/index.ts +0 -60
  34. package/src/bpmn/tasks/ServiceTask.ts +0 -63
  35. package/src/bpmn/tasks/UserTask.ts +0 -64
  36. package/src/bpmn/tasks/index.ts +0 -2
  37. package/src/bpmn-adapter/bpmnIds.ts +0 -31
  38. package/src/bpmn-adapter/index.ts +0 -835
  39. package/src/bpmn-adapter/json2xml.ts +0 -127
  40. package/src/bpmn-adapter/xml2json.ts +0 -544
  41. package/src/bpmn-elements/README.md +0 -223
  42. package/src/bpmn-elements/__tests__/definition.test.js +0 -72
  43. package/src/bpmn-elements/index.d.ts +0 -26
  44. package/src/bpmn-elements/index.ts +0 -107
  45. package/src/bpmn-elements/presets/Event/EndEventFactory.ts +0 -114
  46. package/src/bpmn-elements/presets/Event/IntermediateCatchEvent.ts +0 -108
  47. package/src/bpmn-elements/presets/Event/IntermediateThrowEvent.ts +0 -109
  48. package/src/bpmn-elements/presets/Event/StartEventFactory.ts +0 -114
  49. package/src/bpmn-elements/presets/Event/boundaryEventFactory.ts +0 -117
  50. package/src/bpmn-elements/presets/Event/index.ts +0 -14
  51. package/src/bpmn-elements/presets/Flow/flow.d.ts +0 -6
  52. package/src/bpmn-elements/presets/Flow/index.ts +0 -8
  53. package/src/bpmn-elements/presets/Flow/manhattan.ts +0 -691
  54. package/src/bpmn-elements/presets/Flow/sequenceFlow.ts +0 -65
  55. package/src/bpmn-elements/presets/Gateway/gateway.ts +0 -107
  56. package/src/bpmn-elements/presets/Gateway/index.ts +0 -23
  57. package/src/bpmn-elements/presets/Pool/Lane.ts +0 -211
  58. package/src/bpmn-elements/presets/Pool/Pool.ts +0 -284
  59. package/src/bpmn-elements/presets/Pool/index.ts +0 -89
  60. package/src/bpmn-elements/presets/Task/index.ts +0 -122
  61. package/src/bpmn-elements/presets/Task/subProcess.ts +0 -189
  62. package/src/bpmn-elements/presets/Task/task.ts +0 -193
  63. package/src/bpmn-elements/presets/icons.ts +0 -155
  64. package/src/bpmn-elements/utils.ts +0 -52
  65. package/src/bpmn-elements-adapter/README.md +0 -293
  66. package/src/bpmn-elements-adapter/__tests__/adapter_in.test.js +0 -528
  67. package/src/bpmn-elements-adapter/__tests__/adapter_out.test.js +0 -569
  68. package/src/bpmn-elements-adapter/constant.ts +0 -76
  69. package/src/bpmn-elements-adapter/index.ts +0 -1134
  70. package/src/bpmn-elements-adapter/json2xml.ts +0 -105
  71. package/src/bpmn-elements-adapter/xml2json.ts +0 -542
  72. package/src/components/context-menu/index.ts +0 -253
  73. package/src/components/control/index.ts +0 -155
  74. package/src/components/dnd-panel/index.ts +0 -137
  75. package/src/components/highlight/index.ts +0 -227
  76. package/src/components/menu/index.ts +0 -748
  77. package/src/components/mini-map/index.ts +0 -686
  78. package/src/components/selection-select/index.ts +0 -387
  79. package/src/dynamic-group/index.ts +0 -774
  80. package/src/dynamic-group/model.ts +0 -580
  81. package/src/dynamic-group/node.ts +0 -288
  82. package/src/dynamic-group/utils.ts +0 -46
  83. package/src/index.less +0 -1
  84. package/src/index.ts +0 -47
  85. package/src/insert-node-in-polyline/edge.ts +0 -175
  86. package/src/insert-node-in-polyline/index.ts +0 -193
  87. package/src/materials/curved-edge/__test__/curved-edge.test.ts +0 -46
  88. package/src/materials/curved-edge/index.ts +0 -217
  89. package/src/materials/group/GroupNode.ts +0 -437
  90. package/src/materials/group/index.ts +0 -542
  91. package/src/materials/node-selection/index.ts +0 -380
  92. package/src/mindmap/fakerRoot.ts +0 -19
  93. package/src/mindmap/index.ts +0 -328
  94. package/src/mindmap/markContent.ts +0 -81
  95. package/src/mindmap/markContentOption.ts +0 -81
  96. package/src/mindmap/markEntity.ts +0 -82
  97. package/src/mindmap/markRoot.ts +0 -83
  98. package/src/mindmap/theme.ts +0 -11
  99. package/src/pool/LaneModel.ts +0 -226
  100. package/src/pool/LaneView.ts +0 -220
  101. package/src/pool/PoolModel.ts +0 -631
  102. package/src/pool/PoolView.ts +0 -75
  103. package/src/pool/constant.ts +0 -19
  104. package/src/pool/index.ts +0 -621
  105. package/src/pool/utils.ts +0 -46
  106. package/src/rect-label-node/RectLabelNodeView.ts +0 -33
  107. package/src/rect-label-node/index.ts +0 -15
  108. package/src/style/index.less +0 -381
  109. package/src/style/raw.ts +0 -328
  110. package/src/tools/auto-layout/index.ts +0 -282
  111. package/src/tools/flow-path/index.ts +0 -233
  112. package/src/tools/label/Label.tsx +0 -357
  113. package/src/tools/label/LabelModel.ts +0 -83
  114. package/src/tools/label/LabelOverlay.tsx +0 -162
  115. package/src/tools/label/algorithm.ts +0 -42
  116. package/src/tools/label/index.ts +0 -479
  117. package/src/tools/label/mediumEditor.ts +0 -121
  118. package/src/tools/label/utils.ts +0 -395
  119. package/src/tools/proximity-connect/index.ts +0 -435
  120. package/src/tools/snapshot/README.md +0 -145
  121. package/src/tools/snapshot/index.ts +0 -701
  122. package/src/tools/snapshot/utils.ts +0 -163
  123. package/src/turbo-adapter/index.ts +0 -212
  124. package/stats.html +0 -4842
  125. package/tsconfig.json +0 -18
@@ -1,105 +0,0 @@
1
- /* eslint-disable guard-for-in */
2
- function type(obj: any) {
3
- return Object.prototype.toString.call(obj)
4
- }
5
-
6
- function addSpace(depth: number) {
7
- return ' '.repeat(depth)
8
- }
9
-
10
- function handleAttributes(obj: any): any {
11
- if (type(obj) === '[object Object]') {
12
- return Object.keys(obj).reduce((tmp: any, key: string) => {
13
- let tmpKey = key
14
- if (key.charAt(0) === '-') {
15
- tmpKey = key.substring(1)
16
- }
17
- tmp[tmpKey] = handleAttributes(obj[key])
18
- return tmp
19
- }, {})
20
- }
21
- if (Array.isArray(obj)) {
22
- return obj.map((item) => handleAttributes(item))
23
- }
24
- return obj
25
- }
26
-
27
- function escapeXml(text: string) {
28
- if (text == null) return ''
29
- return text
30
- .toString()
31
- .replace(/&/g, '&')
32
- .replace(/</g, '&lt;')
33
- .replace(/>/g, '&gt;')
34
- .replace(/"/g, '&quot;')
35
- .replace(/'/g, '&apos;')
36
- }
37
-
38
- function getAttributes(obj: any) {
39
- let tmp = obj
40
- try {
41
- if (typeof tmp !== 'string') {
42
- tmp = JSON.parse(obj)
43
- }
44
- } catch (error) {
45
- tmp = JSON.stringify(handleAttributes(obj)).replace(/"/g, "'")
46
- }
47
- return escapeXml(String(tmp))
48
- }
49
-
50
- const tn = '\t\n'
51
-
52
- // @see issue https://github.com/didi/LogicFlow/issues/718, refactoring of function toXml
53
- function toXml(obj: any, name: string, depth: number) {
54
- const frontSpace = addSpace(depth)
55
- let str = ''
56
- const prefix = tn + frontSpace
57
- if (name === '-json') return ''
58
- if (obj !== 0 && obj !== false && !obj) {
59
- return `${prefix}<${name} />`
60
- }
61
- if (name === '#text') {
62
- return prefix + escapeXml(String(obj))
63
- }
64
- if (name === '#cdata-section') {
65
- return `${prefix}<![CDATA[${obj}]]>`
66
- }
67
- if (name === '#comment') {
68
- return `${prefix}<!--${obj}-->`
69
- }
70
- if (`${name}`.charAt(0) === '-') {
71
- return ` ${name.substring(1)}="${getAttributes(obj)}"`
72
- }
73
- if (Array.isArray(obj)) {
74
- str += obj.map((item) => toXml(item, name, depth + 1)).join('')
75
- } else if (type(obj) === '[object Object]') {
76
- const keys = Object.keys(obj)
77
- let attributes = ''
78
- let children = obj['-json'] ? tn + addSpace(depth + 1) + obj['-json'] : ''
79
-
80
- str += `${depth === 0 ? '' : prefix}<${name}`
81
-
82
- keys.forEach((k) => {
83
- k.charAt(0) === '-'
84
- ? (attributes += toXml(obj[k], k, depth + 1))
85
- : (children += toXml(obj[k], k, depth + 1))
86
- })
87
-
88
- str +=
89
- attributes + (children !== '' ? `>${children}${prefix}</${name}>` : ' />')
90
- } else {
91
- str += `${prefix}<${name}>${escapeXml(String(obj))}</${name}>`
92
- }
93
-
94
- return str
95
- }
96
-
97
- function lfJson2Xml(obj: any) {
98
- let xmlStr = ''
99
- for (const key in obj) {
100
- xmlStr += toXml(obj[key], key, 0)
101
- }
102
- return xmlStr
103
- }
104
-
105
- export { lfJson2Xml, handleAttributes, escapeXml }
@@ -1,542 +0,0 @@
1
- /* eslint-disable no-continue */
2
- /* eslint-disable @typescript-eslint/no-this-alias */
3
- /* eslint-disable @typescript-eslint/naming-convention */
4
- /* eslint-disable guard-for-in */
5
- /* eslint-disable func-names */
6
- // @ts-nocheck
7
-
8
- import { has } from 'lodash-es'
9
- import { escapeXml } from './json2xml'
10
- // ========================================================================
11
- // XML.ObjTree -- XML source code from/to JavaScript object like E4X
12
- // ========================================================================
13
-
14
- const XML = function () {}
15
-
16
- // constructor
17
- XML.ObjTree = function () {
18
- // @ts-ignore
19
- return this
20
- }
21
-
22
- // class variables
23
-
24
- XML.ObjTree.VERSION = '0.23'
25
-
26
- // object prototype
27
-
28
- XML.ObjTree.prototype.xmlDecl = '<?xml version="1.0" encoding="UTF-8" ?>\n'
29
- XML.ObjTree.prototype.attr_prefix = '-'
30
-
31
- // method: parseXML( xmlsource )
32
-
33
- XML.ObjTree.prototype.parseXML = function (xml) {
34
- let root
35
- if (window.DOMParser) {
36
- const xmldom = new DOMParser()
37
- // xmldom.async = false; // DOMParser is always sync-mode
38
- const dom = xmldom.parseFromString(xml, 'application/xml')
39
- if (!dom) return
40
- root = dom.documentElement
41
- } else if (window.ActiveXObject) {
42
- xmldom = new ActiveXObject('Microsoft.XMLDOM')
43
- xmldom.async = false
44
- xmldom.loadXML(xml)
45
- root = xmldom.documentElement
46
- }
47
- if (!root) return
48
- const data = this.parseDOM(root)
49
- return data
50
- }
51
-
52
- // method: parseHTTP( url, options, callback )
53
-
54
- XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
55
- const myOpt = {}
56
- for (const key in options) {
57
- myOpt[key] = options[key] // copy object
58
- }
59
- if (!myOpt.method) {
60
- if (
61
- typeof myOpt.postBody === 'undefined' &&
62
- typeof myOpt.postbody === 'undefined' &&
63
- typeof myOpt.parameters === 'undefined'
64
- ) {
65
- myOpt.method = 'get'
66
- } else {
67
- myOpt.method = 'post'
68
- }
69
- }
70
- if (callback) {
71
- myOpt.asynchronous = true // async-mode
72
- const __this = this
73
- const __func = callback
74
- const __save = myOpt.onComplete
75
- myOpt.onComplete = function (trans) {
76
- let tree
77
- if (trans && trans.responseXML && trans.responseXML.documentElement) {
78
- tree = __this.parseDOM(trans.responseXML.documentElement)
79
- }
80
- __func(tree, trans)
81
- if (__save) __save(trans)
82
- }
83
- } else {
84
- myOpt.asynchronous = false // sync-mode
85
- }
86
- let trans
87
- if (typeof HTTP !== 'undefined' && HTTP.Request) {
88
- myOpt.uri = url
89
- const req = new HTTP.Request(myOpt)
90
- if (req) trans = req.transport
91
- } else if (typeof Ajax !== 'undefined' && Ajax.Request) {
92
- const req = new Ajax.Request(url, myOpt)
93
- if (req) trans = req.transport
94
- }
95
- if (callback) return trans
96
- if (trans && trans.responseXML && trans.responseXML.documentElement) {
97
- return this.parseDOM(trans.responseXML.documentElement)
98
- }
99
- }
100
-
101
- XML.ObjTree.prototype.parseDOM = function (root) {
102
- if (!root) return
103
-
104
- this.__force_array = {}
105
- if (this.force_array) {
106
- for (let i = 0; i < this.force_array.length; i++) {
107
- this.__force_array[this.force_array[i]] = 1
108
- }
109
- }
110
-
111
- let json = this.parseElement(root) // parse root node
112
- if (this.__force_array[root.nodeName]) {
113
- json = [json]
114
- }
115
- if (root.nodeType !== 11) {
116
- // DOCUMENT_FRAGMENT_NODE
117
- const tmp = {}
118
- tmp[root.nodeName] = json // root nodeName
119
- json = tmp
120
- }
121
- return json
122
- }
123
-
124
- // method: parseElement( element )
125
- /**
126
- * @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
127
- */
128
- XML.ObjTree.prototype.parseElement = function (elem) {
129
- // PROCESSING_INSTRUCTION_NODE
130
- if (elem.nodeType === 7) {
131
- return
132
- }
133
-
134
- // TEXT_NODE CDATA_SECTION_NODE COMMENT_NODE
135
- if (elem.nodeType === 3 || elem.nodeType === 4 || elem.nodeType === 8) {
136
- // eslint-disable-next-line no-control-regex
137
- const bool = elem.nodeValue.match(/[^\x00-\x20]/)
138
- if (bool == null) return // ignore white spaces
139
- return elem.nodeValue
140
- }
141
-
142
- let retVal = null
143
- const cnt = {}
144
-
145
- if (elem.attributes && elem.attributes.length) {
146
- retVal = {}
147
- for (let i = 0; i < elem.attributes.length; i++) {
148
- let key = elem.attributes[i].nodeName
149
- if (typeof key !== 'string') continue
150
- let val = elem.attributes[i].nodeValue
151
- try {
152
- val = JSON.parse(elem.attributes[i].nodeValue.replace(/'/g, '"'))
153
- } catch (error) {
154
- val = elem.attributes[i].nodeValue
155
- }
156
- if (val === null || val === undefined) continue
157
- key = this.attr_prefix + key
158
- if (typeof cnt[key] === 'undefined') cnt[key] = 0
159
- cnt[key]++
160
- this.addNode(retVal, key, cnt[key], val)
161
- }
162
- }
163
-
164
- // parse child nodes (recursive)
165
- if (elem.childNodes && elem.childNodes.length) {
166
- let textOnly = true
167
- if (retVal) textOnly = false // some attributes exists
168
- for (let i = 0; i < elem.childNodes.length && textOnly; i++) {
169
- const nType = elem.childNodes[i].nodeType
170
- if (nType === 3 || nType === 4 || nType === 8) continue
171
- textOnly = false
172
- }
173
- if (textOnly) {
174
- if (!retVal) retVal = ''
175
- for (let i = 0; i < elem.childNodes.length; i++) {
176
- retVal += elem.childNodes[i].nodeValue
177
- }
178
- } else {
179
- if (!retVal) retVal = {}
180
- for (let i = 0; i < elem.childNodes.length; i++) {
181
- const key = elem.childNodes[i].nodeName
182
- if (typeof key !== 'string') continue
183
- const val = this.parseElement(elem.childNodes[i])
184
- if (!val) continue
185
- if (typeof cnt[key] === 'undefined') cnt[key] = 0
186
- cnt[key]++
187
- this.addNode(retVal, key, cnt[key], val)
188
- }
189
- }
190
- } else {
191
- // @see issue https://github.com/didi/LogicFlow/issues/1068
192
- // if retVal is null, that means the elem doesn't have any attributes and children,
193
- // the elem would be like: <a /> or <a></a>, so set retVal to empty object {}
194
- retVal === null && (retVal = {})
195
- }
196
- return retVal
197
- }
198
-
199
- // method: addNode( hash, key, count, value )
200
-
201
- XML.ObjTree.prototype.addNode = function (hash, key, counts, val) {
202
- if (this.__force_array[key]) {
203
- if (counts === 1) hash[key] = []
204
- hash[key][hash[key].length] = val // push
205
- } else if (counts === 1) {
206
- // 1st sibling
207
- hash[key] = val
208
- } else if (counts === 2) {
209
- // 2nd sibling
210
- hash[key] = [hash[key], val]
211
- } else {
212
- // 3rd sibling and more
213
- hash[key][hash[key].length] = val
214
- }
215
- }
216
-
217
- // method: writeXML( tree )
218
-
219
- XML.ObjTree.prototype.writeXML = function (tree) {
220
- const xml = this.hash_to_xml(null, tree)
221
- return this.xmlDecl + xml
222
- }
223
-
224
- // method: hash_to_xml( tagName, tree )
225
-
226
- XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
227
- const elem = []
228
- const attr = []
229
- for (const key in tree) {
230
- if (!has(tree, key)) continue
231
- const val = tree[key]
232
- if (key.charAt(0) !== this.attr_prefix) {
233
- if (typeof val === 'undefined' || val == null) {
234
- elem[elem.length] = `<${key} />`
235
- } else if (typeof val === 'object' && val.constructor === Array) {
236
- elem[elem.length] = this.array_to_xml(key, val)
237
- } else if (typeof val === 'object') {
238
- elem[elem.length] = this.hash_to_xml(key, val)
239
- } else {
240
- elem[elem.length] = this.scalar_to_xml(key, val)
241
- }
242
- } else {
243
- attr[attr.length] = ` ${key.substring(1)}="${this.xml_escape(val)}"`
244
- }
245
- }
246
- const jattr = attr.join('')
247
- let jelem = elem.join('')
248
- if (typeof name === 'undefined' || name == null) {
249
- // no tag
250
- } else if (elem.length > 0) {
251
- if (jelem.match(/\n/)) {
252
- jelem = `<${name}${jattr}>\n${jelem}</${name}>\n`
253
- } else {
254
- jelem = `<${name}${jattr}>${jelem}</${name}>\n`
255
- }
256
- } else {
257
- jelem = `<${name}${jattr} />\n`
258
- }
259
- return jelem
260
- }
261
-
262
- // method: array_to_xml( tagName, array )
263
-
264
- XML.ObjTree.prototype.array_to_xml = function (name, array) {
265
- const out = []
266
- for (let i = 0; i < array.length; i++) {
267
- const val = array[i]
268
- if (typeof val === 'undefined' || val == null) {
269
- out[out.length] = `<${name} />`
270
- } else if (typeof val === 'object' && val.constructor === Array) {
271
- out[out.length] = this.array_to_xml(name, val)
272
- } else if (typeof val === 'object') {
273
- out[out.length] = this.hash_to_xml(name, val)
274
- } else {
275
- out[out.length] = this.scalar_to_xml(name, val)
276
- }
277
- }
278
- return out.join('')
279
- }
280
-
281
- // method: scalar_to_xml( tagName, text )
282
-
283
- XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
284
- if (name === '#text') {
285
- return this.xml_escape(text)
286
- }
287
- return `<${name}>${this.xml_escape(text)}</${name}>\n`
288
- }
289
-
290
- // method: xml_escape( text )
291
- XML.ObjTree.prototype.xml_escape = escapeXml
292
-
293
- /*
294
- // ========================================================================
295
-
296
- =head1 NAME
297
-
298
- XML.ObjTree -- XML source code from/to JavaScript object like E4X
299
-
300
- =head1 SYNOPSIS
301
-
302
- var xotree = new XML.ObjTree();
303
- var tree1 = {
304
- root: {
305
- node: "Hello, World!"
306
- }
307
- };
308
- var xml1 = xotree.writeXML( tree1 ); // object tree to XML source
309
- alert( "xml1: "+xml1 );
310
-
311
- var xml2 = '<?xml version="1.0"?><response><error>0</error></response>';
312
- var tree2 = xotree.parseXML( xml2 ); // XML source to object tree
313
- alert( "error: "+tree2.response.error );
314
-
315
- =head1 DESCRIPTION
316
-
317
- XML.ObjTree class is a parser/generator between XML source code
318
- and JavaScript object like E4X, ECMAScript for XML.
319
- This is a JavaScript version of the XML::TreePP module for Perl.
320
- This also works as a wrapper for XMLHTTPRequest and successor to JKL.ParseXML class
321
- when this is used with prototype.js or JSAN's HTTP.Request class.
322
-
323
- =head2 JavaScript object tree format
324
-
325
- A sample XML source:
326
-
327
- <?xml version="1.0" encoding="UTF-8"?>
328
- <family name="Kawasaki">
329
- <father>Yasuhisa</father>
330
- <mother>Chizuko</mother>
331
- <children>
332
- <girl>Shiori</girl>
333
- <boy>Yusuke</boy>
334
- <boy>Kairi</boy>
335
- </children>
336
- </family>
337
-
338
- Its JavaScript object tree like JSON/E4X:
339
-
340
- {
341
- 'family': {
342
- '-name': 'Kawasaki',
343
- 'father': 'Yasuhisa',
344
- 'mother': 'Chizuko',
345
- 'children': {
346
- 'girl': 'Shiori'
347
- 'boy': [
348
- 'Yusuke',
349
- 'Kairi'
350
- ]
351
- }
352
- }
353
- };
354
-
355
- Each elements are parsed into objects:
356
-
357
- tree.family.father; # the father's given name.
358
-
359
- Prefix '-' is inserted before every attributes' name.
360
-
361
- tree.family["-name"]; # this family's family name
362
-
363
- A array is used because this family has two boys.
364
-
365
- tree.family.children.boy[0]; # first boy's name
366
- tree.family.children.boy[1]; # second boy's name
367
- tree.family.children.girl; # (girl has no other sisters)
368
-
369
- =head1 METHODS
370
-
371
- =head2 xotree = new XML.ObjTree()
372
-
373
- This constructor method returns a new XML.ObjTree object.
374
-
375
- =head2 xotree.force_array = [ "rdf:li", "item", "-xmlns" ];
376
-
377
- This property allows you to specify a list of element names
378
- which should always be forced into an array representation.
379
- The default value is null, it means that context of the elements
380
- will determine to make array or to keep it scalar.
381
-
382
- =head2 xotree.attr_prefix = '@';
383
-
384
- This property allows you to specify a prefix character which is
385
- inserted before each attribute names.
386
- Instead of default prefix '-', E4X-style prefix '@' is also available.
387
- The default character is '-'.
388
- Or set '@' to access attribute values like E4X, ECMAScript for XML.
389
- The length of attr_prefix must be just one character and not be empty.
390
-
391
- =head2 tree = xotree.parseXML( xmlSrc );
392
-
393
- This method loads an XML document using the supplied string
394
- and returns its JavaScript object converted.
395
-
396
- =head2 tree = xotree.parseDOM( domNode );
397
-
398
- This method parses a DOM tree (ex. responseXML.documentElement)
399
- and returns its JavaScript object converted.
400
-
401
- =head2 tree = xotree.parseHTTP( url, options );
402
-
403
- This method loads a XML file from remote web server
404
- and returns its JavaScript object converted.
405
- XMLHTTPRequest's synchronous mode is always used.
406
- This mode blocks the process until the response is completed.
407
-
408
- First argument is a XML file's URL
409
- which must exist in the same domain as parent HTML file's.
410
- Cross-domain loading is not available for security reasons.
411
-
412
- Second argument is options' object which can contains some parameters:
413
- method, postBody, parameters, onLoading, etc.
414
-
415
- This method requires JSAN's L<HTTP.Request> class or prototype.js's Ajax.Request class.
416
-
417
- =head2 xotree.parseHTTP( url, options, callback );
418
-
419
- If a callback function is set as third argument,
420
- XMLHTTPRequest's asynchronous mode is used.
421
-
422
- This mode calls a callback function with XML file's JavaScript object converted
423
- after the response is completed.
424
-
425
- =head2 xmlSrc = xotree.writeXML( tree );
426
-
427
- This method parses a JavaScript object tree
428
- and returns its XML source generated.
429
-
430
- =head1 EXAMPLES
431
-
432
- =head2 Text node and attributes
433
-
434
- If a element has both of a text node and attributes
435
- or both of a text node and other child nodes,
436
- text node's value is moved to a special node named "#text".
437
-
438
- var xotree = new XML.ObjTree();
439
- var xmlSrc = '<span class="author">Kawasaki Yusuke</span>';
440
- var tree = xotree.parseXML( xmlSrc );
441
- var class = tree.span["-class"]; # attribute
442
- var name = tree.span["#text"]; # text node
443
-
444
- =head2 parseHTTP() method with HTTP-GET and sync-mode
445
-
446
- HTTP/Request.js or prototype.js must be loaded before calling this method.
447
-
448
- var xotree = new XML.ObjTree();
449
- var url = "http://example.com/index.html";
450
- var tree = xotree.parseHTTP( url );
451
- xotree.attr_prefix = '@'; // E4X-style
452
- alert( tree.html["@lang"] );
453
-
454
- This code shows C<lang=""> attribute from a X-HTML source code.
455
-
456
- =head2 parseHTTP() method with HTTP-POST and async-mode
457
-
458
- Third argument is a callback function which is called on onComplete.
459
-
460
- var xotree = new XML.ObjTree();
461
- var url = "http://example.com/mt-tb.cgi";
462
- var opts = {
463
- postBody: "title=...&excerpt=...&url=...&blog_name=..."
464
- };
465
- var func = function ( tree ) {
466
- alert( tree.response.error );
467
- };
468
- xotree.parseHTTP( url, opts, func );
469
-
470
- This code send a track back ping and shows its response code.
471
-
472
- =head2 Simple RSS reader
473
-
474
- This is a RSS reader which loads RDF file and displays all items.
475
-
476
- var xotree = new XML.ObjTree();
477
- xotree.force_array = [ "rdf:li", "item" ];
478
- var url = "http://example.com/news-rdf.xml";
479
- var func = function( tree ) {
480
- var elem = document.getElementById("rss_here");
481
- for( var i=0; i<tree["rdf:RDF"].item.length; i++ ) {
482
- var divTag = document.createElement( "div" );
483
- var aTag = document.createElement( "a" );
484
- aTag.href = tree["rdf:RDF"].item[i].link;
485
- var title = tree["rdf:RDF"].item[i].title;
486
- var tNode = document.createTextNode( title );
487
- aTag.appendChild( tNode );
488
- divTag.appendChild( aTag );
489
- elem.appendChild( divTag );
490
- }
491
- };
492
- xotree.parseHTTP( url, {}, func );
493
-
494
- =head2 XML-RPC using writeXML, prototype.js and parseDOM
495
-
496
- If you wish to use prototype.js's Ajax.Request class by yourself:
497
-
498
- var xotree = new XML.ObjTree();
499
- var reqTree = {
500
- methodCall: {
501
- methodName: "weblogUpdates.ping",
502
- params: {
503
- param: [
504
- { value: "Kawa.net xp top page" }, // 1st param
505
- { value: "http://www.kawa.net/" } // 2nd param
506
- ]
507
- }
508
- }
509
- };
510
- var reqxml = xotree.writeXML( reqTree ); // JS-Object to XML code
511
- var url = "http://example.com/xmlrpc";
512
- var func = function( req ) {
513
- var resDom = req.responseXML.documentElement;
514
- xotree.force_array = [ "member" ];
515
- var resTree = xotree.parseDOM( resDom ); // XML-DOM to JS-Object
516
- alert( resTree.methodResponse.params.param.value.struct.member[0].value.string );
517
- };
518
- var opt = {
519
- method: "post",
520
- postBody: reqxml,
521
- asynchronous: true,
522
- onComplete: func
523
- };
524
- new Ajax.Request( url, opt );
525
-
526
- =head1 AUTHOR
527
-
528
- Yusuke Kawasaki http://www.kawa.net/
529
- =head1 COPYRIGHT AND LICENSE
530
-
531
- Copyright (c) 2005-2006 Yusuke Kawasaki. All rights reserved.
532
- This program is free software; you can redistribute it and/or
533
- modify it under the Artistic license. Or whatever license I choose,
534
- which I will do instead of keeping this documentation like it is.
535
-
536
- =cut
537
- // ========================================================================
538
- */
539
-
540
- const lfXml2Json = (xmlData) => new XML.ObjTree().parseXML(xmlData)
541
-
542
- export { lfXml2Json }