| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
ve.dm.NodeFactory = function VeDmNodeFactory() { |
| 15 |
|
| 16 |
ve.dm.NodeFactory.super.call( this ); |
| 17 |
}; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
OO.inheritClass( ve.dm.NodeFactory, ve.dm.ModelFactory ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
ve.dm.NodeFactory.prototype.getDataElement = function ( type, attributes ) { |
| 34 |
const element = { type: type }; |
| 35 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 36 |
attributes = ve.extendObject( {}, this.registry[ type ].static.defaultAttributes, attributes ); |
| 37 |
if ( !ve.isEmptyObject( attributes ) ) { |
| 38 |
element.attributes = ve.copy( attributes ); |
| 39 |
} |
| 40 |
return element; |
| 41 |
} |
| 42 |
throw new Error( 'Unknown node type: ' + type ); |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
ve.dm.NodeFactory.prototype.getChildNodeTypes = function ( type ) { |
| 53 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 54 |
return this.registry[ type ].static.childNodeTypes; |
| 55 |
} |
| 56 |
throw new Error( 'Unknown node type: ' + type ); |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
ve.dm.NodeFactory.prototype.getParentNodeTypes = function ( type ) { |
| 67 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 68 |
return this.registry[ type ].static.parentNodeTypes; |
| 69 |
} |
| 70 |
throw new Error( 'Unknown node type: ' + type ); |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
ve.dm.NodeFactory.prototype.getSuggestedParentNodeTypes = function ( type ) { |
| 81 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 82 |
return this.registry[ type ].static.suggestedParentNodeTypes; |
| 83 |
} |
| 84 |
throw new Error( 'Unknown node type: ' + type ); |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
ve.dm.NodeFactory.prototype.canNodeHaveChildren = function ( type ) { |
| 95 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 96 |
|
| 97 |
|
| 98 |
const types = this.registry[ type ].static.childNodeTypes; |
| 99 |
return types === null || ( Array.isArray( types ) && types.length > 0 ); |
| 100 |
} |
| 101 |
throw new Error( 'Unknown node type: ' + type ); |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
ve.dm.NodeFactory.prototype.canNodeHaveChildrenNotContent = function ( type ) { |
| 112 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 113 |
return this.canNodeHaveChildren( type ) && |
| 114 |
!this.registry[ type ].static.canContainContent && |
| 115 |
!this.registry[ type ].static.isContent; |
| 116 |
} |
| 117 |
throw new Error( 'Unknown node type: ' + type ); |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
ve.dm.NodeFactory.prototype.isNodeWrapped = function ( type ) { |
| 128 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 129 |
return this.registry[ type ].static.isWrapped; |
| 130 |
} |
| 131 |
throw new Error( 'Unknown node type: ' + type ); |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.dm.NodeFactory.prototype.isNodeUnwrappable = function ( type ) { |
| 142 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 143 |
return this.isNodeWrapped( type ) && this.registry[ type ].static.isUnwrappable; |
| 144 |
} |
| 145 |
throw new Error( 'Unknown node type: ' + type ); |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
ve.dm.NodeFactory.prototype.isMetaData = function ( type ) { |
| 156 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 157 |
return this.registry[ type ].static.isMetaData; |
| 158 |
} |
| 159 |
throw new Error( 'Unknown node type: ' + type ); |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
ve.dm.NodeFactory.prototype.isRemovableMetaData = function ( type ) { |
| 170 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 171 |
return this.registry[ type ].static.removable; |
| 172 |
} |
| 173 |
throw new Error( 'Unknown item type: ' + type ); |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
ve.dm.NodeFactory.prototype.canNodeContainContent = function ( type ) { |
| 184 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 185 |
return this.registry[ type ].static.canContainContent; |
| 186 |
} |
| 187 |
throw new Error( 'Unknown node type: ' + type ); |
| 188 |
}; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
ve.dm.NodeFactory.prototype.canNodeTakeAnnotation = function ( type, annotation ) { |
| 199 |
if ( !Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 200 |
throw new Error( 'Unknown node type: ' + type ); |
| 201 |
} |
| 202 |
const disallowedList = this.registry[ type ].static.disallowedAnnotationTypes; |
| 203 |
|
| 204 |
for ( let i = 0, len = disallowedList.length; i < len; i++ ) { |
| 205 |
if ( annotation instanceof ve.dm.annotationFactory.lookup( disallowedList[ i ] ) ) { |
| 206 |
return false; |
| 207 |
} |
| 208 |
} |
| 209 |
return true; |
| 210 |
}; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
ve.dm.NodeFactory.prototype.isNodeContent = function ( type ) { |
| 220 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 221 |
return this.registry[ type ].static.isContent; |
| 222 |
} |
| 223 |
throw new Error( 'Unknown node type: ' + type ); |
| 224 |
}; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
ve.dm.NodeFactory.prototype.canNodeSerializeAsContent = function ( type ) { |
| 234 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 235 |
return this.registry[ type ].static.isContent || |
| 236 |
this.registry[ type ].static.canSerializeAsContent; |
| 237 |
} |
| 238 |
throw new Error( 'Unknown node type: ' + type ); |
| 239 |
}; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
ve.dm.NodeFactory.prototype.isNodeFocusable = function ( type ) { |
| 249 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 250 |
return this.registry[ type ].static.isFocusable; |
| 251 |
} |
| 252 |
throw new Error( 'Unknown node type: ' + type ); |
| 253 |
}; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
ve.dm.NodeFactory.prototype.doesNodeHaveSignificantWhitespace = function ( type ) { |
| 265 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 266 |
return this.registry[ type ].static.hasSignificantWhitespace; |
| 267 |
} |
| 268 |
throw new Error( 'Unknown node type: ' + type ); |
| 269 |
}; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
ve.dm.NodeFactory.prototype.doesNodeHandleOwnChildren = function ( type ) { |
| 279 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 280 |
return this.registry[ type ].static.handlesOwnChildren; |
| 281 |
} |
| 282 |
throw new Error( 'Unknown node type: ' + type ); |
| 283 |
}; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
ve.dm.NodeFactory.prototype.shouldIgnoreChildren = function ( type ) { |
| 293 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 294 |
return this.registry[ type ].static.ignoreChildren; |
| 295 |
} |
| 296 |
throw new Error( 'Unknown node type: ' + type ); |
| 297 |
}; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
ve.dm.NodeFactory.prototype.isNodeInternal = function ( type ) { |
| 307 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 308 |
return this.registry[ type ].static.isInternal; |
| 309 |
} |
| 310 |
throw new Error( 'Unknown node type: ' + type ); |
| 311 |
}; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
ve.dm.NodeFactory.prototype.isNodeDeletable = function ( type ) { |
| 321 |
if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) { |
| 322 |
return this.registry[ type ].static.isDeletable; |
| 323 |
} |
| 324 |
throw new Error( 'Unknown node type: ' + type ); |
| 325 |
}; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
ve.dm.nodeFactory = new ve.dm.NodeFactory(); |