@miy2/xml-api 0.9.0 → 0.9.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.
- package/README.md +22 -2
- package/dist/collab/bridge.js +1 -2
- package/dist/cst/cst-utils.d.ts +11 -0
- package/dist/cst/cst-utils.js +32 -0
- package/dist/cst/grammar.js +11 -25
- package/dist/cst/parser.js +7 -11
- package/dist/cst/xml-cst.js +1 -5
- package/dist/cst/xml-grammar.js +83 -86
- package/dist/dom.d.ts +20 -1
- package/dist/dom.js +93 -60
- package/dist/engine/editor-state.js +1 -5
- package/dist/engine/sync-engine.d.ts +43 -9
- package/dist/engine/sync-engine.js +166 -122
- package/dist/engine/transaction-builder.d.ts +14 -0
- package/dist/engine/transaction-builder.js +143 -0
- package/dist/engine/transaction.d.ts +3 -0
- package/dist/engine/transaction.js +12 -8
- package/dist/history-manager.d.ts +4 -0
- package/dist/history-manager.js +75 -5
- package/dist/model/formatter.d.ts +2 -0
- package/dist/model/formatter.js +15 -18
- package/dist/model/xml-api-model.d.ts +17 -6
- package/dist/model/xml-api-model.js +40 -34
- package/dist/model/xml-binder.d.ts +8 -1
- package/dist/model/xml-binder.js +48 -34
- package/dist/model/xml-schema.js +1 -5
- package/dist/view/schema-view.d.ts +80 -0
- package/dist/view/schema-view.js +222 -0
- package/dist/view/view-binder.d.ts +47 -0
- package/dist/view/view-binder.js +163 -0
- package/dist/xml-api-events.d.ts +8 -4
- package/dist/xml-api-events.js +1 -5
- package/dist/xml-api.d.ts +36 -22
- package/dist/xml-api.js +77 -59
- package/package.json +4 -2
- package/LICENSE.md +0 -21
package/dist/cst/xml-grammar.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.g_deprecated = exports.grammar = void 0;
|
|
4
|
-
const grammar_1 = require("./grammar");
|
|
5
|
-
const g = new grammar_1.GrammarBuilder();
|
|
1
|
+
import { alt, exc, GrammarBuilder, lit, opt, plus, ref, reg, rep, seq, } from "./grammar";
|
|
2
|
+
const g = new GrammarBuilder();
|
|
6
3
|
const SQ = "\u0027"; // Single Quote '
|
|
7
4
|
const DQ = "\u0022"; // Double Quote "
|
|
8
5
|
// [1] document ::= prolog element Misc*
|
|
@@ -13,115 +10,115 @@ const DQ = "\u0022"; // Double Quote "
|
|
|
13
10
|
// - Clear Parent-Child Hierarchy: Every non-root element has exactly one parent, creating a well-defined tree structure.
|
|
14
11
|
//
|
|
15
12
|
// cf: https://www.w3.org/TR/xml/#NT-document
|
|
16
|
-
g.rule("document",
|
|
13
|
+
g.rule("document", seq(ref("prolog"), ref("element"), rep(ref("Misc"))));
|
|
17
14
|
// [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
|
18
15
|
//
|
|
19
16
|
// any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
|
|
20
17
|
//
|
|
21
18
|
// cf: https://www.w3.org/TR/xml/#NT-Char
|
|
22
|
-
g.rule("Char",
|
|
19
|
+
g.rule("Char", reg("\t|\n|\r|[\u0020-\uD7FF]|[\uE000-\uFFFD]|[\uD800-\uDBFF][\uDC00-\uDFFF]"));
|
|
23
20
|
// [3] S ::= (#x20 | #x9 | #xD | #xA)+
|
|
24
21
|
// cf: https://www.w3.org/TR/xml/#NT-S
|
|
25
|
-
g.rule("S",
|
|
22
|
+
g.rule("S", plus(reg("[\x20\t\r\n]")));
|
|
26
23
|
// [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
27
24
|
// cf: https://www.w3.org/TR/xml/#NT-NameStartChar
|
|
28
|
-
g.rule("NameStartChar",
|
|
25
|
+
g.rule("NameStartChar", alt(lit(":"), reg("[A-Z]"), lit("_"), reg("[a-z]"), reg("[\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]"), reg("[\uD800-\uDB7F][\uDC00-\uDFFF]")));
|
|
29
26
|
// [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
|
30
27
|
// cf: https://www.w3.org/TR/xml/#NT-NameChar
|
|
31
|
-
g.rule("NameChar",
|
|
28
|
+
g.rule("NameChar", alt(ref("NameStartChar"), lit("-"), lit("."), reg("[0-9]"), lit("\u00B7"), reg("[\u0300-\u036F\u203F-\u2040]")));
|
|
32
29
|
// [5] Name ::= NameStartChar (NameChar)*
|
|
33
30
|
// cf: https://www.w3.org/TR/xml/#NT-Name
|
|
34
|
-
g.rule("Name",
|
|
31
|
+
g.rule("Name", seq(ref("NameStartChar"), rep(ref("NameChar"))));
|
|
35
32
|
// [6] Names ::= Name (#x20 Name)*
|
|
36
33
|
// cf: https://www.w3.org/TR/xml/#NT-Names
|
|
37
|
-
g.rule("Names",
|
|
34
|
+
g.rule("Names", seq(ref("Name"), rep(seq(lit("\x20"), ref("Name")))));
|
|
38
35
|
// [7] Nmtoken ::= (NameChar)+
|
|
39
36
|
// cf: https://www.w3.org/TR/xml/#NT-Nmtoken
|
|
40
|
-
g.rule("Nmtoken",
|
|
37
|
+
g.rule("Nmtoken", plus(ref("NameChar")));
|
|
41
38
|
// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
|
|
42
39
|
// cf: https://www.w3.org/TR/xml/#NT-Nmtokens
|
|
43
|
-
g.rule("Nmtokens",
|
|
40
|
+
g.rule("Nmtokens", seq(ref("Nmtoken"), rep(seq(lit(" "), ref("Nmtoken")))));
|
|
44
41
|
// [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | "'" ([^%&'] | PEReference | Reference)* "'"
|
|
45
42
|
// cf: https://www.w3.org/TR/xml/#NT-EntityValue
|
|
46
|
-
g.rule("EntityValue",
|
|
43
|
+
g.rule("EntityValue", alt(seq(lit(DQ), rep(alt(reg("[^%&\\x22]"), ref("PEReference"), ref("Reference"))), lit(DQ)), seq(lit(SQ), rep(alt(reg("[^%&\\x27]"), ref("PEReference"), ref("Reference"))), lit(SQ))));
|
|
47
44
|
// [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
|
|
48
45
|
// cf: https://www.w3.org/TR/xml/#NT-AttValue
|
|
49
|
-
g.rule("AttValue",
|
|
46
|
+
g.rule("AttValue", alt(seq(lit(DQ), rep(alt(reg("[^<&\\x22]"), ref("Reference"))), lit(DQ)), seq(lit(SQ), rep(alt(reg("[^<&\\x27]"), ref("Reference"))), lit(SQ))));
|
|
50
47
|
// [11] SystemLiteral ::= ('"' [^\"]* "'") | ("'" [^']* "'")
|
|
51
48
|
// cf: https://www.w3.org/TR/xml/#NT-SystemLiteral
|
|
52
|
-
g.rule("SystemLiteral",
|
|
49
|
+
g.rule("SystemLiteral", alt(seq(lit(DQ), reg("[^\\x22]*"), lit(DQ)), seq(lit(SQ), reg("[^\\x27]*"), lit(SQ))));
|
|
53
50
|
// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
|
|
54
51
|
// cf: https://www.w3.org/TR/xml/#NT-PubidLiteral
|
|
55
|
-
g.rule("PubidLiteral",
|
|
52
|
+
g.rule("PubidLiteral", alt(seq(lit(DQ), rep(ref("PubidChar")), lit(DQ)), seq(lit(SQ), rep(exc(ref("PubidChar"), lit(SQ))), lit(SQ))));
|
|
56
53
|
// [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
|
|
57
54
|
// cf: https://www.w3.org/TR/xml/#NT-PubidChar
|
|
58
|
-
g.rule("PubidChar",
|
|
55
|
+
g.rule("PubidChar", reg("[\\x20\\r\\na-zA-Z0-9-'()+,./:=?;!*#@$_%]"));
|
|
59
56
|
// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
|
|
60
57
|
// cf: https://www.w3.org/TR/xml/#NT-CharData
|
|
61
|
-
g.rule("CharData",
|
|
58
|
+
g.rule("CharData", rep(exc(reg("[^<&]"), lit("]]\x3E"))));
|
|
62
59
|
// [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
|
|
63
60
|
// cf: https://www.w3.org/TR/xml/#NT-Comment
|
|
64
|
-
g.rule("Comment",
|
|
61
|
+
g.rule("Comment", seq(lit("<!--"), rep(alt(exc(ref("Char"), lit("-")), seq(lit("-"), exc(ref("Char"), lit("-"))))), lit("-->")));
|
|
65
62
|
// [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
|
|
66
63
|
// cf: https://www.w3.org/TR/xml/#NT-PI
|
|
67
|
-
g.rule("PI",
|
|
64
|
+
g.rule("PI", seq(lit("<?"), ref("PITarget"), opt(seq(ref("S"), rep(exc(ref("Char"), lit("?>"))))), lit("?>")));
|
|
68
65
|
// [17] PITarget ::= Name - ((('X' | 'x') ('M' | 'm') ('L' | 'l')))
|
|
69
66
|
// cf: https://www.w3.org/TR/xml/#NT-PITarget
|
|
70
|
-
g.rule("PITarget",
|
|
67
|
+
g.rule("PITarget", exc(ref("Name"), reg("([Xx][Mm][Ll])")));
|
|
71
68
|
// [18] CDSect ::= CDStart CData CDEnd
|
|
72
69
|
// cf: https://www.w3.org/TR/xml/#NT-CDSect
|
|
73
|
-
g.rule("CDSect",
|
|
70
|
+
g.rule("CDSect", seq(ref("CDStart"), ref("CData"), ref("CDEnd")));
|
|
74
71
|
// [19] CDStart ::= '<![CDATA['
|
|
75
72
|
// cf: https://www.w3.org/TR/xml/#NT-CDStart
|
|
76
|
-
g.rule("CDStart",
|
|
73
|
+
g.rule("CDStart", lit("<![CDATA["));
|
|
77
74
|
// [20] CData ::= (Char* - (Char* ']]>' Char*))
|
|
78
75
|
// cf: https://www.w3.org/TR/xml/#NT-CData
|
|
79
|
-
g.rule("CData",
|
|
76
|
+
g.rule("CData", rep(exc(ref("Char"), lit("]]\x3E"))));
|
|
80
77
|
// [21] CDEnd ::= ']]>'
|
|
81
78
|
// cf: https://www.w3.org/TR/xml/#NT-CDEnd
|
|
82
|
-
g.rule("CDEnd",
|
|
79
|
+
g.rule("CDEnd", lit("]]\x3E"));
|
|
83
80
|
// [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
|
|
84
81
|
// cf: https://www.w3.org/TR/xml/#NT-prolog
|
|
85
|
-
g.rule("prolog",
|
|
82
|
+
g.rule("prolog", seq(opt(ref("XMLDecl")), rep(ref("Misc")), opt(seq(ref("doctypedecl"), rep(ref("Misc"))))));
|
|
86
83
|
// [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
|
|
87
84
|
// cf: https://www.w3.org/TR/xml/#NT-XMLDecl
|
|
88
|
-
g.rule("XMLDecl",
|
|
85
|
+
g.rule("XMLDecl", seq(lit("<?xml"), ref("VersionInfo"), opt(ref("EncodingDecl")), opt(ref("SDDecl")), opt(ref("S")), lit("?>")));
|
|
89
86
|
// [24] VersionInfo ::= S 'version' Eq (("'" VersionNum "'") | ('"' VersionNum "'"))
|
|
90
87
|
// cf: https://www.w3.org/TR/xml/#NT-VersionInfo
|
|
91
|
-
g.rule("VersionInfo",
|
|
88
|
+
g.rule("VersionInfo", seq(ref("S"), lit("version"), ref("Eq"), alt(seq(lit(SQ), ref("VersionNum"), lit(SQ)), seq(lit(DQ), ref("VersionNum"), lit(DQ)))));
|
|
92
89
|
// [25] Eq ::= S? '=' S?
|
|
93
90
|
// cf: https://www.w3.org/TR/xml/#NT-Eq
|
|
94
|
-
g.rule("Eq",
|
|
91
|
+
g.rule("Eq", seq(opt(ref("S")), lit("="), opt(ref("S"))));
|
|
95
92
|
// [26] VersionNum ::= '1.' [0-9]+
|
|
96
93
|
// cf: https://www.w3.org/TR/xml/#NT-VersionNum
|
|
97
|
-
g.rule("VersionNum",
|
|
94
|
+
g.rule("VersionNum", seq(lit("1."), plus(reg("[0-9]"))));
|
|
98
95
|
// [27] Misc ::= Comment | PI | S
|
|
99
96
|
// cf: https://www.w3.org/TR/xml/#NT-Misc
|
|
100
|
-
g.rule("Misc",
|
|
97
|
+
g.rule("Misc", alt(ref("Comment"), ref("PI"), ref("S")));
|
|
101
98
|
// [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
|
|
102
99
|
// cf: https://www.w3.org/TR/xml/#NT-doctypedecl
|
|
103
|
-
g.rule("doctypedecl",
|
|
100
|
+
g.rule("doctypedecl", seq(lit("<!DOCTYPE"), ref("S"), ref("Name"), opt(seq(ref("S"), ref("ExternalID"))), opt(ref("S")), opt(seq(lit("["), ref("intSubset"), lit("]"), opt(ref("S")))), lit(">")));
|
|
104
101
|
// [28a] DeclSep ::= PEReference | S
|
|
105
102
|
// cf: https://www.w3.org/TR/xml/#NT-DeclSep
|
|
106
|
-
g.rule("DeclSep",
|
|
103
|
+
g.rule("DeclSep", alt(ref("PEReference"), ref("S")));
|
|
107
104
|
// [28b] intSubset ::= (markupdecl | DeclSep)*
|
|
108
105
|
// cf: https://www.w3.org/TR/xml/#NT-intSubset
|
|
109
|
-
g.rule("intSubset",
|
|
106
|
+
g.rule("intSubset", rep(alt(ref("markupdecl"), ref("DeclSep"))));
|
|
110
107
|
// [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment
|
|
111
108
|
// cf: https://www.w3.org/TR/xml/#NT-markupdecl
|
|
112
|
-
g.rule("markupdecl",
|
|
109
|
+
g.rule("markupdecl", alt(ref("elementdecl"), ref("AttlistDecl"), ref("EntityDecl"), ref("NotationDecl"), ref("PI"), ref("Comment")));
|
|
113
110
|
// [30] extSubset ::= TextDecl? extSubsetDecl
|
|
114
111
|
// cf: https://www.w3.org/TR/xml/#NT-extSubset
|
|
115
|
-
g.rule("extSubset",
|
|
112
|
+
g.rule("extSubset", seq(opt(ref("TextDecl")), ref("extSubsetDecl")));
|
|
116
113
|
// [31] extSubsetDecl ::= ( markupdecl | conditionalSect | DeclSep)*
|
|
117
114
|
// cf: https://www.w3.org/TR/xml/#NT-extSubsetDecl
|
|
118
|
-
g.rule("extSubsetDecl",
|
|
115
|
+
g.rule("extSubsetDecl", rep(alt(ref("markupdecl"), ref("conditionalSect"), ref("DeclSep"))));
|
|
119
116
|
// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') "'"))
|
|
120
117
|
// cf: https://www.w3.org/TR/xml/#NT-SDDecl
|
|
121
|
-
g.rule("SDDecl",
|
|
118
|
+
g.rule("SDDecl", seq(ref("S"), lit("standalone"), ref("Eq"), alt(seq(lit(SQ), alt(lit("yes"), lit("no")), lit(SQ)), seq(lit(DQ), alt(lit("yes"), lit("no")), lit(DQ)))));
|
|
122
119
|
// [39] element ::= EmptyElemTag | STag content ETag
|
|
123
120
|
// cf: https://www.w3.org/TR/xml/#NT-element
|
|
124
|
-
g.rule("element",
|
|
121
|
+
g.rule("element", alt(ref("EmptyElemTag"), seq(ref("STag"), ref("content"), ref("ETag"))));
|
|
125
122
|
// Well-formedness constraint: Element Type Match
|
|
126
123
|
function validateElementTypeMatch(node, input) {
|
|
127
124
|
const structuralNode = node.unwrap();
|
|
@@ -171,89 +168,89 @@ function validateUniqueAttributes(node, input) {
|
|
|
171
168
|
}
|
|
172
169
|
// [40] STag ::= '<' Name (S Attribute)* S? '>'
|
|
173
170
|
// cf: https://www.w3.org/TR/xml/#NT-STag
|
|
174
|
-
g.rule("STag",
|
|
171
|
+
g.rule("STag", seq(lit("<"), ref("Name"), rep(seq(ref("S"), ref("Attribute"))), opt(ref("S")), lit(">")));
|
|
175
172
|
// Well-formedness constraint: Unique Att Spec
|
|
176
173
|
g.verifyRule("STag", validateUniqueAttributes);
|
|
177
174
|
// [41] Attribute ::= Name Eq AttValue
|
|
178
175
|
// cf: https://www.w3.org/TR/xml/#NT-Attribute
|
|
179
|
-
g.rule("Attribute",
|
|
176
|
+
g.rule("Attribute", seq(ref("Name"), ref("Eq"), ref("AttValue")));
|
|
180
177
|
// [42] ETag ::= '</' Name S? '>'
|
|
181
178
|
// cf: https://www.w3.org/TR/xml/#NT-ETag
|
|
182
|
-
g.rule("ETag",
|
|
179
|
+
g.rule("ETag", seq(lit("</"), ref("Name"), opt(ref("S")), lit(">")));
|
|
183
180
|
// [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
|
|
184
181
|
// cf: https://www.w3.org/TR/xml/#NT-content
|
|
185
|
-
g.rule("content",
|
|
182
|
+
g.rule("content", seq(opt(ref("CharData")), rep(seq(alt(ref("element"), ref("Reference"), ref("CDSect"), ref("PI"), ref("Comment")), opt(ref("CharData"))))));
|
|
186
183
|
// [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
|
|
187
184
|
// cf: https://www.w3.org/TR/xml/#NT-EmptyElemTag
|
|
188
|
-
g.rule("EmptyElemTag",
|
|
185
|
+
g.rule("EmptyElemTag", seq(lit("<"), ref("Name"), rep(seq(ref("S"), ref("Attribute"))), opt(ref("S")), lit("/>")));
|
|
189
186
|
// Well-formedness constraint: Unique Att Spec
|
|
190
187
|
g.verifyRule("EmptyElemTag", validateUniqueAttributes);
|
|
191
188
|
// [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
|
|
192
189
|
// cf: https://www.w3.org/TR/xml/#NT-elementdecl
|
|
193
|
-
g.rule("elementdecl",
|
|
190
|
+
g.rule("elementdecl", seq(lit("<!ELEMENT"), ref("S"), ref("Name"), ref("S"), ref("contentspec"), opt(ref("S")), lit(">")));
|
|
194
191
|
// [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
|
|
195
192
|
// cf: https://www.w3.org/TR/xml/#NT-contentspec
|
|
196
|
-
g.rule("contentspec",
|
|
193
|
+
g.rule("contentspec", alt(lit("EMPTY"), lit("ANY"), ref("Mixed"), ref("children")));
|
|
197
194
|
// [47] children ::= (choice | seq) ('?' | '*' | '+')?
|
|
198
195
|
// cf: https://www.w3.org/TR/xml/#NT-children
|
|
199
|
-
g.rule("children",
|
|
196
|
+
g.rule("children", seq(alt(ref("choice"), ref("seq")), opt(reg("[?*+]?"))));
|
|
200
197
|
// [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
|
|
201
198
|
// cf: https://www.w3.org/TR/xml/#NT-cp
|
|
202
|
-
g.rule("cp",
|
|
199
|
+
g.rule("cp", seq(alt(ref("Name"), ref("choice"), ref("seq")), opt(reg("[?*+]?"))));
|
|
203
200
|
// [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
|
|
204
201
|
// cf: https://www.w3.org/TR/xml/#NT-choice
|
|
205
|
-
g.rule("choice",
|
|
202
|
+
g.rule("choice", seq(lit("("), opt(ref("S")), ref("cp"), plus(seq(opt(ref("S")), lit("|"), opt(ref("S")), ref("cp"))), opt(ref("S")), lit(")")));
|
|
206
203
|
// [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
|
|
207
204
|
// cf: https://www.w3.org/TR/xml/#NT-seq
|
|
208
|
-
g.rule("seq",
|
|
205
|
+
g.rule("seq", seq(lit("("), opt(ref("S")), ref("cp"), rep(seq(opt(ref("S")), lit(","), opt(ref("S")), ref("cp"))), opt(ref("S")), lit(")")));
|
|
209
206
|
// [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | '(' S? '#PCDATA' S? ')'
|
|
210
207
|
// cf: https://www.w3.org/TR/xml/#NT-Mixed
|
|
211
|
-
g.rule("Mixed",
|
|
208
|
+
g.rule("Mixed", alt(seq(lit("("), opt(ref("S")), lit("#PCDATA"), rep(seq(opt(ref("S")), lit("|"), opt(ref("S")), ref("Name"))), opt(ref("S")), lit(")*")), seq(lit("("), opt(ref("S")), lit("#PCDATA"), opt(ref("S")), lit(")"))));
|
|
212
209
|
// [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
|
|
213
210
|
// cf: https://www.w3.org/TR/xml/#NT-AttlistDecl
|
|
214
|
-
g.rule("AttlistDecl",
|
|
211
|
+
g.rule("AttlistDecl", seq(lit("<!ATTLIST"), ref("S"), ref("Name"), rep(ref("AttDef")), opt(ref("S")), lit(">")));
|
|
215
212
|
// [53] AttDef ::= S Name S AttType S DefaultDecl
|
|
216
213
|
// cf: https://www.w3.org/TR/xml/#NT-AttDef
|
|
217
|
-
g.rule("AttDef",
|
|
214
|
+
g.rule("AttDef", seq(ref("S"), ref("Name"), ref("S"), ref("AttType"), ref("S"), ref("DefaultDecl")));
|
|
218
215
|
// [54] AttType ::= StringType | TokenizedType | EnumeratedType
|
|
219
216
|
// cf: https://www.w3.org/TR/xml/#NT-AttType
|
|
220
|
-
g.rule("AttType",
|
|
217
|
+
g.rule("AttType", alt(ref("StringType"), ref("TokenizedType"), ref("EnumeratedType")));
|
|
221
218
|
// [55] StringType ::= 'CDATA'
|
|
222
219
|
// cf: https://www.w3.org/TR/xml/#NT-StringType
|
|
223
|
-
g.rule("StringType",
|
|
220
|
+
g.rule("StringType", lit("CDATA"));
|
|
224
221
|
// [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'
|
|
225
222
|
// cf: https://www.w3.org/TR/xml/#NT-TokenizedType
|
|
226
|
-
g.rule("TokenizedType",
|
|
223
|
+
g.rule("TokenizedType", alt(lit("ID"), lit("IDREF"), lit("IDREFS"), lit("ENTITY"), lit("ENTITIES"), lit("NMTOKEN"), lit("NMTOKENS")));
|
|
227
224
|
// [57] EnumeratedType ::= NotationType | Enumeration
|
|
228
225
|
// cf: https://www.w3.org/TR/xml/#NT-EnumeratedType
|
|
229
|
-
g.rule("EnumeratedType",
|
|
226
|
+
g.rule("EnumeratedType", alt(ref("NotationType"), ref("Enumeration")));
|
|
230
227
|
// [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
|
|
231
228
|
// cf: https://www.w3.org/TR/xml/#NT-NotationType
|
|
232
|
-
g.rule("NotationType",
|
|
229
|
+
g.rule("NotationType", seq(lit("NOTATION"), ref("S"), lit("("), opt(ref("S")), ref("Name"), rep(seq(opt(ref("S")), lit("|"), opt(ref("S")), ref("Name"))), opt(ref("S")), lit(")")));
|
|
233
230
|
// [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
|
|
234
231
|
// cf: https://www.w3.org/TR/xml/#NT-Enumeration
|
|
235
|
-
g.rule("Enumeration",
|
|
232
|
+
g.rule("Enumeration", seq(lit("("), opt(ref("S")), ref("Nmtoken"), rep(seq(opt(ref("S")), lit("|"), opt(ref("S")), ref("Nmtoken"))), opt(ref("S")), lit(")")));
|
|
236
233
|
// [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue)
|
|
237
234
|
// cf: https://www.w3.org/TR/xml/#NT-DefaultDecl
|
|
238
|
-
g.rule("DefaultDecl",
|
|
235
|
+
g.rule("DefaultDecl", alt(lit("#REQUIRED"), lit("#IMPLIED"), seq(opt(seq(lit("#FIXED"), ref("S"))), ref("AttValue"))));
|
|
239
236
|
// [61] conditionalSect ::= includeSect | ignoreSect
|
|
240
237
|
// cf: https://www.w3.org/TR/xml/#NT-conditionalSect
|
|
241
|
-
g.rule("conditionalSect",
|
|
238
|
+
g.rule("conditionalSect", alt(ref("includeSect"), ref("ignoreSect")));
|
|
242
239
|
// [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
|
|
243
240
|
// cf: https://www.w3.org/TR/xml/#NT-includeSect
|
|
244
|
-
g.rule("includeSect",
|
|
241
|
+
g.rule("includeSect", seq(lit("<!["), opt(ref("S")), lit("INCLUDE"), opt(ref("S")), lit("["), ref("extSubsetDecl"), lit("]]\x3E")));
|
|
245
242
|
// [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
|
|
246
243
|
// cf: https://www.w3.org/TR/xml/#NT-ignoreSect
|
|
247
|
-
g.rule("ignoreSect",
|
|
244
|
+
g.rule("ignoreSect", seq(lit("<!["), opt(ref("S")), lit("IGNORE"), opt(ref("S")), lit("["), rep(ref("ignoreSectContents")), lit("]]\x3E")));
|
|
248
245
|
// [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
|
|
249
246
|
// cf: https://www.w3.org/TR/xml/#NT-ignoreSectContents
|
|
250
|
-
g.rule("ignoreSectContents",
|
|
247
|
+
g.rule("ignoreSectContents", seq(ref("Ignore"), rep(seq(lit("<!["), ref("ignoreSectContents"), lit("]]\x3E"), ref("Ignore")))));
|
|
251
248
|
// [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
|
|
252
249
|
// cf: https://www.w3.org/TR/xml/#NT-Ignore
|
|
253
|
-
g.rule("Ignore",
|
|
250
|
+
g.rule("Ignore", rep(exc(ref("Char"), reg("(<![|]]\\x3E)"))));
|
|
254
251
|
// [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
|
|
255
252
|
// cf: https://www.w3.org/TR/xml/#NT-CharRef
|
|
256
|
-
g.rule("CharRef",
|
|
253
|
+
g.rule("CharRef", alt(seq(lit("&#"), plus(reg("[0-9]")), lit(";")), seq(lit("&#x"), plus(reg("[0-9a-fA-F]")), lit(";"))));
|
|
257
254
|
// Well-formedness constraint: Legal Character
|
|
258
255
|
// Characters referred to using character references MUST match the production for Char.
|
|
259
256
|
g.verifyRule("CharRef", (node, input) => {
|
|
@@ -274,52 +271,52 @@ g.verifyRule("CharRef", (node, input) => {
|
|
|
274
271
|
});
|
|
275
272
|
// [67] Reference ::= EntityRef | CharRef
|
|
276
273
|
// cf: https://www.w3.org/TR/xml/#NT-Reference
|
|
277
|
-
g.rule("Reference",
|
|
274
|
+
g.rule("Reference", alt(ref("EntityRef"), ref("CharRef")));
|
|
278
275
|
// [68] EntityRef ::= '&' Name ';'
|
|
279
276
|
// cf: https://www.w3.org/TR/xml/#NT-EntityRef
|
|
280
|
-
g.rule("EntityRef",
|
|
277
|
+
g.rule("EntityRef", seq(lit("&"), ref("Name"), lit(";")));
|
|
281
278
|
// [69] PEReference ::= '%' Name ';'
|
|
282
279
|
// cf: https://www.w3.org/TR/xml/#NT-PEReference
|
|
283
|
-
g.rule("PEReference",
|
|
280
|
+
g.rule("PEReference", seq(lit("%"), ref("Name"), lit(";")));
|
|
284
281
|
// [70] EntityDecl ::= GEDecl | PEDecl
|
|
285
282
|
// cf: https://www.w3.org/TR/xml/#NT-EntityDecl
|
|
286
|
-
g.rule("EntityDecl",
|
|
283
|
+
g.rule("EntityDecl", alt(ref("GEDecl"), ref("PEDecl")));
|
|
287
284
|
// [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
|
|
288
285
|
// cf: https://www.w3.org/TR/xml/#NT-GEDecl
|
|
289
|
-
g.rule("GEDecl",
|
|
286
|
+
g.rule("GEDecl", seq(lit("<!ENTITY"), ref("S"), ref("Name"), ref("S"), ref("EntityDef"), opt(ref("S")), lit(">")));
|
|
290
287
|
// [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
|
|
291
288
|
// cf: https://www.w3.org/TR/xml/#NT-PEDecl
|
|
292
|
-
g.rule("PEDecl",
|
|
289
|
+
g.rule("PEDecl", seq(lit("<!ENTITY"), ref("S"), lit("%"), ref("S"), ref("Name"), ref("S"), ref("PEDef"), opt(ref("S")), lit(">")));
|
|
293
290
|
// [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
|
|
294
291
|
// cf: https://www.w3.org/TR/xml/#NT-EntityDef
|
|
295
|
-
g.rule("EntityDef",
|
|
292
|
+
g.rule("EntityDef", alt(ref("EntityValue"), seq(ref("ExternalID"), opt(ref("NDataDecl")))));
|
|
296
293
|
// [74] PEDef ::= EntityValue | ExternalID
|
|
297
294
|
// cf: https://www.w3.org/TR/xml/#NT-PEDef
|
|
298
|
-
g.rule("PEDef",
|
|
295
|
+
g.rule("PEDef", alt(ref("EntityValue"), ref("ExternalID")));
|
|
299
296
|
// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
|
|
300
297
|
// cf: https://www.w3.org/TR/xml/#NT-ExternalID
|
|
301
|
-
g.rule("ExternalID",
|
|
298
|
+
g.rule("ExternalID", alt(seq(lit("SYSTEM"), ref("S"), ref("SystemLiteral")), seq(lit("PUBLIC"), ref("S"), ref("PubidLiteral"), ref("S"), ref("SystemLiteral"))));
|
|
302
299
|
// [76] NDataDecl ::= S 'NDATA' S Name
|
|
303
300
|
// cf: https://www.w3.org/TR/xml/#NT-NDataDecl
|
|
304
|
-
g.rule("NDataDecl",
|
|
301
|
+
g.rule("NDataDecl", seq(ref("S"), lit("NDATA"), ref("S"), ref("Name")));
|
|
305
302
|
// [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
|
|
306
303
|
// cf: https://www.w3.org/TR/xml/#NT-TextDecl
|
|
307
|
-
g.rule("TextDecl",
|
|
304
|
+
g.rule("TextDecl", seq(lit("<?xml"), opt(ref("VersionInfo")), ref("EncodingDecl"), opt(ref("S")), lit("?>")));
|
|
308
305
|
// [78] extParsedEnt ::= TextDecl? content
|
|
309
306
|
// cf: https://www.w3.org/TR/xml/#NT-extParsedEnt
|
|
310
|
-
g.rule("extParsedEnt",
|
|
307
|
+
g.rule("extParsedEnt", seq(opt(ref("TextDecl")), ref("content")));
|
|
311
308
|
// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName "'" | "'" EncName "'")
|
|
312
309
|
// cf: https://www.w3.org/TR/xml/#NT-EncodingDecl
|
|
313
|
-
g.rule("EncodingDecl",
|
|
310
|
+
g.rule("EncodingDecl", seq(ref("S"), lit("encoding"), ref("Eq"), alt(seq(lit(DQ), ref("EncName"), lit(DQ)), seq(lit(SQ), ref("EncName"), lit(SQ)))));
|
|
314
311
|
// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
|
|
315
312
|
// cf: https://www.w3.org/TR/xml/#NT-EncName
|
|
316
|
-
g.rule("EncName",
|
|
313
|
+
g.rule("EncName", seq(reg("[A-Za-z]"), rep(reg("[A-Za-z0-9._-]"))));
|
|
317
314
|
// [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
|
|
318
315
|
// cf: https://www.w3.org/TR/xml/#NT-NotationDecl
|
|
319
|
-
g.rule("NotationDecl",
|
|
316
|
+
g.rule("NotationDecl", seq(lit("<!NOTATION"), ref("S"), ref("Name"), ref("S"), alt(ref("ExternalID"), ref("PublicID")), opt(ref("S")), lit(">")));
|
|
320
317
|
// [83] PublicID ::= 'PUBLIC' S PubidLiteral
|
|
321
318
|
// cf: https://www.w3.org/TR/xml/#NT-PublicID
|
|
322
|
-
g.rule("PublicID",
|
|
319
|
+
g.rule("PublicID", seq(lit("PUBLIC"), ref("S"), ref("PubidLiteral")));
|
|
323
320
|
/**
|
|
324
321
|
* Unimplemented Well-formedness Constraints (WFC)
|
|
325
322
|
*
|
|
@@ -362,5 +359,5 @@ g.rule("PublicID", (0, grammar_1.seq)((0, grammar_1.lit)("PUBLIC"), (0, grammar_
|
|
|
362
359
|
* "Parameter-entity references MUST NOT occur outside the DTD."
|
|
363
360
|
* https://www.w3.org/TR/xml/#indtd
|
|
364
361
|
*/
|
|
365
|
-
|
|
366
|
-
|
|
362
|
+
export const grammar = g.build();
|
|
363
|
+
export const g_deprecated = g;
|
package/dist/dom.d.ts
CHANGED
|
@@ -50,6 +50,13 @@ export interface DOMObserver {
|
|
|
50
50
|
* @param index The index from which the child was removed.
|
|
51
51
|
*/
|
|
52
52
|
onChildRemoved(parent: Node, child: Node, index: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Called when a child node is replaced.
|
|
55
|
+
* @param parent The parent node.
|
|
56
|
+
* @param newChild The new child node.
|
|
57
|
+
* @param oldChild The replaced child node.
|
|
58
|
+
*/
|
|
59
|
+
onChildReplaced(parent: Node, newChild: Node, oldChild: Node): void;
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
62
|
* Base class for all DOM nodes.
|
|
@@ -72,7 +79,7 @@ export declare abstract class Node {
|
|
|
72
79
|
*/
|
|
73
80
|
get parentNode(): Node | null;
|
|
74
81
|
/**
|
|
75
|
-
* Returns a NodeList containing all children of this node.
|
|
82
|
+
* Returns a NodeList containing all children of this node, respecting the document's filter.
|
|
76
83
|
*/
|
|
77
84
|
get childNodes(): NodeList;
|
|
78
85
|
get firstChild(): Node | null;
|
|
@@ -92,6 +99,12 @@ export declare abstract class Node {
|
|
|
92
99
|
* @param refChild The reference node (must be a child of this node).
|
|
93
100
|
*/
|
|
94
101
|
insertBefore<T extends Node>(newChild: T, refChild: Node | null): T;
|
|
102
|
+
/**
|
|
103
|
+
* Replaces a child node with a new node.
|
|
104
|
+
* @param newChild The new node to add.
|
|
105
|
+
* @param oldChild The child node to be replaced.
|
|
106
|
+
*/
|
|
107
|
+
replaceChild<T extends Node>(newChild: T, oldChild: Node): T;
|
|
95
108
|
/**
|
|
96
109
|
* Removes a child node from the DOM and returns the removed node.
|
|
97
110
|
* @param child The child node to remove.
|
|
@@ -148,7 +161,12 @@ export declare class Element extends Node {
|
|
|
148
161
|
export declare class Document extends Node {
|
|
149
162
|
private _documentElement;
|
|
150
163
|
private observer;
|
|
164
|
+
nodeFilter: ((node: ModelNode) => boolean) | null;
|
|
151
165
|
constructor();
|
|
166
|
+
/**
|
|
167
|
+
* Checks if a node is accepted by the current filter.
|
|
168
|
+
*/
|
|
169
|
+
accepts(node: ModelNode): boolean;
|
|
152
170
|
/**
|
|
153
171
|
* Sets the observer to listen for DOM changes.
|
|
154
172
|
*/
|
|
@@ -158,6 +176,7 @@ export declare class Document extends Node {
|
|
|
158
176
|
notifyElementTextChange(element: Element, text: string): void;
|
|
159
177
|
notifyChildAdded(parent: Node, child: Node, index: number): void;
|
|
160
178
|
notifyChildRemoved(parent: Node, child: Node, index: number): void;
|
|
179
|
+
notifyChildReplaced(parent: Node, newChild: Node, oldChild: Node): void;
|
|
161
180
|
get nodeType(): number;
|
|
162
181
|
get nodeName(): string;
|
|
163
182
|
get documentElement(): Element | null;
|