@mak-98/xml-dirvi-app 0.11.0-beta.16 → 0.11.0-beta.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/README.md +122 -0
- package/dist/domain/xml-tree.d.ts +6 -11
- package/dist/domain/xml-tree.d.ts.map +1 -1
- package/dist/domain/xml-tree.js +0 -29
- package/dist/infrastructure/create-xml-dom.d.ts.map +1 -1
- package/dist/infrastructure/create-xml-dom.js +22 -19
- package/dist/infrastructure/get-xml-entries.d.ts +1 -9
- package/dist/infrastructure/get-xml-entries.d.ts.map +1 -1
- package/dist/infrastructure/get-xml-entries.js +118 -74
- package/dist/services/xml-dom.d.ts +11 -12
- package/dist/services/xml-dom.d.ts.map +1 -1
- package/dist/xml-dirvi-app.d.ts.map +1 -1
- package/dist/xml-dirvi-app.js +8 -5
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# XML dirvi app plugin
|
|
2
|
+
|
|
3
|
+
The XML dirvi app plugin lets dirvi load, browse and edit XML data as interactive tree srtuctures.
|
|
4
|
+
|
|
5
|
+
## Default view
|
|
6
|
+
|
|
7
|
+
By default, shows the document structure without applying specialized leaf rules.
|
|
8
|
+
|
|
9
|
+
Elements can be expanded to reveal their child nodes, including text, CDATA,
|
|
10
|
+
comments, and processing instructions. Whitespace-only text nodes are visible,
|
|
11
|
+
including what would be considered newlines for formatting:
|
|
12
|
+
|
|
13
|
+
```xml
|
|
14
|
+
<library>
|
|
15
|
+
<book>My book</book>
|
|
16
|
+
</library>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
would give by default:
|
|
20
|
+
|
|
21
|
+
```txt
|
|
22
|
+
library
|
|
23
|
+
text
|
|
24
|
+
book
|
|
25
|
+
text
|
|
26
|
+
text
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This is usually not desirable, and a way to filter the nodes to only show such
|
|
30
|
+
whitespace formatting in subtrees with `xml:space="preserve"` is provided.
|
|
31
|
+
|
|
32
|
+
Attributes are not child nodes of elements, but are inspectable and changeable.
|
|
33
|
+
|
|
34
|
+
## View options
|
|
35
|
+
|
|
36
|
+
### Filter whitespace-only text
|
|
37
|
+
|
|
38
|
+
- Default: off.
|
|
39
|
+
- Hide text nodes containing only XML whitespace.
|
|
40
|
+
- Do not hide whitespace where `xml:space="preserve"` applies.
|
|
41
|
+
|
|
42
|
+
### Treat text-only elements as leaves
|
|
43
|
+
|
|
44
|
+
- Default: off.
|
|
45
|
+
- Treat an element as a leaf when all of its children are text or CDATA.
|
|
46
|
+
- An empty element also qualifies.
|
|
47
|
+
- Edit its contents as plain text.
|
|
48
|
+
|
|
49
|
+
Saving plain text replaces the element's contents with text. Markup typed into
|
|
50
|
+
the editor is text, not a request to create XML elements. CDATA boundaries
|
|
51
|
+
need not be retained.
|
|
52
|
+
|
|
53
|
+
### Treat extension-marked elements as leaves
|
|
54
|
+
|
|
55
|
+
- Default: off.
|
|
56
|
+
- Configure the attribute name used to specify a file extension.
|
|
57
|
+
- An element with that attribute is a leaf, edited as plain text.
|
|
58
|
+
- Open the editor with a temporary filename using the specified extension, so
|
|
59
|
+
the editor can choose syntax highlighting.
|
|
60
|
+
- The extension rule takes precedence over the other leaf rules.
|
|
61
|
+
|
|
62
|
+
For example, assuming the configured attribute is `extension`:
|
|
63
|
+
|
|
64
|
+
```xml
|
|
65
|
+
<snippet extension="tsx">const App = () => <div>Hello</div>;</snippet>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The editor receives:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
const App = () => <div>Hello</div>;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
After saving, the contents are still text, and the element remains a leaf.
|
|
75
|
+
If an extension-marked element contains child elements or other non-text
|
|
76
|
+
content, report an error rather than silently flattening or discarding it.
|
|
77
|
+
|
|
78
|
+
Treat the extension as data, not as a path or shell command. Reject unsafe
|
|
79
|
+
values before constructing a temporary filename.
|
|
80
|
+
|
|
81
|
+
### Treat `xml:space="preserve"` elements as leaves
|
|
82
|
+
|
|
83
|
+
- Default: off.
|
|
84
|
+
- An element with `xml:space="preserve"` directly on it is a leaf.
|
|
85
|
+
- Edit its contents as **inner XML**, including any nested markup.
|
|
86
|
+
- Parse the edited contents as XML on save.
|
|
87
|
+
|
|
88
|
+
For example, the editor for this element:
|
|
89
|
+
|
|
90
|
+
```xml
|
|
91
|
+
<note xml:space="preserve">Hello <em>world</em>.</note>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
receives:
|
|
95
|
+
|
|
96
|
+
```xml
|
|
97
|
+
Hello <em>world</em>.
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The extension rule takes precedence if both rules apply.
|
|
101
|
+
|
|
102
|
+
`xml:space` can be inherited in XML. For this view option, however, only the
|
|
103
|
+
element that directly declares `xml:space="preserve"` becomes a leaf.
|
|
104
|
+
|
|
105
|
+
## Editing and saving
|
|
106
|
+
|
|
107
|
+
- Open editable content in an external editor through a temporary file.
|
|
108
|
+
- Distinguish plain-text editing from inner-XML editing. Never parse plain-text
|
|
109
|
+
edits as XML markup.
|
|
110
|
+
- For inner-XML edits, support multiple child nodes and namespace declarations
|
|
111
|
+
inherited from ancestors.
|
|
112
|
+
- Reject invalid edits without overwriting the original file.
|
|
113
|
+
- Detect if the original file changed while the editor was open; do not
|
|
114
|
+
silently overwrite those changes.
|
|
115
|
+
- Clean up temporary files after editing.
|
|
116
|
+
- Preserve document content not intentionally edited, even if its serialized
|
|
117
|
+
formatting changes. In particular, do not add or remove meaningful
|
|
118
|
+
whitespace while formatting.
|
|
119
|
+
- Report unsupported XML features instead of silently losing content.
|
|
120
|
+
|
|
121
|
+
Creating or restructuring branches should be a separate, intentional user
|
|
122
|
+
operation, not a side effect of saving plain text.
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { TreeNode } from 'dirvi-lib';
|
|
3
|
+
declare const xmlIdBrand: unique symbol;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* This is not XML document order. XML sibling order is held by the source
|
|
7
|
-
* TreeNode child sequence.
|
|
8
|
-
*
|
|
9
|
-
* Changing the name changes the complete tree key.
|
|
5
|
+
* An opaque, reference-identity ID for a node in the current XML document.
|
|
10
6
|
*/
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export declare function xmlIdName(id: XmlId): string;
|
|
15
|
-
export declare function xmlIdUuid(id: XmlId): string;
|
|
7
|
+
export type XmlId = object & {
|
|
8
|
+
readonly [xmlIdBrand]: true;
|
|
9
|
+
};
|
|
16
10
|
import type { XmlElementChild, XmlNode } from './xml-doc.js';
|
|
17
11
|
export type XmlNodeValue = XmlNode;
|
|
18
12
|
export type XmlTreeNode = TreeNode<XmlId, XmlNodeValue>;
|
|
@@ -107,4 +101,5 @@ export declare const xmlValueSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
107
101
|
target: z.ZodString;
|
|
108
102
|
data: z.ZodString;
|
|
109
103
|
}, z.core.$strip>]>;
|
|
104
|
+
export {};
|
|
110
105
|
//# sourceMappingURL=xml-tree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-tree.d.ts","sourceRoot":"","sources":["../../src/domain/xml-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"xml-tree.d.ts","sourceRoot":"","sources":["../../src/domain/xml-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAM1C,OAAO,CAAC,MAAM,UAAU,EAAE,OAAO,MAAM,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAM7D,OAAO,KAAK,EAAc,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AACnC,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAqFxD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA7BT,CAAC,CAAC,gBAAgB,CAChC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CACtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAFe,CAAC,CAAC,gBAAgB,CAChC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CACtD;;;;;;;;;;;;;;mBAoCiC,CAAC"}
|
package/dist/domain/xml-tree.js
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
// -----------------------------------------------------------------------------
|
|
3
|
-
// Position: Id extends SerializableKey
|
|
4
|
-
// -----------------------------------------------------------------------------
|
|
5
|
-
const uuidSchema = z.uuid();
|
|
6
|
-
/**
|
|
7
|
-
* A node key containing its UUID and display name.
|
|
8
|
-
*
|
|
9
|
-
* This is not XML document order. XML sibling order is held by the source
|
|
10
|
-
* TreeNode child sequence.
|
|
11
|
-
*
|
|
12
|
-
* Changing the name changes the complete tree key.
|
|
13
|
-
*/
|
|
14
|
-
export const xmlIdSchema = z.string().refine((value) => {
|
|
15
|
-
const separator = value.indexOf(':');
|
|
16
|
-
return (separator > 0 &&
|
|
17
|
-
uuidSchema.safeParse(value.slice(0, separator)).success &&
|
|
18
|
-
value.slice(separator + 1).trim().length > 0);
|
|
19
|
-
}, {
|
|
20
|
-
message: 'Expected an XML node ID in the form <uuid>:<node-name>.',
|
|
21
|
-
});
|
|
22
|
-
export function createXmlId(name, uuid) {
|
|
23
|
-
return xmlIdSchema.parse(`${uuid}:${name}`);
|
|
24
|
-
}
|
|
25
|
-
export function xmlIdName(id) {
|
|
26
|
-
return id.slice(id.indexOf(':') + 1);
|
|
27
|
-
}
|
|
28
|
-
export function xmlIdUuid(id) {
|
|
29
|
-
return id.slice(0, id.indexOf(':'));
|
|
30
|
-
}
|
|
31
2
|
const xmlNameSchema = z.object({
|
|
32
3
|
qualifiedName: z.string(),
|
|
33
4
|
localName: z.string(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-xml-dom.d.ts","sourceRoot":"","sources":["../../src/infrastructure/create-xml-dom.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-xml-dom.d.ts","sourceRoot":"","sources":["../../src/infrastructure/create-xml-dom.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAiKrD;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MA4C7C,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DOMParser, Node, } from '@xmldom/xmldom';
|
|
2
|
+
const createXmlId = (node) => node;
|
|
2
3
|
/**
|
|
3
4
|
* Extract name for the domain type from xmldom.
|
|
4
5
|
* @param node
|
|
@@ -136,28 +137,30 @@ export const createXmlDom = (source) => {
|
|
|
136
137
|
},
|
|
137
138
|
}).parseFromString(source, 'application/xml');
|
|
138
139
|
return {
|
|
139
|
-
getDocument: () => ({
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
throw new Error(`XML path not found: ${path.join(' / ')}`);
|
|
150
|
-
}
|
|
151
|
-
node = child;
|
|
140
|
+
getDocument: () => ({
|
|
141
|
+
id: createXmlId(document),
|
|
142
|
+
value: { kind: 'document' },
|
|
143
|
+
}),
|
|
144
|
+
getChildren: (id) => {
|
|
145
|
+
const node = id === undefined ? document : id;
|
|
146
|
+
// Reject detached nodes and nodes from another document.
|
|
147
|
+
let current = node;
|
|
148
|
+
while (current && current !== document) {
|
|
149
|
+
current = current.parentNode;
|
|
152
150
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return children.map(toXmlDocumentChild);
|
|
151
|
+
if (current !== document) {
|
|
152
|
+
throw new Error('XML node does not belong to the current document');
|
|
156
153
|
}
|
|
157
|
-
if (node.nodeType
|
|
158
|
-
|
|
154
|
+
if (node.nodeType !== Node.DOCUMENT_NODE &&
|
|
155
|
+
node.nodeType !== Node.ELEMENT_NODE) {
|
|
156
|
+
throw new Error('XML node is a leaf');
|
|
159
157
|
}
|
|
160
|
-
|
|
158
|
+
return getChildrenXmldomNode(node).map((child) => ({
|
|
159
|
+
id: createXmlId(child),
|
|
160
|
+
value: node.nodeType === Node.DOCUMENT_NODE
|
|
161
|
+
? toXmlDocumentChild(child)
|
|
162
|
+
: toXmlElementChild(child),
|
|
163
|
+
}));
|
|
161
164
|
},
|
|
162
165
|
};
|
|
163
166
|
};
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { XmlDocument } from '../domain/xml-doc.js';
|
|
3
|
-
import type { XmlId, XmlNodeValue } from '../domain/xml-tree.js';
|
|
4
|
-
import { XmlDom } from '../services/xml-dom.js';
|
|
5
|
-
/**
|
|
6
|
-
* Returns the direct children addressed by a dirvi path, in document order.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getXmlEntries(filePath: string, dom: XmlDom, path: readonly XmlId[]): readonly AppChild<XmlId, XmlNodeValue>[];
|
|
9
|
-
export declare function createXmlRoot(filePath: string, document: XmlDocument): AppRoot<XmlId, XmlNodeValue>;
|
|
1
|
+
export {};
|
|
10
2
|
//# sourceMappingURL=get-xml-entries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-xml-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-xml-entries.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-xml-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-xml-entries.ts"],"names":[],"mappings":""}
|
|
@@ -1,74 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
export {};
|
|
2
|
+
// import { createHash } from 'node:crypto';
|
|
3
|
+
//
|
|
4
|
+
// import type { AppChild, AppRoot } from 'dirvi-apis';
|
|
5
|
+
//
|
|
6
|
+
// import type {
|
|
7
|
+
// XmlChildNode,
|
|
8
|
+
// XmlDocument,
|
|
9
|
+
// XmlNodePath,
|
|
10
|
+
// } from '../domain/xml-doc.js';
|
|
11
|
+
// import type { XmlId, XmlNodeValue } from '../domain/xml-tree.js';
|
|
12
|
+
// import { createXmlId } from '../domain/xml-tree.js';
|
|
13
|
+
// import { XmlDom } from '../services/xml-dom.js';
|
|
14
|
+
//
|
|
15
|
+
// // RFC 4122 URL namespace, used to derive deterministic version-5 UUIDs.
|
|
16
|
+
// const uuidNamespace = Buffer.from('6ba7b8119dad11d180b400c04fd430c8', 'hex');
|
|
17
|
+
//
|
|
18
|
+
// function nodeId(
|
|
19
|
+
// filePath: string,
|
|
20
|
+
// position: readonly number[],
|
|
21
|
+
// name: string,
|
|
22
|
+
// ): XmlId {
|
|
23
|
+
// const hash = createHash('sha1')
|
|
24
|
+
// .update(uuidNamespace)
|
|
25
|
+
// .update(JSON.stringify([filePath, position, name]), 'utf8')
|
|
26
|
+
// .digest();
|
|
27
|
+
//
|
|
28
|
+
// const bytes = Buffer.from(hash.subarray(0, 16));
|
|
29
|
+
// bytes[6] = (bytes[6]! & 0x0f) | 0x50; // UUID version 5
|
|
30
|
+
// bytes[8] = (bytes[8]! & 0x3f) | 0x80; // RFC variant
|
|
31
|
+
//
|
|
32
|
+
// const hex = bytes.toString('hex');
|
|
33
|
+
// const uuid = [
|
|
34
|
+
// hex.slice(0, 8),
|
|
35
|
+
// hex.slice(8, 12),
|
|
36
|
+
// hex.slice(12, 16),
|
|
37
|
+
// hex.slice(16, 20),
|
|
38
|
+
// hex.slice(20, 32),
|
|
39
|
+
// ].join('-');
|
|
40
|
+
//
|
|
41
|
+
// return createXmlId(name, uuid);
|
|
42
|
+
// }
|
|
43
|
+
//
|
|
44
|
+
// function nodeName(node: XmlChildNode): string {
|
|
45
|
+
// switch (node.kind) {
|
|
46
|
+
// case 'element':
|
|
47
|
+
// return node.name.qualifiedName;
|
|
48
|
+
// case 'doctype':
|
|
49
|
+
// return node.name;
|
|
50
|
+
// case 'processing-instruction':
|
|
51
|
+
// return node.target;
|
|
52
|
+
// case 'declaration':
|
|
53
|
+
// return '#declaration';
|
|
54
|
+
// case 'text':
|
|
55
|
+
// return '#text';
|
|
56
|
+
// case 'cdata':
|
|
57
|
+
// return '#cdata';
|
|
58
|
+
// case 'comment':
|
|
59
|
+
// return '#comment';
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
//
|
|
63
|
+
// function describeChild(
|
|
64
|
+
// filePath: string,
|
|
65
|
+
// position: XmlNodePath,
|
|
66
|
+
// node: XmlChildNode,
|
|
67
|
+
// ): AppChild<XmlId, XmlNodeValue> {
|
|
68
|
+
// return {
|
|
69
|
+
// id: nodeId(filePath, position, nodeName(node)),
|
|
70
|
+
// kind: node.kind === 'element' ? 'unloaded-branch' : 'leaf',
|
|
71
|
+
// value: node,
|
|
72
|
+
// };
|
|
73
|
+
// }
|
|
74
|
+
//
|
|
75
|
+
// /**
|
|
76
|
+
// * Returns the direct children addressed by a dirvi path, in document order.
|
|
77
|
+
// */
|
|
78
|
+
// export function getXmlEntries(
|
|
79
|
+
// filePath: string,
|
|
80
|
+
// dom: XmlDom,
|
|
81
|
+
// path: readonly XmlId[],
|
|
82
|
+
// ): readonly AppChild<XmlId, XmlNodeValue>[] {
|
|
83
|
+
// let position: XmlNodePath = [];
|
|
84
|
+
//
|
|
85
|
+
// for (const segment of path) {
|
|
86
|
+
// const children = dom.getChildren(position);
|
|
87
|
+
// const index = children.findIndex(
|
|
88
|
+
// (node, i) =>
|
|
89
|
+
// nodeId(filePath, [...position, i], nodeName(node)) === segment,
|
|
90
|
+
// );
|
|
91
|
+
//
|
|
92
|
+
// if (index === -1) {
|
|
93
|
+
// throw new Error(`XML path not found: ${path.join(' / ')}`);
|
|
94
|
+
// }
|
|
95
|
+
//
|
|
96
|
+
// const node = children[index];
|
|
97
|
+
//
|
|
98
|
+
// if (!node || node.kind !== 'element') {
|
|
99
|
+
// throw new Error(`XML path addresses a leaf: ${path.join(' / ')}`);
|
|
100
|
+
// }
|
|
101
|
+
//
|
|
102
|
+
// position = [...position, index];
|
|
103
|
+
// }
|
|
104
|
+
//
|
|
105
|
+
// return dom
|
|
106
|
+
// .getChildren(position)
|
|
107
|
+
// .map((node, index) => describeChild(filePath, [...position, index], node));
|
|
108
|
+
// }
|
|
109
|
+
//
|
|
110
|
+
// export function createXmlRoot(
|
|
111
|
+
// filePath: string,
|
|
112
|
+
// document: XmlDocument,
|
|
113
|
+
// ): AppRoot<XmlId, XmlNodeValue> {
|
|
114
|
+
// return {
|
|
115
|
+
// id: nodeId(filePath, [], '#document'),
|
|
116
|
+
// value: { kind: document.kind },
|
|
117
|
+
// };
|
|
118
|
+
// }
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { XmlDocument, XmlDocumentChild, XmlElementChild
|
|
1
|
+
import type { XmlDocument, XmlDocumentChild, XmlElementChild } from '../domain/xml-doc.js';
|
|
2
|
+
import { XmlId } from '../domain/xml-tree.js';
|
|
3
|
+
export type XmlDomEntry<Value> = {
|
|
4
|
+
id: XmlId;
|
|
5
|
+
value: Value;
|
|
6
|
+
};
|
|
2
7
|
export type XmlDom = {
|
|
8
|
+
/** Returns the document and its ID. */
|
|
9
|
+
getDocument: () => XmlDomEntry<XmlDocument>;
|
|
3
10
|
/**
|
|
4
|
-
* Loads
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
getDocument: () => XmlDocument;
|
|
8
|
-
/**
|
|
9
|
-
* Loads the direct children of the document or an element.
|
|
10
|
-
* Child elements do not have their own children loaded.
|
|
11
|
-
*
|
|
12
|
-
* An empty path addresses the document. Each index selects a child in
|
|
13
|
-
* document order.
|
|
11
|
+
* Loads direct children in document order.
|
|
12
|
+
* Omitting the ID addresses the document.
|
|
14
13
|
*/
|
|
15
|
-
getChildren: (
|
|
14
|
+
getChildren: (id?: XmlId) => readonly XmlDomEntry<XmlDocumentChild | XmlElementChild>[];
|
|
16
15
|
};
|
|
17
16
|
//# sourceMappingURL=xml-dom.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-dom.d.ts","sourceRoot":"","sources":["../../src/services/xml-dom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"xml-dom.d.ts","sourceRoot":"","sources":["../../src/services/xml-dom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI;IAC/B,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,uCAAuC;IACvC,WAAW,EAAE,MAAM,WAAW,CAAC,WAAW,CAAC,CAAC;IAE5C;;;OAGG;IACH,WAAW,EAAE,CACX,EAAE,CAAC,EAAE,KAAK,KACP,SAAS,WAAW,CAAC,gBAAgB,GAAG,eAAe,CAAC,EAAE,CAAC;CACjE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,YAAY,CAAC;AAQrE,eAAO,MAAM,YAAY,EAAE,SA8D1B,CAAC"}
|
package/dist/xml-dirvi-app.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { xmlValueSchema } from './domain/xml-tree.js';
|
|
4
4
|
import { createXmlFileResyncSubscription } from './infrastructure/create-xml-file-resync.js';
|
|
5
5
|
import { createXmlDom } from './infrastructure/create-xml-dom.js';
|
|
6
|
-
import { createXmlRoot, getXmlEntries } from './infrastructure/get-xml-entries.js';
|
|
7
6
|
export const xmlAppPlugin = {
|
|
8
7
|
createAppDefinitionApplicator: (input) => {
|
|
9
8
|
if (input === undefined) {
|
|
10
9
|
throw new Error('xml-dirvi-app: No file path to XML file given.');
|
|
11
10
|
}
|
|
12
11
|
const xmlAbsolutePath = resolve(input);
|
|
12
|
+
// TODO: Make the `xmldom` nodes the IDs.
|
|
13
13
|
// Create dom async on first need, cache afterward
|
|
14
14
|
let dom;
|
|
15
15
|
let domPromise;
|
|
@@ -31,15 +31,18 @@ export const xmlAppPlugin = {
|
|
|
31
31
|
};
|
|
32
32
|
const appDefinition = {
|
|
33
33
|
semanticOrder: true,
|
|
34
|
-
idSchema: xmlIdSchema,
|
|
35
34
|
valueSchema: xmlValueSchema,
|
|
36
35
|
loadChildren: async (path) => {
|
|
37
36
|
const dom = await getDom();
|
|
38
|
-
return
|
|
37
|
+
return dom.getChildren(path.at(-1)).map(({ id, value }) => ({
|
|
38
|
+
id,
|
|
39
|
+
kind: value.kind === 'element' ? 'unloaded-branch' : 'leaf',
|
|
40
|
+
value,
|
|
41
|
+
}));
|
|
39
42
|
},
|
|
40
43
|
loadRoot: async () => {
|
|
41
44
|
const dom = await getDom();
|
|
42
|
-
return
|
|
45
|
+
return dom.getDocument();
|
|
43
46
|
},
|
|
44
47
|
presentNode: (_id, value, isBranch) => ({
|
|
45
48
|
content: value.kind,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mak-98/xml-dirvi-app",
|
|
3
|
-
"version": "0.11.0-beta.
|
|
3
|
+
"version": "0.11.0-beta.17",
|
|
4
4
|
"description": "XML file app for dirvi.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@rgrove/parse-xml": "^5.0.0",
|
|
23
23
|
"@xmldom/xmldom": "^0.9.12",
|
|
24
|
-
"dirvi-apis": "0.11.0-beta.
|
|
24
|
+
"dirvi-apis": "0.11.0-beta.17",
|
|
25
25
|
"env-paths": "^4.0.0",
|
|
26
26
|
"zod": "^4.4.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.0.0",
|
|
30
|
-
"dirvi-lib": "0.11.0-beta.
|
|
30
|
+
"dirvi-lib": "0.11.0-beta.17",
|
|
31
31
|
"typescript": "^5.0.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|